1 /* extended.c - ldap backend extended routines */
4 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
11 #include <ac/string.h>
14 #include "back-ldap.h"
17 BI_op_extended ldap_back_exop_passwd;
21 BI_op_extended *extended;
23 { (struct berval *)&slap_EXOP_MODIFY_PASSWD, ldap_back_exop_passwd },
34 for( i=0; exop_table[i].extended != NULL; i++ ) {
35 if( ber_bvcmp( exop_table[i].oid, &op->oq_extended.rs_reqoid ) == 0 ) {
36 return (exop_table[i].extended)( op, rs );
40 rs->sr_text = "not supported within naming context";
41 return LDAP_UNWILLING_TO_PERFORM;
45 ldap_back_exop_passwd(
49 struct ldapinfo *li = (struct ldapinfo *) op->o_bd->be_private;
51 struct berval id = { 0, NULL };
52 struct berval old = { 0, NULL };
53 struct berval new = { 0, NULL };
54 struct berval dn, mdn = { 0, NULL }, newpw;
60 lc = ldap_back_getconn(op, rs);
61 if (!lc || !ldap_back_dobind(lc, op, rs) ) {
65 rc = slap_passwd_parse( op->oq_extended.rs_reqdata, &id, &old, &new, &rs->sr_text );
66 if (rc != LDAP_SUCCESS)
76 LDAP_LOG ( ACL, DETAIL1, "ldap_back_exop_passwd: \"%s\"%s\"\n",
77 dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
79 Debug( LDAP_DEBUG_TRACE, "ldap_back_exop_passwd: \"%s\"%s\n",
80 dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
84 rs->sr_text = "No password is associated with the Root DSE";
85 return LDAP_UNWILLING_TO_PERFORM;
88 dc.rwmap = &li->rwmap;
97 if ( ldap_back_dn_massage( &dc, &dn, &mdn ) ) {
98 send_ldap_result( op, rs );
103 rc = ldap_passwd(lc->ld, id.bv_len ? &mdn : NULL, old.bv_len ? &old : NULL,
104 new.bv_len ? &new : NULL, op->o_ctrls, NULL, &msgid);
106 if (mdn.bv_val != dn.bv_val) {
110 if (rc == LDAP_SUCCESS) {
111 if (ldap_result(lc->ld, msgid, 1, NULL, &res) == -1) {
112 ldap_get_option(lc->ld, LDAP_OPT_ERROR_NUMBER, &rc);
114 /* sigh. parse twice, because parse_passwd doesn't give
115 * us the err / match / msg info.
117 rc = ldap_parse_result(lc->ld, res, &rs->sr_err, (char **)&rs->sr_matched, (char **)&rs->sr_text,
119 if (rc == LDAP_SUCCESS) {
120 if (rs->sr_err == LDAP_SUCCESS) {
121 rc = ldap_parse_passwd(lc->ld, res, &newpw);
122 if (rc == LDAP_SUCCESS && newpw.bv_val) {
123 rs->sr_type = REP_EXTENDED;
124 rs->sr_rspdata = slap_passwd_return(&newpw);
134 if (rc != LDAP_SUCCESS) {
135 rs->sr_err = ldap_back_map_result(rs);
136 send_ldap_result(op, rs);
137 if (rs->sr_matched) free((char *)rs->sr_matched);
138 if (rs->sr_text) free((char *)rs->sr_text);
139 rs->sr_matched = NULL;