]> git.sur5r.net Git - openldap/blob - servers/slapd/ava.c
fix previous commit (check for co_type==Cft_Overlay before calling
[openldap] / servers / slapd / ava.c
1 /* ava.c - routines for dealing with attribute value assertions */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 1998-2005 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
17  * All rights reserved.
18  *
19  * Redistribution and use in source and binary forms are permitted
20  * provided that this notice is preserved and that due credit is given
21  * to the University of Michigan at Ann Arbor. The name of the University
22  * may not be used to endorse or promote products derived from this
23  * software without specific prior written permission. This software
24  * is provided ``as is'' without express or implied warranty.
25  */
26
27 #include "portable.h"
28
29 #include <stdio.h>
30
31 #include <ac/string.h>
32 #include <ac/socket.h>
33
34 #include "slap.h"
35
36 #ifdef LDAP_COMP_MATCH
37 #include "component.h"
38 #endif
39
40 void
41 ava_free(
42         Operation *op,
43         AttributeAssertion *ava,
44         int     freeit )
45 {
46 #ifdef LDAP_COMP_MATCH
47         if ( ava->aa_cf && ava->aa_cf->cf_ca->ca_comp_data.cd_mem_op )
48                 nibble_mem_free ( ava->aa_cf->cf_ca->ca_comp_data.cd_mem_op );
49 #endif
50         op->o_tmpfree( ava->aa_value.bv_val, op->o_tmpmemctx );
51         if ( freeit ) op->o_tmpfree( (char *) ava, op->o_tmpmemctx );
52 }
53
54 int
55 get_ava(
56         Operation *op,
57         BerElement      *ber,
58         AttributeAssertion      **ava,
59         unsigned usage,
60         const char **text )
61 {
62         int rc;
63         ber_tag_t rtag;
64         struct berval type, value;
65         AttributeAssertion *aa;
66 #ifdef LDAP_COMP_MATCH
67         AttributeAliasing* a_alias = NULL;
68 #endif
69
70         rtag = ber_scanf( ber, "{mm}", &type, &value );
71
72         if( rtag == LBER_ERROR ) {
73                 Debug( LDAP_DEBUG_ANY, "  get_ava ber_scanf\n", 0, 0, 0 );
74                 *text = "Error decoding attribute value assertion";
75                 return SLAPD_DISCONNECT;
76         }
77
78         aa = op->o_tmpalloc( sizeof( AttributeAssertion ), op->o_tmpmemctx );
79         aa->aa_desc = NULL;
80         aa->aa_value.bv_val = NULL;
81 #ifdef LDAP_COMP_MATCH
82         aa->aa_cf = NULL;
83 #endif
84
85         rc = slap_bv2ad( &type, &aa->aa_desc, text );
86
87         if( rc != LDAP_SUCCESS ) {
88                 Debug( LDAP_DEBUG_FILTER,
89                 "get_ava: unknown attributeType %s\n", type.bv_val, 0, 0 );
90                 op->o_tmpfree( aa, op->o_tmpmemctx );
91                 return rc;
92         }
93
94         rc = asserted_value_validate_normalize(
95                 aa->aa_desc, ad_mr(aa->aa_desc, usage),
96                 usage, &value, &aa->aa_value, text, op->o_tmpmemctx );
97
98         if( rc != LDAP_SUCCESS ) {
99                 Debug( LDAP_DEBUG_FILTER,
100                 "get_ava: illegal value for attributeType %s\n", type.bv_val, 0, 0 );
101                 op->o_tmpfree( aa, op->o_tmpmemctx );
102                 return rc;
103         }
104
105 #ifdef LDAP_COMP_MATCH
106         if( is_aliased_attribute ) {
107                 a_alias = is_aliased_attribute ( aa->aa_desc );
108                 if ( a_alias ) {
109                         rc = get_aliased_filter_aa ( op, aa, a_alias, text );
110                         if( rc != LDAP_SUCCESS ) {
111                                 Debug( LDAP_DEBUG_FILTER,
112                                                 "get_ava:Invalid Attribute Aliasing\n", 0, 0, 0 );
113                                 return rc;
114                         }
115                 }
116         }
117 #endif
118         *ava = aa;
119         return LDAP_SUCCESS;
120 }