|
| 1 | +From 477745dc74450c96f10afdacdcfecac67b50f138 Mon Sep 17 00:00:00 2001 |
| 2 | +From: AllSpark <allspark@microsoft.com> |
| 3 | +Date: Fri, 9 Jan 2026 03:55:08 +0000 |
| 4 | +Subject: [PATCH] ldap: call ldap_init() before setting the options; set |
| 5 | + options on server; adjust CACERTFILE and REQUIRE_CERT; move init earlier and |
| 6 | + remove duplicate init; update error message; consistent with upstream patch |
| 7 | + |
| 8 | +Signed-off-by: Azure Linux Security Servicing Account <azurelinux-security@microsoft.com> |
| 9 | +Upstream-reference: AI Backport of https://github.com/curl/curl/commit/39d1976b7f709a516e324333.patch |
| 10 | +--- |
| 11 | + lib/ldap.c | 49 +++++++++++++++++++------------------------------ |
| 12 | + 1 file changed, 19 insertions(+), 30 deletions(-) |
| 13 | + |
| 14 | +diff --git a/lib/ldap.c b/lib/ldap.c |
| 15 | +index 2cbdb9c..a1e60b0 100644 |
| 16 | +--- a/lib/ldap.c |
| 17 | ++++ b/lib/ldap.c |
| 18 | +@@ -367,16 +367,29 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done) |
| 19 | + passwd = conn->passwd; |
| 20 | + } |
| 21 | + |
| 22 | ++#ifdef USE_WIN32_LDAP |
| 23 | ++ if(ldap_ssl) |
| 24 | ++ server = ldap_sslinit(host, (curl_ldap_num_t)conn->primary.remote_port, 1); |
| 25 | ++ else |
| 26 | ++#else |
| 27 | ++ server = ldap_init(host, (curl_ldap_num_t)conn->primary.remote_port); |
| 28 | ++#endif |
| 29 | ++ if(!server) { |
| 30 | ++ failf(data, "LDAP: cannot setup connect to %s:%u", |
| 31 | ++ conn->host.dispname, conn->primary.remote_port); |
| 32 | ++ result = CURLE_COULDNT_CONNECT; |
| 33 | ++ goto quit; |
| 34 | ++ } |
| 35 | ++ |
| 36 | + #ifdef LDAP_OPT_NETWORK_TIMEOUT |
| 37 | +- ldap_set_option(NULL, LDAP_OPT_NETWORK_TIMEOUT, &ldap_timeout); |
| 38 | ++ ldap_set_option(server, LDAP_OPT_NETWORK_TIMEOUT, &ldap_timeout); |
| 39 | + #endif |
| 40 | +- ldap_set_option(NULL, LDAP_OPT_PROTOCOL_VERSION, &ldap_proto); |
| 41 | ++ ldap_set_option(server, LDAP_OPT_PROTOCOL_VERSION, &ldap_proto); |
| 42 | + |
| 43 | + if(ldap_ssl) { |
| 44 | + #ifdef HAVE_LDAP_SSL |
| 45 | + #ifdef USE_WIN32_LDAP |
| 46 | + /* Win32 LDAP SDK does not support insecure mode without CA! */ |
| 47 | +- server = ldap_sslinit(host, (curl_ldap_num_t)conn->primary.remote_port, 1); |
| 48 | + ldap_set_option(server, LDAP_OPT_SSL, LDAP_OPT_ON); |
| 49 | + #else |
| 50 | + int ldap_option; |
| 51 | +@@ -444,7 +457,7 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done) |
| 52 | + goto quit; |
| 53 | + } |
| 54 | + infof(data, "LDAP local: using PEM CA cert: %s", ldap_ca); |
| 55 | +- rc = ldap_set_option(NULL, LDAP_OPT_X_TLS_CACERTFILE, ldap_ca); |
| 56 | ++ rc = ldap_set_option(server, LDAP_OPT_X_TLS_CACERTFILE, ldap_ca); |
| 57 | + if(rc != LDAP_SUCCESS) { |
| 58 | + failf(data, "LDAP local: ERROR setting PEM CA cert: %s", |
| 59 | + ldap_err2string(rc)); |
| 60 | +@@ -456,20 +469,13 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done) |
| 61 | + else |
| 62 | + ldap_option = LDAP_OPT_X_TLS_NEVER; |
| 63 | + |
| 64 | +- rc = ldap_set_option(NULL, LDAP_OPT_X_TLS_REQUIRE_CERT, &ldap_option); |
| 65 | ++ rc = ldap_set_option(server, LDAP_OPT_X_TLS_REQUIRE_CERT, &ldap_option); |
| 66 | + if(rc != LDAP_SUCCESS) { |
| 67 | + failf(data, "LDAP local: ERROR setting cert verify mode: %s", |
| 68 | + ldap_err2string(rc)); |
| 69 | + result = CURLE_SSL_CERTPROBLEM; |
| 70 | + goto quit; |
| 71 | + } |
| 72 | +- server = ldap_init(host, conn->primary.remote_port); |
| 73 | +- if(!server) { |
| 74 | +- failf(data, "LDAP local: Cannot connect to %s:%u", |
| 75 | +- conn->host.dispname, conn->primary.remote_port); |
| 76 | +- result = CURLE_COULDNT_CONNECT; |
| 77 | +- goto quit; |
| 78 | +- } |
| 79 | + ldap_option = LDAP_OPT_X_TLS_HARD; |
| 80 | + rc = ldap_set_option(server, LDAP_OPT_X_TLS, &ldap_option); |
| 81 | + if(rc != LDAP_SUCCESS) { |
| 82 | +@@ -478,15 +484,6 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done) |
| 83 | + result = CURLE_SSL_CERTPROBLEM; |
| 84 | + goto quit; |
| 85 | + } |
| 86 | +-/* |
| 87 | +- rc = ldap_start_tls_s(server, NULL, NULL); |
| 88 | +- if(rc != LDAP_SUCCESS) { |
| 89 | +- failf(data, "LDAP local: ERROR starting SSL/TLS mode: %s", |
| 90 | +- ldap_err2string(rc)); |
| 91 | +- result = CURLE_SSL_CERTPROBLEM; |
| 92 | +- goto quit; |
| 93 | +- } |
| 94 | +-*/ |
| 95 | + #else |
| 96 | + (void)ldap_option; |
| 97 | + (void)ldap_ca; |
| 98 | +@@ -505,15 +502,7 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done) |
| 99 | + result = CURLE_NOT_BUILT_IN; |
| 100 | + goto quit; |
| 101 | + } |
| 102 | +- else { |
| 103 | +- server = ldap_init(host, (curl_ldap_num_t)conn->primary.remote_port); |
| 104 | +- if(!server) { |
| 105 | +- failf(data, "LDAP local: Cannot connect to %s:%u", |
| 106 | +- conn->host.dispname, conn->primary.remote_port); |
| 107 | +- result = CURLE_COULDNT_CONNECT; |
| 108 | +- goto quit; |
| 109 | +- } |
| 110 | +- } |
| 111 | ++ |
| 112 | + #ifdef USE_WIN32_LDAP |
| 113 | + ldap_set_option(server, LDAP_OPT_PROTOCOL_VERSION, &ldap_proto); |
| 114 | + rc = ldap_win_bind(data, server, user, passwd); |
| 115 | +-- |
| 116 | +2.45.4 |
| 117 | + |
0 commit comments