[SSSD] [PATCH] sss_cache: support invalidating services and autofs maps

Jakub Hrozek jhrozek at redhat.com
Thu Apr 12 08:11:56 UTC 2012


On Thu, Apr 12, 2012 at 08:57:12AM +0200, Jan Zelený wrote:
> > On Wed, 2012-04-11 at 09:10 +0200, Jan Zelený wrote:
> > > > I already had the autofs part done from when I wrote the autofs
> > > > support, so adding the services was quite easy.
> > > 
> > > You have a typo in man page (--autofs-map -> --autofs-maps). Also I
> > > wonder if we maybe want finer granularity for services, i.e. not only
> > > filter by name but also by port and protocol. What do you think?
> > 
> > I think it's overkill unless someone asks for it. In the general case,
> > it's not really too harsh to expire all entries (since we're not
> > actually removing them, thus even expired entries will be returned if
> > we're offline).
> 
> Ok, Ack for both patches. Just correct the typo before pushing.
> 
> Thanks
> Jan

attached are patches with the typo fixed
-------------- next part --------------
>From fff71c076d1dddd1fb0de5127a0a3388706274ba Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek at redhat.com>
Date: Thu, 5 Apr 2012 00:20:44 +0200
Subject: [PATCH 1/2] Add sysdb_set_service_attr and sysdb_set_autofsmap_attr

---
 src/db/sysdb_autofs.c   |   28 ++++++++++++++++++++++++++++
 src/db/sysdb_autofs.h   |    6 ++++++
 src/db/sysdb_services.c |   28 ++++++++++++++++++++++++++++
 src/db/sysdb_services.h |    6 ++++++
 4 files changed, 68 insertions(+), 0 deletions(-)

diff --git a/src/db/sysdb_autofs.c b/src/db/sysdb_autofs.c
index e9d918e490714ae24ade6a746ad46c22c08eae3b..eff4e2969f18842fa637851bc729acfd9e7ba796 100644
--- a/src/db/sysdb_autofs.c
+++ b/src/db/sysdb_autofs.c
@@ -396,3 +396,31 @@ done:
     talloc_free(tmp_ctx);
     return ret;
 }
+
+errno_t
+sysdb_set_autofsmap_attr(struct sysdb_ctx *sysdb,
+                         const char *name,
+                         struct sysdb_attrs *attrs,
+                         int mod_op)
+{
+    errno_t ret;
+    struct ldb_dn *dn;
+    TALLOC_CTX *tmp_ctx;
+
+    tmp_ctx = talloc_new(NULL);
+    if (!tmp_ctx) {
+        return ENOMEM;
+    }
+
+    dn = sysdb_autofsmap_dn(tmp_ctx, sysdb, name);
+    if (!dn) {
+        ret = ENOMEM;
+        goto done;
+    }
+
+    ret = sysdb_set_entry_attr(sysdb, dn, attrs, mod_op);
+
+done:
+    talloc_free(tmp_ctx);
+    return ret;
+}
diff --git a/src/db/sysdb_autofs.h b/src/db/sysdb_autofs.h
index e8e5de466dd59d1c47552364fa550671890cf350..b18d505b4bae9db92af5d573edb427984a581791 100644
--- a/src/db/sysdb_autofs.h
+++ b/src/db/sysdb_autofs.h
@@ -85,4 +85,10 @@ sysdb_autofs_map_update_members(struct sysdb_ctx *sysdb,
                                 const char *const *add_entries,
                                 const char *const *del_entries);
 
+errno_t
+sysdb_set_autofsmap_attr(struct sysdb_ctx *sysdb,
+                         const char *name,
+                         struct sysdb_attrs *attrs,
+                         int mod_op);
+
 #endif /* _SYSDB_AUTOFS_H_ */
diff --git a/src/db/sysdb_services.c b/src/db/sysdb_services.c
index 69326309967d9387c99d4f82c46ee52be29e6d57..d443fcd80f0219efbf1ef24bdd0a252eaa93441a 100644
--- a/src/db/sysdb_services.c
+++ b/src/db/sysdb_services.c
@@ -759,3 +759,31 @@ done:
     talloc_free(tmp_ctx);
     return ret;
 }
