diff options
| author | Ulrich Drepper <drepper@redhat.com> | 2007-01-14 05:26:04 +0000 |
|---|---|---|
| committer | Ulrich Drepper <drepper@redhat.com> | 2007-01-14 05:26:04 +0000 |
| commit | b21fa963c4194082792a26023f265ebe50ca5c9e (patch) | |
| tree | 78c2bb40d7a4fdb8b0b9c2c424fba511613e70e8 | |
| parent | 23691ab23b6e631ae0c5cf58455cca25a0058e22 (diff) | |
| download | glibc-b21fa963c4194082792a26023f265ebe50ca5c9e.tar.xz glibc-b21fa963c4194082792a26023f265ebe50ca5c9e.zip | |
* nis/nss_nis/nis-service.c (_nss_nis_getservbyname_r): Correct
computation of keylen.
| -rw-r--r-- | ChangeLog | 3 | ||||
| -rw-r--r-- | NEWS | 4 | ||||
| -rw-r--r-- | inet/Makefile | 4 | ||||
| -rw-r--r-- | nis/nss_nis/nis-service.c | 2 | ||||
| -rw-r--r-- | nscd/Makefile | 9 | ||||
| -rw-r--r-- | nscd/cache.c | 70 | ||||
| -rw-r--r-- | nscd/connections.c | 72 | ||||
| -rw-r--r-- | nscd/gai.c | 3 | ||||
| -rw-r--r-- | nscd/getsrvbynm_r.c | 27 | ||||
| -rw-r--r-- | nscd/getsrvbypt_r.c | 27 | ||||
| -rw-r--r-- | nscd/grpcache.c | 18 | ||||
| -rw-r--r-- | nscd/hstcache.c | 18 | ||||
| -rw-r--r-- | nscd/nscd-client.h | 20 | ||||
| -rw-r--r-- | nscd/nscd.c | 14 | ||||
| -rw-r--r-- | nscd/nscd.conf | 11 | ||||
| -rw-r--r-- | nscd/nscd.h | 22 | ||||
| -rw-r--r-- | nscd/nscd_conf.c | 9 | ||||
| -rw-r--r-- | nscd/nscd_getserv_r.c | 306 | ||||
| -rw-r--r-- | nscd/nscd_proto.h | 10 | ||||
| -rw-r--r-- | nscd/pwdcache.c | 18 | ||||
| -rw-r--r-- | nscd/selinux.c | 9 | ||||
| -rw-r--r-- | nscd/servicescache.c | 473 | ||||
| -rw-r--r-- | nss/Versions | 2 | ||||
| -rw-r--r-- | nss/nsswitch.c | 4 |
24 files changed, 1012 insertions, 143 deletions
@@ -1,5 +1,8 @@ 2007-01-13 Ulrich Drepper <drepper@redhat.com> + * nis/nss_nis/nis-service.c (_nss_nis_getservbyname_r): Correct + computation of keylen. + * include/string.h: Only redefine strndupa if this is really for libc code. @@ -1,4 +1,4 @@ -GNU C Library NEWS -- history of user-visible changes. 2006-10-11 +GNU C Library NEWS -- history of user-visible changes. 2007-1-13 Copyright (C) 1992-2002,2003,2004,2005,2006 Free Software Foundation, Inc. See the end for copying conditions. @@ -9,6 +9,8 @@ Version 2.6 * New Linux interfaces: epoll_pwait. +* nscd can now cache the services database. Implemented by Ulrich Drepper. + Version 2.5 diff --git a/inet/Makefile b/inet/Makefile index 075716fbeb..ad90b06199 100644 --- a/inet/Makefile +++ b/inet/Makefile @@ -1,4 +1,4 @@ -# Copyright (C) 1991-2002, 2003, 2004, 2006 Free Software Foundation, Inc. +# Copyright (C) 1991-2006, 2007 Free Software Foundation, Inc. # This file is part of the GNU C Library. # The GNU C Library is free software; you can redistribute it and/or @@ -79,6 +79,8 @@ CFLAGS-getrpcent_r.c = -fexceptions CFLAGS-getrpcent.c = -fexceptions CFLAGS-getservent_r.c = -fexceptions CFLAGS-getservent.c = -fexceptions +CFLAGS-getsrvbynm_r.c = -DUSE_NSCD=1 +CFLAGS-getsrvbypt_r.c = -DUSE_NSCD=1 CFLAGS-getprtent_r.c = -fexceptions CFLAGS-getprtent.c = -fexceptions CFLAGS-either_ntoh.c = -fexceptions diff --git a/nis/nss_nis/nis-service.c b/nis/nss_nis/nis-service.c index 0c176095c8..59a598f296 100644 --- a/nis/nss_nis/nis-service.c +++ b/nis/nss_nis/nis-service.c @@ -271,7 +271,7 @@ _nss_nis_getservbyname_r (const char *name, const char *protocol, /* If the protocol is given, we could try if our NIS server knows about services.byservicename map. If yes, we only need one query. */ - size_t keylen = strlen (name) + 1 + (protocol ? strlen (protocol) : 0); + size_t keylen = strlen (name) + (protocol ? 1 + strlen (protocol) : 0); char key[keylen + 1]; /* key is: "name/proto" */ diff --git a/nscd/Makefile b/nscd/Makefile index 21657abeb7..ef3ce184f9 100644 --- a/nscd/Makefile +++ b/nscd/Makefile @@ -1,4 +1,4 @@ -# Copyright (C) 1998,2000,2002,2003,2004,2005,2006 +# Copyright (C) 1998,2000,2002,2003,2004,2005,2006,2007 # Free Software Foundation, Inc. # This file is part of the GNU C Library. @@ -22,7 +22,8 @@ # subdir := nscd -routines := nscd_getpw_r nscd_getgr_r nscd_gethst_r nscd_getai nscd_initgroups +routines := nscd_getpw_r nscd_getgr_r nscd_gethst_r nscd_getai \ + nscd_initgroups nscd_getserv_r aux := nscd_helper include ../Makeconfig @@ -32,6 +33,7 @@ vpath %.c ../locale/programs nscd-modules := nscd connections pwdcache getpwnam_r getpwuid_r grpcache \ getgrnam_r getgrgid_r hstcache gethstbyad_r gethstbynm2_r \ + getsrvbynm_r getsrvbypt_r servicescache \ dbg_log nscd_conf nscd_stat cache mem nscd_setup_thread \ xmalloc xstrdup aicache initgrcache gai @@ -117,6 +119,9 @@ CFLAGS-aicache.c += $(nscd-cflags) CFLAGS-selinux.c += $(nscd-cflags) CFLAGS-initgrcache.c += $(nscd-cflags) CFLAGS-gai.c += $(nscd-cflags) +CFLAGS-servicescache.c += $(nscd-cflags) +CFLAGS-getsrvbynm_r.c += $(nscd-cflags) +CFLAGS-getsrvbypt_r.c += $(nscd-cflags) ifeq (yesyes,$(have-fpie)$(build-shared)) relro-LDFLAGS += -Wl,-z,now diff --git a/nscd/cache.c b/nscd/cache.c index ef986f374a..e63a4f87df 100644 --- a/nscd/cache.c +++ b/nscd/cache.c @@ -1,4 +1,4 @@ -/* Copyright (c) 1998, 1999, 2003-2005, 2006 Free Software Foundation, Inc. +/* Copyright (c) 1998, 1999, 2003-2006, 2007 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998. @@ -40,6 +40,25 @@ unsigned int reload_count = DEFAULT_RELOAD_LIMIT; +static void (*const readdfcts[LASTREQ]) (struct database_dyn *, + struct hashentry *, + struct datahead *) = +{ + [GETPWBYNAME] = readdpwbyname, + [GETPWBYUID] = readdpwbyuid, + [GETGRBYNAME] = readdgrbyname, + [GETGRBYGID] = readdgrbygid, + [GETHOSTBYNAME] = readdhstbyname, + [GETHOSTBYNAMEv6] = readdhstbynamev6, + [GETHOSTBYADDR] = readdhstbyaddr, + [GETHOSTBYADDRv6] = readdhstbyaddrv6, + [GETAI] = readdhstai, + [INITGROUPS] = readdinitgroups, + [GETSERVBYNAME] = readdservbyname, + [GETSERVBYPORT] = readdservbyport +}; + + /* Search the cache for a matching entry and return it when found. If this fails search the negative cache and return (void *) -1 if this search was successful. Otherwise return NULL. @@ -328,51 +347,10 @@ prune_cache (struct database_dyn *table, time_t now, int fd) /* Reload the value. We do this only for the initially used key, not the additionally added derived value. */ - switch (runp->type) - { - case GETPWBYNAME: - readdpwbyname (table, runp, dh); - break; - - case GETPWBYUID: - readdpwbyuid (table, runp, dh); - break; - - case GETGRBYNAME: - readdgrbyname (table, runp, dh); - break; - - case GETGRBYGID: - readdgrbygid (table, runp, dh); - break; - - case GETHOSTBYNAME: - readdhstbyname (table, runp, dh); - break; - - case GETHOSTBYNAMEv6: - readdhstbynamev6 (table, runp, dh); - break; - - case GETHOSTBYADDR: - readdhstbyaddr (table, runp, dh); - break; - - case GETHOSTBYADDRv6: - readdhstbyaddrv6 (table, runp, dh); - break; - - case GETAI: - readdhstai (table, runp, dh); - break; - - case INITGROUPS: - readdinitgroups (table, runp, dh); - break; - - default: - assert (! "should never happen"); - } + assert (runp->type < LASTREQ + && readdfcts[runp->type] != NULL); + + readdfcts[runp->type] (table, runp, dh); /* If the entry has been replaced, we might need cleanup. */ diff --git a/nscd/connections.c b/nscd/connections.c index f012b69ed8..a5e758e071 100644 --- a/nscd/connections.c +++ b/nscd/connections.c @@ -75,7 +75,7 @@ static void begin_drop_privileges (void); static void finish_drop_privileges (void); /* Map request type to a string. */ -const char *serv2str[LASTREQ] = +const char *const serv2str[LASTREQ] = { [GETPWBYNAME] = "GETPWBYNAME", [GETPWBYUID] = "GETPWBYUID", @@ -92,7 +92,10 @@ const char *serv2str[LASTREQ] = [GETFDGR] = "GETFDGR", [GETFDHST] = "GETFDHST", [GETAI] = "GETAI", - [INITGROUPS] = "INITGROUPS" + [INITGROUPS] = "INITGROUPS", + [GETSERVBYNAME] = "GETSERVBYNAME", + [GETSERVBYPORT] = "GETSERVBYPORT", + [GETFDSERV] = "GETFDSERV" }; /* The control data structures for the services. */ @@ -107,6 +110,7 @@ struct database_dyn dbs[lastdb] = .propagate = 1, .shared = 0, .max_db_size = DEFAULT_MAX_DB_SIZE, + .reset_res = 0, .filename = "/etc/passwd", .db_filename = _PATH_NSCD_PASSWD_DB, .disabled_iov = &pwd_iov_disabled, @@ -125,6 +129,7 @@ struct database_dyn dbs[lastdb] = .propagate = 1, .shared = 0, .max_db_size = DEFAULT_MAX_DB_SIZE, + .reset_res = 0, .filename = "/etc/group", .db_filename = _PATH_NSCD_GROUP_DB, .disabled_iov = &grp_iov_disabled, @@ -143,6 +148,7 @@ struct database_dyn dbs[lastdb] = .propagate = 0, /* Not used. */ .shared = 0, .max_db_size = DEFAULT_MAX_DB_SIZE, + .reset_res = 1, .filename = "/etc/hosts", .db_filename = _PATH_NSCD_HOSTS_DB, .disabled_iov = &hst_iov_disabled, @@ -151,6 +157,25 @@ struct database_dyn dbs[lastdb] = .wr_fd = -1, .ro_fd = -1, .mmap_used = false + }, + [servdb] = { + .lock = PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP, + .prunelock = PTHREAD_MUTEX_INITIALIZER, + .enabled = 0, + .check_file = 1, + .persistent = 0, + .propagate = 0, /* Not used. */ + .shared = 0, + .max_db_size = DEFAULT_MAX_DB_SIZE, + .reset_res = 0, + .filename = "/etc/services", + .db_filename = _PATH_NSCD_SERVICES_DB, + .disabled_iov = &serv_iov_disabled, + .postimeout = 28800, + .negtimeout = 20, + .wr_fd = -1, + .ro_fd = -1, + .mmap_used = false } }; @@ -170,7 +195,10 @@ static struct database_dyn *const serv2db[LASTREQ] = [GETFDGR] = &dbs[grpdb], [GETFDHST] = &dbs[hstdb], [GETAI] = &dbs[hstdb], - [INITGROUPS] = &dbs[grpdb] + [INITGROUPS] = &dbs[grpdb], + [GETSERVBYNAME] = &dbs[servdb], + [GETSERVBYPORT] = &dbs[servdb], + [GETFDSERV] = &dbs[servdb] }; @@ -305,7 +333,7 @@ check_use (const char *data, nscd_ssize_t first_free, uint8_t *usemap, static int verify_persistent_db (void *mem, struct database_pers_head *readhead, int dbnr) { - assert (dbnr == pwddb || dbnr == grpdb || dbnr == hstdb); + assert (dbnr == pwddb || dbnr == grpdb || dbnr == hstdb || dbnr == servdb); time_t now = time (NULL); @@ -821,18 +849,16 @@ invalidate_cache (char *key, int fd) dbtype number; int32_t resp; - if (strcmp (key, "passwd") == 0) - number = pwddb; - else if (strcmp (key, "group") == 0) - number = grpdb; - else if (__builtin_expect (strcmp (key, "hosts"), 0) == 0) - { - number = hstdb; + for (number = pwddb; number < lastdb; ++number) + if (strcmp (key, dbnames[number]) == 0) + { + if (dbs[number].reset_res) + res_init (); - /* Re-initialize the resolver. resolv.conf might have changed. */ - res_init (); - } - else + break; + } + + if (number == lastdb) { resp = EINVAL; writeall (fd, &resp, sizeof (resp)); @@ -922,8 +948,9 @@ cannot handle old request version %d; current version is %d"), // XXX Clean up so that each new command need not introduce a // XXX new conditional. if ((__builtin_expect (req->type, GETPWBYNAME) >= GETPWBYNAME - && __builtin_expect (req->type, LASTDBREQ) <= LASTDBREQ) - || req->type == GETAI || req->type == INITGROUPS) + && __builtin_expect (req->type, GETHOSTBYADDRv6) <= GETHOSTBYADDRv6) + || req->type == GETAI || req->type == INITGROUPS + || req->type == GETSERVBYNAME || req->type == GETSERVBYPORT) { if (__builtin_expect (debug_level, 0) > 0) { @@ -1067,6 +1094,14 @@ cannot handle old request version %d; current version is %d"), addinitgroups (db, fd, req, key, uid); break; + case GETSERVBYNAME: + addservbyname (db, fd, req, key, uid); + break; + + case GETSERVBYPORT: + addservbyport (db, fd, req, key, uid); + break; + case GETSTAT: case SHUTDOWN: case INVALIDATE: @@ -1112,6 +1147,7 @@ cannot handle old request version %d; current version is %d"), case GETFDPW: case GETFDGR: case GETFDHST: + case GETFDSERV: #ifdef SCM_RIGHTS send_ro_fd (serv2db[req->type], key, fd); #endif @@ -1153,7 +1189,7 @@ cannot open /proc/self/cmdline: %s; disabling paranoia mode"), if (n == -1) { dbg_log (_("\ -cannot open /proc/self/cmdline: %s; disabling paranoia mode"), +cannot read /proc/self/cmdline: %s; disabling paranoia mode"), strerror (errno)); close (fd); diff --git a/nscd/gai.c b/nscd/gai.c index 2e706bdfe7..46f8b8bec9 100644 --- a/nscd/gai.c +++ b/nscd/gai.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. +/* Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 2004. @@ -17,7 +17,6 @@ /* 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 #define __inet_aton inet_aton #define __getsockname getsockname #define __socket socket diff --git a/nscd/getsrvbynm_r.c b/nscd/getsrvbynm_r.c new file mode 100644 index 0000000000..fb60f4802d --- /dev/null +++ b/nscd/getsrvbynm_r.c @@ -0,0 +1,27 @@ +/* Copyright (C) 1996, 1997, 2002, 2007 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License version 2 as + published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +#include <netdb.h> + + +#define LOOKUP_TYPE struct servent +#define FUNCTION_NAME getservbyname +#define DATABASE_NAME services +#define ADD_PARAMS const char *name, const char *proto +#define ADD_VARIABLES name, proto + +#include "../nss/getXXbyYY_r.c" diff --git a/nscd/getsrvbypt_r.c b/nscd/getsrvbypt_r.c new file mode 100644 index 0000000000..fd5b11bc3d --- /dev/null +++ b/nscd/getsrvbypt_r.c @@ -0,0 +1,27 @@ +/* Copyright (C) 1996, 1997, 2002, 2007 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License version 2 as + published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +#include <netdb.h> + + +#define LOOKUP_TYPE struct servent +#define FUNCTION_NAME getservbyport +#define DATABASE_NAME services +#define ADD_PARAMS int port, const char *proto +#define ADD_VARIABLES port, proto + +#include "../nss/getXXbyYY_r.c" diff --git a/nscd/grpcache.c b/nscd/grpcache.c index 5a8fba4759..54d1ef1eef 100644 --- a/nscd/grpcache.c +++ b/nscd/grpcache.c @@ -1,5 +1,5 @@ /* Cache handling for group lookup. - Copyright (C) 1998-2005, 2006 Free Software Foundation, Inc. + Copyright (C) 1998-2005, 2006, 2007 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998. @@ -445,23 +445,14 @@ addgrbyX (struct database_dyn *db, int fd, request_header *req, dbg_log (_("Reloading \"%s\" in group cache!"), keystr); } -#if 0 - uid_t oldeuid = 0; - if (db->secure) - { - oldeuid = geteuid (); - pthread_seteuid_np (uid); - } -#endif - while (lookup (req->type, key, &resultbuf, buffer, buflen, &grp) != 0 && (errval = errno) == ERANGE) { - char *old_buffer = buffer; errno = 0; if (__builtin_expect (buflen > 32768, 0)) { + char *old_buffer = buffer; buflen *= 2; buffer = (char *) realloc (use_malloc ? buffer : NULL, buflen); if (buffer == NULL) @@ -486,11 +477,6 @@ addgrbyX (struct database_dyn *db, int fd, request_header *req, buffer = (char *) extend_alloca (buffer, buflen, 2 * buflen); } -#if 0 - if (db->secure) - pthread_seteuid_np (oldeuid); -#endif - cache_addgr (db, fd, req, keystr, grp, uid, he, dh, errval); if (use_malloc) diff --git a/nscd/hstcache.c b/nscd/hstcache.c index e27ece5bc6..742491aea3 100644 --- a/nscd/hstcache.c +++ b/nscd/hstcache.c @@ -1,5 +1,5 @@ /* Cache handling for host lookup. - Copyright (C) 1998-2005, 2006 Free Software Foundation, Inc. + Copyright (C) 1998-2005, 2006, 2007 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998. @@ -463,24 +463,15 @@ addhstbyX (struct database_dyn *db, int fd, request_header *req, dbg_log (_("Reloading \"%s\" in hosts cache!"), (char *) str); } -#if 0 - uid_t oldeuid = 0; - if (db->secure) - { - oldeuid = geteuid (); - pthread_seteuid_np (uid); - } -#endif - while (lookup (req->type, key, &resultbuf, buffer, buflen, &hst) != 0 && h_errno == NETDB_INTERNAL && (errval = errno) == ERANGE) { - char *old_buffer = buffer; errno = 0; if (__builtin_expect (buflen > 32768, 0)) { + char *old_buffer = buffer; buflen *= 2; buffer = (char *) realloc (use_malloc ? buffer : NULL, buflen); if (buffer == NULL) @@ -505,11 +496,6 @@ addhstbyX (struct database_dyn *db, int fd, request_header *req, buffer = (char *) extend_alloca (buffer, buflen, 2 * buflen); } -#if 0 - if (db->secure) - pthread_seteuid_np (oldeuid); -#endif - |
