diff --git a/GNUmakefile b/GNUmakefile index 72af7f6..56aeca6 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -198,6 +198,7 @@ help: @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_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_LIMIT Don't support limiting concurrent clients in $(BASE_PROGRAM_NAME)." @echo " -DNO_SIGHUP Don't support SIGHUP handling in $(BASE_PROGRAM_NAME)." diff --git a/floppy/floppy144.vfd b/floppy/floppy144.vfd index 408df4e..fdc2f69 100644 Binary files a/floppy/floppy144.vfd and b/floppy/floppy144.vfd differ diff --git a/man/vlmcs.1.html b/man/vlmcs.1.html index 3bea64a..bbaa1f2 100644 --- a/man/vlmcs.1.html +++ b/man/vlmcs.1.html @@ -1,5 +1,5 @@ - + diff --git a/man/vlmcs.1.pdf b/man/vlmcs.1.pdf index c3f862b..7dbf650 100644 Binary files a/man/vlmcs.1.pdf and b/man/vlmcs.1.pdf differ diff --git a/man/vlmcsd-floppy.7.html b/man/vlmcsd-floppy.7.html index ab9bd00..262d6d1 100644 --- a/man/vlmcsd-floppy.7.html +++ b/man/vlmcsd-floppy.7.html @@ -1,5 +1,5 @@ - + diff --git a/man/vlmcsd-floppy.7.pdf b/man/vlmcsd-floppy.7.pdf index e58df11..8750224 100644 Binary files a/man/vlmcsd-floppy.7.pdf and b/man/vlmcsd-floppy.7.pdf differ diff --git a/man/vlmcsd.7.html b/man/vlmcsd.7.html index 51ddd13..1912fbb 100644 --- a/man/vlmcsd.7.html +++ b/man/vlmcsd.7.html @@ -1,5 +1,5 @@ - + diff --git a/man/vlmcsd.7.pdf b/man/vlmcsd.7.pdf index 3247bc0..8855148 100644 Binary files a/man/vlmcsd.7.pdf and b/man/vlmcsd.7.pdf differ diff --git a/man/vlmcsd.8.html b/man/vlmcsd.8.html index b006bd4..ace7183 100644 --- a/man/vlmcsd.8.html +++ b/man/vlmcsd.8.html @@ -1,5 +1,5 @@ - + diff --git a/man/vlmcsd.8.pdf b/man/vlmcsd.8.pdf index 2a58d24..b932c63 100644 Binary files a/man/vlmcsd.8.pdf and b/man/vlmcsd.8.pdf differ diff --git a/man/vlmcsd.ini.5.html b/man/vlmcsd.ini.5.html index 201b33e..fa59aa7 100644 --- a/man/vlmcsd.ini.5.html +++ b/man/vlmcsd.ini.5.html @@ -1,5 +1,5 @@ - + diff --git a/man/vlmcsd.ini.5.pdf b/man/vlmcsd.ini.5.pdf index 3940ea9..e34d939 100644 Binary files a/man/vlmcsd.ini.5.pdf and b/man/vlmcsd.ini.5.pdf differ diff --git a/man/vlmcsdmulti.1.html b/man/vlmcsdmulti.1.html index ed61c12..a092fb5 100644 --- a/man/vlmcsdmulti.1.html +++ b/man/vlmcsdmulti.1.html @@ -1,5 +1,5 @@ - + diff --git a/man/vlmcsdmulti.1.pdf b/man/vlmcsdmulti.1.pdf index f692be3..ab76941 100644 Binary files a/man/vlmcsdmulti.1.pdf and b/man/vlmcsdmulti.1.pdf differ diff --git a/src/GNUmakefile b/src/GNUmakefile index 56620e4..faa6710 100644 --- a/src/GNUmakefile +++ b/src/GNUmakefile @@ -257,14 +257,14 @@ else STRIPFLAGS += -s 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) BASECFLAGS += -DNO_HELP -DNO_USER_SWITCH -DNO_CUSTOM_INTERVALS -DNO_PID_FILE -DNO_VERBOSE_LOG -DNO_VERSION_INFORMATION else ifeq ($(FEATURES), autostart) BASECFLAGS += -DNO_HELP -DNO_VERSION_INFORMATION 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) BASECFLAGS += -DNO_SIGHUP -DNO_PID_FILE -DNO_LIMIT else ifeq ($(FEATURES), inetd) diff --git a/src/config.h b/src/config.h index ae2747f..b584ed5 100644 --- a/src/config.h +++ b/src/config.h @@ -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 #define HWID 0x3A, 0x1C, 0x04, 0x96, 0x00, 0xB6, 0x00, 0x76 @@ -67,21 +47,21 @@ -/* - * ------------------------------- - * Defaults - * ------------------------------- - */ + /* + * ------------------------------- + * Defaults + * ------------------------------- + */ #ifndef INI_FILE -/* - * Uncomment and customize the following line if you want vlmcsd to look for an ini file - * at a default location. - */ + /* + * Uncomment and customize the following line if you want vlmcsd to look for an ini file + * at a default location. + */ -//#define INI_FILE "/etc/vlmcsd.ini" + //#define INI_FILE "/etc/vlmcsd.ini" #endif // INI_FILE @@ -95,7 +75,7 @@ * at a custom default location. */ -//#define DATA_FILE "/etc/vlmcsd.kmd" + //#define DATA_FILE "/etc/vlmcsd.kmd" #endif // DATA_FILE @@ -353,7 +333,7 @@ * Includes the full database in vlmcsd. */ -//#define FULL_INTERNAL_DATA + //#define FULL_INTERNAL_DATA #endif // FULL_INTERNAL_DATA @@ -374,13 +354,25 @@ * your system. */ - //#define NO_FREEBIND +//#define 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 /* * 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. */ -//#define NO_EXTERNAL_DATA + //#define NO_EXTERNAL_DATA #endif // NO_EXTERNAL_DATA @@ -507,7 +499,7 @@ * the program exits with an error message. */ -//#define NO_INTERNAL_DATA + //#define NO_INTERNAL_DATA #endif // NO_INTERNAL_DATA @@ -658,7 +650,7 @@ * smaller binaries but makes emulator detection easier. */ -//#define SIMPLE_RPC + //#define SIMPLE_RPC #endif // !SIMPLE_RPC @@ -670,7 +662,7 @@ * It still supports IPv4 and IPv6. */ -//#define SIMPLE_SOCKETS + //#define SIMPLE_SOCKETS #endif // SIMPLE_SOCKETS diff --git a/src/helpers.c b/src/helpers.c index 65dd5c6..45910ab 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -455,7 +455,7 @@ void getExeName() 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]; diff --git a/src/kms.c b/src/kms.c index e7b0998..6516d60 100644 --- a/src/kms.c +++ b/src/kms.c @@ -301,7 +301,7 @@ static void generateRandomPid(int index, char *const szPid, int serverType, int1 time(&maxTime); # ifndef BUILD_TIME -# define BUILD_TIME 1479938320 +# define BUILD_TIME 1481079869 # endif if (maxTime < (time_t)BUILD_TIME) // Just in case the system time is < 10/17/2013 1:00 pm diff --git a/src/network.c b/src/network.c index 3a1b0f3..f8939b6 100644 --- a/src/network.c +++ b/src/network.c @@ -294,7 +294,6 @@ SOCKET connectToAddress(const char *const addr, const int AddressFamily, int_fas #ifndef NO_SOCKETS -#ifdef SIMPLE_SOCKETS static int_fast8_t allowSocketReuse(SOCKET s) { @@ -322,6 +321,8 @@ static int_fast8_t allowSocketReuse(SOCKET s) } +#ifdef SIMPLE_SOCKETS + int listenOnAllAddresses() { uint32_t port_listen; @@ -575,14 +576,7 @@ static int listenOnAddress(const struct addrinfo *const ai, SOCKET *s) } # endif -# if !_WIN32 && !__CYGWIN__ - 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__ + allowSocketReuse(*s); # if HAVE_FREEBIND # if (defined(IP_NONLOCALOK) || __FreeBSD_kernel__ || __FreeBSD__) && !defined(IPV6_BINDANY) diff --git a/src/ntservice.c b/src/ntservice.c index eb64129..2de01f6 100644 --- a/src/ntservice.c +++ b/src/ntservice.c @@ -16,115 +16,108 @@ SERVICE_STATUS_HANDLE gSvcStatusHandle; 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_SHUTDOWN: + case SERVICE_CONTROL_STOP: + case SERVICE_CONTROL_SHUTDOWN: - ServiceShutdown = TRUE; - ReportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 0); + ServiceShutdown = TRUE; + ReportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 0); - // Remove PID file and free ressources - cleanup(); -# ifdef USE_MSRPC - ReportServiceStatus(SERVICE_STOPPED, NO_ERROR, 0); -# endif // !USE_MSRPC - return; + // Remove PID file and free ressources + cleanup(); +# if __CYGWIN__ || defined(USE_MSRPC) + ReportServiceStatus(SERVICE_STOPPED, NO_ERROR, 0); +# endif // __CYGWIN__ - default: - break; + default: + break; } } static VOID WINAPI ServiceMain(const int argc_unused, CARGV argv_unused) { - // Register the handler function for the service - - gSvcStatusHandle = RegisterServiceCtrlHandler( - NT_SERVICE_NAME, - ServiceCtrlHandler - ); + // Register the handler function for the service - if(!gSvcStatusHandle) - { - //ServiceReportEvent(RegisterServiceCtrlHandler); - return; - } + if (!((gSvcStatusHandle = RegisterServiceCtrlHandler(NT_SERVICE_NAME, ServiceCtrlHandler)))) + { + return; + } - // These SERVICE_STATUS members remain as set here + // These SERVICE_STATUS members remain as set here - gSvcStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS; - gSvcStatus.dwServiceSpecificExitCode = 0; + gSvcStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS; + gSvcStatus.dwServiceSpecificExitCode = 0; - // Run the actual program - ReportServiceStatus(SERVICE_STOPPED, newmain(), 3000); + // Run the actual program + ReportServiceStatus(SERVICE_STOPPED, newmain(), 3000); } SERVICE_TABLE_ENTRY NTServiceDispatchTable[] = { - { - (LPSTR)NT_SERVICE_NAME, - (LPSERVICE_MAIN_FUNCTION) ServiceMain - }, - { - NULL, - NULL - } + { + (LPSTR)NT_SERVICE_NAME, + (LPSERVICE_MAIN_FUNCTION)ServiceMain + }, + { + NULL, + NULL + } }; 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.dwWin32ExitCode = dwWin32ExitCode; - gSvcStatus.dwWaitHint = dwWaitHint; + gSvcStatus.dwCurrentState = dwCurrentState; + gSvcStatus.dwWin32ExitCode = dwWin32ExitCode; + gSvcStatus.dwWaitHint = dwWaitHint; - if (dwCurrentState == SERVICE_START_PENDING) - gSvcStatus.dwControlsAccepted = 0; - else - gSvcStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP; + if (dwCurrentState == SERVICE_START_PENDING) + gSvcStatus.dwControlsAccepted = 0; + else + gSvcStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP; - if ( (dwCurrentState == SERVICE_RUNNING) || - (dwCurrentState == SERVICE_STOPPED) ) - gSvcStatus.dwCheckPoint = 0; - else - gSvcStatus.dwCheckPoint = dwCheckPoint++; + if ((dwCurrentState == SERVICE_RUNNING) || + (dwCurrentState == SERVICE_STOPPED)) + gSvcStatus.dwCheckPoint = 0; + else + gSvcStatus.dwCheckPoint = dwCheckPoint++; - // Report the status of the service to the SCM. - SetServiceStatus(gSvcStatusHandle, &gSvcStatus); + // Report the status of the service to the SCM. + SetServiceStatus(gSvcStatusHandle, &gSvcStatus); } /*VOID ServiceReportEvent(char *szFunction) { - HANDLE hEventSource; - const char *eventStrings[2]; - TCHAR Buffer[80]; - - hEventSource = RegisterEventSource(NULL, NT_SERVICE_NAME); - - if (hEventSource) - { - snprintf(Buffer, 80, "%s failed with %d", szFunction, GetLastError()); - - eventStrings[0] = NT_SERVICE_NAME; - eventStrings[1] = Buffer; - - ReportEvent(hEventSource, // event log handle - EVENTLOG_ERROR_TYPE, // event type - 0, // event category - 00, // event identifier - NULL, // no security identifier - 2, // size of lpszStrings array - 0, // no binary data - eventStrings, // array of strings - NULL); // no binary data - - DeregisterEventSource(hEventSource); - } + HANDLE hEventSource; + const char *eventStrings[2]; + TCHAR Buffer[80]; + + hEventSource = RegisterEventSource(NULL, NT_SERVICE_NAME); + + if (hEventSource) + { + snprintf(Buffer, 80, "%s failed with %d", szFunction, GetLastError()); + + eventStrings[0] = NT_SERVICE_NAME; + eventStrings[1] = Buffer; + + ReportEvent(hEventSource, // event log handle + EVENTLOG_ERROR_TYPE, // event type + 0, // event category + 00, // event identifier + NULL, // no security identifier + 2, // size of lpszStrings array + 0, // no binary data + eventStrings, // array of strings + NULL); // no binary data + + DeregisterEventSource(hEventSource); + } }*/ //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; } - *schSCManager = OpenSCManager( - NULL, // local computer - NULL, // ServicesActive database - SC_MANAGER_ALL_ACCESS); // full access rights + *schSCManager = OpenSCManager( + NULL, // local computer + NULL, // ServicesActive database + 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)))) { @@ -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) { - SC_HANDLE schSCManager; - SC_HANDLE schService; - char szPath[MAX_PATH] = "\""; - - if (!GetModuleFileName(NULL, szPath + sizeof(char), MAX_PATH - 1)) - { - errorout("Cannot install service (%d)\n", (uint32_t)GetLastError()); - return; - } - - strcat(szPath,"\""); - - int i; - for (i = 1; i < global_argc; i ++) - { - // Strip unneccessary parameters, especially the password - if (!strcmp(global_argv[i], "-s")) continue; - - if (!strcmp(global_argv[i], "-W") || - !strcmp(global_argv[i], "-U")) - { - i++; - continue; - } - - strcat(szPath, " "); - - if (strchr(global_argv[i], ' ')) - { - strcat(szPath, "\""); - strcat(szPath, global_argv[i]); - strcat(szPath, "\""); - } - else - strcat(szPath, global_argv[i]); - } - - // Get a handle to the SCM database. + SC_HANDLE schSCManager; + SC_HANDLE schService; + char szPath[MAX_PATH] = "\""; + + if (!GetModuleFileName(NULL, szPath + sizeof(char), MAX_PATH - 1)) + { + errorout("Cannot install service (%d)\n", (uint32_t)GetLastError()); + return; + } + + strcat(szPath, "\""); + + int i; + for (i = 1; i < global_argc; i++) + { + // Strip unneccessary parameters, especially the password + if (!strcmp(global_argv[i], "-s")) continue; + + if (!strcmp(global_argv[i], "-W") || + !strcmp(global_argv[i], "-U")) + { + i++; + continue; + } + + strcat(szPath, " "); + + if (strchr(global_argv[i], ' ')) + { + strcat(szPath, "\""); + strcat(szPath, global_argv[i]); + strcat(szPath, "\""); + } + else + strcat(szPath, global_argv[i]); + } + + // Get a handle to the SCM database. SERVICE_STATUS status; DWORD dwPreviousState; - if (!OpenAndRemoveService(&dwPreviousState, &schSCManager)) - { - errorout("Service removal failed (%d)\n", (uint32_t)GetLastError()); - return; - } + if (!OpenAndRemoveService(&dwPreviousState, &schSCManager)) + { + errorout("Service removal failed (%d)\n", (uint32_t)GetLastError()); + return; + } char *tempUser = NULL; if (ServiceUser) - { - // Shortcuts for some well known users - if (!strcasecmp(ServiceUser, "/l")) ServiceUser="NT AUTHORITY\\LocalService"; - if (!strcasecmp(ServiceUser, "/n")) ServiceUser="NT AUTHORITY\\NetworkService"; - - // Allow Local Users without .\ , e.g. "johndoe" instead of ".\johndoe" - if (!strchr(ServiceUser, '\\')) - { - tempUser = (char*)vlmcsd_malloc(strlen(ServiceUser) + 3); - strcpy(tempUser, ".\\"); - strcat(tempUser, ServiceUser); - ServiceUser = tempUser; - } - } + { + // Shortcuts for some well known users + if (!strcasecmp(ServiceUser, "/l")) ServiceUser = "NT AUTHORITY\\LocalService"; + if (!strcasecmp(ServiceUser, "/n")) ServiceUser = "NT AUTHORITY\\NetworkService"; + + // Allow Local Users without .\ , e.g. "johndoe" instead of ".\johndoe" + if (!strchr(ServiceUser, '\\')) + { + tempUser = (char*)vlmcsd_malloc(strlen(ServiceUser) + 3); + strcpy(tempUser, ".\\"); + strcat(tempUser, ServiceUser); + ServiceUser = tempUser; + } + } schService = CreateService( - schSCManager, // SCM database - NT_SERVICE_NAME, // name of service - NT_SERVICE_DISPLAY_NAME, // service name to display - SERVICE_ALL_ACCESS, // desired access - SERVICE_WIN32_OWN_PROCESS, // service type - SERVICE_AUTO_START, // start type - SERVICE_ERROR_NORMAL, // error control type - szPath, // path to service's binary - NULL, // no load ordering group - NULL, // no tag identifier - "tcpip\0", // depends on TCP/IP - ServiceUser, // LocalSystem account - ServicePassword); // no password + schSCManager, // SCM database + NT_SERVICE_NAME, // name of service + NT_SERVICE_DISPLAY_NAME, // service name to display + SERVICE_ALL_ACCESS, // desired access + SERVICE_WIN32_OWN_PROCESS, // service type + SERVICE_AUTO_START, // start type + SERVICE_ERROR_NORMAL, // error control type + szPath, // path to service's binary + NULL, // no load ordering group + NULL, // no tag identifier + "tcpip\0", // depends on TCP/IP + ServiceUser, // LocalSystem account + ServicePassword); // no password # if __clang__ && (__CYGWIN__ || __MINGW64__ ) // Workaround for clang not understanding some GCC asm syntax used in @@ -271,43 +264,43 @@ static VOID ServiceInstaller(const char *restrict ServiceUser, const char *const # endif if (tempUser) free(tempUser); - if (schService == NULL) - { - errorout("CreateService failed (%u)\n", (uint32_t)GetLastError()); - CloseServiceHandle(schSCManager); - return; - } - else - { - errorout("Service installed successfully\n"); - - if (dwPreviousState == SERVICE_RUNNING) - { - printf("Restarting " NT_SERVICE_NAME " service => "); - status.dwCurrentState = SERVICE_STOPPED; - - if (StartService(schService, 0, NULL)) - { - for (i = 0; i < 10; i++) - { - if (!QueryServiceStatus(schService, &status) || status.dwCurrentState != SERVICE_START_PENDING) break; - Sleep(100); - } - - if (status.dwCurrentState == SERVICE_RUNNING) - printf("Success\n"); - else if (status.dwCurrentState == SERVICE_START_PENDING) - printf("Not ready within a second\n"); - else - errorout("Error\n"); - } - else - errorout("Error %u\n", (uint32_t)GetLastError()); - } - } - - CloseServiceHandle(schService); - CloseServiceHandle(schSCManager); + if (schService == NULL) + { + errorout("CreateService failed (%u)\n", (uint32_t)GetLastError()); + CloseServiceHandle(schSCManager); + return; + } + else + { + errorout("Service installed successfully\n"); + + if (dwPreviousState == SERVICE_RUNNING) + { + printf("Restarting " NT_SERVICE_NAME " service => "); + status.dwCurrentState = SERVICE_STOPPED; + + if (StartService(schService, 0, NULL)) + { + for (i = 0; i < 10; i++) + { + if (!QueryServiceStatus(schService, &status) || status.dwCurrentState != SERVICE_START_PENDING) break; + Sleep(100); + } + + if (status.dwCurrentState == SERVICE_RUNNING) + printf("Success\n"); + else if (status.dwCurrentState == SERVICE_START_PENDING) + printf("Not ready within a second\n"); + else + errorout("Error\n"); + } + else + errorout("Error %u\n", (uint32_t)GetLastError()); + } + } + + CloseServiceHandle(schService); + CloseServiceHandle(schSCManager); } 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 { - switch(OpenAndRemoveService(NULL, NULL)) + switch (OpenAndRemoveService(NULL, NULL)) { case 0: errorout("Error removing service %s\n", NT_SERVICE_NAME); diff --git a/src/wintap.c b/src/wintap.c index 7c516fa..c065284 100644 --- a/src/wintap.c +++ b/src/wintap.c @@ -17,6 +17,10 @@ #include "tap-windows.h" #include +#if !_WIN32 +#include +#endif // !_WIN32 + static char* szIpAddress = "10.10.10.9"; static char* szMask = "30"; static char* szTapName; @@ -117,7 +121,7 @@ static void parseTapArgument(char* argument) exit(VLMCSD_EINVAL); } - Mask = (uint32_t)~(UINT_MAX >> Cidr); + Mask = (uint32_t)~(0xffffffff >> Cidr); Network = IpAddress & Mask; Broadcast = IpAddress | ~Mask; DhcpServer = IpAddress + 1;