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 a316a31

Browse filesBrowse files
committed
bug #39518 [Ldap] Incorrect determination of RelativeDistinguishedName for the "move" operation (astepin)
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [Ldap] Incorrect determination of RelativeDistinguishedName for the "move" operation | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - If the specified "DistinguishedName" contains a comma in the first value, the first "RelativeDistinguishedName" was determined incorrectly. The regular expression now matches up to the first comma which was not escaped with backslash. Testing private methods is a bit messy here. However, I thought it was better than testing this against an LDAP server. Source: https://tools.ietf.org/html/rfc4514#section-3 Commits ------- c7e99a2 [Ldap] Incorrect determination of RelativeDistinguishedName for the "move" operation
2 parents e96b0e7 + c7e99a2 commit a316a31
Copy full SHA for a316a31

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.