1 /* passwd.c - bdb backend password routines */
4 * Copyright 1998-2003 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 };
47 assert( reqoid != NULL );
48 assert( strcmp( LDAP_EXOP_MODIFY_PASSWD, reqoid ) == 0 );
50 rc = slap_passwd_parse( reqdata,
51 &id, NULL, &new, text );
54 LDAP_LOG ( ACL, ENTRY,
55 "==>bdb_exop_passwd: \"%s\"\n", id.bv_val ? id.bv_val : "", 0, 0 );
57 Debug( LDAP_DEBUG_ARGS, "==> bdb_exop_passwd: \"%s\"\n",
58 id.bv_val ? id.bv_val : "", 0, 0 );
61 if( rc != LDAP_SUCCESS ) {
65 if( new.bv_len == 0 ) {
66 slap_passwd_generate(&new);
68 if( new.bv_len == 0 ) {
69 *text = "password generation failed.";
74 *rspdata = slap_passwd_return( &new );
77 slap_passwd_hash( &new, &hash );
79 if( hash.bv_len == 0 ) {
80 *text = "password hash failed";
92 LDAP_LOG ( ACL, DETAIL1, "bdb_exop_passwd: \"%s\"%s\"\n",
93 dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
95 Debug( LDAP_DEBUG_TRACE, "bdb_exop_passwd: \"%s\"%s\n",
96 dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
99 if( dn.bv_len == 0 ) {
100 *text = "No password is associated with the Root DSE";
101 rc = LDAP_UNWILLING_TO_PERFORM;
105 rc = dnNormalize2( NULL, &dn, &ndn );
106 if( rc != LDAP_SUCCESS ) {
107 *text = "Invalid DN";
112 retry: /* transaction retry */
114 bdb_cache_delete_entry(&bdb->bi_cache, e);
115 bdb_unlocked_cache_return_entry_w(&bdb->bi_cache, e);
118 LDAP_LOG ( ACL, DETAIL1, "bdb_exop_passwd: retrying...\n", 0, 0, 0 );
120 Debug( LDAP_DEBUG_TRACE, "bdb_exop_passwd: retrying...\n", 0, 0, 0 );
122 rc = TXN_ABORT( ltid );
124 op->o_private = NULL;
125 op->o_do_not_cache = opinfo.boi_acl_cache;
128 *text = "internal error";
131 ldap_pvt_thread_yield();
134 /* begin transaction */
135 rc = TXN_BEGIN( bdb->bi_dbenv, NULL, <id,
136 bdb->bi_db_opflags );
141 "bdb_exop_passwd: txn_begin failed: %s (%d)\n",
142 db_strerror(rc), rc, 0 );
144 Debug( LDAP_DEBUG_TRACE,
145 "bdb_exop_passwd: txn_begin failed: %s (%d)\n",
146 db_strerror(rc), rc, 0 );
149 *text = "internal error";
153 locker = TXN_ID ( ltid );
156 opinfo.boi_txn = ltid;
157 opinfo.boi_locker = locker;
159 opinfo.boi_acl_cache = op->o_do_not_cache;
160 op->o_private = &opinfo;
163 rc = bdb_dn2entry_w( be, ltid, &ndn, &e, NULL, 0 , locker, &lock);
166 case DB_LOCK_DEADLOCK:
167 case DB_LOCK_NOTGRANTED:
173 *text = "ldap server busy";
177 *text = "internal error";
182 *text = "could not locate authorization entry";
183 rc = LDAP_NO_SUCH_OBJECT;
187 #ifdef BDB_SUBENTRIES
188 if( is_entry_subentry( e ) ) {
189 /* entry is an alias, don't allow operation */
190 *text = "authorization entry is subentry";
196 if( is_entry_alias( e ) ) {
197 /* entry is an alias, don't allow operation */
198 *text = "authorization entry is alias";
199 rc = LDAP_ALIAS_PROBLEM;
204 if( is_entry_referral( e ) ) {
205 /* entry is an referral, don't allow operation */
206 *text = "authorization entry is referral";
213 struct berval vals[2];
216 vals[1].bv_val = NULL;
218 ml.sml_desc = slap_schema.si_ad_userPassword;
219 ml.sml_bvalues = vals;
220 ml.sml_op = LDAP_MOD_REPLACE;
223 rc = bdb_modify_internal( be, conn, op, ltid,
224 &ml, e, text, textbuf, textlen );
226 if ( (rc == LDAP_INSUFFICIENT_ACCESS) && opinfo.boi_err ) {
230 case DB_LOCK_DEADLOCK:
231 case DB_LOCK_NOTGRANTED:
239 *text = "entry modify failed";
243 /* change the entry itself */
244 rc = bdb_id2entry_update( be, ltid, e );
247 case DB_LOCK_DEADLOCK:
248 case DB_LOCK_NOTGRANTED:
251 *text = "entry update failed";
257 rc = TXN_ABORT( ltid );
259 rc = TXN_COMMIT( ltid, 0 );
263 op->o_private = NULL;
265 if( rc == LDAP_SUCCESS ) {
266 replog( be, op, &e->e_name, &e->e_nname, &ml );
272 bdb_unlocked_cache_return_entry_w( &bdb->bi_cache, e );
275 if( hash.bv_val != NULL ) {
281 op->o_private = NULL;