[SSSD] [PATCH] Add provider specific default regular expressions

Sumit Bose sbose at redhat.com
Wed Sep 19 19:49:07 UTC 2012


Hi,

this patch add specific default values for the regular expression to
split user names for the AD and IPA provider. In a perfect patch the
ID provider itself would report back what he would like to use as a
regular expression, but all solutions I could think of would require
some bigger changes to the startup process which are not suitable at
this stage of the 1.9 development. So I picked a more direct solution.

bye,
Sumit
-------------- next part --------------
From 6388218c6a4802cb533e777161557c3a48fea41f Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose at redhat.com>
Date: Wed, 19 Sep 2012 21:28:28 +0200
Subject: [PATCH] Add provider specific default regular expressions

Fixes https://fedorahosted.org/sssd/ticket/1524
---
 src/util/usertools.c |   63 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 63 insertions(+), 0 deletions(-)

diff --git a/src/util/usertools.c b/src/util/usertools.c
index ea640fb30a9fd427d1cd90e8873c4e5fff45e403..d84827807518df60c9c1e83c11f527af765cccfb 100644
--- a/src/util/usertools.c
+++ b/src/util/usertools.c
@@ -75,6 +75,58 @@ static int sss_names_ctx_destructor(struct sss_names_ctx *snctx)
     return 0;
 }
 
+#define IPA_AD_DEFAULT_RE "(((?P<domain>[^\\\\]+)\\\\(?P<name>.+$))|" \
+                         "((?P<name>[^@]+)@(?P<domain>.+$))|" \
+                         "(^(?P<name>[^@\\\\]+)$))"
+
+static errno_t get_id_provider_default_re(TALLOC_CTX *mem_ctx,
+                                          struct confdb_ctx *cdb,
+                                          const char *conf_path,
+                                          char **re_pattern)
+{
+    int ret;
+    size_t c;
+    char *id_provider = NULL;
+
+    struct provider_default_re {
+        const char *name;
+        const char *re;
+    } provider_default_re[] = {{"ipa", IPA_AD_DEFAULT_RE},
+                               {"ad", IPA_AD_DEFAULT_RE},
+                               {NULL, NULL}};
+
+    ret = confdb_get_string(cdb, mem_ctx, conf_path, CONFDB_DOMAIN_ID_PROVIDER,
+                            NULL, &id_provider);
+    if (ret != EOK) {
+        DEBUG(SSSDBG_OP_FAILURE, ("Failed to read ID provider " \
+                                  "from conf db.\n"));
+        ret = ret;
+        goto done;
+    }
+
+    if (id_provider == NULL) {
+        *re_pattern = NULL;
+    } else {
+        for (c = 0; provider_default_re[c].name != NULL; c++) {
+            if (strcmp(id_provider, provider_default_re[c].name) == 0) {
+                *re_pattern = talloc_strdup(mem_ctx, provider_default_re[c].re);
+                if (*re_pattern == NULL) {
+                    DEBUG(SSSDBG_OP_FAILURE, ("talloc_strdup failed.\n"));
+                    ret = ENOMEM;
+                    goto done;
+                }
+                break;
+            }
+        }
+    }
+
+    ret = EOK;
+
+done:
+    talloc_free(id_provider);
+    return ret;
+}
+
 int sss_names_init(TALLOC_CTX *mem_ctx, struct confdb_ctx *cdb,
                    const char *domain, struct sss_names_ctx **out)
 {
@@ -113,6 +165,15 @@ int sss_names_init(TALLOC_CTX *mem_ctx, struct confdb_ctx *cdb,
         if (ret != EOK) goto done;
     }
 
+    if (ctx->re_pattern == NULL) {
+        ret = get_id_provider_default_re(ctx, cdb, conf_path, &ctx->re_pattern);
+        if (ret != EOK) {
+            DEBUG(SSSDBG_OP_FAILURE, ("Failed to get provider default regular " \
+                                      "expression for domain [%s].\n", domain));
+            goto done;
+        }
+    }
+
     if (!ctx->re_pattern) {
         ctx->re_pattern = talloc_strdup(ctx,
                                 "(?P<name>[^@]+)@?(?P<domain>[^@]*$)");
@@ -130,6 +191,8 @@ int sss_names_init(TALLOC_CTX *mem_ctx, struct confdb_ctx *cdb,
 #endif
     }
 
+    DEBUG(SSSDBG_TRACE_INTERNAL, ("Using re [%s].\n", ctx->re_pattern));
+
     ret = confdb_get_string(cdb, ctx, conf_path,
                             CONFDB_FULL_NAME_FORMAT, NULL, &ctx->fq_fmt);
     if (ret != EOK) goto done;
-- 
1.7.7.6



More information about the sssd-devel mailing list