public static extern bool DuplicateTokenEx( SafeTokenHandle hExistingToken, UInt32 desiredAccess, IntPtr pTokenAttributes, SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, TOKEN_TYPE TokenType, out SafeTokenHandle hNewToken);
public static extern bool DuplicateTokenEx( IntPtr hExistingToken, TokenAccessFlags dwDesiredAccess, IntPtr lpThreadAttributes, SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, TOKEN_TYPE TokenType, out IntPtr phNewToken);
private static extern bool DuplicateTokenEx( IntPtr existingToken, uint desiredAccess, IntPtr tokenAttributes, SECURITY_IMPERSONATION_LEVEL impersonationLevel, int tokenType, out IntPtr newToken);
internal static partial bool DuplicateTokenEx( SafeTokenHandle ExistingTokenHandle, TokenAccessLevels DesiredAccess, IntPtr TokenAttributes, SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, System.Security.Principal.TokenType TokenType, ref SafeTokenHandle?DuplicateTokenHandle);
public extern static bool DuplicateTokenEx( IntPtr hExistingToken, uint dwDesiredAccess, ref SECURITY_ATTRIBUTES lpTokenAttributes, SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, TOKEN_TYPE TokenType, out IntPtr phNewToken);
internal static extern bool DuplicateTokenEx( SafeCloseHandle hExistingToken, TokenAccessLevels dwDesiredAccess, IntPtr lpTokenAttributes, SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, TOKEN_TYPE TokenType, ref SafeCloseHandle phNewToken);
/* ----------------------------------------------------------------- */ /// /// GetPrimaryToken /// /// <summary> /// プライマリトークンを取得します。 /// </summary> /// /* ----------------------------------------------------------------- */ private static IntPtr GetPrimaryToken(IntPtr token, SECURITY_IMPERSONATION_LEVEL level) { var dest = IntPtr.Zero; var attr = new SECURITY_ATTRIBUTES(); attr.nLength = (uint)Marshal.SizeOf(attr); var result = AdvApi32.NativeMethods.DuplicateTokenEx( token, 0x0001 | // TOKEN_ASSIGN_PRIMARY 0x0002 | // TOKEN_DUPLICATE 0x0004 | // TOKEN_IMPERSONATE 0x0008, // TOKEN_QUERY ref attr, (int)level, (int)TOKEN_TYPE.TokenPrimary, ref dest ); AdvApi32.NativeMethods.RevertToSelf(); if (!result) { throw new Win32Exception(); } return(dest); }
private extern static bool DuplicateTokenEx( IntPtr hExistingToken, uint dwDesiredAccess, /*ref*/ IntPtr lpTokenAttributes, // since we only call this with null we omit ref and type for laziness SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, TOKEN_TYPE TokenType, out IntPtr phNewToken);
public static AccessTokenHandle Duplicate(AccessTokenHandle originalToken, SECURITY_IMPERSONATION_LEVEL impersonationLevel, TOKEN_TYPE tokenType, params TokenAccess[] desiredAccess) { var defaultAccess = TokenAccess.TOKEN_ALL_ACCESS; uint combinedAccess = (uint)defaultAccess; if (desiredAccess.Length > 0) { combinedAccess = (uint)(new List <TokenAccess>(desiredAccess).Aggregate((x, y) => x | y)); } SECURITY_ATTRIBUTES secAttr = new SECURITY_ATTRIBUTES(); IntPtr newToken; Logger.GetInstance().Debug($"Attempting to duplicate token."); if (!Advapi32.DuplicateTokenEx(originalToken.GetHandle(), combinedAccess, ref secAttr, impersonationLevel, tokenType, out newToken)) { Logger.GetInstance().Error($"Failed to duplicate token. DuplicateTokenEx failed with error code: {Kernel32.GetLastError()}"); throw new DuplicateTokenException(); } Logger.GetInstance().Debug($"Successfully duplicated token."); if (desiredAccess.Length > 0) { return(new AccessTokenHandle(newToken, desiredAccess)); } else { return(new AccessTokenHandle(newToken, defaultAccess)); } }
extern static bool DuplicateTokenEx( IntPtr hExistingToken, uint dwDesiredAccess, ref SECURITY_ATTRIBUTES lpTokenAttributes, SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, TOKEN_TYPE TokenType, out IntPtr phNewToken);
public static extern BOOL DuplicateTokenEx( AccessToken hExistingToken, AccessTokenRights dwDesiredAccess, IntPtr lpTokenAttributes, SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, TOKEN_TYPE TokenType, ref AccessToken phNewToken);
internal static extern bool DuplicateTokenEx( [In] SafeCloseHandle existingTokenHandle, [In] TokenAccessLevels desiredAccess, [In] IntPtr tokenAttributes, [In] SECURITY_IMPERSONATION_LEVEL impersonationLevel, [In] TokenType tokenType, [Out] out SafeCloseHandle duplicateTokenHandle );
public static TokenHandle DuplicateTokenEx(TokenHandle hExistingToken, TokenAccess desiredAccess, SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, TOKEN_TYPE TokenType) { TokenHandle ret; bool result = DuplicateTokenEx(hExistingToken, (uint)desiredAccess, IntPtr.Zero, ImpersonationLevel, TokenType, out ret); if (!result) { throw new Win32Exception(); } return(ret); }
public static SECURITY_QUALITY_OF_SERVICE Create(SECURITY_IMPERSONATION_LEVEL SecurityImpersonation, bool EffectiveOnly, bool DynamicTracking) { var SecurityQos = new SECURITY_QUALITY_OF_SERVICE(); unsafe { SecurityQos.Length = (uint)sizeof(SECURITY_QUALITY_OF_SERVICE);//12 in 64 bits } SecurityQos.ImpersonationLevel = SecurityImpersonation; SecurityQos.EffectiveOnly = EffectiveOnly; SecurityQos.ContextTrackingMode = DynamicTracking; return(SecurityQos); }
private static IntPtr duplicateTokenEx( IntPtr hExistingToken, uint dwDesiredAccess, ref SECURITY_ATTRIBUTES lpTokenAttributes, SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, TOKEN_TYPE TokenType) { IntPtr phNewToken; bool ret = DuplicateTokenEx(hExistingToken, dwDesiredAccess, ref lpTokenAttributes, ImpersonationLevel, TokenType, out phNewToken); if (!ret) { throw new Win32Exception(Marshal.GetLastWin32Error()); } return(phNewToken); }
public static extern bool DuplicateTokenEx(IntPtr existingToken, uint desiredAccess, IntPtr tokenAttributes, SECURITY_IMPERSONATION_LEVEL impersonationLevel, TOKEN_TYPE tokenType, out IntPtr newToken);
internal static extern bool DuplicateTokenEx([In] SafeTokenHandle ExistingTokenHandle, [In] AccessTypes DesiredAccess, [In] IntPtr TokenAttributes, [In] SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, [In] TokenType TokenType, [In, Out] ref SafeTokenHandle DuplicateTokenHandle);
internal static extern bool DuplicateTokenEx(SafeTokenHandle ExistingTokenHandle, TokenAccessLevels DesiredAccess, IntPtr TokenAttributes, SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, TokenType TokenType, ref SafeTokenHandle DuplicateTokenHandle);
private static extern bool DuplicateTokenEx(IntPtr ExistingTokenHandle, uint dwDesiredAccess, ref SECURITY_ATTRIBUTES lpThreadAttributes, SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, int TokenType, ref IntPtr DuplicateTokenHandle);
public static unsafe extern bool DuplicateTokenEx( SafeObjectHandle hExistingToken, ACCESS_MASK dwDesiredAccess, [Friendly(FriendlyFlags.In | FriendlyFlags.Optional)] SECURITY_ATTRIBUTES* lpTokenAttributes, SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, TOKEN_TYPE TokenType, out SafeObjectHandle phNewToken);
static extern bool ImpersonateSelf(SECURITY_IMPERSONATION_LEVEL ImpersonationLevel);
public static extern bool DuplicateTokenEx(int ExistingToken, TOKEN_RIGHTS DesiredAccess, int TokenAttributes, SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, TOKEN_TYPE TokenType, out int NewToken);
public extern static bool DuplicateToken(IntPtr ExistingTokenHandle, SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, ref IntPtr DuplicateTokenHandle);
public static extern bool DuplicateToken([NotNull] SafeTokenHandle existingTokenHandle, SECURITY_IMPERSONATION_LEVEL impersonationLevel, out IntPtr duplicateTokenHandle);
public static bool DuplicateTokenEx(IntPtr hExistingToken, uint dwDesiredAccess, SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, TOKEN_TYPE TokenType, out IntPtr phNewToken) { return(_DuplicateTokenEx(hExistingToken, dwDesiredAccess, IntPtr.Zero, ImpersonationLevel, TokenType, out phNewToken)); }
private static extern bool DuplicateTokenEx(SafeAccessTokenHandle existingToken, uint desiredAccess, [In][Out] SecurityAttributes?tokenAttributes, SECURITY_IMPERSONATION_LEVEL impersonationLevel, TokenType tokenType, out SafeAccessTokenHandle duplicateTokenHandle);
private static extern bool DuplicateTokenEx(IntPtr hExistingToken, UInt32 dwDesiredAccess, IntPtr lpTokenAttributes, SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, TOKEN_TYPE TokenType, ref IntPtr phNewToken);
public static extern int DuplicateToken( IntPtr hToken, SECURITY_IMPERSONATION_LEVEL impersonationLevel, ref IntPtr hNewToken);
public static extern bool ImpersonateSelf(SECURITY_IMPERSONATION_LEVEL ImpersonationLevel);
public static extern bool DuplicateTokenEx(IntPtr hExistingToken, uint dwDesiredAccess, IntPtr tokenAttr, SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, TOKEN_TYPE TokenType, out IntPtr phNewToken);
public static extern bool DuplicateToken( SafeTokenHandle ExistingTokenHandle, SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, out SafeTokenHandle DuplicateTokenHandle);
public static void duplicateToken(IntPtr token, TokenAccessFlags tokenAccess, SECURITY_IMPERSONATION_LEVEL se, TOKEN_TYPE type, out IntPtr duplicated) { if (!DuplicateTokenEx(token, tokenAccess, IntPtr.Zero, se, type, out duplicated)) { duplicated = IntPtr.Zero; } }
public extern static bool DuplicateTokenEx([In] IntPtr TokenHandle, int dwDesiredAccess, [In] ref SECURITY_ATTRIBUTES lpTokenAttributes, SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, TOKEN_TYPE TokenType, out IntPtr phNewToken);
internal static extern bool DuplicateTokenEx(IntPtr hExistingToken, ACCESS dwDesiredAccess, ref SECURITY_ATTRIBUTES lpThreadAttributes, SECURITY_IMPERSONATION_LEVEL impersonationLevel, TOKEN_TYPE dwTokenType, out IntPtr phNewToken);
public extern static Boolean DuplicateTokenEx(IntPtr existingTokenHandle, TokenAccess desiredAccess, IntPtr tokenAttributes, SECURITY_IMPERSONATION_LEVEL impersonationLevel, TOKEN_TYPE tokenType, out IntPtr newTokenHandle);
public extern static bool DuplicateToken(IntPtr ExistingTokenHandle, SECURITY_IMPERSONATION_LEVEL impersonationLevel, out IntPtr DuplicateTokenHandle);
bool DuplicateTokenEx(SafeTokenHandle ExistingTokenHandle, TokenAccessLevels DesiredAccess, IntPtr TokenAttributes, SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, System.Security.Principal.TokenType TokenType, ref SafeTokenHandle DuplicateTokenHandle);
public extern static bool DuplicateToken( SafeTokenHandle ExistingTokenHandle, SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, out SafeTokenHandle DuplicateTokenHandle);
public static extern bool DuplicateTokenEx(IntPtr hExistingToken, uint dwDesiredAccess, [MarshalAs(UnmanagedType.Struct)] ref SECURITY_ATTRIBUTES lpTokenAttributes, SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, TOKEN_TYPE TokenType, out IntPtr phNewToken);