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.

222 lines
7.0 KiB

  1. #ifndef _SERVERVAR_HXX_
  2. #define _SERVERVAR_HXX_
  3. //
  4. // Function used to retrieve a server variable
  5. //
  6. typedef HRESULT
  7. (SERVER_VARIABLE_ROUTINE)
  8. (
  9. W3_CONTEXT *pW3Context,
  10. STRA *pstrValue
  11. );
  12. typedef HRESULT
  13. (SERVER_VARIABLE_ROUTINE_W)
  14. (
  15. W3_CONTEXT *pW3Context,
  16. STRU *pstrValue
  17. );
  18. typedef SERVER_VARIABLE_ROUTINE *PFN_SERVER_VARIABLE_ROUTINE;
  19. typedef SERVER_VARIABLE_ROUTINE_W *PFN_SERVER_VARIABLE_ROUTINE_W;
  20. //
  21. // Forward declaration for each server variable function
  22. //
  23. extern SERVER_VARIABLE_ROUTINE GetServerVariableQueryString;
  24. extern SERVER_VARIABLE_ROUTINE GetServerVariableAllHttp;
  25. extern SERVER_VARIABLE_ROUTINE GetServerVariableAllRaw;
  26. extern SERVER_VARIABLE_ROUTINE GetServerVariableContentLength;
  27. extern SERVER_VARIABLE_ROUTINE GetServerVariableContentType;
  28. extern SERVER_VARIABLE_ROUTINE GetServerVariablePathInfo;
  29. extern SERVER_VARIABLE_ROUTINE GetServerVariablePathTranslated;
  30. extern SERVER_VARIABLE_ROUTINE GetServerVariableRequestMethod;
  31. extern SERVER_VARIABLE_ROUTINE GetServerVariableInstanceId;
  32. extern SERVER_VARIABLE_ROUTINE GetServerVariableRemoteAddr;
  33. extern SERVER_VARIABLE_ROUTINE GetServerVariableRemotePort;
  34. extern SERVER_VARIABLE_ROUTINE GetServerVariableRemoteHost;
  35. extern SERVER_VARIABLE_ROUTINE GetServerVariableServerName;
  36. extern SERVER_VARIABLE_ROUTINE GetServerVariableServerPort;
  37. extern SERVER_VARIABLE_ROUTINE GetServerVariableServerPortSecure;
  38. extern SERVER_VARIABLE_ROUTINE GetServerVariableServerSoftware;
  39. extern SERVER_VARIABLE_ROUTINE GetServerVariableUrl;
  40. extern SERVER_VARIABLE_ROUTINE GetServerVariableInstanceMetaPath;
  41. extern SERVER_VARIABLE_ROUTINE GetServerVariableRemoteUser;
  42. extern SERVER_VARIABLE_ROUTINE GetServerVariableLogonUser;
  43. extern SERVER_VARIABLE_ROUTINE GetServerVariableAuthType;
  44. extern SERVER_VARIABLE_ROUTINE GetServerVariableAuthPassword;
  45. extern SERVER_VARIABLE_ROUTINE GetServerVariableApplMdPath;
  46. extern SERVER_VARIABLE_ROUTINE GetServerVariableApplPhysicalPath;
  47. extern SERVER_VARIABLE_ROUTINE GetServerVariableGatewayInterface;
  48. extern SERVER_VARIABLE_ROUTINE GetServerVariableHttps;
  49. extern SERVER_VARIABLE_ROUTINE GetServerVariableLocalAddr;
  50. extern SERVER_VARIABLE_ROUTINE GetServerVariableHttpsServerIssuer;
  51. extern SERVER_VARIABLE_ROUTINE GetServerVariableHttpsServerSubject;
  52. extern SERVER_VARIABLE_ROUTINE GetServerVariableHttpsSecretKeySize;
  53. extern SERVER_VARIABLE_ROUTINE GetServerVariableHttpsKeySize;
  54. extern SERVER_VARIABLE_ROUTINE GetServerVariableClientCertIssuer;
  55. extern SERVER_VARIABLE_ROUTINE GetServerVariableClientCertSubject;
  56. extern SERVER_VARIABLE_ROUTINE GetServerVariableClientCertCookie;
  57. extern SERVER_VARIABLE_ROUTINE GetServerVariableClientCertSerialNumber;
  58. extern SERVER_VARIABLE_ROUTINE GetServerVariableClientCertFlags;
  59. extern SERVER_VARIABLE_ROUTINE GetServerVariableHttpUrl;
  60. extern SERVER_VARIABLE_ROUTINE GetServerVariableHttpVersion;
  61. extern SERVER_VARIABLE_ROUTINE GetServerVariableAppPoolId;
  62. extern SERVER_VARIABLE_ROUTINE GetServerVariableScriptTranslated;
  63. extern SERVER_VARIABLE_ROUTINE GetServerVariableUnencodedUrl;
  64. extern SERVER_VARIABLE_ROUTINE GetServerVariableSsiExecDisabled;
  65. extern SERVER_VARIABLE_ROUTINE GetServerVariableOriginalUrl;
  66. extern SERVER_VARIABLE_ROUTINE_W GetServerVariablePathInfoW;
  67. extern SERVER_VARIABLE_ROUTINE_W GetServerVariablePathTranslatedW;
  68. extern SERVER_VARIABLE_ROUTINE_W GetServerVariableServerNameW;
  69. extern SERVER_VARIABLE_ROUTINE_W GetServerVariableUrlW;
  70. extern SERVER_VARIABLE_ROUTINE_W GetServerVariableRemoteUserW;
  71. extern SERVER_VARIABLE_ROUTINE_W GetServerVariableLogonUserW;
  72. extern SERVER_VARIABLE_ROUTINE_W GetServerVariableApplMdPathW;
  73. extern SERVER_VARIABLE_ROUTINE_W GetServerVariableApplPhysicalPathW;
  74. extern SERVER_VARIABLE_ROUTINE_W GetServerVariableAppPoolIdW;
  75. extern SERVER_VARIABLE_ROUTINE_W GetServerVariableScriptTranslatedW;
  76. extern SERVER_VARIABLE_ROUTINE_W GetServerVariableOriginalUrlW;
  77. //
  78. // Server variable hash table
  79. //
  80. struct SERVER_VARIABLE_RECORD
  81. {
  82. CHAR * _pszName;
  83. PFN_SERVER_VARIABLE_ROUTINE _pfnRoutine;
  84. PFN_SERVER_VARIABLE_ROUTINE_W _pfnRoutineW;
  85. SERVER_VARIABLE_RECORD * _pNext;
  86. };
  87. #define SERVER_VARIABLE_BUCKETS 131
  88. //
  89. // SERVER_VARIABLE_HASH maps server variable string to routines to eval them
  90. //
  91. class SERVER_VARIABLE_HASH
  92. {
  93. public:
  94. SERVER_VARIABLE_HASH()
  95. {
  96. ZeroMemory( &_rgBuckets, sizeof( _rgBuckets ) );
  97. }
  98. static
  99. CHAR *
  100. ExtractKey(
  101. const SERVER_VARIABLE_RECORD * pRecord
  102. )
  103. {
  104. DBG_ASSERT( pRecord != NULL );
  105. return pRecord->_pszName;
  106. }
  107. VOID
  108. InsertRecord(
  109. SERVER_VARIABLE_RECORD * pRecord
  110. )
  111. {
  112. DWORD dwIndex;
  113. SERVER_VARIABLE_RECORD* pCursor;
  114. dwIndex = HashString( pRecord->_pszName ) % SERVER_VARIABLE_BUCKETS;
  115. pCursor = _rgBuckets[ dwIndex ];
  116. pRecord->_pNext = pCursor;
  117. _rgBuckets[ dwIndex ] = pRecord;
  118. }
  119. SERVER_VARIABLE_RECORD *
  120. FindKey(
  121. CHAR * pszName
  122. )
  123. {
  124. DWORD dwIndex;
  125. SERVER_VARIABLE_RECORD* pRecord;
  126. DBG_ASSERT( pszName != NULL );
  127. dwIndex = HashString( pszName ) % SERVER_VARIABLE_BUCKETS;
  128. pRecord = _rgBuckets[ dwIndex ];
  129. while ( pRecord != NULL )
  130. {
  131. if ( memcmp( pszName, pRecord->_pszName, strlen( pszName ) + 1 ) == 0 )
  132. {
  133. break;
  134. }
  135. pRecord = pRecord->_pNext;
  136. }
  137. return pRecord;
  138. }
  139. static
  140. HRESULT
  141. Initialize(
  142. VOID
  143. );
  144. static
  145. VOID
  146. Terminate(
  147. VOID
  148. );
  149. static
  150. HRESULT
  151. GetServerVariable(
  152. W3_CONTEXT * pContext,
  153. CHAR * pszVariableName,
  154. CHAR * pszBuffer,
  155. DWORD * pcbBuffer
  156. );
  157. static
  158. HRESULT
  159. GetServerVariable(
  160. W3_CONTEXT * pContext,
  161. CHAR * pszVariableName,
  162. STRA * pstrVal
  163. );
  164. static
  165. HRESULT
  166. GetServerVariableW(
  167. W3_CONTEXT * pContext,
  168. CHAR * pszVariableName,
  169. STRU * pstrVal
  170. );
  171. private:
  172. static SERVER_VARIABLE_HASH * sm_pRequestHash;
  173. static SERVER_VARIABLE_RECORD sm_rgServerRoutines[];
  174. static
  175. HRESULT
  176. GetServerVariableRoutine(
  177. CHAR * pszName,
  178. PFN_SERVER_VARIABLE_ROUTINE * ppfnRoutine,
  179. PFN_SERVER_VARIABLE_ROUTINE_W * ppfnRoutineW
  180. );
  181. SERVER_VARIABLE_RECORD * _rgBuckets[ SERVER_VARIABLE_BUCKETS ];
  182. };
  183. HRESULT
  184. TranslateIpAddressToStr (
  185. DWORD dwAddress,
  186. STRA * pstraBuffer
  187. );
  188. #endif