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.

566 lines
17 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1994 **
  4. //*********************************************************************
  5. //
  6. // CFGAPI.C - Functions for exported config API.
  7. //
  8. // HISTORY:
  9. //
  10. // 96/05/22 markdu Created (from inetcfg.dll)
  11. // 96/05/25 markdu Use ICFG_ flags for lpNeedDrivers and lpInstallDrivers.
  12. // 96/05/27 markdu Added lpGetLastInstallErrorText.
  13. //
  14. #include "pch.hpp"
  15. UINT DetectModifyTCPIPBindings(DWORD dwCardFlags,LPCSTR pszBoundTo,BOOL fRemove,BOOL * pfBound);
  16. //*******************************************************************
  17. //
  18. // FUNCTION: IcfgGetLastInstallErrorText
  19. //
  20. // PURPOSE: Get a text string that describes the last installation
  21. // error that occurred. The string should be suitable
  22. // for display in a message box with no further formatting.
  23. //
  24. // PARAMETERS: lpszErrorDesc - points to buffer to receive the string.
  25. // cbErrorDesc - size of buffer.
  26. //
  27. // RETURNS: The length of the string returned.
  28. //
  29. //*******************************************************************
  30. extern "C" DWORD WINAPI IcfgGetLastInstallErrorText(LPSTR lpszErrorDesc, DWORD cbErrorDesc)
  31. {
  32. if (lpszErrorDesc)
  33. {
  34. lstrcpyn(lpszErrorDesc, gpszLastErrorText, cbErrorDesc);
  35. return lstrlen(lpszErrorDesc);
  36. }
  37. else
  38. {
  39. return 0;
  40. }
  41. }
  42. //*******************************************************************
  43. //
  44. // FUNCTION: IcfgNeedInetComponents
  45. //
  46. // PURPOSE: Detects whether the specified system components are
  47. // installed or not.
  48. //
  49. // PARAMETERS: dwfOptions - a combination of ICFG_ flags that specify
  50. // which components to detect as follows:
  51. //
  52. // ICFG_INSTALLTCP - is TCP/IP needed?
  53. // ICFG_INSTALLRAS - is RAS needed?
  54. // ICFG_INSTALLMAIL - is exchange or internet mail needed?
  55. //
  56. // lpfNeedComponents - TRUE if any specified component needs
  57. // to be installed.
  58. //
  59. // RETURNS: HRESULT code, ERROR_SUCCESS if no errors occurred
  60. //
  61. // History: 5/8/97 ChrisK Added INSTALLLAN,INSTALLDIALUP,INSTALLTCPONLY
  62. //
  63. //*******************************************************************
  64. extern "C" HRESULT WINAPI IcfgNeedInetComponents(DWORD dwfOptions, LPBOOL lpfNeedComponents)
  65. {
  66. CLIENTCONFIG ClientConfig;
  67. DEBUGMSG("cfgapi.c::IcfgNeedInetComponents()");
  68. ASSERT(lpfNeedComponents);
  69. // read client configuration
  70. ZeroMemory(&ClientConfig,sizeof(CLIENTCONFIG));
  71. DWORD dwErrCls;
  72. UINT err=GetConfig(&ClientConfig,&dwErrCls);
  73. if (err != OK)
  74. {
  75. LoadSz(IDS_ERRReadConfig, gpszLastErrorText, MAX_ERROR_TEXT);
  76. return err;
  77. }
  78. // check if we are allowed to install TCP/IP
  79. if (dwfOptions & ICFG_INSTALLTCP)
  80. {
  81. // need TCP/IP present and bound to PPP driver
  82. // if (!ClientConfig.fPPPBoundTCP)
  83. //
  84. // vyung - PPPBound TCP is not able to be installed through
  85. // ICW. So here we only check the TCPIP flag.
  86. if (!ClientConfig.fTcpip)
  87. {
  88. if (lpfNeedComponents)
  89. {
  90. *lpfNeedComponents = TRUE;
  91. }
  92. return ERROR_SUCCESS;
  93. }
  94. }
  95. // check if we are allowed to install RNA
  96. if (dwfOptions & ICFG_INSTALLRAS)
  97. {
  98. // need PPPMAC and RNA files if using modem
  99. if (!ClientConfig.fRNAInstalled ||
  100. !ClientConfig.fPPPDriver)
  101. {
  102. if (lpfNeedComponents)
  103. {
  104. *lpfNeedComponents = TRUE;
  105. }
  106. return ERROR_SUCCESS;
  107. }
  108. }
  109. // need Exchange if not installed and user wants to install mail
  110. if ((dwfOptions & ICFG_INSTALLMAIL) &&
  111. (!ClientConfig.fMailInstalled || !ClientConfig.fInetMailInstalled))
  112. {
  113. if (lpfNeedComponents)
  114. {
  115. *lpfNeedComponents = TRUE;
  116. }
  117. return ERROR_SUCCESS;
  118. }
  119. //
  120. // ChrisK 5/8/97
  121. // check if we have a bound LAN adapter
  122. //
  123. if (dwfOptions & ICFG_INSTALLLAN)
  124. {
  125. if (!ClientConfig.fNetcard ||
  126. !ClientConfig.fNetcardBoundTCP)
  127. {
  128. if (lpfNeedComponents)
  129. {
  130. *lpfNeedComponents = TRUE;
  131. }
  132. return ERROR_SUCCESS;
  133. }
  134. }
  135. //
  136. // ChrisK 5/8/97
  137. // Check if we have a bound Dial up adapter
  138. //
  139. if (dwfOptions & ICFG_INSTALLDIALUP)
  140. {
  141. if (!ClientConfig.fPPPDriver ||
  142. !ClientConfig.fPPPBoundTCP)
  143. {
  144. if (lpfNeedComponents)
  145. {
  146. *lpfNeedComponents = TRUE;
  147. }
  148. return ERROR_SUCCESS;
  149. }
  150. }
  151. //
  152. // ChrisK 5/8/97
  153. // Check if TCP is install at all on this system
  154. //
  155. if (dwfOptions & ICFG_INSTALLTCPONLY)
  156. {
  157. if (!ClientConfig.fTcpip)
  158. {
  159. if (lpfNeedComponents)
  160. {
  161. *lpfNeedComponents = TRUE;
  162. }
  163. return ERROR_SUCCESS;
  164. }
  165. }
  166. // no extra drivers needed
  167. if (lpfNeedComponents)
  168. {
  169. *lpfNeedComponents = FALSE;
  170. }
  171. return ERROR_SUCCESS;
  172. }
  173. //*******************************************************************
  174. //
  175. // FUNCTION: IcfgInstallInetComponents
  176. //
  177. // PURPOSE: Install the specified system components.
  178. //
  179. // PARAMETERS: hwndParent - Parent window handle.
  180. // dwfOptions - a combination of ICFG_ flags that controls
  181. // the installation and configuration as follows:
  182. //
  183. // ICFG_INSTALLTCP - install TCP/IP (if needed)
  184. // ICFG_INSTALLRAS - install RAS (if needed)
  185. // ICFG_INSTALLMAIL - install exchange and internet mail
  186. //
  187. // lpfNeedsRestart - if non-NULL, then on return, this will be
  188. // TRUE if windows must be restarted to complete the installation.
  189. //
  190. // RETURNS: HRESULT code, ERROR_SUCCESS if no errors occurred
  191. //
  192. //*******************************************************************
  193. extern "C" HRESULT WINAPI IcfgInstallInetComponents(HWND hwndParent, DWORD dwfOptions,
  194. LPBOOL lpfNeedsRestart)
  195. {
  196. RETERR err;
  197. DWORD dwFiles = 0;
  198. BOOL fInitNetMAC = FALSE;
  199. BOOL fNeedTCPIP=FALSE;
  200. BOOL fNeedPPPMAC=FALSE;
  201. BOOL fNeedToRemoveTCPIP=FALSE;
  202. BOOL fNeedReboot = FALSE;
  203. DWORD dwErrCls;
  204. CLIENTCONFIG ClientConfig;
  205. DEBUGMSG("cfgapi.c::IcfgInstallInetComponents()");
  206. // read client configuration
  207. ZeroMemory(&ClientConfig,sizeof(CLIENTCONFIG));
  208. err=GetConfig(&ClientConfig,&dwErrCls);
  209. if (err != OK)
  210. {
  211. LoadSz(IDS_ERRReadConfig, gpszLastErrorText, MAX_ERROR_TEXT);
  212. return err;
  213. }
  214. // see if we initially have any kind of net card
  215. fInitNetMAC = (ClientConfig.fNetcard | ClientConfig.fPPPDriver);
  216. // install files we need
  217. // install mail if user wants it and not already installed
  218. if (dwfOptions & ICFG_INSTALLMAIL)
  219. {
  220. // need mail files (capone)?
  221. if (!ClientConfig.fMailInstalled)
  222. {
  223. DEBUGMSG("Installing Exchange files");
  224. dwFiles |= ICIF_MAIL;
  225. }
  226. // need internet mail files (rt 66)?
  227. if (!ClientConfig.fInetMailInstalled)
  228. {
  229. DEBUGMSG("Installing Internet Mail files");
  230. dwFiles |= ICIF_INET_MAIL;
  231. }
  232. }
  233. // check if we are allowed to install RNA
  234. if (dwfOptions & ICFG_INSTALLRAS)
  235. {
  236. // install RNA if user is connecting over modem and RNA
  237. // not already installed
  238. if (!ClientConfig.fRNAInstalled)
  239. {
  240. DEBUGMSG("Installing RNA files");
  241. dwFiles |= ICIF_RNA;
  242. }
  243. }
  244. if (dwFiles)
  245. {
  246. {
  247. WAITCURSOR WaitCursor; // show hourglass
  248. // install the component files
  249. err = InstallComponent(hwndParent,IC_INSTALLFILES,
  250. dwFiles);
  251. if (err == NEED_RESTART)
  252. {
  253. DEBUGMSG("Setting restart flag");
  254. // set restart flag so we restart the system at end
  255. fNeedReboot = TRUE;
  256. // NEED_REBOOT also implies success, so set ret code to OK
  257. err = OK;
  258. }
  259. // force an update of the dialog
  260. if (hwndParent)
  261. {
  262. HWND hParent = GetParent(hwndParent);
  263. UpdateWindow(hParent ? hParent : hwndParent);
  264. }
  265. // runonce.exe may get run at next boot, twiddle the
  266. // registry to work around a bug where it trashes the wallpaper
  267. PrepareForRunOnceApp();
  268. }
  269. if (err != OK)
  270. {
  271. LoadSz(IDS_ERRInstallFiles, gpszLastErrorText, MAX_ERROR_TEXT);
  272. return err;
  273. }
  274. WAITCURSOR WaitCursor; // show hourglass
  275. // do some extra stuff if we just installed mail
  276. if (dwFiles & ICIF_MAIL)
  277. {
  278. // .inf file leaves an entry in the registry to run
  279. // MS Exchange wizard, which we don't need since we'll be
  280. // configuring exchange ourselves. Remove the registry
  281. // entry.
  282. RemoveRunOnceEntry(IDS_MAIL_WIZARD_REG_VAL);
  283. // run mlset32, Exchange setup app that it needs to have run.
  284. // need to display error if this fails, this is fairly important.
  285. err=RunMlsetExe(hwndParent);
  286. if (err != ERROR_SUCCESS)
  287. {
  288. LoadSz(IDS_ERRInstallFiles, gpszLastErrorText, MAX_ERROR_TEXT);
  289. return err;
  290. }
  291. }
  292. // run the group converter to put the Inbox icon on desktop,
  293. // put Exchange, RNA et al on start menu
  294. CHAR szExecGrpconv[SMALL_BUF_LEN],szParam[SMALL_BUF_LEN];
  295. LoadSz(IDS_EXEC_GRPCONV,szExecGrpconv,sizeof(szExecGrpconv));
  296. LoadSz(IDS_EXEC_GRPCONV_PARAM,szParam,sizeof(szParam));
  297. ShellExecute(NULL,NULL,szExecGrpconv,szParam,NULL,SW_SHOW);
  298. }
  299. // only install PPPMAC if we are allowed to install RNA
  300. if (dwfOptions & ICFG_INSTALLRAS)
  301. {
  302. // install PPPMAC if not already installed
  303. // Note that we have to install PPPMAC *before* TCP/IP, to work
  304. // in the case where the user has no net installed to start with.
  305. // Otherwise when we install TCP/IP, user gets prompted by net setup
  306. // for their net card; net setup doesn't like the idea of TCP/IP lying
  307. // around without something to bind it to.
  308. fNeedPPPMAC = (!ClientConfig.fPPPDriver);
  309. if (fNeedPPPMAC)
  310. {
  311. DEBUGMSG("Installing PPPMAC");
  312. // make up a computer and workgroup name if not already set, so
  313. // user doesn't get prompted
  314. GenerateComputerNameIfNeeded();
  315. err = InstallPPPMAC(hwndParent);
  316. // 96/05/20 markdu MSN BUG 8551 Check for reboot when installing PPPMAC.
  317. //
  318. // ChrisK 5/29/97 Olympus 4692
  319. // Even if we just rebind PPPMAC we still need to restart the machine.
  320. //
  321. if (err == NEED_RESTART || err == OK)
  322. {
  323. // set restart flag so we restart the system at end
  324. DEBUGMSG("Setting restart flag");
  325. fNeedReboot = TRUE;
  326. // NEED_REBOOT also implies success, so set ret code to OK
  327. err = OK;
  328. }
  329. if (err != OK)
  330. {
  331. LoadSz(IDS_ERRInstallPPPMAC, gpszLastErrorText, MAX_ERROR_TEXT);
  332. return err;
  333. }
  334. // when we install PPPMAC, if there is another net card then PPPMAC
  335. // will automatically "grow" all the protocols that were bound to the
  336. // net card. Strip these off... (netbeui and IPX)
  337. RETERR errTmp = RemoveProtocols(hwndParent,INSTANCE_PPPDRIVER,
  338. PROT_NETBEUI | PROT_IPX);
  339. ASSERT(errTmp == OK);
  340. }
  341. }
  342. // check if we are allowed to install TCP/IP
  343. if (dwfOptions & ICFG_INSTALLTCP)
  344. {
  345. CLIENTCONFIG newClientConfig;
  346. // read the client configuration again, since installing PPP might have
  347. // installed TCP/IP
  348. ZeroMemory(&newClientConfig,sizeof(CLIENTCONFIG));
  349. DWORD dwErrCls;
  350. UINT err=GetConfig(&newClientConfig,&dwErrCls);
  351. if (err != OK)
  352. {
  353. LoadSz(IDS_ERRReadConfig, gpszLastErrorText, MAX_ERROR_TEXT);
  354. return err;
  355. }
  356. // figure out if we need to install TCP/IP
  357. // BUGBUG - only put TCP/IP on appropriate type of card (net card
  358. // or PPP adapter)
  359. // user is connecting via modem, need TCP if not already present
  360. // and bound to PPPMAC. Want to bind to PPP adapters,
  361. fNeedTCPIP = !newClientConfig.fPPPBoundTCP;
  362. if (fNeedTCPIP && newClientConfig.fNetcard &&
  363. !newClientConfig.fNetcardBoundTCP)
  364. {
  365. // if we have to add TCP to PPP driver, then check if TCP is already
  366. // on netcard. If not, then TCP is going to glom on to netcard as
  367. // well as PPP driver when we install it, need to remove it from
  368. // netcard later.
  369. fNeedToRemoveTCPIP= TRUE;
  370. }
  371. // special case: if there were any existing instances of TCP/IP and
  372. // we just added PPPMAC then we don't need to install TCP/IP --
  373. // when the PPPMAC adapter got added it automatically gets an instance
  374. // of all installed protocols (incl. TCP/IP) created for it
  375. if (newClientConfig.fTcpip && fNeedPPPMAC)
  376. {
  377. fNeedTCPIP = FALSE;
  378. }
  379. } // if (dwfOptions & ICFG_INSTALLTCP)
  380. // install TCP/IP if necessary
  381. if (fNeedTCPIP)
  382. {
  383. DEBUGMSG("Installing TCP/IP");
  384. // call out to device manager to install TCP/IP
  385. err = InstallTCPIP(hwndParent);
  386. // 96/05/20 markdu MSN BUG 8551 Check for reboot when installing TCP/IP.
  387. if (err == NEED_RESTART)
  388. {
  389. // NEED_REBOOT also implies success, so set ret code to OK
  390. // Reboot flag is set below ALWAYS. Should really be set here,
  391. // but we don't want to suddenly stop rebooting in cases
  392. // where we used to reboot, even if not needed.
  393. err = OK;
  394. }
  395. if (err != OK)
  396. {
  397. LoadSz(IDS_ERRInstallTCPIP, gpszLastErrorText, MAX_ERROR_TEXT);
  398. return err;
  399. }
  400. if (fNeedToRemoveTCPIP)
  401. {
  402. // remove TCPIP that may have glommed onto net drivers other
  403. // than the one we intend it for
  404. UINT uErrTmp;
  405. uErrTmp=RemoveProtocols(hwndParent,INSTANCE_NETDRIVER,PROT_TCPIP);
  406. ASSERT(uErrTmp == OK);
  407. }
  408. DEBUGMSG("Setting restart flag");
  409. // set restart flag so we restart the system at end
  410. fNeedReboot = TRUE;
  411. }
  412. // if we just installed TCP/IP or PPPMAC, then adjust bindings
  413. if (fNeedPPPMAC || fNeedTCPIP)
  414. {
  415. UINT uErrTmp;
  416. // if file sharing (vserver) is installed, TCP/IP will bind
  417. // to it by default. This is bad, user could be sharing
  418. // files to Internet without knowing it. Unbind VSERVER
  419. // from TCP/IP instances that may used to connect to Internet
  420. // (instances of type INSTANCE_PPPDRIVER)
  421. uErrTmp = IcfgTurnOffFileSharing(INSTANCE_PPPDRIVER, hwndParent);
  422. ASSERT (uErrTmp == ERROR_SUCCESS);
  423. // unbind TCP/IP from VREDIR, if bound on this card type
  424. BOOL fBound;
  425. uErrTmp = DetectModifyTCPIPBindings(INSTANCE_PPPDRIVER,szVREDIR,
  426. TRUE,&fBound);
  427. ASSERT(uErrTmp == ERROR_SUCCESS);
  428. }
  429. // refresh the client configuration info
  430. err = GetConfig(&ClientConfig,&dwErrCls);
  431. if (err != OK)
  432. {
  433. LoadSz(IDS_ERRReadConfig, gpszLastErrorText, MAX_ERROR_TEXT);
  434. return err;
  435. }
  436. // do some special handling if there were *no* netcard devices
  437. // (net cards or PPP drivers) initially installed
  438. if (!fInitNetMAC)
  439. {
  440. ASSERT(fNeedPPPMAC); // should have just installed PPPMAC
  441. // net setup adds some extra net components "by default" when
  442. // we add PPPMAC and there are no net card devices, go kill them
  443. // off.
  444. RETERR reterr = RemoveUnneededDefaultComponents(hwndParent);
  445. ASSERT(reterr == OK);
  446. // since there were no net card devices to begin with, we need
  447. // to restart the system later. (the NDIS VxD is a static VxD
  448. // which needs to run, only gets added when you install a net card.)
  449. DEBUGMSG("Setting restart flag");
  450. // set restart flag so we restart the system at end
  451. fNeedReboot = TRUE;
  452. }
  453. // tell caller whether we need to reboot or not
  454. if (lpfNeedsRestart)
  455. {
  456. *lpfNeedsRestart = fNeedReboot;
  457. }
  458. return ERROR_SUCCESS;
  459. }
  460. /*******************************************************************
  461. NAME: GetConfig
  462. SYNOPSIS: Retrieves client configuration
  463. ********************************************************************/
  464. UINT GetConfig(CLIENTCONFIG * pClientConfig,DWORD * pdwErrCls)
  465. {
  466. ASSERT(pClientConfig);
  467. ASSERT(pdwErrCls);
  468. // get most the client configuration from 16-bit dll
  469. UINT uRet = GetClientConfig(pClientConfig);
  470. if (uRet != OK) {
  471. // GetClientConfig returns SETUPX error codes
  472. *pdwErrCls = ERRCLS_SETUPX;
  473. }
  474. return uRet;
  475. }
  476. //*******************************************************************
  477. //
  478. // FUNCTION: IcfgStartServices
  479. //
  480. // PURPOSE: This is a NOP designed to maintain parity with the NT
  481. // version (icfgnt.dll).
  482. //
  483. // PARAMETERS: none
  484. //
  485. // RETURNS: HRESULT code, ERROR_SUCCESS if no errors occurred
  486. //
  487. //*******************************************************************
  488. extern "C" HRESULT IcfgStartServices()
  489. {
  490. return ERROR_SUCCESS;
  491. }