Blame


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