]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldap/modify.c
fix response sending while rebinding (ITS#4597)
[openldap] / servers / slapd / back-ldap / modify.c
1 /* modify.c - ldap backend modify function */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 1999-2006 The OpenLDAP Foundation.
6  * Portions Copyright 1999-2003 Howard Chu.
7  * Portions Copyright 2000-2003 Pierangelo Masarati.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted only as authorized by the OpenLDAP
12  * Public License.
13  *
14  * A copy of this license is available in the file LICENSE in the
15  * top-level directory of the distribution or, alternatively, at
16  * <http://www.OpenLDAP.org/license.html>.
17  */
18 /* ACKNOWLEDGEMENTS:
19  * This work was initially developed by the Howard Chu for inclusion
20  * in OpenLDAP Software and subsequently enhanced by Pierangelo
21  * Masarati.
22  */
23
24 #include "portable.h"
25
26 #include <stdio.h>
27
28 #include <ac/string.h>
29 #include <ac/socket.h>
30
31 #include "slap.h"
32 #include "back-ldap.h"
33
34 int
35 ldap_back_modify(
36                 Operation       *op,
37                 SlapReply       *rs )
38 {
39         ldapinfo_t              *li = (ldapinfo_t *)op->o_bd->be_private;
40
41         ldapconn_t              *lc;
42         LDAPMod                 **modv = NULL,
43                                 *mods = NULL;
44         Modifications           *ml;
45         int                     i, j, rc;
46         ber_int_t               msgid;
47         int                     isupdate;
48         ldap_back_send_t        retrying = LDAP_BACK_RETRYING;
49         LDAPControl             **ctrls = NULL;
50
51         lc = ldap_back_getconn( op, rs, LDAP_BACK_SENDERR );
52         if ( !lc || !ldap_back_dobind( lc, op, rs, LDAP_BACK_SENDERR ) ) {
53                 return rs->sr_err;
54         }
55
56         for ( i = 0, ml = op->oq_modify.rs_modlist; ml; i++, ml = ml->sml_next )
57                 /* just count mods */ ;
58
59         modv = (LDAPMod **)ch_malloc( ( i + 1 )*sizeof( LDAPMod * )
60                         + i*sizeof( LDAPMod ) );
61         if ( modv == NULL ) {
62                 rc = LDAP_NO_MEMORY;
63                 goto cleanup;
64         }
65         mods = (LDAPMod *)&modv[ i + 1 ];
66
67         isupdate = be_shadow_update( op );
68         for ( i = 0, ml = op->oq_modify.rs_modlist; ml; ml = ml->sml_next ) {
69                 if ( !isupdate && !get_manageDIT( op ) && ml->sml_desc->ad_type->sat_no_user_mod  )
70                 {
71                         continue;
72                 }
73
74                 modv[ i ] = &mods[ i ];
75                 mods[ i ].mod_op = ( ml->sml_op | LDAP_MOD_BVALUES );
76                 mods[ i ].mod_type = ml->sml_desc->ad_cname.bv_val;
77
78                 if ( ml->sml_values != NULL ) {
79                         if ( ml->sml_values == NULL ) { 
80                                 continue;
81                         }
82
83                         for ( j = 0; !BER_BVISNULL( &ml->sml_values[ j ] ); j++ )
84                                 /* just count mods */ ;
85                         mods[ i ].mod_bvalues =
86                                 (struct berval **)ch_malloc( ( j + 1 )*sizeof( struct berval * ) );
87                         for ( j = 0; !BER_BVISNULL( &ml->sml_values[ j ] ); j++ )
88                         {
89                                 mods[ i ].mod_bvalues[ j ] = &ml->sml_values[ j ];
90                         }
91                         mods[ i ].mod_bvalues[ j ] = NULL;
92
93                 } else {
94                         mods[ i ].mod_bvalues = NULL;
95                 }
96
97                 i++;
98         }
99         modv[ i ] = 0;
100
101         ctrls = op->o_ctrls;
102         rc = ldap_back_proxy_authz_ctrl( &lc->lc_bound_ndn,
103                 li->li_version, &li->li_idassert, op, rs, &ctrls );
104         if ( rc != LDAP_SUCCESS ) {
105                 send_ldap_result( op, rs );
106                 rc = -1;
107                 goto cleanup;
108         }
109
110 retry:
111         rs->sr_err = ldap_modify_ext( lc->lc_ld, op->o_req_dn.bv_val, modv,
112                         ctrls, NULL, &msgid );
113         rc = ldap_back_op_result( lc, op, rs, msgid,
114                 li->li_timeout[ LDAP_BACK_OP_MODIFY],
115                 ( LDAP_BACK_SENDRESULT | retrying ) );
116         if ( rs->sr_err == LDAP_UNAVAILABLE && retrying ) {
117                 retrying &= ~LDAP_BACK_RETRYING;
118                 if ( ldap_back_retry( &lc, op, rs, LDAP_BACK_SENDERR ) ) {
119                         goto retry;
120                 }
121         }
122
123 cleanup:;
124         (void)ldap_back_proxy_authz_ctrl_free( op, &ctrls );
125
126         for ( i = 0; modv[ i ]; i++ ) {
127                 ch_free( modv[ i ]->mod_bvalues );
128         }
129         ch_free( modv );
130
131         if ( lc != NULL ) {
132                 ldap_back_release_conn( op, rs, lc );
133         }
134
135         return rc;
136 }
137