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