1
1

* utilvfs.c (vfs_mkstemps): New function - create temporary file

with the name resembling the original, but safe for scripts.
* direntry.c (vfs_s_open): Use it.
(vfs_s_retrieve_file): Likewise.
* extfs.c (extfs_open): Likewise.
* sfs.c (sfs_redirect): Likewise.
Этот коммит содержится в:
Pavel Roskin 2003-10-29 00:50:36 +00:00
родитель 77bcdc8127
Коммит edce41facd
7 изменённых файлов: 58 добавлений и 47 удалений

Просмотреть файл

@ -1,5 +1,12 @@
2003-10-28 Pavel Roskin <proski@gnu.org>
* utilvfs.c (vfs_mkstemps): New function - create temporary file
with the name resembling the original, but safe for scripts.
* direntry.c (vfs_s_open): Use it.
(vfs_s_retrieve_file): Likewise.
* extfs.c (extfs_open): Likewise.
* sfs.c (sfs_redirect): Likewise.
* vfs.c (mc_ungetlocalcopy): Free local path here, not in class
implementations.
* vfs.h (struct vfs_s_class): Constify "local" argument for

Просмотреть файл

@ -729,7 +729,7 @@ vfs_s_open (struct vfs_class *me, const 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);
tmp_handle = mc_mkstemps (&ino->localname, me->name, NULL);
tmp_handle = vfs_mkstemps (&ino->localname, me->name, name);
if (tmp_handle == -1)
return NULL;
close (tmp_handle);
@ -903,7 +903,7 @@ vfs_s_retrieve_file (struct vfs_class *me, struct vfs_s_inode *ino)
fh.ino = ino;
fh.handle = -1;
handle = mc_mkstemps (&ino->localname, me->name, NULL);
handle = vfs_mkstemps (&ino->localname, me->name, ino->ent->name);
if (handle == -1) {
me->verrno = errno;
goto error_4;

Просмотреть файл

@ -674,17 +674,9 @@ extfs_open (struct vfs_class *me, const char *file, int flags, int mode)
ERRNOR (EISDIR, NULL);
if (entry->inode->local_filename == NULL) {
char *local_filename, *suffix;
char *local_filename;
/* retain original filename as a suffix for a temporary filename */
suffix = g_strconcat ("-", entry->name, NULL);
if ((local_handle =
mc_mkstemps (&local_filename, "extfs", suffix)) == -1) {
/* fallback for the case if the filename is too long */
local_handle = mc_mkstemps (&local_filename, "extfs", NULL);
}
g_free (suffix);
local_handle = vfs_mkstemps (&local_filename, "extfs", entry->name);
if (local_handle == -1)
return NULL;

Просмотреть файл

@ -131,7 +131,7 @@ sfs_redirect (struct vfs_class *me, const char *name)
cur = cur->next;
}
handle = mc_mkstemps (&cache, "sfs", NULL);
handle = vfs_mkstemps (&cache, "sfs", name);
if (handle == -1) {
return "/SOMEONE_PLAYING_DIRTY_TMP_TRICKS_ON_US";

Просмотреть файл

@ -18,26 +18,9 @@
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include <config.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <pwd.h>
#include <sys/types.h>
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#include <errno.h>
#include <pwd.h>
#include <grp.h>
#include <ctype.h>
#include "utilvfs.h"
#include "vfs.h"
/* Extract the hostname and username from the path */
@ -207,3 +190,45 @@ vfs_findgid (char *gname)
}
return savegid;
}
/*
* Create a temporary file with a name resembling the original.
* This is needed e.g. for local copies requested by extfs.
* Some extfs scripts may look at the extension.
* We also protect stupid scripts agains dangerous names.
*/
int
vfs_mkstemps (char **pname, const char *prefix, const char *basename)
{
const unsigned char *p;
char *suffix, *q;
int shift;
int fd;
/* Strip directories */
p = strrchr (basename, PATH_SEP);
if (!p)
p = basename;
else
p++;
/* Protection against very long names */
shift = strlen (p) - (MC_MAXPATHLEN - 16);
if (shift > 0)
p += shift;
suffix = g_malloc (MC_MAXPATHLEN);
/* Protection against unusual characters */
q = suffix;
while (*p && (*p != '#')) {
if (strchr (".-_@", *p) || isalnum (*p))
*q++ = *p;
p++;
}
*q = 0;
fd = mc_mkstemps (pname, prefix, suffix);
g_free (suffix);
return fd;
}

Просмотреть файл

@ -16,5 +16,6 @@ char *vfs_split_url (const char *path, char **host, char **user, int *port,
int vfs_finduid (char *name);
int vfs_findgid (char *name);
int vfs_mkstemps (char **pname, const char *prefix, const char *basename);
#endif /* !__UTILVFS_H */

Просмотреть файл

@ -1010,8 +1010,7 @@ mc_munmap (caddr_t addr, size_t len)
static char *
mc_def_getlocalcopy (struct vfs_class *vfs, const char *filename)
{
char *tmp, *suffix;
const char *basename;
char *tmp;
int fdin, fdout, i;
char buffer[8192];
struct stat mystat;
@ -1020,20 +1019,7 @@ mc_def_getlocalcopy (struct vfs_class *vfs, const char *filename)
if (fdin == -1)
return NULL;
/* retain original filename as a suffix for a temporary filename */
basename = strrchr (filename, PATH_SEP);
if (!basename)
basename = filename;
else
basename++;
suffix = g_strconcat ("-", basename, NULL);
if ((fdout = mc_mkstemps (&tmp, "vfs", suffix)) == -1) {
/* fallback for the case if the filename is too long */
fdout = mc_mkstemps (&tmp, "vfs", NULL);
}
g_free (suffix);
fdout = vfs_mkstemps (&tmp, "vfs", filename);
if (fdout == -1)
goto fail;