Skip to content

Commit

Permalink
Ban classes were removed because some ban types apply to multiple obj…
Browse files Browse the repository at this point in the history
…ect types. Klines can now be applied directly to connections, so the kill occurs during registration when possible. #32
  • Loading branch information
cooper committed Jul 24, 2016
1 parent 51bcb19 commit debbf6d
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 18 deletions.
2 changes: 2 additions & 0 deletions INDEV
Original file line number Diff line number Diff line change
Expand Up @@ -3437,3 +3437,5 @@ CHANGES:
fixed an issue where QUITs were sent on ban enforcement for users not yet propagated.
added connection events 'found_ident' and 'found_hostname' for Ban.
Ban now enforces bans on a connection as soon as the host/ident are looked up.
Ban classes were removed because some ban types apply to multiple object types.
Klines can now be applied directly to connections, so the kill occurs during registration when possible.
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" : "10.3"
"version" : "10.4"
}
12 changes: 6 additions & 6 deletions modules/Ban/Ban.module/Ban.pm
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ sub enforce_all_on_user {
my $user = shift;
foreach my $ban (get_all_bans()) {
my $type = $ban_types{ $ban->{type} };
next unless $type->{class} eq 'user';
next unless $type->{user_code};
return 1 if enforce_ban_on_user($ban, $user);
}
return;
Expand All @@ -446,7 +446,7 @@ sub enforce_all_on_conn {
my $conn = shift;
foreach my $ban (get_all_bans()) {
my $type = $ban_types{ $ban->{type} };
next unless $type->{class} eq 'conn';
next unless $type->{conn_code};
return 1 if enforce_ban_on_conn($ban, $conn);
}
return;
Expand All @@ -459,11 +459,11 @@ sub enforce_ban {
my %ban = @_;
my $type = $ban_types{ $ban{type} } or return;

# user ban
if ($type->{class} eq 'user') { return enforce_ban_on_users(%ban) }
if ($type->{class} eq 'conn') { return enforce_ban_on_conns(%ban) }
my @a;
push @a, enforce_ban_on_users(%ban) if $type->{user_code};
push @a, enforce_ban_on_conns(%ban) if $type->{conn_code};

return;
return @a;
}

# enforce a ban on all connections
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" : "4.1"
"version" : "4.2"
}
2 changes: 1 addition & 1 deletion modules/Ban/Ban.module/TS6.module/TS6.pm
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ sub out_bandel {
# CAP_UNKLN: :<source> UNKLINE <target> <user> <host>
if ($ban{type} eq 'kline' && $to_server->has_cap('UNKLN')) {
return sprintf ':%s UNKLINE * %s %s',
ts6_id($from);
ts6_id($from),
$ban{ts6_duration},
$ban{match_user},
$ban{match_host};
Expand Down
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.9"
"version" : "1"
}
1 change: 0 additions & 1 deletion modules/Ban/Dline.module/Dline.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ sub init {
add_cmd => 'dline', # add command
del_cmd => 'undline', # delete command
reason => 'D-Lined', # reason prefix
class => 'conn', # bans apply to
conn_code => \&conn_matches, # connection matcher
match_code => \&_match, # match checker
);
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.3"
"version" : "1.4"
}
16 changes: 10 additions & 6 deletions modules/Ban/Kline.module/Kline.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use warnings;
use strict;
use 5.010;

use utils qw(irc_match);

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

sub init {
Expand All @@ -27,8 +29,8 @@ sub init {
add_cmd => 'kline', # add command
del_cmd => 'unkline', # delete command
reason => 'K-Lined', # reason prefix
class => 'user', # bans apply to
user_code => \&user_matches, # user matcher
user_code => \&user_or_conn_matches, # user matcher
conn_code => \&user_or_conn_matches, # connection matcher
match_code => \&_match, # match checker
);
}
Expand All @@ -49,10 +51,12 @@ sub _match {
return $result;
}

sub user_matches {
my ($user, $ban) = @_;
return 1 if utils::irc_match($user->{ident}.'@'.$user->{host}, $ban->{match});
return 1 if utils::irc_match($user->{ident}.'@'.$user->{ip}, $ban->{match});
sub user_or_conn_matches {
my ($user_conn, $ban) = @_;
my ($ident, $host, $ip) = @$user_conn{ qw(ident host ip) };
return unless length $ident;
return 1 if irc_match("$ident\@$host", $ban->{match});
return 1 if irc_match("$ident\@$ip", $ban->{match});
return;
}

Expand Down

0 comments on commit debbf6d

Please sign in to comment.