Skip to content

Commit 076b8bc

Browse files
committed
feat: support domain users
Signed-off-by: Morgan Epp <60796713+epmog@users.noreply.github.com>
1 parent 884bde2 commit 076b8bc

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

‎src/openjd/sessions/_win32/_helpers.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,16 @@ def logon_user(username: str, password: str) -> HANDLE:
7070
Raises:
7171
OSError - If an error is encountered.
7272
"""
73+
domain: Optional[str] = None
74+
user = username
75+
if "\\" in username:
76+
domain, user = username.split("\\", 1)
77+
# For UPN (user@domain) and local users, domain stays None — Windows resolves automatically
78+
7379
hToken = HANDLE(0)
7480
if not LogonUserW(
75-
username,
76-
None, # TODO - domain handling??
81+
user,
82+
domain,
7783
password,
7884
LOGON32_LOGON_INTERACTIVE,
7985
LOGON32_PROVIDER_DEFAULT,

‎src/openjd/sessions/_win32/_popen_as_user.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,16 @@ def _merge_environment(
168168
else:
169169
env_block = env_ptr
170170

171+
# Parse domain from username for CreateProcessWithLogonW
172+
_logon_user = self.user.user
173+
_logon_domain = None
174+
if "\\" in self.user.user:
175+
_logon_domain, _logon_user = self.user.user.split("\\", 1)
176+
171177
# https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createprocesswithlogonw
172178
if not CreateProcessWithLogonW(
173-
self.user.user,
174-
None, # TODO: Domains not yet supported
179+
_logon_user,
180+
_logon_domain,
175181
self.user.password,
176182
LOGON_WITH_PROFILE,
177183
executable,

0 commit comments

Comments
 (0)