openldap.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225
  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"
  26. #if !defined(CURL_DISABLE_LDAP) && defined(USE_OPENLDAP)
  27. /*
  28. * Notice that USE_OPENLDAP is only a source code selection switch. When
  29. * libcurl is built with USE_OPENLDAP defined the libcurl source code that
  30. * gets compiled is the code from openldap.c, otherwise the code that gets
  31. * compiled is the code from ldap.c.
  32. *
  33. * When USE_OPENLDAP is defined a recent version of the OpenLDAP library
  34. * might be required for compilation and runtime. In order to use ancient
  35. * OpenLDAP library versions, USE_OPENLDAP shall not be defined.
  36. */
  37. #include <ldap.h>
  38. #include "urldata.h"
  39. #include <curl/curl.h>
  40. #include "sendf.h"
  41. #include "vtls/vtls.h"
  42. #include "transfer.h"
  43. #include "curl_ldap.h"
  44. #include "curl_base64.h"
  45. #include "cfilters.h"
  46. #include "connect.h"
  47. #include "curl_sasl.h"
  48. #include "strcase.h"
  49. /* The last 3 #include files should be in this order */
  50. #include "curl_printf.h"
  51. #include "curl_memory.h"
  52. #include "memdebug.h"
  53. /*
  54. * Uncommenting this will enable the built-in debug logging of the openldap
  55. * library. The debug log level can be set using the CURL_OPENLDAP_TRACE
  56. * environment variable. The debug output is written to stderr.
  57. *
  58. * The library supports the following debug flags:
  59. * LDAP_DEBUG_NONE 0x0000
  60. * LDAP_DEBUG_TRACE 0x0001
  61. * LDAP_DEBUG_CONSTRUCT 0x0002
  62. * LDAP_DEBUG_DESTROY 0x0004
  63. * LDAP_DEBUG_PARAMETER 0x0008
  64. * LDAP_DEBUG_ANY 0xffff
  65. *
  66. * For example, use CURL_OPENLDAP_TRACE=0 for no debug,
  67. * CURL_OPENLDAP_TRACE=2 for LDAP_DEBUG_CONSTRUCT messages only,
  68. * CURL_OPENLDAP_TRACE=65535 for all debug message levels.
  69. */
  70. /* #define CURL_OPENLDAP_DEBUG */
  71. /* Machine states. */
  72. typedef enum {
  73. OLDAP_STOP, /* Do nothing state, stops the state machine */
  74. OLDAP_SSL, /* Performing SSL handshake. */
  75. OLDAP_STARTTLS, /* STARTTLS request sent. */
  76. OLDAP_TLS, /* Performing TLS handshake. */
  77. OLDAP_MECHS, /* Get SASL authentication mechanisms. */
  78. OLDAP_SASL, /* SASL binding reply. */
  79. OLDAP_BIND, /* Simple bind reply. */
  80. OLDAP_BINDV2, /* Simple bind reply in protocol version 2. */
  81. OLDAP_LAST /* Never used */
  82. } ldapstate;
  83. #ifndef _LDAP_PVT_H
  84. extern int ldap_pvt_url_scheme2proto(const char *);
  85. extern int ldap_init_fd(ber_socket_t fd, int proto, const char *url,
  86. LDAP **ld);
  87. #endif
  88. static CURLcode oldap_setup_connection(struct Curl_easy *data,
  89. struct connectdata *conn);
  90. static CURLcode oldap_do(struct Curl_easy *data, bool *done);
  91. static CURLcode oldap_done(struct Curl_easy *data, CURLcode, bool);
  92. static CURLcode oldap_connect(struct Curl_easy *data, bool *done);
  93. static CURLcode oldap_connecting(struct Curl_easy *data, bool *done);
  94. static CURLcode oldap_disconnect(struct Curl_easy *data,
  95. struct connectdata *conn, bool dead);
  96. static CURLcode oldap_perform_auth(struct Curl_easy *data, const char *mech,
  97. const struct bufref *initresp);
  98. static CURLcode oldap_continue_auth(struct Curl_easy *data, const char *mech,
  99. const struct bufref *resp);
  100. static CURLcode oldap_cancel_auth(struct Curl_easy *data, const char *mech);
  101. static CURLcode oldap_get_message(struct Curl_easy *data, struct bufref *out);
  102. static Curl_recv oldap_recv;
  103. /*
  104. * LDAP protocol handler.
  105. */
  106. const struct Curl_handler Curl_handler_ldap = {
  107. "ldap", /* scheme */
  108. oldap_setup_connection, /* setup_connection */
  109. oldap_do, /* do_it */
  110. oldap_done, /* done */
  111. ZERO_NULL, /* do_more */
  112. oldap_connect, /* connect_it */
  113. oldap_connecting, /* connecting */
  114. ZERO_NULL, /* doing */
  115. ZERO_NULL, /* proto_getsock */
  116. ZERO_NULL, /* doing_getsock */
  117. ZERO_NULL, /* domore_getsock */
  118. ZERO_NULL, /* perform_getsock */
  119. oldap_disconnect, /* disconnect */
  120. ZERO_NULL, /* write_resp */
  121. ZERO_NULL, /* write_resp_hd */
  122. ZERO_NULL, /* connection_check */
  123. ZERO_NULL, /* attach connection */
  124. PORT_LDAP, /* defport */
  125. CURLPROTO_LDAP, /* protocol */
  126. CURLPROTO_LDAP, /* family */
  127. PROTOPT_NONE /* flags */
  128. };
  129. #ifdef USE_SSL
  130. /*
  131. * LDAPS protocol handler.
  132. */
  133. const struct Curl_handler Curl_handler_ldaps = {
  134. "ldaps", /* scheme */
  135. oldap_setup_connection, /* setup_connection */
  136. oldap_do, /* do_it */
  137. oldap_done, /* done */
  138. ZERO_NULL, /* do_more */
  139. oldap_connect, /* connect_it */
  140. oldap_connecting, /* connecting */
  141. ZERO_NULL, /* doing */
  142. ZERO_NULL, /* proto_getsock */
  143. ZERO_NULL, /* doing_getsock */
  144. ZERO_NULL, /* domore_getsock */
  145. ZERO_NULL, /* perform_getsock */
  146. oldap_disconnect, /* disconnect */
  147. ZERO_NULL, /* write_resp */
  148. ZERO_NULL, /* write_resp_hd */
  149. ZERO_NULL, /* connection_check */
  150. ZERO_NULL, /* attach connection */
  151. PORT_LDAPS, /* defport */
  152. CURLPROTO_LDAPS, /* protocol */
  153. CURLPROTO_LDAP, /* family */
  154. PROTOPT_SSL /* flags */
  155. };
  156. #endif
  157. /* SASL parameters for the ldap protocol */
  158. static const struct SASLproto saslldap = {
  159. "ldap", /* The service name */
  160. oldap_perform_auth, /* Send authentication command */
  161. oldap_continue_auth, /* Send authentication continuation */
  162. oldap_cancel_auth, /* Send authentication cancellation */
  163. oldap_get_message, /* Get SASL response message */
  164. 0, /* Maximum initial response length (no max) */
  165. LDAP_SASL_BIND_IN_PROGRESS, /* Code received when continuation is expected */
  166. LDAP_SUCCESS, /* Code to receive upon authentication success */
  167. SASL_AUTH_NONE, /* Default mechanisms */
  168. 0 /* Configuration flags */
  169. };
  170. struct ldapconninfo {
  171. struct SASL sasl; /* SASL-related parameters */
  172. LDAP *ld; /* Openldap connection handle. */
  173. Curl_recv *recv; /* For stacking SSL handler */
  174. Curl_send *send;
  175. struct berval *servercred; /* SASL data from server. */
  176. ldapstate state; /* Current machine state. */
  177. int proto; /* LDAP_PROTO_TCP/LDAP_PROTO_UDP/LDAP_PROTO_IPC */
  178. int msgid; /* Current message id. */
  179. };
  180. struct ldapreqinfo {
  181. int msgid;
  182. int nument;
  183. };
  184. /*
  185. * oldap_state()
  186. *
  187. * This is the ONLY way to change LDAP state!
  188. */
  189. static void oldap_state(struct Curl_easy *data, ldapstate newstate)
  190. {
  191. struct ldapconninfo *ldapc = data->conn->proto.ldapc;
  192. #if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS)
  193. /* for debug purposes */
  194. static const char * const names[] = {
  195. "STOP",
  196. "SSL",
  197. "STARTTLS",
  198. "TLS",
  199. "MECHS",
  200. "SASL",
  201. "BIND",
  202. "BINDV2",
  203. /* LAST */
  204. };
  205. if(ldapc->state != newstate)
  206. infof(data, "LDAP %p state change from %s to %s",
  207. (void *)ldapc, names[ldapc->state], names[newstate]);
  208. #endif
  209. ldapc->state = newstate;
  210. }
  211. /* Map some particular LDAP error codes to CURLcode values. */
  212. static CURLcode oldap_map_error(int rc, CURLcode result)
  213. {
  214. switch(rc) {
  215. case LDAP_NO_MEMORY:
  216. result = CURLE_OUT_OF_MEMORY;
  217. break;
  218. case LDAP_INVALID_CREDENTIALS:
  219. result = CURLE_LOGIN_DENIED;
  220. break;
  221. case LDAP_PROTOCOL_ERROR:
  222. result = CURLE_UNSUPPORTED_PROTOCOL;
  223. break;
  224. case LDAP_INSUFFICIENT_ACCESS:
  225. result = CURLE_REMOTE_ACCESS_DENIED;
  226. break;
  227. }
  228. return result;
  229. }
  230. static CURLcode oldap_url_parse(struct Curl_easy *data, LDAPURLDesc **ludp)
  231. {
  232. CURLcode result = CURLE_OK;
  233. int rc = LDAP_URL_ERR_BADURL;
  234. static const char * const url_errs[] = {
  235. "success",
  236. "out of memory",
  237. "bad parameter",
  238. "unrecognized scheme",
  239. "unbalanced delimiter",
  240. "bad URL",
  241. "bad host or port",
  242. "bad or missing attributes",
  243. "bad or missing scope",
  244. "bad or missing filter",
  245. "bad or missing extensions"
  246. };
  247. *ludp = NULL;
  248. if(!data->state.up.user && !data->state.up.password &&
  249. !data->state.up.options)
  250. rc = ldap_url_parse(data->state.url, ludp);
  251. if(rc != LDAP_URL_SUCCESS) {
  252. const char *msg = "url parsing problem";
  253. result = rc == LDAP_URL_ERR_MEM ? CURLE_OUT_OF_MEMORY :
  254. CURLE_URL_MALFORMAT;
  255. rc -= LDAP_URL_SUCCESS;
  256. if((size_t) rc < sizeof(url_errs) / sizeof(url_errs[0]))
  257. msg = url_errs[rc];
  258. failf(data, "LDAP local: %s", msg);
  259. }
  260. return result;
  261. }
  262. /* Parse the login options. */
  263. static CURLcode oldap_parse_login_options(struct connectdata *conn)
  264. {
  265. CURLcode result = CURLE_OK;
  266. struct ldapconninfo *li = conn->proto.ldapc;
  267. const char *ptr = conn->options;
  268. while(!result && ptr && *ptr) {
  269. const char *key = ptr;
  270. const char *value;
  271. while(*ptr && *ptr != '=')
  272. ptr++;
  273. value = ptr + 1;
  274. while(*ptr && *ptr != ';')
  275. ptr++;
  276. if(checkprefix("AUTH=", key))
  277. result = Curl_sasl_parse_url_auth_option(&li->sasl, value, ptr - value);
  278. else
  279. result = CURLE_SETOPT_OPTION_SYNTAX;
  280. if(*ptr == ';')
  281. ptr++;
  282. }
  283. return result == CURLE_URL_MALFORMAT ? CURLE_SETOPT_OPTION_SYNTAX : result;
  284. }
  285. static CURLcode oldap_setup_connection(struct Curl_easy *data,
  286. struct connectdata *conn)
  287. {
  288. CURLcode result;
  289. LDAPURLDesc *lud;
  290. (void)conn;
  291. /* Early URL syntax check. */
  292. result = oldap_url_parse(data, &lud);
  293. ldap_free_urldesc(lud);
  294. return result;
  295. }
  296. /*
  297. * Get the SASL authentication challenge from the server credential buffer.
  298. */
  299. static CURLcode oldap_get_message(struct Curl_easy *data, struct bufref *out)
  300. {
  301. struct berval *servercred = data->conn->proto.ldapc->servercred;
  302. if(!servercred || !servercred->bv_val)
  303. return CURLE_WEIRD_SERVER_REPLY;
  304. Curl_bufref_set(out, servercred->bv_val, servercred->bv_len, NULL);
  305. return CURLE_OK;
  306. }
  307. /*
  308. * Sends an initial SASL bind request to the server.
  309. */
  310. static CURLcode oldap_perform_auth(struct Curl_easy *data, const char *mech,
  311. const struct bufref *initresp)
  312. {
  313. struct connectdata *conn = data->conn;
  314. struct ldapconninfo *li = conn->proto.ldapc;
  315. CURLcode result = CURLE_OK;
  316. struct berval cred;
  317. struct berval *pcred = &cred;
  318. int rc;
  319. cred.bv_val = (char *) Curl_bufref_ptr(initresp);
  320. cred.bv_len = Curl_bufref_len(initresp);
  321. if(!cred.bv_val)
  322. pcred = NULL;
  323. rc = ldap_sasl_bind(li->ld, NULL, mech, pcred, NULL, NULL, &li->msgid);
  324. if(rc != LDAP_SUCCESS)
  325. result = oldap_map_error(rc, CURLE_LDAP_CANNOT_BIND);
  326. return result;
  327. }
  328. /*
  329. * Sends SASL continuation.
  330. */
  331. static CURLcode oldap_continue_auth(struct Curl_easy *data, const char *mech,
  332. const struct bufref *resp)
  333. {
  334. struct connectdata *conn = data->conn;
  335. struct ldapconninfo *li = conn->proto.ldapc;
  336. CURLcode result = CURLE_OK;
  337. struct berval cred;
  338. struct berval *pcred = &cred;
  339. int rc;
  340. cred.bv_val = (char *) Curl_bufref_ptr(resp);
  341. cred.bv_len = Curl_bufref_len(resp);
  342. if(!cred.bv_val)
  343. pcred = NULL;
  344. rc = ldap_sasl_bind(li->ld, NULL, mech, pcred, NULL, NULL, &li->msgid);
  345. if(rc != LDAP_SUCCESS)
  346. result = oldap_map_error(rc, CURLE_LDAP_CANNOT_BIND);
  347. return result;
  348. }
  349. /*
  350. * Sends SASL bind cancellation.
  351. */
  352. static CURLcode oldap_cancel_auth(struct Curl_easy *data, const char *mech)
  353. {
  354. struct ldapconninfo *li = data->conn->proto.ldapc;
  355. CURLcode result = CURLE_OK;
  356. int rc = ldap_sasl_bind(li->ld, NULL, LDAP_SASL_NULL, NULL, NULL, NULL,
  357. &li->msgid);
  358. (void)mech;
  359. if(rc != LDAP_SUCCESS)
  360. result = oldap_map_error(rc, CURLE_LDAP_CANNOT_BIND);
  361. return result;
  362. }
  363. /* Starts LDAP simple bind. */
  364. static CURLcode oldap_perform_bind(struct Curl_easy *data, ldapstate newstate)
  365. {
  366. CURLcode result = CURLE_OK;
  367. struct connectdata *conn = data->conn;
  368. struct ldapconninfo *li = conn->proto.ldapc;
  369. char *binddn = NULL;
  370. struct berval passwd;
  371. int rc;
  372. passwd.bv_val = NULL;
  373. passwd.bv_len = 0;
  374. if(data->state.aptr.user) {
  375. binddn = conn->user;
  376. passwd.bv_val = conn->passwd;
  377. passwd.bv_len = strlen(passwd.bv_val);
  378. }
  379. rc = ldap_sasl_bind(li->ld, binddn, LDAP_SASL_SIMPLE, &passwd,
  380. NULL, NULL, &li->msgid);
  381. if(rc == LDAP_SUCCESS)
  382. oldap_state(data, newstate);
  383. else
  384. result = oldap_map_error(rc,
  385. data->state.aptr.user ?
  386. CURLE_LOGIN_DENIED : CURLE_LDAP_CANNOT_BIND);
  387. return result;
  388. }
  389. /* Query the supported SASL authentication mechanisms. */
  390. static CURLcode oldap_perform_mechs(struct Curl_easy *data)
  391. {
  392. CURLcode result = CURLE_OK;
  393. struct ldapconninfo *li = data->conn->proto.ldapc;
  394. int rc;
  395. static const char * const supportedSASLMechanisms[] = {
  396. "supportedSASLMechanisms",
  397. NULL
  398. };
  399. rc = ldap_search_ext(li->ld, "", LDAP_SCOPE_BASE, "(objectclass=*)",
  400. (char **) supportedSASLMechanisms, 0,
  401. NULL, NULL, NULL, 0, &li->msgid);
  402. if(rc == LDAP_SUCCESS)
  403. oldap_state(data, OLDAP_MECHS);
  404. else
  405. result = oldap_map_error(rc, CURLE_LOGIN_DENIED);
  406. return result;
  407. }
  408. /* Starts SASL bind. */
  409. static CURLcode oldap_perform_sasl(struct Curl_easy *data)
  410. {
  411. saslprogress progress = SASL_IDLE;
  412. struct ldapconninfo *li = data->conn->proto.ldapc;
  413. CURLcode result = Curl_sasl_start(&li->sasl, data, TRUE, &progress);
  414. oldap_state(data, OLDAP_SASL);
  415. if(!result && progress != SASL_INPROGRESS)
  416. result = CURLE_LOGIN_DENIED;
  417. return result;
  418. }
  419. #ifdef USE_SSL
  420. static Sockbuf_IO ldapsb_tls;
  421. static bool ssl_installed(struct connectdata *conn)
  422. {
  423. return conn->proto.ldapc->recv != NULL;
  424. }
  425. static CURLcode oldap_ssl_connect(struct Curl_easy *data, ldapstate newstate)
  426. {
  427. CURLcode result = CURLE_OK;
  428. struct connectdata *conn = data->conn;
  429. struct ldapconninfo *li = conn->proto.ldapc;
  430. bool ssldone = 0;
  431. result = Curl_conn_connect(data, FIRSTSOCKET, FALSE, &ssldone);
  432. if(!result) {
  433. oldap_state(data, newstate);
  434. if(ssldone) {
  435. Sockbuf *sb;
  436. /* Install the libcurl SSL handlers into the sockbuf. */
  437. ldap_get_option(li->ld, LDAP_OPT_SOCKBUF, &sb);
  438. ber_sockbuf_add_io(sb, &ldapsb_tls, LBER_SBIOD_LEVEL_TRANSPORT, data);
  439. li->recv = conn->recv[FIRSTSOCKET];
  440. li->send = conn->send[FIRSTSOCKET];
  441. }
  442. }
  443. return result;
  444. }
  445. /* Send the STARTTLS request */
  446. static CURLcode oldap_perform_starttls(struct Curl_easy *data)
  447. {
  448. CURLcode result = CURLE_OK;
  449. struct ldapconninfo *li = data->conn->proto.ldapc;
  450. int rc = ldap_start_tls(li->ld, NULL, NULL, &li->msgid);
  451. if(rc == LDAP_SUCCESS)
  452. oldap_state(data, OLDAP_STARTTLS);
  453. else
  454. result = oldap_map_error(rc, CURLE_USE_SSL_FAILED);
  455. return result;
  456. }
  457. #endif
  458. static CURLcode oldap_connect(struct Curl_easy *data, bool *done)
  459. {
  460. struct connectdata *conn = data->conn;
  461. struct ldapconninfo *li;
  462. static const int version = LDAP_VERSION3;
  463. int rc;
  464. char *hosturl;
  465. #ifdef CURL_OPENLDAP_DEBUG
  466. static int do_trace = -1;
  467. #endif
  468. (void)done;
  469. DEBUGASSERT(!conn->proto.ldapc);
  470. li = calloc(1, sizeof(struct ldapconninfo));
  471. if(!li)
  472. return CURLE_OUT_OF_MEMORY;
  473. else {
  474. CURLcode result;
  475. li->proto = ldap_pvt_url_scheme2proto(data->state.up.scheme);
  476. conn->proto.ldapc = li;
  477. /* Initialize the SASL storage */
  478. Curl_sasl_init(&li->sasl, data, &saslldap);
  479. /* Clear the TLS upgraded flag */
  480. conn->bits.tls_upgraded = FALSE;
  481. result = oldap_parse_login_options(conn);
  482. if(result)
  483. return result;
  484. }
  485. hosturl = aprintf("%s://%s%s%s:%d",
  486. conn->handler->scheme,
  487. conn->bits.ipv6_ip ? "[" : "",
  488. conn->host.name,
  489. conn->bits.ipv6_ip ? "]" : "",
  490. conn->remote_port);
  491. if(!hosturl)
  492. return CURLE_OUT_OF_MEMORY;
  493. rc = ldap_init_fd(conn->sock[FIRSTSOCKET], li->proto, hosturl, &li->ld);
  494. if(rc) {
  495. failf(data, "LDAP local: Cannot connect to %s, %s",
  496. hosturl, ldap_err2string(rc));
  497. free(hosturl);
  498. return CURLE_COULDNT_CONNECT;
  499. }
  500. free(hosturl);
  501. #ifdef CURL_OPENLDAP_DEBUG
  502. if(do_trace < 0) {
  503. const char *env = getenv("CURL_OPENLDAP_TRACE");
  504. do_trace = (env && strtol(env, NULL, 10) > 0);
  505. }
  506. if(do_trace)
  507. ldap_set_option(li->ld, LDAP_OPT_DEBUG_LEVEL, &do_trace);
  508. #endif
  509. /* Try version 3 first. */
  510. ldap_set_option(li->ld, LDAP_OPT_PROTOCOL_VERSION, &version);
  511. /* Do not chase referrals. */
  512. ldap_set_option(li->ld, LDAP_OPT_REFERRALS, LDAP_OPT_OFF);
  513. #ifdef USE_SSL
  514. if(conn->handler->flags & PROTOPT_SSL)
  515. return oldap_ssl_connect(data, OLDAP_SSL);
  516. if(data->set.use_ssl) {
  517. CURLcode result = oldap_perform_starttls(data);
  518. if(!result || data->set.use_ssl != CURLUSESSL_TRY)
  519. return result;
  520. }
  521. #endif
  522. if(li->sasl.prefmech != SASL_AUTH_NONE)
  523. return oldap_perform_mechs(data);
  524. /* Force bind even if anonymous bind is not needed in protocol version 3
  525. to detect missing version 3 support. */
  526. return oldap_perform_bind(data, OLDAP_BIND);
  527. }
  528. /* Handle the supported SASL mechanisms query response */
  529. static CURLcode oldap_state_mechs_resp(struct Curl_easy *data,
  530. LDAPMessage *msg, int code)
  531. {
  532. struct connectdata *conn = data->conn;
  533. struct ldapconninfo *li = conn->proto.ldapc;
  534. int rc;
  535. BerElement *ber = NULL;
  536. CURLcode result = CURLE_OK;
  537. struct berval bv, *bvals;
  538. switch(ldap_msgtype(msg)) {
  539. case LDAP_RES_SEARCH_ENTRY:
  540. /* Got a list of supported SASL mechanisms. */
  541. if(code != LDAP_SUCCESS && code != LDAP_NO_RESULTS_RETURNED)
  542. return CURLE_LOGIN_DENIED;
  543. rc = ldap_get_dn_ber(li->ld, msg, &ber, &bv);
  544. if(rc < 0)
  545. return oldap_map_error(rc, CURLE_BAD_CONTENT_ENCODING);
  546. for(rc = ldap_get_attribute_ber(li->ld, msg, ber, &bv, &bvals);
  547. rc == LDAP_SUCCESS;
  548. rc = ldap_get_attribute_ber(li->ld, msg, ber, &bv, &bvals)) {
  549. int i;
  550. if(!bv.bv_val)
  551. break;
  552. if(bvals) {
  553. for(i = 0; bvals[i].bv_val; i++) {
  554. size_t llen;
  555. unsigned short mech = Curl_sasl_decode_mech((char *) bvals[i].bv_val,
  556. bvals[i].bv_len, &llen);
  557. if(bvals[i].bv_len == llen)
  558. li->sasl.authmechs |= mech;
  559. }
  560. ber_memfree(bvals);
  561. }
  562. }
  563. ber_free(ber, 0);
  564. break;
  565. case LDAP_RES_SEARCH_RESULT:
  566. switch(code) {
  567. case LDAP_SIZELIMIT_EXCEEDED:
  568. infof(data, "Too many authentication mechanisms\n");
  569. FALLTHROUGH();
  570. case LDAP_SUCCESS:
  571. case LDAP_NO_RESULTS_RETURNED:
  572. if(Curl_sasl_can_authenticate(&li->sasl, data))
  573. result = oldap_perform_sasl(data);
  574. else
  575. result = CURLE_LOGIN_DENIED;
  576. break;
  577. default:
  578. result = oldap_map_error(code, CURLE_LOGIN_DENIED);
  579. break;
  580. }
  581. break;
  582. default:
  583. break;
  584. }
  585. return result;
  586. }
  587. /* Handle a SASL bind response. */
  588. static CURLcode oldap_state_sasl_resp(struct Curl_easy *data,
  589. LDAPMessage *msg, int code)
  590. {
  591. struct connectdata *conn = data->conn;
  592. struct ldapconninfo *li = conn->proto.ldapc;
  593. CURLcode result = CURLE_OK;
  594. saslprogress progress;
  595. int rc;
  596. li->servercred = NULL;
  597. rc = ldap_parse_sasl_bind_result(li->ld, msg, &li->servercred, 0);
  598. if(rc != LDAP_SUCCESS) {
  599. failf(data, "LDAP local: sasl ldap_parse_result %s", ldap_err2string(rc));
  600. result = oldap_map_error(rc, CURLE_LOGIN_DENIED);
  601. }
  602. else {
  603. result = Curl_sasl_continue(&li->sasl, data, code, &progress);
  604. if(!result && progress != SASL_INPROGRESS)
  605. oldap_state(data, OLDAP_STOP);
  606. }
  607. if(li->servercred)
  608. ber_bvfree(li->servercred);
  609. return result;
  610. }
  611. /* Handle a simple bind response. */
  612. static CURLcode oldap_state_bind_resp(struct Curl_easy *data, LDAPMessage *msg,
  613. int code)
  614. {
  615. struct connectdata *conn = data->conn;
  616. struct ldapconninfo *li = conn->proto.ldapc;
  617. CURLcode result = CURLE_OK;
  618. struct berval *bv = NULL;
  619. int rc;
  620. if(code != LDAP_SUCCESS)
  621. return oldap_map_error(code, CURLE_LDAP_CANNOT_BIND);
  622. rc = ldap_parse_sasl_bind_result(li->ld, msg, &bv, 0);
  623. if(rc != LDAP_SUCCESS) {
  624. failf(data, "LDAP local: bind ldap_parse_sasl_bind_result %s",
  625. ldap_err2string(rc));
  626. result = oldap_map_error(rc, CURLE_LDAP_CANNOT_BIND);
  627. }
  628. else
  629. oldap_state(data, OLDAP_STOP);
  630. if(bv)
  631. ber_bvfree(bv);
  632. return result;
  633. }
  634. static CURLcode oldap_connecting(struct Curl_easy *data, bool *done)
  635. {
  636. CURLcode result = CURLE_OK;
  637. struct connectdata *conn = data->conn;
  638. struct ldapconninfo *li = conn->proto.ldapc;
  639. LDAPMessage *msg = NULL;
  640. struct timeval tv = {0, 0};
  641. int code = LDAP_SUCCESS;
  642. int rc;
  643. if(li->state != OLDAP_SSL && li->state != OLDAP_TLS) {
  644. /* Get response to last command. */
  645. rc = ldap_result(li->ld, li->msgid, LDAP_MSG_ONE, &tv, &msg);
  646. switch(rc) {
  647. case 0: /* Timed out. */
  648. return CURLE_OK;
  649. case LDAP_RES_SEARCH_ENTRY:
  650. case LDAP_RES_SEARCH_REFERENCE:
  651. break;
  652. default:
  653. li->msgid = 0; /* Nothing to abandon upon error. */
  654. if(rc < 0) {
  655. failf(data, "LDAP local: connecting ldap_result %s",
  656. ldap_err2string(rc));
  657. return oldap_map_error(rc, CURLE_COULDNT_CONNECT);
  658. }
  659. break;
  660. }
  661. /* Get error code from message. */
  662. rc = ldap_parse_result(li->ld, msg, &code, NULL, NULL, NULL, NULL, 0);
  663. if(rc)
  664. code = rc;
  665. else {
  666. /* store the latest code for later retrieval */
  667. data->info.httpcode = code;
  668. }
  669. /* If protocol version 3 is not supported, fallback to version 2. */
  670. if(code == LDAP_PROTOCOL_ERROR && li->state != OLDAP_BINDV2 &&
  671. #ifdef USE_SSL
  672. (ssl_installed(conn) || data->set.use_ssl <= CURLUSESSL_TRY) &&
  673. #endif
  674. li->sasl.prefmech == SASL_AUTH_NONE) {
  675. static const int version = LDAP_VERSION2;
  676. ldap_set_option(li->ld, LDAP_OPT_PROTOCOL_VERSION, &version);
  677. ldap_msgfree(msg);
  678. return oldap_perform_bind(data, OLDAP_BINDV2);
  679. }
  680. }
  681. /* Handle response message according to current state. */
  682. switch(li->state) {
  683. #ifdef USE_SSL
  684. case OLDAP_SSL:
  685. result = oldap_ssl_connect(data, OLDAP_SSL);
  686. if(!result && ssl_installed(conn)) {
  687. if(li->sasl.prefmech != SASL_AUTH_NONE)
  688. result = oldap_perform_mechs(data);
  689. else
  690. result = oldap_perform_bind(data, OLDAP_BIND);
  691. }
  692. break;
  693. case OLDAP_STARTTLS:
  694. if(code != LDAP_SUCCESS) {
  695. if(data->set.use_ssl != CURLUSESSL_TRY)
  696. result = oldap_map_error(code, CURLE_USE_SSL_FAILED);
  697. else if(li->sasl.prefmech != SASL_AUTH_NONE)
  698. result = oldap_perform_mechs(data);
  699. else
  700. result = oldap_perform_bind(data, OLDAP_BIND);
  701. break;
  702. }
  703. result = Curl_ssl_cfilter_add(data, conn, FIRSTSOCKET);
  704. if(result)
  705. break;
  706. FALLTHROUGH();
  707. case OLDAP_TLS:
  708. result = oldap_ssl_connect(data, OLDAP_TLS);
  709. if(result)
  710. result = oldap_map_error(code, CURLE_USE_SSL_FAILED);
  711. else if(ssl_installed(conn)) {
  712. conn->bits.tls_upgraded = TRUE;
  713. if(li->sasl.prefmech != SASL_AUTH_NONE)
  714. result = oldap_perform_mechs(data);
  715. else if(data->state.aptr.user)
  716. result = oldap_perform_bind(data, OLDAP_BIND);
  717. else {
  718. /* Version 3 supported: no bind required */
  719. oldap_state(data, OLDAP_STOP);
  720. result = CURLE_OK;
  721. }
  722. }
  723. break;
  724. #endif
  725. case OLDAP_MECHS:
  726. result = oldap_state_mechs_resp(data, msg, code);
  727. break;
  728. case OLDAP_SASL:
  729. result = oldap_state_sasl_resp(data, msg, code);
  730. break;
  731. case OLDAP_BIND:
  732. case OLDAP_BINDV2:
  733. result = oldap_state_bind_resp(data, msg, code);
  734. break;
  735. default:
  736. /* internal error */
  737. result = CURLE_COULDNT_CONNECT;
  738. break;
  739. }
  740. ldap_msgfree(msg);
  741. *done = li->state == OLDAP_STOP;
  742. if(*done)
  743. conn->recv[FIRSTSOCKET] = oldap_recv;
  744. if(result && li->msgid) {
  745. ldap_abandon_ext(li->ld, li->msgid, NULL, NULL);
  746. li->msgid = 0;
  747. }
  748. return result;
  749. }
  750. static CURLcode oldap_disconnect(struct Curl_easy *data,
  751. struct connectdata *conn,
  752. bool dead_connection)
  753. {
  754. struct ldapconninfo *li = conn->proto.ldapc;
  755. (void) dead_connection;
  756. #ifndef USE_SSL
  757. (void)data;
  758. #endif
  759. if(li) {
  760. if(li->ld) {
  761. #ifdef USE_SSL
  762. if(ssl_installed(conn)) {
  763. Sockbuf *sb;
  764. ldap_get_option(li->ld, LDAP_OPT_SOCKBUF, &sb);
  765. ber_sockbuf_add_io(sb, &ldapsb_tls, LBER_SBIOD_LEVEL_TRANSPORT, data);
  766. }
  767. #endif
  768. ldap_unbind_ext(li->ld, NULL, NULL);
  769. li->ld = NULL;
  770. }
  771. Curl_sasl_cleanup(conn, li->sasl.authused);
  772. conn->proto.ldapc = NULL;
  773. free(li);
  774. }
  775. return CURLE_OK;
  776. }
  777. static CURLcode oldap_do(struct Curl_easy *data, bool *done)
  778. {
  779. struct connectdata *conn = data->conn;
  780. struct ldapconninfo *li = conn->proto.ldapc;
  781. struct ldapreqinfo *lr;
  782. CURLcode result;
  783. int rc;
  784. LDAPURLDesc *lud;
  785. int msgid;
  786. connkeep(conn, "OpenLDAP do");
  787. infof(data, "LDAP local: %s", data->state.url);
  788. result = oldap_url_parse(data, &lud);
  789. if(!result) {
  790. #ifdef USE_SSL
  791. if(ssl_installed(conn)) {
  792. Sockbuf *sb;
  793. /* re-install the libcurl SSL handlers into the sockbuf. */
  794. ldap_get_option(li->ld, LDAP_OPT_SOCKBUF, &sb);
  795. ber_sockbuf_add_io(sb, &ldapsb_tls, LBER_SBIOD_LEVEL_TRANSPORT, data);
  796. }
  797. #endif
  798. rc = ldap_search_ext(li->ld, lud->lud_dn, lud->lud_scope,
  799. lud->lud_filter, lud->lud_attrs, 0,
  800. NULL, NULL, NULL, 0, &msgid);
  801. ldap_free_urldesc(lud);
  802. if(rc != LDAP_SUCCESS) {
  803. failf(data, "LDAP local: ldap_search_ext %s", ldap_err2string(rc));
  804. result = CURLE_LDAP_SEARCH_FAILED;
  805. }
  806. else {
  807. lr = calloc(1, sizeof(struct ldapreqinfo));
  808. if(!lr) {
  809. ldap_abandon_ext(li->ld, msgid, NULL, NULL);
  810. result = CURLE_OUT_OF_MEMORY;
  811. }
  812. else {
  813. lr->msgid = msgid;
  814. data->req.p.ldap = lr;
  815. Curl_xfer_setup1(data, CURL_XFER_RECV, -1, FALSE);
  816. *done = TRUE;
  817. }
  818. }
  819. }
  820. return result;
  821. }
  822. static CURLcode oldap_done(struct Curl_easy *data, CURLcode res,
  823. bool premature)
  824. {
  825. struct connectdata *conn = data->conn;
  826. struct ldapreqinfo *lr = data->req.p.ldap;
  827. (void)res;
  828. (void)premature;
  829. if(lr) {
  830. /* if there was a search in progress, abandon it */
  831. if(lr->msgid) {
  832. struct ldapconninfo *li = conn->proto.ldapc;
  833. ldap_abandon_ext(li->ld, lr->msgid, NULL, NULL);
  834. lr->msgid = 0;
  835. }
  836. data->req.p.ldap = NULL;
  837. free(lr);
  838. }
  839. return CURLE_OK;
  840. }
  841. static CURLcode client_write(struct Curl_easy *data,
  842. const char *prefix, size_t plen,
  843. const char *value, size_t len,
  844. const char *suffix, size_t slen)
  845. {
  846. CURLcode result = CURLE_OK;
  847. if(prefix) {
  848. /* If we have a zero-length value and the prefix ends with a space
  849. separator, drop the latter. */
  850. if(!len && plen && prefix[plen - 1] == ' ')
  851. plen--;
  852. result = Curl_client_write(data, CLIENTWRITE_BODY, (char *) prefix, plen);
  853. }
  854. if(!result && value) {
  855. result = Curl_client_write(data, CLIENTWRITE_BODY, (char *) value, len);
  856. }
  857. if(!result && suffix) {
  858. result = Curl_client_write(data, CLIENTWRITE_BODY, (char *) suffix, slen);
  859. }
  860. return result;
  861. }
  862. static ssize_t oldap_recv(struct Curl_easy *data, int sockindex, char *buf,
  863. size_t len, CURLcode *err)
  864. {
  865. struct connectdata *conn = data->conn;
  866. struct ldapconninfo *li = conn->proto.ldapc;
  867. struct ldapreqinfo *lr = data->req.p.ldap;
  868. int rc;
  869. LDAPMessage *msg = NULL;
  870. BerElement *ber = NULL;
  871. struct timeval tv = {0, 0};
  872. struct berval bv, *bvals;
  873. int binary = 0;
  874. CURLcode result = CURLE_AGAIN;
  875. int code;
  876. char *info = NULL;
  877. (void)len;
  878. (void)buf;
  879. (void)sockindex;
  880. rc = ldap_result(li->ld, lr->msgid, LDAP_MSG_ONE, &tv, &msg);
  881. if(rc < 0) {
  882. failf(data, "LDAP local: search ldap_result %s", ldap_err2string(rc));
  883. result = CURLE_RECV_ERROR;
  884. }
  885. *err = result;
  886. /* error or timed out */
  887. if(!msg)
  888. return -1;
  889. result = CURLE_OK;
  890. switch(ldap_msgtype(msg)) {
  891. case LDAP_RES_SEARCH_RESULT:
  892. lr->msgid = 0;
  893. rc = ldap_parse_result(li->ld, msg, &code, NULL, &info, NULL, NULL, 0);
  894. if(rc) {
  895. failf(data, "LDAP local: search ldap_parse_result %s",
  896. ldap_err2string(rc));
  897. result = CURLE_LDAP_SEARCH_FAILED;
  898. break;
  899. }
  900. /* store the latest code for later retrieval */
  901. data->info.httpcode = code;
  902. switch(code) {
  903. case LDAP_SIZELIMIT_EXCEEDED:
  904. infof(data, "There are more than %d entries", lr->nument);
  905. FALLTHROUGH();
  906. case LDAP_SUCCESS:
  907. data->req.size = data->req.bytecount;
  908. break;
  909. default:
  910. failf(data, "LDAP remote: search failed %s %s", ldap_err2string(code),
  911. info ? info : "");
  912. result = CURLE_LDAP_SEARCH_FAILED;
  913. break;
  914. }
  915. if(info)
  916. ldap_memfree(info);
  917. break;
  918. case LDAP_RES_SEARCH_ENTRY:
  919. lr->nument++;
  920. rc = ldap_get_dn_ber(li->ld, msg, &ber, &bv);
  921. if(rc < 0) {
  922. result = CURLE_RECV_ERROR;
  923. break;
  924. }
  925. result = client_write(data, STRCONST("DN: "), bv.bv_val, bv.bv_len,
  926. STRCONST("\n"));
  927. if(result)
  928. break;
  929. for(rc = ldap_get_attribute_ber(li->ld, msg, ber, &bv, &bvals);
  930. rc == LDAP_SUCCESS;
  931. rc = ldap_get_attribute_ber(li->ld, msg, ber, &bv, &bvals)) {
  932. int i;
  933. if(!bv.bv_val)
  934. break;
  935. if(!bvals) {
  936. result = client_write(data, STRCONST("\t"), bv.bv_val, bv.bv_len,
  937. STRCONST(":\n"));
  938. if(result)
  939. break;
  940. continue;
  941. }
  942. binary = bv.bv_len > 7 &&
  943. !strncmp(bv.bv_val + bv.bv_len - 7, ";binary", 7);
  944. for(i = 0; bvals[i].bv_val != NULL; i++) {
  945. int binval = 0;
  946. result = client_write(data, STRCONST("\t"), bv.bv_val, bv.bv_len,
  947. STRCONST(":"));
  948. if(result)
  949. break;
  950. if(!binary) {
  951. /* check for leading or trailing whitespace */
  952. if(ISBLANK(bvals[i].bv_val[0]) ||
  953. ISBLANK(bvals[i].bv_val[bvals[i].bv_len - 1]))
  954. binval = 1;
  955. else {
  956. /* check for unprintable characters */
  957. unsigned int j;
  958. for(j = 0; j < bvals[i].bv_len; j++)
  959. if(!ISPRINT(bvals[i].bv_val[j])) {
  960. binval = 1;
  961. break;
  962. }
  963. }
  964. }
  965. if(binary || binval) {
  966. char *val_b64 = NULL;
  967. size_t val_b64_sz = 0;
  968. /* Binary value, encode to base64. */
  969. if(bvals[i].bv_len)
  970. result = Curl_base64_encode(bvals[i].bv_val, bvals[i].bv_len,
  971. &val_b64, &val_b64_sz);
  972. if(!result)
  973. result = client_write(data, STRCONST(": "), val_b64, val_b64_sz,
  974. STRCONST("\n"));
  975. free(val_b64);
  976. }
  977. else
  978. result = client_write(data, STRCONST(" "),
  979. bvals[i].bv_val, bvals[i].bv_len,
  980. STRCONST("\n"));
  981. if(result)
  982. break;
  983. }
  984. ber_memfree(bvals);
  985. bvals = NULL;
  986. if(!result)
  987. result = client_write(data, STRCONST("\n"), NULL, 0, NULL, 0);
  988. if(result)
  989. break;
  990. }
  991. ber_free(ber, 0);
  992. if(!result)
  993. result = client_write(data, STRCONST("\n"), NULL, 0, NULL, 0);
  994. if(!result)
  995. result = CURLE_AGAIN;
  996. break;
  997. }
  998. ldap_msgfree(msg);
  999. *err = result;
  1000. return result ? -1 : 0;
  1001. }
  1002. #ifdef USE_SSL
  1003. static int
  1004. ldapsb_tls_setup(Sockbuf_IO_Desc *sbiod, void *arg)
  1005. {
  1006. sbiod->sbiod_pvt = arg;
  1007. return 0;
  1008. }
  1009. static int
  1010. ldapsb_tls_remove(Sockbuf_IO_Desc *sbiod)
  1011. {
  1012. sbiod->sbiod_pvt = NULL;
  1013. return 0;
  1014. }
  1015. /* We do not need to do anything because libcurl does it already */
  1016. static int
  1017. ldapsb_tls_close(Sockbuf_IO_Desc *sbiod)
  1018. {
  1019. (void)sbiod;
  1020. return 0;
  1021. }
  1022. static int
  1023. ldapsb_tls_ctrl(Sockbuf_IO_Desc *sbiod, int opt, void *arg)
  1024. {
  1025. (void)arg;
  1026. if(opt == LBER_SB_OPT_DATA_READY) {
  1027. struct Curl_easy *data = sbiod->sbiod_pvt;
  1028. return Curl_conn_data_pending(data, FIRSTSOCKET);
  1029. }
  1030. return 0;
  1031. }
  1032. static ber_slen_t
  1033. ldapsb_tls_read(Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len)
  1034. {
  1035. struct Curl_easy *data = sbiod->sbiod_pvt;
  1036. ber_slen_t ret = 0;
  1037. if(data) {
  1038. struct connectdata *conn = data->conn;
  1039. if(conn) {
  1040. struct ldapconninfo *li = conn->proto.ldapc;
  1041. CURLcode err = CURLE_RECV_ERROR;
  1042. ret = (li->recv)(data, FIRSTSOCKET, buf, len, &err);
  1043. if(ret < 0 && err == CURLE_AGAIN) {
  1044. SET_SOCKERRNO(EWOULDBLOCK);
  1045. }
  1046. }
  1047. }
  1048. return ret;
  1049. }
  1050. static ber_slen_t
  1051. ldapsb_tls_write(Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len)
  1052. {
  1053. struct Curl_easy *data = sbiod->sbiod_pvt;
  1054. ber_slen_t ret = 0;
  1055. if(data) {
  1056. struct connectdata *conn = data->conn;
  1057. if(conn) {
  1058. struct ldapconninfo *li = conn->proto.ldapc;
  1059. CURLcode err = CURLE_SEND_ERROR;
  1060. ret = (li->send)(data, FIRSTSOCKET, buf, len, FALSE, &err);
  1061. if(ret < 0 && err == CURLE_AGAIN) {
  1062. SET_SOCKERRNO(EWOULDBLOCK);
  1063. }
  1064. }
  1065. }
  1066. return ret;
  1067. }
  1068. static Sockbuf_IO ldapsb_tls =
  1069. {
  1070. ldapsb_tls_setup,
  1071. ldapsb_tls_remove,
  1072. ldapsb_tls_ctrl,
  1073. ldapsb_tls_read,
  1074. ldapsb_tls_write,
  1075. ldapsb_tls_close
  1076. };
  1077. #endif /* USE_SSL */
  1078. #endif /* !CURL_DISABLE_LDAP && USE_OPENLDAP */