2 /* add.c - tcl add routine
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, *entrystr, *results;
26 struct berval suf_tcl;
28 struct tclinfo *ti = (struct tclinfo *) op->o_bd->be_private;
30 if (ti->ti_add.bv_len == 0) {
31 send_ldap_error (op, rs, LDAP_UNWILLING_TO_PERFORM,
32 "add not implemented" );
36 if (tcl_merge_bvlist (op->o_bd->be_suffix, &suf_tcl) == NULL) {
37 send_ldap_error (op, rs, LDAP_OTHER, NULL);
41 entrystr = tcl_clean_entry(op->oq_add.rs_e);
43 command = (char *) ch_malloc (ti->ti_add.bv_len + suf_tcl.bv_len +
44 strlen(entrystr) + 52);
45 sprintf (command, "%s ADD {%ld/%ld} {%s} {%s}",
46 ti->ti_add.bv_val, op->o_connid, (long) op->o_msgid,
47 suf_tcl.bv_val, entrystr);
48 Tcl_Free (suf_tcl.bv_val);
51 ldap_pvt_thread_mutex_lock (&tcl_interpreter_mutex);
52 code = Tcl_GlobalEval (ti->ti_ii->interp, command);
53 results = (char *) ch_strdup (ti->ti_ii->interp->result);
54 ldap_pvt_thread_mutex_unlock (&tcl_interpreter_mutex);
58 rs->sr_err = LDAP_OTHER;
59 Debug (LDAP_DEBUG_SHELL, "tcl_add_error: %s\n", results, 0, 0);
61 interp_send_results (op, rs, results);
64 if (rs->sr_err != LDAP_SUCCESS) {
65 rs->sr_text = "internal backend error";
66 send_ldap_result (op, rs);