]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldap/modify.c
remove unrequired member; address ITS#3913
[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-2005 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         struct ldapconn *lc;
40         LDAPMod         **modv = NULL,
41                         *mods = NULL;
42         Modifications   *ml;
43         int             i, j, rc;
44         ber_int_t       msgid;
45         int             isupdate;
46         int             do_retry = 1;
47         LDAPControl     **ctrls = NULL;
48
49         lc = ldap_back_getconn( op, rs, LDAP_BACK_SENDERR );
50         if ( !lc || !ldap_back_dobind( lc, op, rs, LDAP_BACK_SENDERR ) ) {
51                 return rs->sr_err;
52         }
53
54         for ( i = 0, ml = op->oq_modify.rs_modlist; ml; i++, ml = ml->sml_next )
55                 /* just count mods */ ;
56
57         modv = (LDAPMod **)ch_malloc( ( i + 1 )*sizeof( LDAPMod * )
58                         + i*sizeof( LDAPMod ) );
59         if ( modv == NULL ) {
60                 rc = LDAP_NO_MEMORY;
61                 goto cleanup;
62         }
63         mods = (LDAPMod *)&modv[ i + 1 ];
64
65         isupdate = be_shadow_update( op );
66         for ( i = 0, ml = op->oq_modify.rs_modlist; ml; ml = ml->sml_next ) {
67                 if ( !isupdate && ml->sml_desc->ad_type->sat_no_user_mod  ) {
68                         continue;
69                 }
70
71                 modv[ i ] = &mods[ i ];
72                 mods[ i ].mod_op = ( ml->sml_op | LDAP_MOD_BVALUES );
73                 mods[ i ].mod_type = ml->sml_desc->ad_cname.bv_val;
74
75                 if ( ml->sml_values != NULL ) {
76                         if ( ml->sml_values == NULL ) { 
77                                 continue;
78                         }
79
80                         for ( j = 0; !BER_BVISNULL( &ml->sml_values[ j ] ); j++ )
81                                 /* just count mods */ ;
82                         mods[ i ].mod_bvalues =
83                                 (struct berval **)ch_malloc( ( j + 1 )*sizeof( struct berval * ) );
84                         for ( j = 0; !BER_BVISNULL( &ml->sml_values[ j ] ); j++ )
85                         {
86                                 mods[ i ].mod_bvalues[ j ] = &ml->sml_values[ j ];
87                         }
88                         mods[ i ].mod_bvalues[ j ] = NULL;
89
90                 } else {
91                         mods[ i ].mod_bvalues = NULL;
92                 }
93
94                 i++;
95         }
96         modv[ i ] = 0;
97
98         ctrls = op->o_ctrls;
99         rc = ldap_back_proxy_authz_ctrl( lc, op, rs, &ctrls );
100         if ( rc != LDAP_SUCCESS ) {
101                 send_ldap_result( op, rs );
102                 rc = -1;
103                 goto cleanup;
104         }
105
106 retry:
107         rs->sr_err = ldap_modify_ext( lc->lc_ld, op->o_req_ndn.bv_val, modv,
108                         ctrls, NULL, &msgid );
109         rc = ldap_back_op_result( lc, op, rs, msgid, LDAP_BACK_SENDRESULT );
110         if ( rs->sr_err == LDAP_UNAVAILABLE && do_retry ) {
111                 do_retry = 0;
112                 if ( ldap_back_retry( lc, op, rs, LDAP_BACK_SENDERR ) ) {
113                         goto retry;
114                 }
115         }
116
117 cleanup:;
118         (void)ldap_back_proxy_authz_ctrl_free( op, &ctrls );
119
120         for ( i = 0; modv[ i ]; i++ ) {
121                 ch_free( modv[ i ]->mod_bvalues );
122         }
123         ch_free( modv );
124
125         if ( lc != NULL ) {
126                 ldap_back_release_conn( op, rs, lc );
127         }
128
129         return rc;
130 }
131