+ if (ni->library == NULL)
+ {
+ /* This service has not yet been used. Fetch the service
+ library for it, creating a new one if need be. If there
+ is no service table from the file, this static variable
+ holds the head of the service_library list made from the
+ default configuration. */
+ static name_database default_table;
+ ni->library = nss_new_service (service_table ?: &default_table,
+ ni->name);
+ if (ni->library == NULL)
+ {
+ /* This only happens when out of memory. */
+ free (known);
+ goto remove_from_tree;
+ }
+ }
+
+#if !defined DO_STATIC_NSS || defined PIC
+ if (ni->library->lib_handle == NULL)
+ {
+ /* Load the shared library. */
+ size_t shlen = (7 + strlen (ni->library->name) + 3
+ + strlen (__nss_shlib_revision) + 1);
+
+ struct do_open_args args;
+ args.shlib_name = __alloca (shlen);
+ args.ni = ni;
+
+ /* Construct shared object name. */
+ __stpcpy (__stpcpy (__stpcpy (__stpcpy (args.shlib_name,
+ "libnss_"),
+ ni->library->name),
+ ".so"),
+ __nss_shlib_revision);
+
+ if (nss_dlerror_run (do_open, &args) != 0)
+ /* Failed to load the library. */
+ ni->library->lib_handle = (void *) -1l;
+ }
+
+ if (ni->library->lib_handle == (void *) -1l)
+ /* Library not found => function not found. */
+ result = NULL;
+ else
+ {
+ /* Get the desired function. Again, GNU ld.so magic ahead. */
+ size_t namlen = (5 + strlen (ni->library->name) + 1
+ + strlen (fct_name) + 1);
+ struct get_sym_args args;
+ args.name = __alloca (namlen);
+ args.map = ni->library->lib_handle;
+
+ /* Construct the function name. */
+ __stpcpy (__stpcpy (__stpcpy (__stpcpy (args.name, "_nss_"),
+ ni->library->name),
+ "_"),
+ fct_name);
+
+ /* Look up the symbol. */
+ result = (nss_dlerror_run (get_sym, &args) ? NULL
+ : (void *) (args.loadbase + args.ref->st_value));
+ }
+#else
+ /* We can't get function address dynamically in static linking. */
+ {
+# define DEFINE_ENT(h,nm) \
+ extern void _nss_##h##_get##nm##ent_r (void); \
+ extern void _nss_##h##_end##nm##ent (void); \
+ extern void _nss_##h##_set##nm##ent (void);
+# define DEFINE_GET(h,nm) \
+ extern void _nss_##h##_get##nm##_r (void);
+# define DEFINE_GETBY(h,nm,ky) \
+ extern void _nss_##h##_get##nm##by##ky##_r (void);
+# include "function.def"
+# undef DEFINE_ENT
+# undef DEFINE_GET
+# undef DEFINE_GETBY
+# define DEFINE_ENT(h,nm) \
+ { #h"_get"#nm"ent_r", _nss_##h##_get##nm##ent_r }, \
+ { #h"_end"#nm"ent", _nss_##h##_end##nm##ent }, \
+ { #h"_set"#nm"ent", _nss_##h##_set##nm##ent },
+# define DEFINE_GET(h,nm) \
+ { #h"_get"#nm"_r", _nss_##h##_get##nm##_r },
+# define DEFINE_GETBY(h,nm,ky) \
+ { #h"_get"#nm"by"#ky"_r", _nss_##h##_get##nm##by##ky##_r },
+ static struct fct_tbl { const char *fname; void *fp; } *tp, tbl[] =
+ {
+# include "function.def"
+ { NULL, NULL }
+ };
+ size_t namlen = (5 + strlen (ni->library->name) + 1
+ + strlen (fct_name) + 1);
+ char name[namlen];
+
+ /* Construct the function name. */
+ __stpcpy (__stpcpy (__stpcpy (name, ni->library->name),
+ "_"),
+ fct_name);
+
+ result = NULL;
+ for (tp = &tbl[0]; tp->fname; tp++)
+ if (strcmp (tp->fname, name) == 0)
+ {
+ result = tp->fp;
+ break;
+ }
+ }
+#endif
+
+ /* Remember function pointer for later calls. Even if null, we
+ record it so a second try needn't search the library again. */
+ known->fct_ptr = result;
+ }
+ }
+
+ /* Remove the lock. */
+ __libc_lock_unlock (lock);
+
+ return result;