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/>.
22 #include "system/passwd.h"
23 #include "include/includes.h"
25 #ifdef UID_WRAPPER_REPLACE
35 #ifdef samba_setresuid
36 #undef samba_setresuid
47 #ifdef samba_setresgid
48 #undef samba_setresgid
51 #ifdef samba_setgroups
52 #undef samba_setgroups
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
);
69 #include "../lib/util/setid.h"
73 /* Inside autoconf test. */
74 #if defined(HAVE_UNISTD_H)
79 #include <sys/types.h>
82 #ifdef HAVE_SYS_PRIV_H
89 /* autoconf tests don't include setid.h */
90 int samba_setresuid(uid_t ruid
, uid_t euid
, uid_t suid
);
91 int samba_setresgid(gid_t rgid
, gid_t egid
, gid_t sgid
);
92 int samba_setreuid(uid_t ruid
, uid_t euid
);
93 int samba_setregid(gid_t rgid
, gid_t egid
);
94 int samba_seteuid(uid_t euid
);
95 int samba_setegid(gid_t egid
);
96 int samba_setuid(uid_t uid
);
97 int samba_setgid(gid_t gid
);
98 int samba_setuidx(int flags
, uid_t uid
);
99 int samba_setgidx(int flags
, gid_t gid
);
100 int samba_setgroups(size_t setlen
, const gid_t
*gidset
);
104 #if defined(USE_LINUX_THREAD_CREDENTIALS)
105 #if defined(HAVE_SYSCALL_H)
109 #if defined(HAVE_SYS_SYSCALL_H)
110 #include <sys/syscall.h>
114 /* All the setXX[ug]id functions and setgroups Samba uses. */
115 int samba_setresuid(uid_t ruid
, uid_t euid
, uid_t suid
)
117 #if defined(USE_LINUX_THREAD_CREDENTIALS)
118 return syscall(SYS_setresuid
, ruid
, euid
, suid
);
119 #elif defined(HAVE_SETRESUID)
120 return setresuid(ruid
, euid
, suid
);
127 int samba_setresgid(gid_t rgid
, gid_t egid
, gid_t sgid
)
129 #if defined(USE_LINUX_THREAD_CREDENTIALS)
130 return syscall(SYS_setresgid
, rgid
, egid
, sgid
);
131 #elif defined(HAVE_SETRESGID)
132 return setresgid(rgid
, egid
, sgid
);
139 int samba_setreuid(uid_t ruid
, uid_t euid
)
141 #if defined(USE_LINUX_THREAD_CREDENTIALS)
142 return syscall(SYS_setreuid
, ruid
, euid
);
143 #elif defined(HAVE_SETREUID)
144 return setreuid(ruid
, euid
);
151 int samba_setregid(gid_t rgid
, gid_t egid
)
153 #if defined(USE_LINUX_THREAD_CREDENTIALS)
154 return syscall(SYS_setregid
, rgid
, egid
);
155 #elif defined(HAVE_SETREGID)
156 return setregid(rgid
, egid
);
163 int samba_seteuid(uid_t euid
)
165 #if defined(USE_LINUX_THREAD_CREDENTIALS)
166 /* seteuid is not a separate system call. */
167 return syscall(SYS_setresuid
, -1, euid
, -1);
168 #elif defined(HAVE_SETEUID)
169 return seteuid(euid
);
176 int samba_setegid(gid_t egid
)
178 #if defined(USE_LINUX_THREAD_CREDENTIALS)
179 /* setegid is not a separate system call. */
180 return syscall(SYS_setresgid
, -1, egid
, -1);
181 #elif defined(HAVE_SETEGID)
182 return setegid(egid
);
189 int samba_setuid(uid_t uid
)
191 #if defined(USE_LINUX_THREAD_CREDENTIALS)
192 return syscall(SYS_setuid
, uid
);
193 #elif defined(HAVE_SETUID)
201 int samba_setgid(gid_t gid
)
203 #if defined(USE_LINUX_THREAD_CREDENTIALS)
204 return syscall(SYS_setgid
, gid
);
205 #elif defined(HAVE_SETGID)
213 int samba_setuidx(int flags
, uid_t uid
)
215 #if defined(HAVE_SETUIDX)
216 return setuidx(flags
, uid
);
218 /* USE_LINUX_THREAD_CREDENTIALS doesn't have this. */
224 int samba_setgidx(int flags
, gid_t gid
)
226 #if defined(HAVE_SETGIDX)
227 return setgidx(flags
, gid
);
229 /* USE_LINUX_THREAD_CREDENTIALS doesn't have this. */
235 int samba_setgroups(size_t setlen
, const gid_t
*gidset
)
237 #if defined(USE_LINUX_THREAD_CREDENTIALS)
238 return syscall(SYS_setgroups
, setlen
, gidset
);
239 #elif defined(HAVE_SETGROUPS)
240 return setgroups(setlen
, gidset
);