-/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
#include <dlfcn.h>
#include <errno.h>
#include <netdb.h>
-#include <libc-lock.h>
-#include <link.h> /* We need some help from ld.so. */
+#include <bits/libc-lock.h>
#include <search.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <gnu/lib-names.h>
+#include <elf/ldsodefs.h> /* We need some help from ld.so. */
+
+#if !defined DO_STATIC_NSS || defined PIC
+# include <gnu/lib-names.h>
+#endif
#include "nsswitch.h"
/* Prototypes for the local functions. */
-static void *nss_lookup_function (service_user *ni, const char *fct_name);
-static name_database *nss_parse_file (const char *fname);
-static name_database_entry *nss_getline (char *line);
-static service_user *nss_parse_service_list (const char *line);
+static void *nss_lookup_function (service_user *ni, const char *fct_name)
+ internal_function;
+static name_database *nss_parse_file (const char *fname) internal_function;
+static name_database_entry *nss_getline (char *line) internal_function;
+static service_user *nss_parse_service_list (const char *line)
+ internal_function;
static service_library *nss_new_service (name_database *database,
- const char *name);
+ const char *name) internal_function;
/* Declare external database variables. */
__libc_lock_define_initialized (static, lock)
-
+#if !defined DO_STATIC_NSS || defined PIC
/* String with revision number of the shared object files. */
static const char *const __nss_shlib_revision = LIBNSS_FILES_SO + 15;
+#endif
/* The root of the whole data base. */
static name_database *service_table;
/* -1 == not found
- 0 == adjusted for next function */
+ 0 == function found
+ 1 == finished */
int
__nss_lookup (service_user **ni, const char *fct_name, void **fctp)
{
*fctp = nss_lookup_function (*ni, fct_name);
}
- return *fctp != NULL ? 0 : -1;
+ return *fctp != NULL ? 0 : (*ni)->next == NULL ? 1 : -1;
}
}
+#if !defined DO_STATIC_NSS || defined PIC
static int
nss_dlerror_run (void (*operate) (void *), void *args)
{
char *last_errstring = NULL;
- const char *last_object_name = NULL;
int result;
- (void) _dl_catch_error (&last_errstring, &last_object_name, operate, args);
+ (void) _dl_catch_error (&last_errstring, operate, args);
result = last_errstring != NULL;
if (result)
args->loadbase = _dl_lookup_symbol (args->name, &args->ref,
scope, args->map->l_name, 0);
}
+#endif
/* Comparison function for searching NI->known tree. */
static int
static void *
+internal_function
nss_lookup_function (service_user *ni, const char *fct_name)
{
void **found, *result;
}
}
+#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);
-
+ int saved_errno = errno;
struct do_open_args args;
args.shlib_name = __alloca (shlen);
args.ni = ni;
__nss_shlib_revision);
if (nss_dlerror_run (do_open, &args) != 0)
- /* Failed to load the library. */
- ni->library->lib_handle = (void *) -1l;
+ {
+ /* Failed to load the library. */
+ ni->library->lib_handle = (void *) -1l;
+ __set_errno (saved_errno);
+ }
}
if (ni->library->lib_handle == (void *) -1l)
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. */
static name_database *
+internal_function
nss_parse_file (const char *fname)
{
FILE *fp;
`( <source> ( "[" "!"? (<status> "=" <action> )+ "]" )? )*'
*/
static service_user *
+internal_function
nss_parse_service_list (const char *line)
{
service_user *result = NULL, **nextp = &result;
free (new_service);
return result;
}
- memcpy (source, name, line - name);
- source[line - name] = '\0';
+ *((char *) __mempcpy (source, name, line - name)) = '\0';
new_service->name = source;
}
}
static name_database_entry *
+internal_function
nss_getline (char *line)
{
const char *name;
static service_library *
+internal_function
nss_new_service (name_database *database, const char *name)
{
service_library **currentp = &database->library;