Skip to content

Commit de07b51

Browse files
committed
more progress
1 parent bb75d89 commit de07b51

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

src/ADEffectiveAccess/AclBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ internal AclBuilder(string path, byte[] descriptor) : base()
2424
_group = GetGroup(_targetType);
2525
}
2626

27-
internal IEnumerable<EffectiveAccessRule> EnumerateAccessRules(SchemaMap map)
27+
internal IEnumerable<EffectiveAccessRule> EnumerateAccessRules(GuidResolver map)
2828
{
2929
foreach (ActiveDirectoryAccessRule rule in GetAccessRules(true, true, _targetType))
3030
{
@@ -36,7 +36,7 @@ internal IEnumerable<EffectiveAccessRule> EnumerateAccessRules(SchemaMap map)
3636
}
3737
}
3838

39-
internal IEnumerable<EffectiveAuditRule> EnumerateAuditRules(SchemaMap map)
39+
internal IEnumerable<EffectiveAuditRule> EnumerateAuditRules(GuidResolver map)
4040
{
4141
foreach (ActiveDirectoryAuditRule rule in GetAuditRules(true, true, _targetType))
4242
{

src/ADEffectiveAccess/GetADEffectiveAccessComand.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ public sealed class GetADEffectiveAccessComand : PSCmdlet
1515

1616
private const string IdentitySet = "Identity";
1717

18-
private SchemaMap? _map;
18+
[ThreadStatic]
19+
private static GuidResolver? _map;
1920

2021
[Parameter(Position = 0, ParameterSetName = FilterSet)]
2122
[ValidateNotNullOrEmpty]
@@ -55,7 +56,8 @@ protected override void BeginProcessing()
5556
{
5657
try
5758
{
58-
_map = new SchemaMap(Server);
59+
_map ??= new GuidResolver();
60+
_map.SetCurrentContext(Server);
5961
}
6062
catch (Exception exception)
6163
{
Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,35 @@
44

55
namespace ADEffectiveAccess;
66

7-
internal sealed class SchemaMap
7+
internal sealed class GuidResolver
88
{
9-
private readonly Dictionary<Guid, string> _schemaMap = [];
9+
private readonly Dictionary<string?, Dictionary<Guid, string>> _map = [];
1010

11-
internal SchemaMap(string? server = null)
11+
private Dictionary<Guid, string>? _current;
12+
13+
internal void SetCurrentContext(string? server = null)
1214
{
1315
string path = server is null ? "LDAP://RootDSE" : $"LDAP://{server}/RootDSE";
1416
using DirectoryEntry root = new(path);
17+
string? ctxName = root.Properties["defaultNamingContext"][0]?.ToString();
18+
if (_map.TryGetValue(ctxName, out Dictionary<Guid, string> current))
19+
{
20+
_current = current;
21+
return;
22+
}
23+
24+
current = [];
1525
string? ctxSchema = root.Properties["schemaNamingContext"][0]?.ToString();
1626
string? ctxConfig = root.Properties["configurationNamingContext"][0]?.ToString();
17-
if (ctxSchema is not null) PopulateSchema(ctxSchema, _schemaMap);
18-
if (ctxConfig is not null) PopulateExtendedRights(ctxConfig, _schemaMap);
27+
if (ctxSchema is not null) PopulateSchema(ctxSchema, current);
28+
if (ctxConfig is not null) PopulateExtendedRights(ctxConfig, current);
29+
_map[ctxName] = current;
30+
_current = current;
1931
}
2032

2133
internal string Translate(Guid guid, string defaultValue)
2234
{
23-
if (guid == Guid.Empty || _schemaMap.TryGetValue(guid, out defaultValue))
35+
if (guid == Guid.Empty || _current!.TryGetValue(guid, out defaultValue))
2436
{
2537
return defaultValue;
2638
}

0 commit comments

Comments
 (0)