return dflt;
}
- if ( (getlong (d->value, &val) == 0)
+ if ( (getlong(d->value, &val) == -1)
|| (val > INT_MAX)
|| (val < -1)) {
fprintf (shadow_logfd,
return dflt;
}
- if ( (getlong (d->value, &val) == 0)
+ if ( (getlong(d->value, &val) == -1)
|| (val < 0)
|| (val > INT_MAX)) {
fprintf (shadow_logfd,
return dflt;
}
- if ( (getlong (d->value, &val) == 0)
- || (val < -1)) {
+ if (getlong(d->value, &val) == -1 || val < -1) {
fprintf (shadow_logfd,
_("configuration error - cannot parse %s value: '%s'"),
item, d->value);
* SPDX-License-Identifier: BSD-3-Clause
*/
+
#include <config.h>
#ident "$Id$"
#include <stdlib.h>
#include <errno.h>
+
#include "prototypes.h"
+
/*
* getlong - extract a long integer provided by the numstr string in *result
*
* It supports decimal, hexadecimal or octal representations.
- *
- * Returns 0 on failure, 1 on success.
*/
-int getlong (const char *numstr, /*@out@*/long *result)
+int
+getlong(const char *numstr, /*@out@*/long *result)
{
- long val;
- char *endptr;
+ char *endptr;
+ long val;
errno = 0;
val = strtol(numstr, &endptr, 0);
- if (('\0' == *numstr) || ('\0' != *endptr) || (0 != errno)) {
- return 0;
- }
+ if (('\0' == *numstr) || ('\0' != *endptr) || (0 != errno))
+ return -1;
*result = val;
- return 1;
+ return 0;
}
-
{
long prio;
- if ( (getlong (value, &prio) == 0)
+ if ( (getlong(value, &prio) == -1)
|| (prio != (int) prio)) {
return 0;
}
if (strncmp (cp, "pri=", 4) == 0) {
long inc;
- if ( (getlong (cp + 4, &inc) == 1)
+ if ( (getlong(cp + 4, &inc) == 0)
&& (inc >= -20) && (inc <= 20)) {
errno = 0;
if ( (nice (inc) != -1)
}
if (strncmp (cp, "ulimit=", 7) == 0) {
long blocks;
-
- if ( (getlong (cp + 7, &blocks) == 0)
+ if ( (getlong(cp + 7, &blocks) == -1)
|| (blocks != (int) blocks)
|| (set_filesize_limit (blocks) != 0)) {
SYSLOG ((LOG_WARN,
if (fields[2][0] == '\0') {
spwd.sp_lstchg = -1;
- } else if ( (getlong (fields[2], &spwd.sp_lstchg) == 0)
+ } else if ( (getlong(fields[2], &spwd.sp_lstchg) == -1)
|| (spwd.sp_lstchg < 0)) {
return 0;
}
if (fields[3][0] == '\0') {
spwd.sp_min = -1;
- } else if ( (getlong (fields[3], &spwd.sp_min) == 0)
+ } else if ( (getlong(fields[3], &spwd.sp_min) == -1)
|| (spwd.sp_min < 0)) {
return 0;
}
if (fields[4][0] == '\0') {
spwd.sp_max = -1;
- } else if ( (getlong (fields[4], &spwd.sp_max) == 0)
+ } else if ( (getlong(fields[4], &spwd.sp_max) == -1)
|| (spwd.sp_max < 0)) {
return 0;
}
if (fields[5][0] == '\0') {
spwd.sp_warn = -1;
- } else if ( (getlong (fields[5], &spwd.sp_warn) == 0)
+ } else if ( (getlong(fields[5], &spwd.sp_warn) == -1)
|| (spwd.sp_warn < 0)) {
return 0;
}
if (fields[6][0] == '\0') {
spwd.sp_inact = -1;
- } else if ( (getlong (fields[6], &spwd.sp_inact) == 0)
+ } else if ( (getlong(fields[6], &spwd.sp_inact) == -1)
|| (spwd.sp_inact < 0)) {
return 0;
}
if (fields[7][0] == '\0') {
spwd.sp_expire = -1;
- } else if ( (getlong (fields[7], &spwd.sp_expire) == 0)
+ } else if ( (getlong(fields[7], &spwd.sp_expire) == -1)
|| (spwd.sp_expire < 0)) {
return 0;
}
if (fields[2][0] == '\0') {
spwd.sp_lstchg = -1;
} else {
- if (getlong (fields[2], &spwd.sp_lstchg) == 0) {
+ if (getlong(fields[2], &spwd.sp_lstchg) == -1) {
#ifdef USE_NIS
if (nis_used) {
spwd.sp_lstchg = -1;
if (fields[3][0] == '\0') {
spwd.sp_min = -1;
} else {
- if (getlong (fields[3], &spwd.sp_min) == 0) {
+ if (getlong(fields[3], &spwd.sp_min) == -1) {
#ifdef USE_NIS
if (nis_used) {
spwd.sp_min = -1;
if (fields[4][0] == '\0') {
spwd.sp_max = -1;
} else {
- if (getlong (fields[4], &spwd.sp_max) == 0) {
+ if (getlong(fields[4], &spwd.sp_max) == -1) {
#ifdef USE_NIS
if (nis_used) {
spwd.sp_max = -1;
if (fields[5][0] == '\0') {
spwd.sp_warn = -1;
} else {
- if (getlong (fields[5], &spwd.sp_warn) == 0) {
+ if (getlong(fields[5], &spwd.sp_warn) == -1) {
#ifdef USE_NIS
if (nis_used) {
spwd.sp_warn = -1;
if (fields[6][0] == '\0') {
spwd.sp_inact = -1;
} else {
- if (getlong (fields[6], &spwd.sp_inact) == 0) {
+ if (getlong(fields[6], &spwd.sp_inact) == -1) {
#ifdef USE_NIS
if (nis_used) {
spwd.sp_inact = -1;
if (fields[7][0] == '\0') {
spwd.sp_expire = -1;
} else {
- if (getlong (fields[7], &spwd.sp_expire) == 0) {
+ if (getlong(fields[7], &spwd.sp_expire) == -1) {
#ifdef USE_NIS
if (nis_used) {
spwd.sp_expire = -1;
}
if (isnum) {
long retdate;
- if (getlong (str, &retdate) == 0) {
+ if (getlong(str, &retdate) == -1) {
return -2;
}
return retdate;
SNPRINTF(buf, "%ld", mindays);
change_field (buf, sizeof buf, _("Minimum Password Age"));
- if ( (getlong (buf, &mindays) == 0)
+ if ( (getlong(buf, &mindays) == -1)
|| (mindays < -1)) {
return 0;
}
SNPRINTF(buf, "%ld", maxdays);
change_field (buf, sizeof buf, _("Maximum Password Age"));
- if ( (getlong (buf, &maxdays) == 0)
+ if ( (getlong(buf, &maxdays) == -1)
|| (maxdays < -1)) {
return 0;
}
SNPRINTF(buf, "%ld", warndays);
change_field (buf, sizeof buf, _("Password Expiration Warning"));
- if ( (getlong (buf, &warndays) == 0)
+ if ( (getlong(buf, &warndays) == -1)
|| (warndays < -1)) {
return 0;
}
SNPRINTF(buf, "%ld", inactdays);
change_field (buf, sizeof buf, _("Password Inactive"));
- if ( (getlong (buf, &inactdays) == 0)
+ if ( (getlong(buf, &inactdays) == -1)
|| (inactdays < -1)) {
return 0;
}
break;
case 'I':
Iflg = true;
- if ( (getlong (optarg, &inactdays) == 0)
+ if ( (getlong(optarg, &inactdays) == -1)
|| (inactdays < -1)) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
break;
case 'm':
mflg = true;
- if ( (getlong (optarg, &mindays) == 0)
+ if ( (getlong(optarg, &mindays) == -1)
|| (mindays < -1)) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
break;
case 'M':
Mflg = true;
- if ( (getlong (optarg, &maxdays) == 0)
+ if ( (getlong(optarg, &maxdays) == -1)
|| (maxdays < -1)) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
break;
case 'W':
Wflg = true;
- if ( (getlong (optarg, &warndays) == 0)
+ if ( (getlong(optarg, &warndays) == -1)
|| (warndays < -1)) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
}
#if defined(USE_SHA_CRYPT)
if ( ( ((0 == strcmp (crypt_method, "SHA256")) || (0 == strcmp (crypt_method, "SHA512")))
- && (0 == getlong(optarg, &sha_rounds)))) {
+ && (-1 == getlong(optarg, &sha_rounds)))) {
bad_s = 1;
}
#endif /* USE_SHA_CRYPT */
#if defined(USE_BCRYPT)
if (( (0 == strcmp (crypt_method, "BCRYPT"))
- && (0 == getlong(optarg, &bcrypt_rounds)))) {
+ && (-1 == getlong(optarg, &bcrypt_rounds)))) {
bad_s = 1;
}
#endif /* USE_BCRYPT */
#if defined(USE_YESCRYPT)
if (( (0 == strcmp (crypt_method, "YESCRYPT"))
- && (0 == getlong(optarg, &yescrypt_cost)))) {
+ && (-1 == getlong(optarg, &yescrypt_cost)))) {
bad_s = 1;
}
#endif /* USE_YESCRYPT */
bad_s = 0;
#if defined(USE_SHA_CRYPT)
if ((IS_CRYPT_METHOD("SHA256") || IS_CRYPT_METHOD("SHA512"))
- && (0 == getlong(optarg, &sha_rounds))) {
+ && (-1 == getlong(optarg, &sha_rounds))) {
bad_s = 1;
}
#endif /* USE_SHA_CRYPT */
#if defined(USE_BCRYPT)
if (IS_CRYPT_METHOD("BCRYPT")
- && (0 == getlong(optarg, &bcrypt_rounds))) {
+ && (-1 == getlong(optarg, &bcrypt_rounds))) {
bad_s = 1;
}
#endif /* USE_BCRYPT */
#if defined(USE_YESCRYPT)
if (IS_CRYPT_METHOD("YESCRYPT")
- && (0 == getlong(optarg, &yescrypt_cost))) {
+ && (-1 == getlong(optarg, &yescrypt_cost))) {
bad_s = 1;
}
#endif /* USE_YESCRYPT */
usage (E_SUCCESS);
/*@notreached@*/break;
case 'l':
- if (getlong (optarg, &fail_locktime) == 0) {
+ if (getlong(optarg, &fail_locktime) == -1) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
{
long lmax;
- if ( (getlong (optarg, &lmax) == 0)
+ if ( (getlong(optarg, &lmax) == -1)
|| ((long)(short) lmax != lmax)) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
case 'R': /* no-op, handled in process_root_flag () */
break;
case 't':
- if (getlong (optarg, &days) == 0) {
+ if (getlong(optarg, &days) == -1) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
}
#if defined(USE_SHA_CRYPT)
if ( ( ((0 == strcmp (crypt_method, "SHA256")) || (0 == strcmp (crypt_method, "SHA512")))
- && (0 == getlong(optarg, &sha_rounds)))) {
+ && (-1 == getlong(optarg, &sha_rounds)))) {
bad_s = 1;
}
#endif /* USE_SHA_CRYPT */
#if defined(USE_BCRYPT)
if (( (0 == strcmp (crypt_method, "BCRYPT"))
- && (0 == getlong(optarg, &bcrypt_rounds)))) {
+ && (-1 == getlong(optarg, &bcrypt_rounds)))) {
bad_s = 1;
}
#endif /* USE_BCRYPT */
#if defined(USE_YESCRYPT)
if (( (0 == strcmp (crypt_method, "YESCRYPT"))
- && (0 == getlong(optarg, &yescrypt_cost)))) {
+ && (-1 == getlong(optarg, &yescrypt_cost)))) {
bad_s = 1;
}
#endif /* USE_YESCRYPT */
usage (E_SUCCESS);
/*@notreached@*/break;
case 'i':
- if ( (getlong (optarg, &inact) == 0)
+ if ( (getlong(optarg, &inact) == -1)
|| (inact < -1)) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
anyflag = true;
break;
case 'n':
- if ( (getlong (optarg, &age_min) == 0)
+ if ( (getlong(optarg, &age_min) == -1)
|| (age_min < -1)) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
anyflag = true;
break;
case 'w':
- if ( (getlong (optarg, &warn) == 0)
+ if ( (getlong(optarg, &warn) == -1)
|| (warn < -1)) {
(void) fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
anyflag = true;
break;
case 'x':
- if ( (getlong (optarg, &age_max) == 0)
+ if ( (getlong(optarg, &age_max) == -1)
|| (age_max < -1)) {
(void) fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
* Default Password Inactive value
*/
else if (MATCH (buf, DINACT)) {
- if ( (getlong (cp, &def_inactive) == 0)
+ if ( (getlong(cp, &def_inactive) == -1)
|| (def_inactive < -1)) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
eflg = true;
break;
case 'f':
- if ( (getlong (optarg, &def_inactive) == 0)
+ if ( (getlong(optarg, &def_inactive) == -1)
|| (def_inactive < -1)) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
eflg = true;
break;
case 'f':
- if ( (getlong (optarg, &user_newinactive) == 0)
+ if ( (getlong(optarg, &user_newinactive) == -1)
|| (user_newinactive < -1)) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),