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