Replace all uses of setXX[ug]id() and setgroups with samba_setXX[ug]id() calls.
[kai/samba-autobuild/.git] / lib / util / setid.c
1 /*
2    Unix SMB/CIFS implementation.
3    setXXid() functions for Samba.
4    Copyright (C) Jeremy Allison 2012
5
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.
10
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.
15
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/>.
18 */
19
20 #ifndef AUTOCONF_TEST
21 #include "replace.h"
22 #include "system/passwd.h"
23 #include "include/includes.h"
24
25 #ifdef UID_WRAPPER_REPLACE
26
27 #ifdef samba_seteuid
28 #undef samba_seteuid
29 #endif
30
31 #ifdef samba_setreuid
32 #undef samba_setreuid
33 #endif
34
35 #ifdef samba_setresuid
36 #undef samba_setresuid
37 #endif
38
39 #ifdef samba_setegid
40 #undef samba_setegid
41 #endif
42
43 #ifdef samba_setregid
44 #undef samba_setregid
45 #endif
46
47 #ifdef samba_setresgid
48 #undef samba_setresgid
49 #endif
50
51 #ifdef samba_setgroups
52 #undef samba_setgroups
53 #endif
54
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);
67
68 #endif
69 #endif
70
71 #include "../lib/util/setid.h"
72
73 /* All the setXX[ug]id functions and setgroups Samba uses. */
74 int samba_setresuid(uid_t ruid, uid_t euid, uid_t suid)
75 {
76 #if defined(HAVE_SETRESUID)
77         return setresuid(ruid, euid, suid);
78 #else
79         errno = ENOSYS;
80         return -1;
81 #endif
82 }
83
84 int samba_setresgid(gid_t rgid, gid_t egid, gid_t sgid)
85 {
86 #if defined(HAVE_SETRESGID)
87         return setresgid(rgid, egid, sgid);
88 #else
89         errno = ENOSYS;
90         return -1;
91 #endif
92 }
93
94 int samba_setreuid(uid_t ruid, uid_t euid)
95 {
96 #if defined(HAVE_SETREUID)
97         return setreuid(ruid, euid);
98 #else
99         errno = ENOSYS;
100         return -1;
101 #endif
102 }
103
104 int samba_setregid(gid_t rgid, gid_t egid)
105 {
106 #if defined(HAVE_SETREGID)
107         return setregid(rgid, egid);
108 #else
109         errno = ENOSYS;
110         return -1;
111 #endif
112 }
113
114 int samba_seteuid(uid_t euid)
115 {
116 #if defined(HAVE_SETEUID)
117         return seteuid(euid);
118 #else
119         errno = ENOSYS;
120         return -1;
121 #endif
122 }
123
124 int samba_setegid(gid_t egid)
125 {
126 #if defined(HAVE_SETEGID)
127         return setegid(egid);
128 #else
129         errno = ENOSYS;
130         return -1;
131 #endif
132 }
133
134 int samba_setuid(uid_t uid)
135 {
136 #if defined(HAVE_SETUID)
137         return setuid(uid);
138 #else
139         errno = ENOSYS;
140         return -1;
141 #endif
142 }
143
144 int samba_setgid(gid_t gid)
145 {
146 #if defined(HAVE_SETGID)
147         return setgid(gid);
148 #else
149         errno = ENOSYS;
150         return -1;
151 #endif
152 }
153
154 int samba_setuidx(int flags, uid_t uid)
155 {
156 #if defined(HAVE_SETUIDX)
157         return setuidx(flags, uid);
158 #else
159         errno = ENOSYS;
160         return -1;
161 #endif
162 }
163
164 int samba_setgidx(int flags, gid_t gid)
165 {
166 #if defined(HAVE_SETGIDX)
167         return setgidx(flags, gid);
168 #else
169         errno = ENOSYS;
170         return -1;
171 #endif
172 }
173
174 int samba_setgroups(size_t setlen, const gid_t *gidset)
175 {
176 #if defined(HAVE_SETGROUPS)
177         return setgroups(setlen, gidset);
178 #else
179         errno = ENOSYS;
180         return -1;
181 #endif
182 }