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 );
49 if( rc != LDAP_SUCCESS ) {
53 if( new.bv_len == 0 ) {
54 slap_passwd_generate(&new);
56 if( new.bv_len == 0 ) {
57 rs->sr_text = "password generation failed.";
62 rs->sr_rspdata = slap_passwd_return( &new );
65 slap_passwd_hash( &new, &hash, &rs->sr_text );
67 if( hash.bv_len == 0 ) {
68 if( !rs->sr_text ) rs->sr_text = "password hash failed";
80 LDAP_LOG( BACK_LDBM, DETAIL1,
81 "ldbm_back_exop_passwd: \"%s\"%s\n",
82 dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
84 Debug( LDAP_DEBUG_TRACE, "passwd: \"%s\"%s\n",
85 dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
88 if( dn.bv_len == 0 ) {
89 rs->sr_text = "No password is associated with the Root DSE";
90 rc = LDAP_UNWILLING_TO_PERFORM;
94 rc = dnNormalize( 0, NULL, NULL, &dn, &ndn, op->o_tmpmemctx );
95 if( rc != LDAP_SUCCESS ) {
96 rs->sr_text = "Invalid DN";
100 /* grab giant lock for writing */
101 ldap_pvt_thread_rdwr_wlock(&li->li_giant_rwlock);
103 e = dn2entry_w( op->o_bd, &ndn, NULL );
105 if ( e == NULL || is_entry_glue( e )) {
106 /* FIXME : dn2entry() should return non-glue entry */
107 ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);
108 rs->sr_text = "could not locate authorization entry";
109 rc = LDAP_NO_SUCH_OBJECT;
113 #ifdef LDBM_SUBENTRIES
114 if( is_entry_subentry( e ) ) {
115 /* entry is a subentry, don't allow operation */
116 rs->sr_text = "authorization entry is subentry";
122 if( is_entry_alias( e ) ) {
123 /* entry is an alias, don't allow operation */
124 rs->sr_text = "authorization entry is alias";
125 rc = LDAP_ALIAS_PROBLEM;
131 if( is_entry_referral( e ) ) {
132 /* entry is an referral, don't allow operation */
133 rs->sr_text = "authorization entry is referral";
139 struct berval vals[2];
140 char textbuf[SLAP_TEXT_BUFLEN]; /* non-returnable */
143 vals[1].bv_val = NULL;
145 ml.sml_desc = slap_schema.si_ad_userPassword;
146 ml.sml_values = vals;
147 ml.sml_nvalues = vals;
148 ml.sml_op = LDAP_MOD_REPLACE;
151 rc = ldbm_modify_internal( op,
152 &ml, e, &rs->sr_text, textbuf,
155 /* FIXME: ldbm_modify_internal may set *text = textbuf,
157 if ( rs->sr_text == textbuf ) {
162 /* cannot return textbuf */
163 rs->sr_text = "entry modify failed";
167 /* change the entry itself */
168 if( id2entry_add( op->o_bd, e ) != 0 ) {
169 rs->sr_text = "entry update failed";
173 if( rc == LDAP_SUCCESS ) {
180 cache_return_entry_w( &li->li_cache, e );
181 ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);
184 if( hash.bv_val != NULL ) {
188 if( ndn.bv_val != NULL ) {
189 op->o_tmpfree( ndn.bv_val, op->o_tmpmemctx );