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.

513 lines
12 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. #include <wincred.h>
  15. // macros for code prettiness
  16. #define ALLOCATE_BUFFER 0x1
  17. #define GET_SCHEME 0x2
  18. #define IS_PROXY TRUE
  19. #define IS_SERVER FALSE
  20. #define IS_USER TRUE
  21. #define IS_PASS FALSE
  22. // states set on request handle
  23. #define AUTHSTATE_NONE 0
  24. #define AUTHSTATE_NEGOTIATE 1
  25. #define AUTHSTATE_CHALLENGE 2
  26. #define AUTHSTATE_NEEDTUNNEL 3
  27. #define AUTHSTATE_LAST AUTHSTATE_NEEDTUNNEL
  28. // warning !!! do not add any more AUTHSTATEs without increasing size of bitfield
  29. struct PWC;
  30. class HTTP_REQUEST_HANDLE_OBJECT;
  31. typedef
  32. DWORD
  33. (WINAPI
  34. *PFN_CREDUI_PROMPTFORCREDENTIALS)(
  35. PCREDUI_INFO pUiInfo,
  36. PCSTR pszTargetName,
  37. PCtxtHandle pContext,
  38. DWORD dwAuthError,
  39. PSTR pszUserName,
  40. ULONG ulUserNameMaxChars,
  41. PSTR pszPassword,
  42. ULONG ulPasswordMaxChars,
  43. PBOOL pfSave,
  44. DWORD dwFlags
  45. );
  46. typedef
  47. DWORD
  48. (WINAPI
  49. *PFN_CREDUI_PROMPTFORCREDENTIALS_W)(
  50. PCREDUI_INFOW pUiInfo,
  51. PCWSTR pszTargetName,
  52. PCtxtHandle pContext,
  53. DWORD dwAuthError,
  54. PWSTR pszUserName,
  55. ULONG ulUserNameMaxChars,
  56. PWSTR pszPassword,
  57. ULONG ulPasswordMaxChars,
  58. BOOL *save,
  59. DWORD dwFlags
  60. );
  61. typedef
  62. void
  63. (WINAPI
  64. *PFN_CREDUI_CONFIRMCREDENTIALS)(
  65. PCSTR pszTargetName,
  66. BOOL bConfirm
  67. );
  68. //-----------------------------------------------------------------------------
  69. //
  70. // AUTHCTX
  71. //
  72. class AUTHCTX
  73. {
  74. public:
  75. // States
  76. enum SPMState
  77. {
  78. STATE_NOTLOADED = 0,
  79. STATE_LOADED,
  80. STATE_ERROR
  81. };
  82. // AUTHCTX SPM Schemes
  83. enum SPMScheme
  84. {
  85. SCHEME_BASIC = 0,
  86. SCHEME_DIGEST,
  87. SCHEME_NTLM,
  88. SCHEME_MSN,
  89. SCHEME_DPA,
  90. SCHEME_KERBEROS,
  91. SCHEME_NEGOTIATE,
  92. SCHEME_PASSPORT,
  93. SCHEME_UNKNOWN
  94. };
  95. class SPMData
  96. {
  97. public:
  98. LPSTR szScheme;
  99. DWORD cbScheme;
  100. DWORD dwFlags;
  101. SPMScheme eScheme;
  102. SPMState eState;
  103. SPMData *pNext;
  104. SPMData(LPSTR szScheme, DWORD dwFlags);
  105. ~SPMData();
  106. };
  107. // Global linked list of SPM providers.
  108. static SPMData *g_pSPMList;
  109. // Global spm list state
  110. static SPMState g_eState;
  111. // SubScheme - specifically for the negotiate
  112. // package - can be either NTLM or Kerberos.
  113. SPMScheme _eSubScheme;
  114. DWORD _dwSubFlags;
  115. public:
  116. // Instance specific;
  117. HTTP_REQUEST_HANDLE_OBJECT *_pRequest;
  118. SPMData *_pSPMData;
  119. LPVOID _pvContext;
  120. PWC *_pPWC;
  121. BOOL _fIsProxy;
  122. // credui stuff
  123. HMODULE _hCredUI;
  124. PFN_CREDUI_PROMPTFORCREDENTIALS _pfnCredUIPromptForCredentials;
  125. PFN_CREDUI_PROMPTFORCREDENTIALS_W _pfnCredUIPromptForCredentialsW;
  126. PFN_CREDUI_CONFIRMCREDENTIALS _pfnCredUIConfirmCredentials;
  127. BOOL InitCredUI(void);
  128. LPCSTR _pszFQDN;
  129. // Constructor
  130. AUTHCTX(SPMData *pSPM, PWC* pPWC);
  131. // Destructor
  132. virtual ~AUTHCTX();
  133. // ------------------------ Static Functions -----------------------------
  134. static VOID Enumerate();
  135. static VOID UnloadAll();
  136. static AUTHCTX* CreateAuthCtx(HTTP_REQUEST_HANDLE_OBJECT *pReq, BOOL fIsProxy);
  137. static AUTHCTX* CreateAuthCtx(HTTP_REQUEST_HANDLE_OBJECT *pReq, BOOL fIsProxy,
  138. LPSTR szScheme);
  139. static AUTHCTX* CreateAuthCtx(HTTP_REQUEST_HANDLE_OBJECT *pReq, BOOL fIsProxy,
  140. PWC* pPWC);
  141. static AUTHCTX::SPMState GetSPMListState();
  142. static PWC* SearchPwcList (PWC* pwc, LPSTR lpszHost, DWORD dwPort,
  143. LPSTR lpszUri, LPSTR lpszRealm, SPMData *pSPM);
  144. static PWC* FindOrCreatePWC
  145. (
  146. HTTP_REQUEST_HANDLE_OBJECT *pRequest,
  147. BOOL fIsProxy,
  148. SPMData *pSPM,
  149. LPSTR lpszRealm
  150. );
  151. static DWORD GetAuthHeaderData
  152. (
  153. HTTP_REQUEST_HANDLE_OBJECT *pRequest,
  154. BOOL fIsProxy,
  155. LPSTR szItem,
  156. LPSTR *pszData,
  157. LPDWORD pcbData,
  158. DWORD dwIndex,
  159. DWORD dwFlags
  160. );
  161. // ------------------------ Base class functions ---------------------------
  162. DWORD FindHdrIdxFromScheme(LPDWORD pdwIndex);
  163. LPSTR GetScheme();
  164. DWORD GetFlags();
  165. SPMState GetState();
  166. SPMScheme GetSchemeType();
  167. // ------------------------------ Overrides--------------------------------
  168. // Called before request to generate any pre-authentication headers.
  169. virtual DWORD PreAuthUser(IN LPSTR pBuf, IN OUT LPDWORD pcbBuf) = 0;
  170. // Retrieves response header data
  171. virtual DWORD UpdateFromHeaders(HTTP_REQUEST_HANDLE_OBJECT *pRequest, BOOL fIsProxy) = 0;
  172. // Called after UpdateFromHeaders to update authentication context.
  173. virtual DWORD PostAuthUser() = 0;
  174. };
  175. //-----------------------------------------------------------------------------
  176. //
  177. // BASIC_CTX
  178. //
  179. class BASIC_CTX : public AUTHCTX
  180. {
  181. public:
  182. BASIC_CTX(HTTP_REQUEST_HANDLE_OBJECT *pRequest, BOOL fIsProxy, SPMData* pSPM, PWC* pPWC);
  183. ~BASIC_CTX();
  184. // virtual overrides
  185. DWORD PreAuthUser(IN LPSTR pBuf, IN OUT LPDWORD pcbBuf);
  186. DWORD UpdateFromHeaders(HTTP_REQUEST_HANDLE_OBJECT *pRequest, BOOL fIsProxy);
  187. DWORD PostAuthUser();
  188. };
  189. //-----------------------------------------------------------------------------
  190. //
  191. // PASSPORT_CTX
  192. //
  193. class PASSPORT_CTX : public AUTHCTX
  194. {
  195. public:
  196. PASSPORT_CTX(HTTP_REQUEST_HANDLE_OBJECT *pRequest,
  197. BOOL fIsProxy,
  198. SPMData* pSPM,
  199. PWC* pPWC);
  200. ~PASSPORT_CTX();
  201. BOOL Init(void);
  202. // virtual overrides
  203. virtual DWORD PreAuthUser(IN LPSTR pBuf,
  204. IN OUT LPDWORD pcbBuf);
  205. virtual DWORD UpdateFromHeaders(HTTP_REQUEST_HANDLE_OBJECT *pRequest,
  206. BOOL fIsProxy);
  207. virtual DWORD PostAuthUser();
  208. BOOL PromptForCreds(HBITMAP* phBitmap, PWSTR pwszCbText, PDWORD pdwTextLen,
  209. PWSTR pwszReqUserName, PDWORD pdwReqUserNameLen);
  210. DWORD ModifyRequestBasedOnRU(void);
  211. void IndicatePrivacyEvents(void);
  212. DWORD SetCreds(BOOL* pfCredSet);
  213. void SetCredTimeStamp(PSYSTEMTIME pCredTimeStamp)
  214. {
  215. m_pCredTimestamp = pCredTimeStamp;
  216. }
  217. LPSTR m_lpszRetUrl;
  218. protected:
  219. BOOL InitLogonContext(void);
  220. BOOL CallbackRegistered(void);
  221. BOOL Transfer401ContentFromPP(void);
  222. DWORD HandleSuccessfulLogon(
  223. LPWSTR* ppwszFromPP,
  224. LPDWORD pdwFromPP,
  225. BOOL fPreAuth
  226. );
  227. enum
  228. {
  229. MAX_AUTH_TARGET_LEN = 256,
  230. MAX_AUTH_REALM_LEN = 128
  231. };
  232. PP_LOGON_CONTEXT m_hLogon;
  233. LPINTERNET_THREAD_INFO m_pNewThreadInfo;
  234. LPWSTR m_pwszPartnerInfo;
  235. WCHAR m_wRealm[MAX_AUTH_REALM_LEN];
  236. PSTR m_pszFromPP;
  237. PP_CONTEXT m_hPP;
  238. WCHAR m_wTarget[MAX_AUTH_TARGET_LEN];
  239. // BOOL m_fAuthDeferred;
  240. // BOOL m_fCredsBad;
  241. PSYSTEMTIME m_pCredTimestamp;
  242. BOOL m_fPreauthFailed;
  243. BOOL m_fAnonymous;
  244. HBITMAP m_hBitmap;
  245. PWSTR m_pwszCbText;
  246. DWORD m_dwCbTextLen;
  247. PWSTR m_pwszReqUserName;
  248. DWORD m_dwReqUserNameLen;
  249. };
  250. //-----------------------------------------------------------------------------
  251. //
  252. // PLUG_CTX
  253. //
  254. class PLUG_CTX : public AUTHCTX
  255. {
  256. public:
  257. // Class specific data.
  258. LPSTR _szAlloc;
  259. LPSTR _szData;
  260. DWORD _cbData;
  261. BOOL _fNTLMProxyAuth;
  262. SECURITY_STATUS _SecStatus;
  263. DWORD _dwResolutionId;
  264. // Class specific funcs.
  265. DWORD Load();
  266. DWORD ClearAuthUser(LPVOID *ppvContext, LPSTR szServer);
  267. PCSTR GetUrl(void) const;
  268. LPCSTR GetFQDN(LPCSTR lpszHostName);
  269. DWORD wQueryHeadersAlloc
  270. (
  271. IN HINTERNET hRequestMapped,
  272. IN DWORD dwQuery,
  273. OUT LPDWORD lpdwQueryIndex,
  274. OUT LPSTR *lppszOutStr,
  275. OUT LPDWORD lpdwSize
  276. );
  277. DWORD CrackAuthenticationHeader
  278. (
  279. IN HINTERNET hRequestMapped,
  280. IN BOOL fIsProxy,
  281. IN DWORD dwAuthenticationIndex,
  282. IN OUT LPSTR *lppszAuthHeader,
  283. IN OUT LPSTR *lppszExtra,
  284. IN OUT DWORD *lpdwExtra,
  285. OUT LPSTR *lppszAuthScheme
  286. );
  287. VOID ResolveProtocol();
  288. PLUG_CTX(HTTP_REQUEST_HANDLE_OBJECT *pRequest, BOOL fIsProxy, SPMData* pSPM, PWC* pPWC);
  289. ~PLUG_CTX();
  290. // virtual overrides
  291. DWORD PreAuthUser(IN LPSTR pBuf, IN OUT LPDWORD pcbBuf);
  292. DWORD UpdateFromHeaders(HTTP_REQUEST_HANDLE_OBJECT *pRequest, BOOL fIsProxy);
  293. DWORD PostAuthUser();
  294. };
  295. //-----------------------------------------------------------------------------
  296. //
  297. // DIGEST_CTX
  298. //
  299. class DIGEST_CTX : public AUTHCTX
  300. {
  301. protected:
  302. VOID GetFuncTbl();
  303. VOID InitSecurityBuffers(LPSTR szBuffOut, DWORD cbBuffOut,
  304. LPDWORD dwSecFlags, DWORD dwISCMode);
  305. LPSTR GetRequestUri();
  306. public:
  307. static PSecurityFunctionTable g_pFuncTbl;
  308. static CredHandle g_hCred;
  309. // Class specific data.
  310. SecBuffer _SecBuffIn[10];
  311. SecBufferDesc _SecBuffInDesc;
  312. SecBuffer _SecBuffOut[1];
  313. SecBufferDesc _SecBuffOutDesc;
  314. CtxtHandle _hCtxt;
  315. LPSTR _szAlloc;
  316. LPSTR _szData;
  317. LPSTR _szRequestUri;
  318. DWORD _cbContext;
  319. DWORD _cbData;
  320. DWORD _nRetries;
  321. DIGEST_CTX(HTTP_REQUEST_HANDLE_OBJECT *pRequest, BOOL fIsProxy, SPMData* pSPM, PWC* pPWC);
  322. ~DIGEST_CTX();
  323. DWORD PromptForCreds(HWND hWnd);
  324. // virtual overrides
  325. DWORD PreAuthUser(IN LPSTR pBuf, IN OUT LPDWORD pcbBuf);
  326. DWORD UpdateFromHeaders(HTTP_REQUEST_HANDLE_OBJECT *pRequest, BOOL fIsProxy);
  327. DWORD PostAuthUser();
  328. static VOID FlushCreds();
  329. static VOID Logoff();
  330. };
  331. //-----------------------------------------------------------------------------
  332. //
  333. // PWC class definition.
  334. //
  335. //
  336. struct PWC // PassWord Cache entry
  337. {
  338. PWC* pNext; // next item in linked list
  339. DWORD nLockCount; // number of references
  340. AUTHCTX::SPMData *pSPM; // Scheme
  341. LPSTR lpszHost; // name of server or proxy
  342. DWORD nPort; // dest port for server or proxy
  343. LPSTR lpszUrl; // url pattern with wildcard
  344. LPSTR lpszRealm; // realm, optional, may be null
  345. LPSTR lpszUser; // username, may be null
  346. LPSTR lpszPass; // password, may be null
  347. BOOL fPassEncrypted;
  348. DWORD dwPassBlobSize;
  349. LPSTR lpszNonce; // nonce value
  350. LPSTR lpszOpaque; // opaque value.
  351. BOOL fPreAuth; // allow preauthorization
  352. DWORD SetUser (LPSTR lpszUser);
  353. DWORD SetPass (LPSTR lpszUser);
  354. LPSTR GetUser (void) { return lpszUser;}
  355. LPSTR GetPass (void);
  356. };
  357. PWC *PWC_Create
  358. (
  359. LPSTR lpszHost,
  360. DWORD nPort,
  361. LPSTR lpszUrl,
  362. LPSTR lpszRealm,
  363. AUTHCTX::SPMData* pSPM
  364. );
  365. void PWC_Free (PWC *pwc);
  366. #ifndef ARRAY_ELEMENTS
  367. #define ARRAY_ELEMENTS(rg) (sizeof(rg) / sizeof((rg)[0]))
  368. #endif
  369. // password cache locking
  370. void AuthOpen (void);
  371. void AuthClose (void);
  372. void AuthLock (void);
  373. void AuthUnlock (void);
  374. // worker thread calls
  375. DWORD AuthOnRequest (HINTERNET hRequest);
  376. DWORD AuthOnResponse (HINTERNET hRequest);
  377. // dialog serialization
  378. BOOL AuthInDialog (AUTHCTX *pAuthCtx, INTERNET_AUTH_NOTIFY_DATA *pNotify, BOOL *pfMustLock);
  379. void AuthNotify (PWC *pwc, DWORD error);
  380. // cleanup
  381. void AuthFlush (void); // flush password cache
  382. void AuthUnload (void); // unload everything
  383. #endif // SPLUGIN_HXX