From 04ebcebc1bb5f552a1d4c62f02f72ab5d3815789 Mon Sep 17 00:00:00 2001 From: Norbert Warmuth Date: Wed, 3 Feb 1999 23:19:40 +0000 Subject: [PATCH] Wed Feb 3 22:27:04 1999 Norbert Warmuth * src/util.c (strip_password): Extented to find the url in the first parameter. The second parameter tells whether it should search the url (indicated by known prefixes) in the first parameter or whether the first parameter is a url without a prefix ("ftp://", "/#ftp:", "/#mc:"). * src/main.c (directory_history_add): Strip the password (if any) from the freshly added value. * src/widget.c (push_history): ditto. There's a ugly special casing necessary for the network and ftp link dialogs (urls are entered with out prefix). * src/widget.c (history_put): Restrict read and write access to the history file to the owner (Just in case I forgot to strip passwords somewhere). Mon Feb 1 19:32:12 1999 Norbert Warmuth * vfs/ftpfs.c (insert_dots): renamed from insert_dot. We have to insert ".." as well or directories from ftp servers which don't list "." and ".." are displayed with an additional "/". --- src/ChangeLog | 19 ++++++++++++ src/main.c | 4 ++- src/util.c | 80 +++++++++++++++++++++++++++++++++------------------ src/util.h | 1 + src/widget.c | 14 +++++++++ vfs/ChangeLog | 6 ++++ vfs/ftpfs.c | 45 +++++++++++++++++------------ 7 files changed, 121 insertions(+), 48 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 6ba21fb12..c5f40cb57 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,22 @@ +Wed Feb 3 22:27:04 1999 Norbert Warmuth + + * util.c (strip_password): Extented to find the url in the first + parameter. The second parameter tells whether it should search the + url (indicated by known prefixes) in the first parameter or whether + the first parameter is a url without a prefix ("ftp://", "/#ftp:", + "/#mc:"). + + * main.c (directory_history_add): Strip the password (if any) from + the freshly added value. + + * widget.c (push_history): ditto. There's a ugly special casing + necessary for the network and ftp link dialogs (urls are entered + with out prefix). + + * widget.c (history_put): Restrict read and write access to the + history file to the owner (Just in case I forgot to strip passwords + somewhere). + Mon Feb 1 00:43:15 1999 Timur Bakeyev * screen.c (to_buffer): Code of the function rewritten, as a side diff --git a/src/main.c b/src/main.c index 13a181ac5..51e4bc345 100644 --- a/src/main.c +++ b/src/main.c @@ -899,6 +899,7 @@ directory_history_add (WPanel * panel, char *s) if (!panel->dir_history) { panel->dir_history = g_new0 (Hist, 1); panel->dir_history->text = g_strdup (s); + strip_password (panel->dir_history->text, 1); return; } if (!strcmp (panel->dir_history->text, s)) @@ -914,7 +915,8 @@ directory_history_add (WPanel * panel, char *s) } panel->dir_history = panel->dir_history->next; panel->dir_history->text = g_strdup (s); - + strip_password (panel->dir_history->text, 1); + panel_update_marks (panel); } diff --git a/src/util.c b/src/util.c index ba846a902..49ac817f8 100644 --- a/src/util.c +++ b/src/util.c @@ -321,27 +321,57 @@ char *string_perm (mode_t mode_bits) return mode; } -static char * -strip_password (char *path) +/* p: string which might contain an url with a password (this parameter is + modified in place). + has_prefix = 0: The first parameter is an url without a prefix + (user[:pass]@]machine[:port][remote-dir). Delete + the password. + has_prefix = 1: Search p for known url prefixes. If found delete + the password from the url. + Cavevat: only the first url is found +*/ +char * +strip_password (char *p, int has_prefix) { + static struct { + char *name; + size_t len; + } prefixes[] = { {"/#ftp:", 6}, + {"/#mc:", 5}, + {"ftp://", 6} + }; char *at, *inner_colon, *dir; + int i; + char *result = p; - if ((dir = strchr (path, PATH_SEP)) != NULL) - *dir = '\0'; - /* search for any possible user */ - at = strchr (path, '@'); + for (i = 0; i < sizeof (prefixes)/sizeof (prefixes[0]); i++) { + char *q; - /* We have a username */ - if (at) { - *at = 0; - inner_colon = strchr (path, ':'); - *at = '@'; - if (inner_colon) - strcpy (inner_colon, at); + if (has_prefix) { + if((q = strstr (p, prefixes[i].name)) == 0) + continue; + else + p = q + prefixes[i].len; + }; + + if ((dir = strchr (p, PATH_SEP)) != NULL) + *dir = '\0'; + /* search for any possible user */ + at = strchr (p, '@'); + + /* We have a username */ + if (at) { + *at = 0; + inner_colon = strchr (p, ':'); + *at = '@'; + if (inner_colon) + strcpy (inner_colon, at); + } + if (dir) + *dir = PATH_SEP; + break; } - if (dir) - *dir = PATH_SEP; - return (path); + return (result); } char *strip_home_and_password(char *dir) @@ -354,17 +384,11 @@ char *strip_home_and_password(char *dir) return newdir; } - /* We do not strip homes in /#ftp tree, I do not like ~'s there (see ftpfs.c why) */ -#define STRIP( name ) \ - if (strstr( dir, name )) { \ - strcpy (newdir, dir); \ - strip_password ( strstr( newdir, name ) + strlen(name) ); \ - return newdir; \ - } - STRIP( "/#ftp:" ); - STRIP( "/#mc:" ); - - return dir; + /* We do not strip homes in /#ftp tree, I do not like ~'s there + (see ftpfs.c why) */ + strcpy (newdir, dir); + strip_password (newdir, 1); + return newdir; } static char *maybe_start_group (char *d, int do_group, int *was_wildcard) @@ -1252,4 +1276,4 @@ mad_strdup_printf (const char *format, ...) return buffer; } -#endif /* HAVE_MAD */ \ No newline at end of file +#endif /* HAVE_MAD */ diff --git a/src/util.h b/src/util.h index b26719c44..d2217812d 100644 --- a/src/util.h +++ b/src/util.h @@ -20,6 +20,7 @@ char *size_trunc (long int size); char *size_trunc_sep (long int size); int is_exe (mode_t mode); char *string_perm (mode_t mode_bits); +char *strip_password (char *path, int has_prefix); char *strip_home_and_password(char *dir); char *extension (char *); char *split_extension (char *, int pad); diff --git a/src/widget.c b/src/widget.c index 6a1b496a3..cf0b040a8 100644 --- a/src/widget.c +++ b/src/widget.c @@ -40,6 +40,7 @@ #include "key.h" /* XCTRL and ALT macros */ #include "x.h" #include "profile.h" /* for history loading and saving */ +#include "../vfs/vfs.h" #ifndef HAVE_X # define x_create_button(a,b,c) 1 @@ -942,6 +943,9 @@ void history_put (char *input_name, Hist *h) return; profile = concat_dir_and_file (home_dir, HISTORY_FILE_NAME); + + /* Just in case I forgot to strip passwords somewhere -- Norbert */ + mc_chmod (profile, S_IRUSR | S_IWUSR); while (h->next) /* go to end of list */ h = h->next; @@ -1158,6 +1162,16 @@ push_history (WInput *in, char *text) new->next = 0; new->prev = in->history; new->text = g_strdup (text); +#ifdef HAVE_GNOME + if (strcmp (in->history_name + 4, _(" Link to a remote machine ")) == 0 || + strcmp (in->history_name + 4, _(" FTP to machine ")) == 0) +#else + if (strcmp (in->history_name + 3, _(" Link to a remote machine ")) == 0 || + strcmp (in->history_name + 3, _(" FTP to machine ")) == 0) +#endif + strip_password (new->text, 0); + else + strip_password (new->text, 1); in->history = new; return 2; } diff --git a/vfs/ChangeLog b/vfs/ChangeLog index bc94f230f..f0239028e 100644 --- a/vfs/ChangeLog +++ b/vfs/ChangeLog @@ -1,3 +1,9 @@ +Mon Feb 1 19:32:12 1999 Norbert Warmuth + + * ftpfs.c (insert_dots): renamed from insert_dot. We have to + insert ".." as well or directories from ftp servers which don't + list "." and ".." are displayed with an additional "/". + Mon Feb 1 02:55:07 1999 Timur I. Bakeyev * tcputil.c: One more my bug with '\0' -> NULL. Oops.. diff --git a/vfs/ftpfs.c b/vfs/ftpfs.c index 8c18ddf6e..8b066b6e3 100644 --- a/vfs/ftpfs.c +++ b/vfs/ftpfs.c @@ -1242,8 +1242,8 @@ get_path (struct connection **bucket, char *path) return s_get_path (bucket, path, "/#ftp:"); } -/* Inserts an entry for "." into the linked list. Ignore any errors - because "." isn't important (as fas as you don't try to save a +/* Inserts an entry for "." (and "..") into the linked list. Ignore any + errors because "." isn't important (as fas as you don't try to save a file in the root dir of the ftp server). Actually the dot is needed when stating the root directory, e.g. mc_stat ("/ftp#localhost", &buf). Down the call tree _get_file_entry @@ -1251,26 +1251,32 @@ get_path (struct connection **bucket, char *path) before searching for a fileentry. Whithout "." in the linked list this search fails. -- Norbert. */ static void -insert_dot (struct linklist *file_list, struct connection *bucket) +insert_dots (struct linklist *file_list, struct connection *bucket) { struct direntry *fe; - static char buffer[] = "drwxrwxrwx 1 0 0 1024 Jan 1 1970 ."; + int i; + char buffer[][58] = { + "drwxrwxrwx 1 0 0 1024 Jan 1 1970 .", + "drwxrwxrwx 1 0 0 1024 Jan 1 1970 .." + }; - fe = malloc(sizeof(struct direntry)); - if (fe == NULL) - return; - if (vfs_parse_ls_lga (buffer, &fe->s, &fe->name, &fe->linkname)) { - fe->freshly_created = 0; - fe->count = 1; - fe->local_filename = fe->remote_filename = NULL; - fe->l_stat = NULL; - fe->bucket = bucket; - (fe->s).st_ino = bucket->__inode_counter++; + for (i = 0; i < 2; i++ ) { + fe = malloc(sizeof(struct direntry)); + if (fe == NULL) + return; + if (vfs_parse_ls_lga (buffer[i], &fe->s, &fe->name, &fe->linkname)) { + fe->freshly_created = 0; + fe->count = 1; + fe->local_filename = fe->remote_filename = NULL; + fe->l_stat = NULL; + fe->bucket = bucket; + (fe->s).st_ino = bucket->__inode_counter++; - if (!linklist_insert(file_list, fe)) - free(fe); - } else - free (fe); + if (!linklist_insert(file_list, fe)) + free(fe); + } else + free (fe); + } } static struct dir * @@ -1286,6 +1292,7 @@ retrieve_dir(struct connection *bucket, char *remote_path, int resolve_symlinks) struct dir *dcache; int got_intr = 0; int dot_found = 0; + int dot_dot_found = 0; int has_spaces = (strchr (remote_path, ' ') != NULL); canonicalize_pathname (remote_path); @@ -1443,7 +1450,7 @@ retrieve_dir(struct connection *bucket, char *remote_path, int resolve_symlinks) goto fallback; if (!dot_found) - insert_dot (file_list, bucket); + insert_dots (file_list, bucket); if (!linklist_insert(qdcache(bucket), dcache)) { my_errno = ENOMEM;