Make sure we don't clobber the stack when response consists of the empty
[Samba/gebeck_regimport.git] / source3 / smbd / tdbutil.c
blobcafcde203741bff54cd46fc2742b710fdd36abfe
1 /*
2 Unix SMB/CIFS implementation.
3 Main SMB server routines
4 Copyright (C) Jeremy Allison 2003
5 Copyright (C) Gerald (Jerry) Carter 2004
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "includes.h"
25 /**********************************************************************
26 logging function used by smbd to detect and remove corrupted tdb's
27 **********************************************************************/
29 void smbd_tdb_log(TDB_CONTEXT *tdb, int level, const char *format, ...)
31 va_list ap;
32 char *ptr = NULL;
33 BOOL decrement_smbd_count;
35 va_start(ap, format);
36 vasprintf(&ptr, format, ap);
37 va_end(ap);
39 if (!ptr || !*ptr)
40 return;
42 DEBUG(level, ("tdb(%s): %s", tdb->name ? tdb->name : "unnamed", ptr));
44 if (tdb->ecode == TDB_ERR_CORRUPT) {
45 int ret;
47 DEBUG(0,("tdb_log: TDB %s is corrupt. Removing file and stopping this process.\n",
48 tdb->name ));
50 become_root();
51 ret = unlink(tdb->name);
52 if ( ret ) {
53 DEBUG(0,("ERROR: %s\n", strerror(errno)));
55 unbecome_root();
58 /* if its not connections.tdb, then make sure we decrement the
59 smbd count. If connections.tdb is bad, there's nothing we
60 can do and everything will eventually shut down or clean
61 up anyways */
63 if ( strcmp(tdb->name, lock_path("connections.tdb")) == 0 )
64 decrement_smbd_count = False;
65 else
66 decrement_smbd_count = True;
68 /* now die */
70 smb_panic2("corrupt tdb\n", decrement_smbd_count );
73 if (tdb->ecode == TDB_ERR_IO)
75 if ( strcmp(tdb->name, lock_path("connections.tdb")) == 0 )
76 decrement_smbd_count = False;
77 else
78 decrement_smbd_count = True;
80 smb_panic2( "i/o error on tdb.\n", decrement_smbd_count );
83 SAFE_FREE(ptr);