diff options
Diffstat (limited to 'libs/libcurl/src/ldap.c')
-rw-r--r-- | libs/libcurl/src/ldap.c | 168 |
1 files changed, 50 insertions, 118 deletions
diff --git a/libs/libcurl/src/ldap.c b/libs/libcurl/src/ldap.c index 6bc73526d7..f38653e3e0 100644 --- a/libs/libcurl/src/ldap.c +++ b/libs/libcurl/src/ldap.c @@ -26,6 +26,11 @@ #if !defined(CURL_DISABLE_LDAP) && !defined(USE_OPENLDAP)
+#if defined(__GNUC__) && defined(__APPLE__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+
/*
* Notice that USE_OPENLDAP is only a source code selection switch. When
* libcurl is built with USE_OPENLDAP defined the libcurl source code that
@@ -52,7 +57,7 @@ #ifdef USE_WIN32_LDAP /* Use Windows LDAP implementation. */
# ifdef _MSC_VER
# pragma warning(push)
-# pragma warning(disable: 4201)
+# pragma warning(disable:4201)
# endif
# include <subauth.h> /* for [P]UNICODE_STRING */
# ifdef _MSC_VER
@@ -78,15 +83,16 @@ #include "urldata.h"
#include <curl/curl.h>
+#include "cfilters.h"
#include "sendf.h"
#include "escape.h"
#include "progress.h"
#include "transfer.h"
#include "strcase.h"
-#include "strtok.h"
+#include "curlx/strparse.h"
#include "curl_ldap.h"
-#include "curl_multibyte.h"
-#include "curl_base64.h"
+#include "curlx/multibyte.h"
+#include "curlx/base64.h"
#include "connect.h"
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
@@ -148,7 +154,7 @@ static void _ldap_free_urldesc(LDAPURLDesc *ludp); #define ldap_err2string ldap_err2stringA
#endif
-#if defined(USE_WIN32_LDAP) && defined(_MSC_VER) && (_MSC_VER <= 1600)
+#if defined(USE_WIN32_LDAP) && defined(_MSC_VER) && (_MSC_VER <= 1700)
/* Workaround for warning:
'type cast' : conversion from 'int' to 'void *' of greater size */
#undef LDAP_OPT_ON
@@ -181,6 +187,7 @@ const struct Curl_handler Curl_handler_ldap = { ZERO_NULL, /* write_resp_hd */
ZERO_NULL, /* connection_check */
ZERO_NULL, /* attach connection */
+ ZERO_NULL, /* follow */
PORT_LDAP, /* defport */
CURLPROTO_LDAP, /* protocol */
CURLPROTO_LDAP, /* family */
@@ -210,6 +217,7 @@ const struct Curl_handler Curl_handler_ldaps = { ZERO_NULL, /* write_resp_hd */
ZERO_NULL, /* connection_check */
ZERO_NULL, /* attach connection */
+ ZERO_NULL, /* follow */
PORT_LDAPS, /* defport */
CURLPROTO_LDAPS, /* protocol */
CURLPROTO_LDAP, /* family */
@@ -277,8 +285,8 @@ static int ldap_win_bind(struct Curl_easy *data, LDAP *server, PTCHAR inpass = NULL;
if(user && passwd && (data->set.httpauth & CURLAUTH_BASIC)) {
- inuser = curlx_convert_UTF8_to_tchar((char *) user);
- inpass = curlx_convert_UTF8_to_tchar((char *) passwd);
+ inuser = curlx_convert_UTF8_to_tchar(user);
+ inpass = curlx_convert_UTF8_to_tchar(passwd);
rc = (int)ldap_simple_bind_s(server, inuser, inpass);
@@ -346,7 +354,7 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done) }
/* Get the URL scheme (either ldap or ldaps) */
- if(conn->given->flags & PROTOPT_SSL)
+ if(Curl_conn_is_ssl(conn, FIRSTSOCKET))
ldap_ssl = 1;
infof(data, "LDAP local: trying to establish %s connection",
ldap_ssl ? "encrypted" : "cleartext");
@@ -381,55 +389,7 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done) #else
int ldap_option;
char *ldap_ca = conn->ssl_config.CAfile;
-#if defined(CURL_HAS_NOVELL_LDAPSDK)
- rc = ldapssl_client_init(NULL, NULL);
- if(rc != LDAP_SUCCESS) {
- failf(data, "LDAP local: ldapssl_client_init %s", ldap_err2string(rc));
- result = CURLE_SSL_CERTPROBLEM;
- goto quit;
- }
- if(conn->ssl_config.verifypeer) {
- /* Novell SDK supports DER or BASE64 files. */
- int cert_type = LDAPSSL_CERT_FILETYPE_B64;
- if((data->set.ssl.cert_type) &&
- (strcasecompare(data->set.ssl.cert_type, "DER")))
- cert_type = LDAPSSL_CERT_FILETYPE_DER;
- if(!ldap_ca) {
- failf(data, "LDAP local: ERROR %s CA cert not set",
- (cert_type == LDAPSSL_CERT_FILETYPE_DER ? "DER" : "PEM"));
- result = CURLE_SSL_CERTPROBLEM;
- goto quit;
- }
- infof(data, "LDAP local: using %s CA cert '%s'",
- (cert_type == LDAPSSL_CERT_FILETYPE_DER ? "DER" : "PEM"),
- ldap_ca);
- rc = ldapssl_add_trusted_cert(ldap_ca, cert_type);
- if(rc != LDAP_SUCCESS) {
- failf(data, "LDAP local: ERROR setting %s CA cert: %s",
- (cert_type == LDAPSSL_CERT_FILETYPE_DER ? "DER" : "PEM"),
- ldap_err2string(rc));
- result = CURLE_SSL_CERTPROBLEM;
- goto quit;
- }
- ldap_option = LDAPSSL_VERIFY_SERVER;
- }
- else
- ldap_option = LDAPSSL_VERIFY_NONE;
- rc = ldapssl_set_verify_mode(ldap_option);
- if(rc != LDAP_SUCCESS) {
- failf(data, "LDAP local: ERROR setting cert verify mode: %s",
- ldap_err2string(rc));
- result = CURLE_SSL_CERTPROBLEM;
- goto quit;
- }
- server = ldapssl_init(host, conn->primary.remote_port, 1);
- if(!server) {
- failf(data, "LDAP local: Cannot connect to %s:%u",
- conn->host.dispname, conn->primary.remote_port);
- result = CURLE_COULDNT_CONNECT;
- goto quit;
- }
-#elif defined(LDAP_OPT_X_TLS)
+#ifdef LDAP_OPT_X_TLS
if(conn->ssl_config.verifypeer) {
/* OpenLDAP SDK supports BASE64 files. */
if((data->set.ssl.cert_type) &&
@@ -583,7 +543,7 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done) #endif
name_len = strlen(name);
- result = Curl_client_write(data, CLIENTWRITE_BODY, (char *)"DN: ", 4);
+ result = Curl_client_write(data, CLIENTWRITE_BODY, "DN: ", 4);
if(result) {
FREE_ON_WINLDAP(name);
ldap_memfree(dn);
@@ -597,7 +557,7 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done) goto quit;
}
- result = Curl_client_write(data, CLIENTWRITE_BODY, (char *)"\n", 1);
+ result = Curl_client_write(data, CLIENTWRITE_BODY, "\n", 1);
if(result) {
FREE_ON_WINLDAP(name);
ldap_memfree(dn);
@@ -633,7 +593,7 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done) vals = ldap_get_values_len(server, entryIterator, attribute);
if(vals) {
for(i = 0; (vals[i] != NULL); i++) {
- result = Curl_client_write(data, CLIENTWRITE_BODY, (char *)"\t", 1);
+ result = Curl_client_write(data, CLIENTWRITE_BODY, "\t", 1);
if(result) {
ldap_value_free_len(vals);
FREE_ON_WINLDAP(attr);
@@ -655,7 +615,7 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done) goto quit;
}
- result = Curl_client_write(data, CLIENTWRITE_BODY, (char *)": ", 2);
+ result = Curl_client_write(data, CLIENTWRITE_BODY, ": ", 2);
if(result) {
ldap_value_free_len(vals);
FREE_ON_WINLDAP(attr);
@@ -669,8 +629,8 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done) if((attr_len > 7) &&
(strcmp(";binary", attr + (attr_len - 7)) == 0)) {
/* Binary attribute, encode to base64. */
- result = Curl_base64_encode(vals[i]->bv_val, vals[i]->bv_len,
- &val_b64, &val_b64_sz);
+ result = curlx_base64_encode(vals[i]->bv_val, vals[i]->bv_len,
+ &val_b64, &val_b64_sz);
if(result) {
ldap_value_free_len(vals);
FREE_ON_WINLDAP(attr);
@@ -710,7 +670,7 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done) }
}
- result = Curl_client_write(data, CLIENTWRITE_BODY, (char *)"\n", 1);
+ result = Curl_client_write(data, CLIENTWRITE_BODY, "\n", 1);
if(result) {
ldap_value_free_len(vals);
FREE_ON_WINLDAP(attr);
@@ -730,7 +690,7 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done) FREE_ON_WINLDAP(attr);
ldap_memfree(attribute);
- result = Curl_client_write(data, CLIENTWRITE_BODY, (char *)"\n", 1);
+ result = Curl_client_write(data, CLIENTWRITE_BODY, "\n", 1);
if(result)
goto quit;
}
@@ -750,10 +710,6 @@ quit: ldap_free_urldesc(ludp);
if(server)
ldap_unbind_s(server);
-#if defined(HAVE_LDAP_SSL) && defined(CURL_HAS_NOVELL_LDAPSDK)
- if(ldap_ssl)
- ldapssl_client_deinit();
-#endif /* HAVE_LDAP_SSL && CURL_HAS_NOVELL_LDAPSDK */
FREE_ON_WINLDAP(host);
@@ -772,7 +728,9 @@ static void _ldap_trace(const char *fmt, ...) if(do_trace == -1) {
const char *env = getenv("CURL_TRACE");
- do_trace = (env && strtol(env, NULL, 10) > 0);
+ curl_off_t e = 0;
+ if(!curlx_str_number(&env, &e, INT_MAX))
+ do_trace = e > 0;
}
if(!do_trace)
return;
@@ -800,39 +758,20 @@ static int str2scope(const char *p) return LDAP_SCOPE_SUBTREE;
if(strcasecompare(p, "subtree"))
return LDAP_SCOPE_SUBTREE;
- return (-1);
+ return -1;
}
-/*
- * Split 'str' into strings separated by commas.
- * Note: out[] points into 'str'.
- */
-static bool split_str(char *str, char ***out, size_t *count)
+/* number of entries in the attributes list */
+static size_t num_entries(const char *s)
{
- char **res;
- char *lasts;
- char *s;
- size_t i;
size_t items = 1;
- s = strchr(str, ',');
+ s = strchr(s, ',');
while(s) {
items++;
- s = strchr(++s, ',');
+ s = strchr(s + 1, ',');
}
-
- res = calloc(items, sizeof(char *));
- if(!res)
- return FALSE;
-
- for(i = 0, s = strtok_r(str, ",", &lasts); s && i < items;
- s = strtok_r(NULL, ",", &lasts), i++)
- res[i] = s;
-
- *out = res;
- *count = items;
-
- return TRUE;
+ return items;
}
/*
@@ -926,15 +865,8 @@ static int _ldap_url_parse2(struct Curl_easy *data, *q++ = '\0';
if(*p) {
- char **attributes;
- size_t count = 0;
-
- /* Split the string into an array of attributes */
- if(!split_str(p, &attributes, &count)) {
- rc = LDAP_NO_MEMORY;
-
- goto quit;
- }
+ size_t count = num_entries(p); /* at least one */
+ const char *atp = p;
/* Allocate our array (+1 for the NULL entry) */
#if defined(USE_WIN32_LDAP)
@@ -943,27 +875,25 @@ static int _ldap_url_parse2(struct Curl_easy *data, ludp->lud_attrs = calloc(count + 1, sizeof(char *));
#endif
if(!ludp->lud_attrs) {
- free(attributes);
-
rc = LDAP_NO_MEMORY;
-
goto quit;
}
for(i = 0; i < count; i++) {
char *unescaped;
CURLcode result;
+ struct Curl_str out;
+
+ if(curlx_str_until(&atp, &out, 1024, ','))
+ break;
- LDAP_TRACE(("attr[%zu] '%s'\n", i, attributes[i]));
+ LDAP_TRACE(("attr[%zu] '%.*s'\n", i, (int)out.len, out.str));
/* Unescape the attribute */
- result = Curl_urldecode(attributes[i], 0, &unescaped, NULL,
+ result = Curl_urldecode(out.str, out.len, &unescaped, NULL,
REJECT_ZERO);
if(result) {
- free(attributes);
-
rc = LDAP_NO_MEMORY;
-
goto quit;
}
@@ -975,10 +905,7 @@ static int _ldap_url_parse2(struct Curl_easy *data, free(unescaped);
if(!ludp->lud_attrs[i]) {
- free(attributes);
-
rc = LDAP_NO_MEMORY;
-
goto quit;
}
#else
@@ -986,9 +913,9 @@ static int _ldap_url_parse2(struct Curl_easy *data, #endif
ludp->lud_attrs_dups++;
+ if(curlx_str_single(&atp, ','))
+ break;
}
-
- free(attributes);
}
p = q;
@@ -1082,7 +1009,7 @@ static int _ldap_url_parse(struct Curl_easy *data, ludp = NULL;
}
*ludpp = ludp;
- return (rc);
+ return rc;
}
static void _ldap_free_urldesc(LDAPURLDesc *ludp)
@@ -1113,4 +1040,9 @@ static void _ldap_free_urldesc(LDAPURLDesc *ludp) free(ludp);
}
#endif /* !HAVE_LDAP_URL_PARSE */
+
+#if defined(__GNUC__) && defined(__APPLE__)
+#pragma GCC diagnostic pop
+#endif
+
#endif /* !CURL_DISABLE_LDAP && !USE_OPENLDAP */
|