|
|
6cf099 |
From c12a2635adacbb321c4c2208160f2eb306333e71 Mon Sep 17 00:00:00 2001
|
|
|
6cf099 |
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
|
|
|
6cf099 |
Date: Sun, 11 Oct 2015 16:45:19 +0200
|
|
|
6cf099 |
Subject: [PATCH 102/104] nss: send original name and id with local views if
|
|
|
6cf099 |
possible
|
|
|
6cf099 |
|
|
|
6cf099 |
Resolves:
|
|
|
6cf099 |
https://fedorahosted.org/sssd/ticket/2833
|
|
|
6cf099 |
|
|
|
6cf099 |
Reviewed-by: Sumit Bose <sbose@redhat.com>
|
|
|
6cf099 |
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
6cf099 |
(cherry picked from commit 2f793681b4debbe015815f908dc12c0463711609)
|
|
|
6cf099 |
---
|
|
|
6cf099 |
src/responder/nss/nsssrv_cmd.c | 131 ++++++++++++++++++++++++++++++++++++++++-
|
|
|
6cf099 |
1 file changed, 128 insertions(+), 3 deletions(-)
|
|
|
6cf099 |
|
|
|
6cf099 |
diff --git a/src/responder/nss/nsssrv_cmd.c b/src/responder/nss/nsssrv_cmd.c
|
|
|
6cf099 |
index d177135db00369c2af69eb62f6a4a4aaf54ba510..39fd5b41a31796a05a1790e78cb6c425b39c47cb 100644
|
|
|
6cf099 |
--- a/src/responder/nss/nsssrv_cmd.c
|
|
|
6cf099 |
+++ b/src/responder/nss/nsssrv_cmd.c
|
|
|
6cf099 |
@@ -599,6 +599,124 @@ is_refreshed_on_bg(enum sss_dp_acct_type req_type,
|
|
|
6cf099 |
|
|
|
6cf099 |
static void nsssrv_dp_send_acct_req_done(struct tevent_req *req);
|
|
|
6cf099 |
|
|
|
6cf099 |
+static void get_dp_name_and_id(TALLOC_CTX *mem_ctx,
|
|
|
6cf099 |
+ struct sss_domain_info *dom,
|
|
|
6cf099 |
+ enum sss_dp_acct_type req_type,
|
|
|
6cf099 |
+ const char *opt_name,
|
|
|
6cf099 |
+ uint32_t opt_id,
|
|
|
6cf099 |
+ const char **_name,
|
|
|
6cf099 |
+ uint32_t *_id)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ TALLOC_CTX *tmp_ctx;
|
|
|
6cf099 |
+ struct ldb_result *res = NULL;
|
|
|
6cf099 |
+ const char *attr;
|
|
|
6cf099 |
+ const char *name;
|
|
|
6cf099 |
+ uint32_t id;
|
|
|
6cf099 |
+ errno_t ret;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ /* First set the same values to make things easier. */
|
|
|
6cf099 |
+ *_name = opt_name;
|
|
|
6cf099 |
+ *_id = opt_id;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ if (!DOM_HAS_VIEWS(dom) || !is_local_view(dom->view_name)) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_TRACE_FUNC, "Not a LOCAL view, continuing with "
|
|
|
6cf099 |
+ "provided values.\n");
|
|
|
6cf099 |
+ return;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ tmp_ctx = talloc_new(NULL);
|
|
|
6cf099 |
+ if (tmp_ctx == NULL) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n");
|
|
|
6cf099 |
+ return;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ if (opt_name != NULL) {
|
|
|
6cf099 |
+ switch (req_type) {
|
|
|
6cf099 |
+ case SSS_DP_USER:
|
|
|
6cf099 |
+ case SSS_DP_INITGROUPS:
|
|
|
6cf099 |
+ ret = sysdb_getpwnam_with_views(tmp_ctx, dom, opt_name, &res;;
|
|
|
6cf099 |
+ if (ret != EOK) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_CONF_SETTINGS,
|
|
|
6cf099 |
+ "sysdb_getpwnam_with_views() failed [%d]: %s\n",
|
|
|
6cf099 |
+ ret, sss_strerror(ret));
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+ break;
|
|
|
6cf099 |
+ case SSS_DP_GROUP:
|
|
|
6cf099 |
+ ret = sysdb_getgrnam_with_views(tmp_ctx, dom, opt_name, &res;;
|
|
|
6cf099 |
+ if (ret != EOK) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_CONF_SETTINGS,
|
|
|
6cf099 |
+ "sysdb_getgrnam_with_views() failed [%d]: %s\n",
|
|
|
6cf099 |
+ ret, sss_strerror(ret));
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+ break;
|
|
|
6cf099 |
+ default:
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ if (res == NULL || res->count != 1) {
|
|
|
6cf099 |
+ /* This should not happen with LOCAL view and overridden value. */
|
|
|
6cf099 |
+ DEBUG(SSSDBG_TRACE_FUNC, "Entry is missing?! Continuing with "
|
|
|
6cf099 |
+ "provided values.\n");
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ name = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_NAME, NULL);
|
|
|
6cf099 |
+ if (name == NULL) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_CRIT_FAILURE, "Bug: name cannot be NULL\n");
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ *_name = talloc_steal(mem_ctx, name);
|
|
|
6cf099 |
+ } else if (opt_id != 0) {
|
|
|
6cf099 |
+ switch (req_type) {
|
|
|
6cf099 |
+ case SSS_DP_USER:
|
|
|
6cf099 |
+ ret = sysdb_getpwuid_with_views(tmp_ctx, dom, opt_id, &res;;
|
|
|
6cf099 |
+ if (ret != EOK) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_CONF_SETTINGS,
|
|
|
6cf099 |
+ "sysdb_getpwuid_with_views() failed [%d]: %s\n",
|
|
|
6cf099 |
+ ret, sss_strerror(ret));
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ attr = SYSDB_UIDNUM;
|
|
|
6cf099 |
+ break;
|
|
|
6cf099 |
+ case SSS_DP_GROUP:
|
|
|
6cf099 |
+ ret = sysdb_getgrgid_with_views(tmp_ctx, dom, opt_id, &res;;
|
|
|
6cf099 |
+ if (ret != EOK) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_CONF_SETTINGS,
|
|
|
6cf099 |
+ "sysdb_getgrgid_with_views() failed [%d]: %s\n",
|
|
|
6cf099 |
+ ret, sss_strerror(ret));
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ attr = SYSDB_GIDNUM;
|
|
|
6cf099 |
+ break;
|
|
|
6cf099 |
+ default:
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ if (res == NULL || res->count != 1) {
|
|
|
6cf099 |
+ /* This should not happen with LOCAL view and overridden value. */
|
|
|
6cf099 |
+ DEBUG(SSSDBG_TRACE_FUNC, "Entry is missing?! Continuing with "
|
|
|
6cf099 |
+ "provided values.\n");
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ id = ldb_msg_find_attr_as_uint64(res->msgs[0], attr, 0);
|
|
|
6cf099 |
+ if (id == 0) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_CRIT_FAILURE, "Bug: id cannot be 0\n");
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ *_id = id;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+done:
|
|
|
6cf099 |
+ talloc_free(tmp_ctx);
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
/* FIXME: do not check res->count, but get in a msgs and check in parent */
|
|
|
6cf099 |
errno_t check_cache(struct nss_dom_ctx *dctx,
|
|
|
6cf099 |
struct nss_ctx *nctx,
|
|
|
6cf099 |
@@ -616,6 +734,8 @@ errno_t check_cache(struct nss_dom_ctx *dctx,
|
|
|
6cf099 |
struct tevent_req *req = NULL;
|
|
|
6cf099 |
struct dp_callback_ctx *cb_ctx = NULL;
|
|
|
6cf099 |
uint64_t cacheExpire = 0;
|
|
|
6cf099 |
+ const char *name = opt_name;
|
|
|
6cf099 |
+ uint32_t id = opt_id;
|
|
|
6cf099 |
|
|
|
6cf099 |
/* when searching for a user or netgroup, more than one reply is a
|
|
|
6cf099 |
* db error
|
|
|
6cf099 |
@@ -627,6 +747,11 @@ errno_t check_cache(struct nss_dom_ctx *dctx,
|
|
|
6cf099 |
return ENOENT;
|
|
|
6cf099 |
}
|
|
|
6cf099 |
|
|
|
6cf099 |
+ /* In case of local view we have to always contant DP with the original
|
|
|
6cf099 |
+ * name or id. */
|
|
|
6cf099 |
+ get_dp_name_and_id(dctx->cmdctx, dctx->domain, req_type, opt_name, opt_id,
|
|
|
6cf099 |
+ &name, &id;;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
/* if we have any reply let's check cache validity, but ignore netgroups
|
|
|
6cf099 |
* if refresh_expired_interval is set (which implies that another method
|
|
|
6cf099 |
* is used to refresh netgroups)
|
|
|
6cf099 |
@@ -671,10 +796,10 @@ errno_t check_cache(struct nss_dom_ctx *dctx,
|
|
|
6cf099 |
* immediately.
|
|
|
6cf099 |
*/
|
|
|
6cf099 |
DEBUG(SSSDBG_TRACE_FUNC,
|
|
|
6cf099 |
- "Performing midpoint cache update on [%s]\n", opt_name);
|
|
|
6cf099 |
+ "Performing midpoint cache update on [%s]\n", name);
|
|
|
6cf099 |
|
|
|
6cf099 |
req = sss_dp_get_account_send(cctx, cctx->rctx, dctx->domain, true,
|
|
|
6cf099 |
- req_type, opt_name, opt_id, extra);
|
|
|
6cf099 |
+ req_type, name, id, extra);
|
|
|
6cf099 |
if (!req) {
|
|
|
6cf099 |
DEBUG(SSSDBG_CRIT_FAILURE,
|
|
|
6cf099 |
"Out of memory sending out-of-band data provider "
|
|
|
6cf099 |
@@ -703,7 +828,7 @@ errno_t check_cache(struct nss_dom_ctx *dctx,
|
|
|
6cf099 |
}
|
|
|
6cf099 |
|
|
|
6cf099 |
req = sss_dp_get_account_send(cctx, cctx->rctx, dctx->domain, true,
|
|
|
6cf099 |
- req_type, opt_name, opt_id, extra);
|
|
|
6cf099 |
+ req_type, name, id, extra);
|
|
|
6cf099 |
if (!req) {
|
|
|
6cf099 |
DEBUG(SSSDBG_CRIT_FAILURE,
|
|
|
6cf099 |
"Out of memory sending data provider request\n");
|
|
|
6cf099 |
--
|
|
|
6cf099 |
2.4.3
|
|
|
6cf099 |
|