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.

820 lines
26 KiB

  1. /********************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. SAFReg.cpp
  5. Abstract:
  6. File for Implementation of CSAFReg
  7. Revision History:
  8. Steve Shih created 07/15/99
  9. Davide Massarenti rewrote 05/12/2000
  10. ********************************************************************/
  11. #include "stdafx.h"
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CSAFReg
  14. const WCHAR c_SAFStore [] = HC_HELPSVC_STORE_CHANNELS;
  15. const WCHAR c_szXML_ProductID [] = L"ProductID";
  16. const WCHAR c_szXML_ProductName[] = L"ProductName";
  17. const WCHAR c_szXML_Description[] = L"ProductDescription";
  18. const WCHAR c_szXML_EntryURL [] = L"EntryURL";
  19. const WCHAR c_szXML_IconPath [] = L"VendorIcon";
  20. const WCHAR c_szXML_PublicKey [] = L"PublicKey";
  21. /*
  22. <?xml version="1.0" encoding="utf-8" ?>
  23. <SAFConfig>
  24. <ProductID>Word</ProductID>
  25. <ProductName>Microsoft Word</ProductName>
  26. <ProductDescription>Word Processor</ProductDescription>
  27. <EntryURL>http://www.microsoft.com/office/word</EntryURL>
  28. <VendorIcon>http://steveshi-2/helpportal/images/go_to_4.gif</VendorIcon>
  29. </SAFConfig>
  30. */
  31. /////////////////////////////////////////////////////////////////////////////
  32. CFG_BEGIN_FIELDS_MAP(CSAFReg::Inner_UI)
  33. CFG_ATTRIBUTE( L"SKU" , wstring, m_ths.m_strSKU ),
  34. CFG_ATTRIBUTE( L"LANGUAGE" , long , m_ths.m_lLCID ),
  35. CFG_ATTRIBUTE( L"VENDORNAME" , BSTR , m_bstrVendorName ),
  36. CFG_ATTRIBUTE( L"PRODUCTNAME", BSTR , m_bstrProductName ),
  37. CFG_ATTRIBUTE( L"ICON" , BSTR , m_bstrIcon ),
  38. CFG_ATTRIBUTE( L"URL" , BSTR , m_bstrURL ),
  39. CFG_VALUE ( BSTR , m_bstrDescription ),
  40. CFG_END_FIELDS_MAP()
  41. CFG_BEGIN_CHILD_MAP(CSAFReg::Inner_UI)
  42. CFG_END_CHILD_MAP()
  43. DEFINE_CFG_OBJECT(CSAFReg::Inner_UI,L"UI")
  44. DEFINE_CONFIG_METHODS__NOCHILD(CSAFReg::Inner_UI)
  45. ////////////////////
  46. CFG_BEGIN_FIELDS_MAP(CSAFReg::Inner_Product)
  47. CFG_ATTRIBUTE( L"ID" , BSTR, m_bstrProductID ),
  48. CFG_ATTRIBUTE( L"SECURITY" , BSTR, m_bstrSecurity ),
  49. CFG_ATTRIBUTE( L"NOTIFICATION", BSTR, m_bstrNotification ),
  50. CFG_END_FIELDS_MAP()
  51. CFG_BEGIN_CHILD_MAP(CSAFReg::Inner_Product)
  52. CFG_CHILD(CSAFReg::Inner_UI)
  53. CFG_END_CHILD_MAP()
  54. DEFINE_CFG_OBJECT(CSAFReg::Inner_Product,L"PRODUCT")
  55. DEFINE_CONFIG_METHODS_CREATEINSTANCE_SECTION(CSAFReg::Inner_Product,tag,defSubType)
  56. if(tag == _cfg_table_tags[0])
  57. {
  58. defSubType = &(*(m_lstUI.insert( m_lstUI.end() )));
  59. return S_OK;
  60. }
  61. DEFINE_CONFIG_METHODS_SAVENODE_SECTION(CSAFReg::Inner_Product,xdn)
  62. hr = MPC::Config::SaveList( m_lstUI, xdn );
  63. DEFINE_CONFIG_METHODS_END(CSAFReg::Inner_Product)
  64. ////////////////////
  65. CFG_BEGIN_FIELDS_MAP(CSAFReg::Inner_Vendor)
  66. CFG_ATTRIBUTE( L"ID" , BSTR, m_bstrVendorID ),
  67. CFG_ATTRIBUTE( L"PUBLICKEY" , BSTR, m_bstrPublicKey ),
  68. CFG_ATTRIBUTE( L"USERACCOUNT", BSTR, m_bstrUserAccount ),
  69. CFG_END_FIELDS_MAP()
  70. CFG_BEGIN_CHILD_MAP(CSAFReg::Inner_Vendor)
  71. CFG_CHILD(CSAFReg::Inner_Product)
  72. CFG_END_CHILD_MAP()
  73. DEFINE_CFG_OBJECT(CSAFReg::Inner_Vendor,L"VENDOR")
  74. DEFINE_CONFIG_METHODS_CREATEINSTANCE_SECTION(CSAFReg::Inner_Vendor,tag,defSubType)
  75. if(tag == _cfg_table_tags[0])
  76. {
  77. defSubType = &(*(m_lstProducts.insert( m_lstProducts.end() )));
  78. return S_OK;
  79. }
  80. DEFINE_CONFIG_METHODS_SAVENODE_SECTION(CSAFReg::Inner_Vendor,xdn)
  81. hr = MPC::Config::SaveList( m_lstProducts, xdn );
  82. DEFINE_CONFIG_METHODS_END(CSAFReg::Inner_Vendor)
  83. ////////////////////
  84. CFG_BEGIN_FIELDS_MAP(CSAFReg)
  85. CFG_END_FIELDS_MAP()
  86. CFG_BEGIN_CHILD_MAP(CSAFReg)
  87. CFG_CHILD(CSAFReg::Inner_Vendor)
  88. CFG_END_CHILD_MAP()
  89. DEFINE_CFG_OBJECT(CSAFReg,L"SAFREG")
  90. DEFINE_CONFIG_METHODS_CREATEINSTANCE_SECTION(CSAFReg,tag,defSubType)
  91. if(tag == _cfg_table_tags[0])
  92. {
  93. defSubType = &(*(m_lstVendors.insert( m_lstVendors.end() )));
  94. return S_OK;
  95. }
  96. DEFINE_CONFIG_METHODS_SAVENODE_SECTION(CSAFReg,xdn)
  97. hr = MPC::Config::SaveList( m_lstVendors, xdn );
  98. DEFINE_CONFIG_METHODS_END(CSAFReg)
  99. /////////////////////////////////////////////////////////////////////////////
  100. /////////////////////////////////////////////////////////////////////////////
  101. /////////////////////////////////////////////////////////////////////////////
  102. CSAFRegDummy::CSAFRegDummy()
  103. {
  104. // ChannelsList m_lstChannels;
  105. m_itCurrent = m_lstChannels.end(); // ChannelsIter m_itCurrent;
  106. }
  107. HRESULT CSAFRegDummy::Append( /*[in]*/ const CSAFChannelRecord& cr )
  108. {
  109. m_lstChannels.push_back( cr );
  110. m_itCurrent = m_lstChannels.begin();
  111. return S_OK;
  112. }
  113. /////////////////////////////////////////////////////////////////////////////
  114. HRESULT CSAFRegDummy::ReturnField( /*[in]*/ CSAFChannelRecord::SAFREG_Field field ,
  115. /*[out]*/ BSTR *pVal )
  116. {
  117. __HCP_BEGIN_PROPERTY_PUT("CSAFRegDummy::ReturnField",hr);
  118. __MPC_PARAMCHECK_BEGIN(hr)
  119. __MPC_PARAMCHECK_POINTER_AND_SET(pVal,NULL);
  120. __MPC_PARAMCHECK_END();
  121. if(m_itCurrent != m_lstChannels.end())
  122. {
  123. __MPC_EXIT_IF_METHOD_FAILS(hr, m_itCurrent->GetField( field, pVal ));
  124. }
  125. __HCP_END_PROPERTY(hr);
  126. }
  127. /////////////////////////////////////////////////////////////////////////////
  128. STDMETHODIMP CSAFRegDummy::MoveFirst()
  129. {
  130. __HCP_FUNC_ENTRY( "CSAFRegDummy::MoveFirst" );
  131. HRESULT hr;
  132. MPC::SmartLock<_ThreadModel> lock( this );
  133. m_itCurrent = m_lstChannels.begin();
  134. hr = S_OK;
  135. __HCP_FUNC_EXIT(hr);
  136. }
  137. STDMETHODIMP CSAFRegDummy::MoveNext()
  138. {
  139. __HCP_FUNC_ENTRY( "CSAFRegDummy::MoveNext" );
  140. HRESULT hr;
  141. MPC::SmartLock<_ThreadModel> lock( this );
  142. if(m_itCurrent != m_lstChannels.end()) m_itCurrent++;
  143. hr = S_OK;
  144. __HCP_FUNC_EXIT(hr);
  145. }
  146. STDMETHODIMP CSAFRegDummy::get_EOF( VARIANT_BOOL *pVal )
  147. {
  148. __HCP_BEGIN_PROPERTY_GET2("CSAFRegDummy::get_EOF",hr,pVal,VARIANT_TRUE);
  149. *pVal = (m_itCurrent != m_lstChannels.end()) ? VARIANT_FALSE : VARIANT_TRUE;
  150. __HCP_END_PROPERTY(hr);
  151. }
  152. ////////////////////////////////////////////////////////////////////////////////
  153. STDMETHODIMP CSAFRegDummy::get_VendorID ( BSTR *pVal ) { return ReturnField( CSAFChannelRecord::SAFREG_VendorID , pVal ); }
  154. STDMETHODIMP CSAFRegDummy::get_ProductID ( BSTR *pVal ) { return ReturnField( CSAFChannelRecord::SAFREG_ProductID , pVal ); }
  155. STDMETHODIMP CSAFRegDummy::get_VendorName ( BSTR *pVal ) { return ReturnField( CSAFChannelRecord::SAFREG_VendorName , pVal ); }
  156. STDMETHODIMP CSAFRegDummy::get_ProductName ( BSTR *pVal ) { return ReturnField( CSAFChannelRecord::SAFREG_ProductName , pVal ); }
  157. STDMETHODIMP CSAFRegDummy::get_ProductDescription( BSTR *pVal ) { return ReturnField( CSAFChannelRecord::SAFREG_ProductDescription, pVal ); }
  158. STDMETHODIMP CSAFRegDummy::get_VendorIcon ( BSTR *pVal ) { return ReturnField( CSAFChannelRecord::SAFREG_VendorIcon , pVal ); }
  159. STDMETHODIMP CSAFRegDummy::get_SupportUrl ( BSTR *pVal ) { return ReturnField( CSAFChannelRecord::SAFREG_SupportUrl , pVal ); }
  160. STDMETHODIMP CSAFRegDummy::get_PublicKey ( BSTR *pVal ) { return ReturnField( CSAFChannelRecord::SAFREG_PublicKey , pVal ); }
  161. STDMETHODIMP CSAFRegDummy::get_UserAccount ( BSTR *pVal ) { return ReturnField( CSAFChannelRecord::SAFREG_UserAccount , pVal ); }
  162. /////////////////////////////////////////////////////////////////////////////
  163. /////////////////////////////////////////////////////////////////////////////
  164. /////////////////////////////////////////////////////////////////////////////
  165. CSAFReg::CSAFReg()
  166. {
  167. m_szSAFStore = c_SAFStore; MPC::SubstituteEnvVariables( m_szSAFStore ); // MPC::wstring m_szSAFStore;
  168. // VendorList m_lstVendors;
  169. m_fLoaded = false; // bool m_fLoaded;
  170. m_fDirty = false; // bool m_fDirty;
  171. }
  172. ////////////////////
  173. CSAFReg* CSAFReg::s_GLOBAL( NULL );
  174. HRESULT CSAFReg::InitializeSystem()
  175. {
  176. if(s_GLOBAL) return S_OK;
  177. CSAFReg::s_GLOBAL = new CSAFReg;
  178. return CSAFReg::s_GLOBAL ? S_OK : E_OUTOFMEMORY;
  179. }
  180. void CSAFReg::FinalizeSystem()
  181. {
  182. if(s_GLOBAL)
  183. {
  184. delete s_GLOBAL; s_GLOBAL = NULL;
  185. }
  186. }
  187. ////////////////////
  188. HRESULT CSAFReg::EnsureInSync()
  189. {
  190. __HCP_FUNC_ENTRY( "CSAFReg::EnsureInSync" );
  191. HRESULT hr;
  192. if(m_fLoaded == false)
  193. {
  194. m_lstVendors.clear();
  195. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::Config::LoadFile( this, m_szSAFStore.c_str() ));
  196. m_fLoaded = true;
  197. m_fDirty = false;
  198. }
  199. if(m_fDirty)
  200. {
  201. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::Config::SaveFile( this, m_szSAFStore.c_str() ));
  202. m_fDirty = true;
  203. }
  204. hr = S_OK;
  205. __MPC_FUNC_CLEANUP;
  206. __MPC_FUNC_EXIT(hr);
  207. }
  208. /////////////////////////////////////////////////////////////////////////////
  209. HRESULT CSAFReg::ParseFileField( /*[in]*/ MPC::XmlUtil& xml ,
  210. /*[in]*/ LPCWSTR szTag ,
  211. /*[in]*/ CComBSTR& bstrDest )
  212. {
  213. __HCP_FUNC_ENTRY( "CSAFReg::ParseFileField" );
  214. HRESULT hr;
  215. CComVariant vValue;
  216. bool fFound;
  217. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.GetValue( szTag, vValue, fFound ));
  218. if(fFound)
  219. {
  220. if(SUCCEEDED(vValue.ChangeType( VT_BSTR )))
  221. {
  222. bstrDest = vValue.bstrVal;
  223. }
  224. }
  225. hr = S_OK;
  226. __HCP_FUNC_CLEANUP;
  227. __HCP_FUNC_EXIT(hr);
  228. }
  229. HRESULT CSAFReg::ParseFile( /*[in ]*/ MPC::XmlUtil& xml ,
  230. /*[in/out]*/ CSAFChannelRecord& cr )
  231. {
  232. __HCP_FUNC_ENTRY( "CSAFReg::ParseFile" );
  233. HRESULT hr;
  234. __MPC_EXIT_IF_METHOD_FAILS(hr, ParseFileField( xml, c_szXML_ProductID , cr.m_bstrProductID ));
  235. __MPC_EXIT_IF_METHOD_FAILS(hr, ParseFileField( xml, c_szXML_ProductName, cr.m_bstrProductName ));
  236. __MPC_EXIT_IF_METHOD_FAILS(hr, ParseFileField( xml, c_szXML_Description, cr.m_bstrDescription ));
  237. __MPC_EXIT_IF_METHOD_FAILS(hr, ParseFileField( xml, c_szXML_EntryURL , cr.m_bstrURL ));
  238. __MPC_EXIT_IF_METHOD_FAILS(hr, ParseFileField( xml, c_szXML_IconPath , cr.m_bstrIcon ));
  239. __MPC_EXIT_IF_METHOD_FAILS(hr, ParseFileField( xml, c_szXML_PublicKey , cr.m_bstrPublicKey ));
  240. //
  241. // Backward compatibility, when ProductName was not available.
  242. //
  243. if(cr.m_bstrProductName.Length() == 0) cr.m_bstrProductName = cr.m_bstrProductID;
  244. hr = S_OK;
  245. __HCP_FUNC_CLEANUP;
  246. __HCP_FUNC_EXIT(hr);
  247. }
  248. ////////////////////////////////////////////////////////////////////////////////
  249. HRESULT CSAFReg::MoveToChannel( /*[in ]*/ const CSAFChannelRecord& cr ,
  250. /*[in ]*/ bool fCreate ,
  251. /*[out]*/ bool& fFound ,
  252. /*[out]*/ VendorIter& itVendor ,
  253. /*[out]*/ ProdIter* pitProduct ,
  254. /*[out]*/ UIIter* pitUI )
  255. {
  256. __HCP_FUNC_ENTRY( "CSAFReg::MoveToChannel" );
  257. HRESULT hr;
  258. fFound = false;
  259. __MPC_EXIT_IF_METHOD_FAILS(hr, EnsureInSync());
  260. for(itVendor = m_lstVendors.begin(); itVendor != m_lstVendors.end(); itVendor++)
  261. {
  262. if(!MPC::StrICmp( itVendor->m_bstrVendorID, cr.m_bstrVendorID )) break;
  263. }
  264. if(itVendor == m_lstVendors.end())
  265. {
  266. if(!fCreate)
  267. {
  268. __MPC_SET_ERROR_AND_EXIT(hr, S_OK);
  269. }
  270. itVendor = m_lstVendors.insert( m_lstVendors.end() ); m_fDirty = true;
  271. itVendor->m_bstrVendorID = cr.m_bstrVendorID;
  272. }
  273. if(pitProduct)
  274. {
  275. Inner_Vendor& v = *itVendor;
  276. ProdIter itProduct;
  277. for(itProduct = v.m_lstProducts.begin(); itProduct != v.m_lstProducts.end(); itProduct++)
  278. {
  279. if(!MPC::StrICmp( itProduct->m_bstrProductID, cr.m_bstrProductID )) break;
  280. }
  281. if(itProduct == v.m_lstProducts.end())
  282. {
  283. if(!fCreate)
  284. {
  285. __MPC_SET_ERROR_AND_EXIT(hr, S_OK);
  286. }
  287. itProduct = v.m_lstProducts.insert( v.m_lstProducts.end() ); m_fDirty = true;
  288. itProduct->m_bstrProductID = cr.m_bstrProductID;
  289. }
  290. *pitProduct = itProduct;
  291. if(pitUI)
  292. {
  293. Inner_Product& p = *itProduct;
  294. UIIter itUI;
  295. for(itUI = p.m_lstUI.begin(); itUI != p.m_lstUI.end(); itUI++)
  296. {
  297. if(itUI->m_ths == cr.m_ths) break;
  298. }
  299. if(itUI == p.m_lstUI.end())
  300. {
  301. if(!fCreate)
  302. {
  303. __MPC_SET_ERROR_AND_EXIT(hr, S_OK);
  304. }
  305. itUI = p.m_lstUI.insert( p.m_lstUI.end() ); m_fDirty = true;
  306. itUI->m_ths = cr.m_ths;
  307. }
  308. *pitUI = itUI;
  309. }
  310. }
  311. fFound = true;
  312. hr = S_OK;
  313. __HCP_FUNC_CLEANUP;
  314. __HCP_FUNC_EXIT(hr);
  315. }
  316. void CSAFReg::PopulateRecord( /*[in]*/ CSAFChannelRecord& cr ,
  317. /*[in]*/ VendorIter itVendor ,
  318. /*[in]*/ ProdIter itProduct ,
  319. /*[in]*/ UIIter itUI )
  320. {
  321. cr.m_ths.m_strSKU = itUI ->m_ths.m_strSKU ; // SAFREG_SKU
  322. cr.m_ths.m_lLCID = itUI ->m_ths.m_lLCID ; // SAFREG_Language
  323. //
  324. cr.m_bstrVendorID = itVendor ->m_bstrVendorID ; // SAFREG_VendorID
  325. cr.m_bstrProductID = itProduct->m_bstrProductID ; // SAFREG_ProductID
  326. //
  327. cr.m_bstrVendorName = itUI ->m_bstrVendorName ; // SAFREG_VendorName
  328. cr.m_bstrProductName = itUI ->m_bstrProductName ; // SAFREG_ProductName
  329. cr.m_bstrDescription = itUI ->m_bstrDescription ; // SAFREG_ProductDescription
  330. //
  331. cr.m_bstrIcon = itUI ->m_bstrIcon ; // SAFREG_VendorIcon
  332. cr.m_bstrURL = itUI ->m_bstrURL ; // SAFREG_SupportUrl
  333. //
  334. cr.m_bstrPublicKey = itVendor ->m_bstrPublicKey ; // SAFREG_PublicKey
  335. cr.m_bstrUserAccount = itVendor ->m_bstrUserAccount ; // SAFREG_UserAccount
  336. //
  337. cr.m_bstrSecurity = itProduct->m_bstrSecurity ; // SAFREG_Security
  338. cr.m_bstrNotification = itProduct->m_bstrNotification; // SAFREG_Notification
  339. }
  340. ////////////////////////////////////////////////////////////////////////////////
  341. HRESULT CSAFReg::RegisterSupportChannel( /*[in]*/ const CSAFChannelRecord& cr ,
  342. /*[in]*/ MPC::XmlUtil& xml )
  343. {
  344. __HCP_BEGIN_PROPERTY_PUT("CSAFReg::RegisterSupportChannel",hr);
  345. CSAFChannelRecord cr2 = cr;
  346. bool fFound;
  347. VendorIter itVendor;
  348. ProdIter itProduct;
  349. UIIter itUI;
  350. __MPC_EXIT_IF_METHOD_FAILS(hr, ParseFile( xml, cr2 ));
  351. __MPC_EXIT_IF_METHOD_FAILS(hr, MoveToChannel( cr2, /*fCreate*/true, fFound, itVendor, &itProduct, &itUI ));
  352. if(!fFound)
  353. {
  354. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, ERROR_FILE_NOT_FOUND);
  355. }
  356. //
  357. // Update fields.
  358. //
  359. itUI ->m_bstrVendorName = cr2.m_bstrVendorName ;
  360. itUI ->m_bstrProductName = cr2.m_bstrProductName;
  361. itUI ->m_bstrDescription = cr2.m_bstrDescription;
  362. itUI ->m_bstrIcon = cr2.m_bstrIcon ;
  363. itUI ->m_bstrURL = cr2.m_bstrURL ;
  364. itVendor->m_bstrPublicKey = cr2.m_bstrPublicKey ;
  365. //
  366. // Always create a user account associated with the vendor.
  367. //
  368. if(itVendor->m_bstrUserAccount.Length() == 0)
  369. {
  370. GUID guidPassword;
  371. MPC::wstring szComment;
  372. DWORD dwCRC;
  373. __MPC_EXIT_IF_METHOD_FAILS(hr, ::CoCreateGuid( &guidPassword )); // This generates a random password.
  374. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::LocalizeString( IDS_HELPSVC_USERCOMMENT, szComment ));
  375. //
  376. // The user account is created using this template:
  377. //
  378. // SUPPORT_<CRC1>
  379. //
  380. // where <CRC1> is an 8 digit hash of the whole vendor id.
  381. //
  382. //
  383. {
  384. BSTR bstr = itVendor->m_bstrVendorID;
  385. MPC::InitCRC ( dwCRC );
  386. MPC::ComputeCRC( dwCRC, (UCHAR*)bstr, ::SysStringByteLen( bstr ) );
  387. }
  388. //
  389. // The CRC method doesn't guarantee the user account is unique, so you have to try creating
  390. // the user and if it fails, move to a different one. Anyway, it's highly unlikely
  391. //
  392. {
  393. WCHAR rgUserName[64]; swprintf( rgUserName, L"SUPPORT_%08x", (int)dwCRC );
  394. CComBSTR bstrPWD( guidPassword );
  395. CPCHAccounts acc;
  396. for(int pass=0; pass<2; pass++)
  397. {
  398. hr = acc.CreateUser( rgUserName, bstrPWD, itVendor->m_bstrVendorID, szComment.c_str() );
  399. if(SUCCEEDED(hr)) break;
  400. if(hr != HRESULT_FROM_WIN32(NERR_UserExists)) __MPC_SET_ERROR_AND_EXIT(hr, hr);
  401. __MPC_EXIT_IF_METHOD_FAILS(hr, acc.DeleteUser( rgUserName ));
  402. }
  403. itVendor->m_bstrUserAccount = rgUserName;
  404. //
  405. // The account is created disabled.
  406. //
  407. __MPC_EXIT_IF_METHOD_FAILS(hr, acc.ChangeUserStatus( rgUserName, /*fEnable*/false ));
  408. }
  409. }
  410. m_fDirty = true;
  411. __MPC_EXIT_IF_METHOD_FAILS(hr, EnsureInSync());
  412. __HCP_END_PROPERTY(hr);
  413. }
  414. HRESULT CSAFReg::RemoveSupportChannel( /*[in]*/ const CSAFChannelRecord& cr ,
  415. /*[in]*/ MPC::XmlUtil& xml )
  416. {
  417. __HCP_BEGIN_PROPERTY_PUT("CSAFReg::RemoveSupportChannel",hr);
  418. CSAFChannelRecord cr2 = cr;
  419. bool fFound;
  420. VendorIter itVendor;
  421. ProdIter itProduct;
  422. UIIter itUI;
  423. __MPC_EXIT_IF_METHOD_FAILS(hr, ParseFile( xml, cr2 ));
  424. __MPC_EXIT_IF_METHOD_FAILS(hr, MoveToChannel( cr2, /*fCreate*/false, fFound, itVendor, &itProduct, &itUI ));
  425. if(fFound)
  426. {
  427. itProduct->m_lstUI.erase( itUI );
  428. if(itProduct->m_lstUI.size() == 0)
  429. {
  430. itVendor->m_lstProducts.erase( itProduct );
  431. if(itVendor->m_lstProducts.size() == 0)
  432. {
  433. if(itVendor->m_bstrUserAccount.Length())
  434. {
  435. //
  436. // Delete the user account associated with the vendor.
  437. //
  438. CPCHAccounts acc;
  439. CPCHUserProcess::UserEntry ue;
  440. __MPC_EXIT_IF_METHOD_FAILS(hr, ue.InitializeForVendorAccount( itVendor->m_bstrUserAccount,
  441. itVendor->m_bstrVendorID ,
  442. itVendor->m_bstrPublicKey ));
  443. (void)CPCHUserProcess::s_GLOBAL->Remove ( ue );
  444. (void)acc .DeleteUser( itVendor->m_bstrUserAccount );
  445. }
  446. m_lstVendors.erase( itVendor );
  447. }
  448. }
  449. m_fDirty = true;
  450. __MPC_EXIT_IF_METHOD_FAILS(hr, EnsureInSync());
  451. }
  452. __HCP_END_PROPERTY(hr);
  453. }
  454. ////////////////////////////////////////////////////////////////////////////////
  455. HRESULT CSAFReg::CreateReadOnlyCopy( /*[in ]*/ const Taxonomy::HelpSet& ths ,
  456. /*[out]*/ CSAFRegDummy* *pVal )
  457. {
  458. __HCP_BEGIN_PROPERTY_GET("CSAFReg::CreateReadOnlyCopy",hr,pVal);
  459. MPC::AccessCheck ac;
  460. CComPtr<CSAFRegDummy> obj;
  461. CSAFChannelRecord cr;
  462. VendorIter itVendor;
  463. ProdIter itProduct;
  464. UIIter itUI;
  465. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &obj ));
  466. //
  467. // Walk through all the products, only copy those passing the read/write access check.
  468. //
  469. __MPC_EXIT_IF_METHOD_FAILS(hr, ac.GetTokenFromImpersonation());
  470. __MPC_EXIT_IF_METHOD_FAILS(hr, EnsureInSync());
  471. for(itVendor = m_lstVendors.begin(); itVendor != m_lstVendors.end(); itVendor++)
  472. {
  473. Inner_Vendor& v = *itVendor;
  474. for(itProduct = v.m_lstProducts.begin(); itProduct != v.m_lstProducts.end(); itProduct++)
  475. {
  476. Inner_Product& p = *itProduct;
  477. for(itUI = p.m_lstUI.begin(); itUI != p.m_lstUI.end(); itUI++)
  478. {
  479. if(itUI->m_ths == ths)
  480. {
  481. bool fAdd = false;
  482. if(itProduct->m_bstrSecurity.Length() == 0)
  483. {
  484. fAdd = true;
  485. }
  486. else
  487. {
  488. BOOL fGranted;
  489. DWORD dwGranted;
  490. if(SUCCEEDED(ac.Verify( ACCESS_READ, fGranted, dwGranted, itProduct->m_bstrSecurity )) && fGranted)
  491. {
  492. fAdd = true;
  493. }
  494. }
  495. if(fAdd)
  496. {
  497. PopulateRecord( cr, itVendor, itProduct, itUI );
  498. __MPC_EXIT_IF_METHOD_FAILS(hr, obj->Append( cr ));
  499. }
  500. }
  501. }
  502. }
  503. }
  504. *pVal = obj.Detach();
  505. __HCP_END_PROPERTY(hr);
  506. }
  507. ////////////////////////////////////////////////////////////////////////////////
  508. HRESULT CSAFReg::LookupAccountData( /*[in ]*/ BSTR bstrVendorID ,
  509. /*[out]*/ CPCHUserProcess::UserEntry& ue )
  510. {
  511. __HCP_BEGIN_PROPERTY_PUT("CSAFReg::LookupAccountData",hr);
  512. CSAFChannelRecord cr;
  513. bool fFound;
  514. VendorIter itVendor;
  515. //
  516. // Look just for Vendor.
  517. //
  518. cr.m_bstrVendorID = bstrVendorID;
  519. __MPC_EXIT_IF_METHOD_FAILS(hr, MoveToChannel( cr, /*fCreate*/false, fFound, itVendor ));
  520. if(!fFound)
  521. {
  522. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, ERROR_FILE_NOT_FOUND);
  523. }
  524. __MPC_EXIT_IF_METHOD_FAILS(hr, ue.InitializeForVendorAccount( itVendor->m_bstrUserAccount, itVendor->m_bstrVendorID, itVendor->m_bstrPublicKey ));
  525. __HCP_END_PROPERTY(hr);
  526. }
  527. HRESULT CSAFReg::UpdateField( /*[in]*/ const CSAFChannelRecord& cr ,
  528. /*[in]*/ CSAFChannelRecord::SAFREG_Field field )
  529. {
  530. __HCP_BEGIN_PROPERTY_PUT("CSAFReg::UpdateField",hr);
  531. bool fFound;
  532. VendorIter itVendor;
  533. ProdIter itProduct;
  534. UIIter itUI;
  535. __MPC_EXIT_IF_METHOD_FAILS(hr, MoveToChannel( cr, /*fCreate*/false, fFound, itVendor, &itProduct, &itUI ));
  536. if(!fFound)
  537. {
  538. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, ERROR_FILE_NOT_FOUND);
  539. }
  540. switch(field)
  541. {
  542. case CSAFChannelRecord::SAFREG_SKU : itUI ->m_ths.m_strSKU = cr.m_ths.m_strSKU ; break;
  543. case CSAFChannelRecord::SAFREG_Language : itUI ->m_ths.m_lLCID = cr.m_ths.m_lLCID ; break;
  544. case CSAFChannelRecord::SAFREG_VendorID : itVendor ->m_bstrVendorID = cr.m_bstrVendorID ; break;
  545. case CSAFChannelRecord::SAFREG_ProductID : itProduct->m_bstrProductID = cr.m_bstrProductID ; break;
  546. case CSAFChannelRecord::SAFREG_VendorName : itUI ->m_bstrVendorName = cr.m_bstrVendorName ; break;
  547. case CSAFChannelRecord::SAFREG_ProductName : itUI ->m_bstrProductName = cr.m_bstrProductName ; break;
  548. case CSAFChannelRecord::SAFREG_ProductDescription: itUI ->m_bstrDescription = cr.m_bstrDescription ; break;
  549. case CSAFChannelRecord::SAFREG_VendorIcon : itUI ->m_bstrIcon = cr.m_bstrIcon ; break;
  550. case CSAFChannelRecord::SAFREG_SupportUrl : itUI ->m_bstrURL = cr.m_bstrURL ; break;
  551. case CSAFChannelRecord::SAFREG_PublicKey : itVendor ->m_bstrPublicKey = cr.m_bstrPublicKey ; break;
  552. case CSAFChannelRecord::SAFREG_UserAccount : itVendor ->m_bstrUserAccount = cr.m_bstrUserAccount ; break;
  553. case CSAFChannelRecord::SAFREG_Security : itProduct->m_bstrSecurity = cr.m_bstrSecurity ; break;
  554. case CSAFChannelRecord::SAFREG_Notification : itProduct->m_bstrNotification = cr.m_bstrNotification; break;
  555. default: __MPC_SET_ERROR_AND_EXIT(hr, E_INVALIDARG);
  556. }
  557. m_fDirty = true;
  558. __MPC_EXIT_IF_METHOD_FAILS(hr, EnsureInSync());
  559. __HCP_END_PROPERTY(hr);
  560. }
  561. HRESULT CSAFReg::Synchronize( /*[in/out]*/ CSAFChannelRecord& cr ,
  562. /*[out ]*/ bool& fFound )
  563. {
  564. __HCP_BEGIN_PROPERTY_PUT("CSAFReg::Synchronize",hr);
  565. VendorIter itVendor;
  566. ProdIter itProduct;
  567. UIIter itUI;
  568. __MPC_EXIT_IF_METHOD_FAILS(hr, MoveToChannel( cr, /*fCreate*/false, fFound, itVendor, &itProduct, &itUI ));
  569. if(fFound)
  570. {
  571. PopulateRecord( cr, itVendor, itProduct, itUI );
  572. }
  573. __HCP_END_PROPERTY(hr);
  574. }
  575. HRESULT CSAFReg::RemoveSKU( /*[in]*/ const Taxonomy::HelpSet& ths )
  576. {
  577. __HCP_BEGIN_PROPERTY_PUT("CSAFReg::RemoveSKU",hr);
  578. __MPC_EXIT_IF_METHOD_FAILS(hr, EnsureInSync());
  579. for(VendorIter itVendor = m_lstVendors.begin(); itVendor != m_lstVendors.end(); itVendor++)
  580. {
  581. Inner_Vendor& v = *itVendor;
  582. for(ProdIter itProduct = v.m_lstProducts.begin(); itProduct != v.m_lstProducts.end(); itProduct++)
  583. {
  584. Inner_Product& p = *itProduct;
  585. for(UIIter itUI = p.m_lstUI.begin(); itUI != p.m_lstUI.end(); itUI++)
  586. {
  587. if(itUI->m_ths == ths)
  588. {
  589. p.m_lstUI.erase( itUI );
  590. break;
  591. }
  592. }
  593. }
  594. }
  595. __MPC_EXIT_IF_METHOD_FAILS(hr, EnsureInSync());
  596. __HCP_END_PROPERTY(hr);
  597. }