prettyness police
authorJan-Simon Pendry <pendry@ucbvax.Berkeley.EDU>
Sun, 3 Apr 1994 00:35:29 +0000 (16:35 -0800)
committerJan-Simon Pendry <pendry@ucbvax.Berkeley.EDU>
Sun, 3 Apr 1994 00:35:29 +0000 (16:35 -0800)
SCCS-vsn: usr.bin/passwd/local_passwd.c 8.2
SCCS-vsn: usr.bin/passwd/passwd.c 8.2
SCCS-vsn: usr.bin/passwd/Makefile 8.3
SCCS-vsn: usr.bin/passwd/krb_passwd.c 8.2

usr/src/usr.bin/passwd/Makefile
usr/src/usr.bin/passwd/krb_passwd.c
usr/src/usr.bin/passwd/local_passwd.c
usr/src/usr.bin/passwd/passwd.c

index 99aeae5..744cce7 100644 (file)
@@ -1,4 +1,4 @@
-#      @(#)Makefile    8.2 (Berkeley) %G%
+#      @(#)Makefile    8.3 (Berkeley) %G%
 
 PROG=  passwd
 SRCS=  passwd.c
 
 PROG=  passwd
 SRCS=  passwd.c
index 5aab32d..d76715b 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)krb_passwd.c       8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)krb_passwd.c       8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #ifdef KERBEROS
 #endif /* not lint */
 
 #ifdef KERBEROS
@@ -18,27 +18,39 @@ static char sccsid[] = "@(#)krb_passwd.c    8.1 (Berkeley) %G%";
 #include <netinet/in.h>
 #include <kerberosIV/des.h>
 #include <kerberosIV/krb.h>
 #include <netinet/in.h>
 #include <kerberosIV/des.h>
 #include <kerberosIV/krb.h>
+
+#include <err.h>
+#include <errno.h>
 #include <netdb.h>
 #include <netdb.h>
-#include <signal.h>
 #include <pwd.h>
 #include <pwd.h>
-#include <errno.h>
+#include <signal.h>
 #include <stdio.h>
 #include <stdio.h>
-#include "kpasswd_proto.h"
-#include <string.h>
 #include <stdlib.h>
 #include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "kpasswd_proto.h"
+
+#include "extern.h"
 
 #define        PROTO   "tcp"
 
 
 #define        PROTO   "tcp"
 
+static void    send_update __P((int, char *, char *));
+static void    recv_ack __P((int));
+static void    cleanup __P((void));
+static void    finish __P((void));
+
 static struct timeval timeout = { CLIENT_KRB_TIMEOUT, 0 };
 static struct kpasswd_data proto_data;
 static des_cblock okey;
 static Key_schedule osched;
 static struct timeval timeout = { CLIENT_KRB_TIMEOUT, 0 };
 static struct kpasswd_data proto_data;
 static des_cblock okey;
 static Key_schedule osched;
