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 *reqoid,
23 struct berval *reqdata,
25 struct berval **rspdata,
26 LDAPControl *** rspctrls,
30 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
33 struct berval hash = { 0, NULL };
35 struct bdb_op_info opinfo;
36 char textbuf[SLAP_TEXT_BUFLEN];
37 size_t textlen = sizeof textbuf;
39 struct berval id = { 0, NULL };
40 struct berval new = { 0, NULL };
48 assert( reqoid != NULL );
49 assert( ber_bvcmp( &slap_EXOP_MODIFY_PASSWD, reqoid ) == 0 );
51 rc = slap_passwd_parse( reqdata,
52 &id, NULL, &new, text );
55 LDAP_LOG ( ACL, ENTRY,
56 "==>bdb_exop_passwd: \"%s\"\n", id.bv_val ? id.bv_val : "", 0, 0 );
58 Debug( LDAP_DEBUG_ARGS, "==> bdb_exop_passwd: \"%s\"\n",
59 id.bv_val ? id.bv_val : "", 0, 0 );
62 if( rc != LDAP_SUCCESS ) {
66 if( new.bv_len == 0 ) {
67 slap_passwd_generate(&new);
69 if( new.bv_len == 0 ) {
70 *text = "password generation failed.";
75 *rspdata = slap_passwd_return( &new );
78 slap_passwd_hash( &new, &hash );
80 if( hash.bv_len == 0 ) {
81 *text = "password hash failed";
93 LDAP_LOG ( ACL, DETAIL1, "bdb_exop_passwd: \"%s\"%s\"\n",
94 dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
96 Debug( LDAP_DEBUG_TRACE, "bdb_exop_passwd: \"%s\"%s\n",
97 dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
100 if( dn.bv_len == 0 ) {
101 *text = "No password is associated with the Root DSE";
102 rc = LDAP_UNWILLING_TO_PERFORM;
106 rc = dnNormalize2( NULL, &dn, &ndn );
107 if( rc != LDAP_SUCCESS ) {
108 *text = "Invalid DN";
113 retry: /* transaction retry */
115 bdb_cache_delete_entry(&bdb->bi_cache, e);
116 bdb_unlocked_cache_return_entry_w(&bdb->bi_cache, e);
119 LDAP_LOG ( ACL, DETAIL1, "bdb_exop_passwd: retrying...\n", 0, 0, 0 );
121 Debug( LDAP_DEBUG_TRACE, "bdb_exop_passwd: retrying...\n", 0, 0, 0 );
123 rc = TXN_ABORT( ltid );
125 op->o_private = NULL;
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 op->o_private = &opinfo;
162 rc = bdb_dn2entry_w( be, ltid, &ndn, &e, NULL, 0 , locker, &lock);
165 case DB_LOCK_DEADLOCK:
166 case DB_LOCK_NOTGRANTED:
172 *text = "ldap server busy";
176 *text = "internal error";
181 *text = "could not locate authorization entry";
182 rc = LDAP_NO_SUCH_OBJECT;
186 #ifdef BDB_SUBENTRIES
187 if( is_entry_subentry( e ) ) {
188 /* entry is an alias, don't allow operation */
189 *text = "authorization entry is subentry";
195 if( is_entry_alias( e ) ) {
196 /* entry is an alias, don't allow operation */
197 *text = "authorization entry is alias";
198 rc = LDAP_ALIAS_PROBLEM;
203 if( is_entry_referral( e ) ) {
204 /* entry is an referral, don't allow operation */
205 *text = "authorization entry is referral";
212 struct berval vals[2];
215 vals[1].bv_val = NULL;
217 ml.sml_desc = slap_schema.si_ad_userPassword;
218 ml.sml_values = vals;
220 ml.sml_nvalues = vals;
222 ml.sml_op = LDAP_MOD_REPLACE;
225 rc = bdb_modify_internal( be, conn, op, ltid,
226 &ml, e, text, textbuf, textlen );
229 case DB_LOCK_DEADLOCK:
230 case DB_LOCK_NOTGRANTED:
238 *text = "entry modify failed";
242 /* change the entry itself */
243 rc = bdb_id2entry_update( be, ltid, e );
246 case DB_LOCK_DEADLOCK:
247 case DB_LOCK_NOTGRANTED:
250 *text = "entry update failed";
256 rc = TXN_ABORT( ltid );
258 rc = TXN_COMMIT( ltid, 0 );
262 op->o_private = NULL;
264 if( rc == LDAP_SUCCESS ) {
265 replog( be, op, &e->e_name, &e->e_nname, &ml );
271 bdb_unlocked_cache_return_entry_w( &bdb->bi_cache, e );
274 if( hash.bv_val != NULL ) {
280 op->o_private = NULL;