]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/conf.c
Allow pre-defined server local channels ("&").
[ngircd-alex.git] / src / ngircd / conf.c
index a60a10e7a250586ce6b51e21f8b9ddb8004bba56..fc12cd9ba826ed19903120433464b6d148a59f3d 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001,2002 Alexander Barton (alex@barton.de)
+ * Copyright (c)2001-2008 Alexander Barton (alex@barton.de)
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -42,6 +42,7 @@
 #include "client.h"
 #include "defines.h"
 #include "log.h"
+#include "match.h"
 #include "resolve.h"
 #include "tool.h"
 
@@ -53,7 +54,7 @@ static bool Use_Log = true;
 static CONF_SERVER New_Server;
 static int New_Server_Idx;
 
-
+static size_t Conf_Channel_Count;
 static void Set_Defaults PARAMS(( bool InitServers ));
 static bool Read_Config PARAMS(( bool ngircd_starting ));
 static bool Validate_Config PARAMS(( bool TestOnly, bool Rehash ));
@@ -205,8 +206,9 @@ Conf_Test( void )
        struct passwd *pwd;
        struct group *grp;
        unsigned int i;
-       char *topic;
        bool config_valid;
+       size_t predef_channel_count;
+       struct Conf_Channel *predef_chan;
 
        Use_Log = false;
 
@@ -258,6 +260,7 @@ Conf_Test( void )
        printf( "  OperServerMode = %s\n", yesno_to_str(Conf_OperServerMode));
        printf( "  PredefChannelsOnly = %s\n", yesno_to_str(Conf_PredefChannelsOnly));
        printf( "  NoDNS = %s\n", yesno_to_str(Conf_NoDNS));
+       printf( "  NoIdent = %s\n", yesno_to_str(Conf_NoIdent));
 
 #ifdef WANT_IPV6
        printf("  ConnectIPv4 = %s\n", yesno_to_str(Conf_ConnectIPv6));
@@ -292,22 +295,25 @@ Conf_Test( void )
 #endif
                printf( "  MyPassword = %s\n", Conf_Server[i].pwd_in );
                printf( "  PeerPassword = %s\n", Conf_Server[i].pwd_out );
+               printf( "  ServiceMask = %s\n", Conf_Server[i].svs_mask);
                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++ ) {
-               if( ! Conf_Channel[i].name[0] ) continue;
+       predef_channel_count = array_length(&Conf_Channels, sizeof(*predef_chan));
+       predef_chan = array_start(&Conf_Channels);
+
+       for (i = 0; i < predef_channel_count; i++, predef_chan++) {
+               if (!predef_chan->name[0])
+                       continue;
 
                /* Valid "Channel" section */
                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 : "");
+               printf("  Name = %s\n", predef_chan->name);
+               printf("  Modes = %s\n", predef_chan->modes);
+               printf("  Key = %s\n", predef_chan->key);
+               printf("  MaxUsers = %lu\n", predef_chan->maxusers);
+               printf("  Topic = %s\n\n", predef_chan->topic);
        }
 
        return (config_valid ? 0 : 1);
@@ -469,6 +475,16 @@ Conf_AddServer( char *Name, UINT16 Port, char *Host, char *MyPwd, char *PeerPwd
 } /* Conf_AddServer */
 
 
+/**
+ * Check if the given nick name is an service
+ */
+GLOBAL bool
+Conf_IsService(int ConfServer, char *Nick)
+{
+       return MatchCaseInsensitive(Conf_Server[ConfServer].svs_mask, Nick);
+} /* Conf_IsService */
+
+
 static void
 Set_Defaults( bool InitServers )
 {
@@ -507,6 +523,7 @@ Set_Defaults( bool InitServers )
 
        Conf_OperCanMode = false;
        Conf_NoDNS = false;
+       Conf_NoIdent = false;
        Conf_PredefChannelsOnly = false;
        Conf_OperServerMode = false;
 
@@ -642,20 +659,11 @@ Read_Config( bool ngircd_starting )
                                else New_Server_Idx = i;
                                continue;
                        }
