Ejemplo n.º 1
0
 public static SafeNativeHandle GetTokenLinkedToken(SafeNativeHandle hToken)
 {
     using (SafeMemoryBuffer tokenInfo = GetTokenInformation(hToken,
                                                             NativeHelpers.TokenInformationClass.TokenLinkedToken))
     {
         return(new SafeNativeHandle(Marshal.ReadIntPtr(tokenInfo.DangerousGetHandle())));
     }
 }
Ejemplo n.º 2
0
 public static TokenElevationType GetTokenElevationType(SafeNativeHandle hToken)
 {
     using (SafeMemoryBuffer tokenInfo = GetTokenInformation(hToken,
                                                             NativeHelpers.TokenInformationClass.TokenElevationType))
     {
         return((TokenElevationType)Marshal.ReadInt32(tokenInfo.DangerousGetHandle()));
     }
 }
Ejemplo n.º 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());
            }
        }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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));
     }
 }