Fix service path quoting on Windows.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=565671
This commit is contained in:
Roger Light 2020-08-11 09:09:31 +01:00
parent 4ef48269f5
commit 60dc8f5e4c
2 changed files with 11 additions and 6 deletions

View File

@ -1,3 +1,7 @@
Security:
- On Windows the Mosquitto service was being installed without appropriate
path quoting, this has been fixed.
Broker:
- Fix usage message only mentioning v3.1.1. Closes #1713.
- Fix broker refusing to start if only websockets listeners were defined.

View File

@ -70,7 +70,7 @@ void __stdcall service_main(DWORD dwArgc, LPTSTR *lpszArgv)
service_handle = RegisterServiceCtrlHandler("mosquitto", service_handler);
if(service_handle){
memset(conf_path, 0, MAX_PATH + 20);
memset(conf_path, 0, sizeof(conf_path));
rc = GetEnvironmentVariable("MOSQUITTO_DIR", conf_path, MAX_PATH);
if(!rc || rc == MAX_PATH){
service_status.dwCurrentState = SERVICE_STOPPED;
@ -103,25 +103,26 @@ void __stdcall service_main(DWORD dwArgc, LPTSTR *lpszArgv)
void service_install(void)
{
SC_HANDLE sc_manager, svc_handle;
char exe_path[MAX_PATH + 5];
char service_string[MAX_PATH + 20];
char exe_path[MAX_PATH + 1];
SERVICE_DESCRIPTION svc_desc;
memset(exe_path, 0, MAX_PATH+5);
memset(exe_path, 0, sizeof(exe_path));
if(GetModuleFileName(NULL, exe_path, MAX_PATH) == MAX_PATH){
fprintf(stderr, "Error: Path too long.\n");
return;
}
strcat(exe_path, " run");
snprintf(service_string, sizeof(service_string), "\"%s\" run", exe_path);
sc_manager = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE);
if(sc_manager){
svc_handle = CreateService(sc_manager, "mosquitto", "Mosquitto Broker",
SERVICE_START | SERVICE_STOP | SERVICE_CHANGE_CONFIG,
SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
exe_path, NULL, NULL, NULL, NULL, NULL);
service_string, NULL, NULL, NULL, NULL, NULL);
if(svc_handle){
svc_desc.lpDescription = "MQTT v3.1.1 broker";
svc_desc.lpDescription = "Eclipse Mosquitto MQTT v5/v3.1.1 broker";
ChangeServiceConfig2(svc_handle, SERVICE_CONFIG_DESCRIPTION, &svc_desc);
CloseServiceHandle(svc_handle);
}else{