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 };
44 assert( reqoid != NULL );
45 assert( strcmp( LDAP_EXOP_MODIFY_PASSWD, reqoid ) == 0 );
47 rc = slap_passwd_parse( reqdata,
48 &id, NULL, &new, text );
50 Debug( LDAP_DEBUG_ARGS, "==> bdb_exop_passwd: \"%s\"\n",
51 id.bv_val ? id.bv_val : "", 0, 0 );
53 if( rc != LDAP_SUCCESS ) {
57 if( new.bv_len == 0 ) {
58 slap_passwd_generate(&new);
60 if( new.bv_len == 0 ) {
61 *text = "password generation failed.";
66 *rspdata = slap_passwd_return( &new );
69 slap_passwd_hash( &new, &hash );
71 if( hash.bv_len == 0 ) {
72 *text = "password hash failed";
83 Debug( LDAP_DEBUG_TRACE, "bdb_exop_passwd: \"%s\"%s\n",
84 dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
86 if( dn.bv_len == 0 ) {
87 *text = "No password is associated with the Root DSE";
88 rc = LDAP_OPERATIONS_ERROR;
92 rc = dnNormalize2( NULL, &dn, &ndn );
93 if( rc != LDAP_SUCCESS ) {
99 retry: /* transaction retry */
101 bdb_cache_delete_entry(&bdb->bi_cache, e);
102 bdb_cache_return_entry_w(&bdb->bi_cache, e);
104 Debug( LDAP_DEBUG_TRACE, "bdb_exop_passwd: retrying...\n", 0, 0, 0 );
105 rc = TXN_ABORT( ltid );
107 op->o_private = NULL;
110 *text = "internal error";
113 ldap_pvt_thread_yield();
116 /* begin transaction */
117 rc = TXN_BEGIN( bdb->bi_dbenv, NULL, <id,
118 bdb->bi_db_opflags );
121 Debug( LDAP_DEBUG_TRACE,
122 "bdb_exop_passwd: txn_begin failed: %s (%d)\n",
123 db_strerror(rc), rc, 0 );
125 *text = "internal error";
130 opinfo.boi_txn = ltid;
132 op->o_private = &opinfo;
135 rc = bdb_dn2entry_w( be, ltid, &ndn, &e, NULL, 0 );
138 case DB_LOCK_DEADLOCK:
139 case DB_LOCK_NOTGRANTED:
146 *text = "internal error";
151 *text = "could not locate authorization entry";
152 rc = LDAP_NO_SUCH_OBJECT;
156 #ifdef BDB_SUBENTRIES
157 if( is_entry_subentries( e ) ) {
158 /* entry is an alias, don't allow operation */
159 *text = "authorization entry is subentry";
165 if( is_entry_alias( e ) ) {
166 /* entry is an alias, don't allow operation */
167 *text = "authorization entry is alias";
168 rc = LDAP_ALIAS_PROBLEM;
173 if( is_entry_referral( e ) ) {
174 /* entry is an referral, don't allow operation */
175 *text = "authorization entry is referral";
182 struct berval vals[2];
185 vals[1].bv_val = NULL;
187 ml.sml_desc = slap_schema.si_ad_userPassword;
188 ml.sml_bvalues = vals;
189 ml.sml_op = LDAP_MOD_REPLACE;
192 rc = bdb_modify_internal( be, conn, op, ltid,
193 &ml, e, text, textbuf, textlen );
196 case DB_LOCK_DEADLOCK:
197 case DB_LOCK_NOTGRANTED:
204 *text = "entry modify failed";
208 /* change the entry itself */
209 rc = bdb_id2entry_update( be, ltid, e );
212 case DB_LOCK_DEADLOCK:
213 case DB_LOCK_NOTGRANTED:
216 *text = "entry update failed";
222 rc = TXN_ABORT( ltid );
224 rc = TXN_COMMIT( ltid, 0 );
228 op->o_private = NULL;
230 if( rc == LDAP_SUCCESS ) {
231 replog( be, op, &e->e_name, &e->e_nname, &ml );
237 bdb_cache_return_entry_w( &bdb->bi_cache, e );
240 if( hash.bv_val != NULL ) {
246 op->o_private = NULL;