]>
jfr.im git - irc/quakenet/newserv.git/blob - trusts2/trusts_commands.c
ac5d6491beba64332e129b34f81c4209976ae84c
1 #include "../core/schedule.h"
2 #include "../lib/irc_string.h"
3 #include "../localuser/localuserchannel.h"
4 #include "../control/control.h"
9 #include "../lib/version.h"
13 static int commandsregistered
;
16 registerhook ( HOOK_TRUSTS_DBLOADED
, trusts_cmdinit
);
18 /* Now that the database is in a separate module it might be loaded already. */
20 trusts_cmdinit ( HOOK_TRUSTS_DBLOADED
, NULL
);
25 deregisterhook ( HOOK_TRUSTS_DBLOADED
, trusts_cmdinit
);
26 trusts_cmdfini ( 0 , NULL
);
29 void trusts_cmdinit ( int hooknum
, void * arg
) {
30 if ( commandsregistered
)
32 registercontrolcmd ( "trustgroupadd" , 10 , 7 , trust_groupadd
);
33 registercontrolcmd ( "trustgroupmodify" , 10 , 4 , trust_groupmodify
);
34 registercontrolcmd ( "trustgroupdel" , 10 , 2 , trust_groupdel
);
36 registercontrolcmd ( "trustcomment" , 10 , 2 , trust_comment
);
38 registercontrolcmd ( "trustadd" , 10 , 3 , trust_add
);
39 registercontrolcmd ( "trustdel" , 10 , 2 , trust_del
);
41 registercontrolcmd ( "trustdenyadd" , 10 , 2 , trust_denyadd
);
42 registercontrolcmd ( "trustdenycomment" , 10 , 2 , trust_denycomment
);
43 registercontrolcmd ( "trustdenydel" , 10 , 2 , trust_denydel
);
45 registercontrolcmd ( "truststats" , 10 , 2 , trust_stats
);
46 registercontrolcmd ( "trustdump" , 10 , 2 , trust_dump
);
48 registercontrolcmd ( "trustlog" , 10 , 2 , trust_dotrustlog
);
50 commandsregistered
= 1 ;
54 void trusts_cmdfini () {
55 if (! commandsregistered
)
58 deregistercontrolcmd ( "trustgroupadd" , trust_groupadd
);
59 deregistercontrolcmd ( "trustgroupmodify" , trust_groupmodify
);
60 deregistercontrolcmd ( "trustgroupdel" , trust_groupdel
);
62 deregistercontrolcmd ( "trustcomment" , trust_comment
);
64 deregistercontrolcmd ( "trustadd" , trust_add
);
65 deregistercontrolcmd ( "trustdel" , trust_del
);
67 deregistercontrolcmd ( "trustdenyadd" , trust_denyadd
);
68 deregistercontrolcmd ( "trustdenycomment" , trust_denycomment
);
69 deregistercontrolcmd ( "trustdenydel" , trust_denydel
);
71 deregistercontrolcmd ( "truststats" , trust_stats
);
72 deregistercontrolcmd ( "trustdump" , trust_dump
);
74 deregistercontrolcmd ( "trustlog" , trust_dotrustlog
);
76 commandsregistered
= 0 ;
81 /* tgh - should this have a 'maxclones limit'? */
83 int trust_groupadd ( void * source
, int cargc
, char ** cargv
) {
84 nick
* sender
=( nick
*) source
;
86 unsigned long maxclones
;
87 unsigned short maxperip
;
88 unsigned long maxperident
;
91 unsigned long ownerid
;
95 controlreply ( sender
, "Usage: trustgroupadd howmany howlong maxperident maxperip enforceident type ownerid" );
99 maxclones
= strtoul ( cargv
[ 0 ], NULL
, 10 );
100 if ( maxclones
> 10000 ) {
101 /* we allow 0 for unlimited trusts, and only warn on this */
102 controlreply ( sender
, "WARNING: large maximum number of clients - %l u" , maxclones
);
104 expiry
= durationtolong ( cargv
[ 1 ]);
105 if ( expiry
> ( 365 * 86400 ) ) {
106 controlreply ( sender
, "ERROR: Invalid duration given - temporary trusts must be less than 1 year" );
109 ownerid
= strtoul ( cargv
[ 6 ], NULL
, 10 );
110 maxperip
= strtoul ( cargv
[ 3 ], NULL
, 10 );
111 if ( maxperip
> 500 ) {
112 controlreply ( sender
, "ERROR: MaxPerIP value should be less then 500 (if set)" );
115 maxperident
= strtoul ( cargv
[ 2 ], NULL
, 10 );
116 if ( maxperident
> 50 ) {
117 controlreply ( sender
, "ERROR: MaxPerIdent value should be less then 50 (if set)" );
120 if ((( cargv
[ 4 ][ 0 ]!= '0' ) && ( cargv
[ 4 ][ 0 ]!= '1' )) || ( cargv
[ 4 ][ 1 ]!= '\0' )) {
121 controlreply ( sender
, "ERROR: enforceident is a boolean setting, that means it can only be 0 or 1" );
124 enforceident
= cargv
[ 4 ][ 0 ] == '1' ;
126 if ( findtrustgroupbyownerid ( ownerid
) ) {
127 controlreply ( sender
, "ERROR: Q User ID %d already has a trustgroup" , ownerid
);
130 if ( ownerid
> 2147483646 ) {
131 controlreply ( sender
, "ERROR: Invalid Q User ID: %d " , ownerid
);
135 type
= strtoul ( cargv
[ 5 ], NULL
, 10 );
142 controlreply ( sender
, "Invalid Type ( %d )" , type
);
146 t
= createtrustgroup ( ++ trusts_lasttrustgroupid
, maxclones
, maxperident
, maxperip
, enforceident
, getnettime () + expiry
, ownerid
, type
);
149 controlreply ( sender
, "ERROR: An error occured adding trustgroup" );
153 trustsdb_addtrustgroup ( t
);
155 controlreply ( sender
, "Adding trustgroup with ID %l u" , t
-> id
);
156 controlreply ( sender
, "Connections: %d , Enforceident %d , Per ident: %d , Per IP %d " , maxclones
, enforceident
, maxperident
, maxperip
);
157 controlreply ( sender
, "Expires: %d , User ID: %d " , expiry
, ownerid
);
158 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
);
162 int trust_del ( void * source
, int cargc
, char ** cargv
) {
163 nick
* sender
=( nick
*) source
;
164 struct irc_in_addr sin
;
166 patricia_node_t
* node
;
170 controlreply ( sender
, "Syntax: trustdel IP[/mask]" );
174 if ( ipmask_parse ( cargv
[ 0 ], & sin
, & bits
) == 0 ) {
175 controlreply ( sender
, "ERROR: Invalid mask." );
179 if (! is_normalized_ipmask (& sin
, bits
)) {
180 controlreply ( sender
, "ERROR: non-normalized mask." );
184 node
= refnode ( iptree
, & sin
, bits
);
185 if (! node
-> exts
[ tgh_ext
]) {
186 controlreply ( sender
, "ERROR: That CIDR was not trusted." );
189 /*TODO: only allow a host to be removed if <X users? subnets? bah */
190 tg
= (( trusthost_t
*) node
-> exts
[ tgh_ext
])-> trustgroup
;
191 controlreply ( sender
, " %s removed from trustgroup # %l u" , cargv
[ 0 ], tg
-> id
);
192 controlwall ( NO_OPER
, NL_TRUSTS
, " %s removed from trustgroup # %l u" , cargv
[ 0 ], tg
-> id
);
193 trustsdb_deletetrusthost ( node
-> exts
[ tgh_ext
]);
194 trusthost_free ( node
-> exts
[ tgh_ext
]);
195 node
-> exts
[ tgh_ext
] = NULL
;
200 int trust_add ( void * source
, int cargc
, char ** cargv
) {
201 nick
* sender
=( nick
*) source
;
203 struct irc_in_addr sin
;
205 patricia_node_t
* node
, * inode
, * parent
;
210 controlreply ( sender
, "Syntax: trustadd <#groupid> IP[/mask] <duration>" );
214 if ( cargv
[ 0 ][ 0 ]== '#' ){
215 /* find group by id */
216 tg
= findtrustgroupbyid ( strtol (& cargv
[ 0 ][ 1 ], NULL
, 10 ));
218 /* find group by id */
219 tg
= findtrustgroupbyid ( strtol ( cargv
[ 0 ], NULL
, 10 ));
223 controlreply ( sender
, "ERROR: A trustgroup with that ID does not exist." );
228 controlreply ( sender
, "INTERNAL ERROR: Trustgroup has ID 0" );
232 if ( ipmask_parse ( cargv
[ 1 ], & sin
, & bits
) == 0 ) {
233 controlreply ( sender
, "ERROR: Invalid mask." );
237 if (! is_normalized_ipmask (& sin
, bits
)) {
238 controlreply ( sender
, "ERROR: non-normalized mask." );
242 if ( irc_in_addr_is_ipv4 (& sin
) ) {
243 if ( bits
> 128 || bits
< 112 ) {
244 controlreply ( sender
, "ERROR: Not a valid netmask (needs to be between 16 and 32)" );
249 controlreply ( sender
, "ERROR: Not a valid ipv6 netmask " );
255 expiry
= getnettime () + durationtolong ( cargv
[ 2 ]);
257 controlreply ( sender
, "ERROR: Invalid duration given" );
262 node
= refnode ( iptree
, & sin
, bits
);
263 if ( node
-> exts
[ tgh_ext
]) {
264 /* this mask is already trusted */
265 controlreply ( sender
, "ERROR: This mask is already trusted by trustgroup %l u." , (( trusthost_t
*) node
-> exts
[ tgh_ext
])-> trustgroup
-> id
);
268 if ( node
-> exts
[ tgb_ext
] ) {
269 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>" ));
273 /* check child status */
274 PATRICIA_WALK ( node
, inode
)
276 th
= inode
-> exts
[ tgh_ext
];
278 /* we have a child trustgroup */
279 /* Criteria 1: we can't add two hosts into the same group */
280 if ( th
-> trustgroup
== tg
) {
281 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
));
284 /* Criteria 2: we can't trust a subnet containing a trustblock (unless you have +d flag, then warn) */
285 if ( inode
-> exts
[ tgb_ext
] ) {
286 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>" ));
293 /* check parents too */
294 parent
= node
-> parent
;
296 if ( parent
-> exts
[ tgh_ext
]) {
297 th
= parent
-> exts
[ tgh_ext
];
298 /* we have a parent trustgroup */
299 /* Criteria 1: we can't add two hosts into the same group */
300 if ( th
-> trustgroup
== tg
) {
301 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
));
304 /* even if we find 1 parent, we continue to the top */
305 /* Criteria 2: we can't trust a subnet containing a trustblock (unless you have +d flag, then warn) */
306 if ( parent
-> exts
[ tgb_ext
] ) {
307 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>" ));
311 parent
= parent
-> parent
;
314 th
= trusthostadd ( node
, tg
, expiry
);
316 controlreply ( sender
, "ERROR: Unable to add trusted host" );
320 trustsdb_addtrusthost ( th
);
321 controlreply ( sender
, "Added %s to trustgroup # %l u" , cargv
[ 1 ], tg
-> id
);
322 controlwall ( NO_OPER
, NL_TRUSTS
, "Added %s to trustgroup # %l u" , cargv
[ 1 ], tg
-> id
);
326 int trust_dump ( void * source
, int cargc
, char ** cargv
) {
327 nick
* sender
=( nick
*) source
;
331 unsigned long startid
= 0 ;
332 long num
= 0 , count
= 0 , lines
= 0 ;
335 controlreply ( sender
, "Syntax: trustdump <start #id> <number>" );
336 controlreply ( sender
, "Dumps <number> trustgroups starting from <start #id>." );
337 controlreply ( sender
, "This allows to dump very large numbers of groups," );
338 controlreply ( sender
, "so use with care." );
341 strncpy ( tmps3
, cargv
[ 0 ], 20 );
343 num
= atoi ( cargv
[ 1 ]);
345 if ( tmps3
[ 0 ] != '#' ) {
346 controlreply ( sender
, "First parameter has to be a trust ID (prefixed with #)." );
350 startid
= strtoul (& tmps3
[ 1 ], NULL
, 10 );
352 controlreply ( sender
, "Cannot return fewer than 1 group." );
356 controlreply ( sender
, "Will not list more than 500 groups in one go." );
360 if ( startid
> trusts_lasttrustgroupid
) {
361 controlreply ( sender
, "Start ID cannot exceed maximum group ID (# %l d)." , trusts_lasttrustgroupid
);
366 g
= findtrustgroupbyid ( startid
);
368 } while (( g
== NULL
) && ( startid
<= ( trusts_lasttrustgroupid
+ 1 )));
370 controlreply ( sender
, "Failed to find nearest start group." );
374 while ( startid
<= ( trusts_lasttrustgroupid
+ 1 )) {
376 g
= findtrustgroupbyid ( startid
);
380 controlreply ( sender
, "G,# %l u, %l u, %l u, %d , %l u, %l u, %l u, %l u" ,
381 g
-> id
, g
-> currenton
, g
-> maxclones
, g
-> enforceident
, g
-> maxperident
,
382 g
-> maxusage
, g
-> expire
, g
-> lastused
);
387 int hash
= trusts_gettrusthostgroupidhash ( g
-> id
);
388 for ( thptr
= trusthostgroupidtable
[ hash
]; thptr
; thptr
= thptr
-> nextbygroupid
) {
389 if ( thptr
-> trustgroup
-> id
== g
-> id
) {
390 /* TODO: expire here - trusthost_free(thptr);*/
391 controlreply ( sender
, "H,# %l u, %s / %d , %l u, %l u, %l u" , g
-> id
,
392 IPtostr ((( patricia_node_t
*) thptr
-> node
)-> prefix
-> sin
),
393 irc_bitlen (&((( patricia_node_t
*) thptr
-> node
)-> prefix
-> sin
),(( patricia_node_t
*) thptr
-> node
)-> prefix
-> bitlen
),
394 0 /*a->currentlyon*/ ,
405 g
= findtrustgroupbyid ( startid
);
408 controlreply ( sender
, "End of list, %l d groups and %l d lines returned." , count
, lines
);
412 int trust_denyadd ( void * source
, int cargc
, char ** cargv
) {
413 nick
* sender
=( nick
*) source
;
414 struct irc_in_addr sin
;
417 patricia_node_t
* node
;
421 controlreply ( sender
, "Syntax: trustdenyadd IP[/mask] <expiry> <public reason>" );
425 if ( ipmask_parse ( cargv
[ 0 ], & sin
, & bits
) == 0 ) {
426 controlreply ( sender
, "ERROR: Invalid mask." );
430 if (! is_normalized_ipmask (& sin
, bits
)) {
431 controlreply ( sender
, "ERROR: non-normalized mask." );
435 if ( irc_in_addr_is_ipv4 (& sin
) ) {
436 if ( bits
> 128 || bits
< 112 ) {
437 controlreply ( sender
, "ERROR: Not a valid netmask (needs to be between 8 and 32)" );
442 controlreply ( sender
, "ERROR: Not a valid ipv6 netmask " );
447 expiry
= getnettime () + durationtolong ( cargv
[ 1 ]);
449 controlreply ( sender
, "ERROR: Invalid duration given" );
453 node
= refnode ( iptree
, & sin
, bits
);
454 if ( node
-> exts
[ tgb_ext
]) {
455 /* this mask is already blocked */
456 controlreply ( sender
, "ERROR: This mask is already blocked" , (( trustblock_t
*) node
-> exts
[ tgb_ext
])-> id
);
460 tb
= createtrustblock ( ++ trusts_lasttrustblockid
, node
, 0 /*TODO*/ , expiry
, NULL
, cargv
[ 2 ]);
462 controlreply ( sender
, "ERROR: An error occured adding the trustblock" );
464 node
-> exts
[ tgb_ext
] = tb
;
466 trustsdb_addtrustblock ( tb
);
467 controlreply ( sender
, "Added %s to trustblock list" , cargv
[ 0 ]);
468 controlwall ( NO_OPER
, NL_TRUSTS
, "Added %s to trustblock list" , cargv
[ 0 ]);
472 int trust_denycomment ( void * source
, int cargc
, char ** cargv
) {
473 nick
* sender
=( nick
*) source
;
474 struct irc_in_addr sin
;
476 patricia_node_t
* node
;
480 controlreply ( sender
, "Syntax: trustdenycomment IP[/mask] <private reason>" );
484 if ( ipmask_parse ( cargv
[ 0 ], & sin
, & bits
) == 0 ) {
485 controlreply ( sender
, "ERROR: Invalid mask." );
489 if (! is_normalized_ipmask (& sin
, bits
)) {
490 controlreply ( sender
, "ERROR: non-normalized mask." );
494 if ( irc_in_addr_is_ipv4 (& sin
) ) {
495 if ( bits
> 128 || bits
< 112 ) {
496 controlreply ( sender
, "ERROR: Not a valid netmask (needs to be between 8 and 32)" );
501 controlreply ( sender
, "ERROR: Not a valid ipv6 netmask " );
506 node
= refnode ( iptree
, & sin
, bits
);
507 if (! node
-> exts
[ tgb_ext
]) {
508 /* this mask is already blocked */
509 controlreply ( sender
, "ERROR: This mask is not blocked. Use trustdenyadd to add a new block" );
512 derefnode ( iptree
, node
);
513 tb
= node
-> exts
[ tgb_ext
];
515 tb
-> reason_private
= getsstring ( cargv
[ 1 ], 512 );
516 trustsdb_updatetrustblock ( tb
);
517 controlreply ( sender
, "Private Comment added to trustblock %s " , cargv
[ 0 ]);
518 controlwall ( NO_OPER
, NL_TRUSTS
, "Private Comment added to trustblock %s " , cargv
[ 0 ]);
522 int trust_denydel ( void * source
, int cargc
, char ** cargv
) {
523 nick
* sender
=( nick
*) source
;
524 struct irc_in_addr sin
;
526 patricia_node_t
* node
;
529 controlreply ( sender
, "Syntax: trustdenydel IP[/mask]" );
533 if ( ipmask_parse ( cargv
[ 0 ], & sin
, & bits
) == 0 ) {
534 controlreply ( sender
, "ERROR: Invalid mask." );
538 if (! is_normalized_ipmask (& sin
, bits
)) {
539 controlreply ( sender
, "ERROR: non-normalized mask." );
543 node
= refnode ( iptree
, & sin
, bits
);
544 if (! node
-> exts
[ tgb_ext
]) {
545 controlreply ( sender
, "ERROR: That CIDR was not blocked." );
548 controlreply ( sender
, "trustblock removed on %s " , cargv
[ 0 ]);
549 controlwall ( NO_OPER
, NL_TRUSTS
, "trustblock removed on %s " , cargv
[ 0 ]);
550 trustsdb_deletetrustblock ( node
-> exts
[ tgb_ext
]);
551 trustblock_free ( node
-> exts
[ tgb_ext
] );
552 node
-> exts
[ tgb_ext
] = NULL
;
554 controlreply ( sender
, "Not Implemented" );
558 int trust_groupmodify ( void * source
, int cargc
, char ** cargv
) {
559 nick
* sender
=( nick
*) source
;
560 unsigned long oldvalue
, newvalue
;
565 if ( cargc
< 3 || cargc
== 4 ) {
566 controlreply ( sender
, "Syntax: trustgroupmodify <#groupid> <what> [+|-|=]number" );
567 controlreply ( sender
, " +20 means add 20, =20 replaces current value, -20 means subtract" );
568 controlreply ( sender
, " what: maxclones, maxperident, maxperip, expire, enforceident, ownerid" );
572 if ( cargv
[ 0 ][ 0 ]== '#' ){
573 /* find group by id */
574 tg
= findtrustgroupbyid ( strtol (& cargv
[ 0 ][ 1 ], NULL
, 10 ));
576 /* find group by id */
577 tg
= findtrustgroupbyid ( strtol ( cargv
[ 0 ], NULL
, 10 ));
581 controlreply ( sender
, "ERROR: A trustgroup with that ID does not exist." );
586 controlreply ( sender
, "INTERNAL ERROR: Trustgroup has ID 0" );
590 switch ( cargv
[ 2 ][ 0 ] ) {
597 controlreply ( sender
, "ERROR: invalid modifier specified (values values are +,-,=)" );
600 newvalue
= strtoul (& cargv
[ 2 ][ 1 ], NULL
, 10 );
602 if ( ircd_strcmp ( cargv
[ 1 ], "maxclones" )== 0 ) {
603 oldvalue
= tg
-> maxclones
;
606 newvalue
= oldvalue
+ newvalue
;
609 if ( newvalue
> oldvalue
) {
610 controlreply ( sender
, "ERROR: maxclones cannot be less than 0" );
613 newvalue
= oldvalue
- newvalue
;
615 controlreply ( sender
, "ERROR: maxclones limit would be 0 - unlimited maxclones can only be set with '='" );
621 if ( newvalue
> 1000000 ) {
622 controlreply ( sender
, "ERROR: large maximum number of clients - %l u" , newvalue
);
625 if ( newvalue
> 10000 ) {
626 controlreply ( sender
, "WARNING: large maximum number of clients - %l u" , newvalue
);
629 tg
-> maxclones
= newvalue
;
630 } else if ( ircd_strcmp ( cargv
[ 1 ], "maxperident" )== 0 ) {
631 oldvalue
= tg
-> maxperident
;
634 newvalue
= oldvalue
+ newvalue
;
637 if ( newvalue
> oldvalue
) {
638 controlreply ( sender
, "ERROR: maxperident cannot be less than 0" );
641 newvalue
= oldvalue
- newvalue
;
643 controlreply ( sender
, "ERROR: maxperident limit would be 0 - unlimited maxclones can only be set with '='" );
650 controlreply ( sender
, "ERROR: MaxPerIdent value should be less then 50 (if set)" );
653 tg
-> maxperident
= newvalue
;
654 } else if ( ircd_strcmp ( cargv
[ 1 ], "maxperip" )== 0 ) {
655 oldvalue
= tg
-> maxperip
;
658 newvalue
= oldvalue
+ newvalue
;
661 if ( newvalue
> oldvalue
) {
662 controlreply ( sender
, "ERROR: maxperip cannot be less than 0" );
665 newvalue
= oldvalue
- newvalue
;
667 controlreply ( sender
, "ERROR: maxperip limit would be 0 - unlimited maxclones can only be set with '='" );
673 if ( newvalue
> 500 ) {
674 controlreply ( sender
, "ERROR: MaxPerIP value should be less then 500 (if set)" );
677 tg
-> maxperip
= newvalue
;
678 } else if ( ircd_strcmp ( cargv
[ 1 ], "expire" )== 0 ) {
679 oldvalue
= tg
-> expire
;
680 expiry
= durationtolong (& cargv
[ 2 ][ 1 ]);
682 if ( expiry
> ( 365 * 86400 ) ) {
683 controlreply ( sender
, "ERROR: Invalid duration given - temporary trusts can not be longer then 1 year" );
689 newvalue
= oldvalue
+ expiry
;
692 newvalue
= oldvalue
- expiry
;
693 if ( newvalue
< getnettime () ) {
694 controlreply ( sender
, "ERROR: Can't set expiry before current nettime - use trustgroupdel to delete trust groups" );
700 newvalue
= getnettime () + expiry
;
704 tg
-> expire
= newvalue
;
705 } else if ( ircd_strcmp ( cargv
[ 1 ], "enforceident" )== 0 ) {
706 oldvalue
= tg
-> enforceident
;
707 if ( ( newvalue
!= 0 && newvalue
!= 1 ) || * mod
!= '=' ) {
708 controlreply ( sender
, "ERROR: enforceident is a boolean setting, that means it can only be 0 or 1, and can only be set by '='" );
711 tg
-> enforceident
= newvalue
;
712 } else if ( ircd_strcmp ( cargv
[ 1 ], "ownerid" )== 0 ) {
713 oldvalue
= tg
-> ownerid
;
715 controlreply ( sender
, "ERROR: Q user ID can only be set by '='" );
718 if ( findtrustgroupbyownerid ( newvalue
) ) {
719 controlreply ( sender
, "ERROR: Q User ID %d already has a trustgroup" , newvalue
);
723 if ( newvalue
> 2147483646 ) {
724 controlreply ( sender
, "ERROR: Invalid Q User ID: %d " , newvalue
);
728 tg
-> ownerid
= newvalue
;
730 controlreply ( sender
, "Modification: %s changed to %l u from %l u for trustgroup %l u" , cargv
[ 1 ], newvalue
, oldvalue
, tg
-> id
);
731 controlwall ( NO_OPER
, NL_TRUSTS
, "Modification: %s changed to %l u from %l u for trustgroup %l u" , cargv
[ 1 ], newvalue
, oldvalue
, tg
-> id
);
733 trustsdb_updatetrustgroup ( tg
);
737 int trust_groupdel ( void * source
, int cargc
, char ** cargv
) {
738 nick
* sender
=( nick
*) source
;
739 trusthost_t
* thptr
, * nthptr
;
741 patricia_node_t
* node
;
744 controlreply ( sender
, "Syntax: trustgroupdel <#id|id>" );
748 if ( cargv
[ 0 ][ 0 ]== '#' ){
749 /* find group by id */
750 tg
= findtrustgroupbyid ( strtol (& cargv
[ 0 ][ 1 ], NULL
, 10 ));
752 /* find group by id */
753 tg
= findtrustgroupbyid ( strtol ( cargv
[ 0 ], NULL
, 10 ));
757 controlreply ( sender
, "ERROR: A trustgroup with that ID does not exist." );
762 controlreply ( sender
, "INTERNAL ERROR: Trustgroup has ID 0" );
766 /* we have a trustgroup to remove */
767 int hash
= trusts_gettrusthostgroupidhash ( tg
-> id
);
768 for ( thptr
= trusthostgroupidtable
[ hash
]; thptr
; thptr
= nthptr
) {
769 nthptr
= thptr
-> nextbygroupid
;
770 if ( thptr
-> trustgroup
== tg
) {
772 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
);
773 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
);
774 trustsdb_deletetrusthost ( thptr
);
775 trusthost_free ( thptr
);
776 node
-> exts
[ tgh_ext
] = NULL
;
779 controlwall ( NO_OPER
, NL_TRUSTS
, "removed trustgroup # %l u" , tg
-> id
);
780 controlreply ( sender
, "removed trustgroup # %l u" , tg
-> id
);
781 trustsdb_deletetrustgroup ( tg
);
787 int trust_stats ( void * source
, int cargc
, char ** cargv
) {
788 nick
* sender
=( nick
*) source
;
789 trustgroup_t
* tg
; trusthost_t
* thptr
; int i
;
790 unsigned long thcount
= 0 , ucount
= 0 , mcount
= 0 , tgcount
= 0 ;
791 unsigned long hentries
= 0 ;
792 unsigned long netcount4
[ 33 ];
793 unsigned long netucount4
[ 33 ];
794 unsigned long netmcount4
[ 33 ];
795 unsigned long netcount6
[ 129 ];
796 unsigned long netucount6
[ 129 ];
797 unsigned long netmcount6
[ 129 ];
800 int maxthmask6
= 128 ;
802 for ( i
= 0 ; i
< 33 ; i
++) {
808 for ( i
= 0 ; i
< 129 ; i
++) {
814 for ( i
= 0 ; i
< TRUSTS_HASH_GROUPSIZE
; i
++ ) {
815 for ( tg
= trustgroupidtable
[ i
]; tg
; tg
= tg
-> nextbyid
) {
821 for ( i
= 0 ; i
< TRUSTS_HASH_HOSTSIZE
; i
++ ) {
822 for ( thptr
= trusthostidtable
[ i
]; thptr
; thptr
= thptr
-> nextbyid
) {
826 ucount
+= thptr
-> node
-> usercount
;
827 mcount
+= thptr
-> maxused
;
828 if ( irc_in_addr_is_ipv4 (&(( patricia_node_t
*) thptr
-> node
)-> prefix
-> sin
)) {
829 netcount4
[(( patricia_node_t
*) thptr
-> node
)-> prefix
-> bitlen
- 96 ]++;
830 netucount4
[(( patricia_node_t
*) thptr
-> node
)-> prefix
-> bitlen
- 96 ]+= thptr
-> node
-> usercount
;
831 netmcount4
[(( patricia_node_t
*) thptr
-> node
)-> prefix
-> bitlen
- 96 ]+= thptr
-> maxused
;
832 if ( ((( patricia_node_t
*) thptr
-> node
)-> prefix
-> bitlen
- 96 ) < maxthmask4
) {
833 maxthmask4
= ((( patricia_node_t
*) thptr
-> node
)-> prefix
-> bitlen
- 96 );
836 controlreply ( sender
, " %s " , IPtostr ((( patricia_node_t
*) thptr
-> node
)-> prefix
-> sin
));
837 netcount6
[(( patricia_node_t
*) thptr
-> node
)-> prefix
-> bitlen
]++;
838 netucount6
[(( patricia_node_t
*) thptr
-> node
)-> prefix
-> bitlen
]+= thptr
-> node
-> usercount
;
839 netmcount6
[(( patricia_node_t
*) thptr
-> node
)-> prefix
-> bitlen
]+= thptr
-> maxused
;
840 if ( (( patricia_node_t
*) thptr
-> node
)-> prefix
-> bitlen
< maxthmask6
) {
841 maxthmask6
= (( patricia_node_t
*) thptr
-> node
)-> prefix
-> bitlen
;
846 controlreply ( sender
, "Online trust users: %l u" , ucount
);
847 controlreply ( sender
, "Maximum online users: %l u" , mcount
);
848 controlreply ( sender
, "Trust groups: %l u" , tgcount
);
849 controlreply ( sender
, "Maximum group ID: # %l u" , trusts_lasttrustgroupid
);
850 controlreply ( sender
, "Trusted hosts/nets: %l u" , thcount
);
851 controlreply ( sender
, "Largest subnet (v4): / %d " , maxthmask4
);
852 controlreply ( sender
, "Largest subnet (v6): / %d " , maxthmask6
);
853 controlreply ( sender
, "IPv4 Subnets:" );
854 for ( i
= 0 ; i
< 32 ; i
++) {
855 if ( netcount4
[ i
]== 0 ) continue ;
856 controlreply ( sender
, "|-*/ %d (Netcount: %l u Cur: %l u Max: %l u)" , i
, netcount4
[ i
], netucount4
[ i
], netmcount4
[ i
]);
858 controlreply ( sender
, "`-*/32 (Netcount: %l u Cur: %l u Max: %l u)" , netcount4
[ 32 ], netucount4
[ 32 ], netmcount4
[ 32 ]);
859 controlreply ( sender
, "IPv6 Subnets:" );
860 for ( i
= 0 ; i
< 128 ; i
++) {
861 if ( netcount6
[ i
]== 0 ) continue ;
862 controlreply ( sender
, "|-*/ %d (Netcount: %l u Cur: %l u Max: %l u)" , i
, netcount6
[ i
], netucount6
[ i
], netmcount6
[ i
]);
864 controlreply ( sender
, "`-*/128 (Netcount: %l u Cur: %l u Max: %l u)" , netcount6
[ 128 ], netucount6
[ 128 ], netmcount6
[ 128 ]);
870 int trust_comment ( void * source
, int cargc
, char ** cargv
) {
871 nick
* sender
=( nick
*) source
;
875 controlreply ( sender
, "Syntax: trustcomment <#groupid> <comment>" );
879 if ( cargv
[ 0 ][ 0 ]== '#' ){
880 /* find group by id */
881 tg
= findtrustgroupbyid ( strtol (& cargv
[ 0 ][ 1 ], NULL
, 10 ));
883 /* find group by id */
884 tg
= findtrustgroupbyid ( strtol ( cargv
[ 0 ], NULL
, 10 ));
888 controlreply ( sender
, "A trustgroup with that ID does not exist." );
893 controlreply ( sender
, "Internal error: Trustgroup has ID 0" );
897 trustsdb_logmessage ( tg
, 0 , 1 , cargv
[ 1 ]);
899 controlreply ( sender
, "Comment: %s for trustgroup %l u" , cargv
[ 1 ], tg
-> id
);
900 controlwall ( NO_OPER
, NL_TRUSTS
, "Comment: %s for trustgroup %l u" , cargv
[ 1 ], tg
-> id
);
905 int trust_dotrustlog ( void * source
, int cargc
, char ** cargv
) {
907 unsigned long interval
;
911 controlreply ( np
, "Syntax: trustlog <#groupid> [duration]" );
915 if ( cargv
[ 0 ][ 0 ]== '#' ){
916 trustid
= strtol (& cargv
[ 0 ][ 1 ], NULL
, 10 );
918 trustid
= strtol ( cargv
[ 0 ], NULL
, 10 );
922 interval
= getnettime () - durationtolong ( cargv
[ 1 ]);
926 trustsdb_retrievetrustlog ( np
, trustid
, interval
);