-KTEXT_ST ticket;
-Key_schedule random_schedule;
-long authopts;
-char realm[REALM_SZ], krbhst[MAX_HSTNM];
-int sock;
+static KTEXT_ST ticket;
+static Key_schedule random_schedule;
+static long authopts;
+static char realm[REALM_SZ], krbhst[MAX_HSTNM];
+static int sock;
 
 
+int
 krb_passwd()
 {
        struct servent *se;
 krb_passwd()
 {
        struct servent *se;
@@ -57,52 +69,47 @@ krb_passwd()
        (void)signal(SIGTSTP, SIG_IGN);
 
        if (setrlimit(RLIMIT_CORE, &rl) < 0) {
        (void)signal(SIGTSTP, SIG_IGN);
 
        if (setrlimit(RLIMIT_CORE, &rl) < 0) {
-               (void)fprintf(stderr,
-                   "passwd: setrlimit: %s\n", strerror(errno));
-               return(1);
+               warn("setrlimit");
+               return (1);
        }
 
        if ((se = getservbyname(SERVICE, PROTO)) == NULL) {
        }
 
        if ((se = getservbyname(SERVICE, PROTO)) == NULL) {
-               (void)fprintf(stderr,
-                   "passwd: couldn't find entry for service %s/%s\n",
+               warnx("couldn't find entry for service %s/%s",
                    SERVICE, PROTO);
                    SERVICE, PROTO);
-               return(1);
+               return (1);
        }
 
        if ((rval = krb_get_lrealm(realm,1)) != KSUCCESS) {
        }
 
        if ((rval = krb_get_lrealm(realm,1)) != KSUCCESS) {
-               (void)fprintf(stderr,
-                   "passwd: couldn't get local Kerberos realm: %s\n",
+               warnx("couldn't get local Kerberos realm: %s",
                    krb_err_txt[rval]);
                    krb_err_txt[rval]);
-               return(1);
+               return (1);
        }
 
        if ((rval = krb_get_krbhst(krbhst, realm, 1)) != KSUCCESS) {
        }
 
        if ((rval = krb_get_krbhst(krbhst, realm, 1)) != KSUCCESS) {
-               (void)fprintf(stderr,
-                   "passwd: couldn't get Kerberos host: %s\n",
+               warnx("couldn't get Kerberos host: %s",
                    krb_err_txt[rval]);
                    krb_err_txt[rval]);
-               return(1);
+               return (1);
        }
 
        if ((host = gethostbyname(krbhst)) == NULL) {
        }
 
        if ((host = gethostbyname(krbhst)) == NULL) {
-               (void)fprintf(stderr,
-                   "passwd: couldn't get host entry for krb host %s\n",
+               warnx("couldn't get host entry for krb host %s",
                    krbhst);
                    krbhst);
-               return(1);
+               return (1);
        }
 
        sin.sin_family = host->h_addrtype;
        }
 
        sin.sin_family = host->h_addrtype;
-       bcopy(host->h_addr, (char *) &sin.sin_addr, host->h_length);
+       memmove((char *) &sin.sin_addr, host->h_addr, host->h_length);
        sin.sin_port = se->s_port;
 
        if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
        sin.sin_port = se->s_port;
 
        if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
-               (void)fprintf(stderr, "passwd: socket: %s\n", strerror(errno));
-               return(1);
+               warn("socket");
+               return (1);
        }
 
        if (connect(sock, (struct sockaddr *) &sin, sizeof(sin)) < 0) {
        }
 
        if (connect(sock, (struct sockaddr *) &sin, sizeof(sin)) < 0) {
-               (void)fprintf(stderr, "passwd: connect: %s\n", strerror(errno));
+               warn("connect");
                (void)close(sock);
                (void)close(sock);
-               return(1);
+               return (1);
        }
 
        rval = krb_sendauth(
        }
 
        rval = krb_sendauth(
@@ -122,9 +129,8 @@ krb_passwd()
        );
 
        if (rval != KSUCCESS) {
        );
 
        if (rval != KSUCCESS) {
-               (void)fprintf(stderr, "passwd: Kerberos sendauth error: %s\n",
-                   krb_err_txt[rval]);
-               return(1);
+               warnx("Kerberos sendauth error: %s", krb_err_txt[rval]);
+               return (1);
        }
 
        krb_get_cred("krbtgt", realm, realm, &cred);
        }
 
        krb_get_cred("krbtgt", realm, realm, &cred);
@@ -134,9 +140,8 @@ krb_passwd()
 
        if (des_read_pw_string(pass,
            sizeof(pass)-1, "Old Kerberos password:", 0)) {
 
        if (des_read_pw_string(pass,
            sizeof(pass)-1, "Old Kerberos password:", 0)) {
-               (void)fprintf(stderr,
-                   "passwd: error reading old Kerberos password\n");
-               return(1);
+               warnx("error reading old Kerberos password");
+               return (1);
        }
 
        (void)des_string_to_key(pass, okey);
        }
 
        (void)des_string_to_key(pass, okey);
@@ -153,23 +158,22 @@ krb_passwd()
 
        if ((rval < 1) || !FD_ISSET(sock, &readfds)) {
                if(rval == 0) {
 
        if ((rval < 1) || !FD_ISSET(sock, &readfds)) {
                if(rval == 0) {
-                       (void)fprintf(stderr, "passwd: timed out (aborted)\n");
+                       warnx("timed out (aborted)");
                        cleanup();
                        cleanup();
-                       return(1);
+                       return (1);
                }
                }
-               (void)fprintf(stderr, "passwd: select failed (aborted)\n");
+               warnx("select failed (aborted)");
                cleanup();
                cleanup();
-               return(1);
+               return (1);
        }
 
        /* read verification string */
 
        if (des_read(sock, &proto_data, sizeof(proto_data)) !=
            sizeof(proto_data)) {
        }
 
        /* read verification string */
 
        if (des_read(sock, &proto_data, sizeof(proto_data)) !=
            sizeof(proto_data)) {
-               (void)fprintf(stderr,
-                   "passwd: couldn't read verification string (aborted)\n");
+               warnx("couldn't read verification string (aborted)");
                cleanup();
                cleanup();
-               return(1);
+               return (1);
        }
 
        (void)signal(SIGHUP, finish);
        }
 
        (void)signal(SIGHUP, finish);
