]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/conf.c
Introduce option to configure the maximum nick name lenth in ngircd.conf
[ngircd-alex.git] / src / ngircd / conf.c
index b54c3f15feaf893608a5e17d563dd7d69b690445..c55aaf53a775f8945706a73305d3157ed277b623 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: conf.c,v 1.95 2006/11/10 10:05:08 alex Exp $";
+static char UNUSED id[] = "$Id: conf.c,v 1.102 2007/11/21 12:16:36 alex Exp $";
 
 #include "imp.h"
 #include <assert.h>
@@ -205,9 +205,11 @@ Conf_Test( void )
        printf( "  OperCanUseMode = %s\n", Conf_OperCanMode == true ? "yes" : "no" );
        printf( "  OperServerMode = %s\n", Conf_OperServerMode == true? "yes" : "no" );
        printf( "  PredefChannelsOnly = %s\n", Conf_PredefChannelsOnly == true ? "yes" : "no" );
-       printf( "  MaxConnections = %ld\n", Conf_MaxConnections>0 ? Conf_MaxConnections : -1);
-       printf( "  MaxConnectionsIP = %d\n", Conf_MaxConnectionsIP>0 ? Conf_MaxConnectionsIP : -1);
-       printf( "  MaxJoins = %d\n\n", Conf_MaxJoins>0 ? Conf_MaxJoins : -1);
+       printf( "  NoDNS = %s\n", Conf_NoDNS ? "yes" : "no");
+       printf( "  MaxConnections = %ld\n", Conf_MaxConnections);
+       printf( "  MaxConnectionsIP = %d\n", Conf_MaxConnectionsIP);
+       printf( "  MaxJoins = %d\n", Conf_MaxJoins>0 ? Conf_MaxJoins : -1);
+       printf( "  MaxNickLength = %u\n\n", Conf_MaxNickLength - 1);
 
        for( i = 0; i < Conf_Oper_Count; i++ ) {
                if( ! Conf_Oper[i].name[0] ) continue;
@@ -230,7 +232,8 @@ Conf_Test( void )
                printf( "  Port = %u\n", (unsigned int)Conf_Server[i].port );
                printf( "  MyPassword = %s\n", Conf_Server[i].pwd_in );
                printf( "  PeerPassword = %s\n", Conf_Server[i].pwd_out );
-               printf( "  Group = %d\n\n", Conf_Server[i].group );
+               printf( "  Group = %d\n", Conf_Server[i].group );
+               printf( "  Passive = %s\n\n", Conf_Server[i].flags & CONF_SFLAG_DISABLED ? "yes" : "no");
        }
 
        for( i = 0; i < Conf_Channel_Count; i++ ) {
@@ -240,6 +243,8 @@ Conf_Test( void )
                puts( "[CHANNEL]" );
                printf( "  Name = %s\n", Conf_Channel[i].name );
                printf( "  Modes = %s\n", Conf_Channel[i].modes );
+               printf( "  Key = %s\n", Conf_Channel[i].key );
+               printf( "  MaxUsers = %lu\n", Conf_Channel[i].maxusers );
 
                topic = (char*)array_start(&Conf_Channel[i].topic);
                printf( "  Topic = %s\n\n", topic ? topic : "");
@@ -334,6 +339,24 @@ Conf_EnableServer( char *Name, UINT16 Port )
 } /* Conf_EnableServer */
 
 
