]> jfr.im git - irc/quakenet/newserv.git/blob - trusts/trusts_policy.c
Should probably say which user is violating the ident limit.
[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 if(np->ipnode->usercount > 5)
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);
21 return;
22 }
23
24 tg = th->group;
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) {
33 if(tg->count > tg->trustedfor) {
34 /*
35 if(tg->count > (long)tg->exts[countext]) {
36
37 tg->exts[countext] = (void *)(long)tg->count;
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);
46
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 }
57 }
58
59 if(identcount > tg->maxperident)
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);
61 }
62 } else {
63 if(tg->count < tg->maxusage)
64 tg->exts[countext] = (void *)(long)tg->count;
65 }
66 }
67
68 void _init(void) {
69 countext = registertgext("count");
70 if(countext == -1)
71 return;
72
73 registerhook(HOOK_TRUSTS_NEWNICK, policycheck);
74 registerhook(HOOK_TRUSTS_LOSTNICK, policycheck);
75 }
76
77 void _fini(void) {
78 if(countext == -1)
79 return;
80
81 releasetgext(countext);
82
83 deregisterhook(HOOK_TRUSTS_NEWNICK, policycheck);
84 deregisterhook(HOOK_TRUSTS_LOSTNICK, policycheck);
85 }