From: Arvid Requate Date: Thu, 20 Mar 2014 21:49:08 +0000 (+0100) Subject: dfs_server: randomize the server redirect set X-Git-Tag: ldb-1.1.17~579 X-Git-Url: http://git.samba.org/samba.git/?p=sfrench%2Fsamba-autobuild%2F.git;a=commitdiff_plain;h=cfa6fe8d6974c35cc50aef2f6cdbbbd9b513e483 dfs_server: randomize the server redirect set comply with [MS-DFSC] section 3.2.1.1 Signed-off-by: Arvid Requate Reviewed-by: Andrew Bartlett Reviewed-by: Stefan Metzmacher --- diff --git a/dfs_server/dfs_server_ad.c b/dfs_server/dfs_server_ad.c index 504ab799ba3..5e2634fb7a1 100644 --- a/dfs_server/dfs_server_ad.c +++ b/dfs_server/dfs_server_ad.c @@ -38,6 +38,24 @@ struct dc_set { 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 */ @@ -265,6 +283,8 @@ static NTSTATUS get_dcs_insite(TALLOC_CTX *ctx, struct ldb_context *ldb, talloc_free(msg); } + shuffle_dc_set(list); + talloc_free(r); return NT_STATUS_OK; }