From: Joerg D. <jd...@us...> - 2006-11-20 15:47:57
|
Update of /cvsroot/ispman/ispman/lib/ISPMan In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv9989/lib/ISPMan Modified Files: UserMan.pm Log Message: consolidated mail alias check fixed bug with bogus mail alias check Index: UserMan.pm =================================================================== RCS file: /cvsroot/ispman/ispman/lib/ISPMan/UserMan.pm,v retrieving revision 1.61 retrieving revision 1.62 diff -u -d -r1.61 -r1.62 --- UserMan.pm 15 Nov 2006 22:23:29 -0000 1.61 +++ UserMan.pm 20 Nov 2006 15:47:54 -0000 1.62 @@ -323,23 +323,52 @@ # added by Michael Bunk, Jan 2006 sub containsInvalidMailAliases { my $self = shift; - my $aliases = shift; + my $user = shift; my $masterDomain = shift; + my $aliases = shift; my $replicas = $self->getReplicasOfDomain($masterDomain); my @validDomains; + + # determine all valid domains if ( defined($replicas) ) { @validDomains = keys %$replicas; } push @validDomains, $masterDomain; - OUTER: foreach (@$aliases) { - next if (/^[\w\.\-\+]*$/); + + # check all aliases for validity + foreach (@$aliases) { + next if /^$/; + + # check fully qualified address + if (/^[\w\.\-\+]+$/) { + return ( 1, _("Mail address is not fully qualified") . ": " . $_ ); + } + + # check for out-of-bounds addresses if (/^[\w\.\-\+]*@([\w\.\-]+)$/) { - foreach my $d (@validDomains) { - next OUTER if ( $d eq $1 ); + if ( !grep /^$1$/, @validDomains ) { + return ( + 1, + _( + "Mail aliases to users from foreign domains are forbidden" + ) + . ": " + . $_ + ); } } - return ( 1, - _("Mail aliases to users from foreign domains are forbidden: '$_'") - ); + + # check for uniqueness + my $found_dn = $self->getDNForMailAddress($_); + my $user_dn = $self->getUserDN( $masterDomain, $user ); + if ( defined($found_dn) && ( $found_dn ne $user_dn ) ) { + return ( 1, + _("Mail alias") . " " . $_ . " " + . _("conflicts with") . "\"" + . $found_dn + . "\".<br>" + . _("Aborting update!") ); + } } + return ( 0, undef ); } @@ -364,20 +393,11 @@ $data->{'mailAlias'} = $self->as_arrayref( split( /\s+/, $r->param("mailAlias") ) ); - # check uniqueness of mail aliases - for ( split( /\s+/, $r->param("mailAlias") ) ) { - my $found_dn = $self->getDNForMailAddress($_); - if ( defined($found_dn) && ( $found_dn ne $dn ) ) { - print "Mail alias $_ conflicts with \"$found_dn\".<br>"; - print "Aborting update!"; - return 0; - } - } - - # added by Michael Bunk, Jan 2006 + # check mail aliases my ( $invalid, $errmsg ) = - $self->containsInvalidMailAliases( $data->{'mailAlias'}, - $userInfo->{'ispmanDomain'} ); + $self->containsInvalidMailAliases( $r->param("uid"), + $userInfo->{'ispmanDomain'}, + $data->{'mailAlias'} ); if ($invalid) { print $errmsg; return 0; @@ -434,7 +454,7 @@ # added by Michael Bunk, Jan 2006 my ( $invalid, $errmsg ) = - $self->containsInvalidMailAliases( $values, $domain ); + $self->containsInvalidMailAliases( $uid, $domain, $values ); if ($invalid) { print $errmsg; @@ -452,7 +472,7 @@ # added by Michael Bunk, Jan 2006 my ( $invalid, $errmsg ) = - $self->containsInvalidMailAliases( $values, $domain ); + $self->containsInvalidMailAliases( $uid, $domain, $values ); if ($invalid) { print $errmsg; |