Ejemplo n.º 1
0
        public bool TokenMembershipCheck(string sid)
        {
            bool   result = false;
            IntPtr zero   = IntPtr.Zero;

            try
            {
                if (!NativeMethodProvider.ConvertStringSidToSid(sid, out zero))
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error());
                }
                if (!NativeMethodProvider.CheckTokenMembership(IntPtr.Zero, zero, ref result))
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error());
                }
            }
            catch (Exception e)
            {
                SetupLogger.LogError(e);
            }
            finally
            {
                if (zero != IntPtr.Zero)
                {
                    NativeMethodProvider.LocalFree(zero);
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        public uint GetAccessCheck(byte[] ntsd, string listString)
        {
            uint desiredAccess = 33554432U;

            NativeMethodProvider.GENERIC_MAPPING    genericMapping = NativeMethodProvider.GenericMapping(string.Empty);
            NativeMethodProvider.OBJECT_TYPE_LIST[] list           = NativeMethodProvider.ObjectTypeList(string.Empty);
            return(this.AccessCheck(desiredAccess, ntsd, genericMapping, list));
        }
Ejemplo n.º 3
0
        public bool IsCoreServer()
        {
            int  num;
            bool flag = NativeMethodProvider.GetProductInfo(Environment.OSVersion.Version.Major, Environment.OSVersion.Version.Minor, 0, 0, out num);

            ExTraceGlobals.FaultInjectionTracer.TraceTest <int>(2332437821U, ref num);
            if (flag)
            {
                flag = ((long)num == 12L || (long)num == 39L || (long)num == 13L || (long)num == 40L || (long)num == 14L || (long)num == 41L);
            }
            return(flag);
        }
Ejemplo n.º 4
0
        private uint AccessCheck(uint desiredAccess, byte[] ntsd, NativeMethodProvider.GENERIC_MAPPING genericMapping, NativeMethodProvider.OBJECT_TYPE_LIST[] list)
        {
            uint   result  = 0U;
            int    num     = 0;
            IntPtr intPtr  = IntPtr.Zero;
            IntPtr intPtr2 = IntPtr.Zero;
            IntPtr intPtr3 = IntPtr.Zero;
            bool   flag    = false;

            try
            {
                intPtr2 = Marshal.AllocHGlobal(1024);
                int num2 = 1024;
                NativeMethodProvider.MapGenericMask(ref desiredAccess, ref genericMapping);
                if (!NativeMethodProvider.ImpersonateSelf(2))
                {
                    int lastWin32Error = Marshal.GetLastWin32Error();
                    throw new Win32Exception(lastWin32Error);
                }
                flag    = true;
                intPtr  = this.GetTokenHandle();
                intPtr3 = NativeMethodProvider.OBJECT_TYPE_LIST.NativeStruct(list);
                if (!NativeMethodProvider.AccessCheckByType(ntsd, IntPtr.Zero, intPtr, desiredAccess, intPtr3, list.Length, ref genericMapping, intPtr2, ref num2, ref result, ref num))
                {
                    int lastWin32Error = Marshal.GetLastWin32Error();
                    SetupLogger.LogError(new Win32Exception(lastWin32Error));
                }
            }
            finally
            {
                if (intPtr3 != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(intPtr3);
                }
                if (intPtr != IntPtr.Zero)
                {
                    NativeMethodProvider.CloseHandle(intPtr);
                }
                if (intPtr2 != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(intPtr2);
                }
                if (flag)
                {
                    NativeMethodProvider.RevertToSelf();
                }
            }
            return(result);
        }
Ejemplo n.º 5
0
        public string GetSiteName(string server)
        {
            IntPtr zero   = IntPtr.Zero;
            int    num    = NativeMethodProvider.DsGetSiteName(server, ref zero);
            string result = string.Empty;

            if (num == 0 && zero != IntPtr.Zero)
            {
                result = Marshal.PtrToStringUni(zero);
            }
            if (zero != IntPtr.Zero)
            {
                NativeMethodProvider.NetApiBufferFree(zero);
            }
            return(result);
        }
Ejemplo n.º 6
0
        private IntPtr GetTokenHandle()
        {
            IntPtr zero  = IntPtr.Zero;
            IntPtr zero2 = IntPtr.Zero;
            int    num   = 0;

            if (!NativeMethodProvider.OpenThreadToken(NativeMethodProvider.GetCurrentThread(), 8U, true, ref zero))
            {
                num = Marshal.GetLastWin32Error();
                if (num == 1008)
                {
                    num = 0;
                    if (!NativeMethodProvider.OpenProcessToken(NativeMethodProvider.GetCurrentProcess(), 8U, ref zero))
                    {
                        num = Marshal.GetLastWin32Error();
                    }
                }
            }
            if (num != 0)
            {
                throw new Win32Exception(num);
            }
            return(zero);
        }
Ejemplo n.º 7
0
 public uint GetAccessCheck(string ntsdString, string listString)
 {
     byte[] ntsd = NativeMethodProvider.ExtFormatByteArrayFromString(ntsdString);
     return(this.GetAccessCheck(ntsd, listString));
 }