]> git.saurik.com Git - apple/system_cmds.git/blobdiff - pwd_mkdb.tproj/pwd_mkdb.c
system_cmds-735.20.1.tar.gz
[apple/system_cmds.git] / pwd_mkdb.tproj / pwd_mkdb.c
index b2daac5d7927b0d9b51d37a756d011a9ff057d3f..7d024228d6cd8754eaea94c61b18487fe8f46d68 100644 (file)
@@ -31,8 +31,9 @@
  * SUCH DAMAGE.
  */
 
+#include <sys/cdefs.h>
 #ifndef lint
-static const char copyright[] =
+__unused static const char copyright[] =
 "@(#) Copyright (c) 1991, 1993, 1994\n\
        The Regents of the University of California.  All rights reserved.\n";
 #endif /* not lint */
@@ -41,7 +42,7 @@ static const char copyright[] =
 #if 0
 static const char sccsid[] = "from: @(#)pwd_mkdb.c     8.5 (Berkeley) 4/20/94";
 #else
-static const char rcsid[] = "$OpenBSD: pwd_mkdb.c,v 1.36 2003/06/08 21:14:55 millert Exp $";
+__unused static const char rcsid[] = "$OpenBSD: pwd_mkdb.c,v 1.36 2003/06/08 21:14:55 millert Exp $";
 #endif
 #endif /* not lint */
 
@@ -62,6 +63,7 @@ static const char rcsid[] = "$OpenBSD: pwd_mkdb.c,v 1.36 2003/06/08 21:14:55 mil
 #include <unistd.h>
 #include <util.h>
 #include <sys/param.h>
+#include "pw_scan.h"
 
 #define        INSECURE        1
 #define        SECURE          2
@@ -75,12 +77,12 @@ static const char rcsid[] = "$OpenBSD: pwd_mkdb.c,v 1.36 2003/06/08 21:14:55 mil
 #define        SHADOW_GROUP    "wheel"
 
 HASHINFO openinfo = {
-       4096,           /* bsize */
-       32,             /* ffactor */
-       256,            /* nelem */
-       2048 * 1024,    /* cachesize */
-       NULL,           /* hash() */
-       0               /* lorder */
+       .bsize = 4096,
+       .ffactor = 32,
+       .nelem = 256,
+       .cachesize = 2048 * 1024,
+       .hash = NULL,
+       .lorder = 0
 };
 
 static char *pname;                            /* password file name */
@@ -108,7 +110,7 @@ main(int argc, char **argv)
        struct passwd pwd;
        struct group *grp;
        sigset_t set;
-       uid_t olduid;
+       uid_t olduid = UID_MAX;
        gid_t shadow;
        int ch, tfd, makeold, secureonly, flags, checkonly;
        char *username, buf[MAX(MAXPATHLEN, LINE_MAX * 2)];
@@ -148,7 +150,7 @@ main(int argc, char **argv)
        if (argc != 1 || (makeold && secureonly) ||
            (username && (*username == '+' || *username == '-')))
                usage();
-       
+
        if ((grp = getgrnam(SHADOW_GROUP)) == NULL)
                errx(1, "cannot find `%s' in the group database, aborting",
                    SHADOW_GROUP);
@@ -192,9 +194,9 @@ main(int argc, char **argv)
 
        /* Tweak openinfo values for large passwd files. */
        if (st.st_size > (off_t)100*1024)
-               openinfo.cachesize = MIN(st.st_size * 20, (off_t)12*1024*1024);
+               openinfo.cachesize = (u_int)MIN(st.st_size * 20, (off_t)12*1024*1024);
        if (st.st_size / 128 > openinfo.nelem)
-               openinfo.nelem = st.st_size / 128;
+               openinfo.nelem = (u_int)(st.st_size / 128);
 
         /* If only updating a single record, stash the old uid */
        if (username) {
@@ -382,13 +384,12 @@ fmt:              errno = EFTYPE; /* XXX */
        return (1);
 }
 
-void                    
-cp(from, to, mode)              
-       char *from, *to;
-       mode_t mode;    
-{               
+void
+cp(char *from, char *to, mode_t mode)
+{
        static char buf[MAXBSIZE];
-       int from_fd, rcount, to_fd, wcount;
+       int from_fd, to_fd;
+       ssize_t rcount, wcount;
 
        if ((from_fd = open(from, O_RDONLY, 0)) < 0)
                error(from);
@@ -414,8 +415,7 @@ cp(from, to, mode)
 }
 
 void
-mv(from, to)
-       char *from, *to;
+mv(char *from, char *to)
 {
        char buf[MAXPATHLEN * 2];
 
@@ -429,27 +429,23 @@ mv(from, to)
 }
 
 void
-error(name)
-       char *name;
+error(char *name)
 {
-
        warn("%s", name);
        cleanup();
        exit(1);
 }
 
 void
-errorx(name)
-       char *name;
+errorx(char *name)
 {
-
        warnx("%s", name);
        cleanup();
        exit(1);
 }
 
 void
-cleanup()
+cleanup(void)
 {
        char buf[MAXPATHLEN];
 
@@ -472,7 +468,6 @@ cleanup()
 void
 usage(void)
 {
-
        (void)fprintf(stderr,
            "usage: pwd_mkdb [-c] [-p | -s] [-d basedir] [-u username] file\n");
        exit(1);
@@ -513,6 +508,11 @@ db_store(FILE *fp, FILE *oldfp, DB *edp, DB *dp, struct passwd *pw,
        key.data = (u_char *)tbuf;
        for (cnt = 1; scan(fp, pw, &flags); ++cnt) {
 
+#ifdef __APPLE__
+               if (pw->pw_name == NULL)
+                       continue;
+#endif
+
                if (firsttime) {
                        /* Look like YP? */
                        if ((pw->pw_name[0] == '+') || (pw->pw_name[0] == '-'))