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.6 2001/12/31 02:18:51 alex Exp $
14 * conf.h: Konfiguration des ngircd
17 * Revision 1.6 2001/12/31 02:18:51 alex
18 * - viele neue Befehle (WHOIS, ISON, OPER, DIE, RESTART),
19 * - neuen Header "defines.h" mit (fast) allen Konstanten.
20 * - Code Cleanups und viele "kleine" Aenderungen & Bugfixes.
22 * Revision 1.5 2001/12/30 19:26:11 alex
23 * - Unterstuetzung fuer die Konfigurationsdatei eingebaut.
25 * Revision 1.4 2001/12/26 22:48:53 alex
26 * - MOTD-Datei ist nun konfigurierbar und wird gelesen.
28 * Revision 1.3 2001/12/26 14:45:37 alex
31 * Revision 1.2 2001/12/26 03:19:57 alex
32 * - erste Konfigurations-Variablen definiert: PING/PONG-Timeout.
34 * Revision 1.1 2001/12/12 17:18:20 alex
35 * - Modul fuer Server-Konfiguration begonnen.
56 LOCAL VOID Read_Config( VOID );
57 LOCAL VOID Validate_Config( VOID );
60 GLOBAL VOID Conf_Init( VOID )
62 /* Konfigurationsvariablen initialisieren: zunaechst Default-
63 * Werte setzen, dann Konfigurationsdtaei einlesen. */
65 strcpy( Conf_File, "/usr/local/etc/ngircd.conf" );
67 strcpy( Conf_ServerName, "" );
68 strcpy( Conf_ServerInfo, PACKAGE" "VERSION );
70 strcpy( Conf_Oper, "" );
71 strcpy( Conf_OperPwd, "" );
73 strcpy( Conf_MotdFile, "/usr/local/etc/ngircd.motd" );
75 Conf_ListenPorts_Count = 0;
77 Conf_PingTimeout = 120;
78 Conf_PongTimeout = 10;
80 /* Konfigurationsdatei einlesen und validieren */
86 GLOBAL VOID Conf_Exit( VOID )
92 LOCAL VOID Read_Config( VOID )
94 /* Konfigurationsdatei einlesen. */
96 CHAR str[LINE_LEN], *var, *arg, *ptr;
102 fd = fopen( Conf_File, "r" );
105 /* Keine Konfigurationsdatei gefunden */
106 Log( LOG_ALERT, "Can't read configuration \"%s\": %s", Conf_File, strerror( errno ));
107 Log( LOG_ALERT, PACKAGE" exiting due to fatal errors!" );
116 if( ! fgets( str, LINE_LEN, fd )) break;
120 /* Kommentarzeilen und leere Zeilen ueberspringen */
121 if( str[0] == ';' || str[0] == '#' || str[0] == '\0' ) continue;
123 ptr = strchr( str, '=' );
126 Log( LOG_ERR, "%s, line %d: Syntax error!", Conf_File, line );
131 var = str; ngt_TrimStr( var );
132 arg = ptr + 1; ngt_TrimStr( arg );
134 if( strcasecmp( str, "ServerName" ) == 0 )
136 /* Der Server-Name */
137 strncpy( Conf_ServerName, arg, CLIENT_ID_LEN );
138 Conf_ServerName[CLIENT_ID_LEN - 1] = '\0';
141 else if( strcasecmp( str, "ServerInfo" ) == 0 )
143 /* Server-Info-Text */
144 strncpy( Conf_ServerInfo, arg, CLIENT_INFO_LEN );
145 Conf_ServerInfo[CLIENT_INFO_LEN - 1] = '\0';
148 else if( strcasecmp( str, "Operator" ) == 0 )
150 /* Name des IRC Operator */
151 strncpy( Conf_Oper, arg, CLIENT_PASS_LEN );
152 Conf_Oper[CLIENT_PASS_LEN - 1] = '\0';
155 else if( strcasecmp( str, "OperatorPwd" ) == 0 )
157 /* Passwort des IRC Operator */
158 strncpy( Conf_OperPwd, arg, CLIENT_PASS_LEN );
159 Conf_OperPwd[CLIENT_PASS_LEN - 1] = '\0';
162 else if( strcasecmp( str, "ListenPorts" ) == 0 )
164 /* Ports, durch "," getrennt, auf denen der Server
165 * Verbindungen annehmen soll */
166 ptr = strtok( arg, "," );
171 if( Conf_ListenPorts_Count + 1 > LISTEN_PORTS ) Log( LOG_ERR, "Too many listen ports configured. Port %ld ignored.", port );
172 if( port > 0 && port < 0xFFFF ) Conf_ListenPorts[Conf_ListenPorts_Count++] = port;
173 else Log( LOG_ERR, "Illegal port number: %ld. Ignored.", port );
174 ptr = strtok( NULL, "," );
178 else if( strcasecmp( str, "MotdFile" ) == 0 )
180 /* Datei mit der "message of the day" (MOTD) */
181 strncpy( Conf_MotdFile, arg, FNAME_LEN );
182 Conf_MotdFile[FNAME_LEN - 1] = '\0';
185 else if( strcasecmp( str, "PingTimeout" ) == 0 )
188 Conf_PingTimeout = atoi( arg );
189 if(( Conf_PingTimeout ) < 5 ) Conf_PingTimeout = 5;
192 else if( strcasecmp( str, "PongTimeout" ) == 0 )
195 Conf_PongTimeout = atoi( arg );
196 if(( Conf_PongTimeout ) < 5 ) Conf_PongTimeout = 5;
200 if( ! ok ) Log( LOG_ERR, "%s, line %d: Unknown variable \"%s\"!", Conf_File, line, var );
207 LOCAL VOID Validate_Config( VOID )
209 /* Konfiguration ueberpruefen */
211 if( ! Conf_ServerName[0] )
213 /* Kein Servername konfiguriert */
214 Log( LOG_ALERT, "No server name configured (use \"ServerName\")!", Conf_File, strerror( errno ));
215 Log( LOG_ALERT, PACKAGE" exiting due to fatal errors!" );
218 } /* Validate_Config */