diff --git a/vfs/ChangeLog b/vfs/ChangeLog index 844e675aa..7dc2c91b8 100644 --- a/vfs/ChangeLog +++ b/vfs/ChangeLog @@ -1,3 +1,13 @@ +2000-10-31 Pavel Machek + + * ftpfs.c (dir_load): From Roland Mainz + : add '.' and '..' + directories + + * *.c: From Roland: it is not possible to g_free() something + allocated by strdup(), because g_malloc might be different for + malloc. Therefore wrapped strdup into g_strdup() wrapper. + 2000-10-22 Andrew V. Samoilov * samba/libsmb/nterr.c (nt_errs): constified diff --git a/vfs/direntry.c b/vfs/direntry.c index e25ba2c03..aa1ad9ad7 100644 --- a/vfs/direntry.c +++ b/vfs/direntry.c @@ -766,7 +766,7 @@ vfs_s_open (vfs *me, char *file, int flags, int mode) ent = vfs_s_generate_entry (me, name, dir, 0755); ino = ent->ino; vfs_s_insert_entry (me, dir, ent); - ino->localname = tempnam (NULL, me->name); + ino->localname = g_tempnam (NULL, me->name); was_changed = 1; } @@ -935,7 +935,7 @@ vfs_s_retrieve_file(vfs *me, struct vfs_s_inode *ino) memset(&fh, 0, sizeof(fh)); fh.ino = ino; - if (!(ino->localname = tempnam (NULL, me->name))) ERRNOR (ENOMEM, 0); + if (!(ino->localname = g_tempnam (NULL, me->name))) ERRNOR (ENOMEM, 0); handle = open(ino->localname, O_RDWR | O_CREAT | O_TRUNC | O_EXCL, 0600); if (handle == -1) { @@ -1185,3 +1185,20 @@ vfs_s_get_line_interruptible (vfs *me, char *buffer, int size, int fd) buffer [size-1] = 0; return 0; } + + +/* Roland: on most non-GNU/Linux platforms malloc()!=g_malloc() which + * may cause crashes. This wrapper ensures that memory from tempnam + * can safely free'ed with g_free() + */ +char * +g_tempnam( const char *dir, const char *prefix ) +{ + char *tmp = (char *)tempnam( dir, prefix ); + char *name; + + name = g_strdup( tmp ); + free( tmp ); + return( name ); +} + diff --git a/vfs/extfs.c b/vfs/extfs.c index 331ac5de6..8205261d6 100644 --- a/vfs/extfs.c +++ b/vfs/extfs.c @@ -605,7 +605,7 @@ static void *extfs_open (vfs *me, char *file, int flags, int mode) char *cmd; char *archive_name, *p; - entry->inode->local_filename = tempnam (NULL, "extfs"); + entry->inode->local_filename = g_tempnam (NULL, "extfs"); { int handle; diff --git a/vfs/ftpfs.c b/vfs/ftpfs.c index 9508d6ff8..c6f6f5cb8 100644 --- a/vfs/ftpfs.c +++ b/vfs/ftpfs.c @@ -1219,7 +1219,31 @@ dir_load(vfs *me, vfs_s_inode *dir, char *remote_path) /* Clear the interrupt flag */ enable_interrupt_key (); - + +#if 1 + { + /* added 20001006 by gisburn + * add dots '.' and '..'. This must be _executed_ before scanning the dir as the + * code below may jump directly into error handling code (without executing + * remaining code). And C doesn't have try {...} finally {}; :-) + */ + vfs_s_inode *parent = dir->ent->dir; + + if( parent==NULL ) + parent = dir; + + ent = vfs_s_generate_entry(me, ".", dir, 0); + ent->ino->st=dir->st; + num_entries++; + vfs_s_insert_entry(me, dir, ent); + + ent = vfs_s_generate_entry(me, "..", parent, 0); + ent->ino->st=parent->st; + num_entries++; + vfs_s_insert_entry(me, dir, ent); + } +#endif + while (1) { int i; int res = vfs_s_get_line_interruptible (me, buffer, sizeof (buffer), sock); @@ -1729,6 +1753,7 @@ static int netrc_next (void) static const char * const keywords [] = { "default", "machine", "login", "password", "passwd", "account", "macdef" }; + while (1) { netrcp = skip_separators (netrcp); if (*netrcp != '\n') diff --git a/vfs/shared_ftp_fish.c b/vfs/shared_ftp_fish.c index 3258f83da..42c48f9e3 100644 --- a/vfs/shared_ftp_fish.c +++ b/vfs/shared_ftp_fish.c @@ -330,7 +330,7 @@ _get_file_entry(struct connection *bucket, char *file_name, ent->local_filename = NULL; } if (flags & O_TRUNC) { - ent->local_filename = tempnam (NULL, X "fs"); + ent->local_filename = g_tempnam (NULL, X "fs"); if (ent->local_filename == NULL) ERRNOR (ENOMEM, NULL); handle = open(ent->local_filename, O_CREAT | O_TRUNC | O_RDWR | O_EXCL, 0600); if (handle < 0) ERRNOR (EIO, NULL); @@ -368,7 +368,7 @@ _get_file_entry(struct connection *bucket, char *file_name, ent->bucket = bucket; ent->name = g_strdup(p); ent->remote_filename = g_strdup(file_name); - ent->local_filename = tempnam (NULL, X "fs"); + ent->local_filename = g_tempnam (NULL, X "fs"); if (!ent->name || !ent->remote_filename || !ent->local_filename) { direntry_destructor(ent); ERRNOR (ENOMEM, NULL); @@ -841,7 +841,7 @@ static int retrieve_file(struct direntry *fe) if (fe->local_filename) return 1; - if (!(fe->local_filename = tempnam (NULL, X))) ERRNOR (ENOMEM, 0); + if (!(fe->local_filename = g_tempnam (NULL, X))) ERRNOR (ENOMEM, 0); fe->local_is_temp = 1; local_handle = open(fe->local_filename, O_RDWR | O_CREAT | O_TRUNC | O_EXCL, 0600); diff --git a/vfs/vfs.c b/vfs/vfs.c index 33b61d2a2..7862714f1 100644 --- a/vfs/vfs.c +++ b/vfs/vfs.c @@ -1060,7 +1060,7 @@ mc_def_getlocalcopy (vfs *vfs, char *filename) fdin = mc_open (filename, O_RDONLY); if (fdin == -1) return NULL; - tmp = tempnam (NULL, "mclocalcopy"); + tmp = g_tempnam (NULL, "mclocalcopy"); fdout = open (tmp, O_CREAT|O_WRONLY|O_TRUNC|O_EXCL, 0600); if (fdout == -1) goto fail; diff --git a/vfs/xdirentry.h b/vfs/xdirentry.h index 20d64cdb3..116bd8102 100644 --- a/vfs/xdirentry.h +++ b/vfs/xdirentry.h @@ -254,12 +254,20 @@ int vfs_s_get_line_interruptible (vfs *me, char *buffer, int size, int fd); /* misc */ int vfs_s_retrieve_file (vfs *me, struct vfs_s_inode *ino); +/* alloc temp name which can be safely free'd with g_free() */ +char *g_tempnam( const char *dir, const char *prefix ); +#if 0 /* If non-null, FREE */ #define ifree(ptr) do { if (ptr) g_free(ptr); } while (0) +#define ERRNOR(a, b) do { me->verrno = a; return b; } while (0) +#else +#define ifree(ptr) { if (ptr) g_free(ptr); } +#define ERRNOR(a, b) { me->verrno = a; return b; } +#endif #define MEDATA ((struct vfs_s_data *) me->data) -#define ERRNOR(a, b) do { me->verrno = a; return b; } while (0) + #define FH ((struct vfs_s_fh *) fh) #define FH_SUPER FH->ino->super