1 /* search.c - tcl search routines
3 * $Id: tcl_search.c,v 1.4 1999/02/19 06:55:20 bcollins Exp $
5 * Copyright 1999, Ben Collins <bcollins@debian.org>, All rights reserved.
7 * Redistribution and use in source and binary forms are permitted only
8 * as authorized by the OpenLDAP Public License. A copy of this
9 * license is available at http://www.OpenLDAP.org/license.html or
10 * in file LICENSE in the top-level directory of the distribution.
36 char *attrs_tcl = NULL, *suf_tcl, *results, *command;
38 struct tclinfo *ti = (struct tclinfo *) be->be_private;
41 if (ti->ti_search == NULL) {
42 send_ldap_result (conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
43 "search not implemented");
47 for (i = 0; attrs != NULL && attrs[i] != NULL; i++);
49 attrs_tcl = Tcl_Merge (i, attrs);
51 for (i = 0; be->be_suffix[i] != NULL; i++);
52 suf_tcl = Tcl_Merge (i, be->be_suffix);
54 command = (char *) ch_malloc (strlen (ti->ti_search) + strlen (suf_tcl)
55 + strlen (base) + 40 + strlen (filterstr) + (attrs_tcl ==
57 : strlen (attrs_tcl)) + 72);
59 "%s SEARCH {%ld} {%s} {%s} {%d} {%d} {%d} {%d} {%s} {%d} {%s}",
60 ti->ti_search, op->o_msgid, suf_tcl, base, scope, deref,
61 sizelimit, timelimit, filterstr, attrsonly ? 1 : 0,
63 NULL ? "{all}" : attrs_tcl);
67 ldap_pvt_thread_mutex_lock (&tcl_interpreter_mutex);
68 code = Tcl_GlobalEval (ti->ti_ii->interp, command);
69 results = (char *) ch_strdup (ti->ti_ii->interp->result);
70 ldap_pvt_thread_mutex_unlock (&tcl_interpreter_mutex);
74 err = LDAP_OPERATIONS_ERROR;
75 Debug (LDAP_DEBUG_SHELL, "tcl_search_error: %s\n", results,
78 interp_send_results (be, conn, op, results, NULL, 0);
81 if (err != LDAP_SUCCESS)
82 send_ldap_result (conn, op, err, NULL,
83 "internal backend error");