From a4212024ce67deb1bbc0f94bc5cf37f1998500d6 Mon Sep 17 00:00:00 2001 From: David Hall Date: Fri, 9 Aug 2019 16:37:09 -0600 Subject: [PATCH] Updates for use of PSID --- Security/AccessControl/SystemSecurity.cs | 10 +++++----- UnitTests/PInvoke/Security/AdvApi32/PSIDTests.cs | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Security/AccessControl/SystemSecurity.cs b/Security/AccessControl/SystemSecurity.cs index 58b816ff..ccd347a3 100644 --- a/Security/AccessControl/SystemSecurity.cs +++ b/Security/AccessControl/SystemSecurity.cs @@ -191,7 +191,7 @@ namespace Vanara.Security.AccessControl var ts = sids.DangerousGetHandle().ToIEnum(names.Length).ToArray(); var retVal = new SystemAccountInfo[names.Length]; for (var i = 0; i < names.Length; i++) - retVal[i] = new SystemAccountInfo(names[i], ts[i].Use, IsValidSid(ts[i].Use) ? new SecurityIdentifier(ts[i].Sid) : null, ts[i].DomainIndex, d); + retVal[i] = new SystemAccountInfo(names[i], ts[i].Use, IsValidSid(ts[i].Use) ? new SecurityIdentifier((IntPtr)ts[i].Sid) : null, ts[i].DomainIndex, d); return retVal; } @@ -208,7 +208,7 @@ namespace Vanara.Security.AccessControl var opts = (preferInternetNames ? LsaLookupSidsFlags.LSA_LOOKUP_PREFER_INTERNET_NAMES : 0) | (disallowConnectedAccts ? LsaLookupSidsFlags.LSA_LOOKUP_DISALLOW_CONNECTED_ACCOUNT_INTERNET_SID : 0); var psids = sids.Select(s => new PinnedSid(s)); - var ret = LsaLookupSids2(Handle, opts, (uint)sids.Length, psids.Select(s => (IntPtr)s).ToArray(), out var domains, out var names); + var ret = LsaLookupSids2(Handle, opts, (uint)sids.Length, psids.Select(s => s.PSID).ToArray(), out var domains, out var names); if (ret != NTStatus.STATUS_SUCCESS && ret != NTStatus.STATUS_SOME_NOT_MAPPED) ThrowIfLsaError(ret); var d = domains.DangerousGetHandle().ToStructure().DomainList.ToArray(); @@ -239,14 +239,14 @@ namespace Vanara.Security.AccessControl private static string FromPriv(SystemPrivilege priv) => SystemPrivilegeTypeConverter.PrivLookup[priv]; - private static void ThrowIfLsaError(uint lsaRetVal) + private static void ThrowIfLsaError(NTStatus lsaRetVal) { LsaNtStatusToWinError(lsaRetVal).ThrowIfFailed(); } private void AddRights(string accountName, params string[] privilegeNames) { - ThrowIfLsaError(LsaAddAccountRights(Handle, GetSid(accountName), privilegeNames, privilegeNames.Length)); + ThrowIfLsaError(LsaAddAccountRights(Handle, GetSid(accountName), privilegeNames, (uint)privilegeNames.Length)); } private SafeLSA_HANDLE GetAccount(string accountName, LsaAccountAccessMask mask = LsaAccountAccessMask.ACCOUNT_VIEW) @@ -299,7 +299,7 @@ namespace Vanara.Security.AccessControl private void RemoveRights(string accountName, params string[] privilegeNames) { - ThrowIfLsaError(LsaRemoveAccountRights(Handle, GetSid(accountName), false, privilegeNames, privilegeNames.Length)); + ThrowIfLsaError(LsaRemoveAccountRights(Handle, GetSid(accountName), false, privilegeNames, (uint)privilegeNames.Length)); } private static void SetSystemAccess(SafeLSA_HANDLE hAcct, AccountLogonRights rights) diff --git a/UnitTests/PInvoke/Security/AdvApi32/PSIDTests.cs b/UnitTests/PInvoke/Security/AdvApi32/PSIDTests.cs index 0796c91f..fb1c738f 100644 --- a/UnitTests/PInvoke/Security/AdvApi32/PSIDTests.cs +++ b/UnitTests/PInvoke/Security/AdvApi32/PSIDTests.cs @@ -29,10 +29,10 @@ namespace Vanara.PInvoke.Tests var sid4 = new SafePSID(100); Assert.That(!sid4.IsClosed); Assert.That(!sid4.IsValidSid); - Assert.That(sid4.Size, Is.EqualTo(100)); + Assert.That((int)sid4.Size, Is.EqualTo(100)); sid4.Dispose(); Assert.That(sid4.IsClosed); - Assert.That(sid4.Size, Is.EqualTo(0)); + Assert.That((int)sid4.Size, Is.EqualTo(0)); Assert.That(sid.Equals("X"), Is.False); Assert.That(sid.Equals(sid3), Is.False);