summaryrefslogtreecommitdiff
path: root/nss
diff options
context:
space:
mode:
authorThomas Schwinge <thomas@codesourcery.com>2012-07-22 19:58:41 +0200
committerThomas Schwinge <thomas@codesourcery.com>2012-07-22 19:58:41 +0200
commitef724a37cdb3012efb5b7233eb8b450ad91d3d69 (patch)
tree2334455220f417223cc1a75aebe76302cdffdf5a /nss
parent6f276c2517990f6569b961b4d4919cbce570ac45 (diff)
parent47e5dcdf349a1aea5c8997104ef785412f0d34fa (diff)
Merge branch 'baseline' into refs/top-bases/tschwinge/Roger_Whittaker
Conflicts: configure configure.in elf/rtld.c misc/syslog.c sysdeps/gnu/configure sysdeps/gnu/configure.in sysdeps/mach/hurd/accept4.c sysdeps/mach/hurd/bits/posix_opt.h sysdeps/mach/hurd/dup3.c sysdeps/mach/hurd/i386/init-first.c sysdeps/mach/hurd/kernel-features.h sysdeps/mach/hurd/readlinkat.c
Diffstat (limited to 'nss')
-rw-r--r--nss/Makefile2
-rw-r--r--nss/nsswitch.c110
-rw-r--r--nss/tst-nss-static.c15
3 files changed, 95 insertions, 32 deletions
diff --git a/nss/Makefile b/nss/Makefile
index 54d50d051c..a272ebe13d 100644
--- a/nss/Makefile
+++ b/nss/Makefile
@@ -75,6 +75,8 @@ libnss_db-inhibit-o = $(filter-out .os,$(object-suffixes))
ifeq ($(build-static-nss),yes)
routines += $(libnss_files-routines)
static-only-routines += $(libnss_files-routines)
+tests-static = tst-nss-static
+tests += $(tests-static)
endif
include ../Rules
diff --git a/nss/nsswitch.c b/nss/nsswitch.c
index 7acb1403fd..464f478d2b 100644
--- a/nss/nsswitch.c
+++ b/nss/nsswitch.c
@@ -1,5 +1,4 @@
-/* Copyright (C) 1996-1999,2001-2007,2009,2010,2011
- Free Software Foundation, Inc.
+/* Copyright (C) 1996-2012 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
@@ -86,6 +85,12 @@ static const char *const __nss_shlib_revision = LIBNSS_FILES_SO + 15;
/* The root of the whole data base. */
static name_database *service_table;
+/* List of default service lists that were generated by glibc because
+ /etc/nsswitch.conf did not provide a value.
+ The list is only maintained so we can free such service lists in
+ __libc_freeres. */
+static name_database_entry *defconfig_entries;
+
/* Nonzero if this is the nscd process. */
static bool is_nscd;
@@ -141,8 +146,27 @@ __nss_database_lookup (const char *database, const char *alternate_name,
DEFCONFIG specifies the default service list for this database,
or null to use the most common default. */
if (*ni == NULL)
- *ni = nss_parse_service_list (defconfig
- ?: "nis [NOTFOUND=return] files");
+ {
+ *ni = nss_parse_service_list (defconfig
+ ?: "nis [NOTFOUND=return] files");
+ if (*ni != NULL)
+ {
+ /* Record the memory we've just allocated in defconfig_entries list,
+ so we can free it later. */
+ name_database_entry *entry;
+
+ /* Allocate ENTRY plus size of name (1 here). */
+ entry = (name_database_entry *) malloc (sizeof (*entry) + 1);
+
+ if (entry != NULL)
+ {
+ entry->next = defconfig_entries;
+ entry->service = *ni;
+ entry->name[0] = '\0';
+ defconfig_entries = entry;
+ }
+ }
+ }
__libc_lock_unlock (lock);
@@ -315,7 +339,7 @@ nss_load_library (service_user *ni)
if (ni->library->lib_handle == NULL)
{
/* Load the shared library. */
- size_t shlen = (7 + strlen (ni->library->name) + 3
+ size_t shlen = (7 + strlen (ni->name) + 3
+ strlen (__nss_shlib_revision) + 1);
int saved_errno = errno;
char shlib_name[shlen];
@@ -323,7 +347,7 @@ nss_load_library (service_user *ni)
/* Construct shared object name. */
__stpcpy (__stpcpy (__stpcpy (__stpcpy (shlib_name,
"libnss_"),
- ni->library->name),
+ ni->name),
".so"),
__nss_shlib_revision);
@@ -337,14 +361,14 @@ nss_load_library (service_user *ni)
else if (is_nscd)
{
/* Call the init function when nscd is used. */
- size_t initlen = (5 + strlen (ni->library->name)
+ size_t initlen = (5 + strlen (ni->name)
+ strlen ("_init") + 1);
char init_name[initlen];
/* Construct the init function name. */
__stpcpy (__stpcpy (__stpcpy (init_name,
"_nss_"),
- ni->library->name),
+ ni->name),
"_init");
/* Find the optional init function. */
@@ -428,13 +452,13 @@ __nss_lookup_function (service_user *ni, const char *fct_name)
else
{
/* Get the desired function. */
- size_t namlen = (5 + strlen (ni->library->name) + 1
+ size_t namlen = (5 + strlen (ni->name) + 1
+ strlen (fct_name) + 1);
char name[namlen];
/* Construct the function name. */
__stpcpy (__stpcpy (__stpcpy (__stpcpy (name, "_nss_"),
- ni->library->name),
+ ni->name),
"_"),
fct_name);
@@ -457,12 +481,12 @@ __nss_lookup_function (service_user *ni, const char *fct_name)
# include "function.def"
{ NULL, NULL }
};
- size_t namlen = (5 + strlen (ni->library->name) + 1
+ size_t namlen = (5 + strlen (ni->name) + 1
+ strlen (fct_name) + 1);
char name[namlen];
/* Construct the function name. */
- __stpcpy (__stpcpy (__stpcpy (name, ni->library->name),
+ __stpcpy (__stpcpy (__stpcpy (name, ni->name),
"_"),
fct_name);
@@ -644,7 +668,7 @@ nss_parse_service_list (const char *line)
else if (__strncasecmp (name, "UNAVAIL", 7) == 0)
status = NSS_STATUS_UNAVAIL;
else
- return result;
+ goto finish;
}
else if (line - name == 8)
{
@@ -653,15 +677,15 @@ nss_parse_service_list (const char *line)
else if (__strncasecmp (name, "TRYAGAIN", 8) == 0)
status = NSS_STATUS_TRYAGAIN;
else
- return result;
+ goto finish;
}
else
- return result;
+ goto finish;
while (isspace (line[0]))
++line;
if (line[0] != '=')
- return result;
+ goto finish;
do
++line;
while (isspace (line[0]));
@@ -677,7 +701,7 @@ nss_parse_service_list (const char *line)
&& __strncasecmp (name, "CONTINUE", 8) == 0)
action = NSS_ACTION_CONTINUE;
else
- return result;
+ goto finish;
if (not)
{
@@ -705,6 +729,11 @@ nss_parse_service_list (const char *line)
*nextp = new_service;
nextp = &new_service->next;
+ continue;
+
+ finish:
+ free (new_service);
+ return result;
}
}
@@ -816,22 +845,9 @@ __nss_disable_nscd (void (*cb) (size_t, struct traced_file *))
}
#endif
-
-/* Free all resources if necessary. */
-libc_freeres_fn (free_mem)
+static void
+free_database_entries (name_database_entry *entry)
{
- name_database *top = service_table;
- name_database_entry *entry;
- service_library *library;
-
- if (top == NULL)
- /* Maybe we have not read the nsswitch.conf file. */
- return;
-
- /* Don't disturb ongoing other threads (if there are any). */
- service_table = NULL;
-
- entry = top->entry;
while (entry != NULL)
{
name_database_entry *olde = entry;
@@ -851,6 +867,36 @@ libc_freeres_fn (free_mem)
entry = entry->next;
free (olde);
}
+}
+
+/* Free all resources if necessary. */
+libc_freeres_fn (free_defconfig)
+{
+ name_database_entry *entry = defconfig_entries;
+
+ if (entry == NULL)
+ /* defconfig was not used. */
+ return;
+
+ /* Don't disturb ongoing other threads (if there are any). */
+ defconfig_entries = NULL;
+
+ free_database_entries (entry);
+}
+
+libc_freeres_fn (free_mem)
+{
+ name_database *top = service_table;
+ service_library *library;
+
+ if (top == NULL)
+ /* Maybe we have not read the nsswitch.conf file. */
+ return;
+
+ /* Don't disturb ongoing other threads (if there are any). */
+ service_table = NULL;
+
+ free_database_entries (top->entry);
library = top->library;
while (library != NULL)
diff --git a/nss/tst-nss-static.c b/nss/tst-nss-static.c
new file mode 100644
index 0000000000..98cf073deb
--- /dev/null
+++ b/nss/tst-nss-static.c
@@ -0,0 +1,15 @@
+/* glibc test for static NSS. */
+#include <stdio.h>
+
+#define TEST_FUNCTION do_test ()
+static int
+do_test (void)
+{
+ struct passwd *pw;
+
+ pw = getpwuid(0);
+ return pw == NULL;
+}
+
+
+#include "../test-skeleton.c"