Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/pw/pw.c
| Show First 20 Lines • Show All 126 Lines • ▼ Show 20 Lines | main(int argc, char *argv[]) | ||||
| /* | /* | ||||
| * Break off the first couple of words to determine what exactly | * Break off the first couple of words to determine what exactly | ||||
| * we're being asked to do | * we're being asked to do | ||||
| */ | */ | ||||
| while (argc > 1) { | while (argc > 1) { | ||||
| if (*argv[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]; | arg = argv[1][1]; | ||||
| if (arg == 'V' || arg == 'R') { | if (arg == 'V' || arg == 'R') { | ||||
| if (relocated) | if (relocated) | ||||
| errx(EXIT_FAILURE, "Both '-R' and '-V' " | errx(EXIT_FAILURE, "Both '-R' and '-V' " | ||||
| "specified, only one accepted"); | "specified, only one accepted"); | ||||
| relocated = true; | relocated = true; | ||||
| optarg = &argv[1][2]; | optarg = &argv[1][2]; | ||||
| Show All 15 Lines | if (*argv[1] == '-') { | ||||
| strlcpy(conf.rootdir, optarg, | strlcpy(conf.rootdir, optarg, | ||||
| sizeof(conf.rootdir)); | sizeof(conf.rootdir)); | ||||
| PWF._altdir = PWF_ROOTDIR; | PWF._altdir = PWF_ROOTDIR; | ||||
| } | } | ||||
| snprintf(conf.etcpath, sizeof(conf.etcpath), | snprintf(conf.etcpath, sizeof(conf.etcpath), | ||||
| "%s%s", optarg, arg == 'R' ? | "%s%s", optarg, arg == 'R' ? | ||||
| _PATH_PWD : ""); | _PATH_PWD : ""); | ||||
| conf.altroot = true; | 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 | } else | ||||
| break; | break; | ||||
| } else if (mode == -1 && (tmp = getindex(Modes, argv[1])) != -1) | } else if (mode == -1 && (tmp = getindex(Modes, argv[1])) != -1) | ||||
| mode = tmp; | mode = tmp; | ||||
| else if (which == -1 && (tmp = getindex(Which, argv[1])) != -1) | else if (which == -1 && (tmp = getindex(Which, argv[1])) != -1) | ||||
| which = tmp; | which = tmp; | ||||
| else if ((mode == -1 && which == -1) && | else if ((mode == -1 && which == -1) && | ||||
| ((tmp = getindex(Combo1, argv[1])) != -1 || | ((tmp = getindex(Combo1, argv[1])) != -1 || | ||||
| Show All 15 Lines | main(int argc, char *argv[]) | ||||
| */ | */ | ||||
| if (mode == -1 || which == -1) | if (mode == -1 || which == -1) | ||||
| cmdhelp(mode, which); | cmdhelp(mode, which); | ||||
| conf.rootfd = open(conf.rootdir, O_DIRECTORY|O_CLOEXEC); | conf.rootfd = open(conf.rootdir, O_DIRECTORY|O_CLOEXEC); | ||||
| if (conf.rootfd == -1) | if (conf.rootfd == -1) | ||||
| errx(EXIT_FAILURE, "Unable to open '%s'", conf.rootdir); | 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)); | return (cmdfunc[which][mode](argc, argv, arg1)); | ||||
| } | } | ||||
| static int | static int | ||||
| getindex(const char *words[], const char *word) | getindex(const char *words[], const char *word) | ||||
| { | { | ||||
| int i = 0; | int i = 0; | ||||
| Show All 22 Lines | cmdhelp(int mode, int which) | ||||
| else { | else { | ||||
| /* | /* | ||||
| * We need to give mode specific help | * We need to give mode specific help | ||||
| */ | */ | ||||
| static const char *help[W_NUM][M_NUM] = | 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-V etcdir alternate /etc location\n" | ||||
| "\t-R rootdir alternate root directory\n" | "\t-R rootdir alternate root directory\n" | ||||
| "\t-C config configuration file\n" | "\t-C config configuration file\n" | ||||
| "\t-M metalog mtree file, must precede 'useradd'\n" | |||||
| "\t-q quiet operation\n" | "\t-q quiet operation\n" | ||||
| " Adding users:\n" | " Adding users:\n" | ||||
| "\t-n name login name\n" | "\t-n name login name\n" | ||||
| "\t-u uid user id\n" | "\t-u uid user id\n" | ||||
| "\t-c comment user name/comment\n" | "\t-c comment user name/comment\n" | ||||
| "\t-d directory home directory\n" | "\t-d directory home directory\n" | ||||
| "\t-e date account expiry date\n" | "\t-e date account expiry date\n" | ||||
| "\t-p date password expiry date\n" | "\t-p date password expiry date\n" | ||||
| "\t-g grp initial group\n" | "\t-g grp initial group\n" | ||||
| "\t-G grp1,grp2 additional groups\n" | "\t-G grp1,grp2 additional groups\n" | ||||
| "\t-m [ -k dir ] create and set up home\n" | "\t-m [ -k dir ] create and set up home\n" | ||||
| "\t-M mode home directory permissions\n" | "\t-M mode home directory permissions\n" | ||||
| "\t-s shell name of login shell\n" | "\t-s shell name of login shell\n" | ||||
| "\t-o duplicate uid ok\n" | "\t-o duplicate uid ok\n" | ||||
| "\t-L class user class\n" | "\t-L class user class\n" | ||||
| "\t-h fd read password on fd\n" | "\t-h fd read password on fd\n" | ||||
| "\t-H fd read encrypted password on fd\n" | "\t-H fd read encrypted password on fd\n" | ||||
| "\t-Y update NIS maps\n" | "\t-Y update NIS maps\n" | ||||
| "\t-N no update\n" | "\t-N no update\n" | ||||
| " Setting defaults:\n" | " Setting defaults:\n" | ||||
| "\t-D set user defaults\n" | "\t-D set user defaults\n" | ||||
emaste: maybe worth doing this bugfix separately so we can MFC it in advance of other changes here? | |||||
| "\t-b dir default home root dir\n" | "\t-b dir default home root dir\n" | ||||
| "\t-e period default expiry period\n" | "\t-e period default expiry period\n" | ||||
| "\t-p period default password change period\n" | "\t-p period default password change period\n" | ||||
| "\t-g group default group\n" | "\t-g group default group\n" | ||||
| "\t-G grp1,grp2 additional groups\n" | "\t-G grp1,grp2 additional groups\n" | ||||
| "\t-L class default user class\n" | "\t-L class default user class\n" | ||||
| "\t-k dir default home skeleton\n" | "\t-k dir default home skeleton\n" | ||||
| "\t-M mode home directory permissions\n" | "\t-M mode home directory permissions\n" | ||||
| ▲ Show 20 Lines • Show All 119 Lines • Show Last 20 Lines | |||||
maybe worth doing this bugfix separately so we can MFC it in advance of other changes here?