s3: Add SERVERID_UNIQUE_ID_NOT_TO_VERIFY, bug 8760
authorVolker Lendecke <vl@samba.org>
Wed, 15 Feb 2012 10:22:45 +0000 (11:22 +0100)
committerJeremy Allison <jra@samba.org>
Wed, 15 Feb 2012 20:10:22 +0000 (21:10 +0100)
Autobuild-User: Jeremy Allison <jra@samba.org>
Autobuild-Date: Wed Feb 15 21:10:22 CET 2012 on sn-devel-104

source3/include/serverid.h
source3/lib/ctdbd_conn.c
source3/lib/serverid.c
source3/smbd/server.c

index babb21b8f77fe2a8f15a1861acad7211bd2c914c..8fc06a15d88251cadd8881c1b099603980d12532 100644 (file)
@@ -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,10 @@ 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
+ * SERVERID_UNIQUE_ID_NOT_TO_VERIFY
+ */
+uint64_t serverid_get_random_unique_id(void);
+
 #endif
index 12b736deb3938ca2a44cca30b365c877959ba713..9c7300207804fa3648d44c05a942b50d08a69bcb 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "includes.h"
 #include "util_tdb.h"
+#include "serverid.h"
 
 #ifdef CLUSTER_SUPPORT
 
@@ -1228,8 +1229,14 @@ bool ctdb_serverids_exist(struct ctdbd_connection *conn,
                }
 
                for (i=0; i<vnn->num_srvids; i++) {
-                       results[vnn->pid_indexes[i]] =
-                               ((reply->data[i/8] & (1<<(i%8))) != 0);
+                       int idx = vnn->pid_indexes[i];
+
+                       if (pids[i].unique_id ==
+                           SERVERID_UNIQUE_ID_NOT_TO_VERIFY) {
+                               results[idx] = true;
+                               continue;
+                       }
+                       results[idx] = ((reply->data[i/8] & (1<<(i%8))) != 0);
                }
 
                TALLOC_FREE(reply);
index 6a8083a7a2db3f8debdf8e3ff00f7fc02560a493..02de2b4f9cacd23e04a4182d00509172847aa70e 100644 (file)
@@ -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;
@@ -308,6 +312,10 @@ bool serverids_exist(const struct server_id *ids, int num_ids, bool *results)
                struct serverid_key key;
                TDB_DATA tdbkey;
 
+               if (ids[i].unique_id == SERVERID_UNIQUE_ID_NOT_TO_VERIFY) {
+                       results[i] = true;
+                       continue;
+               }
                if (!results[i]) {
                        continue;
                }
@@ -433,3 +441,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(void)
+{
+       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;
+}
index 10d59adbc6c51c25783d8cd5eef4ad95b25b0002..182b3461978471aee304daf886f1af60cbbddec8 100644 (file)
@@ -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
        /*