mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 20:36:50 +03:00
* vfs.h: Rename URL_DEFAULTANON to URL_ALLOW_ANON.
* utilvfs.c (vfs_split_url): Return NULL as username if URL_ALLOW_ANON is set and no username is found in the URL, otherwise use current name. * ftpfs.c (ftp_split_url): New function - split URL and look up username and password if needed. (login_server): Use ftp_split_url(). (archive_same): Likewise.
This commit is contained in:
parent
129df509f9
commit
6ddf5f78ed
@ -1,3 +1,14 @@
|
||||
2002-07-11 Pavel Roskin <proski@gnu.org>
|
||||
|
||||
* vfs.h: Rename URL_DEFAULTANON to URL_ALLOW_ANON.
|
||||
* utilvfs.c (vfs_split_url): Return NULL as username if
|
||||
URL_ALLOW_ANON is set and no username is found in the URL,
|
||||
otherwise use current name.
|
||||
* ftpfs.c (ftp_split_url): New function - split URL and look up
|
||||
username and password if needed.
|
||||
(login_server): Use ftp_split_url().
|
||||
(archive_same): Likewise.
|
||||
|
||||
2002-07-10 Pavel Roskin <proski@gnu.org>
|
||||
|
||||
* tcputil.h: Move use_netrc declaration ...
|
||||
|
122
vfs/ftpfs.c
122
vfs/ftpfs.c
@ -217,8 +217,34 @@ translate_path (vfs *me, vfs_s_super *super, const char *remote_path)
|
||||
#define FTP_COMMAND_PORT 21
|
||||
#define HSC_PROXY_PORT 9875
|
||||
|
||||
#define my_get_host_and_username(path, host, user, port, pass) \
|
||||
vfs_split_url (path, host, user, port, pass, FTP_COMMAND_PORT, URL_DEFAULTANON)
|
||||
static void
|
||||
ftp_split_url(char *path, char **host, char **user, int *port, char **pass)
|
||||
{
|
||||
char *p;
|
||||
char *tmp_pass;
|
||||
|
||||
/* Caller is not interested in password, but the functions below want
|
||||
* a valid pointer */
|
||||
if (!pass) {
|
||||
pass = &tmp_pass;
|
||||
}
|
||||
|
||||
p = vfs_split_url (path, host, user, port, pass, FTP_COMMAND_PORT,
|
||||
URL_ALLOW_ANON);
|
||||
|
||||
if (!*user) {
|
||||
if (use_netrc)
|
||||
lookup_netrc (*host, user, pass);
|
||||
else
|
||||
*user = g_strdup ("anonymous");
|
||||
}
|
||||
|
||||
if (p)
|
||||
g_free (p);
|
||||
|
||||
if (pass == &tmp_pass && *pass)
|
||||
g_free (*pass);
|
||||
}
|
||||
|
||||
/* Returns a reply code, check /usr/include/arpa/ftp.h for possible values */
|
||||
static int
|
||||
@ -428,11 +454,8 @@ login_server (vfs *me, vfs_s_super *super, const char *netrcpass)
|
||||
#if defined(HSC_PROXY)
|
||||
char *p;
|
||||
int port;
|
||||
p = my_get_host_and_username (ftpfs_proxy_host, 0, &proxyname,
|
||||
&port, 0);
|
||||
if (p)
|
||||
g_free (p);
|
||||
|
||||
ftp_split_url (ftpfs_proxy_host, 0, &proxyname, &port, 0);
|
||||
p = g_strconcat (_(" Proxy: Password required for "), proxyname, " ",
|
||||
NULL);
|
||||
proxypass = vfs_get_password (p);
|
||||
@ -646,12 +669,14 @@ ftpfs_get_proxy_host_and_port (char *proxy, char **host, int *port)
|
||||
char *user, *dir;
|
||||
|
||||
#if defined(HSC_PROXY)
|
||||
dir = vfs_split_url (proxy, host, &user, port, 0, HSC_PROXY_PORT, URL_DEFAULTANON);
|
||||
dir = vfs_split_url (proxy, host, &user, port, 0, HSC_PROXY_PORT, URL_ALLOW_ANON);
|
||||
#else
|
||||
dir = vfs_split_url (proxy, host, &user, port, 0, FTP_COMMAND_PORT, URL_DEFAULTANON);
|
||||
dir = vfs_split_url (proxy, host, &user, port, 0, FTP_COMMAND_PORT, URL_ALLOW_ANON);
|
||||
#endif
|
||||
|
||||
g_free (user);
|
||||
if (user)
|
||||
g_free (user);
|
||||
|
||||
if (dir)
|
||||
g_free (dir);
|
||||
}
|
||||
@ -791,10 +816,7 @@ open_archive (vfs *me, vfs_s_super *super, char *archive_name, char *op)
|
||||
char *host, *user, *password;
|
||||
int port;
|
||||
|
||||
op = vfs_split_url (strchr(op, ':')+1, &host, &user, &port, &password, FTP_COMMAND_PORT, URL_DEFAULTANON);
|
||||
|
||||
if (op)
|
||||
g_free (op);
|
||||
ftp_split_url (strchr (op, ':') + 1, &host, &user, &port, &password);
|
||||
|
||||
SUP.host = host;
|
||||
SUP.user = user;
|
||||
@ -802,22 +824,14 @@ open_archive (vfs *me, vfs_s_super *super, char *archive_name, char *op)
|
||||
SUP.home = NULL;
|
||||
SUP.proxy= 0;
|
||||
SUP.use_proxy = ftpfs_check_proxy (host);
|
||||
SUP.password = NULL;
|
||||
SUP.password = password;
|
||||
SUP.use_passive_connection = ftpfs_use_passive_connections | source_route;
|
||||
SUP.use_source_route = source_route;
|
||||
SUP.strict = ftpfs_use_unix_list_options?RFC_AUTODETECT:RFC_STRICT;
|
||||
SUP.strict = ftpfs_use_unix_list_options ? RFC_AUTODETECT : RFC_STRICT;
|
||||
SUP.isbinary = TYPE_UNKNOWN;
|
||||
SUP.remote_is_amiga = 0;
|
||||
super->name = g_strdup("/");
|
||||
#if 0
|
||||
super->name = g_strconcat( "/#ftp:", user, "@", host, "/", NULL );
|
||||
#endif
|
||||
super->root = vfs_s_new_inode (me, super, vfs_s_default_stat(me, S_IFDIR | 0755));
|
||||
if (password)
|
||||
SUP.password = password;
|
||||
/* try to get user and/or password from ~/.netrc */
|
||||
else if (use_netrc)
|
||||
lookup_netrc(SUP.host, &SUP.user, &SUP.password);
|
||||
|
||||
return open_archive_int (me, super);
|
||||
}
|
||||
@ -826,17 +840,9 @@ static int
|
||||
archive_same(vfs *me, vfs_s_super *super, char *archive_name, char *op, void *cookie)
|
||||
{
|
||||
char *host, *user;
|
||||
char *pass = NULL;
|
||||
int port;
|
||||
|
||||
op = vfs_split_url (strchr(op, ':')+1, &host, &user, &port, 0, 21, URL_DEFAULTANON);
|
||||
|
||||
if (op)
|
||||
g_free (op);
|
||||
|
||||
/* replace the dummy user with the one from ~/.netrc */
|
||||
if (use_netrc && !strcmp(user, "*netrc*"))
|
||||
lookup_netrc(SUP.host, &user, &pass);
|
||||
ftp_split_url (strchr(op, ':') + 1, &host, &user, &port, 0);
|
||||
|
||||
port = ((strcmp (host, SUP.host) == 0) &&
|
||||
(strcmp (user, SUP.user) == 0) &&
|
||||
@ -1640,58 +1646,6 @@ static int ftpfs_rmdir (vfs *me, char *path)
|
||||
return send_ftp_command(me, path, "RMD /%s", OPT_FLUSH);
|
||||
}
|
||||
|
||||
#ifdef FIXME_LATER_ALIGATOR
|
||||
static void my_forget (char *file)
|
||||
{
|
||||
struct linklist *l;
|
||||
char *host, *user, *pass, *rp;
|
||||
int port;
|
||||
|
||||
#ifndef BROKEN_PATHS
|
||||
if (strncmp (file, "/#ftp:", 6))
|
||||
return; /* Normal: consider cd /bla/#ftp */
|
||||
#else
|
||||
if (!(file = strstr (file, "/#ftp:")))
|
||||
return;
|
||||
#endif
|
||||
|
||||
file += 6;
|
||||
if (!(rp = my_get_host_and_username (file, &host, &user, &port, &pass))) {
|
||||
g_free (host);
|
||||
g_free (user);
|
||||
if (pass)
|
||||
wipe_password (pass);
|
||||
return;
|
||||
}
|
||||
|
||||
/* we do not care about the path actually */
|
||||
g_free (rp);
|
||||
|
||||
for (l = connections_list->next; l != connections_list; l = l->next){
|
||||
struct connection *bucket = l->data;
|
||||
|
||||
if ((strcmp (host, SUP.host) == 0) &&
|
||||
(strcmp (user, SUP.user) == 0) &&
|
||||
(port == SUP.port)){
|
||||
|
||||
/* close socket: the child owns it now */
|
||||
close (bucket->sock);
|
||||
bucket->sock = -1;
|
||||
|
||||
/* reopen the connection */
|
||||
bucket->sock = ftpfs_open_socket (bucket);
|
||||
if (bucket->sock != -1)
|
||||
login_server (bucket, pass);
|
||||
break;
|
||||
}
|
||||
}
|
||||
g_free (host);
|
||||
g_free (user);
|
||||
if (pass)
|
||||
wipe_password (pass);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int ftpfs_fh_open (vfs *me, vfs_s_fh *fh, int flags, int mode)
|
||||
{
|
||||
fh->u.ftp.append = 0;
|
||||
|
@ -53,12 +53,13 @@
|
||||
* ftp://joe@foo.edu:11321/private
|
||||
* ftp://joe:password@foo.se
|
||||
*
|
||||
* If the user is empty, e.g. ftp://@roxanne/private, then your login name
|
||||
* is supplied.
|
||||
* Returns malloc()ed host, user and pass they are present.
|
||||
* If the user is empty, e.g. ftp://@roxanne/private, and URL_ALLOW_ANON
|
||||
* is not set, then the current login name is supplied.
|
||||
*
|
||||
* returns malloced host if host isn't null, user and pass if pass is not null.
|
||||
* returns a malloced strings with the pathname relative to the host.
|
||||
* */
|
||||
* Return value is a malloc()ed string with the pathname relative to the
|
||||
* host.
|
||||
*/
|
||||
|
||||
char *vfs_split_url (const char *path, char **host, char **user,
|
||||
int *port, char **pass, int default_port, int flags)
|
||||
@ -68,9 +69,6 @@ char *vfs_split_url (const char *path, char **host, char **user,
|
||||
char *retval;
|
||||
char *pcopy = g_strdup (path);
|
||||
char *pend = pcopy + strlen (pcopy);
|
||||
int default_is_anon = flags & URL_DEFAULTANON;
|
||||
/* get user from ~/.netrc if we're supposed to */
|
||||
int default_is_netrc = use_netrc;
|
||||
|
||||
if (pass)
|
||||
*pass = NULL;
|
||||
@ -97,7 +95,7 @@ char *vfs_split_url (const char *path, char **host, char **user,
|
||||
if (at){
|
||||
*at = 0;
|
||||
inner_colon = strchr (pcopy, ':');
|
||||
if (inner_colon){
|
||||
if (inner_colon) {
|
||||
*inner_colon = 0;
|
||||
inner_colon++;
|
||||
if (pass)
|
||||
@ -105,11 +103,6 @@ char *vfs_split_url (const char *path, char **host, char **user,
|
||||
}
|
||||
if (*pcopy != 0)
|
||||
*user = g_strdup (pcopy);
|
||||
else {
|
||||
default_is_anon = 0;
|
||||
/* don't lookup ~/.netrc, use login name instead */
|
||||
default_is_netrc = 0;
|
||||
}
|
||||
|
||||
if (pend == at+1)
|
||||
rest = at;
|
||||
@ -118,22 +111,17 @@ char *vfs_split_url (const char *path, char **host, char **user,
|
||||
} else
|
||||
rest = pcopy;
|
||||
|
||||
/* dummy user to be replaced in lookup_netrc() in ftpfs.c */
|
||||
if (!*user && (default_is_netrc == 1))
|
||||
*user = g_strdup ("*netrc*");
|
||||
|
||||
if (!*user){
|
||||
if (default_is_anon)
|
||||
*user = g_strdup ("anonymous");
|
||||
if (!*user && !(flags & URL_ALLOW_ANON)) {
|
||||
passwd_info = getpwuid (geteuid ());
|
||||
if (passwd_info && passwd_info->pw_name)
|
||||
*user = g_strdup (passwd_info->pw_name);
|
||||
else {
|
||||
if ((passwd_info = getpwuid (geteuid ())) == NULL)
|
||||
*user = g_strdup ("anonymous");
|
||||
else {
|
||||
*user = g_strdup (passwd_info->pw_name);
|
||||
}
|
||||
endpwent ();
|
||||
/* This is very unlikely to happen */
|
||||
*user = g_strdup ("anonymous");
|
||||
}
|
||||
endpwent ();
|
||||
}
|
||||
|
||||
/* Check if the host comes with a port spec, if so, chop it */
|
||||
colon = strchr (rest, ':');
|
||||
if (colon){
|
||||
|
@ -319,6 +319,11 @@ extern int vfs_parse_filedate(int idx, time_t *t);
|
||||
|
||||
extern void vfs_die (char *msg);
|
||||
extern char *vfs_get_password (char *msg);
|
||||
|
||||
/* Flags for vfs_split_url() */
|
||||
#define URL_ALLOW_ANON 1
|
||||
#define URL_NOSLASH 2
|
||||
|
||||
extern char *vfs_split_url (const char *path, char **host, char **user,
|
||||
int *port, char **pass, int default_port, int flags);
|
||||
|
||||
@ -337,8 +342,6 @@ vfs_smb_get_authinfo (const char *host, const char *share, const char *domain,
|
||||
const char *user);
|
||||
#endif /* WITH_SMBFS */
|
||||
|
||||
#define URL_DEFAULTANON 1
|
||||
#define URL_NOSLASH 2
|
||||
extern void vfs_print_stats (const char *fs_name, const char *action,
|
||||
const char *file_name, off_t have, off_t need);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user