]> jfr.im git - irc/quakenet/newserv.git/blame - trusts/trusts.h
Treat 6to4 clients as if they're connecting via IPv4.
[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
2ab0a1e7
CP
21#define MAXTRUSTEDFOR 50000
22#define MAXDURATION 365 * 86400 * 20
23#define MAXPERIDENT 1000
24
35449aa5
CP
25#define TABLES_REGULAR 0
26#define TABLES_MIGRATION 1
27#define TABLES_REPLICATION 2
28
caf2d02a
GB
29#define CLEANUP_TH_INACTIVE 30
30
2b6e02e2
CP
31struct trustmigration;
32
1bbe1ac3
CP
33struct trusthost;
34
be2823bc 35typedef struct trusthost {
9bf9e8a1
CP
36 unsigned int id;
37
caf2d02a 38
65f34016 39 uint32_t ip, mask;
4be1aaf2 40 unsigned int maxusage;
caf2d02a 41 time_t created;
be2823bc
CP
42 time_t lastseen;
43
1bbe1ac3
CP
44 nick *users;
45 struct trustgroup *group;
46
47 unsigned int count;
48
be2823bc
CP
49 struct trusthost *next;
50} trusthost;
51
2b6e02e2
CP
52typedef struct trustgroup {
53 unsigned int id;
54
55 sstring *name;
56 unsigned int trustedfor;
57 int mode;
58 unsigned int maxperident;
4be1aaf2 59 unsigned int maxusage;
2b6e02e2 60 time_t expires;
be2823bc 61 time_t lastseen;
1f685425 62 time_t lastmaxusereset;
2b6e02e2
CP
63 sstring *createdby, *contact, *comment;
64
be2823bc 65 trusthost *hosts;
1bbe1ac3
CP
66 unsigned int count;
67
2b6e02e2 68 struct trustgroup *next;
2129448c
CP
69
70 void *exts[MAXTGEXTS];
2b6e02e2
CP
71} trustgroup;
72
1bbe1ac3
CP
73#define nextbytrust(x) (nick *)((x)->exts[trusts_nextuserext])
74#define gettrusthost(x) (trusthost *)((x)->exts[trusts_thext])
75#define setnextbytrust(x, y) (x)->exts[trusts_nextuserext] = (y)
76#define settrusthost(x, y) (x)->exts[trusts_thext] = (y)
77
45e8ce62
CP
78/* trusts.c */
79extern int trusts_thext, trusts_nextuserext;
2129448c
CP
80int findtgext(const char *);
81int registertgext(const char *);
82void releasetgext(int);
82a316e7 83int trusts_fullyonline(void);
45e8ce62 84
8a95d3e4
CP
85/* formats.c */
86char *trusts_timetostr(time_t);
65f34016
CP
87int trusts_parsecidr(const char *, uint32_t *, short *);
88int trusts_str2cidr(const char *, uint32_t *, uint32_t *);
89char *trusts_cidr2str(uint32_t, uint32_t);
82a316e7
CP
90char *dumpth(trusthost *, int);
91char *dumptg(trustgroup *, int);
92int parseth(char *, trusthost *, unsigned int *, int);
93int parsetg(char *, trustgroup *, int);
94char *rtrim(char *);
5ada3782
CP
95
96/* data.c */
be2823bc 97extern trustgroup *tglist;
5ada3782
CP
98trustgroup *tg_getbyid(unsigned int);
99void th_free(trusthost *);
82a316e7 100trusthost *th_add(trusthost *);
2ab0a1e7 101void tg_free(trustgroup *, int);
82a316e7 102trustgroup *tg_add(trustgroup *);
d2c08930 103trusthost *th_getbyhost(uint32_t);
9097ab05
CP
104trusthost *th_getbyhostandmask(uint32_t, uint32_t);
105trusthost *th_getsmallestsupersetbyhost(uint32_t, uint32_t);
106trustgroup *tg_strtotg(char *);
107void th_adjusthosts(trusthost *th, trusthost *, trusthost *);
108void th_getsuperandsubsets(uint32_t, uint32_t, trusthost **, trusthost **);
b76fd8e6
CP
109trusthost *th_getsubsetbyhost(uint32_t ip, uint32_t mask);
110trusthost *th_getnextsubsetbyhost(trusthost *th, uint32_t ip, uint32_t mask);
2ab0a1e7
CP
111trusthost *th_getbyid(unsigned int);
112int tg_modify(trustgroup *, trustgroup *);
5ada3782
CP
113
114/* migration.c */
82a316e7
CP
115typedef void (*TrustMigrationGroup)(void *, trustgroup *);
116typedef void (*TrustMigrationHost)(void *, trusthost *, unsigned int);
5ada3782 117typedef void (*TrustMigrationFini)(void *, int);
2b6e02e2 118
2ab0a1e7
CP
119/* trusts_db.c */
120extern int trustsdbloaded;
121int trusts_loaddb(void);
122void trusts_closedb(int);
123trustgroup *tg_new(trustgroup *);
124trusthost *th_new(trustgroup *, char *);
125void trustsdb_insertth(char *, trusthost *, unsigned int);
126void trustsdb_inserttg(char *, trustgroup *);
127trustgroup *tg_copy(trustgroup *);
128trusthost *th_copy(trusthost *);
129void tg_update(trustgroup *);
130void tg_delete(trustgroup *);
131void th_delete(trusthost *);
1467e9a4
GB
132void trustlog(trustgroup *tg, const char *user, const char *format, ...);
133void trustlogspewid(nick *np, unsigned int groupid, unsigned int limit);
134void trustlogspewname(nick *np, const char *groupname, unsigned int limit);
01bd21d3 135void trustloggrep(nick *np, const char *pattern, unsigned int limit);
2ab0a1e7 136
5ada3782
CP
137typedef struct trustmigration {
138 int count, cur;
139 void *schedule;
140 void *tag;
141
142 TrustMigrationGroup group;
143 TrustMigrationHost host;
144 TrustMigrationFini fini;
145} trustmigration;
146
147/* db-migration.c */
5ada3782 148typedef void (*TrustDBMigrationCallback)(int, void *);
2d4ba67d 149
9097ab05
CP
150/* events.c */
151void trusts_newnick(nick *, int);
152void trusts_lostnick(nick *, int);
153
813c5b73
CP
154/* trusts_api.c */
155int istrusted(nick *);
ac3af088
GB
156int trustgline(trustgroup *tg, const char *ident, int duration, const char *reason);
157int trustungline(trustgroup *tg, const char *ident, int duration, const char *reason);
813c5b73 158
2b6e02e2 159#endif