]> sourceware.org Git - glibc.git/blob - sysdeps/mach/hurd/setresgid.c
Amend log entry with omitted file.
[glibc.git] / sysdeps / mach / hurd / setresgid.c
1 /* setresgid -- set effective group ID, real group ID, and saved-set group ID
2 Copyright (C) 2002, 2005 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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.
9
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.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
19
20 #include <errno.h>
21 #include <unistd.h>
22 #include <hurd.h>
23 #include <hurd/id.h>
24
25 /* Set the effective group ID, real group ID, and saved-set group ID,
26 of the calling process to EGID, RGID, and SGID, respectively. */
27 int
28 __setresgid (gid_t egid, gid_t rgid, gid_t sgid)
29 {
30 auth_t newauth;
31 error_t err;
32 gid_t agids[2] = { rgid, sgid };
33
34 HURD_CRITICAL_BEGIN;
35 __mutex_lock (&_hurd_id.lock);
36 err = _hurd_check_ids ();
37
38 if (!err)
39 {
40 /* Make a new auth handle which has EGID as the first element in the
41 list of effective gids. */
42
43 if (_hurd_id.gen.ngids > 0)
44 {
45 _hurd_id.gen.gids[0] = egid;
46 _hurd_id.valid = 0;
47 }
48 if (_hurd_id.aux.ngids > 1)
49 {
50 _hurd_id.aux.gids[0] = rgid;
51 _hurd_id.aux.gids[1] = sgid;
52 _hurd_id.valid = 0;
53 }
54
55 err = __USEPORT (AUTH, __auth_makeauth
56 (port, NULL, MACH_MSG_TYPE_COPY_SEND, 0,
57 _hurd_id.gen.uids, _hurd_id.gen.nuids,
58 _hurd_id.aux.uids, _hurd_id.aux.nuids,
59 _hurd_id.gen.ngids ? _hurd_id.gen.gids : &egid,
60 _hurd_id.gen.ngids ?: 1,
61 _hurd_id.aux.ngids > 1 ? _hurd_id.aux.gids : agids,
62 _hurd_id.aux.ngids > 1 ? _hurd_id.aux.ngids : 2,
63 &newauth));
64 }
65
66 __mutex_unlock (&_hurd_id.lock);
67 HURD_CRITICAL_END;
68
69 if (err)
70 return __hurd_fail (err);
71
72 /* Install the new handle and reauthenticate everything. */
73 err = __setauth (newauth);
74 __mach_port_deallocate (__mach_task_self (), newauth);
75 return err;
76 }
77 libc_hidden_def (__setresgid)
78 weak_alias (__setresgid, setresgid)
This page took 0.037769 seconds and 5 git commands to generate.