Skip to content

Commit

Permalink
fix: replace BUILTIN container with domain node
Browse files Browse the repository at this point in the history
  • Loading branch information
mistahj67 committed Apr 17, 2024
1 parent e9ef5be commit 1689cb2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/CommonLib/Processors/ContainerProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ public TypedPrincipal GetContainingObject(string distinguishedName)
{
var containerDn = Helpers.RemoveDistinguishedNamePrefix(distinguishedName);

if (containerDn.StartsWith("CN=BUILTIN", StringComparison.OrdinalIgnoreCase))
{
var domain = Helpers.DistinguishedNameToDomain(distinguishedName);
var domainSid = _utils.GetSidFromDomainName(domain);
return new TypedPrincipal(domainSid, Label.Domain);

Check failure on line 55 in src/CommonLib/Processors/ContainerProcessor.cs

View workflow job for this annotation

GitHub Actions / build

The name 'Label' does not exist in the current context

Check failure on line 55 in src/CommonLib/Processors/ContainerProcessor.cs

View workflow job for this annotation

GitHub Actions / build

The name 'Label' does not exist in the current context
}

if (string.IsNullOrEmpty(containerDn))
return null;

Expand Down
4 changes: 4 additions & 0 deletions test/unit/ContainerProcessorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ public void ContainerProcessor_GetContainingObject_ExpectedResult()
result = proc.GetContainingObject("CN=PRIMARY,OU=DOMAIN CONTROLLERS,DC=TESTLAB,DC=LOCAL");
Assert.Equal(Label.OU, result.ObjectType);
Assert.Equal("0DE400CD-2FF3-46E0-8A26-2C917B403C65", result.ObjectIdentifier);

result = proc.GetContainingObject("CN=ADMINISTRATORS,CN=BUILTIN,DC=TESTLAB,DC=LOCAL");
Assert.Equal(Label.Domain, result.ObjectType);
Assert.Equal("S-1-5-21-3130019616-2776909439-2417379446", result.ObjectIdentifier);
}

[Fact]
Expand Down
7 changes: 6 additions & 1 deletion test/unit/Facades/MockLDAPUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,12 @@ public string GetDomainNameFromSid(string sid)

public string GetSidFromDomainName(string domainName)
{
throw new NotImplementedException();
if (domainName.Equals("TESTLAB.LOCAL", StringComparison.OrdinalIgnoreCase))
{
return "S-1-5-21-3130019616-2776909439-2417379446";
}

return null;
}

public string ConvertWellKnownPrincipal(string sid, string domain)
Expand Down

0 comments on commit 1689cb2

Please sign in to comment.