From d9f11cd85bd533df21be792b11fc21385c210b6b Mon Sep 17 00:00:00 2001 From: Simon Wilkinson Date: Wed, 16 Mar 2011 15:31:40 +0000 Subject: [PATCH] kauth: Use strtol for integer argument handling Use strtol, rather than a combination of util_isint and atoi to handle integer arguments. This is much cleaner, far more portable, and removes a dependency on an internal library function that this file is the only user of. Change-Id: I3140a396ae3ec32e4498f62769f27c76f03001d9 Reviewed-on: http://gerrit.openafs.org/4245 Tested-by: BuildBot Reviewed-by: Derrick Brashear --- src/kauth/admin_tools.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/kauth/admin_tools.c b/src/kauth/admin_tools.c index 7e953f68e..a65cf1959 100644 --- a/src/kauth/admin_tools.c +++ b/src/kauth/admin_tools.c @@ -582,6 +582,7 @@ SetFields(struct cmd_syndesc *as, void *arock) int code; char name[MAXKTCNAMELEN]; char instance[MAXKTCNAMELEN]; + char *end; afs_int32 flags = 0; Date expiration = 0; afs_int32 lifetime = 0; @@ -638,9 +639,8 @@ SetFields(struct cmd_syndesc *as, void *arock) for (i = 0; i < 4; misc_auth_bytes[i++] = 0); if (as->parms[4].items) { - if (util_isint(as->parms[4].items->data)) - pwexpiry = atoi(as->parms[4].items->data); - else { + pwexpiry = strtol(as->parms[4].items->data, &end, 10); + if (*end != '\0') { fprintf(stderr, "Password lifetime specified must be a non-negative decimal integer.\n"); pwexpiry = -1; @@ -650,9 +650,9 @@ SetFields(struct cmd_syndesc *as, void *arock) "Password lifetime range must be [0..254] days.\n"); fprintf(stderr, "Zero represents an unlimited lifetime.\n"); return KABADCMD; - } else { - misc_auth_bytes[0] = pwexpiry + 1; } + + misc_auth_bytes[0] = pwexpiry + 1; } if (as->parms[5].items) { @@ -673,15 +673,14 @@ SetFields(struct cmd_syndesc *as, void *arock) if (as->parms[6].items) { int nfailures; + nfailures = strtol(as->parms[6].items->data, &end, 10); - if (util_isint(as->parms[6].items->data) - && ((nfailures = atoi(as->parms[6].items->data)) < 255)) { - misc_auth_bytes[2] = nfailures + 1; - } else { + if (*end != '\0' || nfailures < 0 || nfailures > 254) { fprintf(stderr, "Failure limit must be in [0..254].\n"); fprintf(stderr, "Zero represents unlimited login attempts.\n"); return KABADCMD; } + misc_auth_bytes[2] = nfailures + 1; } if (as->parms[7].items) { -- 2.39.5