- ConfigReader* Conf = new ConfigReader(ServerInstance);
- if (rebind)
- {
- for (int j =0; j < Conf->Enumerate("bind"); j++)
- {
- std::string Type = Conf->ReadValue("bind","type",j);
- std::string IP = Conf->ReadValue("bind","address",j);
- std::string Port = Conf->ReadValue("bind","port",j);
- std::string transport = Conf->ReadValue("bind","transport",j);
- if (Type == "servers")
- {
- irc::portparser portrange(Port, false);
- int portno = -1;
- while ((portno = portrange.GetToken()))
- {
- if (IP == "*")
- IP = "";
-
- if ((!transport.empty()) && (hooks.find(transport.c_str()) == hooks.end()))
- {
- ServerInstance->Log(DEFAULT,"m_spanningtree: WARNING: Can't find transport type '%s' for port %s:%s - maybe you forgot to load it BEFORE m_spanningtree in your config file? - Skipping this port binding", transport.c_str(), IP.c_str(), Port.c_str());
- break;
- }
-
- TreeSocket* listener = new TreeSocket(this, ServerInstance, IP.c_str(), portno, true, 10, transport.empty() ? NULL : hooks[transport.c_str()]);
- if (listener->GetState() == I_LISTENING)
- {
- ServerInstance->Log(DEFAULT,"m_spanningtree: Binding server port %s:%d successful!", IP.c_str(), portno);
- Bindings.push_back(listener);
- }
- else
- {
- ServerInstance->Log(DEFAULT,"m_spanningtree: Warning: Failed to bind server port %s:%d",IP.c_str(), portno);
- listener->Close();
- DELETE(listener);
- }
- }
- }
- }
- }
- FlatLinks = Conf->ReadFlag("options","flatlinks",0);
- HideULines = Conf->ReadFlag("options","hideulines",0);
- AnnounceTSChange = Conf->ReadFlag("options","announcets",0);
- EnableTimeSync = !(Conf->ReadFlag("options","notimesync",0));
- LinkBlocks.clear();
- ValidIPs.clear();
- for (int j =0; j < Conf->Enumerate("link"); j++)
- {
- Link L;
- std::string Allow = Conf->ReadValue("link","allowmask",j);
- L.Name = (Conf->ReadValue("link","name",j)).c_str();
- L.IPAddr = Conf->ReadValue("link","ipaddr",j);
- L.FailOver = Conf->ReadValue("link","failover",j).c_str();
- L.Port = Conf->ReadInteger("link","port",j,true);
- L.SendPass = Conf->ReadValue("link","sendpass",j);
- L.RecvPass = Conf->ReadValue("link","recvpass",j);
- L.AutoConnect = Conf->ReadInteger("link","autoconnect",j,true);
- L.HiddenFromStats = Conf->ReadFlag("link","hidden",j);
- L.Timeout = Conf->ReadInteger("link","timeout",j,true);
- L.Hook = Conf->ReadValue("link", "transport", j);
-
- if ((!L.Hook.empty()) && (hooks.find(L.Hook.c_str()) == hooks.end()))
- {
- ServerInstance->Log(DEFAULT,"m_spanningtree: WARNING: Can't find transport type '%s' for link '%s' - maybe you forgot to load it BEFORE m_spanningtree in your config file? Skipping <link> tag completely.",
- L.Hook.c_str(), L.Name.c_str());
- continue;
-
- }
-
- L.NextConnectTime = time(NULL) + L.AutoConnect;
- /* Bugfix by brain, do not allow people to enter bad configurations */
- if (L.Name != ServerInstance->Config->ServerName)
- {
- if ((L.IPAddr != "") && (L.RecvPass != "") && (L.SendPass != "") && (L.Name != "") && (L.Port))
- {
- ValidIPs.push_back(L.IPAddr);
-
- if (Allow.length())
- ValidIPs.push_back(Allow);
-
- /* Needs resolving */
- insp_inaddr binip;
- if (insp_aton(L.IPAddr.c_str(), &binip) < 1)
- {
- try
- {
- bool cached;
- SecurityIPResolver* sr = new SecurityIPResolver((Module*)this->Creator, this, ServerInstance, L.IPAddr, L, cached);
- ServerInstance->AddResolver(sr, cached);
- }
- catch (ModuleException& e)
- {
- }
- }
-
- LinkBlocks.push_back(L);
- }
- else
- {
- if (L.IPAddr == "")
- {
- ServerInstance->Log(DEFAULT,"Invalid configuration for server '%s', IP address not defined!",L.Name.c_str());
- }
- else if (L.RecvPass == "")
- {
- ServerInstance->Log(DEFAULT,"Invalid configuration for server '%s', recvpass not defined!",L.Name.c_str());
- }
- else if (L.SendPass == "")
- {
- ServerInstance->Log(DEFAULT,"Invalid configuration for server '%s', sendpass not defined!",L.Name.c_str());
- }
- else if (L.Name == "")
- {
- ServerInstance->Log(DEFAULT,"Invalid configuration, link tag without a name!");
- }
- else if (!L.Port)
- {
- ServerInstance->Log(DEFAULT,"Invalid configuration for server '%s', no port specified!",L.Name.c_str());
- }
- }
- }
- else
- {
- ServerInstance->Log(DEFAULT,"Invalid configuration for server '%s', link tag has the same server name as the local server!",L.Name.c_str());
- }
- }
- DELETE(Conf);
+ ConfigReader* Conf = new ConfigReader(ServerInstance);
+ if (rebind)
+ {
+ for (int j =0; j < Conf->Enumerate("bind"); j++)
+ {
+ std::string Type = Conf->ReadValue("bind","type",j);
+ std::string IP = Conf->ReadValue("bind","address",j);
+ std::string Port = Conf->ReadValue("bind","port",j);
+ std::string transport = Conf->ReadValue("bind","transport",j);
+ if (Type == "servers")
+ {
+ irc::portparser portrange(Port, false);
+ int portno = -1;
+ while ((portno = portrange.GetToken()))
+ {
+ if (IP == "*")
+ IP = "";
+
+ if ((!transport.empty()) && (hooks.find(transport.c_str()) == hooks.end()))
+ {
+ ServerInstance->Log(DEFAULT,"m_spanningtree: WARNING: Can't find transport type '%s' for port %s:%s - maybe you forgot to load it BEFORE m_spanningtree in your config file? - Skipping this port binding", transport.c_str(), IP.c_str(), Port.c_str());
+ break;
+ }
+
+ TreeSocket* listener = new TreeSocket(this, ServerInstance, IP.c_str(), portno, true, 10, transport.empty() ? NULL : hooks[transport.c_str()]);
+ if (listener->GetState() == I_LISTENING)
+ {
+ ServerInstance->Log(DEFAULT,"m_spanningtree: Binding server port %s:%d successful!", IP.c_str(), portno);
+ Bindings.push_back(listener);
+ }
+ else
+ {
+ ServerInstance->Log(DEFAULT,"m_spanningtree: Warning: Failed to bind server port: %s:%d: %s",IP.c_str(), portno, strerror(errno));
+ listener->Close();
+ DELETE(listener);
+ }
+ }
+ }
+ }
+ }
+ FlatLinks = Conf->ReadFlag("options","flatlinks",0);
+ HideULines = Conf->ReadFlag("options","hideulines",0);
+ AnnounceTSChange = Conf->ReadFlag("options","announcets",0);
+ EnableTimeSync = Conf->ReadFlag("timesync","enable",0);
+ MasterTime = Conf->ReadFlag("timesync", "master", 0);
+ ChallengeResponse = !Conf->ReadFlag("options", "disablehmac", 0);
+ LinkBlocks.clear();
+ ValidIPs.clear();
+ for (int j =0; j < Conf->Enumerate("link"); j++)
+ {
+ Link L;
+ std::string Allow = Conf->ReadValue("link", "allowmask", j);
+ L.Name = (Conf->ReadValue("link", "name", j)).c_str();
+ L.AllowMask = Allow;
+ L.IPAddr = Conf->ReadValue("link", "ipaddr", j);
+ L.FailOver = Conf->ReadValue("link", "failover", j).c_str();
+ L.Port = Conf->ReadInteger("link", "port", j, true);
+ L.SendPass = Conf->ReadValue("link", "sendpass", j);
+ L.RecvPass = Conf->ReadValue("link", "recvpass", j);
+ L.AutoConnect = Conf->ReadInteger("link", "autoconnect", j, true);
+ L.HiddenFromStats = Conf->ReadFlag("link", "hidden", j);
+ L.Timeout = Conf->ReadInteger("link", "timeout", j, true);
+ L.Hook = Conf->ReadValue("link", "transport", j);
+ L.Bind = Conf->ReadValue("link", "bind", j);
+ L.Hidden = Conf->ReadFlag("link", "hidden", j);
+
+ if ((!L.Hook.empty()) && (hooks.find(L.Hook.c_str()) == hooks.end()))
+ {
+ ServerInstance->Log(DEFAULT,"m_spanningtree: WARNING: Can't find transport type '%s' for link '%s' - maybe you forgot to load it BEFORE m_spanningtree in your config file? Skipping <link> tag completely.",
+ L.Hook.c_str(), L.Name.c_str());
+ continue;
+
+ }
+
+ L.NextConnectTime = time(NULL) + L.AutoConnect;
+ /* Bugfix by brain, do not allow people to enter bad configurations */
+ if (L.Name != ServerInstance->Config->ServerName)
+ {
+ if ((L.IPAddr != "") && (L.RecvPass != "") && (L.SendPass != "") && (L.Name != "") && (L.Port))
+ {
+ ValidIPs.push_back(L.IPAddr);
+
+ if (Allow.length())
+ ValidIPs.push_back(Allow);
+
+ /* Needs resolving */
+ bool ipvalid = true;
+ QueryType start_type = DNS_QUERY_A;
+#ifdef IPV6
+ start_type = DNS_QUERY_AAAA;
+ if (strchr(L.IPAddr.c_str(),':'))
+ {
+ in6_addr n;
+ if (inet_pton(AF_INET6, L.IPAddr.c_str(), &n) < 1)
+ ipvalid = false;
+ }
+ else
+ {
+ in_addr n;
+ if (inet_aton(L.IPAddr.c_str(),&n) < 1)
+ ipvalid = false;
+ }
+#else
+ in_addr n;
+ if (inet_aton(L.IPAddr.c_str(),&n) < 1)
+ ipvalid = false;
+#endif
+
+ if (!ipvalid)
+ {
+ try
+ {
+ bool cached;
+ SecurityIPResolver* sr = new SecurityIPResolver((Module*)this->Creator, this, ServerInstance, L.IPAddr, L, cached, start_type);
+ ServerInstance->AddResolver(sr, cached);
+ }
+ catch (ModuleException& e)
+ {
+ }
+ }
+
+ LinkBlocks.push_back(L);
+ }
+ else
+ {
+ if (L.IPAddr == "")
+ {
+ ServerInstance->Log(DEFAULT,"Invalid configuration for server '%s', IP address not defined!",L.Name.c_str());
+ }
+ else if (L.RecvPass == "")
+ {
+ ServerInstance->Log(DEFAULT,"Invalid configuration for server '%s', recvpass not defined!",L.Name.c_str());
+ }
+ else if (L.SendPass == "")
+ {
+ ServerInstance->Log(DEFAULT,"Invalid configuration for server '%s', sendpass not defined!",L.Name.c_str());
+ }
+ else if (L.Name == "")
+ {
+ ServerInstance->Log(DEFAULT,"Invalid configuration, link tag without a name!");
+ }
+ else if (!L.Port)
+ {
+ ServerInstance->Log(DEFAULT,"Invalid configuration for server '%s', no port specified!",L.Name.c_str());
+ }
+ }
+ }
+ else
+ {
+ ServerInstance->Log(DEFAULT,"Invalid configuration for server '%s', link tag has the same server name as the local server!",L.Name.c_str());
+ }
+ }
+ DELETE(Conf);