From: Joerg Sonnenberger Date: Wed, 31 Mar 2010 13:56:55 +0000 (-0400) Subject: getgrnam_r and getpwnam_r might not exist, so fallback to the older X-Git-Tag: v3.0.0a~1134 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d45151bf135724291296d478016ac270198cc3e7;p=thirdparty%2Flibarchive.git getgrnam_r and getpwnam_r might not exist, so fallback to the older non-reentrant getgrnam and getpwnam in that case. Based on patch from Hauke Fath. SVN-Revision: 2058 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 44c6a3f07..74737787c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -387,6 +387,8 @@ 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(getgrnam_r HAVE_GETGRNAM_R) +CHECK_FUNCTION_EXISTS_GLIBC(getpwnam_r HAVE_GETPWNAM_R) CHECK_FUNCTION_EXISTS_GLIBC(getpid HAVE_GETPID) CHECK_FUNCTION_EXISTS_GLIBC(lchflags HAVE_LCHFLAGS) CHECK_FUNCTION_EXISTS_GLIBC(lchmod HAVE_LCHMOD) diff --git a/configure.ac b/configure.ac index 51f27c348..26f836b35 100644 --- a/configure.ac +++ b/configure.ac @@ -400,6 +400,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]) 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_write_disk_set_standard_lookup.c b/libarchive/archive_write_disk_set_standard_lookup.c index e7a81e755..ce9b7923e 100644 --- a/libarchive/archive_write_disk_set_standard_lookup.c +++ b/libarchive/archive_write_disk_set_standard_lookup.c @@ -127,6 +127,7 @@ lookup_gid(void *private_data, const char *gname, int64_t gid) /* Note: If strdup fails, that's okay; we just won't cache. */ b->hash = h; #if HAVE_GRP_H +# if HAVE_GETGRNAM_R { char _buffer[128]; size_t bufsize = 128; @@ -153,6 +154,15 @@ lookup_gid(void *private_data, const char *gname, int64_t gid) if (buffer != _buffer) free(buffer); } +# else /* HAVE_GETGRNAM_R */ + { + struct group *result; + + result = getgrnam(gname); + if (result != NULL) + gid = result->gr_gid; + } +# endif /* HAVE_GETGRNAM_R */ #elif defined(_WIN32) && !defined(__CYGWIN__) /* TODO: do a gname->gid lookup for Windows. */ #else @@ -192,6 +202,7 @@ lookup_uid(void *private_data, const char *uname, int64_t uid) /* Note: If strdup fails, that's okay; we just won't cache. */ b->hash = h; #if HAVE_PWD_H +# if HAVE_GETPWNAM_R { char _buffer[128]; size_t bufsize = 128; @@ -218,6 +229,15 @@ lookup_uid(void *private_data, const char *uname, int64_t uid) if (buffer != _buffer) free(buffer); } +# else /* HAVE_GETPWNAM_R */ + { + struct passwd *result; + + result = getpwnam(uname); + if (result != NULL) + uid = result->pw_uid; + } +#endif /* HAVE_GETPWNAM_R */ #elif defined(_WIN32) && !defined(__CYGWIN__) /* TODO: do a uname->uid lookup for Windows. */ #else