diff options
| author | fukachan <fukachan> | 2002-04-07 12:13:02 +0000 |
|---|---|---|
| committer | fukachan <fukachan> | 2002-04-07 12:13:02 +0000 |
| commit | eab38d001d7f459bfe8c940d1905f72f92ff33d7 (patch) | |
| tree | b72f8c265c515429ec44e97601a731771a906210 | |
| parent | 98dde351410282433875892b6f589a8a0b5e33f1 (diff) | |
| download | fml8-eab38d001d7f459bfe8c940d1905f72f92ff33d7.tar.gz fml8-eab38d001d7f459bfe8c940d1905f72f92ff33d7.tar.bz2 fml8-eab38d001d7f459bfe8c940d1905f72f92ff33d7.zip | |
admin_member_passwd_maps -> admin_member_password_maps
more friendly variable name syntax
more comments, documents
| -rw-r--r-- | fml/lib/FML/Command/Auth.pm | 42 | ||||
| -rw-r--r-- | fml/lib/FML/Command/DirUtils.pm | 37 | ||||
| -rw-r--r-- | fml/lib/FML/Command/FileUtils.pm | 29 | ||||
| -rw-r--r-- | fml/lib/FML/Command/SendFile.pm | 40 | ||||
| -rw-r--r-- | fml/lib/FML/Command/UserControl.pm | 11 |
5 files changed, 103 insertions, 56 deletions
diff --git a/fml/lib/FML/Command/Auth.pm b/fml/lib/FML/Command/Auth.pm index b044c888..601b0158 100644 --- a/fml/lib/FML/Command/Auth.pm +++ b/fml/lib/FML/Command/Auth.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: Auth.pm,v 1.2 2002/03/23 14:24:35 fukachan Exp $ +# $FML: Auth.pm,v 1.3 2002/03/30 11:08:34 fukachan Exp $ # package FML::Command::Auth; @@ -28,31 +28,57 @@ FML::Command::Auth - authentication functions =head1 METHODS -=head2 C<new()> +=head2 new() + +=head2 reject() + +return 0 :-) (dummy) =cut +# Descriptions: ordinary constructor +# Arguments: OBJ($self) HASH_REF($args) +# Side Effects: none +# Return Value: OBJ sub new { - my ($self) = @_; + my ($self, $args) = @_; my ($type) = ref($self) || $self; my $me = {}; return bless $me, $type; } +# Descriptions: virtual reject handler, just return 0 :-) +# Arguments: OBJ($self) HASH_REF($args) +# Side Effects: none +# Return Value: NUM sub reject { return 0; } +=head2 check_password($curproc, $args, $optargs) + +check the password if it is valid or not. + +=cut + + +# Descriptions: check the password if it is valid or not. +# Arguments: OBJ($self) +# HASH_REF($curproc) +# HASH_REF($args) +# HASH_REF($optargs) +# Side Effects: none +# Return Value: NUM sub check_password { my ($self, $curproc, $args, $optargs) = @_; my $config = $curproc->{ config }; - my $maplist = $config->get_as_array_ref('admin_member_passwd_maps'); + my $maplist = $config->get_as_array_ref('admin_member_password_maps'); my $address = $optargs->{ address }; my $password = $optargs->{ password }; @@ -66,11 +92,13 @@ sub check_password for my $map (@$maplist) { use IO::Adapter; - my $obj = new IO::Adapter $map; - my $addrs = $obj->find( $user , { want => 'key,value', all => 1 }); + my $mapobj = new IO::Adapter $map; + my $addrs = $mapobj->find( $user , { want => 'key,value', all => 1 }); + # if this $map has this $user entry, + # try to check { user => password } relation. if (defined $addrs) { - LOOP: + PASSWORD_ENTRY: for my $r (@$addrs) { my ($u, $p_infile) = split(/\s+/, $r); my $p_input = crypt( $password, $p_infile ); diff --git a/fml/lib/FML/Command/DirUtils.pm b/fml/lib/FML/Command/DirUtils.pm index 0ab9c1ed..8155fbab 100644 --- a/fml/lib/FML/Command/DirUtils.pm +++ b/fml/lib/FML/Command/DirUtils.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: DirUtils.pm,v 1.3 2002/03/26 04:01:12 fukachan Exp $ +# $FML: DirUtils.pm,v 1.4 2002/03/30 11:08:34 fukachan Exp $ # package FML::Command::DirUtils; @@ -58,32 +58,47 @@ sub dir my $argv = $du_args->{ argv }; my $opt_ls = ''; - # option - if (defined($du_args->{ opt_ls }) && - $du_args->{ opt_ls } =~ /^-[A-Za-z]+$/) { - $opt_ls = $du_args->{ opt_ls }; + # option: permit "ls [-A-Za-z]" syntax + if (defined($du_args->{ opt_ls })) { + my $opt = $du_args->{ opt_ls }; + if ($opt =~ /^-[A-Za-z]+$/) { + $opt_ls = $opt; + } + else { + LogWarn("deny ls options '$opt'"); + } } # regexp my $basic_variable = $self->{ _basic_variable }; - my $regexp = $basic_variable->{ directory }; + my $dir_regexp = $basic_variable->{ directory }; + my $ml_home_dir = $config->{ ml_home_dir }; - my $ml_home_dir = $config->{ ml_home_dir }; - chdir $ml_home_dir; + # chdir + chdir $ml_home_dir || croak("cannot chdir \$ml_home_dir"); my $y = ''; for my $x (@$argv) { - if ($x =~ /^$regexp$/ || $x =~ /^\s*$/) { + if ($x =~ /^$dir_regexp$/ || $x =~ /^\s*$/) { $y .= " ". $x; } } if (-x $path_ls) { Log("$path_ls $opt_ls $y"); - my $buf = `$path_ls $opt_ls $y`; - $curproc->reply_message($buf); + + use FileHandle; + my $fh = new FileHandle "$path_ls $opt_ls $y|"; + if (defined $fh) { + while (<$fh>) { $curproc->reply_message($_);} + $fh->close(); + } + else { + LogError("tail to run '$path_ls $opt_ls $y'"); + } } else { + LogError("\$path_ls is not found"); croak("\$path_ls is not found"); } } diff --git a/fml/lib/FML/Command/FileUtils.pm b/fml/lib/FML/Command/FileUtils.pm index 50e1e1ab..addf1184 100644 --- a/fml/lib/FML/Command/FileUtils.pm +++ b/fml/lib/FML/Command/FileUtils.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: FileUtils.pm,v 1.1 2002/03/26 04:01:35 fukachan Exp $ +# $FML: FileUtils.pm,v 1.2 2002/03/30 11:08:34 fukachan Exp $ # package FML::Command::FileUtils; @@ -45,6 +45,10 @@ sub new } +# Descriptions: remove files +# Arguments: OBJ($self) ... varargs ... +# Side Effects: remove files +# Return Value: same as remove() sub delete { my ($self, @p) = @_; @@ -60,25 +64,26 @@ sub delete sub remove { my ($self, $curproc, $command_args, $du_args) = @_; - my $config = $curproc->{ config }; - my $argv = $du_args->{ options }; - my $is_warn = 0; + my $config = $curproc->{ config }; + my $argv = $du_args->{ options }; + my $is_error = 0; # regexp my $basic_variable = $self->{ _basic_variable }; - my $regexp = $basic_variable->{ file }; + my $file_regexp = $basic_variable->{ file }; + my $ml_home_dir = $config->{ ml_home_dir }; - my $ml_home_dir = $config->{ ml_home_dir }; - chdir $ml_home_dir; + # chdir $ml_home_dir firstly. return ASAP if failed. + chdir $ml_home_dir || croak("cannot chdir \$ml_home_dir"); for my $file (@$argv) { - if ($file =~ /^$regexp$/) { + if ($file =~ /^$file_regexp$/) { if (-f $file) { unlink $file; if (-f $file) { LogError("fail to remove $file"); - $is_warn++; + $is_error++; } else { Log("remove $file"); @@ -88,11 +93,11 @@ sub remove } } else { + LogWarn("no such file $file"); $curproc->reply_message_nl("command.no_such_file", "no such file $file", { _arg_file => $file } ); - LogWarn("no such file $file"); - $is_warn++; + $is_error++; } } else { @@ -102,7 +107,7 @@ sub remove } } - if ($is_warn) { + if ($is_error) { croak("remove: something fail."); } } diff --git a/fml/lib/FML/Command/SendFile.pm b/fml/lib/FML/Command/SendFile.pm index 6f26b32e..0373e796 100644 --- a/fml/lib/FML/Command/SendFile.pm +++ b/fml/lib/FML/Command/SendFile.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: SendFile.pm,v 1.13 2002/02/23 10:22:16 fukachan Exp $ +# $FML: SendFile.pm,v 1.14 2002/03/30 13:48:26 fukachan Exp $ # package FML::Command::SendFile; @@ -66,21 +66,21 @@ sub send_article for my $fn (@files) { my $filelist = $self->_is_valid_argument($curproc, $fn); if (defined $filelist) { - for my $fn (@$filelist) { + for my $filename (@$filelist) { use FML::Article; my $article = new FML::Article $curproc; - my $file = $article->filepath($fn); - if (-f $file) { - Log("send back article $fn"); + my $filepath = $article->filepath($filename); + if (-f $filepath) { + Log("send back article $filename"); $curproc->reply_message( { type => "message/rfc822; charset=$charset", - path => $file, - filename => $fn, - disposition => "$ml_name ML article $fn", + path => $filepath, + filename => $filename, + disposition => "$ml_name ML article $filename", }); } else { - Log("no such file: $file"); + Log("no such file: $filepath"); } } } @@ -153,8 +153,8 @@ sub _is_valid_argument sub _expand_range { my ($first, $last) = @_; + my (@fn) = (); - my (@fn); for ($first .. $last) { push(@fn, $_);} return \@fn; } @@ -162,7 +162,7 @@ sub _expand_range =head2 C<send_file($curproc, $command_args)> -send back file specified as C<$command_args->{ _file_to_send }>. +send back file specified as C<$command_args->{ _filepath_to_send }>. =cut @@ -175,14 +175,14 @@ send back file specified as C<$command_args->{ _file_to_send }>. sub send_file { my ($self, $curproc, $command_args) = @_; - my $file_name = $command_args->{ _filename_to_send }; - my $what_file = $command_args->{ _file_to_send }; - my $config = $curproc->{ config }; - my $charset = $config->{ reply_message_charset }; + my $filename = $command_args->{ _filename_to_send }; + my $filepath = $command_args->{ _filepath_to_send }; + my $config = $curproc->{ config }; + my $charset = $config->{ reply_message_charset }; # template substitution: kanji code, $varname expansion et. al. my $params = { - src => $what_file, + src => $filepath, charset_out => $charset, }; my $xxxx_template = $curproc->prepare_file_to_return( $params ); @@ -191,12 +191,12 @@ sub send_file $curproc->reply_message( { type => "text/plain; charset=$charset", path => $xxxx_template, - filename => $file_name, - disposition => $file_name, + filename => $filename, + disposition => $filename, }); } else { - croak("$what_file not found\n"); + croak("$filepath not found\n"); } } @@ -224,7 +224,7 @@ sub send_user_xxx_message # if "help" is found in $ml_home_dir (e.g. /var/spool/ml/elena), # send it. if (-f $config->{ "${type}_file" }) { - $command_args->{ _file_to_send } = $config->{ "${type}_file" }; + $command_args->{ _filepath_to_send } = $config->{ "${type}_file" }; $self->send_file($curproc, $command_args); } # if "help" is not found, use the default help message. diff --git a/fml/lib/FML/Command/UserControl.pm b/fml/lib/FML/Command/UserControl.pm index 734ac1a9..acef9ef1 100644 --- a/fml/lib/FML/Command/UserControl.pm +++ b/fml/lib/FML/Command/UserControl.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: UserControl.pm,v 1.2 2002/03/30 11:08:34 fukachan Exp $ +# $FML: UserControl.pm,v 1.3 2002/04/01 12:41:40 fukachan Exp $ # package FML::Command::UserControl; @@ -12,7 +12,10 @@ use strict; use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD); use Carp; use File::Spec; +use FML::Credential; use FML::Log qw(Log LogWarn LogError); +use IO::Adapter; + =head1 NAME @@ -26,10 +29,6 @@ FML::Command::UserControl - utility functions to send back file(s) =cut -use IO::Adapter; -use FML::Credential; -use FML::Log qw(Log LogWarn LogError); - # Descriptions: standard constructor # Arguments: OBJ($self) @@ -59,7 +58,7 @@ sub useradd my $cred = new FML::Credential; unless ($cred->has_address_in_map($map, $address)) { my $obj = new IO::Adapter $map; - $obj->touch(); + $obj->touch(); # create a new map entry (e.g. file) if needed. $obj->add( $address ); unless ($obj->error()) { Log("add $address to map=$map"); |
