Blame


1 f4ade537 2001-12-11 alex /*
2 f4ade537 2001-12-11 alex * ngIRCd -- The Next Generation IRC Daemon
3 5e3e3ad4 2003-01-01 alex * Copyright (c)2001-2003 by Alexander Barton (alex@barton.de)
4 f4ade537 2001-12-11 alex *
5 fa7b3f0e 2002-12-12 alex * This program is free software; you can redistribute it and/or modify
6 fa7b3f0e 2002-12-12 alex * it under the terms of the GNU General Public License as published by
7 fa7b3f0e 2002-12-12 alex * the Free Software Foundation; either version 2 of the License, or
8 fa7b3f0e 2002-12-12 alex * (at your option) any later version.
9 fa7b3f0e 2002-12-12 alex * Please read the file COPYING, README and AUTHORS for more information.
10 f4ade537 2001-12-11 alex *
11 fa7b3f0e 2002-12-12 alex * Main program -- main()
12 f4ade537 2001-12-11 alex */
13 f4ade537 2001-12-11 alex
14 f4ade537 2001-12-11 alex
15 ca33cbda 2002-03-12 alex #include "portab.h"
16 fa7b3f0e 2002-12-12 alex
17 5e3e3ad4 2003-01-01 alex static char UNUSED id[] = "$Id: ngircd.c,v 1.71 2003/01/01 13:32:23 alex Exp $";
18 f4ade537 2001-12-11 alex
19 ca33cbda 2002-03-12 alex #include "imp.h"
20 f4ade537 2001-12-11 alex #include <assert.h>
21 22cf0c5d 2002-01-12 alex #include <errno.h>
22 f4ade537 2001-12-11 alex #include <stdio.h>
23 75c0bd25 2002-04-04 alex #include <stdlib.h>
24 418add93 2001-12-12 alex #include <signal.h>
25 52424b49 2002-01-11 alex #include <string.h>
26 22cf0c5d 2002-01-12 alex #include <unistd.h>
27 03d971d9 2002-01-02 alex #include <sys/types.h>
28 9ec32d15 2002-06-02 alex #include <sys/stat.h>
29 03d971d9 2002-01-02 alex #include <sys/wait.h>
30 ac9da09e 2001-12-30 alex #include <time.h>
31 70c9c051 2002-11-10 alex #include <pwd.h>
32 70c9c051 2002-11-10 alex #include <grp.h>
33 b61b8c4d 2001-12-12 alex
34 ba258e65 2002-05-27 alex #include "resolve.h"
35 ba258e65 2002-05-27 alex #include "conn.h"
36 58c6c8f3 2001-12-14 alex #include "client.h"
37 ba258e65 2002-05-27 alex #include "channel.h"
38 418add93 2001-12-12 alex #include "conf.h"
39 25f32ce8 2002-10-07 alex #include "cvs-version.h"
40 ca33cbda 2002-03-12 alex #include "defines.h"
41 ba258e65 2002-05-27 alex #include "lists.h"
42 f4ade537 2001-12-11 alex #include "log.h"
43 1751c869 2001-12-21 alex #include "parse.h"
44 ba258e65 2002-05-27 alex #include "irc.h"
45 f4ade537 2001-12-11 alex
46 ca33cbda 2002-03-12 alex #include "exp.h"
47 f4ade537 2001-12-11 alex #include "ngircd.h"
48 f4ade537 2001-12-11 alex
49 f4ade537 2001-12-11 alex
50 ba258e65 2002-05-27 alex LOCAL VOID Initialize_Signal_Handler PARAMS(( VOID ));
51 ba258e65 2002-05-27 alex LOCAL VOID Signal_Handler PARAMS(( INT Signal ));
52 f4ade537 2001-12-11 alex
53 ba258e65 2002-05-27 alex LOCAL VOID Show_Version PARAMS(( VOID ));
54 ba258e65 2002-05-27 alex LOCAL VOID Show_Help PARAMS(( VOID ));
55 9856253d 2001-12-30 alex
56 52424b49 2002-01-11 alex
57 ba258e65 2002-05-27 alex GLOBAL int
58 ba258e65 2002-05-27 alex main( int argc, const char *argv[] )
59 f4ade537 2001-12-11 alex {
60 70c9c051 2002-11-10 alex struct passwd *pwd;
61 70c9c051 2002-11-10 alex struct group *grp;
62 a89dc546 2002-03-27 alex BOOLEAN ok, configtest = FALSE;
63 c7b55aa6 2002-10-09 alex LONG pid, n;
64 95a4b1b1 2002-03-25 alex INT i;
65 52424b49 2002-01-11 alex
66 9ec32d15 2002-06-02 alex umask( 0077 );
67 9ec32d15 2002-06-02 alex
68 43a4bc5b 2002-12-19 alex NGIRCd_SignalQuit = NGIRCd_SignalRestart = NGIRCd_SignalRehash = FALSE;
69 43a4bc5b 2002-12-19 alex NGIRCd_NoDaemon = NGIRCd_Passive = FALSE;
70 52424b49 2002-01-11 alex #ifdef DEBUG
71 52424b49 2002-01-11 alex NGIRCd_Debug = FALSE;
72 52424b49 2002-01-11 alex #endif
73 d79a7d28 2002-01-18 alex #ifdef SNIFFER
74 d79a7d28 2002-01-18 alex NGIRCd_Sniffer = FALSE;
75 d79a7d28 2002-01-18 alex #endif
76 6626395c 2002-12-26 alex strlcpy( NGIRCd_ConfFile, SYSCONFDIR, sizeof( NGIRCd_ConfFile ));
77 6626395c 2002-12-26 alex strlcat( NGIRCd_ConfFile, CONFIG_FILE, sizeof( NGIRCd_ConfFile ));
78 52424b49 2002-01-11 alex
79 52424b49 2002-01-11 alex /* Kommandozeile parsen */
80 52424b49 2002-01-11 alex for( i = 1; i < argc; i++ )
81 52424b49 2002-01-11 alex {
82 52424b49 2002-01-11 alex ok = FALSE;
83 52424b49 2002-01-11 alex if(( argv[i][0] == '-' ) && ( argv[i][1] == '-' ))
84 52424b49 2002-01-11 alex {
85 52424b49 2002-01-11 alex /* Lange Option */
86 52424b49 2002-01-11 alex
87 72accd4e 2002-03-28 alex if( strcmp( argv[i], "--config" ) == 0 )
88 72accd4e 2002-03-28 alex {
89 72accd4e 2002-03-28 alex if( i + 1 < argc )
90 72accd4e 2002-03-28 alex {
91 0ced4181 2002-12-26 alex /* Ok, there's an parameter left */
92 0ced4181 2002-12-26 alex strlcpy( NGIRCd_ConfFile, argv[i + 1], sizeof( NGIRCd_ConfFile ));
93 72accd4e 2002-03-28 alex
94 0ced4181 2002-12-26 alex /* next parameter */
95 72accd4e 2002-03-28 alex i++; ok = TRUE;
96 72accd4e 2002-03-28 alex }
97 72accd4e 2002-03-28 alex }
98 a89dc546 2002-03-27 alex if( strcmp( argv[i], "--configtest" ) == 0 )
99 a89dc546 2002-03-27 alex {
100 a89dc546 2002-03-27 alex configtest = TRUE;
101 a89dc546 2002-03-27 alex ok = TRUE;
102 a89dc546 2002-03-27 alex }
103 eea1a88b 2002-02-19 alex #ifdef DEBUG
104 eea1a88b 2002-02-19 alex if( strcmp( argv[i], "--debug" ) == 0 )
105 eea1a88b 2002-02-19 alex {
106 eea1a88b 2002-02-19 alex NGIRCd_Debug = TRUE;
107 eea1a88b 2002-02-19 alex ok = TRUE;
108 eea1a88b 2002-02-19 alex }
109 eea1a88b 2002-02-19 alex #endif
110 52424b49 2002-01-11 alex if( strcmp( argv[i], "--help" ) == 0 )
111 52424b49 2002-01-11 alex {
112 a89dc546 2002-03-27 alex Show_Version( );
113 a89dc546 2002-03-27 alex puts( "" ); Show_Help( ); puts( "" );
114 52424b49 2002-01-11 alex exit( 1 );
115 52424b49 2002-01-11 alex }
116 eea1a88b 2002-02-19 alex if( strcmp( argv[i], "--nodaemon" ) == 0 )
117 52424b49 2002-01-11 alex {
118 eea1a88b 2002-02-19 alex NGIRCd_NoDaemon = TRUE;
119 eea1a88b 2002-02-19 alex ok = TRUE;
120 52424b49 2002-01-11 alex }
121 eea1a88b 2002-02-19 alex if( strcmp( argv[i], "--passive" ) == 0 )
122 52424b49 2002-01-11 alex {
123 eea1a88b 2002-02-19 alex NGIRCd_Passive = TRUE;
124 d79a7d28 2002-01-18 alex ok = TRUE;
125 d79a7d28 2002-01-18 alex }
126 d79a7d28 2002-01-18 alex #ifdef SNIFFER
127 d79a7d28 2002-01-18 alex if( strcmp( argv[i], "--sniffer" ) == 0 )
128 d79a7d28 2002-01-18 alex {
129 d79a7d28 2002-01-18 alex NGIRCd_Sniffer = TRUE;
130 52424b49 2002-01-11 alex ok = TRUE;
131 52424b49 2002-01-11 alex }
132 52424b49 2002-01-11 alex #endif
133 eea1a88b 2002-02-19 alex if( strcmp( argv[i], "--version" ) == 0 )
134 52424b49 2002-01-11 alex {
135 d67d94ea 2002-03-10 alex Show_Version( );
136 eea1a88b 2002-02-19 alex exit( 1 );
137 52424b49 2002-01-11 alex }
138 52424b49 2002-01-11 alex }
139 52424b49 2002-01-11 alex else if(( argv[i][0] == '-' ) && ( argv[i][1] != '-' ))
140 52424b49 2002-01-11 alex {
141 52424b49 2002-01-11 alex /* Kurze Option */
142 52424b49 2002-01-11 alex
143 c7b55aa6 2002-10-09 alex for( n = 1; n < (LONG)strlen( argv[i] ); n++ )
144 52424b49 2002-01-11 alex {
145 52424b49 2002-01-11 alex ok = FALSE;
146 52424b49 2002-01-11 alex #ifdef DEBUG
147 52424b49 2002-01-11 alex if( argv[i][n] == 'd' )
148 52424b49 2002-01-11 alex {
149 52424b49 2002-01-11 alex NGIRCd_Debug = TRUE;
150 52424b49 2002-01-11 alex ok = TRUE;
151 52424b49 2002-01-11 alex }
152 52424b49 2002-01-11 alex #endif
153 72accd4e 2002-03-28 alex if( argv[i][n] == 'f' )
154 72accd4e 2002-03-28 alex {
155 85aad869 2002-03-31 alex if(( ! argv[i][n + 1] ) && ( i + 1 < argc ))
156 72accd4e 2002-03-28 alex {
157 0ced4181 2002-12-26 alex /* Ok, next character is a blank */
158 0ced4181 2002-12-26 alex strlcpy( NGIRCd_ConfFile, argv[i + 1], sizeof( NGIRCd_ConfFile ));
159 72accd4e 2002-03-28 alex
160 0ced4181 2002-12-26 alex /* go to the following parameter */
161 c7b55aa6 2002-10-09 alex i++; n = (LONG)strlen( argv[i] );
162 72accd4e 2002-03-28 alex ok = TRUE;
163 72accd4e 2002-03-28 alex }
164 72accd4e 2002-03-28 alex }
165 eea1a88b 2002-02-19 alex if( argv[i][n] == 'n' )
166 eea1a88b 2002-02-19 alex {
167 eea1a88b 2002-02-19 alex NGIRCd_NoDaemon = TRUE;
168 eea1a88b 2002-02-19 alex ok = TRUE;
169 eea1a88b 2002-02-19 alex }
170 eea1a88b 2002-02-19 alex if( argv[i][n] == 'p' )
171 eea1a88b 2002-02-19 alex {
172 eea1a88b 2002-02-19 alex NGIRCd_Passive = TRUE;
173 eea1a88b 2002-02-19 alex ok = TRUE;
174 eea1a88b 2002-02-19 alex }
175 d79a7d28 2002-01-18 alex #ifdef SNIFFER
176 d79a7d28 2002-01-18 alex if( argv[i][n] == 's' )
177 d79a7d28 2002-01-18 alex {
178 d79a7d28 2002-01-18 alex NGIRCd_Sniffer = TRUE;
179 d79a7d28 2002-01-18 alex ok = TRUE;
180 d79a7d28 2002-01-18 alex }
181 d79a7d28 2002-01-18 alex #endif
182 52424b49 2002-01-11 alex
183 52424b49 2002-01-11 alex if( ! ok )
184 52424b49 2002-01-11 alex {
185 ba258e65 2002-05-27 alex printf( "%s: invalid option \"-%c\"!\n", PACKAGE, argv[i][n] );
186 ba258e65 2002-05-27 alex printf( "Try \"%s --help\" for more information.\n", PACKAGE );
187 52424b49 2002-01-11 alex exit( 1 );
188 52424b49 2002-01-11 alex }
189 52424b49 2002-01-11 alex }
190 f4ade537 2001-12-11 alex
191 52424b49 2002-01-11 alex }
192 52424b49 2002-01-11 alex if( ! ok )
193 52424b49 2002-01-11 alex {
194 ba258e65 2002-05-27 alex printf( "%s: invalid option \"%s\"!\n", PACKAGE, argv[i] );
195 ba258e65 2002-05-27 alex printf( "Try \"%s --help\" for more information.\n", PACKAGE );
196 52424b49 2002-01-11 alex exit( 1 );
197 52424b49 2002-01-11 alex }
198 52424b49 2002-01-11 alex }
199 52424b49 2002-01-11 alex
200 eea1a88b 2002-02-19 alex /* Debug-Level (fuer IRC-Befehl "VERSION") ermitteln */
201 eea1a88b 2002-02-19 alex strcpy( NGIRCd_DebugLevel, "" );
202 eea1a88b 2002-02-19 alex #ifdef DEBUG
203 eea1a88b 2002-02-19 alex if( NGIRCd_Debug ) strcpy( NGIRCd_DebugLevel, "1" );
204 eea1a88b 2002-02-19 alex #endif
205 eea1a88b 2002-02-19 alex #ifdef SNIFFER
206 991da8ea 2002-05-18 alex if( NGIRCd_Sniffer )
207 991da8ea 2002-05-18 alex {
208 991da8ea 2002-05-18 alex NGIRCd_Debug = TRUE;
209 991da8ea 2002-05-18 alex strcpy( NGIRCd_DebugLevel, "2" );
210 991da8ea 2002-05-18 alex }
211 eea1a88b 2002-02-19 alex #endif
212 a89dc546 2002-03-27 alex
213 a89dc546 2002-03-27 alex /* Soll nur die Konfigurations ueberprueft und ausgegeben werden? */
214 a89dc546 2002-03-27 alex if( configtest )
215 a89dc546 2002-03-27 alex {
216 a89dc546 2002-03-27 alex Show_Version( ); puts( "" );
217 a89dc546 2002-03-27 alex exit( Conf_Test( ));
218 a89dc546 2002-03-27 alex }
219 eea1a88b 2002-02-19 alex
220 43a4bc5b 2002-12-19 alex while( ! NGIRCd_SignalQuit )
221 804b1ec4 2001-12-31 alex {
222 22cf0c5d 2002-01-12 alex /* In der Regel wird ein Sub-Prozess ge-fork()'t, der
223 22cf0c5d 2002-01-12 alex * nicht mehr mit dem Terminal verbunden ist. Mit der
224 22cf0c5d 2002-01-12 alex * Option "--nodaemon" kann dies (z.B. zum Debuggen)
225 22cf0c5d 2002-01-12 alex * verhindert werden. */
226 22cf0c5d 2002-01-12 alex if( ! NGIRCd_NoDaemon )
227 22cf0c5d 2002-01-12 alex {
228 22cf0c5d 2002-01-12 alex /* Daemon im Hintergrund erzeugen */
229 c7b55aa6 2002-10-09 alex pid = (LONG)fork( );
230 22cf0c5d 2002-01-12 alex if( pid > 0 )
231 22cf0c5d 2002-01-12 alex {
232 22cf0c5d 2002-01-12 alex /* "alter" Prozess */
233 22cf0c5d 2002-01-12 alex exit( 0 );
234 22cf0c5d 2002-01-12 alex }
235 22cf0c5d 2002-01-12 alex if( pid < 0 )
236 22cf0c5d 2002-01-12 alex {
237 22cf0c5d 2002-01-12 alex /* Fehler */
238 ba258e65 2002-05-27 alex printf( "%s: Can't fork: %s!\nFatal error, exiting now ...\n", PACKAGE, strerror( errno ));
239 22cf0c5d 2002-01-12 alex exit( 1 );
240 22cf0c5d 2002-01-12 alex }
241 fe2bc90e 2002-03-06 alex
242 fe2bc90e 2002-03-06 alex /* Child-Prozess initialisieren */
243 95a4b1b1 2002-03-25 alex (VOID)setsid( );
244 22cf0c5d 2002-01-12 alex chdir( "/" );
245 22cf0c5d 2002-01-12 alex }
246 22cf0c5d 2002-01-12 alex
247 804b1ec4 2001-12-31 alex /* Globale Variablen initialisieren */
248 804b1ec4 2001-12-31 alex NGIRCd_Start = time( NULL );
249 95a4b1b1 2002-03-25 alex (VOID)strftime( NGIRCd_StartStr, 64, "%a %b %d %Y at %H:%M:%S (%Z)", localtime( &NGIRCd_Start ));
250 43a4bc5b 2002-12-19 alex NGIRCd_SignalRehash = FALSE;
251 43a4bc5b 2002-12-19 alex NGIRCd_SignalRestart = FALSE;
252 43a4bc5b 2002-12-19 alex NGIRCd_SignalQuit = FALSE;
253 ff280ce4 2001-12-12 alex
254 804b1ec4 2001-12-31 alex /* Module initialisieren */
255 804b1ec4 2001-12-31 alex Log_Init( );
256 ba258e65 2002-05-27 alex Resolve_Init( );
257 804b1ec4 2001-12-31 alex Conf_Init( );
258 ba258e65 2002-05-27 alex Lists_Init( );
259 804b1ec4 2001-12-31 alex Channel_Init( );
260 804b1ec4 2001-12-31 alex Client_Init( );
261 804b1ec4 2001-12-31 alex Conn_Init( );
262 f4ade537 2001-12-11 alex
263 07c3e62e 2002-03-29 alex /* Wenn als root ausgefuehrt und eine andere UID
264 07c3e62e 2002-03-29 alex * konfiguriert ist, jetzt zu dieser wechseln */
265 fe06f6e9 2002-03-29 alex if( getuid( ) == 0 )
266 07c3e62e 2002-03-29 alex {
267 fe06f6e9 2002-03-29 alex if( Conf_GID != 0 )
268 07c3e62e 2002-03-29 alex {
269 07c3e62e 2002-03-29 alex /* Neue Group-ID setzen */
270 07c3e62e 2002-03-29 alex if( setgid( Conf_GID ) != 0 ) Log( LOG_ERR, "Can't change Group-ID to %u: %s", Conf_GID, strerror( errno ));
271 07c3e62e 2002-03-29 alex }
272 fe06f6e9 2002-03-29 alex if( Conf_UID != 0 )
273 07c3e62e 2002-03-29 alex {
274 07c3e62e 2002-03-29 alex /* Neue User-ID setzen */
275 fe06f6e9 2002-03-29 alex if( setuid( Conf_UID ) != 0 ) Log( LOG_ERR, "Can't change User-ID to %u: %s", Conf_UID, strerror( errno ));
276 07c3e62e 2002-03-29 alex }
277 07c3e62e 2002-03-29 alex }
278 70c9c051 2002-11-10 alex
279 70c9c051 2002-11-10 alex /* User, Gruppe und Prozess-ID des Daemon ausgeben */
280 70c9c051 2002-11-10 alex pwd = getpwuid( getuid( )); grp = getgrgid( getgid( ));
281 70c9c051 2002-11-10 alex Log( LOG_INFO, "Running as user %s(%ld), group %s(%ld), with PID %ld.", pwd ? pwd->pw_name : "unknown", (LONG)getuid( ), grp ? grp->gr_name : "unknown", (LONG)getgid( ), (LONG)getpid( ));
282 07c3e62e 2002-03-29 alex
283 70c9c051 2002-11-10 alex /* stderr in "Error-File" umlenken */
284 fe06f6e9 2002-03-29 alex Log_InitErrorfile( );
285 fe06f6e9 2002-03-29 alex
286 804b1ec4 2001-12-31 alex /* Signal-Handler initialisieren */
287 804b1ec4 2001-12-31 alex Initialize_Signal_Handler( );
288 65b31ffb 2002-09-02 alex
289 c76e6769 2002-09-02 alex /* Protokoll- und Server-Identifikation erzeugen. Die vom ngIRCd
290 c76e6769 2002-09-02 alex * beim PASS-Befehl verwendete Syntax sowie die erweiterten Flags
291 c76e6769 2002-09-02 alex * sind in doc/Protocol.txt beschrieben. */
292 14cbca87 2002-09-07 alex #ifdef IRCPLUS
293 1c668252 2002-09-03 alex sprintf( NGIRCd_ProtoID, "%s%s %s|%s:%s", PROTOVER, PROTOIRCPLUS, PACKAGE, VERSION, IRCPLUSFLAGS );
294 65f3adca 2002-11-26 alex #ifdef USE_ZLIB
295 65f3adca 2002-11-26 alex strcat( NGIRCd_ProtoID, "Z" );
296 65f3adca 2002-11-26 alex #endif
297 c76e6769 2002-09-02 alex if( Conf_OperCanMode ) strcat( NGIRCd_ProtoID, "o" );
298 14cbca87 2002-09-07 alex #else
299 14cbca87 2002-09-07 alex sprintf( NGIRCd_ProtoID, "%s%s %s|%s", PROTOVER, PROTOIRC, PACKAGE, VERSION );
300 14cbca87 2002-09-07 alex #endif
301 c76e6769 2002-09-02 alex strcat( NGIRCd_ProtoID, " P" );
302 65f3adca 2002-11-26 alex #ifdef USE_ZLIB
303 65f3adca 2002-11-26 alex strcat( NGIRCd_ProtoID, "Z" );
304 65f3adca 2002-11-26 alex #endif
305 65b31ffb 2002-09-02 alex Log( LOG_DEBUG, "Protocol and server ID is \"%s\".", NGIRCd_ProtoID );
306 9856253d 2001-12-30 alex
307 b788a3da 2002-06-02 alex /* Vordefinierte Channels anlegen */
308 b788a3da 2002-06-02 alex Channel_InitPredefined( );
309 b788a3da 2002-06-02 alex
310 804b1ec4 2001-12-31 alex /* Listen-Ports initialisieren */
311 e311cc01 2002-11-22 alex if( Conn_InitListeners( ) < 1 )
312 e311cc01 2002-11-22 alex {
313 e311cc01 2002-11-22 alex Log( LOG_ALERT, "Server isn't listening on a single port!" );
314 e311cc01 2002-11-22 alex Log( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE );
315 e311cc01 2002-11-22 alex exit( 1 );
316 e311cc01 2002-11-22 alex }
317 e311cc01 2002-11-22 alex
318 804b1ec4 2001-12-31 alex /* Hauptschleife */
319 9ec32d15 2002-06-02 alex Conn_Handler( );
320 804b1ec4 2001-12-31 alex
321 804b1ec4 2001-12-31 alex /* Alles abmelden */
322 804b1ec4 2001-12-31 alex Conn_Exit( );
323 804b1ec4 2001-12-31 alex Client_Exit( );
324 804b1ec4 2001-12-31 alex Channel_Exit( );
325 ba258e65 2002-05-27 alex Lists_Exit( );
326 804b1ec4 2001-12-31 alex Log_Exit( );
327 804b1ec4 2001-12-31 alex }
328 fe2bc90e 2002-03-06 alex
329 f4ade537 2001-12-11 alex return 0;
330 f4ade537 2001-12-11 alex } /* main */
331 f4ade537 2001-12-11 alex
332 f4ade537 2001-12-11 alex
333 ba258e65 2002-05-27 alex GLOBAL CHAR *
334 ba258e65 2002-05-27 alex NGIRCd_Version( VOID )
335 52424b49 2002-01-11 alex {
336 52424b49 2002-01-11 alex STATIC CHAR version[126];
337 25f32ce8 2002-10-07 alex
338 25f32ce8 2002-10-07 alex #ifdef CVSDATE
339 25f32ce8 2002-10-07 alex sprintf( version, "%s %s(%s)-%s", PACKAGE, VERSION, CVSDATE, NGIRCd_VersionAddition( ));
340 25f32ce8 2002-10-07 alex #else
341 14cbca87 2002-09-07 alex sprintf( version, "%s %s-%s", PACKAGE, VERSION, NGIRCd_VersionAddition( ));
342 25f32ce8 2002-10-07 alex #endif
343 3fbbfe44 2002-02-17 alex return version;
344 3fbbfe44 2002-02-17 alex } /* NGIRCd_Version */
345 3fbbfe44 2002-02-17 alex
346 3fbbfe44 2002-02-17 alex
347 ba258e65 2002-05-27 alex GLOBAL CHAR *
348 ba258e65 2002-05-27 alex NGIRCd_VersionAddition( VOID )
349 3fbbfe44 2002-02-17 alex {
350 3fbbfe44 2002-02-17 alex STATIC CHAR txt[64];
351 3fbbfe44 2002-02-17 alex
352 52424b49 2002-01-11 alex strcpy( txt, "" );
353 52424b49 2002-01-11 alex
354 52424b49 2002-01-11 alex #ifdef USE_SYSLOG
355 52424b49 2002-01-11 alex if( txt[0] ) strcat( txt, "+" );
356 52424b49 2002-01-11 alex strcat( txt, "SYSLOG" );
357 52424b49 2002-01-11 alex #endif
358 65f3adca 2002-11-26 alex #ifdef USE_ZLIB
359 65f3adca 2002-11-26 alex if( txt[0] ) strcat( txt, "+" );
360 65f3adca 2002-11-26 alex strcat( txt, "ZLIB" );
361 65f3adca 2002-11-26 alex #endif
362 52424b49 2002-01-11 alex #ifdef DEBUG
363 52424b49 2002-01-11 alex if( txt[0] ) strcat( txt, "+" );
364 52424b49 2002-01-11 alex strcat( txt, "DEBUG" );
365 52424b49 2002-01-11 alex #endif
366 52424b49 2002-01-11 alex #ifdef SNIFFER
367 52424b49 2002-01-11 alex if( txt[0] ) strcat( txt, "+" );
368 52424b49 2002-01-11 alex strcat( txt, "SNIFFER" );
369 52424b49 2002-01-11 alex #endif
370 14cbca87 2002-09-07 alex #ifdef STRICT_RFC
371 14cbca87 2002-09-07 alex if( txt[0] ) strcat( txt, "+" );
372 14cbca87 2002-09-07 alex strcat( txt, "RFC" );
373 14cbca87 2002-09-07 alex #endif
374 14cbca87 2002-09-07 alex #ifdef IRCPLUS
375 14cbca87 2002-09-07 alex if( txt[0] ) strcat( txt, "+" );
376 14cbca87 2002-09-07 alex strcat( txt, "IRCPLUS" );
377 14cbca87 2002-09-07 alex #endif
378 14cbca87 2002-09-07 alex
379 6626395c 2002-12-26 alex if( txt[0] ) strlcat( txt, "-", sizeof( txt ));
380 6626395c 2002-12-26 alex strlcat( txt, TARGET_CPU, sizeof( txt ));
381 6626395c 2002-12-26 alex strlcat( txt, "/", sizeof( txt ));
382 6626395c 2002-12-26 alex strlcat( txt, TARGET_VENDOR, sizeof( txt ));
383 6626395c 2002-12-26 alex strlcat( txt, "/", sizeof( txt ));
384 6626395c 2002-12-26 alex strlcat( txt, TARGET_OS, sizeof( txt ));
385 52424b49 2002-01-11 alex
386 3fbbfe44 2002-02-17 alex return txt;
387 3fbbfe44 2002-02-17 alex } /* NGIRCd_VersionAddition */
388 e311cc01 2002-11-22 alex
389 e311cc01 2002-11-22 alex
390 e311cc01 2002-11-22 alex GLOBAL VOID
391 cf2d4794 2002-11-22 alex NGIRCd_Rehash( VOID )
392 e311cc01 2002-11-22 alex {
393 e311cc01 2002-11-22 alex CHAR old_name[CLIENT_ID_LEN];
394 43a4bc5b 2002-12-19 alex
395 43a4bc5b 2002-12-19 alex Log( LOG_NOTICE|LOG_snotice, "Re-reading configuration NOW!" );
396 43a4bc5b 2002-12-19 alex NGIRCd_SignalRehash = FALSE;
397 43a4bc5b 2002-12-19 alex
398 e311cc01 2002-11-22 alex /* Alle Listen-Sockets schliessen */
399 e311cc01 2002-11-22 alex Conn_ExitListeners( );
400 52424b49 2002-01-11 alex
401 e311cc01 2002-11-22 alex /* Alten Server-Namen merken */
402 695631b2 2002-12-26 alex assert( sizeof( old_name ) == sizeof( Conf_ServerName ));
403 e311cc01 2002-11-22 alex strcpy( old_name, Conf_ServerName );
404 3fbbfe44 2002-02-17 alex
405 e311cc01 2002-11-22 alex /* Konfiguration neu lesen ... */
406 a2544e49 2002-12-30 alex Conf_Rehash( );
407 e311cc01 2002-11-22 alex
408 e311cc01 2002-11-22 alex /* Alten Server-Namen wiederherstellen: dieser
409 e311cc01 2002-11-22 alex * kann nicht zur Laufzeit geaendert werden ... */
410 e311cc01 2002-11-22 alex if( strcmp( old_name, Conf_ServerName ) != 0 )
411 e311cc01 2002-11-22 alex {
412 e311cc01 2002-11-22 alex strcpy( Conf_ServerName, old_name );
413 e311cc01 2002-11-22 alex Log( LOG_ERR, "Can't change \"ServerName\" on runtime! Ignored new name." );
414 e311cc01 2002-11-22 alex }
415 e311cc01 2002-11-22 alex
416 e311cc01 2002-11-22 alex /* neue pre-defined Channel anlegen: */
417 e311cc01 2002-11-22 alex Channel_InitPredefined( );
418 e311cc01 2002-11-22 alex
419 e311cc01 2002-11-22 alex /* Listen-Sockets neu anlegen: */
420 e311cc01 2002-11-22 alex Conn_InitListeners( );
421 e311cc01 2002-11-22 alex
422 43a4bc5b 2002-12-19 alex Log( LOG_NOTICE|LOG_snotice, "Re-reading of configuration done." );
423 cf2d4794 2002-11-22 alex } /* NGIRCd_Rehash */
424 e311cc01 2002-11-22 alex
425 e311cc01 2002-11-22 alex
426 ba258e65 2002-05-27 alex LOCAL VOID
427 ba258e65 2002-05-27 alex Initialize_Signal_Handler( VOID )
428 418add93 2001-12-12 alex {
429 08cf5607 2001-12-26 alex /* Signal-Handler initialisieren: einige Signale
430 08cf5607 2001-12-26 alex * werden ignoriert, andere speziell behandelt. */
431 418add93 2001-12-12 alex
432 62266a8d 2002-02-25 alex #ifdef HAVE_SIGACTION
433 62266a8d 2002-02-25 alex /* sigaction() ist vorhanden */
434 62266a8d 2002-02-25 alex
435 418add93 2001-12-12 alex struct sigaction saction;
436 418add93 2001-12-12 alex
437 418add93 2001-12-12 alex /* Signal-Struktur initialisieren */
438 418add93 2001-12-12 alex memset( &saction, 0, sizeof( saction ));
439 23253edb 2002-01-22 alex saction.sa_handler = Signal_Handler;
440 9919f38d 2002-02-19 alex #ifdef SA_RESTART
441 6f955d2a 2002-02-23 alex saction.sa_flags |= SA_RESTART;
442 9919f38d 2002-02-19 alex #endif
443 6f955d2a 2002-02-23 alex #ifdef SA_NOCLDWAIT
444 6f955d2a 2002-02-23 alex saction.sa_flags |= SA_NOCLDWAIT;
445 6f955d2a 2002-02-23 alex #endif
446 418add93 2001-12-12 alex
447 418add93 2001-12-12 alex /* Signal-Handler einhaengen */
448 418add93 2001-12-12 alex sigaction( SIGINT, &saction, NULL );
449 418add93 2001-12-12 alex sigaction( SIGQUIT, &saction, NULL );
450 418add93 2001-12-12 alex sigaction( SIGTERM, &saction, NULL);
451 3fbbfe44 2002-02-17 alex sigaction( SIGHUP, &saction, NULL);
452 03d971d9 2002-01-02 alex sigaction( SIGCHLD, &saction, NULL);
453 eb952e35 2001-12-24 alex
454 eb952e35 2001-12-24 alex /* einige Signale ignorieren */
455 eb952e35 2001-12-24 alex saction.sa_handler = SIG_IGN;
456 eb952e35 2001-12-24 alex sigaction( SIGPIPE, &saction, NULL );
457 62266a8d 2002-02-25 alex #else
458 62266a8d 2002-02-25 alex /* kein sigaction() vorhanden */
459 62266a8d 2002-02-25 alex
460 62266a8d 2002-02-25 alex /* Signal-Handler einhaengen */
461 62266a8d 2002-02-25 alex signal( SIGINT, Signal_Handler );
462 62266a8d 2002-02-25 alex signal( SIGQUIT, Signal_Handler );
463 62266a8d 2002-02-25 alex signal( SIGTERM, Signal_Handler );
464 62266a8d 2002-02-25 alex signal( SIGHUP, Signal_Handler );
465 62266a8d 2002-02-25 alex signal( SIGCHLD, Signal_Handler );
466 62266a8d 2002-02-25 alex
467 62266a8d 2002-02-25 alex /* einige Signale ignorieren */
468 62266a8d 2002-02-25 alex signal( SIGPIPE, SIG_IGN );
469 62266a8d 2002-02-25 alex #endif
470 418add93 2001-12-12 alex } /* Initialize_Signal_Handler */
471 418add93 2001-12-12 alex
472 418add93 2001-12-12 alex
473 ba258e65 2002-05-27 alex LOCAL VOID
474 ba258e65 2002-05-27 alex Signal_Handler( INT Signal )
475 f4ade537 2001-12-11 alex {
476 418add93 2001-12-12 alex /* Signal-Handler. Dieser wird aufgerufen, wenn eines der Signale eintrifft,
477 418add93 2001-12-12 alex * fuer das wir uns registriert haben (vgl. Initialize_Signal_Handler). Die
478 418add93 2001-12-12 alex * Nummer des eingetroffenen Signals wird der Funktion uebergeben. */
479 418add93 2001-12-12 alex
480 f4ade537 2001-12-11 alex switch( Signal )
481 f4ade537 2001-12-11 alex {
482 f4ade537 2001-12-11 alex case SIGTERM:
483 b61b8c4d 2001-12-12 alex case SIGINT:
484 b61b8c4d 2001-12-12 alex case SIGQUIT:
485 418add93 2001-12-12 alex /* wir soll(t)en uns wohl beenden ... */
486 43a4bc5b 2002-12-19 alex NGIRCd_SignalQuit = TRUE;
487 f4ade537 2001-12-11 alex break;
488 3fbbfe44 2002-02-17 alex case SIGHUP:
489 e311cc01 2002-11-22 alex /* Konfiguration neu einlesen: */
490 43a4bc5b 2002-12-19 alex NGIRCd_SignalRehash = TRUE;
491 3fbbfe44 2002-02-17 alex break;
492 03d971d9 2002-01-02 alex case SIGCHLD:
493 03d971d9 2002-01-02 alex /* Child-Prozess wurde beendet. Zombies vermeiden: */
494 03d971d9 2002-01-02 alex while( waitpid( -1, NULL, WNOHANG ) > 0);
495 03d971d9 2002-01-02 alex break;
496 43a4bc5b 2002-12-19 alex #ifdef DEBUG
497 f4ade537 2001-12-11 alex default:
498 418add93 2001-12-12 alex /* unbekanntes bzw. unbehandeltes Signal */
499 43a4bc5b 2002-12-19 alex Log( LOG_DEBUG, "Got signal %d! Ignored.", Signal );
500 43a4bc5b 2002-12-19 alex #endif
501 f4ade537 2001-12-11 alex }
502 f4ade537 2001-12-11 alex } /* Signal_Handler */
503 f4ade537 2001-12-11 alex
504 f4ade537 2001-12-11 alex
505 ba258e65 2002-05-27 alex LOCAL VOID
506 ba258e65 2002-05-27 alex Show_Version( VOID )
507 52424b49 2002-01-11 alex {
508 52424b49 2002-01-11 alex puts( NGIRCd_Version( ));
509 5e3e3ad4 2003-01-01 alex puts( "Copyright (c)2001-2003 by Alexander Barton (<alex@barton.de>)." );
510 5b27e491 2002-04-01 alex puts( "Homepage: <http://arthur.ath.cx/~alex/ngircd/>\n" );
511 52424b49 2002-01-11 alex puts( "This is free software; see the source for copying conditions. There is NO" );
512 52424b49 2002-01-11 alex puts( "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." );
513 52424b49 2002-01-11 alex } /* Show_Version */
514 52424b49 2002-01-11 alex
515 52424b49 2002-01-11 alex
516 ba258e65 2002-05-27 alex LOCAL VOID
517 ba258e65 2002-05-27 alex Show_Help( VOID )
518 52424b49 2002-01-11 alex {
519 52424b49 2002-01-11 alex #ifdef DEBUG
520 72accd4e 2002-03-28 alex puts( " -d, --debug log extra debug messages" );
521 52424b49 2002-01-11 alex #endif
522 72accd4e 2002-03-28 alex puts( " -f, --config <f> use file <f> as configuration file" );
523 1c0ded41 2002-11-18 alex puts( " -n, --nodaemon don't fork and don't detach from controlling terminal" );
524 72accd4e 2002-03-28 alex puts( " -p, --passive disable automatic connections to other servers" );
525 72accd4e 2002-03-28 alex #ifdef SNIFFER
526 72accd4e 2002-03-28 alex puts( " -s, --sniffer enable network sniffer and display all IRC traffic" );
527 9951e135 2002-01-21 alex #endif
528 72accd4e 2002-03-28 alex puts( " --configtest read, validate and display configuration; then exit" );
529 72accd4e 2002-03-28 alex puts( " --version output version information and exit" );
530 72accd4e 2002-03-28 alex puts( " --help display this help and exit" );
531 52424b49 2002-01-11 alex } /* Show_Help */
532 52424b49 2002-01-11 alex
533 52424b49 2002-01-11 alex
534 f4ade537 2001-12-11 alex /* -eof- */