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;
59 lc = ldap_back_getconn(op, rs);
60 if (!lc || !ldap_back_dobind(lc, op, rs) ) {
64 rc = slap_passwd_parse( op->oq_extended.rs_reqdata, &id, &old, &new, &rs->sr_text );
65 if (rc != LDAP_SUCCESS)
75 LDAP_LOG ( ACL, DETAIL1, "ldap_back_exop_passwd: \"%s\"%s\"\n",
76 dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
78 Debug( LDAP_DEBUG_TRACE, "ldap_back_exop_passwd: \"%s\"%s\n",
79 dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
83 rs->sr_text = "No password is associated with the Root DSE";
84 return LDAP_UNWILLING_TO_PERFORM;
88 switch ( rewrite_session( li->rwinfo, "modifyPwd", dn.bv_val, op->o_conn, &mdn.bv_val ) ) {
89 case REWRITE_REGEXEC_OK:
90 if ( mdn.bv_val == NULL ) {
91 mdn.bv_val = dn.bv_val;
93 mdn.bv_len = strlen(mdn.bv_val);
95 LDAP_LOG( BACK_LDAP, DETAIL1,
96 "[rw] modifyPwd: \"%s\" -> \"%s\"\n", dn.bv_val, mdn.bv_val, 0 );
97 #else /* !NEW_LOGGING */
98 Debug( LDAP_DEBUG_ARGS, "rw> modifyPwd: \"%s\" -> \"%s\"\n%s",
99 dn.bv_val, mdn.bv_val, "" );
100 #endif /* !NEW_LOGGING */
103 case REWRITE_REGEXEC_UNWILLING:
104 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
105 "Operation not allowed" );
108 case REWRITE_REGEXEC_ERR:
109 send_ldap_error( op, rs, LDAP_OTHER,
113 #else /* !ENABLE_REWRITE */
114 ldap_back_dn_massage( li, &dn, &mdn, 0, 1 );
115 #endif /* !ENABLE_REWRITE */
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(rc);
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;