Artifactspublic-v0

curl

master
ply4 git calls30 ms298 KiB3 cachedprotocol v2
1388 lines39 KiBRaw
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9 * Copyright (C) Howard Chu, <hyc@openldap.org>
10 *
11 * This software is licensed as described in the file COPYING, which
12 * you should have received as part of this distribution. The terms
13 * are also available at https://curl.se/docs/copyright.html.
14 *
15 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
16 * copies of the Software, and permit persons to whom the Software is
17 * furnished to do so, under the terms of the COPYING file.
18 *
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
21 *
22 * SPDX-License-Identifier: curl
23 *
24 ***************************************************************************/
25#include "curl_setup.h"
27#if !defined(CURL_DISABLE_LDAP) && defined(USE_OPENLDAP)
29/*
30 * Notice that USE_OPENLDAP is only a source code selection switch. When
31 * libcurl is built with USE_OPENLDAP defined the libcurl source code that
32 * gets compiled is the code from openldap.c, otherwise the code that gets
33 * compiled is the code from ldap.c.
34 *
35 * When USE_OPENLDAP is defined a recent version of the OpenLDAP library
36 * might be required for compilation and runtime. In order to use ancient
37 * OpenLDAP library versions, USE_OPENLDAP shall not be defined.
38 */
40#include <ldap.h>
42#include "urldata.h"
43#include "url.h"
44#include "sendf.h"
45#include "curl_trc.h"
46#include "vtls/vtls.h"
47#include "transfer.h"
48#include "curl_ldap.h"
49#include "curlx/base64.h"
50#include "cfilters.h"
51#include "connect.h"
52#include "curl_sasl.h"
53#include "strcase.h"
54#include "bufref.h"
56/*
57 * Uncommenting this will enable the built-in debug logging of the openldap
58 * library. The debug log level can be set using the CURL_OPENLDAP_TRACE
59 * environment variable. The debug output is written to stderr.
60 *
61 * The library supports the following debug flags:
62 * LDAP_DEBUG_NONE 0x0000
63 * LDAP_DEBUG_TRACE 0x0001
64 * LDAP_DEBUG_CONSTRUCT 0x0002
65 * LDAP_DEBUG_DESTROY 0x0004
66 * LDAP_DEBUG_PARAMETER 0x0008
67 * LDAP_DEBUG_ANY 0xffff
68 *
69 * For example, use CURL_OPENLDAP_TRACE=0 for no debug,
70 * CURL_OPENLDAP_TRACE=2 for LDAP_DEBUG_CONSTRUCT messages only,
71 * CURL_OPENLDAP_TRACE=65535 for all debug message levels.
72 */
73/* #define CURL_OPENLDAP_DEBUG */
75/* Machine states. */
76typedef enum {
77 OLDAP_STOP, /* Do nothing state, stops the state machine */
78 OLDAP_SSL, /* Performing SSL handshake. */
79 OLDAP_STARTTLS, /* STARTTLS request sent. */
80 OLDAP_TLS, /* Performing TLS handshake. */
81 OLDAP_MECHS, /* Get SASL authentication mechanisms. */
82 OLDAP_SASL, /* SASL binding reply. */
83 OLDAP_BIND, /* Simple bind reply. */
84 OLDAP_BINDV2, /* Simple bind reply in protocol version 2. */
85 OLDAP_LAST /* Never used */
86} ldapstate;
88#ifndef _LDAP_PVT_H
89extern int ldap_pvt_url_scheme2proto(const char *);
90extern int ldap_init_fd(ber_socket_t fd, int proto, const char *url,
91 LDAP **ld);
92#endif
94static Curl_recv oldap_recv;
96struct ldapconninfo {
97 struct SASL sasl; /* SASL-related parameters */
98 LDAP *ld; /* Openldap connection handle. */
99 Curl_recv *recv; /* For stacking SSL handler */
100 Curl_send *send;
101 struct berval *servercred; /* SASL data from server. */
102 ldapstate state; /* Current machine state. */
103 curl_socket_t dupfd; /* duplicated socket */
104 int proto; /* LDAP_PROTO_TCP/LDAP_PROTO_UDP/LDAP_PROTO_IPC */
105 int msgid; /* Current message id. */
106};
108struct ldapreqinfo {
109 int msgid;
110 int nument;
111};
113/* meta key for storing ldapconninfo at easy handle */
114#define CURL_META_LDAP_EASY "meta:proto:ldap:easy"
115/* meta key for storing ldapconninfo at connection */
116#define CURL_META_LDAP_CONN "meta:proto:ldap:conn"
118/*
119 * oldap_state()
120 *
121 * This is the ONLY way to change LDAP state!
122 */
123static void oldap_state(struct Curl_easy *data, struct ldapconninfo *li,
124 ldapstate newstate)
126#if defined(DEBUGBUILD) && defined(CURLVERBOSE)
127 /* for debug purposes */
128 static const char * const names[] = {
129 "STOP",
130 "SSL",
131 "STARTTLS",
132 "TLS",
133 "MECHS",
134 "SASL",
135 "BIND",
136 "BINDV2",
137 /* LAST */
138 };
140 if(li->state != newstate)
141 infof(data, "LDAP %p state change from %s to %s",
142 (void *)li, names[li->state], names[newstate]);
143#else
144 (void)data;
145#endif
146 li->state = newstate;
149/* Map some particular LDAP error codes to CURLcode values. */
150static CURLcode oldap_map_error(int rc, CURLcode result)
152 switch(rc) {
153 case LDAP_NO_MEMORY:
154 return CURLE_OUT_OF_MEMORY;
155 case LDAP_INVALID_CREDENTIALS:
156 return CURLE_LOGIN_DENIED;
157 case LDAP_PROTOCOL_ERROR:
158 return CURLE_UNSUPPORTED_PROTOCOL;
159 case LDAP_INSUFFICIENT_ACCESS:
160 return CURLE_REMOTE_ACCESS_DENIED;
161 }
162 return result;
165static CURLcode oldap_url_parse(struct Curl_easy *data, LDAPURLDesc **ludp)
167 CURLcode result = CURLE_OK;
168 int rc;
169 static const char * const url_errs[] = {
170 "success",
171 "out of memory",
172 "bad parameter",
173 "unrecognized scheme",
174 "unbalanced delimiter",
175 "bad URL",
176 "bad host or port",
177 "bad or missing attributes",
178 "bad or missing scope",
179 "bad or missing filter",
180 "bad or missing extensions"
181 };
183 *ludp = NULL;
184 /* `ldap_url_parse() seems to be terrible with urls
185 * that have user/pass/options in it. So when we have options or
186 * creds from the url, fail without calling the function.
187 * Yes, this is super-weird code and I do not like it. */
188 if((data->state.creds && (data->state.creds->source == CREDS_URL)) ||
189 data->state.up.options)
190 rc = LDAP_URL_ERR_BADURL;
191 else
192 rc = ldap_url_parse(Curl_bufref_ptr(&data->state.url), ludp);
194 if(rc != LDAP_URL_SUCCESS) {
195 const char *msg = "url parsing problem";
197 result = rc == LDAP_URL_ERR_MEM ? CURLE_OUT_OF_MEMORY :
198 CURLE_URL_MALFORMAT;
199 rc -= LDAP_URL_SUCCESS;
200 if((size_t)rc < CURL_ARRAYSIZE(url_errs))
201 msg = url_errs[rc];
202 failf(data, "LDAP local: %s", msg);
203 }
204 return result;
207/* Parse the login options. */
208static CURLcode oldap_parse_login_options(struct connectdata *conn)
210 CURLcode result = CURLE_OK;
211 struct ldapconninfo *li = Curl_conn_meta_get(conn, CURL_META_LDAP_CONN);
212 const char *ptr = conn->options;
214 DEBUGASSERT(li);
215 if(!li)
216 return CURLE_FAILED_INIT;
218 while(!result && ptr && *ptr) {
219 const char *key = ptr;
220 const char *value;
222 while(*ptr && *ptr != '=')
223 ptr++;
225 value = ptr + 1;
227 while(*ptr && *ptr != ';')
228 ptr++;
230 if(checkprefix("AUTH=", key))
231 result = Curl_sasl_parse_url_auth_option(&li->sasl, value, ptr - value);
232 else
233 result = CURLE_SETOPT_OPTION_SYNTAX;
235 if(*ptr == ';')
236 ptr++;
237 }
239 return result == CURLE_URL_MALFORMAT ? CURLE_SETOPT_OPTION_SYNTAX : result;
242static CURLcode oldap_setup_connection(struct Curl_easy *data,
243 struct connectdata *conn)
245 CURLcode result;
246 LDAPURLDesc *lud;
247 (void)conn;
249 /* Early URL syntax check. */
250 result = oldap_url_parse(data, &lud);
251 ldap_free_urldesc(lud);
253 return result;
256/*
257 * Get the SASL authentication challenge from the server credential buffer.
258 */
259static CURLcode oldap_get_message(struct Curl_easy *data, struct bufref *out)
261 struct ldapconninfo *li =
262 Curl_conn_meta_get(data->conn, CURL_META_LDAP_CONN);
263 struct berval *servercred = li ? li->servercred : NULL;
264 DEBUGASSERT(li);
265 if(!li)
266 return CURLE_FAILED_INIT;
268 if(!servercred || !servercred->bv_val)
269 return CURLE_WEIRD_SERVER_REPLY;
270 Curl_bufref_set(out, servercred->bv_val, servercred->bv_len, NULL);
271 return CURLE_OK;
274/*
275 * Sends an initial SASL bind request to the server.
276 */
277static CURLcode oldap_perform_auth(struct Curl_easy *data, const char *mech,
278 const struct bufref *initresp)
280 struct connectdata *conn = data->conn;
281 struct ldapconninfo *li = Curl_conn_meta_get(conn, CURL_META_LDAP_CONN);
282 struct berval cred;
283 struct berval *pcred = &cred;
284 int rc;
286 DEBUGASSERT(li);
287 if(!li)
288 return CURLE_FAILED_INIT;
289 cred.bv_val = (char *)CURL_UNCONST(Curl_bufref_ptr(initresp));
290 cred.bv_len = Curl_bufref_len(initresp);
291 if(!cred.bv_val)
292 pcred = NULL;
293 rc = ldap_sasl_bind(li->ld, NULL, mech, pcred, NULL, NULL, &li->msgid);
294 if(rc != LDAP_SUCCESS)
295 return oldap_map_error(rc, CURLE_LDAP_CANNOT_BIND);
296 return CURLE_OK;
299/*
300 * Sends SASL continuation.
301 */
302static CURLcode oldap_continue_auth(struct Curl_easy *data, const char *mech,
303 const struct bufref *resp)
305 struct connectdata *conn = data->conn;
306 struct ldapconninfo *li = Curl_conn_meta_get(conn, CURL_META_LDAP_CONN);
307 struct berval cred;
308 struct berval *pcred = &cred;
309 int rc;
311 if(!li)
312 return CURLE_FAILED_INIT;
313 cred.bv_val = (char *)CURL_UNCONST(Curl_bufref_ptr(resp));
314 cred.bv_len = Curl_bufref_len(resp);
315 if(!cred.bv_val)
316 pcred = NULL;
317 rc = ldap_sasl_bind(li->ld, NULL, mech, pcred, NULL, NULL, &li->msgid);
318 if(rc != LDAP_SUCCESS)
319 return oldap_map_error(rc, CURLE_LDAP_CANNOT_BIND);
320 return CURLE_OK;
323/*
324 * Sends SASL bind cancellation.
325 */
326static CURLcode oldap_cancel_auth(struct Curl_easy *data, const char *mech)
328 struct ldapconninfo *li =
329 Curl_conn_meta_get(data->conn, CURL_META_LDAP_CONN);
330 int rc;
332 (void)mech;
333 if(!li)
334 return CURLE_FAILED_INIT;
335 rc = ldap_sasl_bind(li->ld, NULL, LDAP_SASL_NULL, NULL, NULL, NULL,
336 &li->msgid);
337 if(rc != LDAP_SUCCESS)
338 return oldap_map_error(rc, CURLE_LDAP_CANNOT_BIND);
339 return CURLE_OK;
342/* Starts LDAP simple bind. */
343static CURLcode oldap_perform_bind(struct Curl_easy *data, ldapstate newstate)
345 struct connectdata *conn = data->conn;
346 struct ldapconninfo *li = Curl_conn_meta_get(conn, CURL_META_LDAP_CONN);
347 const char *binddn = NULL;
348 struct berval passwd;
349 int rc;
351 if(!li)
352 return CURLE_FAILED_INIT;
353 passwd.bv_val = NULL;
354 passwd.bv_len = 0;
356 if(conn->creds) {
357 binddn = Curl_creds_user(conn->creds);
358 passwd.bv_val = CURL_UNCONST(Curl_creds_passwd(conn->creds));
359 passwd.bv_len = strlen(passwd.bv_val);
360 }
362 rc = ldap_sasl_bind(li->ld, binddn, LDAP_SASL_SIMPLE, &passwd,
363 NULL, NULL, &li->msgid);
364 if(rc != LDAP_SUCCESS)
365 return oldap_map_error(rc,
366 data->state.creds ?
367 CURLE_LOGIN_DENIED : CURLE_LDAP_CANNOT_BIND);
368 oldap_state(data, li, newstate);
369 return CURLE_OK;
372/* Query the supported SASL authentication mechanisms. */
373static CURLcode oldap_perform_mechs(struct Curl_easy *data)
375 struct ldapconninfo *li =
376 Curl_conn_meta_get(data->conn, CURL_META_LDAP_CONN);
377 int rc;
378 static const char * const supportedSASLMechanisms[] = {
379 "supportedSASLMechanisms",
380 NULL
381 };
383 if(!li)
384 return CURLE_FAILED_INIT;
385 /* Casting away the const for the 3rd parameter that the LDAP API expects as
386 a non-const char ** is potentially unsafe but we believe the lack of
387 const in the API was an oversight and that no LDAP implementation
388 actually modifies the input. */
389 rc = ldap_search_ext(li->ld, "", LDAP_SCOPE_BASE, "(objectclass=*)",
390 (char **)CURL_UNCONST(supportedSASLMechanisms), 0,
391 NULL, NULL, NULL, 0, &li->msgid);
392 if(rc != LDAP_SUCCESS)
393 return oldap_map_error(rc, CURLE_LOGIN_DENIED);
394 oldap_state(data, li, OLDAP_MECHS);
395 return CURLE_OK;
398/* Starts SASL bind. */
399static CURLcode oldap_perform_sasl(struct Curl_easy *data)
401 struct ldapconninfo *li =
402 Curl_conn_meta_get(data->conn, CURL_META_LDAP_CONN);
403 saslprogress progress = SASL_IDLE;
404 CURLcode result;
406 if(!li)
407 return CURLE_FAILED_INIT;
408 result = Curl_sasl_start(&li->sasl, data, TRUE, &progress);
410 oldap_state(data, li, OLDAP_SASL);
411 if(!result && progress != SASL_INPROGRESS)
412 result = Curl_sasl_is_blocked(&li->sasl, data);
413 return result;
416#ifdef USE_SSL
417static int ldapsb_tls_setup(Sockbuf_IO_Desc *sbiod, void *arg)
419 sbiod->sbiod_pvt = arg;
420 return 0;
423static int ldapsb_tls_remove(Sockbuf_IO_Desc *sbiod)
425 sbiod->sbiod_pvt = NULL;
426 return 0;
429/* if there is a duplicated socket to close, close it */
430static int ldapsb_tls_close(Sockbuf_IO_Desc *sbiod)
432 struct Curl_easy *data = sbiod->sbiod_pvt;
433 if(data) {
434 struct connectdata *conn = data->conn;
435 if(conn) {
436 struct ldapconninfo *li = Curl_conn_meta_get(conn, CURL_META_LDAP_CONN);
437 if(li && (li->dupfd != CURL_SOCKET_BAD)) {
438 sclose(li->dupfd);
439 li->dupfd = CURL_SOCKET_BAD;
440 }
441 }
442 }
444 return 0;
447static int ldapsb_tls_ctrl(Sockbuf_IO_Desc *sbiod, int opt, void *arg)
449 (void)arg;
450 if(opt == LBER_SB_OPT_DATA_READY) {
451 struct Curl_easy *data = sbiod->sbiod_pvt;
452 return Curl_conn_data_pending(data, FIRSTSOCKET);
453 }
454 return 0;
457static ber_slen_t ldapsb_tls_read(Sockbuf_IO_Desc *sbiod, void *buf,
458 ber_len_t len)
460 struct Curl_easy *data = sbiod->sbiod_pvt;
461 ber_slen_t ret = 0;
462 if(data) {
463 struct connectdata *conn = data->conn;
464 if(conn) {
465 struct ldapconninfo *li = Curl_conn_meta_get(conn, CURL_META_LDAP_CONN);
466 CURLcode result = CURLE_RECV_ERROR;
467 size_t nread;
469 if(!li) {
470 SET_SOCKERRNO(SOCKEINVAL);
471 return -1;
472 }
473 result = (li->recv)(data, FIRSTSOCKET, buf, len, &nread);
474 if(result == CURLE_AGAIN) {
475 SET_SOCKERRNO(SOCKEWOULDBLOCK);
476 }
477 ret = result ? -1 : (ber_slen_t)nread;
478 }
479 }
480 return ret;
483static ber_slen_t ldapsb_tls_write(Sockbuf_IO_Desc *sbiod, void *buf,
484 ber_len_t len)
486 struct Curl_easy *data = sbiod->sbiod_pvt;
487 ber_slen_t ret = 0;
488 if(data) {
489 struct connectdata *conn = data->conn;
490 if(conn) {
491 struct ldapconninfo *li = Curl_conn_meta_get(conn, CURL_META_LDAP_CONN);
492 CURLcode result = CURLE_SEND_ERROR;
493 size_t nwritten;
495 if(!li) {
496 SET_SOCKERRNO(SOCKEINVAL);
497 return -1;
498 }
499 result = (li->send)(data, FIRSTSOCKET, buf, len, FALSE, &nwritten);
500 if(result == CURLE_AGAIN) {
501 SET_SOCKERRNO(SOCKEWOULDBLOCK);
502 }
503 ret = result ? -1 : (ber_slen_t)nwritten;
504 }
505 }
506 return ret;
509static Sockbuf_IO ldapsb_tls = {
510 ldapsb_tls_setup,
511 ldapsb_tls_remove,
512 ldapsb_tls_ctrl,
513 ldapsb_tls_read,
514 ldapsb_tls_write,
515 ldapsb_tls_close
516};
518static bool ssl_installed(struct connectdata *conn)
520 struct ldapconninfo *li = Curl_conn_meta_get(conn, CURL_META_LDAP_CONN);
521 return li && li->recv;
524static CURLcode oldap_ssl_connect(struct Curl_easy *data, ldapstate newstate)
526 struct connectdata *conn = data->conn;
527 struct ldapconninfo *li = Curl_conn_meta_get(conn, CURL_META_LDAP_CONN);
528 bool ssldone = FALSE;
529 CURLcode result;
531 if(!li)
532 return CURLE_FAILED_INIT;
533 result = Curl_conn_connect(data, FIRSTSOCKET, FALSE, &ssldone);
534 if(result)
535 return result;
536 oldap_state(data, li, newstate);
538 if(ssldone) {
539 Sockbuf *sb;
541 /* Install the libcurl SSL handlers into the sockbuf. */
542 if((ldap_get_option(li->ld, LDAP_OPT_SOCKBUF, &sb) != LDAP_OPT_SUCCESS) ||
543 ber_sockbuf_add_io(sb, &ldapsb_tls, LBER_SBIOD_LEVEL_TRANSPORT, data))
544 return CURLE_FAILED_INIT;
545 li->recv = conn->recv[FIRSTSOCKET];
546 li->send = conn->send[FIRSTSOCKET];
547 }
549 return result;
552/* Send the STARTTLS request */
553static CURLcode oldap_perform_starttls(struct Curl_easy *data)
555 struct ldapconninfo *li =
556 Curl_conn_meta_get(data->conn, CURL_META_LDAP_CONN);
557 int rc;
559 if(!li)
560 return CURLE_FAILED_INIT;
561 rc = ldap_start_tls(li->ld, NULL, NULL, &li->msgid);
562 if(rc != LDAP_SUCCESS)
563 return oldap_map_error(rc, CURLE_USE_SSL_FAILED);
564 oldap_state(data, li, OLDAP_STARTTLS);
565 return CURLE_OK;
567#endif
569static void oldap_easy_dtor(const void *key, size_t klen, void *entry)
571 struct ldapreqinfo *lr = entry;
572 (void)key;
573 (void)klen;
574 curlx_free(lr);
577static void oldap_conn_dtor(const void *key, size_t klen, void *entry)
579 struct ldapconninfo *li = entry;
580 (void)key;
581 (void)klen;
582 if(li->ld) {
583 ldap_unbind_ext(li->ld, NULL, NULL);
584 li->ld = NULL;
585 }
586 curlx_free(li);
589/* SASL parameters for the ldap protocol */
590static const struct SASLproto saslldap = {
591 "ldap", /* The service name */
592 oldap_perform_auth, /* Send authentication command */
593 oldap_continue_auth, /* Send authentication continuation */
594 oldap_cancel_auth, /* Send authentication cancellation */
595 oldap_get_message, /* Get SASL response message */
596 0, /* Maximum initial response length (no max) */
597 LDAP_SASL_BIND_IN_PROGRESS, /* Code received when continuation is expected */
598 LDAP_SUCCESS, /* Code to receive upon authentication success */
599 SASL_AUTH_NONE, /* Default mechanisms */
600 0 /* Configuration flags */
601};
603static CURLcode oldap_connect(struct Curl_easy *data, bool *done)
605 struct connectdata *conn = data->conn;
606 struct ldapconninfo *li;
607 static const int version = LDAP_VERSION3;
608 char *hosturl = NULL;
609 CURLcode result;
610 int rc;
611#ifdef CURL_OPENLDAP_DEBUG
612 static int do_trace = -1;
613#endif
615 (void)done;
617 li = curlx_calloc(1, sizeof(struct ldapconninfo));
618 if(!li) {
619 result = CURLE_OUT_OF_MEMORY;
620 goto out;
621 }
622 li->dupfd = CURL_SOCKET_BAD;
624 result = Curl_conn_meta_set(conn, CURL_META_LDAP_CONN, li, oldap_conn_dtor);
625 if(result)
626 goto out;
628 li->proto = ldap_pvt_url_scheme2proto(data->state.origin->scheme->name);
630 /* Initialize the SASL storage */
631 Curl_sasl_init(&li->sasl, data, &saslldap);
633 result = oldap_parse_login_options(conn);
634 if(result)
635 goto out;
637 hosturl = curl_maprintf("%s://%s:%u",
638 conn->scheme->name,
639 conn->origin->ipv6 ?
640 conn->origin->user_hostname :
641 conn->origin->hostname,
642 conn->origin->port);
643 if(!hosturl) {
644 result = CURLE_OUT_OF_MEMORY;
645 goto out;
646 }
648 {
649#ifdef _WIN32
650 SOCKET dupfd = INVALID_SOCKET;
651 WSAPROTOCOL_INFO pi;
652 if(WSADuplicateSocket(conn->sock[FIRSTSOCKET], GetCurrentProcessId(),
653 &pi))
654 ; /* error */
655 else
656 dupfd = CURL_SOCKET(pi.iAddressFamily, pi.iSocketType, pi.iProtocol);
657#else
658#ifdef F_DUPFD_CLOEXEC
659 int dupfd = fcntl(conn->sock[FIRSTSOCKET], F_DUPFD_CLOEXEC, 0);
660#else
661 int dupfd = dup(conn->sock[FIRSTSOCKET]);
662#ifdef HAVE_FCNTL
663 if((dupfd != CURL_SOCKET_BAD) &&
664 (fcntl(dupfd, F_SETFD, FD_CLOEXEC) < 0)) {
665 sclose(dupfd);
666 dupfd = CURL_SOCKET_BAD;
667 }
668#endif /* HAVE_FCNTL */
669#endif /* F_DUPFD_CLOEXEC */
670#endif /* _WIN32 */
672 if(dupfd == CURL_SOCKET_BAD) {
673 result = CURLE_COULDNT_CONNECT;
674 goto out;
675 }
676 rc = ldap_init_fd((ber_socket_t)dupfd, li->proto, hosturl, &li->ld);
677 if(rc)
678 sclose(dupfd);
679 else
680 /* store the socket, as when this is used by TLS we close this ourselves
681 and at this point the code does not yet know if this will use TLS or
682 not */
683 li->dupfd = dupfd;
684 }
685 if(rc) {
686 failf(data, "LDAP local: Cannot connect to %s, %s",
687 hosturl, ldap_err2string(rc));
688 result = CURLE_COULDNT_CONNECT;
689 goto out;
690 }
692#ifdef CURL_OPENLDAP_DEBUG
693 if(do_trace < 0) {
694 const char *env = getenv("CURL_OPENLDAP_TRACE");
695 curl_off_t e = 0;
696 if(!curlx_str_number(&env, &e, INT_MAX))
697 do_trace = e > 0;
698 }
699 if(do_trace)
700 ldap_set_option(li->ld, LDAP_OPT_DEBUG_LEVEL, &do_trace);
701#endif
703 /* Try version 3 first. */
704 ldap_set_option(li->ld, LDAP_OPT_PROTOCOL_VERSION, &version);
706 /* Do not chase referrals. */
707 ldap_set_option(li->ld, LDAP_OPT_REFERRALS, LDAP_OPT_OFF);
709 {
710 ber_len_t max = 256 * 1024;
711 Sockbuf *sb;
712 if((ldap_get_option(li->ld, LDAP_OPT_SOCKBUF, &sb) != LDAP_OPT_SUCCESS) ||
713 /* Set the maximum allowed size of an incoming message, which to
714 OpenLDAP means that it will malloc() memory up to this size. If not
715 set, there is no limit and we instead risk a malloc() failure. */
716 !ber_sockbuf_ctrl(sb, LBER_SB_OPT_SET_MAX_INCOMING, &max)) {
717 result = CURLE_FAILED_INIT;
718 goto out;
719 }
720 }
722#ifdef USE_SSL
723 if(Curl_conn_is_ssl(conn, FIRSTSOCKET)) {
724 result = oldap_ssl_connect(data, OLDAP_SSL);
725 goto out;
726 }
728 if(data->set.use_ssl) {
729 result = oldap_perform_starttls(data);
730 if(!result || data->set.use_ssl != CURLUSESSL_TRY)
731 goto out;
732 }
733#endif
735 if(li->sasl.prefmech != SASL_AUTH_NONE) {
736 result = oldap_perform_mechs(data);
737 goto out;
738 }
740 /* Force bind even if anonymous bind is not needed in protocol version 3
741 to detect missing version 3 support. */
742 result = oldap_perform_bind(data, OLDAP_BIND);
744out:
745 curlx_free(hosturl);
746 return result;
749/* Handle the supported SASL mechanisms query response */
750static CURLcode oldap_state_mechs_resp(struct Curl_easy *data,
751 LDAPMessage *msg, int code)
753 struct connectdata *conn;
754 struct ldapconninfo *li;
755 int rc;
756 BerElement *ber = NULL;
757 CURLcode result = CURLE_OK;
758 struct berval bv, *bvals;
760 if(!data)
761 return CURLE_FAILED_INIT;
763 conn = data->conn;
764 li = Curl_conn_meta_get(conn, CURL_META_LDAP_CONN);
766 if(!li)
767 return CURLE_FAILED_INIT;
768 switch(ldap_msgtype(msg)) {
769 case LDAP_RES_SEARCH_ENTRY:
770 /* Got a list of supported SASL mechanisms. */
771 if(code != LDAP_SUCCESS && code != LDAP_NO_RESULTS_RETURNED)
772 return CURLE_LOGIN_DENIED;
774 rc = ldap_get_dn_ber(li->ld, msg, &ber, &bv);
775 if(rc < 0)
776 return oldap_map_error(rc, CURLE_BAD_CONTENT_ENCODING);
777 for(rc = ldap_get_attribute_ber(li->ld, msg, ber, &bv, &bvals);
778 rc == LDAP_SUCCESS;
779 rc = ldap_get_attribute_ber(li->ld, msg, ber, &bv, &bvals)) {
780 int i;
782 if(!bv.bv_val)
783 break;
785 if(bvals) {
786 for(i = 0; bvals[i].bv_val; i++) {
787 size_t llen;
788 unsigned short mech =
789 Curl_sasl_decode_mech((const char *)bvals[i].bv_val,
790 bvals[i].bv_len, &llen);
791 if(bvals[i].bv_len == llen)
792 li->sasl.authmechs |= mech;
793 }
794 ber_memfree(bvals);
795 }
796 }
797 ber_free(ber, 0);
798 break;
800 case LDAP_RES_SEARCH_RESULT:
801 switch(code) {
802 case LDAP_SIZELIMIT_EXCEEDED:
803 infof(data, "Too many authentication mechanisms");
804 FALLTHROUGH();
805 case LDAP_SUCCESS:
806 case LDAP_NO_RESULTS_RETURNED:
807 if(Curl_sasl_can_authenticate(&li->sasl, data))
808 result = oldap_perform_sasl(data);
809 else
810 result = CURLE_LOGIN_DENIED;
811 break;
812 default:
813 result = oldap_map_error(code, CURLE_LOGIN_DENIED);
814 break;
815 }
816 break;
817 default:
818 break;
819 }
820 return result;
823/* Handle a SASL bind response. */
824static CURLcode oldap_state_sasl_resp(struct Curl_easy *data,
825 LDAPMessage *msg, int code)
827 struct connectdata *conn = data->conn;
828 struct ldapconninfo *li = Curl_conn_meta_get(conn, CURL_META_LDAP_CONN);
829 CURLcode result = CURLE_OK;
830 saslprogress progress;
831 int rc;
833 if(!li)
834 return CURLE_FAILED_INIT;
835 li->servercred = NULL;
836 rc = ldap_parse_sasl_bind_result(li->ld, msg, &li->servercred, 0);
837 if(rc != LDAP_SUCCESS) {
838 failf(data, "LDAP local: sasl ldap_parse_result %s", ldap_err2string(rc));
839 result = oldap_map_error(rc, CURLE_LOGIN_DENIED);
840 }
841 else {
842 result = Curl_sasl_continue(&li->sasl, data, code, &progress);
843 if(!result) {
844 switch(progress) {
845 case SASL_DONE:
846 oldap_state(data, li, OLDAP_STOP); /* Authenticated */
847 break;
848 case SASL_IDLE: /* No mechanism left after cancellation */
849 failf(data, "Authentication cancelled");
850 result = CURLE_LOGIN_DENIED;
851 break;
852 default:
853 break;
854 }
855 }
856 }
858 if(li->servercred)
859 ber_bvfree(li->servercred);
860 return result;
863/* Handle a simple bind response. */
864static CURLcode oldap_state_bind_resp(struct Curl_easy *data, LDAPMessage *msg,
865 int code)
867 struct connectdata *conn = data->conn;
868 struct ldapconninfo *li = Curl_conn_meta_get(conn, CURL_META_LDAP_CONN);
869 CURLcode result = CURLE_OK;
870 struct berval *bv = NULL;
871 int rc;
873 if(!li)
874 return CURLE_FAILED_INIT;
876 if(code != LDAP_SUCCESS)
877 return oldap_map_error(code, CURLE_LDAP_CANNOT_BIND);
879 rc = ldap_parse_sasl_bind_result(li->ld, msg, &bv, 0);
880 if(rc != LDAP_SUCCESS) {
881 failf(data, "LDAP local: bind ldap_parse_sasl_bind_result %s",
882 ldap_err2string(rc));
883 result = oldap_map_error(rc, CURLE_LDAP_CANNOT_BIND);
884 }
885 else
886 oldap_state(data, li, OLDAP_STOP);
888 if(bv)
889 ber_bvfree(bv);
890 return result;
893static CURLcode oldap_connecting(struct Curl_easy *data, bool *done)
895 CURLcode result = CURLE_OK;
896 struct connectdata *conn = data->conn;
897 struct ldapconninfo *li = Curl_conn_meta_get(conn, CURL_META_LDAP_CONN);
898 LDAPMessage *msg = NULL;
899 struct timeval tv = { 0, 0 };
900 int code = LDAP_SUCCESS;
901 int rc;
903 if(!li)
904 return CURLE_FAILED_INIT;
906 if(li->state != OLDAP_SSL && li->state != OLDAP_TLS) {
907 /* Get response to last command. */
908 rc = ldap_result(li->ld, li->msgid, LDAP_MSG_ONE, &tv, &msg);
909 switch(rc) {
910 case 0: /* Timed out. */
911 return CURLE_OK;
912 case LDAP_RES_SEARCH_ENTRY:
913 case LDAP_RES_SEARCH_REFERENCE:
914 break;
915 default:
916 li->msgid = 0; /* Nothing to abandon upon error. */
917 if(rc < 0) {
918 failf(data, "LDAP local: connecting ldap_result %s",
919 ldap_err2string(rc));
920 return oldap_map_error(rc, CURLE_COULDNT_CONNECT);
921 }
922 break;
923 }
925 /* Get error code from message. */
926 rc = ldap_parse_result(li->ld, msg, &code, NULL, NULL, NULL, NULL, 0);
927 if(rc)
928 code = rc;
929 else {
930 /* store the latest code for later retrieval */
931 data->info.httpcode = code;
932 }
934 /* If protocol version 3 is not supported, fallback to version 2. */
935 if(code == LDAP_PROTOCOL_ERROR && li->state != OLDAP_BINDV2 &&
936#ifdef USE_SSL
937 (ssl_installed(conn) || data->set.use_ssl <= CURLUSESSL_TRY) &&
938#endif
939 li->sasl.prefmech == SASL_AUTH_NONE) {
940 static const int version = LDAP_VERSION2;
942 ldap_set_option(li->ld, LDAP_OPT_PROTOCOL_VERSION, &version);
943 ldap_msgfree(msg);
944 return oldap_perform_bind(data, OLDAP_BINDV2);
945 }
946 }
948 /* Handle response message according to current state. */
949 switch(li->state) {
951#ifdef USE_SSL
952 case OLDAP_SSL:
953 result = oldap_ssl_connect(data, OLDAP_SSL);
954 if(!result && ssl_installed(conn)) {
955 if(li->sasl.prefmech != SASL_AUTH_NONE)
956 result = oldap_perform_mechs(data);
957 else
958 result = oldap_perform_bind(data, OLDAP_BIND);
959 }
960 break;
961 case OLDAP_STARTTLS:
962 if(code != LDAP_SUCCESS) {
963 if(data->set.use_ssl != CURLUSESSL_TRY)
964 result = oldap_map_error(code, CURLE_USE_SSL_FAILED);
965 else if(li->sasl.prefmech != SASL_AUTH_NONE)
966 result = oldap_perform_mechs(data);
967 else
968 result = oldap_perform_bind(data, OLDAP_BIND);
969 break;
970 }
971 result = Curl_ssl_cfilter_add(
972 data, Curl_conn_get_origin(conn, FIRSTSOCKET), conn, FIRSTSOCKET);
973 if(result)
974 break;
975 FALLTHROUGH();
976 case OLDAP_TLS:
977 result = oldap_ssl_connect(data, OLDAP_TLS);
978 if(result)
979 result = oldap_map_error(code, CURLE_USE_SSL_FAILED);
980 else if(ssl_installed(conn)) {
981 if(li->sasl.prefmech != SASL_AUTH_NONE)
982 result = oldap_perform_mechs(data);
983 else if(data->state.creds)
984 result = oldap_perform_bind(data, OLDAP_BIND);
985 else {
986 /* Version 3 supported: no bind required */
987 oldap_state(data, li, OLDAP_STOP);
988 result = CURLE_OK;
989 }
990 }
991 break;
992#endif
994 case OLDAP_MECHS:
995 result = oldap_state_mechs_resp(data, msg, code);
996 break;
997 case OLDAP_SASL:
998 result = oldap_state_sasl_resp(data, msg, code);
999 break;
1000 case OLDAP_BIND:
1001 case OLDAP_BINDV2:
1002 result = oldap_state_bind_resp(data, msg, code);
1003 break;
1004 default:
1005 /* internal error */
1006 result = CURLE_COULDNT_CONNECT;
1007 break;
1010 ldap_msgfree(msg);
1012 *done = li->state == OLDAP_STOP;
1013 if(*done)
1014 conn->recv[FIRSTSOCKET] = oldap_recv;
1016 if(result && li->msgid) {
1017 ldap_abandon_ext(li->ld, li->msgid, NULL, NULL);
1018 li->msgid = 0;
1020 return result;
1023static CURLcode oldap_disconnect(struct Curl_easy *data,
1024 struct connectdata *conn,
1025 bool dead_connection)
1027 struct ldapconninfo *li = Curl_conn_meta_get(conn, CURL_META_LDAP_CONN);
1028 (void)dead_connection;
1029#ifndef USE_SSL
1030 (void)data;
1031#endif
1033 if(li && li->ld) {
1034#ifdef USE_SSL
1035 if(ssl_installed(conn)) {
1036 Sockbuf *sb;
1037 if(ldap_get_option(li->ld, LDAP_OPT_SOCKBUF, &sb) != LDAP_OPT_SUCCESS ||
1038 ber_sockbuf_add_io(sb, &ldapsb_tls, LBER_SBIOD_LEVEL_TRANSPORT, data))
1039 return CURLE_FAILED_INIT;
1041#endif
1042 ldap_unbind_ext(li->ld, NULL, NULL);
1043 li->ld = NULL;
1045 return CURLE_OK;
1048static CURLcode oldap_do(struct Curl_easy *data, bool *done)
1050 struct connectdata *conn = data->conn;
1051 struct ldapconninfo *li = Curl_conn_meta_get(conn, CURL_META_LDAP_CONN);
1052 struct ldapreqinfo *lr;
1053 CURLcode result;
1054 int rc;
1055 LDAPURLDesc *lud;
1056 int msgid;
1058 if(!li)
1059 return CURLE_FAILED_INIT;
1061 infof(data, "LDAP local: %s", Curl_bufref_ptr(&data->state.url));
1063 result = oldap_url_parse(data, &lud);
1064 if(result)
1065 goto out;
1067#ifdef USE_SSL
1068 if(ssl_installed(conn)) {
1069 Sockbuf *sb;
1070 /* re-install the libcurl SSL handlers into the sockbuf. */
1071 if((ldap_get_option(li->ld, LDAP_OPT_SOCKBUF, &sb) != LDAP_OPT_SUCCESS) ||
1072 ber_sockbuf_add_io(sb, &ldapsb_tls, LBER_SBIOD_LEVEL_TRANSPORT, data)) {
1073 ldap_free_urldesc(lud);
1074 return CURLE_FAILED_INIT;
1077#endif
1079 rc = ldap_search_ext(li->ld, lud->lud_dn, lud->lud_scope,
1080 lud->lud_filter, lud->lud_attrs, 0,
1081 NULL, NULL, NULL, 0, &msgid);
1082 ldap_free_urldesc(lud);
1083 if(rc != LDAP_SUCCESS) {
1084 failf(data, "LDAP local: ldap_search_ext %s", ldap_err2string(rc));
1085 result = CURLE_LDAP_SEARCH_FAILED;
1086 goto out;
1089 lr = curlx_calloc(1, sizeof(struct ldapreqinfo));
1090 if(!lr ||
1091 Curl_meta_set(data, CURL_META_LDAP_EASY, lr, oldap_easy_dtor)) {
1092 ldap_abandon_ext(li->ld, msgid, NULL, NULL);
1093 result = CURLE_OUT_OF_MEMORY;
1094 goto out;
1097 lr->msgid = msgid;
1098 Curl_xfer_setup_recv(data, FIRSTSOCKET, -1);
1099 *done = TRUE;
1101out:
1102 return result;
1105static CURLcode oldap_done(struct Curl_easy *data, CURLcode res,
1106 bool premature)
1108 struct connectdata *conn = data->conn;
1109 struct ldapreqinfo *lr = Curl_meta_get(data, CURL_META_LDAP_EASY);
1111 (void)res;
1112 (void)premature;
1114 if(lr) {
1115 /* if there was a search in progress, abandon it */
1116 if(lr->msgid) {
1117 struct ldapconninfo *li = Curl_conn_meta_get(conn, CURL_META_LDAP_CONN);
1118 if(li && li->ld) {
1119 ldap_abandon_ext(li->ld, lr->msgid, NULL, NULL);
1121 lr->msgid = 0;
1123 Curl_meta_remove(data, CURL_META_LDAP_EASY);
1126 return CURLE_OK;
1129static CURLcode client_write(struct Curl_easy *data,
1130 const char *prefix, size_t plen,
1131 const char *value, size_t len,
1132 const char *suffix, size_t slen)
1134 CURLcode result = CURLE_OK;
1136 if(prefix) {
1137 /* If we have a zero-length value and the prefix ends with a space
1138 separator, drop the latter. */
1139 if(!len && plen && prefix[plen - 1] == ' ')
1140 plen--;
1141 result = Curl_client_write(data, CLIENTWRITE_BODY, prefix, plen);
1143 if(!result && value) {
1144 result = Curl_client_write(data, CLIENTWRITE_BODY, value, len);
1146 if(!result && suffix) {
1147 result = Curl_client_write(data, CLIENTWRITE_BODY, suffix, slen);
1149 return result;
1152/* RFC 2849: a string that is not a SAFE-STRING (leading ':' or '<', leading or
1153 trailing space, or any non-printable byte such as CR/LF) cannot go into LDIF
1154 as-is. DNs and values get base64-encoded instead; an attribute type has no
1155 base64 form in LDIF and is rejected by the caller. */
1156static bool oldap_str_needs_base64(const char *s, size_t len)
1158 size_t i;
1159 if(!len)
1160 return FALSE;
1161 if((s[0] == ':') || (s[0] == '<') || ISBLANK(s[0]) || ISBLANK(s[len - 1]))
1162 return TRUE;
1163 for(i = 0; i < len; i++)
1164 if(!ISPRINT(s[i]))
1165 return TRUE;
1166 return FALSE;
1169static CURLcode oldap_recv(struct Curl_easy *data, int8_t sockindex, char *buf,
1170 size_t len, size_t *pnread)
1172 struct connectdata *conn = data->conn;
1173 struct ldapconninfo *li = Curl_conn_meta_get(conn, CURL_META_LDAP_CONN);
1174 struct ldapreqinfo *lr = Curl_meta_get(data, CURL_META_LDAP_EASY);
1175 int rc;
1176 LDAPMessage *msg = NULL;
1177 BerElement *ber = NULL;
1178 struct timeval tv = { 0, 0 };
1179 struct berval bv, *bvals;
1180 CURLcode result = CURLE_AGAIN;
1181 int code;
1182 char *info = NULL;
1184 (void)len;
1185 (void)buf;
1186 (void)sockindex;
1187 *pnread = 0;
1188 if(!li || !lr)
1189 return CURLE_FAILED_INIT;
1191 rc = ldap_result(li->ld, lr->msgid, LDAP_MSG_ONE, &tv, &msg);
1192 if(rc < 0) {
1193 failf(data, "LDAP local: search ldap_result %s", ldap_err2string(rc));
1194 result = CURLE_RECV_ERROR;
1197 /* error or timed out */
1198 if(!msg)
1199 return result;
1201 result = CURLE_OK;
1203 switch(ldap_msgtype(msg)) {
1204 case LDAP_RES_SEARCH_RESULT:
1205 lr->msgid = 0;
1206 rc = ldap_parse_result(li->ld, msg, &code, NULL, &info, NULL, NULL, 0);
1207 if(rc) {
1208 failf(data, "LDAP local: search ldap_parse_result %s",
1209 ldap_err2string(rc));
1210 result = CURLE_LDAP_SEARCH_FAILED;
1211 break;
1214 /* store the latest code for later retrieval */
1215 data->info.httpcode = code;
1217 switch(code) {
1218 case LDAP_SIZELIMIT_EXCEEDED:
1219 infof(data, "There are more than %d entries", lr->nument);
1220 FALLTHROUGH();
1221 case LDAP_SUCCESS:
1222 data->req.size = data->req.bytecount;
1223 break;
1224 default:
1225 failf(data, "LDAP remote: search failed %s %s", ldap_err2string(code),
1226 info ? info : "");
1227 result = CURLE_LDAP_SEARCH_FAILED;
1228 break;
1230 if(info)
1231 ldap_memfree(info);
1232 break;
1233 case LDAP_RES_SEARCH_ENTRY:
1234 lr->nument++;
1235 rc = ldap_get_dn_ber(li->ld, msg, &ber, &bv);
1236 if(rc < 0) {
1237 result = CURLE_RECV_ERROR;
1238 break;
1241 if(oldap_str_needs_base64(bv.bv_val, bv.bv_len)) {
1242 char *dn_b64 = NULL;
1243 size_t dn_b64_sz = 0;
1245 /* A DN with e.g. CR/LF would inject LDIF lines, so base64-encode it. */
1246 result = curlx_base64_encode((uint8_t *)bv.bv_val, bv.bv_len,
1247 &dn_b64, &dn_b64_sz);
1248 if(!result)
1249 result = client_write(data, STRCONST("DN:: "), dn_b64, dn_b64_sz,
1250 STRCONST("\n"));
1251 curlx_free(dn_b64);
1253 else
1254 result = client_write(data, STRCONST("DN: "), bv.bv_val, bv.bv_len,
1255 STRCONST("\n"));
1256 if(result)
1257 break;
1259 for(rc = ldap_get_attribute_ber(li->ld, msg, ber, &bv, &bvals);
1260 rc == LDAP_SUCCESS;
1261 rc = ldap_get_attribute_ber(li->ld, msg, ber, &bv, &bvals)) {
1262 int i;
1263 bool binary;
1265 if(!bv.bv_val)
1266 break;
1268 /* An attribute type has no base64 form in LDIF, so a type carrying
1269 control bytes (CR/LF etc.) would let a hostile server inject lines.
1270 A conformant type name never contains them, so reject it. */
1271 if(oldap_str_needs_base64(bv.bv_val, bv.bv_len)) {
1272 failf(data, "LDAP local: attribute type contains illegal bytes");
1273 if(bvals)
1274 ber_memfree(bvals);
1275 result = CURLE_WEIRD_SERVER_REPLY;
1276 break;
1279 if(!bvals) {
1280 result = client_write(data, STRCONST("\t"), bv.bv_val, bv.bv_len,
1281 STRCONST(":\n"));
1282 if(result)
1283 break;
1284 continue;
1287 binary = bv.bv_len > 7 &&
1288 curl_strnequal(bv.bv_val + bv.bv_len - 7, ";binary", 7);
1290 for(i = 0; bvals[i].bv_val; i++) {
1291 bool binval = FALSE;
1293 result = client_write(data, STRCONST("\t"), bv.bv_val, bv.bv_len,
1294 STRCONST(":"));
1295 if(result)
1296 break;
1298 if(!binary)
1299 binval = oldap_str_needs_base64(bvals[i].bv_val, bvals[i].bv_len);
1300 if(binary || binval) {
1301 char *val_b64 = NULL;
1302 size_t val_b64_sz = 0;
1304 /* Binary value, encode to base64. */
1305 if(bvals[i].bv_len)
1306 result = curlx_base64_encode((uint8_t *)bvals[i].bv_val,
1307 bvals[i].bv_len,
1308 &val_b64, &val_b64_sz);
1309 if(!result)
1310 result = client_write(data, STRCONST(": "), val_b64, val_b64_sz,
1311 STRCONST("\n"));
1312 curlx_free(val_b64);
1314 else
1315 result = client_write(data, STRCONST(" "),
1316 bvals[i].bv_val, bvals[i].bv_len,
1317 STRCONST("\n"));
1318 if(result)
1319 break;
1322 ber_memfree(bvals);
1323 bvals = NULL;
1324 if(!result)
1325 result = client_write(data, STRCONST("\n"), NULL, 0, NULL, 0);
1326 if(result)
1327 break;
1330 if(!result)
1331 result = client_write(data, STRCONST("\n"), NULL, 0, NULL, 0);
1332 if(!result)
1333 result = CURLE_AGAIN;
1334 break;
1337 ber_free(ber, 0);
1338 ldap_msgfree(msg);
1339 return result;
1342void Curl_ldap_version(char *buf, size_t bufsz)
1344 LDAPAPIInfo api;
1345 api.ldapai_info_version = LDAP_API_INFO_VERSION;
1347 if(ldap_get_option(NULL, LDAP_OPT_API_INFO, &api) == LDAP_OPT_SUCCESS) {
1348 unsigned int patch = (unsigned int)(api.ldapai_vendor_version % 100);
1349 unsigned int major = (unsigned int)(api.ldapai_vendor_version / 10000);
1350 unsigned int minor =
1351 (((unsigned int)api.ldapai_vendor_version - (major * 10000))
1352 - patch) / 100;
1353 curl_msnprintf(buf, bufsz, "%s/%u.%u.%u",
1354 api.ldapai_vendor_name, major, minor, patch);
1355 ldap_memfree(api.ldapai_vendor_name);
1356 ber_memvfree((void **)api.ldapai_extensions);
1358 else
1359 curl_msnprintf(buf, bufsz, "OpenLDAP");
1363 * LDAP protocol handler.
1364 */
1365const struct Curl_protocol Curl_protocol_ldap = {
1366 oldap_setup_connection, /* setup_connection */
1367 ZERO_NULL, /* setup_filters */
1368 oldap_do, /* do_it */
1369 oldap_done, /* done */
1370 ZERO_NULL, /* do_more */
1371 oldap_connect, /* connect_it */
1372 oldap_connecting, /* connecting */
1373 ZERO_NULL, /* doing */
1374 ZERO_NULL, /* proto_pollset */
1375 ZERO_NULL, /* doing_pollset */
1376 ZERO_NULL, /* domore_pollset */
1377 ZERO_NULL, /* perform_pollset */
1378 oldap_disconnect, /* disconnect */
1379 ZERO_NULL, /* write_resp */
1380 ZERO_NULL, /* write_resp_hd */
1381 ZERO_NULL, /* connection_is_dead */
1382 ZERO_NULL, /* attach connection */
1383 ZERO_NULL, /* follow */
1386#endif /* !CURL_DISABLE_LDAP && USE_OPENLDAP */
1388/* The LDAP scheme structs are in ldap.c */
Diagnostics4 git calls · 30 ms
CallStatusSizeTime030 ms
discover200152 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=152
git.server.agent=gitty/1.0
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch object-format
git.server.fetch=shallow filter sideband-all
git.protocol.version=2
git.pkt.frames=8
git.pkt.data=6
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=152
git.pkt.payload.max=34
ls-refs200149 B · hit2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=149
git.response.cache=HIT
git.response.duration_ms=2
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=149
git.pkt.payload.max=78
git.ls_refs.count=2
git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit7 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=21
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=7
git.fetch.filter=blob:none
git.fetch.filter.requested=tree:0
git.fetch.filter.fallback=blob:none
git.fetch.filter.learned=false
git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=10
git.pkt.data=8
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=293470
git.pkt.payload.max=65516
git.sideband.band1.bytes=293354
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=87
git.pack.bytes=293354
git.pack.ofs_delta=0
git.pack.ref_delta=1
git.pack.chain.max=1
git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0
git.pack.full=86
Open pack map
fetch20011 KiB · hit21 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=11299
git.response.cache=HIT
git.response.duration_ms=21
git.fetch.wants=982a59ca8aa0333e4af15909c014f6fa509fbe33
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=11299
git.pkt.payload.max=11278
git.sideband.band1.bytes=11277
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
Ref
refs/heads/master
Commit
31c911efe5652725e930f4d2e60c9060e5f6646d
cf-ray
a5e9e6ba789ceefa
Request
a46053ca…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format