This makes them compatible with liba2i's functions.
Signed-off-by: Alejandro Colomar <alx@kernel.org>
#include "atoi/str2i.h"
-extern inline int getlong(const char *restrict s, long *restrict n);
-extern inline int getulong(const char *restrict s, unsigned long *restrict n);
+extern inline int str2sl(long *restrict n, const char *restrict s);
+extern inline int str2ul(unsigned long *restrict n, const char *restrict s);
#include "attr.h"
-ATTR_STRING(1) ATTR_ACCESS(write_only, 2)
-inline int getlong(const char *restrict s, long *restrict n);
-ATTR_STRING(1) ATTR_ACCESS(write_only, 2)
-inline int getulong(const char *restrict s, unsigned long *restrict n);
+ATTR_STRING(2) ATTR_ACCESS(write_only, 1)
+inline int str2sl(long *restrict n, const char *restrict s);
+ATTR_STRING(2) ATTR_ACCESS(write_only, 1)
+inline int str2ul(unsigned long *restrict n, const char *restrict s);
inline int
-getlong(const char *restrict s, long *restrict n)
+str2sl(long *restrict n, const char *restrict s)
{
return a2sl(n, s, NULL, 0, LONG_MIN, LONG_MAX);
}
inline int
-getulong(const char *restrict s, unsigned long *restrict n)
+str2ul(unsigned long *restrict n, const char *restrict s)
{
return a2ul(n, s, NULL, 0, 0, ULONG_MAX);
}
return dflt;
}
- if ( (getlong(d->value, &val) == -1)
+ if ( (str2sl(&val, d->value) == -1)
|| (val > INT_MAX)
|| (val < -1)) {
fprintf (shadow_logfd,
return dflt;
}
- if ( (getlong(d->value, &val) == -1)
+ if ( (str2sl(&val, d->value) == -1)
|| (val < 0)
|| (val > INT_MAX)) {
fprintf (shadow_logfd,
return dflt;
}
- if (getlong(d->value, &val) == -1 || val < -1) {
+ if (str2sl(&val, d->value) == -1 || val < -1) {
fprintf (shadow_logfd,
_("configuration error - cannot parse %s value: '%s'"),
item, d->value);
return dflt;
}
- if (getulong(d->value, &val) == -1) {
+ if (str2ul(&val, d->value) == -1) {
fprintf (shadow_logfd,
_("configuration error - cannot parse %s value: '%s'"),
item, d->value);
/* Gather up the ranges from the command line */
mapping = mappings;
for (idx = 0, argidx = 0; idx < ranges; idx++, argidx += 3, mapping++) {
- if (getulong(argv[argidx + 0], &mapping->upper) == -1) {
+ if (str2ul(&mapping->upper, argv[argidx + 0]) == -1) {
free(mappings);
return NULL;
}
- if (getulong(argv[argidx + 1], &mapping->lower) == -1) {
+ if (str2ul(&mapping->lower, argv[argidx + 1]) == -1) {
free(mappings);
return NULL;
}
- if (getulong(argv[argidx + 2], &mapping->count) == -1) {
+ if (str2ul(&mapping->count, argv[argidx + 2]) == -1) {
free(mappings);
return NULL;
}
limit = RLIM_INFINITY;
}
else {
- /* We cannot use getlong here because it fails when there
+ /* We cannot use str2sl() here because it fails when there
* is more to the value than just this number!
* Also, we are limited to base 10 here (hex numbers will not
* work with the limit string parser as is anyway)
{
long prio;
- if ( (getlong(value, &prio) == -1)
+ if ( (str2sl(&prio, value) == -1)
|| (prio != (int) prio)) {
return 0;
}
{
unsigned long mask;
- if ( (getulong(value, &mask) == -1)
+ if ( (str2ul(&mask, value) == -1)
|| (mask != (mode_t) mask)) {
return 0;
}
{
unsigned long limit, count;
- if (getulong(maxlogins, &limit) == -1) {
+ if (str2ul(&limit, maxlogins) == -1) {
return 0;
}
if (strncmp (cp, "pri=", 4) == 0) {
long inc;
- if ( (getlong(cp + 4, &inc) == 0)
+ if ( (str2sl(&inc, cp + 4) == 0)
&& (inc >= -20) && (inc <= 20)) {
errno = 0;
if ( (nice (inc) != -1)
}
if (strncmp (cp, "ulimit=", 7) == 0) {
long blocks;
- if ( (getlong(cp + 7, &blocks) == -1)
+ if ( (str2sl(&blocks, cp + 7) == -1)
|| (blocks != (int) blocks)
|| (set_filesize_limit (blocks) != 0)) {
SYSLOG ((LOG_WARN,
if (strncmp (cp, "umask=", 6) == 0) {
unsigned long mask;
- if ( (getulong(cp + 6, &mask) == -1)
+ if ( (str2ul(&mask, cp + 6) == -1)
|| (mask != (mode_t) mask)) {
SYSLOG ((LOG_WARN,
"Can't set umask value for user %s",
*cp = '\0';
cp++;
- if (getulong(cp, &remote_speed) == -1) {
+ if (str2ul(&remote_speed, cp) == -1)
remote_speed = 9600;
- }
}
for (i = 0;
( (speed_table[i].spd_baud != remote_speed)
if (fields[2][0] == '\0') {
spwd.sp_lstchg = -1;
- } else if ( (getlong(fields[2], &spwd.sp_lstchg) == -1)
+ } else if ( (str2sl(&spwd.sp_lstchg, fields[2]) == -1)
|| (spwd.sp_lstchg < 0)) {
return NULL;
}
if (fields[3][0] == '\0') {
spwd.sp_min = -1;
- } else if ( (getlong(fields[3], &spwd.sp_min) == -1)
+ } else if ( (str2sl(&spwd.sp_min, fields[3]) == -1)
|| (spwd.sp_min < 0)) {
return NULL;
}
if (fields[4][0] == '\0') {
spwd.sp_max = -1;
- } else if ( (getlong(fields[4], &spwd.sp_max) == -1)
+ } else if ( (str2sl(&spwd.sp_max, fields[4]) == -1)
|| (spwd.sp_max < 0)) {
return NULL;
}
if (fields[5][0] == '\0') {
spwd.sp_warn = -1;
- } else if ( (getlong(fields[5], &spwd.sp_warn) == -1)
+ } else if ( (str2sl(&spwd.sp_warn, fields[5]) == -1)
|| (spwd.sp_warn < 0)) {
return NULL;
}
if (fields[6][0] == '\0') {
spwd.sp_inact = -1;
- } else if ( (getlong(fields[6], &spwd.sp_inact) == -1)
+ } else if ( (str2sl(&spwd.sp_inact, fields[6]) == -1)
|| (spwd.sp_inact < 0)) {
return NULL;
}
if (fields[7][0] == '\0') {
spwd.sp_expire = -1;
- } else if ( (getlong(fields[7], &spwd.sp_expire) == -1)
+ } else if ( (str2sl(&spwd.sp_expire, fields[7]) == -1)
|| (spwd.sp_expire < 0)) {
return NULL;
}
if (fields[8][0] == '\0') {
spwd.sp_flag = SHADOW_SP_FLAG_UNSET;
- } else if (getulong(fields[8], &spwd.sp_flag) == -1) {
+ } else if (str2ul(&spwd.sp_flag, fields[8]) == -1) {
return NULL;
}
if (fields[2][0] == '\0') {
spwd.sp_lstchg = -1;
} else {
- if (getlong(fields[2], &spwd.sp_lstchg) == -1)
+ if (str2sl(&spwd.sp_lstchg, fields[2]) == -1)
return 0;
if (spwd.sp_lstchg < 0)
return 0;
if (fields[3][0] == '\0') {
spwd.sp_min = -1;
} else {
- if (getlong(fields[3], &spwd.sp_min) == -1)
+ if (str2sl(&spwd.sp_min, fields[3]) == -1)
return 0;
if (spwd.sp_min < 0)
return 0;
if (fields[4][0] == '\0') {
spwd.sp_max = -1;
} else {
- if (getlong(fields[4], &spwd.sp_max) == -1)
+ if (str2sl(&spwd.sp_max, fields[4]) == -1)
return 0;
if (spwd.sp_max < 0)
return 0;
if (fields[5][0] == '\0') {
spwd.sp_warn = -1;
} else {
- if (getlong(fields[5], &spwd.sp_warn) == -1)
+ if (str2sl(&spwd.sp_warn, fields[5]) == -1)
return 0;
if (spwd.sp_warn < 0)
return 0;
if (fields[6][0] == '\0') {
spwd.sp_inact = -1;
} else {
- if (getlong(fields[6], &spwd.sp_inact) == -1)
+ if (str2sl(&spwd.sp_inact, fields[6]) == -1)
return 0;
if (spwd.sp_inact < 0)
return 0;
if (fields[7][0] == '\0') {
spwd.sp_expire = -1;
} else {
- if (getlong(fields[7], &spwd.sp_expire) == -1)
+ if (str2sl(&spwd.sp_expire, fields[7]) == -1)
return 0;
if (spwd.sp_expire < 0)
return 0;
if (fields[8][0] == '\0') {
spwd.sp_flag = SHADOW_SP_FLAG_UNSET;
} else {
- if (getulong(fields[8], &spwd.sp_flag) == -1)
+ if (str2ul(&spwd.sp_flag, fields[8]) == -1)
return 0;
if (spwd.sp_flag < 0)
return 0;
}
if (isnum) {
long retdate;
- if (getlong(str, &retdate) == -1) {
+ if (str2sl(&retdate, str) == -1)
return -2;
- }
return retdate;
}
if (i != SUBID_NFIELDS || *fields[0] == '\0' || *fields[1] == '\0' || *fields[2] == '\0')
return NULL;
range.owner = fields[0];
- if (getulong(fields[1], &range.start) == -1)
+ if (str2ul(&range.start, fields[1]) == -1)
return NULL;
- if (getulong(fields[2], &range.count) == -1)
+ if (str2ul(&range.count, fields[2]) == -1)
return NULL;
return ⦥
SNPRINTF(buf, "%ld", mindays);
change_field (buf, sizeof buf, _("Minimum Password Age"));
- if ( (getlong(buf, &mindays) == -1)
+ if ( (str2sl(&mindays, buf) == -1)
|| (mindays < -1)) {
return 0;
}
SNPRINTF(buf, "%ld", maxdays);
change_field (buf, sizeof buf, _("Maximum Password Age"));
- if ( (getlong(buf, &maxdays) == -1)
+ if ( (str2sl(&maxdays, buf) == -1)
|| (maxdays < -1)) {
return 0;
}
SNPRINTF(buf, "%ld", warndays);
change_field (buf, sizeof buf, _("Password Expiration Warning"));
- if ( (getlong(buf, &warndays) == -1)
+ if ( (str2sl(&warndays, buf) == -1)
|| (warndays < -1)) {
return 0;
}
SNPRINTF(buf, "%ld", inactdays);
change_field (buf, sizeof buf, _("Password Inactive"));
- if ( (getlong(buf, &inactdays) == -1)
+ if ( (str2sl(&inactdays, buf) == -1)
|| (inactdays < -1)) {
return 0;
}
break;
case 'I':
Iflg = true;
- if ( (getlong(optarg, &inactdays) == -1)
+ if ( (str2sl(&inactdays, optarg) == -1)
|| (inactdays < -1)) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
break;
case 'm':
mflg = true;
- if ( (getlong(optarg, &mindays) == -1)
+ if ( (str2sl(&mindays, optarg) == -1)
|| (mindays < -1)) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
break;
case 'M':
Mflg = true;
- if ( (getlong(optarg, &maxdays) == -1)
+ if ( (str2sl(&maxdays, optarg) == -1)
|| (maxdays < -1)) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
break;
case 'W':
Wflg = true;
- if ( (getlong(optarg, &warndays) == -1)
+ if ( (str2sl(&warndays, optarg) == -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")))
- && (-1 == getlong(optarg, &sha_rounds)))) {
+ && (-1 == str2sl(&sha_rounds, optarg)))) {
bad_s = 1;
}
#endif /* USE_SHA_CRYPT */
#if defined(USE_BCRYPT)
if (( (0 == strcmp (crypt_method, "BCRYPT"))
- && (-1 == getlong(optarg, &bcrypt_rounds)))) {
+ && (-1 == str2sl(&bcrypt_rounds, optarg)))) {
bad_s = 1;
}
#endif /* USE_BCRYPT */
#if defined(USE_YESCRYPT)
if (( (0 == strcmp (crypt_method, "YESCRYPT"))
- && (-1 == getlong(optarg, &yescrypt_cost)))) {
+ && (-1 == str2sl(&yescrypt_cost, optarg)))) {
bad_s = 1;
}
#endif /* USE_YESCRYPT */
bad_s = 0;
#if defined(USE_SHA_CRYPT)
if ((IS_CRYPT_METHOD("SHA256") || IS_CRYPT_METHOD("SHA512"))
- && (-1 == getlong(optarg, &sha_rounds))) {
+ && (-1 == str2sl(&sha_rounds, optarg))) {
bad_s = 1;
}
#endif /* USE_SHA_CRYPT */
#if defined(USE_BCRYPT)
if (IS_CRYPT_METHOD("BCRYPT")
- && (-1 == getlong(optarg, &bcrypt_rounds))) {
+ && (-1 == str2sl(&bcrypt_rounds, optarg))) {
bad_s = 1;
}
#endif /* USE_BCRYPT */
#if defined(USE_YESCRYPT)
if (IS_CRYPT_METHOD("YESCRYPT")
- && (-1 == getlong(optarg, &yescrypt_cost))) {
+ && (-1 == str2sl(&yescrypt_cost, optarg))) {
bad_s = 1;
}
#endif /* USE_YESCRYPT */
usage (E_SUCCESS);
/*@notreached@*/break;
case 'l':
- if (getlong(optarg, &fail_locktime) == -1) {
+ if (str2sl(&fail_locktime, optarg) == -1) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
{
long lmax;
- if ( (getlong(optarg, &lmax) == -1)
+ if ( (str2sl(&lmax, optarg) == -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) == -1) {
+ if (str2sl(&days, optarg) == -1) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
case 'b':
{
unsigned long inverse_days;
- if (getulong(optarg, &inverse_days) == -1) {
+ if (str2ul(&inverse_days, optarg) == -1) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
case 't':
{
unsigned long days;
- if (getulong(optarg, &days) == -1) {
+ if (str2ul(&days, optarg) == -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")))
- && (-1 == getlong(optarg, &sha_rounds)))) {
+ && (-1 == str2sl(&sha_rounds, optarg)))) {
bad_s = 1;
}
#endif /* USE_SHA_CRYPT */
#if defined(USE_BCRYPT)
if (( (0 == strcmp (crypt_method, "BCRYPT"))
- && (-1 == getlong(optarg, &bcrypt_rounds)))) {
+ && (-1 == str2sl(&bcrypt_rounds, optarg)))) {
bad_s = 1;
}
#endif /* USE_BCRYPT */
#if defined(USE_YESCRYPT)
if (( (0 == strcmp (crypt_method, "YESCRYPT"))
- && (-1 == getlong(optarg, &yescrypt_cost)))) {
+ && (-1 == str2sl(&yescrypt_cost, optarg)))) {
bad_s = 1;
}
#endif /* USE_YESCRYPT */
usage (E_SUCCESS);
/*@notreached@*/break;
case 'i':
- if ( (getlong(optarg, &inact) == -1)
+ if ( (str2sl(&inact, optarg) == -1)
|| (inact < -1)) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
anyflag = true;
break;
case 'n':
- if ( (getlong(optarg, &age_min) == -1)
+ if ( (str2sl(&age_min, optarg) == -1)
|| (age_min < -1)) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
anyflag = true;
break;
case 'w':
- if ( (getlong(optarg, &warn) == -1)
+ if ( (str2sl(&warn, optarg) == -1)
|| (warn < -1)) {
(void) fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
anyflag = true;
break;
case 'x':
- if ( (getlong(optarg, &age_max) == -1)
+ if ( (str2sl(&age_max, optarg) == -1)
|| (age_max < -1)) {
(void) fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
* Default Password Inactive value
*/
else if (MATCH (buf, DINACT)) {
- if ( (getlong(ccp, &def_inactive) == -1)
+ if ( (str2sl(&def_inactive, ccp) == -1)
|| (def_inactive < -1)) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
eflg = true;
break;
case 'f':
- if ( (getlong(optarg, &def_inactive) == -1)
+ if ( (str2sl(&def_inactive, optarg) == -1)
|| (def_inactive < -1)) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
eflg = true;
break;
case 'f':
- if ( (getlong(optarg, &user_newinactive) == -1)
+ if ( (str2sl(&user_newinactive, optarg) == -1)
|| (user_newinactive < -1)) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),