diff options
author | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2016-08-20 19:50:45 +0200 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2016-08-20 19:50:45 +0200 |
commit | 4dd9e35bfd35d3138bc44169baba098005bad51e (patch) | |
tree | a4939c43a9c3fe00eb27f023e14acc5e1fe8808c /nss | |
parent | bd42a4599d1b6f77bcfe1e4f67b7cbd9e1cb2dfd (diff) | |
parent | f76453c31593957fec1a99b986bfa5506618b79c (diff) |
Merge commit 'refs/top-bases/t/bigmem' into t/bigmem
Diffstat (limited to 'nss')
58 files changed, 313 insertions, 328 deletions
diff --git a/nss/Makefile b/nss/Makefile index c8880c061c..65ab7b5419 100644 --- a/nss/Makefile +++ b/nss/Makefile @@ -1,4 +1,4 @@ -# Copyright (C) 1996-2014 Free Software Foundation, Inc. +# Copyright (C) 1996-2015 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 @@ -20,6 +20,8 @@ # subdir := nss +include ../Makeconfig + headers := nss.h # This is the trivial part which goes into libc itself. @@ -29,19 +31,25 @@ routines = nsswitch getnssent getnssent_r digits_dots \ # These are the databases that go through nss dispatch. # Caution: if you add a database here, you must add its real name # in databases.def, too. -databases = proto service hosts network grp pwd rpc ethers \ - spwd netgrp key alias sgrp +databases = proto service hosts network grp pwd ethers \ + spwd netgrp alias sgrp + +ifneq (,$(filter sunrpc,$(subdirs))) +databases += key rpc +have-sunrpc := 1 +else +have-sunrpc := 0 +endif +CPPFLAGS-getent.c = -DHAVE_SUNRPC=$(have-sunrpc) others := getent makedb install-bin := getent makedb makedb-modules = xmalloc hash-string extra-objs += $(makedb-modules:=.o) -tests = test-netdb tst-nss-test1 test-digits-dots +tests = test-netdb tst-nss-test1 test-digits-dots tst-nss-getpwent xtests = bug-erange -include ../Makeconfig - # Specify rules for the nss_* modules. We have some services. services := files db @@ -105,7 +113,7 @@ $(objpfx)makedb: $(makedb-modules:%=$(objpfx)%.o) $(inst_vardbdir)/Makefile: db-Makefile $(+force) $(do-install) -CFLAGS-nss_test1.c = -DNOT_IN_libc=1 +libof-nss_test1 = extramodules $(objpfx)/libnss_test1.so: $(objpfx)nss_test1.os $(link-libc-deps) $(build-module) ifdef libnss_test1.so-version diff --git a/nss/XXX-lookup.c b/nss/XXX-lookup.c index 83ba6cf896..ba8bad11c1 100644 --- a/nss/XXX-lookup.c +++ b/nss/XXX-lookup.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996-2014 Free Software Foundation, Inc. +/* Copyright (C) 1996-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. diff --git a/nss/alias-lookup.c b/nss/alias-lookup.c index c771858309..1153a4534a 100644 --- a/nss/alias-lookup.c +++ b/nss/alias-lookup.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996-2014 Free Software Foundation, Inc. +/* Copyright (C) 1996-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. diff --git a/nss/databases.def b/nss/databases.def index 0d01581ddd..1ff1a1b157 100644 --- a/nss/databases.def +++ b/nss/databases.def @@ -1,5 +1,5 @@ /* List of all databases defined for the NSS in GNU C Library. - Copyright (C) 1996-2014 Free Software Foundation, Inc. + Copyright (C) 1996-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. diff --git a/nss/db-Makefile b/nss/db-Makefile index d0009d0fac..fc62344d60 100644 --- a/nss/db-Makefile +++ b/nss/db-Makefile @@ -1,5 +1,5 @@ # Makefile to (re-)generate db versions of system database files. -# Copyright (C) 1996-2014 Free Software Foundation, Inc. +# Copyright (C) 1996-2015 Free Software Foundation, Inc. # This file is part of the GNU C Library. # Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. # diff --git a/nss/digits_dots.c b/nss/digits_dots.c index 0c12bf1f3d..d4453e4f93 100644 --- a/nss/digits_dots.c +++ b/nss/digits_dots.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1997-2014 Free Software Foundation, Inc. +/* Copyright (C) 1997-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by H.J. Lu <hjl@gnu.ai.mit.edu>, 1997. diff --git a/nss/ethers-lookup.c b/nss/ethers-lookup.c index 46bd76d879..7faaaae6ab 100644 --- a/nss/ethers-lookup.c +++ b/nss/ethers-lookup.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996-2014 Free Software Foundation, Inc. +/* Copyright (C) 1996-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. diff --git a/nss/function.def b/nss/function.def index 4dfea8555d..e5869e3365 100644 --- a/nss/function.def +++ b/nss/function.def @@ -1,5 +1,5 @@ /* List of functions defined for static NSS in GNU C Library. - Copyright (C) 1996-2014 Free Software Foundation, Inc. + Copyright (C) 1996-2015 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 diff --git a/nss/getXXbyYY.c b/nss/getXXbyYY.c index c9c64156aa..15fecf8491 100644 --- a/nss/getXXbyYY.c +++ b/nss/getXXbyYY.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996-2014 Free Software Foundation, Inc. +/* Copyright (C) 1996-2015 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 diff --git a/nss/getXXbyYY_r.c b/nss/getXXbyYY_r.c index edb74db029..198f8cfebd 100644 --- a/nss/getXXbyYY_r.c +++ b/nss/getXXbyYY_r.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996-2014 Free Software Foundation, Inc. +/* Copyright (C) 1996-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. diff --git a/nss/getXXent.c b/nss/getXXent.c index 609650e272..e1c796da01 100644 --- a/nss/getXXent.c +++ b/nss/getXXent.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996-2014 Free Software Foundation, Inc. +/* Copyright (C) 1996-2015 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 diff --git a/nss/getXXent_r.c b/nss/getXXent_r.c index 89acb09031..16334581c2 100644 --- a/nss/getXXent_r.c +++ b/nss/getXXent_r.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996-2014 Free Software Foundation, Inc. +/* Copyright (C) 1996-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. diff --git a/nss/getent.c b/nss/getent.c index 1209f8e7cd..34df8487a9 100644 --- a/nss/getent.c +++ b/nss/getent.c @@ -1,4 +1,4 @@ -/* Copyright (c) 1998-2014 Free Software Foundation, Inc. +/* Copyright (c) 1998-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998. @@ -87,7 +87,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\ -"), "2014"); +"), "2015"); fprintf (stream, gettext ("Written by %s.\n"), "Thorsten Kukuk"); } @@ -700,6 +700,7 @@ protocols_keys (int number, char *key[]) return result; } +#if HAVE_SUNRPC /* Now is all for rpc */ static void print_rpc (struct rpcent *rpc) @@ -745,6 +746,7 @@ rpc_keys (int number, char *key[]) return result; } +#endif /* for services */ static void @@ -884,7 +886,9 @@ D(netgroup) D(networks) D(passwd) D(protocols) +#if HAVE_SUNRPC D(rpc) +#endif D(services) D(shadow) #undef D diff --git a/nss/getnssent.c b/nss/getnssent.c index ef05ccfbb5..594505bf95 100644 --- a/nss/getnssent.c +++ b/nss/getnssent.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2014 Free Software Foundation, Inc. +/* Copyright (C) 2000-2015 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 diff --git a/nss/getnssent_r.c b/nss/getnssent_r.c index 31d4c91139..f5b903671c 100644 --- a/nss/getnssent_r.c +++ b/nss/getnssent_r.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2014 Free Software Foundation, Inc. +/* Copyright (C) 2000-2015 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 diff --git a/nss/grp-lookup.c b/nss/grp-lookup.c index 0509194062..22a364bb1f 100644 --- a/nss/grp-lookup.c +++ b/nss/grp-lookup.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996-2014 Free Software Foundation, Inc. +/* Copyright (C) 1996-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. diff --git a/nss/hosts-lookup.c b/nss/hosts-lookup.c index 2301242095..905b128d76 100644 --- a/nss/hosts-lookup.c +++ b/nss/hosts-lookup.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996-2014 Free Software Foundation, Inc. +/* Copyright (C) 1996-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. diff --git a/nss/key-lookup.c b/nss/key-lookup.c index 1625ab8a49..eab6a80c4d 100644 --- a/nss/key-lookup.c +++ b/nss/key-lookup.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996-2014 Free Software Foundation, Inc. +/* Copyright (C) 1996-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. diff --git a/nss/makedb.c b/nss/makedb.c index 7c1a766bdf..c7b466ab43 100644 --- a/nss/makedb.c +++ b/nss/makedb.c @@ -1,5 +1,5 @@ /* Create simple DB database from textual input. - Copyright (C) 1996-2014 Free Software Foundation, Inc. + Copyright (C) 1996-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. @@ -386,7 +386,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\ -"), "2014"); +"), "2015"); fprintf (stream, gettext ("Written by %s.\n"), "Ulrich Drepper"); } diff --git a/nss/netgrp-lookup.c b/nss/netgrp-lookup.c index b7937fdb8f..286f507200 100644 --- a/nss/netgrp-lookup.c +++ b/nss/netgrp-lookup.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996-2014 Free Software Foundation, Inc. +/* Copyright (C) 1996-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. diff --git a/nss/network-lookup.c b/nss/network-lookup.c index 80004c7f8e..fef6a9f849 100644 --- a/nss/network-lookup.c +++ b/nss/network-lookup.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996-2014 Free Software Foundation, Inc. +/* Copyright (C) 1996-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. @@ -1,4 +1,4 @@ -/* Copyright (C) 1996-2014 Free Software Foundation, Inc. +/* Copyright (C) 1996-2015 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 diff --git a/nss/nss_db/db-XXX.c b/nss/nss_db/db-XXX.c index 89b1a126c2..4a0766ab52 100644 --- a/nss/nss_db/db-XXX.c +++ b/nss/nss_db/db-XXX.c @@ -1,5 +1,5 @@ /* Common code for DB-based databases in nss_db module. - Copyright (C) 1996-2014 Free Software Foundation, Inc. + Copyright (C) 1996-2015 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 @@ -191,6 +191,12 @@ enum nss_status \ char *p = memcpy (buffer, valstr, len); \ \ int err = parse_line (p, result, data, buflen, errnop EXTRA_ARGS); \ + \ + /* Advance before break_if_match, lest it uses continue to skip + to the next entry. */ \ + if ((hidx += hval2) >= header->dbs[i].hashsize) \ + hidx -= header->dbs[i].hashsize; \ + \ if (err > 0) \ { \ status = NSS_STATUS_SUCCESS; \ @@ -203,9 +209,6 @@ enum nss_status \ status = NSS_STATUS_TRYAGAIN; \ break; \ } \ - \ - if ((hidx += hval2) >= header->dbs[i].hashsize) \ - hidx -= header->dbs[i].hashsize; \ } \ \ if (status == NSS_STATUS_NOTFOUND) \ diff --git a/nss/nss_db/db-init.c b/nss/nss_db/db-init.c index 521c452665..099d89b1f8 100644 --- a/nss/nss_db/db-init.c +++ b/nss/nss_db/db-init.c @@ -1,5 +1,5 @@ /* Initialization in nss_db module. - Copyright (C) 2011-2014 Free Software Foundation, Inc. + Copyright (C) 2011-2015 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 @@ -22,35 +22,25 @@ #include <nscd/nscd.h> #include <string.h> -static union -{ - struct traced_file file; - char buf[sizeof (struct traced_file) + sizeof (_PATH_VARDB "passwd.db")]; -} pwd_traced_file; - -static union -{ - struct traced_file file; - char buf[sizeof (struct traced_file) + sizeof (_PATH_VARDB "group.db")]; -} grp_traced_file; +#define PWD_FILENAME (_PATH_VARDB "passwd.db") +define_traced_file (pwd, PWD_FILENAME); -static union -{ - struct traced_file file; - char buf[sizeof (struct traced_file) + sizeof (_PATH_VARDB "services.db")]; -} serv_traced_file; +#define GRP_FILENAME (_PATH_VARDB "group.db") +define_traced_file (grp, GRP_FILENAME); +#define SERV_FILENAME (_PATH_VARDB "services.db") +define_traced_file (serv, SERV_FILENAME); void _nss_db_init (void (*cb) (size_t, struct traced_file *)) { - strcpy (pwd_traced_file.file.fname,_PATH_VARDB "passwd.db"); + init_traced_file (&pwd_traced_file.file, PWD_FILENAME, 0); cb (pwddb, &pwd_traced_file.file); - strcpy (grp_traced_file.file.fname, _PATH_VARDB "group.db"); + init_traced_file (&grp_traced_file.file, GRP_FILENAME, 0); cb (grpdb, &grp_traced_file.file); - strcpy (serv_traced_file.file.fname, _PATH_VARDB "services.db"); + init_traced_file (&serv_traced_file.file, SERV_FILENAME, 0); cb (servdb, &serv_traced_file.file); } diff --git a/nss/nss_db/db-initgroups.c b/nss/nss_db/db-initgroups.c index fb130f9dd6..d182fc4f42 100644 --- a/nss/nss_db/db-initgroups.c +++ b/nss/nss_db/db-initgroups.c @@ -1,5 +1,5 @@ /* Initgroups handling in nss_db module. - Copyright (C) 2011-2014 Free Software Foundation, Inc. + Copyright (C) 2011-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@gmail.com>. diff --git a/nss/nss_db/db-netgrp.c b/nss/nss_db/db-netgrp.c index 8c8fbd8180..94d6adac68 100644 --- a/nss/nss_db/db-netgrp.c +++ b/nss/nss_db/db-netgrp.c @@ -1,5 +1,5 @@ /* Netgroup file parser in nss_db modules. - Copyright (C) 1996-2014 Free Software Foundation, Inc. + Copyright (C) 1996-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. diff --git a/nss/nss_db/db-open.c b/nss/nss_db/db-open.c index ea867a7a7f..c482232b3c 100644 --- a/nss/nss_db/db-open.c +++ b/nss/nss_db/db-open.c @@ -1,5 +1,5 @@ /* Common database routines for nss_db. - Copyright (C) 2000-2014 Free Software Foundation, Inc. + Copyright (C) 2000-2015 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 @@ -25,7 +25,6 @@ #include <sys/mman.h> #include <not-cancel.h> -#include <kernel-features.h> #include "nss_db.h" /* Open the database stored in FILE. If succesful, store either a diff --git a/nss/nss_db/nss_db.h b/nss/nss_db/nss_db.h index 5c6b46b47c..4af2229ac1 100644 --- a/nss/nss_db/nss_db.h +++ b/nss/nss_db/nss_db.h @@ -1,5 +1,5 @@ /* Common database open/close routines for nss_db. - Copyright (C) 1999-2014 Free Software Foundation, Inc. + Copyright (C) 1999-2015 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 diff --git a/nss/nss_files/files-XXX.c b/nss/nss_files/files-XXX.c index 36242f9d44..f002f431e5 100644 --- a/nss/nss_files/files-XXX.c +++ b/nss/nss_files/files-XXX.c @@ -1,5 +1,5 @@ /* Common code for file-based databases in nss_files module. - Copyright (C) 1996-2014 Free Software Foundation, Inc. + Copyright (C) 1996-2015 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 @@ -60,24 +60,23 @@ /* Locks the static variables in this file. */ __libc_lock_define_initialized (static, lock) -/* Maintenance of the shared stream open on the database file. */ +/* Maintenance of the stream open on the database file. For getXXent + operations the stream needs to be held open across calls, the other + getXXbyYY operations all use their own stream. */ static FILE *stream; -static fpos_t position; -static enum { nouse, getent, getby } last_use; -static int keep_stream; /* Open database file if not already opened. */ static enum nss_status -internal_setent (int stayopen) +internal_setent (FILE **stream) { enum nss_status status = NSS_STATUS_SUCCESS; - if (stream == NULL) + if (*stream == NULL) { - stream = fopen (DATAFILE, "rce"); + *stream = fopen (DATAFILE, "rce"); - if (stream == NULL) + if (*stream == NULL) status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL; else { @@ -90,7 +89,7 @@ internal_setent (int stayopen) int result; int flags; - result = flags = fcntl (fileno (stream), F_GETFD, 0); + result = flags = fcntl (fileno (*stream), F_GETFD, 0); if (result >= 0) { # ifdef O_CLOEXEC @@ -100,15 +99,15 @@ internal_setent (int stayopen) # endif { flags |= FD_CLOEXEC; - result = fcntl (fileno (stream), F_SETFD, flags); + result = fcntl (fileno (*stream), F_SETFD, flags); } } if (result < 0) { /* Something went wrong. Close the stream and return a failure. */ - fclose (stream); - stream = NULL; + fclose (*stream); + *stream = NULL; status = NSS_STATUS_UNAVAIL; } } @@ -116,11 +115,7 @@ internal_setent (int stayopen) } } else - rewind (stream); - - /* Remember STAYOPEN flag. */ - if (stream != NULL) - keep_stream |= stayopen; + rewind (*stream); return status; } @@ -134,16 +129,7 @@ CONCAT(_nss_files_set,ENTNAME) (int stayopen) __libc_lock_lock (lock); - status = internal_setent (stayopen); - - if (status == NSS_STATUS_SUCCESS && fgetpos (stream, &position) < 0) - { - fclose (stream); - stream = NULL; - status = NSS_STATUS_UNAVAIL; - } - - last_use = getent; + status = internal_setent (&stream); __libc_lock_unlock (lock); @@ -153,12 +139,12 @@ CONCAT(_nss_files_set,ENTNAME) (int stayopen) /* Close the database file. */ static void -internal_endent (void) +internal_endent (FILE **stream) { - if (stream != NULL) + if (*stream != NULL) { - fclose (stream); - stream = NULL; + fclose (*stream); + *stream = NULL; } } @@ -169,10 +155,7 @@ CONCAT(_nss_files_end,ENTNAME) (void) { __libc_lock_lock (lock); - internal_endent (); - - /* Reset STAYOPEN flag. */ - keep_stream = 0; + internal_endent (&stream); __libc_lock_unlock (lock); @@ -198,10 +181,12 @@ get_contents (char *linebuf, size_t len, FILE *stream) { int curlen = ((remaining_len > (size_t) INT_MAX) ? INT_MAX : remaining_len); - char *p = fgets_unlocked (curbuf, curlen, stream); + /* Terminate the line so that we can test for overflow. */ ((unsigned char *) curbuf)[curlen - 1] = 0xff; + char *p = fgets_unlocked (curbuf, curlen, stream); + /* EOF or read error. */ if (p == NULL) return gcr_error; @@ -225,7 +210,7 @@ get_contents (char *linebuf, size_t len, FILE *stream) /* Parsing the database file into `struct STRUCTURE' data structures. */ static enum nss_status -internal_getent (struct STRUCTURE *result, +internal_getent (FILE *stream, struct STRUCTURE *result, char *buffer, size_t buflen, int *errnop H_ERRNO_PROTO EXTRA_ARGS_DECL) { @@ -272,7 +257,7 @@ internal_getent (struct STRUCTURE *result, || ! (parse_result = parse_line (p, result, data, buflen, errnop EXTRA_ARGS))); - if (__builtin_expect (parse_result == -1, 0)) + if (__glibc_unlikely (parse_result == -1)) { H_ERRNO_SET (NETDB_INTERNAL); return NSS_STATUS_TRYAGAIN; @@ -298,45 +283,14 @@ CONCAT(_nss_files_get,ENTNAME_r) (struct STRUCTURE *result, char *buffer, { int save_errno = errno; - status = internal_setent (0); + status = internal_setent (&stream); __set_errno (save_errno); - - if (status == NSS_STATUS_SUCCESS && fgetpos (stream, &position) < 0) - { - fclose (stream); - stream = NULL; - status = NSS_STATUS_UNAVAIL; - } } if (status == NSS_STATUS_SUCCESS) - { - /* If the last use was not by the getent function we need the - position the stream. */ - if (last_use != getent) - { - if (fsetpos (stream, &position) < 0) - status = NSS_STATUS_UNAVAIL; - else - last_use = getent; - } - - if (status == NSS_STATUS_SUCCESS) - { - status = internal_getent (result, buffer, buflen, errnop - H_ERRNO_ARG EXTRA_ARGS_VALUE); - - /* Remember this position if we were successful. If the - operation failed we give the user a chance to repeat the - operation (perhaps the buffer was too small). */ - if (status == NSS_STATUS_SUCCESS) - fgetpos (stream, &position); - else - /* We must make sure we reposition the stream the next call. */ - last_use = nouse; - } - } + status = internal_getent (stream, result, buffer, buflen, errnop + H_ERRNO_ARG EXTRA_ARGS_VALUE); __libc_lock_unlock (lock); @@ -362,27 +316,20 @@ _nss_files_get##name##_r (proto, \ size_t buflen, int *errnop H_ERRNO_PROTO) \ { \ enum nss_status status; \ + FILE *stream = NULL; \ \ - __libc_lock_lock (lock); \ - \ - /* Reset file pointer to beginning or open file. */ \ - status = internal_setent (keep_stream); \ + /* Open file. */ \ + status = internal_setent (&stream); \ \ if (status == NSS_STATUS_SUCCESS) \ { \ - /* Tell getent function that we have repositioned the file pointer. */ \ - last_use = getby; \ - \ - while ((status = internal_getent (result, buffer, buflen, errnop \ + while ((status = internal_getent (stream, result, buffer, buflen, errnop \ H_ERRNO_ARG EXTRA_ARGS_VALUE)) \ == NSS_STATUS_SUCCESS) \ { break_if_match } \ \ - if (! keep_stream) \ - internal_endent (); \ + internal_endent (&stream); \ } \ \ - __libc_lock_unlock (lock); \ - \ return status; \ } diff --git a/nss/nss_files/files-alias.c b/nss/nss_files/files-alias.c index 53088f6a8b..071c01d158 100644 --- a/nss/nss_files/files-alias.c +++ b/nss/nss_files/files-alias.c @@ -1,5 +1,5 @@ /* Mail alias file parser in nss_files module. - Copyright (C) 1996-2014 Free Software Foundation, Inc. + Copyright (C) 1996-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. @@ -33,23 +33,23 @@ /* Locks the static variables in this file. */ __libc_lock_define_initialized (static, lock) -/* Maintenance of the shared stream open on the database file. */ +/* Maintenance of the stream open on the database file. For getXXent + operations the stream needs to be held open across calls, the other + getXXbyYY operations all use their own stream. */ static FILE *stream; -static fpos_t position; -static enum { nouse, getent, getby } last_use; static enum nss_status -internal_setent (void) +internal_setent (FILE **stream) { enum nss_status status = NSS_STATUS_SUCCESS; - if (stream == NULL) + if (*stream == NULL) { - stream = fopen ("/etc/aliases", "rce"); + *stream = fopen ("/etc/aliases", "rce"); - if (stream == NULL) + if (*stream == NULL) status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL; else { @@ -62,7 +62,7 @@ internal_setent (void) int result; int flags; - result = flags = fcntl (fileno (stream), F_GETFD, 0); + result = flags = fcntl (fileno (*stream), F_GETFD, 0); if (result >= 0) { # ifdef O_CLOEXEC @@ -72,14 +72,14 @@ internal_setent (void) # endif { flags |= FD_CLOEXEC; - result = fcntl (fileno (stream), F_SETFD, flags); + result = fcntl (fileno (*stream), F_SETFD, flags); } } if (result < 0) { /* Something went wrong. Close the stream and return a failure. */ - fclose (stream); + fclose (*stream); stream = NULL; status = NSS_STATUS_UNAVAIL; } @@ -88,7 +88,7 @@ internal_setent (void) } } else - rewind (stream); + rewind (*stream); return status; } @@ -102,16 +102,7 @@ _nss_files_setaliasent (void) __libc_lock_lock (lock); - status = internal_setent (); - - if (status == NSS_STATUS_SUCCESS && fgetpos (stream, &position) < 0) - { - fclose (stream); - stream = NULL; - status = NSS_STATUS_UNAVAIL; - } - - last_use = getent; + status = internal_setent (&stream); __libc_lock_unlock (lock); @@ -121,12 +112,12 @@ _nss_files_setaliasent (void) /* Close the database file. */ static void -internal_endent (void) +internal_endent (FILE **stream) { - if (stream != NULL) + if (*stream != NULL) { - fclose (stream); - stream = NULL; + fclose (*stream); + *stream = NULL; } } @@ -137,7 +128,7 @@ _nss_files_endaliasent (void) { __libc_lock_lock (lock); - internal_endent (); + internal_endent (&stream); __libc_lock_unlock (lock); @@ -146,7 +137,7 @@ _nss_files_endaliasent (void) /* Parsing the database file into `struct aliasent' data structures. */ static enum nss_status -get_next_alias (const char *match, struct aliasent *result, +get_next_alias (FILE *stream, const char *match, struct aliasent *result, char *buffer, size_t buflen, int *errnop) { enum nss_status status = NSS_STATUS_NOTFOUND; @@ -397,35 +388,16 @@ _nss_files_getaliasent_r (struct aliasent *result, char *buffer, size_t buflen, /* Be prepared that the set*ent function was not called before. */ if (stream == NULL) - status = internal_setent (); + status = internal_setent (&stream); if (status == NSS_STATUS_SUCCESS) { - /* If the last use was not by the getent function we need the - position the stream. */ - if (last_use != getent) - { - if (fsetpos (stream, &position) < 0) - status = NSS_STATUS_UNAVAIL; - else - last_use = getent; - } + result->alias_local = 1; - if (status == NSS_STATUS_SUCCESS) - { - result->alias_local = 1; - - /* Read lines until we get a definite result. */ - do - status = get_next_alias (NULL, result, buffer, buflen, errnop); - while (status == NSS_STATUS_RETURN); - - /* If we successfully read an entry remember this position. */ - if (status == NSS_STATUS_SUCCESS) - fgetpos (stream, &position); - else - last_use = nouse; - } + /* Read lines until we get a definite result. */ + do + status = get_next_alias (stream, NULL, result, buffer, buflen, errnop); + while (status == NSS_STATUS_RETURN); } __libc_lock_unlock (lock); @@ -440,6 +412,7 @@ _nss_files_getaliasbyname_r (const char *name, struct aliasent *result, { /* Return next entry in host file. */ enum nss_status status = NSS_STATUS_SUCCESS; + FILE *stream = NULL; if (name == NULL) { @@ -447,11 +420,8 @@ _nss_files_getaliasbyname_r (const char *name, struct aliasent *result, return NSS_STATUS_UNAVAIL; } - __libc_lock_lock (lock); - - /* Open the stream or rest it. */ - status = internal_setent (); - last_use = getby; + /* Open the stream. */ + status = internal_setent (&stream); if (status == NSS_STATUS_SUCCESS) { @@ -459,13 +429,11 @@ _nss_files_getaliasbyname_r (const char *name, struct aliasent *result, /* Read lines until we get a definite result. */ do - status = get_next_alias (name, result, buffer, buflen, errnop); + status = get_next_alias (stream, name, result, buffer, buflen, errnop); while (status == NSS_STATUS_RETURN); } - internal_endent (); - - __libc_lock_unlock (lock); + internal_endent (&stream); return status; } diff --git a/nss/nss_files/files-ethers.c b/nss/nss_files/files-ethers.c index 3f9ec57448..47fa7843fd 100644 --- a/nss/nss_files/files-ethers.c +++ b/nss/nss_files/files-ethers.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996-2014 Free Software Foundation, Inc. +/* Copyright (C) 1996-2015 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 diff --git a/nss/nss_files/files-grp.c b/nss/nss_files/files-grp.c index 36068d446b..42155bc2e3 100644 --- a/nss/nss_files/files-grp.c +++ b/nss/nss_files/files-grp.c @@ -1,5 +1,5 @@ /* Group file parser in nss_files module. - Copyright (C) 1996-2014 Free Software Foundation, Inc. + Copyright (C) 1996-2015 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 diff --git a/nss/nss_files/files-have_o_cloexec.c b/nss/nss_files/files-have_o_cloexec.c index 4a6cd173ed..0b61a44859 100644 --- a/nss/nss_files/files-have_o_cloexec.c +++ b/nss/nss_files/files-have_o_cloexec.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2007-2014 Free Software Foundation, Inc. +/* Copyright (C) 2007-2015 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 diff --git a/nss/nss_files/files-hosts.c b/nss/nss_files/files-hosts.c index ab64eadabb..4117458c92 100644 --- a/nss/nss_files/files-hosts.c +++ b/nss/nss_files/files-hosts.c @@ -1,5 +1,5 @@ /* Hosts file parser in nss_files module. - Copyright (C) 1996-2014 Free Software Foundation, Inc. + Copyright (C) 1996-2015 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 @@ -120,14 +120,13 @@ _nss_files_gethostbyname3_r (const char *name, int af, struct hostent *result, char *buffer, size_t buflen, int *errnop, int *herrnop, int32_t *ttlp, char **canonp) { + FILE *stream = NULL; uintptr_t pad = -(uintptr_t) buffer % __alignof__ (struct hostent_data); buffer += pad; buflen = buflen > pad ? buflen - pad : 0; - __libc_lock_lock (lock); - - /* Reset file pointer to beginning or open file. */ - enum nss_status status = internal_setent (keep_stream); + /* Open file. */ + enum nss_status status = internal_setent (&stream); if (status == NSS_STATUS_SUCCESS) { @@ -135,10 +134,7 @@ _nss_files_gethostbyname3_r (const char *name, int af, struct hostent *result, addresses to IPv6 addresses really the right thing to do? */ int flags = ((_res.options & RES_USE_INET6) ? AI_V4MAPPED : 0); - /* Tell getent function that we have repositioned the file pointer. */ - last_use = getby; - - while ((status = internal_getent (result, buffer, buflen, errnop, + while ((status = internal_getent (stream, result, buffer, buflen, errnop, herrnop, af, flags)) == NSS_STATUS_SUCCESS) { @@ -165,7 +161,7 @@ _nss_files_gethostbyname3_r (const char *name, int af, struct hostent *result, bufferend = (char *) &result->h_aliases[naliases + 1]; again: - while ((status = internal_getent (&tmp_result_buf, tmp_buffer, + while ((status = internal_getent (stream, &tmp_result_buf, tmp_buffer, tmp_buflen, errnop, herrnop, af, flags)) == NSS_STATUS_SUCCESS) @@ -341,15 +337,12 @@ _nss_files_gethostbyname3_r (const char *name, int af, struct hostent *result, free (tmp_buffer); } - if (! keep_stream) - internal_endent (); + internal_endent (&stream); } if (canonp && status == NSS_STATUS_SUCCESS) *canonp = result->h_name; - __libc_lock_unlock (lock); - return status; } @@ -378,16 +371,13 @@ _nss_files_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat, char *buffer, size_t buflen, int *errnop, int *herrnop, int32_t *ttlp) { - __libc_lock_lock (lock); + FILE *stream = NULL; - /* Reset file pointer to beginning or open file. */ - enum nss_status status = internal_setent (keep_stream); + /* Open file. */ + enum nss_status status = internal_setent (&stream); if (status == NSS_STATUS_SUCCESS) { - /* Tell getent function that we have repositioned the file pointer. */ - last_use = getby; - bool any = false; bool got_canon = false; while (1) @@ -399,7 +389,7 @@ _nss_files_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat, buflen = buflen > pad ? buflen - pad : 0; struct hostent result; - status = internal_getent (&result, buffer, buflen, errnop, + status = internal_getent (stream, &result, buffer, buflen, errnop, herrnop, AF_UNSPEC, 0); if (status != NSS_STATUS_SUCCESS) break; @@ -475,8 +465,7 @@ _nss_files_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat, status = NSS_STATUS_SUCCESS; } - if (! keep_stream) - internal_endent (); + internal_endent (&stream); } else if (status == NSS_STATUS_TRYAGAIN) { @@ -489,7 +478,5 @@ _nss_files_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat, *herrnop = NO_DATA; } - __libc_lock_unlock (lock); - return status; } diff --git a/nss/nss_files/files-init.c b/nss/nss_files/files-init.c index 346395c6ff..72eced41bf 100644 --- a/nss/nss_files/files-init.c +++ b/nss/nss_files/files-init.c @@ -1,5 +1,5 @@ /* Initialization in nss_files module. - Copyright (C) 2011-2014 Free Software Foundation, Inc. + Copyright (C) 2011-2015 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 @@ -21,47 +21,43 @@ #include <string.h> #include <nscd/nscd.h> +#define PWD_FILENAME "/etc/passwd" +define_traced_file (pwd, PWD_FILENAME); -#define TF(id, filename, ...) \ -static union \ -{ \ - struct traced_file file; \ - char buf[sizeof (struct traced_file) + sizeof (filename)]; \ -} id##_traced_file = \ - { \ - .file = \ - { \ - __VA_ARGS__ \ - } \ - } +#define GRP_FILENAME "/etc/group" +define_traced_file (grp, GRP_FILENAME); -TF (pwd, "/etc/passwd"); -TF (grp, "/etc/group"); -TF (hst, "/etc/hosts"); -TF (resolv, "/etc/resolv.conf", .call_res_init = 1); -TF (serv, "/etc/services"); -TF (netgr, "/etc/netgroup"); +#define HST_FILENAME "/etc/hosts" +define_traced_file (hst, HST_FILENAME); +#define RESOLV_FILENAME "/etc/resolv.conf" +define_traced_file (resolv, RESOLV_FILENAME); + +#define SERV_FILENAME "/etc/services" +define_traced_file (serv, SERV_FILENAME); + +#define NETGR_FILENAME "/etc/netgroup" +define_traced_file (netgr, NETGR_FILENAME); void _nss_files_init (void (*cb) (size_t, struct traced_file *)) { - strcpy (pwd_traced_file.file.fname, "/etc/passwd"); + init_traced_file (&pwd_traced_file.file, PWD_FILENAME, 0); cb (pwddb, &pwd_traced_file.file); - strcpy (grp_traced_file.file.fname, "/etc/group"); + init_traced_file (&grp_traced_file.file, GRP_FILENAME, 0); cb (grpdb, &grp_traced_file.file); - strcpy (hst_traced_file.file.fname, "/etc/hosts"); + init_traced_file (&hst_traced_file.file, HST_FILENAME, 0); cb (hstdb, &hst_traced_file.file); - strcpy (resolv_traced_file.file.fname, "/etc/resolv.conf"); + init_traced_file (&resolv_traced_file.file, RESOLV_FILENAME, 1); cb (hstdb, &resolv_traced_file.file); - strcpy (serv_traced_file.file.fname, "/etc/services"); + init_traced_file (&serv_traced_file.file, SERV_FILENAME, 0); cb (servdb, &serv_traced_file.file); - strcpy (netgr_traced_file.file.fname, "/etc/netgroup"); + init_traced_file (&netgr_traced_file.file, NETGR_FILENAME, 0); cb (netgrdb, &netgr_traced_file.file); } diff --git a/nss/nss_files/files-initgroups.c b/nss/nss_files/files-initgroups.c index 9249c24939..084d36be8a 100644 --- a/nss/nss_files/files-initgroups.c +++ b/nss/nss_files/files-initgroups.c @@ -1,5 +1,5 @@ /* Initgroups handling in nss_files module. - Copyright (C) 2011-2014 Free Software Foundation, Inc. + Copyright (C) 2011-2015 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 diff --git a/nss/nss_files/files-key.c b/nss/nss_files/files-key.c index 561f79b669..2d64744b2d 100644 --- a/nss/nss_files/files-key.c +++ b/nss/nss_files/files-key.c @@ -1,5 +1,5 @@ /* Public key file parser in nss_files module. - Copyright (C) 1996-2014 Free Software Foundation, Inc. + Copyright (C) 1996-2015 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 diff --git a/nss/nss_files/files-netgrp.c b/nss/nss_files/files-netgrp.c index 34eae4c5be..8886c2625a 100644 --- a/nss/nss_files/files-netgrp.c +++ b/nss/nss_files/files-netgrp.c @@ -1,5 +1,5 @@ /* Netgroup file parser in nss_files modules. - Copyright (C) 1996-2014 Free Software Foundation, Inc. + Copyright (C) 1996-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. @@ -252,7 +252,7 @@ _nss_netgroup_parseline (char **cursor, struct __netgrent *result, if (cp - host > buflen) { *errnop = ERANGE; - status = NSS_STATUS_UNAVAIL; + status = NSS_STATUS_TRYAGAIN; } else { diff --git a/nss/nss_files/files-network.c b/nss/nss_files/files-network.c index c0ac7bbd0a..46e99451a1 100644 --- a/nss/nss_files/files-network.c +++ b/nss/nss_files/files-network.c @@ -1,5 +1,5 @@ /* Networks file parser in nss_files module. - Copyright (C) 1996-2014 Free Software Foundation, Inc. + Copyright (C) 1996-2015 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 diff --git a/nss/nss_files/files-parse.c b/nss/nss_files/files-parse.c index 1da1a6f352..9911633013 100644 --- a/nss/nss_files/files-parse.c +++ b/nss/nss_files/files-parse.c @@ -1,5 +1,5 @@ /* Common code for file-based database parsers in nss_files module. - Copyright (C) 1996-2014 Free Software Foundation, Inc. + Copyright (C) 1996-2015 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 @@ -73,7 +73,7 @@ struct parser_data /* Export the line parser function so it can be used in nss_db. */ # define parser_stclass /* Global */ # define parse_line CONCAT(_nss_files_parse_,ENTNAME) -# ifdef IS_IN_libc +# if IS_IN (libc) /* We are defining one of the functions that actually lives in libc because it is used to implement fget*ent and suchlike. */ # define nss_files_parse_hidden_def(name) libc_hidden_def (name) diff --git a/nss/nss_files/files-proto.c b/nss/nss_files/files-proto.c index fded57dc20..370266a04c 100644 --- a/nss/nss_files/files-proto.c +++ b/nss/nss_files/files-proto.c @@ -1,5 +1,5 @@ /* Protocols file parser in nss_files module. - Copyright (C) 1996-2014 Free Software Foundation, Inc. + Copyright (C) 1996-2015 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 diff --git a/nss/nss_files/files-pwd.c b/nss/nss_files/files-pwd.c index 5d3c46be81..84ce5bb1fb 100644 --- a/nss/nss_files/files-pwd.c +++ b/nss/nss_files/files-pwd.c @@ -1,5 +1,5 @@ /* User file parser in nss_files module. - Copyright (C) 1996-2014 Free Software Foundation, Inc. + Copyright (C) 1996-2015 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 diff --git a/nss/nss_files/files-rpc.c b/nss/nss_files/files-rpc.c index 1cb9b78bde..34f6aec690 100644 --- a/nss/nss_files/files-rpc.c +++ b/nss/nss_files/files-rpc.c @@ -1,5 +1,5 @@ /* SunRPC program number file parser in nss_files module. - Copyright (C) 1996-2014 Free Software Foundation, Inc. + Copyright (C) 1996-2015 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 diff --git a/nss/nss_files/files-service.c b/nss/nss_files/files-service.c index 2401cb0852..7fccbdbdbd 100644 --- a/nss/nss_files/files-service.c +++ b/nss/nss_files/files-service.c @@ -1,5 +1,5 @@ /* Services file parser in nss_files module. - Copyright (C) 1996-2014 Free Software Foundation, Inc. + Copyright (C) 1996-2015 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 @@ -44,8 +44,11 @@ DB_LOOKUP (servbyname, ':', { /* Must match both protocol (if specified) and name. */ if (proto != NULL && strcmp (result->s_proto, proto)) - continue; - LOOKUP_NAME (s_name, s_aliases) + /* A continue statement here breaks nss_db, because it + bypasses advancing to the next db entry, and it + doesn't make nss_files any more efficient. */; + else + LOOKUP_NAME (s_name, s_aliases) }, const char *name, const char *proto) diff --git a/nss/nss_files/files-sgrp.c b/nss/nss_files/files-sgrp.c index 2b2159a4ef..ac74324d70 100644 --- a/nss/nss_files/files-sgrp.c +++ b/nss/nss_files/files-sgrp.c @@ -1,5 +1,5 @@ /* User file parser in nss_files module. - Copyright (C) 2009-2014 Free Software Foundation, Inc. + Copyright (C) 2009-2015 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 diff --git a/nss/nss_files/files-spwd.c b/nss/nss_files/files-spwd.c index b7e2dddb44..a255454fd4 100644 --- a/nss/nss_files/files-spwd.c +++ b/nss/nss_files/files-spwd.c @@ -1,5 +1,5 @@ /* User file parser in nss_files module. - Copyright (C) 1996-2014 Free Software Foundation, Inc. + Copyright (C) 1996-2015 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 diff --git a/nss/nsswitch.c b/nss/nsswitch.c index 07ca225232..9712623157 100644 --- a/nss/nsswitch.c +++ b/nss/nsswitch.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996-2014 Free Software Foundation, Inc. +/* Copyright (C) 1996-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. diff --git a/nss/nsswitch.h b/nss/nsswitch.h index 90a0c62f77..a5318fa82b 100644 --- a/nss/nsswitch.h +++ b/nss/nsswitch.h @@ -1,4 +1,4 @@ -/* Copyright (C) 1996-2014 Free Software Foundation, Inc. +/* Copyright (C) 1996-2015 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 diff --git a/nss/proto-lookup.c b/nss/proto-lookup.c index 8ccc9da2f2..f4a9781366 100644 --- a/nss/proto-lookup.c +++ b/nss/proto-lookup.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996-2014 Free Software Foundation, Inc. +/* Copyright (C) 1996-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. diff --git a/nss/pwd-lookup.c b/nss/pwd-lookup.c index b2c1bc7419..f9f58d0a03 100644 --- a/nss/pwd-lookup.c +++ b/nss/pwd-lookup.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996-2014 Free Software Foundation, Inc. +/* Copyright (C) 1996-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. diff --git a/nss/rpc-lookup.c b/nss/rpc-lookup.c index 6ef66fcf2e..ad0312d4f8 100644 --- a/nss/rpc-lookup.c +++ b/nss/rpc-lookup.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996-2014 Free Software Foundation, Inc. +/* Copyright (C) 1996-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. diff --git a/nss/service-lookup.c b/nss/service-lookup.c index 7f7dcdfb4a..6462832ec6 100644 --- a/nss/service-lookup.c +++ b/nss/service-lookup.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996-2014 Free Software Foundation, Inc. +/* Copyright (C) 1996-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. diff --git a/nss/sgrp-lookup.c b/nss/sgrp-lookup.c index ee1782de1b..a384a4e307 100644 --- a/nss/sgrp-lookup.c +++ b/nss/sgrp-lookup.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2009-2014 Free Software Foundation, Inc. +/* Copyright (C) 2009-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@redhat.com>, 2009. diff --git a/nss/spwd-lookup.c b/nss/spwd-lookup.c index aba1a4cc02..3074e91f2c 100644 --- a/nss/spwd-lookup.c +++ b/nss/spwd-lookup.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996-2014 Free Software Foundation, Inc. +/* Copyright (C) 1996-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. diff --git a/nss/test-digits-dots.c b/nss/test-digits-dots.c index db6fdb7b33..98202fc40a 100644 --- a/nss/test-digits-dots.c +++ b/nss/test-digits-dots.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2013-2014 Free Software Foundation, Inc. +/* Copyright (C) 2013-2015 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 diff --git a/nss/test-netdb.c b/nss/test-netdb.c index 1620b5b173..7088549311 100644 --- a/nss/test-netdb.c +++ b/nss/test-netdb.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1998-2014 Free Software Foundation, Inc. +/* Copyright (C) 1998-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Andreas Jaeger <aj@suse.de>, 1998. @@ -23,14 +23,12 @@ - /etc/hosts - /etc/networks - /etc/protocols - - /etc/rpc The tests try to be fairly generic and simple so that they work on every possible setup (and might therefore not detect some possible errors). */ #include <netdb.h> -#include <rpc/netdb.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -300,43 +298,6 @@ test_protocols (void) } -static void -output_rpcent (const char *call, struct rpcent *rptr) -{ - char **pptr; - - if (rptr == NULL) - printf ("Call: %s returned NULL\n", call); - else - { - printf ("Call: %s, returned: r_name: %s, r_number: %d\n", - call, rptr->r_name, rptr->r_number); - for (pptr = rptr->r_aliases; *pptr != NULL; pptr++) - printf (" alias: %s\n", *pptr); - } -} - -static void -test_rpc (void) -{ - struct rpcent *rptr; - - rptr = getrpcbyname ("portmap"); - output_rpcent ("getrpcyname (\"portmap\")", rptr); - - rptr = getrpcbynumber (100000); - output_rpcent ("getrpcbynumber (100000)", rptr); - - setrpcent (0); - do - { - rptr = getrpcent (); - output_rpcent ("getrpcent ()", rptr); - } - while (rptr != NULL); - endrpcent (); -} - /* Override /etc/nsswitch.conf for this program. This is mainly useful for developers. */ static void __attribute__ ((unused)) @@ -351,13 +312,12 @@ setdb (const char *dbname) __nss_configure_lookup ("networks", dbname); } __nss_configure_lookup ("protocols", dbname); - __nss_configure_lookup ("rpc", dbname); __nss_configure_lookup ("services", dbname); } -int -main (void) +static int +do_test (void) { /* setdb ("db"); @@ -366,7 +326,6 @@ main (void) test_hosts (); test_network (); test_protocols (); - test_rpc (); test_services (); if (error_count) @@ -376,3 +335,6 @@ main (void) return (error_count != 0); } + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" diff --git a/nss/tst-nss-getpwent.c b/nss/tst-nss-getpwent.c new file mode 100644 index 0000000000..f2e8abce60 --- /dev/null +++ b/nss/tst-nss-getpwent.c @@ -0,0 +1,118 @@ +/* Copyright (C) 2015 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 + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <pwd.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +int +do_test (void) +{ + /* Count the number of entries in the password database, and fetch + data from the first and last entries. */ + size_t count = 0; + struct passwd * pw; + char *first_name = NULL; + uid_t first_uid = 0; + char *last_name = NULL; + uid_t last_uid = 0; + setpwent (); + while ((pw = getpwent ()) != NULL) + { + if (first_name == NULL) + { + first_name = strdup (pw->pw_name); + if (first_name == NULL) + { + printf ("strdup: %m\n"); + return 1; + } + first_uid = pw->pw_uid; + } + + free (last_name); + last_name = strdup (pw->pw_name); + if (last_name == NULL) + { + printf ("strdup: %m\n"); + return 1; + } + last_uid = pw->pw_uid; + ++count; + } + endpwent (); + + if (count == 0) + { + printf ("No entries in the password database.\n"); + return 0; + } + + /* Try again, this time interleaving with name-based and UID-based + lookup operations. The counts do not match if the interleaved + lookups affected the enumeration. */ + size_t new_count = 0; + setpwent (); + while ((pw = getpwent ()) != NULL) + { + if (new_count == count) + { + printf ("Additional entry in the password database.\n"); + return 1; + } + ++new_count; + struct passwd *pw2 = getpwnam (first_name); + if (pw2 == NULL) + { + printf ("getpwnam (%s) failed: %m\n", first_name); + return 1; + } + pw2 = getpwnam (last_name); + if (pw2 == NULL) + { + printf ("getpwnam (%s) failed: %m\n", last_name); + return 1; + } + pw2 = getpwuid (first_uid); + if (pw2 == NULL) + { + printf ("getpwuid (%llu) failed: %m\n", + (unsigned long long) first_uid); + return 1; + } + pw2 = getpwuid (last_uid); + if (pw2 == NULL) + { + printf ("getpwuid (%llu) failed: %m\n", + (unsigned long long) last_uid); + return 1; + } + } + endpwent (); + if (new_count < count) + { + printf ("Missing entry in the password database.\n"); + return 1; + } + + return 0; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" diff --git a/nss/tst-nss-test1.c b/nss/tst-nss-test1.c index 4e443d4539..c5750e0956 100644 --- a/nss/tst-nss-test1.c +++ b/nss/tst-nss-test1.c @@ -21,7 +21,7 @@ do_test (void) if (p->pw_uid != *np || strncmp (p->pw_name, "name", 4) != 0 || atol (p->pw_name + 4) != *np) { - printf ("passwd entry %ju wrong (%s, %u)\n", + printf ("passwd entry %td wrong (%s, %u)\n", np - pwdids, p->pw_name, p->pw_uid); retval = 1; break; |