diff options
Diffstat (limited to 'nscd')
| -rw-r--r-- | nscd/Makefile | 2 | ||||
| -rw-r--r-- | nscd/cache.c | 2 | ||||
| -rw-r--r-- | nscd/gai.c | 5 | ||||
| -rw-r--r-- | nscd/grpcache.c | 3 | ||||
| -rw-r--r-- | nscd/nscd-client.h | 10 | ||||
| -rw-r--r-- | nscd/nscd.c | 4 | ||||
| -rw-r--r-- | nscd/nscd.init | 9 | ||||
| -rw-r--r-- | nscd/nscd_getai.c | 71 | ||||
| -rw-r--r-- | nscd/nscd_getgr_r.c | 108 | ||||
| -rw-r--r-- | nscd/nscd_gethst_r.c | 147 | ||||
| -rw-r--r-- | nscd/nscd_getpw_r.c | 70 | ||||
| -rw-r--r-- | nscd/nscd_helper.c | 43 | ||||
| -rw-r--r-- | nscd/nscd_initgroups.c | 62 | ||||
| -rw-r--r-- | nscd/pwdcache.c | 3 | ||||
| -rw-r--r-- | nscd/selinux.c | 18 | ||||
| -rw-r--r-- | nscd/selinux.h | 4 |
16 files changed, 222 insertions, 339 deletions
diff --git a/nscd/Makefile b/nscd/Makefile index 9c98018217..21657abeb7 100644 --- a/nscd/Makefile +++ b/nscd/Makefile @@ -119,9 +119,7 @@ CFLAGS-initgrcache.c += $(nscd-cflags) CFLAGS-gai.c += $(nscd-cflags) ifeq (yesyes,$(have-fpie)$(build-shared)) -ifeq (yes,$(have-z-relro)) relro-LDFLAGS += -Wl,-z,now -endif $(objpfx)nscd: $(addprefix $(objpfx),$(nscd-modules:=.o)) $(LINK.o) -pie -Wl,-O1 $(nscd-cflags) \ diff --git a/nscd/cache.c b/nscd/cache.c index be9be2aa4f..ef986f374a 100644 --- a/nscd/cache.c +++ b/nscd/cache.c @@ -125,7 +125,7 @@ cache_add (int type, const void *key, size_t len, struct datahead *packet, dbg_log (_("add new entry \"%s\" of type %s for %s to cache%s"), str, serv2str[type], dbnames[table - dbs], - first ? " (first)" : ""); + first ? _(" (first)") : ""); } unsigned long int hash = __nis_hash (key, len) % table->head->module; diff --git a/nscd/gai.c b/nscd/gai.c index 68719d876a..2e706bdfe7 100644 --- a/nscd/gai.c +++ b/nscd/gai.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc. +/* Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 2004. @@ -15,7 +15,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include <alloca.h> /* This file uses the getaddrinfo code but it compiles it without NSCD support. We just need a few symbol renames. */ #define __getservbyname_r getservbyname_r @@ -27,8 +26,6 @@ #define __sendto sendto #define __strchrnul strchrnul #define __getline getline -/* nscd uses 1MB or 2MB thread stacks. */ -#define __libc_use_alloca(size) (size <= __MAX_ALLOCA_CUTOFF) #include <getaddrinfo.c> diff --git a/nscd/grpcache.c b/nscd/grpcache.c index c207492cc0..5a8fba4759 100644 --- a/nscd/grpcache.c +++ b/nscd/grpcache.c @@ -1,5 +1,5 @@ /* Cache handling for group lookup. - Copyright (C) 1998-2005, 2006, 2007 Free Software Foundation, Inc. + Copyright (C) 1998-2005, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998. @@ -279,7 +279,6 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req, /* Adjust pointers into the memory block. */ gr_name = (char *) newp + (gr_name - (char *) dataset); cp = (char *) newp + (cp - (char *) dataset); - key_copy = (char *) newp + (key_copy - (char *) dataset); dataset = memcpy (newp, dataset, total + n); alloca_used = false; diff --git a/nscd/nscd-client.h b/nscd/nscd-client.h index 8946b6315b..0fd2d9f547 100644 --- a/nscd/nscd-client.h +++ b/nscd/nscd-client.h @@ -1,4 +1,4 @@ -/* Copyright (c) 1998, 1999, 2000, 2003, 2004, 2005, 2006, 2007 +/* Copyright (c) 1998, 1999, 2000, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998. @@ -307,10 +307,10 @@ static inline int __nscd_drop_map_ref (struct mapped_database *map, /* Search the mapped database. */ -extern struct datahead *__nscd_cache_search (request_type type, - const char *key, - size_t keylen, - const struct mapped_database *mapped); +extern const struct datahead *__nscd_cache_search (request_type type, + const char *key, + size_t keylen, + const struct mapped_database *mapped); /* Wrappers around read, readv and write that only read/write less than LEN bytes on error or EOF. */ diff --git a/nscd/nscd.c b/nscd/nscd.c index add4698406..b68ae2f413 100644 --- a/nscd/nscd.c +++ b/nscd/nscd.c @@ -1,4 +1,4 @@ -/* Copyright (c) 1998-2003, 2004, 2005, 2006 Free Software Foundation, Inc. +/* Copyright (c) 1998-2006, 2007 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998. @@ -402,7 +402,7 @@ print_version (FILE *stream, struct argp_state *state) Copyright (C) %s Free Software Foundation, Inc.\n\ This is free software; see the source for copying conditions. There is NO\n\ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ -"), "2006"); +"), "2007"); fprintf (stream, gettext ("Written by %s.\n"), "Thorsten Kukuk and Ulrich Drepper"); } diff --git a/nscd/nscd.init b/nscd/nscd.init index a0074b99e5..a882da7d8b 100644 --- a/nscd/nscd.init +++ b/nscd/nscd.init @@ -49,15 +49,8 @@ prog=nscd start () { [ -d /var/run/nscd ] || mkdir /var/run/nscd [ -d /var/db/nscd ] || mkdir /var/db/nscd - secure="" -# for table in passwd group hosts -# do -# if egrep -q '^'$table':.*nisplus' /etc/nsswitch.conf; then -# /usr/lib/nscd_nischeck $table || secure="$secure -S $table,yes" -# fi -# done echo -n $"Starting $prog: " - daemon /usr/sbin/nscd $secure + daemon /usr/sbin/nscd RETVAL=$? echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/nscd diff --git a/nscd/nscd_getai.c b/nscd/nscd_getai.c index 5df32dc6dc..b59c31ea26 100644 --- a/nscd/nscd_getai.c +++ b/nscd/nscd_getai.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc. +/* Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@redhat.com>, 2004. @@ -42,7 +42,6 @@ __nscd_getai (const char *key, struct nscd_ai_result **result, int *h_errnop) { size_t keylen = strlen (key) + 1; int gc_cycle; - int nretries = 0; /* If the mapping is available, try to search there instead of communicating with the nscd. */ @@ -51,53 +50,49 @@ __nscd_getai (const char *key, struct nscd_ai_result **result, int *h_errnop) &gc_cycle); retry:; + const ai_response_header *ai_resp = NULL; struct nscd_ai_result *resultbuf = NULL; const char *recend = (const char *) ~UINTMAX_C (0); char *respdata = NULL; int retval = -1; int sock = -1; - ai_response_header ai_resp; if (mapped != NO_MAPPING) { - struct datahead *found = __nscd_cache_search (GETAI, key, keylen, - mapped); + const struct datahead *found = __nscd_cache_search (GETAI, key, keylen, + mapped); if (found != NULL) { - respdata = (char *) (&found->data[0].aidata + 1); - ai_resp = found->data[0].aidata; + ai_resp = &found->data[0].aidata; + respdata = (char *) (ai_resp + 1); recend = (const char *) found->data + found->recsize; - /* Now check if we can trust ai_resp fields. If GC is - in progress, it can contain anything. */ - if (mapped->head->gc_cycle != gc_cycle) - { - retval = -2; - goto out; - } } } /* If we do not have the cache mapped, try to get the data over the socket. */ - if (respdata == NULL) + ai_response_header ai_resp_mem; + if (ai_resp == NULL) { - sock = __nscd_open_socket (key, keylen, GETAI, &ai_resp, - sizeof (ai_resp)); + sock = __nscd_open_socket (key, keylen, GETAI, &ai_resp_mem, + sizeof (ai_resp_mem)); if (sock == -1) { /* nscd not running or wrong version. */ __nss_not_use_nscd_hosts = 1; goto out; } + + ai_resp = &ai_resp_mem; } - if (ai_resp.found == 1) + if (ai_resp->found == 1) { - size_t datalen = ai_resp.naddrs + ai_resp.addrslen + ai_resp.canonlen; + size_t datalen = ai_resp->naddrs + ai_resp->addrslen + ai_resp->canonlen; - /* This check really only affects the case where the data + /* This check is really only affects the case where the data comes from the mapped cache. */ - if (respdata + datalen > recend) + if ((char *) (ai_resp + 1) + datalen > recend) { assert (sock == -1); goto out; @@ -113,10 +108,10 @@ __nscd_getai (const char *key, struct nscd_ai_result **result, int *h_errnop) } /* Set up the data structure, including pointers. */ - resultbuf->naddrs = ai_resp.naddrs; + resultbuf->naddrs = ai_resp->naddrs; resultbuf->addrs = (char *) (resultbuf + 1); - resultbuf->family = (uint8_t *) (resultbuf->addrs + ai_resp.addrslen); - if (ai_resp.canonlen != 0) + resultbuf->family = (uint8_t *) (resultbuf->addrs + ai_resp->addrslen); + if (ai_resp->canonlen != 0) resultbuf->canon = (char *) (resultbuf->family + resultbuf->naddrs); else resultbuf->canon = NULL; @@ -142,13 +137,10 @@ __nscd_getai (const char *key, struct nscd_ai_result **result, int *h_errnop) /* Try to detect corrupt databases. */ if (resultbuf->canon != NULL - && resultbuf->canon[ai_resp.canonlen - 1] != '\0') + && resultbuf->canon[ai_resp->canonlen - 1] != '\0') /* We cannot use the database. */ { - if (mapped->head->gc_cycle != gc_cycle) - retval = -2; - else - free (resultbuf); + free (resultbuf); goto out_close; } @@ -158,7 +150,7 @@ __nscd_getai (const char *key, struct nscd_ai_result **result, int *h_errnop) } else { - if (__builtin_expect (ai_resp.found == -1, 0)) + if (__builtin_expect (ai_resp->found == -1, 0)) { /* The daemon does not cache this database. */ __nss_not_use_nscd_hosts = 1; @@ -166,7 +158,7 @@ __nscd_getai (const char *key, struct nscd_ai_result **result, int *h_errnop) } /* Store the error number. */ - *h_errnop = ai_resp.error; + *h_errnop = ai_resp->error; /* The `errno' to some value != ERANGE. */ __set_errno (ENOENT); @@ -178,25 +170,22 @@ __nscd_getai (const char *key, struct nscd_ai_result **result, int *h_errnop) if (sock != -1) close_not_cancel_no_status (sock); out: - if (__nscd_drop_map_ref (mapped, &gc_cycle) != 0) + if (__nscd_drop_map_ref (mapped, &gc_cycle) != 0 && retval != -1) { /* When we come here this means there has been a GC cycle while we were looking for the data. This means the data might have been inconsistent. Retry if possible. */ - if ((gc_cycle & 1) != 0 || ++nretries == 5 || retval == -1) + if ((gc_cycle & 1) != 0) { /* nscd is just running gc now. Disable using the mapping. */ - if (atomic_decrement_val (&mapped->counter) == 0) - __nscd_unmap (mapped); + __nscd_unmap (mapped); mapped = NO_MAPPING; } - if (retval != -1) - { - *result = NULL; - free (resultbuf); - goto retry; - } + *result = NULL; + free (resultbuf); + + goto retry; } return retval; diff --git a/nscd/nscd_getgr_r.c b/nscd/nscd_getgr_r.c index fc036f2888..922b906c19 100644 --- a/nscd/nscd_getgr_r.c +++ b/nscd/nscd_getgr_r.c @@ -1,5 +1,4 @@ -/* Copyright (C) 1998-2000, 2002-2005, 2006, 2007 - Free Software Foundation, Inc. +/* Copyright (C) 1998-2000, 2002-2005, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Thorsten Kukuk <kukuk@uni-paderborn.de>, 1998. @@ -89,7 +88,6 @@ nscd_getgr_r (const char *key, size_t keylen, request_type type, struct group **result) { int gc_cycle; - int nretries = 0; const uint32_t *len = NULL; size_t lensize = 0; @@ -99,59 +97,55 @@ nscd_getgr_r (const char *key, size_t keylen, request_type type, &__gr_map_handle, &gc_cycle); retry:; + const gr_response_header *gr_resp = NULL; const char *gr_name = NULL; size_t gr_name_len = 0; int retval = -1; const char *recend = (const char *) ~UINTMAX_C (0); - gr_response_header gr_resp; if (mapped != NO_MAPPING) { - struct datahead *found = __nscd_cache_search (type, key, keylen, mapped); + const struct datahead *found = __nscd_cache_search (type, key, keylen, + mapped); if (found != NULL) { - len = (const uint32_t *) (&found->data[0].grdata + 1); - gr_resp = found->data[0].grdata; + gr_resp = &found->data[0].grdata; + len = (const uint32_t *) (gr_resp + 1); + /* The alignment is always sufficient. */ + assert (((uintptr_t) len & (__alignof__ (*len) - 1)) == 0); gr_name = ((const char *) len - + gr_resp.gr_mem_cnt * sizeof (uint32_t)); - gr_name_len = gr_resp.gr_name_len + gr_resp.gr_passwd_len; + + gr_resp->gr_mem_cnt * sizeof (uint32_t)); + gr_name_len = gr_resp->gr_name_len + gr_resp->gr_passwd_len; recend = (const char *) found->data + found->recsize; - /* Now check if we can trust gr_resp fields. If GC is - in progress, it can contain anything. */ - if (mapped->head->gc_cycle != gc_cycle) - { - retval = -2; - goto out; - } - - /* The alignment is always sufficient, unless GC is in progress. */ - assert (((uintptr_t) len & (__alignof__ (*len) - 1)) == 0); } } + gr_response_header gr_resp_mem; int sock = -1; - if (gr_name == NULL) + if (gr_resp == NULL) { - sock = __nscd_open_socket (key, keylen, type, &gr_resp, - sizeof (gr_resp)); + sock = __nscd_open_socket (key, keylen, type, &gr_resp_mem, + sizeof (gr_resp_mem)); if (sock == -1) { __nss_not_use_nscd_group = 1; goto out; } + + gr_resp = &gr_resp_mem; } /* No value found so far. */ *result = NULL; - if (__builtin_expect (gr_resp.found == -1, 0)) + if (__builtin_expect (gr_resp->found == -1, 0)) { /* The daemon does not cache this database. */ __nss_not_use_nscd_group = 1; goto out_close; } - if (gr_resp.found == 1) + if (gr_resp->found == 1) { struct iovec vec[2]; char *p = buffer; @@ -163,8 +157,8 @@ nscd_getgr_r (const char *key, size_t keylen, request_type type, align the pointer. */ align = ((__alignof__ (char *) - (p - ((char *) 0))) & (__alignof__ (char *) - 1)); - total_len = (align + (1 + gr_resp.gr_mem_cnt) * sizeof (char *) - + gr_resp.gr_name_len + gr_resp.gr_passwd_len); + total_len = (align + (1 + gr_resp->gr_mem_cnt) * sizeof (char *) + + gr_resp->gr_name_len + gr_resp->gr_passwd_len); if (__builtin_expect (buflen < total_len, 0)) { no_room: @@ -176,16 +170,16 @@ nscd_getgr_r (const char *key, size_t keylen, request_type type, p += align; resultbuf->gr_mem = (char **) p; - p += (1 + gr_resp.gr_mem_cnt) * sizeof (char *); + p += (1 + gr_resp->gr_mem_cnt) * sizeof (char *); /* Set pointers for strings. */ resultbuf->gr_name = p; - p += gr_resp.gr_name_len; + p += gr_resp->gr_name_len; resultbuf->gr_passwd = p; - p += gr_resp.gr_passwd_len; + p += gr_resp->gr_passwd_len; /* Fill in what we know now. */ - resultbuf->gr_gid = gr_resp.gr_gid; + resultbuf->gr_gid = gr_resp->gr_gid; /* Read the length information, group name, and password. */ if (gr_name == NULL) @@ -193,17 +187,17 @@ nscd_getgr_r (const char *key, size_t keylen, request_type type, /* Allocate array to store lengths. */ if (lensize == 0) { - lensize = gr_resp.gr_mem_cnt * sizeof (uint32_t); + lensize = gr_resp->gr_mem_cnt * sizeof (uint32_t); len = (uint32_t *) alloca (lensize); } - else if (gr_resp.gr_mem_cnt * sizeof (uint32_t) > lensize) + else if (gr_resp->gr_mem_cnt * sizeof (uint32_t) > lensize) len = extend_alloca (len, lensize, - gr_resp.gr_mem_cnt * sizeof (uint32_t)); + gr_resp->gr_mem_cnt * sizeof (uint32_t)); vec[0].iov_base = (void *) len; - vec[0].iov_len = gr_resp.gr_mem_cnt * sizeof (uint32_t); + vec[0].iov_len = gr_resp->gr_mem_cnt * sizeof (uint32_t); vec[1].iov_base = resultbuf->gr_name; - vec[1].iov_len = gr_resp.gr_name_len + gr_resp.gr_passwd_len; + vec[1].iov_len = gr_resp->gr_name_len + gr_resp->gr_passwd_len; total_len = vec[0].iov_len + vec[1].iov_len; /* Get this data. */ @@ -215,14 +209,14 @@ nscd_getgr_r (const char *key, size_t keylen, request_type type, /* We already have the data. Just copy the group name and password. */ memcpy (resultbuf->gr_name, gr_name, - gr_resp.gr_name_len + gr_resp.gr_passwd_len); + gr_resp->gr_name_len + gr_resp->gr_passwd_len); /* Clear the terminating entry. */ - resultbuf->gr_mem[gr_resp.gr_mem_cnt] = NULL; + resultbuf->gr_mem[gr_resp->gr_mem_cnt] = NULL; /* Prepare reading the group members. */ total_len = 0; - for (cnt = 0; cnt < gr_resp.gr_mem_cnt; ++cnt) + for (cnt = 0; cnt < gr_resp->gr_mem_cnt; ++cnt) { resultbuf->gr_mem[cnt] = p; total_len += len[cnt]; @@ -230,25 +224,9 @@ nscd_getgr_r (const char *key, size_t keylen, request_type type, } if (__builtin_expect (gr_name + gr_name_len + total_len > recend, 0)) - { - /* len array might contain garbage during nscd GC cycle, - retry rather than fail in that case. */ - if (gr_name != NULL && mapped->head->gc_cycle != gc_cycle) - retval = -2; - goto out_close; - } + goto out_close; if (__builtin_expect (total_len > buflen, 0)) - { - /* len array might contain garbage during nscd GC cycle, - retry rather than fail in that case. */ - if (gr_name != NULL && mapped->head->gc_cycle != gc_cycle) - { - retval = -2; - goto out_close; - } - else - goto no_room; - } + goto no_room; retval = 0; if (gr_name == NULL) @@ -270,14 +248,14 @@ nscd_getgr_r (const char *key, size_t keylen, request_type type, /* Try to detect corrupt databases. */ if (resultbuf->gr_name[gr_name_len - 1] != '\0' - || resultbuf->gr_passwd[gr_resp.gr_passwd_len - 1] != '\0' - || ({for (cnt = 0; cnt < gr_resp.gr_mem_cnt; ++cnt) + || resultbuf->gr_passwd[gr_resp->gr_passwd_len - 1] != '\0' + || ({for (cnt = 0; cnt < gr_resp->gr_mem_cnt; ++cnt) if (resultbuf->gr_mem[cnt][len[cnt] - 1] != '\0') break; - cnt < gr_resp.gr_mem_cnt; })) + cnt < gr_resp->gr_mem_cnt; })) { /* We cannot use the database. */ - retval = mapped->head->gc_cycle != gc_cycle ? -2 : -1; + retval = -1; goto out_close; } @@ -296,21 +274,19 @@ nscd_getgr_r (const char *key, size_t keylen, request_type type, if (sock != -1) close_not_cancel_no_status (sock); out: - if (__nscd_drop_map_ref (mapped, &gc_cycle) != 0) + if (__nscd_drop_map_ref (mapped, &gc_cycle) != 0 && retval != -1) { /* When we come here this means there has been a GC cycle while we were looking for the data. This means the data might have been inconsistent. Retry if possible. */ - if ((gc_cycle & 1) != 0 || ++nretries == 5 || retval == -1) + if ((gc_cycle & 1) != 0) { /* nscd is just running gc now. Disable using the mapping. */ - if (atomic_decrement_val (&mapped->counter) == 0) - __nscd_unmap (mapped); + __nscd_unmap (mapped); mapped = NO_MAPPING; } - if (retval != -1) - goto retry; + goto retry; } return retval; diff --git a/nscd/nscd_gethst_r.c b/nscd/nscd_gethst_r.c index 90e1815bdd..516977bcc4 100644 --- a/nscd/nscd_gethst_r.c +++ b/nscd/nscd_gethst_r.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1998-2005, 2006, 2007 Free Software Foundation, Inc. +/* Copyright (C) 1998-2005, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998. @@ -118,6 +118,7 @@ nscd_gethst_r (const char *key, size_t keylen, request_type type, &gc_cycle); retry:; + const hst_response_header *hst_resp = NULL; const char *h_name = NULL; const uint32_t *aliases_len = NULL; const char *addr_list = NULL; @@ -125,27 +126,18 @@ nscd_gethst_r (const char *key, size_t keylen, request_type type, int retval = -1; const char *recend = (const char *) ~UINTMAX_C (0); int sock = -1; - hst_response_header hst_resp; if (mapped != NO_MAPPING) { - /* No const qualifier, as it can change during garbage collection. */ - struct datahead *found = __nscd_cache_search (type, key, keylen, mapped); + const struct datahead *found = __nscd_cache_search (type, key, keylen, + mapped); if (found != NULL) { - h_name = (char *) (&found->data[0].hs |
