summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/Makefile.in2
-rw-r--r--source3/include/proto.h14
-rw-r--r--source3/include/smb.h68
-rw-r--r--source3/lib/util.c279
4 files changed, 70 insertions, 293 deletions
diff --git a/source3/Makefile.in b/source3/Makefile.in
index e5a6bfc36a..e8b88b38a9 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -130,7 +130,7 @@ PASSDB_OBJ = passdb.o ldap.o smbpass.o nisppass.o smbpassfile.o
# general utility object files
UTILOBJ1 = util.o system.o charset.o kanji.o fault.o smbencrypt.o smbdes.o charcnv.o genrand.o
UTILOBJ2 = $(UTILOBJ1) md4.o loadparm.o params.o pcap.o username.o time.o membuffer.o namequery.o nmblib.o
-UTILOBJ3 = $(UTILOBJ2) signal.o netmask.o dfree.o
+UTILOBJ3 = $(UTILOBJ2) signal.o netmask.o dfree.o debug.o
UTILOBJ = $(UTILOBJ3) credentials.o interface.o replace.o print_svid.o smberr.o pidfile.o slprintf.o \
$(SSL_OBJ) $(UBIOBJ)
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 56d72bd339..10f01c1b9d 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -160,6 +160,15 @@ BOOL deal_with_creds(uchar sess_key[8],
DOM_CRED *sto_clnt_cred,
DOM_CRED *rcv_clnt_cred, DOM_CRED *rtn_srv_cred);
+/*The following definitions come from debug.c */
+
+int sig_usr2( void );
+int sig_usr1( void );
+void setup_logging( char *pname, BOOL interactive );
+void reopen_logs( void );
+void force_check_log_size( void );
+BOOL dbghdr( int level, char *file, char *func, int line );
+
/*The following definitions come from dfree.c */
int sys_disk_free(char *path,int *bsize,int *dfree,int *dsize);
@@ -1972,11 +1981,6 @@ BOOL user_in_list(char *user,char *list);
/*The following definitions come from util.c */
-int sig_usr2(void);
-int sig_usr1(void);
-void setup_logging(char *pname,BOOL interactive);
-void reopen_logs(void);
-void force_check_log_size(void);
char *tmpdir(void);
BOOL is_a_socket(int fd);
BOOL next_token(char **ptr,char *buff,char *sep);
diff --git a/source3/include/smb.h b/source3/include/smb.h
index 115d8ce31b..60e214d73e 100644
--- a/source3/include/smb.h
+++ b/source3/include/smb.h
@@ -90,17 +90,69 @@ typedef unsigned short uint16;
/* how long to wait for secondary SMB packets (milli-seconds) */
#define SMB_SECONDARY_WAIT (60*1000)
-/* debugging code */
-#if !defined(WITH_SYSLOG) || defined(NO_SYSLOG)
-#define DEBUG(level,body) ((DEBUGLEVEL>=(level))?(Debug1 body):0)
-#define DEBUGLVL(level) (DEBUGLEVEL>=(level))
+/* -------------------------------------------------------------------------- **
+ * Debugging code. See also debug.c
+ */
+
+/* mkproto.awk has trouble with ifdef'd function definitions (it ignores
+ * the #ifdef directive and will read both definitions, thus creating two
+ * diffferent prototype declarations), so we must do these by hand.
+ */
+#ifdef HAVE_STDARG_H
+int Debug1( char *, ... );
+BOOL dbgtext( char *, ... );
#else
-extern int syslog_level;
+int Debug1();
+BOOL dbgtext();
+#endif
-#define DEBUG(level,body) ((DEBUGLEVEL>=(level))? (syslog_level = (level), Debug1 body):0)
-#define DEBUGLVL(level) ( DEBUGLEVEL >= (syslog_level=(level)) )
+/* If we have these macros, we can add additional info to the header. */
+#ifdef HAVE_FILE_MACRO
+#define FILE_MACRO (__FILE__)
+#else
+#define FILE_MACRO ("")
#endif
+#ifdef HAVE_FUNCTION_MACRO
+#define FUNCTION_MACRO (__FUNCTION__)
+#else
+#define FUNCTION_MACRO ("")
+#endif
+
+/* Debugging macros.
+ * DEBUGLVL() - If level is <= the system-wide DEBUGLEVEL then generate a
+ * header using the default macros for file, line, and
+ * function name.
+ * Returns True if the debug level was <= DEBUGLEVEL.
+ * Example usage:
+ * if( DEBUGLVL( 2 ) )
+ * dbgtext( "Some text.\n" );
+ * DEGUG() - Good old DEBUG(). Each call to DEBUG() will generate a new
+ * header *unless* the previous debug output was unterminated
+ * (i.e., no '\n'). See debug.c:dbghdr() for more info.
+ * Example usage:
+ * DEBUG( 2, ("Some text.\n") );
+ * DEBUGADD() - If level <= DEBUGLEVEL, then the text is appended to the
+ * current message (i.e., no header).
+ * Usage:
+ * DEBUGADD( 2, ("Some additional text.\n") );
+ */
+#define DEBUGLVL( level ) \
+ ( (DEBUGLEVEL>=(level)) \
+ && dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) ) )
+
+#define DEBUG( level, body ) \
+ if( (DEBUGLEVEL>=(level)) \
+ && dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) ) ) \
+ (void)dbgtext body
+
+#define DEBUGADD( level, body ) \
+ if( DEBUGLEVEL>=(level) ) (void)dbgtext body
+
+/* End Debugging code section.
+ * -------------------------------------------------------------------------- **
+ */
+
/* this defines the error codes that receive_smb can put in smb_read_error */
#define READ_TIMEOUT 1
#define READ_EOF 2
@@ -1154,10 +1206,8 @@ struct parm_struct
#define ERRCMD 0xFF /* Command was not in the "SMB" format. */
#ifdef HAVE_STDARG_H
-int Debug1(char *, ...);
int slprintf(char *str, int n, char *format, ...);
#else
-int Debug1();
int slprintf();
#endif
diff --git a/source3/lib/util.c b/source3/lib/util.c
index e14211ebd7..0c9fa55d7d 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -38,7 +38,7 @@ extern int sslFd;
pstring scope = "";
-int DEBUGLEVEL = 1;
+extern int DEBUGLEVEL;
BOOL passive = False;
@@ -47,9 +47,6 @@ int Protocol = PROTOCOL_COREPLUS;
/* a default finfo structure to ensure all fields are sensible */
file_info def_finfo = {-1,0,0,0,0,0,0,""};
-/* these are some file handles where debug info will be stored */
-FILE *dbf = NULL;
-
/* the client file descriptor */
int Client = -1;
@@ -69,9 +66,6 @@ int trans_num = 0;
*/
int case_default = CASE_LOWER;
-pstring debugf = "";
-int syslog_level = 0;
-
/* the following control case operations - they are put here so the
client can link easily */
BOOL case_sensitive;
@@ -99,280 +93,9 @@ char **my_netbios_names;
int smb_read_error = 0;
-static BOOL stdout_logging = False;
-
static char *filename_dos(char *path,char *buf);
-#if defined(SIGUSR2)
-/******************************************************************************
- catch a sigusr2 - decrease the debug log level.
- *****************************************************************************/
-int sig_usr2(void)
-{
- BlockSignals( True, SIGUSR2);
-
- DEBUGLEVEL--;
-
- if(DEBUGLEVEL < 0)
- DEBUGLEVEL = 0;
-
- DEBUG( 0, ( "Got SIGUSR2 set debug level to %d.\n", DEBUGLEVEL ) );
-
- BlockSignals( False, SIGUSR2);
- CatchSignal(SIGUSR2, SIGNAL_CAST sig_usr2);
-
- return(0);
-}
-#endif /* SIGUSR1 */
-
-#if defined(SIGUSR1)
-/******************************************************************************
- catch a sigusr1 - increase the debug log level.
- *****************************************************************************/
-int sig_usr1(void)
-{
- BlockSignals( True, SIGUSR1);
-
- DEBUGLEVEL++;
-
- if(DEBUGLEVEL > 10)
- DEBUGLEVEL = 10;
-
- DEBUG( 0, ( "Got SIGUSR1 set debug level to %d.\n", DEBUGLEVEL ) );
-
- BlockSignals( False, SIGUSR1);
- CatchSignal(SIGUSR1, SIGNAL_CAST sig_usr1);
- return(0);
-}
-#endif /* SIGUSR1 */
-
-
-/*******************************************************************
- get ready for syslog stuff
- ******************************************************************/
-void setup_logging(char *pname,BOOL interactive)
-{
-#ifdef WITH_SYSLOG
- if (!interactive) {
- char *p = strrchr(pname,'/');
- if (p) pname = p+1;
-#ifdef LOG_DAEMON
- openlog(pname, LOG_PID, SYSLOG_FACILITY);
-#else /* for old systems that have no facility codes. */
- openlog(pname, LOG_PID);
-#endif
- }
-#endif
- if (interactive) {
- stdout_logging = True;
- dbf = stdout;
- }
-}
-
-
-BOOL append_log=False;
-
-
-/****************************************************************************
-reopen the log files
-****************************************************************************/
-void reopen_logs(void)
-{
- pstring fname;
-
- if (DEBUGLEVEL > 0)
- {
- pstrcpy(fname,debugf);
- if (lp_loaded() && (*lp_logfile()))
- pstrcpy(fname,lp_logfile());
-
- if (!strcsequal(fname,debugf) || !dbf || !file_exist(debugf,NULL))
- {
- int oldumask = umask(022);
- pstrcpy(debugf,fname);
- if (dbf)
- fclose(dbf);
- if (append_log)
- dbf = fopen(debugf,"a");
- else
- dbf = fopen(debugf,"w");
- /*
- * Fix from klausr@ITAP.Physik.Uni-Stuttgart.De
- * to fix problem where smbd's that generate less
- * than 100 messages keep growing the log.
- */
- force_check_log_size();
- if (dbf)
- setbuf(dbf,NULL);
- umask(oldumask);
- }
- }
- else
- {
- if (dbf)
- {
- fclose(dbf);
- dbf = NULL;
- }
- }
-}
-
-/*******************************************************************
- Number of debug messages that have been output.
- Used to check log size.
-********************************************************************/
-
-static int debug_count=0;
-
-/*******************************************************************
- Force a check of the log size.
-********************************************************************/
-void force_check_log_size(void)
-{
- debug_count = 100;
-}
-
-/*******************************************************************
- Check if the log has grown too big
-********************************************************************/
-
-static void check_log_size(void)
-{
- int maxlog;
- struct stat st;
-
- if (debug_count++ < 100 || getuid() != 0)
- return;
-
- maxlog = lp_max_log_size() * 1024;
- if (!dbf || maxlog <= 0)
- return;
-
- if (fstat(fileno(dbf),&st) == 0 && st.st_size > maxlog) {
- fclose(dbf);
- dbf = NULL;
- reopen_logs();
- if (dbf && file_size(debugf) > maxlog) {
- pstring name;
- fclose(dbf);
- dbf = NULL;
- slprintf(name,sizeof(name)-1,"%s.old",debugf);
- rename(debugf,name);
- reopen_logs();
- }
- }
- debug_count=0;
-}
-
-
-/*******************************************************************
-write an debug message on the debugfile. This is called by the DEBUG
-macro
-********************************************************************/
-#ifdef HAVE_STDARG_H
- int Debug1(char *format_str, ...)
-{
-#else
- int Debug1(va_alist)
-va_dcl
-{
- char *format_str;
-#endif
- va_list ap;
- int old_errno = errno;
-
- if (stdout_logging) {
-#ifdef HAVE_STDARG_H
- va_start(ap, format_str);
-#else
- va_start(ap);
- format_str = va_arg(ap,char *);
-#endif
- vfprintf(dbf,format_str,ap);
- va_end(ap);
- errno = old_errno;
- return(0);
- }
-
-#ifdef WITH_SYSLOG
- if (!lp_syslog_only())
-#endif
- {
- if (!dbf) {
- int oldumask = umask(022);
- if(append_log)
- dbf = fopen(debugf,"a");
- else
- dbf = fopen(debugf,"w");
- umask(oldumask);
- if (dbf) {
- setbuf(dbf,NULL);
- } else {
- errno = old_errno;
- return(0);
- }
- }
- }
-
-#ifdef WITH_SYSLOG
- if (syslog_level < lp_syslog())
- {
- /*
- * map debug levels to syslog() priorities
- * note that not all DEBUG(0, ...) calls are
- * necessarily errors
- */
- static int priority_map[] = {
- LOG_ERR, /* 0 */
- LOG_WARNING, /* 1 */
- LOG_NOTICE, /* 2 */
- LOG_INFO, /* 3 */
- };
- int priority;
- pstring msgbuf;
-
- if (syslog_level >= sizeof(priority_map) / sizeof(priority_map[0]) ||
- syslog_level < 0)
- priority = LOG_DEBUG;
- else
- priority = priority_map[syslog_level];
-
-#ifdef HAVE_STDARG_H
- va_start(ap, format_str);
-#else
- va_start(ap);
- format_str = va_arg(ap,char *);
-#endif
- vslprintf(msgbuf, sizeof(msgbuf)-1,format_str, ap);
- va_end(ap);
-
- msgbuf[255] = '\0';
- syslog(priority, "%s", msgbuf);
- }
-#endif
-
-#ifdef WITH_SYSLOG
- if (!lp_syslog_only())
-#endif
- {
-#ifdef HAVE_STDARG_H
- va_start(ap, format_str);
-#else
- va_start(ap);
- format_str = va_arg(ap,char *);
-#endif
- vfprintf(dbf,format_str,ap);
- va_end(ap);
- fflush(dbf);
- }
-
- check_log_size();
-
- errno = old_errno;
-
- return(0);
-}
/****************************************************************************
find a suitable temporary directory. The result should be copied immediately