+
+errno_t
+sysdb_set_service_attr(struct sysdb_ctx *sysdb,
+                       const char *name,
+                       struct sysdb_attrs *attrs,
+                       int mod_op)
+{
+    errno_t ret;
+    struct ldb_dn *dn;
+    TALLOC_CTX *tmp_ctx;
+
+    tmp_ctx = talloc_new(NULL);
+    if (!tmp_ctx) {
+        return ENOMEM;
+    }
+
+    dn = sysdb_svc_dn(sysdb, tmp_ctx, sysdb->domain->name, name);
+    if (!dn) {
+        ret = ENOMEM;
+        goto done;
+    }
+
+    ret = sysdb_set_entry_attr(sysdb, dn, attrs, mod_op);
+
+done:
+    talloc_free(tmp_ctx);
+    return ret;
+}
diff --git a/src/db/sysdb_services.h b/src/db/sysdb_services.h
index 97817d88b7a6b1f15b391109a0bfdae354bd22b7..29d531ed847027ae96f44170ed1f98b7e41693a3 100644
--- a/src/db/sysdb_services.h
+++ b/src/db/sysdb_services.h
@@ -85,4 +85,10 @@ sysdb_svc_delete(struct sysdb_ctx *sysdb,
                  int port,
                  const char *proto);
 
+errno_t
+sysdb_set_service_attr(struct sysdb_ctx *sysdb,
+                       const char *name,
+                       struct sysdb_attrs *attrs,
+                       int mod_op);
+
 #endif /* SYSDB_SERVICES_H_ */
-- 
1.7.7.6

-------------- next part --------------
>From 7602f0279cb19a520903d040f5cb4bcbc81a1304 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek at redhat.com>
Date: Mon, 2 Apr 2012 23:20:20 -0400
Subject: [PATCH 2/2] sss_cache: support invalidating services and autofs maps

https://fedorahosted.org/sssd/ticket/1170
---
 src/man/sss_cache.8.xml |   44 ++++++++++++++++
 src/tools/sss_cache.c   |  127 +++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 162 insertions(+), 9 deletions(-)

diff --git a/src/man/sss_cache.8.xml b/src/man/sss_cache.8.xml
index f30d00d6c808ea2f866c2f2225079027b1e15c6c..7fe599cd8418dac2d506cf817ff62ec57ead82a6 100644
--- a/src/man/sss_cache.8.xml
+++ b/src/man/sss_cache.8.xml
@@ -105,6 +105,50 @@
             </varlistentry>
             <varlistentry>
                 <term>
+                    <option>-s</option>,<option>--service</option>
+                    <replaceable>service</replaceable>
+                </term>
+                <listitem>
+                    <para>
+                        Invalidate specific service.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>
+                    <option>-S</option>,<option>--services</option>
+                </term>
+                <listitem>
+                    <para>
+                        Invalidate all service records. This option overrides
+                        invalidation of specific service if it was also set.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry condition="with_autofs">
+                <term>
+                    <option>-a</option>,<option>--autofs-map</option>
+                    <replaceable>autofs-map</replaceable>
+                </term>
+                <listitem>
+                    <para>
+                        Invalidate specific autofs maps.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry condition="with_autofs">
+                <term>
+                    <option>-A</option>,<option>--autofs-maps</option>
+                </term>
+                <listitem>
+                    <para>
+                        Invalidate all autofs maps. This option overrides
+                        invalidation of specific map if it was also set.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>
                     <option>-d</option>,<option>--domain</option>
                     <replaceable>domain</replaceable>
                 </term>
diff --git a/src/tools/sss_cache.c b/src/tools/sss_cache.c
index a9885b07fbd152dbc5a92db76a84c5ca762bfe00..c673c1da53adbecb59d4521df7a3b4af5baf2c40 100644
--- a/src/tools/sss_cache.c
+++ b/src/tools/sss_cache.c
@@ -28,24 +28,43 @@
 #include "util/util.h"
 #include "tools/sss_sync_ops.h"
 #include "db/sysdb.h"
+#include "db/sysdb_services.h"
+#include "db/sysdb_autofs.h"
 
 #define INVALIDATE_NONE 0
 #define INVALIDATE_USERS 1
 #define INVALIDATE_GROUPS 2
 #define INVALIDATE_NETGROUPS 4
+#define INVALIDATE_SERVICES 8
+#define INVALIDATE_AUTOFSMAPS 16
+
+enum sss_cache_entry {
+    TYPE_USER=0,
+    TYPE_GROUP,
+    TYPE_NETGROUP,
+    TYPE_SERVICE,
+    TYPE_AUTOFSMAP
+};
 
-#define TYPE_USER  0
-#define TYPE_GROUP 1
-#define TYPE_NETGROUP 2
 struct entry_type_t {
     const char *type_string;
     int (* search_fn)(TALLOC_CTX *, struct sysdb_ctx *,
                const char *, const char **, size_t *, struct ldb_message ***);
 };
