summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGunnar Wrobel <wrobel@pardus.de>2007-11-28 12:45:32 (GMT)
committerGunnar Wrobel <wrobel@pardus.de>2007-11-28 12:45:32 (GMT)
commitf38c1307c5225fb946502c8d280f8a0fdfdefeba (patch)
tree256db41c60cc45ccad4a2cdc1c596a84bb58b0e0
parent9eba0b3fa1c09369e70c802b374c0a47a5114359 (diff)
downloadperl-Kolab-f38c1307c5225fb946502c8d280f8a0fdfdefeba.tar.gz
kolab/issue1313 (resmngr cannot create calendar folder in multidomain setup)
-rw-r--r--ChangeLog10
-rw-r--r--lib/Kolab/LDAP.pm107
2 files changed, 116 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 40fa4f7..145db92 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2007-11-28 Gunnar Wrobel <p@rdus.de>
+
+ * lib/Kolab/LDAP.pm (syncDomains, createObject):
+
+ Added syncing for the domins the user specified. We need one
+ calendar user in each domain and resource/group accounts should
+ allow the calendar user to access the mailbox.
+
+ kolab/issue1313 (resmngr cannot create calendar folder in multidomain setup)
+
2007-10-23 Thomas Arendsen Hein <thomas@intevation.de>
* lib/Kolab.pm: Show component and log level when sending debug
diff --git a/lib/Kolab/LDAP.pm b/lib/Kolab/LDAP.pm
index 030a2da..cfcf3b9 100644
--- a/lib/Kolab/LDAP.pm
+++ b/lib/Kolab/LDAP.pm
@@ -36,6 +36,8 @@ use DB_File;
use Kolab;
use Kolab::Util;
use Kolab::Cyrus;
+use Digest::SHA1 qw(sha1);
+use MIME::Base64 qw(encode_base64);
use vars qw(%uid_db %gyard_db %newuid_db %gyard_ts_db %quota_db);
require Exporter;
@@ -351,8 +353,14 @@ sub createObject
# the groups/resources folder.
# TODO: Don't hardcode username
Kolab::log('L', "Detected group or resource account, adding ACL for calendar", KOLAB_ERROR );
+ my $domain;
+ if ($uid =~ /.*\@(.*)/) {
+ $domain = $1;
+ } else {
+ $domain = $Kolab::config{'postfix-mydomain'};
+ }
Kolab::Cyrus::setACL($cyrus,$uid,0, ["$uid all",
- 'calendar@'.$Kolab::config{'postfix-mydomain'}
+ 'calendar@' . $domain
.' all']);
}
}
@@ -568,6 +576,8 @@ sub sync
%uid_db = %newuid_db;
+ syncDomains();
+
Kolab::log('L', 'Finished synchronisation');
}
@@ -685,6 +695,101 @@ sub syncBasic
return $ts;
}
+sub syncDomains
+{
+ Kolab::log('L', "Synchronising domains");
+
+ my $ldapmesg;
+ my $uid;
+ my $ldapobject;
+ my @domains;
+ my $domain;
+
+ my $ldap = &create(
+ $Kolab::config{'ldap_ip'},
+ $Kolab::config{'ldap_port'},
+ $Kolab::config{'bind_dn'},
+ $Kolab::config{'bind_pw'}
+ );
+
+ # If we have an old "cn=calendar" we need to fix the DN of that
+ # object
+ my $dn = 'cn=calendar,cn=internal,' . $Kolab::config{'base_dn'};
+ $ldapmesg = $ldap->search(
+ base => 'cn=internal,' . $Kolab::config{'base_dn'},
+ scope => 'one',
+ filter => '(&(objectClass=kolabInetOrgPerson)(cn=calendar))',
+ attrs => [
+ 'objectClass',
+ 'uid',
+ ],
+ );
+
+ if ( UNIVERSAL::isa( $ldapmesg, 'Net::LDAP::Search') && $ldapmesg->count() > 0) {
+ Kolab::log('L', "Identified old calendar user with DN `$dn'", KOLAB_DEBUG);
+ my $cn = 'cn=' . $Kolab::config{'calendar_id'} . '@' . $Kolab::config{'postfix-mydomain'};
+ $ldap->moddn($dn, newrdn => $cn, deleteoldrdn => 1);
+ Kolab::log('L', "Renamed old calendar user with DN `$dn' to DN `$cn'", KOLAB_INFO);
+ } else {
+ Kolab::log('L', "Unable to locate old calendar user with DN `$dn'", KOLAB_DEBUG);
+ }
+
+ if( ref($Kolab::config{'postfix-mydestination'}) eq 'ARRAY' ) {
+ @domains = @{$Kolab::config{'postfix-mydestination'}};
+ } else {
+ @domains =( $Kolab::config{'postfix-mydestination'} );
+ }
+
+ my $sha_pw = hash_pw($Kolab::config{'calendar_pw'});
+ foreach $domain (@domains) {
+ $uid = $Kolab::config{'calendar_id'} . '@' . $domain;
+ $dn = 'cn=' . $uid . ',cn=internal,' . $Kolab::config{'base_dn'};
+ $ldapmesg = $ldap->search(
+ base => $dn,
+ scope => 'one',
+ filter => '(&(objectClass=kolabInetOrgPerson))',
+ attrs => [
+ 'objectClass',
+ 'uid',
+ ],
+ );
+ if ( UNIVERSAL::isa( $ldapmesg, 'Net::LDAP::Search') && $ldapmesg->code() <= 0) {
+ Kolab::log('L', "Calendar user for domain `$domain' exists", KOLAB_DEBUG);
+ } else {
+ $ldapobject = Net::LDAP::Entry->new;
+ $ldapobject->replace('cn' => $uid,
+ 'sn' => 'n/a n/a',
+ 'uid' => $uid,
+ 'userPassword' => $sha_pw,
+ 'objectclass' => ['top','inetorgperson','kolabinetorgperson']);
+ $ldapobject->dn($dn);
+ $ldapobject->update($ldap);
+ undef $ldapobject;
+ Kolab::log('L', "Created new calendar user with DN `$dn' for domain `$domain'", KOLAB_INFO);
+ }
+ }
+
+}
+
+# Taken from Samba::LDAP::User.pm
+sub hash_pw {
+ my $pass = shift;
+
+ # Generate SSHA hash (SHA1 with salt)
+ my $salt = make_salt(4);
+ return '{SSHA}' . encode_base64(sha1($pass . $salt) . $salt, '');
+}
+
+sub make_salt {
+ my $self = shift;
+ my $length = shift || '32';
+
+ my @tab = ('.', '/', 0 .. 9, 'A' .. 'Z', 'a' .. 'z');
+
+ return join "", @tab[ map {rand 64} (1 .. $length) ];
+}
+
+
1;
__END__
# Below is stub documentation for your module. You'd better edit it!