コード例 #1
0
 public unsafe static extern BOOL AdjustTokenPrivileges(
     AccessToken TokenHandle,
     BOOL DisableAllPrivileges,
     TOKEN_PRIVILEGES *NewState,
     uint BufferLength,
     TOKEN_PRIVILEGES *PreviousState,
     out uint ReturnLength);
コード例 #2
0
        public unsafe TokenPrivilegeCollection(WindowsIdentity identity)
        {
            int bufferSize = 1024;

            byte[] buffer = new byte[bufferSize];

            using (SafeTokenHandle tokenHandle = new SafeTokenHandle(identity.Token, false))
            {
                if (!TryGetTokenPrivileges(tokenHandle, buffer, out bufferSize))
                {
                    buffer = new byte[bufferSize];

                    if (!TryGetTokenPrivileges(tokenHandle, buffer, out bufferSize))
                    {
                        throw PscxException.LastWin32Exception();
                    }
                }
            }

            fixed(void *ptr = buffer)
            {
                TOKEN_PRIVILEGES *   tp = (TOKEN_PRIVILEGES *)(ptr);
                LUID_AND_ATTRIBUTES *la = &tp->Privileges;

                int remaining = tp->PrivilegeCount;

                while (remaining-- > 0)
                {
                    Add(new TokenPrivilege(*la++));
                }
            }
        }
コード例 #3
0
        public unsafe byte[] ToTOKEN_PRIVILEGES()
        {
            if (Count == 0)
            {
                return(null);
            }

            int bufferSize =
                (Marshal.SizeOf(typeof(TOKEN_PRIVILEGES))) +
                (Marshal.SizeOf(typeof(LUID_AND_ATTRIBUTES)) * (Count - 1));

            byte[] buffer = new byte[bufferSize];

            fixed(void *ptr = buffer)
            {
                TOKEN_PRIVILEGES *   tp = (TOKEN_PRIVILEGES *)(ptr);
                LUID_AND_ATTRIBUTES *la = &tp->Privileges;

                tp->PrivilegeCount = Count;

                for (int i = 0; i < Count; i++)
                {
                    *la++ = this[i].Value;
                }
            }

            return(buffer);
        }
コード例 #4
0
 internal static unsafe extern bool AdjustTokenPrivileges(SafeCloseHandle tokenHandle, bool disableAllPrivileges, TOKEN_PRIVILEGES *newState, int bufferLength, IntPtr previousState, IntPtr returnLength);
コード例 #5
0
 public static extern int AdjustTokenPrivileges([NativeTypeName("HANDLE")] IntPtr TokenHandle, [NativeTypeName("BOOL")] int DisableAllPrivileges, [NativeTypeName("PTOKEN_PRIVILEGES")] TOKEN_PRIVILEGES *NewState, [NativeTypeName("DWORD")] uint BufferLength, [NativeTypeName("PTOKEN_PRIVILEGES")] TOKEN_PRIVILEGES *PreviousState, [NativeTypeName("PDWORD")] uint *ReturnLength);