>From 88b83b0f8611443f68639f42d78658d455b22b71 Mon Sep 17 00:00:00 2001
From: Pavel Reichl <preichl@redhat.com>
Date: Mon, 21 Jul 2014 08:06:23 +0100
Subject: [PATCH 2/3] UTIL: rename find_subdomain_by_name

The function was named "find_subdomain" yet it could find both main
domain and subdomain.

sed 's/find_subdomain_by_name/find_domain_by_name/' -i `find . -name "*.[ch]"`
---
 src/providers/ad/ad_access.c          |  4 +--
 src/providers/ad/ad_id.c              |  2 +-
 src/providers/ad/ad_subdomains.c      |  4 +--
 src/providers/data_provider_be.c      |  2 +-
 src/providers/ipa/ipa_access.c        |  2 +-
 src/providers/ipa/ipa_hbac_common.c   |  4 +--
 src/providers/ipa/ipa_idmap.c         |  6 ++---
 src/providers/ipa/ipa_selinux.c       |  4 +--
 src/providers/ipa/ipa_subdomains.c    |  2 +-
 src/providers/ipa/ipa_subdomains_id.c | 10 ++++----
 src/providers/krb5/krb5_utils.c       |  4 +--
 src/providers/ldap/ldap_access.c      |  2 +-
 src/tests/cmocka/test_utils.c         | 46 +++++++++++++++++------------------
 src/util/domain_info_utils.c          |  8 +++---
 src/util/usertools.c                  |  2 +-
 src/util/util.h                       |  6 ++---
 16 files changed, 54 insertions(+), 54 deletions(-)

