Mark internal nss symbols with attribute_hidden [BZ #18822]
[glibc.git] / nss / nsswitch.c
blob834bef6f9c7844a78435d5e3f6f295cc9940f371
1 /* Copyright (C) 1996-2017 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <ctype.h>
20 #include <dlfcn.h>
21 #include <errno.h>
22 #include <netdb.h>
23 #include <libc-lock.h>
24 #include <search.h>
25 #include <stdio.h>
26 #include <stdio_ext.h>
27 #include <stdlib.h>
28 #include <string.h>
30 #include <aliases.h>
31 #include <grp.h>
32 #include <netinet/ether.h>
33 #include <pwd.h>
34 #include <shadow.h>
36 #if !defined DO_STATIC_NSS || defined SHARED
37 # include <gnu/lib-names.h>
38 #endif
40 #include "nsswitch.h"
41 #include "../nscd/nscd_proto.h"
42 #include <sysdep.h>
44 /* Prototypes for the local functions. */
45 static name_database *nss_parse_file (const char *fname) internal_function;
46 static name_database_entry *nss_getline (char *line) internal_function;
47 static service_user *nss_parse_service_list (const char *line)
48 internal_function;
49 #if !defined DO_STATIC_NSS || defined SHARED
50 static service_library *nss_new_service (name_database *database,
51 const char *name) internal_function;
52 #endif
55 /* Declare external database variables. */
56 #define DEFINE_DATABASE(name) \
57 extern service_user *__nss_##name##_database attribute_hidden; \
58 weak_extern (__nss_##name##_database)
59 #include "databases.def"
60 #undef DEFINE_DATABASE
62 /* Structure to map database name to variable. */
63 static const struct
65 const char name[10];
66 service_user **dbp;
67 } databases[] =
69 #define DEFINE_DATABASE(name) \
70 { #name, &__nss_##name##_database },
71 #include "databases.def"
72 #undef DEFINE_DATABASE
74 #define ndatabases (sizeof (databases) / sizeof (databases[0]))
76 #ifdef USE_NSCD
77 /* Flags whether custom rules for database is set. */
78 bool __nss_database_custom[NSS_DBSIDX_max];
79 #endif
82 __libc_lock_define_initialized (static, lock)
84 #if !defined DO_STATIC_NSS || defined SHARED
85 /* String with revision number of the shared object files. */
86 static const char *const __nss_shlib_revision = LIBNSS_FILES_SO + 15;
87 #endif
89 /* The root of the whole data base. */
90 static name_database *service_table;
92 /* List of default service lists that were generated by glibc because
93 /etc/nsswitch.conf did not provide a value.
94 The list is only maintained so we can free such service lists in
95 __libc_freeres. */
96 static name_database_entry *defconfig_entries;
99 #if defined USE_NSCD && (!defined DO_STATIC_NSS || defined SHARED)
100 /* Nonzero if this is the nscd process. */
101 static bool is_nscd;
102 /* The callback passed to the init functions when nscd is used. */
103 static void (*nscd_init_cb) (size_t, struct traced_file *);
104 #endif
107 /* -1 == database not found
108 0 == database entry pointer stored */
110 __nss_database_lookup (const char *database, const char *alternate_name,
111 const char *defconfig, service_user **ni)
113 /* Prevent multiple threads to change the service table. */
114 __libc_lock_lock (lock);
116 /* Reconsider database variable in case some other thread called
117 `__nss_configure_lookup' while we waited for the lock. */
118 if (*ni != NULL)
120 __libc_lock_unlock (lock);
121 return 0;
124 /* Are we initialized yet? */
125 if (service_table == NULL)
126 /* Read config file. */
127 service_table = nss_parse_file (_PATH_NSSWITCH_CONF);
129 /* Test whether configuration data is available. */
130 if (service_table != NULL)
132 /* Return first `service_user' entry for DATABASE. */
133 name_database_entry *entry;
135 /* XXX Could use some faster mechanism here. But each database is
136 only requested once and so this might not be critical. */
137 for (entry = service_table->entry; entry != NULL; entry = entry->next)
138 if (strcmp (database, entry->name) == 0)
139 *ni = entry->service;
141 if (*ni == NULL && alternate_name != NULL)
142 /* We haven't found an entry so far. Try to find it with the
143 alternative name. */
144 for (entry = service_table->entry; entry != NULL; entry = entry->next)
145 if (strcmp (alternate_name, entry->name) == 0)
146 *ni = entry->service;
149 /* No configuration data is available, either because nsswitch.conf
150 doesn't exist or because it doesn't have a line for this database.
152 DEFCONFIG specifies the default service list for this database,
153 or null to use the most common default. */
154 if (*ni == NULL)
156 *ni = nss_parse_service_list (defconfig
157 ?: "nis [NOTFOUND=return] files");
158 if (*ni != NULL)
160 /* Record the memory we've just allocated in defconfig_entries list,
161 so we can free it later. */
162 name_database_entry *entry;
164 /* Allocate ENTRY plus size of name (1 here). */
165 entry = (name_database_entry *) malloc (sizeof (*entry) + 1);
167 if (entry != NULL)
169 entry->next = defconfig_entries;
170 entry->service = *ni;
171 entry->name[0] = '\0';
172 defconfig_entries = entry;
177 __libc_lock_unlock (lock);
179 return *ni != NULL ? 0 : -1;
181 libc_hidden_def (__nss_database_lookup)
184 /* -1 == not found
185 0 == function found
186 1 == finished */
188 __nss_lookup (service_user **ni, const char *fct_name, const char *fct2_name,
189 void **fctp)
191 *fctp = __nss_lookup_function (*ni, fct_name);
192 if (*fctp == NULL && fct2_name != NULL)
193 *fctp = __nss_lookup_function (*ni, fct2_name);
195 while (*fctp == NULL
196 && nss_next_action (*ni, NSS_STATUS_UNAVAIL) == NSS_ACTION_CONTINUE
197 && (*ni)->next != NULL)
199 *ni = (*ni)->next;
201 *fctp = __nss_lookup_function (*ni, fct_name);
202 if (*fctp == NULL && fct2_name != NULL)
203 *fctp = __nss_lookup_function (*ni, fct2_name);
206 return *fctp != NULL ? 0 : (*ni)->next == NULL ? 1 : -1;
208 libc_hidden_def (__nss_lookup)
211 /* -1 == not found
212 0 == adjusted for next function
213 1 == finished */
215 __nss_next2 (service_user **ni, const char *fct_name, const char *fct2_name,
216 void **fctp, int status, int all_values)
218 if (all_values)
220 if (nss_next_action (*ni, NSS_STATUS_TRYAGAIN) == NSS_ACTION_RETURN
221 && nss_next_action (*ni, NSS_STATUS_UNAVAIL) == NSS_ACTION_RETURN
222 && nss_next_action (*ni, NSS_STATUS_NOTFOUND) == NSS_ACTION_RETURN
223 && nss_next_action (*ni, NSS_STATUS_SUCCESS) == NSS_ACTION_RETURN)
224 return 1;
226 else
228 /* This is really only for debugging. */
229 if (__builtin_expect (NSS_STATUS_TRYAGAIN > status
230 || status > NSS_STATUS_RETURN, 0))
231 __libc_fatal ("illegal status in __nss_next");
233 if (nss_next_action (*ni, status) == NSS_ACTION_RETURN)
234 return 1;
237 if ((*ni)->next == NULL)
238 return -1;
242 *ni = (*ni)->next;
244 *fctp = __nss_lookup_function (*ni, fct_name);
245 if (*fctp == NULL && fct2_name != NULL)
246 *fctp = __nss_lookup_function (*ni, fct2_name);
248 while (*fctp == NULL
249 && nss_next_action (*ni, NSS_STATUS_UNAVAIL) == NSS_ACTION_CONTINUE
250 && (*ni)->next != NULL);
252 return *fctp != NULL ? 0 : -1;
254 libc_hidden_def (__nss_next2)
258 attribute_compat_text_section
259 __nss_next (service_user **ni, const char *fct_name, void **fctp, int status,
260 int all_values)
262 return __nss_next2 (ni, fct_name, NULL, fctp, status, all_values);
267 __nss_configure_lookup (const char *dbname, const char *service_line)
269 service_user *new_db;
270 size_t cnt;
272 for (cnt = 0; cnt < ndatabases; ++cnt)
274 int cmp = strcmp (dbname, databases[cnt].name);
275 if (cmp == 0)
276 break;
277 if (cmp < 0)
279 __set_errno (EINVAL);
280 return -1;
284 if (cnt == ndatabases)
286 __set_errno (EINVAL);
287 return -1;
290 /* Test whether it is really used. */
291 if (databases[cnt].dbp == NULL)
292 /* Nothing to do, but we could do. */
293 return 0;
295 /* Try to generate new data. */
296 new_db = nss_parse_service_list (service_line);
297 if (new_db == NULL)
299 /* Illegal service specification. */
300 __set_errno (EINVAL);
301 return -1;
304 /* Prevent multiple threads to change the service table. */
305 __libc_lock_lock (lock);
307 /* Install new rules. */
308 *databases[cnt].dbp = new_db;
309 #ifdef USE_NSCD
310 __nss_database_custom[cnt] = true;
311 #endif
313 __libc_lock_unlock (lock);
315 return 0;
319 /* Comparison function for searching NI->known tree. */
320 static int
321 known_compare (const void *p1, const void *p2)
323 return p1 == p2 ? 0 : strcmp (*(const char *const *) p1,
324 *(const char *const *) p2);
328 #if !defined DO_STATIC_NSS || defined SHARED
329 /* Load library. */
330 static int
331 nss_load_library (service_user *ni)
333 if (ni->library == NULL)
335 /* This service has not yet been used. Fetch the service
336 library for it, creating a new one if need be. If there
337 is no service table from the file, this static variable
338 holds the head of the service_library list made from the
339 default configuration. */
340 static name_database default_table;
341 ni->library = nss_new_service (service_table ?: &default_table,
342 ni->name);
343 if (ni->library == NULL)
344 return -1;
347 if (ni->library->lib_handle == NULL)
349 /* Load the shared library. */
350 size_t shlen = (7 + strlen (ni->name) + 3
351 + strlen (__nss_shlib_revision) + 1);
352 int saved_errno = errno;
353 char shlib_name[shlen];
355 /* Construct shared object name. */
356 __stpcpy (__stpcpy (__stpcpy (__stpcpy (shlib_name,
357 "libnss_"),
358 ni->name),
359 ".so"),
360 __nss_shlib_revision);
362 ni->library->lib_handle = __libc_dlopen (shlib_name);
363 if (ni->library->lib_handle == NULL)
365 /* Failed to load the library. */
366 ni->library->lib_handle = (void *) -1l;
367 __set_errno (saved_errno);
369 # ifdef USE_NSCD
370 else if (is_nscd)
372 /* Call the init function when nscd is used. */
373 size_t initlen = (5 + strlen (ni->name)
374 + strlen ("_init") + 1);
375 char init_name[initlen];
377 /* Construct the init function name. */
378 __stpcpy (__stpcpy (__stpcpy (init_name,
379 "_nss_"),
380 ni->name),
381 "_init");
383 /* Find the optional init function. */
384 void (*ifct) (void (*) (size_t, struct traced_file *))
385 = __libc_dlsym (ni->library->lib_handle, init_name);
386 if (ifct != NULL)
388 void (*cb) (size_t, struct traced_file *) = nscd_init_cb;
389 # ifdef PTR_DEMANGLE
390 PTR_DEMANGLE (cb);
391 # endif
392 ifct (cb);
395 # endif
398 return 0;
400 #endif
403 void *
404 __nss_lookup_function (service_user *ni, const char *fct_name)
406 void **found, *result;
408 /* We now modify global data. Protect it. */
409 __libc_lock_lock (lock);
411 /* Search the tree of functions previously requested. Data in the
412 tree are `known_function' structures, whose first member is a
413 `const char *', the lookup key. The search returns a pointer to
414 the tree node structure; the first member of the is a pointer to
415 our structure (i.e. what will be a `known_function'); since the
416 first member of that is the lookup key string, &FCT_NAME is close
417 enough to a pointer to our structure to use as a lookup key that
418 will be passed to `known_compare' (above). */
420 found = __tsearch (&fct_name, &ni->known, &known_compare);
421 if (found == NULL)
422 /* This means out-of-memory. */
423 result = NULL;
424 else if (*found != &fct_name)
426 /* The search found an existing structure in the tree. */
427 result = ((known_function *) *found)->fct_ptr;
428 #ifdef PTR_DEMANGLE
429 PTR_DEMANGLE (result);
430 #endif
432 else
434 /* This name was not known before. Now we have a node in the tree
435 (in the proper sorted position for FCT_NAME) that points to
436 &FCT_NAME instead of any real `known_function' structure.
437 Allocate a new structure and fill it in. */
439 known_function *known = malloc (sizeof *known);
440 if (! known)
442 #if !defined DO_STATIC_NSS || defined SHARED
443 remove_from_tree:
444 #endif
445 /* Oops. We can't instantiate this node properly.
446 Remove it from the tree. */
447 __tdelete (&fct_name, &ni->known, &known_compare);
448 free (known);
449 result = NULL;
451 else
453 /* Point the tree node at this new structure. */
454 *found = known;
455 known->fct_name = fct_name;
457 #if !defined DO_STATIC_NSS || defined SHARED
458 /* Load the appropriate library. */
459 if (nss_load_library (ni) != 0)
460 /* This only happens when out of memory. */
461 goto remove_from_tree;
463 if (ni->library->lib_handle == (void *) -1l)
464 /* Library not found => function not found. */
465 result = NULL;
466 else
468 /* Get the desired function. */
469 size_t namlen = (5 + strlen (ni->name) + 1
470 + strlen (fct_name) + 1);
471 char name[namlen];
473 /* Construct the function name. */
474 __stpcpy (__stpcpy (__stpcpy (__stpcpy (name, "_nss_"),
475 ni->name),
476 "_"),
477 fct_name);
479 /* Look up the symbol. */
480 result = __libc_dlsym (ni->library->lib_handle, name);
482 #else
483 /* We can't get function address dynamically in static linking. */
485 # define DEFINE_ENT(h,nm) \
486 { #h"_get"#nm"ent_r", _nss_##h##_get##nm##ent_r }, \
487 { #h"_end"#nm"ent", _nss_##h##_end##nm##ent }, \
488 { #h"_set"#nm"ent", _nss_##h##_set##nm##ent },
489 # define DEFINE_GET(h,nm) \
490 { #h"_get"#nm"_r", _nss_##h##_get##nm##_r },
491 # define DEFINE_GETBY(h,nm,ky) \
492 { #h"_get"#nm"by"#ky"_r", _nss_##h##_get##nm##by##ky##_r },
493 static struct fct_tbl { const char *fname; void *fp; } *tp, tbl[] =
495 # include "function.def"
496 { NULL, NULL }
498 size_t namlen = (5 + strlen (ni->name) + 1
499 + strlen (fct_name) + 1);
500 char name[namlen];
502 /* Construct the function name. */
503 __stpcpy (__stpcpy (__stpcpy (name, ni->name),
504 "_"),
505 fct_name);
507 result = NULL;
508 for (tp = &tbl[0]; tp->fname; tp++)
509 if (strcmp (tp->fname, name) == 0)
511 result = tp->fp;
512 break;
515 #endif
517 /* Remember function pointer for later calls. Even if null, we
518 record it so a second try needn't search the library again. */
519 known->fct_ptr = result;
520 #ifdef PTR_MANGLE
521 PTR_MANGLE (known->fct_ptr);
522 #endif
526 /* Remove the lock. */
527 __libc_lock_unlock (lock);
529 return result;
531 libc_hidden_def (__nss_lookup_function)
534 static name_database *
535 internal_function
536 nss_parse_file (const char *fname)
538 FILE *fp;
539 name_database *result;
540 name_database_entry *last;
541 char *line;
542 size_t len;
544 /* Open the configuration file. */
545 fp = fopen (fname, "rce");
546 if (fp == NULL)
547 return NULL;
549 /* No threads use this stream. */
550 __fsetlocking (fp, FSETLOCKING_BYCALLER);
552 result = (name_database *) malloc (sizeof (name_database));
553 if (result == NULL)
555 fclose (fp);
556 return NULL;
559 result->entry = NULL;
560 result->library = NULL;
561 last = NULL;
562 line = NULL;
563 len = 0;
566 name_database_entry *this;
567 ssize_t n;
569 n = __getline (&line, &len, fp);
570 if (n < 0)
571 break;
572 if (line[n - 1] == '\n')
573 line[n - 1] = '\0';
575 /* Because the file format does not know any form of quoting we
576 can search forward for the next '#' character and if found
577 make it terminating the line. */
578 *__strchrnul (line, '#') = '\0';
580 /* If the line is blank it is ignored. */
581 if (line[0] == '\0')
582 continue;
584 /* Each line completely specifies the actions for a database. */
585 this = nss_getline (line);
586 if (this != NULL)
588 if (last != NULL)
589 last->next = this;
590 else
591 result->entry = this;
593 last = this;
596 while (!feof_unlocked (fp));
598 /* Free the buffer. */
599 free (line);
600 /* Close configuration file. */
601 fclose (fp);
603 return result;
607 /* Read the source names:
608 `( <source> ( "[" "!"? (<status> "=" <action> )+ "]" )? )*'
610 static service_user *
611 internal_function
612 nss_parse_service_list (const char *line)
614 service_user *result = NULL, **nextp = &result;
616 while (1)
618 service_user *new_service;
619 const char *name;
621 while (isspace (line[0]))
622 ++line;
623 if (line[0] == '\0')
624 /* No source specified. */
625 return result;
627 /* Read <source> identifier. */
628 name = line;
629 while (line[0] != '\0' && !isspace (line[0]) && line[0] != '[')
630 ++line;
631 if (name == line)
632 return result;
635 new_service = (service_user *) malloc (sizeof (service_user)
636 + (line - name + 1));
637 if (new_service == NULL)
638 return result;
640 *((char *) __mempcpy (new_service->name, name, line - name)) = '\0';
642 /* Set default actions. */
643 new_service->actions[2 + NSS_STATUS_TRYAGAIN] = NSS_ACTION_CONTINUE;
644 new_service->actions[2 + NSS_STATUS_UNAVAIL] = NSS_ACTION_CONTINUE;
645 new_service->actions[2 + NSS_STATUS_NOTFOUND] = NSS_ACTION_CONTINUE;
646 new_service->actions[2 + NSS_STATUS_SUCCESS] = NSS_ACTION_RETURN;
647 new_service->actions[2 + NSS_STATUS_RETURN] = NSS_ACTION_RETURN;
648 new_service->library = NULL;
649 new_service->known = NULL;
650 new_service->next = NULL;
652 while (isspace (line[0]))
653 ++line;
655 if (line[0] == '[')
657 /* Read criterions. */
659 ++line;
660 while (line[0] != '\0' && isspace (line[0]));
664 int not;
665 enum nss_status status;
666 lookup_actions action;
668 /* Grok ! before name to mean all statii but that one. */
669 not = line[0] == '!';
670 if (not)
671 ++line;
673 /* Read status name. */
674 name = line;
675 while (line[0] != '\0' && !isspace (line[0]) && line[0] != '='
676 && line[0] != ']')
677 ++line;
679 /* Compare with known statii. */
680 if (line - name == 7)
682 if (__strncasecmp (name, "SUCCESS", 7) == 0)
683 status = NSS_STATUS_SUCCESS;
684 else if (__strncasecmp (name, "UNAVAIL", 7) == 0)
685 status = NSS_STATUS_UNAVAIL;
686 else
687 goto finish;
689 else if (line - name == 8)
691 if (__strncasecmp (name, "NOTFOUND", 8) == 0)
692 status = NSS_STATUS_NOTFOUND;
693 else if (__strncasecmp (name, "TRYAGAIN", 8) == 0)
694 status = NSS_STATUS_TRYAGAIN;
695 else
696 goto finish;
698 else
699 goto finish;
701 while (isspace (line[0]))
702 ++line;
703 if (line[0] != '=')
704 goto finish;
706 ++line;
707 while (isspace (line[0]));
709 name = line;
710 while (line[0] != '\0' && !isspace (line[0]) && line[0] != '='
711 && line[0] != ']')
712 ++line;
714 if (line - name == 6 && __strncasecmp (name, "RETURN", 6) == 0)
715 action = NSS_ACTION_RETURN;
716 else if (line - name == 8
717 && __strncasecmp (name, "CONTINUE", 8) == 0)
718 action = NSS_ACTION_CONTINUE;
719 else if (line - name == 5
720 && __strncasecmp (name, "MERGE", 5) == 0)
721 action = NSS_ACTION_MERGE;
722 else
723 goto finish;
725 if (not)
727 /* Save the current action setting for this status,
728 set them all to the given action, and reset this one. */
729 const lookup_actions save = new_service->actions[2 + status];
730 new_service->actions[2 + NSS_STATUS_TRYAGAIN] = action;
731 new_service->actions[2 + NSS_STATUS_UNAVAIL] = action;
732 new_service->actions[2 + NSS_STATUS_NOTFOUND] = action;
733 new_service->actions[2 + NSS_STATUS_SUCCESS] = action;
734 new_service->actions[2 + status] = save;
736 else
737 new_service->actions[2 + status] = action;
739 /* Skip white spaces. */
740 while (isspace (line[0]))
741 ++line;
743 while (line[0] != ']');
745 /* Skip the ']'. */
746 ++line;
749 *nextp = new_service;
750 nextp = &new_service->next;
751 continue;
753 finish:
754 free (new_service);
755 return result;
759 static name_database_entry *
760 internal_function
761 nss_getline (char *line)
763 const char *name;
764 name_database_entry *result;
765 size_t len;
767 /* Ignore leading white spaces. ATTENTION: this is different from
768 what is implemented in Solaris. The Solaris man page says a line
769 beginning with a white space character is ignored. We regard
770 this as just another misfeature in Solaris. */
771 while (isspace (line[0]))
772 ++line;
774 /* Recognize `<database> ":"'. */
775 name = line;
776 while (line[0] != '\0' && !isspace (line[0]) && line[0] != ':')
777 ++line;
778 if (line[0] == '\0' || name == line)
779 /* Syntax error. */
780 return NULL;
781 *line++ = '\0';
783 len = strlen (name) + 1;
785 result = (name_database_entry *) malloc (sizeof (name_database_entry) + len);
786 if (result == NULL)
787 return NULL;
789 /* Save the database name. */
790 memcpy (result->name, name, len);
792 /* Parse the list of services. */
793 result->service = nss_parse_service_list (line);
795 result->next = NULL;
796 return result;
800 #if !defined DO_STATIC_NSS || defined SHARED
801 static service_library *
802 internal_function
803 nss_new_service (name_database *database, const char *name)
805 service_library **currentp = &database->library;
807 while (*currentp != NULL)
809 if (strcmp ((*currentp)->name, name) == 0)
810 return *currentp;
811 currentp = &(*currentp)->next;
814 /* We have to add the new service. */
815 *currentp = (service_library *) malloc (sizeof (service_library));
816 if (*currentp == NULL)
817 return NULL;
819 (*currentp)->name = name;
820 (*currentp)->lib_handle = NULL;
821 (*currentp)->next = NULL;
823 return *currentp;
825 #endif
828 #if defined SHARED && defined USE_NSCD
829 /* Load all libraries for the service. */
830 static void
831 nss_load_all_libraries (const char *service, const char *def)
833 service_user *ni = NULL;
835 if (__nss_database_lookup (service, NULL, def, &ni) == 0)
836 while (ni != NULL)
838 nss_load_library (ni);
839 ni = ni->next;
844 /* Called by nscd and nscd alone. */
845 void
846 __nss_disable_nscd (void (*cb) (size_t, struct traced_file *))
848 # ifdef PTR_MANGLE
849 PTR_MANGLE (cb);
850 # endif
851 nscd_init_cb = cb;
852 is_nscd = true;
854 /* Find all the relevant modules so that the init functions are called. */
855 nss_load_all_libraries ("passwd", "compat [NOTFOUND=return] files");
856 nss_load_all_libraries ("group", "compat [NOTFOUND=return] files");
857 nss_load_all_libraries ("hosts", "dns [!UNAVAIL=return] files");
858 nss_load_all_libraries ("services", NULL);
860 /* Disable all uses of NSCD. */
861 __nss_not_use_nscd_passwd = -1;
862 __nss_not_use_nscd_group = -1;
863 __nss_not_use_nscd_hosts = -1;
864 __nss_not_use_nscd_services = -1;
865 __nss_not_use_nscd_netgroup = -1;
867 #endif
869 static void
870 free_database_entries (name_database_entry *entry)
872 while (entry != NULL)
874 name_database_entry *olde = entry;
875 service_user *service = entry->service;
877 while (service != NULL)
879 service_user *olds = service;
881 if (service->known != NULL)
882 __tdestroy (service->known, free);
884 service = service->next;
885 free (olds);
888 entry = entry->next;
889 free (olde);
893 /* Free all resources if necessary. */
894 libc_freeres_fn (free_defconfig)
896 name_database_entry *entry = defconfig_entries;
898 if (entry == NULL)
899 /* defconfig was not used. */
900 return;
902 /* Don't disturb ongoing other threads (if there are any). */
903 defconfig_entries = NULL;
905 free_database_entries (entry);
908 libc_freeres_fn (free_mem)
910 name_database *top = service_table;
911 service_library *library;
913 if (top == NULL)
914 /* Maybe we have not read the nsswitch.conf file. */
915 return;
917 /* Don't disturb ongoing other threads (if there are any). */
918 service_table = NULL;
920 free_database_entries (top->entry);
922 library = top->library;
923 while (library != NULL)
925 service_library *oldl = library;
927 if (library->lib_handle && library->lib_handle != (void *) -1l)
928 __libc_dlclose (library->lib_handle);
930 library = library->next;
931 free (oldl);
934 free (top);