1 /* modify.c - ldap backend modify function */
2 /* $OpenLDAP: pkg/ldap/servers/slapd/back-ldap/modify.c,v 1.69.2.5 2008/02/11 23:26:46 kurt Exp $ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1999-2008 The OpenLDAP Foundation.
6 * Portions Copyright 1999-2003 Howard Chu.
7 * Portions Copyright 2000-2003 Pierangelo Masarati.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted only as authorized by the OpenLDAP
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>.
19 * This work was initially developed by the Howard Chu for inclusion
20 * in OpenLDAP Software and subsequently enhanced by Pierangelo
28 #include <ac/string.h>
29 #include <ac/socket.h>
32 #include "back-ldap.h"
39 ldapinfo_t
*li
= (ldapinfo_t
*)op
->o_bd
->be_private
;
41 ldapconn_t
*lc
= NULL
;
42 LDAPMod
**modv
= NULL
,
48 ldap_back_send_t retrying
= LDAP_BACK_RETRYING
;
49 LDAPControl
**ctrls
= NULL
;
51 if ( !ldap_back_dobind( &lc
, op
, rs
, LDAP_BACK_SENDERR
) ) {
55 for ( i
= 0, ml
= op
->orm_modlist
; ml
; i
++, ml
= ml
->sml_next
)
56 /* just count mods */ ;
58 modv
= (LDAPMod
**)ch_malloc( ( i
+ 1 )*sizeof( LDAPMod
* )
59 + i
*sizeof( LDAPMod
) );
64 mods
= (LDAPMod
*)&modv
[ i
+ 1 ];
66 isupdate
= be_shadow_update( op
);
67 for ( i
= 0, ml
= op
->orm_modlist
; ml
; ml
= ml
->sml_next
) {
68 if ( !isupdate
&& !get_relax( op
) && ml
->sml_desc
->ad_type
->sat_no_user_mod
)
73 modv
[ i
] = &mods
[ i
];
74 mods
[ i
].mod_op
= ( ml
->sml_op
| LDAP_MOD_BVALUES
);
75 mods
[ i
].mod_type
= ml
->sml_desc
->ad_cname
.bv_val
;
77 if ( ml
->sml_values
!= NULL
) {
78 if ( ml
->sml_values
== NULL
) {
82 for ( j
= 0; !BER_BVISNULL( &ml
->sml_values
[ j
] ); j
++ )
83 /* just count mods */ ;
84 mods
[ i
].mod_bvalues
=
85 (struct berval
**)ch_malloc( ( j
+ 1 )*sizeof( struct berval
* ) );
86 for ( j
= 0; !BER_BVISNULL( &ml
->sml_values
[ j
] ); j
++ )
88 mods
[ i
].mod_bvalues
[ j
] = &ml
->sml_values
[ j
];
90 mods
[ i
].mod_bvalues
[ j
] = NULL
;
93 mods
[ i
].mod_bvalues
= NULL
;
102 rc
= ldap_back_controls_add( op
, rs
, lc
, &ctrls
);
103 if ( rc
!= LDAP_SUCCESS
) {
104 send_ldap_result( op
, rs
);
109 rs
->sr_err
= ldap_modify_ext( lc
->lc_ld
, op
->o_req_dn
.bv_val
, modv
,
110 ctrls
, NULL
, &msgid
);
111 rc
= ldap_back_op_result( lc
, op
, rs
, msgid
,
112 li
->li_timeout
[ SLAP_OP_MODIFY
],
113 ( LDAP_BACK_SENDRESULT
| retrying
) );
114 if ( rs
->sr_err
== LDAP_UNAVAILABLE
&& retrying
) {
115 retrying
&= ~LDAP_BACK_RETRYING
;
116 if ( ldap_back_retry( &lc
, op
, rs
, LDAP_BACK_SENDERR
) ) {
117 /* if the identity changed, there might be need to re-authz */
118 (void)ldap_back_controls_free( op
, rs
, &ctrls
);
124 (void)ldap_back_controls_free( op
, rs
, &ctrls
);
126 for ( i
= 0; modv
[ i
]; i
++ ) {
127 ch_free( modv
[ i
]->mod_bvalues
);
132 ldap_back_release_conn( li
, lc
);