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.

298 lines
7.9 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // sdopipemgr.cpp
  8. //
  9. //
  10. // SYNOPSIS
  11. //
  12. // Defines the class PipelineMgr.
  13. //
  14. // MODIFICATION HISTORY
  15. //
  16. // 02/03/2000 Original version.
  17. //
  18. ///////////////////////////////////////////////////////////////////////////////
  19. #include "stdafx.h"
  20. #include <sdocomponentfactory.h>
  21. #include <sdohelperfuncs.h>
  22. #include <sdopipemgr.h>
  23. #define IAS_PROVIDER_MICROSOFT_RADIUS_PROXY 8
  24. #define IAS_PROVIDER_MICROSOFT_PROXY_POLICY 5
  25. _COM_SMARTPTR_TYPEDEF(ISdo, __uuidof(ISdo));
  26. _COM_SMARTPTR_TYPEDEF(ISdoCollection, __uuidof(ISdoCollection));
  27. HRESULT PipelineMgr::Initialize(ISdo* pSdoService) throw ()
  28. {
  29. using _com_util::CheckError;
  30. try
  31. {
  32. // Get the request handlers collection.
  33. _variant_t disp;
  34. CheckError(pSdoService->GetProperty(
  35. PROPERTY_IAS_REQUESTHANDLERS_COLLECTION,
  36. &disp
  37. ));
  38. ISdoCollectionPtr handlers(disp);
  39. // Get the number of handlers to be managed.
  40. long count;
  41. CheckError(handlers->get_Count(&count));
  42. // Reserve space in our internal collection ...
  43. components.reserve(count);
  44. // ... and create a SAFEARRAY to give to the pipline.
  45. _variant_t result;
  46. SAFEARRAYBOUND bound[2] = { { count, 0 }, { 2, 0 } };
  47. V_ARRAY(&result) = SafeArrayCreate(VT_VARIANT, 2, bound);
  48. if (!V_ARRAY(&result)) { _com_issue_error(E_OUTOFMEMORY); }
  49. V_VT(&result) = VT_ARRAY | VT_VARIANT;
  50. // The next element in the SAFEARRAY to be populated.
  51. VARIANT* next = (VARIANT*)V_ARRAY(&result)->pvData;
  52. // Get an enumerator on the handler collection.
  53. IUnknownPtr unk;
  54. CheckError(handlers->get__NewEnum(&unk));
  55. IEnumVARIANTPtr iter(unk);
  56. // Iterate through the handlers.
  57. _variant_t element;
  58. unsigned long fetched;
  59. while (iter->Next(1, &element, &fetched) == S_OK && fetched == 1)
  60. {
  61. // Get an SDO from the VARIANT.
  62. ISdoPtr handler(element);
  63. element.Clear();
  64. // Get the handlers ProgID ...
  65. CheckError(handler->GetProperty(PROPERTY_COMPONENT_PROG_ID, next));
  66. // ... and create the COM component.
  67. IUnknownPtr object(V_BSTR(next), NULL, CLSCTX_INPROC_SERVER);
  68. // Store the component in the SAFEARRAY.
  69. V_VT(++next) = VT_UNKNOWN;
  70. (V_UNKNOWN(next) = object)->AddRef();
  71. ++next;
  72. // Create the wrapper.
  73. _variant_t id;
  74. CheckError(handler->GetProperty(PROPERTY_COMPONENT_ID, &id));
  75. ComponentPtr component = MakeComponent(
  76. COMPONENT_TYPE_REQUEST_HANDLER,
  77. V_I4(&id)
  78. );
  79. // Initialize the wrapper.
  80. CheckError(component->PutObject(object, __uuidof(IIasComponent)));
  81. CheckError(component->Initialize(pSdoService));
  82. // Save it in our internal collection.
  83. components.push_back(component);
  84. }
  85. // Create and initialize the pipeline.
  86. pipeline.CreateInstance(L"IAS.Pipeline", NULL, CLSCTX_INPROC_SERVER);
  87. CheckError(pipeline->InitNew());
  88. CheckError(pipeline->PutProperty(0, &result));
  89. CheckError(pipeline->Initialize());
  90. }
  91. catch (const _com_error& ce)
  92. {
  93. return ce.Error();
  94. }
  95. catch (const std::bad_alloc&)
  96. {
  97. return E_OUTOFMEMORY;
  98. }
  99. catch (...)
  100. {
  101. return E_FAIL;
  102. }
  103. return S_OK;
  104. }
  105. HRESULT PipelineMgr::Configure(ISdo* pSdoService) throw ()
  106. {
  107. // Configure each of the components.
  108. for (ComponentIterator i = components.begin(); i != components.end(); ++i)
  109. {
  110. (*i)->Configure(pSdoService);
  111. }
  112. return S_OK;
  113. }
  114. void PipelineMgr::Shutdown()
  115. {
  116. for (ComponentIterator i = components.begin(); i != components.end(); ++i)
  117. {
  118. (*i)->Suspend();
  119. (*i)->Shutdown();
  120. }
  121. components.clear();
  122. pipeline->Shutdown();
  123. pipeline.Attach(NULL);
  124. }
  125. HRESULT PipelineMgr::GetPipeline(IRequestHandler** handler) throw ()
  126. {
  127. return pipeline->QueryInterface(
  128. __uuidof(IRequestHandler),
  129. (PVOID*)handler
  130. );
  131. }
  132. void LinkPoliciesToEnforcer(
  133. ISdo* service,
  134. LONG policiesAlias,
  135. LONG profilesAlias,
  136. LONG handlerAlias
  137. )
  138. {
  139. using _com_util::CheckError;
  140. // Get an enumerator for the policies collection.
  141. IEnumVARIANTPtr policies;
  142. CheckError(SDOGetCollectionEnumerator(
  143. service,
  144. policiesAlias,
  145. &policies
  146. ));
  147. // Get the profiles collection.
  148. _variant_t profilesProperty;
  149. CheckError(service->GetProperty(
  150. profilesAlias,
  151. &profilesProperty
  152. ));
  153. ISdoCollectionPtr profiles(profilesProperty);
  154. // Iterate through the policies.
  155. ISdoPtr policy;
  156. while (SDONextObjectFromCollection(policies, &policy) == S_OK)
  157. {
  158. // Get the policy name ...
  159. _variant_t name;
  160. CheckError(policy->GetProperty(
  161. PROPERTY_SDO_NAME,
  162. &name
  163. ));
  164. // ... and find the corresponding profile.
  165. IDispatchPtr item;
  166. CheckError(profiles->Item(&name, &item));
  167. ISdoPtr profile(item);
  168. // Get the attributes collection from the profile ...
  169. _variant_t attributes;
  170. CheckError(profile->GetProperty(
  171. PROPERTY_PROFILE_ATTRIBUTES_COLLECTION,
  172. &attributes
  173. ));
  174. // ... and link it to the policy.
  175. CheckError(policy->PutProperty(
  176. PROPERTY_POLICY_ACTION,
  177. &attributes
  178. ));
  179. }
  180. // Get the request handler that will enforce these policies.
  181. ISdoPtr handler;
  182. CheckError(SDOGetComponentFromCollection(
  183. service,
  184. PROPERTY_IAS_REQUESTHANDLERS_COLLECTION,
  185. handlerAlias,
  186. &handler
  187. ));
  188. // Get the policy collection as a variant ...
  189. _variant_t policiesValue;
  190. CheckError(service->GetProperty(
  191. policiesAlias,
  192. &policiesValue
  193. ));
  194. // ... and link it to the handler.
  195. CheckError(handler->PutProperty(
  196. PROPERTY_NAP_POLICIES_COLLECTION,
  197. &policiesValue
  198. ));
  199. }
  200. VOID
  201. WINAPI
  202. LinkGroupsToProxy(
  203. ISdo* service,
  204. IDataStoreObject* ias
  205. )
  206. {
  207. using _com_util::CheckError;
  208. ISdoPtr proxy;
  209. CheckError(SDOGetComponentFromCollection(
  210. service,
  211. PROPERTY_IAS_REQUESTHANDLERS_COLLECTION,
  212. IAS_PROVIDER_MICROSOFT_RADIUS_PROXY,
  213. &proxy
  214. ));
  215. _variant_t v(ias);
  216. CheckError(proxy->PutProperty(
  217. PROPERTY_RADIUSPROXY_SERVERGROUPS,
  218. &v
  219. ));
  220. }
  221. HRESULT
  222. WINAPI
  223. LinkHandlerProperties(
  224. ISdo* pSdoService,
  225. IDataStoreObject* pDsObject
  226. ) throw ()
  227. {
  228. try
  229. {
  230. LinkPoliciesToEnforcer(
  231. pSdoService,
  232. PROPERTY_IAS_POLICIES_COLLECTION,
  233. PROPERTY_IAS_PROFILES_COLLECTION,
  234. IAS_PROVIDER_MICROSOFT_NAP
  235. );
  236. LinkPoliciesToEnforcer(
  237. pSdoService,
  238. PROPERTY_IAS_PROXYPOLICIES_COLLECTION,
  239. PROPERTY_IAS_PROXYPROFILES_COLLECTION,
  240. IAS_PROVIDER_MICROSOFT_PROXY_POLICY
  241. );
  242. LinkGroupsToProxy(
  243. pSdoService,
  244. pDsObject
  245. );
  246. }
  247. catch (const _com_error& ce)
  248. {
  249. return ce.Error();
  250. }
  251. catch (...)
  252. {
  253. return E_FAIL;
  254. }
  255. return S_OK;
  256. }