Home | History | Annotate | Line # | Download | only in back-wt
      1  1.1  christos /*	$NetBSD: config.c,v 1.3 2025/09/05 21:16:31 christos Exp $	*/
      2  1.1  christos 
      3  1.1  christos /* OpenLDAP WiredTiger backend */
      4  1.1  christos /* $OpenLDAP$ */
      5  1.1  christos /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
      6  1.1  christos  *
      7  1.3  christos  * Copyright 2002-2024 The OpenLDAP Foundation.
      8  1.1  christos  * All rights reserved.
      9  1.1  christos  *
     10  1.1  christos  * Redistribution and use in source and binary forms, with or without
     11  1.1  christos  * modification, are permitted only as authorized by the OpenLDAP
     12  1.1  christos  * Public License.
     13  1.1  christos  *
     14  1.1  christos  * A copy of this license is available in the file LICENSE in the
     15  1.1  christos  * top-level directory of the distribution or, alternatively, at
     16  1.1  christos  * <http://www.OpenLDAP.org/license.html>.
     17  1.1  christos  */
     18  1.1  christos /* ACKNOWLEDGEMENTS:
     19  1.1  christos  * This work was developed by HAMANO Tsukasa <hamano (at) osstech.co.jp>
     20  1.1  christos  * based on back-bdb for inclusion in OpenLDAP Software.
     21  1.1  christos  * WiredTiger is a product of MongoDB Inc.
     22  1.1  christos  */
     23  1.1  christos 
     24  1.1  christos #include <sys/cdefs.h>
     25  1.1  christos __RCSID("$NetBSD: config.c,v 1.3 2025/09/05 21:16:31 christos Exp $");
     26  1.1  christos 
     27  1.1  christos #include "portable.h"
     28  1.1  christos 
     29  1.1  christos #include <stdio.h>
     30  1.1  christos #include <ac/string.h>
     31  1.1  christos #include "back-wt.h"
     32  1.1  christos #include "slap-config.h"
     33  1.1  christos 
     34  1.1  christos #include "lutil.h"
     35  1.1  christos #include "ldap_rq.h"
     36  1.1  christos 
     37  1.1  christos static ConfigDriver wt_cf_gen;
     38  1.1  christos 
     39  1.1  christos enum {
     40  1.1  christos 	WT_DIRECTORY = 1,
     41  1.1  christos 	WT_CONFIG,
     42  1.1  christos 	WT_INDEX,
     43  1.3  christos 	WT_MODE,
     44  1.3  christos 	WT_IDLCACHE,
     45  1.1  christos };
     46  1.1  christos 
     47  1.1  christos static ConfigTable wtcfg[] = {
     48  1.1  christos     { "directory", "dir", 2, 2, 0, ARG_STRING|ARG_MAGIC|WT_DIRECTORY,
     49  1.1  christos 	  wt_cf_gen, "( OLcfgDbAt:0.1 NAME 'olcDbDirectory' "
     50  1.1  christos 	  "DESC 'Directory for database content' "
     51  1.1  christos 	  "EQUALITY caseIgnoreMatch "
     52  1.1  christos 	  "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
     53  1.1  christos 	{ "index", "attr> <[pres,eq,approx,sub]", 2, 3, 0, ARG_MAGIC|WT_INDEX,
     54  1.1  christos 	  wt_cf_gen, "( OLcfgDbAt:0.2 NAME 'olcDbIndex' "
     55  1.1  christos 	  "DESC 'Attribute index parameters' "
     56  1.1  christos 	  "EQUALITY caseIgnoreMatch "
     57  1.1  christos 	  "SYNTAX OMsDirectoryString )", NULL, NULL },
     58  1.3  christos 	{ "mode", "mode", 2, 2, 0, ARG_MAGIC|WT_MODE,
     59  1.3  christos 	  wt_cf_gen, "( OLcfgDbAt:0.3 NAME 'olcDbMode' "
     60  1.3  christos 	  "DESC 'Unix permissions of database files' "
     61  1.3  christos 	  "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
     62  1.3  christos 	{ "wtconfig", "config", 2, 2, 0, ARG_STRING|ARG_MAGIC|WT_CONFIG,
     63  1.3  christos 	  wt_cf_gen, "( OLcfgDbAt:13.1 NAME 'olcWtConfig' "
     64  1.3  christos 	  "DESC 'Configuration for WiredTiger' "
     65  1.3  christos 	  "EQUALITY caseIgnoreMatch "
     66  1.3  christos 	  "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
     67  1.3  christos 	{ "idlcache", NULL, 1, 2, 0, ARG_ON_OFF|ARG_MAGIC|WT_IDLCACHE,
     68  1.3  christos 	  wt_cf_gen, "( OLcfgDbAt:13.2 NAME 'olcIDLcache' "
     69  1.3  christos 	  "DESC 'enable IDL cache' "
     70  1.3  christos 	  "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
     71  1.1  christos 	{ NULL, NULL, 0, 0, 0, ARG_IGNORED,
     72  1.1  christos 		NULL, NULL, NULL, NULL }
     73  1.1  christos };
     74  1.1  christos 
     75  1.1  christos static ConfigOCs wtocs[] = {
     76  1.3  christos 	{ "( OLcfgDbOc:13.1 "
     77  1.1  christos 	  "NAME 'olcWtConfig' "
     78  1.1  christos 	  "DESC 'Wt backend configuration' "
     79  1.1  christos 	  "SUP olcDatabaseConfig "
     80  1.1  christos 	  "MUST olcDbDirectory "
     81  1.3  christos 	  "MAY ( olcWtConfig $ olcDbIndex $ olcDbMode $ olcIDLcache) )",
     82  1.1  christos 	  Cft_Database, wtcfg },
     83  1.1  christos 	{ NULL, 0, NULL }
     84  1.1  christos };
     85  1.1  christos 
     86  1.1  christos /* reindex entries on the fly */
     87  1.1  christos static void *
     88  1.1  christos wt_online_index( void *ctx, void *arg )
     89  1.1  christos {
     90  1.1  christos 	// Not implement yet
     91  1.3  christos 	return NULL;
     92  1.1  christos }
     93  1.1  christos 
     94  1.1  christos /* Cleanup loose ends after Modify completes */
     95  1.1  christos static int
     96  1.1  christos wt_cf_cleanup( ConfigArgs *c )
     97  1.1  christos {
     98  1.1  christos 	// Not implement yet
     99  1.1  christos 	return 0;
    100  1.1  christos }
    101  1.1  christos 
    102  1.1  christos static int
    103  1.1  christos wt_cf_gen( ConfigArgs *c )
    104  1.1  christos {
    105  1.1  christos 	struct wt_info *wi = (struct wt_info *) c->be->be_private;
    106  1.1  christos 	int rc;
    107  1.1  christos 
    108  1.3  christos 	if( c->op == SLAP_CONFIG_EMIT ) {
    109  1.3  christos 		rc = 0;
    110  1.3  christos 		switch( c->type ) {
    111  1.3  christos 		case WT_DIRECTORY:
    112  1.3  christos 			if ( wi->wi_home ) {
    113  1.3  christos 				c->value_string = ch_strdup( wi->wi_home );
    114  1.3  christos 			} else {
    115  1.3  christos 				rc = 1;
    116  1.3  christos 			}
    117  1.3  christos 			break;
    118  1.3  christos 		case WT_INDEX:
    119  1.3  christos 			wt_attr_index_unparse( wi, &c->rvalue_vals );
    120  1.3  christos 			if ( !c->rvalue_vals ) rc = 1;
    121  1.3  christos 			break;
    122  1.3  christos 		case WT_IDLCACHE:
    123  1.3  christos 			if ( wi->wi_flags & WT_USE_IDLCACHE) {
    124  1.3  christos 				c->value_int = 1;
    125  1.3  christos 			}
    126  1.3  christos 			break;
    127  1.3  christos 		}
    128  1.3  christos 		return rc;
    129  1.3  christos 	} else if ( c->op == LDAP_MOD_DELETE ) {
    130  1.1  christos 		rc = 0;
    131  1.1  christos 		return rc;
    132  1.1  christos 	}
    133  1.1  christos 
    134  1.1  christos 	switch( c->type ) {
    135  1.1  christos 	case WT_DIRECTORY:
    136  1.3  christos 		ch_free( wi->wi_home );
    137  1.3  christos 		wi->wi_home = c->value_string;
    138  1.1  christos 		break;
    139  1.1  christos 	case WT_CONFIG:
    140  1.3  christos 		if(strlen(wi->wi_config) + 1 + strlen(c->value_string) > WT_CONFIG_MAX){
    141  1.3  christos 			fprintf( stderr, "%s: "
    142  1.3  christos 					 "\"wtconfig\" are too long. Increase WT_CONFIG_MAX or you may realloc the buffer.\n",
    143  1.3  christos 					 c->log );
    144  1.3  christos 			return 1;
    145  1.3  christos 		}
    146  1.3  christos 		/* size of wi->wi_config is WT_CONFIG_MAX + 1, it's guaranteed with NUL-terminate. */
    147  1.3  christos 		strcat(wi->wi_config, ",");
    148  1.3  christos 		strcat(wi->wi_config, c->value_string);
    149  1.1  christos 		break;
    150  1.1  christos 
    151  1.1  christos 	case WT_INDEX:
    152  1.1  christos 		rc = wt_attr_index_config( wi, c->fname, c->lineno,
    153  1.1  christos 								   c->argc - 1, &c->argv[1], &c->reply);
    154  1.1  christos 
    155  1.1  christos 		if( rc != LDAP_SUCCESS ) return 1;
    156  1.1  christos 		wi->wi_flags |= WT_OPEN_INDEX;
    157  1.1  christos 
    158  1.1  christos 		if ( wi->wi_flags & WT_IS_OPEN ) {
    159  1.1  christos 			config_push_cleanup( c, wt_cf_cleanup );
    160  1.1  christos 
    161  1.1  christos 			if ( !wi->wi_index_task ) {
    162  1.1  christos 				/* Start the task as soon as we finish here. Set a long
    163  1.1  christos                  * interval (10 hours) so that it only gets scheduled once.
    164  1.1  christos                  */
    165  1.1  christos 				if ( c->be->be_suffix == NULL || BER_BVISNULL( &c->be->be_suffix[0] ) ) {
    166  1.1  christos 					fprintf( stderr, "%s: "
    167  1.1  christos 							 "\"index\" must occur after \"suffix\".\n",
    168  1.1  christos 							 c->log );
    169  1.1  christos 					return 1;
    170  1.1  christos 				}
    171  1.1  christos 				ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
    172  1.1  christos 				wi->wi_index_task = ldap_pvt_runqueue_insert(&slapd_rq, 36000,
    173  1.1  christos 															 wt_online_index, c->be,
    174  1.1  christos 															 LDAP_XSTRING(wt_online_index),
    175  1.1  christos 															 c->be->be_suffix[0].bv_val );
    176  1.1  christos 				ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
    177  1.1  christos 			}
    178  1.1  christos 		}
    179  1.1  christos 		break;
    180  1.1  christos 
    181  1.3  christos 	case WT_MODE:
    182  1.3  christos 		fprintf( stderr, "%s: "
    183  1.3  christos 				 "back-wt does not support \"mode\" option. use umask instead.\n",
    184  1.3  christos 				 c->log );
    185  1.3  christos 		return 1;
    186  1.3  christos 
    187  1.3  christos 	case WT_IDLCACHE:
    188  1.3  christos 		if ( c->value_int ) {
    189  1.3  christos 			wi->wi_flags |= WT_USE_IDLCACHE;
    190  1.3  christos 		} else {
    191  1.3  christos 			wi->wi_flags &= ~WT_USE_IDLCACHE;
    192  1.3  christos 		}
    193  1.3  christos 		break;
    194  1.1  christos 	}
    195  1.1  christos 	return LDAP_SUCCESS;
    196  1.1  christos }
    197  1.1  christos 
    198  1.1  christos int wt_back_init_cf( BackendInfo *bi )
    199  1.1  christos {
    200  1.1  christos 	int rc;
    201  1.1  christos 	bi->bi_cf_ocs = wtocs;
    202  1.1  christos 
    203  1.1  christos 	rc = config_register_schema( wtcfg, wtocs );
    204  1.1  christos 	if ( rc ) return rc;
    205  1.1  christos 	return 0;
    206  1.1  christos }
    207  1.1  christos 
    208  1.1  christos /*
    209  1.1  christos  * Local variables:
    210  1.1  christos  * indent-tabs-mode: t
    211  1.1  christos  * tab-width: 4
    212  1.1  christos  * c-basic-offset: 4
    213  1.1  christos  * End:
    214  1.1  christos  */
    215