1 /* OpenLDAP WiredTiger backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2002-2016 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>.
17 * This work was developed by HAMANO Tsukasa <hamano@osstech.co.jp>
18 * based on back-bdb for inclusion in OpenLDAP Software.
19 * WiredTiger is a product of MongoDB Inc.
25 /* Find the ad, return -1 if not found,
26 * set point for insertion if ins is non-NULL
29 wt_attr_slot( struct wt_info *wi, AttributeDescription *ad, int *ins )
31 unsigned base = 0, cursor = 0;
32 unsigned n = wi->wi_nattrs;
36 unsigned pivot = n >> 1;
37 cursor = base + pivot;
39 val = SLAP_PTRCMP( ad, wi->wi_attrs[cursor]->ai_desc );
42 } else if ( val > 0 ) {
58 ainfo_insert( struct wt_info *wi, AttrInfo *a )
61 int i = wt_attr_slot( wi, a->ai_desc, &x );
67 wi->wi_attrs = ch_realloc( wi->wi_attrs, ( wi->wi_nattrs+1 ) *
68 sizeof( AttrInfo * ));
69 if ( x < wi->wi_nattrs )
70 AC_MEMCPY( &wi->wi_attrs[x+1], &wi->wi_attrs[x],
71 ( wi->wi_nattrs - x ) * sizeof( AttrInfo *));
80 AttributeDescription *desc )
82 int i = wt_attr_slot( wi, desc, NULL );
83 return i < 0 ? NULL : wi->wi_attrs[i];
93 struct config_reply_s *c_reply)
99 char **indexes = NULL;
101 attrs = ldap_str2charray( argv[0], "," );
103 if( attrs == NULL ) {
104 fprintf( stderr, "%s: line %d: "
105 "no attributes specified: %s\n",
106 fname, lineno, argv[0] );
107 return LDAP_PARAM_ERROR;
111 indexes = ldap_str2charray( argv[1], "," );
113 if( indexes == NULL ) {
114 fprintf( stderr, "%s: line %d: "
115 "no indexes specified: %s\n",
116 fname, lineno, argv[1] );
117 rc = LDAP_PARAM_ERROR;
122 if( indexes == NULL ) {
123 mask = wi->wi_defaultmask;
128 for ( i = 0; indexes[i] != NULL; i++ ) {
131 rc = slap_str2index( indexes[i], &index );
133 if( rc != LDAP_SUCCESS ) {
136 snprintf(c_reply->msg, sizeof(c_reply->msg),
137 "index type \"%s\" undefined", indexes[i] );
139 fprintf( stderr, "%s: line %d: %s\n",
140 fname, lineno, c_reply->msg );
142 rc = LDAP_PARAM_ERROR;
153 snprintf(c_reply->msg, sizeof(c_reply->msg),
154 "no indexes selected" );
155 fprintf( stderr, "%s: line %d: %s\n",
156 fname, lineno, c_reply->msg );
158 rc = LDAP_PARAM_ERROR;
162 for ( i = 0; attrs[i] != NULL; i++ ) {
164 AttributeDescription *ad;
166 #ifdef LDAP_COMP_MATCH
167 ComponentReference* cr = NULL;
168 AttrInfo *a_cr = NULL;
171 if( strcasecmp( attrs[i], "default" ) == 0 ) {
172 wi->wi_defaultmask |= mask;
176 #ifdef LDAP_COMP_MATCH
177 if ( is_component_reference( attrs[i] ) ) {
178 rc = extract_component_reference( attrs[i], &cr );
179 if ( rc != LDAP_SUCCESS ) {
182 snprintf(c_reply->msg, sizeof(c_reply->msg),
183 "index component reference\"%s\" undefined",
185 fprintf( stderr, "%s: line %d: %s\n",
186 fname, lineno, c_reply->msg );
190 cr->cr_indexmask = mask;
192 * After extracting a component reference
193 * only the name of a attribute will be remaining
200 rc = slap_str2ad( attrs[i], &ad, &text );
202 if( rc != LDAP_SUCCESS ) {
205 snprintf(c_reply->msg, sizeof(c_reply->msg),
206 "index attribute \"%s\" undefined",
209 fprintf( stderr, "%s: line %d: %s\n",
210 fname, lineno, c_reply->msg );
213 #ifdef LDAP_COMP_MATCH
219 if( ad == slap_schema.si_ad_entryDN || slap_ad_is_binary( ad ) ) {
221 snprintf(c_reply->msg, sizeof(c_reply->msg),
222 "index of attribute \"%s\" disallowed", attrs[i] );
223 fprintf( stderr, "%s: line %d: %s\n",
224 fname, lineno, c_reply->msg );
226 rc = LDAP_UNWILLING_TO_PERFORM;
230 if( IS_SLAP_INDEX( mask, SLAP_INDEX_APPROX ) && !(
231 ad->ad_type->sat_approx
232 && ad->ad_type->sat_approx->smr_indexer
233 && ad->ad_type->sat_approx->smr_filter ) )
236 snprintf(c_reply->msg, sizeof(c_reply->msg),
237 "approx index of attribute \"%s\" disallowed", attrs[i] );
238 fprintf( stderr, "%s: line %d: %s\n",
239 fname, lineno, c_reply->msg );
241 rc = LDAP_INAPPROPRIATE_MATCHING;
245 if( IS_SLAP_INDEX( mask, SLAP_INDEX_EQUALITY ) && !(
246 ad->ad_type->sat_equality
247 && ad->ad_type->sat_equality->smr_indexer
248 && ad->ad_type->sat_equality->smr_filter ) )
251 snprintf(c_reply->msg, sizeof(c_reply->msg),
252 "equality index of attribute \"%s\" disallowed", attrs[i] );
253 fprintf( stderr, "%s: line %d: %s\n",
254 fname, lineno, c_reply->msg );
256 rc = LDAP_INAPPROPRIATE_MATCHING;
260 if( IS_SLAP_INDEX( mask, SLAP_INDEX_SUBSTR ) && !(
261 ad->ad_type->sat_substr
262 && ad->ad_type->sat_substr->smr_indexer
263 && ad->ad_type->sat_substr->smr_filter ) )
266 snprintf(c_reply->msg, sizeof(c_reply->msg),
267 "substr index of attribute \"%s\" disallowed", attrs[i] );
268 fprintf( stderr, "%s: line %d: %s\n",
269 fname, lineno, c_reply->msg );
271 rc = LDAP_INAPPROPRIATE_MATCHING;
275 Debug( LDAP_DEBUG_CONFIG, "index %s 0x%04lx\n",
276 ad->ad_cname.bv_val, mask, 0 );
278 a = (AttrInfo *) ch_malloc( sizeof(AttrInfo) );
280 #ifdef LDAP_COMP_MATCH
285 if ( wi->wi_flags & WT_IS_OPEN ) {
287 a->ai_newmask = mask;
289 a->ai_indexmask = mask;
293 #ifdef LDAP_COMP_MATCH
295 a_cr = wt_attr_mask( wi, ad );
298 * AttrInfo is already in AVL
299 * just add the extracted component reference
303 rc = insert_component_reference( cr, &a_cr->ai_cr );
304 if ( rc != LDAP_SUCCESS) {
305 fprintf( stderr, " error during inserting component reference in %s ", attrs[i]);
306 rc = LDAP_PARAM_ERROR;
311 rc = insert_component_reference( cr, &a->ai_cr );
312 if ( rc != LDAP_SUCCESS) {
313 fprintf( stderr, " error during inserting component reference in %s ", attrs[i]);
314 rc = LDAP_PARAM_ERROR;
321 rc = ainfo_insert( wi, a );
323 if ( wi->wi_flags & WT_IS_OPEN ) {
324 AttrInfo *b = wt_attr_mask( wi, ad );
325 /* If there is already an index defined for this attribute
326 * it must be replaced. Otherwise we end up with multiple
327 * olcIndex values for the same attribute */
328 if ( b->ai_indexmask & WT_INDEX_DELETING ) {
329 /* If we were editing this attr, reset it */
330 b->ai_indexmask &= ~WT_INDEX_DELETING;
331 /* If this is leftover from a previous add, commit it */
333 b->ai_indexmask = b->ai_newmask;
334 b->ai_newmask = a->ai_newmask;
341 snprintf(c_reply->msg, sizeof(c_reply->msg),
342 "duplicate index definition for attr \"%s\"",
344 fprintf( stderr, "%s: line %d: %s\n",
345 fname, lineno, c_reply->msg );
348 rc = LDAP_PARAM_ERROR;
354 ldap_charray_free( attrs );
355 if ( indexes != NULL ) ldap_charray_free( indexes );
361 wt_attr_info_free( AttrInfo *ai )
363 #ifdef LDAP_COMP_MATCH
370 wt_attr_index_destroy( struct wt_info *wi )
374 for ( i=0; i<wi->wi_nattrs; i++ )
375 wt_attr_info_free( wi->wi_attrs[i] );
377 free( wi->wi_attrs );
384 * indent-tabs-mode: t