]> jfr.im git - irc/quakenet/newserv.git/blame - glines/glines.c
Make TRUST_RELIABLE_USERNAME a user-settable option.
[irc/quakenet/newserv.git] / glines / glines.c
CommitLineData
8f128e0d 1#include <stdio.h>
a473a1be 2#include "../lib/irc_string.h"
c4610da5 3#include "../lib/version.h"
813c5b73 4#include "../irc/irc.h"
813c5b73 5#include "../trusts/trusts.h"
a473a1be 6#include "../control/control.h"
813c5b73
CP
7#include "glines.h"
8
c4610da5
GB
9MODULE_VERSION("");
10
a473a1be
GB
11static 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
3c5c26a8 24void glinesetmask(const char *mask, int duration, const char *reason, const char *creator) {
3057daed
GB
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 }
3c5c26a8 29
3057daed 30 controlwall(NO_OPER, NL_GLINES, "Setting gline on '%s' lasting %s with reason '%s', created by: %s", mask, longtoduration(duration, 0), reason, creator);
8f128e0d 31 irc_send("%s GL * +%s %d %jd :%s", mynumeric->content, mask, duration, (intmax_t)getnettime(), reason);
813c5b73
CP
32}
33
ae8b0453 34void glineremovemask(const char *mask) {
3057daed 35 controlwall(NO_OPER, NL_GLINES, "Removing gline on '%s'.", mask);
ae8b0453 36 irc_send("%s GL * -%s", mynumeric->content, mask);
8f128e0d 37}
ac3af088 38
8f128e0d 39static void glinesetmask_cb(const char *mask, int hits, void *arg) {
46b488b3 40 gline_params *gp = arg;
3c5c26a8 41 glinesetmask(mask, gp->duration, gp->reason, gp->creator);
8f128e0d 42}
a473a1be 43
8f128e0d
GB
44int 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);
a473a1be
GB
50
51 if (!(flags & GLINE_IGNORE_TRUST)) {
8f128e0d 52 th = th_getbyhost(ip);
ac3af088 53
3a8c35c9 54 if(th && (th->group->flags & TRUST_RELIABLE_USERNAME)) { /* Trust with reliable usernames */
8f128e0d
GB
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;
ac3af088
GB
61 }
62 }
813c5b73 63
a473a1be 64 if (!(flags & GLINE_ALWAYS_USER))
8f128e0d 65 user = "*";
a473a1be 66
8f128e0d
GB
67 /* Widen gline to match the node mask. */
68 if(nodebits<bits)
69 bits = nodebits;
a473a1be 70
8f128e0d
GB
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);
a473a1be
GB
77 }
78
a473a1be 79 return count;
813c5b73
CP
80}
81
3c5c26a8 82int glinebyip(const char *user, struct irc_in_addr *ip, unsigned char bits, int duration, const char *reason, int flags, const char *creator) {
8f128e0d 83 gline_params gp;
8c45c18f
GB
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
8f128e0d
GB
94 gp.duration = duration;
95 gp.reason = reason;
82a9536d 96 gp.creator = creator;
8f128e0d
GB
97 return glinesuggestbyip(user, ip, bits, flags, glinesetmask_cb, &gp);
98}
ac3af088 99
8f128e0d
GB
100int glinesuggestbynick(nick *np, int flags, void (*callback)(const char *, int, void *), void *uarg) {
101 if (flags & GLINE_ALWAYS_NICK) {
8c45c18f
GB
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;
8f128e0d
GB
109 } else {
110 return glinesuggestbyip(np->ident, &np->p_ipaddr, 128, flags, callback, uarg);
ac3af088 111 }
8f128e0d 112}
813c5b73 113
3c5c26a8 114int glinebynick(nick *np, int duration, const char *reason, int flags, const char *creator) {
8f128e0d 115 gline_params gp;
8c45c18f
GB
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.",
29527e36 121 np->nick, np->ident, IPtostr(np->p_ipaddr), longtoduration(duration, 0), reason, hits, MAXGLINEUSERS);
8c45c18f
GB
122 return 0;
123 }
124 }
125
8f128e0d
GB
126 gp.duration = duration;
127 gp.reason = reason;
3c5c26a8 128 gp.creator = creator;
8f128e0d 129 return glinesuggestbynick(np, flags, glinesetmask_cb, &gp);
813c5b73 130}