ldbm_config.c 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. #ifdef HAVE_CONFIG_H
  39. # include <config.h>
  40. #endif
  41. /* ldbm_config.c - Handles configuration information that is global to all ldbm instances. */
  42. #include "back-ldbm.h"
  43. #include "dblayer.h"
  44. /* Forward declarations */
  45. static int parse_ldbm_config_entry(struct ldbminfo *li, Slapi_Entry *e, config_info *config_array);
  46. /* Forward callback declarations */
  47. int ldbm_config_search_entry_callback(Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry* entryAfter, int *returncode, char *returntext, void *arg);
  48. int ldbm_config_modify_entry_callback(Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry* entryAfter, int *returncode, char *returntext, void *arg);
  49. static char *ldbm_skeleton_entries[] =
  50. {
  51. "dn:cn=config, cn=%s, cn=plugins, cn=config\n"
  52. "objectclass:top\n"
  53. "objectclass:extensibleObject\n"
  54. "cn:config\n",
  55. "dn:cn=monitor, cn=%s, cn=plugins, cn=config\n"
  56. "objectclass:top\n"
  57. "objectclass:extensibleObject\n"
  58. "cn:monitor\n",
  59. "dn:cn=database, cn=monitor, cn=%s, cn=plugins, cn=config\n"
  60. "objectclass:top\n"
  61. "objectclass:extensibleObject\n"
  62. "cn:database\n",
  63. ""
  64. };
  65. /* Used to add an array of entries, like the one above and
  66. * ldbm_instance_skeleton_entries in ldbm_instance_config.c, to the dse.
  67. * Returns 0 on success.
  68. */
  69. int ldbm_config_add_dse_entries(struct ldbminfo *li, char **entries, char *string1, char *string2, char *string3, int flags)
  70. {
  71. int x;
  72. Slapi_Entry *e;
  73. Slapi_PBlock *util_pb = NULL;
  74. int rc;
  75. int result;
  76. char entry_string[512];
  77. int dont_write_file = 0;
  78. char ebuf[BUFSIZ];
  79. if (flags & LDBM_INSTANCE_CONFIG_DONT_WRITE) {
  80. dont_write_file = 1;
  81. }
  82. for(x = 0; strlen(entries[x]) > 0; x++) {
  83. util_pb = slapi_pblock_new();
  84. PR_snprintf(entry_string, 512, entries[x], string1, string2, string3);
  85. e = slapi_str2entry(entry_string, 0);
  86. PR_snprintf(ebuf, sizeof(ebuf), slapi_entry_get_dn_const(e)); /* for logging */
  87. slapi_add_entry_internal_set_pb(util_pb, e, NULL, li->li_identity, 0);
  88. slapi_pblock_set(util_pb, SLAPI_DSE_DONT_WRITE_WHEN_ADDING,
  89. &dont_write_file);
  90. rc = slapi_add_internal_pb(util_pb);
  91. slapi_pblock_get(util_pb, SLAPI_PLUGIN_INTOP_RESULT, &result);
  92. if (!rc && (result == LDAP_SUCCESS)) {
  93. LDAPDebug(LDAP_DEBUG_CONFIG, "Added database config entry [%s]\n",
  94. ebuf, 0, 0);
  95. } else if (result == LDAP_ALREADY_EXISTS) {
  96. LDAPDebug(LDAP_DEBUG_TRACE, "Database config entry [%s] already exists - skipping\n",
  97. ebuf, 0, 0);
  98. } else {
  99. LDAPDebug(LDAP_DEBUG_ANY, "Unable to add config entry [%s] to the DSE: %d %d\n",
  100. ebuf, result, rc);
  101. }
  102. slapi_pblock_destroy(util_pb);
  103. }
  104. return 0;
  105. }
  106. /* used to add a single entry, special case of above */
  107. int ldbm_config_add_dse_entry(struct ldbminfo *li, char *entry, int flags)
  108. {
  109. char *entries[] = { "%s", "" };
  110. return ldbm_config_add_dse_entries(li, entries, entry, NULL, NULL, flags);
  111. }
  112. /* Finds an entry in a config_info array with the given name. Returns
  113. * the entry on success and NULL when not found.
  114. */
  115. config_info *get_config_info(config_info *config_array, char *attr_name)
  116. {
  117. int x;
  118. for(x = 0; config_array[x].config_name != NULL; x++) {
  119. if (!strcasecmp(config_array[x].config_name, attr_name)) {
  120. return &(config_array[x]);
  121. }
  122. }
  123. return NULL;
  124. }
  125. /*------------------------------------------------------------------------
  126. * Get and set functions for ldbm and dblayer variables
  127. *----------------------------------------------------------------------*/
  128. static void *ldbm_config_lookthroughlimit_get(void *arg)
  129. {
  130. struct ldbminfo *li = (struct ldbminfo *) arg;
  131. return (void *) ((uintptr_t)(li->li_lookthroughlimit));
  132. }
  133. static int ldbm_config_lookthroughlimit_set(void *arg, void *value, char *errorbuf, int phase, int apply)
  134. {
  135. struct ldbminfo *li = (struct ldbminfo *) arg;
  136. int retval = LDAP_SUCCESS;
  137. int val = (int) ((uintptr_t)value);
  138. /* Do whatever we can to make sure the data is ok. */
  139. if (apply) {
  140. li->li_lookthroughlimit = val;
  141. }
  142. return retval;
  143. }
  144. static void *ldbm_config_mode_get(void *arg)
  145. {
  146. struct ldbminfo *li = (struct ldbminfo *) arg;
  147. return (void *) ((uintptr_t)(li->li_mode));
  148. }
  149. static int ldbm_config_mode_set(void *arg, void *value, char *errorbuf, int phase, int apply)
  150. {
  151. struct ldbminfo *li = (struct ldbminfo *) arg;
  152. int retval = LDAP_SUCCESS;
  153. int val = (int) ((uintptr_t)value);
  154. /* Do whatever we can to make sure the data is ok. */
  155. if (apply) {
  156. li->li_mode = val;
  157. }
  158. return retval;
  159. }
  160. static void *ldbm_config_allidsthreshold_get(void *arg)
  161. {
  162. struct ldbminfo *li = (struct ldbminfo *) arg;
  163. return (void *) ((uintptr_t)(li->li_allidsthreshold));
  164. }
  165. static int ldbm_config_allidsthreshold_set(void *arg, void *value, char *errorbuf, int phase, int apply)
  166. {
  167. struct ldbminfo *li = (struct ldbminfo *) arg;
  168. int retval = LDAP_SUCCESS;
  169. int val = (int) ((uintptr_t)value);
  170. /* Do whatever we can to make sure the data is ok. */
  171. /* Catch attempts to configure a stupidly low allidsthreshold */
  172. if (val < 100) {
  173. val = 100;
  174. }
  175. if (apply) {
  176. li->li_allidsthreshold = val;
  177. }
  178. return retval;
  179. }
  180. static void *ldbm_config_directory_get(void *arg)
  181. {
  182. struct ldbminfo *li = (struct ldbminfo *) arg;
  183. /* Remember get functions of type string need to return
  184. * alloced memory. */
  185. return (void *) slapi_ch_strdup(li->li_new_directory);
  186. }
  187. static int ldbm_config_directory_set(void *arg, void *value, char *errorbuf, int phase, int apply)
  188. {
  189. struct ldbminfo *li = (struct ldbminfo *) arg;
  190. int retval = LDAP_SUCCESS;
  191. char *val = (char *) value;
  192. char tmpbuf[BUFSIZ];
  193. errorbuf[0] = '\0';
  194. if (!apply) {
  195. /* we should really do some error checking here. */
  196. return retval;
  197. }
  198. if (CONFIG_PHASE_RUNNING == phase) {
  199. slapi_ch_free((void **) &(li->li_new_directory));
  200. li->li_new_directory = rel2abspath(val); /* normalize the path;
  201. strdup'ed in rel2abspath */
  202. LDAPDebug(LDAP_DEBUG_ANY, "New db directory location will not take affect until the server is restarted\n", 0, 0, 0);
  203. } else {
  204. slapi_ch_free((void **) &(li->li_new_directory));
  205. slapi_ch_free((void **) &(li->li_directory));
  206. if (NULL == val || '\0' == *val) {
  207. LDAPDebug(LDAP_DEBUG_ANY,
  208. "ERROR: db directory is not set; check %s in the db config: %s\n",
  209. CONFIG_DIRECTORY, CONFIG_LDBM_DN, 0);
  210. retval = LDAP_PARAM_ERROR;
  211. } else {
  212. if (0 == strcmp(val, "get default")) {
  213. /* We use this funky "get default" string for the caller to
  214. * tell us that it has no idea what the db directory should
  215. * be. This code figures it out be reading "cn=config,cn=ldbm
  216. * database,cn=plugins,cn=config" entry. */
  217. Slapi_PBlock *search_pb;
  218. Slapi_Entry **entries = NULL;
  219. Slapi_Attr *attr = NULL;
  220. Slapi_Value *v = NULL;
  221. const char *s = NULL;
  222. int res;
  223. search_pb = slapi_pblock_new();
  224. slapi_search_internal_set_pb(search_pb, CONFIG_LDBM_DN,
  225. LDAP_SCOPE_BASE, "objectclass=*", NULL, 0, NULL, NULL,
  226. li->li_identity, 0);
  227. slapi_search_internal_pb(search_pb);
  228. slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_RESULT, &res);
  229. if (res != LDAP_SUCCESS) {
  230. LDAPDebug(LDAP_DEBUG_ANY,
  231. "ERROR: ldbm plugin unable to read %s\n",
  232. CONFIG_LDBM_DN, 0, 0);
  233. retval = res;
  234. goto done;
  235. }
  236. slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries);
  237. if (NULL == entries) {
  238. LDAPDebug(LDAP_DEBUG_ANY,
  239. "ERROR: ldbm plugin unable to read %s\n",
  240. CONFIG_LDBM_DN, 0, 0);
  241. retval = LDAP_OPERATIONS_ERROR;
  242. goto done;
  243. }
  244. res = slapi_entry_attr_find(entries[0], "nsslapd-directory", &attr);
  245. if (res != 0 || attr == NULL) {
  246. LDAPDebug(LDAP_DEBUG_ANY,
  247. "ERROR: ldbm plugin unable to read attribute nsslapd-directory from %s\n",
  248. CONFIG_LDBM_DN, 0, 0);
  249. retval = LDAP_OPERATIONS_ERROR;
  250. goto done;
  251. }
  252. if ( slapi_attr_first_value(attr,&v) != 0
  253. || ( NULL == v )
  254. || ( NULL == ( s = slapi_value_get_string( v )))) {
  255. LDAPDebug(LDAP_DEBUG_ANY,
  256. "ERROR: ldbm plugin unable to read attribute nsslapd-directory from %s\n",
  257. CONFIG_LDBM_DN, 0, 0);
  258. retval = LDAP_OPERATIONS_ERROR;
  259. goto done;
  260. }
  261. slapi_pblock_destroy(search_pb);
  262. if (NULL == s || '\0' == s || 0 == PL_strcmp(s, "(null)")) {
  263. LDAPDebug(LDAP_DEBUG_ANY,
  264. "ERROR: db directory is not set; check %s in the db config: %s\n",
  265. CONFIG_DIRECTORY, CONFIG_LDBM_DN, 0);
  266. retval = LDAP_PARAM_ERROR;
  267. goto done;
  268. }
  269. PR_snprintf(tmpbuf, BUFSIZ, "%s", s);
  270. val = tmpbuf;
  271. }
  272. li->li_new_directory = rel2abspath(val); /* normalize the path;
  273. strdup'ed in
  274. rel2abspath */
  275. li->li_directory = rel2abspath(val); /* ditto */
  276. }
  277. }
  278. done:
  279. return retval;
  280. }
  281. static void *ldbm_config_dbcachesize_get(void *arg)
  282. {
  283. struct ldbminfo *li = (struct ldbminfo *) arg;
  284. return (void *) (li->li_new_dbcachesize);
  285. }
  286. static int ldbm_config_dbcachesize_set(void *arg, void *value, char *errorbuf, int phase, int apply)
  287. {
  288. struct ldbminfo *li = (struct ldbminfo *) arg;
  289. int retval = LDAP_SUCCESS;
  290. size_t val = (size_t) value;
  291. if (apply) {
  292. /* Stop the user configuring a stupidly small cache */
  293. /* min: 8KB (page size) * def thrd cnts (threadnumber==20). */
  294. #define DBDEFMINSIZ 500000
  295. if (val < DBDEFMINSIZ) {
  296. LDAPDebug( LDAP_DEBUG_ANY,"WARNING: cache too small, increasing to %dK bytes\n", DBDEFMINSIZ/1000, 0, 0);
  297. val = DBDEFMINSIZ;
  298. }
  299. if (CONFIG_PHASE_RUNNING == phase) {
  300. li->li_new_dbcachesize = val;
  301. LDAPDebug(LDAP_DEBUG_ANY, "New db cache size will not take affect until the server is restarted\n", 0, 0, 0);
  302. } else {
  303. li->li_new_dbcachesize = val;
  304. li->li_dbcachesize = val;
  305. }
  306. }
  307. return retval;
  308. }
  309. static void *ldbm_config_maxpassbeforemerge_get(void *arg)
  310. {
  311. struct ldbminfo *li = (struct ldbminfo *) arg;
  312. return (void *) ((uintptr_t)(li->li_maxpassbeforemerge));
  313. }
  314. static int ldbm_config_maxpassbeforemerge_set(void *arg, void *value, char *errorbuf, int phase, int apply)
  315. {
  316. struct ldbminfo *li = (struct ldbminfo *) arg;
  317. int retval = LDAP_SUCCESS;
  318. int val = (int) ((uintptr_t)value);
  319. if (apply) {
  320. if (val < 0) {
  321. LDAPDebug( LDAP_DEBUG_ANY,"WARNING: maxpassbeforemerge will not take negative value\n", 0, 0, 0);
  322. val = 100;
  323. }
  324. li->li_maxpassbeforemerge = val;
  325. }
  326. return retval;
  327. }
  328. static void *ldbm_config_dbncache_get(void *arg)
  329. {
  330. struct ldbminfo *li = (struct ldbminfo *) arg;
  331. return (void *) ((uintptr_t)(li->li_new_dbncache));
  332. }
  333. static int ldbm_config_dbncache_set(void *arg, void *value, char *errorbuf, int phase, int apply)
  334. {
  335. struct ldbminfo *li = (struct ldbminfo *) arg;
  336. int retval = LDAP_SUCCESS;
  337. int val = (int) ((uintptr_t)value);
  338. if (apply) {
  339. if (val < 0) {
  340. LDAPDebug( LDAP_DEBUG_ANY,"WARNING: ncache will not take negative value\n", 0, 0, 0);
  341. val = 0;
  342. }
  343. if (CONFIG_PHASE_RUNNING == phase) {
  344. li->li_new_dbncache = val;
  345. LDAPDebug(LDAP_DEBUG_ANY, "New db ncache will not take affect until the server is restarted\n", 0, 0, 0);
  346. } else {
  347. li->li_new_dbncache = val;
  348. li->li_dbncache = val;
  349. }
  350. }
  351. return retval;
  352. }
  353. static void *ldbm_config_db_logdirectory_get(void *arg)
  354. {
  355. struct ldbminfo *li = (struct ldbminfo *) arg;
  356. /* Remember get functions of type string need to return
  357. * alloced memory. */
  358. /* if dblayer_log_directory is set to a string different from ""
  359. * then it has been set, return this variable
  360. * otherwise it is set to default, use the instance home directory
  361. */
  362. if (strlen(li->li_dblayer_private->dblayer_log_directory) > 0)
  363. return (void *) slapi_ch_strdup(li->li_dblayer_private->dblayer_log_directory);
  364. else
  365. return (void *) slapi_ch_strdup(li->li_new_directory);
  366. }
  367. static int ldbm_config_db_logdirectory_set(void *arg, void *value, char *errorbuf, int phase, int apply)
  368. {
  369. struct ldbminfo *li = (struct ldbminfo *) arg;
  370. int retval = LDAP_SUCCESS;
  371. char *val = (char *) value;
  372. if (apply) {
  373. slapi_ch_free((void **) &(li->li_dblayer_private->dblayer_log_directory));
  374. li->li_dblayer_private->dblayer_log_directory = slapi_ch_strdup(val);
  375. }
  376. return retval;
  377. }
  378. static void *ldbm_config_db_durable_transactions_get(void *arg)
  379. {
  380. struct ldbminfo *li = (struct ldbminfo *) arg;
  381. return (void *) ((uintptr_t)li->li_dblayer_private->dblayer_durable_transactions);
  382. }
  383. static int ldbm_config_db_durable_transactions_set(void *arg, void *value, char *errorbuf, int phase, int apply)
  384. {
  385. struct ldbminfo *li = (struct ldbminfo *) arg;
  386. int retval = LDAP_SUCCESS;
  387. int val = (int) ((uintptr_t)value);
  388. if (apply) {
  389. li->li_dblayer_private->dblayer_durable_transactions = val;
  390. }
  391. return retval;
  392. }
  393. static void *ldbm_config_db_lockdown_get(void *arg)
  394. {
  395. struct ldbminfo *li = (struct ldbminfo *) arg;
  396. return (void *) ((uintptr_t)li->li_dblayer_private->dblayer_lockdown);
  397. }
  398. static int ldbm_config_db_lockdown_set(
  399. void *arg,
  400. void *value,
  401. char *errorbuf,
  402. int phase,
  403. int apply
  404. )
  405. {
  406. struct ldbminfo *li = (struct ldbminfo *) arg;
  407. int retval = LDAP_SUCCESS;
  408. int val = (int) ((uintptr_t)value);
  409. if (apply) {
  410. li->li_dblayer_private->dblayer_lockdown = val;
  411. }
  412. return retval;
  413. }
  414. static void *ldbm_config_db_circular_logging_get(void *arg)
  415. {
  416. struct ldbminfo *li = (struct ldbminfo *) arg;
  417. return (void *) ((uintptr_t)li->li_dblayer_private->dblayer_circular_logging);
  418. }
  419. static int ldbm_config_db_circular_logging_set(void *arg, void *value, char *errorbuf, int phase, int apply)
  420. {
  421. struct ldbminfo *li = (struct ldbminfo *) arg;
  422. int retval = LDAP_SUCCESS;
  423. int val = (int) ((uintptr_t)value);
  424. if (apply) {
  425. li->li_dblayer_private->dblayer_circular_logging = val;
  426. }
  427. return retval;
  428. }
  429. static void *ldbm_config_db_transaction_logging_get(void *arg)
  430. {
  431. struct ldbminfo *li = (struct ldbminfo *) arg;
  432. return (void *) ((uintptr_t)li->li_dblayer_private->dblayer_enable_transactions);
  433. }
  434. static int ldbm_config_db_transaction_logging_set(void *arg, void *value, char *errorbuf, int phase, int apply)
  435. {
  436. struct ldbminfo *li = (struct ldbminfo *) arg;
  437. int retval = LDAP_SUCCESS;
  438. int val = (int) ((uintptr_t)value);
  439. if (apply) {
  440. li->li_dblayer_private->dblayer_enable_transactions = val;
  441. }
  442. return retval;
  443. }
  444. static void *ldbm_config_db_logbuf_size_get(void *arg)
  445. {
  446. struct ldbminfo *li = (struct ldbminfo *) arg;
  447. return (void *) li->li_dblayer_private->dblayer_logbuf_size;
  448. }
  449. static int ldbm_config_db_logbuf_size_set(void *arg, void *value, char *errorbuf, int phase, int apply)
  450. {
  451. struct ldbminfo *li = (struct ldbminfo *) arg;
  452. int retval = LDAP_SUCCESS;
  453. size_t val = (size_t) value;
  454. if (apply) {
  455. li->li_dblayer_private->dblayer_logbuf_size = val;
  456. }
  457. return retval;
  458. }
  459. static void *ldbm_config_db_checkpoint_interval_get(void *arg)
  460. {
  461. struct ldbminfo *li = (struct ldbminfo *) arg;
  462. return (void *) ((uintptr_t)li->li_dblayer_private->dblayer_checkpoint_interval);
  463. }
  464. static int ldbm_config_db_checkpoint_interval_set(void *arg, void *value, char *errorbuf, int phase, int apply)
  465. {
  466. struct ldbminfo *li = (struct ldbminfo *) arg;
  467. int retval = LDAP_SUCCESS;
  468. int val = (int) ((uintptr_t)value);
  469. if (apply) {
  470. li->li_dblayer_private->dblayer_checkpoint_interval = val;
  471. }
  472. return retval;
  473. }
  474. static void *ldbm_config_db_page_size_get(void *arg)
  475. {
  476. struct ldbminfo *li = (struct ldbminfo *) arg;
  477. return (void *) li->li_dblayer_private->dblayer_page_size;
  478. }
  479. static int ldbm_config_db_page_size_set(void *arg, void *value, char *errorbuf, int phase, int apply)
  480. {
  481. struct ldbminfo *li = (struct ldbminfo *) arg;
  482. int retval = LDAP_SUCCESS;
  483. size_t val = (size_t) value;
  484. if (apply) {
  485. li->li_dblayer_private->dblayer_page_size = val;
  486. }
  487. return retval;
  488. }
  489. static void *ldbm_config_db_index_page_size_get(void *arg)
  490. {
  491. struct ldbminfo *li = (struct ldbminfo *) arg;
  492. return (void *) li->li_dblayer_private->dblayer_index_page_size;
  493. }
  494. static int ldbm_config_db_index_page_size_set(void *arg, void *value, char *errorbuf, int phase, int apply)
  495. {
  496. struct ldbminfo *li = (struct ldbminfo *) arg;
  497. int retval = LDAP_SUCCESS;
  498. size_t val = (size_t) value;
  499. if (apply) {
  500. li->li_dblayer_private->dblayer_index_page_size = val;
  501. }
  502. return retval;
  503. }
  504. static void *ldbm_config_db_idl_divisor_get(void *arg)
  505. {
  506. struct ldbminfo *li = (struct ldbminfo *) arg;
  507. return (void *) ((uintptr_t)li->li_dblayer_private->dblayer_idl_divisor);
  508. }
  509. static int ldbm_config_db_idl_divisor_set(void *arg, void *value, char *errorbuf, int phase, int apply)
  510. {
  511. struct ldbminfo *li = (struct ldbminfo *) arg;
  512. int retval = LDAP_SUCCESS;
  513. int val = (int) ((uintptr_t)value);
  514. if (apply) {
  515. li->li_dblayer_private->dblayer_idl_divisor = val;
  516. }
  517. return retval;
  518. }
  519. static void *ldbm_config_db_logfile_size_get(void *arg)
  520. {
  521. struct ldbminfo *li = (struct ldbminfo *) arg;
  522. return (void *) li->li_dblayer_private->dblayer_logfile_size;
  523. }
  524. static int ldbm_config_db_logfile_size_set(void *arg, void *value, char *errorbuf, int phase, int apply)
  525. {
  526. struct ldbminfo *li = (struct ldbminfo *) arg;
  527. int retval = LDAP_SUCCESS;
  528. size_t val = (size_t) value;
  529. if (apply) {
  530. li->li_dblayer_private->dblayer_logfile_size = val;
  531. }
  532. return retval;
  533. }
  534. static void *ldbm_config_db_spin_count_get(void *arg)
  535. {
  536. struct ldbminfo *li = (struct ldbminfo *) arg;
  537. return (void *) ((uintptr_t)li->li_dblayer_private->dblayer_spin_count);
  538. }
  539. static int ldbm_config_db_spin_count_set(void *arg, void *value, char *errorbuf, int phase, int apply)
  540. {
  541. struct ldbminfo *li = (struct ldbminfo *) arg;
  542. int retval = LDAP_SUCCESS;
  543. int val = (int) ((uintptr_t)value);
  544. if (apply) {
  545. li->li_dblayer_private->dblayer_spin_count = val;
  546. }
  547. return retval;
  548. }
  549. static void *ldbm_config_db_trickle_percentage_get(void *arg)
  550. {
  551. struct ldbminfo *li = (struct ldbminfo *) arg;
  552. return (void *) ((uintptr_t)li->li_dblayer_private->dblayer_trickle_percentage);
  553. }
  554. static int ldbm_config_db_trickle_percentage_set(void *arg, void *value, char *errorbuf, int phase, int apply)
  555. {
  556. struct ldbminfo *li = (struct ldbminfo *) arg;
  557. int retval = LDAP_SUCCESS;
  558. int val = (int) ((uintptr_t)value);
  559. if (val < 0 || val > 100) {
  560. PR_snprintf(errorbuf, SLAPI_DSE_RETURNTEXT_SIZE,
  561. "Error: Invalid value for %s (%d). Must be between 0 and 100\n", CONFIG_DB_TRICKLE_PERCENTAGE, val);
  562. LDAPDebug(LDAP_DEBUG_ANY, "%s", errorbuf, 0, 0);
  563. return LDAP_UNWILLING_TO_PERFORM;
  564. }
  565. if (apply) {
  566. li->li_dblayer_private->dblayer_trickle_percentage = val;
  567. }
  568. return retval;
  569. }
  570. static void *ldbm_config_db_verbose_get(void *arg)
  571. {
  572. struct ldbminfo *li = (struct ldbminfo *) arg;
  573. return (void *) ((uintptr_t)li->li_dblayer_private->dblayer_verbose);
  574. }
  575. static int ldbm_config_db_verbose_set(void *arg, void *value, char *errorbuf, int phase, int apply)
  576. {
  577. struct ldbminfo *li = (struct ldbminfo *) arg;
  578. int retval = LDAP_SUCCESS;
  579. int val = (int) ((uintptr_t)value);
  580. if (apply) {
  581. li->li_dblayer_private->dblayer_verbose = val;
  582. }
  583. return retval;
  584. }
  585. static void *ldbm_config_db_debug_get(void *arg)
  586. {
  587. struct ldbminfo *li = (struct ldbminfo *) arg;
  588. return (void *) ((uintptr_t)li->li_dblayer_private->dblayer_debug);
  589. }
  590. static int ldbm_config_db_debug_set(void *arg, void *value, char *errorbuf, int phase, int apply)
  591. {
  592. struct ldbminfo *li = (struct ldbminfo *) arg;
  593. int retval = LDAP_SUCCESS;
  594. int val = (int) ((uintptr_t)value);
  595. if (apply) {
  596. li->li_dblayer_private->dblayer_debug = val;
  597. }
  598. return retval;
  599. }
  600. static void *ldbm_config_db_named_regions_get(void *arg)
  601. {
  602. struct ldbminfo *li = (struct ldbminfo *) arg;
  603. return (void *) ((uintptr_t)li->li_dblayer_private->dblayer_named_regions);
  604. }
  605. static int ldbm_config_db_named_regions_set(void *arg, void *value, char *errorbuf, int phase, int apply)
  606. {
  607. struct ldbminfo *li = (struct ldbminfo *) arg;
  608. int retval = LDAP_SUCCESS;
  609. int val = (int) ((uintptr_t)value);
  610. if (apply) {
  611. li->li_dblayer_private->dblayer_named_regions = val;
  612. }
  613. return retval;
  614. }
  615. static void *ldbm_config_db_private_mem_get(void *arg)
  616. {
  617. struct ldbminfo *li = (struct ldbminfo *) arg;
  618. return (void *) ((uintptr_t)li->li_dblayer_private->dblayer_private_mem);
  619. }
  620. static int ldbm_config_db_private_mem_set(void *arg, void *value, char *errorbuf, int phase, int apply)
  621. {
  622. struct ldbminfo *li = (struct ldbminfo *) arg;
  623. int retval = LDAP_SUCCESS;
  624. int val = (int) ((uintptr_t)value);
  625. if (apply) {
  626. li->li_dblayer_private->dblayer_private_mem = val;
  627. }
  628. return retval;
  629. }
  630. static void *ldbm_config_db_private_import_mem_get(void *arg)
  631. {
  632. struct ldbminfo *li = (struct ldbminfo *) arg;
  633. return (void *) ((uintptr_t)li->li_dblayer_private->dblayer_private_import_mem);
  634. }
  635. static int ldbm_config_db_private_import_mem_set(void *arg, void *value, char *errorbuf, int phase, int apply)
  636. {
  637. struct ldbminfo *li = (struct ldbminfo *) arg;
  638. int retval = LDAP_SUCCESS;
  639. int val = (int) ((uintptr_t)value);
  640. if (apply) {
  641. li->li_dblayer_private->dblayer_private_import_mem = val;
  642. }
  643. return retval;
  644. }
  645. static void *ldbm_config_db_shm_key_get(void *arg)
  646. {
  647. struct ldbminfo *li = (struct ldbminfo *) arg;
  648. return (void *) li->li_dblayer_private->dblayer_shm_key;
  649. }
  650. static int ldbm_config_db_shm_key_set(
  651. void *arg,
  652. void *value,
  653. char *errorbuf,
  654. int phase,
  655. int apply
  656. )
  657. {
  658. struct ldbminfo *li = (struct ldbminfo *) arg;
  659. int retval = LDAP_SUCCESS;
  660. int val = (int) ((uintptr_t)value);
  661. if (apply) {
  662. li->li_dblayer_private->dblayer_shm_key = val;
  663. }
  664. return retval;
  665. }
  666. static void *ldbm_config_db_lock_get(void *arg)
  667. {
  668. struct ldbminfo *li = (struct ldbminfo *) arg;
  669. return (void *) ((uintptr_t)li->li_dblayer_private->dblayer_lock_config);
  670. }
  671. static int ldbm_config_db_lock_set(void *arg, void *value, char *errorbuf, int phase, int apply)
  672. {
  673. struct ldbminfo *li = (struct ldbminfo *) arg;
  674. int retval = LDAP_SUCCESS;
  675. size_t val = (size_t) value;
  676. if (apply) {
  677. if (CONFIG_PHASE_RUNNING == phase) {
  678. li->li_dblayer_private->dblayer_lock_config = val;
  679. LDAPDebug(LDAP_DEBUG_ANY, "New db cache size will not take affect until the server is restarted\n", 0, 0, 0);
  680. } else {
  681. li->li_dblayer_private->dblayer_lock_config = val;
  682. }
  683. }
  684. return retval;
  685. }
  686. static void *ldbm_config_db_cache_get(void *arg)
  687. {
  688. struct ldbminfo *li = (struct ldbminfo *) arg;
  689. return (void *) ((uintptr_t)li->li_dblayer_private->dblayer_cache_config);
  690. }
  691. static int ldbm_config_db_cache_set(void *arg, void *value, char *errorbuf, int phase, int apply)
  692. {
  693. struct ldbminfo *li = (struct ldbminfo *) arg;
  694. int retval = LDAP_SUCCESS;
  695. int val = (int) ((uintptr_t)value);
  696. if (apply) {
  697. li->li_dblayer_private->dblayer_cache_config = val;
  698. }
  699. return retval;
  700. }
  701. static void *ldbm_config_db_debug_checkpointing_get(void *arg)
  702. {
  703. struct ldbminfo *li = (struct ldbminfo *) arg;
  704. return (void *) ((uintptr_t)li->li_dblayer_private->db_debug_checkpointing);
  705. }
  706. static int ldbm_config_db_debug_checkpointing_set(void *arg, void *value, char *errorbuf, int phase, int apply)
  707. {
  708. struct ldbminfo *li = (struct ldbminfo *) arg;
  709. int retval = LDAP_SUCCESS;
  710. int val = (int) ((uintptr_t)value);
  711. if (apply) {
  712. li->li_dblayer_private->db_debug_checkpointing = val;
  713. }
  714. return retval;
  715. }
  716. static void *ldbm_config_db_home_directory_get(void *arg)
  717. {
  718. struct ldbminfo *li = (struct ldbminfo *) arg;
  719. /* Remember get functions of type string need to return
  720. * alloced memory. */
  721. return (void *) slapi_ch_strdup(li->li_dblayer_private->dblayer_dbhome_directory);
  722. }
  723. static int ldbm_config_db_home_directory_set(void *arg, void *value, char *errorbuf, int phase, int apply)
  724. {
  725. struct ldbminfo *li = (struct ldbminfo *) arg;
  726. int retval = LDAP_SUCCESS;
  727. char *val = (char *) value;
  728. if (apply) {
  729. slapi_ch_free((void **) &(li->li_dblayer_private->dblayer_dbhome_directory));
  730. li->li_dblayer_private->dblayer_dbhome_directory = slapi_ch_strdup(val);
  731. }
  732. return retval;
  733. }
  734. static void *ldbm_config_import_cache_autosize_get(void *arg)
  735. {
  736. struct ldbminfo *li = (struct ldbminfo *)arg;
  737. return (void *)((uintptr_t)(li->li_import_cache_autosize));
  738. }
  739. static int ldbm_config_import_cache_autosize_set(void *arg, void *value, char *errorbuf,
  740. int phase, int apply)
  741. {
  742. struct ldbminfo *li = (struct ldbminfo *)arg;
  743. if (apply)
  744. li->li_import_cache_autosize = (int)((uintptr_t)value);
  745. return LDAP_SUCCESS;
  746. }
  747. static void *ldbm_config_cache_autosize_get(void *arg)
  748. {
  749. struct ldbminfo *li = (struct ldbminfo *)arg;
  750. return (void *)((uintptr_t)(li->li_cache_autosize));
  751. }
  752. static int ldbm_config_cache_autosize_set(void *arg, void *value, char *errorbuf,
  753. int phase, int apply)
  754. {
  755. struct ldbminfo *li = (struct ldbminfo *)arg;
  756. if (apply)
  757. li->li_cache_autosize = (int)((uintptr_t)value);
  758. return LDAP_SUCCESS;
  759. }
  760. static void *ldbm_config_cache_autosize_split_get(void *arg)
  761. {
  762. struct ldbminfo *li = (struct ldbminfo *)arg;
  763. return (void *)((uintptr_t)(li->li_cache_autosize_split));
  764. }
  765. static int ldbm_config_cache_autosize_split_set(void *arg, void *value, char *errorbuf,
  766. int phase, int apply)
  767. {
  768. struct ldbminfo *li = (struct ldbminfo *)arg;
  769. if (apply)
  770. li->li_cache_autosize_split = (int)((uintptr_t)value);
  771. return LDAP_SUCCESS;
  772. }
  773. static void *ldbm_config_import_cachesize_get(void *arg)
  774. {
  775. struct ldbminfo *li = (struct ldbminfo *)arg;
  776. return (void *)(li->li_import_cachesize);
  777. }
  778. static int ldbm_config_import_cachesize_set(void *arg, void *value, char *errorbuf,
  779. int phase, int apply)
  780. {
  781. struct ldbminfo *li = (struct ldbminfo *)arg;
  782. if (apply)
  783. li->li_import_cachesize = (size_t)value;
  784. return LDAP_SUCCESS;
  785. }
  786. static void *ldbm_config_index_buffer_size_get(void *arg)
  787. {
  788. return (void *)import_get_index_buffer_size();
  789. }
  790. static int ldbm_config_index_buffer_size_set(void *arg, void *value, char *errorbuf,
  791. int phase, int apply)
  792. {
  793. if (apply)
  794. import_configure_index_buffer_size((size_t)value);
  795. return LDAP_SUCCESS;
  796. }
  797. static void *ldbm_config_idl_get_idl_new(void *arg)
  798. {
  799. if (idl_get_idl_new())
  800. return slapi_ch_strdup("new");
  801. else
  802. return slapi_ch_strdup("old");
  803. }
  804. static int ldbm_config_idl_set_tune(void *arg, void *value, char *errorbuf,
  805. int phase, int apply)
  806. {
  807. if (!strcasecmp("new", value))
  808. idl_set_tune(4096);
  809. else
  810. idl_set_tune(0);
  811. return LDAP_SUCCESS;
  812. }
  813. static void *ldbm_config_serial_lock_get(void *arg)
  814. {
  815. struct ldbminfo *li = (struct ldbminfo *) arg;
  816. return (void *) ((uintptr_t)li->li_fat_lock);
  817. }
  818. static int ldbm_config_serial_lock_set(void *arg, void *value, char *errorbuf,
  819. int phase, int apply)
  820. {
  821. struct ldbminfo *li = (struct ldbminfo *) arg;
  822. if (apply) {
  823. li->li_fat_lock = (int) ((uintptr_t)value);
  824. }
  825. return LDAP_SUCCESS;
  826. }
  827. static void *ldbm_config_legacy_errcode_get(void *arg)
  828. {
  829. struct ldbminfo *li = (struct ldbminfo *) arg;
  830. return (void *) ((uintptr_t)li->li_legacy_errcode);
  831. }
  832. static int ldbm_config_legacy_errcode_set(void *arg, void *value, char *errorbuf,
  833. int phase, int apply)
  834. {
  835. struct ldbminfo *li = (struct ldbminfo *) arg;
  836. if (apply) {
  837. li->li_legacy_errcode = (int) ((uintptr_t)value);
  838. }
  839. return LDAP_SUCCESS;
  840. }
  841. static int
  842. ldbm_config_set_bypass_filter_test(void *arg, void *value, char *errorbuf,
  843. int phase, int apply)
  844. {
  845. struct ldbminfo *li = (struct ldbminfo *)arg;
  846. if (apply) {
  847. char *myvalue = (char *)value;
  848. if (0 == strcasecmp(myvalue, "on")) {
  849. li->li_filter_bypass = 1;
  850. li->li_filter_bypass_check = 0;
  851. } else if (0 == strcasecmp(myvalue, "verify")) {
  852. li->li_filter_bypass = 1;
  853. li->li_filter_bypass_check = 1;
  854. } else {
  855. li->li_filter_bypass = 0;
  856. li->li_filter_bypass_check = 0;
  857. }
  858. }
  859. return LDAP_SUCCESS;
  860. }
  861. static void *ldbm_config_get_bypass_filter_test(void *arg)
  862. {
  863. struct ldbminfo *li = (struct ldbminfo *)arg;
  864. char *retstr = NULL;
  865. if (li->li_filter_bypass) {
  866. if (li->li_filter_bypass_check) {
  867. /* meaningful only if is bypass filter test called */
  868. retstr = slapi_ch_strdup("verify");
  869. } else {
  870. retstr = slapi_ch_strdup("on");
  871. }
  872. } else {
  873. retstr = slapi_ch_strdup("off");
  874. }
  875. return (void *)retstr;
  876. }
  877. static int ldbm_config_set_use_vlv_index(void *arg, void *value, char *errorbuf, int phase, int apply)
  878. {
  879. struct ldbminfo *li = (struct ldbminfo *) arg;
  880. int val = (int) ((uintptr_t)value);
  881. if (apply) {
  882. if (val) {
  883. li->li_use_vlv = 1;
  884. } else {
  885. li->li_use_vlv = 0;
  886. }
  887. }
  888. return LDAP_SUCCESS;
  889. }
  890. static void *ldbm_config_get_use_vlv_index(void *arg)
  891. {
  892. struct ldbminfo *li = (struct ldbminfo *) arg;
  893. return (void *) ((uintptr_t)li->li_use_vlv);
  894. }
  895. static int
  896. ldbm_config_exclude_from_export_set( void *arg, void *value, char *errorbuf,
  897. int phase, int apply)
  898. {
  899. struct ldbminfo *li = (struct ldbminfo *)arg;
  900. if ( apply ) {
  901. if ( NULL != li->li_attrs_to_exclude_from_export ) {
  902. charray_free( li->li_attrs_to_exclude_from_export );
  903. li->li_attrs_to_exclude_from_export = NULL;
  904. }
  905. if ( NULL != value ) {
  906. char *dupvalue = slapi_ch_strdup( value );
  907. li->li_attrs_to_exclude_from_export = slapi_str2charray( dupvalue, " " );
  908. slapi_ch_free((void**)&dupvalue);
  909. }
  910. }
  911. return LDAP_SUCCESS;
  912. }
  913. static void *
  914. ldbm_config_exclude_from_export_get( void *arg )
  915. {
  916. struct ldbminfo *li = (struct ldbminfo *)arg;
  917. char *p, *retstr = NULL;
  918. size_t len = 0;
  919. if ( NULL != li->li_attrs_to_exclude_from_export &&
  920. NULL != li->li_attrs_to_exclude_from_export[0] ) {
  921. int i;
  922. for ( i = 0; li->li_attrs_to_exclude_from_export[i] != NULL; ++i ) {
  923. len += strlen( li->li_attrs_to_exclude_from_export[i] ) + 1;
  924. }
  925. p = retstr = slapi_ch_malloc( len );
  926. for ( i = 0; li->li_attrs_to_exclude_from_export[i] != NULL; ++i ) {
  927. if ( i > 0 ) {
  928. *p++ = ' ';
  929. }
  930. strcpy( p, li->li_attrs_to_exclude_from_export[i] );
  931. p += strlen( p );
  932. }
  933. *p = '\0';
  934. } else {
  935. retstr = slapi_ch_strdup( "" );
  936. }
  937. return (void *)retstr;
  938. }
  939. static void *ldbm_config_db_tx_max_get(void *arg)
  940. {
  941. struct ldbminfo *li = (struct ldbminfo *) arg;
  942. return (void *) ((uintptr_t)li->li_dblayer_private->dblayer_tx_max);
  943. }
  944. static int ldbm_config_db_tx_max_set(
  945. void *arg,
  946. void *value,
  947. char *errorbuf,
  948. int phase,
  949. int apply
  950. )
  951. {
  952. struct ldbminfo *li = (struct ldbminfo *) arg;
  953. int retval = LDAP_SUCCESS;
  954. int val = (int) ((uintptr_t)value);
  955. if (apply) {
  956. li->li_dblayer_private->dblayer_tx_max = val;
  957. }
  958. return retval;
  959. }
  960. /*------------------------------------------------------------------------
  961. * Configuration array for ldbm and dblayer variables
  962. *----------------------------------------------------------------------*/
  963. static config_info ldbm_config[] = {
  964. {CONFIG_LOOKTHROUGHLIMIT, CONFIG_TYPE_INT, "5000", &ldbm_config_lookthroughlimit_get, &ldbm_config_lookthroughlimit_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
  965. {CONFIG_MODE, CONFIG_TYPE_INT_OCTAL, "0600", &ldbm_config_mode_get, &ldbm_config_mode_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
  966. {CONFIG_IDLISTSCANLIMIT, CONFIG_TYPE_INT, "4000", &ldbm_config_allidsthreshold_get, &ldbm_config_allidsthreshold_set, CONFIG_FLAG_ALWAYS_SHOW},
  967. {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},
  968. {CONFIG_DBCACHESIZE, CONFIG_TYPE_SIZE_T, "10000000", &ldbm_config_dbcachesize_get, &ldbm_config_dbcachesize_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
  969. {CONFIG_DBNCACHE, CONFIG_TYPE_INT, "0", &ldbm_config_dbncache_get, &ldbm_config_dbncache_set, CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
  970. {CONFIG_MAXPASSBEFOREMERGE, CONFIG_TYPE_INT, "100", &ldbm_config_maxpassbeforemerge_get, &ldbm_config_maxpassbeforemerge_set, 0},
  971. /* dblayer config attributes */
  972. {CONFIG_DB_LOGDIRECTORY, CONFIG_TYPE_STRING, "", &ldbm_config_db_logdirectory_get, &ldbm_config_db_logdirectory_set, CONFIG_FLAG_ALWAYS_SHOW},
  973. {CONFIG_DB_DURABLE_TRANSACTIONS, CONFIG_TYPE_ONOFF, "on", &ldbm_config_db_durable_transactions_get, &ldbm_config_db_durable_transactions_set, CONFIG_FLAG_ALWAYS_SHOW},
  974. {CONFIG_DB_CIRCULAR_LOGGING, CONFIG_TYPE_ONOFF, "on", &ldbm_config_db_circular_logging_get, &ldbm_config_db_circular_logging_set, 0},
  975. {CONFIG_DB_TRANSACTION_LOGGING, CONFIG_TYPE_ONOFF, "on", &ldbm_config_db_transaction_logging_get, &ldbm_config_db_transaction_logging_set, 0},
  976. {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},
  977. {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},
  978. {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},
  979. {CONFIG_DB_PAGE_SIZE, CONFIG_TYPE_SIZE_T, "0", &ldbm_config_db_page_size_get, &ldbm_config_db_page_size_set, 0},
  980. {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},
  981. {CONFIG_DB_IDL_DIVISOR, CONFIG_TYPE_INT, "0", &ldbm_config_db_idl_divisor_get, &ldbm_config_db_idl_divisor_set, 0},
  982. {CONFIG_DB_LOGFILE_SIZE, CONFIG_TYPE_SIZE_T, "0", &ldbm_config_db_logfile_size_get, &ldbm_config_db_logfile_size_set, 0},
  983. {CONFIG_DB_TRICKLE_PERCENTAGE, CONFIG_TYPE_INT, "5", &ldbm_config_db_trickle_percentage_get, &ldbm_config_db_trickle_percentage_set, 0},
  984. {CONFIG_DB_SPIN_COUNT, CONFIG_TYPE_INT, "0", &ldbm_config_db_spin_count_get, &ldbm_config_db_spin_count_set, 0},
  985. {CONFIG_DB_VERBOSE, CONFIG_TYPE_ONOFF, "off", &ldbm_config_db_verbose_get, &ldbm_config_db_verbose_set, 0},
  986. {CONFIG_DB_DEBUG, CONFIG_TYPE_ONOFF, "on", &ldbm_config_db_debug_get, &ldbm_config_db_debug_set, 0},
  987. {CONFIG_DB_NAMED_REGIONS, CONFIG_TYPE_ONOFF, "off", &ldbm_config_db_named_regions_get, &ldbm_config_db_named_regions_set, 0},
  988. {CONFIG_DB_LOCK, CONFIG_TYPE_INT, "10000", &ldbm_config_db_lock_get, &ldbm_config_db_lock_set, 0},
  989. {CONFIG_DB_PRIVATE_MEM, CONFIG_TYPE_ONOFF, "off", &ldbm_config_db_private_mem_get, &ldbm_config_db_private_mem_set, 0},
  990. {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},
  991. {CONFIG_DB_SHM_KEY, CONFIG_TYPE_LONG, "389389", &ldbm_config_db_shm_key_get, &ldbm_config_db_shm_key_set, 0},
  992. {CONFIG_DB_CACHE, CONFIG_TYPE_INT, "0", &ldbm_config_db_cache_get, &ldbm_config_db_cache_set, 0},
  993. {CONFIG_DB_DEBUG_CHECKPOINTING, CONFIG_TYPE_ONOFF, "off", &ldbm_config_db_debug_checkpointing_get, &ldbm_config_db_debug_checkpointing_set, 0},
  994. {CONFIG_DB_HOME_DIRECTORY, CONFIG_TYPE_STRING, "", &ldbm_config_db_home_directory_get, &ldbm_config_db_home_directory_set, 0},
  995. {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},
  996. {CONFIG_CACHE_AUTOSIZE, CONFIG_TYPE_INT, "0", &ldbm_config_cache_autosize_get, &ldbm_config_cache_autosize_set, 0},
  997. {CONFIG_CACHE_AUTOSIZE_SPLIT, CONFIG_TYPE_INT, "50", &ldbm_config_cache_autosize_split_get, &ldbm_config_cache_autosize_split_set, 0},
  998. {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},
  999. {CONFIG_IDL_SWITCH, CONFIG_TYPE_STRING, "new", &ldbm_config_idl_get_idl_new, &ldbm_config_idl_set_tune, CONFIG_FLAG_ALWAYS_SHOW},
  1000. {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},
  1001. {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},
  1002. {CONFIG_DB_LOCKDOWN, CONFIG_TYPE_ONOFF, "off", &ldbm_config_db_lockdown_get, &ldbm_config_db_lockdown_set, 0},
  1003. {CONFIG_INDEX_BUFFER_SIZE, CONFIG_TYPE_INT, "0", &ldbm_config_index_buffer_size_get, &ldbm_config_index_buffer_size_set, 0},
  1004. {CONFIG_EXCLUDE_FROM_EXPORT, CONFIG_TYPE_STRING,
  1005. CONFIG_EXCLUDE_FROM_EXPORT_DEFAULT_VALUE,
  1006. &ldbm_config_exclude_from_export_get,
  1007. &ldbm_config_exclude_from_export_set, CONFIG_FLAG_ALWAYS_SHOW},
  1008. {CONFIG_DB_TX_MAX, CONFIG_TYPE_INT, "200", &ldbm_config_db_tx_max_get, &ldbm_config_db_tx_max_set, 0},
  1009. {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},
  1010. {CONFIG_USE_LEGACY_ERRORCODE, CONFIG_TYPE_ONOFF, "off", &ldbm_config_legacy_errcode_get, &ldbm_config_legacy_errcode_set, 0},
  1011. {NULL, 0, NULL, NULL, NULL, 0}
  1012. };
  1013. void ldbm_config_setup_default(struct ldbminfo *li)
  1014. {
  1015. config_info *config;
  1016. char err_buf[SLAPI_DSE_RETURNTEXT_SIZE];
  1017. for (config = ldbm_config; config->config_name != NULL; config++) {
  1018. ldbm_config_set((void *)li, config->config_name, ldbm_config, NULL /* use default */, err_buf, CONFIG_PHASE_INITIALIZATION, 1 /* apply */);
  1019. }
  1020. }
  1021. void
  1022. ldbm_config_read_instance_entries(struct ldbminfo *li, const char *backend_type)
  1023. {
  1024. Slapi_PBlock *tmp_pb;
  1025. char basedn[BUFSIZ];
  1026. Slapi_Entry **entries = NULL;
  1027. /* Construct the base dn of the subtree that holds the instance entries. */
  1028. PR_snprintf(basedn, BUFSIZ, "cn=%s, cn=plugins, cn=config", backend_type);
  1029. /* Do a search of the subtree containing the instance entries */
  1030. tmp_pb = slapi_pblock_new();
  1031. slapi_search_internal_set_pb(tmp_pb, basedn, LDAP_SCOPE_SUBTREE, "(objectclass=nsBackendInstance)", NULL, 0, NULL, NULL, li->li_identity, 0);
  1032. slapi_search_internal_pb (tmp_pb);
  1033. slapi_pblock_get(tmp_pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries);
  1034. if (entries!=NULL) {
  1035. int i;
  1036. for (i=0; entries[i]!=NULL; i++) {
  1037. ldbm_instance_add_instance_entry_callback(NULL, entries[i], NULL, NULL, NULL, li);
  1038. }
  1039. }
  1040. slapi_free_search_results_internal(tmp_pb);
  1041. slapi_pblock_destroy(tmp_pb);
  1042. }
  1043. /* Reads in any config information held in the dse for the ldbm plugin.
  1044. * Creates dse entries used to configure the ldbm plugin and dblayer
  1045. * if they don't already exist. Registers dse callback functions to
  1046. * maintain those dse entries. Returns 0 on success.
  1047. */
  1048. int ldbm_config_load_dse_info(struct ldbminfo *li)
  1049. {
  1050. Slapi_PBlock *search_pb;
  1051. Slapi_Entry **entries = NULL;
  1052. int res;
  1053. char dn[BUFSIZ];
  1054. /* We try to read the entry
  1055. * cn=config, cn=ldbm database, cn=plugins, cn=config. If the entry is
  1056. * there, then we process the config information it stores.
  1057. */
  1058. PR_snprintf(dn, BUFSIZ, "cn=config, cn=%s, cn=plugins, cn=config",
  1059. li->li_plugin->plg_name);
  1060. search_pb = slapi_pblock_new();
  1061. slapi_search_internal_set_pb(search_pb, dn, LDAP_SCOPE_BASE,
  1062. "objectclass=*", NULL, 0, NULL, NULL, li->li_identity, 0);
  1063. slapi_search_internal_pb (search_pb);
  1064. slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_RESULT, &res);
  1065. if (LDAP_NO_SUCH_OBJECT == res) {
  1066. /* Add skeleten dse entries for the ldbm plugin */
  1067. ldbm_config_add_dse_entries(li, ldbm_skeleton_entries,
  1068. li->li_plugin->plg_name, NULL, NULL, 0);
  1069. } else if (res != LDAP_SUCCESS) {
  1070. LDAPDebug(LDAP_DEBUG_ANY, "Error accessing the ldbm config DSE\n",
  1071. 0, 0, 0);
  1072. return 1;
  1073. } else {
  1074. /* Need to parse the configuration information for the ldbm
  1075. * plugin that is held in the DSE. */
  1076. slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES,
  1077. &entries);
  1078. if (NULL == entries || entries[0] == NULL) {
  1079. LDAPDebug(LDAP_DEBUG_ANY, "Error accessing the ldbm config DSE\n",
  1080. 0, 0, 0);
  1081. return 1;
  1082. }
  1083. if (0 != parse_ldbm_config_entry(li, entries[0], ldbm_config)) {
  1084. LDAPDebug(LDAP_DEBUG_ANY, "Error parsing the ldbm config DSE\n",
  1085. 0, 0, 0);
  1086. return 1;
  1087. }
  1088. }
  1089. if (search_pb) {
  1090. slapi_free_search_results_internal(search_pb);
  1091. slapi_pblock_destroy(search_pb);
  1092. }
  1093. /* Find all the instance entries and create a Slapi_Backend and an
  1094. * ldbm_instance for each */
  1095. ldbm_config_read_instance_entries(li, li->li_plugin->plg_name);
  1096. /* setup the dse callback functions for the ldbm backend config entry */
  1097. PR_snprintf(dn, BUFSIZ, "cn=config, cn=%s, cn=plugins, cn=config",
  1098. li->li_plugin->plg_name);
  1099. slapi_config_register_callback(SLAPI_OPERATION_SEARCH, DSE_FLAG_PREOP, dn,
  1100. LDAP_SCOPE_BASE, "(objectclass=*)", ldbm_config_search_entry_callback,
  1101. (void *) li);
  1102. slapi_config_register_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_PREOP, dn,
  1103. LDAP_SCOPE_BASE, "(objectclass=*)", ldbm_config_modify_entry_callback,
  1104. (void *) li);
  1105. slapi_config_register_callback(DSE_OPERATION_WRITE, DSE_FLAG_PREOP, dn,
  1106. LDAP_SCOPE_BASE, "(objectclass=*)", ldbm_config_search_entry_callback,
  1107. (void *) li);
  1108. /* setup the dse callback functions for the ldbm backend monitor entry */
  1109. PR_snprintf(dn, BUFSIZ, "cn=monitor, cn=%s, cn=plugins, cn=config",
  1110. li->li_plugin->plg_name);
  1111. slapi_config_register_callback(SLAPI_OPERATION_SEARCH, DSE_FLAG_PREOP, dn,
  1112. LDAP_SCOPE_BASE, "(objectclass=*)", ldbm_back_monitor_search,
  1113. (void *)li);
  1114. /* And the ldbm backend database monitor entry */
  1115. PR_snprintf(dn, BUFSIZ, "cn=database, cn=monitor, cn=%s, cn=plugins, cn=config",
  1116. li->li_plugin->plg_name);
  1117. slapi_config_register_callback(SLAPI_OPERATION_SEARCH, DSE_FLAG_PREOP, dn,
  1118. LDAP_SCOPE_BASE, "(objectclass=*)", ldbm_back_dbmonitor_search,
  1119. (void *)li);
  1120. /* setup the dse callback functions for the ldbm backend instance
  1121. * entries */
  1122. PR_snprintf(dn, BUFSIZ, "cn=%s, cn=plugins, cn=config", li->li_plugin->plg_name);
  1123. slapi_config_register_callback(SLAPI_OPERATION_ADD, DSE_FLAG_PREOP, dn,
  1124. LDAP_SCOPE_SUBTREE, "(objectclass=nsBackendInstance)",
  1125. ldbm_instance_add_instance_entry_callback, (void *) li);
  1126. slapi_config_register_callback(SLAPI_OPERATION_ADD, DSE_FLAG_POSTOP, dn,
  1127. LDAP_SCOPE_SUBTREE, "(objectclass=nsBackendInstance)",
  1128. ldbm_instance_postadd_instance_entry_callback, (void *) li);
  1129. slapi_config_register_callback(SLAPI_OPERATION_DELETE, DSE_FLAG_PREOP, dn,
  1130. LDAP_SCOPE_SUBTREE, "(objectclass=nsBackendInstance)",
  1131. ldbm_instance_delete_instance_entry_callback, (void *) li);
  1132. slapi_config_register_callback(SLAPI_OPERATION_DELETE, DSE_FLAG_POSTOP, dn,
  1133. LDAP_SCOPE_SUBTREE, "(objectclass=nsBackendInstance)",
  1134. ldbm_instance_post_delete_instance_entry_callback, (void *) li);
  1135. return 0;
  1136. }
  1137. /* Utility function used in creating config entries. Using the
  1138. * config_info, this function gets info and formats in the correct
  1139. * way.
  1140. * buf is char[BUFSIZ]
  1141. */
  1142. void ldbm_config_get(void *arg, config_info *config, char *buf)
  1143. {
  1144. char *tmp_string;
  1145. size_t val = 0;
  1146. if (config == NULL) {
  1147. buf[0] = '\0';
  1148. }
  1149. switch(config->config_type) {
  1150. case CONFIG_TYPE_INT:
  1151. sprintf(buf, "%d", (int) ((uintptr_t)config->config_get_fn(arg)));
  1152. break;
  1153. case CONFIG_TYPE_INT_OCTAL:
  1154. sprintf(buf, "%o", (int) ((uintptr_t)config->config_get_fn(arg)));
  1155. break;
  1156. case CONFIG_TYPE_LONG:
  1157. sprintf(buf, "%ld", (long) config->config_get_fn(arg));
  1158. break;
  1159. case CONFIG_TYPE_SIZE_T:
  1160. val = (size_t) config->config_get_fn(arg);
  1161. sprintf(buf, "%lu", val);
  1162. break;
  1163. case CONFIG_TYPE_STRING:
  1164. /* Remember the get function for strings returns memory
  1165. * that must be freed. */
  1166. tmp_string = (char *) config->config_get_fn(arg);
  1167. PR_snprintf(buf, BUFSIZ, "%s", (char *) tmp_string);
  1168. slapi_ch_free((void **)&tmp_string);
  1169. break;
  1170. case CONFIG_TYPE_ONOFF:
  1171. if ((int) ((uintptr_t)config->config_get_fn(arg))) {
  1172. sprintf(buf, "on");
  1173. } else {
  1174. sprintf(buf, "off");
  1175. }
  1176. break;
  1177. }
  1178. }
  1179. /*
  1180. * Returns:
  1181. * SLAPI_DSE_CALLBACK_ERROR on failure
  1182. * SLAPI_DSE_CALLBACK_OK on success
  1183. */
  1184. int ldbm_config_search_entry_callback(Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Entry *entryAfter, int *returncode, char *returntext, void *arg)
  1185. {
  1186. char buf[BUFSIZ];
  1187. struct berval *vals[2];
  1188. struct berval val;
  1189. struct ldbminfo *li= (struct ldbminfo *) arg;
  1190. config_info *config;
  1191. vals[0] = &val;
  1192. vals[1] = NULL;
  1193. returntext[0] = '\0';
  1194. PR_Lock(li->li_config_mutex);
  1195. for(config = ldbm_config; config->config_name != NULL; config++) {
  1196. /* Go through the ldbm_config table and fill in the entry. */
  1197. if (!(config->config_flags & (CONFIG_FLAG_ALWAYS_SHOW | CONFIG_FLAG_PREVIOUSLY_SET))) {
  1198. /* This config option shouldn't be shown */
  1199. continue;
  1200. }
  1201. ldbm_config_get((void *) li, config, buf);
  1202. val.bv_val = buf;
  1203. val.bv_len = strlen(buf);
  1204. slapi_entry_attr_replace(e, config->config_name, vals);
  1205. }
  1206. PR_Unlock(li->li_config_mutex);
  1207. *returncode = LDAP_SUCCESS;
  1208. return SLAPI_DSE_CALLBACK_OK;
  1209. }
  1210. int ldbm_config_ignored_attr(char *attr_name)
  1211. {
  1212. /* These are the names of attributes that are in the
  1213. * config entries but are not config attributes. */
  1214. if (!strcasecmp("objectclass", attr_name) ||
  1215. !strcasecmp("cn", attr_name) ||
  1216. !strcasecmp("creatorsname", attr_name) ||
  1217. !strcasecmp("modifiersname", attr_name) ||
  1218. !strcasecmp("createtimestamp", attr_name) ||
  1219. !strcasecmp("numsubordinates", attr_name) ||
  1220. !strcasecmp("modifytimestamp", attr_name)) {
  1221. return 1;
  1222. } else {
  1223. return 0;
  1224. }
  1225. }
  1226. /* Returns LDAP_SUCCESS on success */
  1227. int ldbm_config_set(void *arg, char *attr_name, config_info *config_array, struct berval *bval, char *err_buf, int phase, int apply_mod)
  1228. {
  1229. config_info *config;
  1230. int use_default;
  1231. int int_val;
  1232. long long_val;
  1233. size_t sz_val;
  1234. PRInt64 llval;
  1235. int maxint = (int)(((unsigned int)~0)>>1);
  1236. int minint = ~maxint;
  1237. PRInt64 llmaxint;
  1238. PRInt64 llminint;
  1239. int err = 0;
  1240. char *str_val;
  1241. int retval = 0;
  1242. LL_I2L(llmaxint, maxint);
  1243. LL_I2L(llminint, minint);
  1244. config = get_config_info(config_array, attr_name);
  1245. if (NULL == config) {
  1246. LDAPDebug(LDAP_DEBUG_CONFIG, "Unknown config attribute %s\n", attr_name, 0, 0);
  1247. PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Unknown config attribute %s\n", attr_name);
  1248. return LDAP_SUCCESS; /* Ignore unknown attributes */
  1249. }
  1250. /* Some config attrs can't be changed while the server is running. */
  1251. if (phase == CONFIG_PHASE_RUNNING &&
  1252. !(config->config_flags & CONFIG_FLAG_ALLOW_RUNNING_CHANGE)) {
  1253. PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "%s can't be modified while the server is running.\n", attr_name);
  1254. LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
  1255. return LDAP_UNWILLING_TO_PERFORM;
  1256. }
  1257. /* If the config phase is initialization or if bval is NULL, we will use
  1258. * the default value for the attribute. */
  1259. if (CONFIG_PHASE_INITIALIZATION == phase || NULL == bval) {
  1260. if (CONFIG_FLAG_SKIP_DEFAULT_SETTING & config->config_flags) {
  1261. return LDAP_SUCCESS; /* Skipping the default config setting */
  1262. }
  1263. use_default = 1;
  1264. } else {
  1265. use_default = 0;
  1266. /* Since we are setting the value for the config attribute, we
  1267. * need to turn on the CONFIG_FLAG_PREVIOUSLY_SET flag to make
  1268. * sure this attribute is shown. */
  1269. config->config_flags |= CONFIG_FLAG_PREVIOUSLY_SET;
  1270. }
  1271. switch(config->config_type) {
  1272. case CONFIG_TYPE_INT:
  1273. if (use_default) {
  1274. str_val = config->config_default_value;
  1275. } else {
  1276. str_val = bval->bv_val;
  1277. }
  1278. /* get the value as a 64 bit value */
  1279. llval = db_atoi(str_val, &err);
  1280. /* check for parsing error (e.g. not a number) */
  1281. if (err) {
  1282. PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is not a number\n",
  1283. str_val, attr_name);
  1284. LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
  1285. return LDAP_UNWILLING_TO_PERFORM;
  1286. /* check for overflow */
  1287. } else if (LL_CMP(llval, >, llmaxint)) {
  1288. PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is greater than the maximum %d\n",
  1289. str_val, attr_name, maxint);
  1290. LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
  1291. return LDAP_UNWILLING_TO_PERFORM;
  1292. /* check for underflow */
  1293. } else if (LL_CMP(llval, <, llminint)) {
  1294. PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is less than the minimum %d\n",
  1295. str_val, attr_name, minint);
  1296. LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
  1297. return LDAP_UNWILLING_TO_PERFORM;
  1298. }
  1299. /* convert 64 bit value to 32 bit value */
  1300. LL_L2I(int_val, llval);
  1301. retval = config->config_set_fn(arg, (void *) ((uintptr_t)int_val), err_buf, phase, apply_mod);
  1302. break;
  1303. case CONFIG_TYPE_INT_OCTAL:
  1304. if (use_default) {
  1305. int_val = (int) strtol(config->config_default_value, NULL, 8);
  1306. } else {
  1307. int_val = (int) strtol((char *)bval->bv_val, NULL, 8);
  1308. }
  1309. retval = config->config_set_fn(arg, (void *) ((uintptr_t)int_val), err_buf, phase, apply_mod);
  1310. break;
  1311. case CONFIG_TYPE_LONG:
  1312. if (use_default) {
  1313. str_val = config->config_default_value;
  1314. } else {
  1315. str_val = bval->bv_val;
  1316. }
  1317. /* get the value as a 64 bit value */
  1318. llval = db_atoi(str_val, &err);
  1319. /* check for parsing error (e.g. not a number) */
  1320. if (err) {
  1321. PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is not a number\n",
  1322. str_val, attr_name);
  1323. LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
  1324. return LDAP_UNWILLING_TO_PERFORM;
  1325. /* check for overflow */
  1326. } else if (LL_CMP(llval, >, llmaxint)) {
  1327. PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is greater than the maximum %d\n",
  1328. str_val, attr_name, maxint);
  1329. LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
  1330. return LDAP_UNWILLING_TO_PERFORM;
  1331. /* check for underflow */
  1332. } else if (LL_CMP(llval, <, llminint)) {
  1333. PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is less than the minimum %d\n",
  1334. str_val, attr_name, minint);
  1335. LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
  1336. return LDAP_UNWILLING_TO_PERFORM;
  1337. }
  1338. /* convert 64 bit value to 32 bit value */
  1339. LL_L2I(long_val, llval);
  1340. retval = config->config_set_fn(arg, (void *) long_val, err_buf, phase, apply_mod);
  1341. break;
  1342. case CONFIG_TYPE_SIZE_T:
  1343. if (use_default) {
  1344. str_val = config->config_default_value;
  1345. } else {
  1346. str_val = bval->bv_val;
  1347. }
  1348. /* get the value as a size_t value */
  1349. sz_val = db_strtoul(str_val, &err);
  1350. /* check for parsing error (e.g. not a number) */
  1351. if (err == EINVAL) {
  1352. PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is not a number\n",
  1353. str_val, attr_name);
  1354. LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
  1355. return LDAP_UNWILLING_TO_PERFORM;
  1356. /* check for overflow */
  1357. } else if (err == ERANGE) {
  1358. PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is outside the range of representable values\n",
  1359. str_val, attr_name);
  1360. LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
  1361. return LDAP_UNWILLING_TO_PERFORM;
  1362. }
  1363. retval = config->config_set_fn(arg, (void *) sz_val, err_buf, phase, apply_mod);
  1364. break;
  1365. case CONFIG_TYPE_STRING:
  1366. if (use_default) {
  1367. retval = config->config_set_fn(arg, config->config_default_value, err_buf, phase, apply_mod);
  1368. } else {
  1369. retval = config->config_set_fn(arg, bval->bv_val, err_buf, phase, apply_mod);
  1370. }
  1371. break;
  1372. case CONFIG_TYPE_ONOFF:
  1373. if (use_default) {
  1374. int_val = !strcasecmp(config->config_default_value, "on");
  1375. } else {
  1376. int_val = !strcasecmp((char *) bval->bv_val, "on");
  1377. }
  1378. retval = config->config_set_fn(arg, (void *) ((uintptr_t)int_val), err_buf, phase, apply_mod);
  1379. break;
  1380. }
  1381. return retval;
  1382. }
  1383. static int parse_ldbm_config_entry(struct ldbminfo *li, Slapi_Entry *e, config_info *config_array)
  1384. {
  1385. Slapi_Attr *attr = NULL;
  1386. for (slapi_entry_first_attr(e, &attr); attr; slapi_entry_next_attr(e, attr, &attr)) {
  1387. char *attr_name = NULL;
  1388. Slapi_Value *sval = NULL;
  1389. struct berval *bval;
  1390. char err_buf[SLAPI_DSE_RETURNTEXT_SIZE];
  1391. slapi_attr_get_type(attr, &attr_name);
  1392. /* There are some attributes that we don't care about, like objectclass. */
  1393. if (ldbm_config_ignored_attr(attr_name)) {
  1394. continue;
  1395. }
  1396. slapi_attr_first_value(attr, &sval);
  1397. bval = (struct berval *) slapi_value_get_berval(sval);
  1398. if (ldbm_config_set(li, attr_name, config_array, bval, err_buf, CONFIG_PHASE_STARTUP, 1 /* apply */) != LDAP_SUCCESS) {
  1399. LDAPDebug(LDAP_DEBUG_ANY, "Error with config attribute %s : %s\n", attr_name, err_buf, 0);
  1400. return 1;
  1401. }
  1402. }
  1403. return 0;
  1404. }
  1405. /*
  1406. * Returns:
  1407. * SLAPI_DSE_CALLBACK_ERROR on failure
  1408. * SLAPI_DSE_CALLBACK_OK on success
  1409. */
  1410. int ldbm_config_modify_entry_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* e, int *returncode, char *returntext, void *arg)
  1411. {
  1412. int i;
  1413. char *attr_name;
  1414. LDAPMod **mods;
  1415. int rc = LDAP_SUCCESS;
  1416. int apply_mod = 0;
  1417. struct ldbminfo *li= (struct ldbminfo *) arg;
  1418. /* This lock is probably way too conservative, but we don't expect much
  1419. * contention for it. */
  1420. PR_Lock(li->li_config_mutex);
  1421. slapi_pblock_get( pb, SLAPI_MODIFY_MODS, &mods );
  1422. returntext[0] = '\0';
  1423. /*
  1424. * First pass: set apply mods to 0 so only input validation will be done;
  1425. * 2nd pass: set apply mods to 1 to apply changes to internal storage
  1426. */
  1427. for ( apply_mod = 0; apply_mod <= 1 && LDAP_SUCCESS == rc; apply_mod++ ) {
  1428. for (i = 0; mods[i] && LDAP_SUCCESS == rc; i++) {
  1429. attr_name = mods[i]->mod_type;
  1430. /* There are some attributes that we don't care about, like modifiersname. */
  1431. if (ldbm_config_ignored_attr(attr_name)) {
  1432. continue;
  1433. }
  1434. if (SLAPI_IS_MOD_DELETE(mods[i]->mod_op) ||
  1435. SLAPI_IS_MOD_ADD(mods[i]->mod_op)) {
  1436. rc= LDAP_UNWILLING_TO_PERFORM;
  1437. PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "%s attributes is not allowed",
  1438. (mods[i]->mod_op & LDAP_MOD_DELETE) ? "Deleting" : "Adding");
  1439. } else if (mods[i]->mod_op & LDAP_MOD_REPLACE) {
  1440. /* This assumes there is only one bval for this mod. */
  1441. rc = ldbm_config_set((void *) li, attr_name, ldbm_config,
  1442. ( mods[i]->mod_bvalues == NULL ) ? NULL
  1443. : mods[i]->mod_bvalues[0], returntext,
  1444. ((li->li_flags&LI_FORCE_MOD_CONFIG)?
  1445. CONFIG_PHASE_INTERNAL:CONFIG_PHASE_RUNNING),
  1446. apply_mod);
  1447. }
  1448. }
  1449. }
  1450. PR_Unlock(li->li_config_mutex);
  1451. *returncode= rc;
  1452. if(LDAP_SUCCESS == rc) {
  1453. return SLAPI_DSE_CALLBACK_OK;
  1454. }
  1455. else {
  1456. return SLAPI_DSE_CALLBACK_ERROR;
  1457. }
  1458. }
  1459. /* This function is used to set config attributes. It can be used as a
  1460. * shortcut to doing an internal modify operation on the config DSE.
  1461. */
  1462. void ldbm_config_internal_set(struct ldbminfo *li, char *attrname, char *value)
  1463. {
  1464. char err_buf[SLAPI_DSE_RETURNTEXT_SIZE];
  1465. struct berval bval;
  1466. bval.bv_val = value;
  1467. bval.bv_len = strlen(value);
  1468. if (ldbm_config_set((void *) li, attrname, ldbm_config, &bval,
  1469. err_buf, CONFIG_PHASE_INTERNAL, 1 /* apply */) != LDAP_SUCCESS) {
  1470. LDAPDebug(LDAP_DEBUG_ANY,
  1471. "Internal Error: Error setting instance config attr %s to %s: %s\n",
  1472. attrname, value, err_buf);
  1473. exit(1);
  1474. }
  1475. }
  1476. /*
  1477. * replace_ldbm_config_value:
  1478. * - update an ldbm database config value
  1479. */
  1480. void replace_ldbm_config_value(char *conftype, char *val, struct ldbminfo *li)
  1481. {
  1482. Slapi_PBlock pb;
  1483. Slapi_Mods smods;
  1484. pblock_init(&pb);
  1485. slapi_mods_init(&smods, 1);
  1486. slapi_mods_add(&smods, LDAP_MOD_REPLACE, conftype, strlen(val), val);
  1487. slapi_modify_internal_set_pb(&pb, CONFIG_LDBM_DN,
  1488. slapi_mods_get_ldapmods_byref(&smods),
  1489. NULL, NULL, li->li_identity, 0);
  1490. slapi_modify_internal_pb(&pb);
  1491. slapi_mods_done(&smods);
  1492. pblock_done(&pb);
  1493. }