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.

397 lines
9.3 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. splugin.hxx
  5. Abstract:
  6. This file contains definitions for splugin.cxx
  7. Author:
  8. Arthur Bierer (arthurbi) 25-Dec-1995
  9. Revision History:
  10. Rajeev Dujari (rajeevd) 01-Oct-1996 overhaul
  11. --*/
  12. #ifndef SPLUGIN_HXX
  13. #define SPLUGIN_HXX
  14. // macros for code prettiness
  15. #define ALLOCATE_BUFFER 0x1
  16. #define GET_SCHEME 0x2
  17. #define IS_PROXY TRUE
  18. #define IS_SERVER FALSE
  19. // states set on request handle
  20. #define AUTHSTATE_NONE 0
  21. #define AUTHSTATE_NEGOTIATE 1
  22. #define AUTHSTATE_CHALLENGE 2
  23. #define AUTHSTATE_NEEDTUNNEL 3
  24. #define AUTHSTATE_LAST AUTHSTATE_NEEDTUNNEL
  25. // warning !!! do not add any more AUTHSTATEs without increasing size of bitfield
  26. struct AUTH_CREDS;
  27. class HTTP_REQUEST_HANDLE_OBJECT;
  28. //-----------------------------------------------------------------------------
  29. //
  30. // AUTHCTX
  31. //
  32. class NOVTABLE AUTHCTX
  33. {
  34. public:
  35. // States
  36. enum SPMState
  37. {
  38. STATE_NOTLOADED = 0,
  39. STATE_LOADED,
  40. STATE_ERROR
  41. };
  42. class SPMData
  43. {
  44. public:
  45. LPSTR szScheme;
  46. DWORD cbScheme;
  47. DWORD dwFlags;
  48. DWORD eScheme;
  49. SPMState eState;
  50. SPMData *pNext;
  51. SPMData(LPSTR szScheme, DWORD dwFlags);
  52. ~SPMData();
  53. };
  54. // Global linked list of SPM providers.
  55. static SPMData *g_pSPMList;
  56. // Global spm list state
  57. static SPMState g_eState;
  58. // SubScheme - specifically for the negotiate
  59. // package - can be either NTLM or Kerberos.
  60. DWORD _eSubScheme;
  61. DWORD _dwSubFlags;
  62. public:
  63. // Instance specific;
  64. HTTP_REQUEST_HANDLE_OBJECT *_pRequest;
  65. SPMData *_pSPMData;
  66. LPVOID _pvContext;
  67. CCritSec _CtxCriSec;
  68. AUTH_CREDS *_pCreds;
  69. BOOL _fIsProxy;
  70. // Constructor
  71. AUTHCTX(SPMData *pSPM, AUTH_CREDS* pCreds);
  72. // Destructor
  73. virtual ~AUTHCTX();
  74. // ------------------------ Static Functions -----------------------------
  75. static VOID Enumerate();
  76. static VOID UnloadAll();
  77. static AUTHCTX* CreateAuthCtx(HTTP_REQUEST_HANDLE_OBJECT *pReq, BOOL fIsProxy);
  78. static AUTHCTX* CreateAuthCtx(HTTP_REQUEST_HANDLE_OBJECT *pReq, BOOL fIsProxy,
  79. LPSTR szScheme);
  80. static AUTHCTX* CreateAuthCtx(HTTP_REQUEST_HANDLE_OBJECT *pReq, BOOL fIsProxy,
  81. AUTH_CREDS* pCreds);
  82. static AUTHCTX::SPMState GetSPMListState();
  83. static AUTH_CREDS* SearchCredsList (AUTH_CREDS* Creds, LPSTR lpszHost,
  84. LPSTR lpszUri, LPSTR lpszRealm, SPMData *pSPM);
  85. static AUTH_CREDS* CreateCreds
  86. (
  87. HTTP_REQUEST_HANDLE_OBJECT *pRequest,
  88. BOOL fIsProxy,
  89. SPMData *pSPM,
  90. LPSTR lpszRealm
  91. );
  92. static DWORD GetAuthHeaderData
  93. (
  94. HTTP_REQUEST_HANDLE_OBJECT *pRequest,
  95. BOOL fIsProxy,
  96. LPSTR szItem,
  97. LPSTR *pszData,
  98. LPDWORD pcbData,
  99. DWORD dwIndex,
  100. DWORD dwFlags
  101. );
  102. // ------------------------ Base class functions ---------------------------
  103. DWORD FindHdrIdxFromScheme(LPDWORD pdwIndex);
  104. LPSTR GetScheme();
  105. DWORD GetFlags();
  106. SPMState GetState();
  107. DWORD GetSchemeType();
  108. DWORD GetRawSchemeType();
  109. // ------------------------------ Overrides--------------------------------
  110. // Called before request to generate any pre-authentication headers.
  111. virtual DWORD PreAuthUser(IN LPSTR pBuf, IN OUT LPDWORD pcbBuf) = 0;
  112. // Retrieves response header data
  113. virtual DWORD UpdateFromHeaders(HTTP_REQUEST_HANDLE_OBJECT *pRequest, BOOL fIsProxy) = 0;
  114. // Called after UpdateFromHeaders to update authentication context.
  115. virtual DWORD PostAuthUser() = 0;
  116. };
  117. //-----------------------------------------------------------------------------
  118. //
  119. // BASIC_CTX
  120. //
  121. class BASIC_CTX : public AUTHCTX
  122. {
  123. public:
  124. BASIC_CTX(HTTP_REQUEST_HANDLE_OBJECT *pRequest, BOOL fIsProxy, SPMData* pSPM, AUTH_CREDS* pCreds);
  125. ~BASIC_CTX();
  126. // virtual overrides
  127. DWORD PreAuthUser(IN LPSTR pBuf, IN OUT LPDWORD pcbBuf);
  128. DWORD UpdateFromHeaders(HTTP_REQUEST_HANDLE_OBJECT *pRequest, BOOL fIsProxy);
  129. DWORD PostAuthUser();
  130. };
  131. //-----------------------------------------------------------------------------
  132. //
  133. // PASSPORT_CTX
  134. //
  135. class INTERNET_HANDLE_OBJECT;
  136. class PASSPORT_CTX : public AUTHCTX
  137. {
  138. public:
  139. PASSPORT_CTX(HTTP_REQUEST_HANDLE_OBJECT *pRequest,
  140. BOOL fIsProxy,
  141. SPMData* pSPM,
  142. AUTH_CREDS* pCreds);
  143. ~PASSPORT_CTX();
  144. BOOL Init(void);
  145. // virtual overrides
  146. virtual DWORD PreAuthUser(IN LPSTR pBuf,
  147. IN OUT LPDWORD pcbBuf);
  148. virtual DWORD UpdateFromHeaders(HTTP_REQUEST_HANDLE_OBJECT *pRequest,
  149. BOOL fIsProxy);
  150. virtual DWORD PostAuthUser();
  151. BOOL PromptForCreds(HBITMAP** ppBitmap, PWSTR* ppwszAuthTarget);
  152. LPSTR m_lpszRetUrl;
  153. protected:
  154. BOOL InitLogonContext(void);
  155. BOOL CallbackRegistered(void);
  156. DWORD HandleSuccessfulLogon(
  157. LPWSTR pwszFromPP,
  158. LPDWORD pdwFromPP,
  159. BOOL fPreAuth
  160. );
  161. BOOL RetryLogon(void);
  162. enum
  163. {
  164. MAX_AUTH_TARGET_LEN = 256,
  165. MAX_AUTH_REALM_LEN = 128
  166. };
  167. PP_LOGON_CONTEXT m_hLogon;
  168. LPINTERNET_THREAD_INFO m_pNewThreadInfo;
  169. LPWSTR m_pwszPartnerInfo;
  170. WCHAR m_wRealm[MAX_AUTH_REALM_LEN];
  171. CHAR m_FromPP[2048];
  172. WCHAR m_wTarget[MAX_AUTH_TARGET_LEN];
  173. INTERNET_HANDLE_OBJECT* m_pInternet;
  174. };
  175. //-----------------------------------------------------------------------------
  176. //
  177. // PLUG_CTX
  178. //
  179. class PLUG_CTX : public AUTHCTX
  180. {
  181. public:
  182. // Class specific data.
  183. LPSTR _szAlloc;
  184. LPSTR _szData;
  185. DWORD _cbData;
  186. BOOL _fNTLMProxyAuth;
  187. LPSTR _pszFQDN;
  188. // Class specific funcs.
  189. DWORD Load();
  190. DWORD ClearAuthUser(LPVOID *ppvContext, LPSTR szServer);
  191. DWORD wQueryHeadersAlloc
  192. (
  193. IN HINTERNET hRequestMapped,
  194. IN DWORD dwQuery,
  195. OUT LPDWORD lpdwQueryIndex,
  196. OUT LPSTR *lppszOutStr,
  197. OUT LPDWORD lpdwSize
  198. );
  199. DWORD CrackAuthenticationHeader
  200. (
  201. IN HINTERNET hRequestMapped,
  202. IN BOOL fIsProxy,
  203. IN DWORD dwAuthenticationIndex,
  204. IN OUT LPSTR *lppszAuthHeader,
  205. IN OUT LPSTR *lppszExtra,
  206. IN OUT DWORD *lpdwExtra,
  207. OUT LPSTR *lppszAuthScheme
  208. );
  209. VOID ResolveProtocol();
  210. LPSTR GetFQDN(LPSTR lpszHostName);
  211. PLUG_CTX(HTTP_REQUEST_HANDLE_OBJECT *pRequest, BOOL fIsProxy, SPMData* pSPM, AUTH_CREDS* pCreds);
  212. ~PLUG_CTX();
  213. // virtual overrides
  214. DWORD PreAuthUser(IN LPSTR pBuf, IN OUT LPDWORD pcbBuf);
  215. DWORD UpdateFromHeaders(HTTP_REQUEST_HANDLE_OBJECT *pRequest, BOOL fIsProxy);
  216. DWORD PostAuthUser();
  217. };
  218. //-----------------------------------------------------------------------------
  219. //
  220. // DIGEST_CTX
  221. //
  222. class DIGEST_CTX : public AUTHCTX
  223. {
  224. protected:
  225. VOID GetFuncTbl();
  226. VOID InitSecurityBuffers(LPSTR szBuffOut, DWORD cbBuffOut,
  227. LPDWORD dwSecFlags, DWORD dwISCMode);
  228. LPSTR GetRequestUri();
  229. public:
  230. static PSecurityFunctionTable g_pFuncTbl;
  231. static CredHandle g_hCred;
  232. // Class specific data.
  233. SecBuffer _SecBuffIn[10];
  234. SecBufferDesc _SecBuffInDesc;
  235. SecBuffer _SecBuffOut[1];
  236. SecBufferDesc _SecBuffOutDesc;
  237. CtxtHandle _hCtxt;
  238. LPSTR _szAlloc;
  239. LPSTR _szData;
  240. LPSTR _szRequestUri;
  241. DWORD _cbContext;
  242. DWORD _cbData;
  243. DWORD _nRetries;
  244. DIGEST_CTX(HTTP_REQUEST_HANDLE_OBJECT *pRequest, BOOL fIsProxy, SPMData* pSPM, AUTH_CREDS* pCreds);
  245. ~DIGEST_CTX();
  246. DWORD PromptForCreds(HWND hWnd);
  247. // virtual overrides
  248. DWORD PreAuthUser(IN LPSTR pBuf, IN OUT LPDWORD pcbBuf);
  249. DWORD UpdateFromHeaders(HTTP_REQUEST_HANDLE_OBJECT *pRequest, BOOL fIsProxy);
  250. DWORD PostAuthUser();
  251. static VOID FlushCreds();
  252. static VOID Logoff();
  253. };
  254. struct AUTH_CREDS
  255. {
  256. AUTHCTX::SPMData *pSPM; // Scheme
  257. LPSTR lpszHost; // name of server or proxy
  258. LPSTR lpszRealm; // realm, optional, may be null
  259. LPSTR lpszUser; // username, may be null
  260. LPSTR lpszPass; // password, may be null
  261. DWORD SetUser (LPSTR lpszUser);
  262. DWORD SetPass (LPSTR lpszUser);
  263. LPSTR GetUser (void) { return lpszUser;}
  264. LPSTR GetPass (void) { return lpszPass;}
  265. };
  266. #ifndef ARRAY_ELEMENTS
  267. #define ARRAY_ELEMENTS(rg) (sizeof(rg) / sizeof((rg)[0]))
  268. #endif
  269. // password cache locking
  270. BOOL AuthOpen (void);
  271. void AuthClose (void);
  272. BOOL AuthLock (void);
  273. void AuthUnlock (void);
  274. // worker thread calls
  275. DWORD AuthOnRequest (HINTERNET hRequest);
  276. DWORD AuthOnResponse (HINTERNET hRequest);
  277. // cleanup
  278. void AuthFlush (void); // flush password cache
  279. void AuthUnload (void); // unload everything
  280. #endif // SPLUGIN_HXX