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.

1298 lines
35 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: propifs.hxx
  7. //
  8. // Contents: Common definitions for object activation.
  9. //
  10. // Classes: InstantiationInfo
  11. // ServerLocationInfo
  12. //
  13. // History: 03-Feb-98 Vinaykr Created
  14. //
  15. //--------------------------------------------------------------------------
  16. #ifndef __PROPIFS_HXX__
  17. #define __PROPIFS_HXX__
  18. #include <Serializ.h>
  19. #include <immact.h>
  20. #include <activate.h>
  21. #include <privact.h>
  22. #include <custmact.h>
  23. #include <serial.hxx>
  24. #include <actprops.hxx>
  25. #ifndef OLESCM
  26. #include <context.hxx>
  27. #endif
  28. #define ActMemAlloc(cb) MIDL_user_allocate(cb)
  29. #define ActMemFree(pv) MIDL_user_free(pv)
  30. #define MAX_ACTARRAY_SIZE 10
  31. extern HRESULT ReleaseIFD(
  32. MInterfacePointer *pIRD);
  33. static inline WCHAR *makeWStringCopy(WCHAR *pwszStr)
  34. {
  35. DWORD l = lstrlenW(pwszStr);
  36. WCHAR * newstr = (WCHAR*) ActMemAlloc((l+1)*sizeof(WCHAR));
  37. if (newstr != NULL)
  38. lstrcpyW(newstr,pwszStr);
  39. return newstr;
  40. }
  41. //----------------------------------------------------------------------
  42. // Prototypes for the CoMarshal family of functions
  43. //----------------------------------------------------------------------
  44. // These are function pointers to avoid using them inside of rpcss.dll.
  45. // (rpcss.dll may not link with ole32.dll)
  46. typedef HRESULT (__stdcall *PFN_COMARSHALINTERFACE)(IN LPSTREAM pStm,
  47. IN REFIID riid,
  48. IN LPUNKNOWN pUnk,
  49. IN DWORD dwDestContext,
  50. IN LPVOID pvDestContext,
  51. IN DWORD mshlflags);
  52. extern PFN_COMARSHALINTERFACE pfnCoMarshalInterface;
  53. typedef HRESULT (__stdcall *PFN_COGETMARSHALSIZEMAX)(IN LPDWORD pSz,
  54. IN REFIID riid,
  55. IN LPUNKNOWN pUnk,
  56. IN DWORD dwDestContext,
  57. IN LPVOID pvDestContext,
  58. IN DWORD mshlflags);
  59. extern PFN_COGETMARSHALSIZEMAX pfnCoGetMarshalSizeMax;
  60. typedef HRESULT (__stdcall *PFN_COUNMARSHALINTERFACE)(IN LPSTREAM pStm,
  61. IN REFIID riid,
  62. OUT LPVOID FAR* ppv);
  63. extern PFN_COUNMARSHALINTERFACE pfnCoUnmarshalInterface;
  64. typedef HRESULT (__stdcall *PFN_CORELEASEMARSHALDATA)(IN LPSTREAM pStm);
  65. extern PFN_CORELEASEMARSHALDATA pfnCoReleaseMarshalData;
  66. // Call this to initialize the function pointers.
  67. void InitMarshalling(void);
  68. class SerializableProperty: public ISerializable
  69. {
  70. public:
  71. SerializableProperty():_parent(0),_unSerialized(FALSE),_added(FALSE)
  72. {}
  73. //Serialization Methods
  74. STDMETHOD (SetParent) ( ISerializableParent *pParent)
  75. {
  76. _parent = pParent;
  77. return S_OK;
  78. }
  79. inline BOOL IsAdded()
  80. {
  81. return _added;
  82. }
  83. inline void Added()
  84. {
  85. _added = TRUE;
  86. }
  87. inline BOOL IsInproc(Serializer *pSer,
  88. OUT DWORD *pdwMaxDestCtx,
  89. OUT DWORD *pdwCurrDestCtx)
  90. {
  91. pSer->GetCurrDestCtx(pdwCurrDestCtx);
  92. pSer->GetMaxDestCtx(pdwMaxDestCtx);
  93. return ((*pdwCurrDestCtx == MSHCTX_CROSSCTX)||
  94. (*pdwCurrDestCtx == MSHCTX_INPROC));
  95. }
  96. inline BOOL IsInproc(Serializer *pSer)
  97. {
  98. DWORD dwCurrDestCtx;
  99. pSer->GetCurrDestCtx(&dwCurrDestCtx);
  100. return ((dwCurrDestCtx == MSHCTX_CROSSCTX)||
  101. (dwCurrDestCtx == MSHCTX_INPROC));
  102. }
  103. protected:
  104. ISerializableParent *_parent;
  105. BOOL _unSerialized;
  106. BOOL _added;
  107. };
  108. class InstantiationInfo : public IInstantiationInfo,
  109. public SerializableProperty
  110. {
  111. public:
  112. InstantiationInfo()
  113. {
  114. ZeroMemory(&_instantiationInfoData, sizeof(InstantiationInfoData));
  115. _instantiationInfoData.clientCOMVersion.MajorVersion
  116. = COM_MAJOR_VERSION;
  117. _instantiationInfoData.clientCOMVersion.MinorVersion
  118. = COM_MINOR_VERSION;
  119. }
  120. virtual ~InstantiationInfo()
  121. {
  122. if (_instantiationInfoData.pIID != _pIIDs)
  123. ActMemFree(_instantiationInfoData.pIID);
  124. }
  125. // Methods from IUnknown
  126. STDMETHOD (QueryInterface) ( REFIID riid, LPVOID* ppvObj);
  127. STDMETHOD_(ULONG,AddRef) ( void );
  128. STDMETHOD_(ULONG,Release) ( void );
  129. inline HRESULT SetClientCOMVersion(COMVERSION version)
  130. {
  131. _instantiationInfoData.clientCOMVersion = version;
  132. return S_OK;
  133. }
  134. inline HRESULT GetClientCOMVersion(COMVERSION **ppVersion)
  135. {
  136. *ppVersion = &_instantiationInfoData.clientCOMVersion;
  137. return S_OK;
  138. }
  139. inline HRESULT SetClsid(IN REFGUID clsid)
  140. {
  141. _instantiationInfoData.classId = clsid;
  142. return S_OK;
  143. }
  144. inline HRESULT GetClsid(OUT GUID *pClsid)
  145. {
  146. *pClsid = _instantiationInfoData.classId;
  147. return S_OK;
  148. }
  149. inline HRESULT SetClsctx(IN DWORD dwClsctx)
  150. {
  151. _instantiationInfoData.classCtx = dwClsctx;
  152. return S_OK;
  153. }
  154. inline HRESULT GetClsctx(OUT DWORD *pdwClsctx)
  155. {
  156. *pdwClsctx = _instantiationInfoData.classCtx;
  157. return S_OK;
  158. }
  159. inline HRESULT SetActivationFlags(IN DWORD dwActvFlags)
  160. {
  161. _instantiationInfoData.actvflags = dwActvFlags;
  162. return S_OK;
  163. }
  164. inline HRESULT GetActivationFlags(OUT DWORD *pdwActvFlags)
  165. {
  166. *pdwActvFlags = _instantiationInfoData.actvflags;
  167. return S_OK;
  168. }
  169. inline HRESULT SetInstFlag(IN DWORD flag)
  170. {
  171. _instantiationInfoData.instFlag = flag;
  172. return S_OK;
  173. }
  174. inline HRESULT GetInstFlag(OUT DWORD *pFlag)
  175. {
  176. *pFlag = _instantiationInfoData.instFlag;
  177. return S_OK;
  178. }
  179. inline HRESULT SetIsSurrogate()
  180. {
  181. _instantiationInfoData.fIsSurrogate = TRUE;
  182. return S_OK;
  183. }
  184. inline HRESULT GetIsSurrogate(BOOL *pIsSurrogate)
  185. {
  186. *pIsSurrogate = _instantiationInfoData.fIsSurrogate;
  187. return S_OK;
  188. }
  189. inline HRESULT GetRequestedIIDs(
  190. OUT DWORD *pcIfs,
  191. OUT IID **ppIID)
  192. {
  193. *pcIfs = _instantiationInfoData.cIID;
  194. *ppIID = _instantiationInfoData.pIID;
  195. return S_OK;
  196. }
  197. inline HRESULT AddRequestedIIDs(
  198. IN DWORD cIfs,
  199. IN IID *pIID)
  200. {
  201. IID *newiids;
  202. //--------------------------------------------------------------------
  203. // Check if we need to allocate
  204. //--------------------------------------------------------------------
  205. if ((_unSerialized) || (cIfs + _instantiationInfoData.cIID) > MAX_ACTARRAY_SIZE)
  206. {
  207. newiids = (IID*) ActMemAlloc(sizeof(IID) *
  208. (cIfs + _instantiationInfoData.cIID));
  209. if (newiids == NULL)
  210. return E_OUTOFMEMORY;
  211. //----------------------------------------------------------------
  212. // Copy old into new
  213. //----------------------------------------------------------------
  214. if (_instantiationInfoData.cIID)
  215. {
  216. memcpy(newiids,
  217. _instantiationInfoData.pIID,
  218. sizeof(IID)*_instantiationInfoData.cIID);
  219. if (_instantiationInfoData.pIID != _pIIDs)
  220. ActMemFree(_instantiationInfoData.pIID);
  221. }
  222. }
  223. else
  224. newiids = _pIIDs;
  225. //--------------------------------------------------------------------
  226. // Copy new into array
  227. //--------------------------------------------------------------------
  228. memcpy(&newiids[_instantiationInfoData.cIID],
  229. pIID, sizeof(IID)*cIfs);
  230. _instantiationInfoData.pIID = newiids;
  231. _instantiationInfoData.cIID += cIfs;
  232. return S_OK;
  233. }
  234. //Serialization Methods
  235. STDMETHOD (SerializableQueryInterface) ( REFIID riid, LPVOID* ppvObj);
  236. STDMETHOD(Serialize)(IN void *pSer);
  237. STDMETHOD(UnSerialize)(IN void *pSer);
  238. STDMETHOD(GetSize)(IN void *pSer, OUT DWORD *pdwSize);
  239. STDMETHOD(GetCLSID)(OUT CLSID *pclsid);
  240. private:
  241. InstantiationInfoData _instantiationInfoData;
  242. IID _pIIDs[MAX_ACTARRAY_SIZE];
  243. };
  244. class ServerLocationInfo: public IServerLocationInfo, public SerializableProperty
  245. {
  246. public:
  247. // ctor/dtor
  248. ServerLocationInfo();
  249. virtual ~ServerLocationInfo();
  250. // Methods from IUnknown
  251. STDMETHOD (QueryInterface) ( REFIID riid, LPVOID* ppvObj);
  252. STDMETHOD_(ULONG,AddRef) ( void );
  253. STDMETHOD_(ULONG,Release) ( void );
  254. STDMETHOD (SetRemoteServerName) (IN WCHAR *pwszMachineName);
  255. STDMETHOD(GetRemoteServerName) (OUT WCHAR **ppwszMachineName)
  256. {
  257. *ppwszMachineName = _locationInfoData.machineName;
  258. return S_OK;
  259. }
  260. STDMETHOD (SetProcess) (IN DWORD processId, DWORD dwPRT);
  261. STDMETHOD (GetProcess) (OUT DWORD* pProcessId, DWORD* pdwPRT);
  262. STDMETHOD (SetApartment) (IN APTID apartmentId)
  263. {
  264. _locationInfoData.apartmentId = apartmentId;
  265. return S_OK;
  266. }
  267. STDMETHOD (GetApartment) (OUT APTID *pApartmentId)
  268. {
  269. *pApartmentId = _locationInfoData.apartmentId;
  270. return S_OK;
  271. }
  272. STDMETHOD (SetContext) (IN IObjContext *pObjectContext)
  273. {
  274. HRESULT hr = pObjectContext->QueryInterface(IID_IStdObjectContext, (void**)&_pObjectContext);
  275. Win4Assert(SUCCEEDED(hr) && "Not COM internal context!");
  276. if (SUCCEEDED(hr))
  277. {
  278. // Get an internal ref and release the user ref.
  279. _pObjectContext->InternalAddRef();
  280. _pObjectContext->Release();
  281. }
  282. return hr;
  283. }
  284. STDMETHOD (GetContext) (OUT IObjContext **ppObjectContext)
  285. {
  286. CObjectContext *pCtx;
  287. GetInternalContext(&pCtx);
  288. if (pCtx)
  289. {
  290. // Return a user counted reference to the context.
  291. pCtx->AddRef();
  292. pCtx->InternalRelease();
  293. *ppObjectContext = (IObjContext*)pCtx;
  294. }
  295. return S_OK;
  296. }
  297. STDMETHOD(Serialize)(IN void *pSer);
  298. STDMETHOD(UnSerialize)(IN void *pSer);
  299. STDMETHOD(GetSize)(IN void *pSer, OUT DWORD *pdwSize);
  300. STDMETHOD(GetCLSID)(OUT CLSID *pclsid);
  301. STDMETHOD(UnSerializeCallBack)(REFCLSID clsid, ISerializable **ppSer=0)
  302. { return E_NOTIMPL;}
  303. STDMETHOD (SerializableQueryInterface) ( REFIID riid, LPVOID* ppvObj);
  304. HRESULT GetInternalContext(CObjectContext **ppObjectContext)
  305. {
  306. if (_pObjectContext)
  307. _pObjectContext->InternalAddRef();
  308. *ppObjectContext = _pObjectContext;
  309. return S_OK;
  310. }
  311. // Gives us a non-refcounted ISpecialSystemProperties* interface ptr; we
  312. // need this so we can store/retrieve certain activation state from it.s
  313. void SetSpecialPropsInterface(ISpecialSystemProperties* pISSP)
  314. {
  315. Win4Assert(!_pISSP && "_pISSP should not be set twice");
  316. _pISSP = pISSP; // no refcount -- we do not release this
  317. };
  318. private:
  319. LocationInfoData _locationInfoData;
  320. CObjectContext *_pObjectContext;
  321. ISpecialSystemProperties* _pISSP;
  322. };
  323. class SecurityInfo:public IActivationSecurityInfo, public ILegacyInfo, public SerializableProperty
  324. {
  325. public:
  326. SecurityInfo()
  327. {
  328. ZeroMemory(&_securityInfoData, sizeof(SecurityInfoData));
  329. }
  330. inline static void freeCOAUTHIDENTITY(COAUTHIDENTITY *id)
  331. {
  332. if (id)
  333. {
  334. ActMemFree(id->User);
  335. ActMemFree(id->Domain);
  336. ActMemFree(id->Password);
  337. ActMemFree(id);
  338. }
  339. }
  340. inline static void freeCOAUTHINFO(COAUTHINFO *info)
  341. {
  342. if (info)
  343. {
  344. ActMemFree(info->pwszServerPrincName);
  345. freeCOAUTHIDENTITY(info->pAuthIdentityData);
  346. ActMemFree(info);
  347. }
  348. }
  349. inline static void freeCOSERVERINFO(COSERVERINFO *info)
  350. {
  351. if (info)
  352. {
  353. ActMemFree(info->pwszName);
  354. freeCOAUTHINFO(info->pAuthInfo);
  355. ActMemFree(info);
  356. }
  357. }
  358. virtual ~SecurityInfo()
  359. {
  360. // Free only if unmarshaled (in which case the
  361. // memory has been allocated by the marshaler)
  362. // We don't do deep copy, client frees these
  363. // blobs after activation.
  364. if (_unSerialized)
  365. {
  366. freeCOSERVERINFO(_securityInfoData.pServerInfo);
  367. freeCOAUTHIDENTITY(_securityInfoData.pAuthIdentityInfo);
  368. }
  369. }
  370. // Methods from IUnknown
  371. STDMETHOD (QueryInterface) ( REFIID riid, LPVOID* ppvObj);
  372. STDMETHOD_(ULONG,AddRef) ( void );
  373. STDMETHOD_(ULONG,Release) ( void );
  374. // IActivationSecurityInfo Methods
  375. STDMETHOD(SetAuthnFlags)(IN DWORD dwAuthnFlags)
  376. {
  377. _securityInfoData.dwAuthnFlags = dwAuthnFlags;
  378. return S_OK;
  379. }
  380. STDMETHOD(GetAuthnFlags)(OUT DWORD *pdwAuthnFlags)
  381. {
  382. *pdwAuthnFlags = _securityInfoData.dwAuthnFlags;
  383. return S_OK;
  384. }
  385. STDMETHOD(SetAuthnSvc)(IN DWORD dwAuthnSvc)
  386. {
  387. return E_NOTIMPL;
  388. }
  389. STDMETHOD(GetAuthnSvc)(OUT DWORD *pdwAuthnSvc)
  390. {
  391. *pdwAuthnSvc =
  392. _securityInfoData.pServerInfo->pAuthInfo->dwAuthnSvc;
  393. return S_OK;
  394. }
  395. STDMETHOD(SetAuthzSvc)(IN DWORD dwAuthzSvc)
  396. {
  397. return E_NOTIMPL;
  398. }
  399. STDMETHOD(GetAuthzSvc)(OUT DWORD *pdwAuthzSvc)
  400. {
  401. *pdwAuthzSvc =
  402. _securityInfoData.pServerInfo->pAuthInfo->dwAuthzSvc;
  403. return S_OK;
  404. }
  405. STDMETHOD(SetAuthnLevel)(IN DWORD dwAuthnLevel)
  406. {
  407. return E_NOTIMPL;
  408. }
  409. STDMETHOD(GetAuthnLevel)(OUT DWORD *pdwAuthnLevel)
  410. {
  411. *pdwAuthnLevel =
  412. _securityInfoData.pServerInfo->pAuthInfo->dwAuthnLevel;
  413. return S_OK;
  414. }
  415. STDMETHOD(SetImpLevel)(IN DWORD dwImpLevel)
  416. {
  417. return E_NOTIMPL;
  418. }
  419. STDMETHOD(GetImpLevel)(OUT DWORD *pdwImpLevel)
  420. {
  421. *pdwImpLevel =
  422. _securityInfoData.pServerInfo->pAuthInfo->dwImpersonationLevel;
  423. return S_OK;
  424. }
  425. STDMETHOD(SetCapabilities)(IN DWORD dwCapabilities)
  426. {
  427. return E_NOTIMPL;
  428. }
  429. STDMETHOD(GetCapabilities)(OUT DWORD *pdwCapabilities)
  430. {
  431. *pdwCapabilities =
  432. _securityInfoData.pServerInfo->pAuthInfo->dwCapabilities;
  433. return S_OK;
  434. }
  435. STDMETHOD(SetAuthIdentity)(COAUTHIDENTITY *pAuthIdentityData)
  436. {
  437. _securityInfoData.pAuthIdentityInfo = pAuthIdentityData;
  438. return S_OK;
  439. }
  440. STDMETHOD(GetAuthIdentity)(OUT COAUTHIDENTITY **ppAuthIdentityData)
  441. {
  442. *ppAuthIdentityData = _securityInfoData.pAuthIdentityInfo;
  443. return S_OK;
  444. }
  445. STDMETHOD(SetServerPrincipalName)(LPWSTR pwszServerPrincName)
  446. {
  447. return E_NOTIMPL;
  448. }
  449. STDMETHOD(GetServerPrincipalName)(OUT LPWSTR *ppwszServerPrincName)
  450. {
  451. *ppwszServerPrincName =
  452. _securityInfoData.pServerInfo->pAuthInfo->pwszServerPrincName;
  453. return S_OK;
  454. }
  455. //ILegacyInfo Methods
  456. STDMETHOD(SetCOSERVERINFO)(IN COSERVERINFO *pServerInfo)
  457. {
  458. _securityInfoData.pServerInfo = pServerInfo;
  459. if ((pServerInfo) && (pServerInfo->pwszName))
  460. {
  461. IServerLocationInfo *iloc;
  462. QueryInterface(IID_IServerLocationInfo, (void**) &iloc);
  463. iloc->SetRemoteServerName(pServerInfo->pwszName);
  464. iloc->Release();
  465. }
  466. return S_OK;
  467. }
  468. STDMETHOD(GetCOSERVERINFO)(OUT COSERVERINFO **ppServerInfo)
  469. {
  470. *ppServerInfo = _securityInfoData.pServerInfo;
  471. return S_OK;
  472. }
  473. STDMETHOD(SetCOAUTHINFO)(IN COAUTHINFO *pAuthInfo)
  474. {
  475. _securityInfoData.pServerInfo->pAuthInfo = pAuthInfo;
  476. return S_OK;
  477. }
  478. //Methods from IActivationPropertySet
  479. STDMETHOD(Reset)()
  480. {
  481. if (_unSerialized)
  482. {
  483. freeCOSERVERINFO(_securityInfoData.pServerInfo);
  484. freeCOAUTHIDENTITY(_securityInfoData.pAuthIdentityInfo);
  485. _securityInfoData.pServerInfo = 0;
  486. _securityInfoData.pAuthIdentityInfo = 0;
  487. }
  488. _unSerialized = FALSE;
  489. return S_OK;
  490. }
  491. // ISerializable Methods
  492. STDMETHOD(Serialize)(IN void *pSer);
  493. STDMETHOD(UnSerialize)(IN void *pSer);
  494. STDMETHOD(GetSize)(IN void *pSer, OUT DWORD *pdwSize);
  495. STDMETHOD(GetCLSID)(OUT CLSID *pclsid);
  496. STDMETHOD(UnSerializeCallBack)(REFCLSID clsid, ISerializable **ppSer=0)
  497. { return E_NOTIMPL;}
  498. STDMETHOD (SerializableQueryInterface) ( REFIID riid, LPVOID* ppvObj);
  499. private:
  500. SecurityInfoData _securityInfoData;
  501. };
  502. class ScmRequestInfo : public IScmRequestInfo, public SerializableProperty
  503. {
  504. public:
  505. ScmRequestInfo()
  506. {
  507. ZeroMemory(&_scmRequestInfoData, sizeof(ScmRequestInfoData));
  508. }
  509. inline void freeScmInfo(PRIV_SCM_INFO *pScmInfo)
  510. {
  511. if (_unSerialized && pScmInfo)
  512. {
  513. ActMemFree(pScmInfo->pwszWinstaDesktop);
  514. ActMemFree(pScmInfo->pEnvBlock);
  515. ActMemFree(pScmInfo);
  516. }
  517. }
  518. inline void freeRemoteRequest(REMOTE_REQUEST_SCM_INFO *remoteRequest)
  519. {
  520. if (remoteRequest)
  521. {
  522. ActMemFree(remoteRequest->pRequestedProtseqs);
  523. ActMemFree(remoteRequest);
  524. }
  525. }
  526. virtual ~ScmRequestInfo()
  527. {
  528. freeScmInfo((PRIV_SCM_INFO *)_scmRequestInfoData.pScmInfo);
  529. freeRemoteRequest((REMOTE_REQUEST_SCM_INFO *)_scmRequestInfoData.remoteRequest);
  530. }
  531. // Methods from IUnknown
  532. STDMETHOD (QueryInterface) ( REFIID riid, LPVOID* ppvObj);
  533. STDMETHOD_(ULONG,AddRef) ( void );
  534. STDMETHOD_(ULONG,Release) ( void );
  535. // Methods from IScmRequestInfo
  536. STDMETHOD(SetScmInfo)(IN PRIV_SCM_INFO *pScmInfo)
  537. {
  538. freeScmInfo((PRIV_SCM_INFO *)_scmRequestInfoData.pScmInfo);
  539. _scmRequestInfoData.pScmInfo = (CustomPrivScmInfo*)pScmInfo;
  540. freeRemoteRequest((REMOTE_REQUEST_SCM_INFO *)_scmRequestInfoData.remoteRequest);
  541. _scmRequestInfoData.remoteRequest = NULL;
  542. return S_OK;
  543. }
  544. STDMETHOD(GetScmInfo)(OUT PRIV_SCM_INFO **ppScmInfo)
  545. {
  546. *ppScmInfo = (PRIV_SCM_INFO*)_scmRequestInfoData.pScmInfo;
  547. return S_OK;
  548. }
  549. STDMETHOD(SetRemoteRequestInfo)(IN REMOTE_REQUEST_SCM_INFO *pRemoteReq)
  550. {
  551. freeRemoteRequest((REMOTE_REQUEST_SCM_INFO *)_scmRequestInfoData.remoteRequest);
  552. _scmRequestInfoData.remoteRequest =
  553. (customREMOTE_REQUEST_SCM_INFO*) pRemoteReq;
  554. freeScmInfo((PRIV_SCM_INFO *)_scmRequestInfoData.pScmInfo);
  555. _scmRequestInfoData.pScmInfo = NULL;
  556. return S_OK;
  557. }
  558. STDMETHOD(GetRemoteRequestInfo)(OUT REMOTE_REQUEST_SCM_INFO **ppRemoteReq)
  559. {
  560. *ppRemoteReq = (REMOTE_REQUEST_SCM_INFO*)
  561. _scmRequestInfoData.remoteRequest;
  562. return S_OK;
  563. }
  564. STDMETHOD(Reset)()
  565. {
  566. _scmRequestInfoData.pScmInfo = 0;
  567. _scmRequestInfoData.remoteRequest = 0;
  568. _unSerialized = FALSE;
  569. return S_OK;
  570. }
  571. // ISerializable Methods
  572. STDMETHOD(Serialize)(IN void *pSer);
  573. STDMETHOD(UnSerialize)(IN void *pSer);
  574. STDMETHOD(GetSize)(IN void *pSer, OUT DWORD *pdwSize);
  575. STDMETHOD(GetCLSID)(OUT CLSID *pclsid);
  576. STDMETHOD(UnSerializeCallBack)(REFCLSID clsid, ISerializable **ppSer=0)
  577. { return E_NOTIMPL;}
  578. STDMETHOD (SerializableQueryInterface) ( REFIID riid, LPVOID* ppvObj);
  579. private:
  580. ScmRequestInfoData _scmRequestInfoData;
  581. };
  582. class ContextInfo :
  583. public IPrivActivationContextInfo,
  584. public SerializableProperty,
  585. public IOverrideTargetContext
  586. {
  587. public:
  588. ContextInfo()
  589. {
  590. _pClientCtx = 0;
  591. _pPrototypeCtx = 0;
  592. ZeroMemory(&_contextInfoData, sizeof(ActivationContextInfoData));
  593. _contextInfoData.clientOK = TRUE;
  594. _toReleaseIFD = TRUE;
  595. _ctxOverride = GUID_NULL;
  596. }
  597. virtual ~ContextInfo()
  598. {
  599. if (_pClientCtx)
  600. _pClientCtx->InternalRelease();
  601. if (_pPrototypeCtx)
  602. _pPrototypeCtx->InternalRelease();
  603. if (_contextInfoData.pIFDClientCtx)
  604. {
  605. if (_toReleaseIFD)
  606. {
  607. InitMarshalling();
  608. if (pfnCoReleaseMarshalData)
  609. {
  610. ActivationStream stream((InterfaceData*)_contextInfoData.pIFDClientCtx);
  611. pfnCoReleaseMarshalData(&stream);
  612. }
  613. }
  614. ActMemFree(_contextInfoData.pIFDClientCtx);
  615. }
  616. if (_contextInfoData.pIFDPrototypeCtx)
  617. {
  618. if (_toReleaseIFD)
  619. {
  620. InitMarshalling();
  621. if (pfnCoReleaseMarshalData)
  622. {
  623. ActivationStream stream((InterfaceData*)_contextInfoData.pIFDPrototypeCtx);
  624. pfnCoReleaseMarshalData(&stream);
  625. }
  626. }
  627. ActMemFree(_contextInfoData.pIFDPrototypeCtx);
  628. }
  629. }
  630. // Methods from IUnknown
  631. STDMETHOD (QueryInterface) ( REFIID riid, LPVOID* ppvObj);
  632. STDMETHOD_(ULONG,AddRef) ( void );
  633. STDMETHOD_(ULONG,Release) ( void );
  634. // Methods from IActivationContextInfo
  635. STDMETHOD(SetClientContext)(IN IContext *pctx)
  636. {
  637. if (_unSerialized) //Can only set on IInitActPropsIn
  638. return E_NOTIMPL;
  639. // We always want to set the internal context.
  640. _pClientCtx = NULL;
  641. if (pctx)
  642. {
  643. // We want an internal reference to the supplied context, not a
  644. // user reference. Hence, we QI for the StdObjectContext and
  645. // take an internal reference.
  646. HRESULT hr = pctx->QueryInterface(IID_IStdObjectContext, (void**)&_pClientCtx);
  647. Win4Assert(SUCCEEDED(hr));
  648. if (SUCCEEDED(hr))
  649. {
  650. _pClientCtx->InternalAddRef();
  651. _pClientCtx->Release();
  652. }
  653. return hr;
  654. }
  655. return S_OK;
  656. }
  657. STDMETHOD(GetClientContext)(OUT IContext **ppCtx);
  658. HRESULT GetInternalClientContext(OUT CObjectContext **ppCtx);
  659. STDMETHOD(SetPrototypeContext)(IN IContext *pctx)
  660. {
  661. if (_unSerialized) //Can only set on IInitActPropsIn
  662. return E_NOTIMPL;
  663. // We always want to set the internal context.
  664. _pPrototypeCtx = NULL;
  665. if (pctx)
  666. {
  667. // We want an internal reference to the supplied context, not a
  668. // user reference. Hence, we QI for the StdObjectContext and
  669. // take an internal reference.
  670. HRESULT hr = pctx->QueryInterface(IID_IStdObjectContext, (void**)&_pPrototypeCtx);
  671. Win4Assert(SUCCEEDED(hr));
  672. if (SUCCEEDED(hr))
  673. {
  674. _pPrototypeCtx->InternalAddRef();
  675. _pPrototypeCtx->Release();
  676. }
  677. return hr;
  678. }
  679. return S_OK;
  680. }
  681. STDMETHOD(GetPrototypeContext)(OUT IContext **ppCtx);
  682. HRESULT GetInternalPrototypeContext(OUT CObjectContext **ppCtx);
  683. STDMETHOD(PrototypeExists)(BOOL *pBExists)
  684. {
  685. if ((_pPrototypeCtx!=NULL) ||
  686. ((_unSerialized) &&
  687. (_contextInfoData.pIFDPrototypeCtx != NULL)))
  688. *pBExists = TRUE;
  689. else
  690. *pBExists = FALSE;
  691. return S_OK;
  692. }
  693. STDMETHOD(IsClientContextOK)(OUT BOOL *pBOk)
  694. {
  695. *pBOk = _contextInfoData.clientOK;
  696. return S_OK;
  697. }
  698. STDMETHOD(SetClientContextNotOK)()
  699. {
  700. _contextInfoData.clientOK = FALSE;
  701. return S_OK;
  702. }
  703. // IOverrideTargetContext Methods
  704. STDMETHOD(OverrideTargetContext)(REFGUID guidTargetCtxtId)
  705. {
  706. _ctxOverride = guidTargetCtxtId;
  707. return S_OK;
  708. }
  709. // ISerializable Methods
  710. STDMETHOD(Serialize)(IN void *pSer);
  711. STDMETHOD(UnSerialize)(IN void *pSer);
  712. STDMETHOD(GetSize)(IN void *pSer, OUT DWORD *pdwSize);
  713. STDMETHOD(GetCLSID)(OUT CLSID *pclsid);
  714. STDMETHOD(UnSerializeCallBack)(REFCLSID clsid, ISerializable **ppSer=0)
  715. { return E_NOTIMPL;}
  716. STDMETHOD (SerializableQueryInterface) ( REFIID riid, LPVOID* ppvObj);
  717. public:
  718. ActivationContextInfoData _contextInfoData;
  719. GUID _ctxOverride;
  720. private:
  721. CObjectContext *_pClientCtx;
  722. CObjectContext *_pPrototypeCtx;
  723. BOOL _toReleaseIFD;
  724. };
  725. class ScmReplyInfo : public IScmReplyInfo, public SerializableProperty
  726. {
  727. public:
  728. ScmReplyInfo()
  729. {
  730. ZeroMemory(&_scmReplyInfoData, sizeof(_scmReplyInfoData));
  731. }
  732. inline void freeResolverInfo()
  733. {
  734. if (_scmReplyInfoData.pResolverInfo)
  735. {
  736. ActMemFree(_scmReplyInfoData.pResolverInfo->pwszDllServer);
  737. ActMemFree(_scmReplyInfoData.pResolverInfo->pServerORBindings);
  738. ActMemFree(_scmReplyInfoData.pResolverInfo->OxidInfo.psa);
  739. ActMemFree(_scmReplyInfoData.pResolverInfo);
  740. }
  741. }
  742. inline void freeRemoteReplyInfo()
  743. {
  744. if (_scmReplyInfoData.remoteReply)
  745. {
  746. ActMemFree(_scmReplyInfoData.remoteReply->pdsaOxidBindings);
  747. ActMemFree(_scmReplyInfoData.remoteReply);
  748. }
  749. }
  750. virtual ~ScmReplyInfo()
  751. {
  752. freeResolverInfo();
  753. freeRemoteReplyInfo();
  754. }
  755. // Methods from IUnknown
  756. STDMETHOD (QueryInterface) ( REFIID riid, LPVOID* ppvObj);
  757. STDMETHOD_(ULONG,AddRef) ( void );
  758. STDMETHOD_(ULONG,Release) ( void );
  759. // Methods from IScmReplyInfo
  760. STDMETHOD(SetRemoteReplyInfo)(IN REMOTE_REPLY_SCM_INFO *pRemoteReq)
  761. {
  762. _scmReplyInfoData.remoteReply =
  763. (customREMOTE_REPLY_SCM_INFO*) pRemoteReq;
  764. freeResolverInfo();
  765. _scmReplyInfoData.pResolverInfo = NULL;
  766. return S_OK;
  767. }
  768. STDMETHOD(GetRemoteReplyInfo)(OUT REMOTE_REPLY_SCM_INFO **ppRemoteReq)
  769. {
  770. *ppRemoteReq = (REMOTE_REPLY_SCM_INFO*)
  771. _scmReplyInfoData.remoteReply;
  772. return S_OK;
  773. }
  774. STDMETHOD(SetResolverInfo)(IN PRIV_RESOLVER_INFO *pResolverInfo)
  775. {
  776. _scmReplyInfoData.pResolverInfo = (CustomPrivResolverInfo*)pResolverInfo;
  777. freeRemoteReplyInfo();
  778. _scmReplyInfoData.remoteReply = NULL;
  779. return S_OK;
  780. }
  781. STDMETHOD(GetResolverInfo)(OUT PRIV_RESOLVER_INFO **ppResolverInfo)
  782. {
  783. *ppResolverInfo = (PRIV_RESOLVER_INFO*)_scmReplyInfoData.pResolverInfo;
  784. return S_OK;
  785. }
  786. //Methods from IActivationPropertySet
  787. STDMETHOD(Reset)()
  788. {
  789. _scmReplyInfoData.remoteReply = 0;
  790. _scmReplyInfoData.pResolverInfo = 0;
  791. _unSerialized = FALSE;
  792. return S_OK;
  793. }
  794. // ISerializable Methods
  795. STDMETHOD(Serialize)(IN void *pSer);
  796. STDMETHOD(UnSerialize)(IN void *pSer);
  797. STDMETHOD(GetSize)(IN void *pSer, OUT DWORD *pdwSize);
  798. STDMETHOD(GetCLSID)(OUT CLSID *pclsid);
  799. STDMETHOD(UnSerializeCallBack)(REFCLSID clsid, ISerializable **ppSer=0)
  800. { return E_NOTIMPL;}
  801. STDMETHOD (SerializableQueryInterface) ( REFIID riid, LPVOID* ppvObj);
  802. private:
  803. ScmReplyInfoData _scmReplyInfoData;
  804. };
  805. class InstanceInfo : public IInstanceInfo, public SerializableProperty
  806. {
  807. public:
  808. InstanceInfo()
  809. {
  810. ZeroMemory(&_instanceInfoData, sizeof(InstanceInfoData));
  811. _pstg = 0;
  812. }
  813. virtual ~InstanceInfo()
  814. {
  815. if (_pstg)
  816. _pstg->Release();
  817. if (_instanceInfoData.fileName)
  818. ActMemFree(_instanceInfoData.fileName);
  819. //NOTE: need to copy in SCM to always free here
  820. if (_instanceInfoData.ifdROT)
  821. ActMemFree(_instanceInfoData.ifdROT);
  822. if (_instanceInfoData.ifdStg)
  823. ActMemFree(_instanceInfoData.ifdStg);
  824. }
  825. // Methods from IUnknown
  826. STDMETHOD (QueryInterface) ( REFIID riid, LPVOID* ppvObj);
  827. STDMETHOD_(ULONG,AddRef) ( void );
  828. STDMETHOD_(ULONG,Release) ( void );
  829. // Methods from IInstanceInfo
  830. STDMETHOD(SetStorage)(IN IStorage *pstg);
  831. STDMETHOD(GetStorage)(OUT IStorage **ppstg);
  832. STDMETHOD(GetStorageIFD)(MInterfacePointer **pStgIfd)
  833. {
  834. if (!_unSerialized)
  835. return E_FAIL;
  836. *pStgIfd = _instanceInfoData.ifdStg;
  837. return S_OK;
  838. }
  839. STDMETHOD(SetStorageIFD)(MInterfacePointer *pStgIfd)
  840. {
  841. Win4Assert(_instanceInfoData.ifdStg == NULL);
  842. _instanceInfoData.ifdStg = pStgIfd;
  843. return S_OK;
  844. }
  845. STDMETHOD(SetIfdROT) (IN MInterfacePointer *pIFD)
  846. {
  847. _instanceInfoData.ifdROT = pIFD;
  848. return S_OK;
  849. }
  850. STDMETHOD(GetIfdROT) (OUT MInterfacePointer **ppIFD)
  851. {
  852. *ppIFD = _instanceInfoData.ifdROT;
  853. return S_OK;
  854. }
  855. STDMETHOD(SetFile)(IN WCHAR *pfile, DWORD mode)
  856. {
  857. ActMemFree(_instanceInfoData.fileName);
  858. _instanceInfoData.fileName = makeWStringCopy(pfile);
  859. if (_instanceInfoData.fileName==NULL)
  860. return E_OUTOFMEMORY;
  861. _instanceInfoData.mode = mode;
  862. return S_OK;
  863. }
  864. STDMETHOD(GetFile)(OUT WCHAR **ppfile, DWORD *pmode)
  865. {
  866. *ppfile = _instanceInfoData.fileName;
  867. *pmode = _instanceInfoData.mode;
  868. return S_OK;
  869. }
  870. // ISerializable Methods
  871. STDMETHOD(Serialize)(IN void *pSer);
  872. STDMETHOD(UnSerialize)(IN void *pSer);
  873. STDMETHOD(GetSize)(IN void *pSer, OUT DWORD *pdwSize);
  874. STDMETHOD(GetCLSID)(OUT CLSID *pclsid);
  875. STDMETHOD(UnSerializeCallBack)(REFCLSID clsid, ISerializable **ppSer=0)
  876. { return E_NOTIMPL;}
  877. STDMETHOD (SerializableQueryInterface) ( REFIID riid, LPVOID* ppvObj);
  878. inline void CleanupLocalState(void)
  879. {
  880. if (_pstg)
  881. {
  882. _pstg->Release();
  883. _pstg = NULL;
  884. }
  885. }
  886. private:
  887. InstanceInfoData _instanceInfoData;
  888. IStorage *_pstg;
  889. };
  890. class OpaqueDataInfo : public IOpaqueDataInfo, public SerializableProperty
  891. {
  892. public:
  893. inline HRESULT CopyOpaqueData(OpaqueData *pDst,
  894. OpaqueData *pSrc,
  895. DWORD dwLen,
  896. BOOL bDeep)
  897. {
  898. HRESULT hr = S_OK;
  899. for (DWORD i=0; i<dwLen; i++)
  900. {
  901. pDst->guid = pSrc->guid;
  902. pDst->dataLength = pSrc->dataLength;
  903. pDst->reserved1 = pSrc->reserved1;
  904. pDst->reserved2 = pSrc->reserved2;
  905. if (bDeep)
  906. {
  907. pDst->data = (BYTE*)
  908. ActMemAlloc((pSrc->dataLength+7)&~7);
  909. if (pDst->data == NULL)
  910. return E_OUTOFMEMORY;
  911. memcpy(pDst->data,
  912. pSrc->data,
  913. pSrc->dataLength);
  914. }
  915. else
  916. pDst->data = pSrc->data;
  917. pDst++;
  918. pSrc++;
  919. }
  920. return hr;
  921. }
  922. OpaqueDataInfo()
  923. {
  924. _cOpaqueData = 0;
  925. _dwCollSize = 0;
  926. _pOpaqueData = NULL;
  927. }
  928. ~OpaqueDataInfo()
  929. {
  930. for (DWORD i=0; i<_cOpaqueData;i++)
  931. ActMemFree(_pOpaqueData[i].data);
  932. ActMemFree(_pOpaqueData);
  933. }
  934. // Methods from IUnknown
  935. STDMETHOD (QueryInterface) ( REFIID riid, LPVOID* ppvObj);
  936. STDMETHOD_(ULONG,AddRef) ( void );
  937. STDMETHOD_(ULONG,Release) ( void );
  938. // Methods from IOpaqueDataInfo
  939. STDMETHOD (AddOpaqueData) (OpaqueData *pData);
  940. STDMETHOD (GetOpaqueData) (REFGUID guid,
  941. OpaqueData **pData);
  942. STDMETHOD (DeleteOpaqueData) (REFGUID guid);
  943. STDMETHOD (GetOpaqueDataCount) (ULONG *pulCount);
  944. STDMETHOD (GetAllOpaqueData) (OpaqueData **prgData);
  945. // ISerializable Methods
  946. STDMETHOD(Serialize)(IN void *pSer);
  947. STDMETHOD(UnSerialize)(IN void *pSer);
  948. STDMETHOD(GetSize)(IN void *pSer, OUT DWORD *pdwSize);
  949. STDMETHOD(GetCLSID)(OUT CLSID *pclsid);
  950. STDMETHOD(UnSerializeCallBack)(REFCLSID clsid, ISerializable **ppSer=0)
  951. { return E_NOTIMPL;}
  952. STDMETHOD (SerializableQueryInterface) ( REFIID riid, LPVOID* ppvObj);
  953. STDMETHOD (SetParent) ( ISerializableParent *pParent);
  954. private:
  955. DWORD _cOpaqueData;
  956. DWORD _dwCollSize;
  957. OpaqueData *_pOpaqueData;
  958. void *_pAct;
  959. };
  960. class SpecialProperties : public ISpecialSystemProperties,
  961. public SerializableProperty
  962. {
  963. public:
  964. SpecialProperties()
  965. {
  966. ZeroMemory(&_data, sizeof(SpecialPropertiesData));
  967. }
  968. ~SpecialProperties()
  969. {
  970. }
  971. SpecialProperties & operator =(SpecialProperties &sp)
  972. {
  973. if(this == &sp) return *this;
  974. _data = sp._data;
  975. return *this;
  976. }
  977. // Methods from ISpecialSystemProperties
  978. STDMETHOD (SetSessionId) (ULONG dwSessionId, BOOL bUseConsole, BOOL fRemoteThisSessionId)
  979. {
  980. if (bUseConsole)
  981. {
  982. _data.dwFlags |= SPD_FLAG_USE_CONSOLE_SESSION;
  983. _data.dwSessionId = 0;
  984. }
  985. else
  986. {
  987. _data.dwFlags &= ~SPD_FLAG_USE_CONSOLE_SESSION;
  988. _data.dwSessionId = dwSessionId;
  989. }
  990. _data.fRemoteThisSessionId = fRemoteThisSessionId;
  991. return S_OK;
  992. }
  993. STDMETHOD (GetSessionId) (ULONG *pdwSessionId, BOOL* pbUseConsole)
  994. {
  995. if (_data.dwFlags & SPD_FLAG_USE_CONSOLE_SESSION)
  996. {
  997. *pbUseConsole = TRUE;
  998. *pdwSessionId = 0;
  999. }
  1000. else
  1001. {
  1002. *pbUseConsole = FALSE;
  1003. *pdwSessionId = _data.dwSessionId;
  1004. }
  1005. return S_OK;
  1006. }
  1007. STDMETHOD (GetSessionId2) (ULONG *pdwSessionId, BOOL* pbUseConsole, BOOL* pfRemoteThisSessionId)
  1008. {
  1009. HRESULT hr = GetSessionId(pdwSessionId, pbUseConsole);
  1010. if (SUCCEEDED(hr))
  1011. {
  1012. *pfRemoteThisSessionId = _data.fRemoteThisSessionId;
  1013. }
  1014. return hr;
  1015. }
  1016. STDMETHOD (SetClientImpersonating) (BOOL fClientImpersonating)
  1017. {
  1018. _data.fClientImpersonating = fClientImpersonating;
  1019. return S_OK;
  1020. }
  1021. STDMETHOD (GetClientImpersonating) (BOOL* pfClientImpersonating)
  1022. {
  1023. *pfClientImpersonating = _data.fClientImpersonating;
  1024. return S_OK;
  1025. }
  1026. STDMETHOD (SetPartitionId) (REFGUID guidPartition)
  1027. {
  1028. _data.fPartitionIDPresent = TRUE;
  1029. memcpy (&_data.guidPartition,&guidPartition, sizeof(GUID));
  1030. return S_OK;
  1031. }
  1032. STDMETHOD (GetPartitionId) (GUID* pguidPartition)
  1033. {
  1034. Win4Assert(pguidPartition != NULL);
  1035. if (_data.fPartitionIDPresent)
  1036. {
  1037. memcpy (pguidPartition,&_data.guidPartition,sizeof(GUID));
  1038. return S_OK;
  1039. }
  1040. return E_FAIL;
  1041. }
  1042. STDMETHOD (SetProcessRequestType) (DWORD dwPRT)
  1043. {
  1044. _data.dwPRTFlags = dwPRT;
  1045. return S_OK;
  1046. }
  1047. STDMETHOD (GetProcessRequestType) (DWORD* pdwPRT)
  1048. {
  1049. *pdwPRT = _data.dwPRTFlags;
  1050. return S_OK;
  1051. }
  1052. STDMETHOD (SetOrigClsctx) (DWORD dwClsCtx)
  1053. {
  1054. _data.dwOrigClsctx = dwClsCtx;
  1055. return S_OK;
  1056. }
  1057. STDMETHOD (GetOrigClsctx) (DWORD *pdwClsCtx)
  1058. {
  1059. if(!pdwClsCtx) return E_POINTER;
  1060. *pdwClsCtx = _data.dwOrigClsctx;
  1061. return S_OK;
  1062. }
  1063. // Methods from IUnknown
  1064. STDMETHOD (QueryInterface) ( REFIID riid, LPVOID* ppvObj);
  1065. STDMETHOD_(ULONG,AddRef) ( void );
  1066. STDMETHOD_(ULONG,Release) ( void );
  1067. // ISerializable Methods
  1068. STDMETHOD(Serialize)(IN void *pSer);
  1069. STDMETHOD(UnSerialize)(IN void *pSer);
  1070. STDMETHOD(GetSize)(IN void *pSer, OUT DWORD *pdwSize);
  1071. STDMETHOD(GetCLSID)(OUT CLSID *pclsid);
  1072. STDMETHOD(UnSerializeCallBack)(REFCLSID clsid, ISerializable **ppSer=0)
  1073. { return E_NOTIMPL;}
  1074. STDMETHOD (SerializableQueryInterface) ( REFIID riid, LPVOID* ppvObj);
  1075. private:
  1076. SpecialPropertiesData _data;
  1077. };
  1078. #endif // __PROPIFS_HXX__