Replace all uses of setXX[ug]id() and setgroups with samba_setXX[ug]id() calls.
[Samba/id10ts.git] / lib / util / setid.c
blob8b2efc076f395723986cf589ac4fa027f681d3d8
1 /*
2 Unix SMB/CIFS implementation.
3 setXXid() functions for Samba.
4 Copyright (C) Jeremy Allison 2012
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef AUTOCONF_TEST
21 #include "replace.h"
22 #include "system/passwd.h"
23 #include "include/includes.h"
25 #ifdef UID_WRAPPER_REPLACE
27 #ifdef samba_seteuid
28 #undef samba_seteuid
29 #endif
31 #ifdef samba_setreuid
32 #undef samba_setreuid
33 #endif
35 #ifdef samba_setresuid
36 #undef samba_setresuid
37 #endif
39 #ifdef samba_setegid
40 #undef samba_setegid
41 #endif
43 #ifdef samba_setregid
44 #undef samba_setregid
45 #endif
47 #ifdef samba_setresgid
48 #undef samba_setresgid
49 #endif
51 #ifdef samba_setgroups
52 #undef samba_setgroups
53 #endif
55 /* uid_wrapper will have redefined these. */
56 int samba_setresuid(uid_t ruid, uid_t euid, uid_t suid);
57 int samba_setresgid(gid_t rgid, gid_t egid, gid_t sgid);
58 int samba_setreuid(uid_t ruid, uid_t euid);
59 int samba_setregid(gid_t rgid, gid_t egid);
60 int samba_seteuid(uid_t euid);
61 int samba_setegid(gid_t egid);
62 int samba_setuid(uid_t uid);
63 int samba_setgid(gid_t gid);
64 int samba_setuidx(int flags, uid_t uid);
65 int samba_setgidx(int flags, gid_t gid);
66 int samba_setgroups(size_t setlen, const gid_t *gidset);
68 #endif
69 #endif
71 #include "../lib/util/setid.h"
73 /* All the setXX[ug]id functions and setgroups Samba uses. */
74 int samba_setresuid(uid_t ruid, uid_t euid, uid_t suid)
76 #if defined(HAVE_SETRESUID)
77 return setresuid(ruid, euid, suid);
78 #else
79 errno = ENOSYS;
80 return -1;
81 #endif
84 int samba_setresgid(gid_t rgid, gid_t egid, gid_t sgid)
86 #if defined(HAVE_SETRESGID)
87 return setresgid(rgid, egid, sgid);
88 #else
89 errno = ENOSYS;
90 return -1;
91 #endif
94 int samba_setreuid(uid_t ruid, uid_t euid)
96 #if defined(HAVE_SETREUID)
97 return setreuid(ruid, euid);
98 #else
99 errno = ENOSYS;
100 return -1;
101 #endif
104 int samba_setregid(gid_t rgid, gid_t egid)
106 #if defined(HAVE_SETREGID)
107 return setregid(rgid, egid);
108 #else
109 errno = ENOSYS;
110 return -1;
111 #endif
114 int samba_seteuid(uid_t euid)
116 #if defined(HAVE_SETEUID)
117 return seteuid(euid);
118 #else
119 errno = ENOSYS;
120 return -1;
121 #endif
124 int samba_setegid(gid_t egid)
126 #if defined(HAVE_SETEGID)
127 return setegid(egid);
128 #else
129 errno = ENOSYS;
130 return -1;
131 #endif
134 int samba_setuid(uid_t uid)
136 #if defined(HAVE_SETUID)
137 return setuid(uid);
138 #else
139 errno = ENOSYS;
140 return -1;
141 #endif
144 int samba_setgid(gid_t gid)
146 #if defined(HAVE_SETGID)
147 return setgid(gid);
148 #else
149 errno = ENOSYS;
150 return -1;
151 #endif
154 int samba_setuidx(int flags, uid_t uid)
156 #if defined(HAVE_SETUIDX)
157 return setuidx(flags, uid);
158 #else
159 errno = ENOSYS;
160 return -1;
161 #endif
164 int samba_setgidx(int flags, gid_t gid)
166 #if defined(HAVE_SETGIDX)
167 return setgidx(flags, gid);
168 #else
169 errno = ENOSYS;
170 return -1;
171 #endif
174 int samba_setgroups(size_t setlen, const gid_t *gidset)
176 #if defined(HAVE_SETGROUPS)
177 return setgroups(setlen, gidset);
178 #else
179 errno = ENOSYS;
180 return -1;
181 #endif