]> diplodocus.org Git - nmh/blobdiff - sbr/ruserpass.c
Hoist test of search string for NULL out of loop.
[nmh] / sbr / ruserpass.c
index 7038cf5ce4ac87a2f15e0ce8150c5d24343c9c2d..610f32a5c3b9c16d6f6821a3f0695525f86c9707 100644 (file)
@@ -59,7 +59,7 @@ static int token(char *);
 
 
 void
-ruserpass(char *host, char **aname, char **apass)
+ruserpass(const char *host, char **aname, char **apass, int flags)
 {
     int t, usedefault = 0;
     struct stat stb;
@@ -95,14 +95,13 @@ ruserpass(char *host, char **aname, char **apass)
                while ((t = token(tokval)) && t != MACH && t != DEFAULT) {
                    switch(t) {
                    case LOGIN:
-                       if (token(tokval) && *aname == 0) {
-                           *aname = mh_xmalloc((size_t) strlen(tokval) + 1);
-                           strcpy(*aname, tokval);
-                       }
+                       if (token(tokval) && *aname == 0)
+                            *aname = mh_xstrdup(tokval);
                        break;
 
                    case PASSWD:
-                       if (fstat(fileno(cfile), &stb) >= 0 &&
+                       if (!credentials_no_perm_check &&
+                           fstat(fileno(cfile), &stb) >= 0 &&
                            (stb.st_mode & 077) != 0) {
                            /* We make this a fatal error to force the
                               user to correct it. */
@@ -111,10 +110,8 @@ ruserpass(char *host, char **aname, char **apass)
                            adios(NULL, "Remove password or correct file "
                                  "permissions.");
                        }
-                       if (token(tokval) && *apass == 0) {
-                           *apass = mh_xmalloc((size_t) strlen(tokval) + 1);
-                           strcpy(*apass, tokval);
-                       }
+                       if (token(tokval) && *apass == 0)
+                            *apass = mh_xstrdup(tokval);
                        break;
 
                    case ACCOUNT:
@@ -136,7 +133,7 @@ ruserpass(char *host, char **aname, char **apass)
        }
     }
 
-    if (!*aname) {
+    if (!*aname && ! (flags & RUSERPASS_NO_PROMPT_USER)) {
        char tmp[80];
        char *myname;
 
@@ -151,16 +148,15 @@ ruserpass(char *host, char **aname, char **apass)
        if (fgets(tmp, sizeof(tmp) - 1, stdin) == NULL) {
            advise ("tmp", "fgets");
        }
-       tmp[strlen(tmp) - 1] = '\0';
+        TrimSuffixC(tmp, '\n');
        if (*tmp != '\0' || myname == NULL) {
            myname = tmp;
        }
 
-       *aname = mh_xmalloc((size_t) strlen(myname) + 1);
-       strcpy (*aname, myname);
+        *aname = mh_xstrdup(myname);
     }
 
-    if (!*apass) {
+    if (!*apass && ! (flags & RUSERPASS_NO_PROMPT_PASSWORD)) {
        char prompt[256];
        char *mypass;
 
@@ -171,8 +167,7 @@ ruserpass(char *host, char **aname, char **apass)
            mypass = *aname;
        }
 
-       *apass = mh_xmalloc((size_t) strlen(mypass) + 1);
-       strcpy (*apass, mypass);
+        *aname = mh_xstrdup(mypass);
     }
 
 }