1 /* passwd.c - ldbm backend password routines */
4 * Copyright 1998-2000 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,
30 struct berval *** refs
33 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
36 struct berval *hash = NULL;
38 struct berval *id = NULL;
39 struct berval *new = NULL;
44 assert( reqoid != NULL );
45 assert( strcmp( LDAP_EXOP_X_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 ? id->bv_val : "" ));
55 Debug( LDAP_DEBUG_ARGS, "==> ldbm_back_exop_passwd: \"%s\"\n",
56 id ? id->bv_val : "", 0, 0 );
60 if( rc != LDAP_SUCCESS ) {
64 if( new == NULL || new->bv_len == 0 ) {
65 new = slap_passwd_generate();
67 if( new == NULL || new->bv_len == 0 ) {
68 *text = "password generation failed.";
73 *rspdata = slap_passwd_return( new );
76 hash = slap_passwd_hash( new );
78 if( hash == NULL || 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 ? " (proxy)" : "" ));
95 Debug( LDAP_DEBUG_TRACE, "passwd: \"%s\"%s\n",
96 dn.bv_val, id ? " (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 e = dn2entry_w( be, ndn.bv_val, NULL );
113 *text = "could not locate authorization entry";
114 rc = LDAP_NO_SUCH_OBJECT;
118 if( is_entry_alias( e ) ) {
119 /* entry is an alias, don't allow operation */
120 *text = "authorization entry is alias";
121 rc = LDAP_ALIAS_PROBLEM;
125 rc = LDAP_OPERATIONS_ERROR;
127 if( is_entry_referral( e ) ) {
128 /* entry is an referral, don't allow operation */
129 *text = "authorization entry is referral";
135 struct berval *vals[2];
136 char textbuf[SLAP_TEXT_BUFLEN]; /* non-returnable */
141 ml.sml_desc = slap_schema.si_ad_userPassword;
142 ml.sml_bvalues = vals;
143 ml.sml_op = LDAP_MOD_REPLACE;
146 rc = ldbm_modify_internal( be,
147 conn, op, op->o_ndn.bv_val, &ml, e, text, textbuf,
150 /* FIXME: ldbm_modify_internal may set *text = textbuf,
152 if ( *text == textbuf ) {
157 /* cannot return textbuf */
158 *text = "entry modify failed";
162 /* change the entry itself */
163 if( id2entry_add( be, e ) != 0 ) {
164 *text = "entry update failed";
168 if( rc == LDAP_SUCCESS ) {
169 replog( be, op, &e->e_name, &e->e_nname, &ml );
175 cache_return_entry_w( &li->li_cache, e );
190 if( ndn.bv_val != NULL ) {