* ftpfs.c (translate_path): Remove leading slash(es) more

carefully.
(initconn): Check getsockname() return value.
Eliminate goto.
(linear_abort): Make ipbuf const array.
This commit is contained in:
Andrew V. Samoilov 2002-02-01 12:21:55 +00:00
parent ce7bae4dd7
commit 20c71f0c51
2 changed files with 20 additions and 16 deletions

View File

@ -1,3 +1,11 @@
2002-02-01 Andrew V. Samoilov <kai@cmail.ru>
* ftpfs.c (translate_path): Remove leading slash(es) more
carefully.
(initconn): Check getsockname() return value.
Eliminate goto.
(linear_abort): Make ipbuf const array.
2002-01-29 Andrew V. Samoilov <kai@cmail.ru> 2002-01-29 Andrew V. Samoilov <kai@cmail.ru>
* ftpfs.c (reconnect): New function to restore closed connection. * ftpfs.c (reconnect): New function to restore closed connection.

View File

@ -176,18 +176,18 @@ translate_path (vfs *me, vfs_s_super *super, const char *remote_path)
fflush (logfile); fflush (logfile);
} }
/* strip leading slash(es) */
while (*remote_path == '/')
remote_path++;
/* /*
* Don't change "/" into "", e.g. "CWD " would be * Don't change "/" into "", e.g. "CWD " would be
* invalid. * invalid.
*/ */
if (*remote_path == '/' && remote_path[1] == '\0') if (*remote_path == '\0')
return g_strdup ("."); return g_strdup (".");
/* strip leading slash */ ret = g_strdup (remote_path);
if (*remote_path == '/')
ret = g_strdup (remote_path + 1);
else
ret = g_strdup (remote_path);
/* replace first occurance of ":/" with ":" */ /* replace first occurance of ":/" with ":" */
if ((p = strchr (ret, ':')) && *(p + 1) == '/') if ((p = strchr (ret, ':')) && *(p + 1) == '/')
@ -953,21 +953,17 @@ initconn (vfs *me, vfs_s_super *super)
/* If passive setup fails, fallback to active connections */ /* If passive setup fails, fallback to active connections */
/* Active FTP connection */ /* Active FTP connection */
if (bind (data, (struct sockaddr *)&data_addr, len) < 0) if ((bind (data, (struct sockaddr *)&data_addr, len) == 0) &&
goto error_return; (getsockname(data, (struct sockaddr *) &data_addr, &len) == 0) &&
getsockname(data, (struct sockaddr *) &data_addr, &len); (listen (data, 1) == 0))
if (listen (data, 1) < 0)
goto error_return;
{ {
unsigned char *a = (unsigned char *)&data_addr.sin_addr; unsigned char *a = (unsigned char *)&data_addr.sin_addr;
unsigned char *p = (unsigned char *)&data_addr.sin_port; unsigned char *p = (unsigned char *)&data_addr.sin_port;
if (command (me, super, WAIT_REPLY, "PORT %d,%d,%d,%d,%d,%d", a[0], a[1], if (command (me, super, WAIT_REPLY, "PORT %d,%d,%d,%d,%d,%d", a[0], a[1],
a[2], a[3], p[0], p[1]) != COMPLETE) a[2], a[3], p[0], p[1]) == COMPLETE)
goto error_return; return data;
} }
return data;
error_return:
close(data); close(data);
my_errno = EIO; my_errno = EIO;
return -1; return -1;
@ -1018,7 +1014,7 @@ static void
linear_abort (vfs *me, vfs_s_fh *fh) linear_abort (vfs *me, vfs_s_fh *fh)
{ {
vfs_s_super *super = FH_SUPER; vfs_s_super *super = FH_SUPER;
static unsigned char ipbuf[3] = { IAC, IP, IAC }; static unsigned char const ipbuf[3] = { IAC, IP, IAC };
fd_set mask; fd_set mask;
char buf[1024]; char buf[1024];
int dsock = FH_SOCK; int dsock = FH_SOCK;