Skip to content

Commit 5e8a54d

Browse files
committed
fix: use SID comparison in is_process_user() for UPN support
LookupAccountName resolves both UPN (user@domain.com) and DDL (DOMAIN\user) to a SID, so the comparison correctly identifies the same account regardless of format. Falls back to string comparison if SID lookup fails. Signed-off-by: Morgan Epp <60796713+epmog@users.noreply.github.com>
1 parent 076b8bc commit 5e8a54d

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

‎src/openjd/sessions/_session_user.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,17 @@ def is_process_user(self) -> bool:
6262
"""
6363
Returns True if the session user is the user running the current process, else False.
6464
65+
On Windows, this uses SID comparison to correctly handle different username formats
66+
(e.g. UPN "user@domain.com" vs DDL "DOMAIN\\user") that refer to the same account.
6567
"""
68+
if is_windows():
69+
try:
70+
user_sid, _, _ = win32security.LookupAccountName(None, self.user)
71+
process_sid, _, _ = win32security.LookupAccountName(None, self._get_process_user())
72+
return user_sid == process_sid
73+
except pywintypes.error:
74+
# Fall back to string comparison if SID lookup fails
75+
return self.user == self._get_process_user()
6676
return self.user == self._get_process_user()
6777

6878

0 commit comments

Comments
 (0)