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.

1881 lines
45 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name :
  4. servervar.cxx
  5. Abstract:
  6. Server Variable evaluation goo
  7. Author:
  8. Bilal Alam (balam) 20-Feb-2000
  9. Environment:
  10. Win32 - User Mode
  11. Project:
  12. ULW3.DLL
  13. --*/
  14. #include "precomp.hxx"
  15. //
  16. // Hash table mapping variable name to a PFN_SERVER_VARIABLE_ROUTINE
  17. //
  18. SERVER_VARIABLE_HASH * SERVER_VARIABLE_HASH::sm_pRequestHash;
  19. SERVER_VARIABLE_RECORD SERVER_VARIABLE_HASH::sm_rgServerRoutines[] =
  20. {
  21. { "ALL_HTTP", GetServerVariableAllHttp, NULL },
  22. { "ALL_RAW", GetServerVariableAllRaw, NULL },
  23. { "APPL_MD_PATH", GetServerVariableApplMdPath, GetServerVariableApplMdPathW },
  24. { "APPL_PHYSICAL_PATH", GetServerVariableApplPhysicalPath, GetServerVariableApplPhysicalPathW },
  25. { "AUTH_PASSWORD", GetServerVariableAuthPassword, NULL },
  26. { "AUTH_TYPE", GetServerVariableAuthType, NULL },
  27. { "AUTH_USER", GetServerVariableRemoteUser, GetServerVariableRemoteUserW },
  28. { "CERT_COOKIE", GetServerVariableClientCertCookie, NULL },
  29. { "CERT_FLAGS", GetServerVariableClientCertFlags, NULL },
  30. { "CERT_ISSUER", GetServerVariableClientCertIssuer, NULL },
  31. { "CERT_KEYSIZE", GetServerVariableHttpsKeySize, NULL },
  32. { "CERT_SECRETKEYSIZE", GetServerVariableHttpsSecretKeySize, NULL },
  33. { "CERT_SERIALNUMBER", GetServerVariableClientCertSerialNumber, NULL },
  34. { "CERT_SERVER_ISSUER", GetServerVariableHttpsServerIssuer, NULL },
  35. { "CERT_SERVER_SUBJECT", GetServerVariableHttpsServerSubject, NULL },
  36. { "CERT_SUBJECT", GetServerVariableClientCertSubject, NULL },
  37. { "CONTENT_LENGTH", GetServerVariableContentLength, NULL },
  38. { "CONTENT_TYPE", GetServerVariableContentType, NULL },
  39. { "GATEWAY_INTERFACE", GetServerVariableGatewayInterface, NULL },
  40. { "LOGON_USER", GetServerVariableLogonUser, GetServerVariableLogonUserW },
  41. { "HTTPS", GetServerVariableHttps, NULL },
  42. { "HTTPS_KEYSIZE", GetServerVariableHttpsKeySize, NULL },
  43. { "HTTPS_SECRETKEYSIZE", GetServerVariableHttpsSecretKeySize, NULL },
  44. { "HTTPS_SERVER_ISSUER", GetServerVariableHttpsServerIssuer, NULL },
  45. { "HTTPS_SERVER_SUBJECT", GetServerVariableHttpsServerSubject, NULL },
  46. { "INSTANCE_ID", GetServerVariableInstanceId, NULL },
  47. { "INSTANCE_META_PATH", GetServerVariableInstanceMetaPath, NULL },
  48. { "PATH_INFO", GetServerVariablePathInfo, GetServerVariablePathInfoW },
  49. { "PATH_TRANSLATED", GetServerVariablePathTranslated, GetServerVariablePathTranslatedW },
  50. { "QUERY_STRING", GetServerVariableQueryString, NULL },
  51. { "REMOTE_ADDR", GetServerVariableRemoteAddr, NULL },
  52. { "REMOTE_HOST", GetServerVariableRemoteHost, NULL },
  53. { "REMOTE_USER", GetServerVariableRemoteUser, GetServerVariableRemoteUserW },
  54. { "REQUEST_METHOD", GetServerVariableRequestMethod, NULL },
  55. { "SCRIPT_NAME", GetServerVariableUrl, GetServerVariableUrlW },
  56. { "SERVER_NAME", GetServerVariableServerName, NULL },
  57. { "LOCAL_ADDR", GetServerVariableLocalAddr, NULL },
  58. { "SERVER_PORT", GetServerVariableServerPort, NULL },
  59. { "SERVER_PORT_SECURE", GetServerVariableServerPortSecure, NULL },
  60. { "SERVER_PROTOCOL", GetServerVariableHttpVersion, NULL },
  61. { "SERVER_SOFTWARE", GetServerVariableServerSoftware, NULL },
  62. { "UNMAPPED_REMOTE_USER", GetServerVariableRemoteUser, GetServerVariableRemoteUserW },
  63. { "URL", GetServerVariableUrl, GetServerVariableUrlW },
  64. { "HTTP_URL", GetServerVariableHttpUrl, NULL },
  65. { "HTTP_METHOD", GetServerVariableRequestMethod, NULL },
  66. { "HTTP_VERSION", GetServerVariableHttpVersion, NULL },
  67. { "APP_POOL_ID", GetServerVariableAppPoolId, GetServerVariableAppPoolIdW },
  68. { "SCRIPT_TRANSLATED", GetServerVariableScriptTranslated, GetServerVariableScriptTranslatedW },
  69. { "UNENCODED_URL", GetServerVariableUnencodedUrl, NULL },
  70. { NULL, NULL, NULL }
  71. };
  72. //static
  73. HRESULT
  74. SERVER_VARIABLE_HASH::Initialize(
  75. VOID
  76. )
  77. /*++
  78. Routine Description:
  79. Initialize global server variable hash table
  80. Arguments:
  81. None
  82. Return Value:
  83. HRESULT
  84. --*/
  85. {
  86. SERVER_VARIABLE_RECORD * pRecord;
  87. LK_RETCODE lkrc = LK_SUCCESS;
  88. sm_pRequestHash = new SERVER_VARIABLE_HASH;
  89. if ( sm_pRequestHash == NULL )
  90. {
  91. return HRESULT_FROM_WIN32( ERROR_NOT_ENOUGH_MEMORY );
  92. }
  93. //
  94. // Add every string->routine mapping
  95. //
  96. pRecord = sm_rgServerRoutines;
  97. while ( pRecord->_pszName != NULL )
  98. {
  99. lkrc = sm_pRequestHash->InsertRecord( pRecord );
  100. if ( lkrc != LK_SUCCESS )
  101. {
  102. break;
  103. }
  104. pRecord++;
  105. }
  106. //
  107. // If any insert failed, then fail initialization
  108. //
  109. if ( lkrc != LK_SUCCESS )
  110. {
  111. delete sm_pRequestHash;
  112. sm_pRequestHash = NULL;
  113. return HRESULT_FROM_WIN32( lkrc ); // ARGH
  114. }
  115. else
  116. {
  117. return NO_ERROR;
  118. }
  119. }
  120. //static
  121. VOID
  122. SERVER_VARIABLE_HASH::Terminate(
  123. VOID
  124. )
  125. /*++
  126. Routine Description:
  127. Cleanup global server variable hash table
  128. Arguments:
  129. None
  130. Return Value:
  131. None
  132. --*/
  133. {
  134. if ( sm_pRequestHash != NULL )
  135. {
  136. delete sm_pRequestHash;
  137. sm_pRequestHash = NULL;
  138. }
  139. }
  140. //static
  141. HRESULT
  142. SERVER_VARIABLE_HASH::GetServerVariableRoutine(
  143. CHAR * pszName,
  144. PFN_SERVER_VARIABLE_ROUTINE * ppfnRoutine,
  145. PFN_SERVER_VARIABLE_ROUTINE_W * ppfnRoutineW
  146. )
  147. /*++
  148. Routine Description:
  149. Lookup the hash table for a routine to evaluate the given variable
  150. Arguments:
  151. pszName - Name of server variable
  152. ppfnRoutine - Set to the routine if successful
  153. Return Value:
  154. HRESULT
  155. --*/
  156. {
  157. LK_RETCODE lkrc;
  158. SERVER_VARIABLE_RECORD* pServerVariableRecord = NULL;
  159. if ( pszName == NULL ||
  160. ppfnRoutine == NULL ||
  161. ppfnRoutineW == NULL )
  162. {
  163. DBG_ASSERT( FALSE );
  164. return HRESULT_FROM_WIN32( ERROR_INVALID_PARAMETER );
  165. }
  166. DBG_ASSERT( sm_pRequestHash != NULL );
  167. lkrc = sm_pRequestHash->FindKey( pszName,
  168. &pServerVariableRecord );
  169. if ( lkrc != LK_SUCCESS )
  170. {
  171. return HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND );
  172. }
  173. else
  174. {
  175. DBG_ASSERT( pServerVariableRecord != NULL );
  176. *ppfnRoutine = pServerVariableRecord->_pfnRoutine;
  177. *ppfnRoutineW = pServerVariableRecord->_pfnRoutineW;
  178. return NO_ERROR;
  179. }
  180. }
  181. //static
  182. HRESULT
  183. SERVER_VARIABLE_HASH::GetServerVariable(
  184. W3_CONTEXT * pW3Context,
  185. CHAR * pszVariableName,
  186. CHAR * pszBuffer,
  187. DWORD * pcbBuffer
  188. )
  189. /*++
  190. Routine Description:
  191. Get server variable
  192. Arguments:
  193. pW3Context - W3_CONTEXT with request state. Can be NULL if we are
  194. just determining whether the server variable requested is
  195. valid.
  196. pszVariable - Variable name to retrieve
  197. pszBuffer - Filled with variable on success
  198. pcbBuffer - On input, the size of input buffer. On out, the required size
  199. Return Value:
  200. HRESULT
  201. --*/
  202. {
  203. HRESULT hr;
  204. if (pszVariableName[0] == 'U' &&
  205. strncmp(pszVariableName, "UNICODE_", 8) == 0)
  206. {
  207. STACK_STRU (strValW, MAX_PATH);
  208. if (FAILED( hr = GetServerVariableW( pW3Context,
  209. pszVariableName + 8,
  210. &strValW ) ) ||
  211. FAILED( hr = strValW.CopyToBuffer( (LPWSTR)pszBuffer,
  212. pcbBuffer ) ) )
  213. {
  214. return hr;
  215. }
  216. }
  217. else
  218. {
  219. STACK_STRA (strVal, MAX_PATH);
  220. if (FAILED( hr = GetServerVariable( pW3Context,
  221. pszVariableName,
  222. &strVal ) ) ||
  223. FAILED( hr = strVal.CopyToBuffer( pszBuffer,
  224. pcbBuffer ) ) )
  225. {
  226. return hr;
  227. }
  228. }
  229. return S_OK;
  230. }
  231. //static
  232. HRESULT
  233. SERVER_VARIABLE_HASH::GetServerVariable(
  234. W3_CONTEXT * pW3Context,
  235. CHAR * pszVariableName,
  236. STRA * pstrVal
  237. )
  238. /*++
  239. Routine Description:
  240. Get server variable
  241. Arguments:
  242. pW3Context - W3_CONTEXT with request state. Can be NULL if we are
  243. just determining whether the server variable requested is
  244. valid. If NULL, we will return an empty string (and success)
  245. if the variable requested is valid.
  246. pszVariable - Variable name to retrieve
  247. pstrVal - Filled with variable on success
  248. Return Value:
  249. HRESULT
  250. --*/
  251. {
  252. HRESULT hr = S_OK;
  253. PFN_SERVER_VARIABLE_ROUTINE pfnRoutine = NULL;
  254. PFN_SERVER_VARIABLE_ROUTINE_W pfnRoutineW = NULL;
  255. //
  256. // First: Is this a server variable we know about? If so handle it
  257. // by calling the appropriate server variable routine
  258. //
  259. hr = SERVER_VARIABLE_HASH::GetServerVariableRoutine( pszVariableName,
  260. &pfnRoutine,
  261. &pfnRoutineW );
  262. if ( SUCCEEDED(hr) )
  263. {
  264. DBG_ASSERT( pfnRoutine != NULL );
  265. if ( pW3Context != NULL )
  266. {
  267. return pfnRoutine( pW3Context, pstrVal );
  268. }
  269. else
  270. {
  271. //
  272. // Just return empty string to signify that the variable is
  273. // valid but we just don't know the value at this time
  274. //
  275. return pstrVal->Copy( "", 0 );
  276. }
  277. }
  278. //
  279. // Second: Is this a header name (prefixed with HTTP_)
  280. //
  281. if ( pW3Context != NULL &&
  282. pszVariableName[ 0 ] == 'H' &&
  283. !strncmp( pszVariableName, "HTTP_" , 5 ) )
  284. {
  285. STACK_STRA( strVariable, 256 );
  286. hr = strVariable.Copy( pszVariableName + 5 );
  287. if ( FAILED( hr ) )
  288. {
  289. return hr;
  290. }
  291. // Change '_' to '-'
  292. PCHAR pszCursor = strchr( strVariable.QueryStr(), '_' );
  293. while ( pszCursor != NULL )
  294. {
  295. *pszCursor++ = '-';
  296. pszCursor = strchr( pszCursor, '_' );
  297. }
  298. return pW3Context->QueryRequest()->GetHeader( strVariable,
  299. pstrVal );
  300. }
  301. return HRESULT_FROM_WIN32( ERROR_INVALID_INDEX );
  302. }
  303. //static
  304. HRESULT
  305. SERVER_VARIABLE_HASH::GetServerVariableW(
  306. W3_CONTEXT * pW3Context,
  307. CHAR * pszVariableName,
  308. STRU * pstrVal
  309. )
  310. /*++
  311. Routine Description:
  312. Get server variable
  313. Arguments:
  314. pW3Context - W3_CONTEXT with request state. Can be NULL if we are
  315. just determining whether the server variable requested is
  316. valid. If NULL, we will return an empty string (and success)
  317. if the variable requested is valid.
  318. pszVariable - Variable name to retrieve
  319. pstrVal - Filled with variable on success
  320. Return Value:
  321. HRESULT
  322. --*/
  323. {
  324. HRESULT hr = S_OK;
  325. PFN_SERVER_VARIABLE_ROUTINE pfnRoutine = NULL;
  326. PFN_SERVER_VARIABLE_ROUTINE_W pfnRoutineW = NULL;
  327. hr = SERVER_VARIABLE_HASH::GetServerVariableRoutine( pszVariableName,
  328. &pfnRoutine,
  329. &pfnRoutineW );
  330. if ( SUCCEEDED(hr) )
  331. {
  332. if (pW3Context == NULL)
  333. {
  334. //
  335. // Just return empty string to signify that the variable is
  336. // valid but we just don't know the value at this time
  337. //
  338. return pstrVal->Copy( L"", 0 );
  339. }
  340. if (pfnRoutineW != NULL)
  341. {
  342. //
  343. // This server-variable contains real unicode data and there
  344. // is a unicode ServerVariable routine for this
  345. //
  346. return pfnRoutineW( pW3Context, pstrVal );
  347. }
  348. else
  349. {
  350. //
  351. // No unicode version, use the ANSI version and just wide'ize it
  352. //
  353. STACK_STRA( straVal, 256);
  354. DBG_ASSERT( pfnRoutine != NULL );
  355. if (FAILED(hr = pfnRoutine( pW3Context, &straVal )) ||
  356. FAILED(hr = pstrVal->CopyA( straVal.QueryStr(),
  357. straVal.QueryCCH() )))
  358. {
  359. return hr;
  360. }
  361. return S_OK;
  362. }
  363. }
  364. return HRESULT_FROM_WIN32( ERROR_INVALID_INDEX );
  365. }
  366. //
  367. // Server variable functions
  368. //
  369. HRESULT
  370. GetServerVariableQueryString(
  371. W3_CONTEXT *pW3Context,
  372. STRA *pstrVal
  373. )
  374. {
  375. DBG_ASSERT( pW3Context != NULL );
  376. return pW3Context->QueryRequest()->GetQueryStringA(pstrVal);
  377. }
  378. HRESULT
  379. GetServerVariableAllHttp(
  380. W3_CONTEXT *pW3Context,
  381. STRA *pstrVal
  382. )
  383. {
  384. DBG_ASSERT( pW3Context != NULL );
  385. return pW3Context->QueryRequest()->GetAllHeaders( pstrVal, TRUE );
  386. }
  387. HRESULT
  388. GetServerVariableAllRaw(
  389. W3_CONTEXT *pW3Context,
  390. STRA *pstrVal
  391. )
  392. {
  393. DBG_ASSERT( pW3Context != NULL );
  394. return pW3Context->QueryRequest()->GetAllHeaders( pstrVal, FALSE );
  395. }
  396. HRESULT
  397. GetServerVariableContentLength(
  398. W3_CONTEXT *pW3Context,
  399. STRA *pstrVal
  400. )
  401. {
  402. DBG_ASSERT( pW3Context != NULL );
  403. PCHAR pszContentLength;
  404. CHAR szMinusOne[33]; // Max documented size of _ultoa
  405. if ( pW3Context->QueryRequest()->IsChunkedRequest() )
  406. {
  407. _ultoa( (unsigned long) -1, szMinusOne, 10 );
  408. pszContentLength = szMinusOne;
  409. }
  410. else
  411. {
  412. pszContentLength = pW3Context->QueryRequest()->
  413. GetHeader( HttpHeaderContentLength );
  414. }
  415. if ( pszContentLength == NULL )
  416. {
  417. pszContentLength = "0";
  418. }
  419. return pstrVal->Copy( pszContentLength );
  420. }
  421. HRESULT
  422. GetServerVariableContentType(
  423. W3_CONTEXT *pW3Context,
  424. STRA *pstrVal
  425. )
  426. {
  427. DBG_ASSERT( pW3Context != NULL );
  428. PCHAR pszContentType = pW3Context->QueryRequest()->
  429. GetHeader( HttpHeaderContentType );
  430. if ( pszContentType == NULL )
  431. {
  432. pszContentType = "";
  433. }
  434. return pstrVal->Copy( pszContentType );
  435. }
  436. HRESULT
  437. GetServerVariableInstanceId(
  438. W3_CONTEXT *pW3Context,
  439. STRA *pstrVal
  440. )
  441. {
  442. DBG_ASSERT( pW3Context != NULL );
  443. CHAR pszId[16];
  444. _itoa( pW3Context->QueryRequest()->QuerySiteId(), pszId, 10 );
  445. return pstrVal->Copy( pszId );
  446. }
  447. HRESULT
  448. GetServerVariableRemoteHost(
  449. W3_CONTEXT *pW3Context,
  450. STRA *pstrVal
  451. )
  452. {
  453. HRESULT hr;
  454. DBG_ASSERT( pW3Context != NULL );
  455. //
  456. // If we have a resolved DNS name, then use it. Otherwise just
  457. // return the address
  458. //
  459. hr = pW3Context->QueryMainContext()->GetRemoteDNSName( pstrVal );
  460. if ( hr == HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED ) )
  461. {
  462. hr = GetServerVariableRemoteAddr( pW3Context, pstrVal );
  463. }
  464. return hr;
  465. }
  466. HRESULT
  467. GetServerVariableRemoteAddr(
  468. W3_CONTEXT *pW3Context,
  469. STRA *pstrVal
  470. )
  471. {
  472. DBG_ASSERT( pW3Context != NULL );
  473. DWORD dwAddr = pW3Context->QueryRequest()->QueryRemoteAddress();
  474. //
  475. // The dwAddr is reverse order from in_addr...
  476. //
  477. in_addr inAddr;
  478. inAddr.S_un.S_un_b.s_b1 = (u_char)(( dwAddr & 0xff000000 ) >> 24);
  479. inAddr.S_un.S_un_b.s_b2 = (u_char)(( dwAddr & 0x00ff0000 ) >> 16);
  480. inAddr.S_un.S_un_b.s_b3 = (u_char)(( dwAddr & 0x0000ff00 ) >> 8);
  481. inAddr.S_un.S_un_b.s_b4 = (u_char) ( dwAddr & 0x000000ff );
  482. LPSTR pszAddr = inet_ntoa( inAddr );
  483. if ( pszAddr == NULL )
  484. {
  485. return HRESULT_FROM_WIN32( GetLastError() );
  486. }
  487. return pstrVal->Copy( pszAddr );
  488. }
  489. HRESULT
  490. GetServerVariableServerName(
  491. W3_CONTEXT *pW3Context,
  492. STRA *pstrVal
  493. )
  494. {
  495. DBG_ASSERT( pW3Context != NULL );
  496. //
  497. // If the client send a host name, use it.
  498. //
  499. CHAR *szHost = pW3Context->QueryRequest()->GetHeader( HttpHeaderHost );
  500. if ( szHost )
  501. {
  502. CHAR *pszColon = strchr( szHost, ':' );
  503. if (pszColon == NULL)
  504. {
  505. return pstrVal->Copy( szHost );
  506. }
  507. else
  508. {
  509. return pstrVal->Copy( szHost,
  510. DIFF( pszColon - szHost ) );
  511. }
  512. }
  513. //
  514. // No host from the client, so populate the buffer with
  515. // the IP address.
  516. //
  517. DWORD dwAddr = pW3Context->QueryRequest()->QueryLocalAddress();
  518. //
  519. // The dwAddr is reverse order from in_addr...
  520. //
  521. in_addr inAddr;
  522. inAddr.S_un.S_un_b.s_b1 = (u_char)(( dwAddr & 0xff000000 ) >> 24);
  523. inAddr.S_un.S_un_b.s_b2 = (u_char)(( dwAddr & 0x00ff0000 ) >> 16);
  524. inAddr.S_un.S_un_b.s_b3 = (u_char)(( dwAddr & 0x0000ff00 ) >> 8);
  525. inAddr.S_un.S_un_b.s_b4 = (u_char) ( dwAddr & 0x000000ff );
  526. LPSTR pszAddr = inet_ntoa( inAddr );
  527. if ( pszAddr == NULL )
  528. {
  529. return HRESULT_FROM_WIN32( GetLastError() );
  530. }
  531. return pstrVal->Copy( pszAddr );
  532. }
  533. HRESULT
  534. GetServerVariableServerPort(
  535. W3_CONTEXT *pW3Context,
  536. STRA *pstrVal
  537. )
  538. {
  539. DBG_ASSERT( pW3Context != NULL );
  540. USHORT port = pW3Context->QueryRequest()->QueryLocalPort();
  541. CHAR szPort[8];
  542. _itoa( port, szPort, 10 );
  543. return pstrVal->Copy( szPort );
  544. }
  545. HRESULT
  546. GetServerVariablePathInfo(
  547. W3_CONTEXT *pW3Context,
  548. STRA *pstrVal
  549. )
  550. {
  551. DBG_ASSERT( pW3Context != NULL );
  552. URL_CONTEXT *pUrlContext;
  553. pUrlContext = pW3Context->QueryUrlContext();
  554. //
  555. // We might be called in an early filter where URL context isn't available
  556. //
  557. if ( pUrlContext == NULL )
  558. {
  559. pstrVal->Reset();
  560. return NO_ERROR;
  561. }
  562. W3_URL_INFO *pUrlInfo;
  563. DBG_REQUIRE( pUrlInfo = pUrlContext->QueryUrlInfo() );
  564. W3_SITE *pSite;
  565. DBG_REQUIRE( pSite = pW3Context->QuerySite() );
  566. W3_HANDLER *pHandler;
  567. pHandler = pW3Context->QueryHandler();
  568. HRESULT hr;
  569. //
  570. // In the case of script maps, if AllowPathInfoForScriptMappings
  571. // is not set for the site, we ignore path info, it is
  572. // just the URL
  573. //
  574. if ( pHandler != NULL &&
  575. pHandler->QueryScriptMapEntry() &&
  576. !pSite->QueryAllowPathInfoForScriptMappings() )
  577. {
  578. STACK_STRU (strUrl, MAX_PATH);
  579. if (FAILED(hr = pW3Context->QueryRequest()->GetUrl( &strUrl )) ||
  580. FAILED(hr = pstrVal->CopyW( strUrl.QueryStr() )))
  581. {
  582. return hr;
  583. }
  584. return S_OK;
  585. }
  586. else
  587. {
  588. // BUGBUG: do real conversion?
  589. return pstrVal->CopyW( pUrlInfo->QueryPathInfo()->QueryStr() );
  590. }
  591. }
  592. HRESULT
  593. GetServerVariablePathInfoW(
  594. W3_CONTEXT *pW3Context,
  595. STRU *pstrVal
  596. )
  597. {
  598. DBG_ASSERT( pW3Context != NULL );
  599. URL_CONTEXT *pUrlContext;
  600. pUrlContext = pW3Context->QueryUrlContext();
  601. //
  602. // We might be called in an early filter where URL context isn't available
  603. //
  604. if ( pUrlContext == NULL )
  605. {
  606. pstrVal->Reset();
  607. return NO_ERROR;
  608. }
  609. W3_URL_INFO *pUrlInfo;
  610. DBG_REQUIRE( pUrlInfo = pUrlContext->QueryUrlInfo() );
  611. W3_SITE *pSite;
  612. DBG_REQUIRE( pSite = pW3Context->QuerySite() );
  613. W3_HANDLER *pHandler;
  614. pHandler = pW3Context->QueryHandler();
  615. //
  616. // In the case of script maps, if AllowPathInfoForScriptMappings
  617. // is not set for the site, we ignore path info, it is
  618. // just the URL
  619. //
  620. if ( pHandler != NULL &&
  621. pHandler->QueryScriptMapEntry() &&
  622. !pSite->QueryAllowPathInfoForScriptMappings() )
  623. {
  624. return pW3Context->QueryRequest()->GetUrl( pstrVal );
  625. }
  626. else
  627. {
  628. return pstrVal->Copy( pUrlInfo->QueryPathInfo()->QueryStr() );
  629. }
  630. }
  631. HRESULT
  632. GetServerVariablePathTranslated(
  633. W3_CONTEXT *pW3Context,
  634. STRA *pstrVal
  635. )
  636. {
  637. DBG_ASSERT( pW3Context != NULL );
  638. HRESULT hr;
  639. URL_CONTEXT *pUrlContext;
  640. pUrlContext = pW3Context->QueryUrlContext();
  641. W3_URL_INFO *pUrlInfo;
  642. DBG_REQUIRE( pUrlInfo = pUrlContext->QueryUrlInfo() );
  643. W3_SITE *pSite;
  644. DBG_REQUIRE( pSite = pW3Context->QuerySite() );
  645. W3_HANDLER *pHandler;
  646. pHandler = pW3Context->QueryHandler();
  647. BOOL fUsePathInfo;
  648. if ( pHandler != NULL &&
  649. pHandler->QueryScriptMapEntry() &&
  650. !pSite->QueryAllowPathInfoForScriptMappings() )
  651. {
  652. fUsePathInfo = FALSE;
  653. }
  654. else
  655. {
  656. fUsePathInfo = TRUE;
  657. }
  658. STACK_STRU (struPathTranslated, 256);
  659. //
  660. // This is a new virtual path to have filters map
  661. //
  662. hr = pUrlInfo->GetPathTranslated( pW3Context,
  663. fUsePathInfo,
  664. &struPathTranslated );
  665. if (SUCCEEDED(hr))
  666. {
  667. // BUGBUG: do proper conversion?
  668. hr = pstrVal->CopyW( struPathTranslated.QueryStr() );
  669. }
  670. return hr;
  671. }
  672. HRESULT
  673. GetServerVariablePathTranslatedW(
  674. W3_CONTEXT *pW3Context,
  675. STRU *pstrVal
  676. )
  677. {
  678. DBG_ASSERT( pW3Context != NULL );
  679. URL_CONTEXT *pUrlContext;
  680. pUrlContext = pW3Context->QueryUrlContext();
  681. W3_URL_INFO *pUrlInfo;
  682. DBG_REQUIRE( pUrlInfo = pUrlContext->QueryUrlInfo() );
  683. W3_SITE *pSite;
  684. DBG_REQUIRE( pSite = pW3Context->QuerySite() );
  685. W3_HANDLER *pHandler;
  686. pHandler = pW3Context->QueryHandler();
  687. BOOL fUsePathInfo;
  688. if ( pHandler != NULL &&
  689. pHandler->QueryScriptMapEntry() &&
  690. !pSite->QueryAllowPathInfoForScriptMappings() )
  691. {
  692. fUsePathInfo = FALSE;
  693. }
  694. else
  695. {
  696. fUsePathInfo = TRUE;
  697. }
  698. //
  699. // This is a new virtual path to have filters map
  700. //
  701. return pUrlInfo->GetPathTranslated( pW3Context,
  702. fUsePathInfo,
  703. pstrVal );
  704. }
  705. HRESULT
  706. GetServerVariableRequestMethod(
  707. W3_CONTEXT *pW3Context,
  708. STRA *pstrVal
  709. )
  710. {
  711. DBG_ASSERT( pW3Context != NULL );
  712. return pW3Context->QueryRequest()->GetVerbString( pstrVal );
  713. }
  714. HRESULT
  715. GetServerVariableServerPortSecure(
  716. W3_CONTEXT *pW3Context,
  717. STRA *pstrVal
  718. )
  719. {
  720. DBG_ASSERT( pW3Context != NULL );
  721. if ( pW3Context->QueryRequest()->IsSecureRequest() )
  722. {
  723. return pstrVal->Copy("1", 1);
  724. }
  725. return pstrVal->Copy("0", 1);
  726. }
  727. HRESULT
  728. GetServerVariableServerSoftware(
  729. W3_CONTEXT *pW3Context,
  730. STRA *pstrVal
  731. )
  732. {
  733. DBG_ASSERT( pW3Context != NULL );
  734. //
  735. // BUGBUG - probably don't want this hardcoded...
  736. //
  737. return pstrVal->Copy( SERVER_SOFTWARE_STRING );
  738. }
  739. HRESULT
  740. GetServerVariableUrl(
  741. W3_CONTEXT *pW3Context,
  742. STRA *pstrVal
  743. )
  744. {
  745. URL_CONTEXT * pUrlContext;
  746. W3_URL_INFO * pUrlInfo;
  747. STACK_STRU( strUrl, 256 );
  748. HRESULT hr;
  749. DBG_ASSERT( pW3Context != NULL );
  750. //
  751. // URL context can be NULL if an early filter is called GetServerVar()
  752. //
  753. pUrlContext = pW3Context->QueryUrlContext();
  754. if ( pUrlContext != NULL )
  755. {
  756. pUrlInfo = pUrlContext->QueryUrlInfo();
  757. DBG_ASSERT( pUrlInfo != NULL );
  758. return pstrVal->CopyW( pUrlInfo->QueryProcessedUrl()->QueryStr() );
  759. }
  760. else
  761. {
  762. hr = pW3Context->QueryRequest()->GetUrl( &strUrl );
  763. if ( FAILED( hr ) )
  764. {
  765. return hr;
  766. }
  767. return pstrVal->CopyW( strUrl.QueryStr() );
  768. }
  769. }
  770. HRESULT
  771. GetServerVariableUrlW(
  772. W3_CONTEXT *pW3Context,
  773. STRU *pstrVal
  774. )
  775. {
  776. URL_CONTEXT * pUrlContext;
  777. W3_URL_INFO * pUrlInfo;
  778. DBG_ASSERT( pW3Context != NULL );
  779. //
  780. // URL context can be NULL if an early filter is called GetServerVar()
  781. //
  782. pUrlContext = pW3Context->QueryUrlContext();
  783. if ( pUrlContext != NULL )
  784. {
  785. pUrlInfo = pUrlContext->QueryUrlInfo();
  786. DBG_ASSERT( pUrlInfo != NULL );
  787. return pstrVal->Copy( pUrlInfo->QueryProcessedUrl()->QueryStr() );
  788. }
  789. else
  790. {
  791. return pW3Context->QueryRequest()->GetUrl( pstrVal );
  792. }
  793. }
  794. HRESULT
  795. GetServerVariableInstanceMetaPath(
  796. W3_CONTEXT *pW3Context,
  797. STRA *pstrVal
  798. )
  799. {
  800. DBG_ASSERT( pW3Context != NULL );
  801. STRU *pstrMetaPath = pW3Context->QuerySite()->QueryMBPath();
  802. DBG_ASSERT( pstrMetaPath );
  803. // BUGBUG: do proper conversion?
  804. return pstrVal->CopyW( pstrMetaPath->QueryStr() );
  805. }
  806. HRESULT
  807. GetServerVariableLogonUser(
  808. W3_CONTEXT *pW3Context,
  809. STRA *pstrVal
  810. )
  811. {
  812. DBG_ASSERT( pW3Context != NULL );
  813. W3_USER_CONTEXT *pUserContext;
  814. pUserContext = pW3Context->QueryUserContext();
  815. if ( pUserContext == NULL )
  816. {
  817. return pW3Context->QueryRequest()->GetRequestUserName( pstrVal );
  818. }
  819. else
  820. {
  821. return pstrVal->CopyW( pUserContext->QueryUserName() );
  822. }
  823. }
  824. HRESULT
  825. GetServerVariableLogonUserW(
  826. W3_CONTEXT *pW3Context,
  827. STRU *pstrVal
  828. )
  829. {
  830. DBG_ASSERT( pW3Context != NULL );
  831. W3_USER_CONTEXT *pUserContext;
  832. pUserContext = pW3Context->QueryUserContext();
  833. if ( pUserContext == NULL )
  834. {
  835. return pstrVal->CopyA( pW3Context->QueryRequest()->QueryRequestUserName()->QueryStr() );
  836. }
  837. else
  838. {
  839. return pstrVal->Copy( pUserContext->QueryUserName() );
  840. }
  841. return S_OK;
  842. }
  843. HRESULT
  844. GetServerVariableRemoteUser(
  845. W3_CONTEXT *pW3Context,
  846. STRA *pstrVal
  847. )
  848. {
  849. HRESULT hr;
  850. DBG_ASSERT( pW3Context != NULL );
  851. hr = pW3Context->QueryRequest()->GetRequestUserName( pstrVal );
  852. if ( FAILED( hr ) )
  853. {
  854. return hr;
  855. }
  856. if ( pstrVal->IsEmpty() )
  857. {
  858. W3_USER_CONTEXT *pUserContext;
  859. pUserContext = pW3Context->QueryUserContext();
  860. if ( pUserContext != NULL )
  861. {
  862. hr = pstrVal->CopyW( pUserContext->QueryRemoteUserName() );
  863. }
  864. else
  865. {
  866. hr = NO_ERROR;
  867. }
  868. }
  869. return hr;
  870. }
  871. HRESULT
  872. GetServerVariableRemoteUserW(
  873. W3_CONTEXT *pW3Context,
  874. STRU *pstrVal
  875. )
  876. {
  877. DBG_ASSERT( pW3Context != NULL );
  878. STRA *pstrUserName = pW3Context->QueryRequest()->QueryRequestUserName();
  879. if ( pstrUserName->IsEmpty() )
  880. {
  881. W3_USER_CONTEXT *pUserContext;
  882. pUserContext = pW3Context->QueryUserContext();
  883. if ( pUserContext != NULL )
  884. {
  885. return pstrVal->Copy( pUserContext->QueryRemoteUserName() );
  886. }
  887. }
  888. else
  889. {
  890. return pstrVal->CopyA( pstrUserName->QueryStr() );
  891. }
  892. return S_OK;
  893. }
  894. HRESULT
  895. GetServerVariableAuthType(
  896. W3_CONTEXT *pW3Context,
  897. STRA *pstrVal
  898. )
  899. {
  900. DBG_ASSERT( pW3Context != NULL );
  901. DBG_ASSERT( pstrVal != NULL );
  902. HRESULT hr = S_OK;
  903. W3_USER_CONTEXT *pUserContext = pW3Context->QueryUserContext();
  904. if ( pUserContext != NULL )
  905. {
  906. if ( pUserContext->QueryAuthType() == MD_ACCESS_MAP_CERT )
  907. {
  908. pstrVal->Copy( "SSL/PCT" );
  909. }
  910. else if ( pUserContext->QueryAuthType() == MD_AUTH_ANONYMOUS )
  911. {
  912. pstrVal->Copy( "" );
  913. }
  914. else
  915. {
  916. hr = pW3Context->QueryRequest()->GetAuthType( pstrVal );
  917. }
  918. }
  919. else
  920. {
  921. DBG_ASSERT ( FALSE );
  922. hr = HRESULT_FROM_WIN32( ERROR_INVALID_PARAMETER );
  923. }
  924. return hr;
  925. }
  926. HRESULT
  927. GetServerVariableAuthPassword(
  928. W3_CONTEXT *pW3Context,
  929. STRA *pstrVal
  930. )
  931. {
  932. W3_USER_CONTEXT * pUserContext;
  933. DBG_ASSERT( pW3Context != NULL );
  934. pUserContext = pW3Context->QueryUserContext();
  935. DBG_ASSERT( pUserContext != NULL );
  936. return pstrVal->CopyW( pUserContext->QueryPassword() );
  937. }
  938. //
  939. // CODEWORK
  940. //
  941. // GetServerVariableApplMdPath & GetServerVariableApplPhysicalPath
  942. // both try to deal with missing or invalid MD_APP_PATH data. In IIS5
  943. // they never had to, because MD_APP_PATH was used by wam when
  944. // initiallizing the CWamInfo object. If/When we include applications
  945. // into the isapi handler, these functions should be simplified.
  946. //
  947. // TaylorW 3-27-00
  948. //
  949. HRESULT
  950. GetServerVariableApplMdPath(
  951. W3_CONTEXT *pW3Context,
  952. STRA *pstrVal
  953. )
  954. {
  955. //
  956. // CODEWORK - Child Execute
  957. //
  958. DBG_ASSERT( pW3Context != NULL );
  959. URL_CONTEXT *pUrlContext = pW3Context->QueryUrlContext();
  960. if (pUrlContext == NULL)
  961. {
  962. return E_FAIL;
  963. }
  964. W3_METADATA *pMetaData = pUrlContext->QueryMetaData();
  965. if (pMetaData == NULL)
  966. {
  967. return E_FAIL;
  968. }
  969. STRU * pstrAppMetaPath = pMetaData->QueryAppMetaPath();
  970. HRESULT hr;
  971. if( pstrAppMetaPath->IsEmpty() )
  972. {
  973. //
  974. // This really shouldn't be necessary, because we should not
  975. // even start up if there is no application defined, but we
  976. // do right now and stress does not property call AppCreate.
  977. //
  978. W3_SITE * pSite = pW3Context->QuerySite();
  979. DBG_ASSERT( pSite );
  980. STRU * pstrSiteMetaRoot = pSite->QueryMBRoot();
  981. hr = pstrVal->CopyW( pstrSiteMetaRoot->QueryStr() );
  982. }
  983. else
  984. {
  985. hr = pstrVal->CopyW( pstrAppMetaPath->QueryStr() );
  986. }
  987. return hr;
  988. }
  989. HRESULT
  990. GetServerVariableApplMdPathW(
  991. W3_CONTEXT *pW3Context,
  992. STRU *pstrVal
  993. )
  994. {
  995. DBG_ASSERT( pW3Context != NULL );
  996. URL_CONTEXT *pUrlContext = pW3Context->QueryUrlContext();
  997. if (pUrlContext == NULL)
  998. {
  999. return E_FAIL;
  1000. }
  1001. W3_METADATA *pMetaData = pUrlContext->QueryMetaData();
  1002. if (pMetaData == NULL)
  1003. {
  1004. return E_FAIL;
  1005. }
  1006. STRU * pstrAppMetaPath = pMetaData->QueryAppMetaPath();
  1007. HRESULT hr;
  1008. if( pstrAppMetaPath->IsEmpty() )
  1009. {
  1010. //
  1011. // This really shouldn't be necessary, because we should not
  1012. // even start up if there is no application defined, but we
  1013. // do right now and stress does not property call AppCreate.
  1014. //
  1015. W3_SITE * pSite = pW3Context->QuerySite();
  1016. DBG_ASSERT( pSite );
  1017. STRU * pstrSiteMetaRoot = pSite->QueryMBRoot();
  1018. hr = pstrVal->Copy( pstrSiteMetaRoot->QueryStr() );
  1019. }
  1020. else
  1021. {
  1022. hr = pstrVal->Copy( pstrAppMetaPath->QueryStr() );
  1023. }
  1024. return hr;
  1025. }
  1026. HRESULT
  1027. GetServerVariableApplPhysicalPath(
  1028. W3_CONTEXT *pW3Context,
  1029. STRA *pstrVal
  1030. )
  1031. {
  1032. DBG_ASSERT( pW3Context != NULL );
  1033. DBG_ASSERT( pstrVal );
  1034. STACK_STRA( strAppMetaPath, MAX_PATH );
  1035. STACK_STRU( strAppUrl, MAX_PATH );
  1036. HRESULT hr = E_FAIL;
  1037. hr = GetServerVariableApplMdPath( pW3Context, &strAppMetaPath );
  1038. if( SUCCEEDED(hr) )
  1039. {
  1040. //
  1041. // pstrAppMetaPath is a full metabase path:
  1042. // /LM/W3SVC/<site>/Root/...
  1043. //
  1044. // To convert it to a physical path we will use
  1045. // W3_STATE_URLINFO::MapPath, but this requires
  1046. // that we remove the metabase prefixes and build
  1047. // a Url string.
  1048. //
  1049. //
  1050. // Get the metabase path for the site root
  1051. //
  1052. W3_SITE *pSite = pW3Context->QuerySite();
  1053. DBG_ASSERT( pSite );
  1054. STRU *pstrSiteRoot = pSite->QueryMBRoot();
  1055. DBG_ASSERT( pstrSiteRoot );
  1056. //
  1057. // Make some assumptions about the site path and the AppMetaPath
  1058. // being well-formed. The AppMetaPath may not have a terminating
  1059. // /, but the site root will.
  1060. //
  1061. DBG_ASSERT( pstrSiteRoot->QueryCCH() >=
  1062. sizeof("/LM/W3SVC/1/Root/") - 1
  1063. );
  1064. if( strAppMetaPath.QueryCCH() < pstrSiteRoot->QueryCCH() - 1 )
  1065. {
  1066. //
  1067. // This indicates an invalid value for MD_APP_ROOT is sitting
  1068. // around. We need to bail if this is the case.
  1069. //
  1070. DBGPRINTF(( DBG_CONTEXT,
  1071. "Invalid MD_APP_ROOT detected (%s)\n",
  1072. strAppMetaPath.QueryStr()
  1073. ));
  1074. return HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
  1075. }
  1076. DBG_ASSERT( strAppMetaPath.QueryCCH() >=
  1077. sizeof("/LM/W3SVC/1/Root/") - 2
  1078. );
  1079. //
  1080. // The AppUrl will be the metabase path -
  1081. // all the /LM/W3SVC/1/ROOT goo
  1082. //
  1083. CHAR * pszStartAppUrl = strAppMetaPath.QueryStr() +
  1084. (pstrSiteRoot->QueryCCH() - 1);
  1085. //
  1086. // The AppMetaPath may not have a terminating /, so if it is
  1087. // a site root pszStartAppUrl will be empty.
  1088. //
  1089. if( *pszStartAppUrl != '\0' )
  1090. {
  1091. if( *pszStartAppUrl != '/' )
  1092. {
  1093. DBGPRINTF(( DBG_CONTEXT,
  1094. "Invalid MD_APP_ROOT detected (%s)\n",
  1095. strAppMetaPath.QueryStr()
  1096. ));
  1097. return HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
  1098. }
  1099. hr = strAppUrl.CopyA(
  1100. pszStartAppUrl,
  1101. strAppMetaPath.QueryCCH() - (pstrSiteRoot->QueryCCH() - 1)
  1102. );
  1103. }
  1104. else
  1105. {
  1106. hr = strAppUrl.Copy( L"/", 1 );
  1107. }
  1108. if( SUCCEEDED(hr) )
  1109. {
  1110. STACK_STRU (strAppPath, MAX_PATH);
  1111. //
  1112. // Convert to a physical path
  1113. //
  1114. hr = W3_STATE_URLINFO::MapPath( pW3Context,
  1115. strAppUrl,
  1116. &strAppPath,
  1117. NULL,
  1118. NULL,
  1119. NULL
  1120. );
  1121. if (SUCCEEDED(hr))
  1122. {
  1123. hr = pstrVal->CopyW(strAppPath.QueryStr());
  1124. //
  1125. // Ensure that the last character in the path
  1126. // is '\\'. There are legacy scripts that will
  1127. // concatenate filenames to this path, and many
  1128. // of them will break if we don't do this.
  1129. //
  1130. if ( SUCCEEDED( hr ) &&
  1131. *(pstrVal->QueryStr()+pstrVal->QueryCCH()-1) != '\\' )
  1132. {
  1133. hr = pstrVal->Append( "\\" );
  1134. }
  1135. }
  1136. }
  1137. }
  1138. return hr;
  1139. }
  1140. HRESULT
  1141. GetServerVariableApplPhysicalPathW(
  1142. W3_CONTEXT *pW3Context,
  1143. STRU *pstrVal
  1144. )
  1145. {
  1146. DBG_ASSERT( pW3Context != NULL );
  1147. DBG_ASSERT( pstrVal );
  1148. STACK_STRU( strAppMetaPath, MAX_PATH );
  1149. STACK_STRU( strAppUrl, MAX_PATH );
  1150. HRESULT hr = E_FAIL;
  1151. hr = GetServerVariableApplMdPathW( pW3Context, &strAppMetaPath );
  1152. if( SUCCEEDED(hr) )
  1153. {
  1154. //
  1155. // pstrAppMetaPath is a full metabase path:
  1156. // /LM/W3SVC/<site>/Root/...
  1157. //
  1158. // To convert it to a physical path we will use
  1159. // W3_STATE_URLINFO::MapPath, but this requires
  1160. // that we remove the metabase prefixes and build
  1161. // a Url string.
  1162. //
  1163. //
  1164. // Get the metabase path for the site root
  1165. //
  1166. W3_SITE *pSite = pW3Context->QuerySite();
  1167. DBG_ASSERT( pSite );
  1168. STRU *pstrSiteRoot = pSite->QueryMBRoot();
  1169. DBG_ASSERT( pstrSiteRoot );
  1170. //
  1171. // Make some assumptions about the site path and the AppMetaPath
  1172. // being well-formed. The AppMetaPath may not have a terminating
  1173. // /, but the site root will.
  1174. //
  1175. DBG_ASSERT( pstrSiteRoot->QueryCCH() >=
  1176. sizeof("/LM/W3SVC/1/Root/") - 1
  1177. );
  1178. if( strAppMetaPath.QueryCCH() < pstrSiteRoot->QueryCCH() - 1 )
  1179. {
  1180. //
  1181. // This indicates an invalid value for MD_APP_ROOT is sitting
  1182. // around. We need to bail if this is the case.
  1183. //
  1184. DBGPRINTF(( DBG_CONTEXT,
  1185. "Invalid MD_APP_ROOT detected (%S)\n",
  1186. strAppMetaPath.QueryStr()
  1187. ));
  1188. return HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
  1189. }
  1190. DBG_ASSERT( strAppMetaPath.QueryCCH() >=
  1191. sizeof("/LM/W3SVC/1/Root/") - 2
  1192. );
  1193. //
  1194. // The AppUrl will be the metabase path -
  1195. // all the /LM/W3SVC/1/ROOT goo
  1196. //
  1197. WCHAR * pszStartAppUrl = strAppMetaPath.QueryStr() +
  1198. (pstrSiteRoot->QueryCCH() - 1);
  1199. //
  1200. // The AppMetaPath may not have a terminating /, so if it is
  1201. // a site root pszStartAppUrl will be empty.
  1202. //
  1203. if( *pszStartAppUrl != L'\0' )
  1204. {
  1205. if( *pszStartAppUrl != L'/' )
  1206. {
  1207. DBGPRINTF(( DBG_CONTEXT,
  1208. "Invalid MD_APP_ROOT detected (%s)\n",
  1209. strAppMetaPath.QueryStr()
  1210. ));
  1211. return HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
  1212. }
  1213. hr = strAppUrl.Copy(
  1214. pszStartAppUrl,
  1215. strAppMetaPath.QueryCCH() - (pstrSiteRoot->QueryCCH() - 1)
  1216. );
  1217. }
  1218. else
  1219. {
  1220. hr = strAppUrl.Copy( L"/", 1 );
  1221. }
  1222. if( SUCCEEDED(hr) )
  1223. {
  1224. hr = W3_STATE_URLINFO::MapPath( pW3Context,
  1225. strAppUrl,
  1226. pstrVal,
  1227. NULL,
  1228. NULL,
  1229. NULL
  1230. );
  1231. //
  1232. // Ensure that the last character in the path
  1233. // is '\\'. There are legacy scripts that will
  1234. // concatenate filenames to this path, and many
  1235. // of them will break if we don't do this.
  1236. //
  1237. if ( SUCCEEDED( hr ) &&
  1238. *(pstrVal->QueryStr()+pstrVal->QueryCCH()-1) != L'\\' )
  1239. {
  1240. hr = pstrVal->Append( L"\\" );
  1241. }
  1242. }
  1243. }
  1244. return hr;
  1245. }
  1246. HRESULT
  1247. GetServerVariableGatewayInterface(
  1248. W3_CONTEXT *pW3Context,
  1249. STRA *pstrVal
  1250. )
  1251. {
  1252. DBG_ASSERT( pW3Context != NULL );
  1253. return pstrVal->Copy("CGI/1.1", 7);
  1254. }
  1255. HRESULT GetServerVariableLocalAddr(
  1256. W3_CONTEXT *pW3Context,
  1257. STRA *pstrVal
  1258. )
  1259. {
  1260. DBG_ASSERT( pW3Context != NULL );
  1261. DWORD dwAddr = pW3Context->QueryRequest()->QueryLocalAddress();
  1262. //
  1263. // The dwAddr is reverse order from in_addr...
  1264. //
  1265. in_addr inAddr;
  1266. inAddr.S_un.S_un_b.s_b1 = (u_char)(( dwAddr & 0xff000000 ) >> 24);
  1267. inAddr.S_un.S_un_b.s_b2 = (u_char)(( dwAddr & 0x00ff0000 ) >> 16);
  1268. inAddr.S_un.S_un_b.s_b3 = (u_char)(( dwAddr & 0x0000ff00 ) >> 8);
  1269. inAddr.S_un.S_un_b.s_b4 = (u_char) ( dwAddr & 0x000000ff );
  1270. LPSTR pszAddr = inet_ntoa( inAddr );
  1271. if ( pszAddr == NULL )
  1272. {
  1273. return HRESULT_FROM_WIN32( GetLastError() );
  1274. }
  1275. return pstrVal->Copy( pszAddr );
  1276. }
  1277. HRESULT GetServerVariableHttps(
  1278. W3_CONTEXT *pW3Context,
  1279. STRA *pstrVal)
  1280. {
  1281. DBG_ASSERT( pW3Context != NULL );
  1282. if (pW3Context->QueryRequest()->IsSecureRequest())
  1283. {
  1284. return pstrVal->Copy("on", 2);
  1285. }
  1286. return pstrVal->Copy("off", 3);
  1287. }
  1288. HRESULT
  1289. GetServerVariableHttpsKeySize(
  1290. W3_CONTEXT * pW3Context,
  1291. STRA * pstrVal
  1292. )
  1293. {
  1294. HTTP_SSL_INFO * pSslInfo;
  1295. CHAR achNum[ 64 ];
  1296. pSslInfo = pW3Context->QueryRequest()->QuerySslInfo();
  1297. if ( pSslInfo == NULL )
  1298. {
  1299. achNum[ 0 ] = '\0';
  1300. }
  1301. else
  1302. {
  1303. _itoa( pSslInfo->ConnectionKeySize,
  1304. achNum,
  1305. 10 );
  1306. }
  1307. return pstrVal->Copy( achNum );
  1308. }
  1309. HRESULT
  1310. GetServerVariableClientCertIssuer(
  1311. W3_CONTEXT * pW3Context,
  1312. STRA * pstrVal
  1313. )
  1314. {
  1315. CERTIFICATE_CONTEXT * pCertContext;
  1316. pCertContext = pW3Context->QueryMainContext()->QueryCertificateContext();
  1317. if ( pCertContext == NULL )
  1318. {
  1319. return pstrVal->Copy( "", 0 );
  1320. }
  1321. else
  1322. {
  1323. return pCertContext->GetIssuer( pstrVal );
  1324. }
  1325. }
  1326. HRESULT
  1327. GetServerVariableClientCertSubject(
  1328. W3_CONTEXT * pW3Context,
  1329. STRA * pstrVal
  1330. )
  1331. {
  1332. CERTIFICATE_CONTEXT * pCertContext;
  1333. pCertContext = pW3Context->QueryMainContext()->QueryCertificateContext();
  1334. if ( pCertContext == NULL )
  1335. {
  1336. return pstrVal->Copy( "", 0 );
  1337. }
  1338. else
  1339. {
  1340. return pCertContext->GetSubject( pstrVal );
  1341. }
  1342. }
  1343. HRESULT
  1344. GetServerVariableClientCertCookie(
  1345. W3_CONTEXT * pW3Context,
  1346. STRA * pstrVal
  1347. )
  1348. {
  1349. CERTIFICATE_CONTEXT * pCertContext;
  1350. pCertContext = pW3Context->QueryMainContext()->QueryCertificateContext();
  1351. if ( pCertContext == NULL )
  1352. {
  1353. return pstrVal->Copy( "", 0 );
  1354. }
  1355. else
  1356. {
  1357. return pCertContext->GetCookie( pstrVal );
  1358. }
  1359. }
  1360. HRESULT
  1361. GetServerVariableClientCertSerialNumber(
  1362. W3_CONTEXT * pW3Context,
  1363. STRA * pstrVal
  1364. )
  1365. {
  1366. CERTIFICATE_CONTEXT * pCertContext;
  1367. pCertContext = pW3Context->QueryMainContext()->QueryCertificateContext();
  1368. if ( pCertContext == NULL )
  1369. {
  1370. return pstrVal->Copy( "", 0 );
  1371. }
  1372. else
  1373. {
  1374. return pCertContext->GetSerialNumber( pstrVal );
  1375. }
  1376. }
  1377. HRESULT
  1378. GetServerVariableClientCertFlags(
  1379. W3_CONTEXT * pW3Context,
  1380. STRA * pstrVal
  1381. )
  1382. {
  1383. CERTIFICATE_CONTEXT * pCertContext;
  1384. pCertContext = pW3Context->QueryMainContext()->QueryCertificateContext();
  1385. if ( pCertContext == NULL )
  1386. {
  1387. return pstrVal->Copy( "0", 1 );
  1388. }
  1389. else
  1390. {
  1391. return pCertContext->GetFlags( pstrVal );
  1392. }
  1393. }
  1394. HRESULT
  1395. GetServerVariableHttpsSecretKeySize(
  1396. W3_CONTEXT * pW3Context,
  1397. STRA * pstrVal
  1398. )
  1399. {
  1400. HTTP_SSL_INFO * pSslInfo;
  1401. CHAR achNum[ 64 ];
  1402. pSslInfo = pW3Context->QueryRequest()->QuerySslInfo();
  1403. if ( pSslInfo == NULL )
  1404. {
  1405. achNum[ 0 ] = '\0';
  1406. }
  1407. else
  1408. {
  1409. _itoa( pSslInfo->ServerCertKeySize,
  1410. achNum,
  1411. 10 );
  1412. }
  1413. return pstrVal->Copy( achNum );
  1414. }
  1415. HRESULT
  1416. GetServerVariableHttpsServerIssuer(
  1417. W3_CONTEXT * pW3Context,
  1418. STRA * pstrVal
  1419. )
  1420. {
  1421. HTTP_SSL_INFO * pSslInfo;
  1422. CHAR * pszVariable;
  1423. pSslInfo = pW3Context->QueryRequest()->QuerySslInfo();
  1424. if ( pSslInfo == NULL )
  1425. {
  1426. pszVariable = "";
  1427. }
  1428. else
  1429. {
  1430. DBG_ASSERT( pSslInfo->pServerCertIssuer != NULL );
  1431. pszVariable = pSslInfo->pServerCertIssuer;
  1432. }
  1433. return pstrVal->Copy( pszVariable );
  1434. }
  1435. HRESULT
  1436. GetServerVariableHttpsServerSubject(
  1437. W3_CONTEXT * pW3Context,
  1438. STRA * pstrVal
  1439. )
  1440. {
  1441. HTTP_SSL_INFO * pSslInfo;
  1442. CHAR * pszVariable;
  1443. pSslInfo = pW3Context->QueryRequest()->QuerySslInfo();
  1444. if ( pSslInfo == NULL )
  1445. {
  1446. pszVariable = "";
  1447. }
  1448. else
  1449. {
  1450. DBG_ASSERT( pSslInfo->pServerCertSubject != NULL );
  1451. pszVariable = pSslInfo->pServerCertSubject;
  1452. }
  1453. return pstrVal->Copy( pszVariable );
  1454. }
  1455. HRESULT
  1456. GetServerVariableHttpUrl(
  1457. W3_CONTEXT * pW3Context,
  1458. STRA * pstrVal
  1459. )
  1460. {
  1461. //
  1462. // HTTP_URL gets the raw url for the request. If a filter has
  1463. // modified the url the request object handles redirecting the
  1464. // RawUrl variable
  1465. //
  1466. DBG_ASSERT( pW3Context != NULL );
  1467. return pW3Context->QueryRequest()->GetRawUrl( pstrVal );
  1468. }
  1469. HRESULT
  1470. GetServerVariableHttpVersion(
  1471. W3_CONTEXT * pW3Context,
  1472. STRA * pstrVal
  1473. )
  1474. {
  1475. //
  1476. // HTTP_VERSION returns the client version string
  1477. //
  1478. DBG_ASSERT( pW3Context != NULL );
  1479. return pW3Context->QueryRequest()->GetVersionString( pstrVal );
  1480. }
  1481. HRESULT
  1482. GetServerVariableAppPoolId(
  1483. W3_CONTEXT * pW3Context,
  1484. STRA * pstrVal
  1485. )
  1486. {
  1487. //
  1488. // APP_POOL_ID returns the AppPoolId WAS started us with
  1489. //
  1490. DBG_ASSERT( pW3Context != NULL );
  1491. return pstrVal->CopyW( (LPWSTR)UlAtqGetContextProperty(NULL,
  1492. ULATQ_PROPERTY_APP_POOL_ID) );
  1493. }
  1494. HRESULT
  1495. GetServerVariableAppPoolIdW(
  1496. W3_CONTEXT * pW3Context,
  1497. STRU * pstrVal
  1498. )
  1499. {
  1500. //
  1501. // APP_POOL_ID returns the AppPoolId WAS started us with
  1502. //
  1503. DBG_ASSERT( pW3Context != NULL );
  1504. return pstrVal->Copy( (LPWSTR)UlAtqGetContextProperty(NULL,
  1505. ULATQ_PROPERTY_APP_POOL_ID) );
  1506. }
  1507. HRESULT
  1508. GetServerVariableScriptTranslated(
  1509. W3_CONTEXT * pW3Context,
  1510. STRA * pstrVal
  1511. )
  1512. {
  1513. DBG_ASSERT( pW3Context != NULL );
  1514. URL_CONTEXT *pUrlContext = pW3Context->QueryUrlContext();
  1515. DBG_ASSERT( pUrlContext != NULL );
  1516. return pstrVal->CopyW( pUrlContext->QueryPhysicalPath()->QueryStr() );
  1517. }
  1518. HRESULT
  1519. GetServerVariableScriptTranslatedW(
  1520. W3_CONTEXT * pW3Context,
  1521. STRU * pstrVal
  1522. )
  1523. {
  1524. DBG_ASSERT( pW3Context != NULL );
  1525. URL_CONTEXT *pUrlContext = pW3Context->QueryUrlContext();
  1526. DBG_ASSERT( pUrlContext != NULL );
  1527. return pstrVal->Copy( *pUrlContext->QueryPhysicalPath() );
  1528. }
  1529. HRESULT
  1530. GetServerVariableUnencodedUrl(
  1531. W3_CONTEXT * pW3Context,
  1532. STRA * pstrVal
  1533. )
  1534. {
  1535. DBG_ASSERT( pW3Context != NULL );
  1536. W3_REQUEST *pW3Request = pW3Context->QueryRequest();
  1537. DBG_ASSERT( pW3Request != NULL );
  1538. return pW3Request->GetRawUrl(pstrVal);
  1539. }