]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/conf.c
New configuration option "Mask" for [Operator] sections to limit OPER command.
[ngircd-alex.git] / src / ngircd / conf.c
index d1696b921afe3c57a20c1efd545e68a482962787..312ebff9a1cfcb724b3065613b1acefe904abdd0 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: conf.c,v 1.67 2005/01/20 00:13:08 alex Exp $";
+static char UNUSED id[] = "$Id: conf.c,v 1.69 2005/03/02 16:07:31 alex Exp $";
 
 #include "imp.h"
 #include <assert.h>
@@ -122,7 +122,8 @@ Conf_Test( VOID )
        printf( "  AdminEMail = %s\n", Conf_ServerAdminMail );
        printf( "  MotdFile = %s\n", Conf_MotdFile );
        printf( "  MotdPhrase = %s\n", Conf_MotdPhrase );
-       printf( "  ChrootDir= %s\n", Conf_Chroot );
+       printf( "  ChrootDir = %s\n", Conf_Chroot );
+       printf( "  PidFile = %s\n", Conf_PidFile);
        printf( "  Ports = " );
        for( i = 0; i < Conf_ListenPorts_Count; i++ )
        {
@@ -157,6 +158,7 @@ Conf_Test( VOID )
                puts( "[OPERATOR]" );
                printf( "  Name = %s\n", Conf_Oper[i].name );
                printf( "  Password = %s\n", Conf_Oper[i].pwd );
+               if ( Conf_Oper[i].mask ) printf( "  Mask = %s\n", Conf_Oper[i].mask );
                puts( "" );
        }
 
@@ -356,6 +358,8 @@ Set_Defaults( BOOLEAN InitServers )
 
        strlcpy( Conf_Chroot, CHROOT_DIR, sizeof( Conf_Chroot ));
 
+       strlcpy( Conf_PidFile, PID_FILE, sizeof( Conf_PidFile ));
+
        Conf_ListenPorts_Count = 0;
        strcpy( Conf_ListenAddress, "" );
 
@@ -463,8 +467,12 @@ Read_Config( VOID )
                                else
                                {
                                        /* Initialize new operator structure */
-                                       strcpy( Conf_Oper[Conf_Oper_Count].name, "" );
-                                       strcpy( Conf_Oper[Conf_Oper_Count].pwd, "" );
+                                       Conf_Oper[Conf_Oper_Count].name[0] = '\0';
+                                       Conf_Oper[Conf_Oper_Count].pwd[0] = '\0';
+                                       if (Conf_Oper[Conf_Oper_Count].mask) {
+                                               free(Conf_Oper[Conf_Oper_Count].mask );
+                                               Conf_Oper[Conf_Oper_Count].mask = NULL;
+                                       }
                                        Conf_Oper_Count++;
                                }
                                continue;
@@ -650,6 +658,16 @@ Handle_GLOBAL( INT Line, CHAR *Var, CHAR *Arg )
 
                return;
        }
+
+       if ( strcasecmp( Var, "PidFile" ) == 0 )
+       {
+               /* name of pidfile */
+               if( strlcpy( Conf_PidFile, Arg, sizeof( Conf_PidFile )) >= sizeof( Conf_PidFile ))
+                       Config_Error_TooLong( Line, Var );
+
+               return;
+       }
+
        if( strcasecmp( Var, "ServerUID" ) == 0 )
        {
                /* UID the daemon should switch to */
@@ -769,6 +787,7 @@ Handle_GLOBAL( INT Line, CHAR *Var, CHAR *Arg )
 LOCAL VOID
 Handle_OPERATOR( INT Line, CHAR *Var, CHAR *Arg )
 {
+       unsigned int len;
        assert( Line > 0 );
        assert( Var != NULL );
        assert( Arg != NULL );
@@ -786,7 +805,19 @@ Handle_OPERATOR( INT Line, CHAR *Var, CHAR *Arg )
                if( strlcpy( Conf_Oper[Conf_Oper_Count - 1].pwd, Arg, sizeof( Conf_Oper[Conf_Oper_Count - 1].pwd )) >= sizeof( Conf_Oper[Conf_Oper_Count - 1].pwd )) Config_Error_TooLong( Line, Var );
                return;
        }
-       
+       if( strcasecmp( Var, "Mask" ) == 0 )
+       {
+               if (Conf_Oper[Conf_Oper_Count - 1].mask) return; /* Hostname already configured */
+               len = strlen( Arg ) + 1;
+               Conf_Oper[Conf_Oper_Count - 1].mask = malloc( len );
+               if (! Conf_Oper[Conf_Oper_Count - 1].mask) {
+                       Config_Error( LOG_ERR, "%s, line %d: Cannot allocate memory for operator mask: %s", NGIRCd_ConfFile, Line, strerror(errno) );
+                       return;
+               }
+
+               strlcpy( Conf_Oper[Conf_Oper_Count - 1].mask, Arg, len);
+               return;
+       }
        Config_Error( LOG_ERR, "%s, line %d (section \"Operator\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
 } /* Handle_OPERATOR */