@@ -179,36 +183,33 @@ krb_passwd()
                cleanup();
                /* don't complain loud if user just hit return */
                if (pass == NULL || (!*pass))
                cleanup();
                /* don't complain loud if user just hit return */
                if (pass == NULL || (!*pass))
-                       return(0);
+                       return (0);
                (void)fprintf(stderr, "Sorry\n");
                (void)fprintf(stderr, "Sorry\n");
-               return(1);
+               return (1);
        }
 
        (void)des_key_sched(proto_data.random_key, random_schedule);
        (void)des_set_key(proto_data.random_key, random_schedule);
        }
 
        (void)des_key_sched(proto_data.random_key, random_schedule);
        (void)des_set_key(proto_data.random_key, random_schedule);
-       (void)bzero(pass, sizeof(pass));
+       (void)memset(pass, 0, sizeof(pass));
 
        if (des_read_pw_string(pass,
            sizeof(pass)-1, "New Kerberos password:", 0)) {
 
        if (des_read_pw_string(pass,
            sizeof(pass)-1, "New Kerberos password:", 0)) {
-               (void)fprintf(stderr,
-                   "passwd: error reading new Kerberos password (aborted)\n");
+               warnx("error reading new Kerberos password (aborted)");
                cleanup();
                cleanup();
-               return(1);
+               return (1);
        }
 
        if (des_read_pw_string(password,
            sizeof(password)-1, "Retype new Kerberos password:", 0)) {
        }
 
        if (des_read_pw_string(password,
            sizeof(password)-1, "Retype new Kerberos password:", 0)) {
-               (void)fprintf(stderr,
-                   "passwd: error reading new Kerberos password (aborted)\n");
+               warnx("error reading new Kerberos password (aborted)");
                cleanup();
                cleanup();
-               return(1);
+               return (1);
        }
 
        if (strcmp(password, pass) != 0) {
        }
 
        if (strcmp(password, pass) != 0) {
-               (void)fprintf(stderr,
-                   "passwd: password mismatch (aborted)\n");
+               warnx("password mismatch (aborted)");
                cleanup();
                cleanup();
-               return(1);
+               return (1);
        }
 
        if (strlen(pass) == 0)
        }
 
        if (strlen(pass) == 0)
@@ -225,20 +226,20 @@ krb_passwd()
            select(sock + 1, &readfds, (fd_set *) 0, (fd_set *) 0, &timeout);
        if ((rval < 1) || !FD_ISSET(sock, &readfds)) {
                if(rval == 0) {
            select(sock + 1, &readfds, (fd_set *) 0, (fd_set *) 0, &timeout);
        if ((rval < 1) || !FD_ISSET(sock, &readfds)) {
                if(rval == 0) {
-                       (void)fprintf(stderr,
-                           "passwd: timed out reading ACK (aborted)\n");
+                       warnx("timed out reading ACK (aborted)");
                        cleanup();
                        exit(1);
                }
                        cleanup();
                        exit(1);
                }
-               (void)fprintf(stderr, "passwd: select failed (aborted)\n");
+               warnx("select failed (aborted)");
                cleanup();
                exit(1);
        }
        recv_ack(sock);
        cleanup();
                cleanup();
                exit(1);
        }
        recv_ack(sock);
        cleanup();
-       exit(0);
+       return (0);
 }
 
 }
 
+static void
 send_update(dest, pwd, str)
        int dest;
        char *pwd, *str;
 send_update(dest, pwd, str)
        int dest;
        char *pwd, *str;
@@ -248,14 +249,14 @@ send_update(dest, pwd, str)
        (void)strncpy(ud.secure_msg, str, _PASSWORD_LEN);
        (void)strncpy(ud.pw, pwd, sizeof(ud.pw));
        if (des_write(dest, &ud, sizeof(ud)) != sizeof(ud)) {
        (void)strncpy(ud.secure_msg, str, _PASSWORD_LEN);
        (void)strncpy(ud.pw, pwd, sizeof(ud.pw));
        if (des_write(dest, &ud, sizeof(ud)) != sizeof(ud)) {
-               (void)fprintf(stderr,
-                   "passwd: couldn't write pw update (abort)\n");
-               bzero((char *)&ud, sizeof(ud));
+               warnx("couldn't write pw update (abort)");
+               memset((char *)&ud, 0, sizeof(ud));
                cleanup();
                exit(1);
        }
 }
 
                cleanup();
                exit(1);
        }
 }
 
