dfs_server: randomize the server redirect set
authorArvid Requate <requate@univention.de>
Thu, 20 Mar 2014 21:49:08 +0000 (22:49 +0100)
committerJeremy Allison <jra@samba.org>
Fri, 21 Mar 2014 18:20:17 +0000 (19:20 +0100)
comply with [MS-DFSC] section 3.2.1.1

Signed-off-by: Arvid Requate <requate@univention.de>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
dfs_server/dfs_server_ad.c

index 504ab799ba3badf241e9ee52bb608f7836adec61..5e2634fb7a1a9dcedfb4f5f4b443ec2f6b1795f0 100644 (file)
@@ -38,6 +38,24 @@ struct dc_set {
        uint32_t count;
 };
 
        uint32_t count;
 };
 
+static void shuffle_dc_set(struct dc_set *list)
+{
+       uint32_t i;
+
+       srandom(time(NULL));
+
+       for (i = list->count; i > 1; i--) {
+               uint32_t r;
+               const char *tmp;
+
+               r = random() % i;
+
+               tmp = list->names[i - 1];
+               list->names[i - 1] = list->names[r];
+               list->names[r] = tmp;
+       }
+}
+
 /*
   fill a referral type structure
  */
 /*
   fill a referral type structure
  */
@@ -265,6 +283,8 @@ static NTSTATUS get_dcs_insite(TALLOC_CTX *ctx, struct ldb_context *ldb,
                talloc_free(msg);
        }
 
                talloc_free(msg);
        }
 
+       shuffle_dc_set(list);
+
        talloc_free(r);
        return NT_STATUS_OK;
 }
        talloc_free(r);
        return NT_STATUS_OK;
 }