]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/passwd.c
Remove lint
[openldap] / servers / slapd / back-ldbm / passwd.c
1 /* extended.c - ldbm backend extended routines */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-1999 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            *oid,
25     struct berval       *reqdata,
26     struct berval       **rspdata,
27         LDAPControl *** rspctrls,
28         char**  text
29 )
30 {
31         struct ldbminfo *li = (struct ldbminfo *) be->be_private;
32         int rc;
33         Entry *e = NULL;
34         struct berval *hash = NULL;
35
36         struct berval *id = NULL;
37         struct berval *new = NULL;
38
39         char *dn;
40
41         assert( oid != NULL );
42         assert( strcmp( LDAP_EXOP_X_MODIFY_PASSWD, oid ) == 0 );
43
44         rc = slap_passwd_parse( reqdata,
45                 &id, NULL, &new, text );
46
47         Debug( LDAP_DEBUG_ARGS, "==> ldbm_back_exop_passwd: \"%s\"\n",
48                 id ? id->bv_val : "", 0, 0 );
49
50         if( rc != LDAP_SUCCESS ) {
51                 goto done;
52         }
53
54         if( new == NULL || new->bv_len == 0 ) {
55                 new = slap_passwd_generate();
56
57                 if( new == NULL || new->bv_len == 0 ) {
58                         *text = ch_strdup("password generation failed.");
59                         rc = LDAP_OPERATIONS_ERROR;
60                         goto done;
61                 }
62                 
63                 *rspdata = slap_passwd_return( new );
64         }
65
66         hash = slap_passwd_hash( new );
67
68         if( hash == NULL || hash->bv_len == 0 ) {
69                 *text = ch_strdup("password hash failed");
70                 rc = LDAP_OPERATIONS_ERROR;
71                 goto done;
72         }
73
74         dn = id ? id->bv_val : op->o_dn;
75
76         Debug( LDAP_DEBUG_TRACE, "passwd: \"%s\"%s\n",
77                 dn, id ? " (proxy)" : "", 0 );
78
79         if( dn == NULL || dn[0] == '\0' ) {
80                 *text = ch_strdup("No password is associated with the Root DSE");
81                 rc = LDAP_OPERATIONS_ERROR;
82                 goto done;
83         }
84
85         e = dn2entry_w( be, dn, NULL );
86
87         if( e == NULL ) {
88                 *text = ch_strdup("could not locate authorization entry");
89                 rc = LDAP_OPERATIONS_ERROR;
90                 goto done;
91         }
92
93         if( ! access_allowed( be, conn, op, e, "entry", NULL, ACL_WRITE ) ) {
94                 *text = ch_strdup("access to authorization entry denied");
95                 rc = LDAP_INSUFFICIENT_ACCESS;
96                 goto done;
97         }
98
99         if( is_entry_alias( e ) ) {
100                 /* entry is an alias, don't allow operation */
101                 *text = ch_strdup("authorization entry is alias");
102                 rc = LDAP_ALIAS_PROBLEM;
103                 goto done;
104         }
105
106         rc = LDAP_OPERATIONS_ERROR;
107
108         if( is_entry_referral( e ) ) {
109                 /* entry is an referral, don't allow operation */
110                 *text = ch_strdup("authorization entry is referral");
111                 goto done;
112         }
113
114         {
115                 LDAPModList ml;
116                 struct berval *vals[2];
117
118                 vals[0] = hash;
119                 vals[1] = NULL;
120
121                 ml.ml_type = ch_strdup("userPassword");
122                 ml.ml_bvalues = vals;
123                 ml.ml_op = LDAP_MOD_REPLACE | LDAP_MOD_BVALUES;
124                 ml.ml_next = NULL;
125
126                 rc = ldbm_modify_internal( be,
127                         conn, op, op->o_ndn, &ml, e );
128
129                 ch_free(ml.ml_type);
130         }
131
132         if( rc == LDAP_SUCCESS ) {
133                 /* change the entry itself */
134                 if( id2entry_add( be, e ) != 0 ) {
135                         rc = LDAP_OPERATIONS_ERROR;
136                 }
137         }
138         
139 done:
140         if( e != NULL ) {
141                 cache_return_entry_w( &li->li_cache, e );
142         }
143
144         if( id != NULL ) {
145                 ber_bvfree( id );
146         }
147
148         if( new != NULL ) {
149                 ber_bvfree( new );
150         }
151
152         if( hash != NULL ) {
153                 ber_bvfree( hash );
154         }
155
156         return rc;
157 }