mirror of
				https://github.com/osmarks/ngircd.git
				synced 2025-10-31 14:02:59 +00:00 
			
		
		
		
	Implement new configuration option "IncludeDir"
The option "IncludeDir" in the [Options] section can be used
to specify a directory which can contain further configuration
files and configuration file snippets matching the pattern
"*.conf" that should be read in after the main configuration
file ("ngircd.conf" by default) has been parsed.
Closes bug #157.
			
			
This commit is contained in:
		| @@ -167,6 +167,10 @@ | |||||||
| 	# prepended to their user name. | 	# prepended to their user name. | ||||||
| 	;Ident = yes | 	;Ident = yes | ||||||
|  |  | ||||||
|  | 	# Directory containing configuration snippets (*.conf), that should | ||||||
|  | 	# be read in after parsing this configuration file. | ||||||
|  | 	;IncludeDir = :ETCDIR:/conf.d | ||||||
|  |  | ||||||
| 	# Enhance user privacy slightly (useful for IRC server on TOR or I2P) | 	# Enhance user privacy slightly (useful for IRC server on TOR or I2P) | ||||||
| 	# by censoring some information like idle time, logon time, etc. | 	# by censoring some information like idle time, logon time, etc. | ||||||
| 	;MorePrivacy = no | 	;MorePrivacy = no | ||||||
|   | |||||||
| @@ -1,7 +1,7 @@ | |||||||
| .\" | .\" | ||||||
| .\" ngircd.conf(5) manual page template | .\" ngircd.conf(5) manual page template | ||||||
| .\" | .\" | ||||||
| .TH ngircd.conf 5 "Feb 2013" ngIRCd "ngIRCd Manual" | .TH ngircd.conf 5 "May 2013" ngIRCd "ngIRCd Manual" | ||||||
| .SH NAME | .SH NAME | ||||||
| ngircd.conf \- configuration file of ngIRCd | ngircd.conf \- configuration file of ngIRCd | ||||||
| .SH SYNOPSIS | .SH SYNOPSIS | ||||||
| @@ -265,6 +265,11 @@ Users identified using IDENT are registered without the "~" character | |||||||
| prepended to their user name. | prepended to their user name. | ||||||
| Default: yes. | Default: yes. | ||||||
| .TP | .TP | ||||||
|  | .TP | ||||||
|  | \fBIncludeDir\fR (string) | ||||||
|  | Directory containing configuration snippets (*.conf), that should be read in | ||||||
|  | after parsing the current configuration file. | ||||||
|  | Default: none. | ||||||
| \fBMorePrivacy\fR (boolean) | \fBMorePrivacy\fR (boolean) | ||||||
| This will cause ngIRCd to censor user idle time, logon time as well as the | This will cause ngIRCd to censor user idle time, logon time as well as the | ||||||
| part/quit messages (that are sometimes used to inform everyone about which | part/quit messages (that are sometimes used to inform everyone about which | ||||||
|   | |||||||
| @@ -34,7 +34,7 @@ | |||||||
| #include <grp.h> | #include <grp.h> | ||||||
| #include <sys/types.h> | #include <sys/types.h> | ||||||
| #include <unistd.h> | #include <unistd.h> | ||||||
|  | #include <dirent.h> | ||||||
|  |  | ||||||
| #include "array.h" | #include "array.h" | ||||||
| #include "ngircd.h" | #include "ngircd.h" | ||||||
| @@ -55,6 +55,7 @@ static int New_Server_Idx; | |||||||
|  |  | ||||||
| static char Conf_MotdFile[FNAME_LEN]; | static char Conf_MotdFile[FNAME_LEN]; | ||||||
| static char Conf_HelpFile[FNAME_LEN]; | static char Conf_HelpFile[FNAME_LEN]; | ||||||
|  | static char Conf_IncludeDir[FNAME_LEN]; | ||||||
|  |  | ||||||
| static void Set_Defaults PARAMS(( bool InitServers )); | static void Set_Defaults PARAMS(( bool InitServers )); | ||||||
| static bool Read_Config PARAMS(( bool TestOnly, bool IsStarting )); | static bool Read_Config PARAMS(( bool TestOnly, bool IsStarting )); | ||||||
| @@ -404,6 +405,7 @@ Conf_Test( void ) | |||||||
| #ifdef IDENT | #ifdef IDENT | ||||||
| 	printf("  Ident = %s\n", yesno_to_str(Conf_Ident)); | 	printf("  Ident = %s\n", yesno_to_str(Conf_Ident)); | ||||||
| #endif | #endif | ||||||
|  | 	printf("  IncludeDir = %s\n", Conf_IncludeDir); | ||||||
| 	printf("  MorePrivacy = %s\n", yesno_to_str(Conf_MorePrivacy)); | 	printf("  MorePrivacy = %s\n", yesno_to_str(Conf_MorePrivacy)); | ||||||
| 	printf("  NoticeAuth = %s\n", yesno_to_str(Conf_NoticeAuth)); | 	printf("  NoticeAuth = %s\n", yesno_to_str(Conf_NoticeAuth)); | ||||||
| 	printf("  OperCanUseMode = %s\n", yesno_to_str(Conf_OperCanMode)); | 	printf("  OperCanUseMode = %s\n", yesno_to_str(Conf_OperCanMode)); | ||||||
| @@ -778,6 +780,7 @@ Set_Defaults(bool InitServers) | |||||||
| #else | #else | ||||||
| 	Conf_Ident = false; | 	Conf_Ident = false; | ||||||
| #endif | #endif | ||||||
|  | 	strcpy(Conf_IncludeDir, ""); | ||||||
| 	Conf_MorePrivacy = false; | 	Conf_MorePrivacy = false; | ||||||
| 	Conf_NoticeAuth = false; | 	Conf_NoticeAuth = false; | ||||||
| 	Conf_OperCanMode = false; | 	Conf_OperCanMode = false; | ||||||
| @@ -876,8 +879,11 @@ static bool | |||||||
| Read_Config(bool TestOnly, bool IsStarting) | Read_Config(bool TestOnly, bool IsStarting) | ||||||
| { | { | ||||||
| 	const UINT16 defaultport = 6667; | 	const UINT16 defaultport = 6667; | ||||||
|  | 	char *ptr, file[FNAME_LEN]; | ||||||
|  | 	struct dirent *entry; | ||||||
| 	int i, n; | 	int i, n; | ||||||
| 	FILE *fd; | 	FILE *fd; | ||||||
|  | 	DIR *dh; | ||||||
|  |  | ||||||
| 	/* Open configuration file */ | 	/* Open configuration file */ | ||||||
| 	fd = fopen( NGIRCd_ConfFile, "r" ); | 	fd = fopen( NGIRCd_ConfFile, "r" ); | ||||||
| @@ -938,9 +944,37 @@ Read_Config(bool TestOnly, bool IsStarting) | |||||||
| #endif | #endif | ||||||
|  |  | ||||||
| 	Read_Config_File(NGIRCd_ConfFile, fd); | 	Read_Config_File(NGIRCd_ConfFile, fd); | ||||||
|  | 	fclose(fd); | ||||||
|  |  | ||||||
| 	/* Close configuration file */ | 	if (Conf_IncludeDir[0]) { | ||||||
| 	fclose( fd ); | 		/* Include further configuration files, if any */ | ||||||
|  | 		dh = opendir(Conf_IncludeDir); | ||||||
|  | 		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); | ||||||
|  | 		} else | ||||||
|  | 			Config_Error(LOG_ALERT, | ||||||
|  | 				     "Can't open include directory \"%s\": %s", | ||||||
|  | 				     Conf_IncludeDir, strerror(errno)); | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	/* Check if there is still a server to add */ | 	/* Check if there is still a server to add */ | ||||||
| 	if( New_Server.name[0] ) { | 	if( New_Server.name[0] ) { | ||||||
| @@ -999,6 +1033,7 @@ static void Read_Config_File(const char *File, FILE *fd) | |||||||
| 	size_t count; | 	size_t count; | ||||||
|  |  | ||||||
| 	/* Read configuration file */ | 	/* Read configuration file */ | ||||||
|  | 	section[0] = '\0'; | ||||||
| 	while (true) { | 	while (true) { | ||||||
| 		if (!fgets(str, LINE_LEN, fd)) | 		if (!fgets(str, LINE_LEN, fd)) | ||||||
| 			break; | 			break; | ||||||
| @@ -1648,6 +1683,12 @@ Handle_OPTIONS(const char *File, int Line, char *Var, char *Arg) | |||||||
| 		WarnIdent(Line); | 		WarnIdent(Line); | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
|  | 	if (strcasecmp(Var, "IncludeDir") == 0) { | ||||||
|  | 		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) { | 	if (strcasecmp(Var, "MorePrivacy") == 0) { | ||||||
| 		Conf_MorePrivacy = Check_ArgIsTrue(Arg); | 		Conf_MorePrivacy = Check_ArgIsTrue(Arg); | ||||||
| 		return; | 		return; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Alexander Barton
					Alexander Barton