|
|
62a0d7 |
From de876c0de1056008786f56aa56f1198479cb58d2 Mon Sep 17 00:00:00 2001
|
|
|
62a0d7 |
From: Pavel Reichl <preichl@redhat.com>
|
|
|
62a0d7 |
Date: Fri, 27 Nov 2015 07:53:00 -0500
|
|
|
62a0d7 |
Subject: [PATCH] NSS: Fix memory leak netgroup
|
|
|
62a0d7 |
|
|
|
62a0d7 |
Resolves:
|
|
|
62a0d7 |
https://fedorahosted.org/sssd/ticket/2865
|
|
|
62a0d7 |
|
|
|
62a0d7 |
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
62a0d7 |
(cherry picked from commit 4231a17e66e0809a9c3d42207b45f95429cbb46c)
|
|
|
62a0d7 |
---
|
|
|
62a0d7 |
src/responder/nss/nsssrv_netgroup.c | 41 ++++++++++++++++++++++++++-----------
|
|
|
62a0d7 |
1 file changed, 29 insertions(+), 12 deletions(-)
|
|
|
62a0d7 |
|
|
|
62a0d7 |
diff --git a/src/responder/nss/nsssrv_netgroup.c b/src/responder/nss/nsssrv_netgroup.c
|
|
|
62a0d7 |
index c71043858988bbf6c66aaab1357d24d3701c777f..94fe3776d94a24dec03a5766c4026c3887b448aa 100644
|
|
|
62a0d7 |
--- a/src/responder/nss/nsssrv_netgroup.c
|
|
|
62a0d7 |
+++ b/src/responder/nss/nsssrv_netgroup.c
|
|
|
62a0d7 |
@@ -435,14 +435,18 @@ static errno_t create_negcache_netgr(struct setent_step_ctx *step_ctx)
|
|
|
62a0d7 |
errno_t ret;
|
|
|
62a0d7 |
struct getent_ctx *netgr;
|
|
|
62a0d7 |
|
|
|
62a0d7 |
- netgr = talloc_zero(step_ctx->nctx, struct getent_ctx);
|
|
|
62a0d7 |
- if (netgr == NULL) {
|
|
|
62a0d7 |
- DEBUG(SSSDBG_CRIT_FAILURE, "talloc_zero failed.\n");
|
|
|
62a0d7 |
- ret = ENOMEM;
|
|
|
62a0d7 |
- goto done;
|
|
|
62a0d7 |
- } else {
|
|
|
62a0d7 |
- netgr->ready = true;
|
|
|
62a0d7 |
- netgr->found = false;
|
|
|
62a0d7 |
+ /* Is there already netgroup with such name? */
|
|
|
62a0d7 |
+ ret = get_netgroup_entry(step_ctx->nctx, step_ctx->name,
|
|
|
62a0d7 |
+ &netgr);
|
|
|
62a0d7 |
+ if (ret != EOK || netgr == NULL) {
|
|
|
62a0d7 |
+
|
|
|
62a0d7 |
+ netgr = talloc_zero(step_ctx->nctx, struct getent_ctx);
|
|
|
62a0d7 |
+ if (netgr == NULL) {
|
|
|
62a0d7 |
+ DEBUG(SSSDBG_CRIT_FAILURE, "talloc_zero failed.\n");
|
|
|
62a0d7 |
+ ret = ENOMEM;
|
|
|
62a0d7 |
+ goto done;
|
|
|
62a0d7 |
+ }
|
|
|
62a0d7 |
+
|
|
|
62a0d7 |
netgr->entries = NULL;
|
|
|
62a0d7 |
netgr->lookup_table = step_ctx->nctx->netgroups;
|
|
|
62a0d7 |
netgr->name = talloc_strdup(netgr, step_ctx->name);
|
|
|
62a0d7 |
@@ -457,13 +461,20 @@ static errno_t create_negcache_netgr(struct setent_step_ctx *step_ctx)
|
|
|
62a0d7 |
DEBUG(SSSDBG_CRIT_FAILURE, "set_netgroup_entry failed.\n");
|
|
|
62a0d7 |
goto done;
|
|
|
62a0d7 |
}
|
|
|
62a0d7 |
- set_netgr_lifetime(step_ctx->nctx->neg_timeout, step_ctx, netgr);
|
|
|
62a0d7 |
}
|
|
|
62a0d7 |
|
|
|
62a0d7 |
+ netgr->ready = true;
|
|
|
62a0d7 |
+ netgr->found = false;
|
|
|
62a0d7 |
+
|
|
|
62a0d7 |
+ set_netgr_lifetime(step_ctx->nctx->neg_timeout, step_ctx, netgr);
|
|
|
62a0d7 |
+
|
|
|
62a0d7 |
+ ret = EOK;
|
|
|
62a0d7 |
+
|
|
|
62a0d7 |
done:
|
|
|
62a0d7 |
if (ret != EOK) {
|
|
|
62a0d7 |
talloc_free(netgr);
|
|
|
62a0d7 |
}
|
|
|
62a0d7 |
+
|
|
|
62a0d7 |
return ret;
|
|
|
62a0d7 |
}
|
|
|
62a0d7 |
|
|
|
62a0d7 |
@@ -474,6 +485,12 @@ static errno_t lookup_netgr_step(struct setent_step_ctx *step_ctx)
|
|
|
62a0d7 |
struct getent_ctx *netgr;
|
|
|
62a0d7 |
char *name = NULL;
|
|
|
62a0d7 |
uint32_t lifetime;
|
|
|
62a0d7 |
+ TALLOC_CTX *tmp_ctx;
|
|
|
62a0d7 |
+
|
|
|
62a0d7 |
+ tmp_ctx = talloc_new(NULL);
|
|
|
62a0d7 |
+ if (tmp_ctx == NULL) {
|
|
|
62a0d7 |
+ return ENOMEM;
|
|
|
62a0d7 |
+ }
|
|
|
62a0d7 |
|
|
|
62a0d7 |
/* Check each domain for this netgroup name */
|
|
|
62a0d7 |
while (dom) {
|
|
|
62a0d7 |
@@ -494,8 +511,7 @@ static errno_t lookup_netgr_step(struct setent_step_ctx *step_ctx)
|
|
|
62a0d7 |
/* make sure to update the dctx if we changed domain */
|
|
|
62a0d7 |
step_ctx->dctx->domain = dom;
|
|
|
62a0d7 |
|
|
|
62a0d7 |
- talloc_free(name);
|
|
|
62a0d7 |
- name = sss_get_cased_name(step_ctx, step_ctx->name,
|
|
|
62a0d7 |
+ name = sss_get_cased_name(tmp_ctx, step_ctx->name,
|
|
|
62a0d7 |
dom->case_sensitive);
|
|
|
62a0d7 |
if (!name) {
|
|
|
62a0d7 |
DEBUG(SSSDBG_CRIT_FAILURE, "sss_get_cased_name failed\n");
|
|
|
62a0d7 |
@@ -623,10 +639,11 @@ static errno_t lookup_netgr_step(struct setent_step_ctx *step_ctx)
|
|
|
62a0d7 |
"create_negcache_netgr failed with: %d:[%s], ignored.\n",
|
|
|
62a0d7 |
ret, sss_strerror(ret));
|
|
|
62a0d7 |
}
|
|
|
62a0d7 |
+
|
|
|
62a0d7 |
ret = ENOENT;
|
|
|
62a0d7 |
|
|
|
62a0d7 |
done:
|
|
|
62a0d7 |
- talloc_free(name);
|
|
|
62a0d7 |
+ talloc_free(tmp_ctx);
|
|
|
62a0d7 |
return ret;
|
|
|
62a0d7 |
}
|
|
|
62a0d7 |
|
|
|
62a0d7 |
--
|
|
|
62a0d7 |
2.4.11
|
|
|
62a0d7 |
|