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 */
21 /* Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
23 * This work has been developed to fulfill the requirements
24 * of SysNet s.n.c. <http:www.sys-net.it> and it has been donated
25 * to the OpenLDAP Foundation in the hope that it may be useful
26 * to the Open Source community, but WITHOUT ANY WARRANTY.
28 * Permission is granted to anyone to use this software for any purpose
29 * on any computer system, and to alter it and redistribute it, subject
30 * to the following restrictions:
32 * 1. The author and SysNet s.n.c. are not responsible for the consequences
33 * of use of this software, no matter how awful, even if they arise from
36 * 2. The origin of this software must not be misrepresented, either by
37 * explicit claim or by omission. Since few users ever read sources,
38 * credits should appear in the documentation.
40 * 3. Altered versions must be plainly marked as such, and must not be
41 * misrepresented as being the original software. Since few users
42 * ever read sources, credits should appear in the documentation.
43 * SysNet s.n.c. cannot be responsible for the consequences of the
46 * 4. This notice may not be removed or altered.
49 * This software is based on the backend back-ldap, implemented
50 * by Howard Chu <hyc@highlandsun.com>, and modified by Mark Valence
51 * <kurash@sassafras.com>, Pierangelo Masarati <ando@sys-net.it> and other
52 * contributors. The contribution of the original software to the present
53 * implementation is acknowledged in this copyright statement.
55 * A special acknowledgement goes to Howard for the overall architecture
56 * (and for borrowing large pieces of code), and to Mark, who implemented
57 * from scratch the attribute/objectclass mapping.
59 * The original copyright statement follows.
61 * Copyright 1999, Howard Chu, All rights reserved. <hyc@highlandsun.com>
63 * Permission is granted to anyone to use this software for any purpose
64 * on any computer system, and to alter it and redistribute it, subject
65 * to the following restrictions:
67 * 1. The author is not responsible for the consequences of use of this
68 * software, no matter how awful, even if they arise from flaws in it.
70 * 2. The origin of this software must not be misrepresented, either by
71 * explicit claim or by omission. Since few users ever read sources,
72 * credits should appear in the documentation.
74 * 3. Altered versions must be plainly marked as such, and must not be
75 * misrepresented as being the original software. Since few users
76 * ever read sources, credits should appear in the
79 * 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_add( Operation *op, SlapReply *rs )
98 struct metainfo *li = ( struct metainfo * )op->o_bd->be_private;
100 int i, candidate = -1;
103 struct berval mdn = { 0, NULL }, mapped;
107 LDAP_LOG( BACK_META, ENTRY, "meta_back_add: %s\n",
108 op->o_req_dn.bv_val, 0, 0 );
109 #else /* !NEW_LOGGING */
110 Debug(LDAP_DEBUG_ARGS, "==> meta_back_add: %s\n",
111 op->o_req_dn.bv_val, 0, 0 );
112 #endif /* !NEW_LOGGING */
115 * get the current connection
117 lc = meta_back_getconn( op, rs, META_OP_REQUIRE_SINGLE,
118 &op->o_req_ndn, &candidate );
120 send_ldap_result( op, rs );
123 if ( !meta_back_dobind( lc, op )
124 || !meta_back_is_valid( lc, candidate ) ) {
125 rs->sr_err = LDAP_OTHER;
126 send_ldap_result( op, rs );
131 * Rewrite the add dn, if needed
133 dc.rwmap = &li->targets[ candidate ]->rwmap;
134 dc.conn = op->o_conn;
138 if ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
139 send_ldap_result( op, rs );
143 /* Count number of attributes in entry */
144 for ( i = 1, a = op->oq_add.rs_e->e_attrs; a; i++, a = a->a_next );
146 /* Create array of LDAPMods for ldap_add() */
147 attrs = ch_malloc( sizeof( LDAPMod * )*i );
149 for ( i = 0, a = op->oq_add.rs_e->e_attrs; a; a = a->a_next ) {
152 if ( a->a_desc->ad_type->sat_no_user_mod ) {
156 ldap_back_map( &li->targets[ candidate ]->rwmap.rwm_at,
157 &a->a_desc->ad_cname, &mapped, BACKLDAP_MAP );
158 if ( mapped.bv_val == NULL || mapped.bv_val[0] == '\0' ) {
162 attrs[ i ] = ch_malloc( sizeof( LDAPMod ) );
163 if ( attrs[ i ] == NULL ) {
166 attrs[ i ]->mod_op = LDAP_MOD_BVALUES;
167 attrs[ i ]->mod_type = mapped.bv_val;
170 * FIXME: dn-valued attrs should be rewritten
171 * to allow their use in ACLs at the back-ldap
174 if ( strcmp( a->a_desc->ad_type->sat_syntax->ssyn_oid,
175 SLAPD_DN_SYNTAX ) == 0 ) {
176 (void)ldap_dnattr_rewrite( &dc, a->a_vals );
179 for ( j = 0; a->a_vals[ j ].bv_val; j++ );
180 attrs[ i ]->mod_vals.modv_bvals = ch_malloc((j+1)*sizeof(struct berval *));
181 for ( j = 0; a->a_vals[ j ].bv_val; j++ ) {
182 attrs[ i ]->mod_vals.modv_bvals[ j ] = &a->a_vals[ j ];
184 attrs[ i ]->mod_vals.modv_bvals[ j ] = NULL;
189 ldap_add_s( lc->conns[ candidate ].ld, mdn.bv_val, attrs );
190 for ( --i; i >= 0; --i ) {
191 free( attrs[ i ]->mod_vals.modv_bvals );
195 if ( mdn.bv_val != op->oq_add.rs_e->e_dn ) {
198 return meta_back_op_result( lc, op, rs );