From 9bc608a5ff89b3b344e83e4d421f6ae1095e630b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
Date: Tue, 10 Sep 2013 14:58:20 +0200
Subject: [PATCH 2/5] sdap: add sdap_domain_get_by_dn()

This function will find sdap domain by comparing object dn
with domain search bases.

Resolves:
https://fedorahosted.org/sssd/ticket/2064
---
 src/providers/ldap/ldap_common.c | 29 +++++++++++++++++++++++++++++
 src/providers/ldap/ldap_common.h |  4 ++++
 2 files changed, 33 insertions(+)

diff --git a/src/providers/ldap/ldap_common.c b/src/providers/ldap/ldap_common.c
index b3a048c1cb7336cec0a5bbfebd3509c56637bed3..3a7751f0321df6c10bcb3ff6effa0a519eaa29ce 100644
--- a/src/providers/ldap/ldap_common.c
+++ b/src/providers/ldap/ldap_common.c
@@ -63,6 +63,35 @@ sdap_domain_get(struct sdap_options *opts,
     return sditer;
 }
 
+struct sdap_domain *
+sdap_domain_get_by_dn(struct sdap_options *opts,
+                      const char *dn)
+{
+    struct sdap_domain *sditer = NULL;
+    TALLOC_CTX *tmp_ctx = NULL;
+
+    tmp_ctx = talloc_new(NULL);
+    if (tmp_ctx == NULL) {
+        return NULL;
+    }
+
+    DLIST_FOR_EACH(sditer, opts->sdom) {
+        if (sss_ldap_dn_in_search_bases(tmp_ctx, dn, sditer->search_bases, NULL) ||
+            sss_ldap_dn_in_search_bases(tmp_ctx, dn, sditer->user_search_bases, NULL) ||
+            sss_ldap_dn_in_search_bases(tmp_ctx, dn, sditer->group_search_bases, NULL) ||
+            sss_ldap_dn_in_search_bases(tmp_ctx, dn, sditer->netgroup_search_bases, NULL) ||
+            sss_ldap_dn_in_search_bases(tmp_ctx, dn, sditer->sudo_search_bases, NULL) ||
+            sss_ldap_dn_in_search_bases(tmp_ctx, dn, sditer->service_search_bases, NULL) ||
+            sss_ldap_dn_in_search_bases(tmp_ctx, dn, sditer->autofs_search_bases, NULL)) {
+            break;
+        }
+    }
+
+    talloc_free(tmp_ctx);
+    return sditer;
+}
+
+
 errno_t
 sdap_domain_add(struct sdap_options *opts,
                 struct sss_domain_info *dom,
diff --git a/src/providers/ldap/ldap_common.h b/src/providers/ldap/ldap_common.h
index 0d565fc63b7e949e628ae5cf079e54c134464e77..d18b236559935cd0d9804b3b83b042537e76f656 100644
--- a/src/providers/ldap/ldap_common.h
+++ b/src/providers/ldap/ldap_common.h
@@ -277,6 +277,10 @@ sdap_domain_remove(struct sdap_options *opts,
 
 struct sdap_domain *sdap_domain_get(struct sdap_options *opts,
                                     struct sss_domain_info *dom);
+
+struct sdap_domain *sdap_domain_get_by_dn(struct sdap_options *opts,
+                                          const char *dn);
+
 errno_t
 sdap_create_search_base(TALLOC_CTX *mem_ctx,
                         const char *unparsed_base,
-- 
1.7.11.7

