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.

775 lines
18 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name :
  4. w3inst.hxx
  5. Abstract:
  6. This file contains type definitions for multiple instance
  7. support.
  8. Author:
  9. Johnson Apacible (JohnsonA) Jun-04-1996
  10. Revision History:
  11. --*/
  12. #ifndef _W3INST_H_
  13. #define _W3INST_H_
  14. #include <iiscert.hxx>
  15. #include <iisctl.hxx>
  16. #include <capiutil.hxx>
  17. #include <certnotf.hxx>
  18. #include <sslinfo.hxx>
  19. #include <lkrhash.h>
  20. #include "iistypes.hxx"
  21. class W3_ENDPOINT;
  22. class FILTER_LIST;
  23. //
  24. // The maximum number of SSPI providers we'll return to clients
  25. //
  26. #define MAX_SSPI_PROVIDERS 5
  27. //
  28. // Returns pointer to the global filter list
  29. //
  30. #define GLOBAL_FILTER_LIST() (((W3_IIS_SERVICE *)g_pInetSvc)->QueryGlobalFilterList())
  31. //
  32. // This is the W3 version of the IIS_SERVER
  33. //
  34. //
  35. // Mapper type we support
  36. //
  37. enum MAPPER_TYPE {
  38. MT_MD5,
  39. MT_ITA,
  40. MT_CERT11,
  41. MT_CERTW,
  42. MT_LAST
  43. } ;
  44. extern LPVOID g_pMappers[MT_LAST];
  45. extern PFN_SF_NOTIFY g_pSslKeysNotify;
  46. class W3_IIS_SERVICE : public IIS_SERVICE {
  47. public:
  48. //
  49. // Virtuals
  50. //
  51. virtual BOOL AddInstanceInfo(
  52. IN DWORD dwInstance,
  53. IN BOOL fMigrateRoots
  54. );
  55. virtual DWORD DisconnectUsersByInstance(
  56. IN IIS_SERVER_INSTANCE * pInstance
  57. );
  58. virtual VOID StopInstanceProcs(
  59. IN IIS_SERVER_INSTANCE * pInstance
  60. );
  61. virtual DWORD GetServiceConfigInfoSize(IN DWORD dwLevel);
  62. W3_IIS_SERVICE(
  63. IN LPCTSTR lpszServiceName,
  64. IN LPCSTR lpszModuleName,
  65. IN LPCSTR lpszRegParamKey,
  66. IN DWORD dwServiceId,
  67. IN ULONGLONG SvcLocId,
  68. IN BOOL MultipleInstanceSupport,
  69. IN DWORD cbAcceptExRecvBuffer,
  70. IN ATQ_CONNECT_CALLBACK pfnConnect,
  71. IN ATQ_COMPLETION pfnConnectEx,
  72. IN ATQ_COMPLETION pfnIoCompletion
  73. );
  74. FILTER_LIST * QueryGlobalFilterList( VOID ) const
  75. { return m_pGlobalFilterList; }
  76. W3_SERVER_STATISTICS* QueryGlobalStatistics()
  77. { return &m_GlobalStats; }
  78. BOOL
  79. GetGlobalStatistics(
  80. IN DWORD dwLevel,
  81. OUT PCHAR *pBuffer
  82. );
  83. BOOL AggregateStatistics(
  84. IN PCHAR pDestination,
  85. IN PCHAR pSource
  86. );
  87. BOOL ReadInProcISAPIList( VOID );
  88. #if defined(CAL_ENABLED)
  89. DWORD QueryCalVcPerLicense() const
  90. { return m_CalVcPerLicense; }
  91. DWORD QueryCalW3Error() const
  92. { return m_CalW3Error; }
  93. DWORD QueryCalAuthReserveTimeout() const
  94. { return m_CalAuthReserveTimeout; }
  95. DWORD QueryCalSslReserveTimeout() const
  96. { return m_CalSslReserveTimeout; }
  97. DWORD QueryCalMode() const
  98. { return m_CalMode; }
  99. #endif
  100. const CHAR * QueryInProcISAPI( DWORD i ) const
  101. { return (m_astrInProcISAPI ? m_astrInProcISAPI[i].QueryStr() : NULL); }
  102. const BOOL QueryIsISAPIDllName( DWORD i ) const
  103. { return (m_afISAPIDllName? m_afISAPIDllName[i] : FALSE); }
  104. DWORD QueryInProcISAPICount( VOID ) const
  105. { return m_cInProcISAPI; }
  106. BOOL FDavDll() const
  107. { return m_hinstDav != NULL; }
  108. CHAR *SzDavDllGet() const
  109. { return m_strDav.QueryStr(); }
  110. LONG GetReferenceCount() const
  111. { return m_cReferences; };
  112. static APIERR ReferenceW3Service( PVOID pService );
  113. static APIERR DereferenceW3Service( PVOID pService );
  114. protected:
  115. virtual ~W3_IIS_SERVICE();
  116. virtual VOID MDChangeNotify( MD_CHANGE_OBJECT * pco );
  117. VOID GetDavDll();
  118. private:
  119. FILTER_LIST * m_pGlobalFilterList;
  120. W3_SERVER_STATISTICS m_GlobalStats;
  121. #if defined(CAL_ENABLED)
  122. DWORD m_CalVcPerLicense;
  123. DWORD m_CalW3Error;
  124. DWORD m_CalAuthReserveTimeout;
  125. DWORD m_CalSslReserveTimeout;
  126. DWORD m_CalMode;
  127. #endif
  128. //
  129. // This is the list of fully qualified ISAPI dlls that
  130. // must be run in process
  131. //
  132. BOOL* m_afISAPIDllName;
  133. STR * m_astrInProcISAPI;
  134. DWORD m_cInProcISAPI;
  135. class CInProcISAPIs
  136. : public CTypedHashTable<CInProcISAPIs, const STR, const CHAR*>
  137. {
  138. public:
  139. static const CHAR* ExtractKey(const STR* pEntry)
  140. {
  141. return pEntry->QueryStr();
  142. }
  143. static DWORD CalcKeyHash(const CHAR* pszKey)
  144. {
  145. // use the last 16 chars of the pathname
  146. // this gives a good distribution
  147. int cchKey = lstrlen(pszKey);
  148. if (cchKey > 16)
  149. pszKey += cchKey - 16;
  150. return HashStringNoCase(pszKey, cchKey);
  151. }
  152. static bool EqualKeys(const CHAR* pszKey1, const CHAR* pszKey2)
  153. {
  154. return lstrcmpi(pszKey1, pszKey2) == 0;
  155. }
  156. static void AddRefRecord(const STR* pEntry, int nIncr)
  157. {}
  158. CInProcISAPIs()
  159. : CTypedHashTable<CInProcISAPIs, const STR, const CHAR*>(
  160. "CInProcISAPIs")
  161. {}
  162. };
  163. CInProcISAPIs m_InProcISAPItable;
  164. TS_RESOURCE m_InProcLock;
  165. public:
  166. BOOL IsInProcISAPI(LPCSTR pszImageName)
  167. {
  168. const STR* pStr;
  169. m_InProcLock.Lock( TSRES_LOCK_READ );
  170. BOOL fRet = LK_SUCCESS == m_InProcISAPItable.FindKey(pszImageName, &pStr);
  171. m_InProcLock.Unlock();
  172. return fRet;
  173. }
  174. private:
  175. //
  176. // Location of the DAV .dll.
  177. //
  178. STR m_strDav;
  179. HINSTANCE m_hinstDav; // NULL if no .dll
  180. //
  181. // Reference count for service.
  182. //
  183. LONG m_cReferences;
  184. };
  185. typedef W3_IIS_SERVICE *PW3_IIS_SERVICE;
  186. //
  187. // This is the W3 version of the instance. Will contain all the
  188. // W3 specific operations.
  189. //
  190. class W3_SERVER_INSTANCE : public IIS_SERVER_INSTANCE {
  191. private:
  192. VOID LogCertStatus();
  193. VOID LogCTLStatus();
  194. //
  195. // signature
  196. //
  197. DWORD m_signature;
  198. //
  199. // Should we use host name?
  200. //
  201. DWORD m_dwUseHostName;
  202. //
  203. // default name of distant host
  204. //
  205. PCHAR m_pszDefaultHostName;
  206. //
  207. // Support byte range?
  208. //
  209. BOOL m_fAcceptByteRanges;
  210. //
  211. // Logging
  212. //
  213. BOOL m_fLogErrors;
  214. BOOL m_fLogSuccess;
  215. //
  216. // TRUE to use host name to build redirection indication
  217. //
  218. BOOL m_fUseHostName;
  219. //
  220. // called to change pwd
  221. //
  222. STR m_strAuthChangeUrl;
  223. //
  224. // called on pwd expired
  225. //
  226. STR m_strAuthExpiredUrl;
  227. STR m_strAuthExpiredUnsecureUrl;
  228. DWORD m_dwAuthChangeFlags;
  229. //
  230. // called on advance notification for pwd expiration
  231. //
  232. STR m_strAdvNotPwdExpUrl;
  233. STR m_strAdvNotPwdExpUnsecureUrl;
  234. //
  235. // advance notification for pwd expiration in days
  236. //
  237. DWORD m_cAdvNotPwdExpInDays;
  238. #if 0
  239. //
  240. // How much should the server read of client Content-Length
  241. //
  242. DWORD m_cbUploadReadAhead;
  243. #endif
  244. //
  245. // LogonNetUser( LOGON32_LOGON_NETWORK ) workstation field usage
  246. //
  247. DWORD m_dwNetLogonWks;
  248. //
  249. // Pwd expiration advance notification cache TTL
  250. //
  251. DWORD m_dwAdvCacheTTL;
  252. //
  253. // Use Atq Pool thread for CGI IO
  254. //
  255. BOOL m_fUsePoolThreadForCGI;
  256. //
  257. // Are there any secure filters loaded?
  258. //
  259. BOOL m_fAnySecureFilters;
  260. //
  261. // Message to send when access is denied
  262. //
  263. PCHAR m_pszAccessDeniedMsg;
  264. //
  265. // List of filters this server instance requires
  266. //
  267. FILTER_LIST * m_pFilterList;
  268. LPVOID m_apMappers[MT_LAST];
  269. //
  270. // used to store statistics for W3 instance
  271. //
  272. LPW3_SERVER_STATISTICS m_pW3Stats;
  273. //
  274. // Enable using path following script mapping as path_info
  275. //
  276. BOOL m_fAllowPathInfoForScriptMappings;
  277. //
  278. // Enable processing of NTCR Authorization header if logged on
  279. //
  280. BOOL m_fProcessNtcrIfLoggedOn;
  281. //
  282. // Client certificate checking mode
  283. //
  284. DWORD m_dwCertCheckMode;
  285. BUFFER m_buSslCa;
  286. DWORD m_dwSslCa;
  287. //
  288. // Job Objects
  289. //
  290. DWORD m_dwJobResetInterval;
  291. DWORD m_dwJobIntervalSchedulerCookie;
  292. TS_RESOURCE m_tsJobLock;
  293. LONGLONG m_llJobResetIntervalCPU;
  294. DWORD m_dwJobQueryInterval;
  295. DWORD m_dwJobLoggingSchedulerCookie;
  296. BOOL m_fCPULoggingEnabled;
  297. BOOL m_fCPULimitsEnabled;
  298. DWORD m_dwJobCGICPULimit;
  299. DWORD m_dwJobLoggingOptions;
  300. PW3_JOB_OBJECT m_pwjoApplication;
  301. PW3_JOB_OBJECT m_pwjoCGI;
  302. DWORD m_dwLastJobState;
  303. //
  304. // LONGLONG limits are cpu time in units of 100 nanoseconds
  305. //
  306. LONGLONG m_llJobSiteCPULimitLogEvent;
  307. LONGLONG m_llJobSiteCPULimitPriority;
  308. LONGLONG m_llJobSiteCPULimitProcStop;
  309. LONGLONG m_llJobSiteCPULimitPause;
  310. BOOL m_fJobSiteCPULimitLogEventEnabled;
  311. BOOL m_fJobSiteCPULimitPriorityEnabled;
  312. BOOL m_fJobSiteCPULimitProcStopEnabled;
  313. BOOL m_fJobSiteCPULimitPauseEnabled;
  314. //
  315. // SSL info object
  316. //
  317. IIS_SSL_INFO *m_pSSLInfo;
  318. public:
  319. W3_SERVER_INSTANCE(
  320. IN PW3_IIS_SERVICE pService,
  321. IN DWORD dwInstanceId,
  322. IN USHORT Port,
  323. IN LPCSTR lpszRegParamKey,
  324. IN LPWSTR lpwszAnonPasswordSecretName,
  325. IN LPWSTR lpwszVirtualRootsSecretName,
  326. IN BOOL fMigrateRoots = FALSE
  327. );
  328. virtual ~W3_SERVER_INSTANCE( );
  329. //
  330. // Instance start & stop
  331. //
  332. virtual DWORD StartInstance();
  333. virtual DWORD StopInstance();
  334. //
  335. // read w3 parameters
  336. //
  337. BOOL ReadPrivateW3Params( );
  338. BOOL ReadMappers();
  339. //
  340. // read w3 parameters
  341. //
  342. BOOL ReadPublicW3Params( DWORD Fc );
  343. BOOL WritePublicW3Params(IN LPW3_CONFIG_INFO pConfig);
  344. APIERR InitializeHostName( VOID );
  345. APIERR InitializeDirBrowsing( VOID );
  346. VOID CleanupRegistryStrings(VOID);
  347. //
  348. // member variable wrappers
  349. //
  350. BOOL IsAcceptByteRanges( ) { return m_fAcceptByteRanges; }
  351. BOOL IsLogErrors( ) { return m_fLogErrors; }
  352. BOOL IsLogSuccess( ) { return m_fLogSuccess; }
  353. BOOL IsUsePoolThreadForCGI() { return m_fUsePoolThreadForCGI; }
  354. #if 0
  355. BOOL IsUseHostName( ) { return (BOOL)m_dwUseHostName; }
  356. #endif
  357. LPSTR QueryAccessDeniedMsg( ) { return m_pszAccessDeniedMsg; }
  358. LPSTR QueryDefaultHostName() { return m_pszDefaultHostName; }
  359. LPSTR QueryAuthChangeUrl( ) { return m_strAuthChangeUrl.IsEmpty() ? NULL : m_strAuthChangeUrl.QueryStr(); }
  360. LPSTR QueryAuthExpiredUrl( )
  361. {
  362. if ( m_dwAuthChangeFlags & MD_AUTH_CHANGE_DISABLE )
  363. {
  364. return NULL;
  365. }
  366. if ( m_dwAuthChangeFlags & MD_AUTH_CHANGE_UNSECURE )
  367. {
  368. return m_strAuthExpiredUnsecureUrl.IsEmpty() ? NULL : m_strAuthExpiredUnsecureUrl.QueryStr();
  369. }
  370. else
  371. {
  372. return m_strAuthExpiredUrl.IsEmpty() ? NULL : m_strAuthExpiredUrl.QueryStr();
  373. }
  374. }
  375. LPSTR QueryAdvNotPwdExpUrl( )
  376. {
  377. if ( m_dwAuthChangeFlags & MD_AUTH_ADVNOTIFY_DISABLE )
  378. {
  379. return NULL;
  380. }
  381. if ( m_dwAuthChangeFlags & MD_AUTH_CHANGE_UNSECURE )
  382. {
  383. return m_strAdvNotPwdExpUnsecureUrl.IsEmpty() ? NULL : m_strAdvNotPwdExpUnsecureUrl.QueryStr();
  384. }
  385. else
  386. {
  387. return m_strAdvNotPwdExpUrl.IsEmpty() ? NULL : m_strAdvNotPwdExpUrl.QueryStr();
  388. }
  389. }
  390. DWORD QueryAdvNotPwdExpInDays() { return m_cAdvNotPwdExpInDays; }
  391. #if 0
  392. DWORD QueryUploadReadAhead( ) { return m_cbUploadReadAhead; }
  393. #endif
  394. DWORD QueryNetLogonWks( ) { return m_dwNetLogonWks; }
  395. DWORD QueryAdvCacheTTL( ) { return m_dwAdvCacheTTL; }
  396. DWORD QueryEncCaps();
  397. DWORD QueryCertCheckMode() { return m_dwCertCheckMode; }
  398. BOOL IsSslCa( LPBYTE* pb, LPDWORD pdw)
  399. { if ( m_dwSslCa ) { *pdw = m_dwSslCa; *pb = (LPBYTE)m_buSslCa.QueryPtr(); return TRUE; } *pdw = NULL; *pb = 0; return FALSE; }
  400. BOOL QueryAllowPathInfoForScriptMappings() { return m_fAllowPathInfoForScriptMappings; }
  401. dllexp LPVOID QueryMapper( MAPPER_TYPE mt );
  402. BOOL ProcessNtcrIfLoggedOn() { return m_fProcessNtcrIfLoggedOn; }
  403. //
  404. // Keep track of Statistics counters for this instance
  405. //
  406. LPW3_SERVER_STATISTICS QueryStatsObj() { return m_pW3Stats; }
  407. //
  408. // Filter list management for this instance
  409. //
  410. BOOL CreateFilterList( VOID );
  411. FILTER_LIST * QueryFilterList( VOID ) const { DBG_ASSERT(m_cReadLocks);return m_pFilterList; }
  412. //
  413. // Job Object
  414. //
  415. //
  416. // Data access protection methods
  417. //
  418. dllexp VOID
  419. LockJobsForRead( VOID )
  420. {
  421. m_tsJobLock.Lock( TSRES_LOCK_READ );
  422. }
  423. dllexp VOID
  424. LockJobsForWrite( VOID )
  425. {
  426. m_tsJobLock.Lock( TSRES_LOCK_WRITE );
  427. }
  428. dllexp VOID
  429. UnlockJobs( VOID )
  430. {
  431. m_tsJobLock.Unlock( );
  432. }
  433. VOID SetCompletionPorts( VOID );
  434. DWORD SetCompletionPort(IN PW3_JOB_OBJECT pwjoCurrent);
  435. DWORD AddProcessToJob(IN HANDLE hProcess, IN BOOL bIsApplicationProcess);
  436. VOID GetPercentFromCPUTime(IN LONGLONG llCPUTime,
  437. OUT LPSTR pszPercentCPUTime);
  438. VOID LogJobInfo(IN PJOBOBJECT_BASIC_ACCOUNTING_INFORMATION pjbaiLogInfo,
  439. IN JOB_OBJECT_LOG_EVENTS joleLogEvent,
  440. IN JOB_OBJECT_PROCESS_TYPE joptProcessType);
  441. VOID LogJobsInfo( IN JOB_OBJECT_LOG_EVENTS joleLogEvent,
  442. IN JOBOBJECT_BASIC_ACCOUNTING_INFORMATION *pjobaiApplicationInfo,
  443. IN JOBOBJECT_BASIC_ACCOUNTING_INFORMATION *pjobaiCGIInfo,
  444. IN JOBOBJECT_BASIC_ACCOUNTING_INFORMATION *pjobaiSumInfo );
  445. VOID QueryAndLogJobInfo(IN JOB_OBJECT_LOG_EVENTS joleLogEvent,
  446. IN BOOL bResetCounters = FALSE);
  447. VOID ResetJobQueryInterval();
  448. VOID ResetJobResetInterval();
  449. VOID JobResetInterval();
  450. VOID TerminateCPUApplications(DWORD_PTR dwValue);
  451. VOID SetJobLimits(SET_LIMIT_ACTION slaAction,
  452. DWORD dwValue,
  453. LONGLONG llJobCPULimit = 0);
  454. LONGLONG GetCPUTimeFromInterval(DWORD dwInterval);
  455. BOOL IsLimitValid(LONGLONG llLimit);
  456. BOOL ScheduleJobDeferredProcessing();
  457. BOOL ScheduleJobDeferredReset();
  458. BOOL ScheduleJobDeferredLogging();
  459. BOOL QueryAndSumJobInfo(JOBOBJECT_BASIC_ACCOUNTING_INFORMATION *pjobaiSumInfo,
  460. JOBOBJECT_BASIC_ACCOUNTING_INFORMATION *pjobaiApplicationInfo,
  461. JOBOBJECT_BASIC_ACCOUNTING_INFORMATION *pjobaiCGIInfo,
  462. BOOL bResetCounters);
  463. VOID SetJobSiteCPULimits(BOOL fHasWriteLock);
  464. VOID LimitSiteCPU(BOOL fEnableLimits,
  465. BOOL fHasWriteLock);
  466. BOOL ExceededLimit(LONGLONG llCPULimit,
  467. JOBOBJECT_BASIC_ACCOUNTING_INFORMATION *pjobaiSumInfo);
  468. LONGLONG CalculateTimeUntilStop(LONGLONG llCPULimit,
  469. JOBOBJECT_BASIC_ACCOUNTING_INFORMATION *pjobaiSumInfo);
  470. LONGLONG CalculateNewJobLimit(LONGLONG llTimeToNextLimit,
  471. DWORD dwNumJobObjects);
  472. VOID StartJobs();
  473. VOID StopJobs();
  474. VOID ProcessStopNotification();
  475. VOID ProcessStartNotification();
  476. VOID ProcessPauseNotification();
  477. LONGLONG
  478. PercentCPULimitToCPUTime(DWORD dwLimitPercent);
  479. BOOL AreProcsCPUStopped() {return m_fJobSiteCPULimitProcStopEnabled;};
  480. BOOL IsSiteCPUPaused() {return m_fJobSiteCPULimitPauseEnabled;};
  481. //
  482. // Server-side SSL object
  483. //
  484. dllexp IIS_SSL_INFO* GetAndReferenceSSLInfoObj();
  485. dllexp static VOID ResetSSLInfo( LPVOID pvParam );
  486. //
  487. // VIRTUALS for service specific params/RPC admin
  488. //
  489. virtual BOOL SetServiceConfig(IN PCHAR pConfig );
  490. virtual BOOL GetServiceConfig(IN OUT PCHAR pConfig,IN DWORD dwLevel);
  491. virtual BOOL GetStatistics( IN DWORD dwLevel, OUT PCHAR *pBuffer);
  492. virtual BOOL ClearStatistics( );
  493. virtual BOOL DisconnectUser( IN DWORD dwIdUser );
  494. virtual BOOL EnumerateUsers( OUT PCHAR* pBuffer, OUT PDWORD nRead );
  495. virtual VOID MDChangeNotify( MD_CHANGE_OBJECT * pco );
  496. };
  497. typedef W3_SERVER_INSTANCE *PW3_SERVER_INSTANCE;
  498. /*++
  499. Routine Description:
  500. Get the total amount of CPU time in an interval.
  501. Arguments:
  502. dwInterval The interval length in minutes.
  503. Returns:
  504. The amount of CPU time per interval in 100 nanosecond units.
  505. --*/
  506. inline
  507. LONGLONG
  508. W3_SERVER_INSTANCE::GetCPUTimeFromInterval(DWORD dwInterval)
  509. {
  510. return ((LONGLONG)dwInterval *
  511. (LONGLONG)g_dwNumProcessors *
  512. (LONGLONG)MINUTESTO100NANOSECONDS);
  513. }
  514. /*++
  515. Routine Description:
  516. Determines if a limit is between 0 and the interval length.
  517. Arguments:
  518. llLimit The limit in 100 nanosecond units.
  519. Returns:
  520. TRUE if there is a valid limit.
  521. --*/
  522. inline
  523. BOOL
  524. W3_SERVER_INSTANCE::IsLimitValid(LONGLONG llLimit)
  525. {
  526. return ((llLimit > 0) &&
  527. (llLimit < m_llJobResetIntervalCPU));
  528. }
  529. //
  530. // signatures
  531. //
  532. #define W3_SERVER_INSTANCE_SIGNATURE (DWORD)' ISW'
  533. #define W3_SERVER_INSTANCE_SIGNATURE_FREE (DWORD)'fISW'
  534. //
  535. // externs
  536. //
  537. DWORD
  538. InitializeInstances(
  539. PW3_IIS_SERVICE pService
  540. );
  541. DWORD
  542. ActivateW3Endpoints(
  543. VOID
  544. );
  545. BOOL
  546. SetFlushMapperNotify(
  547. SF_NOTIFY_TYPE mt,
  548. PFN_SF_NOTIFY pFn
  549. );
  550. VOID NotifySslChangesWrapper( LPVOID pvParam );
  551. VOID ResetServerCertWrapper( LPVOID pvParam );
  552. BOOL
  553. SetSllKeysNotify(
  554. PFN_SF_NOTIFY pFn
  555. );
  556. #endif // _W3INST_H_