From: Alejandro Colomar Date: Tue, 9 Jan 2024 19:04:43 +0000 (+0100) Subject: lib/sgetspent.c: sgetspent(): Simplify, by calling a2sl() instead of str2sl() X-Git-Tag: 4.17.0-rc1~159 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=326bdfe70b3c9ab3dd3d1b32352f2121c629c18f;p=thirdparty%2Fshadow.git lib/sgetspent.c: sgetspent(): Simplify, by calling a2sl() instead of str2sl() Reviewed-by: "Serge E. Hallyn" Signed-off-by: Alejandro Colomar --- diff --git a/lib/sgetspent.c b/lib/sgetspent.c index ef86e8e20..f4ace5218 100644 --- a/lib/sgetspent.c +++ b/lib/sgetspent.c @@ -19,6 +19,7 @@ #include #include +#include "atoi/a2i.h" #include "atoi/str2i.h" #include "prototypes.h" #include "shadowlog_internal.h" @@ -83,34 +84,28 @@ sgetspent(const char *string) * incorrectly formatted number. */ - if (fields[2][0] == '\0') { + if (fields[2][0] == '\0') spwd.sp_lstchg = -1; - } else if ( (str2sl(&spwd.sp_lstchg, fields[2]) == -1) - || (spwd.sp_lstchg < 0)) { + else if (a2sl(&spwd.sp_lstchg, fields[2], NULL, 0, 0, LONG_MAX) == -1) return NULL; - } /* * Get the minimum period between password changes. */ - if (fields[3][0] == '\0') { + if (fields[3][0] == '\0') spwd.sp_min = -1; - } else if ( (str2sl(&spwd.sp_min, fields[3]) == -1) - || (spwd.sp_min < 0)) { + else if (a2sl(&spwd.sp_min, fields[3], NULL, 0, 0, LONG_MAX) == -1) return NULL; - } /* * Get the maximum number of days a password is valid. */ - if (fields[4][0] == '\0') { + if (fields[4][0] == '\0') spwd.sp_max = -1; - } else if ( (str2sl(&spwd.sp_max, fields[4]) == -1) - || (spwd.sp_max < 0)) { + else if (a2sl(&spwd.sp_max, fields[4], NULL, 0, 0, LONG_MAX) == -1) return NULL; - } /* * If there are only OFIELDS fields (this is a SVR3.2 /etc/shadow @@ -130,47 +125,40 @@ sgetspent(const char *string) * Get the number of days of password expiry warning. */ - if (fields[5][0] == '\0') { + if (fields[5][0] == '\0') spwd.sp_warn = -1; - } else if ( (str2sl(&spwd.sp_warn, fields[5]) == -1) - || (spwd.sp_warn < 0)) { + else if (a2sl(&spwd.sp_warn, fields[5], NULL, 0, 0, LONG_MAX) == -1) return NULL; - } /* * Get the number of days of inactivity before an account is * disabled. */ - if (fields[6][0] == '\0') { + if (fields[6][0] == '\0') spwd.sp_inact = -1; - } else if ( (str2sl(&spwd.sp_inact, fields[6]) == -1) - || (spwd.sp_inact < 0)) { + else if (a2sl(&spwd.sp_inact, fields[6], NULL, 0, 0, LONG_MAX) == -1) return NULL; - } /* * Get the number of days after the epoch before the account is * set to expire. */ - if (fields[7][0] == '\0') { + if (fields[7][0] == '\0') spwd.sp_expire = -1; - } else if ( (str2sl(&spwd.sp_expire, fields[7]) == -1) - || (spwd.sp_expire < 0)) { + else if (a2sl(&spwd.sp_expire, fields[7], NULL, 0, 0, LONG_MAX) == -1) return NULL; - } /* * This field is reserved for future use. But it isn't supposed * to have anything other than a valid integer in it. */ - if (fields[8][0] == '\0') { + if (fields[8][0] == '\0') spwd.sp_flag = SHADOW_SP_FLAG_UNSET; - } else if (str2ul(&spwd.sp_flag, fields[8]) == -1) { + else if (str2ul(&spwd.sp_flag, fields[8]) == -1) return NULL; - } return (&spwd); }