Vinzenz Feenstra has uploaded a new change for review. Change subject: win32: Retrieve the active session through enumeration ......................................................................
win32: Retrieve the active session through enumeration Using WTSGetActiveConsoleSessionId() does in case of RDP connections give a session id which is not corresponding to the users session in some cases. By enumerating through the sessions and retriving the session with the 'State' 'WTSActive' we are able to reliably retrieve the current active session. This is required in order to get the logged-in user and being able to retrieve the user token for performing operations in their name. Change-Id: I569d4b6b80e102b83b7e6e39c12524f2d588ad37 Bug-Url: https://bugzilla.redhat.com/1068750 Signed-off-by: Vinzenz Feenstra <vfeen...@redhat.com> --- M ovirt-guest-agent/GuestAgentWin32.py 1 file changed, 10 insertions(+), 3 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-guest-agent refs/changes/15/26915/1 diff --git a/ovirt-guest-agent/GuestAgentWin32.py b/ovirt-guest-agent/GuestAgentWin32.py index 4cf3d9d..a1b87a8 100644 --- a/ovirt-guest-agent/GuestAgentWin32.py +++ b/ovirt-guest-agent/GuestAgentWin32.py @@ -47,6 +47,13 @@ return key_value.value +def GetActiveSessionId(): + for session in win32ts.WTSEnumerateSessions(): + if session['State'] == win32ts.WTSActive: + return session['SessionId'] + return win32ts.WTSGetActiveConsoleSessionId() + + def GetNetworkInterfaces(): interfaces = list() try: @@ -192,7 +199,7 @@ logging.exception("Error occurred during user login.") def logoff(self): - sessionId = win32ts.WTSGetActiveConsoleSessionId() + sessionId = GetActiveSessionId() if sessionId != 0xffffffff: logging.debug("Logging off current user (session %d)", sessionId) win32ts.WTSLogoffSession(win32ts.WTS_CURRENT_SERVER_HANDLE, @@ -257,7 +264,7 @@ def LockWorkStation(self): try: logging.debug("LockWorkStation was called.") - sessionId = win32ts.WTSGetActiveConsoleSessionId() + sessionId = GetActiveSessionId() if sessionId != 0xffffffff: logging.debug("Locking workstation (session %d)", sessionId) dupToken = None @@ -360,7 +367,7 @@ user = "None" try: domain = "" - sessionId = win32ts.WTSGetActiveConsoleSessionId() + sessionId = GetActiveSessionId() if sessionId != 0xffffffff: user = win32ts.WTSQuerySessionInformation( win32ts.WTS_CURRENT_SERVER_HANDLE, -- To view, visit http://gerrit.ovirt.org/26915 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I569d4b6b80e102b83b7e6e39c12524f2d588ad37 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-guest-agent Gerrit-Branch: master Gerrit-Owner: Vinzenz Feenstra <vfeen...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches