alpha: Purge __ASSUME_STAT64_SYSCALL
[glibc.git] / nss / nsswitch.c
bloba2628c747c91dd964372202586b6a291df513b72
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 #ifdef PTR_DEMANGLE
419 PTR_DEMANGLE (result);
420 #endif
422 else
424 /* This name was not known before. Now we have a node in the tree
425 (in the proper sorted position for FCT_NAME) that points to
426 &FCT_NAME instead of any real `known_function' structure.
427 Allocate a new structure and fill it in. */
429 known_function *known = malloc (sizeof *known);
430 if (! known)
432 remove_from_tree:
433 /* Oops. We can't instantiate this node properly.
434 Remove it from the tree. */
435 __tdelete (&fct_name, &ni->known, &known_compare);
436 free (known);
437 result = NULL;
439 else
441 /* Point the tree node at this new structure. */
442 *found = known;
443 known->fct_name = fct_name;
445 #if !defined DO_STATIC_NSS || defined SHARED
446 /* Load the appropriate library. */
447 if (nss_load_library (ni) != 0)
448 /* This only happens when out of memory. */
449 goto remove_from_tree;
451 if (ni->library->lib_handle == (void *) -1l)
452 /* Library not found => function not found. */
453 result = NULL;
454 else
456 /* Get the desired function. */
457 size_t namlen = (5 + strlen (ni->name) + 1
458 + strlen (fct_name) + 1);
459 char name[namlen];
461 /* Construct the function name. */
462 __stpcpy (__stpcpy (__stpcpy (__stpcpy (name, "_nss_"),
463 ni->name),
464 "_"),
465 fct_name);
467 /* Look up the symbol. */
468 result = __libc_dlsym (ni->library->lib_handle, name);
470 #else
471 /* We can't get function address dynamically in static linking. */
473 # define DEFINE_ENT(h,nm) \
474 { #h"_get"#nm"ent_r", _nss_##h##_get##nm##ent_r }, \
475 { #h"_end"#nm"ent", _nss_##h##_end##nm##ent }, \
476 { #h"_set"#nm"ent", _nss_##h##_set##nm##ent },
477 # define DEFINE_GET(h,nm) \
478 { #h"_get"#nm"_r", _nss_##h##_get##nm##_r },
479 # define DEFINE_GETBY(h,nm,ky) \
480 { #h"_get"#nm"by"#ky"_r", _nss_##h##_get##nm##by##ky##_r },
481 static struct fct_tbl { const char *fname; void *fp; } *tp, tbl[] =
483 # include "function.def"
484 { NULL, NULL }
486 size_t namlen = (5 + strlen (ni->name) + 1
487 + strlen (fct_name) + 1);
488 char name[namlen];
490 /* Construct the function name. */
491 __stpcpy (__stpcpy (__stpcpy (name, ni->name),
492 "_"),
493 fct_name);
495 result = NULL;
496 for (tp = &tbl[0]; tp->fname; tp++)
497 if (strcmp (tp->fname, name) == 0)
499 result = tp->fp;
500 break;
503 #endif
505 /* Remember function pointer for later calls. Even if null, we
506 record it so a second try needn't search the library again. */
507 known->fct_ptr = result;
508 #ifdef PTR_MANGLE
509 PTR_MANGLE (known->fct_ptr);
510 #endif
514 /* Remove the lock. */
515 __libc_lock_unlock (lock);
517 return result;
519 libc_hidden_def (__nss_lookup_function)
522 static name_database *
523 internal_function
524 nss_parse_file (const char *fname)
526 FILE *fp;
527 name_database *result;
528 name_database_entry *last;
529 char *line;
530 size_t len;
532 /* Open the configuration file. */
533 fp = fopen (fname, "rce");
534 if (fp == NULL)
535 return NULL;
537 /* No threads use this stream. */
538 __fsetlocking (fp, FSETLOCKING_BYCALLER);
540 result = (name_database *) malloc (sizeof (name_database));
541 if (result == NULL)
543 fclose (fp);
544 return NULL;
547 result->entry = NULL;
548 result->library = NULL;
549 last = NULL;
550 line = NULL;
551 len = 0;
554 name_database_entry *this;
555 ssize_t n;
557 n = __getline (&line, &len, fp);
558 if (n < 0)
559 break;
560 if (line[n - 1] == '\n')
561 line[n - 1] = '\0';
563 /* Because the file format does not know any form of quoting we
564 can search forward for the next '#' character and if found
565 make it terminating the line. */
566 *__strchrnul (line, '#') = '\0';
568 /* If the line is blank it is ignored. */
569 if (line[0] == '\0')
570 continue;
572 /* Each line completely specifies the actions for a database. */
573 this = nss_getline (line);
574 if (this != NULL)
576 if (last != NULL)
577 last->next = this;
578 else
579 result->entry = this;
581 last = this;
584 while (!feof_unlocked (fp));
586 /* Free the buffer. */
587 free (line);
588 /* Close configuration file. */
589 fclose (fp);
591 return result;
595 /* Read the source names:
596 `( <source> ( "[" "!"? (<status> "=" <action> )+ "]" )? )*'
598 static service_user *
599 internal_function
600 nss_parse_service_list (const char *line)
602 service_user *result = NULL, **nextp = &result;
604 while (1)
606 service_user *new_service;
607 const char *name;
609 while (isspace (line[0]))
610 ++line;
611 if (line[0] == '\0')
612 /* No source specified. */
613 return result;
615 /* Read <source> identifier. */
616 name = line;
617 while (line[0] != '\0' && !isspace (line[0]) && line[0] != '[')
618 ++line;
619 if (name == line)
620 return result;
623 new_service = (service_user *) malloc (sizeof (service_user)
624 + (line - name + 1));
625 if (new_service == NULL)
626 return result;
628 *((char *) __mempcpy (new_service->name, name, line - name)) = '\0';
630 /* Set default actions. */
631 new_service->actions[2 + NSS_STATUS_TRYAGAIN] = NSS_ACTION_CONTINUE;
632 new_service->actions[2 + NSS_STATUS_UNAVAIL] = NSS_ACTION_CONTINUE;
633 new_service->actions[2 + NSS_STATUS_NOTFOUND] = NSS_ACTION_CONTINUE;
634 new_service->actions[2 + NSS_STATUS_SUCCESS] = NSS_ACTION_RETURN;
635 new_service->actions[2 + NSS_STATUS_RETURN] = NSS_ACTION_RETURN;
636 new_service->library = NULL;
637 new_service->known = NULL;
638 new_service->next = NULL;
640 while (isspace (line[0]))
641 ++line;
643 if (line[0] == '[')
645 /* Read criterions. */
647 ++line;
648 while (line[0] != '\0' && isspace (line[0]));
652 int not;
653 enum nss_status status;
654 lookup_actions action;
656 /* Grok ! before name to mean all statii but that one. */
657 not = line[0] == '!';
658 if (not)
659 ++line;
661 /* Read status name. */
662 name = line;
663 while (line[0] != '\0' && !isspace (line[0]) && line[0] != '='
664 && line[0] != ']')
665 ++line;
667 /* Compare with known statii. */
668 if (line - name == 7)
670 if (__strncasecmp (name, "SUCCESS", 7) == 0)
671 status = NSS_STATUS_SUCCESS;
672 else if (__strncasecmp (name, "UNAVAIL", 7) == 0)
673 status = NSS_STATUS_UNAVAIL;
674 else
675 goto finish;
677 else if (line - name == 8)
679 if (__strncasecmp (name, "NOTFOUND", 8) == 0)
680 status = NSS_STATUS_NOTFOUND;
681 else if (__strncasecmp (name, "TRYAGAIN", 8) == 0)
682 status = NSS_STATUS_TRYAGAIN;
683 else
684 goto finish;
686 else
687 goto finish;
689 while (isspace (line[0]))
690 ++line;
691 if (line[0] != '=')
692 goto finish;
694 ++line;
695 while (isspace (line[0]));
697 name = line;
698 while (line[0] != '\0' && !isspace (line[0]) && line[0] != '='
699 && line[0] != ']')
700 ++line;
702 if (line - name == 6 && __strncasecmp (name, "RETURN", 6) == 0)
703 action = NSS_ACTION_RETURN;
704 else if (line - name == 8
705 && __strncasecmp (name, "CONTINUE", 8) == 0)
706 action = NSS_ACTION_CONTINUE;
707 else
708 goto finish;
710 if (not)
712 /* Save the current action setting for this status,
713 set them all to the given action, and reset this one. */
714 const lookup_actions save = new_service->actions[2 + status];
715 new_service->actions[2 + NSS_STATUS_TRYAGAIN] = action;
716 new_service->actions[2 + NSS_STATUS_UNAVAIL] = action;
717 new_service->actions[2 + NSS_STATUS_NOTFOUND] = action;
718 new_service->actions[2 + NSS_STATUS_SUCCESS] = action;
719 new_service->actions[2 + status] = save;
721 else
722 new_service->actions[2 + status] = action;
724 /* Skip white spaces. */
725 while (isspace (line[0]))
726 ++line;
728 while (line[0] != ']');
730 /* Skip the ']'. */
731 ++line;
734 *nextp = new_service;
735 nextp = &new_service->next;
736 continue;
738 finish:
739 free (new_service);
740 return result;
744 static name_database_entry *
745 internal_function
746 nss_getline (char *line)
748 const char *name;
749 name_database_entry *result;
750 size_t len;
752 /* Ignore leading white spaces. ATTENTION: this is different from
753 what is implemented in Solaris. The Solaris man page says a line
754 beginning with a white space character is ignored. We regard
755 this as just another misfeature in Solaris. */
756 while (isspace (line[0]))
757 ++line;
759 /* Recognize `<database> ":"'. */
760 name = line;
761 while (line[0] != '\0' && !isspace (line[0]) && line[0] != ':')
762 ++line;
763 if (line[0] == '\0' || name == line)
764 /* Syntax error. */
765 return NULL;
766 *line++ = '\0';
768 len = strlen (name) + 1;
770 result = (name_database_entry *) malloc (sizeof (name_database_entry) + len);
771 if (result == NULL)
772 return NULL;
774 /* Save the database name. */
775 memcpy (result->name, name, len);
777 /* Parse the list of services. */
778 result->service = nss_parse_service_list (line);
780 result->next = NULL;
781 return result;
785 static service_library *
786 internal_function
787 nss_new_service (name_database *database, const char *name)
789 service_library **currentp = &database->library;
791 while (*currentp != NULL)
793 if (strcmp ((*currentp)->name, name) == 0)
794 return *currentp;
795 currentp = &(*currentp)->next;
798 /* We have to add the new service. */
799 *currentp = (service_library *) malloc (sizeof (service_library));
800 if (*currentp == NULL)
801 return NULL;
803 (*currentp)->name = name;
804 (*currentp)->lib_handle = NULL;
805 (*currentp)->next = NULL;
807 return *currentp;
811 #ifdef SHARED
812 /* Load all libraries for the service. */
813 static void
814 nss_load_all_libraries (const char *service, const char *def)
816 service_user *ni = NULL;
818 if (__nss_database_lookup (service, NULL, def, &ni) == 0)
819 while (ni != NULL)
821 nss_load_library (ni);
822 ni = ni->next;
827 /* Called by nscd and nscd alone. */
828 void
829 __nss_disable_nscd (void (*cb) (size_t, struct traced_file *))
831 # ifdef PTR_MANGLE
832 PTR_MANGLE (cb);
833 # endif
834 nscd_init_cb = cb;
835 is_nscd = true;
837 /* Find all the relevant modules so that the init functions are called. */
838 nss_load_all_libraries ("passwd", "compat [NOTFOUND=return] files");
839 nss_load_all_libraries ("group", "compat [NOTFOUND=return] files");
840 nss_load_all_libraries ("hosts", "dns [!UNAVAIL=return] files");
841 nss_load_all_libraries ("services", NULL);
843 /* Disable all uses of NSCD. */
844 __nss_not_use_nscd_passwd = -1;
845 __nss_not_use_nscd_group = -1;
846 __nss_not_use_nscd_hosts = -1;
847 __nss_not_use_nscd_services = -1;
848 __nss_not_use_nscd_netgroup = -1;
850 #endif
852 static void
853 free_database_entries (name_database_entry *entry)
855 while (entry != NULL)
857 name_database_entry *olde = entry;
858 service_user *service = entry->service;
860 while (service != NULL)
862 service_user *olds = service;
864 if (service->known != NULL)
865 __tdestroy (service->known, free);
867 service = service->next;
868 free (olds);
871 entry = entry->next;
872 free (olde);
876 /* Free all resources if necessary. */
877 libc_freeres_fn (free_defconfig)
879 name_database_entry *entry = defconfig_entries;
881 if (entry == NULL)
882 /* defconfig was not used. */
883 return;
885 /* Don't disturb ongoing other threads (if there are any). */
886 defconfig_entries = NULL;
888 free_database_entries (entry);
891 libc_freeres_fn (free_mem)
893 name_database *top = service_table;
894 service_library *library;
896 if (top == NULL)
897 /* Maybe we have not read the nsswitch.conf file. */
898 return;
900 /* Don't disturb ongoing other threads (if there are any). */
901 service_table = NULL;
903 free_database_entries (top->entry);
905 library = top->library;
906 while (library != NULL)
908 service_library *oldl = library;
910 if (library->lib_handle && library->lib_handle != (void *) -1l)
911 __libc_dlclose (library->lib_handle);
913 library = library->next;
914 free (oldl);
917 free (top);