From d690578b31d8e2be8d55be2e320d8bae6805f97a Mon Sep 17 00:00:00 2001
From: Cove Schneider <cove@ilm.com>
Date: Fri, 31 May 2013 23:56:48 -0700
Subject: [PATCH] Add ldap_autofs_map_master_name option

---
 src/config/etc/sssd.api.d/sssd-ipa.conf  |  1 +
 src/config/etc/sssd.api.d/sssd-ldap.conf |  1 +
 src/db/sysdb_autofs.h                    |  5 +++--
 src/man/sssd-ldap.5.xml                  | 13 +++++++++++++
 src/providers/ad/ad_opts.h               |  1 +
 src/providers/data_provider_be.c         |  7 -------
 src/providers/ipa/ipa_opts.h             |  1 +
 src/providers/ldap/ldap_common.c         | 15 +++++++++++++++
 src/providers/ldap/ldap_common.h         |  2 ++
 src/providers/ldap/ldap_opts.h           |  3 +++
 src/providers/ldap/sdap.h                |  1 +
 src/providers/ldap/sdap_autofs.c         | 12 ++++++++++++
 12 files changed, 53 insertions(+), 9 deletions(-)

diff --git a/src/config/etc/sssd.api.d/sssd-ipa.conf b/src/config/etc/sssd.api.d/sssd-ipa.conf
index e6f1bb0a88dd72a5f7bfcb269fa4736e7efd947c..5105a40a629d87a62a21cb6933a758943c1688cc 100644
--- a/src/config/etc/sssd.api.d/sssd-ipa.conf
+++ b/src/config/etc/sssd.api.d/sssd-ipa.conf
@@ -162,6 +162,7 @@ ipa_hostgroup_uuid = str, None, false
 
 [provider/ipa/autofs]
 ipa_automount_location = str, None, false
+ldap_autofs_map_master_name = str, None, false
 ldap_autofs_map_object_class = str, None, false
 ldap_autofs_map_name = str, None, false
 ldap_autofs_entry_object_class = str, None, false
diff --git a/src/config/etc/sssd.api.d/sssd-ldap.conf b/src/config/etc/sssd.api.d/sssd-ldap.conf
index 14e979da3413fe575e83b9a508c6cd8029d2bfba..aa521567f3f657885ba8978fdd118174b0ff9b4f 100644
--- a/src/config/etc/sssd.api.d/sssd-ldap.conf
+++ b/src/config/etc/sssd.api.d/sssd-ldap.conf
@@ -153,6 +153,7 @@ ldap_sudorule_notafter = str, None, false
 ldap_sudorule_order = str, None, false
 
 [provider/ldap/autofs]
+ldap_autofs_map_master_name = str, None, false
 ldap_autofs_map_object_class = str, None, false
 ldap_autofs_map_name = str, None, false
 ldap_autofs_entry_object_class = str, None, false
diff --git a/src/db/sysdb_autofs.h b/src/db/sysdb_autofs.h
index e3528ce4e6bd2c8b594c80828cfb02a9a7ce7923..97edaea03179d89d37073df41ca95cd544a53a29 100644
--- a/src/db/sysdb_autofs.h
+++ b/src/db/sysdb_autofs.h
@@ -28,8 +28,9 @@
 #define AUTOFS_MAP_SUBDIR   "autofsmaps"
 #define AUTOFS_ENTRY_SUBDIR "autofsentries"
 
-#define SYSDB_AUTOFS_MAP_OC     "automountMap"
-#define SYSDB_AUTOFS_MAP_NAME   "automountMapName"
+#define SYSDB_AUTOFS_MAP_MASTER_NAME   "automountMapMasterName"
+#define SYSDB_AUTOFS_MAP_OC            "automountMap"
+#define SYSDB_AUTOFS_MAP_NAME          "automountMapName"
 
 #define SYSDB_AUTOFS_ENTRY_OC     "automount"
 #define SYSDB_AUTOFS_ENTRY_KEY    "automountKey"
diff --git a/src/man/sssd-ldap.5.xml b/src/man/sssd-ldap.5.xml
index 37df5ec1b2e0b150b407f5e3e39db21860055580..b06286742577b84c347701ab0cd56c4e661a44c8 100644
--- a/src/man/sssd-ldap.5.xml
+++ b/src/man/sssd-ldap.5.xml
@@ -2169,6 +2169,19 @@ ldap_access_filter = memberOf=cn=allowedusers,ou=Groups,dc=example,dc=com
         <para>
             <variablelist>
                 <varlistentry>
+                    <term>ldap_autofs_map_master_name (string)</term>
+                    <listitem>
+                        <para>
+                            The name of the automount master map in LDAP.
+                        </para>
+                        <para>
+                            Default: auto.master
+                        </para>
+                    </listitem>
+                </varlistentry>
+            </variablelist>
+            <variablelist>
+                <varlistentry>
                     <term>ldap_autofs_map_object_class (string)</term>
                     <listitem>
                         <para>
