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.

419 lines
10 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. struct WINHTTP_REQUEST_CREDENTIALS;
  29. //-----------------------------------------------------------------------------
  30. //
  31. // AUTHCTX
  32. //
  33. class NOVTABLE AUTHCTX
  34. {
  35. public:
  36. // States
  37. enum SPMState
  38. {
  39. STATE_NOTLOADED = 0,
  40. STATE_LOADED,
  41. STATE_ERROR
  42. };
  43. class SPMData
  44. {
  45. public:
  46. LPSTR szScheme;
  47. DWORD cbScheme;
  48. DWORD dwFlags;
  49. DWORD eScheme;
  50. SPMState eState;
  51. SPMData *pNext;
  52. SPMData(LPSTR szScheme, DWORD dwFlags);
  53. ~SPMData();
  54. };
  55. // Global linked list of SPM providers.
  56. static SPMData *g_pSPMList;
  57. // Global spm list state
  58. static SPMState g_eState;
  59. // SubScheme - specifically for the negotiate
  60. // package - can be either NTLM or Kerberos.
  61. DWORD _eSubScheme;
  62. DWORD _dwSubFlags;
  63. public:
  64. // Instance specific;
  65. HTTP_REQUEST_HANDLE_OBJECT *_pRequest;
  66. SPMData *_pSPMData;
  67. LPVOID _pvContext;
  68. CCritSec _CtxCriSec;
  69. AUTH_CREDS *_pCreds;
  70. BOOL _fIsProxy;
  71. BOOL _fDisableAutoLogon;
  72. void DisableAutoLogon(void) { _fDisableAutoLogon = TRUE; }
  73. // Constructor
  74. AUTHCTX(SPMData *pSPM, AUTH_CREDS* pCreds);
  75. // Destructor
  76. virtual ~AUTHCTX();
  77. // ------------------------ Static Functions -----------------------------
  78. static BOOL InitializeSPMList();
  79. static VOID UnloadAll();
  80. static AUTHCTX* CreateAuthCtx(HTTP_REQUEST_HANDLE_OBJECT *pReq, BOOL fIsProxy);
  81. static AUTHCTX* CreateAuthCtx(HTTP_REQUEST_HANDLE_OBJECT *pReq, BOOL fIsProxy,
  82. LPSTR szScheme);
  83. static AUTHCTX* CreateAuthCtx(HTTP_REQUEST_HANDLE_OBJECT *pReq, BOOL fIsProxy,
  84. AUTH_CREDS* pCreds);
  85. static SPMData* SPMLookup(LPSTR szScheme);
  86. static AUTHCTX::SPMState GetSPMListState();
  87. static AUTH_CREDS* SearchCredsList (AUTH_CREDS* Creds, LPSTR lpszHost,
  88. LPSTR lpszUri, LPSTR lpszRealm, SPMData *pSPM);
  89. static AUTH_CREDS* CreateCreds
  90. (
  91. HTTP_REQUEST_HANDLE_OBJECT *pRequest,
  92. BOOL fIsProxy,
  93. SPMData *pSPM,
  94. LPSTR lpszRealm,
  95. WINHTTP_REQUEST_CREDENTIALS* pRequestCredentials = NULL
  96. );
  97. static DWORD GetAuthHeaderData
  98. (
  99. HTTP_REQUEST_HANDLE_OBJECT *pRequest,
  100. BOOL fIsProxy,
  101. LPSTR szItem,
  102. LPSTR *pszData,
  103. LPDWORD pcbData,
  104. DWORD dwIndex,
  105. DWORD dwFlags
  106. );
  107. // ------------------------ Base class functions ---------------------------
  108. DWORD FindHdrIdxFromScheme(LPDWORD pdwIndex);
  109. LPSTR GetScheme();
  110. DWORD GetFlags();
  111. SPMState GetState();
  112. DWORD GetSchemeType();
  113. DWORD GetRawSchemeType();
  114. // ------------------------------ Overrides--------------------------------
  115. // Called before request to generate any pre-authentication headers.
  116. virtual DWORD PreAuthUser(IN LPSTR pBuf, IN OUT LPDWORD pcbBuf) = 0;
  117. // Retrieves response header data
  118. virtual DWORD UpdateFromHeaders(HTTP_REQUEST_HANDLE_OBJECT *pRequest, BOOL fIsProxy) = 0;
  119. // Called after UpdateFromHeaders to update authentication context.
  120. virtual DWORD PostAuthUser() = 0;
  121. };
  122. //-----------------------------------------------------------------------------
  123. //
  124. // BASIC_CTX
  125. //
  126. class BASIC_CTX : public AUTHCTX
  127. {
  128. public:
  129. BASIC_CTX(HTTP_REQUEST_HANDLE_OBJECT *pRequest, BOOL fIsProxy, SPMData* pSPM, AUTH_CREDS* pCreds);
  130. ~BASIC_CTX();
  131. // virtual overrides
  132. DWORD PreAuthUser(IN LPSTR pBuf, IN OUT LPDWORD pcbBuf);
  133. DWORD UpdateFromHeaders(HTTP_REQUEST_HANDLE_OBJECT *pRequest, BOOL fIsProxy);
  134. DWORD PostAuthUser();
  135. };
  136. //-----------------------------------------------------------------------------
  137. //
  138. // PASSPORT_CTX
  139. //
  140. class INTERNET_HANDLE_OBJECT;
  141. class PASSPORT_CTX : public AUTHCTX
  142. {
  143. public:
  144. PASSPORT_CTX(HTTP_REQUEST_HANDLE_OBJECT *pRequest,
  145. BOOL fIsProxy,
  146. SPMData* pSPM,
  147. AUTH_CREDS* pCreds);
  148. ~PASSPORT_CTX();
  149. BOOL Init(void);
  150. // virtual overrides
  151. virtual DWORD PreAuthUser(IN LPSTR pBuf,
  152. IN OUT LPDWORD pcbBuf);
  153. virtual DWORD UpdateFromHeaders(HTTP_REQUEST_HANDLE_OBJECT *pRequest,
  154. BOOL fIsProxy);
  155. virtual DWORD PostAuthUser();
  156. BOOL PromptForCreds(HBITMAP** ppBitmap, PWSTR* ppwszAuthTarget);
  157. LPSTR m_lpszRetUrl;
  158. protected:
  159. BOOL InitLogonContext(void);
  160. BOOL CallbackRegistered(void);
  161. DWORD HandleSuccessfulLogon(
  162. LPWSTR* ppwszFromPP,
  163. LPDWORD pdwFromPP,
  164. BOOL fPreAuth
  165. );
  166. DWORD SetCreds(BOOL* pfCredSet);
  167. BOOL Transfer401ContentFromPP(void);
  168. DWORD ModifyRequestBasedOnRU(void);
  169. enum
  170. {
  171. MAX_AUTH_TARGET_LEN = 256,
  172. MAX_AUTH_REALM_LEN = 128
  173. };
  174. PP_LOGON_CONTEXT m_hLogon;
  175. LPINTERNET_THREAD_INFO m_pNewThreadInfo;
  176. LPWSTR m_pwszPartnerInfo;
  177. WCHAR m_wRealm[MAX_AUTH_REALM_LEN];
  178. PSTR m_pszFromPP;
  179. WCHAR m_wTarget[MAX_AUTH_TARGET_LEN];
  180. INTERNET_HANDLE_OBJECT* m_pInternet;
  181. BOOL m_fPreauthFailed;
  182. BOOL m_fAnonymous;
  183. // BOOL m_AuthComplete;
  184. BOOL _fChallengeSeen;
  185. public:
  186. // BOOL fAuthInProgress(void) { return !m_AuthComplete; }
  187. LPSTR m_pszCbUrl;
  188. LPSTR m_pszCbTxt;
  189. };
  190. //-----------------------------------------------------------------------------
  191. //
  192. // PLUG_CTX
  193. //
  194. class PLUG_CTX : public AUTHCTX
  195. {
  196. public:
  197. // Class specific data.
  198. LPSTR _szAlloc;
  199. LPSTR _szData;
  200. DWORD _cbData;
  201. BOOL _fNTLMProxyAuth;
  202. LPSTR _pszFQDN;
  203. BOOL _fChallengeSeen;
  204. // Class specific funcs.
  205. DWORD Load();
  206. DWORD ClearAuthUser(LPVOID *ppvContext, LPSTR szServer);
  207. DWORD wQueryHeadersAlloc
  208. (
  209. IN HINTERNET hRequestMapped,
  210. IN DWORD dwQuery,
  211. OUT LPDWORD lpdwQueryIndex,
  212. OUT LPSTR *lppszOutStr,
  213. OUT LPDWORD lpdwSize
  214. );
  215. DWORD CrackAuthenticationHeader
  216. (
  217. IN HINTERNET hRequestMapped,
  218. IN BOOL fIsProxy,
  219. IN DWORD dwAuthenticationIndex,
  220. IN OUT LPSTR *lppszAuthHeader,
  221. IN OUT LPSTR *lppszExtra,
  222. IN OUT DWORD *lpdwExtra,
  223. OUT LPSTR *lppszAuthScheme
  224. );
  225. VOID ResolveProtocol();
  226. LPSTR GetFQDN(LPSTR lpszHostName);
  227. PLUG_CTX(HTTP_REQUEST_HANDLE_OBJECT *pRequest, BOOL fIsProxy, SPMData* pSPM, AUTH_CREDS* pCreds);
  228. ~PLUG_CTX();
  229. // virtual overrides
  230. DWORD PreAuthUser(IN LPSTR pBuf, IN OUT LPDWORD pcbBuf);
  231. DWORD UpdateFromHeaders(HTTP_REQUEST_HANDLE_OBJECT *pRequest, BOOL fIsProxy);
  232. DWORD PostAuthUser();
  233. };
  234. //-----------------------------------------------------------------------------
  235. //
  236. // DIGEST_CTX
  237. //
  238. class DIGEST_CTX : public AUTHCTX
  239. {
  240. protected:
  241. VOID InitSecurityBuffers(LPSTR szBuffOut, DWORD cbBuffOut,
  242. LPDWORD dwSecFlags, DWORD dwISCMode);
  243. LPSTR GetRequestUri();
  244. LPSTR _pszVerb;
  245. public:
  246. static CCritSec s_CritSection; // lock before modifying DIGEST_CTX static variables
  247. static HINSTANCE g_hSecLib;
  248. static PSecurityFunctionTable g_pFuncTbl;
  249. static unsigned int g_iUniquePerDigestCtxInt;
  250. static BOOL GlobalInitialize();
  251. static void GlobalRelease();
  252. // Class specific data.
  253. SecBuffer _SecBuffIn[10];
  254. SecBufferDesc _SecBuffInDesc;
  255. SecBuffer _SecBuffOut[1];
  256. SecBufferDesc _SecBuffOutDesc;
  257. CtxtHandle _hCtxt;
  258. CHAR _szUserCtx[64];
  259. CredHandle _hCred; // if _hCred == NULL, constructor failed.
  260. LPSTR _szAlloc;
  261. LPSTR _szData;
  262. LPSTR _szRequestUri;
  263. DWORD _cbContext;
  264. DWORD _cbData;
  265. DIGEST_CTX(HTTP_REQUEST_HANDLE_OBJECT *pRequest, BOOL fIsProxy, SPMData* pSPM, AUTH_CREDS* pCreds);
  266. ~DIGEST_CTX();
  267. // virtual overrides
  268. DWORD PreAuthUser(IN LPSTR pBuf, IN OUT LPDWORD pcbBuf);
  269. DWORD UpdateFromHeaders(HTTP_REQUEST_HANDLE_OBJECT *pRequest, BOOL fIsProxy);
  270. DWORD PostAuthUser();
  271. };
  272. struct AUTH_CREDS
  273. {
  274. AUTHCTX::SPMData *pSPM; // Scheme
  275. LPSTR lpszHost; // name of server or proxy
  276. LPSTR lpszRealm; // realm, optional, may be null
  277. LPSTR lpszUser; // username, may be null
  278. XSTRING xszPass; // password; use XSTRING to encrypt
  279. DWORD SetUser (LPSTR lpszUser);
  280. DWORD SetPass (LPSTR lpszUser);
  281. LPSTR GetUser (void) { return lpszUser;}
  282. LPSTR GetPass (void) { return xszPass.GetUnencryptedString();}
  283. };
  284. #ifndef ARRAY_ELEMENTS
  285. #define ARRAY_ELEMENTS(rg) (sizeof(rg) / sizeof((rg)[0]))
  286. #endif
  287. // password cache locking
  288. BOOL AuthOpen (void);
  289. void AuthClose (void);
  290. BOOL AuthLock (void);
  291. void AuthUnlock (void);
  292. // worker thread calls
  293. DWORD AuthOnRequest (HINTERNET hRequest);
  294. DWORD AuthOnResponse (HINTERNET hRequest);
  295. // cleanup
  296. void AuthUnload (void); // unload everything
  297. #endif // SPLUGIN_HXX