1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
19 #include "inspircd_config.h"
21 #include <sys/resource.h>
22 #include <sys/types.h>
29 #include "inspircd_io.h"
30 #include "inspircd_util.h"
31 #include "inspstring.h"
32 #include "helperfuncs.h"
35 extern ServerConfig *Config;
36 extern int openSockfd[MAXSOCKS];
40 ServerConfig::ServerConfig()
43 *ServerName = *Network = *ServerDesc = *AdminName = '\0';
44 *AdminEmail = *AdminNick = *diepass = *restartpass = '\0';
45 *motd = *rules = *PrefixQuit = *DieValue = *DNSServer = '\0';
46 *ModPath = *MyExecutable = *DisabledCommands = *PID = '\0';
52 NetBufferSize = 10240;
53 SoftLimit = MAXCLIENTS;
61 void ServerConfig::ClearStack()
63 include_stack.clear();
67 void ServerConfig::Read(bool bail, userrec* user)
69 char dbg[MAXBUF],pauseval[MAXBUF],Value[MAXBUF],timeout[MAXBUF],NB[MAXBUF],flood[MAXBUF],MW[MAXBUF],MCON[MAXBUF];
70 char AH[MAXBUF],AP[MAXBUF],AF[MAXBUF],DNT[MAXBUF],pfreq[MAXBUF],thold[MAXBUF],sqmax[MAXBUF],rqmax[MAXBUF],SLIMT[MAXBUF];
72 std::stringstream errstr;
73 include_stack.clear();
75 if (!LoadConf(CONFIG_FILE,&Config->config_f,&errstr))
78 log(DEFAULT,"There were errors in your configuration:\n%s",errstr.str().c_str());
81 printf("There were errors in your configuration:\n%s",errstr.str().c_str());
89 WriteServ(user->fd,"NOTICE %s :There were errors in the configuration file:",user->nick);
92 errstr.getline(dataline,1024);
93 WriteServ(user->fd,"NOTICE %s :%s",user->nick,dataline);
98 WriteOpers("There were errors in the configuration file:");
101 errstr.getline(dataline,1024);
102 WriteOpers(dataline);
109 ConfValue("server","name",0,Config->ServerName,&Config->config_f);
110 ConfValue("server","description",0,Config->ServerDesc,&Config->config_f);
111 ConfValue("server","network",0,Config->Network,&Config->config_f);
112 ConfValue("admin","name",0,Config->AdminName,&Config->config_f);
113 ConfValue("admin","email",0,Config->AdminEmail,&Config->config_f);
114 ConfValue("admin","nick",0,Config->AdminNick,&Config->config_f);
115 ConfValue("files","motd",0,Config->motd,&Config->config_f);
116 ConfValue("files","rules",0,Config->rules,&Config->config_f);
117 ConfValue("power","diepass",0,Config->diepass,&Config->config_f);
118 ConfValue("power","pause",0,pauseval,&Config->config_f);
119 ConfValue("power","restartpass",0,Config->restartpass,&Config->config_f);
120 ConfValue("options","prefixquit",0,Config->PrefixQuit,&Config->config_f);
121 ConfValue("die","value",0,Config->DieValue,&Config->config_f);
122 ConfValue("options","loglevel",0,dbg,&Config->config_f);
123 ConfValue("options","netbuffersize",0,NB,&Config->config_f);
124 ConfValue("options","maxwho",0,MW,&Config->config_f);
125 ConfValue("options","allowhalfop",0,AH,&Config->config_f);
126 ConfValue("options","allowprotect",0,AP,&Config->config_f);
127 ConfValue("options","allowfounder",0,AF,&Config->config_f);
128 ConfValue("dns","server",0,Config->DNSServer,&Config->config_f);
129 ConfValue("dns","timeout",0,DNT,&Config->config_f);
130 ConfValue("options","moduledir",0,Config->ModPath,&Config->config_f);
131 ConfValue("disabled","commands",0,Config->DisabledCommands,&Config->config_f);
132 ConfValue("options","somaxconn",0,MCON,&Config->config_f);
133 ConfValue("options","softlimit",0,SLIMT,&Config->config_f);
135 Config->SoftLimit = atoi(SLIMT);
136 if ((Config->SoftLimit < 1) || (Config->SoftLimit > MAXCLIENTS))
138 log(DEFAULT,"WARNING: <options:softlimit> value is greater than %d or less than 0, set to %d.",MAXCLIENTS,MAXCLIENTS);
139 Config->SoftLimit = MAXCLIENTS;
141 Config->MaxConn = atoi(MCON);
142 if (Config->MaxConn > SOMAXCONN)
143 log(DEFAULT,"WARNING: <options:somaxconn> value may be higher than the system-defined SOMAXCONN value!");
144 Config->NetBufferSize = atoi(NB);
145 Config->MaxWhoResults = atoi(MW);
146 Config->dns_timeout = atoi(DNT);
147 if (!Config->dns_timeout)
148 Config->dns_timeout = 5;
149 if (!Config->MaxConn)
150 Config->MaxConn = SOMAXCONN;
151 if (!*Config->DNSServer)
152 strlcpy(Config->DNSServer,"127.0.0.1",MAXBUF);
153 if (!*Config->ModPath)
154 strlcpy(Config->ModPath,MOD_PATH,MAXBUF);
155 Config->AllowHalfop = ((!strcasecmp(AH,"true")) || (!strcasecmp(AH,"1")) || (!strcasecmp(AH,"yes")));
156 if ((!Config->NetBufferSize) || (Config->NetBufferSize > 65535) || (Config->NetBufferSize < 1024))
158 log(DEFAULT,"No NetBufferSize specified or size out of range, setting to default of 10240.");
159 Config->NetBufferSize = 10240;
161 if ((!Config->MaxWhoResults) || (Config->MaxWhoResults > 65535) || (Config->MaxWhoResults < 1))
163 log(DEFAULT,"No MaxWhoResults specified or size out of range, setting to default of 128.");
164 Config->MaxWhoResults = 128;
166 Config->LogLevel = DEFAULT;
167 if (!strcmp(dbg,"debug"))
169 Config->LogLevel = DEBUG;
170 Config->debugging = 1;
172 if (!strcmp(dbg,"verbose"))
173 Config->LogLevel = VERBOSE;
174 if (!strcmp(dbg,"default"))
175 Config->LogLevel = DEFAULT;
176 if (!strcmp(dbg,"sparse"))
177 Config->LogLevel = SPARSE;
178 if (!strcmp(dbg,"none"))
179 Config->LogLevel = NONE;
181 readfile(Config->MOTD,Config->motd);
182 log(DEFAULT,"Reading message of the day...");
183 readfile(Config->RULES,Config->rules);
184 log(DEFAULT,"Reading connect classes...");
186 for (int i = 0; i < ConfValueEnum("connect",&Config->config_f); i++)
189 ConfValue("connect","allow",i,Value,&Config->config_f);
190 ConfValue("connect","timeout",i,timeout,&Config->config_f);
191 ConfValue("connect","flood",i,flood,&Config->config_f);
192 ConfValue("connect","pingfreq",i,pfreq,&Config->config_f);
193 ConfValue("connect","threshold",i,thold,&Config->config_f);
194 ConfValue("connect","sendq",i,sqmax,&Config->config_f);
195 ConfValue("connect","recvq",i,rqmax,&Config->config_f);
198 strlcpy(c.host,Value,MAXBUF);
200 strlcpy(Value,"",MAXBUF);
201 ConfValue("connect","password",i,Value,&Config->config_f);
202 strlcpy(c.pass,Value,MAXBUF);
203 c.registration_timeout = 90; // default is 2 minutes
205 c.flood = atoi(flood);
207 c.sendqmax = 262144; // 256k
208 c.recvqmax = 4096; // 4k
211 c.threshold = atoi(thold);
215 c.sendqmax = atoi(sqmax);
219 c.recvqmax = atoi(rqmax);
223 c.registration_timeout = atoi(timeout);
227 c.pingtime = atoi(pfreq);
229 Classes.push_back(c);
233 ConfValue("connect","deny",i,Value,&Config->config_f);
234 strlcpy(c.host,Value,MAXBUF);
236 Classes.push_back(c);
237 log(DEBUG,"Read connect class type DENY, host=%s",c.host);
241 log(DEFAULT,"Reading K lines,Q lines and Z lines from config...");
242 read_xline_defaults();
243 log(DEFAULT,"Applying K lines, Q lines and Z lines...");
244 apply_lines(APPLY_ALL);
246 ConfValue("pid","file",0,Config->PID,&Config->config_f);
247 // write once here, to try it out and make sure its ok
248 WritePID(Config->PID);
250 log(DEFAULT,"Done reading configuration file, InspIRCd is now starting.");
253 log(DEFAULT,"Adding and removing modules due to rehash...");
255 std::vector<std::string> old_module_names, new_module_names, added_modules, removed_modules;
257 // store the old module names
258 for (std::vector<std::string>::iterator t = module_names.begin(); t != module_names.end(); t++)
260 old_module_names.push_back(*t);
263 // get the new module names
264 for (int count2 = 0; count2 < ConfValueEnum("module",&Config->config_f); count2++)
266 ConfValue("module","name",count2,Value,&Config->config_f);
267 new_module_names.push_back(Value);
270 // now create a list of new modules that are due to be loaded
271 // and a seperate list of modules which are due to be unloaded
272 for (std::vector<std::string>::iterator _new = new_module_names.begin(); _new != new_module_names.end(); _new++)
275 for (std::vector<std::string>::iterator old = old_module_names.begin(); old != old_module_names.end(); old++)
281 added_modules.push_back(*_new);
283 for (std::vector<std::string>::iterator oldm = old_module_names.begin(); oldm != old_module_names.end(); oldm++)
286 for (std::vector<std::string>::iterator newm = new_module_names.begin(); newm != new_module_names.end(); newm++)
292 removed_modules.push_back(*oldm);
294 // now we have added_modules, a vector of modules to be loaded, and removed_modules, a vector of modules
296 int rem = 0, add = 0;
297 if (!removed_modules.empty())
298 for (std::vector<std::string>::iterator removing = removed_modules.begin(); removing != removed_modules.end(); removing++)
300 if (UnloadModule(removing->c_str()))
302 WriteOpers("*** REHASH UNLOADED MODULE: %s",removing->c_str());
303 WriteServ(user->fd,"973 %s %s :Module %s successfully unloaded.",user->nick, removing->c_str(), removing->c_str());
308 WriteServ(user->fd,"972 %s %s :Failed to unload module %s: %s",user->nick, removing->c_str(), removing->c_str(), ModuleError());
311 if (!added_modules.empty())
312 for (std::vector<std::string>::iterator adding = added_modules.begin(); adding != added_modules.end(); adding++)
314 if (LoadModule(adding->c_str()))
316 WriteOpers("*** REHASH LOADED MODULE: %s",adding->c_str());
317 WriteServ(user->fd,"975 %s %s :Module %s successfully loaded.",user->nick, adding->c_str(), adding->c_str());
322 WriteServ(user->fd,"974 %s %s :Failed to load module %s: %s",user->nick, adding->c_str(), adding->c_str(), ModuleError());
325 log(DEFAULT,"Successfully unloaded %lu of %lu modules and loaded %lu of %lu modules.",(unsigned long)rem,(unsigned long)removed_modules.size(),
326 (unsigned long)add,(unsigned long)added_modules.size());
331 void WriteOpers(char* text, ...);
333 void Exit (int status)
335 if (Config->log_file)
336 fclose(Config->log_file);
337 send_error("Server shutdown.");
341 void Killed(int status)
343 if (Config->log_file)
344 fclose(Config->log_file);
345 send_error("Server terminated.");
349 void Rehash(int status)
351 WriteOpers("Rehashing config file %s due to SIGHUP",CONFIG_FILE);
352 Config->Read(false,NULL);
359 printf("\033[1;32mInspire Internet Relay Chat Server, compiled %s at %s\n",__DATE__,__TIME__);
360 printf("(C) ChatSpike Development team.\033[0m\n\n");
361 printf("Developers:\033[1;32m Brain, FrostyCoolSlug\033[0m\n");
362 printf("Documentation:\033[1;32m FrostyCoolSlug, w00t\033[0m\n");
363 printf("Testers:\033[1;32m typobox43, piggles, Lord_Zathras, CC\033[0m\n");
364 printf("Name concept:\033[1;32m Lord_Zathras\033[0m\n\n");
367 void WritePID(std::string filename)
369 ofstream outfile(filename.c_str());
370 if (outfile.is_open())
377 printf("Failed to write PID-file '%s', exiting.\n",filename.c_str());
378 log(DEFAULT,"Failed to write PID-file '%s', exiting.",filename.c_str());
384 int DaemonSeed (void)
387 signal (SIGALRM, SIG_IGN);
388 signal (SIGHUP, Rehash);
389 signal (SIGPIPE, SIG_IGN);
390 signal (SIGTERM, Exit);
391 signal (SIGSEGV, Error);
392 if ((childpid = fork ()) < 0)
394 else if (childpid > 0)
398 printf("InspIRCd Process ID: \033[1;32m%lu\033[0m\n",(unsigned long)getpid());
400 setpriority(PRIO_PROCESS,(int)getpid(),15);
402 if (Config->unlimitcore)
405 if (getrlimit(RLIMIT_CORE, &rl) == -1)
407 log(DEFAULT,"Failed to getrlimit()!");
412 rl.rlim_cur = rl.rlim_max;
413 if (setrlimit(RLIMIT_CORE, &rl) == -1)
414 log(DEFAULT,"setrlimit() failed, cannot increase coredump size.");
422 /* Make Sure Modules Are Avaliable!
423 * (BugFix By Craig.. See? I do work! :p)
424 * Modified by brain, requires const char*
425 * to work with other API functions
428 bool FileExists (const char* file)
431 if ((input = fopen (file, "r")) == NULL)
442 /* ConfProcess does the following things to a config line in the following order:
444 * Processes the line for syntax errors as shown below
445 * (1) Line void of quotes or equals (a malformed, illegal tag format)
446 * (2) Odd number of quotes on the line indicating a missing quote
447 * (3) number of equals signs not equal to number of quotes / 2 (missing an equals sign)
448 * (4) Spaces between the opening bracket (<) and the keyword
449 * (5) Spaces between a keyword and an equals sign
450 * (6) Spaces between an equals sign and a quote
451 * Removes trailing spaces
452 * Removes leading spaces
453 * Converts tabs to spaces
454 * Turns multiple spaces that are outside of quotes into single spaces
457 std::string ServerConfig::ConfProcess(char* buffer, long linenumber, std::stringstream* errorstream, bool &error, std::string filename)
459 long number_of_quotes = 0;
460 long number_of_equals = 0;
461 bool has_open_bracket = false;
462 bool in_quotes = false;
468 // firstly clean up the line by stripping spaces from the start and end and converting tabs to spaces
469 for (unsigned int d = 0; d < strlen(buffer); d++)
470 if ((buffer[d]) == 9)
472 while ((buffer[0] == ' ') && (strlen(buffer)>0)) buffer++;
473 while ((buffer[strlen(buffer)-1] == ' ') && (strlen(buffer)>0)) buffer[strlen(buffer)-1] = '\0';
475 // empty lines are syntactically valid, as are comments
476 if (!(*buffer) || buffer[0] == '#')
479 for (unsigned int c = 0; c < strlen(buffer); c++)
481 // convert all spaces that are OUTSIDE quotes into hardspace (0xA0) as this will make them easier to
482 // search and replace later :)
483 if ((!in_quotes) && (buffer[c] == ' '))
485 if ((buffer[c] == '<') && (!in_quotes))
487 has_open_bracket = true;
488 if (strlen(buffer) == 1)
490 *errorstream << "Tag without identifier at " << filename << ":" << linenumber << endl;
494 else if ((tolower(buffer[c+1]) < 'a') || (tolower(buffer[c+1]) > 'z'))
496 *errorstream << "Invalid characters in identifier at " << filename << ":" << linenumber << endl;
501 if (buffer[c] == '"')
504 in_quotes = (!in_quotes);
506 if ((buffer[c] == '=') && (!in_quotes))
509 if (strlen(buffer) == c)
511 *errorstream << "Variable without a value at " << filename << ":" << linenumber << endl;
515 else if (buffer[c+1] != '"')
517 *errorstream << "Variable name not followed immediately by its value at " << filename << ":" << linenumber << endl;
523 *errorstream << "Value without a variable (line starts with '=') at " << filename << ":" << linenumber << endl;
527 else if (buffer[c-1] == '\xA0')
529 *errorstream << "Variable name not followed immediately by its value at " << filename << ":" << linenumber << endl;
535 // no quotes, and no equals. something freaky.
536 if ((!number_of_quotes) || (!number_of_equals) && (strlen(buffer)>2) && (buffer[0]=='<'))
538 *errorstream << "Malformed tag at " << filename << ":" << linenumber << endl;
542 // odd number of quotes. thats just wrong.
543 if ((number_of_quotes % 2) != 0)
545 *errorstream << "Missing \" at " << filename << ":" << linenumber << endl;
549 if (number_of_equals < (number_of_quotes/2))
551 *errorstream << "Missing '=' at " << filename << ":" << linenumber << endl;
553 if (number_of_equals > (number_of_quotes/2))
555 *errorstream << "Too many '=' at " << filename << ":" << linenumber << endl;
558 std::string parsedata = buffer;
559 // turn multispace into single space
560 while (parsedata.find("\xA0\xA0") != std::string::npos)
562 parsedata.erase(parsedata.find("\xA0\xA0"),1);
565 // turn our hardspace back into softspace
566 for (unsigned int d = 0; d < parsedata.length(); d++)
568 if (parsedata[d] == '\xA0')
572 // and we're done, the line is fine!
576 int ServerConfig::fgets_safe(char* buffer, size_t maxsize, FILE* &file)
579 unsigned int bufptr = 0;
580 while ((!feof(file)) && (c_read != '\n') && (c_read != '\r') && (bufptr < maxsize))
582 c_read = fgetc(file);
583 if ((c_read != '\n') && (c_read != '\r'))
584 buffer[bufptr++] = c_read;
586 buffer[bufptr] = '\0';
590 bool ServerConfig::LoadConf(const char* filename, std::stringstream *target, std::stringstream* errorstream)
593 errorstream->str("");
595 // first, check that the file exists before we try to do anything with it
596 if (!FileExists(filename))
598 *errorstream << "File " << filename << " not found." << endl;
601 // Fix the chmod of the file to restrict it to the current user and group
602 chmod(filename,0600);
603 for (unsigned int t = 0; t < include_stack.size(); t++)
605 if (std::string(filename) == include_stack[t])
607 *errorstream << "File " << filename << " is included recursively (looped inclusion)." << endl;
611 include_stack.push_back(filename);
613 FILE* conf = fopen(filename,"r");
619 if (fgets_safe(buffer, MAXBUF, conf))
621 if ((!feof(conf)) && (buffer) && (strlen(buffer)))
623 if ((buffer[0] != '#') && (buffer[0] != '\r') && (buffer[0] != '\n'))
625 if (!strncmp(buffer,"<include file=\"",15))
628 char confpath[10240],newconf[10240];
629 // include file directive
630 buf += 15; // advance to filename
631 for (unsigned int j = 0; j < strlen(buf); j++)
641 log(DEFAULT,"Opening included file '%s'",buf);
644 strlcpy(confpath,CONFIG_FILE,10240);
645 if (strstr(confpath,"/inspircd.conf"))
647 // leaves us with just the path
648 *(strstr(confpath,"/inspircd.conf")) = '\0';
650 snprintf(newconf,10240,"%s/%s",confpath,buf);
652 else snprintf(newconf,10240,"%s",buf);
653 std::stringstream merge(stringstream::in | stringstream::out);
654 // recursively call LoadConf and get the new data, use the same errorstream
655 if (LoadConf(newconf, &merge, errorstream))
657 // append to the end of the file
658 std::string newstuff = merge.str();
663 // the error propogates up to its parent recursively
664 // causing the config reader to bail at the top level.
672 std::string data = this->ConfProcess(buffer,linenumber++,errorstream,error,filename);
690 /* Counts the number of tags of a certain type within the config file, e.g. to enumerate opers */
692 int ServerConfig::EnumConf(std::stringstream *config, const char* tag)
695 char buffer[MAXBUF], c_tag[MAXBUF], c, lastc;
696 int in_token, in_quotes, tptr, idx = 0;
698 const char* buf = config->str().c_str();
700 long len = strlen(buf);
710 if ((c == '#') && (lastc == '\n'))
712 while ((c != '\n') && (bptr<len))
718 if ((c == '<') && (!in_quotes))
733 in_quotes = (!in_quotes);
735 if ((c == '>') && (!in_quotes))
738 if (!strcmp(c_tag,tag))
740 /* correct tag, but wrong index */
750 if ((in_token) && (c != '\n') && (c != '\r'))
760 /* Counts the number of values within a certain tag */
762 int ServerConfig::EnumValues(std::stringstream *config, const char* tag, int index)
765 char buffer[MAXBUF], c_tag[MAXBUF], c, lastc;
766 int in_token, in_quotes, tptr, idx = 0;
768 bool correct_tag = false;
771 const char* buf = config->str().c_str();
773 long len = strlen(buf);
783 if ((c == '#') && (lastc == '\n'))
785 while ((c != '\n') && (bptr<len))
791 if ((c == '<') && (!in_quotes))
802 if ((!strcmp(c_tag,tag)) && (idx == index))
811 in_quotes = (!in_quotes);
814 if ( (correct_tag) && (!in_quotes) && ( (c == ' ') || (c == '\n') || (c == '\r') ) )
818 if ((c == '>') && (!in_quotes))
823 if (!strcmp(c_tag,tag))
825 /* correct tag, but wrong index */
835 if ((in_token) && (c != '\n') && (c != '\r'))
847 int ServerConfig::ConfValueEnum(char* tag, std::stringstream* config)
849 return EnumConf(config,tag);
854 /* Retrieves a value from the config file. If there is more than one value of the specified
855 * key and section (e.g. for opers etc) then the index value specifies which to retreive, e.g.
857 * ConfValue("oper","name",2,result);
860 int ServerConfig::ReadConf(std::stringstream *config, const char* tag, const char* var, int index, char *result)
863 char buffer[65535], c_tag[MAXBUF], c, lastc;
864 int in_token, in_quotes, tptr, idx = 0;
867 const char* buf = config->str().c_str();
869 long len = config->str().length();
881 // FIX: Treat tabs as spaces
884 if ((c == '<') && (!in_quotes))
895 // FIX: Tab can follow a tagname as well as space.
896 } while ((c != ' ') && (c != 9));
900 in_quotes = (!in_quotes);
902 if ((c == '>') && (!in_quotes))
907 if (!strcmp(c_tag,tag))
909 if ((buffer) && (c_tag) && (var))
911 key = strstr(buffer,var);
914 /* value not found in tag */
932 for (unsigned j = 0; j < strlen(key); j++)
939 strlcpy(result,key,MAXBUF);
945 if (!strcmp(c_tag,tag))
947 /* correct tag, but wrong index */
957 if ((in_token) && (c != '\n') && (c != '\r'))
964 strcpy(result,""); // value or its tag not found at all
970 int ServerConfig::ConfValue(char* tag, char* var, int index, char *result,std::stringstream *config)
972 ReadConf(config, tag, var, index, result);
978 // This will bind a socket to a port. It works for UDP/TCP
979 int BindSocket (int sockfd, struct sockaddr_in client, struct sockaddr_in server, int port, char* addr)
981 memset((char *)&server,0,sizeof(server));
983 inet_aton(addr,&addy);
984 server.sin_family = AF_INET;
985 if (!strcmp(addr,""))
987 server.sin_addr.s_addr = htonl(INADDR_ANY);
991 server.sin_addr = addy;
993 server.sin_port = htons(port);
994 if (bind(sockfd,(struct sockaddr*)&server,sizeof(server))<0)
1000 listen(sockfd, Config->MaxConn);
1006 // Open a TCP Socket
1007 int OpenTCPSocket (void)
1011 struct linger linger = { 0 };
1013 if ((sockfd = socket (AF_INET, SOCK_STREAM, 0)) < 0)
1017 setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (const char*)&on, sizeof(on));
1018 /* This is BSD compatible, setting l_onoff to 0 is *NOT* http://web.irc.org/mla/ircd-dev/msg02259.html */
1020 linger.l_linger = 1;
1021 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, (const char*)&linger,sizeof(linger));
1028 char configToken[MAXBUF], Addr[MAXBUF], Type[MAXBUF];
1029 sockaddr_in client,server;
1030 int clientportcount = 0;
1032 for (int count = 0; count < Config->ConfValueEnum("bind",&Config->config_f); count++)
1034 Config->ConfValue("bind","port",count,configToken,&Config->config_f);
1035 Config->ConfValue("bind","address",count,Addr,&Config->config_f);
1036 Config->ConfValue("bind","type",count,Type,&Config->config_f);
1037 if (strcmp(Type,"servers"))
1039 // modules handle server bind types now,
1040 // its not a typo in the strcmp.
1041 Config->ports[clientportcount] = atoi(configToken);
1042 strlcpy(Config->addrs[clientportcount],Addr,256);
1044 log(DEBUG,"InspIRCd: startup: read binding %s:%s [%s] from config",Addr,configToken, Type);
1047 int PortCount = clientportcount;
1049 for (int count = 0; count < PortCount; count++)
1051 if ((openSockfd[BoundPortCount] = OpenTCPSocket()) == ERROR)
1053 log(DEBUG,"InspIRCd: startup: bad fd %lu",(unsigned long)openSockfd[BoundPortCount]);
1056 if (BindSocket(openSockfd[BoundPortCount],client,server,Config->ports[count],Config->addrs[count]) == ERROR)
1058 log(DEFAULT,"InspIRCd: startup: failed to bind port %lu",(unsigned long)Config->ports[count]);
1060 else /* well we at least bound to one socket so we'll continue */
1066 /* if we didn't bind to anything then abort */
1067 if (!BoundPortCount)
1069 log(DEFAULT,"InspIRCd: startup: no ports bound, bailing!");
1070 printf("\nERROR: Was not able to bind any of %lu ports! Please check your configuration.\n\n", (unsigned long)PortCount);
1074 return BoundPortCount;