| 1 | /*
|
|---|
| 2 | Unix SMB/CIFS implementation.
|
|---|
| 3 | Samba utility functions
|
|---|
| 4 | Copyright (C) Andrew Tridgell 1992-1998
|
|---|
| 5 | Copyright (C) Elrond 2002
|
|---|
| 6 | Copyright (C) Simo Sorce 2002
|
|---|
| 7 |
|
|---|
| 8 | This program is free software; you can redistribute it and/or modify
|
|---|
| 9 | it under the terms of the GNU General Public License as published by
|
|---|
| 10 | the Free Software Foundation; either version 3 of the License, or
|
|---|
| 11 | (at your option) any later version.
|
|---|
| 12 |
|
|---|
| 13 | This program is distributed in the hope that it will be useful,
|
|---|
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 16 | GNU General Public License for more details.
|
|---|
| 17 |
|
|---|
| 18 | You should have received a copy of the GNU General Public License
|
|---|
| 19 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 20 | */
|
|---|
| 21 |
|
|---|
| 22 | #include "includes.h"
|
|---|
| 23 |
|
|---|
| 24 | /* -------------------------------------------------------------------------- **
|
|---|
| 25 | * Defines...
|
|---|
| 26 | *
|
|---|
| 27 | * FORMAT_BUFR_MAX - Index of the last byte of the format buffer;
|
|---|
| 28 | * format_bufr[FORMAT_BUFR_MAX] should always be reserved
|
|---|
| 29 | * for a terminating null byte.
|
|---|
| 30 | */
|
|---|
| 31 |
|
|---|
| 32 | #define FORMAT_BUFR_SIZE 1024
|
|---|
| 33 | #define FORMAT_BUFR_MAX (FORMAT_BUFR_SIZE - 1)
|
|---|
| 34 |
|
|---|
| 35 | /* -------------------------------------------------------------------------- **
|
|---|
| 36 | * This module implements Samba's debugging utility.
|
|---|
| 37 | *
|
|---|
| 38 | * The syntax of a debugging log file is represented as:
|
|---|
| 39 | *
|
|---|
| 40 | * <debugfile> :== { <debugmsg> }
|
|---|
| 41 | *
|
|---|
| 42 | * <debugmsg> :== <debughdr> '\n' <debugtext>
|
|---|
| 43 | *
|
|---|
| 44 | * <debughdr> :== '[' TIME ',' LEVEL ']' [ [FILENAME ':'] [FUNCTION '()'] ]
|
|---|
| 45 | *
|
|---|
| 46 | * <debugtext> :== { <debugline> }
|
|---|
| 47 | *
|
|---|
| 48 | * <debugline> :== TEXT '\n'
|
|---|
| 49 | *
|
|---|
| 50 | * TEXT is a string of characters excluding the newline character.
|
|---|
| 51 | * LEVEL is the DEBUG level of the message (an integer in the range 0..10).
|
|---|
| 52 | * TIME is a timestamp.
|
|---|
| 53 | * FILENAME is the name of the file from which the debug message was generated.
|
|---|
| 54 | * FUNCTION is the function from which the debug message was generated.
|
|---|
| 55 | *
|
|---|
| 56 | * Basically, what that all means is:
|
|---|
| 57 | *
|
|---|
| 58 | * - A debugging log file is made up of debug messages.
|
|---|
| 59 | *
|
|---|
| 60 | * - Each debug message is made up of a header and text. The header is
|
|---|
| 61 | * separated from the text by a newline.
|
|---|
| 62 | *
|
|---|
| 63 | * - The header begins with the timestamp and debug level of the message
|
|---|
| 64 | * enclosed in brackets. The filename and function from which the
|
|---|
| 65 | * message was generated may follow. The filename is terminated by a
|
|---|
| 66 | * colon, and the function name is terminated by parenthesis.
|
|---|
| 67 | *
|
|---|
| 68 | * - The message text is made up of zero or more lines, each terminated by
|
|---|
| 69 | * a newline.
|
|---|
| 70 | */
|
|---|
| 71 |
|
|---|
| 72 | /* -------------------------------------------------------------------------- **
|
|---|
| 73 | * External variables.
|
|---|
| 74 | *
|
|---|
| 75 | * dbf - Global debug file handle.
|
|---|
| 76 | * debugf - Debug file name.
|
|---|
| 77 | * DEBUGLEVEL - System-wide debug message limit. Messages with message-
|
|---|
| 78 | * levels higher than DEBUGLEVEL will not be processed.
|
|---|
| 79 | */
|
|---|
| 80 |
|
|---|
| 81 | XFILE *dbf = NULL;
|
|---|
| 82 | static char *debugf = NULL;
|
|---|
| 83 | bool debug_warn_unknown_class = True;
|
|---|
| 84 | bool debug_auto_add_unknown_class = True;
|
|---|
| 85 | bool AllowDebugChange = True;
|
|---|
| 86 |
|
|---|
| 87 | /*
|
|---|
| 88 | used to check if the user specified a
|
|---|
| 89 | logfile on the command line
|
|---|
| 90 | */
|
|---|
| 91 | bool override_logfile;
|
|---|
| 92 |
|
|---|
| 93 | /*
|
|---|
| 94 | * This is to allow assignment to DEBUGLEVEL before the debug
|
|---|
| 95 | * system has been initialized.
|
|---|
| 96 | */
|
|---|
| 97 | static int debug_all_class_hack = 1;
|
|---|
| 98 | static bool debug_all_class_isset_hack = True;
|
|---|
| 99 |
|
|---|
| 100 | static int debug_num_classes = 0;
|
|---|
| 101 | int *DEBUGLEVEL_CLASS = &debug_all_class_hack;
|
|---|
| 102 | bool *DEBUGLEVEL_CLASS_ISSET = &debug_all_class_isset_hack;
|
|---|
| 103 |
|
|---|
| 104 | /* DEBUGLEVEL is #defined to *debug_level */
|
|---|
| 105 | int DEBUGLEVEL = &debug_all_class_hack;
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 | /* -------------------------------------------------------------------------- **
|
|---|
| 109 | * Internal variables.
|
|---|
| 110 | *
|
|---|
| 111 | * stdout_logging - Default False, if set to True then dbf will be set to
|
|---|
| 112 | * stdout and debug output will go to dbf only, and not
|
|---|
| 113 | * to syslog. Set in setup_logging() and read in Debug1().
|
|---|
| 114 | *
|
|---|
| 115 | * debug_count - Number of debug messages that have been output.
|
|---|
| 116 | * Used to check log size.
|
|---|
| 117 | *
|
|---|
| 118 | * syslog_level - Internal copy of the message debug level. Written by
|
|---|
| 119 | * dbghdr() and read by Debug1().
|
|---|
| 120 | *
|
|---|
| 121 | * format_bufr - Used to format debug messages. The dbgtext() function
|
|---|
| 122 | * prints debug messages to a string, and then passes the
|
|---|
| 123 | * string to format_debug_text(), which uses format_bufr
|
|---|
| 124 | * to build the formatted output.
|
|---|
| 125 | *
|
|---|
| 126 | * format_pos - Marks the first free byte of the format_bufr.
|
|---|
| 127 | *
|
|---|
| 128 | *
|
|---|
| 129 | * log_overflow - When this variable is True, never attempt to check the
|
|---|
| 130 | * size of the log. This is a hack, so that we can write
|
|---|
| 131 | * a message using DEBUG, from open_logs() when we
|
|---|
| 132 | * are unable to open a new log file for some reason.
|
|---|
| 133 | */
|
|---|
| 134 |
|
|---|
| 135 | static bool stdout_logging = False;
|
|---|
| 136 | static int debug_count = 0;
|
|---|
| 137 | #ifdef WITH_SYSLOG
|
|---|
| 138 | static int syslog_level = 0;
|
|---|
| 139 | #endif
|
|---|
| 140 | static char *format_bufr = NULL;
|
|---|
| 141 | static size_t format_pos = 0;
|
|---|
| 142 | static bool log_overflow = False;
|
|---|
| 143 |
|
|---|
| 144 | /*
|
|---|
| 145 | * Define all the debug class selection names here. Names *MUST NOT* contain
|
|---|
| 146 | * white space. There must be one name for each DBGC_<class name>, and they
|
|---|
| 147 | * must be in the table in the order of DBGC_<class name>..
|
|---|
| 148 | */
|
|---|
| 149 | static const char *default_classname_table[] = {
|
|---|
| 150 | "all", /* DBGC_ALL; index refs traditional DEBUGLEVEL */
|
|---|
| 151 | "tdb", /* DBGC_TDB */
|
|---|
| 152 | "printdrivers", /* DBGC_PRINTDRIVERS */
|
|---|
| 153 | "lanman", /* DBGC_LANMAN */
|
|---|
| 154 | "smb", /* DBGC_SMB */
|
|---|
| 155 | "rpc_parse", /* DBGC_RPC_PARSE */
|
|---|
| 156 | "rpc_srv", /* DBGC_RPC_SRV */
|
|---|
| 157 | "rpc_cli", /* DBGC_RPC_CLI */
|
|---|
| 158 | "passdb", /* DBGC_PASSDB */
|
|---|
| 159 | "sam", /* DBGC_SAM */
|
|---|
| 160 | "auth", /* DBGC_AUTH */
|
|---|
| 161 | "winbind", /* DBGC_WINBIND */
|
|---|
| 162 | "vfs", /* DBGC_VFS */
|
|---|
| 163 | "idmap", /* DBGC_IDMAP */
|
|---|
| 164 | "quota", /* DBGC_QUOTA */
|
|---|
| 165 | "acls", /* DBGC_ACLS */
|
|---|
| 166 | "locking", /* DBGC_LOCKING */
|
|---|
| 167 | "msdfs", /* DBGC_MSDFS */
|
|---|
| 168 | "dmapi", /* DBGC_DMAPI */
|
|---|
| 169 | "registry", /* DBGC_REGISTRY */
|
|---|
| 170 | NULL
|
|---|
| 171 | };
|
|---|
| 172 |
|
|---|
| 173 | static char **classname_table = NULL;
|
|---|
| 174 |
|
|---|
| 175 |
|
|---|
| 176 | /* -------------------------------------------------------------------------- **
|
|---|
| 177 | * Functions...
|
|---|
| 178 | */
|
|---|
| 179 |
|
|---|
| 180 | /***************************************************************************
|
|---|
| 181 | Free memory pointed to by global pointers.
|
|---|
| 182 | ****************************************************************************/
|
|---|
| 183 |
|
|---|
| 184 | static bool initialized;
|
|---|
| 185 |
|
|---|
| 186 | void gfree_debugsyms(void)
|
|---|
| 187 | {
|
|---|
| 188 | int i;
|
|---|
| 189 |
|
|---|
| 190 | if ( classname_table ) {
|
|---|
| 191 | for ( i = 0; i < debug_num_classes; i++ ) {
|
|---|
| 192 | SAFE_FREE( classname_table[i] );
|
|---|
| 193 | }
|
|---|
| 194 | SAFE_FREE( classname_table );
|
|---|
| 195 | }
|
|---|
| 196 |
|
|---|
| 197 | if ( DEBUGLEVEL_CLASS != &debug_all_class_hack ) {
|
|---|
| 198 | SAFE_FREE( DEBUGLEVEL_CLASS );
|
|---|
| 199 | DEBUGLEVEL_CLASS = &debug_all_class_hack;
|
|---|
| 200 | }
|
|---|
| 201 |
|
|---|
| 202 | if ( DEBUGLEVEL_CLASS_ISSET != &debug_all_class_isset_hack ) {
|
|---|
| 203 | SAFE_FREE( DEBUGLEVEL_CLASS_ISSET );
|
|---|
| 204 | DEBUGLEVEL_CLASS_ISSET = &debug_all_class_isset_hack;
|
|---|
|
|---|