summaryrefslogtreecommitdiff
path: root/src/id.c
diff options
context:
space:
mode:
authorPetr Stodůlka <pstodulk@redhat.com>2014-06-25 18:26:23 +0100
committerPádraig Brady <P@draigBrady.com>2014-06-26 12:07:10 +0100
commit408461c0e7e5ddc6bfd0fddb2c79d35a02238ee0 (patch)
tree217c189cbf8ef3bc5b0279e78a7e2cdfed4c3afe /src/id.c
parentd71c12f1e4e165c7da59989b49ded2805b7977cc (diff)
downloadcoreutils-408461c0e7e5ddc6bfd0fddb2c79d35a02238ee0.tar.xz
id: output the effective group for the process
* src/id.c (print_full_info): When no user is specified, output the effective group for the _process_, rather than the default group from the system database, which may be different. * tests/id/setgid.sh: Add a case for `id` as well as `id -G`. * NEWS: Mention the bug fix. Fixes http://bugs.gnu.org/7320 Reported at http://bugzilla.redhat.com/1016163
Diffstat (limited to 'src/id.c')
-rw-r--r--src/id.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/id.c b/src/id.c
index 3348f8013..f46bb41b5 100644
--- a/src/id.c
+++ b/src/id.c
@@ -399,19 +399,20 @@ print_full_info (const char *username)
gid_t *groups;
int i;
- int n_groups = xgetgroups (username, (pwd ? pwd->pw_gid : -1),
- &groups);
+ gid_t primary_group;
+ if (username)
+ primary_group = pwd ? pwd->pw_gid : -1;
+ else
+ primary_group = egid;
+
+ int n_groups = xgetgroups (username, primary_group, &groups);
if (n_groups < 0)
{
if (username)
- {
- error (0, errno, _("failed to get groups for user %s"),
- quote (username));
- }
+ error (0, errno, _("failed to get groups for user %s"),
+ quote (username));
else
- {
- error (0, errno, _("failed to get groups for the current process"));
- }
+ error (0, errno, _("failed to get groups for the current process"));
ok = false;
return;
}