From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../nsis/Contrib/ServicesHelper/Services.cpp | 241 +++++++++++++++++++++ .../nsis/Contrib/ServicesHelper/ServicesHelper.dsp | 115 ++++++++++ .../nsis/Contrib/ServicesHelper/ServicesHelper.dsw | 29 +++ .../nsis/Contrib/ServicesHelper/ServicesHelper.sln | 20 ++ .../Contrib/ServicesHelper/ServicesHelper.vcproj | 212 ++++++++++++++++++ 5 files changed, 617 insertions(+) create mode 100644 other-licenses/nsis/Contrib/ServicesHelper/Services.cpp create mode 100644 other-licenses/nsis/Contrib/ServicesHelper/ServicesHelper.dsp create mode 100644 other-licenses/nsis/Contrib/ServicesHelper/ServicesHelper.dsw create mode 100644 other-licenses/nsis/Contrib/ServicesHelper/ServicesHelper.sln create mode 100644 other-licenses/nsis/Contrib/ServicesHelper/ServicesHelper.vcproj (limited to 'other-licenses/nsis/Contrib/ServicesHelper') diff --git a/other-licenses/nsis/Contrib/ServicesHelper/Services.cpp b/other-licenses/nsis/Contrib/ServicesHelper/Services.cpp new file mode 100644 index 0000000000..5c3d2fe59f --- /dev/null +++ b/other-licenses/nsis/Contrib/ServicesHelper/Services.cpp @@ -0,0 +1,241 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include +#include "../../../../toolkit/mozapps/update/common/pathhash.h" + +#pragma comment(lib, "advapi32.lib") + +typedef struct _stack_t { + struct _stack_t *next; + TCHAR text[MAX_PATH]; +} stack_t; + +int popstring(stack_t **stacktop, LPTSTR str, int len); +void pushstring(stack_t **stacktop, LPCTSTR str, int len); + +/** + * Determines if the specified service exists or not + * + * @param serviceName The name of the service to check + * @param exists Whether or not the service exists + * @return TRUE if there were no errors + */ +static BOOL +IsServiceInstalled(LPCWSTR serviceName, BOOL &exists) +{ + exists = FALSE; + + // Get a handle to the local computer SCM database with full access rights. + SC_HANDLE serviceManager = OpenSCManager(NULL, NULL, + SC_MANAGER_ENUMERATE_SERVICE); + if (!serviceManager) { + return FALSE; + } + + SC_HANDLE serviceHandle = OpenServiceW(serviceManager, + serviceName, + SERVICE_QUERY_CONFIG); + if (!serviceHandle && GetLastError() != ERROR_SERVICE_DOES_NOT_EXIST) { + CloseServiceHandle(serviceManager); + return FALSE; + } + + if (serviceHandle) { + CloseServiceHandle(serviceHandle); + exists = TRUE; + } + + CloseServiceHandle(serviceManager); + return TRUE; +} + +/** + * Determines if the specified service is installed or not + * + * @param stacktop A pointer to the top of the stack + * @param variables A pointer to the NSIS variables + * @return 0 if the service does not exist + * 1 if the service does exist + * -1 if there was an error. + */ +extern "C" void __declspec(dllexport) +IsInstalled(HWND hwndParent, int string_size, + TCHAR *variables, stack_t **stacktop, void *extra) +{ + TCHAR tmp[MAX_PATH] = { L'\0' }; + WCHAR serviceName[MAX_PATH] = { '\0' }; + popstring(stacktop, tmp, MAX_PATH); + +#if !defined(UNICODE) + MultiByteToWideChar(CP_ACP, 0, tmp, -1, serviceName, MAX_PATH); +#else + wcscpy(serviceName, tmp); +#endif + + BOOL serviceInstalled; + if (!IsServiceInstalled(serviceName, serviceInstalled)) { + pushstring(stacktop, TEXT("-1"), 3); + } else { + pushstring(stacktop, serviceInstalled ? TEXT("1") : TEXT("0"), 2); + } +} + +/** + * Stops the specified service. + * + * @param serviceName The name of the service to stop + * @return TRUE if the operation was successful + */ +static BOOL +StopService(LPCWSTR serviceName) +{ + // Get a handle to the local computer SCM database with full access rights. + SC_HANDLE serviceManager = OpenSCManager(NULL, NULL, + SC_MANAGER_ENUMERATE_SERVICE); + if (!serviceManager) { + return FALSE; + } + + SC_HANDLE serviceHandle = OpenServiceW(serviceManager, + serviceName, + SERVICE_STOP); + if (!serviceHandle) { + CloseServiceHandle(serviceManager); + return FALSE; + } + + //Stop the service so it deletes faster and so the uninstaller + // can actually delete its EXE. + DWORD totalWaitTime = 0; + SERVICE_STATUS status; + static const int maxWaitTime = 1000 * 60; // Never wait more than a minute + BOOL stopped = FALSE; + if (ControlService(serviceHandle, SERVICE_CONTROL_STOP, &status)) { + do { + Sleep(status.dwWaitHint); + // + 10 milliseconds to make sure we always approach maxWaitTime + totalWaitTime += (status.dwWaitHint + 10); + if (status.dwCurrentState == SERVICE_STOPPED) { + stopped = true; + break; + } else if (totalWaitTime > maxWaitTime) { + break; + } + } while (QueryServiceStatus(serviceHandle, &status)); + } + + CloseServiceHandle(serviceHandle); + CloseServiceHandle(serviceManager); + return stopped; +} + +/** + * Stops the specified service + * + * @param stacktop A pointer to the top of the stack + * @param variables A pointer to the NSIS variables + * @return 1 if the service was stopped, 0 on error + */ +extern "C" void __declspec(dllexport) +Stop(HWND hwndParent, int string_size, + TCHAR *variables, stack_t **stacktop, void *extra) +{ + TCHAR tmp[MAX_PATH] = { L'\0' }; + WCHAR serviceName[MAX_PATH] = { '\0' }; + + popstring(stacktop, tmp, MAX_PATH); + +#if !defined(UNICODE) + MultiByteToWideChar(CP_ACP, 0, tmp, -1, serviceName, MAX_PATH); +#else + wcscpy(serviceName, tmp); +#endif + + if (StopService(serviceName)) { + pushstring(stacktop, TEXT("1"), 2); + } else { + pushstring(stacktop, TEXT("0"), 2); + } +} + +/** + * Determines a unique registry path from a file or directory path + * + * @param stacktop A pointer to the top of the stack + * @param variables A pointer to the NSIS variables + * @return The unique registry path or an empty string on error + */ +extern "C" void __declspec(dllexport) +PathToUniqueRegistryPath(HWND hwndParent, int string_size, + TCHAR *variables, stack_t **stacktop, + void *extra) +{ + TCHAR tmp[MAX_PATH] = { L'\0' }; + WCHAR installBasePath[MAX_PATH] = { '\0' }; + popstring(stacktop, tmp, MAX_PATH); + +#if !defined(UNICODE) + MultiByteToWideChar(CP_ACP, 0, tmp, -1, installBasePath, MAX_PATH); +#else + wcscpy(installBasePath, tmp); +#endif + + WCHAR registryPath[MAX_PATH + 1] = { '\0' }; + if (CalculateRegistryPathFromFilePath(installBasePath, registryPath)) { + pushstring(stacktop, registryPath, wcslen(registryPath) + 1); + } else { + pushstring(stacktop, TEXT(""), 1); + } +} + +BOOL WINAPI +DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) +{ + return TRUE; +} + +/** + * Removes an element from the top of the NSIS stack + * + * @param stacktop A pointer to the top of the stack + * @param str The string to pop to + * @param len The max length + * @return 0 on success +*/ +int popstring(stack_t **stacktop, TCHAR *str, int len) +{ + // Removes the element from the top of the stack and puts it in the buffer + stack_t *th; + if (!stacktop || !*stacktop) { + return 1; + } + + th = (*stacktop); + lstrcpyn(str,th->text, len); + *stacktop = th->next; + GlobalFree((HGLOBAL)th); + return 0; +} + +/** + * Adds an element to the top of the NSIS stack + * + * @param stacktop A pointer to the top of the stack + * @param str The string to push on the stack + * @param len The length of the string to push on the stack + * @return 0 on success +*/ +void pushstring(stack_t **stacktop, const TCHAR *str, int len) +{ + stack_t *th; + if (!stacktop) { + return; + } + + th = (stack_t*)GlobalAlloc(GPTR, sizeof(stack_t) + len); + lstrcpyn(th->text, str, len); + th->next = *stacktop; + *stacktop = th; +} diff --git a/other-licenses/nsis/Contrib/ServicesHelper/ServicesHelper.dsp b/other-licenses/nsis/Contrib/ServicesHelper/ServicesHelper.dsp new file mode 100644 index 0000000000..8c9577c516 --- /dev/null +++ b/other-licenses/nsis/Contrib/ServicesHelper/ServicesHelper.dsp @@ -0,0 +1,115 @@ +# Microsoft Developer Studio Project File - Name="ServicesHelper" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=ServicesHelper - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "ServicesHelper.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "ServicesHelper.mak" CFG="ServicesHelper - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "ServicesHelper - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "ServicesHelper - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "ServicesHelper - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXDLL_EXPORTS" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_UNICODE" /D "UNICODE" /D "_USRDLL" /D "EXDLL_EXPORTS" /D _WIN32_WINNT=0x0400 /FR /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib MSVCRT.LIB /nologo /entry:"DllMain" /dll /machine:I386 /nodefaultlib /out:"../../Plugins/ServicesHelper.dll" /opt:nowin98 +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "ServicesHelper - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXDLL_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXDLL_EXPORTS" /YX /FD /GZ /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "ServicesHelper - Win32 Release" +# Name "ServicesHelper - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=\toolkit\mozapps\update\common\pathhash.cpp +# End Source File +# Begin Source File + +SOURCE=\toolkit\mozapps\update\common\pathhash.h +# End Source File +# Begin Source File + +SOURCE=.\Services.cpp +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# End Target +# End Project diff --git a/other-licenses/nsis/Contrib/ServicesHelper/ServicesHelper.dsw b/other-licenses/nsis/Contrib/ServicesHelper/ServicesHelper.dsw new file mode 100644 index 0000000000..c144217016 --- /dev/null +++ b/other-licenses/nsis/Contrib/ServicesHelper/ServicesHelper.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "ServicesHelper"=.\ServicesHelper.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/other-licenses/nsis/Contrib/ServicesHelper/ServicesHelper.sln b/other-licenses/nsis/Contrib/ServicesHelper/ServicesHelper.sln new file mode 100644 index 0000000000..348a8e3003 --- /dev/null +++ b/other-licenses/nsis/Contrib/ServicesHelper/ServicesHelper.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ServicesHelper", "ServicesHelper.vcproj", "{A0D0AD52-1D8B-402E-92EF-81AE0C320BD7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A0D0AD52-1D8B-402E-92EF-81AE0C320BD7}.Debug|Win32.ActiveCfg = Debug|Win32 + {A0D0AD52-1D8B-402E-92EF-81AE0C320BD7}.Debug|Win32.Build.0 = Debug|Win32 + {A0D0AD52-1D8B-402E-92EF-81AE0C320BD7}.Release|Win32.ActiveCfg = Release|Win32 + {A0D0AD52-1D8B-402E-92EF-81AE0C320BD7}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/other-licenses/nsis/Contrib/ServicesHelper/ServicesHelper.vcproj b/other-licenses/nsis/Contrib/ServicesHelper/ServicesHelper.vcproj new file mode 100644 index 0000000000..637fa5110f --- /dev/null +++ b/other-licenses/nsis/Contrib/ServicesHelper/ServicesHelper.vcproj @@ -0,0 +1,212 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3