2 /* search.c - tcl search 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.
31 struct berval *filterstr,
36 char *attrs_tcl = NULL, *results, *command;
37 struct berval suf_tcl;
39 struct tclinfo *ti = (struct tclinfo *) be->be_private;
42 if (ti->ti_search.bv_len == 0) {
43 send_ldap_result (conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
44 "search not implemented", NULL, NULL );
48 for (i = 0, an = attrs; an && an->an_name.bv_val; an++, i++);
50 char **sattrs = ch_malloc( (i+1) * sizeof(char *));
51 for (i = 0, an = attrs; an->an_name.bv_val; an++, i++)
52 sattrs[i] = an->an_name.bv_val;
54 attrs_tcl = Tcl_Merge (i, sattrs);
58 if (tcl_merge_bvlist (be->be_suffix, &suf_tcl) == NULL) {
60 send_ldap_result (conn, op, LDAP_OTHER, NULL,
65 command = (char *) ch_malloc (ti->ti_search.bv_len + suf_tcl.bv_len
66 + base->bv_len + 60 + filterstr->bv_len +
67 (attrs_tcl == NULL ? 5 : strlen (attrs_tcl)) + 72);
69 "%s SEARCH {%ld/%ld} {%s} {%s} {%d} {%d} {%d} {%d} {%s} {%d} {%s}",
70 ti->ti_search.bv_val, op->o_connid, (long) op->o_msgid,
71 suf_tcl.bv_val, base->bv_val, scope, deref,
72 sizelimit, timelimit, filterstr->bv_val, attrsonly ? 1 : 0,
73 attrs_tcl == NULL ? "{all}" : attrs_tcl);
75 Tcl_Free (suf_tcl.bv_val);
77 ldap_pvt_thread_mutex_lock (&tcl_interpreter_mutex);
78 code = Tcl_GlobalEval (ti->ti_ii->interp, command);
79 results = (char *) ch_strdup (ti->ti_ii->interp->result);
80 ldap_pvt_thread_mutex_unlock (&tcl_interpreter_mutex);
85 Debug (LDAP_DEBUG_SHELL, "tcl_search_error: %s\n", results,
88 interp_send_results (be, conn, op, results, attrs, 0);
91 if (err != LDAP_SUCCESS)
92 send_ldap_result (conn, op, err, NULL,
93 "internal backend error", NULL, NULL );