conf.c 63 KB

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