cb_config.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright 2001 Sun Microsystems, Inc.
  3. * Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
  4. * All rights reserved.
  5. * END COPYRIGHT BLOCK **/
  6. #include "cb.h"
  7. #include <errno.h>
  8. /* Forward declarations */
  9. static int cb_parse_config_entry(cb_backend * cb, Slapi_Entry *e);
  10. /* body starts here */
  11. /* Used to add an array of entries, like the one above and
  12. ** cb_instance_skeleton_entries to the dse.
  13. ** Returns 0 on success.
  14. */
  15. int cb_config_add_dse_entries(cb_backend *cb, char **entries, char *string1, char *string2, char *string3)
  16. {
  17. int x;
  18. Slapi_Entry *e;
  19. Slapi_PBlock *util_pb = NULL;
  20. int res, rc = 0;
  21. char entry_string[CB_BUFSIZE];
  22. for(x = 0; strlen(entries[x]) > 0; x++) {
  23. util_pb = slapi_pblock_new();
  24. sprintf(entry_string, entries[x], string1, string2, string3);
  25. e = slapi_str2entry(entry_string, 0);
  26. slapi_add_entry_internal_set_pb(util_pb, e, NULL, cb->identity, 0);
  27. slapi_add_internal_pb(util_pb);
  28. slapi_pblock_get(util_pb, SLAPI_PLUGIN_INTOP_RESULT, &res);
  29. if ( LDAP_SUCCESS != res && LDAP_ALREADY_EXISTS != res ) {
  30. char ebuf[ BUFSIZ ];
  31. slapi_log_error(SLAPI_LOG_PLUGIN, CB_PLUGIN_SUBSYSTEM,
  32. "Unable to add config entry (%s) to the DSE: %s\n",
  33. escape_string(slapi_entry_get_dn(e), ebuf),
  34. ldap_err2string(res));
  35. rc = res;
  36. slapi_pblock_destroy(util_pb);
  37. break;
  38. }
  39. slapi_pblock_destroy(util_pb);
  40. }
  41. return rc;
  42. }
  43. /*
  44. ** Try to read the entry cn=config,cn=chaining database,cn=plugins,cn=config
  45. ** If the entry is there, then process the configuration information it stores.
  46. ** If it is missing, create it with default configuration.
  47. ** The default configuration is taken from the default entry if it exists
  48. */
  49. int cb_config_load_dse_info(Slapi_PBlock * pb) {
  50. Slapi_PBlock *search_pb,*default_pb;
  51. Slapi_Entry **entries = NULL;
  52. Slapi_Entry *configEntry=NULL;
  53. int res,default_res,i;
  54. char defaultDn[CB_BUFSIZE];
  55. cb_backend *cb;
  56. slapi_pblock_get( pb, SLAPI_PLUGIN_PRIVATE, &cb );
  57. /* Get global configuration entry */
  58. search_pb = slapi_pblock_new();
  59. slapi_search_internal_set_pb(search_pb, cb->configDN, LDAP_SCOPE_BASE,
  60. "objectclass=*", NULL, 0, NULL, NULL, cb->identity, 0);
  61. slapi_search_internal_pb (search_pb);
  62. slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_RESULT, &res);
  63. if ( LDAP_SUCCESS == res ) {
  64. slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries);
  65. if (NULL == entries || entries[0] == NULL) {
  66. slapi_log_error(SLAPI_LOG_PLUGIN, CB_PLUGIN_SUBSYSTEM,
  67. "Error accessing entry <%s>\n",cb->configDN);
  68. slapi_free_search_results_internal(search_pb);
  69. slapi_pblock_destroy(search_pb);
  70. return 1;
  71. }
  72. configEntry=entries[0];
  73. } else
  74. if ( LDAP_NO_SUCH_OBJECT == res ) {
  75. /* Don't do anything. The default conf is used */
  76. configEntry=NULL;
  77. } else {
  78. slapi_free_search_results_internal(search_pb);
  79. slapi_pblock_destroy(search_pb);
  80. slapi_log_error(SLAPI_LOG_PLUGIN, CB_PLUGIN_SUBSYSTEM,
  81. "Error accessing entry <%s> (%s)\n",cb->configDN,ldap_err2string(res));
  82. return 1;
  83. }
  84. /* Parse the configuration entry */
  85. /* Default config if configEntry is NULL*/
  86. cb_parse_config_entry(cb, configEntry);
  87. slapi_free_search_results_internal(search_pb);
  88. slapi_pblock_destroy(search_pb);
  89. /*
  90. ** Parse the chaining backend instances
  91. ** Immediate subordinates of cn=<plugin name>,cn=plugins,cn=config
  92. */
  93. search_pb = slapi_pblock_new();
  94. slapi_search_internal_set_pb(search_pb, cb->pluginDN, LDAP_SCOPE_ONELEVEL,
  95. CB_CONFIG_INSTANCE_FILTER,NULL,0,NULL,NULL,cb->identity, 0);
  96. slapi_search_internal_pb (search_pb);
  97. slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_RESULT, &res);
  98. if (res != LDAP_SUCCESS) {
  99. slapi_log_error(SLAPI_LOG_PLUGIN, CB_PLUGIN_SUBSYSTEM,
  100. "Error accessing the config DSE (%s)\n",ldap_err2string(res));
  101. slapi_free_search_results_internal(search_pb);
  102. slapi_pblock_destroy(search_pb);
  103. return 1;
  104. }
  105. /* Get the default instance value entry if it exists */
  106. /* else create it */
  107. sprintf(defaultDn,"cn=default instance config,%s",cb->pluginDN);
  108. default_pb = slapi_pblock_new();
  109. slapi_search_internal_set_pb(default_pb, defaultDn, LDAP_SCOPE_BASE,
  110. "objectclass=*", NULL, 0, NULL, NULL, cb->identity, 0);
  111. slapi_search_internal_pb (default_pb);
  112. slapi_pblock_get(default_pb, SLAPI_PLUGIN_INTOP_RESULT, &default_res);
  113. if (LDAP_SUCCESS != default_res) {
  114. cb_create_default_backend_instance_config(cb);
  115. }
  116. slapi_free_search_results_internal(default_pb);
  117. slapi_pblock_destroy(default_pb);
  118. slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries);
  119. for (i=0; entries && entries[i]; i++) {
  120. int retcode;
  121. char * aDn=slapi_entry_get_dn(entries[i]);
  122. slapi_dn_normalize(aDn);
  123. cb_instance_add_config_callback(pb,entries[i],NULL,&retcode,NULL,cb);
  124. }
  125. slapi_free_search_results_internal(search_pb);
  126. slapi_pblock_destroy(search_pb);
  127. /* Add callbacks */
  128. slapi_config_register_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_PREOP, cb->configDN,
  129. LDAP_SCOPE_BASE, "(objectclass=*)",cb_config_modify_check_callback, (void *) cb);
  130. slapi_config_register_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_POSTOP, cb->configDN,
  131. LDAP_SCOPE_BASE, "(objectclass=*)",cb_config_modify_callback, (void *) cb);
  132. slapi_config_register_callback(SLAPI_OPERATION_ADD, DSE_FLAG_PREOP, cb->configDN,
  133. LDAP_SCOPE_BASE, "(objectclass=*)",cb_config_add_check_callback, (void *) cb);
  134. slapi_config_register_callback(SLAPI_OPERATION_ADD, DSE_FLAG_POSTOP, cb->configDN,
  135. LDAP_SCOPE_BASE, "(objectclass=*)",cb_config_add_callback, (void *) cb);
  136. slapi_config_register_callback(SLAPI_OPERATION_SEARCH, DSE_FLAG_PREOP, cb->configDN,
  137. LDAP_SCOPE_BASE, "(objectclass=*)",cb_config_search_callback, (void *) cb);
  138. /* instance creation */
  139. slapi_config_register_callback(SLAPI_OPERATION_ADD, DSE_FLAG_PREOP, cb->pluginDN,
  140. LDAP_SCOPE_SUBTREE, CB_CONFIG_INSTANCE_FILTER, cb_config_add_instance_check_callback, (void *) cb);
  141. slapi_config_register_callback(SLAPI_OPERATION_ADD, DSE_FLAG_POSTOP, cb->pluginDN,
  142. LDAP_SCOPE_SUBTREE, CB_CONFIG_INSTANCE_FILTER, cb_config_add_instance_callback, (void *) cb);
  143. return 0;
  144. }
  145. /* Check validity of the modification */
  146. int cb_config_add_check_callback(Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry* e2, int *returncode,
  147. char *returntext, void *arg)
  148. {
  149. Slapi_Attr *attr = NULL;
  150. Slapi_Value *sval;
  151. struct berval * bval;
  152. int i;
  153. cb_backend *cb = (cb_backend *) arg;
  154. CB_ASSERT (cb!=NULL);
  155. for (slapi_entry_first_attr(e, &attr); attr; slapi_entry_next_attr(e, attr, &attr)) {
  156. char * attr_name=NULL;
  157. slapi_attr_get_type(attr, &attr_name);
  158. if ( !strcasecmp ( attr_name, CB_CONFIG_GLOBAL_FORWARD_CTRLS )) {
  159. /* First, parse the values to make sure they are valid */
  160. i = slapi_attr_first_value(attr, &sval);
  161. while (i != -1 ) {
  162. bval = (struct berval *) slapi_value_get_berval(sval);
  163. if (!cb_is_control_forwardable(cb,bval->bv_val)) {
  164. slapi_log_error(SLAPI_LOG_PLUGIN,CB_PLUGIN_SUBSYSTEM,
  165. "control %s can't be forwarded.\n",bval->bv_val);
  166. *returncode=LDAP_CONSTRAINT_VIOLATION;
  167. return SLAPI_DSE_CALLBACK_ERROR;
  168. }
  169. i = slapi_attr_next_value(attr, i, &sval);
  170. }
  171. }
  172. }
  173. *returncode=LDAP_SUCCESS;
  174. return SLAPI_DSE_CALLBACK_OK;
  175. }
  176. /*
  177. ** Global config is beeing added
  178. ** Take the new values into account
  179. */
  180. int
  181. cb_config_add_callback(Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry* e2, int *returncode,
  182. char *returntext, void *arg)
  183. {
  184. Slapi_Attr *attr = NULL;
  185. Slapi_Value *sval;
  186. struct berval * bval;
  187. int i;
  188. cb_backend *cb = (cb_backend *) arg;
  189. CB_ASSERT (cb!=NULL);
  190. for (slapi_entry_first_attr(e, &attr); attr; slapi_entry_next_attr(e, attr, &attr)) {
  191. char * attr_name=NULL;
  192. slapi_attr_get_type(attr, &attr_name);
  193. if ( !strcasecmp ( attr_name, CB_CONFIG_GLOBAL_FORWARD_CTRLS )) {
  194. /* First, parse the values to make sure they are valid */
  195. i = slapi_attr_first_value(attr, &sval);
  196. while (i != -1 ) {
  197. bval = (struct berval *) slapi_value_get_berval(sval);
  198. if (!cb_is_control_forwardable(cb,bval->bv_val)) {
  199. slapi_log_error(SLAPI_LOG_PLUGIN,CB_PLUGIN_SUBSYSTEM,
  200. "control %s can't be forwarded.\n",bval->bv_val);
  201. *returncode=LDAP_CONSTRAINT_VIOLATION;
  202. return SLAPI_DSE_CALLBACK_ERROR;
  203. }
  204. i = slapi_attr_next_value(attr, i, &sval);
  205. }
  206. /* second pass. apply changes */
  207. cb_unregister_all_supported_control(cb);
  208. i = slapi_attr_first_value(attr, &sval);
  209. while (i != -1 ) {
  210. bval = (struct berval *) slapi_value_get_berval(sval);
  211. cb_register_supported_control(cb,bval->bv_val,0);
  212. i = slapi_attr_next_value(attr, i, &sval);
  213. }
  214. }
  215. }
  216. *returncode=LDAP_SUCCESS;
  217. return SLAPI_DSE_CALLBACK_OK;
  218. }
  219. int
  220. cb_config_search_callback(Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry* e2, int *returncode,
  221. char *returntext, void *arg) {
  222. cb_backend *cb = (cb_backend *) arg;
  223. struct berval val;
  224. struct berval *vals[2];
  225. int i = 0;
  226. CB_ASSERT (cb!=NULL);
  227. vals[0] = &val;
  228. vals[1] = NULL;
  229. /* naming attribute */
  230. val.bv_val = "config";
  231. val.bv_len = strlen( val.bv_val );
  232. slapi_entry_attr_replace( e, "cn", (struct berval **)vals );
  233. /* objectclass attribute */
  234. val.bv_val = "top";
  235. val.bv_len = strlen( val.bv_val );
  236. slapi_entry_attr_replace( e, "objectclass", (struct berval **)vals );
  237. val.bv_val = CB_CONFIG_EXTENSIBLEOCL;
  238. val.bv_len = strlen( val.bv_val );
  239. slapi_entry_attr_merge( e, "objectclass", (struct berval **)vals );
  240. /* other attributes */
  241. PR_RWLock_Rlock(cb->config.rwl_config_lock);
  242. for (i=0; cb->config.forward_ctrls && cb->config.forward_ctrls[i] ; i++) {
  243. val.bv_val=cb->config.forward_ctrls[i];
  244. val.bv_len = strlen( val.bv_val );
  245. if (i==0)
  246. slapi_entry_attr_replace( e, CB_CONFIG_GLOBAL_FORWARD_CTRLS, (struct berval **)vals );
  247. else
  248. slapi_entry_attr_merge( e, CB_CONFIG_GLOBAL_FORWARD_CTRLS, (struct berval **)vals );
  249. }
  250. for (i=0;cb->config.chaining_components && cb->config.chaining_components[i];i++) {
  251. val.bv_val=cb->config.chaining_components[i];
  252. val.bv_len = strlen( val.bv_val );
  253. if (i==0)
  254. slapi_entry_attr_replace( e, CB_CONFIG_GLOBAL_CHAINING_COMPONENTS,
  255. (struct berval **)vals );
  256. else
  257. slapi_entry_attr_merge( e, CB_CONFIG_GLOBAL_CHAINING_COMPONENTS,
  258. (struct berval **)vals );
  259. }
  260. for (i=0; cb->config.chainable_components && cb->config.chainable_components[i]; i++) {
  261. val.bv_val=cb->config.chainable_components[i];
  262. val.bv_len = strlen( val.bv_val );
  263. if (i==0)
  264. slapi_entry_attr_replace( e, CB_CONFIG_GLOBAL_CHAINABLE_COMPONENTS,
  265. (struct berval **)vals );
  266. else
  267. slapi_entry_attr_merge( e, CB_CONFIG_GLOBAL_CHAINABLE_COMPONENTS,
  268. (struct berval **)vals );
  269. }
  270. PR_RWLock_Unlock(cb->config.rwl_config_lock);
  271. *returncode = LDAP_SUCCESS;
  272. return SLAPI_DSE_CALLBACK_OK;
  273. }
  274. /* Check validity of the modification */
  275. int
  276. cb_config_modify_check_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* e, int *returncode,
  277. char *returntext, void *arg)
  278. {
  279. LDAPMod **mods;
  280. char *attr_name;
  281. int i,j;
  282. cb_backend *cb = (cb_backend *) arg;
  283. CB_ASSERT (cb!=NULL);
  284. slapi_pblock_get( pb, SLAPI_MODIFY_MODS, &mods );
  285. for (i = 0; mods[i] ; i++) {
  286. attr_name = mods[i]->mod_type;
  287. if ( !strcasecmp ( attr_name, CB_CONFIG_GLOBAL_FORWARD_CTRLS )) {
  288. char * config_attr_value;
  289. for (j = 0; mods[i]->mod_bvalues && mods[i]->mod_bvalues[j]; j++) {
  290. config_attr_value = (char *) mods[i]->mod_bvalues[j]->bv_val;
  291. if (!cb_is_control_forwardable(cb,config_attr_value)) {
  292. slapi_log_error(SLAPI_LOG_PLUGIN,CB_PLUGIN_SUBSYSTEM,
  293. "control %s can't be forwarded.\n",config_attr_value);
  294. *returncode=LDAP_CONSTRAINT_VIOLATION;
  295. return SLAPI_DSE_CALLBACK_ERROR;
  296. }
  297. }
  298. }
  299. }
  300. *returncode=LDAP_SUCCESS;
  301. return SLAPI_DSE_CALLBACK_OK;
  302. }
  303. int
  304. cb_config_modify_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* e, int *returncode,
  305. char *returntext, void *arg)
  306. {
  307. LDAPMod **mods;
  308. char *attr_name;
  309. int i,j;
  310. cb_backend *cb = (cb_backend *) arg;
  311. CB_ASSERT (cb!=NULL);
  312. slapi_pblock_get( pb, SLAPI_MODIFY_MODS, &mods );
  313. for (i = 0; mods[i] ; i++) {
  314. attr_name = mods[i]->mod_type;
  315. if ( !strcasecmp ( attr_name, CB_CONFIG_GLOBAL_FORWARD_CTRLS )) {
  316. char * config_attr_value;
  317. int done=0;
  318. for (j = 0; mods[i]->mod_bvalues && mods[i]->mod_bvalues[j]; j++) {
  319. config_attr_value = (char *) mods[i]->mod_bvalues[j]->bv_val;
  320. if (!cb_is_control_forwardable(cb,config_attr_value)) {
  321. slapi_log_error(SLAPI_LOG_PLUGIN,CB_PLUGIN_SUBSYSTEM,
  322. "control %s can't be forwarded.\n",config_attr_value);
  323. *returncode=LDAP_CONSTRAINT_VIOLATION;
  324. return SLAPI_DSE_CALLBACK_ERROR;
  325. }
  326. if ( mods[i]->mod_op & LDAP_MOD_REPLACE) {
  327. if (!done) {
  328. cb_unregister_all_supported_control(cb);
  329. done=1;
  330. }
  331. cb_register_supported_control(cb,config_attr_value,0);
  332. } else
  333. if ( (mods[i]->mod_op & ~LDAP_MOD_BVALUES) == LDAP_MOD_ADD) {
  334. cb_register_supported_control(cb,config_attr_value,0);
  335. } else
  336. if ( (mods[i]->mod_op & ~LDAP_MOD_BVALUES) == LDAP_MOD_DELETE) {
  337. cb_unregister_supported_control(cb,config_attr_value,0);
  338. }
  339. }
  340. if (NULL == mods[i]->mod_bvalues)
  341. cb_unregister_all_supported_control(cb);
  342. } else
  343. if ( !strcasecmp ( attr_name, CB_CONFIG_GLOBAL_DEBUG )) {
  344. /* assume single-valued */
  345. if (mods[i]->mod_op & LDAP_MOD_DELETE)
  346. cb_set_debug(0);
  347. else if ((mods[i]->mod_op & ~LDAP_MOD_BVALUES) == LDAP_MOD_ADD)
  348. cb_set_debug(1);
  349. } else
  350. if ( !strcasecmp ( attr_name, CB_CONFIG_GLOBAL_CHAINING_COMPONENTS )) {
  351. char * config_attr_value;
  352. int done=0;
  353. PR_RWLock_Wlock(cb->config.rwl_config_lock);
  354. for (j = 0; mods[i]->mod_bvalues && mods[i]->mod_bvalues[j]; j++) {
  355. config_attr_value = (char *) mods[i]->mod_bvalues[j]->bv_val;
  356. if ( mods[i]->mod_op & LDAP_MOD_REPLACE) {
  357. if (!done) {
  358. charray_free(cb->config.chaining_components);
  359. cb->config.chaining_components=NULL;
  360. done=1;
  361. }
  362. /* XXXSD assume dn. Normalize it */
  363. charray_add(&cb->config.chaining_components,
  364. slapi_dn_normalize(slapi_ch_strdup(config_attr_value)));
  365. } else
  366. if ( (mods[i]->mod_op & ~LDAP_MOD_BVALUES) == LDAP_MOD_ADD) {
  367. charray_add(&cb->config.chaining_components,
  368. slapi_dn_normalize(slapi_ch_strdup(config_attr_value)));
  369. } else
  370. if ( (mods[i]->mod_op & ~LDAP_MOD_BVALUES) == LDAP_MOD_DELETE) {
  371. charray_remove(cb->config.chaining_components,
  372. slapi_dn_normalize(slapi_ch_strdup(config_attr_value)));
  373. }
  374. }
  375. if (NULL == mods[i]->mod_bvalues) {
  376. charray_free(cb->config.chaining_components);
  377. cb->config.chaining_components=NULL;
  378. }
  379. PR_RWLock_Unlock(cb->config.rwl_config_lock);
  380. } else
  381. if ( !strcasecmp ( attr_name, CB_CONFIG_GLOBAL_CHAINABLE_COMPONENTS )) {
  382. char * config_attr_value;
  383. int done=0;
  384. PR_RWLock_Wlock(cb->config.rwl_config_lock);
  385. for (j = 0; mods[i]->mod_bvalues && mods[i]->mod_bvalues[j]; j++) {
  386. config_attr_value = (char *) mods[i]->mod_bvalues[j]->bv_val;
  387. if ( mods[i]->mod_op & LDAP_MOD_REPLACE) {
  388. if (!done) {
  389. charray_free(cb->config.chainable_components);
  390. cb->config.chainable_components=NULL;
  391. done=1;
  392. }
  393. charray_add(&cb->config.chainable_components,
  394. slapi_dn_normalize(slapi_ch_strdup(config_attr_value)
  395. ));
  396. } else
  397. if ( (mods[i]->mod_op & ~LDAP_MOD_BVALUES) == LDAP_MOD_ADD) {
  398. charray_add(&cb->config.chainable_components,
  399. slapi_dn_normalize(slapi_ch_strdup(config_attr_value)
  400. ));
  401. } else
  402. if ( (mods[i]->mod_op & ~LDAP_MOD_BVALUES) == LDAP_MOD_DELETE) {
  403. charray_remove(cb->config.chainable_components,
  404. slapi_dn_normalize(slapi_ch_strdup(config_attr_value)
  405. ));
  406. }
  407. }
  408. if (NULL == mods[i]->mod_bvalues) {
  409. charray_free(cb->config.chainable_components);
  410. cb->config.chainable_components=NULL;
  411. }
  412. PR_RWLock_Unlock(cb->config.rwl_config_lock);
  413. }
  414. }
  415. *returncode=LDAP_SUCCESS;
  416. return SLAPI_DSE_CALLBACK_OK;
  417. }
  418. /*
  419. ** Creation of a new backend instance
  420. */
  421. int
  422. cb_config_add_instance_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* e, int *returncode,
  423. char *returntext, void *arg)
  424. {
  425. cb_backend *cb=(cb_backend *)arg;
  426. CB_ASSERT(cb!=NULL);
  427. cb_instance_add_config_callback(pb,entryBefore,NULL,returncode,returntext,cb);
  428. return SLAPI_DSE_CALLBACK_OK;
  429. }
  430. int
  431. cb_config_add_instance_check_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* e, int *returncode,
  432. char *returntext, void *arg)
  433. {
  434. cb_backend *cb=(cb_backend *)arg;
  435. CB_ASSERT(cb!=NULL);
  436. return cb_instance_add_config_check_callback(pb,entryBefore,NULL,returncode,returntext,cb);
  437. }
  438. /*
  439. ** Parse the global chaining backend configuration
  440. */
  441. static int cb_parse_config_entry(cb_backend * cb, Slapi_Entry *e)
  442. {
  443. Slapi_Attr *attr = NULL;
  444. Slapi_Value *sval;
  445. struct berval *bval;
  446. int i;
  447. if (e == NULL)
  448. return LDAP_SUCCESS;
  449. cb_set_debug(0);
  450. for (slapi_entry_first_attr(e, &attr); attr; slapi_entry_next_attr(e, attr, &attr)) {
  451. char * attr_name=NULL;
  452. slapi_attr_get_type(attr, &attr_name);
  453. if ( !strcasecmp ( attr_name, CB_CONFIG_GLOBAL_FORWARD_CTRLS )) {
  454. i = slapi_attr_first_value(attr, &sval);
  455. PR_RWLock_Wlock(cb->config.rwl_config_lock);
  456. if (cb->config.forward_ctrls) {
  457. charray_free(cb->config.forward_ctrls);
  458. cb->config.forward_ctrls=NULL;
  459. }
  460. PR_RWLock_Unlock(cb->config.rwl_config_lock);
  461. while (i != -1 ) {
  462. bval = (struct berval *) slapi_value_get_berval(sval);
  463. /* For now, don't support operation type */
  464. cb_register_supported_control(cb,bval->bv_val,
  465. SLAPI_OPERATION_SEARCH | SLAPI_OPERATION_COMPARE |
  466. SLAPI_OPERATION_ADD | SLAPI_OPERATION_DELETE |
  467. SLAPI_OPERATION_MODIFY | SLAPI_OPERATION_MODDN);
  468. i = slapi_attr_next_value(attr, i, &sval);
  469. }
  470. } else
  471. if ( !strcasecmp ( attr_name, CB_CONFIG_GLOBAL_CHAINING_COMPONENTS )) {
  472. i = slapi_attr_first_value(attr, &sval);
  473. PR_RWLock_Wlock(cb->config.rwl_config_lock);
  474. if (cb->config.chaining_components) {
  475. charray_free(cb->config.chaining_components);
  476. cb->config.chaining_components=NULL;
  477. }
  478. while (i != -1 ) {
  479. bval = (struct berval *) slapi_value_get_berval(sval);
  480. /* XXXSD assume dn. Normalize it */
  481. charray_add( &cb->config.chaining_components,
  482. slapi_dn_normalize(slapi_ch_strdup(bval->bv_val)));
  483. i = slapi_attr_next_value(attr, i, &sval);
  484. }
  485. PR_RWLock_Unlock(cb->config.rwl_config_lock);
  486. } else
  487. if ( !strcasecmp ( attr_name, CB_CONFIG_GLOBAL_CHAINABLE_COMPONENTS )) {
  488. i = slapi_attr_first_value(attr, &sval);
  489. PR_RWLock_Wlock(cb->config.rwl_config_lock);
  490. if (cb->config.chainable_components) {
  491. charray_free(cb->config.chainable_components);
  492. cb->config.chainable_components=NULL;
  493. }
  494. while (i != -1 ) {
  495. bval = (struct berval *) slapi_value_get_berval(sval);
  496. charray_add( &cb->config.chainable_components,
  497. slapi_dn_normalize(slapi_ch_strdup(bval->bv_val)));
  498. i = slapi_attr_next_value(attr, i, &sval);
  499. }
  500. PR_RWLock_Unlock(cb->config.rwl_config_lock);
  501. } else
  502. if ( !strcasecmp ( attr_name, CB_CONFIG_GLOBAL_DEBUG )) {
  503. i = slapi_attr_first_value(attr, &sval);
  504. if (i != -1 ) {
  505. bval = (struct berval *) slapi_value_get_berval(sval);
  506. /* any value */
  507. cb_set_debug(1);
  508. }
  509. }
  510. }
  511. return LDAP_SUCCESS;
  512. }