Support NULL-tokens in user_impersonator

Specifying NULL token is a no-op now. This simplifies client code when
impersonation is optional.

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2019-08-23 10:48:09 +02:00
parent ae62e57126
commit fa1514e9b3
2 changed files with 4 additions and 4 deletions

View File

@ -832,11 +832,11 @@ namespace winstd
/// ///
/// Construct the impersonator and impersonates the given user /// Construct the impersonator and impersonates the given user
/// ///
/// \param[in] hToken A handle to a primary or impersonation access token that represents a logged-on user /// \param[in] hToken A handle to a primary or impersonation access token that represents a logged-on user or NULL for no impersonation.
/// ///
/// \sa [ImpersonateLoggedOnUser function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa378612.aspx) /// \sa [ImpersonateLoggedOnUser function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa378612.aspx)
/// ///
user_impersonator(_In_ HANDLE hToken); user_impersonator(_In_opt_ HANDLE hToken);
/// ///
/// Reverts to current user and destructs the impersonator /// Reverts to current user and destructs the impersonator

View File

@ -283,9 +283,9 @@ winstd::actctx_activator::~actctx_activator()
// winstd::user_impersonator // winstd::user_impersonator
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
winstd::user_impersonator::user_impersonator(_In_ HANDLE hToken) winstd::user_impersonator::user_impersonator(_In_opt_ HANDLE hToken)
{ {
m_cookie = ImpersonateLoggedOnUser(hToken); m_cookie = hToken && ImpersonateLoggedOnUser(hToken);
} }