コード例 #1
0
        internal static SafeLsaPolicyHandle LsaOpenPolicy(string systemName, PolicyRights rights)
        {
            Win32Native.LSA_OBJECT_ATTRIBUTES lsa_OBJECT_ATTRIBUTES;
            lsa_OBJECT_ATTRIBUTES.Length                   = Marshal.SizeOf(typeof(Win32Native.LSA_OBJECT_ATTRIBUTES));
            lsa_OBJECT_ATTRIBUTES.RootDirectory            = IntPtr.Zero;
            lsa_OBJECT_ATTRIBUTES.ObjectName               = IntPtr.Zero;
            lsa_OBJECT_ATTRIBUTES.Attributes               = 0;
            lsa_OBJECT_ATTRIBUTES.SecurityDescriptor       = IntPtr.Zero;
            lsa_OBJECT_ATTRIBUTES.SecurityQualityOfService = IntPtr.Zero;
            SafeLsaPolicyHandle result;
            uint num;

            if ((num = Win32Native.LsaOpenPolicy(systemName, ref lsa_OBJECT_ATTRIBUTES, (int)rights, out result)) == 0U)
            {
                return(result);
            }
            if (num == 3221225506U)
            {
                throw new UnauthorizedAccessException();
            }
            if (num == 3221225626U || num == 3221225495U)
            {
                throw new OutOfMemoryException();
            }
            int errorCode = Win32Native.LsaNtStatusToWinError((int)num);

            throw new SystemException(Win32Native.GetMessage(errorCode));
        }
コード例 #2
0
ファイル: Win32.cs プロジェクト: er0dr1guez/corefx
        //
        // Wrapper around advapi32.LsaOpenPolicy
        //


        internal static SafeLsaPolicyHandle LsaOpenPolicy(
            string systemName,
            PolicyRights rights)
        {
            uint ReturnCode;
            SafeLsaPolicyHandle Result;
            Interop.LSA_OBJECT_ATTRIBUTES Loa;

            Loa.Length = Marshal.SizeOf<Interop.LSA_OBJECT_ATTRIBUTES>();
            Loa.RootDirectory = IntPtr.Zero;
            Loa.ObjectName = IntPtr.Zero;
            Loa.Attributes = 0;
            Loa.SecurityDescriptor = IntPtr.Zero;
            Loa.SecurityQualityOfService = IntPtr.Zero;

            if (0 == (ReturnCode = Interop.mincore.LsaOpenPolicy(systemName, ref Loa, (int)rights, out Result)))
            {
                return Result;
            }
            else if (ReturnCode == Interop.StatusOptions.STATUS_ACCESS_DENIED)
            {
                throw new UnauthorizedAccessException();
            }
            else if (ReturnCode == Interop.StatusOptions.STATUS_INSUFFICIENT_RESOURCES ||
                      ReturnCode == Interop.StatusOptions.STATUS_NO_MEMORY)
            {
                throw new OutOfMemoryException();
            }
            else
            {
                int win32ErrorCode = Interop.mincore.RtlNtStatusToDosError(unchecked((int)ReturnCode));

                throw new Win32Exception(win32ErrorCode);
            }
        }
コード例 #3
0
        //
        // Wrapper around advapi32.LsaOpenPolicy
        //


        internal static SafeLsaPolicyHandle LsaOpenPolicy(
            string?systemName,
            PolicyRights rights)
        {
            Interop.OBJECT_ATTRIBUTES attributes = default;
            uint error = Interop.Advapi32.LsaOpenPolicy(systemName, ref attributes, (int)rights, out SafeLsaPolicyHandle policyHandle);

            if (error == 0)
            {
                return(policyHandle);
            }
            else if (error == Interop.StatusOptions.STATUS_ACCESS_DENIED)
            {
                throw new UnauthorizedAccessException();
            }
            else if (error == Interop.StatusOptions.STATUS_INSUFFICIENT_RESOURCES ||
                     error == Interop.StatusOptions.STATUS_NO_MEMORY)
            {
                throw new OutOfMemoryException();
            }
            else
            {
                uint win32ErrorCode = Interop.Advapi32.LsaNtStatusToWinError(error);

                throw new Win32Exception(unchecked ((int)win32ErrorCode));
            }
        }
コード例 #4
0
        internal static SafeLsaPolicyHandle LsaOpenPolicy(string systemName, PolicyRights rights)
        {
            Win32Native.LSA_OBJECT_ATTRIBUTES attributes;
            attributes.Length                   = Marshal.SizeOf(typeof(Win32Native.LSA_OBJECT_ATTRIBUTES));
            attributes.RootDirectory            = IntPtr.Zero;
            attributes.ObjectName               = IntPtr.Zero;
            attributes.Attributes               = 0;
            attributes.SecurityDescriptor       = IntPtr.Zero;
            attributes.SecurityQualityOfService = IntPtr.Zero;
            SafeLsaPolicyHandle handle;
            uint num;

            if ((int)(num = Win32Native.LsaOpenPolicy(systemName, ref attributes, (int)rights, out handle)) == 0)
            {
                return(handle);
            }
            if ((int)num == -1073741790)
            {
                throw new UnauthorizedAccessException();
            }
            if ((int)num == -1073741670 || (int)num == -1073741801)
            {
                throw new OutOfMemoryException();
            }
            throw new SystemException(Win32Native.GetMessage(Win32Native.LsaNtStatusToWinError((int)num)));
        }
