]> jfr.im git - irc/quakenet/newserv.git/blame - glines/glines.c
Glines: Make the test warning more obvious.
[irc/quakenet/newserv.git] / glines / glines.c
CommitLineData
8f128e0d 1#include <stdio.h>
a473a1be 2#include "../lib/irc_string.h"
813c5b73 3#include "../irc/irc.h"
813c5b73 4#include "../trusts/trusts.h"
a473a1be 5#include "../control/control.h"
813c5b73
CP
6#include "glines.h"
7
a473a1be
GB
8static int countmatchingusers(const char *identmask, struct irc_in_addr *ip, unsigned char bits) {
9 nick *np;
10 int i;
11 int count = 0;
12
13 for(i=0;i<NICKHASHSIZE;i++)
14 for (np=nicktable[i];np;np=np->next)
15 if (ipmask_check(&np->p_nodeaddr, ip, bits) && match2strings(identmask, np->ident))
16 count++;
17
18 return count;
19}
20
8f128e0d
GB
21void glinesetmask(const char *mask, int duration, const char *reason) {
22 irc_send("%s GL * +%s %d %jd :%s", mynumeric->content, mask, duration, (intmax_t)getnettime(), reason);
813c5b73
CP
23}
24
8f128e0d
GB
25void glineremovemask(const char *mask, int duration, const char *reason) {
26 irc_send("%s GL * -%s %d %jd :%s", mynumeric->content, mask, duration, (intmax_t)getnettime(), reason);
27}
ac3af088 28
8f128e0d 29static void glinesetmask_cb(const char *mask, int hits, void *arg) {
5a95d7ab 30 controlwall(NO_OPER, NL_GLINES, "Would set gline on '%s' (hits: %d). CURRENTLY DISABLED FOR TESTING PURPOSES.", mask, hits);
a473a1be 31
8f128e0d
GB
32/* gline_params *gp = arg;
33 glinesetmask(mask, gp->duration, gp->reason);*/
34}
a473a1be 35
8f128e0d
GB
36int glinesuggestbyip(const char *user, struct irc_in_addr *ip, unsigned char bits, int flags, gline_callback callback, void *uarg) {
37 trusthost *th, *oth;
38 int count;
39 unsigned char nodebits;
40
41 nodebits = getnodebits(ip);
a473a1be
GB
42
43 if (!(flags & GLINE_IGNORE_TRUST)) {
8f128e0d 44 th = th_getbyhost(ip);
ac3af088 45
de723023 46 if(th && (th->group->flags & TRUST_ENFORCE_IDENT)) { /* Trust with enforceident enabled */
8f128e0d
GB
47 count = 0;
48
49 for(oth=th->group->hosts;oth;oth=oth->next)
50 count += glinesuggestbyip(user, &oth->ip, oth->bits, flags | GLINE_ALWAYS_USER | GLINE_IGNORE_TRUST, callback, uarg);
51
52 return count;
ac3af088
GB
53 }
54 }
813c5b73 55
a473a1be 56 if (!(flags & GLINE_ALWAYS_USER))
8f128e0d 57 user = "*";
a473a1be 58
8f128e0d
GB
59 /* Widen gline to match the node mask. */
60 if(nodebits<bits)
61 bits = nodebits;
a473a1be 62
8f128e0d
GB
63 count = countmatchingusers(user, ip, bits);
64
65 if (!(flags & GLINE_SIMULATE)) {
66 char mask[512];
67 snprintf(mask, sizeof(mask), "%s@%s", user, trusts_cidr2str(ip, bits));
68 callback(mask, count, uarg);
a473a1be
GB
69 }
70
a473a1be 71 return count;
813c5b73
CP
72}
73
8f128e0d
GB
74int glinebyip(const char *user, struct irc_in_addr *ip, unsigned char bits, int duration, const char *reason, int flags) {
75 gline_params gp;
76 gp.duration = duration;
77 gp.reason = reason;
78 return glinesuggestbyip(user, ip, bits, flags, glinesetmask_cb, &gp);
79}
ac3af088 80
8f128e0d
GB
81int glinesuggestbynick(nick *np, int flags, void (*callback)(const char *, int, void *), void *uarg) {
82 if (flags & GLINE_ALWAYS_NICK) {
83 char mask[512];
84 snprintf(mask, sizeof(mask), "%s!*@*", np->nick);
85 callback(mask, 1, uarg); /* TODO: figure out if user was online. */
86 return 1; /* TODO: figure out if user was online. */
87 } else {
88 return glinesuggestbyip(np->ident, &np->p_ipaddr, 128, flags, callback, uarg);
ac3af088 89 }
8f128e0d 90}
813c5b73 91
8f128e0d
GB
92int glinebynick(nick *np, int duration, const char *reason, int flags) {
93 gline_params gp;
94 gp.duration = duration;
95 gp.reason = reason;
96 return glinesuggestbynick(np, flags, glinesetmask_cb, &gp);
813c5b73 97}