* fish.c: Use name_quote() to quote filenames.

(file_store): Close localname on error.
This commit is contained in:
Andrew V. Samoilov 2002-11-01 16:55:02 +00:00
parent 1d5f40892a
commit e458d50651
2 changed files with 62 additions and 38 deletions

View File

@ -1,3 +1,8 @@
2002-11-01 Andrew V. Samoilov <sav@bcs.zp.ua>
* fish.c: Use name_quote() to quote filenames.
(file_store): Close localname on error.
2002-10-25 Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz> 2002-10-25 Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
* ftpfs.c (linear_abort): Close data socket, ProFTPD 1.2.6 * ftpfs.c (linear_abort): Close data socket, ProFTPD 1.2.6
@ -515,8 +520,7 @@
fish.local_stat ... fish.local_stat ...
* fish.c (linear_close): ... here. * fish.c (linear_close): ... here.
* ftpfs.c (linear_read): Unset control_connection_buzy * ftpfs.c (linear_read): Unset control_connection_buzy on EOF.
on EOF.
(ftpfs_fh_close): Call vfs_s_invalidate (). (ftpfs_fh_close): Call vfs_s_invalidate ().
* fish.c (fish_fh_open): Don't retrieve file if it is * fish.c (fish_fh_open): Don't retrieve file if it is
@ -1698,13 +1702,13 @@
2000-04-05 Andrew V. Samoilov <sav@bcs.zp.ua> 2000-04-05 Andrew V. Samoilov <sav@bcs.zp.ua>
* utilfs.c (vfs_split_url): don't assign *pass if pass is NULL * utilfs.c (vfs_split_url): Don't assign *pass if pass is NULL
* fish.c (archive_open, archive_same): memory allocated by * fish.c (archive_open, archive_same): memory allocated by
vfs_split_url () must be released after use, don't strdup() vfs_split_url() must be released after use, don't strdup()
values allocated by vfs_split_url () and NULL passed to values allocated by vfs_split_url() and NULL passed to
vfs_split_url () when password value is unused vfs_split_url() when password value is unused
* ftpfs.c (archive_open, archive_same): ditto plus same for * ftpfs.c (archive_open, archive_same): ditto plus same for
ftpfs_get_proxy_host_and_port () ftpfs_get_proxy_host_and_port()
2000-04-06 Timur Bakeyev <mc@bat.ru> 2000-04-06 Timur Bakeyev <mc@bat.ru>

View File

