1 /* extended.c - ldap backend extended routines */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2003 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
21 /* This is an altered version */
26 #include <ac/string.h>
29 #include "back-ldap.h"
32 BI_op_extended ldap_back_exop_passwd;
36 BI_op_extended *extended;
38 { (struct berval *)&slap_EXOP_MODIFY_PASSWD, ldap_back_exop_passwd },
49 for( i=0; exop_table[i].extended != NULL; i++ ) {
50 if( ber_bvcmp( exop_table[i].oid, &op->oq_extended.rs_reqoid ) == 0 ) {
51 return (exop_table[i].extended)( op, rs );
55 rs->sr_text = "not supported within naming context";
56 return LDAP_UNWILLING_TO_PERFORM;
60 ldap_back_exop_passwd(
64 struct ldapinfo *li = (struct ldapinfo *) op->o_bd->be_private;
66 struct berval id = { 0, NULL };
67 struct berval old = { 0, NULL };
68 struct berval new = { 0, NULL };
69 struct berval dn, mdn = { 0, NULL }, newpw;
75 lc = ldap_back_getconn(op, rs);
76 if (!lc || !ldap_back_dobind(lc, op, rs) ) {
80 rc = slap_passwd_parse( op->oq_extended.rs_reqdata, &id, &old, &new, &rs->sr_text );
81 if (rc != LDAP_SUCCESS)
91 LDAP_LOG ( ACL, DETAIL1, "ldap_back_exop_passwd: \"%s\"%s\"\n",
92 dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
94 Debug( LDAP_DEBUG_TRACE, "ldap_back_exop_passwd: \"%s\"%s\n",
95 dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
99 rs->sr_text = "No password is associated with the Root DSE";
100 return LDAP_UNWILLING_TO_PERFORM;
103 dc.rwmap = &li->rwmap;
104 #ifdef ENABLE_REWRITE
105 dc.conn = op->o_conn;
107 dc.ctx = "modifyPwd";
112 if ( ldap_back_dn_massage( &dc, &dn, &mdn ) ) {
113 send_ldap_result( op, rs );
118 rc = ldap_passwd(lc->ld, id.bv_len ? &mdn : NULL, old.bv_len ? &old : NULL,
119 new.bv_len ? &new : NULL, op->o_ctrls, NULL, &msgid);
121 if (mdn.bv_val != dn.bv_val) {
125 if (rc == LDAP_SUCCESS) {
126 if (ldap_result(lc->ld, msgid, 1, NULL, &res) == -1) {
127 ldap_get_option(lc->ld, LDAP_OPT_ERROR_NUMBER, &rc);
129 /* sigh. parse twice, because parse_passwd doesn't give
130 * us the err / match / msg info.
132 rc = ldap_parse_result(lc->ld, res, &rs->sr_err, (char **)&rs->sr_matched, (char **)&rs->sr_text,
134 if (rc == LDAP_SUCCESS) {
135 if (rs->sr_err == LDAP_SUCCESS) {
136 rc = ldap_parse_passwd(lc->ld, res, &newpw);
137 if (rc == LDAP_SUCCESS && newpw.bv_val) {
138 rs->sr_type = REP_EXTENDED;
139 rs->sr_rspdata = slap_passwd_return(&newpw);
149 if (rc != LDAP_SUCCESS) {
150 rs->sr_err = ldap_back_map_result(rs);
151 send_ldap_result(op, rs);
152 if (rs->sr_matched) free((char *)rs->sr_matched);
153 if (rs->sr_text) free((char *)rs->sr_text);
154 rs->sr_matched = NULL;