2003-02-16 17:22:44 +08:00
|
|
|
/* extended.c - ldap backend extended routines */
|
|
|
|
/* $OpenLDAP$ */
|
2003-11-27 14:35:14 +08:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2005-01-02 04:49:32 +08:00
|
|
|
* Copyright 2003-2005 The OpenLDAP Foundation.
|
2003-11-27 14:35:14 +08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
|
|
|
*
|
|
|
|
* A copy of this license is available in the file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
2003-02-16 17:22:44 +08:00
|
|
|
*/
|
2003-11-27 14:35:14 +08:00
|
|
|
/* ACKNOWLEDGEMENTS:
|
|
|
|
* This work was initially developed by the Howard Chu for inclusion
|
|
|
|
* in OpenLDAP Software and subsequently enhanced by Pierangelo
|
|
|
|
* Masarati.
|
|
|
|
*/
|
2003-02-16 17:22:44 +08:00
|
|
|
|
|
|
|
#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 {
|
2005-08-26 10:17:13 +08:00
|
|
|
struct berval oid;
|
2003-02-16 17:22:44 +08:00
|
|
|
BI_op_extended *extended;
|
|
|
|
} exop_table[] = {
|
2005-08-26 10:17:13 +08:00
|
|
|
{ BER_BVC(LDAP_EXOP_MODIFY_PASSWD), ldap_back_exop_passwd },
|
|
|
|
{ BER_BVNULL, NULL }
|
2003-02-16 17:22:44 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
int
|
|
|
|
ldap_back_extended(
|
2004-11-13 22:43:30 +08:00
|
|
|
Operation *op,
|
|
|
|
SlapReply *rs )
|
2003-02-16 17:22:44 +08:00
|
|
|
{
|
2004-11-13 22:43:30 +08:00
|
|
|
int i;
|
2003-02-16 17:22:44 +08:00
|
|
|
|
2004-11-13 22:43:30 +08:00
|
|
|
for ( i = 0; exop_table[i].extended != NULL; i++ ) {
|
2005-08-26 10:17:13 +08:00
|
|
|
if ( bvmatch( &exop_table[i].oid, &op->oq_extended.rs_reqoid ) )
|
2004-11-13 22:43:30 +08:00
|
|
|
{
|
2005-11-19 23:00:50 +08:00
|
|
|
ldapconn_t *lc;
|
2004-11-13 22:43:30 +08:00
|
|
|
LDAPControl **oldctrls = NULL;
|
|
|
|
int rc;
|
2003-12-01 16:04:51 +08:00
|
|
|
|
|
|
|
/* FIXME: this needs to be called here, so it is
|
|
|
|
* called twice; maybe we could avoid the
|
|
|
|
* ldap_back_dobind() call inside each extended()
|
|
|
|
* call ... */
|
2005-01-24 17:38:11 +08:00
|
|
|
lc = ldap_back_getconn( op, rs, LDAP_BACK_SENDERR );
|
|
|
|
if ( !lc || !ldap_back_dobind( lc, op, rs, LDAP_BACK_SENDERR ) ) {
|
2003-12-01 16:04:51 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
oldctrls = op->o_ctrls;
|
2004-11-13 22:43:30 +08:00
|
|
|
if ( ldap_back_proxy_authz_ctrl( lc, op, rs,
|
|
|
|
&op->o_ctrls ) )
|
|
|
|
{
|
2003-12-01 16:04:51 +08:00
|
|
|
op->o_ctrls = oldctrls;
|
|
|
|
send_ldap_result( op, rs );
|
|
|
|
rs->sr_text = NULL;
|
2005-06-30 00:38:09 +08:00
|
|
|
rc = rs->sr_err;
|
|
|
|
goto done;
|
2003-12-01 16:04:51 +08:00
|
|
|
}
|
|
|
|
|
2004-11-13 22:43:30 +08:00
|
|
|
rc = ( *exop_table[i].extended )( op, rs );
|
2003-12-01 16:04:51 +08:00
|
|
|
|
|
|
|
if ( op->o_ctrls && op->o_ctrls != oldctrls ) {
|
|
|
|
free( op->o_ctrls[ 0 ] );
|
|
|
|
free( op->o_ctrls );
|
|
|
|
}
|
|
|
|
op->o_ctrls = oldctrls;
|
|
|
|
|
2005-06-30 00:38:09 +08:00
|
|
|
done:;
|
|
|
|
if ( lc != NULL ) {
|
|
|
|
ldap_back_release_conn( op, rs, lc );
|
|
|
|
}
|
|
|
|
|
2003-12-01 16:04:51 +08:00
|
|
|
return rc;
|
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(
|
2004-11-13 22:43:30 +08:00
|
|
|
Operation *op,
|
|
|
|
SlapReply *rs )
|
2003-02-16 17:22:44 +08:00
|
|
|
{
|
2005-11-19 23:00:50 +08:00
|
|
|
ldapconn_t *lc;
|
2004-11-13 22:43:30 +08:00
|
|
|
req_pwdexop_s *qpw = &op->oq_pwdexop;
|
|
|
|
LDAPMessage *res;
|
|
|
|
ber_int_t msgid;
|
|
|
|
int rc, isproxy;
|
|
|
|
int do_retry = 1;
|
|
|
|
|
2005-01-24 17:38:11 +08:00
|
|
|
lc = ldap_back_getconn( op, rs, LDAP_BACK_SENDERR );
|
|
|
|
if ( !lc || !ldap_back_dobind( lc, op, rs, LDAP_BACK_SENDERR ) ) {
|
2003-02-16 17:22:44 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2004-03-01 03:04:34 +08:00
|
|
|
isproxy = ber_bvcmp( &op->o_req_ndn, &op->o_ndn );
|
2003-02-16 17:22:44 +08:00
|
|
|
|
2004-11-13 22:43:30 +08:00
|
|
|
Debug( LDAP_DEBUG_ARGS, "==> ldap_back_exop_passwd(\"%s\")%s\n",
|
2004-03-01 03:04:34 +08:00
|
|
|
op->o_req_dn.bv_val, isproxy ? " (proxy)" : "", 0 );
|
2003-02-16 17:22:44 +08:00
|
|
|
|
2004-10-01 19:16:38 +08:00
|
|
|
retry:
|
2004-11-13 22:43:30 +08:00
|
|
|
rc = ldap_passwd( lc->lc_ld, isproxy ? &op->o_req_dn : NULL,
|
2004-04-06 07:47:17 +08:00
|
|
|
qpw->rs_old.bv_val ? &qpw->rs_old : NULL,
|
|
|
|
qpw->rs_new.bv_val ? &qpw->rs_new : NULL,
|
2004-11-13 22:43:30 +08:00
|
|
|
op->o_ctrls, NULL, &msgid );
|
2003-03-12 02:09:38 +08:00
|
|
|
|
2004-11-13 22:43:30 +08:00
|
|
|
if ( rc == LDAP_SUCCESS ) {
|
|
|
|
if ( ldap_result( lc->lc_ld, msgid, 1, NULL, &res ) == -1 ) {
|
|
|
|
ldap_get_option( lc->lc_ld, LDAP_OPT_ERROR_NUMBER, &rc );
|
2005-11-19 23:00:50 +08:00
|
|
|
ldap_back_freeconn( op, lc, 0 );
|
2004-07-05 07:35:18 +08:00
|
|
|
lc = NULL;
|
|
|
|
|
2003-02-16 17:22:44 +08:00
|
|
|
} else {
|
2004-11-13 22:43:30 +08:00
|
|
|
/* sigh. parse twice, because parse_passwd
|
|
|
|
* doesn't give us the err / match / msg info.
|
2003-02-16 17:22:44 +08:00
|
|
|
*/
|
2004-11-13 22:43:30 +08:00
|
|
|
rc = ldap_parse_result( lc->lc_ld, res, &rs->sr_err,
|
|
|
|
(char **)&rs->sr_matched,
|
|
|
|
(char **)&rs->sr_text,
|
|
|
|
NULL, NULL, 0 );
|
2005-11-20 09:59:26 +08:00
|
|
|
#ifndef LDAP_NULL_IS_NULL
|
2005-11-03 19:58:06 +08:00
|
|
|
if ( rs->sr_matched && rs->sr_matched[ 0 ] == '\0' ) {
|
|
|
|
free( (char *)rs->sr_matched );
|
2005-11-04 05:48:46 +08:00
|
|
|
rs->sr_matched = NULL;
|
2005-11-03 19:58:06 +08:00
|
|
|
}
|
|
|
|
if ( rs->sr_text && rs->sr_text[ 0 ] == '\0' ) {
|
|
|
|
free( (char *)rs->sr_text );
|
2005-11-04 05:48:46 +08:00
|
|
|
rs->sr_text = NULL;
|
2005-11-03 19:58:06 +08:00
|
|
|
}
|
2005-11-20 09:59:26 +08:00
|
|
|
#endif /* LDAP_NULL_IS_NULL */
|
2004-11-13 22:43:30 +08:00
|
|
|
if ( rc == LDAP_SUCCESS ) {
|
|
|
|
if ( rs->sr_err == LDAP_SUCCESS ) {
|
|
|
|
struct berval newpw;
|
|
|
|
|
|
|
|
rc = ldap_parse_passwd( lc->lc_ld, res,
|
|
|
|
&newpw);
|
|
|
|
if ( rc == LDAP_SUCCESS &&
|
|
|
|
!BER_BVISNULL( &newpw ) )
|
|
|
|
{
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_type = REP_EXTENDED;
|
2004-11-13 22:43:30 +08:00
|
|
|
rs->sr_rspdata = slap_passwd_return( &newpw );
|
|
|
|
free( newpw.bv_val );
|
2003-02-16 17:22:44 +08:00
|
|
|
}
|
2004-11-13 22:43:30 +08:00
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2004-11-13 22:43:30 +08:00
|
|
|
ldap_msgfree( res );
|
2003-02-16 17:22:44 +08:00
|
|
|
}
|
|
|
|
}
|
2004-11-13 22:43:30 +08:00
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
2004-04-06 01:36:53 +08:00
|
|
|
rs->sr_err = slap_map_api2result( rs );
|
2004-10-01 19:16:38 +08:00
|
|
|
if ( rs->sr_err == LDAP_UNAVAILABLE && do_retry ) {
|
|
|
|
do_retry = 0;
|
2005-11-19 23:00:50 +08:00
|
|
|
if ( ldap_back_retry( &lc, op, rs, LDAP_BACK_SENDERR ) ) {
|
2004-11-13 22:43:30 +08:00
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
send_ldap_result( op, rs );
|
2003-02-16 17:22:44 +08:00
|
|
|
rc = -1;
|
|
|
|
}
|
2004-10-01 19:16:38 +08:00
|
|
|
|
2005-11-03 19:58:06 +08:00
|
|
|
/* these have to be freed anyway... */
|
|
|
|
if ( rs->sr_matched ) {
|
|
|
|
free( (char *)rs->sr_matched );
|
2005-11-04 05:48:46 +08:00
|
|
|
rs->sr_matched = NULL;
|
2005-11-03 19:58:06 +08:00
|
|
|
}
|
|
|
|
if ( rs->sr_text ) {
|
|
|
|
free( (char *)rs->sr_text );
|
2005-11-04 05:48:46 +08:00
|
|
|
rs->sr_text = NULL;
|
2005-11-03 19:58:06 +08:00
|
|
|
}
|
|
|
|
|
2005-06-30 00:38:09 +08:00
|
|
|
if ( lc != NULL ) {
|
|
|
|
ldap_back_release_conn( op, rs, lc );
|
|
|
|
}
|
|
|
|
|
2003-02-16 17:22:44 +08:00
|
|
|
return rc;
|
|
|
|
}
|