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;
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 );
50 LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
51 "ldbm_back_exop_passwd: \"%s\"\n",
52 id ? id->bv_val : "" ));
54 Debug( LDAP_DEBUG_ARGS, "==> ldbm_back_exop_passwd: \"%s\"\n",
55 id ? id->bv_val : "", 0, 0 );
59 if( rc != LDAP_SUCCESS ) {
63 if( new == NULL || new->bv_len == 0 ) {
64 new = slap_passwd_generate();
66 if( new == NULL || new->bv_len == 0 ) {
67 *text = "password generation failed.";
72 *rspdata = slap_passwd_return( new );
75 hash = slap_passwd_hash( new );
77 if( hash == NULL || hash->bv_len == 0 ) {
78 *text = "password hash failed";
83 dn = id ? id->bv_val : op->o_dn;
86 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
87 "ldbm_back_exop_passwd: \"%s\"%s\n",
88 dn, id ? " (proxy)" : "" ));
90 Debug( LDAP_DEBUG_TRACE, "passwd: \"%s\"%s\n",
91 dn, id ? " (proxy)" : "", 0 );
95 if( dn == NULL || dn[0] == '\0' ) {
96 *text = "No password is associated with the Root DSE";
97 rc = LDAP_OPERATIONS_ERROR;
101 if( dn_normalize( dn ) == NULL ) {
102 *text = "Invalid DN";
103 rc = LDAP_INVALID_DN_SYNTAX;
107 e = dn2entry_w( be, dn, NULL );
110 *text = "could not locate authorization entry";
111 rc = LDAP_NO_SUCH_OBJECT;
115 if( is_entry_alias( e ) ) {
116 /* entry is an alias, don't allow operation */
117 *text = "authorization entry is alias";
118 rc = LDAP_ALIAS_PROBLEM;
122 rc = LDAP_OPERATIONS_ERROR;
124 if( is_entry_referral( e ) ) {
125 /* entry is an referral, don't allow operation */
126 *text = "authorization entry is referral";
132 struct berval *vals[2];
133 char textbuf[SLAP_TEXT_BUFLEN]; /* non-returnable */
139 ml.sml_desc = slap_schema.si_ad_userPassword;
140 ml.sml_bvalues = vals;
141 ml.sml_op = LDAP_MOD_REPLACE;
144 rc = ldbm_modify_internal( be,
145 conn, op, op->o_ndn, &ml, e, text, textbuf, textlen );
147 /* FIXME: ldbm_modify_internal may set *tex = textbuf,
149 if ( *text == textbuf ) {
154 /* cannot return textbuf */
155 *text = "entry modify failed";
159 /* change the entry itself */
160 if( id2entry_add( be, e ) != 0 ) {
161 *text = "entry update failed";
165 replog( be, op, e->e_dn, &ml );
170 cache_return_entry_w( &li->li_cache, e );