backend.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  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. /* backend.c - Slapi_Backend methods */
  42. #include "slap.h"
  43. void
  44. be_init( Slapi_Backend *be, const char *type, const char *name, int isprivate, int logchanges, int sizelimit, int timelimit )
  45. {
  46. slapdFrontendConfig_t *fecfg;
  47. be->be_suffixlist = NULL;
  48. be->be_suffixlock = PR_NewLock();
  49. be->be_suffixcounter = slapi_counter_new();
  50. /* e.g. dn: cn=config,cn=NetscapeRoot,cn=ldbm database,cn=plugins,cn=config */
  51. be->be_basedn = slapi_create_dn_string("cn=%s,cn=%s,cn=plugins,cn=config",
  52. name, type);
  53. if (NULL == be->be_basedn) {
  54. LDAPDebug2Args(LDAP_DEBUG_ANY,
  55. "be_init: failed create instance dn for plugin %s, "
  56. "instance %s\n", type, name);
  57. }
  58. be->be_configdn = slapi_create_dn_string("cn=config,cn=%s,cn=%s,cn=plugins,cn=config",
  59. name, type);
  60. if (NULL == be->be_configdn) {
  61. LDAPDebug2Args(LDAP_DEBUG_ANY,
  62. "be_init: failed create instance config dn for "
  63. "plugin %s, instance %s\n", type, name);
  64. }
  65. be->be_monitordn = slapi_create_dn_string("cn=monitor,cn=%s,cn=%s,cn=plugins,cn=config",
  66. name, type);
  67. if (NULL == be->be_configdn) {
  68. LDAPDebug2Args(LDAP_DEBUG_ANY,
  69. "be_init: failed create instance monitor dn for "
  70. "plugin %s, instance %s\n", type, name);
  71. }
  72. be->be_sizelimit = sizelimit;
  73. be->be_pagedsizelimit = config_get_pagedsizelimit();
  74. be->be_timelimit = timelimit;
  75. /* maximum group nesting level before giving up */
  76. be->be_maxnestlevel = SLAPD_DEFAULT_GROUPNESTLEVEL;
  77. be->be_noacl= 0;
  78. be->be_flags=0;
  79. if (( fecfg = getFrontendConfig()) != NULL )
  80. {
  81. if ( fecfg->backendconfig != NULL && fecfg->backendconfig[ 0 ] != NULL )
  82. {
  83. be->be_backendconfig = slapi_ch_strdup( fecfg->backendconfig[0] );
  84. }
  85. else
  86. {
  87. be->be_backendconfig= NULL;
  88. }
  89. be->be_readonly = fecfg->readonly;
  90. }
  91. else
  92. {
  93. be->be_readonly= 0;
  94. be->be_backendconfig= NULL;
  95. }
  96. be->be_lastmod = LDAP_UNDEFINED;
  97. be->be_type = slapi_ch_strdup(type);
  98. be->be_include = NULL;
  99. be->be_private = isprivate;
  100. be->be_logchanges = logchanges;
  101. be->be_database = NULL;
  102. be->be_writeconfig = NULL;
  103. be->be_delete_on_exit = 0;
  104. be->be_state = BE_STATE_STOPPED;
  105. be->be_state_lock = PR_NewLock();
  106. be->be_name = slapi_ch_strdup(name);
  107. be->be_mapped = 0;
  108. be->be_usn_counter = NULL;
  109. }
  110. void
  111. be_done(Slapi_Backend *be)
  112. {
  113. int i;
  114. int count = slapi_counter_get_value(be->be_suffixcounter);
  115. struct suffixlist *list, *next;
  116. list = be->be_suffixlist;
  117. for(i=0; i < count && list; i++)
  118. {
  119. next = list->next;
  120. slapi_sdn_free(&list->be_suffix);
  121. slapi_ch_free((void **)&list);
  122. list = next;
  123. }
  124. slapi_ch_free((void **)&be->be_basedn);
  125. slapi_ch_free((void **)&be->be_configdn);
  126. slapi_ch_free((void **)&be->be_monitordn);
  127. slapi_ch_free((void **)&be->be_type);
  128. slapi_ch_free((void **)&be->be_backendconfig);
  129. /* JCM char **be_include; ??? */
  130. slapi_ch_free((void **)&be->be_name);
  131. if (!config_get_entryusn_global()) {
  132. slapi_counter_destroy(&be->be_usn_counter);
  133. }
  134. slapi_counter_destroy(&be->be_suffixcounter);
  135. PR_DestroyLock(be->be_suffixlock);
  136. PR_DestroyLock(be->be_state_lock);
  137. if (be->be_lock != NULL)
  138. {
  139. slapi_destroy_rwlock(be->be_lock);
  140. be->be_lock = NULL;
  141. }
  142. }
  143. void
  144. slapi_be_delete_onexit (Slapi_Backend *be)
  145. {
  146. be->be_delete_on_exit = 1;
  147. }
  148. void
  149. slapi_be_set_readonly(Slapi_Backend *be, int readonly)
  150. {
  151. be->be_readonly = readonly;
  152. }
  153. int
  154. slapi_be_get_readonly(Slapi_Backend *be)
  155. {
  156. return be->be_readonly;
  157. }
  158. /*
  159. * Check if suffix, exactly matches a registered
  160. * suffix of this backend.
  161. */
  162. int
  163. slapi_be_issuffix( const Slapi_Backend *be, const Slapi_DN *suffix )
  164. {
  165. struct suffixlist *list;
  166. int r= 0;
  167. /* this backend is no longer valid */
  168. if (be->be_state != BE_STATE_DELETED)
  169. {
  170. int i = 0, count;
  171. count = slapi_counter_get_value(be->be_suffixcounter);
  172. list = be->be_suffixlist;
  173. while(list && i < count){
  174. if ( slapi_sdn_compare( list->be_suffix, suffix ) == 0){
  175. r = 1;
  176. break;
  177. }
  178. i++;
  179. list = list->next;
  180. }
  181. }
  182. return r;
  183. }
  184. int
  185. be_isdeleted( const Slapi_Backend *be )
  186. {
  187. return ((be == NULL) || (BE_STATE_DELETED == be->be_state));
  188. }
  189. void
  190. be_addsuffix(Slapi_Backend *be,const Slapi_DN *suffix)
  191. {
  192. if (be->be_state != BE_STATE_DELETED)
  193. {
  194. struct suffixlist *new_suffix, *list;
  195. new_suffix = (struct suffixlist *)slapi_ch_malloc(sizeof(struct suffixlist));
  196. new_suffix->be_suffix = slapi_sdn_dup(suffix);
  197. new_suffix->next = NULL;
  198. PR_Lock(be->be_suffixlock);
  199. if(be->be_suffixlist == NULL){
  200. be->be_suffixlist = new_suffix;
  201. } else {
  202. list = be->be_suffixlist;
  203. while(list->next != NULL){
  204. list = list->next;
  205. }
  206. list->next = new_suffix;
  207. }
  208. slapi_counter_increment(be->be_suffixcounter);
  209. PR_Unlock(be->be_suffixlock);
  210. }
  211. }
  212. void slapi_be_addsuffix(Slapi_Backend *be,const Slapi_DN *suffix)
  213. {
  214. be_addsuffix(be,suffix);
  215. }
  216. /*
  217. * The Slapi_DN pointer will always be valid even though the array
  218. * itself may be changing due to the addition of a suffix.
  219. */
  220. const Slapi_DN *
  221. slapi_be_getsuffix(Slapi_Backend *be,int n)
  222. {
  223. struct suffixlist *list;
  224. if(NULL == be)
  225. return NULL;
  226. if(be->be_state != BE_STATE_DELETED) {
  227. if (be->be_suffixlist !=NULL && n < slapi_counter_get_value(be->be_suffixcounter)) {
  228. int i = 0;
  229. list = be->be_suffixlist;
  230. while(list != NULL && i <= n){
  231. if(i == n){
  232. return list->be_suffix;
  233. }
  234. list = list->next;
  235. i++;
  236. }
  237. }
  238. }
  239. return NULL;
  240. }
  241. const char *
  242. slapi_be_gettype(Slapi_Backend *be)
  243. {
  244. const char *r= NULL;
  245. if (be->be_state != BE_STATE_DELETED)
  246. {
  247. r= be->be_type;
  248. }
  249. return r;
  250. }
  251. Slapi_DN *
  252. be_getconfigdn(Slapi_Backend *be, Slapi_DN *dn)
  253. {
  254. if (be->be_state == BE_STATE_DELETED)
  255. {
  256. slapi_sdn_set_ndn_byref(dn,NULL);
  257. }
  258. else
  259. {
  260. slapi_sdn_set_ndn_byref(dn,be->be_configdn);
  261. }
  262. return dn;
  263. }
  264. Slapi_DN *
  265. be_getmonitordn(Slapi_Backend *be, Slapi_DN *dn)
  266. {
  267. if (be->be_state == BE_STATE_DELETED)
  268. {
  269. slapi_sdn_set_ndn_byref(dn,NULL);
  270. }
  271. else
  272. {
  273. slapi_sdn_set_ndn_byref(dn,be->be_monitordn);
  274. }
  275. return dn;
  276. }
  277. int
  278. be_writeconfig ( Slapi_Backend *be )
  279. {
  280. Slapi_PBlock *newpb;
  281. if (be->be_state == BE_STATE_DELETED || be->be_private ||
  282. (be->be_writeconfig == NULL) ) {
  283. return -1;
  284. }
  285. else {
  286. newpb = slapi_pblock_new();
  287. slapi_pblock_set ( newpb, SLAPI_PLUGIN, (void *) be->be_database );
  288. slapi_pblock_set ( newpb, SLAPI_BACKEND, (void *) be );
  289. (be->be_writeconfig)(newpb);
  290. slapi_pblock_destroy ( newpb );
  291. return 1;
  292. }
  293. }
  294. /*
  295. * Find out if changes made to entries in this backend
  296. * should be recorded in the changelog.
  297. */
  298. int
  299. slapi_be_logchanges(Slapi_Backend *be)
  300. {
  301. if (be->be_state == BE_STATE_DELETED)
  302. return 0;
  303. return be->be_logchanges;
  304. }
  305. int
  306. slapi_be_private ( Slapi_Backend *be )
  307. {
  308. if ( be!=NULL )
  309. {
  310. return (be->be_private);
  311. }
  312. return 0;
  313. }
  314. void *
  315. slapi_be_get_instance_info(Slapi_Backend * be)
  316. {
  317. PR_ASSERT(NULL != be);
  318. return be->be_instance_info;
  319. }
  320. void
  321. slapi_be_set_instance_info(Slapi_Backend * be, void * data)
  322. {
  323. PR_ASSERT(NULL != be);
  324. be->be_instance_info=data;
  325. }
  326. int
  327. slapi_be_getentrypoint(Slapi_Backend *be, int entrypoint, void **ret_fnptr, Slapi_PBlock *pb)
  328. {
  329. PR_ASSERT(NULL != be);
  330. /* this is something needed for most of the entry points */
  331. if (pb)
  332. {
  333. slapi_pblock_set( pb, SLAPI_PLUGIN, be->be_database );
  334. slapi_pblock_set( pb, SLAPI_BACKEND, be );
  335. }
  336. switch (entrypoint) {
  337. case SLAPI_PLUGIN_DB_BIND_FN:
  338. *ret_fnptr = (void*)be->be_bind;
  339. break;
  340. case SLAPI_PLUGIN_DB_UNBIND_FN:
  341. *ret_fnptr = (void*)be->be_unbind;
  342. break;
  343. case SLAPI_PLUGIN_DB_SEARCH_FN:
  344. *ret_fnptr = (void*)be->be_search;
  345. break;
  346. case SLAPI_PLUGIN_DB_COMPARE_FN:
  347. *ret_fnptr = (void*)be->be_compare;
  348. break;
  349. case SLAPI_PLUGIN_DB_MODIFY_FN:
  350. *ret_fnptr = (void*)be->be_modify;
  351. break;
  352. case SLAPI_PLUGIN_DB_MODRDN_FN:
  353. *ret_fnptr = (void*)be->be_modrdn;
  354. break;
  355. case SLAPI_PLUGIN_DB_ADD_FN:
  356. *ret_fnptr = (void*)be->be_add;
  357. break;
  358. case SLAPI_PLUGIN_DB_DELETE_FN:
  359. *ret_fnptr = (void*)be->be_delete;
  360. break;
  361. case SLAPI_PLUGIN_DB_ABANDON_FN:
  362. *ret_fnptr = (void*)be->be_abandon;
  363. break;
  364. case SLAPI_PLUGIN_DB_CONFIG_FN:
  365. *ret_fnptr = (void*)be->be_config;
  366. break;
  367. case SLAPI_PLUGIN_CLOSE_FN:
  368. *ret_fnptr = (void*)be->be_close;
  369. break;
  370. case SLAPI_PLUGIN_DB_FLUSH_FN:
  371. *ret_fnptr = (void*)be->be_flush;
  372. break;
  373. case SLAPI_PLUGIN_START_FN:
  374. *ret_fnptr = (void*)be->be_start;
  375. break;
  376. case SLAPI_PLUGIN_DB_RESULT_FN:
  377. *ret_fnptr = (void*)be->be_result;
  378. break;
  379. case SLAPI_PLUGIN_DB_LDIF2DB_FN:
  380. *ret_fnptr = (void*)be->be_ldif2db;
  381. break;
  382. case SLAPI_PLUGIN_DB_DB2LDIF_FN:
  383. *ret_fnptr = (void*)be->be_db2ldif;
  384. break;
  385. case SLAPI_PLUGIN_DB_ARCHIVE2DB_FN:
  386. *ret_fnptr = (void*)be->be_archive2db;
  387. break;
  388. case SLAPI_PLUGIN_DB_DB2ARCHIVE_FN:
  389. *ret_fnptr = (void*)be->be_db2archive;
  390. break;
  391. case SLAPI_PLUGIN_DB_NEXT_SEARCH_ENTRY_FN:
  392. *ret_fnptr = (void*)be->be_next_search_entry;
  393. break;
  394. case SLAPI_PLUGIN_DB_NEXT_SEARCH_ENTRY_EXT_FN:
  395. *ret_fnptr = (void*)be->be_next_search_entry_ext;
  396. break;
  397. case SLAPI_PLUGIN_DB_ENTRY_RELEASE_FN:
  398. *ret_fnptr = (void*)be->be_entry_release;
  399. break;
  400. case SLAPI_PLUGIN_DB_SEARCH_RESULTS_RELEASE_FN:
  401. *ret_fnptr = (void*)be->be_search_results_release;
  402. break;
  403. case SLAPI_PLUGIN_DB_PREV_SEARCH_RESULTS_FN:
  404. *ret_fnptr = be->be_prev_search_results;
  405. break;
  406. case SLAPI_PLUGIN_DB_SIZE_FN:
  407. *ret_fnptr = (void*)be->be_dbsize;
  408. break;
  409. case SLAPI_PLUGIN_DB_TEST_FN:
  410. *ret_fnptr = (void*)be->be_dbtest;
  411. break;
  412. case SLAPI_PLUGIN_DB_RMDB_FN:
  413. *ret_fnptr = (void*)be->be_rmdb;
  414. break;
  415. case SLAPI_PLUGIN_DB_INIT_INSTANCE_FN:
  416. *ret_fnptr = (void*)be->be_init_instance;
  417. break;
  418. case SLAPI_PLUGIN_DB_SEQ_FN:
  419. *ret_fnptr = (void*)be->be_seq;
  420. break;
  421. case SLAPI_PLUGIN_DB_DB2INDEX_FN:
  422. *ret_fnptr = (void*)be->be_db2index;
  423. break;
  424. case SLAPI_PLUGIN_CLEANUP_FN:
  425. *ret_fnptr = (void*)be->be_cleanup;
  426. break;
  427. default:
  428. slapi_log_error(SLAPI_LOG_FATAL, NULL,
  429. "slapi_be_getentrypoint: unknown entry point %d\n", entrypoint);
  430. return -1;
  431. }
  432. return 0;
  433. }
  434. int
  435. slapi_be_setentrypoint(Slapi_Backend *be, int entrypoint, void *ret_fnptr, Slapi_PBlock *pb)
  436. {
  437. PR_ASSERT(NULL != be);
  438. /* this is something needed for most of the entry points */
  439. if (pb)
  440. {
  441. be->be_database=pb->pb_plugin;
  442. return 0;
  443. }
  444. switch (entrypoint) {
  445. case SLAPI_PLUGIN_DB_BIND_FN:
  446. be->be_bind=(IFP)ret_fnptr;
  447. break;
  448. case SLAPI_PLUGIN_DB_UNBIND_FN:
  449. be->be_unbind=(IFP)ret_fnptr;
  450. break;
  451. case SLAPI_PLUGIN_DB_SEARCH_FN:
  452. be->be_search=(IFP)ret_fnptr;
  453. break;
  454. case SLAPI_PLUGIN_DB_COMPARE_FN:
  455. be->be_compare=(IFP)ret_fnptr;
  456. break;
  457. case SLAPI_PLUGIN_DB_MODIFY_FN:
  458. be->be_modify=(IFP)ret_fnptr;
  459. break;
  460. case SLAPI_PLUGIN_DB_MODRDN_FN:
  461. be->be_modrdn=(IFP)ret_fnptr;
  462. break;
  463. case SLAPI_PLUGIN_DB_ADD_FN:
  464. be->be_add=(IFP)ret_fnptr;
  465. break;
  466. case SLAPI_PLUGIN_DB_DELETE_FN:
  467. be->be_delete=(IFP)ret_fnptr;
  468. break;
  469. case SLAPI_PLUGIN_DB_ABANDON_FN:
  470. be->be_abandon=(IFP)ret_fnptr;
  471. break;
  472. case SLAPI_PLUGIN_DB_CONFIG_FN:
  473. be->be_config=(IFP)ret_fnptr;
  474. break;
  475. case SLAPI_PLUGIN_CLOSE_FN:
  476. be->be_close=(IFP)ret_fnptr;
  477. break;
  478. case SLAPI_PLUGIN_DB_FLUSH_FN:
  479. be->be_flush=(IFP)ret_fnptr;
  480. break;
  481. case SLAPI_PLUGIN_START_FN:
  482. be->be_start=(IFP)ret_fnptr;
  483. break;
  484. case SLAPI_PLUGIN_DB_RESULT_FN:
  485. be->be_result=(IFP)ret_fnptr;
  486. break;
  487. case SLAPI_PLUGIN_DB_LDIF2DB_FN:
  488. be->be_ldif2db=(IFP)ret_fnptr;
  489. break;
  490. case SLAPI_PLUGIN_DB_DB2LDIF_FN:
  491. be->be_db2ldif=(IFP) ret_fnptr;
  492. break;
  493. case SLAPI_PLUGIN_DB_ARCHIVE2DB_FN:
  494. be->be_archive2db=(IFP) ret_fnptr;
  495. break;
  496. case SLAPI_PLUGIN_DB_DB2ARCHIVE_FN:
  497. be->be_db2archive=(IFP) ret_fnptr;
  498. break;
  499. case SLAPI_PLUGIN_DB_NEXT_SEARCH_ENTRY_FN:
  500. be->be_next_search_entry=(IFP) ret_fnptr;
  501. break;
  502. case SLAPI_PLUGIN_DB_NEXT_SEARCH_ENTRY_EXT_FN:
  503. be->be_next_search_entry_ext=(IFP) ret_fnptr;
  504. break;
  505. case SLAPI_PLUGIN_DB_ENTRY_RELEASE_FN:
  506. be->be_entry_release=(IFP) ret_fnptr;
  507. break;
  508. case SLAPI_PLUGIN_DB_SEARCH_RESULTS_RELEASE_FN:
  509. be->be_search_results_release=(VFPP) ret_fnptr;
  510. break;
  511. case SLAPI_PLUGIN_DB_PREV_SEARCH_RESULTS_FN:
  512. be->be_prev_search_results = (VFP) ret_fnptr;
  513. break;
  514. case SLAPI_PLUGIN_DB_SIZE_FN:
  515. be->be_dbsize=(IFP) ret_fnptr;
  516. break;
  517. case SLAPI_PLUGIN_DB_TEST_FN:
  518. be->be_dbtest=(IFP)ret_fnptr;
  519. break;
  520. case SLAPI_PLUGIN_DB_RMDB_FN:
  521. be->be_rmdb=(IFP)ret_fnptr;
  522. break;
  523. case SLAPI_PLUGIN_DB_INIT_INSTANCE_FN:
  524. be->be_init_instance=(IFP)ret_fnptr;
  525. break;
  526. case SLAPI_PLUGIN_DB_SEQ_FN:
  527. be->be_seq=(IFP)ret_fnptr;
  528. break;
  529. case SLAPI_PLUGIN_DB_DB2INDEX_FN:
  530. be->be_db2index=(IFP)ret_fnptr;
  531. break;
  532. case SLAPI_PLUGIN_CLEANUP_FN:
  533. be->be_cleanup=(IFP)ret_fnptr;
  534. break;
  535. default:
  536. slapi_log_error(SLAPI_LOG_FATAL, NULL,
  537. "slapi_be_setentrypoint: unknown entry point %d\n", entrypoint);
  538. return -1;
  539. }
  540. return 0;
  541. }
  542. int slapi_be_is_flag_set(Slapi_Backend * be, int flag)
  543. {
  544. return be->be_flags & flag;
  545. }
  546. void slapi_be_set_flag(Slapi_Backend * be, int flag)
  547. {
  548. be->be_flags|= flag;
  549. }
  550. char * slapi_be_get_name(Slapi_Backend * be)
  551. {
  552. return be->be_name;
  553. }
  554. void be_set_sizelimit(Slapi_Backend * be, int sizelimit)
  555. {
  556. be->be_sizelimit = sizelimit;
  557. }
  558. void be_set_timelimit(Slapi_Backend * be, int timelimit)
  559. {
  560. be->be_timelimit = timelimit;
  561. }
  562. void be_set_pagedsizelimit(Slapi_Backend * be, int sizelimit)
  563. {
  564. be->be_pagedsizelimit = sizelimit;
  565. }
  566. int
  567. slapi_back_get_info(Slapi_Backend *be, int cmd, void **info)
  568. {
  569. int rc = -1;
  570. if (!be || !be->be_get_info || !info) {
  571. return rc;
  572. }
  573. rc = (*be->be_get_info)(be, cmd, info);
  574. return rc;
  575. }
  576. int
  577. slapi_back_set_info(Slapi_Backend *be, int cmd, void *info)
  578. {
  579. int rc = -1;
  580. if (!be || !be->be_set_info || !info) {
  581. return rc;
  582. }
  583. rc = (*be->be_set_info)(be, cmd, info);
  584. return rc;
  585. }
  586. int
  587. slapi_back_ctrl_info(Slapi_Backend *be, int cmd, void *info)
  588. {
  589. int rc = -1;
  590. if (!be || !be->be_ctrl_info || !info) {
  591. return rc;
  592. }
  593. rc = (*be->be_ctrl_info)(be, cmd, info);
  594. return rc;
  595. }
  596. /* API to expose DB transaction begin */
  597. /* See memberof.c for usage. */
  598. int
  599. slapi_back_transaction_begin(Slapi_PBlock *pb)
  600. {
  601. IFP txn_begin;
  602. if(slapi_pblock_get(pb, SLAPI_PLUGIN_DB_BEGIN_FN, (void*)&txn_begin) ||
  603. !txn_begin)
  604. {
  605. return SLAPI_BACK_TRANSACTION_NOT_SUPPORTED;
  606. } else {
  607. return txn_begin(pb);
  608. }
  609. }
  610. /* API to expose DB transaction commit */
  611. int
  612. slapi_back_transaction_commit(Slapi_PBlock *pb)
  613. {
  614. IFP txn_commit;
  615. if(slapi_pblock_get(pb, SLAPI_PLUGIN_DB_COMMIT_FN, (void*)&txn_commit) ||
  616. !txn_commit)
  617. {
  618. return SLAPI_BACK_TRANSACTION_NOT_SUPPORTED;
  619. } else {
  620. return txn_commit(pb);
  621. }
  622. }
  623. /* API to expose DB transaction abort */
  624. int
  625. slapi_back_transaction_abort(Slapi_PBlock *pb)
  626. {
  627. IFP txn_abort;
  628. if(slapi_pblock_get(pb, SLAPI_PLUGIN_DB_ABORT_FN, (void*)&txn_abort) ||
  629. !txn_abort)
  630. {
  631. return SLAPI_BACK_TRANSACTION_NOT_SUPPORTED;
  632. } else {
  633. return txn_abort(pb);
  634. }
  635. }