summaryrefslogtreecommitdiff
path: root/fml/lib
diff options
context:
space:
mode:
authorfukachan <fukachan>2003-03-06 09:34:15 +0000
committerfukachan <fukachan>2003-03-06 09:34:15 +0000
commit4adda7ecf9024dbd5d87df5afbe5c868b6a1a4d6 (patch)
tree70db79fec288fa6672ce86960c73217464fdee92 /fml/lib
parenta05f56c6a519e4bc945cf2c08328d68e72ca4d54 (diff)
downloadfml8-4adda7ecf9024dbd5d87df5afbe5c868b6a1a4d6.tar.gz
fml8-4adda7ecf9024dbd5d87df5afbe5c868b6a1a4d6.tar.bz2
fml8-4adda7ecf9024dbd5d87df5afbe5c868b6a1a4d6.zip
moved main codes of _check_restrions() to methods defined in new
FML::Restriction::Post module. switched to use FML::Restriction::Post.
Diffstat (limited to 'fml/lib')
-rw-r--r--fml/lib/FML/Process/Kernel.pm63
-rw-r--r--fml/lib/FML/Restriction/Post.pm156
2 files changed, 173 insertions, 46 deletions
diff --git a/fml/lib/FML/Process/Kernel.pm b/fml/lib/FML/Process/Kernel.pm
index bc2c79ec..b21362e0 100644
--- a/fml/lib/FML/Process/Kernel.pm
+++ b/fml/lib/FML/Process/Kernel.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: Kernel.pm,v 1.161 2003/03/05 15:47:21 fukachan Exp $
+# $FML: Kernel.pm,v 1.162 2003/03/06 04:17:19 fukachan Exp $
#
package FML::Process::Kernel;
@@ -983,58 +983,29 @@ sub _check_restrictions
my $sender = $cred->sender();
my $rules = $config->get_as_array_ref( "${type}_restrictions" );
- # XXX-TODO: method()-ify these functions for further enhancement.
- for my $rule (@$rules) {
- if ($rule eq 'reject_system_accounts') {
- my $match = $cred->match_system_accounts($sender);
- if ($match) {
- Log("${rule}: $match matches sender address");
- $pcb->set("check_restrictions", "deny_reason", $rule);
- return 0;
- }
- }
- elsif ($rule eq 'permit_anyone') {
- return 1;
- }
- elsif ($rule eq 'permit_member_maps') {
- # Q: the mail sender is a ML member?
- if ($cred->is_member($sender)) {
- # A: Yes, we permit to distribute this article.
- return 1;
- }
- else {
- # A: No, deny distribution
- LogError("$sender is not an ML member");
- LogError( $cred->error() );
+ use FML::Restriction::Post;
+ my $acl = new FML::Restriction::Post $curproc;
- # reply this info in each FML::Process::* module.
- # $curproc->reply_message_nl('error.not_member',
- # "you are not a ML member." );
- # $curproc->reply_message( " your address: $sender" );
-
- $pcb->set("check_restrictions", "deny_reason", $rule);
- return 0;
- }
- }
- elsif ($rule eq 'permit_commands_for_stranger') {
- use FML::Command::DataCheck;
- my $check = new FML::Command::DataCheck;
- if ($check->find_commands_for_stranger($curproc)) {
- Log("$rule matched. accepted.");
- return 1;
- }
- }
- elsif ($rule eq 'reject') {
- $pcb->set("check_restrictions", "deny_reason", $rule);
- return 0;
+ my ($match, $result) = (0, 0);
+ for my $rule (@$rules) {
+ if ($acl->can($rule)) {
+ # match = matched. return as soon as possible from here.
+ # ASAP or RETRY the next rule, depends on the rule.
+ # result = action determined by matched rule.
+ ($match, $result) = $acl->$rule($rule, $sender);
}
else {
+ ($match, $result) = (0, undef);
LogWarn("unknown rule=$rule");
}
+
+ if ($match) {
+ Log("match rule=$rule sender=$sender");
+ return($result eq "permit" ? 1 : 0);
+ }
}
- # deny by default
- return 0;
+ return 0; # deny by default
}
diff --git a/fml/lib/FML/Restriction/Post.pm b/fml/lib/FML/Restriction/Post.pm
new file mode 100644
index 00000000..aee17dd0
--- /dev/null
+++ b/fml/lib/FML/Restriction/Post.pm
@@ -0,0 +1,156 @@
+#-*- 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: Post.pm,v 1.8 2002/12/15 15:17:18 fukachan Exp $
+#
+
+package FML::Restriction::Post;
+use strict;
+use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD);
+use Carp;
+use FML::Log qw(Log LogWarn LogError);
+
+
+=head1 NAME
+
+FML::Restriction::Post - restricts who is allowed to post/use command mails.
+
+=head1 SYNOPSIS
+
+collection of utility functions used in Post routines.
+
+=head1 DESCRIPTION
+
+=head1 METHODS
+
+=cut
+
+
+# Descriptions: constructor.
+# Arguments: OBJ($self) OBJ($curproc)
+# Side Effects: none
+# Return Value: OBJ
+sub new
+{
+ my ($self, $curproc) = @_;
+ my ($type) = ref($self) || $self;
+ my $me = { _curproc => $curproc };
+ return bless $me, $type;
+}
+
+
+sub reject_system_accounts
+{
+ my ($self, $rule, $sender) = @_;
+ my $curproc = $self->{ _curproc };
+ my $cred = $curproc->{ credential };
+ my $match = $cred->match_system_accounts($sender);
+ my $pcb = $curproc->{ pcb };
+
+ if ($match) {
+ Log("${rule}: $match matches sender address");
+ $pcb->set("check_restrictions", "deny_reason", $rule);
+ return("matched", "deny");
+ }
+
+ return(0, undef);
+}
+
+
+sub permit_anyone
+{
+ my ($self, $rule, $sender) = @_;
+
+ return("matched", "permit");
+}
+
+
+sub permit_member_maps
+{
+ my ($self, $rule, $sender) = @_;
+ my $curproc = $self->{ _curproc };
+ my $cred = $curproc->{ credential };
+ my $pcb = $curproc->{ pcb };
+
+ # Q: the mail sender is a ML member?
+ if ($cred->is_member($sender)) {
+ # A: Yes, we permit to distribute this article.
+ return("matched", "permit");
+ }
+ else {
+ # A: No, deny distribution
+ LogError("$sender is not an ML member");
+ LogError( $cred->error() );
+
+ # reply this info in each FML::Process::* module.
+ # $curproc->reply_message_nl('error.not_member',
+ # "you are not a ML member." );
+ # $curproc->reply_message( " your address: $sender" );
+
+ # save reason for later use.
+ $pcb->set("check_restrictions", "deny_reason", $rule);
+
+ # XXX "deny ASAP if this method fails." ? NO, wrong!
+ # XXX permit_XXX() allows the trial match of another rules.
+ # return("matched", "deny");
+ }
+
+ return(0, undef);
+}
+
+
+sub permit_commands_for_stranger
+{
+ my ($self, $rule, $sender) = @_;
+ my $curproc = $self->{ _curproc };
+ my $pcb = $curproc->{ pcb };
+
+ use FML::Command::DataCheck;
+ my $check = new FML::Command::DataCheck;
+ if ($check->find_commands_for_stranger($curproc)) {
+ Log("$rule matched. accepted.");
+ return("matched", "permit");
+ }
+
+ return(0, undef);
+}
+
+
+sub reject
+{
+ my ($self, $rule, $sender) = @_;
+ my $curproc = $self->{ _curproc };
+ my $pcb = $curproc->{ pcb };
+
+ $pcb->set("check_restrictions", "deny_reason", $rule);
+ return("matched", "deny");
+}
+
+
+=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::Restriction::Post first appeared in fml8 mailing list driver package.
+See C<http://www.fml.org/> for more details.
+
+=cut
+
+
+1;