2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2003 The OpenLDAP Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
11 * A copy of this license is available in the file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
16 * This work was initially developed by the Howard Chu for inclusion
17 * in OpenLDAP Software and subsequently enhanced by Pierangelo
20 /* This is an altered version */
22 * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
24 * This work has been developed to fulfill the requirements
25 * of SysNet s.n.c. <http:www.sys-net.it> and it has been donated
26 * to the OpenLDAP Foundation in the hope that it may be useful
27 * to the Open Source community, but WITHOUT ANY WARRANTY.
29 * Permission is granted to anyone to use this software for any purpose
30 * on any computer system, and to alter it and redistribute it, subject
31 * to the following restrictions:
33 * 1. The author and SysNet s.n.c. are not responsible for the consequences
34 * of use of this software, no matter how awful, even if they arise from
37 * 2. The origin of this software must not be misrepresented, either by
38 * explicit claim or by omission. Since few users ever read sources,
39 * credits should appear in the documentation.
41 * 3. Altered versions must be plainly marked as such, and must not be
42 * misrepresented as being the original software. Since few users
43 * ever read sources, credits should appear in the documentation.
44 * SysNet s.n.c. cannot be responsible for the consequences of the
47 * 4. This notice may not be removed or altered.
50 * This software is based on the backend back-ldap, implemented
51 * by Howard Chu <hyc@highlandsun.com>, and modified by Mark Valence
52 * <kurash@sassafras.com>, Pierangelo Masarati <ando@sys-net.it> and other
53 * contributors. The contribution of the original software to the present
54 * implementation is acknowledged in this copyright statement.
56 * A special acknowledgement goes to Howard for the overall architecture
57 * (and for borrowing large pieces of code), and to Mark, who implemented
58 * from scratch the attribute/objectclass mapping.
60 * The original copyright statement follows.
62 * Copyright 1999, Howard Chu, All rights reserved. <hyc@highlandsun.com>
64 * Permission is granted to anyone to use this software for any purpose
65 * on any computer system, and to alter it and redistribute it, subject
66 * to the following restrictions:
68 * 1. The author is not responsible for the consequences of use of this
69 * software, no matter how awful, even if they arise from flaws in it.
71 * 2. The origin of this software must not be misrepresented, either by
72 * explicit claim or by omission. Since few users ever read sources,
73 * credits should appear in the documentation.
75 * 3. Altered versions must be plainly marked as such, and must not be
76 * misrepresented as being the original software. Since few users
77 * ever read sources, credits should appear in the
80 * 4. This notice may not be removed or altered.
88 #include <ac/string.h>
89 #include <ac/socket.h>
92 #include "../back-ldap/back-ldap.h"
93 #include "back-meta.h"
96 meta_back_modify( Operation *op, SlapReply *rs )
98 struct metainfo *li = ( struct metainfo * )op->o_bd->be_private;
101 LDAPMod **modv = NULL;
102 LDAPMod *mods = NULL;
104 int candidate = -1, i;
105 struct berval mdn = { 0, NULL };
106 struct berval mapped;
109 lc = meta_back_getconn( op, rs, META_OP_REQUIRE_SINGLE,
110 &op->o_req_ndn, &candidate );
116 if ( !meta_back_dobind( lc, op )
117 || !meta_back_is_valid( lc, candidate ) ) {
118 rs->sr_err = LDAP_OTHER;
124 * Rewrite the modify dn, if needed
126 dc.rwmap = &li->targets[ candidate ]->rwmap;
127 dc.conn = op->o_conn;
131 if ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
136 for ( i = 0, ml = op->oq_modify.rs_modlist; ml; i++ ,ml = ml->sml_next )
139 mods = ch_malloc( sizeof( LDAPMod )*i );
140 if ( mods == NULL ) {
141 rs->sr_err = LDAP_NO_MEMORY;
145 modv = ( LDAPMod ** )ch_malloc( ( i + 1 )*sizeof( LDAPMod * ) );
146 if ( modv == NULL ) {
147 rs->sr_err = LDAP_NO_MEMORY;
152 dc.ctx = "modifyAttrDN";
153 for ( i = 0, ml = op->oq_modify.rs_modlist; ml; ml = ml->sml_next ) {
156 if ( ml->sml_desc->ad_type->sat_no_user_mod ) {
160 ldap_back_map( &li->targets[ candidate ]->rwmap.rwm_at,
161 &ml->sml_desc->ad_cname, &mapped,
163 if ( mapped.bv_val == NULL || mapped.bv_val[0] == '\0' ) {
167 modv[ i ] = &mods[ i ];
168 mods[ i ].mod_op = ml->sml_op | LDAP_MOD_BVALUES;
169 mods[ i ].mod_type = mapped.bv_val;
172 * FIXME: dn-valued attrs should be rewritten
173 * to allow their use in ACLs at the back-ldap
176 if ( strcmp( ml->sml_desc->ad_type->sat_syntax->ssyn_oid,
177 SLAPD_DN_SYNTAX ) == 0 ) {
178 ( void )ldap_dnattr_rewrite( &dc, ml->sml_bvalues );
181 if ( ml->sml_bvalues != NULL ){
182 for (j = 0; ml->sml_bvalues[ j ].bv_val; j++);
183 mods[ i ].mod_bvalues = (struct berval **)ch_malloc((j+1) *
184 sizeof(struct berval *));
185 for (j = 0; ml->sml_bvalues[ j ].bv_val; j++)
186 mods[ i ].mod_bvalues[ j ] = &ml->sml_bvalues[j];
187 mods[ i ].mod_bvalues[ j ] = NULL;
190 mods[ i ].mod_bvalues = NULL;
197 ldap_modify_s( lc->conns[ candidate ].ld, mdn.bv_val, modv );
200 if ( mdn.bv_val != op->o_req_dn.bv_val ) {
203 if ( modv != NULL ) {
204 for ( i = 0; modv[ i ]; i++) {
205 free( modv[ i ]->mod_bvalues );
212 return meta_back_op_result( lc, op, rs ) == LDAP_SUCCESS
216 send_ldap_result( op, rs );