diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2011-08-29 20:57:37 +0000 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2011-08-29 20:57:37 +0000 |
commit | ef4080e37a8827ba611246465c448b2324bada41 (patch) | |
tree | 74c268a454c2146a6dbbf719f527e917e4f251b9 | |
parent | 8a356210e1cd0b63da5ea3b07b469db1bfe0f217 (diff) |
implement and use a strtoui() function if uid_t or gid_t is of size unsigned int (thanks Jakub Hrozek)
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-pam-ldapd@1528 ef36b2f9-881f-0410-afb5-c4e39611909c
-rw-r--r-- | configure.ac | 3 | ||||
-rw-r--r-- | nslcd/common.c | 17 | ||||
-rw-r--r-- | nslcd/common.h | 13 |
3 files changed, 32 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac index bc1c9a1..2f123e5 100644 --- a/configure.ac +++ b/configure.ac @@ -289,7 +289,7 @@ AC_C_CONST AC_CHECK_FUNCS([sigaction snprintf]) AC_CHECK_FUNCS(gethostbyname) AC_SEARCH_LIBS(socket,socket) -AC_CHECK_FUNCS([strcasecmp strncasecmp strchr strcspn strspn strtol]) +AC_CHECK_FUNCS([strcasecmp strncasecmp strchr strcspn strspn strtol strtoul strtoull]) AC_CHECK_FUNCS([malloc realloc]) AC_FUNC_FORK AC_CHECK_FUNCS(__assert_fail) @@ -303,6 +303,7 @@ AC_TYPE_INT32_T AC_TYPE_UINT8_T AC_TYPE_UINT16_T AC_TYPE_UINT32_T +AC_CHECK_SIZEOF(unsigned int) AC_CHECK_SIZEOF(unsigned long int) AC_CHECK_SIZEOF(unsigned long long int) AC_CHECK_SIZEOF(uid_t) diff --git a/nslcd/common.c b/nslcd/common.c index cb94c2f..264439a 100644 --- a/nslcd/common.c +++ b/nslcd/common.c @@ -269,3 +269,20 @@ long int binsid2id(const char *binsid) return (((long int)binsid[i])&0xff)|((((long int)binsid[i+1])&0xff)<<8)| ((((long int)binsid[i+2])&0xff)<<16)|((((long int)binsid[i+3])&0xff)<<24); } + +#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) +{ + unsigned long val; + val=strtoul(nptr,endptr,base); + if (val>UINT_MAX) + { + errno=ERANGE; + return UINT_MAX; + } + /* If errno was set by strtoull, 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 9e41c30..63a535f 100644 --- a/nslcd/common.h +++ b/nslcd/common.h @@ -138,6 +138,9 @@ int nsswitch_db_uses_ldap(const char *filename,const char *db); #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 @@ -147,10 +150,20 @@ int nsswitch_db_uses_ldap(const char *filename,const char *db); #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 (uid_t)strtoui #else #error unable to find implementation for strtogid() #endif +#ifdef WANT_STRTOUI +/* provide a strtoui() if it is needed */ +unsigned int strtoui(const char *nptr,char **endptr,int base); +#endif /* WANT_STRTOUI */ + /* these are the functions for initialising the database specific modules */ void alias_init(void); |