curl_sspi.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. #ifndef HEADER_CURL_SSPI_H
  2. #define HEADER_CURL_SSPI_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  11. *
  12. * This software is licensed as described in the file COPYING, which
  13. * you should have received as part of this distribution. The terms
  14. * are also available at https://curl.se/docs/copyright.html.
  15. *
  16. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  17. * copies of the Software, and permit persons to whom the Software is
  18. * furnished to do so, under the terms of the COPYING file.
  19. *
  20. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  21. * KIND, either express or implied.
  22. *
  23. * SPDX-License-Identifier: curl
  24. *
  25. ***************************************************************************/
  26. #include "curl_setup.h"
  27. #ifdef USE_WINDOWS_SSPI
  28. #include <curl/curl.h>
  29. /*
  30. * When including the following three headers, it is mandatory to define either
  31. * SECURITY_WIN32 or SECURITY_KERNEL, indicating who is compiling the code.
  32. */
  33. #undef SECURITY_WIN32
  34. #undef SECURITY_KERNEL
  35. #define SECURITY_WIN32 1
  36. #include <security.h>
  37. #include <sspi.h>
  38. #include <rpc.h>
  39. CURLcode Curl_sspi_global_init(void);
  40. void Curl_sspi_global_cleanup(void);
  41. /* This is used to populate the domain in a SSPI identity structure */
  42. CURLcode Curl_override_sspi_http_realm(const char *chlg,
  43. SEC_WINNT_AUTH_IDENTITY *identity);
  44. /* This is used to generate an SSPI identity structure */
  45. CURLcode Curl_create_sspi_identity(const char *userp, const char *passwdp,
  46. SEC_WINNT_AUTH_IDENTITY *identity);
  47. /* This is used to free an SSPI identity structure */
  48. void Curl_sspi_free_identity(SEC_WINNT_AUTH_IDENTITY *identity);
  49. /* Forward-declaration of global variables defined in curl_sspi.c */
  50. extern HMODULE s_hSecDll;
  51. extern PSecurityFunctionTable s_pSecFn;
  52. /* Provide some definitions missing in old headers */
  53. #define SP_NAME_DIGEST "WDigest"
  54. #define SP_NAME_NTLM "NTLM"
  55. #define SP_NAME_NEGOTIATE "Negotiate"
  56. #define SP_NAME_KERBEROS "Kerberos"
  57. #ifndef ISC_REQ_USE_HTTP_STYLE
  58. #define ISC_REQ_USE_HTTP_STYLE 0x01000000
  59. #endif
  60. #ifndef ISC_RET_REPLAY_DETECT
  61. #define ISC_RET_REPLAY_DETECT 0x00000004
  62. #endif
  63. #ifndef ISC_RET_SEQUENCE_DETECT
  64. #define ISC_RET_SEQUENCE_DETECT 0x00000008
  65. #endif
  66. #ifndef ISC_RET_CONFIDENTIALITY
  67. #define ISC_RET_CONFIDENTIALITY 0x00000010
  68. #endif
  69. #ifndef ISC_RET_ALLOCATED_MEMORY
  70. #define ISC_RET_ALLOCATED_MEMORY 0x00000100
  71. #endif
  72. #ifndef ISC_RET_STREAM
  73. #define ISC_RET_STREAM 0x00008000
  74. #endif
  75. #ifndef SEC_E_INSUFFICIENT_MEMORY
  76. # define SEC_E_INSUFFICIENT_MEMORY ((HRESULT)0x80090300L)
  77. #endif
  78. #ifndef SEC_E_INVALID_HANDLE
  79. # define SEC_E_INVALID_HANDLE ((HRESULT)0x80090301L)
  80. #endif
  81. #ifndef SEC_E_UNSUPPORTED_FUNCTION
  82. # define SEC_E_UNSUPPORTED_FUNCTION ((HRESULT)0x80090302L)
  83. #endif
  84. #ifndef SEC_E_TARGET_UNKNOWN
  85. # define SEC_E_TARGET_UNKNOWN ((HRESULT)0x80090303L)
  86. #endif
  87. #ifndef SEC_E_INTERNAL_ERROR
  88. # define SEC_E_INTERNAL_ERROR ((HRESULT)0x80090304L)
  89. #endif
  90. #ifndef SEC_E_SECPKG_NOT_FOUND
  91. # define SEC_E_SECPKG_NOT_FOUND ((HRESULT)0x80090305L)
  92. #endif
  93. #ifndef SEC_E_NOT_OWNER
  94. # define SEC_E_NOT_OWNER ((HRESULT)0x80090306L)
  95. #endif
  96. #ifndef SEC_E_CANNOT_INSTALL
  97. # define SEC_E_CANNOT_INSTALL ((HRESULT)0x80090307L)
  98. #endif
  99. #ifndef SEC_E_INVALID_TOKEN
  100. # define SEC_E_INVALID_TOKEN ((HRESULT)0x80090308L)
  101. #endif
  102. #ifndef SEC_E_CANNOT_PACK
  103. # define SEC_E_CANNOT_PACK ((HRESULT)0x80090309L)
  104. #endif
  105. #ifndef SEC_E_QOP_NOT_SUPPORTED
  106. # define SEC_E_QOP_NOT_SUPPORTED ((HRESULT)0x8009030AL)
  107. #endif
  108. #ifndef SEC_E_NO_IMPERSONATION
  109. # define SEC_E_NO_IMPERSONATION ((HRESULT)0x8009030BL)
  110. #endif
  111. #ifndef SEC_E_LOGON_DENIED
  112. # define SEC_E_LOGON_DENIED ((HRESULT)0x8009030CL)
  113. #endif
  114. #ifndef SEC_E_UNKNOWN_CREDENTIALS
  115. # define SEC_E_UNKNOWN_CREDENTIALS ((HRESULT)0x8009030DL)
  116. #endif
  117. #ifndef SEC_E_NO_CREDENTIALS
  118. # define SEC_E_NO_CREDENTIALS ((HRESULT)0x8009030EL)
  119. #endif
  120. #ifndef SEC_E_MESSAGE_ALTERED
  121. # define SEC_E_MESSAGE_ALTERED ((HRESULT)0x8009030FL)
  122. #endif
  123. #ifndef SEC_E_OUT_OF_SEQUENCE
  124. # define SEC_E_OUT_OF_SEQUENCE ((HRESULT)0x80090310L)
  125. #endif
  126. #ifndef SEC_E_NO_AUTHENTICATING_AUTHORITY
  127. # define SEC_E_NO_AUTHENTICATING_AUTHORITY ((HRESULT)0x80090311L)
  128. #endif
  129. #ifndef SEC_E_BAD_PKGID
  130. # define SEC_E_BAD_PKGID ((HRESULT)0x80090316L)
  131. #endif
  132. #ifndef SEC_E_CONTEXT_EXPIRED
  133. # define SEC_E_CONTEXT_EXPIRED ((HRESULT)0x80090317L)
  134. #endif
  135. #ifndef SEC_E_INCOMPLETE_MESSAGE
  136. # define SEC_E_INCOMPLETE_MESSAGE ((HRESULT)0x80090318L)
  137. #endif
  138. #ifndef SEC_E_INCOMPLETE_CREDENTIALS
  139. # define SEC_E_INCOMPLETE_CREDENTIALS ((HRESULT)0x80090320L)
  140. #endif
  141. #ifndef SEC_E_BUFFER_TOO_SMALL
  142. # define SEC_E_BUFFER_TOO_SMALL ((HRESULT)0x80090321L)
  143. #endif
  144. #ifndef SEC_E_WRONG_PRINCIPAL
  145. # define SEC_E_WRONG_PRINCIPAL ((HRESULT)0x80090322L)
  146. #endif
  147. #ifndef SEC_E_TIME_SKEW
  148. # define SEC_E_TIME_SKEW ((HRESULT)0x80090324L)
  149. #endif
  150. #ifndef SEC_E_UNTRUSTED_ROOT
  151. # define SEC_E_UNTRUSTED_ROOT ((HRESULT)0x80090325L)
  152. #endif
  153. #ifndef SEC_E_ILLEGAL_MESSAGE
  154. # define SEC_E_ILLEGAL_MESSAGE ((HRESULT)0x80090326L)
  155. #endif
  156. #ifndef SEC_E_CERT_UNKNOWN
  157. # define SEC_E_CERT_UNKNOWN ((HRESULT)0x80090327L)
  158. #endif
  159. #ifndef SEC_E_CERT_EXPIRED
  160. # define SEC_E_CERT_EXPIRED ((HRESULT)0x80090328L)
  161. #endif
  162. #ifndef SEC_E_ENCRYPT_FAILURE
  163. # define SEC_E_ENCRYPT_FAILURE ((HRESULT)0x80090329L)
  164. #endif
  165. #ifndef SEC_E_DECRYPT_FAILURE
  166. # define SEC_E_DECRYPT_FAILURE ((HRESULT)0x80090330L)
  167. #endif
  168. #ifndef SEC_E_ALGORITHM_MISMATCH
  169. # define SEC_E_ALGORITHM_MISMATCH ((HRESULT)0x80090331L)
  170. #endif
  171. #ifndef SEC_E_SECURITY_QOS_FAILED
  172. # define SEC_E_SECURITY_QOS_FAILED ((HRESULT)0x80090332L)
  173. #endif
  174. #ifndef SEC_E_UNFINISHED_CONTEXT_DELETED
  175. # define SEC_E_UNFINISHED_CONTEXT_DELETED ((HRESULT)0x80090333L)
  176. #endif
  177. #ifndef SEC_E_NO_TGT_REPLY
  178. # define SEC_E_NO_TGT_REPLY ((HRESULT)0x80090334L)
  179. #endif
  180. #ifndef SEC_E_NO_IP_ADDRESSES
  181. # define SEC_E_NO_IP_ADDRESSES ((HRESULT)0x80090335L)
  182. #endif
  183. #ifndef SEC_E_WRONG_CREDENTIAL_HANDLE
  184. # define SEC_E_WRONG_CREDENTIAL_HANDLE ((HRESULT)0x80090336L)
  185. #endif
  186. #ifndef SEC_E_CRYPTO_SYSTEM_INVALID
  187. # define SEC_E_CRYPTO_SYSTEM_INVALID ((HRESULT)0x80090337L)
  188. #endif
  189. #ifndef SEC_E_MAX_REFERRALS_EXCEEDED
  190. # define SEC_E_MAX_REFERRALS_EXCEEDED ((HRESULT)0x80090338L)
  191. #endif
  192. #ifndef SEC_E_MUST_BE_KDC
  193. # define SEC_E_MUST_BE_KDC ((HRESULT)0x80090339L)
  194. #endif
  195. #ifndef SEC_E_STRONG_CRYPTO_NOT_SUPPORTED
  196. # define SEC_E_STRONG_CRYPTO_NOT_SUPPORTED ((HRESULT)0x8009033AL)
  197. #endif
  198. #ifndef SEC_E_TOO_MANY_PRINCIPALS
  199. # define SEC_E_TOO_MANY_PRINCIPALS ((HRESULT)0x8009033BL)
  200. #endif
  201. #ifndef SEC_E_NO_PA_DATA
  202. # define SEC_E_NO_PA_DATA ((HRESULT)0x8009033CL)
  203. #endif
  204. #ifndef SEC_E_PKINIT_NAME_MISMATCH
  205. # define SEC_E_PKINIT_NAME_MISMATCH ((HRESULT)0x8009033DL)
  206. #endif
  207. #ifndef SEC_E_SMARTCARD_LOGON_REQUIRED
  208. # define SEC_E_SMARTCARD_LOGON_REQUIRED ((HRESULT)0x8009033EL)
  209. #endif
  210. #ifndef SEC_E_SHUTDOWN_IN_PROGRESS
  211. # define SEC_E_SHUTDOWN_IN_PROGRESS ((HRESULT)0x8009033FL)
  212. #endif
  213. #ifndef SEC_E_KDC_INVALID_REQUEST
  214. # define SEC_E_KDC_INVALID_REQUEST ((HRESULT)0x80090340L)
  215. #endif
  216. #ifndef SEC_E_KDC_UNABLE_TO_REFER
  217. # define SEC_E_KDC_UNABLE_TO_REFER ((HRESULT)0x80090341L)
  218. #endif
  219. #ifndef SEC_E_KDC_UNKNOWN_ETYPE
  220. # define SEC_E_KDC_UNKNOWN_ETYPE ((HRESULT)0x80090342L)
  221. #endif
  222. #ifndef SEC_E_UNSUPPORTED_PREAUTH
  223. # define SEC_E_UNSUPPORTED_PREAUTH ((HRESULT)0x80090343L)
  224. #endif
  225. #ifndef SEC_E_DELEGATION_REQUIRED
  226. # define SEC_E_DELEGATION_REQUIRED ((HRESULT)0x80090345L)
  227. #endif
  228. #ifndef SEC_E_BAD_BINDINGS
  229. # define SEC_E_BAD_BINDINGS ((HRESULT)0x80090346L)
  230. #endif
  231. #ifndef SEC_E_MULTIPLE_ACCOUNTS
  232. # define SEC_E_MULTIPLE_ACCOUNTS ((HRESULT)0x80090347L)
  233. #endif
  234. #ifndef SEC_E_NO_KERB_KEY
  235. # define SEC_E_NO_KERB_KEY ((HRESULT)0x80090348L)
  236. #endif
  237. #ifndef SEC_E_CERT_WRONG_USAGE
  238. # define SEC_E_CERT_WRONG_USAGE ((HRESULT)0x80090349L)
  239. #endif
  240. #ifndef SEC_E_DOWNGRADE_DETECTED
  241. # define SEC_E_DOWNGRADE_DETECTED ((HRESULT)0x80090350L)
  242. #endif
  243. #ifndef SEC_E_SMARTCARD_CERT_REVOKED
  244. # define SEC_E_SMARTCARD_CERT_REVOKED ((HRESULT)0x80090351L)
  245. #endif
  246. #ifndef SEC_E_ISSUING_CA_UNTRUSTED
  247. # define SEC_E_ISSUING_CA_UNTRUSTED ((HRESULT)0x80090352L)
  248. #endif
  249. #ifndef SEC_E_REVOCATION_OFFLINE_C
  250. # define SEC_E_REVOCATION_OFFLINE_C ((HRESULT)0x80090353L)
  251. #endif
  252. #ifndef SEC_E_PKINIT_CLIENT_FAILURE
  253. # define SEC_E_PKINIT_CLIENT_FAILURE ((HRESULT)0x80090354L)
  254. #endif
  255. #ifndef SEC_E_SMARTCARD_CERT_EXPIRED
  256. # define SEC_E_SMARTCARD_CERT_EXPIRED ((HRESULT)0x80090355L)
  257. #endif
  258. #ifndef SEC_E_NO_S4U_PROT_SUPPORT
  259. # define SEC_E_NO_S4U_PROT_SUPPORT ((HRESULT)0x80090356L)
  260. #endif
  261. #ifndef SEC_E_CROSSREALM_DELEGATION_FAILURE
  262. # define SEC_E_CROSSREALM_DELEGATION_FAILURE ((HRESULT)0x80090357L)
  263. #endif
  264. #ifndef SEC_E_REVOCATION_OFFLINE_KDC
  265. # define SEC_E_REVOCATION_OFFLINE_KDC ((HRESULT)0x80090358L)
  266. #endif
  267. #ifndef SEC_E_ISSUING_CA_UNTRUSTED_KDC
  268. # define SEC_E_ISSUING_CA_UNTRUSTED_KDC ((HRESULT)0x80090359L)
  269. #endif
  270. #ifndef SEC_E_KDC_CERT_EXPIRED
  271. # define SEC_E_KDC_CERT_EXPIRED ((HRESULT)0x8009035AL)
  272. #endif
  273. #ifndef SEC_E_KDC_CERT_REVOKED
  274. # define SEC_E_KDC_CERT_REVOKED ((HRESULT)0x8009035BL)
  275. #endif
  276. #ifndef SEC_E_INVALID_PARAMETER
  277. # define SEC_E_INVALID_PARAMETER ((HRESULT)0x8009035DL)
  278. #endif
  279. #ifndef SEC_E_DELEGATION_POLICY
  280. # define SEC_E_DELEGATION_POLICY ((HRESULT)0x8009035EL)
  281. #endif
  282. #ifndef SEC_E_POLICY_NLTM_ONLY
  283. # define SEC_E_POLICY_NLTM_ONLY ((HRESULT)0x8009035FL)
  284. #endif
  285. #ifndef SEC_I_CONTINUE_NEEDED
  286. # define SEC_I_CONTINUE_NEEDED ((HRESULT)0x00090312L)
  287. #endif
  288. #ifndef SEC_I_COMPLETE_NEEDED
  289. # define SEC_I_COMPLETE_NEEDED ((HRESULT)0x00090313L)
  290. #endif
  291. #ifndef SEC_I_COMPLETE_AND_CONTINUE
  292. # define SEC_I_COMPLETE_AND_CONTINUE ((HRESULT)0x00090314L)
  293. #endif
  294. #ifndef SEC_I_LOCAL_LOGON
  295. # define SEC_I_LOCAL_LOGON ((HRESULT)0x00090315L)
  296. #endif
  297. #ifndef SEC_I_CONTEXT_EXPIRED
  298. # define SEC_I_CONTEXT_EXPIRED ((HRESULT)0x00090317L)
  299. #endif
  300. #ifndef SEC_I_INCOMPLETE_CREDENTIALS
  301. # define SEC_I_INCOMPLETE_CREDENTIALS ((HRESULT)0x00090320L)
  302. #endif
  303. #ifndef SEC_I_RENEGOTIATE
  304. # define SEC_I_RENEGOTIATE ((HRESULT)0x00090321L)
  305. #endif
  306. #ifndef SEC_I_NO_LSA_CONTEXT
  307. # define SEC_I_NO_LSA_CONTEXT ((HRESULT)0x00090323L)
  308. #endif
  309. #ifndef SEC_I_SIGNATURE_NEEDED
  310. # define SEC_I_SIGNATURE_NEEDED ((HRESULT)0x0009035CL)
  311. #endif
  312. #ifndef CRYPT_E_REVOKED
  313. # define CRYPT_E_REVOKED ((HRESULT)0x80092010L)
  314. #endif
  315. #ifdef UNICODE
  316. # define SECFLAG_WINNT_AUTH_IDENTITY \
  317. (unsigned long)SEC_WINNT_AUTH_IDENTITY_UNICODE
  318. #else
  319. # define SECFLAG_WINNT_AUTH_IDENTITY \
  320. (unsigned long)SEC_WINNT_AUTH_IDENTITY_ANSI
  321. #endif
  322. /*
  323. * Definitions required from ntsecapi.h are directly provided below this point
  324. * to avoid including ntsecapi.h due to a conflict with OpenSSL's safestack.h
  325. */
  326. #define KERB_WRAP_NO_ENCRYPT 0x80000001
  327. #endif /* USE_WINDOWS_SSPI */
  328. #endif /* HEADER_CURL_SSPI_H */