]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/conf.c
New configuration option "Listen" to bind the server to a specific ip.
[ngircd-alex.git] / src / ngircd / conf.c
index 011dffec691d3f3ce287305f7d4a1bd157c09a47..0abb3c81531c40d791cef63ddc41113f3b1d2b1f 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: conf.c,v 1.53 2002/12/31 16:12:50 alex Exp $";
+static char UNUSED id[] = "$Id: conf.c,v 1.60 2003/09/11 12:05:28 alex Exp $";
 
 #include "imp.h"
 #include <assert.h>
@@ -108,7 +108,7 @@ Conf_Test( VOID )
        puts( "[GLOBAL]" );
        printf( "  ServerName = %s\n", Conf_ServerName );
        printf( "  ServerInfo = %s\n", Conf_ServerInfo );
-       printf( "  ServerPwd = %s\n", Conf_ServerPwd );
+       printf( "  Password = %s\n", Conf_ServerPwd );
        printf( "  AdminInfo1 = %s\n", Conf_ServerAdmin1 );
        printf( "  AdminInfo2 = %s\n", Conf_ServerAdmin2 );
        printf( "  AdminEMail = %s\n", Conf_ServerAdminMail );
@@ -120,6 +120,7 @@ Conf_Test( VOID )
                printf( "%u", Conf_ListenPorts[i] );
        }
        puts( "" );
+       printf( "  Listen = %s\n", Conf_ListenAddress );
        pwd = getpwuid( Conf_UID );
        if( pwd ) printf( "  ServerUID = %s\n", pwd->pw_name );
        else printf( "  ServerUID = %ld\n", (LONG)Conf_UID );
@@ -210,7 +211,6 @@ Conf_UnsetServer( CONN_ID Idx )
                                Conf_Server[i].lasttry = time( NULL ) - Conf_ConnectRetry + RECONNECT_DELAY;
                        }
                }
-               break;
        }
 } /* Conf_UnsetServer */
 
@@ -231,9 +231,9 @@ GLOBAL INT
 Conf_GetServer( CONN_ID Idx )
 {
        /* Get index of server in configuration structure */
-
-       INT i;
-
+       
+       INT i = 0;
+       
        assert( Idx > NONE );
 
        for( i = 0; i < MAX_SERVERS; i++ )
@@ -330,7 +330,7 @@ Set_Defaults( BOOLEAN InitServers )
        INT i;
 
        strcpy( Conf_ServerName, "" );
-       sprintf( Conf_ServerInfo, "%s %s", PACKAGEVERSION );
+       sprintf( Conf_ServerInfo, "%s %s", PACKAGE_NAME, PACKAGE_VERSION );
        strcpy( Conf_ServerPwd, "" );
 
        strcpy( Conf_ServerAdmin1, "" );
@@ -341,6 +341,7 @@ Set_Defaults( BOOLEAN InitServers )
        strlcat( Conf_MotdFile, MOTD_FILE, sizeof( Conf_MotdFile ));
 
        Conf_ListenPorts_Count = 0;
+       strcpy( Conf_ListenAddress, "" );
 
        Conf_UID = Conf_GID = 0;
        
@@ -368,7 +369,7 @@ Read_Config( VOID )
        /* Read configuration file. */
 
        CHAR section[LINE_LEN], str[LINE_LEN], *var, *arg, *ptr;
-       INT line, i;
+       INT line, i, n;
        FILE *fd;
 
        /* Open configuration file */
@@ -377,7 +378,7 @@ Read_Config( VOID )
        {
                /* No configuration file found! */
                Config_Error( LOG_ALERT, "Can't read configuration \"%s\": %s", NGIRCd_ConfFile, strerror( errno ));
-               Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE );
+               Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
                exit( 1 );
        }
 
@@ -385,11 +386,37 @@ Read_Config( VOID )
 
        /* Clean up server configuration structure: mark all already
         * configured servers as "once" so that they are deleted
-        * after the next disconnect and delete all unused servers. */
+        * after the next disconnect and delete all unused servers.
+        * And delete all servers which are "duplicates" of servers
+        * that are already marked as "once" (such servers have been
+        * created by the last rehash but are now useless). */
        for( i = 0; i < MAX_SERVERS; i++ )
        {
                if( Conf_Server[i].conn_id == NONE ) Init_Server_Struct( &Conf_Server[i] );
-               else Conf_Server[i].flags |= CONF_SFLAG_ONCE;
+               else
+               {
+                       /* This structure is in use ... */
+                       if( Conf_Server[i].flags & CONF_SFLAG_ONCE )
+                       {
+                               /* Check for duplicates */
+                               for( n = 0; n < MAX_SERVERS; n++ )
+                               {
+                                       if( n == i ) continue;
+
+                                       if( Conf_Server[i].conn_id == Conf_Server[n].conn_id )
+                                       {
+                                               Init_Server_Struct( &Conf_Server[n] );
+                                               Log( LOG_DEBUG, "Deleted unused duplicate server %d (kept %d).", n, i );
+                                       }
+                               }
+                       }
+                       else
+                       {
+                               /* Mark server as "once" */
+                               Conf_Server[i].flags |= CONF_SFLAG_ONCE;
+                               Log( LOG_DEBUG, "Marked server %d as \"once\"", i );
+                       }
+               }
        }
 
        /* Initialize variables */
@@ -674,6 +701,15 @@ Handle_GLOBAL( INT Line, CHAR *Var, CHAR *Arg )
                Conf_MaxJoins = atoi( Arg );
                return;
        }
+       if( strcasecmp( Var, "Listen" ) == 0 )
+       {
+               /* IP-Address to bind sockets */
+               if( strlcpy( Conf_ListenAddress, Arg, sizeof( Conf_ListenAddress )) >= sizeof( Conf_ListenAddress ))
+               {
+                       Config_Error( LOG_WARNING, "%s, line %d: Value of \"Listen\" too long!", NGIRCd_ConfFile, Line );
+                       return;
+               }
+       }
 
        Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
 } /* Handle_GLOBAL */
@@ -808,7 +844,18 @@ Validate_Config( BOOLEAN Configtest )
                Config_Error( LOG_ALERT, "No server name configured in \"%s\" ('ServerName')!", NGIRCd_ConfFile );
                if( ! Configtest )
                {
-                       Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE );
+                       Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
+                       exit( 1 );
+               }
+       }
+       
+       if( ! strchr( Conf_ServerName, '.' ))
+       {
+               /* No dot in server name! */
+               Config_Error( LOG_ALERT, "Invalid server name configured in \"%s\" ('ServerName'): Dot missing!", NGIRCd_ConfFile );
+               if( ! Configtest )
+               {
+                       Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
                        exit( 1 );
                }
        }
@@ -820,7 +867,7 @@ Validate_Config( BOOLEAN Configtest )
                Config_Error( LOG_ALERT, "No administrator email address configured in \"%s\" ('AdminEMail')!", NGIRCd_ConfFile );
                if( ! Configtest )
                {
-                       Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE );
+                       Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
                        exit( 1 );
                }
        }