ctdb-pmda: CTDB client code does not require ctdb->methods
[sharpe/samba-autobuild/.git] / dfs_server / dfs_server_ad.c
index 5e2634fb7a1a9dcedfb4f5f4b443ec2f6b1795f0..04aa7e00ae3e94866028cba22b625b40e047d411 100644 (file)
@@ -27,6 +27,7 @@
 #include "lib/tsocket/tsocket.h"
 #include "dfs_server/dfs_server_ad.h"
 #include "lib/util/util_net.h"
+#include "libds/common/roles.h"
 
 #define MAX_DFS_RESPONSE 56*1024 /* 56 Kb */
 
@@ -40,20 +41,18 @@ struct dc_set {
 
 static void shuffle_dc_set(struct dc_set *list)
 {
-       uint32_t i;
-
-       srandom(time(NULL));
+       uint32_t i;
 
-       for (i = list->count; i > 1; i--) {
-               uint32_t r;
-               const char *tmp;
+       for (i = list->count; i > 1; i--) {
+               uint32_t r;
+               const char *tmp;
 
-               r = random() % i;
+               r = generate_random() % i;
 
-               tmp = list->names[i - 1];
-               list->names[i - 1] = list->names[r];
-               list->names[r] = tmp;
-       }
+               tmp = list->names[i - 1];
+               list->names[i - 1] = list->names[r];
+               list->names[r] = tmp;
+       }
 }
 
 /*
@@ -366,7 +365,11 @@ static NTSTATUS get_dcs(TALLOC_CTX *ctx, struct ldb_context *ldb,
                /* All of this was to get the DN of the searched_site */
                sitedn = r->msgs[0]->dn;
 
-               set_list = talloc_realloc(subctx, set_list, struct dc_set *, current_pos+1);
+               /*
+                * We will realloc + 2 because we will need one additional place
+                * for element at current_pos + 1 for the NULL element
+                */
+               set_list = talloc_realloc(subctx, set_list, struct dc_set *, current_pos+2);
                if (set_list == NULL) {
                        TALLOC_FREE(subctx);
                        return NT_STATUS_NO_MEMORY;
@@ -380,6 +383,9 @@ static NTSTATUS get_dcs(TALLOC_CTX *ctx, struct ldb_context *ldb,
 
                set_list[current_pos]->names = NULL;
                set_list[current_pos]->count = 0;
+
+               set_list[current_pos+1] = NULL;
+
                status = get_dcs_insite(subctx, ldb, sitedn,
                                        set_list[current_pos], need_fqdn);
                if (!NT_STATUS_IS_OK(status)) {
@@ -468,8 +474,6 @@ static NTSTATUS get_dcs(TALLOC_CTX *ctx, struct ldb_context *ldb,
                        }
                }
        }
-       current_pos++;
-       set_list[current_pos] = NULL;
 
        *pset_list = talloc_move(ctx, &set_list);
        talloc_free(subctx);
@@ -796,6 +800,7 @@ NTSTATUS dfs_server_ad_get_referrals(struct loadparm_context *lp_ctx,
        const char *netbios_name;
        const char *dns_name;
        const char **netbios_aliases;
+       char path_separator;
 
        if (!lpcfg_host_msdfs(lp_ctx)) {
                return NT_STATUS_FS_DRIVER_REQUIRED;
@@ -823,16 +828,18 @@ NTSTATUS dfs_server_ad_get_referrals(struct loadparm_context *lp_ctx,
                return NT_STATUS_NO_MEMORY;
        }
 
-       while(*server_name && *server_name == '\\') {
+       path_separator = (*server_name == '/') ? '/' : '\\';
+
+       while(*server_name && *server_name == path_separator) {
                server_name++;
        }
 
-       dfs_name = strchr(server_name, '\\');
+       dfs_name = strchr_m(server_name, path_separator);
        if (dfs_name != NULL) {
                dfs_name[0] = '\0';
                dfs_name++;
 
-               link_path = strchr(dfs_name, '\\');
+               link_path = strchr_m(dfs_name, path_separator);
                if (link_path != NULL) {
                        link_path[0] = '\0';
                        link_path++;