]>
jfr.im git - irc/quakenet/newserv.git/blob - trusts/data.c
4 #include "../lib/sstring.h"
5 #include "../core/hooks.h"
6 #include "../core/nsmalloc.h"
7 #include "../lib/irc_string.h"
12 void th_dbupdatecounts ( trusthost
*);
13 void tg_dbupdatecounts ( trustgroup
*);
15 void trusts_freeall ( void ) {
19 for ( tg
= tglist
; tg
; tg
= ntg
) {
21 for ( th
= tg
-> hosts
; th
; th
= nth
) {
33 trustgroup
* tg_getbyid ( unsigned int id
) {
36 for ( tg
= tglist
; tg
; tg
= tg
-> next
)
43 void th_free ( trusthost
* th
) {
44 nsfree ( POOL_TRUSTS
, th
);
47 int th_add ( trustgroup
* tg
, unsigned int id
, char * host
, unsigned int maxusage
, time_t lastseen
) {
51 if (! trusts_str2cidr ( host
, & ip
, & mask
))
54 th
= nsmalloc ( POOL_TRUSTS
, sizeof ( trusthost
));
59 th
-> maxusage
= maxusage
;
60 th
-> lastseen
= lastseen
;
74 void tg_free ( trustgroup
* tg
) {
75 triggerhook ( HOOK_TRUSTS_LOSTGROUP
, tg
);
77 freesstring ( tg
-> name
);
78 freesstring ( tg
-> createdby
);
79 freesstring ( tg
-> contact
);
80 freesstring ( tg
-> comment
);
81 nsfree ( POOL_TRUSTS
, tg
);
84 int tg_add ( unsigned int id
, char * name
, unsigned int trustedfor
, int mode
, unsigned int maxperident
, unsigned int maxusage
, time_t expires
, time_t lastseen
, time_t lastmaxuserreset
, char * createdby
, char * contact
, char * comment
) {
85 trustgroup
* tg
= nsmalloc ( POOL_TRUSTS
, sizeof ( trustgroup
));
89 tg
-> name
= getsstring ( name
, TRUSTNAMELEN
);
90 tg
-> createdby
= getsstring ( createdby
, NICKLEN
);
91 tg
-> contact
= getsstring ( contact
, CONTACTLEN
);
92 tg
-> comment
= getsstring ( comment
, COMMENTLEN
);
93 if (! tg
-> name
|| ! tg
-> createdby
|| ! tg
-> contact
|| ! tg
-> comment
) {
99 tg
-> trustedfor
= trustedfor
;
101 tg
-> maxperident
= maxperident
;
102 tg
-> maxusage
= maxusage
;
103 tg
-> expires
= expires
;
104 tg
-> lastseen
= lastseen
;
105 tg
-> lastmaxuserreset
= lastmaxuserreset
;
110 memset ( tg
-> exts
, 0 , sizeof ( tg
-> exts
));
115 triggerhook ( HOOK_TRUSTS_NEWGROUP
, tg
);
120 trusthost
* th_getbyhost ( uint32_t host
) {
124 for ( tg
= tglist
; tg
; tg
= tg
-> next
)
125 for ( th
= tg
-> hosts
; th
; th
= th
-> next
)
126 if (( host
& th
-> mask
) == th
-> ip
)
132 void trusts_flush ( void ) {
135 time_t t
= time ( NULL
);
137 for ( tg
= tglist
; tg
; tg
= tg
-> next
) {
141 tg_dbupdatecounts ( tg
);
143 for ( th
= tg
-> hosts
; th
; th
= th
-> next
) {
147 th_dbupdatecounts ( th
);
152 trustgroup
* tg_strtotg ( char * name
) {
158 id
= strtoul (& name
[ 1 ], NULL
, 10 );
162 for ( tg
= tglist
; tg
; tg
= tg
-> next
)
167 for ( tg
= tglist
; tg
; tg
= tg
-> next
)
168 if (! match ( name
, tg
-> name
-> content
))
171 id
= strtoul ( name
, NULL
, 10 );
176 for ( tg
= tglist
; tg
; tg
= tg
-> next
)