s4 dsdb util: samdb_client_site_name use dsdb_domain_count
authorGary Lockyer <gary@catalyst.net.nz>
Wed, 13 Feb 2019 20:18:20 +0000 (09:18 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 14 Feb 2019 04:03:24 +0000 (05:03 +0100)
Replace the call to samdb_search_count with dsdb_domain_count. As this
is the only remaining caller of samdb_search_count, replacing it will
allow the removal of samdb_search_count.

Signed-off-by: Gary Lockyer <gary@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source4/dsdb/common/util.c

index f5496c7d17e2972b914c7be27ac324c7596ee51f..e2ed8405c93a1d775ba56e5f615531292c2327eb 100644 (file)
@@ -1899,7 +1899,7 @@ const char *samdb_client_site_name(struct ldb_context *ldb, TALLOC_CTX *mem_ctx,
        const char *site_name = NULL, *l_subnet_name = NULL;
        const char *allow_list[2] = { NULL, NULL };
        unsigned int i, count;
        const char *site_name = NULL, *l_subnet_name = NULL;
        const char *allow_list[2] = { NULL, NULL };
        unsigned int i, count;
-       int cnt, ret;
+       int ret;
 
        /*
         * if we don't have a client ip e.g. ncalrpc
 
        /*
         * if we don't have a client ip e.g. ncalrpc
@@ -1965,8 +1965,18 @@ const char *samdb_client_site_name(struct ldb_context *ldb, TALLOC_CTX *mem_ctx,
                 * is for sure the same as our server site). If more sites do
                 * exist then we don't know which one to use and set the site
                 * name to "". */
                 * is for sure the same as our server site). If more sites do
                 * exist then we don't know which one to use and set the site
                 * name to "". */
-               cnt = samdb_search_count(ldb, mem_ctx, sites_container_dn,
-                                        "(objectClass=site)");
+               size_t cnt = 0;
+               ret = dsdb_domain_count(
+                       ldb,
+                       &cnt,
+                       sites_container_dn,
+                       NULL,
+                       LDB_SCOPE_SUBTREE,
+                       "(objectClass=site)");
+               if (ret != LDB_SUCCESS) {
+                       site_name = NULL;
+                       goto exit;
+               }
                if (cnt == 1) {
                        site_name = samdb_server_site_name(ldb, mem_ctx);
                } else {
                if (cnt == 1) {
                        site_name = samdb_server_site_name(ldb, mem_ctx);
                } else {
@@ -1979,6 +1989,7 @@ const char *samdb_client_site_name(struct ldb_context *ldb, TALLOC_CTX *mem_ctx,
                *subnet_name = talloc_strdup(mem_ctx, l_subnet_name);
        }
 
                *subnet_name = talloc_strdup(mem_ctx, l_subnet_name);
        }
 
+exit:
        talloc_free(sites_container_dn);
        talloc_free(subnets_dn);
        talloc_free(res);
        talloc_free(sites_container_dn);
        talloc_free(subnets_dn);
        talloc_free(res);