file reorg, pathnames.h, paths.h
[unix-history] / usr / src / usr.bin / chpass / field.c
index c3954d8..9144737 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)field.c    5.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)field.c    5.9 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -25,7 +25,7 @@ static char sccsid[] = "@(#)field.c   5.4 (Berkeley) %G%";
 #include <strings.h>
 #include <stdio.h>
 #include <ctype.h>
 #include <strings.h>
 #include <stdio.h>
 #include <ctype.h>
-#include <chpass.h>
+#include "chpass.h"
 #include "pathnames.h"
 
 /* ARGSUSED */
 #include "pathnames.h"
 
 /* ARGSUSED */
@@ -35,18 +35,43 @@ p_login(p, pw, ep)
        struct entry *ep;
 {
        if (!*p) {
        struct entry *ep;
 {
        if (!*p) {
-               fprintf(stderr, "chpass: empty field");
+               (void)fprintf(stderr, "chpass: empty login field.\n");
                return(1);
        }
        if (*p == '-') {
                return(1);
        }
        if (*p == '-') {
-               fprintf(stderr,
+               (void)fprintf(stderr,
                    "chpass: login names may not begin with a hyphen.\n");
                return(1);
        }
        if (!(pw->pw_name = strdup(p))) {
                    "chpass: login names may not begin with a hyphen.\n");
                return(1);
        }
        if (!(pw->pw_name = strdup(p))) {
-               fprintf(stderr, "chpass: can't save entry");
+               (void)fprintf(stderr, "chpass: can't save entry.\n");
                return(1);
        }
                return(1);
        }
+       if (index(p, '.'))
+               (void)fprintf(stderr,
+                   "chpass: \'.\' is dangerous in a login name.\n");
+       for (; *p; ++p)
+               if (isupper(*p)) {
+                       (void)fprintf(stderr,
+                           "chpass: upper-case letters are dangerous in a login name.\n");
+                       break;
+               }
+       return(0);
+}
+
+/* ARGSUSED */
+p_passwd(p, pw, ep)
+       char *p;
+       struct passwd *pw;
+       struct entry *ep;
+{
+       if (!*p)
+               pw->pw_passwd = "";     /* "NOLOGIN"; */
+       else if (!(pw->pw_passwd = strdup(p))) {
+               (void)fprintf(stderr, "chpass: can't save password entry.\n");
+               return(1);
+       }
+       
        return(0);
 }
 
        return(0);
 }
 
@@ -59,16 +84,16 @@ p_uid(p, pw, ep)
        int id;
 
        if (!*p) {
        int id;
 
        if (!*p) {
-               fprintf(stderr, "chpass: empty field");
+               (void)fprintf(stderr, "chpass: empty uid field.\n");
                return(1);
        }
        if (!isdigit(*p)) {
                return(1);
        }
        if (!isdigit(*p)) {
-               fprintf(stderr, "chpass: illegal uid");
+               (void)fprintf(stderr, "chpass: illegal uid.\n");
                return(1);
        }
        id = atoi(p);
        if ((u_int)id > USHRT_MAX) {
                return(1);
        }
        id = atoi(p);
        if ((u_int)id > USHRT_MAX) {
-               fprintf(stderr, "chpass: %d > max uid value (%d)",
+               (void)fprintf(stderr, "chpass: %d > max uid value (%d).\n",
                    id, USHRT_MAX);
                return(1);
        }
                    id, USHRT_MAX);
                return(1);
        }
@@ -86,12 +111,13 @@ p_gid(p, pw, ep)
        int id;
 
        if (!*p) {
        int id;
 
        if (!*p) {
-               fprintf(stderr, "chpass: empty field");
+               (void)fprintf(stderr, "chpass: empty gid field.\n");
                return(1);
        }
        if (!isdigit(*p)) {
                if (!(gr = getgrnam(p))) {
                return(1);
        }
        if (!isdigit(*p)) {
                if (!(gr = getgrnam(p))) {
-                       fprintf(stderr, "chpass: unknown group %s", p);
+                       (void)fprintf(stderr,
+                           "chpass: unknown group %s.\n", p);
                        return(1);
                }
                pw->pw_gid = gr->gr_gid;
                        return(1);
                }
                pw->pw_gid = gr->gr_gid;
@@ -99,7 +125,7 @@ p_gid(p, pw, ep)
        }
        id = atoi(p);
        if ((u_int)id > USHRT_MAX) {
        }
        id = atoi(p);
        if ((u_int)id > USHRT_MAX) {
-               fprintf(stderr, "chpass: %d > max gid value (%d)",
+               (void)fprintf(stderr, "chpass: %d > max gid value (%d).\n",
                    id, USHRT_MAX);
                return(1);
        }
                    id, USHRT_MAX);
                return(1);
        }
