Wed Feb 3 22:27:04 1999 Norbert Warmuth <nwarmuth@privat.circular.de>

* 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  <nwarmuth@privat.circular.de>

* 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 "/".
This commit is contained in:
Norbert Warmuth 1999-02-03 23:19:40 +00:00
parent 06e379de33
commit 04ebcebc1b
7 changed files with 121 additions and 48 deletions

View File

@ -1,3 +1,22 @@
Wed Feb 3 22:27:04 1999 Norbert Warmuth <nwarmuth@privat.circular.de>
* 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 <mc@bat.ru>
* screen.c (to_buffer): Code of the function rewritten, as a side

View File

@ -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);
}

View File

@ -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 */
#endif /* HAVE_MAD */

View File

@ -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);

View File

@ -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;
}

View File

@ -1,3 +1,9 @@
Mon Feb 1 19:32:12 1999 Norbert Warmuth <nwarmuth@privat.circular.de>
* 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 <mc@bat.ru>
* tcputil.c: One more my bug with '\0' -> NULL. Oops..

View File

@ -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;