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;
50 LDAPControl **ctrls = NULL;
52 lc = ldap_back_getconn(op, rs);
53 if ( !lc || !ldap_back_dobind( lc, op, rs ) ) {
58 * Rewrite the modify dn, if needed
60 dc.rwmap = &li->rwmap;
69 if ( ldap_back_dn_massage( &dc, &op->o_req_ndn, &mdn ) ) {
70 send_ldap_result( op, rs );
74 for (i=0, ml=op->oq_modify.rs_modlist; ml; i++,ml=ml->sml_next)
77 mods = (LDAPMod *)ch_malloc(i*sizeof(LDAPMod));
82 modv = (LDAPMod **)ch_malloc((i+1)*sizeof(LDAPMod *));
89 dc.ctx = "modifyAttrDN";
92 isupdate = be_shadow_update( op );
93 for (i=0, ml=op->oq_modify.rs_modlist; ml; ml=ml->sml_next) {
96 if ( !isupdate && ml->sml_desc->ad_type->sat_no_user_mod ) {
100 if ( ml->sml_desc == slap_schema.si_ad_objectClass
101 || ml->sml_desc == slap_schema.si_ad_structuralObjectClass ) {
103 mapped = ml->sml_desc->ad_cname;
106 ldap_back_map(&li->rwmap.rwm_at,
107 &ml->sml_desc->ad_cname,
108 &mapped, BACKLDAP_MAP);
109 if (mapped.bv_val == NULL || mapped.bv_val[0] == '\0') {
115 mods[i].mod_op = ml->sml_op | LDAP_MOD_BVALUES;
116 mods[i].mod_type = mapped.bv_val;
118 if ( ml->sml_values != NULL ) {
120 for (j = 0; ml->sml_values[j].bv_val; j++);
121 mods[i].mod_bvalues = (struct berval **)ch_malloc((j+1) *
122 sizeof(struct berval *));
123 for (j = 0; ml->sml_values[j].bv_val; j++) {
124 ldap_back_map(&li->rwmap.rwm_oc,
126 &mapped, BACKLDAP_MAP);
127 if (mapped.bv_val == NULL || mapped.bv_val[0] == '\0') {
130 mods[i].mod_bvalues[j] = &mapped;
132 mods[i].mod_bvalues[j] = NULL;
135 if ( ml->sml_desc->ad_type->sat_syntax ==
136 slap_schema.si_syn_distinguishedName ) {
137 ldap_dnattr_rewrite( &dc, ml->sml_values );
140 if ( ml->sml_values == NULL ) {
144 for (j = 0; ml->sml_values[j].bv_val; j++);
145 mods[i].mod_bvalues = (struct berval **)ch_malloc((j+1) *
146 sizeof(struct berval *));
147 for (j = 0; ml->sml_values[j].bv_val; j++)
148 mods[i].mod_bvalues[j] = &ml->sml_values[j];
149 mods[i].mod_bvalues[j] = NULL;
153 mods[i].mod_bvalues = NULL;
161 #ifdef LDAP_BACK_PROXY_AUTHZ
162 rc = ldap_back_proxy_authz_ctrl( lc, op, rs, &ctrls );
163 if ( rc != LDAP_SUCCESS ) {
166 #endif /* LDAP_BACK_PROXY_AUTHZ */
168 rs->sr_err = ldap_modify_ext( lc->ld, mdn.bv_val, modv,
169 ctrls, NULL, &msgid );
172 #ifdef LDAP_BACK_PROXY_AUTHZ
173 if ( ctrls && ctrls != op->o_ctrls ) {
177 #endif /* LDAP_BACK_PROXY_AUTHZ */
179 if ( mdn.bv_val != op->o_req_ndn.bv_val ) {
182 for (i=0; modv[i]; i++) {
183 ch_free(modv[i]->mod_bvalues);
188 #ifdef LDAP_BACK_PROXY_AUTHZ
189 if ( rc != LDAP_SUCCESS ) {
190 send_ldap_result( op, rs );
193 #endif /* LDAP_BACK_PROXY_AUTHZ */
195 return ldap_back_op_result( lc, op, rs, msgid, 1 );