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 #ifdef SLAPD_SCHEMA_NOT_COMPAT
44 AttributeDescription *entry = slap_schema.si_ad_entry;
46 static const char *entry = "entry";
49 assert( reqoid != NULL );
50 assert( strcmp( LDAP_EXOP_X_MODIFY_PASSWD, reqoid ) == 0 );
52 rc = slap_passwd_parse( reqdata,
53 &id, NULL, &new, text );
55 Debug( LDAP_DEBUG_ARGS, "==> ldbm_back_exop_passwd: \"%s\"\n",
56 id ? id->bv_val : "", 0, 0 );
58 if( rc != LDAP_SUCCESS ) {
62 if( new == NULL || new->bv_len == 0 ) {
63 new = slap_passwd_generate();
65 if( new == NULL || new->bv_len == 0 ) {
66 *text = "password generation failed.";
71 *rspdata = slap_passwd_return( new );
74 hash = slap_passwd_hash( new );
76 if( hash == NULL || hash->bv_len == 0 ) {
77 *text = "password hash failed";
82 dn = id ? id->bv_val : op->o_dn;
84 Debug( LDAP_DEBUG_TRACE, "passwd: \"%s\"%s\n",
85 dn, id ? " (proxy)" : "", 0 );
87 if( dn == NULL || dn[0] == '\0' ) {
88 *text = "No password is associated with the Root DSE";
89 rc = LDAP_OPERATIONS_ERROR;
93 e = dn2entry_w( be, dn, NULL );
96 *text = "could not locate authorization entry";
97 rc = LDAP_OPERATIONS_ERROR;
101 if( ! access_allowed( be, conn, op, e, entry, NULL, ACL_WRITE ) ) {
102 *text = "access to authorization entry denied";
103 rc = LDAP_INSUFFICIENT_ACCESS;
107 if( is_entry_alias( e ) ) {
108 /* entry is an alias, don't allow operation */
109 *text = "authorization entry is alias";
110 rc = LDAP_ALIAS_PROBLEM;
114 rc = LDAP_OPERATIONS_ERROR;
116 if( is_entry_referral( e ) ) {
117 /* entry is an referral, don't allow operation */
118 *text = "authorization entry is referral";
124 struct berval *vals[2];
129 #ifdef SLAPD_SCHEMA_NOT_COMPAT
130 ml.sml_desc = slap_schema.si_ad_userPassword;
132 ml.sml_type = ch_strdup("userPassword");
134 ml.sml_bvalues = vals;
135 ml.sml_op = LDAP_MOD_REPLACE;
138 rc = ldbm_modify_internal( be,
139 conn, op, op->o_ndn, &ml, e, text );
141 #ifndef SLAPD_SCHEMA_NOT_COMPAT
146 if( rc == LDAP_SUCCESS ) {
147 /* change the entry itself */
148 if( id2entry_add( be, e ) != 0 ) {
149 *text = "entry update failed";
156 cache_return_entry_w( &li->li_cache, e );