2 * Copyright (c) 2009 Andrew Tridgell
3 * Copyright (c) 2011-2013 Andreas Schneider <asn@samba.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 #include <sys/types.h>
30 #ifdef HAVE_SYS_SYSCALL_H
31 #include <sys/syscall.h>
40 #ifdef HAVE_GCC_THREAD_LOCAL_STORAGE
41 # define UWRAP_THREAD __thread
46 #ifdef HAVE_DESTRUCTOR_ATTRIBUTE
47 #define DESTRUCTOR_ATTRIBUTE __attribute__ ((destructor))
49 #define DESTRUCTOR_ATTRIBUTE
50 #endif /* HAVE_DESTRUCTOR_ATTRIBUTE */
52 /* GCC have printf type attribute check. */
53 #ifdef HAVE_FUNCTION_ATTRIBUTE_FORMAT
54 #define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
56 #define PRINTF_ATTRIBUTE(a,b)
57 #endif /* HAVE_FUNCTION_ATTRIBUTE_FORMAT */
59 #define UWRAP_DLIST_ADD(list,item) do { \
61 (item)->prev = NULL; \
62 (item)->next = NULL; \
65 (item)->prev = NULL; \
66 (item)->next = (list); \
67 (list)->prev = (item); \
72 #define UWRAP_DLIST_REMOVE(list,item) do { \
73 if ((list) == (item)) { \
74 (list) = (item)->next; \
76 (list)->prev = NULL; \
80 (item)->prev->next = (item)->next; \
83 (item)->next->prev = (item)->prev; \
86 (item)->prev = NULL; \
87 (item)->next = NULL; \
91 #define SAFE_FREE(x) do { if ((x) != NULL) {free(x); (x)=NULL;} } while(0)
106 # define UWRAP_LOG(...)
108 static void uwrap_log(enum uwrap_dbglvl_e dbglvl
, const char *format
, ...) PRINTF_ATTRIBUTE(2, 3);
109 # define UWRAP_LOG(dbglvl, ...) uwrap_log((dbglvl), __VA_ARGS__)
111 static void uwrap_log(enum uwrap_dbglvl_e dbglvl
, const char *format
, ...)
116 unsigned int lvl
= 0;
118 d
= getenv("UID_WRAPPER_DEBUGLEVEL");
123 va_start(va
, format
);
124 vsnprintf(buffer
, sizeof(buffer
), format
, va
);
129 case UWRAP_LOG_ERROR
:
131 "UWRAP_ERROR(%d): %s\n",
132 (int)getpid(), buffer
);
136 "UWRAP_WARN(%d): %s\n",
137 (int)getpid(), buffer
);
139 case UWRAP_LOG_DEBUG
:
141 "UWRAP_DEBUG(%d): %s\n",
142 (int)getpid(), buffer
);
144 case UWRAP_LOG_TRACE
:
146 "UWRAP_TRACE(%d): %s\n",
147 (int)getpid(), buffer
);
158 #define LIBC_NAME "libc.so"
160 struct uwrap_libc_fns
{
161 int (*_libc_setuid
)(uid_t uid
);
162 uid_t (*_libc_getuid
)(void);
165 int (*_libc_seteuid
)(uid_t euid
);
168 int (*_libc_setreuid
)(uid_t ruid
, uid_t euid
);
170 #ifdef HAVE_SETRESUID
171 int (*_libc_setresuid
)(uid_t ruid
, uid_t euid
, uid_t suid
);
173 uid_t (*_libc_geteuid
)(void);
175 int (*_libc_setgid
)(gid_t gid
);
176 gid_t (*_libc_getgid
)(void);
178 int (*_libc_setegid
)(uid_t egid
);
181 int (*_libc_setregid
)(uid_t rgid
, uid_t egid
);
183 #ifdef HAVE_SETRESGID
184 int (*_libc_setresgid
)(uid_t rgid
, uid_t egid
, uid_t sgid
);
186 gid_t (*_libc_getegid
)(void);
187 int (*_libc_getgroups
)(int size
, gid_t list
[]);
188 int (*_libc_setgroups
)(size_t size
, const gid_t
*list
);
190 long int (*_libc_syscall
)(long int sysno
, ...);
195 * We keep the virtualised euid/egid/groups information here
197 struct uwrap_thread
{
212 struct uwrap_thread
*next
;
213 struct uwrap_thread
*prev
;
219 struct uwrap_libc_fns fns
;
228 struct uwrap_thread
*ids
;
231 static struct uwrap uwrap
;
233 /* Shortcut to the list item */
234 static UWRAP_THREAD
struct uwrap_thread
*uwrap_tls_id
;
236 /* The mutex or accessing the id */
237 static pthread_mutex_t uwrap_id_mutex
= PTHREAD_MUTEX_INITIALIZER
;
239 /*********************************************************
241 *********************************************************/
243 bool uid_wrapper_enabled(void);
244 void uwrap_destructor(void) DESTRUCTOR_ATTRIBUTE
;
246 /*********************************************************
247 * UWRAP LIBC LOADER FUNCTIONS
248 *********************************************************/
256 static void *uwrap_load_lib_handle(enum uwrap_lib lib
)
258 int flags
= RTLD_LAZY
;
263 flags
|= RTLD_DEEPBIND
;
269 case UWRAP_LIBSOCKET
:
272 handle
= uwrap
.libc
.handle
;
273 if (handle
== NULL
) {
274 for (handle
= NULL
, i
= 10; handle
== NULL
&& i
>= 0; i
--) {
275 char soname
[256] = {0};
277 snprintf(soname
, sizeof(soname
), "libc.so.%d", i
);
278 handle
= dlopen(soname
, flags
);
281 uwrap
.libc
.handle
= handle
;
286 if (handle
== NULL
) {
288 handle
= uwrap
.libc
.handle
= RTLD_NEXT
;
291 "Failed to dlopen library: %s\n",
300 static void *_uwrap_load_lib_function(enum uwrap_lib lib
, const char *fn_name
)
305 handle
= uwrap_load_lib_handle(lib
);
307 func
= dlsym(handle
, fn_name
);
310 "Failed to find %s: %s\n",
318 #define uwrap_load_lib_function(lib, fn_name) \
319 if (uwrap.libc.fns._libc_##fn_name == NULL) { \
320 *(void **) (&uwrap.libc.fns._libc_##fn_name) = \
321 _uwrap_load_lib_function(lib, #fn_name); \
327 * Functions expeciall from libc need to be loaded individually, you can't load
328 * all at once or gdb will segfault at startup. The same applies to valgrind and
329 * has probably something todo with with the linker.
330 * So we need load each function at the point it is called the first time.
332 static int libc_setuid(uid_t uid
)
334 uwrap_load_lib_function(UWRAP_LIBC
, setuid
);
336 return uwrap
.libc
.fns
._libc_setuid(uid
);
339 static uid_t
libc_getuid(void)
341 uwrap_load_lib_function(UWRAP_LIBC
, getuid
);
343 return uwrap
.libc
.fns
._libc_getuid();
347 static int libc_seteuid(uid_t euid
)
349 uwrap_load_lib_function(UWRAP_LIBC
, seteuid
);
351 return uwrap
.libc
.fns
._libc_seteuid(euid
);
356 static int libc_setreuid(uid_t ruid
, uid_t euid
)
358 uwrap_load_lib_function(UWRAP_LIBC
, setreuid
);
360 return uwrap
.libc
.fns
._libc_setreuid(ruid
, euid
);
364 #ifdef HAVE_SETRESUID
365 static int libc_setresuid(uid_t ruid
, uid_t euid
, uid_t suid
)
367 uwrap_load_lib_function(UWRAP_LIBC
, setresuid
);
369 return uwrap
.libc
.fns
._libc_setresuid(ruid
, euid
, suid
);
373 static uid_t
libc_geteuid(void)
375 uwrap_load_lib_function(UWRAP_LIBC
, geteuid
);
377 return uwrap
.libc
.fns
._libc_geteuid();
380 static int libc_setgid(gid_t gid
)
382 uwrap_load_lib_function(UWRAP_LIBC
, setgid
);
384 return uwrap
.libc
.fns
._libc_setgid(gid
);
387 static gid_t
libc_getgid(void)
389 uwrap_load_lib_function(UWRAP_LIBC
, getgid
);
391 return uwrap
.libc
.fns
._libc_getgid();
395 static int libc_setegid(gid_t egid
)
397 uwrap_load_lib_function(UWRAP_LIBC
, setegid
);
399 return uwrap
.libc
.fns
._libc_setegid(egid
);
404 static int libc_setregid(gid_t rgid
, gid_t egid
)
406 uwrap_load_lib_function(UWRAP_LIBC
, setregid
);
408 return uwrap
.libc
.fns
._libc_setregid(rgid
, egid
);
412 #ifdef HAVE_SETRESGID
413 static int libc_setresgid(gid_t rgid
, gid_t egid
, gid_t sgid
)
415 uwrap_load_lib_function(UWRAP_LIBC
, setresgid
);
417 return uwrap
.libc
.fns
._libc_setresgid(rgid
, egid
, sgid
);
421 static gid_t
libc_getegid(void)
423 uwrap_load_lib_function(UWRAP_LIBC
, getegid
);
425 return uwrap
.libc
.fns
._libc_getegid();
428 static int libc_getgroups(int size
, gid_t list
[])
430 uwrap_load_lib_function(UWRAP_LIBC
, getgroups
);
432 return uwrap
.libc
.fns
._libc_getgroups(size
, list
);
435 static int libc_setgroups(size_t size
, const gid_t
*list
)
437 uwrap_load_lib_function(UWRAP_LIBC
, setgroups
);
439 return uwrap
.libc
.fns
._libc_setgroups(size
, list
);
443 static long int libc_vsyscall(long int sysno
, va_list va
)
449 uwrap_load_lib_function(UWRAP_LIBC
, syscall
);
451 for (i
= 0; i
< 8; i
++) {
452 args
[i
] = va_arg(va
, long int);
455 rc
= uwrap
.libc
.fns
._libc_syscall(sysno
,
469 /*********************************************************
471 *********************************************************/
473 static struct uwrap_thread
*find_uwrap_id(pthread_t tid
)
475 struct uwrap_thread
*id
;
477 for (id
= uwrap
.ids
; id
; id
= id
->next
) {
478 if (pthread_equal(id
->tid
, tid
)) {
486 static int uwrap_new_id(pthread_t tid
, bool do_alloc
)
488 struct uwrap_thread
*id
= uwrap_tls_id
;
491 id
= malloc(sizeof(struct uwrap_thread
));
493 UWRAP_LOG(UWRAP_LOG_ERROR
, "Unable to allocate memory");
498 id
->groups
= malloc(sizeof(gid_t
) * 1);
499 if (id
->groups
== NULL
) {
500 UWRAP_LOG(UWRAP_LOG_ERROR
, "Unable to allocate memory");
506 UWRAP_DLIST_ADD(uwrap
.ids
, id
);
513 id
->ruid
= id
->euid
= id
->suid
= uwrap
.myuid
;
514 id
->rgid
= id
->egid
= id
->sgid
= uwrap
.mygid
;
517 id
->groups
[0] = uwrap
.mygid
;
522 static void uwrap_thread_prepare(void)
524 pthread_mutex_lock(&uwrap_id_mutex
);
527 * What happens if another atfork prepare functions calls a uwrap
528 * function? So disable it in case another atfork prepare function
529 * calls a (s)uid function.
531 uwrap
.enabled
= false;
534 static void uwrap_thread_parent(void)
536 uwrap
.enabled
= true;
538 pthread_mutex_unlock(&uwrap_id_mutex
);
541 static void uwrap_thread_child(void)
543 uwrap
.enabled
= true;
545 pthread_mutex_unlock(&uwrap_id_mutex
);
548 static void uwrap_init(void)
550 const char *env
= getenv("UID_WRAPPER");
551 pthread_t tid
= pthread_self();
555 if (uwrap
.initialised
) {
556 struct uwrap_thread
*id
= uwrap_tls_id
;
563 pthread_mutex_lock(&uwrap_id_mutex
);
564 id
= find_uwrap_id(tid
);
566 rc
= uwrap_new_id(tid
, true);
571 /* We reuse an old thread id */
574 uwrap_new_id(tid
, false);
576 pthread_mutex_unlock(&uwrap_id_mutex
);
582 * If we hold a lock and the application forks, then the child
583 * is not able to unlock the mutex and we are in a deadlock.
584 * This should prevent such deadlocks.
586 pthread_atfork(&uwrap_thread_prepare
,
587 &uwrap_thread_parent
,
588 &uwrap_thread_child
);
590 pthread_mutex_lock(&uwrap_id_mutex
);
592 uwrap
.initialised
= true;
593 uwrap
.enabled
= false;
595 if (env
!= NULL
&& env
[0] == '1') {
596 const char *root
= getenv("UID_WRAPPER_ROOT");
599 /* put us in one group */
600 if (root
!= NULL
&& root
[0] == '1') {
604 uwrap
.myuid
= libc_geteuid();
605 uwrap
.mygid
= libc_getegid();
608 rc
= uwrap_new_id(tid
, true);
613 uwrap
.enabled
= true;
616 pthread_mutex_unlock(&uwrap_id_mutex
);
619 bool uid_wrapper_enabled(void)
623 return uwrap
.enabled
? true : false;
626 static int uwrap_setresuid_thread(uid_t ruid
, uid_t euid
, uid_t suid
)
628 struct uwrap_thread
*id
= uwrap_tls_id
;
630 if (ruid
== (uid_t
)-1 && euid
== (uid_t
)-1 && suid
== (uid_t
)-1) {
635 pthread_mutex_lock(&uwrap_id_mutex
);
636 if (ruid
!= (uid_t
)-1) {
640 if (euid
!= (uid_t
)-1) {
644 if (suid
!= (uid_t
)-1) {
647 pthread_mutex_unlock(&uwrap_id_mutex
);
652 static int uwrap_setresuid(uid_t ruid
, uid_t euid
, uid_t suid
)
654 struct uwrap_thread
*id
;
656 if (ruid
== (uid_t
)-1 && euid
== (uid_t
)-1 && suid
== (uid_t
)-1) {
661 pthread_mutex_lock(&uwrap_id_mutex
);
662 for (id
= uwrap
.ids
; id
; id
= id
->next
) {
667 if (ruid
!= (uid_t
)-1) {
671 if (euid
!= (uid_t
)-1) {
675 if (suid
!= (uid_t
)-1) {
679 pthread_mutex_unlock(&uwrap_id_mutex
);
687 int setuid(uid_t uid
)
689 if (!uid_wrapper_enabled()) {
690 return libc_setuid(uid
);
693 return uwrap_setresuid(uid
, -1, -1);
697 int seteuid(uid_t euid
)
699 if (euid
== (uid_t
)-1) {
704 if (!uid_wrapper_enabled()) {
705 return libc_seteuid(euid
);
708 return uwrap_setresuid(-1, euid
, -1);
713 int setreuid(uid_t ruid
, uid_t euid
)
715 if (ruid
== (uid_t
)-1 && euid
== (uid_t
)-1) {
720 if (!uid_wrapper_enabled()) {
721 return libc_setreuid(ruid
, euid
);
724 return uwrap_setresuid(ruid
, euid
, -1);
728 #ifdef HAVE_SETRESUID
729 int setresuid(uid_t ruid
, uid_t euid
, uid_t suid
)
731 if (!uid_wrapper_enabled()) {
732 return libc_setresuid(ruid
, euid
, suid
);
735 return uwrap_setresuid(ruid
, euid
, suid
);
742 static uid_t
uwrap_getuid(void)
744 struct uwrap_thread
*id
= uwrap_tls_id
;
747 pthread_mutex_lock(&uwrap_id_mutex
);
749 pthread_mutex_unlock(&uwrap_id_mutex
);
756 if (!uid_wrapper_enabled()) {
757 return libc_getuid();
760 return uwrap_getuid();
766 static uid_t
uwrap_geteuid(void)
768 const char *env
= getenv("UID_WRAPPER_MYUID");
769 struct uwrap_thread
*id
= uwrap_tls_id
;
772 pthread_mutex_lock(&uwrap_id_mutex
);
774 pthread_mutex_unlock(&uwrap_id_mutex
);
776 /* Disable root and return myuid */
777 if (env
!= NULL
&& env
[0] == '1') {
786 if (!uid_wrapper_enabled()) {
787 return libc_geteuid();
790 return uwrap_geteuid();
793 static int uwrap_setresgid_thread(gid_t rgid
, gid_t egid
, gid_t sgid
)
795 struct uwrap_thread
*id
= uwrap_tls_id
;
797 if (rgid
== (gid_t
)-1 && egid
== (gid_t
)-1 && sgid
== (gid_t
)-1) {
802 pthread_mutex_lock(&uwrap_id_mutex
);
803 if (rgid
!= (gid_t
)-1) {
807 if (egid
!= (gid_t
)-1) {
811 if (sgid
!= (gid_t
)-1) {
814 pthread_mutex_unlock(&uwrap_id_mutex
);
819 static int uwrap_setresgid(gid_t rgid
, gid_t egid
, gid_t sgid
)
821 struct uwrap_thread
*id
;
823 if (rgid
== (gid_t
)-1 && egid
== (gid_t
)-1 && sgid
== (gid_t
)-1) {
828 pthread_mutex_lock(&uwrap_id_mutex
);
829 for (id
= uwrap
.ids
; id
; id
= id
->next
) {
834 if (rgid
!= (gid_t
)-1) {
838 if (egid
!= (gid_t
)-1) {
842 if (sgid
!= (gid_t
)-1) {
846 pthread_mutex_unlock(&uwrap_id_mutex
);
854 int setgid(gid_t gid
)
856 if (!uid_wrapper_enabled()) {
857 return libc_setgid(gid
);
860 return uwrap_setresgid(gid
, -1, -1);
864 int setegid(gid_t egid
)
866 if (!uid_wrapper_enabled()) {
867 return libc_setegid(egid
);
870 return uwrap_setresgid(-1, egid
, -1);
875 int setregid(gid_t rgid
, gid_t egid
)
877 if (!uid_wrapper_enabled()) {
878 return libc_setregid(rgid
, egid
);
881 return uwrap_setresgid(rgid
, egid
, -1);
885 #ifdef HAVE_SETRESGID
886 int setresgid(gid_t rgid
, gid_t egid
, gid_t sgid
)
888 if (!uid_wrapper_enabled()) {
889 return libc_setresgid(rgid
, egid
, sgid
);
892 return uwrap_setresgid(rgid
, egid
, sgid
);
899 static gid_t
uwrap_getgid(void)
901 struct uwrap_thread
*id
= uwrap_tls_id
;
904 pthread_mutex_lock(&uwrap_id_mutex
);
906 pthread_mutex_unlock(&uwrap_id_mutex
);
913 if (!uid_wrapper_enabled()) {
914 return libc_getgid();
917 return uwrap_getgid();
923 static uid_t
uwrap_getegid(void)
925 struct uwrap_thread
*id
= uwrap_tls_id
;
928 pthread_mutex_lock(&uwrap_id_mutex
);
930 pthread_mutex_unlock(&uwrap_id_mutex
);
937 if (!uid_wrapper_enabled()) {
938 return libc_getegid();
941 return uwrap_getegid();
944 static int uwrap_setgroups_thread(size_t size
, const gid_t
*list
)
946 struct uwrap_thread
*id
= uwrap_tls_id
;
949 pthread_mutex_lock(&uwrap_id_mutex
);
954 tmp
= realloc(id
->groups
, sizeof(gid_t
) * size
);
962 memcpy(id
->groups
, list
, size
* sizeof(gid_t
));
967 pthread_mutex_unlock(&uwrap_id_mutex
);
972 static int uwrap_setgroups(size_t size
, const gid_t
*list
)
974 struct uwrap_thread
*id
;
977 pthread_mutex_lock(&uwrap_id_mutex
);
980 for (id
= uwrap
.ids
; id
; id
= id
->next
) {
983 tmp
= realloc(id
->groups
, sizeof(gid_t
) * size
);
991 memcpy(id
->groups
, list
, size
* sizeof(gid_t
));
997 pthread_mutex_unlock(&uwrap_id_mutex
);
1002 #ifdef HAVE_SETGROUPS_INT
1003 int setgroups(int size
, const gid_t
*list
)
1005 int setgroups(size_t size
, const gid_t
*list
)
1008 if (!uid_wrapper_enabled()) {
1009 return libc_setgroups(size
, list
);
1012 return uwrap_setgroups(size
, list
);
1015 static int uwrap_getgroups(int size
, gid_t
*list
)
1017 struct uwrap_thread
*id
= uwrap_tls_id
;
1020 pthread_mutex_lock(&uwrap_id_mutex
);
1021 ngroups
= id
->ngroups
;
1023 if (size
> ngroups
) {
1029 if (size
< ngroups
) {
1033 memcpy(list
, id
->groups
, size
* sizeof(gid_t
));
1036 pthread_mutex_unlock(&uwrap_id_mutex
);
1041 int getgroups(int size
, gid_t
*list
)
1043 if (!uid_wrapper_enabled()) {
1044 return libc_getgroups(size
, list
);
1047 return uwrap_getgroups(size
, list
);
1050 #if (defined(HAVE_SYS_SYSCALL_H) || defined(HAVE_SYSCALL_H)) \
1051 && (defined(SYS_setreuid) || defined(SYS_setreuid32))
1052 static long int uwrap_syscall (long int sysno
, va_list vp
)
1059 #ifdef HAVE_LINUX_32BIT_SYSCALLS
1063 rc
= uwrap_getgid();
1068 #ifdef HAVE_LINUX_32BIT_SYSCALLS
1072 rc
= uwrap_getegid();
1075 #endif /* SYS_getegid */
1077 #ifdef HAVE_LINUX_32BIT_SYSCALLS
1081 gid_t gid
= (gid_t
) va_arg(vp
, int);
1083 rc
= uwrap_setresgid_thread(gid
, -1, -1);
1087 #ifdef HAVE_LINUX_32BIT_SYSCALLS
1088 case SYS_setregid32
:
1091 uid_t rgid
= (uid_t
) va_arg(vp
, int);
1092 uid_t egid
= (uid_t
) va_arg(vp
, int);
1094 rc
= uwrap_setresgid_thread(rgid
, egid
, -1);
1097 #ifdef SYS_setresgid
1099 #ifdef HAVE_LINUX_32BIT_SYSCALLS
1100 case SYS_setresgid32
:
1103 uid_t rgid
= (uid_t
) va_arg(vp
, int);
1104 uid_t egid
= (uid_t
) va_arg(vp
, int);
1105 uid_t sgid
= (uid_t
) va_arg(vp
, int);
1107 rc
= uwrap_setresgid_thread(rgid
, egid
, sgid
);
1110 #endif /* SYS_setresgid */
1114 #ifdef HAVE_LINUX_32BIT_SYSCALLS
1118 rc
= uwrap_getuid();
1123 #ifdef HAVE_LINUX_32BIT_SYSCALLS
1127 rc
= uwrap_geteuid();
1130 #endif /* SYS_geteuid */
1132 #ifdef HAVE_LINUX_32BIT_SYSCALLS
1136 uid_t uid
= (uid_t
) va_arg(vp
, int);
1138 rc
= uwrap_setresuid_thread(uid
, -1, -1);
1142 #ifdef HAVE_LINUX_32BIT_SYSCALLS
1143 case SYS_setreuid32
:
1146 uid_t ruid
= (uid_t
) va_arg(vp
, int);
1147 uid_t euid
= (uid_t
) va_arg(vp
, int);
1149 rc
= uwrap_setresuid_thread(ruid
, euid
, -1);
1152 #ifdef SYS_setresuid
1154 #ifdef HAVE_LINUX_32BIT_SYSCALLS
1155 case SYS_setresuid32
:
1158 uid_t ruid
= (uid_t
) va_arg(vp
, int);
1159 uid_t euid
= (uid_t
) va_arg(vp
, int);
1160 uid_t suid
= (uid_t
) va_arg(vp
, int);
1162 rc
= uwrap_setresuid_thread(ruid
, euid
, suid
);
1165 #endif /* SYS_setresuid */
1169 #ifdef HAVE_LINUX_32BIT_SYSCALLS
1170 case SYS_setgroups32
:
1173 size_t size
= (size_t) va_arg(vp
, size_t);
1174 gid_t
*list
= (gid_t
*) va_arg(vp
, int *);
1176 rc
= uwrap_setgroups_thread(size
, list
);
1180 UWRAP_LOG(UWRAP_LOG_DEBUG
,
1181 "UID_WRAPPER calling non-wrapped syscall %lu\n",
1184 rc
= libc_vsyscall(sysno
, vp
);
1192 #ifdef HAVE_SYSCALL_INT
1193 int syscall (int sysno
, ...)
1195 long int syscall (long int sysno
, ...)
1198 #ifdef HAVE_SYSCALL_INT
1205 va_start(va
, sysno
);
1207 if (!uid_wrapper_enabled()) {
1208 rc
= libc_vsyscall(sysno
, va
);
1213 rc
= uwrap_syscall(sysno
, va
);
1218 #endif /* HAVE_SYSCALL */
1219 #endif /* HAVE_SYS_SYSCALL_H || HAVE_SYSCALL_H */
1221 /****************************
1223 ***************************/
1226 * This function is called when the library is unloaded and makes sure that
1227 * resources are freed.
1229 void uwrap_destructor(void)
1231 struct uwrap_thread
*u
= uwrap
.ids
;
1233 pthread_mutex_lock(&uwrap_id_mutex
);
1235 UWRAP_DLIST_REMOVE(uwrap
.ids
, u
);
1237 SAFE_FREE(u
->groups
);
1242 pthread_mutex_unlock(&uwrap_id_mutex
);
1244 if (uwrap
.libc
.handle
!= NULL
) {
1245 dlclose(uwrap
.libc
.handle
);