コード例 #5
0
        internal static SafeLsaPolicyHandle LsaOpenPolicy(string systemName, PolicyRights rights)
        {
            SafeLsaPolicyHandle handle;

            Win32Native.LSA_OBJECT_ATTRIBUTES lsa_object_attributes;
            lsa_object_attributes.Length                   = Marshal.SizeOf(typeof(Win32Native.LSA_OBJECT_ATTRIBUTES));
            lsa_object_attributes.RootDirectory            = IntPtr.Zero;
            lsa_object_attributes.ObjectName               = IntPtr.Zero;
            lsa_object_attributes.Attributes               = 0;
            lsa_object_attributes.SecurityDescriptor       = IntPtr.Zero;
            lsa_object_attributes.SecurityQualityOfService = IntPtr.Zero;
            uint num = Win32Native.LsaOpenPolicy(systemName, ref lsa_object_attributes, (int)rights, out handle);

            if (num == 0)
            {
                return(handle);
            }
            if (num == 0xc0000022)
            {
                throw new UnauthorizedAccessException();
            }
            if ((num != 0xc000009a) && (num != 0xc0000017))
            {
                throw new SystemException(Win32Native.GetMessage(Win32Native.LsaNtStatusToWinError((int)num)));
            }
            throw new OutOfMemoryException();
        }
コード例 #6
0
ファイル: Win32.cs プロジェクト: nsivov/mono
        //
        // Wrapper around advapi32.LsaOpenPolicy
        //


        internal static SafeLsaPolicyHandle LsaOpenPolicy(
            string systemName,
            PolicyRights rights)
        {
            uint ReturnCode;
            SafeLsaPolicyHandle Result;

            Interop.LSA_OBJECT_ATTRIBUTES Loa;

            Loa.Length                   = Marshal.SizeOf <Interop.LSA_OBJECT_ATTRIBUTES>();
            Loa.RootDirectory            = IntPtr.Zero;
            Loa.ObjectName               = IntPtr.Zero;
            Loa.Attributes               = 0;
            Loa.SecurityDescriptor       = IntPtr.Zero;
            Loa.SecurityQualityOfService = IntPtr.Zero;

            if (0 == (ReturnCode = Interop.Advapi32.LsaOpenPolicy(systemName, ref Loa, (int)rights, out Result)))
            {
                return(Result);
            }
            else if (ReturnCode == Interop.StatusOptions.STATUS_ACCESS_DENIED)
            {
                throw new UnauthorizedAccessException();
            }
            else if (ReturnCode == Interop.StatusOptions.STATUS_INSUFFICIENT_RESOURCES ||
                     ReturnCode == Interop.StatusOptions.STATUS_NO_MEMORY)
            {
                throw new OutOfMemoryException();
            }
            else
            {
                throw new SecurityException(string.Format(CultureInfo.InvariantCulture, "LsaOpenPolicy returned status {0}", ReturnCode));
            }
        }
コード例 #7
0
        //
        // Wrapper around advapi32.LsaOpenPolicy
        //


        internal static SafeLsaPolicyHandle LsaOpenPolicy(
            string systemName,
            PolicyRights rights)
        {
            uint ReturnCode;
            SafeLsaPolicyHandle Result;

            Interop.LSA_OBJECT_ATTRIBUTES Loa;

            Loa.Length                   = Marshal.SizeOf <Interop.LSA_OBJECT_ATTRIBUTES>();
            Loa.RootDirectory            = IntPtr.Zero;
            Loa.ObjectName               = IntPtr.Zero;
            Loa.Attributes               = 0;
            Loa.SecurityDescriptor       = IntPtr.Zero;
            Loa.SecurityQualityOfService = IntPtr.Zero;

            if (0 == (ReturnCode = Interop.mincore.LsaOpenPolicy(systemName, ref Loa, (int)rights, out Result)))
            {
                return(Result);
            }
            else if (ReturnCode == Interop.StatusOptions.STATUS_ACCESS_DENIED)
            {
                throw new UnauthorizedAccessException();
            }
            else if (ReturnCode == Interop.StatusOptions.STATUS_INSUFFICIENT_RESOURCES ||
                     ReturnCode == Interop.StatusOptions.STATUS_NO_MEMORY)
            {
                throw new OutOfMemoryException();
            }
            else
            {
                int win32ErrorCode = Interop.mincore.RtlNtStatusToDosError(unchecked ((int)ReturnCode));

                throw new Exception(Interop.mincore.GetMessage(win32ErrorCode));
            }
        }
コード例 #8
0
 internal static SafeLsaPolicyHandle LsaOpenPolicy(string systemName, PolicyRights rights)
 {
     SafeLsaPolicyHandle handle;
     Win32Native.LSA_OBJECT_ATTRIBUTES lsa_object_attributes;
     lsa_object_attributes.Length = Marshal.SizeOf(typeof(Win32Native.LSA_OBJECT_ATTRIBUTES));
     lsa_object_attributes.RootDirectory = IntPtr.Zero;
     lsa_object_attributes.ObjectName = IntPtr.Zero;
     lsa_object_attributes.Attributes = 0;
     lsa_object_attributes.SecurityDescriptor = IntPtr.Zero;
     lsa_object_attributes.SecurityQualityOfService = IntPtr.Zero;
     uint num = Win32Native.LsaOpenPolicy(systemName, ref lsa_object_attributes, (int) rights, out handle);
     if (num == 0)
     {
         return handle;
     }
     if (num == 0xc0000022)
     {
         throw new UnauthorizedAccessException();
     }
     if ((num != 0xc000009a) && (num != 0xc0000017))
     {
         throw new SystemException(Win32Native.GetMessage(Win32Native.LsaNtStatusToWinError((int) num)));
     }
     throw new OutOfMemoryException();
 }