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