vlmcsd-1107-2016-12-12-Hotbird64

pull/5/head svn1107
Wind4 8 years ago
parent af593fc11b
commit c5e1a0a591

@ -198,6 +198,7 @@ help:
@echo " -DNO_SOCKETS Don't support standalone operation. Requires an internet superserver to start $(BASE_PROGRAM_NAME)." @echo " -DNO_SOCKETS Don't support standalone operation. Requires an internet superserver to start $(BASE_PROGRAM_NAME)."
@echo " -DSIMPLE_SOCKETS Compile $(BASE_PROGRAM_NAME) with basic socket support only. Removes -L option." @echo " -DSIMPLE_SOCKETS Compile $(BASE_PROGRAM_NAME) with basic socket support only. Removes -L option."
@echo " -DSIMPLE_RPC Don't support RPC with NDR64 and BTFN in $(BASE_PROGRAM_NAME) (but do in $(BASE_CLIENT_NAME)). Makes emulator detection easy." @echo " -DSIMPLE_RPC Don't support RPC with NDR64 and BTFN in $(BASE_PROGRAM_NAME) (but do in $(BASE_CLIENT_NAME)). Makes emulator detection easy."
@echo " -DNO_TAP Compile $(BASE_PROGRAM_NAME) without VPN support (Windows and Cygwin only)."
@echo " -DNO_CL_PIDS Don't support specifying ePIDs and HwId from the command line in $(BASE_PROGRAM_NAME)." @echo " -DNO_CL_PIDS Don't support specifying ePIDs and HwId from the command line in $(BASE_PROGRAM_NAME)."
@echo " -DNO_LIMIT Don't support limiting concurrent clients in $(BASE_PROGRAM_NAME)." @echo " -DNO_LIMIT Don't support limiting concurrent clients in $(BASE_PROGRAM_NAME)."
@echo " -DNO_SIGHUP Don't support SIGHUP handling in $(BASE_PROGRAM_NAME)." @echo " -DNO_SIGHUP Don't support SIGHUP handling in $(BASE_PROGRAM_NAME)."

Binary file not shown.

@ -1,5 +1,5 @@
<!-- Creator : groff version 1.22.3 --> <!-- Creator : groff version 1.22.3 -->
<!-- CreationDate: Mon Dec 5 18:18:46 2016 --> <!-- CreationDate: Sun Dec 11 22:03:19 2016 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"> "http://www.w3.org/TR/html4/loose.dtd">
<html> <html>

Binary file not shown.

@ -1,5 +1,5 @@
<!-- Creator : groff version 1.22.3 --> <!-- Creator : groff version 1.22.3 -->
<!-- CreationDate: Mon Dec 5 18:18:46 2016 --> <!-- CreationDate: Sun Dec 11 22:03:20 2016 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"> "http://www.w3.org/TR/html4/loose.dtd">
<html> <html>

Binary file not shown.

@ -1,5 +1,5 @@
<!-- Creator : groff version 1.22.3 --> <!-- Creator : groff version 1.22.3 -->
<!-- CreationDate: Mon Dec 5 18:18:46 2016 --> <!-- CreationDate: Sun Dec 11 22:03:19 2016 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"> "http://www.w3.org/TR/html4/loose.dtd">
<html> <html>

Binary file not shown.

@ -1,5 +1,5 @@
<!-- Creator : groff version 1.22.3 --> <!-- Creator : groff version 1.22.3 -->
<!-- CreationDate: Mon Dec 5 18:18:46 2016 --> <!-- CreationDate: Sun Dec 11 22:03:20 2016 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"> "http://www.w3.org/TR/html4/loose.dtd">
<html> <html>

Binary file not shown.

@ -1,5 +1,5 @@
<!-- Creator : groff version 1.22.3 --> <!-- Creator : groff version 1.22.3 -->
<!-- CreationDate: Mon Dec 5 18:18:46 2016 --> <!-- CreationDate: Sun Dec 11 22:03:20 2016 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"> "http://www.w3.org/TR/html4/loose.dtd">
<html> <html>

Binary file not shown.