+
+static errno_t search_services(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb,
+                              const char *sub_filter, const char **attrs,
+                              size_t *msgs_count, struct ldb_message ***msgs);
+static errno_t search_autofsmaps(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb,
+                                 const char *sub_filter, const char **attrs,
+                                 size_t *msgs_count, struct ldb_message ***msgs);
+
 static struct entry_type_t entry_types[] = {
     {"user", sysdb_search_users},
     {"group", sysdb_search_groups},
-    {"netgroup", sysdb_search_netgroups}
+    {"netgroup", sysdb_search_netgroups},
+    {"service", search_services},
+    {"autofsmap", search_autofsmaps}
 };
 
 struct cache_tool_ctx {
@@ -56,6 +75,8 @@ struct cache_tool_ctx {
     char *user_filter;
     char *group_filter;
     char *netgroup_filter;
+    char *service_filter;
+    char *autofs_filter;
 };
 
 errno_t init_domains(struct cache_tool_ctx *ctx, const char *domain);
@@ -63,7 +84,7 @@ errno_t init_context(int argc, const char *argv[], struct cache_tool_ctx **tctx)
 errno_t invalidate_entry(TALLOC_CTX *ctx, struct sysdb_ctx *sysdb,
                          const char *name, int entry_type);
 void invalidate_entries(TALLOC_CTX *ctx, struct sysdb_ctx *sysdb,
-                        int entry_type, const char *filter);
+                        enum sss_cache_entry entry_type, const char *filter);
 
 int main(int argc, const char *argv[])
 {
@@ -89,6 +110,8 @@ int main(int argc, const char *argv[])
         invalidate_entries(tctx, sysdb, TYPE_USER, tctx->user_filter);
         invalidate_entries(tctx, sysdb, TYPE_GROUP, tctx->group_filter);
         invalidate_entries(tctx, sysdb, TYPE_NETGROUP, tctx->netgroup_filter);
+        invalidate_entries(tctx, sysdb, TYPE_SERVICE, tctx->service_filter);
+        invalidate_entries(tctx, sysdb, TYPE_AUTOFSMAP, tctx->autofs_filter);
 
         ret = sysdb_transaction_commit(sysdb);
         if (ret != EOK) {
@@ -102,9 +125,8 @@ done:
     return ret;
 }
 
-
 void invalidate_entries(TALLOC_CTX *ctx, struct sysdb_ctx *sysdb,
-                        int entry_type, const char *filter)
+                        enum sss_cache_entry entry_type, const char *filter)
 {
     const char *attrs[] = {SYSDB_NAME, NULL};
     size_t msg_count;
@@ -168,6 +190,14 @@ errno_t invalidate_entry(TALLOC_CTX *ctx, struct sysdb_ctx *sysdb,
                     ret = sysdb_set_netgroup_attr(sysdb, name,
                             sys_attrs, SYSDB_MOD_REP);
                     break;
+                case TYPE_SERVICE:
+                    ret = sysdb_set_service_attr(sysdb, name,
+                                                 sys_attrs, SYSDB_MOD_REP);
+                    break;
+                case TYPE_AUTOFSMAP:
+                    ret = sysdb_set_autofsmap_attr(sysdb, name,
+                                                   sys_attrs, SYSDB_MOD_REP);
+                    break;
                 default:
                     return EINVAL;
             }
@@ -185,7 +215,8 @@ errno_t invalidate_entry(TALLOC_CTX *ctx, struct sysdb_ctx *sysdb,
     return ret;
 }
 
-errno_t init_domains(struct cache_tool_ctx *ctx, const char *domain) {
+errno_t init_domains(struct cache_tool_ctx *ctx, const char *domain)
+{
     char *confdb_path;
     int ret;
     struct sysdb_ctx *db_ctx = NULL;
@@ -243,6 +274,8 @@ errno_t init_context(int argc, const char *argv[], struct cache_tool_ctx **tctx)
     char *user = NULL;
     char *group = NULL;
     char *netgroup = NULL;
+    char *service = NULL;
+    char *map = NULL;
     char *domain = NULL;
     int debug = SSSDBG_DEFAULT;
     errno_t ret = EOK;
@@ -264,6 +297,16 @@ errno_t init_context(int argc, const char *argv[], struct cache_tool_ctx **tctx)
             _("Invalidate particular netgroup"), NULL },
         { "netgroups", 'N', POPT_ARG_NONE, NULL, 'n',
             _("Invalidate all netgroups"), NULL },
+        { "service", 's', POPT_ARG_STRING, &service, 0,
+            _("Invalidate particular service"), NULL },
+        { "services", 'S', POPT_ARG_NONE, NULL, 's',
+            _("Invalidate all services"), NULL },
+#ifdef BUILD_AUTOFS
+        { "autofs-map", 'a', POPT_ARG_STRING, &map, 0,
+            _("Invalidate particular autofs map"), NULL },
+        { "autofs-maps", 'A', POPT_ARG_NONE, NULL, 'a',
+            _("Invalidate all autofs maps"), NULL },
+#endif /* BUILD_AUTOFS */
         { "domain", 'd', POPT_ARG_STRING, &domain, 0,
             _("Only invalidate entries from a particular domain"), NULL },
         POPT_TABLEEND
@@ -288,6 +331,12 @@ errno_t init_context(int argc, const char *argv[], struct cache_tool_ctx **tctx)
             case 'n':
                 idb |= INVALIDATE_NETGROUPS;
                 break;
+            case 's':
+                idb |= INVALIDATE_SERVICES;
+                break;
+            case 'a':
+                idb |= INVALIDATE_AUTOFSMAPS;
+                break;
         }
     }
     if (ret != -1) {
@@ -323,9 +372,27 @@ errno_t init_context(int argc, const char *argv[], struct cache_tool_ctx **tctx)
         ctx->netgroup_filter = talloc_asprintf(ctx, "(%s=%s)", SYSDB_NAME,
                                                netgroup);
     }
