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>
18 #if BDB_CONFIG_INDICES
20 /* for the cache of attribute information (which are indexed, etc.) */
21 typedef struct bdb_attrinfo {
23 AttributeDescription *ai_desc; /* attribute description cn;lang-en */
27 slap_mask_t ai_indexmask; /* how the attr is indexed */
33 AttributeDescription *desc,
41 return ad_cmp( desc, a->ai_desc );
43 return( strcasecmp( desc, a->ai_desc ) );
54 return ad_cmp( a->ai_desc, b->ai_desc );
56 return( strcasecmp( a->ai_desc, b->ai_desc ) );
65 AttributeDescription *desc,
69 slap_mask_t *indexmask )
73 a = (AttrInfo *) avl_find( bdb->bi_attrs, desc,
74 (AVL_CMP) ainfo_type_cmp );
76 *indexmask = a != NULL ? a->ai_indexmask : 0;
81 bdb_attr_index_config(
92 char **indexes = NULL;
94 attrs = str2charray( argv[0], "," );
97 fprintf( stderr, "%s: line %d: "
98 "no attributes specified: %s\n",
99 fname, lineno, argv[0] );
100 return LDAP_PARAM_ERROR;
104 indexes = str2charray( argv[1], "," );
106 if( indexes == NULL ) {
107 fprintf( stderr, "%s: line %d: "
108 "no indexes specified: %s\n",
109 fname, lineno, argv[1] );
110 return LDAP_PARAM_ERROR;
114 if( indexes == NULL ) {
115 mask = bdb->bi_defaultmask;
120 for ( i = 0; indexes[i] != NULL; i++ ) {
122 rc = slap_str2index( indexes[i], &index );
124 if( rc != LDAP_SUCCESS ) {
125 fprintf( stderr, "%s: line %d: "
126 "index type \"%s\" undefined\n",
127 fname, lineno, indexes[i] );
128 return LDAP_PARAM_ERROR;
136 fprintf( stderr, "%s: line %d: "
137 "no indexes selected\n",
139 return LDAP_PARAM_ERROR;
142 for ( i = 0; attrs[i] != NULL; i++ ) {
144 AttributeDescription *ad;
147 if( strcasecmp( attrs[i], "default" ) == 0 ) {
148 bdb->bi_defaultmask = mask;
152 a = (AttrInfo *) ch_malloc( sizeof(AttrInfo) );
155 rc = slap_str2ad( attrs[i], &ad, &text );
157 if( rc != LDAP_SUCCESS ) {
158 fprintf( stderr, "%s: line %d: "
159 "index attribute \"%s\" undefined\n",
160 fname, lineno, attrs[i] );
164 if( slap_ad_is_binary( ad ) ) {
165 fprintf( stderr, "%s: line %d: "
166 "index of attribute \"%s\" disallowed\n",
167 fname, lineno, attrs[i] );
168 return LDAP_UNWILLING_TO_PERFORM;
171 if( IS_SLAP_INDEX( mask, SLAP_INDEX_APPROX ) && !(
172 ( ad->ad_type->sat_approx
173 && ad->ad_type->sat_approx->smr_indexer
174 && ad->ad_type->sat_approx->smr_filter )
175 && ( ad->ad_type->sat_equality
176 && ad->ad_type->sat_equality->smr_indexer
177 && ad->ad_type->sat_equality->smr_filter ) ) )
179 fprintf( stderr, "%s: line %d: "
180 "approx index of attribute \"%s\" disallowed\n",
181 fname, lineno, attrs[i] );
182 return LDAP_INAPPROPRIATE_MATCHING;
185 if( IS_SLAP_INDEX( mask, SLAP_INDEX_EQUALITY ) && !(
186 ad->ad_type->sat_equality
187 && ad->ad_type->sat_equality->smr_indexer
188 && ad->ad_type->sat_equality->smr_filter ) )
190 fprintf( stderr, "%s: line %d: "
191 "equality index of attribute \"%s\" disallowed\n",
192 fname, lineno, attrs[i] );
193 return LDAP_INAPPROPRIATE_MATCHING;
196 if( IS_SLAP_INDEX( mask, SLAP_INDEX_SUBSTR ) && !(
197 ad->ad_type->sat_substr
198 && ad->ad_type->sat_substr->smr_indexer
199 && ad->ad_type->sat_substr->smr_filter ) )
201 fprintf( stderr, "%s: line %d: "
202 "substr index of attribute \"%s\" disallowed\n",
203 fname, lineno, attrs[i] );
204 return LDAP_INAPPROPRIATE_MATCHING;
208 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
209 "attr_index_config: index %s 0x%04x\n",
210 ad->ad_cname->bv_val, mask ));
212 Debug( LDAP_DEBUG_CONFIG, "index %s 0x%04x\n",
213 ad->ad_cname->bv_val, mask, 0 );
220 a->ai_desc = ch_strdup( ad->ad_cname->bv_val );
224 a->ai_indexmask = mask;
226 rc = avl_insert( &bdb->bi_attrs, (caddr_t) a,
227 (AVL_CMP) ainfo_cmp, (AVL_DUP) avl_dup_error );
230 fprintf( stderr, "%s: line %d: duplicate index definition "
231 "for attr \"%s\" (ignored)\n",
232 fname, lineno, attrs[i] );
234 return LDAP_PARAM_ERROR;
238 charray_free( attrs );
239 if ( indexes != NULL ) charray_free( indexes );
246 ainfo_free( void *attr )
250 ad_free( ai->ai_desc, 1 );
258 bdb_attr_index_destroy( Avlnode *tree )
260 avl_free( tree, ainfo_free );