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