]>
Commit | Line | Data |
---|---|---|
1 | #ifndef __TRUSTS_H | |
2 | #define __TRUSTS_H | |
3 | ||
4 | #include <time.h> | |
5 | #include <stdint.h> | |
6 | #include "../nick/nick.h" | |
7 | #include "../lib/sstring.h" | |
8 | ||
9 | #define MIGRATION_STOPPED -1 | |
10 | #define MIGRATION_LASTERROR -2 | |
11 | ||
12 | #define CONTACTLEN 100 | |
13 | #define COMMENTLEN 300 | |
14 | #define TRUSTNAMELEN 100 | |
15 | #define TRUSTHOSTLEN 100 | |
16 | #define CREATEDBYLEN NICKLEN + 1 | |
17 | #define TRUSTLOGLEN 200 | |
18 | ||
19 | #define MAXTGEXTS 5 | |
20 | ||
21 | #define MAXTRUSTEDFOR 5000 | |
22 | #define MAXDURATION 365 * 86400 * 20 | |
23 | #define MAXPERIDENT 1000 | |
24 | #define MAXPERNODE 1000 | |
25 | ||
26 | #define TABLES_REGULAR 0 | |
27 | #define TABLES_MIGRATION 1 | |
28 | #define TABLES_REPLICATION 2 | |
29 | ||
30 | #define CLEANUP_TH_INACTIVE 60 | |
31 | ||
32 | #define POLICY_GLINE_DURATION 1800 | |
33 | ||
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 | ||
40 | #define DEFAULT_TRUSTPORT 5776 | |
41 | ||
42 | #define TRUST_ENFORCE_IDENT 1 /* This must be 1 for compatibility with O. */ | |
43 | #define TRUST_NO_CLEANUP 2 | |
44 | #define TRUST_PROTECTED 4 | |
45 | #define TRUST_RELIABLE_USERNAME 8 | |
46 | #define TRUST_UNTHROTTLE 16 | |
47 | ||
48 | #define TRUST_MIN_UNPRIVILEGED_BITS_IPV4 (96 + 20) | |
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 | |
53 | ||
54 | struct trustmigration; | |
55 | ||
56 | struct trusthost; | |
57 | ||
58 | typedef struct trusthost { | |
59 | unsigned int id; | |
60 | ||
61 | struct irc_in_addr ip; | |
62 | unsigned char bits; | |
63 | unsigned int maxusage; | |
64 | time_t created; | |
65 | time_t lastseen; | |
66 | ||
67 | nick *users; | |
68 | struct trustgroup *group; | |
69 | ||
70 | unsigned int count; | |
71 | ||
72 | int maxpernode; | |
73 | int nodebits; | |
74 | ||
75 | struct trusthost *parent, *children; | |
76 | unsigned int marker; | |
77 | ||
78 | struct trusthost *nextbychild; | |
79 | struct trusthost *next; | |
80 | } trusthost; | |
81 | ||
82 | typedef struct trustgroup { | |
83 | unsigned int id; | |
84 | ||
85 | sstring *name; | |
86 | unsigned int trustedfor; | |
87 | int flags; | |
88 | int maxperident; | |
89 | unsigned int maxusage; | |
90 | time_t expires; | |
91 | time_t lastseen; | |
92 | time_t lastmaxusereset; | |
93 | sstring *createdby, *contact, *comment; | |
94 | ||
95 | trusthost *hosts; | |
96 | unsigned int count; | |
97 | ||
98 | unsigned int marker; | |
99 | ||
100 | struct trustgroup *next; | |
101 | ||
102 | void *exts[MAXTGEXTS]; | |
103 | } trustgroup; | |
104 | ||
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 | ||
110 | /* trusts.c */ | |
111 | extern int trusts_thext, trusts_nextuserext; | |
112 | int findtgext(const char *); | |
113 | int registertgext(const char *); | |
114 | void releasetgext(int); | |
115 | int trusts_fullyonline(void); | |
116 | ||
117 | /* formats.c */ | |
118 | char *trusts_timetostr(time_t); | |
119 | char *dumpth(trusthost *, int); | |
120 | char *dumptg(trustgroup *, int); | |
121 | int parseth(char *, trusthost *, unsigned int *, int); | |
122 | int parsetg(char *, trustgroup *, int); | |
123 | char *rtrim(char *); | |
124 | ||
125 | /* data.c */ | |
126 | extern trustgroup *tglist; | |
127 | trustgroup *tg_getbyid(unsigned int); | |
128 | void th_free(trusthost *); | |
129 | trusthost *th_add(trusthost *); | |
130 | void tg_free(trustgroup *, int); | |
131 | trustgroup *tg_add(trustgroup *); | |
132 | trusthost *th_getbyhost(struct irc_in_addr *); | |
133 | trusthost *th_getbyhostandmask(struct irc_in_addr *, uint32_t); | |
134 | trusthost *th_getsmallestsupersetbyhost(struct irc_in_addr *, uint32_t); | |
135 | trustgroup *tg_strtotg(char *); | |
136 | void th_adjusthosts(trusthost *th, trusthost *, trusthost *); | |
137 | void th_getsuperandsubsets(struct irc_in_addr *, uint32_t, trusthost **, trusthost **); | |
138 | trusthost *th_getsubsetbyhost(struct irc_in_addr *ip, uint32_t mask); | |
139 | trusthost *th_getnextsubsetbyhost(trusthost *th, struct irc_in_addr *ip, uint32_t mask); | |
140 | void th_linktree(void); | |
141 | unsigned int nexttgmarker(void); | |
142 | unsigned int nextthmarker(void); | |
143 | trusthost *th_getbyid(unsigned int); | |
144 | int tg_modify(trustgroup *, trustgroup *); | |
145 | int th_modify(trusthost *, trusthost *); | |
146 | ||
147 | /* migration.c */ | |
148 | typedef void (*TrustMigrationGroup)(void *, trustgroup *); | |
149 | typedef void (*TrustMigrationHost)(void *, trusthost *, unsigned int); | |
150 | typedef void (*TrustMigrationFini)(void *, int); | |
151 | ||
152 | /* trusts_db.c */ | |
153 | extern int trustsdbloaded; | |
154 | int trusts_loaddb(void); | |
155 | void trusts_closedb(int); | |
156 | trustgroup *tg_new(trustgroup *); | |
157 | trusthost *th_new(trustgroup *, char *); | |
158 | void trustsdb_insertth(char *, trusthost *, unsigned int); | |
159 | void trustsdb_inserttg(char *, trustgroup *); | |
160 | trustgroup *tg_copy(trustgroup *); | |
161 | trusthost *th_copy(trusthost *); | |
162 | void tg_update(trustgroup *); | |
163 | void tg_delete(trustgroup *); | |
164 | void th_update(trusthost *); | |
165 | void th_delete(trusthost *); | |
166 | void trustlog(trustgroup *tg, const char *user, const char *format, ...); | |
167 | void trustlogspewid(nick *np, unsigned int groupid, unsigned int limit); | |
168 | void trustlogspewname(nick *np, const char *groupname, unsigned int limit); | |
169 | void trustloggrep(nick *np, const char *pattern, unsigned int limit); | |
170 | ||
171 | typedef 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 */ | |
182 | typedef void (*TrustDBMigrationCallback)(int, void *); | |
183 | ||
184 | /* events.c */ | |
185 | void trusts_newnick(nick *, int); | |
186 | void trusts_lostnick(nick *, int); | |
187 | ||
188 | /* trusts_api.c */ | |
189 | int istrusted(nick *); | |
190 | unsigned char getnodebits(struct irc_in_addr *ip); | |
191 | ||
192 | #endif |