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 50000
22 #define MAXDURATION 365 * 86400 * 20
23 #define MAXPERIDENT 1000
25 #define TABLES_REGULAR 0
26 #define TABLES_MIGRATION 1
27 #define TABLES_REPLICATION 2
29 #define CLEANUP_TH_INACTIVE 30
31 struct trustmigration
;
35 typedef struct trusthost
{
39 unsigned int maxusage
;
44 struct trustgroup
*group
;
51 struct trusthost
*parent
, *children
;
54 struct trusthost
*nextbychild
;
55 struct trusthost
*next
;
58 typedef struct trustgroup
{
62 unsigned int trustedfor
;
64 unsigned int maxperident
;
65 unsigned int maxusage
;
68 time_t lastmaxusereset
;
69 sstring
*createdby
, *contact
, *comment
;
76 struct trustgroup
*next
;
78 void *exts
[MAXTGEXTS
];
81 #define nextbytrust(x) (nick *)((x)->exts[trusts_nextuserext])
82 #define gettrusthost(x) (trusthost *)((x)->exts[trusts_thext])
83 #define setnextbytrust(x, y) (x)->exts[trusts_nextuserext] = (y)
84 #define settrusthost(x, y) (x)->exts[trusts_thext] = (y)
87 extern int trusts_thext
, trusts_nextuserext
;
88 int findtgext(const char *);
89 int registertgext(const char *);
90 void releasetgext(int);
91 int trusts_fullyonline(void);
94 char *trusts_timetostr(time_t);
95 int trusts_parsecidr(const char *, uint32_t *, short *);
96 int trusts_str2cidr(const char *, uint32_t *, uint32_t *);
97 char *trusts_cidr2str(uint32_t, uint32_t);
98 char *dumpth(trusthost
*, int);
99 char *dumptg(trustgroup
*, int);
100 int parseth(char *, trusthost
*, unsigned int *, int);
101 int parsetg(char *, trustgroup
*, int);
105 extern trustgroup
*tglist
;
106 trustgroup
*tg_getbyid(unsigned int);
107 void th_free(trusthost
*);
108 trusthost
*th_add(trusthost
*);
109 void tg_free(trustgroup
*, int);
110 trustgroup
*tg_add(trustgroup
*);
111 trusthost
*th_getbyhost(uint32_t);
112 trusthost
*th_getbyhostandmask(uint32_t, uint32_t);
113 trusthost
*th_getsmallestsupersetbyhost(uint32_t, uint32_t);
114 trustgroup
*tg_strtotg(char *);
115 void th_adjusthosts(trusthost
*th
, trusthost
*, trusthost
*);
116 void th_getsuperandsubsets(uint32_t, uint32_t, trusthost
**, trusthost
**);
117 trusthost
*th_getsubsetbyhost(uint32_t ip
, uint32_t mask
);
118 trusthost
*th_getnextsubsetbyhost(trusthost
*th
, uint32_t ip
, uint32_t mask
);
119 void th_linktree(void);
120 unsigned int nexttgmarker(void);
121 unsigned int nextthmarker(void);
122 trusthost
*th_getbyid(unsigned int);
123 int tg_modify(trustgroup
*, trustgroup
*);
126 typedef void (*TrustMigrationGroup
)(void *, trustgroup
*);
127 typedef void (*TrustMigrationHost
)(void *, trusthost
*, unsigned int);
128 typedef void (*TrustMigrationFini
)(void *, int);
131 extern int trustsdbloaded
;
132 int trusts_loaddb(void);
133 void trusts_closedb(int);
134 trustgroup
*tg_new(trustgroup
*);
135 trusthost
*th_new(trustgroup
*, char *);
136 void trustsdb_insertth(char *, trusthost
*, unsigned int);
137 void trustsdb_inserttg(char *, trustgroup
*);
138 trustgroup
*tg_copy(trustgroup
*);
139 trusthost
*th_copy(trusthost
*);
140 void tg_update(trustgroup
*);
141 void tg_delete(trustgroup
*);
142 void th_delete(trusthost
*);
143 void trustlog(trustgroup
*tg
, const char *user
, const char *format
, ...);
144 void trustlogspewid(nick
*np
, unsigned int groupid
, unsigned int limit
);
145 void trustlogspewname(nick
*np
, const char *groupname
, unsigned int limit
);
146 void trustloggrep(nick
*np
, const char *pattern
, unsigned int limit
);
148 typedef struct trustmigration
{
153 TrustMigrationGroup group
;
154 TrustMigrationHost host
;
155 TrustMigrationFini fini
;
159 typedef void (*TrustDBMigrationCallback
)(int, void *);
162 void trusts_newnick(nick
*, int);
163 void trusts_lostnick(nick
*, int);
166 int istrusted(nick
*);
167 int trustgline(trustgroup
*tg
, const char *ident
, int duration
, const char *reason
);
168 int trustungline(trustgroup
*tg
, const char *ident
, int duration
, const char *reason
);