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;
23 struct berval hash = { 0, NULL };
25 struct bdb_op_info opinfo;
26 char textbuf[SLAP_TEXT_BUFLEN];
27 size_t textlen = sizeof textbuf;
29 struct berval id = { 0, NULL };
30 struct berval new = { 0, NULL };
32 struct berval dn = { 0, NULL };
33 struct berval ndn = { 0, NULL };
38 assert( ber_bvcmp( &slap_EXOP_MODIFY_PASSWD, &op->oq_extended.rs_reqoid ) == 0 );
40 rc = slap_passwd_parse( op->oq_extended.rs_reqdata,
41 &id, NULL, &new, &rs->sr_text );
44 LDAP_LOG ( ACL, ENTRY,
45 "==>bdb_exop_passwd: \"%s\"\n", id.bv_val ? id.bv_val : "", 0, 0 );
47 Debug( LDAP_DEBUG_ARGS, "==> bdb_exop_passwd: \"%s\"\n",
48 id.bv_val ? id.bv_val : "", 0, 0 );
51 if( rc != LDAP_SUCCESS ) {
55 if( new.bv_len == 0 ) {
56 slap_passwd_generate(&new);
58 if( new.bv_len == 0 ) {
59 rs->sr_text = "password generation failed.";
64 rs->sr_rspdata = slap_passwd_return( &new );
67 slap_passwd_hash( &new, &hash );
69 if( hash.bv_len == 0 ) {
70 rs->sr_text = "password hash failed";
82 LDAP_LOG ( ACL, DETAIL1, "bdb_exop_passwd: \"%s\"%s\"\n",
83 dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
85 Debug( LDAP_DEBUG_TRACE, "bdb_exop_passwd: \"%s\"%s\n",
86 dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
89 if( dn.bv_len == 0 ) {
90 rs->sr_text = "No password is associated with the Root DSE";
91 rc = LDAP_UNWILLING_TO_PERFORM;
95 rc = dnNormalize2( NULL, &dn, &ndn );
96 if( rc != LDAP_SUCCESS ) {
97 rs->sr_text = "Invalid DN";
102 retry: /* transaction retry */
104 bdb_cache_delete_entry(&bdb->bi_cache, e);
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_w( op->o_bd, ltid, &ndn, &e, NULL, 0 , locker, &lock);
156 case DB_LOCK_DEADLOCK:
157 case DB_LOCK_NOTGRANTED:
163 rs->sr_text = "ldap server busy";
167 rs->sr_text = "internal error";
172 rs->sr_text = "could not locate authorization entry";
173 rc = LDAP_NO_SUCH_OBJECT;
177 #ifdef BDB_SUBENTRIES
178 if( is_entry_subentry( e ) ) {
179 /* entry is an alias, don't allow operation */
180 rs->sr_text = "authorization entry is subentry";
186 if( is_entry_alias( e ) ) {
187 /* entry is an alias, don't allow operation */
188 rs->sr_text = "authorization entry is alias";
189 rc = LDAP_ALIAS_PROBLEM;
194 if( is_entry_referral( e ) ) {
195 /* entry is an referral, don't allow operation */
196 rs->sr_text = "authorization entry is referral";
203 struct berval vals[2];
206 vals[1].bv_val = NULL;
208 ml.sml_desc = slap_schema.si_ad_userPassword;
209 ml.sml_values = vals;
210 ml.sml_nvalues = NULL;
211 ml.sml_op = LDAP_MOD_REPLACE;
214 rc = bdb_modify_internal( op, ltid,
215 &ml, e, &rs->sr_text, textbuf, textlen );
217 if ( (rc == LDAP_INSUFFICIENT_ACCESS) && opinfo.boi_err ) {
221 case DB_LOCK_DEADLOCK:
222 case DB_LOCK_NOTGRANTED:
230 rs->sr_text = "entry modify failed";
234 /* change the entry itself */
235 rc = bdb_id2entry_update( op->o_bd, ltid, e );
238 case DB_LOCK_DEADLOCK:
239 case DB_LOCK_NOTGRANTED:
242 rs->sr_text = "entry update failed";
248 rc = TXN_ABORT( ltid );
250 rc = TXN_COMMIT( ltid, 0 );
254 op->o_private = NULL;
256 if( rc == LDAP_SUCCESS ) {
257 op->o_req_dn = e->e_name;
258 op->o_req_ndn = e->e_nname;
259 op->oq_modify.rs_modlist = &ml;
261 op->oq_extended.rs_reqoid = slap_EXOP_MODIFY_PASSWD;
267 bdb_unlocked_cache_return_entry_w( &bdb->bi_cache, e );
270 if( hash.bv_val != NULL ) {
274 if( ndn.bv_val != NULL ) {
280 op->o_private = NULL;