+static void
 recv_ack(remote)
        int remote;
 {
 recv_ack(remote)
        int remote;
 {
@@ -264,25 +265,27 @@ recv_ack(remote)
 
        cc = des_read(remote, buf, sizeof(buf));
        if (cc <= 0) {
 
        cc = des_read(remote, buf, sizeof(buf));
        if (cc <= 0) {
-               (void)fprintf(stderr,
-                   "passwd: error reading acknowledgement (aborted)\n");
+               warnx("error reading acknowledgement (aborted)");
                cleanup();
                exit(1);
        }
        (void)printf("%s", buf);
 }
 
                cleanup();
                exit(1);
        }
        (void)printf("%s", buf);
 }
 
+static void
 cleanup()
 {
 cleanup()
 {
-       (void)bzero((char *)&proto_data, sizeof(proto_data));
-       (void)bzero((char *)okey, sizeof(okey));
-       (void)bzero((char *)osched, sizeof(osched));
-       (void)bzero((char *)random_schedule, sizeof(random_schedule));
+
+       (void)memset((char *)&proto_data, 0, sizeof(proto_data));
+       (void)memset((char *)okey, 0, sizeof(okey));
+       (void)memset((char *)osched, 0, sizeof(osched));
+       (void)memset((char *)random_schedule, 0, sizeof(random_schedule));
 }
 
 static void
 finish()
 {
 }
 
 static void
 finish()
 {
+
        (void)close(sock);
        exit(1);
 }
        (void)close(sock);
        exit(1);
 }
index 9ace128..8eb0716 100644 (file)
@@ -6,62 +6,52 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)local_passwd.c     8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)local_passwd.c     8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
-#include <pwd.h>
+
+#include <ctype.h>
+#include <err.h>
 #include <errno.h>
 #include <errno.h>
+#include <pwd.h>
 #include <stdio.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
 
 
-uid_t uid;
+#include <pw_copy.h>
+#include <pw_util.h>
 
 
-char *progname = "passwd";
-char *tempname;
+#include "extern.h"
 
 
-local_passwd(uname)
-       char *uname;
-{
-       struct passwd *pw;
-       int pfd, tfd;
-       char *getnewpasswd();
+static uid_t uid;
 
 
-       if (!(pw = getpwnam(uname))) {
-               (void)fprintf(stderr, "passwd: unknown user %s.\n", uname);
-               exit(1);
-       }
+char   *tempname;
 
 
-       uid = getuid();
-       if (uid && uid != pw->pw_uid) {
-               (void)fprintf(stderr, "passwd: %s\n", strerror(EACCES));
-               exit(1);
-       }
-
-       pw_init();
-       pfd = pw_lock();
-       tfd = pw_tmp();
-
-       /*
-        * Get the new password.  Reset passwd change time to zero; when
-        * classes are implemented, go and get the "offset" value for this
-        * class and reset the timer.
-        */
-       pw->pw_passwd = getnewpasswd(pw);
-       pw->pw_change = 0;
-       pw_copy(pfd, tfd, pw);
+static unsigned char itoa64[] =                /* 0 ... 63 => ascii - 64 */
+       "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
 
 
-       if (!pw_mkdb())
-               pw_error((char *)NULL, 0, 1);
-       exit(0);
+void
+to64(s, v, n)
+       char *s;
+       long v;
+       int n;
+{
+       while (--n >= 0) {
+               *s++ = itoa64[v&0x3f];
+               v >>= 6;
+       }
 }
 
 char *
 getnewpasswd(pw)
 }
 
 char *
 getnewpasswd(pw)
-       register struct passwd *pw;
+       struct passwd *pw;
 {
 {
-       register char *p, *t;
        int tries;
        int tries;
-       char buf[_PASSWORD_LEN+1], salt[9], *crypt(), *getpass();
+       char *p, *t;
+       char buf[_PASSWORD_LEN+1], salt[9];
 
        (void)printf("Changing local password for %s.\n", pw->pw_name);
 
 
        (void)printf("Changing local password for %s.\n", pw->pw_name);
 
@@ -101,19 +91,37 @@ getnewpasswd(pw)
 #else
        to64(&salt[0], random(), 2);
 #endif
 #else
        to64(&salt[0], random(), 2);
 #endif
-       return(crypt(buf, salt));
+       return (crypt(buf, salt));
 }
 
 }
 
