--- /dev/null
+/*
+ * PROJECT: ReactOS W32Time Service
+ * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
+ * PURPOSE: Service Registration
+ * COPYRIGHT: Copyright 2021 Eric Kohl <ekohl@reactos.org>
+ */
+
+#include "w32time.h"
+#include <debug.h>
+#include <strsafe.h>
+
+#include "resource.h"
+
+static
+PWSTR
+ReadString(
+ _In_ UINT uID)
+{
+ HINSTANCE hInstance;
+ int nLength;
+ PWSTR pszString, pszPtr;
+
+ hInstance = GetModuleHandleW(L"w32time");
+ if (hInstance == NULL)
+ return NULL;
+
+ nLength = LoadStringW(hInstance, uID, (LPWSTR)&pszPtr, 0);
+ if (nLength == 0)
+ return NULL;
+
+ pszString = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (nLength + 1) * sizeof(WCHAR));
+ if (pszString == NULL)
+ return NULL;
+
+ wcsncpy(pszString, pszPtr, nLength);
+
+ return pszString;
+}
+
+
+static
+HRESULT
+RegisterService(VOID)
+{
+ SC_HANDLE hServiceManager = NULL;
+ SC_HANDLE hService = NULL;
+ HKEY hKey = NULL;
+ PWSTR pszValue;
+ PWSTR pszDisplayName = NULL, pszDescription = NULL;
+ DWORD dwDisposition, dwError;
+ SERVICE_DESCRIPTIONW ServiceDescription;
+ HRESULT hresult = S_OK;
+
+ DPRINT("RegisterService()\n");
+
+ hServiceManager = OpenSCManagerW(NULL, NULL, SC_MANAGER_CREATE_SERVICE);
+ if (hServiceManager == NULL)
+ {
+ DPRINT1("OpenSCManager() failed!\n");
+ hresult = E_FAIL;
+ goto done;
+ }
+
+ pszDisplayName = ReadString(IDS_DISPLAYNAME);
+ if (pszDisplayName == NULL)
+ {
+ DPRINT1("ReadString(IDS_DISPLAYNAME) failed!\n");
+ hresult = E_FAIL;
+ goto done;
+ }
+
+ pszDescription = ReadString(IDS_DESCRIPTION);
+ if (pszDescription == NULL)
+ {
+ DPRINT1("ReadString(IDS_DESCRIPTION) failed!\n");
+ hresult = E_FAIL;
+ goto done;
+ }
+
+ hService = CreateServiceW(hServiceManager,
+ L"W32Time",
+ pszDisplayName,
+ GENERIC_WRITE,
+ SERVICE_WIN32_SHARE_PROCESS,
+ SERVICE_AUTO_START,
+ SERVICE_ERROR_NORMAL,
+ L"%SystemRoot%\\system32\\svchost.exe -k netsvcs",
+ L"Time", NULL, NULL, L"LocalSystem", NULL);
+ if (hService == NULL)
+ {
+ DPRINT1("CreateService() failed!\n");
+ hresult = E_FAIL;
+ goto done;
+ }
+
+ ServiceDescription.lpDescription = pszDescription;
+ if (ChangeServiceConfig2W(hService,
+ SERVICE_CONFIG_DESCRIPTION,
+ &ServiceDescription) == FALSE)
+ {
+ DPRINT1("ChangeServiceConfig2() failed!\n");
+ hresult = E_FAIL;
+ goto done;
+ }
+
+ dwError = RegCreateKeyExW(HKEY_LOCAL_MACHINE,
+ L"System\\CurrentControlSet\\Services\\W32Time\\Parameters",
+ 0,
+ NULL,
+ REG_OPTION_NON_VOLATILE,
+ KEY_WRITE,
+ NULL,
+ &hKey,
+ &dwDisposition);
+ if (dwError != ERROR_SUCCESS)
+ {
+ DPRINT1("RegCreateKeyEx() failed!\n");
+ hresult = E_FAIL;
+ goto done;
+ }
+
+ pszValue = L"%SystemRoot%\\system32\\w32time.dll";
+ dwError = RegSetValueExW(hKey,
+ L"ServiceDll",
+ 0,
+ REG_EXPAND_SZ,
+ (LPBYTE)pszValue,
+ (wcslen(pszValue) + 1) * sizeof(WCHAR));
+ if (dwError != ERROR_SUCCESS)
+ {
+ DPRINT1("RegSetValueEx() failed!\n");
+ hresult = E_FAIL;
+ goto done;
+ }
+
+ pszValue = L"SvchostEntry_W32Time";
+ dwError = RegSetValueExW(hKey,
+ L"ServiceMain",
+ 0,
+ REG_SZ,
+ (LPBYTE)pszValue,
+ (wcslen(pszValue) + 1) * sizeof(WCHAR));
+ if (dwError != ERROR_SUCCESS)
+ {
+ DPRINT1("RegSetValueEx() failed!\n");
+ hresult = E_FAIL;
+ goto done;
+ }
+
+done:
+ if (hKey)
+ RegCloseKey(hKey);
+
+ if (hService)
+ CloseServiceHandle(hService);
+
+ if (hServiceManager)
+ CloseServiceHandle(hServiceManager);
+
+ if (pszDescription)
+ HeapFree(GetProcessHeap(), 0, pszDescription);
+
+ if (pszDisplayName)
+ HeapFree(GetProcessHeap(), 0, pszDisplayName);
+
+ return hresult;
+}
+
+
+static
+HRESULT
+SetParametersValues(VOID)
+{
+ HKEY hKey = NULL;
+ PWSTR pszValue;
+ DWORD dwDisposition, dwError;
+ HRESULT hresult = S_OK;
+
+ dwError = RegCreateKeyExW(HKEY_LOCAL_MACHINE,
+ L"System\\CurrentControlSet\\Services\\W32Time\\Parameters",
+ 0,
+ NULL,
+ REG_OPTION_NON_VOLATILE,
+ KEY_WRITE,
+ NULL,
+ &hKey,
+ &dwDisposition);
+ if (dwError != ERROR_SUCCESS)
+ {
+ DPRINT1("RegCreateKeyEx() failed!\n");
+ goto done;
+ }
+
+ pszValue = L"NTP";
+ dwError = RegSetValueExW(hKey,
+ L"Type",
+ 0,
+ REG_SZ,
+ (LPBYTE)pszValue,
+ (wcslen(pszValue) + 1) * sizeof(WCHAR));
+ if (dwError != ERROR_SUCCESS)
+ {
+ DPRINT1("RegSetValueEx() failed!\n");
+ goto done;
+ }
+
+done:
+ if (hKey)
+ RegCloseKey(hKey);
+
+ return hresult;
+}
+
+
+static
+HRESULT
+SetNtpClientValues(VOID)
+{
+ HKEY hKey = NULL;
+ DWORD dwValue;
+ DWORD dwDisposition, dwError;
+ HRESULT hresult = S_OK;
+
+ dwError = RegCreateKeyExW(HKEY_LOCAL_MACHINE,
+ L"System\\CurrentControlSet\\Services\\W32Time\\TimeProviders\\NtpClient",
+ 0,
+ NULL,
+ REG_OPTION_NON_VOLATILE,
+ KEY_WRITE,
+ NULL,
+ &hKey,
+ &dwDisposition);
+ if (dwError != ERROR_SUCCESS)
+ {
+ DPRINT1("RegCreateKeyEx() failed!\n");
+ goto done;
+ }
+
+ dwValue = 0x00093a80;
+ dwError = RegSetValueExW(hKey,
+ L"SpecialPollInterval",
+ 0,
+ REG_DWORD,
+ (LPBYTE)&dwValue,
+ sizeof(dwValue));
+ if (dwError != ERROR_SUCCESS)
+ {
+ DPRINT1("RegSetValueEx() failed!\n");
+ goto done;
+ }
+
+done:
+ if (hKey)
+ RegCloseKey(hKey);
+
+ return hresult;
+}
+
+
+HRESULT
+WINAPI
+DllRegisterServer(VOID)
+{
+ HRESULT hresult;
+
+ hresult = RegisterService();
+ if (FAILED(hresult))
+ return hresult;
+
+ hresult = SetParametersValues();
+ if (FAILED(hresult))
+ return hresult;
+
+ hresult = SetNtpClientValues();
+
+ return hresult;
+}
+
+
+HRESULT
+WINAPI
+DllUnregisterServer(VOID)
+{
+ DPRINT1("DllUnregisterServer()\n");
+ return S_OK;
+}
HKLM,"SYSTEM\CurrentControlSet\Services\WlanSvc","Start",0x00010001,0x00000002
HKLM,"SYSTEM\CurrentControlSet\Services\WlanSvc","Type",0x00010001,0x00000110
-; W32TIME service
-HKLM,"SYSTEM\CurrentControlSet\Services\W32Time","DisplayName",0x00000000,%W32TIME_SERVICE%
-HKLM,"SYSTEM\CurrentControlSet\Services\W32Time","Description",0x00000000,%W32TIME_SERVICE_DESCRIPTION%
-HKLM,"SYSTEM\CurrentControlSet\Services\W32Time","ErrorControl",0x00010001,0x00000001
-HKLM,"SYSTEM\CurrentControlSet\Services\W32Time","Group",0x00000000,"Time"
-HKLM,"SYSTEM\CurrentControlSet\Services\W32Time","ImagePath",0x00020000,"%SystemRoot%\system32\svchost.exe -k netsvcs"
-HKLM,"SYSTEM\CurrentControlSet\Services\W32Time","ObjectName",0x00000000,"LocalSystem"
-HKLM,"SYSTEM\CurrentControlSet\Services\W32Time","Start",0x00010001,0x00000002
-HKLM,"SYSTEM\CurrentControlSet\Services\W32Time","Type",0x00010001,0x00000020
-HKLM,"SYSTEM\CurrentControlSet\Services\W32Time\Parameters","ServiceDll",0x00020000,"%SystemRoot%\system32\w32time.dll"
-HKLM,"SYSTEM\CurrentControlSet\Services\W32Time\Parameters","ServiceMain",0x00000000,"SvchostEntry_W32Time"
-HKLM,"SYSTEM\CurrentControlSet\Services\W32Time\Parameters","Type",0x00010000,"NTP"
-HKLM,"SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient","SpecialPollInterval",0x00010001,0x00093a80
-
; Simple TCP services
HKLM,"SYSTEM\CurrentControlSet\Services\tcpsvcs","Description",0x00000000,%TCPSVCS_SERVICE_DECRIPTION%
HKLM,"SYSTEM\CurrentControlSet\Services\tcpsvcs","DisplayName",0x00000000,%TCPSVCS_SERVICE%
WLANSVC_SERVICE="WLAN Service"
WLANSVC_SERVICE_DESCRIPTION="WLAN Service"
-W32TIME_SERVICE="Time Service"
-W32TIME_SERVICE_DESCRIPTION="ReactOS Time Service"
-
WORKSTATION_SERVICE="Workstation"
WORKSTATION_SERVICE_DESCRIPTION="Responsible for creating and maintaining network connections to servers."
WLANSVC_SERVICE="Usługa WLAN"
WLANSVC_SERVICE_DESCRIPTION="Usługa WLAN"
-W32TIME_SERVICE="Usługa Czas"
-W32TIME_SERVICE_DESCRIPTION="Usługa Czas systemu ReactOS"
-
WORKSTATION_SERVICE="Stacja robocza"
WORKSTATION_SERVICE_DESCRIPTION="Tworzy i zachowuje połączenia sieciowe klientów z serwerami."
WLANSVC_SERVICE="Servicio de WLAN"
WLANSVC_SERVICE_DESCRIPTION="Servicio de redes inalámbricas WLAN."
-W32TIME_SERVICE="Servicio de hora"
-W32TIME_SERVICE_DESCRIPTION="Servicio de hora para ReactOS"
-
WORKSTATION_SERVICE="Estación de trabajo"
WORKSTATION_SERVICE_DESCRIPTION="Es el responsable de crear y mantener las conexiones de redes LAN a los servidores."
WLANSVC_SERVICE="WLAN Hizmeti"
WLANSVC_SERVICE_DESCRIPTION="WLAN Hizmeti"
-W32TIME_SERVICE="Zaman Hizmeti"
-W32TIME_SERVICE_DESCRIPTION="ReactOS Zaman Hizmeti"
-
WORKSTATION_SERVICE="İş İstasyonu"
WORKSTATION_SERVICE_DESCRIPTION="Sunuculara ağ bağlantılarını oluşturmaktan ve yönetmekten sorumludur."