2003-02-16 17:22:44 +08:00
|
|
|
/* extended.c - ldap backend extended routines */
|
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/*
|
|
|
|
* Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
|
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
|
|
|
|
#include "slap.h"
|
|
|
|
#include "back-ldap.h"
|
|
|
|
#include "lber_pvt.h"
|
|
|
|
|
|
|
|
BI_op_extended ldap_back_exop_passwd;
|
|
|
|
|
|
|
|
static struct exop {
|
|
|
|
struct berval *oid;
|
|
|
|
BI_op_extended *extended;
|
|
|
|
} exop_table[] = {
|
|
|
|
{ (struct berval *)&slap_EXOP_MODIFY_PASSWD, ldap_back_exop_passwd },
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
int
|
|
|
|
ldap_back_extended(
|
|
|
|
Operation *op,
|
2003-03-30 17:03:54 +08:00
|
|
|
SlapReply *rs )
|
2003-02-16 17:22:44 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for( i=0; exop_table[i].extended != NULL; i++ ) {
|
2003-03-30 17:03:54 +08:00
|
|
|
if( ber_bvcmp( exop_table[i].oid, &op->oq_extended.rs_reqoid ) == 0 ) {
|
|
|
|
return (exop_table[i].extended)( op, rs );
|
2003-02-16 17:22:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_text = "not supported within naming context";
|
2003-02-16 17:22:44 +08:00
|
|
|
return LDAP_UNWILLING_TO_PERFORM;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ldap_back_exop_passwd(
|
|
|
|
Operation *op,
|
2003-03-30 17:03:54 +08:00
|
|
|
SlapReply *rs )
|
2003-02-16 17:22:44 +08:00
|
|
|
{
|
2003-03-30 17:03:54 +08:00
|
|
|
struct ldapinfo *li = (struct ldapinfo *) op->o_bd->be_private;
|
2003-02-16 17:22:44 +08:00
|
|
|
struct ldapconn *lc;
|
|
|
|
struct berval id = { 0, NULL };
|
|
|
|
struct berval old = { 0, NULL };
|
|
|
|
struct berval new = { 0, NULL };
|
2003-02-16 17:42:04 +08:00
|
|
|
struct berval dn, mdn = { 0, NULL }, newpw;
|
2003-02-16 17:22:44 +08:00
|
|
|
LDAPMessage *res;
|
|
|
|
ber_int_t msgid;
|
|
|
|
int rc;
|
2003-04-07 18:15:18 +08:00
|
|
|
dncookie dc;
|
2003-02-16 17:22:44 +08:00
|
|
|
|
2003-04-04 07:23:56 +08:00
|
|
|
lc = ldap_back_getconn(op, rs);
|
|
|
|
if (!lc || !ldap_back_dobind(lc, op, rs) ) {
|
2003-02-16 17:22:44 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
rc = slap_passwd_parse( op->oq_extended.rs_reqdata, &id, &old, &new, &rs->sr_text );
|
2003-02-16 17:22:44 +08:00
|
|
|
if (rc != LDAP_SUCCESS)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
if (id.bv_len) {
|
|
|
|
dn = id;
|
|
|
|
} else {
|
|
|
|
dn = op->o_dn;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NEW_LOGGING
|
|
|
|
LDAP_LOG ( ACL, DETAIL1, "ldap_back_exop_passwd: \"%s\"%s\"\n",
|
|
|
|
dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
|
|
|
|
#else
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "ldap_back_exop_passwd: \"%s\"%s\n",
|
|
|
|
dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (dn.bv_len == 0) {
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_text = "No password is associated with the Root DSE";
|
2003-02-16 17:22:44 +08:00
|
|
|
return LDAP_UNWILLING_TO_PERFORM;
|
|
|
|
}
|
|
|
|
if (id.bv_len) {
|
2003-04-07 18:15:18 +08:00
|
|
|
dc.li = li;
|
2003-02-16 17:22:44 +08:00
|
|
|
#ifdef ENABLE_REWRITE
|
2003-04-07 18:15:18 +08:00
|
|
|
dc.conn = op->o_conn;
|
|
|
|
dc.rs = rs;
|
|
|
|
dc.ctx = "modifyPwd";
|
|
|
|
#else
|
|
|
|
dc.tofrom = 1;
|
|
|
|
dc.normalized = 0;
|
|
|
|
#endif
|
|
|
|
if ( ldap_back_dn_massage( &dc, &dn, &mdn ) ) {
|
|
|
|
send_ldap_result( op, rs );
|
|
|
|
return -1;
|
2003-02-16 17:22:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = ldap_passwd(lc->ld, id.bv_len ? &mdn : NULL, old.bv_len ? &old : NULL,
|
|
|
|
new.bv_len ? &new : NULL, op->o_ctrls, NULL, &msgid);
|
2003-03-12 02:09:38 +08:00
|
|
|
|
|
|
|
if (mdn.bv_val != dn.bv_val) {
|
2003-02-16 17:22:44 +08:00
|
|
|
free(mdn.bv_val);
|
2003-03-12 02:09:38 +08:00
|
|
|
}
|
|
|
|
|
2003-02-16 17:22:44 +08:00
|
|
|
if (rc == LDAP_SUCCESS) {
|
|
|
|
if (ldap_result(lc->ld, msgid, 1, NULL, &res) == -1) {
|
|
|
|
ldap_get_option(lc->ld, LDAP_OPT_ERROR_NUMBER, &rc);
|
|
|
|
} else {
|
|
|
|
/* sigh. parse twice, because parse_passwd doesn't give
|
|
|
|
* us the err / match / msg info.
|
|
|
|
*/
|
2003-03-30 17:03:54 +08:00
|
|
|
rc = ldap_parse_result(lc->ld, res, &rs->sr_err, (char **)&rs->sr_matched, (char **)&rs->sr_text,
|
2003-02-16 17:22:44 +08:00
|
|
|
NULL, NULL, 0);
|
|
|
|
if (rc == LDAP_SUCCESS) {
|
2003-03-30 17:03:54 +08:00
|
|
|
if (rs->sr_err == LDAP_SUCCESS) {
|
2003-02-16 17:22:44 +08:00
|
|
|
rc = ldap_parse_passwd(lc->ld, res, &newpw);
|
2003-02-16 17:42:04 +08:00
|
|
|
if (rc == LDAP_SUCCESS && newpw.bv_val) {
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_type = REP_EXTENDED;
|
|
|
|
rs->sr_rspdata = slap_passwd_return(&newpw);
|
2003-02-16 17:42:04 +08:00
|
|
|
free(newpw.bv_val);
|
2003-02-16 17:22:44 +08:00
|
|
|
}
|
|
|
|
} else {
|
2003-03-30 17:03:54 +08:00
|
|
|
rc = rs->sr_err;
|
2003-02-16 17:22:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ldap_msgfree(res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rc != LDAP_SUCCESS) {
|
2003-04-05 06:20:49 +08:00
|
|
|
rs->sr_err = ldap_back_map_result(rs);
|
2003-03-30 17:03:54 +08:00
|
|
|
send_ldap_result(op, rs);
|
|
|
|
if (rs->sr_matched) free((char *)rs->sr_matched);
|
|
|
|
if (rs->sr_text) free((char *)rs->sr_text);
|
|
|
|
rs->sr_matched = NULL;
|
|
|
|
rs->sr_text = NULL;
|
2003-02-16 17:22:44 +08:00
|
|
|
rc = -1;
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|