diff options
author | Gerald Carter <jerry@samba.org> | 2004-02-12 05:59:03 +0000 |
---|---|---|
committer | Gerald Carter <jerry@samba.org> | 2004-02-12 05:59:03 +0000 |
commit | 30d707b8ae4c53140e0215090f7a3c8936ab2b47 (patch) | |
tree | 33884a5c06762f63e28e4f39ff5aaba03cbcbc1e /source3/smbd | |
parent | ed1862b3b21d1cbe4a013838bf5c581c600657c2 (diff) | |
download | samba-30d707b8ae4c53140e0215090f7a3c8936ab2b47.tar.gz samba-30d707b8ae4c53140e0215090f7a3c8936ab2b47.tar.bz2 samba-30d707b8ae4c53140e0215090f7a3c8936ab2b47.zip |
tdbsam & smb_panic merge from 3.0 (initial tests are ok but I'll setup a HEAD PDC tomorrow)
(This used to be commit c57b24ee49aee0f0687742da7f8d741c62f6effe)
Diffstat (limited to 'source3/smbd')
-rw-r--r-- | source3/smbd/connection.c | 8 | ||||
-rw-r--r-- | source3/smbd/server.c | 2 | ||||
-rw-r--r-- | source3/smbd/session.c | 4 | ||||
-rw-r--r-- | source3/smbd/tdbutil.c | 85 |
4 files changed, 93 insertions, 6 deletions
diff --git a/source3/smbd/connection.c b/source3/smbd/connection.c index 5bb76eb3bd..a9ab142461 100644 --- a/source3/smbd/connection.c +++ b/source3/smbd/connection.c @@ -29,8 +29,8 @@ static TDB_CONTEXT *tdb; 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); + tdb = tdb_open_ex(lock_path("connections.tdb"), 0, TDB_CLEAR_IF_FIRST|TDB_DEFAULT, + O_RDWR | O_CREAT, 0644, smbd_tdb_log); return tdb; } @@ -131,8 +131,8 @@ BOOL claim_connection(connection_struct *conn, const char *name,int max_connecti TDB_DATA kbuf, dbuf; if (!tdb) - tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_CLEAR_IF_FIRST|TDB_DEFAULT, - O_RDWR | O_CREAT, 0644); + tdb = tdb_open_ex(lock_path("connections.tdb"), 0, TDB_CLEAR_IF_FIRST|TDB_DEFAULT, + O_RDWR | O_CREAT, 0644, smbd_tdb_log); if (!tdb) return False; diff --git a/source3/smbd/server.c b/source3/smbd/server.c index e2ffe8cc9f..be59e92cd7 100644 --- a/source3/smbd/server.c +++ b/source3/smbd/server.c @@ -501,6 +501,7 @@ BOOL reload_services(BOOL test) return(ret); } + #if DUMP_CORE /******************************************************************* prepare to dump a core file - carefully! @@ -890,3 +891,4 @@ void build_options(BOOL screen); exit_server("normal exit"); return(0); } + diff --git a/source3/smbd/session.c b/source3/smbd/session.c index 4d8826d332..a811a6e305 100644 --- a/source3/smbd/session.c +++ b/source3/smbd/session.c @@ -53,8 +53,8 @@ BOOL session_claim(user_struct *vuser) } if (!tdb) { - tdb = tdb_open_log(lock_path("sessionid.tdb"), 0, TDB_CLEAR_IF_FIRST|TDB_DEFAULT, - O_RDWR | O_CREAT, 0644); + tdb = tdb_open_ex(lock_path("sessionid.tdb"), 0, TDB_CLEAR_IF_FIRST|TDB_DEFAULT, + O_RDWR | O_CREAT, 0644, smbd_tdb_log); if (!tdb) { DEBUG(1,("session_claim: failed to open sessionid tdb\n")); return False; diff --git a/source3/smbd/tdbutil.c b/source3/smbd/tdbutil.c new file mode 100644 index 0000000000..cafcde2037 --- /dev/null +++ b/source3/smbd/tdbutil.c @@ -0,0 +1,85 @@ +/* + Unix SMB/CIFS implementation. + Main SMB server routines + Copyright (C) Jeremy Allison 2003 + Copyright (C) Gerald (Jerry) Carter 2004 + + 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" + + +/********************************************************************** + logging function used by smbd to detect and remove corrupted tdb's +**********************************************************************/ + +void smbd_tdb_log(TDB_CONTEXT *tdb, int level, const char *format, ...) +{ + va_list ap; + char *ptr = NULL; + BOOL decrement_smbd_count; + + va_start(ap, format); + vasprintf(&ptr, format, ap); + va_end(ap); + + if (!ptr || !*ptr) + return; + + DEBUG(level, ("tdb(%s): %s", tdb->name ? tdb->name : "unnamed", ptr)); + + if (tdb->ecode == TDB_ERR_CORRUPT) { + int ret; + + DEBUG(0,("tdb_log: TDB %s is corrupt. Removing file and stopping this process.\n", + tdb->name )); + + become_root(); + ret = unlink(tdb->name); + if ( ret ) { + DEBUG(0,("ERROR: %s\n", strerror(errno))); + } + unbecome_root(); + + + /* if its not connections.tdb, then make sure we decrement the + smbd count. If connections.tdb is bad, there's nothing we + can do and everything will eventually shut down or clean + up anyways */ + + if ( strcmp(tdb->name, lock_path("connections.tdb")) == 0 ) + decrement_smbd_count = False; + else + decrement_smbd_count = True; + + /* now die */ + + smb_panic2("corrupt tdb\n", decrement_smbd_count ); + } + + if (tdb->ecode == TDB_ERR_IO) + { + if ( strcmp(tdb->name, lock_path("connections.tdb")) == 0 ) + decrement_smbd_count = False; + else + decrement_smbd_count = True; + + smb_panic2( "i/o error on tdb.\n", decrement_smbd_count ); + } + + SAFE_FREE(ptr); +} + |