Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c7e99a2

Browse filesBrowse files
Artem Stepinjderusse
authored andcommitted
[Ldap] Incorrect determination of RelativeDistinguishedName for the "move" operation
1 parent e96b0e7 commit c7e99a2
Copy full SHA for c7e99a2

File tree

Expand file treeCollapse file tree

2 files changed

+33
-3
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+33
-3
lines changed

‎src/Symfony/Component/Ldap/Adapter/ExtLdap/EntryManager.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Ldap/Adapter/ExtLdap/EntryManager.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function addAttributeValues(Entry $entry, string $attribute, array $value
7979
$con = $this->getConnectionResource();
8080

8181
if (!@ldap_mod_add($con, $entry->getDn(), [$attribute => $values])) {
82-
throw new LdapException(sprintf('Could not add values to entry "%s", attribute %s: ', $entry->getDn(), $attribute).ldap_error($con));
82+
throw new LdapException(sprintf('Could not add values to entry "%s", attribute "%s": ', $entry->getDn(), $attribute).ldap_error($con));
8383
}
8484
}
8585

@@ -94,7 +94,7 @@ public function removeAttributeValues(Entry $entry, string $attribute, array $va
9494
$con = $this->getConnectionResource();
9595

9696
if (!@ldap_mod_del($con, $entry->getDn(), [$attribute => $values])) {
97-
throw new LdapException(sprintf('Could not remove values from entry "%s", attribute %s: ', $entry->getDn(), $attribute).ldap_error($con));
97+
throw new LdapException(sprintf('Could not remove values from entry "%s", attribute "%s": ', $entry->getDn(), $attribute).ldap_error($con));
9898
}
9999
}
100100

@@ -159,7 +159,7 @@ public function applyOperations(string $dn, iterable $operations): void
159159

160160
private function parseRdnFromEntry(Entry $entry): string
161161
{
162-
if (!preg_match('/^([^,]+),/', $entry->getDn(), $matches)) {
162+
if (!preg_match('/(^[^,\\\\]*(?:\\\\.[^,\\\\]*)*),/', $entry->getDn(), $matches)) {
163163
throw new LdapException(sprintf('Entry "%s" malformed, could not parse RDN.', $entry->getDn()));
164164
}
165165

‎src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/EntryManagerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/EntryManagerTest.php
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,34 @@ public function testGetResources()
4444
$entryManager = new EntryManager($connection);
4545
$entryManager->update($entry);
4646
}
47+
48+
/**
49+
* @see https://tools.ietf.org/html/rfc4514#section-3
50+
*
51+
* @dataProvider moveWithRFC4514DistinguishedNameProvider
52+
*/
53+
public function testMoveWithRFC4514DistinguishedName(string $dn, string $expectedRdn)
54+
{
55+
$connection = $this->createMock(Connection::class);
56+
57+
$entry = new Entry($dn);
58+
$entryManager = new EntryManager($connection);
59+
60+
$method = (new \ReflectionClass(EntryManager::class))->getMethod('parseRdnFromEntry');
61+
$method->setAccessible(true);
62+
63+
$cn = $method->invokeArgs($entryManager, [$entry, 'a']);
64+
65+
$this->assertSame($expectedRdn, $cn);
66+
}
67+
68+
public function moveWithRFC4514DistinguishedNameProvider(): array
69+
{
70+
return [
71+
['CN=Simple,DC=example,DC=net', 'CN=Simple'],
72+
['CN=James \"Jim\" Smith\, III,DC=example,DC=net', 'CN=James \"Jim\" Smith\, III'],
73+
['UID=jsmith,DC=example,DC=net', 'UID=jsmith'],
74+
["CN=Before\0dAfter,DC=example,DC=net", "CN=Before\0dAfter"],
75+
];
76+
}
4777
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.