ava.c 1.36 KB
Newer Older
1
/* $OpenLDAP$ */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
2
/*
Kurt Zeilenga's avatar
Kurt Zeilenga committed
3
 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
Kurt Zeilenga's avatar
Kurt Zeilenga committed
4
5
 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
 */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
6
7
/* ava.c - routines for dealing with attribute value assertions */

Kurt Zeilenga's avatar
Kurt Zeilenga committed
8
9
#include "portable.h"

Kurt Zeilenga's avatar
Kurt Zeilenga committed
10
#include <stdio.h>
Kurt Zeilenga's avatar
Kurt Zeilenga committed
11
12
13
14

#include <ac/string.h>
#include <ac/socket.h>

Kurt Zeilenga's avatar
Kurt Zeilenga committed
15
16
#include "slap.h"

17
18
19
20
21
22
23
24
25
26
27
28
29
30

void
ava_free(
    AttributeAssertion *ava,
    int	freeit
)
{
	ad_free( ava->aa_desc, 1 );
	ber_bvfree( ava->aa_value );
	if ( freeit ) {
		ch_free( (char *) ava );
	}
}

31
32
33
int
get_ava(
    BerElement	*ber,
34
    AttributeAssertion	**ava,
35
	unsigned usage,
Kurt Zeilenga's avatar
Kurt Zeilenga committed
36
	const char **text
37
38
39
)
{
	int rc;
40
	struct berval type, value, *nvalue;
41
42
	AttributeAssertion *aa;

43
	rc = ber_scanf( ber, "{oo}", &type, &value );
44
45
46

	if( rc == LBER_ERROR ) {
		Debug( LDAP_DEBUG_ANY, "  get_ava ber_scanf\n", 0, 0, 0 );
47
		*text = "Error decoding attribute value assertion";
48
49
50
51
		return SLAPD_DISCONNECT;
	}

	aa = ch_malloc( sizeof( AttributeAssertion ) );
52
	aa->aa_desc = NULL;
53
	aa->aa_value = NULL;
54

55
	rc = slap_bv2ad( &type, &aa->aa_desc, text );
56
	ch_free( type.bv_val );
57
58

	if( rc != LDAP_SUCCESS ) {
59
		ch_free( value.bv_val );
60
61
62
63
		ch_free( aa );
		return rc;
	}

64
65
	rc = value_normalize( aa->aa_desc, usage, &value, &nvalue, text );
	ch_free( value.bv_val );
66
67
68
69
70
71
72

	if( rc != LDAP_SUCCESS ) {
		ad_free( aa->aa_desc, 1 );
		ch_free( aa );
		return rc;
	}

73
	aa->aa_value = nvalue;
74
	*ava = aa;
75
76
77
78

	return LDAP_SUCCESS;
}