[SSSD] [PATCH] Always request the auto.master map from Data Provider

Jakub Hrozek jhrozek at redhat.com
Sat Dec 15 17:39:16 UTC 2012


The attached patches implement functionality the admins have been asking
for in the autofs responder - when the auto.master map is requested,
refresh the mountpoints.

The motivation is that it is quite common for the admin to change the
maps and just SIGHUP the automounter or run automounter -m for testing
and see the current maps.

https://fedorahosted.org/sssd/ticket/1592

I tried to split the patches into small consumable pieces. Hopefully it
will ease the review.

[PATCH 1/7] SYSDB: fix copy-n-paste error
A one-liner

[PATCH 2/7] SYSDB: Add API to invalidate all map objects
This sysdb API will be used later to invalidate the autofs maps

[PATCH 3/7] DP: invalidate all cached maps if a request for auto.master
comes in
If the Data Provider receives a request for the auto.master map, it
passes on a flag to let the actual provider let know he should
invalidate the existing maps

[PATCH 4/7] AUTOFS: allow removing entries from hash table
There is a timed desctructor in the autofs responder that, when the
entry timeout passes, removes the autofs map from the hash table while
the map is freed. This patch adds a hash delete callback so that if the
map is removed from the hash table with hash_delete, its hash table
pointer will be invalidated. Later, when the entry is being freed, the
destructor won't attempt to remove it from the hash table.

[PATCH 5/7] AUTOFS: remove all maps from hash if request for auto.master
comes in
When a request for auto.master comes in, we need to remove all the maps
from the lookup hash table. We can't simply delete the maps, because
another request might be processing them, so instead the maps are
removed from the hash table, effectively becoming orphaned. The maps
will get freed when the timed destructor is invoked.

[PATCH 6/7] RESPONDERS: Create a common file with service names and
versions
The monitor sends calls different sbus methods to different responders.
Instead of including headers of the particular responders directly in
monitor, which breaks layering a little, create a common header file
that will be included from src/responder/common/

[PATCH 7/7] AUTOFS: Clear enum cache if a request comes in from the
sss_cache
In order for sss_cache to work correctly, we must also signal the autofs
responder to invalidate the hash table requests.
-------------- next part --------------
>From c8d628b49328fddd91a58ca00ca8369486560444 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek at redhat.com>
Date: Sat, 15 Dec 2012 13:18:16 +0100
Subject: [PATCH 1/7] SYSDB: fix copy-n-paste error

---
 src/db/sysdb_autofs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/db/sysdb_autofs.c b/src/db/sysdb_autofs.c
index c5ec4c8c6edf2fff8e0a0d17fab1b87a093df7bc..cbef2dfa32b6abf1c6985cc3c4779e0e744e3c5a 100644
--- a/src/db/sysdb_autofs.c
+++ b/src/db/sysdb_autofs.c
@@ -195,7 +195,7 @@ sysdb_get_map_byname(TALLOC_CTX *mem_ctx,
     filter = talloc_asprintf(tmp_ctx, "(&(objectclass=%s)(%s=%s))",
                              SYSDB_AUTOFS_MAP_OC, SYSDB_NAME, safe_map_name);
     if (!filter) {
-        ret = EOK;
+        ret = ENOMEM;
         goto done;
     }
 
-- 
1.8.0.2

-------------- next part --------------
>From 4667bac9252f0c4d8a19140ba2552232addd8af9 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek at redhat.com>
Date: Sat, 15 Dec 2012 13:19:04 +0100
Subject: [PATCH 2/7] SYSDB: Add API to invalidate all map objects

This sysdb API will be used later to invalidate the autofs maps
---
 src/db/sysdb_autofs.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/db/sysdb_autofs.h |  3 ++
 2 files changed, 94 insertions(+)

diff --git a/src/db/sysdb_autofs.c b/src/db/sysdb_autofs.c
index cbef2dfa32b6abf1c6985cc3c4779e0e744e3c5a..57380cfdcde2bc43befcaee94c7d9f540dd88b97 100644
--- a/src/db/sysdb_autofs.c
+++ b/src/db/sysdb_autofs.c
@@ -417,3 +417,94 @@ done:
     talloc_free(tmp_ctx);
     return ret;
 }
