|
4 | 4 |
|
5 | 5 | namespace ADEffectiveAccess; |
6 | 6 |
|
7 | | -internal sealed class SchemaMap |
| 7 | +internal sealed class GuidResolver |
8 | 8 | { |
9 | | - private readonly Dictionary<Guid, string> _schemaMap = []; |
| 9 | + private readonly Dictionary<string?, Dictionary<Guid, string>> _map = []; |
10 | 10 |
|
11 | | - internal SchemaMap(string? server = null) |
| 11 | + private Dictionary<Guid, string>? _current; |
| 12 | + |
| 13 | + internal void SetCurrentContext(string? server = null) |
12 | 14 | { |
13 | 15 | string path = server is null ? "LDAP://RootDSE" : $"LDAP://{server}/RootDSE"; |
14 | 16 | 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 = []; |
15 | 25 | string? ctxSchema = root.Properties["schemaNamingContext"][0]?.ToString(); |
16 | 26 | 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; |
19 | 31 | } |
20 | 32 |
|
21 | 33 | internal string Translate(Guid guid, string defaultValue) |
22 | 34 | { |
23 | | - if (guid == Guid.Empty || _schemaMap.TryGetValue(guid, out defaultValue)) |
| 35 | + if (guid == Guid.Empty || _current!.TryGetValue(guid, out defaultValue)) |
24 | 36 | { |
25 | 37 | return defaultValue; |
26 | 38 | } |
|
0 commit comments