From 3af58faa587f263481899bbe5a258c74be6038c0 Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Sun, 31 May 2015 10:02:01 +0000 Subject: Use asprintf instead of malloc + snprintf and test the memory allocation --- pw/pw.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'pw/pw.c') diff --git a/pw/pw.c b/pw/pw.c index ff48db7..0c41f03 100644 --- a/pw/pw.c +++ b/pw/pw.c @@ -221,8 +221,9 @@ main(int argc, char *argv[]) char * etcpath = getarg(&arglist, 'V')->val; if (*etcpath) { if (config == NULL) { /* Only override config location if -C not specified */ - config = malloc(MAXPATHLEN); - snprintf(config, MAXPATHLEN, "%s/pw.conf", etcpath); + asprintf(&config, "%s/pw.conf", etcpath); + if (config == NULL) + errx(EX_OSERR, "out of memory"); } memcpy(&PWF, &VPWF, sizeof PWF); setpwdir(etcpath); -- cgit v1.2.3 From f1cacd691c6b62757f4a0168eded3d8672a06b13 Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Wed, 3 Jun 2015 19:08:25 +0000 Subject: New pw -R rootdir option This allows to set an alternate root directory in which the users/groups will be manipulated Requested by: gjb, ian Tested by: gjb --- pw/pw.c | 79 +++++++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 52 insertions(+), 27 deletions(-) (limited to 'pw/pw.c') diff --git a/pw/pw.c b/pw/pw.c index 0c41f03..496ecd8 100644 --- a/pw/pw.c +++ b/pw/pw.c @@ -56,7 +56,7 @@ static const char *Combo2[] = { struct pwf PWF = { - 0, + PWF_REGULAR, setpwent, endpwent, getpwent, @@ -71,7 +71,7 @@ struct pwf PWF = }; struct pwf VPWF = { - 1, + PWF_ALT, vsetpwent, vendpwent, vgetpwent, @@ -99,24 +99,27 @@ main(int argc, char *argv[]) char *config = NULL; struct userconf *cnf; struct stat st; + char arg; + struct carg *carg; + char *etcpath = NULL; static const char *opts[W_NUM][M_NUM] = { { /* user */ - "V:C:qn:u:c:d:e:p:g:G:mM:k:s:oL:i:w:h:H:Db:NPy:Y", - "V:C:qn:u:rY", - "V:C:qn:u:c:d:e:p:g:G:mM:l:k:s:w:L:h:H:FNPY", - "V:C:qn:u:FPa7", - "V:C:q", - "V:C:q", - "V:C:q" + "R:V:C:qn:u:c:d:e:p:g:G:mM:k:s:oL:i:w:h:H:Db:NPy:Y", + "R:V:C:qn:u:rY", + "R:V:C:qn:u:c:d:e:p:g:G:mM:l:k:s:w:L:h:H:FNPY", + "R:V:C:qn:u:FPa7", + "R:V:C:q", + "R:V:C:q", + "R:V:C:q" }, { /* grp */ - "V:C:qn:g:h:H:M:opNPY", - "V:C:qn:g:Y", - "V:C:qn:d:g:l:h:H:FM:m:NPY", - "V:C:qn:g:FPa", - "V:C:q" + "R:V:C:qn:g:h:H:M:opNPY", + "R:V:C:qn:g:Y", + "R:V:C:qn:d:g:l:h:H:FM:m:NPY", + "R:V:C:qn:g:FPa", + "R:V:C:q" } }; @@ -141,7 +144,8 @@ main(int argc, char *argv[]) /* * Special case, allow pw -V [args] for scripts etc. */ - if (argv[1][1] == 'V') { + arg = argv[1][1]; + if (arg == 'V' || arg == 'R') { optarg = &argv[1][2]; if (*optarg == '\0') { if (stat(argv[2], &st) != 0) @@ -155,7 +159,7 @@ main(int argc, char *argv[]) ++argv; --argc; } - addarg(&arglist, 'V', optarg); + addarg(&arglist, arg, optarg); } else break; } @@ -217,19 +221,29 @@ main(int argc, char *argv[]) config = getarg(&arglist, 'C') ? getarg(&arglist, 'C')->val : NULL; - if (getarg(&arglist, 'V') != NULL) { - char * etcpath = getarg(&arglist, 'V')->val; - if (*etcpath) { - if (config == NULL) { /* Only override config location if -C not specified */ - asprintf(&config, "%s/pw.conf", etcpath); - if (config == NULL) - errx(EX_OSERR, "out of memory"); - } - memcpy(&PWF, &VPWF, sizeof PWF); - setpwdir(etcpath); - setgrdir(etcpath); + if ((carg = getarg(&arglist, 'R')) != NULL) { + asprintf(&etcpath, "%s/etc", carg->val); + if (etcpath == NULL) + errx(EX_OSERR, "out of memory"); + } + if (etcpath == NULL && (carg = getarg(&arglist, 'V')) != NULL) { + etcpath = strdup(carg->val); + if (etcpath == NULL) + errx(EX_OSERR, "out of memory"); + } + if (etcpath && *etcpath) { + if (config == NULL) { /* Only override config location if -C not specified */ + asprintf(&config, "%s/pw.conf", etcpath); + if (config == NULL) + errx(EX_OSERR, "out of memory"); } + setpwdir(etcpath); + setgrdir(etcpath); + memcpy(&PWF, &VPWF, sizeof PWF); + if (getarg(&arglist, 'R')) + PWF._altdir = PWF_ROOTDIR; } + free(etcpath); /* * Now, let's do the common initialisation @@ -303,6 +317,7 @@ cmdhelp(int mode, int which) { "usage: pw useradd [name] [switches]\n" "\t-V etcdir alternate /etc location\n" + "\t-R rootir alternate root directory\n" "\t-C config configuration file\n" "\t-q quiet operation\n" " Adding users:\n" @@ -325,6 +340,7 @@ cmdhelp(int mode, int which) "\t-N no update\n" " Setting defaults:\n" "\t-V etcdir alternate /etc location\n" + "\t-R rootir 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" @@ -341,12 +357,14 @@ cmdhelp(int mode, int which) "\t-y path set NIS passwd file path\n", "usage: pw userdel [uid|name] [switches]\n" "\t-V etcdir alternate /etc location\n" + "\t-R rootir alternate root directory\n" "\t-n name login name\n" "\t-u uid user id\n" "\t-Y update NIS maps\n" "\t-r remove home & contents\n", "usage: pw usermod [uid|name] [switches]\n" "\t-V etcdir alternate /etc location\n" + "\t-R rootir alternate root directory\n" "\t-C config configuration file\n" "\t-q quiet operation\n" "\t-F force add if no user\n" @@ -370,6 +388,7 @@ cmdhelp(int mode, int which) "\t-N no update\n", "usage: pw usershow [uid|name] [switches]\n" "\t-V etcdir alternate /etc location\n" + "\t-R rootir alternate root directory\n" "\t-n name login name\n" "\t-u uid user id\n" "\t-F force print\n" @@ -378,6 +397,7 @@ cmdhelp(int mode, int which) "\t-7 print in v7 format\n", "usage: pw usernext [switches]\n" "\t-V etcdir alternate /etc location\n" + "\t-R rootir alternate root directory\n" "\t-C config configuration file\n" "\t-q quiet operation\n", "usage pw: lock [switches]\n" @@ -392,6 +412,7 @@ cmdhelp(int mode, int which) { "usage: pw groupadd [group|gid] [switches]\n" "\t-V etcdir alternate /etc location\n" + "\t-R rootir alternate root directory\n" "\t-C config configuration file\n" "\t-q quiet operation\n" "\t-n group group name\n" @@ -402,11 +423,13 @@ cmdhelp(int mode, int which) "\t-N no update\n", "usage: pw groupdel [group|gid] [switches]\n" "\t-V etcdir alternate /etc location\n" + "\t-R rootir alternate root directory\n" "\t-n name group name\n" "\t-g gid group id\n" "\t-Y update NIS maps\n", "usage: pw groupmod [group|gid] [switches]\n" "\t-V etcdir alternate /etc location\n" + "\t-R rootir alternate root directory\n" "\t-C config configuration file\n" "\t-q quiet operation\n" "\t-F force add if not exists\n" @@ -420,6 +443,7 @@ cmdhelp(int mode, int which) "\t-N no update\n", "usage: pw groupshow [group|gid] [switches]\n" "\t-V etcdir alternate /etc location\n" + "\t-R rootir alternate root directory\n" "\t-n name group name\n" "\t-g gid group id\n" "\t-F force print\n" @@ -427,6 +451,7 @@ cmdhelp(int mode, int which) "\t-a print all accounting groups\n", "usage: pw groupnext [switches]\n" "\t-V etcdir alternate /etc location\n" + "\t-R rootir alternate root directory\n" "\t-C config configuration file\n" "\t-q quiet operation\n" } -- cgit v1.2.3 From 39d77815028ba1a72509c07e0a8583493f6ec0a8 Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Sun, 7 Jun 2015 14:34:38 +0000 Subject: Add a new global struct pwconf to store etcpath, rootdir and struct userconf Do not add anymore -R and -V to arglist Add an error message if both -V and -R are set in arguments --- pw/pw.c | 56 ++++++++++++++++++++++++++------------------------------ 1 file changed, 26 insertions(+), 30 deletions(-) (limited to 'pw/pw.c') diff --git a/pw/pw.c b/pw/pw.c index 496ecd8..174a9dc 100644 --- a/pw/pw.c +++ b/pw/pw.c @@ -33,6 +33,7 @@ static const char rcsid[] = #include #include #include +#include #include #include "pw.h" @@ -84,6 +85,8 @@ struct pwf VPWF = vgetgrnam, }; +struct pwconf conf; + static struct cargs arglist; static int getindex(const char *words[], const char *word); @@ -97,11 +100,9 @@ main(int argc, char *argv[]) int mode = -1; int which = -1; char *config = NULL; - struct userconf *cnf; struct stat st; char arg; - struct carg *carg; - char *etcpath = NULL; + bool relocated = false; static const char *opts[W_NUM][M_NUM] = { @@ -123,12 +124,15 @@ main(int argc, char *argv[]) } }; - static int (*funcs[W_NUM]) (struct userconf * _cnf, int _mode, struct cargs * _args) = + static int (*funcs[W_NUM]) (int _mode, struct cargs * _args) = { /* Request handlers */ pw_user, pw_group }; + conf.rootdir[0] = '\0'; + strlcpy(conf.etcpath, _PATH_PWD, sizeof(conf.etcpath)); + LIST_INIT(&arglist); (void)setlocale(LC_ALL, ""); @@ -146,6 +150,10 @@ main(int argc, char *argv[]) */ arg = argv[1][1]; if (arg == 'V' || arg == 'R') { + if (relocated) + errx(EXIT_FAILURE, "Both '-R' and '-V' " + "specified, only one accepted"); + relocated = true; optarg = &argv[1][2]; if (*optarg == '\0') { if (stat(argv[2], &st) != 0) @@ -159,7 +167,14 @@ main(int argc, char *argv[]) ++argv; --argc; } - addarg(&arglist, arg, optarg); + memcpy(&PWF, &VPWF, sizeof PWF); + if (arg == 'R') { + strlcpy(conf.rootdir, optarg, + sizeof(conf.rootdir)); + PWF._altdir = PWF_ROOTDIR; + } + snprintf(conf.etcpath, sizeof(conf.etcpath), + "%s%s", optarg, arg == 'R' ? "/etc" : ""); } else break; } @@ -220,37 +235,18 @@ main(int argc, char *argv[]) */ config = getarg(&arglist, 'C') ? getarg(&arglist, 'C')->val : NULL; - - if ((carg = getarg(&arglist, 'R')) != NULL) { - asprintf(&etcpath, "%s/etc", carg->val); - if (etcpath == NULL) + if (config == NULL) { /* Only override config location if -C not specified */ + asprintf(&config, "%s/pw.conf", conf.etcpath); + if (config == NULL) errx(EX_OSERR, "out of memory"); } - if (etcpath == NULL && (carg = getarg(&arglist, 'V')) != NULL) { - etcpath = strdup(carg->val); - if (etcpath == NULL) - errx(EX_OSERR, "out of memory"); - } - if (etcpath && *etcpath) { - if (config == NULL) { /* Only override config location if -C not specified */ - asprintf(&config, "%s/pw.conf", etcpath); - if (config == NULL) - errx(EX_OSERR, "out of memory"); - } - setpwdir(etcpath); - setgrdir(etcpath); - memcpy(&PWF, &VPWF, sizeof PWF); - if (getarg(&arglist, 'R')) - PWF._altdir = PWF_ROOTDIR; - } - free(etcpath); /* * Now, let's do the common initialisation */ - cnf = read_userconfig(config); + conf.userconf = read_userconfig(config); - ch = funcs[which] (cnf, mode, &arglist); + ch = funcs[which] (mode, &arglist); /* * If everything went ok, and we've been asked to update @@ -274,7 +270,7 @@ main(int argc, char *argv[]) if ((i = WEXITSTATUS(i)) != 0) errx(ch, "make exited with status %d", i); else - pw_log(cnf, mode, which, "NIS maps updated"); + pw_log(conf.userconf, mode, which, "NIS maps updated"); } } return ch; -- cgit v1.2.3 From ed070f3fb430bf14b9fae10c25312f6dc4235aa6 Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Sun, 7 Jun 2015 14:54:07 +0000 Subject: Handle -C and -Y locally and stop adding them to arglist --- pw/pw.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'pw/pw.c') diff --git a/pw/pw.c b/pw/pw.c index 174a9dc..991019d 100644 --- a/pw/pw.c +++ b/pw/pw.c @@ -102,7 +102,7 @@ main(int argc, char *argv[]) char *config = NULL; struct stat st; char arg; - bool relocated = false; + bool relocated, nis; static const char *opts[W_NUM][M_NUM] = { @@ -130,6 +130,7 @@ main(int argc, char *argv[]) pw_group }; + relocated = nis = false; conf.rootdir[0] = '\0'; strlcpy(conf.etcpath, _PATH_PWD, sizeof(conf.etcpath)); @@ -210,10 +211,20 @@ main(int argc, char *argv[]) optarg = NULL; while ((ch = getopt(argc, argv, opts[which][mode])) != -1) { - if (ch == '?') + switch (ch) { + case '?': errx(EX_USAGE, "unknown switch"); - else + break; + case 'C': + config = optarg; + break; + case 'Y': + nis = true; + break; + default: addarg(&arglist, ch, optarg); + break; + } optarg = NULL; } @@ -234,7 +245,6 @@ main(int argc, char *argv[]) * Set our base working path if not overridden */ - config = getarg(&arglist, 'C') ? getarg(&arglist, 'C')->val : NULL; if (config == NULL) { /* Only override config location if -C not specified */ asprintf(&config, "%s/pw.conf", conf.etcpath); if (config == NULL) @@ -252,7 +262,7 @@ main(int argc, char *argv[]) * If everything went ok, and we've been asked to update * the NIS maps, then do it now */ - if (ch == EXIT_SUCCESS && getarg(&arglist, 'Y') != NULL) { + if (ch == EXIT_SUCCESS && nis) { pid_t pid; fflush(NULL); -- cgit v1.2.3 From 577824cadb88a52417c8a551d1aa6b70b2224b22 Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Sun, 7 Jun 2015 15:09:53 +0000 Subject: Handle dryrun (-N) via global pwconf --- pw/pw.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'pw/pw.c') diff --git a/pw/pw.c b/pw/pw.c index 991019d..7a86680 100644 --- a/pw/pw.c +++ b/pw/pw.c @@ -132,6 +132,7 @@ main(int argc, char *argv[]) relocated = nis = false; conf.rootdir[0] = '\0'; + conf.dryrun = false; strlcpy(conf.etcpath, _PATH_PWD, sizeof(conf.etcpath)); LIST_INIT(&arglist); @@ -218,6 +219,9 @@ main(int argc, char *argv[]) case 'C': config = optarg; break; + case 'N': + conf.dryrun = true; + break; case 'Y': nis = true; break; @@ -231,7 +235,7 @@ main(int argc, char *argv[]) /* * Must be root to attempt an update */ - if (geteuid() != 0 && mode != M_PRINT && mode != M_NEXT && getarg(&arglist, 'N')==NULL) + if (geteuid() != 0 && mode != M_PRINT && mode != M_NEXT && !conf.dryrun) errx(EX_NOPERM, "you must be root to run this program"); /* -- cgit v1.2.3 From fec3dfc01be2e26eb5df5998a06066e2064e0a4b Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Sun, 7 Jun 2015 15:27:17 +0000 Subject: Handle pretty print (-P) via global pwconf --- pw/pw.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'pw/pw.c') diff --git a/pw/pw.c b/pw/pw.c index 7a86680..22665e9 100644 --- a/pw/pw.c +++ b/pw/pw.c @@ -133,6 +133,7 @@ main(int argc, char *argv[]) relocated = nis = false; conf.rootdir[0] = '\0'; conf.dryrun = false; + conf.pretty = false; strlcpy(conf.etcpath, _PATH_PWD, sizeof(conf.etcpath)); LIST_INIT(&arglist); @@ -222,6 +223,9 @@ main(int argc, char *argv[]) case 'N': conf.dryrun = true; break; + case 'P': + conf.pretty = true; + break; case 'Y': nis = true; break; -- cgit v1.2.3 From 98e6bc31dc6985604ba6aa31a3c58fcb3f077127 Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Sun, 7 Jun 2015 15:29:58 +0000 Subject: Initialize conf using menset(3) --- pw/pw.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'pw/pw.c') diff --git a/pw/pw.c b/pw/pw.c index 22665e9..6376133 100644 --- a/pw/pw.c +++ b/pw/pw.c @@ -131,9 +131,7 @@ main(int argc, char *argv[]) }; relocated = nis = false; - conf.rootdir[0] = '\0'; - conf.dryrun = false; - conf.pretty = false; + memset(&conf, 0, sizeof(conf)); strlcpy(conf.etcpath, _PATH_PWD, sizeof(conf.etcpath)); LIST_INIT(&arglist); -- cgit v1.2.3 From 8b4eba30cac45e27a97d4e86a8e8506b0e8dc318 Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Sun, 7 Jun 2015 15:33:08 +0000 Subject: Handle -7 via gloval pwconf --- pw/pw.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'pw/pw.c') diff --git a/pw/pw.c b/pw/pw.c index 6376133..c81b5c4 100644 --- a/pw/pw.c +++ b/pw/pw.c @@ -215,6 +215,9 @@ main(int argc, char *argv[]) case '?': errx(EX_USAGE, "unknown switch"); break; + case '7': + conf.v7 = true; + break; case 'C': config = optarg; break; -- cgit v1.2.3 From 7d8cc6729f3fcf5fb4c38936179b2c0b9b026130 Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Sun, 7 Jun 2015 19:03:41 +0000 Subject: Refactor input validation Mutualize code to validate inputs of both 'user' and 'group' command Test that the input name fits into MAXLOGNAME --- pw/pw.c | 49 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) (limited to 'pw/pw.c') diff --git a/pw/pw.c b/pw/pw.c index c81b5c4..7274c32 100644 --- a/pw/pw.c +++ b/pw/pw.c @@ -99,9 +99,11 @@ main(int argc, char *argv[]) int ch; int mode = -1; int which = -1; + long id = -1; char *config = NULL; struct stat st; - char arg; + const char *errstr; + char arg, *name; bool relocated, nis; static const char *opts[W_NUM][M_NUM] = @@ -124,12 +126,14 @@ main(int argc, char *argv[]) } }; - static int (*funcs[W_NUM]) (int _mode, struct cargs * _args) = + static int (*funcs[W_NUM]) (int _mode, char *_name, long _id, + struct cargs * _args) = { /* Request handlers */ pw_user, pw_group }; + name = NULL; relocated = nis = false; memset(&conf, 0, sizeof(conf)); strlcpy(conf.etcpath, _PATH_PWD, sizeof(conf.etcpath)); @@ -190,9 +194,15 @@ main(int argc, char *argv[]) mode = tmp % M_NUM; } else if (strcmp(argv[1], "help") == 0 && argv[2] == NULL) cmdhelp(mode, which); - else if (which != -1 && mode != -1) - addarg(&arglist, 'n', argv[1]); - else + else if (which != -1 && mode != -1) { + if (strspn(argv[1], "0123456789") == strlen(argv[1])) { + id = strtonum(argv[1], 0, LONG_MAX, &errstr); + if (errstr != NULL) + errx(EX_USAGE, "Bad id '%s': %s", + argv[1], errstr); + } else + name = argv[1]; + } else errx(EX_USAGE, "unknown keyword `%s'", argv[1]); ++argv; --argc; @@ -230,6 +240,30 @@ main(int argc, char *argv[]) case 'Y': nis = true; break; + case 'g': + if (which == 0) { /* for user* */ + addarg(&arglist, 'g', optarg); + break; + } + /* FALLTHROUGH */ + case 'u': + if (strspn(optarg, "0123456789") != strlen(optarg)) + errx(EX_USAGE, "%s expects a number", + which == 1 ? "-g" : "-u" ); + id = strtonum(optarg, 0, LONG_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); default: addarg(&arglist, ch, optarg); break; @@ -237,6 +271,9 @@ main(int argc, char *argv[]) optarg = NULL; } + if (name != NULL && strlen(name) >= MAXLOGNAME) + errx(EX_USAGE, "name too long: %s", name); + /* * Must be root to attempt an update */ @@ -265,7 +302,7 @@ main(int argc, char *argv[]) */ conf.userconf = read_userconfig(config); - ch = funcs[which] (mode, &arglist); + ch = funcs[which] (mode, name, id, &arglist); /* * If everything went ok, and we've been asked to update -- cgit v1.2.3 From 34211cbde959d55fb8e6b818365341d0193e7253 Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Sun, 7 Jun 2015 19:33:25 +0000 Subject: In case of rename validate the length of the new name Check early that the new name fits MAXLOGNAME and store it in pwconf --- pw/pw.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'pw/pw.c') diff --git a/pw/pw.c b/pw/pw.c index 7274c32..ae030ec 100644 --- a/pw/pw.c +++ b/pw/pw.c @@ -234,6 +234,11 @@ main(int argc, char *argv[]) case 'N': conf.dryrun = true; break; + case 'l': + if (strlen(optarg) >= MAXLOGNAME) + errx(EX_USAGE, "new name too long: %s", optarg); + conf.newname = optarg; + break; case 'P': conf.pretty = true; break; -- cgit v1.2.3 From 068c2f64c08c71d084c16d066a0fb3802e26b7a9 Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Sun, 7 Jun 2015 19:59:01 +0000 Subject: Fix duplicate checking --- pw/pw.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'pw/pw.c') diff --git a/pw/pw.c b/pw/pw.c index ae030ec..a311572 100644 --- a/pw/pw.c +++ b/pw/pw.c @@ -269,6 +269,10 @@ main(int argc, char *argv[]) if (errstr != NULL) errx(EX_USAGE, "Bad id '%s': %s", optarg, errstr); + break; + case 'o': + conf.checkduplicate = true; + break; default: addarg(&arglist, ch, optarg); break; -- cgit v1.2.3 From 5b291029a9ed6f6ac19b03b29501179559dc07c3 Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Sun, 7 Jun 2015 20:44:06 +0000 Subject: Fix generating configuration file --- pw/pw.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'pw/pw.c') diff --git a/pw/pw.c b/pw/pw.c index a311572..d8d8c03 100644 --- a/pw/pw.c +++ b/pw/pw.c @@ -229,7 +229,8 @@ main(int argc, char *argv[]) conf.v7 = true; break; case 'C': - config = optarg; + conf.config = optarg; + config = conf.config; break; case 'N': conf.dryrun = true; -- cgit v1.2.3 From 50b3230917e6e4c6538d6d0f01fed543b8be5efc Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Sun, 7 Jun 2015 20:59:59 +0000 Subject: Fix setting uid/gid min/max via pw --- pw/pw.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'pw/pw.c') diff --git a/pw/pw.c b/pw/pw.c index d8d8c03..30fb55b 100644 --- a/pw/pw.c +++ b/pw/pw.c @@ -251,11 +251,20 @@ main(int argc, char *argv[]) addarg(&arglist, 'g', optarg); break; } - /* FALLTHROUGH */ - case 'u': if (strspn(optarg, "0123456789") != strlen(optarg)) - errx(EX_USAGE, "%s expects a number", - which == 1 ? "-g" : "-u" ); + errx(EX_USAGE, "-g expects a number"); + id = strtonum(optarg, 0, LONG_MAX, &errstr); + if (errstr != NULL) + errx(EX_USAGE, "Bad id '%s': %s", optarg, + errstr); + break; + case 'u': + if (strspn(optarg, "0123456789,") != strlen(optarg)) + errx(EX_USAGE, "-u expects a number"); + if (strchr(optarg, ',') != NULL) { + addarg(&arglist, 'u', optarg); + break; + } id = strtonum(optarg, 0, LONG_MAX, &errstr); if (errstr != NULL) errx(EX_USAGE, "Bad id '%s': %s", optarg, -- cgit v1.2.3 From 44a564bd4185ea1e172a8f310d13f71f24abf73f Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Sun, 7 Jun 2015 21:57:20 +0000 Subject: Remove '-q' support for pw [user|group] next the intent of -q in this command is to return as exit status the value of the next group/user id, which does not make sense given exit status are limited to values between 0 and 255. --- pw/pw.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'pw/pw.c') diff --git a/pw/pw.c b/pw/pw.c index 30fb55b..d75557e 100644 --- a/pw/pw.c +++ b/pw/pw.c @@ -113,7 +113,7 @@ main(int argc, char *argv[]) "R:V:C:qn:u:rY", "R:V:C:qn:u:c:d:e:p:g:G:mM:l:k:s:w:L:h:H:FNPY", "R:V:C:qn:u:FPa7", - "R:V:C:q", + "R:V:C", "R:V:C:q", "R:V:C:q" }, @@ -122,7 +122,7 @@ main(int argc, char *argv[]) "R:V:C:qn:g:Y", "R:V:C:qn:d:g:l:h:H:FM:m:NPY", "R:V:C:qn:g:FPa", - "R:V:C:q" + "R:V:C" } }; @@ -469,8 +469,7 @@ cmdhelp(int mode, int which) "usage: pw usernext [switches]\n" "\t-V etcdir alternate /etc location\n" "\t-R rootir alternate root directory\n" - "\t-C config configuration file\n" - "\t-q quiet operation\n", + "\t-C config configuration file\n", "usage pw: lock [switches]\n" "\t-V etcdir alternate /etc locations\n" "\t-C config configuration file\n" @@ -524,7 +523,6 @@ cmdhelp(int mode, int which) "\t-V etcdir alternate /etc location\n" "\t-R rootir alternate root directory\n" "\t-C config configuration file\n" - "\t-q quiet operation\n" } }; -- cgit v1.2.3 From 8cf9c51c20f43a1cafc48f42d29666c58cdfa781 Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Sun, 7 Jun 2015 21:59:43 +0000 Subject: Fix mistakes than came along with r284139 --- pw/pw.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'pw/pw.c') diff --git a/pw/pw.c b/pw/pw.c index d75557e..b21f6c0 100644 --- a/pw/pw.c +++ b/pw/pw.c @@ -113,7 +113,7 @@ main(int argc, char *argv[]) "R:V:C:qn:u:rY", "R:V:C:qn:u:c:d:e:p:g:G:mM:l:k:s:w:L:h:H:FNPY", "R:V:C:qn:u:FPa7", - "R:V:C", + "R:V:C:", "R:V:C:q", "R:V:C:q" }, @@ -122,7 +122,7 @@ main(int argc, char *argv[]) "R:V:C:qn:g:Y", "R:V:C:qn:d:g:l:h:H:FM:m:NPY", "R:V:C:qn:g:FPa", - "R:V:C" + "R:V:C:" } }; -- cgit v1.2.3 From 07d47dbbf964e186685045cb504935dd9be45792 Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Mon, 8 Jun 2015 05:27:34 +0000 Subject: backout remove of -q option for pw [user|group] next While the return code is broken, some corner case usage depends on the functionnality, so backout until we get better regression tests covering those corner case usage. --- pw/pw.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'pw/pw.c') diff --git a/pw/pw.c b/pw/pw.c index b21f6c0..30fb55b 100644 --- a/pw/pw.c +++ b/pw/pw.c @@ -113,7 +113,7 @@ main(int argc, char *argv[]) "R:V:C:qn:u:rY", "R:V:C:qn:u:c:d:e:p:g:G:mM:l:k:s:w:L:h:H:FNPY", "R:V:C:qn:u:FPa7", - "R:V:C:", + "R:V:C:q", "R:V:C:q", "R:V:C:q" }, @@ -122,7 +122,7 @@ main(int argc, char *argv[]) "R:V:C:qn:g:Y", "R:V:C:qn:d:g:l:h:H:FM:m:NPY", "R:V:C:qn:g:FPa", - "R:V:C:" + "R:V:C:q" } }; @@ -469,7 +469,8 @@ cmdhelp(int mode, int which) "usage: pw usernext [switches]\n" "\t-V etcdir alternate /etc location\n" "\t-R rootir alternate root directory\n" - "\t-C config configuration file\n", + "\t-C config configuration file\n" + "\t-q quiet operation\n", "usage pw: lock [switches]\n" "\t-V etcdir alternate /etc locations\n" "\t-C config configuration file\n" @@ -523,6 +524,7 @@ cmdhelp(int mode, int which) "\t-V etcdir alternate /etc location\n" "\t-R rootir alternate root directory\n" "\t-C config configuration file\n" + "\t-q quiet operation\n" } }; -- cgit v1.2.3