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

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