Skip to content

Commit 5335d43

Browse files
committed
added support for domain\user for key-based auth
1 parent 2d6e648 commit 5335d43

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

contrib/win32/openssh/install-sshd.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ $scriptdir = Split-Path $scriptpath
44
$sshdpath = Join-Path $scriptdir "sshd.exe"
55
$sshagentpath = Join-Path $scriptdir "ssh-agent.exe"
66

7+
$ntrights = Join-Path $scriptdir "ntrights.exe -u `"NT SERVICE\SSHD`" +r SeAssignPrimaryTokenPrivilege"
8+
79
if (-not (Test-Path $sshdpath)) {
810
throw "sshd.exe is not present in script path"
911
}
@@ -25,5 +27,6 @@ cmd.exe /c 'sc.exe sdset ssh-agent D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPW
2527

2628
New-Service -Name sshd -BinaryPathName $sshdpath -Description "SSH Deamon" -StartupType Manual -DependsOn ssh-agent | Out-Null
2729
sc.exe config sshd obj= "NT SERVICE\SSHD"
30+
cmd.exe /c $ntrights
2831
Write-Host -ForegroundColor Green "sshd and ssh-agent services successfully installed"
2932

contrib/win32/win32compat/ssh-agent/authagent-request.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ InitLsaString(LSA_STRING *lsa_string, const char *str)
5050
}
5151
}
5252

53+
#define MAX_USER_LEN 256
5354
static HANDLE
5455
generate_user_token(wchar_t* user) {
55-
HANDLE lsa_handle = 0, token = 0;;
56+
HANDLE lsa_handle = 0, token = 0;
5657
LSA_OPERATIONAL_MODE mode;
5758
ULONG auth_package_id;
5859
NTSTATUS ret, subStatus;
@@ -64,7 +65,33 @@ generate_user_token(wchar_t* user) {
6465
LUID logonId;
6566
QUOTA_LIMITS quotas;
6667
DWORD cbProfile;
67-
BOOL domain_user = (wcschr(user, L'@') != NULL)? TRUE : FALSE;
68+
BOOL domain_user;
69+
70+
/* prep user name - TODO: implment an accurate check if user is domain account*/
71+
if (wcsnlen(user, MAX_USER_LEN) == MAX_USER_LEN) {
72+
debug("user length is not supported");
73+
goto done;
74+
}
75+
76+
if (wcschr(user, L'\\') != NULL) {
77+
wchar_t *un = NULL, *dn = NULL;
78+
DWORD un_len = 0, dn_len = 0;
79+
dn = user;
80+
dn_len = wcschr(user, L'\\') - user;
81+
un = wcschr(user, L'\\') + 1;
82+
un_len = wcsnlen(user, MAX_USER_LEN) - dn_len - 1;
83+
if (dn_len == 0 || un_len == 0) {
84+
debug("cannot get user token - bad user name");
85+
goto done;
86+
}
87+
memcpy(user_copy, un, un_len * sizeof(wchar_t));
88+
user_copy[un_len] = L'@';
89+
memcpy(user_copy + un_len + 1, dn, dn_len * sizeof(wchar_t));
90+
user_copy[dn_len + 1 + un_len] = L'\0';
91+
user = user_copy;
92+
}
93+
94+
domain_user = (wcschr(user, L'@') != NULL) ? TRUE : FALSE;
6895

6996
InitLsaString(&logon_process_name, "ssh-agent");
7097
if (domain_user)

0 commit comments

Comments
 (0)