mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-03 10:04:32 +03:00
* tcputil.h: Move use_netrc declaration ...
* vfs.h: ... here. * ftpfs.c: Implement .netrc support unconditionally. (lookup_netrc): Make static. * utilvfs.c: Initialize default_is_netrc. From Thomas Zajic <zlatko@gmx.at>
This commit is contained in:
parent
200356c074
commit
2acfb89cd4
@ -1,5 +1,12 @@
|
||||
2002-07-10 Pavel Roskin <proski@gnu.org>
|
||||
|
||||
* tcputil.h: Move use_netrc declaration ...
|
||||
* vfs.h: ... here.
|
||||
* ftpfs.c: Implement .netrc support unconditionally.
|
||||
(lookup_netrc): Make static.
|
||||
* utilvfs.c: Initialize default_is_netrc.
|
||||
From Thomas Zajic <zlatko@gmx.at>
|
||||
|
||||
* direntry.c (vfs_s_open): Don't pass O_LINEAR to open() -
|
||||
this flag is for VFS only, and causes side effects in Cygwin.
|
||||
* extfs.c (extfs_open): Likewise.
|
||||
|
31
vfs/ftpfs.c
31
vfs/ftpfs.c
@ -162,6 +162,7 @@ static int command (vfs *me, vfs_s_super *super, int wait_reply, char *fmt, ...)
|
||||
__attribute__ ((format (printf, 4, 5)));
|
||||
static int ftpfs_open_socket (vfs *me, vfs_s_super *super);
|
||||
static int login_server (vfs *me, vfs_s_super *super, const char *netrcpass);
|
||||
static int lookup_netrc (char *host, char **login, char **pass);
|
||||
|
||||
static char *
|
||||
translate_path (vfs *me, vfs_s_super *super, const char *remote_path)
|
||||
@ -814,6 +815,10 @@ open_archive (vfs *me, vfs_s_super *super, char *archive_name, char *op)
|
||||
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);
|
||||
}
|
||||
|
||||
@ -821,6 +826,7 @@ 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);
|
||||
@ -828,6 +834,10 @@ archive_same(vfs *me, vfs_s_super *super, char *archive_name, char *op, void *co
|
||||
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) &&
|
||||
(strcmp (user, SUP.user) == 0) &&
|
||||
(port == SUP.port));
|
||||
@ -1861,7 +1871,6 @@ void ftpfs_set_debug (const char *file)
|
||||
ftp_data.logfile = logfile;
|
||||
}
|
||||
|
||||
#ifdef USE_NETRC
|
||||
static char buffer[BUF_MEDIUM];
|
||||
static char *netrc, *netrcp;
|
||||
|
||||
@ -1923,7 +1932,7 @@ static int netrc_has_incorrect_mode (char * netrcname, char * netrc)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lookup_netrc (char *host, char **login, char **pass)
|
||||
static int lookup_netrc (char *host, char **login, char **pass)
|
||||
{
|
||||
char *netrcname, *tmp;
|
||||
char hostname[MAXHOSTNAMELEN], *domain;
|
||||
@ -1936,8 +1945,11 @@ int lookup_netrc (char *host, char **login, char **pass)
|
||||
} *rup_cache = NULL, *rupp;
|
||||
|
||||
for (rupp = rup_cache; rupp != NULL; rupp = rupp->next)
|
||||
if (!strcmp (host, rupp->host)) {
|
||||
if (rupp->login != NULL)
|
||||
/* return from cache only if host AND user match! */
|
||||
if ((!strcmp (host, rupp->host)) &&
|
||||
(rupp->login != NULL) &&
|
||||
(*login != NULL) &&
|
||||
(!strcmp(rupp->login, *login))) {
|
||||
*login = g_strdup (rupp->login);
|
||||
if (rupp->pass != NULL)
|
||||
*pass = g_strdup (rupp->pass);
|
||||
@ -1970,7 +1982,8 @@ int lookup_netrc (char *host, char **login, char **pass)
|
||||
switch (keyword) {
|
||||
case 3:
|
||||
if (netrc_next ()) {
|
||||
if (*login == NULL)
|
||||
/* replace the dummy user with the one from ~/.netrc */
|
||||
if ((*login == NULL) || !strcmp(*login, "*netrc*"))
|
||||
*login = g_strdup (buffer);
|
||||
else if (strcmp (*login, buffer))
|
||||
keyword = 20;
|
||||
@ -2015,8 +2028,12 @@ int lookup_netrc (char *host, char **login, char **pass)
|
||||
rupp->host = g_strdup (host);
|
||||
rupp->login = rupp->pass = 0;
|
||||
|
||||
if (*login != NULL)
|
||||
if (*login != NULL) {
|
||||
if (!strcmp(*login, "*netrc*"))
|
||||
/* no match in ~/.netrc, try anonymous */
|
||||
*login = g_strdup("anonymous");
|
||||
rupp->login = g_strdup (*login);
|
||||
}
|
||||
if (*pass != NULL)
|
||||
rupp->pass = g_strdup (*pass);
|
||||
rupp->next = rup_cache;
|
||||
@ -2024,5 +2041,3 @@ int lookup_netrc (char *host, char **login, char **pass)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* USE_NETRC */
|
||||
|
@ -90,7 +90,6 @@ extern char *ftpfs_proxy_host;
|
||||
extern int ftpfs_directory_timeout;
|
||||
extern int ftpfs_always_use_proxy;
|
||||
|
||||
extern int use_netrc;
|
||||
extern int ftpfs_retry_seconds;
|
||||
extern int ftpfs_use_passive_connections;
|
||||
extern int ftpfs_use_unix_list_options;
|
||||
|
@ -25,5 +25,4 @@ char *get_host_and_username (char *path, char **host, char **user, int *port,
|
||||
int default_port, int default_to_anon, char **pass);
|
||||
|
||||
extern int tcp_inited;
|
||||
extern int use_netrc;
|
||||
extern int got_sigpipe;
|
||||
|
@ -69,6 +69,8 @@ char *vfs_split_url (const char *path, char **host, char **user,
|
||||
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;
|
||||
@ -103,8 +105,11 @@ char *vfs_split_url (const char *path, char **host, char **user,
|
||||
}
|
||||
if (*pcopy != 0)
|
||||
*user = g_strdup (pcopy);
|
||||
else
|
||||
else {
|
||||
default_is_anon = 0;
|
||||
/* don't lookup ~/.netrc, use login name instead */
|
||||
default_is_netrc = 0;
|
||||
}
|
||||
|
||||
if (pend == at+1)
|
||||
rest = at;
|
||||
@ -113,6 +118,10 @@ 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");
|
||||
|
Loading…
Reference in New Issue
Block a user