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 const char *filterstr,
36 char *attrs_tcl = NULL, *suf_tcl, *results, *command;
38 struct tclinfo *ti = (struct tclinfo *) be->be_private;
43 if (ti->ti_search == NULL) {
44 send_ldap_result (conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
45 "search not implemented", NULL, NULL );
49 for (i = 0, an = attrs; an != NULL; an=an->an_next, i++);
51 sattrs = ch_malloc( (i+1) * sizeof(char *));
52 for (i = 0, an = attrs; an; an=an->an_next, i++)
53 sattrs[i] = an->an_name.bv_val;
55 attrs_tcl = Tcl_Merge (i, sattrs);
59 for (i = 0; be->be_suffix[i] != NULL; i++);
60 suf_tcl = Tcl_Merge (i, be->be_suffix);
62 command = (char *) ch_malloc (strlen (ti->ti_search) + strlen (suf_tcl)
63 + strlen (base) + 40 + strlen (filterstr) + (attrs_tcl ==
65 : strlen (attrs_tcl)) + 72);
67 "%s SEARCH {%ld} {%s} {%s} {%d} {%d} {%d} {%d} {%s} {%d} {%s}",
68 ti->ti_search, op->o_msgid, suf_tcl, base, scope, deref,
69 sizelimit, timelimit, filterstr, attrsonly ? 1 : 0,
71 NULL ? "{all}" : attrs_tcl);
75 ldap_pvt_thread_mutex_lock (&tcl_interpreter_mutex);
76 code = Tcl_GlobalEval (ti->ti_ii->interp, command);
77 results = (char *) ch_strdup (ti->ti_ii->interp->result);
78 ldap_pvt_thread_mutex_unlock (&tcl_interpreter_mutex);
82 err = LDAP_OPERATIONS_ERROR;
83 Debug (LDAP_DEBUG_SHELL, "tcl_search_error: %s\n", results,
86 interp_send_results (be, conn, op, results, attrs, 0);
89 if (err != LDAP_SUCCESS)
90 send_ldap_result (conn, op, err, NULL,
91 "internal backend error", NULL, NULL );