Blame


1 f4ade537 2001-12-11 alex /*
2 f4ade537 2001-12-11 alex * ngIRCd -- The Next Generation IRC Daemon
3 1547f76c 2002-01-02 alex * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
4 f4ade537 2001-12-11 alex *
5 f4ade537 2001-12-11 alex * Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen
6 f4ade537 2001-12-11 alex * der GNU General Public License (GPL), wie von der Free Software Foundation
7 f4ade537 2001-12-11 alex * herausgegeben, weitergeben und/oder modifizieren, entweder unter Version 2
8 f4ade537 2001-12-11 alex * der Lizenz oder (wenn Sie es wuenschen) jeder spaeteren Version.
9 f4ade537 2001-12-11 alex * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
10 804b1ec4 2001-12-31 alex * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
11 f4ade537 2001-12-11 alex *
12 d040fa2a 2002-09-09 alex * $Id: log.c,v 1.37 2002/09/09 22:55:21 alex Exp $
13 f4ade537 2001-12-11 alex *
14 f4ade537 2001-12-11 alex * log.c: Logging-Funktionen
15 f4ade537 2001-12-11 alex */
16 f4ade537 2001-12-11 alex
17 f4ade537 2001-12-11 alex
18 ca33cbda 2002-03-12 alex #include "portab.h"
19 f4ade537 2001-12-11 alex
20 ca33cbda 2002-03-12 alex #include "imp.h"
21 f4ade537 2001-12-11 alex #include <assert.h>
22 fe2bc90e 2002-03-06 alex #include <errno.h>
23 f4ade537 2001-12-11 alex #include <stdarg.h>
24 f4ade537 2001-12-11 alex #include <stdio.h>
25 3be92e9d 2001-12-26 alex #include <string.h>
26 fe2bc90e 2002-03-06 alex #include <sys/types.h>
27 fe2bc90e 2002-03-06 alex #include <unistd.h>
28 50352dc9 2001-12-27 alex
29 50352dc9 2001-12-27 alex #ifdef USE_SYSLOG
30 3d1a0962 2001-12-12 alex #include <syslog.h>
31 50352dc9 2001-12-27 alex #endif
32 f4ade537 2001-12-11 alex
33 006c0328 2002-01-11 alex #include "ngircd.h"
34 ca33cbda 2002-03-12 alex #include "defines.h"
35 c2f60abe 2002-05-27 alex #include "conn.h"
36 c2f60abe 2002-05-27 alex #include "client.h"
37 c2f60abe 2002-05-27 alex #include "channel.h"
38 20a2ffef 2002-03-27 alex #include "irc-write.h"
39 006c0328 2002-01-11 alex
40 ca33cbda 2002-03-12 alex #include "exp.h"
41 f4ade537 2001-12-11 alex #include "log.h"
42 f4ade537 2001-12-11 alex
43 f4ade537 2001-12-11 alex
44 1c00ddff 2002-03-29 alex LOCAL CHAR Error_File[FNAME_LEN];
45 3d74a9c3 2002-03-29 alex LOCAL CHAR Init_Txt[127];
46 1c00ddff 2002-03-29 alex
47 1c00ddff 2002-03-29 alex
48 c2f60abe 2002-05-27 alex LOCAL VOID Wall_ServerNotice PARAMS(( CHAR *Msg ));
49 20a2ffef 2002-03-27 alex
50 20a2ffef 2002-03-27 alex
51 c2f60abe 2002-05-27 alex GLOBAL VOID
52 c2f60abe 2002-05-27 alex Log_Init( VOID )
53 f4ade537 2001-12-11 alex {
54 50352dc9 2001-12-27 alex #ifdef USE_SYSLOG
55 fcb47ae6 2002-02-19 alex /* Syslog initialisieren */
56 0dc0308d 2001-12-25 alex openlog( PACKAGE, LOG_CONS|LOG_PID, LOG_LOCAL5 );
57 50352dc9 2001-12-27 alex #endif
58 fcb47ae6 2002-02-19 alex
59 fcb47ae6 2002-02-19 alex /* Hello World! */
60 006c0328 2002-01-11 alex Log( LOG_NOTICE, "%s started.", NGIRCd_Version( ));
61 fe2bc90e 2002-03-06 alex
62 fcb47ae6 2002-02-19 alex /* Informationen uebern den "Operation Mode" */
63 3d74a9c3 2002-03-29 alex strcpy( Init_Txt, "" );
64 fcb47ae6 2002-02-19 alex #ifdef DEBUG
65 fcb47ae6 2002-02-19 alex if( NGIRCd_Debug )
66 fcb47ae6 2002-02-19 alex {
67 3d74a9c3 2002-03-29 alex if( Init_Txt[0] ) strcat( Init_Txt, ", " );
68 3d74a9c3 2002-03-29 alex strcat( Init_Txt, "debug-mode" );
69 fcb47ae6 2002-02-19 alex }
70 fcb47ae6 2002-02-19 alex #endif
71 fcb47ae6 2002-02-19 alex if( NGIRCd_NoDaemon )
72 fcb47ae6 2002-02-19 alex {
73 3d74a9c3 2002-03-29 alex if( Init_Txt[0] ) strcat( Init_Txt, ", " );
74 3d74a9c3 2002-03-29 alex strcat( Init_Txt, "no-daemon-mode" );
75 fcb47ae6 2002-02-19 alex }
76 fcb47ae6 2002-02-19 alex if( NGIRCd_Passive )
77 fcb47ae6 2002-02-19 alex {
78 3d74a9c3 2002-03-29 alex if( Init_Txt[0] ) strcat( Init_Txt, ", " );
79 3d74a9c3 2002-03-29 alex strcat( Init_Txt, "passive-mode" );
80 fcb47ae6 2002-02-19 alex }
81 fcb47ae6 2002-02-19 alex #ifdef SNIFFER
82 fcb47ae6 2002-02-19 alex if( NGIRCd_Sniffer )
83 fcb47ae6 2002-02-19 alex {
84 3d74a9c3 2002-03-29 alex if( Init_Txt[0] ) strcat( Init_Txt, ", " );
85 3d74a9c3 2002-03-29 alex strcat( Init_Txt, "network sniffer" );
86 fcb47ae6 2002-02-19 alex }
87 fcb47ae6 2002-02-19 alex #endif
88 3d74a9c3 2002-03-29 alex if( Init_Txt[0] ) Log( LOG_INFO, "Activating: %s.", Init_Txt );
89 3d74a9c3 2002-03-29 alex } /* Log_Init */
90 fe2bc90e 2002-03-06 alex
91 3d74a9c3 2002-03-29 alex
92 c2f60abe 2002-05-27 alex GLOBAL VOID
93 c2f60abe 2002-05-27 alex Log_InitErrorfile( VOID )
94 3d74a9c3 2002-03-29 alex {
95 773d886d 2002-03-29 alex /* "Error-Log" initialisieren: stderr in Datei umlenken. Dort
96 773d886d 2002-03-29 alex * landen z.B. alle Ausgaben von assert()-Aufrufen. */
97 3d74a9c3 2002-03-29 alex
98 b58ab32b 2002-03-31 alex /* Dateiname zusammen bauen */
99 f7327524 2002-05-30 alex sprintf( Error_File, "%s/%s-%ld.err", ERROR_DIR, PACKAGE, (INT32)getpid( ));
100 b58ab32b 2002-03-31 alex
101 b58ab32b 2002-03-31 alex /* stderr umlenken */
102 b58ab32b 2002-03-31 alex fflush( stderr );
103 773d886d 2002-03-29 alex if( ! freopen( Error_File, "w", stderr ))
104 773d886d 2002-03-29 alex {
105 773d886d 2002-03-29 alex Log( LOG_ERR, "Can't reopen stderr (\"%s\"): %s", Error_File, strerror( errno ));
106 773d886d 2002-03-29 alex return;
107 773d886d 2002-03-29 alex }
108 fe2bc90e 2002-03-06 alex
109 b58ab32b 2002-03-31 alex /* Einige Infos in das Error-File schreiben */
110 d68fb7a3 2002-03-29 alex fputs( ctime( &NGIRCd_Start ), stderr );
111 773d886d 2002-03-29 alex fprintf( stderr, "%s started.\n", NGIRCd_Version( ));
112 3d74a9c3 2002-03-29 alex fprintf( stderr, "Activating: %s\n\n", Init_Txt[0] ? Init_Txt : "-" );
113 fe2bc90e 2002-03-06 alex fflush( stderr );
114 b58ab32b 2002-03-31 alex
115 b58ab32b 2002-03-31 alex Log( LOG_DEBUG, "Redirected stderr to \"%s\".", Error_File );
116 3d74a9c3 2002-03-29 alex } /* Log_InitErrfile */
117 f4ade537 2001-12-11 alex
118 f4ade537 2001-12-11 alex
119 c2f60abe 2002-05-27 alex GLOBAL VOID
120 c2f60abe 2002-05-27 alex Log_Exit( VOID )
121 f4ade537 2001-12-11 alex {
122 fcb47ae6 2002-02-19 alex /* Good Bye! */
123 5cac5404 2002-06-02 alex if( NGIRCd_Restart ) Log( LOG_NOTICE, "%s done (restarting).", PACKAGE );
124 5cac5404 2002-06-02 alex else Log( LOG_NOTICE, "%s done.", PACKAGE );
125 b9a2c4a8 2002-03-21 alex
126 1c00ddff 2002-03-29 alex /* Error-File (stderr) loeschen */
127 1c00ddff 2002-03-29 alex if( unlink( Error_File ) != 0 ) Log( LOG_ERR, "Can't delete \"%s\": %s", Error_File, strerror( errno ));
128 1c00ddff 2002-03-29 alex
129 50352dc9 2001-12-27 alex #ifdef USE_SYSLOG
130 fcb47ae6 2002-02-19 alex /* syslog abmelden */
131 3d1a0962 2001-12-12 alex closelog( );
132 50352dc9 2001-12-27 alex #endif
133 f4ade537 2001-12-11 alex } /* Log_Exit */
134 f4ade537 2001-12-11 alex
135 f4ade537 2001-12-11 alex
136 f7327524 2002-05-30 alex #ifdef PROTOTYPES
137 c2f60abe 2002-05-27 alex GLOBAL VOID
138 c2f60abe 2002-05-27 alex Log( INT Level, CONST CHAR *Format, ... )
139 f7327524 2002-05-30 alex #else
140 f7327524 2002-05-30 alex GLOBAL VOID
141 f7327524 2002-05-30 alex Log( Level, Format, va_alist )
142 f7327524 2002-05-30 alex INT Level;
143 f7327524 2002-05-30 alex CONST CHAR *Format;
144 f7327524 2002-05-30 alex va_dcl
145 f7327524 2002-05-30 alex #endif
146 f4ade537 2001-12-11 alex {
147 f4ade537 2001-12-11 alex /* Eintrag in Logfile(s) schreiben */
148 f4ade537 2001-12-11 alex
149 f4ade537 2001-12-11 alex CHAR msg[MAX_LOG_MSG_LEN];
150 20a2ffef 2002-03-27 alex BOOLEAN snotice;
151 f4ade537 2001-12-11 alex va_list ap;
152 f4ade537 2001-12-11 alex
153 ec1922ef 2001-12-29 alex assert( Format != NULL );
154 ec1922ef 2001-12-29 alex
155 20a2ffef 2002-03-27 alex if( Level & LOG_snotice )
156 20a2ffef 2002-03-27 alex {
157 20a2ffef 2002-03-27 alex /* Notice an User mit "s" Mode */
158 20a2ffef 2002-03-27 alex snotice = TRUE;
159 20a2ffef 2002-03-27 alex Level &= ~LOG_snotice;
160 20a2ffef 2002-03-27 alex }
161 773d886d 2002-03-29 alex else snotice = FALSE;
162 20a2ffef 2002-03-27 alex
163 006c0328 2002-01-11 alex #ifdef DEBUG
164 006c0328 2002-01-11 alex if(( Level == LOG_DEBUG ) && ( ! NGIRCd_Debug )) return;
165 006c0328 2002-01-11 alex #else
166 d4a60bd4 2001-12-25 alex if( Level == LOG_DEBUG ) return;
167 d4a60bd4 2001-12-25 alex #endif
168 d4a60bd4 2001-12-25 alex
169 f4ade537 2001-12-11 alex /* String mit variablen Argumenten zusammenbauen ... */
170 f7327524 2002-05-30 alex #ifdef PROTOTYPES
171 f4ade537 2001-12-11 alex va_start( ap, Format );
172 f7327524 2002-05-30 alex #else
173 f7327524 2002-05-30 alex va_start( ap );
174 f7327524 2002-05-30 alex #endif
175 10363b39 2002-03-03 alex vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
176 10363b39 2002-03-03 alex va_end( ap );
177 f4ade537 2001-12-11 alex
178 bebf0383 2002-03-30 alex if( NGIRCd_NoDaemon )
179 bebf0383 2002-03-30 alex {
180 bebf0383 2002-03-30 alex /* auf Konsole ausgeben */
181 40ebd470 2002-09-03 alex fprintf( stdout, "[%d] %s\n", Level, msg );
182 40ebd470 2002-09-03 alex fflush( stdout );
183 d040fa2a 2002-09-09 alex }
184 d040fa2a 2002-09-09 alex #ifdef USE_SYSLOG
185 d040fa2a 2002-09-09 alex else
186 d040fa2a 2002-09-09 alex {
187 d040fa2a 2002-09-09 alex /* Syslog */
188 d040fa2a 2002-09-09 alex syslog( Level, msg );
189 bebf0383 2002-03-30 alex }
190 d040fa2a 2002-09-09 alex #endif
191 fe2bc90e 2002-03-06 alex
192 bebf0383 2002-03-30 alex if( Level <= LOG_CRIT )
193 bebf0383 2002-03-30 alex {
194 bebf0383 2002-03-30 alex /* Kritische Meldungen in Error-File (stderr) */
195 bebf0383 2002-03-30 alex fprintf( stderr, "%s\n", msg );
196 bebf0383 2002-03-30 alex fflush( stderr );
197 bebf0383 2002-03-30 alex }
198 bebf0383 2002-03-30 alex
199 bebf0383 2002-03-30 alex if( snotice )
200 bebf0383 2002-03-30 alex {
201 bebf0383 2002-03-30 alex /* NOTICE an lokale User mit "s"-Mode */
202 bebf0383 2002-03-30 alex Wall_ServerNotice( msg );
203 bebf0383 2002-03-30 alex }
204 f4ade537 2001-12-11 alex } /* Log */
205 f4ade537 2001-12-11 alex
206 f4ade537 2001-12-11 alex
207 c2f60abe 2002-05-27 alex GLOBAL VOID
208 c2f60abe 2002-05-27 alex Log_Init_Resolver( VOID )
209 ec1922ef 2001-12-29 alex {
210 ec1922ef 2001-12-29 alex #ifdef USE_SYSLOG
211 ec1922ef 2001-12-29 alex openlog( PACKAGE, LOG_CONS|LOG_PID, LOG_LOCAL5 );
212 ec1922ef 2001-12-29 alex #endif
213 ec1922ef 2001-12-29 alex } /* Log_Init_Resolver */
214 ec1922ef 2001-12-29 alex
215 ec1922ef 2001-12-29 alex
216 c2f60abe 2002-05-27 alex GLOBAL VOID
217 c2f60abe 2002-05-27 alex Log_Exit_Resolver( VOID )
218 ec1922ef 2001-12-29 alex {
219 ec1922ef 2001-12-29 alex #ifdef USE_SYSLOG
220 ec1922ef 2001-12-29 alex closelog( );
221 ec1922ef 2001-12-29 alex #endif
222 ec1922ef 2001-12-29 alex } /* Log_Exit_Resolver */
223 ec1922ef 2001-12-29 alex
224 ec1922ef 2001-12-29 alex
225 f7327524 2002-05-30 alex #ifdef PROTOTYPES
226 c2f60abe 2002-05-27 alex GLOBAL VOID
227 c2f60abe 2002-05-27 alex Log_Resolver( CONST INT Level, CONST CHAR *Format, ... )
228 f7327524 2002-05-30 alex #else
229 f7327524 2002-05-30 alex GLOBAL VOID
230 f7327524 2002-05-30 alex Log_Resolver( Level, Format, va_alist )
231 f7327524 2002-05-30 alex CONST INT Level;
232 f7327524 2002-05-30 alex CONST CHAR *Format;
233 f7327524 2002-05-30 alex va_dcl
234 f7327524 2002-05-30 alex #endif
235 ec1922ef 2001-12-29 alex {
236 ec1922ef 2001-12-29 alex /* Eintrag des Resolver in Logfile(s) schreiben */
237 ec1922ef 2001-12-29 alex
238 03783eea 2002-01-05 alex #ifndef USE_SYSLOG
239 03783eea 2002-01-05 alex return;
240 03783eea 2002-01-05 alex #else
241 03783eea 2002-01-05 alex
242 ec1922ef 2001-12-29 alex CHAR msg[MAX_LOG_MSG_LEN];
243 ec1922ef 2001-12-29 alex va_list ap;
244 ec1922ef 2001-12-29 alex
245 ec1922ef 2001-12-29 alex assert( Format != NULL );
246 ec1922ef 2001-12-29 alex
247 d040fa2a 2002-09-09 alex if( NGIRCd_NoDaemon ) return;
248 d040fa2a 2002-09-09 alex
249 006c0328 2002-01-11 alex #ifdef DEBUG
250 006c0328 2002-01-11 alex if(( Level == LOG_DEBUG ) && ( ! NGIRCd_Debug )) return;
251 006c0328 2002-01-11 alex #else
252 ec1922ef 2001-12-29 alex if( Level == LOG_DEBUG ) return;
253 ec1922ef 2001-12-29 alex #endif
254 ec1922ef 2001-12-29 alex
255 ec1922ef 2001-12-29 alex /* String mit variablen Argumenten zusammenbauen ... */
256 f7327524 2002-05-30 alex #ifdef PROTOTYPES
257 ec1922ef 2001-12-29 alex va_start( ap, Format );
258 f7327524 2002-05-30 alex #else
259 f7327524 2002-05-30 alex va_start( ap );
260 f7327524 2002-05-30 alex #endif
261 10363b39 2002-03-03 alex vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
262 10363b39 2002-03-03 alex va_end( ap );
263 ec1922ef 2001-12-29 alex
264 ec1922ef 2001-12-29 alex /* ... und ausgeben */
265 ec1922ef 2001-12-29 alex syslog( Level, msg );
266 ec1922ef 2001-12-29 alex
267 03783eea 2002-01-05 alex #endif
268 ec1922ef 2001-12-29 alex } /* Log_Resolver */
269 ec1922ef 2001-12-29 alex
270 ec1922ef 2001-12-29 alex
271 c2f60abe 2002-05-27 alex LOCAL VOID
272 c2f60abe 2002-05-27 alex Wall_ServerNotice( CHAR *Msg )
273 20a2ffef 2002-03-27 alex {
274 773d886d 2002-03-29 alex /* Server-Notice an entsprechende User verschicken */
275 773d886d 2002-03-29 alex
276 20a2ffef 2002-03-27 alex CLIENT *c;
277 20a2ffef 2002-03-27 alex
278 20a2ffef 2002-03-27 alex assert( Msg != NULL );
279 773d886d 2002-03-29 alex
280 20a2ffef 2002-03-27 alex c = Client_First( );
281 20a2ffef 2002-03-27 alex while( c )
282 20a2ffef 2002-03-27 alex {
283 da8da1ce 2002-03-27 alex if(( Client_Conn( c ) > NONE ) && ( Client_HasMode( c, 's' ))) IRC_WriteStrClient( c, "NOTICE %s :%s", Client_ThisServer( ), Msg );
284 20a2ffef 2002-03-27 alex c = Client_Next( c );
285 20a2ffef 2002-03-27 alex }
286 20a2ffef 2002-03-27 alex } /* Wall_ServerNotice */
287 20a2ffef 2002-03-27 alex
288 20a2ffef 2002-03-27 alex
289 f4ade537 2001-12-11 alex /* -eof- */