| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797 |
- /** BEGIN COPYRIGHT BLOCK
- * This Program is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation; version 2 of the License.
- *
- * This Program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA 02111-1307 USA.
- *
- * In addition, as a special exception, Red Hat, Inc. gives You the additional
- * right to link the code of this Program with code not covered under the GNU
- * General Public License ("Non-GPL Code") and to distribute linked combinations
- * including the two, subject to the limitations in this paragraph. Non-GPL Code
- * permitted under this exception must only link to the code of this Program
- * through those well defined interfaces identified in the file named EXCEPTION
- * found in the source code files (the "Approved Interfaces"). The files of
- * Non-GPL Code may instantiate templates or use macros or inline functions from
- * the Approved Interfaces without causing the resulting work to be covered by
- * the GNU General Public License. Only Red Hat, Inc. may make changes or
- * additions to the list of Approved Interfaces. You must obey the GNU General
- * Public License in all respects for all of the Program code and other code used
- * in conjunction with the Program except the Non-GPL Code covered by this
- * exception. If you modify this file, you may extend this exception to your
- * version of the file, but you are not obligated to do so. If you do not wish to
- * provide this exception without modification, you must delete this exception
- * statement from your version and license this file solely under the GPL without
- * exception.
- *
- *
- * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
- * Copyright (C) 2005 Red Hat, Inc.
- * All rights reserved.
- * END COPYRIGHT BLOCK **/
- #ifdef HAVE_CONFIG_H
- # include <config.h>
- #endif
- /* ldbm_config.c - Handles configuration information that is global to all ldbm instances. */
- #include "back-ldbm.h"
- #include "dblayer.h"
- /* Forward declarations */
- static int parse_ldbm_config_entry(struct ldbminfo *li, Slapi_Entry *e, config_info *config_array);
- /* Forward callback declarations */
- int ldbm_config_search_entry_callback(Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry* entryAfter, int *returncode, char *returntext, void *arg);
- int ldbm_config_modify_entry_callback(Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry* entryAfter, int *returncode, char *returntext, void *arg);
- static char *ldbm_skeleton_entries[] =
- {
- "dn:cn=config, cn=%s, cn=plugins, cn=config\n"
- "objectclass:top\n"
- "objectclass:extensibleObject\n"
- "cn:config\n",
- "dn:cn=monitor, cn=%s, cn=plugins, cn=config\n"
- "objectclass:top\n"
- "objectclass:extensibleObject\n"
- "cn:monitor\n",
- "dn:cn=database, cn=monitor, cn=%s, cn=plugins, cn=config\n"
- "objectclass:top\n"
- "objectclass:extensibleObject\n"
- "cn:database\n",
- ""
- };
- /* Used to add an array of entries, like the one above and
- * ldbm_instance_skeleton_entries in ldbm_instance_config.c, to the dse.
- * Returns 0 on success.
- */
- int ldbm_config_add_dse_entries(struct ldbminfo *li, char **entries, char *string1, char *string2, char *string3, int flags)
- {
- int x;
- Slapi_Entry *e;
- Slapi_PBlock *util_pb = NULL;
- int rc;
- int result;
- char entry_string[512];
- int dont_write_file = 0;
- char ebuf[BUFSIZ];
- if (flags & LDBM_INSTANCE_CONFIG_DONT_WRITE) {
- dont_write_file = 1;
- }
- for(x = 0; strlen(entries[x]) > 0; x++) {
- util_pb = slapi_pblock_new();
- PR_snprintf(entry_string, 512, entries[x], string1, string2, string3);
- e = slapi_str2entry(entry_string, 0);
- PR_snprintf(ebuf, sizeof(ebuf), slapi_entry_get_dn_const(e)); /* for logging */
- slapi_add_entry_internal_set_pb(util_pb, e, NULL, li->li_identity, 0);
- slapi_pblock_set(util_pb, SLAPI_DSE_DONT_WRITE_WHEN_ADDING,
- &dont_write_file);
- rc = slapi_add_internal_pb(util_pb);
- slapi_pblock_get(util_pb, SLAPI_PLUGIN_INTOP_RESULT, &result);
- if (!rc && (result == LDAP_SUCCESS)) {
- LDAPDebug(LDAP_DEBUG_CONFIG, "Added database config entry [%s]\n",
- ebuf, 0, 0);
- } else if (result == LDAP_ALREADY_EXISTS) {
- LDAPDebug(LDAP_DEBUG_TRACE, "Database config entry [%s] already exists - skipping\n",
- ebuf, 0, 0);
- } else {
- LDAPDebug(LDAP_DEBUG_ANY, "Unable to add config entry [%s] to the DSE: %d %d\n",
- ebuf, result, rc);
- }
- slapi_pblock_destroy(util_pb);
- }
- return 0;
- }
- /* used to add a single entry, special case of above */
- int ldbm_config_add_dse_entry(struct ldbminfo *li, char *entry, int flags)
- {
- char *entries[] = { "%s", "" };
- return ldbm_config_add_dse_entries(li, entries, entry, NULL, NULL, flags);
- }
- /* Finds an entry in a config_info array with the given name. Returns
- * the entry on success and NULL when not found.
- */
- config_info *get_config_info(config_info *config_array, char *attr_name)
- {
- int x;
- for(x = 0; config_array[x].config_name != NULL; x++) {
- if (!strcasecmp(config_array[x].config_name, attr_name)) {
- return &(config_array[x]);
- }
- }
- return NULL;
- }
- /*------------------------------------------------------------------------
- * Get and set functions for ldbm and dblayer variables
- *----------------------------------------------------------------------*/
- static void *ldbm_config_lookthroughlimit_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- return (void *) ((uintptr_t)(li->li_lookthroughlimit));
- }
- static int ldbm_config_lookthroughlimit_set(void *arg, void *value, char *errorbuf, int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- int retval = LDAP_SUCCESS;
- int val = (int) ((uintptr_t)value);
- /* Do whatever we can to make sure the data is ok. */
- if (apply) {
- li->li_lookthroughlimit = val;
- }
- return retval;
- }
- static void *ldbm_config_mode_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- return (void *) ((uintptr_t)(li->li_mode));
- }
- static int ldbm_config_mode_set(void *arg, void *value, char *errorbuf, int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- int retval = LDAP_SUCCESS;
- int val = (int) ((uintptr_t)value);
- /* Do whatever we can to make sure the data is ok. */
- if (apply) {
- li->li_mode = val;
- }
- return retval;
- }
- static void *ldbm_config_allidsthreshold_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- return (void *) ((uintptr_t)(li->li_allidsthreshold));
- }
- static int ldbm_config_allidsthreshold_set(void *arg, void *value, char *errorbuf, int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- int retval = LDAP_SUCCESS;
- int val = (int) ((uintptr_t)value);
- /* Do whatever we can to make sure the data is ok. */
- /* Catch attempts to configure a stupidly low allidsthreshold */
- if (val < 100) {
- val = 100;
- }
- if (apply) {
- li->li_allidsthreshold = val;
- }
- return retval;
- }
- static void *ldbm_config_directory_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- /* Remember get functions of type string need to return
- * alloced memory. */
- return (void *) slapi_ch_strdup(li->li_new_directory);
- }
- static int ldbm_config_directory_set(void *arg, void *value, char *errorbuf, int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- int retval = LDAP_SUCCESS;
- char *val = (char *) value;
- char tmpbuf[BUFSIZ];
- errorbuf[0] = '\0';
- if (!apply) {
- /* we should really do some error checking here. */
- return retval;
- }
- if (CONFIG_PHASE_RUNNING == phase) {
- slapi_ch_free((void **) &(li->li_new_directory));
- li->li_new_directory = rel2abspath(val); /* normalize the path;
- strdup'ed in rel2abspath */
- LDAPDebug(LDAP_DEBUG_ANY, "New db directory location will not take affect until the server is restarted\n", 0, 0, 0);
- } else {
- slapi_ch_free((void **) &(li->li_new_directory));
- slapi_ch_free((void **) &(li->li_directory));
- if (NULL == val || '\0' == *val) {
- LDAPDebug(LDAP_DEBUG_ANY,
- "ERROR: db directory is not set; check %s in the db config: %s\n",
- CONFIG_DIRECTORY, CONFIG_LDBM_DN, 0);
- retval = LDAP_PARAM_ERROR;
- } else {
- if (0 == strcmp(val, "get default")) {
- /* We use this funky "get default" string for the caller to
- * tell us that it has no idea what the db directory should
- * be. This code figures it out be reading "cn=config,cn=ldbm
- * database,cn=plugins,cn=config" entry. */
- Slapi_PBlock *search_pb;
- Slapi_Entry **entries = NULL;
- Slapi_Attr *attr = NULL;
- Slapi_Value *v = NULL;
- const char *s = NULL;
- int res;
-
- search_pb = slapi_pblock_new();
- slapi_search_internal_set_pb(search_pb, CONFIG_LDBM_DN,
- LDAP_SCOPE_BASE, "objectclass=*", NULL, 0, NULL, NULL,
- li->li_identity, 0);
- slapi_search_internal_pb(search_pb);
- slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_RESULT, &res);
-
- if (res != LDAP_SUCCESS) {
- LDAPDebug(LDAP_DEBUG_ANY,
- "ERROR: ldbm plugin unable to read %s\n",
- CONFIG_LDBM_DN, 0, 0);
- retval = res;
- goto done;
- }
-
- slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries);
- if (NULL == entries) {
- LDAPDebug(LDAP_DEBUG_ANY,
- "ERROR: ldbm plugin unable to read %s\n",
- CONFIG_LDBM_DN, 0, 0);
- retval = LDAP_OPERATIONS_ERROR;
- goto done;
- }
-
- res = slapi_entry_attr_find(entries[0], "nsslapd-directory", &attr);
- if (res != 0 || attr == NULL) {
- LDAPDebug(LDAP_DEBUG_ANY,
- "ERROR: ldbm plugin unable to read attribute nsslapd-directory from %s\n",
- CONFIG_LDBM_DN, 0, 0);
- retval = LDAP_OPERATIONS_ERROR;
- goto done;
- }
-
- if ( slapi_attr_first_value(attr,&v) != 0
- || ( NULL == v )
- || ( NULL == ( s = slapi_value_get_string( v )))) {
- LDAPDebug(LDAP_DEBUG_ANY,
- "ERROR: ldbm plugin unable to read attribute nsslapd-directory from %s\n",
- CONFIG_LDBM_DN, 0, 0);
- retval = LDAP_OPERATIONS_ERROR;
- goto done;
- }
- slapi_pblock_destroy(search_pb);
- if (NULL == s || '\0' == s || 0 == PL_strcmp(s, "(null)")) {
- LDAPDebug(LDAP_DEBUG_ANY,
- "ERROR: db directory is not set; check %s in the db config: %s\n",
- CONFIG_DIRECTORY, CONFIG_LDBM_DN, 0);
- retval = LDAP_PARAM_ERROR;
- goto done;
- }
- PR_snprintf(tmpbuf, BUFSIZ, "%s", s);
- val = tmpbuf;
- }
- li->li_new_directory = rel2abspath(val); /* normalize the path;
- strdup'ed in
- rel2abspath */
- li->li_directory = rel2abspath(val); /* ditto */
- }
- }
- done:
- return retval;
- }
- static void *ldbm_config_dbcachesize_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
-
- return (void *) (li->li_new_dbcachesize);
- }
- static int ldbm_config_dbcachesize_set(void *arg, void *value, char *errorbuf, int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- int retval = LDAP_SUCCESS;
- size_t val = (size_t) value;
- if (apply) {
- /* Stop the user configuring a stupidly small cache */
- /* min: 8KB (page size) * def thrd cnts (threadnumber==20). */
- #define DBDEFMINSIZ 500000
- if (val < DBDEFMINSIZ) {
- LDAPDebug( LDAP_DEBUG_ANY,"WARNING: cache too small, increasing to %dK bytes\n", DBDEFMINSIZ/1000, 0, 0);
- val = DBDEFMINSIZ;
- }
-
- if (CONFIG_PHASE_RUNNING == phase) {
- li->li_new_dbcachesize = val;
- LDAPDebug(LDAP_DEBUG_ANY, "New db cache size will not take affect until the server is restarted\n", 0, 0, 0);
- } else {
- li->li_new_dbcachesize = val;
- li->li_dbcachesize = val;
- }
-
- }
-
- return retval;
- }
- static void *ldbm_config_maxpassbeforemerge_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- return (void *) ((uintptr_t)(li->li_maxpassbeforemerge));
- }
- static int ldbm_config_maxpassbeforemerge_set(void *arg, void *value, char *errorbuf, int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- int retval = LDAP_SUCCESS;
- int val = (int) ((uintptr_t)value);
-
- if (apply) {
- if (val < 0) {
- LDAPDebug( LDAP_DEBUG_ANY,"WARNING: maxpassbeforemerge will not take negative value\n", 0, 0, 0);
- val = 100;
- }
-
- li->li_maxpassbeforemerge = val;
- }
- return retval;
- }
- static void *ldbm_config_dbncache_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- return (void *) ((uintptr_t)(li->li_new_dbncache));
- }
- static int ldbm_config_dbncache_set(void *arg, void *value, char *errorbuf, int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- int retval = LDAP_SUCCESS;
- int val = (int) ((uintptr_t)value);
-
- if (apply) {
- if (val < 0) {
- LDAPDebug( LDAP_DEBUG_ANY,"WARNING: ncache will not take negative value\n", 0, 0, 0);
- val = 0;
- }
-
- if (CONFIG_PHASE_RUNNING == phase) {
- li->li_new_dbncache = val;
- LDAPDebug(LDAP_DEBUG_ANY, "New db ncache will not take affect until the server is restarted\n", 0, 0, 0);
- } else {
- li->li_new_dbncache = val;
- li->li_dbncache = val;
- }
-
- }
-
- return retval;
- }
- static void *ldbm_config_db_logdirectory_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- /* Remember get functions of type string need to return
- * alloced memory. */
- /* if dblayer_log_directory is set to a string different from ""
- * then it has been set, return this variable
- * otherwise it is set to default, use the instance home directory
- */
- if (strlen(li->li_dblayer_private->dblayer_log_directory) > 0)
- return (void *) slapi_ch_strdup(li->li_dblayer_private->dblayer_log_directory);
- else
- return (void *) slapi_ch_strdup(li->li_new_directory);
- }
- static int ldbm_config_db_logdirectory_set(void *arg, void *value, char *errorbuf, int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- int retval = LDAP_SUCCESS;
- char *val = (char *) value;
-
- if (apply) {
- slapi_ch_free((void **) &(li->li_dblayer_private->dblayer_log_directory));
- li->li_dblayer_private->dblayer_log_directory = slapi_ch_strdup(val);
- }
-
- return retval;
- }
- static void *ldbm_config_db_durable_transactions_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
-
- return (void *) ((uintptr_t)li->li_dblayer_private->dblayer_durable_transactions);
- }
- static int ldbm_config_db_durable_transactions_set(void *arg, void *value, char *errorbuf, int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- int retval = LDAP_SUCCESS;
- int val = (int) ((uintptr_t)value);
-
- if (apply) {
- li->li_dblayer_private->dblayer_durable_transactions = val;
- }
-
- return retval;
- }
- static void *ldbm_config_db_lockdown_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
-
- return (void *) ((uintptr_t)li->li_dblayer_private->dblayer_lockdown);
- }
- static int ldbm_config_db_lockdown_set(
- void *arg,
- void *value,
- char *errorbuf,
- int phase,
- int apply
- )
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- int retval = LDAP_SUCCESS;
- int val = (int) ((uintptr_t)value);
- if (apply) {
- li->li_dblayer_private->dblayer_lockdown = val;
- }
- return retval;
- }
- static void *ldbm_config_db_circular_logging_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
-
- return (void *) ((uintptr_t)li->li_dblayer_private->dblayer_circular_logging);
- }
- static int ldbm_config_db_circular_logging_set(void *arg, void *value, char *errorbuf, int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- int retval = LDAP_SUCCESS;
- int val = (int) ((uintptr_t)value);
-
- if (apply) {
- li->li_dblayer_private->dblayer_circular_logging = val;
- }
-
- return retval;
- }
- static void *ldbm_config_db_transaction_logging_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
-
- return (void *) ((uintptr_t)li->li_dblayer_private->dblayer_enable_transactions);
- }
- static int ldbm_config_db_transaction_logging_set(void *arg, void *value, char *errorbuf, int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- int retval = LDAP_SUCCESS;
- int val = (int) ((uintptr_t)value);
-
- if (apply) {
- li->li_dblayer_private->dblayer_enable_transactions = val;
- }
-
- return retval;
- }
- static void *ldbm_config_db_logbuf_size_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
-
- return (void *) li->li_dblayer_private->dblayer_logbuf_size;
- }
- static int ldbm_config_db_logbuf_size_set(void *arg, void *value, char *errorbuf, int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- int retval = LDAP_SUCCESS;
- size_t val = (size_t) value;
-
- if (apply) {
- li->li_dblayer_private->dblayer_logbuf_size = val;
- }
-
- return retval;
- }
- static void *ldbm_config_db_checkpoint_interval_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
-
- return (void *) ((uintptr_t)li->li_dblayer_private->dblayer_checkpoint_interval);
- }
- static int ldbm_config_db_checkpoint_interval_set(void *arg, void *value, char *errorbuf, int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- int retval = LDAP_SUCCESS;
- int val = (int) ((uintptr_t)value);
-
- if (apply) {
- li->li_dblayer_private->dblayer_checkpoint_interval = val;
- }
-
- return retval;
- }
- static void *ldbm_config_db_page_size_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
-
- return (void *) li->li_dblayer_private->dblayer_page_size;
- }
- static int ldbm_config_db_page_size_set(void *arg, void *value, char *errorbuf, int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- int retval = LDAP_SUCCESS;
- size_t val = (size_t) value;
-
- if (apply) {
- li->li_dblayer_private->dblayer_page_size = val;
- }
-
- return retval;
- }
- static void *ldbm_config_db_index_page_size_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
-
- return (void *) li->li_dblayer_private->dblayer_index_page_size;
- }
- static int ldbm_config_db_index_page_size_set(void *arg, void *value, char *errorbuf, int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- int retval = LDAP_SUCCESS;
- size_t val = (size_t) value;
-
- if (apply) {
- li->li_dblayer_private->dblayer_index_page_size = val;
- }
-
- return retval;
- }
- static void *ldbm_config_db_idl_divisor_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
-
- return (void *) ((uintptr_t)li->li_dblayer_private->dblayer_idl_divisor);
- }
- static int ldbm_config_db_idl_divisor_set(void *arg, void *value, char *errorbuf, int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- int retval = LDAP_SUCCESS;
- int val = (int) ((uintptr_t)value);
-
- if (apply) {
- li->li_dblayer_private->dblayer_idl_divisor = val;
- }
-
- return retval;
- }
- static void *ldbm_config_db_logfile_size_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
-
- return (void *) li->li_dblayer_private->dblayer_logfile_size;
- }
- static int ldbm_config_db_logfile_size_set(void *arg, void *value, char *errorbuf, int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- int retval = LDAP_SUCCESS;
- size_t val = (size_t) value;
-
- if (apply) {
- li->li_dblayer_private->dblayer_logfile_size = val;
- }
-
- return retval;
- }
- static void *ldbm_config_db_spin_count_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
-
- return (void *) ((uintptr_t)li->li_dblayer_private->dblayer_spin_count);
- }
- static int ldbm_config_db_spin_count_set(void *arg, void *value, char *errorbuf, int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- int retval = LDAP_SUCCESS;
- int val = (int) ((uintptr_t)value);
-
- if (apply) {
- li->li_dblayer_private->dblayer_spin_count = val;
- }
-
- return retval;
- }
- static void *ldbm_config_db_trickle_percentage_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
-
- return (void *) ((uintptr_t)li->li_dblayer_private->dblayer_trickle_percentage);
- }
- static int ldbm_config_db_trickle_percentage_set(void *arg, void *value, char *errorbuf, int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- int retval = LDAP_SUCCESS;
- int val = (int) ((uintptr_t)value);
-
- if (val < 0 || val > 100) {
- PR_snprintf(errorbuf, SLAPI_DSE_RETURNTEXT_SIZE,
- "Error: Invalid value for %s (%d). Must be between 0 and 100\n", CONFIG_DB_TRICKLE_PERCENTAGE, val);
- LDAPDebug(LDAP_DEBUG_ANY, "%s", errorbuf, 0, 0);
- return LDAP_UNWILLING_TO_PERFORM;
- }
-
- if (apply) {
- li->li_dblayer_private->dblayer_trickle_percentage = val;
- }
-
- return retval;
- }
- static void *ldbm_config_db_verbose_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
-
- return (void *) ((uintptr_t)li->li_dblayer_private->dblayer_verbose);
- }
- static int ldbm_config_db_verbose_set(void *arg, void *value, char *errorbuf, int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- int retval = LDAP_SUCCESS;
- int val = (int) ((uintptr_t)value);
-
- if (apply) {
- li->li_dblayer_private->dblayer_verbose = val;
- }
-
- return retval;
- }
- static void *ldbm_config_db_debug_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
-
- return (void *) ((uintptr_t)li->li_dblayer_private->dblayer_debug);
- }
- static int ldbm_config_db_debug_set(void *arg, void *value, char *errorbuf, int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- int retval = LDAP_SUCCESS;
- int val = (int) ((uintptr_t)value);
-
- if (apply) {
- li->li_dblayer_private->dblayer_debug = val;
- }
-
- return retval;
- }
- static void *ldbm_config_db_named_regions_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
-
- return (void *) ((uintptr_t)li->li_dblayer_private->dblayer_named_regions);
- }
- static int ldbm_config_db_named_regions_set(void *arg, void *value, char *errorbuf, int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- int retval = LDAP_SUCCESS;
- int val = (int) ((uintptr_t)value);
-
- if (apply) {
- li->li_dblayer_private->dblayer_named_regions = val;
- }
-
- return retval;
- }
- static void *ldbm_config_db_private_mem_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
-
- return (void *) ((uintptr_t)li->li_dblayer_private->dblayer_private_mem);
- }
- static int ldbm_config_db_private_mem_set(void *arg, void *value, char *errorbuf, int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- int retval = LDAP_SUCCESS;
- int val = (int) ((uintptr_t)value);
-
- if (apply) {
- li->li_dblayer_private->dblayer_private_mem = val;
- }
-
- return retval;
- }
- static void *ldbm_config_db_private_import_mem_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
-
- return (void *) ((uintptr_t)li->li_dblayer_private->dblayer_private_import_mem);
- }
- static int ldbm_config_db_private_import_mem_set(void *arg, void *value, char *errorbuf, int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- int retval = LDAP_SUCCESS;
- int val = (int) ((uintptr_t)value);
-
- if (apply) {
- li->li_dblayer_private->dblayer_private_import_mem = val;
- }
-
- return retval;
- }
- static void *ldbm_config_db_shm_key_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- return (void *) li->li_dblayer_private->dblayer_shm_key;
- }
- static int ldbm_config_db_shm_key_set(
- void *arg,
- void *value,
- char *errorbuf,
- int phase,
- int apply
- )
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- int retval = LDAP_SUCCESS;
- int val = (int) ((uintptr_t)value);
- if (apply) {
- li->li_dblayer_private->dblayer_shm_key = val;
- }
- return retval;
- }
- static void *ldbm_config_db_lock_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
-
- return (void *) ((uintptr_t)li->li_dblayer_private->dblayer_lock_config);
- }
- static int ldbm_config_db_lock_set(void *arg, void *value, char *errorbuf, int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- int retval = LDAP_SUCCESS;
- size_t val = (size_t) value;
- if (apply) {
- if (CONFIG_PHASE_RUNNING == phase) {
- li->li_dblayer_private->dblayer_lock_config = val;
- LDAPDebug(LDAP_DEBUG_ANY, "New db cache size will not take affect until the server is restarted\n", 0, 0, 0);
- } else {
- li->li_dblayer_private->dblayer_lock_config = val;
- }
-
- }
- return retval;
- }
- static void *ldbm_config_db_cache_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
-
- return (void *) ((uintptr_t)li->li_dblayer_private->dblayer_cache_config);
- }
- static int ldbm_config_db_cache_set(void *arg, void *value, char *errorbuf, int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- int retval = LDAP_SUCCESS;
- int val = (int) ((uintptr_t)value);
-
- if (apply) {
- li->li_dblayer_private->dblayer_cache_config = val;
- }
-
- return retval;
- }
- static void *ldbm_config_db_debug_checkpointing_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
-
- return (void *) ((uintptr_t)li->li_dblayer_private->db_debug_checkpointing);
- }
- static int ldbm_config_db_debug_checkpointing_set(void *arg, void *value, char *errorbuf, int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- int retval = LDAP_SUCCESS;
- int val = (int) ((uintptr_t)value);
-
- if (apply) {
- li->li_dblayer_private->db_debug_checkpointing = val;
- }
-
- return retval;
- }
- static void *ldbm_config_db_home_directory_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
-
- /* Remember get functions of type string need to return
- * alloced memory. */
- return (void *) slapi_ch_strdup(li->li_dblayer_private->dblayer_dbhome_directory);
- }
- static int ldbm_config_db_home_directory_set(void *arg, void *value, char *errorbuf, int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- int retval = LDAP_SUCCESS;
- char *val = (char *) value;
-
- if (apply) {
- slapi_ch_free((void **) &(li->li_dblayer_private->dblayer_dbhome_directory));
- li->li_dblayer_private->dblayer_dbhome_directory = slapi_ch_strdup(val);
- }
-
- return retval;
- }
- static void *ldbm_config_import_cache_autosize_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *)arg;
- return (void *)((uintptr_t)(li->li_import_cache_autosize));
- }
- static int ldbm_config_import_cache_autosize_set(void *arg, void *value, char *errorbuf,
- int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *)arg;
- if (apply)
- li->li_import_cache_autosize = (int)((uintptr_t)value);
- return LDAP_SUCCESS;
- }
- static void *ldbm_config_cache_autosize_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *)arg;
- return (void *)((uintptr_t)(li->li_cache_autosize));
- }
- static int ldbm_config_cache_autosize_set(void *arg, void *value, char *errorbuf,
- int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *)arg;
- if (apply)
- li->li_cache_autosize = (int)((uintptr_t)value);
- return LDAP_SUCCESS;
- }
- static void *ldbm_config_cache_autosize_split_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *)arg;
- return (void *)((uintptr_t)(li->li_cache_autosize_split));
- }
- static int ldbm_config_cache_autosize_split_set(void *arg, void *value, char *errorbuf,
- int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *)arg;
- if (apply)
- li->li_cache_autosize_split = (int)((uintptr_t)value);
- return LDAP_SUCCESS;
- }
- static void *ldbm_config_import_cachesize_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *)arg;
- return (void *)(li->li_import_cachesize);
- }
- static int ldbm_config_import_cachesize_set(void *arg, void *value, char *errorbuf,
- int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *)arg;
- if (apply)
- li->li_import_cachesize = (size_t)value;
- return LDAP_SUCCESS;
- }
- static void *ldbm_config_index_buffer_size_get(void *arg)
- {
- return (void *)import_get_index_buffer_size();
- }
- static int ldbm_config_index_buffer_size_set(void *arg, void *value, char *errorbuf,
- int phase, int apply)
- {
- if (apply)
- import_configure_index_buffer_size((size_t)value);
- return LDAP_SUCCESS;
- }
- static void *ldbm_config_idl_get_idl_new(void *arg)
- {
- if (idl_get_idl_new())
- return slapi_ch_strdup("new");
- else
- return slapi_ch_strdup("old");
- }
- static int ldbm_config_idl_set_tune(void *arg, void *value, char *errorbuf,
- int phase, int apply)
- {
- if (!strcasecmp("new", value))
- idl_set_tune(4096);
- else
- idl_set_tune(0);
- return LDAP_SUCCESS;
- }
- static void *ldbm_config_serial_lock_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- return (void *) ((uintptr_t)li->li_fat_lock);
- }
- static int ldbm_config_serial_lock_set(void *arg, void *value, char *errorbuf,
- int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
-
- if (apply) {
- li->li_fat_lock = (int) ((uintptr_t)value);
- }
-
- return LDAP_SUCCESS;
- }
- static void *ldbm_config_legacy_errcode_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- return (void *) ((uintptr_t)li->li_legacy_errcode);
- }
- static int ldbm_config_legacy_errcode_set(void *arg, void *value, char *errorbuf,
- int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
-
- if (apply) {
- li->li_legacy_errcode = (int) ((uintptr_t)value);
- }
-
- return LDAP_SUCCESS;
- }
- static int
- ldbm_config_set_bypass_filter_test(void *arg, void *value, char *errorbuf,
- int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *)arg;
- if (apply) {
- char *myvalue = (char *)value;
- if (0 == strcasecmp(myvalue, "on")) {
- li->li_filter_bypass = 1;
- li->li_filter_bypass_check = 0;
- } else if (0 == strcasecmp(myvalue, "verify")) {
- li->li_filter_bypass = 1;
- li->li_filter_bypass_check = 1;
- } else {
- li->li_filter_bypass = 0;
- li->li_filter_bypass_check = 0;
- }
- }
- return LDAP_SUCCESS;
- }
- static void *ldbm_config_get_bypass_filter_test(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *)arg;
- char *retstr = NULL;
- if (li->li_filter_bypass) {
- if (li->li_filter_bypass_check) {
- /* meaningful only if is bypass filter test called */
- retstr = slapi_ch_strdup("verify");
- } else {
- retstr = slapi_ch_strdup("on");
- }
- } else {
- retstr = slapi_ch_strdup("off");
- }
- return (void *)retstr;
- }
- static int ldbm_config_set_use_vlv_index(void *arg, void *value, char *errorbuf, int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- int val = (int) ((uintptr_t)value);
-
- if (apply) {
- if (val) {
- li->li_use_vlv = 1;
- } else {
- li->li_use_vlv = 0;
- }
- }
- return LDAP_SUCCESS;
- }
- static void *ldbm_config_get_use_vlv_index(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- return (void *) ((uintptr_t)li->li_use_vlv);
- }
- static int
- ldbm_config_exclude_from_export_set( void *arg, void *value, char *errorbuf,
- int phase, int apply)
- {
- struct ldbminfo *li = (struct ldbminfo *)arg;
- if ( apply ) {
- if ( NULL != li->li_attrs_to_exclude_from_export ) {
- charray_free( li->li_attrs_to_exclude_from_export );
- li->li_attrs_to_exclude_from_export = NULL;
- }
-
- if ( NULL != value ) {
- char *dupvalue = slapi_ch_strdup( value );
- li->li_attrs_to_exclude_from_export = slapi_str2charray( dupvalue, " " );
- slapi_ch_free((void**)&dupvalue);
- }
- }
-
- return LDAP_SUCCESS;
- }
- static void *
- ldbm_config_exclude_from_export_get( void *arg )
- {
- struct ldbminfo *li = (struct ldbminfo *)arg;
- char *p, *retstr = NULL;
- size_t len = 0;
-
- if ( NULL != li->li_attrs_to_exclude_from_export &&
- NULL != li->li_attrs_to_exclude_from_export[0] ) {
- int i;
-
- for ( i = 0; li->li_attrs_to_exclude_from_export[i] != NULL; ++i ) {
- len += strlen( li->li_attrs_to_exclude_from_export[i] ) + 1;
- }
- p = retstr = slapi_ch_malloc( len );
- for ( i = 0; li->li_attrs_to_exclude_from_export[i] != NULL; ++i ) {
- if ( i > 0 ) {
- *p++ = ' ';
- }
- strcpy( p, li->li_attrs_to_exclude_from_export[i] );
- p += strlen( p );
- }
- *p = '\0';
- } else {
- retstr = slapi_ch_strdup( "" );
- }
-
- return (void *)retstr;
- }
- static void *ldbm_config_db_tx_max_get(void *arg)
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- return (void *) ((uintptr_t)li->li_dblayer_private->dblayer_tx_max);
- }
- static int ldbm_config_db_tx_max_set(
- void *arg,
- void *value,
- char *errorbuf,
- int phase,
- int apply
- )
- {
- struct ldbminfo *li = (struct ldbminfo *) arg;
- int retval = LDAP_SUCCESS;
- int val = (int) ((uintptr_t)value);
- if (apply) {
- li->li_dblayer_private->dblayer_tx_max = val;
- }
- return retval;
- }
- /*------------------------------------------------------------------------
- * Configuration array for ldbm and dblayer variables
- *----------------------------------------------------------------------*/
- static config_info ldbm_config[] = {
- {CONFIG_LOOKTHROUGHLIMIT, CONFIG_TYPE_INT, "5000", &ldbm_config_lookthroughlimit_get, &ldbm_config_lookthroughlimit_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
- {CONFIG_MODE, CONFIG_TYPE_INT_OCTAL, "0600", &ldbm_config_mode_get, &ldbm_config_mode_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
- {CONFIG_IDLISTSCANLIMIT, CONFIG_TYPE_INT, "4000", &ldbm_config_allidsthreshold_get, &ldbm_config_allidsthreshold_set, CONFIG_FLAG_ALWAYS_SHOW},
- {CONFIG_DIRECTORY, CONFIG_TYPE_STRING, "", &ldbm_config_directory_get, &ldbm_config_directory_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE|CONFIG_FLAG_SKIP_DEFAULT_SETTING},
- {CONFIG_DBCACHESIZE, CONFIG_TYPE_SIZE_T, "10000000", &ldbm_config_dbcachesize_get, &ldbm_config_dbcachesize_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
- {CONFIG_DBNCACHE, CONFIG_TYPE_INT, "0", &ldbm_config_dbncache_get, &ldbm_config_dbncache_set, CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
- {CONFIG_MAXPASSBEFOREMERGE, CONFIG_TYPE_INT, "100", &ldbm_config_maxpassbeforemerge_get, &ldbm_config_maxpassbeforemerge_set, 0},
-
- /* dblayer config attributes */
- {CONFIG_DB_LOGDIRECTORY, CONFIG_TYPE_STRING, "", &ldbm_config_db_logdirectory_get, &ldbm_config_db_logdirectory_set, CONFIG_FLAG_ALWAYS_SHOW},
- {CONFIG_DB_DURABLE_TRANSACTIONS, CONFIG_TYPE_ONOFF, "on", &ldbm_config_db_durable_transactions_get, &ldbm_config_db_durable_transactions_set, CONFIG_FLAG_ALWAYS_SHOW},
- {CONFIG_DB_CIRCULAR_LOGGING, CONFIG_TYPE_ONOFF, "on", &ldbm_config_db_circular_logging_get, &ldbm_config_db_circular_logging_set, 0},
- {CONFIG_DB_TRANSACTION_LOGGING, CONFIG_TYPE_ONOFF, "on", &ldbm_config_db_transaction_logging_get, &ldbm_config_db_transaction_logging_set, 0},
- {CONFIG_DB_CHECKPOINT_INTERVAL, CONFIG_TYPE_INT, "60", &ldbm_config_db_checkpoint_interval_get, &ldbm_config_db_checkpoint_interval_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
- {CONFIG_DB_TRANSACTION_BATCH, CONFIG_TYPE_INT, "0", &dblayer_get_batch_transactions, &dblayer_set_batch_transactions, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
- {CONFIG_DB_LOGBUF_SIZE, CONFIG_TYPE_SIZE_T, "0", &ldbm_config_db_logbuf_size_get, &ldbm_config_db_logbuf_size_set, CONFIG_FLAG_ALWAYS_SHOW},
- {CONFIG_DB_PAGE_SIZE, CONFIG_TYPE_SIZE_T, "0", &ldbm_config_db_page_size_get, &ldbm_config_db_page_size_set, 0},
- {CONFIG_DB_INDEX_PAGE_SIZE, CONFIG_TYPE_SIZE_T, "0", &ldbm_config_db_index_page_size_get, &ldbm_config_db_index_page_size_set, 0},
- {CONFIG_DB_IDL_DIVISOR, CONFIG_TYPE_INT, "0", &ldbm_config_db_idl_divisor_get, &ldbm_config_db_idl_divisor_set, 0},
- {CONFIG_DB_LOGFILE_SIZE, CONFIG_TYPE_SIZE_T, "0", &ldbm_config_db_logfile_size_get, &ldbm_config_db_logfile_size_set, 0},
- {CONFIG_DB_TRICKLE_PERCENTAGE, CONFIG_TYPE_INT, "5", &ldbm_config_db_trickle_percentage_get, &ldbm_config_db_trickle_percentage_set, 0},
- {CONFIG_DB_SPIN_COUNT, CONFIG_TYPE_INT, "0", &ldbm_config_db_spin_count_get, &ldbm_config_db_spin_count_set, 0},
- {CONFIG_DB_VERBOSE, CONFIG_TYPE_ONOFF, "off", &ldbm_config_db_verbose_get, &ldbm_config_db_verbose_set, 0},
- {CONFIG_DB_DEBUG, CONFIG_TYPE_ONOFF, "on", &ldbm_config_db_debug_get, &ldbm_config_db_debug_set, 0},
- {CONFIG_DB_NAMED_REGIONS, CONFIG_TYPE_ONOFF, "off", &ldbm_config_db_named_regions_get, &ldbm_config_db_named_regions_set, 0},
- {CONFIG_DB_LOCK, CONFIG_TYPE_INT, "10000", &ldbm_config_db_lock_get, &ldbm_config_db_lock_set, 0},
- {CONFIG_DB_PRIVATE_MEM, CONFIG_TYPE_ONOFF, "off", &ldbm_config_db_private_mem_get, &ldbm_config_db_private_mem_set, 0},
- {CONFIG_DB_PRIVATE_IMPORT_MEM, CONFIG_TYPE_ONOFF, "on", &ldbm_config_db_private_import_mem_get, &ldbm_config_db_private_import_mem_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
- {CONFIG_DB_SHM_KEY, CONFIG_TYPE_LONG, "389389", &ldbm_config_db_shm_key_get, &ldbm_config_db_shm_key_set, 0},
- {CONFIG_DB_CACHE, CONFIG_TYPE_INT, "0", &ldbm_config_db_cache_get, &ldbm_config_db_cache_set, 0},
- {CONFIG_DB_DEBUG_CHECKPOINTING, CONFIG_TYPE_ONOFF, "off", &ldbm_config_db_debug_checkpointing_get, &ldbm_config_db_debug_checkpointing_set, 0},
- {CONFIG_DB_HOME_DIRECTORY, CONFIG_TYPE_STRING, "", &ldbm_config_db_home_directory_get, &ldbm_config_db_home_directory_set, 0},
- {CONFIG_IMPORT_CACHE_AUTOSIZE, CONFIG_TYPE_INT, "-1", &ldbm_config_import_cache_autosize_get, &ldbm_config_import_cache_autosize_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
- {CONFIG_CACHE_AUTOSIZE, CONFIG_TYPE_INT, "0", &ldbm_config_cache_autosize_get, &ldbm_config_cache_autosize_set, 0},
- {CONFIG_CACHE_AUTOSIZE_SPLIT, CONFIG_TYPE_INT, "50", &ldbm_config_cache_autosize_split_get, &ldbm_config_cache_autosize_split_set, 0},
- {CONFIG_IMPORT_CACHESIZE, CONFIG_TYPE_SIZE_T, "20000000", &ldbm_config_import_cachesize_get, &ldbm_config_import_cachesize_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
- {CONFIG_IDL_SWITCH, CONFIG_TYPE_STRING, "new", &ldbm_config_idl_get_idl_new, &ldbm_config_idl_set_tune, CONFIG_FLAG_ALWAYS_SHOW},
- {CONFIG_BYPASS_FILTER_TEST, CONFIG_TYPE_STRING, "on", &ldbm_config_get_bypass_filter_test, &ldbm_config_set_bypass_filter_test, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
- {CONFIG_USE_VLV_INDEX, CONFIG_TYPE_ONOFF, "on", &ldbm_config_get_use_vlv_index, &ldbm_config_set_use_vlv_index, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
- {CONFIG_DB_LOCKDOWN, CONFIG_TYPE_ONOFF, "off", &ldbm_config_db_lockdown_get, &ldbm_config_db_lockdown_set, 0},
- {CONFIG_INDEX_BUFFER_SIZE, CONFIG_TYPE_INT, "0", &ldbm_config_index_buffer_size_get, &ldbm_config_index_buffer_size_set, 0},
- {CONFIG_EXCLUDE_FROM_EXPORT, CONFIG_TYPE_STRING,
- CONFIG_EXCLUDE_FROM_EXPORT_DEFAULT_VALUE,
- &ldbm_config_exclude_from_export_get,
- &ldbm_config_exclude_from_export_set, CONFIG_FLAG_ALWAYS_SHOW},
- {CONFIG_DB_TX_MAX, CONFIG_TYPE_INT, "200", &ldbm_config_db_tx_max_get, &ldbm_config_db_tx_max_set, 0},
- {CONFIG_SERIAL_LOCK, CONFIG_TYPE_ONOFF, "on", &ldbm_config_serial_lock_get, &ldbm_config_serial_lock_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
- {CONFIG_USE_LEGACY_ERRORCODE, CONFIG_TYPE_ONOFF, "off", &ldbm_config_legacy_errcode_get, &ldbm_config_legacy_errcode_set, 0},
- {NULL, 0, NULL, NULL, NULL, 0}
- };
- void ldbm_config_setup_default(struct ldbminfo *li)
- {
- config_info *config;
- char err_buf[SLAPI_DSE_RETURNTEXT_SIZE];
-
- for (config = ldbm_config; config->config_name != NULL; config++) {
- ldbm_config_set((void *)li, config->config_name, ldbm_config, NULL /* use default */, err_buf, CONFIG_PHASE_INITIALIZATION, 1 /* apply */);
- }
- }
- void
- ldbm_config_read_instance_entries(struct ldbminfo *li, const char *backend_type)
- {
- Slapi_PBlock *tmp_pb;
- char basedn[BUFSIZ];
- Slapi_Entry **entries = NULL;
- /* Construct the base dn of the subtree that holds the instance entries. */
- PR_snprintf(basedn, BUFSIZ, "cn=%s, cn=plugins, cn=config", backend_type);
- /* Do a search of the subtree containing the instance entries */
- tmp_pb = slapi_pblock_new();
- slapi_search_internal_set_pb(tmp_pb, basedn, LDAP_SCOPE_SUBTREE, "(objectclass=nsBackendInstance)", NULL, 0, NULL, NULL, li->li_identity, 0);
- slapi_search_internal_pb (tmp_pb);
- slapi_pblock_get(tmp_pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries);
- if (entries!=NULL) {
- int i;
- for (i=0; entries[i]!=NULL; i++) {
- ldbm_instance_add_instance_entry_callback(NULL, entries[i], NULL, NULL, NULL, li);
- }
- }
- slapi_free_search_results_internal(tmp_pb);
- slapi_pblock_destroy(tmp_pb);
- }
- /* Reads in any config information held in the dse for the ldbm plugin.
- * Creates dse entries used to configure the ldbm plugin and dblayer
- * if they don't already exist. Registers dse callback functions to
- * maintain those dse entries. Returns 0 on success.
- */
- int ldbm_config_load_dse_info(struct ldbminfo *li)
- {
- Slapi_PBlock *search_pb;
- Slapi_Entry **entries = NULL;
- int res;
- char dn[BUFSIZ];
- /* We try to read the entry
- * cn=config, cn=ldbm database, cn=plugins, cn=config. If the entry is
- * there, then we process the config information it stores.
- */
- PR_snprintf(dn, BUFSIZ, "cn=config, cn=%s, cn=plugins, cn=config",
- li->li_plugin->plg_name);
- search_pb = slapi_pblock_new();
- slapi_search_internal_set_pb(search_pb, dn, LDAP_SCOPE_BASE,
- "objectclass=*", NULL, 0, NULL, NULL, li->li_identity, 0);
- slapi_search_internal_pb (search_pb);
- slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_RESULT, &res);
- if (LDAP_NO_SUCH_OBJECT == res) {
- /* Add skeleten dse entries for the ldbm plugin */
- ldbm_config_add_dse_entries(li, ldbm_skeleton_entries,
- li->li_plugin->plg_name, NULL, NULL, 0);
- } else if (res != LDAP_SUCCESS) {
- LDAPDebug(LDAP_DEBUG_ANY, "Error accessing the ldbm config DSE\n",
- 0, 0, 0);
- return 1;
- } else {
- /* Need to parse the configuration information for the ldbm
- * plugin that is held in the DSE. */
- slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES,
- &entries);
- if (NULL == entries || entries[0] == NULL) {
- LDAPDebug(LDAP_DEBUG_ANY, "Error accessing the ldbm config DSE\n",
- 0, 0, 0);
- return 1;
- }
- if (0 != parse_ldbm_config_entry(li, entries[0], ldbm_config)) {
- LDAPDebug(LDAP_DEBUG_ANY, "Error parsing the ldbm config DSE\n",
- 0, 0, 0);
- return 1;
- }
- }
- if (search_pb) {
- slapi_free_search_results_internal(search_pb);
- slapi_pblock_destroy(search_pb);
- }
-
- /* Find all the instance entries and create a Slapi_Backend and an
- * ldbm_instance for each */
- ldbm_config_read_instance_entries(li, li->li_plugin->plg_name);
- /* setup the dse callback functions for the ldbm backend config entry */
- PR_snprintf(dn, BUFSIZ, "cn=config, cn=%s, cn=plugins, cn=config",
- li->li_plugin->plg_name);
- slapi_config_register_callback(SLAPI_OPERATION_SEARCH, DSE_FLAG_PREOP, dn,
- LDAP_SCOPE_BASE, "(objectclass=*)", ldbm_config_search_entry_callback,
- (void *) li);
- slapi_config_register_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_PREOP, dn,
- LDAP_SCOPE_BASE, "(objectclass=*)", ldbm_config_modify_entry_callback,
- (void *) li);
- slapi_config_register_callback(DSE_OPERATION_WRITE, DSE_FLAG_PREOP, dn,
- LDAP_SCOPE_BASE, "(objectclass=*)", ldbm_config_search_entry_callback,
- (void *) li);
- /* setup the dse callback functions for the ldbm backend monitor entry */
- PR_snprintf(dn, BUFSIZ, "cn=monitor, cn=%s, cn=plugins, cn=config",
- li->li_plugin->plg_name);
- slapi_config_register_callback(SLAPI_OPERATION_SEARCH, DSE_FLAG_PREOP, dn,
- LDAP_SCOPE_BASE, "(objectclass=*)", ldbm_back_monitor_search,
- (void *)li);
- /* And the ldbm backend database monitor entry */
- PR_snprintf(dn, BUFSIZ, "cn=database, cn=monitor, cn=%s, cn=plugins, cn=config",
- li->li_plugin->plg_name);
- slapi_config_register_callback(SLAPI_OPERATION_SEARCH, DSE_FLAG_PREOP, dn,
- LDAP_SCOPE_BASE, "(objectclass=*)", ldbm_back_dbmonitor_search,
- (void *)li);
- /* setup the dse callback functions for the ldbm backend instance
- * entries */
- PR_snprintf(dn, BUFSIZ, "cn=%s, cn=plugins, cn=config", li->li_plugin->plg_name);
- slapi_config_register_callback(SLAPI_OPERATION_ADD, DSE_FLAG_PREOP, dn,
- LDAP_SCOPE_SUBTREE, "(objectclass=nsBackendInstance)",
- ldbm_instance_add_instance_entry_callback, (void *) li);
- slapi_config_register_callback(SLAPI_OPERATION_ADD, DSE_FLAG_POSTOP, dn,
- LDAP_SCOPE_SUBTREE, "(objectclass=nsBackendInstance)",
- ldbm_instance_postadd_instance_entry_callback, (void *) li);
- slapi_config_register_callback(SLAPI_OPERATION_DELETE, DSE_FLAG_PREOP, dn,
- LDAP_SCOPE_SUBTREE, "(objectclass=nsBackendInstance)",
- ldbm_instance_delete_instance_entry_callback, (void *) li);
- slapi_config_register_callback(SLAPI_OPERATION_DELETE, DSE_FLAG_POSTOP, dn,
- LDAP_SCOPE_SUBTREE, "(objectclass=nsBackendInstance)",
- ldbm_instance_post_delete_instance_entry_callback, (void *) li);
- return 0;
- }
- /* Utility function used in creating config entries. Using the
- * config_info, this function gets info and formats in the correct
- * way.
- * buf is char[BUFSIZ]
- */
- void ldbm_config_get(void *arg, config_info *config, char *buf)
- {
- char *tmp_string;
- size_t val = 0;
-
- if (config == NULL) {
- buf[0] = '\0';
- }
-
- switch(config->config_type) {
- case CONFIG_TYPE_INT:
- sprintf(buf, "%d", (int) ((uintptr_t)config->config_get_fn(arg)));
- break;
- case CONFIG_TYPE_INT_OCTAL:
- sprintf(buf, "%o", (int) ((uintptr_t)config->config_get_fn(arg)));
- break;
- case CONFIG_TYPE_LONG:
- sprintf(buf, "%ld", (long) config->config_get_fn(arg));
- break;
- case CONFIG_TYPE_SIZE_T:
- val = (size_t) config->config_get_fn(arg);
- sprintf(buf, "%lu", val);
- break;
- case CONFIG_TYPE_STRING:
- /* Remember the get function for strings returns memory
- * that must be freed. */
- tmp_string = (char *) config->config_get_fn(arg);
- PR_snprintf(buf, BUFSIZ, "%s", (char *) tmp_string);
- slapi_ch_free((void **)&tmp_string);
- break;
- case CONFIG_TYPE_ONOFF:
- if ((int) ((uintptr_t)config->config_get_fn(arg))) {
- sprintf(buf, "on");
- } else {
- sprintf(buf, "off");
- }
- break;
- }
- }
- /*
- * Returns:
- * SLAPI_DSE_CALLBACK_ERROR on failure
- * SLAPI_DSE_CALLBACK_OK on success
- */
- int ldbm_config_search_entry_callback(Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Entry *entryAfter, int *returncode, char *returntext, void *arg)
- {
- char buf[BUFSIZ];
- struct berval *vals[2];
- struct berval val;
- struct ldbminfo *li= (struct ldbminfo *) arg;
- config_info *config;
-
- vals[0] = &val;
- vals[1] = NULL;
-
- returntext[0] = '\0';
-
- PR_Lock(li->li_config_mutex);
-
- for(config = ldbm_config; config->config_name != NULL; config++) {
- /* Go through the ldbm_config table and fill in the entry. */
- if (!(config->config_flags & (CONFIG_FLAG_ALWAYS_SHOW | CONFIG_FLAG_PREVIOUSLY_SET))) {
- /* This config option shouldn't be shown */
- continue;
- }
-
- ldbm_config_get((void *) li, config, buf);
-
- val.bv_val = buf;
- val.bv_len = strlen(buf);
- slapi_entry_attr_replace(e, config->config_name, vals);
- }
-
- PR_Unlock(li->li_config_mutex);
- *returncode = LDAP_SUCCESS;
- return SLAPI_DSE_CALLBACK_OK;
- }
- int ldbm_config_ignored_attr(char *attr_name)
- {
- /* These are the names of attributes that are in the
- * config entries but are not config attributes. */
- if (!strcasecmp("objectclass", attr_name) ||
- !strcasecmp("cn", attr_name) ||
- !strcasecmp("creatorsname", attr_name) ||
- !strcasecmp("modifiersname", attr_name) ||
- !strcasecmp("createtimestamp", attr_name) ||
- !strcasecmp("numsubordinates", attr_name) ||
- !strcasecmp("modifytimestamp", attr_name)) {
- return 1;
- } else {
- return 0;
- }
- }
- /* Returns LDAP_SUCCESS on success */
- int ldbm_config_set(void *arg, char *attr_name, config_info *config_array, struct berval *bval, char *err_buf, int phase, int apply_mod)
- {
- config_info *config;
- int use_default;
- int int_val;
- long long_val;
- size_t sz_val;
- PRInt64 llval;
- int maxint = (int)(((unsigned int)~0)>>1);
- int minint = ~maxint;
- PRInt64 llmaxint;
- PRInt64 llminint;
- int err = 0;
- char *str_val;
- int retval = 0;
- LL_I2L(llmaxint, maxint);
- LL_I2L(llminint, minint);
- config = get_config_info(config_array, attr_name);
- if (NULL == config) {
- LDAPDebug(LDAP_DEBUG_CONFIG, "Unknown config attribute %s\n", attr_name, 0, 0);
- PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Unknown config attribute %s\n", attr_name);
- return LDAP_SUCCESS; /* Ignore unknown attributes */
- }
- /* Some config attrs can't be changed while the server is running. */
- if (phase == CONFIG_PHASE_RUNNING &&
- !(config->config_flags & CONFIG_FLAG_ALLOW_RUNNING_CHANGE)) {
- PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "%s can't be modified while the server is running.\n", attr_name);
- LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
- return LDAP_UNWILLING_TO_PERFORM;
- }
-
- /* If the config phase is initialization or if bval is NULL, we will use
- * the default value for the attribute. */
- if (CONFIG_PHASE_INITIALIZATION == phase || NULL == bval) {
- if (CONFIG_FLAG_SKIP_DEFAULT_SETTING & config->config_flags) {
- return LDAP_SUCCESS; /* Skipping the default config setting */
- }
- use_default = 1;
- } else {
- use_default = 0;
-
- /* Since we are setting the value for the config attribute, we
- * need to turn on the CONFIG_FLAG_PREVIOUSLY_SET flag to make
- * sure this attribute is shown. */
- config->config_flags |= CONFIG_FLAG_PREVIOUSLY_SET;
- }
-
- switch(config->config_type) {
- case CONFIG_TYPE_INT:
- if (use_default) {
- str_val = config->config_default_value;
- } else {
- str_val = bval->bv_val;
- }
- /* get the value as a 64 bit value */
- llval = db_atoi(str_val, &err);
- /* check for parsing error (e.g. not a number) */
- if (err) {
- PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is not a number\n",
- str_val, attr_name);
- LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
- return LDAP_UNWILLING_TO_PERFORM;
- /* check for overflow */
- } else if (LL_CMP(llval, >, llmaxint)) {
- PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is greater than the maximum %d\n",
- str_val, attr_name, maxint);
- LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
- return LDAP_UNWILLING_TO_PERFORM;
- /* check for underflow */
- } else if (LL_CMP(llval, <, llminint)) {
- PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is less than the minimum %d\n",
- str_val, attr_name, minint);
- LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
- return LDAP_UNWILLING_TO_PERFORM;
- }
- /* convert 64 bit value to 32 bit value */
- LL_L2I(int_val, llval);
- retval = config->config_set_fn(arg, (void *) ((uintptr_t)int_val), err_buf, phase, apply_mod);
- break;
- case CONFIG_TYPE_INT_OCTAL:
- if (use_default) {
- int_val = (int) strtol(config->config_default_value, NULL, 8);
- } else {
- int_val = (int) strtol((char *)bval->bv_val, NULL, 8);
- }
- retval = config->config_set_fn(arg, (void *) ((uintptr_t)int_val), err_buf, phase, apply_mod);
- break;
- case CONFIG_TYPE_LONG:
- if (use_default) {
- str_val = config->config_default_value;
- } else {
- str_val = bval->bv_val;
- }
- /* get the value as a 64 bit value */
- llval = db_atoi(str_val, &err);
- /* check for parsing error (e.g. not a number) */
- if (err) {
- PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is not a number\n",
- str_val, attr_name);
- LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
- return LDAP_UNWILLING_TO_PERFORM;
- /* check for overflow */
- } else if (LL_CMP(llval, >, llmaxint)) {
- PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is greater than the maximum %d\n",
- str_val, attr_name, maxint);
- LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
- return LDAP_UNWILLING_TO_PERFORM;
- /* check for underflow */
- } else if (LL_CMP(llval, <, llminint)) {
- PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is less than the minimum %d\n",
- str_val, attr_name, minint);
- LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
- return LDAP_UNWILLING_TO_PERFORM;
- }
- /* convert 64 bit value to 32 bit value */
- LL_L2I(long_val, llval);
- retval = config->config_set_fn(arg, (void *) long_val, err_buf, phase, apply_mod);
- break;
- case CONFIG_TYPE_SIZE_T:
- if (use_default) {
- str_val = config->config_default_value;
- } else {
- str_val = bval->bv_val;
- }
- /* get the value as a size_t value */
- sz_val = db_strtoul(str_val, &err);
- /* check for parsing error (e.g. not a number) */
- if (err == EINVAL) {
- PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is not a number\n",
- str_val, attr_name);
- LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
- return LDAP_UNWILLING_TO_PERFORM;
- /* check for overflow */
- } else if (err == ERANGE) {
- PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is outside the range of representable values\n",
- str_val, attr_name);
- LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
- return LDAP_UNWILLING_TO_PERFORM;
- }
- retval = config->config_set_fn(arg, (void *) sz_val, err_buf, phase, apply_mod);
- break;
- case CONFIG_TYPE_STRING:
- if (use_default) {
- retval = config->config_set_fn(arg, config->config_default_value, err_buf, phase, apply_mod);
- } else {
- retval = config->config_set_fn(arg, bval->bv_val, err_buf, phase, apply_mod);
- }
- break;
- case CONFIG_TYPE_ONOFF:
- if (use_default) {
- int_val = !strcasecmp(config->config_default_value, "on");
- } else {
- int_val = !strcasecmp((char *) bval->bv_val, "on");
- }
- retval = config->config_set_fn(arg, (void *) ((uintptr_t)int_val), err_buf, phase, apply_mod);
- break;
- }
-
- return retval;
- }
- static int parse_ldbm_config_entry(struct ldbminfo *li, Slapi_Entry *e, config_info *config_array)
- {
- Slapi_Attr *attr = NULL;
-
- for (slapi_entry_first_attr(e, &attr); attr; slapi_entry_next_attr(e, attr, &attr)) {
- char *attr_name = NULL;
- Slapi_Value *sval = NULL;
- struct berval *bval;
- char err_buf[SLAPI_DSE_RETURNTEXT_SIZE];
-
- slapi_attr_get_type(attr, &attr_name);
-
- /* There are some attributes that we don't care about, like objectclass. */
- if (ldbm_config_ignored_attr(attr_name)) {
- continue;
- }
- slapi_attr_first_value(attr, &sval);
- bval = (struct berval *) slapi_value_get_berval(sval);
-
- if (ldbm_config_set(li, attr_name, config_array, bval, err_buf, CONFIG_PHASE_STARTUP, 1 /* apply */) != LDAP_SUCCESS) {
- LDAPDebug(LDAP_DEBUG_ANY, "Error with config attribute %s : %s\n", attr_name, err_buf, 0);
- return 1;
- }
- }
- return 0;
- }
- /*
- * Returns:
- * SLAPI_DSE_CALLBACK_ERROR on failure
- * SLAPI_DSE_CALLBACK_OK on success
- */
- int ldbm_config_modify_entry_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* e, int *returncode, char *returntext, void *arg)
- {
- int i;
- char *attr_name;
- LDAPMod **mods;
- int rc = LDAP_SUCCESS;
- int apply_mod = 0;
- struct ldbminfo *li= (struct ldbminfo *) arg;
-
- /* This lock is probably way too conservative, but we don't expect much
- * contention for it. */
- PR_Lock(li->li_config_mutex);
-
- slapi_pblock_get( pb, SLAPI_MODIFY_MODS, &mods );
-
- returntext[0] = '\0';
- /*
- * First pass: set apply mods to 0 so only input validation will be done;
- * 2nd pass: set apply mods to 1 to apply changes to internal storage
- */
- for ( apply_mod = 0; apply_mod <= 1 && LDAP_SUCCESS == rc; apply_mod++ ) {
- for (i = 0; mods[i] && LDAP_SUCCESS == rc; i++) {
- attr_name = mods[i]->mod_type;
-
- /* There are some attributes that we don't care about, like modifiersname. */
- if (ldbm_config_ignored_attr(attr_name)) {
- continue;
- }
-
- if (SLAPI_IS_MOD_DELETE(mods[i]->mod_op) ||
- SLAPI_IS_MOD_ADD(mods[i]->mod_op)) {
- rc= LDAP_UNWILLING_TO_PERFORM;
- PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "%s attributes is not allowed",
- (mods[i]->mod_op & LDAP_MOD_DELETE) ? "Deleting" : "Adding");
- } else if (mods[i]->mod_op & LDAP_MOD_REPLACE) {
- /* This assumes there is only one bval for this mod. */
- rc = ldbm_config_set((void *) li, attr_name, ldbm_config,
- ( mods[i]->mod_bvalues == NULL ) ? NULL
- : mods[i]->mod_bvalues[0], returntext,
- ((li->li_flags&LI_FORCE_MOD_CONFIG)?
- CONFIG_PHASE_INTERNAL:CONFIG_PHASE_RUNNING),
- apply_mod);
- }
- }
- }
-
- PR_Unlock(li->li_config_mutex);
-
- *returncode= rc;
- if(LDAP_SUCCESS == rc) {
- return SLAPI_DSE_CALLBACK_OK;
- }
- else {
- return SLAPI_DSE_CALLBACK_ERROR;
- }
- }
- /* This function is used to set config attributes. It can be used as a
- * shortcut to doing an internal modify operation on the config DSE.
- */
- void ldbm_config_internal_set(struct ldbminfo *li, char *attrname, char *value)
- {
- char err_buf[SLAPI_DSE_RETURNTEXT_SIZE];
- struct berval bval;
-
- bval.bv_val = value;
- bval.bv_len = strlen(value);
-
- if (ldbm_config_set((void *) li, attrname, ldbm_config, &bval,
- err_buf, CONFIG_PHASE_INTERNAL, 1 /* apply */) != LDAP_SUCCESS) {
- LDAPDebug(LDAP_DEBUG_ANY,
- "Internal Error: Error setting instance config attr %s to %s: %s\n",
- attrname, value, err_buf);
- exit(1);
- }
- }
- /*
- * replace_ldbm_config_value:
- * - update an ldbm database config value
- */
- void replace_ldbm_config_value(char *conftype, char *val, struct ldbminfo *li)
- {
- Slapi_PBlock pb;
- Slapi_Mods smods;
- pblock_init(&pb);
- slapi_mods_init(&smods, 1);
- slapi_mods_add(&smods, LDAP_MOD_REPLACE, conftype, strlen(val), val);
- slapi_modify_internal_set_pb(&pb, CONFIG_LDBM_DN,
- slapi_mods_get_ldapmods_byref(&smods),
- NULL, NULL, li->li_identity, 0);
- slapi_modify_internal_pb(&pb);
- slapi_mods_done(&smods);
- pblock_done(&pb);
- }
|