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.

403 lines
12 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 1998.
  5. //
  6. // File: catreg.hxx
  7. //
  8. // Contents: Catalog registry helper classes
  9. //
  10. // Classes: CGibCallBack, CRegistryScopesCallBackFixups,
  11. // CRegistryScopesCallBackAdd, CRegistryScopesCallBackFind
  12. //
  13. // History: 13-Dec-1996 dlee split from cicat.cxx
  14. // 24-Jul-1997 KrishnaN enabled for null catalogs
  15. //
  16. //----------------------------------------------------------------------------
  17. #pragma once
  18. #include <dynload.hxx>
  19. #include <tstrhash.hxx>
  20. #include <notifary.hxx>
  21. //+---------------------------------------------------------------------------
  22. //
  23. // Class: CIISVirtualDirectory
  24. //
  25. // Purpose: All the info CI needs for an IIS virtual directory
  26. //
  27. // History: 2-Sep-97 dlee Created
  28. //
  29. //----------------------------------------------------------------------------
  30. class CIISVirtualDirectory
  31. {
  32. public:
  33. CIISVirtualDirectory( WCHAR const * pwcVPath,
  34. WCHAR const * pwcPPath,
  35. BOOL fIsIndexed,
  36. DWORD dwAccess,
  37. WCHAR const * pwcUser,
  38. WCHAR const * pwcPassword,
  39. BOOL fIsAVRoot );
  40. ~CIISVirtualDirectory()
  41. {
  42. WCHAR * pwcPW = _xPassword.GetPointer();
  43. if ( 0 != pwcPW )
  44. {
  45. unsigned cwc = wcslen( pwcPW );
  46. SecureZeroMemory( pwcPW, cwc * sizeof WCHAR );
  47. }
  48. }
  49. WCHAR const * VPath() { return _xVPath.GetPointer(); }
  50. unsigned VPathLen() { return _cwcVPath; }
  51. WCHAR const * PPath() { return _xPPath.GetPointer(); }
  52. unsigned PPathLen() { return _cwcPPath; }
  53. BOOL IsIndexed() { return _fIsIndexed; }
  54. BOOL IsAVRoot() { return _fIsAVRoot; }
  55. DWORD Access() { return _dwAccess; }
  56. WCHAR const * User() { return _xUser.GetPointer(); }
  57. WCHAR const * Password() { return _xPassword.GetPointer(); }
  58. ULONG Hash()
  59. {
  60. return Hash( VPath() );
  61. }
  62. static ULONG Hash( WCHAR const * pwc )
  63. {
  64. ULONG ulG;
  65. for ( ULONG ulH=0; *pwc; pwc++)
  66. {
  67. ulH = (ulH << 4) + (*pwc);
  68. if (ulG = (ulH & 0xf0000000))
  69. ulH ^= ulG >> 24;
  70. ulH &= ~ulG;
  71. }
  72. return ulH;
  73. }
  74. int Compare( WCHAR const * pwcVDir )
  75. {
  76. return wcscmp( VPath(), pwcVDir );
  77. }
  78. CIISVirtualDirectory * & Next() { return _pNext; }
  79. private:
  80. XPtrST<WCHAR> _xVPath;
  81. unsigned _cwcVPath;
  82. XPtrST<WCHAR> _xPPath;
  83. unsigned _cwcPPath;
  84. BOOL _fIsIndexed;
  85. BOOL _fIsAVRoot;
  86. DWORD _dwAccess;
  87. XPtrST<WCHAR> _xUser;
  88. XPtrST<WCHAR> _xPassword; // Short-lived in memory; don't encrypt.
  89. CIISVirtualDirectory * _pNext;
  90. };
  91. //+---------------------------------------------------------------------------
  92. //
  93. // Class: CIISVirtualDirectories
  94. //
  95. // Purpose: Maintains a list of IIS virtual directories
  96. //
  97. // History: 2-Sep-97 dlee Created
  98. //
  99. //----------------------------------------------------------------------------
  100. class CiCat;
  101. class CIISVirtualDirectories : public CMetaDataCallBack
  102. {
  103. public:
  104. CIISVirtualDirectories( CiVRootTypeEnum eType ) : _eType( eType ) {}
  105. ~CIISVirtualDirectories() {}
  106. SCODE CallBack( WCHAR const * pwcVRoot,
  107. WCHAR const * pwcPRoot,
  108. BOOL fIsIndexed,
  109. DWORD dwAccess,
  110. WCHAR const * pwcUser,
  111. WCHAR const * pwcPassword,
  112. BOOL fIsAVRoot );
  113. BOOL Lookup( WCHAR const * pwcVPath,
  114. unsigned cwcVPath,
  115. WCHAR const * pwcPPath,
  116. unsigned cwcPPath );
  117. void Enum( CiCat & cicat );
  118. void Enum( CMetaDataCallBack & callback );
  119. private:
  120. CCountedDynArray<CIISVirtualDirectory> _aDirectories;
  121. CHashtable<CIISVirtualDirectory> _htDirectories;
  122. CiVRootTypeEnum _eType;
  123. };
  124. //+-------------------------------------------------------------------------
  125. //
  126. // Class: CRegistryScopesCallBackFixups
  127. //
  128. // Synopsis: Callback class for adding scope fixups
  129. //
  130. // History: 16-Oct-96 dlee Created
  131. //
  132. //--------------------------------------------------------------------------
  133. class CRegistryScopesCallBackFixups : public CRegCallBack
  134. {
  135. public:
  136. CRegistryScopesCallBackFixups( PCatalog * pCat ) :
  137. _pcat( pCat )
  138. {
  139. }
  140. NTSTATUS CallBack( WCHAR *pValueName, ULONG uValueType,
  141. VOID *pValueData, ULONG uValueLength)
  142. {
  143. CParseRegistryScope parse( pValueName,
  144. uValueType,
  145. pValueData,
  146. uValueLength );
  147. if ( ( parse.IsPhysical() ||
  148. parse.IsShadowAlias() ||
  149. parse.IsVirtualPlaceholder() ) &&
  150. ( 0 != parse.GetFixup() ) )
  151. {
  152. ciDebugOut(( DEB_ITRACE, "callbackFixups '%ws', fixup as '%ws'\n",
  153. pValueName, parse.GetFixup() ));
  154. _pcat->GetScopeFixup()->Add( parse.GetScope(), parse.GetFixup() );
  155. }
  156. return S_OK;
  157. }
  158. private:
  159. PCatalog * _pcat;
  160. }; //CRegistryScopesCallBackFixups
  161. //+-------------------------------------------------------------------------
  162. //
  163. // Class: CRegistryScopesCallBackRemoveAlias
  164. //
  165. // Synopsis: Callback class for removing automatic alias scopes
  166. //
  167. // History: 16-Oct-96 dlee Created
  168. //
  169. //--------------------------------------------------------------------------
  170. DeclDynLoad2( NetApi32,
  171. NetApiBufferFree,
  172. NET_API_STATUS,
  173. NET_API_FUNCTION,
  174. ( LPVOID Buffer ),
  175. ( Buffer ),
  176. NetShareGetInfo,
  177. NET_API_STATUS,
  178. NET_API_FUNCTION,
  179. ( LPWSTR servername, LPWSTR netname, DWORD level, LPBYTE * bufptr ),
  180. ( servername, netname, level, bufptr ) );
  181. class CRegistryScopesCallBackRemoveAlias : public CRegCallBack
  182. {
  183. public:
  184. CRegistryScopesCallBackRemoveAlias( CiCat & Cat,
  185. CDynLoadNetApi32 & dlNetApi32,
  186. BOOL fRemoveAll );
  187. NTSTATUS CallBack( WCHAR *pValueName, ULONG uValueType,
  188. VOID *pValueData, ULONG uValueLength);
  189. BOOL WasScopeRemoved() { return _fScopeRemoved; }
  190. private:
  191. CiCat & _cicat;
  192. CDynLoadNetApi32 & _dlNetApi32;
  193. BOOL _fScopeRemoved;
  194. BOOL _fRemoveAll;
  195. DWORD _ccCompName;
  196. WCHAR _wcsCompName[MAX_COMPUTERNAME_LENGTH+1];
  197. }; //CRegistryScopesCallBackRemoveAlias
  198. //+-------------------------------------------------------------------------
  199. //
  200. // Class: CRegistryScopesCallBackFind
  201. //
  202. // Synopsis: Callback class for finding a scope in the registry
  203. //
  204. // History: 16-Oct-96 dlee Created
  205. //
  206. //--------------------------------------------------------------------------
  207. class CRegistryScopesCallBackFind : public CRegCallBack
  208. {
  209. public:
  210. CRegistryScopesCallBackFind( WCHAR const *pwcRoot ) :
  211. _root( pwcRoot ),
  212. _fWasFound( FALSE )
  213. {
  214. _root.AppendBackSlash();
  215. ciDebugOut(( DEB_ITRACE, "callbackfind setup for '%ws'\n",
  216. _root.Get() ));
  217. }
  218. NTSTATUS CallBack( WCHAR *pValueName, ULONG uValueType,
  219. VOID *pValueData, ULONG uValueLength)
  220. {
  221. // if the value isn't a string, ignore it.
  222. if ( REG_SZ == uValueType )
  223. {
  224. CParseRegistryScope parse( pValueName,
  225. uValueType,
  226. pValueData,
  227. uValueLength );
  228. if ( parse.IsPhysical() )
  229. {
  230. CLowcaseBuf value( parse.GetScope() );
  231. value.AppendBackSlash();
  232. ciDebugOut(( DEB_ITRACE, "callbackfind '%ws', '%ws'\n",
  233. value.Get(), pValueData ));
  234. if ( _root.AreEqual( value ) )
  235. _fWasFound = TRUE;
  236. ciDebugOut(( DEB_ITRACE, "callbackfind wasfound: %d\n",
  237. _fWasFound ));
  238. }
  239. }
  240. return S_OK;
  241. }
  242. BOOL WasFound() { return _fWasFound; }
  243. private:
  244. BOOL _fWasFound;
  245. CLowcaseBuf _root;
  246. }; //CRegistryScopesCallBackFind
  247. //+-------------------------------------------------------------------------
  248. //
  249. // Class: CRegistryScopesCallBackAdd
  250. //
  251. // Synopsis: Callback class for adding scopes from the registry
  252. //
  253. // History: 16-Oct-96 dlee Created
  254. //
  255. //--------------------------------------------------------------------------
  256. class CRegistryScopesCallBackAdd : public CRegCallBack
  257. {
  258. public:
  259. CRegistryScopesCallBackAdd( CiCat &cicat ) : _cicat( cicat )
  260. {
  261. }
  262. NTSTATUS CallBack( WCHAR *pValueName, ULONG uValueType,
  263. VOID *pValueData, ULONG uValueLength );
  264. private:
  265. CiCat & _cicat;
  266. }; //CRegistryScopesCallBackAdd
  267. //+-------------------------------------------------------------------------
  268. //
  269. // Class: CRegistryScopesCallBackFillUsnArray
  270. //
  271. // Synopsis: Callback class for populating the Usn Volume Array with
  272. // scopes from the registry
  273. //
  274. // History: 23-Jun-98 kitmanh Created
  275. //
  276. //--------------------------------------------------------------------------
  277. class CRegistryScopesCallBackFillUsnArray : public CRegCallBack
  278. {
  279. public:
  280. CRegistryScopesCallBackFillUsnArray( CiCat &cicat ) : _cicat( cicat )
  281. {
  282. }
  283. NTSTATUS CallBack( WCHAR *pValueName, ULONG uValueType,
  284. VOID *pValueData, ULONG uValueLength );
  285. private:
  286. CiCat & _cicat;
  287. }; //CRegistryScopesCallBackAdd
  288. //+-------------------------------------------------------------------------
  289. //
  290. // Class: CRegistryScopesCallBackToDismount
  291. //
  292. // Synopsis: Callback class to check if the catalog contains a scope on
  293. // the volume to be dismounted
  294. //
  295. // History: 21-Jul-98 kitmanh Created
  296. //
  297. //--------------------------------------------------------------------------
  298. class CRegistryScopesCallBackToDismount : public CRegCallBack
  299. {
  300. public:
  301. CRegistryScopesCallBackToDismount( WCHAR wcVol ) :
  302. _wcVol( wcVol ),
  303. _fWasFound( FALSE )
  304. {
  305. }
  306. NTSTATUS CallBack( WCHAR *pValueName, ULONG uValueType,
  307. VOID *pValueData, ULONG uValueLength );
  308. BOOL WasFound() { return _fWasFound; }
  309. private:
  310. WCHAR _wcVol;
  311. BOOL _fWasFound;
  312. }; //CRegistryScopesCallBackToDismount
  313. //+-------------------------------------------------------------------------
  314. //
  315. // Class: CRegistryScopesCallBackAddDrvNotif
  316. //
  317. // Synopsis: Callback class to register the scopes for drive
  318. // notifications
  319. //
  320. // History: 19-Aug-98 kitmanh Created
  321. //
  322. //--------------------------------------------------------------------------
  323. class CRegistryScopesCallBackAddDrvNotif : public CRegCallBack
  324. {
  325. public:
  326. CRegistryScopesCallBackAddDrvNotif( CDrvNotifArray * pNotifArray ) :
  327. _pNotifArray( pNotifArray )
  328. {
  329. }
  330. NTSTATUS CallBack( WCHAR *pValueName, ULONG uValueType,
  331. VOID *pValueData, ULONG uValueLength );
  332. private:
  333. CDrvNotifArray * _pNotifArray;
  334. }; //CRegistryScopesCallBackAddDrvNotif