@ -357,6 +357,7 @@ dir_load(vfs *me, vfs_s_inode *dir, char *remote_path)
char buffer[8192]; char buffer[8192];
vfs_s_entry *ent = NULL; vfs_s_entry *ent = NULL;
FILE *logfile; FILE *logfile;
char *quoted_path;
logfile = MEDATA->logfile; logfile = MEDATA->logfile;
@ -365,22 +366,22 @@ dir_load(vfs *me, vfs_s_inode *dir, char *remote_path)
gettimeofday(&dir->u.fish.timestamp, NULL); gettimeofday(&dir->u.fish.timestamp, NULL);
dir->u.fish.timestamp.tv_sec += 10; /* was 360: 10 is good for dir->u.fish.timestamp.tv_sec += 10; /* was 360: 10 is good for
stressing direntry layer a bit */ stressing direntry layer a bit */
quoted_path = name_quote (remote_path, 0);
command(me, super, NONE, command(me, super, NONE,
"#LIST /%s\n" "#LIST /%s\n"
"ls -lLa \"/%s\" 2>/dev/null | grep '^[^cbt]' | (\n" "ls -lLa /%s 2>/dev/null | grep '^[^cbt]' | (\n"
"while read p x u g s m d y n; do\n" "while read p x u g s m d y n; do\n"
"echo \"P$p $u.$g\nS$s\nd$m $d $y\n:$n\n\"\n" "echo \"P$p $u.$g\nS$s\nd$m $d $y\n:$n\n\"\n"
"done\n" "done\n"
")\n" ")\n"
"ls -lLa \"/%s\" 2>/dev/null | grep '^[cb]' | (\n" "ls -lLa /%s 2>/dev/null | grep '^[cb]' | (\n"
"while read p x u g a i m d y n; do\n" "while read p x u g a i m d y n; do\n"
"echo \"P$p $u.$g\nE$a$i\nd$m $d $y\n:$n\n\"\n" "echo \"P$p $u.$g\nE$a$i\nd$m $d $y\n:$n\n\"\n"
"done\n" "done\n"
")\n" ")\n"
"echo '### 200'\n", "echo '### 200'\n",
remote_path, remote_path, remote_path); remote_path, quoted_path, quoted_path);
g_free (quoted_path);
#define SIMPLE_ENTRY vfs_s_generate_entry(me, NULL, dir, 0) #define SIMPLE_ENTRY vfs_s_generate_entry(me, NULL, dir, 0)
ent = SIMPLE_ENTRY; ent = SIMPLE_ENTRY;
while (1) { while (1) {
@ -481,15 +482,20 @@ file_store(vfs *me, vfs_s_fh *fh, char *name, char *localname)
struct stat s; struct stat s;
int was_error = 0; int was_error = 0;
int h; int h;
char *quoted_name;
h = open(localname, O_RDONLY); h = open (localname, O_RDONLY);
if (fstat(h, &s)<0) if (h == -1)
ERRNOR (EIO, -1); ERRNOR (EIO, -1);
if (fstat(h, &s)<0) {
close (h);
ERRNOR (EIO, -1);
}
/* Use this as stor: ( dd block ; dd smallblock ) | ( cat > file; cat > /dev/null ) */ /* Use this as stor: ( dd block ; dd smallblock ) | ( cat > file; cat > /dev/null ) */
print_vfs_message(_("fish: store %s: sending command..."), name ); print_vfs_message(_("fish: store %s: sending command..."), name );
quoted_name = name_quote (name, 0);
/* /*
* FIXME: Limit size to unsigned long for now. * FIXME: Limit size to unsigned long for now.
* Files longer than 256 * ULONG_MAX are not supported. * Files longer than 256 * ULONG_MAX are not supported.
@ -497,18 +503,18 @@ file_store(vfs *me, vfs_s_fh *fh, char *name, char *localname)
if (!fh->u.fish.append) if (!fh->u.fish.append)
n = command (me, super, WAIT_REPLY, n = command (me, super, WAIT_REPLY,
"#STOR %lu /%s\n" "#STOR %lu /%s\n"
"> \"/%s\"\n" "> /%s\n"
"echo '### 001'\n" "echo '### 001'\n"
"(\n" "(\n"
"dd ibs=256 obs=4096 count=%lu\n" "dd ibs=256 obs=4096 count=%lu\n"
"dd bs=%lu count=1\n" "dd bs=%lu count=1\n"
") 2>/dev/null | (\n" ") 2>/dev/null | (\n"
"cat > \"/%s\"\n" "cat > /%s\n"
"cat > /dev/null\n" "cat > /dev/null\n"
"); echo '### 200'\n", "); echo '### 200'\n",
(unsigned long) s.st_size, name, name, (unsigned long) s.st_size, name, quoted_name,
(unsigned long) (s.st_size >> 8), (unsigned long) (s.st_size >> 8),
((unsigned long) s.st_size) & (256 - 1), name); ((unsigned long) s.st_size) & (256 - 1), quoted_name);
else else
n = command (me, super, WAIT_REPLY, n = command (me, super, WAIT_REPLY,
"#STOR %lu /%s\n" "#STOR %lu /%s\n"
@ -517,16 +523,18 @@ file_store(vfs *me, vfs_s_fh *fh, char *name, char *localname)
"dd ibs=256 obs=4096 count=%lu\n" "dd ibs=256 obs=4096 count=%lu\n"
"dd bs=%lu count=1\n" "dd bs=%lu count=1\n"
") 2>/dev/null | (\n" ") 2>/dev/null | (\n"
"cat >> \"/%s\"\n" "cat >> /%s\n"
"cat > /dev/null\n" "cat > /dev/null\n"
"); echo '### 200'\n", "); echo '### 200'\n",
(unsigned long) s.st_size, name, (unsigned long) s.st_size, name,
(unsigned long) (s.st_size >> 8), (unsigned long) (s.st_size >> 8),
((unsigned long) s.st_size) & (256 - 1), name); ((unsigned long) s.st_size) & (256 - 1), quoted_name);
if (n != PRELIM) g_free (quoted_name);
if (n != PRELIM) {
close (h);
ERRNOR(E_REMOTE, -1); ERRNOR(E_REMOTE, -1);
}
total = 0; total = 0;
while (1) { while (1) {
@ -549,9 +557,9 @@ file_store(vfs *me, vfs_s_fh *fh, char *name, char *localname)
was_error ? _("zeros") : _("file"), total, was_error ? _("zeros") : _("file"), total,
(unsigned long) s.st_size); (unsigned long) s.st_size);
} }
close(h);
if ((get_reply (me, SUP.sockr, NULL, 0) != COMPLETE) || was_error) if ((get_reply (me, SUP.sockr, NULL, 0) != COMPLETE) || was_error)
ERRNOR (E_REMOTE, -1); ERRNOR (E_REMOTE, -1);
close(h);
return 0; return 0;
error_return: error_return:
close(h); close(h);
@ -562,21 +570,25 @@ error_return:
static int linear_start(vfs *me, vfs_s_fh *fh, int offset) static int linear_start(vfs *me, vfs_s_fh *fh, int offset)
{ {
char *name; char *name;
char *quoted_name;
if (offset) if (offset)
ERRNOR (E_NOTSUPP, 0); ERRNOR (E_NOTSUPP, 0);
/* fe->local_stat.st_mtime = 0; FIXME: what is this good for? */ /* fe->local_stat.st_mtime = 0; FIXME: what is this good for? */
name = vfs_s_fullpath (me, fh->ino); name = vfs_s_fullpath (me, fh->ino);
if (!name) if (!name)
return 0; return 0;
quoted_name = name_quote (name, 0);
g_free (name);
name = quoted_name;
fh->u.fish.append = 0; fh->u.fish.append = 0;
offset = command(me, FH_SUPER, WANT_STRING, offset = command(me, FH_SUPER, WANT_STRING,
"#RETR /%s\n" "#RETR /%s\n"
"ls -l \"/%s\" 2>/dev/null | (\n" "ls -l /%s 2>/dev/null | (\n"
"read var1 var2 var3 var4 var5 var6\n" "read var1 var2 var3 var4 var5 var6\n"
"echo \"$var5\"\n" "echo \"$var5\"\n"
")\n" ")\n"
"echo '### 100'\n" "echo '### 100'\n"
"cat \"/%s\"\n" "cat /%s\n"
"echo '### 200'\n", "echo '### 200'\n",
name, name, name ); name, name, name );
g_free (name); g_free (name);
@ -681,9 +693,11 @@ send_fish_command(vfs *me, vfs_s_super *super, char *cmd, int flags)
char *rpath; \ char *rpath; \
vfs_s_super *super; \ vfs_s_super *super; \
if (!(rpath = vfs_s_get_path_mangle(me, path, &super, 0))) \ if (!(rpath = vfs_s_get_path_mangle(me, path, &super, 0))) \
return -1; return -1; \
rpath = name_quote (rpath, 0);
#define POSTFIX(flags) \ #define POSTFIX(flags) \
g_free (rpath); \
return send_fish_command(me, super, buf, flags); return send_fish_command(me, super, buf, flags);
static int static int
@ -702,32 +716,38 @@ fish_chmod (vfs *me, char *path, int mode)
static int fish_##name (vfs *me, char *path1, char *path2) \ static int fish_##name (vfs *me, char *path1, char *path2) \
{ \ { \
char buf[BUF_LARGE]; \ char buf[BUF_LARGE]; \
char *rpath1 = NULL, *rpath2 = NULL; \ char *rpath1, *rpath2; \
vfs_s_super *super1, *super2; \ vfs_s_super *super1, *super2; \
if (!(rpath1 = vfs_s_get_path_mangle(me, path1, &super1, 0))) \ if (!(rpath1 = vfs_s_get_path_mangle(me, path1, &super1, 0))) \
return -1; \ return -1; \
if (!(rpath2 = vfs_s_get_path_mangle(me, path2, &super2, 0))) \ if (!(rpath2 = vfs_s_get_path_mangle(me, path2, &super2, 0))) \
return -1; \ return -1; \
g_snprintf(buf, 1023, string "\n", rpath1, rpath2, rpath1, rpath2 ); \ rpath1 = name_quote (rpath1, 0); \
rpath2 = name_quote (rpath2, 0); \
g_snprintf(buf, sizeof(buf), string "\n", rpath1, rpath2, rpath1, rpath2); \
g_free (rpath1); \
g_free (rpath2); \
return send_fish_command(me, super2, buf, OPT_FLUSH); \ return send_fish_command(me, super2, buf, OPT_FLUSH); \
} }
#define XTEST if (bucket1 != bucket2) { ERRNOR (EXDEV, -1); } #define XTEST if (bucket1 != bucket2) { ERRNOR (EXDEV, -1); }
FISH_OP(rename, XTEST, "#RENAME /%s /%s\n" FISH_OP(rename, XTEST, "#RENAME /%s /%s\n"
"mv \"/%s\" \"/%s\" 2>/dev/null\n" "mv /%s /%s 2>/dev/null\n"
"echo '### 000'" ) "echo '### 000'" )
FISH_OP(link, XTEST, "#LINK /%s /%s\n" FISH_OP(link, XTEST, "#LINK /%s /%s\n"
"ln \"/%s\" \"/%s\" 2>/dev/null\n" "ln /%s /%s 2>/dev/null\n"
"echo '### 000'" ) "echo '### 000'" )
static int fish_symlink (vfs *me, char *setto, char *path) static int fish_symlink (vfs *me, char *setto, char *path)
{ {
PREFIX PREFIX
setto = name_quote (setto, 0);
g_snprintf(buf, sizeof(buf), g_snprintf(buf, sizeof(buf),
"#SYMLINK %s /%s\n" "#SYMLINK %s /%s\n"
"ln -s \"%s\" \"/%s\" 2>/dev/null\n" "ln -s %s /%s 2>/dev/null\n"
"echo '### 000'\n", "echo '### 000'\n",
setto, rpath, setto, rpath); setto, rpath, setto, rpath);
g_free (setto);
POSTFIX(OPT_FLUSH); POSTFIX(OPT_FLUSH);
} }
@ -749,7 +769,7 @@ fish_chown (vfs *me, char *path, int owner, int group)
sgroup = gr->gr_name; sgroup = gr->gr_name;
g_snprintf(buf, sizeof(buf), g_snprintf(buf, sizeof(buf),
"#CHOWN /%s /%s\n" "#CHOWN /%s /%s\n"
"chown %s \"/%s\" 2>/dev/null\n" "chown %s /%s 2>/dev/null\n"
"echo '### 000'\n", "echo '### 000'\n",
sowner, rpath, sowner, rpath,
sowner, rpath); sowner, rpath);
@ -757,7 +777,7 @@ fish_chown (vfs *me, char *path, int owner, int group)
/* FIXME: what should we report if chgrp succeeds but chown fails? */ /* FIXME: what should we report if chgrp succeeds but chown fails? */
g_snprintf(buf, sizeof(buf), g_snprintf(buf, sizeof(buf),
"#CHGRP /%s /%s\n" "#CHGRP /%s /%s\n"
"chgrp %s \"/%s\" 2>/dev/null\n" "chgrp %s /%s 2>/dev/null\n"
"echo '### 000'\n", "echo '### 000'\n",
sgroup, rpath, sgroup, rpath,
sgroup, rpath); sgroup, rpath);
@ -770,7 +790,7 @@ static int fish_unlink (vfs *me, char *path)
PREFIX PREFIX
g_snprintf(buf, sizeof(buf), g_snprintf(buf, sizeof(buf),
"#DELE /%s\n" "#DELE /%s\n"
"rm -f \"/%s\" 2>/dev/null\n" "rm -f /%s 2>/dev/null\n"
"echo '### 000'\n", "echo '### 000'\n",
rpath, rpath); rpath, rpath);
POSTFIX(OPT_FLUSH); POSTFIX(OPT_FLUSH);
@ -781,7 +801,7 @@ static int fish_mkdir (vfs *me, char *path, mode_t mode)
PREFIX PREFIX
g_snprintf(buf, sizeof(buf), g_snprintf(buf, sizeof(buf),
"#MKD /%s\n" "#MKD /%s\n"
"mkdir \"/%s\" 2>/dev/null\n" "mkdir /%s 2>/dev/null\n"
"echo '### 000'\n", "echo '### 000'\n",
rpath, rpath); rpath, rpath);
POSTFIX(OPT_FLUSH); POSTFIX(OPT_FLUSH);
@ -792,7 +812,7 @@ static int fish_rmdir (vfs *me, char *path)
PREFIX PREFIX
g_snprintf(buf, sizeof(buf), g_snprintf(buf, sizeof(buf),
"#RMD /%s\n" "#RMD /%s\n"
"rmdir \"/%s\" 2>/dev/null\n" "rmdir /%s 2>/dev/null\n"
"echo '### 000'\n", "echo '### 000'\n",
rpath, rpath); rpath, rpath);
POSTFIX(OPT_FLUSH); POSTFIX(OPT_FLUSH);