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.

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