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.

425 lines
12 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997-1998
  5. //
  6. // File: cimbmgr.hxx
  7. //
  8. // Contents: Content index Meta Base Manager
  9. //
  10. // Classes: CMetaDataMgr, CMetaDataHandle, CMetaDataComSink,
  11. // CMetaDataCallBack, CMetaDataVPathChangeCallBack
  12. //
  13. // History: 07-Feb-1997 dlee Created
  14. //
  15. //----------------------------------------------------------------------------
  16. #pragma once
  17. #include <iadmw.h>
  18. #include <iiscnfg.h>
  19. enum CiVRootTypeEnum
  20. {
  21. W3VRoot = 0,
  22. NNTPVRoot = 1,
  23. IMAPVRoot = 2
  24. };
  25. // Timeout for opening metabase handles (in milliseconds)
  26. const DWORD cmsCIMetabaseTimeout = 60000;
  27. //+---------------------------------------------------------------------------
  28. //
  29. // Function: GetVRootServiceType
  30. //
  31. // Purpose: Returns a string representation of a vroot type
  32. //
  33. // History: 20-Jun-1997 dlee Created
  34. //
  35. //----------------------------------------------------------------------------
  36. inline WCHAR const * GetVRootService( CiVRootTypeEnum eType )
  37. {
  38. if ( W3VRoot == eType )
  39. return L"w3svc";
  40. if ( NNTPVRoot == eType )
  41. return L"nntpsvc";
  42. Win4Assert( IMAPVRoot == eType );
  43. return L"imapsvc";
  44. } //GetVRootService
  45. //+---------------------------------------------------------------------------
  46. //
  47. // Class: CMetaDataCallBack
  48. //
  49. // Purpose: Pure virtual for vpath enumeration
  50. //
  51. // History: 07-Feb-1997 dlee Created
  52. //
  53. //----------------------------------------------------------------------------
  54. class CMetaDataCallBack
  55. {
  56. public:
  57. virtual SCODE CallBack( WCHAR const * pwcVPath,
  58. WCHAR const * pwcPRoot,
  59. BOOL fIsIndexed,
  60. DWORD dwAccess,
  61. WCHAR const * pwcUser,
  62. WCHAR const * pwcPassword,
  63. BOOL fIsAVRoot ) = 0;
  64. virtual ~CMetaDataCallBack() {}
  65. };
  66. //+---------------------------------------------------------------------------
  67. //
  68. // Class: CMetaDataVirtualServerCallBack
  69. //
  70. // Purpose: Pure virtual for vroot enumeration
  71. //
  72. // History: 07-Feb-1997 dlee Created
  73. //
  74. //----------------------------------------------------------------------------
  75. class CMetaDataVirtualServerCallBack
  76. {
  77. public:
  78. virtual SCODE CallBack( DWORD iInstance,
  79. WCHAR const * pwcInstance ) = 0;
  80. virtual ~CMetaDataVirtualServerCallBack() {}
  81. };
  82. //+---------------------------------------------------------------------------
  83. //
  84. // Class: CMetaDataVRootChangeCallBack
  85. //
  86. // Purpose: Pure virtual for vpath change notification
  87. //
  88. // History: 07-Feb-1997 dlee Created
  89. //
  90. //----------------------------------------------------------------------------
  91. class CMetaDataVPathChangeCallBack
  92. {
  93. public:
  94. virtual SCODE CallBack( BOOL fCancel ) = 0;
  95. virtual ~CMetaDataVPathChangeCallBack() {}
  96. };
  97. //+---------------------------------------------------------------------------
  98. //
  99. // Class: CMetaDataComSink
  100. //
  101. // Purpose: Connection point callback helper class for vpath change
  102. // notificaton.
  103. //
  104. // History: 07-Feb-1997 dlee Created
  105. //
  106. //----------------------------------------------------------------------------
  107. class CMetaDataComSink : public IMSAdminBaseSink
  108. {
  109. public:
  110. CMetaDataComSink() : _lRefCount( 1 ), _pCallBack( 0 )
  111. {
  112. _awcInstance[0] = 0;
  113. }
  114. ~CMetaDataComSink()
  115. {
  116. ciDebugOut(( DEB_ITRACE, "~sink %#x %d\n", this, _lRefCount ));
  117. }
  118. void SetCallBack( CMetaDataVPathChangeCallBack *p )
  119. {
  120. _pCallBack = p;
  121. }
  122. CMetaDataVPathChangeCallBack * GetCallBack()
  123. {
  124. return _pCallBack;
  125. }
  126. void SetInstance( WCHAR const * pwcInstance )
  127. {
  128. wcscpy( _awcInstance, pwcInstance );
  129. }
  130. SCODE STDMETHODCALLTYPE QueryInterface( REFIID riid, void **ppObject )
  131. {
  132. if ( IID_IUnknown == riid || IID_IMSAdminBaseSink == riid )
  133. *ppObject = (IMSAdminBaseSink *) this;
  134. else
  135. return E_NOINTERFACE;
  136. AddRef();
  137. return S_OK;
  138. }
  139. ULONG STDMETHODCALLTYPE AddRef()
  140. {
  141. return InterlockedIncrement( &_lRefCount );
  142. }
  143. ULONG STDMETHODCALLTYPE Release()
  144. {
  145. Win4Assert( _lRefCount >= 1 );
  146. ULONG cRefs = InterlockedDecrement( &_lRefCount );
  147. if ( 0 == cRefs )
  148. delete this;
  149. return cRefs;
  150. }
  151. SCODE STDMETHODCALLTYPE SinkNotify(
  152. DWORD cChanges,
  153. MD_CHANGE_OBJECT pcoChangeList[] );
  154. SCODE STDMETHODCALLTYPE ShutdownNotify();
  155. private:
  156. long _lRefCount;
  157. CMetaDataVPathChangeCallBack * _pCallBack;
  158. WCHAR _awcInstance[ METADATA_MAX_NAME_LEN ];
  159. };
  160. //+---------------------------------------------------------------------------
  161. //
  162. // Class: CMetaDataHandle
  163. //
  164. // Purpose: Smart meta data handle class
  165. //
  166. // History: 07-Feb-1997 dlee Created
  167. //
  168. //----------------------------------------------------------------------------
  169. class CMetaDataHandle
  170. {
  171. public:
  172. CMetaDataHandle( XInterface<IMSAdminBase> & xAdminBase,
  173. WCHAR const * pwcPath,
  174. BOOL fWrite = FALSE )
  175. : _xAdminBase( xAdminBase ),
  176. _h( 0 )
  177. {
  178. SCODE sc = _xAdminBase->OpenKey( METADATA_MASTER_ROOT_HANDLE,
  179. (LPWSTR) pwcPath,
  180. ( fWrite ? METADATA_PERMISSION_WRITE :
  181. 0 ) |
  182. METADATA_PERMISSION_READ,
  183. cmsCIMetabaseTimeout,
  184. &_h );
  185. if ( FAILED( sc ) )
  186. {
  187. ciDebugOut(( DEB_WARN, "couldn't open metaobject '%ws', 0x%x\n",
  188. pwcPath, sc ));
  189. THROW( CException( sc ) );
  190. }
  191. }
  192. CMetaDataHandle( XInterface<IMSAdminBase> & xAdminBase,
  193. METADATA_HANDLE h )
  194. : _xAdminBase( xAdminBase ),
  195. _h( h )
  196. {
  197. }
  198. ~CMetaDataHandle()
  199. {
  200. if ( 0 != _h )
  201. _xAdminBase->CloseKey( _h );
  202. }
  203. METADATA_HANDLE Get() { return _h; }
  204. private:
  205. METADATA_HANDLE _h;
  206. XInterface<IMSAdminBase> & _xAdminBase;
  207. };
  208. //+---------------------------------------------------------------------------
  209. //
  210. // Class: CVRootStack
  211. //
  212. // Purpose: Stack of vroots, proots, and access masks
  213. //
  214. // History: 07-Feb-1997 dlee Created
  215. //
  216. //----------------------------------------------------------------------------
  217. class CVRootStack
  218. {
  219. public:
  220. CVRootStack() {}
  221. void Push( WCHAR const * pwcVRoot, WCHAR const * pwcPRoot, DWORD access )
  222. {
  223. _Access[ _Access.Count() ] = access;
  224. unsigned cwcV = 1 + wcslen( pwcVRoot );
  225. XArray<WCHAR> xVRoot( cwcV );
  226. RtlCopyMemory( xVRoot.GetPointer(), pwcVRoot, xVRoot.SizeOf() );
  227. _VRoots.Push( xVRoot.GetPointer() );
  228. xVRoot.Acquire();
  229. unsigned cwcP = 1 + wcslen( pwcPRoot );
  230. XArray<WCHAR> xPRoot( cwcP );
  231. RtlCopyMemory( xPRoot.GetPointer(), pwcPRoot, xPRoot.SizeOf() );
  232. _PRoots.Push( xPRoot.GetPointer() );
  233. xPRoot.Acquire();
  234. }
  235. void Pop()
  236. {
  237. delete [] _VRoots.Pop();
  238. delete [] _PRoots.Pop();
  239. _Access.Remove( _Access.Count() - 1 );
  240. }
  241. WCHAR const * PeekTopVRoot() const
  242. {
  243. Win4Assert( !IsEmpty() );
  244. return _VRoots.Get( _VRoots.Count() - 1 );
  245. }
  246. WCHAR const * PeekTopPRoot() const
  247. {
  248. Win4Assert( !IsEmpty() );
  249. return _PRoots.Get( _PRoots.Count() - 1 );
  250. }
  251. DWORD PeekTopAccess() const
  252. {
  253. Win4Assert( !IsEmpty() );
  254. return _Access[ _Access.Count() - 1 ];
  255. }
  256. BOOL IsEmpty() const { return 0 == _VRoots.Count(); }
  257. private:
  258. CDynStack<WCHAR> _VRoots;
  259. CDynStack<WCHAR> _PRoots;
  260. CDynArrayInPlace<DWORD> _Access;
  261. };
  262. //+---------------------------------------------------------------------------
  263. //
  264. // Class: CMetaDataMgr
  265. //
  266. // Purpose: Class that encapsulates K2 metabase API for CI
  267. //
  268. // History: 07-Feb-1997 dlee Created
  269. //
  270. //----------------------------------------------------------------------------
  271. class CMetaDataMgr
  272. {
  273. public:
  274. CMetaDataMgr( BOOL fTopLevel,
  275. CiVRootTypeEnum eType,
  276. DWORD dwInstance = 0xffffffff,
  277. WCHAR const * pwcMachine = L"." );
  278. ~CMetaDataMgr();
  279. static BOOL IsIISAdminUp( BOOL & fIISAdminInstalled );
  280. void EnumVPaths( CMetaDataCallBack & callBack );
  281. void AddVRoot( WCHAR const * pwcVRoot,
  282. WCHAR const * pwcPRoot,
  283. DWORD dwAccess );
  284. SCODE RemoveVRoot( WCHAR const * pwcVRoot );
  285. void GetVRoot( WCHAR const * pwcVRoot,
  286. WCHAR * pwcPRoot );
  287. void GetVRootPW( WCHAR const * pwcVRoot,
  288. WCHAR * pwcPassword );
  289. void AddScriptMap( WCHAR const * pwcMap );
  290. void RemoveScriptMap( WCHAR const * pwcExt );
  291. BOOL ExtensionHasScriptMap( WCHAR const * pwcExt );
  292. BOOL ExtensionHasTargetScriptMap( WCHAR const * pwcExt, WCHAR const * pwcDll );
  293. void AddApplicationDependency( WCHAR const * pwcApp );
  294. void AddRestrictionList( WCHAR const * pwcRestriction );
  295. void RemoveApplicationDependency( WCHAR const * pwcKey );
  296. void RemoveRestrictionList( WCHAR const * pwcKey );
  297. void AddInProcessIsapiApp( WCHAR const * pwcApp );
  298. void EnableVPathNotify( CMetaDataVPathChangeCallBack *pCallBack );
  299. void DisableVPathNotify();
  300. void SetIsIndexed( WCHAR const * pwcVPath,
  301. BOOL fIsIndexed );
  302. BOOL IsIndexed( WCHAR const * pwcVPath );
  303. void EnumVServers( CMetaDataVirtualServerCallBack & callBack );
  304. ULONG GetVPathAccess( WCHAR const * pwcVPath );
  305. ULONG GetVPathSSLAccess( WCHAR const * pwcVPath );
  306. ULONG GetVPathAuthorization( WCHAR const * pwcVPath );
  307. void Flush( void );
  308. private:
  309. ULONG GetVPathFlags( WCHAR const * pwcVPath, ULONG mdID, ULONG ulDefault );
  310. XInterface<IMSAdminBase> & Get() { return _xAdminBase; }
  311. BOOL ReportVPath( CVRootStack & vrootStack,
  312. CMetaDataCallBack & callBack,
  313. CMetaDataHandle & mdRoot,
  314. WCHAR const * pwcRelative );
  315. void ReportVirtualServer( CMetaDataVirtualServerCallBack & callBack,
  316. CMetaDataHandle & mdRoot,
  317. WCHAR const * pwcRelative );
  318. void Enum( CVRootStack & vrootStack,
  319. CMetaDataCallBack & callBack,
  320. CMetaDataHandle & mdRoot,
  321. WCHAR const * pcRelative );
  322. void Enum( CMetaDataVirtualServerCallBack & callBack,
  323. CMetaDataHandle & mdRoot,
  324. WCHAR const * pwcRelative );
  325. void ReadRootValue( CMetaDataHandle & mdRoot,
  326. METADATA_RECORD & mdr,
  327. XGrowable<WCHAR> & xData,
  328. DWORD dwIdentifier );
  329. void WriteRootValue( CMetaDataHandle & mdRoot,
  330. METADATA_RECORD & mdr,
  331. WCHAR const * pwcData,
  332. unsigned cwcData );
  333. BOOL _fNotifyEnabled;
  334. BOOL _fTopLevel;
  335. XInterface<IMSAdminBase> _xAdminBase;
  336. XInterface<CMetaDataComSink> _xSink;
  337. XInterface<IConnectionPoint> _xCP;
  338. DWORD _dwCookie;
  339. WCHAR _awcInstance[METADATA_MAX_NAME_LEN];
  340. };