]> jfr.im git - irc/quakenet/newserv.git/commitdiff
Refactor trustgline code and implement glinebyhost/unglinebyhost.
authorGunnar Beutner <redacted>
Sun, 16 Jun 2013 02:13:07 +0000 (04:13 +0200)
committerGunnar Beutner <redacted>
Sun, 16 Jun 2013 02:13:07 +0000 (04:13 +0200)
--HG--
branch : shroudtrusts

glines/glines.c
glines/glines.h
trusts/trusts.h
trusts/trusts_api.c
trusts/trusts_commands.c

index 794e612f1a091e6e4cab5912b1f070155373886c..584a731cff09686da8a30f71ffe888f1480714fb 100644 (file)
@@ -3,18 +3,40 @@
 #include "../trusts/trusts.h"
 #include "glines.h"
 
-void glinebynick(nick *np, int duration, char *reason) {
-  irc_send("%s GL * +%s@%s %d %jd :%s", mynumeric->content, istrusted(np)?np->ident:"*", IPtostr(np->p_ipaddr), duration, (intmax_t)getnettime(), reason);
+void glinebynick(nick *np, int duration, const char *reason) {
+  glinebyhost(np->ident, IPtostr(np->p_ipaddr), duration, reason);
 }
 
-void glinebyhost(char *ident, char *hostname, int duration, char *reason) {
-  /* TODO: resolve trustgroup and trustgline */
+void glinebyhost(const char *ident, const char *hostname, int duration, const char *reason) {
+  uint32_t ip;
+  short mask;
+  trusthost *th;
+
+  if(trusts_parsecidr(hostname, &ip, &mask)) {
+    th = th_getbyhost(ip);
+
+    if(th) {
+      trustgline(th->group, ident, duration, reason);
+      return;
+    }
+  }
 
   irc_send("%s GL * +%s@%s %d %jd :%s", mynumeric->content, ident, hostname, duration, (intmax_t)getnettime(), reason);
 }
 
-void unglinebyhost(char *ident, char *hostname, int duration, char *reason) {
-  /* TODO: trustungline */
+void unglinebyhost(const char *ident, const char *hostname, int duration, const char *reason) {
+  uint32_t ip;
+  short mask;
+  trusthost *th;
+
+  if(trusts_parsecidr(hostname, &ip, &mask)) {
+    th = th_getbyhost(ip);
+
+    if(th) {
+      trustungline(th->group, ident, duration, reason);
+      return;
+    }
+  }
 
   irc_send("%s GL * -%s@%s %d %jd :%s", mynumeric->content, ident, hostname, duration, (intmax_t)getnettime(), reason);
 }
index 29f554d4c16504b8251605169c2375ae75c9c024..d8d8948052d04bb5a30e54da5c2df8481cfff8e2 100644 (file)
@@ -1,8 +1,8 @@
 #ifndef __GLINES_H
 #define __GLINES_H
 
-void glinebynick(nick *, int, char *);
-void glinebyhost(char *, char *, int, char *);
-void unglinebyhost(char *, char *, int, char *);
+void glinebynick(nick *, int, const char *);
+void glinebyhost(const char *, const char *, int, const char *);
+void unglinebyhost(const char *, const char *, int, const char *);
 
 #endif
index 284163a5ae199f3cf2f44f6ae5e6824714a9da96..5ba72752a46e22207b72c7177283add25cbe91a7 100644 (file)
@@ -157,5 +157,7 @@ void trusts_lostnick(nick *, int);
 
 /* trusts_api.c */
 int istrusted(nick *);
+int trustgline(trustgroup *tg, const char *ident, int duration, const char *reason);
+int trustungline(trustgroup *tg, const char *ident, int duration, const char *reason);
 
 #endif
index 23fe063511d6702d96e6fdea6e19496055bf1e94..c23aa49c1053000b45e7e7754ae3a2e290939bb4 100644 (file)
@@ -1,6 +1,33 @@
 #include <../nick/nick.h>
+#include "../irc/irc.h"
 #include "trusts.h"
 
 int istrusted(nick *np) {
   return gettrusthost(np) != NULL;
 }
+
+int trustgline(trustgroup *tg, const char *ident, int duration, const char *reason) {
+  trusthost *th;
+  int count = 0;
+
+  for(th=tg->hosts;th;th=th->next) {
+    char *cidrstr = trusts_cidr2str(th->ip, th->mask);
+    irc_send("%s GL * +%s@%s %d %jd :%s", mynumeric->content, ident, cidrstr, duration, (intmax_t)getnettime(), reason);
+    count++;
+  }
+
+  return count;
+}
+
+int trustungline(trustgroup *tg, const char *ident, int duration, const char *reason) {
+  trusthost *th;
+  int count = 0;
+
+  for(th=tg->hosts;th;th=th->next) {
+    char *cidrstr = trusts_cidr2str(th->ip, th->mask);
+    irc_send("%s GL * +%s@%s %d %jd :%s", mynumeric->content, ident, cidrstr, duration, (intmax_t)getnettime(), reason);
+    count++;
+  }
+
+  return count;
+}
index 3750ff8a91325442c4607c544ebbfeda15f34d9c..a56a7780507ea57aa52baf100dd919cc79412246 100644 (file)
@@ -4,7 +4,6 @@
 #include "../lib/irc_string.h"
 #include "../lib/strlfunc.h"
 #include "../core/nsmalloc.h"
-#include "../irc/irc.h"
 #include "trusts.h"
 
 static void registercommands(int, void *);
@@ -262,8 +261,7 @@ static int trusts_cmdtrustgline(void *source, int cargc, char **cargv) {
   trustgroup *tg;
   nick *sender = source;
   char *user, *reason;
-  int duration, count = 0;
-  trusthost *th;
+  int duration, count;
 
   if(cargc < 4)
     return CMD_USAGE;
@@ -284,11 +282,7 @@ static int trusts_cmdtrustgline(void *source, int cargc, char **cargv) {
 
   reason = cargv[3];
 
-  for(th=tg->hosts;th;th=th->next) {
-    char *cidrstr = trusts_cidr2str(th->ip, th->mask);
-    irc_send("%s GL * +%s@%s %d %jd :%s", mynumeric->content, user, cidrstr, duration, (intmax_t)getnettime(), reason);
-    count++;
-  }
+  count = trustgline(tg, user, duration, reason);
 
   controlwall(NO_OPER, NL_GLINES|NL_TRUSTS, "%s TRUSTGLINE'd user '%s' on group '%s', %d gline(s) set.", controlid(sender), user, tg->name->content, count);
   controlreply(sender, "Done. %d gline(s) set.", count);
@@ -300,8 +294,7 @@ static int trusts_cmdtrustungline(void *source, int cargc, char **cargv) {
   trustgroup *tg;
   nick *sender = source;
   char *user, *reason;
-  int duration, count = 0;
-  trusthost *th;
+  int count;
 
   if(cargc < 2)
     return CMD_USAGE;
@@ -314,11 +307,7 @@ static int trusts_cmdtrustungline(void *source, int cargc, char **cargv) {
 
   user = cargv[1];
 
-  for(th=tg->hosts;th;th=th->next) {
-    char *cidrstr = trusts_cidr2str(th->ip, th->mask);
-    irc_send("%s GL * -%s@%s", mynumeric->content, user, cidrstr);
-    count++;
-  }
+  count = trustungline(tg, user, 0, "Deactivated.");
 
   controlwall(NO_OPER, NL_GLINES|NL_TRUSTS, "%s TRUSTUNGLINE'd user '%s' on group '%s', %d gline(s) removed.", controlid(sender), user, tg->name->content, count);
   controlreply(sender, "Done. %d gline(s) removed.", count);