HADOOP-10989. Work around buggy getgrouplist() implementations on Linux that 
return 0 on failure. Contributed by Chris Nauroth.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1619659 
13f79535-47bb-0310-9956-ffa450edef68


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/b6c24472
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/b6c24472
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/b6c24472

Branch: refs/heads/HDFS-6584
Commit: b6c24472f31c1509699b5b4d0c0f9fb5db69a49a
Parents: 7be2808
Author: Chris Nauroth <[email protected]>
Authored: Fri Aug 22 04:05:18 2014 +0000
Committer: Chris Nauroth <[email protected]>
Committed: Fri Aug 22 04:05:18 2014 +0000

----------------------------------------------------------------------
 hadoop-common-project/hadoop-common/CHANGES.txt           |  3 +++
 .../src/org/apache/hadoop/security/hadoop_user_info.c     | 10 ++++++++++
 2 files changed, 13 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/b6c24472/hadoop-common-project/hadoop-common/CHANGES.txt
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt 
b/hadoop-common-project/hadoop-common/CHANGES.txt
index 655df79..52fc3e0 100644
--- a/hadoop-common-project/hadoop-common/CHANGES.txt
+++ b/hadoop-common-project/hadoop-common/CHANGES.txt
@@ -686,6 +686,9 @@ Release 2.6.0 - UNRELEASED
 
     HADOOP-10488. TestKeyProviderFactory fails randomly. (tucu)
 
+    HADOOP-10989. Work around buggy getgrouplist() implementations on Linux 
that
+    return 0 on failure. (cnauroth)
+
 Release 2.5.0 - 2014-08-11
 
   INCOMPATIBLE CHANGES

http://git-wip-us.apache.org/repos/asf/hadoop/blob/b6c24472/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/security/hadoop_user_info.c
----------------------------------------------------------------------
diff --git 
a/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/security/hadoop_user_info.c
 
b/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/security/hadoop_user_info.c
index ca288ec..e2438b1 100644
--- 
a/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/security/hadoop_user_info.c
+++ 
b/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/security/hadoop_user_info.c
@@ -193,7 +193,17 @@ int hadoop_user_info_getgroups(struct hadoop_user_info 
*uinfo)
   ngroups = uinfo->gids_size;
   ret = getgrouplist(uinfo->pwd.pw_name, uinfo->pwd.pw_gid, 
                          uinfo->gids, &ngroups);
+  // Return value is different on Linux vs. FreeBSD.  Linux: the number of 
groups
+  // or -1 on error.  FreeBSD: 0 on success or -1 on error.  Unfortunately, we
+  // can't accept a 0 return on Linux, because buggy implementations have been
+  // observed to return 0 but leave the other out parameters in an 
indeterminate
+  // state.  This deviates from the man page, but it has been observed in
+  // practice.  See issue HADOOP-10989 for details.
+#ifdef __linux__
+  if (ret > 0) {
+#else
   if (ret >= 0) {
+#endif
     uinfo->num_gids = ngroups;
     ret = put_primary_gid_first(uinfo);
     if (ret) {

Reply via email to