]> diplodocus.org Git - nmh/blobdiff - sbr/ruserpass.c
Another pass at cleaning up (some of) the manpages.
[nmh] / sbr / ruserpass.c
index 3c8565fdbf1b21c2ecb58edd78ae9231f47a6df3..7038cf5ce4ac87a2f15e0ce8150c5d24343c9c2d 100644 (file)
@@ -34,7 +34,7 @@ static FILE *cfile;
 #define        ID      10
 #define        MACH    11
 
-static char tokval[100];
+#define MAX_TOKVAL_SIZE 1024
 
 struct toktab {
     char *tokstr;
@@ -55,7 +55,7 @@ static struct toktab toktabs[] = {
 /*
  * prototypes
  */
-static int token(void);
+static int token(char *);
 
 
 void
@@ -71,7 +71,10 @@ ruserpass(char *host, char **aname, char **apass)
        if (errno != ENOENT)
            perror (credentials_file);
     } else {
-       while ((t = token())) {
+        char tokval[MAX_TOKVAL_SIZE];
+        tokval[0] = '\0';
+
+       while ((t = token(tokval))) {
            switch(t) {
            case DEFAULT:
                usedefault = 1;
@@ -79,7 +82,7 @@ ruserpass(char *host, char **aname, char **apass)
 
            case MACH:
                if (!usedefault) {
-                   if (token() != ID)
+                   if (token(tokval) != ID)
                        continue;
                    /*
                     * Allow match either for user's host name.
@@ -89,10 +92,10 @@ ruserpass(char *host, char **aname, char **apass)
                    continue;
                }
            match:
-               while ((t = token()) && t != MACH && t != DEFAULT) {
+               while ((t = token(tokval)) && t != MACH && t != DEFAULT) {
                    switch(t) {
                    case LOGIN:
-                       if (token() && *aname == 0) {
+                       if (token(tokval) && *aname == 0) {
                            *aname = mh_xmalloc((size_t) strlen(tokval) + 1);
                            strcpy(*aname, tokval);
                        }
@@ -108,7 +111,7 @@ ruserpass(char *host, char **aname, char **apass)
                            adios(NULL, "Remove password or correct file "
                                  "permissions.");
                        }
-                       if (token() && *apass == 0) {
+                       if (token(tokval) && *apass == 0) {
                            *apass = mh_xmalloc((size_t) strlen(tokval) + 1);
                            strcpy(*apass, tokval);
                        }
@@ -145,9 +148,11 @@ ruserpass(char *host, char **aname, char **apass)
        }
        printf("Name (%s:%s): ", host, myname);
 
-       fgets(tmp, sizeof(tmp) - 1, stdin);
+       if (fgets(tmp, sizeof(tmp) - 1, stdin) == NULL) {
+           advise ("tmp", "fgets");
+       }
        tmp[strlen(tmp) - 1] = '\0';
-       if (*tmp != '\0') {
+       if (*tmp != '\0' || myname == NULL) {
            myname = tmp;
        }
 
@@ -161,7 +166,7 @@ ruserpass(char *host, char **aname, char **apass)
 
        snprintf(prompt, sizeof(prompt), "Password (%s:%s): ", host, *aname);
        mypass = nmh_getpass(prompt);
-       
+
        if (*mypass == '\0') {
            mypass = *aname;
        }
@@ -173,7 +178,7 @@ ruserpass(char *host, char **aname, char **apass)
 }
 
 static int
-token(void)
+token(char *tokval)
 {
     char *cp;
     int c;
@@ -192,6 +197,10 @@ token(void)
            if (c == '\\')
                c = getc(cfile);
            *cp++ = c;
+            if (cp - tokval > MAX_TOKVAL_SIZE-1) {
+                adios(NULL, "credential tokens restricted to length %d",
+                      MAX_TOKVAL_SIZE - 1);
+            }
        }
     } else {
        *cp++ = c;
@@ -200,6 +209,10 @@ token(void)
            if (c == '\\')
                c = getc(cfile);
            *cp++ = c;
+            if (cp - tokval > MAX_TOKVAL_SIZE-1) {
+                adios(NULL, "credential tokens restricted to length %d",
+                      MAX_TOKVAL_SIZE - 1);
+            }
        }
     }
     *cp = 0;