summaryrefslogtreecommitdiff
path: root/fml/lib
diff options
context:
space:
mode:
authorfukachan <fukachan>2002-04-24 04:35:38 +0000
committerfukachan <fukachan>2002-04-24 04:35:38 +0000
commit979e5b18bf35e1873fc5774b725e8a374bf435a2 (patch)
treee17879d9f3b3205744f772bc6d44f9618683dfa9 /fml/lib
parent7e7532704084193ca042ab8f307b19b7a28ec75a (diff)
downloadfml8-979e5b18bf35e1873fc5774b725e8a374bf435a2.tar.gz
fml8-979e5b18bf35e1873fc5774b725e8a374bf435a2.tar.bz2
fml8-979e5b18bf35e1873fc5774b725e8a374bf435a2.zip
check $ml_name duplication over all $alias_maps in the postfix case
Diffstat (limited to 'fml/lib')
-rw-r--r--fml/lib/FML/Command/Admin/newml.pm43
-rw-r--r--fml/lib/FML/MTAControl.pm87
2 files changed, 119 insertions, 11 deletions
diff --git a/fml/lib/FML/Command/Admin/newml.pm b/fml/lib/FML/Command/Admin/newml.pm
index 243f14f2..f1941f76 100644
--- a/fml/lib/FML/Command/Admin/newml.pm
+++ b/fml/lib/FML/Command/Admin/newml.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: newml.pm,v 1.27 2002/04/24 03:50:00 fukachan Exp $
+# $FML: newml.pm,v 1.28 2002/04/24 03:59:15 fukachan Exp $
#
package FML::Command::Admin::newml;
@@ -95,6 +95,12 @@ sub process
}
}
+ # check alias key defined in MTA aliases
+ if ($self->_mta_alias_has_ml_entry($curproc, $ml_name)) {
+ warn("$ml_name already exists (somewhere in MTA aliases)");
+ return ;
+ }
+
# o.k. here we go !
eval q{
use File::Utils qw(mkdirhier);
@@ -180,7 +186,7 @@ sub _update_aliases
_install($src, $dst, $params);
# append
- if ($self->_alias_has_ml_entry($alias, $ml_name)) {
+ if ($self->_alias_has_ml_entry($curproc, $alias, $ml_name)) {
print STDERR "warning: $ml_name already defined!\n";
print STDERR " ignore aliases updating.\n";
}
@@ -203,13 +209,42 @@ sub _update_aliases
}
+
+# Descriptions: $alias file has an $ml_name entry or not
+# Arguments: OBJ($self) OBJ($curproc) STR($ml_name)
+# Side Effects: none
+# Return Value: NUM( 1 or 0 )
+sub _mta_alias_has_ml_entry
+{
+ my ($self, $curproc, $ml_name) = @_;
+ my $found = 0;
+
+ eval q{
+ use FML::MTAControl;
+ my $postfix = new FML::MTAControl;
+ $found = $postfix->find_key_in_alias($curproc, {
+ mta_type => 'postfix',
+ key => $ml_name,
+ });
+ };
+ croak($@) if $@;
+
+ return $found;
+}
+
+
# Descriptions: $alias file has an $ml_name entry or not
-# Arguments: OBJ($self) STR($alias) STR($ml_name)
+# Arguments: OBJ($self) OBJ($curproc) STR($alias) STR($ml_name)
# Side Effects: none
# Return Value: NUM( 1 or 0 )
sub _alias_has_ml_entry
{
- my ($self, $alias, $ml_name) = @_;
+ my ($self, $curproc, $alias, $ml_name) = @_;
+ my $found = 0;
+
+ # search all entries defined in MTA
+ $found = $self->_mta_alias_has_ml_entry($curproc, $ml_name);
+ return 1 if $found;
use FileHandle;
my $fh = new FileHandle $alias;
diff --git a/fml/lib/FML/MTAControl.pm b/fml/lib/FML/MTAControl.pm
index b76b664a..8fcb48e6 100644
--- a/fml/lib/FML/MTAControl.pm
+++ b/fml/lib/FML/MTAControl.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: PostfixControl.pm,v 1.3 2001/12/23 03:50:26 fukachan Exp $
+# $FML: MTAControl.pm,v 1.1 2002/04/24 03:59:14 fukachan Exp $
#
package FML::MTAControl;
@@ -12,6 +12,9 @@ use strict;
use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD);
use Carp;
+my $debug = 0;
+
+
=head1 NAME
FML::MTAControl - postfix utilities
@@ -41,9 +44,9 @@ sub new
# Descriptions: update alias
-# Arguments: OBJ($self)
-# Side Effects: none
-# Return Value: OBJ
+# Arguments: OBJ($self) HASH_REF($curproc) HASH_REF($optargs)
+# Side Effects: update aliases
+# Return Value: none
sub update_alias
{
my ($self, $curproc, $optargs) = @_;
@@ -59,9 +62,9 @@ sub update_alias
# Descriptions: update alias
-# Arguments: OBJ($self)
-# Side Effects: none
-# Return Value: OBJ
+# Arguments: OBJ($self) HASH_REF($curproc) HASH_REF($optargs)
+# Side Effects: update aliases
+# Return Value: none
sub postfix_update_alias
{
my ($self, $curproc, $optargs) = @_;
@@ -75,6 +78,76 @@ sub postfix_update_alias
}
+# Descriptions: find key
+# Arguments: OBJ($self) HASH_REF($curproc) HASH_REF($optargs)
+# Side Effects: none
+# Return Value: none
+sub find_key_in_alias
+{
+ my ($self, $curproc, $optargs) = @_;
+ my $mta_type = $optargs->{ mta_type };
+ my $key = $optargs->{ key };
+
+ if ($mta_type eq 'postfix') {
+ $self->postfix_find_key_in_alias($curproc, $optargs);
+ }
+ else {
+ croak("unknown MTA");
+ }
+}
+
+
+# Descriptions: find key in aliases
+# Arguments: OBJ($self) HASH_REF($curproc) HASH_REF($optargs)
+# Side Effects: none
+# Return Value: NUM(1 or 0)
+sub postfix_find_key_in_alias
+{
+ my ($self, $curproc, $optargs) = @_;
+ my $key = $optargs->{ key };
+ my $maps = $self->postfix_alias_maps($curproc, $optargs);
+
+ for my $map (@$maps) {
+ print STDERR "scan key = $key, map = $map\n" if $debug;
+
+ use FileHandle;
+ my $fh = new FileHandle $map;
+ if (defined $fh) {
+ while (<$fh>) {
+ return 1 if /^$key:/;
+ }
+ }
+ else {
+ warn("cannot open $map");
+ }
+ $fh->close;
+ }
+
+ return 0;
+}
+
+
+# Descriptions: return alias_maps as ARRAY_REF
+# Arguments: OBJ($self) HASH_REF($curproc) HASH_REF($optargs)
+# Side Effects: none
+# Return Value: ARRAY_REF
+sub postfix_alias_maps
+{
+ my ($self, $curproc, $optargs) = @_;
+ my $config = $curproc->{ config };
+ my $prog = $config->{ path_postconf };
+
+
+ my $maps = `$prog alias_maps`;
+ $maps =~ s/\s+\w+:/ /g;
+ $maps =~ s/^.*=\s*//;
+ chomp $maps;
+
+ my (@maps) = split(/\s+/, $maps);
+ return \@maps;
+}
+
+
=head1 AUTHOR
Ken'ichi Fukamachi