Skip to content

Commit

Permalink
more work on TS6 bans. #32. moved fnv() to utils.pm. fixed some oper …
Browse files Browse the repository at this point in the history
…notices which were broken since the changes to ->notice_info().
  • Loading branch information
cooper committed Jul 23, 2016
1 parent de5f50c commit 8dcea06
Show file tree
Hide file tree
Showing 19 changed files with 148 additions and 48 deletions.
3 changes: 3 additions & 0 deletions INDEV
Original file line number Diff line number Diff line change
Expand Up @@ -3423,3 +3423,6 @@ CHANGES:
->notice_info() can now be called on servers as well, which yields the server name and SID.

56. working on implementing bans in TS6. added some outgoing commands. #32.
more work on TS6 bans. #32.
moved fnv() to utils.pm.
fixed some oper notices which were broken since the changes to ->notice_info().
2 changes: 1 addition & 1 deletion modules/Ban/Ban.module/Ban.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"description" : "provides an interface for user and server banning",
"name" : "Ban",
"package" : "M::Ban",
"version" : "9.1"
"version" : "9.2"
}
2 changes: 1 addition & 1 deletion modules/Ban/Ban.module/Ban.pm
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ sub handle_del_command {
# delete it
delete_ban_by_id($ban{id});
expire_ban(%ban, deleted => 1);
$pool->fire_command_all(bandel => $ban{id});
$pool->fire_command_all(bandel => \%ban);

# notices
my $notice = gnotice("${type_name}_delete" => $ban{match}, $user->notice_info);
Expand Down
2 changes: 1 addition & 1 deletion modules/Ban/Ban.module/JELP.module/JELP.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"description" : "JELP ban propagation",
"name" : "Ban::JELP",
"package" : "M::Ban::JELP",
"version" : "0.7"
"version" : "0.8"
}
2 changes: 1 addition & 1 deletion modules/Ban/Ban.module/JELP.module/JELP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ sub ocmd_banidk {
# BANDEL: delete a ban
sub ocmd_bandel {
my $to_server = shift;
my $str = join ' ', @_;
my $str = join ' ', map $_->{id}, @_;
":$$me{sid} BANDEL $str"
}

Expand Down
2 changes: 1 addition & 1 deletion modules/Ban/Ban.module/TS6.module/TS6.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"description" : "TS6 ban propagation",
"name" : "Ban::TS6",
"package" : "M::Ban::TS6",
"version" : "1"
"version" : "2.2"
}
132 changes: 113 additions & 19 deletions modules/Ban/Ban.module/TS6.module/TS6.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use warnings;
use strict;
use 5.010;

use utils qw(fnv);
use M::TS6::Utils qw(ts6_id);

