]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/passwd.c
SLAPD_SCHEMA_NOT_COMPAT: framework for value_match() and value_find()
[openldap] / servers / slapd / back-ldbm / passwd.c
1 /* extended.c - ldbm backend extended routines */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11
12 #include <ac/socket.h>
13 #include <ac/string.h>
14
15 #include "slap.h"
16 #include "back-ldbm.h"
17 #include "proto-back-ldbm.h"
18
19 int
20 ldbm_back_exop_passwd(
21     Backend             *be,
22     Connection          *conn,
23     Operation           *op,
24         char            *reqoid,
25     struct berval       *reqdata,
26         char            **rspoid,
27     struct berval       **rspdata,
28         LDAPControl *** rspctrls,
29         char**  text,
30     struct berval       *** refs
31 )
32 {
33         struct ldbminfo *li = (struct ldbminfo *) be->be_private;
34         int rc;
35         Entry *e = NULL;
36         struct berval *hash = NULL;
37
38         struct berval *id = NULL;
39         struct berval *new = NULL;
40
41         char *dn;
42
43 #ifdef SLAPD_SCHEMA_NOT_COMPAT
44         static AttributeDescription *entry = NULL;
45 #else
46         static const char *entry = "entry";
47 #endif
48
49         assert( reqoid != NULL );
50         assert( strcmp( LDAP_EXOP_X_MODIFY_PASSWD, reqoid ) == 0 );
51
52         rc = slap_passwd_parse( reqdata,
53                 &id, NULL, &new, text );
54
55         Debug( LDAP_DEBUG_ARGS, "==> ldbm_back_exop_passwd: \"%s\"\n",
56                 id ? id->bv_val : "", 0, 0 );
57
58         if( rc != LDAP_SUCCESS ) {
59                 goto done;
60         }
61
62         if( new == NULL || new->bv_len == 0 ) {
63                 new = slap_passwd_generate();
64
65                 if( new == NULL || new->bv_len == 0 ) {
66                         *text = "password generation failed.";
67                         rc = LDAP_OTHER;
68                         goto done;
69                 }
70                 
71                 *rspdata = slap_passwd_return( new );
72         }
73
74         hash = slap_passwd_hash( new );
75
76         if( hash == NULL || hash->bv_len == 0 ) {
77                 *text = "password hash failed";
78                 rc = LDAP_OTHER;
79                 goto done;
80         }
81
82         dn = id ? id->bv_val : op->o_dn;
83
84         Debug( LDAP_DEBUG_TRACE, "passwd: \"%s\"%s\n",
85                 dn, id ? " (proxy)" : "", 0 );
86
87         if( dn == NULL || dn[0] == '\0' ) {
88                 *text = "No password is associated with the Root DSE";
89                 rc = LDAP_OPERATIONS_ERROR;
90                 goto done;
91         }
92
93         e = dn2entry_w( be, dn, NULL );
94
95         if( e == NULL ) {
96                 *text = "could not locate authorization entry";
97                 rc = LDAP_OPERATIONS_ERROR;
98                 goto done;
99         }
100
101         if( ! access_allowed( be, conn, op, e, entry, NULL, ACL_WRITE ) ) {
102                 *text = "access to authorization entry denied";
103                 rc = LDAP_INSUFFICIENT_ACCESS;
104                 goto done;
105         }
106
107         if( is_entry_alias( e ) ) {
108                 /* entry is an alias, don't allow operation */
109                 *text = "authorization entry is alias";
110                 rc = LDAP_ALIAS_PROBLEM;
111                 goto done;
112         }
113
114         rc = LDAP_OPERATIONS_ERROR;
115
116         if( is_entry_referral( e ) ) {
117                 /* entry is an referral, don't allow operation */
118                 *text = "authorization entry is referral";
119                 goto done;
120         }
121
122         {
123                 Modifications ml;
124                 struct berval *vals[2];
125
126                 vals[0] = hash;
127                 vals[1] = NULL;
128
129 #ifdef SLAPD_SCHEMA_NOT_COMPAT
130                 ml.sml_desc = slap_schema.si_ad_userPassword;
131 #else
132                 ml.sml_type = ch_strdup("userPassword");
133 #endif
134                 ml.sml_bvalues = vals;
135                 ml.sml_op = LDAP_MOD_REPLACE;
136                 ml.sml_next = NULL;
137
138                 rc = ldbm_modify_internal( be,
139                         conn, op, op->o_ndn, &ml, e );
140
141 #ifndef SLAPD_SCHEMA_NOT_COMPAT
142                 ch_free(ml.ml_type);
143 #endif
144         }
145
146         if( rc == LDAP_SUCCESS ) {
147                 /* change the entry itself */
148                 if( id2entry_add( be, e ) != 0 ) {
149                         *text = "entry update failed";
150                         rc = LDAP_OTHER;
151                 }
152         }
153         
154 done:
155         if( e != NULL ) {
156                 cache_return_entry_w( &li->li_cache, e );
157         }
158
159         if( id != NULL ) {
160                 ber_bvfree( id );
161         }
162
163         if( new != NULL ) {
164                 ber_bvfree( new );
165         }
166
167         if( hash != NULL ) {
168                 ber_bvfree( hash );
169         }
170
171         return rc;
172 }