openldap.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224
  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: CURLE_URL_MALFORMAT;
  254. rc -= LDAP_URL_SUCCESS;
  255. if((size_t) rc < sizeof(url_errs) / sizeof(url_errs[0]))
  256. msg = url_errs[rc];
  257. failf(data, "LDAP local: %s", msg);
  258. }
  259. return result;
  260. }
  261. /* Parse the login options. */
  262. static CURLcode oldap_parse_login_options(struct connectdata *conn)
  263. {
  264. CURLcode result = CURLE_OK;
  265. struct ldapconninfo *li = conn->proto.ldapc;
  266. const char *ptr = conn->options;
  267. while(!result && ptr && *ptr) {
  268. const char *key = ptr;
  269. const char *value;
  270. while(*ptr && *ptr != '=')
  271. ptr++;
  272. value = ptr + 1;
  273. while(*ptr && *ptr != ';')
  274. ptr++;
  275. if(checkprefix("AUTH=", key))
  276. result = Curl_sasl_parse_url_auth_option(&li->sasl, value, ptr - value);
  277. else
  278. result = CURLE_SETOPT_OPTION_SYNTAX;
  279. if(*ptr == ';')
  280. ptr++;
  281. }
  282. return result == CURLE_URL_MALFORMAT? CURLE_SETOPT_OPTION_SYNTAX: result;
  283. }
  284. static CURLcode oldap_setup_connection(struct Curl_easy *data,
  285. struct connectdata *conn)
  286. {
  287. CURLcode result;
  288. LDAPURLDesc *lud;
  289. (void)conn;
  290. /* Early URL syntax check. */
  291. result = oldap_url_parse(data, &lud);
  292. ldap_free_urldesc(lud);
  293. return result;
  294. }
  295. /*
  296. * Get the SASL authentication challenge from the server credential buffer.
  297. */
  298. static CURLcode oldap_get_message(struct Curl_easy *data, struct bufref *out)
  299. {
  300. struct berval *servercred = data->conn->proto.ldapc->servercred;
  301. if(!servercred || !servercred->bv_val)
  302. return CURLE_WEIRD_SERVER_REPLY;
  303. Curl_bufref_set(out, servercred->bv_val, servercred->bv_len, NULL);
  304. return CURLE_OK;
  305. }
  306. /*
  307. * Sends an initial SASL bind request to the server.
  308. */
  309. static CURLcode oldap_perform_auth(struct Curl_easy *data, const char *mech,
  310. const struct bufref *initresp)
  311. {
  312. struct connectdata *conn = data->conn;
  313. struct ldapconninfo *li = conn->proto.ldapc;
  314. CURLcode result = CURLE_OK;
  315. struct berval cred;
  316. struct berval *pcred = &cred;
  317. int rc;
  318. cred.bv_val = (char *) Curl_bufref_ptr(initresp);
  319. cred.bv_len = Curl_bufref_len(initresp);
  320. if(!cred.bv_val)
  321. pcred = NULL;
  322. rc = ldap_sasl_bind(li->ld, NULL, mech, pcred, NULL, NULL, &li->msgid);
  323. if(rc != LDAP_SUCCESS)
  324. result = oldap_map_error(rc, CURLE_LDAP_CANNOT_BIND);
  325. return result;
  326. }
  327. /*
  328. * Sends SASL continuation.
  329. */
  330. static CURLcode oldap_continue_auth(struct Curl_easy *data, const char *mech,
  331. const struct bufref *resp)
  332. {
  333. struct connectdata *conn = data->conn;
  334. struct ldapconninfo *li = conn->proto.ldapc;
  335. CURLcode result = CURLE_OK;
  336. struct berval cred;
  337. struct berval *pcred = &cred;
  338. int rc;
  339. cred.bv_val = (char *) Curl_bufref_ptr(resp);
  340. cred.bv_len = Curl_bufref_len(resp);
  341. if(!cred.bv_val)
  342. pcred = NULL;
  343. rc = ldap_sasl_bind(li->ld, NULL, mech, pcred, NULL, NULL, &li->msgid);
  344. if(rc != LDAP_SUCCESS)
  345. result = oldap_map_error(rc, CURLE_LDAP_CANNOT_BIND);
  346. return result;
  347. }
  348. /*
  349. * Sends SASL bind cancellation.
  350. */
  351. static CURLcode oldap_cancel_auth(struct Curl_easy *data, const char *mech)
  352. {
  353. struct ldapconninfo *li = data->conn->proto.ldapc;
  354. CURLcode result = CURLE_OK;
  355. int rc = ldap_sasl_bind(li->ld, NULL, LDAP_SASL_NULL, NULL, NULL, NULL,
  356. &li->msgid);
  357. (void)mech;
  358. if(rc != LDAP_SUCCESS)
  359. result = oldap_map_error(rc, CURLE_LDAP_CANNOT_BIND);
  360. return result;
  361. }
  362. /* Starts LDAP simple bind. */
  363. static CURLcode oldap_perform_bind(struct Curl_easy *data, ldapstate newstate)
  364. {
  365. CURLcode result = CURLE_OK;
  366. struct connectdata *conn = data->conn;
  367. struct ldapconninfo *li = conn->proto.ldapc;
  368. char *binddn = NULL;
  369. struct berval passwd;
  370. int rc;
  371. passwd.bv_val = NULL;
  372. passwd.bv_len = 0;
  373. if(data->state.aptr.user) {
  374. binddn = conn->user;
  375. passwd.bv_val = conn->passwd;
  376. passwd.bv_len = strlen(passwd.bv_val);
  377. }
  378. rc = ldap_sasl_bind(li->ld, binddn, LDAP_SASL_SIMPLE, &passwd,
  379. NULL, NULL, &li->msgid);
  380. if(rc == LDAP_SUCCESS)
  381. oldap_state(data, newstate);
  382. else
  383. result = oldap_map_error(rc,
  384. data->state.aptr.user?
  385. CURLE_LOGIN_DENIED: CURLE_LDAP_CANNOT_BIND);
  386. return result;
  387. }
  388. /* Query the supported SASL authentication mechanisms. */
  389. static CURLcode oldap_perform_mechs(struct Curl_easy *data)
  390. {
  391. CURLcode result = CURLE_OK;
  392. struct ldapconninfo *li = data->conn->proto.ldapc;
  393. int rc;
  394. static const char * const supportedSASLMechanisms[] = {
  395. "supportedSASLMechanisms",
  396. NULL
  397. };
  398. rc = ldap_search_ext(li->ld, "", LDAP_SCOPE_BASE, "(objectclass=*)",
  399. (char **) supportedSASLMechanisms, 0,
  400. NULL, NULL, NULL, 0, &li->msgid);
  401. if(rc == LDAP_SUCCESS)
  402. oldap_state(data, OLDAP_MECHS);
  403. else
  404. result = oldap_map_error(rc, CURLE_LOGIN_DENIED);
  405. return result;
  406. }
  407. /* Starts SASL bind. */
  408. static CURLcode oldap_perform_sasl(struct Curl_easy *data)
  409. {
  410. saslprogress progress = SASL_IDLE;
  411. struct ldapconninfo *li = data->conn->proto.ldapc;
  412. CURLcode result = Curl_sasl_start(&li->sasl, data, TRUE, &progress);
  413. oldap_state(data, OLDAP_SASL);
  414. if(!result && progress != SASL_INPROGRESS)
  415. result = CURLE_LOGIN_DENIED;
  416. return result;
  417. }
  418. #ifdef USE_SSL
  419. static Sockbuf_IO ldapsb_tls;
  420. static bool ssl_installed(struct connectdata *conn)
  421. {
  422. return conn->proto.ldapc->recv != NULL;
  423. }
  424. static CURLcode oldap_ssl_connect(struct Curl_easy *data, ldapstate newstate)
  425. {
  426. CURLcode result = CURLE_OK;
  427. struct connectdata *conn = data->conn;
  428. struct ldapconninfo *li = conn->proto.ldapc;
  429. bool ssldone = 0;
  430. result = Curl_conn_connect(data, FIRSTSOCKET, FALSE, &ssldone);
  431. if(!result) {
  432. oldap_state(data, newstate);
  433. if(ssldone) {
  434. Sockbuf *sb;
  435. /* Install the libcurl SSL handlers into the sockbuf. */
  436. ldap_get_option(li->ld, LDAP_OPT_SOCKBUF, &sb);
  437. ber_sockbuf_add_io(sb, &ldapsb_tls, LBER_SBIOD_LEVEL_TRANSPORT, data);
  438. li->recv = conn->recv[FIRSTSOCKET];
  439. li->send = conn->send[FIRSTSOCKET];
  440. }
  441. }
  442. return result;
  443. }
  444. /* Send the STARTTLS request */
  445. static CURLcode oldap_perform_starttls(struct Curl_easy *data)
  446. {
  447. CURLcode result = CURLE_OK;
  448. struct ldapconninfo *li = data->conn->proto.ldapc;
  449. int rc = ldap_start_tls(li->ld, NULL, NULL, &li->msgid);
  450. if(rc == LDAP_SUCCESS)
  451. oldap_state(data, OLDAP_STARTTLS);
  452. else
  453. result = oldap_map_error(rc, CURLE_USE_SSL_FAILED);
  454. return result;
  455. }
  456. #endif
  457. static CURLcode oldap_connect(struct Curl_easy *data, bool *done)
  458. {
  459. struct connectdata *conn = data->conn;
  460. struct ldapconninfo *li;
  461. static const int version = LDAP_VERSION3;
  462. int rc;
  463. char *hosturl;
  464. #ifdef CURL_OPENLDAP_DEBUG
  465. static int do_trace = -1;
  466. #endif
  467. (void)done;
  468. DEBUGASSERT(!conn->proto.ldapc);
  469. li = calloc(1, sizeof(struct ldapconninfo));
  470. if(!li)
  471. return CURLE_OUT_OF_MEMORY;
  472. else {
  473. CURLcode result;
  474. li->proto = ldap_pvt_url_scheme2proto(data->state.up.scheme);
  475. conn->proto.ldapc = li;
  476. /* Initialize the SASL storage */
  477. Curl_sasl_init(&li->sasl, data, &saslldap);
  478. /* Clear the TLS upgraded flag */
  479. conn->bits.tls_upgraded = FALSE;
  480. result = oldap_parse_login_options(conn);
  481. if(result)
  482. return result;
  483. }
  484. hosturl = aprintf("%s://%s%s%s:%d",
  485. conn->handler->scheme,
  486. conn->bits.ipv6_ip? "[": "",
  487. conn->host.name,
  488. conn->bits.ipv6_ip? "]": "",
  489. conn->remote_port);
  490. if(!hosturl)
  491. return CURLE_OUT_OF_MEMORY;
  492. rc = ldap_init_fd(conn->sock[FIRSTSOCKET], li->proto, hosturl, &li->ld);
  493. if(rc) {
  494. failf(data, "LDAP local: Cannot connect to %s, %s",
  495. hosturl, ldap_err2string(rc));
  496. free(hosturl);
  497. return CURLE_COULDNT_CONNECT;
  498. }
  499. free(hosturl);
  500. #ifdef CURL_OPENLDAP_DEBUG
  501. if(do_trace < 0) {
  502. const char *env = getenv("CURL_OPENLDAP_TRACE");
  503. do_trace = (env && strtol(env, NULL, 10) > 0);
  504. }
  505. if(do_trace)
  506. ldap_set_option(li->ld, LDAP_OPT_DEBUG_LEVEL, &do_trace);
  507. #endif
  508. /* Try version 3 first. */
  509. ldap_set_option(li->ld, LDAP_OPT_PROTOCOL_VERSION, &version);
  510. /* Do not chase referrals. */
  511. ldap_set_option(li->ld, LDAP_OPT_REFERRALS, LDAP_OPT_OFF);
  512. #ifdef USE_SSL
  513. if(conn->handler->flags & PROTOPT_SSL)
  514. return oldap_ssl_connect(data, OLDAP_SSL);
  515. if(data->set.use_ssl) {
  516. CURLcode result = oldap_perform_starttls(data);
  517. if(!result || data->set.use_ssl != CURLUSESSL_TRY)
  518. return result;
  519. }
  520. #endif
  521. if(li->sasl.prefmech != SASL_AUTH_NONE)
  522. return oldap_perform_mechs(data);
  523. /* Force bind even if anonymous bind is not needed in protocol version 3
  524. to detect missing version 3 support. */
  525. return oldap_perform_bind(data, OLDAP_BIND);
  526. }
  527. /* Handle the supported SASL mechanisms query response */
  528. static CURLcode oldap_state_mechs_resp(struct Curl_easy *data,
  529. LDAPMessage *msg, int code)
  530. {
  531. struct connectdata *conn = data->conn;
  532. struct ldapconninfo *li = conn->proto.ldapc;
  533. int rc;
  534. BerElement *ber = NULL;
  535. CURLcode result = CURLE_OK;
  536. struct berval bv, *bvals;
  537. switch(ldap_msgtype(msg)) {
  538. case LDAP_RES_SEARCH_ENTRY:
  539. /* Got a list of supported SASL mechanisms. */
  540. if(code != LDAP_SUCCESS && code != LDAP_NO_RESULTS_RETURNED)
  541. return CURLE_LOGIN_DENIED;
  542. rc = ldap_get_dn_ber(li->ld, msg, &ber, &bv);
  543. if(rc < 0)
  544. return oldap_map_error(rc, CURLE_BAD_CONTENT_ENCODING);
  545. for(rc = ldap_get_attribute_ber(li->ld, msg, ber, &bv, &bvals);
  546. rc == LDAP_SUCCESS;
  547. rc = ldap_get_attribute_ber(li->ld, msg, ber, &bv, &bvals)) {
  548. int i;
  549. if(!bv.bv_val)
  550. break;
  551. if(bvals) {
  552. for(i = 0; bvals[i].bv_val; i++) {
  553. size_t llen;
  554. unsigned short mech = Curl_sasl_decode_mech((char *) bvals[i].bv_val,
  555. bvals[i].bv_len, &llen);
  556. if(bvals[i].bv_len == llen)
  557. li->sasl.authmechs |= mech;
  558. }
  559. ber_memfree(bvals);
  560. }
  561. }
  562. ber_free(ber, 0);
  563. break;
  564. case LDAP_RES_SEARCH_RESULT:
  565. switch(code) {
  566. case LDAP_SIZELIMIT_EXCEEDED:
  567. infof(data, "Too many authentication mechanisms\n");
  568. FALLTHROUGH();
  569. case LDAP_SUCCESS:
  570. case LDAP_NO_RESULTS_RETURNED:
  571. if(Curl_sasl_can_authenticate(&li->sasl, data))
  572. result = oldap_perform_sasl(data);
  573. else
  574. result = CURLE_LOGIN_DENIED;
  575. break;
  576. default:
  577. result = oldap_map_error(code, CURLE_LOGIN_DENIED);
  578. break;
  579. }
  580. break;
  581. default:
  582. break;
  583. }
  584. return result;
  585. }
  586. /* Handle a SASL bind response. */
  587. static CURLcode oldap_state_sasl_resp(struct Curl_easy *data,
  588. LDAPMessage *msg, int code)
  589. {
  590. struct connectdata *conn = data->conn;
  591. struct ldapconninfo *li = conn->proto.ldapc;
  592. CURLcode result = CURLE_OK;
  593. saslprogress progress;
  594. int rc;
  595. li->servercred = NULL;
  596. rc = ldap_parse_sasl_bind_result(li->ld, msg, &li->servercred, 0);
  597. if(rc != LDAP_SUCCESS) {
  598. failf(data, "LDAP local: sasl ldap_parse_result %s", ldap_err2string(rc));
  599. result = oldap_map_error(rc, CURLE_LOGIN_DENIED);
  600. }
  601. else {
  602. result = Curl_sasl_continue(&li->sasl, data, code, &progress);
  603. if(!result && progress != SASL_INPROGRESS)
  604. oldap_state(data, OLDAP_STOP);
  605. }
  606. if(li->servercred)
  607. ber_bvfree(li->servercred);
  608. return result;
  609. }
  610. /* Handle a simple bind response. */
  611. static CURLcode oldap_state_bind_resp(struct Curl_easy *data, LDAPMessage *msg,
  612. int code)
  613. {
  614. struct connectdata *conn = data->conn;
  615. struct ldapconninfo *li = conn->proto.ldapc;
  616. CURLcode result = CURLE_OK;
  617. struct berval *bv = NULL;
  618. int rc;
  619. if(code != LDAP_SUCCESS)
  620. return oldap_map_error(code, CURLE_LDAP_CANNOT_BIND);
  621. rc = ldap_parse_sasl_bind_result(li->ld, msg, &bv, 0);
  622. if(rc != LDAP_SUCCESS) {
  623. failf(data, "LDAP local: bind ldap_parse_sasl_bind_result %s",
  624. ldap_err2string(rc));
  625. result = oldap_map_error(rc, CURLE_LDAP_CANNOT_BIND);
  626. }
  627. else
  628. oldap_state(data, OLDAP_STOP);
  629. if(bv)
  630. ber_bvfree(bv);
  631. return result;
  632. }
  633. static CURLcode oldap_connecting(struct Curl_easy *data, bool *done)
  634. {
  635. CURLcode result = CURLE_OK;
  636. struct connectdata *conn = data->conn;
  637. struct ldapconninfo *li = conn->proto.ldapc;
  638. LDAPMessage *msg = NULL;
  639. struct timeval tv = {0, 0};
  640. int code = LDAP_SUCCESS;
  641. int rc;
  642. if(li->state != OLDAP_SSL && li->state != OLDAP_TLS) {
  643. /* Get response to last command. */
  644. rc = ldap_result(li->ld, li->msgid, LDAP_MSG_ONE, &tv, &msg);
  645. switch(rc) {
  646. case 0: /* Timed out. */
  647. return CURLE_OK;
  648. case LDAP_RES_SEARCH_ENTRY:
  649. case LDAP_RES_SEARCH_REFERENCE:
  650. break;
  651. default:
  652. li->msgid = 0; /* Nothing to abandon upon error. */
  653. if(rc < 0) {
  654. failf(data, "LDAP local: connecting ldap_result %s",
  655. ldap_err2string(rc));
  656. return oldap_map_error(rc, CURLE_COULDNT_CONNECT);
  657. }
  658. break;
  659. }
  660. /* Get error code from message. */
  661. rc = ldap_parse_result(li->ld, msg, &code, NULL, NULL, NULL, NULL, 0);
  662. if(rc)
  663. code = rc;
  664. else {
  665. /* store the latest code for later retrieval */
  666. data->info.httpcode = code;
  667. }
  668. /* If protocol version 3 is not supported, fallback to version 2. */
  669. if(code == LDAP_PROTOCOL_ERROR && li->state != OLDAP_BINDV2 &&
  670. #ifdef USE_SSL
  671. (ssl_installed(conn) || data->set.use_ssl <= CURLUSESSL_TRY) &&
  672. #endif
  673. li->sasl.prefmech == SASL_AUTH_NONE) {
  674. static const int version = LDAP_VERSION2;
  675. ldap_set_option(li->ld, LDAP_OPT_PROTOCOL_VERSION, &version);
  676. ldap_msgfree(msg);
  677. return oldap_perform_bind(data, OLDAP_BINDV2);
  678. }
  679. }
  680. /* Handle response message according to current state. */
  681. switch(li->state) {
  682. #ifdef USE_SSL
  683. case OLDAP_SSL:
  684. result = oldap_ssl_connect(data, OLDAP_SSL);
  685. if(!result && ssl_installed(conn)) {
  686. if(li->sasl.prefmech != SASL_AUTH_NONE)
  687. result = oldap_perform_mechs(data);
  688. else
  689. result = oldap_perform_bind(data, OLDAP_BIND);
  690. }
  691. break;
  692. case OLDAP_STARTTLS:
  693. if(code != LDAP_SUCCESS) {
  694. if(data->set.use_ssl != CURLUSESSL_TRY)
  695. result = oldap_map_error(code, CURLE_USE_SSL_FAILED);
  696. else if(li->sasl.prefmech != SASL_AUTH_NONE)
  697. result = oldap_perform_mechs(data);
  698. else
  699. result = oldap_perform_bind(data, OLDAP_BIND);
  700. break;
  701. }
  702. result = Curl_ssl_cfilter_add(data, conn, FIRSTSOCKET);
  703. if(result)
  704. break;
  705. FALLTHROUGH();
  706. case OLDAP_TLS:
  707. result = oldap_ssl_connect(data, OLDAP_TLS);
  708. if(result)
  709. result = oldap_map_error(code, CURLE_USE_SSL_FAILED);
  710. else if(ssl_installed(conn)) {
  711. conn->bits.tls_upgraded = TRUE;
  712. if(li->sasl.prefmech != SASL_AUTH_NONE)
  713. result = oldap_perform_mechs(data);
  714. else if(data->state.aptr.user)
  715. result = oldap_perform_bind(data, OLDAP_BIND);
  716. else {
  717. /* Version 3 supported: no bind required */
  718. oldap_state(data, OLDAP_STOP);
  719. result = CURLE_OK;
  720. }
  721. }
  722. break;
  723. #endif
  724. case OLDAP_MECHS:
  725. result = oldap_state_mechs_resp(data, msg, code);
  726. break;
  727. case OLDAP_SASL:
  728. result = oldap_state_sasl_resp(data, msg, code);
  729. break;
  730. case OLDAP_BIND:
  731. case OLDAP_BINDV2:
  732. result = oldap_state_bind_resp(data, msg, code);
  733. break;
  734. default:
  735. /* internal error */
  736. result = CURLE_COULDNT_CONNECT;
  737. break;
  738. }
  739. ldap_msgfree(msg);
  740. *done = li->state == OLDAP_STOP;
  741. if(*done)
  742. conn->recv[FIRSTSOCKET] = oldap_recv;
  743. if(result && li->msgid) {
  744. ldap_abandon_ext(li->ld, li->msgid, NULL, NULL);
  745. li->msgid = 0;
  746. }
  747. return result;
  748. }
  749. static CURLcode oldap_disconnect(struct Curl_easy *data,
  750. struct connectdata *conn,
  751. bool dead_connection)
  752. {
  753. struct ldapconninfo *li = conn->proto.ldapc;
  754. (void) dead_connection;
  755. #ifndef USE_SSL
  756. (void)data;
  757. #endif
  758. if(li) {
  759. if(li->ld) {
  760. #ifdef USE_SSL
  761. if(ssl_installed(conn)) {
  762. Sockbuf *sb;
  763. ldap_get_option(li->ld, LDAP_OPT_SOCKBUF, &sb);
  764. ber_sockbuf_add_io(sb, &ldapsb_tls, LBER_SBIOD_LEVEL_TRANSPORT, data);
  765. }
  766. #endif
  767. ldap_unbind_ext(li->ld, NULL, NULL);
  768. li->ld = NULL;
  769. }
  770. Curl_sasl_cleanup(conn, li->sasl.authused);
  771. conn->proto.ldapc = NULL;
  772. free(li);
  773. }
  774. return CURLE_OK;
  775. }
  776. static CURLcode oldap_do(struct Curl_easy *data, bool *done)
  777. {
  778. struct connectdata *conn = data->conn;
  779. struct ldapconninfo *li = conn->proto.ldapc;
  780. struct ldapreqinfo *lr;
  781. CURLcode result;
  782. int rc;
  783. LDAPURLDesc *lud;
  784. int msgid;
  785. connkeep(conn, "OpenLDAP do");
  786. infof(data, "LDAP local: %s", data->state.url);
  787. result = oldap_url_parse(data, &lud);
  788. if(!result) {
  789. #ifdef USE_SSL
  790. if(ssl_installed(conn)) {
  791. Sockbuf *sb;
  792. /* re-install the libcurl SSL handlers into the sockbuf. */
  793. ldap_get_option(li->ld, LDAP_OPT_SOCKBUF, &sb);
  794. ber_sockbuf_add_io(sb, &ldapsb_tls, LBER_SBIOD_LEVEL_TRANSPORT, data);
  795. }
  796. #endif
  797. rc = ldap_search_ext(li->ld, lud->lud_dn, lud->lud_scope,
  798. lud->lud_filter, lud->lud_attrs, 0,
  799. NULL, NULL, NULL, 0, &msgid);
  800. ldap_free_urldesc(lud);
  801. if(rc != LDAP_SUCCESS) {
  802. failf(data, "LDAP local: ldap_search_ext %s", ldap_err2string(rc));
  803. result = CURLE_LDAP_SEARCH_FAILED;
  804. }
  805. else {
  806. lr = calloc(1, sizeof(struct ldapreqinfo));
  807. if(!lr) {
  808. ldap_abandon_ext(li->ld, msgid, NULL, NULL);
  809. result = CURLE_OUT_OF_MEMORY;
  810. }
  811. else {
  812. lr->msgid = msgid;
  813. data->req.p.ldap = lr;
  814. Curl_xfer_setup(data, FIRSTSOCKET, -1, FALSE, -1);
  815. *done = TRUE;
  816. }
  817. }
  818. }
  819. return result;
  820. }
  821. static CURLcode oldap_done(struct Curl_easy *data, CURLcode res,
  822. bool premature)
  823. {
  824. struct connectdata *conn = data->conn;
  825. struct ldapreqinfo *lr = data->req.p.ldap;
  826. (void)res;
  827. (void)premature;
  828. if(lr) {
  829. /* if there was a search in progress, abandon it */
  830. if(lr->msgid) {
  831. struct ldapconninfo *li = conn->proto.ldapc;
  832. ldap_abandon_ext(li->ld, lr->msgid, NULL, NULL);
  833. lr->msgid = 0;
  834. }
  835. data->req.p.ldap = NULL;
  836. free(lr);
  837. }
  838. return CURLE_OK;
  839. }
  840. static CURLcode client_write(struct Curl_easy *data,
  841. const char *prefix, size_t plen,
  842. const char *value, size_t len,
  843. const char *suffix, size_t slen)
  844. {
  845. CURLcode result = CURLE_OK;
  846. if(prefix) {
  847. /* If we have a zero-length value and the prefix ends with a space
  848. separator, drop the latter. */
  849. if(!len && plen && prefix[plen - 1] == ' ')
  850. plen--;
  851. result = Curl_client_write(data, CLIENTWRITE_BODY, (char *) prefix, plen);
  852. }
  853. if(!result && value) {
  854. result = Curl_client_write(data, CLIENTWRITE_BODY, (char *) value, len);
  855. }
  856. if(!result && suffix) {
  857. result = Curl_client_write(data, CLIENTWRITE_BODY, (char *) suffix, slen);
  858. }
  859. return result;
  860. }
  861. static ssize_t oldap_recv(struct Curl_easy *data, int sockindex, char *buf,
  862. size_t len, CURLcode *err)
  863. {
  864. struct connectdata *conn = data->conn;
  865. struct ldapconninfo *li = conn->proto.ldapc;
  866. struct ldapreqinfo *lr = data->req.p.ldap;
  867. int rc;
  868. LDAPMessage *msg = NULL;
  869. BerElement *ber = NULL;
  870. struct timeval tv = {0, 0};
  871. struct berval bv, *bvals;
  872. int binary = 0;
  873. CURLcode result = CURLE_AGAIN;
  874. int code;
  875. char *info = NULL;
  876. (void)len;
  877. (void)buf;
  878. (void)sockindex;
  879. rc = ldap_result(li->ld, lr->msgid, LDAP_MSG_ONE, &tv, &msg);
  880. if(rc < 0) {
  881. failf(data, "LDAP local: search ldap_result %s", ldap_err2string(rc));
  882. result = CURLE_RECV_ERROR;
  883. }
  884. *err = result;
  885. /* error or timed out */
  886. if(!msg)
  887. return -1;
  888. result = CURLE_OK;
  889. switch(ldap_msgtype(msg)) {
  890. case LDAP_RES_SEARCH_RESULT:
  891. lr->msgid = 0;
  892. rc = ldap_parse_result(li->ld, msg, &code, NULL, &info, NULL, NULL, 0);
  893. if(rc) {
  894. failf(data, "LDAP local: search ldap_parse_result %s",
  895. ldap_err2string(rc));
  896. result = CURLE_LDAP_SEARCH_FAILED;
  897. break;
  898. }
  899. /* store the latest code for later retrieval */
  900. data->info.httpcode = code;
  901. switch(code) {
  902. case LDAP_SIZELIMIT_EXCEEDED:
  903. infof(data, "There are more than %d entries", lr->nument);
  904. FALLTHROUGH();
  905. case LDAP_SUCCESS:
  906. data->req.size = data->req.bytecount;
  907. break;
  908. default:
  909. failf(data, "LDAP remote: search failed %s %s", ldap_err2string(code),
  910. info ? info : "");
  911. result = CURLE_LDAP_SEARCH_FAILED;
  912. break;
  913. }
  914. if(info)
  915. ldap_memfree(info);
  916. break;
  917. case LDAP_RES_SEARCH_ENTRY:
  918. lr->nument++;
  919. rc = ldap_get_dn_ber(li->ld, msg, &ber, &bv);
  920. if(rc < 0) {
  921. result = CURLE_RECV_ERROR;
  922. break;
  923. }
  924. result = client_write(data, STRCONST("DN: "), bv.bv_val, bv.bv_len,
  925. STRCONST("\n"));
  926. if(result)
  927. break;
  928. for(rc = ldap_get_attribute_ber(li->ld, msg, ber, &bv, &bvals);
  929. rc == LDAP_SUCCESS;
  930. rc = ldap_get_attribute_ber(li->ld, msg, ber, &bv, &bvals)) {
  931. int i;
  932. if(!bv.bv_val)
  933. break;
  934. if(!bvals) {
  935. result = client_write(data, STRCONST("\t"), bv.bv_val, bv.bv_len,
  936. STRCONST(":\n"));
  937. if(result)
  938. break;
  939. continue;
  940. }
  941. binary = bv.bv_len > 7 &&
  942. !strncmp(bv.bv_val + bv.bv_len - 7, ";binary", 7);
  943. for(i = 0; bvals[i].bv_val != NULL; i++) {
  944. int binval = 0;
  945. result = client_write(data, STRCONST("\t"), bv.bv_val, bv.bv_len,
  946. STRCONST(":"));
  947. if(result)
  948. break;
  949. if(!binary) {
  950. /* check for leading or trailing whitespace */
  951. if(ISBLANK(bvals[i].bv_val[0]) ||
  952. ISBLANK(bvals[i].bv_val[bvals[i].bv_len - 1]))
  953. binval = 1;
  954. else {
  955. /* check for unprintable characters */
  956. unsigned int j;
  957. for(j = 0; j < bvals[i].bv_len; j++)
  958. if(!ISPRINT(bvals[i].bv_val[j])) {
  959. binval = 1;
  960. break;
  961. }
  962. }
  963. }
  964. if(binary || binval) {
  965. char *val_b64 = NULL;
  966. size_t val_b64_sz = 0;
  967. /* Binary value, encode to base64. */
  968. if(bvals[i].bv_len)
  969. result = Curl_base64_encode(bvals[i].bv_val, bvals[i].bv_len,
  970. &val_b64, &val_b64_sz);
  971. if(!result)
  972. result = client_write(data, STRCONST(": "), val_b64, val_b64_sz,
  973. STRCONST("\n"));
  974. free(val_b64);
  975. }
  976. else
  977. result = client_write(data, STRCONST(" "),
  978. bvals[i].bv_val, bvals[i].bv_len,
  979. STRCONST("\n"));
  980. if(result)
  981. break;
  982. }
  983. ber_memfree(bvals);
  984. bvals = NULL;
  985. if(!result)
  986. result = client_write(data, STRCONST("\n"), NULL, 0, NULL, 0);
  987. if(result)
  988. break;
  989. }
  990. ber_free(ber, 0);
  991. if(!result)
  992. result = client_write(data, STRCONST("\n"), NULL, 0, NULL, 0);
  993. if(!result)
  994. result = CURLE_AGAIN;
  995. break;
  996. }
  997. ldap_msgfree(msg);
  998. *err = result;
  999. return result? -1: 0;
  1000. }
  1001. #ifdef USE_SSL
  1002. static int
  1003. ldapsb_tls_setup(Sockbuf_IO_Desc *sbiod, void *arg)
  1004. {
  1005. sbiod->sbiod_pvt = arg;
  1006. return 0;
  1007. }
  1008. static int
  1009. ldapsb_tls_remove(Sockbuf_IO_Desc *sbiod)
  1010. {
  1011. sbiod->sbiod_pvt = NULL;
  1012. return 0;
  1013. }
  1014. /* We don't need to do anything because libcurl does it already */
  1015. static int
  1016. ldapsb_tls_close(Sockbuf_IO_Desc *sbiod)
  1017. {
  1018. (void)sbiod;
  1019. return 0;
  1020. }
  1021. static int
  1022. ldapsb_tls_ctrl(Sockbuf_IO_Desc *sbiod, int opt, void *arg)
  1023. {
  1024. (void)arg;
  1025. if(opt == LBER_SB_OPT_DATA_READY) {
  1026. struct Curl_easy *data = sbiod->sbiod_pvt;
  1027. return Curl_conn_data_pending(data, FIRSTSOCKET);
  1028. }
  1029. return 0;
  1030. }
  1031. static ber_slen_t
  1032. ldapsb_tls_read(Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len)
  1033. {
  1034. struct Curl_easy *data = sbiod->sbiod_pvt;
  1035. ber_slen_t ret = 0;
  1036. if(data) {
  1037. struct connectdata *conn = data->conn;
  1038. if(conn) {
  1039. struct ldapconninfo *li = conn->proto.ldapc;
  1040. CURLcode err = CURLE_RECV_ERROR;
  1041. ret = (li->recv)(data, FIRSTSOCKET, buf, len, &err);
  1042. if(ret < 0 && err == CURLE_AGAIN) {
  1043. SET_SOCKERRNO(EWOULDBLOCK);
  1044. }
  1045. }
  1046. }
  1047. return ret;
  1048. }
  1049. static ber_slen_t
  1050. ldapsb_tls_write(Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len)
  1051. {
  1052. struct Curl_easy *data = sbiod->sbiod_pvt;
  1053. ber_slen_t ret = 0;
  1054. if(data) {
  1055. struct connectdata *conn = data->conn;
  1056. if(conn) {
  1057. struct ldapconninfo *li = conn->proto.ldapc;
  1058. CURLcode err = CURLE_SEND_ERROR;
  1059. ret = (li->send)(data, FIRSTSOCKET, buf, len, &err);
  1060. if(ret < 0 && err == CURLE_AGAIN) {
  1061. SET_SOCKERRNO(EWOULDBLOCK);
  1062. }
  1063. }
  1064. }
  1065. return ret;
  1066. }
  1067. static Sockbuf_IO ldapsb_tls =
  1068. {
  1069. ldapsb_tls_setup,
  1070. ldapsb_tls_remove,
  1071. ldapsb_tls_ctrl,
  1072. ldapsb_tls_read,
  1073. ldapsb_tls_write,
  1074. ldapsb_tls_close
  1075. };
  1076. #endif /* USE_SSL */
  1077. #endif /* !CURL_DISABLE_LDAP && USE_OPENLDAP */