]> jfr.im git - irc/quakenet/newserv.git/blame - glines/glines.c
Implement nocleanup attribute for TGs.
[irc/quakenet/newserv.git] / glines / glines.c
CommitLineData
a473a1be 1#include "../lib/irc_string.h"
813c5b73 2#include "../irc/irc.h"
813c5b73 3#include "../trusts/trusts.h"
a473a1be 4#include "../control/control.h"
813c5b73
CP
5#include "glines.h"
6
a473a1be
GB
7static int countmatchingusers(const char *identmask, struct irc_in_addr *ip, unsigned char bits) {
8 nick *np;
9 int i;
10 int count = 0;
11
12 for(i=0;i<NICKHASHSIZE;i++)
13 for (np=nicktable[i];np;np=np->next)
14 if (ipmask_check(&np->p_nodeaddr, ip, bits) && match2strings(identmask, np->ident))
15 count++;
16
17 return count;
18}
19
20int glinebynick(nick *np, int duration, const char *reason, int flags) {
21 return glinebyhost(np->ident, IPtostr(np->p_ipaddr), duration, reason, flags);
813c5b73
CP
22}
23
a473a1be 24int glinebyhost(const char *ident, const char *hostname, int duration, const char *reason, int flags) {
91215aff
GB
25 struct irc_in_addr ip;
26 unsigned char bits;
ac3af088 27 trusthost *th;
a473a1be 28 int count;
ac3af088 29
a473a1be
GB
30 if(flags & GLINE_SIMULATE)
31 return -1; /* TODO */
32
33 if(!ipmask_parse(hostname, &ip, NULL)) {
34 irc_send("%s GL * +%s@%s %d %jd :%s", mynumeric->content, ident, hostname, duration, (intmax_t)getnettime(), reason);
35 return 0;
36 }
37
38 bits = getnodebits(&ip);
39
40 if (!(flags & GLINE_IGNORE_TRUST)) {
91215aff 41 th = th_getbyhost(&ip);
ac3af088 42
de723023 43 if(th && (th->group->flags & TRUST_ENFORCE_IDENT)) { /* Trust with enforceident enabled */
ac3af088 44 trustgline(th->group, ident, duration, reason);
a473a1be 45 return 0;
ac3af088
GB
46 }
47 }
813c5b73 48
a473a1be
GB
49 if (!(flags & GLINE_ALWAYS_USER))
50 ident = "*";
51
52 count = countmatchingusers(ident, &ip, bits);
53
54 if (!(flags & MAXGLINEUSERS) && count>MAXGLINEUSERS) {
55 controlwall(NO_OPER, NL_GLINES, "Attempted to set gline on %s@%s: Would match %d users (limit: %d)- not set.", ident, trusts_cidr2str(&ip, bits), count, MAXGLINEUSERS);
56 return -1;
57 }
58
59 irc_send("%s GL * +%s@%s %d %jd :%s", mynumeric->content, ident, trusts_cidr2str(&ip, bits), duration, (intmax_t)getnettime(), reason);
60 return count;
813c5b73
CP
61}
62
a473a1be 63void unglinebyhost(const char *ident, const char *hostname, int duration, const char *reason, int flags) {
91215aff
GB
64 struct irc_in_addr ip;
65 unsigned char bits;
ac3af088
GB
66 trusthost *th;
67
a473a1be
GB
68 if(!ipmask_parse(hostname, &ip, &bits)) {
69 irc_send("%s GL * -%s@%s %d %jd :%s", mynumeric->content, ident, hostname, duration, (intmax_t)getnettime(), reason);
70 return;
71 }
72
73 bits = getnodebits(&ip);
74
75 if (!(flags & GLINE_IGNORE_TRUST)) {
91215aff 76 th = th_getbyhost(&ip);
ac3af088 77
a473a1be
GB
78 if(th && th->group->mode) { /* Trust with enforceident enabled */
79 trustgline(th->group, ident, duration, reason);
ac3af088
GB
80 return;
81 }
82 }
813c5b73 83
a473a1be
GB
84 if (!(flags & GLINE_ALWAYS_USER))
85 ident = "*";
86
87 irc_send("%s GL * -%s@%s %d %jd :%s", mynumeric->content, ident, trusts_cidr2str(&ip, bits), duration, (intmax_t)getnettime(), reason);
813c5b73 88}