From: Alexander Barton Date: Sun, 30 Dec 2001 19:26:11 +0000 (+0000) Subject: - Unterstuetzung fuer die Konfigurationsdatei eingebaut. X-Git-Tag: rel-0-0-1~14 X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=ngircd-alex.git;a=commitdiff_plain;h=9856253dc40be19a0e4713b12187732e7420febe - Unterstuetzung fuer die Konfigurationsdatei eingebaut. --- diff --git a/src/ngircd/client.c b/src/ngircd/client.c index 913370c8..5b8e6547 100644 --- a/src/ngircd/client.c +++ b/src/ngircd/client.c @@ -9,7 +9,7 @@ * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste * der an comBase beteiligten Autoren finden Sie in der Datei AUTHORS. * - * $Id: client.c,v 1.12 2001/12/29 20:18:18 alex Exp $ + * $Id: client.c,v 1.13 2001/12/30 19:26:11 alex Exp $ * * client.c: Management aller Clients * @@ -21,6 +21,9 @@ * Server gewesen, so existiert eine entsprechende CONNECTION-Struktur. * * $Log: client.c,v $ + * Revision 1.13 2001/12/30 19:26:11 alex + * - Unterstuetzung fuer die Konfigurationsdatei eingebaut. + * * Revision 1.12 2001/12/29 20:18:18 alex * - neue Funktion Client_SetHostname(). * @@ -75,6 +78,7 @@ #include #include "channel.h" +#include "conf.h" #include "conn.h" #include "irc.h" #include "log.h" @@ -98,6 +102,7 @@ GLOBAL VOID Client_Init( VOID ) if( ! This_Server ) { Log( LOG_EMERG, "Can't allocate client structure for server! Going down." ); + Log( LOG_ALERT, PACKAGE" exiting due to fatal errors!" ); exit( 1 ); } @@ -111,7 +116,7 @@ GLOBAL VOID Client_Init( VOID ) h = gethostbyname( This_Server->host ); if( h ) strcpy( This_Server->host, h->h_name ); - strcpy( This_Server->nick, This_Server->host ); + strcpy( This_Server->nick, Conf_ServerName ); My_Clients = This_Server; } /* Client_Init */ @@ -264,7 +269,7 @@ GLOBAL CHAR *Client_GetID( CLIENT *Client ) assert( Client != NULL ); - if( Client->type == CLIENT_SERVER ) return Client->host; + if( Client->type == CLIENT_SERVER ) return Client->nick; sprintf( GetID_Buffer, "%s!%s@%s", Client->nick, Client->user, Client->host ); return GetID_Buffer; diff --git a/src/ngircd/conf.c b/src/ngircd/conf.c index 8a2085a7..fec8903a 100644 --- a/src/ngircd/conf.c +++ b/src/ngircd/conf.c @@ -9,11 +9,14 @@ * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste * der an comBase beteiligten Autoren finden Sie in der Datei AUTHORS. * - * $Id: conf.c,v 1.4 2001/12/26 22:48:53 alex Exp $ + * $Id: conf.c,v 1.5 2001/12/30 19:26:11 alex Exp $ * * conf.h: Konfiguration des ngircd * * $Log: conf.c,v $ + * Revision 1.5 2001/12/30 19:26:11 alex + * - Unterstuetzung fuer die Konfigurationsdatei eingebaut. + * * Revision 1.4 2001/12/26 22:48:53 alex * - MOTD-Datei ist nun konfigurierbar und wird gelesen. * @@ -33,28 +36,44 @@ #include #include +#include +#include +#include + +#include "client.h" +#include "log.h" +#include "tool.h" #include #include "conf.h" +#define MAX_LINE_LEN 246 /* max. Laenge einer Konfigurationszeile */ + + LOCAL VOID Read_Config( VOID ); +LOCAL VOID Validate_Config( VOID ); GLOBAL VOID Conf_Init( VOID ) { /* Konfigurationsvariablen initialisieren: zunaechst Default- * Werte setzen, dann Konfigurationsdtaei einlesen. */ - + strcpy( Conf_File, "/usr/local/etc/ngircd.conf" ); + + strcpy( Conf_ServerName, "" ); + + strcpy( Conf_MotdFile, "/usr/local/etc/ngircd.motd" ); + + Conf_ListenPorts_Count = 0; Conf_PingTimeout = 120; Conf_PongTimeout = 10; - strcpy( Conf_MotdFile, "/usr/local/etc/ngircd.motd" ); - - /* Konfigurationsdatei einlesen */ + /* Konfigurationsdatei einlesen und validieren */ Read_Config( ); + Validate_Config( ); } /* Config_Init */ @@ -67,9 +86,108 @@ GLOBAL VOID Conf_Exit( VOID ) LOCAL VOID Read_Config( VOID ) { /* Konfigurationsdatei einlesen. */ + + CHAR str[MAX_LINE_LEN], *var, *arg, *ptr; + BOOLEAN ok; + INT32 port; + INT line; + FILE *fd; + + fd = fopen( Conf_File, "r" ); + if( ! fd ) + { + /* Keine Konfigurationsdatei gefunden */ + Log( LOG_ALERT, "Can't read configuration \"%s\": %s", Conf_File, strerror( errno )); + Log( LOG_ALERT, PACKAGE" exiting due to fatal errors!" ); + exit( 1 ); + } + + line = 0; + while( TRUE ) + { + if( ! fgets( str, MAX_LINE_LEN, fd )) break; + ngt_TrimStr( str ); + line++; + + /* Kommentarzeilen und leere Zeilen ueberspringen */ + if( str[0] == ';' || str[0] == '#' || str[0] == '\0' ) continue; + + ok = FALSE; + + ptr = strchr( str, '=' ); + if( ! ptr ) + { + Log( LOG_ERR, "%s, line %d: Syntax error!", Conf_File, line ); + continue; + } + *ptr = '\0'; + + var = str; ngt_TrimStr( var ); + arg = ptr + 1; ngt_TrimStr( arg ); + + if( strcasecmp( str, "ServerName" ) == 0 ) + { + /* Der Server-Name */ + strncpy( Conf_ServerName, arg, CLIENT_ID_LEN ); + Conf_ServerName[CLIENT_ID_LEN] = '\0'; + ok = TRUE; + } + else if( strcasecmp( str, "ListenPorts" ) == 0 ) + { + /* Ports, durch "," getrennt, auf denen der Server + * Verbindungen annehmen soll */ + ptr = strtok( arg, "," ); + while( ptr ) + { + ngt_TrimStr( ptr ); + port = atol( ptr ); + if( Conf_ListenPorts_Count + 1 > LISTEN_PORTS ) Log( LOG_ERR, "Too many listen ports configured. Port %ld ignored.", port ); + if( port > 0 && port < 0xFFFF ) Conf_ListenPorts[Conf_ListenPorts_Count++] = port; + else Log( LOG_ERR, "Illegal port number: %ld. Ignored.", port ); + ptr = strtok( NULL, "," ); + } + ok = TRUE; + } + else if( strcasecmp( str, "MotdFile" ) == 0 ) + { + /* Datei mit der "message of the day" (MOTD) */ + strncpy( Conf_MotdFile, arg, FNAME_LEN ); + Conf_MotdFile[FNAME_LEN] = '\0'; + ok = TRUE; + } + else if( strcasecmp( str, "PingTimeout" ) == 0 ) + { + /* PING-Timeout */ + Conf_PingTimeout = atoi( arg ); + if(( Conf_PingTimeout ) < 5 ) Conf_PingTimeout = 5; + ok = TRUE; + } + else if( strcasecmp( str, "PongTimeout" ) == 0 ) + { + /* PONG-Timeout */ + Conf_PongTimeout = atoi( arg ); + if(( Conf_PongTimeout ) < 5 ) Conf_PongTimeout = 5; + ok = TRUE; + } + + if( ! ok ) Log( LOG_ERR, "%s, line %d: Unknown variable \"%s\"!", Conf_File, line, var ); + } - /* ... */ + fclose( fd ); } /* Read_Config */ +LOCAL VOID Validate_Config( VOID ) +{ + /* Konfiguration ueberpruefen */ + + if( ! Conf_ServerName[0] ) + { + /* Kein Servername konfiguriert */ + Log( LOG_ALERT, "No server name configured (use \"ServerName\")!", Conf_File, strerror( errno )); + Log( LOG_ALERT, PACKAGE" exiting due to fatal errors!" ); + exit( 1 ); + } +} /* Validate_Config */ + /* -eof- */ diff --git a/src/ngircd/conf.h b/src/ngircd/conf.h index 07ed1eda..ceea6a52 100644 --- a/src/ngircd/conf.h +++ b/src/ngircd/conf.h @@ -9,11 +9,14 @@ * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste * der an comBase beteiligten Autoren finden Sie in der Datei AUTHORS. * - * $Id: conf.h,v 1.4 2001/12/26 22:48:53 alex Exp $ + * $Id: conf.h,v 1.5 2001/12/30 19:26:11 alex Exp $ * * conf.h: Konfiguration des ngircd (Header) * * $Log: conf.h,v $ + * Revision 1.5 2001/12/30 19:26:11 alex + * - Unterstuetzung fuer die Konfigurationsdatei eingebaut. + * * Revision 1.4 2001/12/26 22:48:53 alex * - MOTD-Datei ist nun konfigurierbar und wird gelesen. * @@ -33,14 +36,20 @@ #define FNAME_LEN 256 +#define LISTEN_PORTS 16 + + +GLOBAL CHAR Conf_File[FNAME_LEN]; /* Konfigurationsdatei */ +GLOBAL CHAR Conf_ServerName[CLIENT_ID_LEN]; /* Name ("Nick") des Servers */ -GLOBAL CHAR Conf_File[FNAME_LEN]; /* Konfigurationsdatei */ +GLOBAL CHAR Conf_MotdFile[FNAME_LEN]; /* Datei mit MOTD-Text */ -GLOBAL INT Conf_PingTimeout; /* Ping Timeout */ -GLOBAL INT Conf_PongTimeout; /* Pong Timeout */ +GLOBAL INT Conf_ListenPorts[LISTEN_PORTS]; /* Ports, auf denen der Server Verbindungen */ +GLOBAL INT Conf_ListenPorts_Count; /* entgegen nimmt sowie deren Anzahl */ -GLOBAL CHAR Conf_MotdFile[FNAME_LEN]; /* Datei mit MOTD-Text */ +GLOBAL INT Conf_PingTimeout; /* Ping Timeout */ +GLOBAL INT Conf_PongTimeout; /* Pong Timeout */ GLOBAL VOID Conf_Init( VOID ); diff --git a/src/ngircd/conn.c b/src/ngircd/conn.c index d2479db5..1a166898 100644 --- a/src/ngircd/conn.c +++ b/src/ngircd/conn.c @@ -9,11 +9,14 @@ * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste * der an comBase beteiligten Autoren finden Sie in der Datei AUTHORS. * - * $Id: conn.c,v 1.21 2001/12/29 22:33:36 alex Exp $ + * $Id: conn.c,v 1.22 2001/12/30 19:26:11 alex Exp $ * * connect.h: Verwaltung aller Netz-Verbindungen ("connections") * * $Log: conn.c,v $ + * Revision 1.22 2001/12/30 19:26:11 alex + * - Unterstuetzung fuer die Konfigurationsdatei eingebaut. + * * Revision 1.21 2001/12/29 22:33:36 alex * - bessere Dokumentation des Modules bzw. der Funktionen. * @@ -288,7 +291,7 @@ GLOBAL BOOLEAN Conn_NewListener( CONST INT Port ) if( sock > My_Max_Fd ) My_Max_Fd = sock; - Log( LOG_INFO, "Now listening on port %d, socket %d.", Port, sock ); + Log( LOG_INFO, "Now listening on port %d (socket %d).", Port, sock ); return TRUE; } /* Conn_NewListener */ diff --git a/src/ngircd/irc.c b/src/ngircd/irc.c index e9061890..c476d34f 100644 --- a/src/ngircd/irc.c +++ b/src/ngircd/irc.c @@ -9,11 +9,14 @@ * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste * der an comBase beteiligten Autoren finden Sie in der Datei AUTHORS. * - * $Id: irc.c,v 1.14 2001/12/30 11:42:00 alex Exp $ + * $Id: irc.c,v 1.15 2001/12/30 19:26:11 alex Exp $ * * irc.c: IRC-Befehle * * $Log: irc.c,v $ + * Revision 1.15 2001/12/30 19:26:11 alex + * - Unterstuetzung fuer die Konfigurationsdatei eingebaut. + * * Revision 1.14 2001/12/30 11:42:00 alex * - der Server meldet nun eine ordentliche "Start-Zeit". * @@ -480,9 +483,9 @@ LOCAL BOOLEAN Hello_User( CLIENT *Client ) Log( LOG_NOTICE, "User \"%s!%s@%s\" (%s) registered (connection %d).", Client->nick, Client->user, Client->host, Client->name, Client->conn_id ); IRC_WriteStrClient( Client, This_Server, RPL_WELCOME_MSG, Client->nick, Client_GetID( Client )); - IRC_WriteStrClient( Client, This_Server, RPL_YOURHOST_MSG, Client->nick, This_Server->host ); + IRC_WriteStrClient( Client, This_Server, RPL_YOURHOST_MSG, Client->nick, This_Server->nick ); IRC_WriteStrClient( Client, This_Server, RPL_CREATED_MSG, Client->nick, NGIRCd_StartStr ); - IRC_WriteStrClient( Client, This_Server, RPL_MYINFO_MSG, Client->nick, This_Server->host ); + IRC_WriteStrClient( Client, This_Server, RPL_MYINFO_MSG, Client->nick, This_Server->nick ); Client->type = CLIENT_USER; @@ -506,7 +509,7 @@ LOCAL BOOLEAN Show_MOTD( CLIENT *Client ) return IRC_WriteStrClient( Client, This_Server, ERR_NOMOTD_MSG, Client->nick ); } - IRC_WriteStrClient( Client, This_Server, RPL_MOTDSTART_MSG, Client->nick, This_Server->host ); + IRC_WriteStrClient( Client, This_Server, RPL_MOTDSTART_MSG, Client->nick, This_Server->nick ); while( TRUE ) { if( ! fgets( line, 126, fd )) break; diff --git a/src/ngircd/ngircd.c b/src/ngircd/ngircd.c index e630ea70..4e18f6ac 100644 --- a/src/ngircd/ngircd.c +++ b/src/ngircd/ngircd.c @@ -9,11 +9,14 @@ * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste * der an comBase beteiligten Autoren finden Sie in der Datei AUTHORS. * - * $Id: ngircd.c,v 1.13 2001/12/30 11:42:00 alex Exp $ + * $Id: ngircd.c,v 1.14 2001/12/30 19:26:12 alex Exp $ * * ngircd.c: Hier beginnt alles ;-) * * $Log: ngircd.c,v $ + * Revision 1.14 2001/12/30 19:26:12 alex + * - Unterstuetzung fuer die Konfigurationsdatei eingebaut. + * * Revision 1.13 2001/12/30 11:42:00 alex * - der Server meldet nun eine ordentliche "Start-Zeit". * @@ -88,6 +91,8 @@ LOCAL VOID Initialize_Signal_Handler( VOID ); LOCAL VOID Signal_Handler( INT Signal ); +LOCAL VOID Initialize_Listen_Ports( VOID ); + GLOBAL INT main( INT argc, CONST CHAR *argv[] ) { @@ -110,9 +115,9 @@ GLOBAL INT main( INT argc, CONST CHAR *argv[] ) /* Signal-Handler initialisieren */ Initialize_Signal_Handler( ); - - if( ! Conn_NewListener( 6668 )) exit( 1 ); - if( ! Conn_NewListener( 6669 )) Log( LOG_WARNING, "Can't create second listening socket!" ); + + /* Listen-Ports initialisieren */ + Initialize_Listen_Ports( ); /* Hauptschleife */ while( ! NGIRCd_Quit ) @@ -177,4 +182,26 @@ LOCAL VOID Signal_Handler( INT Signal ) } /* Signal_Handler */ +LOCAL VOID Initialize_Listen_Ports( VOID ) +{ + /* Ports, auf denen der Server Verbindungen entgegennehmen + * soll, initialisieren */ + + INT created, i; + + created = 0; + for( i = 0; i < Conf_ListenPorts_Count; i++ ) + { + if( Conn_NewListener( Conf_ListenPorts[i] )) created++; + else Log( LOG_ERR, "Can't listen on port %d!", Conf_ListenPorts[i] ); + } + + if( created < 1 ) + { + Log( LOG_ALERT, "Server isn't listening on a single port!" ); + Log( LOG_ALERT, PACKAGE" exiting due to fatal errors!" ); + exit( 1 ); + } +} /* Initialize_Listen_Ports */ + /* -eof- */