summaryrefslogtreecommitdiff
path: root/nslcd
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2011-08-29 20:57:37 +0000
committerArthur de Jong <arthur@arthurdejong.org>2011-08-29 20:57:37 +0000
commitef4080e37a8827ba611246465c448b2324bada41 (patch)
tree74c268a454c2146a6dbbf719f527e917e4f251b9 /nslcd
parent8a356210e1cd0b63da5ea3b07b469db1bfe0f217 (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
Diffstat (limited to 'nslcd')
-rw-r--r--nslcd/common.c17
-rw-r--r--nslcd/common.h13
2 files changed, 30 insertions, 0 deletions
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);