1 /* Copyright (c) 2003 by International Business Machines, Inc.
3 * International Business Machines, Inc. (hereinafter called IBM) grants
4 * permission under its copyrights to use, copy, modify, and distribute this
5 * Software with or without fee, provided that the above copyright notice and
6 * all paragraphs of this notice appear in all copies, and that the name of IBM
7 * not be used in connection with the marketing of any product incorporating
8 * the Software or modifications thereof, without specific, written prior
11 * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
12 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
13 * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
14 * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
15 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
16 * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
23 #include <ac/socket.h>
24 #include <ac/string.h>
29 #include "../back-ldap/back-ldap.h"
30 #include "back-meta.h"
32 #undef ldap_debug /* silence a warning in ldap-int.h */
34 #include "../../../libraries/libldap/ldap-int.h"
62 add_attribute(const char* attr_name,
79 /* Two empty callback functions to avoid sending results */
80 void callback_null_response(
90 struct berval *resdata,
91 struct berval *sasldata,
96 void callback_null_sresult(
114 struct timeval tv; /* time */
115 enum type_of_result err;
123 struct exception* result )
132 result->type = SUCCESS;
134 if ( e->e_dn != NULL ) {
135 tmplen = strlen( e->e_dn );
136 size = LDIF_SIZE_NEEDED( 2, tmplen );
139 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
140 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
142 tmplen = a->a_desc->ad_cname.bv_len;
143 size += LDIF_SIZE_NEEDED( tmplen, bv.bv_len);
146 if ((size < size_init) && result) {
147 result->type = SIZE_ERR;
158 struct berval* query_uuid,
159 struct exception* result )
161 struct entry_info info;
162 struct berval normdn;
163 struct berval prettydn;
166 slap_callback cb = {callback_null_response,
167 add_func, merge_func, NULL};
169 Filter* filter = str2filter("(queryid=*)");
171 dnPrettyNormal(0, &(e->e_name), &prettydn, &normdn);
173 free(e->e_name.bv_val);
174 e->e_name = prettydn;
178 info.uuid = query_uuid;
184 cb.sc_private = &info;
186 op.o_tag = LDAP_REQ_SEARCH;
187 op.o_protocol = LDAP_VERSION3;
188 op.o_ndn = conn->c_ndn;
191 op.o_time = slap_get_time();
192 op.o_do_not_cache = 1;
194 be->be_search( be, conn, &op, NULL, &(e->e_nname),
195 LDAP_SCOPE_BASE, LDAP_DEREF_NEVER, 1, 0,
196 filter, NULL, NULL, 0 );
197 result->type = info.err;
198 if ( result->type == SUCCESS )
199 result->rc = info.added;
202 return ( info.size_final - info.size_init );
211 AttributeName *attrs,
218 Attribute *a_new, *a;
223 struct timeval time; /* time */
224 long timediff; /* time */
225 slap_callback *tmp = op->o_callback;
226 struct entry_info* info = tmp->sc_private;
227 Filter* filter = str2filter("(queryid=*)");
228 Entry* entry = info->entry;
229 struct berval* uuid = info->uuid;
230 Modifications *modhead = NULL;
232 Modifications **modtail = &modhead;
233 AttributeDescription* a_new_desc;
234 const char *text = NULL;
238 be = select_backend(&entry->e_nname, 0, 0);
240 info->size_init = get_entry_size(e, 0, 0);
241 a_new = entry->e_attrs;
243 while (a_new != NULL) {
244 a_new_desc = a_new->a_desc;
245 mod = (Modifications *) malloc( sizeof(Modifications) );
246 mod->sml_op = LDAP_MOD_REPLACE;
247 ber_dupbv(&(mod->sml_type), &(a_new_desc->ad_cname));
249 for (count=0; a_new->a_vals[count].bv_val; count++)
251 mod->sml_bvalues = (struct berval*) malloc(
252 (count+1) * sizeof( struct berval) );
254 for (i=0; i < count; i++) {
255 ber_dupbv(mod->sml_bvalues+i, a_new->a_vals+i);
258 mod->sml_bvalues[count].bv_val = 0;
259 mod->sml_bvalues[count].bv_len = 0;
261 mod->sml_desc = NULL;
262 slap_bv2ad(&mod->sml_type, &mod->sml_desc, &text);
265 modtail = &mod->sml_next;
266 a_new = a_new->a_next;
269 /* add query UUID to queryid attribute */
270 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
271 mod->sml_op = LDAP_MOD_ADD;
272 mod->sml_desc = slap_schema.si_ad_queryid;
273 ber_dupbv(&(mod->sml_type), &(mod->sml_desc->ad_cname));
274 mod->sml_bvalues = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
275 ber_dupbv( mod->sml_bvalues, uuid );
276 mod->sml_bvalues[1].bv_val = NULL;
277 mod->sml_bvalues[1].bv_len = 0;
279 mod->sml_next = NULL;
281 if (be->be_modify(be, conn, op, &(entry->e_name),
282 &(entry->e_nname), modhead) != 0 ) {
283 info->err = MERGE_ERR;
286 op->o_callback->sc_sendentry = get_size_func;
287 op->o_callback->sc_sresult = NULL;
289 if (be->be_search( be, conn, op, NULL, &(entry->e_nname),
290 LDAP_SCOPE_BASE, LDAP_DEREF_NEVER, 1, 0,
291 filter, NULL, NULL, 0 ) != 0) {
292 info->err = GET_SIZE_ERR;
309 slap_callback *tmp = op->o_callback;
310 struct entry_info *info = tmp->sc_private;
311 Entry* entry = info->entry;
312 struct berval* uuid = info->uuid;
314 BerVarray value_array;
318 struct timeval time; /* time */
319 long timediff; /* time */
322 * new entry, construct an entry with
323 * the projected attributes
328 be = select_backend(&entry->e_nname, 0, 0);
329 e = (Entry*)malloc(sizeof(Entry));
331 ber_dupbv(&e->e_name,&entry->e_name);
332 ber_dupbv(&e->e_nname,&entry->e_nname);
338 /* add queryid attribute */
339 value_array = (struct berval *)malloc(2 * sizeof( struct berval) );
340 ber_dupbv(value_array, uuid);
341 value_array[1].bv_val = NULL;
342 value_array[1].bv_len = 0;
344 a = add_attribute("queryid", e, value_array);
346 /* append the attribute list from the fetched entry */
347 a->a_next = entry->e_attrs;
348 entry->e_attrs = NULL;
350 info->size_final = get_entry_size(e, 0, NULL);
351 if ( be->be_add( be, conn, op, e ) == 0 ) {
353 be_entry_release_w( be, conn, op, e );
355 info->err = MERGE_ERR;
361 add_attribute(const char* attr_name,
363 BerVarray value_array)
365 Attribute* new_attr, *last_attr;
368 if (e->e_attrs == NULL)
371 for (last_attr = e->e_attrs; last_attr->a_next;
372 last_attr = last_attr->a_next)
375 new_attr = (Attribute*)malloc(sizeof(Attribute));
377 last_attr->a_next = new_attr;
379 e->e_attrs = new_attr;
381 new_attr->a_next = NULL;
382 new_attr->a_desc = NULL;
383 new_attr->a_vals = value_array;
384 slap_str2ad(attr_name, &(new_attr->a_desc), &text);
395 AttributeName *attrs,
400 slap_callback *tmp = op->o_callback;
401 struct entry_info *info = tmp->sc_private;
402 struct exception result;
404 result.type = info->err;
405 info->size_final = get_entry_size(entry, info->size_init, &result);
408 #endif /* LDAP_CACHING */