1 /* modify.c - ldap backend modify function */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1999-2004 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 struct ldapinfo *li = (struct ldapinfo *) op->o_bd->be_private;
41 LDAPMod **modv = NULL;
46 struct berval mdn = BER_BVNULL;
51 LDAPControl **ctrls = NULL;
53 lc = ldap_back_getconn(op, rs);
54 if ( !lc || !ldap_back_dobind( lc, op, rs ) ) {
59 * Rewrite the modify dn, if needed
61 dc.rwmap = &li->rwmap;
70 if ( ldap_back_dn_massage( &dc, &op->o_req_ndn, &mdn ) ) {
71 send_ldap_result( op, rs );
75 for (i=0, ml=op->oq_modify.rs_modlist; ml; i++,ml=ml->sml_next)
78 mods = (LDAPMod *)ch_malloc(i*sizeof(LDAPMod));
83 modv = (LDAPMod **)ch_malloc((i+1)*sizeof(LDAPMod *));
90 dc.ctx = "modifyAttrDN";
93 isupdate = be_shadow_update( op );
94 for (i=0, ml=op->oq_modify.rs_modlist; ml; ml=ml->sml_next) {
97 if ( !isupdate && ml->sml_desc->ad_type->sat_no_user_mod ) {
101 if ( ml->sml_desc == slap_schema.si_ad_objectClass
102 || ml->sml_desc == slap_schema.si_ad_structuralObjectClass ) {
104 mapped = ml->sml_desc->ad_cname;
107 ldap_back_map(&li->rwmap.rwm_at,
108 &ml->sml_desc->ad_cname,
109 &mapped, BACKLDAP_MAP);
110 if (mapped.bv_val == NULL || mapped.bv_val[0] == '\0') {
116 mods[i].mod_op = ml->sml_op | LDAP_MOD_BVALUES;
117 mods[i].mod_type = mapped.bv_val;
119 if ( ml->sml_values != NULL ) {
121 for (j = 0; ml->sml_values[j].bv_val; j++);
122 mods[i].mod_bvalues = (struct berval **)ch_malloc((j+1) *
123 sizeof(struct berval *));
124 for (j = 0; ml->sml_values[j].bv_val; j++) {
125 ldap_back_map(&li->rwmap.rwm_oc,
127 &mapped, BACKLDAP_MAP);
128 if (mapped.bv_val == NULL || mapped.bv_val[0] == '\0') {
131 mods[i].mod_bvalues[j] = &mapped;
133 mods[i].mod_bvalues[j] = NULL;
136 if ( ml->sml_desc->ad_type->sat_syntax ==
137 slap_schema.si_syn_distinguishedName ) {
138 ldap_dnattr_rewrite( &dc, ml->sml_values );
141 if ( ml->sml_values == NULL ) {
145 for (j = 0; ml->sml_values[j].bv_val; j++);
146 mods[i].mod_bvalues = (struct berval **)ch_malloc((j+1) *
147 sizeof(struct berval *));
148 for (j = 0; ml->sml_values[j].bv_val; j++)
149 mods[i].mod_bvalues[j] = &ml->sml_values[j];
150 mods[i].mod_bvalues[j] = NULL;
154 mods[i].mod_bvalues = NULL;
162 #ifdef LDAP_BACK_PROXY_AUTHZ
163 rc = ldap_back_proxy_authz_ctrl( lc, op, rs, &ctrls );
164 if ( rc != LDAP_SUCCESS ) {
165 send_ldap_result( op, rs );
169 #endif /* LDAP_BACK_PROXY_AUTHZ */
172 rs->sr_err = ldap_modify_ext( lc->ld, mdn.bv_val, modv,
173 ctrls, NULL, &msgid );
174 rc = ldap_back_op_result( lc, op, rs, msgid, 1 );
175 if ( rs->sr_err == LDAP_UNAVAILABLE && do_retry ) {
177 if ( ldap_back_retry (lc, op, rs )) goto retry;
181 #ifdef LDAP_BACK_PROXY_AUTHZ
182 if ( ctrls && ctrls != op->o_ctrls ) {
186 #endif /* LDAP_BACK_PROXY_AUTHZ */
188 if ( mdn.bv_val != op->o_req_ndn.bv_val ) {
191 for (i=0; modv[i]; i++) {
192 ch_free(modv[i]->mod_bvalues);