microsoft / dotnet

This repo is the official home of .NET on GitHub. It's a great starting point to find many .NET OSS projects from Microsoft and the community, including many that are part of the .NET Foundation.
https://devblogs.microsoft.com/dotnet/
MIT License
14.25k stars 2.2k forks source link

ArgumentException for initializing SecurityIdentifier for WellKnownSidType.LogonIdsSid or WellKnownSidType.WinLocalLogonSid in .Net6 #1419

Open iyrwis opened 7 months ago

iyrwis commented 7 months ago

Here is my reproduce code on .Net6, any suggestions?

using System; using System.Security.Principal;

namespace ConsoleApp45 { class Program { static void Main(string[] args) { Console.WriteLine("New param");

        var param = new SecurityIdentifier("S-1-5-21-198055498-3910363945-93989812");
        SecurityIdentifier sid;

        Console.WriteLine("New sid");

        foreach (WellKnownSidType type in Enum.GetValues(typeof(WellKnownSidType)))
        {
            if (type == WellKnownSidType.LogonIdsSid || type == WellKnownSidType.WinLocalLogonSid)
            {
                // these types can't be created, skip
                continue;
            }

            try
            {
                sid = new SecurityIdentifier(type, param);
                Console.WriteLine(type.ToString());
            }
            catch (ArgumentException)
            {
                Console.WriteLine($"The error type is: {type}");
            }
        }
    }
}

}