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 };
42 struct berval dn = { 0, NULL };
43 struct berval ndn = { 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;
126 op->o_do_not_cache = opinfo.boi_acl_cache;
129 *text = "internal error";
132 ldap_pvt_thread_yield();
135 /* begin transaction */
136 rc = TXN_BEGIN( bdb->bi_dbenv, NULL, <id,
137 bdb->bi_db_opflags );
142 "bdb_exop_passwd: txn_begin failed: %s (%d)\n",
143 db_strerror(rc), rc, 0 );
145 Debug( LDAP_DEBUG_TRACE,
146 "bdb_exop_passwd: txn_begin failed: %s (%d)\n",
147 db_strerror(rc), rc, 0 );
150 *text = "internal error";
154 locker = TXN_ID ( ltid );
157 opinfo.boi_txn = ltid;
158 opinfo.boi_locker = locker;
160 opinfo.boi_acl_cache = op->o_do_not_cache;
161 op->o_private = &opinfo;
164 rc = bdb_dn2entry_w( be, ltid, &ndn, &e, NULL, 0 , locker, &lock);
167 case DB_LOCK_DEADLOCK:
168 case DB_LOCK_NOTGRANTED:
174 *text = "ldap server busy";
178 *text = "internal error";
183 *text = "could not locate authorization entry";
184 rc = LDAP_NO_SUCH_OBJECT;
188 #ifdef BDB_SUBENTRIES
189 if( is_entry_subentry( e ) ) {
190 /* entry is an alias, don't allow operation */
191 *text = "authorization entry is subentry";
197 if( is_entry_alias( e ) ) {
198 /* entry is an alias, don't allow operation */
199 *text = "authorization entry is alias";
200 rc = LDAP_ALIAS_PROBLEM;
205 if( is_entry_referral( e ) ) {
206 /* entry is an referral, don't allow operation */
207 *text = "authorization entry is referral";
214 struct berval vals[2];
217 vals[1].bv_val = NULL;
219 ml.sml_desc = slap_schema.si_ad_userPassword;
220 ml.sml_values = vals;
222 ml.sml_nvalues = NULL;
224 ml.sml_op = LDAP_MOD_REPLACE;
227 rc = bdb_modify_internal( be, conn, op, ltid,
228 &ml, e, text, textbuf, textlen );
230 if ( (rc == LDAP_INSUFFICIENT_ACCESS) && opinfo.boi_err ) {
234 case DB_LOCK_DEADLOCK:
235 case DB_LOCK_NOTGRANTED:
243 *text = "entry modify failed";
247 /* change the entry itself */
248 rc = bdb_id2entry_update( be, ltid, e );
251 case DB_LOCK_DEADLOCK:
252 case DB_LOCK_NOTGRANTED:
255 *text = "entry update failed";
261 rc = TXN_ABORT( ltid );
263 rc = TXN_COMMIT( ltid, 0 );
267 op->o_private = NULL;
269 if( rc == LDAP_SUCCESS ) {
270 replog( be, op, &e->e_name, &e->e_nname, &ml );
276 bdb_unlocked_cache_return_entry_w( &bdb->bi_cache, e );
279 if( hash.bv_val != NULL ) {
283 if( ndn.bv_val != NULL ) {
289 op->o_private = NULL;