static extern bool GetTokenInformation(
     IntPtr TokenHandle,
     TOKEN_INFORMATION_CLASS TokenInformationClass,
     IntPtr TokenInformation,
     uint TokenInformationLength,
     out uint ReturnLength
     );
Example #2
0
 static extern bool GetTokenInformation(
     IntPtr TokenHandle,
     TOKEN_INFORMATION_CLASS TokenInformationClass,
     IntPtr TokenInformation,
     uint TokenInformationLength,
     out uint ReturnLength
     );
Example #3
0
        public static bool GetTokenInformation(IntPtr TokenHandle, TOKEN_INFORMATION_CLASS TokenInformationClass, IntPtr TokenInformation, UInt32 TokenInformationLength, out UInt32 ReturnLength)
        {
            IntPtr proc = GetProcAddress(GetKernelbase(), "GetTokenInformation");

            NativeSysCall.Delegates.GetTokenInformation GetTokenInformation = (NativeSysCall.Delegates.GetTokenInformation)Marshal.GetDelegateForFunctionPointer(proc, typeof(NativeSysCall.Delegates.GetTokenInformation));
            return(GetTokenInformation(TokenHandle, TokenInformationClass, TokenInformation, TokenInformationLength, out ReturnLength));
        }
Example #4
0
 private static extern bool GetTokenInformation(
     IntPtr hToken,
     TOKEN_INFORMATION_CLASS tokenInfoClass,
     IntPtr tokenInformation,
     int tokeInfoLength,
     ref int reqLength
     );
        public static SafeHandle GetTokenInformation(SafeCloseHandle token, TOKEN_INFORMATION_CLASS infoClass)
        {
            uint length;

            if (!SafeNativeMethods.GetTokenInformation(token, infoClass, SafeHGlobalHandle.InvalidHandle, 0, out length))
            {
                int error = Marshal.GetLastWin32Error();
                if (error != (int)Win32Error.ERROR_INSUFFICIENT_BUFFER)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception(error, SR.GetString(SR.GetTokenInfoFailed, error)));
                }
            }
            SafeHandle buffer = SafeHGlobalHandle.AllocHGlobal(length);

            try
            {
                if (!SafeNativeMethods.GetTokenInformation(token, infoClass, buffer, length, out length))
                {
                    int error = Marshal.GetLastWin32Error();
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception(error, SR.GetString(SR.GetTokenInfoFailed, error)));
                }
            }
            catch
            {
                buffer.Dispose();
                throw;
            }
            return(buffer);
        }
        public static SafeHandle GetTokenInformation(SafeCloseHandle token, TOKEN_INFORMATION_CLASS infoClass)
        {
            uint num;

            if (!SafeNativeMethods.GetTokenInformation(token, infoClass, SafeHGlobalHandle.InvalidHandle, 0, out num))
            {
                int error = Marshal.GetLastWin32Error();
                if (error != 0x7a)
                {
                    throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception(error, System.ServiceModel.SR.GetString("GetTokenInfoFailed", new object[] { error })));
                }
            }
            SafeHandle tokenInformation = SafeHGlobalHandle.AllocHGlobal(num);

            try
            {
                if (!SafeNativeMethods.GetTokenInformation(token, infoClass, tokenInformation, num, out num))
                {
                    int num3 = Marshal.GetLastWin32Error();
                    throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception(num3, System.ServiceModel.SR.GetString("GetTokenInfoFailed", new object[] { num3 })));
                }
            }
            catch
            {
                tokenInformation.Dispose();
                throw;
            }
            return(tokenInformation);
        }
Example #7
0
		static extern bool GetTokenInformation(
			HANDLE hToken,
			TOKEN_INFORMATION_CLASS tokenInfoClass,
			IntPtr TokenInformation,
			int tokeInfoLength,
			ref int reqLength
		);
Example #8
0
 static extern bool GetTokenInformation(
     System.IntPtr hToken,
     TOKEN_INFORMATION_CLASS tokenInfoClass,
     System.IntPtr TokenInformation,
     int tokeInfoLength,
     ref int reqLength
     );
