]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/mach/hurd/setresgid.c
1 /* setresgid -- set real group ID, effective group ID, and saved-set group ID
2 Copyright (C) 2002, 2005, 2006 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
24 /* Set the real group ID, effective group ID, and saved-set group ID,
25 of the calling process to RGID, EGID, and SGID, respectively. */
27 __setresgid (gid_t rgid
, gid_t egid
, gid_t sgid
)
31 gid_t agids
[2] = { rgid
, sgid
};
34 __mutex_lock (&_hurd_id
.lock
);
35 err
= _hurd_check_ids ();
39 /* Make a new auth handle which has EGID as the first element in the
40 list of effective gids. */
42 if (_hurd_id
.gen
.ngids
> 0)
44 _hurd_id
.gen
.gids
[0] = egid
;
47 if (_hurd_id
.aux
.ngids
> 1)
49 _hurd_id
.aux
.gids
[0] = rgid
;
50 _hurd_id
.aux
.gids
[1] = sgid
;
54 err
= __USEPORT (AUTH
, __auth_makeauth
55 (port
, NULL
, MACH_MSG_TYPE_COPY_SEND
, 0,
56 _hurd_id
.gen
.uids
, _hurd_id
.gen
.nuids
,
57 _hurd_id
.aux
.uids
, _hurd_id
.aux
.nuids
,
58 _hurd_id
.gen
.ngids
? _hurd_id
.gen
.gids
: &egid
,
59 _hurd_id
.gen
.ngids
?: 1,
60 _hurd_id
.aux
.ngids
> 1 ? _hurd_id
.aux
.gids
: agids
,
61 _hurd_id
.aux
.ngids
> 1 ? _hurd_id
.aux
.ngids
: 2,
65 __mutex_unlock (&_hurd_id
.lock
);
69 return __hurd_fail (err
);
71 /* Install the new handle and reauthenticate everything. */
72 err
= __setauth (newauth
);
73 __mach_port_deallocate (__mach_task_self (), newauth
);
76 libc_hidden_def (__setresgid
)
77 weak_alias (__setresgid
, setresgid
)