aboutsummaryrefslogtreecommitdiff
path: root/nss/nss_module.c
diff options
context:
space:
mode:
authorDJ Delorie <dj@redhat.com>2020-11-09 22:06:57 -0500
committerDJ Delorie <dj@redhat.com>2020-12-04 17:15:53 -0500
commitf8847d83e17774ed5e9c0f75ef693680b91bcae4 (patch)
treee67c662ee3cc09742242c19a253b5b62bbaa3ee7 /nss/nss_module.c
parentfa78feca47fdc226b46e7f6fea4c08c10fccd182 (diff)
downloadglibc-f8847d83e17774ed5e9c0f75ef693680b91bcae4.tar
glibc-f8847d83e17774ed5e9c0f75ef693680b91bcae4.tar.gz
glibc-f8847d83e17774ed5e9c0f75ef693680b91bcae4.tar.bz2
glibc-f8847d83e17774ed5e9c0f75ef693680b91bcae4.zip
nsswitch: use new internal API (core)
Core changes to switch the NSS internals to use the new API. Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Diffstat (limited to 'nss/nss_module.c')
-rw-r--r--nss/nss_module.c64
1 files changed, 63 insertions, 1 deletions
diff --git a/nss/nss_module.c b/nss/nss_module.c
index 8de8db09c3..fdb4e994df 100644
--- a/nss/nss_module.c
+++ b/nss/nss_module.c
@@ -16,7 +16,9 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
-#include <nss_module.h>
+#include <nsswitch.h>
+#include <nscd/nscd.h>
+#include <nscd/nscd_proto.h>
#include <array_length.h>
#include <assert.h>
@@ -287,6 +289,66 @@ __nss_module_get_function (struct nss_module *module, const char *name)
return fptr;
}
+#if defined SHARED && defined USE_NSCD
+/* Load all libraries for the service. */
+static void
+nss_load_all_libraries (const char *service, const char *def)
+{
+ nss_action_list ni = NULL;
+
+ if (__nss_database_lookup2 (service, NULL, def, &ni) == 0)
+ while (ni->module != NULL)
+ {
+ __nss_module_load (ni->module);
+ ++ni;
+ }
+}
+
+define_traced_file (pwd, _PATH_NSSWITCH_CONF);
+define_traced_file (grp, _PATH_NSSWITCH_CONF);
+define_traced_file (hst, _PATH_NSSWITCH_CONF);
+define_traced_file (serv, _PATH_NSSWITCH_CONF);
+define_traced_file (netgr, _PATH_NSSWITCH_CONF);
+
+/* Called by nscd and nscd alone. */
+void
+__nss_disable_nscd (void (*cb) (size_t, struct traced_file *))
+{
+ void (*cb1) (size_t, struct traced_file *);
+ cb1 = cb;
+# ifdef PTR_MANGLE
+ PTR_MANGLE (cb);
+# endif
+ nscd_init_cb = cb;
+ is_nscd = true;
+
+ /* Find all the relevant modules so that the init functions are called. */
+ nss_load_all_libraries ("passwd", DEFAULT_CONFIG);
+ nss_load_all_libraries ("group", DEFAULT_CONFIG);
+ nss_load_all_libraries ("hosts", "dns [!UNAVAIL=return] files");
+ nss_load_all_libraries ("services", NULL);
+
+ /* Make sure NSCD purges its cache if nsswitch.conf changes. */
+ init_traced_file (&pwd_traced_file.file, _PATH_NSSWITCH_CONF, 0);
+ cb1 (pwddb, &pwd_traced_file.file);
+ init_traced_file (&grp_traced_file.file, _PATH_NSSWITCH_CONF, 0);
+ cb1 (grpdb, &grp_traced_file.file);
+ init_traced_file (&hst_traced_file.file, _PATH_NSSWITCH_CONF, 0);
+ cb1 (hstdb, &hst_traced_file.file);
+ init_traced_file (&serv_traced_file.file, _PATH_NSSWITCH_CONF, 0);
+ cb1 (servdb, &serv_traced_file.file);
+ init_traced_file (&netgr_traced_file.file, _PATH_NSSWITCH_CONF, 0);
+ cb1 (netgrdb, &netgr_traced_file.file);
+
+ /* Disable all uses of NSCD. */
+ __nss_not_use_nscd_passwd = -1;
+ __nss_not_use_nscd_group = -1;
+ __nss_not_use_nscd_hosts = -1;
+ __nss_not_use_nscd_services = -1;
+ __nss_not_use_nscd_netgroup = -1;
+}
+#endif
+
void __libc_freeres_fn_section
__nss_module_freeres (void)
{