1 /* passwd.c - bdb backend password routines */
4 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
11 #include <ac/string.h>
22 struct berval *reqdata,
24 struct berval **rspdata,
25 LDAPControl *** rspctrls,
29 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
32 struct berval hash = { 0, NULL };
34 struct bdb_op_info opinfo;
35 char textbuf[SLAP_TEXT_BUFLEN];
36 size_t textlen = sizeof textbuf;
38 struct berval id = { 0, NULL };
39 struct berval new = { 0, NULL };
43 assert( reqoid != NULL );
44 assert( strcmp( LDAP_EXOP_X_MODIFY_PASSWD, reqoid ) == 0 );
46 rc = slap_passwd_parse( reqdata,
47 &id, NULL, &new, text );
49 Debug( LDAP_DEBUG_ARGS, "==> bdb_exop_passwd: \"%s\"\n",
50 id.bv_val ? id.bv_val : "", 0, 0 );
52 if( rc != LDAP_SUCCESS ) {
56 if( new.bv_len == 0 ) {
57 slap_passwd_generate(&new);
59 if( new.bv_len == 0 ) {
60 *text = "password generation failed.";
65 *rspdata = slap_passwd_return( &new );
68 slap_passwd_hash( &new, &hash );
70 if( hash.bv_len == 0 ) {
71 *text = "password hash failed";
76 dn = id.bv_val ? &id : &op->o_dn;
78 Debug( LDAP_DEBUG_TRACE, "bdb_exop_passwd: \"%s\"%s\n",
79 dn->bv_val, id.bv_val ? " (proxy)" : "", 0 );
81 if( dn->bv_len == 0 ) {
82 *text = "No password is associated with the Root DSE";
83 rc = LDAP_OPERATIONS_ERROR;
88 retry: /* transaction retry */
90 bdb_cache_delete_entry(&bdb->bi_cache, e);
91 bdb_cache_return_entry_w(&bdb->bi_cache, e);
93 Debug( LDAP_DEBUG_TRACE, "bdb_exop_passwd: retrying...\n", 0, 0, 0 );
94 rc = txn_abort( ltid );
99 *text = "internal error";
102 ldap_pvt_thread_yield();
106 /* begin transaction */
107 rc = txn_begin( bdb->bi_dbenv, NULL, <id,
108 bdb->bi_db_opflags );
111 Debug( LDAP_DEBUG_TRACE,
112 "bdb_exop_passwd: txn_begin failed: %s (%d)\n",
113 db_strerror(rc), rc, 0 );
115 *text = "internal error";
121 opinfo.boi_txn = ltid;
123 op->o_private = &opinfo;
126 rc = bdb_dn2entry_w( be, ltid, dn, &e, NULL, 0 );
129 case DB_LOCK_DEADLOCK:
130 case DB_LOCK_NOTGRANTED:
137 *text = "internal error";
142 *text = "could not locate authorization entry";
143 rc = LDAP_NO_SUCH_OBJECT;
147 if( is_entry_alias( e ) ) {
148 /* entry is an alias, don't allow operation */
149 *text = "authorization entry is alias";
150 rc = LDAP_ALIAS_PROBLEM;
155 if( is_entry_referral( e ) ) {
156 /* entry is an referral, don't allow operation */
157 *text = "authorization entry is referral";
158 rc = LDAP_OPERATIONS_ERROR;
164 struct berval vals[2];
167 vals[1].bv_val = NULL;
169 ml.sml_desc = slap_schema.si_ad_userPassword;
170 ml.sml_bvalues = vals;
171 ml.sml_op = LDAP_MOD_REPLACE;
174 rc = bdb_modify_internal( be, conn, op, ltid,
175 &ml, e, text, textbuf, textlen );
178 case DB_LOCK_DEADLOCK:
179 case DB_LOCK_NOTGRANTED:
186 *text = "entry modify failed";
190 /* change the entry itself */
191 rc = bdb_id2entry_update( be, ltid, e );
194 case DB_LOCK_DEADLOCK:
195 case DB_LOCK_NOTGRANTED:
198 *text = "entry update failed";
202 if( bdb->bi_txn && rc == 0 ) {
203 rc = txn_commit( ltid, 0 );
206 op->o_private = NULL;
208 if( rc == LDAP_SUCCESS ) {
209 replog( be, op, &e->e_name, &e->e_nname, &ml );
215 bdb_cache_return_entry_w( &bdb->bi_cache, e );
218 if( hash.bv_val != NULL ) {
224 op->o_private = NULL;