Bug 1003963 - id always report default primary group when gid/egid has been set to other group
id always report default primary group when gid/egid has been set to other group
Status: CLOSED DUPLICATE of bug 816708
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: coreutils (Show other bugs)
6.4
All Linux
unspecified Severity unspecified
: rc
: ---
Assigned To: Ondrej Vasik
qe-baseos-daemons
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2013-09-03 11:03 EDT by Ron van der Wees
Modified: 2013-09-04 03:00 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2013-09-04 03:00:07 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
Reproducer source code (720 bytes, text/x-csrc)
2013-09-03 11:03 EDT, Ron van der Wees
no flags Details

  None (edit)
Description Ron van der Wees 2013-09-03 11:03:38 EDT
Created attachment 793234 [details]
Reproducer source code

Description of problem:
/usr/bin/id -G always reports the primary group as defined in /etc/passwd, even
when gid, egid and supplementary group list has been set to a different group.


Version-Release number of selected component (if applicable):
coreutils-8.4-19.el6.x86_64

How reproducible:
Always


Steps to Reproduce:
1. Create additional group:
   # groupadd -g 1010 group1010
2. Add user:
   # useradd user1
3. Make user member of additional group
   # gpasswd -a user1 group1010
4. Build and install reproducer:
   # gcc -Wall -o reproducer reproducer2.c
   # install -m4755 reproducer /usr/local/bin/reproducer
5.  Run reproducer which sets gid/egid to group1010 and calls exceve(2)
    to execute "id -G"


Actual results:
On RHEL-6.4:
# su - user1
$ /usr/local/bin/reproducer 
1010 501    <<---- Even when gid and egid have been set to 1010, the primary
                   gid as configured in /etc/passwd is reported while not
                   not being effective.


Expected results:
On RHEL-5.9:
# su - user1
$ /usr/local/bin/reproducer 
1010        <<---- Only the gid as set by reproducer is shown.


Additional info:
The reproducer calls execve(2) in stead of system(3) to avoid bash dropping
the privileges.

From coreutils-8.4/lib/mgetgroups.c in function mgetgroups():
~~~
  ng = (username
        ? getugroups (max_n_groups, g, username, gid)
        : getgroups (max_n_groups - (gid != (gid_t) -1),
                                g + (gid != (gid_t) -1)));

  if (ng < 0)
    {
      /* Failure is unexpected, but handle it anyway.  */
      int saved_errno = errno;
      free (g);
      errno = saved_errno;
      return -1;
    }

  if (!username && gid != (gid_t) -1)   <-- primary gid is always added to list
    {
      *g = gid;
      ng++;
    }
~~~
Comment 1 Ondrej Vasik 2013-09-04 03:00:07 EDT
Thanks for report. I believe this is duplicate of https://bugzilla.redhat.com/show_bug.cgi?id=816708 (I checked the fixed version of id and it works just fine).

*** This bug has been marked as a duplicate of bug 816708 ***

Note You need to log in before you can comment on or make changes to this bug.