Blame SOURCES/0088-autofs-always-refresh-auto.master.patch

5fca41
From ac712654f07be9e9c05156c89af54eac483d75d6 Mon Sep 17 00:00:00 2001
5fca41
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
5fca41
Date: Mon, 2 Sep 2019 13:05:14 +0200
5fca41
Subject: [PATCH 88/90] autofs: always refresh auto.master
5fca41
MIME-Version: 1.0
5fca41
Content-Type: text/plain; charset=UTF-8
5fca41
Content-Transfer-Encoding: 8bit
5fca41
5fca41
Reviewed-by: Tomáš Halman <thalman@redhat.com>
5fca41
---
5fca41
 src/responder/autofs/autofs_private.h | 10 ++++-
5fca41
 src/responder/autofs/autofssrv.c      | 25 ++++++++----
5fca41
 src/responder/autofs/autofssrv_cmd.c  | 56 ++++++++++++++++++++++-----
5fca41
 3 files changed, 74 insertions(+), 17 deletions(-)
5fca41
5fca41
diff --git a/src/responder/autofs/autofs_private.h b/src/responder/autofs/autofs_private.h
5fca41
index 3be25d4d9..175a7768f 100644
5fca41
--- a/src/responder/autofs/autofs_private.h
5fca41
+++ b/src/responder/autofs/autofs_private.h
5fca41
@@ -21,6 +21,8 @@
5fca41
 #ifndef _AUTOFSSRV_PRIVATE_H_
5fca41
 #define _AUTOFSSRV_PRIVATE_H_
5fca41
 
5fca41
+#include <dhash.h>
5fca41
+
5fca41
 #include "responder/common/responder.h"
5fca41
 #include "responder/common/responder_sbus.h"
5fca41
 #include "responder/common/cache_req/cache_req.h"
5fca41
@@ -55,6 +57,12 @@ struct autofs_enum_ctx {
5fca41
     /* False if the result is being created. */
5fca41
     bool ready;
5fca41
 
5fca41
+    /* Enumeration context key. */
5fca41
+    const char *key;
5fca41
+
5fca41
+    /* Hash table that contains this enumeration context. */
5fca41
+    hash_table_t *table;
5fca41
+
5fca41
     /* Requests that awaits the data. */
5fca41
     struct setent_req_list *notify_list;
5fca41
 };
5fca41
@@ -62,6 +70,6 @@ struct autofs_enum_ctx {
5fca41
 struct sss_cmd_table *get_autofs_cmds(void);
5fca41
 int autofs_connection_setup(struct cli_ctx *cctx);
5fca41
 
5fca41
-errno_t autofs_orphan_maps(struct autofs_ctx *actx);
5fca41
+void autofs_orphan_maps(struct autofs_ctx *actx);
5fca41
 
5fca41
 #endif /* _AUTOFSSRV_PRIVATE_H_ */
5fca41
diff --git a/src/responder/autofs/autofssrv.c b/src/responder/autofs/autofssrv.c
5fca41
index 309ed76b1..922da5fd4 100644
5fca41
--- a/src/responder/autofs/autofssrv.c
5fca41
+++ b/src/responder/autofs/autofssrv.c
5fca41
@@ -85,17 +85,26 @@ static int autofs_clean_hash_table(struct sbus_request *dbus_req, void *data)
5fca41
     struct resp_ctx *rctx = talloc_get_type(data, struct resp_ctx);
5fca41
     struct autofs_ctx *actx =
5fca41
             talloc_get_type(rctx->pvt_ctx, struct autofs_ctx);
5fca41
-    errno_t ret;
5fca41
 
5fca41
-    ret = autofs_orphan_maps(actx);
5fca41
-    if (ret != EOK) {
5fca41
-        DEBUG(SSSDBG_OP_FAILURE, "Could not invalidate maps\n");
5fca41
-        return ret;
5fca41
-    }
5fca41
+    autofs_orphan_maps(actx);
5fca41
 
5fca41
     return sbus_request_return_and_finish(dbus_req, DBUS_TYPE_INVALID);
5fca41
 }
