1 /* extended.c - ldbm backend extended routines */
4 * Copyright 1998-2000 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,
27 struct berval **rspdata,
28 LDAPControl *** rspctrls,
30 struct berval *** refs
33 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
36 struct berval *hash = NULL;
38 struct berval *id = NULL;
39 struct berval *new = NULL;
43 AttributeDescription *entry = slap_schema.si_ad_entry;
45 assert( reqoid != NULL );
46 assert( strcmp( LDAP_EXOP_X_MODIFY_PASSWD, reqoid ) == 0 );
48 rc = slap_passwd_parse( reqdata,
49 &id, NULL, &new, text );
51 Debug( LDAP_DEBUG_ARGS, "==> ldbm_back_exop_passwd: \"%s\"\n",
52 id ? id->bv_val : "", 0, 0 );
54 if( rc != LDAP_SUCCESS ) {
58 if( new == NULL || new->bv_len == 0 ) {
59 new = slap_passwd_generate();
61 if( new == NULL || new->bv_len == 0 ) {
62 *text = "password generation failed.";
67 *rspdata = slap_passwd_return( new );
70 hash = slap_passwd_hash( new );
72 if( hash == NULL || hash->bv_len == 0 ) {
73 *text = "password hash failed";
78 dn = id ? id->bv_val : op->o_dn;
80 Debug( LDAP_DEBUG_TRACE, "passwd: \"%s\"%s\n",
81 dn, id ? " (proxy)" : "", 0 );
83 if( dn == NULL || dn[0] == '\0' ) {
84 *text = "No password is associated with the Root DSE";
85 rc = LDAP_OPERATIONS_ERROR;
89 e = dn2entry_w( be, dn, NULL );
92 *text = "could not locate authorization entry";
93 rc = LDAP_OPERATIONS_ERROR;
97 if( ! access_allowed( be, conn, op, e, entry, NULL, ACL_WRITE ) ) {
98 *text = "access to authorization entry denied";
99 rc = LDAP_INSUFFICIENT_ACCESS;
103 if( is_entry_alias( e ) ) {
104 /* entry is an alias, don't allow operation */
105 *text = "authorization entry is alias";
106 rc = LDAP_ALIAS_PROBLEM;
110 rc = LDAP_OPERATIONS_ERROR;
112 if( is_entry_referral( e ) ) {
113 /* entry is an referral, don't allow operation */
114 *text = "authorization entry is referral";
120 struct berval *vals[2];
125 ml.sml_desc = slap_schema.si_ad_userPassword;
126 ml.sml_bvalues = vals;
127 ml.sml_op = LDAP_MOD_REPLACE;
130 rc = ldbm_modify_internal( be,
131 conn, op, op->o_ndn, &ml, e, text );
135 if( rc == LDAP_SUCCESS ) {
136 /* change the entry itself */
137 if( id2entry_add( be, e ) != 0 ) {
138 *text = "entry update failed";
145 cache_return_entry_w( &li->li_cache, e );