1 /* passwd.c - bdb backend password routines */
4 * Copyright 1998-2000 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,
27 struct berval *** refs )
29 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
32 struct berval *hash = NULL;
34 struct bdb_op_info opinfo;
35 char textbuf[SLAP_TEXT_BUFLEN];
36 size_t textlen = sizeof textbuf;
38 struct berval *id = NULL;
39 struct berval *new = NULL;
43 assert( reqoid != NULL );
44 assert( strcmp( LDAP_EXOP_X_MODIFY_PASSWD, reqoid ) == 0 );
46 rc = slap_passwd_parse( reqdata,
47 &id, NULL, &new, text );
49 Debug( LDAP_DEBUG_ARGS, "==> bdb_exop_passwd: \"%s\"\n",
50 id ? id->bv_val : "", 0, 0 );
52 if( rc != LDAP_SUCCESS ) {
56 if( new == NULL || new->bv_len == 0 ) {
57 new = slap_passwd_generate();
59 if( new == NULL || new->bv_len == 0 ) {
60 *text = "password generation failed.";
65 *rspdata = slap_passwd_return( new );
68 hash = slap_passwd_hash( new );
70 if( hash == NULL || hash->bv_len == 0 ) {
71 *text = "password hash failed";
76 dn = id ? id->bv_val : op->o_dn;
78 Debug( LDAP_DEBUG_TRACE, "bdb_exop_passwd: \"%s\"%s\n",
79 dn, id ? " (proxy)" : "", 0 );
81 if( dn == NULL || dn[0] == '\0' ) {
82 *text = "No password is associated with the Root DSE";
83 rc = LDAP_OPERATIONS_ERROR;
88 retry: /* transaction retry */
89 Debug( LDAP_DEBUG_TRACE, "bdb_exop_passwd: retrying...\n", 0, 0, 0 );
90 rc = txn_abort( ltid );
95 *text = "internal error";
101 /* begin transaction */
102 rc = txn_begin( bdb->bi_dbenv, NULL, <id,
103 bdb->bi_db_opflags );
106 Debug( LDAP_DEBUG_TRACE,
107 "bdb_exop_passwd: txn_begin failed: %s (%d)\n",
108 db_strerror(rc), rc, 0 );
110 *text = "internal error";
116 opinfo.boi_txn = ltid;
118 op->o_private = &opinfo;
121 rc = bdb_dn2entry( be, ltid, dn, &e, NULL, 0 );
124 case DB_LOCK_DEADLOCK:
125 case DB_LOCK_NOTGRANTED:
132 *text = "internal error";
137 *text = "could not locate authorization entry";
138 rc = LDAP_NO_SUCH_OBJECT;
142 if( is_entry_alias( e ) ) {
143 /* entry is an alias, don't allow operation */
144 *text = "authorization entry is alias";
145 rc = LDAP_ALIAS_PROBLEM;
150 if( is_entry_referral( e ) ) {
151 /* entry is an referral, don't allow operation */
152 *text = "authorization entry is referral";
153 rc = LDAP_OPERATIONS_ERROR;
159 struct berval *vals[2];
164 ml.sml_desc = slap_schema.si_ad_userPassword;
165 ml.sml_bvalues = vals;
166 ml.sml_op = LDAP_MOD_REPLACE;
169 rc = bdb_modify_internal( be, conn, op, ltid,
170 &ml, e, text, textbuf, textlen );
173 case DB_LOCK_DEADLOCK:
174 case DB_LOCK_NOTGRANTED:
176 bdb_entry_return( be, e );
183 *text = "entry modify failed";
189 /* change the entry itself */
190 rc = bdb_id2entry_update( be, ltid, e );
193 case DB_LOCK_DEADLOCK:
194 case DB_LOCK_NOTGRANTED:
195 bdb_entry_return( be, e );
199 *text = "entry update failed";
203 if( bdb->bi_txn && rc == 0 ) {
204 rc = txn_commit( ltid, 0 );
207 op->o_private = NULL;
211 bdb_entry_return( be, e );
228 op->o_private = NULL;