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