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;
36 struct berval *id = NULL;
37 struct berval *new = NULL;
41 assert( reqoid != NULL );
42 assert( strcmp( LDAP_EXOP_X_MODIFY_PASSWD, reqoid ) == 0 );
44 rc = slap_passwd_parse( reqdata,
45 &id, NULL, &new, text );
47 Debug( LDAP_DEBUG_ARGS, "==> bdb_exop_passwd: \"%s\"\n",
48 id ? id->bv_val : "", 0, 0 );
50 if( rc != LDAP_SUCCESS ) {
54 if( new == NULL || new->bv_len == 0 ) {
55 new = slap_passwd_generate();
57 if( new == NULL || new->bv_len == 0 ) {
58 *text = "password generation failed.";
63 *rspdata = slap_passwd_return( new );
66 hash = slap_passwd_hash( new );
68 if( hash == NULL || hash->bv_len == 0 ) {
69 *text = "password hash failed";
74 dn = id ? id->bv_val : op->o_dn;
76 Debug( LDAP_DEBUG_TRACE, "passwd: \"%s\"%s\n",
77 dn, id ? " (proxy)" : "", 0 );
79 if( dn == NULL || dn[0] == '\0' ) {
80 *text = "No password is associated with the Root DSE";
81 rc = LDAP_OPERATIONS_ERROR;
86 /* transaction retry */
87 retry: rc = txn_abort( ltid );
92 *text = "internal error";
97 /* begin transaction */
98 rc = txn_begin( bdb->bi_dbenv, NULL, <id, 0 );
100 Debug( LDAP_DEBUG_TRACE,
101 "bdb_exop_passwd: txn_begin failed: %s (%d)\n",
102 db_strerror(rc), rc, 0 );
104 *text = "internal error";
109 opinfo.boi_txn = ltid;
111 op->o_private = &opinfo;
114 rc = bdb_dn2entry( be, ltid, dn, &e, NULL, 0 );
117 case DB_LOCK_DEADLOCK:
118 case DB_LOCK_NOTGRANTED:
125 *text = "internal error";
130 *text = "could not locate authorization entry";
131 rc = LDAP_OPERATIONS_ERROR;
135 if( is_entry_alias( e ) ) {
136 /* entry is an alias, don't allow operation */
137 *text = "authorization entry is alias";
138 rc = LDAP_ALIAS_PROBLEM;
143 if( is_entry_referral( e ) ) {
144 /* entry is an referral, don't allow operation */
145 *text = "authorization entry is referral";
146 rc = LDAP_OPERATIONS_ERROR;
152 struct berval *vals[2];
157 ml.sml_desc = slap_schema.si_ad_userPassword;
158 ml.sml_bvalues = vals;
159 ml.sml_op = LDAP_MOD_REPLACE;
162 rc = bdb_modify_internal( be, conn, op, ltid,
163 op->o_ndn, &ml, e, text );
166 case DB_LOCK_DEADLOCK:
167 case DB_LOCK_NOTGRANTED:
168 bdb_entry_return( be, e );
175 *text = "entry modify failed";
181 /* change the entry itself */
182 rc = bdb_id2entry_update( be, ltid, e );
185 case DB_LOCK_DEADLOCK:
186 case DB_LOCK_NOTGRANTED:
187 bdb_entry_return( be, e );
190 *text = "entry update failed";
197 bdb_entry_return( be, e );
214 op->o_private = NULL;