summaryrefslogtreecommitdiffstats
path: root/usr.sbin/pw/pw.c
diff options
context:
space:
mode:
authorbapt <bapt@FreeBSD.org>2015-07-04 15:27:04 +0000
committerbapt <bapt@FreeBSD.org>2015-07-04 15:27:04 +0000
commitaf8a9dfc9a193bc5ddc96c6d338dc4332a50cc40 (patch)
tree96d012439ab6aafe264558a93d999b3aeee9f1d4 /usr.sbin/pw/pw.c
parent52e3c0b514125582b11c79c93e8ac5d1e3679e86 (diff)
downloadFreeBSD-src-af8a9dfc9a193bc5ddc96c6d338dc4332a50cc40.zip
FreeBSD-src-af8a9dfc9a193bc5ddc96c6d338dc4332a50cc40.tar.gz
Validate input of pw usermod -h and pwusermod -H
Push the code that set the password into a separate function to improve readability Add regression tests about pw usermod -h and pw usermod -H
Diffstat (limited to 'usr.sbin/pw/pw.c')
-rw-r--r--usr.sbin/pw/pw.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/usr.sbin/pw/pw.c b/usr.sbin/pw/pw.c
index 30fb55b..b9bd9d0 100644
--- a/usr.sbin/pw/pw.c
+++ b/usr.sbin/pw/pw.c
@@ -137,6 +137,7 @@ main(int argc, char *argv[])
relocated = nis = false;
memset(&conf, 0, sizeof(conf));
strlcpy(conf.etcpath, _PATH_PWD, sizeof(conf.etcpath));
+ conf.fd = -1;
LIST_INIT(&arglist);
@@ -280,6 +281,35 @@ main(int argc, char *argv[])
errx(EX_USAGE, "Bad id '%s': %s", optarg,
errstr);
break;
+ case 'H':
+ if (conf.fd != -1)
+ errx(EX_USAGE, "'-h' and '-H' are mutually "
+ "exclusive options");
+ conf.precrypted = true;
+ if (strspn(optarg, "0123456789") != strlen(optarg))
+ errx(EX_USAGE, "'-H' expects a file descriptor");
+
+ conf.fd = strtonum(optarg, 0, INT_MAX, &errstr);
+ if (errstr != NULL)
+ errx(EX_USAGE, "Bad file descriptor '%s': %s",
+ optarg, errstr);
+ break;
+ case 'h':
+ if (conf.fd != -1)
+ errx(EX_USAGE, "'-h' and '-H' are mutually "
+ "exclusive options");
+
+ if (strcmp(optarg, "-") == 0)
+ conf.fd = '-';
+ else if (strspn(optarg, "0123456789") == strlen(optarg)) {
+ conf.fd = strtonum(optarg, 0, INT_MAX, &errstr);
+ if (errstr != NULL)
+ errx(EX_USAGE, "'-h' expects a "
+ "file descriptor or '-'");
+ } else
+ errx(EX_USAGE, "'-h' expects a file "
+ "descriptor or '-'");
+ break;
case 'o':
conf.checkduplicate = true;
break;
OpenPOWER on IntegriCloud