Fix serviceManager handle closing + winproxy.SetThreadToken for py3

This commit is contained in:
hakril
2024-06-10 21:25:08 +02:00
parent 92742a4e97
commit b1f0d74a3a
3 changed files with 12 additions and 2 deletions
+8 -1
View File
@@ -117,7 +117,14 @@ def test_token_duplicate(newtok):
assert x.impersonation_level == i
def test_set_thread_token():
tok = windows.current_process.token
imp_tok = tok.duplicate(type=gdef.TokenImpersonation, impersonation_level=gdef.SecurityImpersonation)
cur_thread = windows.current_thread
try:
cur_thread.token = imp_tok # Test some impersonnation
finally:
cur_thread.token = None
# def test_token_groups
+3
View File
@@ -5,6 +5,7 @@ from collections import namedtuple
from contextlib import contextmanager
from windows import utils
from windows import winproxy
from windows.pycompat import int_types
import windows.generated_def as gdef
from windows.generated_def import *
@@ -40,6 +41,8 @@ from windows.pycompat import basestring, urepr_encode
class ServiceManager(utils.AutoHandle):
"""An object to query, list and explore services"""
_close_function = staticmethod(winproxy.CloseServiceHandle)
def __init__(self):
self.enum_flags = None #: Lazy computed at first enum
+1 -1
View File
@@ -47,7 +47,7 @@ def OpenThreadToken(ThreadHandle, DesiredAccess, OpenAsSelf, TokenHandle):
@Advapi32Proxy()
def SetThreadToken(Thread, Token):
if isinstance(Thread, (int, long)):
if isinstance(Thread, windows.pycompat.int_types):
Thread = gdef.HANDLE(Thread)
return SetThreadToken.ctypes_function(Thread, Token)