1 /* passwd.c - ldbm backend password routines */
4 * Copyright 1998-2003 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"
21 ldbm_back_exop_passwd(
25 struct ldbminfo *li = (struct ldbminfo *) op->o_bd->be_private;
28 struct berval hash = { 0, NULL };
30 struct berval id = { 0, NULL };
31 struct berval new = { 0, NULL };
33 struct berval dn = { 0, NULL };
34 struct berval ndn = { 0, NULL };
36 assert( ber_bvcmp( &slap_EXOP_MODIFY_PASSWD, &op->oq_extended.rs_reqoid ) == 0 );
38 rc = slap_passwd_parse( op->oq_extended.rs_reqdata,
39 &id, NULL, &new, &rs->sr_text );
42 LDAP_LOG( BACK_LDBM, ENTRY,
43 "ldbm_back_exop_passwd: \"%s\"\n", id.bv_val ? id.bv_val : "", 0,0 );
45 Debug( LDAP_DEBUG_ARGS, "==> ldbm_back_exop_passwd: \"%s\"\n",
46 id.bv_val ? id.bv_val : "", 0, 0 );
50 if( rc != LDAP_SUCCESS ) {
54 if( new.bv_len == 0 ) {
55 slap_passwd_generate(&new);
57 if( new.bv_len == 0 ) {
58 rs->sr_text = "password generation failed.";
63 rs->sr_rspdata = slap_passwd_return( &new );
66 slap_passwd_hash( &new, &hash );
68 if( hash.bv_len == 0 ) {
69 rs->sr_text = "password hash failed";
81 LDAP_LOG( BACK_LDBM, DETAIL1,
82 "ldbm_back_exop_passwd: \"%s\"%s\n",
83 dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
85 Debug( LDAP_DEBUG_TRACE, "passwd: \"%s\"%s\n",
86 dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
89 if( dn.bv_len == 0 ) {
90 rs->sr_text = "No password is associated with the Root DSE";
91 rc = LDAP_UNWILLING_TO_PERFORM;
95 rc = dnNormalize2( NULL, &dn, &ndn );
96 if( rc != LDAP_SUCCESS ) {
97 rs->sr_text = "Invalid DN";
101 /* grab giant lock for writing */
102 ldap_pvt_thread_rdwr_wlock(&li->li_giant_rwlock);
104 e = dn2entry_w( op->o_bd, &ndn, NULL );
106 ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);
107 rs->sr_text = "could not locate authorization entry";
108 rc = LDAP_NO_SUCH_OBJECT;
112 if( is_entry_alias( e ) ) {
113 /* entry is an alias, don't allow operation */
114 rs->sr_text = "authorization entry is alias";
115 rc = LDAP_ALIAS_PROBLEM;
121 if( is_entry_referral( e ) ) {
122 /* entry is an referral, don't allow operation */
123 rs->sr_text = "authorization entry is referral";
129 struct berval vals[2];
130 char textbuf[SLAP_TEXT_BUFLEN]; /* non-returnable */
133 vals[1].bv_val = NULL;
135 ml.sml_desc = slap_schema.si_ad_userPassword;
136 ml.sml_values = vals;
137 ml.sml_nvalues = vals;
138 ml.sml_op = LDAP_MOD_REPLACE;
141 rc = ldbm_modify_internal( op,
142 &ml, e, &rs->sr_text, textbuf,
145 /* FIXME: ldbm_modify_internal may set *text = textbuf,
147 if ( rs->sr_text == textbuf ) {
152 /* cannot return textbuf */
153 rs->sr_text = "entry modify failed";
157 /* change the entry itself */
158 if( id2entry_add( op->o_bd, e ) != 0 ) {
159 rs->sr_text = "entry update failed";
163 if( rc == LDAP_SUCCESS ) {
170 cache_return_entry_w( &li->li_cache, e );
171 ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);
174 if( hash.bv_val != NULL ) {
178 if( ndn.bv_val != NULL ) {