aboutsummaryrefslogtreecommitdiff
path: root/nscd
diff options
context:
space:
mode:
Diffstat (limited to 'nscd')
-rw-r--r--nscd/grpcache.c34
-rw-r--r--nscd/nscd.c61
-rw-r--r--nscd/pwdcache.c35
3 files changed, 95 insertions, 35 deletions
diff --git a/nscd/grpcache.c b/nscd/grpcache.c
index 3f3f4ba0ec..2806ddd52e 100644
--- a/nscd/grpcache.c
+++ b/nscd/grpcache.c
@@ -22,6 +22,7 @@
#include <pthread.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include <rpcsvc/nis.h>
#include <sys/types.h>
@@ -48,7 +49,7 @@ typedef struct grphash grphash;
struct gidhash
{
struct gidhash *next;
- struct grphash *grptr;
+ struct group *grptr;
};
typedef struct gidhash gidhash;
@@ -176,6 +177,7 @@ static int
add_cache (struct group *grp)
{
grphash *work;
+ gidhash *gidwork;
unsigned long int hash = __nis_hash (grp->gr_name,
strlen (grp->gr_name)) % modulo;
@@ -197,7 +199,17 @@ add_cache (struct group *grp)
}
time (&work->create);
- gidtbl[grp->gr_gid % modulo].grptr = work;
+ gidwork = &gidtbl[grp->gr_gid % modulo];
+ if (gidwork->grptr == NULL)
+ gidwork->grptr = work->grp;
+ else
+ {
+ while (gidwork->next != NULL)
+ gidwork = gidwork->next;
+
+ gidwork->next = calloc (1, sizeof (gidhash));
+ gidwork->next->grptr = work->grp;
+ }
return 0;
}
@@ -231,8 +243,8 @@ cache_search_gid (gid_t gid)
while (work->grptr != NULL)
{
- if (work->grptr->grp->gr_gid == gid)
- return work->grptr->grp;
+ if (work->grptr->gr_gid == gid)
+ return work->grptr;
if (work->next != NULL)
work = work->next;
else
@@ -475,7 +487,7 @@ cache_getgrgid (void *v_param)
return NULL;
}
-void *
+static void *
grptable_update (void *v)
{
time_t now;
@@ -509,7 +521,7 @@ grptable_update (void *v)
while (uh && uh->grptr)
{
- if (uh->grptr->grp->gr_gid == work->grp->gr_gid)
+ if (uh->grptr->gr_gid == work->grp->gr_gid)
{
if (debug_flag > 3)
dbg_log (_("Give gid for \"%s\" free"),
@@ -543,14 +555,14 @@ grptable_update (void *v)
}
}
if (debug_flag > 2)
- dbg_log (_("(pwdtable_update) Release wait lock\n"));
+ dbg_log (_("(grptable_update) Release wait lock"));
pthread_rwlock_unlock (&grplock);
sleep (20);
}
return NULL;
}
-void *
+static void *
negtable_update (void *v)
{
time_t now;
@@ -561,12 +573,12 @@ negtable_update (void *v)
while (!do_shutdown)
{
if (debug_flag > 2)
- dbg_log (_("(negtable_update) Wait for write lock!"));
+ dbg_log (_("(neggrptable_update) Wait for write lock!"));
pthread_rwlock_wrlock (&neglock);
if (debug_flag > 2)
- dbg_log (_("(negtable_update) Have write lock"));
+ dbg_log (_("(neggrptable_update) Have write lock"));
time (&now);
for (i = 0; i < modulo; ++i)
@@ -597,7 +609,7 @@ negtable_update (void *v)
}
}
if (debug_flag > 2)
- dbg_log (_("(negtable_update) Release wait lock"));
+ dbg_log (_("(neggrptable_update) Release wait lock"));
pthread_rwlock_unlock (&neglock);
sleep (10);
}
diff --git a/nscd/nscd.c b/nscd/nscd.c
index 9f167d2daa..e1c636775f 100644
--- a/nscd/nscd.c
+++ b/nscd/nscd.c
@@ -309,7 +309,7 @@ write_pid (const char *file)
typedef int (*pwbyname_function) (const char *name, struct passwd *pw,
char *buffer, size_t buflen);
-/* Hanlde incoming requests. */
+/* Handle incoming requests. */
static
void handle_requests (void)
{
@@ -317,6 +317,12 @@ void handle_requests (void)
int conn; /* Handle on which connection (client) the request came from. */
int done = 0;
char *key;
+ pthread_attr_t th_attr;
+
+ /* We will create all threads detached. Therefore prepare an attribute
+ now. */
+ pthread_attr_init (&th_attr);
+ pthread_attr_setdetachstate (&th_attr, PTHREAD_CREATE_DETACHED);
while (!done)
{
@@ -331,15 +337,23 @@ void handle_requests (void)
{
param_t *param = malloc (sizeof (param_t));
pthread_t thread;
+ int status;
if (debug_flag)
dbg_log ("\tGETPWBYNAME (%s)", key);
param->key = key;
param->conn = conn;
if (disabled_passwd)
- pthread_create (&thread, NULL, cache_pw_disabled, (void *)param);
+ status = pthread_create (&thread, &th_attr, cache_pw_disabled,
+ (void *)param);
else
- pthread_create (&thread, NULL, cache_getpwnam, (void *)param);
+ status = pthread_create (&thread, &th_attr, cache_getpwnam,
+ (void *)param);
+ if (status != 0)
+ {
+ dbg_log (_("Creation of thread failed: %s"), strerror (errno));
+ close_socket (conn);
+ }
pthread_detach (thread);
}
break;
@@ -347,48 +361,69 @@ void handle_requests (void)
{
param_t *param = malloc (sizeof (param_t));
pthread_t thread;
+ int status;
if (debug_flag)
dbg_log ("\tGETPWBYUID (%s)", key);
param->key = key;
param->conn = conn;
if (disabled_passwd)
- pthread_create (&thread, NULL, cache_pw_disabled, (void *)param);
+ status = pthread_create (&thread, &th_attr, cache_pw_disabled,
+ (void *)param);
else
- pthread_create (&thread, NULL, cache_getpwuid, (void *)param);
- pthread_detach (thread);
+ status = pthread_create (&thread, &th_attr, cache_getpwuid,
+ (void *)param);
+ if (status != 0)
+ {
+ dbg_log (_("Creation of thread failed: %s"), strerror (errno));
+ close_socket (conn);
+ }
}
break;
case GETGRBYNAME:
{
param_t *param = malloc (sizeof (param_t));
pthread_t thread;
+ int status;
if (debug_flag)
dbg_log ("\tGETGRBYNAME (%s)", key);
param->key = key;
param->conn = conn;
if (disabled_group)
- pthread_create (&thread, NULL, cache_gr_disabled, (void *)param);
+ status = pthread_create (&thread, &th_attr, cache_gr_disabled,
+ (void *)param);
else
- pthread_create (&thread, NULL, cache_getgrnam, (void *)param);
- pthread_detach (thread);
+ status = pthread_create (&thread, &th_attr, cache_getgrnam,
+ (void *)param);
+ if (status != 0)
+ {
+ dbg_log (_("Creation of thread failed: %s"), strerror (errno));
+ close_socket (conn);
+ }
}
break;
case GETGRBYGID:
{
param_t *param = malloc (sizeof (param_t));
pthread_t thread;
+ int status;
if (debug_flag)
dbg_log ("\tGETGRBYGID (%s)", key);
param->key = key;
param->conn = conn;
if (disabled_group)
- pthread_create (&thread, NULL, cache_gr_disabled, (void *)param);
+ status = pthread_create (&thread, &th_attr, cache_gr_disabled,
+ (void *)param);
else
- pthread_create (&thread, NULL, cache_getgrgid, (void *)param);
- pthread_detach (thread);
+ status = pthread_create (&thread, &th_attr, cache_getgrgid,
+ (void *)param);
+ if (status != 0)
+ {
+ dbg_log (_("Creation of thread failed: %s"), strerror (errno));
+ close_socket (conn);
+ }
}
break;
case GETHOSTBYNAME:
@@ -432,4 +467,6 @@ void handle_requests (void)
break;
}
}
+
+ pthread_attr_destroy (&th_attr);
}
diff --git a/nscd/pwdcache.c b/nscd/pwdcache.c
index 721e77b7c9..e2bf73afc1 100644
--- a/nscd/pwdcache.c
+++ b/nscd/pwdcache.c
@@ -22,6 +22,7 @@
#include <pthread.h>
#include <pwd.h>
#include <string.h>
+#include <unistd.h>
#include <rpcsvc/nis.h>
#include <sys/types.h>
@@ -48,7 +49,7 @@ typedef struct pwdhash pwdhash;
struct uidhash
{
struct uidhash *next;
- struct pwdhash *pwptr;
+ struct passwd *pwptr;
};
typedef struct uidhash uidhash;
@@ -159,6 +160,7 @@ static int
add_cache (struct passwd *pwd)
{
pwdhash *work;
+ uidhash *uidwork;
unsigned long int hash = __nis_hash (pwd->pw_name,
strlen (pwd->pw_name)) % modulo;
@@ -180,8 +182,17 @@ add_cache (struct passwd *pwd)
}
/* Set a pointer from the pwuid hash table to the pwname hash table */
time (&work->create);
- uidtbl[pwd->pw_uid % modulo].pwptr = work;
+ uidwork = &uidtbl[pwd->pw_uid % modulo];
+ if (uidwork->pwptr == NULL)
+ uidwork->pwptr = work->pwd;
+ else
+ {
+ while (uidwork->next != NULL)
+ uidwork = uidwork->next;
+ uidwork->next = calloc (1, sizeof (uidhash));
+ uidwork->next->pwptr = work->pwd;
+ }
return 0;
}
@@ -214,8 +225,8 @@ cache_search_uid (uid_t uid)
while (work->pwptr != NULL)
{
- if (work->pwptr->pwd->pw_uid == uid)
- return work->pwptr->pwd;
+ if (work->pwptr->pw_uid == uid)
+ return work->pwptr;
if (work->next != NULL)
work = work->next;
else
@@ -458,7 +469,7 @@ cache_getpwuid (void *v_param)
return NULL;
}
-void *
+static void *
pwdtable_update (void *v)
{
time_t now;
@@ -492,7 +503,7 @@ pwdtable_update (void *v)
while (uh != NULL && uh->pwptr)
{
- if (uh->pwptr->pwd->pw_uid == work->pwd->pw_uid)
+ if (uh->pwptr->pw_uid == work->pwd->pw_uid)
{
if (debug_flag)
dbg_log (_("Give uid for \"%s\" free"),
@@ -533,7 +544,7 @@ pwdtable_update (void *v)
return NULL;
}
-void *
+static void *
negtable_update (void *v)
{
time_t now;
@@ -544,12 +555,12 @@ negtable_update (void *v)
while (!do_shutdown)
{
if (debug_flag > 2)
- dbg_log (_("(negtable_update) Wait for write lock!"));
+ dbg_log (_("(negpwdtable_update) Wait for write lock!"));
pthread_rwlock_wrlock (&neglock);
- if (debug_flag)
- dbg_log (_("(negtable_update) Have write lock"));
+ if (debug_flag > 2)
+ dbg_log (_("(negpwdtable_update) Have write lock"));
time (&now);
for (i = 0; i < modulo; ++i)
@@ -579,8 +590,8 @@ negtable_update (void *v)
work = work->next;
}
}
- if (debug_flag)
- dbg_log (_("(negtable_update) Release wait lock"));
+ if (debug_flag > 2)
+ dbg_log (_("(negpwdtable_update) Release wait lock"));
pthread_rwlock_unlock (&neglock);
sleep (10);