diff options
author | Volker Lendecke <vlendec@samba.org> | 2007-05-08 13:44:36 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:21:55 -0500 |
commit | 4aa44f7475e03dcc596f6a13fffffda7268074a1 (patch) | |
tree | 2b0529c892a64a3c2283df64d6ea14433056d04a /source3 | |
parent | dcc2fe7cb61937aa191bf8b5f353d0308a8011a3 (diff) | |
download | samba-4aa44f7475e03dcc596f6a13fffffda7268074a1.tar.gz samba-4aa44f7475e03dcc596f6a13fffffda7268074a1.tar.bz2 samba-4aa44f7475e03dcc596f6a13fffffda7268074a1.zip |
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)
Diffstat (limited to 'source3')
-rw-r--r-- | source3/Makefile.in | 2 | ||||
-rw-r--r-- | source3/lib/conn_tdb.c | 109 | ||||
-rw-r--r-- | source3/lib/messages.c | 4 | ||||
-rw-r--r-- | source3/nmbd/nmbd_processlogon.c | 16 | ||||
-rw-r--r-- | source3/rpc_server/srv_netlog_nt.c | 16 | ||||
-rw-r--r-- | source3/rpc_server/srv_spoolss_nt.c | 4 | ||||
-rw-r--r-- | source3/rpc_server/srv_srvsvc_nt.c | 21 | ||||
-rw-r--r-- | source3/smbd/connection.c | 29 | ||||
-rw-r--r-- | source3/smbd/lanman.c | 3 | ||||
-rw-r--r-- | source3/smbd/server.c | 2 | ||||
-rw-r--r-- | source3/smbd/statcache.c | 3 | ||||
-rw-r--r-- | source3/utils/net_status.c | 72 | ||||
-rw-r--r-- | source3/utils/smbcontrol.c | 40 | ||||
-rw-r--r-- | source3/utils/status.c | 47 | ||||
-rw-r--r-- | source3/web/statuspage.c | 83 |
15 files changed, 210 insertions, 241 deletions
diff --git a/source3/Makefile.in b/source3/Makefile.in index 5ddcaa1401..0346217ff7 100644 --- a/source3/Makefile.in +++ b/source3/Makefile.in @@ -272,7 +272,7 @@ LIB_WITH_PROTO_OBJ = $(VERSION_OBJ) lib/charcnv.o lib/debug.o lib/fault.o \ lib/tallocmsg.o lib/dmallocmsg.o libsmb/smb_signing.o \ lib/md5.o lib/hmacmd5.o lib/arc4.o lib/iconv.o \ nsswitch/wb_client.o $(WBCOMMON_OBJ) \ - lib/pam_errors.o intl/lang_tdb.o \ + lib/pam_errors.o intl/lang_tdb.o lib/conn_tdb.o \ lib/adt_tree.o lib/gencache.o $(TDB_OBJ) \ lib/module.o lib/events.o lib/ldap_escape.o @CHARSET_STATIC@ \ lib/secdesc.o lib/util_seaccess.o lib/secace.o lib/secacl.o \ diff --git a/source3/lib/conn_tdb.c b/source3/lib/conn_tdb.c new file mode 100644 index 0000000000..e6f491bbfb --- /dev/null +++ b/source3/lib/conn_tdb.c @@ -0,0 +1,109 @@ +/* + Unix SMB/CIFS implementation. + Low-level connections.tdb access functions + Copyright (C) Volker Lendecke 2007 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +TDB_CONTEXT *conn_tdb_ctx(BOOL rw) +{ + static TDB_CONTEXT *tdb; + + if (tdb != NULL) { + return tdb; + } + + if (rw) { + tdb = tdb_open_log(lock_path("connections.tdb"), 0, + TDB_CLEAR_IF_FIRST|TDB_DEFAULT, + O_RDWR | O_CREAT, 0644); + } + else { + tdb = tdb_open_log(lock_path("connections.tdb"), 0, + TDB_DEFAULT, O_RDONLY, 0); + } + + if (tdb == NULL) { + DEBUG(0, ("Could not open connections.tdb: %s\n", + strerror(errno))); + } + + return tdb; +} + +struct conn_traverse_state { + int (*fn)(TDB_CONTEXT *tdb, + const struct connections_key *key, + const struct connections_data *data, + void *private_data); + void *private_data; +}; + +static int conn_traverse_fn(TDB_CONTEXT *tdb, TDB_DATA key, + TDB_DATA data, void *private_data) +{ + struct conn_traverse_state *state = + (struct conn_traverse_state *)private_data; + + if ((key.dsize != sizeof(struct connections_key)) + || (data.dsize != sizeof(struct connections_data))) { + return 0; + } + + return state->fn( + tdb, (const struct connections_key *)key.dptr, + (const struct connections_data *)data.dptr, + state->private_data); +} + +int connections_traverse(int (*fn)(TDB_CONTEXT *tdb, TDB_DATA key, + TDB_DATA data, void *private_data), + void *private_data) +{ + TDB_CONTEXT *tdb = conn_tdb_ctx(True); + + if (tdb == NULL) { + DEBUG(5, ("Could not open connections.tdb r/w, trying r/o\n")); + tdb = conn_tdb_ctx(False); + } + + if (tdb == NULL) { + return -1; + } + + return tdb_traverse(tdb, fn, private_data); +} + +int connections_forall(int (*fn)(TDB_CONTEXT *tdb, + const struct connections_key *key, + const struct connections_data *data, + void *private_data), + void *private_data) +{ + struct conn_traverse_state state; + + state.fn = fn; + state.private_data = private_data; + + return connections_traverse(conn_traverse_fn, (void *)&state); +} + +BOOL connections_init(BOOL rw) +{ + return (conn_tdb_ctx(rw) != NULL); +} diff --git a/source3/lib/messages.c b/source3/lib/messages.c index 6ecb89571b..10bf5dfcf7 100644 --- a/source3/lib/messages.c +++ b/source3/lib/messages.c @@ -665,7 +665,7 @@ static int traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DATA dbuf, void * * @retval True for success. **/ -BOOL message_send_all(TDB_CONTEXT *conn_tdb, int msg_type, +BOOL message_send_all(int msg_type, const void *buf, size_t len, BOOL duplicates_allowed, int *n_sent) @@ -691,7 +691,7 @@ BOOL message_send_all(TDB_CONTEXT *conn_tdb, int msg_type, msg_all.duplicates = duplicates_allowed; msg_all.n_sent = 0; - tdb_traverse(conn_tdb, traverse_fn, &msg_all); + connections_traverse(traverse_fn, &msg_all); if (n_sent) *n_sent = msg_all.n_sent; return True; diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index ee7d732ae4..15be7f59c0 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -38,24 +38,10 @@ Send a message to smbd to do a sam delta sync static void send_repl_message(uint32 low_serial) { - TDB_CONTEXT *tdb; - - tdb = tdb_open_log(lock_path("connections.tdb"), 0, - TDB_DEFAULT, O_RDONLY, 0); - - if (!tdb) { - DEBUG(3, ("send_repl_message(): failed to open connections " - "database\n")); - return; - } - DEBUG(3, ("sending replication message, serial = 0x%04x\n", low_serial)); - - message_send_all(tdb, MSG_SMB_SAM_REPL, &low_serial, + message_send_all(MSG_SMB_SAM_REPL, &low_serial, sizeof(low_serial), False, NULL); - - tdb_close(tdb); } /**************************************************************************** diff --git a/source3/rpc_server/srv_netlog_nt.c b/source3/rpc_server/srv_netlog_nt.c index 0c12cb3b7c..e110f39289 100644 --- a/source3/rpc_server/srv_netlog_nt.c +++ b/source3/rpc_server/srv_netlog_nt.c @@ -75,22 +75,8 @@ Send a message to smbd to do a sam synchronisation static void send_sync_message(void) { - TDB_CONTEXT *tdb; - - tdb = tdb_open_log(lock_path("connections.tdb"), 0, - TDB_DEFAULT, O_RDONLY, 0); - - if (!tdb) { - DEBUG(3, ("send_sync_message(): failed to open connections " - "database\n")); - return; - } - DEBUG(3, ("sending sam synchronisation message\n")); - - message_send_all(tdb, MSG_SMB_SAM_SYNC, NULL, 0, False, NULL); - - tdb_close(tdb); + message_send_all(MSG_SMB_SAM_SYNC, NULL, 0, False, NULL); } /************************************************************************* diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 7e46541b94..a4edeb2cfd 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -311,7 +311,7 @@ WERROR delete_printer_hook( NT_USER_TOKEN *token, const char *sharename ) if ( (ret = smbrun(command, NULL)) == 0 ) { /* Tell everyone we updated smb.conf. */ - 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); } if ( is_print_op ) @@ -6253,7 +6253,7 @@ BOOL add_printer_hook(NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printer) if ( (ret = smbrun(command, &fd)) == 0 ) { /* Tell everyone we updated smb.conf. */ - 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); } if ( is_print_op ) diff --git a/source3/rpc_server/srv_srvsvc_nt.c b/source3/rpc_server/srv_srvsvc_nt.c index 2365f7ece3..59e86e4912 100644 --- a/source3/rpc_server/srv_srvsvc_nt.c +++ b/source3/rpc_server/srv_srvsvc_nt.c @@ -104,27 +104,22 @@ static WERROR net_enum_pipes( TALLOC_CTX *ctx, struct srvsvc_NetFileInfo3 **info uint32 *count, uint32 *resume ) { struct file_enum_count fenum; - TDB_CONTEXT *conn_tdb = conn_tdb_ctx(); - if ( !conn_tdb ) { - DEBUG(0,("net_enum_pipes: Failed to retrieve the connections tdb handle!\n")); - return WERR_ACCESS_DENIED; - } - fenum.ctx = ctx; fenum.info = *info; fenum.count = *count; - if (tdb_traverse(conn_tdb, pipe_enum_fn, &fenum) == -1) { - DEBUG(0,("net_enum_pipes: traverse of connections.tdb failed with error %s.\n", - tdb_errorstr(conn_tdb) )); + if (connections_traverse(pipe_enum_fn, &fenum) == -1) { + DEBUG(0,("net_enum_pipes: traverse of connections.tdb " + "failed\n")); return WERR_NOMEM; } *info = fenum.info; *count = fenum.count; - return WERR_OK;} + return WERR_OK; +} /******************************************************************* ********************************************************************/ @@ -1421,7 +1416,7 @@ static WERROR add_share(const char *share_name, const char *path, if ( (ret = smbrun(command, NULL)) == 0 ) { /* Tell everyone we updated smb.conf. */ - message_send_all(conn_tdb_ctx(), MSG_SMB_CONF_UPDATED, + message_send_all(MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL); } @@ -1517,7 +1512,7 @@ static WERROR delete_share(const char *sharename, if ( (ret = smbrun(command, NULL)) == 0 ) { /* Tell everyone we updated smb.conf. */ - message_send_all(conn_tdb_ctx(), MSG_SMB_CONF_UPDATED, + message_send_all(MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL); } @@ -1575,7 +1570,7 @@ static WERROR change_share(const char *share_name, const char *path, if ( (ret = smbrun(command, NULL)) == 0 ) { /* Tell everyone we updated smb.conf. */ - message_send_all(conn_tdb_ctx(), MSG_SMB_CONF_UPDATED, + message_send_all(MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL); } 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, diff --git a/source3/utils/net_status.c b/source3/utils/net_status.c index af6952389c..88c1789f71 100644 --- a/source3/utils/net_status.c +++ b/source3/utils/net_status.c @@ -84,27 +84,22 @@ static int net_status_sessions(int argc, const char **argv) return 0; } -static int show_share(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, +static int show_share(TDB_CONTEXT *tdb, + const struct connections_key *key, + const struct connections_data *crec, void *state) { - struct connections_data crec; - - if (dbuf.dsize != sizeof(crec)) + if (crec->cnum == -1) return 0; - memcpy(&crec, dbuf.dptr, sizeof(crec)); - - if (crec.cnum == -1) - return 0; - - if (!process_exists(crec.pid)) { + if (!process_exists(crec->pid)) { return 0; } d_printf("%-10.10s %s %-12s %s", - crec.servicename, procid_str_static(&crec.pid), - crec.machine, - time_to_asc(crec.start)); + crec->servicename, procid_str_static(&crec->pid), + crec->machine, + time_to_asc(crec->start)); return 0; } @@ -139,41 +134,37 @@ static int collect_pid(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, return 0; } -static int show_share_parseable(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, +static int show_share_parseable(TDB_CONTEXT *tdb, + const struct connections_key *key, + const struct connections_data *crec, void *state) { struct sessionids *ids = (struct sessionids *)state; - struct connections_data crec; int i; BOOL guest = True; - if (dbuf.dsize != sizeof(crec)) - return 0; - - memcpy(&crec, dbuf.dptr, sizeof(crec)); - - if (crec.cnum == -1) + if (crec->cnum == -1) return 0; - if (!process_exists(crec.pid)) { + if (!process_exists(crec->pid)) { return 0; } for (i=0; i<ids->num_entries; i++) { struct server_id id = ids->entries[i].pid; - if (procid_equal(&id, &crec.pid)) { + if (procid_equal(&id, &crec->pid)) { guest = False; break; } } d_printf("%s\\%s\\%s\\%s\\%s\\%s\\%s", - crec.servicename,procid_str_static(&crec.pid), + crec->servicename,procid_str_static(&crec->pid), guest ? "" : uidtoname(ids->entries[i].uid), guest ? "" : gidtoname(ids->entries[i].gid), - crec.machine, + crec->machine, guest ? "" : ids->entries[i].hostname, - time_to_asc(crec.start)); + time_to_asc(crec->start)); return 0; } @@ -197,18 +188,7 @@ static int net_status_shares_parseable(int argc, const char **argv) tdb_traverse(tdb, collect_pid, &ids); tdb_close(tdb); - tdb = tdb_open_log(lock_path("connections.tdb"), 0, - TDB_DEFAULT, O_RDONLY, 0); - - if (tdb == NULL) { - d_fprintf(stderr, "%s not initialised\n", lock_path("connections.tdb")); - d_fprintf(stderr, "This is normal if no SMB client has ever " - "connected to your server.\n"); - return -1; - } - - tdb_traverse(tdb, show_share_parseable, &ids); - tdb_close(tdb); + connections_forall(show_share_parseable, &ids); SAFE_FREE(ids.entries); @@ -217,8 +197,6 @@ static int net_status_shares_parseable(int argc, const char **argv) static int net_status_shares(int argc, const char **argv) { - TDB_CONTEXT *tdb; - if (argc == 0) { d_printf("\nService pid machine " @@ -226,19 +204,7 @@ static int net_status_shares(int argc, const char **argv) d_printf("-------------------------------------" "------------------\n"); - tdb = tdb_open_log(lock_path("connections.tdb"), 0, - TDB_DEFAULT, O_RDONLY, 0); - - if (tdb == NULL) { - d_fprintf(stderr, "%s not initialised\n", - lock_path("connections.tdb")); - d_fprintf(stderr, "This is normal if no SMB client has " - "ever connected to your server.\n"); - return -1; - } - - tdb_traverse(tdb, show_share, NULL); - tdb_close(tdb); + connections_forall(show_share, NULL); return 0; } diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c index d9eb5b78ea..ab46cbce65 100644 --- a/source3/utils/smbcontrol.c +++ b/source3/utils/smbcontrol.c @@ -51,7 +51,6 @@ static BOOL send_message(struct server_id pid, int msg_type, const void *buf, int len, BOOL duplicates) { - TDB_CONTEXT *tdb; BOOL ret; int n_sent = 0; @@ -62,21 +61,11 @@ static BOOL send_message(struct server_id pid, int msg_type, return NT_STATUS_IS_OK(message_send_pid(pid, msg_type, buf, len, duplicates)); - tdb = tdb_open_log(lock_path("connections.tdb"), 0, - TDB_DEFAULT, O_RDWR, 0); - if (!tdb) { - fprintf(stderr,"Failed to open connections database" - ": %s\n", strerror(errno)); - return False; - } - - ret = message_send_all(tdb,msg_type, buf, len, duplicates, + ret = message_send_all(msg_type, buf, len, duplicates, &n_sent); DEBUG(10,("smbcontrol/send_message: broadcast message to " "%d processes\n", n_sent)); - tdb_close(tdb); - return ret; } @@ -247,16 +236,11 @@ cleanup: ptrace(PTRACE_DETACH, pid, NULL, NULL); } -static int stack_trace_connection(TDB_CONTEXT * tdb, TDB_DATA key, - TDB_DATA data, void * priv) +static int stack_trace_connection(TDB_CONTEXT * tdb, + const struct connections_key *key, + const struct connections_data *conn, { - struct connections_data conn; - - if (data.dsize != sizeof(conn)) - return 0; - - memcpy(&conn, data.dptr, sizeof(conn)); - print_stack_trace(procid_to_pid(&conn.pid), (int *)priv); + print_stack_trace(procid_to_pid(&conn->pid), (int *)priv); return 0; } @@ -286,19 +270,7 @@ static BOOL do_daemon_stack_trace(const struct server_id pid, */ print_stack_trace(dest, &count); } else { - TDB_CONTEXT * tdb; - - tdb = tdb_open_log(lock_path("connections.tdb"), 0, - TDB_DEFAULT, O_RDONLY, 0); - if (!tdb) { - fprintf(stderr, - "Failed to open connections database: %s\n", - strerror(errno)); - return False; - } - - tdb_traverse(tdb, stack_trace_connection, &count); - tdb_close(tdb); + connections_traverse(stack_trace_connection, &count); } return True; diff --git a/source3/utils/status.c b/source3/utils/status.c index d3bb79dd01..aa014c8410 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -188,26 +188,22 @@ static void print_brl(SMB_DEV_T dev, (double)start, (double)size); } -static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state) +static int traverse_fn1(TDB_CONTEXT *tdb, + const struct connections_key *key, + const struct connections_data *crec, + void *state) { - struct connections_data crec; - - if (dbuf.dsize != sizeof(crec)) - return 0; - - memcpy(&crec, dbuf.dptr, sizeof(crec)); - - if (crec.cnum == -1) + if (crec->cnum == -1) return 0; - if (!process_exists(crec.pid) || !Ucrit_checkUid(crec.uid)) { + if (!process_exists(crec->pid) || !Ucrit_checkUid(crec->uid)) { return 0; } d_printf("%-10s %s %-12s %s", - crec.servicename,procid_str_static(&crec.pid), - crec.machine, - time_to_asc(crec.start)); + crec->servicename,procid_str_static(&crec->pid), + crec->machine, + time_to_asc(crec->start)); return 0; } @@ -339,26 +335,19 @@ static int traverse_sessionid(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, vo } if ( show_shares ) { - tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0); - if (!tdb) { - d_printf("%s not initialised\n", lock_path("connections.tdb")); - d_printf("This is normal if an SMB client has never connected to your server.\n"); - } else { - if (verbose) { - d_printf("Opened %s\n", lock_path("connections.tdb")); - } + if (verbose) { + d_printf("Opened %s\n", lock_path("connections.tdb")); + } - if (brief) - exit(0); + if (brief) + exit(0); - d_printf("\nService pid machine Connected at\n"); - d_printf("-------------------------------------------------------\n"); + d_printf("\nService pid machine Connected at\n"); + d_printf("-------------------------------------------------------\n"); - tdb_traverse(tdb, traverse_fn1, NULL); - tdb_close(tdb); + connections_forall(traverse_fn1, NULL); - d_printf("\n"); - } + d_printf("\n"); if ( shares_only ) exit(0); diff --git a/source3/web/statuspage.c b/source3/web/statuspage.c index 7b5c528a7d..2071561e2e 100644 --- a/source3/web/statuspage.c +++ b/source3/web/statuspage.c @@ -167,20 +167,17 @@ static void print_share_mode(const struct share_mode_entry *e, /* kill off any connections chosen by the user */ -static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* state) +static int traverse_fn1(TDB_CONTEXT *tdb, + const struct connections_key *key, + const struct connections_data *crec, + void* state) { - struct connections_data crec; - - if (dbuf.dsize != sizeof(crec)) - return 0; - - memcpy(&crec, dbuf.dptr, sizeof(crec)); - - if (crec.cnum == -1 && process_exists(crec.pid)) { + if (crec->cnum == -1 && process_exists(crec->pid)) { char buf[30]; - slprintf(buf,sizeof(buf)-1,"kill_%s", procid_str_static(&crec.pid)); + slprintf(buf, sizeof(buf)-1,"kill_%s", + procid_str_static(&crec->pid)); if (cgi_variable(buf)) { - kill_pid(crec.pid); + kill_pid(crec->pid); sleep(SLEEP_TIME); } } @@ -188,28 +185,24 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* st } /* traversal fn for showing machine connections */ -static int traverse_fn2(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* state) +static int traverse_fn2(TDB_CONTEXT *tdb, + const struct connections_key *key, + const struct connections_data *crec, + void* state) { - struct connections_data crec; - - if (dbuf.dsize != sizeof(crec)) - return 0; - - memcpy(&crec, dbuf.dptr, sizeof(crec)); - - if (crec.cnum == -1 || !process_exists(crec.pid) || - procid_equal(&crec.pid, &smbd_pid)) + if (crec->cnum == -1 || !process_exists(crec->pid) || + procid_equal(&crec->pid, &smbd_pid)) return 0; - addPid2Machine (crec.pid, crec.machine); + addPid2Machine (crec->pid, crec->machine); printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td>\n", - procid_str_static(&crec.pid), - crec.machine,crec.addr, - tstring(crec.start)); + procid_str_static(&crec->pid), + crec->machine, crec->addr, + tstring(crec->start)); if (geteuid() == 0) { printf("<td><input type=submit value=\"X\" name=\"kill_%s\"></td>\n", - procid_str_static(&crec.pid)); + procid_str_static(&crec->pid)); } printf("</tr>\n"); @@ -217,23 +210,19 @@ static int traverse_fn2(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* st } /* traversal fn for showing share connections */ -static int traverse_fn3(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* state) +static int traverse_fn3(TDB_CONTEXT *tdb, + const struct connections_key *key, + const struct connections_data *crec, + void* state) { - struct connections_data crec; - - if (dbuf.dsize != sizeof(crec)) - return 0; - - memcpy(&crec, dbuf.dptr, sizeof(crec)); - - if (crec.cnum == -1 || !process_exists(crec.pid)) + if (crec->cnum == -1 || !process_exists(crec->pid)) return 0; printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n", - crec.servicename,uidtoname(crec.uid), - gidtoname(crec.gid),procid_str_static(&crec.pid), - crec.machine, - tstring(crec.start)); + crec->servicename, uidtoname(crec->uid), + gidtoname(crec->gid),procid_str_static(&crec->pid), + crec->machine, + tstring(crec->start)); return 0; } @@ -244,7 +233,6 @@ void status_page(void) const char *v; int autorefresh=0; int refresh_interval=30; - TDB_CONTEXT *tdb; int nr_running=0; BOOL waitup = False; @@ -322,8 +310,7 @@ void status_page(void) PID_or_Machine = 0; } - tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0); - if (tdb) tdb_traverse(tdb, traverse_fn1, NULL); + connections_forall(traverse_fn1, NULL); initPid2Machine (); @@ -344,12 +331,6 @@ void status_page(void) printf("<p>\n"); - if (!tdb) { - /* open failure either means no connections have been - made */ - } - - printf("<table>\n"); printf("<tr><td>%s</td><td>%s</td></tr>", _("version:"), SAMBA_VERSION_STRING); @@ -419,7 +400,7 @@ void status_page(void) } printf("</tr>\n"); - if (tdb) tdb_traverse(tdb, traverse_fn2, NULL); + connections_forall(traverse_fn2, NULL); printf("</table><p>\n"); @@ -428,7 +409,7 @@ void status_page(void) printf("<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>\n\n", _("Share"), _("User"), _("Group"), _("PID"), _("Client"), _("Date")); - if (tdb) tdb_traverse(tdb, traverse_fn3, NULL); + connections_forall(traverse_fn3, NULL); printf("</table><p>\n"); @@ -441,8 +422,6 @@ void status_page(void) locking_end(); printf("</table>\n"); - if (tdb) tdb_close(tdb); - printf("<br><input type=submit name=\"show_client_in_col_1\" value=\"%s\">\n", _("Show Client in col 1")); printf("<input type=submit name=\"show_pid_in_col_1\" value=\"%s\">\n", _("Show PID in col 1")); |