/* extended.c - ldap backend extended routines */
/* $OpenLDAP$ */
-/*
- * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 2003-2005 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
+ */
+/* ACKNOWLEDGEMENTS:
+ * This work was initially developed by the Howard Chu for inclusion
+ * in OpenLDAP Software and subsequently enhanced by Pierangelo
+ * Masarati.
*/
#include "portable.h"
BI_op_extended ldap_back_exop_passwd;
static struct exop {
- struct berval *oid;
+ struct berval oid;
BI_op_extended *extended;
} exop_table[] = {
- { (struct berval *)&slap_EXOP_MODIFY_PASSWD, ldap_back_exop_passwd },
- { NULL, NULL }
+ { BER_BVC(LDAP_EXOP_MODIFY_PASSWD), ldap_back_exop_passwd },
+ { BER_BVNULL, NULL }
};
int
ldap_back_extended(
- Backend *be,
- Connection *conn,
- Operation *op,
- struct berval *reqoid,
- struct berval *reqdata,
- char **rspoid,
- struct berval **rspdata,
- LDAPControl *** rspctrls,
- const char** text,
- BerVarray *refs
-)
+ Operation *op,
+ SlapReply *rs )
{
- int i;
-
- for( i=0; exop_table[i].extended != NULL; i++ ) {
- if( ber_bvcmp( exop_table[i].oid, reqoid ) == 0 ) {
- return (exop_table[i].extended)(
- be, conn, op,
- reqoid, reqdata,
- rspoid, rspdata, rspctrls,
- text, refs );
+ int i;
+
+ for ( i = 0; exop_table[i].extended != NULL; i++ ) {
+ if ( bvmatch( &exop_table[i].oid, &op->oq_extended.rs_reqoid ) )
+ {
+ ldapconn_t *lc;
+ LDAPControl **oldctrls = NULL;
+ int rc;
+
+ /* FIXME: this needs to be called here, so it is
+ * called twice; maybe we could avoid the
+ * ldap_back_dobind() call inside each extended()
+ * call ... */
+ lc = ldap_back_getconn( op, rs, LDAP_BACK_SENDERR );
+ if ( !lc || !ldap_back_dobind( lc, op, rs, LDAP_BACK_SENDERR ) ) {
+ return -1;
+ }
+
+ oldctrls = op->o_ctrls;
+ if ( ldap_back_proxy_authz_ctrl( lc, op, rs,
+ &op->o_ctrls ) )
+ {
+ op->o_ctrls = oldctrls;
+ send_ldap_result( op, rs );
+ rs->sr_text = NULL;
+ rc = rs->sr_err;
+ goto done;
+ }
+
+ rc = ( *exop_table[i].extended )( op, rs );
+
+ if ( op->o_ctrls && op->o_ctrls != oldctrls ) {
+ free( op->o_ctrls[ 0 ] );
+ free( op->o_ctrls );
+ }
+ op->o_ctrls = oldctrls;
+
+done:;
+ if ( lc != NULL ) {
+ ldap_back_release_conn( op, rs, lc );
+ }
+
+ return rc;
}
}
- *text = "not supported within naming context";
+ rs->sr_text = "not supported within naming context";
return LDAP_UNWILLING_TO_PERFORM;
}
int
ldap_back_exop_passwd(
- Backend *be,
- Connection *conn,
- Operation *op,
- struct berval *reqoid,
- struct berval *reqdata,
- char **rspoid,
- struct berval **rspdata,
- LDAPControl *** rspctrls,
- const char **text,
- BerVarray *refs )
+ Operation *op,
+ SlapReply *rs )
{
- struct ldapinfo *li = (struct ldapinfo *) be->be_private;
- struct ldapconn *lc;
- struct berval id = { 0, NULL };
- struct berval old = { 0, NULL };
- struct berval new = { 0, NULL };
- struct berval dn, mdn = { 0, NULL }, newpw;
- LDAPMessage *res;
- ber_int_t msgid;
- char *msg = NULL, *match = NULL;
- int rc;
-
- lc = ldap_back_getconn(li, conn, op);
- if (!lc || !ldap_back_dobind(li, lc, conn, op) ) {
+ ldapconn_t *lc;
+ req_pwdexop_s *qpw = &op->oq_pwdexop;
+ LDAPMessage *res;
+ ber_int_t msgid;
+ int rc, isproxy;
+ int do_retry = 1;
+
+ lc = ldap_back_getconn( op, rs, LDAP_BACK_SENDERR );
+ if ( !lc || !ldap_back_dobind( lc, op, rs, LDAP_BACK_SENDERR ) ) {
return -1;
}
- rc = slap_passwd_parse( reqdata, &id, &old, &new, text );
- if (rc != LDAP_SUCCESS)
- return rc;
-
- if (id.bv_len) {
- dn = id;
- } else {
- dn = op->o_dn;
- }
+ isproxy = ber_bvcmp( &op->o_req_ndn, &op->o_ndn );
-#ifdef NEW_LOGGING
- LDAP_LOG ( ACL, DETAIL1, "ldap_back_exop_passwd: \"%s\"%s\"\n",
- dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
-#else
- Debug( LDAP_DEBUG_TRACE, "ldap_back_exop_passwd: \"%s\"%s\n",
- dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
-#endif
-
- if (dn.bv_len == 0) {
- *text = "No password is associated with the Root DSE";
- return LDAP_UNWILLING_TO_PERFORM;
- }
- if (id.bv_len) {
-#ifdef ENABLE_REWRITE
- switch ( rewrite_session( li->rwinfo, "modifyPwd", dn.bv_val, conn, &mdn.bv_val ) ) {
- case REWRITE_REGEXEC_OK:
- if ( mdn.bv_val == NULL ) {
- mdn.bv_val = dn.bv_val;
- }
- mdn.bv_len = strlen(mdn.bv_val);
-#ifdef NEW_LOGGING
- LDAP_LOG( BACK_LDAP, DETAIL1,
- "[rw] modifyPwd: \"%s\" -> \"%s\"\n", dn.bv_val, mdn.bv_val, 0 );
-#else /* !NEW_LOGGING */
- Debug( LDAP_DEBUG_ARGS, "rw> modifyPwd: \"%s\" -> \"%s\"\n%s",
- dn.bv_val, mdn.bv_val, "" );
-#endif /* !NEW_LOGGING */
- break;
-
- case REWRITE_REGEXEC_UNWILLING:
- send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM,
- NULL, "Operation not allowed", NULL, NULL );
- return( -1 );
-
- case REWRITE_REGEXEC_ERR:
- send_ldap_result( conn, op, LDAP_OTHER,
- NULL, "Rewrite error", NULL, NULL );
- return( -1 );
- }
-#else /* !ENABLE_REWRITE */
- ldap_back_dn_massage( li, &dn, &mdn, 0, 1 );
-#endif /* !ENABLE_REWRITE */
- }
+ Debug( LDAP_DEBUG_ARGS, "==> ldap_back_exop_passwd(\"%s\")%s\n",
+ op->o_req_dn.bv_val, isproxy ? " (proxy)" : "", 0 );
+
+retry:
+ rc = ldap_passwd( lc->lc_ld, isproxy ? &op->o_req_dn : NULL,
+ qpw->rs_old.bv_val ? &qpw->rs_old : NULL,
+ qpw->rs_new.bv_val ? &qpw->rs_new : NULL,
+ op->o_ctrls, NULL, &msgid );
+
+ if ( rc == LDAP_SUCCESS ) {
+ if ( ldap_result( lc->lc_ld, msgid, LDAP_MSG_ALL, NULL, &res ) == -1 ) {
+ ldap_get_option( lc->lc_ld, LDAP_OPT_ERROR_NUMBER, &rc );
+ ldap_back_freeconn( op, lc, 0 );
+ lc = NULL;
- rc = ldap_passwd(lc->ld, id.bv_len ? &mdn : NULL, old.bv_len ? &old : NULL,
- new.bv_len ? &new : NULL, op->o_ctrls, NULL, &msgid);
-#ifdef ENABLE_REWRITE
- if (mdn.bv_val != dn.bv_val)
-#endif
- free(mdn.bv_val);
- if (rc == LDAP_SUCCESS) {
- if (ldap_result(lc->ld, msgid, 1, NULL, &res) == -1) {
- ldap_get_option(lc->ld, LDAP_OPT_ERROR_NUMBER, &rc);
} else {
- /* sigh. parse twice, because parse_passwd doesn't give
- * us the err / match / msg info.
+ /* sigh. parse twice, because parse_passwd
+ * doesn't give us the err / match / msg info.
*/
- int err;
- rc = ldap_parse_result(lc->ld, res, &err, &match, &msg,
- NULL, NULL, 0);
- if (rc == LDAP_SUCCESS) {
- if (err == LDAP_SUCCESS) {
- rc = ldap_parse_passwd(lc->ld, res, &newpw);
- if (rc == LDAP_SUCCESS && newpw.bv_val) {
- *rspdata = slap_passwd_return(&newpw);
- free(newpw.bv_val);
+ rc = ldap_parse_result( lc->lc_ld, res, &rs->sr_err,
+ (char **)&rs->sr_matched,
+ (char **)&rs->sr_text,
+ NULL, NULL, 0 );
+#ifndef LDAP_NULL_IS_NULL
+ if ( rs->sr_matched && rs->sr_matched[ 0 ] == '\0' ) {
+ free( (char *)rs->sr_matched );
+ rs->sr_matched = NULL;
+ }
+ if ( rs->sr_text && rs->sr_text[ 0 ] == '\0' ) {
+ free( (char *)rs->sr_text );
+ rs->sr_text = NULL;
+ }
+#endif /* LDAP_NULL_IS_NULL */
+ if ( rc == LDAP_SUCCESS ) {
+ if ( rs->sr_err == LDAP_SUCCESS ) {
+ struct berval newpw;
+
+ rc = ldap_parse_passwd( lc->lc_ld, res,
+ &newpw);
+ if ( rc == LDAP_SUCCESS &&
+ !BER_BVISNULL( &newpw ) )
+ {
+ rs->sr_type = REP_EXTENDED;
+ rs->sr_rspdata = slap_passwd_return( &newpw );
+ free( newpw.bv_val );
}
+
} else {
- rc = err;
+ rc = rs->sr_err;
}
}
- ldap_msgfree(res);
+ ldap_msgfree( res );
}
}
- if (rc != LDAP_SUCCESS) {
- rc = ldap_back_map_result(rc);
- send_ldap_result(conn, op, rc, match, msg, NULL, NULL);
- if (match) free(match);
- if (msg) free(msg);
+ if ( rc != LDAP_SUCCESS ) {
+ rs->sr_err = slap_map_api2result( rs );
+ if ( rs->sr_err == LDAP_UNAVAILABLE && do_retry ) {
+ do_retry = 0;
+ if ( ldap_back_retry( &lc, op, rs, LDAP_BACK_SENDERR ) ) {
+ goto retry;
+ }
+ }
+ send_ldap_result( op, rs );
rc = -1;
}
+
+ /* these have to be freed anyway... */
+ if ( rs->sr_matched ) {
+ free( (char *)rs->sr_matched );
+ rs->sr_matched = NULL;
+ }
+ if ( rs->sr_text ) {
+ free( (char *)rs->sr_text );
+ rs->sr_text = NULL;
+ }
+
+ if ( lc != NULL ) {
+ ldap_back_release_conn( op, rs, lc );
+ }
+
return rc;
}