http_negotiate.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 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 #if !defined(CURL_DISABLE_HTTP) && defined(USE_SPNEGO)
00026 
00027 #include "urldata.h"
00028 #include "sendf.h"
00029 #include "http_negotiate.h"
00030 #include "vauth/vauth.h"
00031 
00032 /* The last 3 #include files should be in this order */
00033 #include "curl_printf.h"
00034 #include "curl_memory.h"
00035 #include "memdebug.h"
00036 
00037 CURLcode Curl_input_negotiate(struct connectdata *conn, bool proxy,
00038                               const char *header)
00039 {
00040   CURLcode result;
00041   struct Curl_easy *data = conn->data;
00042   size_t len;
00043 
00044   /* Point to the username, password, service and host */
00045   const char *userp;
00046   const char *passwdp;
00047   const char *service;
00048   const char *host;
00049 
00050   /* Point to the correct struct with this */
00051   struct negotiatedata *neg_ctx;
00052 
00053   if(proxy) {
00054     userp = conn->http_proxy.user;
00055     passwdp = conn->http_proxy.passwd;
00056     service = data->set.str[STRING_PROXY_SERVICE_NAME] ?
00057               data->set.str[STRING_PROXY_SERVICE_NAME] : "HTTP";
00058     host = conn->http_proxy.host.name;
00059     neg_ctx = &data->state.proxyneg;
00060   }
00061   else {
00062     userp = conn->user;
00063     passwdp = conn->passwd;
00064     service = data->set.str[STRING_SERVICE_NAME] ?
00065               data->set.str[STRING_SERVICE_NAME] : "HTTP";
00066     host = conn->host.name;
00067     neg_ctx = &data->state.negotiate;
00068   }
00069 
00070   /* Not set means empty */
00071   if(!userp)
00072     userp = "";
00073 
00074   if(!passwdp)
00075     passwdp = "";
00076 
00077   /* Obtain the input token, if any */
00078   header += strlen("Negotiate");
00079   while(*header && ISSPACE(*header))
00080     header++;
00081 
00082   len = strlen(header);
00083   if(!len) {
00084     /* Is this the first call in a new negotiation? */
00085     if(neg_ctx->context) {
00086       /* The server rejected our authentication and hasn't suppled any more
00087       negotiation mechanisms */
00088       return CURLE_LOGIN_DENIED;
00089     }
00090   }
00091 
00092   /* Initilise the security context and decode our challenge */
00093   result = Curl_auth_decode_spnego_message(data, userp, passwdp, service,
00094                                            host, header, neg_ctx);
00095 
00096   if(result)
00097     Curl_auth_spnego_cleanup(neg_ctx);
00098 
00099   return result;
00100 }
00101 
00102 CURLcode Curl_output_negotiate(struct connectdata *conn, bool proxy)
00103 {
00104   struct negotiatedata *neg_ctx = proxy ? &conn->data->state.proxyneg :
00105     &conn->data->state.negotiate;
00106   char *base64 = NULL;
00107   size_t len = 0;
00108   char *userp;
00109   CURLcode result;
00110 
00111   result = Curl_auth_create_spnego_message(conn->data, neg_ctx, &base64, &len);
00112   if(result)
00113     return result;
00114 
00115   userp = aprintf("%sAuthorization: Negotiate %s\r\n", proxy ? "Proxy-" : "",
00116                   base64);
00117 
00118   if(proxy) {
00119     Curl_safefree(conn->allocptr.proxyuserpwd);
00120     conn->allocptr.proxyuserpwd = userp;
00121   }
00122   else {
00123     Curl_safefree(conn->allocptr.userpwd);
00124     conn->allocptr.userpwd = userp;
00125   }
00126 
00127   free(base64);
00128 
00129   return (userp == NULL) ? CURLE_OUT_OF_MEMORY : CURLE_OK;
00130 }
00131 
00132 void Curl_cleanup_negotiate(struct Curl_easy *data)
00133 {
00134   Curl_auth_spnego_cleanup(&data->state.negotiate);
00135   Curl_auth_spnego_cleanup(&data->state.proxyneg);
00136 }
00137 
00138 #endif /* !CURL_DISABLE_HTTP && USE_SPNEGO */


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