@ -1,5 +1,5 @@
<!-- Creator : groff version 1.22.3 --> <!-- Creator : groff version 1.22.3 -->
<!-- CreationDate: Mon Dec 5 18:18:46 2016 --> <!-- CreationDate: Sun Dec 11 22:03:19 2016 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"> "http://www.w3.org/TR/html4/loose.dtd">
<html> <html>

Binary file not shown.

@ -257,14 +257,14 @@ else
STRIPFLAGS += -s STRIPFLAGS += -s
endif endif
LIBRARY_CFLAGS = -DSIMPLE_SOCKETS -DNO_TIMEOUT -DNO_SIGHUP -DNO_CL_PIDS -DNO_LOG -DNO_RANDOM_EPID -DNO_INI_FILE -DNO_HELP -DNO_CUSTOM_INTERVALS -DNO_PID_FILE -DNO_USER_SWITCH -DNO_VERBOSE_LOG -DNO_LIMIT -DNO_VERSION_INFORMATION -DNO_PRIVATE_IP_DETECT -DNO_STRICT_MODES -DNO_CLIENT_LIST -UNO_SOCKETS -USIMPLE_RPC LIBRARY_CFLAGS = -DSIMPLE_SOCKETS -DNO_TIMEOUT -DNO_SIGHUP -DNO_CL_PIDS -DNO_LOG -DNO_RANDOM_EPID -DNO_INI_FILE -DNO_HELP -DNO_CUSTOM_INTERVALS -DNO_PID_FILE -DNO_USER_SWITCH -DNO_VERBOSE_LOG -DNO_LIMIT -DNO_VERSION_INFORMATION -DNO_PRIVATE_IP_DETECT -DNO_STRICT_MODES -DNO_CLIENT_LIST -DNO_TAP -UNO_SOCKETS -USIMPLE_RPC
ifeq ($(FEATURES), embedded) ifeq ($(FEATURES), embedded)
BASECFLAGS += -DNO_HELP -DNO_USER_SWITCH -DNO_CUSTOM_INTERVALS -DNO_PID_FILE -DNO_VERBOSE_LOG -DNO_VERSION_INFORMATION BASECFLAGS += -DNO_HELP -DNO_USER_SWITCH -DNO_CUSTOM_INTERVALS -DNO_PID_FILE -DNO_VERBOSE_LOG -DNO_VERSION_INFORMATION
else ifeq ($(FEATURES), autostart) else ifeq ($(FEATURES), autostart)
BASECFLAGS += -DNO_HELP -DNO_VERSION_INFORMATION BASECFLAGS += -DNO_HELP -DNO_VERSION_INFORMATION
else ifeq ($(FEATURES), minimum) else ifeq ($(FEATURES), minimum)
BASECFLAGS += -DSIMPLE_RPC -DSIMPLE_SOCKETS -DNO_TIMEOUT -DNO_SIGHUP -DNO_CL_PIDS -DNO_LOG -DNO_RANDOM_EPID -DNO_INI_FILE -DNO_HELP -DNO_CUSTOM_INTERVALS -DNO_PID_FILE -DNO_USER_SWITCH -DNO_VERBOSE_LOG -DNO_LIMIT -DNO_VERSION_INFORMATION -DNO_PRIVATE_IP_DETECT -DSMALL_AES -DNO_STRICT_MODES -DNO_CLIENT_LIST -DUNSAFE_DATA_LOAD -DNO_EXTERNAL_DATA -UFULL_INTERNAL_DATA -U_PEDANTIC BASECFLAGS += -DSIMPLE_RPC -DSIMPLE_SOCKETS -DNO_TIMEOUT -DNO_SIGHUP -DNO_CL_PIDS -DNO_LOG -DNO_RANDOM_EPID -DNO_INI_FILE -DNO_HELP -DNO_CUSTOM_INTERVALS -DNO_PID_FILE -DNO_USER_SWITCH -DNO_VERBOSE_LOG -DNO_LIMIT -DNO_VERSION_INFORMATION -DNO_PRIVATE_IP_DETECT -DSMALL_AES -DNO_STRICT_MODES -DNO_TAP -DNO_CLIENT_LIST -DUNSAFE_DATA_LOAD -DNO_EXTERNAL_DATA -UFULL_INTERNAL_DATA -U_PEDANTIC
else ifeq ($(FEATURES), most) else ifeq ($(FEATURES), most)
BASECFLAGS += -DNO_SIGHUP -DNO_PID_FILE -DNO_LIMIT BASECFLAGS += -DNO_SIGHUP -DNO_PID_FILE -DNO_LIMIT
else ifeq ($(FEATURES), inetd) else ifeq ($(FEATURES), inetd)

