conf.c 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402
  1. /*
  2. * ngIRCd -- The Next Generation IRC Daemon
  3. * Copyright (c)2001-2014 Alexander Barton (alex@barton.de) and Contributors.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. * Please read the file COPYING, README and AUTHORS for more information.
  10. */
  11. #include "portab.h"
  12. /**
  13. * @file
  14. * Configuration management (reading, parsing & validation)
  15. */
  16. #include "imp.h"
  17. #include <assert.h>
  18. #include <ctype.h>
  19. #include <errno.h>
  20. #ifdef PROTOTYPES
  21. # include <stdarg.h>
  22. #else
  23. # include <varargs.h>
  24. #endif
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include <strings.h>
  29. #include <unistd.h>
  30. #include <pwd.h>
  31. #include <grp.h>
  32. #include <sys/types.h>
  33. #include <unistd.h>
  34. #include <dirent.h>
  35. #include "array.h"
  36. #include "ngircd.h"
  37. #include "conn.h"
  38. #include "channel.h"
  39. #include "defines.h"
  40. #include "log.h"
  41. #include "match.h"
  42. #include "tool.h"
  43. #include "exp.h"
  44. #include "conf.h"
  45. static bool Use_Log = true, Using_MotdFile = true;
  46. static CONF_SERVER New_Server;
  47. static int New_Server_Idx;
  48. static char Conf_MotdFile[FNAME_LEN];
  49. static char Conf_HelpFile[FNAME_LEN];
  50. static char Conf_IncludeDir[FNAME_LEN];
  51. static void Set_Defaults PARAMS(( bool InitServers ));
  52. static bool Read_Config PARAMS(( bool TestOnly, bool IsStarting ));
  53. static void Read_Config_File PARAMS(( const char *File, FILE *fd ));
  54. static bool Validate_Config PARAMS(( bool TestOnly, bool Rehash ));
  55. static void Handle_GLOBAL PARAMS((const char *File, int Line,
  56. char *Var, char *Arg ));
  57. static void Handle_LIMITS PARAMS((const char *File, int Line,
  58. char *Var, char *Arg ));
  59. static void Handle_OPTIONS PARAMS((const char *File, int Line,
  60. char *Var, char *Arg ));
  61. static void Handle_OPERATOR PARAMS((const char *File, int Line,
  62. char *Var, char *Arg ));
  63. static void Handle_SERVER PARAMS((const char *File, int Line,
  64. char *Var, char *Arg ));
  65. static void Handle_CHANNEL PARAMS((const char *File, int Line,
  66. char *Var, char *Arg ));
  67. static void Config_Error PARAMS((const int Level, const char *Format, ...));
  68. static void Config_Error_NaN PARAMS((const char *File, const int LINE,
  69. const char *Value));
  70. static void Config_Error_Section PARAMS((const char *File, const int Line,
  71. const char *Item, const char *Section));
  72. static void Config_Error_TooLong PARAMS((const char *File, const int LINE,
  73. const char *Value));
  74. static void Init_Server_Struct PARAMS(( CONF_SERVER *Server ));
  75. #ifdef WANT_IPV6
  76. #define DEFAULT_LISTEN_ADDRSTR "::,0.0.0.0"
  77. #else
  78. #define DEFAULT_LISTEN_ADDRSTR "0.0.0.0"
  79. #endif
  80. #ifdef HAVE_LIBSSL
  81. #define DEFAULT_CIPHERS "HIGH:!aNULL:@STRENGTH"
  82. #endif
  83. #ifdef HAVE_LIBGNUTLS
  84. #define DEFAULT_CIPHERS "SECURE128"
  85. #endif
  86. #ifdef SSL_SUPPORT
  87. static void Handle_SSL PARAMS((const char *File, int Line, char *Var, char *Ark));
  88. struct SSLOptions Conf_SSLOptions;
  89. /**
  90. * Initialize SSL configuration.
  91. */
  92. static void
  93. ConfSSL_Init(void)
  94. {
  95. free(Conf_SSLOptions.KeyFile);
  96. Conf_SSLOptions.KeyFile = NULL;
  97. free(Conf_SSLOptions.CertFile);
  98. Conf_SSLOptions.CertFile = NULL;
  99. free(Conf_SSLOptions.DHFile);
  100. Conf_SSLOptions.DHFile = NULL;
  101. array_free_wipe(&Conf_SSLOptions.KeyFilePassword);
  102. array_free(&Conf_SSLOptions.ListenPorts);
  103. free(Conf_SSLOptions.CipherList);
  104. Conf_SSLOptions.CipherList = NULL;
  105. }
  106. /**
  107. * Check if the current configuration uses/requires SSL.
  108. *
  109. * @returns true if SSL is used and should be initialized.
  110. */
  111. GLOBAL bool
  112. Conf_SSLInUse(void)
  113. {
  114. int i;
  115. /* SSL listen ports configured? */
  116. if (array_bytes(&Conf_SSLOptions.ListenPorts))
  117. return true;
  118. for (i = 0; i < MAX_SERVERS; i++) {
  119. if (Conf_Server[i].port > 0
  120. && Conf_Server[i].SSLConnect)
  121. return true;
  122. }
  123. return false;
  124. }
  125. /**
  126. * Make sure that a configured file is readable.
  127. *
  128. * Currently, this function is only used for SSL-related options ...
  129. *
  130. * @param Var Configuration variable
  131. * @param Filename Configured filename
  132. */
  133. static void
  134. CheckFileReadable(const char *Var, const char *Filename)
  135. {
  136. FILE *fp;
  137. if (!Filename)
  138. return;
  139. fp = fopen(Filename, "r");
  140. if (fp)
  141. fclose(fp);
  142. else
  143. Config_Error(LOG_ERR, "Can't read \"%s\" (\"%s\"): %s",
  144. Filename, Var, strerror(errno));
  145. }
  146. #endif
  147. /**
  148. * Duplicate string and warn on errors.
  149. *
  150. * @returns Pointer to string on success, NULL otherwise.
  151. */
  152. static char *
  153. strdup_warn(const char *str)
  154. {
  155. char *ptr = strdup(str);
  156. if (!ptr)
  157. Config_Error(LOG_ERR,
  158. "Could not allocate memory for string: %s", str);
  159. return ptr;
  160. }
  161. /**
  162. * Output a comma separated list of ports (integer values).
  163. */
  164. static void
  165. ports_puts(array *a)
  166. {
  167. size_t len;
  168. UINT16 *ports;
  169. len = array_length(a, sizeof(UINT16));
  170. if (len--) {
  171. ports = (UINT16*) array_start(a);
  172. printf("%u", (unsigned int) *ports);
  173. while (len--) {
  174. ports++;
  175. printf(", %u", (unsigned int) *ports);
  176. }
  177. }
  178. putc('\n', stdout);
  179. }
  180. /**
  181. * Parse a comma separated string into an array of port numbers (integers).
  182. */
  183. static void
  184. ports_parse(array *a, const char *File, int Line, char *Arg)
  185. {
  186. char *ptr;
  187. int port;
  188. UINT16 port16;
  189. array_trunc(a);
  190. ptr = strtok( Arg, "," );
  191. while (ptr) {
  192. ngt_TrimStr(ptr);
  193. port = atoi(ptr);
  194. if (port > 0 && port < 0xFFFF) {
  195. port16 = (UINT16) port;
  196. if (!array_catb(a, (char*)&port16, sizeof port16))
  197. Config_Error(LOG_ERR, "%s, line %d Could not add port number %ld: %s",
  198. File, Line, port, strerror(errno));
  199. } else {
  200. Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Illegal port number %ld!",
  201. File, Line, port );
  202. }
  203. ptr = strtok( NULL, "," );
  204. }
  205. }
  206. /**
  207. * Initialize configuration module.
  208. */
  209. GLOBAL void
  210. Conf_Init( void )
  211. {
  212. Read_Config(false, true);
  213. Validate_Config(false, false);
  214. }
  215. /**
  216. * "Rehash" (reload) server configuration.
  217. *
  218. * @returns true if configuration has been re-read, false on errors.
  219. */
  220. GLOBAL bool
  221. Conf_Rehash( void )
  222. {
  223. if (!Read_Config(false, false))
  224. return false;
  225. Validate_Config(false, true);
  226. /* Update CLIENT structure of local server */
  227. Client_SetInfo(Client_ThisServer(), Conf_ServerInfo);
  228. return true;
  229. }
  230. /**
  231. * Output a boolean value as "yes/no" string.
  232. */
  233. static const char*
  234. yesno_to_str(int boolean_value)
  235. {
  236. if (boolean_value)
  237. return "yes";
  238. return "no";
  239. }
  240. /**
  241. * Free all IRC operator configuration structures.
  242. */
  243. static void
  244. opers_free(void)
  245. {
  246. struct Conf_Oper *op;
  247. size_t len;
  248. len = array_length(&Conf_Opers, sizeof(*op));
  249. op = array_start(&Conf_Opers);
  250. while (len--) {
  251. free(op->mask);
  252. op++;
  253. }
  254. array_free(&Conf_Opers);
  255. }
  256. /**
  257. * Output all IRC operator configuration structures.
  258. */
  259. static void
  260. opers_puts(void)
  261. {
  262. struct Conf_Oper *op;
  263. size_t count, i;
  264. count = array_length(&Conf_Opers, sizeof(*op));
  265. op = array_start(&Conf_Opers);
  266. for (i = 0; i < count; i++, op++) {
  267. if (!op->name[0])
  268. continue;
  269. puts("[OPERATOR]");
  270. printf(" Name = %s\n", op->name);
  271. printf(" Password = %s\n", op->pwd);
  272. printf(" Mask = %s\n\n", op->mask ? op->mask : "");
  273. }
  274. }
  275. /**
  276. * Read configuration, validate and output it.
  277. *
  278. * This function waits for a keypress of the user when stdin/stdout are valid
  279. * tty's ("you can read our nice message and we can read in your keypress").
  280. *
  281. * @return 0 on success, 1 on failure(s); therefore the result code can
  282. * directly be used by exit() when running "ngircd --configtest".
  283. */
  284. GLOBAL int
  285. Conf_Test( void )
  286. {
  287. struct passwd *pwd;
  288. struct group *grp;
  289. unsigned int i;
  290. bool config_valid;
  291. size_t predef_channel_count;
  292. struct Conf_Channel *predef_chan;
  293. Use_Log = false;
  294. if (!Read_Config(true, true))
  295. return 1;
  296. config_valid = Validate_Config(true, false);
  297. /* Valid tty? */
  298. if(isatty(fileno(stdin)) && isatty(fileno(stdout))) {
  299. puts("OK, press enter to see a dump of your server configuration ...");
  300. getchar();
  301. } else
  302. puts("Ok, dump of your server configuration follows:\n");
  303. puts("[GLOBAL]");
  304. printf(" Name = %s\n", Conf_ServerName);
  305. printf(" AdminInfo1 = %s\n", Conf_ServerAdmin1);
  306. printf(" AdminInfo2 = %s\n", Conf_ServerAdmin2);
  307. printf(" AdminEMail = %s\n", Conf_ServerAdminMail);
  308. printf(" HelpFile = %s\n", Conf_HelpFile);
  309. printf(" Info = %s\n", Conf_ServerInfo);
  310. printf(" Listen = %s\n", Conf_ListenAddress);
  311. if (Using_MotdFile) {
  312. printf(" MotdFile = %s\n", Conf_MotdFile);
  313. printf(" MotdPhrase =\n");
  314. } else {
  315. printf(" MotdFile = \n");
  316. printf(" MotdPhrase = %s\n", array_bytes(&Conf_Motd)
  317. ? (const char*) array_start(&Conf_Motd) : "");
  318. }
  319. if (!Conf_PAM)
  320. printf(" Password = %s\n", Conf_ServerPwd);
  321. printf(" PidFile = %s\n", Conf_PidFile);
  322. printf(" Ports = ");
  323. ports_puts(&Conf_ListenPorts);
  324. grp = getgrgid(Conf_GID);
  325. if (grp)
  326. printf(" ServerGID = %s\n", grp->gr_name);
  327. else
  328. printf(" ServerGID = %ld\n", (long)Conf_GID);
  329. pwd = getpwuid(Conf_UID);
  330. if (pwd)
  331. printf(" ServerUID = %s\n", pwd->pw_name);
  332. else
  333. printf(" ServerUID = %ld\n", (long)Conf_UID);
  334. puts("");
  335. puts("[LIMITS]");
  336. printf(" ConnectRetry = %d\n", Conf_ConnectRetry);
  337. printf(" IdleTimeout = %d\n", Conf_IdleTimeout);
  338. printf(" MaxConnections = %d\n", Conf_MaxConnections);
  339. printf(" MaxConnectionsIP = %d\n", Conf_MaxConnectionsIP);
  340. printf(" MaxJoins = %d\n", Conf_MaxJoins > 0 ? Conf_MaxJoins : -1);
  341. printf(" MaxNickLength = %u\n", Conf_MaxNickLength - 1);
  342. printf(" MaxListSize = %d\n", Conf_MaxListSize);
  343. printf(" PingTimeout = %d\n", Conf_PingTimeout);
  344. printf(" PongTimeout = %d\n", Conf_PongTimeout);
  345. puts("");
  346. puts("[OPTIONS]");
  347. printf(" AllowedChannelTypes = %s\n", Conf_AllowedChannelTypes);
  348. printf(" AllowRemoteOper = %s\n", yesno_to_str(Conf_AllowRemoteOper));
  349. printf(" ChrootDir = %s\n", Conf_Chroot);
  350. printf(" CloakHost = %s\n", Conf_CloakHost);
  351. printf(" CloakHostModeX = %s\n", Conf_CloakHostModeX);
  352. printf(" CloakHostSalt = %s\n", Conf_CloakHostSalt);
  353. printf(" CloakUserToNick = %s\n", yesno_to_str(Conf_CloakUserToNick));
  354. #ifdef WANT_IPV6
  355. printf(" ConnectIPv4 = %s\n", yesno_to_str(Conf_ConnectIPv6));
  356. printf(" ConnectIPv6 = %s\n", yesno_to_str(Conf_ConnectIPv4));
  357. #endif
  358. printf(" DefaultUserModes = %s\n", Conf_DefaultUserModes);
  359. printf(" DNS = %s\n", yesno_to_str(Conf_DNS));
  360. #ifdef IDENT
  361. printf(" Ident = %s\n", yesno_to_str(Conf_Ident));
  362. #endif
  363. printf(" IncludeDir = %s\n", Conf_IncludeDir);
  364. printf(" MorePrivacy = %s\n", yesno_to_str(Conf_MorePrivacy));
  365. printf(" NoticeAuth = %s\n", yesno_to_str(Conf_NoticeAuth));
  366. printf(" OperCanUseMode = %s\n", yesno_to_str(Conf_OperCanMode));
  367. printf(" OperChanPAutoOp = %s\n", yesno_to_str(Conf_OperChanPAutoOp));
  368. printf(" OperServerMode = %s\n", yesno_to_str(Conf_OperServerMode));
  369. #ifdef PAM
  370. printf(" PAM = %s\n", yesno_to_str(Conf_PAM));
  371. printf(" PAMIsOptional = %s\n", yesno_to_str(Conf_PAMIsOptional));
  372. #endif
  373. #ifndef STRICT_RFC
  374. printf(" RequireAuthPing = %s\n", yesno_to_str(Conf_AuthPing));
  375. #endif
  376. printf(" ScrubCTCP = %s\n", yesno_to_str(Conf_ScrubCTCP));
  377. #ifdef SYSLOG
  378. printf(" SyslogFacility = %s\n",
  379. ngt_SyslogFacilityName(Conf_SyslogFacility));
  380. #endif
  381. printf(" WebircPassword = %s\n", Conf_WebircPwd);
  382. puts("");
  383. #ifdef SSL_SUPPORT
  384. puts("[SSL]");
  385. printf(" CertFile = %s\n", Conf_SSLOptions.CertFile
  386. ? Conf_SSLOptions.CertFile : "");
  387. printf(" CipherList = %s\n", Conf_SSLOptions.CipherList ?
  388. Conf_SSLOptions.CipherList : DEFAULT_CIPHERS);
  389. printf(" DHFile = %s\n", Conf_SSLOptions.DHFile
  390. ? Conf_SSLOptions.DHFile : "");
  391. printf(" KeyFile = %s\n", Conf_SSLOptions.KeyFile
  392. ? Conf_SSLOptions.KeyFile : "");
  393. if (array_bytes(&Conf_SSLOptions.KeyFilePassword))
  394. puts(" KeyFilePassword = <secret>");
  395. else
  396. puts(" KeyFilePassword = ");
  397. array_free_wipe(&Conf_SSLOptions.KeyFilePassword);
  398. printf(" Ports = ");
  399. ports_puts(&Conf_SSLOptions.ListenPorts);
  400. puts("");
  401. #endif
  402. opers_puts();
  403. for( i = 0; i < MAX_SERVERS; i++ ) {
  404. if( ! Conf_Server[i].name[0] ) continue;
  405. /* Valid "Server" section */
  406. puts( "[SERVER]" );
  407. printf( " Name = %s\n", Conf_Server[i].name );
  408. printf( " Host = %s\n", Conf_Server[i].host );
  409. printf( " Port = %u\n", (unsigned int)Conf_Server[i].port );
  410. #ifdef SSL_SUPPORT
  411. printf( " SSLConnect = %s\n", Conf_Server[i].SSLConnect?"yes":"no");
  412. #endif
  413. printf( " MyPassword = %s\n", Conf_Server[i].pwd_in );
  414. printf( " PeerPassword = %s\n", Conf_Server[i].pwd_out );
  415. printf( " ServiceMask = %s\n", Conf_Server[i].svs_mask);
  416. printf( " Group = %d\n", Conf_Server[i].group );
  417. printf( " Passive = %s\n\n", Conf_Server[i].flags & CONF_SFLAG_DISABLED ? "yes" : "no");
  418. }
  419. predef_channel_count = array_length(&Conf_Channels, sizeof(*predef_chan));
  420. predef_chan = array_start(&Conf_Channels);
  421. for (i = 0; i < predef_channel_count; i++, predef_chan++) {
  422. if (!predef_chan->name[0])
  423. continue;
  424. /* Valid "Channel" section */
  425. puts( "[CHANNEL]" );
  426. printf(" Name = %s\n", predef_chan->name);
  427. printf(" Modes = %s\n", predef_chan->modes);
  428. printf(" Key = %s\n", predef_chan->key);
  429. printf(" MaxUsers = %lu\n", predef_chan->maxusers);
  430. printf(" Topic = %s\n", predef_chan->topic);
  431. printf(" KeyFile = %s\n\n", predef_chan->keyfile);
  432. }
  433. return (config_valid ? 0 : 1);
  434. }
  435. /**
  436. * Remove connection information from configured server.
  437. *
  438. * If the server is set as "once", delete it from our configuration;
  439. * otherwise set the time for the next connection attempt.
  440. *
  441. * Non-server connections will be silently ignored.
  442. */
  443. GLOBAL void
  444. Conf_UnsetServer( CONN_ID Idx )
  445. {
  446. int i;
  447. time_t t;
  448. /* Check all our configured servers */
  449. for( i = 0; i < MAX_SERVERS; i++ ) {
  450. if( Conf_Server[i].conn_id != Idx ) continue;
  451. /* Gotcha! Mark server configuration as "unused": */
  452. Conf_Server[i].conn_id = NONE;
  453. if( Conf_Server[i].flags & CONF_SFLAG_ONCE ) {
  454. /* Delete configuration here */
  455. Init_Server_Struct( &Conf_Server[i] );
  456. } else {
  457. /* Set time for next connect attempt */
  458. t = time(NULL);
  459. if (Conf_Server[i].lasttry < t - Conf_ConnectRetry) {
  460. /* The connection has been "long", so we don't
  461. * require the next attempt to be delayed. */
  462. Conf_Server[i].lasttry =
  463. t - Conf_ConnectRetry + RECONNECT_DELAY;
  464. } else {
  465. /* "Short" connection, enforce "ConnectRetry"
  466. * but randomize it a little bit: 15 seconds. */
  467. Conf_Server[i].lasttry =
  468. #ifdef HAVE_ARC4RANDOM
  469. t + (arc4random() % 15);
  470. #else
  471. t + rand() / (RAND_MAX / 15);
  472. #endif
  473. }
  474. }
  475. }
  476. }
  477. /**
  478. * Set connection information for specified configured server.
  479. */
  480. GLOBAL bool
  481. Conf_SetServer( int ConfServer, CONN_ID Idx )
  482. {
  483. assert( ConfServer > NONE );
  484. assert( Idx > NONE );
  485. if (Conf_Server[ConfServer].conn_id > NONE &&
  486. Conf_Server[ConfServer].conn_id != Idx) {
  487. Log(LOG_ERR,
  488. "Connection %d: Server configuration of \"%s\" already in use by connection %d!",
  489. Idx, Conf_Server[ConfServer].name,
  490. Conf_Server[ConfServer].conn_id);
  491. Conn_Close(Idx, NULL, "Server configuration already in use", true);
  492. return false;
  493. }
  494. Conf_Server[ConfServer].conn_id = Idx;
  495. return true;
  496. }
  497. /**
  498. * Get index of server in configuration structure.
  499. */
  500. GLOBAL int
  501. Conf_GetServer( CONN_ID Idx )
  502. {
  503. int i = 0;
  504. assert( Idx > NONE );
  505. for( i = 0; i < MAX_SERVERS; i++ ) {
  506. if( Conf_Server[i].conn_id == Idx ) return i;
  507. }
  508. return NONE;
  509. }
  510. /**
  511. * Enable a server by name and adjust its port number.
  512. *
  513. * @returns true if a server has been enabled and now has a valid port
  514. * number and host name for outgoing connections.
  515. */
  516. GLOBAL bool
  517. Conf_EnableServer( const char *Name, UINT16 Port )
  518. {
  519. int i;
  520. assert( Name != NULL );
  521. for( i = 0; i < MAX_SERVERS; i++ ) {
  522. if( strcasecmp( Conf_Server[i].name, Name ) == 0 ) {
  523. /* Gotcha! Set port and enable server: */
  524. Conf_Server[i].port = Port;
  525. Conf_Server[i].flags &= ~CONF_SFLAG_DISABLED;
  526. return (Conf_Server[i].port && Conf_Server[i].host[0]);
  527. }
  528. }
  529. return false;
  530. }
  531. /**
  532. * Enable a server by name.
  533. *
  534. * The server is only usable as outgoing server, if it has set a valid port
  535. * number for outgoing connections!
  536. * If not, you have to use Conf_EnableServer() function to make it available.
  537. *
  538. * @returns true if a server has been enabled; false otherwise.
  539. */
  540. GLOBAL bool
  541. Conf_EnablePassiveServer(const char *Name)
  542. {
  543. int i;
  544. assert( Name != NULL );
  545. for (i = 0; i < MAX_SERVERS; i++) {
  546. if ((strcasecmp( Conf_Server[i].name, Name ) == 0)
  547. && (Conf_Server[i].port > 0)) {
  548. /* BINGO! Enable server */
  549. Conf_Server[i].flags &= ~CONF_SFLAG_DISABLED;
  550. return true;
  551. }
  552. }
  553. return false;
  554. }
  555. /**
  556. * Disable a server by name.
  557. * An already established connection will be disconnected.
  558. *
  559. * @returns true if a server was found and has been disabled.
  560. */
  561. GLOBAL bool
  562. Conf_DisableServer( const char *Name )
  563. {
  564. int i;
  565. assert( Name != NULL );
  566. for( i = 0; i < MAX_SERVERS; i++ ) {
  567. if( strcasecmp( Conf_Server[i].name, Name ) == 0 ) {
  568. /* Gotcha! Disable and disconnect server: */
  569. Conf_Server[i].flags |= CONF_SFLAG_DISABLED;
  570. if( Conf_Server[i].conn_id > NONE )
  571. Conn_Close(Conf_Server[i].conn_id, NULL,
  572. "Server link terminated on operator request",
  573. true);
  574. return true;
  575. }
  576. }
  577. return false;
  578. }
  579. /**
  580. * Add a new remote server to our configuration.
  581. *
  582. * @param Name Name of the new server.
  583. * @param Port Port number to connect to or 0 for incoming connections.
  584. * @param Host Host name to connect to.
  585. * @param MyPwd Password that will be sent to the peer.
  586. * @param PeerPwd Password that must be received from the peer.
  587. * @returns true if the new server has been added; false otherwise.
  588. */
  589. GLOBAL bool
  590. Conf_AddServer(const char *Name, UINT16 Port, const char *Host,
  591. const char *MyPwd, const char *PeerPwd)
  592. {
  593. int i;
  594. assert( Name != NULL );
  595. assert( Host != NULL );
  596. assert( MyPwd != NULL );
  597. assert( PeerPwd != NULL );
  598. /* Search unused item in server configuration structure */
  599. for( i = 0; i < MAX_SERVERS; i++ ) {
  600. /* Is this item used? */
  601. if( ! Conf_Server[i].name[0] ) break;
  602. }
  603. if( i >= MAX_SERVERS ) return false;
  604. Init_Server_Struct( &Conf_Server[i] );
  605. strlcpy( Conf_Server[i].name, Name, sizeof( Conf_Server[i].name ));
  606. strlcpy( Conf_Server[i].host, Host, sizeof( Conf_Server[i].host ));
  607. strlcpy( Conf_Server[i].pwd_out, MyPwd, sizeof( Conf_Server[i].pwd_out ));
  608. strlcpy( Conf_Server[i].pwd_in, PeerPwd, sizeof( Conf_Server[i].pwd_in ));
  609. Conf_Server[i].port = Port;
  610. Conf_Server[i].flags = CONF_SFLAG_ONCE;
  611. return true;
  612. }
  613. /**
  614. * Check if the given nickname is reserved for services on a particular server.
  615. *
  616. * @param ConfServer The server index to check.
  617. * @param Nick The nickname to check.
  618. * @returns true if the given nickname belongs to an "IRC service".
  619. */
  620. GLOBAL bool
  621. Conf_NickIsService(int ConfServer, const char *Nick)
  622. {
  623. assert (ConfServer >= 0);
  624. assert (ConfServer < MAX_SERVERS);
  625. return MatchCaseInsensitiveList(Conf_Server[ConfServer].svs_mask,
  626. Nick, ",");
  627. }
  628. /**
  629. * Check if the given nickname is blocked for "normal client" use.
  630. *
  631. * @param ConfServer The server index or NONE to check all configured servers.
  632. * @param Nick The nickname to check.
  633. * @returns true if the given nickname belongs to an "IRC service".
  634. */
  635. GLOBAL bool
  636. Conf_NickIsBlocked(const char *Nick)
  637. {
  638. int i;
  639. for(i = 0; i < MAX_SERVERS; i++) {
  640. if (!Conf_Server[i].name[0])
  641. continue;
  642. if (Conf_NickIsService(i, Nick))
  643. return true;
  644. }
  645. return false;
  646. }
  647. /**
  648. * Initialize configuration settings with their default values.
  649. */
  650. static void
  651. Set_Defaults(bool InitServers)
  652. {
  653. int i;
  654. char random[RANDOM_SALT_LEN + 1];
  655. /* Global */
  656. strcpy(Conf_ServerName, "");
  657. strcpy(Conf_ServerAdmin1, "");
  658. strcpy(Conf_ServerAdmin2, "");
  659. strcpy(Conf_ServerAdminMail, "");
  660. snprintf(Conf_ServerInfo, sizeof Conf_ServerInfo, "%s %s",
  661. PACKAGE_NAME, PACKAGE_VERSION);
  662. free(Conf_ListenAddress);
  663. Conf_ListenAddress = NULL;
  664. array_free(&Conf_ListenPorts);
  665. array_free(&Conf_Motd);
  666. array_free(&Conf_Helptext);
  667. strlcpy(Conf_MotdFile, SYSCONFDIR, sizeof(Conf_MotdFile));
  668. strlcat(Conf_MotdFile, MOTD_FILE, sizeof(Conf_MotdFile));
  669. strlcpy(Conf_HelpFile, DOCDIR, sizeof(Conf_HelpFile));
  670. strlcat(Conf_HelpFile, HELP_FILE, sizeof(Conf_HelpFile));
  671. strcpy(Conf_ServerPwd, "");
  672. strlcpy(Conf_PidFile, PID_FILE, sizeof(Conf_PidFile));
  673. Conf_UID = Conf_GID = 0;
  674. /* Limits */
  675. Conf_ConnectRetry = 60;
  676. Conf_IdleTimeout = 0;
  677. Conf_MaxConnections = 0;
  678. Conf_MaxConnectionsIP = 5;
  679. Conf_MaxJoins = 10;
  680. Conf_MaxNickLength = CLIENT_NICK_LEN_DEFAULT;
  681. Conf_MaxListSize = 100;
  682. Conf_PingTimeout = 120;
  683. Conf_PongTimeout = 20;
  684. /* Options */
  685. strlcpy(Conf_AllowedChannelTypes, CHANTYPES,
  686. sizeof(Conf_AllowedChannelTypes));
  687. Conf_AllowRemoteOper = false;
  688. #ifndef STRICT_RFC
  689. Conf_AuthPing = false;
  690. #endif
  691. strlcpy(Conf_Chroot, CHROOT_DIR, sizeof(Conf_Chroot));
  692. strcpy(Conf_CloakHost, "");
  693. strcpy(Conf_CloakHostModeX, "");
  694. strlcpy(Conf_CloakHostSalt, ngt_RandomStr(random, RANDOM_SALT_LEN),
  695. sizeof(Conf_CloakHostSalt));
  696. Conf_CloakUserToNick = false;
  697. Conf_ConnectIPv4 = true;
  698. #ifdef WANT_IPV6
  699. Conf_ConnectIPv6 = true;
  700. #else
  701. Conf_ConnectIPv6 = false;
  702. #endif
  703. strcpy(Conf_DefaultUserModes, "");
  704. Conf_DNS = true;
  705. #ifdef IDENTAUTH
  706. Conf_Ident = true;
  707. #else
  708. Conf_Ident = false;
  709. #endif
  710. strcpy(Conf_IncludeDir, "");
  711. Conf_MorePrivacy = false;
  712. Conf_NoticeAuth = false;
  713. Conf_OperCanMode = false;
  714. Conf_OperChanPAutoOp = true;
  715. Conf_OperServerMode = false;
  716. #ifdef PAM
  717. Conf_PAM = true;
  718. #else
  719. Conf_PAM = false;
  720. #endif
  721. Conf_PAMIsOptional = false;
  722. #ifdef SYSLOG
  723. Conf_ScrubCTCP = false;
  724. #ifdef LOG_LOCAL5
  725. Conf_SyslogFacility = LOG_LOCAL5;
  726. #else
  727. Conf_SyslogFacility = 0;
  728. #endif
  729. #endif
  730. /* Initialize server configuration structures */
  731. if (InitServers) {
  732. for (i = 0; i < MAX_SERVERS;
  733. Init_Server_Struct(&Conf_Server[i++]));
  734. }
  735. }
  736. /**
  737. * Get number of configured listening ports.
  738. *
  739. * @returns The number of ports (IPv4+IPv6) on which the server should listen.
  740. */
  741. static bool
  742. no_listenports(void)
  743. {
  744. size_t cnt = array_bytes(&Conf_ListenPorts);
  745. #ifdef SSL_SUPPORT
  746. cnt += array_bytes(&Conf_SSLOptions.ListenPorts);
  747. #endif
  748. return cnt == 0;
  749. }
  750. /**
  751. * Read contents of a text file into an array.
  752. *
  753. * This function is used to read the MOTD and help text file, for example.
  754. *
  755. * @param filename Name of the file to read.
  756. * @return true, when the file has been read in.
  757. */
  758. static bool
  759. Read_TextFile(const char *Filename, const char *Name, array *Destination)
  760. {
  761. char line[127];
  762. FILE *fp;
  763. int line_no = 1;
  764. if (*Filename == '\0')
  765. return false;
  766. fp = fopen(Filename, "r");
  767. if (!fp) {
  768. Config_Error(LOG_ERR, "Can't read %s file \"%s\": %s",
  769. Name, Filename, strerror(errno));
  770. return false;
  771. }
  772. array_free(Destination);
  773. while (fgets(line, (int)sizeof line, fp)) {
  774. ngt_TrimLastChr(line, '\n');
  775. /* add text including \0 */
  776. if (!array_catb(Destination, line, strlen(line) + 1)) {
  777. Log(LOG_ERR, "Cannot read/add \"%s\", line %d: %s",
  778. Filename, line_no, strerror(errno));
  779. break;
  780. }
  781. line_no++;
  782. }
  783. fclose(fp);
  784. return true;
  785. }
  786. /**
  787. * Read ngIRCd configuration file.
  788. *
  789. * Please note that this function uses exit(1) on fatal errors and therefore
  790. * can result in ngIRCd terminating!
  791. *
  792. * @param ngircd_starting Flag indicating if ngIRCd is starting or not.
  793. * @returns true when the configuration file has been read
  794. * successfully; false otherwise.
  795. */
  796. static bool
  797. Read_Config(bool TestOnly, bool IsStarting)
  798. {
  799. const UINT16 defaultport = 6667;
  800. char *ptr, file[FNAME_LEN];
  801. struct dirent *entry;
  802. int i, n;
  803. FILE *fd;
  804. DIR *dh;
  805. /* Open configuration file */
  806. fd = fopen( NGIRCd_ConfFile, "r" );
  807. if( ! fd ) {
  808. /* No configuration file found! */
  809. Config_Error( LOG_ALERT, "Can't read configuration \"%s\": %s",
  810. NGIRCd_ConfFile, strerror( errno ));
  811. if (!IsStarting)
  812. return false;
  813. Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
  814. exit( 1 );
  815. }
  816. opers_free();
  817. Set_Defaults(IsStarting);
  818. if (TestOnly)
  819. Config_Error(LOG_INFO,
  820. "Reading configuration from \"%s\" ...",
  821. NGIRCd_ConfFile );
  822. /* Clean up server configuration structure: mark all already
  823. * configured servers as "once" so that they are deleted
  824. * after the next disconnect and delete all unused servers.
  825. * And delete all servers which are "duplicates" of servers
  826. * that are already marked as "once" (such servers have been
  827. * created by the last rehash but are now useless). */
  828. for( i = 0; i < MAX_SERVERS; i++ ) {
  829. if( Conf_Server[i].conn_id == NONE ) Init_Server_Struct( &Conf_Server[i] );
  830. else {
  831. /* This structure is in use ... */
  832. if( Conf_Server[i].flags & CONF_SFLAG_ONCE ) {
  833. /* Check for duplicates */
  834. for( n = 0; n < MAX_SERVERS; n++ ) {
  835. if( n == i ) continue;
  836. if( Conf_Server[i].conn_id == Conf_Server[n].conn_id ) {
  837. Init_Server_Struct( &Conf_Server[n] );
  838. #ifdef DEBUG
  839. Log(LOG_DEBUG,"Deleted unused duplicate server %d (kept %d).",
  840. n, i );
  841. #endif
  842. }
  843. }
  844. } else {
  845. /* Mark server as "once" */
  846. Conf_Server[i].flags |= CONF_SFLAG_ONCE;
  847. Log( LOG_DEBUG, "Marked server %d as \"once\"", i );
  848. }
  849. }
  850. }
  851. /* Initialize variables */
  852. Init_Server_Struct( &New_Server );
  853. New_Server_Idx = NONE;
  854. #ifdef SSL_SUPPORT
  855. ConfSSL_Init();
  856. #endif
  857. Read_Config_File(NGIRCd_ConfFile, fd);
  858. fclose(fd);
  859. if (Conf_IncludeDir[0]) {
  860. dh = opendir(Conf_IncludeDir);
  861. if (!dh)
  862. Config_Error(LOG_ALERT,
  863. "Can't open include directory \"%s\": %s",
  864. Conf_IncludeDir, strerror(errno));
  865. } else {
  866. strlcpy(Conf_IncludeDir, SYSCONFDIR, sizeof(Conf_IncludeDir));
  867. strlcat(Conf_IncludeDir, CONFIG_DIR, sizeof(Conf_IncludeDir));
  868. dh = opendir(Conf_IncludeDir);
  869. }
  870. /* Include further configuration files, if IncludeDir is available */
  871. if (dh) {
  872. while ((entry = readdir(dh)) != NULL) {
  873. ptr = strrchr(entry->d_name, '.');
  874. if (!ptr || strcasecmp(ptr, ".conf") != 0)
  875. continue;
  876. snprintf(file, sizeof(file), "%s/%s",
  877. Conf_IncludeDir, entry->d_name);
  878. if (TestOnly)
  879. Config_Error(LOG_INFO,
  880. "Reading configuration from \"%s\" ...",
  881. file);
  882. fd = fopen(file, "r");
  883. if (fd) {
  884. Read_Config_File(file, fd);
  885. fclose(fd);
  886. } else
  887. Config_Error(LOG_ALERT,
  888. "Can't read configuration \"%s\": %s",
  889. file, strerror(errno));
  890. }
  891. closedir(dh);
  892. }
  893. /* Check if there is still a server to add */
  894. if( New_Server.name[0] ) {
  895. /* Copy data to "real" server structure */
  896. assert( New_Server_Idx > NONE );
  897. Conf_Server[New_Server_Idx] = New_Server;
  898. }
  899. /* not a single listening port? Add default. */
  900. if (no_listenports() &&
  901. !array_copyb(&Conf_ListenPorts, (char*) &defaultport, sizeof defaultport))
  902. {
  903. Config_Error(LOG_ALERT, "Could not add default listening Port %u: %s",
  904. (unsigned int) defaultport, strerror(errno));
  905. exit(1);
  906. }
  907. if (!Conf_ListenAddress)
  908. Conf_ListenAddress = strdup_warn(DEFAULT_LISTEN_ADDRSTR);
  909. if (!Conf_ListenAddress) {
  910. Config_Error(LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME);
  911. exit(1);
  912. }
  913. /* No MOTD phrase configured? (re)try motd file. */
  914. if (array_bytes(&Conf_Motd) == 0) {
  915. if (Read_TextFile(Conf_MotdFile, "MOTD", &Conf_Motd))
  916. Using_MotdFile = true;
  917. }
  918. /* Try to read ngIRCd help text file. */
  919. (void)Read_TextFile(Conf_HelpFile, "help text", &Conf_Helptext);
  920. if (!array_bytes(&Conf_Helptext))
  921. Config_Error(LOG_WARNING,
  922. "No help text available, HELP command will be of limited use.");
  923. #ifdef SSL_SUPPORT
  924. /* Make sure that all SSL-related files are readable */
  925. CheckFileReadable("CertFile", Conf_SSLOptions.CertFile);
  926. CheckFileReadable("DHFile", Conf_SSLOptions.DHFile);
  927. CheckFileReadable("KeyFile", Conf_SSLOptions.KeyFile);
  928. /* Set the default ciphers if none were configured */
  929. if (!Conf_SSLOptions.CipherList)
  930. Conf_SSLOptions.CipherList = strdup_warn(DEFAULT_CIPHERS);
  931. #endif
  932. return true;
  933. }
  934. /**
  935. * Read in and handle a configuration file.
  936. *
  937. * @param File Name of the configuration file.
  938. * @param fd File descriptor already opened for reading.
  939. */
  940. static void
  941. Read_Config_File(const char *File, FILE *fd)
  942. {
  943. char section[LINE_LEN], str[LINE_LEN], *var, *arg, *ptr;
  944. int i, line = 0;
  945. size_t count;
  946. /* Read configuration file */
  947. section[0] = '\0';
  948. while (true) {
  949. if (!fgets(str, sizeof(str), fd))
  950. break;
  951. ngt_TrimStr(str);
  952. line++;
  953. /* Skip comments and empty lines */
  954. if (str[0] == ';' || str[0] == '#' || str[0] == '\0')
  955. continue;
  956. if (strlen(str) >= sizeof(str) - 1) {
  957. Config_Error(LOG_WARNING, "%s, line %d too long!",
  958. File, line);
  959. continue;
  960. }
  961. /* Is this the beginning of a new section? */
  962. if ((str[0] == '[') && (str[strlen(str) - 1] == ']')) {
  963. strlcpy(section, str, sizeof(section));
  964. if (strcasecmp(section, "[GLOBAL]") == 0
  965. || strcasecmp(section, "[LIMITS]") == 0
  966. || strcasecmp(section, "[OPTIONS]") == 0
  967. #ifdef SSL_SUPPORT
  968. || strcasecmp(section, "[SSL]") == 0
  969. #endif
  970. )
  971. continue;
  972. if (strcasecmp(section, "[SERVER]") == 0) {
  973. /* Check if there is already a server to add */
  974. if (New_Server.name[0]) {
  975. /* Copy data to "real" server structure */
  976. assert(New_Server_Idx > NONE);
  977. Conf_Server[New_Server_Idx] =
  978. New_Server;
  979. }
  980. /* Re-init structure for new server */
  981. Init_Server_Struct(&New_Server);
  982. /* Search unused item in server configuration structure */
  983. for (i = 0; i < MAX_SERVERS; i++) {
  984. /* Is this item used? */
  985. if (!Conf_Server[i].name[0])
  986. break;
  987. }
  988. if (i >= MAX_SERVERS) {
  989. /* Oops, no free item found! */
  990. Config_Error(LOG_ERR,
  991. "Too many servers configured.");
  992. New_Server_Idx = NONE;
  993. } else
  994. New_Server_Idx = i;
  995. continue;
  996. }
  997. if (strcasecmp(section, "[CHANNEL]") == 0) {
  998. count = array_length(&Conf_Channels,
  999. sizeof(struct
  1000. Conf_Channel));
  1001. if (!array_alloc
  1002. (&Conf_Channels,
  1003. sizeof(struct Conf_Channel), count)) {
  1004. Config_Error(LOG_ERR,
  1005. "Could not allocate memory for new operator (line %d)",
  1006. line);
  1007. }
  1008. continue;
  1009. }
  1010. if (strcasecmp(section, "[OPERATOR]") == 0) {
  1011. count = array_length(&Conf_Opers,
  1012. sizeof(struct Conf_Oper));
  1013. if (!array_alloc(&Conf_Opers,
  1014. sizeof(struct Conf_Oper),
  1015. count)) {
  1016. Config_Error(LOG_ERR,
  1017. "Could not allocate memory for new channel (line &d)",
  1018. line);
  1019. }
  1020. continue;
  1021. }
  1022. Config_Error(LOG_ERR,
  1023. "%s, line %d: Unknown section \"%s\"!",
  1024. File, line, section);
  1025. section[0] = 0x1;
  1026. }
  1027. if (section[0] == 0x1)
  1028. continue;
  1029. /* Split line into variable name and parameters */
  1030. ptr = strchr(str, '=');
  1031. if (!ptr) {
  1032. Config_Error(LOG_ERR, "%s, line %d: Syntax error!",
  1033. File, line);
  1034. continue;
  1035. }
  1036. *ptr = '\0';
  1037. var = str;
  1038. ngt_TrimStr(var);
  1039. arg = ptr + 1;
  1040. ngt_TrimStr(arg);
  1041. if (strcasecmp(section, "[GLOBAL]") == 0)
  1042. Handle_GLOBAL(File, line, var, arg);
  1043. else if (strcasecmp(section, "[LIMITS]") == 0)
  1044. Handle_LIMITS(File, line, var, arg);
  1045. else if (strcasecmp(section, "[OPTIONS]") == 0)
  1046. Handle_OPTIONS(File, line, var, arg);
  1047. #ifdef SSL_SUPPORT
  1048. else if (strcasecmp(section, "[SSL]") == 0)
  1049. Handle_SSL(File, line, var, arg);
  1050. #endif
  1051. else if (strcasecmp(section, "[OPERATOR]") == 0)
  1052. Handle_OPERATOR(File, line, var, arg);
  1053. else if (strcasecmp(section, "[SERVER]") == 0)
  1054. Handle_SERVER(File, line, var, arg);
  1055. else if (strcasecmp(section, "[CHANNEL]") == 0)
  1056. Handle_CHANNEL(File, line, var, arg);
  1057. else
  1058. Config_Error(LOG_ERR,
  1059. "%s, line %d: Variable \"%s\" outside section!",
  1060. File, line, var);
  1061. }
  1062. }
  1063. /**
  1064. * Check whether a string argument is "true" or "false".
  1065. *
  1066. * @param Arg Input string.
  1067. * @returns true if the input string has been parsed as "yes", "true"
  1068. * (case insensitive) or a non-zero integer value.
  1069. */
  1070. static bool
  1071. Check_ArgIsTrue(const char *Arg)
  1072. {
  1073. if (strcasecmp(Arg, "yes") == 0)
  1074. return true;
  1075. if (strcasecmp(Arg, "true") == 0)
  1076. return true;
  1077. if (atoi(Arg) != 0)
  1078. return true;
  1079. return false;
  1080. }
  1081. /**
  1082. * Handle setting of "MaxNickLength".
  1083. *
  1084. * @param Line Line number in configuration file.
  1085. * @raram Arg Input string.
  1086. * @returns New configured maximum nickname length.
  1087. */
  1088. static unsigned int
  1089. Handle_MaxNickLength(const char *File, int Line, const char *Arg)
  1090. {
  1091. unsigned new;
  1092. new = (unsigned) atoi(Arg) + 1;
  1093. if (new > CLIENT_NICK_LEN) {
  1094. Config_Error(LOG_WARNING,
  1095. "%s, line %d: Value of \"MaxNickLength\" exceeds %u!",
  1096. File, Line, CLIENT_NICK_LEN - 1);
  1097. return CLIENT_NICK_LEN;
  1098. }
  1099. if (new < 2) {
  1100. Config_Error(LOG_WARNING,
  1101. "%s, line %d: Value of \"MaxNickLength\" must be at least 1!",
  1102. File, Line);
  1103. return 2;
  1104. }
  1105. return new;
  1106. }
  1107. /**
  1108. * Output a warning messages if IDENT is configured but not compiled in.
  1109. */
  1110. static void
  1111. WarnIdent(const char UNUSED *File, int UNUSED Line)
  1112. {
  1113. #ifndef IDENTAUTH
  1114. if (Conf_Ident) {
  1115. /* user has enabled ident lookups explicitly, but ... */
  1116. Config_Error(LOG_WARNING,
  1117. "%s: line %d: \"Ident = yes\", but ngircd was built without IDENT support!",
  1118. File, Line);
  1119. }
  1120. #endif
  1121. }
  1122. /**
  1123. * Output a warning messages if IPv6 is configured but not compiled in.
  1124. */
  1125. static void
  1126. WarnIPv6(const char UNUSED *File, int UNUSED Line)
  1127. {
  1128. #ifndef WANT_IPV6
  1129. if (Conf_ConnectIPv6) {
  1130. /* user has enabled IPv6 explicitly, but ... */
  1131. Config_Error(LOG_WARNING,
  1132. "%s: line %d: \"ConnectIPv6 = yes\", but ngircd was built without IPv6 support!",
  1133. File, Line);
  1134. }
  1135. #endif
  1136. }
  1137. /**
  1138. * Output a warning messages if PAM is configured but not compiled in.
  1139. */
  1140. static void
  1141. WarnPAM(const char UNUSED *File, int UNUSED Line)
  1142. {
  1143. #ifndef PAM
  1144. if (Conf_PAM) {
  1145. Config_Error(LOG_WARNING,
  1146. "%s: line %d: \"PAM = yes\", but ngircd was built without PAM support!",
  1147. File, Line);
  1148. }
  1149. #endif
  1150. }
  1151. /**
  1152. * Handle legacy "NoXXX" options in [GLOBAL] section.
  1153. *
  1154. * TODO: This function and support for "NoXXX" could be removed starting
  1155. * with ngIRCd release 19 (one release after marking it "deprecated").
  1156. *
  1157. * @param Var Variable name.
  1158. * @param Arg Argument string.
  1159. * @returns true if a NoXXX option has been processed; false otherwise.
  1160. */
  1161. static bool
  1162. CheckLegacyNoOption(const char *Var, const char *Arg)
  1163. {
  1164. if(strcasecmp(Var, "NoDNS") == 0) {
  1165. Conf_DNS = !Check_ArgIsTrue( Arg );
  1166. return true;
  1167. }
  1168. if (strcasecmp(Var, "NoIdent") == 0) {
  1169. Conf_Ident = !Check_ArgIsTrue(Arg);
  1170. return true;
  1171. }
  1172. if(strcasecmp(Var, "NoPAM") == 0) {
  1173. Conf_PAM = !Check_ArgIsTrue(Arg);
  1174. return true;
  1175. }
  1176. return false;
  1177. }
  1178. /**
  1179. * Handle deprecated legacy options in [GLOBAL] section.
  1180. *
  1181. * TODO: This function and support for these options in the [Global] section
  1182. * could be removed starting with ngIRCd release 19 (one release after
  1183. * marking it "deprecated").
  1184. *
  1185. * @param Var Variable name.
  1186. * @param Arg Argument string.
  1187. * @returns true if a legacy option has been processed; false otherwise.
  1188. */
  1189. static const char*
  1190. CheckLegacyGlobalOption(const char *File, int Line, char *Var, char *Arg)
  1191. {
  1192. if (strcasecmp(Var, "AllowRemoteOper") == 0
  1193. || strcasecmp(Var, "ChrootDir") == 0
  1194. || strcasecmp(Var, "ConnectIPv4") == 0
  1195. || strcasecmp(Var, "ConnectIPv6") == 0
  1196. || strcasecmp(Var, "OperCanUseMode") == 0
  1197. || strcasecmp(Var, "OperChanPAutoOp") == 0
  1198. || strcasecmp(Var, "OperServerMode") == 0
  1199. || strcasecmp(Var, "PredefChannelsOnly") == 0
  1200. || strcasecmp(Var, "SyslogFacility") == 0
  1201. || strcasecmp(Var, "WebircPassword") == 0) {
  1202. Handle_OPTIONS(File, Line, Var, Arg);
  1203. return "[Options]";
  1204. }
  1205. if (strcasecmp(Var, "ConnectRetry") == 0
  1206. || strcasecmp(Var, "IdleTimeout") == 0
  1207. || strcasecmp(Var, "MaxConnections") == 0
  1208. || strcasecmp(Var, "MaxConnectionsIP") == 0
  1209. || strcasecmp(Var, "MaxJoins") == 0
  1210. || strcasecmp(Var, "MaxNickLength") == 0
  1211. || strcasecmp(Var, "PingTimeout") == 0
  1212. || strcasecmp(Var, "PongTimeout") == 0) {
  1213. Handle_LIMITS(File, Line, Var, Arg);
  1214. return "[Limits]";
  1215. }
  1216. #ifdef SSL_SUPPORT
  1217. if (strcasecmp(Var, "SSLCertFile") == 0
  1218. || strcasecmp(Var, "SSLDHFile") == 0
  1219. || strcasecmp(Var, "SSLKeyFile") == 0
  1220. || strcasecmp(Var, "SSLKeyFilePassword") == 0
  1221. || strcasecmp(Var, "SSLPorts") == 0) {
  1222. Handle_SSL(File, Line, Var + 3, Arg);
  1223. return "[SSL]";
  1224. }
  1225. #endif
  1226. return NULL;
  1227. }
  1228. /**
  1229. * Strip "no" prefix of a string.
  1230. *
  1231. * TODO: This function and support for "NoXXX" should be removed starting
  1232. * with ngIRCd release 19! (One release after marking it "deprecated").
  1233. *
  1234. * @param str Pointer to input string starting with "no".
  1235. * @returns New pointer to string without "no" prefix.
  1236. */
  1237. static const char *
  1238. NoNo(const char *str)
  1239. {
  1240. assert(strncasecmp("no", str, 2) == 0 && str[2]);
  1241. return str + 2;
  1242. }
  1243. /**
  1244. * Invert "boolean" string.
  1245. *
  1246. * TODO: This function and support for "NoXXX" should be removed starting
  1247. * with ngIRCd release 19! (One release after marking it "deprecated").
  1248. *
  1249. * @param arg "Boolean" input string.
  1250. * @returns Pointer to inverted "boolean string".
  1251. */
  1252. static const char *
  1253. InvertArg(const char *arg)
  1254. {
  1255. return yesno_to_str(!Check_ArgIsTrue(arg));
  1256. }
  1257. /**
  1258. * Handle variable in [Global] configuration section.
  1259. *
  1260. * @param Line Line numer in configuration file.
  1261. * @param Var Variable name.
  1262. * @param Arg Variable argument.
  1263. */
  1264. static void
  1265. Handle_GLOBAL(const char *File, int Line, char *Var, char *Arg )
  1266. {
  1267. struct passwd *pwd;
  1268. struct group *grp;
  1269. size_t len;
  1270. const char *section;
  1271. assert(File != NULL);
  1272. assert(Line > 0);
  1273. assert(Var != NULL);
  1274. assert(Arg != NULL);
  1275. if (strcasecmp(Var, "Name") == 0) {
  1276. len = strlcpy(Conf_ServerName, Arg, sizeof(Conf_ServerName));
  1277. if (len >= sizeof(Conf_ServerName))
  1278. Config_Error_TooLong(File, Line, Var);
  1279. return;
  1280. }
  1281. if (strcasecmp(Var, "AdminInfo1") == 0) {
  1282. len = strlcpy(Conf_ServerAdmin1, Arg, sizeof(Conf_ServerAdmin1));
  1283. if (len >= sizeof(Conf_ServerAdmin1))
  1284. Config_Error_TooLong(File, Line, Var);
  1285. return;
  1286. }
  1287. if (strcasecmp(Var, "AdminInfo2") == 0) {
  1288. len = strlcpy(Conf_ServerAdmin2, Arg, sizeof(Conf_ServerAdmin2));
  1289. if (len >= sizeof(Conf_ServerAdmin2))
  1290. Config_Error_TooLong(File, Line, Var);
  1291. return;
  1292. }
  1293. if (strcasecmp(Var, "AdminEMail") == 0) {
  1294. len = strlcpy(Conf_ServerAdminMail, Arg,
  1295. sizeof(Conf_ServerAdminMail));
  1296. if (len >= sizeof(Conf_ServerAdminMail))
  1297. Config_Error_TooLong(File, Line, Var);
  1298. return;
  1299. }
  1300. if (strcasecmp(Var, "Info") == 0) {
  1301. len = strlcpy(Conf_ServerInfo, Arg, sizeof(Conf_ServerInfo));
  1302. if (len >= sizeof(Conf_ServerInfo))
  1303. Config_Error_TooLong(File, Line, Var);
  1304. return;
  1305. }
  1306. if (strcasecmp(Var, "HelpFile") == 0) {
  1307. len = strlcpy(Conf_HelpFile, Arg, sizeof(Conf_HelpFile));
  1308. if (len >= sizeof(Conf_HelpFile))
  1309. Config_Error_TooLong(File, Line, Var);
  1310. return;
  1311. }
  1312. if (strcasecmp(Var, "Listen") == 0) {
  1313. if (Conf_ListenAddress) {
  1314. Config_Error(LOG_ERR,
  1315. "Multiple Listen= options, ignoring: %s",
  1316. Arg);
  1317. return;
  1318. }
  1319. Conf_ListenAddress = strdup_warn(Arg);
  1320. /* If allocation fails, we're in trouble: we cannot ignore the
  1321. * error -- otherwise ngircd would listen on all interfaces. */
  1322. if (!Conf_ListenAddress) {
  1323. Config_Error(LOG_ALERT,
  1324. "%s exiting due to fatal errors!",
  1325. PACKAGE_NAME);
  1326. exit(1);
  1327. }
  1328. return;
  1329. }
  1330. if (strcasecmp(Var, "MotdFile") == 0) {
  1331. len = strlcpy(Conf_MotdFile, Arg, sizeof(Conf_MotdFile));
  1332. if (len >= sizeof(Conf_MotdFile))
  1333. Config_Error_TooLong(File, Line, Var);
  1334. return;
  1335. }
  1336. if (strcasecmp(Var, "MotdPhrase") == 0) {
  1337. len = strlen(Arg);
  1338. if (len == 0)
  1339. return;
  1340. if (len >= 127) {
  1341. Config_Error_TooLong(File, Line, Var);
  1342. return;
  1343. }
  1344. if (!array_copyb(&Conf_Motd, Arg, len + 1))
  1345. Config_Error(LOG_WARNING,
  1346. "%s, line %d: Could not append MotdPhrase: %s",
  1347. File, Line, strerror(errno));
  1348. Using_MotdFile = false;
  1349. return;
  1350. }
  1351. if(strcasecmp(Var, "Password") == 0) {
  1352. len = strlcpy(Conf_ServerPwd, Arg, sizeof(Conf_ServerPwd));
  1353. if (len >= sizeof(Conf_ServerPwd))
  1354. Config_Error_TooLong(File, Line, Var);
  1355. return;
  1356. }
  1357. if (strcasecmp(Var, "PidFile") == 0) {
  1358. len = strlcpy(Conf_PidFile, Arg, sizeof(Conf_PidFile));
  1359. if (len >= sizeof(Conf_PidFile))
  1360. Config_Error_TooLong(File, Line, Var);
  1361. return;
  1362. }
  1363. if (strcasecmp(Var, "Ports") == 0) {
  1364. ports_parse(&Conf_ListenPorts, File, Line, Arg);
  1365. return;
  1366. }
  1367. if (strcasecmp(Var, "ServerGID") == 0) {
  1368. grp = getgrnam(Arg);
  1369. if (grp)
  1370. Conf_GID = grp->gr_gid;
  1371. else {
  1372. Conf_GID = (unsigned int)atoi(Arg);
  1373. if (!Conf_GID && strcmp(Arg, "0"))
  1374. Config_Error(LOG_WARNING,
  1375. "%s, line %d: Value of \"%s\" is not a valid group name or ID!",
  1376. File, Line, Var);
  1377. }
  1378. return;
  1379. }
  1380. if (strcasecmp(Var, "ServerUID") == 0) {
  1381. pwd = getpwnam(Arg);
  1382. if (pwd)
  1383. Conf_UID = pwd->pw_uid;
  1384. else {
  1385. Conf_UID = (unsigned int)atoi(Arg);
  1386. if (!Conf_UID && strcmp(Arg, "0"))
  1387. Config_Error(LOG_WARNING,
  1388. "%s, line %d: Value of \"%s\" is not a valid user name or ID!",
  1389. File, Line, Var);
  1390. }
  1391. return;
  1392. }
  1393. if (CheckLegacyNoOption(Var, Arg)) {
  1394. /* TODO: This function and support for "NoXXX" could be
  1395. * be removed starting with ngIRCd release 19 (one release
  1396. * after marking it "deprecated"). */
  1397. Config_Error(LOG_WARNING,
  1398. "%s, line %d (section \"Global\"): \"No\"-Prefix is deprecated, use \"%s = %s\" in [Options] section!",
  1399. File, Line, NoNo(Var), InvertArg(Arg));
  1400. if (strcasecmp(Var, "NoIdent") == 0)
  1401. WarnIdent(File, Line);
  1402. else if (strcasecmp(Var, "NoPam") == 0)
  1403. WarnPAM(File, Line);
  1404. return;
  1405. }
  1406. if ((section = CheckLegacyGlobalOption(File, Line, Var, Arg))) {
  1407. /** TODO: This function and support for these options in the
  1408. * [Global] section could be removed starting with ngIRCd
  1409. * release 19 (one release after marking it "deprecated"). */
  1410. if (strncasecmp(Var, "SSL", 3) == 0) {
  1411. Config_Error(LOG_WARNING,
  1412. "%s, line %d (section \"Global\"): \"%s\" is deprecated here, move it to %s and rename to \"%s\"!",
  1413. File, Line, Var, section,
  1414. Var + 3);
  1415. } else {
  1416. Config_Error(LOG_WARNING,
  1417. "%s, line %d (section \"Global\"): \"%s\" is deprecated here, move it to %s!",
  1418. File, Line, Var, section);
  1419. }
  1420. return;
  1421. }
  1422. Config_Error_Section(File, Line, Var, "Global");
  1423. }
  1424. /**
  1425. * Handle variable in [Limits] configuration section.
  1426. *
  1427. * @param Line Line numer in configuration file.
  1428. * @param Var Variable name.
  1429. * @param Arg Variable argument.
  1430. */
  1431. static void
  1432. Handle_LIMITS(const char *File, int Line, char *Var, char *Arg)
  1433. {
  1434. assert(File != NULL);
  1435. assert(Line > 0);
  1436. assert(Var != NULL);
  1437. assert(Arg != NULL);
  1438. if (strcasecmp(Var, "ConnectRetry") == 0) {
  1439. Conf_ConnectRetry = atoi(Arg);
  1440. if (Conf_ConnectRetry < 5) {
  1441. Config_Error(LOG_WARNING,
  1442. "%s, line %d: Value of \"ConnectRetry\" too low!",
  1443. File, Line);
  1444. Conf_ConnectRetry = 5;
  1445. }
  1446. return;
  1447. }
  1448. if (strcasecmp(Var, "IdleTimeout") == 0) {
  1449. Conf_IdleTimeout = atoi(Arg);
  1450. if (!Conf_IdleTimeout && strcmp(Arg, "0"))
  1451. Config_Error_NaN(File, Line, Var);
  1452. return;
  1453. }
  1454. if (strcasecmp(Var, "MaxConnections") == 0) {
  1455. Conf_MaxConnections = atoi(Arg);
  1456. if (!Conf_MaxConnections && strcmp(Arg, "0"))
  1457. Config_Error_NaN(File, Line, Var);
  1458. return;
  1459. }
  1460. if (strcasecmp(Var, "MaxConnectionsIP") == 0) {
  1461. Conf_MaxConnectionsIP = atoi(Arg);
  1462. if (!Conf_MaxConnectionsIP && strcmp(Arg, "0"))
  1463. Config_Error_NaN(File, Line, Var);
  1464. return;
  1465. }
  1466. if (strcasecmp(Var, "MaxJoins") == 0) {
  1467. Conf_MaxJoins = atoi(Arg);
  1468. if (!Conf_MaxJoins && strcmp(Arg, "0"))
  1469. Config_Error_NaN(File, Line, Var);
  1470. return;
  1471. }
  1472. if (strcasecmp(Var, "MaxNickLength") == 0) {
  1473. Conf_MaxNickLength = Handle_MaxNickLength(File, Line, Arg);
  1474. return;
  1475. }
  1476. if (strcasecmp(Var, "MaxListSize") == 0) {
  1477. Conf_MaxListSize = atoi(Arg);
  1478. if (!Conf_MaxListSize && strcmp(Arg, "0"))
  1479. Config_Error_NaN(File, Line, Var);
  1480. return;
  1481. }
  1482. if (strcasecmp(Var, "PingTimeout") == 0) {
  1483. Conf_PingTimeout = atoi(Arg);
  1484. if (Conf_PingTimeout < 5) {
  1485. Config_Error(LOG_WARNING,
  1486. "%s, line %d: Value of \"PingTimeout\" too low!",
  1487. File, Line);
  1488. Conf_PingTimeout = 5;
  1489. }
  1490. return;
  1491. }
  1492. if (strcasecmp(Var, "PongTimeout") == 0) {
  1493. Conf_PongTimeout = atoi(Arg);
  1494. if (Conf_PongTimeout < 5) {
  1495. Config_Error(LOG_WARNING,
  1496. "%s, line %d: Value of \"PongTimeout\" too low!",
  1497. File, Line);
  1498. Conf_PongTimeout = 5;
  1499. }
  1500. return;
  1501. }
  1502. Config_Error_Section(File, Line, Var, "Limits");
  1503. }
  1504. /**
  1505. * Handle variable in [Options] configuration section.
  1506. *
  1507. * @param Line Line numer in configuration file.
  1508. * @param Var Variable name.
  1509. * @param Arg Variable argument.
  1510. */
  1511. static void
  1512. Handle_OPTIONS(const char *File, int Line, char *Var, char *Arg)
  1513. {
  1514. size_t len;
  1515. char *p;
  1516. assert(File != NULL);
  1517. assert(Line > 0);
  1518. assert(Var != NULL);
  1519. assert(Arg != NULL);
  1520. if (strcasecmp(Var, "AllowedChannelTypes") == 0) {
  1521. p = Arg;
  1522. Conf_AllowedChannelTypes[0] = '\0';
  1523. while (*p) {
  1524. if (strchr(Conf_AllowedChannelTypes, *p)) {
  1525. /* Prefix is already included; ignore it */
  1526. p++;
  1527. continue;
  1528. }
  1529. if (strchr(CHANTYPES, *p)) {
  1530. len = strlen(Conf_AllowedChannelTypes) + 1;
  1531. assert(len < sizeof(Conf_AllowedChannelTypes));
  1532. Conf_AllowedChannelTypes[len - 1] = *p;
  1533. Conf_AllowedChannelTypes[len] = '\0';
  1534. } else {
  1535. Config_Error(LOG_WARNING,
  1536. "%s, line %d: Unknown channel prefix \"%c\" in \"AllowedChannelTypes\"!",
  1537. File, Line, *p);
  1538. }
  1539. p++;
  1540. }
  1541. return;
  1542. }
  1543. if (strcasecmp(Var, "AllowRemoteOper") == 0) {
  1544. Conf_AllowRemoteOper = Check_ArgIsTrue(Arg);
  1545. return;
  1546. }
  1547. if (strcasecmp(Var, "ChrootDir") == 0) {
  1548. len = strlcpy(Conf_Chroot, Arg, sizeof(Conf_Chroot));
  1549. if (len >= sizeof(Conf_Chroot))
  1550. Config_Error_TooLong(File, Line, Var);
  1551. return;
  1552. }
  1553. if (strcasecmp(Var, "CloakHost") == 0) {
  1554. len = strlcpy(Conf_CloakHost, Arg, sizeof(Conf_CloakHost));
  1555. if (len >= sizeof(Conf_CloakHost))
  1556. Config_Error_TooLong(File, Line, Var);
  1557. return;
  1558. }
  1559. if (strcasecmp(Var, "CloakHostModeX") == 0) {
  1560. len = strlcpy(Conf_CloakHostModeX, Arg, sizeof(Conf_CloakHostModeX));
  1561. if (len >= sizeof(Conf_CloakHostModeX))
  1562. Config_Error_TooLong(File, Line, Var);
  1563. return;
  1564. }
  1565. if (strcasecmp(Var, "CloakHostSalt") == 0) {
  1566. len = strlcpy(Conf_CloakHostSalt, Arg, sizeof(Conf_CloakHostSalt));
  1567. if (len >= sizeof(Conf_CloakHostSalt))
  1568. Config_Error_TooLong(File, Line, Var);
  1569. return;
  1570. }
  1571. if (strcasecmp(Var, "CloakUserToNick") == 0) {
  1572. Conf_CloakUserToNick = Check_ArgIsTrue(Arg);
  1573. return;
  1574. }
  1575. if (strcasecmp(Var, "ConnectIPv6") == 0) {
  1576. Conf_ConnectIPv6 = Check_ArgIsTrue(Arg);
  1577. WarnIPv6(File, Line);
  1578. return;
  1579. }
  1580. if (strcasecmp(Var, "ConnectIPv4") == 0) {
  1581. Conf_ConnectIPv4 = Check_ArgIsTrue(Arg);
  1582. return;
  1583. }
  1584. if (strcasecmp(Var, "DefaultUserModes") == 0) {
  1585. p = Arg;
  1586. Conf_DefaultUserModes[0] = '\0';
  1587. while (*p) {
  1588. if (strchr(Conf_DefaultUserModes, *p)) {
  1589. /* Mode is already included; ignore it */
  1590. p++;
  1591. continue;
  1592. }
  1593. if (strchr(USERMODES, *p)) {
  1594. len = strlen(Conf_DefaultUserModes) + 1;
  1595. assert(len < sizeof(Conf_DefaultUserModes));
  1596. Conf_DefaultUserModes[len - 1] = *p;
  1597. Conf_DefaultUserModes[len] = '\0';
  1598. } else {
  1599. Config_Error(LOG_WARNING,
  1600. "%s, line %d: Unknown user mode \"%c\" in \"DefaultUserModes\"!",
  1601. File, Line, *p);
  1602. }
  1603. p++;
  1604. }
  1605. return;
  1606. }
  1607. if (strcasecmp(Var, "DNS") == 0) {
  1608. Conf_DNS = Check_ArgIsTrue(Arg);
  1609. return;
  1610. }
  1611. if (strcasecmp(Var, "Ident") == 0) {
  1612. Conf_Ident = Check_ArgIsTrue(Arg);
  1613. WarnIdent(File, Line);
  1614. return;
  1615. }
  1616. if (strcasecmp(Var, "IncludeDir") == 0) {
  1617. if (Conf_IncludeDir[0]) {
  1618. Config_Error(LOG_ERR,
  1619. "%s, line %d: Can't overwrite value of \"IncludeDir\" variable!",
  1620. File, Line);
  1621. return;
  1622. }
  1623. len = strlcpy(Conf_IncludeDir, Arg, sizeof(Conf_IncludeDir));
  1624. if (len >= sizeof(Conf_IncludeDir))
  1625. Config_Error_TooLong(File, Line, Var);
  1626. return;
  1627. }
  1628. if (strcasecmp(Var, "MorePrivacy") == 0) {
  1629. Conf_MorePrivacy = Check_ArgIsTrue(Arg);
  1630. return;
  1631. }
  1632. if (strcasecmp(Var, "NoticeAuth") == 0) {
  1633. Conf_NoticeAuth = Check_ArgIsTrue(Arg);
  1634. return;
  1635. }
  1636. if (strcasecmp(Var, "OperCanUseMode") == 0) {
  1637. Conf_OperCanMode = Check_ArgIsTrue(Arg);
  1638. return;
  1639. }
  1640. if (strcasecmp(Var, "OperChanPAutoOp") == 0) {
  1641. Conf_OperChanPAutoOp = Check_ArgIsTrue(Arg);
  1642. return;
  1643. }
  1644. if (strcasecmp(Var, "OperServerMode") == 0) {
  1645. Conf_OperServerMode = Check_ArgIsTrue(Arg);
  1646. return;
  1647. }
  1648. if (strcasecmp(Var, "PAM") == 0) {
  1649. Conf_PAM = Check_ArgIsTrue(Arg);
  1650. WarnPAM(File, Line);
  1651. return;
  1652. }
  1653. if (strcasecmp(Var, "PAMIsOptional") == 0 ) {
  1654. Conf_PAMIsOptional = Check_ArgIsTrue(Arg);
  1655. return;
  1656. }
  1657. if (strcasecmp(Var, "PredefChannelsOnly") == 0) {
  1658. /*
  1659. * TODO: This section and support for "PredefChannelsOnly"
  1660. * could be removed starting with ngIRCd release 22 (one
  1661. * release after marking it "deprecated") ...
  1662. */
  1663. Config_Error(LOG_WARNING,
  1664. "%s, line %d (section \"Options\"): \"%s\" is deprecated, please use \"AllowedChannelTypes\"!",
  1665. File, Line, Var);
  1666. if (Check_ArgIsTrue(Arg))
  1667. Conf_AllowedChannelTypes[0] = '\0';
  1668. else
  1669. strlcpy(Conf_AllowedChannelTypes, CHANTYPES,
  1670. sizeof(Conf_AllowedChannelTypes));
  1671. return;
  1672. }
  1673. #ifndef STRICT_RFC
  1674. if (strcasecmp(Var, "RequireAuthPing") == 0) {
  1675. Conf_AuthPing = Check_ArgIsTrue(Arg);
  1676. return;
  1677. }
  1678. #endif
  1679. if (strcasecmp(Var, "ScrubCTCP") == 0) {
  1680. Conf_ScrubCTCP = Check_ArgIsTrue(Arg);
  1681. return;
  1682. }
  1683. #ifdef SYSLOG
  1684. if (strcasecmp(Var, "SyslogFacility") == 0) {
  1685. Conf_SyslogFacility = ngt_SyslogFacilityID(Arg,
  1686. Conf_SyslogFacility);
  1687. return;
  1688. }
  1689. #endif
  1690. if (strcasecmp(Var, "WebircPassword") == 0) {
  1691. len = strlcpy(Conf_WebircPwd, Arg, sizeof(Conf_WebircPwd));
  1692. if (len >= sizeof(Conf_WebircPwd))
  1693. Config_Error_TooLong(File, Line, Var);
  1694. return;
  1695. }
  1696. Config_Error_Section(File, Line, Var, "Options");
  1697. }
  1698. #ifdef SSL_SUPPORT
  1699. /**
  1700. * Handle variable in [SSL] configuration section.
  1701. *
  1702. * @param Line Line numer in configuration file.
  1703. * @param Var Variable name.
  1704. * @param Arg Variable argument.
  1705. */
  1706. static void
  1707. Handle_SSL(const char *File, int Line, char *Var, char *Arg)
  1708. {
  1709. assert(File != NULL);
  1710. assert(Line > 0);
  1711. assert(Var != NULL);
  1712. assert(Arg != NULL);
  1713. if (strcasecmp(Var, "CertFile") == 0) {
  1714. assert(Conf_SSLOptions.CertFile == NULL);
  1715. Conf_SSLOptions.CertFile = strdup_warn(Arg);
  1716. return;
  1717. }
  1718. if (strcasecmp(Var, "DHFile") == 0) {
  1719. assert(Conf_SSLOptions.DHFile == NULL);
  1720. Conf_SSLOptions.DHFile = strdup_warn(Arg);
  1721. return;
  1722. }
  1723. if (strcasecmp(Var, "KeyFile") == 0) {
  1724. assert(Conf_SSLOptions.KeyFile == NULL);
  1725. Conf_SSLOptions.KeyFile = strdup_warn(Arg);
  1726. return;
  1727. }
  1728. if (strcasecmp(Var, "KeyFilePassword") == 0) {
  1729. assert(array_bytes(&Conf_SSLOptions.KeyFilePassword) == 0);
  1730. if (!array_copys(&Conf_SSLOptions.KeyFilePassword, Arg))
  1731. Config_Error(LOG_ERR,
  1732. "%s, line %d (section \"SSL\"): Could not copy %s: %s!",
  1733. File, Line, Var, strerror(errno));
  1734. return;
  1735. }
  1736. if (strcasecmp(Var, "Ports") == 0) {
  1737. ports_parse(&Conf_SSLOptions.ListenPorts, File, Line, Arg);
  1738. return;
  1739. }
  1740. if (strcasecmp(Var, "CipherList") == 0) {
  1741. assert(Conf_SSLOptions.CipherList == NULL);
  1742. Conf_SSLOptions.CipherList = strdup_warn(Arg);
  1743. return;
  1744. }
  1745. Config_Error_Section(File, Line, Var, "SSL");
  1746. }
  1747. #endif
  1748. /**
  1749. * Handle variable in [Operator] configuration section.
  1750. *
  1751. * @param Line Line numer in configuration file.
  1752. * @param Var Variable name.
  1753. * @param Arg Variable argument.
  1754. */
  1755. static void
  1756. Handle_OPERATOR(const char *File, int Line, char *Var, char *Arg )
  1757. {
  1758. size_t len;
  1759. struct Conf_Oper *op;
  1760. assert( File != NULL );
  1761. assert( Line > 0 );
  1762. assert( Var != NULL );
  1763. assert( Arg != NULL );
  1764. op = array_get(&Conf_Opers, sizeof(*op),
  1765. array_length(&Conf_Opers, sizeof(*op)) - 1);
  1766. if (!op)
  1767. return;
  1768. if (strcasecmp(Var, "Name") == 0) {
  1769. /* Name of IRC operator */
  1770. len = strlcpy(op->name, Arg, sizeof(op->name));
  1771. if (len >= sizeof(op->name))
  1772. Config_Error_TooLong(File, Line, Var);
  1773. return;
  1774. }
  1775. if (strcasecmp(Var, "Password") == 0) {
  1776. /* Password of IRC operator */
  1777. len = strlcpy(op->pwd, Arg, sizeof(op->pwd));
  1778. if (len >= sizeof(op->pwd))
  1779. Config_Error_TooLong(File, Line, Var);
  1780. return;
  1781. }
  1782. if (strcasecmp(Var, "Mask") == 0) {
  1783. if (op->mask)
  1784. return; /* Hostname already configured */
  1785. op->mask = strdup_warn( Arg );
  1786. return;
  1787. }
  1788. Config_Error_Section(File, Line, Var, "Operator");
  1789. }
  1790. /**
  1791. * Handle variable in [Server] configuration section.
  1792. *
  1793. * @param Line Line numer in configuration file.
  1794. * @param Var Variable name.
  1795. * @param Arg Variable argument.
  1796. */
  1797. static void
  1798. Handle_SERVER(const char *File, int Line, char *Var, char *Arg )
  1799. {
  1800. long port;
  1801. size_t len;
  1802. assert( File != NULL );
  1803. assert( Line > 0 );
  1804. assert( Var != NULL );
  1805. assert( Arg != NULL );
  1806. /* Ignore server block if no space is left in server configuration structure */
  1807. if( New_Server_Idx <= NONE ) return;
  1808. if( strcasecmp( Var, "Host" ) == 0 ) {
  1809. /* Hostname of the server */
  1810. len = strlcpy( New_Server.host, Arg, sizeof( New_Server.host ));
  1811. if (len >= sizeof( New_Server.host ))
  1812. Config_Error_TooLong(File, Line, Var);
  1813. return;
  1814. }
  1815. if( strcasecmp( Var, "Name" ) == 0 ) {
  1816. /* Name of the server ("Nick"/"ID") */
  1817. len = strlcpy( New_Server.name, Arg, sizeof( New_Server.name ));
  1818. if (len >= sizeof( New_Server.name ))
  1819. Config_Error_TooLong(File, Line, Var);
  1820. return;
  1821. }
  1822. if (strcasecmp(Var, "Bind") == 0) {
  1823. if (ng_ipaddr_init(&New_Server.bind_addr, Arg, 0))
  1824. return;
  1825. Config_Error(LOG_ERR, "%s, line %d (section \"Server\"): Can't parse IP address \"%s\"",
  1826. File, Line, Arg);
  1827. return;
  1828. }
  1829. if( strcasecmp( Var, "MyPassword" ) == 0 ) {
  1830. /* Password of this server which is sent to the peer */
  1831. if (*Arg == ':') {
  1832. Config_Error(LOG_ERR,
  1833. "%s, line %d (section \"Server\"): MyPassword must not start with ':'!",
  1834. File, Line);
  1835. }
  1836. len = strlcpy( New_Server.pwd_in, Arg, sizeof( New_Server.pwd_in ));
  1837. if (len >= sizeof( New_Server.pwd_in ))
  1838. Config_Error_TooLong(File, Line, Var);
  1839. return;
  1840. }
  1841. if( strcasecmp( Var, "PeerPassword" ) == 0 ) {
  1842. /* Passwort of the peer which must be received */
  1843. len = strlcpy( New_Server.pwd_out, Arg, sizeof( New_Server.pwd_out ));
  1844. if (len >= sizeof( New_Server.pwd_out ))
  1845. Config_Error_TooLong(File, Line, Var);
  1846. return;
  1847. }
  1848. if( strcasecmp( Var, "Port" ) == 0 ) {
  1849. /* Port to which this server should connect */
  1850. port = atol( Arg );
  1851. if (port >= 0 && port < 0xFFFF)
  1852. New_Server.port = (UINT16)port;
  1853. else
  1854. Config_Error(LOG_ERR,
  1855. "%s, line %d (section \"Server\"): Illegal port number %ld!",
  1856. File, Line, port );
  1857. return;
  1858. }
  1859. #ifdef SSL_SUPPORT
  1860. if( strcasecmp( Var, "SSLConnect" ) == 0 ) {
  1861. New_Server.SSLConnect = Check_ArgIsTrue(Arg);
  1862. return;
  1863. }
  1864. #endif
  1865. if( strcasecmp( Var, "Group" ) == 0 ) {
  1866. /* Server group */
  1867. New_Server.group = atoi( Arg );
  1868. if (!New_Server.group && strcmp(Arg, "0"))
  1869. Config_Error_NaN(File, Line, Var);
  1870. return;
  1871. }
  1872. if( strcasecmp( Var, "Passive" ) == 0 ) {
  1873. if (Check_ArgIsTrue(Arg))
  1874. New_Server.flags |= CONF_SFLAG_DISABLED;
  1875. return;
  1876. }
  1877. if (strcasecmp(Var, "ServiceMask") == 0) {
  1878. len = strlcpy(New_Server.svs_mask, ngt_LowerStr(Arg),
  1879. sizeof(New_Server.svs_mask));
  1880. if (len >= sizeof(New_Server.svs_mask))
  1881. Config_Error_TooLong(File, Line, Var);
  1882. return;
  1883. }
  1884. Config_Error_Section(File, Line, Var, "Server");
  1885. }
  1886. /**
  1887. * Copy channel name into channel structure.
  1888. *
  1889. * If the channel name is not valid because of a missing prefix ('#', '&'),
  1890. * a default prefix of '#' will be added.
  1891. *
  1892. * @param new_chan New already allocated channel structure.
  1893. * @param name Name of the new channel.
  1894. * @returns true on success, false otherwise.
  1895. */
  1896. static bool
  1897. Handle_Channelname(struct Conf_Channel *new_chan, const char *name)
  1898. {
  1899. size_t size = sizeof(new_chan->name);
  1900. char *dest = new_chan->name;
  1901. if (!Channel_IsValidName(name)) {
  1902. /*
  1903. * maybe user forgot to add a '#'.
  1904. * This is only here for user convenience.
  1905. */
  1906. *dest = '#';
  1907. --size;
  1908. ++dest;
  1909. }
  1910. return size > strlcpy(dest, name, size);
  1911. }
  1912. /**
  1913. * Handle variable in [Channel] configuration section.
  1914. *
  1915. * @param Line Line numer in configuration file.
  1916. * @param Var Variable name.
  1917. * @param Arg Variable argument.
  1918. */
  1919. static void
  1920. Handle_CHANNEL(const char *File, int Line, char *Var, char *Arg)
  1921. {
  1922. size_t len;
  1923. struct Conf_Channel *chan;
  1924. assert( File != NULL );
  1925. assert( Line > 0 );
  1926. assert( Var != NULL );
  1927. assert( Arg != NULL );
  1928. chan = array_get(&Conf_Channels, sizeof(*chan),
  1929. array_length(&Conf_Channels, sizeof(*chan)) - 1);
  1930. if (!chan)
  1931. return;
  1932. if (strcasecmp(Var, "Name") == 0) {
  1933. if (!Handle_Channelname(chan, Arg))
  1934. Config_Error_TooLong(File, Line, Var);
  1935. return;
  1936. }
  1937. if (strcasecmp(Var, "Modes") == 0) {
  1938. /* Initial modes */
  1939. len = strlcpy(chan->modes, Arg, sizeof(chan->modes));
  1940. if (len >= sizeof(chan->modes))
  1941. Config_Error_TooLong(File, Line, Var);
  1942. return;
  1943. }
  1944. if( strcasecmp( Var, "Topic" ) == 0 ) {
  1945. /* Initial topic */
  1946. len = strlcpy(chan->topic, Arg, sizeof(chan->topic));
  1947. if (len >= sizeof(chan->topic))
  1948. Config_Error_TooLong(File, Line, Var);
  1949. return;
  1950. }
  1951. if( strcasecmp( Var, "Key" ) == 0 ) {
  1952. /* Initial Channel Key (mode k) */
  1953. len = strlcpy(chan->key, Arg, sizeof(chan->key));
  1954. if (len >= sizeof(chan->key))
  1955. Config_Error_TooLong(File, Line, Var);
  1956. return;
  1957. }
  1958. if( strcasecmp( Var, "MaxUsers" ) == 0 ) {
  1959. /* maximum user limit, mode l */
  1960. chan->maxusers = (unsigned long) atol(Arg);
  1961. if (!chan->maxusers && strcmp(Arg, "0"))
  1962. Config_Error_NaN(File, Line, Var);
  1963. return;
  1964. }
  1965. if (strcasecmp(Var, "KeyFile") == 0) {
  1966. /* channel keys */
  1967. len = strlcpy(chan->keyfile, Arg, sizeof(chan->keyfile));
  1968. if (len >= sizeof(chan->keyfile))
  1969. Config_Error_TooLong(File, Line, Var);
  1970. return;
  1971. }
  1972. Config_Error_Section(File, Line, Var, "Channel");
  1973. }
  1974. /**
  1975. * Validate server configuration.
  1976. *
  1977. * Please note that this function uses exit(1) on fatal errors and therefore
  1978. * can result in ngIRCd terminating!
  1979. *
  1980. * @param Configtest true if the daemon has been called with "--configtest".
  1981. * @param Rehash true if re-reading configuration on runtime.
  1982. * @returns true if configuration is valid.
  1983. */
  1984. static bool
  1985. Validate_Config(bool Configtest, bool Rehash)
  1986. {
  1987. /* Validate configuration settings. */
  1988. #ifdef DEBUG
  1989. int i, servers, servers_once;
  1990. #endif
  1991. bool config_valid = true;
  1992. char *ptr;
  1993. /* Emit a warning when the config file is not a full path name */
  1994. if (NGIRCd_ConfFile[0] && NGIRCd_ConfFile[0] != '/') {
  1995. Config_Error(LOG_WARNING,
  1996. "Not specifying a full path name to \"%s\" can cause problems when rehashing the server!",
  1997. NGIRCd_ConfFile);
  1998. }
  1999. /* Validate configured server name, see RFC 2812 section 2.3.1 */
  2000. ptr = Conf_ServerName;
  2001. do {
  2002. if (*ptr >= 'a' && *ptr <= 'z') continue;
  2003. if (*ptr >= 'A' && *ptr <= 'Z') continue;
  2004. if (*ptr >= '0' && *ptr <= '9') continue;
  2005. if (ptr > Conf_ServerName) {
  2006. if (*ptr == '.' || *ptr == '-')
  2007. continue;
  2008. }
  2009. Conf_ServerName[0] = '\0';
  2010. break;
  2011. } while (*(++ptr));
  2012. if (!Conf_ServerName[0]) {
  2013. /* No server name configured! */
  2014. config_valid = false;
  2015. Config_Error(LOG_ALERT,
  2016. "No (valid) server name configured in \"%s\" (section 'Global': 'Name')!",
  2017. NGIRCd_ConfFile);
  2018. if (!Configtest && !Rehash) {
  2019. Config_Error(LOG_ALERT,
  2020. "%s exiting due to fatal errors!",
  2021. PACKAGE_NAME);
  2022. exit(1);
  2023. }
  2024. }
  2025. if (Conf_ServerName[0] && !strchr(Conf_ServerName, '.')) {
  2026. /* No dot in server name! */
  2027. config_valid = false;
  2028. Config_Error(LOG_ALERT,
  2029. "Invalid server name configured in \"%s\" (section 'Global': 'Name'): Dot missing!",
  2030. NGIRCd_ConfFile);
  2031. if (!Configtest) {
  2032. Config_Error(LOG_ALERT,
  2033. "%s exiting due to fatal errors!",
  2034. PACKAGE_NAME);
  2035. exit(1);
  2036. }
  2037. }
  2038. #ifdef STRICT_RFC
  2039. if (!Conf_ServerAdminMail[0]) {
  2040. /* No administrative contact configured! */
  2041. config_valid = false;
  2042. Config_Error(LOG_ALERT,
  2043. "No administrator email address configured in \"%s\" ('AdminEMail')!",
  2044. NGIRCd_ConfFile);
  2045. if (!Configtest) {
  2046. Config_Error(LOG_ALERT,
  2047. "%s exiting due to fatal errors!",
  2048. PACKAGE_NAME);
  2049. exit(1);
  2050. }
  2051. }
  2052. #endif
  2053. if (!Conf_ServerAdmin1[0] && !Conf_ServerAdmin2[0]
  2054. && !Conf_ServerAdminMail[0]) {
  2055. /* No administrative information configured! */
  2056. Config_Error(LOG_WARNING,
  2057. "No administrative information configured but required by RFC!");
  2058. }
  2059. #ifdef PAM
  2060. if (Conf_PAM && Conf_ServerPwd[0])
  2061. Config_Error(LOG_ERR,
  2062. "This server uses PAM, \"Password\" in [Global] section will be ignored!");
  2063. #endif
  2064. #ifdef DEBUG
  2065. servers = servers_once = 0;
  2066. for (i = 0; i < MAX_SERVERS; i++) {
  2067. if (Conf_Server[i].name[0]) {
  2068. servers++;
  2069. if (Conf_Server[i].flags & CONF_SFLAG_ONCE)
  2070. servers_once++;
  2071. }
  2072. }
  2073. Log(LOG_DEBUG,
  2074. "Configuration: Operators=%ld, Servers=%d[%d], Channels=%ld",
  2075. array_length(&Conf_Opers, sizeof(struct Conf_Oper)),
  2076. servers, servers_once,
  2077. array_length(&Conf_Channels, sizeof(struct Conf_Channel)));
  2078. #endif
  2079. return config_valid;
  2080. }
  2081. /**
  2082. * Output "line too long" warning.
  2083. *
  2084. * @param Line Line number in configuration file.
  2085. * @param Item Affected variable name.
  2086. */
  2087. static void
  2088. Config_Error_TooLong(const char *File, const int Line, const char *Item)
  2089. {
  2090. Config_Error(LOG_WARNING, "%s, line %d: Value of \"%s\" too long!",
  2091. File, Line, Item );
  2092. }
  2093. /**
  2094. * Output "unknown variable" warning.
  2095. *
  2096. * @param Line Line number in configuration file.
  2097. * @param Item Affected variable name.
  2098. * @param Section Section name.
  2099. */
  2100. static void
  2101. Config_Error_Section(const char *File, const int Line, const char *Item,
  2102. const char *Section)
  2103. {
  2104. Config_Error(LOG_ERR, "%s, line %d (section \"%s\"): Unknown variable \"%s\"!",
  2105. File, Line, Section, Item);
  2106. }
  2107. /**
  2108. * Output "not a number" warning.
  2109. *
  2110. * @param Line Line number in configuration file.
  2111. * @param Item Affected variable name.
  2112. */
  2113. static void
  2114. Config_Error_NaN(const char *File, const int Line, const char *Item )
  2115. {
  2116. Config_Error(LOG_WARNING, "%s, line %d: Value of \"%s\" is not a number!",
  2117. File, Line, Item );
  2118. }
  2119. /**
  2120. * Output configuration error to console and/or logfile.
  2121. *
  2122. * On runtime, the normal log functions of the daemon are used. But when
  2123. * testing the configuration ("--configtest"), all messages go directly
  2124. * to the console.
  2125. *
  2126. * @param Level Severity level of the message.
  2127. * @param Format Format string; see printf() function.
  2128. */
  2129. #ifdef PROTOTYPES
  2130. static void Config_Error( const int Level, const char *Format, ... )
  2131. #else
  2132. static void Config_Error( Level, Format, va_alist )
  2133. const int Level;
  2134. const char *Format;
  2135. va_dcl
  2136. #endif
  2137. {
  2138. char msg[MAX_LOG_MSG_LEN];
  2139. va_list ap;
  2140. assert( Format != NULL );
  2141. #ifdef PROTOTYPES
  2142. va_start( ap, Format );
  2143. #else
  2144. va_start( ap );
  2145. #endif
  2146. vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
  2147. va_end( ap );
  2148. if (!Use_Log) {
  2149. if (Level <= LOG_WARNING)
  2150. printf(" - %s\n", msg);
  2151. else
  2152. puts(msg);
  2153. } else
  2154. Log(Level, "%s", msg);
  2155. }
  2156. #ifdef DEBUG
  2157. /**
  2158. * Dump internal state of the "configuration module".
  2159. */
  2160. GLOBAL void
  2161. Conf_DebugDump(void)
  2162. {
  2163. int i;
  2164. Log(LOG_DEBUG, "Configured servers:");
  2165. for (i = 0; i < MAX_SERVERS; i++) {
  2166. if (! Conf_Server[i].name[0])
  2167. continue;
  2168. Log(LOG_DEBUG,
  2169. " - %s: %s:%d, last=%ld, group=%d, flags=%d, conn=%d",
  2170. Conf_Server[i].name, Conf_Server[i].host,
  2171. Conf_Server[i].port, Conf_Server[i].lasttry,
  2172. Conf_Server[i].group, Conf_Server[i].flags,
  2173. Conf_Server[i].conn_id);
  2174. }
  2175. }
  2176. #endif
  2177. /**
  2178. * Initialize server configuration structure to default values.
  2179. *
  2180. * @param Server Pointer to server structure to initialize.
  2181. */
  2182. static void
  2183. Init_Server_Struct( CONF_SERVER *Server )
  2184. {
  2185. assert( Server != NULL );
  2186. memset( Server, 0, sizeof (CONF_SERVER) );
  2187. Server->group = NONE;
  2188. Server->lasttry = time( NULL ) - Conf_ConnectRetry + STARTUP_DELAY;
  2189. if( NGIRCd_Passive ) Server->flags = CONF_SFLAG_DISABLED;
  2190. Proc_InitStruct(&Server->res_stat);
  2191. Server->conn_id = NONE;
  2192. memset(&Server->bind_addr, 0, sizeof(Server->bind_addr));
  2193. }
  2194. /* -eof- */