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 };
44 assert( reqoid != NULL );
45 assert( strcmp( LDAP_EXOP_MODIFY_PASSWD, reqoid ) == 0 );
47 rc = slap_passwd_parse( reqdata,
48 &id, NULL, &new, text );
51 LDAP_LOG (( "passwd", LDAP_LEVEL_ENTRY, "==>bdb_exop_passwd: \"%s\"\n",
52 id.bv_val ? id.bv_val : "" ));
54 Debug( LDAP_DEBUG_ARGS, "==> bdb_exop_passwd: \"%s\"\n",
55 id.bv_val ? id.bv_val : "", 0, 0 );
58 if( rc != LDAP_SUCCESS ) {
62 if( new.bv_len == 0 ) {
63 slap_passwd_generate(&new);
65 if( new.bv_len == 0 ) {
66 *text = "password generation failed.";
71 *rspdata = slap_passwd_return( &new );
74 slap_passwd_hash( &new, &hash );
76 if( hash.bv_len == 0 ) {
77 *text = "password hash failed";
89 LDAP_LOG (( "passwd", LDAP_LEVEL_DETAIL1, "bdb_exop_passwd: \"%s\"%s\"\n",
90 dn.bv_val, id.bv_len ? " (proxy)" : "" ));
92 Debug( LDAP_DEBUG_TRACE, "bdb_exop_passwd: \"%s\"%s\n",
93 dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
96 if( dn.bv_len == 0 ) {
97 *text = "No password is associated with the Root DSE";
98 rc = LDAP_OPERATIONS_ERROR;
102 rc = dnNormalize2( NULL, &dn, &ndn );
103 if( rc != LDAP_SUCCESS ) {
104 *text = "Invalid DN";
109 retry: /* transaction retry */
111 bdb_cache_delete_entry(&bdb->bi_cache, e);
112 bdb_cache_return_entry_w(&bdb->bi_cache, e);
115 LDAP_LOG (( "passwd", LDAP_LEVEL_DETAIL1, "bdb_exop_passwd: retrying...\n" ));
117 Debug( LDAP_DEBUG_TRACE, "bdb_exop_passwd: retrying...\n", 0, 0, 0 );
119 rc = TXN_ABORT( ltid );
121 op->o_private = NULL;
124 *text = "internal error";
127 ldap_pvt_thread_yield();
130 /* begin transaction */
131 rc = TXN_BEGIN( bdb->bi_dbenv, NULL, <id,
132 bdb->bi_db_opflags );
136 LDAP_LOG (( "passwd", LDAP_LEVEL_ERR, "bdb_exop_passwd: txn_begin failed: %s (%d)\n", db_strerror(rc), rc ));
138 Debug( LDAP_DEBUG_TRACE,
139 "bdb_exop_passwd: txn_begin failed: %s (%d)\n",
140 db_strerror(rc), rc, 0 );
143 *text = "internal error";
148 opinfo.boi_txn = ltid;
150 op->o_private = &opinfo;
153 rc = bdb_dn2entry_w( be, ltid, &ndn, &e, NULL, 0 );
156 case DB_LOCK_DEADLOCK:
157 case DB_LOCK_NOTGRANTED:
164 *text = "internal error";
169 *text = "could not locate authorization entry";
170 rc = LDAP_NO_SUCH_OBJECT;
174 #ifdef BDB_SUBENTRIES
175 if( is_entry_subentries( e ) ) {
176 /* entry is an alias, don't allow operation */
177 *text = "authorization entry is subentry";
183 if( is_entry_alias( e ) ) {
184 /* entry is an alias, don't allow operation */
185 *text = "authorization entry is alias";
186 rc = LDAP_ALIAS_PROBLEM;
191 if( is_entry_referral( e ) ) {
192 /* entry is an referral, don't allow operation */
193 *text = "authorization entry is referral";
200 struct berval vals[2];
203 vals[1].bv_val = NULL;
205 ml.sml_desc = slap_schema.si_ad_userPassword;
206 ml.sml_bvalues = vals;
207 ml.sml_op = LDAP_MOD_REPLACE;
210 rc = bdb_modify_internal( be, conn, op, ltid,
211 &ml, e, text, textbuf, textlen );
214 case DB_LOCK_DEADLOCK:
215 case DB_LOCK_NOTGRANTED:
223 *text = "entry modify failed";
227 /* change the entry itself */
228 rc = bdb_id2entry_update( be, ltid, e );
231 case DB_LOCK_DEADLOCK:
232 case DB_LOCK_NOTGRANTED:
235 *text = "entry update failed";
241 rc = TXN_ABORT( ltid );
243 rc = TXN_COMMIT( ltid, 0 );
247 op->o_private = NULL;
249 if( rc == LDAP_SUCCESS ) {
250 replog( be, op, &e->e_name, &e->e_nname, &ml );
256 bdb_cache_return_entry_w( &bdb->bi_cache, e );
259 if( hash.bv_val != NULL ) {
265 op->o_private = NULL;