From 9fcfc4054e0c525f1188ab2380cf1ce686bc314d Mon Sep 17 00:00:00 2001 From: DavidXanatos Date: Mon, 25 Oct 2021 18:22:45 +0200 Subject: [PATCH] fixes --- Sandboxie/core/dll/config.c | 34 ++++++++-------------------- Sandboxie/core/dll/guititle.c | 2 +- Sandboxie/core/dll/rpcrt.c | 4 ++-- Sandboxie/core/dll/sbiedll.h | 9 ++++---- Sandboxie/core/dll/userenv.c | 2 +- Sandboxie/core/svc/iphlpserver.cpp | 2 +- Sandboxie/core/svc/sbieiniserver.cpp | 17 +++++++++----- 7 files changed, 29 insertions(+), 41 deletions(-) diff --git a/Sandboxie/core/dll/config.c b/Sandboxie/core/dll/config.c index 5f9f0bca..663022bb 100644 --- a/Sandboxie/core/dll/config.c +++ b/Sandboxie/core/dll/config.c @@ -277,20 +277,20 @@ BOOLEAN Config_String2Bool(const WCHAR* value, BOOLEAN defval) _FX BOOLEAN Config_GetSettingsForImageName_bool(const WCHAR* setting, BOOLEAN defval) { - return SbieDll_GetSettingsForImageName_bool(NULL, Dll_ImageName, setting, defval); + return SbieDll_GetSettingsForName_bool(NULL, Dll_ImageName, setting, defval); } //--------------------------------------------------------------------------- -// SbieDll_GetSettingsForImageName_bool +// SbieDll_GetSettingsForName_bool //--------------------------------------------------------------------------- -_FX BOOLEAN SbieDll_GetSettingsForImageName_bool( - const WCHAR* boxname, const WCHAR* image_name, const WCHAR* setting, BOOLEAN defval) +_FX BOOLEAN SbieDll_GetSettingsForName_bool( + const WCHAR* boxname, const WCHAR* name, const WCHAR* setting, BOOLEAN defval) { WCHAR value[16]; - SbieDll_GetSettingsForImageName(boxname, image_name, setting, value, sizeof(value), NULL); + SbieDll_GetSettingsForName(boxname, name, setting, value, sizeof(value), NULL); return Config_String2Bool(value, defval); } @@ -329,12 +329,12 @@ _FX BOOLEAN Config_InitPatternList(const WCHAR* setting, LIST* list) //--------------------------------------------------------------------------- -// SbieDll_GetSettingsForImageName +// SbieDll_GetSettingsForName //--------------------------------------------------------------------------- -_FX BOOLEAN SbieDll_GetSettingsForImageName( - const WCHAR* boxname, const WCHAR* image_name, const WCHAR* setting, WCHAR* value, ULONG value_size, const WCHAR* deftext) +_FX BOOLEAN SbieDll_GetSettingsForName( + const WCHAR* boxname, const WCHAR* name, const WCHAR* setting, WCHAR* value, ULONG value_size, const WCHAR* deftext) { WCHAR conf_buf[2048]; ULONG found_level = -1; @@ -349,7 +349,7 @@ _FX BOOLEAN SbieDll_GetSettingsForImageName( ++index; ULONG level = -1; - WCHAR* found_value = Config_MatchImageAndGetValue(conf_buf, image_name, &level); + WCHAR* found_value = Config_MatchImageAndGetValue(conf_buf, name, &level); if (!found_value || level > found_level) continue; //if (found_value) { @@ -568,19 +568,3 @@ BOOLEAN SbieDll_CheckStringInList(const WCHAR* string, const WCHAR* boxname, con } return FALSE; } - - -//--------------------------------------------------------------------------- -// SbieDll_GetBoolForStringFromList -//--------------------------------------------------------------------------- - - -BOOLEAN SbieDll_GetBoolForStringFromList(const WCHAR* string, const WCHAR* boxname, const WCHAR* setting, BOOLEAN def) -{ - WCHAR buf[32]; - if (SbieDll_GetStringForStringList(string, boxname, setting, buf, sizeof(buf))) - return Config_String2Bool(buf, def); - return def; -} - - diff --git a/Sandboxie/core/dll/guititle.c b/Sandboxie/core/dll/guititle.c index 098e6578..56df53be 100644 --- a/Sandboxie/core/dll/guititle.c +++ b/Sandboxie/core/dll/guititle.c @@ -68,7 +68,7 @@ _FX BOOLEAN Gui_InitTitle(void) // initialize title variables // - SbieDll_GetStringForStringList(Dll_ImageName, NULL, L"BoxNameTitle", buf, sizeof(buf)); + SbieDll_GetSettingsForName(NULL, Dll_ImageName, L"BoxNameTitle", buf, sizeof(buf), NULL); if (*buf == L'y' || *buf == L'Y') { // indicator + box name UNICODE_STRING uni; diff --git a/Sandboxie/core/dll/rpcrt.c b/Sandboxie/core/dll/rpcrt.c index aeb6bb9c..3b7b15d6 100644 --- a/Sandboxie/core/dll/rpcrt.c +++ b/Sandboxie/core/dll/rpcrt.c @@ -709,7 +709,7 @@ _FX ULONG RpcRt_RpcBindingFromStringBindingW( if (CallingModule) { // get the DLL specific preset if present - use_RpcMgmtSetComTimeout = SbieDll_GetBoolForStringFromList(CallingModule, NULL, L"UseRpcMgmtSetComTimeout", use_RpcMgmtSetComTimeout); + use_RpcMgmtSetComTimeout = SbieDll_GetSettingsForName_bool(NULL, CallingModule, L"UseRpcMgmtSetComTimeout", use_RpcMgmtSetComTimeout); // // check for a "RpcPortBinding" entry @@ -834,7 +834,7 @@ _FX RPC_STATUS RpcRt_RpcBindingCreateW( if (CallingModule) { // get the DLL specific preset if present - use_RpcMgmtSetComTimeout = SbieDll_GetBoolForStringFromList(CallingModule, NULL, L"UseRpcMgmtSetComTimeout", use_RpcMgmtSetComTimeout); + use_RpcMgmtSetComTimeout = SbieDll_GetSettingsForName_bool(NULL, CallingModule, L"UseRpcMgmtSetComTimeout", use_RpcMgmtSetComTimeout); // // check for a "RpcPortBinding" entry diff --git a/Sandboxie/core/dll/sbiedll.h b/Sandboxie/core/dll/sbiedll.h index 3c5a4854..776e9f55 100644 --- a/Sandboxie/core/dll/sbiedll.h +++ b/Sandboxie/core/dll/sbiedll.h @@ -206,13 +206,12 @@ SBIEDLL_EXPORT BOOLEAN SbieDll_MatchImage(const WCHAR* pat_str, const WCHAR* te SBIEDLL_EXPORT BOOLEAN SbieDll_GetStringForStringList(const WCHAR* string, const WCHAR* boxname, const WCHAR* setting, WCHAR* value, ULONG value_size); SBIEDLL_EXPORT BOOLEAN SbieDll_CheckStringInList(const WCHAR* string, const WCHAR* boxname, const WCHAR* setting); -SBIEDLL_EXPORT BOOLEAN SbieDll_GetBoolForStringFromList(const WCHAR* string, const WCHAR* boxname, const WCHAR* setting, BOOLEAN def); -SBIEDLL_EXPORT BOOLEAN SbieDll_GetSettingsForImageName( - const WCHAR* boxname, const WCHAR* image_name, const WCHAR* setting, WCHAR* value, ULONG value_size, const WCHAR* deftext); +SBIEDLL_EXPORT BOOLEAN SbieDll_GetSettingsForName( + const WCHAR* boxname, const WCHAR* name, const WCHAR* setting, WCHAR* value, ULONG value_size, const WCHAR* deftext); -SBIEDLL_EXPORT BOOLEAN SbieDll_GetSettingsForImageName_bool( - const WCHAR* boxname, const WCHAR* image_name, const WCHAR* setting, BOOLEAN defval); +SBIEDLL_EXPORT BOOLEAN SbieDll_GetSettingsForName_bool( + const WCHAR* boxname, const WCHAR* name, const WCHAR* setting, BOOLEAN defval); SBIEDLL_EXPORT BOOLEAN SbieDll_GetBorderColor(const WCHAR* box_name, COLORREF* color, BOOL* title, int* width); diff --git a/Sandboxie/core/dll/userenv.c b/Sandboxie/core/dll/userenv.c index a1d4cf10..4b80e74f 100644 --- a/Sandboxie/core/dll/userenv.c +++ b/Sandboxie/core/dll/userenv.c @@ -81,7 +81,7 @@ _FX BOOLEAN UserEnv_InitVer(HMODULE module) void* GetVersionExA; WCHAR str[32]; - if (SbieDll_GetSettingsForImageName(NULL, Dll_ImageName, L"OverrideOsBuild", str, sizeof(str), NULL)) + if (SbieDll_GetSettingsForName(NULL, Dll_ImageName, L"OverrideOsBuild", str, sizeof(str), NULL)) UserEnv_dwBuildNumber = _wtoi(str); if (UserEnv_dwBuildNumber == 0 && Dll_OsBuild < 9600) diff --git a/Sandboxie/core/svc/iphlpserver.cpp b/Sandboxie/core/svc/iphlpserver.cpp index 1c04bf42..bdf3872c 100644 --- a/Sandboxie/core/svc/iphlpserver.cpp +++ b/Sandboxie/core/svc/iphlpserver.cpp @@ -192,7 +192,7 @@ MSG_HEADER *IpHlpServer::CreateHandler(MSG_HEADER *msg, HANDLE idProcess) if (!NT_SUCCESS(SbieApi_QueryProcess(idProcess, boxname, exename, NULL, NULL))) return SHORT_REPLY(E_FAIL); - if (!SbieDll_GetSettingsForImageName_bool(boxname, exename, L"AllowNetworkAccess", TRUE)) + if (!SbieDll_GetSettingsForName_bool(boxname, exename, L"AllowNetworkAccess", TRUE)) return SHORT_REPLY(ERROR_ACCESS_DENIED); if (0 != SbieApi_CheckInternetAccess( diff --git a/Sandboxie/core/svc/sbieiniserver.cpp b/Sandboxie/core/svc/sbieiniserver.cpp index f3ef054b..baecd155 100644 --- a/Sandboxie/core/svc/sbieiniserver.cpp +++ b/Sandboxie/core/svc/sbieiniserver.cpp @@ -1004,8 +1004,8 @@ MSG_HEADER *SbieIniServer::GetSetting(MSG_HEADER *msg) } else if (_wcsicmp(I->Name.c_str(), req->setting) == 0) { if(!iniData.empty()) // string list - iniData.push_back(L'\0'); - //iniData.push_back(L'\n'); + //iniData.push_back(L'\0'); + iniData.push_back(L'\n'); iniData += I->Value; } } @@ -1099,7 +1099,7 @@ ULONG SbieIniServer::SetSetting(MSG_HEADER* msg) if (have_value) { - for (WCHAR* value = req->value; req->value_len > 0 && *value != L'\0';) + /*for (WCHAR* value = req->value; req->value_len > 0 && *value != L'\0';) { pSection->Entries.insert(pos, SIniEntry{ req->setting, value }); @@ -1109,8 +1109,13 @@ ULONG SbieIniServer::SetSetting(MSG_HEADER* msg) req->value_len -= 1; value += len + 1; } - } - /*for (WCHAR* value = req->value; *value != L'\0'; ) + }*/ + + // + // Note: SbieCtrl passes a \n separated list to replace all values in a string list + // + + for (WCHAR* value = req->value; *value != L'\0'; ) { ULONG cpylen, skiplen; WCHAR *cr = wcschr(value, L'\n'); @@ -1127,7 +1132,7 @@ ULONG SbieIniServer::SetSetting(MSG_HEADER* msg) pSection->Entries.insert(pos, SIniEntry{ req->setting, std::wstring(value, cpylen) }); value += skiplen; - }*/ + } } return STATUS_SUCCESS;