1 /* attr.c - backend routines for dealing with attributes */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2000-2004 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
21 #include <ac/socket.h>
22 #include <ac/string.h>
27 /* for the cache of attribute information (which are indexed, etc.) */
28 typedef struct bdb_attrinfo {
29 AttributeDescription *ai_desc; /* attribute description cn;lang-en */
30 slap_mask_t ai_indexmask; /* how the attr is indexed */
39 const AttributeDescription *desc = v_desc;
40 const AttrInfo *a = v_a;
41 return SLAP_PTRCMP(desc, a->ai_desc);
50 const AttrInfo *a = v_a, *b = v_b;
51 return SLAP_PTRCMP(a->ai_desc, b->ai_desc);
57 AttributeDescription *desc,
58 slap_mask_t *indexmask )
62 a = (AttrInfo *) avl_find( bdb->bi_attrs, desc, ainfo_type_cmp );
64 *indexmask = a != NULL ? a->ai_indexmask : 0;
68 bdb_attr_index_config(
79 char **indexes = NULL;
81 attrs = ldap_str2charray( argv[0], "," );
84 fprintf( stderr, "%s: line %d: "
85 "no attributes specified: %s\n",
86 fname, lineno, argv[0] );
87 return LDAP_PARAM_ERROR;
91 indexes = ldap_str2charray( argv[1], "," );
93 if( indexes == NULL ) {
94 fprintf( stderr, "%s: line %d: "
95 "no indexes specified: %s\n",
96 fname, lineno, argv[1] );
97 return LDAP_PARAM_ERROR;
101 if( indexes == NULL ) {
102 mask = bdb->bi_defaultmask;
107 for ( i = 0; indexes[i] != NULL; i++ ) {
109 rc = slap_str2index( indexes[i], &index );
111 if( rc != LDAP_SUCCESS ) {
112 fprintf( stderr, "%s: line %d: "
113 "index type \"%s\" undefined\n",
114 fname, lineno, indexes[i] );
115 return LDAP_PARAM_ERROR;
123 fprintf( stderr, "%s: line %d: "
124 "no indexes selected\n",
126 return LDAP_PARAM_ERROR;
129 for ( i = 0; attrs[i] != NULL; i++ ) {
131 AttributeDescription *ad;
134 if( strcasecmp( attrs[i], "default" ) == 0 ) {
135 bdb->bi_defaultmask = mask;
139 a = (AttrInfo *) ch_malloc( sizeof(AttrInfo) );
142 rc = slap_str2ad( attrs[i], &ad, &text );
144 if( rc != LDAP_SUCCESS ) {
145 fprintf( stderr, "%s: line %d: "
146 "index attribute \"%s\" undefined\n",
147 fname, lineno, attrs[i] );
151 if( slap_ad_is_binary( ad ) ) {
152 fprintf( stderr, "%s: line %d: "
153 "index of attribute \"%s\" disallowed\n",
154 fname, lineno, attrs[i] );
155 return LDAP_UNWILLING_TO_PERFORM;
158 if( IS_SLAP_INDEX( mask, SLAP_INDEX_APPROX ) && !(
159 ( ad->ad_type->sat_approx
160 && ad->ad_type->sat_approx->smr_indexer
161 && ad->ad_type->sat_approx->smr_filter )
162 && ( ad->ad_type->sat_equality
163 && ad->ad_type->sat_equality->smr_indexer
164 && ad->ad_type->sat_equality->smr_filter ) ) )
166 fprintf( stderr, "%s: line %d: "
167 "approx index of attribute \"%s\" disallowed\n",
168 fname, lineno, attrs[i] );
169 return LDAP_INAPPROPRIATE_MATCHING;
172 if( IS_SLAP_INDEX( mask, SLAP_INDEX_EQUALITY ) && !(
173 ad->ad_type->sat_equality
174 && ad->ad_type->sat_equality->smr_indexer
175 && ad->ad_type->sat_equality->smr_filter ) )
177 fprintf( stderr, "%s: line %d: "
178 "equality index of attribute \"%s\" disallowed\n",
179 fname, lineno, attrs[i] );
180 return LDAP_INAPPROPRIATE_MATCHING;
183 if( IS_SLAP_INDEX( mask, SLAP_INDEX_SUBSTR ) && !(
184 ad->ad_type->sat_substr
185 && ad->ad_type->sat_substr->smr_indexer
186 && ad->ad_type->sat_substr->smr_filter ) )
188 fprintf( stderr, "%s: line %d: "
189 "substr index of attribute \"%s\" disallowed\n",
190 fname, lineno, attrs[i] );
191 return LDAP_INAPPROPRIATE_MATCHING;
195 LDAP_LOG( BACK_BDB, DETAIL1,
196 "attr_index_config: index %s 0x%04lx\n",
197 ad->ad_cname.bv_val, mask, 0 );
199 Debug( LDAP_DEBUG_CONFIG, "index %s 0x%04lx\n",
200 ad->ad_cname.bv_val, mask, 0 );
205 a->ai_indexmask = mask;
207 rc = avl_insert( &bdb->bi_attrs, (caddr_t) a,
208 ainfo_cmp, avl_dup_error );
211 fprintf( stderr, "%s: line %d: duplicate index definition "
212 "for attr \"%s\" (ignored)\n",
213 fname, lineno, attrs[i] );
215 return LDAP_PARAM_ERROR;
219 ldap_charray_free( attrs );
220 if ( indexes != NULL ) ldap_charray_free( indexes );
226 bdb_attr_index_destroy( Avlnode *tree )
228 avl_free( tree, free );