Skip to content

Commit 4325585

Browse files
feat: emit delegated managed service accounts
I now process delegated managed service accounts as typed objects, resolve their predecessor links, and write them to a dedicated collection file. Signed-off-by: Adil Alperen Çiftci <adilalperenciftci@users.noreply.github.com>
1 parent 846e431 commit 4325585

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

‎src/Runtime/ObjectProcessors.cs‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ internal async Task<OutputBase> ProcessObject(IDirectoryObject entry, ResolvedSe
137137
return await ProcessSiteServerObject(entry, resolvedSearchResult);
138138
case Label.SiteSubnet:
139139
return await ProcessSiteSubnetObject(entry, resolvedSearchResult);
140+
case Label.DMSA:
141+
return await ProcessDMSAObject(entry, resolvedSearchResult);
140142
case Label.Base:
141143
return null;
142144
default:
@@ -248,6 +250,46 @@ await _containerProcessor.GetContainingObject(dn) is (true, var container))
248250
return ret;
249251
}
250252

253+
private async Task<DMSA> ProcessDMSAObject(IDirectoryObject entry,
254+
ResolvedSearchResult resolvedSearchResult) {
255+
var ret = new DMSA {
256+
ObjectIdentifier = resolvedSearchResult.ObjectId,
257+
Properties = new Dictionary<string, object>(GetCommonProperties(entry, resolvedSearchResult)) {
258+
{ "samaccountname", entry.GetProperty(LDAPProperties.SAMAccountName) }
259+
}
260+
};
261+
262+
if (_methods.HasFlag(CollectionMethod.ACL)) {
263+
var aces = await _aclProcessor.ProcessACL(resolvedSearchResult, entry, true)
264+
.ToArrayAsync(cancellationToken: _cancellationToken);
265+
ret.Properties.Add("doesanyacegrantownerrights", aces.Any(ace => ace.IsPermissionForOwnerRightsSid));
266+
ret.Properties.Add("doesanyinheritedacegrantownerrights",
267+
aces.Any(ace => ace.IsInheritedPermissionForOwnerRightsSid));
268+
ret.Aces = aces;
269+
ret.IsACLProtected = _aclProcessor.IsACLProtected(entry);
270+
ret.Properties.Add("isaclprotected", ret.IsACLProtected);
271+
}
272+
273+
if (_methods.HasFlag(CollectionMethod.ObjectProps)) {
274+
if (entry.TryGetProperty(LDAPProperties.ManagedAccountPrecededByLink, out var predecessor) &&
275+
await _context.LDAPUtils.ResolveDistinguishedName(predecessor) is (true, var principal)) {
276+
ret.PrecededBy = principal;
277+
}
278+
279+
if (_context.Flags.CollectAllProperties) {
280+
ret.Properties = ContextUtils.Merge(_ldapPropertyProcessor.ParseAllProperties(entry),
281+
ret.Properties);
282+
}
283+
}
284+
285+
if (_methods.HasFlag(CollectionMethod.Container) &&
286+
await _containerProcessor.GetContainingObject(entry) is (true, var container)) {
287+
ret.ContainedBy = container;
288+
}
289+
290+
return ret;
291+
}
292+
251293
private async Task<Computer> ProcessComputerObject(
252294
IDirectoryObject entry,
253295
ResolvedSearchResult resolvedSearchResult

‎src/Runtime/OutputWriter.cs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class OutputWriter
3737
private readonly JsonDataWriter<Site> _siteOutput;
3838
private readonly JsonDataWriter<SiteServer> _siteServerOutput;
3939
private readonly JsonDataWriter<SiteSubnet> _siteSubnetOutput;
40+
private readonly JsonDataWriter<DMSA> _dmsaOutput;
4041

4142

4243
private int _completedCount;
@@ -63,6 +64,7 @@ public OutputWriter(IContext context, Channel<OutputBase> outputChannel)
6364
_siteOutput = new JsonDataWriter<Site>(_context, DataType.Sites);
6465
_siteServerOutput = new JsonDataWriter<SiteServer>(_context, DataType.SiteServers);
6566
_siteSubnetOutput = new JsonDataWriter<SiteSubnet>(_context, DataType.SiteSubnets);
67+
_dmsaOutput = new JsonDataWriter<DMSA>(_context, DataType.DMSAs);
6668

6769
_runTimer = new Stopwatch();
6870
_statusTimer = new Timer(_context.StatusInterval);
@@ -160,6 +162,9 @@ internal async Task<string> StartWriter()
160162
case SiteSubnet siteSubnet:
161163
await _siteSubnetOutput.AcceptObject(siteSubnet);
162164
break;
165+
case DMSA dmsa:
166+
await _dmsaOutput.AcceptObject(dmsa);
167+
break;
163168
default:
164169
throw new ArgumentOutOfRangeException(nameof(item));
165170
}
@@ -187,6 +192,7 @@ private async Task<string> FlushWriters()
187192
await _siteOutput.FlushWriter();
188193
await _siteServerOutput.FlushWriter();
189194
await _siteSubnetOutput.FlushWriter();
195+
await _dmsaOutput.FlushWriter();
190196
CloseOutput();
191197
var fileName = ZipFiles();
192198
return fileName;
@@ -218,6 +224,7 @@ private string ZipFiles()
218224
_enterpriseCAOutput.GetFilename(), _nTAuthStoreOutput.GetFilename(),
219225
_certTemplateOutput.GetFilename(), _issuancePolicyOutput.GetFilename(),
220226
_siteOutput.GetFilename(), _siteServerOutput.GetFilename(), _siteSubnetOutput.GetFilename(),
227+
_dmsaOutput.GetFilename(),
221228
});
222229

223230
foreach (var entry in fileList.Where(x => !string.IsNullOrEmpty(x)))
@@ -245,4 +252,4 @@ private string ZipFiles()
245252
return resolvedFileName;
246253
}
247254
}
248-
}
255+
}

0 commit comments

Comments
 (0)