Back to index

openldap  2.4.31
ava.c
Go to the documentation of this file.
00001 /* ava.c - routines for dealing with attribute value assertions */
00002 /* $OpenLDAP$ */
00003 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00004  *
00005  * Copyright 1998-2012 The OpenLDAP Foundation.
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted only as authorized by the OpenLDAP
00010  * Public License.
00011  *
00012  * A copy of this license is available in the file LICENSE in the
00013  * top-level directory of the distribution or, alternatively, at
00014  * <http://www.OpenLDAP.org/license.html>.
00015  */
00016 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
00017  * All rights reserved.
00018  *
00019  * Redistribution and use in source and binary forms are permitted
00020  * provided that this notice is preserved and that due credit is given
00021  * to the University of Michigan at Ann Arbor. The name of the University
00022  * may not be used to endorse or promote products derived from this
00023  * software without specific prior written permission. This software
00024  * is provided ``as is'' without express or implied warranty.
00025  */
00026 
00027 #include "portable.h"
00028 
00029 #include <stdio.h>
00030 
00031 #include <ac/string.h>
00032 #include <ac/socket.h>
00033 
00034 #include "slap.h"
00035 
00036 #ifdef LDAP_COMP_MATCH
00037 #include "component.h"
00038 #endif
00039 
00040 void
00041 ava_free(
00042        Operation *op,
00043        AttributeAssertion *ava,
00044        int    freeit )
00045 {
00046 #ifdef LDAP_COMP_MATCH
00047        if ( ava->aa_cf && ava->aa_cf->cf_ca->ca_comp_data.cd_mem_op )
00048               nibble_mem_free ( ava->aa_cf->cf_ca->ca_comp_data.cd_mem_op );
00049 #endif
00050        op->o_tmpfree( ava->aa_value.bv_val, op->o_tmpmemctx );
00051        if ( ava->aa_desc->ad_flags & SLAP_DESC_TEMPORARY )
00052               op->o_tmpfree( ava->aa_desc, op->o_tmpmemctx );
00053        if ( freeit ) op->o_tmpfree( (char *) ava, op->o_tmpmemctx );
00054 }
00055 
00056 int
00057 get_ava(
00058        Operation *op,
00059        BerElement    *ber,
00060        Filter *f,
00061        unsigned usage,
00062        const char **text )
00063 {
00064        int rc;
00065        ber_tag_t rtag;
00066        struct berval type, value;
00067        AttributeAssertion *aa;
00068 #ifdef LDAP_COMP_MATCH
00069        AttributeAliasing* a_alias = NULL;
00070 #endif
00071 
00072        rtag = ber_scanf( ber, "{mm}", &type, &value );
00073 
00074        if( rtag == LBER_ERROR ) {
00075               Debug( LDAP_DEBUG_ANY, "  get_ava ber_scanf\n", 0, 0, 0 );
00076               *text = "Error decoding attribute value assertion";
00077               return SLAPD_DISCONNECT;
00078        }
00079 
00080        aa = op->o_tmpalloc( sizeof( AttributeAssertion ), op->o_tmpmemctx );
00081        aa->aa_desc = NULL;
00082        aa->aa_value.bv_val = NULL;
00083 #ifdef LDAP_COMP_MATCH
00084        aa->aa_cf = NULL;
00085 #endif
00086 
00087        rc = slap_bv2ad( &type, &aa->aa_desc, text );
00088 
00089        if( rc != LDAP_SUCCESS ) {
00090               f->f_choice |= SLAPD_FILTER_UNDEFINED;
00091               *text = NULL;
00092               rc = slap_bv2undef_ad( &type, &aa->aa_desc, text,
00093                             SLAP_AD_PROXIED|SLAP_AD_NOINSERT );
00094 
00095               if( rc != LDAP_SUCCESS ) {
00096                      Debug( LDAP_DEBUG_FILTER,
00097                      "get_ava: unknown attributeType %s\n", type.bv_val, 0, 0 );
00098                      aa->aa_desc = slap_bv2tmp_ad( &type, op->o_tmpmemctx );
00099                      ber_dupbv_x( &aa->aa_value, &value, op->o_tmpmemctx );
00100                      f->f_ava = aa;
00101                      return LDAP_SUCCESS;
00102               }
00103        }
00104 
00105        rc = asserted_value_validate_normalize(
00106               aa->aa_desc, ad_mr(aa->aa_desc, usage),
00107               usage, &value, &aa->aa_value, text, op->o_tmpmemctx );
00108 
00109        if( rc != LDAP_SUCCESS ) {
00110               f->f_choice |= SLAPD_FILTER_UNDEFINED;
00111               Debug( LDAP_DEBUG_FILTER,
00112               "get_ava: illegal value for attributeType %s\n", type.bv_val, 0, 0 );
00113               ber_dupbv_x( &aa->aa_value, &value, op->o_tmpmemctx );
00114               *text = NULL;
00115               rc = LDAP_SUCCESS;
00116        }
00117 
00118 #ifdef LDAP_COMP_MATCH
00119        if( is_aliased_attribute ) {
00120               a_alias = is_aliased_attribute ( aa->aa_desc );
00121               if ( a_alias ) {
00122                      rc = get_aliased_filter_aa ( op, aa, a_alias, text );
00123                      if( rc != LDAP_SUCCESS ) {
00124                             Debug( LDAP_DEBUG_FILTER,
00125                                           "get_ava: Invalid Attribute Aliasing\n", 0, 0, 0 );
00126                             return rc;
00127                      }
00128               }
00129        }
00130 #endif
00131        f->f_ava = aa;
00132        return LDAP_SUCCESS;
00133 }