@ -31,26 +31,6 @@
/*
* Define default ePIDs and HWID here. Preferrably grab ePIDs and HWID
* from a real KMS server.
*/
//#ifndef EPID_WINDOWS
//#define EPID_WINDOWS "03612-00206-471-452343-03-1033-14393.0000-2932016"
//#endif
//
//#ifndef EPID_OFFICE2010
//#define EPID_OFFICE2010 "03612-00096-199-303490-03-1033-14393.0000-2932016"
//#endif
//
//#ifndef EPID_OFFICE2013
//#define EPID_OFFICE2013 "03612-00206-234-394838-03-1033-14393.0000-2932016"
//#endif
//
//#ifndef EPID_OFFICE2016
//#define EPID_OFFICE2016 "03612-00206-437-938923-03-1033-14393.0000-2932016"
//#endif
#ifndef HWID // HwId from the Ratiborus VM #ifndef HWID // HwId from the Ratiborus VM
#define HWID 0x3A, 0x1C, 0x04, 0x96, 0x00, 0xB6, 0x00, 0x76 #define HWID 0x3A, 0x1C, 0x04, 0x96, 0x00, 0xB6, 0x00, 0x76
@ -67,21 +47,21 @@
/* /*
* ------------------------------- * -------------------------------
* Defaults * Defaults
* ------------------------------- * -------------------------------
*/ */
#ifndef INI_FILE #ifndef INI_FILE
/* /*
* Uncomment and customize the following line if you want vlmcsd to look for an ini file * Uncomment and customize the following line if you want vlmcsd to look for an ini file
* at a default location. * at a default location.
*/ */
//#define INI_FILE "/etc/vlmcsd.ini" //#define INI_FILE "/etc/vlmcsd.ini"
#endif // INI_FILE #endif // INI_FILE
@ -95,7 +75,7 @@
* at a custom default location. * at a custom default location.
*/ */
//#define DATA_FILE "/etc/vlmcsd.kmd" //#define DATA_FILE "/etc/vlmcsd.kmd"
#endif // DATA_FILE #endif // DATA_FILE
@ -353,7 +333,7 @@
* Includes the full database in vlmcsd. * Includes the full database in vlmcsd.
*/ */
//#define FULL_INTERNAL_DATA //#define FULL_INTERNAL_DATA
#endif // FULL_INTERNAL_DATA #endif // FULL_INTERNAL_DATA
@ -374,13 +354,25 @@
* your system. * your system.
*/ */
//#define NO_FREEBIND //#define NO_FREEBIND
#endif // NO_FREEBIND #endif // NO_FREEBIND
#ifndef NO_TAP
/*
* Do not compile support for using a VPN adapter under Windows. Disables -O command line option.
*/
//#define NO_TAP
#endif // NO_TAP
#ifndef NO_VERSION_INFORMATION #ifndef NO_VERSION_INFORMATION
/* /*
* Removes the -V option from vlmcsd and vlmcs that displays the version information * Removes the -V option from vlmcsd and vlmcs that displays the version information
@ -493,7 +485,7 @@
* and ini file parameter KmsData. Implies UNSAFE_DATA_LOAD. * and ini file parameter KmsData. Implies UNSAFE_DATA_LOAD.
*/ */
//#define NO_EXTERNAL_DATA //#define NO_EXTERNAL_DATA
#endif // NO_EXTERNAL_DATA #endif // NO_EXTERNAL_DATA
@ -507,7 +499,7 @@
* the program exits with an error message. * the program exits with an error message.
*/ */
//#define NO_INTERNAL_DATA //#define NO_INTERNAL_DATA
#endif // NO_INTERNAL_DATA #endif // NO_INTERNAL_DATA
@ -658,7 +650,7 @@
* smaller binaries but makes emulator detection easier. * smaller binaries but makes emulator detection easier.
*/ */
//#define SIMPLE_RPC //#define SIMPLE_RPC
#endif // !SIMPLE_RPC #endif // !SIMPLE_RPC
@ -670,7 +662,7 @@
* It still supports IPv4 and IPv6. * It still supports IPv4 and IPv6.
*/ */
//#define SIMPLE_SOCKETS //#define SIMPLE_SOCKETS
#endif // SIMPLE_SOCKETS #endif // SIMPLE_SOCKETS

