|
|
@ -25,6 +25,7 @@ oal_connect(oal_config_t * const config) |
|
|
|
|
|
|
|
|
|
|
|
if ((rc = ldap_initialize(&ld, config->bindurls)) != LDAP_SUCCESS) { |
|
|
|
if ((rc = ldap_initialize(&ld, config->bindurls)) != LDAP_SUCCESS) { |
|
|
|
snprintf(config->error, sizeof(config->error), "can't connnect to ldap server(s): %s", strerror(errno)); |
|
|
|
snprintf(config->error, sizeof(config->error), "can't connnect to ldap server(s): %s", strerror(errno)); |
|
|
|
|
|
|
|
return 1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (config->bindtimeout) |
|
|
|
if (config->bindtimeout) |
|
|
@ -33,41 +34,38 @@ oal_connect(oal_config_t * const config) |
|
|
|
/* hardcoded options */ |
|
|
|
/* hardcoded options */ |
|
|
|
if (ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, &ldapver) != LDAP_OPT_SUCCESS) { |
|
|
|
if (ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, &ldapver) != LDAP_OPT_SUCCESS) { |
|
|
|
snprintf(config->error, sizeof(config->error), "can't set ldap protocol version"); |
|
|
|
snprintf(config->error, sizeof(config->error), "can't set ldap protocol version"); |
|
|
|
goto error; |
|
|
|
return 1; |
|
|
|
} |
|
|
|
} |
|
|
|
if (ldap_set_option(ld, LDAP_OPT_SIZELIMIT, &sizelimit) != LDAP_OPT_SUCCESS) { |
|
|
|
if (ldap_set_option(ld, LDAP_OPT_SIZELIMIT, &sizelimit) != LDAP_OPT_SUCCESS) { |
|
|
|
snprintf(config->error, sizeof(config->error), "can't set max results limit"); |
|
|
|
snprintf(config->error, sizeof(config->error), "can't set max results limit"); |
|
|
|
goto error; |
|
|
|
return 1; |
|
|
|
} |
|
|
|
} |
|
|
|
/* timeouts */ |
|
|
|
/* timeouts */ |
|
|
|
if (ldap_set_option(ld, LDAP_OPT_NETWORK_TIMEOUT, &tv) != LDAP_OPT_SUCCESS) { |
|
|
|
if (ldap_set_option(ld, LDAP_OPT_NETWORK_TIMEOUT, &tv) != LDAP_OPT_SUCCESS) { |
|
|
|
snprintf(config->error, sizeof(config->error), "can't set network timeout: %d", config->bindtimeout); |
|
|
|
snprintf(config->error, sizeof(config->error), "can't set network timeout: %d", config->bindtimeout); |
|
|
|
goto error; |
|
|
|
return 1; |
|
|
|
} |
|
|
|
} |
|
|
|
if (ldap_set_option(ld, LDAP_OPT_TIMEOUT, &tv) != LDAP_OPT_SUCCESS) { |
|
|
|
if (ldap_set_option(ld, LDAP_OPT_TIMEOUT, &tv) != LDAP_OPT_SUCCESS) { |
|
|
|
snprintf(config->error, sizeof(config->error), "can't set search timeout: %d", config->bindtimeout); |
|
|
|
snprintf(config->error, sizeof(config->error), "can't set search timeout: %d", config->bindtimeout); |
|
|
|
goto error; |
|
|
|
return 1; |
|
|
|
} |
|
|
|
} |
|
|
|
/* TODO: hardcoded */ |
|
|
|
/* TODO: hardcoded */ |
|
|
|
if (ldap_set_option(ld, LDAP_OPT_REFERRALS, LDAP_OPT_OFF) != LDAP_OPT_SUCCESS) { |
|
|
|
if (ldap_set_option(ld, LDAP_OPT_REFERRALS, LDAP_OPT_OFF) != LDAP_OPT_SUCCESS) { |
|
|
|
snprintf(config->error, sizeof(config->error), "can't set follow referrals to 'off'"); |
|
|
|
snprintf(config->error, sizeof(config->error), "can't set follow referrals to 'off'"); |
|
|
|
goto error; |
|
|
|
return 1; |
|
|
|
} |
|
|
|
} |
|
|
|
/* required */ |
|
|
|
/* required */ |
|
|
|
if (ldap_set_option(ld, LDAP_OPT_DEFBASE, config->basedn) != LDAP_OPT_SUCCESS) { |
|
|
|
if (ldap_set_option(ld, LDAP_OPT_DEFBASE, config->basedn) != LDAP_OPT_SUCCESS) { |
|
|
|
snprintf(config->error, sizeof(config->error), "can't set searchbase: %s", config->basedn); |
|
|
|
snprintf(config->error, sizeof(config->error), "can't set searchbase: %s", config->basedn); |
|
|
|
goto error; |
|
|
|
return 1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if((rc = ldap_simple_bind_s(ld, config->binddn, config->bindpass)) != LDAP_SUCCESS) { |
|
|
|
if((rc = ldap_simple_bind_s(ld, config->binddn, config->bindpass)) != LDAP_SUCCESS) { |
|
|
|
snprintf(config->error, sizeof(config->error), "can't bind to ldap server: %s", ldap_err2string(rc)); |
|
|
|
snprintf(config->error, sizeof(config->error), "can't bind to ldap server: %s", ldap_err2string(rc)); |
|
|
|
goto error; |
|
|
|
return 1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return 0; /* success */ |
|
|
|
return 0; /* success */ |
|
|
|
|
|
|
|
|
|
|
|
error: |
|
|
|
|
|
|
|
return 1; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|