Пример #1
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static int CreateWellKnownSid(
            WellKnownSidType sidType,
            SecurityIdentifier domainSid,
            out byte[] resultSid
            )
        {
            //
            // Check if the api is supported
            //
            if (!WellKnownSidApisSupported)
            {
                throw new PlatformNotSupportedException(Environment.GetResourceString("PlatformNotSupported_RequiresW2kSP3"));
            }

            //
            // Passing an array as big as it can ever be is a small price to pay for
            // not having to P/Invoke twice (once to get the buffer, once to get the data)
            //

            uint length = ( uint )SecurityIdentifier.MaxBinaryLength;

            resultSid = new byte[length];

            if (FALSE != Win32Native.CreateWellKnownSid(( int )sidType, domainSid == null ? null : domainSid.BinaryForm, resultSid, ref length))
            {
                return(Win32Native.ERROR_SUCCESS);
            }
            else
            {
                resultSid = null;

                return(Marshal.GetLastWin32Error());
            }
        }
Пример #2
0
        internal static int CreateWellKnownSid(WellKnownSidType sidType, SecurityIdentifier domainSid, out byte[] resultSid)
        {
            if (!Win32.WellKnownSidApisSupported)
            {
                throw new PlatformNotSupportedException(Environment.GetResourceString("PlatformNotSupported_RequiresW2kSP3"));
            }
            uint maxBinaryLength = (uint)SecurityIdentifier.MaxBinaryLength;

            resultSid = new byte[maxBinaryLength];
            if (Win32Native.CreateWellKnownSid((int)sidType, (domainSid == null) ? null : domainSid.BinaryForm, resultSid, ref maxBinaryLength) != 0)
            {
                return(0);
            }
            resultSid = null;
            return(Marshal.GetLastWin32Error());
        }