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 *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 ( ACL, ENTRY,
55 "==>bdb_exop_passwd: \"%s\"\n", id.bv_val ? id.bv_val : "", 0, 0 );
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 ( ACL, DETAIL1, "bdb_exop_passwd: \"%s\"%s\"\n",
93 dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
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_UNWILLING_TO_PERFORM;
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 ( ACL, DETAIL1, "bdb_exop_passwd: retrying...\n", 0, 0, 0 );
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 );
140 "bdb_exop_passwd: txn_begin failed: %s (%d)\n",
141 db_strerror(rc), rc, 0 );
143 Debug( LDAP_DEBUG_TRACE,
144 "bdb_exop_passwd: txn_begin failed: %s (%d)\n",
145 db_strerror(rc), rc, 0 );
148 *text = "internal error";
152 locker = TXN_ID ( ltid );
155 opinfo.boi_txn = ltid;
156 opinfo.boi_locker = locker;
158 op->o_private = &opinfo;
161 rc = bdb_dn2entry_w( be, ltid, &ndn, &e, NULL, 0 , locker, &lock);
164 case DB_LOCK_DEADLOCK:
165 case DB_LOCK_NOTGRANTED:
171 *text = "ldap server busy";
175 *text = "internal error";
180 *text = "could not locate authorization entry";
181 rc = LDAP_NO_SUCH_OBJECT;
185 #ifdef BDB_SUBENTRIES
186 if( is_entry_subentry( e ) ) {
187 /* entry is an alias, don't allow operation */
188 *text = "authorization entry is subentry";
194 if( is_entry_alias( e ) ) {
195 /* entry is an alias, don't allow operation */
196 *text = "authorization entry is alias";
197 rc = LDAP_ALIAS_PROBLEM;
202 if( is_entry_referral( e ) ) {
203 /* entry is an referral, don't allow operation */
204 *text = "authorization entry is referral";
211 struct berval vals[2];
214 vals[1].bv_val = NULL;
216 ml.sml_desc = slap_schema.si_ad_userPassword;
217 ml.sml_bvalues = vals;
218 ml.sml_op = LDAP_MOD_REPLACE;
221 rc = bdb_modify_internal( be, conn, op, ltid,
222 &ml, e, text, textbuf, textlen );
225 case DB_LOCK_DEADLOCK:
226 case DB_LOCK_NOTGRANTED:
234 *text = "entry modify failed";
238 /* change the entry itself */
239 rc = bdb_id2entry_update( be, ltid, e );
242 case DB_LOCK_DEADLOCK:
243 case DB_LOCK_NOTGRANTED:
246 *text = "entry update failed";
252 rc = TXN_ABORT( ltid );
254 rc = TXN_COMMIT( ltid, 0 );
258 op->o_private = NULL;
260 if( rc == LDAP_SUCCESS ) {
261 replog( be, op, &e->e_name, &e->e_nname, &ml );
267 bdb_cache_return_entry_w( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
270 if( hash.bv_val != NULL ) {
276 op->o_private = NULL;