Fixed: ssh-shellhost.exe is orphaned when sshd.exe aborts unexpectedly (#73)
https://github.com/PowerShell/Win32-OpenSSH/issues/512
This commit is contained in:
parent
70784d5606
commit
f5b88d422e
|
@ -77,6 +77,14 @@ reset_pw() {
|
||||||
free(pw.pw_name);
|
free(pw.pw_name);
|
||||||
if (pw.pw_dir)
|
if (pw.pw_dir)
|
||||||
free(pw.pw_dir);
|
free(pw.pw_dir);
|
||||||
|
if (pw.pw_domain)
|
||||||
|
free(pw.pw_domain);
|
||||||
|
if (pw.pw_sid)
|
||||||
|
free(pw.pw_sid);
|
||||||
|
pw.pw_name = NULL;
|
||||||
|
pw.pw_dir = NULL;
|
||||||
|
pw.pw_domain = NULL;
|
||||||
|
pw.pw_sid = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct passwd*
|
static struct passwd*
|
||||||
|
@ -90,11 +98,10 @@ get_passwd(const char *user_utf8, LPWSTR user_sid) {
|
||||||
HKEY reg_key = 0;
|
HKEY reg_key = 0;
|
||||||
int tmp_len = PATH_MAX;
|
int tmp_len = PATH_MAX;
|
||||||
PDOMAIN_CONTROLLER_INFOW pdc = NULL;
|
PDOMAIN_CONTROLLER_INFOW pdc = NULL;
|
||||||
|
DWORD dsStatus;
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
|
||||||
reset_pw();
|
reset_pw();
|
||||||
|
|
||||||
if ((user_utf16 = utf8_to_utf16(user_utf8) ) == NULL) {
|
if ((user_utf16 = utf8_to_utf16(user_utf8) ) == NULL) {
|
||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
goto done;
|
goto done;
|
||||||
|
@ -118,42 +125,26 @@ get_passwd(const char *user_utf8, LPWSTR user_sid) {
|
||||||
if (user_sid == NULL) {
|
if (user_sid == NULL) {
|
||||||
NET_API_STATUS status;
|
NET_API_STATUS status;
|
||||||
if ((status = NetUserGetInfo(udom_utf16, uname_utf16, 23, &user_info)) != NERR_Success) {
|
if ((status = NetUserGetInfo(udom_utf16, uname_utf16, 23, &user_info)) != NERR_Success) {
|
||||||
debug("NetUserGetInfo() failed with error: %d \n", status);
|
debug("NetUserGetInfo() failed with error: %d for user: %ls and domain: %ls \n", status, uname_utf16, udom_utf16);
|
||||||
|
|
||||||
/* We reach here only for domain users.
|
if ((dsStatus = DsGetDcNameW(NULL, udom_utf16, NULL, NULL, DS_DIRECTORY_SERVICE_PREFERRED, &pdc)) != ERROR_SUCCESS) {
|
||||||
* If we didn't get the domain name from the end-user then we treat it as error and return.
|
|
||||||
*/
|
|
||||||
if (udom_utf16 == NULL) {
|
|
||||||
errno = ENOENT;
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
DWORD dsStatus;
|
|
||||||
if ((dsStatus = DsGetDcNameW(NULL, udom_utf16, NULL, NULL, DS_DIRECTORY_SERVICE_PREFERRED, &pdc)) == ERROR_SUCCESS) {
|
|
||||||
if ((status = NetUserGetInfo(pdc->DomainControllerName, uname_utf16, 23, &user_info)) != NERR_Success) {
|
|
||||||
debug("NetUserGetInfo() with domainController failed with error: %d \n", status);
|
|
||||||
|
|
||||||
if (ConvertSidToStringSidW(((LPUSER_INFO_23)user_info)->usri23_user_sid, &user_sid_local) == FALSE) {
|
|
||||||
error("ConvertSidToStringSidW() failed with error: %d\n", GetLastError());
|
|
||||||
|
|
||||||
errno = ENOENT;
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
error("DsGetDcNameW() failed with error: %d \n", dsStatus);
|
error("DsGetDcNameW() failed with error: %d \n", dsStatus);
|
||||||
errno = ENOENT;
|
errno = ENOENT;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((status = NetUserGetInfo(pdc->DomainControllerName, uname_utf16, 23, &user_info)) != NERR_Success) {
|
||||||
|
debug("NetUserGetInfo() with domainController: %ls failed with error: %d \n", pdc->DomainControllerName, status);
|
||||||
|
errno = ENOENT;
|
||||||
|
goto done;
|
||||||
}
|
}
|
||||||
else {
|
}
|
||||||
|
|
||||||
if (ConvertSidToStringSidW(((LPUSER_INFO_23)user_info)->usri23_user_sid, &user_sid_local) == FALSE) {
|
if (ConvertSidToStringSidW(((LPUSER_INFO_23)user_info)->usri23_user_sid, &user_sid_local) == FALSE) {
|
||||||
debug("NetUserGetInfo() Succeded but ConvertSidToStringSidW() failed with error: %d\n", GetLastError());
|
debug("NetUserGetInfo() Succeded but ConvertSidToStringSidW() failed with error: %d\n", GetLastError());
|
||||||
errno = ENOENT;
|
errno = ENOENT;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
user_sid = user_sid_local;
|
user_sid = user_sid_local;
|
||||||
}
|
}
|
||||||
|
|
|
@ -921,6 +921,9 @@ DWORD WINAPI ProcessPipes(LPVOID p) {
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
/* pipe_in has ended */
|
||||||
|
PostThreadMessage(hostThreadId, WM_APPEXIT, 0, 0);
|
||||||
|
|
||||||
dwStatus = GetLastError();
|
dwStatus = GetLastError();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
1
misc.c
1
misc.c
|
@ -230,6 +230,7 @@ pwcopy(struct passwd *pw)
|
||||||
copy->pw_domain = xstrdup(pw->pw_domain);
|
copy->pw_domain = xstrdup(pw->pw_domain);
|
||||||
else
|
else
|
||||||
copy->pw_domain = NULL;
|
copy->pw_domain = NULL;
|
||||||
|
copy->pw_sid = xstrdup(pw->pw_sid);
|
||||||
#endif // WINDOWS
|
#endif // WINDOWS
|
||||||
|
|
||||||
return copy;
|
return copy;
|
||||||
|
|
Loading…
Reference in New Issue