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 = { 0, NULL };
49 #ifdef LDAP_BACK_PROXY_AUTHZ
50 LDAPControl **ctrls = NULL;
51 #endif /* LDAP_BACK_PROXY_AUTHZ */
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_dn, &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";
92 for (i=0, ml=op->oq_modify.rs_modlist; ml; ml=ml->sml_next) {
95 if ( ml->sml_desc->ad_type->sat_no_user_mod ) {
99 if ( ml->sml_desc == slap_schema.si_ad_objectClass
100 || ml->sml_desc == slap_schema.si_ad_structuralObjectClass ) {
102 mapped = ml->sml_desc->ad_cname;
105 ldap_back_map(&li->rwmap.rwm_at,
106 &ml->sml_desc->ad_cname,
107 &mapped, BACKLDAP_MAP);
108 if (mapped.bv_val == NULL || mapped.bv_val[0] == '\0') {
114 mods[i].mod_op = ml->sml_op | LDAP_MOD_BVALUES;
115 mods[i].mod_type = mapped.bv_val;
117 if ( ml->sml_bvalues != NULL ) {
119 for (j = 0; ml->sml_bvalues[j].bv_val; j++);
120 mods[i].mod_bvalues = (struct berval **)ch_malloc((j+1) *
121 sizeof(struct berval *));
122 for (j = 0; ml->sml_bvalues[j].bv_val; j++) {
123 ldap_back_map(&li->rwmap.rwm_oc,
125 &mapped, BACKLDAP_MAP);
126 if (mapped.bv_val == NULL || mapped.bv_val[0] == '\0') {
129 mods[i].mod_bvalues[j] = &mapped;
131 mods[i].mod_bvalues[j] = NULL;
134 if ( ml->sml_desc->ad_type->sat_syntax ==
135 slap_schema.si_syn_distinguishedName ) {
136 ldap_dnattr_rewrite( &dc, ml->sml_bvalues );
139 if ( ml->sml_bvalues == NULL ) {
143 for (j = 0; ml->sml_bvalues[j].bv_val; j++);
144 mods[i].mod_bvalues = (struct berval **)ch_malloc((j+1) *
145 sizeof(struct berval *));
146 for (j = 0; ml->sml_bvalues[j].bv_val; j++)
147 mods[i].mod_bvalues[j] = &ml->sml_bvalues[j];
148 mods[i].mod_bvalues[j] = NULL;
152 mods[i].mod_bvalues = NULL;
159 #ifdef LDAP_BACK_PROXY_AUTHZ
160 rc = ldap_back_proxy_authz_ctrl( lc, op, rs, &ctrls );
161 if ( rc != LDAP_SUCCESS ) {
164 #endif /* LDAP_BACK_PROXY_AUTHZ */
166 rs->sr_err = ldap_modify_ext( lc->ld, mdn.bv_val, modv,
167 #ifdef LDAP_BACK_PROXY_AUTHZ
169 #else /* ! LDAP_BACK_PROXY_AUTHZ */
171 #endif /* ! LDAP_BACK_PROXY_AUTHZ */
175 #ifdef LDAP_BACK_PROXY_AUTHZ
176 if ( ctrls && ctrls != op->o_ctrls ) {
180 #endif /* LDAP_BACK_PROXY_AUTHZ */
182 if ( mdn.bv_val != op->o_req_dn.bv_val ) {
185 for (i=0; modv[i]; i++) {
186 ch_free(modv[i]->mod_bvalues);
191 #ifdef LDAP_BACK_PROXY_AUTHZ
192 if ( rc != LDAP_SUCCESS ) {
193 send_ldap_result( op, rs );
196 #endif /* LDAP_BACK_PROXY_AUTHZ */
198 return ldap_back_op_result( lc, op, rs, msgid, 1 );