1 /* $Id: bsd-setres_id.c,v 1.2 2013/12/07 21:23:09 djm Exp $ */
4 * Copyright (c) 2012 Darren Tucker (dtucker at zip com au).
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 #include <sys/types.h>
29 #if !defined(HAVE_SETRESGID) || defined(BROKEN_SETRESGID)
31 setresgid(gid_t rgid, gid_t egid, gid_t sgid)
33 int ret = 0, saved_errno;
39 #if defined(HAVE_SETREGID) && !defined(BROKEN_SETREGID)
40 if (setregid(rgid, egid) < 0) {
42 error("setregid %u: %.100s", rgid, strerror(errno));
47 if (setegid(egid) < 0) {
49 error("setegid %u: %.100s", (u_int)egid, strerror(errno));
53 if (setgid(rgid) < 0) {
55 error("setgid %u: %.100s", rgid, strerror(errno));
64 #if !defined(HAVE_SETRESUID) || defined(BROKEN_SETRESUID)
66 setresuid(uid_t ruid, uid_t euid, uid_t suid)
68 int ret = 0, saved_errno;
74 #if defined(HAVE_SETREUID) && !defined(BROKEN_SETREUID)
75 if (setreuid(ruid, euid) < 0) {
77 error("setreuid %u: %.100s", ruid, strerror(errno));
83 # ifndef SETEUID_BREAKS_SETUID
84 if (seteuid(euid) < 0) {
86 error("seteuid %u: %.100s", euid, strerror(errno));
91 if (setuid(ruid) < 0) {
93 error("setuid %u: %.100s", ruid, strerror(errno));