Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

559 lines
12 KiB

  1. /****************************************************************************
  2. *
  3. * icfg32.cpp
  4. *
  5. * Microsoft Confidential
  6. * Copyright (c) 1992-1998 Microsoft Corporation
  7. * All rights reserved
  8. *
  9. * This module provides the implementation of the methods for
  10. * the NT specific functionality of inetcfg
  11. *
  12. * 6/5/97 ChrisK Inherited from AmnonH
  13. *
  14. ***************************************************************************/
  15. #include <windows.h>
  16. #include <wtypes.h>
  17. #include <cfgapi.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <setupapi.h>
  21. #include <basetyps.h>
  22. #include <devguid.h>
  23. #include <lmsname.h>
  24. #include "debug.h"
  25. #define REG_DATA_EXTRA_SPACE 255
  26. extern DWORD g_dwLastError;
  27. //+----------------------------------------------------------------------------
  28. //
  29. // Function GetOSBuildNumber
  30. //
  31. // Synopsis Get the build number of Operating system
  32. //
  33. // Arguments None
  34. //
  35. // Returns Build Number of OS
  36. //
  37. // History 3/5/97 VetriV Created
  38. //
  39. //-----------------------------------------------------------------------------
  40. DWORD GetOSMajorVersionNumber(void)
  41. {
  42. OSVERSIONINFO oviVersion;
  43. ZeroMemory(&oviVersion,sizeof(oviVersion));
  44. oviVersion.dwOSVersionInfoSize = sizeof(oviVersion);
  45. GetVersionEx(&oviVersion);
  46. return(oviVersion.dwMajorVersion);
  47. }
  48. //+----------------------------------------------------------------------------
  49. //
  50. // Function: IcfgNeedModem
  51. //
  52. // Synopsis: Check system configuration to determine if there is at least
  53. // one physical modem installed
  54. //
  55. // Arguments: dwfOptions - currently not used
  56. //
  57. // Returns: HRESULT - S_OK if successfull
  58. // lpfNeedModem - TRUE if no modems are available
  59. //
  60. // History: 6/5/97 ChrisK Inherited
  61. //
  62. //-----------------------------------------------------------------------------
  63. HRESULT WINAPI
  64. IcfgNeedModem (DWORD dwfOptions, LPBOOL lpfNeedModem)
  65. {
  66. if (GetOSMajorVersionNumber() == 5)
  67. {
  68. return IcfgNeedModemNT5(dwfOptions, lpfNeedModem);
  69. }
  70. else
  71. {
  72. return IcfgNeedModemNT4(dwfOptions, lpfNeedModem);
  73. }
  74. }
  75. //+----------------------------------------------------------------------------
  76. //
  77. // Function: IcfgInstallModem
  78. //
  79. // Synopsis:
  80. // This function is called when ICW verified that RAS is installed,
  81. // but no modems are avilable. It needs to make sure a modem is availble.
  82. // There are two possible scenarios:
  83. //
  84. // a. There are no modems installed. This happens when someone deleted
  85. // a modem after installing RAS. In this case we need to run the modem
  86. // install wizard, and configure the newly installed modem to be a RAS
  87. // dialout device.
  88. //
  89. // b. There are modems installed, but non of them is configured as a dial out
  90. // device. In this case, we silently convert them to be DialInOut devices,
  91. // so ICW can use them.
  92. //
  93. // Arguments: hwndParent - handle to parent window
  94. // dwfOptions - not used
  95. //
  96. // Returns: lpfNeedsStart - not used
  97. //
  98. // History: 6/5/97 ChrisK Inherited
  99. //
  100. //-----------------------------------------------------------------------------
  101. HRESULT WINAPI
  102. IcfgInstallModem (HWND hwndParent, DWORD dwfOptions, LPBOOL lpfNeedsStart)
  103. {
  104. if (GetOSMajorVersionNumber() == 5)
  105. {
  106. return IcfgInstallModemNT5(hwndParent, dwfOptions, lpfNeedsStart);
  107. }
  108. else
  109. {
  110. return IcfgInstallModemNT4(hwndParent, dwfOptions, lpfNeedsStart);
  111. }
  112. }
  113. //+----------------------------------------------------------------------------
  114. //
  115. // Function: IcfgNeedInetComponets
  116. //
  117. // Synopsis: Check to see if the components marked in the options are
  118. // installed on the system
  119. //
  120. // Arguements: dwfOptions - set of bit flag indicating which components to
  121. // check for
  122. //
  123. // Returns; HRESULT - S_OK if successfull
  124. // lpfNeedComponents - TRUE is some components are not installed
  125. //
  126. // History: 6/5/97 ChrisK Inherited
  127. //
  128. //-----------------------------------------------------------------------------
  129. HRESULT WINAPI
  130. IcfgNeedInetComponents(DWORD dwfOptions, LPBOOL lpfNeedComponents)
  131. {
  132. if (GetOSMajorVersionNumber() == 5)
  133. {
  134. return IcfgNeedInetComponentsNT5(dwfOptions, lpfNeedComponents);
  135. }
  136. else
  137. {
  138. return IcfgNeedInetComponentsNT4(dwfOptions, lpfNeedComponents);
  139. }
  140. }
  141. //+----------------------------------------------------------------------------
  142. //
  143. // Function: IcfgInstallInetComponents
  144. //
  145. // Synopsis: Install the components as specified by the dwfOptions values
  146. //
  147. // Arguments hwndParent - handle to parent window
  148. // dwfOptions - set of bit flags indicating which components to
  149. // install
  150. //
  151. // Returns: HRESULT - S_OK if success
  152. // lpfNeedsReboot - TRUE if reboot is required
  153. //
  154. // History: 6/5/97 ChrisK Inherited
  155. //
  156. //-----------------------------------------------------------------------------
  157. HRESULT WINAPI
  158. IcfgInstallInetComponents(HWND hwndParent, DWORD dwfOptions, LPBOOL lpfNeedsRestart)
  159. {
  160. if (GetOSMajorVersionNumber() == 5)
  161. {
  162. return IcfgInstallInetComponentsNT5(hwndParent, dwfOptions, lpfNeedsRestart);
  163. }
  164. else
  165. {
  166. return IcfgInstallInetComponentsNT4(hwndParent, dwfOptions, lpfNeedsRestart);
  167. }
  168. }
  169. //+----------------------------------------------------------------------------
  170. //
  171. // Function: IcfgGetLastInstallErrorText
  172. //
  173. // Synopsis: Format error message for most recent error
  174. //
  175. // Arguments: none
  176. //
  177. // Returns: DWORD - win32 error code
  178. // lpszErrorDesc - string containing error message
  179. // cbErrorDesc - size of lpszErrorDesc
  180. //
  181. // History: 6/5/97 ChrisK Inherited
  182. //
  183. //-----------------------------------------------------------------------------
  184. DWORD WINAPI
  185. IcfgGetLastInstallErrorText(LPSTR lpszErrorDesc, DWORD cbErrorDesc)
  186. {
  187. Dprintf("ICFGNT: IcfgGetLastInstallErrorText\n");
  188. return(FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM,
  189. NULL,
  190. g_dwLastError,
  191. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), //The user default language
  192. lpszErrorDesc,
  193. cbErrorDesc,
  194. NULL));
  195. }
  196. //+----------------------------------------------------------------------------
  197. //
  198. // Function: DoStartService
  199. //
  200. // Synopsis: Start a particular service
  201. //
  202. // Arguments: hManager - handle to open service manager
  203. // szServiceName - name of service to start
  204. //
  205. // Returns: DWORD - win32 error code
  206. //
  207. // History: 6/5/97 ChrisK Inherited
  208. // 7/28/97 ChrisK Added query section
  209. //-----------------------------------------------------------------------------
  210. DWORD
  211. DoStartService(SC_HANDLE hManager, LPTSTR szServiceName)
  212. {
  213. SC_HANDLE hService = NULL;
  214. DWORD dwRC = ERROR_SUCCESS;
  215. //
  216. // Validate parameters
  217. //
  218. Assert(hManager && szServiceName);
  219. Dprintf("ICFGNT: DoStartService\n");
  220. hService = OpenService(hManager, szServiceName, SERVICE_START);
  221. if(hService != NULL)
  222. {
  223. if(!StartService(hService, 0, NULL))
  224. {
  225. dwRC = GetLastError();
  226. if(dwRC == ERROR_SERVICE_ALREADY_RUNNING)
  227. {
  228. //
  229. // If the service is already running, great, we're done.
  230. //
  231. dwRC = ERROR_SUCCESS;
  232. goto DoStartServiceExit;
  233. }
  234. }
  235. CloseServiceHandle(hService);
  236. hService = NULL;
  237. }
  238. //
  239. // Try to simply see if the service is running
  240. //
  241. Dprintf("ICFGNT: Failed to start service, try just querying it.\n");
  242. hService = OpenService(hManager, szServiceName, SERVICE_QUERY_STATUS);
  243. if(hService != NULL)
  244. {
  245. SERVICE_STATUS sstatus;
  246. ZeroMemory(&sstatus,sizeof(sstatus));
  247. if(QueryServiceStatus(hService,&sstatus))
  248. {
  249. if ((SERVICE_RUNNING == sstatus.dwCurrentState) ||
  250. (SERVICE_START_PENDING == sstatus.dwCurrentState))
  251. {
  252. //
  253. // The service is running
  254. //
  255. dwRC = ERROR_SUCCESS;
  256. goto DoStartServiceExit;
  257. }
  258. else
  259. {
  260. //
  261. // The service not running and we can't access it.
  262. //
  263. Dprintf("ICFGNT: Queried service is not running.\n");
  264. dwRC = ERROR_ACCESS_DENIED;
  265. goto DoStartServiceExit;
  266. }
  267. }
  268. else
  269. {
  270. //
  271. // Can not query service
  272. //
  273. Dprintf("ICFGNT: QueryServiceStatus failed.\n");
  274. dwRC = GetLastError();
  275. goto DoStartServiceExit;
  276. }
  277. }
  278. else
  279. {
  280. //
  281. // Can't open the service
  282. //
  283. Dprintf("ICFGNT: Cannot OpenService.\n");
  284. dwRC = GetLastError();
  285. goto DoStartServiceExit;
  286. }
  287. DoStartServiceExit:
  288. if (hService)
  289. {
  290. CloseServiceHandle(hService);
  291. }
  292. return(dwRC);
  293. }
  294. //+----------------------------------------------------------------------------
  295. //
  296. // Function: ValidateProductSuite
  297. //
  298. // Synopsis: Check registry for a particular Product Suite string
  299. //
  300. // Arguments: SuiteName - name of product suite to look for
  301. //
  302. // Returns: TRUE - the suite exists
  303. //
  304. // History: 6/5/97 ChrisK Inherited
  305. //
  306. //-----------------------------------------------------------------------------
  307. BOOL
  308. ValidateProductSuite(LPSTR SuiteName)
  309. {
  310. BOOL rVal = FALSE;
  311. LONG Rslt;
  312. HKEY hKey = NULL;
  313. DWORD Type = 0;
  314. DWORD Size = 0;
  315. LPSTR ProductSuite = NULL;
  316. LPSTR p;
  317. Dprintf("ICFGNT: ValidateProductSuite\n");
  318. //
  319. // Determine the size required to read registry values
  320. //
  321. Rslt = RegOpenKey(
  322. HKEY_LOCAL_MACHINE,
  323. "System\\CurrentControlSet\\Control\\ProductOptions",
  324. &hKey
  325. );
  326. if (Rslt != ERROR_SUCCESS)
  327. {
  328. goto exit;
  329. }
  330. Rslt = RegQueryValueEx(
  331. hKey,
  332. "ProductSuite",
  333. NULL,
  334. &Type,
  335. NULL,
  336. &Size
  337. );
  338. if (Rslt != ERROR_SUCCESS)
  339. {
  340. goto exit;
  341. }
  342. if (!Size)
  343. {
  344. goto exit;
  345. }
  346. ProductSuite = (LPSTR) GlobalAlloc( GPTR, Size );
  347. if (!ProductSuite)
  348. {
  349. goto exit;
  350. }
  351. //
  352. // Read ProductSuite information
  353. //
  354. Rslt = RegQueryValueEx(
  355. hKey,
  356. "ProductSuite",
  357. NULL,
  358. &Type,
  359. (LPBYTE) ProductSuite,
  360. &Size
  361. );
  362. if (Rslt != ERROR_SUCCESS)
  363. {
  364. goto exit;
  365. }
  366. if (Type != REG_MULTI_SZ)
  367. {
  368. goto exit;
  369. }
  370. //
  371. // Look for a particular string in the data returned
  372. // Note: data is terminiated with two NULLs
  373. //
  374. p = ProductSuite;
  375. while (*p) {
  376. if (strstr( p, SuiteName ))
  377. {
  378. rVal = TRUE;
  379. break;
  380. }
  381. p += (lstrlen( p ) + 1);
  382. }
  383. exit:
  384. if (ProductSuite)
  385. {
  386. GlobalFree( ProductSuite );
  387. }
  388. if (hKey)
  389. {
  390. RegCloseKey( hKey );
  391. }
  392. return rVal;
  393. }
  394. //+----------------------------------------------------------------------------
  395. //
  396. // Function: IcfgStartServices
  397. //
  398. // Synopsis: Start all services required by system
  399. //
  400. // Arguments: none
  401. //
  402. // Returns: HRESULT - S_OK if success
  403. //
  404. // History: 6/5/97 ChrisK Iherited
  405. //
  406. //-----------------------------------------------------------------------------
  407. HRESULT WINAPI
  408. IcfgStartServices()
  409. {
  410. //
  411. // returns ERROR_SERVICE_DISABLED if the service is disabled
  412. //
  413. SC_HANDLE hManager;
  414. Dprintf("ICFGNT: IcfgStartServices\n");
  415. hManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
  416. if(hManager == NULL)
  417. {
  418. return(GetLastError());
  419. }
  420. DWORD dwErr;
  421. /*
  422. //
  423. // Don't start RASAUTO anymore, it isn't necessary for RAS to be running.
  424. //
  425. if (!ValidateProductSuite( "Small Business" ))
  426. {
  427. dwErr = DoStartService(hManager, TEXT("RASAUTO"));
  428. //
  429. // Ignore the return value, CM should proceed even if RASAUTO failed to launch
  430. //
  431. }
  432. */
  433. dwErr = DoStartService(hManager, TEXT("RASMAN"));
  434. CloseServiceHandle(hManager);
  435. return(dwErr);
  436. }
  437. //+----------------------------------------------------------------------------
  438. //
  439. // Function: IcfgIsGlobalDNS
  440. //
  441. // Note: these functions are not needed on an NT system and it therefore not
  442. // implemented
  443. //
  444. //-----------------------------------------------------------------------------
  445. HRESULT WINAPI
  446. IcfgIsGlobalDNS(LPBOOL lpfGlobalDNS)
  447. {
  448. *lpfGlobalDNS = FALSE;
  449. return(ERROR_SUCCESS);
  450. }
  451. HRESULT WINAPI
  452. IcfgRemoveGlobalDNS()
  453. {
  454. return(ERROR_SUCCESS);
  455. }
  456. HRESULT WINAPI
  457. InetGetSupportedPlatform(LPDWORD pdwPlatform)
  458. {
  459. *pdwPlatform = VER_PLATFORM_WIN32_NT;
  460. return(ERROR_SUCCESS);
  461. }
  462. HRESULT WINAPI
  463. InetSetAutodial(BOOL fEnable, LPCSTR lpszEntryName)
  464. {
  465. return(ERROR_INVALID_FUNCTION);
  466. }
  467. HRESULT WINAPI
  468. InetGetAutodial(LPBOOL lpfEnable, LPSTR lpszEntryName, DWORD cbEntryName)
  469. {
  470. return(ERROR_INVALID_FUNCTION);
  471. }
  472. HRESULT WINAPI
  473. InetSetAutodialAddress(DWORD dwDialingLocation, LPSTR szEntry)
  474. {
  475. return(ERROR_SUCCESS);
  476. }
  477. #ifdef __cplusplus
  478. extern "C"
  479. {
  480. #endif // __cplusplus
  481. void __cdecl main() {};
  482. #ifdef __cplusplus
  483. }
  484. #endif // __cplusplus