1 /* passwd.c - bdb backend password routines */
4 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
11 #include <ac/string.h>
22 struct berval *reqdata,
24 struct berval **rspdata,
25 LDAPControl *** rspctrls,
29 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
32 struct berval hash = { 0, NULL };
34 struct bdb_op_info opinfo;
35 char textbuf[SLAP_TEXT_BUFLEN];
36 size_t textlen = sizeof textbuf;
38 struct berval id = { 0, NULL };
39 struct berval new = { 0, NULL };
47 assert( reqoid != NULL );
48 assert( strcmp( LDAP_EXOP_MODIFY_PASSWD, reqoid ) == 0 );
50 rc = slap_passwd_parse( reqdata,
51 &id, NULL, &new, text );
54 LDAP_LOG (( "passwd", LDAP_LEVEL_ENTRY, "==>bdb_exop_passwd: \"%s\"\n",
55 id.bv_val ? id.bv_val : "" ));
57 Debug( LDAP_DEBUG_ARGS, "==> bdb_exop_passwd: \"%s\"\n",
58 id.bv_val ? id.bv_val : "", 0, 0 );
61 if( rc != LDAP_SUCCESS ) {
65 if( new.bv_len == 0 ) {
66 slap_passwd_generate(&new);
68 if( new.bv_len == 0 ) {
69 *text = "password generation failed.";
74 *rspdata = slap_passwd_return( &new );
77 slap_passwd_hash( &new, &hash );
79 if( hash.bv_len == 0 ) {
80 *text = "password hash failed";
92 LDAP_LOG (( "passwd", LDAP_LEVEL_DETAIL1, "bdb_exop_passwd: \"%s\"%s\"\n",
93 dn.bv_val, id.bv_len ? " (proxy)" : "" ));
95 Debug( LDAP_DEBUG_TRACE, "bdb_exop_passwd: \"%s\"%s\n",
96 dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
99 if( dn.bv_len == 0 ) {
100 *text = "No password is associated with the Root DSE";
101 rc = LDAP_OPERATIONS_ERROR;
105 rc = dnNormalize2( NULL, &dn, &ndn );
106 if( rc != LDAP_SUCCESS ) {
107 *text = "Invalid DN";
112 retry: /* transaction retry */
114 bdb_cache_delete_entry(&bdb->bi_cache, e);
115 bdb_cache_return_entry_w(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
118 LDAP_LOG (( "passwd", LDAP_LEVEL_DETAIL1, "bdb_exop_passwd: retrying...\n" ));
120 Debug( LDAP_DEBUG_TRACE, "bdb_exop_passwd: retrying...\n", 0, 0, 0 );
122 rc = TXN_ABORT( ltid );
124 op->o_private = NULL;
127 *text = "internal error";
130 ldap_pvt_thread_yield();
133 /* begin transaction */
134 rc = TXN_BEGIN( bdb->bi_dbenv, NULL, <id,
135 bdb->bi_db_opflags );
139 LDAP_LOG (( "passwd", LDAP_LEVEL_ERR, "bdb_exop_passwd: txn_begin failed: %s (%d)\n", db_strerror(rc), rc ));
141 Debug( LDAP_DEBUG_TRACE,
142 "bdb_exop_passwd: txn_begin failed: %s (%d)\n",
143 db_strerror(rc), rc, 0 );
146 *text = "internal error";
150 locker = TXN_ID ( ltid );
153 opinfo.boi_txn = ltid;
155 op->o_private = &opinfo;
158 rc = bdb_dn2entry_w( be, ltid, &ndn, &e, NULL, 0 , locker, &lock);
161 case DB_LOCK_DEADLOCK:
162 case DB_LOCK_NOTGRANTED:
168 *text = "ldap server busy";
172 *text = "internal error";
177 *text = "could not locate authorization entry";
178 rc = LDAP_NO_SUCH_OBJECT;
182 #ifdef BDB_SUBENTRIES
183 if( is_entry_subentry( e ) ) {
184 /* entry is an alias, don't allow operation */
185 *text = "authorization entry is subentry";
191 if( is_entry_alias( e ) ) {
192 /* entry is an alias, don't allow operation */
193 *text = "authorization entry is alias";
194 rc = LDAP_ALIAS_PROBLEM;
199 if( is_entry_referral( e ) ) {
200 /* entry is an referral, don't allow operation */
201 *text = "authorization entry is referral";
208 struct berval vals[2];
211 vals[1].bv_val = NULL;
213 ml.sml_desc = slap_schema.si_ad_userPassword;
214 ml.sml_bvalues = vals;
215 ml.sml_op = LDAP_MOD_REPLACE;
218 rc = bdb_modify_internal( be, conn, op, ltid,
219 &ml, e, text, textbuf, textlen );
222 case DB_LOCK_DEADLOCK:
223 case DB_LOCK_NOTGRANTED:
231 *text = "entry modify failed";
235 /* change the entry itself */
236 rc = bdb_id2entry_update( be, ltid, e );
239 case DB_LOCK_DEADLOCK:
240 case DB_LOCK_NOTGRANTED:
243 *text = "entry update failed";
249 rc = TXN_ABORT( ltid );
251 rc = TXN_COMMIT( ltid, 0 );
255 op->o_private = NULL;
257 if( rc == LDAP_SUCCESS ) {
258 replog( be, op, &e->e_name, &e->e_nname, &ml );
264 bdb_cache_return_entry_w( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
267 if( hash.bv_val != NULL ) {
273 op->o_private = NULL;