The hash table that is used to cache netgroups is allocated with
low-level hash_create() and the freed in a destructor. The entries
themselves are talloc pointers with destructors which results in a funky
behaviour during shutdown, often a segfault.

I think the correct thing to do is just use sss_hash_create() so that
the table is deallocated when the responder goes away.
From 3bbfd747bcf6f364f4d0e3aecf95a26cb2e68abf Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <[email protected]>
Date: Thu, 2 Feb 2012 19:44:38 +0100
Subject: [PATCH] NSS: Use sss_hash_create instead of destructor

---
 src/responder/nss/nsssrv.c          |   14 +-------------
 src/responder/nss/nsssrv_netgroup.c |    1 +
 2 files changed, 2 insertions(+), 13 deletions(-)

diff --git a/src/responder/nss/nsssrv.c b/src/responder/nss/nsssrv.c
index 
ab836938b79b4600a3885461d651695f86d37119..a85695b041282d216a7602cb8767d2a5aab73b51
 100644
--- a/src/responder/nss/nsssrv.c
+++ b/src/responder/nss/nsssrv.c
@@ -241,17 +241,6 @@ static void nss_dp_reconnect_init(struct sbus_connection 
*conn,
     /* nss_shutdown(rctx); */
 }
 
-static int nss_ctx_destructor(void *memctx)
-{
-    struct nss_ctx *nctx = (struct nss_ctx *) memctx;
-
-    if (nctx->netgroups) {
-        hash_destroy(nctx->netgroups);
-        nctx->netgroups = NULL;
-    }
-    return 0;
-}
-
 int nss_process_init(TALLOC_CTX *mem_ctx,
                      struct tevent_context *ev,
                      struct confdb_ctx *cdb)
@@ -267,7 +256,6 @@ int nss_process_init(TALLOC_CTX *mem_ctx,
         DEBUG(0, ("fatal error initializing nss_ctx\n"));
         return ENOMEM;
     }
-    talloc_set_destructor((TALLOC_CTX *) nctx, nss_ctx_destructor);
 
     ret = sss_ncache_init(nctx, &nctx->ncache);
     if (ret != EOK) {
@@ -313,7 +301,7 @@ int nss_process_init(TALLOC_CTX *mem_ctx,
     }
 
     /* Create the lookup table for netgroup results */
-    hret = hash_create(10, &nctx->netgroups, NULL, NULL);
+    hret = sss_hash_create(nctx, 10, &nctx->netgroups);
     if (hret != HASH_SUCCESS) {
         DEBUG(0,("Unable to initialize netgroup hash table\n"));
         return EIO;
diff --git a/src/responder/nss/nsssrv_netgroup.c 
b/src/responder/nss/nsssrv_netgroup.c
index 
093329fa3cc95e60bea52f1a6150818bc2cb0c4a..02b88c7b5a2baa3c2e6991cec7e18ad20e10d666
 100644
--- a/src/responder/nss/nsssrv_netgroup.c
+++ b/src/responder/nss/nsssrv_netgroup.c
@@ -78,6 +78,7 @@ static errno_t set_netgroup_entry(struct nss_ctx *nctx,
         DEBUG(4, ("Hash error [%d][%s]", hret, hash_error_string(hret)));
         return EIO;
     }
+    talloc_steal(nctx->netgroups, netgr);
     talloc_set_destructor((TALLOC_CTX *) netgr, netgr_hash_remove);
 
     return EOK;
-- 
1.7.7.6

_______________________________________________
sssd-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/sssd-devel

Reply via email to