[SSSD] [sssd PR#558][synchronized] WIP: Add a test for sss_nss_getgrouplist_timeout and fix invalidating the initgroups cache

2019-09-04 Thread jhrozek
   URL: https://github.com/SSSD/sssd/pull/558
Author: jhrozek
 Title: #558: WIP: Add a test for sss_nss_getgrouplist_timeout and fix 
invalidating the initgroups cache
Action: synchronized

To pull the PR as Git branch:
git remote add ghsssd https://github.com/SSSD/sssd
git fetch ghsssd pull/558/head:pr558
git checkout pr558
From 09c3b270e6efa56cb943db09160e40172c2fb11a Mon Sep 17 00:00:00 2001
From: Jakub Hrozek 
Date: Tue, 24 Apr 2018 16:31:38 +0200
Subject: [PATCH 1/2] NSS: Fix deleting named entries from the initgroup memory
 cache

---
 src/responder/nss/nss_cmd.c|  8 ++--
 src/responder/nss/nss_get_object.c | 17 +++--
 2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/src/responder/nss/nss_cmd.c b/src/responder/nss/nss_cmd.c
index dae1759103..b669866d3e 100644
--- a/src/responder/nss/nss_cmd.c
+++ b/src/responder/nss/nss_cmd.c
@@ -493,12 +493,16 @@ static errno_t invalidate_cache(struct nss_cmd_ctx *cmd_ctx,
 return ret;
 }
 
-memcache_delete_entry(cmd_ctx->nss_ctx, cmd_ctx->nss_ctx->rctx, NULL,
-  output_name, 0, memcache_type);
 if (memcache_type == SSS_MC_INITGROUPS) {
+memcache_delete_entry(cmd_ctx->nss_ctx, cmd_ctx->nss_ctx->rctx, NULL,
+  result->lookup_name, 0, memcache_type);
+
 /* Invalidate the passwd data as well */
 memcache_delete_entry(cmd_ctx->nss_ctx, cmd_ctx->nss_ctx->rctx,
   result->domain, output_name, 0, SSS_MC_PASSWD);
+} else {
+memcache_delete_entry(cmd_ctx->nss_ctx, cmd_ctx->nss_ctx->rctx, NULL,
+  output_name, 0, memcache_type);
 }
 talloc_free(output_name);
 
diff --git a/src/responder/nss/nss_get_object.c b/src/responder/nss/nss_get_object.c
index 2ef34c564c..2f231df8b5 100644
--- a/src/responder/nss/nss_get_object.c
+++ b/src/responder/nss/nss_get_object.c
@@ -109,12 +109,17 @@ memcache_delete_entry(struct nss_ctx *nss_ctx,
 }
 
 if (name != NULL) {
-ret = sized_output_name(NULL, rctx, name, dom, _name);
-if (ret != EOK) {
-DEBUG(SSSDBG_OP_FAILURE,
-  "Unable to create sized name [%d]: %s\n",
-  ret, sss_strerror(ret));
-return ret;
+if (type == SSS_MC_INITGROUPS) {
+sized_name = talloc_zero(NULL, struct sized_string);
+to_sized_string(sized_name, name);
+} else {
+ret = sized_output_name(NULL, rctx, name, dom, _name);
+if (ret != EOK) {
+DEBUG(SSSDBG_OP_FAILURE,
+"Unable to create sized name [%d]: %s\n",
+ret, sss_strerror(ret));
+return ret;
+}
 }
 
 ret = memcache_delete_entry_by_name(nss_ctx, sized_name, type);

From 0e7f363b8dff7b99c9bcfbcf469243199c61b4a8 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek 
Date: Mon, 23 Apr 2018 21:33:49 +0200
Subject: [PATCH 2/2] TESTS: Add tests for the sss_nss_getgrouplist_timeout
 function

---
 src/tests/intg/Makefile.am|   2 +
 src/tests/intg/sssd_nss_ex.py |  86 +++
 src/tests/intg/test_nss_ex.py | 261 ++
 3 files changed, 349 insertions(+)
 create mode 100644 src/tests/intg/sssd_nss_ex.py
 create mode 100644 src/tests/intg/test_nss_ex.py

diff --git a/src/tests/intg/Makefile.am b/src/tests/intg/Makefile.am
index f60751a444..223f8642a2 100644
--- a/src/tests/intg/Makefile.am
+++ b/src/tests/intg/Makefile.am
@@ -3,6 +3,7 @@ dist_noinst_DATA = \
 config.py.m4 \
 util.py \
 sssd_nss.py \
+sssd_nss_ex.py \
 sssd_id.py \
 sssd_ldb.py \
 sssd_netgroup.py \
@@ -40,6 +41,7 @@ dist_noinst_DATA = \
 test_ssh_pubkey.py \
 test_pam_responder.py \
 test_sudo.py \
+test_nss_ex.py \
 $(NULL)
 
 EXTRA_DIST = data/cwrap-dbus-system.conf.in
diff --git a/src/tests/intg/sssd_nss_ex.py b/src/tests/intg/sssd_nss_ex.py
new file mode 100644
index 00..381f3cae34
--- /dev/null
+++ b/src/tests/intg/sssd_nss_ex.py
@@ -0,0 +1,86 @@
+#
+# Shared module for integration tests that need to access the sssd_nss_ex
+# interface directly
+#
+# Copyright (c) 2018 Red Hat, Inc.
+#
+# This is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 only
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see .
+
+import config
+import errno
+from ctypes import (cdll, c_int, c_char_p, c_char,
+   

[SSSD] [sssd PR#558][synchronized] WIP: Add a test for sss_nss_getgrouplist_timeout and fix invalidating the initgroups cache

2019-01-20 Thread jhrozek
   URL: https://github.com/SSSD/sssd/pull/558
Author: jhrozek
 Title: #558: WIP: Add a test for sss_nss_getgrouplist_timeout and fix 
invalidating the initgroups cache
Action: synchronized

To pull the PR as Git branch:
git remote add ghsssd https://github.com/SSSD/sssd
git fetch ghsssd pull/558/head:pr558
git checkout pr558
From 2da0f4a08eb72a924b9c2b9a00f0caeadc352d93 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek 
Date: Tue, 24 Apr 2018 16:31:38 +0200
Subject: [PATCH 1/2] NSS: Fix deleting named entries from the initgroup memory
 cache

---
 src/responder/nss/nss_cmd.c|  8 ++--
 src/responder/nss/nss_get_object.c | 17 +++--
 2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/src/responder/nss/nss_cmd.c b/src/responder/nss/nss_cmd.c
index 9ee6ca805e..ef4c75fc4a 100644
--- a/src/responder/nss/nss_cmd.c
+++ b/src/responder/nss/nss_cmd.c
@@ -493,12 +493,16 @@ static errno_t invalidate_cache(struct nss_cmd_ctx *cmd_ctx,
 return ret;
 }
 
-memcache_delete_entry(cmd_ctx->nss_ctx, cmd_ctx->nss_ctx->rctx, NULL,
-  output_name, 0, memcache_type);
 if (memcache_type == SSS_MC_INITGROUPS) {
+memcache_delete_entry(cmd_ctx->nss_ctx, cmd_ctx->nss_ctx->rctx, NULL,
+  result->lookup_name, 0, memcache_type);
+
 /* Invalidate the passwd data as well */
 memcache_delete_entry(cmd_ctx->nss_ctx, cmd_ctx->nss_ctx->rctx,
   result->domain, output_name, 0, SSS_MC_PASSWD);
+} else {
+memcache_delete_entry(cmd_ctx->nss_ctx, cmd_ctx->nss_ctx->rctx, NULL,
+  output_name, 0, memcache_type);
 }
 talloc_free(output_name);
 
diff --git a/src/responder/nss/nss_get_object.c b/src/responder/nss/nss_get_object.c
index 15faced006..bab817ab4a 100644
--- a/src/responder/nss/nss_get_object.c
+++ b/src/responder/nss/nss_get_object.c
@@ -109,12 +109,17 @@ memcache_delete_entry(struct nss_ctx *nss_ctx,
 }
 
 if (name != NULL) {
-ret = sized_output_name(NULL, rctx, name, dom, _name);
-if (ret != EOK) {
-DEBUG(SSSDBG_OP_FAILURE,
-  "Unable to create sized name [%d]: %s\n",
-  ret, sss_strerror(ret));
-return ret;
+if (type == SSS_MC_INITGROUPS) {
+sized_name = talloc_zero(NULL, struct sized_string);
+to_sized_string(sized_name, name);
+} else {
+ret = sized_output_name(NULL, rctx, name, dom, _name);
+if (ret != EOK) {
+DEBUG(SSSDBG_OP_FAILURE,
+"Unable to create sized name [%d]: %s\n",
+ret, sss_strerror(ret));
+return ret;
+}
 }
 
 ret = memcache_delete_entry_by_name(nss_ctx, sized_name, type);

From e9f7d71d169ed8aa81644b4db79b2bb2bbd1dee0 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek 
Date: Mon, 23 Apr 2018 21:33:49 +0200
Subject: [PATCH 2/2] TESTS: Add tests for the sss_nss_getgrouplist_timeout
 function

---
 src/tests/intg/Makefile.am|   2 +
 src/tests/intg/sssd_nss_ex.py |  86 +++
 src/tests/intg/test_nss_ex.py | 261 ++
 3 files changed, 349 insertions(+)
 create mode 100644 src/tests/intg/sssd_nss_ex.py
 create mode 100644 src/tests/intg/test_nss_ex.py

diff --git a/src/tests/intg/Makefile.am b/src/tests/intg/Makefile.am
index 9c53382613..028fe8ed3c 100644
--- a/src/tests/intg/Makefile.am
+++ b/src/tests/intg/Makefile.am
@@ -3,6 +3,7 @@ dist_noinst_DATA = \
 config.py.m4 \
 util.py \
 sssd_nss.py \
+sssd_nss_ex.py \
 sssd_id.py \
 sssd_ldb.py \
 sssd_netgroup.py \
@@ -36,6 +37,7 @@ dist_noinst_DATA = \
 data/ad_schema.ldif \
 test_pysss_nss_idmap.py \
 test_infopipe.py \
+test_nss_ex.py \
 $(NULL)
 
 EXTRA_DIST = data/cwrap-dbus-system.conf.in
diff --git a/src/tests/intg/sssd_nss_ex.py b/src/tests/intg/sssd_nss_ex.py
new file mode 100644
index 00..381f3cae34
--- /dev/null
+++ b/src/tests/intg/sssd_nss_ex.py
@@ -0,0 +1,86 @@
+#
+# Shared module for integration tests that need to access the sssd_nss_ex
+# interface directly
+#
+# Copyright (c) 2018 Red Hat, Inc.
+#
+# This is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 only
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see .
+
+import config
+import errno
+from ctypes import (cdll, c_int, c_char_p, c_char,
+