Re: 2.0.2 released ...
- From: Christophe Fergeau <teuf users sourceforge net>
- To: Michael Meeks <michael ximian com>
- Cc: gnome-vfs-list gnome org
- Subject: Re: 2.0.2 released ...
- Date: 20 Sep 2002 09:32:39 +0200
> Righty ho - I think it's best to split and commit; and then get this
> last bit done.
>
So I split those patches yesterday evening. They should work separately,
but in fact I tested all the ssh patches after applying ssh-fixes since
otherwise I can't use the ssh method
Each patch have a Changelog entry so I won't get into details in this
mail.
The ssh-quote patch has a few changes apart from adding g_shell_quote: I
moved around some g_free, so I may have introduced leaks even if I was
very careful with that. I also renamed a variable named j to bytes_read
and changed two 'if (strlen(str)>0)' to 'if (*str != '\0')' (I should
have put those changes in ssh-fixes but that would have been a little
painful so I let them in ssh-quote)
Christophe
--- gnome-vfs/ChangeLog 2002-07-27 05:50:12.000000000 +0200
+++ gnome-vfs-new/ChangeLog 2002-09-19 20:12:54.000000000 +0200
@@ -1,3 +1,8 @@
+2002-09-19 Christophe Fergeau <teuf users sourceforge net>
+ * modules/ssh-method.c:
+ Correctly report "Authentification failed" when the method couldn't
+ run ssh because ssh waited for a password
+
2002-07-26 Ian McKellar <yakk yakk net>
* libgnomevfs/gnome-vfs-xfer.c: (copy_file):
--- gnome-vfs/modules/ssh-method.c 2002-07-19 09:57:11.000000000 +0200
+++ gnome-vfs-new/modules/ssh-method.c 2002-09-19 21:25:14.000000000 +0200
@@ -47,6 +47,7 @@
GnomeVFSOpenMode open_mode;
int read_fd;
int write_fd;
+ int error_fd;
pid_t pid;
} SshHandle;
@@ -145,6 +146,78 @@
NULL /* create_symbolic_link */
};
+
+static gboolean
+ssh_data_available_on_stderr (SshHandle *handle)
+{
+ struct timeval timeout;
+ fd_set set;
+ int max;
+ int res;
+
+ /* This function checks if there was data output by ssh
+ * on stderr to detect if we could successfully connect
+ * (without that, trying to read from stderr may block)
+ * It first check both stderr and stdout because if we
+ * have data on stdout, we assume there will be nothing
+ * output on stderr (we don't want to block on the first
+ * select for too long if there will be nothing output on
+ * stderr)
+ * FIXME: that's some quite ugly code only to detect if
+ * a try to read from stderr will block. Maybe there is
+ * a cleaner way to do that
+ */
+ FD_ZERO (&set);
+ FD_SET (handle->read_fd, &set);
+ FD_SET (handle->error_fd, &set);
+ timeout.tv_sec = 3;
+ timeout.tv_usec = 0;
+ if (handle->error_fd >= handle->read_fd) {
+ max = handle->error_fd;
+ } else {
+ max = handle->read_fd;
+ }
+ res = select (max+1,&set, NULL, NULL, &timeout);
+ if (res <= 0){
+ return FALSE;
+ }
+ FD_CLR (handle->read_fd, &set);
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 0;
+ if (select (handle->error_fd+1, &set, NULL, NULL, &timeout)<=0) {
+ return FALSE;
+ }
+ return TRUE;
+}
+
+static GnomeVFSResult
+ssh_check_connection (SshHandle *handle)
+{
+ GIOChannel *channel;
+ GIOStatus result;
+ gchar *line;
+
+ if (!ssh_data_available_on_stderr (handle)) {
+ return GNOME_VFS_OK;
+ }
+
+ channel = g_io_channel_unix_new (handle->error_fd);
+ result = g_io_channel_read_line (channel, &line, NULL, NULL, NULL);
+ if (result != G_IO_STATUS_NORMAL) {
+ return GNOME_VFS_OK;
+ }
+ g_io_channel_shutdown (channel, FALSE, NULL);
+ g_io_channel_unref (channel);
+
+ if (strcmp ("Permission denied.\r\n", line) == 0) {
+ return GNOME_VFS_ERROR_ACCESS_DENIED;
+ }
+ g_print("Unknown error: %s\n", line);
+ /* FIXME: which other errors can ssh return ? */
+ return GNOME_VFS_ERROR_GENERIC;
+}
+
+
/* FIXME: does this like FDs? */
static GnomeVFSResult
ssh_connect (SshHandle **handle_return,
@@ -155,7 +228,7 @@
char *command_line;
int argc;
GError *gerror = NULL;
-
+ GnomeVFSResult result;
command_line = g_strconcat ("ssh -oBatchmode=yes -x -l ",
gnome_vfs_uri_get_user_name (uri),
@@ -177,24 +250,33 @@
handle->uri = uri;
g_spawn_async_with_pipes (NULL, argv, NULL,
- G_SPAWN_SEARCH_PATH | G_SPAWN_STDERR_TO_DEV_NULL,
- NULL, NULL,
- &handle->pid, &handle->write_fd, &handle->read_fd,
- NULL, &gerror);
+ G_SPAWN_SEARCH_PATH, NULL, NULL,
+ &handle->pid,
+ &handle->write_fd, &handle->read_fd,
+ &handle->error_fd, &gerror);
g_strfreev (argv);
if (gerror) {
g_warning (gerror->message);
g_free (handle);
+ handle = NULL;
+ return GNOME_VFS_ERROR_SERVICE_NOT_AVAILABLE;
}
gnome_vfs_uri_ref (handle->uri);
*handle_return = handle;
- return GNOME_VFS_OK;
+ result = ssh_check_connection (handle);
+ if (result != GNOME_VFS_OK) {
+ gnome_vfs_uri_unref (handle->uri);
+ g_free (handle);
+ handle = NULL;
+ }
+ return result;
}
+
static GnomeVFSResult
ssh_destroy (SshHandle *handle)
{
@@ -200,6 +282,7 @@
{
close (handle->read_fd);
close (handle->write_fd);
+ close (handle->error_fd);
gnome_vfs_uri_unref (handle->uri);
kill (handle->pid, SIGINT);
g_free (handle);
--- gnome-vfs/ChangeLog 2002-07-27 05:50:12.000000000 +0200
+++ gnome-vfs-new/ChangeLog 2002-09-19 20:08:10.000000000 +0200
@@ -1,3 +1,12 @@
+2002-09-19 Christophe Fergeau <teuf users sourceforge net>
+ * modules/ssh-method.c:
+ Make do_read return GNOME_VFS_ERROR_EOF when it read 0 byte
+ Force C locale in ssh_connect before running ssh (the ls parsing
+ function expects ls output to be in this locale)
+ When the uri contains no username, use the name of the current user
+ (otherwise ssh://localhost won't work).
+ Fix a possible buffer overflow in do_read_directory
+
2002-07-26 Ian McKellar <yakk yakk net>
* libgnomevfs/gnome-vfs-xfer.c: (copy_file):
--- gnome-vfs/modules/ssh-method.c 2002-07-19 09:57:11.000000000 +0200
+++ gnome-vfs/modules/ssh-method-new.c 2002-09-19 20:57:37.000000000 +0200
@@ -37,6 +36,8 @@
#include <unistd.h>
#include <signal.h>
+#define LINE_LENGTH 4096 /* max line length we'll grok */
+
typedef struct {
GnomeVFSMethodHandle method_handle;
GnomeVFSURI *uri;
@@ -153,17 +234,21 @@
char ** argv;
SshHandle *handle;
char *command_line;
+ const gchar *username;
int argc;
GError *gerror = NULL;
+ username = gnome_vfs_uri_get_user_name(uri);
+ if (username == NULL) {
+ username = g_get_user_name();
+ }
- command_line = g_strconcat ("ssh -oBatchmode=yes -x -l ",
- gnome_vfs_uri_get_user_name (uri),
+ command_line = g_strconcat ("ssh -oBatchMode=yes -x -l ",
+ username,
" ", gnome_vfs_uri_get_host_name (uri),
- " ", command,
+ " ", "\"LC_ALL=C;", command,"\"",
NULL);
-
g_shell_parse_argv (command_line, &argc, &argv, &gerror);
g_free (command_line);
if (gerror) {
@@ -397,8 +463,14 @@
GnomeVFSFileSize *bytes_read,
GnomeVFSContext *context)
{
- return ssh_read ((SshHandle *)method_handle, buffer, num_bytes,
+ GnomeVFSResult result;
+
+ result = ssh_read ((SshHandle *)method_handle, buffer, num_bytes,
bytes_read);
+ if (*bytes_read == 0) {
+ result = GNOME_VFS_ERROR_EOF;
+ }
+ return result;
}
/* alternative impl:
@@ -461,8 +534,6 @@
return ssh_destroy ((SshHandle *)method_handle);
}
-#define LINE_LENGTH 4096 /* max line length we'll grok */
-
static GnomeVFSResult
do_read_directory (GnomeVFSMethod *method,
GnomeVFSMethodHandle *method_handle,
@@ -470,10 +541,10 @@
GnomeVFSContext *context)
{
GnomeVFSResult result = GNOME_VFS_OK;
- char line[LINE_LENGTH];
+ char line[LINE_LENGTH+1];
char c;
int i=0;
- GnomeVFSFileSize j;
+ GnomeVFSFileSize bytes_read;
struct stat st;
char *tempfilename, *filename, *linkname;
@@ -482,11 +553,12 @@
filename = NULL;
linkname = NULL;
i = 0;
- j = 0;
+ bytes_read = 0;
while (i<LINE_LENGTH) {
- result = ssh_read ((SshHandle *)method_handle, &c, 1, &j);
- if (j == 0 || c == '\r' || c == '\n') {
+ result = ssh_read ((SshHandle *)method_handle, &c,
+ sizeof(char), &bytes_read);
+ if (bytes_read == 0 || c == '\r' || c == '\n') {
break;
}
@@ -497,7 +569,9 @@
line[i] = c;
i++;
}
-
+ /* Here we can have i == LINE_LENGTH which explains
+ * why the size of line is LINE_LENGTH+1
+ */
line[i] = 0;
if (i == 0) {
return GNOME_VFS_ERROR_EOF;
--- gnome-vfs/ChangeLog 2002-09-19 21:11:47.000000000 +0200
+++ gnome-vfs-new/ChangeLog 2002-09-19 21:13:59.000000000 +0200
@@ -1,4 +1,9 @@
+2002-09-19 Christophe Fergeau <teuf users sourceforge net>
+
+ * modules/ssh-method.c:
+ Quote filenames using g_shell_quote before passing them to ssh
+
2002-07-26 Ian McKellar <yakk yakk net>
* libgnomevfs/gnome-vfs-xfer.c: (copy_file):
--- gnome-vfs/modules/ssh-method.c 2002-07-19 09:57:11.000000000 +0200
+++ gnome-vfs/modules/ssh-method-new.c 2002-09-19 20:25:59.000000000 +0200
@@ -256,26 +352,6 @@
}
#if 0
-static char *ssh_escape (const char *string)
-{
- char *new_str;
- int i,j;
-
- new_str = g_malloc0 (strlen (string)*2+3);
-
- new_str[0]='\'';
-
- for (i=0,j=1; string[i] != '\0'; i++, j++) {
- if (string[i] == '\'') {
- new_str[j] = '\\';
- j++;
- }
- new_str[j] = string[i];
- }
-
- return new_str;
-}
-
static GnomeVFSResult
ssh_send (SshHandle *handle,
const char *string)
@@ -305,27 +381,23 @@
GnomeVFSResult result = GNOME_VFS_OK;
char *cmd;
SshHandle *handle = NULL;
- char *name;
-
- /* FIXME: escape for shell */
- name = gnome_vfs_unescape_string (uri->text, G_DIR_SEPARATOR_S);
if (mode == GNOME_VFS_OPEN_READ) {
- /* FIXME: escape for shell */
- cmd = g_strdup_printf ("cat '%s'", name);
+ char *name;
+ char *quoted_name;
+ name = gnome_vfs_unescape_string (uri->text,
+ G_DIR_SEPARATOR_S);
+ quoted_name = g_shell_quote (name);
+ g_free (name);
+
+ cmd = g_strdup_printf ("cat %s", quoted_name);
result = ssh_connect (&handle, uri, cmd);
g_free (cmd);
-
+ g_free (quoted_name);
if (result != GNOME_VFS_OK) {
- g_free (name);
return result;
}
-
- } else if (mode == GNOME_VFS_OPEN_WRITE) {
- g_free (name);
- return GNOME_VFS_ERROR_INVALID_OPEN_MODE;
} else {
- g_free (name);
return GNOME_VFS_ERROR_INVALID_OPEN_MODE;
}
@@ -333,9 +405,7 @@
handle->type = SSH_FILE;
*method_handle = (GnomeVFSMethodHandle *)handle;
- g_free (name);
-
- return result;
+ return GNOME_VFS_OK;
}
static GnomeVFSResult
@@ -351,23 +421,22 @@
char *cmd;
GnomeVFSResult result;
char *name;
-
- /* FIXME: escape for shell */
- name = gnome_vfs_unescape_string (uri->text, G_DIR_SEPARATOR_S);
+ char *quoted_name;
if (mode != GNOME_VFS_OPEN_WRITE) {
- g_free (name);
return GNOME_VFS_ERROR_INVALID_OPEN_MODE;
}
+ name = gnome_vfs_unescape_string (uri->text, G_DIR_SEPARATOR_S);
+ quoted_name = g_shell_quote (name);
- /* FIXME: escape for shell */
- cmd = g_strdup_printf ("cat > '%s'", name);
+ cmd = g_strdup_printf ("cat > %s", quoted_name);
result = ssh_connect (&handle, uri, cmd);
g_free (cmd);
+ g_free (name);
+ g_free (quoted_name);
if (result != GNOME_VFS_OK) {
- g_free (name);
return result;
}
@@ -377,7 +445,6 @@
handle->type = SSH_FILE;
*method_handle = (GnomeVFSMethodHandle *)handle;
- g_free (name);
return result;
}
@@ -427,17 +500,19 @@
char *cmd = NULL;
GnomeVFSResult result;
char *name;
+ char *quoted_name;
- /* FIXME: escape for shell */
name = gnome_vfs_unescape_string (uri->text, G_DIR_SEPARATOR_S);
+ quoted_name = g_shell_quote (name);
- if (strlen (name) > 0) {
- cmd = g_strdup_printf ("ls -l '%s'", name);
+ if (*name != '\0') {
+ cmd = g_strdup_printf ("ls -l %s", quoted_name);
} else {
cmd = g_strdup_printf ("ls -l '/'");
}
result = ssh_connect (&handle, uri, cmd);
+ g_free (quoted_name);
g_free (name);
g_free (cmd);
@@ -449,7 +524,6 @@
handle->type = SSH_LIST;
*method_handle = (GnomeVFSMethodHandle *)handle;
- return result;
return GNOME_VFS_OK;
}
@@ -556,12 +630,13 @@
char *cmd = NULL;
GnomeVFSResult result;
char *name;
+ char *quoted_name;
- /* FIXME: escape for shell */
name = gnome_vfs_unescape_string (uri->text, G_DIR_SEPARATOR_S);
+ quoted_name = g_shell_quote (name);
- if (strlen (name) > 0) {
- cmd = g_strdup_printf ("ls -ld '%s' 2>&1", name);
+ if (*name != '\0') {
+ cmd = g_strdup_printf ("ls -ld %s 2>&1", quoted_name);
} else {
cmd = g_strdup_printf ("ls -ld '/' 2>&1");
}
@@ -569,6 +644,7 @@
result = ssh_connect (&handle, uri, cmd);
g_free (cmd);
g_free (name);
+ g_free (quoted_name);
if (result != GNOME_VFS_OK) {
return result;
@@ -595,15 +671,16 @@
char *cmd = NULL;
GnomeVFSResult result;
char *name;
+ char *quoted_name;
- /* FIXME: escape for shell */
name = gnome_vfs_unescape_string (uri->text, G_DIR_SEPARATOR_S);
+ quoted_name = g_shell_quote (name);
- /* FIXME: escape for shell */
- cmd = g_strdup_printf ("mkdir '%s'", name);
+ cmd = g_strdup_printf ("mkdir %s", quoted_name);
result = ssh_connect (&handle, uri, cmd);
g_free (cmd);
g_free (name);
+ g_free (quoted_name);
if (result != GNOME_VFS_OK) {
return result;
@@ -623,16 +700,18 @@
char *cmd = NULL;
GnomeVFSResult result;
gchar *name;
+ gchar *quoted_name;
name = gnome_vfs_unescape_string (uri->text, G_DIR_SEPARATOR_S);
if (name == NULL)
return GNOME_VFS_ERROR_INVALID_URI;
+ quoted_name = g_shell_quote (name);
- /* FIXME: escape for shell */
- cmd = g_strdup_printf ("rm -rf '%s'", name);
+ cmd = g_strdup_printf ("rm -rf %s", quoted_name);
result = ssh_connect (&handle, uri, cmd);
g_free (cmd);
g_free (name);
+ g_free (quoted_name);
if (result != GNOME_VFS_OK) {
return result;
@@ -652,16 +731,18 @@
char *cmd = NULL;
GnomeVFSResult result;
gchar *name;
+ gchar *quoted_name;
name = gnome_vfs_unescape_string (uri->text, G_DIR_SEPARATOR_S);
if (name == NULL)
return GNOME_VFS_ERROR_INVALID_URI;
+ quoted_name = g_shell_quote (name);
- /* FIXME: escape for shell */
- cmd = g_strdup_printf ("rm -rf '%s'", name);
+ cmd = g_strdup_printf ("rm -rf %s", quoted_name);
result = ssh_connect (&handle, uri, cmd);
g_free (cmd);
g_free (name);
+ g_free (quoted_name);
if (result != GNOME_VFS_OK) {
return result;
@@ -692,6 +773,8 @@
char *encoded_dir;
char *dir;
char *new_name;
+ char *quoted_full_name;
+ char *quoted_new_name;
encoded_dir = gnome_vfs_uri_extract_dirname (uri);
dir = gnome_vfs_unescape_string (encoded_dir, G_DIR_SEPARATOR_S);
@@ -710,32 +793,35 @@
}
/* FIXME: escape for shell */
- cmd = g_strdup_printf ("mv '%s' '%s'", full_name,
- new_name);
+ quoted_new_name = g_shell_quote (new_name);
+ quoted_full_name = g_shell_quote (full_name);
+ cmd = g_strdup_printf ("mv %s %s", quoted_full_name,
+ quoted_new_name);
result = ssh_connect (&handle, uri, cmd);
g_free (cmd);
g_free (dir);
g_free (new_name);
+ g_free (quoted_new_name);
+ g_free (quoted_full_name);
+ g_free (full_name);
+
+ if (result != GNOME_VFS_OK) {
+ return result;
+ }
/* Read all info from remote host */
while (1) {
char c;
GnomeVFSResult res;
- GnomeVFSFileSize j;
- res = ssh_read (handle, &c, 1, &j);
- if (j == 0 || res != GNOME_VFS_OK)
+ GnomeVFSFileSize bytes_read;
+ res = ssh_read (handle, &c, 1, &bytes_read);
+ if (bytes_read == 0 || res != GNOME_VFS_OK)
break;
}
ssh_destroy (handle);
-
- if (result != GNOME_VFS_OK) {
- g_free (full_name);
- return result;
- }
}
- g_free (full_name);
return result;
}
--- gnome-vfs/ChangeLog 2002-07-27 05:50:12.000000000 +0200
+++ gnome-vfs-new/ChangeLog 2002-09-19 20:34:01.000000000 +0200
@@ -1,3 +1,8 @@
+2002-09-19 Christophe Fergeau <teuf users sourceforge net>
+ * modules/ftp-method.c:
+ Moved ftp authentification to a separate function (ftp_login)
+ Correctly return GNOME_VFS_ERROR_EOF when do_read didn't read anything
+
2002-07-26 Ian McKellar <yakk yakk net>
* libgnomevfs/gnome-vfs-xfer.c: (copy_file):
--- gnome-vfs/modules/ftp-method.c 2002-05-08 21:04:51.000000000 +0200
+++ gnome-vfs-new/modules/ftp-method.c 2002-09-19 19:48:05.000000000 +0200
@@ -48,8 +49,8 @@
#include <libgnomevfs/gnome-vfs-method.h>
#include <libgnomevfs/gnome-vfs-mime.h>
#include <libgnomevfs/gnome-vfs-mime-utils.h>
-#include <libgnomevfs/gnome-vfs-module-shared.h>
#include <libgnomevfs/gnome-vfs-module.h>
+#include <libgnomevfs/gnome-vfs-module-shared.h>
#include <libgnomevfs/gnome-vfs-parse-ls.h>
#include <libgnomevfs/gnome-vfs-utils.h>
#include <stdio.h> /* for sscanf */
@@ -504,12 +505,32 @@
}
+
+static GnomeVFSResult ftp_login (FtpConnection *conn,
+ const char *user, const char *password)
+{
+ gchar *tmpstring;
+ GnomeVFSResult result;
+
+ tmpstring = g_strdup_printf ("USER %s", user);
+ result = do_basic_command (conn, tmpstring);
+ g_free (tmpstring);
+
+ if (IS_300 (conn->response_code)) {
+ tmpstring = g_strdup_printf ("PASS %s", password);
+ result = do_basic_command (conn, tmpstring);
+ g_free (tmpstring);
+ }
+
+ return result;
+}
+
+
static GnomeVFSResult
ftp_connection_create (FtpConnection **connptr, GnomeVFSURI *uri, GnomeVFSContext *context)
{
FtpConnection *conn = g_new0 (FtpConnection, 1);
GnomeVFSResult result;
- gchar *tmpstring;
gint port = control_port;
const gchar *user = anon_user;
const gchar *pass = anon_pass;
@@ -573,15 +594,7 @@
return result;
}
- tmpstring = g_strdup_printf ("USER %s", user);
- result = do_basic_command (conn, tmpstring);
- g_free (tmpstring);
-
- if (IS_300 (conn->response_code)) {
- tmpstring = g_strdup_printf ("PASS %s", pass);
- result = do_basic_command (conn, tmpstring);
- g_free (tmpstring);
- }
+ result = ftp_login(conn, user, pass);
if (result != GNOME_VFS_OK) {
/* login failed */
@@ -592,6 +605,7 @@
gnome_vfs_uri_unref (conn->uri);
g_string_free (conn->response_buffer, TRUE);
g_free (conn);
+
return result;
}
@@ -860,7 +874,7 @@
GnomeVFSContext *context)
{
FtpConnection *conn = (FtpConnection * )method_handle;
-
+ GnomeVFSResult result;
#if 0
/*
if (conn->operation != FTP_READ) {
@@ -870,7 +884,11 @@
g_print ("do_read (%p)\n", method_handle);
#endif
- return gnome_vfs_iobuf_read (conn->data_iobuf, buffer, num_bytes, bytes_read);
+ result = gnome_vfs_iobuf_read (conn->data_iobuf, buffer, num_bytes, bytes_read);
+ if (*bytes_read == 0) {
+ result = GNOME_VFS_ERROR_EOF;
+ }
+ return result;
}
static GnomeVFSResult
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]