]> git.cameronkatri.com Git - pw-darwin.git/blobdiff - pw/pw.c
Cast uid/git to uintmax_t when using printf-like functions so the size of
[pw-darwin.git] / pw / pw.c
diff --git a/pw/pw.c b/pw/pw.c
index 951abc6a0b0af5c08fc1e6557b418c9fcf43408e..88c83dbfa125a5cdda983d620d2a555ab774c6c0 100644 (file)
--- a/pw/pw.c
+++ b/pw/pw.c
@@ -136,8 +136,10 @@ main(int argc, char *argv[])
        name = NULL;
        relocated = nis = false;
        memset(&conf, 0, sizeof(conf));
+       strlcpy(conf.rootdir, "/", sizeof(conf.rootdir));
        strlcpy(conf.etcpath, _PATH_PWD, sizeof(conf.etcpath));
        conf.fd = -1;
+       conf.checkduplicate = true;
 
        LIST_INIT(&arglist);
 
@@ -197,7 +199,7 @@ main(int argc, char *argv[])
                        cmdhelp(mode, which);
                else if (which != -1 && mode != -1) {
                        if (strspn(argv[1], "0123456789") == strlen(argv[1])) {
-                               id = strtonum(argv[1], 0, LONG_MAX, &errstr);
+                               id = strtounum(argv[1], 0, UID_MAX, &errstr);
                                if (errstr != NULL)
                                        errx(EX_USAGE, "Bad id '%s': %s",
                                            argv[1], errstr);
@@ -215,6 +217,9 @@ main(int argc, char *argv[])
        if (mode == -1 || which == -1)
                cmdhelp(mode, which);
 
+       conf.rootfd = open(conf.rootdir, O_DIRECTORY|O_CLOEXEC);
+       if (conf.rootfd == -1)
+               errx(EXIT_FAILURE, "Unable to open '%s'", conf.rootdir);
        conf.which = which;
        /*
         * We know which mode we're in and what we're about to do, so now
@@ -234,6 +239,9 @@ main(int argc, char *argv[])
                        conf.config = optarg;
                        config = conf.config;
                        break;
+               case 'F':
+                       conf.force = true;
+                       break;
                case 'N':
                        conf.dryrun = true;
                        break;
@@ -248,6 +256,12 @@ main(int argc, char *argv[])
                case 'Y':
                        nis = true;
                        break;
+               case 'a':
+                       conf.all = true;
+                       break;
+               case 'c':
+                       conf.gecos = pw_checkname(optarg, 1);
+                       break;
                case 'g':
                        if (which == 0) { /* for user* */
                                addarg(&arglist, 'g', optarg);
@@ -255,7 +269,7 @@ main(int argc, char *argv[])
                        }
                        if (strspn(optarg, "0123456789") != strlen(optarg))
                                errx(EX_USAGE, "-g expects a number");
-                       id = strtonum(optarg, 0, LONG_MAX, &errstr);
+                       id = strtounum(optarg, 0, GID_MAX, &errstr);
                        if (errstr != NULL)
                                errx(EX_USAGE, "Bad id '%s': %s", optarg,
                                    errstr);
@@ -267,20 +281,13 @@ main(int argc, char *argv[])
                                addarg(&arglist, 'u', optarg);
                                break;
                        }
-                       id = strtonum(optarg, 0, LONG_MAX, &errstr);
+                       id = strtounum(optarg, 0, UID_MAX, &errstr);
                        if (errstr != NULL)
                                errx(EX_USAGE, "Bad id '%s': %s", optarg,
                                    errstr);
                        break;
                case 'n':
-                       if (strspn(optarg, "0123456789") != strlen(optarg)) {
-                               name = optarg;
-                               break;
-                       }
-                       id = strtonum(optarg, 0, LONG_MAX, &errstr);
-                       if (errstr != NULL)
-                               errx(EX_USAGE, "Bad id '%s': %s", optarg,
-                                   errstr);
+                       name = optarg;
                        break;
                case 'H':
                        if (conf.fd != -1)
@@ -312,11 +319,14 @@ main(int argc, char *argv[])
                                    "descriptor or '-'");
                        break;
                case 'o':
-                       conf.checkduplicate = true;
+                       conf.checkduplicate = false;
                        break;
                case 'q':
                        conf.quiet = true;
                        break;
+               case 'r':
+                       conf.deletehome = true;
+                       break;
                default:
                        addarg(&arglist, ch, optarg);
                        break;
@@ -570,7 +580,12 @@ cmdhelp(int mode, int which)
 struct carg    *
 getarg(struct cargs * _args, int ch)
 {
-       struct carg    *c = LIST_FIRST(_args);
+       struct carg    *c;
+
+       if (_args == NULL)
+               return (NULL);
+       
+       c = LIST_FIRST(_args);
 
        while (c != NULL && c->ch != ch)
                c = LIST_NEXT(c, list);