1 /* passwd.c - ldbm backend password routines */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2003 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
21 #include <ac/socket.h>
22 #include <ac/string.h>
25 #include "back-ldbm.h"
26 #include "proto-back-ldbm.h"
30 ldbm_back_exop_passwd(
34 struct ldbminfo *li = (struct ldbminfo *) op->o_bd->be_private;
37 struct berval hash = { 0, NULL };
39 struct berval id = { 0, NULL };
40 struct berval new = { 0, NULL };
42 struct berval dn = { 0, NULL };
43 struct berval ndn = { 0, NULL };
45 assert( ber_bvcmp( &slap_EXOP_MODIFY_PASSWD, &op->oq_extended.rs_reqoid ) == 0 );
47 rc = slap_passwd_parse( op->oq_extended.rs_reqdata,
48 &id, NULL, &new, &rs->sr_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 );
58 if( rc != LDAP_SUCCESS ) {
62 if( new.bv_len == 0 ) {
63 slap_passwd_generate(&new);
65 if( new.bv_len == 0 ) {
66 rs->sr_text = "password generation failed.";
71 rs->sr_rspdata = slap_passwd_return( &new );
74 slap_passwd_hash( &new, &hash, &rs->sr_text );
76 if( hash.bv_len == 0 ) {
77 if( !rs->sr_text ) rs->sr_text = "password hash failed";
89 LDAP_LOG( BACK_LDBM, DETAIL1,
90 "ldbm_back_exop_passwd: \"%s\"%s\n",
91 dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
93 Debug( LDAP_DEBUG_TRACE, "passwd: \"%s\"%s\n",
94 dn.bv_val, id.bv_len ? " (proxy)" : "", 0 );
97 if( dn.bv_len == 0 ) {
98 rs->sr_text = "No password is associated with the Root DSE";
99 rc = LDAP_UNWILLING_TO_PERFORM;
103 rc = dnNormalize( 0, NULL, NULL, &dn, &ndn, op->o_tmpmemctx );
104 if( rc != LDAP_SUCCESS ) {
105 rs->sr_text = "Invalid DN";
109 /* grab giant lock for writing */
110 ldap_pvt_thread_rdwr_wlock(&li->li_giant_rwlock);
112 e = dn2entry_w( op->o_bd, &ndn, NULL );
114 if ( e == NULL || is_entry_glue( e )) {
115 /* FIXME : dn2entry() should return non-glue entry */
116 ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);
117 rs->sr_text = "could not locate authorization entry";
118 rc = LDAP_NO_SUCH_OBJECT;
122 #ifdef LDBM_SUBENTRIES
123 if( is_entry_subentry( e ) ) {
124 /* entry is a subentry, don't allow operation */
125 rs->sr_text = "authorization entry is subentry";
131 if( is_entry_alias( e ) ) {
132 /* entry is an alias, don't allow operation */
133 rs->sr_text = "authorization entry is alias";
134 rc = LDAP_ALIAS_PROBLEM;
140 if( is_entry_referral( e ) ) {
141 /* entry is an referral, don't allow operation */
142 rs->sr_text = "authorization entry is referral";
148 struct berval vals[2];
149 char textbuf[SLAP_TEXT_BUFLEN]; /* non-returnable */
152 vals[1].bv_val = NULL;
154 ml.sml_desc = slap_schema.si_ad_userPassword;
155 ml.sml_values = vals;
156 ml.sml_nvalues = vals;
157 ml.sml_op = LDAP_MOD_REPLACE;
160 rc = ldbm_modify_internal( op,
161 &ml, e, &rs->sr_text, textbuf,
164 /* FIXME: ldbm_modify_internal may set *text = textbuf,
166 if ( rs->sr_text == textbuf ) {
171 /* cannot return textbuf */
172 rs->sr_text = "entry modify failed";
176 /* change the entry itself */
177 if( id2entry_add( op->o_bd, e ) != 0 ) {
178 rs->sr_text = "entry update failed";
182 if( rc == LDAP_SUCCESS ) {
189 cache_return_entry_w( &li->li_cache, e );
190 ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);
193 if( hash.bv_val != NULL ) {
197 if( ndn.bv_val != NULL ) {
198 op->o_tmpfree( ndn.bv_val, op->o_tmpmemctx );