From: Joerg Sonnenberger Date: Sat, 19 Jun 2010 17:25:58 +0000 (-0400) Subject: Fall back to getgrgid and getpwuid if the reentrant versions are missing. X-Git-Tag: v3.0.0a~944 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2730e1cb1dcc8b002dc3bdcd8894f83d477927f4;p=thirdparty%2Flibarchive.git Fall back to getgrgid and getpwuid if the reentrant versions are missing. SVN-Revision: 2490 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 716a70d9d..69107bea3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -492,8 +492,10 @@ CHECK_FUNCTION_EXISTS_GLIBC(ftruncate HAVE_FTRUNCATE) CHECK_FUNCTION_EXISTS_GLIBC(futimens HAVE_FUTIMENS) CHECK_FUNCTION_EXISTS_GLIBC(futimes HAVE_FUTIMES) CHECK_FUNCTION_EXISTS_GLIBC(geteuid HAVE_GETEUID) +CHECK_FUNCTION_EXISTS_GLIBC(getgrgid_r HAVE_GETGRGID_R) CHECK_FUNCTION_EXISTS_GLIBC(getgrnam_r HAVE_GETGRNAM_R) CHECK_FUNCTION_EXISTS_GLIBC(getpwnam_r HAVE_GETPWNAM_R) +CHECK_FUNCTION_EXISTS_GLIBC(getpwuid_r HAVE_GETPWUID_R) CHECK_FUNCTION_EXISTS_GLIBC(getpid HAVE_GETPID) CHECK_FUNCTION_EXISTS_GLIBC(gmtime_r HAVE_GMTIME_R) CHECK_FUNCTION_EXISTS_GLIBC(lchflags HAVE_LCHFLAGS) diff --git a/build/cmake/config.h.in b/build/cmake/config.h.in index 736591898..ba871812e 100644 --- a/build/cmake/config.h.in +++ b/build/cmake/config.h.in @@ -272,12 +272,18 @@ /* Define to 1 if you have the `geteuid' function. */ #cmakedefine HAVE_GETEUID 1 +/* Define to 1 if you have the `getgrgid_r' function. */ +#cmakedefine HAVE_GETGRGID_R + /* Define to 1 if you have the `getgrnam_r' function. */ #cmakedefine HAVE_GETGRNAM_R 1 /* Define to 1 if you have the `getpwnam_r' function. */ #cmakedefine HAVE_GETPWNAM_R 1 +/* Define to 1 if you have the `getpwuid_r' function. */ +#cmakedefine HAVE_GETPWUID_R + /* Define to 1 if you have the `getpid' function. */ #cmakedefine HAVE_GETPID 1 diff --git a/configure.ac b/configure.ac index 3b2fbca59..a0c19505f 100644 --- a/configure.ac +++ b/configure.ac @@ -415,7 +415,7 @@ AC_CHECK_STDCALL_FUNC([CreateHardLinkA],[const char *, const char *, void *]) AC_CHECK_FUNCS([chflags chown chroot ctime_r]) AC_CHECK_FUNCS([fchdir fchflags fchmod fchown fcntl fork]) AC_CHECK_FUNCS([fstat ftruncate futimens futimes geteuid getpid]) -AC_CHECK_FUNCS([getgrnam_r getpwnam_r gmtime_r]) +AC_CHECK_FUNCS([getgrgid_r getgrnam_r getpwnam_r getpwuid_r gmtime_r]) AC_CHECK_FUNCS([lchflags lchmod lchown link localtime_r lstat]) AC_CHECK_FUNCS([lutimes mbrtowc memmove memset mkdir mkfifo mknod mkstemp]) AC_CHECK_FUNCS([nl_langinfo pipe poll readlink]) diff --git a/libarchive/archive_read_disk_set_standard_lookup.c b/libarchive/archive_read_disk_set_standard_lookup.c index ceaf0cf2d..c302b98df 100644 --- a/libarchive/archive_read_disk_set_standard_lookup.c +++ b/libarchive/archive_read_disk_set_standard_lookup.c @@ -192,6 +192,7 @@ lookup_uname(void *data, int64_t uid) &lookup_uname_helper, (id_t)uid)); } +#if HAVE_GETPWUID_R static const char * lookup_uname_helper(struct name_cache *cache, id_t id) { @@ -232,6 +233,20 @@ lookup_uname_helper(struct name_cache *cache, id_t id) return strdup(result->pw_name); } +#else +static const char * +lookup_uname_helper(struct name_cache *cache, id_t id) +{ + struct passwd *result; + + result = getpwuid((uid_t)id); + + if (result == NULL) + return (NULL); + + return strdup(result->pw_name); +} +#endif #if ARCHIVE_VERSION_NUMBER < 3000000 static const char * @@ -246,6 +261,7 @@ lookup_gname(void *data, int64_t gid) &lookup_gname_helper, (id_t)gid)); } +#if HAVE_GETGRGID_R static const char * lookup_gname_helper(struct name_cache *cache, id_t id) { @@ -284,4 +300,19 @@ lookup_gname_helper(struct name_cache *cache, id_t id) return strdup(result->gr_name); } +#else +static const char * +lookup_gname_helper(struct name_cache *cache, id_t id) +{ + struct group *result; + + result = getgrgid((gid_t)id); + + if (result == NULL) + return (NULL); + + return strdup(result->gr_name); +} +#endif + #endif /* ! (_WIN32 && !__CYGWIN__) */