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>
18 bdb_exop_passwd( Operation *op, SlapReply *rs )
20 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
24 struct berval hash = { 0, NULL };
25 DB_TXN *ltid = NULL, *lt2;
26 struct bdb_op_info opinfo;
27 char textbuf[SLAP_TEXT_BUFLEN];
28 size_t textlen = sizeof textbuf;
30 struct berval id = { 0, NULL };
31 struct berval new = { 0, NULL };
33 struct berval dn = { 0, NULL };
34 struct berval ndn = { 0, NULL };
41 assert( ber_bvcmp( &slap_EXOP_MODIFY_PASSWD, &op->oq_extended.rs_reqoid ) == 0 );
43 rc = slap_passwd_parse( op->oq_extended.rs_reqdata,
44 &id, NULL, &new, &rs->sr_text );
47 LDAP_LOG ( ACL, ENTRY,
48 "==>bdb_exop_passwd: \"%s\"\n", id.bv_val ? id.bv_val : "", 0, 0 );
50 Debug( LDAP_DEBUG_ARGS, "==> bdb_exop_passwd: \"%s\"\n",
51 id.bv_val ? id.bv_val : "", 0, 0 );
54 if( rc != LDAP_SUCCESS ) {
58 if( new.bv_len == 0 ) {
59 slap_passwd_generate(&new);
61 if( new.bv_len == 0 ) {
62 rs->sr_text = "password generation failed.";
67 rs->sr_rspdata = slap_passwd_return( &new );
70 slap_passwd_hash( &new, &hash, &rs->sr_text );
72 if( hash.bv_len == 0 ) {
73 if( !rs->sr_text ) rs->sr_text = "password hash failed";
85 LDAP_LOG ( ACL, DETAIL1, "bdb_exop_passwd: \"%s\"%s\"\n",
86 dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
88 Debug( LDAP_DEBUG_TRACE, "bdb_exop_passwd: \"%s\"%s\n",
89 dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
92 if( dn.bv_len == 0 ) {
93 rs->sr_text = "No password is associated with the Root DSE";
94 rc = LDAP_UNWILLING_TO_PERFORM;
98 rc = dnNormalize( 0, NULL, NULL, &dn, &ndn, op->o_tmpmemctx );
99 if( rc != LDAP_SUCCESS ) {
100 rs->sr_text = "Invalid DN";
105 retry: /* transaction retry */
107 bdb_unlocked_cache_return_entry_w(&bdb->bi_cache, e);
110 LDAP_LOG ( ACL, DETAIL1, "bdb_exop_passwd: retrying...\n", 0, 0, 0 );
112 Debug( LDAP_DEBUG_TRACE, "bdb_exop_passwd: retrying...\n", 0, 0, 0 );
114 rc = TXN_ABORT( ltid );
116 op->o_private = NULL;
117 op->o_do_not_cache = opinfo.boi_acl_cache;
120 rs->sr_text = "internal error";
123 ldap_pvt_thread_yield();
124 bdb_trans_backoff( ++num_retries );
127 /* begin transaction */
128 rc = TXN_BEGIN( bdb->bi_dbenv, NULL, <id,
129 bdb->bi_db_opflags );
134 "bdb_exop_passwd: txn_begin failed: %s (%d)\n",
135 db_strerror(rc), rc, 0 );
137 Debug( LDAP_DEBUG_TRACE,
138 "bdb_exop_passwd: txn_begin failed: %s (%d)\n",
139 db_strerror(rc), rc, 0 );
142 rs->sr_text = "internal error";
146 locker = TXN_ID ( ltid );
148 opinfo.boi_bdb = op->o_bd;
149 opinfo.boi_txn = ltid;
150 opinfo.boi_locker = locker;
152 opinfo.boi_acl_cache = op->o_do_not_cache;
153 op->o_private = &opinfo;
156 rc = bdb_dn2entry( op, ltid, &ndn, &ei, 0 , locker, &lock );
159 case DB_LOCK_DEADLOCK:
160 case DB_LOCK_NOTGRANTED:
166 rs->sr_text = "ldap server busy";
170 rs->sr_text = "internal error";
174 if ( ei ) e = ei->bei_e;
176 if ( e == NULL || is_entry_glue( e )) {
177 /* FIXME: dn2entry() should return non-glue entry */
178 rs->sr_text = "could not locate authorization entry";
179 rc = LDAP_NO_SUCH_OBJECT;
183 #ifdef BDB_SUBENTRIES
184 if( is_entry_subentry( e ) ) {
185 /* entry is a subentry, don't allow operation */
186 rs->sr_text = "authorization entry is subentry";
193 if( is_entry_alias( e ) ) {
194 /* entry is an alias, don't allow operation */
195 rs->sr_text = "authorization entry is alias";
196 rc = LDAP_ALIAS_PROBLEM;
201 if( is_entry_referral( e ) ) {
202 /* entry is an referral, don't allow operation */
203 rs->sr_text = "authorization entry is referral";
208 /* nested transaction */
209 rc = TXN_BEGIN( bdb->bi_dbenv, ltid, <2,
210 bdb->bi_db_opflags );
214 LDAP_LOG ( OPERATION, ERR,
215 "bdb_exop_passwd: txn_begin(2) failed: %s (%d)\n",
216 db_strerror(rs->sr_err), rs->sr_err, 0 );
218 Debug( LDAP_DEBUG_TRACE,
219 "bdb_exop_passwd: txn_begin(2) failed: %s (%d)\n",
220 db_strerror(rs->sr_err), rs->sr_err, 0 );
223 rs->sr_text = "internal error";
229 struct berval vals[2];
237 vals[1].bv_val = NULL;
239 ml.sml_desc = slap_schema.si_ad_userPassword;
240 ml.sml_values = vals;
241 ml.sml_nvalues = NULL;
242 ml.sml_op = LDAP_MOD_REPLACE;
245 rc = bdb_modify_internal( op, lt2,
246 &ml, e, &rs->sr_text, textbuf, textlen );
248 if ( (rc == LDAP_INSUFFICIENT_ACCESS) && opinfo.boi_err ) {
252 case DB_LOCK_DEADLOCK:
253 case DB_LOCK_NOTGRANTED:
261 rs->sr_text = "entry modify failed";
265 /* change the entry itself */
266 rc = bdb_id2entry_update( op->o_bd, lt2, e );
269 case DB_LOCK_DEADLOCK:
270 case DB_LOCK_NOTGRANTED:
273 rs->sr_text = "entry update failed";
276 if ( TXN_COMMIT( lt2, 0 ) != 0 ) {
278 rs->sr_text = "txn_commit(2) failed";
283 rc = TXN_ABORT( ltid );
285 bdb_cache_modify( save, e->e_attrs,
286 bdb->bi_dbenv, locker, &lock );
287 rc = TXN_COMMIT( ltid, 0 );
291 op->o_private = NULL;
293 if( rc == LDAP_SUCCESS ) {
294 op->o_req_dn = e->e_name;
295 op->o_req_ndn = e->e_nname;
296 op->oq_modify.rs_modlist = &ml;
298 op->oq_extended.rs_reqoid = slap_EXOP_MODIFY_PASSWD;
304 bdb_unlocked_cache_return_entry_w( &bdb->bi_cache, e );
307 if( hash.bv_val != NULL ) {
311 if( ndn.bv_val != NULL ) {
312 op->o_tmpfree( ndn.bv_val, op->o_tmpmemctx );
317 op->o_private = NULL;