20 char * afw_ldap_internal_allattrs[] = {
"+",
"*", NULL };
22 static const int impl_zero = 0;
26 afw_ldap_internal_search_s(
33 rv = ldap_search_s(session->ld, (
char *)dn, ldap_scope, (
char *)filter,
34 afw_ldap_internal_allattrs, 0, &result);
37 afw_ldap_internal_cleanup_ldap_msgfree, xctx);
39 if (rv != LDAP_SUCCESS) {
49 afw_ldap_internal_cleanup_ldap_msgfree(
52 ldap_msgfree((LDAPMessage *)data);
56 afw_ldap_internal_cleanup_ldap_value_free_len(
59 ldap_value_free_len((
struct berval **)data);
63 afw_ldap_internal_cleanup_ldap_memfree(
71 afw_ldap_internal_get_object_id(
78 dn_z = ldap_get_dn(self->ld, e);
81 afw_ldap_internal_cleanup_ldap_memfree,
85 ldap_get_option(self->ld, LDAP_OPT_ERROR_NUMBER, &errno);
95 #if defined(_WIN32) || defined(WIN32)
96 BOOLEAN impl_prevent_verify_server_cert(
98 PCCERT_CONTEXT *pServerCert
106 afw_ldap_internal_session_begin(
116 apr_ldap_err_t *err = NULL;
117 int version = LDAP_VERSION3;
126 if (self->adaptor->lud->lud_scheme &&
127 strcmp(self->adaptor->lud->lud_scheme,
"ldaps") == 0)
129 secure = APR_LDAP_SSL;
131 secure = APR_LDAP_NONE;
134 self->adaptor->lud->lud_host, self->adaptor->lud->lud_port,
136 if (rv != LDAP_SUCCESS) {
138 (err && err->msg)?err->msg:
"Unknown error.", xctx);
143 LDAP_OPT_PROTOCOL_VERSION,
146 if (rv != LDAP_SUCCESS) {
151 if (adaptor->prevent_verify_cert) {
156 #if defined(_WIN32) || defined(WIN32)
157 rv = ldap_set_option(self->ld, LDAP_OPT_SERVER_CERTIFICATE,
158 impl_prevent_verify_server_cert);
161 APR_LDAP_OPT_VERIFY_CERT,
167 if (rv != LDAP_SUCCESS) {
183 self->adaptor->bind_parameters, p, xctx);
187 &adaptor->pub.adaptor_id);
192 &afw_ldap_s_dn, p, xctx);
194 &afw_ldap_s_password, p, xctx);
195 if (!self->bind_dn_z || !self->bind_password_z) {
198 &adaptor->pub.adaptor_id);
208 rv = ldap_simple_bind_s(self->ld,
209 (
char *)self->bind_dn_z,
210 (
char *)self->bind_password_z);
211 if (rv != LDAP_SUCCESS) {
213 "Error binding with user and password.", xctx);
225 ldap_unbind(self->ld);
232 afw_ldap_internal_create_object_from_entry(
249 if (!object_id || !object_id->s) {
250 object_id = afw_ldap_internal_get_object_id(
self, e, FALSE, xctx);
257 first_attribute = NULL;
258 if (self->adaptor->metadata &&
259 self->adaptor->metadata->object_type_attributes)
261 first_attribute = apr_hash_get
262 (self->adaptor->metadata->object_type_attributes,
263 object_type_id->s, object_type_id->len);
271 for (a = ldap_first_attribute(self->ld, e, &be); a;
272 a = ldap_next_attribute(self->ld, e, be))
274 bv = ldap_get_values_len(self->ld, e, a);
280 first_attribute, property_name);
283 value = afw_ldap_metadata_bv_to_value(
self, attribute,
284 property_name, bv, o->p, xctx);
292 ldap_value_free_len(bv);
302 ldap_value_free_len(bv);
318 object_type_id, object_id, xctx);
324 #define AFW_QUERY_CRITERIA_CONTINUE(x) \
325 (x != AFW_QUERY_CRITERIA_FALSE && x != AFW_QUERY_CRITERIA_TRUE)
335 afw_ldap_internal_expression_from_filter_entry(
341 const afw_utf8_t *property_name, *property_value;
351 property_name = entry->property_name;
354 bv = afw_ldap_metadata_value_to_bv(session, property_name, entry->value, xctx);
357 "Query criteria could not be converted into an LDAP filter string.", xctx);
361 property_value =
afw_utf8_create((*bv)->bv_val, (*bv)->bv_len, xctx->p, xctx);
363 switch (entry->op_id) {
364 case afw_query_criteria_filter_op_id_eq:
370 case afw_query_criteria_filter_op_id_ne:
376 case afw_query_criteria_filter_op_id_lt:
382 case afw_query_criteria_filter_op_id_le:
388 case afw_query_criteria_filter_op_id_gt:
394 case afw_query_criteria_filter_op_id_ge:
402 "query operator not supported by LDAP", xctx);
406 return filter_expression;
413 afw_ldap_internal_expression_from_query_criteria(
422 filter_expression = afw_ldap_internal_expression_from_filter_entry(
423 session, entry, xctx);
429 return filter_expression;
433 else if (AFW_QUERY_CRITERIA_CONTINUE(entry->on_true) &&
434 AFW_QUERY_CRITERIA_CONTINUE(entry->on_false))
436 on_true = afw_ldap_internal_expression_from_query_criteria(
437 session, entry->on_true, xctx);
438 on_false = afw_ldap_internal_expression_from_query_criteria(
439 session, entry->on_false, xctx);
449 else if (AFW_QUERY_CRITERIA_CONTINUE(entry->on_true))
451 on_true = afw_ldap_internal_expression_from_query_criteria(
452 session, entry->on_true, xctx);
456 filter_expression->len, filter_expression->s,
457 on_true->len, on_true->s);
461 else if (AFW_QUERY_CRITERIA_CONTINUE(entry->on_false))
463 on_false = afw_ldap_internal_expression_from_query_criteria(
464 session, entry->on_false, xctx);
473 return filter_expression;
Adaptive Framework Core API.
Adaptive Framework LDAP Internal Header
#define afw_value_is_object(A_VALUE)
Macro to determine if value is evaluated object.
#define AFW_UTF8_FMT_ARG(A_STRING)
Convenience Macro for use with AFW_UTF8_FMT to specify arg.
#define AFW_UTF8_Z_LEN
String is NUL (0) terminate.
#define AFW_UTF8_FMT
Format string specifier used for afw_utf8_t.
afw_utf8_octet_t afw_utf8_z_t
NFC normalized UTF-8 null terminated string.
#define AFW_FINALLY
Always executed regardless of error.
#define AFW_THROW_ERROR_RV_Z(code, rv_source_id, rv, message_z, xctx)
Macro used to set error and rv in xctx and throw it.
#define AFW_ENDTRY
Ends an AFW try block.
#define AFW_TRY
Begin an AFW TRY block.
#define AFW_THROW_ERROR_FZ(code, xctx, format_z,...)
Macro used to set error and 0 rv in xctx and throw it.
#define AFW_THROW_ERROR_Z(code, message_z, xctx)
Macro used to set error and 0 rv in xctx and throw it.
afw_object_old_get_property_as_utf8_z(const afw_object_t *instance, const afw_utf8_t *property_name, const afw_pool_t *p, afw_xctx_t *xctx)
Get an object's property value including ancestors as utf8_z in specified pool.
#define afw_object_create_managed(p, xctx)
Create an empty entity object in its own pool.
afw_object_set_property(const afw_object_t *instance, const afw_utf8_t *property_name, const afw_value_t *value, afw_xctx_t *xctx)
Set the value of an object's property.
#define afw_pool_get_apr_pool(instance)
Call method get_apr_pool of interface afw_pool.
#define afw_pool_register_cleanup_before(instance, data, data2, cleanup, xctx)
Call method register_cleanup_before of interface afw_pool.
#define AFW_QUERY_CRITERIA_FALSE
#define AFW_QUERY_CRITERIA_TRUE
#define afw_utf8_create_copy(s, len, p, xctx)
Make a utf-8 sting from chars in pool specified.
afw_utf8_printf(const afw_pool_t *p, afw_xctx_t *xctx, const afw_utf8_z_t *format,...)
Create a utf-8 string using a c format string in specified pool.
#define afw_utf8_create(s, len, p, xctx)
Create utf-8 string without copy unless necessary in pool specified.
#define afw_value_evaluate(value, p, xctx)
Evaluate value if needed using specific pool.
Interface afw_object public struct.
Interface afw_pool public struct.
Parsed filter entry from query string.
NFC normalized UTF-8 string.
struct for data type object values.
Interface afw_value public struct.
Interface afw_xctx public struct.