s4:dsdb Provide an intelegent fallback if not CN=Subnets is found
authorAndrew Bartlett <abartlet@samba.org>
Fri, 7 May 2010 12:43:36 +0000 (22:43 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Sun, 9 May 2010 11:18:52 +0000 (21:18 +1000)
We may as well fall back rather than return NULL (which callers don't
do useful things with).

Andrew Bartlett

source4/dsdb/common/util.c

index 7064fcf67d44624da82b0a8a6ff17354026e1bc1..40f0a7f6c67f9f9d40563bd00b7ade792a651035 100644 (file)
@@ -1607,7 +1607,7 @@ const char *samdb_client_site_name(struct ldb_context *ldb, TALLOC_CTX *mem_ctx,
        const struct ldb_val *val;
        const char *site_name = NULL, *l_subnet_name = NULL;
        const char *allow_list[2] = { NULL, NULL };
-       unsigned int i;
+       unsigned int i, count;
        int cnt, ret;
 
        /*
@@ -1632,13 +1632,17 @@ const char *samdb_client_site_name(struct ldb_context *ldb, TALLOC_CTX *mem_ctx,
 
        ret = ldb_search(ldb, mem_ctx, &res, subnets_dn, LDB_SCOPE_ONELEVEL,
                         attrs, NULL);
-       if (ret != LDB_SUCCESS) {
+       if (ret == LDB_ERR_NO_SUCH_OBJECT) {
+               count = 0;
+       } else if (ret != LDB_SUCCESS) {
                talloc_free(sites_container_dn);
                talloc_free(subnets_dn);
                return NULL;
+       } else {
+               count = res->count;
        }
 
-       for (i = 0; i < res->count; i++) {
+       for (i = 0; i < count; i++) {
                l_subnet_name = ldb_msg_find_attr_as_string(res->msgs[i], "cn",
                                                            NULL);