1999-02-18 10:18:39 +08:00
|
|
|
/* result.c - tcl backend utility functions
|
|
|
|
*
|
1999-08-18 03:00:59 +08:00
|
|
|
* $Id: tcl_util.c,v 1.8 1999/08/02 23:38:43 hallvard Exp $
|
1999-02-15 03:20:14 +08:00
|
|
|
*
|
|
|
|
* Copyright 1999, Ben Collins <bcollins@debian.org>, All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms are permitted only
|
|
|
|
* as authorized by the OpenLDAP Public License. A copy of this
|
|
|
|
* license is available at http://www.OpenLDAP.org/license.html or
|
|
|
|
* in file LICENSE in the top-level directory of the distribution.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/unistd.h>
|
|
|
|
|
|
|
|
#include "slap.h"
|
|
|
|
#include "tcl_back.h"
|
|
|
|
|
|
|
|
int
|
1999-02-18 10:18:39 +08:00
|
|
|
interp_send_results (
|
|
|
|
Backend * be,
|
|
|
|
Connection * conn,
|
|
|
|
Operation * op,
|
|
|
|
char *result,
|
|
|
|
char **attrs,
|
|
|
|
int attrsonly
|
1999-02-15 03:20:14 +08:00
|
|
|
)
|
|
|
|
{
|
1999-02-18 10:18:39 +08:00
|
|
|
int bsize, len, argcPtr, i, err, code;
|
|
|
|
char *buf, *bp, **argvPtr, *line, *matched, *info;
|
|
|
|
Entry *e;
|
1999-02-15 03:20:14 +08:00
|
|
|
struct tclinfo *ti = (struct tclinfo *) be->be_private;
|
1999-02-18 10:18:39 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* read in the result and send it along
|
|
|
|
*/
|
|
|
|
buf = (char *) ch_malloc (BUFSIZ);
|
1999-02-15 03:20:14 +08:00
|
|
|
buf[0] = '\0';
|
|
|
|
bsize = BUFSIZ;
|
|
|
|
bp = buf;
|
1999-02-18 10:18:39 +08:00
|
|
|
code = Tcl_SplitList (ti->ti_ii->interp, result, &argcPtr, &argvPtr);
|
1999-02-15 03:20:14 +08:00
|
|
|
if (code != TCL_OK) {
|
|
|
|
argcPtr = 0;
|
|
|
|
send_ldap_result (conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
|
1999-08-03 09:38:43 +08:00
|
|
|
"internal backend error", NULL, NULL );
|
1999-02-15 03:20:14 +08:00
|
|
|
return -1;
|
|
|
|
}
|
1999-02-18 10:18:39 +08:00
|
|
|
for (i = 0; i < argcPtr; i++) {
|
1999-02-15 03:20:14 +08:00
|
|
|
line = argvPtr[i];
|
1999-02-18 10:18:39 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ignore lines beginning with DEBUG:
|
|
|
|
*/
|
|
|
|
if (strncasecmp (line, "DEBUG:", 6) == 0) {
|
1999-02-15 03:20:14 +08:00
|
|
|
continue;
|
|
|
|
}
|
1999-02-18 10:18:39 +08:00
|
|
|
len = strlen (line) + 1;
|
|
|
|
while (bp + len - buf > bsize) {
|
1999-02-15 03:20:14 +08:00
|
|
|
bsize += BUFSIZ;
|
1999-02-18 10:18:39 +08:00
|
|
|
buf = (char *) ch_realloc (buf, bsize);
|
1999-02-15 03:20:14 +08:00
|
|
|
}
|
1999-02-18 10:18:39 +08:00
|
|
|
sprintf (bp, "%s\n", line);
|
1999-02-15 03:20:14 +08:00
|
|
|
bp += len;
|
|
|
|
|
1999-02-18 10:18:39 +08:00
|
|
|
/*
|
|
|
|
* line marked the end of an entry or result
|
|
|
|
*/
|
|
|
|
if (line[0] == '\0') {
|
|
|
|
if (strncasecmp (buf, "RESULT", 6) == 0) {
|
1999-02-15 03:20:14 +08:00
|
|
|
break;
|
|
|
|
}
|
1999-02-18 10:18:39 +08:00
|
|
|
if ((e = str2entry (buf)) == NULL) {
|
1999-02-28 13:55:48 +08:00
|
|
|
Debug (LDAP_DEBUG_SHELL,
|
1999-02-18 10:18:39 +08:00
|
|
|
"str2entry(%s) failed\n",
|
|
|
|
buf, 0, 0);
|
1999-02-15 03:20:14 +08:00
|
|
|
} else {
|
1999-02-18 10:18:39 +08:00
|
|
|
send_search_entry (be, conn, op, e, attrs,
|
1999-08-03 09:38:43 +08:00
|
|
|
attrsonly, NULL );
|
1999-02-18 10:18:39 +08:00
|
|
|
entry_free (e);
|
1999-02-15 03:20:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bp = buf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-02-18 10:18:39 +08:00
|
|
|
(void) str2result (buf, &err, &matched, &info);
|
1999-02-15 03:20:14 +08:00
|
|
|
|
1999-02-18 10:18:39 +08:00
|
|
|
/*
|
|
|
|
* otherwise, front end will send this result
|
|
|
|
*/
|
|
|
|
if (err != 0 || op->o_tag != LDAP_REQ_BIND) {
|
1999-08-03 09:38:43 +08:00
|
|
|
send_ldap_result (conn, op, err, matched, info, NULL, NULL );
|
1999-02-15 03:20:14 +08:00
|
|
|
}
|
|
|
|
|
1999-02-18 10:18:39 +08:00
|
|
|
free (buf);
|
|
|
|
Tcl_Free ((char *) argvPtr);
|
|
|
|
return (err);
|
1999-02-15 03:20:14 +08:00
|
|
|
}
|
|
|
|
|
1999-02-18 10:18:39 +08:00
|
|
|
char *
|
|
|
|
tcl_clean_entry (
|
|
|
|
Entry * e
|
|
|
|
)
|
1999-02-15 03:20:14 +08:00
|
|
|
{
|
1999-02-17 10:05:28 +08:00
|
|
|
char *entrystr, *mark1, *mark2, *buf, *bp, *dup;
|
|
|
|
int len, bsize;
|
1999-02-15 03:20:14 +08:00
|
|
|
|
1999-08-18 03:00:59 +08:00
|
|
|
ldap_pvt_thread_mutex_lock(&entry2str_mutex);
|
|
|
|
entrystr = entry2str (e, &len);
|
1999-02-15 03:20:14 +08:00
|
|
|
|
1999-02-18 10:18:39 +08:00
|
|
|
buf = (char *) ch_malloc (BUFSIZ);
|
1999-02-17 10:05:28 +08:00
|
|
|
buf[0] = '\0';
|
|
|
|
bsize = BUFSIZ;
|
|
|
|
bp = buf;
|
|
|
|
bp++[0] = ' ';
|
1999-02-15 03:20:14 +08:00
|
|
|
|
1999-02-17 10:05:28 +08:00
|
|
|
mark1 = entrystr;
|
|
|
|
do {
|
1999-02-15 03:20:14 +08:00
|
|
|
if (mark1[0] == '\n') {
|
1999-02-18 10:18:39 +08:00
|
|
|
mark1++;
|
1999-02-15 03:20:14 +08:00
|
|
|
}
|
1999-02-19 15:55:20 +08:00
|
|
|
dup = (char *) ch_strdup (mark1);
|
1999-02-18 10:18:39 +08:00
|
|
|
if (dup[0] != '\0') {
|
|
|
|
if ((mark2 = (char *) strchr (dup, '\n')) != NULL) {
|
1999-02-15 03:20:14 +08:00
|
|
|
mark2[0] = '\0';
|
1999-02-18 10:18:39 +08:00
|
|
|
}
|
|
|
|
len = strlen (dup) + 3;
|
|
|
|
while (bp + len - buf > bsize) {
|
1999-02-15 03:20:14 +08:00
|
|
|
bsize += BUFSIZ;
|
1999-02-18 10:18:39 +08:00
|
|
|
buf = (char *) ch_realloc (buf, bsize);
|
|
|
|
}
|
|
|
|
if (mark1[0] == '\0') {
|
|
|
|
sprintf (bp, "{} ");
|
|
|
|
} else {
|
|
|
|
sprintf (bp, "{%s} ", dup);
|
|
|
|
}
|
|
|
|
bp += len;
|
|
|
|
if (mark2 != NULL) {
|
1999-02-15 03:20:14 +08:00
|
|
|
mark2[0] = '\n';
|
1999-02-18 10:18:39 +08:00
|
|
|
}
|
1999-02-15 03:20:14 +08:00
|
|
|
}
|
1999-02-18 10:18:39 +08:00
|
|
|
free (dup);
|
1999-02-17 10:05:28 +08:00
|
|
|
} while ((mark1 = (char *) strchr (mark1, '\n')) != NULL);
|
1999-08-18 03:00:59 +08:00
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_unlock (&entry2str_mutex);
|
1999-02-17 10:05:28 +08:00
|
|
|
return buf;
|
1999-02-15 03:20:14 +08:00
|
|
|
}
|
|
|
|
|
1999-02-18 10:18:39 +08:00
|
|
|
int
|
|
|
|
tcl_ldap_debug (
|
|
|
|
ClientData clientData,
|
|
|
|
Tcl_Interp * interp,
|
|
|
|
int argc,
|
|
|
|
char *argv[]
|
1999-02-15 03:20:14 +08:00
|
|
|
)
|
|
|
|
{
|
1999-02-17 10:05:28 +08:00
|
|
|
if (argv[1] != NULL) {
|
1999-02-28 13:55:48 +08:00
|
|
|
Debug (LDAP_DEBUG_SHELL, "tcl_debug: %s\n", argv[1], 0, 0);
|
1999-02-17 10:05:28 +08:00
|
|
|
}
|
|
|
|
return TCL_OK;
|
1999-02-15 03:20:14 +08:00
|
|
|
}
|
1999-02-18 10:18:39 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
readtclscript (
|
|
|
|
char *script,
|
|
|
|
Tcl_Interp * my_tcl)
|
|
|
|
{
|
|
|
|
int code;
|
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
f = fopen (script, "r");
|
|
|
|
if (f == NULL) {
|
1999-02-28 13:55:48 +08:00
|
|
|
Debug (LDAP_DEBUG_SHELL, "Could not open scriptpath %s\n", script,
|
1999-02-18 10:18:39 +08:00
|
|
|
0, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fclose (f);
|
|
|
|
code = Tcl_EvalFile (my_tcl, script);
|
|
|
|
if (code != TCL_OK) {
|
1999-02-28 13:55:48 +08:00
|
|
|
Debug (LDAP_DEBUG_SHELL, "%s: %s\n", script,
|
1999-02-18 10:18:39 +08:00
|
|
|
Tcl_GetVar (my_tcl, "errorInfo", TCL_GLOBAL_ONLY), 0);
|
1999-02-28 13:55:48 +08:00
|
|
|
Debug (LDAP_DEBUG_SHELL, "%s: error at line\n", script,
|
1999-02-18 10:18:39 +08:00
|
|
|
my_tcl->errorLine, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|