+
+    if (idb & INVALIDATE_SERVICES) {
+        ctx->service_filter = talloc_strdup(ctx, "*");
+    } else if (service) {
+        ctx->service_filter = talloc_strdup(ctx, service);
+    }
+
+    if (idb & INVALIDATE_AUTOFSMAPS) {
+        ctx->autofs_filter = talloc_asprintf(ctx, "(&(objectclass=%s)(%s=*))",
+                                             SYSDB_AUTOFS_MAP_OC, SYSDB_NAME);
+    } else if (map) {
+        ctx->autofs_filter = talloc_asprintf(ctx, "(&(objectclass=%s)(%s=%s))",
+                                             SYSDB_AUTOFS_MAP_OC,
+                                             SYSDB_NAME, map);
+    }
+
     if (((idb & INVALIDATE_USERS || user) && !ctx->user_filter) ||
         ((idb & INVALIDATE_GROUPS || group) && !ctx->group_filter) ||
-        ((idb & INVALIDATE_NETGROUPS || netgroup) && !ctx->netgroup_filter)) {
+        ((idb & INVALIDATE_NETGROUPS || netgroup) && !ctx->netgroup_filter) ||
+        ((idb & INVALIDATE_SERVICES || service) && !ctx->service_filter) ||
+        ((idb & INVALIDATE_AUTOFSMAPS || map) && !ctx->autofs_filter)) {
         DEBUG(1, ("Construction of filters failed\n"));
         ret = ENOMEM;
         goto fini;
@@ -353,3 +420,45 @@ fini:
     }
     return ret;
 }
+
+static errno_t
+search_services(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb,
+                const char *sub_filter, const char **attrs,
+                size_t *msgs_count, struct ldb_message ***msgs)
+{
+    errno_t ret;
+    struct ldb_result *res;
+
+    if (strcmp(sub_filter, "*") == 0) {
+        /* All services */
+        ret = sysdb_enumservent(mem_ctx, sysdb, &res);
+    } else {
+        /* Get service by name */
+        ret = sysdb_getservbyname(mem_ctx, sysdb, sub_filter,
+                                  NULL, &res);
+    }
+
+    if (ret != EOK) {
+        DEBUG(SSSDBG_OP_FAILURE, ("Could not get service from sysdb: "
+              "[%d]: %s\n", ret, strerror(ret)));
+        return ret;
+    }
+
+    *msgs_count = res->count;
+    *msgs = res->msgs;
+    return EOK;
+}
+
+static errno_t
+search_autofsmaps(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb,
+                  const char *sub_filter, const char **attrs,
+                  size_t *msgs_count, struct ldb_message ***msgs)
+{
+#ifdef BUILD_AUTOFS
+    return sysdb_search_custom(mem_ctx, sysdb, sub_filter,
+                               AUTOFS_MAP_SUBDIR, attrs,
+                               msgs_count, msgs);
+#else
+    return ENOSYS;
+#endif  /* BUILD_AUTOFS */
+}
-- 
1.7.7.6



More information about the sssd-devel mailing list