6 #include "../nick/nick.h"
7 #include "../lib/sstring.h"
9 #define MIGRATION_STOPPED -1
10 #define MIGRATION_LASTERROR -2
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
21 #define MAXTRUSTEDFOR 5000
22 #define MAXDURATION 365 * 86400 * 20
23 #define MAXPERIDENT 1000
24 #define MAXPERNODE 1000
26 #define TABLES_REGULAR 0
27 #define TABLES_MIGRATION 1
28 #define TABLES_REPLICATION 2
30 #define CLEANUP_TH_INACTIVE 60
32 #define POLICY_GLINE_DURATION 1800
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
40 #define DEFAULT_TRUSTPORT 5776
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
47 #define TRUST_MIN_UNPRIVILEGED_BITS_IPV4 (96 + 20)
48 #define TRUST_MIN_UNPRIVILEGED_BITS_IPV6 32
50 #define TRUST_MIN_UNPRIVILEGED_NODEBITS_IPV4 (96 + 24)
51 #define TRUST_MIN_UNPRIVILEGED_NODEBITS_IPV6 48
53 struct trustmigration
;
57 typedef struct trusthost
{
60 struct irc_in_addr ip
;
62 unsigned int maxusage
;
67 struct trustgroup
*group
;
74 struct trusthost
*parent
, *children
;
77 struct trusthost
*nextbychild
;
78 struct trusthost
*next
;
81 typedef struct trustgroup
{
85 unsigned int trustedfor
;
87 unsigned int maxperident
;
88 unsigned int maxusage
;
91 time_t lastmaxusereset
;
92 sstring
*createdby
, *contact
, *comment
;
99 struct trustgroup
*next
;
101 void *exts
[MAXTGEXTS
];
104 #define nextbytrust(x) (nick *)((x)->exts[trusts_nextuserext])
105 #define gettrusthost(x) (trusthost *)((x)->exts[trusts_thext])
106 #define setnextbytrust(x, y) (x)->exts[trusts_nextuserext] = (y)
107 #define settrusthost(x, y) (x)->exts[trusts_thext] = (y)
110 extern int trusts_thext
, trusts_nextuserext
;
111 int findtgext(const char *);
112 int registertgext(const char *);
113 void releasetgext(int);
114 int trusts_fullyonline(void);
117 char *trusts_timetostr(time_t);
118 char *dumpth(trusthost
*, int);
119 char *dumptg(trustgroup
*, int);
120 int parseth(char *, trusthost
*, unsigned int *, int);
121 int parsetg(char *, trustgroup
*, int);
125 extern trustgroup
*tglist
;
126 trustgroup
*tg_getbyid(unsigned int);
127 void th_free(trusthost
*);
128 trusthost
*th_add(trusthost
*);
129 void tg_free(trustgroup
*, int);
130 trustgroup
*tg_add(trustgroup
*);
131 trusthost
*th_getbyhost(struct irc_in_addr
*);
132 trusthost
*th_getbyhostandmask(struct irc_in_addr
*, uint32_t);
133 trusthost
*th_getsmallestsupersetbyhost(struct irc_in_addr
*, uint32_t);
134 trustgroup
*tg_strtotg(char *);
135 void th_adjusthosts(trusthost
*th
, trusthost
*, trusthost
*);
136 void th_getsuperandsubsets(struct irc_in_addr
*, uint32_t, trusthost
**, trusthost
**);
137 trusthost
*th_getsubsetbyhost(struct irc_in_addr
*ip
, uint32_t mask
);
138 trusthost
*th_getnextsubsetbyhost(trusthost
*th
, struct irc_in_addr
*ip
, uint32_t mask
);
139 void th_linktree(void);
140 unsigned int nexttgmarker(void);
141 unsigned int nextthmarker(void);
142 trusthost
*th_getbyid(unsigned int);
143 int tg_modify(trustgroup
*, trustgroup
*);
144 int th_modify(trusthost
*, trusthost
*);
147 typedef void (*TrustMigrationGroup
)(void *, trustgroup
*);
148 typedef void (*TrustMigrationHost
)(void *, trusthost
*, unsigned int);
149 typedef void (*TrustMigrationFini
)(void *, int);
152 extern int trustsdbloaded
;
153 int trusts_loaddb(void);
154 void trusts_closedb(int);
155 trustgroup
*tg_new(trustgroup
*);
156 trusthost
*th_new(trustgroup
*, char *);
157 void trustsdb_insertth(char *, trusthost
*, unsigned int);
158 void trustsdb_inserttg(char *, trustgroup
*);
159 trustgroup
*tg_copy(trustgroup
*);
160 trusthost
*th_copy(trusthost
*);
161 void tg_update(trustgroup
*);
162 void tg_delete(trustgroup
*);
163 void th_update(trusthost
*);
164 void th_delete(trusthost
*);
165 void trustlog(trustgroup
*tg
, const char *user
, const char *format
, ...);
166 void trustlogspewid(nick
*np
, unsigned int groupid
, unsigned int limit
);
167 void trustlogspewname(nick
*np
, const char *groupname
, unsigned int limit
);
168 void trustloggrep(nick
*np
, const char *pattern
, unsigned int limit
);
170 typedef struct trustmigration
{
175 TrustMigrationGroup group
;
176 TrustMigrationHost host
;
177 TrustMigrationFini fini
;
181 typedef void (*TrustDBMigrationCallback
)(int, void *);
184 void trusts_newnick(nick
*, int);
185 void trusts_lostnick(nick
*, int);
188 int istrusted(nick
*);
189 unsigned char getnodebits(struct irc_in_addr
*ip
);