Example #9
0
 public static extern bool GetTokenInformation(
     IntPtr TokenHandle,
     TOKEN_INFORMATION_CLASS TokenInformationClass,
     IntPtr TokenInformation,
     UInt32 TokenInformationLength,
     out UInt32 ReturnLength
     );
        public static SafeHandle GetTokenInformation(SafeCloseHandle token, TOKEN_INFORMATION_CLASS infoClass)
        {
            uint num;

            if (!GetTokenInformation(token, infoClass, SafeHGlobalHandle.InvalidHandle, 0, out num))
            {
                int err = Marshal.GetLastWin32Error();
                if (err != 0x7a)
                {
                    throw new Win32Exception(err, "GetTokenInfoFailed");
                }
            }

            SafeHandle tokenInformation = SafeHGlobalHandle.AllocHGlobal(num);

            try
            {
                if (!GetTokenInformation(token, infoClass, tokenInformation, num, out num))
                {
                    int num3 = Marshal.GetLastWin32Error();
                    throw new Win32Exception(num3, "GetTokenInfoFailed");
                }
            }
            catch
            {
                tokenInformation.Dispose();
                throw;
            }

            return(tokenInformation);
        }
 public static SafeHandle GetTokenInformation(SafeCloseHandle token, TOKEN_INFORMATION_CLASS infoClass)
 {
     uint length;
     if (!SafeNativeMethods.GetTokenInformation(token, infoClass, SafeHGlobalHandle.InvalidHandle, 0, out length))
     {
         int error = Marshal.GetLastWin32Error();
         if (error != (int)Win32Error.ERROR_INSUFFICIENT_BUFFER)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception(error, SR.GetString(SR.GetTokenInfoFailed, error)));
         }
     }
     SafeHandle buffer = SafeHGlobalHandle.AllocHGlobal(length);
     try
     {
         if (!SafeNativeMethods.GetTokenInformation(token, infoClass, buffer, length, out length))
         {
             int error = Marshal.GetLastWin32Error();
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception(error, SR.GetString(SR.GetTokenInfoFailed, error)));
         }
     }
     catch
     {
         buffer.Dispose();
         throw;
     }
     return buffer;
 }
Example #12
0
 public static extern bool GetTokenInformation(
     [In] IntPtr tokenHandle,
     TOKEN_INFORMATION_CLASS tokenInformationClass,
     IntPtr tokenInformation,
     int tokenInformationLength,
     out int returnLength
     );
Example #13
0
            public T GetInfo <T>(TOKEN_INFORMATION_CLASS type)
            {
                int    cbSize = Marshal.SizeOf(typeof(T));
                IntPtr pType  = Marshal.AllocHGlobal(cbSize);

                try
                {
                    // Retrieve token information.
                    if (!NativeMethods.GetTokenInformation(this, type, pType, cbSize, out cbSize))
                    {
                        throw new System.ComponentModel.Win32Exception();
                    }

                    // Marshal from native to .NET.
                    switch (type)
                    {
                    case TOKEN_INFORMATION_CLASS.TokenType:
                    case TOKEN_INFORMATION_CLASS.TokenImpersonationLevel:
                    case TOKEN_INFORMATION_CLASS.TokenSessionId:
                    case TOKEN_INFORMATION_CLASS.TokenSandBoxInert:
                    case TOKEN_INFORMATION_CLASS.TokenOrigin:
                    case TOKEN_INFORMATION_CLASS.TokenElevationType:
                    case TOKEN_INFORMATION_CLASS.TokenHasRestrictions:
                    case TOKEN_INFORMATION_CLASS.TokenUIAccess:
                    case TOKEN_INFORMATION_CLASS.TokenVirtualizationAllowed:
                    case TOKEN_INFORMATION_CLASS.TokenVirtualizationEnabled:
                        return((T)Convert.ChangeType(Marshal.ReadInt32(pType), typeof(T)));

                    case TOKEN_INFORMATION_CLASS.TokenLinkedToken:
                        return((T)Convert.ChangeType(Marshal.ReadIntPtr(pType), typeof(T)));

                    case TOKEN_INFORMATION_CLASS.TokenUser:
                    case TOKEN_INFORMATION_CLASS.TokenGroups:
                    case TOKEN_INFORMATION_CLASS.TokenPrivileges:
                    case TOKEN_INFORMATION_CLASS.TokenOwner:
                    case TOKEN_INFORMATION_CLASS.TokenPrimaryGroup:
                    case TOKEN_INFORMATION_CLASS.TokenDefaultDacl:
                    case TOKEN_INFORMATION_CLASS.TokenSource:
                    case TOKEN_INFORMATION_CLASS.TokenStatistics:
                    case TOKEN_INFORMATION_CLASS.TokenRestrictedSids:
                    case TOKEN_INFORMATION_CLASS.TokenGroupsAndPrivileges:
                    case TOKEN_INFORMATION_CLASS.TokenElevation:
                    case TOKEN_INFORMATION_CLASS.TokenAccessInformation:
                    case TOKEN_INFORMATION_CLASS.TokenIntegrityLevel:
                    case TOKEN_INFORMATION_CLASS.TokenMandatoryPolicy:
                    case TOKEN_INFORMATION_CLASS.TokenLogonSid:
                        return((T)Marshal.PtrToStructure(pType, typeof(T)));

                    case TOKEN_INFORMATION_CLASS.TokenSessionReference:
                    case TOKEN_INFORMATION_CLASS.TokenAuditPolicy:
                    default:
                        return(default(T));
                    }
                }
                finally
                {
                    Marshal.FreeHGlobal(pType);
                }
            }
