1 /* attr.c - backend routines for dealing with attributes */
4 * Copyright 1998-2003 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"
18 /* for the cache of attribute information (which are indexed, etc.) */
19 typedef struct ldbm_attrinfo {
20 AttributeDescription *ai_desc; /* attribute description cn;lang-en */
21 slap_mask_t ai_indexmask; /* how the attr is indexed */
30 const AttributeDescription *desc = v_desc;
31 const AttrInfo *a = v_a;
32 return desc - a->ai_desc;
41 const AttrInfo *a = v_a, *b = v_b;
42 return a->ai_desc - b->ai_desc;
48 AttributeDescription *desc,
49 slap_mask_t *indexmask )
53 a = avl_find( li->li_attrs, desc, ainfo_type_cmp );
55 *indexmask = a != NULL ? a->ai_indexmask : 0;
70 char **indexes = NULL;
72 attrs = ldap_str2charray( argv[0], "," );
75 fprintf( stderr, "%s: line %d: "
76 "no attributes specified: %s\n",
77 fname, lineno, argv[0] );
78 return LDAP_PARAM_ERROR;
82 indexes = ldap_str2charray( argv[1], "," );
84 if( indexes == NULL ) {
85 fprintf( stderr, "%s: line %d: "
86 "no indexes specified: %s\n",
87 fname, lineno, argv[1] );
88 return LDAP_PARAM_ERROR;
92 if( indexes == NULL ) {
93 mask = li->li_defaultmask;
98 for ( i = 0; indexes[i] != NULL; i++ ) {
100 rc = slap_str2index( indexes[i], &index );
102 if( rc != LDAP_SUCCESS ) {
103 fprintf( stderr, "%s: line %d: "
104 "index type \"%s\" undefined\n",
105 fname, lineno, indexes[i] );
106 return LDAP_PARAM_ERROR;
114 fprintf( stderr, "%s: line %d: "
115 "no indexes selected\n",
117 return LDAP_PARAM_ERROR;
120 for ( i = 0; attrs[i] != NULL; i++ ) {
122 AttributeDescription *ad;
125 if( strcasecmp( attrs[i], "default" ) == 0 ) {
126 li->li_defaultmask = mask;
130 a = (AttrInfo *) ch_malloc( sizeof(AttrInfo) );
133 rc = slap_str2ad( attrs[i], &ad, &text );
135 if( rc != LDAP_SUCCESS ) {
136 fprintf( stderr, "%s: line %d: "
137 "index attribute \"%s\" undefined\n",
138 fname, lineno, attrs[i] );
142 if( slap_ad_is_binary( ad ) ) {
143 fprintf( stderr, "%s: line %d: "
144 "index of attribute \"%s\" disallowed\n",
145 fname, lineno, attrs[i] );
146 return LDAP_UNWILLING_TO_PERFORM;
149 if( IS_SLAP_INDEX( mask, SLAP_INDEX_APPROX ) && !(
150 ( ad->ad_type->sat_approx
151 && ad->ad_type->sat_approx->smr_indexer
152 && ad->ad_type->sat_approx->smr_filter )
153 && ( ad->ad_type->sat_equality
154 && ad->ad_type->sat_equality->smr_indexer
155 && ad->ad_type->sat_equality->smr_filter ) ) )
157 fprintf( stderr, "%s: line %d: "
158 "approx index of attribute \"%s\" disallowed\n",
159 fname, lineno, attrs[i] );
160 return LDAP_INAPPROPRIATE_MATCHING;
163 if( IS_SLAP_INDEX( mask, SLAP_INDEX_EQUALITY ) && !(
164 ad->ad_type->sat_equality
165 && ad->ad_type->sat_equality->smr_indexer
166 && ad->ad_type->sat_equality->smr_filter ) )
168 fprintf( stderr, "%s: line %d: "
169 "equality index of attribute \"%s\" disallowed\n",
170 fname, lineno, attrs[i] );
171 return LDAP_INAPPROPRIATE_MATCHING;
174 if( IS_SLAP_INDEX( mask, SLAP_INDEX_SUBSTR ) && !(
175 ad->ad_type->sat_substr
176 && ad->ad_type->sat_substr->smr_indexer
177 && ad->ad_type->sat_substr->smr_filter ) )
179 fprintf( stderr, "%s: line %d: "
180 "substr index of attribute \"%s\" disallowed\n",
181 fname, lineno, attrs[i] );
182 return LDAP_INAPPROPRIATE_MATCHING;
186 LDAP_LOG( BACK_LDBM, DETAIL1,
187 "attr_index_config: index %s 0x%04lx\n",
188 ad->ad_cname.bv_val, mask, 0 );
190 Debug( LDAP_DEBUG_CONFIG, "index %s 0x%04lx\n",
191 ad->ad_cname.bv_val, mask, 0 );
197 a->ai_indexmask = mask;
199 rc = avl_insert( &li->li_attrs, (caddr_t) a,
200 ainfo_cmp, avl_dup_error );
203 fprintf( stderr, "%s: line %d: duplicate index definition "
204 "for attr \"%s\" (ignored)\n",
205 fname, lineno, attrs[i] );
207 return LDAP_PARAM_ERROR;
211 ldap_charray_free( attrs );
212 if ( indexes != NULL ) ldap_charray_free( indexes );
218 attr_index_destroy( Avlnode *tree )
220 avl_free( tree, free );