ldbm_config.c 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913
  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. PL_strncpyz(ebuf, slapi_entry_get_dn_const(e), sizeof(ebuf)); /* 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 > -1) && (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_entryrdn_switch_get(void *arg)
  828. {
  829. return (void *)((uintptr_t)entryrdn_get_switch());
  830. }
  831. static int ldbm_config_entryrdn_switch_set(void *arg, void *value,
  832. char *errorbuf, int phase, int apply)
  833. {
  834. if (apply) {
  835. entryrdn_set_switch((int)((uintptr_t)value));
  836. }
  837. return LDAP_SUCCESS;
  838. }
  839. static void *ldbm_config_entryrdn_noancestorid_get(void *arg)
  840. {
  841. return (void *)((uintptr_t)entryrdn_get_noancestorid());
  842. }
  843. static int ldbm_config_entryrdn_noancestorid_set(void *arg, void *value,
  844. char *errorbuf, int phase, int apply)
  845. {
  846. if (apply) {
  847. entryrdn_set_noancestorid((int)((uintptr_t)value));
  848. }
  849. return LDAP_SUCCESS;
  850. }
  851. static void *ldbm_config_legacy_errcode_get(void *arg)
  852. {
  853. struct ldbminfo *li = (struct ldbminfo *) arg;
  854. return (void *) ((uintptr_t)li->li_legacy_errcode);
  855. }
  856. static int ldbm_config_legacy_errcode_set(void *arg, void *value, char *errorbuf,
  857. int phase, int apply)
  858. {
  859. struct ldbminfo *li = (struct ldbminfo *) arg;
  860. if (apply) {
  861. li->li_legacy_errcode = (int) ((uintptr_t)value);
  862. }
  863. return LDAP_SUCCESS;
  864. }
  865. static int
  866. ldbm_config_set_bypass_filter_test(void *arg, void *value, char *errorbuf,
  867. int phase, int apply)
  868. {
  869. struct ldbminfo *li = (struct ldbminfo *)arg;
  870. if (apply) {
  871. char *myvalue = (char *)value;
  872. if (0 == strcasecmp(myvalue, "on")) {
  873. li->li_filter_bypass = 1;
  874. li->li_filter_bypass_check = 0;
  875. } else if (0 == strcasecmp(myvalue, "verify")) {
  876. li->li_filter_bypass = 1;
  877. li->li_filter_bypass_check = 1;
  878. } else {
  879. li->li_filter_bypass = 0;
  880. li->li_filter_bypass_check = 0;
  881. }
  882. }
  883. return LDAP_SUCCESS;
  884. }
  885. static void *ldbm_config_get_bypass_filter_test(void *arg)
  886. {
  887. struct ldbminfo *li = (struct ldbminfo *)arg;
  888. char *retstr = NULL;
  889. if (li->li_filter_bypass) {
  890. if (li->li_filter_bypass_check) {
  891. /* meaningful only if is bypass filter test called */
  892. retstr = slapi_ch_strdup("verify");
  893. } else {
  894. retstr = slapi_ch_strdup("on");
  895. }
  896. } else {
  897. retstr = slapi_ch_strdup("off");
  898. }
  899. return (void *)retstr;
  900. }
  901. static int ldbm_config_set_use_vlv_index(void *arg, void *value, char *errorbuf, int phase, int apply)
  902. {
  903. struct ldbminfo *li = (struct ldbminfo *) arg;
  904. int val = (int) ((uintptr_t)value);
  905. if (apply) {
  906. if (val) {
  907. li->li_use_vlv = 1;
  908. } else {
  909. li->li_use_vlv = 0;
  910. }
  911. }
  912. return LDAP_SUCCESS;
  913. }
  914. static void *ldbm_config_get_use_vlv_index(void *arg)
  915. {
  916. struct ldbminfo *li = (struct ldbminfo *) arg;
  917. return (void *) ((uintptr_t)li->li_use_vlv);
  918. }
  919. static int
  920. ldbm_config_exclude_from_export_set( void *arg, void *value, char *errorbuf,
  921. int phase, int apply)
  922. {
  923. struct ldbminfo *li = (struct ldbminfo *)arg;
  924. if ( apply ) {
  925. if ( NULL != li->li_attrs_to_exclude_from_export ) {
  926. charray_free( li->li_attrs_to_exclude_from_export );
  927. li->li_attrs_to_exclude_from_export = NULL;
  928. }
  929. if ( NULL != value ) {
  930. char *dupvalue = slapi_ch_strdup( value );
  931. li->li_attrs_to_exclude_from_export = slapi_str2charray( dupvalue, " " );
  932. slapi_ch_free((void**)&dupvalue);
  933. }
  934. }
  935. return LDAP_SUCCESS;
  936. }
  937. static void *
  938. ldbm_config_exclude_from_export_get( void *arg )
  939. {
  940. struct ldbminfo *li = (struct ldbminfo *)arg;
  941. char *p, *retstr = NULL;
  942. size_t len = 0;
  943. if ( NULL != li->li_attrs_to_exclude_from_export &&
  944. NULL != li->li_attrs_to_exclude_from_export[0] ) {
  945. int i;
  946. for ( i = 0; li->li_attrs_to_exclude_from_export[i] != NULL; ++i ) {
  947. len += strlen( li->li_attrs_to_exclude_from_export[i] ) + 1;
  948. }
  949. p = retstr = slapi_ch_malloc( len );
  950. for ( i = 0; li->li_attrs_to_exclude_from_export[i] != NULL; ++i ) {
  951. if ( i > 0 ) {
  952. *p++ = ' ';
  953. }
  954. strcpy( p, li->li_attrs_to_exclude_from_export[i] );
  955. p += strlen( p );
  956. }
  957. *p = '\0';
  958. } else {
  959. retstr = slapi_ch_strdup( "" );
  960. }
  961. return (void *)retstr;
  962. }
  963. static void *ldbm_config_db_tx_max_get(void *arg)
  964. {
  965. struct ldbminfo *li = (struct ldbminfo *) arg;
  966. return (void *) ((uintptr_t)li->li_dblayer_private->dblayer_tx_max);
  967. }
  968. static int ldbm_config_db_tx_max_set(
  969. void *arg,
  970. void *value,
  971. char *errorbuf,
  972. int phase,
  973. int apply
  974. )
  975. {
  976. struct ldbminfo *li = (struct ldbminfo *) arg;
  977. int retval = LDAP_SUCCESS;
  978. int val = (int) ((uintptr_t)value);
  979. if (apply) {
  980. li->li_dblayer_private->dblayer_tx_max = val;
  981. }
  982. return retval;
  983. }
  984. /*------------------------------------------------------------------------
  985. * Configuration array for ldbm and dblayer variables
  986. *----------------------------------------------------------------------*/
  987. static config_info ldbm_config[] = {
  988. {CONFIG_LOOKTHROUGHLIMIT, CONFIG_TYPE_INT, "5000", &ldbm_config_lookthroughlimit_get, &ldbm_config_lookthroughlimit_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
  989. {CONFIG_MODE, CONFIG_TYPE_INT_OCTAL, "0600", &ldbm_config_mode_get, &ldbm_config_mode_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
  990. {CONFIG_IDLISTSCANLIMIT, CONFIG_TYPE_INT, "4000", &ldbm_config_allidsthreshold_get, &ldbm_config_allidsthreshold_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
  991. {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},
  992. {CONFIG_DBCACHESIZE, CONFIG_TYPE_SIZE_T, "10000000", &ldbm_config_dbcachesize_get, &ldbm_config_dbcachesize_set, CONFIG_FLAG_ALWAYS_SHOW|CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
  993. {CONFIG_DBNCACHE, CONFIG_TYPE_INT, "0", &ldbm_config_dbncache_get, &ldbm_config_dbncache_set, CONFIG_FLAG_ALLOW_RUNNING_CHANGE},
  994. {CONFIG_MAXPASSBEFOREMERGE, CONFIG_TYPE_INT, "100", &ldbm_config_maxpassbeforemerge_get, &ldbm_config_maxpassbeforemerge_set, 0},
  995. /* dblayer config attributes */
  996. {CONFIG_DB_LOGDIRECTORY, CONFIG_TYPE_STRING, "", &ldbm_config_db_logdirectory_get, &ldbm_config_db_logdirectory_set, CONFIG_FLAG_ALWAYS_SHOW},
  997. {CONFIG_DB_DURABLE_TRANSACTIONS, CONFIG_TYPE_ONOFF, "on", &ldbm_config_db_durable_transactions_get, &ldbm_config_db_durable_transactions_set, CONFIG_FLAG_ALWAYS_SHOW},
  998. {CONFIG_DB_CIRCULAR_LOGGING, CONFIG_TYPE_ONOFF, "on", &ldbm_config_db_circular_logging_get, &ldbm_config_db_circular_logging_set, 0},
  999. {CONFIG_DB_TRANSACTION_LOGGING, CONFIG_TYPE_ONOFF, "on", &ldbm_config_db_transaction_logging_get, &ldbm_config_db_transaction_logging_set, 0},
  1000. {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},
  1001. {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},
  1002. {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},
  1003. {CONFIG_DB_PAGE_SIZE, CONFIG_TYPE_SIZE_T, "0", &ldbm_config_db_page_size_get, &ldbm_config_db_page_size_set, 0},
  1004. {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},
  1005. {CONFIG_DB_IDL_DIVISOR, CONFIG_TYPE_INT, "0", &ldbm_config_db_idl_divisor_get, &ldbm_config_db_idl_divisor_set, 0},
  1006. {CONFIG_DB_LOGFILE_SIZE, CONFIG_TYPE_SIZE_T, "0", &ldbm_config_db_logfile_size_get, &ldbm_config_db_logfile_size_set, 0},
  1007. {CONFIG_DB_TRICKLE_PERCENTAGE, CONFIG_TYPE_INT, "5", &ldbm_config_db_trickle_percentage_get, &ldbm_config_db_trickle_percentage_set, 0},
  1008. {CONFIG_DB_SPIN_COUNT, CONFIG_TYPE_INT, "0", &ldbm_config_db_spin_count_get, &ldbm_config_db_spin_count_set, 0},
  1009. {CONFIG_DB_VERBOSE, CONFIG_TYPE_ONOFF, "off", &ldbm_config_db_verbose_get, &ldbm_config_db_verbose_set, 0},
  1010. {CONFIG_DB_DEBUG, CONFIG_TYPE_ONOFF, "on", &ldbm_config_db_debug_get, &ldbm_config_db_debug_set, 0},
  1011. {CONFIG_DB_NAMED_REGIONS, CONFIG_TYPE_ONOFF, "off", &ldbm_config_db_named_regions_get, &ldbm_config_db_named_regions_set, 0},
  1012. {CONFIG_DB_LOCK, CONFIG_TYPE_INT, "10000", &ldbm_config_db_lock_get, &ldbm_config_db_lock_set, 0},
  1013. {CONFIG_DB_PRIVATE_MEM, CONFIG_TYPE_ONOFF, "off", &ldbm_config_db_private_mem_get, &ldbm_config_db_private_mem_set, 0},
  1014. {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},
  1015. {CONFIG_DB_SHM_KEY, CONFIG_TYPE_LONG, "389389", &ldbm_config_db_shm_key_get, &ldbm_config_db_shm_key_set, 0},
  1016. {CONFIG_DB_CACHE, CONFIG_TYPE_INT, "0", &ldbm_config_db_cache_get, &ldbm_config_db_cache_set, 0},
  1017. {CONFIG_DB_DEBUG_CHECKPOINTING, CONFIG_TYPE_ONOFF, "off", &ldbm_config_db_debug_checkpointing_get, &ldbm_config_db_debug_checkpointing_set, 0},
  1018. {CONFIG_DB_HOME_DIRECTORY, CONFIG_TYPE_STRING, "", &ldbm_config_db_home_directory_get, &ldbm_config_db_home_directory_set, 0},
  1019. {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},
  1020. {CONFIG_CACHE_AUTOSIZE, CONFIG_TYPE_INT, "0", &ldbm_config_cache_autosize_get, &ldbm_config_cache_autosize_set, 0},
  1021. {CONFIG_CACHE_AUTOSIZE_SPLIT, CONFIG_TYPE_INT, "50", &ldbm_config_cache_autosize_split_get, &ldbm_config_cache_autosize_split_set, 0},
  1022. {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},
  1023. {CONFIG_IDL_SWITCH, CONFIG_TYPE_STRING, "new", &ldbm_config_idl_get_idl_new, &ldbm_config_idl_set_tune, CONFIG_FLAG_ALWAYS_SHOW},
  1024. {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},
  1025. {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},
  1026. {CONFIG_DB_LOCKDOWN, CONFIG_TYPE_ONOFF, "off", &ldbm_config_db_lockdown_get, &ldbm_config_db_lockdown_set, 0},
  1027. {CONFIG_INDEX_BUFFER_SIZE, CONFIG_TYPE_INT, "0", &ldbm_config_index_buffer_size_get, &ldbm_config_index_buffer_size_set, 0},
  1028. {CONFIG_EXCLUDE_FROM_EXPORT, CONFIG_TYPE_STRING,
  1029. CONFIG_EXCLUDE_FROM_EXPORT_DEFAULT_VALUE,
  1030. &ldbm_config_exclude_from_export_get,
  1031. &ldbm_config_exclude_from_export_set, CONFIG_FLAG_ALWAYS_SHOW},
  1032. {CONFIG_DB_TX_MAX, CONFIG_TYPE_INT, "200", &ldbm_config_db_tx_max_get, &ldbm_config_db_tx_max_set, 0},
  1033. {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},
  1034. {CONFIG_USE_LEGACY_ERRORCODE, CONFIG_TYPE_ONOFF, "off", &ldbm_config_legacy_errcode_get, &ldbm_config_legacy_errcode_set, 0},
  1035. {CONFIG_ENTRYRDN_SWITCH, CONFIG_TYPE_ONOFF, "on", &ldbm_config_entryrdn_switch_get, &ldbm_config_entryrdn_switch_set, CONFIG_FLAG_ALWAYS_SHOW},
  1036. {CONFIG_ENTRYRDN_NOANCESTORID, CONFIG_TYPE_ONOFF, "off", &ldbm_config_entryrdn_noancestorid_get, &ldbm_config_entryrdn_noancestorid_set, 0 /* no show */},
  1037. {NULL, 0, NULL, NULL, NULL, 0}
  1038. };
  1039. void ldbm_config_setup_default(struct ldbminfo *li)
  1040. {
  1041. config_info *config;
  1042. char err_buf[SLAPI_DSE_RETURNTEXT_SIZE];
  1043. for (config = ldbm_config; config->config_name != NULL; config++) {
  1044. ldbm_config_set((void *)li, config->config_name, ldbm_config, NULL /* use default */, err_buf, CONFIG_PHASE_INITIALIZATION, 1 /* apply */, LDAP_MOD_REPLACE);
  1045. }
  1046. }
  1047. void
  1048. ldbm_config_read_instance_entries(struct ldbminfo *li, const char *backend_type)
  1049. {
  1050. Slapi_PBlock *tmp_pb;
  1051. Slapi_Entry **entries = NULL;
  1052. char *basedn = NULL;
  1053. /* Construct the base dn of the subtree that holds the instance entries. */
  1054. basedn = slapi_create_dn_string("cn=%s,cn=plugins,cn=config", backend_type);
  1055. if (NULL == basedn) {
  1056. LDAPDebug1Arg(LDAP_DEBUG_ANY,
  1057. "ldbm_config_read_instance_entries: "
  1058. "failed create backend dn for %s\n", backend_type);
  1059. return;
  1060. }
  1061. /* Do a search of the subtree containing the instance entries */
  1062. tmp_pb = slapi_pblock_new();
  1063. slapi_search_internal_set_pb(tmp_pb, basedn, LDAP_SCOPE_SUBTREE, "(objectclass=nsBackendInstance)", NULL, 0, NULL, NULL, li->li_identity, 0);
  1064. slapi_search_internal_pb (tmp_pb);
  1065. slapi_pblock_get(tmp_pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries);
  1066. if (entries!=NULL) {
  1067. int i;
  1068. for (i=0; entries[i]!=NULL; i++) {
  1069. ldbm_instance_add_instance_entry_callback(NULL, entries[i], NULL, NULL, NULL, li);
  1070. }
  1071. }
  1072. slapi_free_search_results_internal(tmp_pb);
  1073. slapi_pblock_destroy(tmp_pb);
  1074. slapi_ch_free_string(&basedn);
  1075. }
  1076. /* Reads in any config information held in the dse for the ldbm plugin.
  1077. * Creates dse entries used to configure the ldbm plugin and dblayer
  1078. * if they don't already exist. Registers dse callback functions to
  1079. * maintain those dse entries. Returns 0 on success.
  1080. */
  1081. int ldbm_config_load_dse_info(struct ldbminfo *li)
  1082. {
  1083. Slapi_PBlock *search_pb;
  1084. Slapi_Entry **entries = NULL;
  1085. char *dn = NULL;
  1086. int rval = 0;
  1087. /* We try to read the entry
  1088. * cn=config, cn=ldbm database, cn=plugins, cn=config. If the entry is
  1089. * there, then we process the config information it stores.
  1090. */
  1091. dn = slapi_create_dn_string("cn=config,cn=%s,cn=plugins,cn=config",
  1092. li->li_plugin->plg_name);
  1093. if (NULL == dn) {
  1094. LDAPDebug1Arg(LDAP_DEBUG_ANY,
  1095. "ldbm_config_load_dse_info: "
  1096. "failed create config dn for %s\n",
  1097. li->li_plugin->plg_name);
  1098. rval = 1;
  1099. goto bail;
  1100. }
  1101. search_pb = slapi_pblock_new();
  1102. if (!search_pb) {
  1103. LDAPDebug(LDAP_DEBUG_ANY,
  1104. "ldbm_config_load_dse_info: Out of memory\n",
  1105. 0, 0, 0);
  1106. rval = 1;
  1107. goto bail;
  1108. }
  1109. slapi_search_internal_set_pb(search_pb, dn, LDAP_SCOPE_BASE,
  1110. "objectclass=*", NULL, 0, NULL, NULL, li->li_identity, 0);
  1111. slapi_search_internal_pb (search_pb);
  1112. slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_RESULT, &rval);
  1113. if (LDAP_NO_SUCH_OBJECT == rval) {
  1114. /* Add skeleten dse entries for the ldbm plugin */
  1115. ldbm_config_add_dse_entries(li, ldbm_skeleton_entries,
  1116. li->li_plugin->plg_name, NULL, NULL, 0);
  1117. } else if (rval != LDAP_SUCCESS) {
  1118. LDAPDebug(LDAP_DEBUG_ANY, "Error accessing the ldbm config DSE\n",
  1119. 0, 0, 0);
  1120. rval = 1;
  1121. goto bail;
  1122. } else {
  1123. /* Need to parse the configuration information for the ldbm
  1124. * plugin that is held in the DSE. */
  1125. slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES,
  1126. &entries);
  1127. if (NULL == entries || entries[0] == NULL) {
  1128. LDAPDebug(LDAP_DEBUG_ANY, "Error accessing the ldbm config DSE\n",
  1129. 0, 0, 0);
  1130. rval = 1;
  1131. goto bail;
  1132. }
  1133. if (0 != parse_ldbm_config_entry(li, entries[0], ldbm_config)) {
  1134. LDAPDebug(LDAP_DEBUG_ANY, "Error parsing the ldbm config DSE\n",
  1135. 0, 0, 0);
  1136. rval = 1;
  1137. goto bail;
  1138. }
  1139. }
  1140. if (search_pb) {
  1141. slapi_free_search_results_internal(search_pb);
  1142. slapi_pblock_destroy(search_pb);
  1143. }
  1144. /* Find all the instance entries and create a Slapi_Backend and an
  1145. * ldbm_instance for each */
  1146. ldbm_config_read_instance_entries(li, li->li_plugin->plg_name);
  1147. /* setup the dse callback functions for the ldbm backend config entry */
  1148. slapi_config_register_callback(SLAPI_OPERATION_SEARCH, DSE_FLAG_PREOP, dn,
  1149. LDAP_SCOPE_BASE, "(objectclass=*)", ldbm_config_search_entry_callback,
  1150. (void *) li);
  1151. slapi_config_register_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_PREOP, dn,
  1152. LDAP_SCOPE_BASE, "(objectclass=*)", ldbm_config_modify_entry_callback,
  1153. (void *) li);
  1154. slapi_config_register_callback(DSE_OPERATION_WRITE, DSE_FLAG_PREOP, dn,
  1155. LDAP_SCOPE_BASE, "(objectclass=*)", ldbm_config_search_entry_callback,
  1156. (void *) li);
  1157. slapi_ch_free_string(&dn);
  1158. /* setup the dse callback functions for the ldbm backend monitor entry */
  1159. dn = slapi_create_dn_string("cn=monitor,cn=%s,cn=plugins,cn=config",
  1160. li->li_plugin->plg_name);
  1161. if (NULL == dn) {
  1162. LDAPDebug1Arg(LDAP_DEBUG_ANY,
  1163. "ldbm_config_load_dse_info: "
  1164. "failed create monitor dn for %s\n",
  1165. li->li_plugin->plg_name);
  1166. rval = 1;
  1167. goto bail;
  1168. }
  1169. slapi_config_register_callback(SLAPI_OPERATION_SEARCH, DSE_FLAG_PREOP, dn,
  1170. LDAP_SCOPE_BASE, "(objectclass=*)", ldbm_back_monitor_search,
  1171. (void *)li);
  1172. slapi_ch_free_string(&dn);
  1173. /* And the ldbm backend database monitor entry */
  1174. dn = slapi_create_dn_string("cn=database,cn=monitor,cn=%s,cn=plugins,cn=config",
  1175. li->li_plugin->plg_name);
  1176. if (NULL == dn) {
  1177. LDAPDebug1Arg(LDAP_DEBUG_ANY,
  1178. "ldbm_config_load_dse_info: "
  1179. "failed create monitor database dn for %s\n",
  1180. li->li_plugin->plg_name);
  1181. rval = 1;
  1182. goto bail;
  1183. }
  1184. slapi_config_register_callback(SLAPI_OPERATION_SEARCH, DSE_FLAG_PREOP, dn,
  1185. LDAP_SCOPE_BASE, "(objectclass=*)", ldbm_back_dbmonitor_search,
  1186. (void *)li);
  1187. slapi_ch_free_string(&dn);
  1188. /* setup the dse callback functions for the ldbm backend instance
  1189. * entries */
  1190. dn = slapi_create_dn_string("cn=%s,cn=plugins,cn=config",
  1191. li->li_plugin->plg_name);
  1192. if (NULL == dn) {
  1193. LDAPDebug1Arg(LDAP_DEBUG_ANY,
  1194. "ldbm_config_load_dse_info: "
  1195. "failed create plugin dn for %s\n",
  1196. li->li_plugin->plg_name);
  1197. rval = 1;
  1198. goto bail;
  1199. }
  1200. slapi_config_register_callback(SLAPI_OPERATION_ADD, DSE_FLAG_PREOP, dn,
  1201. LDAP_SCOPE_SUBTREE, "(objectclass=nsBackendInstance)",
  1202. ldbm_instance_add_instance_entry_callback, (void *) li);
  1203. slapi_config_register_callback(SLAPI_OPERATION_ADD, DSE_FLAG_POSTOP, dn,
  1204. LDAP_SCOPE_SUBTREE, "(objectclass=nsBackendInstance)",
  1205. ldbm_instance_postadd_instance_entry_callback, (void *) li);
  1206. slapi_config_register_callback(SLAPI_OPERATION_DELETE, DSE_FLAG_PREOP, dn,
  1207. LDAP_SCOPE_SUBTREE, "(objectclass=nsBackendInstance)",
  1208. ldbm_instance_delete_instance_entry_callback, (void *) li);
  1209. slapi_config_register_callback(SLAPI_OPERATION_DELETE, DSE_FLAG_POSTOP, dn,
  1210. LDAP_SCOPE_SUBTREE, "(objectclass=nsBackendInstance)",
  1211. ldbm_instance_post_delete_instance_entry_callback, (void *) li);
  1212. bail:
  1213. slapi_ch_free_string(&dn);
  1214. return rval;
  1215. }
  1216. /* Utility function used in creating config entries. Using the
  1217. * config_info, this function gets info and formats in the correct
  1218. * way.
  1219. * buf is char[BUFSIZ]
  1220. */
  1221. void ldbm_config_get(void *arg, config_info *config, char *buf)
  1222. {
  1223. char *tmp_string;
  1224. size_t val = 0;
  1225. if (config == NULL) {
  1226. buf[0] = '\0';
  1227. return;
  1228. }
  1229. switch(config->config_type) {
  1230. case CONFIG_TYPE_INT:
  1231. sprintf(buf, "%d", (int) ((uintptr_t)config->config_get_fn(arg)));
  1232. break;
  1233. case CONFIG_TYPE_INT_OCTAL:
  1234. sprintf(buf, "%o", (int) ((uintptr_t)config->config_get_fn(arg)));
  1235. break;
  1236. case CONFIG_TYPE_LONG:
  1237. sprintf(buf, "%ld", (long) config->config_get_fn(arg));
  1238. break;
  1239. case CONFIG_TYPE_SIZE_T:
  1240. val = (size_t) config->config_get_fn(arg);
  1241. sprintf(buf, "%lu", val);
  1242. break;
  1243. case CONFIG_TYPE_STRING:
  1244. /* Remember the get function for strings returns memory
  1245. * that must be freed. */
  1246. tmp_string = (char *) config->config_get_fn(arg);
  1247. PR_snprintf(buf, BUFSIZ, "%s", (char *) tmp_string);
  1248. slapi_ch_free((void **)&tmp_string);
  1249. break;
  1250. case CONFIG_TYPE_ONOFF:
  1251. if ((int) ((uintptr_t)config->config_get_fn(arg))) {
  1252. sprintf(buf, "on");
  1253. } else {
  1254. sprintf(buf, "off");
  1255. }
  1256. break;
  1257. }
  1258. }
  1259. /*
  1260. * Returns:
  1261. * SLAPI_DSE_CALLBACK_ERROR on failure
  1262. * SLAPI_DSE_CALLBACK_OK on success
  1263. */
  1264. int ldbm_config_search_entry_callback(Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Entry *entryAfter, int *returncode, char *returntext, void *arg)
  1265. {
  1266. char buf[BUFSIZ];
  1267. struct berval *vals[2];
  1268. struct berval val;
  1269. struct ldbminfo *li= (struct ldbminfo *) arg;
  1270. config_info *config;
  1271. vals[0] = &val;
  1272. vals[1] = NULL;
  1273. returntext[0] = '\0';
  1274. PR_Lock(li->li_config_mutex);
  1275. for(config = ldbm_config; config->config_name != NULL; config++) {
  1276. /* Go through the ldbm_config table and fill in the entry. */
  1277. if (!(config->config_flags & (CONFIG_FLAG_ALWAYS_SHOW | CONFIG_FLAG_PREVIOUSLY_SET))) {
  1278. /* This config option shouldn't be shown */
  1279. continue;
  1280. }
  1281. ldbm_config_get((void *) li, config, buf);
  1282. val.bv_val = buf;
  1283. val.bv_len = strlen(buf);
  1284. slapi_entry_attr_replace(e, config->config_name, vals);
  1285. }
  1286. PR_Unlock(li->li_config_mutex);
  1287. *returncode = LDAP_SUCCESS;
  1288. return SLAPI_DSE_CALLBACK_OK;
  1289. }
  1290. int ldbm_config_ignored_attr(char *attr_name)
  1291. {
  1292. /* These are the names of attributes that are in the
  1293. * config entries but are not config attributes. */
  1294. if (!strcasecmp("objectclass", attr_name) ||
  1295. !strcasecmp("cn", attr_name) ||
  1296. !strcasecmp("creatorsname", attr_name) ||
  1297. !strcasecmp("modifiersname", attr_name) ||
  1298. !strcasecmp("createtimestamp", attr_name) ||
  1299. !strcasecmp(LDBM_NUMSUBORDINATES_STR, attr_name) ||
  1300. !strcasecmp("modifytimestamp", attr_name)) {
  1301. return 1;
  1302. } else {
  1303. return 0;
  1304. }
  1305. }
  1306. /* Returns LDAP_SUCCESS on success */
  1307. int ldbm_config_set(void *arg, char *attr_name, config_info *config_array, struct berval *bval, char *err_buf, int phase, int apply_mod, int mod_op)
  1308. {
  1309. config_info *config;
  1310. int use_default;
  1311. int int_val;
  1312. long long_val;
  1313. size_t sz_val;
  1314. PRInt64 llval;
  1315. int maxint = (int)(((unsigned int)~0)>>1);
  1316. int minint = ~maxint;
  1317. PRInt64 llmaxint;
  1318. PRInt64 llminint;
  1319. int err = 0;
  1320. char *str_val;
  1321. int retval = 0;
  1322. LL_I2L(llmaxint, maxint);
  1323. LL_I2L(llminint, minint);
  1324. config = get_config_info(config_array, attr_name);
  1325. if (NULL == config) {
  1326. LDAPDebug(LDAP_DEBUG_CONFIG, "Unknown config attribute %s\n", attr_name, 0, 0);
  1327. PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Unknown config attribute %s\n", attr_name);
  1328. return LDAP_SUCCESS; /* Ignore unknown attributes */
  1329. }
  1330. /* Some config attrs can't be changed while the server is running. */
  1331. if (phase == CONFIG_PHASE_RUNNING &&
  1332. !(config->config_flags & CONFIG_FLAG_ALLOW_RUNNING_CHANGE)) {
  1333. PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "%s can't be modified while the server is running.\n", attr_name);
  1334. LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
  1335. return LDAP_UNWILLING_TO_PERFORM;
  1336. }
  1337. /* If the config phase is initialization or if bval is NULL or if we are deleting
  1338. the value, we will use the default value for the attribute. */
  1339. if ((CONFIG_PHASE_INITIALIZATION == phase) || (NULL == bval) || SLAPI_IS_MOD_DELETE(mod_op)) {
  1340. if (CONFIG_FLAG_SKIP_DEFAULT_SETTING & config->config_flags) {
  1341. return LDAP_SUCCESS; /* Skipping the default config setting */
  1342. }
  1343. use_default = 1;
  1344. } else {
  1345. use_default = 0;
  1346. /* cannot use mod add on a single valued attribute if the attribute was
  1347. previously set to a non-default value */
  1348. if (SLAPI_IS_MOD_ADD(mod_op) && apply_mod &&
  1349. (config->config_flags & CONFIG_FLAG_PREVIOUSLY_SET)) {
  1350. PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE,
  1351. "cannot add a value to single valued attribute %s.\n",
  1352. attr_name);
  1353. return LDAP_OBJECT_CLASS_VIOLATION;
  1354. }
  1355. }
  1356. /* if delete, and a specific value was provided to delete, the existing value must
  1357. match that value, or return LDAP_NO_SUCH_ATTRIBUTE */
  1358. if (SLAPI_IS_MOD_DELETE(mod_op) && bval && bval->bv_len && bval->bv_val) {
  1359. char buf[BUFSIZ];
  1360. ldbm_config_get(arg, config, buf);
  1361. if (PL_strncmp(buf, bval->bv_val, bval->bv_len)) {
  1362. PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE,
  1363. "value [%s] for attribute %s does not match existing value [%s].\n",
  1364. bval->bv_val, attr_name, buf);
  1365. return LDAP_NO_SUCH_ATTRIBUTE;
  1366. }
  1367. }
  1368. switch(config->config_type) {
  1369. case CONFIG_TYPE_INT:
  1370. if (use_default) {
  1371. str_val = config->config_default_value;
  1372. } else {
  1373. str_val = bval->bv_val;
  1374. }
  1375. /* get the value as a 64 bit value */
  1376. llval = db_atoi(str_val, &err);
  1377. /* check for parsing error (e.g. not a number) */
  1378. if (err) {
  1379. PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is not a number\n",
  1380. str_val, attr_name);
  1381. LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
  1382. return LDAP_UNWILLING_TO_PERFORM;
  1383. /* check for overflow */
  1384. } else if (LL_CMP(llval, >, llmaxint)) {
  1385. PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is greater than the maximum %d\n",
  1386. str_val, attr_name, maxint);
  1387. LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
  1388. return LDAP_UNWILLING_TO_PERFORM;
  1389. /* check for underflow */
  1390. } else if (LL_CMP(llval, <, llminint)) {
  1391. PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is less than the minimum %d\n",
  1392. str_val, attr_name, minint);
  1393. LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
  1394. return LDAP_UNWILLING_TO_PERFORM;
  1395. }
  1396. /* convert 64 bit value to 32 bit value */
  1397. LL_L2I(int_val, llval);
  1398. retval = config->config_set_fn(arg, (void *) ((uintptr_t)int_val), err_buf, phase, apply_mod);
  1399. break;
  1400. case CONFIG_TYPE_INT_OCTAL:
  1401. if (use_default) {
  1402. int_val = (int) strtol(config->config_default_value, NULL, 8);
  1403. } else {
  1404. int_val = (int) strtol((char *)bval->bv_val, NULL, 8);
  1405. }
  1406. retval = config->config_set_fn(arg, (void *) ((uintptr_t)int_val), err_buf, phase, apply_mod);
  1407. break;
  1408. case CONFIG_TYPE_LONG:
  1409. if (use_default) {
  1410. str_val = config->config_default_value;
  1411. } else {
  1412. str_val = bval->bv_val;
  1413. }
  1414. /* get the value as a 64 bit value */
  1415. llval = db_atoi(str_val, &err);
  1416. /* check for parsing error (e.g. not a number) */
  1417. if (err) {
  1418. PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is not a number\n",
  1419. str_val, attr_name);
  1420. LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
  1421. return LDAP_UNWILLING_TO_PERFORM;
  1422. /* check for overflow */
  1423. } else if (LL_CMP(llval, >, llmaxint)) {
  1424. PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is greater than the maximum %d\n",
  1425. str_val, attr_name, maxint);
  1426. LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
  1427. return LDAP_UNWILLING_TO_PERFORM;
  1428. /* check for underflow */
  1429. } else if (LL_CMP(llval, <, llminint)) {
  1430. PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is less than the minimum %d\n",
  1431. str_val, attr_name, minint);
  1432. LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
  1433. return LDAP_UNWILLING_TO_PERFORM;
  1434. }
  1435. /* convert 64 bit value to 32 bit value */
  1436. LL_L2I(long_val, llval);
  1437. retval = config->config_set_fn(arg, (void *) long_val, err_buf, phase, apply_mod);
  1438. break;
  1439. case CONFIG_TYPE_SIZE_T:
  1440. if (use_default) {
  1441. str_val = config->config_default_value;
  1442. } else {
  1443. str_val = bval->bv_val;
  1444. }
  1445. /* get the value as a size_t value */
  1446. sz_val = db_strtoul(str_val, &err);
  1447. /* check for parsing error (e.g. not a number) */
  1448. if (err == EINVAL) {
  1449. PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is not a number\n",
  1450. str_val, attr_name);
  1451. LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
  1452. return LDAP_UNWILLING_TO_PERFORM;
  1453. /* check for overflow */
  1454. } else if (err == ERANGE) {
  1455. PR_snprintf(err_buf, SLAPI_DSE_RETURNTEXT_SIZE, "Error: value %s for attr %s is outside the range of representable values\n",
  1456. str_val, attr_name);
  1457. LDAPDebug(LDAP_DEBUG_ANY, "%s", err_buf, 0, 0);
  1458. return LDAP_UNWILLING_TO_PERFORM;
  1459. }
  1460. retval = config->config_set_fn(arg, (void *) sz_val, err_buf, phase, apply_mod);
  1461. break;
  1462. case CONFIG_TYPE_STRING:
  1463. if (use_default) {
  1464. retval = config->config_set_fn(arg, config->config_default_value, err_buf, phase, apply_mod);
  1465. } else {
  1466. retval = config->config_set_fn(arg, bval->bv_val, err_buf, phase, apply_mod);
  1467. }
  1468. break;
  1469. case CONFIG_TYPE_ONOFF:
  1470. if (use_default) {
  1471. int_val = !strcasecmp(config->config_default_value, "on");
  1472. } else {
  1473. int_val = !strcasecmp((char *) bval->bv_val, "on");
  1474. }
  1475. retval = config->config_set_fn(arg, (void *) ((uintptr_t)int_val), err_buf, phase, apply_mod);
  1476. break;
  1477. }
  1478. /* operation was successful and we applied the value? */
  1479. if (!retval && apply_mod) {
  1480. /* Since we are setting the value for the config attribute, we
  1481. * need to turn on the CONFIG_FLAG_PREVIOUSLY_SET flag to make
  1482. * sure this attribute is shown. */
  1483. if (use_default) {
  1484. /* attr deleted or we are using the default value */
  1485. config->config_flags &= ~CONFIG_FLAG_PREVIOUSLY_SET;
  1486. } else {
  1487. /* attr set explicitly */
  1488. config->config_flags |= CONFIG_FLAG_PREVIOUSLY_SET;
  1489. }
  1490. }
  1491. return retval;
  1492. }
  1493. static int parse_ldbm_config_entry(struct ldbminfo *li, Slapi_Entry *e, config_info *config_array)
  1494. {
  1495. Slapi_Attr *attr = NULL;
  1496. for (slapi_entry_first_attr(e, &attr); attr; slapi_entry_next_attr(e, attr, &attr)) {
  1497. char *attr_name = NULL;
  1498. Slapi_Value *sval = NULL;
  1499. struct berval *bval;
  1500. char err_buf[SLAPI_DSE_RETURNTEXT_SIZE];
  1501. slapi_attr_get_type(attr, &attr_name);
  1502. /* There are some attributes that we don't care about, like objectclass. */
  1503. if (ldbm_config_ignored_attr(attr_name)) {
  1504. continue;
  1505. }
  1506. slapi_attr_first_value(attr, &sval);
  1507. bval = (struct berval *) slapi_value_get_berval(sval);
  1508. if (ldbm_config_set(li, attr_name, config_array, bval, err_buf, CONFIG_PHASE_STARTUP, 1 /* apply */, LDAP_MOD_REPLACE) != LDAP_SUCCESS) {
  1509. LDAPDebug(LDAP_DEBUG_ANY, "Error with config attribute %s : %s\n", attr_name, err_buf, 0);
  1510. return 1;
  1511. }
  1512. }
  1513. return 0;
  1514. }
  1515. /*
  1516. * Returns:
  1517. * SLAPI_DSE_CALLBACK_ERROR on failure
  1518. * SLAPI_DSE_CALLBACK_OK on success
  1519. */
  1520. int ldbm_config_modify_entry_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* e, int *returncode, char *returntext, void *arg)
  1521. {
  1522. int i;
  1523. char *attr_name;
  1524. LDAPMod **mods;
  1525. int rc = LDAP_SUCCESS;
  1526. int apply_mod = 0;
  1527. struct ldbminfo *li= (struct ldbminfo *) arg;
  1528. /* This lock is probably way too conservative, but we don't expect much
  1529. * contention for it. */
  1530. PR_Lock(li->li_config_mutex);
  1531. slapi_pblock_get( pb, SLAPI_MODIFY_MODS, &mods );
  1532. returntext[0] = '\0';
  1533. /*
  1534. * First pass: set apply mods to 0 so only input validation will be done;
  1535. * 2nd pass: set apply mods to 1 to apply changes to internal storage
  1536. */
  1537. for ( apply_mod = 0; apply_mod <= 1 && LDAP_SUCCESS == rc; apply_mod++ ) {
  1538. for (i = 0; mods[i] && LDAP_SUCCESS == rc; i++) {
  1539. attr_name = mods[i]->mod_type;
  1540. /* There are some attributes that we don't care about, like modifiersname. */
  1541. if (ldbm_config_ignored_attr(attr_name)) {
  1542. continue;
  1543. }
  1544. /* when deleting a value, and this is the last or only value, set
  1545. the config param to its default value
  1546. when adding a value, if the value is set to its default value, replace
  1547. it with the new value - otherwise, if it is single valued, reject the
  1548. operation with TYPE_OR_VALUE_EXISTS */
  1549. /* This assumes there is only one bval for this mod. */
  1550. rc = ldbm_config_set((void *) li, attr_name, ldbm_config,
  1551. ( mods[i]->mod_bvalues == NULL ) ? NULL
  1552. : mods[i]->mod_bvalues[0], returntext,
  1553. ((li->li_flags&LI_FORCE_MOD_CONFIG)?
  1554. CONFIG_PHASE_INTERNAL:CONFIG_PHASE_RUNNING),
  1555. apply_mod, mods[i]->mod_op);
  1556. }
  1557. }
  1558. PR_Unlock(li->li_config_mutex);
  1559. *returncode= rc;
  1560. if(LDAP_SUCCESS == rc) {
  1561. return SLAPI_DSE_CALLBACK_OK;
  1562. }
  1563. else {
  1564. return SLAPI_DSE_CALLBACK_ERROR;
  1565. }
  1566. }
  1567. /* This function is used to set config attributes. It can be used as a
  1568. * shortcut to doing an internal modify operation on the config DSE.
  1569. */
  1570. void ldbm_config_internal_set(struct ldbminfo *li, char *attrname, char *value)
  1571. {
  1572. char err_buf[SLAPI_DSE_RETURNTEXT_SIZE];
  1573. struct berval bval;
  1574. bval.bv_val = value;
  1575. bval.bv_len = strlen(value);
  1576. if (ldbm_config_set((void *) li, attrname, ldbm_config, &bval,
  1577. err_buf, CONFIG_PHASE_INTERNAL, 1 /* apply */,
  1578. LDAP_MOD_REPLACE) != LDAP_SUCCESS) {
  1579. LDAPDebug(LDAP_DEBUG_ANY,
  1580. "Internal Error: Error setting instance config attr %s to %s: %s\n",
  1581. attrname, value, err_buf);
  1582. exit(1);
  1583. }
  1584. }
  1585. /*
  1586. * replace_ldbm_config_value:
  1587. * - update an ldbm database config value
  1588. */
  1589. void replace_ldbm_config_value(char *conftype, char *val, struct ldbminfo *li)
  1590. {
  1591. Slapi_PBlock pb;
  1592. Slapi_Mods smods;
  1593. pblock_init(&pb);
  1594. slapi_mods_init(&smods, 1);
  1595. slapi_mods_add(&smods, LDAP_MOD_REPLACE, conftype, strlen(val), val);
  1596. slapi_modify_internal_set_pb(&pb, CONFIG_LDBM_DN,
  1597. slapi_mods_get_ldapmods_byref(&smods),
  1598. NULL, NULL, li->li_identity, 0);
  1599. slapi_modify_internal_pb(&pb);
  1600. slapi_mods_done(&smods);
  1601. pblock_done(&pb);
  1602. }