]> jfr.im git - irc/quakenet/newserv.git/blame - trusts/trusts_policy.c
Remove fake user if they can't reconnect.
[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
b9cafbd9
CP
18 if(!th) {
19 if(np->ipnode->usercount > 5)
148db7b8 20 controlwall(NO_OPER, NL_TRUSTS, "Hard connection limit exceeded on IP: %s (untrusted) %d connected, 5 max.", IPtostr(np->p_ipaddr), np->ipnode->usercount);
b9cafbd9
CP
21 return;
22 }
23
24 tg = th->group;
2129448c
CP
25 /*
26 * the purpose of this logic is to avoid spam like this:
27 * WARNING: tgX exceeded limit: 11 connected vs 10 max
28 * (goes back down to 10)
29 * WARNING: tgX exceeded limit: 11 connected vs 10 max
30 */
31
32 if(hooknum == HOOK_TRUSTS_NEWNICK) {
148db7b8
CP
33 if(tg->count > tg->trustedfor) {
34/*
2129448c 35 if(tg->count > (long)tg->exts[countext]) {
148db7b8 36
2129448c 37 tg->exts[countext] = (void *)(long)tg->count;
148db7b8
CP
38*/
39 controlwall(NO_OPER, NL_TRUSTS, "Hard connection limit exceeded: '%s', %d connected, %d max.", tg->name->content, tg->count, tg->trustedfor);
40 }
41/*
42 }
43*/
44 if((tg->mode == 1) && (np->ident[0] == '~'))
45 controlwall(NO_OPER, NL_TRUSTS, "Ident required: '%s' %s!%s@%s.", tg->name->content, np->nick, np->ident, np->host->name->content);
2129448c 46
148db7b8
CP
47 if(tg->maxperident > 0) {
48 int identcount = 0;
49 trusthost *th2;
50 nick *tnp;
51
52 for(th2=tg->hosts;th2;th2=th2->next) {
53 for(tnp=th2->users;tnp;tnp=nextbytrust(tnp)) {
54 if(!ircd_strcmp(tnp->ident, np->ident))
55 identcount++;
56 }
2129448c 57 }
148db7b8
CP
58
59 if(identcount > tg->maxperident)
bc97b768 60 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
61 }
62 } else {
63 if(tg->count < tg->maxusage)
64 tg->exts[countext] = (void *)(long)tg->count;
65 }
cfe0e8e4
CP
66}
67
68void _init(void) {
2129448c
CP
69 countext = registertgext("count");
70 if(countext == -1)
71 return;
72
cfe0e8e4 73 registerhook(HOOK_TRUSTS_NEWNICK, policycheck);
2129448c 74 registerhook(HOOK_TRUSTS_LOSTNICK, policycheck);
cfe0e8e4
CP
75}
76
77void _fini(void) {
2129448c
CP
78 if(countext == -1)
79 return;
80
81 releasetgext(countext);
82
cfe0e8e4 83 deregisterhook(HOOK_TRUSTS_NEWNICK, policycheck);
2129448c 84 deregisterhook(HOOK_TRUSTS_LOSTNICK, policycheck);
cfe0e8e4 85}