Fixing issue with net stop sshd

This commit is contained in:
Manoj Ampalam 2016-10-18 13:40:11 -07:00
parent 1bcdbf4a48
commit 92ddf4f9e1
2 changed files with 23 additions and 15 deletions

View File

@ -32,6 +32,7 @@
#include <ws2tcpip.h>
#include <mswsock.h>
#include <errno.h>
#include <VersionHelpers.h>
#include "w32fd.h"
#include <stddef.h>
#include "inc\utf.h"
@ -985,20 +986,26 @@ int
w32_gethostname(char *name_utf8, size_t len) {
wchar_t name_utf16[256];
char* tmp_name_utf8 = NULL;
if (GetHostNameW(name_utf16, 256) == SOCKET_ERROR) {
errno = errno_from_WSALastError();
return -1;
}
if ((tmp_name_utf8 = utf16_to_utf8(name_utf16)) == NULL ||
strlen(tmp_name_utf8) >= len) {
errno = EFAULT; //??
return -1;
}
if (IsWindows8OrGreater()) {
/* TODO - GetHostNameW not present in Win7, do GetProcAddr on Win8+*/
// if (GetHostNameW(name_utf16, 256) == SOCKET_ERROR) {
// errno = errno_from_WSALastError();
// return -1;
// }
memcpy(name_utf8, tmp_name_utf8, strlen(tmp_name_utf8) + 1);
free(tmp_name_utf8);
return 0;
// if ((tmp_name_utf8 = utf16_to_utf8(name_utf16)) == NULL ||
// strlen(tmp_name_utf8) >= len) {
// errno = EFAULT; //??
// return -1;
// }
// memcpy(name_utf8, tmp_name_utf8, strlen(tmp_name_utf8) + 1);
// free(tmp_name_utf8);
// return 0;
}
else
return gethostname(name_utf8, len);
}
void

7
sshd.c
View File

@ -1895,9 +1895,10 @@ main(int ac, char **av)
{
do
{
SERVICE_TABLE_ENTRY DispatchTable[] =
int wmain(int , wchar_t **);
SERVICE_TABLE_ENTRYW DispatchTable[] =
{
{SVCNAME, (LPSERVICE_MAIN_FUNCTION) main},
{L"SSHD", (LPSERVICE_MAIN_FUNCTIONW) wmain},
{NULL, NULL}
};
@ -1920,7 +1921,7 @@ main(int ac, char **av)
* for any other reason, bail out.
*/
if (!StartServiceCtrlDispatcher(DispatchTable))
if (!StartServiceCtrlDispatcherW(DispatchTable))
{
if (GetLastError() == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT)
{