Page MenuHomePhorge

D5286.1775249052.diff
No OneTemporary

Authored By
Unknown
Size
8 KB
Referenced Files
None
Subscribers
None

D5286.1775249052.diff

diff --git a/src/app/Console/Commands/Data/Import/LdifCommand.php b/src/app/Console/Commands/Data/Import/LdifCommand.php
--- a/src/app/Console/Commands/Data/Import/LdifCommand.php
+++ b/src/app/Console/Commands/Data/Import/LdifCommand.php
@@ -179,10 +179,10 @@
[$attr, $remainder] = explode(':', $line, 2);
$attr = strtolower($attr);
- if ($remainder[0] === ':') {
+ if (isset($remainder[0]) && $remainder[0] === ':') {
$remainder = base64_decode(substr($remainder, 2));
} else {
- $remainder = ltrim($remainder);
+ $remainder = ltrim((string) $remainder);
}
if (array_key_exists($attr, $entry)) {
@@ -228,7 +228,7 @@
}
$this->wallet->owner->contacts()->create([
- 'name' => $data->name,
+ 'name' => $data->name ?? null,
'email' => $data->email,
]);
}
@@ -633,6 +633,14 @@
'Domains' => 'domain',
];
+ // Skip entries with these classes
+ $ignoreByClass = [
+ 'cossuperdefinition',
+ 'extensibleobject',
+ 'nscontainer',
+ 'nsroledefinition',
+ ];
+
// Ignore LDIF header
if (!empty($entry['version'])) {
return null;
@@ -640,15 +648,17 @@
if (!isset($entry['objectclass'])) {
$entry['objectclass'] = [];
+ } else {
+ $entry['objectclass'] = array_map('strtolower', (array) $entry['objectclass']);
}
// Skip non-importable entries
- if (
- preg_match('/uid=(cyrus-admin|kolab-service)/', $entry['dn'])
- || in_array('nsroledefinition', $entry['objectclass'])
- || in_array('organizationalUnit', $entry['objectclass'])
- || in_array('organizationalunit', $entry['objectclass'])
- ) {
+ if (count(array_intersect($entry['objectclass'], $ignoreByClass)) > 0) {
+ return null;
+ }
+
+ // Skip special entries
+ if (preg_match('/uid=(cyrus-admin|kolab-service)/', $entry['dn'])) {
return null;
}
@@ -684,7 +694,7 @@
}
// Silently ignore groups with no 'mail' attribute
- if ($type == 'group' && empty($entry['mail'])) {
+ if (empty($entry['mail']) && $type == 'group') {
return null;
}
@@ -716,7 +726,9 @@
if (empty($entry['mail'])) {
$error = "Missing 'mail' attribute";
} else {
- if (!empty($entry['cn'])) {
+ if (!empty($entry['displayname'])) {
+ $result['name'] = $this->attrStringValue($entry, 'displayname');
+ } elseif (!empty($entry['cn'])) {
$result['name'] = $this->attrStringValue($entry, 'cn');
}
@@ -745,6 +757,8 @@
}
} elseif (!empty($entry['dn']) && str_starts_with($entry['dn'], 'dc=')) {
$result['namespace'] = strtolower(str_replace(['dc=', ','], ['', '.'], $entry['dn']));
+ } elseif (!empty($entry['ou']) && preg_match('/^[a-zA-Z0-9.]+\.[a-zA-Z]+$/', $entry['ou'])) {
+ $result['namespace'] = strtolower($entry['ou']);
} else {
$error = "Missing 'associatedDomain' and 'dn' attribute";
}
@@ -1001,6 +1015,7 @@
$rights = $map[$rights] ?? $rights;
if (in_array($rights, $supportedRights) && ($label === 'anyone' || strpos($label, '@'))) {
+ $label = strtolower($label);
$entry = "{$label}, {$rights}";
}
@@ -1047,7 +1062,7 @@
// 'deny' rules aren't supported
if (isset($entry[0]) && $entry[0] !== '-') {
- $rule = $entry;
+ $rule = strtolower($entry);
}
$rules[$idx] = $rule;
diff --git a/src/database/migrations/2025_05_30_100000_users_password_ldap_column.php b/src/database/migrations/2025_05_30_100000_users_password_ldap_column.php
new file mode 100644
--- /dev/null
+++ b/src/database/migrations/2025_05_30_100000_users_password_ldap_column.php
@@ -0,0 +1,28 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration {
+ /**
+ * Run the migrations.
+ */
+ public function up()
+ {
+ Schema::table(
+ 'users',
+ static function (Blueprint $table) {
+ $table->string('password_ldap', 512)->nullable()->change();
+ }
+ );
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down()
+ {
+ // Note: We can't set the length to a smaller value if there are already entries that are long
+ }
+};
diff --git a/src/tests/Feature/Console/Data/Import/LdifTest.php b/src/tests/Feature/Console/Data/Import/LdifTest.php
--- a/src/tests/Feature/Console/Data/Import/LdifTest.php
+++ b/src/tests/Feature/Console/Data/Import/LdifTest.php
@@ -113,14 +113,17 @@
/** @var Domain[] $domains */
$domains = $owner->domains(false, false)->orderBy('namespace')->get();
- $this->assertCount(2, $domains);
+ $this->assertCount(3, $domains);
$this->assertSame('kolab3-alias.com', $domains[0]->namespace);
$this->assertSame('kolab3.com', $domains[1]->namespace);
+ $this->assertSame('my.kolab3.com', $domains[2]->namespace);
$this->assertSame(Domain::TYPE_EXTERNAL, $domains[0]->type);
$this->assertSame(Domain::TYPE_EXTERNAL, $domains[1]->type);
+ $this->assertSame(Domain::TYPE_EXTERNAL, $domains[2]->type);
$this->assertEntitlements($domains[0], ['domain-hosting']);
$this->assertEntitlements($domains[1], ['domain-hosting']);
+ $this->assertEntitlements($domains[2], ['domain-hosting']);
// Shared folders
/** @var SharedFolder[] $folders */
@@ -268,6 +271,11 @@
$result = $this->invokeMethod($command, 'parseLDAPContact', [$entry]);
$this->assertSame(['name' => 'Test', 'email' => 'test@test.com'], $result[0]);
$this->assertNull($result[1]);
+
+ $entry = ['mail' => ['test@test.com'], 'cn' => 'Test', 'displayname' => 'Display Name'];
+ $result = $this->invokeMethod($command, 'parseLDAPContact', [$entry]);
+ $this->assertSame(['name' => 'Display Name', 'email' => 'test@test.com'], $result[0]);
+ $this->assertNull($result[1]);
}
/**
@@ -287,6 +295,16 @@
$this->assertSame(['namespace' => 'test.com'], $result[0]);
$this->assertNull($result[1]);
+ $entry = ['ou' => 'sub.test.com'];
+ $result = $this->invokeMethod($command, 'parseLDAPDomain', [$entry]);
+ $this->assertSame(['namespace' => 'sub.test.com'], $result[0]);
+ $this->assertNull($result[1]);
+
+ $entry = ['dn' => 'dc=test,dc=kolab,dc=org'];
+ $result = $this->invokeMethod($command, 'parseLDAPDomain', [$entry]);
+ $this->assertSame(['namespace' => 'test.kolab.org'], $result[0]);
+ $this->assertNull($result[1]);
+
$entry = ['associateddomain' => 'test.com', 'inetdomainstatus' => 'deleted'];
$result = $this->invokeMethod($command, 'parseLDAPDomain', [$entry]);
$this->assertSame([], $result[0]);
diff --git a/src/tests/data/kolab3.ldif b/src/tests/data/kolab3.ldif
--- a/src/tests/data/kolab3.ldif
+++ b/src/tests/data/kolab3.ldif
@@ -1,3 +1,6 @@
+version: 1
+
+# entry-id: 1
dn: associateddomain=kolab3.com,ou=Domains,dc=hosted,dc=com
objectClass: top
objectClass: domainrelatedobject
@@ -6,6 +9,17 @@
associatedDomain: kolab3.com
associatedDomain: kolab3-alias.com
+# entry-id: 2
+dn: ou=my.kolab3.com,ou=Domains,dc=hosted,dc=com
+modifyTimestamp: 20220912130615Z
+modifiersName: cn=directory manager
+nsUniqueId: ed008f0d-21fe11ed-90dee5c5-e8b7dc42
+ou: my.kolab3.com
+objectClass: top
+objectClass: organizationalunit
+creatorsName: cn=directory manager
+createTimestamp: 20220822094441Z
+
dn: uid=owner@kolab3.com,ou=People,ou=kolab3.com,dc=hosted,dc=com
cn: Aleksander Machniak
displayName: Machniak, Aleksander
@@ -66,7 +80,7 @@
uniqueMember: uid=user@kolab3.com,ou=People,ou=kolab3.com,dc=hosted,dc=com
uniqueMember: uid=owner@kolab3.com,ou=People,ou=kolab3.com,dc=hosted,dc=com
kolabAllowSMTPRecipient: recipient@kolab.org
-kolabAllowSMTPSender: sender@gmail.com
+kolabAllowSMTPSender: Sender@gmail.com
dn: cn=Error,ou=Groups,ou=kolab3.com,dc=hosted,dc=com
cn: Error
@@ -108,7 +122,7 @@
alias: folder-alias1@kolab3.com
alias: folder-alias2@kolab3.com
acl: anyone, read-write
-acl: owner@kolab3.com, full
+acl: Owner@kolab3.com, full
dn: cn=Folder2,ou=Shared Folders,ou=kolab3.com,dc=hosted,dc=com
cn: Folder2

File Metadata

Mime Type
text/plain
Expires
Fri, Apr 3, 8:44 PM (2 h, 48 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18826421
Default Alt Text
D5286.1775249052.diff (8 KB)

Event Timeline