2 /* compare.c - tcl compare 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.
26 AttributeAssertion * ava
29 char *command, *results;
30 struct berval suf_tcl;
32 struct tclinfo *ti = (struct tclinfo *) be->be_private;
34 if (ti->ti_compare.bv_len == 0) {
35 send_ldap_result (conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
36 "compare not implemented", NULL, NULL );
40 if (tcl_merge_bvlist (be->be_suffix, &suf_tcl) == NULL) {
41 send_ldap_result (conn, op, LDAP_OPERATIONS_ERROR, NULL,
46 command = (char *) ch_malloc (ti->ti_compare.bv_len +
47 suf_tcl.bv_len + dn->bv_len + ava->aa_desc->ad_cname.bv_len +
48 ava->aa_value.bv_len + 64);
49 sprintf (command, "%s COMPARE {%ld} {%s} {%s} {%s: %s}",
50 ti->ti_compare.bv_val, (long) op->o_msgid, suf_tcl.bv_val,
52 ava->aa_desc->ad_cname.bv_val, ava->aa_value.bv_val);
53 Tcl_Free (suf_tcl.bv_val);
55 ldap_pvt_thread_mutex_lock (&tcl_interpreter_mutex);
56 code = Tcl_GlobalEval (ti->ti_ii->interp, command);
57 results = (char *) ch_strdup (ti->ti_ii->interp->result);
58 ldap_pvt_thread_mutex_unlock (&tcl_interpreter_mutex);
62 err = LDAP_OPERATIONS_ERROR;
63 Debug (LDAP_DEBUG_SHELL, "tcl_compare_error: %s\n", results,
66 interp_send_results (be, conn, op, results, NULL, 0);
69 if (err != LDAP_SUCCESS)
70 send_ldap_result (conn, op, err, NULL,
71 "internal backend error", NULL, NULL );