Skip to content

Commit 92ddf4f

Browse files
committed
Fixing issue with net stop sshd
1 parent 1bcdbf4 commit 92ddf4f

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

contrib/win32/win32compat/socketio.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <ws2tcpip.h>
3333
#include <mswsock.h>
3434
#include <errno.h>
35+
#include <VersionHelpers.h>
3536
#include "w32fd.h"
3637
#include <stddef.h>
3738
#include "inc\utf.h"
@@ -985,20 +986,26 @@ int
985986
w32_gethostname(char *name_utf8, size_t len) {
986987
wchar_t name_utf16[256];
987988
char* tmp_name_utf8 = NULL;
988-
if (GetHostNameW(name_utf16, 256) == SOCKET_ERROR) {
989-
errno = errno_from_WSALastError();
990-
return -1;
991-
}
992989

993-
if ((tmp_name_utf8 = utf16_to_utf8(name_utf16)) == NULL ||
994-
strlen(tmp_name_utf8) >= len) {
995-
errno = EFAULT; //??
996-
return -1;
990+
if (IsWindows8OrGreater()) {
991+
/* TODO - GetHostNameW not present in Win7, do GetProcAddr on Win8+*/
992+
// if (GetHostNameW(name_utf16, 256) == SOCKET_ERROR) {
993+
// errno = errno_from_WSALastError();
994+
// return -1;
995+
// }
996+
997+
// if ((tmp_name_utf8 = utf16_to_utf8(name_utf16)) == NULL ||
998+
// strlen(tmp_name_utf8) >= len) {
999+
// errno = EFAULT; //??
1000+
// return -1;
1001+
// }
1002+
1003+
// memcpy(name_utf8, tmp_name_utf8, strlen(tmp_name_utf8) + 1);
1004+
// free(tmp_name_utf8);
1005+
// return 0;
9971006
}
998-
999-
memcpy(name_utf8, tmp_name_utf8, strlen(tmp_name_utf8) + 1);
1000-
free(tmp_name_utf8);
1001-
return 0;
1007+
else
1008+
return gethostname(name_utf8, len);
10021009
}
10031010

10041011
void

sshd.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,9 +1895,10 @@ main(int ac, char **av)
18951895
{
18961896
do
18971897
{
1898-
SERVICE_TABLE_ENTRY DispatchTable[] =
1898+
int wmain(int , wchar_t **);
1899+
SERVICE_TABLE_ENTRYW DispatchTable[] =
18991900
{
1900-
{SVCNAME, (LPSERVICE_MAIN_FUNCTION) main},
1901+
{L"SSHD", (LPSERVICE_MAIN_FUNCTIONW) wmain},
19011902
{NULL, NULL}
19021903
};
19031904

@@ -1920,7 +1921,7 @@ main(int ac, char **av)
19201921
* for any other reason, bail out.
19211922
*/
19221923

1923-
if (!StartServiceCtrlDispatcher(DispatchTable))
1924+
if (!StartServiceCtrlDispatcherW(DispatchTable))
19241925
{
19251926
if (GetLastError() == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT)
19261927
{

0 commit comments

Comments
 (0)