@ -455,7 +455,7 @@ void getExeName()
fn_exe = (char*)getauxval(AT_EXECFN); fn_exe = (char*)getauxval(AT_EXECFN);
# elif __UCLIBC__ && __UCLIBC_MAJOR__ < 1 && !defined(NO_PROCFS) // Workaround for older uclibc # elif (__ANDROID__ && __ANDROID_API__ < 16) || (__UCLIBC__ && __UCLIBC_MAJOR__ < 1 && !defined(NO_PROCFS)) // Workaround for older uclibc
char temp[PATH_MAX + 1]; char temp[PATH_MAX + 1];

@ -301,7 +301,7 @@ static void generateRandomPid(int index, char *const szPid, int serverType, int1
time(&maxTime); time(&maxTime);
# ifndef BUILD_TIME # ifndef BUILD_TIME
# define BUILD_TIME 1479938320 # define BUILD_TIME 1481079869
# endif # endif
if (maxTime < (time_t)BUILD_TIME) // Just in case the system time is < 10/17/2013 1:00 pm if (maxTime < (time_t)BUILD_TIME) // Just in case the system time is < 10/17/2013 1:00 pm

@ -294,7 +294,6 @@ SOCKET connectToAddress(const char *const addr, const int AddressFamily, int_fas
#ifndef NO_SOCKETS #ifndef NO_SOCKETS
#ifdef SIMPLE_SOCKETS
static int_fast8_t allowSocketReuse(SOCKET s) static int_fast8_t allowSocketReuse(SOCKET s)
{ {
@ -322,6 +321,8 @@ static int_fast8_t allowSocketReuse(SOCKET s)
} }
#ifdef SIMPLE_SOCKETS
int listenOnAllAddresses() int listenOnAllAddresses()
{ {
uint32_t port_listen; uint32_t port_listen;
@ -575,14 +576,7 @@ static int listenOnAddress(const struct addrinfo *const ai, SOCKET *s)
} }
# endif # endif
# if !_WIN32 && !__CYGWIN__ allowSocketReuse(*s);
if (setsockopt(*s, SOL_SOCKET, SO_REUSEADDR, (sockopt_t)&socketOption, sizeof(socketOption)))
{
# ifdef _PEDANTIC
printerrorf("Warning: %s does not support socket option SO_REUSEADDR: %s\n", ipstr, vlmcsd_strerror(socket_errno));
# endif // _PEDANTIC
}
# endif // !_WIN32 && !__CYGWIN__
# if HAVE_FREEBIND # if HAVE_FREEBIND
# if (defined(IP_NONLOCALOK) || __FreeBSD_kernel__ || __FreeBSD__) && !defined(IPV6_BINDANY) # if (defined(IP_NONLOCALOK) || __FreeBSD_kernel__ || __FreeBSD__) && !defined(IPV6_BINDANY)

@ -16,115 +16,108 @@ SERVICE_STATUS_HANDLE gSvcStatusHandle;
VOID WINAPI ServiceCtrlHandler(DWORD dwCtrl) VOID WINAPI ServiceCtrlHandler(DWORD dwCtrl)
{ {
// Handle the requested control code. // Handle the requested control code.
switch(dwCtrl) switch (dwCtrl)
{ {
case SERVICE_CONTROL_STOP: case SERVICE_CONTROL_STOP:
case SERVICE_CONTROL_SHUTDOWN: case SERVICE_CONTROL_SHUTDOWN:
ServiceShutdown = TRUE; ServiceShutdown = TRUE;
ReportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 0); ReportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);
// Remove PID file and free ressources // Remove PID file and free ressources
cleanup(); cleanup();
# ifdef USE_MSRPC # if __CYGWIN__ || defined(USE_MSRPC)
ReportServiceStatus(SERVICE_STOPPED, NO_ERROR, 0); ReportServiceStatus(SERVICE_STOPPED, NO_ERROR, 0);
# endif // !USE_MSRPC # endif // __CYGWIN__
return;
default: default:
break; break;
} }
} }
static VOID WINAPI ServiceMain(const int argc_unused, CARGV argv_unused) static VOID WINAPI ServiceMain(const int argc_unused, CARGV argv_unused)
{ {
// Register the handler function for the service // Register the handler function for the service
gSvcStatusHandle = RegisterServiceCtrlHandler(
NT_SERVICE_NAME,
ServiceCtrlHandler
);
if(!gSvcStatusHandle) if (!((gSvcStatusHandle = RegisterServiceCtrlHandler(NT_SERVICE_NAME, ServiceCtrlHandler))))
{ {
//ServiceReportEvent(RegisterServiceCtrlHandler); return;
return; }
}
// These SERVICE_STATUS members remain as set here // These SERVICE_STATUS members remain as set here
gSvcStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS; gSvcStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
gSvcStatus.dwServiceSpecificExitCode = 0; gSvcStatus.dwServiceSpecificExitCode = 0;
// Run the actual program // Run the actual program
ReportServiceStatus(SERVICE_STOPPED, newmain(), 3000); ReportServiceStatus(SERVICE_STOPPED, newmain(), 3000);
} }
SERVICE_TABLE_ENTRY NTServiceDispatchTable[] = { SERVICE_TABLE_ENTRY NTServiceDispatchTable[] = {
{ {
(LPSTR)NT_SERVICE_NAME, (LPSTR)NT_SERVICE_NAME,
(LPSERVICE_MAIN_FUNCTION) ServiceMain (LPSERVICE_MAIN_FUNCTION)ServiceMain
}, },
{ {
NULL, NULL,
NULL NULL
} }
}; };
VOID ReportServiceStatus(const DWORD dwCurrentState, const DWORD dwWin32ExitCode, const DWORD dwWaitHint) VOID ReportServiceStatus(const DWORD dwCurrentState, const DWORD dwWin32ExitCode, const DWORD dwWaitHint)
{ {
static DWORD dwCheckPoint = 1; static DWORD dwCheckPoint = 1;
// Fill in the SERVICE_STATUS structure. // Fill in the SERVICE_STATUS structure.
gSvcStatus.dwCurrentState = dwCurrentState; gSvcStatus.dwCurrentState = dwCurrentState;
gSvcStatus.dwWin32ExitCode = dwWin32ExitCode; gSvcStatus.dwWin32ExitCode = dwWin32ExitCode;
gSvcStatus.dwWaitHint = dwWaitHint; gSvcStatus.dwWaitHint = dwWaitHint;
if (dwCurrentState == SERVICE_START_PENDING) if (dwCurrentState == SERVICE_START_PENDING)
gSvcStatus.dwControlsAccepted = 0; gSvcStatus.dwControlsAccepted = 0;
else else
gSvcStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP; gSvcStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;
if ( (dwCurrentState == SERVICE_RUNNING) || if ((dwCurrentState == SERVICE_RUNNING) ||
(dwCurrentState == SERVICE_STOPPED) ) (dwCurrentState == SERVICE_STOPPED))
gSvcStatus.dwCheckPoint = 0; gSvcStatus.dwCheckPoint = 0;
else else
gSvcStatus.dwCheckPoint = dwCheckPoint++; gSvcStatus.dwCheckPoint = dwCheckPoint++;
// Report the status of the service to the SCM. // Report the status of the service to the SCM.
SetServiceStatus(gSvcStatusHandle, &gSvcStatus); SetServiceStatus(gSvcStatusHandle, &gSvcStatus);
} }
/*VOID ServiceReportEvent(char *szFunction) /*VOID ServiceReportEvent(char *szFunction)
{ {
HANDLE hEventSource; HANDLE hEventSource;
const char *eventStrings[2]; const char *eventStrings[2];
TCHAR Buffer[80]; TCHAR Buffer[80];
hEventSource = RegisterEventSource(NULL, NT_SERVICE_NAME); hEventSource = RegisterEventSource(NULL, NT_SERVICE_NAME);
if (hEventSource) if (hEventSource)
{ {
snprintf(Buffer, 80, "%s failed with %d", szFunction, GetLastError()); snprintf(Buffer, 80, "%s failed with %d", szFunction, GetLastError());
eventStrings[0] = NT_SERVICE_NAME; eventStrings[0] = NT_SERVICE_NAME;
eventStrings[1] = Buffer; eventStrings[1] = Buffer;
ReportEvent(hEventSource, // event log handle ReportEvent(hEventSource, // event log handle
EVENTLOG_ERROR_TYPE, // event type EVENTLOG_ERROR_TYPE, // event type
0, // event category 0, // event category
00, // event identifier 00, // event identifier
NULL, // no security identifier NULL, // no security identifier
2, // size of lpszStrings array 2, // size of lpszStrings array
0, // no binary data 0, // no binary data
eventStrings, // array of strings eventStrings, // array of strings
NULL); // no binary data NULL); // no binary data
DeregisterEventSource(hEventSource); DeregisterEventSource(hEventSource);
} }
}*/ }*/
//Returns 0=Error, 1=Success, 2=Doesn't exist //Returns 0=Error, 1=Success, 2=Doesn't exist
@ -146,12 +139,12 @@ static uint_fast8_t OpenAndRemoveService(DWORD *dwPreviousState, SC_HANDLE *schS
closeManager = TRUE; closeManager = TRUE;
} }
*schSCManager = OpenSCManager( *schSCManager = OpenSCManager(
NULL, // local computer NULL, // local computer
NULL, // ServicesActive database NULL, // ServicesActive database
SC_MANAGER_ALL_ACCESS); // full access rights SC_MANAGER_ALL_ACCESS); // full access rights
if (!*schSCManager) return 0; if (!*schSCManager) return 0;
if (!((installedService = OpenService(*schSCManager, NT_SERVICE_NAME, SERVICE_ALL_ACCESS)))) if (!((installedService = OpenService(*schSCManager, NT_SERVICE_NAME, SERVICE_ALL_ACCESS))))
{ {
@ -182,86 +175,86 @@ static uint_fast8_t OpenAndRemoveService(DWORD *dwPreviousState, SC_HANDLE *schS
static VOID ServiceInstaller(const char *restrict ServiceUser, const char *const ServicePassword) static VOID ServiceInstaller(const char *restrict ServiceUser, const char *const ServicePassword)
{ {
SC_HANDLE schSCManager; SC_HANDLE schSCManager;
SC_HANDLE schService; SC_HANDLE schService;
char szPath[MAX_PATH] = "\""; char szPath[MAX_PATH] = "\"";
if (!GetModuleFileName(NULL, szPath + sizeof(char), MAX_PATH - 1)) if (!GetModuleFileName(NULL, szPath + sizeof(char), MAX_PATH - 1))
{ {
errorout("Cannot install service (%d)\n", (uint32_t)GetLastError()); errorout("Cannot install service (%d)\n", (uint32_t)GetLastError());
return; return;
} }
strcat(szPath,"\""); strcat(szPath, "\"");
int i; int i;
for (i = 1; i < global_argc; i ++) for (i = 1; i < global_argc; i++)
{ {
// Strip unneccessary parameters, especially the password // Strip unneccessary parameters, especially the password
if (!strcmp(global_argv[i], "-s")) continue; if (!strcmp(global_argv[i], "-s")) continue;
if (!strcmp(global_argv[i], "-W") || if (!strcmp(global_argv[i], "-W") ||
!strcmp(global_argv[i], "-U")) !strcmp(global_argv[i], "-U"))
{ {
i++; i++;
continue; continue;
} }
strcat(szPath, " "); strcat(szPath, " ");
if (strchr(global_argv[i], ' ')) if (strchr(global_argv[i], ' '))
{ {
strcat(szPath, "\""); strcat(szPath, "\"");
strcat(szPath, global_argv[i]); strcat(szPath, global_argv[i]);
strcat(szPath, "\""); strcat(szPath, "\"");
} }
else else
strcat(szPath, global_argv[i]); strcat(szPath, global_argv[i]);
} }
// Get a handle to the SCM database. // Get a handle to the SCM database.
SERVICE_STATUS status; SERVICE_STATUS status;
DWORD dwPreviousState; DWORD dwPreviousState;
if (!OpenAndRemoveService(&dwPreviousState, &schSCManager)) if (!OpenAndRemoveService(&dwPreviousState, &schSCManager))
{ {
errorout("Service removal failed (%d)\n", (uint32_t)GetLastError()); errorout("Service removal failed (%d)\n", (uint32_t)GetLastError());
return; return;
} }
char *tempUser = NULL; char *tempUser = NULL;
if (ServiceUser) if (ServiceUser)
{ {
// Shortcuts for some well known users // Shortcuts for some well known users
if (!strcasecmp(ServiceUser, "/l")) ServiceUser="NT AUTHORITY\\LocalService"; if (!strcasecmp(ServiceUser, "/l")) ServiceUser = "NT AUTHORITY\\LocalService";
if (!strcasecmp(ServiceUser, "/n")) ServiceUser="NT AUTHORITY\\NetworkService"; if (!strcasecmp(ServiceUser, "/n")) ServiceUser = "NT AUTHORITY\\NetworkService";
// Allow Local Users without .\ , e.g. "johndoe" instead of ".\johndoe" // Allow Local Users without .\ , e.g. "johndoe" instead of ".\johndoe"
if (!strchr(ServiceUser, '\\')) if (!strchr(ServiceUser, '\\'))
{ {
tempUser = (char*)vlmcsd_malloc(strlen(ServiceUser) + 3); tempUser = (char*)vlmcsd_malloc(strlen(ServiceUser) + 3);
strcpy(tempUser, ".\\"); strcpy(tempUser, ".\\");
strcat(tempUser, ServiceUser); strcat(tempUser, ServiceUser);
ServiceUser = tempUser; ServiceUser = tempUser;
} }
} }
schService = CreateService( schService = CreateService(
schSCManager, // SCM database schSCManager, // SCM database
NT_SERVICE_NAME, // name of service NT_SERVICE_NAME, // name of service
NT_SERVICE_DISPLAY_NAME, // service name to display NT_SERVICE_DISPLAY_NAME, // service name to display
SERVICE_ALL_ACCESS, // desired access SERVICE_ALL_ACCESS, // desired access
SERVICE_WIN32_OWN_PROCESS, // service type SERVICE_WIN32_OWN_PROCESS, // service type
SERVICE_AUTO_START, // start type SERVICE_AUTO_START, // start type
SERVICE_ERROR_NORMAL, // error control type SERVICE_ERROR_NORMAL, // error control type
szPath, // path to service's binary szPath, // path to service's binary
NULL, // no load ordering group NULL, // no load ordering group
NULL, // no tag identifier NULL, // no tag identifier
"tcpip\0", // depends on TCP/IP "tcpip\0", // depends on TCP/IP
ServiceUser, // LocalSystem account ServiceUser, // LocalSystem account
ServicePassword); // no password ServicePassword); // no password
# if __clang__ && (__CYGWIN__ || __MINGW64__ ) # if __clang__ && (__CYGWIN__ || __MINGW64__ )
// Workaround for clang not understanding some GCC asm syntax used in <w32api/psdk_inc/intrin-impl.h> // Workaround for clang not understanding some GCC asm syntax used in <w32api/psdk_inc/intrin-impl.h>
@ -271,43 +264,43 @@ static VOID ServiceInstaller(const char *restrict ServiceUser, const char *const
# endif # endif
if (tempUser) free(tempUser); if (tempUser) free(tempUser);
if (schService == NULL) if (schService == NULL)
{ {
errorout("CreateService failed (%u)\n", (uint32_t)GetLastError()); errorout("CreateService failed (%u)\n", (uint32_t)GetLastError());
CloseServiceHandle(schSCManager); CloseServiceHandle(schSCManager);
return; return;
} }
else else
{ {
errorout("Service installed successfully\n"); errorout("Service installed successfully\n");
if (dwPreviousState == SERVICE_RUNNING) if (dwPreviousState == SERVICE_RUNNING)
{ {
printf("Restarting " NT_SERVICE_NAME " service => "); printf("Restarting " NT_SERVICE_NAME " service => ");
status.dwCurrentState = SERVICE_STOPPED; status.dwCurrentState = SERVICE_STOPPED;
if (StartService(schService, 0, NULL)) if (StartService(schService, 0, NULL))
{ {
for (i = 0; i < 10; i++) for (i = 0; i < 10; i++)
{ {
if (!QueryServiceStatus(schService, &status) || status.dwCurrentState != SERVICE_START_PENDING) break; if (!QueryServiceStatus(schService, &status) || status.dwCurrentState != SERVICE_START_PENDING) break;
Sleep(100); Sleep(100);
} }
if (status.dwCurrentState == SERVICE_RUNNING) if (status.dwCurrentState == SERVICE_RUNNING)
printf("Success\n"); printf("Success\n");
else if (status.dwCurrentState == SERVICE_START_PENDING) else if (status.dwCurrentState == SERVICE_START_PENDING)
printf("Not ready within a second\n"); printf("Not ready within a second\n");
else else
errorout("Error\n"); errorout("Error\n");
} }
else else
errorout("Error %u\n", (uint32_t)GetLastError()); errorout("Error %u\n", (uint32_t)GetLastError());
} }
} }
CloseServiceHandle(schService); CloseServiceHandle(schService);
CloseServiceHandle(schSCManager); CloseServiceHandle(schSCManager);
} }
int NtServiceInstallation(const int_fast8_t installService, const char *restrict ServiceUser, const char *const ServicePassword) int NtServiceInstallation(const int_fast8_t installService, const char *restrict ServiceUser, const char *const ServicePassword)
@ -322,7 +315,7 @@ int NtServiceInstallation(const int_fast8_t installService, const char *restrict
if (installService == 2) // Remove if (installService == 2) // Remove
{ {
switch(OpenAndRemoveService(NULL, NULL)) switch (OpenAndRemoveService(NULL, NULL))
{ {
case 0: case 0:
errorout("Error removing service %s\n", NT_SERVICE_NAME); errorout("Error removing service %s\n", NT_SERVICE_NAME);

@ -17,6 +17,10 @@
#include "tap-windows.h" #include "tap-windows.h"
#include <iphlpapi.h> #include <iphlpapi.h>
#if !_WIN32
#include <arpa/inet.h>
#endif // !_WIN32
static char* szIpAddress = "10.10.10.9"; static char* szIpAddress = "10.10.10.9";
static char* szMask = "30"; static char* szMask = "30";
static char* szTapName; static char* szTapName;
@ -117,7 +121,7 @@ static void parseTapArgument(char* argument)
exit(VLMCSD_EINVAL); exit(VLMCSD_EINVAL);
} }
Mask = (uint32_t)~(UINT_MAX >> Cidr); Mask = (uint32_t)~(0xffffffff >> Cidr);
Network = IpAddress & Mask; Network = IpAddress & Mask;
Broadcast = IpAddress | ~Mask; Broadcast = IpAddress | ~Mask;
DhcpServer = IpAddress + 1; DhcpServer = IpAddress + 1;

Loading…
Cancel
Save