Replace random() and related calls with generate_random_buffer()
authorRobin McCorkell <rmccorkell@karoshi.org.uk>
Thu, 9 Jul 2015 14:28:05 +0000 (15:28 +0100)
committerJeremy Allison <jra@samba.org>
Fri, 10 Jul 2015 04:33:07 +0000 (06:33 +0200)
Result: better seeded random numbers that are cryptographically secure
(not that it matters in this case)

Please let it be right this time...

Signed-off-by: Robin McCorkell <rmccorkell@karoshi.org.uk>
Reviewed-by: Volker Lendecke <Volker.Lendecke@SerNet.DE>
Reviewed-by: Jeremy Allison <jra@samba.org>
dfs_server/dfs_server_ad.c
source3/smbd/msdfs.c

index 3d93e19..6146632 100644 (file)
@@ -42,13 +42,11 @@ 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;
+               r = generate_random() % i;
 
                tmp = list->names[i - 1];
                list->names[i - 1] = list->names[r];
index a39efce..e895c1f 100644 (file)
@@ -431,13 +431,12 @@ NTSTATUS create_conn_struct_cwd(TALLOC_CTX *ctx,
 
 static void shuffle_strlist(char **list, int count)
 {
-       int i, r;
+       int i;
+       uint32_t r;
        char *tmp;
 
-       srandom(time(NULL));
-
        for (i = count; i > 1; i--) {
-               r = random() % i;
+               r = generate_random() % i;
 
                tmp = list[i-1];
                list[i-1] = list[r];