diff options
| author | fukachan <fukachan> | 2003-06-22 16:05:11 +0000 |
|---|---|---|
| committer | fukachan <fukachan> | 2003-06-22 16:05:11 +0000 |
| commit | e4d7ca6b7a93039ca13eb7a6addf9d6ef0ae268c (patch) | |
| tree | 77f63e1acbd4b44748d7d360d588c1036a356c9b | |
| parent | 1d7fcbb73c77e421003725f2acda2fc0edafa828 (diff) | |
| download | fml8-e4d7ca6b7a93039ca13eb7a6addf9d6ef0ae268c.tar.gz fml8-e4d7ca6b7a93039ca13eb7a6addf9d6ef0ae268c.tar.bz2 fml8-e4d7ca6b7a93039ca13eb7a6addf9d6ef0ae268c.zip | |
add && enable functions: check_command_limit, check_line_length_limit.
| -rw-r--r-- | fml/etc/default_config.cf.ja.in | 28 | ||||
| -rw-r--r-- | fml/etc/src/config.cf.ja/command.cf | 28 | ||||
| -rw-r--r-- | fml/lib/FML/Command/Filter.pm | 146 | ||||
| -rw-r--r-- | fml/lib/FML/Filter/Size.pm | 55 |
4 files changed, 252 insertions, 5 deletions
diff --git a/fml/etc/default_config.cf.ja.in b/fml/etc/default_config.cf.ja.in index f3f8eda9..46a33c0c 100644 --- a/fml/etc/default_config.cf.ja.in +++ b/fml/etc/default_config.cf.ja.in @@ -1237,15 +1237,41 @@ use_command_mail_size_filter = yes # Descriptions: フィルタリングのルール。 -# どのルールにもマッチしないなら、記事の投稿は認められる。 +# どのルールにもマッチしないなら、コマンドメールは認められる。 # History: # Value: # Examples: command_mail_size_filter_rules = check_header_size check_body_size + check_command_limit + check_line_length_limit permit +=head2 メール一通あたりに含まれているコマンドの総数の上限 + + +# Descriptions: メール一通あたりに含まれているコマンドの総数の上限。 +# History: $MAXNUM_COMMAND_INPUT +# Value: NUM +# Examples: 100 +command_mail_valid_command_limit = 100 + + +# Descriptions: メール一通あたりに含まれているコマンドの総数の上限。 +# History: $MAXNUM_COMMAND_INPUT +# Value: NUM +# Examples: 100 +command_mail_junk_command_limit = 100 + + +# Descriptions: 一行あたりのコマンドの長さの上限 +# History: $MAXLEN_COMMAND_INPUT +# Value: NUM +# Examples: 128 +command_mail_line_length_limit = 128 + + =head2 コマンドの定義 # diff --git a/fml/etc/src/config.cf.ja/command.cf b/fml/etc/src/config.cf.ja/command.cf index 0632a17d..3ce662b0 100644 --- a/fml/etc/src/config.cf.ja/command.cf +++ b/fml/etc/src/config.cf.ja/command.cf @@ -71,15 +71,41 @@ use_command_mail_size_filter = yes # Descriptions: フィルタリングのルール。 -# どのルールにもマッチしないなら、記事の投稿は認められる。 +# どのルールにもマッチしないなら、コマンドメールは認められる。 # History: # Value: # Examples: command_mail_size_filter_rules = check_header_size check_body_size + check_command_limit + check_line_length_limit permit +=head2 メール一通あたりに含まれているコマンドの総数の上限 + + +# Descriptions: メール一通あたりに含まれているコマンドの総数の上限。 +# History: $MAXNUM_COMMAND_INPUT +# Value: NUM +# Examples: 100 +command_mail_valid_command_limit = 100 + + +# Descriptions: メール一通あたりに含まれているコマンドの総数の上限。 +# History: $MAXNUM_COMMAND_INPUT +# Value: NUM +# Examples: 100 +command_mail_junk_command_limit = 100 + + +# Descriptions: 一行あたりのコマンドの長さの上限 +# History: $MAXLEN_COMMAND_INPUT +# Value: NUM +# Examples: 128 +command_mail_line_length_limit = 128 + + =head2 コマンドの定義 # diff --git a/fml/lib/FML/Command/Filter.pm b/fml/lib/FML/Command/Filter.pm new file mode 100644 index 00000000..3dbd3af1 --- /dev/null +++ b/fml/lib/FML/Command/Filter.pm @@ -0,0 +1,146 @@ +#-*- perl -*- +# +# Copyright (C) 2003 Ken'ichi Fukamachi +# All rights reserved. This program is free software; you can +# redistribute it and/or modify it under the same terms as Perl itself. +# +# $FML$ +# + +package FML::Command::Filter; +use strict; +use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD $debug); +use Carp; +use FML::Log qw(Log LogWarn LogError); + + +# XXX_LOCK_CHANNEL: auth_map_modify +my $lock_channel = "auth_map_modify"; + + +=head1 NAME + +FML::Command::Filter - command mail specific filters + +=head1 SYNOPSIS + +=head1 DESCRIPTION + +=head1 METHODS + +=head2 new() + +=head2 reject() + +dummy :-) + +=cut + + +# Descriptions: constructor. +# Arguments: OBJ($self) HASH_REF($args) +# Side Effects: none +# Return Value: OBJ +sub new +{ + my ($self, $args) = @_; + my ($type) = ref($self) || $self; + my $me = {}; + return bless $me, $type; +} + + +# Descriptions: virtual reject handler, just return __LAST__ :-) +# Arguments: OBJ($self) OBJ($curproc) OBJ($msg) +# Side Effects: none +# Return Value: STR (__LAST__, a special upcall) +sub reject +{ + my ($self, $curproc, $msg) = @_; + + return '__LAST__'; +} + + +# Descriptions: +# Arguments: OBJ($self) OBJ($curproc) OBJ($msg) +# Side Effects: admin password modified. +# Return Value: NUM +sub check_command_limit +{ + my ($self, $curproc, $msg) = @_; + my $config = $curproc->config(); + my $limit = $config->{ command_mail_valid_command_limit } || 1024; + my $lines = $msg->message_text_as_array_ref(); + my $count = 0; + + LINE: + for my $buf (@$lines) { + $count++ if $buf =~ /^\w+$|^\w+\s+/o; + last LINE if $count > $limit; + } + + if ( $count > $limit ) { + Log("command_limit: $count > $limit"); + } + + my $r = "number of commands per mail exceeds limit $limit"; + return( $count > $limit ? $r : '' ); +} + + +# Descriptions: +# Arguments: OBJ($self) OBJ($curproc) OBJ($msg) +# Side Effects: admin password modified. +# Return Value: NUM +sub check_line_length_limit +{ + my ($self, $curproc, $msg) = @_; + my $config = $curproc->config(); + my $limit = $config->{ command_mail_line_length_limit } || 999; + my $lines = $msg->message_text_as_array_ref(); + my $match = 0; + my $len; + + LINE: + for my $buf (@$lines) { + $len = length($buf); + + if ($len > $limit) { + $match++; + } + } + + if ($match) { + Log("line_length_limit: $match times (\$len > $limit)"); + } + + my $r = "too long command (> $limit bytes)\n"; + return( $match ? $r : '' ); +} + + +=head1 CODING STYLE + +See C<http://www.fml.org/software/FNF/> on fml coding style guide. + +=head1 AUTHOR + +Ken'ichi Fukamachi + +=head1 COPYRIGHT + +Copyright (C) 2003 Ken'ichi Fukamachi + +All rights reserved. This program is free software; you can +redistribute it and/or modify it under the same terms as Perl itself. + +=head1 HISTORY + +FML::Command::Filter first appeared in fml8 mailing list driver package. +See C<http://www.fml.org/> for more details. + +=cut + + +1; diff --git a/fml/lib/FML/Filter/Size.pm b/fml/lib/FML/Filter/Size.pm index b7f479b1..01bdf33f 100644 --- a/fml/lib/FML/Filter/Size.pm +++ b/fml/lib/FML/Filter/Size.pm @@ -4,7 +4,7 @@ # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: Size.pm,v 1.2 2002/12/20 03:41:28 fukachan Exp $ +# $FML: Size.pm,v 1.1 2003/05/14 12:02:01 fukachan Exp $ # package FML::Filter::Size; @@ -208,8 +208,57 @@ sub _check_mail_size } } - $self->error_set($reason) if $reason; - croak($reason); + if ($reason) { + $self->error_set($reason); + croak($reason); + } +} + + +=head1 + +=cut + + +# Descriptions: +# Arguments: OBJ($self) OBJ($msg) STR($type) +# Side Effects: +# Return Value: none +sub check_command_limit +{ + my ($self, $msg, $type) = @_; + my $curproc = $self->{ _curproc }; + + use FML::Command::Filter; + my $_msg = $curproc->incoming_message_body(); + my $obj = new FML::Command::Filter; + my $reason = $obj->check_command_limit($curproc, $_msg); + + if ($reason) { + $self->error_set($reason); + croak($reason); + } +} + + +# Descriptions: +# Arguments: OBJ($self) OBJ($msg) STR($type) +# Side Effects: +# Return Value: none +sub check_line_length_limit +{ + my ($self, $msg, $type) = @_; + my $curproc = $self->{ _curproc }; + + use FML::Command::Filter; + my $_msg = $curproc->incoming_message_body(); + my $obj = new FML::Command::Filter; + my $reason = $obj->check_line_length_limit($curproc, $_msg); + + if ($reason) { + $self->error_set($reason); + croak($reason); + } } |
