2001-12-11 22:53:04 +01:00
|
|
|
/*
|
|
|
|
* ngIRCd -- The Next Generation IRC Daemon
|
2002-01-02 03:42:58 +01:00
|
|
|
* Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
|
2001-12-11 22:53:04 +01:00
|
|
|
*
|
|
|
|
* Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen
|
|
|
|
* der GNU General Public License (GPL), wie von der Free Software Foundation
|
|
|
|
* herausgegeben, weitergeben und/oder modifizieren, entweder unter Version 2
|
|
|
|
* der Lizenz oder (wenn Sie es wuenschen) jeder spaeteren Version.
|
|
|
|
* Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
|
2001-12-31 03:18:51 +01:00
|
|
|
* der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
|
2001-12-11 22:53:04 +01:00
|
|
|
*
|
2002-03-30 00:58:10 +01:00
|
|
|
* $Id: log.c,v 1.30 2002/03/29 23:58:10 alex Exp $
|
2001-12-11 22:53:04 +01:00
|
|
|
*
|
|
|
|
* log.c: Logging-Funktionen
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2002-03-12 15:37:51 +01:00
|
|
|
#include "portab.h"
|
2001-12-11 22:53:04 +01:00
|
|
|
|
2002-03-12 15:37:51 +01:00
|
|
|
#include "imp.h"
|
2001-12-11 22:53:04 +01:00
|
|
|
#include <assert.h>
|
2002-03-06 16:36:04 +01:00
|
|
|
#include <errno.h>
|
2001-12-11 22:53:04 +01:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
2001-12-26 04:22:16 +01:00
|
|
|
#include <string.h>
|
2002-03-06 16:36:04 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
2001-12-27 02:44:49 +01:00
|
|
|
|
|
|
|
#ifdef USE_SYSLOG
|
2001-12-13 00:31:24 +01:00
|
|
|
#include <syslog.h>
|
2001-12-27 02:44:49 +01:00
|
|
|
#endif
|
2001-12-11 22:53:04 +01:00
|
|
|
|
2002-01-11 15:45:37 +01:00
|
|
|
#include "ngircd.h"
|
2002-03-27 21:53:30 +01:00
|
|
|
#include "client.h"
|
2002-03-12 15:37:51 +01:00
|
|
|
#include "defines.h"
|
2002-03-27 21:53:30 +01:00
|
|
|
#include "irc-write.h"
|
2002-01-11 15:45:37 +01:00
|
|
|
|
2002-03-12 15:37:51 +01:00
|
|
|
#include "exp.h"
|
2001-12-11 22:53:04 +01:00
|
|
|
#include "log.h"
|
|
|
|
|
|
|
|
|
2002-03-29 21:59:22 +01:00
|
|
|
LOCAL CHAR Error_File[FNAME_LEN];
|
2002-03-30 00:33:42 +01:00
|
|
|
LOCAL CHAR Init_Txt[127];
|
2002-03-29 21:59:22 +01:00
|
|
|
|
|
|
|
|
2002-03-27 21:53:30 +01:00
|
|
|
LOCAL VOID Wall_ServerNotice( CHAR *Msg );
|
|
|
|
|
|
|
|
|
2001-12-11 22:53:04 +01:00
|
|
|
GLOBAL VOID Log_Init( VOID )
|
|
|
|
{
|
2001-12-27 02:44:49 +01:00
|
|
|
#ifdef USE_SYSLOG
|
2002-02-19 21:07:13 +01:00
|
|
|
/* Syslog initialisieren */
|
2001-12-25 20:20:39 +01:00
|
|
|
openlog( PACKAGE, LOG_CONS|LOG_PID, LOG_LOCAL5 );
|
2001-12-27 02:44:49 +01:00
|
|
|
#endif
|
2002-02-19 21:07:13 +01:00
|
|
|
|
|
|
|
/* Hello World! */
|
2002-01-11 15:45:37 +01:00
|
|
|
Log( LOG_NOTICE, "%s started.", NGIRCd_Version( ));
|
2002-03-06 16:36:04 +01:00
|
|
|
|
2002-02-19 21:07:13 +01:00
|
|
|
/* Informationen uebern den "Operation Mode" */
|
2002-03-30 00:33:42 +01:00
|
|
|
strcpy( Init_Txt, "" );
|
2002-02-19 21:07:13 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
if( NGIRCd_Debug )
|
|
|
|
{
|
2002-03-30 00:33:42 +01:00
|
|
|
if( Init_Txt[0] ) strcat( Init_Txt, ", " );
|
|
|
|
strcat( Init_Txt, "debug-mode" );
|
2002-02-19 21:07:13 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if( NGIRCd_NoDaemon )
|
|
|
|
{
|
2002-03-30 00:33:42 +01:00
|
|
|
if( Init_Txt[0] ) strcat( Init_Txt, ", " );
|
|
|
|
strcat( Init_Txt, "no-daemon-mode" );
|
2002-02-19 21:07:13 +01:00
|
|
|
}
|
|
|
|
if( NGIRCd_Passive )
|
|
|
|
{
|
2002-03-30 00:33:42 +01:00
|
|
|
if( Init_Txt[0] ) strcat( Init_Txt, ", " );
|
|
|
|
strcat( Init_Txt, "passive-mode" );
|
2002-02-19 21:07:13 +01:00
|
|
|
}
|
|
|
|
#ifdef SNIFFER
|
|
|
|
if( NGIRCd_Sniffer )
|
|
|
|
{
|
2002-03-30 00:33:42 +01:00
|
|
|
if( Init_Txt[0] ) strcat( Init_Txt, ", " );
|
|
|
|
strcat( Init_Txt, "network sniffer" );
|
2002-02-19 21:07:13 +01:00
|
|
|
}
|
|
|
|
#endif
|
2002-03-30 00:33:42 +01:00
|
|
|
if( Init_Txt[0] ) Log( LOG_INFO, "Activating: %s.", Init_Txt );
|
|
|
|
} /* Log_Init */
|
2002-03-06 16:36:04 +01:00
|
|
|
|
2002-03-30 00:33:42 +01:00
|
|
|
|
|
|
|
GLOBAL VOID Log_InitErrorfile( VOID )
|
|
|
|
{
|
2002-03-29 23:55:42 +01:00
|
|
|
/* "Error-Log" initialisieren: stderr in Datei umlenken. Dort
|
|
|
|
* landen z.B. alle Ausgaben von assert()-Aufrufen. */
|
2002-03-30 00:33:42 +01:00
|
|
|
|
2002-03-06 16:36:04 +01:00
|
|
|
fflush( stderr );
|
2002-03-29 23:55:42 +01:00
|
|
|
sprintf( Error_File, ERROR_DIR"/"PACKAGE"-%ld.err", (INT32)getpid( ));
|
|
|
|
if( ! freopen( Error_File, "w", stderr ))
|
|
|
|
{
|
|
|
|
Log( LOG_ERR, "Can't reopen stderr (\"%s\"): %s", Error_File, strerror( errno ));
|
|
|
|
return;
|
|
|
|
}
|
2002-03-06 16:36:04 +01:00
|
|
|
|
2002-03-30 00:58:10 +01:00
|
|
|
fputs( ctime( &NGIRCd_Start ), stderr );
|
2002-03-29 23:55:42 +01:00
|
|
|
fprintf( stderr, "%s started.\n", NGIRCd_Version( ));
|
2002-03-30 00:33:42 +01:00
|
|
|
fprintf( stderr, "Activating: %s\n\n", Init_Txt[0] ? Init_Txt : "-" );
|
2002-03-06 16:36:04 +01:00
|
|
|
fflush( stderr );
|
2002-03-30 00:33:42 +01:00
|
|
|
} /* Log_InitErrfile */
|
2001-12-11 22:53:04 +01:00
|
|
|
|
|
|
|
|
|
|
|
GLOBAL VOID Log_Exit( VOID )
|
|
|
|
{
|
2002-02-19 21:07:13 +01:00
|
|
|
/* Good Bye! */
|
2001-12-15 01:07:56 +01:00
|
|
|
Log( LOG_NOTICE, PACKAGE" done.");
|
2002-03-21 13:00:23 +01:00
|
|
|
|
2002-03-29 21:59:22 +01:00
|
|
|
/* Error-File (stderr) loeschen */
|
|
|
|
if( unlink( Error_File ) != 0 ) Log( LOG_ERR, "Can't delete \"%s\": %s", Error_File, strerror( errno ));
|
|
|
|
|
2001-12-27 02:44:49 +01:00
|
|
|
#ifdef USE_SYSLOG
|
2002-02-19 21:07:13 +01:00
|
|
|
/* syslog abmelden */
|
2001-12-13 00:31:24 +01:00
|
|
|
closelog( );
|
2001-12-27 02:44:49 +01:00
|
|
|
#endif
|
2001-12-11 22:53:04 +01:00
|
|
|
} /* Log_Exit */
|
|
|
|
|
|
|
|
|
2002-03-27 21:53:30 +01:00
|
|
|
GLOBAL VOID Log( INT Level, CONST CHAR *Format, ... )
|
2001-12-11 22:53:04 +01:00
|
|
|
{
|
|
|
|
/* Eintrag in Logfile(s) schreiben */
|
|
|
|
|
|
|
|
CHAR msg[MAX_LOG_MSG_LEN];
|
2002-03-27 21:53:30 +01:00
|
|
|
BOOLEAN snotice;
|
2001-12-11 22:53:04 +01:00
|
|
|
va_list ap;
|
|
|
|
|
2001-12-29 21:16:31 +01:00
|
|
|
assert( Format != NULL );
|
|
|
|
|
2002-03-27 21:53:30 +01:00
|
|
|
if( Level & LOG_snotice )
|
|
|
|
{
|
|
|
|
/* Notice an User mit "s" Mode */
|
|
|
|
snotice = TRUE;
|
|
|
|
Level &= ~LOG_snotice;
|
|
|
|
}
|
2002-03-29 23:55:42 +01:00
|
|
|
else snotice = FALSE;
|
2002-03-27 21:53:30 +01:00
|
|
|
|
2002-01-11 15:45:37 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
if(( Level == LOG_DEBUG ) && ( ! NGIRCd_Debug )) return;
|
|
|
|
#else
|
2001-12-25 23:04:26 +01:00
|
|
|
if( Level == LOG_DEBUG ) return;
|
|
|
|
#endif
|
|
|
|
|
2001-12-11 22:53:04 +01:00
|
|
|
/* String mit variablen Argumenten zusammenbauen ... */
|
|
|
|
va_start( ap, Format );
|
2002-03-03 18:17:01 +01:00
|
|
|
vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
|
|
|
|
va_end( ap );
|
2001-12-11 22:53:04 +01:00
|
|
|
|
2002-03-27 21:53:30 +01:00
|
|
|
/* Konsole */
|
2002-01-11 15:45:37 +01:00
|
|
|
if( NGIRCd_NoDaemon ) printf( "[%d] %s\n", Level, msg );
|
2002-03-06 16:36:04 +01:00
|
|
|
|
2001-12-27 02:44:49 +01:00
|
|
|
#ifdef USE_SYSLOG
|
2002-03-06 16:36:04 +01:00
|
|
|
/* Syslog */
|
2001-12-13 00:31:24 +01:00
|
|
|
syslog( Level, msg );
|
2001-12-27 02:44:49 +01:00
|
|
|
#endif
|
2002-03-27 21:53:30 +01:00
|
|
|
|
|
|
|
/* lokale User mit "s"-Mode */
|
|
|
|
if( snotice ) Wall_ServerNotice( msg );
|
2001-12-11 22:53:04 +01:00
|
|
|
} /* Log */
|
|
|
|
|
|
|
|
|
2001-12-29 21:16:31 +01:00
|
|
|
GLOBAL VOID Log_Init_Resolver( VOID )
|
|
|
|
{
|
|
|
|
#ifdef USE_SYSLOG
|
|
|
|
openlog( PACKAGE, LOG_CONS|LOG_PID, LOG_LOCAL5 );
|
|
|
|
#endif
|
|
|
|
} /* Log_Init_Resolver */
|
|
|
|
|
|
|
|
|
|
|
|
GLOBAL VOID Log_Exit_Resolver( VOID )
|
|
|
|
{
|
|
|
|
#ifdef USE_SYSLOG
|
|
|
|
closelog( );
|
|
|
|
#endif
|
|
|
|
} /* Log_Exit_Resolver */
|
|
|
|
|
|
|
|
|
|
|
|
GLOBAL VOID Log_Resolver( CONST INT Level, CONST CHAR *Format, ... )
|
|
|
|
{
|
|
|
|
/* Eintrag des Resolver in Logfile(s) schreiben */
|
|
|
|
|
2002-01-05 16:54:40 +01:00
|
|
|
#ifndef USE_SYSLOG
|
|
|
|
return;
|
|
|
|
#else
|
|
|
|
|
2001-12-29 21:16:31 +01:00
|
|
|
CHAR msg[MAX_LOG_MSG_LEN];
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
assert( Format != NULL );
|
|
|
|
|
2002-01-11 15:45:37 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
if(( Level == LOG_DEBUG ) && ( ! NGIRCd_Debug )) return;
|
|
|
|
#else
|
2001-12-29 21:16:31 +01:00
|
|
|
if( Level == LOG_DEBUG ) return;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* String mit variablen Argumenten zusammenbauen ... */
|
|
|
|
va_start( ap, Format );
|
2002-03-03 18:17:01 +01:00
|
|
|
vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
|
|
|
|
va_end( ap );
|
2001-12-29 21:16:31 +01:00
|
|
|
|
|
|
|
/* ... und ausgeben */
|
|
|
|
syslog( Level, msg );
|
|
|
|
|
2002-01-05 16:54:40 +01:00
|
|
|
#endif
|
2001-12-29 21:16:31 +01:00
|
|
|
} /* Log_Resolver */
|
|
|
|
|
|
|
|
|
2002-03-27 21:53:30 +01:00
|
|
|
LOCAL VOID Wall_ServerNotice( CHAR *Msg )
|
|
|
|
{
|
2002-03-29 23:55:42 +01:00
|
|
|
/* Server-Notice an entsprechende User verschicken */
|
|
|
|
|
2002-03-27 21:53:30 +01:00
|
|
|
CLIENT *c;
|
|
|
|
|
|
|
|
assert( Msg != NULL );
|
2002-03-29 23:55:42 +01:00
|
|
|
|
2002-03-27 21:53:30 +01:00
|
|
|
c = Client_First( );
|
|
|
|
while( c )
|
|
|
|
{
|
2002-03-27 22:03:09 +01:00
|
|
|
if(( Client_Conn( c ) > NONE ) && ( Client_HasMode( c, 's' ))) IRC_WriteStrClient( c, "NOTICE %s :%s", Client_ThisServer( ), Msg );
|
2002-03-27 21:53:30 +01:00
|
|
|
c = Client_Next( c );
|
|
|
|
}
|
|
|
|
} /* Wall_ServerNotice */
|
|
|
|
|
|
|
|
|
2001-12-11 22:53:04 +01:00
|
|
|
/* -eof- */
|