]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldap/modify.c
remove rewrite stuff -- now delegted to rwm overlay
[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-2004 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 );
50         if ( !lc || !ldap_back_dobind( lc, op, rs ) ) {
51                 return -1;
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 #ifdef LDAP_BACK_PROXY_AUTHZ
100         rc = ldap_back_proxy_authz_ctrl( lc, op, rs, &ctrls );
101         if ( rc != LDAP_SUCCESS ) {
102                 send_ldap_result( op, rs );
103                 rc = -1;
104                 goto cleanup;
105         }
106 #endif /* LDAP_BACK_PROXY_AUTHZ */
107
108 retry:
109         rs->sr_err = ldap_modify_ext( lc->lc_ld, op->o_req_ndn.bv_val, modv,
110                         ctrls, NULL, &msgid );
111         rc = ldap_back_op_result( lc, op, rs, msgid, 1 );
112         if ( rs->sr_err == LDAP_UNAVAILABLE && do_retry ) {
113                 do_retry = 0;
114                 if ( ldap_back_retry(lc, op, rs ) ) {
115                         goto retry;
116                 }
117         }
118
119 cleanup:;
120 #ifdef LDAP_BACK_PROXY_AUTHZ
121         (void)ldap_back_proxy_authz_ctrl_free( op, &ctrls );
122 #endif /* LDAP_BACK_PROXY_AUTHZ */
123
124         for ( i = 0; modv[ i ]; i++ ) {
125                 ch_free( modv[ i ]->mod_bvalues );
126         }
127         ch_free( modv );
128
129         return rc;
130 }
131