]> jfr.im git - irc/quakenet/newserv.git/blame_incremental - trusts/trusts.h
CHANSERV: tell user when they can't attempts to auth any more, and drop max attempts...
[irc/quakenet/newserv.git] / trusts / trusts.h
... / ...
CommitLineData
1#ifndef __TRUSTS_H
2#define __TRUSTS_H
3
4#include <time.h>
5#include <stdint.h>
6#include "../nick/nick.h"
7#include "../lib/sstring.h"
8
9#define MIGRATION_STOPPED -1
10#define MIGRATION_LASTERROR -2
11
12#define CONTACTLEN 100
13#define COMMENTLEN 300
14#define TRUSTNAMELEN 100
15#define TRUSTHOSTLEN 100
16#define CREATEDBYLEN NICKLEN + 1
17#define TRUSTLOGLEN 200
18
19#define MAXTGEXTS 5
20
21#define MAXTRUSTEDFOR 5000
22#define MAXDURATION 365 * 86400 * 20
23#define MAXPERIDENT 1000
24#define MAXPERNODE 1000
25
26#define TABLES_REGULAR 0
27#define TABLES_MIGRATION 1
28#define TABLES_REPLICATION 2
29
30#define CLEANUP_TH_INACTIVE 60
31
32#define POLICY_GLINE_DURATION 1800
33
34#define POLICY_SUCCESS 0
35#define POLICY_FAILURE_NODECOUNT 1
36#define POLICY_FAILURE_GROUPCOUNT 2
37#define POLICY_FAILURE_IDENTD 3
38#define POLICY_FAILURE_IDENTCOUNT 4
39
40#define DEFAULT_TRUSTPORT 5776
41
42#define TRUST_ENFORCE_IDENT 1 /* This must be 1 for compatibility with O. */
43#define TRUST_NO_CLEANUP 2
44#define TRUST_PROTECTED 4
45#define TRUST_RELIABLE_USERNAME 8
46#define TRUST_UNTHROTTLE 16
47
48#define TRUST_MIN_UNPRIVILEGED_BITS_IPV4 (96 + 20)
49#define TRUST_MIN_UNPRIVILEGED_BITS_IPV6 32
50
51#define TRUST_MIN_UNPRIVILEGED_NODEBITS_IPV4 (96 + 24)
52#define TRUST_MIN_UNPRIVILEGED_NODEBITS_IPV6 48
53
54#define TRUST_MIN_TIME_RETHROTTLE 120
55
56struct trustmigration;
57
58struct trusthost;
59
60typedef struct trusthost {
61 unsigned int id;
62
63 struct irc_in_addr ip;
64 unsigned char bits;
65 unsigned int maxusage;
66 time_t created;
67 time_t lastseen;
68
69 nick *users;
70 struct trustgroup *group;
71
72 unsigned int count;
73
74 int maxpernode;
75 int nodebits;
76
77 struct trusthost *parent, *children;
78 unsigned int marker;
79
80 struct trusthost *nextbychild;
81 struct trusthost *next;
82} trusthost;
83
84typedef struct trustgroup {
85 unsigned int id;
86
87 sstring *name;
88 unsigned int trustedfor;
89 int flags;
90 int maxperident;
91 unsigned int maxusage;
92 time_t expires;
93 time_t lastseen;
94 time_t lastmaxusereset;
95 sstring *createdby, *contact, *comment;
96
97 trusthost *hosts;
98 unsigned int count;
99
100 unsigned int marker;
101
102 struct trustgroup *next;
103
104 void *exts[MAXTGEXTS];
105} trustgroup;
106
107#define nextbytrust(x) (nick *)((x)->exts[trusts_nextuserext])
108#define gettrusthost(x) (trusthost *)((x)->exts[trusts_thext])
109#define setnextbytrust(x, y) (x)->exts[trusts_nextuserext] = (y)
110#define settrusthost(x, y) (x)->exts[trusts_thext] = (y)
111
112/* trusts.c */
113extern int trusts_thext, trusts_nextuserext;
114int findtgext(const char *);
115int registertgext(const char *);
116void releasetgext(int);
117int trusts_fullyonline(void);
118
119/* formats.c */
120char *trusts_timetostr(time_t);
121char *dumpth(trusthost *, int);
122char *dumptg(trustgroup *, int);
123int parseth(char *, trusthost *, unsigned int *, int);
124int parsetg(char *, trustgroup *, int);
125char *rtrim(char *);
126
127/* data.c */
128extern trustgroup *tglist;
129trustgroup *tg_getbyid(unsigned int);
130void th_free(trusthost *);
131trusthost *th_add(trusthost *);
132void tg_free(trustgroup *, int);
133trustgroup *tg_add(trustgroup *);
134trusthost *th_getbyhost(struct irc_in_addr *);
135trusthost *th_getbyhostandmask(struct irc_in_addr *, uint32_t);
136trusthost *th_getsmallestsupersetbyhost(struct irc_in_addr *, uint32_t);
137trustgroup *tg_strtotg(char *);
138void th_adjusthosts(trusthost *th, trusthost *, trusthost *);
139void th_getsuperandsubsets(struct irc_in_addr *, uint32_t, trusthost **, trusthost **);
140trusthost *th_getsubsetbyhost(struct irc_in_addr *ip, uint32_t mask);
141trusthost *th_getnextsubsetbyhost(trusthost *th, struct irc_in_addr *ip, uint32_t mask);
142void th_linktree(void);
143unsigned int nexttgmarker(void);
144unsigned int nextthmarker(void);
145trusthost *th_getbyid(unsigned int);
146int tg_modify(trustgroup *, trustgroup *);
147int th_modify(trusthost *, trusthost *);
148
149/* migration.c */
150typedef void (*TrustMigrationGroup)(void *, trustgroup *);
151typedef void (*TrustMigrationHost)(void *, trusthost *, unsigned int);
152typedef void (*TrustMigrationFini)(void *, int);
153
154/* trusts_db.c */
155extern int trustsdbloaded;
156int trusts_loaddb(void);
157void trusts_closedb(int);
158trustgroup *tg_new(trustgroup *);
159trusthost *th_new(trustgroup *, char *);
160void trustsdb_insertth(char *, trusthost *, unsigned int);
161void trustsdb_inserttg(char *, trustgroup *);
162trustgroup *tg_copy(trustgroup *);
163trusthost *th_copy(trusthost *);
164void tg_update(trustgroup *);
165void tg_delete(trustgroup *);
166void th_update(trusthost *);
167void th_delete(trusthost *);
168void trustlog(trustgroup *tg, const char *user, const char *format, ...);
169void trustlogspewid(nick *np, unsigned int groupid, unsigned int limit);
170void trustlogspewname(nick *np, const char *groupname, unsigned int limit);
171void trustloggrep(nick *np, const char *pattern, unsigned int limit);
172
173typedef struct trustmigration {
174 int count, cur;
175 void *schedule;
176 void *tag;
177
178 TrustMigrationGroup group;
179 TrustMigrationHost host;
180 TrustMigrationFini fini;
181} trustmigration;
182
183/* db-migration.c */
184typedef void (*TrustDBMigrationCallback)(int, void *);
185
186/* events.c */
187void trusts_newnick(nick *, int);
188void trusts_lostnick(nick *, int);
189
190/* trusts_api.c */
191int istrusted(nick *);
192unsigned char getnodebits(struct irc_in_addr *ip);
193
194#endif