Re: Things to do before 4.6.0



* Pavel Roskin <proski gnu org>, 26/06/2002, 05:17

> This is a list of things that I want to be done before the 4.6.0 release.  
> [...]
> 1) Review the outstanding patches in this list and apply them, unless
> they seem unstable or introduce new features.  Resubmitting of patches
> with more detailed comments would help, but is not required.

Which reminds me: is there any basic problem with my .netrc patch that I'm
probably not aware of (except, maybe, that it isn't exactly a showcase of
extreme elegance in C programming :-)? Is this one of the new features that
will be held back until 4.6.0 has been released, or one of those waiting in
the queue to be reviewed? Or am I really the only one who is using mc *and*
actually finds ~/.netrc useful? Just curious ...

The initial problems [1] have been cleaned up, to the best of my knowledge.
The last discussion [2] concerned the strcpy vs. strncpy (non-)problem. I'll
attach the latest version (which is basically the same as the ones before,
except that it is now against 2002-07-09-16), which applies and compiles
cleanly without warnings (that, and all occurrences of strncpy() have been
replaced by strcpy()).

RFC: as you might know, I'm using "*netrc*" as an internal dummy user name.
While this seems to be a rather unusual user name for a Unix system, I'm
not sure whether it is actually an illegal one as well. Would it be safer
to use ":netrc:" instead (my chown(1) man page tells me that according to
POSIX, a ":" colon is not a valid character in a user name)?

Coming to think of it, I'd probably be better off just using ":netrc:" and
stop worrying (provided that this doesn't break parsing URLs that contain
user name & password ["ftp://user:password host/dir/"], I'd have to look
into that first), but still: what about non-Unix/non-POSIX systems - should
I care?

Any & all comments appreciated.

TIA,
Thomas

[1] http://mail.gnome.org/archives/mc-devel/2002-April/msg00055.html
[2] http://mail.gnome.org/archives/mc-devel/2002-May/msg00006.html
-- 
=-------------------------------------------------------------------------=
-  Thomas "ZlatkO" Zajic    <zlatko gmx at>     Linux-2.4.18 & Mutt-1.4i  -
-  "It is not easy to cut through a human head with a hacksaw."  (M. C.)  -
=-------------------------------------------------------------------------=
diff -urp mc-4.5.99a/src/boxes.c mc-4.5.99a-netrc/src/boxes.c
--- mc-4.5.99a/src/boxes.c	Mon Oct  1 08:51:15 2001
+++ mc-4.5.99a-netrc/src/boxes.c	Wed Jul 10 17:15:51 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/vfs/ftpfs.c mc-4.5.99a-netrc/vfs/ftpfs.c
--- mc-4.5.99a/vfs/ftpfs.c	Wed Jul  3 21:55:39 2002
+++ mc-4.5.99a-netrc/vfs/ftpfs.c	Wed Jul 10 17:15:51 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)
@@ -814,6 +817,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);
 }
 
@@ -821,6 +830,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);
@@ -828,6 +840,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 && !strcmp(user, "*netrc*"))
+	lookup_netrc(SUP.host, &user, &pass);
+#endif
+
     port = ((strcmp (host, SUP.host) == 0) &&
 	    (strcmp (user, SUP.user) == 0) &&
 	    (port == SUP.port));
@@ -1936,13 +1954,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) {
@@ -1970,7 +1991,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) || !strcmp(*login, "*netrc*"))
 			    *login = g_strdup (buffer);
 			else if (strcmp (*login, buffer))
 			    keyword = 20;
@@ -2015,8 +2037,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 (!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;
Only in mc-4.5.99a-netrc/vfs: ftpfs.c~
diff -urp mc-4.5.99a/vfs/utilvfs.c mc-4.5.99a-netrc/vfs/utilvfs.c
--- mc-4.5.99a/vfs/utilvfs.c	Fri Aug  3 12:12:18 2001
+++ mc-4.5.99a-netrc/vfs/utilvfs.c	Wed Jul 10 17:15:51 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/vfs/utilvfs.h mc-4.5.99a-netrc/vfs/utilvfs.h
--- mc-4.5.99a/vfs/utilvfs.h	Mon Jun 25 23:34:46 2001
+++ mc-4.5.99a-netrc/vfs/utilvfs.h	Wed Jul 10 17:15:51 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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]