1 /* attr.c - backend routines for dealing with attributes */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2006 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>
25 #include "back-ldbm.h"
27 /* for the cache of attribute information (which are indexed, etc.) */
28 typedef struct ldbm_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 = avl_find( li->li_attrs, desc, ainfo_type_cmp );
64 *indexmask = a != NULL ? a->ai_indexmask : 0;
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 = li->li_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 li->li_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 ) )
163 fprintf( stderr, "%s: line %d: "
164 "approx index of attribute \"%s\" disallowed\n",
165 fname, lineno, attrs[i] );
166 return LDAP_INAPPROPRIATE_MATCHING;
169 if( IS_SLAP_INDEX( mask, SLAP_INDEX_EQUALITY ) && !(
170 ad->ad_type->sat_equality
171 && ad->ad_type->sat_equality->smr_indexer
172 && ad->ad_type->sat_equality->smr_filter ) )
174 fprintf( stderr, "%s: line %d: "
175 "equality index of attribute \"%s\" disallowed\n",
176 fname, lineno, attrs[i] );
177 return LDAP_INAPPROPRIATE_MATCHING;
180 if( IS_SLAP_INDEX( mask, SLAP_INDEX_SUBSTR ) && !(
181 ad->ad_type->sat_substr
182 && ad->ad_type->sat_substr->smr_indexer
183 && ad->ad_type->sat_substr->smr_filter ) )
185 fprintf( stderr, "%s: line %d: "
186 "substr index of attribute \"%s\" disallowed\n",
187 fname, lineno, attrs[i] );
188 return LDAP_INAPPROPRIATE_MATCHING;
191 Debug( LDAP_DEBUG_CONFIG, "index %s 0x%04lx\n",
192 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\"" SLAPD_CONF_UNKNOWN_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 );