s3-serverid: add a readonly variant of the serverid init code.
authorGünther Deschner <gd@samba.org>
Fri, 6 Sep 2013 15:44:49 +0000 (17:44 +0200)
committerKarolin Seeger <kseeger@samba.org>
Mon, 9 Sep 2013 08:08:21 +0000 (10:08 +0200)
Guenther

Signed-off-by: Günther Deschner <gd@samba.org>
source3/include/serverid.h
source3/lib/serverid.c

index 435c88b892d6eac30edc82671556a14ab878aac7..56b72374c4eef24a36b8a6c96cd14426a2dad5c3 100644 (file)
@@ -73,4 +73,6 @@ bool serverid_parent_init(TALLOC_CTX *mem_ctx);
  */
 uint64_t serverid_get_random_unique_id(void);
 
+bool serverid_init_readonly(TALLOC_CTX *mem_ctx);
+
 #endif
index 420633ff23e5d786c58bb5b1e3267849058cc75f..9a0deb38edc7cea3112fbcfba2f8c04a6af0a572 100644 (file)
@@ -36,11 +36,12 @@ struct serverid_data {
 
 static struct db_context *db_ptr = NULL;
 
-static struct db_context *serverid_init(TALLOC_CTX *mem_ctx)
+static struct db_context *serverid_init(TALLOC_CTX *mem_ctx,
+                                       bool readonly)
 {
        db_ptr = db_open(mem_ctx, lock_path("serverid.tdb"),
                         0, TDB_DEFAULT|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
-                        O_RDWR | O_CREAT,
+                        readonly ? O_RDONLY : O_RDWR | O_CREAT,
                         0644);
        return db_ptr;
 }
@@ -53,7 +54,18 @@ bool serverid_parent_init(TALLOC_CTX *mem_ctx)
         * work.
         */
 
-       if (serverid_init(mem_ctx) == NULL) {
+       if (serverid_init(mem_ctx, false) == NULL) {
+               DEBUG(1, ("could not open serverid.tdb: %s\n",
+                         strerror(errno)));
+               return false;
+       }
+
+       return true;
+}
+
+bool serverid_init_readonly(TALLOC_CTX *mem_ctx)
+{
+       if (serverid_init(mem_ctx, true) == NULL) {
                DEBUG(1, ("could not open serverid.tdb: %s\n",
                          strerror(errno)));
                return false;
@@ -68,7 +80,7 @@ static struct db_context *serverid_db(void)
                return db_ptr;
        }
 
-       return serverid_init(NULL);
+       return serverid_init(NULL, false);
 }
 
 static void serverid_fill_key(const struct server_id *id,