]> jfr.im git - irc/quakenet/newserv.git/blame - trusts/trusts.h
Removed obsolete code in trustdotimeout().
[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
de723023
GB
40#define TRUST_ENFORCE_IDENT 1 /* This must be 1 for compatibility with O. */
41#define TRUST_NO_CLEANUP 2
e40626f0
GB
42#define TRUST_PROTECTED 4
43
44#define TRUST_MIN_UNPRIVILEGED_BITS_IPV4 (96 + 32)
45#define TRUST_MIN_UNPRIVILEGED_BITS_IPV6 32
46
47#define TRUST_MIN_UNPRIVILEGED_NODEBITS_IPV4 (96 + 24)
48#define TRUST_MIN_UNPRIVILEGED_NODEBITS_IPV6 48
de723023 49
2b6e02e2
CP
50struct trustmigration;
51
1bbe1ac3
CP
52struct trusthost;
53
be2823bc 54typedef struct trusthost {
9bf9e8a1
CP
55 unsigned int id;
56
6e6e98da
GB
57 struct irc_in_addr ip;
58 unsigned char bits;
4be1aaf2 59 unsigned int maxusage;
caf2d02a 60 time_t created;
be2823bc
CP
61 time_t lastseen;
62
1bbe1ac3
CP
63 nick *users;
64 struct trustgroup *group;
65
66 unsigned int count;
67
cebc4cab
GB
68 int maxpernode;
69 int nodebits;
70
34e3de85
GB
71 struct trusthost *parent, *children;
72 unsigned int marker;
73
74 struct trusthost *nextbychild;
be2823bc
CP
75 struct trusthost *next;
76} trusthost;
77
2b6e02e2
CP
78typedef struct trustgroup {
79 unsigned int id;
80
81 sstring *name;
82 unsigned int trustedfor;
de723023 83 int flags;
2b6e02e2 84 unsigned int maxperident;
4be1aaf2 85 unsigned int maxusage;
2b6e02e2 86 time_t expires;
be2823bc 87 time_t lastseen;
1f685425 88 time_t lastmaxusereset;
2b6e02e2
CP
89 sstring *createdby, *contact, *comment;
90
be2823bc 91 trusthost *hosts;
1bbe1ac3
CP
92 unsigned int count;
93
34e3de85
GB
94 unsigned int marker;
95
2b6e02e2 96 struct trustgroup *next;
2129448c
CP
97
98 void *exts[MAXTGEXTS];
2b6e02e2
CP
99} trustgroup;
100
1bbe1ac3
CP
101#define nextbytrust(x) (nick *)((x)->exts[trusts_nextuserext])
102#define gettrusthost(x) (trusthost *)((x)->exts[trusts_thext])
103#define setnextbytrust(x, y) (x)->exts[trusts_nextuserext] = (y)
104#define settrusthost(x, y) (x)->exts[trusts_thext] = (y)
105
45e8ce62
CP
106/* trusts.c */
107extern int trusts_thext, trusts_nextuserext;
2129448c
CP
108int findtgext(const char *);
109int registertgext(const char *);
110void releasetgext(int);
82a316e7 111int trusts_fullyonline(void);
45e8ce62 112
8a95d3e4
CP
113/* formats.c */
114char *trusts_timetostr(time_t);
6e6e98da 115char *trusts_cidr2str(struct irc_in_addr *ip, unsigned char);
82a316e7
CP
116char *dumpth(trusthost *, int);
117char *dumptg(trustgroup *, int);
118int parseth(char *, trusthost *, unsigned int *, int);
119int parsetg(char *, trustgroup *, int);
120char *rtrim(char *);
5ada3782
CP
121
122/* data.c */
be2823bc 123extern trustgroup *tglist;
5ada3782
CP
124trustgroup *tg_getbyid(unsigned int);
125void th_free(trusthost *);
82a316e7 126trusthost *th_add(trusthost *);
2ab0a1e7 127void tg_free(trustgroup *, int);
82a316e7 128trustgroup *tg_add(trustgroup *);
6e6e98da
GB
129trusthost *th_getbyhost(struct irc_in_addr *);
130trusthost *th_getbyhostandmask(struct irc_in_addr *, uint32_t);
131trusthost *th_getsmallestsupersetbyhost(struct irc_in_addr *, uint32_t);
9097ab05
CP
132trustgroup *tg_strtotg(char *);
133void th_adjusthosts(trusthost *th, trusthost *, trusthost *);
6e6e98da
GB
134void th_getsuperandsubsets(struct irc_in_addr *, uint32_t, trusthost **, trusthost **);
135trusthost *th_getsubsetbyhost(struct irc_in_addr *ip, uint32_t mask);
136trusthost *th_getnextsubsetbyhost(trusthost *th, struct irc_in_addr *ip, uint32_t mask);
34e3de85
GB
137void th_linktree(void);
138unsigned int nexttgmarker(void);
139unsigned int nextthmarker(void);
2ab0a1e7
CP
140trusthost *th_getbyid(unsigned int);
141int tg_modify(trustgroup *, trustgroup *);
058f68c5 142int th_modify(trusthost *, trusthost *);
5ada3782
CP
143
144/* migration.c */
82a316e7
CP
145typedef void (*TrustMigrationGroup)(void *, trustgroup *);
146typedef void (*TrustMigrationHost)(void *, trusthost *, unsigned int);
5ada3782 147typedef void (*TrustMigrationFini)(void *, int);
2b6e02e2 148
2ab0a1e7
CP
149/* trusts_db.c */
150extern int trustsdbloaded;
151int trusts_loaddb(void);
152void trusts_closedb(int);
153trustgroup *tg_new(trustgroup *);
154trusthost *th_new(trustgroup *, char *);
155void trustsdb_insertth(char *, trusthost *, unsigned int);
156void trustsdb_inserttg(char *, trustgroup *);
157trustgroup *tg_copy(trustgroup *);
158trusthost *th_copy(trusthost *);
159void tg_update(trustgroup *);
160void tg_delete(trustgroup *);
c1da06f9 161void th_update(trusthost *);
2ab0a1e7 162void th_delete(trusthost *);
1467e9a4
GB
163void trustlog(trustgroup *tg, const char *user, const char *format, ...);
164void trustlogspewid(nick *np, unsigned int groupid, unsigned int limit);
165void trustlogspewname(nick *np, const char *groupname, unsigned int limit);
01bd21d3 166void trustloggrep(nick *np, const char *pattern, unsigned int limit);
2ab0a1e7 167
5ada3782
CP
168typedef struct trustmigration {
169 int count, cur;
170 void *schedule;
171 void *tag;
172
173 TrustMigrationGroup group;
174 TrustMigrationHost host;
175 TrustMigrationFini fini;
176} trustmigration;
177
178/* db-migration.c */
5ada3782 179typedef void (*TrustDBMigrationCallback)(int, void *);
2d4ba67d 180
9097ab05
CP
181/* events.c */
182void trusts_newnick(nick *, int);
183void trusts_lostnick(nick *, int);
184
813c5b73
CP
185/* trusts_api.c */
186int istrusted(nick *);
a473a1be 187unsigned char getnodebits(struct irc_in_addr *ip);
813c5b73 188
2b6e02e2 189#endif