diff options
author | Baptiste Daroussin <bapt@FreeBSD.org> | 2015-07-04 15:27:04 +0000 |
---|---|---|
committer | Baptiste Daroussin <bapt@FreeBSD.org> | 2015-07-04 15:27:04 +0000 |
commit | a723ebdc0a4d074c12bedca8c7d483a13105c295 (patch) | |
tree | c041c77aaa80a7890f98192b8b6c245c94f7166c /pw/pw.c | |
parent | cc666f9d1a91a808b95a347674765342e3a354ef (diff) | |
download | pw-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.c | 30 |
1 files changed, 30 insertions, 0 deletions
@@ -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; |