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.

593 lines
16 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1999.
  5. //
  6. // File: dlproxy.hxx
  7. //
  8. // Contents: Proxy class which is used by the downlevel Daemon process
  9. // to communicate with the CI process.
  10. //
  11. // History: 1-30-96 srikants Created
  12. //
  13. //----------------------------------------------------------------------------
  14. #pragma once
  15. #include <fdaemon.hxx>
  16. #include <namesem.hxx>
  17. #include <shrdnam.hxx>
  18. #include <pidmap.hxx>
  19. #define CI_NO_CATALOG_NAME L"[!none!]"
  20. //
  21. // Signatures for structures laid out in the shared memory buffer.
  22. //
  23. enum
  24. {
  25. eFilterSig1 = 0x11111111,
  26. eFilterSig2 = 0x22222222,
  27. eFilterSig3 = 0x33333333,
  28. eFilterSig4 = 0x44444444,
  29. eFilterSig5 = 0x55555555,
  30. eFilterSig6 = 0x66666666,
  31. eFilterSig7 = 0x77777777,
  32. eFilterSig8 = 0x88888888,
  33. eFilterSig9 = 0x99999999,
  34. eFilterSigA = 0xAAAAAAAA
  35. };
  36. const FILTER_DATA_READY_BUF_SIZE = CI_FILTER_BUFFER_SIZE_DEFAULT * 1024;
  37. // const MAX_DL_VAR_BUF_SIZE = 128*1024;
  38. //
  39. // Length of the variable length part in the data passed between the
  40. // DownLevel Daemon process and CI.
  41. // This is set to the same value as the size of the entrybuffer because
  42. // that is the biggest data passed between the two.
  43. //
  44. const MAX_DL_VAR_BUF_SIZE = FILTER_DATA_READY_BUF_SIZE;
  45. //+---------------------------------------------------------------------------
  46. //
  47. // Class: CFilterReadyLayout
  48. //
  49. // Purpose: Layout of the data for FilterReady() call
  50. //
  51. // History: 1-30-96 srikants Created
  52. //
  53. //----------------------------------------------------------------------------
  54. class CFilterReadyLayout
  55. {
  56. public:
  57. void Init( ULONG cbMax, ULONG cb, ULONG cMaxDocs )
  58. {
  59. _cbMax = cbMax - FIELD_OFFSET( CFilterReadyLayout, _abBuffer ) ;
  60. Win4Assert( cb <= _cbMax );
  61. if ( cb > _cbMax )
  62. {
  63. THROW( CException( STATUS_NO_MEMORY) );
  64. }
  65. _sig1 = eFilterSig1;
  66. _cb = cb;
  67. _cMaxDocs = cMaxDocs;
  68. _sig2 = eFilterSig2;
  69. }
  70. BOOL IsValid() const
  71. {
  72. return eFilterSig1 == _sig1 && eFilterSig2 == _sig2 &&
  73. _cb <= _cbMax;
  74. }
  75. ULONG GetCount() const { return _cb; }
  76. void SetCount( ULONG cb ) { _cb = cb; }
  77. ULONG GetMaxDocs() const { return _cMaxDocs; }
  78. BYTE const * GetBuffer() const { return (BYTE const *) _abBuffer; }
  79. BYTE * GetBuffer() { return (BYTE *) _abBuffer; }
  80. private:
  81. ULONG _sig1; // Signature
  82. ULONG _cbMax; // Maximum BYTES in _wcBuffer;
  83. ULONG _cb; // Number of bytes in the current buffer
  84. ULONG _cMaxDocs; // Maximum number of documents
  85. ULONG _sig2; // Signature
  86. LONGLONG _abBuffer[1]; // Place holder for the buffer
  87. };
  88. //+---------------------------------------------------------------------------
  89. //
  90. // Class: CFilterDataLayout
  91. //
  92. // Purpose: Layout of the data for FilterDataReady() call
  93. //
  94. // History: 1-30-96 srikants Created
  95. //
  96. //----------------------------------------------------------------------------
  97. class CFilterDataLayout
  98. {
  99. public:
  100. void Init( BYTE const * pEntryBuf, ULONG cb )
  101. {
  102. _sig3 = eFilterSig3;
  103. _cbMax = sizeof(_ab);
  104. _cb = cb;
  105. Win4Assert( _cb <= _cbMax );
  106. Win4Assert( pEntryBuf == GetBuffer() );
  107. }
  108. BOOL IsValid() const
  109. {
  110. return eFilterSig3 == _sig3 && _cb <= _cbMax;
  111. }
  112. ULONG GetSize() const { return _cb; }
  113. BYTE const * GetBuffer() const { return (BYTE *) _ab; }
  114. BYTE * GetBuffer() { return (BYTE *) _ab; }
  115. ULONG GetMaxSize() const { return sizeof(_ab); }
  116. private:
  117. ULONG _sig3; // Signature
  118. ULONG _cbMax; // Maximum number of bytes allowed
  119. ULONG _cb; // Number of valid bytes in the buffer
  120. //
  121. // Guarantee 8 byte alignment of data.
  122. //
  123. LONGLONG _ab[FILTER_DATA_READY_BUF_SIZE/sizeof(LONGLONG)];
  124. // Maximum size of the buffer for data
  125. };
  126. //+---------------------------------------------------------------------------
  127. //
  128. // Class: CFilterMoreDoneLayout
  129. //
  130. // Purpose: Layout for FilterMore() and FilterDone() calls.
  131. //
  132. // History: 1-30-96 srikants Created
  133. //
  134. //----------------------------------------------------------------------------
  135. class CFilterMoreDoneLayout
  136. {
  137. public:
  138. void Init( STATUS const * aStatus, ULONG cStatus )
  139. {
  140. _sig4 = eFilterSig4;
  141. Win4Assert( cStatus <= CI_MAX_DOCS_IN_WORDLIST );
  142. _cStatus = cStatus;
  143. RtlCopyMemory( _aStatus, aStatus, cStatus * sizeof(STATUS) );
  144. }
  145. BOOL IsValid() const
  146. {
  147. return eFilterSig4 == _sig4 && _cStatus <= CI_MAX_DOCS_IN_WORDLIST;
  148. }
  149. STATUS const * GetStatusArray() const { return _aStatus; }
  150. ULONG GetCount() const { return _cStatus; }
  151. private:
  152. ULONG _sig4; // Signature
  153. ULONG _cStatus; // Number of status elements valid
  154. STATUS _aStatus[CI_MAX_DOCS_IN_WORDLIST];
  155. // Array of statuses
  156. };
  157. //+---------------------------------------------------------------------------
  158. //
  159. // Class: CFilterStoreValueLayout
  160. //
  161. // Purpose: Layout for the data of FilterStoreValue() call
  162. //
  163. // History: 1-31-96 srikants Created
  164. //
  165. //----------------------------------------------------------------------------
  166. class CFilterStoreValueLayout
  167. {
  168. public:
  169. SCODE Init( ULONG cbMax, WORKID widFake,
  170. CFullPropSpec const & ps, CStorageVariant const & var );
  171. void Get( WORKID & widFake, CFullPropSpec & ps, CStorageVariant & var );
  172. BOOL IsValid() const
  173. {
  174. return eFilterSig5 == _sig5 && _cb <= _cbMax;
  175. }
  176. BYTE const * GetBuffer() const { return (BYTE *) _ab; }
  177. BYTE * GetBuffer() { return (BYTE *) _ab; }
  178. ULONG GetCount() const { return _cb; }
  179. WORKID GetWorkid() const { return _widFake; }
  180. void SetStatus( BOOL fSuccess ) { _fSuccess = fSuccess; }
  181. BOOL GetStatus() const { return _fSuccess; }
  182. private:
  183. ULONG _sig5;
  184. WORKID _widFake;
  185. ULONG _cbMax; // Maximum number of bytes allowed in _ab
  186. ULONG _cb;
  187. BOOL _fSuccess; // Success code of the operation
  188. //
  189. // We will serialize the FULLPROPSPEC first and then the VARIANT
  190. //
  191. // FORCE a 8byte alignment.
  192. //
  193. LONGLONG _ab[1]; // place holder for variable data
  194. };
  195. //+---------------------------------------------------------------------------
  196. //
  197. // Class: CFilterStoreSecurityLayout
  198. //
  199. // Purpose: Layout for the data of FilterStoreSecurity() call
  200. //
  201. // History: 06 Fen 96 AlanW Created
  202. //
  203. //----------------------------------------------------------------------------
  204. class CFilterStoreSecurityLayout
  205. {
  206. public:
  207. void Init( ULONG cbMax, WORKID widFake, PSECURITY_DESCRIPTOR pSD, ULONG cbSD );
  208. BOOL IsValid() const
  209. {
  210. return eFilterSig8 == _sig8 && _cb <= _cbMax;
  211. }
  212. PSECURITY_DESCRIPTOR GetSD() { return &_ab; }
  213. ULONG GetCount() const { return _cb; }
  214. WORKID GetWorkid() const { return _widFake; }
  215. void SetSdid( ULONG sdid ) { _sdid = sdid; }
  216. ULONG GetSdid() const { return _sdid; }
  217. void SetStatus( BOOL fSuccess ) { _fSuccess = fSuccess; }
  218. BOOL GetStatus() const { return _fSuccess; }
  219. private:
  220. ULONG _sig8;
  221. ULONG _cbMax; // Maximum number of bytes allowed in _ab
  222. ULONG _cb;
  223. WORKID _widFake;
  224. ULONG _sdid; // Return value of the operation
  225. BOOL _fSuccess; // Success code of the operation
  226. //
  227. // The variable data is a copy of a self-relative security descriptor
  228. //
  229. SECURITY_DESCRIPTOR _ab; // place holder for variable data
  230. };
  231. class CPidMapper;
  232. class CSimplePidRemapper;
  233. //+---------------------------------------------------------------------------
  234. //
  235. // Class: CFPSToPROPIDLayout
  236. //
  237. // Purpose: Layout of data for the FPSToPROPID() call.
  238. //
  239. // History: 30-Dec-1997 kylep Created
  240. //
  241. //----------------------------------------------------------------------------
  242. class CFPSToPROPIDLayout
  243. {
  244. public:
  245. void Init( ULONG cbMax, CFullPropSpec const & fps );
  246. BOOL IsValid() const { return eFilterSig6 == _sig6 && _cb <= _cbMax; }
  247. BYTE const * GetBuffer() const { return (BYTE *) &_ab[0]; }
  248. BYTE * GetBuffer() { return (BYTE *) &_ab[0]; }
  249. ULONG GetCount() const { return _cb; }
  250. void SetCount( ULONG cb ) { _cb = cb; }
  251. PROPID GetPROPID() const { return *((PROPID *)&_ab[0]); }
  252. private:
  253. ULONG _sig6;
  254. ULONG _cbMax; // Maximum number of bytes allowed
  255. ULONG _cb; // Number of valid bytes serialized
  256. LONGLONG _ab[1]; // Serialized bytes
  257. };
  258. //+---------------------------------------------------------------------------
  259. //
  260. // Class: CFilterStartupDataLayout
  261. //
  262. // Purpose: Startup data for the filter daemon. It is passed through
  263. // from the client in the main process to the client in the
  264. // daemon.
  265. //
  266. // History: 12-13-96 srikants Created
  267. //
  268. //----------------------------------------------------------------------------
  269. class CFilterStartupDataLayout
  270. {
  271. public:
  272. void Init()
  273. {
  274. _sigA = eFilterSigA;
  275. _cbMax = sizeof(_ab);
  276. _cb = 0;
  277. }
  278. BOOL IsValid() const
  279. {
  280. return eFilterSigA == _sigA && _cb <= _cbMax;
  281. }
  282. BOOL SetData( GUID const & clsidDaemonClientMgr,
  283. BYTE const * pbData, ULONG cbData )
  284. {
  285. Win4Assert( IsValid() );
  286. if ( cbData <= _cbMax )
  287. {
  288. _clsidDaemonClientMgr = clsidDaemonClientMgr;
  289. RtlCopyMemory( _ab, pbData, cbData );
  290. _cb = cbData;
  291. return TRUE;
  292. }
  293. else return FALSE;
  294. }
  295. BYTE const * GetData( ULONG & cbData )
  296. {
  297. cbData = _cb;
  298. return (BYTE const *) _ab;
  299. }
  300. GUID const & GetClientMgrCLSID() const { return _clsidDaemonClientMgr; }
  301. private:
  302. ULONG _sigA; // Signature
  303. ULONG _cbMax; // Maximum number of bytes in the var buffer
  304. ULONG _cb; // Number of bytes in the var buffer.
  305. GUID _clsidDaemonClientMgr;
  306. // CLSID of the client component.
  307. LONGLONG _ab[ 65536 / sizeof LONGLONG ]; // Client data location, same as eMaxVarData
  308. };
  309. //+---------------------------------------------------------------------------
  310. //
  311. // Class: CFilterSharedMemLayout
  312. //
  313. // Purpose: Layout of the shared memory between the CI and DownLevel
  314. // daemon process.
  315. //
  316. // History: 1-31-96 srikants Created
  317. //
  318. //----------------------------------------------------------------------------
  319. class CFilterSharedMemLayout
  320. {
  321. public:
  322. //
  323. // Type of the work signalled by the Daemon to CI.
  324. //
  325. enum EFilterWorkType
  326. {
  327. eNone,
  328. eFilterStartupData,
  329. eFilterReady,
  330. eFilterDataReady,
  331. eFilterMore,
  332. eFilterDone,
  333. eFilterStoreValue,
  334. eFPSToPROPID,
  335. eFilterStoreSecurity,
  336. };
  337. void Init()
  338. {
  339. _type = eNone;
  340. _sig7 = eFilterSig7;
  341. RtlZeroMemory( &_data, sizeof(_data) );
  342. }
  343. BOOL IsValid() const
  344. {
  345. return eFilterSig7 == _sig7;
  346. }
  347. EFilterWorkType GetWorkType() const { return _type; }
  348. void SetWorkType( EFilterWorkType type ) { _type = type; }
  349. SCODE GetStatus() const { return _status; }
  350. void SetStatus( SCODE status ) { _status = status; }
  351. CFilterStartupDataLayout & GetStartupData() { return _data._filterStartup; }
  352. CFilterReadyLayout & GetFilterReady() { return _data._filterReady; }
  353. CFilterDataLayout & GetFilterDataReady() { return _filterData; }
  354. CFilterMoreDoneLayout & GetFilterMore() { return _data._filterMore; }
  355. CFilterMoreDoneLayout & GetFilterDone() { return _data._filterDone; }
  356. CFilterStoreValueLayout & GetFilterStoreValueLayout() { return _data._filterStore; }
  357. CFilterStoreSecurityLayout & GetFilterStoreSecurityLayout() { return _data._filterSdStore; }
  358. CFPSToPROPIDLayout & GetFPSToPROPID() { return _data._FPSToPROPID; }
  359. ULONG GetMaxVarDataSize() const { return sizeof(_data); }
  360. private:
  361. EFilterWorkType _type; // Type of the work.
  362. ULONG _sig7; // Signature.
  363. SCODE _status; // Status of the operation.
  364. CFilterDataLayout _filterData;
  365. //
  366. // Overlay for various functions.
  367. //
  368. union
  369. {
  370. enum { eMaxVarData = 64 * 1024 }; // 64K
  371. CFilterStartupDataLayout _filterStartup;
  372. CFilterReadyLayout _filterReady;
  373. CFilterMoreDoneLayout _filterMore;
  374. CFilterMoreDoneLayout _filterDone;
  375. CFilterStoreValueLayout _filterStore;
  376. CFilterStoreSecurityLayout _filterSdStore;
  377. CFPSToPROPIDLayout _FPSToPROPID;
  378. BYTE _ab[eMaxVarData];
  379. } _data;
  380. };
  381. //
  382. // Total size of the shared memory between the Daemon and CI.
  383. //
  384. const MAX_DL_SHARED_MEM = sizeof(CFilterSharedMemLayout);
  385. //+---------------------------------------------------------------------------
  386. //
  387. // Class: CGenericCiProxy
  388. //
  389. // Purpose: Proxy class for the DaemonProcess to communicate
  390. // with CI process.
  391. //
  392. // History: 1-30-96 srikants Created
  393. //
  394. //----------------------------------------------------------------------------
  395. class CGenericCiProxy : public CiProxy
  396. {
  397. enum { iDaemon = 0,
  398. iParent = 1
  399. }; // indices of wait handles
  400. public:
  401. CGenericCiProxy( CSharedNameGen & nameGen,
  402. DWORD dwMemSize,
  403. DWORD parentId );
  404. ~CGenericCiProxy();
  405. //
  406. // CiProxy methods
  407. //
  408. virtual SCODE FilterReady( BYTE* docBuffer,
  409. ULONG & cb,
  410. ULONG cMaxDocs );
  411. virtual SCODE FilterDataReady ( BYTE const * pEntryBuf,
  412. ULONG cb );
  413. virtual SCODE FilterMore( STATUS const * aStatus, ULONG cStatus );
  414. virtual SCODE FilterDone( STATUS const * aStatus, ULONG cStatus );
  415. virtual SCODE FilterStoreValue( WORKID widFake,
  416. CFullPropSpec const & ps,
  417. CStorageVariant const & var,
  418. BOOL & fCanStore );
  419. virtual SCODE FilterStoreSecurity( WORKID widFake,
  420. PSECURITY_DESCRIPTOR pSD,
  421. ULONG cbSD,
  422. BOOL & fCanStore );
  423. //
  424. // PPidConverter methods
  425. //
  426. virtual SCODE FPSToPROPID( CFullPropSpec const & fps, PROPID & pid );
  427. BYTE const * GetStartupData( GUID & clsidClientMgr, ULONG & cb );
  428. BYTE * GetEntryBuffer( ULONG & cb );
  429. void SetPriority( ULONG priClass, ULONG priThread );
  430. private:
  431. //
  432. // No default constructor.
  433. //
  434. CGenericCiProxy();
  435. void _LokGiveWork( CFilterSharedMemLayout::EFilterWorkType type )
  436. {
  437. _pLayout->SetWorkType( type );
  438. _evtDaemon.Reset();
  439. _evtCi.Set();
  440. }
  441. void _WaitForResponse();
  442. void ProbeForParentProcess();
  443. CIPMutexSem _mutex; // Shared mutex protecting the
  444. // common data.
  445. CLocalSystemSharedMemory _sharedMem; // Shared memory used by the two.
  446. CFilterSharedMemLayout * _pLayout; // Layout of the shared memory
  447. CEventSem _evtCi; // Event used to signal CI.
  448. CEventSem _evtDaemon; // Event used to signal Daemon.
  449. HANDLE _aWait[2]; // Array of handles to wait on
  450. ULONG _cHandles;
  451. };