]>
Commit | Line | Data |
---|---|---|
1 | #include <stdio.h> | |
2 | #include "../lib/irc_string.h" | |
3 | #include "../lib/version.h" | |
4 | #include "../irc/irc.h" | |
5 | #include "../trusts/trusts.h" | |
6 | #include "../control/control.h" | |
7 | #include "glines.h" | |
8 | ||
9 | MODULE_VERSION(""); | |
10 | ||
11 | static int countmatchingusers(const char *identmask, struct irc_in_addr *ip, unsigned char bits) { | |
12 | nick *np; | |
13 | int i; | |
14 | int count = 0; | |
15 | ||
16 | for(i=0;i<NICKHASHSIZE;i++) | |
17 | for (np=nicktable[i];np;np=np->next) | |
18 | if (ipmask_check(&np->p_nodeaddr, ip, bits) && match2strings(identmask, np->ident)) | |
19 | count++; | |
20 | ||
21 | return count; | |
22 | } | |
23 | ||
24 | void glinesetmask(const char *mask, int duration, const char *reason, const char *creator) { | |
25 | if(strcmp(creator, "trusts_policy")==0) { | |
26 | controlwall(NO_OPER, NL_GLINES, "(NOT) Setting gline on '%s' lasting %s with reason '%s', created by: %s", mask, longtoduration(duration, 0), reason, creator); | |
27 | return; | |
28 | } | |
29 | ||
30 | controlwall(NO_OPER, NL_GLINES, "Setting gline on '%s' lasting %s with reason '%s', created by: %s", mask, longtoduration(duration, 0), reason, creator); | |
31 | irc_send("%s GL * +%s %d %jd :%s", mynumeric->content, mask, duration, (intmax_t)getnettime(), reason); | |
32 | } | |
33 | ||
34 | void glineremovemask(const char *mask) { | |
35 | controlwall(NO_OPER, NL_GLINES, "Removing gline on '%s'.", mask); | |
36 | irc_send("%s GL * -%s", mynumeric->content, mask); | |
37 | } | |
38 | ||
39 | static void glinesetmask_cb(const char *mask, int hits, void *arg) { | |
40 | gline_params *gp = arg; | |
41 | glinesetmask(mask, gp->duration, gp->reason, gp->creator); | |
42 | } | |
43 | ||
44 | int glinesuggestbyip(const char *user, struct irc_in_addr *ip, unsigned char bits, int flags, gline_callback callback, void *uarg) { | |
45 | trusthost *th, *oth; | |
46 | int count; | |
47 | unsigned char nodebits; | |
48 | ||
49 | nodebits = getnodebits(ip); | |
50 | ||
51 | if (!(flags & GLINE_IGNORE_TRUST)) { | |
52 | th = th_getbyhost(ip); | |
53 | ||
54 | if(th && (th->group->flags & TRUST_RELIABLE_USERNAME)) { /* Trust with reliable usernames */ | |
55 | count = 0; | |
56 | ||
57 | for(oth=th->group->hosts;oth;oth=oth->next) | |
58 | count += glinesuggestbyip(user, &oth->ip, oth->bits, flags | GLINE_ALWAYS_USER | GLINE_IGNORE_TRUST, callback, uarg); | |
59 | ||
60 | return count; | |
61 | } | |
62 | } | |
63 | ||
64 | if (!(flags & GLINE_ALWAYS_USER)) | |
65 | user = "*"; | |
66 | ||
67 | /* Widen gline to match the node mask. */ | |
68 | if(nodebits<bits) | |
69 | bits = nodebits; | |
70 | ||
71 | count = countmatchingusers(user, ip, bits); | |
72 | ||
73 | if (!(flags & GLINE_SIMULATE)) { | |
74 | char mask[512]; | |
75 | snprintf(mask, sizeof(mask), "%s@%s", user, trusts_cidr2str(ip, bits)); | |
76 | callback(mask, count, uarg); | |
77 | } | |
78 | ||
79 | return count; | |
80 | } | |
81 | ||
82 | int glinebyip(const char *user, struct irc_in_addr *ip, unsigned char bits, int duration, const char *reason, int flags, const char *creator) { | |
83 | gline_params gp; | |
84 | ||
85 | if(!(flags & GLINE_SIMULATE)) { | |
86 | int hits = glinesuggestbyip(user, ip, bits, flags | GLINE_SIMULATE, NULL, NULL); | |
87 | if(hits>MAXGLINEUSERS) { | |
88 | controlwall(NO_OPER, NL_GLINES, "Suggested gline(s) for '%s@%s' lasting %s with reason '%s' would hit %d users (limit: %d) - NOT SET.", | |
89 | user, trusts_cidr2str(ip, bits), longtoduration(duration, 0), reason, hits, MAXGLINEUSERS); | |
90 | return 0; | |
91 | } | |
92 | } | |
93 | ||
94 | gp.duration = duration; | |
95 | gp.reason = reason; | |
96 | gp.creator = creator; | |
97 | return glinesuggestbyip(user, ip, bits, flags, glinesetmask_cb, &gp); | |
98 | } | |
99 | ||
100 | int glinesuggestbynick(nick *np, int flags, void (*callback)(const char *, int, void *), void *uarg) { | |
101 | if (flags & GLINE_ALWAYS_NICK) { | |
102 | if(!(flags & GLINE_SIMULATE)) { | |
103 | char mask[512]; | |
104 | snprintf(mask, sizeof(mask), "%s!*@*", np->nick); | |
105 | callback(mask, 1, uarg); | |
106 | } | |
107 | ||
108 | return 1; | |
109 | } else { | |
110 | return glinesuggestbyip(np->ident, &np->p_ipaddr, 128, flags, callback, uarg); | |
111 | } | |
112 | } | |
113 | ||
114 | int glinebynick(nick *np, int duration, const char *reason, int flags, const char *creator) { | |
115 | gline_params gp; | |
116 | ||
117 | if(!(flags & GLINE_SIMULATE)) { | |
118 | int hits = glinesuggestbyip(np->ident, &np->p_ipaddr, 128, flags | GLINE_SIMULATE, NULL, NULL); | |
119 | if(hits>MAXGLINEUSERS) { | |
120 | 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.", | |
121 | np->nick, np->ident, IPtostr(np->p_ipaddr), longtoduration(duration, 0), reason, hits, MAXGLINEUSERS); | |
122 | return 0; | |
123 | } | |
124 | } | |
125 | ||
126 | gp.duration = duration; | |
127 | gp.reason = reason; | |
128 | gp.creator = creator; | |
129 | return glinesuggestbynick(np, flags, glinesetmask_cb, &gp); | |
130 | } |