]> git.sur5r.net Git - openldap/blob - servers/slapd/ava.c
Don't pass NULL DN to rewrite_session(), causes assertion failure
[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         if ( freeit ) {
27                 op->o_tmpfree( (char *) ava, op->o_tmpmemctx );
28         }
29 }
30
31 int
32 get_ava(
33         Operation *op,
34         BerElement      *ber,
35         AttributeAssertion      **ava,
36         unsigned usage,
37         const char **text
38 )
39 {
40         int rc;
41         ber_tag_t rtag;
42         struct berval type, value;
43         AttributeAssertion *aa;
44
45         rtag = ber_scanf( ber, "{mm}", &type, &value );
46
47         if( rtag == LBER_ERROR ) {
48 #ifdef NEW_LOGGING
49                 LDAP_LOG( FILTER, ERR, "get_ava:  ber_scanf failure\n", 0, 0, 0 );
50 #else
51                 Debug( LDAP_DEBUG_ANY, "  get_ava ber_scanf\n", 0, 0, 0 );
52 #endif
53                 *text = "Error decoding attribute value assertion";
54                 return SLAPD_DISCONNECT;
55         }
56
57         aa = op->o_tmpalloc( sizeof( AttributeAssertion ), op->o_tmpmemctx );
58         aa->aa_desc = NULL;
59         aa->aa_value.bv_val = NULL;
60
61         rc = slap_bv2ad( &type, &aa->aa_desc, text );
62
63         if( rc != LDAP_SUCCESS ) {
64                 op->o_tmpfree( aa, op->o_tmpmemctx );
65                 return rc;
66         }
67
68         rc = asserted_value_validate_normalize(
69                 aa->aa_desc, ad_mr(aa->aa_desc, usage),
70                 usage, &value, &aa->aa_value, text, op->o_tmpmemctx );
71
72         if( rc != LDAP_SUCCESS ) {
73                 op->o_tmpfree( aa, op->o_tmpmemctx );
74                 return rc;
75         }
76
77         *ava = aa;
78
79         return LDAP_SUCCESS;
80 }