]> diplodocus.org Git - nmh/blobdiff - sbr/ruserpass.c
showfile.c: Move interface to own file.
[nmh] / sbr / ruserpass.c
index 43784d528d02158c3050a90e88dfb836d613162d..55694c82747fb56c705ea64a9f068a9f24860654 100644 (file)
@@ -1,4 +1,5 @@
-/*
+/* ruserpass.c -- parse .netrc-format file.
+ *
  * Portions of this code are
  * Copyright (c) 1985 Regents of the University of California.
  * All rights reserved.
  * distribution for complete copyright information.
  */
 
-#include <h/mh.h>
-#include <h/utils.h>
+#include "h/mh.h"
+#include "getpass.h"
+#include "ruserpass.h"
+#include "credentials.h"
+#include "error.h"
+#include "h/utils.h"
 #include <pwd.h>
 
 static FILE *cfile;
@@ -63,7 +68,7 @@ static int token(char *);
 void
 ruserpass(const char *host, char **aname, char **apass, int flags)
 {
-    int t, usedefault = 0;
+    int t;
     struct stat stb;
 
     init_credentials_file ();
@@ -76,11 +81,12 @@ ruserpass(const char *host, char **aname, char **apass, int flags)
         char tokval[MAX_TOKVAL_SIZE];
         tokval[0] = '\0';
 
+        bool usedefault = false;
        while ((t = token(tokval))) {
            switch(t) {
            case DEFAULT:
-               usedefault = 1;
-               /* FALL THROUGH */
+               usedefault = true;
+               /* FALLTHRU */
 
            case MACH:
                if (!usedefault) {
@@ -107,9 +113,9 @@ ruserpass(const char *host, char **aname, char **apass, int flags)
                            (stb.st_mode & 077) != 0) {
                            /* We make this a fatal error to force the
                               user to correct it. */
-                            advise(NULL, "group or other permissions, %#o, "
+                            inform("group or other permissions, %#o, "
                                 "forbidden: %s", stb.st_mode, credentials_file);
-                           adios(NULL, "Remove password or correct file "
+                           die("Remove password or correct file "
                                  "permissions.");
                        }
                        if (token(tokval) && *apass == 0)
@@ -147,10 +153,10 @@ ruserpass(const char *host, char **aname, char **apass, int flags)
        }
        printf("Name (%s:%s): ", host, myname);
 
-       if (fgets(tmp, sizeof(tmp) - 1, stdin) == NULL) {
+       if (fgets(tmp, sizeof tmp, stdin) == NULL) {
            advise ("tmp", "fgets");
        }
-        TrimSuffixC(tmp, '\n');
+        trim_suffix_c(tmp, '\n');
        if (*tmp != '\0' || myname == NULL) {
            myname = tmp;
        }
@@ -209,7 +215,7 @@ token(char *tokval)
 
         *cp++ = c;
         if (cp - tokval > MAX_TOKVAL_SIZE-1) {
-            adios(NULL, "credential tokens restricted to length %d",
+            die("credential tokens restricted to length %d",
                   MAX_TOKVAL_SIZE - 1);
         }
     }
@@ -217,7 +223,7 @@ token(char *tokval)
 
     for (t = toktabs; t->tokstr; t++)
        if (!strcmp(t->tokstr, tokval))
-           return (t->tval);
+           return t->tval;
 
-    return (ID);
+    return ID;
 }