curl_gssapi.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 2011 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at https://curl.haxx.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. ***************************************************************************/
  22. #include "curl_setup.h"
  23. #ifdef HAVE_GSSAPI
  24. #include "curl_gssapi.h"
  25. #include "sendf.h"
  26. static char spnego_oid_bytes[] = "\x2b\x06\x01\x05\x05\x02";
  27. gss_OID_desc Curl_spnego_mech_oid = { 6, &spnego_oid_bytes };
  28. static char krb5_oid_bytes[] = "\x2a\x86\x48\x86\xf7\x12\x01\x02\x02";
  29. gss_OID_desc Curl_krb5_mech_oid = { 9, &krb5_oid_bytes };
  30. OM_uint32 Curl_gss_init_sec_context(
  31. struct SessionHandle *data,
  32. OM_uint32 *minor_status,
  33. gss_ctx_id_t *context,
  34. gss_name_t target_name,
  35. gss_OID mech_type,
  36. gss_channel_bindings_t input_chan_bindings,
  37. gss_buffer_t input_token,
  38. gss_buffer_t output_token,
  39. const bool mutual_auth,
  40. OM_uint32 *ret_flags)
  41. {
  42. OM_uint32 req_flags = GSS_C_REPLAY_FLAG;
  43. if(mutual_auth)
  44. req_flags |= GSS_C_MUTUAL_FLAG;
  45. if(data->set.gssapi_delegation & CURLGSSAPI_DELEGATION_POLICY_FLAG) {
  46. #ifdef GSS_C_DELEG_POLICY_FLAG
  47. req_flags |= GSS_C_DELEG_POLICY_FLAG;
  48. #else
  49. infof(data, "warning: support for CURLGSSAPI_DELEGATION_POLICY_FLAG not "
  50. "compiled in\n");
  51. #endif
  52. }
  53. if(data->set.gssapi_delegation & CURLGSSAPI_DELEGATION_FLAG)
  54. req_flags |= GSS_C_DELEG_FLAG;
  55. return gss_init_sec_context(minor_status,
  56. GSS_C_NO_CREDENTIAL, /* cred_handle */
  57. context,
  58. target_name,
  59. mech_type,
  60. req_flags,
  61. 0, /* time_req */
  62. input_chan_bindings,
  63. input_token,
  64. NULL, /* actual_mech_type */
  65. output_token,
  66. ret_flags,
  67. NULL /* time_rec */);
  68. }
  69. /*
  70. * Curl_gss_log_error()
  71. *
  72. * This is used to log a GSS-API error status.
  73. *
  74. * Parameters:
  75. *
  76. * data [in] - The session handle.
  77. * status [in] - The status code.
  78. * prefix [in] - The prefix of the log message.
  79. */
  80. void Curl_gss_log_error(struct SessionHandle *data, OM_uint32 status,
  81. const char *prefix)
  82. {
  83. OM_uint32 maj_stat;
  84. OM_uint32 min_stat;
  85. OM_uint32 msg_ctx = 0;
  86. gss_buffer_desc status_string;
  87. char buf[1024];
  88. size_t len;
  89. snprintf(buf, sizeof(buf), "%s", prefix);
  90. len = strlen(buf);
  91. do {
  92. maj_stat = gss_display_status(&min_stat,
  93. status,
  94. GSS_C_MECH_CODE,
  95. GSS_C_NO_OID,
  96. &msg_ctx,
  97. &status_string);
  98. if(sizeof(buf) > len + status_string.length + 1) {
  99. snprintf(buf + len, sizeof(buf) - len,
  100. ": %s", (char*)status_string.value);
  101. len += status_string.length;
  102. }
  103. gss_release_buffer(&min_stat, &status_string);
  104. } while(!GSS_ERROR(maj_stat) && msg_ctx != 0);
  105. infof(data, "%s\n", buf);
  106. }
  107. #endif /* HAVE_GSSAPI */