#include "winbind_client.h"
+#if HAVE_PTHREAD_H
+#include <pthread.h>
+#endif
+
+#if HAVE_PTHREAD
+static pthread_mutex_t winbind_nss_mutex = PTHREAD_MUTEX_INITIALIZER;
+#endif
+
/* Maximum number of users to pass back over the unix domain socket
per call. This is not a static limit on the total number of users
or groups returned in total. */
fprintf(stderr, "[%5d]: setpwent\n", getpid());
#endif
+#if HAVE_PTHREAD
+ pthread_mutex_lock(&winbind_nss_mutex);
+#endif
+
if (num_pw_cache > 0) {
ndx_pw_cache = num_pw_cache = 0;
winbindd_free_response(&getpwent_response);
fprintf(stderr, "[%5d]: setpwent returns %s (%d)\n", getpid(),
nss_err_str(ret), ret);
#endif
+
+#if HAVE_PTHREAD
+ pthread_mutex_unlock(&winbind_nss_mutex);
+#endif
return ret;
}
fprintf(stderr, "[%5d]: endpwent\n", getpid());
#endif
+#if HAVE_PTHREAD
+ pthread_mutex_lock(&winbind_nss_mutex);
+#endif
+
if (num_pw_cache > 0) {
ndx_pw_cache = num_pw_cache = 0;
winbindd_free_response(&getpwent_response);
fprintf(stderr, "[%5d]: endpwent returns %s (%d)\n", getpid(),
nss_err_str(ret), ret);
#endif
+
+#if HAVE_PTHREAD
+ pthread_mutex_unlock(&winbind_nss_mutex);
+#endif
+
return ret;
}
fprintf(stderr, "[%5d]: getpwent\n", getpid());
#endif
+#if HAVE_PTHREAD
+ pthread_mutex_lock(&winbind_nss_mutex);
+#endif
+
/* Return an entry from the cache if we have one, or if we are
called again because we exceeded our static buffer. */
fprintf(stderr, "[%5d]: getpwent returns %s (%d)\n", getpid(),
nss_err_str(ret), ret);
#endif
+
+#if HAVE_PTHREAD
+ pthread_mutex_unlock(&winbind_nss_mutex);
+#endif
return ret;
}
NSS_STATUS ret;
static struct winbindd_response response;
struct winbindd_request request;
- static int keep_response=0;
+ static int keep_response;
#ifdef DEBUG_NSS
- fprintf(stderr, "[%5d]: getpwuid %d\n", getpid(), (unsigned int)uid);
+ fprintf(stderr, "[%5d]: getpwuid_r %d\n", getpid(), (unsigned int)uid);
+#endif
+
+#if HAVE_PTHREAD
+ pthread_mutex_lock(&winbind_nss_mutex);
#endif
/* If our static buffer needs to be expanded we are called again */
- if (!keep_response) {
+ if (!keep_response || uid != response.data.pw.pw_uid) {
/* Call for the first time */
ret = fill_pwent(result, &response.data.pw, &buffer, &buflen);
if (ret == NSS_STATUS_TRYAGAIN) {
- keep_response = true;
*errnop = errno = ERANGE;
goto done;
}
}
winbindd_free_response(&response);
+
done:
#ifdef DEBUG_NSS
fprintf(stderr, "[%5d]: getpwuid %d returns %s (%d)\n", getpid(),
(unsigned int)uid, nss_err_str(ret), ret);
#endif
+
+#if HAVE_PTHREAD
+ pthread_mutex_unlock(&winbind_nss_mutex);
+#endif
+
return ret;
}
static int keep_response;
#ifdef DEBUG_NSS
- fprintf(stderr, "[%5d]: getpwnam %s\n", getpid(), name);
+ fprintf(stderr, "[%5d]: getpwnam_r %s\n", getpid(), name);
+#endif
+
+#if HAVE_PTHREAD
+ pthread_mutex_lock(&winbind_nss_mutex);
#endif
/* If our static buffer needs to be expanded we are called again */
- if (!keep_response) {
+ if (!keep_response || strcmp(name,response.data.pw.pw_name) != 0) {
/* Call for the first time */
fprintf(stderr, "[%5d]: getpwnam %s returns %s (%d)\n", getpid(),
name, nss_err_str(ret), ret);
#endif
+
+#if HAVE_PTHREAD
+ pthread_mutex_unlock(&winbind_nss_mutex);
+#endif
+
return ret;
}
fprintf(stderr, "[%5d]: setgrent\n", getpid());
#endif
+#if HAVE_PTHREAD
+ pthread_mutex_lock(&winbind_nss_mutex);
+#endif
+
if (num_gr_cache > 0) {
ndx_gr_cache = num_gr_cache = 0;
winbindd_free_response(&getgrent_response);
fprintf(stderr, "[%5d]: setgrent returns %s (%d)\n", getpid(),
nss_err_str(ret), ret);
#endif
+
+#if HAVE_PTHREAD
+ pthread_mutex_unlock(&winbind_nss_mutex);
+#endif
+
return ret;
}
fprintf(stderr, "[%5d]: endgrent\n", getpid());
#endif
+#if HAVE_PTHREAD
+ pthread_mutex_lock(&winbind_nss_mutex);
+#endif
+
if (num_gr_cache > 0) {
ndx_gr_cache = num_gr_cache = 0;
winbindd_free_response(&getgrent_response);
fprintf(stderr, "[%5d]: endgrent returns %s (%d)\n", getpid(),
nss_err_str(ret), ret);
#endif
+
+#if HAVE_PTHREAD
+ pthread_mutex_unlock(&winbind_nss_mutex);
+#endif
+
return ret;
}
fprintf(stderr, "[%5d]: getgrent\n", getpid());
#endif
+#if HAVE_PTHREAD
+ pthread_mutex_lock(&winbind_nss_mutex);
+#endif
+
/* Return an entry from the cache if we have one, or if we are
called again because we exceeded our static buffer. */
fprintf(stderr, "[%5d]: getgrent returns %s (%d)\n", getpid(),
nss_err_str(ret), ret);
#endif
+
+#if HAVE_PTHREAD
+ pthread_mutex_unlock(&winbind_nss_mutex);
+#endif
+
return ret;
}
fprintf(stderr, "[%5d]: getgrnam %s\n", getpid(), name);
#endif
+#if HAVE_PTHREAD
+ pthread_mutex_lock(&winbind_nss_mutex);
+#endif
+
/* If our static buffer needs to be expanded we are called again */
-
- if (!keep_response) {
+ /* Or if the stored response group name differs from the request. */
+
+ if (!keep_response || strcmp(name,response.data.gr.gr_name) != 0) {
/* Call for the first time */
}
} else {
-
+
/* We've been called again */
-
+
ret = fill_grent(result, &response.data.gr,
(char *)response.extra_data.data, &buffer,
&buflen);
-
+
if (ret == NSS_STATUS_TRYAGAIN) {
keep_response = true;
*errnop = errno = ERANGE;
fprintf(stderr, "[%5d]: getgrnam %s returns %s (%d)\n", getpid(),
name, nss_err_str(ret), ret);
#endif
+
+#if HAVE_PTHREAD
+ pthread_mutex_unlock(&winbind_nss_mutex);
+#endif
+
return ret;
}
fprintf(stderr, "[%5d]: getgrgid %d\n", getpid(), gid);
#endif
+#if HAVE_PTHREAD
+ pthread_mutex_lock(&winbind_nss_mutex);
+#endif
+
/* If our static buffer needs to be expanded we are called again */
+ /* Or if the stored response group name differs from the request. */
- if (!keep_response) {
+ if (!keep_response || gid != response.data.gr.gr_gid) {
/* Call for the first time */
fprintf(stderr, "[%5d]: getgrgid %d returns %s (%d)\n", getpid(),
(unsigned int)gid, nss_err_str(ret), ret);
#endif
+
+#if HAVE_PTHREAD
+ pthread_mutex_unlock(&winbind_nss_mutex);
+#endif
return ret;
}
user, group);
#endif
+#if HAVE_PTHREAD
+ pthread_mutex_lock(&winbind_nss_mutex);
+#endif
+
ZERO_STRUCT(request);
ZERO_STRUCT(response);
fprintf(stderr, "[%5d]: initgroups %s returns %s (%d)\n", getpid(),
user, nss_err_str(ret), ret);
#endif
+
+#if HAVE_PTHREAD
+ pthread_mutex_unlock(&winbind_nss_mutex);
+#endif
+
return ret;
}
fprintf(stderr, "[%5d]: getusersids %s\n", getpid(), user_sid);
#endif
+#if HAVE_PTHREAD
+ pthread_mutex_lock(&winbind_nss_mutex);
+#endif
+
ZERO_STRUCT(request);
ZERO_STRUCT(response);
done:
winbindd_free_response(&response);
+
+#if HAVE_PTHREAD
+ pthread_mutex_unlock(&winbind_nss_mutex);
+#endif
+
return ret;
}
fprintf(stderr, "[%5d]: nametosid %s\n", getpid(), name);
#endif
+#if HAVE_PTHREAD
+ pthread_mutex_lock(&winbind_nss_mutex);
+#endif
+
ZERO_STRUCT(response);
ZERO_STRUCT(request);
failed:
winbindd_free_response(&response);
+
+#if HAVE_PTHREAD
+ pthread_mutex_unlock(&winbind_nss_mutex);
+#endif
+
return ret;
}
fprintf(stderr, "[%5d]: sidtoname %s\n", getpid(), sid);
#endif
+#if HAVE_PTHREAD
+ pthread_mutex_lock(&winbind_nss_mutex);
+#endif
+
ZERO_STRUCT(response);
ZERO_STRUCT(request);
failed:
winbindd_free_response(&response);
+
+#if HAVE_PTHREAD
+ pthread_mutex_unlock(&winbind_nss_mutex);
+#endif
+
return ret;
}
fprintf(stderr, "[%5d]: sidtouid %s\n", getpid(), sid);
#endif
+#if HAVE_PTHREAD
+ pthread_mutex_lock(&winbind_nss_mutex);
+#endif
+
ZERO_STRUCT(request);
ZERO_STRUCT(response);
*uid = response.data.uid;
failed:
+
+#if HAVE_PTHREAD
+ pthread_mutex_unlock(&winbind_nss_mutex);
+#endif
+
return ret;
}
fprintf(stderr, "[%5d]: sidtogid %s\n", getpid(), sid);
#endif
+#if HAVE_PTHREAD
+ pthread_mutex_lock(&winbind_nss_mutex);
+#endif
+
ZERO_STRUCT(request);
ZERO_STRUCT(response);
*gid = response.data.gid;
failed:
+
+#if HAVE_PTHREAD
+ pthread_mutex_lock(&winbind_nss_mutex);
+#endif
+
return ret;
}
fprintf(stderr, "[%5u]: uidtosid %u\n", (unsigned int)getpid(), (unsigned int)uid);
#endif
+#if HAVE_PTHREAD
+ pthread_mutex_lock(&winbind_nss_mutex);
+#endif
+
ZERO_STRUCT(response);
ZERO_STRUCT(request);
failed:
winbindd_free_response(&response);
+
+#if HAVE_PTHREAD
+ pthread_mutex_unlock(&winbind_nss_mutex);
+#endif
+
return ret;
}
fprintf(stderr, "[%5u]: gidtosid %u\n", (unsigned int)getpid(), (unsigned int)gid);
#endif
+#if HAVE_PTHREAD
+ pthread_mutex_lock(&winbind_nss_mutex);
+#endif
+
ZERO_STRUCT(response);
ZERO_STRUCT(request);
failed:
winbindd_free_response(&response);
+
+#if HAVE_PTHREAD
+ pthread_mutex_unlock(&winbind_nss_mutex);
+#endif
+
return ret;
}