Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 1 | /* GSSAPI/krb5 support for FTP - loosely based on old krb4.c |
| 2 | * |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 3 | * Copyright (c) 1995, 1996, 1997, 1998, 1999 Kungliga Tekniska Högskolan |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 4 | * (Royal Institute of Technology, Stockholm, Sweden). |
Elliott Hughes | 0128fe4 | 2018-02-27 14:57:55 -0800 | [diff] [blame] | 5 | * Copyright (c) 2004 - 2017 Daniel Stenberg |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 6 | * All rights reserved. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions |
| 10 | * are met: |
| 11 | * |
| 12 | * 1. Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * |
| 15 | * 2. Redistributions in binary form must reproduce the above copyright |
| 16 | * notice, this list of conditions and the following disclaimer in the |
| 17 | * documentation and/or other materials provided with the distribution. |
| 18 | * |
| 19 | * 3. Neither the name of the Institute nor the names of its contributors |
| 20 | * may be used to endorse or promote products derived from this software |
| 21 | * without specific prior written permission. |
| 22 | * |
| 23 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND |
| 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE |
| 27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 33 | * SUCH DAMAGE. */ |
| 34 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 35 | #include "curl_setup.h" |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 36 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 37 | #if defined(HAVE_GSSAPI) && !defined(CURL_DISABLE_FTP) |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 38 | |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 39 | #ifdef HAVE_NETDB_H |
| 40 | #include <netdb.h> |
| 41 | #endif |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 42 | |
| 43 | #include "urldata.h" |
| 44 | #include "curl_base64.h" |
| 45 | #include "ftp.h" |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 46 | #include "curl_gssapi.h" |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 47 | #include "sendf.h" |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 48 | #include "curl_sec.h" |
| 49 | #include "warnless.h" |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 50 | |
Alex Deymo | d15eaac | 2016-06-28 14:49:26 -0700 | [diff] [blame] | 51 | /* The last 3 #include files should be in this order */ |
| 52 | #include "curl_printf.h" |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 53 | #include "curl_memory.h" |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 54 | #include "memdebug.h" |
| 55 | |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 56 | static int |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 57 | krb5_init(void *app_data) |
| 58 | { |
| 59 | gss_ctx_id_t *context = app_data; |
| 60 | /* Make sure our context is initialized for krb5_end. */ |
| 61 | *context = GSS_C_NO_CONTEXT; |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | static int |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 66 | krb5_check_prot(void *app_data, int level) |
| 67 | { |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 68 | (void)app_data; /* unused */ |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 69 | if(level == PROT_CONFIDENTIAL) |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 70 | return -1; |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | static int |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 75 | krb5_decode(void *app_data, void *buf, int len, |
| 76 | int level UNUSED_PARAM, |
| 77 | struct connectdata *conn UNUSED_PARAM) |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 78 | { |
| 79 | gss_ctx_id_t *context = app_data; |
| 80 | OM_uint32 maj, min; |
| 81 | gss_buffer_desc enc, dec; |
| 82 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 83 | (void)level; |
| 84 | (void)conn; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 85 | |
| 86 | enc.value = buf; |
| 87 | enc.length = len; |
Elliott Hughes | cac3980 | 2018-04-27 16:19:43 -0700 | [diff] [blame] | 88 | maj = gss_unwrap(&min, *context, &enc, &dec, NULL, NULL); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 89 | if(maj != GSS_S_COMPLETE) { |
| 90 | if(len >= 4) |
| 91 | strcpy(buf, "599 "); |
| 92 | return -1; |
| 93 | } |
| 94 | |
| 95 | memcpy(buf, dec.value, dec.length); |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 96 | len = curlx_uztosi(dec.length); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 97 | gss_release_buffer(&min, &dec); |
| 98 | |
| 99 | return len; |
| 100 | } |
| 101 | |
| 102 | static int |
| 103 | krb5_overhead(void *app_data, int level, int len) |
| 104 | { |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 105 | /* no arguments are used */ |
| 106 | (void)app_data; |
| 107 | (void)level; |
| 108 | (void)len; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 109 | return 0; |
| 110 | } |
| 111 | |
| 112 | static int |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 113 | krb5_encode(void *app_data, const void *from, int length, int level, void **to) |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 114 | { |
| 115 | gss_ctx_id_t *context = app_data; |
| 116 | gss_buffer_desc dec, enc; |
| 117 | OM_uint32 maj, min; |
| 118 | int state; |
| 119 | int len; |
| 120 | |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 121 | /* NOTE that the cast is safe, neither of the krb5, gnu gss and heimdal |
Elliott Hughes | cac3980 | 2018-04-27 16:19:43 -0700 | [diff] [blame] | 122 | * libraries modify the input buffer in gss_wrap() |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 123 | */ |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 124 | dec.value = (void *)from; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 125 | dec.length = length; |
Elliott Hughes | cac3980 | 2018-04-27 16:19:43 -0700 | [diff] [blame] | 126 | maj = gss_wrap(&min, *context, |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 127 | level == PROT_PRIVATE, |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 128 | GSS_C_QOP_DEFAULT, |
| 129 | &dec, &state, &enc); |
| 130 | |
| 131 | if(maj != GSS_S_COMPLETE) |
| 132 | return -1; |
| 133 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 134 | /* malloc a new buffer, in case gss_release_buffer doesn't work as |
| 135 | expected */ |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 136 | *to = malloc(enc.length); |
| 137 | if(!*to) |
| 138 | return -1; |
| 139 | memcpy(*to, enc.value, enc.length); |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 140 | len = curlx_uztosi(enc.length); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 141 | gss_release_buffer(&min, &enc); |
| 142 | return len; |
| 143 | } |
| 144 | |
| 145 | static int |
| 146 | krb5_auth(void *app_data, struct connectdata *conn) |
| 147 | { |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 148 | int ret = AUTH_OK; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 149 | char *p; |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 150 | const char *host = conn->host.name; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 151 | ssize_t nread; |
| 152 | curl_socklen_t l = sizeof(conn->local_addr); |
Alex Deymo | e3149cc | 2016-10-05 11:18:42 -0700 | [diff] [blame] | 153 | struct Curl_easy *data = conn->data; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 154 | CURLcode result; |
Alex Deymo | d15eaac | 2016-06-28 14:49:26 -0700 | [diff] [blame] | 155 | const char *service = data->set.str[STRING_SERVICE_NAME] ? |
| 156 | data->set.str[STRING_SERVICE_NAME] : |
| 157 | "ftp"; |
| 158 | const char *srv_host = "host"; |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 159 | gss_buffer_desc input_buffer, output_buffer, _gssresp, *gssresp; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 160 | OM_uint32 maj, min; |
| 161 | gss_name_t gssname; |
| 162 | gss_ctx_id_t *context = app_data; |
| 163 | struct gss_channel_bindings_struct chan; |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 164 | size_t base64_sz = 0; |
Alex Deymo | d15eaac | 2016-06-28 14:49:26 -0700 | [diff] [blame] | 165 | struct sockaddr_in **remote_addr = |
| 166 | (struct sockaddr_in **)&conn->ip_addr->ai_addr; |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 167 | char *stringp; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 168 | |
| 169 | if(getsockname(conn->sock[FIRSTSOCKET], |
Alex Deymo | d15eaac | 2016-06-28 14:49:26 -0700 | [diff] [blame] | 170 | (struct sockaddr *)&conn->local_addr, &l) < 0) |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 171 | perror("getsockname()"); |
| 172 | |
| 173 | chan.initiator_addrtype = GSS_C_AF_INET; |
| 174 | chan.initiator_address.length = l - 4; |
Alex Deymo | d15eaac | 2016-06-28 14:49:26 -0700 | [diff] [blame] | 175 | chan.initiator_address.value = &conn->local_addr.sin_addr.s_addr; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 176 | chan.acceptor_addrtype = GSS_C_AF_INET; |
| 177 | chan.acceptor_address.length = l - 4; |
Alex Deymo | d15eaac | 2016-06-28 14:49:26 -0700 | [diff] [blame] | 178 | chan.acceptor_address.value = &(*remote_addr)->sin_addr.s_addr; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 179 | chan.application_data.length = 0; |
| 180 | chan.application_data.value = NULL; |
| 181 | |
| 182 | /* this loop will execute twice (once for service, once for host) */ |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 183 | for(;;) { |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 184 | /* this really shouldn't be repeated here, but can't help it */ |
| 185 | if(service == srv_host) { |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 186 | result = Curl_ftpsend(conn, "AUTH GSSAPI"); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 187 | if(result) |
| 188 | return -2; |
Alex Deymo | d15eaac | 2016-06-28 14:49:26 -0700 | [diff] [blame] | 189 | |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 190 | if(Curl_GetFTPResponse(&nread, conn, NULL)) |
| 191 | return -1; |
| 192 | |
| 193 | if(data->state.buffer[0] != '3') |
| 194 | return -1; |
| 195 | } |
| 196 | |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 197 | stringp = aprintf("%s@%s", service, host); |
| 198 | if(!stringp) |
| 199 | return -2; |
| 200 | |
| 201 | input_buffer.value = stringp; |
| 202 | input_buffer.length = strlen(stringp); |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 203 | maj = gss_import_name(&min, &input_buffer, GSS_C_NT_HOSTBASED_SERVICE, |
| 204 | &gssname); |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 205 | free(stringp); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 206 | if(maj != GSS_S_COMPLETE) { |
| 207 | gss_release_name(&min, &gssname); |
| 208 | if(service == srv_host) { |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 209 | Curl_failf(data, "Error importing service name %s@%s", service, host); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 210 | return AUTH_ERROR; |
| 211 | } |
| 212 | service = srv_host; |
| 213 | continue; |
| 214 | } |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 215 | /* We pass NULL as |output_name_type| to avoid a leak. */ |
| 216 | gss_display_name(&min, gssname, &output_buffer, NULL); |
| 217 | Curl_infof(data, "Trying against %s\n", output_buffer.value); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 218 | gssresp = GSS_C_NO_BUFFER; |
| 219 | *context = GSS_C_NO_CONTEXT; |
| 220 | |
| 221 | do { |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 222 | /* Release the buffer at each iteration to avoid leaking: the first time |
| 223 | we are releasing the memory from gss_display_name. The last item is |
| 224 | taken care by a final gss_release_buffer. */ |
| 225 | gss_release_buffer(&min, &output_buffer); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 226 | ret = AUTH_OK; |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 227 | maj = Curl_gss_init_sec_context(data, |
| 228 | &min, |
| 229 | context, |
| 230 | gssname, |
| 231 | &Curl_krb5_mech_oid, |
| 232 | &chan, |
| 233 | gssresp, |
| 234 | &output_buffer, |
| 235 | TRUE, |
| 236 | NULL); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 237 | |
| 238 | if(gssresp) { |
| 239 | free(_gssresp.value); |
| 240 | gssresp = NULL; |
| 241 | } |
| 242 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 243 | if(GSS_ERROR(maj)) { |
| 244 | Curl_infof(data, "Error creating security context\n"); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 245 | ret = AUTH_ERROR; |
| 246 | break; |
| 247 | } |
| 248 | |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 249 | if(output_buffer.length != 0) { |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 250 | char *cmd; |
| 251 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 252 | result = Curl_base64_encode(data, (char *)output_buffer.value, |
| 253 | output_buffer.length, &p, &base64_sz); |
| 254 | if(result) { |
| 255 | Curl_infof(data, "base64-encoding: %s\n", |
| 256 | curl_easy_strerror(result)); |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 257 | ret = AUTH_ERROR; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 258 | break; |
| 259 | } |
| 260 | |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 261 | cmd = aprintf("ADAT %s", p); |
| 262 | if(cmd) |
| 263 | result = Curl_ftpsend(conn, cmd); |
| 264 | else |
| 265 | result = CURLE_OUT_OF_MEMORY; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 266 | |
| 267 | free(p); |
| 268 | |
| 269 | if(result) { |
| 270 | ret = -2; |
| 271 | break; |
| 272 | } |
| 273 | |
| 274 | if(Curl_GetFTPResponse(&nread, conn, NULL)) { |
| 275 | ret = -1; |
| 276 | break; |
| 277 | } |
| 278 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 279 | if(data->state.buffer[0] != '2' && data->state.buffer[0] != '3') { |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 280 | Curl_infof(data, "Server didn't accept auth data\n"); |
| 281 | ret = AUTH_ERROR; |
| 282 | break; |
| 283 | } |
| 284 | |
Elliott Hughes | 0128fe4 | 2018-02-27 14:57:55 -0800 | [diff] [blame] | 285 | _gssresp.value = NULL; /* make sure it is initialized */ |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 286 | p = data->state.buffer + 4; |
| 287 | p = strstr(p, "ADAT="); |
| 288 | if(p) { |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 289 | result = Curl_base64_decode(p + 5, |
| 290 | (unsigned char **)&_gssresp.value, |
| 291 | &_gssresp.length); |
| 292 | if(result) { |
| 293 | Curl_failf(data, "base64-decoding: %s", |
| 294 | curl_easy_strerror(result)); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 295 | ret = AUTH_CONTINUE; |
| 296 | break; |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | gssresp = &_gssresp; |
| 301 | } |
| 302 | } while(maj == GSS_S_CONTINUE_NEEDED); |
| 303 | |
| 304 | gss_release_name(&min, &gssname); |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 305 | gss_release_buffer(&min, &output_buffer); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 306 | |
| 307 | if(gssresp) |
| 308 | free(_gssresp.value); |
| 309 | |
| 310 | if(ret == AUTH_OK || service == srv_host) |
| 311 | return ret; |
| 312 | |
| 313 | service = srv_host; |
| 314 | } |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 315 | return ret; |
| 316 | } |
| 317 | |
| 318 | static void krb5_end(void *app_data) |
| 319 | { |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 320 | OM_uint32 min; |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 321 | gss_ctx_id_t *context = app_data; |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 322 | if(*context != GSS_C_NO_CONTEXT) { |
| 323 | #ifdef DEBUGBUILD |
| 324 | OM_uint32 maj = |
| 325 | #endif |
| 326 | gss_delete_sec_context(&min, context, GSS_C_NO_BUFFER); |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 327 | DEBUGASSERT(maj == GSS_S_COMPLETE); |
| 328 | } |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | struct Curl_sec_client_mech Curl_krb5_client_mech = { |
| 332 | "GSSAPI", |
| 333 | sizeof(gss_ctx_id_t), |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 334 | krb5_init, |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 335 | krb5_auth, |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 336 | krb5_end, |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 337 | krb5_check_prot, |
| 338 | krb5_overhead, |
| 339 | krb5_encode, |
| 340 | krb5_decode |
| 341 | }; |
| 342 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 343 | #endif /* HAVE_GSSAPI && !CURL_DISABLE_FTP */ |