]> jfr.im git - irc/quakenet/newserv.git/blame - trusts/trusts_policy.c
Fixed maxpernode policy enforcement.
[irc/quakenet/newserv.git] / trusts / trusts_policy.c
CommitLineData
cfe0e8e4
CP
1#include "../core/hooks.h"
2#include "../control/control.h"
148db7b8 3#include "../lib/irc_string.h"
cfe0e8e4
CP
4#include "trusts.h"
5
2129448c
CP
6static int countext;
7
cfe0e8e4 8static void policycheck(int hooknum, void *arg) {
9097ab05
CP
9 void **args = arg;
10 nick *np = args[0];
11 long moving = (long)args[1];
cfe0e8e4 12 trusthost *th = gettrusthost(np);
c2cc7b4c 13 trustgroup *tg;
cfe0e8e4 14
9097ab05
CP
15 if(moving)
16 return;
17
cebc4cab
GB
18 if(!th)
19 return;
20
6e6e98da
GB
21 tg = th->group;
22
23 if(th->maxpernode && np->ipnode->usercount > th->maxpernode) {
ee303647 24 controlwall(NO_OPER, NL_TRUSTS, "Hard connection limit exceeded on IP: %s (group: %s) %d connected, %d max.", IPtostr(np->p_ipaddr), tg->name->content, np->ipnode->usercount, th->maxpernode);
b9cafbd9
CP
25 return;
26 }
27
2129448c
CP
28 /*
29 * the purpose of this logic is to avoid spam like this:
30 * WARNING: tgX exceeded limit: 11 connected vs 10 max
31 * (goes back down to 10)
32 * WARNING: tgX exceeded limit: 11 connected vs 10 max
33 */
34
35 if(hooknum == HOOK_TRUSTS_NEWNICK) {
148db7b8
CP
36 if(tg->count > tg->trustedfor) {
37/*
2129448c 38 if(tg->count > (long)tg->exts[countext]) {
148db7b8 39
2129448c 40 tg->exts[countext] = (void *)(long)tg->count;
148db7b8
CP
41*/
42 controlwall(NO_OPER, NL_TRUSTS, "Hard connection limit exceeded: '%s', %d connected, %d max.", tg->name->content, tg->count, tg->trustedfor);
43 }
44/*
45 }
46*/
47 if((tg->mode == 1) && (np->ident[0] == '~'))
48 controlwall(NO_OPER, NL_TRUSTS, "Ident required: '%s' %s!%s@%s.", tg->name->content, np->nick, np->ident, np->host->name->content);
2129448c 49
148db7b8
CP
50 if(tg->maxperident > 0) {
51 int identcount = 0;
52 trusthost *th2;
53 nick *tnp;
54
55 for(th2=tg->hosts;th2;th2=th2->next) {
56 for(tnp=th2->users;tnp;tnp=nextbytrust(tnp)) {
57 if(!ircd_strcmp(tnp->ident, np->ident))
58 identcount++;
59 }
2129448c 60 }
148db7b8
CP
61
62 if(identcount > tg->maxperident)
bc97b768 63 controlwall(NO_OPER, NL_TRUSTS, "Hard ident limit exceeded: '%s' %s!%s@%s, %d connected, %d max.", tg->name->content, np->nick, np->ident, np->host->name->content, identcount, tg->maxperident);
2129448c
CP
64 }
65 } else {
66 if(tg->count < tg->maxusage)
67 tg->exts[countext] = (void *)(long)tg->count;
68 }
cfe0e8e4
CP
69}
70
71void _init(void) {
2129448c
CP
72 countext = registertgext("count");
73 if(countext == -1)
74 return;
75
cfe0e8e4 76 registerhook(HOOK_TRUSTS_NEWNICK, policycheck);
2129448c 77 registerhook(HOOK_TRUSTS_LOSTNICK, policycheck);
cfe0e8e4
CP
78}
79
80void _fini(void) {
2129448c
CP
81 if(countext == -1)
82 return;
83
84 releasetgext(countext);
85
cfe0e8e4 86 deregisterhook(HOOK_TRUSTS_NEWNICK, policycheck);
2129448c 87 deregisterhook(HOOK_TRUSTS_LOSTNICK, policycheck);
cfe0e8e4 88}