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.

244 lines
7.0 KiB

  1. //+------------------------------------------------------------------
  2. //
  3. // Copyright (C) 1991-1997 Microsoft Corporation.
  4. //
  5. // File: defprop.cxx
  6. //
  7. // Contents: Deferred property retriever for filesystems
  8. //
  9. // Classes: CCiCDeferredPropRetriever
  10. //
  11. // History: 12-Jan-97 SitaramR Created
  12. //
  13. //-------------------------------------------------------------------
  14. #include <pch.cxx>
  15. #pragma hdrstop
  16. #include <fsciexps.hxx>
  17. #include <defprop.hxx>
  18. #include <seccache.hxx>
  19. #include <oleprop.hxx>
  20. //+---------------------------------------------------------------------------
  21. //
  22. // Member: CCiCDeferredPropRetriever::CCiCDeferredPropRetriever
  23. //
  24. // Synopsis: Constructor
  25. //
  26. // Arguments: [cat] -- Catalog
  27. // [secCache] -- Cache of AccessCheck() results
  28. // [fUsePathAlias] -- TRUE if client is going through rdr/svr
  29. //
  30. // History: 12-Jan-97 SitaramR Created
  31. //
  32. //----------------------------------------------------------------------------
  33. CCiCDeferredPropRetriever::CCiCDeferredPropRetriever( PCatalog & cat,
  34. CSecurityCache & secCache,
  35. BOOL fUsePathAlias )
  36. : _cat( cat ),
  37. _secCache( secCache ),
  38. _remoteAccess( cat.GetImpersonationTokenCache() ),
  39. _fUsePathAlias( fUsePathAlias ),
  40. _cRefs( 1 )
  41. {
  42. }
  43. //+---------------------------------------------------------------------------
  44. //
  45. // Member: CCiCDeferredPropRetriever::~CCiCDeferredPropRetriever
  46. //
  47. // Synopsis: Destructor
  48. //
  49. // History: 12-Jan-97 SitaramR Created
  50. //
  51. //----------------------------------------------------------------------------
  52. CCiCDeferredPropRetriever::~CCiCDeferredPropRetriever()
  53. {
  54. }
  55. //+---------------------------------------------------------------------------
  56. //
  57. // Member: CCiCDeferredPropRetriever::RetrieveDeferredValueByPropSpec
  58. //
  59. // Effects: Fetch value from the property cache and/or from docfile
  60. //
  61. // Arguments: [wid] -- Workid
  62. // [pPropSpec] -- Property to fetch
  63. // [pPropVar] -- Value returned here
  64. //
  65. // Notes: It's the responsibility of the caller to free the variant
  66. // by calling VariantClear on pVar
  67. //
  68. // History: 12-Jan-97 SitaramR Created
  69. //
  70. //----------------------------------------------------------------------------
  71. SCODE STDMETHODCALLTYPE CCiCDeferredPropRetriever::RetrieveDeferredValueByPropSpec(
  72. WORKID wid,
  73. const FULLPROPSPEC * pPropSpec,
  74. PROPVARIANT * pVar )
  75. {
  76. //
  77. // Set up the failure case
  78. //
  79. pVar->vt = VT_EMPTY;
  80. if ( widInvalid == wid )
  81. return CI_E_WORKID_NOTVALID;
  82. SCODE sc = S_OK;
  83. TRY
  84. {
  85. //
  86. // First check the security access
  87. //
  88. // 8-byte align this memory
  89. XArray<BYTE> xBuf( sizeof_CCompositePropRecord );
  90. XCompositeRecord rec( _cat, wid, xBuf.Get() );
  91. SDID sdid = _cat.FetchSDID( rec.Get(), wid );
  92. BOOL fGranted = _secCache.IsGranted( sdid, FILE_READ_DATA );
  93. if ( fGranted )
  94. {
  95. CFullPropSpec *pPS = (CFullPropSpec *) pPropSpec;
  96. PROPID pid = _cat.PropertyToPropId( *pPS, TRUE );
  97. if ( ! _cat.FetchValue( rec.Get(), pid, *pVar ) )
  98. {
  99. //
  100. // Try fetching the value from the docfile
  101. //
  102. rec.Free();
  103. CFunnyPath funnyPath;
  104. SIZE_T cwc = _cat.WorkIdToPath( wid, funnyPath );
  105. if ( cwc > 0 )
  106. {
  107. XGrowable<WCHAR> xVPath;
  108. cwc = _cat.WorkIdToVirtualPath( wid, 0, xVPath );
  109. if ( CImpersonateRemoteAccess::IsNetPath( funnyPath.GetActualPath() ) )
  110. _remoteAccess.ImpersonateIf( funnyPath.GetActualPath(),
  111. cwc != 0 ? xVPath.Get() : 0 );
  112. else if ( _remoteAccess.IsImpersonated() )
  113. _remoteAccess.Release();
  114. COLEPropManager propMgr;
  115. propMgr.Open( funnyPath );
  116. propMgr.ReadProperty( *pPS, *pVar );
  117. }
  118. }
  119. }
  120. else
  121. {
  122. vqDebugOut(( DEB_ERROR,
  123. "CCiCDeferredPropRetriever::RetrieveDeferredValueByPropSpec, security check failed\n" ));
  124. }
  125. }
  126. CATCH( CException, e )
  127. {
  128. sc = e.GetErrorCode();
  129. vqDebugOut(( DEB_ERROR,
  130. "CCiCDeferredPropRetriever::RetrieveDeferredValueByPropSpec - Exception caught 0x%x\n",
  131. sc ));
  132. }
  133. END_CATCH;
  134. return sc;
  135. } //RetrieveDeferredValueByPropSpec
  136. //+-------------------------------------------------------------------------
  137. //
  138. // Method: CCiCDeferredPropRetriever::AddRef
  139. //
  140. // Synopsis: Increments refcount
  141. //
  142. // History: 12-Jan-1997 SitaramR Created
  143. //
  144. //--------------------------------------------------------------------------
  145. ULONG STDMETHODCALLTYPE CCiCDeferredPropRetriever::AddRef()
  146. {
  147. return InterlockedIncrement( (long *) &_cRefs );
  148. }
  149. //+-------------------------------------------------------------------------
  150. //
  151. // Method: CCiCDeferredPropRetriever::Release
  152. //
  153. // Synopsis: Decrement refcount. Delete if necessary.
  154. //
  155. // History: 12-Jan-1997 SitaramR Created
  156. //
  157. //--------------------------------------------------------------------------
  158. ULONG STDMETHODCALLTYPE CCiCDeferredPropRetriever::Release()
  159. {
  160. Win4Assert( _cRefs > 0 );
  161. ULONG uTmp = InterlockedDecrement( (long *) &_cRefs );
  162. if ( 0 == uTmp )
  163. delete this;
  164. return uTmp;
  165. }
  166. //+-------------------------------------------------------------------------
  167. //
  168. // Method: CCiCDeferredPropRetriever::QueryInterface
  169. //
  170. // Synopsis: Rebind to other interface
  171. //
  172. // Arguments: [riid] -- IID of new interface
  173. // [ppvObject] -- New interface * returned here
  174. //
  175. // Returns: S_OK if bind succeeded, E_NOINTERFACE if bind failed
  176. //
  177. // History: 12-Jan-1997 SitaramR Created
  178. //
  179. //--------------------------------------------------------------------------
  180. SCODE STDMETHODCALLTYPE CCiCDeferredPropRetriever::QueryInterface(
  181. REFIID riid,
  182. void ** ppvObject)
  183. {
  184. IUnknown *pUnkTemp = 0;
  185. SCODE sc = S_OK;
  186. if ( IID_ICiCDeferredPropRetriever == riid )
  187. pUnkTemp = (IUnknown *)(ICiCDeferredPropRetriever *) this;
  188. else if ( IID_IUnknown == riid )
  189. pUnkTemp = (IUnknown *) this;
  190. else
  191. sc = E_NOINTERFACE;
  192. if( 0 != pUnkTemp )
  193. {
  194. *ppvObject = (void * )pUnkTemp;
  195. pUnkTemp->AddRef();
  196. }
  197. else
  198. {
  199. *ppvObject = 0;
  200. }
  201. return sc;
  202. } //QueryInterface