* 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.
Этот коммит содержится в:
родитель
77bcdc8127
Коммит
edce41facd
@ -1,5 +1,12 @@
|
|||||||
2003-10-28 Pavel Roskin <proski@gnu.org>
|
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
|
* vfs.c (mc_ungetlocalcopy): Free local path here, not in class
|
||||||
implementations.
|
implementations.
|
||||||
* vfs.h (struct vfs_s_class): Constify "local" argument for
|
* 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);
|
ent = vfs_s_generate_entry (me, name, dir, 0755);
|
||||||
ino = ent->ino;
|
ino = ent->ino;
|
||||||
vfs_s_insert_entry (me, dir, ent);
|
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)
|
if (tmp_handle == -1)
|
||||||
return NULL;
|
return NULL;
|
||||||
close (tmp_handle);
|
close (tmp_handle);
|
||||||
@ -903,7 +903,7 @@ vfs_s_retrieve_file (struct vfs_class *me, struct vfs_s_inode *ino)
|
|||||||
fh.ino = ino;
|
fh.ino = ino;
|
||||||
fh.handle = -1;
|
fh.handle = -1;
|
||||||
|
|
||||||
handle = mc_mkstemps (&ino->localname, me->name, NULL);
|
handle = vfs_mkstemps (&ino->localname, me->name, ino->ent->name);
|
||||||
if (handle == -1) {
|
if (handle == -1) {
|
||||||
me->verrno = errno;
|
me->verrno = errno;
|
||||||
goto error_4;
|
goto error_4;
|
||||||
|
12
vfs/extfs.c
12
vfs/extfs.c
@ -674,17 +674,9 @@ extfs_open (struct vfs_class *me, const char *file, int flags, int mode)
|
|||||||
ERRNOR (EISDIR, NULL);
|
ERRNOR (EISDIR, NULL);
|
||||||
|
|
||||||
if (entry->inode->local_filename == NULL) {
|
if (entry->inode->local_filename == NULL) {
|
||||||
char *local_filename, *suffix;
|
char *local_filename;
|
||||||
|
|
||||||
/* retain original filename as a suffix for a temporary filename */
|
local_handle = vfs_mkstemps (&local_filename, "extfs", entry->name);
|
||||||
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);
|
|
||||||
|
|
||||||
if (local_handle == -1)
|
if (local_handle == -1)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -131,7 +131,7 @@ sfs_redirect (struct vfs_class *me, const char *name)
|
|||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
handle = mc_mkstemps (&cache, "sfs", NULL);
|
handle = vfs_mkstemps (&cache, "sfs", name);
|
||||||
|
|
||||||
if (handle == -1) {
|
if (handle == -1) {
|
||||||
return "/SOMEONE_PLAYING_DIRTY_TMP_TRICKS_ON_US";
|
return "/SOMEONE_PLAYING_DIRTY_TMP_TRICKS_ON_US";
|
||||||
|
@ -18,26 +18,9 @@
|
|||||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <unistd.h>
|
#include <ctype.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 "utilvfs.h"
|
#include "utilvfs.h"
|
||||||
|
|
||||||
#include "vfs.h"
|
#include "vfs.h"
|
||||||
|
|
||||||
/* Extract the hostname and username from the path */
|
/* Extract the hostname and username from the path */
|
||||||
@ -207,3 +190,45 @@ vfs_findgid (char *gname)
|
|||||||
}
|
}
|
||||||
return savegid;
|
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_finduid (char *name);
|
||||||
int vfs_findgid (char *name);
|
int vfs_findgid (char *name);
|
||||||
|
int vfs_mkstemps (char **pname, const char *prefix, const char *basename);
|
||||||
|
|
||||||
#endif /* !__UTILVFS_H */
|
#endif /* !__UTILVFS_H */
|
||||||
|
18
vfs/vfs.c
18
vfs/vfs.c
@ -1010,8 +1010,7 @@ mc_munmap (caddr_t addr, size_t len)
|
|||||||
static char *
|
static char *
|
||||||
mc_def_getlocalcopy (struct vfs_class *vfs, const char *filename)
|
mc_def_getlocalcopy (struct vfs_class *vfs, const char *filename)
|
||||||
{
|
{
|
||||||
char *tmp, *suffix;
|
char *tmp;
|
||||||
const char *basename;
|
|
||||||
int fdin, fdout, i;
|
int fdin, fdout, i;
|
||||||
char buffer[8192];
|
char buffer[8192];
|
||||||
struct stat mystat;
|
struct stat mystat;
|
||||||
@ -1020,20 +1019,7 @@ mc_def_getlocalcopy (struct vfs_class *vfs, const char *filename)
|
|||||||
if (fdin == -1)
|
if (fdin == -1)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* retain original filename as a suffix for a temporary filename */
|
fdout = vfs_mkstemps (&tmp, "vfs", 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);
|
|
||||||
|
|
||||||
if (fdout == -1)
|
if (fdout == -1)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user