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.

742 lines
14 KiB

  1. /*++
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. w3server.h
  5. Abstract:
  6. Type definition for worker process implementation of IIS.
  7. Author:
  8. Taylor Weiss (TaylorW) 16-Dec-1999
  9. Revision History:
  10. At this point - the following features of the IIS5 code base are
  11. considered obsolete (ie never to be part of IIS+):
  12. 1. Service control manager goo
  13. 2. RPC administration support
  14. 3. Down-level admin support
  15. 4. Socket/Endpoint goo
  16. 5. Direct handling of site - start/stop/pause/etc
  17. 6. Password change support (ie. .htr hooks).
  18. --*/
  19. #ifndef _W3SERVER_H_
  20. #define _W3SERVER_H_
  21. /************************************************************
  22. * Include Headers
  23. ************************************************************/
  24. #include "mb_notify.h"
  25. /************************************************************
  26. * Type Definitions
  27. ************************************************************/
  28. #define W3_SERVER_MB_PATH L"/LM/W3SVC/"
  29. #define W3_SERVER_MB_PATH_CCH 10
  30. enum RESTRICTION_LIST_TYPE
  31. {
  32. IsapiRestrictionList,
  33. CgiRestrictionList
  34. };
  35. class W3_SITE;
  36. /*++
  37. class W3_SERVER
  38. Encapsulates global settings for an HTTP server run in
  39. a duct-tape worker process.
  40. Condenses the relevant functionality exposed in IIS
  41. through the IIS_SERVICE and W3_IIS_SERVICE.
  42. --*/
  43. #define W3_SERVER_SIGNATURE 'VRSW'
  44. #define W3_SERVER_FREE_SIGNATURE 'fRSW'
  45. /*++
  46. A simple referenced record to hold an image name
  47. --*/
  48. class W3_IMAGE_RECORD
  49. {
  50. public:
  51. W3_IMAGE_RECORD()
  52. : _cRefs( 1 )
  53. {
  54. }
  55. HRESULT
  56. Create(
  57. LPCWSTR pName,
  58. BOOL fIsAllowed
  59. )
  60. {
  61. _fIsAllowed = fIsAllowed;
  62. return strName.Copy( pName );
  63. }
  64. LPWSTR
  65. QueryName(
  66. VOID
  67. ) const
  68. {
  69. return (LPWSTR)strName.QueryStr();
  70. }
  71. BOOL
  72. QueryIsAllowed(
  73. VOID
  74. ) const
  75. {
  76. return _fIsAllowed;
  77. }
  78. VOID
  79. ReferenceImageRecord(
  80. VOID
  81. )
  82. {
  83. InterlockedIncrement( &_cRefs );
  84. }
  85. VOID
  86. DereferenceImageRecord(
  87. VOID
  88. )
  89. {
  90. DBG_ASSERT( _cRefs != 0 );
  91. if ( InterlockedDecrement( &_cRefs ) == 0 )
  92. {
  93. delete this;
  94. }
  95. }
  96. VOID
  97. SetAllowedFlag(
  98. BOOL fIsAllowed
  99. )
  100. {
  101. _fIsAllowed = fIsAllowed;
  102. }
  103. private:
  104. ~W3_IMAGE_RECORD()
  105. {
  106. }
  107. LONG _cRefs;
  108. STRU strName;
  109. BOOL _fIsAllowed;
  110. };
  111. /*++
  112. class W3_SITE_LIST
  113. The list of sites serviced by a W3_SERVER.
  114. --*/
  115. class W3_SITE_LIST :
  116. public CTypedHashTable<W3_SITE_LIST, W3_SITE, DWORD>
  117. {
  118. public:
  119. W3_SITE_LIST() :
  120. CTypedHashTable<W3_SITE_LIST, W3_SITE, DWORD>("W3_SITE_LIST")
  121. {}
  122. static DWORD
  123. ExtractKey(const W3_SITE *site);
  124. static DWORD
  125. CalcKeyHash(const DWORD key)
  126. {
  127. return key;
  128. }
  129. static bool
  130. EqualKeys(DWORD key1, DWORD key2)
  131. {
  132. return key1 == key2;
  133. }
  134. static VOID
  135. AddRefRecord(W3_SITE *site, int nIncr);
  136. private:
  137. W3_SITE_LIST(const W3_SITE_LIST &);
  138. void operator=(const W3_SITE_LIST &);
  139. };
  140. class W3_RESTRICTION_LIST :
  141. public CTypedHashTable<W3_RESTRICTION_LIST, W3_IMAGE_RECORD, LPCWSTR>
  142. {
  143. public:
  144. W3_RESTRICTION_LIST() :
  145. CTypedHashTable<W3_RESTRICTION_LIST, W3_IMAGE_RECORD, LPCWSTR>("W3_RESTRICTION_LIST")
  146. {
  147. _cRefs = 1;
  148. _fInitialized = FALSE;
  149. }
  150. static LPCWSTR
  151. ExtractKey(const W3_IMAGE_RECORD *pEntry)
  152. {
  153. return pEntry->QueryName();
  154. }
  155. static DWORD
  156. CalcKeyHash(LPCWSTR pszKey)
  157. {
  158. DWORD cchKey = (DWORD)wcslen(pszKey);
  159. return HashStringNoCase(pszKey, cchKey);
  160. }
  161. static bool
  162. EqualKeys(LPCWSTR pszKey1, LPCWSTR pszKey2)
  163. {
  164. return _wcsicmp( pszKey1, pszKey2 ) == 0;
  165. }
  166. static void
  167. AddRefRecord(W3_IMAGE_RECORD *pEntry, int nIncr)
  168. {
  169. if ( nIncr == +1 )
  170. {
  171. pEntry->ReferenceImageRecord();
  172. }
  173. else if ( nIncr == - 1)
  174. {
  175. pEntry->DereferenceImageRecord();
  176. }
  177. }
  178. HRESULT
  179. Create(MULTISZ * pmszList, RESTRICTION_LIST_TYPE ListType);
  180. VOID
  181. ReferenceRestrictionList()
  182. {
  183. DBG_ASSERT( _cRefs != 0 );
  184. InterlockedIncrement( &_cRefs );
  185. }
  186. VOID
  187. DereferenceRestrictionList()
  188. {
  189. DBG_ASSERT( _cRefs > 0 );
  190. if ( InterlockedDecrement( &_cRefs ) == 0 )
  191. {
  192. delete this;
  193. }
  194. }
  195. BOOL
  196. IsImageEnabled(LPCWSTR szImage);
  197. private:
  198. BOOL _fInitialized;
  199. BOOL _fAllowUnknown;
  200. LONG _cRefs;
  201. W3_RESTRICTION_LIST(const W3_RESTRICTION_LIST &);
  202. void operator=(const W3_RESTRICTION_LIST &);
  203. ~W3_RESTRICTION_LIST()
  204. {}
  205. };
  206. class W3_METADATA_CACHE;
  207. class W3_URL_INFO_CACHE;
  208. class UL_RESPONSE_CACHE;
  209. class DIGEST_CONTEXT_CACHE;
  210. class W3_SERVER
  211. {
  212. //
  213. // CODEWORK
  214. // Using friends to keep the public interface of this
  215. // class as clean as possible. It's pretty sleazy so
  216. // we definitely should undo if it isn't valuable.
  217. //
  218. friend class MB_LISTENER;
  219. public:
  220. W3_SERVER( BOOL fCompatibilityMode );
  221. ~W3_SERVER();
  222. HRESULT
  223. Initialize(
  224. INT argc,
  225. LPWSTR argv[]
  226. );
  227. VOID
  228. Terminate(
  229. HRESULT hrReason
  230. );
  231. HRESULT
  232. StartListen(
  233. VOID
  234. );
  235. IMSAdminBase *
  236. QueryMDObject(
  237. VOID
  238. ) const
  239. {
  240. // This is only valid if all are threads are CoInited
  241. // in the MTA
  242. return m_pMetaBase;
  243. }
  244. LPCWSTR
  245. QueryMDPath(
  246. VOID
  247. ) const
  248. {
  249. return W3_SERVER_MB_PATH;
  250. }
  251. TOKEN_CACHE *
  252. QueryTokenCache(
  253. VOID
  254. ) const
  255. {
  256. return m_pTokenCache;
  257. }
  258. DIGEST_CONTEXT_CACHE *
  259. QueryDigestContextCache(
  260. VOID
  261. ) const
  262. {
  263. return m_pDigestContextCache;
  264. }
  265. W3_FILE_INFO_CACHE *
  266. QueryFileCache(
  267. VOID
  268. ) const
  269. {
  270. return m_pFileCache;
  271. }
  272. W3_URL_INFO_CACHE *
  273. QueryUrlInfoCache(
  274. VOID
  275. ) const
  276. {
  277. return m_pUrlInfoCache;
  278. }
  279. W3_METADATA_CACHE *
  280. QueryMetaCache(
  281. VOID
  282. ) const
  283. {
  284. return m_pMetaCache;
  285. }
  286. UL_RESPONSE_CACHE *
  287. QueryUlCache(
  288. VOID
  289. ) const
  290. {
  291. return m_pUlCache;
  292. }
  293. DWORD
  294. QuerySystemChangeNumber(
  295. VOID
  296. ) const
  297. {
  298. return m_dwSystemChangeNumber;
  299. }
  300. W3_SITE *
  301. FindSite(
  302. IN DWORD dwInstance
  303. );
  304. BOOL
  305. AddSite(
  306. IN W3_SITE * pInstance,
  307. IN bool fOverWrite = false
  308. );
  309. BOOL
  310. RemoveSite(
  311. IN W3_SITE * pInstance
  312. );
  313. VOID
  314. DestroyAllSites(
  315. VOID
  316. );
  317. VOID WriteLockSiteList()
  318. {
  319. m_pSiteList->WriteLock();
  320. }
  321. VOID WriteUnlockSiteList()
  322. {
  323. m_pSiteList->WriteUnlock();
  324. }
  325. HRESULT CollectCounters(
  326. PBYTE * ppCounterData,
  327. DWORD * pdwCounterData
  328. );
  329. HRESULT
  330. LoadString(
  331. DWORD dwStringID,
  332. CHAR * pszString,
  333. DWORD * pcbString
  334. );
  335. VOID
  336. GetCacheStatistics(
  337. IISWPGlobalCounters * pCacheCtrs
  338. );
  339. BOOL
  340. QueryInBackwardCompatibilityMode(
  341. VOID
  342. )
  343. {
  344. return m_fInBackwardCompatibilityMode;
  345. }
  346. HRESULT
  347. ReadUseDigestSSP(
  348. VOID
  349. );
  350. BOOL
  351. QueryUseDigestSSP(
  352. VOID
  353. )
  354. {
  355. return m_fUseDigestSSP;
  356. }
  357. BOOL
  358. QueryDoCentralBinaryLogging(
  359. VOID
  360. )
  361. {
  362. return m_fDoCentralBinaryLogging;
  363. }
  364. CHAR *
  365. QueryComputerName(
  366. VOID
  367. )
  368. {
  369. return m_pszComputerName;
  370. }
  371. USHORT
  372. QueryComputerNameLength(
  373. VOID
  374. )
  375. {
  376. return m_cchComputerName;
  377. }
  378. BOOL
  379. QueryIsCommandLineLaunch(
  380. VOID
  381. )
  382. {
  383. return m_fIsCommandLineLaunch;
  384. }
  385. BOOL
  386. QueryIsDavEnabled(
  387. VOID
  388. ) const
  389. {
  390. return m_fDavEnabled;
  391. }
  392. BOOL
  393. QueryIsTraceEnabled(
  394. VOID
  395. ) const
  396. {
  397. return m_fTraceEnabled;
  398. }
  399. void LogEvent(IN DWORD idMessage,
  400. IN WORD cSubStrings,
  401. IN const WCHAR *apszSubStrings[],
  402. IN DWORD errCode = 0)
  403. {
  404. m_EventLog.LogEvent(idMessage,
  405. cSubStrings,
  406. apszSubStrings,
  407. errCode);
  408. }
  409. static
  410. VOID
  411. OnShutdown(
  412. BOOL fDoImmediate
  413. );
  414. static
  415. VOID
  416. FlushUlResponses(
  417. MULTISZ * pmszUrls
  418. );
  419. BOOL
  420. QueryIsIsapiImageEnabled(
  421. LPCWSTR szImage
  422. );
  423. BOOL
  424. QueryIsCgiImageEnabled(
  425. LPCWSTR szImage
  426. );
  427. private:
  428. //
  429. // Metabase change handlers
  430. //
  431. HRESULT
  432. MetabaseChangeNotification(
  433. DWORD dwMDNumElements,
  434. MD_CHANGE_OBJECT pcoChangeList[]
  435. );
  436. HRESULT
  437. HandleMetabaseChange(
  438. const MD_CHANGE_OBJECT & ChangeObject
  439. );
  440. HRESULT
  441. InitializeRestrictionList(
  442. RESTRICTION_LIST_TYPE ListType
  443. );
  444. W3_RESTRICTION_LIST *
  445. CreateRestrictionList(
  446. MULTISZ * pmszImageList,
  447. RESTRICTION_LIST_TYPE ListType
  448. );
  449. HRESULT
  450. InitializeCaches(
  451. VOID
  452. );
  453. VOID
  454. TerminateCaches(
  455. VOID
  456. );
  457. //
  458. // Internal Types
  459. //
  460. enum INIT_STATUS {
  461. INIT_NONE,
  462. INIT_SHUTDOWN_EVENT,
  463. INIT_IISUTIL,
  464. INIT_WINSOCK,
  465. INIT_METABASE,
  466. INIT_MB_LISTENER,
  467. INIT_W3_SITE,
  468. INIT_ULATQ,
  469. INIT_SITE_LIST,
  470. INIT_FILTERS,
  471. INIT_CACHES,
  472. INIT_W3_CONNECTION,
  473. INIT_W3_CONTEXT,
  474. INIT_W3_REQUEST,
  475. INIT_W3_RESPONSE,
  476. INIT_SERVER_VARIABLES,
  477. INIT_MIME_MAP,
  478. INIT_LOGGING,
  479. INIT_RAW_CONNECTION,
  480. INIT_CERTIFICATE_CONTEXT,
  481. INIT_HTTP_COMPRESSION,
  482. INIT_ISAPI_RESTRICTION_LIST,
  483. INIT_CGI_RESTRICTION_LIST,
  484. INIT_SERVER
  485. };
  486. DWORD m_Signature;
  487. //
  488. // How far have we initialized?
  489. //
  490. INIT_STATUS m_InitStatus;
  491. //
  492. // All important pointer to ABO
  493. //
  494. IMSAdminBase * m_pMetaBase;
  495. //
  496. // Site list
  497. //
  498. W3_SITE_LIST * m_pSiteList;
  499. //
  500. // Site info used for optimization when only one site is on the list
  501. // Issue 08/28/2001 jaroslad: one site optimization should eventually be
  502. // integrated with LKR hash that could optimize for empty tables
  503. // and tables with one item
  504. //
  505. W3_SITE * m_pOneSite;
  506. //
  507. // Synchronize access to m_pOneSite (refcounted object)
  508. //
  509. CReaderWriterLock2 m_OneSiteLock;
  510. //
  511. // Metabase change nofication object
  512. //
  513. MB_LISTENER * m_pMetabaseListener;
  514. //
  515. // event log
  516. //
  517. EVENT_LOG m_EventLog;
  518. //
  519. // Are we in backward compatibility mode?
  520. //
  521. BOOL m_fInBackwardCompatibilityMode;
  522. //
  523. // Do we use new Digest SSP?
  524. //
  525. BOOL m_fUseDigestSSP;
  526. //
  527. // Do we log into the central binary log?
  528. //
  529. BOOL m_fDoCentralBinaryLogging;
  530. //
  531. // Number of current sites
  532. //
  533. DWORD m_cSites;
  534. //
  535. // Handle to the resource DLL containing response strings
  536. //
  537. HMODULE m_hResourceDll;
  538. //
  539. // The buffer used to put in all the site and global counters in to
  540. // pass to WAS
  541. //
  542. PBYTE m_pCounterDataBuffer;
  543. DWORD m_dwCounterDataBuffer;
  544. //
  545. // The server's name
  546. //
  547. CHAR m_pszComputerName[MAX_COMPUTERNAME_LENGTH + 1];
  548. USHORT m_cchComputerName;
  549. //
  550. // All our caches
  551. //
  552. TOKEN_CACHE * m_pTokenCache;
  553. DIGEST_CONTEXT_CACHE * m_pDigestContextCache;
  554. W3_FILE_INFO_CACHE * m_pFileCache;
  555. W3_METADATA_CACHE * m_pMetaCache;
  556. W3_URL_INFO_CACHE * m_pUrlInfoCache;
  557. UL_RESPONSE_CACHE * m_pUlCache;
  558. //
  559. // :-( System change number. Tie it to sink for perf reasons
  560. //
  561. DWORD m_dwSystemChangeNumber;
  562. //
  563. // Secure server - image enabled lists
  564. //
  565. W3_RESTRICTION_LIST * m_pIsapiRestrictionList;
  566. W3_RESTRICTION_LIST * m_pCgiRestrictionList;
  567. CReaderWriterLock3 m_IsapiRestrictionLock;
  568. CReaderWriterLock3 m_CgiRestrictionLock;
  569. //
  570. // Remember if DAV is enabled or not
  571. //
  572. BOOL m_fDavEnabled;
  573. //
  574. // Were we command line launched?
  575. //
  576. BOOL m_fIsCommandLineLaunch;
  577. //
  578. // Is TRACE enabled?
  579. //
  580. BOOL m_fTraceEnabled;
  581. };
  582. extern W3_SERVER * g_pW3Server;
  583. #endif // _W3SERVER_H_