# define UWRAP_THREAD
#endif
+# define UWRAP_LOCK(m) do { \
+ pthread_mutex_lock(&( m ## _mutex)); \
+} while(0)
+
+# define UWRAP_UNLOCK(m) do { \
+ pthread_mutex_unlock(&( m ## _mutex)); \
+} while(0)
+
#ifdef HAVE_DESTRUCTOR_ATTRIBUTE
#define DESTRUCTOR_ATTRIBUTE __attribute__ ((destructor))
#else
static void uwrap_thread_prepare(void)
{
- pthread_mutex_lock(&uwrap_id_mutex);
+ UWRAP_LOCK(uwrap_id);
/*
* What happens if another atfork prepare functions calls a uwrap
{
uwrap.enabled = true;
- pthread_mutex_unlock(&uwrap_id_mutex);
+ UWRAP_UNLOCK(uwrap_id);
}
static void uwrap_thread_child(void)
{
uwrap.enabled = true;
- pthread_mutex_unlock(&uwrap_id_mutex);
+ UWRAP_UNLOCK(uwrap_id);
}
static void uwrap_init(void)
return;
}
- pthread_mutex_lock(&uwrap_id_mutex);
+ UWRAP_LOCK(uwrap_id);
id = find_uwrap_id(tid);
if (id == NULL) {
rc = uwrap_new_id(tid, true);
uwrap_new_id(tid, false);
}
- pthread_mutex_unlock(&uwrap_id_mutex);
+ UWRAP_UNLOCK(uwrap_id);
return;
}
&uwrap_thread_parent,
&uwrap_thread_child);
- pthread_mutex_lock(&uwrap_id_mutex);
+ UWRAP_LOCK(uwrap_id);
uwrap.initialised = true;
uwrap.enabled = false;
uwrap.myuid == 0 ? "root" : "user");
}
- pthread_mutex_unlock(&uwrap_id_mutex);
+ UWRAP_UNLOCK(uwrap_id);
UWRAP_LOG(UWRAP_LOG_DEBUG, "Succeccfully initialized uid_wrapper");
}
uwrap_init();
return uwrap.enabled ? true : false;
+ UWRAP_UNLOCK(uwrap_id);
}
static int uwrap_setresuid_thread(uid_t ruid, uid_t euid, uid_t suid)
return -1;
}
- pthread_mutex_lock(&uwrap_id_mutex);
+ UWRAP_LOCK(uwrap_id);
if (ruid != (uid_t)-1) {
id->ruid = ruid;
}
if (suid != (uid_t)-1) {
id->suid = suid;
}
- pthread_mutex_unlock(&uwrap_id_mutex);
+ UWRAP_UNLOCK(uwrap_id);
return 0;
}
return -1;
}
- pthread_mutex_lock(&uwrap_id_mutex);
+ UWRAP_LOCK(uwrap_id);
for (id = uwrap.ids; id; id = id->next) {
if (id->dead) {
continue;
id->suid = suid;
}
}
- pthread_mutex_unlock(&uwrap_id_mutex);
+ UWRAP_UNLOCK(uwrap_id);
return 0;
}
struct uwrap_thread *id = uwrap_tls_id;
uid_t uid;
- pthread_mutex_lock(&uwrap_id_mutex);
+ UWRAP_LOCK(uwrap_id);
uid = id->ruid;
- pthread_mutex_unlock(&uwrap_id_mutex);
+ UWRAP_UNLOCK(uwrap_id);
return uid;
}
struct uwrap_thread *id = uwrap_tls_id;
uid_t uid;
- pthread_mutex_lock(&uwrap_id_mutex);
+ UWRAP_LOCK(uwrap_id);
uid = id->euid;
- pthread_mutex_unlock(&uwrap_id_mutex);
+ UWRAP_UNLOCK(uwrap_id);
/* Disable root and return myuid */
if (env != NULL && env[0] == '1') {
return -1;
}
- pthread_mutex_lock(&uwrap_id_mutex);
+ UWRAP_LOCK(uwrap_id);
if (rgid != (gid_t)-1) {
id->rgid = rgid;
}
if (sgid != (gid_t)-1) {
id->sgid = sgid;
}
- pthread_mutex_unlock(&uwrap_id_mutex);
+ UWRAP_UNLOCK(uwrap_id);
return 0;
}
return -1;
}
- pthread_mutex_lock(&uwrap_id_mutex);
+ UWRAP_LOCK(uwrap_id);
for (id = uwrap.ids; id; id = id->next) {
if (id->dead) {
continue;
id->sgid = sgid;
}
}
- pthread_mutex_unlock(&uwrap_id_mutex);
+ UWRAP_UNLOCK(uwrap_id);
return 0;
}
struct uwrap_thread *id = uwrap_tls_id;
gid_t gid;
- pthread_mutex_lock(&uwrap_id_mutex);
+ UWRAP_LOCK(uwrap_id);
gid = id->rgid;
- pthread_mutex_unlock(&uwrap_id_mutex);
+ UWRAP_UNLOCK(uwrap_id);
return gid;
}
struct uwrap_thread *id = uwrap_tls_id;
gid_t gid;
- pthread_mutex_lock(&uwrap_id_mutex);
+ UWRAP_LOCK(uwrap_id);
gid = id->egid;
- pthread_mutex_unlock(&uwrap_id_mutex);
+ UWRAP_UNLOCK(uwrap_id);
return gid;
}
struct uwrap_thread *id = uwrap_tls_id;
int rc = -1;
- pthread_mutex_lock(&uwrap_id_mutex);
+ UWRAP_LOCK(uwrap_id);
if (size == 0) {
free(id->groups);
rc = 0;
out:
- pthread_mutex_unlock(&uwrap_id_mutex);
+ UWRAP_UNLOCK(uwrap_id);
return rc;
}
struct uwrap_thread *id;
int rc = -1;
- pthread_mutex_lock(&uwrap_id_mutex);
+ UWRAP_LOCK(uwrap_id);
if (size == 0) {
for (id = uwrap.ids; id; id = id->next) {
rc = 0;
out:
- pthread_mutex_unlock(&uwrap_id_mutex);
+ UWRAP_UNLOCK(uwrap_id);
return rc;
}
struct uwrap_thread *id = uwrap_tls_id;
int ngroups;
- pthread_mutex_lock(&uwrap_id_mutex);
+ UWRAP_LOCK(uwrap_id);
ngroups = id->ngroups;
if (size > ngroups) {
memcpy(list, id->groups, size * sizeof(gid_t));
out:
- pthread_mutex_unlock(&uwrap_id_mutex);
+ UWRAP_UNLOCK(uwrap_id);
return ngroups;
}
{
struct uwrap_thread *u = uwrap.ids;
- pthread_mutex_lock(&uwrap_id_mutex);
+ UWRAP_LOCK(uwrap_id);
while (u != NULL) {
UWRAP_DLIST_REMOVE(uwrap.ids, u);
u = uwrap.ids;
}
- pthread_mutex_unlock(&uwrap_id_mutex);
+ UWRAP_UNLOCK(uwrap_id);
if (uwrap.libc.handle != NULL) {
dlclose(uwrap.libc.handle);