Author: arp Date: Wed Dec 11 23:18:29 2013 New Revision: 1550313 URL: http://svn.apache.org/r1550313 Log: Merging r1549949 through r1550312 from trunk to branch HDFS-2832
Modified: hadoop/common/branches/HDFS-2832/hadoop-common-project/hadoop-common/CHANGES.txt (contents, props changed) hadoop/common/branches/HDFS-2832/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/security/hadoop_user_info.c Modified: hadoop/common/branches/HDFS-2832/hadoop-common-project/hadoop-common/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-2832/hadoop-common-project/hadoop-common/CHANGES.txt?rev=1550313&r1=1550312&r2=1550313&view=diff ============================================================================== --- hadoop/common/branches/HDFS-2832/hadoop-common-project/hadoop-common/CHANGES.txt (original) +++ hadoop/common/branches/HDFS-2832/hadoop-common-project/hadoop-common/CHANGES.txt Wed Dec 11 23:18:29 2013 @@ -538,6 +538,9 @@ Release 2.3.0 - UNRELEASED HADOOP-10081. Client.setupIOStreams can leak socket resources on exception or error (Tsuyoshi OZAWA via jlowe) + HADOOP-10087. UserGroupInformation.getGroupNames() fails to return primary + group first when JniBasedUnixGroupsMappingWithFallback is used (cmccabe) + Release 2.2.0 - 2013-10-13 INCOMPATIBLE CHANGES Propchange: hadoop/common/branches/HDFS-2832/hadoop-common-project/hadoop-common/CHANGES.txt ------------------------------------------------------------------------------ Merged /hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt:r1549626-1550312 Modified: hadoop/common/branches/HDFS-2832/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/security/hadoop_user_info.c URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-2832/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/security/hadoop_user_info.c?rev=1550313&r1=1550312&r2=1550313&view=diff ============================================================================== --- hadoop/common/branches/HDFS-2832/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/security/hadoop_user_info.c (original) +++ hadoop/common/branches/HDFS-2832/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/security/hadoop_user_info.c Wed Dec 11 23:18:29 2013 @@ -122,13 +122,43 @@ int hadoop_user_info_fetch(struct hadoop } } +static int put_primary_gid_first(struct hadoop_user_info *uinfo) +{ + int i, num_gids = uinfo->num_gids; + gid_t first_gid; + gid_t gid; + gid_t primary = uinfo->pwd.pw_gid; + + if (num_gids < 1) { + // There are no gids, but we expected at least one. + return EINVAL; + } + first_gid = uinfo->gids[0]; + if (first_gid == primary) { + // First gid is already the primary. + return 0; + } + for (i = 1; i < num_gids; i++) { + gid = uinfo->gids[i]; + if (gid == primary) { + // swap first gid and this gid. + uinfo->gids[0] = gid; + uinfo->gids[i] = first_gid; + return 0; + } + } + // Did not find the primary gid in the list. + return EINVAL; +} + int hadoop_user_info_getgroups(struct hadoop_user_info *uinfo) { int ret, ngroups; gid_t *ngids; if (!uinfo->pwd.pw_name) { - return EINVAL; // invalid user info + // invalid user info + return EINVAL; } uinfo->num_gids = 0; if (!uinfo->gids) { @@ -141,8 +171,12 @@ int hadoop_user_info_getgroups(struct ha ngroups = uinfo->gids_size; ret = getgrouplist(uinfo->pwd.pw_name, uinfo->pwd.pw_gid, uinfo->gids, &ngroups); - if (ret != -1) { + if (ret > 0) { uinfo->num_gids = ngroups; + ret = put_primary_gid_first(uinfo); + if (ret) { + return ret; + } return 0; } ngids = realloc(uinfo->gids, sizeof(uinfo->gids[0]) * ngroups); @@ -153,11 +187,12 @@ int hadoop_user_info_getgroups(struct ha uinfo->gids_size = ngroups; ret = getgrouplist(uinfo->pwd.pw_name, uinfo->pwd.pw_gid, uinfo->gids, &ngroups); - if (ret != -1) { - uinfo->num_gids = ngroups; - return 0; + if (ret < 0) { + return EIO; } - return EIO; + uinfo->num_gids = ngroups; + ret = put_primary_gid_first(uinfo); + return ret; } #ifdef USER_TESTING