]> jfr.im git - irc/quakenet/newserv.git/blobdiff - trusts/trusts_slave.c
CHANSERV: remove accidental sendemail from SETEMAIL command.
[irc/quakenet/newserv.git] / trusts / trusts_slave.c
index 9b5dc4e1f44387c946d878c1332508c0aec08f1e..3986c3e05a7cc91e9ae25c2eaa49c1a6141a4b3b 100644 (file)
@@ -7,6 +7,7 @@
 #include "../core/config.h"
 #include "../core/error.h"
 #include "../control/control.h"
+#include "../lib/version.h"
 #include "../lib/sha1.h"
 #include "../lib/hmac.h"
 #include "../lib/irc_string.h"
@@ -15,6 +16,8 @@
 #include "../xsb/xsb.h"
 #include "trusts.h"
 
+MODULE_VERSION("");
+
 static int syncing, synced;
 static sstring *smasterserver;
 
@@ -39,9 +42,9 @@ static void __abandonreplication(const char *fn, int line, char *error, ...) {
 
   Error("trusts_slave", ERR_ERROR, "%s", buf2);
 
-  syncing = 0;
+  syncing = synced = 0;
 
-  /* TODO: warn IRC */
+  controlwall(NO_DEVELOPER, NL_TRUSTS, "Warning: %s", buf2);
 }
 
 #define abandonreplication(x, ...) __abandonreplication(__FUNCTION__, __LINE__, x , # __VA_ARGS__)
@@ -235,7 +238,7 @@ static int xsb_trfini(void *source, int argc, char **argv) {
   }
 
   SHA1Final(digest, &s);
-  if(strcasecmp(hmac_printhex(digest, digestbuf, SHA1_DIGESTSIZE), buf)) {
+  if(hmac_strcmp(hmac_printhex(digest, digestbuf, SHA1_DIGESTSIZE), buf)) {
     abandonreplication("digest mismatch");
     return CMD_ERROR;
   }
@@ -304,7 +307,7 @@ static int xsb_traddhost(void *source, int argc, char **argv) {
     return CMD_ERROR;
   }
 
-  th.group = tg_inttotg(tgid);
+  th.group = tg_getbyid(tgid);
   if(!th.group) {
     abandonreplication("unable to lookup trustgroup");
     return CMD_ERROR;
@@ -319,6 +322,9 @@ static int xsb_traddhost(void *source, int argc, char **argv) {
 }
 
 static int xsb_trdelhost(void *source, int argc, char **argv) {
+  unsigned int id;
+  trusthost *th;
+
   if(!synced)
     return CMD_OK;
 
@@ -330,10 +336,58 @@ static int xsb_trdelhost(void *source, int argc, char **argv) {
     return CMD_ERROR;
   }
 
+  id = strtoul(argv[0], NULL, 10);
+  if(!id) {
+    abandonreplication("unable to convert id to integer");
+    return CMD_ERROR;
+  }
+
+  th = th_getbyid(id);
+  if(!th) {
+    abandonreplication("unable to lookup id");
+    return CMD_ERROR;
+  }
+
+  th_delete(th);
+
   return CMD_OK;
 }
 
 static int xsb_trdelgroup(void *source, int argc, char **argv) {
+  unsigned int id;
+  trustgroup *tg;
+
+  if(!synced)
+    return CMD_OK;
+
+  if(!masterserver(source))
+    return CMD_ERROR;
+
+  if(argc < 1) {
+    abandonreplication("bad number of arguments");
+    return CMD_ERROR;
+  }
+
+  id = strtoul(argv[0], NULL, 10);
+  if(!id) {
+    abandonreplication("unable to convert id to integer");
+    return CMD_ERROR;
+  }
+
+  tg = tg_getbyid(id);
+  if(!tg) {
+    abandonreplication("unable to lookup id");
+    return CMD_ERROR;
+  }
+
+  tg_delete(tg);
+
+  return CMD_OK;
+}
+
+static int xsb_trmodifygroup(void *source, int argc, char **argv) {
+  trustgroup tg, *otg;
+
   if(!synced)
     return CMD_OK;
 
@@ -345,6 +399,73 @@ static int xsb_trdelgroup(void *source, int argc, char **argv) {
     return CMD_ERROR;
   }
 
+  if(!parsetg(argv[0], &tg, 0)) {
+    abandonreplication("bad trustgroup line: %s", argv[0]);
+    return CMD_ERROR;
+  }
+
+  otg = tg_getbyid(tg.id);
+
+  if(otg && !tg_modify(otg, &tg)) {
+    abandonreplication("unable to modify database");
+    return CMD_ERROR;
+  }
+
+  freesstring(tg.name);
+  freesstring(tg.createdby);
+  freesstring(tg.contact);
+  freesstring(tg.comment);
+
+  if(!otg) {
+    abandonreplication("unable to lookup id");
+    return CMD_ERROR;
+  }
+
+  tg_update(otg);
+
+  return CMD_OK;
+}
+
+static int xsb_trmodifyhost(void *source, int argc, char **argv) {
+  trustgroup *tg;
+  trusthost th, *oth;
+  unsigned int groupid;
+
+  if(!synced)
+    return CMD_OK;
+
+  if(!masterserver(source))
+    return CMD_ERROR;
+
+  if(argc < 1) {
+    abandonreplication("bad number of arguments");
+    return CMD_ERROR;
+  }
+
+  if(!parseth(argv[0], &th, &groupid, 0)) {
+    abandonreplication("bad trusthost line: %s", argv[0]);
+    return CMD_ERROR;
+  }
+
+  tg = tg_getbyid(groupid);
+
+  for(oth=tg->hosts;oth;oth=oth->next) {
+    if(ipmask_check(&oth->ip, &th.ip, th.bits) && th.bits == oth->bits)
+      break;
+  }
+
+  if(oth && !th_modify(oth, &th)) {
+    abandonreplication("unable to modify database");
+    return CMD_ERROR;
+  }
+
+  if(!oth) {
+    abandonreplication("unable to lookup host");
+    return CMD_ERROR;
+  }
+
+  th_update(oth);
+
   return CMD_OK;
 }
 
@@ -421,6 +542,8 @@ void _init(void) {
   xsb_addcommand("traddgroup", 1, xsb_traddgroup);
   xsb_addcommand("trdelhost", 1, xsb_trdelhost);
   xsb_addcommand("trdelgroup", 1, xsb_trdelgroup);
+  xsb_addcommand("trmodifygroup", 1, xsb_trmodifygroup);
+  xsb_addcommand("trmodifyhost", 1, xsb_trmodifyhost);
 
   registerhook(HOOK_SERVER_LINKED, __serverlinked);
   syncsched = schedulerecurring(time(NULL)+5, 0, 60, checksynced, NULL);
@@ -444,6 +567,8 @@ void _fini(void) {
   xsb_delcommand("traddgroup", xsb_traddgroup);
   xsb_delcommand("trdelhost", xsb_trdelhost);
   xsb_delcommand("trdelgroup", xsb_trdelgroup);
+  xsb_delcommand("trmodifygroup", xsb_trmodifygroup);
+  xsb_delcommand("trmodifyhost", xsb_trmodifyhost);
 
   deregisterhook(HOOK_SERVER_LINKED, __serverlinked);