1 /* extended.c - ldbm backend extended routines */
4 * Copyright 1998-1999 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 );
49 Debug( LDAP_DEBUG_ARGS, "==> ldbm_back_exop_passwd: \"%s\"\n",
50 id ? id->bv_val : "", 0, 0 );
52 if( rc != LDAP_SUCCESS ) {
56 if( new == NULL || new->bv_len == 0 ) {
57 new = slap_passwd_generate();
59 if( new == NULL || new->bv_len == 0 ) {
60 *text = ch_strdup("password generation failed.");
61 rc = LDAP_OPERATIONS_ERROR;
65 *rspdata = slap_passwd_return( new );
68 hash = slap_passwd_hash( new );
70 if( hash == NULL || hash->bv_len == 0 ) {
71 *text = ch_strdup("password hash failed");
72 rc = LDAP_OPERATIONS_ERROR;
76 dn = id ? id->bv_val : op->o_dn;
78 Debug( LDAP_DEBUG_TRACE, "passwd: \"%s\"%s\n",
79 dn, id ? " (proxy)" : "", 0 );
81 if( dn == NULL || dn[0] == '\0' ) {
82 *text = ch_strdup("No password is associated with the Root DSE");
83 rc = LDAP_OPERATIONS_ERROR;
87 e = dn2entry_w( be, dn, NULL );
90 *text = ch_strdup("could not locate authorization entry");
91 rc = LDAP_OPERATIONS_ERROR;
95 if( ! access_allowed( be, conn, op, e, "entry", NULL, ACL_WRITE ) ) {
96 *text = ch_strdup("access to authorization entry denied");
97 rc = LDAP_INSUFFICIENT_ACCESS;
101 if( is_entry_alias( e ) ) {
102 /* entry is an alias, don't allow operation */
103 *text = ch_strdup("authorization entry is alias");
104 rc = LDAP_ALIAS_PROBLEM;
108 rc = LDAP_OPERATIONS_ERROR;
110 if( is_entry_referral( e ) ) {
111 /* entry is an referral, don't allow operation */
112 *text = ch_strdup("authorization entry is referral");
118 struct berval *vals[2];
123 #ifdef SLAPD_SCHEMA_NOT_COMPAT
124 /* not yet implemented */
126 ml.ml_type = ch_strdup("userPassword");
127 ml.ml_bvalues = vals;
128 ml.ml_op = LDAP_MOD_REPLACE;
132 rc = ldbm_modify_internal( be,
133 conn, op, op->o_ndn, &ml, e );
135 #ifdef SLAPD_SCHEMA_NOT_COMPAT
136 /* not yet implemented */
142 if( rc == LDAP_SUCCESS ) {
143 /* change the entry itself */
144 if( id2entry_add( be, e ) != 0 ) {
145 rc = LDAP_OPERATIONS_ERROR;
151 cache_return_entry_w( &li->li_cache, e );