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(( "backend", LDAP_LEVEL_ENTRY,
52 "ldbm_back_exop_passwd: \"%s\"\n",
53 id.bv_val ? id.bv_val : "" ));
55 Debug( LDAP_DEBUG_ARGS, "==> ldbm_back_exop_passwd: \"%s\"\n",
56 id.bv_val ? id.bv_val : "", 0, 0 );
60 if( rc != LDAP_SUCCESS ) {
64 if( new.bv_len == 0 ) {
65 slap_passwd_generate(&new);
67 if( new.bv_len == 0 ) {
68 *text = "password generation failed.";
73 *rspdata = slap_passwd_return( &new );
76 slap_passwd_hash( &new, &hash );
78 if( hash.bv_len == 0 ) {
79 *text = "password hash failed";
91 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
92 "ldbm_back_exop_passwd: \"%s\"%s\n",
93 dn.bv_val, id.bv_len ? " (proxy)" : "" ));
95 Debug( LDAP_DEBUG_TRACE, "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_OPERATIONS_ERROR;
105 rc = dnNormalize2( NULL, &dn, &ndn );
106 if( rc != LDAP_SUCCESS ) {
107 *text = "Invalid DN";
111 /* grab giant lock for writing */
112 ldap_pvt_thread_rdwr_wlock(&li->li_giant_rwlock);
114 e = dn2entry_w( be, &ndn, NULL );
116 ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);
117 *text = "could not locate authorization entry";
118 rc = LDAP_NO_SUCH_OBJECT;
122 if( is_entry_alias( e ) ) {
123 /* entry is an alias, don't allow operation */
124 *text = "authorization entry is alias";
125 rc = LDAP_ALIAS_PROBLEM;
129 rc = LDAP_OPERATIONS_ERROR;
131 if( is_entry_referral( e ) ) {
132 /* entry is an referral, don't allow operation */
133 *text = "authorization entry is referral";
139 struct berval vals[2];
140 char textbuf[SLAP_TEXT_BUFLEN]; /* non-returnable */
143 vals[1].bv_val = NULL;
145 ml.sml_desc = slap_schema.si_ad_userPassword;
146 ml.sml_bvalues = vals;
147 ml.sml_op = LDAP_MOD_REPLACE;
150 rc = ldbm_modify_internal( be,
151 conn, op, op->o_ndn.bv_val, &ml, e, text, textbuf,
154 /* FIXME: ldbm_modify_internal may set *text = textbuf,
156 if ( *text == textbuf ) {
161 /* cannot return textbuf */
162 *text = "entry modify failed";
166 /* change the entry itself */
167 if( id2entry_add( be, e ) != 0 ) {
168 *text = "entry update failed";
172 if( rc == LDAP_SUCCESS ) {
173 replog( be, op, &e->e_name, &e->e_nname, &ml );
179 cache_return_entry_w( &li->li_cache, e );
180 ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);
183 if( hash.bv_val != NULL ) {
187 if( ndn.bv_val != NULL ) {