1 /* extended.c - ldap backend extended routines */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2003-2006 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was initially developed by the Howard Chu for inclusion
18 * in OpenLDAP Software and subsequently enhanced by Pierangelo
25 #include <ac/string.h>
28 #include "back-ldap.h"
31 static BI_op_extended ldap_back_exop_passwd;
32 static BI_op_extended ldap_back_exop_generic;
36 BI_op_extended *extended;
38 { BER_BVC(LDAP_EXOP_MODIFY_PASSWD), ldap_back_exop_passwd },
43 ldap_back_extended_one( Operation *op, SlapReply *rs, BI_op_extended exop )
45 ldapinfo_t *li = (ldapinfo_t *) op->o_bd->be_private;
48 LDAPControl **oldctrls = NULL;
51 /* FIXME: this needs to be called here, so it is
52 * called twice; maybe we could avoid the
53 * ldap_back_dobind() call inside each extended()
55 lc = ldap_back_getconn( op, rs, LDAP_BACK_SENDERR );
56 if ( !lc || !ldap_back_dobind( lc, op, rs, LDAP_BACK_SENDERR ) ) {
60 oldctrls = op->o_ctrls;
61 if ( ldap_back_proxy_authz_ctrl( &lc->lc_bound_ndn,
62 li->li_version, &li->li_idassert, op, rs, &op->o_ctrls ) )
64 op->o_ctrls = oldctrls;
65 send_ldap_extended( op, rs );
67 /* otherwise frontend resends result */
68 rc = rs->sr_err = SLAPD_ABANDON;
74 if ( op->o_ctrls && op->o_ctrls != oldctrls ) {
75 free( op->o_ctrls[ 0 ] );
78 op->o_ctrls = oldctrls;
82 ldap_back_release_conn( op, rs, lc );
95 for ( i = 0; exop_table[i].extended != NULL; i++ ) {
96 if ( bvmatch( &exop_table[i].oid, &op->oq_extended.rs_reqoid ) )
98 return ldap_back_extended_one( op, rs, exop_table[i].extended );
102 /* if we get here, the exop is known; the best that we can do
103 * is pass it thru as is */
104 /* FIXME: maybe a list of OIDs to pass thru would be safer */
105 return ldap_back_extended_one( op, rs, ldap_back_exop_generic );
109 ldap_back_exop_passwd(
113 ldapinfo_t *li = (ldapinfo_t *) op->o_bd->be_private;
116 req_pwdexop_s *qpw = &op->oq_pwdexop;
123 lc = ldap_back_getconn( op, rs, LDAP_BACK_SENDERR );
124 if ( !lc || !ldap_back_dobind( lc, op, rs, LDAP_BACK_SENDERR ) ) {
128 isproxy = ber_bvcmp( &op->o_req_ndn, &op->o_ndn );
130 Debug( LDAP_DEBUG_ARGS, "==> ldap_back_exop_passwd(\"%s\")%s\n",
131 op->o_req_dn.bv_val, isproxy ? " (proxy)" : "", 0 );
134 rc = ldap_passwd( lc->lc_ld, isproxy ? &op->o_req_dn : NULL,
135 qpw->rs_old.bv_val ? &qpw->rs_old : NULL,
136 qpw->rs_new.bv_val ? &qpw->rs_new : NULL,
137 op->o_ctrls, NULL, &msgid );
139 if ( rc == LDAP_SUCCESS ) {
140 if ( ldap_result( lc->lc_ld, msgid, LDAP_MSG_ALL, NULL, &res ) == -1 ) {
141 ldap_get_option( lc->lc_ld, LDAP_OPT_ERROR_NUMBER, &rc );
145 /* sigh. parse twice, because parse_passwd
146 * doesn't give us the err / match / msg info.
148 rc = ldap_parse_result( lc->lc_ld, res, &rs->sr_err,
149 (char **)&rs->sr_matched,
153 if ( rc == LDAP_SUCCESS ) {
154 if ( rs->sr_err == LDAP_SUCCESS ) {
157 /* this never happens because
158 * the frontend is generating
159 * the new password, so when
160 * the passwd exop is proxied,
161 * it never delegates password
162 * generation to the remote server
164 rc = ldap_parse_passwd( lc->lc_ld, res,
166 if ( rc == LDAP_SUCCESS &&
167 !BER_BVISNULL( &newpw ) )
169 rs->sr_type = REP_EXTENDED;
170 rs->sr_rspdata = slap_passwd_return( &newpw );
171 free( newpw.bv_val );
182 if ( rc != LDAP_SUCCESS ) {
183 rs->sr_err = slap_map_api2result( rs );
184 if ( rs->sr_err == LDAP_UNAVAILABLE && do_retry ) {
186 if ( ldap_back_retry( &lc, op, rs, LDAP_BACK_SENDERR ) ) {
191 if ( LDAP_BACK_QUARANTINE( li ) ) {
192 ldap_back_quarantine( op, rs );
195 if ( text ) rs->sr_text = text;
196 send_ldap_extended( op, rs );
197 /* otherwise frontend resends result */
198 rc = rs->sr_err = SLAPD_ABANDON;
200 } else if ( LDAP_BACK_QUARANTINE( li ) ) {
201 ldap_back_quarantine( op, rs );
204 /* these have to be freed anyway... */
205 if ( rs->sr_matched ) {
206 free( (char *)rs->sr_matched );
207 rs->sr_matched = NULL;
216 ldap_back_release_conn( op, rs, lc );
223 ldap_back_exop_generic(
227 ldapinfo_t *li = (ldapinfo_t *) op->o_bd->be_private;
236 lc = ldap_back_getconn( op, rs, LDAP_BACK_SENDERR );
237 if ( !lc || !ldap_back_dobind( lc, op, rs, LDAP_BACK_SENDERR ) ) {
241 Debug( LDAP_DEBUG_ARGS, "==> ldap_back_exop_generic(%s, \"%s\")\n",
242 op->ore_reqoid.bv_val, op->o_req_dn.bv_val, 0 );
245 rc = ldap_extended_operation( lc->lc_ld,
246 op->ore_reqoid.bv_val, op->ore_reqdata,
247 op->o_ctrls, NULL, &msgid );
249 if ( rc == LDAP_SUCCESS ) {
250 if ( ldap_result( lc->lc_ld, msgid, LDAP_MSG_ALL, NULL, &res ) == -1 ) {
251 ldap_get_option( lc->lc_ld, LDAP_OPT_ERROR_NUMBER, &rc );
255 /* sigh. parse twice, because parse_passwd
256 * doesn't give us the err / match / msg info.
258 rc = ldap_parse_result( lc->lc_ld, res, &rs->sr_err,
259 (char **)&rs->sr_matched,
262 if ( rc == LDAP_SUCCESS ) {
263 if ( rs->sr_err == LDAP_SUCCESS ) {
264 rc = ldap_parse_extended_result( lc->lc_ld, res,
265 (char **)&rs->sr_rspoid, &rs->sr_rspdata, 0 );
266 if ( rc == LDAP_SUCCESS ) {
267 rs->sr_type = REP_EXTENDED;
278 if ( rc != LDAP_SUCCESS ) {
279 rs->sr_err = slap_map_api2result( rs );
280 if ( rs->sr_err == LDAP_UNAVAILABLE && do_retry ) {
282 if ( ldap_back_retry( &lc, op, rs, LDAP_BACK_SENDERR ) ) {
287 if ( LDAP_BACK_QUARANTINE( li ) ) {
288 ldap_back_quarantine( op, rs );
291 if ( text ) rs->sr_text = text;
292 send_ldap_extended( op, rs );
293 /* otherwise frontend resends result */
294 rc = rs->sr_err = SLAPD_ABANDON;
296 } else if ( LDAP_BACK_QUARANTINE( li ) ) {
297 ldap_back_quarantine( op, rs );
300 /* these have to be freed anyway... */
301 if ( rs->sr_matched ) {
302 free( (char *)rs->sr_matched );
303 rs->sr_matched = NULL;
312 ldap_back_release_conn( op, rs, lc );