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.

304 lines
7.0 KiB

  1. //
  2. // S F N O B J . C P P
  3. //
  4. // Implementation of the CSFNCfg notify object model
  5. //
  6. #include "pch.h"
  7. #pragma hdrstop
  8. #include "sfnobj.h"
  9. #include "ncatlui.h"
  10. #include "ncui.h"
  11. #include "ncreg.h"
  12. #include "ncmisc.h"
  13. extern const WCHAR c_szFPNWVolumes[];
  14. extern const WCHAR c_szSys[];
  15. extern const WCHAR c_szPath[];
  16. extern const WCHAR c_szBackslash[];
  17. extern const WCHAR c_szInfId_MS_NwSapAgent[];
  18. static const WCHAR c_szSysVolRoot[] = L"C:\\SysVol";
  19. //---[ Prototypes ]-----------------------------------------------------------
  20. HRESULT HrCopySysVolFiles(INetCfgComponent * pncc);
  21. //
  22. // Destructor
  23. //
  24. CSFNCfg::CSFNCfg()
  25. {
  26. // Initialize member variables.
  27. m_pnc = NULL;
  28. m_pncc = NULL;
  29. m_eInstallAction = eActUnknown;
  30. m_fDirty = FALSE;
  31. m_fAlreadyInstalled = FALSE;
  32. // Config lib stuff
  33. m_hlibConfig = NULL;
  34. m_pfnIsSpoolerRunning = NULL;
  35. m_pfnRunNcpDlg = NULL;
  36. m_pfnRemoveNcpServer = NULL;
  37. m_pfnCommitNcpDlg = NULL;
  38. // Propsheet pages
  39. m_apspObj[0] = NULL;
  40. m_apspObj[1] = NULL;
  41. m_dwTuning = c_dwDefaultTuning;
  42. m_szSysVol[0] = L'\0';
  43. m_szFPNWServerName[0] = L'\0';
  44. m_pNcpInfoHandle = NULL;
  45. }
  46. CSFNCfg::~CSFNCfg()
  47. {
  48. ReleaseObj(m_pncc);
  49. ReleaseObj(m_pnc);
  50. }
  51. //
  52. // INetCfgNotify
  53. //
  54. STDMETHODIMP CSFNCfg::Initialize( INetCfgComponent * pnccItem,
  55. INetCfg* pnc,
  56. BOOL fInstalling)
  57. {
  58. Validate_INetCfgNotify_Initialize(pnccItem, pnc, fInstalling);
  59. m_pncc = pnccItem;
  60. m_pnc = pnc;
  61. AssertSz(m_pncc, "m_pncc NULL in CSFNCfg::Initialize");
  62. AssertSz(m_pnc, "m_pnc NULL in CSFNCfg::Initialize");
  63. // Determine if already installed. Don't trust the fInstalling, because
  64. // this component is a have disk component and we don't want to do
  65. // much if already installed.
  66. //
  67. // Addref the config objects
  68. //
  69. AddRefObj(m_pncc);
  70. AddRefObj(m_pnc);
  71. return S_OK;
  72. }
  73. STDMETHODIMP CSFNCfg::Upgrade(DWORD dwSetupFlags,
  74. DWORD dwUpgradeFromBuildNo)
  75. {
  76. // during first time install, perform some basic tasks that aren't related
  77. // to bindings
  78. if (dwSetupFlags & NSF_POSTSYSINSTALL)
  79. {
  80. HRESULT hr = HrCodeFromOldINF();
  81. if (SUCCEEDED(hr))
  82. {
  83. m_fDirty = TRUE;
  84. }
  85. }
  86. return S_OK;
  87. }
  88. STDMETHODIMP CSFNCfg::ReadAnswerFile(PCWSTR pszAnswerFile,
  89. PCWSTR pszAnswerSection)
  90. {
  91. return S_OK;
  92. }
  93. STDMETHODIMP CSFNCfg::Install(DWORD dw)
  94. {
  95. HRESULT hr = S_OK;
  96. NT_PRODUCT_TYPE pt;
  97. Validate_INetCfgNotify_Install(dw);
  98. m_eInstallAction = eActInstall;
  99. RtlGetNtProductType (&pt);
  100. if (NtProductLanManNt != pt)
  101. {
  102. // Return a warning instead of an error so the UI won't popup an
  103. // error dialog after we've already notified the user of why the
  104. // install failed.
  105. //
  106. // Tell the user that they can't install on this platform.
  107. //
  108. NcMsgBox(GetActiveWindow(), IDS_FPNW_CAPTION,
  109. IDS_WKS_ONLY, MB_OK | MB_ICONINFORMATION);
  110. hr = E_FAIL;
  111. TraceTag(ttidSFNCfg, "User tried to install on machine other than a DC, this is not allowed.");
  112. goto Error;
  113. }
  114. // Install SAP, which should install nwlnkipx
  115. //
  116. hr = HrInstallComponentOboComponent(m_pnc, NULL,
  117. GUID_DEVCLASS_NETSERVICE,
  118. c_szInfId_MS_NwSapAgent,
  119. m_pncc,
  120. NULL);
  121. if (FAILED(hr))
  122. {
  123. goto Error;
  124. }
  125. // Write the sysvol info if not already present
  126. //
  127. hr = HrWriteDefaultSysVol();
  128. if (FAILED(hr))
  129. {
  130. goto Error;
  131. }
  132. // Call the fpnw configuration code and have it do it's stuff
  133. //
  134. hr = HrCodeFromOldINF();
  135. if (FAILED(hr))
  136. {
  137. goto Error;
  138. }
  139. // Copy files to the location the user specified in the fpnw dialog
  140. //
  141. hr = HrCopySysVolFiles(m_pncc);
  142. if (SUCCEEDED(hr))
  143. {
  144. m_fDirty = TRUE;
  145. }
  146. Error:
  147. // Validate_INetCfgNotify_Install_Return(hr);
  148. TraceError("CSFNCfg::Install", hr);
  149. return hr;
  150. }
  151. HRESULT CSFNCfg::HrWriteDefaultSysVol()
  152. {
  153. HRESULT hr;
  154. PWSTR pszValue = NULL;
  155. tstring str;
  156. str = c_szFPNWVolumes;
  157. str += c_szBackslash;
  158. str += c_szSys;
  159. hr = HrRegQueryMultiSzWithAlloc(HKEY_LOCAL_MACHINE, str.c_str(),
  160. &pszValue);
  161. if (HRESULT_FROM_WIN32 (ERROR_FILE_NOT_FOUND) == hr)
  162. {
  163. // Not found is ok, we need to write the default value
  164. //
  165. str = c_szPath;
  166. str += c_szSysVolRoot;
  167. hr = HrRegAddStringToMultiSz(str.c_str(), HKEY_LOCAL_MACHINE,
  168. c_szFPNWVolumes, c_szSys,
  169. STRING_FLAG_ENSURE_AT_END,
  170. 0);
  171. }
  172. else if (S_OK == hr)
  173. {
  174. // Just clean up
  175. MemFree(pszValue);
  176. }
  177. TraceError("CSFNCfg::HrWriteDefaultSysVol", hr);
  178. return hr;
  179. }
  180. STDMETHODIMP CSFNCfg::Removing()
  181. {
  182. m_eInstallAction = eActInstall;
  183. HRESULT hr = HrLoadConfigDLL();
  184. if (SUCCEEDED(hr))
  185. {
  186. m_fDirty = TRUE;
  187. // Remove the SAP Agent service
  188. hr = HrRemoveComponentOboComponent(m_pnc,
  189. GUID_DEVCLASS_NETSERVICE,
  190. c_szInfId_MS_NwSapAgent,
  191. m_pncc);
  192. if (hr == NETCFG_S_STILL_REFERENCED)
  193. {
  194. // If services are still in use, that's OK, I just needed to make
  195. // sure that I released my reference.
  196. //
  197. hr = S_OK;
  198. }
  199. }
  200. Validate_INetCfgNotify_Removing_Return(hr);
  201. TraceError("CSFNCfg::Removing", hr);
  202. return hr;
  203. }
  204. STDMETHODIMP CSFNCfg::Validate()
  205. {
  206. return S_OK;
  207. }
  208. STDMETHODIMP CSFNCfg::CancelChanges()
  209. {
  210. return S_OK;
  211. }
  212. STDMETHODIMP CSFNCfg::ApplyRegistryChanges()
  213. {
  214. HRESULT hr = S_OK;
  215. BOOL fResult = TRUE;
  216. if (m_fDirty)
  217. {
  218. if (eActInstall == m_eInstallAction)
  219. {
  220. Assert(m_pfnCommitNcpDlg);
  221. Assert(m_pNcpInfoHandle);
  222. // The TRUE below means that we're installing.
  223. //
  224. fResult = m_pfnCommitNcpDlg(NULL, TRUE, m_pNcpInfoHandle);
  225. if (FALSE == fResult)
  226. {
  227. hr = E_FAIL;
  228. }
  229. }
  230. else if (eActRemove == m_eInstallAction)
  231. {
  232. // Removing
  233. Assert(m_pfnRemoveNcpServer);
  234. if (FALSE == m_pfnRemoveNcpServer(NULL))
  235. {
  236. hr = E_FAIL;
  237. }
  238. }
  239. }
  240. else
  241. {
  242. hr = S_FALSE;
  243. }
  244. Validate_INetCfgNotify_Apply_Return(hr);
  245. TraceError("CSFNCfg::ApplyRegistryChanges",
  246. (hr == S_FALSE) ? S_OK : hr);
  247. return hr;
  248. }