Exemple #1
0
int
entry_decode_dn( EntryHeader *eh, struct berval *dn, struct berval *ndn )
{
	int i;
	unsigned char *ptr = (unsigned char *)eh->bv.bv_val;

	assert( dn != NULL || ndn != NULL );

	ptr = (unsigned char *)eh->data;
	i = entry_getlen(&ptr);
	if ( dn != NULL ) {
		dn->bv_val = (char *) ptr;
		dn->bv_len = i;
	}

	if ( ndn != NULL ) {
		ptr += i + 1;
		i = entry_getlen(&ptr);
		ndn->bv_val = (char *) ptr;
		ndn->bv_len = i;
	}

	Debug( LDAP_DEBUG_TRACE,
		"entry_decode_dn: \"%s\"\n",
		dn ? dn->bv_val : ndn->bv_val );

	return 0;
}
Exemple #2
0
int wt_entry_header(WT_ITEM *item, EntryHeader *eh){
	unsigned char *ptr = (unsigned char *)item->data;

    /* Some overlays can create empty entries
     * so don't check for zeros here.
     */
	eh->nattrs = entry_getlen(&ptr);
    eh->nvals = entry_getlen(&ptr);
    eh->data = (char *)ptr;
	return LDAP_SUCCESS;
}
Exemple #3
0
/* Retrieve an Entry that was stored using entry_encode above.
 * First entry_header must be called to decode the size of the entry.
 * Then a single block of memory must be malloc'd to accomodate the
 * bervals and the bulk data. Next the bulk data is retrieved from
 * the DB and parsed by entry_decode.
 *
 * Note: everything is stored in a single contiguous block, so
 * you can not free individual attributes or names from this
 * structure. Attempting to do so will likely corrupt memory.
 */
int entry_header(EntryHeader *eh)
{
	unsigned char *ptr = (unsigned char *)eh->bv.bv_val;

	/* Some overlays can create empty entries
	 * so don't check for zeros here.
	 */
	eh->nattrs = entry_getlen(&ptr);
	eh->nvals = entry_getlen(&ptr);
	eh->data = (char *)ptr;
	return LDAP_SUCCESS;
}
Exemple #4
0
/* Retrieve an Entry that was stored using entry_encode above.
 * First entry_header must be called to decode the size of the entry.
 * Then a single block of memory must be malloc'd to accomodate the
 * bervals and the bulk data. Next the bulk data is retrieved from
 * the DB and parsed by entry_decode.
 *
 * Note: everything is stored in a single contiguous block, so
 * you can not free individual attributes or names from this
 * structure. Attempting to do so will likely corrupt memory.
 */
int entry_header(EntryHeader *eh)
{
	unsigned char *ptr = (unsigned char *)eh->bv.bv_val;

	eh->nattrs = entry_getlen(&ptr);
	if ( !eh->nattrs ) {
		Debug( LDAP_DEBUG_ANY,
			"entry_header: attribute count was zero\n", 0, 0, 0);
		return LDAP_OTHER;
	}
	eh->nvals = entry_getlen(&ptr);
	if ( !eh->nvals ) {
		Debug( LDAP_DEBUG_ANY,
			"entry_header: value count was zero\n", 0, 0, 0);
		return LDAP_OTHER;
	}
	eh->data = (char *)ptr;
	return LDAP_SUCCESS;
}
Exemple #5
0
int entry_decode(EntryHeader *eh, Entry **e)
#endif
{
	int i, j, nattrs, nvals ALLOW_UNUSED;
	int rc;
	Attribute *a;
	Entry *x;
	const char *text;
	AttributeDescription *ad;
	unsigned char *ptr = (unsigned char *)eh->bv.bv_val;
	BerVarray bptr;

	nattrs = eh->nattrs;
	nvals = eh->nvals;
	x = entry_alloc();
	x->e_attrs = attrs_alloc( nattrs );
	ptr = (unsigned char *)eh->data;
	i = entry_getlen(&ptr);
	x->e_name.bv_val = (char *) ptr;
	x->e_name.bv_len = i;
	ptr += i+1;
	i = entry_getlen(&ptr);
	x->e_nname.bv_val = (char *) ptr;
	x->e_nname.bv_len = i;
	ptr += i+1;
	Debug( LDAP_DEBUG_TRACE,
		"entry_decode: \"%s\"\n",
		x->e_dn );
	x->e_bv = eh->bv;

	a = x->e_attrs;
	bptr = (BerVarray)eh->bv.bv_val;

	while ((i = entry_getlen(&ptr))) {
		struct berval bv;
		bv.bv_len = i;
		bv.bv_val = (char *) ptr;
		ad = NULL;
		rc = slap_bv2ad( &bv, &ad, &text );

		if( rc != LDAP_SUCCESS ) {
			Debug( LDAP_DEBUG_TRACE,
				"<= entry_decode: str2ad(%s): %s\n", ptr, text );
			rc = slap_bv2undef_ad( &bv, &ad, &text, 0 );

			if( rc != LDAP_SUCCESS ) {
				Debug( LDAP_DEBUG_ANY,
					"<= entry_decode: slap_str2undef_ad(%s): %s\n",
						ptr, text );
				return rc;
			}
		}
		ptr += i + 1;
		a->a_desc = ad;
		a->a_flags = SLAP_ATTR_DONT_FREE_DATA | SLAP_ATTR_DONT_FREE_VALS;
		j = entry_getlen(&ptr);
		a->a_numvals = j;
		a->a_vals = bptr;

		while (j) {
			i = entry_getlen(&ptr);
			bptr->bv_len = i;
			bptr->bv_val = (char *)ptr;
			ptr += i+1;
			bptr++;
			j--;
		}
		bptr->bv_val = NULL;
		bptr->bv_len = 0;
		bptr++;

		j = entry_getlen(&ptr);
		if (j) {
			a->a_nvals = bptr;
			while (j) {
				i = entry_getlen(&ptr);
				bptr->bv_len = i;
				bptr->bv_val = (char *)ptr;
				ptr += i+1;
				bptr++;
				j--;
			}
			bptr->bv_val = NULL;
			bptr->bv_len = 0;
			bptr++;
		} else {
			a->a_nvals = a->a_vals;
		}
		/* FIXME: This is redundant once a sorted entry is saved into the DB */
		if ( a->a_desc->ad_type->sat_flags & SLAP_AT_SORTED_VAL ) {
			rc = slap_sort_vals( (Modifications *)a, &text, &j, NULL );
			if ( rc == LDAP_SUCCESS ) {
				a->a_flags |= SLAP_ATTR_SORTED_VALS;
			} else if ( rc == LDAP_TYPE_OR_VALUE_EXISTS ) {
				/* should never happen */
				Debug( LDAP_DEBUG_ANY,
					"entry_decode: attributeType %s value #%d provided more than once\n",
					a->a_desc->ad_cname.bv_val, j );
				return rc;
			}
		}
		a = a->a_next;
		nattrs--;
		if ( !nattrs )
			break;
	}

	Debug(LDAP_DEBUG_TRACE, "<= entry_decode(%s)\n",
		x->e_dn );
	*e = x;
	return 0;
}