1
0

cb_config.c 23 KB

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