diff --git a/Program.cs b/Program.cs index 201ac4a..4d84760 100644 --- a/Program.cs +++ b/Program.cs @@ -262,8 +262,18 @@ static int Main(string[] args) silentMode |= ConfigManager.Instance.Config.SilentMode; verboseMode |= ConfigManager.Instance.Config.VerboseMode; + // Before anything is read from ProgramData\ManagedBootstrap: a standard user can + // create files under ProgramData, and this process trusts what it finds there. + var dataDirectoryNotes = IsRunningAsAdministrator() + ? DataDirectoryGuard.Secure() + : new List(); + Logger.Initialize(LogDirectory, Version, verboseMode, silentMode); Logger.Debug("Main() called with arguments: " + string.Join(" ", args)); + foreach (var note in dataDirectoryNotes) + { + Logger.Warning($"Data directory: {note}"); + } foreach (var retired in ConfigManager.Instance.RetiredSettingsPresent) { Logger.Warning($"Setting {retired} is ignored: it was never implemented and has been removed"); @@ -936,7 +946,7 @@ private static int SaveSettingsFromArgs(string[] args) // never limited. The manifest and preflight are small; a throttled run // downloads no item. var throttle = BaselineThrottle.Evaluate(BaselineThrottle.Read(), DateTimeOffset.Now, - ConfigManager.Instance.Config.BaselineMinIntervalHours, forced); + ConfigManager.Instance.Config.BaselineMinIntervalHours, forced, Version); if (throttle.Skip) { Logger.WriteSkipped($"Baseline throttle: skipping this run: {throttle.Reason}"); diff --git a/README.md b/README.md index 7ec764b..562506c 100644 --- a/README.md +++ b/README.md @@ -222,13 +222,16 @@ prompt. Every baseline run downloads from the package host, so baselines are rate-limited. The check runs only after the preflight has chosen baseline, so provisioning is never limited. It reads `C:\ProgramData\ManagedBootstrap\baseline.json`, which holds the -last baseline's `end_time`, `status` and `consecutive_failures`. `last-run.json` +last baseline's `end_time`, `status`, `consecutive_failures`, the version that last +completed one (`tool_version`) and the version that last tried (`attempt_version`). `last-run.json` cannot hold the clock, because every run rewrites it. | Last baseline | Next baseline | |---|---| +| Completed by another BootstrapMate version, and this version has not tried one | Runs | +| Interrupted (the run never recorded its end) | Runs at the next trigger | | Completed less than `BaselineMinIntervalHours` ago (default 144) | Skips | -| Failed, partially failed or interrupted for the first time | One retry after 24 hours, never sooner | +| Failed or partially failed for the first time | One retry after 24 hours, never sooner | | Failed again after that retry | Waits the full interval | | None: a provisioning run clears the record | Runs | | Any, with `C:\ProgramData\ManagedBootstrap\.bootstrap_force` present | Runs; the preflight consumes the file | @@ -236,7 +239,8 @@ cannot hold the clock, because every run rewrites it. A throttled run fetches the manifest and runs the preflight, then downloads nothing. It logs why, ends as `skip`, records SetupAssistant and Userland as `Skipped` in `status.json`, and leaves `baseline.json` alone. `--force` does not bypass the -throttle. `BaselineMinIntervalHours` comes from policy or the settings registry +throttle, and BootstrapMate never relaunches itself: a retry comes only from the next +normal trigger (the Intune install or the daily Self-Heal task). `BaselineMinIntervalHours` comes from policy or the settings registry (0-8760; 0 disables the limit for completed runs). A baseline run also skips an item without downloading it when the manifest says diff --git a/RunReport.cs b/RunReport.cs index 65b3fc5..fd9df94 100644 --- a/RunReport.cs +++ b/RunReport.cs @@ -33,8 +33,8 @@ public static void Start(string version) /// /// A last-run.json still at "running" belongs to a run that died: this run holds the /// single-instance lock, so none other is going. Its session is relabelled - /// "interrupted", and an interrupted baseline counts as a failed one, so the throttle - /// gives it one retry a day later instead of letting whatever killed it loop. + /// "interrupted", and so is the baseline record, which lets the next baseline run + /// straight away: the retry comes from the next normal trigger, never a relaunch. /// private static void RecoverInterruptedRun() { @@ -46,7 +46,7 @@ private static void RecoverInterruptedRun() if (string.Equals(orphan.RunType, RunTypes.Baseline, StringComparison.OrdinalIgnoreCase)) { var when = DateTimeOffset.TryParse(orphan.StartTime, out var started) ? started : DateTimeOffset.Now; - BaselineThrottle.Write(BaselineThrottle.After(BaselineThrottle.Read(), RunStatuses.Interrupted, when)); + BaselineThrottle.Write(BaselineThrottle.After(BaselineThrottle.Read(), RunStatuses.Interrupted, when, orphan.ToolVersion)); } } @@ -97,7 +97,7 @@ public static void Finish(string? status = null) // The baseline clock: a baseline sets it, a provisioning run clears it (a // machine provisioned again starts over), a skip leaves it alone. if (_record.RunType == RunTypes.Baseline) - BaselineThrottle.Write(BaselineThrottle.After(BaselineThrottle.Read(), outcome.Status, new DateTimeOffset(outcome.End))); + BaselineThrottle.Write(BaselineThrottle.After(BaselineThrottle.Read(), outcome.Status, new DateTimeOffset(outcome.End), _record.ToolVersion)); else if (_record.RunType == RunTypes.Provisioning && outcome.Status == RunStatuses.Completed) BaselineThrottle.Clear(); } diff --git a/installer/Product.wxs b/installer/Product.wxs index 1be9831..5d701d0 100644 --- a/installer/Product.wxs +++ b/installer/Product.wxs @@ -80,6 +80,23 @@ + + + + + + + + + + + @@ -155,6 +172,7 @@ + diff --git a/resources/en-US/BootstrapMate.adml b/resources/en-US/BootstrapMate.adml index bed50d2..4179fe5 100644 --- a/resources/en-US/BootstrapMate.adml +++ b/resources/en-US/BootstrapMate.adml @@ -87,7 +87,7 @@ Default: Disabled Default: C:\Program Files\BootstrapMate Minimum Hours Between Baseline Runs - A baseline run that starts less than this many hours after the last completed baseline exits as a skip before downloading anything. A failed, partially failed or interrupted baseline gets one retry after 24 hours, never sooner; if that retry fails too, the full interval applies. Provisioning runs are not limited. While C:\ProgramData\ManagedBootstrap\.bootstrap_force is present the limit does not apply; the preflight consumes the file. + A baseline run that starts less than this many hours after the last completed baseline exits as a skip before downloading anything. A new BootstrapMate version always gets a baseline. An interrupted baseline runs again at the next trigger. A failed or partially failed baseline gets one retry after 24 hours, never sooner; if that retry fails too, the full interval applies. Provisioning runs are not limited. While C:\ProgramData\ManagedBootstrap\.bootstrap_force is present the limit does not apply; the preflight consumes the file. Range: 0-8760 hours Default: 144 hours (6 days) diff --git a/src/BootstrapMate.Core/BaselineThrottle.cs b/src/BootstrapMate.Core/BaselineThrottle.cs index 9afdc5b..be16afd 100644 --- a/src/BootstrapMate.Core/BaselineThrottle.cs +++ b/src/BootstrapMate.Core/BaselineThrottle.cs @@ -13,6 +13,10 @@ public sealed class BaselineRecord [JsonPropertyName("end_time")] public string EndTime { get; set; } = ""; [JsonPropertyName("status")] public string Status { get; set; } = ""; [JsonPropertyName("consecutive_failures")] public int ConsecutiveFailures { get; set; } + /// The BootstrapMate version of the last completed baseline. + [JsonPropertyName("tool_version")] public string? ToolVersion { get; set; } + /// The BootstrapMate version of the last baseline, whatever its outcome. + [JsonPropertyName("attempt_version")] public string? AttemptVersion { get; set; } } /// @@ -26,9 +30,14 @@ public sealed class BaselineRecord /// The .bootstrap_force file in ProgramData\ManagedBootstrap: run. The throttle /// only looks; the preflight consumes it. /// No record: run. A provisioning run clears the record. +/// This BootstrapMate is not the version that completed the last baseline, and has not +/// tried one yet: run. A new build always gets a baseline, whatever the interval; once it has +/// tried and failed, the failure rules below apply to it. +/// Last baseline was interrupted (it never recorded its end): run. The retry comes from +/// the next normal trigger; BootstrapMate never relaunches itself. /// Last baseline completed less than BaselineMinIntervalHours ago (default 144): skip. -/// Last baseline failed, partially failed or was interrupted: one retry after 24 hours; -/// if that retry fails too, the full interval applies again. +/// Last baseline failed or partially failed: one retry after 24 hours; if that retry +/// fails too, the full interval applies again. /// /// A throttled run leaves the record alone, so the last real baseline stays the reference. /// @@ -42,10 +51,18 @@ public static class BaselineThrottle public sealed record Decision(bool Skip, string Reason); - public static Decision Evaluate(BaselineRecord? last, DateTimeOffset now, int minIntervalHours, bool forced) + public static Decision Evaluate(BaselineRecord? last, DateTimeOffset now, int minIntervalHours, bool forced, string currentVersion) { if (forced) return new(false, $"{ForceFilePath} is present"); if (last is null) return new(false, "no baseline recorded"); + if (!string.Equals(last.ToolVersion ?? "", currentVersion, StringComparison.OrdinalIgnoreCase) && + !string.Equals(last.AttemptVersion ?? "", currentVersion, StringComparison.OrdinalIgnoreCase)) + { + var was = string.IsNullOrEmpty(last.ToolVersion) ? "an unrecorded version" : $"v{last.ToolVersion}"; + return new(false, $"BootstrapMate v{currentVersion} has not completed a baseline (last completed by {was})"); + } + if (string.Equals(last.Status, RunStatuses.Interrupted, StringComparison.OrdinalIgnoreCase)) + return new(false, "last baseline was interrupted"); if (!DateTimeOffset.TryParse(last.EndTime, out var when)) return new(false, "last baseline has no readable time"); @@ -68,15 +85,26 @@ public static Decision Evaluate(BaselineRecord? last, DateTimeOffset now, int mi return new(false, $"last baseline {last.Status} {age.TotalHours:F1}h ago (limit {wait.TotalHours:F0}h)"); } - /// The record a finished baseline leaves, counting failures in a row. - public static BaselineRecord After(BaselineRecord? previous, string status, DateTimeOffset end) => new() + /// + /// The record a baseline leaves. Failures and partial failures count in a row; an + /// interruption is not counted, since the run never got to fail. The version is the + /// one that last completed a baseline. + /// + public static BaselineRecord After(BaselineRecord? previous, string status, DateTimeOffset end, string version) { - EndTime = end.ToString("yyyy-MM-ddTHH:mm:ss.fffzzz"), - Status = status, - ConsecutiveFailures = string.Equals(status, RunStatuses.Completed, StringComparison.OrdinalIgnoreCase) - ? 0 - : (previous?.ConsecutiveFailures ?? 0) + 1 - }; + bool completed = string.Equals(status, RunStatuses.Completed, StringComparison.OrdinalIgnoreCase); + bool interrupted = string.Equals(status, RunStatuses.Interrupted, StringComparison.OrdinalIgnoreCase); + return new() + { + EndTime = end.ToString("yyyy-MM-ddTHH:mm:ss.fffzzz"), + Status = status, + ConsecutiveFailures = completed ? 0 + : interrupted ? previous?.ConsecutiveFailures ?? 0 + : (previous?.ConsecutiveFailures ?? 0) + 1, + ToolVersion = completed ? version : previous?.ToolVersion, + AttemptVersion = version + }; + } private static readonly JsonSerializerOptions WriteOptions = new() { WriteIndented = true }; diff --git a/src/BootstrapMate.Core/DataDirectoryGuard.cs b/src/BootstrapMate.Core/DataDirectoryGuard.cs new file mode 100644 index 0000000..c9d0378 --- /dev/null +++ b/src/BootstrapMate.Core/DataDirectoryGuard.cs @@ -0,0 +1,204 @@ +using System.Runtime.Versioning; +using System.Security.AccessControl; +using System.Security.Principal; + +namespace BootstrapMate.Core; + +/// +/// Keeps ProgramData\ManagedBootstrap for administrators. BootstrapMate runs as SYSTEM and +/// acts on what it finds there (the force file, cached installers, its own records), so +/// nothing in it may come from a standard user. +/// +/// +/// ProgramData's default ACL lets any user create files and folders below it, and a +/// folder created there inherits that. Before a run reads anything, this resets the +/// folder to SYSTEM and Administrators full control and Users read, not inherited, and +/// removes every entry a non-administrator owns and every reparse point. The MSI sets +/// the same ACL when it installs. +/// +[SupportedOSPlatform("windows")] +public static class DataDirectoryGuard +{ + public static readonly string DefaultRoot = @"C:\ProgramData\ManagedBootstrap"; + + private static readonly SecurityIdentifier System = new(WellKnownSidType.LocalSystemSid, null); + private static readonly SecurityIdentifier Administrators = new(WellKnownSidType.BuiltinAdministratorsSid, null); + private static readonly SecurityIdentifier Users = new(WellKnownSidType.BuiltinUsersSid, null); + private static readonly SecurityIdentifier TrustedInstaller = + new("S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464"); + + /// + /// The owner this process may assign: SYSTEM when it runs as SYSTEM; an elevated + /// administrator may only assign the Administrators group. + /// + private static SecurityIdentifier AssignableOwner() + { + using var identity = WindowsIdentity.GetCurrent(); + return identity.User == System ? System : Administrators; + } + + /// Owners whose files a SYSTEM run may trust. + public static bool IsTrustedOwner(SecurityIdentifier? owner) => + owner is not null && (owner == System || owner == Administrators || owner == TrustedInstaller); + + /// + /// Locks down and returns one line per thing it removed or could + /// not fix, for the caller to log once its log is open. Must run elevated. + /// + public static List Secure(string? root = null) + { + var target = root ?? DefaultRoot; + var notes = new List(); + + try + { + var info = new DirectoryInfo(target); + if (info.Exists && info.Attributes.HasFlag(FileAttributes.ReparsePoint)) + { + // A link in place of the folder would send every write somewhere else. + Directory.Delete(target); + notes.Add($"Removed {target}: it was a link, not a folder"); + } + // Owner SYSTEM (Administrators from an elevated session) as well: whoever owns + // the folder can rewrite its ACL. + Directory.CreateDirectory(target); + var folder = new DirectoryInfo(target); + folder.SetAccessControl(LockedSecurity(withOwner: true, notes)); + Sweep(folder, notes); + } + catch (Exception ex) + { + notes.Add($"Could not secure {target}: {ex.Message}"); + } + + return notes; + } + + /// + /// SYSTEM and Administrators full control, Users read, inherited by everything below and + /// not inheriting from ProgramData. Same as the MSI's SDDL. + /// + private static DirectorySecurity LockedSecurity(bool withOwner, List notes) + { + var security = new DirectorySecurity(); + security.SetAccessRuleProtection(isProtected: true, preserveInheritance: false); + const InheritanceFlags all = InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit; + security.AddAccessRule(new FileSystemAccessRule(System, FileSystemRights.FullControl, all, PropagationFlags.None, AccessControlType.Allow)); + security.AddAccessRule(new FileSystemAccessRule(Administrators, FileSystemRights.FullControl, all, PropagationFlags.None, AccessControlType.Allow)); + security.AddAccessRule(new FileSystemAccessRule(Users, FileSystemRights.ReadAndExecute, all, PropagationFlags.None, AccessControlType.Allow)); + if (withOwner) + { + try { security.SetOwner(AssignableOwner()); } + catch (Exception ex) { notes.Add($"Owner not changed: {ex.Message}"); } + } + return security; + } + + /// + /// Removes every entry a non-administrator owns, and every reparse point, below + /// . Links are deleted, never followed. + /// + private static void Sweep(DirectoryInfo directory, List notes) + { + IEnumerable entries; + try + { + entries = directory.EnumerateFileSystemInfos("*", new EnumerationOptions + { + AttributesToSkip = 0, + IgnoreInaccessible = false, + RecurseSubdirectories = false + }).ToList(); + } + catch (Exception ex) + { + notes.Add($"Could not list {directory.FullName}: {ex.Message}"); + return; + } + + foreach (var entry in entries) + { + try + { + bool link = entry.Attributes.HasFlag(FileAttributes.ReparsePoint); + var owner = OwnerOf(entry); + if (!link && !IsTrustedOwner(owner) && UnderLogs(entry)) + { + // Logs are only read, never acted on, and an elevated run by an Entra ID + // administrator owns what it writes under its own SID. Keep them; just + // take them back for SYSTEM. + try + { + Reclaim(entry); + notes.Add($"Took ownership of {entry.FullName} (was {owner?.Value ?? "unknown owner"})"); + if (entry is DirectoryInfo logDir) Sweep(logDir, notes); + } + catch (Exception ex) + { + // Its own ACL shuts SYSTEM out; the folder above still lets it go. + if (entry is DirectoryInfo d) Directory.Delete(d.FullName, recursive: true); + else File.Delete(entry.FullName); + notes.Add($"Removed {entry.FullName}: could not take ownership ({ex.Message})"); + } + } + else if (link || !IsTrustedOwner(owner)) + { + var why = link ? "a link" : $"created by a non-administrator ({owner?.Value ?? "unknown owner"})"; + if (entry is DirectoryInfo dir) + // A link is removed on its own; a real folder with everything in it. + Directory.Delete(dir.FullName, recursive: !link); + else + File.Delete(entry.FullName); + notes.Add($"Removed {entry.FullName}: {why}"); + } + else if (entry is DirectoryInfo dir) + { + Sweep(dir, notes); + } + } + catch (Exception ex) + { + notes.Add($"Could not check {entry.FullName}: {ex.Message}"); + } + } + } + + private static bool UnderLogs(FileSystemInfo entry) => + entry.FullName.Contains(@"\logs\", StringComparison.OrdinalIgnoreCase); + + /// Owner SYSTEM (or Administrators), explicit entries dropped, the folder's ACL inherited again. + private static void Reclaim(FileSystemInfo entry) + { + if (entry is DirectoryInfo dir) + { + var security = new DirectorySecurity(); + security.SetOwner(AssignableOwner()); + security.SetAccessRuleProtection(isProtected: false, preserveInheritance: false); + dir.SetAccessControl(security); + } + else if (entry is FileInfo file) + { + var security = new FileSecurity(); + security.SetOwner(AssignableOwner()); + security.SetAccessRuleProtection(isProtected: false, preserveInheritance: false); + file.SetAccessControl(security); + } + } + + private static SecurityIdentifier? OwnerOf(FileSystemInfo entry) + { + try + { + return entry switch + { + DirectoryInfo d => d.GetAccessControl(AccessControlSections.Owner).GetOwner(typeof(SecurityIdentifier)) as SecurityIdentifier, + FileInfo f => f.GetAccessControl(AccessControlSections.Owner).GetOwner(typeof(SecurityIdentifier)) as SecurityIdentifier, + _ => null + }; + } + catch + { + return null; + } + } +} diff --git a/tests/BootstrapMate.Core.Tests/BaselineThrottleTests.cs b/tests/BootstrapMate.Core.Tests/BaselineThrottleTests.cs index 4bfbbda..84b699e 100644 --- a/tests/BootstrapMate.Core.Tests/BaselineThrottleTests.cs +++ b/tests/BootstrapMate.Core.Tests/BaselineThrottleTests.cs @@ -7,15 +7,19 @@ public class BaselineThrottleTests { private static readonly DateTimeOffset Now = new(2026, 10, 5, 3, 0, 0, TimeSpan.FromHours(-7)); + private const string V = "2026.10.05.1200"; + private static BaselineRecord Record(string status, double hoursAgo, int failures = 0) => new() { Status = status, EndTime = Now.AddHours(-hoursAgo).ToString("yyyy-MM-ddTHH:mm:ss.fffzzz"), - ConsecutiveFailures = failures + ConsecutiveFailures = failures, + ToolVersion = V, + AttemptVersion = V }; - private static BaselineThrottle.Decision Eval(BaselineRecord? last, bool forced = false, int interval = 144) => - BaselineThrottle.Evaluate(last, Now, interval, forced); + private static BaselineThrottle.Decision Eval(BaselineRecord? last, bool forced = false, int interval = 144, string version = V) => + BaselineThrottle.Evaluate(last, Now, interval, forced, version); [Fact] public void AYoungCompletedBaselineSkips() @@ -32,7 +36,6 @@ public void AnOldCompletedBaselineRuns() => [Theory] [InlineData(RunStatuses.Failed)] [InlineData(RunStatuses.PartialFailure)] - [InlineData(RunStatuses.Interrupted)] public void AFirstFailureRetriesOnceAfter24Hours(string status) { Assert.True(Eval(Record(status, 23, failures: 1)).Skip); @@ -43,10 +46,43 @@ public void AFirstFailureRetriesOnceAfter24Hours(string status) public void OnceTheRetryIsUsedTheFullIntervalApplies() { Assert.True(Eval(Record(RunStatuses.Failed, 25, failures: 2)).Skip); - Assert.True(Eval(Record(RunStatuses.Interrupted, 143, failures: 5)).Skip); + Assert.True(Eval(Record(RunStatuses.PartialFailure, 143, failures: 5)).Skip); Assert.False(Eval(Record(RunStatuses.Failed, 145, failures: 2)).Skip); } + [Fact] + public void AnInterruptedBaselineRetriesOnTheNextTrigger() + { + var d = Eval(Record(RunStatuses.Interrupted, 0.01, failures: 3)); + Assert.False(d.Skip); + Assert.Contains("interrupted", d.Reason); + } + + [Fact] + public void ANewBootstrapMateAlwaysGetsABaseline() + { + var d = Eval(Record(RunStatuses.Completed, 1), version: "2026.10.06.0900"); + Assert.False(d.Skip); + Assert.Contains("2026.10.06.0900", d.Reason); + } + + [Fact] + public void ARecordWithoutAVersionLetsTheNextBaselineRun() + { + var last = Record(RunStatuses.Completed, 1); + last.ToolVersion = null; + last.AttemptVersion = null; + Assert.False(Eval(last).Skip); + } + + [Fact] + public void ANewBuildThatFailedItsBaselineWaitsLikeAnyOther() + { + var last = BaselineThrottle.After(Record(RunStatuses.Completed, 30), RunStatuses.Failed, Now.AddHours(-1), "2026.10.06.0900"); + Assert.Equal(V, last.ToolVersion); + Assert.True(Eval(last, version: "2026.10.06.0900").Skip); + } + [Fact] public void AFailedBaselineNeverRetriesSoonerThan24HoursEvenWithAShortInterval() => Assert.True(Eval(Record(RunStatuses.Failed, 2, failures: 1), interval: 1).Skip); @@ -81,11 +117,15 @@ public void TheDefaultIntervalIsSixDays() => [Fact] public void FailuresCountUntilABaselineCompletes() { - var first = BaselineThrottle.After(null, RunStatuses.Failed, Now); + var first = BaselineThrottle.After(null, RunStatuses.Failed, Now, V); Assert.Equal(1, first.ConsecutiveFailures); - var second = BaselineThrottle.After(first, RunStatuses.Interrupted, Now); + var interrupted = BaselineThrottle.After(first, RunStatuses.Interrupted, Now, V); + Assert.Equal(1, interrupted.ConsecutiveFailures); + var second = BaselineThrottle.After(interrupted, RunStatuses.PartialFailure, Now, V); Assert.Equal(2, second.ConsecutiveFailures); - Assert.Equal(0, BaselineThrottle.After(second, RunStatuses.Completed, Now).ConsecutiveFailures); + var done = BaselineThrottle.After(second, RunStatuses.Completed, Now, V); + Assert.Equal(0, done.ConsecutiveFailures); + Assert.Equal(V, done.ToolVersion); } [Fact] diff --git a/tests/BootstrapMate.Core.Tests/DataDirectoryGuardTests.cs b/tests/BootstrapMate.Core.Tests/DataDirectoryGuardTests.cs new file mode 100644 index 0000000..1507caa --- /dev/null +++ b/tests/BootstrapMate.Core.Tests/DataDirectoryGuardTests.cs @@ -0,0 +1,26 @@ +using System.Security.Principal; +using BootstrapMate.Core; +using Xunit; + +namespace BootstrapMate.Core.Tests; + +public class DataDirectoryGuardTests +{ + [Theory] + [InlineData("S-1-5-18")] + [InlineData("S-1-5-32-544")] + [InlineData("S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464")] + public void SystemAdministratorsAndTrustedInstallerAreTrusted(string sid) => + Assert.True(DataDirectoryGuard.IsTrustedOwner(new SecurityIdentifier(sid))); + + [Theory] + [InlineData("S-1-5-32-545")] + [InlineData("S-1-1-0")] + [InlineData("S-1-5-21-3246027979-1167926813-4013428807-1013")] + [InlineData("S-1-12-1-3542060892-1225955714-2633365921-1831687713")] + public void UsersAndPeopleAreNot(string sid) => + Assert.False(DataDirectoryGuard.IsTrustedOwner(new SecurityIdentifier(sid))); + + [Fact] + public void NoOwnerIsNotTrusted() => Assert.False(DataDirectoryGuard.IsTrustedOwner(null)); +}