@@ -113,14 +139,13 @@ p_class(p, pw, ep)
        struct passwd *pw;
        struct entry *ep;
 {
        struct passwd *pw;
        struct entry *ep;
 {
-       if (!*p) {
-               fprintf(stderr, "chpass: empty field");
-               return(0);
-       }
-       if (!(pw->pw_class = strdup(p))) {
-               fprintf(stderr, "chpass: can't save entry");
+       if (!*p)
+               pw->pw_class = "";
+       else if (!(pw->pw_class = strdup(p))) {
+               (void)fprintf(stderr, "chpass: can't save entry.\n");
                return(1);
        }
                return(1);
        }
+       
        return(0);
 }
 
        return(0);
 }
 
@@ -132,7 +157,7 @@ p_change(p, pw, ep)
 {
        if (!atot(p, &pw->pw_change))
                return(0);
 {
        if (!atot(p, &pw->pw_change))
                return(0);
-       fprintf(stderr, "chpass: illegal date for change field");
+       (void)fprintf(stderr, "chpass: illegal date for change field.\n");
        return(1);
 }
 
        return(1);
 }
 
@@ -144,18 +169,20 @@ p_expire(p, pw, ep)
 {
        if (!atot(p, &pw->pw_expire))
                return(0);
 {
        if (!atot(p, &pw->pw_expire))
                return(0);
-       fprintf(stderr, "chpass: illegal date for expire field");
+       (void)fprintf(stderr, "chpass: illegal date for expire field.\n");
        return(1);
 }
 
 /* ARGSUSED */
        return(1);
 }
 
 /* ARGSUSED */
-p_save(p, pw, ep)
+p_gecos(p, pw, ep)
        char *p;
        struct passwd *pw;
        struct entry *ep;
 {
        char *p;
        struct passwd *pw;
        struct entry *ep;
 {
-       if (*p && !(ep->save = strdup(p))) {
-               fprintf(stderr, "chpass: can't save entry");
+       if (!*p)
+               ep->save = "";
+       else if (!(ep->save = strdup(p))) {
+               (void)fprintf(stderr, "chpass: can't save entry.\n");
                return(1);
        }
        return(0);
                return(1);
        }
        return(0);
@@ -168,11 +195,11 @@ p_hdir(p, pw, ep)
        struct entry *ep;
 {
        if (!*p) {
        struct entry *ep;
 {
        if (!*p) {
-               fprintf(stderr, "chpass: empty field");
+               (void)fprintf(stderr, "chpass: empty home directory field.\n");
                return(1);
        }
        if (!(pw->pw_dir = strdup(p))) {
                return(1);
        }
        if (!(pw->pw_dir = strdup(p))) {
-               fprintf(stderr, "chpass: can't save entry");
+               (void)fprintf(stderr, "chpass: can't save entry.\n");
                return(1);
        }
        return(0);
                return(1);
        }
        return(0);
@@ -197,7 +224,8 @@ p_shell(p, pw, ep)
                        /* only admin can set "restricted" shells */
                        if (!uid)
                                break;
                        /* only admin can set "restricted" shells */
                        if (!uid)
                                break;
-                       fprintf(stderr, "chpass: %s: non-standard shell", p);
+                       (void)fprintf(stderr,
+                           "chpass: %s: non-standard shell.\n", p);
                        return(1);
                }
                if (!strcmp(p, sh))
                        return(1);
                }
                if (!strcmp(p, sh))
@@ -209,7 +237,7 @@ p_shell(p, pw, ep)
                }
        }
        if (!(pw->pw_shell = strdup(p))) {
                }
        }
        if (!(pw->pw_shell = strdup(p))) {
-               fprintf(stderr, "chpass: can't save entry");
+               (void)fprintf(stderr, "chpass: can't save entry.\n");
                return(1);
        }
        return(0);
                return(1);
        }
        return(0);