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 },
32 struct berval *reqoid,
33 struct berval *reqdata,
35 struct berval **rspdata,
36 LDAPControl *** rspctrls,
43 for( i=0; exop_table[i].extended != NULL; i++ ) {
44 if( ber_bvcmp( exop_table[i].oid, reqoid ) == 0 ) {
45 return (exop_table[i].extended)(
48 rspoid, rspdata, rspctrls,
53 *text = "not supported within naming context";
54 return LDAP_UNWILLING_TO_PERFORM;
58 ldap_back_exop_passwd(
62 struct berval *reqoid,
63 struct berval *reqdata,
65 struct berval **rspdata,
66 LDAPControl *** rspctrls,
70 struct ldapinfo *li = (struct ldapinfo *) be->be_private;
72 struct berval id = { 0, NULL };
73 struct berval old = { 0, NULL };
74 struct berval new = { 0, NULL };
75 struct berval dn, mdn = { 0, NULL }, newpw;
78 char *msg = NULL, *match = NULL;
81 lc = ldap_back_getconn(li, conn, op);
82 if (!lc || !ldap_back_dobind(li, lc, conn, op) ) {
86 rc = slap_passwd_parse( reqdata, &id, &old, &new, text );
87 if (rc != LDAP_SUCCESS)
97 LDAP_LOG ( ACL, DETAIL1, "ldap_back_exop_passwd: \"%s\"%s\"\n",
98 dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
100 Debug( LDAP_DEBUG_TRACE, "ldap_back_exop_passwd: \"%s\"%s\n",
101 dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
104 if (dn.bv_len == 0) {
105 *text = "No password is associated with the Root DSE";
106 return LDAP_UNWILLING_TO_PERFORM;
109 #ifdef ENABLE_REWRITE
110 switch ( rewrite_session( li->rwinfo, "modifyPwd", dn.bv_val, conn, &mdn.bv_val ) ) {
111 case REWRITE_REGEXEC_OK:
112 if ( mdn.bv_val == NULL ) {
113 mdn.bv_val = dn.bv_val;
115 mdn.bv_len = strlen(mdn.bv_val);
117 LDAP_LOG( BACK_LDAP, DETAIL1,
118 "[rw] modifyPwd: \"%s\" -> \"%s\"\n", dn.bv_val, mdn.bv_val, 0 );
119 #else /* !NEW_LOGGING */
120 Debug( LDAP_DEBUG_ARGS, "rw> modifyPwd: \"%s\" -> \"%s\"\n%s",
121 dn.bv_val, mdn.bv_val, "" );
122 #endif /* !NEW_LOGGING */
125 case REWRITE_REGEXEC_UNWILLING:
126 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM,
127 NULL, "Operation not allowed", NULL, NULL );
130 case REWRITE_REGEXEC_ERR:
131 send_ldap_result( conn, op, LDAP_OTHER,
132 NULL, "Rewrite error", NULL, NULL );
135 #else /* !ENABLE_REWRITE */
136 ldap_back_dn_massage( li, &dn, &mdn, 0, 1 );
137 #endif /* !ENABLE_REWRITE */
140 rc = ldap_passwd(lc->ld, id.bv_len ? &mdn : NULL, old.bv_len ? &old : NULL,
141 new.bv_len ? &new : NULL, op->o_ctrls, NULL, &msgid);
143 if (mdn.bv_val != dn.bv_val) {
147 if (rc == LDAP_SUCCESS) {
148 if (ldap_result(lc->ld, msgid, 1, NULL, &res) == -1) {
149 ldap_get_option(lc->ld, LDAP_OPT_ERROR_NUMBER, &rc);
151 /* sigh. parse twice, because parse_passwd doesn't give
152 * us the err / match / msg info.
155 rc = ldap_parse_result(lc->ld, res, &err, &match, &msg,
157 if (rc == LDAP_SUCCESS) {
158 if (err == LDAP_SUCCESS) {
159 rc = ldap_parse_passwd(lc->ld, res, &newpw);
160 if (rc == LDAP_SUCCESS && newpw.bv_val) {
161 *rspdata = slap_passwd_return(&newpw);
171 if (rc != LDAP_SUCCESS) {
172 rc = ldap_back_map_result(rc);
173 send_ldap_result(conn, op, rc, match, msg, NULL, NULL);
174 if (match) free(match);