Page MenuHomePhorge

D5286.1775399211.diff
No OneTemporary

Authored By
Unknown
Size
6 KB
Referenced Files
None
Subscribers
None

D5286.1775399211.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' || in_array('organizationalunit', $entry['objectclass']))) {
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";
}
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,33 @@
+<?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()
+ {
+ Schema::table(
+ 'users',
+ static function (Blueprint $table) {
+ $table->string('password_ldap')->nullable()->change();
+ }
+ );
+ }
+};
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
@@ -268,6 +268,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 +292,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]);

File Metadata

Mime Type
text/plain
Expires
Sun, Apr 5, 2:26 PM (4 m, 22 s ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18833642
Default Alt Text
D5286.1775399211.diff (6 KB)

Event Timeline