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.

619 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. );
  240. HRESULT RemovePackage
  241. (
  242. IN LPCWSTR szPackageID
  243. );
  244. HRESULT AddComponentToPackage
  245. (
  246. IN LPCWSTR szPackageID,
  247. IN LPCWSTR szComponentCLSID
  248. );
  249. HRESULT RemoveComponentFromPackage
  250. (
  251. IN LPCWSTR szPackageID,
  252. IN LPCWSTR szComponentCLSID,
  253. IN DWORD dwAppIsolated
  254. );
  255. BOOL IsPackageInstalled
  256. (
  257. IN LPCWSTR szPackageID,
  258. IN LPCWSTR szComponentCLSID
  259. );
  260. HRESULT GetSafeArrayOfCLSIDs // Create an one element SafeArray object that contains szComponentCLSID
  261. (
  262. IN LPCWSTR szComponentCLSID,
  263. OUT SAFEARRAY** pm_aCLSID
  264. );
  265. VOID ReleaseAll(VOID);
  266. private:
  267. enum TECatelogObject{eTPackage, eTComponent};
  268. HRESULT SetPackageProperties( IN LPCWSTR * rgpszValues);
  269. HRESULT SetPackageObjectProperty
  270. (
  271. IN LPCWSTR szPropertyName,
  272. IN LPCWSTR szPropertyValue
  273. );
  274. HRESULT SetComponentObjectProperties(
  275. IN LPCWSTR szComponentCLSID
  276. );
  277. HRESULT SetComponentObjectProperty
  278. (
  279. IN ICatalogObject * pComponent,
  280. IN LPCWSTR szPropertyName,
  281. IN LPCWSTR szPropertyValue,
  282. BOOL fPropertyValue = FALSE
  283. );
  284. ICOMAdminCatalog* m_pCatalog;
  285. ICatalogCollection* m_pPkgCollection;
  286. ICatalogCollection* m_pCompCollection;
  287. ICatalogObject* m_pPackage;
  288. };
  289. //
  290. // WamRegMetabaseConfig
  291. // Class defined to access the metabase, read/write application properties from/to Metabase.
  292. //
  293. class WamRegMetabaseConfig
  294. {
  295. public:
  296. static HRESULT MetabaseInit
  297. (
  298. VOID
  299. );
  300. static HRESULT MetabaseUnInit
  301. (
  302. VOID
  303. );
  304. static BOOL Initialized( VOID )
  305. {
  306. return ( m_pMetabase != NULL );
  307. }
  308. HRESULT UpdateMD
  309. (
  310. IN MDPropItem* prgProp,
  311. IN DWORD dwMDAttributes,
  312. IN LPCWSTR wszMetabasePath,
  313. IN BOOL fSaveData = FALSE
  314. );
  315. HRESULT MDUpdateIISDefault
  316. (
  317. );
  318. HRESULT MDCreatePath
  319. (
  320. IN IMSAdminBase *pMetabaseIn,
  321. IN LPCWSTR szMetabasePath
  322. );
  323. BOOL MDDoesPathExist
  324. (
  325. IN IMSAdminBase *pMetabaseIn,
  326. IN LPCWSTR szMetabasePath
  327. );
  328. HRESULT MDSetStringProperty
  329. (
  330. IN IMSAdminBase * pMetabaseIn,
  331. IN LPCWSTR szMetabasePath,
  332. IN DWORD szMetabaseProperty,
  333. IN LPCWSTR szMetabaseValue,
  334. IN DWORD dwMDUserType = IIS_MD_UT_WAM,
  335. IN DWORD dwMDAttributes = METADATA_NO_ATTRIBUTES
  336. );
  337. HRESULT MDSetKeyType
  338. (
  339. IN IMSAdminBase * pMetabaseIn,
  340. IN LPCWSTR szMetabasePath,
  341. IN LPCWSTR szKeyType
  342. );
  343. HRESULT MDDeleteKey
  344. (
  345. IN IMSAdminBase * pMetabaseIn,
  346. IN LPCWSTR szMetabasePath,
  347. IN LPCWSTR szKey
  348. );
  349. HRESULT MDGetDWORD
  350. (
  351. IN LPCWSTR szMetabasePath,
  352. IN DWORD dwMDIdentifier,
  353. OUT DWORD *pdwData
  354. );
  355. HRESULT MDSetAppState
  356. (
  357. IN LPCWSTR szMetabasePath,
  358. IN DWORD dwState
  359. );
  360. HRESULT MDGetPropPaths
  361. (
  362. IN LPCWSTR szMetabasePath,
  363. IN DWORD dwMDIdentifier,
  364. OUT WCHAR** pBuffer,
  365. OUT DWORD* pdwBufferSize
  366. );
  367. HRESULT MDGetWAMCLSID
  368. (
  369. IN LPCWSTR szMetabasePath,
  370. IN OUT LPWSTR szWAMCLSID
  371. );
  372. HRESULT MDGetIdentity
  373. (
  374. IN LPWSTR szIdentity,
  375. IN DWORD cbIdentity,
  376. IN LPWSTR szPwd,
  377. IN DWORD cbPwd
  378. );
  379. HRESULT MDGetAppName
  380. (
  381. IN LPCWSTR szMetaPath,
  382. OUT LPWSTR * ppszAppName
  383. );
  384. HRESULT MDGetStringAttribute
  385. (
  386. IN LPCWSTR szMetaPath,
  387. DWORD dwMDIdentifier,
  388. OUT LPWSTR * ppszBuffer
  389. );
  390. HRESULT MDGetAllSiteRoots
  391. (
  392. OUT LPWSTR * ppszBuffer
  393. );
  394. HRESULT GetSignatureOnPath
  395. (
  396. IN LPCWSTR pwszMetabasePath,
  397. OUT DWORD* pdwSignature
  398. );
  399. HRESULT GetWebServerName
  400. (
  401. IN LPCWSTR wszMetabasePath,
  402. IN OUT LPWSTR wszWebServerName,
  403. IN UINT cBuffer
  404. );
  405. HRESULT SaveData
  406. (
  407. VOID
  408. );
  409. HRESULT MDGetLastOutProcPackageID
  410. (
  411. IN LPCWSTR szMetabasePath,
  412. IN OUT LPWSTR szLastOutProcPackageID
  413. );
  414. HRESULT MDRemoveProperty
  415. (
  416. IN LPCWSTR pwszMetabasePath,
  417. DWORD dwIdentifier,
  418. DWORD dwType
  419. );
  420. HRESULT MDRemovePropertyByArray
  421. (
  422. IN MDPropItem* prgProp
  423. );
  424. VOID InitPropItemData
  425. (
  426. IN OUT MDPropItem* pMDPropItem
  427. );
  428. HRESULT MDGetIDs
  429. (
  430. IN LPCWSTR szMetabasePath,
  431. OUT LPWSTR szWAMCLSID,
  432. OUT LPWSTR szPackageID,
  433. IN DWORD dwAppMode
  434. );
  435. VOID MDSetPropItem
  436. (
  437. IN MDPropItem* prgProps,
  438. IN DWORD iIndex,
  439. IN LPCWSTR pwstrVal
  440. );
  441. VOID MDSetPropItem
  442. (
  443. IN MDPropItem* prgProps,
  444. IN DWORD iIndex,
  445. IN DWORD dwVal
  446. );
  447. VOID MDDeletePropItem
  448. (
  449. IN MDPropItem* prgProps,
  450. IN DWORD iIndex
  451. );
  452. BOOL HasAdminAccess
  453. (
  454. VOID
  455. );
  456. private:
  457. DWORD WamRegChkSum
  458. (
  459. IN LPCWSTR pszKey,
  460. IN DWORD cchKey
  461. );
  462. // Time out for metabase = 5 seconds
  463. static const DWORD m_dwMDDefaultTimeOut;
  464. static const MDPropItem m_rgMDPropTemplate[];
  465. //
  466. // The global metabase pointer,
  467. // created at the WAMREG start up time,
  468. // deleted when WAMREG is shutdown.
  469. //
  470. static IMSAdminBaseW* m_pMetabase;
  471. };
  472. inline HRESULT WamRegMetabaseConfig::SaveData(VOID)
  473. {
  474. DBG_ASSERT(m_pMetabase);
  475. return m_pMetabase->SaveData();
  476. }
  477. inline VOID WamRegMetabaseConfig::MDSetPropItem
  478. (
  479. IN MDPropItem* prgProps,
  480. IN DWORD iIndex,
  481. IN LPCWSTR pwstrVal
  482. )
  483. {
  484. DBG_ASSERT(prgProps && iIndex < IWMDP_MAX);
  485. prgProps[iIndex].dwAction = EMD_SET;
  486. prgProps[iIndex].pwstrVal = (LPWSTR)pwstrVal;
  487. }
  488. inline VOID WamRegMetabaseConfig::MDSetPropItem
  489. (
  490. IN MDPropItem* prgProps,
  491. IN DWORD iIndex,
  492. IN DWORD dwVal
  493. )
  494. {
  495. DBG_ASSERT(prgProps && iIndex < IWMDP_MAX);
  496. prgProps[iIndex].dwAction = EMD_SET;
  497. prgProps[iIndex].dwVal = dwVal;
  498. }
  499. inline VOID WamRegMetabaseConfig::MDDeletePropItem
  500. (
  501. IN MDPropItem* prgProps,
  502. IN DWORD iIndex
  503. )
  504. {
  505. DBG_ASSERT(prgProps && iIndex < IWMDP_MAX);
  506. prgProps[iIndex].dwAction = EMD_DELETE;
  507. }
  508. extern WamRegGlobal g_WamRegGlobal;
  509. extern WamRegRegistryConfig g_RegistryConfig;
  510. #endif // _WAMREG_AUXFUNC_H