summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.c100
-rw-r--r--src/init.c42
-rw-r--r--src/messages.c16
-rw-r--r--src/protocol/bahamut.c4
-rw-r--r--src/protocol/inspircd11.c4
-rw-r--r--src/protocol/inspircd12.cpp10
-rw-r--r--src/protocol/ratbox.c4
-rw-r--r--src/protocol/unreal32.c4
8 files changed, 88 insertions, 96 deletions
diff --git a/src/config.c b/src/config.c
index 8a8473764..9b61d3ec6 100644
--- a/src/config.c
+++ b/src/config.c
@@ -27,17 +27,8 @@ static const char *SERVICES_CONF_NEW = "services_new.conf";
char *IRCDModule;
char *EncModule;
-char *RemoteServer;
-int RemotePort;
-char *RemotePassword;
-char *RemoteServer2;
-int RemotePort2;
-char *RemotePassword2;
-
-char *RemoteServer3;
-int RemotePort3;
-char *RemotePassword3;
+std::list<Uplink *> Uplinks;
char *LocalHost;
int LocalPort;
@@ -566,15 +557,57 @@ void ServerConfig::ReportConfigError(const std::string &errormessage, bool bail)
}
}
+bool InitUplinks(ServerConfig *, const char *)
+{
+ if (!Uplinks.empty()) {
+ std::list<Uplink *>::iterator curr_uplink = Uplinks.begin(), end_uplink = Uplinks.end();
+ for (; curr_uplink != end_uplink; ++curr_uplink) delete *curr_uplink;
+ }
+ Uplinks.clear();
+ return true;
+}
+
+bool DoUplink(ServerConfig *conf, const char *, const char **, ValueList &values, int *)
+{
+ // Validation variables
+ const char *host = values[0].GetString(), *password = values[2].GetString();
+ int port = values[1].GetInteger();
+ ValueItem vi_host(host), vi_port(port), vi_password(password);
+ // Validate the host to make sure it is not empty
+ if (!ValidateNotEmpty(conf, "uplink", "host", vi_host))
+ throw ConfigException("One or more values in your configuration file failed to validate. Please see your ircd.log for more information.");
+ // Validate the port to make sure it is a valid port
+ if (!ValidatePort(conf, "uplink", "port", vi_port))
+ throw ConfigException("One or more values in your configuration file failed to validate. Please see your ircd.log for more information.");
+ // Validate the password to make sure it is not empty
+ if (!ValidateNotEmpty(conf, "uplink", "password", vi_password))
+ throw ConfigException("One or more values in your configuration file failed to validate. Please see your ircd.log for more information.");
+ // If we get here, all the values are valid, we'll add it to the Uplinks list
+ Uplinks.push_back(new Uplink(host, port, password));
+ return true;
+}
+
+bool DoneUplinks(ServerConfig *, const char *)
+{
+ return true;
+}
+
bool InitModules(ServerConfig *, const char *)
{
Modules.clear();
return true;
}
-bool DoModule(ServerConfig *, const char *, const char **, ValueList &values, int *)
+bool DoModule(ServerConfig *conf, const char *, const char **, ValueList &values, int *)
{
+ // First we validate that there was a name in the module block
+ const char *module = values[0].GetString();
+ ValueItem vi(module);
+ if (!ValidateNotEmpty(conf, "module", "name", vi))
+ throw ConfigException("One or more values in your configuration file failed to validate. Please see your ircd.log for more information.");
+ // If the string isn't empty, add a space before we add the module name
if (!Modules.empty()) Modules += " ";
+ // Add the module name to the string
Modules += values[0].GetString();
return true;
}
@@ -619,34 +652,31 @@ int ServerConfig::Read(bool bail)
*
* If you want to create a directive using a character pointer specifically to hold a hostname (this will call ValidateHostname automatically):
* char *blarg;
- * {"tag", "value", "", new ValueContainerChar(blarg), DT_HOSTNAME, <validation>},
+ * {"tag", "value", "", new ValueContainerChar(&blarg), DT_HOSTNAME, <validation>},
*
* If you want to create a directive using a character pointer that specifically can not have spaces in it (this will call ValidateNoSpaces automatically):
* char *blarg;
- * {"tag", "value", "", new ValueContainerChar(blarg), DT_NOSPACES, <validation>},
+ * {"tag", "value", "", new ValueContainerChar(&blarg), DT_NOSPACES, <validation>},
*
* If you want to create a directive using a character pointer specifically to hold an IP address (this will call ValidateIP automatically):
* char *blarg;
- * {"tag", "value", "", new ValueContainerChar(blarg), DT_IPADDRESS, <validation>},
+ * {"tag", "value", "", new ValueContainerChar(&blarg), DT_IPADDRESS, <validation>},
*
* If you want to create a directive using a time (a time_t variable converted from a string):
* time_t blarg;
* {"tag", "value", "", new ValueContainterTime(&blarg), DT_TIME, <validation>},
*
* For the second-to-last argument, you can or (|) in the following values:
- * DT_NORELOAD - The variable can't be changed on a reload of the configuration (CURRENTLY NOT SET UP TO WORK YET)
+ * DT_NORELOAD - The variable can't be changed on a reload of the configuration
* DT_ALLOW_WILD - Allows wildcards/CIDR in DT_IPADDRESS
* DT_ALLOW_NEWLINE - Allows new line characters in DT_CHARPTR and DT_STRING
*
* We may need to add some other validation functions to handle certain things, we can handle that later.
* Any questions about these, w00t, feel free to ask. */
- {"uplink", "type", "", new ValueContainerChar(&IRCDModule), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty},
- {"uplink", "host", "", new ValueContainerChar(&RemoteServer), DT_HOSTNAME | DT_NORELOAD, ValidateNotEmpty},
- {"uplink", "port", "0", new ValueContainerInt(&RemotePort), DT_INTEGER | DT_NORELOAD, ValidatePort},
- {"uplink", "password", "", new ValueContainerChar(&RemotePassword), DT_NOSPACES | DT_NORELOAD, ValidateNotEmpty},
- {"uplink", "id", "", new ValueContainerChar(&Numeric), DT_NOSPACES | DT_NORELOAD, NoValidation},
{"serverinfo", "name", "", new ValueContainerChar(&ServerName), DT_HOSTNAME | DT_NORELOAD, ValidateNotEmpty},
{"serverinfo", "description", "", new ValueContainerChar(&ServerDesc), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty},
+ {"serverinfo", "type", "", new ValueContainerChar(&IRCDModule), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty},
+ {"serverinfo", "id", "", new ValueContainerChar(&Numeric), DT_NOSPACES | DT_NORELOAD, NoValidation},
{"serverinfo", "ident", "", new ValueContainerChar(&ServiceUser), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty},
{"serverinfo", "hostname", "", new ValueContainerChar(&ServiceHost), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty},
{"serverinfo", "pid", "services.pid", new ValueContainerChar(&PIDFilename), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty},
@@ -813,6 +843,11 @@ int ServerConfig::Read(bool bail)
/* These tags can occur multiple times, and therefore they have special code to read them
* which is different to the code for reading the singular tags listed above. */
MultiConfig MultiValues[] = {
+ {"uplink",
+ {"host", "port", "password", NULL},
+ {"", "0", "", NULL},
+ {DT_HOSTNAME | DT_NORELOAD, DT_INTEGER | DT_NORELOAD, DT_NOSPACES | DT_NORELOAD},
+ InitUplinks, DoUplink, DoneUplinks},
{"module",
{"name", NULL},
{"", NULL},
@@ -845,8 +880,8 @@ int ServerConfig::Read(bool bail)
dt &= ~DT_ALLOW_NEWLINE;
dt &= ~DT_ALLOW_WILD;
dt &= ~DT_NORELOAD;
- // If the value is set to not allow reloading and we are reloading (bail will be true), skip the item
- if (noreload && bail)
+ // If the value is set to not allow reloading and we are reloading (bail will be false), skip the item
+ if (noreload && !bail)
continue;
ConfValue(config_data, Values[Index].tag, Values[Index].value, Values[Index].default_value, 0, item, BUFSIZE, allow_newlines);
ValueItem vi(item);
@@ -932,8 +967,8 @@ int ServerConfig::Read(bool bail)
dt &= ~DT_ALLOW_NEWLINE;
dt &= ~DT_ALLOW_WILD;
dt &= ~DT_NORELOAD;
- // If the value is set to not allow reloading and we are reloading (bail will be true), skip the item
- if (noreload && bail)
+ // If the value is set to not allow reloading and we are reloading (bail will be false), skip the item
+ if (noreload && !bail)
continue;
switch (dt) {
case DT_NOSPACES: {
@@ -986,7 +1021,8 @@ int ServerConfig::Read(bool bail)
}
break;
case DT_INTEGER:
- case DT_UINTEGER: {
+ case DT_UINTEGER:
+ case DT_LUINTEGER: {
int item = 0;
if (ConfValueInteger(config_data, MultiValues[Index].tag, MultiValues[Index].items[valuenum],
MultiValues[Index].items_default[valuenum], tagnum, item)) vl.push_back(ValueItem(item));
@@ -1403,13 +1439,6 @@ bool ValueItem::GetBool()
Directive directives[] = {
{"LocalAddress", {{PARAM_STRING, 0, &LocalHost},
{PARAM_PORT, PARAM_OPTIONAL, &LocalPort}}},
- {"ModuleAutoload", {{PARAM_STRING, PARAM_RELOAD, &Modules}}},
- {"RemoteServer2", {{PARAM_STRING, 0, &RemoteServer2},
- {PARAM_PORT, 0, &RemotePort2},
- {PARAM_STRING, 0, &RemotePassword2}}},
- {"RemoteServer3", {{PARAM_STRING, 0, &RemoteServer3},
- {PARAM_PORT, 0, &RemotePort3},
- {PARAM_STRING, 0, &RemotePassword3}}},
};
/*************************************************************************/
@@ -1676,7 +1705,7 @@ int read_config(int reload)
}
}
- retval = serverConfig.Read(reload);
+ retval = serverConfig.Read(reload ? false : true);
if (!retval) return 0; // Temporary until most of the below is modified to use the new parser -- CyberBotX
config = fopen(SERVICES_CONF, "r");
if (!config) {
@@ -1698,7 +1727,8 @@ int read_config(int reload)
}
fclose(config);
- if (!reload) {
+ // This section will need better checking after we get LocalAddress moved to the new config
+ /*if (!reload) {
if (RemoteServer3)
CHECK(RemoteServer2);
@@ -1713,7 +1743,7 @@ int read_config(int reload)
retval = 0;
}
}
- }
+ }*/
if (temp_nsuserhost) {
if (!(s = strchr(temp_nsuserhost, '@'))) {
diff --git a/src/init.c b/src/init.c
index 3e4f2ed72..e9042adeb 100644
--- a/src/init.c
+++ b/src/init.c
@@ -14,7 +14,7 @@
#include "services.h"
#include "pseudo.h"
-int servernum = 0;
+Uplink *uplink_server;
extern void moduleAddMsgs(void);
extern void moduleAddIRCDMsgs(void);
@@ -142,14 +142,14 @@ static int parse_options(int ac, char **av)
*t++ = 0;
portnum = atoi(t);
if ((portnum > 0) && (portnum < 65535))
- RemotePort = portnum;
+ /*RemotePort = portnum*/; // Needs fixing to handle the Uplinks list
else {
fprintf(stderr,
"-remote: Port numbers must be in the range 1..65535. Using default.\n");
return -1;
}
}
- RemoteServer = s;
+ /*RemoteServer = s*/; // Needs fixing to handle the Uplinks list
} else if (strcmp(s, "local") == 0) {
if (++i >= ac) {
fprintf(stderr,
@@ -608,35 +608,17 @@ int init_secondary(int ac, char **av)
send_event(EVENT_CONNECT, 1, EVENT_START);
/* Connect to the remote server */
- servsock = conn(RemoteServer, RemotePort, LocalHost, LocalPort);
- if (servsock < 0 && RemoteServer2) {
- servsock = conn(RemoteServer2, RemotePort2, LocalHost, LocalPort);
- if (servsock < 0 && RemoteServer3) {
- servsock =
- conn(RemoteServer3, RemotePort3, LocalHost, LocalPort);
- if (servsock < 0) {
- fatal_perror("Can't connect to server");
- } else {
- servernum = 3;
- alog("Connected to Server %d (%s:%d)", servernum,
- RemoteServer3, RemotePort3);
- }
- } else {
- if (servsock < 0) {
- fatal_perror("Can't connect to server");
- }
- servernum = 2;
- alog("Connected to Server %d (%s:%d)", servernum,
- RemoteServer2, RemotePort2);
- }
- } else {
- if (servsock < 0) {
- fatal_perror("Can't connect to server");
+ std::list<Uplink *>::iterator curr_uplink = Uplinks.begin(), end_uplink = Uplinks.end();
+ int servernum = 1;
+ for (; curr_uplink != end_uplink; ++curr_uplink, ++servernum) {
+ uplink_server = *curr_uplink;
+ servsock = conn(uplink_server->host, uplink_server->port, LocalHost, LocalPort);
+ if (servsock >= 0) {
+ alog("Connected to Server %d (%s:%d)", servernum, uplink_server->host, uplink_server->port);
+ break;
}
- servernum = 1;
- alog("Connected to Server %d (%s:%d)", servernum, RemoteServer,
- RemotePort);
}
+ if (curr_uplink == end_uplink) fatal_perror("Can't connect to any servers");
ircdproto->SendConnect();
send_event(EVENT_CONNECT, 1, EVENT_STOP);
diff --git a/src/messages.c b/src/messages.c
index ece0a3cd4..4f82d96df 100644
--- a/src/messages.c
+++ b/src/messages.c
@@ -221,19 +221,9 @@ int m_stats(const char *source, int ac, const char **av)
if (u && is_oper(u)) {
- if (servernum == 1) {
- ircdproto->SendNumeric(ServerName, 211, source, "Server SendBuf SentBytes SentMsgs RecvBuf RecvBytes RecvMsgs ConnTime");
- ircdproto->SendNumeric(ServerName, 211, source, "%s %d %d %d %d %d %d %ld", RemoteServer, write_buffer_len(), total_written, -1, read_buffer_len(),
- total_read, -1, time(NULL) - start_time);
- } else if (servernum == 2) {
- ircdproto->SendNumeric(ServerName, 211, source, "Server SendBuf SentBytes SentMsgs RecvBuf RecvBytes RecvMsgs ConnTime");
- ircdproto->SendNumeric(ServerName, 211, source, "%s %d %d %d %d %d %d %ld", RemoteServer2, write_buffer_len(), total_written, -1, read_buffer_len(),
- total_read, -1, time(NULL) - start_time);
- } else if (servernum == 3) {
- ircdproto->SendNumeric(ServerName, 211, source, "Server SendBuf SentBytes SentMsgs RecvBuf RecvBytes RecvMsgs ConnTime");
- ircdproto->SendNumeric(ServerName, 211, source, "%s %d %d %d %d %d %d %ld", RemoteServer3, write_buffer_len(), total_written, -1, read_buffer_len(),
- total_read, -1, time(NULL) - start_time);
- }
+ ircdproto->SendNumeric(ServerName, 211, source, "Server SendBuf SentBytes SentMsgs RecvBuf RecvBytes RecvMsgs ConnTime");
+ ircdproto->SendNumeric(ServerName, 211, source, "%s %d %d %d %d %d %d %ld", uplink_server->host, write_buffer_len(), total_written, -1, read_buffer_len(),
+ total_read, -1, time(NULL) - start_time);
}
ircdproto->SendNumeric(ServerName, 219, source, "%c :End of /STATS report.", *av[0] ? *av[0] : '*');
diff --git a/src/protocol/bahamut.c b/src/protocol/bahamut.c
index 9effddb20..424a5da8b 100644
--- a/src/protocol/bahamut.c
+++ b/src/protocol/bahamut.c
@@ -721,9 +721,7 @@ class BahamutIRCdProto : public IRCDProto
void SendConnect()
{
me_server = new_server(NULL, ServerName, ServerDesc, SERVER_ISME, NULL);
- if (servernum == 1) bahamut_cmd_pass(RemotePassword);
- else if (servernum == 2) bahamut_cmd_pass(RemotePassword2);
- else if (servernum == 3) bahamut_cmd_pass(RemotePassword3);
+ bahamut_cmd_pass(uplink_server->password);
bahamut_cmd_capab();
SendServer(ServerName, 1, ServerDesc);
bahamut_cmd_svinfo();
diff --git a/src/protocol/inspircd11.c b/src/protocol/inspircd11.c
index f66ef2f2b..043e169f1 100644
--- a/src/protocol/inspircd11.c
+++ b/src/protocol/inspircd11.c
@@ -606,9 +606,7 @@ class InspIRCdProto : public IRCDProto
void SendConnect()
{
- if (servernum == 1) inspircd_cmd_pass(RemotePassword);
- else if (servernum == 2) inspircd_cmd_pass(RemotePassword2);
- else if (servernum == 3) inspircd_cmd_pass(RemotePassword3);
+ inspircd_cmd_pass(uplink_server->password);
SendServer(ServerName, 0, ServerDesc);
send_cmd(NULL, "BURST");
send_cmd(ServerName, "VERSION :Anope-%s %s :%s - %s (%s) -- %s", version_number, ServerName, ircd->name, version_flags, EncModule, version_build);
diff --git a/src/protocol/inspircd12.cpp b/src/protocol/inspircd12.cpp
index fd48fb924..51c614a70 100644
--- a/src/protocol/inspircd12.cpp
+++ b/src/protocol/inspircd12.cpp
@@ -609,9 +609,7 @@ class InspIRCdProto : public IRCDProto
void SendConnect()
{
- if (servernum == 1) inspircd_cmd_pass(RemotePassword);
- else if (servernum == 2) inspircd_cmd_pass(RemotePassword2);
- else if (servernum == 3) inspircd_cmd_pass(RemotePassword3);
+ inspircd_cmd_pass(uplink_server->password);
SendServer(ServerName, 0, ServerDesc);
send_cmd(NULL, "BURST");
send_cmd(TS6SID, "VERSION :Anope-%s %s :%s - %s (%s) -- %s", version_number, ServerName, ircd->name, version_flags, EncModule, version_build);
@@ -728,16 +726,16 @@ int anope_event_mode(const char *source, int ac, const char **av)
*/
User *u = find_byuid(source);
User *u2 = find_byuid(av[0]);
-
+
// This can happen with server-origin modes.
if (u == NULL)
u = u2;
-
+
// drop it like fire.
// most likely situation was
if (u == NULL || u2 == NULL)
return MOD_CONT;
-
+
av[0] = u2->nick;
do_umode(u->nick, ac, av);
}
diff --git a/src/protocol/ratbox.c b/src/protocol/ratbox.c
index bfceeab0c..eca562c54 100644
--- a/src/protocol/ratbox.c
+++ b/src/protocol/ratbox.c
@@ -595,9 +595,7 @@ class RatboxProto : public IRCDTS6Proto
{
/* Make myself known to myself in the serverlist */
me_server = new_server(NULL, ServerName, ServerDesc, SERVER_ISME, TS6SID);
- if (servernum == 1) ratbox_cmd_pass(RemotePassword);
- else if (servernum == 2) ratbox_cmd_pass(RemotePassword2);
- else if (servernum == 3) ratbox_cmd_pass(RemotePassword3);
+ ratbox_cmd_pass(uplink_server->password);
ratbox_cmd_capab();
SendServer(ServerName, 1, ServerDesc);
ratbox_cmd_svinfo();
diff --git a/src/protocol/unreal32.c b/src/protocol/unreal32.c
index 5a820f3aa..c0ee75c6c 100644
--- a/src/protocol/unreal32.c
+++ b/src/protocol/unreal32.c
@@ -739,9 +739,7 @@ class UnrealIRCdProto : public IRCDProto
if (Numeric) me_server = new_server(NULL, ServerName, ServerDesc, SERVER_ISME, Numeric);
else me_server = new_server(NULL, ServerName, ServerDesc, SERVER_ISME, NULL);
unreal_cmd_capab();
- if (servernum == 1) unreal_cmd_pass(RemotePassword);
- else if (servernum == 2) unreal_cmd_pass(RemotePassword2);
- else if (servernum == 3) unreal_cmd_pass(RemotePassword3);
+ unreal_cmd_pass(uplink_server->password);
SendServer(ServerName, 1, ServerDesc);
}