diff --git a/src/providers/ad/ad_opts.h b/src/providers/ad/ad_opts.h
index 218614dca82ab1b5a2d54291ead3d9719a4c7e2a..8ce0c475265a8602edea72ecdff18f77f8ecab75 100644
--- a/src/providers/ad/ad_opts.h
+++ b/src/providers/ad/ad_opts.h
@@ -65,6 +65,7 @@ struct dp_option ad_def_ldap_opts[] = {
     { "ldap_sudo_include_netgroups", DP_OPT_BOOL, BOOL_TRUE, BOOL_TRUE },
     { "ldap_sudo_include_regexp", DP_OPT_BOOL, BOOL_TRUE, BOOL_TRUE },
     { "ldap_autofs_search_base", DP_OPT_STRING, NULL_STRING, NULL_STRING },
+    { "ldap_autofs_map_master_name", DP_OPT_STRING, NULL_STRING, NULL_STRING },
     { "ldap_schema", DP_OPT_STRING, { "ad" }, NULL_STRING },
     { "ldap_offline_timeout", DP_OPT_NUMBER, { .number = 60 }, NULL_NUMBER },
     { "ldap_force_upper_case_realm", DP_OPT_BOOL, BOOL_TRUE, BOOL_FALSE },
diff --git a/src/providers/data_provider_be.c b/src/providers/data_provider_be.c
index cd6715680eb4871806cc5148cecd2e118885a105..11e8979c2afe4bbcad19ef77b241843463e02c58 100644
--- a/src/providers/data_provider_be.c
+++ b/src/providers/data_provider_be.c
@@ -1643,13 +1643,6 @@ 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/ipa/ipa_opts.h b/src/providers/ipa/ipa_opts.h
index 4dfa72db430b1d3dfb528cc425c7156baf5ebe47..f8a3bdda0d8b2cc66d40b73dec2aab3b9e65b5d9 100644
--- a/src/providers/ipa/ipa_opts.h
+++ b/src/providers/ipa/ipa_opts.h
@@ -89,6 +89,7 @@ struct dp_option ipa_def_ldap_opts[] = {
     { "ldap_sudo_include_netgroups", DP_OPT_BOOL, BOOL_TRUE, BOOL_TRUE },
     { "ldap_sudo_include_regexp", DP_OPT_BOOL, BOOL_TRUE, BOOL_TRUE },
     { "ldap_autofs_search_base", DP_OPT_STRING, NULL_STRING, NULL_STRING },
+    { "ldap_autofs_map_master_name", DP_OPT_STRING, NULL_STRING, NULL_STRING },
     { "ldap_schema", DP_OPT_STRING, { "ipa_v1" }, NULL_STRING },
     { "ldap_offline_timeout", DP_OPT_NUMBER, { .number = 60 }, NULL_NUMBER },
     { "ldap_force_upper_case_realm", DP_OPT_BOOL, BOOL_TRUE, BOOL_TRUE },
diff --git a/src/providers/ldap/ldap_common.c b/src/providers/ldap/ldap_common.c
index acb24b190157efe06967963ad05014cf9017db7f..0c70d44b78eaa45f27e6ae0ee29c96404ca6df0b 100644
--- a/src/providers/ldap/ldap_common.c
+++ b/src/providers/ldap/ldap_common.c
@@ -407,10 +407,25 @@ int ldap_get_autofs_options(TALLOC_CTX *memctx,
                             struct sdap_options *opts)
 {
     const char *search_base;
+    const char *master_map;
     struct sdap_attr_map *default_entry_map;
     struct sdap_attr_map *default_mobject_map;
     int ret;
 
+    /* automount master map name */
+    master_map = dp_opt_get_string(opts->basic, SDAP_AUTOFS_MAP_MASTER_NAME);
+    if (master_map == NULL) {
+        ret = dp_opt_set_string(opts->basic, SDAP_AUTOFS_MAP_MASTER_NAME,
+            AUTOFS_MAP_MASTER_NAME);
+        if (ret != EOK) {
+            DEBUG(SSSDBG_OP_FAILURE, ("Could not set autofs master map name"
+                  " to default value\n"));
+            return ret;
+        } 
+        master_map = dp_opt_get_string(opts->basic, SDAP_AUTOFS_MAP_MASTER_NAME);
+    }
+    DEBUG(SSSDBG_FUNC_DATA, ("Option ldap_autofs_map_master_name set to %s\n", master_map));
+
     /* search base */
     search_base = dp_opt_get_string(opts->basic, SDAP_SEARCH_BASE);
     if (search_base != NULL) {
diff --git a/src/providers/ldap/ldap_common.h b/src/providers/ldap/ldap_common.h
index 2d17b755808e58831b458bcc86a50eb74b1f1057..ec48db68a457b9cf4e490b649eaefd0573ad8e71 100644
--- a/src/providers/ldap/ldap_common.h
+++ b/src/providers/ldap/ldap_common.h
@@ -39,6 +39,8 @@
 #define LDAP_SSL_URI "ldaps://"
 #define LDAP_LDAPI_URI "ldapi://"
 
+#define AUTOFS_MAP_MASTER_NAME "auto.master"
+
 /* a fd the child process would log into */
 extern int ldap_child_debug_fd;
 
diff --git a/src/providers/ldap/ldap_opts.h b/src/providers/ldap/ldap_opts.h
index 807716c18244ae70759d9b2eff7e40fd3c634fb2..37612c31178dba6ada33b0fc4c73028bf28da467 100644
--- a/src/providers/ldap/ldap_opts.h
+++ b/src/providers/ldap/ldap_opts.h
@@ -56,6 +56,7 @@ struct dp_option default_basic_opts[] = {
     { "ldap_sudo_include_netgroups", DP_OPT_BOOL, BOOL_TRUE, BOOL_TRUE },
     { "ldap_sudo_include_regexp", DP_OPT_BOOL, BOOL_TRUE, BOOL_TRUE },
     { "ldap_autofs_search_base", DP_OPT_STRING, NULL_STRING, NULL_STRING },
+    { "ldap_autofs_map_master_name", DP_OPT_STRING, NULL_STRING, NULL_STRING },
     { "ldap_schema", DP_OPT_STRING, { "rfc2307" }, NULL_STRING },
     { "ldap_offline_timeout", DP_OPT_NUMBER, { .number = 60 }, NULL_NUMBER },
     { "ldap_force_upper_case_realm", DP_OPT_BOOL, BOOL_FALSE, BOOL_FALSE },
@@ -330,12 +331,14 @@ struct sdap_attr_map service_map[] = {
 };
 
 struct sdap_attr_map rfc2307_autofs_mobject_map[] = {
+    { "ldap_autofs_map_master_name", "automountMapMasterName", SYSDB_AUTOFS_MAP_MASTER_NAME, NULL },
     { "ldap_autofs_map_object_class", "automountMap", SYSDB_AUTOFS_MAP_OC, NULL },
     { "ldap_autofs_map_name", "ou", SYSDB_AUTOFS_MAP_NAME, NULL },
     SDAP_ATTR_MAP_TERMINATOR
 };
 
 struct sdap_attr_map rfc2307_autofs_entry_map[] = {
+    { "ldap_autofs_map_master_name", "automountMapMasterName", SYSDB_AUTOFS_MAP_MASTER_NAME, NULL },
     { "ldap_autofs_entry_object_class", "automount", SYSDB_AUTOFS_ENTRY_OC, NULL },
     { "ldap_autofs_entry_key", "cn", SYSDB_AUTOFS_ENTRY_KEY, NULL },
     { "ldap_autofs_entry_value", "automountInformation", SYSDB_AUTOFS_ENTRY_VALUE, NULL },
diff --git a/src/providers/ldap/sdap.h b/src/providers/ldap/sdap.h
index 162250fff76295807cce0779bebdf88577ed755c..7d2d3f534c04f4a21a920286fa17f199277999e9 100644
--- a/src/providers/ldap/sdap.h
+++ b/src/providers/ldap/sdap.h
@@ -164,6 +164,7 @@ enum sdap_basic_opt {
     SDAP_SUDO_INCLUDE_NETGROUPS,
     SDAP_SUDO_INCLUDE_REGEXP,
     SDAP_AUTOFS_SEARCH_BASE,
+    SDAP_AUTOFS_MAP_MASTER_NAME,
     SDAP_SCHEMA,
     SDAP_OFFLINE_TIMEOUT,
     SDAP_FORCE_UPPER_CASE_REALM,
diff --git a/src/providers/ldap/sdap_autofs.c b/src/providers/ldap/sdap_autofs.c
index 0bb211aa3e3ae9ec822e117f8febf8378bb09f79..e4ef7257bd251fdf7cc672c7f96bb67e3bc4ff32 100644
--- a/src/providers/ldap/sdap_autofs.c
+++ b/src/providers/ldap/sdap_autofs.c
@@ -30,6 +30,7 @@
 #include "providers/ldap/sdap.h"
 #include "providers/ldap/sdap_async.h"
 #include "providers/dp_backend.h"
+#include "providers/data_provider.h"
 #include "db/sysdb_autofs.h"
 #include "util/util.h"
 
@@ -82,6 +83,7 @@ void sdap_autofs_handler(struct be_req *be_req)
     struct sdap_id_ctx *id_ctx;
     struct be_autofs_req *autofs_req;
     struct tevent_req *req;
+    const char *master_map;
     int ret = EOK;
 
     DEBUG(SSSDBG_TRACE_INTERNAL, ("sdap autofs handler called\n"));
@@ -98,6 +100,16 @@ 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->mapname != NULL) {
+        master_map = dp_opt_get_string(id_ctx->opts->basic,
+                                       SDAP_AUTOFS_MAP_MASTER_NAME);
+        if (strcmp(master_map, autofs_req->mapname) == 0) {
+            autofs_req->invalidate = true;
+            DEBUG(SSSDBG_FUNC_DATA, ("Refresh of automount master map triggered: %s\n",
+                  autofs_req->mapname));
+        }
+    }
+
     if (autofs_req->invalidate) {
         ret = sysdb_invalidate_autofs_maps(id_ctx->be->domain->sysdb,
                                            id_ctx->be->domain);
-- 
1.7.12.4 (Apple Git-37)

