Fix LOG_MAKEPRI to agree with BSD
[glibc.git] / nss / nsswitch.c
blob464f478d2b7f5c90aae2a0e54ff0a9618a2ef2f1
1 /* Copyright (C) 1996-2012 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 <bits/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 static service_library *nss_new_service (name_database *database,
50 const char *name) internal_function;
53 /* Declare external database variables. */
54 #define DEFINE_DATABASE(name) \
55 extern service_user *__nss_##name##_database attribute_hidden; \
56 weak_extern (__nss_##name##_database)
57 #include "databases.def"
58 #undef DEFINE_DATABASE
60 /* Structure to map database name to variable. */
61 static const struct
63 const char name[10];
64 service_user **dbp;
65 } databases[] =
67 #define DEFINE_DATABASE(name) \
68 { #name, &__nss_##name##_database },
69 #include "databases.def"
70 #undef DEFINE_DATABASE
72 #define ndatabases (sizeof (databases) / sizeof (databases[0]))
74 /* Flags whether custom rules for database is set. */
75 bool __nss_database_custom[NSS_DBSIDX_max];
78 __libc_lock_define_initialized (static, lock)
80 #if !defined DO_STATIC_NSS || defined SHARED
81 /* String with revision number of the shared object files. */
82 static const char *const __nss_shlib_revision = LIBNSS_FILES_SO + 15;
83 #endif
85 /* The root of the whole data base. */
86 static name_database *service_table;
88 /* List of default service lists that were generated by glibc because
89 /etc/nsswitch.conf did not provide a value.
90 The list is only maintained so we can free such service lists in
91 __libc_freeres. */
92 static name_database_entry *defconfig_entries;
95 /* Nonzero if this is the nscd process. */
96 static bool is_nscd;
97 /* The callback passed to the init functions when nscd is used. */
98 static void (*nscd_init_cb) (size_t, struct traced_file *);
101 /* -1 == database not found
102 0 == database entry pointer stored */
104 __nss_database_lookup (const char *database, const char *alternate_name,
105 const char *defconfig, service_user **ni)
107 /* Prevent multiple threads to change the service table. */
108 __libc_lock_lock (lock);
110 /* Reconsider database variable in case some other thread called
111 `__nss_configure_lookup' while we waited for the lock. */
112 if (*ni != NULL)
114 __libc_lock_unlock (lock);
115 return 0;
118 /* Are we initialized yet? */
119 if (service_table == NULL)
120 /* Read config file. */
121 service_table = nss_parse_file (_PATH_NSSWITCH_CONF);
123 /* Test whether configuration data is available. */
124 if (service_table != NULL)
126 /* Return first `service_user' entry for DATABASE. */
127 name_database_entry *entry;
129 /* XXX Could use some faster mechanism here. But each database is
130 only requested once and so this might not be critical. */
131 for (entry = service_table->entry; entry != NULL; entry = entry->next)
132 if (strcmp (database, entry->name) == 0)
133 *ni = entry->service;
135 if (*ni == NULL && alternate_name != NULL)
136 /* We haven't found an entry so far. Try to find it with the
137 alternative name. */
138 for (entry = service_table->entry; entry != NULL; entry = entry->next)
139 if (strcmp (alternate_name, entry->name) == 0)
140 *ni = entry->service;
143 /* No configuration data is available, either because nsswitch.conf
144 doesn't exist or because it doesn't have a line for this database.
146 DEFCONFIG specifies the default service list for this database,
147 or null to use the most common default. */
148 if (*ni == NULL)
150 *ni = nss_parse_service_list (defconfig
151 ?: "nis [NOTFOUND=return] files");
152 if (*ni != NULL)
154 /* Record the memory we've just allocated in defconfig_entries list,
155 so we can free it later. */
156 name_database_entry *entry;
158 /* Allocate ENTRY plus size of name (1 here). */
159 entry = (name_database_entry *) malloc (sizeof (*entry) + 1);
161 if (entry != NULL)
163 entry->next = defconfig_entries;
164 entry->service = *ni;
165 entry->name[0] = '\0';
166 defconfig_entries = entry;
171 __libc_lock_unlock (lock);
173 return *ni != NULL ? 0 : -1;
175 libc_hidden_def (__nss_database_lookup)
178 /* -1 == not found
179 0 == function found
180 1 == finished */
182 __nss_lookup (service_user **ni, const char *fct_name, const char *fct2_name,
183 void **fctp)
185 *fctp = __nss_lookup_function (*ni, fct_name);
186 if (*fctp == NULL && fct2_name != NULL)
187 *fctp = __nss_lookup_function (*ni, fct2_name);
189 while (*fctp == NULL
190 && nss_next_action (*ni, NSS_STATUS_UNAVAIL) == NSS_ACTION_CONTINUE
191 && (*ni)->next != NULL)
193 *ni = (*ni)->next;
195 *fctp = __nss_lookup_function (*ni, fct_name);
196 if (*fctp == NULL && fct2_name != NULL)
197 *fctp = __nss_lookup_function (*ni, fct2_name);
200 return *fctp != NULL ? 0 : (*ni)->next == NULL ? 1 : -1;
202 libc_hidden_def (__nss_lookup)
205 /* -1 == not found
206 0 == adjusted for next function
207 1 == finished */
209 __nss_next2 (service_user **ni, const char *fct_name, const char *fct2_name,
210 void **fctp, int status, int all_values)
212 if (all_values)
214 if (nss_next_action (*ni, NSS_STATUS_TRYAGAIN) == NSS_ACTION_RETURN
215 && nss_next_action (*ni, NSS_STATUS_UNAVAIL) == NSS_ACTION_RETURN
216 && nss_next_action (*ni, NSS_STATUS_NOTFOUND) == NSS_ACTION_RETURN
217 && nss_next_action (*ni, NSS_STATUS_SUCCESS) == NSS_ACTION_RETURN)
218 return 1;
220 else
222 /* This is really only for debugging. */
223 if (__builtin_expect (NSS_STATUS_TRYAGAIN > status
224 || status > NSS_STATUS_RETURN, 0))
225 __libc_fatal ("illegal status in __nss_next");
227 if (nss_next_action (*ni, status) == NSS_ACTION_RETURN)
228 return 1;
231 if ((*ni)->next == NULL)
232 return -1;
236 *ni = (*ni)->next;
238 *fctp = __nss_lookup_function (*ni, fct_name);
239 if (*fctp == NULL && fct2_name != NULL)
240 *fctp = __nss_lookup_function (*ni, fct2_name);
242 while (*fctp == NULL
243 && nss_next_action (*ni, NSS_STATUS_UNAVAIL) == NSS_ACTION_CONTINUE
244 && (*ni)->next != NULL);
246 return *fctp != NULL ? 0 : -1;
248 libc_hidden_def (__nss_next2)
252 attribute_compat_text_section
253 __nss_next (service_user **ni, const char *fct_name, void **fctp, int status,
254 int all_values)
256 return __nss_next2 (ni, fct_name, NULL, fctp, status, all_values);
261 __nss_configure_lookup (const char *dbname, const char *service_line)
263 service_user *new_db;
264 size_t cnt;
266 for (cnt = 0; cnt < ndatabases; ++cnt)
268 int cmp = strcmp (dbname, databases[cnt].name);
269 if (cmp == 0)
270 break;
271 if (cmp < 0)
273 __set_errno (EINVAL);
274 return -1;
278 if (cnt == ndatabases)
280 __set_errno (EINVAL);
281 return -1;
284 /* Test whether it is really used. */
285 if (databases[cnt].dbp == NULL)
286 /* Nothing to do, but we could do. */
287 return 0;
289 /* Try to generate new data. */
290 new_db = nss_parse_service_list (service_line);
291 if (new_db == NULL)
293 /* Illegal service specification. */
294 __set_errno (EINVAL);
295 return -1;
298 /* Prevent multiple threads to change the service table. */
299 __libc_lock_lock (lock);
301 /* Install new rules. */
302 *databases[cnt].dbp = new_db;
303 __nss_database_custom[cnt] = true;
305 __libc_lock_unlock (lock);
307 return 0;
311 /* Comparison function for searching NI->known tree. */
312 static int
313 known_compare (const void *p1, const void *p2)
315 return p1 == p2 ? 0 : strcmp (*(const char *const *) p1,
316 *(const char *const *) p2);
320 #if !defined DO_STATIC_NSS || defined SHARED
321 /* Load library. */
322 static int
323 nss_load_library (service_user *ni)
325 if (ni->library == NULL)
327 /* This service has not yet been used. Fetch the service
328 library for it, creating a new one if need be. If there
329 is no service table from the file, this static variable
330 holds the head of the service_library list made from the
331 default configuration. */
332 static name_database default_table;
333 ni->library = nss_new_service (service_table ?: &default_table,
334 ni->name);
335 if (ni->library == NULL)
336 return -1;
339 if (ni->library->lib_handle == NULL)
341 /* Load the shared library. */
342 size_t shlen = (7 + strlen (ni->name) + 3
343 + strlen (__nss_shlib_revision) + 1);
344 int saved_errno = errno;
345 char shlib_name[shlen];
347 /* Construct shared object name. */
348 __stpcpy (__stpcpy (__stpcpy (__stpcpy (shlib_name,
349 "libnss_"),
350 ni->name),
351 ".so"),
352 __nss_shlib_revision);
354 ni->library->lib_handle = __libc_dlopen (shlib_name);
355 if (ni->library->lib_handle == NULL)
357 /* Failed to load the library. */
358 ni->library->lib_handle = (void *) -1l;
359 __set_errno (saved_errno);
361 else if (is_nscd)
363 /* Call the init function when nscd is used. */
364 size_t initlen = (5 + strlen (ni->name)
365 + strlen ("_init") + 1);
366 char init_name[initlen];
368 /* Construct the init function name. */
369 __stpcpy (__stpcpy (__stpcpy (init_name,
370 "_nss_"),
371 ni->name),
372 "_init");
374 /* Find the optional init function. */
375 void (*ifct) (void (*) (size_t, struct traced_file *))
376 = __libc_dlsym (ni->library->lib_handle, init_name);
377 if (ifct != NULL)
379 void (*cb) (size_t, struct traced_file *) = nscd_init_cb;
380 # ifdef PTR_DEMANGLE
381 PTR_DEMANGLE (cb);
382 # endif
383 ifct (cb);
388 return 0;
390 #endif
393 void *
394 __nss_lookup_function (service_user *ni, const char *fct_name)
396 void **found, *result;
398 /* We now modify global data. Protect it. */
399 __libc_lock_lock (lock);
401 /* Search the tree of functions previously requested. Data in the
402 tree are `known_function' structures, whose first member is a
403 `const char *', the lookup key. The search returns a pointer to
404 the tree node structure; the first member of the is a pointer to
405 our structure (i.e. what will be a `known_function'); since the
406 first member of that is the lookup key string, &FCT_NAME is close
407 enough to a pointer to our structure to use as a lookup key that
408 will be passed to `known_compare' (above). */
410 found = __tsearch (&fct_name, &ni->known, &known_compare);
411 if (found == NULL)
412 /* This means out-of-memory. */
413 result = NULL;
414 else if (*found != &fct_name)
416 /* The search found an existing structure in the tree. */
417 result = ((known_function *) *found)->fct_ptr;
418 PTR_DEMANGLE (result);
420 else
422 /* This name was not known before. Now we have a node in the tree
423 (in the proper sorted position for FCT_NAME) that points to
424 &FCT_NAME instead of any real `known_function' structure.
425 Allocate a new structure and fill it in. */
427 known_function *known = malloc (sizeof *known);
428 if (! known)
430 remove_from_tree:
431 /* Oops. We can't instantiate this node properly.
432 Remove it from the tree. */
433 __tdelete (&fct_name, &ni->known, &known_compare);
434 free (known);
435 result = NULL;
437 else
439 /* Point the tree node at this new structure. */
440 *found = known;
441 known->fct_name = fct_name;
443 #if !defined DO_STATIC_NSS || defined SHARED
444 /* Load the appropriate library. */
445 if (nss_load_library (ni) != 0)
446 /* This only happens when out of memory. */
447 goto remove_from_tree;
449 if (ni->library->lib_handle == (void *) -1l)
450 /* Library not found => function not found. */
451 result = NULL;
452 else
454 /* Get the desired function. */
455 size_t namlen = (5 + strlen (ni->name) + 1
456 + strlen (fct_name) + 1);
457 char name[namlen];
459 /* Construct the function name. */
460 __stpcpy (__stpcpy (__stpcpy (__stpcpy (name, "_nss_"),
461 ni->name),
462 "_"),
463 fct_name);
465 /* Look up the symbol. */
466 result = __libc_dlsym (ni->library->lib_handle, name);
468 #else
469 /* We can't get function address dynamically in static linking. */
471 # define DEFINE_ENT(h,nm) \
472 { #h"_get"#nm"ent_r", _nss_##h##_get##nm##ent_r }, \
473 { #h"_end"#nm"ent", _nss_##h##_end##nm##ent }, \
474 { #h"_set"#nm"ent", _nss_##h##_set##nm##ent },
475 # define DEFINE_GET(h,nm) \
476 { #h"_get"#nm"_r", _nss_##h##_get##nm##_r },
477 # define DEFINE_GETBY(h,nm,ky) \
478 { #h"_get"#nm"by"#ky"_r", _nss_##h##_get##nm##by##ky##_r },
479 static struct fct_tbl { const char *fname; void *fp; } *tp, tbl[] =
481 # include "function.def"
482 { NULL, NULL }
484 size_t namlen = (5 + strlen (ni->name) + 1
485 + strlen (fct_name) + 1);
486 char name[namlen];
488 /* Construct the function name. */
489 __stpcpy (__stpcpy (__stpcpy (name, ni->name),
490 "_"),
491 fct_name);
493 result = NULL;
494 for (tp = &tbl[0]; tp->fname; tp++)
495 if (strcmp (tp->fname, name) == 0)
497 result = tp->fp;
498 break;
501 #endif
503 /* Remember function pointer for later calls. Even if null, we
504 record it so a second try needn't search the library again. */
505 known->fct_ptr = result;
506 PTR_MANGLE (known->fct_ptr);
510 /* Remove the lock. */
511 __libc_lock_unlock (lock);
513 return result;
515 libc_hidden_def (__nss_lookup_function)
518 static name_database *
519 internal_function
520 nss_parse_file (const char *fname)
522 FILE *fp;
523 name_database *result;
524 name_database_entry *last;
525 char *line;
526 size_t len;
528 /* Open the configuration file. */
529 fp = fopen (fname, "rce");
530 if (fp == NULL)
531 return NULL;
533 /* No threads use this stream. */
534 __fsetlocking (fp, FSETLOCKING_BYCALLER);
536 result = (name_database *) malloc (sizeof (name_database));
537 if (result == NULL)
539 fclose (fp);
540 return NULL;
543 result->entry = NULL;
544 result->library = NULL;
545 last = NULL;
546 line = NULL;
547 len = 0;
550 name_database_entry *this;
551 ssize_t n;
553 n = __getline (&line, &len, fp);
554 if (n < 0)
555 break;
556 if (line[n - 1] == '\n')
557 line[n - 1] = '\0';
559 /* Because the file format does not know any form of quoting we
560 can search forward for the next '#' character and if found
561 make it terminating the line. */
562 *__strchrnul (line, '#') = '\0';
564 /* If the line is blank it is ignored. */
565 if (line[0] == '\0')
566 continue;
568 /* Each line completely specifies the actions for a database. */
569 this = nss_getline (line);
570 if (this != NULL)
572 if (last != NULL)
573 last->next = this;
574 else
575 result->entry = this;
577 last = this;
580 while (!feof_unlocked (fp));
582 /* Free the buffer. */
583 free (line);
584 /* Close configuration file. */
585 fclose (fp);
587 return result;
591 /* Read the source names:
592 `( <source> ( "[" "!"? (<status> "=" <action> )+ "]" )? )*'
594 static service_user *
595 internal_function
596 nss_parse_service_list (const char *line)
598 service_user *result = NULL, **nextp = &result;
600 while (1)
602 service_user *new_service;
603 const char *name;
605 while (isspace (line[0]))
606 ++line;
607 if (line[0] == '\0')
608 /* No source specified. */
609 return result;
611 /* Read <source> identifier. */
612 name = line;
613 while (line[0] != '\0' && !isspace (line[0]) && line[0] != '[')
614 ++line;
615 if (name == line)
616 return result;
619 new_service = (service_user *) malloc (sizeof (service_user)
620 + (line - name + 1));
621 if (new_service == NULL)
622 return result;
624 *((char *) __mempcpy (new_service->name, name, line - name)) = '\0';
626 /* Set default actions. */
627 new_service->actions[2 + NSS_STATUS_TRYAGAIN] = NSS_ACTION_CONTINUE;
628 new_service->actions[2 + NSS_STATUS_UNAVAIL] = NSS_ACTION_CONTINUE;
629 new_service->actions[2 + NSS_STATUS_NOTFOUND] = NSS_ACTION_CONTINUE;
630 new_service->actions[2 + NSS_STATUS_SUCCESS] = NSS_ACTION_RETURN;
631 new_service->actions[2 + NSS_STATUS_RETURN] = NSS_ACTION_RETURN;
632 new_service->library = NULL;
633 new_service->known = NULL;
634 new_service->next = NULL;
636 while (isspace (line[0]))
637 ++line;
639 if (line[0] == '[')
641 /* Read criterions. */
643 ++line;
644 while (line[0] != '\0' && isspace (line[0]));
648 int not;
649 enum nss_status status;
650 lookup_actions action;
652 /* Grok ! before name to mean all statii but that one. */
653 not = line[0] == '!';
654 if (not)
655 ++line;
657 /* Read status name. */
658 name = line;
659 while (line[0] != '\0' && !isspace (line[0]) && line[0] != '='
660 && line[0] != ']')
661 ++line;
663 /* Compare with known statii. */
664 if (line - name == 7)
666 if (__strncasecmp (name, "SUCCESS", 7) == 0)
667 status = NSS_STATUS_SUCCESS;
668 else if (__strncasecmp (name, "UNAVAIL", 7) == 0)
669 status = NSS_STATUS_UNAVAIL;
670 else
671 goto finish;
673 else if (line - name == 8)
675 if (__strncasecmp (name, "NOTFOUND", 8) == 0)
676 status = NSS_STATUS_NOTFOUND;
677 else if (__strncasecmp (name, "TRYAGAIN", 8) == 0)
678 status = NSS_STATUS_TRYAGAIN;
679 else
680 goto finish;
682 else
683 goto finish;
685 while (isspace (line[0]))
686 ++line;
687 if (line[0] != '=')
688 goto finish;
690 ++line;
691 while (isspace (line[0]));
693 name = line;
694 while (line[0] != '\0' && !isspace (line[0]) && line[0] != '='
695 && line[0] != ']')
696 ++line;
698 if (line - name == 6 && __strncasecmp (name, "RETURN", 6) == 0)
699 action = NSS_ACTION_RETURN;
700 else if (line - name == 8
701 && __strncasecmp (name, "CONTINUE", 8) == 0)
702 action = NSS_ACTION_CONTINUE;
703 else
704 goto finish;
706 if (not)
708 /* Save the current action setting for this status,
709 set them all to the given action, and reset this one. */
710 const lookup_actions save = new_service->actions[2 + status];
711 new_service->actions[2 + NSS_STATUS_TRYAGAIN] = action;
712 new_service->actions[2 + NSS_STATUS_UNAVAIL] = action;
713 new_service->actions[2 + NSS_STATUS_NOTFOUND] = action;
714 new_service->actions[2 + NSS_STATUS_SUCCESS] = action;
715 new_service->actions[2 + status] = save;
717 else
718 new_service->actions[2 + status] = action;
720 /* Skip white spaces. */
721 while (isspace (line[0]))
722 ++line;
724 while (line[0] != ']');
726 /* Skip the ']'. */
727 ++line;
730 *nextp = new_service;
731 nextp = &new_service->next;
732 continue;
734 finish:
735 free (new_service);
736 return result;
740 static name_database_entry *
741 internal_function
742 nss_getline (char *line)
744 const char *name;
745 name_database_entry *result;
746 size_t len;
748 /* Ignore leading white spaces. ATTENTION: this is different from
749 what is implemented in Solaris. The Solaris man page says a line
750 beginning with a white space character is ignored. We regard
751 this as just another misfeature in Solaris. */
752 while (isspace (line[0]))
753 ++line;
755 /* Recognize `<database> ":"'. */
756 name = line;
757 while (line[0] != '\0' && !isspace (line[0]) && line[0] != ':')
758 ++line;
759 if (line[0] == '\0' || name == line)
760 /* Syntax error. */
761 return NULL;
762 *line++ = '\0';
764 len = strlen (name) + 1;
766 result = (name_database_entry *) malloc (sizeof (name_database_entry) + len);
767 if (result == NULL)
768 return NULL;
770 /* Save the database name. */
771 memcpy (result->name, name, len);
773 /* Parse the list of services. */
774 result->service = nss_parse_service_list (line);
776 result->next = NULL;
777 return result;
781 static service_library *
782 internal_function
783 nss_new_service (name_database *database, const char *name)
785 service_library **currentp = &database->library;
787 while (*currentp != NULL)
789 if (strcmp ((*currentp)->name, name) == 0)
790 return *currentp;
791 currentp = &(*currentp)->next;
794 /* We have to add the new service. */
795 *currentp = (service_library *) malloc (sizeof (service_library));
796 if (*currentp == NULL)
797 return NULL;
799 (*currentp)->name = name;
800 (*currentp)->lib_handle = NULL;
801 (*currentp)->next = NULL;
803 return *currentp;
807 #ifdef SHARED
808 /* Load all libraries for the service. */
809 static void
810 nss_load_all_libraries (const char *service, const char *def)
812 service_user *ni = NULL;
814 if (__nss_database_lookup (service, NULL, def, &ni) == 0)
815 while (ni != NULL)
817 nss_load_library (ni);
818 ni = ni->next;
823 /* Called by nscd and nscd alone. */
824 void
825 __nss_disable_nscd (void (*cb) (size_t, struct traced_file *))
827 # ifdef PTR_MANGLE
828 PTR_MANGLE (cb);
829 # endif
830 nscd_init_cb = cb;
831 is_nscd = true;
833 /* Find all the relevant modules so that the init functions are called. */
834 nss_load_all_libraries ("passwd", "compat [NOTFOUND=return] files");
835 nss_load_all_libraries ("group", "compat [NOTFOUND=return] files");
836 nss_load_all_libraries ("hosts", "dns [!UNAVAIL=return] files");
837 nss_load_all_libraries ("services", NULL);
839 /* Disable all uses of NSCD. */
840 __nss_not_use_nscd_passwd = -1;
841 __nss_not_use_nscd_group = -1;
842 __nss_not_use_nscd_hosts = -1;
843 __nss_not_use_nscd_services = -1;
844 __nss_not_use_nscd_netgroup = -1;
846 #endif
848 static void
849 free_database_entries (name_database_entry *entry)
851 while (entry != NULL)
853 name_database_entry *olde = entry;
854 service_user *service = entry->service;
856 while (service != NULL)
858 service_user *olds = service;
860 if (service->known != NULL)
861 __tdestroy (service->known, free);
863 service = service->next;
864 free (olds);
867 entry = entry->next;
868 free (olde);
872 /* Free all resources if necessary. */
873 libc_freeres_fn (free_defconfig)
875 name_database_entry *entry = defconfig_entries;
877 if (entry == NULL)
878 /* defconfig was not used. */
879 return;
881 /* Don't disturb ongoing other threads (if there are any). */
882 defconfig_entries = NULL;
884 free_database_entries (entry);
887 libc_freeres_fn (free_mem)
889 name_database *top = service_table;
890 service_library *library;
892 if (top == NULL)
893 /* Maybe we have not read the nsswitch.conf file. */
894 return;
896 /* Don't disturb ongoing other threads (if there are any). */
897 service_table = NULL;
899 free_database_entries (top->entry);
901 library = top->library;
902 while (library != NULL)
904 service_library *oldl = library;
906 if (library->lib_handle && library->lib_handle != (void *) -1l)
907 __libc_dlclose (library->lib_handle);
909 library = library->next;
910 free (oldl);
913 free (top);