diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a914d35..03458ea5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Fixed - fixed issue with auto updater not offering version updates - fixed issue with new symlink handling code [#3340](https://github.com/sandboxie-plus/Sandboxie/issues/3340) +- fixed issue with Scm_StartServiceCtrlDispatcherX not behaving correctly when nor tun as service [#1246](https://github.com/sandboxie-plus/Sandboxie/issues/1246) ### Removed - removed obsolete /nosbiectrl switch [#3391](https://github.com/sandboxie-plus/Sandboxie/issues/3391) diff --git a/Sandboxie/apps/com/common.h b/Sandboxie/apps/com/common.h index dbdf513b..4663d014 100644 --- a/Sandboxie/apps/com/common.h +++ b/Sandboxie/apps/com/common.h @@ -1,5 +1,6 @@ /* * Copyright 2004-2020 Sandboxie Holdings, LLC + * Copyright 2021-2023 David Xanatos, xanasoft.com * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -755,6 +756,8 @@ BOOL Hook_Service_Control_Manager(void) BOOL Service_Start_ServiceMain(WCHAR *SvcName, const WCHAR *SvcDllName, const UCHAR *SvcProcName, BOOL UseMyStartServiceCtrlDispatcher) { + static const WCHAR *ServiceName_EnvVar = + L"00000000_" SBIE L"_SERVICE_NAME"; HMODULE dll; LPSERVICE_MAIN_FUNCTION ServiceMain; ULONG table_len; @@ -785,7 +788,7 @@ BOOL Service_Start_ServiceMain(WCHAR *SvcName, const WCHAR *SvcDllName, const UC table[0].lpServiceName = SvcName; table[0].lpServiceProc = ServiceMain; - + SetEnvironmentVariable(ServiceName_EnvVar, SvcName); if (UseMyStartServiceCtrlDispatcher) { PROCESS_DATA *myData; diff --git a/Sandboxie/core/dll/scm_create.c b/Sandboxie/core/dll/scm_create.c index 182615c0..601c8c6d 100644 --- a/Sandboxie/core/dll/scm_create.c +++ b/Sandboxie/core/dll/scm_create.c @@ -1,6 +1,6 @@ /* * Copyright 2004-2020 Sandboxie Holdings, LLC - * Copyright 2020-2021 David Xanatos, xanasoft.com + * Copyright 2020-2023 David Xanatos, xanasoft.com * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -1212,34 +1212,40 @@ _FX BOOL Scm_StartServiceCtrlDispatcherX( // run is not necessarily the first entry in the table. // + if (wcscmp(ServiceName, L"*") == 0) { + + BOOLEAN TooMany; + + if (IsUnicode) { + + SERVICE_TABLE_ENTRYW *svc = (SERVICE_TABLE_ENTRYW *)ServiceTable; + ServiceName = svc->lpServiceName; + TooMany = (svc[1].lpServiceName || svc[1].lpServiceProc); + + } else { + + SERVICE_TABLE_ENTRYA *svc = (SERVICE_TABLE_ENTRYA *)ServiceTable; + + ANSI_STRING ansi; + RtlInitString(&ansi, svc->lpServiceName); + RtlAnsiStringToUnicodeString(&uni, &ansi, TRUE); + ServiceName = uni.Buffer; + + TooMany = (svc[1].lpServiceName || svc[1].lpServiceProc); + } + + if (TooMany) { + + SbieApi_Log(2205, L"StartServiceCtrlDispatcher"); + //SetLastError(ERROR_INVALID_PARAMETER); + //return FALSE; + } + } + } else { - BOOLEAN TooMany; - - if (IsUnicode) { - - SERVICE_TABLE_ENTRYW *svc = (SERVICE_TABLE_ENTRYW *)ServiceTable; - ServiceName = svc->lpServiceName; - TooMany = (svc[1].lpServiceName || svc[1].lpServiceProc); - - } else { - - SERVICE_TABLE_ENTRYA *svc = (SERVICE_TABLE_ENTRYA *)ServiceTable; - - ANSI_STRING ansi; - RtlInitString(&ansi, svc->lpServiceName); - RtlAnsiStringToUnicodeString(&uni, &ansi, TRUE); - ServiceName = uni.Buffer; - - TooMany = (svc[1].lpServiceName || svc[1].lpServiceProc); - } - - if (TooMany) { - - SbieApi_Log(2205, L"StartServiceCtrlDispatcher"); - //SetLastError(ERROR_INVALID_PARAMETER); - //return FALSE; - } + SetLastError(ERROR_FAILED_SERVICE_CONTROLLER_CONNECT); + return FALSE; } WCHAR text[130]; diff --git a/Sandboxie/core/svc/serviceserver2.cpp b/Sandboxie/core/svc/serviceserver2.cpp index 4181e78d..79fc0d47 100644 --- a/Sandboxie/core/svc/serviceserver2.cpp +++ b/Sandboxie/core/svc/serviceserver2.cpp @@ -1,6 +1,6 @@ /* * Copyright 2004-2020 Sandboxie Holdings, LLC - * Copyright 2020-2021 David Xanatos, xanasoft.com + * Copyright 2020-2023 David Xanatos, xanasoft.com * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -334,7 +334,7 @@ ULONG ServiceServer::RunHandler2( if (ok) { errlvl = 0x21; ExePath = BuildPathForStartExe(idProcess, devmap, - (type & SERVICE_WIN32_OWN_PROCESS) ? svcname : NULL, + svcname ? (type & SERVICE_WIN32_OWN_PROCESS) ? svcname : L"*" : NULL, path, NULL); if (! ExePath) { ok = FALSE;