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 TRUST_ENFORCE_IDENT 1 /* This must be 1 for compatibility with O. */
35 #define TRUST_NO_CLEANUP 2
36 #define TRUST_PROTECTED 4
38 #define TRUST_MIN_UNPRIVILEGED_BITS_IPV4 (96 + 32)
39 #define TRUST_MIN_UNPRIVILEGED_BITS_IPV6 32
41 #define TRUST_MIN_UNPRIVILEGED_NODEBITS_IPV4 (96 + 24)
42 #define TRUST_MIN_UNPRIVILEGED_NODEBITS_IPV6 48
44 struct trustmigration
;
48 typedef struct trusthost
{
51 struct irc_in_addr ip
;
53 unsigned int maxusage
;
58 struct trustgroup
*group
;
65 struct trusthost
*parent
, *children
;
68 struct trusthost
*nextbychild
;
69 struct trusthost
*next
;
72 typedef struct trustgroup
{
76 unsigned int trustedfor
;
78 unsigned int maxperident
;
79 unsigned int maxusage
;
82 time_t lastmaxusereset
;
83 sstring
*createdby
, *contact
, *comment
;
90 struct trustgroup
*next
;
92 void *exts
[MAXTGEXTS
];
95 #define nextbytrust(x) (nick *)((x)->exts[trusts_nextuserext])
96 #define gettrusthost(x) (trusthost *)((x)->exts[trusts_thext])
97 #define setnextbytrust(x, y) (x)->exts[trusts_nextuserext] = (y)
98 #define settrusthost(x, y) (x)->exts[trusts_thext] = (y)
101 extern int trusts_thext
, trusts_nextuserext
;
102 int findtgext(const char *);
103 int registertgext(const char *);
104 void releasetgext(int);
105 int trusts_fullyonline(void);
108 char *trusts_timetostr(time_t);
109 char *trusts_cidr2str(struct irc_in_addr
*ip
, unsigned char);
110 char *dumpth(trusthost
*, int);
111 char *dumptg(trustgroup
*, int);
112 int parseth(char *, trusthost
*, unsigned int *, int);
113 int parsetg(char *, trustgroup
*, int);
117 extern trustgroup
*tglist
;
118 trustgroup
*tg_getbyid(unsigned int);
119 void th_free(trusthost
*);
120 trusthost
*th_add(trusthost
*);
121 void tg_free(trustgroup
*, int);
122 trustgroup
*tg_add(trustgroup
*);
123 trusthost
*th_getbyhost(struct irc_in_addr
*);
124 trusthost
*th_getbyhostandmask(struct irc_in_addr
*, uint32_t);
125 trusthost
*th_getsmallestsupersetbyhost(struct irc_in_addr
*, uint32_t);
126 trustgroup
*tg_strtotg(char *);
127 void th_adjusthosts(trusthost
*th
, trusthost
*, trusthost
*);
128 void th_getsuperandsubsets(struct irc_in_addr
*, uint32_t, trusthost
**, trusthost
**);
129 trusthost
*th_getsubsetbyhost(struct irc_in_addr
*ip
, uint32_t mask
);
130 trusthost
*th_getnextsubsetbyhost(trusthost
*th
, struct irc_in_addr
*ip
, uint32_t mask
);
131 void th_linktree(void);
132 unsigned int nexttgmarker(void);
133 unsigned int nextthmarker(void);
134 trusthost
*th_getbyid(unsigned int);
135 int tg_modify(trustgroup
*, trustgroup
*);
136 int th_modify(trusthost
*, trusthost
*);
139 typedef void (*TrustMigrationGroup
)(void *, trustgroup
*);
140 typedef void (*TrustMigrationHost
)(void *, trusthost
*, unsigned int);
141 typedef void (*TrustMigrationFini
)(void *, int);
144 extern int trustsdbloaded
;
145 int trusts_loaddb(void);
146 void trusts_closedb(int);
147 trustgroup
*tg_new(trustgroup
*);
148 trusthost
*th_new(trustgroup
*, char *);
149 void trustsdb_insertth(char *, trusthost
*, unsigned int);
150 void trustsdb_inserttg(char *, trustgroup
*);
151 trustgroup
*tg_copy(trustgroup
*);
152 trusthost
*th_copy(trusthost
*);
153 void tg_update(trustgroup
*);
154 void tg_delete(trustgroup
*);
155 void th_update(trusthost
*);
156 void th_delete(trusthost
*);
157 void trustlog(trustgroup
*tg
, const char *user
, const char *format
, ...);
158 void trustlogspewid(nick
*np
, unsigned int groupid
, unsigned int limit
);
159 void trustlogspewname(nick
*np
, const char *groupname
, unsigned int limit
);
160 void trustloggrep(nick
*np
, const char *pattern
, unsigned int limit
);
162 typedef struct trustmigration
{
167 TrustMigrationGroup group
;
168 TrustMigrationHost host
;
169 TrustMigrationFini fini
;
173 typedef void (*TrustDBMigrationCallback
)(int, void *);
176 void trusts_newnick(nick
*, int);
177 void trusts_lostnick(nick
*, int);
180 int istrusted(nick
*);
181 unsigned char getnodebits(struct irc_in_addr
*ip
);