]>
Commit | Line | Data |
---|---|---|
e2527cba P |
1 | #include "trusts.h" |
2 | ||
3 | void 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 | ||
10 | if(np->ipnode->exts[tgh_ext]) { | |
11 | /* we have a new user on a trust group host */ | |
12 | tgh = (trusthost_t *)np->ipnode->exts[tgh_ext]; | |
13 | /* check if it has expired */ | |
14 | if(tgh->expire && (tgh->expire <= getnettime())) { | |
15 | trusthost_expire(tgh); | |
16 | tgh = NULL; | |
17 | } else { | |
18 | tg = tgh->trustgroup; | |
19 | if(tg->expire && (tg->expire <= getnettime())) { | |
20 | /* expire trust group */ | |
21 | trustgroup_expire(tg); | |
22 | tgh = NULL; | |
23 | } | |
24 | } | |
25 | } | |
26 | ||
27 | if (!tgh) { | |
28 | /* recurse to see if a parent node is trusted */ | |
29 | parent = np->ipnode->parent; | |
30 | while (parent) { | |
31 | if(parent->exts) | |
32 | if( parent->exts[tgh_ext]) { | |
33 | /* falls under parent trust */ | |
34 | tgh = (trusthost_t *)parent->exts[tgh_ext]; | |
35 | if(tgh->expire && (tgh->expire <= getnettime())) { | |
36 | trusthost_expire(tgh); | |
37 | tgh = NULL; | |
38 | } else { | |
39 | tg = tgh->trustgroup; | |
40 | if(tg->expire && (tg->expire <= getnettime())) { | |
41 | /* expire trust group */ | |
42 | trustgroup_expire(tg); | |
43 | tgh = NULL; | |
44 | } else { | |
45 | break; | |
46 | } | |
47 | } | |
48 | } | |
49 | parent = parent->parent; | |
50 | } | |
51 | } | |
52 | ||
53 | if(tgh) { | |
54 | /* we have a trusthost - check it */ | |
55 | tg = tgh->trustgroup; | |
56 | if(((((int)(np->ipnode->usercount))) > tg->maxperip) && tg->maxperip ) { | |
57 | /* user exceed ip trust limit - disconnect */ | |
9a8ffb84 | 58 | 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 |
59 | //killuser(NULL, np, "USER: Exceeding IP Limit."); |
60 | } | |
61 | if( tg->maxclones >0 ) { | |
62 | if( (tg->currenton + 1) > tg->maxclones) { | |
63 | /* user exceeds trust group limit - disconnect */ | |
64 | //killuser(NULL, np, "USER: Exceeding Trustgroup Limit."); | |
9a8ffb84 | 65 | 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 |
66 | } |
67 | } | |
68 | if ( np->ident[0] == '~') { | |
69 | /* non-ident user */ | |
70 | if (tg->enforceident ) { | |
9a8ffb84 | 71 | 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 |
72 | //killuser(NULL, np, "USER: Ident Required From Your Host."); |
73 | /*TODO: add short gline here - ~*@%s - "IDENTD required from your host", "MissingIDENT" */ | |
74 | } | |
75 | } else { | |
76 | /* ident user */ | |
77 | /*TODO: need to tidy out ident currenton */ | |
78 | increment_ident_count(np, tg); | |
79 | } | |
80 | /* Trust Checks Passed: OK - increment counters */ | |
81 | increment_trust_ipnode(np->ipnode); | |
82 | return; | |
83 | } | |
84 | /* non trusted user - OK */ | |
85 | } | |
86 | ||
87 | ||
88 | void trusts_hook_lostuser(int hook, void *arg) { | |
89 | nick *np = (nick *)arg; | |
90 | trusthost_t *tgh = NULL; | |
91 | trustgroup_t *tg = NULL; | |
92 | patricia_node_t *parent; | |
93 | ||
94 | if(!np) { | |
95 | Error("nodecount", ERR_ERROR, "np was NULL"); | |
96 | } | |
97 | if(!np->ipnode) { | |
98 | Error("nodecount", ERR_ERROR, "np->ipnode was NULL"); | |
99 | } | |
100 | if(!np->ipnode->exts) { | |
101 | Error("nodecount", ERR_ERROR, "np->ipnode->exts was NULL"); | |
102 | } | |
103 | ||
104 | decrement_trust_ipnode(np->ipnode); | |
105 | ||
106 | if(np->ipnode->exts[tgh_ext]) { | |
107 | tgh = (trusthost_t *)np->ipnode->exts[tgh_ext]; | |
108 | } else { | |
109 | parent = np->ipnode->parent; | |
110 | while (parent) { | |
111 | if(parent->exts) | |
112 | if( parent->exts[tgh_ext]) { | |
113 | /* falls under parent trust */ | |
114 | tgh = (trusthost_t *)parent->exts[tgh_ext]; | |
115 | break; | |
116 | } | |
117 | parent = parent->parent; | |
118 | } | |
119 | } | |
120 | if(tgh) { | |
121 | tg = tgh->trustgroup; | |
122 | if ( np->ident[0] != '~') { | |
123 | decrement_ident_count(np, tg); | |
124 | } | |
125 | } | |
126 | } | |
127 |