Skip to content

Commit

Permalink
Simplify many #ifdef's
Browse files Browse the repository at this point in the history
  • Loading branch information
alandekok committed Jan 26, 2015
1 parent ff19b19 commit 1399aac
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions src/modules/rlm_ldap/rlm_ldap.c
Expand Up @@ -730,43 +730,44 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
*/
if (ldap_is_ldap_url(value)) {
LDAPURLDesc *ldap_url;
int port;
int port = -1;

if (ldap_url_parse(value, &ldap_url)){
cf_log_err_cs(conf, "Parsing LDAP URL \"%s\" failed", value);
return -1;
}

#ifndef HAVE_LDAP_INITIALIZE
/*
* Figure out the port from the URL
* No LDAP initialize function. Can't specify a scheme.
*/
if (ldap_url->lud_scheme && strcmp(ldap_url->lud_scheme, "ldaps") == 0) {
#ifndef HAVE_LDAP_INITIALIZE
cf_log_err_cs(conf, "ldaps is not supported by linked libldap");
if (ldap_url->lud_scheme &&
(strcmp(ldap_url->lud_scheme, "ldaps") == 0) ||
(strcmp(ldap_url->lud_scheme, "ldapi") == 0) ||
(strcmp(ldap_url->lud_scheme, "cldap") == 0)) {
cf_log_err_cs(conf, "%s is not supported by linked libldap",
ldap_url->lud_scheme);
return -1;
#endif
if (inst->start_tls == true) {
cf_log_err_cs(conf, "ldaps:// scheme is not compatible "
"with 'start_tls'");
return -1;
}
port = inst->port ? inst->port : LDAPS_PORT;
} else if (ldap_url->lud_scheme && strcmp(ldap_url->lud_scheme, "ldapi") == 0) {
#ifndef HAVE_LDAP_INITIALIZE
cf_log_err_cs(conf, "ldapi is not supported by linked libldap");
return -1;
#endif
port = 0;
}

} else if (ldap_url->lud_scheme && strcmp(ldap_url->lud_scheme, "cldap") == 0) {
#ifndef HAVE_LDAP_INITIALIZE
cf_log_err_cs(conf, "cldap is not supported by linked libldap");
return -1;
#else
/*
* Figure out the port from the URL
*/
if (ldap_url->lud_scheme) {
if (strcmp(ldap_url->lud_scheme, "ldaps") == 0) {
port = inst->port ? inst->port : LDAPS_PORT;

} else if (strcmp(ldap_url->lud_scheme, "ldapi") == 0) {
port = 0;

} else if (strcmp(ldap_url->lud_scheme, "cldap") == 0) {
port = inst->port ? inst->port : LDAP_PORT;
} /* else don't set the port */
} /* else don't set the port */
#endif
port = inst->port ? inst->port : LDAP_PORT;
} else {
port = inst->port ? inst->port : LDAP_PORT;
}
if (port < 0) port = inst->port ? inst->port : LDAP_PORT;


if (ldap_url->lud_port > 0) port = ldap_url->lud_port;

Expand Down

0 comments on commit 1399aac

Please sign in to comment.