+
+errno_t
+sysdb_invalidate_autofs_maps(struct sysdb_ctx *sysdb)
+{
+    errno_t ret;
+    TALLOC_CTX *tmp_ctx;
+    const char *filter;
+    struct sysdb_attrs *sys_attrs = NULL;
+    const char *attrs[] = { SYSDB_OBJECTCLASS,
+                            SYSDB_NAME,
+                            SYSDB_CACHE_EXPIRE,
+                            NULL };
+    size_t count;
+    struct ldb_message **msgs;
+    const char *name;
+    bool in_transaction = false;
+    int sret;
+    int i;
+
+    tmp_ctx = talloc_new(NULL);
+    if (!tmp_ctx) return ENOMEM;
+
+    filter = talloc_asprintf(tmp_ctx, "(&(objectclass=%s)(%s=*))",
+                             SYSDB_AUTOFS_MAP_OC, SYSDB_NAME);
+    if (!filter) {
+        ret = ENOMEM;
+        goto done;
+    }
+
+    ret = sysdb_search_custom(tmp_ctx, sysdb, filter,
+                              AUTOFS_MAP_SUBDIR, attrs,
+                              &count, &msgs);
+    if (ret != EOK && ret != ENOENT) {
+        DEBUG(SSSDBG_CRIT_FAILURE,
+              ("Error looking up autofs maps"));
+        goto done;
+    } else if (ret == ENOENT) {
+        ret = EOK;
+        goto done;
+    }
+
+    sys_attrs = sysdb_new_attrs(tmp_ctx);
+    if (!sys_attrs) {
+        ret = ENOMEM;
+        goto done;
+    }
+
+    ret = sysdb_attrs_add_time_t(sys_attrs, SYSDB_CACHE_EXPIRE, 1);
+    if (ret != EOK) {
+        goto done;
+    }
+
+    ret = sysdb_transaction_start(sysdb);
+    if (ret != EOK) {
+        DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to start transaction\n"));
+        goto done;
+    }
+    in_transaction = true;
+
+    for (i = 0; i < count; i++) {
+        name = ldb_msg_find_attr_as_string(msgs[i], SYSDB_NAME, NULL);
+        if (!name) {
+            DEBUG(SSSDBG_MINOR_FAILURE, ("A map with no name?\n"));
+            continue;
+        }
+
+        ret = sysdb_set_autofsmap_attr(sysdb, name, sys_attrs, SYSDB_MOD_REP);
+        if (ret != EOK) {
+            DEBUG(SSSDBG_MINOR_FAILURE, ("Could not expire map %s\n", name));
+            continue;
+        }
+    }
+
+    ret = sysdb_transaction_commit(sysdb);
+    if (ret != EOK) {
+        DEBUG(SSSDBG_OP_FAILURE, ("Could not commit transaction\n"));
+        goto done;
+    }
+    in_transaction = false;
+
+    ret = EOK;
+done:
+    if (in_transaction) {
+        sret = sysdb_transaction_cancel(sysdb);
+        if (sret != EOK) {
+            DEBUG(SSSDBG_OP_FAILURE, ("Could not cancel transaction\n"));
+        }
+    }
+    talloc_free(tmp_ctx);
+    return ret;
+}
diff --git a/src/db/sysdb_autofs.h b/src/db/sysdb_autofs.h
index c4b5253ab4e5be9c600d80a69c54bed2958b3a2d..8c8d0f560ff5aa40cb8a7e5513dc36d1c09cd896 100644
--- a/src/db/sysdb_autofs.h
+++ b/src/db/sysdb_autofs.h
@@ -78,4 +78,7 @@ sysdb_set_autofsmap_attr(struct sysdb_ctx *sysdb,
                          struct sysdb_attrs *attrs,
                          int mod_op);
 
+errno_t
+sysdb_invalidate_autofs_maps(struct sysdb_ctx *sysdb);
+
 #endif /* _SYSDB_AUTOFS_H_ */
-- 
1.8.0.2

-------------- next part --------------
>From 3f6f20e19e11b15c69c1f4a7d7a42bf94adc7c7b Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek at redhat.com>
Date: Sat, 15 Dec 2012 13:20:30 +0100
Subject: [PATCH 3/7] DP: invalidate all cached maps if a request for
 auto.master comes in

If the Data Provider receives a request for the auto.master map, it
passes on a flag to let the actual provider let know he should
invalidate the existing maps
---
 src/providers/data_provider_be.c | 7 +++++++
 src/providers/dp_backend.h       | 1 +
 src/providers/ldap/sdap_autofs.c | 8 ++++++++
 3 files changed, 16 insertions(+)

diff --git a/src/providers/data_provider_be.c b/src/providers/data_provider_be.c
index da319ffa607db804d5a193f4eb64f2a184fcc1ab..5208b48cbc4a15a3f8207a70986af3fd360ec581 100644
--- a/src/providers/data_provider_be.c
+++ b/src/providers/data_provider_be.c
@@ -1491,6 +1491,13 @@ static int be_autofs_handler(DBusMessage *message, struct sbus_connection *conn)
         goto done;
     }
 
