#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);
}
#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
/* 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
#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;
+}
#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 *);
trustgroup *tg;
nick *sender = source;
char *user, *reason;
- int duration, count = 0;
- trusthost *th;
+ int duration, count;
if(cargc < 4)
return CMD_USAGE;
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);
trustgroup *tg;
nick *sender = source;
char *user, *reason;
- int duration, count = 0;
- trusthost *th;
+ int count;
if(cargc < 2)
return CMD_USAGE;
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);