Commits

Jason R. Coombs committed cd374cb

Fleshed out a working get_current_user

  • Participants
  • Parent commits 8a27aec

Comments (0)

Files changed (1)

jaraco/windows/security.py

 	Given a token, get the token information for it.
 	"""
 	data_size = ctypes.wintypes.DWORD()
-	info = information_class()
+	ctypes.windll.advapi32.GetTokenInformation(token, information_class.num,
+		0, 0, ctypes.byref(data_size))
+	data = ctypes.create_string_buffer(data_size.value)
 	handle_nonzero_success(ctypes.windll.advapi32.GetTokenInformation(token,
 		information_class.num,
-		ctypes.byref(info), ctypes.sizeof(information_class),
+		ctypes.byref(data), ctypes.sizeof(data),
 		ctypes.byref(data_size)))
-	return info
+	return ctypes.cast(data, ctypes.POINTER(TOKEN_USER)).contents
 
 class TokenAccess:
 	TOKEN_QUERY = 0x8
 
 def OpenProcessToken(proc_handle, access):
 	result = ctypes.wintypes.HANDLE()
-	ctypes.windll.advapi32.OpenProcessToken(
-		proc_handle, access, ctypes.byref(result))
+	proc_handle = ctypes.wintypes.HANDLE(proc_handle)
+	handle_nonzero_success(ctypes.windll.advapi32.OpenProcessToken(
+		proc_handle, access, ctypes.byref(result)))
 	return result
 
 def get_current_user():