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 #ifdef LDAP_BACK_PROXY_AUTHZ
51 LDAPControl **ctrls = NULL;
52 #endif /* LDAP_BACK_PROXY_AUTHZ */
54 lc = ldap_back_getconn(op, rs);
55 if ( !lc || !ldap_back_dobind( lc, op, rs ) ) {
60 * Rewrite the modify dn, if needed
62 dc.rwmap = &li->rwmap;
71 if ( ldap_back_dn_massage( &dc, &op->o_req_ndn, &mdn ) ) {
72 send_ldap_result( op, rs );
76 for (i=0, ml=op->oq_modify.rs_modlist; ml; i++,ml=ml->sml_next)
79 mods = (LDAPMod *)ch_malloc(i*sizeof(LDAPMod));
84 modv = (LDAPMod **)ch_malloc((i+1)*sizeof(LDAPMod *));
91 dc.ctx = "modifyAttrDN";
94 isupdate = be_shadow_update( op );
95 for (i=0, ml=op->oq_modify.rs_modlist; ml; ml=ml->sml_next) {
98 if ( !isupdate && ml->sml_desc->ad_type->sat_no_user_mod ) {
102 if ( ml->sml_desc == slap_schema.si_ad_objectClass
103 || ml->sml_desc == slap_schema.si_ad_structuralObjectClass ) {
105 mapped = ml->sml_desc->ad_cname;
108 ldap_back_map(&li->rwmap.rwm_at,
109 &ml->sml_desc->ad_cname,
110 &mapped, BACKLDAP_MAP);
111 if (mapped.bv_val == NULL || mapped.bv_val[0] == '\0') {
117 mods[i].mod_op = ml->sml_op | LDAP_MOD_BVALUES;
118 mods[i].mod_type = mapped.bv_val;
120 if ( ml->sml_values != NULL ) {
122 for (j = 0; ml->sml_values[j].bv_val; j++);
123 mods[i].mod_bvalues = (struct berval **)ch_malloc((j+1) *
124 sizeof(struct berval *));
125 for (j = 0; ml->sml_values[j].bv_val; j++) {
126 ldap_back_map(&li->rwmap.rwm_oc,
128 &mapped, BACKLDAP_MAP);
129 if (mapped.bv_val == NULL || mapped.bv_val[0] == '\0') {
132 mods[i].mod_bvalues[j] = &mapped;
134 mods[i].mod_bvalues[j] = NULL;
137 if ( ml->sml_desc->ad_type->sat_syntax ==
138 slap_schema.si_syn_distinguishedName ) {
139 ldap_dnattr_rewrite( &dc, ml->sml_values );
142 if ( ml->sml_values == NULL ) {
146 for (j = 0; ml->sml_values[j].bv_val; j++);
147 mods[i].mod_bvalues = (struct berval **)ch_malloc((j+1) *
148 sizeof(struct berval *));
149 for (j = 0; ml->sml_values[j].bv_val; j++)
150 mods[i].mod_bvalues[j] = &ml->sml_values[j];
151 mods[i].mod_bvalues[j] = NULL;
155 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 ) {
167 #endif /* LDAP_BACK_PROXY_AUTHZ */
169 rs->sr_err = ldap_modify_ext( lc->ld, mdn.bv_val, modv,
170 #ifdef LDAP_BACK_PROXY_AUTHZ
172 #else /* ! LDAP_BACK_PROXY_AUTHZ */
174 #endif /* ! LDAP_BACK_PROXY_AUTHZ */
178 #ifdef LDAP_BACK_PROXY_AUTHZ
179 if ( ctrls && ctrls != op->o_ctrls ) {
183 #endif /* LDAP_BACK_PROXY_AUTHZ */
185 if ( mdn.bv_val != op->o_req_ndn.bv_val ) {
188 for (i=0; modv[i]; i++) {
189 ch_free(modv[i]->mod_bvalues);
194 #ifdef LDAP_BACK_PROXY_AUTHZ
195 if ( rc != LDAP_SUCCESS ) {
196 send_ldap_result( op, rs );
199 #endif /* LDAP_BACK_PROXY_AUTHZ */
201 return ldap_back_op_result( lc, op, rs, msgid, 1 );