Use ASCII in LC_TIME of om_ET for better readability
[glibc.git] / nss / nsswitch.c
blob8a146b956f8f93caf04f38c67a9d4349619d9724
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);
46 static name_database_entry *nss_getline (char *line);
47 static service_user *nss_parse_service_list (const char *line);
48 #if !defined DO_STATIC_NSS || defined SHARED
49 static service_library *nss_new_service (name_database *database,
50 const char *name);
51 #endif
54 /* Declare external database variables. */
55 #define DEFINE_DATABASE(name) \
56 extern service_user *__nss_##name##_database attribute_hidden; \
57 weak_extern (__nss_##name##_database)
58 #include "databases.def"
59 #undef DEFINE_DATABASE
61 /* Structure to map database name to variable. */
62 static const struct
64 const char name[10];
65 service_user **dbp;
66 } databases[] =
68 #define DEFINE_DATABASE(name) \
69 { #name, &__nss_##name##_database },
70 #include "databases.def"
71 #undef DEFINE_DATABASE
73 #define ndatabases (sizeof (databases) / sizeof (databases[0]))
75 #ifdef USE_NSCD
76 /* Flags whether custom rules for database is set. */
77 bool __nss_database_custom[NSS_DBSIDX_max];
78 #endif
81 __libc_lock_define_initialized (static, lock)
83 #if !defined DO_STATIC_NSS || defined SHARED
84 /* String with revision number of the shared object files. */
85 static const char *const __nss_shlib_revision = LIBNSS_FILES_SO + 15;
86 #endif
88 /* The root of the whole data base. */
89 static name_database *service_table;
91 /* List of default service lists that were generated by glibc because
92 /etc/nsswitch.conf did not provide a value.
93 The list is only maintained so we can free such service lists in
94 __libc_freeres. */
95 static name_database_entry *defconfig_entries;
98 #if defined USE_NSCD && (!defined DO_STATIC_NSS || defined SHARED)
99 /* Nonzero if this is the nscd process. */
100 static bool is_nscd;
101 /* The callback passed to the init functions when nscd is used. */
102 static void (*nscd_init_cb) (size_t, struct traced_file *);
103 #endif
106 /* -1 == database not found
107 0 == database entry pointer stored */
109 __nss_database_lookup (const char *database, const char *alternate_name,
110 const char *defconfig, service_user **ni)
112 /* Prevent multiple threads to change the service table. */
113 __libc_lock_lock (lock);
115 /* Reconsider database variable in case some other thread called
116 `__nss_configure_lookup' while we waited for the lock. */
117 if (*ni != NULL)
119 __libc_lock_unlock (lock);
120 return 0;
123 /* Are we initialized yet? */
124 if (service_table == NULL)
125 /* Read config file. */
126 service_table = nss_parse_file (_PATH_NSSWITCH_CONF);
128 /* Test whether configuration data is available. */
129 if (service_table != NULL)
131 /* Return first `service_user' entry for DATABASE. */
132 name_database_entry *entry;
134 /* XXX Could use some faster mechanism here. But each database is
135 only requested once and so this might not be critical. */
136 for (entry = service_table->entry; entry != NULL; entry = entry->next)
137 if (strcmp (database, entry->name) == 0)
138 *ni = entry->service;
140 if (*ni == NULL && alternate_name != NULL)
141 /* We haven't found an entry so far. Try to find it with the
142 alternative name. */
143 for (entry = service_table->entry; entry != NULL; entry = entry->next)
144 if (strcmp (alternate_name, entry->name) == 0)
145 *ni = entry->service;
148 /* No configuration data is available, either because nsswitch.conf
149 doesn't exist or because it doesn't have a line for this database.
151 DEFCONFIG specifies the default service list for this database,
152 or null to use the most common default. */
153 if (*ni == NULL)
155 *ni = nss_parse_service_list (defconfig
156 ?: "nis [NOTFOUND=return] files");
157 if (*ni != NULL)
159 /* Record the memory we've just allocated in defconfig_entries list,
160 so we can free it later. */
161 name_database_entry *entry;
163 /* Allocate ENTRY plus size of name (1 here). */
164 entry = (name_database_entry *) malloc (sizeof (*entry) + 1);
166 if (entry != NULL)
168 entry->next = defconfig_entries;
169 entry->service = *ni;
170 entry->name[0] = '\0';
171 defconfig_entries = entry;
176 __libc_lock_unlock (lock);
178 return *ni != NULL ? 0 : -1;
180 libc_hidden_def (__nss_database_lookup)
183 /* -1 == not found
184 0 == function found
185 1 == finished */
187 __nss_lookup (service_user **ni, const char *fct_name, const char *fct2_name,
188 void **fctp)
190 *fctp = __nss_lookup_function (*ni, fct_name);
191 if (*fctp == NULL && fct2_name != NULL)
192 *fctp = __nss_lookup_function (*ni, fct2_name);
194 while (*fctp == NULL
195 && nss_next_action (*ni, NSS_STATUS_UNAVAIL) == NSS_ACTION_CONTINUE
196 && (*ni)->next != NULL)
198 *ni = (*ni)->next;
200 *fctp = __nss_lookup_function (*ni, fct_name);
201 if (*fctp == NULL && fct2_name != NULL)
202 *fctp = __nss_lookup_function (*ni, fct2_name);
205 return *fctp != NULL ? 0 : (*ni)->next == NULL ? 1 : -1;
207 libc_hidden_def (__nss_lookup)
210 /* -1 == not found
211 0 == adjusted for next function
212 1 == finished */
214 __nss_next2 (service_user **ni, const char *fct_name, const char *fct2_name,
215 void **fctp, int status, int all_values)
217 if (all_values)
219 if (nss_next_action (*ni, NSS_STATUS_TRYAGAIN) == NSS_ACTION_RETURN
220 && nss_next_action (*ni, NSS_STATUS_UNAVAIL) == NSS_ACTION_RETURN
221 && nss_next_action (*ni, NSS_STATUS_NOTFOUND) == NSS_ACTION_RETURN
222 && nss_next_action (*ni, NSS_STATUS_SUCCESS) == NSS_ACTION_RETURN)
223 return 1;
225 else
227 /* This is really only for debugging. */
228 if (__builtin_expect (NSS_STATUS_TRYAGAIN > status
229 || status > NSS_STATUS_RETURN, 0))
230 __libc_fatal ("illegal status in __nss_next");
232 if (nss_next_action (*ni, status) == NSS_ACTION_RETURN)
233 return 1;
236 if ((*ni)->next == NULL)
237 return -1;
241 *ni = (*ni)->next;
243 *fctp = __nss_lookup_function (*ni, fct_name);
244 if (*fctp == NULL && fct2_name != NULL)
245 *fctp = __nss_lookup_function (*ni, fct2_name);
247 while (*fctp == NULL
248 && nss_next_action (*ni, NSS_STATUS_UNAVAIL) == NSS_ACTION_CONTINUE
249 && (*ni)->next != NULL);
251 return *fctp != NULL ? 0 : -1;
253 libc_hidden_def (__nss_next2)
257 attribute_compat_text_section
258 __nss_next (service_user **ni, const char *fct_name, void **fctp, int status,
259 int all_values)
261 return __nss_next2 (ni, fct_name, NULL, fctp, status, all_values);
266 __nss_configure_lookup (const char *dbname, const char *service_line)
268 service_user *new_db;
269 size_t cnt;
271 for (cnt = 0; cnt < ndatabases; ++cnt)
273 int cmp = strcmp (dbname, databases[cnt].name);
274 if (cmp == 0)
275 break;
276 if (cmp < 0)
278 __set_errno (EINVAL);
279 return -1;
283 if (cnt == ndatabases)
285 __set_errno (EINVAL);
286 return -1;
289 /* Test whether it is really used. */
290 if (databases[cnt].dbp == NULL)
291 /* Nothing to do, but we could do. */
292 return 0;
294 /* Try to generate new data. */
295 new_db = nss_parse_service_list (service_line);
296 if (new_db == NULL)
298 /* Illegal service specification. */
299 __set_errno (EINVAL);
300 return -1;
303 /* Prevent multiple threads to change the service table. */
304 __libc_lock_lock (lock);
306 /* Install new rules. */
307 *databases[cnt].dbp = new_db;
308 #ifdef USE_NSCD
309 __nss_database_custom[cnt] = true;
310 #endif
312 __libc_lock_unlock (lock);
314 return 0;
318 /* Comparison function for searching NI->known tree. */
319 static int
320 known_compare (const void *p1, const void *p2)
322 return p1 == p2 ? 0 : strcmp (*(const char *const *) p1,
323 *(const char *const *) p2);
327 #if !defined DO_STATIC_NSS || defined SHARED
328 /* Load library. */
329 static int
330 nss_load_library (service_user *ni)
332 if (ni->library == NULL)
334 /* This service has not yet been used. Fetch the service
335 library for it, creating a new one if need be. If there
336 is no service table from the file, this static variable
337 holds the head of the service_library list made from the
338 default configuration. */
339 static name_database default_table;
340 ni->library = nss_new_service (service_table ?: &default_table,
341 ni->name);
342 if (ni->library == NULL)
343 return -1;
346 if (ni->library->lib_handle == NULL)
348 /* Load the shared library. */
349 size_t shlen = (7 + strlen (ni->name) + 3
350 + strlen (__nss_shlib_revision) + 1);
351 int saved_errno = errno;
352 char shlib_name[shlen];
354 /* Construct shared object name. */
355 __stpcpy (__stpcpy (__stpcpy (__stpcpy (shlib_name,
356 "libnss_"),
357 ni->name),
358 ".so"),
359 __nss_shlib_revision);
361 ni->library->lib_handle = __libc_dlopen (shlib_name);
362 if (ni->library->lib_handle == NULL)
364 /* Failed to load the library. */
365 ni->library->lib_handle = (void *) -1l;
366 __set_errno (saved_errno);
368 # ifdef USE_NSCD
369 else if (is_nscd)
371 /* Call the init function when nscd is used. */
372 size_t initlen = (5 + strlen (ni->name)
373 + strlen ("_init") + 1);
374 char init_name[initlen];
376 /* Construct the init function name. */
377 __stpcpy (__stpcpy (__stpcpy (init_name,
378 "_nss_"),
379 ni->name),
380 "_init");
382 /* Find the optional init function. */
383 void (*ifct) (void (*) (size_t, struct traced_file *))
384 = __libc_dlsym (ni->library->lib_handle, init_name);
385 if (ifct != NULL)
387 void (*cb) (size_t, struct traced_file *) = nscd_init_cb;
388 # ifdef PTR_DEMANGLE
389 PTR_DEMANGLE (cb);
390 # endif
391 ifct (cb);
394 # endif
397 return 0;
399 #endif
402 void *
403 __nss_lookup_function (service_user *ni, const char *fct_name)
405 void **found, *result;
407 /* We now modify global data. Protect it. */
408 __libc_lock_lock (lock);
410 /* Search the tree of functions previously requested. Data in the
411 tree are `known_function' structures, whose first member is a
412 `const char *', the lookup key. The search returns a pointer to
413 the tree node structure; the first member of the is a pointer to
414 our structure (i.e. what will be a `known_function'); since the
415 first member of that is the lookup key string, &FCT_NAME is close
416 enough to a pointer to our structure to use as a lookup key that
417 will be passed to `known_compare' (above). */
419 found = __tsearch (&fct_name, &ni->known, &known_compare);
420 if (found == NULL)
421 /* This means out-of-memory. */
422 result = NULL;
423 else if (*found != &fct_name)
425 /* The search found an existing structure in the tree. */
426 result = ((known_function *) *found)->fct_ptr;
427 #ifdef PTR_DEMANGLE
428 PTR_DEMANGLE (result);
429 #endif
431 else
433 /* This name was not known before. Now we have a node in the tree
434 (in the proper sorted position for FCT_NAME) that points to
435 &FCT_NAME instead of any real `known_function' structure.
436 Allocate a new structure and fill it in. */
438 known_function *known = malloc (sizeof *known);
439 if (! known)
441 #if !defined DO_STATIC_NSS || defined SHARED
442 remove_from_tree:
443 #endif
444 /* Oops. We can't instantiate this node properly.
445 Remove it from the tree. */
446 __tdelete (&fct_name, &ni->known, &known_compare);
447 free (known);
448 result = NULL;
450 else
452 /* Point the tree node at this new structure. */
453 *found = known;
454 known->fct_name = fct_name;
456 #if !defined DO_STATIC_NSS || defined SHARED
457 /* Load the appropriate library. */
458 if (nss_load_library (ni) != 0)
459 /* This only happens when out of memory. */
460 goto remove_from_tree;
462 if (ni->library->lib_handle == (void *) -1l)
463 /* Library not found => function not found. */
464 result = NULL;
465 else
467 /* Get the desired function. */
468 size_t namlen = (5 + strlen (ni->name) + 1
469 + strlen (fct_name) + 1);
470 char name[namlen];
472 /* Construct the function name. */
473 __stpcpy (__stpcpy (__stpcpy (__stpcpy (name, "_nss_"),
474 ni->name),
475 "_"),
476 fct_name);
478 /* Look up the symbol. */
479 result = __libc_dlsym (ni->library->lib_handle, name);
481 #else
482 /* We can't get function address dynamically in static linking. */
484 # define DEFINE_ENT(h,nm) \
485 { #h"_get"#nm"ent_r", _nss_##h##_get##nm##ent_r }, \
486 { #h"_end"#nm"ent", _nss_##h##_end##nm##ent }, \
487 { #h"_set"#nm"ent", _nss_##h##_set##nm##ent },
488 # define DEFINE_GET(h,nm) \
489 { #h"_get"#nm"_r", _nss_##h##_get##nm##_r },
490 # define DEFINE_GETBY(h,nm,ky) \
491 { #h"_get"#nm"by"#ky"_r", _nss_##h##_get##nm##by##ky##_r },
492 static struct fct_tbl { const char *fname; void *fp; } *tp, tbl[] =
494 # include "function.def"
495 { NULL, NULL }
497 size_t namlen = (5 + strlen (ni->name) + 1
498 + strlen (fct_name) + 1);
499 char name[namlen];
501 /* Construct the function name. */
502 __stpcpy (__stpcpy (__stpcpy (name, ni->name),
503 "_"),
504 fct_name);
506 result = NULL;
507 for (tp = &tbl[0]; tp->fname; tp++)
508 if (strcmp (tp->fname, name) == 0)
510 result = tp->fp;
511 break;
514 #endif
516 /* Remember function pointer for later calls. Even if null, we
517 record it so a second try needn't search the library again. */
518 known->fct_ptr = result;
519 #ifdef PTR_MANGLE
520 PTR_MANGLE (known->fct_ptr);
521 #endif
525 /* Remove the lock. */
526 __libc_lock_unlock (lock);
528 return result;
530 libc_hidden_def (__nss_lookup_function)
533 static name_database *
534 nss_parse_file (const char *fname)
536 FILE *fp;
537 name_database *result;
538 name_database_entry *last;
539 char *line;
540 size_t len;
542 /* Open the configuration file. */
543 fp = fopen (fname, "rce");
544 if (fp == NULL)
545 return NULL;
547 /* No threads use this stream. */
548 __fsetlocking (fp, FSETLOCKING_BYCALLER);
550 result = (name_database *) malloc (sizeof (name_database));
551 if (result == NULL)
553 fclose (fp);
554 return NULL;
557 result->entry = NULL;
558 result->library = NULL;
559 last = NULL;
560 line = NULL;
561 len = 0;
564 name_database_entry *this;
565 ssize_t n;
567 n = __getline (&line, &len, fp);
568 if (n < 0)
569 break;
570 if (line[n - 1] == '\n')
571 line[n - 1] = '\0';
573 /* Because the file format does not know any form of quoting we
574 can search forward for the next '#' character and if found
575 make it terminating the line. */
576 *__strchrnul (line, '#') = '\0';
578 /* If the line is blank it is ignored. */
579 if (line[0] == '\0')
580 continue;
582 /* Each line completely specifies the actions for a database. */
583 this = nss_getline (line);
584 if (this != NULL)
586 if (last != NULL)
587 last->next = this;
588 else
589 result->entry = this;
591 last = this;
594 while (!feof_unlocked (fp));
596 /* Free the buffer. */
597 free (line);
598 /* Close configuration file. */
599 fclose (fp);
601 return result;
605 /* Read the source names:
606 `( <source> ( "[" "!"? (<status> "=" <action> )+ "]" )? )*'
608 static service_user *
609 nss_parse_service_list (const char *line)
611 service_user *result = NULL, **nextp = &result;
613 while (1)
615 service_user *new_service;
616 const char *name;
618 while (isspace (line[0]))
619 ++line;
620 if (line[0] == '\0')
621 /* No source specified. */
622 return result;
624 /* Read <source> identifier. */
625 name = line;
626 while (line[0] != '\0' && !isspace (line[0]) && line[0] != '[')
627 ++line;
628 if (name == line)
629 return result;
632 new_service = (service_user *) malloc (sizeof (service_user)
633 + (line - name + 1));
634 if (new_service == NULL)
635 return result;
637 *((char *) __mempcpy (new_service->name, name, line - name)) = '\0';
639 /* Set default actions. */
640 new_service->actions[2 + NSS_STATUS_TRYAGAIN] = NSS_ACTION_CONTINUE;
641 new_service->actions[2 + NSS_STATUS_UNAVAIL] = NSS_ACTION_CONTINUE;
642 new_service->actions[2 + NSS_STATUS_NOTFOUND] = NSS_ACTION_CONTINUE;
643 new_service->actions[2 + NSS_STATUS_SUCCESS] = NSS_ACTION_RETURN;
644 new_service->actions[2 + NSS_STATUS_RETURN] = NSS_ACTION_RETURN;
645 new_service->library = NULL;
646 new_service->known = NULL;
647 new_service->next = NULL;
649 while (isspace (line[0]))
650 ++line;
652 if (line[0] == '[')
654 /* Read criterions. */
656 ++line;
657 while (line[0] != '\0' && isspace (line[0]));
661 int not;
662 enum nss_status status;
663 lookup_actions action;
665 /* Grok ! before name to mean all statii but that one. */
666 not = line[0] == '!';
667 if (not)
668 ++line;
670 /* Read status name. */
671 name = line;
672 while (line[0] != '\0' && !isspace (line[0]) && line[0] != '='
673 && line[0] != ']')
674 ++line;
676 /* Compare with known statii. */
677 if (line - name == 7)
679 if (__strncasecmp (name, "SUCCESS", 7) == 0)
680 status = NSS_STATUS_SUCCESS;
681 else if (__strncasecmp (name, "UNAVAIL", 7) == 0)
682 status = NSS_STATUS_UNAVAIL;
683 else
684 goto finish;
686 else if (line - name == 8)
688 if (__strncasecmp (name, "NOTFOUND", 8) == 0)
689 status = NSS_STATUS_NOTFOUND;
690 else if (__strncasecmp (name, "TRYAGAIN", 8) == 0)
691 status = NSS_STATUS_TRYAGAIN;
692 else
693 goto finish;
695 else
696 goto finish;
698 while (isspace (line[0]))
699 ++line;
700 if (line[0] != '=')
701 goto finish;
703 ++line;
704 while (isspace (line[0]));
706 name = line;
707 while (line[0] != '\0' && !isspace (line[0]) && line[0] != '='
708 && line[0] != ']')
709 ++line;
711 if (line - name == 6 && __strncasecmp (name, "RETURN", 6) == 0)
712 action = NSS_ACTION_RETURN;
713 else if (line - name == 8
714 && __strncasecmp (name, "CONTINUE", 8) == 0)
715 action = NSS_ACTION_CONTINUE;
716 else if (line - name == 5
717 && __strncasecmp (name, "MERGE", 5) == 0)
718 action = NSS_ACTION_MERGE;
719 else
720 goto finish;
722 if (not)
724 /* Save the current action setting for this status,
725 set them all to the given action, and reset this one. */
726 const lookup_actions save = new_service->actions[2 + status];
727 new_service->actions[2 + NSS_STATUS_TRYAGAIN] = action;
728 new_service->actions[2 + NSS_STATUS_UNAVAIL] = action;
729 new_service->actions[2 + NSS_STATUS_NOTFOUND] = action;
730 new_service->actions[2 + NSS_STATUS_SUCCESS] = action;
731 new_service->actions[2 + status] = save;
733 else
734 new_service->actions[2 + status] = action;
736 /* Skip white spaces. */
737 while (isspace (line[0]))
738 ++line;
740 while (line[0] != ']');
742 /* Skip the ']'. */
743 ++line;
746 *nextp = new_service;
747 nextp = &new_service->next;
748 continue;
750 finish:
751 free (new_service);
752 return result;
756 static name_database_entry *
757 nss_getline (char *line)
759 const char *name;
760 name_database_entry *result;
761 size_t len;
763 /* Ignore leading white spaces. ATTENTION: this is different from
764 what is implemented in Solaris. The Solaris man page says a line
765 beginning with a white space character is ignored. We regard
766 this as just another misfeature in Solaris. */
767 while (isspace (line[0]))
768 ++line;
770 /* Recognize `<database> ":"'. */
771 name = line;
772 while (line[0] != '\0' && !isspace (line[0]) && line[0] != ':')
773 ++line;
774 if (line[0] == '\0' || name == line)
775 /* Syntax error. */
776 return NULL;
777 *line++ = '\0';
779 len = strlen (name) + 1;
781 result = (name_database_entry *) malloc (sizeof (name_database_entry) + len);
782 if (result == NULL)
783 return NULL;
785 /* Save the database name. */
786 memcpy (result->name, name, len);
788 /* Parse the list of services. */
789 result->service = nss_parse_service_list (line);
791 result->next = NULL;
792 return result;
796 #if !defined DO_STATIC_NSS || defined SHARED
797 static service_library *
798 nss_new_service (name_database *database, const char *name)
800 service_library **currentp = &database->library;
802 while (*currentp != NULL)
804 if (strcmp ((*currentp)->name, name) == 0)
805 return *currentp;
806 currentp = &(*currentp)->next;
809 /* We have to add the new service. */
810 *currentp = (service_library *) malloc (sizeof (service_library));
811 if (*currentp == NULL)
812 return NULL;
814 (*currentp)->name = name;
815 (*currentp)->lib_handle = NULL;
816 (*currentp)->next = NULL;
818 return *currentp;
820 #endif
823 #if defined SHARED && defined USE_NSCD
824 /* Load all libraries for the service. */
825 static void
826 nss_load_all_libraries (const char *service, const char *def)
828 service_user *ni = NULL;
830 if (__nss_database_lookup (service, NULL, def, &ni) == 0)
831 while (ni != NULL)
833 nss_load_library (ni);
834 ni = ni->next;
839 /* Called by nscd and nscd alone. */
840 void
841 __nss_disable_nscd (void (*cb) (size_t, struct traced_file *))
843 # ifdef PTR_MANGLE
844 PTR_MANGLE (cb);
845 # endif
846 nscd_init_cb = cb;
847 is_nscd = true;
849 /* Find all the relevant modules so that the init functions are called. */
850 nss_load_all_libraries ("passwd", "compat [NOTFOUND=return] files");
851 nss_load_all_libraries ("group", "compat [NOTFOUND=return] files");
852 nss_load_all_libraries ("hosts", "dns [!UNAVAIL=return] files");
853 nss_load_all_libraries ("services", NULL);
855 /* Disable all uses of NSCD. */
856 __nss_not_use_nscd_passwd = -1;
857 __nss_not_use_nscd_group = -1;
858 __nss_not_use_nscd_hosts = -1;
859 __nss_not_use_nscd_services = -1;
860 __nss_not_use_nscd_netgroup = -1;
862 #endif
864 static void
865 free_database_entries (name_database_entry *entry)
867 while (entry != NULL)
869 name_database_entry *olde = entry;
870 service_user *service = entry->service;
872 while (service != NULL)
874 service_user *olds = service;
876 if (service->known != NULL)
877 __tdestroy (service->known, free);
879 service = service->next;
880 free (olds);
883 entry = entry->next;
884 free (olde);
888 /* Free all resources if necessary. */
889 libc_freeres_fn (free_defconfig)
891 name_database_entry *entry = defconfig_entries;
893 if (entry == NULL)
894 /* defconfig was not used. */
895 return;
897 /* Don't disturb ongoing other threads (if there are any). */
898 defconfig_entries = NULL;
900 free_database_entries (entry);
903 libc_freeres_fn (free_mem)
905 name_database *top = service_table;
906 service_library *library;
908 if (top == NULL)
909 /* Maybe we have not read the nsswitch.conf file. */
910 return;
912 /* Don't disturb ongoing other threads (if there are any). */
913 service_table = NULL;
915 free_database_entries (top->entry);
917 library = top->library;
918 while (library != NULL)
920 service_library *oldl = library;
922 if (library->lib_handle && library->lib_handle != (void *) -1l)
923 __libc_dlclose (library->lib_handle);
925 library = library->next;
926 free (oldl);
929 free (top);