+GLOBAL bool
+Conf_EnablePassiveServer(const char *Name)
+{
+       /* Enable specified server */
+       int i;
+
+       assert( Name != NULL );
+       for (i = 0; i < MAX_SERVERS; i++) {
+               if ((strcasecmp( Conf_Server[i].name, Name ) == 0) && (Conf_Server[i].port > 0)) {
+                       /* BINGO! Enable server */
+                       Conf_Server[i].flags &= ~CONF_SFLAG_DISABLED;
+                       return true;
+               }
+       }
+       return false;
+} /* Conf_EnablePassiveServer */
+
+
 GLOBAL bool
 Conf_DisableServer( char *Name )
 {
@@ -423,12 +446,14 @@ Set_Defaults( bool InitServers )
        Conf_Channel_Count = 0;
 
        Conf_OperCanMode = false;
+       Conf_NoDNS = false;
        Conf_PredefChannelsOnly = false;
        Conf_OperServerMode = false;
 
-       Conf_MaxConnections = -1;
+       Conf_MaxConnections = 0;
        Conf_MaxConnectionsIP = 5;
        Conf_MaxJoins = 10;
+       Conf_MaxNickLength = CLIENT_NICK_LEN_DEFAULT;
 
        /* Initialize server configuration structures */
        if( InitServers ) for( i = 0; i < MAX_SERVERS; Init_Server_Struct( &Conf_Server[i++] ));
@@ -555,6 +580,8 @@ Read_Config( void )
                                        /* Initialize new channel structure */
                                        strcpy( Conf_Channel[Conf_Channel_Count].name, "" );
                                        strcpy( Conf_Channel[Conf_Channel_Count].modes, "" );
+                                       strcpy( Conf_Channel[Conf_Channel_Count].key, "" );
+                                       Conf_Channel[Conf_Channel_Count].maxusers = 0;
                                        array_free(&Conf_Channel[Conf_Channel_Count].topic);
                                        Conf_Channel_Count++;
                                }
@@ -613,6 +640,27 @@ Check_ArgIsTrue( const char *Arg )
 } /* Check_ArgIsTrue */
 
 
+static unsigned int Handle_MaxNickLength(int Line, const char *Arg)
+{
+       unsigned new;
+
+       new = (unsigned) atoi(Arg) + 1;
+       if (new > CLIENT_NICK_LEN) {
+               Config_Error(LOG_WARNING,
+                            "%s, line %d: Value of \"MaxNickLength\" exceeds %u!",
+                            NGIRCd_ConfFile, Line, CLIENT_NICK_LEN - 1);
+               return CLIENT_NICK_LEN;
+       }
+       if (new < 2) {
+               Config_Error(LOG_WARNING,
+                            "%s, line %d: Value of \"MaxNickLength\" must be at least 1!",
+                            NGIRCd_ConfFile, Line);
+               return 2;
+       }
+       return new;
+} /* Handle_MaxNickLength */
+
+
 static void
 Handle_GLOBAL( int Line, char *Var, char *Arg )
 {
@@ -760,6 +808,11 @@ Handle_GLOBAL( int Line, char *Var, char *Arg )
                Conf_PredefChannelsOnly = Check_ArgIsTrue( Arg );
                return;
        }
+       if( strcasecmp( Var, "NoDNS" ) == 0 ) {
+               /* don't do reverse dns lookups when clients connect? */
+               Conf_NoDNS = Check_ArgIsTrue( Arg );
+               return;
+       }
        if( strcasecmp( Var, "OperCanUseMode" ) == 0 ) {
                /* Are IRC operators allowed to use MODE in channels they aren't Op in? */
                Conf_OperCanMode = Check_ArgIsTrue( Arg );
@@ -771,7 +824,7 @@ Handle_GLOBAL( int Line, char *Var, char *Arg )
                return;
        }
        if( strcasecmp( Var, "MaxConnections" ) == 0 ) {
-               /* Maximum number of connections. Values <= 0 are equal to "no limit". */
+               /* Maximum number of connections. 0 -> "no limit". */
 #ifdef HAVE_ISDIGIT
                if( ! isdigit( (int)*Arg )) Config_Error_NaN( Line, Var);
                else
@@ -780,7 +833,7 @@ Handle_GLOBAL( int Line, char *Var, char *Arg )
                return;
        }
        if( strcasecmp( Var, "MaxConnectionsIP" ) == 0 ) {
-               /* Maximum number of simultaneous connections from one IP. Values <= 0 -> "no limit" */
+               /* Maximum number of simultaneous connections from one IP. 0 -> "no limit" */
 #ifdef HAVE_ISDIGIT
                if( ! isdigit( (int)*Arg )) Config_Error_NaN( Line, Var );
                else
@@ -789,7 +842,7 @@ Handle_GLOBAL( int Line, char *Var, char *Arg )
                return;
        }
        if( strcasecmp( Var, "MaxJoins" ) == 0 ) {
-               /* Maximum number of channels a user can join. Values <= 0 are equal to "no limit". */
+               /* Maximum number of channels a user can join. 0 -> "no limit". */
 #ifdef HAVE_ISDIGIT
                if( ! isdigit( (int)*Arg )) Config_Error_NaN( Line, Var );
                else
@@ -797,6 +850,13 @@ Handle_GLOBAL( int Line, char *Var, char *Arg )
                Conf_MaxJoins = atoi( Arg );
                return;
        }
