Go to the documentation of this file.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 #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
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
00045 const char *userp;
00046 const char *passwdp;
00047 const char *service;
00048 const char *host;
00049
00050
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
00071 if(!userp)
00072 userp = "";
00073
00074 if(!passwdp)
00075 passwdp = "";
00076
00077
00078 header += strlen("Negotiate");
00079 while(*header && ISSPACE(*header))
00080 header++;
00081
00082 len = strlen(header);
00083 if(!len) {
00084
00085 if(neg_ctx->context) {
00086
00087
00088 return CURLE_LOGIN_DENIED;
00089 }
00090 }
00091
00092
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