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 };
39 assert( ber_bvcmp( &slap_EXOP_MODIFY_PASSWD, &op->oq_extended.rs_reqoid ) == 0 );
41 rc = slap_passwd_parse( op->oq_extended.rs_reqdata,
42 &id, NULL, &new, &rs->sr_text );
45 LDAP_LOG ( ACL, ENTRY,
46 "==>bdb_exop_passwd: \"%s\"\n", id.bv_val ? id.bv_val : "", 0, 0 );
48 Debug( LDAP_DEBUG_ARGS, "==> bdb_exop_passwd: \"%s\"\n",
49 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 rs->sr_text = "password generation failed.";
65 rs->sr_rspdata = slap_passwd_return( &new );
68 slap_passwd_hash( &new, &hash, &rs->sr_text );
70 if( hash.bv_len == 0 ) {
71 if( !rs->sr_text ) rs->sr_text = "password hash failed";
83 LDAP_LOG ( ACL, DETAIL1, "bdb_exop_passwd: \"%s\"%s\"\n",
84 dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
86 Debug( LDAP_DEBUG_TRACE, "bdb_exop_passwd: \"%s\"%s\n",
87 dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
90 if( dn.bv_len == 0 ) {
91 rs->sr_text = "No password is associated with the Root DSE";
92 rc = LDAP_UNWILLING_TO_PERFORM;
96 rc = dnNormalize( 0, NULL, NULL, &dn, &ndn, op->o_tmpmemctx );
97 if( rc != LDAP_SUCCESS ) {
98 rs->sr_text = "Invalid DN";
103 retry: /* transaction retry */
105 bdb_unlocked_cache_return_entry_w(&bdb->bi_cache, e);
108 LDAP_LOG ( ACL, DETAIL1, "bdb_exop_passwd: retrying...\n", 0, 0, 0 );
110 Debug( LDAP_DEBUG_TRACE, "bdb_exop_passwd: retrying...\n", 0, 0, 0 );
112 rc = TXN_ABORT( ltid );
114 op->o_private = NULL;
115 op->o_do_not_cache = opinfo.boi_acl_cache;
118 rs->sr_text = "internal error";
121 ldap_pvt_thread_yield();
124 /* begin transaction */
125 rc = TXN_BEGIN( bdb->bi_dbenv, NULL, <id,
126 bdb->bi_db_opflags );
131 "bdb_exop_passwd: txn_begin failed: %s (%d)\n",
132 db_strerror(rc), rc, 0 );
134 Debug( LDAP_DEBUG_TRACE,
135 "bdb_exop_passwd: txn_begin failed: %s (%d)\n",
136 db_strerror(rc), rc, 0 );
139 rs->sr_text = "internal error";
143 locker = TXN_ID ( ltid );
145 opinfo.boi_bdb = op->o_bd;
146 opinfo.boi_txn = ltid;
147 opinfo.boi_locker = locker;
149 opinfo.boi_acl_cache = op->o_do_not_cache;
150 op->o_private = &opinfo;
153 rc = bdb_dn2entry( op->o_bd, ltid, &ndn, &ei, 0 , locker, &lock, op->o_tmpmemctx );
156 case DB_LOCK_DEADLOCK:
157 case DB_LOCK_NOTGRANTED:
163 rs->sr_text = "ldap server busy";
167 rs->sr_text = "internal error";
171 if ( ei ) e = ei->bei_e;
174 rs->sr_text = "could not locate authorization entry";
175 rc = LDAP_NO_SUCH_OBJECT;
179 #ifdef BDB_SUBENTRIES
180 if( is_entry_subentry( e ) ) {
181 /* entry is a subentry, don't allow operation */
182 rs->sr_text = "authorization entry is subentry";
188 if( is_entry_alias( e ) ) {
189 /* entry is an alias, don't allow operation */
190 rs->sr_text = "authorization entry is alias";
191 rc = LDAP_ALIAS_PROBLEM;
196 if( is_entry_referral( e ) ) {
197 /* entry is an referral, don't allow operation */
198 rs->sr_text = "authorization entry is referral";
203 /* nested transaction */
204 rc = TXN_BEGIN( bdb->bi_dbenv, ltid, <2,
205 bdb->bi_db_opflags );
209 LDAP_LOG ( OPERATION, ERR,
210 "bdb_exop_passwd: txn_begin(2) failed: %s (%d)\n", db_strerror(rs->sr_err), rs->sr_err, 0 );
212 Debug( LDAP_DEBUG_TRACE,
213 "bdb_exop_passwd: txn_begin(2) failed: %s (%d)\n",
214 db_strerror(rs->sr_err), rs->sr_err, 0 );
217 rs->sr_text = "internal error";
222 struct berval vals[2];
230 vals[1].bv_val = NULL;
232 ml.sml_desc = slap_schema.si_ad_userPassword;
233 ml.sml_values = vals;
234 ml.sml_nvalues = NULL;
235 ml.sml_op = LDAP_MOD_REPLACE;
238 rc = bdb_modify_internal( op, lt2,
239 &ml, e, &rs->sr_text, textbuf, textlen );
241 if ( (rc == LDAP_INSUFFICIENT_ACCESS) && opinfo.boi_err ) {
245 case DB_LOCK_DEADLOCK:
246 case DB_LOCK_NOTGRANTED:
254 rs->sr_text = "entry modify failed";
258 /* change the entry itself */
259 rc = bdb_id2entry_update( op->o_bd, lt2, e );
262 case DB_LOCK_DEADLOCK:
263 case DB_LOCK_NOTGRANTED:
266 rs->sr_text = "entry update failed";
269 if ( TXN_COMMIT( lt2, 0 ) != 0 ) {
271 rs->sr_text = "txn_commit(2) failed";
276 rc = TXN_ABORT( ltid );
278 bdb_cache_modify( save, e->e_attrs,
279 bdb->bi_dbenv, locker, &lock );
280 rc = TXN_COMMIT( ltid, 0 );
284 op->o_private = NULL;
286 if( rc == LDAP_SUCCESS ) {
287 op->o_req_dn = e->e_name;
288 op->o_req_ndn = e->e_nname;
289 op->oq_modify.rs_modlist = &ml;
291 op->oq_extended.rs_reqoid = slap_EXOP_MODIFY_PASSWD;
297 bdb_unlocked_cache_return_entry_w( &bdb->bi_cache, e );
300 if( hash.bv_val != NULL ) {
304 if( ndn.bv_val != NULL ) {
305 op->o_tmpfree( ndn.bv_val, op->o_tmpmemctx );
310 op->o_private = NULL;