1 /* attr.c - backend routines for dealing with attributes */
4 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/socket.h>
13 #include <ac/string.h>
16 #include "back-ldbm.h"
19 /* for the cache of attribute information (which are indexed, etc.) */
20 typedef struct ldbm_attrinfo {
22 AttributeDescription *ai_desc; /* attribute description cn;lang-en */
26 slap_mask_t ai_indexmask; /* how the attr is indexed */
32 AttributeDescription *desc,
40 return ad_cmp( desc, a->ai_desc );
42 return( strcasecmp( desc, a->ai_desc ) );
53 return ad_cmp( a->ai_desc, b->ai_desc );
55 return( strcasecmp( a->ai_desc, b->ai_desc ) );
63 AttributeDescription *desc,
67 slap_mask_t *indexmask )
71 a = (AttrInfo *) avl_find( li->li_attrs, desc,
72 (AVL_CMP) ainfo_type_cmp );
74 *indexmask = a != NULL ? a->ai_indexmask : 0;
89 char **indexes = NULL;
91 attrs = str2charray( argv[0], "," );
94 fprintf( stderr, "%s: line %d: "
95 "no attributes specified: %s\n",
96 fname, lineno, argv[0] );
97 return LDAP_PARAM_ERROR;
101 indexes = str2charray( argv[1], "," );
103 if( indexes == NULL ) {
104 fprintf( stderr, "%s: line %d: "
105 "no indexes specified: %s\n",
106 fname, lineno, argv[1] );
107 return LDAP_PARAM_ERROR;
111 if( indexes == NULL ) {
112 mask = li->li_defaultmask;
117 for ( i = 0; indexes[i] != NULL; i++ ) {
119 rc = slap_str2index( indexes[i], &index );
121 if( rc != LDAP_SUCCESS ) {
122 fprintf( stderr, "%s: line %d: "
123 "index type \"%s\" undefined\n",
124 fname, lineno, indexes[i] );
125 return LDAP_PARAM_ERROR;
133 fprintf( stderr, "%s: line %d: "
134 "no indexes selected\n",
136 return LDAP_PARAM_ERROR;
139 for ( i = 0; attrs[i] != NULL; i++ ) {
141 AttributeDescription *ad;
144 if( strcasecmp( attrs[i], "default" ) == 0 ) {
145 li->li_defaultmask = mask;
149 a = (AttrInfo *) ch_malloc( sizeof(AttrInfo) );
152 rc = slap_str2ad( attrs[i], &ad, &text );
154 if( rc != LDAP_SUCCESS ) {
155 fprintf( stderr, "%s: line %d: "
156 "index attribute \"%s\" undefined\n",
157 fname, lineno, attrs[i] );
161 if( slap_ad_is_binary( ad ) ) {
162 fprintf( stderr, "%s: line %d: "
163 "index of attribute \"%s\" disallowed\n",
164 fname, lineno, attrs[i] );
165 return LDAP_UNWILLING_TO_PERFORM;
168 if( IS_SLAP_INDEX( mask, SLAP_INDEX_APPROX ) && !(
169 ( ad->ad_type->sat_approx
170 && ad->ad_type->sat_approx->smr_indexer
171 && ad->ad_type->sat_approx->smr_filter )
172 && ( ad->ad_type->sat_equality
173 && ad->ad_type->sat_equality->smr_indexer
174 && ad->ad_type->sat_equality->smr_filter ) ) )
176 fprintf( stderr, "%s: line %d: "
177 "approx index of attribute \"%s\" disallowed\n",
178 fname, lineno, attrs[i] );
179 return LDAP_INAPPROPRIATE_MATCHING;
182 if( IS_SLAP_INDEX( mask, SLAP_INDEX_EQUALITY ) && !(
183 ad->ad_type->sat_equality
184 && ad->ad_type->sat_equality->smr_indexer
185 && ad->ad_type->sat_equality->smr_filter ) )
187 fprintf( stderr, "%s: line %d: "
188 "equality index of attribute \"%s\" disallowed\n",
189 fname, lineno, attrs[i] );
190 return LDAP_INAPPROPRIATE_MATCHING;
193 if( IS_SLAP_INDEX( mask, SLAP_INDEX_SUBSTR ) && !(
194 ad->ad_type->sat_substr
195 && ad->ad_type->sat_substr->smr_indexer
196 && ad->ad_type->sat_substr->smr_filter ) )
198 fprintf( stderr, "%s: line %d: "
199 "substr index of attribute \"%s\" disallowed\n",
200 fname, lineno, attrs[i] );
201 return LDAP_INAPPROPRIATE_MATCHING;
205 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
206 "attr_index_config: index %s 0x%04x\n",
207 ad->ad_cname.bv_val, mask ));
209 Debug( LDAP_DEBUG_CONFIG, "index %s 0x%04x\n",
210 ad->ad_cname.bv_val, mask, 0 );
217 a->ai_desc = ch_strdup( ad->ad_cname.bv_val );
220 a->ai_indexmask = mask;
222 rc = avl_insert( &li->li_attrs, (caddr_t) a,
223 (AVL_CMP) ainfo_cmp, (AVL_DUP) avl_dup_error );
226 fprintf( stderr, "%s: line %d: duplicate index definition "
227 "for attr \"%s\" (ignored)\n",
228 fname, lineno, attrs[i] );
230 return LDAP_PARAM_ERROR;
234 charray_free( attrs );
235 if ( indexes != NULL ) charray_free( indexes );
242 ainfo_free( void *attr )
252 attr_index_destroy( Avlnode *tree )
254 avl_free( tree, ainfo_free );