-                       if( strcasecmp( section, "[CHANNEL]" ) == 0 ) {
-                               if( Conf_Channel_Count + 1 > MAX_DEFCHANNELS ) {
-                                       Config_Error( LOG_ERR, "Too many pre-defined channels configured." );
-                               } else {
-                                       /* 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++;
-                               }
+                       if (strcasecmp(section, "[CHANNEL]") == 0) {
+                               Conf_Channel_Count++;
                                continue;
                        }
+
                        Config_Error( LOG_ERR, "%s, line %d: Unknown section \"%s\"!", NGIRCd_ConfFile, line, section );
                        section[0] = 0x1;
                }
@@ -891,6 +899,19 @@ Handle_GLOBAL( int Line, char *Var, char *Arg )
                Conf_NoDNS = Check_ArgIsTrue( Arg );
                return;
        }
+       if (strcasecmp(Var, "NoIdent") == 0) {
+               /* don't do IDENT lookups when clients connect? */
+               Conf_NoIdent = Check_ArgIsTrue(Arg);
+#ifndef IDENTAUTH
+               if (!Conf_NoIdent) {
+                       /* user has enabled ident lookups explicitly, but ... */
+                       Config_Error(LOG_WARNING,
+                               "%s: line %d: NoIdent=False, but ngircd was built without IDENT support",
+                               NGIRCd_ConfFile, Line);
+               }
+#endif
+               return;
+       }
 #ifdef WANT_IPV6
        /* the default setting for all the WANT_IPV6 special options is 'true' */
        if( strcasecmp( Var, "ConnectIPv6" ) == 0 ) {
@@ -1128,19 +1149,29 @@ Handle_SERVER( int Line, char *Var, char *Arg )
                        New_Server.flags |= CONF_SFLAG_DISABLED;
                return;
        }
-       
+       if (strcasecmp(Var, "ServiceMask") == 0) {
+               len = strlcpy(New_Server.svs_mask, ngt_LowerStr(Arg),
+                             sizeof(New_Server.svs_mask));
+               if (len >= sizeof(New_Server.svs_mask))
+                       Config_Error_TooLong(Line, Var);
+               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)
+Handle_Channelname(struct Conf_Channel *new_chan, const char *name)
 {
-       size_t size = sizeof( Conf_Channel[chancount].name );
-       char *dest = Conf_Channel[chancount].name;
+       size_t size = sizeof(new_chan->name);
+       char *dest = new_chan->name;
 
-       if (*name && *name != '#') {
+       /* Channels names must begin with "&" or "#", if it is
+        * missing, add a '#'. This is only here for user convenience.
+        */
+       if (*name && *name != '#' && *name != '&') {
                *dest = '#';
                --size;
                ++dest;
@@ -1150,48 +1181,54 @@ Handle_Channelname(size_t chancount, const char *name)
 
 
 static void
-Handle_CHANNEL( int Line, char *Var, char *Arg )
+Handle_CHANNEL(int Line, char *Var, char *Arg)
 {
        size_t len;
-       size_t chancount = 0;
+       size_t chancount;
+       struct Conf_Channel *chan;
 
        assert( Line > 0 );
        assert( Var != NULL );
        assert( Arg != NULL );
-       if (Conf_Channel_Count > 0)
-               chancount = Conf_Channel_Count - 1;
+       assert(Conf_Channel_Count > 0);
 
-       if( strcasecmp( Var, "Name" ) == 0 ) {
-               if (!Handle_Channelname(chancount, Arg))
-                       Config_Error_TooLong( Line, Var );
+       chancount = Conf_Channel_Count - 1;
+
+       chan = array_alloc(&Conf_Channels, sizeof(*chan), chancount);
+       if (!chan) {
+               Config_Error(LOG_ERR, "Could not allocate memory for predefined channel (%d:%s = %s)", Line, Var, Arg);
                return;
        }
-       if( strcasecmp( Var, "Modes" ) == 0 ) {
+       if (strcasecmp(Var, "Name") == 0) {
+               if (!Handle_Channelname(chan, Arg))
+                       Config_Error_TooLong(Line, Var);
+               return;
+       }
+       if (strcasecmp(Var, "Modes") == 0) {
                /* Initial modes */
-               len = strlcpy( Conf_Channel[chancount].modes, Arg, sizeof( Conf_Channel[chancount].modes ));
-               if (len >= sizeof( Conf_Channel[chancount].modes ))
+               len = strlcpy(chan->modes, Arg, sizeof(chan->modes));
+               if (len >= sizeof(chan->modes))
                        Config_Error_TooLong( Line, Var );
                return;
        }
        if( strcasecmp( Var, "Topic" ) == 0 ) {
                /* Initial topic */
-               if (!array_copys( &Conf_Channel[chancount].topic, Arg))
+               len = strlcpy(chan->topic, Arg, sizeof(chan->topic));
+               if (len >= sizeof(chan->topic))
                        Config_Error_TooLong( Line, Var );
                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 ))
+               len = strlcpy(chan->key, Arg, sizeof(chan->key));
+               if (len >= sizeof(chan->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)
+               chan->maxusers = (unsigned long) atol(Arg);
+               if (chan->maxusers == 0)
                        Config_Error_NaN(Line, Var);
                return;
        }