1 /* passwd.c - ldbm backend password routines */
4 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/socket.h>
13 #include <ac/string.h>
16 #include "back-ldbm.h"
17 #include "proto-back-ldbm.h"
20 ldbm_back_exop_passwd(
25 struct berval *reqdata,
27 struct berval **rspdata,
28 LDAPControl *** rspctrls,
33 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
36 struct berval hash = { 0, NULL };
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( BACK_LDBM, ENTRY,
52 "ldbm_back_exop_passwd: \"%s\"\n", id.bv_val ? id.bv_val : "", 0,0 );
54 Debug( LDAP_DEBUG_ARGS, "==> ldbm_back_exop_passwd: \"%s\"\n",
55 id.bv_val ? id.bv_val : "", 0, 0 );
59 if( rc != LDAP_SUCCESS ) {
63 if( new.bv_len == 0 ) {
64 slap_passwd_generate(&new);
66 if( new.bv_len == 0 ) {
67 *text = "password generation failed.";
72 *rspdata = slap_passwd_return( &new );
75 slap_passwd_hash( &new, &hash );
77 if( hash.bv_len == 0 ) {
78 *text = "password hash failed";
90 LDAP_LOG( BACK_LDBM, DETAIL1,
91 "ldbm_back_exop_passwd: \"%s\"%s\n",
92 dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
94 Debug( LDAP_DEBUG_TRACE, "passwd: \"%s\"%s\n",
95 dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
98 if( dn.bv_len == 0 ) {
99 *text = "No password is associated with the Root DSE";
100 rc = LDAP_OPERATIONS_ERROR;
104 rc = dnNormalize2( NULL, &dn, &ndn );
105 if( rc != LDAP_SUCCESS ) {
106 *text = "Invalid DN";
110 /* grab giant lock for writing */
111 ldap_pvt_thread_rdwr_wlock(&li->li_giant_rwlock);
113 e = dn2entry_w( be, &ndn, NULL );
115 ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);
116 *text = "could not locate authorization entry";
117 rc = LDAP_NO_SUCH_OBJECT;
121 if( is_entry_alias( e ) ) {
122 /* entry is an alias, don't allow operation */
123 *text = "authorization entry is alias";
124 rc = LDAP_ALIAS_PROBLEM;
128 rc = LDAP_OPERATIONS_ERROR;
130 if( is_entry_referral( e ) ) {
131 /* entry is an referral, don't allow operation */
132 *text = "authorization entry is referral";
138 struct berval vals[2];
139 char textbuf[SLAP_TEXT_BUFLEN]; /* non-returnable */
142 vals[1].bv_val = NULL;
144 ml.sml_desc = slap_schema.si_ad_userPassword;
145 ml.sml_bvalues = vals;
146 ml.sml_op = LDAP_MOD_REPLACE;
149 rc = ldbm_modify_internal( be,
150 conn, op, op->o_ndn.bv_val, &ml, e, text, textbuf,
153 /* FIXME: ldbm_modify_internal may set *text = textbuf,
155 if ( *text == textbuf ) {
160 /* cannot return textbuf */
161 *text = "entry modify failed";
165 /* change the entry itself */
166 if( id2entry_add( be, e ) != 0 ) {
167 *text = "entry update failed";
171 if( rc == LDAP_SUCCESS ) {
172 replog( be, op, &e->e_name, &e->e_nname, &ml );
178 cache_return_entry_w( &li->li_cache, e );
179 ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);
182 if( hash.bv_val != NULL ) {
186 if( ndn.bv_val != NULL ) {