conf.c 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413
  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:!SSLv3"
  76. #endif
  77. #ifdef HAVE_LIBGNUTLS
  78. #define DEFAULT_CIPHERS "SECURE128:-VERS-SSL3.0"
  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. Conf_Server[i].lasttry = 0;
  546. return true;
  547. }
  548. }
  549. return false;
  550. }
  551. /**
  552. * Disable a server by name.
  553. * An already established connection will be disconnected.
  554. *
  555. * @returns true if a server was found and has been disabled.
  556. */
  557. GLOBAL bool
  558. Conf_DisableServer( const char *Name )
  559. {
  560. int i;
  561. assert( Name != NULL );
  562. for( i = 0; i < MAX_SERVERS; i++ ) {
  563. if( strcasecmp( Conf_Server[i].name, Name ) == 0 ) {
  564. /* Gotcha! Disable and disconnect server: */
  565. Conf_Server[i].flags |= CONF_SFLAG_DISABLED;
  566. if( Conf_Server[i].conn_id > NONE )
  567. Conn_Close(Conf_Server[i].conn_id, NULL,
  568. "Server link terminated on operator request",
  569. true);
  570. return true;
  571. }
  572. }
  573. return false;
  574. }
  575. /**
  576. * Add a new remote server to our configuration.
  577. *
  578. * @param Name Name of the new server.
  579. * @param Port Port number to connect to or 0 for incoming connections.
  580. * @param Host Host name to connect to.
  581. * @param MyPwd Password that will be sent to the peer.
  582. * @param PeerPwd Password that must be received from the peer.
  583. * @returns true if the new server has been added; false otherwise.
  584. */
  585. GLOBAL bool
  586. Conf_AddServer(const char *Name, UINT16 Port, const char *Host,
  587. const char *MyPwd, const char *PeerPwd)
  588. {
  589. int i;
  590. assert( Name != NULL );
  591. assert( Host != NULL );
  592. assert( MyPwd != NULL );
  593. assert( PeerPwd != NULL );
  594. /* Search unused item in server configuration structure */
  595. for( i = 0; i < MAX_SERVERS; i++ ) {
  596. /* Is this item used? */
  597. if( ! Conf_Server[i].name[0] ) break;
  598. }
  599. if( i >= MAX_SERVERS ) return false;
  600. Init_Server_Struct( &Conf_Server[i] );
  601. strlcpy( Conf_Server[i].name, Name, sizeof( Conf_Server[i].name ));
  602. strlcpy( Conf_Server[i].host, Host, sizeof( Conf_Server[i].host ));
  603. strlcpy( Conf_Server[i].pwd_out, MyPwd, sizeof( Conf_Server[i].pwd_out ));
  604. strlcpy( Conf_Server[i].pwd_in, PeerPwd, sizeof( Conf_Server[i].pwd_in ));
  605. Conf_Server[i].port = Port;
  606. Conf_Server[i].flags = CONF_SFLAG_ONCE;
  607. return true;
  608. }
  609. /**
  610. * Check if the given nickname is reserved for services on a particular server.
  611. *
  612. * @param ConfServer The server index to check.
  613. * @param Nick The nickname to check.
  614. * @returns true if the given nickname belongs to an "IRC service".
  615. */
  616. GLOBAL bool
  617. Conf_NickIsService(int ConfServer, const char *Nick)
  618. {
  619. assert (ConfServer >= 0);
  620. assert (ConfServer < MAX_SERVERS);
  621. return MatchCaseInsensitiveList(Conf_Server[ConfServer].svs_mask,
  622. Nick, ",");
  623. }
  624. /**
  625. * Check if the given nickname is blocked for "normal client" use.
  626. *
  627. * @param ConfServer The server index or NONE to check all configured servers.
  628. * @param Nick The nickname to check.
  629. * @returns true if the given nickname belongs to an "IRC service".
  630. */
  631. GLOBAL bool
  632. Conf_NickIsBlocked(const char *Nick)
  633. {
  634. int i;
  635. for(i = 0; i < MAX_SERVERS; i++) {
  636. if (!Conf_Server[i].name[0])
  637. continue;
  638. if (Conf_NickIsService(i, Nick))
  639. return true;
  640. }
  641. return false;
  642. }
  643. /**
  644. * Initialize configuration settings with their default values.
  645. */
  646. static void
  647. Set_Defaults(bool InitServers)
  648. {
  649. int i;
  650. char random[RANDOM_SALT_LEN + 1];
  651. /* Global */
  652. strcpy(Conf_ServerName, "");
  653. strcpy(Conf_ServerAdmin1, "");
  654. strcpy(Conf_ServerAdmin2, "");
  655. strcpy(Conf_ServerAdminMail, "");
  656. snprintf(Conf_ServerInfo, sizeof Conf_ServerInfo, "%s %s",
  657. PACKAGE_NAME, PACKAGE_VERSION);
  658. strcpy(Conf_Network, "");
  659. free(Conf_ListenAddress);
  660. Conf_ListenAddress = NULL;
  661. array_free(&Conf_ListenPorts);
  662. array_free(&Conf_Motd);
  663. array_free(&Conf_Helptext);
  664. strlcpy(Conf_MotdFile, SYSCONFDIR, sizeof(Conf_MotdFile));
  665. strlcat(Conf_MotdFile, MOTD_FILE, sizeof(Conf_MotdFile));
  666. strlcpy(Conf_HelpFile, DOCDIR, sizeof(Conf_HelpFile));
  667. strlcat(Conf_HelpFile, HELP_FILE, sizeof(Conf_HelpFile));
  668. strcpy(Conf_ServerPwd, "");
  669. strlcpy(Conf_PidFile, PID_FILE, sizeof(Conf_PidFile));
  670. Conf_UID = Conf_GID = 0;
  671. /* Limits */
  672. Conf_ConnectRetry = 60;
  673. Conf_IdleTimeout = 0;
  674. Conf_MaxConnections = 0;
  675. Conf_MaxConnectionsIP = 5;
  676. Conf_MaxJoins = 10;
  677. Conf_MaxNickLength = CLIENT_NICK_LEN_DEFAULT;
  678. Conf_MaxListSize = 100;
  679. Conf_PingTimeout = 120;
  680. Conf_PongTimeout = 20;
  681. /* Options */
  682. strlcpy(Conf_AllowedChannelTypes, CHANTYPES,
  683. sizeof(Conf_AllowedChannelTypes));
  684. Conf_AllowRemoteOper = false;
  685. #ifndef STRICT_RFC
  686. Conf_AuthPing = false;
  687. #endif
  688. strlcpy(Conf_Chroot, CHROOT_DIR, sizeof(Conf_Chroot));
  689. strcpy(Conf_CloakHost, "");
  690. strcpy(Conf_CloakHostModeX, "");
  691. strlcpy(Conf_CloakHostSalt, ngt_RandomStr(random, RANDOM_SALT_LEN),
  692. sizeof(Conf_CloakHostSalt));
  693. Conf_CloakUserToNick = false;
  694. Conf_ConnectIPv4 = true;
  695. #ifdef WANT_IPV6
  696. Conf_ConnectIPv6 = true;
  697. #else
  698. Conf_ConnectIPv6 = false;
  699. #endif
  700. strcpy(Conf_DefaultUserModes, "");
  701. Conf_DNS = true;
  702. #ifdef IDENTAUTH
  703. Conf_Ident = true;
  704. #else
  705. Conf_Ident = false;
  706. #endif
  707. strcpy(Conf_IncludeDir, "");
  708. Conf_MorePrivacy = false;
  709. Conf_NoticeAuth = false;
  710. Conf_OperCanMode = false;
  711. Conf_OperChanPAutoOp = true;
  712. Conf_OperServerMode = false;
  713. #ifdef PAM
  714. Conf_PAM = true;
  715. #else
  716. Conf_PAM = false;
  717. #endif
  718. Conf_PAMIsOptional = false;
  719. Conf_ScrubCTCP = false;
  720. #ifdef SYSLOG
  721. #ifdef LOG_LOCAL5
  722. Conf_SyslogFacility = LOG_LOCAL5;
  723. #else
  724. Conf_SyslogFacility = 0;
  725. #endif
  726. #endif
  727. /* Initialize server configuration structures */
  728. if (InitServers) {
  729. for (i = 0; i < MAX_SERVERS;
  730. Init_Server_Struct(&Conf_Server[i++]));
  731. }
  732. }
  733. /**
  734. * Get number of configured listening ports.
  735. *
  736. * @returns The number of ports (IPv4+IPv6) on which the server should listen.
  737. */
  738. static bool
  739. no_listenports(void)
  740. {
  741. size_t cnt = array_bytes(&Conf_ListenPorts);
  742. #ifdef SSL_SUPPORT
  743. cnt += array_bytes(&Conf_SSLOptions.ListenPorts);
  744. #endif
  745. return cnt == 0;
  746. }
  747. /**
  748. * Read contents of a text file into an array.
  749. *
  750. * This function is used to read the MOTD and help text file, for example.
  751. *
  752. * @param filename Name of the file to read.
  753. * @return true, when the file has been read in.
  754. */
  755. static bool
  756. Read_TextFile(const char *Filename, const char *Name, array *Destination)
  757. {
  758. char line[127];
  759. FILE *fp;
  760. int line_no = 1;
  761. if (*Filename == '\0')
  762. return false;
  763. fp = fopen(Filename, "r");
  764. if (!fp) {
  765. Config_Error(LOG_ERR, "Can't read %s file \"%s\": %s",
  766. Name, Filename, strerror(errno));
  767. return false;
  768. }
  769. array_free(Destination);
  770. while (fgets(line, (int)sizeof line, fp)) {
  771. ngt_TrimLastChr(line, '\n');
  772. /* add text including \0 */
  773. if (!array_catb(Destination, line, strlen(line) + 1)) {
  774. Log(LOG_ERR, "Cannot read/add \"%s\", line %d: %s",
  775. Filename, line_no, strerror(errno));
  776. break;
  777. }
  778. line_no++;
  779. }
  780. fclose(fp);
  781. return true;
  782. }
  783. /**
  784. * Read ngIRCd configuration file.
  785. *
  786. * Please note that this function uses exit(1) on fatal errors and therefore
  787. * can result in ngIRCd terminating!
  788. *
  789. * @param ngircd_starting Flag indicating if ngIRCd is starting or not.
  790. * @returns true when the configuration file has been read
  791. * successfully; false otherwise.
  792. */
  793. static bool
  794. Read_Config(bool TestOnly, bool IsStarting)
  795. {
  796. const UINT16 defaultport = 6667;
  797. char *ptr, file[FNAME_LEN];
  798. struct dirent *entry;
  799. int i, n;
  800. FILE *fd;
  801. DIR *dh;
  802. /* Open configuration file */
  803. fd = fopen( NGIRCd_ConfFile, "r" );
  804. if( ! fd ) {
  805. /* No configuration file found! */
  806. Config_Error( LOG_ALERT, "Can't read configuration \"%s\": %s",
  807. NGIRCd_ConfFile, strerror( errno ));
  808. if (!IsStarting)
  809. return false;
  810. Config_Error( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
  811. exit( 1 );
  812. }
  813. opers_free();
  814. Set_Defaults(IsStarting);
  815. if (TestOnly)
  816. Config_Error(LOG_INFO,
  817. "Reading configuration from \"%s\" ...",
  818. NGIRCd_ConfFile );
  819. /* Clean up server configuration structure: mark all already
  820. * configured servers as "once" so that they are deleted
  821. * after the next disconnect and delete all unused servers.
  822. * And delete all servers which are "duplicates" of servers
  823. * that are already marked as "once" (such servers have been
  824. * created by the last rehash but are now useless). */
  825. for( i = 0; i < MAX_SERVERS; i++ ) {
  826. if( Conf_Server[i].conn_id == NONE ) Init_Server_Struct( &Conf_Server[i] );
  827. else {
  828. /* This structure is in use ... */
  829. if( Conf_Server[i].flags & CONF_SFLAG_ONCE ) {
  830. /* Check for duplicates */
  831. for( n = 0; n < MAX_SERVERS; n++ ) {
  832. if( n == i ) continue;
  833. if( Conf_Server[i].conn_id == Conf_Server[n].conn_id ) {
  834. Init_Server_Struct( &Conf_Server[n] );
  835. #ifdef DEBUG
  836. Log(LOG_DEBUG,"Deleted unused duplicate server %d (kept %d).",
  837. n, i );
  838. #endif
  839. }
  840. }
  841. } else {
  842. /* Mark server as "once" */
  843. Conf_Server[i].flags |= CONF_SFLAG_ONCE;
  844. Log( LOG_DEBUG, "Marked server %d as \"once\"", i );
  845. }
  846. }
  847. }
  848. /* Initialize variables */
  849. Init_Server_Struct( &New_Server );
  850. New_Server_Idx = NONE;
  851. #ifdef SSL_SUPPORT
  852. ConfSSL_Init();
  853. #endif
  854. Read_Config_File(NGIRCd_ConfFile, fd);
  855. fclose(fd);
  856. if (Conf_IncludeDir[0]) {
  857. dh = opendir(Conf_IncludeDir);
  858. if (!dh)
  859. Config_Error(LOG_ALERT,
  860. "Can't open include directory \"%s\": %s",
  861. Conf_IncludeDir, strerror(errno));
  862. } else {
  863. strlcpy(Conf_IncludeDir, SYSCONFDIR, sizeof(Conf_IncludeDir));
  864. strlcat(Conf_IncludeDir, CONFIG_DIR, sizeof(Conf_IncludeDir));
  865. dh = opendir(Conf_IncludeDir);
  866. }
  867. /* Include further configuration files, if IncludeDir is available */
  868. if (dh) {
  869. while ((entry = readdir(dh)) != NULL) {
  870. ptr = strrchr(entry->d_name, '.');
  871. if (!ptr || strcasecmp(ptr, ".conf") != 0)
  872. continue;
  873. snprintf(file, sizeof(file), "%s/%s",
  874. Conf_IncludeDir, entry->d_name);
  875. if (TestOnly)
  876. Config_Error(LOG_INFO,
  877. "Reading configuration from \"%s\" ...",
  878. file);
  879. fd = fopen(file, "r");
  880. if (fd) {
  881. Read_Config_File(file, fd);
  882. fclose(fd);
  883. } else
  884. Config_Error(LOG_ALERT,
  885. "Can't read configuration \"%s\": %s",
  886. file, strerror(errno));
  887. }
  888. closedir(dh);
  889. }
  890. /* Check if there is still a server to add */
  891. if( New_Server.name[0] ) {
  892. /* Copy data to "real" server structure */
  893. assert( New_Server_Idx > NONE );
  894. Conf_Server[New_Server_Idx] = New_Server;
  895. }
  896. /* not a single listening port? Add default. */
  897. if (no_listenports() &&
  898. !array_copyb(&Conf_ListenPorts, (char*) &defaultport, sizeof defaultport))
  899. {
  900. Config_Error(LOG_ALERT, "Could not add default listening Port %u: %s",
  901. (unsigned int) defaultport, strerror(errno));
  902. exit(1);
  903. }
  904. if (!Conf_ListenAddress)
  905. Conf_ListenAddress = strdup_warn(DEFAULT_LISTEN_ADDRSTR);
  906. if (!Conf_ListenAddress) {
  907. Config_Error(LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME);
  908. exit(1);
  909. }
  910. /* No MOTD phrase configured? (re)try motd file. */
  911. if (array_bytes(&Conf_Motd) == 0) {
  912. if (Read_TextFile(Conf_MotdFile, "MOTD", &Conf_Motd))
  913. Using_MotdFile = true;
  914. }
  915. /* Try to read ngIRCd help text file. */
  916. (void)Read_TextFile(Conf_HelpFile, "help text", &Conf_Helptext);
  917. if (!array_bytes(&Conf_Helptext))
  918. Config_Error(LOG_WARNING,
  919. "No help text available, HELP command will be of limited use.");
  920. #ifdef SSL_SUPPORT
  921. /* Make sure that all SSL-related files are readable */
  922. CheckFileReadable("CertFile", Conf_SSLOptions.CertFile);
  923. CheckFileReadable("DHFile", Conf_SSLOptions.DHFile);
  924. CheckFileReadable("KeyFile", Conf_SSLOptions.KeyFile);
  925. /* Set the default ciphers if none were configured */
  926. if (!Conf_SSLOptions.CipherList)
  927. Conf_SSLOptions.CipherList = strdup_warn(DEFAULT_CIPHERS);
  928. #endif
  929. return true;
  930. }
  931. /**
  932. * Read in and handle a configuration file.
  933. *
  934. * @param File Name of the configuration file.
  935. * @param fd File descriptor already opened for reading.
  936. */
  937. static void
  938. Read_Config_File(const char *File, FILE *fd)
  939. {
  940. char section[LINE_LEN], str[LINE_LEN], *var, *arg, *ptr;
  941. int i, line = 0;
  942. size_t count;
  943. /* Read configuration file */
  944. section[0] = '\0';
  945. while (true) {
  946. if (!fgets(str, sizeof(str), fd))
  947. break;
  948. ngt_TrimStr(str);
  949. line++;
  950. /* Skip comments and empty lines */
  951. if (str[0] == ';' || str[0] == '#' || str[0] == '\0')
  952. continue;
  953. if (strlen(str) >= sizeof(str) - 1) {
  954. Config_Error(LOG_WARNING, "%s, line %d too long!",
  955. File, line);
  956. continue;
  957. }
  958. /* Is this the beginning of a new section? */
  959. if ((str[0] == '[') && (str[strlen(str) - 1] == ']')) {
  960. strlcpy(section, str, sizeof(section));
  961. if (strcasecmp(section, "[GLOBAL]") == 0
  962. || strcasecmp(section, "[LIMITS]") == 0
  963. || strcasecmp(section, "[OPTIONS]") == 0
  964. #ifdef SSL_SUPPORT
  965. || strcasecmp(section, "[SSL]") == 0
  966. #endif
  967. )
  968. continue;
  969. if (strcasecmp(section, "[SERVER]") == 0) {
  970. /* Check if there is already a server to add */
  971. if (New_Server.name[0]) {
  972. /* Copy data to "real" server structure */
  973. assert(New_Server_Idx > NONE);
  974. Conf_Server[New_Server_Idx] =
  975. New_Server;
  976. }
  977. /* Re-init structure for new server */
  978. Init_Server_Struct(&New_Server);
  979. /* Search unused item in server configuration structure */
  980. for (i = 0; i < MAX_SERVERS; i++) {
  981. /* Is this item used? */
  982. if (!Conf_Server[i].name[0])
  983. break;
  984. }
  985. if (i >= MAX_SERVERS) {
  986. /* Oops, no free item found! */
  987. Config_Error(LOG_ERR,
  988. "Too many servers configured.");
  989. New_Server_Idx = NONE;
  990. } else
  991. New_Server_Idx = i;
  992. continue;
  993. }
  994. if (strcasecmp(section, "[CHANNEL]") == 0) {
  995. count = array_length(&Conf_Channels,
  996. sizeof(struct
  997. Conf_Channel));
  998. if (!array_alloc
  999. (&Conf_Channels,
  1000. sizeof(struct Conf_Channel), count)) {
  1001. Config_Error(LOG_ERR,
  1002. "Could not allocate memory for new operator (line %d)",
  1003. line);
  1004. }
  1005. continue;
  1006. }
  1007. if (strcasecmp(section, "[OPERATOR]") == 0) {
  1008. count = array_length(&Conf_Opers,
  1009. sizeof(struct Conf_Oper));
  1010. if (!array_alloc(&Conf_Opers,
  1011. sizeof(struct Conf_Oper),
  1012. count)) {
  1013. Config_Error(LOG_ERR,
  1014. "Could not allocate memory for new channel (line &d)",
  1015. line);
  1016. }
  1017. continue;
  1018. }
  1019. Config_Error(LOG_ERR,
  1020. "%s, line %d: Unknown section \"%s\"!",
  1021. File, line, section);
  1022. section[0] = 0x1;
  1023. }
  1024. if (section[0] == 0x1)
  1025. continue;
  1026. /* Split line into variable name and parameters */
  1027. ptr = strchr(str, '=');
  1028. if (!ptr) {
  1029. Config_Error(LOG_ERR, "%s, line %d: Syntax error!",
  1030. File, line);
  1031. continue;
  1032. }
  1033. *ptr = '\0';
  1034. var = str;
  1035. ngt_TrimStr(var);
  1036. arg = ptr + 1;
  1037. ngt_TrimStr(arg);
  1038. if (strcasecmp(section, "[GLOBAL]") == 0)
  1039. Handle_GLOBAL(File, line, var, arg);
  1040. else if (strcasecmp(section, "[LIMITS]") == 0)
  1041. Handle_LIMITS(File, line, var, arg);
  1042. else if (strcasecmp(section, "[OPTIONS]") == 0)
  1043. Handle_OPTIONS(File, line, var, arg);
  1044. #ifdef SSL_SUPPORT
  1045. else if (strcasecmp(section, "[SSL]") == 0)
  1046. Handle_SSL(File, line, var, arg);
  1047. #endif
  1048. else if (strcasecmp(section, "[OPERATOR]") == 0)
  1049. Handle_OPERATOR(File, line, var, arg);
  1050. else if (strcasecmp(section, "[SERVER]") == 0)
  1051. Handle_SERVER(File, line, var, arg);
  1052. else if (strcasecmp(section, "[CHANNEL]") == 0)
  1053. Handle_CHANNEL(File, line, var, arg);
  1054. else
  1055. Config_Error(LOG_ERR,
  1056. "%s, line %d: Variable \"%s\" outside section!",
  1057. File, line, var);
  1058. }
  1059. }
  1060. /**
  1061. * Check whether a string argument is "true" or "false".
  1062. *
  1063. * @param Arg Input string.
  1064. * @returns true if the input string has been parsed as "yes", "true"
  1065. * (case insensitive) or a non-zero integer value.
  1066. */
  1067. static bool
  1068. Check_ArgIsTrue(const char *Arg)
  1069. {
  1070. if (strcasecmp(Arg, "yes") == 0)
  1071. return true;
  1072. if (strcasecmp(Arg, "true") == 0)
  1073. return true;
  1074. if (atoi(Arg) != 0)
  1075. return true;
  1076. return false;
  1077. }
  1078. /**
  1079. * Handle setting of "MaxNickLength".
  1080. *
  1081. * @param Line Line number in configuration file.
  1082. * @raram Arg Input string.
  1083. * @returns New configured maximum nickname length.
  1084. */
  1085. static unsigned int
  1086. Handle_MaxNickLength(const char *File, int Line, const char *Arg)
  1087. {
  1088. unsigned new;
  1089. new = (unsigned) atoi(Arg) + 1;
  1090. if (new > CLIENT_NICK_LEN) {
  1091. Config_Error(LOG_WARNING,
  1092. "%s, line %d: Value of \"MaxNickLength\" exceeds %u!",
  1093. File, Line, CLIENT_NICK_LEN - 1);
  1094. return CLIENT_NICK_LEN;
  1095. }
  1096. if (new < 2) {
  1097. Config_Error(LOG_WARNING,
  1098. "%s, line %d: Value of \"MaxNickLength\" must be at least 1!",
  1099. File, Line);
  1100. return 2;
  1101. }
  1102. return new;
  1103. }
  1104. /**
  1105. * Output a warning messages if IDENT is configured but not compiled in.
  1106. */
  1107. static void
  1108. WarnIdent(const char UNUSED *File, int UNUSED Line)
  1109. {
  1110. #ifndef IDENTAUTH
  1111. if (Conf_Ident) {
  1112. /* user has enabled ident lookups explicitly, but ... */
  1113. Config_Error(LOG_WARNING,
  1114. "%s: line %d: \"Ident = yes\", but ngircd was built without IDENT support!",
  1115. File, Line);
  1116. }
  1117. #endif
  1118. }
  1119. /**
  1120. * Output a warning messages if IPv6 is configured but not compiled in.
  1121. */
  1122. static void
  1123. WarnIPv6(const char UNUSED *File, int UNUSED Line)
  1124. {
  1125. #ifndef WANT_IPV6
  1126. if (Conf_ConnectIPv6) {
  1127. /* user has enabled IPv6 explicitly, but ... */
  1128. Config_Error(LOG_WARNING,
  1129. "%s: line %d: \"ConnectIPv6 = yes\", but ngircd was built without IPv6 support!",
  1130. File, Line);
  1131. }
  1132. #endif
  1133. }
  1134. /**
  1135. * Output a warning messages if PAM is configured but not compiled in.
  1136. */
  1137. static void
  1138. WarnPAM(const char UNUSED *File, int UNUSED Line)
  1139. {
  1140. #ifndef PAM
  1141. if (Conf_PAM) {
  1142. Config_Error(LOG_WARNING,
  1143. "%s: line %d: \"PAM = yes\", but ngircd was built without PAM support!",
  1144. File, Line);
  1145. }
  1146. #endif
  1147. }
  1148. /**
  1149. * Handle legacy "NoXXX" options in [GLOBAL] section.
  1150. *
  1151. * TODO: This function and support for "NoXXX" could be removed starting
  1152. * with ngIRCd release 19 (one release after marking it "deprecated").
  1153. *
  1154. * @param Var Variable name.
  1155. * @param Arg Argument string.
  1156. * @returns true if a NoXXX option has been processed; false otherwise.
  1157. */
  1158. static bool
  1159. CheckLegacyNoOption(const char *Var, const char *Arg)
  1160. {
  1161. if(strcasecmp(Var, "NoDNS") == 0) {
  1162. Conf_DNS = !Check_ArgIsTrue( Arg );
  1163. return true;
  1164. }
  1165. if (strcasecmp(Var, "NoIdent") == 0) {
  1166. Conf_Ident = !Check_ArgIsTrue(Arg);
  1167. return true;
  1168. }
  1169. if(strcasecmp(Var, "NoPAM") == 0) {
  1170. Conf_PAM = !Check_ArgIsTrue(Arg);
  1171. return true;
  1172. }
  1173. return false;
  1174. }
  1175. /**
  1176. * Handle deprecated legacy options in [GLOBAL] section.
  1177. *
  1178. * TODO: This function and support for these options in the [Global] section
  1179. * could be removed starting with ngIRCd release 19 (one release after
  1180. * marking it "deprecated").
  1181. *
  1182. * @param Var Variable name.
  1183. * @param Arg Argument string.
  1184. * @returns true if a legacy option has been processed; false otherwise.
  1185. */
  1186. static const char*
  1187. CheckLegacyGlobalOption(const char *File, int Line, char *Var, char *Arg)
  1188. {
  1189. if (strcasecmp(Var, "AllowRemoteOper") == 0
  1190. || strcasecmp(Var, "ChrootDir") == 0
  1191. || strcasecmp(Var, "ConnectIPv4") == 0
  1192. || strcasecmp(Var, "ConnectIPv6") == 0
  1193. || strcasecmp(Var, "OperCanUseMode") == 0
  1194. || strcasecmp(Var, "OperChanPAutoOp") == 0
  1195. || strcasecmp(Var, "OperServerMode") == 0
  1196. || strcasecmp(Var, "PredefChannelsOnly") == 0
  1197. || strcasecmp(Var, "SyslogFacility") == 0
  1198. || strcasecmp(Var, "WebircPassword") == 0) {
  1199. Handle_OPTIONS(File, Line, Var, Arg);
  1200. return "[Options]";
  1201. }
  1202. if (strcasecmp(Var, "ConnectRetry") == 0
  1203. || strcasecmp(Var, "IdleTimeout") == 0
  1204. || strcasecmp(Var, "MaxConnections") == 0
  1205. || strcasecmp(Var, "MaxConnectionsIP") == 0
  1206. || strcasecmp(Var, "MaxJoins") == 0
  1207. || strcasecmp(Var, "MaxNickLength") == 0
  1208. || strcasecmp(Var, "PingTimeout") == 0
  1209. || strcasecmp(Var, "PongTimeout") == 0) {
  1210. Handle_LIMITS(File, Line, Var, Arg);
  1211. return "[Limits]";
  1212. }
  1213. #ifdef SSL_SUPPORT
  1214. if (strcasecmp(Var, "SSLCertFile") == 0
  1215. || strcasecmp(Var, "SSLDHFile") == 0
  1216. || strcasecmp(Var, "SSLKeyFile") == 0
  1217. || strcasecmp(Var, "SSLKeyFilePassword") == 0
  1218. || strcasecmp(Var, "SSLPorts") == 0) {
  1219. Handle_SSL(File, Line, Var + 3, Arg);
  1220. return "[SSL]";
  1221. }
  1222. #endif
  1223. return NULL;
  1224. }
  1225. /**
  1226. * Strip "no" prefix of a string.
  1227. *
  1228. * TODO: This function and support for "NoXXX" should be removed starting
  1229. * with ngIRCd release 19! (One release after marking it "deprecated").
  1230. *
  1231. * @param str Pointer to input string starting with "no".
  1232. * @returns New pointer to string without "no" prefix.
  1233. */
  1234. static const char *
  1235. NoNo(const char *str)
  1236. {
  1237. assert(strncasecmp("no", str, 2) == 0 && str[2]);
  1238. return str + 2;
  1239. }
  1240. /**
  1241. * Invert "boolean" string.
  1242. *
  1243. * TODO: This function and support for "NoXXX" should be removed starting
  1244. * with ngIRCd release 19! (One release after marking it "deprecated").
  1245. *
  1246. * @param arg "Boolean" input string.
  1247. * @returns Pointer to inverted "boolean string".
  1248. */
  1249. static const char *
  1250. InvertArg(const char *arg)
  1251. {
  1252. return yesno_to_str(!Check_ArgIsTrue(arg));
  1253. }
  1254. /**
  1255. * Handle variable in [Global] configuration section.
  1256. *
  1257. * @param Line Line numer in configuration file.
  1258. * @param Var Variable name.
  1259. * @param Arg Variable argument.
  1260. */
  1261. static void
  1262. Handle_GLOBAL(const char *File, int Line, char *Var, char *Arg )
  1263. {
  1264. struct passwd *pwd;
  1265. struct group *grp;
  1266. size_t len;
  1267. const char *section;
  1268. char *ptr;
  1269. assert(File != NULL);
  1270. assert(Line > 0);
  1271. assert(Var != NULL);
  1272. assert(Arg != NULL);
  1273. if (strcasecmp(Var, "Name") == 0) {
  1274. len = strlcpy(Conf_ServerName, Arg, sizeof(Conf_ServerName));
  1275. if (len >= sizeof(Conf_ServerName))
  1276. Config_Error_TooLong(File, Line, Var);
  1277. return;
  1278. }
  1279. if (strcasecmp(Var, "AdminInfo1") == 0) {
  1280. len = strlcpy(Conf_ServerAdmin1, Arg, sizeof(Conf_ServerAdmin1));
  1281. if (len >= sizeof(Conf_ServerAdmin1))
  1282. Config_Error_TooLong(File, Line, Var);
  1283. return;
  1284. }
  1285. if (strcasecmp(Var, "AdminInfo2") == 0) {
  1286. len = strlcpy(Conf_ServerAdmin2, Arg, sizeof(Conf_ServerAdmin2));
  1287. if (len >= sizeof(Conf_ServerAdmin2))
  1288. Config_Error_TooLong(File, Line, Var);
  1289. return;
  1290. }
  1291. if (strcasecmp(Var, "AdminEMail") == 0) {
  1292. len = strlcpy(Conf_ServerAdminMail, Arg,
  1293. sizeof(Conf_ServerAdminMail));
  1294. if (len >= sizeof(Conf_ServerAdminMail))
  1295. Config_Error_TooLong(File, Line, Var);
  1296. return;
  1297. }
  1298. if (strcasecmp(Var, "Info") == 0) {
  1299. len = strlcpy(Conf_ServerInfo, Arg, sizeof(Conf_ServerInfo));
  1300. if (len >= sizeof(Conf_ServerInfo))
  1301. Config_Error_TooLong(File, Line, Var);
  1302. return;
  1303. }
  1304. if (strcasecmp(Var, "HelpFile") == 0) {
  1305. len = strlcpy(Conf_HelpFile, Arg, sizeof(Conf_HelpFile));
  1306. if (len >= sizeof(Conf_HelpFile))
  1307. Config_Error_TooLong(File, Line, Var);
  1308. return;
  1309. }
  1310. if (strcasecmp(Var, "Listen") == 0) {
  1311. if (Conf_ListenAddress) {
  1312. Config_Error(LOG_ERR,
  1313. "Multiple Listen= options, ignoring: %s",
  1314. Arg);
  1315. return;
  1316. }
  1317. Conf_ListenAddress = strdup_warn(Arg);
  1318. /* If allocation fails, we're in trouble: we cannot ignore the
  1319. * error -- otherwise ngircd would listen on all interfaces. */
  1320. if (!Conf_ListenAddress) {
  1321. Config_Error(LOG_ALERT,
  1322. "%s exiting due to fatal errors!",
  1323. PACKAGE_NAME);
  1324. exit(1);
  1325. }
  1326. return;
  1327. }
  1328. if (strcasecmp(Var, "MotdFile") == 0) {
  1329. len = strlcpy(Conf_MotdFile, Arg, sizeof(Conf_MotdFile));
  1330. if (len >= sizeof(Conf_MotdFile))
  1331. Config_Error_TooLong(File, Line, Var);
  1332. return;
  1333. }
  1334. if (strcasecmp(Var, "MotdPhrase") == 0) {
  1335. len = strlen(Arg);
  1336. if (len == 0)
  1337. return;
  1338. if (len >= 127) {
  1339. Config_Error_TooLong(File, Line, Var);
  1340. return;
  1341. }
  1342. if (!array_copyb(&Conf_Motd, Arg, len + 1))
  1343. Config_Error(LOG_WARNING,
  1344. "%s, line %d: Could not append MotdPhrase: %s",
  1345. File, Line, strerror(errno));
  1346. Using_MotdFile = false;
  1347. return;
  1348. }
  1349. if (strcasecmp(Var, "Network") == 0) {
  1350. len = strlcpy(Conf_Network, Arg, sizeof(Conf_Network));
  1351. if (len >= sizeof(Conf_Network))
  1352. Config_Error_TooLong(File, Line, Var);
  1353. ptr = strchr(Conf_Network, ' ');
  1354. if (ptr) {
  1355. Config_Error(LOG_WARNING,
  1356. "%s, line %d: \"Network\" can't contain spaces!",
  1357. File, Line);
  1358. *ptr = '\0';
  1359. }
  1360. return;
  1361. }
  1362. if(strcasecmp(Var, "Password") == 0) {
  1363. len = strlcpy(Conf_ServerPwd, Arg, sizeof(Conf_ServerPwd));
  1364. if (len >= sizeof(Conf_ServerPwd))
  1365. Config_Error_TooLong(File, Line, Var);
  1366. return;
  1367. }
  1368. if (strcasecmp(Var, "PidFile") == 0) {
  1369. len = strlcpy(Conf_PidFile, Arg, sizeof(Conf_PidFile));
  1370. if (len >= sizeof(Conf_PidFile))
  1371. Config_Error_TooLong(File, Line, Var);
  1372. return;
  1373. }
  1374. if (strcasecmp(Var, "Ports") == 0) {
  1375. ports_parse(&Conf_ListenPorts, File, Line, Arg);
  1376. return;
  1377. }
  1378. if (strcasecmp(Var, "ServerGID") == 0) {
  1379. grp = getgrnam(Arg);
  1380. if (grp)
  1381. Conf_GID = grp->gr_gid;
  1382. else {
  1383. Conf_GID = (unsigned int)atoi(Arg);
  1384. if (!Conf_GID && strcmp(Arg, "0"))
  1385. Config_Error(LOG_WARNING,
  1386. "%s, line %d: Value of \"%s\" is not a valid group name or ID!",
  1387. File, Line, Var);
  1388. }
  1389. return;
  1390. }
  1391. if (strcasecmp(Var, "ServerUID") == 0) {
  1392. pwd = getpwnam(Arg);
  1393. if (pwd)
  1394. Conf_UID = pwd->pw_uid;
  1395. else {
  1396. Conf_UID = (unsigned int)atoi(Arg);
  1397. if (!Conf_UID && strcmp(Arg, "0"))
  1398. Config_Error(LOG_WARNING,
  1399. "%s, line %d: Value of \"%s\" is not a valid user name or ID!",
  1400. File, Line, Var);
  1401. }
  1402. return;
  1403. }
  1404. if (CheckLegacyNoOption(Var, Arg)) {
  1405. /* TODO: This function and support for "NoXXX" could be
  1406. * be removed starting with ngIRCd release 19 (one release
  1407. * after marking it "deprecated"). */
  1408. Config_Error(LOG_WARNING,
  1409. "%s, line %d (section \"Global\"): \"No\"-Prefix is deprecated, use \"%s = %s\" in [Options] section!",
  1410. File, Line, NoNo(Var), InvertArg(Arg));
  1411. if (strcasecmp(Var, "NoIdent") == 0)
  1412. WarnIdent(File, Line);
  1413. else if (strcasecmp(Var, "NoPam") == 0)
  1414. WarnPAM(File, Line);
  1415. return;
  1416. }
  1417. if ((section = CheckLegacyGlobalOption(File, Line, Var, Arg))) {
  1418. /** TODO: This function and support for these options in the
  1419. * [Global] section could be removed starting with ngIRCd
  1420. * release 19 (one release after marking it "deprecated"). */
  1421. if (strncasecmp(Var, "SSL", 3) == 0) {
  1422. Config_Error(LOG_WARNING,
  1423. "%s, line %d (section \"Global\"): \"%s\" is deprecated here, move it to %s and rename to \"%s\"!",
  1424. File, Line, Var, section,
  1425. Var + 3);
  1426. } else {
  1427. Config_Error(LOG_WARNING,
  1428. "%s, line %d (section \"Global\"): \"%s\" is deprecated here, move it to %s!",
  1429. File, Line, Var, section);
  1430. }
  1431. return;
  1432. }
  1433. Config_Error_Section(File, Line, Var, "Global");
  1434. }
  1435. /**
  1436. * Handle variable in [Limits] configuration section.
  1437. *
  1438. * @param Line Line numer in configuration file.
  1439. * @param Var Variable name.
  1440. * @param Arg Variable argument.
  1441. */
  1442. static void
  1443. Handle_LIMITS(const char *File, int Line, char *Var, char *Arg)
  1444. {
  1445. assert(File != NULL);
  1446. assert(Line > 0);
  1447. assert(Var != NULL);
  1448. assert(Arg != NULL);
  1449. if (strcasecmp(Var, "ConnectRetry") == 0) {
  1450. Conf_ConnectRetry = atoi(Arg);
  1451. if (Conf_ConnectRetry < 5) {
  1452. Config_Error(LOG_WARNING,
  1453. "%s, line %d: Value of \"ConnectRetry\" too low!",
  1454. File, Line);
  1455. Conf_ConnectRetry = 5;
  1456. }
  1457. return;
  1458. }
  1459. if (strcasecmp(Var, "IdleTimeout") == 0) {
  1460. Conf_IdleTimeout = atoi(Arg);
  1461. if (!Conf_IdleTimeout && strcmp(Arg, "0"))
  1462. Config_Error_NaN(File, Line, Var);
  1463. return;
  1464. }
  1465. if (strcasecmp(Var, "MaxConnections") == 0) {
  1466. Conf_MaxConnections = atoi(Arg);
  1467. if (!Conf_MaxConnections && strcmp(Arg, "0"))
  1468. Config_Error_NaN(File, Line, Var);
  1469. return;
  1470. }
  1471. if (strcasecmp(Var, "MaxConnectionsIP") == 0) {
  1472. Conf_MaxConnectionsIP = atoi(Arg);
  1473. if (!Conf_MaxConnectionsIP && strcmp(Arg, "0"))
  1474. Config_Error_NaN(File, Line, Var);
  1475. return;
  1476. }
  1477. if (strcasecmp(Var, "MaxJoins") == 0) {
  1478. Conf_MaxJoins = atoi(Arg);
  1479. if (!Conf_MaxJoins && strcmp(Arg, "0"))
  1480. Config_Error_NaN(File, Line, Var);
  1481. return;
  1482. }
  1483. if (strcasecmp(Var, "MaxNickLength") == 0) {
  1484. Conf_MaxNickLength = Handle_MaxNickLength(File, Line, Arg);
  1485. return;
  1486. }
  1487. if (strcasecmp(Var, "MaxListSize") == 0) {
  1488. Conf_MaxListSize = atoi(Arg);
  1489. if (!Conf_MaxListSize && strcmp(Arg, "0"))
  1490. Config_Error_NaN(File, Line, Var);
  1491. return;
  1492. }
  1493. if (strcasecmp(Var, "PingTimeout") == 0) {
  1494. Conf_PingTimeout = atoi(Arg);
  1495. if (Conf_PingTimeout < 5) {
  1496. Config_Error(LOG_WARNING,
  1497. "%s, line %d: Value of \"PingTimeout\" too low!",
  1498. File, Line);
  1499. Conf_PingTimeout = 5;
  1500. }
  1501. return;
  1502. }
  1503. if (strcasecmp(Var, "PongTimeout") == 0) {
  1504. Conf_PongTimeout = atoi(Arg);
  1505. if (Conf_PongTimeout < 5) {
  1506. Config_Error(LOG_WARNING,
  1507. "%s, line %d: Value of \"PongTimeout\" too low!",
  1508. File, Line);
  1509. Conf_PongTimeout = 5;
  1510. }
  1511. return;
  1512. }
  1513. Config_Error_Section(File, Line, Var, "Limits");
  1514. }
  1515. /**
  1516. * Handle variable in [Options] configuration section.
  1517. *
  1518. * @param Line Line numer in configuration file.
  1519. * @param Var Variable name.
  1520. * @param Arg Variable argument.
  1521. */
  1522. static void
  1523. Handle_OPTIONS(const char *File, int Line, char *Var, char *Arg)
  1524. {
  1525. size_t len;
  1526. char *p;
  1527. assert(File != NULL);
  1528. assert(Line > 0);
  1529. assert(Var != NULL);
  1530. assert(Arg != NULL);
  1531. if (strcasecmp(Var, "AllowedChannelTypes") == 0) {
  1532. p = Arg;
  1533. Conf_AllowedChannelTypes[0] = '\0';
  1534. while (*p) {
  1535. if (strchr(Conf_AllowedChannelTypes, *p)) {
  1536. /* Prefix is already included; ignore it */
  1537. p++;
  1538. continue;
  1539. }
  1540. if (strchr(CHANTYPES, *p)) {
  1541. len = strlen(Conf_AllowedChannelTypes) + 1;
  1542. assert(len < sizeof(Conf_AllowedChannelTypes));
  1543. Conf_AllowedChannelTypes[len - 1] = *p;
  1544. Conf_AllowedChannelTypes[len] = '\0';
  1545. } else {
  1546. Config_Error(LOG_WARNING,
  1547. "%s, line %d: Unknown channel prefix \"%c\" in \"AllowedChannelTypes\"!",
  1548. File, Line, *p);
  1549. }
  1550. p++;
  1551. }
  1552. return;
  1553. }
  1554. if (strcasecmp(Var, "AllowRemoteOper") == 0) {
  1555. Conf_AllowRemoteOper = Check_ArgIsTrue(Arg);
  1556. return;
  1557. }
  1558. if (strcasecmp(Var, "ChrootDir") == 0) {
  1559. len = strlcpy(Conf_Chroot, Arg, sizeof(Conf_Chroot));
  1560. if (len >= sizeof(Conf_Chroot))
  1561. Config_Error_TooLong(File, Line, Var);
  1562. return;
  1563. }
  1564. if (strcasecmp(Var, "CloakHost") == 0) {
  1565. len = strlcpy(Conf_CloakHost, Arg, sizeof(Conf_CloakHost));
  1566. if (len >= sizeof(Conf_CloakHost))
  1567. Config_Error_TooLong(File, Line, Var);
  1568. return;
  1569. }
  1570. if (strcasecmp(Var, "CloakHostModeX") == 0) {
  1571. len = strlcpy(Conf_CloakHostModeX, Arg, sizeof(Conf_CloakHostModeX));
  1572. if (len >= sizeof(Conf_CloakHostModeX))
  1573. Config_Error_TooLong(File, Line, Var);
  1574. return;
  1575. }
  1576. if (strcasecmp(Var, "CloakHostSalt") == 0) {
  1577. len = strlcpy(Conf_CloakHostSalt, Arg, sizeof(Conf_CloakHostSalt));
  1578. if (len >= sizeof(Conf_CloakHostSalt))
  1579. Config_Error_TooLong(File, Line, Var);
  1580. return;
  1581. }
  1582. if (strcasecmp(Var, "CloakUserToNick") == 0) {
  1583. Conf_CloakUserToNick = Check_ArgIsTrue(Arg);
  1584. return;
  1585. }
  1586. if (strcasecmp(Var, "ConnectIPv6") == 0) {
  1587. Conf_ConnectIPv6 = Check_ArgIsTrue(Arg);
  1588. WarnIPv6(File, Line);
  1589. return;
  1590. }
  1591. if (strcasecmp(Var, "ConnectIPv4") == 0) {
  1592. Conf_ConnectIPv4 = Check_ArgIsTrue(Arg);
  1593. return;
  1594. }
  1595. if (strcasecmp(Var, "DefaultUserModes") == 0) {
  1596. p = Arg;
  1597. Conf_DefaultUserModes[0] = '\0';
  1598. while (*p) {
  1599. if (strchr(Conf_DefaultUserModes, *p)) {
  1600. /* Mode is already included; ignore it */
  1601. p++;
  1602. continue;
  1603. }
  1604. if (strchr(USERMODES, *p)) {
  1605. len = strlen(Conf_DefaultUserModes) + 1;
  1606. assert(len < sizeof(Conf_DefaultUserModes));
  1607. Conf_DefaultUserModes[len - 1] = *p;
  1608. Conf_DefaultUserModes[len] = '\0';
  1609. } else {
  1610. Config_Error(LOG_WARNING,
  1611. "%s, line %d: Unknown user mode \"%c\" in \"DefaultUserModes\"!",
  1612. File, Line, *p);
  1613. }
  1614. p++;
  1615. }
  1616. return;
  1617. }
  1618. if (strcasecmp(Var, "DNS") == 0) {
  1619. Conf_DNS = Check_ArgIsTrue(Arg);
  1620. return;
  1621. }
  1622. if (strcasecmp(Var, "Ident") == 0) {
  1623. Conf_Ident = Check_ArgIsTrue(Arg);
  1624. WarnIdent(File, Line);
  1625. return;
  1626. }
  1627. if (strcasecmp(Var, "IncludeDir") == 0) {
  1628. if (Conf_IncludeDir[0]) {
  1629. Config_Error(LOG_ERR,
  1630. "%s, line %d: Can't overwrite value of \"IncludeDir\" variable!",
  1631. File, Line);
  1632. return;
  1633. }
  1634. len = strlcpy(Conf_IncludeDir, Arg, sizeof(Conf_IncludeDir));
  1635. if (len >= sizeof(Conf_IncludeDir))
  1636. Config_Error_TooLong(File, Line, Var);
  1637. return;
  1638. }
  1639. if (strcasecmp(Var, "MorePrivacy") == 0) {
  1640. Conf_MorePrivacy = Check_ArgIsTrue(Arg);
  1641. return;
  1642. }
  1643. if (strcasecmp(Var, "NoticeAuth") == 0) {
  1644. Conf_NoticeAuth = Check_ArgIsTrue(Arg);
  1645. return;
  1646. }
  1647. if (strcasecmp(Var, "OperCanUseMode") == 0) {
  1648. Conf_OperCanMode = Check_ArgIsTrue(Arg);
  1649. return;
  1650. }
  1651. if (strcasecmp(Var, "OperChanPAutoOp") == 0) {
  1652. Conf_OperChanPAutoOp = Check_ArgIsTrue(Arg);
  1653. return;
  1654. }
  1655. if (strcasecmp(Var, "OperServerMode") == 0) {
  1656. Conf_OperServerMode = Check_ArgIsTrue(Arg);
  1657. return;
  1658. }
  1659. if (strcasecmp(Var, "PAM") == 0) {
  1660. Conf_PAM = Check_ArgIsTrue(Arg);
  1661. WarnPAM(File, Line);
  1662. return;
  1663. }
  1664. if (strcasecmp(Var, "PAMIsOptional") == 0 ) {
  1665. Conf_PAMIsOptional = Check_ArgIsTrue(Arg);
  1666. return;
  1667. }
  1668. if (strcasecmp(Var, "PredefChannelsOnly") == 0) {
  1669. /*
  1670. * TODO: This section and support for "PredefChannelsOnly"
  1671. * could be removed starting with ngIRCd release 22 (one
  1672. * release after marking it "deprecated") ...
  1673. */
  1674. Config_Error(LOG_WARNING,
  1675. "%s, line %d (section \"Options\"): \"%s\" is deprecated, please use \"AllowedChannelTypes\"!",
  1676. File, Line, Var);
  1677. if (Check_ArgIsTrue(Arg))
  1678. Conf_AllowedChannelTypes[0] = '\0';
  1679. else
  1680. strlcpy(Conf_AllowedChannelTypes, CHANTYPES,
  1681. sizeof(Conf_AllowedChannelTypes));
  1682. return;
  1683. }
  1684. #ifndef STRICT_RFC
  1685. if (strcasecmp(Var, "RequireAuthPing") == 0) {
  1686. Conf_AuthPing = Check_ArgIsTrue(Arg);
  1687. return;
  1688. }
  1689. #endif
  1690. if (strcasecmp(Var, "ScrubCTCP") == 0) {
  1691. Conf_ScrubCTCP = Check_ArgIsTrue(Arg);
  1692. return;
  1693. }
  1694. #ifdef SYSLOG
  1695. if (strcasecmp(Var, "SyslogFacility") == 0) {
  1696. Conf_SyslogFacility = ngt_SyslogFacilityID(Arg,
  1697. Conf_SyslogFacility);
  1698. return;
  1699. }
  1700. #endif
  1701. if (strcasecmp(Var, "WebircPassword") == 0) {
  1702. len = strlcpy(Conf_WebircPwd, Arg, sizeof(Conf_WebircPwd));
  1703. if (len >= sizeof(Conf_WebircPwd))
  1704. Config_Error_TooLong(File, Line, Var);
  1705. return;
  1706. }
  1707. Config_Error_Section(File, Line, Var, "Options");
  1708. }
  1709. #ifdef SSL_SUPPORT
  1710. /**
  1711. * Handle variable in [SSL] configuration section.
  1712. *
  1713. * @param Line Line numer in configuration file.
  1714. * @param Var Variable name.
  1715. * @param Arg Variable argument.
  1716. */
  1717. static void
  1718. Handle_SSL(const char *File, int Line, char *Var, char *Arg)
  1719. {
  1720. assert(File != NULL);
  1721. assert(Line > 0);
  1722. assert(Var != NULL);
  1723. assert(Arg != NULL);
  1724. if (strcasecmp(Var, "CertFile") == 0) {
  1725. assert(Conf_SSLOptions.CertFile == NULL);
  1726. Conf_SSLOptions.CertFile = strdup_warn(Arg);
  1727. return;
  1728. }
  1729. if (strcasecmp(Var, "DHFile") == 0) {
  1730. assert(Conf_SSLOptions.DHFile == NULL);
  1731. Conf_SSLOptions.DHFile = strdup_warn(Arg);
  1732. return;
  1733. }
  1734. if (strcasecmp(Var, "KeyFile") == 0) {
  1735. assert(Conf_SSLOptions.KeyFile == NULL);
  1736. Conf_SSLOptions.KeyFile = strdup_warn(Arg);
  1737. return;
  1738. }
  1739. if (strcasecmp(Var, "KeyFilePassword") == 0) {
  1740. assert(array_bytes(&Conf_SSLOptions.KeyFilePassword) == 0);
  1741. if (!array_copys(&Conf_SSLOptions.KeyFilePassword, Arg))
  1742. Config_Error(LOG_ERR,
  1743. "%s, line %d (section \"SSL\"): Could not copy %s: %s!",
  1744. File, Line, Var, strerror(errno));
  1745. return;
  1746. }
  1747. if (strcasecmp(Var, "Ports") == 0) {
  1748. ports_parse(&Conf_SSLOptions.ListenPorts, File, Line, Arg);
  1749. return;
  1750. }
  1751. if (strcasecmp(Var, "CipherList") == 0) {
  1752. assert(Conf_SSLOptions.CipherList == NULL);
  1753. Conf_SSLOptions.CipherList = strdup_warn(Arg);
  1754. return;
  1755. }
  1756. Config_Error_Section(File, Line, Var, "SSL");
  1757. }
  1758. #endif
  1759. /**
  1760. * Handle variable in [Operator] configuration section.
  1761. *
  1762. * @param Line Line numer in configuration file.
  1763. * @param Var Variable name.
  1764. * @param Arg Variable argument.
  1765. */
  1766. static void
  1767. Handle_OPERATOR(const char *File, int Line, char *Var, char *Arg )
  1768. {
  1769. size_t len;
  1770. struct Conf_Oper *op;
  1771. assert( File != NULL );
  1772. assert( Line > 0 );
  1773. assert( Var != NULL );
  1774. assert( Arg != NULL );
  1775. op = array_get(&Conf_Opers, sizeof(*op),
  1776. array_length(&Conf_Opers, sizeof(*op)) - 1);
  1777. if (!op)
  1778. return;
  1779. if (strcasecmp(Var, "Name") == 0) {
  1780. /* Name of IRC operator */
  1781. len = strlcpy(op->name, Arg, sizeof(op->name));
  1782. if (len >= sizeof(op->name))
  1783. Config_Error_TooLong(File, Line, Var);
  1784. return;
  1785. }
  1786. if (strcasecmp(Var, "Password") == 0) {
  1787. /* Password of IRC operator */
  1788. len = strlcpy(op->pwd, Arg, sizeof(op->pwd));
  1789. if (len >= sizeof(op->pwd))
  1790. Config_Error_TooLong(File, Line, Var);
  1791. return;
  1792. }
  1793. if (strcasecmp(Var, "Mask") == 0) {
  1794. if (op->mask)
  1795. return; /* Hostname already configured */
  1796. op->mask = strdup_warn( Arg );
  1797. return;
  1798. }
  1799. Config_Error_Section(File, Line, Var, "Operator");
  1800. }
  1801. /**
  1802. * Handle variable in [Server] configuration section.
  1803. *
  1804. * @param Line Line numer in configuration file.
  1805. * @param Var Variable name.
  1806. * @param Arg Variable argument.
  1807. */
  1808. static void
  1809. Handle_SERVER(const char *File, int Line, char *Var, char *Arg )
  1810. {
  1811. long port;
  1812. size_t len;
  1813. assert( File != NULL );
  1814. assert( Line > 0 );
  1815. assert( Var != NULL );
  1816. assert( Arg != NULL );
  1817. /* Ignore server block if no space is left in server configuration structure */
  1818. if( New_Server_Idx <= NONE ) return;
  1819. if( strcasecmp( Var, "Host" ) == 0 ) {
  1820. /* Hostname of the server */
  1821. len = strlcpy( New_Server.host, Arg, sizeof( New_Server.host ));
  1822. if (len >= sizeof( New_Server.host ))
  1823. Config_Error_TooLong(File, Line, Var);
  1824. return;
  1825. }
  1826. if( strcasecmp( Var, "Name" ) == 0 ) {
  1827. /* Name of the server ("Nick"/"ID") */
  1828. len = strlcpy( New_Server.name, Arg, sizeof( New_Server.name ));
  1829. if (len >= sizeof( New_Server.name ))
  1830. Config_Error_TooLong(File, Line, Var);
  1831. return;
  1832. }
  1833. if (strcasecmp(Var, "Bind") == 0) {
  1834. if (ng_ipaddr_init(&New_Server.bind_addr, Arg, 0))
  1835. return;
  1836. Config_Error(LOG_ERR, "%s, line %d (section \"Server\"): Can't parse IP address \"%s\"",
  1837. File, Line, Arg);
  1838. return;
  1839. }
  1840. if( strcasecmp( Var, "MyPassword" ) == 0 ) {
  1841. /* Password of this server which is sent to the peer */
  1842. if (*Arg == ':') {
  1843. Config_Error(LOG_ERR,
  1844. "%s, line %d (section \"Server\"): MyPassword must not start with ':'!",
  1845. File, Line);
  1846. }
  1847. len = strlcpy( New_Server.pwd_in, Arg, sizeof( New_Server.pwd_in ));
  1848. if (len >= sizeof( New_Server.pwd_in ))
  1849. Config_Error_TooLong(File, Line, Var);
  1850. return;
  1851. }
  1852. if( strcasecmp( Var, "PeerPassword" ) == 0 ) {
  1853. /* Passwort of the peer which must be received */
  1854. len = strlcpy( New_Server.pwd_out, Arg, sizeof( New_Server.pwd_out ));
  1855. if (len >= sizeof( New_Server.pwd_out ))
  1856. Config_Error_TooLong(File, Line, Var);
  1857. return;
  1858. }
  1859. if( strcasecmp( Var, "Port" ) == 0 ) {
  1860. /* Port to which this server should connect */
  1861. port = atol( Arg );
  1862. if (port >= 0 && port < 0xFFFF)
  1863. New_Server.port = (UINT16)port;
  1864. else
  1865. Config_Error(LOG_ERR,
  1866. "%s, line %d (section \"Server\"): Illegal port number %ld!",
  1867. File, Line, port );
  1868. return;
  1869. }
  1870. #ifdef SSL_SUPPORT
  1871. if( strcasecmp( Var, "SSLConnect" ) == 0 ) {
  1872. New_Server.SSLConnect = Check_ArgIsTrue(Arg);
  1873. return;
  1874. }
  1875. #endif
  1876. if( strcasecmp( Var, "Group" ) == 0 ) {
  1877. /* Server group */
  1878. New_Server.group = atoi( Arg );
  1879. if (!New_Server.group && strcmp(Arg, "0"))
  1880. Config_Error_NaN(File, Line, Var);
  1881. return;
  1882. }
  1883. if( strcasecmp( Var, "Passive" ) == 0 ) {
  1884. if (Check_ArgIsTrue(Arg))
  1885. New_Server.flags |= CONF_SFLAG_DISABLED;
  1886. return;
  1887. }
  1888. if (strcasecmp(Var, "ServiceMask") == 0) {
  1889. len = strlcpy(New_Server.svs_mask, ngt_LowerStr(Arg),
  1890. sizeof(New_Server.svs_mask));
  1891. if (len >= sizeof(New_Server.svs_mask))
  1892. Config_Error_TooLong(File, Line, Var);
  1893. return;
  1894. }
  1895. Config_Error_Section(File, Line, Var, "Server");
  1896. }
  1897. /**
  1898. * Copy channel name into channel structure.
  1899. *
  1900. * If the channel name is not valid because of a missing prefix ('#', '&'),
  1901. * a default prefix of '#' will be added.
  1902. *
  1903. * @param new_chan New already allocated channel structure.
  1904. * @param name Name of the new channel.
  1905. * @returns true on success, false otherwise.
  1906. */
  1907. static bool
  1908. Handle_Channelname(struct Conf_Channel *new_chan, const char *name)
  1909. {
  1910. size_t size = sizeof(new_chan->name);
  1911. char *dest = new_chan->name;
  1912. if (!Channel_IsValidName(name)) {
  1913. /*
  1914. * maybe user forgot to add a '#'.
  1915. * This is only here for user convenience.
  1916. */
  1917. *dest = '#';
  1918. --size;
  1919. ++dest;
  1920. }
  1921. return size > strlcpy(dest, name, size);
  1922. }
  1923. /**
  1924. * Handle variable in [Channel] configuration section.
  1925. *
  1926. * @param Line Line numer in configuration file.
  1927. * @param Var Variable name.
  1928. * @param Arg Variable argument.
  1929. */
  1930. static void
  1931. Handle_CHANNEL(const char *File, int Line, char *Var, char *Arg)
  1932. {
  1933. size_t len;
  1934. struct Conf_Channel *chan;
  1935. assert( File != NULL );
  1936. assert( Line > 0 );
  1937. assert( Var != NULL );
  1938. assert( Arg != NULL );
  1939. chan = array_get(&Conf_Channels, sizeof(*chan),
  1940. array_length(&Conf_Channels, sizeof(*chan)) - 1);
  1941. if (!chan)
  1942. return;
  1943. if (strcasecmp(Var, "Name") == 0) {
  1944. if (!Handle_Channelname(chan, Arg))
  1945. Config_Error_TooLong(File, Line, Var);
  1946. return;
  1947. }
  1948. if (strcasecmp(Var, "Modes") == 0) {
  1949. /* Initial modes */
  1950. len = strlcpy(chan->modes, Arg, sizeof(chan->modes));
  1951. if (len >= sizeof(chan->modes))
  1952. Config_Error_TooLong(File, Line, Var);
  1953. return;
  1954. }
  1955. if( strcasecmp( Var, "Topic" ) == 0 ) {
  1956. /* Initial topic */
  1957. len = strlcpy(chan->topic, Arg, sizeof(chan->topic));
  1958. if (len >= sizeof(chan->topic))
  1959. Config_Error_TooLong(File, Line, Var);
  1960. return;
  1961. }
  1962. if( strcasecmp( Var, "Key" ) == 0 ) {
  1963. /* Initial Channel Key (mode k) */
  1964. len = strlcpy(chan->key, Arg, sizeof(chan->key));
  1965. if (len >= sizeof(chan->key))
  1966. Config_Error_TooLong(File, Line, Var);
  1967. return;
  1968. }
  1969. if( strcasecmp( Var, "MaxUsers" ) == 0 ) {
  1970. /* maximum user limit, mode l */
  1971. chan->maxusers = (unsigned long) atol(Arg);
  1972. if (!chan->maxusers && strcmp(Arg, "0"))
  1973. Config_Error_NaN(File, Line, Var);
  1974. return;
  1975. }
  1976. if (strcasecmp(Var, "KeyFile") == 0) {
  1977. /* channel keys */
  1978. len = strlcpy(chan->keyfile, Arg, sizeof(chan->keyfile));
  1979. if (len >= sizeof(chan->keyfile))
  1980. Config_Error_TooLong(File, Line, Var);
  1981. return;
  1982. }
  1983. Config_Error_Section(File, Line, Var, "Channel");
  1984. }
  1985. /**
  1986. * Validate server configuration.
  1987. *
  1988. * Please note that this function uses exit(1) on fatal errors and therefore
  1989. * can result in ngIRCd terminating!
  1990. *
  1991. * @param Configtest true if the daemon has been called with "--configtest".
  1992. * @param Rehash true if re-reading configuration on runtime.
  1993. * @returns true if configuration is valid.
  1994. */
  1995. static bool
  1996. Validate_Config(bool Configtest, bool Rehash)
  1997. {
  1998. /* Validate configuration settings. */
  1999. #ifdef DEBUG
  2000. int i, servers, servers_once;
  2001. #endif
  2002. bool config_valid = true;
  2003. char *ptr;
  2004. /* Emit a warning when the config file is not a full path name */
  2005. if (NGIRCd_ConfFile[0] && NGIRCd_ConfFile[0] != '/') {
  2006. Config_Error(LOG_WARNING,
  2007. "Not specifying a full path name to \"%s\" can cause problems when rehashing the server!",
  2008. NGIRCd_ConfFile);
  2009. }
  2010. /* Validate configured server name, see RFC 2812 section 2.3.1 */
  2011. ptr = Conf_ServerName;
  2012. do {
  2013. if (*ptr >= 'a' && *ptr <= 'z') continue;
  2014. if (*ptr >= 'A' && *ptr <= 'Z') continue;
  2015. if (*ptr >= '0' && *ptr <= '9') continue;
  2016. if (ptr > Conf_ServerName) {
  2017. if (*ptr == '.' || *ptr == '-')
  2018. continue;
  2019. }
  2020. Conf_ServerName[0] = '\0';
  2021. break;
  2022. } while (*(++ptr));
  2023. if (!Conf_ServerName[0]) {
  2024. /* No server name configured! */
  2025. config_valid = false;
  2026. Config_Error(LOG_ALERT,
  2027. "No (valid) server name configured in \"%s\" (section 'Global': 'Name')!",
  2028. NGIRCd_ConfFile);
  2029. if (!Configtest && !Rehash) {
  2030. Config_Error(LOG_ALERT,
  2031. "%s exiting due to fatal errors!",
  2032. PACKAGE_NAME);
  2033. exit(1);
  2034. }
  2035. }
  2036. if (Conf_ServerName[0] && !strchr(Conf_ServerName, '.')) {
  2037. /* No dot in server name! */
  2038. config_valid = false;
  2039. Config_Error(LOG_ALERT,
  2040. "Invalid server name configured in \"%s\" (section 'Global': 'Name'): Dot missing!",
  2041. NGIRCd_ConfFile);
  2042. if (!Configtest) {
  2043. Config_Error(LOG_ALERT,
  2044. "%s exiting due to fatal errors!",
  2045. PACKAGE_NAME);
  2046. exit(1);
  2047. }
  2048. }
  2049. #ifdef STRICT_RFC
  2050. if (!Conf_ServerAdminMail[0]) {
  2051. /* No administrative contact configured! */
  2052. config_valid = false;
  2053. Config_Error(LOG_ALERT,
  2054. "No administrator email address configured in \"%s\" ('AdminEMail')!",
  2055. NGIRCd_ConfFile);
  2056. if (!Configtest) {
  2057. Config_Error(LOG_ALERT,
  2058. "%s exiting due to fatal errors!",
  2059. PACKAGE_NAME);
  2060. exit(1);
  2061. }
  2062. }
  2063. #endif
  2064. if (!Conf_ServerAdmin1[0] && !Conf_ServerAdmin2[0]
  2065. && !Conf_ServerAdminMail[0]) {
  2066. /* No administrative information configured! */
  2067. Config_Error(LOG_WARNING,
  2068. "No administrative information configured but required by RFC!");
  2069. }
  2070. #ifdef PAM
  2071. if (Conf_PAM && Conf_ServerPwd[0])
  2072. Config_Error(LOG_ERR,
  2073. "This server uses PAM, \"Password\" in [Global] section will be ignored!");
  2074. #endif
  2075. #ifdef DEBUG
  2076. servers = servers_once = 0;
  2077. for (i = 0; i < MAX_SERVERS; i++) {
  2078. if (Conf_Server[i].name[0]) {
  2079. servers++;
  2080. if (Conf_Server[i].flags & CONF_SFLAG_ONCE)
  2081. servers_once++;
  2082. }
  2083. }
  2084. Log(LOG_DEBUG,
  2085. "Configuration: Operators=%ld, Servers=%d[%d], Channels=%ld",
  2086. array_length(&Conf_Opers, sizeof(struct Conf_Oper)),
  2087. servers, servers_once,
  2088. array_length(&Conf_Channels, sizeof(struct Conf_Channel)));
  2089. #endif
  2090. return config_valid;
  2091. }
  2092. /**
  2093. * Output "line too long" warning.
  2094. *
  2095. * @param Line Line number in configuration file.
  2096. * @param Item Affected variable name.
  2097. */
  2098. static void
  2099. Config_Error_TooLong(const char *File, const int Line, const char *Item)
  2100. {
  2101. Config_Error(LOG_WARNING, "%s, line %d: Value of \"%s\" too long!",
  2102. File, Line, Item );
  2103. }
  2104. /**
  2105. * Output "unknown variable" warning.
  2106. *
  2107. * @param Line Line number in configuration file.
  2108. * @param Item Affected variable name.
  2109. * @param Section Section name.
  2110. */
  2111. static void
  2112. Config_Error_Section(const char *File, const int Line, const char *Item,
  2113. const char *Section)
  2114. {
  2115. Config_Error(LOG_ERR, "%s, line %d (section \"%s\"): Unknown variable \"%s\"!",
  2116. File, Line, Section, Item);
  2117. }
  2118. /**
  2119. * Output "not a number" warning.
  2120. *
  2121. * @param Line Line number in configuration file.
  2122. * @param Item Affected variable name.
  2123. */
  2124. static void
  2125. Config_Error_NaN(const char *File, const int Line, const char *Item )
  2126. {
  2127. Config_Error(LOG_WARNING, "%s, line %d: Value of \"%s\" is not a number!",
  2128. File, Line, Item );
  2129. }
  2130. /**
  2131. * Output configuration error to console and/or logfile.
  2132. *
  2133. * On runtime, the normal log functions of the daemon are used. But when
  2134. * testing the configuration ("--configtest"), all messages go directly
  2135. * to the console.
  2136. *
  2137. * @param Level Severity level of the message.
  2138. * @param Format Format string; see printf() function.
  2139. */
  2140. #ifdef PROTOTYPES
  2141. static void Config_Error( const int Level, const char *Format, ... )
  2142. #else
  2143. static void Config_Error( Level, Format, va_alist )
  2144. const int Level;
  2145. const char *Format;
  2146. va_dcl
  2147. #endif
  2148. {
  2149. char msg[MAX_LOG_MSG_LEN];
  2150. va_list ap;
  2151. assert( Format != NULL );
  2152. #ifdef PROTOTYPES
  2153. va_start( ap, Format );
  2154. #else
  2155. va_start( ap );
  2156. #endif
  2157. vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
  2158. va_end( ap );
  2159. if (!Use_Log) {
  2160. if (Level <= LOG_WARNING)
  2161. printf(" - %s\n", msg);
  2162. else
  2163. puts(msg);
  2164. } else
  2165. Log(Level, "%s", msg);
  2166. }
  2167. #ifdef DEBUG
  2168. /**
  2169. * Dump internal state of the "configuration module".
  2170. */
  2171. GLOBAL void
  2172. Conf_DebugDump(void)
  2173. {
  2174. int i;
  2175. Log(LOG_DEBUG, "Configured servers:");
  2176. for (i = 0; i < MAX_SERVERS; i++) {
  2177. if (! Conf_Server[i].name[0])
  2178. continue;
  2179. Log(LOG_DEBUG,
  2180. " - %s: %s:%d, last=%ld, group=%d, flags=%d, conn=%d",
  2181. Conf_Server[i].name, Conf_Server[i].host,
  2182. Conf_Server[i].port, Conf_Server[i].lasttry,
  2183. Conf_Server[i].group, Conf_Server[i].flags,
  2184. Conf_Server[i].conn_id);
  2185. }
  2186. }
  2187. #endif
  2188. /**
  2189. * Initialize server configuration structure to default values.
  2190. *
  2191. * @param Server Pointer to server structure to initialize.
  2192. */
  2193. static void
  2194. Init_Server_Struct( CONF_SERVER *Server )
  2195. {
  2196. assert( Server != NULL );
  2197. memset( Server, 0, sizeof (CONF_SERVER) );
  2198. Server->group = NONE;
  2199. Server->lasttry = time( NULL ) - Conf_ConnectRetry + STARTUP_DELAY;
  2200. if( NGIRCd_Passive ) Server->flags = CONF_SFLAG_DISABLED;
  2201. Proc_InitStruct(&Server->res_stat);
  2202. Server->conn_id = NONE;
  2203. memset(&Server->bind_addr, 0, sizeof(Server->bind_addr));
  2204. }
  2205. /* -eof- */