From 81caaa363ac5e00e1fc606377b9117fa96dc33be Mon Sep 17 00:00:00 2001 From: Manoj Dahal Date: Wed, 15 Feb 2012 09:29:15 +0100 Subject: [PATCH] s3: Add SERVERID_UNIQUE_ID_NOT_TO_VERIFY, bug 8760 --- source3/include/serverid.h | 8 ++++++++ source3/lib/serverid.c | 16 ++++++++++++++++ source3/smbd/server.c | 6 ++---- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/source3/include/serverid.h b/source3/include/serverid.h index babb21b..3b63e3b 100644 --- a/source3/include/serverid.h +++ b/source3/include/serverid.h @@ -22,6 +22,9 @@ #include "includes.h" +/** Don't verify this unique id */ +#define SERVERID_UNIQUE_ID_NOT_TO_VERIFY 0xFFFFFFFFFFFFFFFFULL + /* * Register a server with its unique id */ @@ -69,4 +72,9 @@ bool serverid_traverse_read(int (*fn)(const struct server_id *id, */ bool serverid_parent_init(TALLOC_CTX *mem_ctx); +/* + * Get a random unique_id and make sure that it is not UNIQUE_ID_NOT_TO_VERIFY + */ +uint64_t serverid_get_random_unique_id(); + #endif diff --git a/source3/lib/serverid.c b/source3/lib/serverid.c index 6a8083a..5364d17 100644 --- a/source3/lib/serverid.c +++ b/source3/lib/serverid.c @@ -265,6 +265,10 @@ bool serverid_exists(const struct server_id *id) return false; } + if (id->unique_id == SERVERID_UNIQUE_ID_NOT_TO_VERIFY) { + return true; + } + db = serverid_db(); if (db == NULL) { return false; @@ -433,3 +437,15 @@ bool serverid_traverse(int (*fn)(struct db_record *rec, status = dbwrap_traverse(db, serverid_traverse_fn, &state, NULL); return NT_STATUS_IS_OK(status); } + +uint64_t serverid_get_random_unique_id() +{ + uint64_t unique_id = SERVERID_UNIQUE_ID_NOT_TO_VERIFY; + + while (unique_id == SERVERID_UNIQUE_ID_NOT_TO_VERIFY) { + generate_random_buffer((uint8_t *)&unique_id, + sizeof(unique_id)); + } + + return unique_id; +} diff --git a/source3/smbd/server.c b/source3/smbd/server.c index 10d59ad..4f0adfb 100644 --- a/source3/smbd/server.c +++ b/source3/smbd/server.c @@ -481,7 +481,7 @@ static void smbd_accept_connection(struct tevent_context *ev, * Generate a unique id in the parent process so that we use * the global random state in the parent. */ - generate_random_buffer((uint8_t *)&unique_id, sizeof(unique_id)); + unique_id = serverid_get_random_unique_id(); pid = sys_fork(); if (pid == 0) { @@ -973,7 +973,6 @@ extern void build_options(bool screen); struct smbd_parent_context *parent = NULL; TALLOC_CTX *frame; NTSTATUS status; - uint64_t unique_id; struct tevent_context *ev_ctx; struct messaging_context *msg_ctx; struct tevent_signal *se; @@ -1191,8 +1190,7 @@ extern void build_options(bool screen); become_daemon(Fork, no_process_group, log_stdout); } - generate_random_buffer((uint8_t *)&unique_id, sizeof(unique_id)); - set_my_unique_id(unique_id); + set_my_unique_id(serverid_get_random_unique_id()); #if HAVE_SETPGID /* -- 1.7.9