2010-05-24 18:44:42 -04:00
|
|
|
/***************************************************************************
|
2013-01-03 20:50:28 -05:00
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
2010-05-24 18:44:42 -04:00
|
|
|
*
|
2021-01-08 11:58:15 -05:00
|
|
|
* Copyright (C) 2011 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2018-03-07 08:43:12 -05:00
|
|
|
* Copyright (C) 2010, Howard Chu, <hyc@openldap.org>
|
2010-05-24 18:44:42 -04:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2020-11-04 08:02:01 -05:00
|
|
|
* are also available at https://curl.se/docs/copyright.html.
|
2010-05-24 18:44:42 -04:00
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
|
2013-01-06 13:06:49 -05:00
|
|
|
#include "curl_setup.h"
|
2010-05-24 18:44:42 -04:00
|
|
|
|
2010-06-01 11:25:03 -04:00
|
|
|
#if !defined(CURL_DISABLE_LDAP) && defined(USE_OPENLDAP)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Notice that USE_OPENLDAP is only a source code selection switch. When
|
|
|
|
* libcurl is built with USE_OPENLDAP defined the libcurl source code that
|
2013-01-03 20:50:28 -05:00
|
|
|
* gets compiled is the code from openldap.c, otherwise the code that gets
|
|
|
|
* compiled is the code from ldap.c.
|
2010-06-01 11:25:03 -04:00
|
|
|
*
|
|
|
|
* When USE_OPENLDAP is defined a recent version of the OpenLDAP library
|
|
|
|
* might be required for compilation and runtime. In order to use ancient
|
|
|
|
* OpenLDAP library versions, USE_OPENLDAP shall not be defined.
|
|
|
|
*/
|
2010-05-24 18:44:42 -04:00
|
|
|
|
2010-06-02 05:23:30 -04:00
|
|
|
#include <ldap.h>
|
|
|
|
|
2013-01-03 20:50:28 -05:00
|
|
|
#include "urldata.h"
|
2010-05-24 18:44:42 -04:00
|
|
|
#include <curl/curl.h>
|
2013-01-03 20:50:28 -05:00
|
|
|
#include "sendf.h"
|
2013-12-17 17:32:47 -05:00
|
|
|
#include "vtls/vtls.h"
|
2013-01-03 20:50:28 -05:00
|
|
|
#include "transfer.h"
|
2010-06-02 05:23:30 -04:00
|
|
|
#include "curl_ldap.h"
|
2010-05-24 18:44:42 -04:00
|
|
|
#include "curl_base64.h"
|
2014-05-20 04:32:23 -04:00
|
|
|
#include "connect.h"
|
2016-04-29 09:46:40 -04:00
|
|
|
/* The last 3 #include files should be in this order */
|
2015-03-03 06:36:18 -05:00
|
|
|
#include "curl_printf.h"
|
2015-03-24 18:12:03 -04:00
|
|
|
#include "curl_memory.h"
|
2013-01-03 20:50:28 -05:00
|
|
|
#include "memdebug.h"
|
2010-05-24 18:44:42 -04:00
|
|
|
|
2017-12-06 02:54:35 -05:00
|
|
|
/*
|
|
|
|
* Uncommenting this will enable the built-in debug logging of the openldap
|
|
|
|
* library. The debug log level can be set using the CURL_OPENLDAP_TRACE
|
|
|
|
* environment variable. The debug output is written to stderr.
|
2017-12-06 08:58:26 -05:00
|
|
|
*
|
|
|
|
* The library supports the following debug flags:
|
2017-12-06 02:54:35 -05:00
|
|
|
* LDAP_DEBUG_NONE 0x0000
|
|
|
|
* LDAP_DEBUG_TRACE 0x0001
|
|
|
|
* LDAP_DEBUG_CONSTRUCT 0x0002
|
|
|
|
* LDAP_DEBUG_DESTROY 0x0004
|
|
|
|
* LDAP_DEBUG_PARAMETER 0x0008
|
2017-12-06 08:58:26 -05:00
|
|
|
* LDAP_DEBUG_ANY 0xffff
|
|
|
|
*
|
2017-12-06 02:54:35 -05:00
|
|
|
* For example, use CURL_OPENLDAP_TRACE=0 for no debug,
|
|
|
|
* CURL_OPENLDAP_TRACE=2 for LDAP_DEBUG_CONSTRUCT messages only,
|
|
|
|
* CURL_OPENLDAP_TRACE=65535 for all debug message levels.
|
|
|
|
*/
|
|
|
|
/* #define CURL_OPENLDAP_DEBUG */
|
|
|
|
|
2010-05-27 16:37:00 -04:00
|
|
|
#ifndef _LDAP_PVT_H
|
|
|
|
extern int ldap_pvt_url_scheme2proto(const char *);
|
2011-04-20 09:17:42 -04:00
|
|
|
extern int ldap_init_fd(ber_socket_t fd, int proto, const char *url,
|
|
|
|
LDAP **ld);
|
2010-05-27 16:37:00 -04:00
|
|
|
#endif
|
|
|
|
|
2021-01-08 11:58:15 -05:00
|
|
|
static CURLcode ldap_setup_connection(struct Curl_easy *data,
|
|
|
|
struct connectdata *conn);
|
|
|
|
static CURLcode ldap_do(struct Curl_easy *data, bool *done);
|
|
|
|
static CURLcode ldap_done(struct Curl_easy *data, CURLcode, bool);
|
|
|
|
static CURLcode ldap_connect(struct Curl_easy *data, bool *done);
|
|
|
|
static CURLcode ldap_connecting(struct Curl_easy *data, bool *done);
|
|
|
|
static CURLcode ldap_disconnect(struct Curl_easy *data,
|
|
|
|
struct connectdata *conn, bool dead);
|
2010-05-24 18:44:42 -04:00
|
|
|
|
|
|
|
static Curl_recv ldap_recv;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* LDAP protocol handler.
|
|
|
|
*/
|
|
|
|
|
|
|
|
const struct Curl_handler Curl_handler_ldap = {
|
|
|
|
"LDAP", /* scheme */
|
2014-12-24 12:14:02 -05:00
|
|
|
ldap_setup_connection, /* setup_connection */
|
2010-05-24 18:44:42 -04:00
|
|
|
ldap_do, /* do_it */
|
|
|
|
ldap_done, /* done */
|
|
|
|
ZERO_NULL, /* do_more */
|
|
|
|
ldap_connect, /* connect_it */
|
|
|
|
ldap_connecting, /* connecting */
|
|
|
|
ZERO_NULL, /* doing */
|
|
|
|
ZERO_NULL, /* proto_getsock */
|
|
|
|
ZERO_NULL, /* doing_getsock */
|
2011-10-21 17:36:54 -04:00
|
|
|
ZERO_NULL, /* domore_getsock */
|
2010-05-24 18:44:42 -04:00
|
|
|
ZERO_NULL, /* perform_getsock */
|
|
|
|
ldap_disconnect, /* disconnect */
|
2011-05-05 10:27:03 -04:00
|
|
|
ZERO_NULL, /* readwrite */
|
2017-05-31 07:09:56 -04:00
|
|
|
ZERO_NULL, /* connection_check */
|
2010-05-24 18:44:42 -04:00
|
|
|
PORT_LDAP, /* defport */
|
2011-03-14 17:52:14 -04:00
|
|
|
CURLPROTO_LDAP, /* protocol */
|
2020-09-21 07:45:24 -04:00
|
|
|
CURLPROTO_LDAP, /* family */
|
2011-03-14 17:22:22 -04:00
|
|
|
PROTOPT_NONE /* flags */
|
2010-05-24 18:44:42 -04:00
|
|
|
};
|
|
|
|
|
2010-05-28 06:22:35 -04:00
|
|
|
#ifdef USE_SSL
|
2010-05-24 18:44:42 -04:00
|
|
|
/*
|
|
|
|
* LDAPS protocol handler.
|
|
|
|
*/
|
|
|
|
|
|
|
|
const struct Curl_handler Curl_handler_ldaps = {
|
|
|
|
"LDAPS", /* scheme */
|
2014-12-24 12:14:02 -05:00
|
|
|
ldap_setup_connection, /* setup_connection */
|
2010-05-24 18:44:42 -04:00
|
|
|
ldap_do, /* do_it */
|
|
|
|
ldap_done, /* done */
|
|
|
|
ZERO_NULL, /* do_more */
|
|
|
|
ldap_connect, /* connect_it */
|
|
|
|
ldap_connecting, /* connecting */
|
|
|
|
ZERO_NULL, /* doing */
|
|
|
|
ZERO_NULL, /* proto_getsock */
|
|
|
|
ZERO_NULL, /* doing_getsock */
|
2011-10-21 17:36:54 -04:00
|
|
|
ZERO_NULL, /* domore_getsock */
|
2010-05-24 18:44:42 -04:00
|
|
|
ZERO_NULL, /* perform_getsock */
|
|
|
|
ldap_disconnect, /* disconnect */
|
2011-05-05 10:27:03 -04:00
|
|
|
ZERO_NULL, /* readwrite */
|
2017-05-31 07:09:56 -04:00
|
|
|
ZERO_NULL, /* connection_check */
|
2010-05-24 18:44:42 -04:00
|
|
|
PORT_LDAPS, /* defport */
|
2020-09-21 07:45:24 -04:00
|
|
|
CURLPROTO_LDAPS, /* protocol */
|
|
|
|
CURLPROTO_LDAP, /* family */
|
2011-03-14 17:22:22 -04:00
|
|
|
PROTOPT_SSL /* flags */
|
2010-05-24 18:44:42 -04:00
|
|
|
};
|
2010-05-28 06:22:35 -04:00
|
|
|
#endif
|
2010-05-24 18:44:42 -04:00
|
|
|
|
|
|
|
static const char *url_errs[] = {
|
|
|
|
"success",
|
|
|
|
"out of memory",
|
|
|
|
"bad parameter",
|
|
|
|
"unrecognized scheme",
|
|
|
|
"unbalanced delimiter",
|
|
|
|
"bad URL",
|
|
|
|
"bad host or port",
|
|
|
|
"bad or missing attributes",
|
|
|
|
"bad or missing scope",
|
|
|
|
"bad or missing filter",
|
|
|
|
"bad or missing extensions"
|
|
|
|
};
|
|
|
|
|
2019-09-03 07:31:44 -04:00
|
|
|
struct ldapconninfo {
|
2010-05-24 18:44:42 -04:00
|
|
|
LDAP *ld;
|
|
|
|
Curl_recv *recv; /* for stacking SSL handler */
|
|
|
|
Curl_send *send;
|
|
|
|
int proto;
|
|
|
|
int msgid;
|
|
|
|
bool ssldone;
|
|
|
|
bool sslinst;
|
|
|
|
bool didbind;
|
2019-09-03 07:31:44 -04:00
|
|
|
};
|
2010-05-24 18:44:42 -04:00
|
|
|
|
2020-05-13 18:05:04 -04:00
|
|
|
struct ldapreqinfo {
|
2010-05-24 18:44:42 -04:00
|
|
|
int msgid;
|
|
|
|
int nument;
|
2020-05-13 18:05:04 -04:00
|
|
|
};
|
2010-05-24 18:44:42 -04:00
|
|
|
|
2021-01-08 11:58:15 -05:00
|
|
|
static CURLcode ldap_setup_connection(struct Curl_easy *data,
|
|
|
|
struct connectdata *conn)
|
2010-05-24 18:44:42 -04:00
|
|
|
{
|
2019-09-03 07:31:44 -04:00
|
|
|
struct ldapconninfo *li;
|
2010-05-24 18:44:42 -04:00
|
|
|
LDAPURLDesc *lud;
|
|
|
|
int rc, proto;
|
|
|
|
CURLcode status;
|
|
|
|
|
|
|
|
rc = ldap_url_parse(data->change.url, &lud);
|
2011-04-20 09:17:42 -04:00
|
|
|
if(rc != LDAP_URL_SUCCESS) {
|
2010-05-24 18:44:42 -04:00
|
|
|
const char *msg = "url parsing problem";
|
|
|
|
status = CURLE_URL_MALFORMAT;
|
2011-04-20 09:17:42 -04:00
|
|
|
if(rc > LDAP_URL_SUCCESS && rc <= LDAP_URL_ERR_BADEXTS) {
|
|
|
|
if(rc == LDAP_URL_ERR_MEM)
|
2010-05-24 18:44:42 -04:00
|
|
|
status = CURLE_OUT_OF_MEMORY;
|
|
|
|
msg = url_errs[rc];
|
|
|
|
}
|
|
|
|
failf(conn->data, "LDAP local: %s", msg);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
proto = ldap_pvt_url_scheme2proto(lud->lud_scheme);
|
|
|
|
ldap_free_urldesc(lud);
|
|
|
|
|
2019-09-03 07:31:44 -04:00
|
|
|
li = calloc(1, sizeof(struct ldapconninfo));
|
2012-06-08 14:56:22 -04:00
|
|
|
if(!li)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
2010-05-24 18:44:42 -04:00
|
|
|
li->proto = proto;
|
2019-09-03 07:31:44 -04:00
|
|
|
conn->proto.ldapc = li;
|
2014-05-20 04:32:23 -04:00
|
|
|
connkeep(conn, "OpenLDAP default");
|
2010-05-24 18:44:42 -04:00
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2010-05-28 06:22:35 -04:00
|
|
|
#ifdef USE_SSL
|
2010-05-24 18:44:42 -04:00
|
|
|
static Sockbuf_IO ldapsb_tls;
|
2010-05-28 06:22:35 -04:00
|
|
|
#endif
|
2010-05-24 18:44:42 -04:00
|
|
|
|
2021-01-08 11:58:15 -05:00
|
|
|
static CURLcode ldap_connect(struct Curl_easy *data, bool *done)
|
2010-05-24 18:44:42 -04:00
|
|
|
{
|
2021-01-08 11:58:15 -05:00
|
|
|
struct connectdata *conn = data->conn;
|
2019-09-03 07:31:44 -04:00
|
|
|
struct ldapconninfo *li = conn->proto.ldapc;
|
2010-05-24 18:44:42 -04:00
|
|
|
int rc, proto = LDAP_VERSION3;
|
2014-12-27 16:22:45 -05:00
|
|
|
char hosturl[1024];
|
|
|
|
char *ptr;
|
|
|
|
|
2013-01-17 06:59:23 -05:00
|
|
|
(void)done;
|
2010-05-24 18:44:42 -04:00
|
|
|
|
|
|
|
strcpy(hosturl, "ldap");
|
2017-09-09 17:55:08 -04:00
|
|
|
ptr = hosturl + 4;
|
2011-04-20 09:17:42 -04:00
|
|
|
if(conn->handler->flags & PROTOPT_SSL)
|
2010-05-24 18:44:42 -04:00
|
|
|
*ptr++ = 's';
|
2018-11-22 03:01:24 -05:00
|
|
|
msnprintf(ptr, sizeof(hosturl)-(ptr-hosturl), "://%s:%d",
|
|
|
|
conn->host.name, conn->remote_port);
|
2010-05-24 18:44:42 -04:00
|
|
|
|
2017-12-06 02:54:35 -05:00
|
|
|
#ifdef CURL_OPENLDAP_DEBUG
|
|
|
|
static int do_trace = 0;
|
|
|
|
const char *env = getenv("CURL_OPENLDAP_TRACE");
|
|
|
|
do_trace = (env && strtol(env, NULL, 10) > 0);
|
2017-12-06 08:58:26 -05:00
|
|
|
if(do_trace) {
|
2017-12-06 02:54:35 -05:00
|
|
|
ldap_set_option(li->ld, LDAP_OPT_DEBUG_LEVEL, &do_trace);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-05-24 18:44:42 -04:00
|
|
|
rc = ldap_init_fd(conn->sock[FIRSTSOCKET], li->proto, hosturl, &li->ld);
|
2011-04-20 09:17:42 -04:00
|
|
|
if(rc) {
|
2010-05-24 18:44:42 -04:00
|
|
|
failf(data, "LDAP local: Cannot connect to %s, %s",
|
|
|
|
hosturl, ldap_err2string(rc));
|
|
|
|
return CURLE_COULDNT_CONNECT;
|
|
|
|
}
|
|
|
|
|
|
|
|
ldap_set_option(li->ld, LDAP_OPT_PROTOCOL_VERSION, &proto);
|
|
|
|
|
2010-05-28 06:22:35 -04:00
|
|
|
#ifdef USE_SSL
|
2011-04-20 09:17:42 -04:00
|
|
|
if(conn->handler->flags & PROTOPT_SSL) {
|
2014-12-27 16:22:45 -05:00
|
|
|
CURLcode result;
|
2021-01-13 11:01:31 -05:00
|
|
|
result = Curl_ssl_connect_nonblocking(data, conn,
|
|
|
|
FIRSTSOCKET, &li->ssldone);
|
2014-12-27 16:22:45 -05:00
|
|
|
if(result)
|
|
|
|
return result;
|
2010-05-24 18:44:42 -04:00
|
|
|
}
|
2010-05-28 06:22:35 -04:00
|
|
|
#endif
|
2010-05-24 18:44:42 -04:00
|
|
|
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2021-01-08 11:58:15 -05:00
|
|
|
static CURLcode ldap_connecting(struct Curl_easy *data, bool *done)
|
2010-05-24 18:44:42 -04:00
|
|
|
{
|
2021-01-08 11:58:15 -05:00
|
|
|
struct connectdata *conn = data->conn;
|
2019-09-03 07:31:44 -04:00
|
|
|
struct ldapconninfo *li = conn->proto.ldapc;
|
2014-12-27 16:07:53 -05:00
|
|
|
LDAPMessage *msg = NULL;
|
2015-03-17 08:41:49 -04:00
|
|
|
struct timeval tv = {0, 1}, *tvp;
|
2010-05-24 18:44:42 -04:00
|
|
|
int rc, err;
|
|
|
|
char *info = NULL;
|
|
|
|
|
2010-05-28 06:22:35 -04:00
|
|
|
#ifdef USE_SSL
|
2011-04-20 09:17:42 -04:00
|
|
|
if(conn->handler->flags & PROTOPT_SSL) {
|
2010-05-24 18:44:42 -04:00
|
|
|
/* Is the SSL handshake complete yet? */
|
2011-04-20 09:17:42 -04:00
|
|
|
if(!li->ssldone) {
|
2021-01-13 11:01:31 -05:00
|
|
|
CURLcode result = Curl_ssl_connect_nonblocking(data, conn, FIRSTSOCKET,
|
2014-12-27 16:22:45 -05:00
|
|
|
&li->ssldone);
|
|
|
|
if(result || !li->ssldone)
|
|
|
|
return result;
|
2010-05-24 18:44:42 -04:00
|
|
|
}
|
2014-12-27 16:22:45 -05:00
|
|
|
|
2010-05-24 18:44:42 -04:00
|
|
|
/* Have we installed the libcurl SSL handlers into the sockbuf yet? */
|
2011-04-20 09:17:42 -04:00
|
|
|
if(!li->sslinst) {
|
2010-05-24 18:44:42 -04:00
|
|
|
Sockbuf *sb;
|
|
|
|
ldap_get_option(li->ld, LDAP_OPT_SOCKBUF, &sb);
|
|
|
|
ber_sockbuf_add_io(sb, &ldapsb_tls, LBER_SBIOD_LEVEL_TRANSPORT, conn);
|
|
|
|
li->sslinst = TRUE;
|
|
|
|
li->recv = conn->recv[FIRSTSOCKET];
|
|
|
|
li->send = conn->send[FIRSTSOCKET];
|
|
|
|
}
|
|
|
|
}
|
2010-05-28 06:22:35 -04:00
|
|
|
#endif
|
2010-05-24 18:44:42 -04:00
|
|
|
|
2013-01-17 06:59:23 -05:00
|
|
|
tvp = &tv;
|
2010-05-24 18:44:42 -04:00
|
|
|
|
2018-03-07 08:43:12 -05:00
|
|
|
retry:
|
2011-04-20 09:17:42 -04:00
|
|
|
if(!li->didbind) {
|
2010-05-24 18:44:42 -04:00
|
|
|
char *binddn;
|
|
|
|
struct berval passwd;
|
|
|
|
|
2011-04-20 09:17:42 -04:00
|
|
|
if(conn->bits.user_passwd) {
|
2010-05-24 18:44:42 -04:00
|
|
|
binddn = conn->user;
|
|
|
|
passwd.bv_val = conn->passwd;
|
|
|
|
passwd.bv_len = strlen(passwd.bv_val);
|
2011-04-20 09:17:42 -04:00
|
|
|
}
|
|
|
|
else {
|
2010-05-24 18:44:42 -04:00
|
|
|
binddn = NULL;
|
|
|
|
passwd.bv_val = NULL;
|
|
|
|
passwd.bv_len = 0;
|
|
|
|
}
|
|
|
|
rc = ldap_sasl_bind(li->ld, binddn, LDAP_SASL_SIMPLE, &passwd,
|
|
|
|
NULL, NULL, &li->msgid);
|
2011-04-20 09:17:42 -04:00
|
|
|
if(rc)
|
2010-05-24 18:44:42 -04:00
|
|
|
return CURLE_LDAP_CANNOT_BIND;
|
|
|
|
li->didbind = TRUE;
|
2011-04-20 09:17:42 -04:00
|
|
|
if(tvp)
|
2010-05-24 18:44:42 -04:00
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2014-12-27 16:07:53 -05:00
|
|
|
rc = ldap_result(li->ld, li->msgid, LDAP_MSG_ONE, tvp, &msg);
|
2011-04-20 09:17:42 -04:00
|
|
|
if(rc < 0) {
|
2010-05-24 18:44:42 -04:00
|
|
|
failf(data, "LDAP local: bind ldap_result %s", ldap_err2string(rc));
|
|
|
|
return CURLE_LDAP_CANNOT_BIND;
|
|
|
|
}
|
2011-04-20 09:17:42 -04:00
|
|
|
if(rc == 0) {
|
2010-05-24 18:44:42 -04:00
|
|
|
/* timed out */
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
2014-12-27 16:07:53 -05:00
|
|
|
|
|
|
|
rc = ldap_parse_result(li->ld, msg, &err, NULL, &info, NULL, NULL, 1);
|
2011-04-20 09:17:42 -04:00
|
|
|
if(rc) {
|
2010-05-24 18:44:42 -04:00
|
|
|
failf(data, "LDAP local: bind ldap_parse_result %s", ldap_err2string(rc));
|
|
|
|
return CURLE_LDAP_CANNOT_BIND;
|
|
|
|
}
|
2014-12-27 16:22:45 -05:00
|
|
|
|
2010-05-24 18:44:42 -04:00
|
|
|
/* Try to fallback to LDAPv2? */
|
2011-04-20 09:17:42 -04:00
|
|
|
if(err == LDAP_PROTOCOL_ERROR) {
|
2010-05-24 18:44:42 -04:00
|
|
|
int proto;
|
|
|
|
ldap_get_option(li->ld, LDAP_OPT_PROTOCOL_VERSION, &proto);
|
2011-04-20 09:17:42 -04:00
|
|
|
if(proto == LDAP_VERSION3) {
|
2012-01-18 10:06:29 -05:00
|
|
|
if(info) {
|
|
|
|
ldap_memfree(info);
|
|
|
|
info = NULL;
|
|
|
|
}
|
2010-05-24 18:44:42 -04:00
|
|
|
proto = LDAP_VERSION2;
|
|
|
|
ldap_set_option(li->ld, LDAP_OPT_PROTOCOL_VERSION, &proto);
|
|
|
|
li->didbind = FALSE;
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-20 09:17:42 -04:00
|
|
|
if(err) {
|
2010-05-24 18:44:42 -04:00
|
|
|
failf(data, "LDAP remote: bind failed %s %s", ldap_err2string(rc),
|
|
|
|
info ? info : "");
|
2012-01-18 10:06:29 -05:00
|
|
|
if(info)
|
|
|
|
ldap_memfree(info);
|
2010-05-24 18:44:42 -04:00
|
|
|
return CURLE_LOGIN_DENIED;
|
|
|
|
}
|
2012-01-18 10:06:29 -05:00
|
|
|
|
|
|
|
if(info)
|
|
|
|
ldap_memfree(info);
|
2010-05-24 18:44:42 -04:00
|
|
|
conn->recv[FIRSTSOCKET] = ldap_recv;
|
|
|
|
*done = TRUE;
|
2014-12-27 16:22:45 -05:00
|
|
|
|
2010-05-24 18:44:42 -04:00
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2021-01-08 11:58:15 -05:00
|
|
|
static CURLcode ldap_disconnect(struct Curl_easy *data,
|
|
|
|
struct connectdata *conn, bool dead_connection)
|
2010-05-24 18:44:42 -04:00
|
|
|
{
|
2019-09-03 07:31:44 -04:00
|
|
|
struct ldapconninfo *li = conn->proto.ldapc;
|
2010-11-19 07:43:20 -05:00
|
|
|
(void) dead_connection;
|
2021-01-08 11:58:15 -05:00
|
|
|
(void) data;
|
2010-05-24 18:44:42 -04:00
|
|
|
|
2011-04-20 09:17:42 -04:00
|
|
|
if(li) {
|
|
|
|
if(li->ld) {
|
2010-05-27 16:37:00 -04:00
|
|
|
ldap_unbind_ext(li->ld, NULL, NULL);
|
2010-05-24 18:44:42 -04:00
|
|
|
li->ld = NULL;
|
|
|
|
}
|
2019-09-03 07:31:44 -04:00
|
|
|
conn->proto.ldapc = NULL;
|
2010-05-24 18:44:42 -04:00
|
|
|
free(li);
|
|
|
|
}
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2021-01-08 11:58:15 -05:00
|
|
|
static CURLcode ldap_do(struct Curl_easy *data, bool *done)
|
2010-05-24 18:44:42 -04:00
|
|
|
{
|
2021-01-08 11:58:15 -05:00
|
|
|
struct connectdata *conn = data->conn;
|
2019-09-03 07:31:44 -04:00
|
|
|
struct ldapconninfo *li = conn->proto.ldapc;
|
2020-05-13 18:05:04 -04:00
|
|
|
struct ldapreqinfo *lr;
|
2010-05-24 18:44:42 -04:00
|
|
|
CURLcode status = CURLE_OK;
|
|
|
|
int rc = 0;
|
|
|
|
LDAPURLDesc *ludp = NULL;
|
|
|
|
int msgid;
|
|
|
|
|
2014-05-20 04:32:23 -04:00
|
|
|
connkeep(conn, "OpenLDAP do");
|
2010-05-24 18:44:42 -04:00
|
|
|
|
|
|
|
infof(data, "LDAP local: %s\n", data->change.url);
|
|
|
|
|
|
|
|
rc = ldap_url_parse(data->change.url, &ludp);
|
2011-04-20 09:17:42 -04:00
|
|
|
if(rc != LDAP_URL_SUCCESS) {
|
2010-05-24 18:44:42 -04:00
|
|
|
const char *msg = "url parsing problem";
|
|
|
|
status = CURLE_URL_MALFORMAT;
|
2011-04-20 09:17:42 -04:00
|
|
|
if(rc > LDAP_URL_SUCCESS && rc <= LDAP_URL_ERR_BADEXTS) {
|
|
|
|
if(rc == LDAP_URL_ERR_MEM)
|
2010-05-24 18:44:42 -04:00
|
|
|
status = CURLE_OUT_OF_MEMORY;
|
|
|
|
msg = url_errs[rc];
|
|
|
|
}
|
|
|
|
failf(conn->data, "LDAP local: %s", msg);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = ldap_search_ext(li->ld, ludp->lud_dn, ludp->lud_scope,
|
|
|
|
ludp->lud_filter, ludp->lud_attrs, 0,
|
|
|
|
NULL, NULL, NULL, 0, &msgid);
|
|
|
|
ldap_free_urldesc(ludp);
|
2011-04-20 09:17:42 -04:00
|
|
|
if(rc != LDAP_SUCCESS) {
|
2010-05-24 18:44:42 -04:00
|
|
|
failf(data, "LDAP local: ldap_search_ext %s", ldap_err2string(rc));
|
|
|
|
return CURLE_LDAP_SEARCH_FAILED;
|
|
|
|
}
|
2020-05-13 18:05:04 -04:00
|
|
|
lr = calloc(1, sizeof(struct ldapreqinfo));
|
2012-06-08 14:56:22 -04:00
|
|
|
if(!lr)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
2010-05-24 18:44:42 -04:00
|
|
|
lr->msgid = msgid;
|
2020-11-23 02:32:41 -05:00
|
|
|
data->req.p.ldap = lr;
|
2019-02-28 05:36:26 -05:00
|
|
|
Curl_setup_transfer(data, FIRSTSOCKET, -1, FALSE, -1);
|
2010-05-24 18:44:42 -04:00
|
|
|
*done = TRUE;
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2021-01-08 11:58:15 -05:00
|
|
|
static CURLcode ldap_done(struct Curl_easy *data, CURLcode res,
|
2010-05-24 18:44:42 -04:00
|
|
|
bool premature)
|
|
|
|
{
|
2021-01-08 11:58:15 -05:00
|
|
|
struct connectdata *conn = data->conn;
|
|
|
|
struct ldapreqinfo *lr = data->req.p.ldap;
|
2014-12-27 16:22:45 -05:00
|
|
|
|
2010-05-24 18:44:42 -04:00
|
|
|
(void)res;
|
|
|
|
(void)premature;
|
|
|
|
|
2011-04-20 09:17:42 -04:00
|
|
|
if(lr) {
|
2010-05-24 18:44:42 -04:00
|
|
|
/* if there was a search in progress, abandon it */
|
2011-04-20 09:17:42 -04:00
|
|
|
if(lr->msgid) {
|
2019-09-03 07:31:44 -04:00
|
|
|
struct ldapconninfo *li = conn->proto.ldapc;
|
2010-05-27 16:37:00 -04:00
|
|
|
ldap_abandon_ext(li->ld, lr->msgid, NULL, NULL);
|
2010-05-24 18:44:42 -04:00
|
|
|
lr->msgid = 0;
|
|
|
|
}
|
2020-11-23 02:32:41 -05:00
|
|
|
conn->data->req.p.ldap = NULL;
|
2010-05-24 18:44:42 -04:00
|
|
|
free(lr);
|
|
|
|
}
|
2014-12-27 16:22:45 -05:00
|
|
|
|
2010-05-24 18:44:42 -04:00
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2021-01-08 11:58:15 -05:00
|
|
|
static ssize_t ldap_recv(struct Curl_easy *data, int sockindex, char *buf,
|
2010-05-24 18:44:42 -04:00
|
|
|
size_t len, CURLcode *err)
|
|
|
|
{
|
2021-01-08 11:58:15 -05:00
|
|
|
struct connectdata *conn = data->conn;
|
2019-09-03 07:31:44 -04:00
|
|
|
struct ldapconninfo *li = conn->proto.ldapc;
|
2020-11-23 02:32:41 -05:00
|
|
|
struct ldapreqinfo *lr = data->req.p.ldap;
|
2010-05-24 18:44:42 -04:00
|
|
|
int rc, ret;
|
2014-12-27 16:07:53 -05:00
|
|
|
LDAPMessage *msg = NULL;
|
2010-05-24 18:44:42 -04:00
|
|
|
LDAPMessage *ent;
|
|
|
|
BerElement *ber = NULL;
|
2015-03-17 08:41:49 -04:00
|
|
|
struct timeval tv = {0, 1};
|
2014-12-27 16:07:53 -05:00
|
|
|
|
2010-05-24 18:44:42 -04:00
|
|
|
(void)len;
|
|
|
|
(void)buf;
|
|
|
|
(void)sockindex;
|
|
|
|
|
2014-12-27 16:07:53 -05:00
|
|
|
rc = ldap_result(li->ld, lr->msgid, LDAP_MSG_RECEIVED, &tv, &msg);
|
2011-04-20 09:17:42 -04:00
|
|
|
if(rc < 0) {
|
2010-05-24 18:44:42 -04:00
|
|
|
failf(data, "LDAP local: search ldap_result %s", ldap_err2string(rc));
|
|
|
|
*err = CURLE_RECV_ERROR;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*err = CURLE_AGAIN;
|
|
|
|
ret = -1;
|
|
|
|
|
|
|
|
/* timed out */
|
2014-12-27 16:07:53 -05:00
|
|
|
if(!msg)
|
2010-05-24 18:44:42 -04:00
|
|
|
return ret;
|
|
|
|
|
2014-12-27 16:07:53 -05:00
|
|
|
for(ent = ldap_first_message(li->ld, msg); ent;
|
2018-03-07 08:43:12 -05:00
|
|
|
ent = ldap_next_message(li->ld, ent)) {
|
2018-03-06 17:02:16 -05:00
|
|
|
struct berval bv, *bvals;
|
2010-05-24 18:44:42 -04:00
|
|
|
int binary = 0, msgtype;
|
2015-09-17 12:36:07 -04:00
|
|
|
CURLcode writeerr;
|
2010-05-24 18:44:42 -04:00
|
|
|
|
|
|
|
msgtype = ldap_msgtype(ent);
|
2011-04-20 09:17:42 -04:00
|
|
|
if(msgtype == LDAP_RES_SEARCH_RESULT) {
|
2010-05-24 18:44:42 -04:00
|
|
|
int code;
|
|
|
|
char *info = NULL;
|
|
|
|
rc = ldap_parse_result(li->ld, ent, &code, NULL, &info, NULL, NULL, 0);
|
2011-04-20 09:17:42 -04:00
|
|
|
if(rc) {
|
2011-03-15 19:16:34 -04:00
|
|
|
failf(data, "LDAP local: search ldap_parse_result %s",
|
|
|
|
ldap_err2string(rc));
|
2010-05-24 18:44:42 -04:00
|
|
|
*err = CURLE_LDAP_SEARCH_FAILED;
|
2011-04-20 09:17:42 -04:00
|
|
|
}
|
|
|
|
else if(code && code != LDAP_SIZELIMIT_EXCEEDED) {
|
2010-05-24 18:44:42 -04:00
|
|
|
failf(data, "LDAP remote: search failed %s %s", ldap_err2string(rc),
|
2011-04-20 09:17:42 -04:00
|
|
|
info ? info : "");
|
2010-05-24 18:44:42 -04:00
|
|
|
*err = CURLE_LDAP_SEARCH_FAILED;
|
2011-04-20 09:17:42 -04:00
|
|
|
}
|
|
|
|
else {
|
2010-05-24 18:44:42 -04:00
|
|
|
/* successful */
|
2011-04-20 09:17:42 -04:00
|
|
|
if(code == LDAP_SIZELIMIT_EXCEEDED)
|
2010-05-24 18:44:42 -04:00
|
|
|
infof(data, "There are more than %d entries\n", lr->nument);
|
|
|
|
data->req.size = data->req.bytecount;
|
|
|
|
*err = CURLE_OK;
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
lr->msgid = 0;
|
|
|
|
ldap_memfree(info);
|
|
|
|
break;
|
|
|
|
}
|
2011-04-20 09:17:42 -04:00
|
|
|
else if(msgtype != LDAP_RES_SEARCH_ENTRY)
|
|
|
|
continue;
|
2010-05-24 18:44:42 -04:00
|
|
|
|
|
|
|
lr->nument++;
|
|
|
|
rc = ldap_get_dn_ber(li->ld, ent, &ber, &bv);
|
2011-03-15 19:16:34 -04:00
|
|
|
if(rc < 0) {
|
|
|
|
*err = CURLE_RECV_ERROR;
|
|
|
|
return -1;
|
|
|
|
}
|
2021-01-08 11:58:15 -05:00
|
|
|
writeerr = Curl_client_write(data, CLIENTWRITE_BODY, (char *)"DN: ", 4);
|
2015-09-17 12:36:07 -04:00
|
|
|
if(writeerr) {
|
|
|
|
*err = writeerr;
|
2014-12-08 09:30:14 -05:00
|
|
|
return -1;
|
2015-09-17 12:36:07 -04:00
|
|
|
}
|
2014-12-08 09:30:14 -05:00
|
|
|
|
2021-01-08 11:58:15 -05:00
|
|
|
writeerr = Curl_client_write(data, CLIENTWRITE_BODY, (char *)bv.bv_val,
|
2015-09-17 12:36:07 -04:00
|
|
|
bv.bv_len);
|
|
|
|
if(writeerr) {
|
|
|
|
*err = writeerr;
|
2014-12-08 09:30:14 -05:00
|
|
|
return -1;
|
2015-09-17 12:36:07 -04:00
|
|
|
}
|
2014-12-08 09:30:14 -05:00
|
|
|
|
2021-01-08 11:58:15 -05:00
|
|
|
writeerr = Curl_client_write(data, CLIENTWRITE_BODY, (char *)"\n", 1);
|
2015-09-17 12:36:07 -04:00
|
|
|
if(writeerr) {
|
|
|
|
*err = writeerr;
|
2014-12-08 09:30:14 -05:00
|
|
|
return -1;
|
2015-09-17 12:36:07 -04:00
|
|
|
}
|
2010-05-24 18:44:42 -04:00
|
|
|
data->req.bytecount += bv.bv_len + 5;
|
|
|
|
|
2018-03-06 17:02:16 -05:00
|
|
|
for(rc = ldap_get_attribute_ber(li->ld, ent, ber, &bv, &bvals);
|
2018-03-18 14:13:27 -04:00
|
|
|
rc == LDAP_SUCCESS;
|
2018-03-06 17:02:16 -05:00
|
|
|
rc = ldap_get_attribute_ber(li->ld, ent, ber, &bv, &bvals)) {
|
2010-05-24 18:44:42 -04:00
|
|
|
int i;
|
|
|
|
|
2018-03-07 08:43:12 -05:00
|
|
|
if(bv.bv_val == NULL)
|
|
|
|
break;
|
2010-05-24 18:44:42 -04:00
|
|
|
|
2011-04-20 09:17:42 -04:00
|
|
|
if(bv.bv_len > 7 && !strncmp(bv.bv_val + bv.bv_len - 7, ";binary", 7))
|
2010-05-24 18:44:42 -04:00
|
|
|
binary = 1;
|
2010-11-05 10:53:41 -04:00
|
|
|
else
|
|
|
|
binary = 0;
|
2010-05-24 18:44:42 -04:00
|
|
|
|
2018-03-18 14:13:27 -04:00
|
|
|
if(bvals == NULL) {
|
2021-01-08 11:58:15 -05:00
|
|
|
writeerr = Curl_client_write(data, CLIENTWRITE_BODY, (char *)"\t", 1);
|
2018-03-18 14:13:27 -04:00
|
|
|
if(writeerr) {
|
|
|
|
*err = writeerr;
|
|
|
|
return -1;
|
|
|
|
}
|
2021-01-08 11:58:15 -05:00
|
|
|
writeerr = Curl_client_write(data, CLIENTWRITE_BODY, (char *)bv.bv_val,
|
2018-03-18 14:13:27 -04:00
|
|
|
bv.bv_len);
|
|
|
|
if(writeerr) {
|
|
|
|
*err = writeerr;
|
|
|
|
return -1;
|
|
|
|
}
|
2021-01-08 11:58:15 -05:00
|
|
|
writeerr = Curl_client_write(data, CLIENTWRITE_BODY, (char *)":\n", 2);
|
2018-03-18 14:13:27 -04:00
|
|
|
if(writeerr) {
|
|
|
|
*err = writeerr;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
data->req.bytecount += bv.bv_len + 3;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-09-09 17:09:06 -04:00
|
|
|
for(i = 0; bvals[i].bv_val != NULL; i++) {
|
2010-05-24 18:44:42 -04:00
|
|
|
int binval = 0;
|
2021-01-08 11:58:15 -05:00
|
|
|
writeerr = Curl_client_write(data, CLIENTWRITE_BODY, (char *)"\t", 1);
|
2015-09-17 12:36:07 -04:00
|
|
|
if(writeerr) {
|
|
|
|
*err = writeerr;
|
2014-12-08 09:30:14 -05:00
|
|
|
return -1;
|
2015-09-17 12:36:07 -04:00
|
|
|
}
|
2014-12-08 09:30:14 -05:00
|
|
|
|
2021-01-08 11:58:15 -05:00
|
|
|
writeerr = Curl_client_write(data, CLIENTWRITE_BODY, (char *)bv.bv_val,
|
2018-03-07 08:43:12 -05:00
|
|
|
bv.bv_len);
|
|
|
|
if(writeerr) {
|
|
|
|
*err = writeerr;
|
|
|
|
return -1;
|
|
|
|
}
|
2015-09-17 12:36:07 -04:00
|
|
|
|
2021-01-08 11:58:15 -05:00
|
|
|
writeerr = Curl_client_write(data, CLIENTWRITE_BODY, (char *)":", 1);
|
2018-03-07 08:43:12 -05:00
|
|
|
if(writeerr) {
|
|
|
|
*err = writeerr;
|
|
|
|
return -1;
|
|
|
|
}
|
2010-05-24 18:44:42 -04:00
|
|
|
data->req.bytecount += bv.bv_len + 2;
|
|
|
|
|
2011-04-20 09:17:42 -04:00
|
|
|
if(!binary) {
|
2010-05-24 18:44:42 -04:00
|
|
|
/* check for leading or trailing whitespace */
|
2011-04-20 09:17:42 -04:00
|
|
|
if(ISSPACE(bvals[i].bv_val[0]) ||
|
2018-03-07 08:43:12 -05:00
|
|
|
ISSPACE(bvals[i].bv_val[bvals[i].bv_len-1]))
|
2010-05-24 18:44:42 -04:00
|
|
|
binval = 1;
|
2011-04-20 09:17:42 -04:00
|
|
|
else {
|
2010-05-24 18:44:42 -04:00
|
|
|
/* check for unprintable characters */
|
|
|
|
unsigned int j;
|
2017-09-09 17:09:06 -04:00
|
|
|
for(j = 0; j<bvals[i].bv_len; j++)
|
2011-04-20 09:17:42 -04:00
|
|
|
if(!ISPRINT(bvals[i].bv_val[j])) {
|
2010-05-24 18:44:42 -04:00
|
|
|
binval = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-04-20 09:17:42 -04:00
|
|
|
if(binary || binval) {
|
2011-08-24 02:07:36 -04:00
|
|
|
char *val_b64 = NULL;
|
|
|
|
size_t val_b64_sz = 0;
|
2010-05-24 18:44:42 -04:00
|
|
|
/* Binary value, encode to base64. */
|
2011-08-24 02:07:36 -04:00
|
|
|
CURLcode error = Curl_base64_encode(data,
|
|
|
|
bvals[i].bv_val,
|
|
|
|
bvals[i].bv_len,
|
|
|
|
&val_b64,
|
|
|
|
&val_b64_sz);
|
|
|
|
if(error) {
|
|
|
|
ber_memfree(bvals);
|
|
|
|
ber_free(ber, 0);
|
2014-12-27 16:07:53 -05:00
|
|
|
ldap_msgfree(msg);
|
2011-08-24 02:07:36 -04:00
|
|
|
*err = error;
|
|
|
|
return -1;
|
|
|
|
}
|
2021-01-08 11:58:15 -05:00
|
|
|
writeerr = Curl_client_write(data, CLIENTWRITE_BODY,
|
2015-09-17 12:36:07 -04:00
|
|
|
(char *)": ", 2);
|
|
|
|
if(writeerr) {
|
|
|
|
*err = writeerr;
|
2014-12-08 09:30:14 -05:00
|
|
|
return -1;
|
2015-09-17 12:36:07 -04:00
|
|
|
}
|
2014-12-08 09:30:14 -05:00
|
|
|
|
2010-05-24 18:44:42 -04:00
|
|
|
data->req.bytecount += 2;
|
|
|
|
if(val_b64_sz > 0) {
|
2021-01-08 11:58:15 -05:00
|
|
|
writeerr = Curl_client_write(data, CLIENTWRITE_BODY, val_b64,
|
2018-03-07 08:43:12 -05:00
|
|
|
val_b64_sz);
|
2015-09-17 12:36:07 -04:00
|
|
|
if(writeerr) {
|
|
|
|
*err = writeerr;
|
2014-12-08 09:30:14 -05:00
|
|
|
return -1;
|
2015-09-17 12:36:07 -04:00
|
|
|
}
|
2010-05-24 18:44:42 -04:00
|
|
|
free(val_b64);
|
|
|
|
data->req.bytecount += val_b64_sz;
|
|
|
|
}
|
2011-04-20 09:17:42 -04:00
|
|
|
}
|
|
|
|
else {
|
2021-01-08 11:58:15 -05:00
|
|
|
writeerr = Curl_client_write(data, CLIENTWRITE_BODY, (char *)" ", 1);
|
2015-09-17 12:36:07 -04:00
|
|
|
if(writeerr) {
|
|
|
|
*err = writeerr;
|
2014-12-08 09:30:14 -05:00
|
|
|
return -1;
|
2015-09-17 12:36:07 -04:00
|
|
|
}
|
2014-12-08 09:30:14 -05:00
|
|
|
|
2021-01-08 11:58:15 -05:00
|
|
|
writeerr = Curl_client_write(data, CLIENTWRITE_BODY, bvals[i].bv_val,
|
2015-09-17 12:36:07 -04:00
|
|
|
bvals[i].bv_len);
|
|
|
|
if(writeerr) {
|
|
|
|
*err = writeerr;
|
2014-12-08 09:30:14 -05:00
|
|
|
return -1;
|
2015-09-17 12:36:07 -04:00
|
|
|
}
|
2014-12-08 09:30:14 -05:00
|
|
|
|
2010-05-24 18:44:42 -04:00
|
|
|
data->req.bytecount += bvals[i].bv_len + 1;
|
|
|
|
}
|
2021-01-08 11:58:15 -05:00
|
|
|
writeerr = Curl_client_write(data, CLIENTWRITE_BODY, (char *)"\n", 0);
|
2015-09-17 12:36:07 -04:00
|
|
|
if(writeerr) {
|
|
|
|
*err = writeerr;
|
2014-12-08 09:30:14 -05:00
|
|
|
return -1;
|
2015-09-17 12:36:07 -04:00
|
|
|
}
|
2014-12-08 09:30:14 -05:00
|
|
|
|
2010-05-24 18:44:42 -04:00
|
|
|
data->req.bytecount++;
|
|
|
|
}
|
|
|
|
ber_memfree(bvals);
|
2021-01-08 11:58:15 -05:00
|
|
|
writeerr = Curl_client_write(data, CLIENTWRITE_BODY, (char *)"\n", 0);
|
2015-09-17 12:36:07 -04:00
|
|
|
if(writeerr) {
|
|
|
|
*err = writeerr;
|
2014-12-08 09:30:14 -05:00
|
|
|
return -1;
|
2015-09-17 12:36:07 -04:00
|
|
|
}
|
2010-05-24 18:44:42 -04:00
|
|
|
data->req.bytecount++;
|
|
|
|
}
|
2021-01-08 11:58:15 -05:00
|
|
|
writeerr = Curl_client_write(data, CLIENTWRITE_BODY, (char *)"\n", 0);
|
2015-09-17 12:36:07 -04:00
|
|
|
if(writeerr) {
|
|
|
|
*err = writeerr;
|
2014-12-08 09:30:14 -05:00
|
|
|
return -1;
|
2015-09-17 12:36:07 -04:00
|
|
|
}
|
2010-05-24 18:44:42 -04:00
|
|
|
data->req.bytecount++;
|
|
|
|
ber_free(ber, 0);
|
|
|
|
}
|
2014-12-27 16:07:53 -05:00
|
|
|
ldap_msgfree(msg);
|
2010-05-24 18:44:42 -04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-05-28 06:22:35 -04:00
|
|
|
#ifdef USE_SSL
|
2010-05-24 18:44:42 -04:00
|
|
|
static int
|
|
|
|
ldapsb_tls_setup(Sockbuf_IO_Desc *sbiod, void *arg)
|
|
|
|
{
|
|
|
|
sbiod->sbiod_pvt = arg;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ldapsb_tls_remove(Sockbuf_IO_Desc *sbiod)
|
|
|
|
{
|
|
|
|
sbiod->sbiod_pvt = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We don't need to do anything because libcurl does it already */
|
|
|
|
static int
|
|
|
|
ldapsb_tls_close(Sockbuf_IO_Desc *sbiod)
|
|
|
|
{
|
|
|
|
(void)sbiod;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ldapsb_tls_ctrl(Sockbuf_IO_Desc *sbiod, int opt, void *arg)
|
|
|
|
{
|
|
|
|
(void)arg;
|
2011-04-20 09:17:42 -04:00
|
|
|
if(opt == LBER_SB_OPT_DATA_READY) {
|
2010-05-24 18:44:42 -04:00
|
|
|
struct connectdata *conn = sbiod->sbiod_pvt;
|
|
|
|
return Curl_ssl_data_pending(conn, FIRSTSOCKET);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ber_slen_t
|
|
|
|
ldapsb_tls_read(Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len)
|
|
|
|
{
|
|
|
|
struct connectdata *conn = sbiod->sbiod_pvt;
|
2019-09-03 07:31:44 -04:00
|
|
|
struct ldapconninfo *li = conn->proto.ldapc;
|
2010-05-24 18:44:42 -04:00
|
|
|
ber_slen_t ret;
|
|
|
|
CURLcode err = CURLE_RECV_ERROR;
|
|
|
|
|
2021-01-08 11:58:15 -05:00
|
|
|
ret = (li->recv)(conn->data, FIRSTSOCKET, buf, len, &err);
|
2011-04-20 09:17:42 -04:00
|
|
|
if(ret < 0 && err == CURLE_AGAIN) {
|
2010-05-24 18:44:42 -04:00
|
|
|
SET_SOCKERRNO(EWOULDBLOCK);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ber_slen_t
|
|
|
|
ldapsb_tls_write(Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len)
|
|
|
|
{
|
|
|
|
struct connectdata *conn = sbiod->sbiod_pvt;
|
2019-09-03 07:31:44 -04:00
|
|
|
struct ldapconninfo *li = conn->proto.ldapc;
|
2010-05-24 18:44:42 -04:00
|
|
|
ber_slen_t ret;
|
|
|
|
CURLcode err = CURLE_SEND_ERROR;
|
|
|
|
|
2021-01-08 11:58:15 -05:00
|
|
|
ret = (li->send)(conn->data, FIRSTSOCKET, buf, len, &err);
|
2011-04-20 09:17:42 -04:00
|
|
|
if(ret < 0 && err == CURLE_AGAIN) {
|
2010-05-24 18:44:42 -04:00
|
|
|
SET_SOCKERRNO(EWOULDBLOCK);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Sockbuf_IO ldapsb_tls =
|
|
|
|
{
|
|
|
|
ldapsb_tls_setup,
|
|
|
|
ldapsb_tls_remove,
|
|
|
|
ldapsb_tls_ctrl,
|
|
|
|
ldapsb_tls_read,
|
|
|
|
ldapsb_tls_write,
|
|
|
|
ldapsb_tls_close
|
|
|
|
};
|
2010-05-28 06:22:35 -04:00
|
|
|
#endif /* USE_SSL */
|
2010-05-24 18:44:42 -04:00
|
|
|
|
2010-06-01 11:25:03 -04:00
|
|
|
#endif /* !CURL_DISABLE_LDAP && USE_OPENLDAP */
|