M::Ban->import(qw(
Expand All @@ -30,9 +31,29 @@ M::Ban->import(qw(

our ($api, $mod, $pool, $conf, $me);

###########
### TS6 ###
###########
our %ts6_capabilities = (
KLN => { required => 0 },
UNKLN => { required => 0 }
);

our %ts6_outgoing_commands = (
ban => \&out_ban,
baninfo => \&out_baninfo,
bandel => \&out_bandel
);

our %ts6_incoming_commands = (
ENCAP_KLINE => {
# :uid ENCAP target KLINE duration ident_mask host_mask :reason
params => '-source(user) * * * * * *',
code => \&kline
},
ENCAP_DLINE => {
# :uid ENCAP target DLINE duration ip_mask :reason
params => '-source(user) * * * * *',
code => \&dline
}
);

sub init {

Expand All @@ -46,6 +67,56 @@ sub init {
return 1;
}

# takes a ban hash and returns one ready for ts6 use
sub ts6_ban {
my %ban = @_;

# TS6 only supports kdlines
return unless $ban{type} eq 'kline' || $ban{type} eq 'dline';

# create an ID based on the fnv hash of the mask
$ban{id} //= fnv($ban{match});

# TS6 durations are in minutes rather than seconds, so convert this.
# (if it's permanent it will be zero which is the same)
my $duration = $ban{duration};
if ($duration) {
$duration = int($duration / 60 + 0.5);
$duration = 1 if $duration < 1;
$ban{duration} = $duration;
}

# add user and host if there's an @
if ($ban{match} =~ m/^(.*?)\@(.*)$/) {
$ban{match_user} = $1;
$ban{match_host} = $2;
}
else {
$ban{match_user} = '*';
$ban{match_host} = $ban{match};
}

# match_ts6 is special for using in ts6 commands.
# if it's a KLINE, it's match_user and match_host joined by a space.
# if it's a DLINE, it's the match_host.
$ban{match_ts6} = $ban{type} eq 'kline' ?
join(' ', @ban{'match_user', 'match_host'}) : $ban{match_host};

return %ban;
}

# create and register a ban
sub create_ts6_ban {
my %ban = ts6_ban(@_);
add_or_update_ban(%ban);
enforce_ban(%ban);
activate_ban(%ban);
}

################
### OUTGOING ###
################

# kdlines are NOT usually global and therefore are not bursted in TS6.
# so we can't assume that the server is going to give us any info about its
# local bans. that typically only happens when providing "ON <server>" to the
Expand All @@ -72,10 +143,8 @@ sub out_ban {

# baninfo is the advertisement of a ban. in TS6, use ENCAP K/DLINE
sub out_baninfo {
my ($to_server, $ban, $from) = @_;

# TS6 only supports kdlines
return unless $ban->{type} eq 'kline' || $ban->{type} eq 'dline';
my ($to_server, $ban_, $from) = @_;
my %ban = ts6_ban(%$ban_) or return;

# FIXME: LOL! ENCAP K/DLINE can only come from a user.
# if there's no user, this is probably during burst.
Expand All @@ -84,24 +153,49 @@ sub out_baninfo {
return if !$from;
}

# TS6 durations are in minutes rather than seconds, so convert this.
# (if it's permanent it will be zero which is the same)
my $duration = $ban->{duration};
if ($duration) {
$duration = int($duration / 60 + 0.5);
$duration = 1 if $duration < 1;
}

# charybdis will send the encap target as it is received from the oper.
# we don't care about that though. juno bans are global.

return sprintf ':%s ENCAP * %s %d %s :%s',
ts6_id($from),
uc $ban->{type},
$duration,
$ban->{match},
$ban->{reason};
uc $ban{type},
$ban{duration} || 0,
$ban{match_ts6},
$ban{reason} // 'no reason';
}

# bandel is sent out when a ban is removed. in TS6, use ENCAP UNK/DLINE
sub out_bandel {
my ($to_server, $ban_, $from) = @_;
my %ban = ts6_ban(%$ban_) or return;

# FIXME: LOL! ENCAP K/DLINE can only come from a user.
# if there's no user, this is probably during burst.
if (!$from || !$from->isa('user')) {
$from = ($pool->local_users)[0];
return if !$from;
}

return sprintf ':%s ENCAP * UN%s %s',
ts6_id($from),
uc $ban{type},
$ban{match_ts6};
}

################
### INCOMING ###
################


sub kline {
my ($server, $msg, $user, $serv_mask, undef,
$duration, $ident_mask, $host_mask, $reason) = @_;

}

sub dline {
my ($server, $msg, $user, $serv_mask, undef,
$duration, $ip_mask, $reason) = @_;
}

$mod
2 changes: 1 addition & 1 deletion modules/Ban/Dline.module/Dline.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"description" : "ban connections from server by IP",
"name" : "Ban::Dline",
"package" : "M::Ban::Dline",
"version" : "0.8"
"version" : "0.9"
}
3 changes: 2 additions & 1 deletion modules/Ban/Dline.module/Dline.pm
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ sub init {
sub _match {
my $str = shift;

# TODO: don't allow non-IPs

# does it match a user?
if (my $user = $pool->lookup_user_nick($str)) {
return $user->{ip};
}


return $str;
}

Expand Down
2 changes: 1 addition & 1 deletion modules/Ban/Kline.module/Kline.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"description" : "ban users from server by hostmask",
"name" : "Ban::Kline",
"package" : "M::Ban::Kline",
"version" : "1.2"
"version" : "1.3"
}
2 changes: 1 addition & 1 deletion modules/Cloak.module/Charybdis.module/Charybdis.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"description" : "hostname cloaking compatible with charybdis",
"name" : "Cloak::Charybdis",
"package" : "M::Cloak::Charybdis",
"version" : "4.3"
"version" : "4.4"
}
13 changes: 2 additions & 11 deletions modules/Cloak.module/Charybdis.module/Charybdis.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ use warnings;
use strict;
use 5.010;

use utils qw(fnv);

our ($api, $mod, $pool, $me);

my @ip_char_table = 'g'..'z';
Expand All @@ -27,17 +29,6 @@ sub cloak {
return do_host_cloak_host($host);
}

sub fnv {
my ($string) = @_;
my $h = 0x811c9dc5;
foreach my $c (split //, $string) {
$h ^= ord($c);
$h += ($h << 1) + ($h << 4) + ($h << 7) + ($h << 8) + ($h << 24);
$h &= 0xffffffff;
}
return $h;
}

sub do_host_cloak_ip {
my $in = shift;
my $accum = fnv($in);
Expand Down
2 changes: 1 addition & 1 deletion modules/Git.module/Git.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"description" : "git repository management",
"name" : "Git",
"package" : "M::Git",
"version" : "2.9"
"version" : "3"
}
4 changes: 2 additions & 2 deletions modules/Git.module/Git.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ our %user_commands = (update => {
});

our %oper_notices = (
update_fail => 'update to %s git reposity by %s (%s@%s) failed',
update => '%s git repository updated to version %s successfully by %s (%s@%s)'
update_fail => 'update to %s git reposity by %s failed',
update => '%s git repository updated to version %s successfully by %s'
);

sub init {
Expand Down
2 changes: 1 addition & 1 deletion modules/Modules.module/Modules.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"description" : "manage modules from IRC",
"name" : "Modules",
"package" : "M::Modules",
"version" : "6.4"
"version" : "6.5"
}
6 changes: 3 additions & 3 deletions modules/Modules.module/Modules.pm
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ sub init {
name => shift @$_,
format => shift @$_
) or return foreach (
[ module_load => '%s (%s@%s) loaded %s (%s)' ],
[ module_unload => '%s (%s@%s) unloaded %s' ],
[ module_reload => '%s (%s@%s) reloaded %s' ]
[ module_load => '%s loaded %s (%s)' ],
[ module_unload => '%s unloaded %s' ],
[ module_reload => '%s reloaded %s' ]
);

return 1;
Expand Down
2 changes: 1 addition & 1 deletion modules/Reload.module/Reload.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"description" : "reload the entire IRCd in one command",
"name" : "Reload",
"package" : "M::Reload",
"version" : "6.2"
"version" : "6.3"
}
2 changes: 1 addition & 1 deletion modules/Reload.module/Reload.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ sub init {
# notices.
$mod->register_oper_notice(
name => 'reload',
format => '%s %s by %s (%s@%s)'
format => '%s %s by %s'
) or return;

return 1;
Expand Down
11 changes: 11 additions & 0 deletions modules/ircd.module/utils.module/utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,17 @@ sub valid_ipv4 {
return 1;
}

sub fnv {
my ($string) = @_;
my $h = 0x811c9dc5;
foreach my $c (split //, $string) {
$h ^= ord($c);
$h += ($h << 1) + ($h << 4) + ($h << 7) + ($h << 8) + ($h << 24);
$h &= 0xffffffff;
}
return $h;
}

sub import {
my $this_package = shift;
my $package = caller;
Expand Down

0 comments on commit 8dcea06

Please sign in to comment.