Skip to content

Commit 4988061

Browse files
authored
Fix authentication with DirectoryEntry (#89)
1 parent 94a8306 commit 4988061

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

src/CommonLib/LDAPUtils.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,18 +1702,30 @@ private class ResolvedWellKnownPrincipal
17021702

17031703
public string GetConfigurationPath(string domainName = null)
17041704
{
1705-
var rootDse = domainName == null
1706-
? new DirectoryEntry("LDAP://RootDSE")
1707-
: new DirectoryEntry($"LDAP://{NormalizeDomainName(domainName)}/RootDSE");
1705+
string path = domainName == null
1706+
? "LDAP://RootDSE"
1707+
: $"LDAP://{NormalizeDomainName(domainName)}/RootDSE";
1708+
1709+
DirectoryEntry rootDse;
1710+
if (_ldapConfig.Username != null)
1711+
rootDse = new DirectoryEntry(path, _ldapConfig.Username, _ldapConfig.Password);
1712+
else
1713+
rootDse = new DirectoryEntry(path);
17081714

17091715
return $"{rootDse.Properties["configurationNamingContext"]?[0]}";
17101716
}
17111717

17121718
public string GetSchemaPath(string domainName)
17131719
{
1714-
var rootDse = domainName == null
1715-
? new DirectoryEntry("LDAP://RootDSE")
1716-
: new DirectoryEntry($"LDAP://{NormalizeDomainName(domainName)}/RootDSE");
1720+
string path = domainName == null
1721+
? "LDAP://RootDSE"
1722+
: $"LDAP://{NormalizeDomainName(domainName)}/RootDSE";
1723+
1724+
DirectoryEntry rootDse;
1725+
if (_ldapConfig.Username != null)
1726+
rootDse = new DirectoryEntry(path, _ldapConfig.Username, _ldapConfig.Password);
1727+
else
1728+
rootDse = new DirectoryEntry(path);
17171729

17181730
return $"{rootDse.Properties["schemaNamingContext"]?[0]}";
17191731
}

0 commit comments

Comments
 (0)