From: Howard Chu Date: Fri, 14 Feb 2003 05:23:45 +0000 (+0000) Subject: Use extended async APIs to allow direct parsing of results. Otherwise X-Git-Tag: NO_SLAP_OP_BLOCKS~363 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=0b6772492fb420f729536e2e6c06a4637181e2d4;p=openldap Use extended async APIs to allow direct parsing of results. Otherwise they will be interleaved in LDAP*. Avoid setting any options on the handle. --- diff --git a/servers/slapd/back-ldap/add.c b/servers/slapd/back-ldap/add.c index f9032f0531..cacc1b1dd4 100644 --- a/servers/slapd/back-ldap/add.c +++ b/servers/slapd/back-ldap/add.c @@ -60,6 +60,7 @@ ldap_back_add( LDAPMod **attrs; struct berval mapped; struct berval mdn = { 0, NULL }; + ber_int_t msgid; #ifdef NEW_LOGGING LDAP_LOG( BACK_LDAP, ENTRY, "ldap_back_add: %s\n", e->e_dn, 0, 0 ); @@ -176,7 +177,7 @@ ldap_back_add( } attrs[i] = NULL; - ldap_add_s(lc->ld, mdn.bv_val, attrs); + j = ldap_add_ext(lc->ld, mdn.bv_val, attrs, op->o_ctrls, NULL, &msgid); for (--i; i>= 0; --i) { ch_free(attrs[i]->mod_vals.modv_bvals); ch_free(attrs[i]); @@ -186,7 +187,7 @@ ldap_back_add( free( mdn.bv_val ); } - return( ldap_back_op_result( lc, conn, op ) ); + return( ldap_back_op_result( lc, conn, op, msgid, j ) ); } #ifdef ENABLE_REWRITE diff --git a/servers/slapd/back-ldap/back-ldap.h b/servers/slapd/back-ldap/back-ldap.h index 585f44720c..77f09561c5 100644 --- a/servers/slapd/back-ldap/back-ldap.h +++ b/servers/slapd/back-ldap/back-ldap.h @@ -95,7 +95,8 @@ struct ldapconn *ldap_back_getconn(struct ldapinfo *li, struct slap_conn *conn, struct slap_op *op); int ldap_back_dobind(struct ldapconn *lc, Connection *conn, Operation *op); int ldap_back_map_result(int err); -int ldap_back_op_result(struct ldapconn *lc, Connection *conn, Operation *op); +int ldap_back_op_result(struct ldapconn *lc, Connection *conn, Operation *op, + ber_int_t msgid, int rc); int back_ldap_LTX_init_module(int argc, char *argv[]); void ldap_back_dn_massage(struct ldapinfo *li, struct berval *dn, diff --git a/servers/slapd/back-ldap/bind.c b/servers/slapd/back-ldap/bind.c index 99585edbf9..b24c940269 100644 --- a/servers/slapd/back-ldap/bind.c +++ b/servers/slapd/back-ldap/bind.c @@ -68,20 +68,13 @@ ldap_back_bind( struct berval mdn = { 0, NULL }; int rc = 0; + ber_int_t msgid; lc = ldap_back_getconn(li, conn, op); if ( !lc ) { return( -1 ); } - if ( op->o_ctrls ) { - if ( ldap_set_option( lc->ld, LDAP_OPT_SERVER_CONTROLS, - op->o_ctrls ) != LDAP_SUCCESS ) { - ldap_back_op_result( lc, conn, op ); - return( -1 ); - } - } - /* * Rewrite the bind dn if needed */ @@ -120,23 +113,23 @@ ldap_back_bind( lc->bound_dn.bv_val = NULL; } lc->bound = 0; - rc = ldap_bind_s(lc->ld, mdn.bv_val, cred->bv_val, method); - if (rc != LDAP_SUCCESS) { - rc = ldap_back_op_result( lc, conn, op ); - } else { + /* method is always LDAP_AUTH_SIMPLE if we got here */ + rc = ldap_sasl_bind(lc->ld, mdn.bv_val, LDAP_SASL_SIMPLE, + cred, op->o_ctrls, NULL, &msgid); + rc = ldap_back_op_result( lc, conn, op, msgid, rc ); + if (rc == LDAP_SUCCESS) { lc->bound = 1; if ( mdn.bv_val != dn->bv_val ) { lc->bound_dn = mdn; } else { ber_dupbv( &lc->bound_dn, dn ); } - } - - if ( li->savecred ) { - if ( lc->cred.bv_val ) - ch_free( lc->cred.bv_val ); - ber_dupbv( &lc->cred, cred ); - ldap_set_rebind_proc( lc->ld, ldap_back_rebind, lc ); + if ( li->savecred ) { + if ( lc->cred.bv_val ) + ch_free( lc->cred.bv_val ); + ber_dupbv( &lc->cred, cred ); + ldap_set_rebind_proc( lc->ld, ldap_back_rebind, lc ); + } } /* must re-insert if local DN changed as result of bind */ @@ -419,30 +412,19 @@ ldap_back_getconn(struct ldapinfo *li, Connection *conn, Operation *op) int ldap_back_dobind( struct ldapconn *lc, Connection *conn, Operation *op ) { - int rc = 0; + int rc; + ber_int_t msgid; ldap_pvt_thread_mutex_lock( &lc->lc_mutex ); - if ( op->o_ctrls ) { - if ( ldap_set_option( lc->ld, LDAP_OPT_SERVER_CONTROLS, - op->o_ctrls ) != LDAP_SUCCESS ) { - ldap_back_op_result( lc, conn, op ); - goto leave; + if ( !lc->bound ) { + rc = ldap_sasl_bind(lc->ld, lc->bound_dn.bv_val, + LDAP_SASL_SIMPLE, &lc->cred, NULL, NULL, &msgid); + rc = ldap_back_op_result( lc, conn, op, msgid, rc ); + if (rc == LDAP_SUCCESS) { + lc->bound = 1; } } - - if ( lc->bound ) { - rc = lc->bound; - goto leave; - } - - if ( ldap_bind_s( lc->ld, lc->bound_dn.bv_val, lc->cred.bv_val, - LDAP_AUTH_SIMPLE ) != LDAP_SUCCESS ) { - ldap_back_op_result( lc, conn, op ); - goto leave; - } /* else */ - - rc = lc->bound = 1; -leave: + rc = lc->bound; ldap_pvt_thread_mutex_unlock( &lc->lc_mutex ); return rc; } @@ -510,21 +492,28 @@ ldap_back_map_result(int err) } int -ldap_back_op_result(struct ldapconn *lc, Connection *conn, Operation *op) +ldap_back_op_result(struct ldapconn *lc, Connection *conn, Operation *op, + ber_int_t msgid, int err) { - int err = LDAP_SUCCESS; char *msg = NULL; char *match = NULL; + LDAPMessage *res; + int rc; - ldap_get_option(lc->ld, LDAP_OPT_ERROR_NUMBER, &err); + if (err == LDAP_SUCCESS) { + if (ldap_result(lc->ld, msgid, 0, NULL, &res) == -1) { + ldap_get_option(lc->ld, LDAP_OPT_ERROR_NUMBER, &err); + } else { + rc = ldap_parse_result(lc->ld, res, &err, &match, + &msg, NULL, NULL, 1); + if (rc != LDAP_SUCCESS) err = rc; + } + } + err = ldap_back_map_result(err); /* internal ops must not reply to client */ if ( !conn || op->o_do_not_cache ) goto quiet; - ldap_get_option(lc->ld, LDAP_OPT_ERROR_STRING, &msg); - ldap_get_option(lc->ld, LDAP_OPT_MATCHED_DN, &match); - err = ldap_back_map_result(err); - #ifdef ENABLE_REWRITE /* diff --git a/servers/slapd/back-ldap/compare.c b/servers/slapd/back-ldap/compare.c index 43e8f93fbf..3b9c101b92 100644 --- a/servers/slapd/back-ldap/compare.c +++ b/servers/slapd/back-ldap/compare.c @@ -59,6 +59,8 @@ ldap_back_compare( struct ldapconn *lc; struct berval mapped_oc, mapped_at; struct berval mdn = { 0, NULL }; + int rc; + ber_int_t msgid; lc = ldap_back_getconn(li, conn, op); if (!lc || !ldap_back_dobind( lc, conn, op ) ) { @@ -115,11 +117,12 @@ ldap_back_compare( } } - ldap_compare_s( lc->ld, mdn.bv_val, mapped_oc.bv_val, mapped_at.bv_val ); + rc = ldap_compare_ext( lc->ld, mdn.bv_val, mapped_oc.bv_val, + &mapped_at, op->o_ctrls, NULL, &msgid ); if ( mdn.bv_val != dn->bv_val ) { free( mdn.bv_val ); } - return( ldap_back_op_result( lc, conn, op ) ); + return( ldap_back_op_result( lc, conn, op, msgid, rc ) ); } diff --git a/servers/slapd/back-ldap/delete.c b/servers/slapd/back-ldap/delete.c index b2a8139b49..48ab3c3533 100644 --- a/servers/slapd/back-ldap/delete.c +++ b/servers/slapd/back-ldap/delete.c @@ -56,6 +56,8 @@ ldap_back_delete( { struct ldapinfo *li = (struct ldapinfo *) be->be_private; struct ldapconn *lc; + int rc; + ber_int_t msgid; struct berval mdn = { 0, NULL }; @@ -97,11 +99,11 @@ ldap_back_delete( ldap_back_dn_massage( li, dn, &mdn, 0, 1 ); #endif /* !ENABLE_REWRITE */ - ldap_delete_s( lc->ld, mdn.bv_val ); + rc = ldap_delete_ext( lc->ld, mdn.bv_val, op->o_ctrls, NULL, &msgid ); if ( mdn.bv_val != dn->bv_val ) { free( mdn.bv_val ); } - return( ldap_back_op_result( lc, conn, op ) ); + return( ldap_back_op_result( lc, conn, op, msgid, rc ) ); } diff --git a/servers/slapd/back-ldap/modify.c b/servers/slapd/back-ldap/modify.c index 807801b77a..a44915618d 100644 --- a/servers/slapd/back-ldap/modify.c +++ b/servers/slapd/back-ldap/modify.c @@ -60,9 +60,10 @@ ldap_back_modify( LDAPMod **modv = NULL; LDAPMod *mods; Modifications *ml; - int i, j; + int i, j, rc; struct berval mapped; struct berval mdn = { 0, NULL }; + ber_int_t msgid; lc = ldap_back_getconn(li, conn, op); if ( !lc || !ldap_back_dobind( lc, conn, op ) ) { @@ -156,7 +157,7 @@ ldap_back_modify( } modv[i] = 0; - ldap_modify_s( lc->ld, mdn.bv_val, modv ); + rc = ldap_modify_ext( lc->ld, mdn.bv_val, modv, op->o_ctrls, NULL, &msgid ); cleanup:; #ifdef ENABLE_REWRITE @@ -170,6 +171,6 @@ cleanup:; ch_free(modv[i]->mod_bvalues); ch_free(mods); ch_free(modv); - return( ldap_back_op_result( lc, conn, op )); + return( ldap_back_op_result( lc, conn, op, msgid, rc )); } diff --git a/servers/slapd/back-ldap/modrdn.c b/servers/slapd/back-ldap/modrdn.c index 729822d155..1dd14ea1fc 100644 --- a/servers/slapd/back-ldap/modrdn.c +++ b/servers/slapd/back-ldap/modrdn.c @@ -61,6 +61,8 @@ ldap_back_modrdn( { struct ldapinfo *li = (struct ldapinfo *) be->be_private; struct ldapconn *lc; + int rc; + ber_int_t msgid; struct berval mdn = { 0, NULL }, mnewSuperior = { 0, NULL }; @@ -146,7 +148,8 @@ ldap_back_modrdn( ldap_back_dn_massage( li, dn, &mdn, 0, 1 ); #endif /* !ENABLE_REWRITE */ - ldap_rename2_s( lc->ld, mdn.bv_val, newrdn->bv_val, mnewSuperior.bv_val, deleteoldrdn ); + rc = ldap_rename( lc->ld, mdn.bv_val, newrdn->bv_val, mnewSuperior.bv_val, + deleteoldrdn, op->o_ctrls, NULL, &msgid ); if ( mdn.bv_val != dn->bv_val ) { free( mdn.bv_val ); @@ -156,5 +159,5 @@ ldap_back_modrdn( free( mnewSuperior.bv_val ); } - return( ldap_back_op_result( lc, conn, op ) ); + return( ldap_back_op_result( lc, conn, op, msgid, rc ) ); } diff --git a/servers/slapd/back-ldap/search.c b/servers/slapd/back-ldap/search.c index 0b8ef161ac..d4d8051a5d 100644 --- a/servers/slapd/back-ldap/search.c +++ b/servers/slapd/back-ldap/search.c @@ -90,8 +90,6 @@ ldap_back_search( } /* - * controls are set in ldap_back_dobind() - * * FIXME: in case of values return filter, we might want * to map attrs and maybe rewrite value */ @@ -149,10 +147,12 @@ ldap_back_search( /* should we check return values? */ if (deref != -1) ldap_set_option( lc->ld, LDAP_OPT_DEREF, (void *)&deref); - if (tlimit != -1) - ldap_set_option( lc->ld, LDAP_OPT_TIMELIMIT, (void *)&tlimit); - if (slimit != -1) - ldap_set_option( lc->ld, LDAP_OPT_SIZELIMIT, (void *)&slimit); + if (tlimit != -1) { + tv.tv_sec = tlimit; + tv.tv_usec = 0; + } else { + tv.tv_sec = 0; + } /* * Rewrite the search base, if required @@ -260,11 +260,12 @@ ldap_back_search( mapped_attrs[count] = NULL; } - msgid = ldap_search(lc->ld, mbase.bv_val, scope, mapped_filter, - mapped_attrs, attrsonly); - if ( msgid == -1 ) { + rc = ldap_search_ext(lc->ld, mbase.bv_val, scope, mapped_filter, + mapped_attrs, attrsonly, op->o_ctrls, NULL, tv.tv_sec ? &tv + : NULL, slimit, &msgid); + if ( rc != LDAP_SUCCESS ) { fail:; - rc = ldap_back_op_result(lc, conn, op); + rc = ldap_back_op_result(lc, conn, op, msgid, rc); goto finish; } @@ -339,10 +340,10 @@ fail:; } } else { - sres = ldap_result2error(lc->ld, res, 1); + rc = ldap_parse_result(lc->ld, res, &sres, &match, + &err, NULL, NULL, 1); + if (rc != LDAP_SUCCESS ) sres = rc; sres = ldap_back_map_result(sres); - ldap_get_option(lc->ld, LDAP_OPT_ERROR_STRING, &err); - ldap_get_option(lc->ld, LDAP_OPT_MATCHED_DN, &match); rc = 0; break; }