+    /* If a request for auto.master comes in, the automounter deamon
+     * has been reloaded. Expire all autofs maps to force reload
+     */
+    if (strcmp(be_autofs_req->mapname, "auto.master") == 0) {
+        be_autofs_req->invalidate = true;
+    }
+
     be_req->req_data = be_autofs_req;
 
     if (!be_cli->bectx->bet_info[BET_AUTOFS].bet_ops) {
diff --git a/src/providers/dp_backend.h b/src/providers/dp_backend.h
index 357d58910d19dd859b779d6ef60bc978b839b9b2..58a9b7490df8aab06a2a15f8c0fed9ac5ed33600 100644
--- a/src/providers/dp_backend.h
+++ b/src/providers/dp_backend.h
@@ -169,6 +169,7 @@ struct be_sudo_req {
 
 struct be_autofs_req {
     char *mapname;
+    bool invalidate;
 };
 
 struct be_subdom_req {
diff --git a/src/providers/ldap/sdap_autofs.c b/src/providers/ldap/sdap_autofs.c
index 5e3e3320cea71166b927d7d203f327068af88a6e..7e6f3ecf7382bcbd7fb66d911c69154ccfa572fe 100644
--- a/src/providers/ldap/sdap_autofs.c
+++ b/src/providers/ldap/sdap_autofs.c
@@ -97,6 +97,14 @@ void sdap_autofs_handler(struct be_req *be_req)
     DEBUG(SSSDBG_FUNC_DATA, ("Requested refresh for: %s\n",
           autofs_req->mapname ? autofs_req->mapname : "<ALL>\n"));
 
+    if (autofs_req->invalidate) {
+        ret = sysdb_invalidate_autofs_maps(id_ctx->be->sysdb);
+        if (ret != EOK) {
+            DEBUG(SSSDBG_MINOR_FAILURE, ("Could not invalidate autofs maps, "
+                  "backend might return stale entries\n"));
+        }
+    }
+
     req = sdap_autofs_get_map_send(be_req, be_req->be_ctx->ev,
                                    id_ctx, autofs_req->mapname);
     if (!req) {
-- 
1.8.0.2

-------------- next part --------------
>From 86d20fa59a1b8a6c50bfd7284d1004188c2c3666 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek at redhat.com>
Date: Sat, 15 Dec 2012 13:23:09 +0100
Subject: [PATCH 4/7] AUTOFS: allow removing entries from hash table

There is a timed desctructor in the autofs responder that, when the
entry timeout passes, removes the autofs map from the hash table while
the map is freed. This patch adds a hash delete callback so that if the
map is removed from the hash table with hash_delete, its hash table
pointer will be invalidated. Later, when the entry is being freed, the
destructor won't attempt to remove it from the hash table.
---
 src/responder/autofs/autofs_private.h |  3 +++
 src/responder/autofs/autofssrv.c      |  3 ++-
 src/responder/autofs/autofssrv_cmd.c  | 27 +++++++++++++++++++++++++++
 3 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/src/responder/autofs/autofs_private.h b/src/responder/autofs/autofs_private.h
index bb0c618961f60d6989c8f1f5986f0e2213c76bfa..a2af36e40115c02301594bca12c45411513b2174 100644
--- a/src/responder/autofs/autofs_private.h
+++ b/src/responder/autofs/autofs_private.h
@@ -76,6 +76,9 @@ struct autofs_map_ctx {
 
 struct sss_cmd_table *get_autofs_cmds(void);
 
+void autofs_map_hash_delete_cb(hash_entry_t *item,
+                               hash_destroy_enum deltype, void *pvt);
+
 enum sss_dp_autofs_type {
     SSS_DP_AUTOFS
 };
diff --git a/src/responder/autofs/autofssrv.c b/src/responder/autofs/autofssrv.c
index 86a816a34ce90b409f4f96282673d2bb7e782928..d7c10d6c91c3ea7e781eeb6f1db18035a255f95a 100644
--- a/src/responder/autofs/autofssrv.c
+++ b/src/responder/autofs/autofssrv.c
@@ -158,7 +158,8 @@ autofs_process_init(TALLOC_CTX *mem_ctx,
     }
 
     /* Create the lookup table for setautomntent results */
-    hret = sss_hash_create(autofs_ctx, 10, &autofs_ctx->maps);
+    hret = sss_hash_create_ex(autofs_ctx, 10, &autofs_ctx->maps, 0, 0, 0, 0,
+                              autofs_map_hash_delete_cb, NULL);
     if (hret != HASH_SUCCESS) {
         DEBUG(SSSDBG_CRIT_FAILURE,
               ("Unable to initialize automount maps hash table\n"));
diff --git a/src/responder/autofs/autofssrv_cmd.c b/src/responder/autofs/autofssrv_cmd.c
index 3af4a84685f5f86daaf3e6159cef9c671fc00c39..0cfdbec59c8adcd5bb0c4727876a16e0bef8a026 100644
--- a/src/responder/autofs/autofssrv_cmd.c
+++ b/src/responder/autofs/autofssrv_cmd.c
@@ -118,6 +118,27 @@ get_autofs_map(struct autofs_ctx *actx,
 
 static int autofs_map_hash_remove (TALLOC_CTX *ctx);
 
+void
+autofs_map_hash_delete_cb(hash_entry_t *item,
+                          hash_destroy_enum deltype, void *pvt)
+{
+    struct autofs_map_ctx *map;
+
+    if (deltype != HASH_ENTRY_DESTROY) {
+        return;
+    }
+
+    map = talloc_get_type(item->value.ptr, struct autofs_map_ctx);
+    if (!map) {
+        DEBUG(SSSDBG_OP_FAILURE, ("Invalid autofs map\n"));
+        return;
+    }
+
+    /* So that the destructor wouldn't attempt to remove the map from hash
+     * table */
+    map->map_table = NULL;
+}
+
 static errno_t
 set_autofs_map(struct autofs_ctx *actx,
                struct autofs_map_ctx *map)
@@ -158,6 +179,12 @@ autofs_map_hash_remove(TALLOC_CTX *ctx)
     struct autofs_map_ctx *map =
             talloc_get_type(ctx, struct autofs_map_ctx);
 
+    if (map->map_table == NULL) {
+        DEBUG(SSSDBG_TRACE_LIBS, ("autofs map [%s] was already removed\n",
+              map->mapname));
+        return 0;
+    }
+
     key.type = HASH_KEY_STRING;
     key.str = map->mapname;
 
-- 
1.8.0.2

-------------- next part --------------
>From 12a4ceeb6d635d2fbc86c4d82627bf8222be8f35 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek at redhat.com>
Date: Sat, 15 Dec 2012 13:22:34 +0100
Subject: [PATCH 5/7] AUTOFS: remove all maps from hash if request for
 auto.master comes in

https://fedorahosted.org/sssd/ticket/1592

When a request for auto.master comes in, we need to remove all the maps
from the lookup hash table. We can't simply delete the maps, because
another request might be processing them, so instead the maps are
removed from the hash table, effectively becoming orphaned. The maps
will get freed when the timed destructor is invoked.
---
 src/responder/autofs/autofs_private.h |  2 ++
 src/responder/autofs/autofssrv_cmd.c  | 60 +++++++++++++++++++++++++++++++++--
 2 files changed, 59 insertions(+), 3 deletions(-)

diff --git a/src/responder/autofs/autofs_private.h b/src/responder/autofs/autofs_private.h
index a2af36e40115c02301594bca12c45411513b2174..58445f35b584b1a42debe97eb67b3bb2af1c417e 100644
--- a/src/responder/autofs/autofs_private.h
+++ b/src/responder/autofs/autofs_private.h
@@ -79,6 +79,8 @@ struct sss_cmd_table *get_autofs_cmds(void);
 void autofs_map_hash_delete_cb(hash_entry_t *item,
                                hash_destroy_enum deltype, void *pvt);
 
+errno_t autofs_orphan_maps(struct autofs_ctx *actx);
+
 enum sss_dp_autofs_type {
     SSS_DP_AUTOFS
 };
diff --git a/src/responder/autofs/autofssrv_cmd.c b/src/responder/autofs/autofssrv_cmd.c
index 0cfdbec59c8adcd5bb0c4727876a16e0bef8a026..b85079d0dde5f4f783922748f4061444d9f6c217 100644
--- a/src/responder/autofs/autofssrv_cmd.c
+++ b/src/responder/autofs/autofssrv_cmd.c
@@ -90,6 +90,34 @@ autofs_setent_notify(struct autofs_map_ctx *map_ctx, errno_t ret)
     setent_notify(&map_ctx->reqs, ret);
 }
 
+errno_t
+autofs_orphan_maps(struct autofs_ctx *actx)
+{
+    int hret;
+    unsigned long mcount;
+    unsigned long i;
+    hash_key_t *maps;
+
+    if (!actx || !actx->maps) {
+        return EINVAL;
+    }
+
+    hret = hash_keys(actx->maps, &mcount, &maps);
+    if (hret != HASH_SUCCESS) {
+        return EIO;
+    }
+
+    for (i = 0; i < mcount; i++) {
+        hret = hash_delete(actx->maps, &maps[i]);
+        if (hret != HASH_SUCCESS) {
+            DEBUG(SSSDBG_MINOR_FAILURE, ("Could not delete key from hash\n"));
+            continue;
+        }
+    }
+
+    return EOK;
+}
+
 static errno_t
 get_autofs_map(struct autofs_ctx *actx,
                char *mapname,
@@ -369,6 +397,11 @@ set_autofs_map_lifetime(uint32_t lifetime,
     }
 }
 
+static errno_t
+setautomntent_get_autofs_map(struct autofs_ctx *actx,
+                             char *mapname,
+                             struct autofs_map_ctx **map);
+
 static struct tevent_req *
 setautomntent_send(TALLOC_CTX *mem_ctx,
                    const char *rawname,
@@ -442,7 +475,7 @@ setautomntent_send(TALLOC_CTX *mem_ctx,
     /* Is the result context already available?
      * Check for existing lookups for this map
      */
-    ret = get_autofs_map(actx, state->mapname, &state->map);
+    ret = setautomntent_get_autofs_map(actx, state->mapname, &state->map);
     if (ret == EOK) {
         /* Another process already requested this map
          * Check whether it's ready for processing.
@@ -559,6 +592,25 @@ fail:
 }
 
 static errno_t
+setautomntent_get_autofs_map(struct autofs_ctx *actx,
+                             char *mapname,
+                             struct autofs_map_ctx **map)
+{
+    errno_t ret;
+
+    if (strcmp(mapname, "auto.master") == 0) {
+        /* Iterate over the hash and remove all maps */
+        ret = autofs_orphan_maps(actx);
+        if (ret != EOK) {
+            DEBUG(SSSDBG_MINOR_FAILURE, ("Could not remove existing maps from hash\n"));
+        }
+        return ENOENT;
+    }
+
+    return get_autofs_map(actx, mapname, map);
+}
+
+static errno_t
 lookup_automntmap_update_cache(struct setautomntent_lookup_ctx *lookup_ctx);
 
 static errno_t
@@ -718,8 +770,10 @@ lookup_automntmap_update_cache(struct setautomntent_lookup_ctx *lookup_ctx)
     struct dp_callback_ctx *cb_ctx = NULL;
 
     if (dctx->map != NULL) {
-        cache_expire = ldb_msg_find_attr_as_uint64(dctx->map,
-                                                   SYSDB_CACHE_EXPIRE, 0);
+        if (strcmp(lookup_ctx->mapname, "auto.master") != 0) {
+            cache_expire = ldb_msg_find_attr_as_uint64(dctx->map,
+                                                       SYSDB_CACHE_EXPIRE, 0);
+        }
 
         /* if we have any reply let's check cache validity */
         ret = sss_cmd_check_cache(dctx->map, 0, cache_expire);
-- 
1.8.0.2

-------------- next part --------------
>From 2252007def04173f28a400661445f4c0c962590f Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek at redhat.com>
Date: Sat, 15 Dec 2012 16:24:25 +0100
Subject: [PATCH 6/7] RESPONDERS: Create a common file with service names and
 versions

The monitor sends calls different sbus methods to different responders.
Instead of including headers of the particular responders directly in
monitor, which breaks layering a little, create a common header file
that will be included from src/responder/common/
---
 src/monitor/monitor.c                 |  2 +-
 src/responder/autofs/autofs_private.h |  3 +--
 src/responder/common/responder_sbus.h | 45 +++++++++++++++++++++++++++++++++++
 src/responder/nss/nsssrv.c            |  1 +
 src/responder/nss/nsssrv.h            |  3 ---
 src/responder/pac/pacsrv.h            |  4 +---
 src/responder/pam/pamsrv.c            |  4 +---
 src/responder/ssh/sshsrv.c            |  1 +
 src/responder/ssh/sshsrv_private.h    |  3 ---
 src/responder/sudo/sudosrv.c          |  1 +
 src/responder/sudo/sudosrv_private.h  |  2 --
 11 files changed, 52 insertions(+), 17 deletions(-)
 create mode 100644 src/responder/common/responder_sbus.h

diff --git a/src/monitor/monitor.c b/src/monitor/monitor.c
index 69180cd81a8030729941bd004cbf9754782c3b23..cc6f6d55def27a48f1545136763538b8a2db0904 100644
--- a/src/monitor/monitor.c
+++ b/src/monitor/monitor.c
@@ -51,7 +51,7 @@
 #include "dbus/dbus.h"
 #include "sbus/sssd_dbus.h"
 #include "monitor/monitor_interfaces.h"
-#include "responder/nss/nsssrv.h"
+#include "responder/common/responder_sbus.h"
 
 #ifdef USE_KEYRING
 #include <keyutils.h>
diff --git a/src/responder/autofs/autofs_private.h b/src/responder/autofs/autofs_private.h
index 58445f35b584b1a42debe97eb67b3bb2af1c417e..efe1d623fbf7659beac301983a03163dfc86df0b 100644
--- a/src/responder/autofs/autofs_private.h
+++ b/src/responder/autofs/autofs_private.h
@@ -21,8 +21,7 @@
 #ifndef _AUTOFSSRV_PRIVATE_H_
 #define _AUTOFSSRV_PRIVATE_H_
 
-#define SSS_AUTOFS_SBUS_SERVICE_VERSION 0x0001
-#define SSS_AUTOFS_SBUS_SERVICE_NAME    "autofs"
+#include "responder/common/responder_sbus.h"
 
 #define SSS_AUTOFS_PROTO_VERSION        0x001
 
diff --git a/src/responder/common/responder_sbus.h b/src/responder/common/responder_sbus.h
new file mode 100644
index 0000000000000000000000000000000000000000..82bbcd9b6de1d785828ba0af0b5e93551ca2b482
--- /dev/null
+++ b/src/responder/common/responder_sbus.h
@@ -0,0 +1,45 @@
+/*
+   SSSD
+
+   SSS Client Responder, common header file
+
+   Copyright (C) Red Hat, 2012
+
+   This program 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; either version 3 of the License, or
+   (at your option) any later version.
+
+   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 <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __SSS_RESPONDER_SBUS_H__
+#define __SSS_RESPONDER_SBUS_H__
+
+#define NSS_SBUS_SERVICE_NAME "nss"
+#define NSS_SBUS_SERVICE_VERSION 0x0001
+
+#define SSS_PAM_SBUS_SERVICE_NAME "pam"
+#define SSS_PAM_SBUS_SERVICE_VERSION 0x0001
+
+#define SSS_SUDO_SBUS_SERVICE_NAME "sudo"
+#define SSS_SUDO_SBUS_SERVICE_VERSION 0x0001
+
+#define SSS_AUTOFS_SBUS_SERVICE_NAME    "autofs"
+#define SSS_AUTOFS_SBUS_SERVICE_VERSION 0x0001
+
+#define SSS_SSH_SBUS_SERVICE_NAME    "ssh"
+#define SSS_SSH_SBUS_SERVICE_VERSION 0x0001
+
+#define PAC_SBUS_SERVICE_NAME "pac"
+#define PAC_SBUS_SERVICE_VERSION 0x0001
+
+#endif /* __SSS_RESPONDER_SBUS_H__ */
+
+
diff --git a/src/responder/nss/nsssrv.c b/src/responder/nss/nsssrv.c
index f5cfc85b4861489cd44a1367dc9b26111ff9841c..083e91d7f69d758fcecc99f2fcaac613cff41c3f 100644
--- a/src/responder/nss/nsssrv.c
+++ b/src/responder/nss/nsssrv.c
@@ -42,6 +42,7 @@
 #include "sbus/sssd_dbus.h"
 #include "responder/common/responder_packet.h"
 #include "responder/common/responder.h"
+#include "responder/common/responder_sbus.h"
 #include "providers/data_provider.h"
 #include "monitor/monitor_interfaces.h"
 #include "sbus/sbus_client.h"
diff --git a/src/responder/nss/nsssrv.h b/src/responder/nss/nsssrv.h
index a8b2c3c9766730c25a0c847df9845af1146ae60f..de15f53ec707f229ce4e2fe85af7c673e75e3835 100644
--- a/src/responder/nss/nsssrv.h
+++ b/src/responder/nss/nsssrv.h
@@ -33,9 +33,6 @@
 #include "responder/common/responder_packet.h"
 #include "responder/common/responder.h"
 
-#define NSS_SBUS_SERVICE_VERSION 0x0001
-#define NSS_SBUS_SERVICE_NAME "nss"
-
 #define NSS_PACKET_MAX_RECV_SIZE 1024
 
 struct getent_ctx;
diff --git a/src/responder/pac/pacsrv.h b/src/responder/pac/pacsrv.h
index c0a13a3328cf4b7daf71149d61b7fa3000cd7503..8b73d99573b4be80e2ea63f40c2d8e005b46fb64 100644
--- a/src/responder/pac/pacsrv.h
+++ b/src/responder/pac/pacsrv.h
@@ -37,13 +37,11 @@
 #include "sbus/sssd_dbus.h"
 #include "responder/common/responder_packet.h"
 #include "responder/common/responder.h"
+#include "responder/common/responder_sbus.h"
 #include "lib/idmap/sss_idmap.h"
 #include "util/sss_nss.h"
 #include "db/sysdb.h"
 
-#define PAC_SBUS_SERVICE_VERSION 0x0001
-#define PAC_SBUS_SERVICE_NAME "pac"
-
 #define PAC_PACKET_MAX_RECV_SIZE 1024
 
 struct getent_ctx;
diff --git a/src/responder/pam/pamsrv.c b/src/responder/pam/pamsrv.c
index f877c4f0236e18f6e778bd42c7b39832c609e48f..f0c89a9665478867ab2b1c27bf3003d9753cefcb 100644
--- a/src/responder/pam/pamsrv.c
+++ b/src/responder/pam/pamsrv.c
@@ -43,12 +43,10 @@
 #include "sbus/sbus_client.h"
 #include "responder/pam/pamsrv.h"
 #include "responder/common/negcache.h"
+#include "responder/common/responder_sbus.h"
 
 #define DEFAULT_PAM_FD_LIMIT 8192
 
-#define SSS_PAM_SBUS_SERVICE_VERSION 0x0001
-#define SSS_PAM_SBUS_SERVICE_NAME "pam"
-
 struct sbus_method monitor_pam_methods[] = {
     { MON_CLI_METHOD_PING, monitor_common_pong },
     { MON_CLI_METHOD_RES_INIT, monitor_common_res_init },
diff --git a/src/responder/ssh/sshsrv.c b/src/responder/ssh/sshsrv.c
index 32c0f3080836cde827b4f57477d730aebb26ee86..80a558b5244792ff7545d480ef98c06def81d891 100644
--- a/src/responder/ssh/sshsrv.c
+++ b/src/responder/ssh/sshsrv.c
@@ -24,6 +24,7 @@
 #include "confdb/confdb.h"
 #include "monitor/monitor_interfaces.h"
 #include "responder/common/responder.h"
+#include "responder/common/responder_sbus.h"
 #include "responder/ssh/sshsrv_private.h"
 #include "providers/data_provider.h"
 
diff --git a/src/responder/ssh/sshsrv_private.h b/src/responder/ssh/sshsrv_private.h
index 4b13ca1df10289f486a269788a75a3fc5478c7fc..296bd94a2947796198a0559c06d904b389283ade 100644
--- a/src/responder/ssh/sshsrv_private.h
+++ b/src/responder/ssh/sshsrv_private.h
@@ -23,9 +23,6 @@
 
 #include "responder/common/responder.h"
 
-#define SSS_SSH_SBUS_SERVICE_VERSION 0x0001
-#define SSS_SSH_SBUS_SERVICE_NAME    "ssh"
-
 #define SSS_SSH_KNOWN_HOSTS_PATH PUBCONF_PATH"/known_hosts"
 #define SSS_SSH_KNOWN_HOSTS_TEMP_TMPL PUBCONF_PATH"/.known_hosts.XXXXXX"
 
diff --git a/src/responder/sudo/sudosrv.c b/src/responder/sudo/sudosrv.c
index cb89e1f7586816bf52957bba664dde97d3b3f515..cbcbe2132cd5323741b6d9add9c06a239e34680c 100644
--- a/src/responder/sudo/sudosrv.c
+++ b/src/responder/sudo/sudosrv.c
@@ -24,6 +24,7 @@
 #include "confdb/confdb.h"
 #include "monitor/monitor_interfaces.h"
 #include "responder/common/responder.h"
+#include "responder/common/responder_sbus.h"
 #include "responder/sudo/sudosrv_private.h"
 #include "providers/data_provider.h"
 
diff --git a/src/responder/sudo/sudosrv_private.h b/src/responder/sudo/sudosrv_private.h
index c9eae57b8f2d03852dfed7689e9ca18d0b4afe6d..9d3156ca10fd0ce485734de643a42db89cdcfe44 100644
--- a/src/responder/sudo/sudosrv_private.h
+++ b/src/responder/sudo/sudosrv_private.h
@@ -29,8 +29,6 @@
 #include "responder/common/responder.h"
 
 #define SSS_SUDO_ERROR_OK 0
-#define SSS_SUDO_SBUS_SERVICE_VERSION 0x0001
-#define SSS_SUDO_SBUS_SERVICE_NAME "sudo"
 
 enum sss_dp_sudo_type {
     SSS_DP_SUDO_REFRESH_RULES,
-- 
1.8.0.2

-------------- next part --------------
>From 08a4c6288d5139aa5923be4141f2b1f6074628ff Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek at redhat.com>
Date: Sat, 15 Dec 2012 16:50:31 +0100
Subject: [PATCH 7/7] AUTOFS: Clear enum cache if a request comes in from the
 sss_cache

In order for sss_cache to work correctly, we must also signal the autofs
responder to invalidate the hash table requests.
---
 src/monitor/monitor.c            |  8 ++++++++
 src/monitor/monitor_interfaces.h |  1 +
 src/responder/autofs/autofssrv.c | 22 ++++++++++++++++++++++
 3 files changed, 31 insertions(+)

diff --git a/src/monitor/monitor.c b/src/monitor/monitor.c
index cc6f6d55def27a48f1545136763538b8a2db0904..1fa1592a59b249be0d361e5182e315572dac2011 100644
--- a/src/monitor/monitor.c
+++ b/src/monitor/monitor.c
@@ -761,6 +761,10 @@ static int service_signal_clear_memcache(struct mt_svc *svc)
 {
     return service_signal(svc, MON_CLI_METHOD_CLEAR_MEMCACHE);
 }
+static int service_signal_clear_enum_cache(struct mt_svc *svc)
+{
+    return service_signal(svc, MON_CLI_METHOD_CLEAR_ENUM_CACHE);
+}
 
 static int check_domain_ranges(struct sss_domain_info *domains)
 {
@@ -1346,6 +1350,10 @@ static void monitor_hup(struct tevent_context *ev,
         if (!strcmp(NSS_SBUS_SERVICE_NAME, cur_svc->name)) {
             service_signal_clear_memcache(cur_svc);
         }
+
+        if (!strcmp(SSS_AUTOFS_SBUS_SERVICE_NAME, cur_svc->name)) {
+            service_signal_clear_enum_cache(cur_svc);
+        }
     }
 
 }
diff --git a/src/monitor/monitor_interfaces.h b/src/monitor/monitor_interfaces.h
index abe905035e42588b6fabd758d2fb5539a0c91beb..f27c7d00c9b920a463a7ea7ab3281422053ad5a6 100644
--- a/src/monitor/monitor_interfaces.h
+++ b/src/monitor/monitor_interfaces.h
@@ -46,6 +46,7 @@
 #define MON_CLI_METHOD_RESET_OFFLINE "resetOffline" /* Applicable only to providers */
 #define MON_CLI_METHOD_ROTATE "rotateLogs"
 #define MON_CLI_METHOD_CLEAR_MEMCACHE "clearMemcache"
+#define MON_CLI_METHOD_CLEAR_ENUM_CACHE "clearEnumCache"
 
 #define SSSD_SERVICE_PIPE "private/sbus-monitor"
 
diff --git a/src/responder/autofs/autofssrv.c b/src/responder/autofs/autofssrv.c
index d7c10d6c91c3ea7e781eeb6f1db18035a255f95a..93deffd94fc61119e886c84412518db039ea1aad 100644
--- a/src/responder/autofs/autofssrv.c
+++ b/src/responder/autofs/autofssrv.c
@@ -29,10 +29,14 @@
 #include "providers/data_provider.h"
 #include "responder/autofs/autofs_private.h"
 
+static int autofs_clean_hash_table(DBusMessage *message,
+                                   struct sbus_connection *conn);
+
 struct sbus_method monitor_autofs_methods[] = {
     { MON_CLI_METHOD_PING, monitor_common_pong },
     { MON_CLI_METHOD_RES_INIT, monitor_common_res_init },
     { MON_CLI_METHOD_ROTATE, responder_logrotate },
+    { MON_CLI_METHOD_CLEAR_ENUM_CACHE, autofs_clean_hash_table },
     { NULL, NULL }
 };
 
@@ -101,6 +105,24 @@ autofs_dp_reconnect_init(struct sbus_connection *conn,
                                  be_conn->domain->name));
 }
 
+static int autofs_clean_hash_table(DBusMessage *message,
+                                   struct sbus_connection *conn)
+{
+    struct resp_ctx *rctx = talloc_get_type(sbus_conn_get_private_data(conn),
+                                            struct resp_ctx);
+    struct autofs_ctx *actx =
+            talloc_get_type(rctx->pvt_ctx, struct autofs_ctx);
+    errno_t ret;
+
+    ret = autofs_orphan_maps(actx);
+    if (ret != EOK) {
+        DEBUG(SSSDBG_OP_FAILURE, ("Could not invalidate maps\n"));
+        return ret;
+    }
+
+    return monitor_common_pong(message, conn);
+}
+
 static int
 autofs_process_init(TALLOC_CTX *mem_ctx,
                     struct tevent_context *ev,
-- 
1.8.0.2



More information about the sssd-devel mailing list