diff options
| author | fukachan <fukachan> | 2001-10-11 04:16:39 +0000 |
|---|---|---|
| committer | fukachan <fukachan> | 2001-10-11 04:16:39 +0000 |
| commit | c13e9a095002ecabd5670e80cecbfd85c80d2f6a (patch) | |
| tree | 8a23c61e0172d6f2a0fc276ce7b33edc734cdacd /fml | |
| parent | d6d067048a8c53abcf0754313d547af150883849 (diff) | |
| download | fml8-c13e9a095002ecabd5670e80cecbfd85c80d2f6a.tar.gz fml8-c13e9a095002ecabd5670e80cecbfd85c80d2f6a.tar.bz2 fml8-c13e9a095002ecabd5670e80cecbfd85c80d2f6a.zip | |
FML::Filter::Utils provides utility functions
is_secure_command_string(), is_valid_mail_address()
FML::Process::Command checks input by
FML::Filter::Utils::is_secure_command_string()
Diffstat (limited to 'fml')
| -rw-r--r-- | fml/lib/FML/Filter/Utils.pm | 94 | ||||
| -rw-r--r-- | fml/lib/FML/Process/Command.pm | 22 |
2 files changed, 113 insertions, 3 deletions
diff --git a/fml/lib/FML/Filter/Utils.pm b/fml/lib/FML/Filter/Utils.pm new file mode 100644 index 00000000..e7f133f4 --- /dev/null +++ b/fml/lib/FML/Filter/Utils.pm @@ -0,0 +1,94 @@ +#-*- perl -*- +# +# Copyright (C) 2001 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: @template.pm,v 1.1 2001/08/07 12:23:48 fukachan Exp $ +# + +package FML::Filter::Utils; +use strict; +use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD); +use Carp; + +=head1 NAME + +FML::Filter::Utils - useful subroutines for filtering + +=head1 SYNOPSIS + +collection of utility functions + +=head1 DESCRIPTION + +=head1 METHODS + +=cut + +# Descriptions: +# Arguments: $self $args +# Side Effects: +# History: fml 4.0's SecureP() +# Return Value: none +sub is_secure_command_string +{ + my ($s) = @_; + + # 0. clean up + $s =~ s/^\s*\#\s*//; # remove ^# + + # 1. trivial case + # 1.1. empty + if ($s =~ /^\s*$/) { + return 1; + } + + # 2. allow + # command = \w+ + # mail address = [-_\w]+@[\w\-\.]+ + # command options = last:30 + if ($s =~/^[\s\w\_\-\.\,\@\:]+$/) { + return 1; + } + + return 0; +} + + +=head2 C<is_valid_mail_address($string)> + +1. check C<$strings> contains no Japanese string. + +=cut + + +sub is_valid_mail_address +{ + my ($s) = @_; + + ($s !~ /\s|\033\$[\@B]|\033\([BJ]/ && + $s =~ /^[\0-\177]+\@[\0-\177]+$/) ? 1 : 0; +} + + +=head1 AUTHOR + +Ken'ichi Fukamachi + +=head1 COPYRIGHT + +Copyright (C) 2001 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::Filter::Utils appeared in fml5 mailing list driver package. +See C<http://www.fml.org/> for more details. + +=cut + + +1; diff --git a/fml/lib/FML/Process/Command.pm b/fml/lib/FML/Process/Command.pm index 9e864c0d..d9b85810 100644 --- a/fml/lib/FML/Process/Command.pm +++ b/fml/lib/FML/Process/Command.pm @@ -4,7 +4,7 @@ # Copyright (C) 2000,2001 Ken'ichi Fukamachi # All rights reserved. # -# $FML: Command.pm,v 1.13 2001/10/10 10:08:06 fukachan Exp $ +# $FML: Command.pm,v 1.14 2001/10/10 14:56:01 fukachan Exp $ # package FML::Process::Command; @@ -141,13 +141,29 @@ sub _evaluate_command $curproc->reply_message("result for your command requests follows:"); COMMAND: - for my $command (@body) { + for my $command (@body) { + # + # cheap diagnostics + # + + # 1. command exists or not my $comname = (split(/\s+/, $command))[0]; my $is_valid = $config->has_attribute( "available_commands", $comname ) ? 'yes' : 'no'; Log("command = " . $comname . " (valid?=$is_valid)"); - next if $is_valid eq 'no'; + + # 2. command syntax check + use FML::Filter::Utils; + unless ( FML::Filter::Utils::is_secure_command_string( $command ) ) { + LogError("insecure command: $command"); + $curproc->reply_message("\n$prompt $command"); + $curproc->reply_message("insecure, so ignored."); + $is_valid = 'no'; + } + + # stop. + next COMMAND if $is_valid eq 'no'; # arguments to pass off to each method my @options = (); |
