2 /* modify.c - tcl modify routines
4 * Copyright 1999, Ben Collins <bcollins@debian.org>, All rights reserved.
6 * Redistribution and use in source and binary forms are permitted only
7 * as authorized by the OpenLDAP Public License. A copy of this
8 * license is available at http://www.OpenLDAP.org/license.html or
9 * in file LICENSE in the top-level directory of the distribution.
25 char *command, *bp, *tcl_mods, *results;
26 struct berval suf_tcl;
27 int i, code, len, bsize;
28 struct tclinfo *ti = (struct tclinfo *) op->o_bd->be_private;
29 Modifications *modlist = op->oq_modify.rs_modlist;
31 if (ti->ti_modify.bv_len == 0) {
32 send_ldap_error (op, rs, LDAP_UNWILLING_TO_PERFORM,
33 "modify not implemented" );
37 if (tcl_merge_bvlist (op->o_bd->be_suffix, &suf_tcl) == NULL) {
38 send_ldap_error (op, rs, LDAP_OTHER, NULL);
42 tcl_mods = (char *) ch_malloc (BUFSIZ);
47 for (; modlist != NULL; modlist = modlist->sml_next) {
48 Modification *mods = &modlist->sml_mod;
50 op_add = { sizeof("add") - 1, "add" },
51 op_delete = { sizeof("delete") - 1, "delete" },
52 op_replace = { sizeof("replace") - 1, "replace" },
55 switch (mods->sm_op & ~LDAP_MOD_BVALUES) {
62 case LDAP_MOD_REPLACE:
69 len = mods->sm_type.bv_len + op->bv_len + 7;
70 while (bp + len - tcl_mods > bsize) {
72 tcl_mods = (char *) ch_realloc (tcl_mods, bsize);
74 sprintf (bp, "{ {%s: %s} ", op->bv_val, mods->sm_type.bv_val);
77 mods->sm_bvalues != NULL && mods->sm_bvalues[i].bv_val
80 len = mods->sm_type.bv_len +
81 mods->sm_bvalues[i].bv_len + 5 +
82 (mods->sm_bvalues[i + 1].bv_val == NULL ? 2 : 0);
83 while (bp + len - tcl_mods > bsize) {
85 tcl_mods = (char *) ch_realloc (tcl_mods, bsize);
87 sprintf (bp, "{%s: %s} %s", mods->sm_type.bv_val,
88 mods->sm_bvalues[i].bv_val,
89 mods->sm_bvalues[i + 1].bv_val ==
95 command = (char *) ch_malloc (ti->ti_modify.bv_len + suf_tcl.bv_len
96 + op->o_req_dn.bv_len + strlen (tcl_mods) + 84);
97 /* This space is simply for aesthetics--\ */
98 sprintf (command, "%s MODIFY {%ld/%ld} {%s} {%s} { %s}",
99 ti->ti_modify.bv_val, op->o_connid, (long) op->o_msgid,
100 suf_tcl.bv_val, op->o_req_dn.bv_val, tcl_mods);
101 Tcl_Free (suf_tcl.bv_val);
104 ldap_pvt_thread_mutex_lock (&tcl_interpreter_mutex);
105 code = Tcl_GlobalEval (ti->ti_ii->interp, command);
106 results = (char *) ch_strdup (ti->ti_ii->interp->result);
107 ldap_pvt_thread_mutex_unlock (&tcl_interpreter_mutex);
110 if (code != TCL_OK) {
111 rs->sr_err = LDAP_OTHER;
112 Debug (LDAP_DEBUG_SHELL, "tcl_modify_error: %s\n", results,
115 interp_send_results (op, rs, results);
118 if (rs->sr_err != LDAP_SUCCESS) {
119 rs->sr_text = "internal backend error";
120 send_ldap_result (op, rs);