curl_gssapi.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 2011 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
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, /* cred_handle */
00066                               context,
00067                               target_name,
00068                               mech_type,
00069                               req_flags,
00070                               0, /* time_req */
00071                               input_chan_bindings,
00072                               input_token,
00073                               NULL, /* actual_mech_type */
00074                               output_token,
00075                               ret_flags,
00076                               NULL /* time_rec */);
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  * Curl_gss_log_error()
00107  *
00108  * This is used to log a GSS-API error status.
00109  *
00110  * Parameters:
00111  *
00112  * data    [in] - The session handle.
00113  * prefix  [in] - The prefix of the log message.
00114  * major   [in] - The major status code.
00115  * minor   [in] - The minor status code.
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 /* HAVE_GSSAPI */


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:02