]>
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 GB |
21 | void glinesetmask(const char *mask, int duration, const char *reason, const char *creator) { |
22 | controlwall(NO_OPER, NL_GLINES, "Setting gline on '%s' lasting %s with reason '%s', created by: %s", mask, longtoduration(duration, 0), reason, creator); | |
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) { |
3c5c26a8 GB |
30 | controlwall(NO_OPER, NL_GLINES, "Removing gline on '%s'.", mask); |
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; | |
94 | return glinesuggestbyip(user, ip, bits, flags, glinesetmask_cb, &gp); | |
95 | } | |
ac3af088 | 96 | |
8f128e0d GB |
97 | int glinesuggestbynick(nick *np, int flags, void (*callback)(const char *, int, void *), void *uarg) { |
98 | if (flags & GLINE_ALWAYS_NICK) { | |
8c45c18f GB |
99 | if(!(flags & GLINE_SIMULATE)) { |
100 | char mask[512]; | |
101 | snprintf(mask, sizeof(mask), "%s!*@*", np->nick); | |
102 | callback(mask, 1, uarg); | |
103 | } | |
104 | ||
105 | return 1; | |
8f128e0d GB |
106 | } else { |
107 | return glinesuggestbyip(np->ident, &np->p_ipaddr, 128, flags, callback, uarg); | |
ac3af088 | 108 | } |
8f128e0d | 109 | } |
813c5b73 | 110 | |
3c5c26a8 | 111 | int glinebynick(nick *np, int duration, const char *reason, int flags, const char *creator) { |
8f128e0d | 112 | gline_params gp; |
8c45c18f GB |
113 | |
114 | if(!(flags & GLINE_SIMULATE)) { | |
115 | int hits = glinesuggestbyip(np->ident, &np->p_ipaddr, 128, flags | GLINE_SIMULATE, NULL, NULL); | |
116 | if(hits>MAXGLINEUSERS) { | |
117 | 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 | 118 | np->nick, np->ident, IPtostr(np->p_ipaddr), longtoduration(duration, 0), reason, hits, MAXGLINEUSERS); |
8c45c18f GB |
119 | return 0; |
120 | } | |
121 | } | |
122 | ||
8f128e0d GB |
123 | gp.duration = duration; |
124 | gp.reason = reason; | |
3c5c26a8 | 125 | gp.creator = creator; |
8f128e0d | 126 | return glinesuggestbynick(np, flags, glinesetmask_cb, &gp); |
813c5b73 | 127 | } |