* 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.
Этот коммит содержится в:
родитель
129df509f9
Коммит
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>
|
2002-07-10 Pavel Roskin <proski@gnu.org>
|
||||||
|
|
||||||
* tcputil.h: Move use_netrc declaration ...
|
* 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 FTP_COMMAND_PORT 21
|
||||||
#define HSC_PROXY_PORT 9875
|
#define HSC_PROXY_PORT 9875
|
||||||
|
|
||||||
#define my_get_host_and_username(path, host, user, port, pass) \
|
static void
|
||||||
vfs_split_url (path, host, user, port, pass, FTP_COMMAND_PORT, URL_DEFAULTANON)
|
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 */
|
/* Returns a reply code, check /usr/include/arpa/ftp.h for possible values */
|
||||||
static int
|
static int
|
||||||
@ -428,11 +454,8 @@ login_server (vfs *me, vfs_s_super *super, const char *netrcpass)
|
|||||||
#if defined(HSC_PROXY)
|
#if defined(HSC_PROXY)
|
||||||
char *p;
|
char *p;
|
||||||
int port;
|
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, " ",
|
p = g_strconcat (_(" Proxy: Password required for "), proxyname, " ",
|
||||||
NULL);
|
NULL);
|
||||||
proxypass = vfs_get_password (p);
|
proxypass = vfs_get_password (p);
|
||||||
@ -646,12 +669,14 @@ ftpfs_get_proxy_host_and_port (char *proxy, char **host, int *port)
|
|||||||
char *user, *dir;
|
char *user, *dir;
|
||||||
|
|
||||||
#if defined(HSC_PROXY)
|
#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
|
#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
|
#endif
|
||||||
|
|
||||||
g_free (user);
|
if (user)
|
||||||
|
g_free (user);
|
||||||
|
|
||||||
if (dir)
|
if (dir)
|
||||||
g_free (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;
|
char *host, *user, *password;
|
||||||
int port;
|
int port;
|
||||||
|
|
||||||
op = vfs_split_url (strchr(op, ':')+1, &host, &user, &port, &password, FTP_COMMAND_PORT, URL_DEFAULTANON);
|
ftp_split_url (strchr (op, ':') + 1, &host, &user, &port, &password);
|
||||||
|
|
||||||
if (op)
|
|
||||||
g_free (op);
|
|
||||||
|
|
||||||
SUP.host = host;
|
SUP.host = host;
|
||||||
SUP.user = user;
|
SUP.user = user;
|
||||||
@ -802,22 +824,14 @@ open_archive (vfs *me, vfs_s_super *super, char *archive_name, char *op)
|
|||||||
SUP.home = NULL;
|
SUP.home = NULL;
|
||||||
SUP.proxy= 0;
|
SUP.proxy= 0;
|
||||||
SUP.use_proxy = ftpfs_check_proxy (host);
|
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_passive_connection = ftpfs_use_passive_connections | source_route;
|
||||||
SUP.use_source_route = 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.isbinary = TYPE_UNKNOWN;
|
||||||
SUP.remote_is_amiga = 0;
|
SUP.remote_is_amiga = 0;
|
||||||
super->name = g_strdup("/");
|
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));
|
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);
|
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)
|
archive_same(vfs *me, vfs_s_super *super, char *archive_name, char *op, void *cookie)
|
||||||
{
|
{
|
||||||
char *host, *user;
|
char *host, *user;
|
||||||
char *pass = NULL;
|
|
||||||
int port;
|
int port;
|
||||||
|
|
||||||
op = vfs_split_url (strchr(op, ':')+1, &host, &user, &port, 0, 21, URL_DEFAULTANON);
|
ftp_split_url (strchr(op, ':') + 1, &host, &user, &port, 0);
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
port = ((strcmp (host, SUP.host) == 0) &&
|
port = ((strcmp (host, SUP.host) == 0) &&
|
||||||
(strcmp (user, SUP.user) == 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);
|
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)
|
static int ftpfs_fh_open (vfs *me, vfs_s_fh *fh, int flags, int mode)
|
||||||
{
|
{
|
||||||
fh->u.ftp.append = 0;
|
fh->u.ftp.append = 0;
|
||||||
|
@ -53,12 +53,13 @@
|
|||||||
* ftp://joe@foo.edu:11321/private
|
* ftp://joe@foo.edu:11321/private
|
||||||
* ftp://joe:password@foo.se
|
* ftp://joe:password@foo.se
|
||||||
*
|
*
|
||||||
* If the user is empty, e.g. ftp://@roxanne/private, then your login name
|
* Returns malloc()ed host, user and pass they are present.
|
||||||
* is supplied.
|
* 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.
|
* Return value is a malloc()ed string with the pathname relative to the
|
||||||
* returns a malloced strings with the pathname relative to the host.
|
* host.
|
||||||
* */
|
*/
|
||||||
|
|
||||||
char *vfs_split_url (const char *path, char **host, char **user,
|
char *vfs_split_url (const char *path, char **host, char **user,
|
||||||
int *port, char **pass, int default_port, int flags)
|
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 *retval;
|
||||||
char *pcopy = g_strdup (path);
|
char *pcopy = g_strdup (path);
|
||||||
char *pend = pcopy + strlen (pcopy);
|
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)
|
if (pass)
|
||||||
*pass = NULL;
|
*pass = NULL;
|
||||||
@ -97,7 +95,7 @@ char *vfs_split_url (const char *path, char **host, char **user,
|
|||||||
if (at){
|
if (at){
|
||||||
*at = 0;
|
*at = 0;
|
||||||
inner_colon = strchr (pcopy, ':');
|
inner_colon = strchr (pcopy, ':');
|
||||||
if (inner_colon){
|
if (inner_colon) {
|
||||||
*inner_colon = 0;
|
*inner_colon = 0;
|
||||||
inner_colon++;
|
inner_colon++;
|
||||||
if (pass)
|
if (pass)
|
||||||
@ -105,11 +103,6 @@ char *vfs_split_url (const char *path, char **host, char **user,
|
|||||||
}
|
}
|
||||||
if (*pcopy != 0)
|
if (*pcopy != 0)
|
||||||
*user = g_strdup (pcopy);
|
*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)
|
if (pend == at+1)
|
||||||
rest = at;
|
rest = at;
|
||||||
@ -118,22 +111,17 @@ char *vfs_split_url (const char *path, char **host, char **user,
|
|||||||
} else
|
} else
|
||||||
rest = pcopy;
|
rest = pcopy;
|
||||||
|
|
||||||
/* dummy user to be replaced in lookup_netrc() in ftpfs.c */
|
if (!*user && !(flags & URL_ALLOW_ANON)) {
|
||||||
if (!*user && (default_is_netrc == 1))
|
passwd_info = getpwuid (geteuid ());
|
||||||
*user = g_strdup ("*netrc*");
|
if (passwd_info && passwd_info->pw_name)
|
||||||
|
*user = g_strdup (passwd_info->pw_name);
|
||||||
if (!*user){
|
|
||||||
if (default_is_anon)
|
|
||||||
*user = g_strdup ("anonymous");
|
|
||||||
else {
|
else {
|
||||||
if ((passwd_info = getpwuid (geteuid ())) == NULL)
|
/* This is very unlikely to happen */
|
||||||
*user = g_strdup ("anonymous");
|
*user = g_strdup ("anonymous");
|
||||||
else {
|
|
||||||
*user = g_strdup (passwd_info->pw_name);
|
|
||||||
}
|
|
||||||
endpwent ();
|
|
||||||
}
|
}
|
||||||
|
endpwent ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if the host comes with a port spec, if so, chop it */
|
/* Check if the host comes with a port spec, if so, chop it */
|
||||||
colon = strchr (rest, ':');
|
colon = strchr (rest, ':');
|
||||||
if (colon){
|
if (colon){
|
||||||
|
@ -319,6 +319,11 @@ extern int vfs_parse_filedate(int idx, time_t *t);
|
|||||||
|
|
||||||
extern void vfs_die (char *msg);
|
extern void vfs_die (char *msg);
|
||||||
extern char *vfs_get_password (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,
|
extern char *vfs_split_url (const char *path, char **host, char **user,
|
||||||
int *port, char **pass, int default_port, int flags);
|
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);
|
const char *user);
|
||||||
#endif /* WITH_SMBFS */
|
#endif /* WITH_SMBFS */
|
||||||
|
|
||||||
#define URL_DEFAULTANON 1
|
|
||||||
#define URL_NOSLASH 2
|
|
||||||
extern void vfs_print_stats (const char *fs_name, const char *action,
|
extern void vfs_print_stats (const char *fs_name, const char *action,
|
||||||
const char *file_name, off_t have, off_t need);
|
const char *file_name, off_t have, off_t need);
|
||||||
|
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user