they will be interleaved in LDAP*. Avoid setting any options on the handle.
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 );
}
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]);
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
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,
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
*/
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 */
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;
}
}
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
/*
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 ) ) {
}
}
- 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 ) );
}
{
struct ldapinfo *li = (struct ldapinfo *) be->be_private;
struct ldapconn *lc;
+ int rc;
+ ber_int_t msgid;
struct berval mdn = { 0, NULL };
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 ) );
}
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 ) ) {
}
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
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 ));
}
{
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 };
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 );
free( mnewSuperior.bv_val );
}
- return( ldap_back_op_result( lc, conn, op ) );
+ return( ldap_back_op_result( lc, conn, op, msgid, rc ) );
}
}
/*
- * controls are set in ldap_back_dobind()
- *
* FIXME: in case of values return filter, we might want
* to map attrs and maybe rewrite value
*/
/* 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
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;
}
}
} 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;
}