Sophie

Sophie

distrib > Mandriva > 2009.0 > i586 > by-pkgid > 90db39cc324b70a4dfbda9891d05611e > files > 6

davfs-0.2.4-13mdv2009.0.src.rpm

--- davfs-0.2.4/mount/mount.davfs.c.pix	2002-08-13 22:20:34.000000000 +0200
+++ davfs-0.2.4/mount/mount.davfs.c	2002-08-13 22:25:10.000000000 +0200
@@ -54,6 +54,8 @@
 
 #define AUTOFS
 
+static int passFD_number = -1; 
+
 /* source from samba 2.0 */
 static void exit_parent(int sig)
 {
@@ -299,6 +301,9 @@
  	   strcpy( in_clargs->id, optvalue );
  	 if( !strcmp( optname, "password" ) )
  	   strcpy( in_clargs->pass, optvalue );
+ 	 if( !strcmp( optname, "p" ) ) {     /* read password from given fd */
+	   sscanf(optvalue, "%d", &passFD_number); 
+	 }	 
  	 if( !strcmp( optname, "proxy" ) )
  	   strcpy( in_clargs->proxy, optvalue );
 
@@ -543,6 +548,48 @@
 
     return 0;
 }
+
+/* A function to read the passphrase either from the terminal or from
+ * an open file descriptor -- copied from internat. crypto patch */
+char * xgetpass(const char *prompt)
+{
+        if (passFD_number < 0) /* terminal */
+                return (getpass(prompt));
+        else {       /* file descriptor */
+                char *pass = NULL;
+                int buflen, i;
+
+                buflen=0;
+                for (i=0; ; i++) {
+                        if (i >= buflen-1) {
+                                /* we're running out of space in the buffer. 
+                                 * Make it bigger: */
+                                char *tmppass = pass;
+                                buflen += 128;
+                                pass = realloc(tmppass,buflen);
+                                if (pass == NULL) {
+                                        /* realloc failed. Stop reading _now_. */
+                                        fprintf(stderr,"not enough memory while reading passphrase");
+                                        pass = tmppass; /* the old buffer hasn't changed */
+                                        break;
+                                }
+                        }
+                        if (read(passFD_number, pass+i, 1) != 1 || pass[i] == '\n' )
+                                break;
+                }
+                if (pass == NULL)
+                        return "";
+                else {
+                        pass[i] = 0;
+                        return pass;
+                }
+        }
+}
+
+
+
+
+
 /*
  * Local variables:
  *  c-indent-level: 3
@@ -614,16 +661,10 @@
 
   /* get new passwd if get 404 and no id is specified */
   if (ret == 401 && data.id!=NULL) {
-    char *pass;
-    printf("Connected WEB-DAV server %s\n", url);
-    printf("User Name: ");
-    fgets(data.id, sizeof(data.id) - 1, stdin);
-    strtok(data.id, "\n\r");
-    printf("Password: ");
-    strcpy(data.pass, "");
-    pass = getpass(data.pass);
-    if (pass)
-      strncpy(data.pass, pass, sizeof(data.pass) - 1);
+    char * pass;
+    printf("Connected WEB-DAV server %s for user %s\n", url,data.id);
+    pass = xgetpass("Password: ");
+    strcpy(data.pass, pass);
 
     /* add end slash */
     if (*(url + strlen(url) - 1) != '/')