26 #if !defined(CURL_DISABLE_LDAP) && defined(USE_OPENLDAP) 55 extern int ldap_pvt_url_scheme2proto(
const char *);
56 extern int ldap_init_fd(ber_socket_t fd,
int proto,
const char *url,
75 ldap_setup_connection,
101 ldap_setup_connection,
121 static const char *url_errs[] = {
125 "unrecognized scheme",
126 "unbalanced delimiter",
129 "bad or missing attributes",
130 "bad or missing scope",
131 "bad or missing filter",
132 "bad or missing extensions" 135 typedef struct ldapconninfo {
146 typedef struct ldapreqinfo {
160 if(rc != LDAP_URL_SUCCESS) {
161 const char *
msg =
"url parsing problem";
163 if(rc > LDAP_URL_SUCCESS && rc <= LDAP_URL_ERR_BADEXTS) {
164 if(rc == LDAP_URL_ERR_MEM)
168 failf(conn->
data,
"LDAP local: %s", msg);
171 proto = ldap_pvt_url_scheme2proto(lud->lud_scheme);
174 li =
calloc(1,
sizeof(ldapconninfo));
187 static Sockbuf_IO ldapsb_tls;
194 int rc, proto = LDAP_VERSION3;
200 strcpy(hosturl,
"ldap");
204 snprintf(ptr,
sizeof(hosturl)-(ptr-hosturl),
"://%s:%d",
207 rc = ldap_init_fd(conn->
sock[
FIRSTSOCKET], li->proto, hosturl, &li->ld);
209 failf(data,
"LDAP local: Cannot connect to %s, %s",
214 ldap_set_option(li->ld, LDAP_OPT_PROTOCOL_VERSION, &proto);
232 LDAPMessage *msg = NULL;
233 struct timeval tv = {0, 1}, *tvp;
243 if(result || !li->ssldone)
250 ldap_get_option(li->ld, LDAP_OPT_SOCKBUF, &sb);
251 ber_sockbuf_add_io(sb, &ldapsb_tls, LBER_SBIOD_LEVEL_TRANSPORT, conn);
264 struct berval passwd;
268 passwd.bv_val = conn->
passwd;
269 passwd.bv_len = strlen(passwd.bv_val);
273 passwd.bv_val = NULL;
276 rc = ldap_sasl_bind(li->ld, binddn, LDAP_SASL_SIMPLE, &passwd,
277 NULL, NULL, &li->msgid);
285 rc = ldap_result(li->ld, li->msgid, LDAP_MSG_ONE, tvp, &msg);
295 rc = ldap_parse_result(li->ld, msg, &err, NULL, &info, NULL, NULL, 1);
302 if(err == LDAP_PROTOCOL_ERROR) {
304 ldap_get_option(li->ld, LDAP_OPT_PROTOCOL_VERSION, &proto);
305 if(proto == LDAP_VERSION3) {
310 proto = LDAP_VERSION2;
311 ldap_set_option(li->ld, LDAP_OPT_PROTOCOL_VERSION, &proto);
336 (void) dead_connection;
340 ldap_unbind_ext(li->ld, NULL, NULL);
364 if(rc != LDAP_URL_SUCCESS) {
365 const char *msg =
"url parsing problem";
367 if(rc > LDAP_URL_SUCCESS && rc <= LDAP_URL_ERR_BADEXTS) {
368 if(rc == LDAP_URL_ERR_MEM)
372 failf(conn->
data,
"LDAP local: %s", msg);
376 rc = ldap_search_ext(li->ld, ludp->lud_dn, ludp->lud_scope,
377 ludp->lud_filter, ludp->lud_attrs, 0,
378 NULL, NULL, NULL, 0, &msgid);
380 if(rc != LDAP_SUCCESS) {
384 lr =
calloc(1,
sizeof(ldapreqinfo));
406 ldap_abandon_ext(li->ld, lr->msgid, NULL, NULL);
423 LDAPMessage *msg = NULL;
425 BerElement *ber = NULL;
432 rc = ldap_result(li->ld, lr->msgid, LDAP_MSG_RECEIVED, &tv, &msg);
446 for(ent = ldap_first_message(li->ld, msg); ent;
447 ent = ldap_next_message(li->ld, ent)) {
448 struct berval bv, *bvals, **bvp = &bvals;
449 int binary = 0, msgtype;
452 msgtype = ldap_msgtype(ent);
453 if(msgtype == LDAP_RES_SEARCH_RESULT) {
456 rc = ldap_parse_result(li->ld, ent, &code, NULL, &info, NULL, NULL, 0);
458 failf(data,
"LDAP local: search ldap_parse_result %s",
462 else if(code && code != LDAP_SIZELIMIT_EXCEEDED) {
469 if(code == LDAP_SIZELIMIT_EXCEEDED)
470 infof(data,
"There are more than %d entries\n", lr->nument);
479 else if(msgtype != LDAP_RES_SEARCH_ENTRY)
483 rc = ldap_get_dn_ber(li->ld, ent, &ber, &bv);
510 for(rc = ldap_get_attribute_ber(li->ld, ent, ber, &bv, bvp);
512 rc = ldap_get_attribute_ber(li->ld, ent, ber, &bv, bvp)) {
515 if(bv.bv_val == NULL)
break;
517 if(bv.bv_len > 7 && !strncmp(bv.bv_val + bv.bv_len - 7,
";binary", 7))
522 for(i = 0; bvals[
i].bv_val != NULL; i++) {
546 if(
ISSPACE(bvals[i].bv_val[0]) ||
547 ISSPACE(bvals[i].bv_val[bvals[i].bv_len-1]))
552 for(j = 0; j<bvals[
i].bv_len; j++)
553 if(!
ISPRINT(bvals[i].bv_val[j])) {
559 if(binary || binval) {
560 char *val_b64 = NULL;
561 size_t val_b64_sz = 0;
640 ldapsb_tls_setup(Sockbuf_IO_Desc *sbiod,
void *arg)
642 sbiod->sbiod_pvt = arg;
647 ldapsb_tls_remove(Sockbuf_IO_Desc *sbiod)
649 sbiod->sbiod_pvt = NULL;
655 ldapsb_tls_close(Sockbuf_IO_Desc *sbiod)
662 ldapsb_tls_ctrl(Sockbuf_IO_Desc *sbiod,
int opt,
void *arg)
665 if(opt == LBER_SB_OPT_DATA_READY) {
673 ldapsb_tls_read(Sockbuf_IO_Desc *sbiod,
void *buf, ber_len_t len)
688 ldapsb_tls_write(Sockbuf_IO_Desc *sbiod,
void *buf, ber_len_t len)
702 static Sockbuf_IO ldapsb_tls =
ssize_t( Curl_recv)(struct connectdata *conn, int sockindex, char *buf, size_t len, CURLcode *err)
CURLcode Curl_base64_encode(struct Curl_easy *data, const char *inputbuff, size_t insize, char **outptr, size_t *outlen)
const struct Curl_handler * handler
UNITTEST_START char * ptr
#define Curl_ssl_connect_nonblocking(x, y, z)
UNITTEST_START int result
struct DynamicStatic change
#define Curl_ssl_data_pending(x, y)
void Curl_setup_transfer(struct connectdata *conn, int sockindex, curl_off_t size, bool getheader, curl_off_t *bytecountp, int writesockindex, curl_off_t *writecountp)
#define ldap_free_urldesc
ssize_t( Curl_send)(struct connectdata *conn, int sockindex, const void *buf, size_t len, CURLcode *err)
CURLcode Curl_client_write(struct connectdata *conn, int type, char *ptr, size_t len)
union connectdata::@34 proto
const struct Curl_handler Curl_handler_ldap
#define calloc(nbelem, size)