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