5fca41
 
5fca41
+static void
5fca41
+autofs_maps_delete_cb(hash_entry_t *item,
5fca41
+                      hash_destroy_enum deltype,
5fca41
+                      void *pvt)
5fca41
+{
5fca41
+    struct autofs_ctx *autofs_ctx;
5fca41
+    struct autofs_enum_ctx *enum_ctx;
5fca41
+
5fca41
+    autofs_ctx = talloc_get_type(pvt, struct autofs_ctx);
5fca41
+
5fca41
+    enum_ctx = sss_ptr_get_value(&item->value, struct autofs_enum_ctx);
5fca41
+    talloc_unlink(autofs_ctx->maps, enum_ctx);
5fca41
+}
5fca41
+
5fca41
 static int
5fca41
 autofs_process_init(TALLOC_CTX *mem_ctx,
5fca41
                     struct tevent_context *ev,
5fca41
@@ -158,7 +167,9 @@ autofs_process_init(TALLOC_CTX *mem_ctx,
5fca41
     }
5fca41
 
5fca41
     /* Create the lookup table for setautomntent results */
5fca41
-    autofs_ctx->maps = sss_ptr_hash_create(autofs_ctx, NULL, NULL);
5fca41
+    autofs_ctx->maps = sss_ptr_hash_create(autofs_ctx,
5fca41
+                                           autofs_maps_delete_cb,
5fca41
+                                           autofs_ctx);
5fca41
     if (autofs_ctx->maps == NULL) {
5fca41
         DEBUG(SSSDBG_CRIT_FAILURE,
5fca41
               "Unable to initialize automount maps hash table\n");
5fca41
diff --git a/src/responder/autofs/autofssrv_cmd.c b/src/responder/autofs/autofssrv_cmd.c
5fca41
index d413f8570..71938399e 100644
5fca41
--- a/src/responder/autofs/autofssrv_cmd.c
5fca41
+++ b/src/responder/autofs/autofssrv_cmd.c
5fca41
@@ -131,12 +131,12 @@ autofs_fill_entry(struct ldb_message *entry, struct sss_packet *packet, size_t *
5fca41
     return EOK;
5fca41
 }
5fca41
 
5fca41
-errno_t
5fca41
+void
5fca41
 autofs_orphan_maps(struct autofs_ctx *autofs_ctx)
5fca41
 {
5fca41
-    sss_ptr_hash_delete_all(autofs_ctx->maps, true);
5fca41
-
5fca41
-    return EOK;
5fca41
+    /* It will automatically decrease the refcount of enum_ctx through
5fca41
+     * delete callback. */
5fca41
+    sss_ptr_hash_delete_all(autofs_ctx->maps, false);
5fca41
 }
5fca41
 
5fca41
 static void
5fca41
@@ -149,8 +149,8 @@ autofs_enumctx_lifetime_timeout(struct tevent_context *ev,
5fca41
 
5fca41
     enum_ctx = talloc_get_type(pvt, struct autofs_enum_ctx);
5fca41
 
5fca41
-    /* Free the context. It will be automatically removed from the hash table. */
5fca41
-    talloc_free(enum_ctx);
5fca41
+    /* Remove it from the table. It will automatically decrease the refcount. */
5fca41
+    sss_ptr_hash_delete(enum_ctx->table, enum_ctx->key, false);
5fca41
 }
5fca41
 
5fca41
 static void
5fca41
@@ -185,6 +185,13 @@ autofs_create_enumeration_context(TALLOC_CTX *mem_ctx,
5fca41
     }
5fca41
 
5fca41
     enum_ctx->ready = false;
5fca41
+    enum_ctx->table = autofs_ctx->maps;
5fca41
+
5fca41
+    enum_ctx->key = talloc_strdup(enum_ctx, mapname);
5fca41
+    if (enum_ctx->key == NULL) {
5fca41
+        talloc_free(enum_ctx);
5fca41
+        return NULL;
5fca41
+    }
5fca41
 
5fca41
     ret = sss_ptr_hash_add(autofs_ctx->maps, mapname,
5fca41
                            enum_ctx, struct autofs_enum_ctx);
5fca41
@@ -196,6 +203,34 @@ autofs_create_enumeration_context(TALLOC_CTX *mem_ctx,
5fca41
     return enum_ctx;
5fca41
 }
5fca41
 
5fca41
+static void
5fca41
+autofs_orphan_master_map(struct autofs_ctx *autofs_ctx,
5fca41
+                         const char *mapname)
5fca41
+{
5fca41
+    struct sss_domain_info *dom;
5fca41
+    errno_t ret;
5fca41
+
5fca41
+    if (strcmp(mapname, "auto.master") != 0) {
5fca41
+        return;
5fca41
+    }
5fca41
+
5fca41
+    DEBUG(SSSDBG_TRACE_FUNC, "Invalidating master map\n");
5fca41
+
5fca41
+    /* Remove and invalidate all maps. */
5fca41
+    autofs_orphan_maps(autofs_ctx);
5fca41
+
5fca41
+    DEBUG(SSSDBG_TRACE_FUNC, "Invalidating autofs maps\n");
5fca41
+    for (dom = autofs_ctx->rctx->domains;
5fca41
+         dom != NULL;
5fca41
+         dom = get_next_domain(dom, SSS_GND_DESCEND)) {
5fca41
+        ret = sysdb_invalidate_autofs_maps(dom);
5fca41
+        if (ret != EOK) {
5fca41
+            DEBUG(SSSDBG_MINOR_FAILURE, "Unable to invalidate maps in "
5fca41
+                  "%s [%d]: %s\n", dom->name, ret, sss_strerror(ret));
5fca41
+        }
5fca41
+    }
5fca41
+}
5fca41
+
5fca41
 struct autofs_setent_state {
5fca41
     struct autofs_ctx *autofs_ctx;
5fca41
     struct autofs_enum_ctx *enum_ctx;
5fca41
@@ -323,7 +358,8 @@ static void autofs_setent_done(struct tevent_req *subreq)
5fca41
 }
5fca41
 
5fca41
 static errno_t
5fca41
-autofs_setent_recv(struct tevent_req *req,
5fca41
+autofs_setent_recv(TALLOC_CTX *mem_ctx,
5fca41
+                   struct tevent_req *req,
5fca41
                    struct autofs_enum_ctx **_enum_ctx)
5fca41
 {
5fca41
     struct autofs_setent_state *state;
5fca41
@@ -331,7 +367,7 @@ autofs_setent_recv(struct tevent_req *req,
5fca41
 
5fca41
     TEVENT_REQ_RETURN_ON_ERROR(req);
5fca41
 
5fca41
-    *_enum_ctx = state->enum_ctx;
5fca41
+    *_enum_ctx = talloc_reference(mem_ctx, state->enum_ctx);
5fca41
 
5fca41
     return EOK;
5fca41
 }
5fca41
@@ -430,6 +466,8 @@ sss_autofs_cmd_setautomntent(struct cli_ctx *cli_ctx)
5fca41
         goto done;
5fca41
     }
5fca41
 
5fca41
+    autofs_orphan_master_map(autofs_ctx, cmd_ctx->mapname);
5fca41
+
5fca41
     DEBUG(SSSDBG_TRACE_FUNC, "Obtaining autofs map %s\n",
5fca41
           cmd_ctx->mapname);
5fca41
 
5fca41
@@ -668,7 +706,7 @@ sss_autofs_cmd_getautomntent_done(struct tevent_req *req)
5fca41
 
5fca41
     cmd_ctx = tevent_req_callback_data(req, struct autofs_cmd_ctx);
5fca41
 
5fca41
-    ret = autofs_setent_recv(req, &enum_ctx);
5fca41
+    ret = autofs_setent_recv(cmd_ctx, req, &enum_ctx);
5fca41
     talloc_zfree(req);
5fca41
     if (ret != EOK) {
5fca41
         autofs_cmd_done(cmd_ctx, ret);
5fca41
-- 
5fca41
2.20.1
5fca41