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.

628 lines
17 KiB

  1. /*===================================================================
  2. Microsoft IIS
  3. Microsoft Confidential.
  4. Copyright 1997 Microsoft Corporation. All Rights Reserved.
  5. Component: WAMREG
  6. File: Auxfunc.h
  7. supporting functions header file.
  8. Owner: LeiJin
  9. Note:
  10. ===================================================================*/
  11. #ifndef _WAMREG_AUXFUNC_H
  12. #define _WAMREG_AUXFUNC_H
  13. #include "iadmw.h"
  14. #include "comadmin.h"
  15. #include "wmrgexp.h"
  16. #include "dbgutil.h"
  17. #include "iwamreg.h"
  18. #include "iiscnfg.h"
  19. // EMD_SET an action to set the corresponding metabase identifier in metabase.
  20. // EMD_DELETE an action to delete the corresponding metabase identifier in metabase.
  21. // EMD_NONE an NO-OP action.
  22. #define EMD_SET 1
  23. #define EMD_DELETE 2
  24. #define EMD_NONE 0
  25. // MDPropItem
  26. // Used in WamRegMetabaseConfig, usually created an array of MDPropItem where each elment represents
  27. // one WAMREG application property.
  28. //
  29. struct MDPropItem
  30. {
  31. DWORD dwMDIdentifier; // Metabase Indetitifer
  32. DWORD dwType; // Metabase data type
  33. union
  34. {
  35. DWORD dwVal; // used if dwType is a METADATA_DWORD type.
  36. WCHAR* pwstrVal; // used if dwType is a METADATA_STRING type.
  37. };
  38. DWORD dwAction; // EMD_SET / EMD_DELETE / EMD_NONE
  39. HRESULT hrStatus;
  40. };
  41. //
  42. // Index to Wam Metabase Property
  43. // Each one represents one WAMREG application related metabase property.
  44. //
  45. #define IWMDP_ROOT 0
  46. #define IWMDP_ISOLATED 1
  47. #define IWMDP_WAMCLSID 2
  48. #define IWMDP_PACKAGEID 3
  49. #define IWMDP_PACKAGE_NAME 4
  50. #define IWMDP_LAST_OUTPROC_PID 5
  51. #define IWMDP_FRIENDLY_NAME 6
  52. #define IWMDP_APPSTATE 7
  53. #define IWMDP_OOP_RECOVERLIMIT 8
  54. #define IWMDP_OOP_APP_APPPOOL_ID 9
  55. // Max of the above property.
  56. #define IWMDP_MAX 10
  57. //
  58. // WamAdmLock is used to create an "Critical Section" when perserve the order of App Create/Delete/etc.
  59. // requests.
  60. //
  61. class WamAdmLock
  62. {
  63. public:
  64. WamAdmLock();
  65. BOOL Init(); // Init the WamAdmLock data member.
  66. BOOL UnInit(); // Uninit the WamAdmLock data member
  67. VOID AcquireWriteLock(); // Acquire the Lock
  68. VOID ReleaseWriteLock(); // Release the Lock.
  69. private:
  70. DWORD GetNextServiceToken();
  71. VOID Lock(); // Internal CS lock.
  72. VOID UnLock(); // Internal CS unlock.
  73. // Data
  74. DWORD m_dwServiceToken;
  75. DWORD m_dwServiceNum;
  76. HANDLE m_hWriteLock;
  77. CRITICAL_SECTION m_csLock;
  78. };
  79. inline VOID WamAdmLock::Lock()
  80. {
  81. EnterCriticalSection(&m_csLock);
  82. }
  83. inline VOID WamAdmLock::UnLock()
  84. {
  85. LeaveCriticalSection(&m_csLock);
  86. }
  87. //
  88. // WamRegGlobal
  89. // Contains some default global constant.
  90. // Contains a WamAdmLock memeber for DCOM level request locking.
  91. //
  92. class WamRegGlobal
  93. {
  94. public:
  95. WamRegGlobal() {};
  96. ~WamRegGlobal() {};
  97. BOOL Init();
  98. BOOL UnInit();
  99. VOID AcquireAdmWriteLock(VOID);
  100. VOID ReleaseAdmWriteLock(VOID);
  101. HRESULT CreatePooledApp
  102. (
  103. IN LPCWSTR szMetabasePath,
  104. IN BOOL fInProc,
  105. IN BOOL fRecover = FALSE
  106. );
  107. HRESULT CreateOutProcApp
  108. (
  109. IN LPCWSTR szMetabasePath,
  110. IN BOOL fRecover = FALSE,
  111. IN BOOL fSaveMB = TRUE
  112. );
  113. HRESULT CreateOutProcAppReplica
  114. (
  115. IN LPCWSTR szMetabasePath,
  116. IN LPCWSTR szAppName,
  117. IN LPCWSTR szWamClsid,
  118. IN LPCWSTR szAppId
  119. );
  120. HRESULT DeleteApp
  121. (
  122. IN LPCWSTR szMetabasePath,
  123. IN BOOL fRecoverable,
  124. IN BOOL fRemoveAppPool
  125. );
  126. HRESULT RecoverApp
  127. (
  128. IN LPCWSTR szMetabasePath,
  129. IN BOOL fForceRecover
  130. );
  131. HRESULT SzWamProgID
  132. (
  133. IN LPCWSTR pwszMetabasePath,
  134. OUT LPWSTR *ppszWamProgID
  135. );
  136. HRESULT W3ServiceUtil
  137. (
  138. IN LPCWSTR szMDPath,
  139. IN DWORD dwCommand,
  140. OUT DWORD* dwCallBackResult
  141. );
  142. HRESULT ConstructFullPath
  143. (
  144. IN LPCWSTR pwszMetabasePathPrefix,
  145. IN DWORD dwcPrefix,
  146. IN LPCWSTR pwszPartialPath,
  147. OUT LPWSTR* ppwszResult
  148. );
  149. BOOL FAppPathAllowConfig
  150. (
  151. IN LPCWSTR wszMetabasePath
  152. );
  153. BOOL FIsW3SVCRoot
  154. (
  155. IN LPCWSTR wszMetabasePath
  156. );
  157. private:
  158. HRESULT GetNewSzGUID
  159. (
  160. OUT LPWSTR *ppszGUID
  161. );
  162. HRESULT GetViperPackageName
  163. (
  164. IN LPCWSTR wszMetabasePath,
  165. OUT LPWSTR* pwszViperPackageName
  166. );
  167. public:
  168. //Global Constant, self explained.
  169. static const WCHAR g_szIISInProcPackageName[/*sizeof(DEFAULT_PACKAGENAME)/sizeof(WCHAR)*/];
  170. static const WCHAR g_szIISInProcPackageID[];
  171. static const WCHAR g_szInProcWAMCLSID[];
  172. static const WCHAR g_szInProcWAMProgID[];
  173. static const WCHAR g_szIISOOPPoolPackageName[];
  174. static const WCHAR g_szIISOOPPoolPackageID[];
  175. static const WCHAR g_szOOPPoolWAMCLSID[];
  176. static const WCHAR g_szOOPPoolWAMProgID[];
  177. static const WCHAR g_szMDAppPathPrefix[];
  178. static const DWORD g_cchMDAppPathPrefix;
  179. static const WCHAR g_szMDW3SVCRoot[];
  180. static const DWORD g_cchMDW3SVCRoot;
  181. private:
  182. static WamAdmLock m_WamAdmLock; // a lock for all DCOM level requests.
  183. };
  184. inline VOID WamRegGlobal::AcquireAdmWriteLock(VOID)
  185. {
  186. m_WamAdmLock.AcquireWriteLock();
  187. }
  188. inline VOID WamRegGlobal::ReleaseAdmWriteLock(VOID)
  189. {
  190. m_WamAdmLock.ReleaseWriteLock();
  191. }
  192. //
  193. // WamRegRegistryConfig
  194. // Contains functions that access the Reigstry.
  195. //
  196. class WamRegRegistryConfig
  197. {
  198. public:
  199. WamRegRegistryConfig() {};
  200. ~WamRegRegistryConfig() {};
  201. HRESULT RegisterCLSID
  202. (
  203. IN LPCWSTR szCLSIDEntryIn,
  204. IN LPCWSTR szProgIDIn,
  205. IN BOOL fSetVIProgID
  206. );
  207. HRESULT UnRegisterCLSID
  208. (
  209. IN LPCWSTR wszCLSIDEntryIn,
  210. IN BOOL fDeleteVIProgID
  211. );
  212. HRESULT LoadWamDllPath(VOID);
  213. private:
  214. HRESULT UnRegisterProgID
  215. (
  216. IN LPCWSTR szProgIDIn
  217. );
  218. static const REGSAM samDesired;
  219. static CHAR m_szWamDllPath[MAX_PATH];
  220. };
  221. //
  222. // WamRegPackageConfig
  223. // Contains functions that access the MTS Admin API.
  224. // Class defined to access MTS Admin interface.
  225. //
  226. class WamRegPackageConfig
  227. {
  228. public:
  229. WamRegPackageConfig();
  230. ~WamRegPackageConfig();
  231. HRESULT CreateCatalog(VOID); //Create an MTS catalog object
  232. VOID Cleanup( VOID); // used for cleaning up state
  233. HRESULT CreatePackage
  234. (
  235. IN LPCWSTR szPackageID,
  236. IN LPCWSTR szPackageName,
  237. IN LPCWSTR szIdentity,
  238. IN LPCWSTR szIdPassword,
  239. IN BOOL fInProc
  240. );
  241. HRESULT RemovePackage
  242. (
  243. IN LPCWSTR szPackageID
  244. );
  245. HRESULT AddComponentToPackage
  246. (
  247. IN LPCWSTR szPackageID,
  248. IN LPCWSTR szComponentCLSID
  249. );
  250. HRESULT RemoveComponentFromPackage
  251. (
  252. IN LPCWSTR szPackageID,
  253. IN LPCWSTR szComponentCLSID,
  254. IN DWORD dwAppIsolated
  255. );
  256. BOOL IsPackageInstalled
  257. (
  258. IN LPCWSTR szPackageID,
  259. IN LPCWSTR szComponentCLSID
  260. );
  261. HRESULT GetSafeArrayOfCLSIDs // Create an one element SafeArray object that contains szComponentCLSID
  262. (
  263. IN LPCWSTR szComponentCLSID,
  264. OUT SAFEARRAY** pm_aCLSID
  265. );
  266. VOID ReleaseAll(VOID);
  267. private:
  268. enum TECatelogObject{eTPackage, eTComponent};
  269. HRESULT SetPackageProperties( IN LPCWSTR * rgpszValues);
  270. HRESULT SetPackageObjectProperty
  271. (
  272. IN LPCWSTR szPropertyName,
  273. IN LPCWSTR szPropertyValue
  274. );
  275. HRESULT SetComponentObjectProperties(
  276. IN LPCWSTR szComponentCLSID
  277. );
  278. HRESULT SetComponentObjectProperty
  279. (
  280. IN ICatalogObject * pComponent,
  281. IN LPCWSTR szPropertyName,
  282. IN LPCWSTR szPropertyValue,
  283. BOOL fPropertyValue = FALSE
  284. );
  285. ICOMAdminCatalog* m_pCatalog;
  286. ICatalogCollection* m_pPkgCollection;
  287. ICatalogCollection* m_pCompCollection;
  288. ICatalogObject* m_pPackage;
  289. };
  290. //
  291. // WamRegMetabaseConfig
  292. // Class defined to access the metabase, read/write application properties from/to Metabase.
  293. //
  294. class WamRegMetabaseConfig
  295. {
  296. public:
  297. static HRESULT MetabaseInit
  298. (
  299. VOID
  300. );
  301. static HRESULT MetabaseUnInit
  302. (
  303. VOID
  304. );
  305. static BOOL Initialized( VOID )
  306. {
  307. return ( m_pMetabase != NULL );
  308. }
  309. HRESULT UpdateMD
  310. (
  311. IN MDPropItem* prgProp,
  312. IN DWORD dwMDAttributes,
  313. IN LPCWSTR wszMetabasePath,
  314. IN BOOL fSaveData = FALSE
  315. );
  316. HRESULT MDUpdateIISDefault
  317. (
  318. IN LPCWSTR szIISPackageName,
  319. IN LPCWSTR szIISPackageID,
  320. IN LPCWSTR szDefaultWAMCLSID
  321. );
  322. HRESULT AbortUpdateMD
  323. (
  324. IN MDPropItem* prgProp,
  325. IN LPCWSTR wszMetabasePath
  326. );
  327. HRESULT MDCreatePath
  328. (
  329. IN IMSAdminBase *pMetabaseIn,
  330. IN LPCWSTR szMetabasePath
  331. );
  332. BOOL MDDoesPathExist
  333. (
  334. IN IMSAdminBase *pMetabaseIn,
  335. IN LPCWSTR szMetabasePath
  336. );
  337. HRESULT MDSetStringProperty
  338. (
  339. IN IMSAdminBase * pMetabaseIn,
  340. IN LPCWSTR szMetabasePath,
  341. IN DWORD szMetabaseProperty,
  342. IN LPCWSTR szMetabaseValue,
  343. IN DWORD dwMDUserType = IIS_MD_UT_WAM
  344. );
  345. HRESULT MDSetKeyType
  346. (
  347. IN IMSAdminBase * pMetabaseIn,
  348. IN LPCWSTR szMetabasePath,
  349. IN LPCWSTR szKeyType
  350. );
  351. HRESULT MDDeleteKey
  352. (
  353. IN IMSAdminBase * pMetabaseIn,
  354. IN LPCWSTR szMetabasePath,
  355. IN LPCWSTR szKey
  356. );
  357. HRESULT MDGetDWORD
  358. (
  359. IN LPCWSTR szMetabasePath,
  360. IN DWORD dwMDIdentifier,
  361. OUT DWORD *pdwData
  362. );
  363. HRESULT MDSetAppState
  364. (
  365. IN LPCWSTR szMetabasePath,
  366. IN DWORD dwState
  367. );
  368. HRESULT MDGetPropPaths
  369. (
  370. IN LPCWSTR szMetabasePath,
  371. IN DWORD dwMDIdentifier,
  372. OUT WCHAR** pBuffer,
  373. OUT DWORD* pdwBufferSize
  374. );
  375. HRESULT MDGetWAMCLSID
  376. (
  377. IN LPCWSTR szMetabasePath,
  378. IN OUT LPWSTR szWAMCLSID
  379. );
  380. HRESULT MDGetIdentity
  381. (
  382. IN LPWSTR szIdentity,
  383. IN DWORD cbIdentity,
  384. IN LPWSTR szPwd,
  385. IN DWORD cbPwd
  386. );
  387. HRESULT MDGetAppName
  388. (
  389. IN LPCWSTR szMetaPath,
  390. OUT LPWSTR * ppszAppName
  391. );
  392. HRESULT MDGetStringAttribute
  393. (
  394. IN LPCWSTR szMetaPath,
  395. DWORD dwMDIdentifier,
  396. OUT LPWSTR * ppszBuffer
  397. );
  398. HRESULT MDGetAllSiteRoots
  399. (
  400. OUT LPWSTR * ppszBuffer
  401. );
  402. HRESULT GetSignatureOnPath
  403. (
  404. IN LPCWSTR pwszMetabasePath,
  405. OUT DWORD* pdwSignature
  406. );
  407. HRESULT GetWebServerName
  408. (
  409. IN LPCWSTR wszMetabasePath,
  410. IN OUT LPWSTR wszWebServerName,
  411. IN UINT cBuffer
  412. );
  413. HRESULT SaveData
  414. (
  415. VOID
  416. );
  417. HRESULT MDGetLastOutProcPackageID
  418. (
  419. IN LPCWSTR szMetabasePath,
  420. IN OUT LPWSTR szLastOutProcPackageID
  421. );
  422. HRESULT MDRemoveProperty
  423. (
  424. IN LPCWSTR pwszMetabasePath,
  425. DWORD dwIdentifier,
  426. DWORD dwType
  427. );
  428. HRESULT MDRemovePropertyByArray
  429. (
  430. IN MDPropItem* prgProp
  431. );
  432. VOID InitPropItemData
  433. (
  434. IN OUT MDPropItem* pMDPropItem
  435. );
  436. HRESULT MDGetIDs
  437. (
  438. IN LPCWSTR szMetabasePath,
  439. OUT LPWSTR szWAMCLSID,
  440. OUT LPWSTR szPackageID,
  441. IN DWORD dwAppMode
  442. );
  443. VOID MDSetPropItem
  444. (
  445. IN MDPropItem* prgProps,
  446. IN DWORD iIndex,
  447. IN LPCWSTR pwstrVal
  448. );
  449. VOID MDSetPropItem
  450. (
  451. IN MDPropItem* prgProps,
  452. IN DWORD iIndex,
  453. IN DWORD dwVal
  454. );
  455. VOID MDDeletePropItem
  456. (
  457. IN MDPropItem* prgProps,
  458. IN DWORD iIndex
  459. );
  460. BOOL HasAdminAccess
  461. (
  462. VOID
  463. );
  464. private:
  465. DWORD WamRegChkSum
  466. (
  467. IN LPCWSTR pszKey,
  468. IN DWORD cchKey
  469. );
  470. // Time out for metabase = 5 seconds
  471. static const DWORD m_dwMDDefaultTimeOut;
  472. static const MDPropItem m_rgMDPropTemplate[];
  473. //
  474. // The global metabase pointer,
  475. // created at the WAMREG start up time,
  476. // deleted when WAMREG is shutdown.
  477. //
  478. static IMSAdminBaseW* m_pMetabase;
  479. };
  480. inline HRESULT WamRegMetabaseConfig::SaveData(VOID)
  481. {
  482. DBG_ASSERT(m_pMetabase);
  483. return m_pMetabase->SaveData();
  484. }
  485. inline VOID WamRegMetabaseConfig::MDSetPropItem
  486. (
  487. IN MDPropItem* prgProps,
  488. IN DWORD iIndex,
  489. IN LPCWSTR pwstrVal
  490. )
  491. {
  492. DBG_ASSERT(prgProps && iIndex < IWMDP_MAX);
  493. prgProps[iIndex].dwAction = EMD_SET;
  494. prgProps[iIndex].pwstrVal = (LPWSTR)pwstrVal;
  495. }
  496. inline VOID WamRegMetabaseConfig::MDSetPropItem
  497. (
  498. IN MDPropItem* prgProps,
  499. IN DWORD iIndex,
  500. IN DWORD dwVal
  501. )
  502. {
  503. DBG_ASSERT(prgProps && iIndex < IWMDP_MAX);
  504. prgProps[iIndex].dwAction = EMD_SET;
  505. prgProps[iIndex].dwVal = dwVal;
  506. }
  507. inline VOID WamRegMetabaseConfig::MDDeletePropItem
  508. (
  509. IN MDPropItem* prgProps,
  510. IN DWORD iIndex
  511. )
  512. {
  513. DBG_ASSERT(prgProps && iIndex < IWMDP_MAX);
  514. prgProps[iIndex].dwAction = EMD_DELETE;
  515. }
  516. extern WamRegGlobal g_WamRegGlobal;
  517. extern WamRegRegistryConfig g_RegistryConfig;
  518. #endif // _WAMREG_AUXFUNC_H