]>
jfr.im git - irc/quakenet/newserv.git/blob - trusts2/trusts_commands.c
1 #include "../core/schedule.h"
2 #include "../lib/irc_string.h"
3 #include "../localuser/localuserchannel.h"
4 #include "../control/control.h"
11 registerhook ( HOOK_TRUSTS_DBLOADED
, trusts_cmdinit
);
13 /* Now that the database is in a separate module it might be loaded already. */
15 trusts_cmdinit ( HOOK_TRUSTS_DBLOADED
, NULL
);
20 deregisterhook ( HOOK_TRUSTS_DBLOADED
, trusts_cmdinit
);
24 void trusts_cmdinit ( int hooknum
, void * arg
) {
25 registercontrolcmd ( "trustgroupadd" , 10 , 7 , trust_groupadd
);
26 registercontrolcmd ( "trustgroupmodify" , 10 , 4 , trust_groupmodify
);
27 registercontrolcmd ( "trustgroupdel" , 10 , 2 , trust_groupdel
);
29 registercontrolcmd ( "trustcomment" , 10 , 2 , trust_comment
);
31 registercontrolcmd ( "trustadd" , 10 , 3 , trust_add
);
32 registercontrolcmd ( "trustdel" , 10 , 2 , trust_del
);
34 registercontrolcmd ( "trustdenyadd" , 10 , 2 , trust_denyadd
);
35 registercontrolcmd ( "trustdenycomment" , 10 , 2 , trust_denycomment
);
36 registercontrolcmd ( "trustdenydel" , 10 , 2 , trust_denydel
);
38 registercontrolcmd ( "truststats" , 10 , 2 , trust_stats
);
39 registercontrolcmd ( "trustdump" , 10 , 2 , trust_dump
);
44 void trusts_cmdfini () {
45 deregistercontrolcmd ( "trustgroupadd" , trust_groupadd
);
46 deregistercontrolcmd ( "trustgroupmodify" , trust_groupmodify
);
47 deregistercontrolcmd ( "trustgroupdel" , trust_groupdel
);
49 deregistercontrolcmd ( "trustcomment" , trust_comment
);
51 deregistercontrolcmd ( "trustadd" , trust_add
);
52 deregistercontrolcmd ( "trustdel" , trust_del
);
54 deregistercontrolcmd ( "trustdenyadd" , trust_denyadd
);
55 deregistercontrolcmd ( "trustdenycomment" , trust_denycomment
);
56 deregistercontrolcmd ( "trustdenydel" , trust_denydel
);
58 deregistercontrolcmd ( "truststats" , trust_stats
);
59 deregistercontrolcmd ( "trustdump" , trust_dump
);
65 /* tgh - should this have a 'maxclones limit'? */
67 int trust_groupadd ( void * source
, int cargc
, char ** cargv
) {
68 nick
* sender
=( nick
*) source
;
70 unsigned long maxclones
;
71 unsigned short maxperip
;
72 unsigned long maxperident
;
75 unsigned long ownerid
;
79 controlreply ( sender
, "Usage: trustgroupadd howmany howlong maxperident maxperip enforceident type ownerid" );
83 maxclones
= strtoul ( cargv
[ 0 ], NULL
, 10 );
84 if ( maxclones
> 10000 ) {
85 /* we allow 0 for unlimited trusts, and only warn on this */
86 controlreply ( sender
, "WARNING: large maximum number of clients - %l u" , maxclones
);
88 expiry
= durationtolong ( cargv
[ 1 ]);
89 if ( expiry
> ( 365 * 86400 ) ) {
90 controlreply ( sender
, "ERROR: Invalid duration given - temporary trusts can not be longer then 1 year" );
93 ownerid
= strtoul ( cargv
[ 6 ], NULL
, 10 );
94 maxperip
= strtoul ( cargv
[ 3 ], NULL
, 10 );
96 controlreply ( sender
, "ERROR: MaxPerIP value should be less then 500 (if set)" );
99 maxperident
= strtoul ( cargv
[ 2 ], NULL
, 10 );
100 if ( maxperident
> 50 ) {
101 controlreply ( sender
, "ERROR: MaxPerIdent value should be less then 50 (if set)" );
104 if ((( cargv
[ 4 ][ 0 ]!= '0' ) && ( cargv
[ 4 ][ 0 ]!= '1' )) || ( cargv
[ 4 ][ 1 ]!= '\0' )) {
105 controlreply ( sender
, "ERROR: enforceident is a boolean setting, that means it can only be 0 or 1" );
108 enforceident
= cargv
[ 4 ][ 0 ] == '1' ;
110 if ( findtrustgroupbyownerid ( ownerid
) ) {
111 controlreply ( sender
, "ERROR: Q User ID %d already has a trustgroup" , ownerid
);
114 if ( ownerid
> 2147483646 ) {
115 controlreply ( sender
, "ERROR: Invalid Q User ID: %d " , ownerid
);
119 type
= strtoul ( cargv
[ 5 ], NULL
, 10 );
126 controlreply ( sender
, "Invalid Type ( %d )" , type
);
130 t
= createtrustgroup ( ++ trusts_lasttrustgroupid
, maxclones
, maxperident
, maxperip
, enforceident
, getnettime () + expiry
, ownerid
, type
);
133 controlreply ( sender
, "ERROR: An error occured adding trustgroup" );
137 trustsdb_addtrustgroup ( t
);
139 controlreply ( sender
, "Adding trustgroup with ID %l u" , t
-> id
);
140 controlreply ( sender
, "Connections: %d , Enforceident %d , Per ident: %d , Per IP %d " , maxclones
, enforceident
, maxperident
, maxperip
);
141 controlreply ( sender
, "Expires: %d , User ID: %d " , expiry
, ownerid
);
142 controlwall ( NO_OPER
, NL_TRUSTS
, "NewTrust: ID: %l u, Connections: %d , Enforceident %d , Per ident: %d , Per IP %d , Owner %d " , t
-> id
, maxclones
, enforceident
, maxperident
, maxperip
, ownerid
);
146 int trust_del ( void * source
, int cargc
, char ** cargv
) {
147 nick
* sender
=( nick
*) source
;
148 struct irc_in_addr sin
;
150 patricia_node_t
* node
;
154 controlreply ( sender
, "Syntax: trustdel IP[/mask]" );
158 if ( ipmask_parse ( cargv
[ 0 ], & sin
, & bits
) == 0 ) {
159 controlreply ( sender
, "ERROR: Invalid mask." );
163 node
= refnode ( iptree
, & sin
, bits
);
164 if (! node
-> exts
[ tgh_ext
]) {
165 controlreply ( sender
, "ERROR: That CIDR was not trusted." );
168 /*TODO: only allow a host to be removed if <X users? subnets? bah */
169 tg
= (( trusthost_t
*) node
-> exts
[ tgh_ext
])-> trustgroup
;
170 controlreply ( sender
, " %s removed from trustgroup # %l u" , cargv
[ 0 ], tg
-> id
);
171 controlwall ( NO_OPER
, NL_TRUSTS
, " %s removed from trustgroup # %l u" , cargv
[ 0 ], tg
-> id
);
172 trustsdb_deletetrusthost ( node
-> exts
[ tgh_ext
]);
173 trusthost_free ( node
-> exts
[ tgh_ext
]);
174 node
-> exts
[ tgh_ext
] = NULL
;
179 int trust_add ( void * source
, int cargc
, char ** cargv
) {
180 nick
* sender
=( nick
*) source
;
182 struct irc_in_addr sin
;
184 patricia_node_t
* node
, * inode
, * parent
;
189 controlreply ( sender
, "Syntax: trustadd <#groupid> IP[/mask] <duration>" );
193 if ( cargv
[ 0 ][ 0 ]== '#' ){
194 /* find group by id */
195 tg
= findtrustgroupbyid ( strtol (& cargv
[ 0 ][ 1 ], NULL
, 10 ));
197 /* find group by id */
198 tg
= findtrustgroupbyid ( strtol ( cargv
[ 0 ], NULL
, 10 ));
202 controlreply ( sender
, "ERROR: A trustgroup with that ID does not exist." );
207 controlreply ( sender
, "INTERNAL ERROR: Trustgroup has ID 0" );
211 if ( ipmask_parse ( cargv
[ 1 ], & sin
, & bits
) == 0 ) {
212 controlreply ( sender
, "ERROR: Invalid mask." );
216 if ( irc_in_addr_is_ipv4 (& sin
) ) {
217 if ( bits
> 128 || bits
< 112 ) {
218 controlreply ( sender
, "ERROR: Not a valid netmask (needs to be between 16 and 32)" );
223 controlreply ( sender
, "ERROR: Not a valid ipv6 netmask " );
229 expiry
= getnettime () + durationtolong ( cargv
[ 2 ]);
231 controlreply ( sender
, "ERROR: Invalid duration given" );
236 node
= refnode ( iptree
, & sin
, bits
);
237 if ( node
-> exts
[ tgh_ext
]) {
238 /* this mask is already trusted */
239 controlreply ( sender
, "ERROR: This mask is already trusted by trustgroup %l u." , (( trusthost_t
*) node
-> exts
[ tgh_ext
])-> trustgroup
-> id
);
242 if ( node
-> exts
[ tgb_ext
] ) {
243 controlreply ( sender
, "ERROR: A trustblock exists on this subnet, as follows: ID: %l u, public reason: %s " , (( trustblock_t
*) node
-> exts
[ tgb_ext
])-> id
, ((( trustblock_t
*) node
-> exts
[ tgb_ext
])-> reason_public
? (( trustblock_t
*) node
-> exts
[ tgb_ext
])-> reason_public
-> content
: "<none>" ));
247 /* check child status */
248 PATRICIA_WALK ( node
, inode
)
250 th
= inode
-> exts
[ tgh_ext
];
252 /* we have a child trustgroup */
253 /* Criteria 1: we can't add two hosts into the same group */
254 if ( th
-> trustgroup
== tg
) {
255 controlreply ( sender
, "ERROR: A child subnet is already in this trustgroup, remove that subnet first ( %s / %d )" , IPtostr ( inode
-> prefix
-> sin
), irc_bitlen (&( inode
-> prefix
-> sin
), inode
-> prefix
-> bitlen
));
258 /* Criteria 2: we can't trust a subnet containing a trustblock (unless you have +d flag, then warn) */
259 if ( inode
-> exts
[ tgb_ext
] ) {
260 controlreply ( sender
, "ERROR: A trustblock exists on a child subnet, as follows: ID: %l u, public reason: %s " , (( trustblock_t
*) inode
-> exts
[ tgb_ext
])-> id
, ((( trustblock_t
*) inode
-> exts
[ tgb_ext
])-> reason_public
? (( trustblock_t
*) inode
-> exts
[ tgb_ext
])-> reason_public
-> content
: "<none>" ));
267 /* check parents too */
268 parent
= node
-> parent
;
270 if ( parent
-> exts
[ tgh_ext
]) {
271 th
= parent
-> exts
[ tgh_ext
];
272 /* we have a parent trustgroup */
273 /* Criteria 1: we can't add two hosts into the same group */
274 if ( th
-> trustgroup
== tg
) {
275 controlreply ( sender
, "ERROR: A parent subnet is already in this trustgroup ( %s / %d )" , IPtostr ( parent
-> prefix
-> sin
), irc_bitlen (&( parent
-> prefix
-> sin
), parent
-> prefix
-> bitlen
));
278 /* even if we find 1 parent, we continue to the top */
279 /* Criteria 2: we can't trust a subnet containing a trustblock (unless you have +d flag, then warn) */
280 if ( parent
-> exts
[ tgb_ext
] ) {
281 controlreply ( sender
, "ERROR: A trustblock exists on a parent subnet, as follows: ID: %l u, public reason: %s " , (( trustblock_t
*) parent
-> exts
[ tgb_ext
])-> id
, ((( trustblock_t
*) parent
-> exts
[ tgb_ext
])-> reason_public
? (( trustblock_t
*) parent
-> exts
[ tgb_ext
])-> reason_public
-> content
: "<none>" ));
285 parent
= parent
-> parent
;
288 th
= trusthostadd ( node
, tg
, expiry
);
290 controlreply ( sender
, "ERROR: Unable to add trusted host" );
293 trustsdb_addtrusthost ( th
);
294 controlreply ( sender
, "Added %s to trustgroup # %l u" , cargv
[ 1 ], tg
-> id
);
295 controlwall ( NO_OPER
, NL_TRUSTS
, "Added %s to trustgroup # %l u" , cargv
[ 1 ], tg
-> id
);
299 int trust_dump ( void * source
, int cargc
, char ** cargv
) {
300 nick
* sender
=( nick
*) source
;
304 unsigned long startid
= 0 ;
305 long num
= 0 , count
= 0 , lines
= 0 ;
308 controlreply ( sender
, "Syntax: trustdump <start #id> <number>" );
309 controlreply ( sender
, "Dumps <number> trustgroups starting from <start #id>." );
310 controlreply ( sender
, "This allows to dump very large numbers of groups," );
311 controlreply ( sender
, "so use with care." );
314 strncpy ( tmps3
, cargv
[ 0 ], 20 );
316 num
= atoi ( cargv
[ 1 ]);
318 if ( tmps3
[ 0 ] != '#' ) {
319 controlreply ( sender
, "First parameter has to be a trust ID (prefixed with #)." );
323 startid
= strtoul (& tmps3
[ 1 ], NULL
, 10 );
325 controlreply ( sender
, "Cannot return fewer than 1 group." );
329 controlreply ( sender
, "Will not list more than 500 groups in one go." );
333 if ( startid
> trusts_lasttrustgroupid
) {
334 controlreply ( sender
, "Start ID cannot exceed maximum group ID (# %l d)." , trusts_lasttrustgroupid
);
339 g
= findtrustgroupbyid ( startid
);
341 } while (( g
== NULL
) && ( startid
<= ( trusts_lasttrustgroupid
+ 1 )));
343 controlreply ( sender
, "Failed to find nearest start group." );
347 while ( startid
<= ( trusts_lasttrustgroupid
+ 1 )) {
349 g
= findtrustgroupbyid ( startid
);
353 controlreply ( sender
, "G,# %l u, %l u, %l u, %d , %l u, %l u, %l u, %l u" ,
354 g
-> id
, g
-> currenton
, g
-> maxclones
, g
-> enforceident
, g
-> maxperident
,
355 g
-> maxusage
, g
-> expire
, g
-> lastused
);
360 int hash
= trusts_gettrusthostgroupidhash ( g
-> id
);
361 for ( thptr
= trusthostgroupidtable
[ hash
]; thptr
; thptr
= thptr
-> nextbygroupid
) {
362 if ( thptr
-> trustgroup
-> id
== g
-> id
) {
363 /* TODO: expire here - trusthost_free(thptr);*/
364 controlreply ( sender
, "H,# %l u, %s / %d , %l u, %l u, %l u" , g
-> id
,
365 IPtostr ((( patricia_node_t
*) thptr
-> node
)-> prefix
-> sin
),
366 irc_bitlen (&((( patricia_node_t
*) thptr
-> node
)-> prefix
-> sin
),(( patricia_node_t
*) thptr
-> node
)-> prefix
-> bitlen
),
367 0 /*a->currentlyon*/ ,
378 g
= findtrustgroupbyid ( startid
);
381 controlreply ( sender
, "End of list, %l d groups and %l d lines returned." , count
, lines
);
385 int trust_denyadd ( void * source
, int cargc
, char ** cargv
) {
386 nick
* sender
=( nick
*) source
;
387 struct irc_in_addr sin
;
390 patricia_node_t
* node
;
394 controlreply ( sender
, "Syntax: trustdenyadd IP[/mask] <expiry> <public reason>" );
398 if ( ipmask_parse ( cargv
[ 0 ], & sin
, & bits
) == 0 ) {
399 controlreply ( sender
, "ERROR: Invalid mask." );
403 if ( irc_in_addr_is_ipv4 (& sin
) ) {
404 if ( bits
> 128 || bits
< 112 ) {
405 controlreply ( sender
, "ERROR: Not a valid netmask (needs to be between 8 and 32)" );
410 controlreply ( sender
, "ERROR: Not a valid ipv6 netmask " );
415 expiry
= getnettime () + durationtolong ( cargv
[ 1 ]);
417 controlreply ( sender
, "ERROR: Invalid duration given" );
421 node
= refnode ( iptree
, & sin
, bits
);
422 if ( node
-> exts
[ tgb_ext
]) {
423 /* this mask is already blocked */
424 controlreply ( sender
, "ERROR: This mask is already blocked" , (( trustblock_t
*) node
-> exts
[ tgb_ext
])-> id
);
428 tb
= createtrustblock ( ++ trusts_lasttrustblockid
, node
, 0 /*TODO*/ , expiry
, NULL
, cargv
[ 2 ]);
430 controlreply ( sender
, "ERROR: An error occured adding the trustblock" );
432 node
-> exts
[ tgb_ext
] = tb
;
434 trustsdb_addtrustblock ( tb
);
435 controlreply ( sender
, "Added %s to trustblock list" , cargv
[ 0 ]);
436 controlwall ( NO_OPER
, NL_TRUSTS
, "Added %s to trustblock list" , cargv
[ 0 ]);
440 int trust_denycomment ( void * source
, int cargc
, char ** cargv
) {
441 nick
* sender
=( nick
*) source
;
442 struct irc_in_addr sin
;
444 patricia_node_t
* node
;
448 controlreply ( sender
, "Syntax: trustdenycomment IP[/mask] <private reason>" );
452 if ( ipmask_parse ( cargv
[ 0 ], & sin
, & bits
) == 0 ) {
453 controlreply ( sender
, "ERROR: Invalid mask." );
457 if ( irc_in_addr_is_ipv4 (& sin
) ) {
458 if ( bits
> 128 || bits
< 112 ) {
459 controlreply ( sender
, "ERROR: Not a valid netmask (needs to be between 8 and 32)" );
464 controlreply ( sender
, "ERROR: Not a valid ipv6 netmask " );
469 node
= refnode ( iptree
, & sin
, bits
);
470 if (! node
-> exts
[ tgb_ext
]) {
471 /* this mask is already blocked */
472 controlreply ( sender
, "ERROR: This mask is not blocked. Use trustdenyadd to add a new block" );
475 derefnode ( iptree
, node
);
476 tb
= node
-> exts
[ tgb_ext
];
478 tb
-> reason_private
= getsstring ( cargv
[ 1 ], 512 );
479 trustsdb_updatetrustblock ( tb
);
480 controlreply ( sender
, "Private Comment added to trustblock %s " , cargv
[ 0 ]);
481 controlwall ( NO_OPER
, NL_TRUSTS
, "Private Comment added to trustblock %s " , cargv
[ 0 ]);
485 int trust_denydel ( void * source
, int cargc
, char ** cargv
) {
486 nick
* sender
=( nick
*) source
;
487 struct irc_in_addr sin
;
489 patricia_node_t
* node
;
492 controlreply ( sender
, "Syntax: trustdenydel IP[/mask]" );
496 if ( ipmask_parse ( cargv
[ 0 ], & sin
, & bits
) == 0 ) {
497 controlreply ( sender
, "ERROR: Invalid mask." );
501 node
= refnode ( iptree
, & sin
, bits
);
502 if (! node
-> exts
[ tgb_ext
]) {
503 controlreply ( sender
, "ERROR: That CIDR was not blocked." );
506 controlreply ( sender
, "trustblock removed on %s " , cargv
[ 0 ]);
507 controlwall ( NO_OPER
, NL_TRUSTS
, "trustblock removed on %s " , cargv
[ 0 ]);
508 trustsdb_deletetrustblock ( node
-> exts
[ tgb_ext
]);
509 trustblock_free ( node
-> exts
[ tgb_ext
] );
510 node
-> exts
[ tgb_ext
] = NULL
;
512 controlreply ( sender
, "Not Implemented" );
516 int trust_groupmodify ( void * source
, int cargc
, char ** cargv
) {
517 nick
* sender
=( nick
*) source
;
518 unsigned long oldvalue
, newvalue
;
523 if ( cargc
< 3 || cargc
== 4 ) {
524 controlreply ( sender
, "Syntax: trustgroupmodify <#groupid> <what> [+|-|=]number" );
525 controlreply ( sender
, " +20 means add 20, =20 replaces current value, -20 means subtract" );
526 controlreply ( sender
, " what: maxclones, maxperident, maxperip, expire, enforceident, ownerid" );
530 if ( cargv
[ 0 ][ 0 ]== '#' ){
531 /* find group by id */
532 tg
= findtrustgroupbyid ( strtol (& cargv
[ 0 ][ 1 ], NULL
, 10 ));
534 /* find group by id */
535 tg
= findtrustgroupbyid ( strtol ( cargv
[ 0 ], NULL
, 10 ));
539 controlreply ( sender
, "ERROR: A trustgroup with that ID does not exist." );
544 controlreply ( sender
, "INTERNAL ERROR: Trustgroup has ID 0" );
548 switch ( cargv
[ 2 ][ 0 ] ) {
555 controlreply ( sender
, "ERROR: invalid modifier specified (values values are +,-,=)" );
558 newvalue
= strtoul (& cargv
[ 2 ][ 1 ], NULL
, 10 );
560 if ( ircd_strcmp ( cargv
[ 1 ], "maxclones" )== 0 ) {
561 oldvalue
= tg
-> maxclones
;
564 newvalue
= oldvalue
+ newvalue
;
567 if ( newvalue
> oldvalue
) {
568 controlreply ( sender
, "ERROR: maxclones cannot be less than 0" );
571 newvalue
= oldvalue
- newvalue
;
573 controlreply ( sender
, "ERROR: maxclones limit would be 0 - unlimited maxclones can only be set with '='" );
579 if ( newvalue
> 1000000 ) {
580 controlreply ( sender
, "ERROR: large maximum number of clients - %l u" , newvalue
);
583 if ( newvalue
> 10000 ) {
584 controlreply ( sender
, "WARNING: large maximum number of clients - %l u" , newvalue
);
587 tg
-> maxclones
= newvalue
;
588 } else if ( ircd_strcmp ( cargv
[ 1 ], "maxperident" )== 0 ) {
589 oldvalue
= tg
-> maxperident
;
592 newvalue
= oldvalue
+ newvalue
;
595 if ( newvalue
> oldvalue
) {
596 controlreply ( sender
, "ERROR: maxperident cannot be less than 0" );
599 newvalue
= oldvalue
- newvalue
;
601 controlreply ( sender
, "ERROR: maxperident limit would be 0 - unlimited maxclones can only be set with '='" );
608 controlreply ( sender
, "ERROR: MaxPerIdent value should be less then 50 (if set)" );
611 tg
-> maxperident
= newvalue
;
612 } else if ( ircd_strcmp ( cargv
[ 1 ], "maxperip" )== 0 ) {
613 oldvalue
= tg
-> maxperip
;
616 newvalue
= oldvalue
+ newvalue
;
619 if ( newvalue
> oldvalue
) {
620 controlreply ( sender
, "ERROR: maxperip cannot be less than 0" );
623 newvalue
= oldvalue
- newvalue
;
625 controlreply ( sender
, "ERROR: maxperip limit would be 0 - unlimited maxclones can only be set with '='" );
631 if ( newvalue
> 500 ) {
632 controlreply ( sender
, "ERROR: MaxPerIP value should be less then 500 (if set)" );
635 tg
-> maxperip
= newvalue
;
636 } else if ( ircd_strcmp ( cargv
[ 1 ], "expire" )== 0 ) {
637 oldvalue
= tg
-> expire
;
638 expiry
= durationtolong (& cargv
[ 2 ][ 1 ]);
640 if ( expiry
> ( 365 * 86400 ) ) {
641 controlreply ( sender
, "ERROR: Invalid duration given - temporary trusts can not be longer then 1 year" );
647 newvalue
= oldvalue
+ expiry
;
650 newvalue
= oldvalue
- expiry
;
651 if ( newvalue
< getnettime () ) {
652 controlreply ( sender
, "ERROR: Can't set expiry before current nettime - use trustgroupdel to delete trust groups" );
658 newvalue
= getnettime () + expiry
;
662 tg
-> expire
= newvalue
;
663 } else if ( ircd_strcmp ( cargv
[ 1 ], "enforceident" )== 0 ) {
664 oldvalue
= tg
-> enforceident
;
665 if ( ( newvalue
!= 0 && newvalue
!= 1 ) || * mod
!= '=' ) {
666 controlreply ( sender
, "ERROR: enforceident is a boolean setting, that means it can only be 0 or 1, and can only be set by '='" );
669 tg
-> enforceident
= newvalue
;
670 } else if ( ircd_strcmp ( cargv
[ 1 ], "ownerid" )== 0 ) {
671 oldvalue
= tg
-> ownerid
;
673 controlreply ( sender
, "ERROR: Q user ID can only be set by '='" );
676 if ( findtrustgroupbyownerid ( newvalue
) ) {
677 controlreply ( sender
, "ERROR: Q User ID %d already has a trustgroup" , newvalue
);
681 if ( newvalue
> 2147483646 ) {
682 controlreply ( sender
, "ERROR: Invalid Q User ID: %d " , newvalue
);
686 tg
-> ownerid
= newvalue
;
688 controlreply ( sender
, "Modification: %s changed to %l u from %l u for trustgroup %l u" , cargv
[ 1 ], newvalue
, oldvalue
, tg
-> id
);
689 controlwall ( NO_OPER
, NL_TRUSTS
, "Modification: %s changed to %l u from %l u for trustgroup %l u" , cargv
[ 1 ], newvalue
, oldvalue
, tg
-> id
);
691 trustsdb_updatetrustgroup ( tg
);
695 int trust_groupdel ( void * source
, int cargc
, char ** cargv
) {
696 nick
* sender
=( nick
*) source
;
697 trusthost_t
* thptr
, * nthptr
;
699 patricia_node_t
* node
;
702 controlreply ( sender
, "Syntax: trustgroupdel <#id|id>" );
706 if ( cargv
[ 0 ][ 0 ]== '#' ){
707 /* find group by id */
708 tg
= findtrustgroupbyid ( strtol (& cargv
[ 0 ][ 1 ], NULL
, 10 ));
710 /* find group by id */
711 tg
= findtrustgroupbyid ( strtol ( cargv
[ 0 ], NULL
, 10 ));
715 controlreply ( sender
, "ERROR: A trustgroup with that ID does not exist." );
720 controlreply ( sender
, "INTERNAL ERROR: Trustgroup has ID 0" );
724 /* we have a trustgroup to remove */
725 int hash
= trusts_gettrusthostgroupidhash ( tg
-> id
);
726 for ( thptr
= trusthostgroupidtable
[ hash
]; thptr
; thptr
= nthptr
) {
727 nthptr
= thptr
-> nextbygroupid
;
728 if ( thptr
-> trustgroup
== tg
) {
730 controlwall ( NO_OPER
, NL_TRUSTS
, " %s / %d removed from trustgroup # %l u" , IPtostr ( thptr
-> node
-> prefix
-> sin
), irc_bitlen (&( thptr
-> node
-> prefix
-> sin
), thptr
-> node
-> prefix
-> bitlen
), tg
-> id
);
731 controlreply ( sender
, " %s / %d removed from trustgroup # %l u" , IPtostr ( thptr
-> node
-> prefix
-> sin
), irc_bitlen (&( thptr
-> node
-> prefix
-> sin
), thptr
-> node
-> prefix
-> bitlen
), tg
-> id
);
732 trustsdb_deletetrusthost ( thptr
);
733 trusthost_free ( thptr
);
734 node
-> exts
[ tgh_ext
] = NULL
;
737 controlwall ( NO_OPER
, NL_TRUSTS
, "removed trustgroup # %l u" , tg
-> id
);
738 controlreply ( sender
, "removed trustgroup # %l u" , tg
-> id
);
739 trustsdb_deletetrustgroup ( tg
);
745 int trust_stats ( void * source
, int cargc
, char ** cargv
) {
746 nick
* sender
=( nick
*) source
;
747 trustgroup_t
* tg
; trusthost_t
* thptr
; int i
;
748 unsigned long thcount
= 0 , ucount
= 0 , mcount
= 0 , tgcount
= 0 ;
749 unsigned long hentries
= 0 ;
750 unsigned long netcount4
[ 33 ];
751 unsigned long netucount4
[ 33 ];
752 unsigned long netmcount4
[ 33 ];
753 unsigned long netcount6
[ 129 ];
754 unsigned long netucount6
[ 129 ];
755 unsigned long netmcount6
[ 129 ];
758 int maxthmask6
= 128 ;
760 for ( i
= 0 ; i
< 33 ; i
++) {
766 for ( i
= 0 ; i
< 129 ; i
++) {
772 for ( i
= 0 ; i
< TRUSTS_HASH_GROUPSIZE
; i
++ ) {
773 for ( tg
= trustgroupidtable
[ i
]; tg
; tg
= tg
-> nextbyid
) {
779 for ( i
= 0 ; i
< TRUSTS_HASH_HOSTSIZE
; i
++ ) {
780 for ( thptr
= trusthostidtable
[ i
]; thptr
; thptr
= thptr
-> nextbyid
) {
784 ucount
+= thptr
-> node
-> usercount
;
785 mcount
+= thptr
-> maxused
;
786 if ( irc_in_addr_is_ipv4 (&(( patricia_node_t
*) thptr
-> node
)-> prefix
-> sin
)) {
787 netcount4
[(( patricia_node_t
*) thptr
-> node
)-> prefix
-> bitlen
- 96 ]++;
788 netucount4
[(( patricia_node_t
*) thptr
-> node
)-> prefix
-> bitlen
- 96 ]+= thptr
-> node
-> usercount
;
789 netmcount4
[(( patricia_node_t
*) thptr
-> node
)-> prefix
-> bitlen
- 96 ]+= thptr
-> maxused
;
790 if ( ((( patricia_node_t
*) thptr
-> node
)-> prefix
-> bitlen
- 96 ) < maxthmask4
) {
791 maxthmask4
= ((( patricia_node_t
*) thptr
-> node
)-> prefix
-> bitlen
- 96 );
794 netcount6
[(( patricia_node_t
*) thptr
-> node
)-> prefix
-> bitlen
]++;
795 netucount6
[(( patricia_node_t
*) thptr
-> node
)-> prefix
-> bitlen
]+= thptr
-> node
-> usercount
;
796 netmcount6
[(( patricia_node_t
*) thptr
-> node
)-> prefix
-> bitlen
]+= thptr
-> maxused
;
797 if ( (( patricia_node_t
*) thptr
-> node
)-> prefix
-> bitlen
< maxthmask6
) {
798 maxthmask6
= (( patricia_node_t
*) thptr
-> node
)-> prefix
-> bitlen
;
803 controlreply ( sender
, "Online trust users: %l u" , ucount
);
804 controlreply ( sender
, "Maximum online users: %l u" , mcount
);
805 controlreply ( sender
, "Trust groups: %l u" , tgcount
);
806 controlreply ( sender
, "Maximum group ID: # %l u" , trusts_lasttrustgroupid
);
807 controlreply ( sender
, "Trusted hosts/nets: %l u" , thcount
);
808 controlreply ( sender
, "Largest subnet (v4): / %d " , maxthmask4
);
809 controlreply ( sender
, "Largest subnet (v6): / %d " , maxthmask6
);
810 controlreply ( sender
, "IPv4 Subnets:" );
811 for ( i
= 0 ; i
< 32 ; i
++) {
812 if ( netcount4
[ i
]== 0 ) continue ;
813 controlreply ( sender
, "|-*/ %d (Netcount: %l u Cur: %l u Max: %l u)" , i
, netcount4
[ i
], netucount4
[ i
], netmcount4
[ i
]);
815 controlreply ( sender
, "`-*/32 (Netcount: %l u Cur: %l u Max: %l u)" , netcount4
[ 32 ], netucount4
[ 32 ], netmcount4
[ 32 ]);
816 controlreply ( sender
, "IPv6 Subnets:" );
817 for ( i
= 0 ; i
< 128 ; i
++) {
818 if ( netcount6
[ i
]== 0 ) continue ;
819 controlreply ( sender
, "|-*/ %d (Netcount: %l u Cur: %l u Max: %l u)" , i
, netcount6
[ i
], netucount6
[ i
], netmcount6
[ i
]);
821 controlreply ( sender
, "`-*/128 (Netcount: %l u Cur: %l u Max: %l u)" , netcount6
[ 128 ], netucount6
[ 128 ], netmcount6
[ 128 ]);
827 int trust_comment ( void * source
, int cargc
, char ** cargv
) {
828 nick
* sender
=( nick
*) source
;
832 controlreply ( sender
, "Syntax: trustcomment <#groupid> <comment>" );
836 if ( cargv
[ 0 ][ 0 ]== '#' ){
837 /* find group by id */
838 tg
= findtrustgroupbyid ( strtol (& cargv
[ 0 ][ 1 ], NULL
, 10 ));
840 /* find group by id */
841 tg
= findtrustgroupbyid ( strtol ( cargv
[ 0 ], NULL
, 10 ));
845 controlreply ( sender
, "A trustgroup with that ID does not exist." );
850 controlreply ( sender
, "Internal error: Trustgroup has ID 0" );
854 trustsdb_logmessage ( tg
, 0 , 1 , cargv
[ 1 ]);
856 controlreply ( sender
, "Comment: %s for trustgroup %l u" , cargv
[ 1 ], tg
-> id
);
857 controlwall ( NO_OPER
, NL_TRUSTS
, "Comment: %s for trustgroup %l u" , cargv
[ 1 ], tg
-> id
);