-static unsigned char itoa64[] =                /* 0 ... 63 => ascii - 64 */
-       "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
-
-to64(s, v, n)
-       register char *s;
-       register long v;
-       register int n;
+int
+local_passwd(uname)
+       char *uname;
 {
 {
-       while (--n >= 0) {
-               *s++ = itoa64[v&0x3f];
-               v >>= 6;
-       }
+       struct passwd *pw;
+       int pfd, tfd;
+
+       if (!(pw = getpwnam(uname)))
+               errx(1, "unknown user %s", uname);
+
+       uid = getuid();
+       if (uid && uid != pw->pw_uid)
+               errx(1, "%s", strerror(EACCES));
+
+       pw_init();
+       pfd = pw_lock();
+       tfd = pw_tmp();
+
+       /*
+        * Get the new password.  Reset passwd change time to zero; when
+        * classes are implemented, go and get the "offset" value for this
+        * class and reset the timer.
+        */
+       pw->pw_passwd = getnewpasswd(pw);
+       pw->pw_change = 0;
+       pw_copy(pfd, tfd, pw);
+
+       if (!pw_mkdb())
+               pw_error((char *)NULL, 0, 1);
+       return (0);
 }
 }
index e0643ad..cfe884f 100644 (file)
@@ -12,68 +12,64 @@ static char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)passwd.c   8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)passwd.c   8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <err.h>
 #include <errno.h>
 #include <stdio.h>
 #include <errno.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <unistd.h>
 
 #include <unistd.h>
 
+#include "extern.h"
+
+void   usage __P((void));
+
 #ifdef KERBEROS
 int use_kerberos = 1;
 #endif
 
 #ifdef KERBEROS
 int use_kerberos = 1;
 #endif
 
+int
 main(argc, argv)
        int argc;
        char **argv;
 {
 main(argc, argv)
        int argc;
        char **argv;
 {
-       extern int optind;
-       register int ch;
+       int ch;
        char *uname;
 
        char *uname;
 
-#ifdef KERBEROS
        while ((ch = getopt(argc, argv, "l")) != EOF)
                switch (ch) {
        while ((ch = getopt(argc, argv, "l")) != EOF)
                switch (ch) {
+#ifdef KERBEROS
                case 'l':               /* change local password file */
                        use_kerberos = 0;
                        break;
                case 'l':               /* change local password file */
                        use_kerberos = 0;
                        break;
-#else
-       while ((ch = getopt(argc, argv, "")) != EOF)
-               switch (ch) {
 #endif
                default:
                case '?':
                        usage();
 #endif
                default:
                case '?':
                        usage();
-                       exit(1);
                }
 
        argc -= optind;
        argv += optind;
 
                }
 
        argc -= optind;
        argv += optind;
 
-       if ((uname = getlogin()) == NULL) {
-               (void)fprintf(stderr, "passwd: getlogin: %s\n",
-                   strerror(errno));
-               exit (1);
-       }
+       if ((uname = getlogin()) == NULL)
+               err(1, "getlogin");
 
        switch(argc) {
        case 0:
                break;
        case 1:
 #ifdef KERBEROS
 
        switch(argc) {
        case 0:
                break;
        case 1:
 #ifdef KERBEROS
-               if (use_kerberos && strcmp(argv[0], uname)) {
-                       (void)fprintf(stderr, "passwd: %s\n\t%s\n%s\n",
-"to change another user's Kerberos password, do",
-"\"kinit user; passwd; kdestroy\";",
-"to change a user's local passwd, use \"passwd -l user\"");
-                       exit(1);
-               }
+               if (use_kerberos && strcmp(argv[0], uname))
+                       errx(1,"%s\n\t%s\n%s\n",
+               "to change another user's Kerberos password, do",
+               "\"kinit user; passwd; kdestroy\";",
+               "to change a user's local passwd, use \"passwd -l user\"");
 #endif
                uname = argv[0];
                break;
        default:
                usage();
 #endif
                uname = argv[0];
                break;
        default:
                usage();
-               exit(1);
        }
 
 #ifdef KERBEROS
        }
 
 #ifdef KERBEROS
@@ -83,11 +79,14 @@ main(argc, argv)
        exit(local_passwd(uname));
 }
 
        exit(local_passwd(uname));
 }
 
+void
 usage()
 {
 usage()
 {
+
 #ifdef KERBEROS
        (void)fprintf(stderr, "usage: passwd [-l] user\n");
 #else
        (void)fprintf(stderr, "usage: passwd user\n");
 #endif
 #ifdef KERBEROS
        (void)fprintf(stderr, "usage: passwd [-l] user\n");
 #else
        (void)fprintf(stderr, "usage: passwd user\n");
 #endif
+       exit(1);
 }
 }