summaryrefslogtreecommitdiff
path: root/libs/libcurl/src/openldap.c
diff options
context:
space:
mode:
Diffstat (limited to 'libs/libcurl/src/openldap.c')
-rw-r--r--libs/libcurl/src/openldap.c88
1 files changed, 37 insertions, 51 deletions
diff --git a/libs/libcurl/src/openldap.c b/libs/libcurl/src/openldap.c
index 5feb3813d4..8bbf9711bf 100644
--- a/libs/libcurl/src/openldap.c
+++ b/libs/libcurl/src/openldap.c
@@ -236,17 +236,13 @@ static CURLcode oldap_map_error(int rc, CURLcode result)
{
switch(rc) {
case LDAP_NO_MEMORY:
- result = CURLE_OUT_OF_MEMORY;
- break;
+ return CURLE_OUT_OF_MEMORY;
case LDAP_INVALID_CREDENTIALS:
- result = CURLE_LOGIN_DENIED;
- break;
+ return CURLE_LOGIN_DENIED;
case LDAP_PROTOCOL_ERROR:
- result = CURLE_UNSUPPORTED_PROTOCOL;
- break;
+ return CURLE_UNSUPPORTED_PROTOCOL;
case LDAP_INSUFFICIENT_ACCESS:
- result = CURLE_REMOTE_ACCESS_DENIED;
- break;
+ return CURLE_REMOTE_ACCESS_DENIED;
}
return result;
}
@@ -276,7 +272,8 @@ static CURLcode oldap_url_parse(struct Curl_easy *data, LDAPURLDesc **ludp)
if(rc != LDAP_URL_SUCCESS) {
const char *msg = "url parsing problem";
- result = rc == LDAP_URL_ERR_MEM? CURLE_OUT_OF_MEMORY: CURLE_URL_MALFORMAT;
+ result = rc == LDAP_URL_ERR_MEM ? CURLE_OUT_OF_MEMORY :
+ CURLE_URL_MALFORMAT;
rc -= LDAP_URL_SUCCESS;
if((size_t) rc < sizeof(url_errs) / sizeof(url_errs[0]))
msg = url_errs[rc];
@@ -313,7 +310,7 @@ static CURLcode oldap_parse_login_options(struct connectdata *conn)
ptr++;
}
- return result == CURLE_URL_MALFORMAT? CURLE_SETOPT_OPTION_SYNTAX: result;
+ return result == CURLE_URL_MALFORMAT ? CURLE_SETOPT_OPTION_SYNTAX : result;
}
static CURLcode oldap_setup_connection(struct Curl_easy *data,
@@ -351,7 +348,6 @@ static CURLcode oldap_perform_auth(struct Curl_easy *data, const char *mech,
{
struct connectdata *conn = data->conn;
struct ldapconninfo *li = conn->proto.ldapc;
- CURLcode result = CURLE_OK;
struct berval cred;
struct berval *pcred = &cred;
int rc;
@@ -362,8 +358,8 @@ static CURLcode oldap_perform_auth(struct Curl_easy *data, const char *mech,
pcred = NULL;
rc = ldap_sasl_bind(li->ld, NULL, mech, pcred, NULL, NULL, &li->msgid);
if(rc != LDAP_SUCCESS)
- result = oldap_map_error(rc, CURLE_LDAP_CANNOT_BIND);
- return result;
+ return oldap_map_error(rc, CURLE_LDAP_CANNOT_BIND);
+ return CURLE_OK;
}
/*
@@ -374,7 +370,6 @@ static CURLcode oldap_continue_auth(struct Curl_easy *data, const char *mech,
{
struct connectdata *conn = data->conn;
struct ldapconninfo *li = conn->proto.ldapc;
- CURLcode result = CURLE_OK;
struct berval cred;
struct berval *pcred = &cred;
int rc;
@@ -385,8 +380,8 @@ static CURLcode oldap_continue_auth(struct Curl_easy *data, const char *mech,
pcred = NULL;
rc = ldap_sasl_bind(li->ld, NULL, mech, pcred, NULL, NULL, &li->msgid);
if(rc != LDAP_SUCCESS)
- result = oldap_map_error(rc, CURLE_LDAP_CANNOT_BIND);
- return result;
+ return oldap_map_error(rc, CURLE_LDAP_CANNOT_BIND);
+ return CURLE_OK;
}
/*
@@ -395,20 +390,18 @@ static CURLcode oldap_continue_auth(struct Curl_easy *data, const char *mech,
static CURLcode oldap_cancel_auth(struct Curl_easy *data, const char *mech)
{
struct ldapconninfo *li = data->conn->proto.ldapc;
- CURLcode result = CURLE_OK;
int rc = ldap_sasl_bind(li->ld, NULL, LDAP_SASL_NULL, NULL, NULL, NULL,
&li->msgid);
(void)mech;
if(rc != LDAP_SUCCESS)
- result = oldap_map_error(rc, CURLE_LDAP_CANNOT_BIND);
- return result;
+ return oldap_map_error(rc, CURLE_LDAP_CANNOT_BIND);
+ return CURLE_OK;
}
/* Starts LDAP simple bind. */
static CURLcode oldap_perform_bind(struct Curl_easy *data, ldapstate newstate)
{
- CURLcode result = CURLE_OK;
struct connectdata *conn = data->conn;
struct ldapconninfo *li = conn->proto.ldapc;
char *binddn = NULL;
@@ -426,19 +419,17 @@ static CURLcode oldap_perform_bind(struct Curl_easy *data, ldapstate newstate)
rc = ldap_sasl_bind(li->ld, binddn, LDAP_SASL_SIMPLE, &passwd,
NULL, NULL, &li->msgid);
- if(rc == LDAP_SUCCESS)
- oldap_state(data, newstate);
- else
- result = oldap_map_error(rc,
- data->state.aptr.user?
- CURLE_LOGIN_DENIED: CURLE_LDAP_CANNOT_BIND);
- return result;
+ if(rc != LDAP_SUCCESS)
+ return oldap_map_error(rc,
+ data->state.aptr.user ?
+ CURLE_LOGIN_DENIED : CURLE_LDAP_CANNOT_BIND);
+ oldap_state(data, newstate);
+ return CURLE_OK;
}
/* Query the supported SASL authentication mechanisms. */
static CURLcode oldap_perform_mechs(struct Curl_easy *data)
{
- CURLcode result = CURLE_OK;
struct ldapconninfo *li = data->conn->proto.ldapc;
int rc;
static const char * const supportedSASLMechanisms[] = {
@@ -449,11 +440,10 @@ static CURLcode oldap_perform_mechs(struct Curl_easy *data)
rc = ldap_search_ext(li->ld, "", LDAP_SCOPE_BASE, "(objectclass=*)",
(char **) supportedSASLMechanisms, 0,
NULL, NULL, NULL, 0, &li->msgid);
- if(rc == LDAP_SUCCESS)
- oldap_state(data, OLDAP_MECHS);
- else
- result = oldap_map_error(rc, CURLE_LOGIN_DENIED);
- return result;
+ if(rc != LDAP_SUCCESS)
+ return oldap_map_error(rc, CURLE_LOGIN_DENIED);
+ oldap_state(data, OLDAP_MECHS);
+ return CURLE_OK;
}
/* Starts SASL bind. */
@@ -479,12 +469,10 @@ static bool ssl_installed(struct connectdata *conn)
static CURLcode oldap_ssl_connect(struct Curl_easy *data, ldapstate newstate)
{
- CURLcode result = CURLE_OK;
struct connectdata *conn = data->conn;
struct ldapconninfo *li = conn->proto.ldapc;
- bool ssldone = 0;
-
- result = Curl_conn_connect(data, FIRSTSOCKET, FALSE, &ssldone);
+ bool ssldone = FALSE;
+ CURLcode result = Curl_conn_connect(data, FIRSTSOCKET, FALSE, &ssldone);
if(!result) {
oldap_state(data, newstate);
@@ -505,15 +493,13 @@ static CURLcode oldap_ssl_connect(struct Curl_easy *data, ldapstate newstate)
/* Send the STARTTLS request */
static CURLcode oldap_perform_starttls(struct Curl_easy *data)
{
- CURLcode result = CURLE_OK;
struct ldapconninfo *li = data->conn->proto.ldapc;
int rc = ldap_start_tls(li->ld, NULL, NULL, &li->msgid);
- if(rc == LDAP_SUCCESS)
- oldap_state(data, OLDAP_STARTTLS);
- else
- result = oldap_map_error(rc, CURLE_USE_SSL_FAILED);
- return result;
+ if(rc != LDAP_SUCCESS)
+ return oldap_map_error(rc, CURLE_USE_SSL_FAILED);
+ oldap_state(data, OLDAP_STARTTLS);
+ return CURLE_OK;
}
#endif
@@ -552,9 +538,9 @@ static CURLcode oldap_connect(struct Curl_easy *data, bool *done)
hosturl = aprintf("%s://%s%s%s:%d",
conn->handler->scheme,
- conn->bits.ipv6_ip? "[": "",
+ conn->bits.ipv6_ip ? "[" : "",
conn->host.name,
- conn->bits.ipv6_ip? "]": "",
+ conn->bits.ipv6_ip ? "]" : "",
conn->remote_port);
if(!hosturl)
return CURLE_OUT_OF_MEMORY;
@@ -986,7 +972,7 @@ static ssize_t oldap_recv(struct Curl_easy *data, int sockindex, char *buf,
BerElement *ber = NULL;
struct timeval tv = {0, 0};
struct berval bv, *bvals;
- int binary = 0;
+ bool binary = FALSE;
CURLcode result = CURLE_AGAIN;
int code;
char *info = NULL;
@@ -1069,10 +1055,10 @@ static ssize_t oldap_recv(struct Curl_easy *data, int sockindex, char *buf,
}
binary = bv.bv_len > 7 &&
- !strncmp(bv.bv_val + bv.bv_len - 7, ";binary", 7);
+ !strncmp(bv.bv_val + bv.bv_len - 7, ";binary", 7);
for(i = 0; bvals[i].bv_val != NULL; i++) {
- int binval = 0;
+ bool binval = FALSE;
result = client_write(data, STRCONST("\t"), bv.bv_val, bv.bv_len,
STRCONST(":"));
@@ -1083,13 +1069,13 @@ static ssize_t oldap_recv(struct Curl_easy *data, int sockindex, char *buf,
/* check for leading or trailing whitespace */
if(ISBLANK(bvals[i].bv_val[0]) ||
ISBLANK(bvals[i].bv_val[bvals[i].bv_len - 1]))
- binval = 1;
+ binval = TRUE;
else {
/* check for unprintable characters */
unsigned int j;
for(j = 0; j < bvals[i].bv_len; j++)
if(!ISPRINT(bvals[i].bv_val[j])) {
- binval = 1;
+ binval = TRUE;
break;
}
}
@@ -1134,7 +1120,7 @@ static ssize_t oldap_recv(struct Curl_easy *data, int sockindex, char *buf,
ldap_msgfree(msg);
*err = result;
- return result? -1: 0;
+ return result ? -1 : 0;
}
#ifdef USE_SSL