diff options
Diffstat (limited to 'usr.sbin/pw/pw.c')
-rw-r--r-- | usr.sbin/pw/pw.c | 45 |
1 files changed, 35 insertions, 10 deletions
diff --git a/usr.sbin/pw/pw.c b/usr.sbin/pw/pw.c index fc17f6dba022..7cb5dd160e12 100644 --- a/usr.sbin/pw/pw.c +++ b/usr.sbin/pw/pw.c @@ -132,7 +132,11 @@ main(int argc, char *argv[]) while (argc > 1) { if (*argv[1] == '-') { /* - * Special case, allow pw -V<dir> <operation> [args] for scripts etc. + * Special case, allow pw -V<dir> <operation> [args] for + * scripts etc. + * + * The -M option before the keyword is handled + * differently from -M after a keyword. */ arg = argv[1][1]; if (arg == 'V' || arg == 'R') { @@ -143,12 +147,13 @@ main(int argc, char *argv[]) optarg = &argv[1][2]; if (*optarg == '\0') { if (stat(argv[2], &st) != 0) - errx(EX_OSFILE, \ + errx(EX_OSFILE, "no such directory `%s'", argv[2]); if (!S_ISDIR(st.st_mode)) - errx(EX_OSFILE, "`%s' not a " - "directory", argv[2]); + errx(EX_OSFILE, + "`%s' not a directory", + argv[2]); optarg = argv[2]; ++argv; --argc; @@ -162,10 +167,27 @@ main(int argc, char *argv[]) snprintf(conf.etcpath, sizeof(conf.etcpath), "%s%s", optarg, arg == 'R' ? _PATH_PWD : ""); + conf.altroot = true; + } else if (mode == -1 && which == -1 && arg == 'M') { + int fd; + + optarg = &argv[1][2]; + if (*optarg == '\0') { + optarg = argv[2]; + ++argv; + --argc; + } + fd = open(optarg, + O_WRONLY | O_APPEND | O_CREAT | O_CLOEXEC, + 0644); + if (fd == -1) + errx(EX_OSERR, + "Cannot open metalog `%s'", + optarg); + conf.metalog = fdopen(fd, "ae"); } else break; - } - else if (mode == -1 && (tmp = getindex(Modes, argv[1])) != -1) + } else if (mode == -1 && (tmp = getindex(Modes, argv[1])) != -1) mode = tmp; else if (which == -1 && (tmp = getindex(Which, argv[1])) != -1) which = tmp; @@ -177,7 +199,7 @@ main(int argc, char *argv[]) } else if (strcmp(argv[1], "help") == 0 && argv[2] == NULL) cmdhelp(mode, which); else if (which != -1 && mode != -1) - arg1 = argv[1]; + arg1 = argv[1]; else errx(EX_USAGE, "unknown keyword `%s'", argv[1]); ++argv; @@ -194,6 +216,10 @@ main(int argc, char *argv[]) if (conf.rootfd == -1) errx(EXIT_FAILURE, "Unable to open '%s'", conf.rootdir); + if (conf.metalog != NULL && (which != W_USER || mode != M_ADD)) + errx(EXIT_FAILURE, + "metalog can only be specified with 'useradd'"); + return (cmdfunc[which][mode](argc, argv, arg1)); } @@ -232,10 +258,11 @@ cmdhelp(int mode, int which) static const char *help[W_NUM][M_NUM] = { { - "usage: pw useradd [name] [switches]\n" + "usage: pw [-M metalog] useradd [name] [switches]\n" "\t-V etcdir alternate /etc location\n" "\t-R rootdir alternate root directory\n" "\t-C config configuration file\n" + "\t-M metalog mtree file, must precede 'useradd'\n" "\t-q quiet operation\n" " Adding users:\n" "\t-n name login name\n" @@ -256,8 +283,6 @@ cmdhelp(int mode, int which) "\t-Y update NIS maps\n" "\t-N no update\n" " Setting defaults:\n" - "\t-V etcdir alternate /etc location\n" - "\t-R rootdir alternate root directory\n" "\t-D set user defaults\n" "\t-b dir default home root dir\n" "\t-e period default expiry period\n" |