summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2011-08-27 21:22:40 +0000
committerArthur de Jong <arthur@arthurdejong.org>2011-08-27 21:22:40 +0000
commita0058c9c879aa255f480c2f7a96d2f6b34ad0c5a (patch)
treee34c9c8a668d93a31391f9a27f81ed5fde5b409a
parentdb932574059069ddb8b3fe2b8c06ca854fff7342 (diff)
provide strtouid() and strtogid() functions that use strtoul() or strtoull() (thanks Jakub Hrozek)
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-pam-ldapd@1524 ef36b2f9-881f-0410-afb5-c4e39611909c
-rw-r--r--configure.ac4
-rw-r--r--nslcd/cfg.c4
-rw-r--r--nslcd/common.h18
-rw-r--r--nslcd/group.c2
-rw-r--r--nslcd/passwd.c6
5 files changed, 28 insertions, 6 deletions
diff --git a/configure.ac b/configure.ac
index 2716652..36eeaba 100644
--- a/configure.ac
+++ b/configure.ac
@@ -303,6 +303,10 @@ AC_TYPE_INT32_T
AC_TYPE_UINT8_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
+AC_CHECK_SIZEOF(unsigned long int)
+AC_CHECK_SIZEOF(unsigned long long int)
+AC_CHECK_SIZEOF(uid_t)
+AC_CHECK_SIZEOF(gid_t)
# check for support for the __thread keyword
AC_CACHE_CHECK([whether $CC supports '__thread'], [mn_cv_c___thread_supported],
diff --git a/nslcd/cfg.c b/nslcd/cfg.c
index 5c249c5..00dd8c4 100644
--- a/nslcd/cfg.c
+++ b/nslcd/cfg.c
@@ -431,7 +431,7 @@ static void get_uid(const char *filename,int lnr,
check_argumentcount(filename,lnr,keyword,get_token(line,token,sizeof(token))!=NULL);
/* check if it is a valid numerical uid */
errno=0;
- *var=(uid_t)strtol(token,&tmp,0);
+ *var=strtouid(token,&tmp,0);
if ((*token!='\0')&&(*tmp=='\0')&&(errno==0))
return;
/* find by name */
@@ -457,7 +457,7 @@ static void get_gid(const char *filename,int lnr,
check_argumentcount(filename,lnr,keyword,get_token(line,token,sizeof(token))!=NULL);
/* check if it is a valid numerical gid */
errno=0;
- *var=(gid_t)strtol(token,&tmp,0);
+ *var=strtogid(token,&tmp,0);
if ((*token!='\0')&&(*tmp=='\0')&&(errno==0))
return;
/* find by name */
diff --git a/nslcd/common.h b/nslcd/common.h
index a998bff..9e41c30 100644
--- a/nslcd/common.h
+++ b/nslcd/common.h
@@ -133,6 +133,24 @@ int nsswitch_db_uses_ldap(const char *filename,const char *db);
#endif /* _POSIX_HOST_NAME_MAX */
#endif /* not HOST_NAME_MAX */
+/* 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
+#else
+#error unable to find implementation for strtouid()
+#endif
+
+/* provide strtouid() 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
+#else
+#error unable to find implementation for strtogid()
+#endif
+
/* these are the functions for initialising the database specific
modules */
void alias_init(void);
diff --git a/nslcd/group.c b/nslcd/group.c
index 7ee22e8..010240a 100644
--- a/nslcd/group.c
+++ b/nslcd/group.c
@@ -281,7 +281,7 @@ static int write_group(TFILE *fp,MYLDAP_ENTRY *entry,const char *reqname,
else
{
errno=0;
- gids[numgids]=(gid_t)strtol(gidvalues[numgids],&tmp,0);
+ gids[numgids]=strtogid(gidvalues[numgids],&tmp,0);
if ((*(gidvalues[numgids])=='\0')||(*tmp!='\0'))
{
log_log(LOG_WARNING,"group entry %s contains non-numeric %s value",
diff --git a/nslcd/passwd.c b/nslcd/passwd.c
index d20531d..06e33c2 100644
--- a/nslcd/passwd.c
+++ b/nslcd/passwd.c
@@ -195,7 +195,7 @@ static int entry_has_valid_uid(MYLDAP_ENTRY *entry)
else
{
errno=0;
- uid=(uid_t)strtol(values[i],&tmp,0);
+ uid=strtouid(values[i],&tmp,0);
if ((*(values[i])=='\0')||(*tmp!='\0'))
{
log_log(LOG_WARNING,"passwd entry %s contains non-numeric %s value",
@@ -489,7 +489,7 @@ static int write_passwd(TFILE *fp,MYLDAP_ENTRY *entry,const char *requser,
else
{
errno=0;
- uids[numuids]=(uid_t)strtol(tmpvalues[numuids],&tmp,0);
+ uids[numuids]=strtouid(tmpvalues[numuids],&tmp,0);
if ((*(tmpvalues[numuids])=='\0')||(*tmp!='\0'))
{
log_log(LOG_WARNING,"passwd entry %s contains non-numeric %s value",
@@ -527,7 +527,7 @@ static int write_passwd(TFILE *fp,MYLDAP_ENTRY *entry,const char *requser,
return 0;
}
errno=0;
- gid=(gid_t)strtol(gidbuf,&tmp,0);
+ gid=strtogid(gidbuf,&tmp,0);
if ((gidbuf[0]=='\0')||(*tmp!='\0'))
{
log_log(LOG_WARNING,"passwd entry %s contains non-numeric %s value",