]> git.cameronkatri.com Git - pw-darwin.git/blobdiff - chpass/chpass.c
Properly initialise with content of pw.conf(5) that was mistakenly ignored.
[pw-darwin.git] / chpass / chpass.c
index 22ca2ac7d1301ad6340e01189a1c7cbc13728de5..9f9be5335a682376d0d8063669fbae7f20d45670 100644 (file)
  * SUCH DAMAGE.
  */
 
+#if 0
 #ifndef lint
 static const char copyright[] =
 "@(#) Copyright (c) 1988, 1993, 1994\n\
        The Regents of the University of California.  All rights reserved.\n";
 #endif /* not lint */
 
-#if 0
 #ifndef lint
 static char sccsid[] = "@(#)chpass.c   8.4 (Berkeley) 4/2/94";
 #endif /* not lint */
 #endif
-
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
 #include <sys/param.h>
-#include <sys/stat.h>
-#include <sys/signal.h>
-#include <sys/time.h>
-#include <sys/resource.h>
 
-#include <ctype.h>
 #include <err.h>
 #include <errno.h>
-#include <fcntl.h>
 #include <pwd.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -82,13 +75,11 @@ int master_mode;
 static void    baduser(void);
 static void    usage(void);
 
-char localhost[] = "localhost";
-
 int
 main(int argc, char *argv[])
 {
        enum { NEWSH, LOADENTRY, EDITENTRY, NEWPW, NEWEXP } op;
-       struct passwd *pw = NULL, lpw, *old_pw;
+       struct passwd lpw, *old_pw, *pw;
        int ch, pfd, tfd;
        const char *password;
        char *arg = NULL;
@@ -98,6 +89,7 @@ main(int argc, char *argv[])
        const char *yp_domain = NULL, *yp_host = NULL;
 #endif
 
+       pw = old_pw = NULL;
        op = EDITENTRY;
 #ifdef YP
        while ((ch = getopt(argc, argv, "a:p:s:e:d:h:loy")) != -1)
@@ -166,7 +158,7 @@ main(int argc, char *argv[])
        }
 
 #ifdef YP
-       if ((pw->pw_fields & _PWF_SOURCE) == _PWF_NIS) {
+       if (pw != NULL && (pw->pw_fields & _PWF_SOURCE) == _PWF_NIS) {
                ypclnt = ypclnt_new(yp_domain, "passwd.byname", yp_host);
                master_mode = (ypclnt != NULL &&
                    ypclnt_connect(ypclnt) != -1 &&
@@ -225,7 +217,12 @@ main(int argc, char *argv[])
                pw_fini();
                if (pw == NULL)
                        err(1, "edit()");
-               if (pw_equal(old_pw, pw))
+               /* 
+                * pw_equal does not check for crypted passwords, so we
+                * should do it explicitly
+                */
+               if (pw_equal(old_pw, pw) && 
+                   strcmp(old_pw->pw_passwd, pw->pw_passwd) == 0)
                        errx(0, "user information unchanged");
        }
 
@@ -244,8 +241,11 @@ main(int argc, char *argv[])
 #ifdef YP
        case _PWF_NIS:
                ypclnt = ypclnt_new(yp_domain, "passwd.byname", yp_host);
-               if (ypclnt == NULL ||
-                   ypclnt_connect(ypclnt) == -1 ||
+               if (ypclnt == NULL) {
+                       warnx("ypclnt_new failed");
+                       exit(1);
+               }
+               if (ypclnt_connect(ypclnt) == -1 ||
                    ypclnt_passwd(ypclnt, pw, password) == -1) {
                        warnx("%s", ypclnt->error);
                        ypclnt_free(ypclnt);
@@ -294,7 +294,7 @@ usage(void)
 {
 
        (void)fprintf(stderr,
-           "Usage: chpass%s %s [user]\n",
+           "usage: chpass%s %s [user]\n",
 #ifdef YP
            " [-d domain] [-h host]",
 #else