ispman/lib/ISPMan UserMan.pm,1.58,1.59
Joerg Delker <[email protected]> Tue, 24 Oct 2006 21:32:21 +0000
| Newsgroups | gmane.comp.isp.ispman.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/ispman/ispman/lib/ISPMan
In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv31912/lib/ISPMan
Modified Files:
UserMan.pm
Log Message:
fixed [ 1577377 ] Alias and users
applied perltidy -nolq
Index: UserMan.pm
===================================================================
RCS file: /cvsroot/ispman/ispman/lib/ISPMan/UserMan.pm,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -d -r1.58 -r1.59
--- UserMan.pm 27 May 2006 16:25:05 -0000 1.58
+++ UserMan.pm 24 Oct 2006 21:32:19 -0000 1.59
@@ -50,6 +50,7 @@
addUserFileServerProcess
containsInvalidMailAliases
+ getDNForMailAddress
);
$VERSION = '0.01';
@@ -58,8 +59,8 @@
my $self = shift;
my $r = shift;
my $domain = $r->param("ispmanDomain");
- print
-"Sorry cannot add users to a replica domain<br>Instead add users to its master domain which is ";
+ print "Sorry cannot add users to a replica domain<br>"
+ . "Instead add users to its master domain which is ";
my $replicaMaster =
$self->getEntry(
"ispmanDomain=$domain, $self->{'Config'}->{'ldapBaseDN'}",
@@ -124,7 +125,9 @@
my $domainUserCount = $self->getUserCount($domain);
if ( $domainMaxUsers > 0 && $domainUserCount >= $domainMaxUsers ) {
$self->{'message'} =
-"Max accounts limit exceeded. <br>Your limit is $domainMaxUsers <br>You cannot create any more users.";
+ "Max accounts limit exceeded. <br>"
+ . "Your limit is $domainMaxUsers <br>"
+ . "You cannot create any more users.";
print $self->{'message'};
return;
}
@@ -134,6 +137,13 @@
$self->create_uid( $r->param("userid"), $r->param("ispmanDomain") );
$r->param( "uid", $_uid );
+ # check uid conflicts with existing mail addresses
+ if ( my $check = $self->getDNForMailAddress($_uid) ) {
+ print "Unable to create user \"$_uid\", because mail address is<br>"
+ . "already blocked by \"$check\".";
+ return;
+ }
+
# build new DN for user
my $dn =
"uid=$_uid, ou=users, ispmanDomain=$domain, "
@@ -143,17 +153,11 @@
$self->prepareBranchForDN(
"ou=users, ispmanDomain=$domain, @{[$self->getConf('ldapBaseDN')]}");
-# get domain info and supply it to session data so we can use it in user ldif template
+ # get domain info and supply it to session data
+ # so we can use it in user ldif template
my $domain_info = $self->getDomainInfo( $r->param("ispmanDomain") );
$r->param( "domaininfo", $domain_info );
-# moved to user template
-#my $homeDirectory=join '/', ($domain_info->{'homeDirectory'}, "users", $r->param("uid"), "");
-#my $cn=($r->param("givenName") && $r->param("sn"))? join " ", ($r->param("givenName"), $r->param("sn")) :$r->param("userid");
-#$r->param("cn", $cn);
-#$r->param("sn", ($r->param("sn")? $r->param("sn"):$r->param("userid")));
-#$r->param("homeDirectory", $homeDirectory);
-
# validate ftp quota
if ( $r->param("FTPQuotaMBytes") !~ /\d\d*/
|| $r->param("FTPQuotaMBytes") < 0 )
@@ -174,24 +178,41 @@
# add user to LDAP from user ldif template
if ( $self->addDataFromLdif( "templates/users.ldif.template", $r ) ) {
if ( $r->param("mailHost") ) {
- $self->addProcessToHost( $domain, $r->param("mailHost"),"createMailbox", "mailbox=$_uid");
- my $quota=$r->param("mailQuota") * 1024;
- $self->addProcessToHost($domain, $r->param("mailHost"), "setMailboxQuota", "mailbox=$_uid"a=$quota");
+ $self->addProcessToHost( $domain, $r->param("mailHost"),
+ "createMailbox", "mailbox=$_uid" );
+ my $quota = $r->param("mailQuota") * 1024;
+ $self->addProcessToHost( $domain, $r->param("mailHost"),
+ "setMailboxQuota", "mailbox=$_uid"a=$quota" );
}
- # send the process to method addUserFileServerProcess
- # the process will only be sent to fileHost if one is defined
- # if not defined then we fall back to the old method and send to the filserver group
+ # send the process to method addUserFileServerProcess
+ # the process will only be sent to fileHost if one is defined
+ # if not defined then we fall back to the old method and
+ # send to the filserver group
# passing domain, username, process and username as params
- my $_userInfo=$self->getUserInfo($_uid);
- $self->addUserFileServerProcess( $domain, $_uid, 'createHomeDirectory', "uid=$_uid&homeDirectory=$_userInfo->{'homeDirectory'}&uidNumber=$_userInfo->{'uidNumber'}&gidNumber=$_userInfo->{'gidNumber'}");
-
+ my $_userInfo = $self->getUserInfo($_uid);
+ $self->addUserFileServerProcess( $domain, $_uid, 'createHomeDirectory',
+ "uid=$_uid&homeDirectory=$_userInfo->{'homeDirectory'}&"
+ . "uidNumber=$_userInfo->{'uidNumber'}&"
+ . "gidNumber=$_userInfo->{'gidNumber'}" );
return 1;
}
}
+sub getDNForMailAddress {
+ my $self = shift;
+ my $found = "";
+ while ( ! $found && (my $mail = shift )) {
+ my $entries =
+ $self->getEntriesAsHashRef( $self->{'Config'}->{'ldapBaseDN'},
+ "|(mailLocalAddress=$mail)(mailAlias=$mail)" );
+ my ($found) = keys %$entries;
+ }
+ return $found;
+}
+
sub getUserInfo {
my $self = shift;
my $uid = shift;
@@ -233,7 +254,6 @@
print "Deleting $dn<br>";
$self->{'user'} = $self->{'ldap'}->getEntryAsHashRef($dn);
-
#it is possible that as user has multiple uids.
#hint
#aghaffar_ispman_org
@@ -244,30 +264,30 @@
# first send processes.
-# %%% new method %%
-# send the process to method addUserFileServerProcess
-# the process will only be sent to fileHost if one is defined
-# if not defined then we fall back to the old method and send to the filserver group
-
-# passing domain, username, process and username,homedirecory,uid,gid as params
+ # %%% new method %%
+ # send the process to method addUserFileServerProcess
+ # the process will only be sent to fileHost if one is defined
+ # if not defined then we fall back to the old method and
+ # send to the filserver group
$self->addUserFileServerProcess(
$self->{'user'}{'ispmanDomain'},
$self->{'user'}{'uid'},
'deleteHomeDirectory',
- join '&', (
- "uid=" . $self->{'user'}{'uid'},
- "homeDirectory=" . $self->{'user'}{'homeDirectory'},
- "uidNumber=" . $self->{'user'}{'uidNumber'},
- "gidNumber=" . $self->{'user'}{'gidNumber'}
+ join '&',
+ (
+ "uid=" . $self->{'user'}{'uid'},
+ "homeDirectory=" . $self->{'user'}{'homeDirectory'},
+ "uidNumber=" . $self->{'user'}{'uidNumber'},
+ "gidNumber=" . $self->{'user'}{'gidNumber'}
)
);
if ( $self->{'user'}{"mailHost"} ) {
$self->addProcessToHost(
- $self->{'user'}{'ispmanDomain'},
- $self->{'user'}{"mailHost"},
- "deleteMailbox", "mailbox=$self->{'user'}{'uid'}");
+ $self->{'user'}{'ispmanDomain'}, $self->{'user'}{"mailHost"},
+ "deleteMailbox", "mailbox=$self->{'user'}{'uid'}"
+ );
}
$self->deleteEntry($dn);
}
@@ -276,9 +296,9 @@
my $self = shift;
my $r = shift;
- my $dn = $self->getUserDN( $r->param("ispmanDomain"), $r->param("uid") );
+ my $dn = $self->getUserDN( $r->param("ispmanDomain"), $r->param("uid") );
- $self->killUser( $dn );
+ $self->killUser($dn);
print $self->refreshSignal( $r->param("ispmanDomain") );
@@ -296,28 +316,26 @@
}
# added by Michael Bunk, Jan 2006
-sub containsInvalidMailAliases
-{
- my $self = shift;
- my $aliases = shift;
- my $masterDomain = shift;
- my $replicas = $self->getReplicasOfDomain($masterDomain);
- my @validDomains;
- if(defined($replicas)) { @validDomains = keys %$replicas; }
- push @validDomains, $masterDomain;
-OUTER: foreach(@$aliases)
- {
- next if(/^[\w\.\-\+]*$/);
- if(/^[\w\.\-\+]*@([\w\.\-]+)$/)
- {
- foreach my $d (@validDomains)
- {
- next OUTER if($d eq $1);
- }
+sub containsInvalidMailAliases {
+ my $self = shift;
+ my $aliases = shift;
+ my $masterDomain = shift;
+ my $replicas = $self->getReplicasOfDomain($masterDomain);
+ my @validDomains;
+ if ( defined($replicas) ) { @validDomains = keys %$replicas; }
+ push @validDomains, $masterDomain;
+ OUTER: foreach (@$aliases) {
+ next if (/^[\w\.\-\+]*$/);
+ if (/^[\w\.\-\+]*@([\w\.\-]+)$/) {
+ foreach my $d (@validDomains) {
+ next OUTER if ( $d eq $1 );
+ }
+ }
+ return ( 1,
+ _("Mail aliases to users from foreign domains are forbidden: '$_'")
+ );
}
- return (1, _("Mail aliases to users from foreign domains are forbidden: '$_'"));
- }
- return (0, undef);
+ return ( 0, undef );
}
sub update_user {
@@ -325,7 +343,7 @@
my $r = shift;
my $dn = $self->getUserDN( $r->param("ispmanDomain"), $r->param("uid") );
my $userInfo = $self->getUserInfo( $r->param("uid") );
- my $data = {};
+ my $data = {};
for (
qw(sn givenName homeDirectory loginShell mailLocalAddress mailRoutingAddress FTPStatus FTPQuotaMBytes)
)
@@ -341,32 +359,40 @@
$data->{'mailAlias'} =
$self->as_arrayref( split( /\s+/, $r->param("mailAlias") ) );
- # added by Michael Bunk, Jan 2006
- my ($invalid, $errmsg) = $self->containsInvalidMailAliases($data->{'mailAlias'},
- $userInfo->{'ispmanDomain'});
- if($invalid)
+ # check uniqueness of mail aliases
+ if ( my $check =
+ $self->getDNForMailAddress( split( /\s+/, $r->param("mailAlias") ) ) )
{
- print $errmsg;
- return 0;
+ print "Mail aliases conflict with \"$check\".";
+ return 0;
+ }
+
+ # added by Michael Bunk, Jan 2006
+ my ( $invalid, $errmsg ) =
+ $self->containsInvalidMailAliases( $data->{'mailAlias'},
+ $userInfo->{'ispmanDomain'} );
+ if ($invalid) {
+ print $errmsg;
+ return 0;
}
$data->{'mailForwardingAddress'} =
$self->as_arrayref( split( /\s+/, $r->param("mailForwardingAddress") ) );
- # don't set objectclasses here! It would dishonor non-ispman
+ # don't set objectclasses here! It would dishonor non-ispman
# objectclasses and attributes. Update issues are handled by
# ldifupdate anyways.
# $data->{'objectClass'} = $self->{'Config'}{'ispmanUserObjectclasses'};
if ( $userInfo->{'mailHost'} && $r->param("mailQuota") ) {
- my $quota = $r->param("mailQuota") * 1024;
- my $mailbox=$r->param("uid");
+ my $quota = $r->param("mailQuota") * 1024;
+ my $mailbox = $r->param("uid");
unless ( $quota == $userInfo->{'mailQuota'} ) {
$data->{'mailQuota'} = $quota;
$self->addProcessToHost(
- $userInfo->{'ispmanDomain'},
- $userInfo->{'mailHost'},
- "setMailboxQuota", "mailbox=$mailbox"a=$quota");
+ $userInfo->{'ispmanDomain'}, $userInfo->{'mailHost'},
+ "setMailboxQuota", "mailbox=$mailbox"a=$quota"
+ );
}
}
@@ -400,13 +426,14 @@
my ( $uid, $domain, $values ) = @_;
# added by Michael Bunk, Jan 2006
- my ($invalid, $errmsg) = $self->containsInvalidMailAliases($values, $domain);
- if($invalid)
- {
- print $errmsg;
- # actually, we should return a Net::LDAP::Message to return the same
- # type as addUserAttributeValues()
- return 0;
+ my ( $invalid, $errmsg ) =
+ $self->containsInvalidMailAliases( $values, $domain );
+ if ($invalid) {
+ print $errmsg;
+
+ # actually, we should return a Net::LDAP::Message to return the same
+ # type as addUserAttributeValues()
+ return 0;
}
return $self->addUserAttributeValues( $uid, $domain, 'mailAlias', $values );
@@ -417,13 +444,14 @@
my ( $uid, $domain, $values ) = @_;
# added by Michael Bunk, Jan 2006
- my ($invalid, $errmsg) = $self->containsInvalidMailAliases($values, $domain);
- if($invalid)
- {
- print $errmsg;
- # actually, we should return a Net::LDAP::Message to return the same
- # type as addUserAttributeValues()
- return 0;
+ my ( $invalid, $errmsg ) =
+ $self->containsInvalidMailAliases( $values, $domain );
+ if ($invalid) {
+ print $errmsg;
+
+ # actually, we should return a Net::LDAP::Message to return the same
+ # type as addUserAttributeValues()
+ return 0;
}
return $self->replaceUserAttributeValues( $uid, $domain, 'mailAlias',
@@ -578,14 +606,11 @@
{ $attribute => $_values } );
}
+# generate unique uid from userid and domain
sub create_uid {
my $self = shift;
my ( $userId, $domain ) = @_;
- # here is the logic to convert userName to user_domain_tld
- # If you don't want this behaviour and just wasn't uid uncomment the next line;
- # return $userId;
-
$domain =~ s/\./_/g;
$userId =~ s/\./_/g;
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642