From acf84c88542626d43e847857e5149c49ea977818 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Tue, 20 Jan 2015 20:57:58 +0000 Subject: [PATCH] [NETCFGX][SYSSETUP] - Move TCP/IP driver setup code from netcfgx to syssetup. - Implement SetupStartService(). This installs the TCPIP driver even if no network adapter is available. CORE-8420 #resolve svn path=/trunk/; revision=66069 --- reactos/dll/win32/netcfgx/netcfgx.c | 108 ------------------- reactos/dll/win32/syssetup/install.c | 131 +++++++++++++++++++++++ reactos/dll/win32/syssetup/syssetup.spec | 2 +- 3 files changed, 132 insertions(+), 109 deletions(-) diff --git a/reactos/dll/win32/netcfgx/netcfgx.c b/reactos/dll/win32/netcfgx/netcfgx.c index 3ae083a5b26..d12879d24a5 100644 --- a/reactos/dll/win32/netcfgx/netcfgx.c +++ b/reactos/dll/win32/netcfgx/netcfgx.c @@ -219,106 +219,6 @@ cleanup: return rc; } -/* Install a section of a .inf file - * Returns TRUE if success, FALSE if failure. Error code can - * be retrieved with GetLastError() - */ -static -BOOL -InstallInfSection( - IN HWND hWnd, - IN LPCWSTR InfFile, - IN LPCWSTR InfSection OPTIONAL, - IN LPCWSTR InfService OPTIONAL) -{ - WCHAR Buffer[MAX_PATH]; - HINF hInf = INVALID_HANDLE_VALUE; - UINT BufferSize; - PVOID Context = NULL; - BOOL ret = FALSE; - - /* Get Windows directory */ - BufferSize = MAX_PATH - 5 - wcslen(InfFile); - if (GetWindowsDirectoryW(Buffer, BufferSize) > BufferSize) - { - /* Function failed */ - SetLastError(ERROR_GEN_FAILURE); - goto cleanup; - } - /* We have enough space to add some information in the buffer */ - if (Buffer[wcslen(Buffer) - 1] != '\\') - wcscat(Buffer, L"\\"); - wcscat(Buffer, L"Inf\\"); - wcscat(Buffer, InfFile); - - /* Install specified section */ - hInf = SetupOpenInfFileW(Buffer, NULL, INF_STYLE_WIN4, NULL); - if (hInf == INVALID_HANDLE_VALUE) - goto cleanup; - - Context = SetupInitDefaultQueueCallback(hWnd); - if (Context == NULL) - goto cleanup; - - ret = TRUE; - if (ret && InfSection) - { - ret = SetupInstallFromInfSectionW( - hWnd, hInf, - InfSection, SPINST_ALL, - NULL, NULL, SP_COPY_NEWER, - SetupDefaultQueueCallbackW, Context, - NULL, NULL); - } - if (ret && InfService) - { - ret = SetupInstallServicesFromInfSectionW( - hInf, InfService, 0); - } - -cleanup: - if (Context) - SetupTermDefaultQueueCallback(Context); - if (hInf != INVALID_HANDLE_VALUE) - SetupCloseInfFile(hInf); - return ret; -} - -/* Add default services for network cards */ -static -DWORD -InstallAdditionalServices( - IN HWND hWnd) -{ - BOOL ret; - UNICODE_STRING TcpipServicePath = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\Tcpip"); - - /* Install TCP/IP protocol */ - ret = InstallInfSection(hWnd, - L"nettcpip.inf", - L"MS_TCPIP.PrimaryInstall", - L"MS_TCPIP.PrimaryInstall.Services"); - if (!ret && GetLastError() != ERROR_FILE_NOT_FOUND) - { - DPRINT("InstallInfSection() failed with error 0x%lx\n", GetLastError()); - return GetLastError(); - } - else if (ret) - { - /* Start the TCP/IP driver */ - ret = NtLoadDriver(&TcpipServicePath); - if (ret) - { - /* This isn't really fatal but we want to warn anyway */ - DPRINT1("NtLoadDriver(TCPIP) failed with NTSTATUS 0x%lx\n", (NTSTATUS)ret); - } - } - - - /* You can add here more clients (SMB...) and services (DHCP server...) */ - - return ERROR_SUCCESS; -} static DWORD @@ -589,14 +489,6 @@ InstallNetDevice( goto cleanup; } - /* Install additionnal services */ - rc = InstallAdditionalServices(NULL); - if (rc != ERROR_SUCCESS) - { - DPRINT("InstallAdditionalServices() failed with error 0x%lx\n", rc); - goto cleanup; - } - rc = ERROR_SUCCESS; cleanup: diff --git a/reactos/dll/win32/syssetup/install.c b/reactos/dll/win32/syssetup/install.c index 1cd35ad250e..cdc216d76ca 100644 --- a/reactos/dll/win32/syssetup/install.c +++ b/reactos/dll/win32/syssetup/install.c @@ -43,6 +43,9 @@ DWORD WINAPI CMP_WaitNoPendingInstallEvents(DWORD dwTimeout); +DWORD WINAPI +SetupStartService(LPCWSTR lpServiceName, BOOL bWait); + /* GLOBALS ******************************************************************/ HINF hSysSetupInf = INVALID_HANDLE_VALUE; @@ -843,6 +846,72 @@ SetSetupType(DWORD dwSetupType) return TRUE; } +/* Install a section of a .inf file + * Returns TRUE if success, FALSE if failure. Error code can + * be retrieved with GetLastError() + */ +static +BOOL +InstallInfSection( + IN HWND hWnd, + IN LPCWSTR InfFile, + IN LPCWSTR InfSection OPTIONAL, + IN LPCWSTR InfService OPTIONAL) +{ + WCHAR Buffer[MAX_PATH]; + HINF hInf = INVALID_HANDLE_VALUE; + UINT BufferSize; + PVOID Context = NULL; + BOOL ret = FALSE; + + /* Get Windows directory */ + BufferSize = MAX_PATH - 5 - wcslen(InfFile); + if (GetWindowsDirectoryW(Buffer, BufferSize) > BufferSize) + { + /* Function failed */ + SetLastError(ERROR_GEN_FAILURE); + goto cleanup; + } + /* We have enough space to add some information in the buffer */ + if (Buffer[wcslen(Buffer) - 1] != '\\') + wcscat(Buffer, L"\\"); + wcscat(Buffer, L"Inf\\"); + wcscat(Buffer, InfFile); + + /* Install specified section */ + hInf = SetupOpenInfFileW(Buffer, NULL, INF_STYLE_WIN4, NULL); + if (hInf == INVALID_HANDLE_VALUE) + goto cleanup; + + Context = SetupInitDefaultQueueCallback(hWnd); + if (Context == NULL) + goto cleanup; + + ret = TRUE; + if (ret && InfSection) + { + ret = SetupInstallFromInfSectionW( + hWnd, hInf, + InfSection, SPINST_ALL, + NULL, NULL, SP_COPY_NEWER, + SetupDefaultQueueCallbackW, Context, + NULL, NULL); + } + if (ret && InfService) + { + ret = SetupInstallServicesFromInfSectionW( + hInf, InfService, 0); + } + +cleanup: + if (Context) + SetupTermDefaultQueueCallback(Context); + if (hInf != INVALID_HANDLE_VALUE) + SetupCloseInfFile(hInf); + return ret; +} + + DWORD WINAPI InstallReactOS(HINSTANCE hInstance) { @@ -851,6 +920,7 @@ InstallReactOS(HINSTANCE hInstance) TOKEN_PRIVILEGES privs; HKEY hKey; HINF hShortcutsInf; + BOOL ret; InitializeSetupActionLog(FALSE); LogItem(SYSSETUP_SEVERITY_INFORMATION, L"Installing ReactOS"); @@ -894,6 +964,22 @@ InstallReactOS(HINSTANCE hInstance) CreateDirectory(szBuffer, NULL); } + /* Hack: Install TCP/IP protocol driver */ + ret = InstallInfSection(NULL, + L"nettcpip.inf", + L"MS_TCPIP.PrimaryInstall", + L"MS_TCPIP.PrimaryInstall.Services"); + if (!ret && GetLastError() != ERROR_FILE_NOT_FOUND) + { + DPRINT("InstallInfSection() failed with error 0x%lx\n", GetLastError()); + } + else + { + /* Start the TCP/IP protocol driver */ + SetupStartService(L"Tcpip", FALSE); + } + + if (!CommonInstall()) return 0; @@ -1039,3 +1125,48 @@ SetupChangeLocale(HWND hWnd, LCID Lcid) { return SetupChangeLocaleEx(hWnd, Lcid, NULL, 0, 0, 0); } + + +DWORD +WINAPI +SetupStartService( + LPCWSTR lpServiceName, + BOOL bWait) +{ + SC_HANDLE hManager = NULL; + SC_HANDLE hService = NULL; + DWORD dwError = ERROR_SUCCESS; + + hManager = OpenSCManagerW(NULL, + NULL, + SC_MANAGER_ALL_ACCESS); + if (hManager == NULL) + { + dwError = GetLastError(); + goto done; + } + + hService = OpenServiceW(hManager, + lpServiceName, + SERVICE_START); + if (hService == NULL) + { + dwError = GetLastError(); + goto done; + } + + if (!StartService(hService, 0, NULL)) + { + dwError = GetLastError(); + goto done; + } + +done: + if (hService != NULL) + CloseServiceHandle(hService); + + if (hManager != NULL) + CloseServiceHandle(hManager); + + return dwError; +} diff --git a/reactos/dll/win32/syssetup/syssetup.spec b/reactos/dll/win32/syssetup/syssetup.spec index e2f4a1d8296..e5d1e049c0b 100644 --- a/reactos/dll/win32/syssetup/syssetup.spec +++ b/reactos/dll/win32/syssetup/syssetup.spec @@ -72,7 +72,7 @@ @ stub SetupSetRegisteredOsComponentsOrder @ stub SetupSetSetupInfo @ stub SetupShellSettings -@ stub SetupStartService +@ stdcall SetupStartService(wstr long) @ stub SetupUnregisterOsComponent @ stub StorageCoInstaller @ stub SystemUpdateUserProfileDirectory