4.5.99a (mc-2002-04-26-03) .netrc patch
Thomas Zajic
zlatko at gmx.at
Thu May 9 00:44:33 UTC 2002
Hi Andrew!
* Andrew V. Samoilov <kai at cmail.ru>, 08/05/2002, 09:50
> Can you add -p option to diff. It makes patches more readable.
Done. Complete patch against mc-4.5.99a-2002-05-08-13 attached, applies
and compiles cleanly without warnings.
> > + if (*login != NULL) {
> > + if (!strncmp(*login, "*netrc*", 7))
>
> Sorry, but I don't understand, why do you use strncmp instead of simple
> strcmp?
No particular reason, just a personal preference. Whenever one of the
strings to compare has a fixed known length, I usually use strncmp()
instead of strcmp(). Feel free to change it back if you like strcmp()
better. ;-)
Bye,
Thomas
PS: it's okay to reply only to the list - I'm subscribed to mc-devel,
so there's no need to cc: me in addition to that, and it would save
me a couple of duplicate mails.
--
=-------------------------------------------------------------------------=
- Thomas "ZlatkO" Zajic <zlatko at gmx.at> Linux-2.4.18 & Mutt-1.2.5.1i -
- "It is not easy to cut through a human head with a hacksaw." (M. C.) -
=-------------------------------------------------------------------------=
-------------- next part --------------
diff -urp mc-4.5.99a-orig/src/boxes.c mc-4.5.99a/src/boxes.c
--- mc-4.5.99a-orig/src/boxes.c Mon Oct 1 15:30:24 2001
+++ mc-4.5.99a/src/boxes.c Thu May 9 02:09:19 2002
@@ -716,9 +716,18 @@ tree_box (char *current_dir)
#ifdef USE_VFS
#if defined(USE_NETCODE)
+#if defined(USE_NETRC)
+#define VFSY 15
+#define VFS_WIDGETBASE 8
+#define NETRC_OFFSET 1
+#else
#define VFSY 14
+#define VFS_WIDGETBASE 7
+#define NETRC_OFFSET 0
+#endif
#else
#define VFSY 8
+#define VFS_WIDGETBASE 0
#endif
#define VFSX 56
@@ -741,18 +750,16 @@ static char *ret_ftp_proxy;
static int ret_use_netrc;
#endif
-#if 0
-/* Not used currently */
-{ quick_checkbox, 4, VFSX, 10, VFSY, "Use ~/.netrc",
- 'U', 0, 0, &ret_use_netrc, 0, "" },
-#endif
-
static QuickWidget confvfs_widgets [] = {
{ quick_button, 30, VFSX, VFSY - 3, VFSY, N_("&Cancel"),
0, B_CANCEL, 0, 0, "button-cancel" },
{ quick_button, 12, VFSX, VFSY - 3, VFSY, N_("&Ok"),
0, B_ENTER, 0, 0, "button-ok" },
#if defined(USE_NETCODE)
+#if defined(USE_NETRC)
+{ quick_checkbox, 4, VFSX, 10, VFSY, N_("&Use ~/.netrc"), 0, 0,
+ &ret_use_netrc, 0, "check-use-netrc" },
+#endif
{ quick_input, 4, VFSX, 9, VFSY, "", 48, 0, 0, &ret_ftp_proxy,
"input-ftp-proxy" },
{ quick_checkbox, 4, VFSX, 8, VFSY, N_("&Always use ftp proxy"), 0, 0,
@@ -780,12 +787,6 @@ static QuickWidget confvfs_widgets [] =
static QuickDialog confvfs_dlg =
{ VFSX, VFSY, -1, -1, N_(" Virtual File System Setting "), "[Virtual FS]", "quick_vfs", confvfs_widgets, 0 };
-#if defined(USE_NETCODE)
-#define VFS_WIDGETBASE 7
-#else
-#define VFS_WIDGETBASE 0
-#endif
-
void
configure_vfs (void)
{
@@ -799,9 +800,9 @@ configure_vfs (void)
#if defined(USE_NETCODE)
ret_use_netrc = use_netrc;
g_snprintf(buffer3, sizeof (buffer3), "%i", ftpfs_directory_timeout);
- confvfs_widgets[5].text = buffer3;
- confvfs_widgets[7].text = ftpfs_anonymous_passwd;
- confvfs_widgets[2].text = ftpfs_proxy_host;
+ confvfs_widgets[5 + NETRC_OFFSET].text = buffer3;
+ confvfs_widgets[7 + NETRC_OFFSET].text = ftpfs_anonymous_passwd;
+ confvfs_widgets[2 + NETRC_OFFSET].text = ftpfs_proxy_host;
#endif
if (quick_dialog (&confvfs_dlg) != B_CANCEL) {
diff -urp mc-4.5.99a-orig/vfs/ftpfs.c mc-4.5.99a/vfs/ftpfs.c
--- mc-4.5.99a-orig/vfs/ftpfs.c Fri Feb 8 15:25:59 2002
+++ mc-4.5.99a/vfs/ftpfs.c Thu May 9 02:09:19 2002
@@ -162,6 +162,9 @@ static int command (vfs *me, vfs_s_super
__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);
+#ifdef USE_NETRC
+int lookup_netrc (char *host, char **login, char **pass);
+#endif
static char *
translate_path (vfs *me, vfs_s_super *super, const char *remote_path)
@@ -812,6 +815,12 @@ open_archive (vfs *me, vfs_s_super *supe
super->root = vfs_s_new_inode (me, super, vfs_s_default_stat(me, S_IFDIR | 0755));
if (password)
SUP.password = password;
+#ifdef USE_NETRC
+ /* try to get user and/or password from ~/.netrc */
+ else if (use_netrc)
+ lookup_netrc(SUP.host, &SUP.user, &SUP.password);
+#endif
+
return open_archive_int (me, super);
}
@@ -819,6 +828,9 @@ static int
archive_same(vfs *me, vfs_s_super *super, char *archive_name, char *op, void *cookie)
{
char *host, *user;
+#ifdef USE_NETRC
+ char *pass = NULL;
+#endif
int port;
op = vfs_split_url (strchr(op, ':')+1, &host, &user, &port, 0, 21, URL_DEFAULTANON);
@@ -826,6 +838,12 @@ archive_same(vfs *me, vfs_s_super *super
if (op)
g_free (op);
+#ifdef USE_NETRC
+ /* replace the dummy user with the one from ~/.netrc */
+ if (use_netrc && !strncmp(user, "*netrc*", 7))
+ lookup_netrc(SUP.host, &user, &pass);
+#endif
+
port = ((strcmp (host, SUP.host) == 0) &&
(strcmp (user, SUP.user) == 0) &&
(port == SUP.port));
@@ -1872,13 +1890,16 @@ int lookup_netrc (char *host, char **log
} *rup_cache = NULL, *rupp;
for (rupp = rup_cache; rupp != NULL; rupp = rupp->next)
- if (!strcmp (host, rupp->host)) {
- if (rupp->login != NULL)
- *login = g_strdup (rupp->login);
- if (rupp->pass != NULL)
- *pass = g_strdup (rupp->pass);
- return 0;
- }
+ /* 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);
+ return 0;
+ }
netrcname = concat_dir_and_file (home_dir, ".netrc");
netrcp = netrc = load_file (netrcname);
if (netrc == NULL) {
@@ -1906,7 +1927,8 @@ int lookup_netrc (char *host, char **log
switch (keyword) {
case 3:
if (netrc_next ()) {
- if (*login == NULL)
+ /* replace the dummy user with the one from ~/.netrc */
+ if ((*login == NULL) || !strncmp(*login, "*netrc*", 7))
*login = g_strdup (buffer);
else if (strcmp (*login, buffer))
keyword = 20;
@@ -1951,8 +1973,12 @@ int lookup_netrc (char *host, char **log
rupp->host = g_strdup (host);
rupp->login = rupp->pass = 0;
- if (*login != NULL)
+ if (*login != NULL) {
+ if (!strncmp(*login, "*netrc*", 7))
+ /* 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;
diff -urp mc-4.5.99a-orig/vfs/utilvfs.c mc-4.5.99a/vfs/utilvfs.c
--- mc-4.5.99a-orig/vfs/utilvfs.c Fri Aug 3 12:12:18 2001
+++ mc-4.5.99a/vfs/utilvfs.c Thu May 9 02:09:19 2002
@@ -69,6 +69,10 @@ char *vfs_split_url (const char *path, c
char *pcopy = g_strdup (path);
char *pend = pcopy + strlen (pcopy);
int default_is_anon = flags & URL_DEFAULTANON;
+#ifdef USE_NETRC
+ /* get user from ~/.netrc if we're supposed to */
+ int default_is_netrc = use_netrc;
+#endif
if (pass)
*pass = NULL;
@@ -103,8 +107,13 @@ char *vfs_split_url (const char *path, c
}
if (*pcopy != 0)
*user = g_strdup (pcopy);
- else
+ else {
default_is_anon = 0;
+#ifdef USE_NETRC
+ /* don't lookup ~/.netrc, use login name instead */
+ default_is_netrc = 0;
+#endif
+ }
if (pend == at+1)
rest = at;
@@ -112,6 +121,12 @@ char *vfs_split_url (const char *path, c
rest = at + 1;
} else
rest = pcopy;
+
+#ifdef USE_NETRC
+ /* dummy user to be replaced in lookup_netrc() in ftpfs.c */
+ if (!*user && (default_is_netrc == 1))
+ *user = g_strdup ("*netrc*");
+#endif
if (!*user){
if (default_is_anon)
diff -urp mc-4.5.99a-orig/vfs/utilvfs.h mc-4.5.99a/vfs/utilvfs.h
--- mc-4.5.99a-orig/vfs/utilvfs.h Mon Jun 25 23:34:46 2001
+++ mc-4.5.99a/vfs/utilvfs.h Thu May 9 02:09:19 2002
@@ -3,3 +3,7 @@
#include "../src/tty.h" /* enable/disable interrupt key */
#include "../src/background.h"
#include "../src/main.h"
+
+#ifdef USE_NETRC
+extern int use_netrc;
+#endif
More information about the mc-devel
mailing list