00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "curl_setup.h"
00024
00025 #ifdef HAVE_GSSAPI
00026
00027 #include "curl_gssapi.h"
00028 #include "sendf.h"
00029
00030 static char spnego_oid_bytes[] = "\x2b\x06\x01\x05\x05\x02";
00031 gss_OID_desc Curl_spnego_mech_oid = { 6, &spnego_oid_bytes };
00032 static char krb5_oid_bytes[] = "\x2a\x86\x48\x86\xf7\x12\x01\x02\x02";
00033 gss_OID_desc Curl_krb5_mech_oid = { 9, &krb5_oid_bytes };
00034
00035 OM_uint32 Curl_gss_init_sec_context(
00036 struct Curl_easy *data,
00037 OM_uint32 *minor_status,
00038 gss_ctx_id_t *context,
00039 gss_name_t target_name,
00040 gss_OID mech_type,
00041 gss_channel_bindings_t input_chan_bindings,
00042 gss_buffer_t input_token,
00043 gss_buffer_t output_token,
00044 const bool mutual_auth,
00045 OM_uint32 *ret_flags)
00046 {
00047 OM_uint32 req_flags = GSS_C_REPLAY_FLAG;
00048
00049 if(mutual_auth)
00050 req_flags |= GSS_C_MUTUAL_FLAG;
00051
00052 if(data->set.gssapi_delegation & CURLGSSAPI_DELEGATION_POLICY_FLAG) {
00053 #ifdef GSS_C_DELEG_POLICY_FLAG
00054 req_flags |= GSS_C_DELEG_POLICY_FLAG;
00055 #else
00056 infof(data, "warning: support for CURLGSSAPI_DELEGATION_POLICY_FLAG not "
00057 "compiled in\n");
00058 #endif
00059 }
00060
00061 if(data->set.gssapi_delegation & CURLGSSAPI_DELEGATION_FLAG)
00062 req_flags |= GSS_C_DELEG_FLAG;
00063
00064 return gss_init_sec_context(minor_status,
00065 GSS_C_NO_CREDENTIAL,
00066 context,
00067 target_name,
00068 mech_type,
00069 req_flags,
00070 0,
00071 input_chan_bindings,
00072 input_token,
00073 NULL,
00074 output_token,
00075 ret_flags,
00076 NULL );
00077 }
00078
00079 #define GSS_LOG_BUFFER_LEN 1024
00080 static size_t display_gss_error(OM_uint32 status, int type,
00081 char *buf, size_t len) {
00082 OM_uint32 maj_stat;
00083 OM_uint32 min_stat;
00084 OM_uint32 msg_ctx = 0;
00085 gss_buffer_desc status_string;
00086
00087 do {
00088 maj_stat = gss_display_status(&min_stat,
00089 status,
00090 type,
00091 GSS_C_NO_OID,
00092 &msg_ctx,
00093 &status_string);
00094 if(GSS_LOG_BUFFER_LEN > len + status_string.length + 3) {
00095 len += snprintf(buf + len, GSS_LOG_BUFFER_LEN - len,
00096 "%.*s. ", (int)status_string.length,
00097 (char *)status_string.value);
00098 }
00099 gss_release_buffer(&min_stat, &status_string);
00100 } while(!GSS_ERROR(maj_stat) && msg_ctx != 0);
00101
00102 return len;
00103 }
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 void Curl_gss_log_error(struct Curl_easy *data, const char *prefix,
00118 OM_uint32 major, OM_uint32 minor)
00119 {
00120 char buf[GSS_LOG_BUFFER_LEN];
00121 size_t len = 0;
00122
00123 if(major != GSS_S_FAILURE)
00124 len = display_gss_error(major, GSS_C_GSS_CODE, buf, len);
00125
00126 display_gss_error(minor, GSS_C_MECH_CODE, buf, len);
00127
00128 infof(data, "%s%s\n", prefix, buf);
00129 }
00130
00131 #endif