/* -1 == database not found 0 == database entry pointer stored */ int __nss_database_lookup (const char *database, const char *alternate_name, const char *defconfig, service_user **ni) { /* Prevent multiple threads to change the service table. */ __libc_lock_lock (lock); /* Reconsider database variable in case some other thread called `__nss_configure_lookup' while we waited for the lock. */ if (*ni != NULL) { __libc_lock_unlock (lock); return 0; } /* Are we initialized yet? */ if (service_table == NULL) /* Read config file. */ service_table = nss_parse_file (_PATH_NSSWITCH_CONF); /* Test whether configuration data is available. */ if (service_table != NULL) { /* Return first `service_user' entry for DATABASE. */ name_database_entry *entry; /* XXX Could use some faster mechanism here. But each database is only requested once and so this might not be critical. */ for (entry = service_table->entry; entry != NULL; entry = entry->next) if (strcmp (database, entry->name) == 0) *ni = entry->service; if (*ni == NULL && alternate_name != NULL) /* We haven't found an entry so far. Try to find it with the alternative name. */ for (entry = service_table->entry; entry != NULL; entry = entry->next) if (strcmp (alternate_name, entry->name) == 0) *ni = entry->service; } /* No configuration data is available, either because nsswitch.conf doesn't exist or because it doesn't has a line for this database. DEFCONFIG specifies the default service list for this database, or null to use the most common default. */ if (*ni == NULL) *ni = nss_parse_service_list (defconfig ?: "nis [NOTFOUND=return] files"); __libc_lock_unlock (lock); return 0; }
/* -1 == database not found 0 == database entry pointer stored */ int __nss_database_lookup (const char *database, const char *alternate_name, const char *defconfig, service_user **ni) { /* Prevent multiple threads to change the service table. */ lock_nsswitch; /* Reconsider database variable in case some other thread called `__nss_configure_lookup' while we waited for the lock. */ if (*ni != NULL) { unlock_nsswitch; return 0; } #if __OPTION_EGLIBC_NSSWITCH /* Are we initialized yet? */ if (service_table == NULL) /* Read config file. */ service_table = nss_parse_file (_PATH_NSSWITCH_CONF); #endif /* Test whether configuration data is available. */ if (service_table != NULL) { /* Return first `service_user' entry for DATABASE. */ name_database_entry *entry; /* XXX Could use some faster mechanism here. But each database is only requested once and so this might not be critical. */ for (entry = service_table->entry; entry != NULL; entry = entry->next) if (strcmp (database, entry->name) == 0) *ni = entry->service; if (*ni == NULL && alternate_name != NULL) /* We haven't found an entry so far. Try to find it with the alternative name. */ for (entry = service_table->entry; entry != NULL; entry = entry->next) if (strcmp (alternate_name, entry->name) == 0) *ni = entry->service; } #if __OPTION_EGLIBC_NSSWITCH /* No configuration data is available, either because nsswitch.conf doesn't exist or because it doesn't have a line for this database. DEFCONFIG specifies the default service list for this database, or null to use the most common default. */ if (*ni == NULL) { *ni = nss_parse_service_list (defconfig ?: "nis [NOTFOUND=return] files"); if (*ni != NULL) { /* Record the memory we've just allocated in defconfig_entries list, so we can free it later. */ name_database_entry *entry; /* Allocate ENTRY plus size of name (1 here). */ entry = (name_database_entry *) malloc (sizeof (*entry) + 1); if (entry != NULL) { entry->next = defconfig_entries; entry->service = *ni; entry->name = ""; defconfig_entries = entry; } } }