ldbm_config.c 63 KB

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