+       if( strcasecmp( Var, "MaxNickLength" ) == 0 ) {
+               /* Maximum length of a nick name; must be same on all servers
+                * within the IRC network! */
+               Conf_MaxNickLength = Handle_MaxNickLength(Line, Arg);
+               return;
+       }
+
        if( strcasecmp( Var, "Listen" ) == 0 ) {
                /* IP-Address to bind sockets */
                len = strlcpy( Conf_ListenAddress, Arg, sizeof( Conf_ListenAddress ));
@@ -916,12 +976,32 @@ Handle_SERVER( int Line, char *Var, char *Arg )
                New_Server.group = atoi( Arg );
                return;
        }
+       if( strcasecmp( Var, "Passive" ) == 0 ) {
+               if (Check_ArgIsTrue(Arg))
+                       New_Server.flags |= CONF_SFLAG_DISABLED;
+               return;
+       }
        
        Config_Error( LOG_ERR, "%s, line %d (section \"Server\"): Unknown variable \"%s\"!",
                                                                NGIRCd_ConfFile, Line, Var );
 } /* Handle_SERVER */
 
 
+static bool
+Handle_Channelname(size_t chancount, const char *name)
+{
+       size_t size = sizeof( Conf_Channel[chancount].name );
+       char *dest = Conf_Channel[chancount].name;
+
+       if (*name && *name != '#') {
+               *dest = '#';
+               --size;
+               ++dest;
+       }
+       return size > strlcpy(dest, name, size);
+}
+
+
 static void
 Handle_CHANNEL( int Line, char *Var, char *Arg )
 {
@@ -935,9 +1015,7 @@ Handle_CHANNEL( int Line, char *Var, char *Arg )
                chancount = Conf_Channel_Count - 1;
 
        if( strcasecmp( Var, "Name" ) == 0 ) {
-               /* Name of the channel */
-               len = strlcpy( Conf_Channel[chancount].name, Arg, sizeof( Conf_Channel[chancount].name ));
-               if (len >= sizeof( Conf_Channel[chancount].name ))
+               if (!Handle_Channelname(chancount, Arg))
                        Config_Error_TooLong( Line, Var );
                return;
        }
@@ -955,6 +1033,22 @@ Handle_CHANNEL( int Line, char *Var, char *Arg )
                return;
        }
 
+       if( strcasecmp( Var, "Key" ) == 0 ) {
+               /* Initial Channel Key (mode k) */
+               len = strlcpy(Conf_Channel[chancount].key, Arg, sizeof(Conf_Channel[chancount].key));
+               if (len >= sizeof( Conf_Channel[chancount].key ))
+                       Config_Error_TooLong(Line, Var);
+               return;
+       }
+
+       if( strcasecmp( Var, "MaxUsers" ) == 0 ) {
+               /* maximum user limit, mode l */
+               Conf_Channel[chancount].maxusers = (unsigned long) atol(Arg);
+               if (Conf_Channel[chancount].maxusers == 0)
+                       Config_Error_NaN(Line, Var);
+               return;
+       }
+
        Config_Error( LOG_ERR, "%s, line %d (section \"Channel\"): Unknown variable \"%s\"!",
                                                                NGIRCd_ConfFile, Line, Var );
 } /* Handle_CHANNEL */