Leaked source code of windows server 2003
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.

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