From: Pierangelo Masarati Date: Fri, 4 Apr 2003 00:48:54 +0000 (+0000) Subject: first cut at mapping/rewriting before search (after search it's already handled by... X-Git-Tag: AUTOCONF_2_57~87 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=5598add84e66ea88425c4e997f0ff81f94ba10be;p=openldap first cut at mapping/rewriting before search (after search it's already handled by ldap_build_entry) --- diff --git a/servers/slapd/back-ldap/search.c b/servers/slapd/back-ldap/search.c index 8e719bf022..7817d2198d 100644 --- a/servers/slapd/back-ldap/search.c +++ b/servers/slapd/back-ldap/search.c @@ -639,18 +639,13 @@ ldap_back_entry_get( struct ldapinfo *li = (struct ldapinfo *) op->o_bd->be_private; struct ldapconn *lc; int rc = 1, is_oc; - struct berval mapped = { 0, NULL }, bdn; + struct berval mapped = { 0, NULL }, bdn, mdn; LDAPMessage *result = NULL, *e = NULL; char *gattr[3]; char *filter; Connection *oconn; SlapReply rs; - ldap_back_map(&li->at_map, &at->ad_cname, &mapped, BACKLDAP_MAP); - if (mapped.bv_val == NULL || mapped.bv_val[0] == '\0') { - return 1; - } - /* Tell getconn this is a privileged op */ is_oc = op->o_do_not_cache; op->o_do_not_cache = 1; @@ -665,6 +660,44 @@ ldap_back_entry_get( op->o_do_not_cache = is_oc; op->o_conn = oconn; + /* + * Rewrite the search base, if required + */ +#ifdef ENABLE_REWRITE + switch ( rewrite_session( li->rwinfo, "searchBase", + ndn->bv_val, op->o_conn, &mdn.bv_val ) ) { + case REWRITE_REGEXEC_OK: + if ( mdn.bv_val == NULL ) { + mdn = *ndn; + } else { + mdn.bv_len = strlen( mdn.bv_val ); + } + +#ifdef NEW_LOGGING + LDAP_LOG( BACK_LDAP, DETAIL1, + "[rw] searchBase: \"%s\" -> \"%s\"\n", + ndn->bv_val, mdn.bv_val, 0 ); +#else /* !NEW_LOGGING */ + Debug( LDAP_DEBUG_ARGS, "rw> searchBase: \"%s\" -> \"%s\"\n", + ndn->bv_val, mdn.bv_val, 0 ); +#endif /* !NEW_LOGGING */ + break; + + case REWRITE_REGEXEC_UNWILLING: + case REWRITE_REGEXEC_ERR: + rc = -1; + goto cleanup; + } + +#else /* !ENABLE_REWRITE */ + ldap_back_dn_massage( li, ndn, &mdn, 0, 1 ); +#endif /* !ENABLE_REWRITE */ + + ldap_back_map(&li->at_map, &at->ad_cname, &mapped, BACKLDAP_MAP); + if (mapped.bv_val == NULL || mapped.bv_val[0] == '\0') { + return 1; + } + is_oc = (strcasecmp("objectclass", mapped.bv_val) == 0); if (oc && !is_oc) { gattr[0] = "objectclass"; @@ -685,7 +718,7 @@ ldap_back_entry_get( filter = "(objectclass=*)"; } - if (ldap_search_ext_s(lc->ld, ndn->bv_val, LDAP_SCOPE_BASE, filter, + if (ldap_search_ext_s(lc->ld, mdn.bv_val, LDAP_SCOPE_BASE, filter, gattr, 0, NULL, NULL, LDAP_NO_LIMIT, LDAP_NO_LIMIT, &result) != LDAP_SUCCESS) { @@ -710,6 +743,10 @@ cleanup: ldap_msgfree(result); } + if ( mdn.bv_val != ndn->bv_val ) { + free( mdn.bv_val ); + } + return(rc); }