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.

458 lines
14 KiB

  1. // ICWCfg.cpp : Implementation of CICWSystemConfig
  2. #include "stdafx.h"
  3. #include "icwhelp.h"
  4. #include "ICWCfg.h"
  5. #include <winnetwk.h>
  6. #include <regstr.h>
  7. /////////////////////////////////////////////////////////////////////////////
  8. // CICWSystemConfig
  9. HRESULT CICWSystemConfig::OnDraw(ATL_DRAWINFO& di)
  10. {
  11. return S_OK;
  12. }
  13. //+----------------------------------------------------------------------------
  14. //
  15. // Function IsMSDUN11Installed
  16. //
  17. // Synopsis Check if MSDUN 1.1 or higher is installed
  18. //
  19. // Arguments none
  20. //
  21. // Returns TRUE - MSDUN 1.1 is installed
  22. //
  23. // History 5/28/97 ChrisK created for Olympus Bug 4392
  24. // 1/13/98 DONALDM Copied from ICW \\drywall\slm
  25. //
  26. //-----------------------------------------------------------------------------
  27. #define DUN_11_Version (1.1)
  28. BOOL IsMSDUN11Installed()
  29. {
  30. CHAR szBuffer[MAX_PATH] = {"\0"};
  31. HKEY hkey = NULL;
  32. BOOL bRC = FALSE;
  33. DWORD dwType = 0;
  34. DWORD dwSize = sizeof(szBuffer);
  35. DOUBLE dVersion = 0.0;
  36. if (ERROR_SUCCESS != RegOpenKey(HKEY_LOCAL_MACHINE,
  37. TEXT("System\\CurrentControlSet\\Services\\RemoteAccess"),
  38. &hkey))
  39. {
  40. goto IsMSDUN11InstalledExit;
  41. }
  42. if (ERROR_SUCCESS != RegQueryValueEx(hkey,
  43. TEXT("Version"),
  44. NULL,
  45. &dwType,
  46. (LPBYTE)szBuffer,
  47. &dwSize))
  48. {
  49. goto IsMSDUN11InstalledExit;
  50. }
  51. dVersion = atof(szBuffer);
  52. if (dVersion >= DUN_11_Version)
  53. {
  54. bRC = TRUE;
  55. }
  56. IsMSDUN11InstalledExit:
  57. if (hkey != NULL)
  58. {
  59. RegCloseKey(hkey);
  60. hkey = NULL;
  61. }
  62. return bRC;
  63. }
  64. //
  65. // Function IsScriptingInstalled
  66. //
  67. // Synopsis Check to see if scripting is already installed
  68. //
  69. // Arguments none
  70. //
  71. // Returns TRUE - scripting has been installed
  72. //
  73. // History 10/14/96 ChrisK Creaed
  74. // 1/13/98 DONALDM Copied from ICW \\drywall\slm
  75. //
  76. //-----------------------------------------------------------------------------
  77. BOOL IsScriptingInstalled()
  78. {
  79. BOOL bRC = FALSE;
  80. HKEY hkey = NULL;
  81. DWORD dwSize = 0;
  82. DWORD dwType = 0;
  83. LONG lrc = 0;
  84. HINSTANCE hInst = NULL;
  85. TCHAR szData[MAX_PATH+1];
  86. if (VER_PLATFORM_WIN32_NT == g_dwPlatform)
  87. {
  88. bRC = TRUE;
  89. }
  90. else if (IsMSDUN11Installed())
  91. {
  92. bRC = TRUE;
  93. }
  94. else
  95. {
  96. //
  97. // Verify scripting by checking for smmscrpt.dll in RemoteAccess registry key
  98. //
  99. if (1111 <= g_dwBuild)
  100. {
  101. bRC = TRUE;
  102. }
  103. else
  104. {
  105. bRC = FALSE;
  106. hkey = NULL;
  107. lrc=RegOpenKey(HKEY_LOCAL_MACHINE,TEXT("System\\CurrentControlSet\\Services\\RemoteAccess\\Authentication\\SMM_FILES\\PPP"),&hkey);
  108. if (ERROR_SUCCESS == lrc)
  109. {
  110. dwSize = sizeof(TCHAR)*MAX_PATH;
  111. lrc = RegQueryValueEx(hkey,TEXT("Path"),0,&dwType,(LPBYTE)szData,&dwSize);
  112. if (ERROR_SUCCESS == lrc)
  113. {
  114. if (0 == lstrcmpi(szData,TEXT("smmscrpt.dll")))
  115. bRC = TRUE;
  116. }
  117. }
  118. if (hkey)
  119. RegCloseKey(hkey);
  120. hkey = NULL;
  121. }
  122. //
  123. // Verify that the DLL can be loaded
  124. //
  125. if (bRC)
  126. {
  127. hInst = LoadLibrary(TEXT("smmscrpt.dll"));
  128. if (hInst)
  129. FreeLibrary(hInst);
  130. else
  131. bRC = FALSE;
  132. hInst = NULL;
  133. }
  134. }
  135. return bRC;
  136. }
  137. //+----------------------------------------------------------------------------
  138. //
  139. // Function InstallScripter
  140. //
  141. // Synopsis Install scripting on win95 950.6 builds (not on OSR2)
  142. //
  143. // Arguments none
  144. //
  145. // Returns none
  146. //
  147. // History 10/9/96 ChrisK Copied from mt.cpp in \\trango sources
  148. // 1/13/98 DONALDM Copied from ICW \\drywall\slm
  149. //-----------------------------------------------------------------------------
  150. void CICWSystemConfig::InstallScripter()
  151. {
  152. STARTUPINFO si;
  153. PROCESS_INFORMATION pi;
  154. MSG msg ;
  155. DWORD iWaitResult = 0;
  156. TraceMsg(TF_SYSTEMCONFIG, TEXT("ICWHELP: Install Scripter.\r\n"));
  157. //
  158. // check if scripting is already set up
  159. //
  160. if (!IsScriptingInstalled())
  161. {
  162. TCHAR szCommandLine[] = TEXT("\"icwscrpt.exe\"");
  163. memset(&pi, 0, sizeof(pi));
  164. memset(&si, 0, sizeof(si));
  165. if(!CreateProcess(NULL, szCommandLine, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi))
  166. {
  167. TraceMsg(TF_SYSTEMCONFIG, TEXT("ICWHELP: Cant find ICWSCRPT.EXE\r\n"));
  168. }
  169. else
  170. {
  171. TraceMsg(TF_SYSTEMCONFIG, TEXT("ICWHELP: Launched ICWSCRPT.EXE. Waiting for exit.\r\n"));
  172. //
  173. // wait for event or msgs. Dispatch msgs. Exit when event is signalled.
  174. //
  175. while((iWaitResult=MsgWaitForMultipleObjects(1, &pi.hProcess, FALSE, INFINITE, QS_ALLINPUT))==(WAIT_OBJECT_0 + 1))
  176. {
  177. //
  178. // read all of the messages in this next loop
  179. // removing each message as we read it
  180. //
  181. while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  182. {
  183. TraceMsg(TF_SYSTEMCONFIG, TEXT("ICWHELP: Got msg\r\n"));
  184. //
  185. // how to handle quit message?
  186. //
  187. if (msg.message == WM_QUIT)
  188. {
  189. TraceMsg(TF_SYSTEMCONFIG, TEXT("ICWHELP: Got quit msg\r\n"));
  190. goto done;
  191. }
  192. else
  193. DispatchMessage(&msg);
  194. }
  195. }
  196. done:
  197. CloseHandle(pi.hThread);
  198. CloseHandle(pi.hProcess);
  199. TraceMsg(TF_SYSTEMCONFIG, TEXT("ICWHELP: ICWSCRPT.EXE done\r\n"));
  200. }
  201. }
  202. }
  203. //+----------------------------------------------------------------------------
  204. // Function ConfigSystem
  205. //
  206. // Synopsis Make sure that the system is configured for RAS operations
  207. //
  208. // Arguments none
  209. //
  210. // Return FALSE - if the is not configured. Caller needs to
  211. // call NeedsReboot QuitWizard to get the proper action
  212. // to take.
  213. // NeedsReboot means that we installed stuff, but need the user
  214. // to reboot for the changes to take place
  215. // QuitWizard means just that, time to bail out
  216. // Neither set, means to ask the user user if they really want to
  217. // Quit.
  218. // TRUE - The things are ready to go
  219. //
  220. // History 10/16/96 ChrisK Created
  221. // 1/13/98 DONALDM Copied from ICW \\drywall\slm
  222. //
  223. //-----------------------------------------------------------------------------
  224. STDMETHODIMP CICWSystemConfig::ConfigSystem(BOOL *pbRetVal)
  225. {
  226. HINSTANCE hinetcfg;
  227. TCHAR szBuff256[256+1];
  228. FARPROC fp;
  229. HRESULT hr;
  230. // Assume a failure below.
  231. *pbRetVal = FALSE;
  232. //
  233. // Locate installation entry point
  234. //
  235. hinetcfg = LoadLibrary(TEXT("INETCFG.DLL"));
  236. if (!hinetcfg)
  237. {
  238. wsprintf(szBuff256,GetSz(IDS_CANTLOADINETCFG),TEXT("INETCFG.DLL"));
  239. ::MessageBox(GetActiveWindow(),szBuff256,GetSz(IDS_TITLE),MB_MYERROR);
  240. m_bQuitWizard = TRUE;
  241. return S_OK;
  242. }
  243. fp = GetProcAddress(hinetcfg,"InetConfigSystem");
  244. if (!fp)
  245. {
  246. MsgBox(IDS_CANTLOADCONFIGAPI, MB_MYERROR);
  247. m_bQuitWizard = TRUE;
  248. return S_OK;
  249. }
  250. // Disable the active window, since any UI the following function brings
  251. // up needs to be modal.
  252. HWND hWnd = GetActiveWindow();
  253. // Install and configure TCP/IP and RNA
  254. hr = ((PFNCONFIGAPI)fp)(hWnd,
  255. INETCFG_INSTALLRNA |
  256. INETCFG_INSTALLTCP |
  257. INETCFG_INSTALLMODEM |
  258. (IsNT()?INETCFG_SHOWBUSYANIMATION:0) |
  259. INETCFG_REMOVEIFSHARINGBOUND,
  260. &m_bNeedsReboot);
  261. // Renable the window, and bring it back to the top of the Z-Order
  262. ::SetForegroundWindow(hWnd);
  263. // ::BringWindowToTop(hWnd);
  264. // ::SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
  265. if (hinetcfg)
  266. FreeLibrary(hinetcfg);
  267. hinetcfg = NULL;
  268. // See what happened during the config call
  269. if (hr == ERROR_CANCELLED)
  270. {
  271. return S_OK;
  272. }
  273. else if (hr != ERROR_SUCCESS)
  274. {
  275. WORD wTemp = ( VER_PLATFORM_WIN32_WINDOWS == g_dwPlatform )
  276. ? IDS_CONFIGAPIFAILEDRETRY : IDS_CONFIGURENTFAILEDRETRY;
  277. //
  278. // No retry anymore as its not going to help, just
  279. // provide the user with an OK message
  280. // MKarki (4/15/97) Fix for Bug #7004
  281. //
  282. ::MessageBox(GetActiveWindow(),GetSz(wTemp),GetSz(IDS_TITLE),
  283. MB_MYERROR | MB_OK);
  284. m_bQuitWizard = TRUE;
  285. return hr;
  286. }
  287. else
  288. {
  289. // ChrisK - added 10/9/96
  290. // BUGBUG can this fail, and if so is it a problem???
  291. // original ICW code does not handle failure case here
  292. InstallScripter();
  293. }
  294. // See if we need to reboot. If not, we need to see if the user is logged in
  295. if (!m_bNeedsReboot)
  296. {
  297. TCHAR szUser[MAX_PATH];
  298. DWORD cchUser = ARRAYSIZE(szUser);
  299. // Verify the user is logged on.
  300. if (NO_ERROR != WNetGetUser(NULL,szUser, &cchUser))
  301. {
  302. // Failed to get user info, so we need to restart with a loggin
  303. m_bNeedsRestart = TRUE;
  304. }
  305. else
  306. {
  307. // User is logged in, so we are happy.
  308. *pbRetVal = TRUE;
  309. }
  310. }
  311. return S_OK;
  312. }
  313. STDMETHODIMP CICWSystemConfig::get_NeedsReboot(BOOL * pVal)
  314. {
  315. *pVal = m_bNeedsReboot;
  316. return S_OK;
  317. }
  318. STDMETHODIMP CICWSystemConfig::get_NeedsRestart(BOOL * pVal)
  319. {
  320. *pVal = m_bNeedsRestart;
  321. return S_OK;
  322. }
  323. STDMETHODIMP CICWSystemConfig::get_QuitWizard(BOOL * pVal)
  324. {
  325. *pVal = m_bQuitWizard;
  326. return S_OK;
  327. }
  328. //+----------------------------------------------------------------------------
  329. // Function VerifyRasServicesRunning
  330. //
  331. // Synopsis Make sure that the RAS services are enabled and running
  332. //
  333. // Arguments none
  334. //
  335. // Return FALSE - if the services couldn't be started
  336. //
  337. // History 10/16/96 ChrisK Created
  338. // 1/13/98 DONALDM Copied from ICW \\drywall\slm
  339. //
  340. //-----------------------------------------------------------------------------
  341. STDMETHODIMP CICWSystemConfig::VerifyRASIsRunning(BOOL *pbRetVal)
  342. {
  343. HINSTANCE hInst = NULL;
  344. FARPROC fp = NULL;
  345. HRESULT hr;
  346. *pbRetVal = FALSE; // Don't assume a positive result
  347. hInst = LoadLibrary(TEXT("INETCFG.DLL"));
  348. if (hInst)
  349. {
  350. fp = GetProcAddress(hInst, "InetStartServices");
  351. if (fp)
  352. {
  353. //
  354. // Check Services
  355. //
  356. hr = ((PFINETSTARTSERVICES)fp)();
  357. if (ERROR_SUCCESS == hr)
  358. {
  359. *pbRetVal = TRUE; // Success.
  360. }
  361. else
  362. {
  363. // Report the error, using the Current Active Window
  364. ::MessageBox(GetActiveWindow(), GetSz(IDS_SERVICEDISABLED),
  365. GetSz(IDS_TITLE),MB_MYERROR | MB_OK);
  366. }
  367. }
  368. FreeLibrary(hInst);
  369. }
  370. return S_OK;
  371. }
  372. const TCHAR szNetworkPolicies[] = REGSTR_PATH_POLICIES TEXT("\\") REGSTR_KEY_NETWORK;
  373. const TCHAR szDisableCaching[] = REGSTR_VAL_DISABLEPWDCACHING;
  374. //+----------------------------------------------------------------------------
  375. // Function CheckPasswordCachingPolicy
  376. //
  377. // Synopsis check to see if a policy as been set against password caching
  378. //
  379. // Arguments none
  380. //
  381. // Return TRUE - if password caching is disabled
  382. //
  383. // History
  384. //
  385. //-----------------------------------------------------------------------------
  386. STDMETHODIMP CICWSystemConfig::CheckPasswordCachingPolicy(BOOL *pbRetVal)
  387. {
  388. CMcRegistry reg;
  389. *pbRetVal = FALSE;
  390. // Open the Network policies key
  391. if (reg.OpenKey(HKEY_LOCAL_MACHINE, szNetworkPolicies))
  392. {
  393. DWORD dwVal = 0;
  394. // Get the disableCaching value
  395. if (reg.GetValue(szDisableCaching, dwVal))
  396. {
  397. // if set, then set the return code to TRUE.
  398. if(dwVal)
  399. {
  400. *pbRetVal = TRUE;
  401. TCHAR szLongString[1024];
  402. TCHAR *pszSmallString1, *pszSmallString2;
  403. // 4/28/97 ChrisK
  404. // Fix build break, because string was too long for compiler.
  405. pszSmallString1 = GetSz(IDS_PWCACHE_DISABLED1);
  406. pszSmallString2 = GetSz(IDS_PWCACHE_DISABLED2);
  407. lstrcpy(szLongString,pszSmallString1);
  408. lstrcat(szLongString,pszSmallString2);
  409. ::MessageBox(GetActiveWindow(),szLongString,GetSz(IDS_TITLE), MB_MYERROR);
  410. // We are going to kill the app, so hide it now
  411. ::ShowWindow(GetActiveWindow(), SW_HIDE);
  412. }
  413. }
  414. }
  415. return S_OK;
  416. }