]>
Commit | Line | Data |
---|---|---|
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 |
8 | static 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 | ||
3c5c26a8 | 21 | void glinesetmask(const char *mask, int duration, const char *reason, const char *creator) { |
5baa9510 | 22 | controlwall(NO_OPER, NL_GLINES, "(NOT) Setting gline on '%s' lasting %s with reason '%s', created by: %s", mask, longtoduration(duration, 0), reason, creator); |
3c5c26a8 | 23 | |
46b488b3 | 24 | #if 0 |
8f128e0d | 25 | irc_send("%s GL * +%s %d %jd :%s", mynumeric->content, mask, duration, (intmax_t)getnettime(), reason); |
46b488b3 | 26 | #endif |
813c5b73 CP |
27 | } |
28 | ||
ae8b0453 | 29 | void glineremovemask(const char *mask) { |
5baa9510 | 30 | controlwall(NO_OPER, NL_GLINES, "(NOT) Removing gline on '%s'.", mask); |
3c5c26a8 | 31 | |
46b488b3 | 32 | #if 0 |
ae8b0453 | 33 | irc_send("%s GL * -%s", mynumeric->content, mask); |
46b488b3 | 34 | #endif |
8f128e0d | 35 | } |
ac3af088 | 36 | |
8f128e0d | 37 | static void glinesetmask_cb(const char *mask, int hits, void *arg) { |
46b488b3 | 38 | gline_params *gp = arg; |
3c5c26a8 | 39 | glinesetmask(mask, gp->duration, gp->reason, gp->creator); |
8f128e0d | 40 | } |
a473a1be | 41 | |
8f128e0d GB |
42 | int glinesuggestbyip(const char *user, struct irc_in_addr *ip, unsigned char bits, int flags, gline_callback callback, void *uarg) { |
43 | trusthost *th, *oth; | |
44 | int count; | |
45 | unsigned char nodebits; | |
46 | ||
47 | nodebits = getnodebits(ip); | |
a473a1be GB |
48 | |
49 | if (!(flags & GLINE_IGNORE_TRUST)) { | |
8f128e0d | 50 | th = th_getbyhost(ip); |
ac3af088 | 51 | |
de723023 | 52 | if(th && (th->group->flags & TRUST_ENFORCE_IDENT)) { /* Trust with enforceident enabled */ |
8f128e0d GB |
53 | count = 0; |
54 | ||
55 | for(oth=th->group->hosts;oth;oth=oth->next) | |
56 | count += glinesuggestbyip(user, &oth->ip, oth->bits, flags | GLINE_ALWAYS_USER | GLINE_IGNORE_TRUST, callback, uarg); | |
57 | ||
58 | return count; | |
ac3af088 GB |
59 | } |
60 | } | |
813c5b73 | 61 | |
a473a1be | 62 | if (!(flags & GLINE_ALWAYS_USER)) |
8f128e0d | 63 | user = "*"; |
a473a1be | 64 | |
8f128e0d GB |
65 | /* Widen gline to match the node mask. */ |
66 | if(nodebits<bits) | |
67 | bits = nodebits; | |
a473a1be | 68 | |
8f128e0d GB |
69 | count = countmatchingusers(user, ip, bits); |
70 | ||
71 | if (!(flags & GLINE_SIMULATE)) { | |
72 | char mask[512]; | |
73 | snprintf(mask, sizeof(mask), "%s@%s", user, trusts_cidr2str(ip, bits)); | |
74 | callback(mask, count, uarg); | |
a473a1be GB |
75 | } |
76 | ||
a473a1be | 77 | return count; |
813c5b73 CP |
78 | } |
79 | ||
3c5c26a8 | 80 | int glinebyip(const char *user, struct irc_in_addr *ip, unsigned char bits, int duration, const char *reason, int flags, const char *creator) { |
8f128e0d | 81 | gline_params gp; |
8c45c18f GB |
82 | |
83 | if(!(flags & GLINE_SIMULATE)) { | |
84 | int hits = glinesuggestbyip(user, ip, bits, flags | GLINE_SIMULATE, NULL, NULL); | |
85 | if(hits>MAXGLINEUSERS) { | |
86 | controlwall(NO_OPER, NL_GLINES, "Suggested gline(s) for '%s@%s' lasting %s with reason '%s' would hit %d users (limit: %d) - NOT SET.", | |
87 | user, trusts_cidr2str(ip, bits), longtoduration(duration, 0), reason, hits, MAXGLINEUSERS); | |
88 | return 0; | |
89 | } | |
90 | } | |
91 | ||
8f128e0d GB |
92 | gp.duration = duration; |
93 | gp.reason = reason; | |
82a9536d | 94 | gp.creator = creator; |
8f128e0d GB |
95 | return glinesuggestbyip(user, ip, bits, flags, glinesetmask_cb, &gp); |
96 | } | |
ac3af088 | 97 | |
8f128e0d GB |
98 | int glinesuggestbynick(nick *np, int flags, void (*callback)(const char *, int, void *), void *uarg) { |
99 | if (flags & GLINE_ALWAYS_NICK) { | |
8c45c18f GB |
100 | if(!(flags & GLINE_SIMULATE)) { |
101 | char mask[512]; | |
102 | snprintf(mask, sizeof(mask), "%s!*@*", np->nick); | |
103 | callback(mask, 1, uarg); | |
104 | } | |
105 | ||
106 | return 1; | |
8f128e0d GB |
107 | } else { |
108 | return glinesuggestbyip(np->ident, &np->p_ipaddr, 128, flags, callback, uarg); | |
ac3af088 | 109 | } |
8f128e0d | 110 | } |
813c5b73 | 111 | |
3c5c26a8 | 112 | int glinebynick(nick *np, int duration, const char *reason, int flags, const char *creator) { |
8f128e0d | 113 | gline_params gp; |
8c45c18f GB |
114 | |
115 | if(!(flags & GLINE_SIMULATE)) { | |
116 | int hits = glinesuggestbyip(np->ident, &np->p_ipaddr, 128, flags | GLINE_SIMULATE, NULL, NULL); | |
117 | if(hits>MAXGLINEUSERS) { | |
118 | controlwall(NO_OPER, NL_GLINES, "Suggested gline(s) for nick '%s!%s@%s' lasting %s with reason '%s' would hit %d users (limit: %d) - NOT SET.", | |
29527e36 | 119 | np->nick, np->ident, IPtostr(np->p_ipaddr), longtoduration(duration, 0), reason, hits, MAXGLINEUSERS); |
8c45c18f GB |
120 | return 0; |
121 | } | |
122 | } | |
123 | ||
8f128e0d GB |
124 | gp.duration = duration; |
125 | gp.reason = reason; | |
3c5c26a8 | 126 | gp.creator = creator; |
8f128e0d | 127 | return glinesuggestbynick(np, flags, glinesetmask_cb, &gp); |
813c5b73 | 128 | } |