From 4aa44f7475e03dcc596f6a13fffffda7268074a1 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 8 May 2007 13:44:36 +0000 Subject: r22761: This introduces lib/conn_tdb.c with two main functions: connections_traverse and connections_forall. This centralizes all the routines that did individual tdb_open("connections.tdb") and direct tdb_traverse. Volker (This used to be commit e43e94cda1ad8876b3cb5d1129080b57fa6ec214) --- source3/smbd/connection.c | 29 ++++++++--------------------- source3/smbd/lanman.c | 3 ++- source3/smbd/server.c | 2 +- source3/smbd/statcache.c | 3 +-- 4 files changed, 12 insertions(+), 25 deletions(-) (limited to 'source3/smbd') diff --git a/source3/smbd/connection.c b/source3/smbd/connection.c index e609b90a50..b9cdede69e 100644 --- a/source3/smbd/connection.c +++ b/source3/smbd/connection.c @@ -20,21 +20,6 @@ #include "includes.h" -static TDB_CONTEXT *tdb; - -/**************************************************************************** - Return the connection tdb context (used for message send all). -****************************************************************************/ - -TDB_CONTEXT *conn_tdb_ctx(void) -{ - if (!tdb) - tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_CLEAR_IF_FIRST|TDB_DEFAULT, - O_RDWR | O_CREAT, 0644); - - return tdb; -} - static void make_conn_key(connection_struct *conn, const char *name, TDB_DATA *pkbuf, struct connections_key *pkey) { ZERO_STRUCTP(pkey); @@ -62,6 +47,7 @@ BOOL yield_connection(connection_struct *conn, const char *name) { struct connections_key key; TDB_DATA kbuf; + TDB_CONTEXT *tdb = conn_tdb_ctx(True); if (!tdb) return False; @@ -112,7 +98,7 @@ static int count_fn( TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *u DEBUG(2,("pid %s doesn't exist - deleting connections %d [%s]\n", procid_str_static(&crec.pid), crec.cnum, crec.servicename)); if (tdb_delete(the_tdb, kbuf) != 0) - DEBUG(0,("count_fn: tdb_delete failed with error %s\n", tdb_errorstr(tdb) )); + DEBUG(0,("count_fn: tdb_delete failed with error %s\n", tdb_errorstr(the_tdb) )); return 0; } @@ -139,6 +125,7 @@ static int count_fn( TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *u int count_current_connections( const char *sharename, BOOL clear ) { struct count_stat cs; + TDB_CONTEXT *tdb = conn_tdb_ctx(True); cs.mypid = sys_getpid(); cs.curr_connections = 0; @@ -184,11 +171,10 @@ BOOL claim_connection(connection_struct *conn, const char *name,int max_connecti struct connections_key key; struct connections_data crec; TDB_DATA kbuf, dbuf; + TDB_CONTEXT *tdb = conn_tdb_ctx(True); if (!tdb) { - if ( (tdb =conn_tdb_ctx()) == NULL ) { - return False; - } + return False; } /* @@ -245,6 +231,7 @@ BOOL register_message_flags(BOOL doreg, uint32 msg_flags) struct connections_key key; struct connections_data *pcrec; TDB_DATA kbuf, dbuf; + TDB_CONTEXT *tdb = conn_tdb_ctx(True); if (!tdb) return False; @@ -344,7 +331,7 @@ BOOL store_pipe_opendb( smb_np_struct *p ) data.dptr = (uint8 *)prec; data.dsize = sizeof(struct pipe_open_rec); - if ( (pipe_tdb = conn_tdb_ctx() ) == NULL ) { + if ( (pipe_tdb = conn_tdb_ctx(True) ) == NULL ) { goto done; } @@ -375,7 +362,7 @@ BOOL delete_pipe_opendb( smb_np_struct *p ) goto done; } - if ( (pipe_tdb = conn_tdb_ctx() ) == NULL ) { + if ( (pipe_tdb = conn_tdb_ctx(True) ) == NULL ) { goto done; } diff --git a/source3/smbd/lanman.c b/source3/smbd/lanman.c index 05b1e812b2..b235fd1698 100644 --- a/source3/smbd/lanman.c +++ b/source3/smbd/lanman.c @@ -1894,7 +1894,8 @@ static BOOL api_RNetShareAdd(connection_struct *conn,uint16 vuid, goto error_exit; } else { SAFE_FREE(command); - message_send_all(conn_tdb_ctx(), MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL); + message_send_all(MSG_SMB_CONF_UPDATED, NULL, 0, + False, NULL); } } else { return False; diff --git a/source3/smbd/server.c b/source3/smbd/server.c index 1020ad3aca..b869a1a48e 100644 --- a/source3/smbd/server.c +++ b/source3/smbd/server.c @@ -987,7 +987,7 @@ extern void build_options(BOOL screen); if (!session_init()) exit(1); - if (conn_tdb_ctx() == NULL) + if (!connections_init(True)) exit(1); if (!locking_init(0)) diff --git a/source3/smbd/statcache.c b/source3/smbd/statcache.c index e257483f81..7c2c968d8d 100644 --- a/source3/smbd/statcache.c +++ b/source3/smbd/statcache.c @@ -292,8 +292,7 @@ BOOL stat_cache_lookup(connection_struct *conn, pstring name, pstring dirpath, void send_stat_cache_delete_message(const char *name) { #ifdef DEVELOPER - message_send_all(conn_tdb_ctx(), - MSG_SMB_STAT_CACHE_DELETE, + message_send_all(MSG_SMB_STAT_CACHE_DELETE, name, strlen(name)+1, True, -- cgit