]> git.sur5r.net Git - openldap/blob - servers/slapd/ava.c
now I remember why I introduced the 'has_ldapinfo_dn_ru' flag
[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-2004 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
37 void
38 ava_free(
39         Operation *op,
40         AttributeAssertion *ava,
41         int     freeit
42 )
43 {
44         op->o_tmpfree( ava->aa_value.bv_val, op->o_tmpmemctx );
45         if ( freeit ) {
46                 op->o_tmpfree( (char *) ava, op->o_tmpmemctx );
47         }
48 }
49
50 int
51 get_ava(
52         Operation *op,
53         BerElement      *ber,
54         AttributeAssertion      **ava,
55         unsigned usage,
56         const char **text
57 )
58 {
59         int rc;
60         ber_tag_t rtag;
61         struct berval type, value;
62         AttributeAssertion *aa;
63
64         rtag = ber_scanf( ber, "{mm}", &type, &value );
65
66         if( rtag == LBER_ERROR ) {
67 #ifdef NEW_LOGGING
68                 LDAP_LOG( FILTER, ERR, "get_ava:  ber_scanf failure\n", 0, 0, 0 );
69 #else
70                 Debug( LDAP_DEBUG_ANY, "  get_ava ber_scanf\n", 0, 0, 0 );
71 #endif
72                 *text = "Error decoding attribute value assertion";
73                 return SLAPD_DISCONNECT;
74         }
75
76         aa = op->o_tmpalloc( sizeof( AttributeAssertion ), op->o_tmpmemctx );
77         aa->aa_desc = NULL;
78         aa->aa_value.bv_val = NULL;
79
80         rc = slap_bv2ad( &type, &aa->aa_desc, text );
81
82         if( rc != LDAP_SUCCESS ) {
83 #ifdef NEW_LOGGING
84                 LDAP_LOG( FILTER, ERR,
85                 "get_ava: unknown attributeType %s\n", type.bv_val, 0, 0 );
86 #else
87                 Debug( LDAP_DEBUG_FILTER,
88                 "get_ava: unknown attributeType %s\n", type.bv_val, 0, 0 );
89 #endif
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 #ifdef NEW_LOGGING
100                 LDAP_LOG( FILTER, ERR,
101                 "get_ava: illegal value for attributeType %s\n", type.bv_val, 0, 0 );
102 #else
103                 Debug( LDAP_DEBUG_FILTER,
104                 "get_ava: illegal value for attributeType %s\n", type.bv_val, 0, 0 );
105 #endif
106                 op->o_tmpfree( aa, op->o_tmpmemctx );
107                 return rc;
108         }
109
110         *ava = aa;
111
112         return LDAP_SUCCESS;
113 }