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