]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/conf.c
Change cloaked hostname to be malloc'd on demand
[ngircd-alex.git] / src / ngircd / conf.c
index eee1925555abbe8d05a7a3cc4ba85dfced474945..bae5fa7ad7b8f96467eb200092d0a85440102d7a 100644 (file)
@@ -34,7 +34,7 @@
 #include <grp.h>
 #include <sys/types.h>
 #include <unistd.h>
-
+#include <dirent.h>
 
 #include "array.h"
 #include "ngircd.h"
@@ -55,6 +55,7 @@ static int New_Server_Idx;
 
 static char Conf_MotdFile[FNAME_LEN];
 static char Conf_HelpFile[FNAME_LEN];
+static char Conf_IncludeDir[FNAME_LEN];
 
 static void Set_Defaults PARAMS(( bool InitServers ));
 static bool Read_Config PARAMS(( bool TestOnly, bool IsStarting ));
@@ -404,6 +405,7 @@ Conf_Test( void )
 #ifdef IDENT
        printf("  Ident = %s\n", yesno_to_str(Conf_Ident));
 #endif
+       printf("  IncludeDir = %s\n", Conf_IncludeDir);
        printf("  MorePrivacy = %s\n", yesno_to_str(Conf_MorePrivacy));
        printf("  NoticeAuth = %s\n", yesno_to_str(Conf_NoticeAuth));
        printf("  OperCanUseMode = %s\n", yesno_to_str(Conf_OperCanMode));
@@ -778,6 +780,7 @@ Set_Defaults(bool InitServers)
 #else
        Conf_Ident = false;
 #endif
+       strcpy(Conf_IncludeDir, "");
        Conf_MorePrivacy = false;
        Conf_NoticeAuth = false;
        Conf_OperCanMode = false;
@@ -824,7 +827,7 @@ no_listenports(void)
 /**
  * Read contents of a text file into an array.
  *
- * This function is used to read the MOTD and help text file, for exampe.
+ * This function is used to read the MOTD and help text file, for example.
  *
  * @param filename     Name of the file to read.
  * @return             true, when the file has been read in.
@@ -876,8 +879,11 @@ static bool
 Read_Config(bool TestOnly, bool IsStarting)
 {
        const UINT16 defaultport = 6667;
+       char *ptr, file[FNAME_LEN];
+       struct dirent *entry;
        int i, n;
        FILE *fd;
+       DIR *dh;
 
        /* Open configuration file */
        fd = fopen( NGIRCd_ConfFile, "r" );
@@ -938,9 +944,43 @@ Read_Config(bool TestOnly, bool IsStarting)
 #endif
 
        Read_Config_File(NGIRCd_ConfFile, fd);
+       fclose(fd);
 
-       /* Close configuration file */
-       fclose( fd );
+       if (Conf_IncludeDir[0]) {
+               dh = opendir(Conf_IncludeDir);
+               if (!dh)
+                       Config_Error(LOG_ALERT,
+                                    "Can't open include directory \"%s\": %s",
+                                    Conf_IncludeDir, strerror(errno));
+       } else {
+               strlcpy(Conf_IncludeDir, SYSCONFDIR, sizeof(Conf_IncludeDir));
+               strlcat(Conf_IncludeDir, CONFIG_DIR, sizeof(Conf_IncludeDir));
+               dh = opendir(Conf_IncludeDir);
+       }
+
+       /* Include further configuration files, if IncludeDir is available */
+       if (dh) {
+               while ((entry = readdir(dh)) != NULL) {
+                       ptr = strrchr(entry->d_name, '.');
+                       if (!ptr || strcasecmp(ptr, ".conf") != 0)
+                               continue;
+                       snprintf(file, sizeof(file), "%s/%s",
+                                Conf_IncludeDir, entry->d_name);
+                       if (TestOnly)
+                               Config_Error(LOG_INFO,
+                                            "Reading configuration from \"%s\" ...",
+                                            file);
+                       fd = fopen(file, "r");
+                       if (fd) {
+                               Read_Config_File(file, fd);
+                               fclose(fd);
+                       } else
+                               Config_Error(LOG_ALERT,
+                                            "Can't read configuration \"%s\": %s",
+                                            file, strerror(errno));
+               }
+               closedir(dh);
+       }
 
        /* Check if there is still a server to add */
        if( New_Server.name[0] ) {
@@ -999,6 +1039,7 @@ static void Read_Config_File(const char *File, FILE *fd)
        size_t count;
 
        /* Read configuration file */
+       section[0] = '\0';
        while (true) {
                if (!fgets(str, LINE_LEN, fd))
                        break;
@@ -1648,6 +1689,18 @@ Handle_OPTIONS(const char *File, int Line, char *Var, char *Arg)
                WarnIdent(Line);
                return;
        }
+       if (strcasecmp(Var, "IncludeDir") == 0) {
+               if (Conf_IncludeDir[0]) {
+                       Config_Error(LOG_ERR,
+                                    "%s, line %d: Can't overwrite value of \"IncludeDir\" variable!",
+                                    File, Line);
+                       return;
+               }
+               len = strlcpy(Conf_IncludeDir, Arg, sizeof(Conf_IncludeDir));
+               if (len >= sizeof(Conf_IncludeDir))
+                       Config_Error_TooLong(File, Line, Var);
+               return;
+       }
        if (strcasecmp(Var, "MorePrivacy") == 0) {
                Conf_MorePrivacy = Check_ArgIsTrue(Arg);
                return;