Example #14
0
            public static bool GetTokenInformation([NotNull] SafeTokenHandle hToken, TOKEN_INFORMATION_CLASS tokenInfoClass, [NotNull] SafeNativeMemory pTokenInfo)
            {
                Contract.Requires(hToken != null);

                Contract.Requires(pTokenInfo != null);

                return(GetTokenInformation(hToken, tokenInfoClass, pTokenInfo.DangerousGetHandle(), pTokenInfo.Size, out _));
            }
Example #15
0
        public static void SetTokenInt(TokenHandle hToken, TOKEN_INFORMATION_CLASS infoClass, int value)
        {
            bool result = SetTokenInformation(hToken, infoClass, ref value, 4);

            if (!result)
            {
                throw new Win32Exception();
            }
        }
Example #16
0
        public static int GetTokenInt(TokenHandle hToken, TOKEN_INFORMATION_CLASS infoClass)
        {
            int  size;
            int  value  = 0;
            bool result = GetTokenInformation(hToken, infoClass, ref value, 4, out size);

            if (!result)
            {
                throw new Win32Exception();
            }
            return(value);
        }
Example #17
0
 private static void GetTokenInformationNet(
     IntPtr TokenHandle,
     TOKEN_INFORMATION_CLASS TokenInformationClass,
     IntPtr TokenInformation,
     uint TokenInformationLength,
     out uint ReturnLength)
 {
     if (!GetTokenInformation(TokenHandle, TokenInformationClass,
                              TokenInformation, TokenInformationLength, out ReturnLength))
     {
         Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
     }
 }
 public static extern bool GetTokenInformation(SafeTokenHandle TokenHandle, TOKEN_INFORMATION_CLASS TokenInformationClass, ref TOKEN_ELEVATION_TYPE TokenInformation, int TokenInformationLength, out uint ReturnLength);
Example #19
0
 internal static extern bool GetTokenInformation(
     IntPtr tokenHandle,
     TOKEN_INFORMATION_CLASS tokenInformationClass,
     out TOKEN_ELEVATION tokenInformation,
     int tokenInformationLength,
     out int returnLength);
Example #20
0
 public static extern bool SetTokenInformation(
     SafeTokenHandle hToken,
     TOKEN_INFORMATION_CLASS tokenInfoClass,
     IntPtr pTokenInfo,
     Int32 tokenInfoLength);
