2003-11-27 14:35:14 +08:00
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
2003-03-07 03:44:41 +08:00
|
|
|
*
|
2003-11-27 14:35:14 +08:00
|
|
|
* Copyright 1999-2003 The OpenLDAP Foundation.
|
|
|
|
* Portions Copyright 2003 IBM Corporation.
|
|
|
|
* All rights reserved.
|
2003-03-07 03:44:41 +08:00
|
|
|
*
|
2003-11-27 14:35:14 +08:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
|
|
|
*
|
|
|
|
* A copy of this license is available in the file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
|
|
|
*/
|
|
|
|
/* ACKNOWLEDGEMENTS:
|
|
|
|
* This work was initially developed by the Apurva Kumar for inclusion
|
|
|
|
* in OpenLDAP Software.
|
2003-03-07 03:44:41 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/time.h>
|
|
|
|
|
|
|
|
#include "slap.h"
|
|
|
|
#include "ldif.h"
|
|
|
|
#include "../back-ldap/back-ldap.h"
|
|
|
|
#include "back-meta.h"
|
|
|
|
#include "ldap_pvt.h"
|
|
|
|
#undef ldap_debug /* silence a warning in ldap-int.h */
|
|
|
|
#include "ldap_log.h"
|
|
|
|
#include "../../../libraries/libldap/ldap-int.h"
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
2003-05-09 08:36:31 +08:00
|
|
|
static struct berval bv_queryid_any = BER_BVC( "(queryid=*)" );
|
|
|
|
|
2003-03-07 03:44:41 +08:00
|
|
|
static Attribute*
|
2003-05-09 08:36:31 +08:00
|
|
|
add_attribute(AttributeDescription *ad,
|
2003-03-07 03:44:41 +08:00
|
|
|
Entry* e,
|
|
|
|
BerVarray value_array
|
|
|
|
);
|
|
|
|
|
2003-05-25 01:38:04 +08:00
|
|
|
static int
|
|
|
|
null_response (
|
|
|
|
Operation *op,
|
|
|
|
SlapReply *rs
|
|
|
|
);
|
|
|
|
|
|
|
|
static int
|
|
|
|
normalize_values( Attribute* attr );
|
|
|
|
|
2003-03-07 03:44:41 +08:00
|
|
|
struct entry_info {
|
|
|
|
int size_init;
|
|
|
|
int size_final;
|
|
|
|
int added;
|
|
|
|
Entry* entry;
|
|
|
|
struct berval* uuid;
|
|
|
|
struct timeval tv; /* time */
|
|
|
|
enum type_of_result err;
|
|
|
|
Backend* glue_be;
|
|
|
|
};
|
|
|
|
|
2003-05-25 01:38:04 +08:00
|
|
|
|
2003-03-07 03:44:41 +08:00
|
|
|
int
|
|
|
|
get_entry_size(
|
|
|
|
Entry* e,
|
|
|
|
int size_init,
|
|
|
|
struct exception* result )
|
|
|
|
{
|
|
|
|
Attribute *a;
|
|
|
|
struct berval bv;
|
|
|
|
int i;
|
|
|
|
int tmplen;
|
|
|
|
int size=0;
|
|
|
|
|
|
|
|
if ( result )
|
|
|
|
result->type = SUCCESS;
|
|
|
|
|
|
|
|
if ( e->e_dn != NULL ) {
|
|
|
|
tmplen = strlen( e->e_dn );
|
|
|
|
size = LDIF_SIZE_NEEDED( 2, tmplen );
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
|
|
|
|
for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
|
|
|
|
bv = a->a_vals[i];
|
|
|
|
tmplen = a->a_desc->ad_cname.bv_len;
|
|
|
|
size += LDIF_SIZE_NEEDED( tmplen, bv.bv_len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((size < size_init) && result) {
|
|
|
|
result->type = SIZE_ERR;
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-05-09 08:36:31 +08:00
|
|
|
merge_entry(
|
|
|
|
Operation *op,
|
|
|
|
SlapReply *rs,
|
2003-03-07 03:44:41 +08:00
|
|
|
struct berval* query_uuid,
|
2003-05-09 08:36:31 +08:00
|
|
|
struct exception* result )
|
2003-03-07 03:44:41 +08:00
|
|
|
{
|
2003-05-09 08:36:31 +08:00
|
|
|
struct entry_info info;
|
2003-08-14 07:44:56 +08:00
|
|
|
int rc;
|
|
|
|
Modifications* modlist = NULL;
|
|
|
|
const char* text = NULL;
|
|
|
|
BerVarray value_array;
|
|
|
|
Attribute *uuid_attr, *attr;
|
|
|
|
Entry *e;
|
2003-05-09 08:36:31 +08:00
|
|
|
|
2003-05-25 01:38:04 +08:00
|
|
|
SlapReply sreply = {REP_RESULT};
|
|
|
|
|
2003-05-09 08:36:31 +08:00
|
|
|
Operation op_tmp = *op;
|
2003-08-14 07:44:56 +08:00
|
|
|
slap_callback cb;
|
2003-05-09 08:36:31 +08:00
|
|
|
|
2003-05-25 01:38:04 +08:00
|
|
|
sreply.sr_entry = NULL;
|
|
|
|
sreply.sr_nentries = 0;
|
2003-05-09 08:36:31 +08:00
|
|
|
|
2003-08-14 07:44:56 +08:00
|
|
|
e = ( Entry * ) ch_calloc( 1, sizeof( Entry ));
|
2003-10-22 18:35:49 +08:00
|
|
|
|
|
|
|
dnPrettyNormal(0, &rs->sr_entry->e_name, &op_tmp.o_req_dn, &op_tmp.o_req_ndn, op->o_tmpmemctx);
|
|
|
|
ber_dupbv( &e->e_name, &op_tmp.o_req_dn );
|
|
|
|
ber_dupbv( &e->e_nname, &op_tmp.o_req_ndn );
|
|
|
|
sl_free( op_tmp.o_req_ndn.bv_val, op->o_tmpmemctx );
|
|
|
|
sl_free( op_tmp.o_req_dn.bv_val, op->o_tmpmemctx );
|
|
|
|
op_tmp.o_req_dn = e->e_name;
|
|
|
|
op_tmp.o_req_ndn = e->e_nname;
|
2003-03-07 03:44:41 +08:00
|
|
|
|
2003-08-14 07:44:56 +08:00
|
|
|
e->e_private = NULL;
|
|
|
|
e->e_attrs = NULL;
|
|
|
|
e->e_bv.bv_val = NULL;
|
2003-03-07 03:44:41 +08:00
|
|
|
|
|
|
|
/* add queryid attribute */
|
|
|
|
value_array = (struct berval *)malloc(2 * sizeof( struct berval) );
|
2003-08-14 07:44:56 +08:00
|
|
|
ber_dupbv(value_array, query_uuid);
|
2003-03-07 03:44:41 +08:00
|
|
|
value_array[1].bv_val = NULL;
|
|
|
|
value_array[1].bv_len = 0;
|
|
|
|
|
2003-08-14 07:44:56 +08:00
|
|
|
uuid_attr = add_attribute(slap_schema.si_ad_queryid, e, value_array);
|
2003-03-07 03:44:41 +08:00
|
|
|
|
|
|
|
/* append the attribute list from the fetched entry */
|
2003-08-14 07:44:56 +08:00
|
|
|
uuid_attr->a_next = rs->sr_entry->e_attrs;
|
|
|
|
rs->sr_entry->e_attrs = NULL;
|
2003-03-07 03:44:41 +08:00
|
|
|
|
2003-05-25 01:38:04 +08:00
|
|
|
for ( attr = e->e_attrs; attr; attr = attr->a_next ) {
|
|
|
|
if ( normalize_values( attr ) ) {
|
2003-08-14 07:44:56 +08:00
|
|
|
info.err = MERGE_ERR;
|
|
|
|
result->rc = info.err;
|
|
|
|
return 0;
|
2003-05-25 01:38:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-14 07:44:56 +08:00
|
|
|
info.entry = e;
|
|
|
|
info.uuid = query_uuid;
|
|
|
|
info.size_init = get_entry_size( rs->sr_entry, 0, 0 );
|
|
|
|
info.size_final = 0;
|
|
|
|
info.added = 0;
|
|
|
|
info.glue_be = op->o_bd;
|
|
|
|
info.err = SUCCESS;
|
|
|
|
cb.sc_private = &info;
|
|
|
|
cb.sc_response = null_response;
|
|
|
|
|
|
|
|
op_tmp.o_tag = LDAP_REQ_ADD;
|
|
|
|
op_tmp.o_protocol = LDAP_VERSION3;
|
|
|
|
op_tmp.o_callback = &cb;
|
|
|
|
op_tmp.o_time = slap_get_time();
|
|
|
|
op_tmp.o_do_not_cache = 1;
|
2003-05-09 08:36:31 +08:00
|
|
|
|
|
|
|
op_tmp.ora_e = e;
|
2003-08-14 07:44:56 +08:00
|
|
|
rc = op->o_bd->be_add( &op_tmp, &sreply );
|
|
|
|
|
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
|
|
|
if ( rc == LDAP_ALREADY_EXISTS ) {
|
|
|
|
slap_entry2mods( e, &modlist, &text );
|
|
|
|
op_tmp.o_tag = LDAP_REQ_MODIFY;
|
|
|
|
op_tmp.orm_modlist = modlist;
|
|
|
|
op_tmp.o_req_dn = e->e_name;
|
|
|
|
op_tmp.o_req_ndn = e->e_nname;
|
|
|
|
rc = op->o_bd->be_modify( &op_tmp, &sreply );
|
|
|
|
result->rc = info.added;
|
|
|
|
} else if ( rc == LDAP_REFERRAL ||
|
|
|
|
rc == LDAP_NO_SUCH_OBJECT ) {
|
2003-10-24 16:10:16 +08:00
|
|
|
syncrepl_add_glue( &op_tmp, e );
|
2003-08-14 07:44:56 +08:00
|
|
|
result->rc = info.added;
|
|
|
|
} else {
|
|
|
|
result->rc = 0;
|
|
|
|
}
|
|
|
|
if ( modlist != NULL ) slap_mods_free( modlist );
|
2003-03-07 03:44:41 +08:00
|
|
|
} else {
|
2003-08-14 07:44:56 +08:00
|
|
|
info.size_init = 0;
|
|
|
|
result->rc = info.added;
|
|
|
|
be_entry_release_w( &op_tmp, e );
|
2003-03-07 03:44:41 +08:00
|
|
|
}
|
2003-08-14 07:44:56 +08:00
|
|
|
|
|
|
|
if ( result->rc )
|
|
|
|
info.size_final = get_entry_size( e, info.size_init, result );
|
|
|
|
else
|
|
|
|
info.size_final = info.size_init;
|
|
|
|
|
|
|
|
return ( info.size_final - info.size_init );
|
2003-03-07 03:44:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static Attribute*
|
2003-05-09 08:36:31 +08:00
|
|
|
add_attribute(AttributeDescription *ad,
|
2003-03-07 03:44:41 +08:00
|
|
|
Entry* e,
|
|
|
|
BerVarray value_array)
|
|
|
|
{
|
|
|
|
Attribute* new_attr, *last_attr;
|
|
|
|
const char* text;
|
|
|
|
|
|
|
|
if (e->e_attrs == NULL)
|
|
|
|
last_attr = NULL;
|
|
|
|
else
|
|
|
|
for (last_attr = e->e_attrs; last_attr->a_next;
|
|
|
|
last_attr = last_attr->a_next)
|
|
|
|
;
|
|
|
|
|
|
|
|
new_attr = (Attribute*)malloc(sizeof(Attribute));
|
|
|
|
if (last_attr)
|
|
|
|
last_attr->a_next = new_attr;
|
|
|
|
else
|
|
|
|
e->e_attrs = new_attr;
|
|
|
|
|
|
|
|
new_attr->a_next = NULL;
|
|
|
|
new_attr->a_desc = NULL;
|
|
|
|
new_attr->a_vals = value_array;
|
2003-05-09 08:36:31 +08:00
|
|
|
new_attr->a_desc = ad;
|
2003-03-07 03:44:41 +08:00
|
|
|
|
|
|
|
return new_attr;
|
|
|
|
}
|
|
|
|
|
2003-05-25 01:38:04 +08:00
|
|
|
static int
|
|
|
|
null_response (
|
|
|
|
Operation *op,
|
|
|
|
SlapReply *rs )
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
normalize_values( Attribute* attr )
|
|
|
|
{
|
|
|
|
int nvals, rc, i;
|
|
|
|
|
|
|
|
if (attr->a_vals == NULL) {
|
|
|
|
attr->a_nvals = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( nvals = 0; attr->a_vals[nvals].bv_val; nvals++ )
|
|
|
|
;
|
|
|
|
|
|
|
|
attr->a_nvals = (struct berval*)ch_malloc((nvals+1)*sizeof(struct berval));
|
|
|
|
|
|
|
|
if ( attr->a_desc->ad_type->sat_equality &&
|
|
|
|
attr->a_desc->ad_type->sat_equality->smr_normalize )
|
|
|
|
{
|
|
|
|
for ( i = 0; i < nvals; i++ ) {
|
|
|
|
rc = attr->a_desc->ad_type->sat_equality->smr_normalize(
|
2003-10-22 13:19:30 +08:00
|
|
|
SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
|
2003-05-25 01:38:04 +08:00
|
|
|
attr->a_desc->ad_type->sat_syntax,
|
|
|
|
attr->a_desc->ad_type->sat_equality,
|
|
|
|
&attr->a_vals[i], &attr->a_nvals[i], NULL );
|
|
|
|
if ( rc ) {
|
|
|
|
#ifdef NEW_LOGGING
|
|
|
|
LDAP_LOG( OPERATION, DETAIL1,
|
|
|
|
"Error in normalizing attribute %s value %d (%d)\n",
|
|
|
|
attr->a_desc->ad_cname.bv_val, i, rc );
|
|
|
|
#else
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"Error in normalizing attribute %s value %d (%d)\n",
|
|
|
|
attr->a_desc->ad_cname.bv_val, i, rc );
|
|
|
|
#endif
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for ( i = 0; i < nvals; i++ ) {
|
|
|
|
ber_dupbv( &attr->a_nvals[i], &attr->a_vals[i] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
attr->a_nvals[i].bv_val = NULL;
|
|
|
|
attr->a_nvals[i].bv_len = 0;
|
|
|
|
|
|
|
|
return LDAP_SUCCESS;
|
|
|
|
}
|