1 /* setresuid -- set real user ID, effective user ID, and saved-set user ID
2 Copyright (C) 2002-2016 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 user ID, effective user ID, and saved-set user ID,
25 of the calling process to RUID, EUID, and SUID, respectively. */
27 __setresuid (uid_t ruid
, uid_t euid
, uid_t suid
)
33 __mutex_lock (&_hurd_id
.lock
);
34 err
= _hurd_check_ids ();
38 /* Make a new auth handle which has EUID as the first element in the
39 list of effective uids. */
41 uid_t
*newgen
, *newaux
;
42 uid_t auxs
[2] = { ruid
, suid
};
45 newgen
= _hurd_id
.gen
.uids
;
46 ngen
= _hurd_id
.gen
.nuids
;
49 if (_hurd_id
.gen
.nuids
== 0)
51 /* No effective uids now. The new set will be just UID. */
57 _hurd_id
.gen
.uids
[0] = euid
;
62 newaux
= _hurd_id
.aux
.uids
;
63 naux
= _hurd_id
.aux
.nuids
;
66 if (_hurd_id
.aux
.nuids
== 0)
73 _hurd_id
.aux
.uids
[0] = ruid
;
82 if (_hurd_id
.aux
.nuids
>= 1)
83 auxs
[0] = _hurd_id
.aux
.uids
[0];
84 else if (_hurd_id
.gen
.nuids
>= 1)
85 auxs
[0] = _hurd_id
.gen
.uids
[0];
87 /* Not even an effective UID.
88 Fall back to the only UID we have. */
91 if (_hurd_id
.aux
.nuids
<= 1)
93 /* No saved uids now. The new set will be just UID. */
99 _hurd_id
.aux
.uids
[1] = suid
;
104 err
= __USEPORT (AUTH
, __auth_makeauth
105 (port
, NULL
, MACH_MSG_TYPE_COPY_SEND
, 0,
106 newgen
, ngen
, newaux
, naux
,
107 _hurd_id
.gen
.gids
, _hurd_id
.gen
.ngids
,
108 _hurd_id
.aux
.gids
, _hurd_id
.aux
.ngids
,
112 __mutex_unlock (&_hurd_id
.lock
);
116 return __hurd_fail (err
);
118 /* Install the new handle and reauthenticate everything. */
119 err
= __setauth (newauth
);
120 __mach_port_deallocate (__mach_task_self (), newauth
);
123 libc_hidden_def (__setresuid
)
124 weak_alias (__setresuid
, setresuid
)