diff --git a/nslcd/common.c b/nslcd/common.c index de640b4..60be777 100644 --- a/nslcd/common.c +++ b/nslcd/common.c @@ -338,23 +338,19 @@ unsigned long int binsid2id(const char *binsid) ((((unsigned long int)binsid[i + 3]) & 0xff) << 24); } -/* provide a strtoid() implementation, similar to strtoul() but returning - an range-checked uint32_t instead */ -unsigned int strtoid(const char *nptr,char **endptr,int base) +#ifdef WANT_STRTOUI +/* provide a strtoui() implementation, similar to strtoul() but returning + an range-checked unsigned int instead */ +unsigned int strtoui(const char *nptr, char **endptr, int base) { - long long val; - /* use the fact that long long is 64-bit, even on 32-bit systems */ - val=strtoll(nptr,endptr,base); - if (val>UINT32_MAX) + unsigned long val; + val = strtoul(nptr, endptr, base); + if (val > UINT_MAX) { - errno=ERANGE; - return UINT32_MAX; + errno = ERANGE; + return UINT_MAX; } - else if (val < 0) - { - errno=EINVAL; - return UINT32_MAX; - } - /* If errno was set, we'll pass it back as-is */ - return (uint32_t)val; + /* If errno was set by strtoul, we'll pass it back as-is */ + return (unsigned int)val; } +#endif /* WANT_STRTOUI */ diff --git a/nslcd/common.h b/nslcd/common.h index 97d386e..26fcf48 100644 --- a/nslcd/common.h +++ b/nslcd/common.h @@ -161,10 +161,31 @@ void invalidator_do(enum ldap_map_selector map); #define BUFLEN_HOSTNAME 256 /* host names or FQDN (and safe version) */ #define BUFLEN_MESSAGE 1024 /* message strings */ - -uint32_t strtoid(const char *nptr,char **endptr,int base); -#define strtouid (uid_t)strtoid -#define strtogid (gid_t)strtoid +/* provide strtouid() function alias */ +#if SIZEOF_UID_T == SIZEOF_UNSIGNED_LONG_INT +#define strtouid (uid_t)strtoul +#elif SIZEOF_UID_T == SIZEOF_UNSIGNED_LONG_LONG_INT +#define strtouid (uid_t)strtoull +#elif SIZEOF_UID_T == SIZEOF_UNSIGNED_INT +#define WANT_STRTOUI 1 +#define strtouid (uid_t)strtoui +#else +#error unable to find implementation for strtouid() +#endif + +/* provide strtogid() function alias */ +#if SIZEOF_GID_T == SIZEOF_UNSIGNED_LONG_INT +#define strtogid (gid_t)strtoul +#elif SIZEOF_GID_T == SIZEOF_UNSIGNED_LONG_LONG_INT +#define strtogid (gid_t)strtoull +#elif SIZEOF_GID_T == SIZEOF_UNSIGNED_INT +#ifndef WANT_STRTOUI +#define WANT_STRTOUI 1 +#endif +#define strtogid (gid_t)strtoui +#else +#error unable to find implementation for strtogid() +#endif #ifdef WANT_STRTOUI /* provide a strtoui() if it is needed */ diff --git a/tests/Makefile.am b/tests/Makefile.am index 8c742a7..0a7854e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -22,11 +22,9 @@ TESTS = test_dict test_set test_tio test_expr test_getpeercred test_cfg \ test_attmap test_myldap.sh test_common test_nsscmds.sh \ test_pamcmds.sh test_manpages.sh test_clock \ test_tio_timeout - -#if HAVE_PYTHON -# TESTS += test_pycompile.sh test_pylint.sh -#endif - +if HAVE_PYTHON + TESTS += test_pycompile.sh test_pylint.sh +endif if ENABLE_PYNSLCD TESTS += test_pynslcd_cache.py test_doctest.sh endif