summaryrefslogtreecommitdiff
path: root/lib/util/setid.c
blob: 8b2efc076f395723986cf589ac4fa027f681d3d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
   Unix SMB/CIFS implementation.
   setXXid() functions for Samba.
   Copyright (C) Jeremy Allison 2012

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef AUTOCONF_TEST
#include "replace.h"
#include "system/passwd.h"
#include "include/includes.h"

#ifdef UID_WRAPPER_REPLACE

#ifdef samba_seteuid
#undef samba_seteuid
#endif

#ifdef samba_setreuid
#undef samba_setreuid
#endif

#ifdef samba_setresuid
#undef samba_setresuid
#endif

#ifdef samba_setegid
#undef samba_setegid
#endif

#ifdef samba_setregid
#undef samba_setregid
#endif

#ifdef samba_setresgid
#undef samba_setresgid
#endif

#ifdef samba_setgroups
#undef samba_setgroups
#endif

/* uid_wrapper will have redefined these. */
int samba_setresuid(uid_t ruid, uid_t euid, uid_t suid);
int samba_setresgid(gid_t rgid, gid_t egid, gid_t sgid);
int samba_setreuid(uid_t ruid, uid_t euid);
int samba_setregid(gid_t rgid, gid_t egid);
int samba_seteuid(uid_t euid);
int samba_setegid(gid_t egid);
int samba_setuid(uid_t uid);
int samba_setgid(gid_t gid);
int samba_setuidx(int flags, uid_t uid);
int samba_setgidx(int flags, gid_t gid);
int samba_setgroups(size_t setlen, const gid_t *gidset);

#endif
#endif

#include "../lib/util/setid.h"

/* All the setXX[ug]id functions and setgroups Samba uses. */
int samba_setresuid(uid_t ruid, uid_t euid, uid_t suid)
{
#if defined(HAVE_SETRESUID)
	return setresuid(ruid, euid, suid);
#else
	errno = ENOSYS;
	return -1;
#endif
}

int samba_setresgid(gid_t rgid, gid_t egid, gid_t sgid)
{
#if defined(HAVE_SETRESGID)
	return setresgid(rgid, egid, sgid);
#else
	errno = ENOSYS;
	return -1;
#endif
}

int samba_setreuid(uid_t ruid, uid_t euid)
{
#if defined(HAVE_SETREUID)
	return setreuid(ruid, euid);
#else
	errno = ENOSYS;
	return -1;
#endif
}

int samba_setregid(gid_t rgid, gid_t egid)
{
#if defined(HAVE_SETREGID)
	return setregid(rgid, egid);
#else
	errno = ENOSYS;
	return -1;
#endif
}

int samba_seteuid(uid_t euid)
{
#if defined(HAVE_SETEUID)
	return seteuid(euid);
#else
	errno = ENOSYS;
	return -1;
#endif
}

int samba_setegid(gid_t egid)
{
#if defined(HAVE_SETEGID)
	return setegid(egid);
#else
	errno = ENOSYS;
	return -1;
#endif
}

int samba_setuid(uid_t uid)
{
#if defined(HAVE_SETUID)
	return setuid(uid);
#else
	errno = ENOSYS;
	return -1;
#endif
}

int samba_setgid(gid_t gid)
{
#if defined(HAVE_SETGID)
	return setgid(gid);
#else
	errno = ENOSYS;
	return -1;
#endif
}

int samba_setuidx(int flags, uid_t uid)
{
#if defined(HAVE_SETUIDX)
	return setuidx(flags, uid);
#else
	errno = ENOSYS;
	return -1;
#endif
}

int samba_setgidx(int flags, gid_t gid)
{
#if defined(HAVE_SETGIDX)
	return setgidx(flags, gid);
#else
	errno = ENOSYS;
	return -1;
#endif
}

int samba_setgroups(size_t setlen, const gid_t *gidset)
{
#if defined(HAVE_SETGROUPS)
	return setgroups(setlen, gidset);
#else
	errno = ENOSYS;
	return -1;
#endif
}