summaryrefslogtreecommitdiffstats
path: root/pw/pw.c
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2015-07-04 15:27:04 +0000
committerBaptiste Daroussin <bapt@FreeBSD.org>2015-07-04 15:27:04 +0000
commita723ebdc0a4d074c12bedca8c7d483a13105c295 (patch)
treec041c77aaa80a7890f98192b8b6c245c94f7166c /pw/pw.c
parentcc666f9d1a91a808b95a347674765342e3a354ef (diff)
downloadpw-darwin-a723ebdc0a4d074c12bedca8c7d483a13105c295.tar.gz
pw-darwin-a723ebdc0a4d074c12bedca8c7d483a13105c295.tar.zst
pw-darwin-a723ebdc0a4d074c12bedca8c7d483a13105c295.zip
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 'pw/pw.c')
-rw-r--r--pw/pw.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/pw/pw.c b/pw/pw.c
index 30fb55b..b9bd9d0 100644
--- a/pw/pw.c
+++ b/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;