cb_config.c 26 KB

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