diff --git a/src/providers/ad/ad_access.c b/src/providers/ad/ad_access.c
index 06ad47417c7ee432b7a565238b6605133f6439d6..74077ec1022c84b6930b423f706c9f1f2131e601 100644
--- a/src/providers/ad/ad_access.c
+++ b/src/providers/ad/ad_access.c
@@ -456,9 +456,9 @@ ad_access_handler(struct be_req *breq)
 
     /* Handle subdomains */
     if (strcasecmp(pd->domain, be_ctx->domain->name) != 0) {
-        domain = find_subdomain_by_name(be_ctx->domain, pd->domain, true);
+        domain = find_domain_by_name(be_ctx->domain, pd->domain, true);
         if (domain == NULL) {
-            DEBUG(SSSDBG_OP_FAILURE, "find_subdomain_by_name failed.\n");
+            DEBUG(SSSDBG_OP_FAILURE, "find_domain_by_name failed.\n");
             be_req_terminate(breq, DP_ERR_FATAL, PAM_SYSTEM_ERR, NULL);
             return;
         }
diff --git a/src/providers/ad/ad_id.c b/src/providers/ad/ad_id.c
index 2e53a685fdc57ee72cffbca836166691fb84dfa0..ddb1083703561ddf99c88762b8f5cf9d28da7e08 100644
--- a/src/providers/ad/ad_id.c
+++ b/src/providers/ad/ad_id.c
@@ -360,7 +360,7 @@ ad_account_info_handler(struct be_req *be_req)
     dom = be_ctx->domain;
     if (strcasecmp(ar->domain, be_ctx->domain->name) != 0) {
         /* Subdomain request, verify subdomain */
-        dom = find_subdomain_by_name(be_ctx->domain, ar->domain, true);
+        dom = find_domain_by_name(be_ctx->domain, ar->domain, true);
     }
 
     if (dom == NULL) {
diff --git a/src/providers/ad/ad_subdomains.c b/src/providers/ad/ad_subdomains.c
index efe4b3fe12353880eb5a60044234f72b8c33de81..f7574d05d236ac89d401daae1f049531b56786cc 100644
--- a/src/providers/ad/ad_subdomains.c
+++ b/src/providers/ad/ad_subdomains.c
@@ -799,8 +799,8 @@ static struct ad_id_ctx *ads_get_root_id_ctx(struct ad_subdomains_req_ctx *ctx)
     }
 
     /* With a subsequent run, the root should already be known */
-    root = find_subdomain_by_name(ctx->sd_ctx->be_ctx->domain,
-                                  name, false);
+    root = find_domain_by_name(ctx->sd_ctx->be_ctx->domain,
+                               name, false);
     if (root == NULL) {
         DEBUG(SSSDBG_OP_FAILURE, "Could not find the root domain\n");
         return NULL;
diff --git a/src/providers/data_provider_be.c b/src/providers/data_provider_be.c
index dbd48b20d5e730df87884c325d312e95d3061de4..f3432492df4150b283dbaa16ec2abfc944a32d0e 100644
--- a/src/providers/data_provider_be.c
+++ b/src/providers/data_provider_be.c
@@ -161,7 +161,7 @@ static errno_t be_req_set_domain(struct be_req *be_req, const char *domain)
 {
     struct sss_domain_info *dom = NULL;
 
-    dom = find_subdomain_by_name(be_req->be_ctx->domain, domain, true);
+    dom = find_domain_by_name(be_req->be_ctx->domain, domain, true);
     if (dom == NULL) {
         DEBUG(SSSDBG_CRIT_FAILURE, "Unknown domain [%s]!\n", domain);
         return ERR_DOMAIN_NOT_FOUND;
diff --git a/src/providers/ipa/ipa_access.c b/src/providers/ipa/ipa_access.c
index bb8e45cf9df6169ac71609d566456ac307914654..ed52132ad51fb89eb428233037e623fbbcad13ca 100644
--- a/src/providers/ipa/ipa_access.c
+++ b/src/providers/ipa/ipa_access.c
@@ -89,7 +89,7 @@ void ipa_access_handler(struct be_req *be_req)
     dom = be_ctx->domain;
     if (strcasecmp(pd->domain, be_ctx->domain->name) != 0) {
         /* Subdomain request, verify subdomain */
-        dom = find_subdomain_by_name(be_ctx->domain, pd->domain, true);
+        dom = find_domain_by_name(be_ctx->domain, pd->domain, true);
     }
 
     /* First, verify that this account isn't locked.
diff --git a/src/providers/ipa/ipa_hbac_common.c b/src/providers/ipa/ipa_hbac_common.c
index 317be9944d4d24e4d9d65299203702e8ceef9250..7d68aa5125682e1b43012ac978d42a0bbd2c5d55 100644
--- a/src/providers/ipa/ipa_hbac_common.c
+++ b/src/providers/ipa/ipa_hbac_common.c
@@ -449,9 +449,9 @@ hbac_ctx_to_eval_request(TALLOC_CTX *mem_ctx,
     /* Get user the user name and groups,
      * take care of subdomain users as well */
     if (strcasecmp(pd->domain, domain->name) != 0) {
-        user_dom = find_subdomain_by_name(domain, pd->domain, true);
+        user_dom = find_domain_by_name(domain, pd->domain, true);
         if (user_dom == NULL) {
-            DEBUG(SSSDBG_OP_FAILURE, "find_subdomain_by_name failed.\n");
+            DEBUG(SSSDBG_OP_FAILURE, "find_domain_by_name failed.\n");
             ret = ENOMEM;
             goto done;
         }
diff --git a/src/providers/ipa/ipa_idmap.c b/src/providers/ipa/ipa_idmap.c
index 7e4f985f32e705b0fd728b232873ed20f4ddf859..4e683108223b2119df35625d4f1b3c01ee7947a7 100644
--- a/src/providers/ipa/ipa_idmap.c
+++ b/src/providers/ipa/ipa_idmap.c
@@ -84,11 +84,11 @@ static errno_t ipa_idmap_check_posix_child(struct sdap_idmap_ctx *idmap_ctx,
         return EINVAL;
     }
 
-    forest_root = find_subdomain_by_name(idmap_ctx->id_ctx->be->domain,
-                                         dom->forest, true);
+    forest_root = find_domain_by_name(idmap_ctx->id_ctx->be->domain,
+                                      dom->forest, true);
     if (forest_root == NULL) {
         DEBUG(SSSDBG_OP_FAILURE,
-              "find_subdomain_by_name failed to find forest root [%s].\n",
+              "find_domain_by_name failed to find forest root [%s].\n",
                dom->forest);
         return ENOENT;
     }
diff --git a/src/providers/ipa/ipa_selinux.c b/src/providers/ipa/ipa_selinux.c
index 927e5456f44c1a60326022aa46fd3f4ec301f9ff..6cb014e43ab42cbd8d7caeb3227db6ae359e8104 100644
--- a/src/providers/ipa/ipa_selinux.c
+++ b/src/providers/ipa/ipa_selinux.c
@@ -119,8 +119,8 @@ void ipa_selinux_handler(struct be_req *be_req)
                                        pd->domain);
             goto fail;
         } else {
-            user_domain = find_subdomain_by_name(subdom_be_ctx->domain,
-                                                 pd->domain, true);
+            user_domain = find_domain_by_name(subdom_be_ctx->domain,
+                                              pd->domain, true);
             if (user_domain == NULL) {
                 DEBUG(SSSDBG_MINOR_FAILURE, "No domain entry found " \
                                              "for [%s].\n", pd->domain);
diff --git a/src/providers/ipa/ipa_subdomains.c b/src/providers/ipa/ipa_subdomains.c
index 7103ba28a1713dc126f834d122a042b455109e00..5245048466548475e48a619be52785bdb12295a0 100644
--- a/src/providers/ipa/ipa_subdomains.c
+++ b/src/providers/ipa/ipa_subdomains.c
@@ -342,7 +342,7 @@ const char *get_flat_name_from_subdomain_name(struct be_ctx *be_ctx,
         return NULL;
     }
 
-    dom = find_subdomain_by_name(ctx->be_ctx->domain, name, true);
+    dom = find_domain_by_name(ctx->be_ctx->domain, name, true);
     if (dom) {
         return dom->flat_name;
     }
diff --git a/src/providers/ipa/ipa_subdomains_id.c b/src/providers/ipa/ipa_subdomains_id.c
index 1c4c315a732aa1e1127c63ca428f54c4621d5b94..113bc6c06f82bc631b3efa92b87a1cadc7f22605 100644
--- a/src/providers/ipa/ipa_subdomains_id.c
+++ b/src/providers/ipa/ipa_subdomains_id.c
@@ -75,10 +75,10 @@ struct tevent_req *ipa_get_subdom_acct_send(TALLOC_CTX *memctx,
         goto fail;
     }
 
-    state->domain = find_subdomain_by_name(state->ctx->be->domain,
-                                           ar->domain, true);
+    state->domain = find_domain_by_name(state->ctx->be->domain,
+                                        ar->domain, true);
     if (state->domain == NULL) {
-        DEBUG(SSSDBG_OP_FAILURE, "find_subdomain_by_name failed.\n");
+        DEBUG(SSSDBG_OP_FAILURE, "find_domain_by_name failed.\n");
         ret = ENOMEM;
         goto fail;
     }
@@ -289,8 +289,8 @@ ipa_get_ad_acct_send(TALLOC_CTX *mem_ctx,
     state->ar = ar;
 
     /* This can only be a subdomain request, verify subdomain */
-    state->user_dom = find_subdomain_by_name(ipa_ctx->sdap_id_ctx->be->domain,
-                                             ar->domain, true);
+    state->user_dom = find_domain_by_name(ipa_ctx->sdap_id_ctx->be->domain,
+                                          ar->domain, true);
     if (state->user_dom == NULL) {
         ret = EINVAL;
         goto fail;
diff --git a/src/providers/krb5/krb5_utils.c b/src/providers/krb5/krb5_utils.c
index 0734310cafcdbc22a43544ee470f954d5f897ef6..0d2e281198390043068e21b412b57de04df6a12b 100644
--- a/src/providers/krb5/krb5_utils.c
+++ b/src/providers/krb5/krb5_utils.c
@@ -1094,9 +1094,9 @@ errno_t get_domain_or_subdomain(struct be_ctx *be_ctx,
 
     if (domain_name != NULL &&
         strcasecmp(domain_name, be_ctx->domain->name) != 0) {
-        *dom = find_subdomain_by_name(be_ctx->domain, domain_name, true);
+        *dom = find_domain_by_name(be_ctx->domain, domain_name, true);
         if (*dom == NULL) {
-            DEBUG(SSSDBG_OP_FAILURE, "find_subdomain_by_name failed.\n");
+            DEBUG(SSSDBG_OP_FAILURE, "find_domain_by_name failed.\n");
             return ENOMEM;
         }
     } else {
diff --git a/src/providers/ldap/ldap_access.c b/src/providers/ldap/ldap_access.c
index 05354d10c5febfa861d24aa974a19ee1db1c5152..1913cd9a92342cc985d5c098f224c4fe8c58d465 100644
--- a/src/providers/ldap/ldap_access.c
+++ b/src/providers/ldap/ldap_access.c
@@ -61,7 +61,7 @@ void sdap_pam_access_handler(struct be_req *breq)
     dom = be_ctx->domain;
     if (strcasecmp(pd->domain, be_ctx->domain->name) != 0) {
         /* Subdomain request, verify subdomain */
-        dom = find_subdomain_by_name(be_ctx->domain, pd->domain, true);
+        dom = find_domain_by_name(be_ctx->domain, pd->domain, true);
     }
 
     req = sdap_access_send(breq, be_ctx->ev, be_ctx,
diff --git a/src/tests/cmocka/test_utils.c b/src/tests/cmocka/test_utils.c
index 59b6e08bacf7a3c185bce08670321f709817c46f..2254c0a7cfb00ff9d028b3e50fa989c401418d9a 100644
--- a/src/tests/cmocka/test_utils.c
+++ b/src/tests/cmocka/test_utils.c
@@ -101,23 +101,23 @@ void teardown_dom_list(void **state)
     assert_true(leak_check_teardown());
 }
 
-void test_find_subdomain_by_name_null(void **state)
+void test_find_domain_by_name_null(void **state)
 {
     struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
                                                       struct dom_list_test_ctx);
     struct sss_domain_info *dom;
 
-    dom = find_subdomain_by_name(NULL, NULL, false);
+    dom = find_domain_by_name(NULL, NULL, false);
     assert_null(dom);
 
-    dom = find_subdomain_by_name(test_ctx->dom_list, NULL, false);
+    dom = find_domain_by_name(test_ctx->dom_list, NULL, false);
     assert_null(dom);
 
-    dom = find_subdomain_by_name(NULL, "test", false);
+    dom = find_domain_by_name(NULL, "test", false);
     assert_null(dom);
 }
 
-void test_find_subdomain_by_name(void **state)
+void test_find_domain_by_name(void **state)
 {
     struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
                                                       struct dom_list_test_ctx);
@@ -137,25 +137,25 @@ void test_find_subdomain_by_name(void **state)
         sid = talloc_asprintf(global_talloc_context, SID_TMPL, c);
         assert_non_null(sid);
 
-        dom = find_subdomain_by_name(test_ctx->dom_list, name, false);
+        dom = find_domain_by_name(test_ctx->dom_list, name, false);
         assert_non_null(dom);
         assert_string_equal(name, dom->name);
         assert_string_equal(flat_name, dom->flat_name);
         assert_string_equal(sid, dom->domain_id);
 
-        dom = find_subdomain_by_name(test_ctx->dom_list, name, true);
+        dom = find_domain_by_name(test_ctx->dom_list, name, true);
         assert_non_null(dom);
         assert_string_equal(name, dom->name);
         assert_string_equal(flat_name, dom->flat_name);
         assert_string_equal(sid, dom->domain_id);
 
-        dom = find_subdomain_by_name(test_ctx->dom_list, flat_name, true);
+        dom = find_domain_by_name(test_ctx->dom_list, flat_name, true);
         assert_non_null(dom);
         assert_string_equal(name, dom->name);
         assert_string_equal(flat_name, dom->flat_name);
         assert_string_equal(sid, dom->domain_id);
 
-        dom = find_subdomain_by_name(test_ctx->dom_list, flat_name, false);
+        dom = find_domain_by_name(test_ctx->dom_list, flat_name, false);
         assert_null(dom);
 
         talloc_free(name);
@@ -164,7 +164,7 @@ void test_find_subdomain_by_name(void **state)
     }
 }
 
-void test_find_subdomain_by_name_missing_flat_name(void **state)
+void test_find_domain_by_name_missing_flat_name(void **state)
 {
     struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
                                                       struct dom_list_test_ctx);
@@ -196,7 +196,7 @@ void test_find_subdomain_by_name_missing_flat_name(void **state)
         sid = talloc_asprintf(global_talloc_context, SID_TMPL, c);
         assert_non_null(sid);
 
-        dom = find_subdomain_by_name(test_ctx->dom_list, name, true);
+        dom = find_domain_by_name(test_ctx->dom_list, name, true);
         assert_non_null(dom);
         assert_string_equal(name, dom->name);
         if (c == mis - 1) {
@@ -206,7 +206,7 @@ void test_find_subdomain_by_name_missing_flat_name(void **state)
         }
         assert_string_equal(sid, dom->domain_id);
 
-        dom = find_subdomain_by_name(test_ctx->dom_list, name, false);
+        dom = find_domain_by_name(test_ctx->dom_list, name, false);
         assert_non_null(dom);
         assert_string_equal(name, dom->name);
         if (c == mis - 1) {
@@ -216,7 +216,7 @@ void test_find_subdomain_by_name_missing_flat_name(void **state)
         }
         assert_string_equal(sid, dom->domain_id);
 
-        dom = find_subdomain_by_name(test_ctx->dom_list, flat_name, true);
+        dom = find_domain_by_name(test_ctx->dom_list, flat_name, true);
         if (c == mis - 1) {
             assert_null(dom);
         } else {
@@ -226,7 +226,7 @@ void test_find_subdomain_by_name_missing_flat_name(void **state)
             assert_string_equal(sid, dom->domain_id);
         }
 
-        dom = find_subdomain_by_name(test_ctx->dom_list, flat_name, false);
+        dom = find_domain_by_name(test_ctx->dom_list, flat_name, false);
         assert_null(dom);
 
         talloc_free(name);
@@ -235,7 +235,7 @@ void test_find_subdomain_by_name_missing_flat_name(void **state)
     }
 }
 
-void test_find_subdomain_by_name_disabled(void **state)
+void test_find_domain_by_name_disabled(void **state)
 {
     struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
                                                       struct dom_list_test_ctx);
@@ -267,7 +267,7 @@ void test_find_subdomain_by_name_disabled(void **state)
         sid = talloc_asprintf(global_talloc_context, SID_TMPL, c);
         assert_non_null(sid);
 
-        dom = find_subdomain_by_name(test_ctx->dom_list, name, true);
+        dom = find_domain_by_name(test_ctx->dom_list, name, true);
         if (c == mis - 1) {
             assert_null(dom);
         } else {
@@ -277,7 +277,7 @@ void test_find_subdomain_by_name_disabled(void **state)
             assert_string_equal(sid, dom->domain_id);
         }
 
-        dom = find_subdomain_by_name(test_ctx->dom_list, name, false);
+        dom = find_domain_by_name(test_ctx->dom_list, name, false);
         if (c == mis - 1) {
             assert_null(dom);
         } else {
@@ -287,7 +287,7 @@ void test_find_subdomain_by_name_disabled(void **state)
             assert_string_equal(sid, dom->domain_id);
         }
 
-        dom = find_subdomain_by_name(test_ctx->dom_list, flat_name, true);
+        dom = find_domain_by_name(test_ctx->dom_list, flat_name, true);
         if (c == mis - 1) {
             assert_null(dom);
         } else {
@@ -297,7 +297,7 @@ void test_find_subdomain_by_name_disabled(void **state)
             assert_string_equal(sid, dom->domain_id);
         }
 
-        dom = find_subdomain_by_name(test_ctx->dom_list, flat_name, false);
+        dom = find_domain_by_name(test_ctx->dom_list, flat_name, false);
         assert_null(dom);
 
         talloc_free(name);
@@ -895,13 +895,13 @@ int main(int argc, const char *argv[])
                                  setup_dom_list, teardown_dom_list),
         unit_test_setup_teardown(test_find_domain_by_sid_disabled,
                                  setup_dom_list, teardown_dom_list),
-        unit_test_setup_teardown(test_find_subdomain_by_name_null,
+        unit_test_setup_teardown(test_find_domain_by_name_null,
                                  setup_dom_list, teardown_dom_list),
-        unit_test_setup_teardown(test_find_subdomain_by_name,
+        unit_test_setup_teardown(test_find_domain_by_name,
                                  setup_dom_list, teardown_dom_list),
-        unit_test_setup_teardown(test_find_subdomain_by_name_missing_flat_name,
+        unit_test_setup_teardown(test_find_domain_by_name_missing_flat_name,
                                  setup_dom_list, teardown_dom_list),
-        unit_test_setup_teardown(test_find_subdomain_by_name_disabled,
+        unit_test_setup_teardown(test_find_domain_by_name_disabled,
                                  setup_dom_list, teardown_dom_list),
 
         unit_test_setup_teardown(test_sss_names_init,
diff --git a/src/util/domain_info_utils.c b/src/util/domain_info_utils.c
index 83f3baa62b45c4c42e5dc3acddb38f8d66491bcf..b449591a54990967a73f68dd7385cb21aead1f72 100644
--- a/src/util/domain_info_utils.c
+++ b/src/util/domain_info_utils.c
@@ -87,9 +87,9 @@ bool subdomain_enumerates(struct sss_domain_info *parent,
     return false;
 }
 
-struct sss_domain_info *find_subdomain_by_name(struct sss_domain_info *domain,
-                                               const char *name,
-                                               bool match_any)
+struct sss_domain_info *find_domain_by_name(struct sss_domain_info *domain,
+                                            const char *name,
+                                            bool match_any)
 {
     struct sss_domain_info *dom = domain;
 
@@ -193,7 +193,7 @@ find_subdomain_by_object_name(struct sss_domain_info *domain,
     if (domainname == NULL) {
         dom = domain;
     } else {
-        dom = find_subdomain_by_name(domain, domainname, true);
+        dom = find_domain_by_name(domain, domainname, true);
     }
 
 done:
diff --git a/src/util/usertools.c b/src/util/usertools.c
index 57945c7f15f49213b37b25828c924bef70966a24..06384b8491b412d12dfb39a4ca8a614925996b0a 100644
--- a/src/util/usertools.c
+++ b/src/util/usertools.c
@@ -399,7 +399,7 @@ static struct sss_domain_info * match_any_domain_or_subdomain_name(
         return dom;
     }
 
-    return find_subdomain_by_name(dom, dmatch, true);
+    return find_domain_by_name(dom, dmatch, true);
 }
 
 int sss_parse_name_for_domains(TALLOC_CTX *memctx,
diff --git a/src/util/util.h b/src/util/util.h
index 3cf1bc0a0190a237f21e179400247d2536cb2aed..ee84735c55c0d23088eb973aa6cc3143bb1e4aa7 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -511,9 +511,9 @@ struct sss_domain_info *get_domains_head(struct sss_domain_info *domain);
 
 struct sss_domain_info *get_next_domain(struct sss_domain_info *domain,
                                         bool descend);
-struct sss_domain_info *find_subdomain_by_name(struct sss_domain_info *domain,
-                                               const char *name,
-                                               bool match_any);
+struct sss_domain_info *find_domain_by_name(struct sss_domain_info *domain,
+                                            const char *name,
+                                            bool match_any);
 struct sss_domain_info *find_domain_by_sid(struct sss_domain_info *domain,
                                            const char *sid);
 
-- 
1.9.3

