]>
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 | |
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 |
31 | struct trustmigration; |
32 | ||
1bbe1ac3 CP |
33 | struct trusthost; |
34 | ||
be2823bc | 35 | typedef 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 | ||
34e3de85 GB |
49 | struct trusthost *parent, *children; |
50 | unsigned int marker; | |
51 | ||
52 | struct trusthost *nextbychild; | |
be2823bc CP |
53 | struct trusthost *next; |
54 | } trusthost; | |
55 | ||
2b6e02e2 CP |
56 | typedef struct trustgroup { |
57 | unsigned int id; | |
58 | ||
59 | sstring *name; | |
60 | unsigned int trustedfor; | |
61 | int mode; | |
62 | unsigned int maxperident; | |
4be1aaf2 | 63 | unsigned int maxusage; |
2b6e02e2 | 64 | time_t expires; |
be2823bc | 65 | time_t lastseen; |
1f685425 | 66 | time_t lastmaxusereset; |
2b6e02e2 CP |
67 | sstring *createdby, *contact, *comment; |
68 | ||
be2823bc | 69 | trusthost *hosts; |
1bbe1ac3 CP |
70 | unsigned int count; |
71 | ||
34e3de85 GB |
72 | unsigned int marker; |
73 | ||
2b6e02e2 | 74 | struct trustgroup *next; |
2129448c CP |
75 | |
76 | void *exts[MAXTGEXTS]; | |
2b6e02e2 CP |
77 | } trustgroup; |
78 | ||
1bbe1ac3 CP |
79 | #define nextbytrust(x) (nick *)((x)->exts[trusts_nextuserext]) |
80 | #define gettrusthost(x) (trusthost *)((x)->exts[trusts_thext]) | |
81 | #define setnextbytrust(x, y) (x)->exts[trusts_nextuserext] = (y) | |
82 | #define settrusthost(x, y) (x)->exts[trusts_thext] = (y) | |
83 | ||
45e8ce62 CP |
84 | /* trusts.c */ |
85 | extern int trusts_thext, trusts_nextuserext; | |
2129448c CP |
86 | int findtgext(const char *); |
87 | int registertgext(const char *); | |
88 | void releasetgext(int); | |
82a316e7 | 89 | int trusts_fullyonline(void); |
45e8ce62 | 90 | |
8a95d3e4 CP |
91 | /* formats.c */ |
92 | char *trusts_timetostr(time_t); | |
65f34016 CP |
93 | int trusts_parsecidr(const char *, uint32_t *, short *); |
94 | int trusts_str2cidr(const char *, uint32_t *, uint32_t *); | |
95 | char *trusts_cidr2str(uint32_t, uint32_t); | |
82a316e7 CP |
96 | char *dumpth(trusthost *, int); |
97 | char *dumptg(trustgroup *, int); | |
98 | int parseth(char *, trusthost *, unsigned int *, int); | |
99 | int parsetg(char *, trustgroup *, int); | |
100 | char *rtrim(char *); | |
5ada3782 CP |
101 | |
102 | /* data.c */ | |
be2823bc | 103 | extern trustgroup *tglist; |
5ada3782 CP |
104 | trustgroup *tg_getbyid(unsigned int); |
105 | void th_free(trusthost *); | |
82a316e7 | 106 | trusthost *th_add(trusthost *); |
2ab0a1e7 | 107 | void tg_free(trustgroup *, int); |
82a316e7 | 108 | trustgroup *tg_add(trustgroup *); |
d2c08930 | 109 | trusthost *th_getbyhost(uint32_t); |
9097ab05 CP |
110 | trusthost *th_getbyhostandmask(uint32_t, uint32_t); |
111 | trusthost *th_getsmallestsupersetbyhost(uint32_t, uint32_t); | |
112 | trustgroup *tg_strtotg(char *); | |
113 | void th_adjusthosts(trusthost *th, trusthost *, trusthost *); | |
114 | void th_getsuperandsubsets(uint32_t, uint32_t, trusthost **, trusthost **); | |
b76fd8e6 CP |
115 | trusthost *th_getsubsetbyhost(uint32_t ip, uint32_t mask); |
116 | trusthost *th_getnextsubsetbyhost(trusthost *th, uint32_t ip, uint32_t mask); | |
34e3de85 GB |
117 | void th_linktree(void); |
118 | unsigned int nexttgmarker(void); | |
119 | unsigned int nextthmarker(void); | |
2ab0a1e7 CP |
120 | trusthost *th_getbyid(unsigned int); |
121 | int tg_modify(trustgroup *, trustgroup *); | |
5ada3782 CP |
122 | |
123 | /* migration.c */ | |
82a316e7 CP |
124 | typedef void (*TrustMigrationGroup)(void *, trustgroup *); |
125 | typedef void (*TrustMigrationHost)(void *, trusthost *, unsigned int); | |
5ada3782 | 126 | typedef void (*TrustMigrationFini)(void *, int); |
2b6e02e2 | 127 | |
2ab0a1e7 CP |
128 | /* trusts_db.c */ |
129 | extern int trustsdbloaded; | |
130 | int trusts_loaddb(void); | |
131 | void trusts_closedb(int); | |
132 | trustgroup *tg_new(trustgroup *); | |
133 | trusthost *th_new(trustgroup *, char *); | |
134 | void trustsdb_insertth(char *, trusthost *, unsigned int); | |
135 | void trustsdb_inserttg(char *, trustgroup *); | |
136 | trustgroup *tg_copy(trustgroup *); | |
137 | trusthost *th_copy(trusthost *); | |
138 | void tg_update(trustgroup *); | |
139 | void tg_delete(trustgroup *); | |
140 | void th_delete(trusthost *); | |
1467e9a4 GB |
141 | void trustlog(trustgroup *tg, const char *user, const char *format, ...); |
142 | void trustlogspewid(nick *np, unsigned int groupid, unsigned int limit); | |
143 | void trustlogspewname(nick *np, const char *groupname, unsigned int limit); | |
01bd21d3 | 144 | void trustloggrep(nick *np, const char *pattern, unsigned int limit); |
2ab0a1e7 | 145 | |
5ada3782 CP |
146 | typedef struct trustmigration { |
147 | int count, cur; | |
148 | void *schedule; | |
149 | void *tag; | |
150 | ||
151 | TrustMigrationGroup group; | |
152 | TrustMigrationHost host; | |
153 | TrustMigrationFini fini; | |
154 | } trustmigration; | |
155 | ||
156 | /* db-migration.c */ | |
5ada3782 | 157 | typedef void (*TrustDBMigrationCallback)(int, void *); |
2d4ba67d | 158 | |
9097ab05 CP |
159 | /* events.c */ |
160 | void trusts_newnick(nick *, int); | |
161 | void trusts_lostnick(nick *, int); | |
162 | ||
813c5b73 CP |
163 | /* trusts_api.c */ |
164 | int istrusted(nick *); | |
ac3af088 GB |
165 | int trustgline(trustgroup *tg, const char *ident, int duration, const char *reason); |
166 | int trustungline(trustgroup *tg, const char *ident, int duration, const char *reason); | |
813c5b73 | 167 | |
2b6e02e2 | 168 | #endif |