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.

340 lines
7.8 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1999.
  5. //
  6. // File: N C I A S . C P P
  7. //
  8. // Contents: Installation support for IAS service
  9. //
  10. // Notes:
  11. //
  12. // Author: tperraut 02/22/1999
  13. //
  14. // Revision: tperraut 01/19/2000 bugs 444353, 444354, 444355
  15. //
  16. //----------------------------------------------------------------------------
  17. #include "pch.h"
  18. #pragma hdrstop
  19. #include "netoc.h"
  20. #include "ncreg.h"
  21. #include "ncias.h"
  22. #include "ncstring.h"
  23. #include "userenv.h"
  24. static const char c_szIASRegisterFunctionName[] = "IASDirectoryRegisterService";
  25. static const char c_szIASUnRegisterFunctionName[] = "IASDirectoryUnregisterService";
  26. static const WCHAR c_szIASDllName[] = L"ias.dll";
  27. //+---------------------------------------------------------------------------
  28. //
  29. // Function: HrOcIASRegisterActiveDirectory
  30. //
  31. // Purpose: Try to register IAS in the Active Directory
  32. // if the computer is part of a Win2k domain...
  33. //
  34. // Arguments:
  35. //
  36. // Returns: S_OK if successful, Win32 error otherwise.
  37. //
  38. // Notes:
  39. //
  40. // Author: Thierry Perraut (tperraut)
  41. //
  42. HRESULT HrOcIASUnRegisterActiveDirectory()
  43. {
  44. typedef INT_PTR (WINAPI *UNREGISTER_IAS_ACTIVE_DIRECTORY)();
  45. UNREGISTER_IAS_ACTIVE_DIRECTORY pfnUnRegisterIASActiveDirectory;
  46. ///////////////////
  47. // Load ias.dll
  48. ///////////////////
  49. HMODULE hmod;
  50. HRESULT hr = HrLoadLibAndGetProc (
  51. c_szIASDllName,
  52. c_szIASUnRegisterFunctionName,
  53. &hmod,
  54. &pfnUnRegisterIASActiveDirectory
  55. );
  56. if (S_OK == hr)
  57. {
  58. // fix bug 444354
  59. // pfnUnRegisterIASActiveDirectory not NULL here
  60. if (!FAILED (CoInitialize(NULL)))
  61. {
  62. LONG lresult = pfnUnRegisterIASActiveDirectory();
  63. if (ERROR_SUCCESS != lresult)
  64. {
  65. hr = S_OK; //not a fatal error, should be ignored
  66. }
  67. CoUninitialize();
  68. }
  69. FreeLibrary(hmod);
  70. }
  71. // Errors ignored
  72. hr = S_OK;
  73. return hr;
  74. }
  75. //+---------------------------------------------------------------------------
  76. //
  77. // Function: HrOcIASUnRegisterActiveDirectory
  78. //
  79. // Purpose: Try to remove IAS from the Active Directory
  80. // if the computer is part of a Win2k domain...
  81. //
  82. // Arguments:
  83. //
  84. // Returns: S_OK if successful, Win32 error otherwise.
  85. //
  86. // Notes:
  87. //
  88. // Author: Thierry Perraut (tperraut)
  89. //
  90. HRESULT HrOcIASRegisterActiveDirectory()
  91. {
  92. typedef INT_PTR (WINAPI *REGISTER_IAS_ACTIVE_DIRECTORY)();
  93. REGISTER_IAS_ACTIVE_DIRECTORY pfnRegisterIASActiveDirectory;
  94. ///////////////////
  95. // Load ias.dll
  96. ///////////////////
  97. HMODULE hmod;
  98. HRESULT hr = HrLoadLibAndGetProc (
  99. c_szIASDllName,
  100. c_szIASRegisterFunctionName,
  101. &hmod,
  102. &pfnRegisterIASActiveDirectory
  103. );
  104. if (S_OK == hr)
  105. {
  106. // Fix bug 444353
  107. // pfnRegisterIASActiveDirectory not NULL here
  108. if (!FAILED (CoInitialize(NULL)))
  109. {
  110. LONG lresult = pfnRegisterIASActiveDirectory();
  111. if (ERROR_SUCCESS != lresult)
  112. {
  113. hr = S_OK; //not a fatal error, should be ignored
  114. }
  115. CoUninitialize();
  116. }
  117. FreeLibrary(hmod);
  118. }
  119. // Errors ignored
  120. hr = S_OK;
  121. return hr;
  122. }
  123. HRESULT HrOcIASDisableLMAuthentication()
  124. {
  125. static const WCHAR IASLMAuthKey[] = L"SYSTEM\\CurrentControlSet\\Services\\RemoteAccess\\Policy";
  126. static const WCHAR IASLMAuthValue[] = L"Allow LM Authentication";
  127. HKEY key = NULL;
  128. HRESULT hr = HrRegOpenKeyEx(
  129. HKEY_LOCAL_MACHINE,
  130. IASLMAuthKey,
  131. KEY_SET_VALUE | KEY_EXECUTE | KEY_QUERY_VALUE,
  132. &key
  133. );
  134. if (SUCCEEDED(hr))
  135. {
  136. hr = HrRegQueryValueEx (
  137. key,
  138. IASLMAuthValue,
  139. NULL,
  140. NULL,
  141. NULL
  142. );
  143. if (FAILED(hr))
  144. {
  145. DWORD value = 0;
  146. // No such value: create it
  147. hr = HrRegSetValueEx(
  148. key,
  149. IASLMAuthValue,
  150. REG_DWORD,
  151. reinterpret_cast<BYTE*>(&value),
  152. sizeof(value)
  153. );
  154. }
  155. RegSafeCloseKey(key);
  156. }
  157. hr = S_OK;
  158. return hr;
  159. }
  160. //+---------------------------------------------------------------------------
  161. //
  162. // Function: HrOcIASPreInf
  163. //
  164. // Purpose: Called when IAS service is being installed/upgraded/removed.
  165. // Called before the processing of the INF file
  166. //
  167. // Arguments:
  168. // pnocd [in] Pointer to NETOC data.
  169. //
  170. // Returns: S_OK if successful, Win32 error otherwise.
  171. //
  172. // Notes:
  173. //
  174. // Author: Thierry Perraut (tperraut)
  175. //
  176. HRESULT HrOcIASPreInf(const PNETOCDATA pnocd)
  177. {
  178. HRESULT hr;
  179. switch(pnocd->eit)
  180. {
  181. case IT_INSTALL:
  182. {
  183. // Place holder
  184. hr = S_OK;
  185. break;
  186. }
  187. case IT_REMOVE:
  188. {
  189. // Place holder
  190. hr = S_OK;
  191. break;
  192. }
  193. case IT_UPGRADE:
  194. {
  195. // Place holder
  196. hr = S_OK;
  197. break;
  198. }
  199. default:
  200. {
  201. hr = S_OK; // some new messages should not be seen as errors
  202. }
  203. }
  204. TraceError("HrOcIASPreInf", hr);
  205. return hr;
  206. }
  207. //+---------------------------------------------------------------------------
  208. //
  209. // Function: HrOcIASPostInstall
  210. //
  211. // Purpose: Called when IAS service is being installed/upgraded/removed.
  212. // Called after the processing of the INF file
  213. //
  214. // Arguments:
  215. // pnocd [in] Pointer to NETOC data.
  216. //
  217. // Returns: S_OK if successful, Win32 error otherwise.
  218. //
  219. // Notes:
  220. //
  221. // Author: Thierry Perraut (tperraut)
  222. //
  223. HRESULT HrOcIASPostInstall(const PNETOCDATA pnocd)
  224. {
  225. HRESULT hr;
  226. switch(pnocd->eit)
  227. {
  228. case IT_INSTALL:
  229. {
  230. // Disable LM AUthentication on clean installs
  231. hr = HrOcIASDisableLMAuthentication();
  232. // ignore the result
  233. // call the Active Directory registration code here
  234. hr = HrOcIASRegisterActiveDirectory();
  235. break;
  236. }
  237. case IT_REMOVE:
  238. {
  239. // call the Active Directory clean code here
  240. hr = HrOcIASUnRegisterActiveDirectory();
  241. break;
  242. }
  243. case IT_UPGRADE:
  244. {
  245. hr = S_OK;
  246. break;
  247. }
  248. default:
  249. {
  250. hr = S_OK; // some new messages should not be seen as errors
  251. }
  252. }
  253. TraceError("HrOcIASPostInstall", hr);
  254. return hr;
  255. }
  256. //+---------------------------------------------------------------------------
  257. //
  258. // Function: HrOcExtIAS
  259. //
  260. // Purpose: NetOC external message handler
  261. //
  262. // Arguments:
  263. // pnocd []
  264. // uMsg []
  265. // wParam []
  266. // lParam []
  267. //
  268. // Returns:
  269. //
  270. // Author: tperraut 02/22/1999
  271. //
  272. // Notes:
  273. //
  274. HRESULT HrOcExtIAS(PNETOCDATA pnocd, UINT uMsg,
  275. WPARAM wParam, LPARAM lParam)
  276. {
  277. HRESULT hr;
  278. Assert(pnocd);
  279. switch (uMsg)
  280. {
  281. case NETOCM_PRE_INF:
  282. {
  283. hr = HrOcIASPreInf(pnocd);
  284. break;
  285. }
  286. case NETOCM_POST_INSTALL:
  287. {
  288. hr = HrOcIASPostInstall(pnocd);
  289. break;
  290. }
  291. default:
  292. {
  293. hr = S_OK; // some new messages should not be seen as errors
  294. }
  295. }
  296. TraceError("HrOcExtIAS", hr);
  297. return hr;
  298. }