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.

322 lines
7.3 KiB

  1. #ifndef _AUTHPROVIDER_HXX_
  2. #define _AUTHPROVIDER_HXX_
  3. #define UNINITIALIZED_ID 0xffff
  4. class CONNECTION_AUTH_CONTEXT: public W3_CONNECTION_STATE
  5. {
  6. public:
  7. CONNECTION_AUTH_CONTEXT()
  8. :m_dwInternalId( UNINITIALIZED_ID )
  9. {
  10. if ( sm_pTraceLog != NULL )
  11. {
  12. WriteRefTraceLog( sm_pTraceLog,
  13. 1,
  14. this );
  15. }
  16. }
  17. virtual
  18. ~CONNECTION_AUTH_CONTEXT()
  19. {
  20. if ( sm_pTraceLog != NULL )
  21. {
  22. WriteRefTraceLog( sm_pTraceLog,
  23. 0,
  24. this );
  25. }
  26. }
  27. DWORD
  28. QueryInternalId(
  29. VOID
  30. )
  31. {
  32. return m_dwInternalId;
  33. }
  34. VOID
  35. SetInternalId(
  36. DWORD dwId
  37. )
  38. {
  39. m_dwInternalId = dwId;
  40. }
  41. virtual
  42. BOOL
  43. CheckSignature(
  44. VOID
  45. )
  46. {
  47. return FALSE;
  48. }
  49. VOID
  50. SetSignature(
  51. DWORD dwSignature
  52. )
  53. {
  54. m_dwSignature = dwSignature;
  55. }
  56. DWORD
  57. QuerySignature(
  58. VOID )
  59. {
  60. return m_dwSignature;
  61. }
  62. static
  63. HRESULT
  64. Initialize(
  65. VOID
  66. )
  67. {
  68. #if DBG
  69. sm_pTraceLog = CreateRefTraceLog( 2000, 0 );
  70. #else
  71. sm_pTraceLog = NULL;
  72. #endif
  73. return NO_ERROR;
  74. }
  75. static
  76. VOID
  77. Terminate(
  78. VOID
  79. )
  80. {
  81. if ( sm_pTraceLog != NULL )
  82. {
  83. DestroyRefTraceLog( sm_pTraceLog );
  84. sm_pTraceLog = NULL;
  85. }
  86. }
  87. private:
  88. DWORD m_dwSignature;
  89. DWORD m_dwInternalId;
  90. static PTRACE_LOG sm_pTraceLog;
  91. };
  92. class AUTH_PROVIDER
  93. {
  94. public:
  95. AUTH_PROVIDER()
  96. {
  97. m_dwInternalId = UNINITIALIZED_ID;
  98. }
  99. virtual ~AUTH_PROVIDER()
  100. {
  101. }
  102. virtual
  103. HRESULT
  104. Initialize(
  105. DWORD dwInternalId
  106. ) = 0;
  107. virtual
  108. VOID
  109. Terminate(
  110. VOID
  111. ) = 0;
  112. virtual
  113. HRESULT
  114. DoesApply(
  115. W3_MAIN_CONTEXT * pMainContext,
  116. BOOL * pfApplies
  117. ) = 0;
  118. virtual
  119. HRESULT
  120. DoAuthenticate(
  121. W3_MAIN_CONTEXT * pMainContext,
  122. BOOL * pfFilterFinished
  123. ) = 0;
  124. virtual
  125. HRESULT
  126. OnAccessDenied(
  127. W3_MAIN_CONTEXT * pMainContext
  128. ) = 0;
  129. virtual
  130. DWORD
  131. QueryAuthType(
  132. VOID
  133. ) = 0;
  134. CONNECTION_AUTH_CONTEXT *
  135. QueryConnectionAuthContext(
  136. W3_MAIN_CONTEXT * pMainContext
  137. )
  138. /*++
  139. Description:
  140. Authentication schemes may need to remember authenticaion context
  141. associated with current connection in order to be able to
  142. perform authentication handshake
  143. good example is NTLM that needs 3 legs of authentication
  144. Arguments:
  145. pMainContext - main context
  146. Return Value:
  147. CONNECTION_AUTH_CONTEXT * - NULL if there is no context available
  148. or if there is one but for different
  149. authentication scheme
  150. --*/
  151. {
  152. W3_CONNECTION * pW3Connection = NULL;
  153. CONNECTION_AUTH_CONTEXT * pAuthContext = NULL;
  154. DBG_ASSERT( pMainContext != NULL );
  155. pW3Connection = pMainContext->QueryConnection( FALSE );
  156. if ( pW3Connection != NULL )
  157. {
  158. pAuthContext =
  159. ( CONNECTION_AUTH_CONTEXT * )pW3Connection->
  160. QueryConnectionState( CONTEXT_STATE_AUTHENTICATION );
  161. if ( pAuthContext != NULL &&
  162. pAuthContext->QueryInternalId() == QueryInternalId() )
  163. {
  164. DBG_ASSERT( pAuthContext->CheckSignature() );
  165. return pAuthContext;
  166. }
  167. }
  168. //
  169. // Context we retrieved is either NULL or
  170. // is valid for different auth type
  171. //
  172. return NULL;
  173. }
  174. HRESULT
  175. SetConnectionAuthContext(
  176. W3_MAIN_CONTEXT * pMainContext,
  177. CONNECTION_AUTH_CONTEXT * pNewAuthContext
  178. )
  179. {
  180. /*++
  181. Description:
  182. Authentication schemes may need to remember authenticaion context
  183. associated with current connection in order to be able to
  184. perform authentication handshake
  185. good example is NTLM that needs 3 legs of authentication
  186. Arguments:
  187. pMainContext - main context
  188. pNewAuthContext - new authenticaion context. If there is
  189. some authenticaion context already stored
  190. it will be deleted and replaced with new one
  191. Return Value:
  192. HRESULT
  193. --*/
  194. W3_CONNECTION * pW3Connection = NULL;
  195. CONNECTION_AUTH_CONTEXT * pAuthContext = NULL;
  196. DBG_ASSERT( pMainContext != NULL );
  197. if ( pNewAuthContext == NULL )
  198. {
  199. //
  200. // Perform cleanup if needed
  201. //
  202. pW3Connection = pMainContext->QueryConnection( FALSE );
  203. if ( pW3Connection != NULL )
  204. {
  205. pAuthContext =
  206. ( CONNECTION_AUTH_CONTEXT * )pW3Connection->
  207. QueryConnectionState( CONTEXT_STATE_AUTHENTICATION );
  208. if ( pAuthContext != NULL )
  209. {
  210. pW3Connection->SetConnectionState( CONTEXT_STATE_AUTHENTICATION,
  211. NULL );
  212. delete pAuthContext;
  213. pAuthContext = NULL;
  214. }
  215. }
  216. }
  217. else
  218. {
  219. pW3Connection = pMainContext->QueryConnection( TRUE );
  220. if ( pW3Connection != NULL )
  221. {
  222. pAuthContext =
  223. ( CONNECTION_AUTH_CONTEXT * )pW3Connection->
  224. QueryConnectionState( CONTEXT_STATE_AUTHENTICATION );
  225. if ( pAuthContext != NULL )
  226. {
  227. DBG_ASSERT( pAuthContext->CheckSignature() );
  228. delete pAuthContext;
  229. pAuthContext = NULL;
  230. }
  231. pNewAuthContext->SetInternalId( QueryInternalId() );
  232. pW3Connection->SetConnectionState( CONTEXT_STATE_AUTHENTICATION,
  233. pNewAuthContext );
  234. }
  235. else
  236. {
  237. //
  238. // pMainContext->QueryConnection doesn't return error code
  239. // if it fails return generic error
  240. //
  241. return E_FAIL;
  242. }
  243. }
  244. return NO_ERROR;
  245. }
  246. DWORD
  247. QueryInternalId(
  248. VOID
  249. )
  250. {
  251. DBG_ASSERT( m_dwInternalId != UNINITIALIZED_ID );
  252. return m_dwInternalId;
  253. }
  254. VOID
  255. SetInternalId(
  256. DWORD dwId
  257. )
  258. {
  259. m_dwInternalId = dwId;
  260. }
  261. private:
  262. DWORD m_dwInternalId;
  263. };
  264. #endif