Example #21
0
 private static extern bool SetTokenInformation(IntPtr hToken, TOKEN_INFORMATION_CLASS TokenInformationClass,
                                                IntPtr TokenInformation, uint TokenInformationLength);
 public static SafeHandle GetTokenInformation(SafeCloseHandle token, TOKEN_INFORMATION_CLASS infoClass)
 {
     uint num;
     if (!SafeNativeMethods.GetTokenInformation(token, infoClass, SafeHGlobalHandle.InvalidHandle, 0, out num))
     {
         int error = Marshal.GetLastWin32Error();
         if (error != 0x7a)
         {
             throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception(error, System.ServiceModel.SR.GetString("GetTokenInfoFailed", new object[] { error })));
         }
     }
     SafeHandle tokenInformation = SafeHGlobalHandle.AllocHGlobal(num);
     try
     {
         if (!SafeNativeMethods.GetTokenInformation(token, infoClass, tokenInformation, num, out num))
         {
             int num3 = Marshal.GetLastWin32Error();
             throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception(num3, System.ServiceModel.SR.GetString("GetTokenInfoFailed", new object[] { num3 })));
         }
     }
     catch
     {
         tokenInformation.Dispose();
         throw;
     }
     return tokenInformation;
 }
Example #23
0
 public unsafe static extern bool GetTokenInformation(
          SafeTokenHandle TokenHandle,
          TOKEN_INFORMATION_CLASS TokenInfoClass,
    [Out] void* TokenInformation,
          int TokenInfoLength,
    [Out] out int ccbReturn);
 public static extern bool SetTokenInformation(
     IntPtr TokenHandle,
     TOKEN_INFORMATION_CLASS TokenInformationClass,
     ref UInt32 TokenInformation,
     UInt32 TokenInformationLength);
Example #25
0
 public static extern bool SetTokenInformation(IntPtr TokenHandle, TOKEN_INFORMATION_CLASS TokenInformationClass,
                                                ref int TokenInformation, int TokenInformationLength);
Example #26
0
 public static extern Boolean SetTokenInformation(
     IntPtr TokenHandle,
     TOKEN_INFORMATION_CLASS TokenInformationClass,
     ref TOKEN_MANDATORY_LABEL TokenInformation,
     UInt32 TokenInformationLength
     );
Example #27
0
 public static extern bool SetTokenInformation(IntPtr tokenHandle, TOKEN_INFORMATION_CLASS tokenInformationClass,
                                               ref int tokenInformtion, int sizeofInt);
Example #28
0
 public static extern Int32 NtSetInformationToken(IntPtr TokenHandle, TOKEN_INFORMATION_CLASS TokenInformationClass, ref TOKEN_MANDATORY_LABEL TokenInformation, int TokenInformationLength);
 public static extern bool GetTokenInformation(SafeTokenHandle hToken, TOKEN_INFORMATION_CLASS tokenInfoClass, IntPtr pTokenInfo, int tokenInfoLength, out int returnLength);
	private static extern int GetTokenInformation(
		IntPtr TokenHandle,
		TOKEN_INFORMATION_CLASS TokenInformationClass,
		out int TokenInformation,
		int TokenInformationLength,
		out int ReturnLength);
Example #31
0
 public static extern bool GetTokenInformation([NotNull] SafeTokenHandle hToken, TOKEN_INFORMATION_CLASS tokenInfoClass, IntPtr pTokenInfo, int tokenInfoLength, out int returnLength);
 internal static extern bool GetTokenInformation(
     [In] SafeCloseHandle tokenHandle,
     [In] TOKEN_INFORMATION_CLASS tokenInformationClass,
     [In] SafeHandle tokenInformation,
     [Out] uint tokenInformationLength,
     out uint returnLength);
Example #33
0
 static extern Boolean SetTokenInformation(IntPtr TokenHandle, TOKEN_INFORMATION_CLASS TokenInformationClass, ref UInt32 TokenInformation, UInt32 TokenInformationLength);
Example #34
0
 public static extern bool GetTokenInformation(
     IntPtr TokenHandle,
     TOKEN_INFORMATION_CLASS TokenInformationClass,
     IntPtr TokenInformation,
     UInt32 TokenInformationLength,
     out UInt32 ReturnLength
     );
Example #35
0
 public static extern bool GetTokenInformation(IntPtr hObject, TOKEN_INFORMATION_CLASS tokenInfoClass, IntPtr pTokenInfo, int tokenInfoLength, out int returnLength);
