diff options
author | Jim Meyering <jim@meyering.net> | 2007-07-05 17:42:29 +0200 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2007-07-06 07:44:39 +0200 |
commit | e0066f36c22dce02f9d6327cb881ee7eec6e7539 (patch) | |
tree | 39c5d9c47df892a1ab845e11fc89b93b8e9b6a1a /src/setuidgid.c | |
parent | b8031ff7c74b153f1e929c059e42532a9771eb74 (diff) | |
download | coreutils-e0066f36c22dce02f9d6327cb881ee7eec6e7539.tar.xz |
setuidgid: set all groups, not just the primary one; mgetgroups: new module
I wanted to use the xgetgroups function from id.c, so factored it out
and made it into a non-exiting function (hence the "m" prefix rather than "x").
* src/setuidgid.c (main): Use mgetgroups. Include "mgetgroups.h".
* src/id.c (xgetgroups): Remove function.
Include "mgetgroups.h".
(print_group_list): Use mgetgroups, not xgetgroups.
* gl/modules/mgetgroups: New module.
* gl/lib/mgetgroups.c: New file. mgetgroups is derived from
id.c's xgetgroups function.
* bootstrap.conf (gnulib_modules): Add mgetgroups.
* gl/m4/mgetgroups.m4: New file.
* gl/lib/mgetgroups.h: New file.
Diffstat (limited to 'src/setuidgid.c')
-rw-r--r-- | src/setuidgid.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/setuidgid.c b/src/setuidgid.c index 27c4c7991..ccc8403fc 100644 --- a/src/setuidgid.c +++ b/src/setuidgid.c @@ -1,5 +1,5 @@ /* setuidgid - run a command with the UID and GID of a specified user - Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc. + Copyright (C) 2003-2007 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -28,6 +28,7 @@ #include "error.h" #include "long-options.h" +#include "mgetgroups.h" #include "quote.h" #define PROGRAM_NAME "setuidgid" @@ -105,8 +106,21 @@ main (int argc, char **argv) _("unknown user-ID: %s"), quote (user_id)); #if HAVE_SETGROUPS - if (setgroups (1, &pwd->pw_gid)) - error (SETUIDGID_FAILURE, errno, _("cannot set supplemental group")); + { + GETGROUPS_T *groups; + int n_groups = mgetgroups (user_id, pwd->pw_gid, &groups); + if (n_groups < 0) + { + n_groups = 1; + groups = xmalloc (sizeof *groups); + *groups = pwd->pw_gid; + } + + if (0 < n_groups && setgroups (n_groups, groups)) + error (SETUIDGID_FAILURE, errno, _("cannot set supplemental group(s)")); + + free (groups); + } #endif if (setgid (pwd->pw_gid)) |