X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Foverlays%2Funique.c;h=845b24d2e0454e1b2861f1e939e7bc5611f0971e;hb=200af921f4f1de43d89ba587d711ee9fc739e1bb;hp=e28e6b3540cc8f4400c75008dd449038f66291a2;hpb=69d8588ab436a3da75db84755e3e5ca1f3aaaad5;p=openldap diff --git a/servers/slapd/overlays/unique.c b/servers/slapd/overlays/unique.c index e28e6b3540..845b24d2e0 100644 --- a/servers/slapd/overlays/unique.c +++ b/servers/slapd/overlays/unique.c @@ -2,7 +2,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 2004-2008 The OpenLDAP Foundation. + * Copyright 2004-2011 The OpenLDAP Foundation. * Portions Copyright 2004,2006-2007 Symas Corporation. * All rights reserved. * @@ -47,6 +47,7 @@ typedef struct unique_domain_uri_s { struct berval dn; struct berval ndn; struct berval filter; + Filter *f; struct unique_attrs_s *attrs; int scope; } unique_domain_uri; @@ -141,6 +142,7 @@ unique_free_domain_uri ( unique_domain_uri *uri ) ch_free ( uri->dn.bv_val ); ch_free ( uri->ndn.bv_val ); ch_free ( uri->filter.bv_val ); + filter_free( uri->f ); attr = uri->attrs; while ( attr ) { next_attr = attr->next; @@ -214,6 +216,13 @@ unique_new_domain_uri ( unique_domain_uri **urip, rc = ARG_BAD_CONF; goto exit; } + + if ( BER_BVISNULL( &be->be_rootndn ) || BER_BVISEMPTY( &be->be_rootndn ) ) { + Debug( LDAP_DEBUG_ANY, + "slapo-unique needs a rootdn; " + "backend <%s> has none, YMMV.\n", + be->be_nsuffix[0].bv_val, 0, 0 ); + } } attr_str = url_desc->lud_attrs; @@ -247,17 +256,16 @@ unique_new_domain_uri ( unique_domain_uri **urip, } if (url_desc->lud_filter) { - Filter *f = str2filter( url_desc->lud_filter ); char *ptr; - if ( !f ) { + uri->f = str2filter( url_desc->lud_filter ); + if ( !uri->f ) { snprintf( c->cr_msg, sizeof( c->cr_msg ), "unique: bad filter"); rc = ARG_BAD_CONF; goto exit; } /* make sure the strfilter is in normal form (ITS#5581) */ - filter2bv( f, &uri->filter ); - filter_free( f ); + filter2bv( uri->f, &uri->filter ); ptr = strstr( uri->filter.bv_val, "(?=" /*)*/ ); if ( ptr != NULL && ptr <= ( uri->filter.bv_val - STRLENOF( "(?=" /*)*/ ) + uri->filter.bv_len ) ) { @@ -459,6 +467,13 @@ unique_cf_base( ConfigArgs *c ) abort(); } + if ( rc ) { + ch_free( c->value_dn.bv_val ); + BER_BVZERO( &c->value_dn ); + ch_free( c->value_ndn.bv_val ); + BER_BVZERO( &c->value_ndn ); + } + return rc; } @@ -982,7 +997,7 @@ unique_search( unique_counter uq = { NULL, 0 }; int rc; - Debug(LDAP_DEBUG_TRACE, "==> unique_search %s\n", key, 0, 0); + Debug(LDAP_DEBUG_TRACE, "==> unique_search %s\n", key->bv_val, 0, 0); nop->ors_filter = str2filter_x(nop, key->bv_val); if(nop->ors_filter == NULL) { @@ -1013,7 +1028,7 @@ unique_search( nop->o_bd = on->on_info->oi_origdb; rc = nop->o_bd->be_search(nop, &nrs); - filter_free_x(nop, nop->ors_filter); + filter_free_x(nop, nop->ors_filter, 1); op->o_tmpfree( key->bv_val, op->o_tmpmemctx ); if(rc != LDAP_SUCCESS && rc != LDAP_NO_SUCH_OBJECT) { @@ -1059,18 +1074,29 @@ unique_add( domain = domain->next ) { unique_domain_uri *uri; - int ks = STRLENOF("(|)"); for ( uri = domain->uri; uri; uri = uri->next ) { int len; + int ks = 0; if ( uri->ndn.bv_val && !dnIsSuffix( &op->o_req_ndn, &uri->ndn )) continue; + if ( uri->f ) { + if ( test_filter( NULL, op->ora_e, uri->f ) + == LDAP_COMPARE_FALSE ) + { + Debug( LDAP_DEBUG_TRACE, + "==> unique_add_skip<%s>\n", + op->o_req_dn.bv_val, 0, 0 ); + continue; + } + } + if(!(a = op->ora_e->e_attrs)) { op->o_bd->bd_info = (BackendInfo *) on->on_info; send_ldap_error(op, rs, LDAP_INVALID_SYNTAX, @@ -1091,7 +1117,7 @@ unique_add( if ( !ks ) continue; /* terminating NUL */ - ks++; + ks += sizeof("(|)"); if ( uri->filter.bv_val && uri->filter.bv_len ) ks += uri->filter.bv_len + STRLENOF ("(&)"); @@ -1169,13 +1195,13 @@ unique_modify( domain = domain->next ) { unique_domain_uri *uri; - int ks = STRLENOF("(|)"); for ( uri = domain->uri; uri; uri = uri->next ) { int len; + int ks = 0; if ( uri->ndn.bv_val && !dnIsSuffix( &op->o_req_ndn, &uri->ndn )) @@ -1202,7 +1228,7 @@ unique_modify( if ( !ks ) continue; /* terminating NUL */ - ks++; + ks += sizeof("(|)"); if ( uri->filter.bv_val && uri->filter.bv_len ) ks += uri->filter.bv_len + STRLENOF ("(&)"); @@ -1283,13 +1309,13 @@ unique_modrdn( domain = domain->next ) { unique_domain_uri *uri; - int ks = STRLENOF("(|)"); for ( uri = domain->uri; uri; uri = uri->next ) { int i, len; + int ks = 0; if ( uri->ndn.bv_val && !dnIsSuffix( &op->o_req_ndn, &uri->ndn ) @@ -1338,7 +1364,7 @@ unique_modrdn( if ( !ks ) continue; /* terminating NUL */ - ks++; + ks += sizeof("(|)"); if ( uri->filter.bv_val && uri->filter.bv_len ) ks += uri->filter.bv_len + STRLENOF ("(&)");