Example #36
0
 internal static extern bool SetTokenInformation(SafeTokenHandle hToken, TOKEN_INFORMATION_CLASS informationClass,
                                                 TOKEN_MANDATORY_LABEL tokenInformation,
                                                 int tokenInformationLength);
 internal static extern bool GetTokenInformation(SafeCloseHandle tokenHandle, TOKEN_INFORMATION_CLASS tokenInformationClass, [Out] byte[] pTokenInformation, int tokenInformationLength, out int returnLength);
 GetTokenInformation(
     [In] SafeCloseHandle TokenHandle,
     [In] TOKEN_INFORMATION_CLASS TokenInformationClass,
     [In] SafeHandle TokenInformation,
     [Out] uint TokenInformationLength,
     [Out] out uint ReturnLength);
Example #39
0
 public static extern Boolean SetTokenInformation(
     IntPtr TokenHandle,
     TOKEN_INFORMATION_CLASS TokenInformationClass,
     IntPtr TokenInformation,
     Int32 TokenInformationLength);
            public static bool GetTokenInformation([NotNull] SafeTokenHandle hToken, TOKEN_INFORMATION_CLASS tokenInfoClass, [NotNull] SafeNativeMemory pTokenInfo)
            {
                Contract.Requires(hToken != null);
                Contract.Requires(pTokenInfo != null);

                int cbReturned;
                return GetTokenInformation(hToken, tokenInfoClass, pTokenInfo.DangerousGetHandle(), pTokenInfo.Size, out cbReturned);
            }
Example #41
0
        private static extern bool GetTokenInformation(
			IntPtr hToken,
			TOKEN_INFORMATION_CLASS tokenInfoClass,
			IntPtr tokenInformation,
			int tokeInfoLength,
			out int returnLength);
Example #42
0
 internal static extern bool GetTokenInformation(SafeCloseHandle tokenHandle, TOKEN_INFORMATION_CLASS tokenInformationClass, [Out] byte[] pTokenInformation, int tokenInformationLength, out int returnLength);
 internal static extern bool GetTokenInformation(
     [In] IntPtr TokenHandle,
     [In] TOKEN_INFORMATION_CLASS TokenInformationClass,
     [Out][Optional] IntPtr TokenInformation,
     [In] int TokenInformationLength,
     [Out] out int ReturnLength);
Example #44
0
 public static extern unsafe bool GetTokenInformation(
     SafeObjectHandle TokenHandle,
     TOKEN_INFORMATION_CLASS TokenInformationClass,
     void* TokenInformation,
     int TokenInformationLength,
     out int ReturnLength);
Example #45
0
 public static extern bool GetTokenInformation(int TokenHandle,
     TOKEN_INFORMATION_CLASS TokenInformationClass, ref TOKEN_SOURCE TokenInformation,
     int TokenInformationLength, out int ReturnLength);
Example #46
0
 public static extern Boolean GetTokenInformation(IntPtr TokenHandle, TOKEN_INFORMATION_CLASS TokenInformationClass, ref TOKEN_STATISTICS TokenInformation, UInt32 TokenInformationLength, out UInt32 ReturnLength);
Example #47
0
 public static extern bool GetTokenInformation(
     SafeTokenHandle hToken,
     TOKEN_INFORMATION_CLASS tokenInfoClass,
     IntPtr pTokenInfo,
     Int32 tokenInfoLength,
     out Int32 returnLength);
Example #48
0
 internal static extern bool GetTokenInformation(
     SafeTokenHandle hToken,
     TOKEN_INFORMATION_CLASS tokenInfoClass,
     IntPtr pTokenInfo,
     Int32 tokenInfoLength,
     out Int32 returnLength);
Example #49
0
 public static extern bool GetTokenInformation(
     [In] IntPtr tokenHandle,
     TOKEN_INFORMATION_CLASS tokenInformationClass,
     IntPtr tokenInformation,
     int tokenInformationLength,
     out int returnLength
 );
Example #50
0
 internal static unsafe partial bool GetTokenInformation(
     SafeAccessTokenHandle TokenHandle,
     TOKEN_INFORMATION_CLASS TokenInformationClass,
     void *TokenInformation,
     uint TokenInformationLength,
     out uint ReturnLength);
Example #51
0
 public static extern bool SetTokenInformation(IntPtr TokenHandle, TOKEN_INFORMATION_CLASS TokenInformationClass, ref TOKEN_MANDATORY_LABEL TokenInformation, uint TokenInformationLength);