From 09d3155a24ef85b18c2d6612cb0d40b6fa8fc4c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Deschner?= Date: Fri, 6 Sep 2013 18:08:23 +0200 Subject: [PATCH 1/4] s3-sessionid: move sessionid init call to the only function where it is needed. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Guenther Signed-off-by: Günther Deschner --- source3/utils/net_serverid.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source3/utils/net_serverid.c b/source3/utils/net_serverid.c index 01109b9..7d50ab1 100644 --- a/source3/utils/net_serverid.c +++ b/source3/utils/net_serverid.c @@ -113,6 +113,11 @@ static int net_serverid_wipedbs_sessionid(struct db_record *rec, static int net_serverid_wipedbs(struct net_context *c, int argc, const char **argv) { + if (!sessionid_init()) { + d_printf("failed to open sessionid.tdb\n"); + return -1; + }; + connections_forall(net_serverid_wipedbs_conn, NULL); sessionid_traverse(net_serverid_wipedbs_sessionid, NULL); return 0; @@ -150,10 +155,5 @@ int net_serverid(struct net_context *c, int argc, const char **argv) {NULL, NULL, 0, NULL, NULL} }; - if (!sessionid_init()) { - d_printf("failed to open sessionid.tdb\n"); - return -1; - }; - return net_run_function(c, argc, argv, "net serverid", func); } -- 1.8.3.1 From 112e687e4d7db094f4a9f7666fccd8fcd1a577ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Deschner?= Date: Fri, 6 Sep 2013 17:43:50 +0200 Subject: [PATCH 2/4] s3-serverid: restructure serverid initialization. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Guenther Signed-off-by: Günther Deschner --- source3/lib/serverid.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/source3/lib/serverid.c b/source3/lib/serverid.c index 00dd6c4..420633f 100644 --- a/source3/lib/serverid.c +++ b/source3/lib/serverid.c @@ -34,37 +34,41 @@ struct serverid_data { uint32_t msg_flags; }; -bool serverid_parent_init(TALLOC_CTX *mem_ctx) +static struct db_context *db_ptr = NULL; + +static struct db_context *serverid_init(TALLOC_CTX *mem_ctx) { - struct tdb_wrap *db; + db_ptr = db_open(mem_ctx, lock_path("serverid.tdb"), + 0, TDB_DEFAULT|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, + O_RDWR | O_CREAT, + 0644); + return db_ptr; +} +bool serverid_parent_init(TALLOC_CTX *mem_ctx) +{ /* * Open the tdb in the parent process (smbd) so that our * CLEAR_IF_FIRST optimization in tdb_reopen_all can properly * work. */ - db = tdb_wrap_open(mem_ctx, lock_path("serverid.tdb"), - 0, TDB_DEFAULT|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, O_RDWR|O_CREAT, - 0644); - if (db == NULL) { + if (serverid_init(mem_ctx) == NULL) { DEBUG(1, ("could not open serverid.tdb: %s\n", strerror(errno))); return false; } + return true; } static struct db_context *serverid_db(void) { - static struct db_context *db; - - if (db != NULL) { - return db; + if (db_ptr != NULL) { + return db_ptr; } - db = db_open(NULL, lock_path("serverid.tdb"), 0, - TDB_DEFAULT|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, O_RDWR|O_CREAT, 0644); - return db; + + return serverid_init(NULL); } static void serverid_fill_key(const struct server_id *id, -- 1.8.3.1 From 59977abb70090c74e0e59c04db91e363dc925219 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Deschner?= Date: Fri, 6 Sep 2013 17:44:49 +0200 Subject: [PATCH 3/4] s3-serverid: add a readonly variant of the serverid init code. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Guenther Signed-off-by: Günther Deschner --- source3/include/serverid.h | 2 ++ source3/lib/serverid.c | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/source3/include/serverid.h b/source3/include/serverid.h index 435c88b..56b7237 100644 --- a/source3/include/serverid.h +++ b/source3/include/serverid.h @@ -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 diff --git a/source3/lib/serverid.c b/source3/lib/serverid.c index 420633f..9a0deb3 100644 --- a/source3/lib/serverid.c +++ b/source3/lib/serverid.c @@ -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, -- 1.8.3.1 From 1f2591518a5394089200fffb6cbe9b5608e8b66a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Deschner?= Date: Fri, 6 Sep 2013 18:08:45 +0200 Subject: [PATCH 4/4] s3-serverid: call serverid_init_readonly() from commandline tools. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Guenther Signed-off-by: Günther Deschner --- source3/utils/net_serverid.c | 4 ++++ source3/utils/status.c | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/source3/utils/net_serverid.c b/source3/utils/net_serverid.c index 7d50ab1..5e61f11 100644 --- a/source3/utils/net_serverid.c +++ b/source3/utils/net_serverid.c @@ -36,6 +36,10 @@ static int net_serverid_list_fn(const struct server_id *id, static int net_serverid_list(struct net_context *c, int argc, const char **argv) { + if (!serverid_init_readonly(c)) { + d_printf("failed to open serverid.tdb\n"); + return -1; + } d_printf("pid unique_id msg_flags\n"); return serverid_traverse_read(net_serverid_list_fn, NULL) ? 0 : -1; } diff --git a/source3/utils/status.c b/source3/utils/status.c index dc05096..b89a779 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -38,6 +38,7 @@ #include "session.h" #include "locking/proto.h" #include "messages.h" +#include "serverid.h" #define SMB_MAXPIDS 2048 static uid_t Ucrit_uid = 0; /* added by OH */ @@ -476,6 +477,11 @@ static int traverse_sessionid(const char *key, struct sessionid *session, goto done; } + if (!serverid_init_readonly(frame)) { + d_printf("Can't initialise serverid tdb - exiting\n"); + ret = 1; + goto done; + } result = share_mode_forall(print_share_mode, NULL); if (result == 0) { -- 1.8.3.1