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.

841 lines
26 KiB

  1. // asptxn.cpp : Implementation of DLL Exports.
  2. // Note: Proxy/Stub Information
  3. // To merge the proxy/stub code into the object DLL, add the file
  4. // dlldatax.c to the project. Make sure precompiled headers
  5. // are turned off for this file, and add _MERGE_PROXYSTUB to the
  6. // defines for the project.
  7. //
  8. // If you are not running WinNT4.0 or Win95 with DCOM, then you
  9. // need to remove the following define from dlldatax.c
  10. // #define _WIN32_WINNT 0x0400
  11. //
  12. // Further, if you are running MIDL without /Oicf switch, you also
  13. // need to remove the following define from dlldatax.c.
  14. // #define USE_STUBLESS_PROXY
  15. //
  16. // Modify the custom build rule for asptxn.idl by adding the following
  17. // files to the Outputs.
  18. // asptxn_p.c
  19. // dlldata.c
  20. // To build a separate proxy/stub DLL,
  21. // run nmake -f asptxnps.mk in the project directory.
  22. #include "stdafx.h"
  23. #include "resource.h"
  24. #include <initguid.h>
  25. #include "txnscrpt.h"
  26. #include "dlldatax.h"
  27. #include "txnscrpt_i.c"
  28. #include "txnobj.h"
  29. #include <dbgutil.h>
  30. #include <comadmin.h>
  31. #ifdef _MERGE_PROXYSTUB
  32. extern "C" HINSTANCE hProxyDll;
  33. #endif
  34. CComModule _Module;
  35. BEGIN_OBJECT_MAP(ObjectMap)
  36. OBJECT_ENTRY(CLSID_ASPObjectContextTxRequired, CASPObjectContext)
  37. OBJECT_ENTRY(CLSID_ASPObjectContextTxRequiresNew, CASPObjectContext)
  38. OBJECT_ENTRY(CLSID_ASPObjectContextTxSupported, CASPObjectContext)
  39. OBJECT_ENTRY(CLSID_ASPObjectContextTxNotSupported, CASPObjectContext)
  40. END_OBJECT_MAP()
  41. LPCSTR g_szModuleName = "ASPTXN";
  42. DECLARE_DEBUG_VARIABLE();
  43. DECLARE_DEBUG_PRINTS_OBJECT();
  44. /////////////////////////////////////////////////////////////////////////////
  45. // DLL Entry Point
  46. extern "C"
  47. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  48. {
  49. lpReserved;
  50. #ifdef _MERGE_PROXYSTUB
  51. if (!PrxDllMain(hInstance, dwReason, lpReserved))
  52. return FALSE;
  53. #endif
  54. if (dwReason == DLL_PROCESS_ATTACH)
  55. {
  56. CREATE_DEBUG_PRINT_OBJECT( g_szModuleName );
  57. if( !VALID_DEBUG_PRINT_OBJECT() )
  58. {
  59. return FALSE;
  60. }
  61. LOAD_DEBUG_FLAGS_FROM_REG_STR("System\\CurrentControlSet\\Services\\W3Svc\\ASP", 0);
  62. _Module.Init(ObjectMap, hInstance /*, ATL21 &LIBID_ASPTXNLib */);
  63. DisableThreadLibraryCalls(hInstance);
  64. }
  65. else if (dwReason == DLL_PROCESS_DETACH)
  66. {
  67. _Module.Term();
  68. DELETE_DEBUG_PRINT_OBJECT();
  69. }
  70. return TRUE; // ok
  71. }
  72. /////////////////////////////////////////////////////////////////////////////
  73. // Used to determine whether the DLL can be unloaded by OLE
  74. STDAPI DllCanUnloadNow(void)
  75. {
  76. #ifdef _MERGE_PROXYSTUB
  77. if (PrxDllCanUnloadNow() != S_OK)
  78. return S_FALSE;
  79. #endif
  80. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  81. }
  82. /////////////////////////////////////////////////////////////////////////////
  83. // Returns a class factory to create an object of the requested type
  84. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  85. {
  86. #ifdef _MERGE_PROXYSTUB
  87. if (PrxDllGetClassObject(rclsid, riid, ppv) == S_OK)
  88. return S_OK;
  89. #endif
  90. return _Module.GetClassObject(rclsid, riid, ppv);
  91. }
  92. /////////////////////////////////////////////////////////////////////////////
  93. // DllRegisterServer - Adds entries to the system registry
  94. // Forward references
  95. HRESULT ViperizeContextObject();
  96. HRESULT AddViperUtilPackage();
  97. HRESULT RemoveViperUtilPackage(ICatalogCollection* pPkgCollectionT);
  98. HRESULT AddContextObjectToViperPackage();
  99. STDAPI DllRegisterServer(void)
  100. {
  101. #ifdef _MERGE_PROXYSTUB
  102. HRESULT hRes = PrxDllRegisterServer();
  103. if (FAILED(hRes))
  104. return hRes;
  105. #endif
  106. HRESULT hr = NOERROR;
  107. // registers object, typelib and all interfaces in typelib
  108. hr = _Module.RegisterServer(TRUE);
  109. // create the iis utilities package
  110. if( SUCCEEDED(hr) )
  111. {
  112. HRESULT hrCoInit = CoInitialize( NULL );
  113. // This is kinda dopey, but remove the package if it exists
  114. // so we don't get bogus errors when we add. Ignore the return.
  115. RemoveViperUtilPackage(NULL);
  116. hr = ViperizeContextObject();
  117. if( SUCCEEDED(hrCoInit) )
  118. {
  119. CoUninitialize();
  120. }
  121. }
  122. return hr;
  123. }
  124. /////////////////////////////////////////////////////////////////////////////
  125. // DllUnregisterServer - Removes entries from the system registry
  126. STDAPI DllUnregisterServer(void)
  127. {
  128. #ifdef _MERGE_PROXYSTUB
  129. PrxDllUnregisterServer();
  130. #endif
  131. HRESULT hr = NOERROR;
  132. HRESULT hrCoInit = CoInitialize( NULL );
  133. // Remove the iis utilities package before unregistering the objects
  134. hr = RemoveViperUtilPackage(NULL);
  135. if( SUCCEEDED(hrCoInit) )
  136. {
  137. CoUninitialize();
  138. }
  139. // We don't really care about failures...
  140. hr = _Module.UnregisterServer(/* ATL21 TRUE */);
  141. // NOTE: ATL doesn't unregister the typelibrary. Since
  142. // the interfaces we are exposing are internal to asp we should
  143. // consider removing the typelibrary registry entries.
  144. return hr;
  145. }
  146. // Registration code to be pulled from asp.dll
  147. #define RELEASE(p) if ( p ) { p->Release(); p = NULL; }
  148. #define FREEBSTR(p) SysFreeString( p ); p = NULL;
  149. const WCHAR wszCLSID_ASPObjectContextTxRequired[] = L"{14D0916D-9CDC-11D1-8C4A-00C04FC324A4}";
  150. const WCHAR wszCLSID_ASPObjectContextTxRequiresNew[] = L"{14D0916E-9CDC-11D1-8C4A-00C04FC324A4}";
  151. const WCHAR wszCLSID_ASPObjectContextTxSupported[] = L"{14D0916F-9CDC-11D1-8C4A-00C04FC324A4}";
  152. const WCHAR wszCLSID_ASPObjectContextTxNotSupported[] = L"{14D09170-9CDC-11D1-8C4A-00C04FC324A4}";
  153. const WCHAR wszASPUtilitiesPackageID[] = L"{ADA44581-02C1-11D1-804A-0000F8036614}";
  154. /*===================================================================
  155. GetSafeArrayOfCLSIDs
  156. Get a SafeArray contains one ComponentCLSID
  157. Parameter:
  158. szComponentCLSID the CLSID need to be put in the safe array
  159. paCLSIDs pointer to a pointer of safe array(safe array provided by
  160. caller).
  161. Return: HRESULT
  162. Side Affect:
  163. Note:
  164. ===================================================================*/
  165. HRESULT GetSafeArrayOfCLSIDs
  166. (
  167. IN LPCWSTR szComponentCLSID,
  168. OUT SAFEARRAY** paCLSIDs
  169. )
  170. {
  171. SAFEARRAY* aCLSIDs = NULL;
  172. SAFEARRAYBOUND rgsaBound[1];
  173. LONG Indices[1];
  174. VARIANT varT;
  175. HRESULT hr = NOERROR;
  176. DBG_ASSERT(szComponentCLSID && paCLSIDs);
  177. DBG_ASSERT(*paCLSIDs == NULL);
  178. // PopulateByKey is expecting a SAFEARRAY parameter input,
  179. // Create a one element SAFEARRAY, the one element of the SAFEARRAY contains
  180. // the packageID.
  181. rgsaBound[0].cElements = 1;
  182. rgsaBound[0].lLbound = 0;
  183. aCLSIDs = SafeArrayCreate(VT_VARIANT, 1, rgsaBound);
  184. if (aCLSIDs)
  185. {
  186. Indices[0] = 0;
  187. VariantInit(&varT);
  188. varT.vt = VT_BSTR;
  189. varT.bstrVal = SysAllocString(szComponentCLSID);
  190. hr = SafeArrayPutElement(aCLSIDs, Indices, &varT);
  191. VariantClear(&varT);
  192. if (FAILED(hr))
  193. {
  194. DBGPRINTF((DBG_CONTEXT, "Failed to call SafeArrayPutElement, CLSID is %S, hr %08x\n",
  195. szComponentCLSID,
  196. hr));
  197. if (aCLSIDs != NULL)
  198. {
  199. HRESULT hrT = SafeArrayDestroy(aCLSIDs);
  200. if (FAILED(hrT))
  201. {
  202. DBGPRINTF((DBG_CONTEXT, "Failed to call SafeArrayDestroy(aCLSIDs), hr = %08x\n",
  203. hr));
  204. }
  205. aCLSIDs = NULL;
  206. }
  207. }
  208. }
  209. else
  210. {
  211. hr = HRESULT_FROM_WIN32(GetLastError());
  212. DBGPRINTF((DBG_CONTEXT, "Failed to call SafeArrayCreate, hr %08x\n",
  213. hr));
  214. }
  215. *paCLSIDs = aCLSIDs;
  216. return hr;
  217. }
  218. /*===================================================================
  219. ViperizeContextObject
  220. Creates a Viper package, and adds the Context object to that
  221. package, and marks the object as "InProc".
  222. Returns:
  223. HRESULT - NOERROR on success
  224. Side effects:
  225. Creates Viper package, Viperizes Context object
  226. ===================================================================*/
  227. HRESULT ViperizeContextObject(void)
  228. {
  229. HRESULT hr;
  230. // Add the IIS utility package
  231. hr = AddViperUtilPackage();
  232. // Add the context object to the package
  233. if (SUCCEEDED(hr))
  234. hr = AddContextObjectToViperPackage();
  235. return hr;
  236. }
  237. /*===================================================================
  238. AddViperUtilPackage
  239. Creates a Viper package named "IIS Utility"
  240. Returns:
  241. HRESULT - NOERROR on success
  242. Side effects:
  243. Creates Viper package
  244. ===================================================================*/
  245. HRESULT AddViperUtilPackage(void)
  246. {
  247. HRESULT hr;
  248. BSTR bstr = NULL;
  249. VARIANT varT;
  250. ICatalogCollection* pPkgCollection = NULL;
  251. ICatalogObject* pPackage = NULL;
  252. ICOMAdminCatalog* pCatalog = NULL;
  253. long lPkgCount, lChanges, i;
  254. VariantInit(&varT);
  255. // Create instance of the catalog object
  256. hr = CoCreateInstance(CLSID_COMAdminCatalog
  257. , NULL
  258. , CLSCTX_INPROC_SERVER
  259. , IID_ICOMAdminCatalog
  260. , (void**)&pCatalog);
  261. if (FAILED(hr))
  262. goto LErr;
  263. // Get the Packages collection
  264. bstr = SysAllocString(L"Applications");
  265. hr = pCatalog->GetCollection(bstr, (IDispatch**)&pPkgCollection);
  266. FREEBSTR(bstr);
  267. if (FAILED(hr))
  268. goto LErr;
  269. // Add new IIS Utilities package
  270. hr = pPkgCollection->Add((IDispatch**)&pPackage);
  271. if (FAILED(hr))
  272. goto LErr;
  273. // Set package ID to L"{ADA44581-02C1-11D1-804A-0000F8036614}",
  274. // MTS replication code looks for This fixed packageID
  275. bstr = SysAllocString(L"ID");
  276. varT.vt = VT_BSTR;
  277. varT.bstrVal = SysAllocString(wszASPUtilitiesPackageID);
  278. hr = pPackage->put_Value(bstr, varT);
  279. FREEBSTR(bstr);
  280. VariantClear(&varT);
  281. if (FAILED(hr))
  282. goto LErr;
  283. // Set package "Name" property to "IIS Utilities"
  284. bstr = SysAllocString(L"Name");
  285. varT.vt = VT_BSTR;
  286. varT.bstrVal = SysAllocString(L"IIS Utilities");
  287. hr = pPackage->put_Value(bstr, varT);
  288. FREEBSTR(bstr);
  289. VariantClear(&varT);
  290. if (FAILED(hr))
  291. goto LErr;
  292. // Set activation to InProc
  293. bstr = SysAllocString(L"Activation");
  294. varT.vt = VT_BSTR;
  295. varT.bstrVal = SysAllocString(L"InProc");
  296. hr = pPackage->put_Value(bstr, varT);
  297. FREEBSTR(bstr);
  298. VariantClear(&varT);
  299. if (FAILED(hr))
  300. goto LErr;
  301. // Set CreatedBy to MS IIS
  302. bstr = SysAllocString(L"CreatedBy");
  303. varT.vt = VT_BSTR;
  304. varT.bstrVal = SysAllocString(L"Microsoft Internet Information Services (tm)");
  305. hr = pPackage->put_Value(bstr, varT);
  306. FREEBSTR(bstr);
  307. VariantClear(&varT);
  308. if (FAILED(hr))
  309. goto LErr;
  310. // Set Deleteable = N property on package
  311. bstr = SysAllocString(L"Deleteable");
  312. varT.vt = VT_BSTR;
  313. varT.bstrVal = SysAllocString(L"N");
  314. hr = pPackage->put_Value(bstr, varT);
  315. FREEBSTR(bstr);
  316. VariantClear(&varT);
  317. if (FAILED(hr))
  318. goto LErr;
  319. bstr = SysAllocString(L"AccessChecksLevel");
  320. varT.vt = VT_BSTR;
  321. varT.bstrVal = SysAllocString(L"0");
  322. hr = pPackage->put_Value(bstr, varT);
  323. FREEBSTR(bstr);
  324. VariantClear(&varT);
  325. if (FAILED(hr))
  326. goto LErr;
  327. // Save changes
  328. hr = pPkgCollection->SaveChanges(&lChanges);
  329. if (FAILED(hr))
  330. goto LErr;
  331. LErr:
  332. RELEASE(pPkgCollection);
  333. RELEASE(pPackage);
  334. RELEASE(pCatalog);
  335. return hr;
  336. }
  337. /*===================================================================
  338. RemoveViperUtilPackage
  339. Removes the Viper package named "IIS Utility"
  340. Parameters:
  341. ICatalogCollection* pPkgCollection
  342. If non-null, will use this collection. Otherwise, will
  343. open its own collection
  344. Returns:
  345. HRESULT - NOERROR on success
  346. Side effects:
  347. Removes Viper package
  348. ===================================================================*/
  349. HRESULT RemoveViperUtilPackage(ICatalogCollection* pPkgCollectionT)
  350. {
  351. HRESULT hr;
  352. ICatalogCollection* pPkgCollection = NULL;
  353. ICatalogObject* pPackage = NULL;
  354. ICOMAdminCatalog* pCatalog = NULL;
  355. LONG lPkgCount, lChanges, i;
  356. SAFEARRAY* aCLSIDs = NULL;
  357. // if package collection was passed, use it
  358. if (pPkgCollectionT != NULL)
  359. {
  360. pPkgCollection = pPkgCollectionT;
  361. }
  362. else
  363. {
  364. BSTR bstr = NULL;
  365. // Create instance of the catalog object
  366. hr = CoCreateInstance(CLSID_COMAdminCatalog
  367. , NULL
  368. , CLSCTX_INPROC_SERVER
  369. , IID_ICOMAdminCatalog
  370. , (void**)&pCatalog);
  371. if (FAILED(hr))
  372. goto LErr;
  373. // Get the Packages collection
  374. bstr = SysAllocString(L"Applications");
  375. hr = pCatalog->GetCollection(bstr, (IDispatch**)&pPkgCollection);
  376. FREEBSTR(bstr);
  377. if (FAILED(hr))
  378. goto LErr;
  379. }
  380. hr = GetSafeArrayOfCLSIDs(wszASPUtilitiesPackageID, &aCLSIDs);
  381. if (FAILED(hr))
  382. {
  383. DBGPRINTF((DBG_CONTEXT, "Failed to get SafeArrayofCLSIDs, szPackageID is %S, hr %08x",
  384. wszASPUtilitiesPackageID,
  385. hr));
  386. goto LErr;
  387. }
  388. //
  389. // Populate it
  390. //
  391. hr = pPkgCollection->PopulateByKey(aCLSIDs);
  392. if (FAILED(hr))
  393. {
  394. DBGPRINTF((DBG_CONTEXT, "Failed to call PopulateByKey(), hr = %08x\n",
  395. hr));
  396. goto LErr;
  397. }
  398. // Delete any existing "IIS Utilities" package
  399. hr = pPkgCollection->get_Count(&lPkgCount);
  400. if (FAILED(hr))
  401. {
  402. DBGPRINTF((DBG_CONTEXT, "pPkgCollection->Populate() failed, hr = %08x\n",
  403. hr));
  404. goto LErr;
  405. }
  406. if (SUCCEEDED(hr) && lPkgCount == 1)
  407. {
  408. hr = pPkgCollection->get_Item(0, (IDispatch**)&pPackage);
  409. if (FAILED(hr))
  410. {
  411. goto LErr;
  412. }
  413. BSTR bstr = NULL;
  414. VARIANT varT;
  415. // Found it - remove it and call Save Changes
  416. // First, Set Deleteable = Y property on package
  417. bstr = SysAllocString(L"Deleteable");
  418. VariantInit(&varT);
  419. varT.vt = VT_BSTR;
  420. varT.bstrVal = SysAllocString(L"Y");
  421. hr = pPackage->put_Value(bstr, varT);
  422. FREEBSTR(bstr);
  423. VariantClear(&varT);
  424. if (FAILED(hr))
  425. {
  426. goto LErr;
  427. }
  428. RELEASE(pPackage);
  429. // Let save the Deletable settings
  430. hr = pPkgCollection->SaveChanges(&lChanges);
  431. if (FAILED(hr))
  432. {
  433. DBGPRINTF((DBG_CONTEXT, "Save the Deletable settings failed, hr = %08x\n",
  434. hr));
  435. goto LErr;
  436. }
  437. // Now we can delete
  438. hr = pPkgCollection->Remove(0);
  439. if (FAILED(hr))
  440. {
  441. DBGPRINTF((DBG_CONTEXT, "Remove the Component from package failed, hr = %08x\n",
  442. hr));
  443. goto LErr;
  444. }
  445. // Aha, we should be able to delete now.
  446. hr = pPkgCollection->SaveChanges(&lChanges);
  447. if (FAILED(hr))
  448. {
  449. DBGPRINTF((DBG_CONTEXT, "Save changes failed, hr = %08x\n",
  450. hr));
  451. goto LErr;
  452. }
  453. }
  454. LErr:
  455. if (aCLSIDs != NULL)
  456. {
  457. HRESULT hrT = SafeArrayDestroy(aCLSIDs);
  458. aCLSIDs = NULL;
  459. }
  460. if (pPkgCollectionT == NULL)
  461. RELEASE(pPkgCollection);
  462. RELEASE(pCatalog);
  463. RELEASE(pPackage);
  464. return hr;
  465. }
  466. /*===================================================================
  467. AddContextObjectToViperPackage
  468. Adds the Context object to the Viper package named "IIS Utility"
  469. Returns:
  470. HRESULT - NOERROR on success
  471. Side effects:
  472. Adds the object to the Viper package
  473. ===================================================================*/
  474. HRESULT AddContextObjectToViperPackage()
  475. {
  476. HRESULT hr;
  477. BSTR bstr = NULL;
  478. BSTR bstrAppGUID = NULL;
  479. BSTR bstrGUID = NULL;
  480. VARIANT varName;
  481. VARIANT varKey;
  482. VARIANT varT;
  483. ICatalogCollection* pPkgCollection = NULL;
  484. ICatalogCollection* pCompCollection = NULL;
  485. ICatalogObject* pComponent = NULL;
  486. ICatalogObject* pPackage = NULL;
  487. ICOMAdminCatalog* pCatalog = NULL;
  488. long lPkgCount, lCompCount, lChanges, iT;
  489. BOOL fFound;
  490. SAFEARRAY* aCLSIDs = NULL;
  491. VariantInit(&varKey);
  492. VariantClear(&varKey);
  493. VariantInit(&varName);
  494. VariantClear(&varName);
  495. VariantInit(&varT);
  496. VariantClear(&varT);
  497. // Create instance of the catalog object
  498. hr = CoCreateInstance(CLSID_COMAdminCatalog
  499. , NULL
  500. , CLSCTX_INPROC_SERVER
  501. , IID_ICOMAdminCatalog
  502. , (void**)&pCatalog);
  503. if (FAILED(hr))
  504. goto LErr;
  505. // Get the Packages collection
  506. bstr = SysAllocString(L"Applications");
  507. hr = pCatalog->GetCollection(bstr, (IDispatch**)&pPkgCollection);
  508. SysFreeString(bstr);
  509. if (FAILED(hr))
  510. goto LErr;
  511. hr = GetSafeArrayOfCLSIDs(wszASPUtilitiesPackageID, &aCLSIDs);
  512. if (FAILED(hr))
  513. {
  514. DBGPRINTF((DBG_CONTEXT, "Failed to get SafeArrayofCLSIDs, szPackageID is %S, hr %08x",
  515. wszASPUtilitiesPackageID,
  516. hr));
  517. goto LErr;
  518. }
  519. bstrAppGUID = SysAllocString(wszASPUtilitiesPackageID);
  520. // Actually put the components in the package
  521. bstrGUID = SysAllocString(wszCLSID_ASPObjectContextTxRequired);
  522. hr = pCatalog->ImportComponent(bstrAppGUID ,bstrGUID);
  523. SysFreeString(bstrGUID);
  524. if (FAILED(hr))
  525. goto LErr;
  526. bstrGUID = SysAllocString(wszCLSID_ASPObjectContextTxRequiresNew);
  527. hr = pCatalog->ImportComponent(bstrAppGUID ,bstrGUID);
  528. SysFreeString(bstrGUID);
  529. if (FAILED(hr))
  530. goto LErr;
  531. bstrGUID = SysAllocString(wszCLSID_ASPObjectContextTxSupported);
  532. hr = pCatalog->ImportComponent(bstrAppGUID ,bstrGUID);
  533. SysFreeString(bstrGUID);
  534. if (FAILED(hr))
  535. goto LErr;
  536. bstrGUID = SysAllocString(wszCLSID_ASPObjectContextTxNotSupported);
  537. hr = pCatalog->ImportComponent(bstrAppGUID ,bstrGUID);
  538. SysFreeString(bstrGUID);
  539. if (FAILED(hr))
  540. goto LErr;
  541. varKey.vt = VT_BSTR;
  542. varKey.bstrVal = SysAllocString(wszASPUtilitiesPackageID);
  543. //
  544. // Populate packages
  545. //
  546. hr = pPkgCollection->PopulateByKey(aCLSIDs);
  547. if (FAILED(hr))
  548. {
  549. DBGPRINTF((DBG_CONTEXT, "Failed to call PopulateByKey(), hr = %08x\n",
  550. hr));
  551. goto LErr;
  552. }
  553. // Find "IIS Utilities" package
  554. hr = pPkgCollection->get_Count(&lPkgCount);
  555. if (FAILED(hr))
  556. {
  557. DBGPRINTF((DBG_CONTEXT, "pPkgCollection->Populate() failed, hr = %08x\n",
  558. hr));
  559. goto LErr;
  560. }
  561. if (SUCCEEDED(hr) && lPkgCount == 1)
  562. {
  563. hr = pPkgCollection->get_Item(0, (IDispatch**)&pPackage);
  564. if (FAILED(hr))
  565. {
  566. goto LErr;
  567. }
  568. }
  569. DBG_ASSERT(pPackage != NULL);
  570. // Get the "ComponentsInPackage" collection.
  571. bstr = SysAllocString(L"Components");
  572. hr = pPkgCollection->GetCollection(bstr, varKey, (IDispatch**)&pCompCollection);
  573. SysFreeString(bstr);
  574. if (FAILED(hr))
  575. goto LErr;
  576. // Repopulate the collection so we can find our object and set properties on it
  577. hr = pCompCollection->Populate();
  578. if (FAILED(hr))
  579. goto LErr;
  580. // Find our components in the list (should be four)
  581. hr = pCompCollection->get_Count(&lCompCount);
  582. if (FAILED(hr))
  583. goto LErr;
  584. DBG_ASSERT(lCompCount == 4);
  585. RELEASE(pComponent);
  586. VariantClear(&varKey);
  587. for (iT = (lCompCount-1); iT >= 0 ; iT--)
  588. {
  589. hr = pCompCollection->get_Item(iT, (IDispatch**)&pComponent);
  590. if (FAILED(hr))
  591. goto LErr;
  592. hr = pComponent->get_Key(&varKey);
  593. if (FAILED(hr))
  594. goto LErr;
  595. DBG_ASSERT(varKey.bstrVal);
  596. fFound = FALSE;
  597. if (_wcsicmp(varKey.bstrVal, wszCLSID_ASPObjectContextTxRequired) == 0)
  598. {
  599. // Required
  600. bstr = SysAllocString(L"3");
  601. fFound = TRUE;
  602. }
  603. else if (_wcsicmp(varKey.bstrVal, wszCLSID_ASPObjectContextTxRequiresNew) == 0)
  604. {
  605. // Requires New
  606. bstr = SysAllocString(L"4");
  607. fFound = TRUE;
  608. }
  609. else if (_wcsicmp(varKey.bstrVal, wszCLSID_ASPObjectContextTxSupported) == 0)
  610. {
  611. // Supported
  612. bstr = SysAllocString(L"2");
  613. fFound = TRUE;
  614. }
  615. else if (_wcsicmp(varKey.bstrVal, wszCLSID_ASPObjectContextTxNotSupported) == 0)
  616. {
  617. // Not Supported
  618. bstr = SysAllocString(L"1");
  619. fFound = TRUE;
  620. }
  621. if (fFound)
  622. {
  623. varT.vt = VT_BSTR;
  624. varT.bstrVal = bstr;
  625. bstr = SysAllocString(L"Transaction");
  626. hr = pComponent->put_Value(bstr, varT);
  627. FREEBSTR(bstr);
  628. VariantClear(&varT);
  629. if (FAILED(hr))
  630. goto LErr;
  631. bstr = SysAllocString(L"Description");
  632. varT.vt = VT_BSTR;
  633. varT.bstrVal = SysAllocString(L"ASP Tx Script Context");
  634. hr = pComponent->put_Value(bstr, varT);
  635. FREEBSTR(bstr);
  636. VariantClear(&varT);
  637. if (FAILED(hr))
  638. goto LErr;
  639. bstr = SysAllocString(L"EventTrackingEnabled");
  640. varT.vt = VT_BSTR;
  641. varT.bstrVal = SysAllocString(L"N");
  642. hr = pComponent->put_Value(bstr, varT);
  643. FREEBSTR(bstr);
  644. VariantClear(&varT);
  645. if (FAILED(hr))
  646. goto LErr;
  647. }
  648. VariantClear(&varKey);
  649. RELEASE(pComponent);
  650. }
  651. // Save changes
  652. hr = pCompCollection->SaveChanges(&lChanges);
  653. if (FAILED(hr))
  654. goto LErr;
  655. bstr = SysAllocString(L"Activation");
  656. varT.vt = VT_BSTR;
  657. varT.bstrVal = SysAllocString(L"InProc");
  658. hr = pPackage->put_Value(bstr, varT);
  659. FREEBSTR(bstr);
  660. VariantClear(&varT);
  661. if (FAILED(hr))
  662. goto LErr;
  663. // Save changes
  664. hr = pPkgCollection->SaveChanges(&lChanges);
  665. if (FAILED(hr))
  666. goto LErr;
  667. hr = pPkgCollection->Populate();
  668. if (FAILED(hr))
  669. goto LErr;
  670. // Now that our one object is added to the package, set the Changeable property
  671. // on the package to "No", so no one can mess with it
  672. bstr = SysAllocString(L"Changeable");
  673. varT.vt = VT_BSTR;
  674. varT.bstrVal = SysAllocString(L"N");
  675. hr = pPackage->put_Value(bstr, varT);
  676. FREEBSTR(bstr);
  677. VariantClear(&varT);
  678. if (FAILED(hr))
  679. goto LErr;
  680. // Save changes
  681. hr = pPkgCollection->SaveChanges(&lChanges);
  682. if (FAILED(hr))
  683. goto LErr;
  684. LErr:
  685. DBG_ASSERT(SUCCEEDED(hr));
  686. if (aCLSIDs)
  687. {
  688. SafeArrayDestroy(aCLSIDs);
  689. aCLSIDs = NULL;
  690. }
  691. RELEASE(pCompCollection);
  692. RELEASE(pPkgCollection);
  693. RELEASE(pComponent);
  694. RELEASE(pPackage);
  695. RELEASE(pCatalog);
  696. FREEBSTR(bstrAppGUID);
  697. FREEBSTR(bstr);
  698. VariantClear(&varName);
  699. VariantClear(&varKey);
  700. VariantClear(&varT);
  701. return hr;
  702. } // AddContextObjectToViperPackage