Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / bsd / openldap / dist / servers / slapd / ava.c
blobb04325bbdad7379dafb382fa63c7706d571413b3
1 /* ava.c - routines for dealing with attribute value assertions */
2 /* $OpenLDAP: pkg/ldap/servers/slapd/ava.c,v 1.45.2.3 2008/02/11 23:26:43 kurt Exp $ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2008 The OpenLDAP Foundation.
6 * All rights reserved.
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.
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>.
16 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
17 * All rights reserved.
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.
27 #include "portable.h"
29 #include <stdio.h>
31 #include <ac/string.h>
32 #include <ac/socket.h>
34 #include "slap.h"
36 #ifdef LDAP_COMP_MATCH
37 #include "component.h"
38 #endif
40 void
41 ava_free(
42 Operation *op,
43 AttributeAssertion *ava,
44 int freeit )
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 ( ava->aa_desc->ad_flags & SLAP_DESC_TEMPORARY )
52 op->o_tmpfree( ava->aa_desc, op->o_tmpmemctx );
53 if ( freeit ) op->o_tmpfree( (char *) ava, op->o_tmpmemctx );
56 int
57 get_ava(
58 Operation *op,
59 BerElement *ber,
60 Filter *f,
61 unsigned usage,
62 const char **text )
64 int rc;
65 ber_tag_t rtag;
66 struct berval type, value;
67 AttributeAssertion *aa;
68 #ifdef LDAP_COMP_MATCH
69 AttributeAliasing* a_alias = NULL;
70 #endif
72 rtag = ber_scanf( ber, "{mm}", &type, &value );
74 if( rtag == LBER_ERROR ) {
75 Debug( LDAP_DEBUG_ANY, " get_ava ber_scanf\n", 0, 0, 0 );
76 *text = "Error decoding attribute value assertion";
77 return SLAPD_DISCONNECT;
80 aa = op->o_tmpalloc( sizeof( AttributeAssertion ), op->o_tmpmemctx );
81 aa->aa_desc = NULL;
82 aa->aa_value.bv_val = NULL;
83 #ifdef LDAP_COMP_MATCH
84 aa->aa_cf = NULL;
85 #endif
87 rc = slap_bv2ad( &type, &aa->aa_desc, text );
89 if( rc != LDAP_SUCCESS ) {
90 f->f_choice |= SLAPD_FILTER_UNDEFINED;
91 *text = NULL;
92 rc = slap_bv2undef_ad( &type, &aa->aa_desc, text,
93 SLAP_AD_PROXIED|SLAP_AD_NOINSERT );
95 if( rc != LDAP_SUCCESS ) {
96 Debug( LDAP_DEBUG_FILTER,
97 "get_ava: unknown attributeType %s\n", type.bv_val, 0, 0 );
98 aa->aa_desc = slap_bv2tmp_ad( &type, op->o_tmpmemctx );
99 ber_dupbv_x( &aa->aa_value, &value, op->o_tmpmemctx );
100 f->f_ava = aa;
101 return rc;
105 rc = asserted_value_validate_normalize(
106 aa->aa_desc, ad_mr(aa->aa_desc, usage),
107 usage, &value, &aa->aa_value, text, op->o_tmpmemctx );
109 if( rc != LDAP_SUCCESS ) {
110 f->f_choice |= SLAPD_FILTER_UNDEFINED;
111 Debug( LDAP_DEBUG_FILTER,
112 "get_ava: illegal value for attributeType %s\n", type.bv_val, 0, 0 );
113 ber_dupbv_x( &aa->aa_value, &value, op->o_tmpmemctx );
114 rc = LDAP_SUCCESS;
117 #ifdef LDAP_COMP_MATCH
118 if( is_aliased_attribute ) {
119 a_alias = is_aliased_attribute ( aa->aa_desc );
120 if ( a_alias ) {
121 rc = get_aliased_filter_aa ( op, aa, a_alias, text );
122 if( rc != LDAP_SUCCESS ) {
123 Debug( LDAP_DEBUG_FILTER,
124 "get_ava:Invalid Attribute Aliasing\n", 0, 0, 0 );
125 return rc;
129 #endif
130 f->f_ava = aa;
131 return LDAP_SUCCESS;