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.

386 lines
10 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997 - 2001.
  5. //
  6. // File: CiNulCat.CXX
  7. //
  8. // Contents: Content index null catalog.
  9. //
  10. // Classes:
  11. //
  12. // History: 09-Jul-1997 KrishnaN Created
  13. //
  14. //----------------------------------------------------------------------------
  15. #include <pch.cxx>
  16. #pragma hdrstop
  17. #include <regacc.hxx>
  18. #include <cicat.hxx>
  19. #include <cinulcat.hxx>
  20. #include <update.hxx>
  21. #include <pstore.hxx>
  22. #include <pidremap.hxx>
  23. #include <imprsnat.hxx>
  24. #include <docstore.hxx>
  25. #include <cievtmsg.h>
  26. #include <cifailte.hxx>
  27. #include <regscp.hxx>
  28. #include <cifrmcom.hxx>
  29. #include <glbconst.hxx>
  30. #include <cimbmgr.hxx>
  31. #include "catreg.hxx"
  32. //
  33. // Given a registry string like \Registry\Machine\System\CurrentControlSet\...
  34. // you skip the first 18 characters if using w/ HKEY_LOCAL_MACHINE.
  35. //
  36. unsigned const SKIP_TO_LM = 18;
  37. // -------------------------------------------------------------------------
  38. // DO NOT VIOLATE THE FOLLOWING LOCK HIERARCHY
  39. //
  40. // 1. DocStore Lock
  41. // 2. CiNullCat Admin Lock
  42. // 3. CiNullCat Lock
  43. // 4. Resman Lock
  44. // 5. ScopeTable Lock
  45. // 6. NotifyMgr Lock
  46. // 7. ScanMgr Lock
  47. // 8. Propstore write lock
  48. // 9. Propstore lock record
  49. //
  50. // It is okay for a thread to acquire lock at level X and then acquire a lock
  51. // at a level >= X but not locks < X. This will avoid deadlock situations.
  52. //
  53. // SrikantS - April 25, 1996
  54. // SrikantS _ Dec 31, 1996 - Added DocStore as the highest level lock
  55. //
  56. // -------------------------------------------------------------------------
  57. //+-------------------------------------------------------------------------
  58. //
  59. // Member: CiNullCat::SetAdviseStatus, public
  60. //
  61. // Synopsis: Taken out of the CiNullCat constructor
  62. //
  63. // History: 11-May-2001 KitmanH Taken out from the CiNullCat constructor
  64. //
  65. // Note: The purpose of this function is to prevent circular deleteions
  66. // of CiNullCat and CClientDocStore. If CClientDocStore throws
  67. // after StartUpCiFrameWork, CiNullCat should not AddRef to
  68. // docstore
  69. //
  70. //--------------------------------------------------------------------------
  71. void CiNullCat::SetAdviseStatus()
  72. {
  73. // obtain an ICiCAdviseStatus interface pointer to use
  74. ICiCAdviseStatus *pAdviseStatus = 0;
  75. SCODE sc = _docStore.QueryInterface( IID_ICiCAdviseStatus,
  76. (void **) &pAdviseStatus);
  77. if ( S_OK != sc )
  78. {
  79. Win4Assert( 0 == pAdviseStatus );
  80. THROW( CException(sc) );
  81. }
  82. _xAdviseStatus.Set(pAdviseStatus);
  83. }
  84. //+-------------------------------------------------------------------------
  85. //
  86. // Member: CiNullCat::CiNullCat, public
  87. //
  88. // Synopsis: Creates a new 'content index catalog'
  89. //
  90. // Arguments: [wcsCatPath] - root path of catalog
  91. // [pwcName] - 0 or name of the catalog from the registry
  92. //
  93. // History: 10-Mar-92 BartoszM Created
  94. // 14-mar-92 KyleP Added Content index object.
  95. //
  96. //--------------------------------------------------------------------------
  97. CiNullCat::CiNullCat ( CClientDocStore & docStore)
  98. : _ulSignature( LONGSIG( 'c', 'c', 'a', 't' ) ),
  99. _state(eStarting),
  100. _docStore(docStore),
  101. _fInitialized(FALSE),
  102. _impersonationTokenCache( CINULLCATALOG )
  103. {
  104. CImpersonateSystem impersonate;
  105. BuildRegistryScopesKey( _xScopesKey, CINULLCATALOG );
  106. _impersonationTokenCache.Initialize( CI_ACTIVEX_NAME,
  107. FALSE,
  108. FALSE,
  109. FALSE,
  110. 1,
  111. 1,
  112. 1 );
  113. // These scopes will be used for query time (un)fixups
  114. SetupScopeFixups();
  115. _state = eStarted;
  116. END_CONSTRUCTION( CiNullCat );
  117. } //CiNullCat
  118. //+---------------------------------------------------------------------------
  119. //
  120. // Member: CiNullCat::ShutdownPhase2, public
  121. //
  122. // Synopsis: Dismounts the catalog by stopping all activity.
  123. //
  124. // History: 1-30-96 srikants Created
  125. //
  126. // Notes:
  127. //
  128. //----------------------------------------------------------------------------
  129. void CiNullCat::ShutdownPhase2()
  130. {
  131. CImpersonateSystem impersonate;
  132. TRY
  133. {
  134. // ===================================================
  135. {
  136. CLock lock(_mutex);
  137. _state = eShutdown;
  138. }
  139. // ===================================================
  140. CLock lock(_mutex);
  141. _xCiManager.Free();
  142. }
  143. CATCH( CException, e )
  144. {
  145. ciDebugOut(( DEB_ERROR, "CiNullCat::Shutdown failed with error 0x%X\n",
  146. e.GetErrorCode() ));
  147. }
  148. END_CATCH
  149. } //Shutdown
  150. //+-------------------------------------------------------------------------
  151. //
  152. // Member: CiNullCat::~CiNullCat, public
  153. //
  154. // Synopsis: Destructor
  155. //
  156. // History: 10-Mar-92 BartoszM Created
  157. //
  158. //--------------------------------------------------------------------------
  159. CiNullCat::~CiNullCat ()
  160. {
  161. if ( !IsShutdown() )
  162. ShutdownPhase2();
  163. }
  164. //+---------------------------------------------------------------------------
  165. //
  166. // Member: CiNullCat::CiState, public
  167. //
  168. // Synopsis: Returns state of downlevel CI
  169. //
  170. // Arguments: [state] -- buffer to return state into
  171. //
  172. // History: 14-Dec-95 DwightKr Created
  173. //
  174. //----------------------------------------------------------------------------
  175. #define setState( field, value ) \
  176. if ( state.cbStruct >= ( offsetof( CI_STATE, field) + \
  177. sizeof( state.field ) ) ) \
  178. { \
  179. state.field = ( value ); \
  180. }
  181. SCODE CiNullCat::CiState( CI_STATE & state )
  182. {
  183. SCODE sc = S_OK;
  184. if ( IsStarted() )
  185. {
  186. state.cbStruct = min( state.cbStruct, sizeof(CI_STATE) );
  187. RtlZeroMemory( &state, state.cbStruct );
  188. setState( dwMergeProgress, 100 );
  189. }
  190. else if ( IsShutdown() )
  191. {
  192. sc = CI_E_SHUTDOWN;
  193. }
  194. else
  195. {
  196. sc = CI_E_NOT_INITIALIZED;
  197. }
  198. return sc;
  199. }
  200. //+---------------------------------------------------------------------------
  201. //
  202. // Member: CiNullCat::HandleError
  203. //
  204. // Synopsis: Checks the status code passed and if it indicates corruption,
  205. // the index will be marked corrupt in-memory as well as on
  206. // disk. The recovery will happen on a subsequent restart.
  207. //
  208. // Arguments: [status] - The status code to check for corruption.
  209. //
  210. // History: 3-21-96 srikants Created
  211. //
  212. // Notes: MUST NOT THROW
  213. //
  214. //----------------------------------------------------------------------------
  215. void CiNullCat::HandleError( NTSTATUS status )
  216. {
  217. Win4Assert(CI_PROPSTORE_INCONSISTENCY != status);
  218. Win4Assert(!IsDiskLowError(status));
  219. Win4Assert(!IsCiCorruptStatus(status));
  220. //
  221. // We can't be corrupt, so nothing to do here.
  222. //
  223. } //HandleError
  224. //
  225. // Support for CI Frame Work
  226. //
  227. //+---------------------------------------------------------------------------
  228. //
  229. // Member: CiNullCat::StartupCiFrameWork
  230. //
  231. // Synopsis: Takes the CiManager object pointer and refcounts it.
  232. //
  233. // Arguments: [pICiManager] -
  234. //
  235. // History: 12-05-96 srikants Created
  236. //
  237. // Note: Choose a better name.
  238. //
  239. //----------------------------------------------------------------------------
  240. //
  241. void CiNullCat::StartupCiFrameWork( ICiManager * pICiManager )
  242. {
  243. Win4Assert( 0 != pICiManager );
  244. Win4Assert( 0 == _xCiManager.GetPointer() );
  245. if ( 0 == _xCiManager.GetPointer() )
  246. {
  247. pICiManager->AddRef();
  248. _xCiManager.Set( pICiManager );
  249. }
  250. RefreshRegistryParams();
  251. }
  252. //+---------------------------------------------------------------------------
  253. //
  254. // Member: CiNullCat::RefreshRegistryParams
  255. //
  256. // Synopsis: Refreshes CI registry parameters.
  257. //
  258. // History: 12-12-96 srikants Created
  259. // 1-25-97 mohamedn ICiAdminParams, ICiAdmin
  260. // Notes:
  261. //
  262. //----------------------------------------------------------------------------
  263. void CiNullCat::RefreshRegistryParams()
  264. {
  265. ICiAdminParams *pICiAdminParams = 0;
  266. XInterface<ICiAdminParams> xICiAdminParams;
  267. ICiAdmin *pICiAdmin = 0;
  268. XInterface<ICiAdmin> xICiAdmin;
  269. // ++++++++++++++++++++++++++++++++++++++++++++++++++++
  270. {
  271. CLock lock(_mutex);
  272. if ( !IsShutdown() && 0 != _xCiManager.GetPointer() )
  273. {
  274. // get pICiAdminParams
  275. SCODE sc = _xCiManager->GetAdminParams( &pICiAdminParams );
  276. if ( FAILED(sc) )
  277. {
  278. Win4Assert( 0 == pICiAdminParams );
  279. THROW( CException(sc) );
  280. }
  281. xICiAdminParams.Set(pICiAdminParams);
  282. // get pICiAdmin
  283. sc = _xCiManager->QueryInterface(IID_ICiAdmin,(void **)&pICiAdmin);
  284. if ( FAILED(sc) )
  285. {
  286. Win4Assert( 0 == pICiAdmin );
  287. THROW( CException(sc) );
  288. }
  289. xICiAdmin.Set(pICiAdmin);
  290. }
  291. }
  292. // -----------------------------------------------------
  293. SCODE sc = xICiAdmin->InvalidateLangResources();
  294. if ( FAILED (sc) )
  295. {
  296. Win4Assert( !"Failed to InvalidateLangResources\n" );
  297. THROW( CException(sc) );
  298. }
  299. _regParams.Refresh(pICiAdminParams);
  300. }
  301. //+-------------------------------------------------------------------------
  302. //
  303. // Member: CiNullCat::SetupScopeFixups, private
  304. //
  305. // Synopsis: Grovel registry looking for CI scopes and setup fixups
  306. //
  307. // History: 16-Oct-96 dlee Created
  308. //
  309. //--------------------------------------------------------------------------
  310. void CiNullCat::SetupScopeFixups()
  311. {
  312. TRY
  313. {
  314. ciDebugOut(( DEB_ITRACE, "Reading scope fixups from '%ws'\n", GetScopesKey() ));
  315. CRegAccess regScopes( RTL_REGISTRY_ABSOLUTE, GetScopesKey() );
  316. CRegistryScopesCallBackFixups callback( this );
  317. regScopes.EnumerateValues( 0, callback );
  318. }
  319. CATCH( CException, e )
  320. {
  321. ciDebugOut(( DEB_WARN,
  322. "Exception 0x%x caught groveling ci registry fixups.\n",
  323. e.GetErrorCode() ));
  324. HandleError( e.GetErrorCode() );
  325. }
  326. END_CATCH
  327. } //SetupScopeFixups