summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSumit Bose <sbose@redhat.com>2012-09-19 21:28:28 +0200
committerJakub Hrozek <jhrozek@redhat.com>2012-09-20 18:06:47 +0200
commit3dbd8884d37bfc1db4be973737c44135a5fa3910 (patch)
tree95b701fe8314b2b5b8192c0e52c3367b8a405045
parent6ea1223c5efc200e37739e751df9f39887cf8dcd (diff)
downloadsssd-3dbd8884d37bfc1db4be973737c44135a5fa3910.tar.gz
sssd-3dbd8884d37bfc1db4be973737c44135a5fa3910.tar.bz2
sssd-3dbd8884d37bfc1db4be973737c44135a5fa3910.zip
Add provider specific default regular expressions
Fixes https://fedorahosted.org/sssd/ticket/1524
-rw-r--r--src/util/usertools.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/util/usertools.c b/src/util/usertools.c
index ea640fb3..6a5720d7 100644
--- a/src/util/usertools.c
+++ b/src/util/usertools.c
@@ -75,6 +75,57 @@ 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"));
+ 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 +164,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 +190,8 @@ int sss_names_init(TALLOC_CTX *mem_ctx, struct confdb_ctx *cdb,
#endif
}
+ DEBUG(SSSDBG_CONF_SETTINGS, ("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;