]> jfr.im git - irc/quakenet/newserv.git/blame - trusts2/trusts_handlers.c
Merge.
[irc/quakenet/newserv.git] / trusts2 / trusts_handlers.c
CommitLineData
e2527cba
P
1#include "trusts.h"
2
3void trusts_hook_newuser(int hook, void *arg) {
4 /*TODO: add subnet clone warnings somewhere */
5 nick *np = (nick *)arg;
6 trusthost_t *tgh = NULL;
7 trustgroup_t *tg = NULL;
8 patricia_node_t *parent;
9
4f2ce270
P
10 if (trusts_ignore_np(np)) {
11 return;
12 }
13
e2527cba
P
14 if(np->ipnode->exts[tgh_ext]) {
15 /* we have a new user on a trust group host */
16 tgh = (trusthost_t *)np->ipnode->exts[tgh_ext];
17 /* check if it has expired */
18 if(tgh->expire && (tgh->expire <= getnettime())) {
19 trusthost_expire(tgh);
20 tgh = NULL;
21 } else {
22 tg = tgh->trustgroup;
23 if(tg->expire && (tg->expire <= getnettime())) {
24 /* expire trust group */
25 trustgroup_expire(tg);
26 tgh = NULL;
27 }
28 }
29 }
30
31 if (!tgh) {
32 /* recurse to see if a parent node is trusted */
33 parent = np->ipnode->parent;
34 while (parent) {
35 if(parent->exts)
36 if( parent->exts[tgh_ext]) {
37 /* falls under parent trust */
38 tgh = (trusthost_t *)parent->exts[tgh_ext];
39 if(tgh->expire && (tgh->expire <= getnettime())) {
40 trusthost_expire(tgh);
41 tgh = NULL;
42 } else {
43 tg = tgh->trustgroup;
44 if(tg->expire && (tg->expire <= getnettime())) {
45 /* expire trust group */
46 trustgroup_expire(tg);
47 tgh = NULL;
48 } else {
49 break;
50 }
51 }
52 }
53 parent = parent->parent;
54 }
55 }
56
57 if(tgh) {
58 /* we have a trusthost - check it */
59 tg = tgh->trustgroup;
60 if(((((int)(np->ipnode->usercount))) > tg->maxperip) && tg->maxperip ) {
61 /* user exceed ip trust limit - disconnect */
9a8ffb84 62 controlwall(NO_OPER, NL_TRUSTS, "TG %lu: Exceeding IP limit (%d / %d) for %s!%s@%s (%s)", tg->id, (((int)(np->ipnode->usercount))), tg->maxperip, np->nick, np->ident, np->host->name->content, removeusers == 1 ? "disconnected": "ignored");
e2527cba
P
63 //killuser(NULL, np, "USER: Exceeding IP Limit.");
64 }
65 if( tg->maxclones >0 ) {
66 if( (tg->currenton + 1) > tg->maxclones) {
67 /* user exceeds trust group limit - disconnect */
68 //killuser(NULL, np, "USER: Exceeding Trustgroup Limit.");
9a8ffb84 69 controlwall(NO_OPER, NL_TRUSTS, "TG %lu: Exceeding trustgroup limit (%d / %d) for %s!%s@%s (%s)",tg->id, (tg->currenton + 1), tg->maxclones, np->nick, np->ident, np->host->name->content, removeusers == 1 ? "disconnected": "ignored");
e2527cba
P
70 }
71 }
72 if ( np->ident[0] == '~') {
73 /* non-ident user */
74 if (tg->enforceident ) {
9a8ffb84 75 controlwall(NO_OPER, NL_TRUSTS, "TG %lu: Ident Required for %s!%s@%s (%s)", tg->id, np->nick, np->ident, np->host->name->content, removeusers == 1 ? "disconnected": "ignored");
e2527cba
P
76 //killuser(NULL, np, "USER: Ident Required From Your Host.");
77 /*TODO: add short gline here - ~*@%s - "IDENTD required from your host", "MissingIDENT" */
78 }
79 } else {
80 /* ident user */
81 /*TODO: need to tidy out ident currenton */
82 increment_ident_count(np, tg);
83 }
84 /* Trust Checks Passed: OK - increment counters */
85 increment_trust_ipnode(np->ipnode);
4f2ce270
P
86
87 /* set nick extension for user for future use */
88 np->exts[tgn_ext] = tgh;
89
e2527cba
P
90 return;
91 }
92 /* non trusted user - OK */
93}
94
95
96void trusts_hook_lostuser(int hook, void *arg) {
97 nick *np = (nick *)arg;
98 trusthost_t *tgh = NULL;
99 trustgroup_t *tg = NULL;
100 patricia_node_t *parent;
101
102 if(!np) {
103 Error("nodecount", ERR_ERROR, "np was NULL");
104 }
105 if(!np->ipnode) {
106 Error("nodecount", ERR_ERROR, "np->ipnode was NULL");
107 }
108 if(!np->ipnode->exts) {
109 Error("nodecount", ERR_ERROR, "np->ipnode->exts was NULL");
110 }
111
4f2ce270
P
112 if (trusts_ignore_np(np)) {
113 return;
114 }
115
e2527cba
P
116 decrement_trust_ipnode(np->ipnode);
117
118 if(np->ipnode->exts[tgh_ext]) {
119 tgh = (trusthost_t *)np->ipnode->exts[tgh_ext];
120 } else {
121 parent = np->ipnode->parent;
122 while (parent) {
123 if(parent->exts)
124 if( parent->exts[tgh_ext]) {
125 /* falls under parent trust */
126 tgh = (trusthost_t *)parent->exts[tgh_ext];
127 break;
128 }
129 parent = parent->parent;
130 }
131 }
132 if(tgh) {
133 tg = tgh->trustgroup;
134 if ( np->ident[0] != '~') {
135 decrement_ident_count(np, tg);
136 }
137 }
4f2ce270
P
138
139 /* clear nick extension */
140 np->exts[tgn_ext] = NULL;
e2527cba
P
141}
142