mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-03 18:14:25 +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>
|
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() -
|
* direntry.c (vfs_s_open): Don't pass O_LINEAR to open() -
|
||||||
this flag is for VFS only, and causes side effects in Cygwin.
|
this flag is for VFS only, and causes side effects in Cygwin.
|
||||||
* extfs.c (extfs_open): Likewise.
|
* extfs.c (extfs_open): Likewise.
|
||||||
|
41
vfs/ftpfs.c
41
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)));
|
__attribute__ ((format (printf, 4, 5)));
|
||||||
static int ftpfs_open_socket (vfs *me, vfs_s_super *super);
|
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 login_server (vfs *me, vfs_s_super *super, const char *netrcpass);
|
||||||
|
static int lookup_netrc (char *host, char **login, char **pass);
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
translate_path (vfs *me, vfs_s_super *super, const char *remote_path)
|
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));
|
super->root = vfs_s_new_inode (me, super, vfs_s_default_stat(me, S_IFDIR | 0755));
|
||||||
if (password)
|
if (password)
|
||||||
SUP.password = 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -821,6 +826,7 @@ 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);
|
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)
|
if (op)
|
||||||
g_free (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) &&
|
||||||
(port == SUP.port));
|
(port == SUP.port));
|
||||||
@ -1861,7 +1871,6 @@ void ftpfs_set_debug (const char *file)
|
|||||||
ftp_data.logfile = logfile;
|
ftp_data.logfile = logfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_NETRC
|
|
||||||
static char buffer[BUF_MEDIUM];
|
static char buffer[BUF_MEDIUM];
|
||||||
static char *netrc, *netrcp;
|
static char *netrc, *netrcp;
|
||||||
|
|
||||||
@ -1923,7 +1932,7 @@ static int netrc_has_incorrect_mode (char * netrcname, char * netrc)
|
|||||||
return 0;
|
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 *netrcname, *tmp;
|
||||||
char hostname[MAXHOSTNAMELEN], *domain;
|
char hostname[MAXHOSTNAMELEN], *domain;
|
||||||
@ -1936,13 +1945,16 @@ int lookup_netrc (char *host, char **login, char **pass)
|
|||||||
} *rup_cache = NULL, *rupp;
|
} *rup_cache = NULL, *rupp;
|
||||||
|
|
||||||
for (rupp = rup_cache; rupp != NULL; rupp = rupp->next)
|
for (rupp = rup_cache; rupp != NULL; rupp = rupp->next)
|
||||||
if (!strcmp (host, rupp->host)) {
|
/* return from cache only if host AND user match! */
|
||||||
if (rupp->login != NULL)
|
if ((!strcmp (host, rupp->host)) &&
|
||||||
*login = g_strdup (rupp->login);
|
(rupp->login != NULL) &&
|
||||||
if (rupp->pass != NULL)
|
(*login != NULL) &&
|
||||||
*pass = g_strdup (rupp->pass);
|
(!strcmp(rupp->login, *login))) {
|
||||||
return 0;
|
*login = g_strdup (rupp->login);
|
||||||
}
|
if (rupp->pass != NULL)
|
||||||
|
*pass = g_strdup (rupp->pass);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
netrcname = concat_dir_and_file (home_dir, ".netrc");
|
netrcname = concat_dir_and_file (home_dir, ".netrc");
|
||||||
netrcp = netrc = load_file (netrcname);
|
netrcp = netrc = load_file (netrcname);
|
||||||
if (netrc == NULL) {
|
if (netrc == NULL) {
|
||||||
@ -1970,7 +1982,8 @@ int lookup_netrc (char *host, char **login, char **pass)
|
|||||||
switch (keyword) {
|
switch (keyword) {
|
||||||
case 3:
|
case 3:
|
||||||
if (netrc_next ()) {
|
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);
|
*login = g_strdup (buffer);
|
||||||
else if (strcmp (*login, buffer))
|
else if (strcmp (*login, buffer))
|
||||||
keyword = 20;
|
keyword = 20;
|
||||||
@ -2015,8 +2028,12 @@ int lookup_netrc (char *host, char **login, char **pass)
|
|||||||
rupp->host = g_strdup (host);
|
rupp->host = g_strdup (host);
|
||||||
rupp->login = rupp->pass = 0;
|
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);
|
rupp->login = g_strdup (*login);
|
||||||
|
}
|
||||||
if (*pass != NULL)
|
if (*pass != NULL)
|
||||||
rupp->pass = g_strdup (*pass);
|
rupp->pass = g_strdup (*pass);
|
||||||
rupp->next = rup_cache;
|
rupp->next = rup_cache;
|
||||||
@ -2024,5 +2041,3 @@ int lookup_netrc (char *host, char **login, char **pass)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* USE_NETRC */
|
|
||||||
|
@ -90,7 +90,6 @@ extern char *ftpfs_proxy_host;
|
|||||||
extern int ftpfs_directory_timeout;
|
extern int ftpfs_directory_timeout;
|
||||||
extern int ftpfs_always_use_proxy;
|
extern int ftpfs_always_use_proxy;
|
||||||
|
|
||||||
extern int use_netrc;
|
|
||||||
extern int ftpfs_retry_seconds;
|
extern int ftpfs_retry_seconds;
|
||||||
extern int ftpfs_use_passive_connections;
|
extern int ftpfs_use_passive_connections;
|
||||||
extern int ftpfs_use_unix_list_options;
|
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);
|
int default_port, int default_to_anon, char **pass);
|
||||||
|
|
||||||
extern int tcp_inited;
|
extern int tcp_inited;
|
||||||
extern int use_netrc;
|
|
||||||
extern int got_sigpipe;
|
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 *pcopy = g_strdup (path);
|
||||||
char *pend = pcopy + strlen (pcopy);
|
char *pend = pcopy + strlen (pcopy);
|
||||||
int default_is_anon = flags & URL_DEFAULTANON;
|
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;
|
||||||
@ -103,8 +105,11 @@ 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
|
else {
|
||||||
default_is_anon = 0;
|
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;
|
||||||
@ -113,6 +118,10 @@ 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 && (default_is_netrc == 1))
|
||||||
|
*user = g_strdup ("*netrc*");
|
||||||
|
|
||||||
if (!*user){
|
if (!*user){
|
||||||
if (default_is_anon)
|
if (default_is_anon)
|
||||||
*user = g_strdup ("anonymous");
|
*user = g_strdup ("anonymous");
|
||||||
|
@ -167,6 +167,7 @@
|
|||||||
#ifdef USE_NETCODE
|
#ifdef USE_NETCODE
|
||||||
void ftpfs_hint_reread(int reread);
|
void ftpfs_hint_reread(int reread);
|
||||||
void ftpfs_flushdir(void);
|
void ftpfs_flushdir(void);
|
||||||
|
extern int use_netrc;
|
||||||
#else
|
#else
|
||||||
# define ftpfs_flushdir()
|
# define ftpfs_flushdir()
|
||||||
# define ftpfs_hint_reread(x)
|
# define ftpfs_hint_reread(x)
|
||||||
|
Loading…
Reference in New Issue
Block a user