gunnar: server/perl-kolab/lib/Kolab LDAP.pm,1.1,1.2
cvs at kolab.org
cvs at kolab.org
Wed Nov 28 13:45:34 CET 2007
Author: gunnar
Update of /kolabrepository/server/perl-kolab/lib/Kolab
In directory doto:/tmp/cvs-serv23550/perl-kolab/lib/Kolab
Modified Files:
LDAP.pm
Log Message:
kolab/issue1313 (resmngr cannot create calendar folder in multidomain setup)
Index: LDAP.pm
===================================================================
RCS file: /kolabrepository/server/perl-kolab/lib/Kolab/LDAP.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- LDAP.pm 1 Aug 2007 14:57:42 -0000 1.1
+++ LDAP.pm 28 Nov 2007 12:45:32 -0000 1.2
@@ -36,6 +36,8 @@
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 @@
# 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 @@
%uid_db = %newuid_db;
+ syncDomains();
+
Kolab::log('L', 'Finished synchronisation');
}
@@ -684,6 +694,101 @@
Kolab::log('L', "Finished `$p' object synchronisation");
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__
More information about the commits
mailing list