dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone

Blame SOURCES/0079-autofs-use-cache_req-to-obtain-single-entry-in-geten.patch

8d3578
From 27d2dcfb76625bffe34d2fe185d7677db3f372d6 Mon Sep 17 00:00:00 2001
8d3578
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
8d3578
Date: Tue, 13 Aug 2019 13:10:03 +0200
8d3578
Subject: [PATCH 79/90] autofs: use cache_req to obtain single entry in
8d3578
 getentrybyname
8d3578
MIME-Version: 1.0
8d3578
Content-Type: text/plain; charset=UTF-8
8d3578
Content-Transfer-Encoding: 8bit
8d3578
8d3578
Resolves:
8d3578
https://pagure.io/SSSD/sssd/issue/2607
8d3578
8d3578
Reviewed-by: Tomáš Halman <thalman@redhat.com>
8d3578
---
8d3578
 src/responder/autofs/autofssrv_cmd.c | 54 ++++++++++------------------
8d3578
 1 file changed, 19 insertions(+), 35 deletions(-)
8d3578
8d3578
diff --git a/src/responder/autofs/autofssrv_cmd.c b/src/responder/autofs/autofssrv_cmd.c
8d3578
index 670b6d50d..59e64014d 100644
8d3578
--- a/src/responder/autofs/autofssrv_cmd.c
8d3578
+++ b/src/responder/autofs/autofssrv_cmd.c
8d3578
@@ -750,27 +750,28 @@ autofs_read_getautomntbyname_input(struct cli_ctx *cli_ctx,
8d3578
 
8d3578
 static errno_t
8d3578
 autofs_write_getautomntbyname_output(struct cli_ctx *cli_ctx,
8d3578
-                                     struct autofs_enum_ctx *enum_ctx,
8d3578
+                                     struct cache_req_result *result,
8d3578
                                      const char *keyname)
8d3578
 {
8d3578
     struct cli_protocol *pctx;
8d3578
-    struct ldb_message **entries;
8d3578
-    struct ldb_message *entry = NULL;
8d3578
-    const char *entry_key;
8d3578
+    struct ldb_message *entry;
8d3578
     const char *value;
8d3578
     size_t value_len;
8d3578
     size_t len;
8d3578
-    size_t count;
8d3578
     uint8_t *body;
8d3578
     size_t blen;
8d3578
     size_t rp;
8d3578
-    size_t i;
8d3578
     errno_t ret;
8d3578
 
8d3578
     pctx = talloc_get_type(cli_ctx->protocol_ctx, struct cli_protocol);
8d3578
 
8d3578
-    count = enum_ctx->found ? enum_ctx->result->count - 1 : 0;
8d3578
-    entries = count > 0 ? enum_ctx->result->msgs + 1 : NULL;
8d3578
+    if (result == NULL || result->count == 0) {
8d3578
+        DEBUG(SSSDBG_TRACE_FUNC, "Key [%s] was not found\n", keyname);
8d3578
+        return sss_cmd_empty_packet(pctx->creq->out);
8d3578
+    }
8d3578
+
8d3578
+    DEBUG(SSSDBG_TRACE_INTERNAL, "Found key [%s]\n", keyname);
8d3578
+    entry = result->msgs[0];
8d3578
 
8d3578
     ret = sss_packet_new(pctx->creq, 0, sss_packet_get_cmd(pctx->creq->in),
8d3578
                          &pctx->creq->out);
8d3578
@@ -778,27 +779,6 @@ autofs_write_getautomntbyname_output(struct cli_ctx *cli_ctx,
8d3578
         return ret;
8d3578
     }
8d3578
 
8d3578
-    for (i = 0; i < count; i++) {
8d3578
-        entry_key = ldb_msg_find_attr_as_string(entries[i],
8d3578
-                                                SYSDB_AUTOFS_ENTRY_KEY,
8d3578
-                                                NULL);
8d3578
-        if (entry_key == NULL) {
8d3578
-            DEBUG(SSSDBG_MINOR_FAILURE, "Skipping incomplete entry\n");
8d3578
-            continue;
8d3578
-        }
8d3578
-
8d3578
-        if (strcmp(entry_key, keyname) == 0) {
8d3578
-            DEBUG(SSSDBG_TRACE_INTERNAL, "Found key [%s]\n", keyname);
8d3578
-            entry = entries[i];
8d3578
-            break;
8d3578
-        }
8d3578
-    }
8d3578
-
8d3578
-    if (!enum_ctx->found || count == 0 || entry == NULL) {
8d3578
-        DEBUG(SSSDBG_TRACE_FUNC, "Key [%s] was not found\n", keyname);
8d3578
-        return sss_cmd_empty_packet(pctx->creq->out);
8d3578
-    }
8d3578
-
8d3578
     value = ldb_msg_find_attr_as_string(entry, SYSDB_AUTOFS_ENTRY_VALUE, NULL);
8d3578
     if (value == NULL) {
8d3578
         DEBUG(SSSDBG_CRIT_FAILURE, "No entry value found in [%s]\n", keyname);
8d3578
@@ -856,10 +836,14 @@ sss_autofs_cmd_getautomntbyname(struct cli_ctx *cli_ctx)
8d3578
         goto done;
8d3578
     }
8d3578
 
8d3578
-    DEBUG(SSSDBG_TRACE_FUNC, "Obtaining enumeration context for %s\n",
8d3578
-          cmd_ctx->mapname);
8d3578
+    DEBUG(SSSDBG_TRACE_FUNC, "Obtaining autofs entry %s:%s\n",
8d3578
+          cmd_ctx->mapname, cmd_ctx->keyname);
8d3578
 
8d3578
-    req = autofs_setent_send(cli_ctx, cli_ctx->ev, autofs_ctx, cmd_ctx->mapname);
8d3578
+    req = cache_req_autofs_entry_by_name_send(cli_ctx, cli_ctx->ev,
8d3578
+                                              autofs_ctx->rctx,
8d3578
+                                              autofs_ctx->rctx->ncache, 0, NULL,
8d3578
+                                              cmd_ctx->mapname,
8d3578
+                                              cmd_ctx->keyname);
8d3578
     if (req == NULL) {
8d3578
         DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create tevent request\n");
8d3578
         ret = ENOMEM;
8d3578
@@ -877,20 +861,20 @@ done:
8d3578
 static void
8d3578
 sss_autofs_cmd_getautomntbyname_done(struct tevent_req *req)
8d3578
 {
8d3578
-    struct autofs_enum_ctx *enum_ctx;
8d3578
+    struct cache_req_result *result;
8d3578
     struct autofs_cmd_ctx *cmd_ctx;
8d3578
     errno_t ret;
8d3578
 
8d3578
     cmd_ctx = tevent_req_callback_data(req, struct autofs_cmd_ctx);
8d3578
 
8d3578
-    ret = autofs_setent_recv(req, &enum_ctx);
8d3578
+    ret = cache_req_autofs_entry_by_name_recv(cmd_ctx, req, &result);
8d3578
     talloc_zfree(req);
8d3578
     if (ret != EOK) {
8d3578
         autofs_cmd_done(cmd_ctx, ret);
8d3578
         return;
8d3578
     }
8d3578
 
8d3578
-    ret = autofs_write_getautomntbyname_output(cmd_ctx->cli_ctx, enum_ctx,
8d3578
+    ret = autofs_write_getautomntbyname_output(cmd_ctx->cli_ctx, result,
8d3578
                                                cmd_ctx->keyname);
8d3578
     if (ret != EOK) {
8d3578
         DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create reply packet "
8d3578
-- 
8d3578
2.20.1
8d3578