[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[commits] r14283 - in /trunk: libc/ libc/catgets/ libc/elf/ libc/grp/ libc/inet/ libc/io/ libc/locale/programs/ libc/misc/ libc/nis/ l...
- To: commits@xxxxxxxxxx
- Subject: [commits] r14283 - in /trunk: libc/ libc/catgets/ libc/elf/ libc/grp/ libc/inet/ libc/io/ libc/locale/programs/ libc/misc/ libc/nis/ l...
- From: joseph@xxxxxxxxxx
- Date: Tue, 21 Jun 2011 15:37:40 -0000
Author: joseph
Date: Tue Jun 21 08:37:38 2011
New Revision: 14283
Log:
Merge changes between r14127 and r14282 from /fsf/trunk.
Added:
trunk/libc/elf/pldd-xx.c
- copied unchanged from r14282, fsf/trunk/libc/elf/pldd-xx.c
trunk/libc/elf/pldd.c
- copied, changed from r14282, fsf/trunk/libc/elf/pldd.c
trunk/libc/nss/nss_db/db-initgroups.c
- copied unchanged from r14282, fsf/trunk/libc/nss/nss_db/db-initgroups.c
trunk/libc/sysdeps/unix/sysv/linux/wordsize-64/dl-fxstatat64.c
- copied unchanged from r14282, fsf/trunk/libc/sysdeps/unix/sysv/linux/wordsize-64/dl-fxstatat64.c
trunk/ports/sysdeps/unix/sysv/linux/arm/eabi/internal_sendmmsg.S
- copied unchanged from r14282, fsf/trunk/ports/sysdeps/unix/sysv/linux/arm/eabi/internal_sendmmsg.S
trunk/ports/sysdeps/unix/sysv/linux/mips/mips32/internal_sendmmsg.S
- copied unchanged from r14282, fsf/trunk/ports/sysdeps/unix/sysv/linux/mips/mips32/internal_sendmmsg.S
trunk/ports/sysdeps/unix/sysv/linux/mips/mips32/sendmmsg.c
- copied unchanged from r14282, fsf/trunk/ports/sysdeps/unix/sysv/linux/mips/mips32/sendmmsg.c
Removed:
trunk/libc/nss/nss_db/db-alias.c
trunk/libc/nss/nss_db/dummy-db.h
Modified:
trunk/libc/ChangeLog
trunk/libc/ChangeLog.eglibc
trunk/libc/Makeconfig
trunk/libc/Makefile
trunk/libc/Makerules
trunk/libc/NEWS
trunk/libc/Versions.def
trunk/libc/catgets/gencat.c
trunk/libc/configure
trunk/libc/configure.in
trunk/libc/elf/Makefile
trunk/libc/elf/dl-open.c
trunk/libc/elf/dl-runtime.c
trunk/libc/elf/dl-sym.c
trunk/libc/grp/initgroups.c
trunk/libc/inet/getnetgrent_r.c
trunk/libc/io/fts.c
trunk/libc/locale/programs/ld-collate.c
trunk/libc/locale/programs/ld-ctype.c
trunk/libc/locale/programs/locarchive.c
trunk/libc/misc/syslog.c
trunk/libc/nis/nis_print_group_entry.c
trunk/libc/nis/nss_compat/compat-pwd.c
trunk/libc/nis/nss_compat/compat-spwd.c
trunk/libc/nptl/ChangeLog
trunk/libc/nptl/pthread_rwlock_init.c
trunk/libc/nscd/hstcache.c
trunk/libc/nss/Makefile
trunk/libc/nss/Versions
trunk/libc/nss/databases.def
trunk/libc/nss/db-Makefile
trunk/libc/nss/getent.c
trunk/libc/nss/makedb.c
trunk/libc/nss/nss_db/db-XXX.c
trunk/libc/nss/nss_db/db-netgrp.c
trunk/libc/nss/nss_db/db-open.c
trunk/libc/nss/nss_db/nss_db.h
trunk/libc/nss/nss_files/files-XXX.c
trunk/libc/nss/nss_files/files-ethers.c
trunk/libc/nss/nss_files/files-grp.c
trunk/libc/nss/nss_files/files-hosts.c
trunk/libc/nss/nss_files/files-network.c
trunk/libc/nss/nss_files/files-proto.c
trunk/libc/nss/nss_files/files-pwd.c
trunk/libc/nss/nss_files/files-rpc.c
trunk/libc/nss/nss_files/files-service.c
trunk/libc/nss/nss_files/files-sgrp.c
trunk/libc/nss/nss_files/files-spwd.c
trunk/libc/posix/bug-regex31.c
trunk/libc/resolv/nss_dns/dns-network.c
trunk/libc/resolv/res_hconf.c
trunk/libc/resolv/res_send.c
trunk/libc/shlib-versions
trunk/libc/stdio-common/printf_fp.c
trunk/libc/sunrpc/clnt_udp.c
trunk/libc/sysdeps/i386/dl-irel.h
trunk/libc/sysdeps/posix/getaddrinfo.c
trunk/libc/sysdeps/powerpc/powerpc32/dl-irel.h
trunk/libc/sysdeps/powerpc/powerpc64/dl-irel.h
trunk/libc/sysdeps/sparc/sparc32/dl-irel.h
trunk/libc/sysdeps/sparc/sparc32/dl-plt.h
trunk/libc/sysdeps/sparc/sparc64/dl-irel.h
trunk/libc/sysdeps/sparc/sparc64/dl-plt.h
trunk/libc/sysdeps/unix/sysv/linux/check_native.c
trunk/libc/sysdeps/x86_64/dl-irel.h
trunk/libc/version.h
trunk/ports/ChangeLog.arm
trunk/ports/ChangeLog.mips
trunk/ports/sysdeps/arm/dl-irel.h
trunk/ports/sysdeps/unix/sysv/linux/mips/bits/siginfo.h
trunk/ports/sysdeps/unix/sysv/linux/mips/bits/socket.h
Modified: trunk/libc/ChangeLog
==============================================================================
--- trunk/libc/ChangeLog (original)
+++ trunk/libc/ChangeLog Tue Jun 21 08:37:38 2011
@@ -1,3 +1,167 @@
+2011-06-20 David S. Miller <davem@xxxxxxxxxxxxx>
+
+ * sysdeps/sparc/sparc32/dl-plt.h: Protect against multiple
+ inclusions.
+ * sysdeps/sparc/sparc64/dl-plt.h: Likewise.
+
+ * sysdeps/i386/dl-irel.h (elf_ifunc_invoke): New.
+ (elf_irel): Use it.
+ * sysdeps/powerpc/powerpc32/dl-irel.h: Likewise.
+ * sysdeps/powerpc/powerpc64/dl-irel.h: Likewise.
+ * sysdeps/sparc/sparc32/dl-irel.h: Likewise.
+ * sysdeps/sparc/sparc64/dl-irel.h: Likewise.
+ * sysdeps/x86_64/dl-irel.h: Likewise.
+
+ * elf/dl-runtime.c: Use elf_ifunc_invoke.
+ * elf/dl-sym.c: Likewise.
+
+2011-06-15 Ulrich Drepper <drepper@xxxxxxxxx>
+
+ * resolv/res_send.c (__libc_res_nsend): Fix typos in last patch. We
+ need to dereference resplen2.
+
+2011-06-14 Andreas Schwab <schwab@xxxxxxxxxx>
+
+ * sysdeps/unix/sysv/linux/wordsize-64/dl-fxstatat64.c: New file.
+
+2011-06-15 Ulrich Drepper <drepper@xxxxxxxxx>
+
+ * Makeconfig: Define vardbdir and inst_vardbdir.
+ * nss/Makefile: Add rules to install db-Makefile.
+
+ * nss/nss_db/db-XXX.c: Cleanup.
+
+ * nss/Makefile (libnss_db-dbs): Add db-initgroups.
+ * nss/Versions [libnss_db]: Add _nss_db_initgroups_dyn for
+ GLIBC_PRIVATE.
+ * nss/db-Makefile (groups.db): Emit entries for initgroups lookups.
+ * nss/makedb.c: Implement -g option to specify that value strings
+ are generated and should not be added to table iterated over for
+ get*ent calls.
+ * nss/nss_db/db-initgroups.c: New file.
+
+ * nss/getent.c: Add support for initgroups lookups through getgrouplist
+ interface.
+
+ * grp/initgroups.c (__nss_initgroups_database): Renamed and exported.
+ (internal_getgrouplist): Adjust to name change.
+ Update use_initgroups_entry if this is not the first call.
+ * nss/databases.def: Add initgroups entry.
+
+ * nss/makedb.c (compute_tables): Check result of multiple hash table
+ sizes to minimize maximum chain length.
+
+2011-06-14 Ulrich Drepper <drepper@xxxxxxxxx>
+
+ * Versions.def: Add entry for libnss_db.
+ * shlib-versions: Likewise.
+ * nss/Makefile: Add rules to build libnss_db.
+ * nss/Versions: Add libnss_db information. Organize libnss_files
+ entries better.
+ * nss/db-Makefile: Add gshadow support. Change rules for the new
+ makedb progra. Some minor improvements to generate smaller files.
+ * nss/nss_db/nss_db.h: Move NSS database header data structures to
+ here from...
+ * nss/makedb.c: ...here.
+ Improve database format to be smaller and require less memory at
+ runtime.
+ * nss/nss_db/db-XXX.x: Adjust for new database format. Don't use
+ db anymore.
+ * nss/nss_db/db-netgrp.c: Likewise.
+ * nss/nss_db/db-open.c: Likewise.
+ * nss/nss_files/flies-XXX.x: Adjust comments.
+ * nss/nss_files/files-ethers.c: Adjust for new DB_LOOKUP definition.
+ * nss/nss_files/files-grp.c: Likewise.
+ * nss/nss_files/files-hosts.c: Likewise.
+ * nss/nss_files/files-network.c: Likewise.
+ * nss/nss_files/files-proto.c: Likewise.
+ * nss/nss_files/files-pwd.c: Likewise.
+ * nss/nss_files/files-rpc.c: Likewise.
+ * nss/nss_files/files-service.c: Likewise.
+ * nss/nss_files/files-sgrp.c: Likewise.
+ * nss/nss_files/files-spwd.c: Likewise.
+ * nss/nss_db/db-alias.c: Removed.
+ * nss/nss_db/dummy-db.h: Removed.
+
+2011-06-02 Ulrich Drepper <drepper@xxxxxxxxx>
+
+ * nss/makedb.c: Rewritten to not use database library.
+ * nss/Makefile: Update to build new makedb program.
+
+2011-06-14 Andreas Jaeger <aj@xxxxxxx>
+
+ * sysdeps/unix/sysv/linux/check_native.c: Include <string.h> for
+ memset declaration.
+
+2011-06-10 Andreas Schwab <schwab@xxxxxxxxxx>
+
+ * sysdeps/posix/getaddrinfo.c (gaih_inet): Fix logic allocating
+ tmpbuf.
+
+2011-06-10 Roland McGrath <roland@xxxxxxxxxxxxx>
+
+ * Makerules (shlib.lds): Fail if the linker script comes out empty.
+ * elf/Makefile ($(objpfx)ld.so): Likewise.
+
+ * Makefile ($(common-objpfx)linkobj/libc.so): Break long lines with \.
+ Don't list ld.so twice in dependencies.
+
+ * posix/bug-regex31.c: Include <stdlib.h>.
+
+ * nscd/hstcache.c (cache_addhst): Remove unused variable.
+
+ * nis/nss_compat/compat-spwd.c
+ (getspent_next_nss_netgr): Remove unused variable.
+ * nis/nss_compat/compat-pwd.c (getpwent_next_nss_netgr): Likewise.
+
+ * nis/nis_print_group_entry.c (nis_print_group_entry): Fix "Implicit
+ nonmembers" output to use the right array.
+
+ * resolv/nss_dns/dns-network.c (getanswer_r): Remove unused variable.
+
+ * elf/dl-open.c (_dl_open): Quash warnings when DL_NNS==1.
+
+ * locale/programs/ld-ctype.c (ctype_read): Remove unused variable.
+ * locale/programs/ld-collate.c (add_to_tablewc): Likewise.
+ * catgets/gencat.c (read_input_file): Likewise.
+ * locale/programs/locarchive.c (enlarge_archive): Likewise.
+
+ * sunrpc/clnt_udp.c (__libc_clntudp_bufcreate): Move DONTBLOCK
+ variable definition inside #if's controlling its use.
+
+ * inet/getnetgrent_r.c (innetgr): Remove unused variable.
+
+ * resolv/res_hconf.c (_res_hconf_reorder_addrs): Fix errno restoration.
+
+ * misc/syslog.c (__vsyslog_chk): Remove unused variable.
+
+ * io/fts.c (fts_build): Use if (0 && ...) rather than #if 0 for
+ unreachable code.
+
+ * stdio-common/printf_fp.c (___printf_fp): Remove unused variable.
+
+ * configure.in (nss-crypt check): Use AC_LANG_PROGRAM.
+ * configure: Regenerated.
+
+ * Makerules: Revert last change.
+ * elf/Makefile: Likewise.
+
+2011-06-09 Roland McGrath <roland@xxxxxxxxxxxxx>
+
+ * Makerules ($(common-objpfx)libc_pic.os): Use -Wl, before -r.
+ * elf/Makefile ($(objpfx)librtld.os): Likewise.
+ (reloc-link): Likewise.
+
+2011-06-09 Ulrich Drepper <drepper@xxxxxxxxx>
+
+ * elf/Makefile: Add rules to build pldd.
+ * elf/pldd.c: New file.
+ * elf/pldd-xx.c: New file.
+
+2011-06-07 Ulrich Drepper <drepper@xxxxxxxxx>
+
+ * version.h: Update for 2.15 development version.
+
2011-06-07 David S. Miller <davem@xxxxxxxxxxxxx>
* sysdeps/sparc/sparc32/dl-irel.h (elf_irela): Pass dl_hwcap to
Modified: trunk/libc/ChangeLog.eglibc
==============================================================================
--- trunk/libc/ChangeLog.eglibc (original)
+++ trunk/libc/ChangeLog.eglibc Tue Jun 21 08:37:38 2011
@@ -1,3 +1,8 @@
+2011-06-21 Joseph Myers <joseph@xxxxxxxxxxxxxxxx>
+
+ * elf/pldd.c (argp_program_bug_address): Use REPORT_BUGS_TO.
+ (print_version): Use PKGVERSION.
+
2011-06-21 Joseph Myers <joseph@xxxxxxxxxxxxxxxx>
* elf/sotruss.ksh: Use PKGVERSION and REPORT_BUGS_TO.
Modified: trunk/libc/Makeconfig
==============================================================================
--- trunk/libc/Makeconfig (original)
+++ trunk/libc/Makeconfig Tue Jun 21 08:37:38 2011
@@ -290,6 +290,12 @@
sysconfdir = $(prefix)/etc
endif
inst_sysconfdir = $(install_root)$(sysconfdir)
+
+# Directory for the database files and Makefile for nss_db.
+ifndef vardbdir
+vardbdir = /var/db
+endif
+inst_vardbdir = $(install_root)$(vardbdir)
# What timezone should be the installed default (e.g., US/Eastern).
# Run `make -C time echo-zonenames' to see a list of available zone names.
Modified: trunk/libc/Makefile
==============================================================================
--- trunk/libc/Makefile (original)
+++ trunk/libc/Makefile Tue Jun 21 08:37:38 2011
@@ -147,10 +147,16 @@
lib: $(common-objpfx)linkobj/libc.so
-$(common-objpfx)linkobj/libc.so: $(elfobjdir)/soinit.os $(common-objpfx)linkobj/libc_pic.a $(elfobjdir)/sofini.os $(elfobjdir)/interp.os $(elfobjdir)/ld.so $(common-objpfx)shlib.lds $(common-objpfx)elf/ld.so
+$(common-objpfx)linkobj/libc.so: $(elfobjdir)/soinit.os \
+ $(common-objpfx)linkobj/libc_pic.a \
+ $(elfobjdir)/sofini.os \
+ $(elfobjdir)/interp.os \
+ $(elfobjdir)/ld.so \
+ $(common-objpfx)shlib.lds
$(build-shlib)
-$(common-objpfx)linkobj/libc_pic.a: $(common-objpfx)libc_pic.a $(common-objpfx)sunrpc/librpc_compat_pic.a
+$(common-objpfx)linkobj/libc_pic.a: $(common-objpfx)libc_pic.a \
+ $(common-objpfx)sunrpc/librpc_compat_pic.a
$(..)./scripts/mkinstalldirs $(common-objpfx)linkobj
(cd $(common-objpfx)linkobj; \
$(AR) x ../libc_pic.a; \
Modified: trunk/libc/Makerules
==============================================================================
--- trunk/libc/Makerules (original)
+++ trunk/libc/Makerules Tue Jun 21 08:37:38 2011
@@ -532,6 +532,7 @@
__libc_thread_subfreeres : { *(__libc_thread_subfreeres) }\
PROVIDE(__stop___libc_thread_subfreeres = .);\
/DISCARD/ : { *(.gnu.glibc-stub.*) }@'
+ test -s $@T
mv -f $@T $@
common-generated += shlib.lds
Modified: trunk/libc/NEWS
==============================================================================
--- trunk/libc/NEWS (original)
+++ trunk/libc/NEWS Tue Jun 21 08:37:38 2011
@@ -1,9 +1,18 @@
-GNU C Library NEWS -- history of user-visible changes. 2011-6-4
+GNU C Library NEWS -- history of user-visible changes. 2011-6-15
Copyright (C) 1992-2009, 2010, 2011 Free Software Foundation, Inc.
See the end for copying conditions.
Please send GNU C library bug reports via <http://sources.redhat.com/bugzilla/>
using `glibc' in the "product" field.
+
+Version 2.15
+
+* New program pldd to list loaded object of a process
+ Implemented by Ulrich Drepper.
+
+* Add nss_db support back to glibc. No more dependency on Berkeley db
+ and support for initgroups lookups.
+ Implemented by Ulrich Drepper.
Version 2.14
Modified: trunk/libc/Versions.def
==============================================================================
--- trunk/libc/Versions.def (original)
+++ trunk/libc/Versions.def Tue Jun 21 08:37:38 2011
@@ -65,6 +65,9 @@
GLIBC_PRIVATE
}
libnss_dns {
+ GLIBC_PRIVATE
+}
+libnss_db {
GLIBC_PRIVATE
}
libnss_files {
Modified: trunk/libc/catgets/gencat.c
==============================================================================
--- trunk/libc/catgets/gencat.c (original)
+++ trunk/libc/catgets/gencat.c Tue Jun 21 08:37:38 2011
@@ -470,7 +470,6 @@
else if (strncmp (&this_line[1], "delset", 6) == 0)
{
int cnt = sizeof ("delset");
- size_t set_number;
while (isspace (this_line[cnt]))
++cnt;
@@ -492,11 +491,8 @@
++cnt;
if (cnt == start)
- {
- error_at_line (0, 0, fname, start_line,
- gettext ("illegal set number"));
- set_number = 0;
- }
+ error_at_line (0, 0, fname, start_line,
+ gettext ("illegal set number"));
else
{
const char *symbol;
@@ -509,7 +505,6 @@
/* We have a symbolic set name. This name must
appear somewhere else in the catalogs read so
far. */
- set_number = 0;
for (runp = current->all_sets; runp != NULL;
runp = runp->next)
{
@@ -660,12 +655,10 @@
else if (ident[0] != '\0')
{
struct message_list *runp;
- struct message_list *lastp;
/* Test whether the symbolic name was not used for
another message in this message set. */
runp = current->current_set->messages;
- lastp = NULL;
while (runp != NULL)
if (runp->symbol != NULL && strcmp (ident, runp->symbol) == 0)
break;
Modified: trunk/libc/configure
==============================================================================
--- trunk/libc/configure (original)
+++ trunk/libc/configure Tue Jun 21 08:37:38 2011
@@ -3896,10 +3896,22 @@
CFLAGS="$CFLAGS $nss_includes"
cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
typedef int PRBool;
#include <hasht.h>
#include <nsslowhash.h>
void f (void) { NSSLOW_Init (); }
+int
+main ()
+{
+
+ ;
+ return 0;
+}
_ACEOF
rm -f conftest.$ac_objext
if { (ac_try="$ac_compile"
Modified: trunk/libc/configure.in
==============================================================================
--- trunk/libc/configure.in (original)
+++ trunk/libc/configure.in Tue Jun 21 08:37:38 2011
@@ -298,10 +298,10 @@
fi
old_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $nss_includes"
- AC_COMPILE_IFELSE([typedef int PRBool;
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([typedef int PRBool;
#include <hasht.h>
#include <nsslowhash.h>
-void f (void) { NSSLOW_Init (); }],
+void f (void) { NSSLOW_Init (); }])],
libc_cv_nss_crypt=yes,
AC_MSG_ERROR([
cannot find NSS headers with lowlevel hash function interfaces]))
Modified: trunk/libc/elf/Makefile
==============================================================================
--- trunk/libc/elf/Makefile (original)
+++ trunk/libc/elf/Makefile Tue Jun 21 08:37:38 2011
@@ -150,8 +150,8 @@
install-bin-script = ldd
endif
-others = sprof sln
-install-bin = sprof
+others = sprof sln pldd
+install-bin = sprof pldd
others-static = sln
install-rootsbin = sln
@@ -163,6 +163,8 @@
ldconfig-modules := cache readlib xmalloc xstrdup chroot_canon
extra-objs += $(ldconfig-modules:=.o)
+
+pldd-modules := xmalloc
# To find xmalloc.c and xstrdup.c
vpath %.c ../locale/programs
@@ -415,6 +417,7 @@
sed -e '/^=========/,/^=========/!d;/^=========/d' \
-e 's/\. = .* + SIZEOF_HEADERS;/& _begin = . - SIZEOF_HEADERS;/' \
> $@.lds
+ test -s $@.lds
$(LINK.o) -nostdlib -nostartfiles -shared -o $@ \
$(LDFLAGS-rtld) -Wl,-z,defs $(z-now-$(bind-now)) \
$(filter-out $(map-file),$^) $(load-map-file) \
@@ -500,6 +503,9 @@
$(objpfx)sprof: $(libdl)
$(objpfx)ldconfig: $(ldconfig-modules:%=$(objpfx)%.o)
+
+$(objpfx)pldd: $(pldd-modules:%=$(objpfx)%.o)
+
SYSCONF-FLAGS := -D'SYSCONFDIR="$(sysconfdir)"'
CFLAGS-ldconfig.c = $(SYSCONF-FLAGS) -D'LIBDIR="$(libdir)"' \
-D'SLIBDIR="$(slibdir)"' -DIS_IN_ldconfig=1
Modified: trunk/libc/elf/dl-open.c
==============================================================================
--- trunk/libc/elf/dl-open.c (original)
+++ trunk/libc/elf/dl-open.c Tue Jun 21 08:37:38 2011
@@ -516,7 +516,7 @@
if (__builtin_expect (nsid == LM_ID_NEWLM, 0))
{
/* Find a new namespace. */
- for (nsid = 1; nsid < GL(dl_nns); ++nsid)
+ for (nsid = 1; DL_NNS > 1 && nsid < GL(dl_nns); ++nsid)
if (GL(dl_ns)[nsid]._ns_loaded == NULL)
break;
@@ -528,8 +528,7 @@
_dl_signal_error (EINVAL, file, NULL, N_("\
no more namespaces available for dlmopen()"));
}
-
- if (nsid == GL(dl_nns))
+ else if (nsid == GL(dl_nns))
{
__rtld_lock_initialize (GL(dl_ns)[nsid]._ns_unique_sym_table.lock);
++GL(dl_nns);
Modified: trunk/libc/elf/dl-runtime.c
==============================================================================
--- trunk/libc/elf/dl-runtime.c (original)
+++ trunk/libc/elf/dl-runtime.c Tue Jun 21 08:37:38 2011
@@ -27,6 +27,7 @@
#include <sysdep-cancel.h>
#include "dynamic-link.h"
#include <tls.h>
+#include <dl-irel.h>
#if (!defined ELF_MACHINE_NO_RELA && !defined ELF_MACHINE_PLT_REL) \
@@ -146,7 +147,7 @@
if (sym != NULL
&& __builtin_expect (ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC, 0))
- value = ((DL_FIXUP_VALUE_TYPE (*) (void)) DL_FIXUP_VALUE_ADDR (value)) ();
+ value = elf_ifunc_invoke (DL_FIXUP_VALUE_ADDR (value));
/* Finally, fix up the plt itself. */
if (__builtin_expect (GLRO(dl_bind_not), 0))
@@ -235,8 +236,7 @@
if (defsym != NULL
&& __builtin_expect (ELFW(ST_TYPE) (defsym->st_info)
== STT_GNU_IFUNC, 0))
- value = ((DL_FIXUP_VALUE_TYPE (*) (void))
- DL_FIXUP_VALUE_ADDR (value)) ();
+ value = elf_ifunc_invoke (DL_FIXUP_VALUE_ADDR (value));
}
else
{
@@ -246,8 +246,7 @@
if (__builtin_expect (ELFW(ST_TYPE) (refsym->st_info)
== STT_GNU_IFUNC, 0))
- value = ((DL_FIXUP_VALUE_TYPE (*) (void))
- DL_FIXUP_VALUE_ADDR (value)) ();
+ value = elf_ifunc_invoke (DL_FIXUP_VALUE_ADDR (value));
result = l;
}
Modified: trunk/libc/elf/dl-sym.c
==============================================================================
--- trunk/libc/elf/dl-sym.c (original)
+++ trunk/libc/elf/dl-sym.c Tue Jun 21 08:37:38 2011
@@ -27,6 +27,7 @@
#include <dl-hash.h>
#include <sysdep-cancel.h>
#include <dl-tls.h>
+#include <dl-irel.h>
#ifdef SHARED
@@ -196,8 +197,7 @@
{
DL_FIXUP_VALUE_TYPE fixup
= DL_FIXUP_MAKE_VALUE (result, (ElfW(Addr)) value);
- fixup =
- ((DL_FIXUP_VALUE_TYPE (*) (void)) DL_FIXUP_VALUE_ADDR (fixup)) ();
+ fixup = elf_ifunc_invoke (DL_FIXUP_VALUE_ADDR (fixup));
value = (void *) DL_FIXUP_VALUE_CODE_ADDR (fixup);
}
Copied: trunk/libc/elf/pldd.c (from r14282, fsf/trunk/libc/elf/pldd.c)
==============================================================================
--- fsf/trunk/libc/elf/pldd.c (original)
+++ trunk/libc/elf/pldd.c Tue Jun 21 08:37:38 2011
@@ -52,7 +52,7 @@
/* Bug report address. */
const char *argp_program_bug_address = N_("\
For bug reporting instructions, please see:\n\
-<http://www.gnu.org/software/libc/bugs.html>.\n");
+" REPORT_BUGS_TO ".\n");
/* Definitions of arguments for argp functions. */
static const struct argp_option options[] =
@@ -150,7 +150,7 @@
static void
print_version (FILE *stream, struct argp_state *state)
{
- fprintf (stream, "pldd (GNU %s) %s\n", PACKAGE, VERSION);
+ fprintf (stream, "pldd %s%s\n", PKGVERSION, VERSION);
fprintf (stream, gettext ("\
Copyright (C) %s Free Software Foundation, Inc.\n\
This is free software; see the source for copying conditions. There is NO\n\
Modified: trunk/libc/grp/initgroups.c
==============================================================================
--- trunk/libc/grp/initgroups.c (original)
+++ trunk/libc/grp/initgroups.c Tue Jun 21 08:37:38 2011
@@ -44,7 +44,7 @@
extern void *__nss_lookup_function (service_user *ni, const char *fct_name);
extern service_user *__nss_group_database attribute_hidden;
-static service_user *initgroups_database;
+service_user *__nss_initgroups_database;
static bool use_initgroups_entry;
@@ -80,26 +80,31 @@
/* Start is one, because we have the first group as parameter. */
long int start = 1;
- if (initgroups_database == NULL)
+ if (__nss_initgroups_database == NULL)
{
no_more = __nss_database_lookup ("initgroups", NULL, "",
- &initgroups_database);
- if (no_more == 0 && initgroups_database == NULL)
+ &__nss_initgroups_database);
+ if (no_more == 0 && __nss_initgroups_database == NULL)
{
if (__nss_group_database == NULL)
no_more = __nss_database_lookup ("group", NULL, "compat files",
&__nss_group_database);
- initgroups_database = __nss_group_database;
+ __nss_initgroups_database = __nss_group_database;
}
- else if (initgroups_database != NULL)
+ else if (__nss_initgroups_database != NULL)
{
assert (no_more == 0);
use_initgroups_entry = true;
}
}
-
- service_user *nip = initgroups_database;
+ else
+ /* __nss_initgroups_database might have been set through
+ __nss_configure_lookup in which case use_initgroups_entry was
+ not set here. */
+ use_initgroups_entry = __nss_initgroups_database != __nss_group_database;
+
+ service_user *nip = __nss_initgroups_database;
while (! no_more)
{
long int prev_start = start;
Modified: trunk/libc/inet/getnetgrent_r.c
==============================================================================
--- trunk/libc/inet/getnetgrent_r.c (original)
+++ trunk/libc/inet/getnetgrent_r.c Tue Jun 21 08:37:38 2011
@@ -1,5 +1,5 @@
-/* Copyright (C) 1996, 1997, 1998, 1999, 2002, 2004, 2005, 2007
- Free Software Foundation, Inc.
+/* Copyright (C) 1996,1997,1998,1999,2002,2004,2005,2007,2011
+ 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
@@ -347,7 +347,6 @@
struct __netgrent entry;
int result = 0;
const char *current_group = netgroup;
- int real_entry = 0;
memset (&entry, '\0', sizeof (entry));
@@ -404,8 +403,6 @@
}
else
{
- real_entry = 1;
-
if ((entry.val.triple.host == NULL || host == NULL
|| __strcasecmp (entry.val.triple.host, host) == 0)
&& (entry.val.triple.user == NULL || user == NULL
Modified: trunk/libc/io/fts.c
==============================================================================
--- trunk/libc/io/fts.c (original)
+++ trunk/libc/io/fts.c Tue Jun 21 08:37:38 2011
@@ -748,20 +748,17 @@
p->fts_flags |= FTS_ISW;
#endif
-#if 0
/* Unreachable code. cderrno is only ever set to a nonnull
value if dirp is closed at the same time. But then we
cannot enter this loop. */
- if (cderrno) {
+ if (0 && cderrno) {
if (nlinks) {
p->fts_info = FTS_NS;
p->fts_errno = cderrno;
} else
p->fts_info = FTS_NSOK;
p->fts_accpath = cur->fts_accpath;
- } else
-#endif
- if (nlinks == 0
+ } else if (nlinks == 0
#if defined DT_DIR && defined _DIRENT_HAVE_D_TYPE
|| (nostat &&
dp->d_type != DT_DIR && dp->d_type != DT_UNKNOWN)
Modified: trunk/libc/locale/programs/ld-collate.c
==============================================================================
--- trunk/libc/locale/programs/ld-collate.c (original)
+++ trunk/libc/locale/programs/ld-collate.c Tue Jun 21 08:37:38 2011
@@ -1992,7 +1992,6 @@
{
/* As for the singlebyte table, we recognize sequences and
compress them. */
- struct element_t *lastp;
collidx_table_add (atwc.tablewc, ch,
-(obstack_object_size (atwc.extrapool)
@@ -2092,7 +2091,6 @@
}
/* Next entry. */
- lastp = runp;
runp = runp->wcnext;
}
while (runp != NULL);
Modified: trunk/libc/locale/programs/ld-ctype.c
==============================================================================
--- trunk/libc/locale/programs/ld-ctype.c (original)
+++ trunk/libc/locale/programs/ld-ctype.c Tue Jun 21 08:37:38 2011
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995-2006, 2007, 2009 Free Software Foundation, Inc.
+/* Copyright (C) 1995-2006,2007,2009,2011 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@xxxxxxx>, 1995.
@@ -2112,7 +2112,6 @@
struct token *now;
enum token_t nowtok;
size_t cnt;
- struct charseq *last_seq;
uint32_t last_wch = 0;
enum token_t last_token;
enum token_t ellipsis_token;
@@ -2368,7 +2367,6 @@
}
else
last_str = NULL;
- last_seq = seq;
last_wch = wch;
memcpy (last_charcode, now->val.charcode.bytes, 16);
last_charcode_len = now->val.charcode.nbytes;
Modified: trunk/libc/locale/programs/locarchive.c
==============================================================================
--- trunk/libc/locale/programs/locarchive.c (original)
+++ trunk/libc/locale/programs/locarchive.c Tue Jun 21 08:37:38 2011
@@ -300,7 +300,6 @@
void *p;
unsigned int cnt, loccnt;
struct namehashent *oldnamehashtab;
- struct locrecent *oldlocrectab;
struct locarhandle new_ah;
struct oldlocrecent *oldlocrecarray;
size_t prefix_len = output_prefix ? strlen (output_prefix) : 0;
@@ -432,8 +431,6 @@
still referenced and transfer it into the new file. */
oldnamehashtab = (struct namehashent *) ((char *) ah->addr
+ head->namehash_offset);
- oldlocrectab = (struct locrecent *) ((char *) ah->addr
- + head->locrectab_offset);
/* Sort the old locrec table in order of data position. */
oldlocrecarray = alloca (sizeof (*oldlocrecarray) * head->namehash_size);
Modified: trunk/libc/misc/syslog.c
==============================================================================
--- trunk/libc/misc/syslog.c (original)
+++ trunk/libc/misc/syslog.c Tue Jun 21 08:37:38 2011
@@ -141,7 +141,7 @@
FILE *f;
char *buf = 0;
size_t bufsize = 0;
- size_t prioff, msgoff;
+ size_t msgoff;
#ifndef NO_SIGPIPE
struct sigaction action, oldaction;
int sigpipe;
@@ -192,7 +192,7 @@
else
{
__fsetlocking (f, FSETLOCKING_BYCALLER);
- prioff = fprintf (f, "<%d>", pri);
+ fprintf (f, "<%d>", pri);
(void) time (&now);
f->_IO_write_ptr += __strftime_l (f->_IO_write_ptr,
f->_IO_write_end
Modified: trunk/libc/nis/nis_print_group_entry.c
==============================================================================
--- trunk/libc/nis/nis_print_group_entry.c (original)
+++ trunk/libc/nis/nis_print_group_entry.c Tue Jun 21 08:37:38 2011
@@ -1,4 +1,5 @@
-/* Copyright (c) 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
+/* Copyright (c) 1997,1998,2000,2004,2006,2011
+ Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@xxxxxxxxxxxxxxxxxxx>, 1997.
@@ -156,7 +157,7 @@
{
fputs (_(" Implicit nonmembers:\n"), stdout);
for (i = 0; i < nomem_imp_cnt; ++i)
- printf ("\t%s\n", &mem_imp[i][3]);
+ printf ("\t%s\n", &nomem_imp[i][3]);
}
else
fputs (_(" No implicit nonmembers\n"), stdout);
Modified: trunk/libc/nis/nss_compat/compat-pwd.c
==============================================================================
--- trunk/libc/nis/nss_compat/compat-pwd.c (original)
+++ trunk/libc/nis/nss_compat/compat-pwd.c Tue Jun 21 08:37:38 2011
@@ -1,4 +1,5 @@
-/* Copyright (C) 1996-1999, 2001-2006, 2007 Free Software Foundation, Inc.
+/* Copyright (C) 1996-1999,2001-2006,2007,2011
+ Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@xxxxxxxxxxxxxxxxxxx>, 1996.
@@ -386,9 +387,6 @@
while (1)
{
- char *saved_cursor;
-
- saved_cursor = ent->netgrdata.cursor;
status = __internal_getnetgrent_r (&host, &user, &domain,
&ent->netgrdata, buffer, buflen,
errnop);
Modified: trunk/libc/nis/nss_compat/compat-spwd.c
==============================================================================
--- trunk/libc/nis/nss_compat/compat-spwd.c (original)
+++ trunk/libc/nis/nss_compat/compat-spwd.c Tue Jun 21 08:37:38 2011
@@ -1,4 +1,5 @@
-/* Copyright (C) 1996-1999, 2001-2006, 2007 Free Software Foundation, Inc.
+/* Copyright (C) 1996-1999,2001-2006,2007,2011
+ Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@xxxxxxxxxxxxxxxxxxx>, 1996.
@@ -344,10 +345,8 @@
while (1)
{
- char *saved_cursor;
enum nss_status status;
- saved_cursor = ent->netgrdata.cursor;
status = __internal_getnetgrent_r (&host, &user, &domain,
&ent->netgrdata, buffer, buflen,
errnop);
Modified: trunk/libc/nptl/ChangeLog
==============================================================================
--- trunk/libc/nptl/ChangeLog (original)
+++ trunk/libc/nptl/ChangeLog Tue Jun 21 08:37:38 2011
@@ -1,3 +1,7 @@
+2011-06-14 Andreas Jaeger <aj@xxxxxxx>
+
+ * pthread_rwlock_init.c: Include <string.h> for memset declaration.
+
2011-05-11 Ulrich Drepper <drepper@xxxxxxxxx>
[BZ #386]
Modified: trunk/libc/nptl/pthread_rwlock_init.c
==============================================================================
--- trunk/libc/nptl/pthread_rwlock_init.c (original)
+++ trunk/libc/nptl/pthread_rwlock_init.c Tue Jun 21 08:37:38 2011
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002, 2007, 2009 Free Software Foundation, Inc.
+/* Copyright (C) 2002,2007,2009,2011 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@xxxxxxxxxx>, 2002.
@@ -18,6 +18,7 @@
02111-1307 USA. */
#include "pthreadP.h"
+#include <string.h>
#include <kernel-features.h>
Modified: trunk/libc/nscd/hstcache.c
==============================================================================
--- trunk/libc/nscd/hstcache.c (original)
+++ trunk/libc/nscd/hstcache.c Tue Jun 21 08:37:38 2011
@@ -190,7 +190,6 @@
size_t h_aliases_cnt;
uint32_t *h_aliases_len;
size_t h_addr_list_cnt;
- int addr_list_type;
char *addresses;
char *aliases;
char *key_copy = NULL;
@@ -409,9 +408,6 @@
+ total + req->key_len, MS_ASYNC);
}
- addr_list_type = (hst->h_length == NS_INADDRSZ
- ? GETHOSTBYADDR : GETHOSTBYADDRv6);
-
/* NB: the following code is really complicated. It has
seemlingly duplicated code paths which do the same. The
problem is that we always must add the hash table entry
Modified: trunk/libc/nss/Makefile
==============================================================================
--- trunk/libc/nss/Makefile (original)
+++ trunk/libc/nss/Makefile Tue Jun 21 08:37:38 2011
@@ -44,8 +44,10 @@
$(addsuffix -lookup,$(databases-y))
routines-$(OPTION_EGLIBC_INET) += digits_dots
-others := getent
-install-bin := getent
+others := getent makedb
+install-bin := getent makedb
+makedb-modules = xmalloc hash-string
+extra-objs += $(makedb-modules:=.o)
tests = tst-nss-test1
tests-$(OPTION_EGLIBC_INET) += test-netdb
@@ -59,7 +61,7 @@
endif
# Specify rules for the nss_* modules. We have some services.
-services := files
+services := files db
extra-libs = $(services:%=libnss_%)
# These libraries will be built in the `others' pass rather than
@@ -68,17 +70,28 @@
# The sources are found in the appropriate subdir.
subdir-dirs = $(services:%=nss_%)
-vpath %.c $(subdir-dirs)
+vpath %.c $(subdir-dirs) ../locale/programs ../intl
libnss_files-routines := $(addprefix files-,$(databases-y)) \
files-initgroups files-have_o_cloexec
distribute += files-XXX.c files-parse.c
+libnss_db-dbs := $(addprefix db-,\
+ $(filter-out hosts network key alias,\
+ $(databases))) \
+ db-initgroups
+libnss_db-routines := $(libnss_db-dbs) db-open hash-string
+generated += $(filter-out db-alias.c db-netgrp.c, \
+ $(addsuffix .c,$(libnss_db-dbs)))
+distribute += $(addprefix nss_db/, db-XXX.c nss_db.h)
+
+install-others += $(inst_vardbdir)/Makefile
# Build static module if requested
ifneq ($(build-static-nss),yes)
libnss_files-inhibit-o = $(filter-out .os,$(object-suffixes))
+libnss_db-inhibit-o = $(filter-out .os,$(object-suffixes))
endif
ifneq ($(OPTION_EGLIBC_NSSWITCH),y)
@@ -127,6 +140,10 @@
$(objpfx)getent: $(objpfx)libnss_files.a
endif
+ifeq (yes,$(have-selinux))
+LDLIBS-makedb := -lselinux
+endif
+
# Depend on libc.so so a DT_NEEDED is generated in the shared objects.
# This ensures they will load libc.so for needed symbols if loaded by
# a statically-linked program that hasn't already loaded it.
@@ -134,6 +151,20 @@
$(services:%=$(objpfx)libnss_%.so): $(libnss-libc) \
$(common-objpfx)libc_nonshared.a
+$(objpfx)libnss_db.so: $(objpfx)libnss_files.so
+
+$(libnss_db-dbs:%=$(objpfx)%.c): $(objpfx)db-%.c: nss_files/files-%.c
+ @rm -f $@.new
+ (echo '#define EXTERN_PARSER';\
+ echo '#define GENERIC "../nss_db/db-XXX.c"';\
+ echo '#include "$<"') > $@.new
+ mv -f $@.new $@
+
+
+$(objpfx)makedb: $(makedb-modules:%=$(objpfx)%.o)
+
+$(inst_vardbdir)/Makefile: db-Makefile $(+force)
+ $(do-install)
distribute += nss_test1.c
Modified: trunk/libc/nss/Versions
==============================================================================
--- trunk/libc/nss/Versions (original)
+++ trunk/libc/nss/Versions Tue Jun 21 08:37:38 2011
@@ -27,6 +27,8 @@
_nss_files_endetherent;
_nss_files_getetherent_r;
_nss_files_parse_etherent;
+ _nss_files_gethostton_r;
+ _nss_files_getntohost_r;
_nss_files_setgrent;
_nss_files_endgrent;
@@ -41,14 +43,12 @@
_nss_files_gethostbyname4_r;
_nss_files_gethostbyname_r;
_nss_files_gethostent_r;
- _nss_files_gethostton_r;
_nss_files_setnetent;
_nss_files_endnetent;
_nss_files_getnetbyaddr_r;
_nss_files_getnetbyname_r;
_nss_files_getnetent_r;
- _nss_files_getntohost_r;
_nss_files_parse_netent;
_nss_files_setnetgrent;
@@ -99,3 +99,59 @@
_nss_files_initgroups_dyn;
}
}
+
+libnss_db {
+ GLIBC_PRIVATE {
+ _nss_db_setetherent;
+ _nss_db_endetherent;
+ _nss_db_getetherent_r;
+ _nss_db_gethostton_r;
+ _nss_db_getntohost_r;
+
+ _nss_db_setgrent;
+ _nss_db_endgrent;
+ _nss_db_getgrent_r;
+ _nss_db_getgrgid_r;
+ _nss_db_getgrnam_r;
+
+ _nss_db_setnetgrent;
+ _nss_db_endnetgrent;
+ _nss_db_getnetgrent_r;
+
+ _nss_db_setprotoent;
+ _nss_db_endprotoent;
+ _nss_db_getprotoent_r;
+ _nss_db_getprotobyname_r;
+ _nss_db_getprotobynumber_r;
+
+ _nss_db_setpwent;
+ _nss_db_endpwent;
+ _nss_db_getpwent_r;
+ _nss_db_getpwnam_r;
+ _nss_db_getpwuid_r;
+
+ _nss_db_setrpcent;
+ _nss_db_endrpcent;
+ _nss_db_getrpcent_r;
+ _nss_db_getrpcbyname_r;
+ _nss_db_getrpcbynumber_r;
+
+ _nss_db_setservent;
+ _nss_db_endservent;
+ _nss_db_getservent_r;
+ _nss_db_getservbyname_r;
+ _nss_db_getservbyport_r;
+
+ _nss_db_setsgent;
+ _nss_db_endsgent;
+ _nss_db_getsgent_r;
+ _nss_db_getsgnam_r;
+
+ _nss_db_setspent;
+ _nss_db_endspent;
+ _nss_db_getspent_r;
+ _nss_db_getspnam_r;
+
+ _nss_db_initgroups_dyn;
+ }
+}
Modified: trunk/libc/nss/databases.def
==============================================================================
--- trunk/libc/nss/databases.def (original)
+++ trunk/libc/nss/databases.def Tue Jun 21 08:37:38 2011
@@ -1,5 +1,5 @@
/* List of all databases defined for the NSS in GNU C Library.
- Copyright (C) 1996, 1997, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1996, 1997, 2005, 2011 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@xxxxxxxxxx>, 1996.
@@ -25,6 +25,7 @@
DEFINE_DATABASE (ethers)
DEFINE_DATABASE (group)
DEFINE_DATABASE (hosts)
+DEFINE_DATABASE (initgroups)
DEFINE_DATABASE (netgroup)
DEFINE_DATABASE (networks)
DEFINE_DATABASE (passwd)
Modified: trunk/libc/nss/db-Makefile
==============================================================================
--- trunk/libc/nss/db-Makefile (original)
+++ trunk/libc/nss/db-Makefile Tue Jun 21 08:37:38 2011
@@ -1,5 +1,5 @@
# Makefile to (re-)generate db versions of system database files.
-# Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
+# Copyright (C) 1996, 1997, 1998, 2011 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# Contributed by Ulrich Drepper <drepper@xxxxxxxxxx>, 1996.
#
@@ -20,7 +20,8 @@
# 02111-1307 USA.
DATABASES = $(wildcard /etc/passwd /etc/group /etc/ethers /etc/protocols \
- /etc/rpc /etc/services /etc/shadow /etc/netgroup)
+ /etc/rpc /etc/services /etc/shadow /etc/gshadow \
+ /etc/netgroup)
VAR_DB = /var/db
@@ -32,10 +33,9 @@
$(VAR_DB)/passwd.db: /etc/passwd
@echo -n "$(patsubst %.db,%,$(@F))... "
- @$(AWK) 'BEGIN { FS=":"; OFS=":"; cnt=0 } \
+ @$(AWK) 'BEGIN { FS=":"; OFS=":" } \
/^[ \t]*$$/ { next } \
/^[ \t]*#/ { next } \
- { printf "0%u ", cnt++; print } \
/^[^#]/ { printf ".%s ", $$1; print; \
printf "=%s ", $$3; print }' $^ | \
$(MAKEDB) -o $@ -
@@ -43,21 +43,30 @@
$(VAR_DB)/group.db: /etc/group
@echo -n "$(patsubst %.db,%,$(@F))... "
- @$(AWK) 'BEGIN { FS=":"; OFS=":"; cnt=0 } \
+ @$(AWK) 'BEGIN { FS=":"; OFS=":" } \
/^[ \t]*$$/ { next } \
/^[ \t]*#/ { next } \
- { printf "0%u ", cnt++; print } \
/^[^#]/ { printf ".%s ", $$1; print; \
- printf "=%s ", $$3; print }' $^ | \
+ printf "=%s ", $$3; print; \
+ if ($$4 != "") { \
+ split($$4, grmems, ","); \
+ for (memidx in grmems) { \
+ mem=grmems[memidx]; \
+ if (members[mem] == "") \
+ members[mem]=$$3; \
+ else \
+ members[mem]=members[mem] "," $$3; \
+ } \
+ delete grmems; } } \
+ END { for (mem in members) \
+ printf ":%s $s %s\n", mem, mem, members[mem]; }' $^ | \
$(MAKEDB) -o $@ -
@echo "done."
$(VAR_DB)/ethers.db: /etc/ethers
@echo -n "$(patsubst %.db,%,$(@F))... "
- @$(AWK) 'BEGIN { cnt=0 } \
- /^[ \t]*$$/ { next } \
+ @$(AWK) '/^[ \t]*$$/ { next } \
/^[ \t]*#/ { next } \
- { printf "0%u ", cnt++; print } \
/^[^#]/ { printf ".%s ", $$1; print; \
printf "=%s ", $$2; print }' $^ | \
$(MAKEDB) -o $@ -
@@ -65,10 +74,8 @@
$(VAR_DB)/protocols.db: /etc/protocols
@echo -n "$(patsubst %.db,%,$(@F))... "
- @$(AWK) 'BEGIN { cnt=0 } \
- /^[ \t]*$$/ { next } \
+ @$(AWK) '/^[ \t]*$$/ { next } \
/^[ \t]*#/ { next } \
- { printf "0%u ", cnt++; print } \
/^[^#]/ { printf ".%s ", $$1; print; \
printf "=%s ", $$2; print; \
for (i = 3; i <= NF && !($$i ~ /^#/); ++i) \
@@ -78,10 +85,8 @@
$(VAR_DB)/rpc.db: /etc/rpc
@echo -n "$(patsubst %.db,%,$(@F))... "
- @$(AWK) 'BEGIN { cnt=0 } \
- /^[ \t]*$$/ { next } \
+ @$(AWK) '/^[ \t]*$$/ { next } \
/^[ \t]*#/ { next } \
- { printf "0%u ", cnt++; print } \
/^[^#]/ { printf ".%s ", $$1; print; \
printf "=%s ", $$2; print; \
for (i = 3; i <= NF && !($$i ~ /^#/); ++i) \
@@ -91,26 +96,25 @@
$(VAR_DB)/services.db: /etc/services
@echo -n "$(patsubst %.db,%,$(@F))... "
- @$(AWK) 'BEGIN { FS="[ \t/]+"; cnt=0 } \
+ @$(AWK) 'BEGIN { FS="[ \t/]+" } \
/^[ \t]*$$/ { next } \
/^[ \t]*#/ { next } \
- { printf "0%u ", cnt++; print } \
- /^[^#]/ { printf ".%s/%s ", $$1, $$3; print; \
- printf ".%s/ ", $$1; print; \
+ /^[^#]/ { sub(/[ \t]*#.*$$/, "");\
+ printf ":%s/%s ", $$1, $$3; print; \
+ printf ":%s/ ", $$1; print; \
printf "=%s/%s ", $$2, $$3; print; \
printf "=%s/ ", $$2; print; \
for (i = 4; i <= NF && !($$i ~ /^#/); ++i) \
- { printf ".%s/%s ", $$i, $$3; print; \
- printf ".%s/ ", $$i; print } }' $^ | \
+ { printf ":%s/%s ", $$i, $$3; print; \
+ printf ":%s/ ", $$i; print } }' $^ | \
$(MAKEDB) -o $@ -
@echo "done."
$(VAR_DB)/shadow.db: /etc/shadow
@echo -n "$(patsubst %.db,%,$(@F))... "
- @$(AWK) 'BEGIN { FS=":"; OFS=":"; cnt=0 } \
+ @$(AWK) 'BEGIN { FS=":"; OFS=":" } \
/^[ \t]*$$/ { next } \
/^[ \t]*#/ { next } \
- { printf "0%u ", cnt++; print } \
/^[^#]/ { printf ".%s ", $$1; print }' $^ | \
(umask 077 && $(MAKEDB) -o $@ -)
@echo "done."
@@ -126,14 +130,38 @@
echo; \
fi
+$(VAR_DB)/gshadow.db: /etc/gshadow
+ @echo -n "$(patsubst %.db,%,$(@F))... "
+ @$(AWK) 'BEGIN { FS=":"; OFS=":" } \
+ /^[ \t]*$$/ { next } \
+ /^[ \t]*#/ { next } \
+ /^[^#]/ { printf ".%s ", $$1; print }' $^ | \
+ (umask 077 && $(MAKEDB) -o $@ -)
+ @echo "done."
+ @if chgrp shadow $@ 2>/dev/null; then \
+ chmod g+r $@; \
+ else \
+ chown 0 $@; chgrp 0 $@; chmod 600 $@; \
+ echo; \
+ echo "Warning: The shadow group database $@"; \
+ echo "has been set to be readable only by root. You may want"; \
+ echo "to make it readable by the \`shadow' group depending"; \
+ echo "on your configuration."; \
+ echo; \
+ fi
+
$(VAR_DB)/netgroup.db: /etc/netgroup
@echo -n "$(patsubst %.db,%,$(@F))... "
- @$(AWK) 'BEGIN { cnt=0 } \
+ @$(AWK) 'BEGIN { ini=1 } \
/^[ \t]*$$/ { next } \
/^[ \t]*#/ { next } \
- { printf "0%u ", cnt++; print } \
- /^[^#]/ { end=sub(/\\/, " "); \
+ /^[^#]/ { if (sub(/[ \t]*\\$$/, " ") == 0) end="\n"; \
+ else end=""; \
gsub(/[ \t]+/, " "); \
- if(end == 1) printf "%s", $$0; else print }' $^ | \
+ sub(/^[ \t]*/, ""); \
+ if (ini == 0) printf "%s%s", $$0, end; \
+ else printf ".%s %s%s", $$1, $$0, end; \
+ ini=end == "" ? 0 : 1; } \
+ END { if (ini==0) printf "\n" }' $^ | \
$(MAKEDB) -o $@ -
@echo "done."
Modified: trunk/libc/nss/getent.c
==============================================================================
--- trunk/libc/nss/getent.c (original)
+++ trunk/libc/nss/getent.c Tue Jun 21 08:37:38 2011
@@ -507,6 +507,38 @@
return result;
}
+/* This is for initgroups */
+static int
+initgroups_keys (int number, char *key[])
+{
+ int ngrps = 100;
+ size_t grpslen = ngrps * sizeof (gid_t);
+ gid_t *grps = alloca (grpslen);
+
+ for (int i = 0; i < number; ++i)
+ {
+ int no = ngrps;
+ int n;
+ while ((n = getgrouplist (key[i], -1, grps, &no)) == -1
+ && no > ngrps)
+ {
+ grps = extend_alloca (grps, grpslen, no * sizeof (gid_t));
+ ngrps = no;
+ }
+
+ if (n == -1)
+ return 1;
+
+ printf ("%-21s", key[i]);
+ for (int j = 0; j < n; ++j)
+ if (grps[j] != -1)
+ printf (" %ld", (long int) grps[j]);
+ putchar_unlocked ('\n');
+ }
+
+ return 0;
+}
+
/* This is for networks */
static void
print_networks (struct netent *net)
@@ -851,6 +883,7 @@
D(group)
D(gshadow)
DN(hosts)
+D(initgroups)
DN(netgroup)
DN(networks)
D(passwd)
Modified: trunk/libc/nss/makedb.c
==============================================================================
--- trunk/libc/nss/makedb.c (original)
+++ trunk/libc/nss/makedb.c Tue Jun 21 08:37:38 2011
@@ -1,5 +1,5 @@
/* Create simple DB database from textual input.
- Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1996-2000, 2011 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@xxxxxxxxxx>, 1996.
@@ -19,24 +19,76 @@
02111-1307 USA. */
#include <argp.h>
+#include <assert.h>
#include <ctype.h>
-#include <dlfcn.h>
#include <errno.h>
#include <error.h>
#include <fcntl.h>
+#include <inttypes.h>
#include <libintl.h>
#include <locale.h>
+#include <search.h>
#include <stdio.h>
-#include <stdint.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
+#include <sys/mman.h>
#include <sys/stat.h>
-#include "nss_db/dummy-db.h"
+#include "nss_db/nss_db.h"
/* Get libc version number. */
#include "../version.h"
+/* The hashing function we use. */
+#include "../intl/hash-string.h"
+
+/* SELinux support. */
+#ifdef HAVE_SELINUX
+# include <selinux/selinux.h>
+#endif
+
#define PACKAGE _libc_intl_domainname
+
+/* List of data bases. */
+struct database
+{
+ char dbid;
+ bool extra_string;
+ struct database *next;
+ void *entries;
+ size_t nentries;
+ size_t nhashentries;
+ stridx_t *hashtable;
+ size_t keystrlen;
+ stridx_t *keyidxtab;
+ char *keystrtab;
+} *databases;
+static size_t ndatabases;
+static size_t nhashentries_total;
+static size_t valstrlen;
+static void *valstrtree;
+static char *valstrtab;
+static size_t extrastrlen;
+
+/* Database entry. */
+struct dbentry
+{
+ stridx_t validx;
+ uint32_t hashval;
+ char str[0];
+};
+
+/* Stored string entry. */
+struct valstrentry
+{
+ stridx_t idx;
+ bool extra_string;
+ char str[0];
+};
+
+
+/* True if any entry has been added. */
+static bool any_dbentry;
/* If non-zero convert key to lower case. */
static int to_lowercase;
@@ -63,11 +115,13 @@
N_("Do not print messages while building database") },
{ "undo", 'u', NULL, 0,
N_("Print content of database file, one entry a line") },
+ { "generated", 'g', N_("CHAR"), 0,
+ N_("Generated line not part of iteration") },
{ NULL, 0, NULL, 0, NULL }
};
/* Short description of program. */
-static const char doc[] = N_("Create simple DB database from textual input.");
+static const char doc[] = N_("Create simple database from textual input.");
/* Strings for arguments in help texts. */
static const char args_doc[] = N_("\
@@ -86,10 +140,35 @@
};
+/* List of databases which are not part of the iteration table. */
+static struct db_option
+{
+ char dbid;
+ struct db_option *next;
+} *db_options;
+
+
/* Prototypes for local functions. */
-static int process_input (FILE *input, const char *inname, NSS_DB *output,
+static int process_input (FILE *input, const char *inname,
int to_lowercase, int be_quiet);
-static int print_database (NSS_DB *db);
+static int print_database (int fd);
+static void compute_tables (void);
+static int write_output (int fd);
+
+/* SELinux support. */
+#ifdef HAVE_SELINUX
+/* Set the SELinux file creation context for the given file. */
+static void set_file_creation_context (const char *outname, mode_t mode);
+static void reset_file_creation_context (void);
+#else
+# define set_file_creation_context(_outname,_mode)
+# define reset_file_creation_context()
+#endif
+
+
+/* External functions. */
+extern void *xmalloc (size_t n) __attribute_malloc__;
+extern void *xcalloc (size_t n, size_t m) __attribute_malloc__;
int
@@ -97,10 +176,8 @@
{
const char *input_name;
FILE *input_file;
- NSS_DB *db_file;
- int status;
int remaining;
- int mode = 0666;
+ int mode = 0644;
/* Set locale via LC_ALL. */
setlocale (LC_ALL, "");
@@ -136,24 +213,17 @@
output_name = argv[remaining];
}
- /* First load the shared object to initialize version dependend
- variables. */
- if (load_db () != NSS_STATUS_SUCCESS)
- error (EXIT_FAILURE, 0, gettext ("No usable database library found."));
-
/* Special handling if we are asked to print the database. */
if (do_undo)
{
- dbopen (input_name, db_rdonly, 0666, &db_file);
- if (db_file == NULL)
- error (EXIT_FAILURE, 0, gettext ("cannot open database file `%s': %s"),
- input_name,
- (errno == EINVAL ? gettext ("incorrectly formatted file")
- : strerror (errno)));
-
- status = print_database (db_file);
-
- db_file->close (db_file->db, 0);
+ int fd = open (input_name, O_RDONLY);
+ if (fd == -1)
+ error (EXIT_FAILURE, errno, gettext ("cannot open database file `%s'"),
+ input_name);
+
+ int status = print_database (fd);
+
+ close (fd);
return status;
}
@@ -163,34 +233,87 @@
input_file = stdin;
else
{
- struct stat st;
-
- input_file = fopen (input_name, "r");
+ struct stat64 st;
+
+ input_file = fopen64 (input_name, "r");
if (input_file == NULL)
error (EXIT_FAILURE, errno, gettext ("cannot open input file `%s'"),
input_name);
/* Get the access rights from the source file. The output file should
have the same. */
- if (fstat (fileno (input_file), &st) >= 0)
+ if (fstat64 (fileno (input_file), &st) >= 0)
mode = st.st_mode & ACCESSPERMS;
}
- /* Open output file. This must not be standard output so we don't
- handle "-" and "/dev/stdout" special. */
- dbopen (output_name, DB_CREATE | db_truncate, mode, &db_file);
- if (db_file == NULL)
- error (EXIT_FAILURE, errno, gettext ("cannot open output file `%s'"),
- output_name);
-
/* Start the real work. */
- status = process_input (input_file, input_name, db_file, to_lowercase,
- be_quiet);
+ int status = process_input (input_file, input_name, to_lowercase, be_quiet);
/* Close files. */
if (input_file != stdin)
fclose (input_file);
- db_file->close (db_file->db, 0);
+
+ /* No need to continue when we did not read the file successfully. */
+ if (status != EXIT_SUCCESS)
+ return status;
+
+ /* Bail out if nothing is to be done. */
+ if (!any_dbentry)
+ {
+ if (be_quiet)
+ return EXIT_SUCCESS;
+ else
+ error (EXIT_SUCCESS, 0, gettext ("no entries to be processed"));
+ }
+
+ /* Compute hash and string tables. */
+ compute_tables ();
+
+ /* Open output file. This must not be standard output so we don't
+ handle "-" and "/dev/stdout" special. */
+ char *tmp_output_name;
+ if (asprintf (&tmp_output_name, "%s.XXXXXX", output_name) == -1)
+ error (EXIT_FAILURE, errno, gettext ("cannot create temporary file name"));
+
+ set_file_creation_context (output_name, mode);
+ int fd = mkstemp (tmp_output_name);
+ reset_file_creation_context ();
+ if (fd == -1)
+ error (EXIT_FAILURE, errno, gettext ("cannot create temporary file"));
+
+ status = write_output (fd);
+
+ if (status == EXIT_SUCCESS)
+ {
+ struct stat64 st;
+
+ if (fstat64 (fd, &st) == 0)
+ {
+ if ((st.st_mode & ACCESSPERMS) != mode)
+ /* We ignore problems with changing the mode. */
+ fchmod (fd, mode);
+ }
+ else
+ {
+ error (0, errno, gettext ("cannot stat newly created file"));
+ status = EXIT_FAILURE;
+ }
+ }
+
+ close (fd);
+
+ if (status == EXIT_SUCCESS)
+ {
+ if (rename (tmp_output_name, output_name) != 0)
+ {
+ error (0, errno, gettext ("cannot rename temporary file"));
+ status = EXIT_FAILURE;
+ goto do_unlink;
+ }
+ }
+ else
+ do_unlink:
+ unlink (tmp_output_name);
return status;
}
@@ -200,6 +323,8 @@
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
+ struct db_option *newp;
+
switch (key)
{
case 'f':
@@ -214,6 +339,12 @@
case 'u':
do_undo = 1;
break;
+ case 'g':
+ newp = xmalloc (sizeof (*newp));
+ newp->dbid = arg[0];
+ newp->next = db_options;
+ db_options = newp;
+ break;
default:
return ARGP_ERR_UNKNOWN;
}
@@ -249,16 +380,38 @@
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\
-"), "2000");
+"), "2011");
fprintf (stream, gettext ("Written by %s.\n"), "Ulrich Drepper");
}
static int
-process_input (input, inname, output, to_lowercase, be_quiet)
+dbentry_compare (const void *p1, const void *p2)
+{
+ const struct dbentry *d1 = (const struct dbentry *) p1;
+ const struct dbentry *d2 = (const struct dbentry *) p2;
+
+ if (d1->hashval != d2->hashval)
+ return d1->hashval < d2->hashval ? -1 : 1;
+
+ return strcmp (d1->str, d2->str);
+}
+
+
+static int
+valstr_compare (const void *p1, const void *p2)
+{
+ const struct valstrentry *d1 = (const struct valstrentry *) p1;
+ const struct valstrentry *d2 = (const struct valstrentry *) p2;
+
+ return strcmp (d1->str, d2->str);
+}
+
+
+static int
+process_input (input, inname, to_lowercase, be_quiet)
FILE *input;
const char *inname;
- NSS_DB *output;
int to_lowercase;
int be_quiet;
{
@@ -272,14 +425,11 @@
status = EXIT_SUCCESS;
linenr = 0;
- while (!feof (input))
- {
- DBT key;
- DBT val;
- char *cp;
- int n;
-
- n = getline (&line, &linelen, input);
+ struct database *last_database = NULL;
+
+ while (!feof_unlocked (input))
+ {
+ ssize_t n = getline (&line, &linelen, input);
if (n < 0)
/* This means end of file or some bug. */
break;
@@ -293,15 +443,18 @@
/* Remove trailing newline. */
line[--n] = '\0';
- cp = line;
+ char *cp = line;
while (isspace (*cp))
++cp;
- if (*cp == '#')
- /* First non-space character in line '#': it's a comment. */
+ if (*cp == '#' || *cp == '\0')
+ /* First non-space character in line '#': it's a comment.
+ Also go to the next line if it is empty except for whitespaces. */
continue;
- key.data = cp;
+ /* Skip over the character indicating the database so that it is not
+ affected by TO_LOWERCASE. */
+ char *key = cp++;
while (*cp != '\0' && !isspace (*cp))
{
if (to_lowercase)
@@ -309,85 +462,411 @@
++cp;
}
- if (key.data == cp)
- /* It's an empty line. */
+ if (*cp == '\0')
+ /* It's a line without a value field. */
continue;
- key.size = cp - (char *) key.data;
- key.flags = 0;
+ *cp++ = '\0';
+ size_t keylen = cp - key;
while (isspace (*cp))
++cp;
- val.data = cp;
- val.size = (&line[n] - cp) + 1;
- val.flags = 0;
-
- /* Store the value. */
- status = output->put (output->db, NULL, &key, &val, db_nooverwrite);
- if (status != 0)
+ char *data = cp;
+ size_t datalen = (&line[n] - cp) + 1;
+
+ /* Find the database. */
+ if (last_database == NULL || last_database->dbid != key[0])
{
- if (status == db_keyexist)
+ last_database = databases;
+ while (last_database != NULL && last_database->dbid != key[0])
+ last_database = last_database->next;
+
+ if (last_database == NULL)
{
- if (!be_quiet)
- error_at_line (0, 0, inname, linenr,
- gettext ("duplicate key"));
- /* This is no real error. Just give a warning. */
- status = 0;
- continue;
+ last_database = xmalloc (sizeof (*last_database));
+ last_database->dbid = key[0];
+ last_database->extra_string = false;
+ last_database->next = databases;
+ last_database->entries = NULL;
+ last_database->nentries = 0;
+ last_database->keystrlen = 0;
+ databases = last_database;
+
+ struct db_option *runp = db_options;
+ while (runp != NULL)
+ if (runp->dbid == key[0])
+ {
+ last_database->extra_string = true;
+ break;
+ }
+ else
+ runp = runp->next;
+ }
+ }
+
+ /* Skip the database selector. */
+ ++key;
+ --keylen;
+
+ /* Store the data. */
+ struct valstrentry *nentry = xmalloc (sizeof (struct valstrentry)
+ + datalen);
+ if (last_database->extra_string)
+ nentry->idx = extrastrlen;
+ else
+ nentry->idx = valstrlen;
+ nentry->extra_string = last_database->extra_string;
+ memcpy (nentry->str, data, datalen);
+
+ struct valstrentry **fdata = tsearch (nentry, &valstrtree,
+ valstr_compare);
+ if (fdata == NULL)
+ error (EXIT_FAILURE, errno, gettext ("cannot create search tree"));
+
+ if (*fdata != nentry)
+ {
+ /* We can reuse a string. */
+ free (nentry);
+ nentry = *fdata;
+ }
+ else
+ if (last_database->extra_string)
+ extrastrlen += datalen;
+ else
+ valstrlen += datalen;
+
+ /* Store the key. */
+ struct dbentry *newp = xmalloc (sizeof (struct dbentry) + keylen);
+ newp->validx = nentry->idx;
+ newp->hashval = __hash_string (key);
+ memcpy (newp->str, key, keylen);
+
+ struct dbentry **found = tsearch (newp, &last_database->entries,
+ dbentry_compare);
+ if (found == NULL)
+ error (EXIT_FAILURE, errno, gettext ("cannot create search tree"));
+
+ if (*found != newp)
+ {
+ free (newp);
+ if (!be_quiet)
+ error_at_line (0, 0, inname, linenr, gettext ("duplicate key"));
+ continue;
+ }
+
+ ++last_database->nentries;
+ last_database->keystrlen += keylen;
+
+ any_dbentry = true;
+ }
+
+ if (ferror_unlocked (input))
+ {
+ error (0, 0, gettext ("problems while reading `%s'"), inname);
+ status = EXIT_FAILURE;
+ }
+
+ return status;
+}
+
+
+static void
+copy_valstr (const void *nodep, const VISIT which, const int depth)
+{
+ if (which != leaf && which != postorder)
+ return;
+
+ const struct valstrentry *p = *(const struct valstrentry **) nodep;
+
+ strcpy (valstrtab + (p->extra_string ? valstrlen : 0) + p->idx, p->str);
+}
+
+
+static int
+is_prime (size_t candidate)
+{
+ /* No even number and none less than 10 will be passed here. */
+ size_t divn = 3;
+ size_t sq = divn * divn;
+
+ while (sq < candidate && candidate % divn != 0)
+ {
+ ++divn;
+ sq += 4 * divn;
+ ++divn;
+ }
+
+ return candidate % divn != 0;
+}
+
+
+static size_t
+next_prime (size_t seed)
+{
+ /* Make it definitely odd. */
+ seed |= 1;
+
+ while (!is_prime (seed))
+ seed += 2;
+
+ return seed;
+}
+
+
+static void
+compute_tables (void)
+{
+ valstrtab = xmalloc (roundup (valstrlen + extrastrlen, sizeof (stridx_t)));
+ while ((valstrlen + extrastrlen) % sizeof (stridx_t) != 0)
+ valstrtab[valstrlen++] = '\0';
+ twalk (valstrtree, copy_valstr);
+
+ for (struct database *db = databases; db != NULL; db = db->next)
+ if (db->nentries != 0)
+ {
+ ++ndatabases;
+
+ /* We simply use an odd number large than twice the number of
+ elements to store in the hash table for the size. This gives
+ enough efficiency. */
+#define TEST_RANGE 30
+ size_t nhashentries_min = next_prime (db->nentries < TEST_RANGE
+ ? db->nentries
+ : db->nentries * 2 - TEST_RANGE);
+ size_t nhashentries_max = MAX (nhashentries_min, db->nentries * 4);
+ size_t nhashentries_best = nhashentries_min;
+ size_t chainlength_best = db->nentries;
+
+ db->hashtable = xmalloc (2 * nhashentries_max * sizeof (stridx_t)
+ + db->keystrlen);
+ db->keyidxtab = db->hashtable + nhashentries_max;
+ db->keystrtab = (char *) (db->keyidxtab + nhashentries_max);
+
+ size_t max_chainlength;
+ char *wp;
+ size_t nhashentries;
+ bool copy_string = false;
+
+ void add_key(const void *nodep, const VISIT which, const int depth)
+ {
+ if (which != leaf && which != postorder)
+ return;
+
+ const struct dbentry *dbe = *(const struct dbentry **) nodep;
+
+ ptrdiff_t stridx;
+ if (copy_string)
+ {
+ stridx = wp - db->keystrtab;
+ wp = stpcpy (wp, dbe->str) + 1;
}
else
- error (0, status, gettext ("while writing database file"));
-
- status = EXIT_FAILURE;
-
- clearerr (input);
- break;
+ stridx = 0;
+
+ size_t hidx = dbe->hashval % nhashentries;
+ size_t hval2 = 1 + dbe->hashval % (nhashentries - 2);
+ size_t chainlength = 0;
+
+ while (db->hashtable[hidx] != ~((stridx_t) 0))
+ {
+ ++chainlength;
+ if ((hidx += hval2) >= nhashentries)
+ hidx -= nhashentries;
+ }
+
+ db->hashtable[hidx] = ((db->extra_string ? valstrlen : 0)
+ + dbe->validx);
+ db->keyidxtab[hidx] = stridx;
+
+ max_chainlength = MAX (max_chainlength, chainlength);
}
- }
-
- if (ferror (input))
- {
- error (0, 0, gettext ("problems while reading `%s'"), inname);
- status = EXIT_FAILURE;
- }
-
- return status;
+
+ nhashentries = nhashentries_min;
+ for (size_t cnt = 0; cnt < TEST_RANGE; ++cnt)
+ {
+ memset (db->hashtable, '\xff', nhashentries * sizeof (stridx_t));
+
+ max_chainlength = 0;
+ wp = db->keystrtab;
+
+ twalk (db->entries, add_key);
+
+ if (max_chainlength == 0)
+ {
+ /* No need to look further, this is as good as it gets. */
+ nhashentries_best = nhashentries;
+ break;
+ }
+
+ if (max_chainlength < chainlength_best)
+ {
+ chainlength_best = max_chainlength;
+ nhashentries_best = nhashentries;
+ }
+
+ nhashentries = next_prime (nhashentries + 1);
+ if (nhashentries > nhashentries_max)
+ break;
+ }
+
+ /* Recompute the best table again, this time fill in the strings. */
+ nhashentries = nhashentries_best;
+ memset (db->hashtable, '\xff',
+ 2 * nhashentries_max * sizeof (stridx_t));
+ copy_string = true;
+ wp = db->keystrtab;
+
+ twalk (db->entries, add_key);
+
+ db->nhashentries = nhashentries_best;
+ nhashentries_total += nhashentries_best;
+ }
}
static int
-print_database (db)
- NSS_DB *db;
-{
- DBT key;
- DBT val;
- NSS_DBC *cursor;
- int status;
-
- status = db->cursor (db->db, NULL, &cursor);
- if (status != 0)
- {
- error (0, status, gettext ("while reading database"));
+write_output (int fd)
+{
+ struct nss_db_header *header;
+ uint64_t file_offset = (sizeof (struct nss_db_header)
+ + (ndatabases * sizeof (header->dbs[0])));
+ header = alloca (file_offset);
+
+ header->magic = NSS_DB_MAGIC;
+ header->ndbs = ndatabases;
+ header->valstroffset = file_offset;
+ header->valstrlen = valstrlen;
+
+ size_t filled_dbs = 0;
+ struct iovec iov[2 + ndatabases * 3];
+ iov[0].iov_base = header;
+ iov[0].iov_len = file_offset;
+
+ iov[1].iov_base = valstrtab;
+ iov[1].iov_len = valstrlen + extrastrlen;
+ file_offset += iov[1].iov_len;
+
+ size_t keydataoffset = file_offset + nhashentries_total * sizeof (stridx_t);
+ for (struct database *db = databases; db != NULL; db = db->next)
+ if (db->entries != NULL)
+ {
+ assert (file_offset % sizeof (stridx_t) == 0);
+ assert (filled_dbs < ndatabases);
+
+ header->dbs[filled_dbs].id = db->dbid;
+ memset (header->dbs[filled_dbs].pad, '\0',
+ sizeof (header->dbs[0].pad));
+ header->dbs[filled_dbs].hashsize = db->nhashentries;
+
+ iov[2 + filled_dbs].iov_base = db->hashtable;
+ iov[2 + filled_dbs].iov_len = db->nhashentries * sizeof (stridx_t);
+ header->dbs[filled_dbs].hashoffset = file_offset;
+ file_offset += iov[2 + filled_dbs].iov_len;
+
+ iov[2 + ndatabases + filled_dbs * 2].iov_base = db->keyidxtab;
+ iov[2 + ndatabases + filled_dbs * 2].iov_len
+ = db->nhashentries * sizeof (stridx_t);
+ header->dbs[filled_dbs].keyidxoffset = keydataoffset;
+ keydataoffset += iov[2 + ndatabases + filled_dbs * 2].iov_len;
+
+ iov[3 + ndatabases + filled_dbs * 2].iov_base = db->keystrtab;
+ iov[3 + ndatabases + filled_dbs * 2].iov_len = db->keystrlen;
+ header->dbs[filled_dbs].keystroffset = keydataoffset;
+ keydataoffset += iov[3 + ndatabases + filled_dbs * 2].iov_len;
+
+ ++filled_dbs;
+ }
+
+ assert (filled_dbs == ndatabases);
+ assert (file_offset == (iov[0].iov_len + iov[1].iov_len
+ + nhashentries_total * sizeof (stridx_t)));
+ header->allocate = file_offset;
+
+ if (writev (fd, iov, 2 + ndatabases * 3) != keydataoffset)
+ {
+ error (0, errno, gettext ("failed to write new database file"));
return EXIT_FAILURE;
}
- key.flags = 0;
- val.flags = 0;
- status = cursor->c_get (cursor->cursor, &key, &val, db_first);
- while (status == 0)
- {
- printf ("%.*s %s\n", (int) key.size, (char *) key.data,
- (char *) val.data);
-
- status = cursor->c_get (cursor->cursor, &key, &val, db_next);
- }
-
- if (status != db_notfound)
- {
- error (0, status, gettext ("while reading database"));
- return EXIT_FAILURE;
- }
-
return EXIT_SUCCESS;
}
+
+
+static int
+print_database (int fd)
+{
+ struct stat64 st;
+ if (fstat64 (fd, &st) != 0)
+ error (EXIT_FAILURE, errno, gettext ("cannot stat database file"));
+
+ const struct nss_db_header *header = mmap (NULL, st.st_size, PROT_READ,
+ MAP_PRIVATE|MAP_POPULATE, fd, 0);
+ if (header == MAP_FAILED)
+ error (EXIT_FAILURE, errno, gettext ("cannot map database file"));
+
+ if (header->magic != NSS_DB_MAGIC)
+ error (EXIT_FAILURE, 0, gettext ("file not a database file"));
+
+ const char *valstrtab = (const char *) header + header->valstroffset;
+
+ for (unsigned int dbidx = 0; dbidx < header->ndbs; ++dbidx)
+ {
+ const stridx_t *stridxtab
+ = ((const stridx_t *) ((const char *) header
+ + header->dbs[dbidx].keyidxoffset));
+ const char *keystrtab
+ = (const char *) header + header->dbs[dbidx].keystroffset;
+ const stridx_t *hashtab
+ = (const stridx_t *) ((const char *) header
+ + header->dbs[dbidx].hashoffset);
+
+ for (uint32_t hidx = 0; hidx < header->dbs[dbidx].hashsize; ++hidx)
+ if (hashtab[hidx] != ~((stridx_t) 0))
+ printf ("%c%s %s\n",
+ header->dbs[dbidx].id,
+ keystrtab + stridxtab[hidx],
+ valstrtab + hashtab[hidx]);
+ }
+
+ return EXIT_SUCCESS;
+}
+
+
+#ifdef HAVE_SELINUX
+static void
+set_file_creation_context (const char *outname, mode_t mode)
+{
+ static int enabled;
+ static int enforcing;
+ security_context_t ctx;
+
+ /* Check if SELinux is enabled, and remember. */
+ if (enabled == 0)
+ enabled = is_selinux_enabled ();
+ if (enabled < 0)
+ return;
+
+ /* Check if SELinux is enforcing, and remember. */
+ if (enforcing == 0)
+ enforcing = security_getenforce () ? 1 : -1;
+
+ /* Determine the context which the file should have. */
+ ctx = NULL;
+ if (matchpathcon (outname, S_IFREG | mode, &ctx) == 0 && ctx != NULL)
+ {
+ if (setfscreatecon (ctx) != 0)
+ error (enforcing > 0 ? EXIT_FAILURE : 0, 0,
+ gettext ("cannot set file creation context for `%s'"),
+ outname);
+
+ freecon (ctx);
+ }
+}
+
+static void
+reset_file_creation_context (void)
+{
+ setfscreatecon (NULL);
+}
+#endif
Modified: trunk/libc/nss/nss_db/db-XXX.c
==============================================================================
--- trunk/libc/nss/nss_db/db-XXX.c (original)
+++ trunk/libc/nss/nss_db/db-XXX.c Tue Jun 21 08:37:38 2011
@@ -1,5 +1,5 @@
/* Common code for DB-based databases in nss_db module.
- Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1996-2000, 2011 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
@@ -19,10 +19,14 @@
#include <dlfcn.h>
#include <fcntl.h>
+#include <sys/mman.h>
#include <bits/libc-lock.h>
#include "nsswitch.h"
#include "nss_db.h"
+/* The hashing function we use. */
+#include "../intl/hash-string.h"
+
/* These symbols are defined by the including source file:
ENTNAME -- database name of the structure and functions (hostent, pwent).
@@ -38,25 +42,25 @@
#define DBFILE _PATH_VARDB DATABASE ".db"
#ifdef NEED_H_ERRNO
-#define H_ERRNO_PROTO , int *herrnop
-#define H_ERRNO_ARG , herrnop
-#define H_ERRNO_SET(val) (*herrnop = (val))
+# define H_ERRNO_PROTO , int *herrnop
+# define H_ERRNO_ARG , herrnop
+# define H_ERRNO_SET(val) (*herrnop = (val))
#else
-#define H_ERRNO_PROTO
-#define H_ERRNO_ARG
-#define H_ERRNO_SET(val) ((void) 0)
+# define H_ERRNO_PROTO
+# define H_ERRNO_ARG
+# define H_ERRNO_SET(val) ((void) 0)
#endif
-/* Locks the static variables in this file. */
-__libc_lock_define_initialized (static, lock)
+/* State for this database. */
+static struct nss_db_map state;
+/* Lock to protect the state and global variables. */
+__libc_lock_define (static , lock);
+
+/* Maintenance of the shared handle open on the database. */
+static int keep_db;
+static const char *entidx;
+
-/* Maintenance of the shared handle open on the database. */
-
-static NSS_DB *db;
-static int keep_db;
-static int entidx;
-
-
/* Open the database. */
enum nss_status
CONCAT(_nss_db_set,ENTNAME) (int stayopen)
@@ -65,13 +69,13 @@
__libc_lock_lock (lock);
- status = internal_setent (DBFILE, &db);
+ status = internal_setent (DBFILE, &state);
/* Remember STAYOPEN flag. */
- if (db != NULL)
+ if (status == NSS_STATUS_SUCCESS)
keep_db |= stayopen;
/* Reset the sequential index. */
- entidx = 0;
+ entidx = (const char *) state.header + state.header->valstroffset;
__libc_lock_unlock (lock);
@@ -85,7 +89,7 @@
{
__libc_lock_lock (lock);
- internal_endent (&db);
+ internal_endent (&state);
/* Reset STAYOPEN flag. */
keep_db = 0;
@@ -94,132 +98,124 @@
return NSS_STATUS_SUCCESS;
}
-
-/* Do a database lookup for KEY. */
-static enum nss_status
-lookup (DBT *key, struct STRUCTURE *result,
- void *buffer, size_t buflen, int *errnop H_ERRNO_PROTO EXTRA_ARGS_DECL)
-{
- char *p;
- enum nss_status status;
- int err;
- DBT value;
-
- /* Open the database. */
- if (db == NULL)
- {
- status = internal_setent (DBFILE, &db);
- if (status != NSS_STATUS_SUCCESS)
- {
- *errnop = errno;
- H_ERRNO_SET (NETDB_INTERNAL);
- return status;
- }
- }
-
- /* Succeed iff it matches a value that parses correctly. */
- value.flags = 0;
- err = DL_CALL_FCT (db->get, (db->db, NULL, key, &value, 0));
- if (err != 0)
- {
- if (err == db_notfound)
- {
- H_ERRNO_SET (HOST_NOT_FOUND);
- status = NSS_STATUS_NOTFOUND;
- }
- else
- {
- *errnop = err;
- H_ERRNO_SET (NETDB_INTERNAL);
- status = NSS_STATUS_UNAVAIL;
- }
- }
- else if (buflen < value.size)
- {
- /* No room to copy the data to. */
- *errnop = ERANGE;
- H_ERRNO_SET (NETDB_INTERNAL);
- status = NSS_STATUS_TRYAGAIN;
- }
- else
- {
- /* Copy the result to a safe place. */
- p = (char *) memcpy (buffer, value.data, value.size);
-
- /* Skip leading blanks. */
- while (isspace (*p))
- ++p;
-
- err = parse_line (p, result, buffer, buflen, errnop EXTRA_ARGS);
-
- if (err == 0)
- {
- /* If the key begins with '0' we are trying to get the next
- entry. We want to ignore unparsable lines in this case. */
- if (((char *) key->data)[0] == '0')
- {
- /* Super magical return value. We need to tell our caller
- that it should continue looping. This value cannot
- happen in other cases. */
- status = NSS_STATUS_RETURN;
- }
- else
- {
- H_ERRNO_SET (HOST_NOT_FOUND);
- status = NSS_STATUS_NOTFOUND;
- }
- }
- else if (err < 0)
- {
- H_ERRNO_SET (NETDB_INTERNAL);
- status = NSS_STATUS_TRYAGAIN;
- }
- else
- status = NSS_STATUS_SUCCESS;
- }
-
- if (! keep_db)
- internal_endent (&db);
-
- return status;
-}
/* Macro for defining lookup functions for this DB-based database.
NAME is the name of the lookup; e.g. `pwnam'.
+ DB_CHAR is index indicator for the database.
+
KEYPATTERN gives `printf' args to construct a key string;
- e.g. `(".%s", name)'.
+ e.g. `("%d", id)'.
KEYSIZE gives the allocation size of a buffer to construct it in;
- e.g. `1 + strlen (name)'.
-
- PROTO describes the arguments for the lookup key;
- e.g. `const char *name'.
-
- BREAK_IF_MATCH is ignored, but used by ../nss_files/files-XXX.c. */
-
-#define DB_LOOKUP(name, keysize, keypattern, break_if_match, proto...) \
+ e.g. `1 + sizeof (id) * 4'.
+
+ PROTO is the potentially empty list of other parameters.
+
+ BREAK_IF_MATCH is a block of code which compares `struct STRUCTURE *result'
+ to the lookup key arguments and does `break;' if they match. */
+
+#define DB_LOOKUP(name, db_char, keysize, keypattern, break_if_match, proto...)\
enum nss_status \
-_nss_db_get##name##_r (proto, \
- struct STRUCTURE *result, \
- char *buffer, size_t buflen, int *errnop H_ERRNO_PROTO)\
+ _nss_db_get##name##_r (proto, struct STRUCTURE *result, \
+ char *buffer, size_t buflen, int *errnop H_ERRNO_PROTO)\
{ \
- DBT key; \
- enum nss_status status; \
- const size_t size = (keysize) + 1; \
- key.data = __alloca (size); \
- key.size = KEYPRINTF keypattern; \
- key.flags = 0; \
- __libc_lock_lock (lock); \
- status = lookup (&key, result, buffer, buflen, errnop H_ERRNO_ARG \
- EXTRA_ARGS_VALUE); \
- __libc_lock_unlock (lock); \
+ struct parser_data *data = (void *) buffer; \
+ \
+ if (buflen < sizeof *data) \
+ { \
+ *errnop = ERANGE; \
+ H_ERRNO_SET (NETDB_INTERNAL); \
+ return NSS_STATUS_TRYAGAIN; \
+ } \
+ \
+ struct nss_db_map state = { NULL, 0 }; \
+ enum nss_status status = internal_setent (DBFILE, &state); \
+ if (status != NSS_STATUS_SUCCESS) \
+ { \
+ *errnop = errno; \
+ H_ERRNO_SET (NETDB_INTERNAL); \
+ return status; \
+ } \
+ \
+ const struct nss_db_header *header = state.header; \
+ int i; \
+ for (i = 0; i < header->ndbs; ++i) \
+ if (header->dbs[i].id == db_char) \
+ break; \
+ if (i == header->ndbs) \
+ { \
+ status = NSS_STATUS_UNAVAIL; \
+ goto out; \
+ } \
+ \
+ char *key; \
+ if (db_char == '.') \
+ key = (char *) IGNOREPATTERN keypattern; \
+ else \
+ { \
+ const size_t size = (keysize) + 1; \
+ key = alloca (size); \
+ \
+ KEYPRINTF keypattern; \
+ } \
+ \
+ const stridx_t *hashtable \
+ = (const stridx_t *) ((const char *) header \
+ + header->dbs[i].hashoffset); \
+ const char *valstrtab = (const char *) header + header->valstroffset; \
+ uint32_t hashval = __hash_string (key); \
+ size_t hidx = hashval % header->dbs[i].hashsize; \
+ size_t hval2 = 1 + hashval % (header->dbs[i].hashsize - 2); \
+ \
+ status = NSS_STATUS_NOTFOUND; \
+ while (hashtable[hidx] != ~((stridx_t) 0)) \
+ { \
+ const char *valstr = valstrtab + hashtable[hidx]; \
+ size_t len = strlen (valstr) + 1; \
+ if (len > buflen) \
+ { \
+ /* No room to copy the data to. */ \
+ *errnop = ERANGE; \
+ H_ERRNO_SET (NETDB_INTERNAL); \
+ status = NSS_STATUS_TRYAGAIN; \
+ break; \
+ } \
+ \
+ /* Copy the string to a place where it can be modified. */ \
+ char *p = memcpy (buffer, valstr, len); \
+ \
+ int err = parse_line (p, result, data, buflen, errnop EXTRA_ARGS); \
+ if (err > 0) \
+ { \
+ status = NSS_STATUS_SUCCESS; \
+ break_if_match; \
+ status = NSS_STATUS_NOTFOUND; \
+ } \
+ else if (err == -1) \
+ { \
+ H_ERRNO_SET (NETDB_INTERNAL); \
+ status = NSS_STATUS_TRYAGAIN; \
+ break; \
+ } \
+ \
+ if ((hidx += hval2) >= header->dbs[i].hashsize) \
+ hidx -= header->dbs[i].hashsize; \
+ } \
+ \
+ if (status == NSS_STATUS_NOTFOUND) \
+ H_ERRNO_SET (HOST_NOT_FOUND); \
+ \
+ out: \
+ internal_endent (&state); \
+ \
return status; \
}
-#define KEYPRINTF(pattern, args...) snprintf (key.data, size, pattern ,##args)
+#define KEYPRINTF(pattern, args...) snprintf (key, size, pattern ,##args)
+#define IGNOREPATTERN(pattern, arg1, args...) (char *) (uintptr_t) arg1
@@ -231,30 +227,72 @@
{
/* Return next entry in host file. */
enum nss_status status;
- char buf[20];
- DBT key;
+ struct parser_data *data = (void *) buffer;
+
+ if (buflen < sizeof *data)
+ {
+ *errnop = ERANGE;
+ H_ERRNO_SET (NETDB_INTERNAL);
+ return NSS_STATUS_TRYAGAIN;
+ }
__libc_lock_lock (lock);
- /* Loop until we find a valid entry or hit EOF. See above for the
- special meaning of the status value. */
- do
+ if (state.header == NULL)
{
- key.size = snprintf (key.data = buf, sizeof buf, "0%u", entidx++);
- key.flags = 0;
- status = lookup (&key, result, buffer, buflen, errnop H_ERRNO_ARG
- EXTRA_ARGS_VALUE);
- if (status == NSS_STATUS_TRYAGAIN
-#ifdef NEED_H_ERRNO
- && *herrnop == NETDB_INTERNAL
-#endif
- && *errnop == ERANGE)
- /* Give the user a chance to get the same entry with a larger
- buffer. */
- --entidx;
+ status = internal_setent (DBFILE, &state);
+ if (status != NSS_STATUS_SUCCESS)
+ {
+ *errnop = errno;
+ H_ERRNO_SET (NETDB_INTERNAL);
+ goto out;
+ }
}
- while (status == NSS_STATUS_RETURN);
-
+
+ status = NSS_STATUS_UNAVAIL;
+ if (state.header != MAP_FAILED)
+ {
+ const char *const end = ((const char *) state.header
+ + state.header->valstroffset
+ + state.header->valstrlen);
+ while (entidx < end)
+ {
+ const char *next = rawmemchr (entidx, '\0') + 1;
+ size_t len = next - entidx;
+
+ if (len > buflen)
+ {
+ /* No room to copy the data to. */
+ *errnop = ERANGE;
+ H_ERRNO_SET (NETDB_INTERNAL);
+ status = NSS_STATUS_TRYAGAIN;
+ break;
+ }
+
+ /* Copy the string to a place where it can be modified. */
+ char *p = memcpy (buffer, entidx, len);
+
+ int err = parse_line (p, result, data, buflen, errnop EXTRA_ARGS);
+
+ if (err > 0)
+ {
+ status = NSS_STATUS_SUCCESS;
+ entidx = next;
+ break;
+ }
+ if (err < 0)
+ {
+ H_ERRNO_SET (HOST_NOT_FOUND);
+ status = NSS_STATUS_NOTFOUND;
+ break;
+ }
+
+ /* Continue with the next record, this one is ill-formed. */
+ entidx = next;
+ }
+ }
+
+ out:
__libc_lock_unlock (lock);
return status;
Removed: trunk/libc/nss/nss_db/db-alias.c
==============================================================================
--- trunk/libc/nss/nss_db/db-alias.c (original)
+++ trunk/libc/nss/nss_db/db-alias.c (removed)
@@ -1,215 +1,0 @@
-/* Mail alias file parser in nss_db module.
- Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Ulrich Drepper <drepper@xxxxxxxxxx>, 1996.
-
- 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, write to the Free
- Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA. */
-
-#include <aliases.h>
-#include <alloca.h>
-#include <ctype.h>
-#include <dlfcn.h>
-#include <errno.h>
-#include <bits/libc-lock.h>
-#include <paths.h>
-#include <string.h>
-
-#include "nsswitch.h"
-#include "nss_db.h"
-
-/* Locks the static variables in this file. */
-__libc_lock_define_initialized (static, lock)
-
-/* Maintenance of the shared handle open on the database. */
-
-static NSS_DB *db;
-static int keep_db;
-static unsigned int entidx; /* Index for `getaliasent_r'. */
-
-
-/* Open database. */
-enum nss_status
-_nss_db_setaliasent (int stayopen)
-{
- enum nss_status status;
-
- __libc_lock_lock (lock);
-
- status = internal_setent (_PATH_VARDB "aliases.db", &db);
-
- /* Remember STAYOPEN flag. */
- if (db != NULL)
- keep_db |= stayopen;
-
- /* Reset the sequential index. */
- entidx = 0;
-
- __libc_lock_unlock (lock);
-
- return status;
-}
-
-
-/* Close it again. */
-enum nss_status
-_nss_db_endaliasent (void)
-{
- __libc_lock_lock (lock);
-
- internal_endent (&db);
-
- /* Reset STAYOPEN flag. */
- keep_db = 0;
-
- __libc_lock_unlock (lock);
-
- return NSS_STATUS_SUCCESS;
-}
-
-/* We provide the parse function here. The parser in libnss_files
- cannot be used. The generation of the db file already resolved all
- :include: statements so we simply have to parse the list and store
- the result. */
-static enum nss_status
-lookup (DBT *key, struct aliasent *result, char *buffer,
- size_t buflen, int *errnop)
-{
- enum nss_status status;
- DBT value;
-
- /* Open the database. */
- if (db == NULL)
- {
- status = internal_setent (_PATH_VARDB "aliases.db", &db);
- if (status != NSS_STATUS_SUCCESS)
- {
- *errnop = errno;
- return status;
- }
- }
-
- value.flags = 0;
- if (DL_CALL_FCT (db->get, (db->db, NULL, key, &value, 0)) == 0)
- {
- const char *src = value.data;
- char *cp;
- size_t cnt;
-
- result->alias_members_len = 0;
-
- /* We now have to fill the BUFFER with all the information. */
- if (buflen < key->size + 1)
- {
- no_more_room:
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- buffer = stpncpy (buffer, key->data, key->size) + 1;
- buflen -= key->size + 1;
-
- while (*src != '\0')
- {
- const char *end, *upto;
- while (isspace (*src))
- ++src;
-
- end = strchr (src, ',');
- if (end == NULL)
- end = strchr (src, '\0');
- for (upto = end; upto > src && isspace (upto[-1]); --upto);
-
- if (upto != src)
- {
- if ((upto - src) + __alignof__ (char *) > buflen)
- goto no_more_room;
- buffer = stpncpy (buffer, src, upto - src) + 1;
- buflen -= (upto - src) + __alignof (char *);
- ++result->alias_members_len;
- }
- src = end + (*end != '\0');
- }
-
- /* Now prepare the return. Provide string pointers for the
- currently selected aliases. */
-
- /* Adjust the pointer so it is aligned for storing pointers. */
- buffer += __alignof__ (char *) - 1;
- buffer -= ((buffer - (char *) 0) % __alignof__ (char *));
- result->alias_members = (char **) buffer;
-
- /* Compute addresses of alias entry strings. */
- cp = result->alias_name;
- for (cnt = 0; cnt < result->alias_members_len; ++cnt)
- {
- cp = strchr (cp, '\0') + 1;
- result->alias_members[cnt] = cp;
- }
-
- status = (result->alias_members_len == 0
- ? NSS_STATUS_RETURN : NSS_STATUS_SUCCESS);
- }
- else
- status = NSS_STATUS_NOTFOUND;
-
- if (! keep_db)
- internal_endent (&db);
-
- return status;
-}
-
-enum nss_status
-_nss_db_getaliasent_r (struct aliasent *result, char *buffer, size_t buflen,
- int *errnop)
-{
- /* Return next entry in alias file. */
- enum nss_status status;
- char buf[20];
- DBT key;
-
- __libc_lock_lock (lock);
- key.size = snprintf (key.data = buf, sizeof buf, "0%u", entidx++);
- key.flags = 0;
- status = lookup (&key, result, buffer, buflen, errnop);
- if (status == NSS_STATUS_TRYAGAIN && *errnop == ERANGE)
- /* Give the user a chance to get the same entry with a larger buffer. */
- --entidx;
- __libc_lock_unlock (lock);
-
- return status;
-}
-
-
-enum nss_status
-_nss_db_getaliasbyname_r (const char *name, struct aliasent *result,
- char *buffer, size_t buflen, int *errnop)
-{
- DBT key;
- enum nss_status status;
-
- key.size = 1 + strlen (name);
-
- key.data = __alloca (key.size);
- ((char *) key.data)[0] = '.';
- memcpy (&((char *) key.data)[1], name, key.size - 1);
- key.flags = 0;
-
- __libc_lock_lock (lock);
- status = lookup (&key, result, buffer, buflen, errnop);
- __libc_lock_unlock (lock);
-
- return status;
-}
Modified: trunk/libc/nss/nss_db/db-netgrp.c
==============================================================================
--- trunk/libc/nss/nss_db/db-netgrp.c (original)
+++ trunk/libc/nss/nss_db/db-netgrp.c Tue Jun 21 08:37:38 2011
@@ -1,5 +1,5 @@
/* Netgroup file parser in nss_db modules.
- Copyright (C) 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1996, 1997, 1999, 2000, 2011 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@xxxxxxxxxx>, 1996.
@@ -18,6 +18,7 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
+#include <ctype.h>
#include <dlfcn.h>
#include <errno.h>
#include <fcntl.h>
@@ -29,40 +30,62 @@
#include "nsswitch.h"
#include "nss_db.h"
+/* The hashing function we use. */
+#include "../intl/hash-string.h"
+
#define DBFILE _PATH_VARDB "netgroup.db"
-
-
-/* Locks the static variables in this file. */
-__libc_lock_define_initialized (static, lock)
/* Maintenance of the shared handle open on the database. */
-static NSS_DB *db;
-static char *entry;
-static char *cursor;
-
enum nss_status
-_nss_db_setnetgrent (const char *group)
+_nss_db_setnetgrent (const char *group, struct __netgrent *result)
{
- enum nss_status status;
-
- __libc_lock_lock (lock);
-
- status = internal_setent (DBFILE, &db);
+ struct nss_db_map state;
+ enum nss_status status = internal_setent (DBFILE, &state);
if (status == NSS_STATUS_SUCCESS)
{
- DBT key = { data: (void *) group, size: strlen (group), flags: 0 };
- DBT value;
+ const struct nss_db_header *header = state.header;
+ const stridx_t *hashtable
+ = (const stridx_t *) ((const char *) header
+ + header->dbs[0].hashoffset);
+ const char *valstrtab = (const char *) header + header->valstroffset;
+ uint32_t hashval = __hash_string (group);
+ size_t grouplen = strlen (group);
+ size_t hidx = hashval % header->dbs[0].hashsize;
+ size_t hval2 = 1 + hashval % (header->dbs[0].hashsize - 2);
- value.flags = 0;
- if (DL_CALL_FCT (db->get, (db->db, NULL, &key, &value, 0)) != 0)
- status = NSS_STATUS_NOTFOUND;
- else
- cursor = entry = value.data;
+ status = NSS_STATUS_NOTFOUND;
+ while (hashtable[hidx] != ~((stridx_t) 0))
+ {
+ const char *valstr = valstrtab + hashtable[hidx];
+
+ if (strncmp (valstr, group, grouplen) == 0
+ && isblank (valstr[grouplen]))
+ {
+ const char *cp = &valstr[grouplen + 1];
+ while (isblank (*cp))
+ ++cp;
+ if (*cp != '\0')
+ {
+ result->data = strdup (cp);
+ if (result->data == NULL)
+ status = NSS_STATUS_TRYAGAIN;
+ else
+ {
+ status = NSS_STATUS_SUCCESS;
+ result->cursor = result->data;
+ }
+ break;
+ }
+ }
+
+ if ((hidx += hval2) >= header->dbs[0].hashsize)
+ hidx -= header->dbs[0].hashsize;
+ }
+
+ internal_endent (&state);
}
-
- __libc_lock_unlock (lock);
return status;
@@ -70,14 +93,12 @@
enum nss_status
-_nss_db_endnetgrent (void)
+_nss_db_endnetgrent (struct __netgrent *result)
{
- __libc_lock_lock (lock);
-
- internal_endent (&db);
-
- __libc_lock_unlock (lock);
-
+ free (result->data);
+ result->data = NULL;
+ result->data_size = 0;
+ result->cursor = NULL;
return NSS_STATUS_SUCCESS;
}
@@ -91,13 +112,10 @@
_nss_db_getnetgrent_r (struct __netgrent *result, char *buffer, size_t buflen,
int *errnop)
{
- int status;
+ enum nss_status status;
- __libc_lock_lock (lock);
-
- status = _nss_netgroup_parseline (&cursor, result, buffer, buflen, errnop);
-
- __libc_lock_unlock (lock);
+ status = _nss_netgroup_parseline (&result->cursor, result, buffer, buflen,
+ errnop);
return status;
}
Modified: trunk/libc/nss/nss_db/db-open.c
==============================================================================
--- trunk/libc/nss/nss_db/db-open.c (original)
+++ trunk/libc/nss/nss_db/db-open.c Tue Jun 21 08:37:38 2011
@@ -1,5 +1,5 @@
/* Common database routines for nss_db.
- Copyright (C) 2000 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2011 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,368 +22,51 @@
#include <dlfcn.h>
#include <stdlib.h>
#include <string.h>
-#include <bits/libc-lock.h>
+#include <sys/mman.h>
+#include <not-cancel.h>
-#include "dummy-db.h"
+#include <kernel-features.h>
#include "nss_db.h"
-/* This file contains the functions used to open and close the databases
- read by the rest of libnss_db. Not all of them are thread safe;
- make sure the caller does the appropriate locking.
+/* Open the database stored in FILE. If succesful, store either a
+ pointer to the mapped file or a file handle for the file in H and
+ return NSS_STATUS_SUCCESS. On failure, return the appropriate
+ lookup status. */
+enum nss_status
+internal_setent (const char *file, struct nss_db_map *mapping)
+{
+ enum nss_status status = NSS_STATUS_UNAVAIL;
- We dynamically load the database library, so that it does not have
- to be present when glibc is compiled. Once loaded, the database
- library is never never unloaded again until the libnss_db module is
- unloaded (from the free_mem routine in nsswitch.c) -- we catch the
- unload by providing a shlib destructor. (XXX Does that actually
- work?) */
+ int mode = O_RDONLY | O_LARGEFILE;
+#ifdef O_CLOEXEC
+ mode |= O_CLOEXEC;
+#endif
+ int fd = open_not_cancel_2 (file, mode);
+ if (fd != -1)
+ {
+ struct nss_db_header header;
-/* Handle for the shared Berkeley DB library. If non-null, the
- database library is completely loaded and ready to be used by
- multithreaded code. */
-static void *libdb_handle;
-
-/* The version of the Berkeley DB library we are using. */
-enum {
- nodb,
- db24,
- db27,
- db30
-} libdb_version;
-
-/* Pointer to the db_open function. For use with DB 2.x. */
-static int (*libdb_db_open) (const char *, int,
- uint32_t, int, void *, void *, void **);
-
-/* Pointer to the db_create function. For use with DB 3.x. */
-static int (*libdb_db_create) (void *, void *, uint32_t);
-
-/* Constants which vary from version to version are actually variables
- here. */
-int db_first;
-int db_next;
-int db_nooverwrite;
-int db_truncate;
-int db_rdonly;
-/* Variables which keep track of the error values. */
-int db_keyexist;
-int db_notfound;
-
-/* Locks the static variables in this file. */
-__libc_lock_define_initialized (static, lock)
-
-/* Dynamically load the database library. Return zero if successful,
- non-zero if no suitable version of the library could be loaded.
- Must be called with the above lock held if it might run in a
- multithreaded context.
-
- We try currently:
- - libdb.so.3: the name used by glibc 2.1
- - libdb-3.0.so: the name used by db-3.0.x
- and maybe others in the future. */
-
-enum nss_status
-load_db (void)
-{
- static const char *libnames[] = { "libdb.so.3", "libdb-3.0.so" };
- int x;
-
- for (x = 0; x < sizeof (libnames) / sizeof (libnames[0]); ++x)
- {
- libdb_handle = dlopen (libnames[x], RTLD_LAZY);
- if (libdb_handle == NULL)
- continue;
-
- /* DB 3.0 has db_create instead of db_open. */
- libdb_db_create = dlsym (libdb_handle, "db_create");
-
- if (libdb_db_create == NULL)
- /* DB 2.x uses db_open. */
- libdb_db_open = dlsym (libdb_handle, "db_open");
-
- if (libdb_db_open != NULL || libdb_db_create != NULL)
+ if (read (fd, &header, sizeof (header)) == sizeof (header))
{
- /* Alright, we got a library. Now find out which version it is. */
- const char *(*db_version) (int *, int *, int *);
-
- db_version = dlsym (libdb_handle, "db_version");
- if (db_version != NULL)
- {
- /* Call the function and get the information. */
- int major, minor, subminor;
-
- DL_CALL_FCT (db_version, (&major, &minor, &subminor));
- switch (major)
- {
- case 2:
- /* Sanity check: Do we have db_open? */
- if (libdb_db_open != NULL)
- {
- if (minor < 6 || (minor == 6 && subminor < 4))
- {
- libdb_version = db24;
- db_first = DB24_FIRST;
- db_next = DB24_NEXT;
- db_nooverwrite = DB24_NOOVERWRITE;
- db_truncate = DB24_TRUNCATE;
- }
- else
- {
- libdb_version = db27;
- db_first = DB27_FIRST;
- db_next = DB27_NEXT;
- db_nooverwrite = DB27_NOOVERWRITE;
- db_truncate = DB27_TRUNCATE;
- }
- db_keyexist = DB2x_KEYEXIST;
- db_notfound = DB2x_NOTFOUND;
- db_rdonly = DB2x_RDONLY;
- }
- break;
-
- case 3:
- /* Sanity check: Do we have db_create? */
- if (libdb_db_create != NULL)
- {
- libdb_version = db30;
- db_first = DB30_FIRST;
- db_next = DB30_NEXT;
- db_keyexist = DB30_KEYEXIST;
- db_notfound = DB30_NOTFOUND;
- db_rdonly = DB30_RDONLY;
- }
- break;
-
- default:
- break;
- }
- }
-
- if (libdb_version != nodb)
- return NSS_STATUS_SUCCESS;
-
- /* Clear variables. */
- libdb_db_open = NULL;
- libdb_db_create = NULL;
+ mapping->header = mmap (NULL, header.allocate, PROT_READ,
+ MAP_PRIVATE, fd, 0);
+ mapping->len = header.allocate;
+ if (mapping->header != MAP_FAILED)
+ status = NSS_STATUS_SUCCESS;
+ else if (errno == ENOMEM)
+ status = NSS_STATUS_TRYAGAIN;
}
- dlclose (libdb_handle);
- }
-
- (void) dlerror ();
- return NSS_STATUS_UNAVAIL;
-}
-
-/* Set the `FD_CLOEXEC' flag of FD. Return 0 on success, or -1 on
- error with `errno' set. */
-static int
-set_cloexec_flag (int fd)
-{
- int oldflags = fcntl (fd, F_GETFD, 0);
-
- if (oldflags < 0)
- return oldflags;
-
- oldflags |= FD_CLOEXEC;
-
- return fcntl (fd, F_SETFD, oldflags);
-}
-
-/* Make sure we don't use the library anymore once we are shutting down. */
-static void __attribute__ ((destructor))
-unload_db (void)
-{
- if (libdb_handle != NULL)
- {
- libdb_db_open = NULL;
- libdb_db_create = NULL;
- libdb_version = nodb;
- dlclose (libdb_handle);
- }
-}
-
-/* Open the database stored in FILE. If succesful, store the database
- handle in *DBP and return NSS_STATUS_SUCCESS. On failure, return
- the appropriate lookup status. */
-enum nss_status
-internal_setent (const char *file, NSS_DB **dbp)
-{
- enum nss_status status = NSS_STATUS_SUCCESS;
-
- if (*dbp == NULL)
- {
- if (libdb_db_open == NULL && libdb_db_create == NULL)
- {
- __libc_lock_lock (lock);
-
- if (libdb_db_open == NULL && libdb_db_create == NULL)
- status = load_db ();
-
- __libc_lock_unlock (lock);
- }
-
- if (status == NSS_STATUS_SUCCESS)
- status = dbopen (file, db_rdonly, 0, dbp);
+ close_not_cancel_no_status (fd);
}
return status;
}
-/* Close the database *DBP. */
+/* Close the database. */
void
-internal_endent (NSS_DB **dbp)
+internal_endent (struct nss_db_map *mapping)
{
- NSS_DB *db = *dbp;
-
- if (db != NULL)
- {
- DL_CALL_FCT (db->close, (db->db, 0));
- *dbp = NULL;
- }
+ munmap (mapping->header, mapping->len);
}
-
-/* Allocate a cursor for database DB and transaction TXN. On success,
- store the cursor in *DBCP and return zero. Otherwise return an
- error value. */
-int
-db_cursor (void *db, void *txn, NSS_DBC **dbcp)
-{
- NSS_DBC *dbc;
- int ret;
-
- dbc = (NSS_DBC *) malloc (sizeof (NSS_DBC));
- if (dbc == NULL)
- return ENOMEM;
-
- switch (libdb_version)
- {
- case db24:
- ret = ((struct db24 *) db)->cursor (db, txn, &dbc->cursor);
-
- if (ret == 0)
- dbc->c_get = ((struct dbc24 *) dbc->cursor)->c_get;
- break;
-
- case db27:
- ret = ((struct db27 *) db)->cursor (db, txn, &dbc->cursor, 0);
-
- if (ret == 0)
- dbc->c_get = ((struct dbc27 *) dbc->cursor)->c_get;
- break;
-
- case db30:
- ret = ((struct db30 *) db)->cursor (db, txn, &dbc->cursor, 0);
-
- if (ret == 0)
- dbc->c_get = ((struct dbc30 *) dbc->cursor)->c_get;
- break;
-
- default:
- abort ();
- }
-
- if (ret != 0)
- {
- free (dbc);
- return ret;
- }
-
- *dbcp = dbc;
-
- return 0;
-}
-
-
-/* Open the database in FNAME, for access specified by FLAGS. If
- opening the database causes the file FNAME to be created, it is
- created with MODE. If succesful, store the database handle in *DBP
- and return NSS_STATUS_SUCCESS. On failure, return the appropriate
- lookup status. */
-int
-dbopen (const char *fname, int oper, int mode, NSS_DB **dbp)
-{
- int err;
- int fd;
- NSS_DB *db;
-
- /* Construct the object we pass up. */
- db = (NSS_DB *) calloc (1, sizeof (NSS_DB));
- if (db == NULL)
- return NSS_STATUS_UNAVAIL;
-
- /* Initialize the object. */
- db->cursor = db_cursor;
-
- /* Actually open the database. */
- switch (libdb_version)
- {
- case db24:
- case db27:
- err = DL_CALL_FCT (libdb_db_open,
- (fname, DB_BTREE, oper, mode, NULL, NULL, &db->db));
- if (err != 0)
- goto fail;
-
- if (libdb_version)
- {
- db->close = ((struct db24 *) db->db)->close;
- db->fd = ((struct db24 *) db->db)->fd;
- db->get = ((struct db24 *) db->db)->get;
- db->put = ((struct db24 *) db->db)->put;
- }
- else
- {
- db->close = ((struct db27 *) db->db)->close;
- db->fd = ((struct db27 *) db->db)->fd;
- db->get = ((struct db27 *) db->db)->get;
- db->put = ((struct db27 *) db->db)->put;
- }
- break;
-
- case db30:
- err = DL_CALL_FCT (libdb_db_create, (db->db, NULL, 0));
- if (err != 0)
- goto fail;
-
- db->close = ((struct db30 *) db->db)->close;
- db->fd = ((struct db30 *) db->db)->fd;
- db->get = ((struct db30 *) db->db)->get;
- db->put = ((struct db30 *) db->db)->put;
-
- err = ((struct db30 *) db->db)->open (db->db, fname, NULL, DB_BTREE,
- oper, mode);
- if (err != 0)
- goto fail;
- break;
-
- default:
- abort ();
- }
-
[... 1329 lines stripped ...]