Home | History | Annotate | Line # | Download | only in slapd
ava.c revision 1.1.1.3
      1  1.1.1.2  lukem /*	$NetBSD: ava.c,v 1.1.1.3 2010/12/12 15:22:18 adam Exp $	*/
      2  1.1.1.2  lukem 
      3      1.1  lukem /* ava.c - routines for dealing with attribute value assertions */
      4  1.1.1.3   adam /* OpenLDAP: pkg/ldap/servers/slapd/ava.c,v 1.45.2.6 2010/04/13 20:23:11 kurt Exp */
      5      1.1  lukem /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
      6      1.1  lukem  *
      7  1.1.1.3   adam  * Copyright 1998-2010 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.1  lukem #include "portable.h"
     30      1.1  lukem 
     31      1.1  lukem #include <stdio.h>
     32      1.1  lukem 
     33      1.1  lukem #include <ac/string.h>
     34      1.1  lukem #include <ac/socket.h>
     35      1.1  lukem 
     36      1.1  lukem #include "slap.h"
     37      1.1  lukem 
     38      1.1  lukem #ifdef LDAP_COMP_MATCH
     39      1.1  lukem #include "component.h"
     40      1.1  lukem #endif
     41      1.1  lukem 
     42      1.1  lukem void
     43      1.1  lukem ava_free(
     44      1.1  lukem 	Operation *op,
     45      1.1  lukem 	AttributeAssertion *ava,
     46      1.1  lukem 	int	freeit )
     47      1.1  lukem {
     48      1.1  lukem #ifdef LDAP_COMP_MATCH
     49      1.1  lukem 	if ( ava->aa_cf && ava->aa_cf->cf_ca->ca_comp_data.cd_mem_op )
     50      1.1  lukem 		nibble_mem_free ( ava->aa_cf->cf_ca->ca_comp_data.cd_mem_op );
     51      1.1  lukem #endif
     52      1.1  lukem 	op->o_tmpfree( ava->aa_value.bv_val, op->o_tmpmemctx );
     53      1.1  lukem 	if ( ava->aa_desc->ad_flags & SLAP_DESC_TEMPORARY )
     54      1.1  lukem 		op->o_tmpfree( ava->aa_desc, op->o_tmpmemctx );
     55      1.1  lukem 	if ( freeit ) op->o_tmpfree( (char *) ava, op->o_tmpmemctx );
     56      1.1  lukem }
     57      1.1  lukem 
     58      1.1  lukem int
     59      1.1  lukem get_ava(
     60      1.1  lukem 	Operation *op,
     61      1.1  lukem 	BerElement	*ber,
     62      1.1  lukem 	Filter *f,
     63      1.1  lukem 	unsigned usage,
     64      1.1  lukem 	const char **text )
     65      1.1  lukem {
     66      1.1  lukem 	int rc;
     67      1.1  lukem 	ber_tag_t rtag;
     68      1.1  lukem 	struct berval type, value;
     69      1.1  lukem 	AttributeAssertion *aa;
     70      1.1  lukem #ifdef LDAP_COMP_MATCH
     71      1.1  lukem 	AttributeAliasing* a_alias = NULL;
     72      1.1  lukem #endif
     73      1.1  lukem 
     74      1.1  lukem 	rtag = ber_scanf( ber, "{mm}", &type, &value );
     75      1.1  lukem 
     76      1.1  lukem 	if( rtag == LBER_ERROR ) {
     77      1.1  lukem 		Debug( LDAP_DEBUG_ANY, "  get_ava ber_scanf\n", 0, 0, 0 );
     78      1.1  lukem 		*text = "Error decoding attribute value assertion";
     79      1.1  lukem 		return SLAPD_DISCONNECT;
     80      1.1  lukem 	}
     81      1.1  lukem 
     82      1.1  lukem 	aa = op->o_tmpalloc( sizeof( AttributeAssertion ), op->o_tmpmemctx );
     83      1.1  lukem 	aa->aa_desc = NULL;
     84      1.1  lukem 	aa->aa_value.bv_val = NULL;
     85      1.1  lukem #ifdef LDAP_COMP_MATCH
     86      1.1  lukem 	aa->aa_cf = NULL;
     87      1.1  lukem #endif
     88      1.1  lukem 
     89      1.1  lukem 	rc = slap_bv2ad( &type, &aa->aa_desc, text );
     90      1.1  lukem 
     91      1.1  lukem 	if( rc != LDAP_SUCCESS ) {
     92      1.1  lukem 		f->f_choice |= SLAPD_FILTER_UNDEFINED;
     93      1.1  lukem 		*text = NULL;
     94      1.1  lukem 		rc = slap_bv2undef_ad( &type, &aa->aa_desc, text,
     95      1.1  lukem 				SLAP_AD_PROXIED|SLAP_AD_NOINSERT );
     96      1.1  lukem 
     97      1.1  lukem 		if( rc != LDAP_SUCCESS ) {
     98      1.1  lukem 			Debug( LDAP_DEBUG_FILTER,
     99      1.1  lukem 			"get_ava: unknown attributeType %s\n", type.bv_val, 0, 0 );
    100      1.1  lukem 			aa->aa_desc = slap_bv2tmp_ad( &type, op->o_tmpmemctx );
    101      1.1  lukem 			ber_dupbv_x( &aa->aa_value, &value, op->o_tmpmemctx );
    102      1.1  lukem 			f->f_ava = aa;
    103      1.1  lukem 			return rc;
    104      1.1  lukem 		}
    105      1.1  lukem 	}
    106      1.1  lukem 
    107      1.1  lukem 	rc = asserted_value_validate_normalize(
    108      1.1  lukem 		aa->aa_desc, ad_mr(aa->aa_desc, usage),
    109      1.1  lukem 		usage, &value, &aa->aa_value, text, op->o_tmpmemctx );
    110      1.1  lukem 
    111      1.1  lukem 	if( rc != LDAP_SUCCESS ) {
    112      1.1  lukem 		f->f_choice |= SLAPD_FILTER_UNDEFINED;
    113      1.1  lukem 		Debug( LDAP_DEBUG_FILTER,
    114      1.1  lukem 		"get_ava: illegal value for attributeType %s\n", type.bv_val, 0, 0 );
    115      1.1  lukem 		ber_dupbv_x( &aa->aa_value, &value, op->o_tmpmemctx );
    116  1.1.1.2  lukem 		*text = NULL;
    117      1.1  lukem 		rc = LDAP_SUCCESS;
    118      1.1  lukem 	}
    119      1.1  lukem 
    120      1.1  lukem #ifdef LDAP_COMP_MATCH
    121      1.1  lukem 	if( is_aliased_attribute ) {
    122      1.1  lukem 		a_alias = is_aliased_attribute ( aa->aa_desc );
    123      1.1  lukem 		if ( a_alias ) {
    124      1.1  lukem 			rc = get_aliased_filter_aa ( op, aa, a_alias, text );
    125      1.1  lukem 			if( rc != LDAP_SUCCESS ) {
    126      1.1  lukem 				Debug( LDAP_DEBUG_FILTER,
    127      1.1  lukem 						"get_ava:Invalid Attribute Aliasing\n", 0, 0, 0 );
    128      1.1  lukem 				return rc;
    129      1.1  lukem 			}
    130      1.1  lukem 		}
    131      1.1  lukem 	}
    132      1.1  lukem #endif
    133      1.1  lukem 	f->f_ava = aa;
    134      1.1  lukem 	return LDAP_SUCCESS;
    135      1.1  lukem }
    136