Mercurial > gftp.yaz
changeset 124:65048c959029
2003-4-6 Brian Masney <masneyb@gftp.org>
* lib/config_file.c src/text/gftp-text.c - changed arguments of
gftp_read_config_file() and gftp_read_bookmarks() to take an argument
to the path of the global config directory. The text/gtk+ port will
just pass SHARE_DIR. The native MacOS X port that is in the works
needs this (Nathan Robertson is currently working on this port)
* lib/gftp.h lib/config_file.c - removed config variable type
gftp_option_type_textarray
* lib/gftp.h lib/config_file.c - removed copy_function from
gftp_option_type_var. This is implemented with memcpy() instead
* lib/rfc959.c - remember to rename all instances of firewall_* to
ftp_proxy_*
* lib/sshv2.c - improved generating the argument list for the ssh
client
* lib/sshv2.c lib/misc.c lib/gftp.h - added len argument to
ptym_open()
* lib/protocols.c lib/misc.c lib/config_file.c - use g_strdup()
instead of g_malloc()/strcpy()
author | masneyb |
---|---|
date | Tue, 08 Apr 2003 01:43:33 +0000 |
parents | dd65e3fbd058 |
children | b875de05c22d |
files | ChangeLog lib/config_file.c lib/gftp.h lib/misc.c lib/protocols.c lib/rfc959.c lib/sshv2.c src/text/gftp-text.c |
diffstat | 8 files changed, 281 insertions(+), 277 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Sun Apr 06 15:38:27 2003 +0000 +++ b/ChangeLog Tue Apr 08 01:43:33 2003 +0000 @@ -1,3 +1,76 @@ +2003-4-6 Brian Masney <masneyb@gftp.org> + * lib/config_file.c src/text/gftp-text.c - changed arguments of + gftp_read_config_file() and gftp_read_bookmarks() to take an argument + to the path of the global config directory. The text/gtk+ port will + just pass SHARE_DIR. The native MacOS X port that is in the works + needs this (Nathan Robertson is currently working on this port) + + * lib/gftp.h lib/config_file.c - removed config variable type + gftp_option_type_textarray + + * lib/gftp.h lib/config_file.c - removed copy_function from + gftp_option_type_var. This is implemented with memcpy() instead + + * lib/rfc959.c - remember to rename all instances of firewall_* to + ftp_proxy_* + + * lib/sshv2.c - improved generating the argument list for the ssh + client + + * lib/sshv2.c lib/misc.c lib/gftp.h - added len argument to + ptym_open() + + * lib/protocols.c lib/misc.c lib/config_file.c - use g_strdup() + instead of g_malloc()/strcpy() + +2003-4-5 Brian Masney <masneyb@gftp.org> + * lib/config_file.c lib/options.h lib/gftp.h lib/rfc959.c + lib/rfc2068.c lib/ssh.c - added new internal configuration interface. + Rather than having a global variable for each option, I have a global + hash table (gftp_global_options_htable) that I can look up option names + by name using gftp_lookup_global_option(). I also an options hash + associated with a request structure, so I will be able to call + gftp_lookup_request_option(). I will be able to override options with + bookmarks or while transfers are in progress very easily now. Also, all + options no longer have to appear in config_file.c, the per protocol + options can appear inside their own file + + * lib/gftp.h lib/bookmarks.c lib/local.c lib/rfc959.c lib/rfc2068.c - + remove set_data_type and protocol name from struct gftp_request + + * lib/rfc959.c - renamed all firewall_* variables to ftp_proxy_* in + the config file + + * lib/gftp.h lib/protocols.c lib/rfc959.c - renamed all GFTP_TYPE_* + vars to GFTP_DIRTYPE_* + + * lib/gftp.h - removed ascii field and renamed the node pointer to + user_data in struct gftp_file. In gftp_request, removed any setting + that is now stored in the global/local hash tables. Added + register_module() pointer that will be called whenever the protocol is + first loaded into gftp + + * lib/rfc959.c src/text/gftp-text.c - moved the ascii/binary + translation to rfc959.c. Also, moved any instance of automatically + setting the data type to rfc959.c as well. + + * lib/misc.c lib/sshv2.c - moved all ssh functions from misc.c to + sshv2.c. I had these origionally in misc.c because I used to have 2 + different SSH protocols + + * lib/protocols.c src/text/gftp-text.c - added gftp_calc_kbs() to += protocols.c. This no longer needs to be in the different ports + + * src/text/gftp-text.c - read/write options based on new configuration + interface + + * Use new configuration interface in all source files + + * Updated copyright dates on all source files + + * Note: GTK+ port is completely broken at the moment. I'll upload + those changes whenever I get them done + 2003-04-05 Duarte Loreto <happyguy_pt@hotmail.com> * configure.in: Added "pt" to ALL_LINGUAS. @@ -524,7 +597,7 @@ * cvsclean - added this script - * *.[ch] - added $Id: ChangeLog,v 1.65 2003/04/05 02:25:40 dnloreto Exp $ tags + * *.[ch] - added $Id: ChangeLog,v 1.66 2003/04/08 01:43:31 masneyb Exp $ tags * debian/* - updated files from Debian maintainer
--- a/lib/config_file.c Sun Apr 06 15:38:27 2003 +0000 +++ b/lib/config_file.c Tue Apr 08 01:43:33 2003 +0000 @@ -27,10 +27,7 @@ char *curpos; if (!newentry->protocol) - { - newentry->protocol = g_malloc (4); - strcpy (newentry->protocol, "FTP"); - } + newentry->protocol = g_strdup ("FTP"); /* We have to create the folders. For example, if we have Debian Sites/Debian, we have to create a Debian Sites entry */ @@ -54,8 +51,7 @@ /* Allocate the individual folder. We have to do this for the edit bookmarks feature */ folderentry = g_malloc0 (sizeof (*folderentry)); - folderentry->path = g_malloc (strlen (newentry->path) + 1); - strcpy (folderentry->path, newentry->path); + folderentry->path = g_strdup (newentry->path); folderentry->prev = preventry; folderentry->isfolder = 1; g_hash_table_insert (gftp_bookmarks_htable, folderentry->path, @@ -110,7 +106,7 @@ static void -gftp_read_bookmarks (void) +gftp_read_bookmarks (char *global_data_path) { char *tempstr, *temp1str, buf[255], *curpos; gftp_bookmarks_var * newentry; @@ -126,7 +122,7 @@ if (access (tempstr, F_OK) == -1) { - temp1str = g_strdup_printf ("%s/bookmarks", SHARE_DIR); + temp1str = g_strdup_printf ("%s/bookmarks", global_data_path); if (access (temp1str, F_OK) == -1) { printf (_("Warning: Cannot find master bookmark file %s\n"), @@ -161,8 +157,7 @@ { newentry = g_malloc0 (sizeof (*newentry)); for (; buf[len - 1] == ' ' || buf[len - 1] == ']'; buf[--len] = '\0'); - newentry->path = g_malloc (len); - strcpy (newentry->path, buf + 1); + newentry->path = g_strdup (buf + 1); newentry->isfolder = 0; gftp_add_bookmark (newentry); } @@ -171,8 +166,7 @@ curpos = buf + 9; if (newentry->hostname) g_free (newentry->hostname); - newentry->hostname = g_malloc (strlen (curpos) + 1); - strcpy (newentry->hostname, curpos); + newentry->hostname = g_strdup (curpos); } else if (strncmp (buf, "port", 4) == 0 && newentry) newentry->port = strtol (buf + 5, NULL, 10); @@ -181,40 +175,35 @@ curpos = buf + 9; if (newentry->protocol) g_free (newentry->protocol); - newentry->protocol = g_malloc (strlen (curpos) + 1); - strcpy (newentry->protocol, curpos); + newentry->protocol = g_strdup (curpos); } else if (strncmp (buf, "remote directory", 16) == 0 && newentry) { curpos = buf + 17; if (newentry->remote_dir) g_free (newentry->remote_dir); - newentry->remote_dir = g_malloc (strlen (curpos) + 1); - strcpy (newentry->remote_dir, curpos); + newentry->remote_dir = g_strdup (curpos); } else if (strncmp (buf, "local directory", 15) == 0 && newentry) { curpos = buf + 16; if (newentry->local_dir) g_free (newentry->local_dir); - newentry->local_dir = g_malloc (strlen (curpos) + 1); - strcpy (newentry->local_dir, curpos); + newentry->local_dir = g_strdup (curpos); } else if (strncmp (buf, "username", 8) == 0 && newentry) { curpos = buf + 9; if (newentry->user) g_free (newentry->user); - newentry->user = g_malloc (strlen (curpos) + 1); - strcpy (newentry->user, curpos); + newentry->user = g_strdup (curpos); } else if (strncmp (buf, "password", 8) == 0 && newentry) { curpos = buf + 9; if (newentry->pass) g_free (newentry->pass); - newentry->pass = g_malloc (strlen (curpos) + 1); - strcpy (newentry->pass, curpos); + newentry->pass = g_strdup (curpos); newentry->save_password = *newentry->pass != '\0'; } else if (strncmp (buf, "account", 7) == 0 && newentry) @@ -222,16 +211,14 @@ curpos = buf + 8; if (newentry->acct) g_free (newentry->acct); - newentry->acct = g_malloc (strlen (curpos) + 1); - strcpy (newentry->acct, curpos); + newentry->acct = g_strdup (curpos); } else if (strncmp (buf, "sftpserv_path", 13) == 0 && newentry) { curpos = buf + 14; if (newentry->sftpserv_path) g_free (newentry->sftpserv_path); - newentry->sftpserv_path = g_malloc (strlen (curpos) + 1); - strcpy (newentry->sftpserv_path, curpos); + newentry->sftpserv_path = g_strdup (curpos); } else if (*buf != '#' && *buf != '\0') printf (_("gFTP Warning: Skipping line %d in bookmarks file: %s\n"), @@ -460,7 +447,7 @@ void -gftp_read_config_file (char **argv, int get_xpms) +gftp_read_config_file (char *global_data_path) { char *tempstr, *temp1str, *curpos, buf[255]; gftp_config_list_vars * tmplistvar; @@ -509,7 +496,7 @@ } g_free (temp1str); - temp1str = g_strdup_printf ("%s/gftprc", SHARE_DIR); + temp1str = g_strdup_printf ("%s/gftprc", global_data_path); if (access (temp1str, F_OK) == -1) { printf (_("gFTP Error: Cannot find master config file %s\n"), @@ -611,7 +598,7 @@ gftp_bookmarks->path = g_malloc0 (1); gftp_bookmarks_htable = g_hash_table_new (string_hash_function, string_hash_compare); - gftp_read_bookmarks (); + gftp_read_bookmarks (global_data_path); } @@ -891,14 +878,6 @@ static int -gftp_config_file_copy_text (void *dest, void *src) -{ - *(char **) dest = src; - return (0); -} - - -static int gftp_config_file_read_int (char *str, gftp_config_vars * cv, int line) { cv->value = GINT_TO_POINTER(strtol (str, NULL, 10)); @@ -915,14 +894,6 @@ static int -gftp_config_file_copy_int (void *dest, void *src) -{ - *(int *) dest = GPOINTER_TO_INT(src); - return (0); -} - - -static int gftp_config_file_read_checkbox (char *str, gftp_config_vars * cv, int line) { cv->value = GINT_TO_POINTER(strtol (str, NULL, 10) ? 1 : 0); @@ -947,14 +918,6 @@ static int -gftp_config_file_copy_float (void *dest, void *src) -{ - *(float *) dest = 0.0; /* FIXME */ - return (0); -} - - -static int gftp_config_file_read_color (char *str, gftp_config_vars * cv, int line) { char *red, *green, *blue; @@ -988,14 +951,6 @@ static int -gftp_config_file_copy_color (void *dest, void *src) -{ - *(gftp_color **) dest = src; - return (0); -} - - -static int gftp_config_file_read_intcombo (char *str, gftp_config_vars * cv, int line) { char **clist; @@ -1037,29 +992,20 @@ /* *Note, the index numbers of this array must match up to the numbers in gftp_option_type_enum in gftp.h */ gftp_option_type_var gftp_option_types[] = { - {gftp_config_file_read_text, gftp_config_file_write_text, - NULL, gftp_config_file_copy_text, NULL}, - {NULL, NULL, NULL, NULL, NULL}, /* FIXME _ textarray */ - {gftp_config_file_read_int, gftp_config_file_write_int, - NULL, gftp_config_file_copy_int, NULL}, - {gftp_config_file_read_float, gftp_config_file_write_float, - NULL, gftp_config_file_copy_float, NULL}, - {gftp_config_file_read_checkbox, gftp_config_file_write_int, - NULL, gftp_config_file_copy_int, NULL}, - {gftp_config_file_read_color, gftp_config_file_write_color, - NULL, gftp_config_file_copy_color, NULL}, - {NULL, NULL, NULL, NULL, NULL}, - {NULL, NULL, NULL, NULL, NULL}, - {gftp_config_file_read_text, gftp_config_file_write_hidetext, - NULL, gftp_config_file_copy_text, NULL}, - {NULL, NULL, NULL, NULL, NULL}, - {gftp_config_file_read_text, gftp_config_file_write_text, - NULL, gftp_config_file_copy_text, NULL}, - {NULL, NULL, NULL, NULL, NULL}, - {gftp_config_file_read_intcombo, gftp_config_file_write_intcombo, - NULL, gftp_config_file_copy_int, NULL}, - {NULL, NULL, NULL, NULL, NULL}, - {NULL, NULL, NULL, NULL, NULL} + {gftp_config_file_read_text, gftp_config_file_write_text, NULL, NULL}, + {gftp_config_file_read_int, gftp_config_file_write_int, NULL, NULL}, + {gftp_config_file_read_float, gftp_config_file_write_float, NULL, NULL}, + {gftp_config_file_read_checkbox, gftp_config_file_write_int, NULL, NULL}, + {gftp_config_file_read_color, gftp_config_file_write_color, NULL, NULL}, + {NULL, NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL}, + {gftp_config_file_read_text, gftp_config_file_write_hidetext, NULL, NULL}, + {NULL, NULL, NULL, NULL}, + {gftp_config_file_read_text, gftp_config_file_write_text, NULL, NULL}, + {NULL, NULL, NULL, NULL}, + {gftp_config_file_read_intcombo, gftp_config_file_write_intcombo, NULL, NULL}, + {NULL, NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL} }; @@ -1072,17 +1018,10 @@ if (gftp_global_options_htable != NULL && (tmpconfigvar = g_hash_table_lookup (gftp_global_options_htable, key)) != NULL) - { - if (gftp_option_types[tmpconfigvar->otype].config_copy_function == NULL) - return; - - gftp_option_types[tmpconfigvar->otype].config_copy_function (value, tmpconfigvar->value); - } + memcpy (value, &tmpconfigvar->value, sizeof (value)); else if ((tmplistvar = g_hash_table_lookup (gftp_config_list_htable, key)) != NULL) - { - *(gftp_config_list_vars **) value = tmplistvar; - } + *(gftp_config_list_vars **) value = tmplistvar; else { fprintf (stderr, _("FATAL gFTP Error: Config option '%s' not found in global hash table\n"), key);
--- a/lib/gftp.h Sun Apr 06 15:38:27 2003 +0000 +++ b/lib/gftp.h Tue Apr 08 01:43:33 2003 +0000 @@ -426,20 +426,19 @@ typedef enum { gftp_option_type_text = 0, - gftp_option_type_textarray = 1, - gftp_option_type_int = 2, - gftp_option_type_float = 3, - gftp_option_type_checkbox = 4, - gftp_option_type_color = 5, - gftp_option_type_notebook = 6, - gftp_option_type_newtable = 7, - gftp_option_type_hidetext = 8, - gftp_option_type_label = 9, - gftp_option_type_textbox = 10, - gftp_option_type_subtree = 11, - gftp_option_type_intcombo = 12, - gftp_option_type_charcombo = 13, - gftp_option_type_table = 14 + gftp_option_type_int = 1, + gftp_option_type_float = 2, + gftp_option_type_checkbox = 3, + gftp_option_type_color = 4, + gftp_option_type_notebook = 5, + gftp_option_type_newtable = 6, + gftp_option_type_hidetext = 7, + gftp_option_type_label = 8, + gftp_option_type_textbox = 9, + gftp_option_type_subtree = 10, + gftp_option_type_intcombo = 11, + gftp_option_type_charcombo = 12, + gftp_option_type_table = 13 } gftp_option_type_enum; @@ -484,7 +483,6 @@ int (*read_function) (char *str, gftp_config_vars * cv, int line); int (*write_function) (gftp_config_vars * cv, FILE * fd, int to_config_file); int (*ui_print_function) (char *label, void *ptr, void *user_data); - int (*config_copy_function) (void *dest, void *src); void *user_data; } gftp_option_type_var; @@ -534,8 +532,7 @@ /* config_file.c */ void gftp_add_bookmark ( gftp_bookmarks_var * newentry ); -void gftp_read_config_file ( char **argv, - int get_xpms ); +void gftp_read_config_file ( char *global_data_path ); void gftp_write_bookmarks_file ( void ); @@ -607,7 +604,8 @@ gftp_request * copy_request ( gftp_request * req ); -int ptym_open ( char *pts_name ); +int ptym_open ( char *pts_name, + size_t len ); int ptys_open ( int fdm, char *pts_name );
--- a/lib/misc.c Sun Apr 06 15:38:27 2003 +0000 +++ b/lib/misc.c Tue Apr 08 01:43:33 2003 +0000 @@ -124,8 +124,7 @@ struct passwd *pw; pw = NULL; - str = g_malloc (strlen (src) + 1); - strcpy (str, src); + str = g_strdup (src); if (*str == '~') { @@ -190,10 +189,7 @@ if (pw != NULL) { if ((pos = strchr (newstr, '/')) == NULL) - { - str = g_malloc (strlen (pw->pw_dir) + 1); - strcpy (str, pw->pw_dir); - } + str = g_strdup (pw->pw_dir); else str = g_strconcat (pw->pw_dir, pos, NULL); @@ -568,7 +564,7 @@ int -ptym_open (char *pts_name) +ptym_open (char *pts_name, size_t len) { int fd; @@ -578,7 +574,7 @@ if ((tempstr = _getpty (&fd, O_RDWR, 0600, 0)) == NULL) return (-1); - strcpy (pts_name, tempstr); + strncpy (pts_name, tempstr, len); return (fd); #else /* !__sgi */ @@ -587,7 +583,7 @@ char *tempstr; - strcpy (pts_name, "/dev/ptmx"); + strncpy (pts_name, "/dev/ptmx", len); if ((fd = open (pts_name, O_RDWR)) < 0) return (-1); @@ -609,14 +605,14 @@ return (-1); } - strcpy (pts_name, tempstr); + strncpy (pts_name, tempstr, len); return (fd); #else /* !GRANTPT */ char *pos1, *pos2; - strcpy (pts_name, "/dev/ptyXY"); + strncpy (pts_name, "/dev/ptyXY", len); for (pos1 = "pqrstuvwxyzPQRST"; *pos1 != '\0'; pos1++) { pts_name[8] = *pos1;
--- a/lib/protocols.c Sun Apr 06 15:38:27 2003 +0000 +++ b/lib/protocols.c Tue Apr 08 01:43:33 2003 +0000 @@ -509,14 +509,12 @@ if (i == GFTP_LOCAL_NUM) { - request->directory = g_malloc (strlen (stpos + 6) + 1); - strcpy (request->directory, stpos + 7); + request->directory = g_strdup (stpos + 7); return (0); } for (; *stpos == ' '; stpos++); - str = g_malloc (strlen (stpos) + 1); - strcpy (str, stpos); + str = g_strdup (stpos); for (pos = str + strlen (str) - 1; *pos == ' '; pos--) *pos = '\0'; @@ -583,8 +581,7 @@ if (request->hostname) g_free (request->hostname); - request->hostname = g_malloc (strlen (hostname) + 1); - strcpy (request->hostname, hostname); + request->hostname = g_strdup (hostname); } @@ -596,8 +593,7 @@ if (request->username) g_free (request->username); - request->username = g_malloc (strlen (username) + 1); - strcpy (request->username, username); + request->username = g_strdup (username); } @@ -609,8 +605,7 @@ if (request->password) g_free (request->password); - request->password = g_malloc (strlen (password) + 1); - strcpy (request->password, password); + request->password = g_strdup (password); } @@ -622,8 +617,7 @@ if (request->account) g_free (request->account); - request->account = g_malloc (strlen (account) + 1); - strcpy (request->account, account); + request->account = g_strdup (account); } @@ -640,8 +634,7 @@ { if (request->directory) g_free (request->directory); - request->directory = g_malloc (strlen (directory) + 1); - strcpy (request->directory, directory); + request->directory = g_strdup (directory); } return (0); } @@ -1030,8 +1023,7 @@ char *startpos; startpos = str; - fle->attribs = g_malloc (11); - strcpy (fle->attribs, "----------"); + fle->attribs = g_strdup ("----------"); while (startpos) { startpos++; @@ -1051,12 +1043,9 @@ } if ((startpos = strchr (str, 9)) == NULL) return (GFTP_EFATAL); - fle->file = g_malloc (strlen (startpos)); - strcpy (fle->file, startpos + 1); - fle->user = g_malloc (8); - strcpy (fle->user, _("unknown")); - fle->group = g_malloc (8); - strcpy (fle->group, _("unknown")); + fle->file = g_strdup (startpos + 1); + fle->user = g_strdup (_("unknown")); + fle->group = g_strdup (_("unknown")); return (0); } @@ -1115,18 +1104,14 @@ } else { - fle->group = g_malloc (8); - strcpy (fle->group, _("unknown")); + fle->group = g_strdup (_("unknown")); if (cols == 8) { if ((startpos = copy_token (&fle->user, startpos)) == NULL) return (GFTP_EFATAL); } else - { - fle->user = g_malloc (8); - strcpy (fle->user, _("unknown")); - } + fle->user = g_strdup (_("unknown")); startpos = goto_next_token (startpos); } @@ -1181,9 +1166,8 @@ /* Parse the filename. If this file is a symbolic link, remove the -> part */ if (fle->attribs[0] == 'l' && ((endpos = strstr (startpos, "->")) != NULL)) *(endpos - 1) = '\0'; - fle->file = g_malloc (strlen (startpos) + 1); - strcpy (fle->file, startpos); + fle->file = g_strdup (startpos); /* Uncomment this if you want to strip the spaces off of the end of the file. I don't want to do this by default since there are valid filenames with @@ -1207,24 +1191,20 @@ if ((fle->datetime = parse_time (startpos, &startpos)) == 0) return (GFTP_EFATAL); - /* No such thing on Windoze.. */ - fle->user = g_malloc (8); - strcpy (fle->user, _("unknown")); - fle->group = g_malloc (8); - strcpy (fle->group, _("unknown")); + fle->user = g_strdup (_("unknown")); + fle->group = g_strdup (_("unknown")); startpos = goto_next_token (startpos); - fle->attribs = g_malloc (11); if (startpos[0] == '<') - strcpy (fle->attribs, "drwxrwxrwx"); + fle->attribs = g_strdup ("drwxrwxrwx"); else { - strcpy (fle->attribs, "-rw-rw-rw-"); + fle->attribs = g_strdup ("-rw-rw-rw-"); fle->size = strtol (startpos, NULL, 10); } + startpos = goto_next_token (startpos); - fle->file = g_malloc (strlen (startpos) + 1); - strcpy (fle->file, startpos); + fle->file = g_strdup (startpos); return (0); } @@ -1237,8 +1217,7 @@ if (str[12] != ' ') return (GFTP_EFATAL); str[12] = '\0'; - fle->attribs = g_malloc (13); - strcpy (fle->attribs, str); + fle->attribs = g_strdup (str); startpos = str + 13; while ((*startpos == ' ' || *startpos == '\t') && *startpos != '\0') @@ -1247,8 +1226,7 @@ if ((startpos = copy_token (&fle->user, startpos)) == NULL) return (GFTP_EFATAL); - fle->group = g_malloc (8); - strcpy (fle->group, _("unknown")); + fle->group = g_strdup (_("unknown")); fle->size = strtol (startpos, NULL, 10); @@ -1257,8 +1235,7 @@ return (GFTP_EFATAL); startpos = goto_next_token (startpos); - fle->file = g_malloc (strlen (startpos) + 1); - strcpy (fle->file, startpos); + fle->file = g_strdup (startpos); return (0); } @@ -1273,8 +1250,7 @@ g_return_val_if_fail (lsoutput != NULL, GFTP_EFATAL); g_return_val_if_fail (fle != NULL, GFTP_EFATAL); - str = g_malloc (strlen (lsoutput) + 1); - strcpy (str, lsoutput); + str = g_strdup (lsoutput); memset (fle, 0, sizeof (*fle)); len = strlen (str);
--- a/lib/rfc959.c Sun Apr 06 15:38:27 2003 +0000 +++ b/lib/rfc959.c Tue Apr 08 01:43:33 2003 +0000 @@ -201,21 +201,21 @@ switch (tolower ((int) *(endpos + 2))) { case 'u': - gftp_lookup_request_option (request, "firewall_username", &newval); + gftp_lookup_request_option (request, "ftp_proxy_username", &newval); break; case 'p': - gftp_lookup_request_option (request, "firewall_password", &newval); + gftp_lookup_request_option (request, "ftp_proxy_password", &newval); break; case 'h': - gftp_lookup_request_option (request, "firewall_host", &newval); + gftp_lookup_request_option (request, "ftp_proxy_host", &newval); break; case 'o': - gftp_lookup_request_option (request, "firewall_port", &tmp); + gftp_lookup_request_option (request, "ftp_proxy_port", &tmp); tempport = g_strdup_printf ("%d", tmp); newval = tempport; break; case 'a': - gftp_lookup_request_option (request, "firewall_account", &newval); + gftp_lookup_request_option (request, "ftp_proxy_account", &newval); break; default: endpos++; @@ -416,8 +416,8 @@ parms = request->protocol_data; gftp_lookup_request_option (request, "email", &email); - gftp_lookup_request_option (request, "firewall_host", &proxy_hostname); - gftp_lookup_request_option (request, "firewall_port", &proxy_port); + gftp_lookup_request_option (request, "ftp_proxy_host", &proxy_hostname); + gftp_lookup_request_option (request, "ftp_proxy_port", &proxy_port); if (request->username == NULL || *request->username == '\0') {
--- a/lib/sshv2.c Sun Apr 06 15:38:27 2003 +0000 +++ b/lib/sshv2.c Tue Apr 08 01:43:33 2003 +0000 @@ -32,7 +32,7 @@ gftp_option_type_text, "ssh", NULL, 0, N_("The path to the SSH executable"), GFTP_PORT_ALL, NULL}, {"ssh_extra_params", N_("SSH Extra Params:"), - gftp_option_type_textarray, NULL, NULL, 0, + gftp_option_type_text, NULL, NULL, 0, N_("Extra parameters to pass to the SSH program"), GFTP_PORT_ALL, NULL}, {"ssh2_sftp_path", N_("SSH2 sftp-server path:"), gftp_option_type_text, NULL, NULL, 0, @@ -147,109 +147,110 @@ #define SSH_ERROR_QUESTION -2 #define SSH_WARNING -3 -/* We have the caller send us a pointer to a string so we can write the port - into it. It makes it easier so we don't have to worry about freeing it - later on, the caller can just send us an auto variable, The string - should be at least 6 chars. I know this is messy... */ +static void +sshv2_add_exec_args (char **logstr, size_t *logstr_len, char ***args, + size_t *args_len, size_t *args_cur, char *first, ...) +{ + char tempstr[2048], *curpos, *endpos, save_char; + va_list argp; + int at_end; + + va_start (argp, first); + g_vsnprintf (tempstr, sizeof (tempstr), first, argp); + va_end (argp); + + *logstr_len += strlen (tempstr); + *logstr = g_realloc (*logstr, *logstr_len + 1); + strcat (*logstr, tempstr); + + curpos = tempstr; + while (*curpos == ' ') + curpos++; + + save_char = ' '; + at_end = 0; + while (!at_end) + { + if (*curpos == '"') + { + curpos++; + endpos = strchr (curpos + 1, '"'); + } + else + endpos = strchr (curpos, ' '); + + if (endpos == NULL) + at_end = 1; + else + { + save_char = *endpos; + *endpos = '\0'; + } + + if (*args_cur == *args_len + 1) + { + *args_cur += 10; + *args = g_realloc (*args, sizeof (char *) * *args_cur); + } + + (*args)[(*args_len)++] = g_strdup (curpos); + (*args)[*args_len] = NULL; + + if (!at_end) + { + *endpos = save_char; + curpos = endpos + 1; + while (*curpos == ' ') + curpos++; + } + } +} + static char ** sshv2_gen_exec_args (gftp_request * request, char *execname, - int use_sftp_subsys, char *portstring) + int use_sftp_subsys) { - char **args, *oldstr, *tempstr, *ssh_prog_name, **ssh_extra_params_list; - int i, j, num_ssh_extra_params; - struct servent serv_struct; - - ssh_extra_params_list = NULL; - gftp_lookup_request_option (request, "ssh_extra_params", - &ssh_extra_params_list); + size_t logstr_len, args_len, args_cur; + char **args, *tempstr, *logstr; - num_ssh_extra_params = 0; - if (ssh_extra_params_list != NULL) - { - for (j=0; ssh_extra_params_list[j] != NULL; j++) - { - num_ssh_extra_params++; - } - } - - args = g_malloc (sizeof (char *) * (num_ssh_extra_params + 15)); + gftp_lookup_request_option (request, "ssh_prog_name", &tempstr); + if (tempstr == NULL || *tempstr == '\0') + tempstr = "ssh"; - ssh_prog_name = "ssh"; - gftp_lookup_request_option (request, "ssh_prog_name", &ssh_prog_name); - args[0] = ssh_prog_name; + args_len = 1; + args_cur = 15; + args = g_malloc (sizeof (char *) * args_cur); + args[0] = g_strdup (tempstr); - i = 1; - tempstr = g_strdup (args[0]); - + logstr = g_strdup (args[0]); + logstr_len = strlen (logstr); - if (ssh_extra_params_list != NULL) - { - for (j=0; ssh_extra_params_list[j] != NULL; j++) - { - oldstr = tempstr; - args[i++] = ssh_extra_params_list[j]; - tempstr = g_strconcat (oldstr, " ", ssh_extra_params_list[j], NULL); - g_free (oldstr); - } - } + gftp_lookup_request_option (request, "ssh_extra_params", &tempstr); + if (tempstr != NULL && *tempstr != '\0') + sshv2_add_exec_args (&logstr, &logstr_len, &args, &args_len, &args_cur, + "%s", tempstr); - oldstr = tempstr; - tempstr = g_strconcat (oldstr, " -e none", NULL); - g_free (oldstr); - args[i++] = "-e"; - args[i++] = "none"; + sshv2_add_exec_args (&logstr, &logstr_len, &args, &args_len, &args_cur, + " -e none"); if (request->username && *request->username != '\0') - { - oldstr = tempstr; - tempstr = g_strconcat (oldstr, " -l ", request->username, NULL); - g_free (oldstr); - args[i++] = "-l"; - args[i++] = request->username; - } + sshv2_add_exec_args (&logstr, &logstr_len, &args, &args_len, &args_cur, + " -l %s", request->username); - if (request->port != 0) - { - g_snprintf (portstring, 6, "%d", request->port); - oldstr = tempstr; - tempstr = g_strconcat (oldstr, " -p ", portstring, NULL); - g_free (oldstr); - args[i++] = "-p"; - args[i++] = portstring; - } - else - { - if (!r_getservbyname ("ssh", "tcp", &serv_struct, NULL)) - request->port = 22; - else - request->port = ntohs (serv_struct.s_port); - } + sshv2_add_exec_args (&logstr, &logstr_len, &args, &args_len, &args_cur, + " -p %d", request->port); if (use_sftp_subsys) - { - oldstr = tempstr; - tempstr = g_strconcat (oldstr, " ", request->hostname, " -s sftp", NULL); - g_free (oldstr); - args[i++] = request->hostname; - args[i++] = "-s"; - args[i++] = "sftp"; - args[i] = NULL; - } + sshv2_add_exec_args (&logstr, &logstr_len, &args, &args_len, &args_cur, + " %s -s sftp", request->hostname); else - { - oldstr = tempstr; - tempstr = g_strconcat (oldstr, " ", request->hostname, " \"", execname, - "\"", NULL); - g_free (oldstr); - args[i++] = request->hostname; - args[i++] = execname; - args[i] = NULL; - } + sshv2_add_exec_args (&logstr, &logstr_len, &args, &args_len, &args_cur, + " %s \"%s\"", request->hostname, execname); request->logging_function (gftp_logging_misc, request->user_data, - _("Running program %s\n"), tempstr); - g_free (tempstr); + _("Running program %s\n"), logstr); + g_free (logstr); return (args); } @@ -798,12 +799,23 @@ } +static void +sshv2_free_args (char **args) +{ + int i; + + for (i=0; args[i] != NULL; i++) + g_free (args[i]); + g_free (args); +} + + static int sshv2_connect (gftp_request * request) { int version, fdm, fds, s[2], ret, ssh_use_askpass, sshv2_use_sftp_subsys; - char **args, *tempstr, pts_name[20], *p1, p2, *exepath, port[6], - *ssh2_sftp_path; + char **args, *tempstr, pts_name[20], *p1, p2, *exepath, *ssh2_sftp_path; + struct servent serv_struct; sshv2_message message; pid_t child; @@ -839,9 +851,20 @@ p2 = '/'; } - *port = '\0'; + if (request->port == 0) + { + if (!r_getservbyname ("ssh", "tcp", &serv_struct, NULL)) + { + request->logging_function (gftp_logging_error, request->user_data, + _("Cannot look up service name %s/tcp. Please check your services file\n"), + "ssh"); + } + else + request->port = ntohs (serv_struct.s_port); + } + exepath = g_strdup_printf ("echo -n xsftp ; %s%csftp-server", p1, p2); - args = sshv2_gen_exec_args (request, exepath, sshv2_use_sftp_subsys, port); + args = sshv2_gen_exec_args (request, exepath, sshv2_use_sftp_subsys); if (ssh_use_askpass || sshv2_use_sftp_subsys) { @@ -857,7 +880,7 @@ else { s[0] = s[1] = 0; - if ((fdm = ptym_open (pts_name)) < 0) + if ((fdm = ptym_open (pts_name, sizeof (pts_name))) < 0) { request->logging_function (gftp_logging_error, request->user_data, _("Cannot open master pty %s: %s\n"), pts_name, @@ -911,13 +934,13 @@ !(strlen (tempstr) > 4 && strcmp (tempstr + strlen (tempstr) - 5, "xsftp") == 0)) { - g_free (args); + sshv2_free_args (args); g_free (exepath); return (GFTP_EFATAL); } g_free (tempstr); } - g_free (args); + sshv2_free_args (args); g_free (exepath); request->sockfd = fdm;
--- a/src/text/gftp-text.c Sun Apr 06 15:38:27 2003 +0000 +++ b/src/text/gftp-text.c Tue Apr 08 01:43:33 2003 +0000 @@ -113,14 +113,14 @@ signal (SIGCHLD, sig_child); signal (SIGPIPE, SIG_IGN); - gftp_read_config_file (argv, 0); + gftp_read_config_file (SHARE_DIR); + + if (gftp_parse_command_line (&argc, &argv) != 0) + exit (0); /* SSH doesn't support reading the password with askpass via the command line */ - if (gftp_parse_command_line (&argc, &argv) != 0) - exit (0); - gftp_text_remreq = gftp_request_new (); gftp_set_request_option (gftp_text_remreq, "ssh_use_askpass", GINT_TO_POINTER(0)); @@ -136,7 +136,6 @@ gftp_text_locreq->logging_function = gftp_text_log; gftp_protocols[GFTP_LOCAL_NUM].init (gftp_text_locreq); - startup_directory = ""; gftp_lookup_request_option (gftp_text_locreq, "startup_directory", &startup_directory); if (*startup_directory != '\0')