1 /* extended.c - ldbm backend extended routines */
4 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/socket.h>
13 #include <ac/string.h>
16 #include "back-ldbm.h"
17 #include "proto-back-ldbm.h"
20 ldbm_back_exop_passwd(
25 struct berval *reqdata,
26 struct berval **rspdata,
30 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
33 struct berval *hash = NULL;
35 struct berval *id = NULL;
36 struct berval *new = NULL;
40 assert( oid != NULL );
41 assert( strcmp( LDAP_EXOP_X_MODIFY_PASSWD, oid ) == 0 );
43 rc = slap_passwd_parse( reqdata,
44 &id, NULL, &new, text );
46 Debug( LDAP_DEBUG_ARGS, "==> ldbm_back_exop_passwd: \"%s\"\n",
47 id ? id->bv_val : "", 0, 0 );
49 if( rc != LDAP_SUCCESS ) {
53 if( new == NULL || new->bv_len == 0 ) {
54 *text = ch_strdup("no password provided");
55 rc = LDAP_OPERATIONS_ERROR;
59 hash = slap_passwd_generate( new );
61 if( hash == NULL || hash->bv_len == 0 ) {
62 *text = ch_strdup("password generation failed");
63 rc = LDAP_OPERATIONS_ERROR;
67 dn = id ? id->bv_val : op->o_dn;
69 Debug( LDAP_DEBUG_TRACE, "passwd: \"%s\"%s\n",
70 dn, id ? " (proxy)" : "", 0 );
72 if( dn == NULL || dn[0] == NULL ) {
73 *text = ch_strdup("No password is associated with the Root DSE");
74 rc = LDAP_OPERATIONS_ERROR;
79 id ? id->bv_val : op->o_dn,
83 *text = ch_strdup("could not locate authorization entry");
84 rc = LDAP_OPERATIONS_ERROR;
88 if( ! access_allowed( be, conn, op, e, "entry", NULL, ACL_WRITE ) ) {
89 *text = ch_strdup("access to authorization entry denied");
90 rc = LDAP_INSUFFICIENT_ACCESS;
94 if( is_entry_alias( e ) ) {
95 /* entry is an alias, don't allow operation */
96 *text = ch_strdup("authorization entry is alias");
97 rc = LDAP_ALIAS_PROBLEM;
101 rc = LDAP_OPERATIONS_ERROR;
103 if( is_entry_referral( e ) ) {
104 /* entry is an referral, don't allow operation */
105 *text = ch_strdup("authorization entry is referral");
111 struct berval *vals[2];
116 ml.ml_type = ch_strdup("userPassword");
117 ml.ml_bvalues = vals;
118 ml.ml_op = LDAP_MOD_REPLACE | LDAP_MOD_BVALUES;
121 rc = ldbm_modify_internal( be,
122 conn, op, op->o_ndn, &ml, e );
127 if( rc == LDAP_SUCCESS ) {
128 /* change the entry itself */
129 if( id2entry_add( be, e ) != 0 ) {
130 rc = LDAP_OPERATIONS_ERROR;
136 cache_return_entry_w( &li->li_cache, e );