2 Copyright (C) Andrew Tridgell 2009
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #define UID_WRAPPER_NOT_REPLACE
21 #include "../replace/replace.h"
23 #include "system/passwd.h"
25 #else /* _SAMBA_BUILD_ */
27 #error uid_wrapper_only_supported_in_samba_yet
36 we keep the virtualised euid/egid/groups information here
47 static void uwrap_init(void)
49 if (uwrap
.initialised
) return;
50 uwrap
.initialised
= true;
51 if (getenv("UID_WRAPPER")) {
53 /* put us in one group */
55 uwrap
.groups
= talloc_array(NULL
, gid_t
, 1);
61 _PUBLIC_
int uwrap_enabled(void)
64 return uwrap
.enabled
?1:0;
67 _PUBLIC_
int uwrap_seteuid(uid_t euid
)
73 /* assume for now that the ruid stays as root */
78 _PUBLIC_ uid_t
uwrap_geteuid(void)
87 _PUBLIC_
int uwrap_setegid(gid_t egid
)
93 /* assume for now that the ruid stays as root */
98 _PUBLIC_ uid_t
uwrap_getegid(void)
101 if (!uwrap
.enabled
) {
107 _PUBLIC_
int uwrap_setgroups(size_t size
, const gid_t
*list
)
110 if (!uwrap
.enabled
) {
111 return setgroups(size
, list
);
114 talloc_free(uwrap
.groups
);
119 uwrap
.groups
= talloc_array(NULL
, gid_t
, size
);
120 if (uwrap
.groups
== NULL
) {
124 memcpy(uwrap
.groups
, list
, size
*sizeof(gid_t
));
125 uwrap
.ngroups
= size
;
130 _PUBLIC_
int uwrap_getgroups(int size
, gid_t
*list
)
133 if (!uwrap
.enabled
) {
134 return getgroups(size
, list
);
137 if (size
> uwrap
.ngroups
) {
138 size
= uwrap
.ngroups
;
141 return uwrap
.ngroups
;
143 if (size
< uwrap
.ngroups
) {
147 memcpy(list
, uwrap
.groups
, size
*sizeof(gid_t
));
148 return uwrap
.ngroups
;
151 _PUBLIC_ uid_t
uwrap_getuid(void)
154 if (!uwrap
.enabled
) {
157 /* we don't simulate ruid changing */
161 _PUBLIC_ gid_t
uwrap_getgid(void)
164 if (!uwrap
.enabled
) {
167 /* we don't simulate rgid changing */