Пример #1
0
 public static SafeNativeHandle GetTokenLinkedToken(SafeNativeHandle hToken)
 {
     using (SafeMemoryBuffer tokenInfo = GetTokenInformation(hToken,
                                                             NativeHelpers.TokenInformationClass.TokenLinkedToken))
     {
         return(new SafeNativeHandle(Marshal.ReadIntPtr(tokenInfo.DangerousGetHandle())));
     }
 }
Пример #2
0
 public static TokenElevationType GetTokenElevationType(SafeNativeHandle hToken)
 {
     using (SafeMemoryBuffer tokenInfo = GetTokenInformation(hToken,
                                                             NativeHelpers.TokenInformationClass.TokenElevationType))
     {
         return((TokenElevationType)Marshal.ReadInt32(tokenInfo.DangerousGetHandle()));
     }
 }
Пример #3
0
        public static List <PrivilegeInfo> GetTokenPrivileges(SafeNativeHandle hToken)
        {
            using (SafeMemoryBuffer tokenInfo = GetTokenInformation(hToken,
                                                                    NativeHelpers.TokenInformationClass.TokenPrivileges))
            {
                NativeHelpers.TOKEN_PRIVILEGES tokenPrivs = (NativeHelpers.TOKEN_PRIVILEGES)Marshal.PtrToStructure(
                    tokenInfo.DangerousGetHandle(),
                    typeof(NativeHelpers.TOKEN_PRIVILEGES));

                NativeHelpers.LUID_AND_ATTRIBUTES[] luidAttrs =
                    new NativeHelpers.LUID_AND_ATTRIBUTES[tokenPrivs.PrivilegeCount];
                PtrToStructureArray(luidAttrs, IntPtr.Add(tokenInfo.DangerousGetHandle(),
                                                          Marshal.SizeOf(tokenPrivs.PrivilegeCount)));

                return(luidAttrs.Select(la => new PrivilegeInfo(la)).ToList());
            }
        }
Пример #4
0
 public static TokenStatistics GetTokenStatistics(SafeNativeHandle hToken)
 {
     using (SafeMemoryBuffer tokenInfo = GetTokenInformation(hToken,
                                                             NativeHelpers.TokenInformationClass.TokenStatistics))
     {
         TokenStatistics tokenStats = (TokenStatistics)Marshal.PtrToStructure(
             tokenInfo.DangerousGetHandle(),
             typeof(TokenStatistics));
         return(tokenStats);
     }
 }
Пример #5
0
 public static SecurityIdentifier GetTokenUser(SafeNativeHandle hToken)
 {
     using (SafeMemoryBuffer tokenInfo = GetTokenInformation(hToken,
                                                             NativeHelpers.TokenInformationClass.TokenUser))
     {
         NativeHelpers.TOKEN_USER tokenUser = (NativeHelpers.TOKEN_USER)Marshal.PtrToStructure(
             tokenInfo.DangerousGetHandle(),
             typeof(NativeHelpers.TOKEN_USER));
         return(new SecurityIdentifier(tokenUser.User.Sid));
     }
 }