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,
27 LDAPControl *** rspctrls,
31 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
34 struct berval *hash = NULL;
36 struct berval *id = NULL;
37 struct berval *new = NULL;
41 assert( oid != NULL );
42 assert( strcmp( LDAP_EXOP_X_MODIFY_PASSWD, oid ) == 0 );
44 rc = slap_passwd_parse( reqdata,
45 &id, NULL, &new, text );
47 Debug( LDAP_DEBUG_ARGS, "==> ldbm_back_exop_passwd: \"%s\"\n",
48 id ? id->bv_val : "", 0, 0 );
50 if( rc != LDAP_SUCCESS ) {
54 if( new == NULL || new->bv_len == 0 ) {
55 new = slap_passwd_generate();
57 if( new == NULL || new->bv_len == 0 ) {
58 *text = ch_strdup("password generation failed.");
59 rc = LDAP_OPERATIONS_ERROR;
63 *rspdata = slap_passwd_return( new );
66 hash = slap_passwd_hash( new );
68 if( hash == NULL || hash->bv_len == 0 ) {
69 *text = ch_strdup("password hash failed");
70 rc = LDAP_OPERATIONS_ERROR;
74 dn = id ? id->bv_val : op->o_dn;
76 Debug( LDAP_DEBUG_TRACE, "passwd: \"%s\"%s\n",
77 dn, id ? " (proxy)" : "", 0 );
79 if( dn == NULL || dn[0] == NULL ) {
80 *text = ch_strdup("No password is associated with the Root DSE");
81 rc = LDAP_OPERATIONS_ERROR;
85 e = dn2entry_w( be, dn, NULL );
88 *text = ch_strdup("could not locate authorization entry");
89 rc = LDAP_OPERATIONS_ERROR;
93 if( ! access_allowed( be, conn, op, e, "entry", NULL, ACL_WRITE ) ) {
94 *text = ch_strdup("access to authorization entry denied");
95 rc = LDAP_INSUFFICIENT_ACCESS;
99 if( is_entry_alias( e ) ) {
100 /* entry is an alias, don't allow operation */
101 *text = ch_strdup("authorization entry is alias");
102 rc = LDAP_ALIAS_PROBLEM;
106 rc = LDAP_OPERATIONS_ERROR;
108 if( is_entry_referral( e ) ) {
109 /* entry is an referral, don't allow operation */
110 *text = ch_strdup("authorization entry is referral");
116 struct berval *vals[2];
121 ml.ml_type = ch_strdup("userPassword");
122 ml.ml_bvalues = vals;
123 ml.ml_op = LDAP_MOD_REPLACE | LDAP_MOD_BVALUES;
126 rc = ldbm_modify_internal( be,
127 conn, op, op->o_ndn, &ml, e );
132 if( rc == LDAP_SUCCESS ) {
133 /* change the entry itself */
134 if( id2entry_add( be, e ) != 0 ) {
135 rc = LDAP_OPERATIONS_ERROR;
141 cache_return_entry_w( &li->li_cache, e );