2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001 by Alexander Barton (alex@barton.de)
5 * Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen
6 * der GNU General Public License (GPL), wie von der Free Software Foundation
7 * herausgegeben, weitergeben und/oder modifizieren, entweder unter Version 2
8 * der Lizenz oder (wenn Sie es wuenschen) jeder spaeteren Version.
9 * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
10 * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
12 * $Id: conf.c,v 1.7 2002/01/01 18:25:44 alex Exp $
14 * conf.h: Konfiguration des ngircd
17 * Revision 1.7 2002/01/01 18:25:44 alex
18 * - #include's fuer stdlib.h ergaenzt.
20 * Revision 1.6 2001/12/31 02:18:51 alex
21 * - viele neue Befehle (WHOIS, ISON, OPER, DIE, RESTART),
22 * - neuen Header "defines.h" mit (fast) allen Konstanten.
23 * - Code Cleanups und viele "kleine" Aenderungen & Bugfixes.
25 * Revision 1.5 2001/12/30 19:26:11 alex
26 * - Unterstuetzung fuer die Konfigurationsdatei eingebaut.
28 * Revision 1.4 2001/12/26 22:48:53 alex
29 * - MOTD-Datei ist nun konfigurierbar und wird gelesen.
31 * Revision 1.3 2001/12/26 14:45:37 alex
34 * Revision 1.2 2001/12/26 03:19:57 alex
35 * - erste Konfigurations-Variablen definiert: PING/PONG-Timeout.
37 * Revision 1.1 2001/12/12 17:18:20 alex
38 * - Modul fuer Server-Konfiguration begonnen.
60 LOCAL VOID Read_Config( VOID );
61 LOCAL VOID Validate_Config( VOID );
64 GLOBAL VOID Conf_Init( VOID )
66 /* Konfigurationsvariablen initialisieren: zunaechst Default-
67 * Werte setzen, dann Konfigurationsdtaei einlesen. */
69 strcpy( Conf_File, "/usr/local/etc/ngircd.conf" );
71 strcpy( Conf_ServerName, "" );
72 strcpy( Conf_ServerInfo, PACKAGE" "VERSION );
74 strcpy( Conf_Oper, "" );
75 strcpy( Conf_OperPwd, "" );
77 strcpy( Conf_MotdFile, "/usr/local/etc/ngircd.motd" );
79 Conf_ListenPorts_Count = 0;
81 Conf_PingTimeout = 120;
82 Conf_PongTimeout = 10;
84 /* Konfigurationsdatei einlesen und validieren */
90 GLOBAL VOID Conf_Exit( VOID )
96 LOCAL VOID Read_Config( VOID )
98 /* Konfigurationsdatei einlesen. */
100 CHAR str[LINE_LEN], *var, *arg, *ptr;
106 fd = fopen( Conf_File, "r" );
109 /* Keine Konfigurationsdatei gefunden */
110 Log( LOG_ALERT, "Can't read configuration \"%s\": %s", Conf_File, strerror( errno ));
111 Log( LOG_ALERT, PACKAGE" exiting due to fatal errors!" );
120 if( ! fgets( str, LINE_LEN, fd )) break;
124 /* Kommentarzeilen und leere Zeilen ueberspringen */
125 if( str[0] == ';' || str[0] == '#' || str[0] == '\0' ) continue;
127 ptr = strchr( str, '=' );
130 Log( LOG_ERR, "%s, line %d: Syntax error!", Conf_File, line );
135 var = str; ngt_TrimStr( var );
136 arg = ptr + 1; ngt_TrimStr( arg );
138 if( strcasecmp( str, "ServerName" ) == 0 )
140 /* Der Server-Name */
141 strncpy( Conf_ServerName, arg, CLIENT_ID_LEN );
142 Conf_ServerName[CLIENT_ID_LEN - 1] = '\0';
145 else if( strcasecmp( str, "ServerInfo" ) == 0 )
147 /* Server-Info-Text */
148 strncpy( Conf_ServerInfo, arg, CLIENT_INFO_LEN );
149 Conf_ServerInfo[CLIENT_INFO_LEN - 1] = '\0';
152 else if( strcasecmp( str, "Operator" ) == 0 )
154 /* Name des IRC Operator */
155 strncpy( Conf_Oper, arg, CLIENT_PASS_LEN );
156 Conf_Oper[CLIENT_PASS_LEN - 1] = '\0';
159 else if( strcasecmp( str, "OperatorPwd" ) == 0 )
161 /* Passwort des IRC Operator */
162 strncpy( Conf_OperPwd, arg, CLIENT_PASS_LEN );
163 Conf_OperPwd[CLIENT_PASS_LEN - 1] = '\0';
166 else if( strcasecmp( str, "ListenPorts" ) == 0 )
168 /* Ports, durch "," getrennt, auf denen der Server
169 * Verbindungen annehmen soll */
170 ptr = strtok( arg, "," );
175 if( Conf_ListenPorts_Count + 1 > LISTEN_PORTS ) Log( LOG_ERR, "Too many listen ports configured. Port %ld ignored.", port );
176 if( port > 0 && port < 0xFFFF ) Conf_ListenPorts[Conf_ListenPorts_Count++] = port;
177 else Log( LOG_ERR, "Illegal port number: %ld. Ignored.", port );
178 ptr = strtok( NULL, "," );
182 else if( strcasecmp( str, "MotdFile" ) == 0 )
184 /* Datei mit der "message of the day" (MOTD) */
185 strncpy( Conf_MotdFile, arg, FNAME_LEN );
186 Conf_MotdFile[FNAME_LEN - 1] = '\0';
189 else if( strcasecmp( str, "PingTimeout" ) == 0 )
192 Conf_PingTimeout = atoi( arg );
193 if(( Conf_PingTimeout ) < 5 ) Conf_PingTimeout = 5;
196 else if( strcasecmp( str, "PongTimeout" ) == 0 )
199 Conf_PongTimeout = atoi( arg );
200 if(( Conf_PongTimeout ) < 5 ) Conf_PongTimeout = 5;
204 if( ! ok ) Log( LOG_ERR, "%s, line %d: Unknown variable \"%s\"!", Conf_File, line, var );
211 LOCAL VOID Validate_Config( VOID )
213 /* Konfiguration ueberpruefen */
215 if( ! Conf_ServerName[0] )
217 /* Kein Servername konfiguriert */
218 Log( LOG_ALERT, "No server name configured (use \"ServerName\")!", Conf_File, strerror( errno ));
219 Log( LOG_ALERT, PACKAGE" exiting due to fatal errors!" );
222 } /* Validate_Config */