]> git.sur5r.net Git - openldap/blob - servers/slapd/ava.c
bf43ec5dea5f57453cabb0f651607750259dcb31
[openldap] / servers / slapd / ava.c
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6 /* ava.c - routines for dealing with attribute value assertions */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11
12 #include <ac/string.h>
13 #include <ac/socket.h>
14
15 #include "slap.h"
16
17
18 void
19 ava_free(
20         Operation *op,
21         AttributeAssertion *ava,
22         int     freeit
23 )
24 {
25         /* op->o_tmpfree( ava->aa_value.bv_val, op->o_tmpmemctx ); */
26         ch_free( ava->aa_value.bv_val );
27         if ( freeit ) {
28                 op->o_tmpfree( (char *) ava, op->o_tmpmemctx );
29         }
30 }
31
32 int
33 get_ava(
34         Operation *op,
35         BerElement      *ber,
36         AttributeAssertion      **ava,
37         unsigned usage,
38         const char **text
39 )
40 {
41         int rc;
42         ber_tag_t rtag;
43         struct berval type, value;
44         AttributeAssertion *aa;
45
46         rtag = ber_scanf( ber, "{mm}", &type, &value );
47
48         if( rtag == LBER_ERROR ) {
49 #ifdef NEW_LOGGING
50                 LDAP_LOG( FILTER, ERR, "get_ava:  ber_scanf failure\n", 0, 0, 0 );
51 #else
52                 Debug( LDAP_DEBUG_ANY, "  get_ava ber_scanf\n", 0, 0, 0 );
53 #endif
54                 *text = "Error decoding attribute value assertion";
55                 return SLAPD_DISCONNECT;
56         }
57
58         aa = op->o_tmpalloc( sizeof( AttributeAssertion ), op->o_tmpmemctx );
59         aa->aa_desc = NULL;
60         aa->aa_value.bv_val = NULL;
61
62         rc = slap_bv2ad( &type, &aa->aa_desc, text );
63
64         if( rc != LDAP_SUCCESS ) {
65                 op->o_tmpfree( aa, op->o_tmpmemctx );
66                 return rc;
67         }
68
69         rc = asserted_value_validate_normalize(
70                 aa->aa_desc, ad_mr(aa->aa_desc, usage),
71                 usage, &value, &aa->aa_value, text );
72
73         if( rc != LDAP_SUCCESS ) {
74                 op->o_tmpfree( aa, op->o_tmpmemctx );
75                 return rc;
76         }
77
78         *ava = aa;
79
80         return LDAP_SUCCESS;
81 }