diff options
author | bapt <bapt@FreeBSD.org> | 2015-07-29 06:22:41 +0000 |
---|---|---|
committer | bapt <bapt@FreeBSD.org> | 2015-07-29 06:22:41 +0000 |
commit | 4eb9f59af4f0e049f164c1dfd78a3f515aea90d2 (patch) | |
tree | 98a84b8a96d7783adc54c37bc04004d79098fd05 | |
parent | b7b72de7da1bacfaf7e37fed7943715dd342af86 (diff) | |
download | FreeBSD-src-4eb9f59af4f0e049f164c1dfd78a3f515aea90d2.zip FreeBSD-src-4eb9f59af4f0e049f164c1dfd78a3f515aea90d2.tar.gz |
Create a strtounum function using the same API as strtonum
This function returns uintmax_t
Use this function to convert to gid_t/uid_t
-rw-r--r-- | usr.sbin/pw/Makefile | 2 | ||||
-rw-r--r-- | usr.sbin/pw/pw.c | 6 | ||||
-rw-r--r-- | usr.sbin/pw/pw.h | 4 |
3 files changed, 8 insertions, 4 deletions
diff --git a/usr.sbin/pw/Makefile b/usr.sbin/pw/Makefile index c265399..87bb5f6 100644 --- a/usr.sbin/pw/Makefile +++ b/usr.sbin/pw/Makefile @@ -3,7 +3,7 @@ PROG= pw MAN= pw.conf.5 pw.8 SRCS= pw.c pw_conf.c pw_user.c pw_group.c pw_log.c pw_nis.c pw_vpw.c \ - grupd.c pwupd.c psdate.c bitmap.c cpdir.c rm_r.c + grupd.c pwupd.c psdate.c bitmap.c cpdir.c rm_r.c strtounum.c WARNS?= 3 diff --git a/usr.sbin/pw/pw.c b/usr.sbin/pw/pw.c index c1d9cd3..88c83db 100644 --- a/usr.sbin/pw/pw.c +++ b/usr.sbin/pw/pw.c @@ -199,7 +199,7 @@ main(int argc, char *argv[]) cmdhelp(mode, which); else if (which != -1 && mode != -1) { if (strspn(argv[1], "0123456789") == strlen(argv[1])) { - id = strtonum(argv[1], 0, LONG_MAX, &errstr); + id = strtounum(argv[1], 0, UID_MAX, &errstr); if (errstr != NULL) errx(EX_USAGE, "Bad id '%s': %s", argv[1], errstr); @@ -269,7 +269,7 @@ main(int argc, char *argv[]) } if (strspn(optarg, "0123456789") != strlen(optarg)) errx(EX_USAGE, "-g expects a number"); - id = strtonum(optarg, 0, GID_MAX, &errstr); + id = strtounum(optarg, 0, GID_MAX, &errstr); if (errstr != NULL) errx(EX_USAGE, "Bad id '%s': %s", optarg, errstr); @@ -281,7 +281,7 @@ main(int argc, char *argv[]) addarg(&arglist, 'u', optarg); break; } - id = strtonum(optarg, 0, UID_MAX, &errstr); + id = strtounum(optarg, 0, UID_MAX, &errstr); if (errstr != NULL) errx(EX_USAGE, "Bad id '%s': %s", optarg, errstr); diff --git a/usr.sbin/pw/pw.h b/usr.sbin/pw/pw.h index ed3b715..3ab3c74 100644 --- a/usr.sbin/pw/pw.h +++ b/usr.sbin/pw/pw.h @@ -32,6 +32,7 @@ #include <string.h> #include <unistd.h> #include <stdarg.h> +#include <inttypes.h> #include <errno.h> #include <sys/types.h> #include <sys/stat.h> @@ -101,3 +102,6 @@ char *pw_pwcrypt(char *password); extern const char *Modes[]; extern const char *Which[]; + +uintmax_t strtounum(const char *numstr, uintmax_t minval, uintmax_t maxval, + const char **errmsg); |