def test_Token_change_privileges_disable(self): for enabled_priv , status in win32security.GetTokenInformation(self.token0, win32security.TokenPrivileges): if status & win32security.SE_PRIVILEGE_ENABLED: break was_enabled, was_disabled = _tokens.Token(self.token0).change_privileges(disable_privs=[enabled_priv]) for priv, status in win32security.GetTokenInformation(self.token0, win32security.TokenPrivileges): if priv == enabled_priv: assert not status & win32security.SE_PRIVILEGE_ENABLED _tokens.Token(self.token0).change_privileges(was_enabled, was_disabled)
def test_Token_unimpersonate(): hToken = win32security.LogonUser("alice", "", "Passw0rd", win32security.LOGON32_LOGON_NETWORK, win32security.LOGON32_PROVIDER_DEFAULT) win32security.ImpersonateLoggedOnUser(_tokens.Token(hToken).pyobject()) assert _tokens.token().Owner.pyobject() == alice win32security.RevertToSelf() assert _tokens.token().Owner.pyobject() == me
def test_Token_impersonate(): alice, system, type = win32security.LookupAccountName(None, "alice") hToken = win32security.LogonUser("alice", "", "Passw0rd", win32security.LOGON32_LOGON_NETWORK, win32security.LOGON32_PROVIDER_DEFAULT) token = _tokens.Token(hToken) try: token.impersonate() assert token.Owner.pyobject() == alice finally: win32security.RevertToSelf()
def test_Token_unimpersonate(self): hToken = win32security.LogonUser( "alice", "", "Passw0rd", win32security.LOGON32_LOGON_NETWORK, win32security.LOGON32_PROVIDER_DEFAULT ) me = _tokens.token().Owner.pyobject() win32security.ImpersonateLoggedOnUser(_tokens.Token(hToken).pyobject()) self.assertEquals(_tokens.token().Owner.pyobject(), self.alice) win32security.RevertToSelf() self.assertEquals(_tokens.token().Owner.pyobject(), me)