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.

414 lines
12 KiB

  1. //---[ sfninf.cpp ]-----------------------------------------------------------
  2. //
  3. // NetWare client configuration notify object.
  4. // Functionality from old INF
  5. //
  6. //-----------------------------------------------------------------------------
  7. #include "pch.h"
  8. #pragma hdrstop
  9. #include "sfndef.h"
  10. #include "sfnobj.h"
  11. #include "ncreg.h"
  12. #include "ncsetup.h"
  13. //---[ Constants ]-------------------------------------------------------------
  14. const WCHAR g_szConfigDLLName[] = NW_CONFIG_DLL_NAME; // sfndef.h
  15. const WCHAR c_szLogin[] = L"\\Login";
  16. const WCHAR c_szPublic[] = L"\\Public";
  17. const WCHAR c_szCopyFilesLogin[] = L"CpyFiles_Login";
  18. const WCHAR c_szCopyFilesPublic[] = L"CpyFiles_Public";
  19. extern const WCHAR c_szFPNWVolumes[] = L"System\\CurrentControlSet\\Services\\FPNW\\Volumes";
  20. extern const WCHAR c_szSys[] = L"Sys";
  21. extern const WCHAR c_szPath[] = L"Path=";
  22. //---[ Typedefs ]--------------------------------------------------------------
  23. //---[ Prototypes ]------------------------------------------------------------
  24. HRESULT HrInstallFPNWPerfmonCounters();
  25. //-----------------------------------------------------------------------------
  26. //---[ CSFNCfg::HrCodeFromOldINF ]-------------------------------------------
  27. //
  28. // This contains all of the logic from the old oemnsvnw.inf, or at least
  29. // calls to helper functions that perform all of the logic. This runs pretty
  30. // much straight through the old installadapter code.
  31. //
  32. // Parameters - None
  33. //
  34. //-----------------------------------------------------------------------------
  35. HRESULT CSFNCfg::HrCodeFromOldINF()
  36. {
  37. HRESULT hr = S_OK;
  38. BOOL fResult = TRUE;
  39. hr = HrLoadConfigDLL();
  40. if (FAILED(hr))
  41. {
  42. goto Exit;
  43. }
  44. // Call the FPNWCFG function that tests for a running spooler.
  45. fResult = m_pfnIsSpoolerRunning();
  46. if (!fResult)
  47. {
  48. hr = E_FAIL;
  49. TraceHr(ttidSFNCfg, FAL, hr, FALSE, "HrCodeFromOldINF failed in SpoolerRunning");
  50. goto Exit;
  51. }
  52. hr = HrDoConfigDialog();
  53. if (FAILED(hr))
  54. {
  55. TraceHr(ttidSFNCfg, FAL, hr, FALSE, "HrCodeFromOldINF failed in HrDoConfigDialog");
  56. goto Exit;
  57. }
  58. hr = HrInstallFPNWPerfmonCounters();
  59. if (FAILED(hr))
  60. {
  61. TraceHr(ttidSFNCfg, FAL, hr, FALSE, "HrCodeFromOldINF failed in HrInstallFPNWPerfmonCounters");
  62. goto Exit;
  63. }
  64. Exit:
  65. TraceHr(ttidSFNCfg, FAL, hr, FALSE, "HrCodeFromOldINF");
  66. return hr;
  67. }
  68. //---[ CSFNCfg::HrLoadConfigDLL ]----------------------------------------------
  69. //
  70. // Load nwcfg.dll, so we can call some of the functions within. Also, do the
  71. // GetProcAddress calls for all of the functions that we might need.
  72. //
  73. // Parameters - None
  74. //
  75. //-----------------------------------------------------------------------------
  76. HRESULT CSFNCfg::HrLoadConfigDLL()
  77. {
  78. HRESULT hr = S_OK;
  79. AssertSz(!m_hlibConfig, "This should not be getting initialized twice");
  80. m_hlibConfig = LoadLibrary(g_szConfigDLLName);
  81. if (!m_hlibConfig)
  82. {
  83. DWORD dwLastError = GetLastError();
  84. TraceHr(ttidSFNCfg, FAL, hr, FALSE, "Failed to LoadLib the config DLL");
  85. hr = E_FAIL;
  86. goto Exit;
  87. }
  88. // Get DLL entry point for the IsSpoolerRunning API
  89. //
  90. m_pfnIsSpoolerRunning = (FPNWCFG_ISSPOOLERRUNNING_PROC)
  91. GetProcAddress(m_hlibConfig, "IsSpoolerRunning");
  92. // Get DLL entry point for the RunNcpDlg API
  93. //
  94. m_pfnRunNcpDlg = (FPNWCFG_RUNNCPDLG_PROC)
  95. GetProcAddress(m_hlibConfig, "RunNcpDlg");
  96. // Get DLL entry point for the CommitNcpDlg API
  97. //
  98. m_pfnCommitNcpDlg = (FPNWCFG_COMMITNCPDLG_PROC)
  99. GetProcAddress(m_hlibConfig, "FCommitNcpDlg");
  100. // Get DLL entry point for the RemoveNcpServer API
  101. //
  102. m_pfnRemoveNcpServer = (FPNWCFG_REMOVENCPSERVER_PROC)
  103. GetProcAddress(m_hlibConfig, "RemoveNcpServer");
  104. // If any of these are bogus, then we need to fail out.
  105. //
  106. if (!m_pfnIsSpoolerRunning || !m_pfnRunNcpDlg ||
  107. !m_pfnCommitNcpDlg || !m_pfnRemoveNcpServer)
  108. {
  109. TraceHr(ttidSFNCfg, FAL, hr, FALSE,
  110. "Failed to load one of the config DLL functions");
  111. hr = E_FAIL;
  112. goto Exit;
  113. }
  114. Exit:
  115. TraceHr(ttidSFNCfg, FAL, hr, FALSE, "CSFNCfg::HrLoadConfigDLL()");
  116. return hr;
  117. }
  118. //---[ CSFNCfg::FreeConfigDLL ]----------------------------------------------
  119. //
  120. // Free nwcfg.dll, and NULL out the function pointers.
  121. //
  122. // Parameters - None
  123. //
  124. //-----------------------------------------------------------------------------
  125. VOID CSFNCfg::FreeConfigDLL()
  126. {
  127. // If we successfully loaded the library, free it.
  128. if (m_hlibConfig)
  129. {
  130. // Free up the library resources.
  131. FreeLibrary(m_hlibConfig);
  132. m_hlibConfig = NULL;
  133. m_pfnIsSpoolerRunning = NULL;
  134. m_pfnRunNcpDlg = NULL;
  135. m_pfnCommitNcpDlg = NULL;
  136. }
  137. }
  138. //+---------------------------------------------------------------------------
  139. //
  140. // Function: HrInstallFPNWPerfmonCounters
  141. //
  142. // Purpose: Install FPNW perfmon counters (what did you think it did?)
  143. //
  144. // Arguments:
  145. // (none)
  146. //
  147. // Returns:
  148. //
  149. // Author: jeffspr 5 Feb 1998
  150. //
  151. // Notes:
  152. //
  153. HRESULT HrInstallFPNWPerfmonCounters()
  154. {
  155. HRESULT hr = NOERROR;
  156. BOOL fResult = FALSE;
  157. STARTUPINFO si;
  158. PROCESS_INFORMATION pi;
  159. WCHAR szIniPath[MAX_PATH+1];
  160. WCHAR szCmdLine[MAX_PATH+1];
  161. ZeroMemory((LPVOID) &si, sizeof(si));
  162. si.cb = sizeof(STARTUPINFO);
  163. if (GetSystemDirectory(szIniPath, MAX_PATH+1))
  164. {
  165. wsprintfW(szCmdLine, L"lodctr %s\\fpnwperf.ini", szIniPath);
  166. fResult = CreateProcess(NULL, szCmdLine, NULL, NULL,
  167. FALSE, 0, NULL, NULL, &si, &pi);
  168. if (!fResult)
  169. {
  170. hr = HrFromLastWin32Error();
  171. }
  172. }
  173. else
  174. {
  175. hr = E_FAIL;
  176. }
  177. TraceHr(ttidSFNCfg, FAL, hr, FALSE, "HrInstallFPNWPerfmonCounters");
  178. return hr;
  179. }
  180. HRESULT HrCopySysVolFiles2(INetCfgComponent * pncc, PWSTR pszPath)
  181. {
  182. TraceFileFunc(ttidSFNCfg);
  183. HWND hwndParent = GetActiveWindow();
  184. HRESULT hr;
  185. CSetupInfFile csif;
  186. PSP_FILE_CALLBACK pfc;
  187. PVOID pvCtx;
  188. HSPFILEQ hfq;
  189. tstring str;
  190. // Open the answer file.
  191. hr = csif.HrOpen(L"netsfn.inf", NULL, INF_STYLE_OLDNT | INF_STYLE_WIN4, NULL);
  192. if (FAILED(hr))
  193. {
  194. goto Error;
  195. }
  196. TraceTag(ttidSFNCfg, "Calling SetupOpenFileQueue");
  197. hr = HrSetupOpenFileQueue(&hfq);
  198. if (SUCCEEDED(hr))
  199. {
  200. TraceTag(ttidSFNCfg, "Calling HrAddSectionFilesToQueue - Login");
  201. str = pszPath;
  202. str += c_szLogin;
  203. if (!SetupSetDirectoryId(csif.Hinf(), 32768, str.c_str()))
  204. {
  205. hr = ::HrFromLastWin32Error();
  206. }
  207. if (SUCCEEDED(hr))
  208. {
  209. TraceTag(ttidSFNCfg, "Calling SetupInstallFilesFromInfSection - Login");
  210. hr = HrSetupInstallFilesFromInfSection(csif.Hinf(), NULL, hfq,
  211. c_szCopyFilesLogin, NULL, 0);
  212. }
  213. TraceTag(ttidSFNCfg, "Calling SetupSetDirectoryId - Public");
  214. str = pszPath;
  215. str += c_szPublic;
  216. if (!SetupSetDirectoryId(csif.Hinf(), 32769, str.c_str()))
  217. {
  218. hr = ::HrFromLastWin32Error();
  219. }
  220. if (SUCCEEDED(hr))
  221. {
  222. TraceTag(ttidSFNCfg, "Calling SetupInstallFilesFromInfSection - Public");
  223. hr = HrSetupInstallFilesFromInfSection(csif.Hinf(), NULL, hfq,
  224. c_szCopyFilesPublic, NULL, 0);
  225. }
  226. // Set the default callback context
  227. // If the install is quiet, we need to make sure the callback
  228. // doesn't display UI
  229. //
  230. if (SUCCEEDED(hr))
  231. {
  232. TraceTag(ttidSFNCfg, "Calling SetupInitDefaultQueueCallbackEx");
  233. hr = HrSetupInitDefaultQueueCallbackEx(hwndParent, NULL, 0, 0,
  234. NULL, &pvCtx);
  235. }
  236. if (SUCCEEDED(hr))
  237. {
  238. // Not doing anything special so use SetupApi default handler
  239. // for file copy
  240. pfc = SetupDefaultQueueCallback;
  241. // Scan the queue to see if the files are already in the
  242. // destination and if so, ask the user if he/she wants to
  243. // use what's there (provided we are not doing a quiet install)
  244. // Note: we only scan the queue if we are not in Gui mode setup
  245. //
  246. DWORD dwScanResult;
  247. TraceTag(ttidSFNCfg, "Scanning queue for validity");
  248. hr = HrSetupScanFileQueueWithNoCallback(hfq,
  249. SPQ_SCAN_FILE_VALIDITY | SPQ_SCAN_INFORM_USER,
  250. hwndParent, &dwScanResult);
  251. // Now commit the queue so any files needing to be
  252. // copied, will be
  253. //
  254. if (SUCCEEDED(hr))
  255. {
  256. TraceTag(ttidSFNCfg, "Calling SetupCommitFileQueue");
  257. hr = HrSetupCommitFileQueue(hwndParent, hfq, pfc, pvCtx);
  258. }
  259. TraceTag(ttidSFNCfg, "Closing queue");
  260. // We need to release the default context
  261. //
  262. SetupTermDefaultQueueCallback(pvCtx);
  263. }
  264. // close the file queue
  265. //
  266. SetupCloseFileQueue(hfq);
  267. // Unregister the copy directories
  268. //
  269. SetupSetDirectoryId(csif.Hinf(), 8001, NULL);
  270. SetupSetDirectoryId(csif.Hinf(), 8002, NULL);
  271. }
  272. Error:
  273. TraceHr(ttidSFNCfg, FAL, hr, FALSE, "HrCopySysVolFiles2");
  274. return hr;
  275. }
  276. HRESULT HrCopySysVolFiles(INetCfgComponent * pncc)
  277. {
  278. HRESULT hr = S_OK;
  279. HKEY hkey = NULL;
  280. PWSTR psz = NULL;
  281. PWSTR pszTmp;
  282. Assert(NULL != pncc);
  283. // Open the HKLM "System\\CurrentControlSet\\Services\\FPNW\\Volumes" key
  284. //
  285. hr = HrRegOpenKeyEx(HKEY_LOCAL_MACHINE, c_szFPNWVolumes, KEY_ALL_ACCESS, &hkey);
  286. if (FAILED(hr))
  287. {
  288. TraceHr(ttidSFNCfg, FAL, hr, FALSE, "HrCopySysVolFiles - Volumes key open failed");
  289. goto Error;
  290. }
  291. // Get the "Sys" value
  292. hr = HrRegQueryMultiSzWithAlloc(hkey, c_szSys, &psz);
  293. if (FAILED(hr) || !psz || !(*psz))
  294. {
  295. TraceHr(ttidSFNCfg, FAL, hr, FALSE, "HrCopySysVolFiles - Sys value open failed");
  296. goto Error;
  297. }
  298. // Find the "Path=" multi-sz entry
  299. //
  300. for (pszTmp = psz; (*pszTmp); pszTmp += wcslen(pszTmp))
  301. {
  302. if (0 == _wcsnicmp(pszTmp, c_szPath, wcslen(c_szPath)))
  303. {
  304. pszTmp += wcslen(c_szPath);
  305. break;
  306. }
  307. }
  308. // If the pszPath points to a character then we found the path
  309. //
  310. Assert(pszTmp);
  311. if (*pszTmp)
  312. {
  313. hr = HrCopySysVolFiles2(pncc, pszTmp);
  314. }
  315. else
  316. {
  317. TraceHr(ttidSFNCfg, FAL, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
  318. FALSE, "HrCopySysVolFiles - Sys volume path is missing!");
  319. }
  320. Error:
  321. RegSafeCloseKey(hkey);
  322. MemFree(psz);
  323. // Normalize return code. File not found can occur if the Volumes key
  324. // is not present or if the Sys value is missing. The original NT 4 inf
  325. // code treated these as acceptable.
  326. if (HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) == hr)
  327. {
  328. hr = S_OK;
  329. }
  330. TraceHr(ttidSFNCfg, FAL, hr, FALSE, "HrCopySysVolFiles");
  331. return hr;
  332. }
  333. HRESULT CSFNCfg::HrDoConfigDialog()
  334. {
  335. HRESULT hr = S_OK;
  336. BOOL fResult = FALSE;
  337. BOOL fConfigChanged = FALSE;
  338. fResult = m_pfnRunNcpDlg(NULL, TRUE, &m_pNcpInfoHandle, &fConfigChanged);
  339. if (!fResult)
  340. {
  341. hr = E_FAIL;
  342. goto Exit;
  343. }
  344. Exit:
  345. return hr;
  346. }