Move back-tcl to the Attic

This commit is contained in:
Kurt Zeilenga 2003-12-06 21:37:44 +00:00
parent da6d557cdc
commit c425a7ce1d
21 changed files with 947 additions and 2737 deletions

2079
configure vendored

File diff suppressed because it is too large Load diff

View file

@ -238,9 +238,6 @@ OL_ARG_WITH(shell_module,[ --with-shell-module module type static|dynamic],
OL_ARG_ENABLE(sql,[ --enable-sql enable sql backend], no)dnl
OL_ARG_WITH(sql_module,[ --with-sql-module module type static|dynamic], static,
[static dynamic])
OL_ARG_ENABLE(tcl,[ --enable-tcl enable tcl backend], no)dnl
OL_ARG_WITH(tcl_module,[ --with-tcl-module module type static|dynamic], static,
[static dynamic])
dnl ----------------------------------------------------------------
dnl SLAPD Overlay Options
@ -305,9 +302,6 @@ if test $ol_enable_slapd = no ; then
if test $ol_enable_shell = yes ; then
AC_MSG_WARN([slapd disabled, ignoring --enable-shell argument])
fi
if test $ol_enable_tcl = yes ; then
AC_MSG_WARN([slapd disabled, ignoring --enable-tcl argument])
fi
if test $ol_enable_sql = yes ; then
AC_MSG_WARN([slapd disabled, ignoring --enable-sql argument])
fi
@ -365,9 +359,6 @@ if test $ol_enable_slapd = no ; then
if test $ol_with_shell_module != static ; then
AC_MSG_WARN([slapd disabled, ignoring --with-shell-module argument])
fi
if test $ol_with_tcl_module != static ; then
AC_MSG_WARN([slapd disabled, ignoring --with-tcl-module argument])
fi
if test $ol_with_sql_module != static ; then
AC_MSG_WARN([slapd disabled, ignoring --with-sql-module argument])
fi
@ -397,7 +388,6 @@ if test $ol_enable_slapd = no ; then
ol_enable_passwd=no
ol_enable_perl=no
ol_enable_shell=no
ol_enable_tcl=no
ol_enable_sql=no
ol_enable_modules=no
@ -421,7 +411,6 @@ if test $ol_enable_slapd = no ; then
ol_with_passwd_module=static
ol_with_perl_module=static
ol_with_shell_module=static
ol_with_tcl_module=static
ol_with_sql_module=static
ol_enable_slurpd=no
@ -457,8 +446,7 @@ elif test $ol_enable_ldbm = no ; then
$ol_enable_passwd = no -a \
$ol_enable_perl = no -a \
$ol_enable_shell = no -a \
$ol_enable_sql = no -a \
$ol_enable_tcl = no ; then
$ol_enable_sql = no -a ; then
if test $ol_enable_slapd = yes ; then
AC_MSG_ERROR([slapd requires a backend])
@ -575,7 +563,6 @@ BUILD_PASSWD=no
BUILD_PERL=no
BUILD_SHELL=no
BUILD_SQL=no
BUILD_TCL=no
BUILD_BDB_DYNAMIC=static
BUILD_DNSSRV_DYNAMIC=static
@ -588,7 +575,6 @@ BUILD_NULL_DYNAMIC=static
BUILD_PASSWD_DYNAMIC=static
BUILD_PERL_DYNAMIC=static
BUILD_SHELL_DYNAMIC=static
BUILD_TCL_DYNAMIC=static
BUILD_SQL_DYNAMIC=static
BUILD_DYNGROUP=no
@ -610,7 +596,6 @@ SLAPD_SQL_LDFLAGS=
SLAPD_SQL_LIBS=
SLAPD_SQL_INCLUDES=
MOD_TCL_LIB=
KRB4_LIBS=
KRB5_LIBS=
SASL_LIBS=
@ -822,7 +807,6 @@ else
ol_with_passwd_module=static
ol_with_perl_module=static
ol_with_shell_module=static
ol_with_tcl_module=static
ol_with_sql_module=static
if test $ol_with_dyngroup = mod ; then
AC_MSG_WARN([building static dyngroup overlay])
@ -2175,35 +2159,6 @@ if test $ol_enable_sql != no ; then
fi
fi
dnl ----------------------------------------------------------------
dnl TCL
if test $ol_enable_tcl != no ; then
AC_CHECK_HEADERS(tcl.h)
if test $ac_cv_header_tcl_h != yes ; then
have_tcl=no
else
for lib in tcl tcl7.6 tcl8.0 tcl8.2 ; do
AC_CHECK_LIB($lib,main,
[have_tcl=yes
if test x"$ol_with_tcl_module" = "xstatic" ; then
SLAPD_LIBS="$SLAPD_LIBS -l${lib}"
else
MOD_TCL_LIB="-l${lib}"
fi;break],[have_tcl=no])
done
fi
if test $have_tcl != yes ; then
AC_MSG_WARN([could not find -ltcl])
if test $ol_enable_tcl = yes ; then
AC_MSG_ERROR([could not find tcl, select appropriate options or disable])
fi
ol_enable_tcl=no
fi
fi
dnl ----------------------------------------------------------------
dnl ud needs termcap (should insert check here)
ol_link_termcap=no
@ -2804,21 +2759,6 @@ if test "$ol_enable_shell" != no ; then
fi
fi
if test "$ol_enable_tcl" != no ; then
AC_DEFINE(SLAPD_TCL,1,[define to support TCL backend])
BUILD_SLAPD=yes
BUILD_TCL=yes
if test "$ol_with_tcl_module" != static; then
AC_DEFINE(SLAPD_TCL_DYNAMIC,1,
[define to support dynamic TCL backend])
BUILD_TCL=mod
BUILD_TCL_DYNAMIC=shared
SLAPD_DYNAMIC_BACKENDS="$SLAPD_DYNAMIC_BACKENDS back-tcl"
else
SLAPD_STATIC_BACKENDS="$SLAPD_STATIC_BACKENDS back-tcl"
fi
fi
if test "$ol_link_sql" != no ; then
AC_DEFINE(SLAPD_SQL,1,[define to support SQL backend])
BUILD_SLAPD=yes
@ -2912,7 +2852,6 @@ AC_SUBST(BUILD_SLAPD)
AC_SUBST(BUILD_PERL)
AC_SUBST(BUILD_SHELL)
AC_SUBST(BUILD_SQL)
AC_SUBST(BUILD_TCL)
AC_SUBST(BUILD_BDB_DYNAMIC)
AC_SUBST(BUILD_DNSSRV_DYNAMIC)
AC_SUBST(BUILD_HDB_DYNAMIC)
@ -2925,7 +2864,6 @@ AC_SUBST(BUILD_SLAPD)
AC_SUBST(BUILD_PERL_DYNAMIC)
AC_SUBST(BUILD_SHELL_DYNAMIC)
AC_SUBST(BUILD_SQL_DYNAMIC)
AC_SUBST(BUILD_TCL_DYNAMIC)
AC_SUBST(BUILD_DYNGROUP)
AC_SUBST(BUILD_PROXYCACHE)
AC_SUBST(BUILD_SLURPD)
@ -2937,7 +2875,6 @@ AC_SUBST(LDBM_LIBS)
AC_SUBST(LTHREAD_LIBS)
AC_SUBST(LUTIL_LIBS)
AC_SUBST(WRAP_LIBS)
AC_SUBST(MOD_TCL_LIB)
AC_SUBST(SLAPD_MODULES_CPPFLAGS)
AC_SUBST(SLAPD_MODULES_LDFLAGS)
@ -3009,7 +2946,6 @@ servers/slapd/back-passwd/Makefile:build/top.mk:servers/slapd/back-passwd/Makefi
servers/slapd/back-perl/Makefile:build/top.mk:servers/slapd/back-perl/Makefile.in:build/mod.mk \
servers/slapd/back-shell/Makefile:build/top.mk:servers/slapd/back-shell/Makefile.in:build/mod.mk \
servers/slapd/back-sql/Makefile:build/top.mk:servers/slapd/back-sql/Makefile.in:build/mod.mk \
servers/slapd/back-tcl/Makefile:build/top.mk:servers/slapd/back-tcl/Makefile.in:build/mod.mk \
servers/slapd/shell-backends/Makefile:build/top.mk:servers/slapd/shell-backends/Makefile.in:build/srv.mk \
servers/slapd/slapi/Makefile:build/top.mk:servers/slapd/slapi/Makefile.in:build/lib.mk:build/lib-shared.mk \
servers/slapd/overlays/Makefile:build/top.mk:servers/slapd/overlays/Makefile.in:build/lib.mk:build/lib-shared.mk \

View file

@ -578,9 +578,6 @@
/* Define if you have the <syslog.h> header file. */
#undef HAVE_SYSLOG_H
/* Define if you have the <tcl.h> header file. */
#undef HAVE_TCL_H
/* Define if you have the <tcpd.h> header file. */
#undef HAVE_TCPD_H
@ -1028,12 +1025,6 @@
/* define to support dynamic SHELL backend */
#undef SLAPD_SHELL_DYNAMIC
/* define to support TCL backend */
#undef SLAPD_TCL
/* define to support dynamic TCL backend */
#undef SLAPD_TCL_DYNAMIC
/* define to support SQL backend */
#undef SLAPD_SQL

View file

@ -1,56 +0,0 @@
# Makefile.in for back-tcl
# $OpenLDAP$
## This work is part of OpenLDAP Software <http://www.openldap.org/>.
##
## Copyright 1998-2003 The OpenLDAP Foundation.
## All rights reserved.
##
## Redistribution and use in source and binary forms, with or without
## modification, are permitted only as authorized by the OpenLDAP
## Public License.
##
## A copy of this license is available in the file LICENSE in the
## top-level directory of the distribution or, alternatively, at
## <http://www.OpenLDAP.org/license.html>.
###########################################################################
#
# 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.
#
##########################################################################
SRCS = tcl_init.c tcl_search.c tcl_close.c tcl_config.c tcl_bind.c \
tcl_unbind.c tcl_compare.c tcl_modify.c tcl_add.c tcl_modrdn.c \
tcl_delete.c tcl_abandon.c tcl_util.c
OBJS = tcl_init.lo tcl_search.lo tcl_close.lo tcl_config.lo tcl_bind.lo \
tcl_unbind.lo tcl_compare.lo tcl_modify.lo tcl_add.lo tcl_modrdn.lo \
tcl_delete.lo tcl_abandon.lo tcl_util.lo
LDAP_INCDIR= ../../../include
LDAP_LIBDIR= ../../../libraries
BUILD_OPT = "--enable-tcl"
BUILD_MOD = @BUILD_TCL@
BUILD_MOD_DYNAMIC = @BUILD_TCL_DYNAMIC@
mod_DEFS = -DSLAPD_IMPORT
MOD_DEFS = $(@BUILD_TCL@_DEFS)
shared_LDAP_LIBS = $(LDAP_LIBLDAP_R_LA) $(LDAP_LIBLBER_LA)
NT_LINK_LIBS = -L.. -lslapd $(@BUILD_LIBS_DYNAMIC@_LDAP_LIBS)
UNIX_LINK_LIBS = $(@BUILD_LIBS_DYNAMIC@_LDAP_LIBS)
LIBBASE = back_tcl
XDEFS = $(MODULES_CPPFLAGS)
XINCPATH = -I.. -I$(srcdir)/..
all-local-lib: ../.backend
../.backend: lib$(LIBBASE).a
@touch $@

View file

@ -1 +0,0 @@
The Tcl Backend is described in the slapd-tcl(5) manual page.

View file

@ -1,4 +0,0 @@
* lock mutex on a per interpreter basis instead of global
* Add a version, callable from the tcl script for checking features

View file

@ -1,40 +0,0 @@
/* $OpenLDAP$ */
#ifndef _TCL_EXTERNAL_H
#define _TCL_EXTERNAL_H
LDAP_BEGIN_DECL
extern BI_init tcl_back_initialize;
extern BI_open tcl_back_open;
extern BI_close tcl_back_close;
extern BI_destroy tcl_back_destroy;
extern BI_db_init tcl_back_db_init;
extern BI_db_open tcl_back_db_open;
extern BI_db_close tcl_back_db_close;
extern BI_db_destroy tcl_back_db_destroy;
extern BI_db_config tcl_back_db_config;
extern BI_op_bind tcl_back_bind;
extern BI_op_unbind tcl_back_unbind;
extern BI_op_search tcl_back_search;
extern BI_op_compare tcl_back_compare;
extern BI_op_modify tcl_back_modify;
extern BI_op_modrdn tcl_back_modrdn;
extern BI_op_add tcl_back_add;
extern BI_op_delete tcl_back_delete;
extern BI_op_abandon tcl_back_abandon;
LDAP_END_DECL
#endif /* _TCL_EXTERNAL_H */

View file

@ -1,59 +0,0 @@
/* $OpenLDAP$ */
/* abandon.c - tcl abandon routine
*
* 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 "slap.h"
#include "tcl_back.h"
int
tcl_back_abandon (
Operation * op,
SlapReply * rs
)
{
char *results, *command;
struct berval suf_tcl;
int code, err = 0;
struct tclinfo *ti = (struct tclinfo *) op->o_bd->be_private;
if (ti->ti_abandon.bv_len == 0) {
return (-1);
}
if (tcl_merge_bvlist(op->o_bd->be_suffix, &suf_tcl) == NULL) {
return (-1);
}
command = (char *) ch_malloc (ti->ti_abandon.bv_len + suf_tcl.bv_len
+ 80);
sprintf (command, "%s ABANDON {%ld/%ld} {%s} {%ld/%d}",
ti->ti_abandon.bv_val, op->o_connid, (long) op->o_msgid,
suf_tcl.bv_val, op->o_connid, op->oq_abandon.rs_msgid);
Tcl_Free (suf_tcl.bv_val);
ldap_pvt_thread_mutex_lock (&tcl_interpreter_mutex);
code = Tcl_GlobalEval (ti->ti_ii->interp, command);
results = (char *) ch_strdup (ti->ti_ii->interp->result);
ldap_pvt_thread_mutex_unlock (&tcl_interpreter_mutex);
free (command);
if (code != TCL_OK) {
err = LDAP_OTHER;
Debug (LDAP_DEBUG_SHELL, "tcl_abandon_error: %s\n", results,
0, 0);
}
free (results);
return (err);
}

View file

@ -1,71 +0,0 @@
/* $OpenLDAP$ */
/* add.c - tcl add routine
*
* 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 "slap.h"
#include "tcl_back.h"
int
tcl_back_add (
Operation * op,
SlapReply * rs
)
{
char *command, *entrystr, *results;
struct berval suf_tcl;
int code;
struct tclinfo *ti = (struct tclinfo *) op->o_bd->be_private;
if (ti->ti_add.bv_len == 0) {
send_ldap_error (op, rs, LDAP_UNWILLING_TO_PERFORM,
"add not implemented" );
return (-1);
}
if (tcl_merge_bvlist (op->o_bd->be_suffix, &suf_tcl) == NULL) {
send_ldap_error (op, rs, LDAP_OTHER, NULL);
return (-1);
}
entrystr = tcl_clean_entry(op->oq_add.rs_e);
command = (char *) ch_malloc (ti->ti_add.bv_len + suf_tcl.bv_len +
strlen(entrystr) + 52);
sprintf (command, "%s ADD {%ld/%ld} {%s} {%s}",
ti->ti_add.bv_val, op->o_connid, (long) op->o_msgid,
suf_tcl.bv_val, entrystr);
Tcl_Free (suf_tcl.bv_val);
free (entrystr);
ldap_pvt_thread_mutex_lock (&tcl_interpreter_mutex);
code = Tcl_GlobalEval (ti->ti_ii->interp, command);
results = (char *) ch_strdup (ti->ti_ii->interp->result);
ldap_pvt_thread_mutex_unlock (&tcl_interpreter_mutex);
free (command);
if (code != TCL_OK) {
rs->sr_err = LDAP_OTHER;
Debug (LDAP_DEBUG_SHELL, "tcl_add_error: %s\n", results, 0, 0);
} else {
interp_send_results (op, rs, results);
}
if (rs->sr_err != LDAP_SUCCESS) {
rs->sr_text = "internal backend error";
send_ldap_result (op, rs);
}
free (results);
return (rs->sr_err);
}

View file

@ -1,62 +0,0 @@
/* $OpenLDAP$ */
/* tcl_back.h - tcl backend header (structs, functions)
*
* 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 <tcl.h>
#ifndef SLAPD_TCL_H
#define SLAPD_TCL_H
#include <ldap_cdefs.h>
#include "external.h"
extern ldap_pvt_thread_mutex_t tcl_interpreter_mutex;
struct i_info {
Tcl_Interp *interp;
char *name;
struct i_info *next;
int count;
};
extern struct i_info *global_i;
struct tclinfo {
struct berval ti_script_path;
struct i_info *ti_ii;
struct berval ti_bind;
struct berval ti_unbind;
struct berval ti_search;
struct berval ti_compare;
struct berval ti_modify;
struct berval ti_modrdn;
struct berval ti_add;
struct berval ti_delete;
struct berval ti_abandon;
};
void readtclscript (char *script, Tcl_Interp * my_tcl);
char *tcl_clean_entry (Entry * e);
struct berval *tcl_merge_bvlist (BerVarray bvlist, struct berval *out);
int tcl_ldap_debug (
ClientData clientData,
Tcl_Interp * interp,
int argc,
char *argv[]
);
int interp_send_results (
Operation * op,
SlapReply * rs,
char *result
);
#endif

View file

@ -1,68 +0,0 @@
/* $OpenLDAP$ */
/* bind.c - tcl bind routines
*
* 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 "slap.h"
#include "tcl_back.h"
int
tcl_back_bind (
Operation * op,
SlapReply * rs )
{
char *command, *results;
struct berval suf_tcl;
int code;
struct tclinfo *ti = (struct tclinfo *) op->o_bd->be_private;
if (ti->ti_bind.bv_len == 0) {
send_ldap_error (op, rs, LDAP_UNWILLING_TO_PERFORM,
"bind not implemented" );
return (-1);
}
if (tcl_merge_bvlist (op->o_bd->be_suffix, &suf_tcl) == NULL) {
send_ldap_error (op, rs, LDAP_OTHER, NULL );
return (-1);
}
command = (char *) ch_malloc (ti->ti_bind.bv_len + suf_tcl.bv_len +
op->o_req_dn.bv_len + op->oq_bind.rb_cred.bv_len + 84);
sprintf (command, "%s BIND {%ld/%ld} {%s} {%s} {%d} {%lu} {%s}",
ti->ti_bind.bv_val, op->o_connid, (long) op->o_msgid,
suf_tcl.bv_val,
op->o_req_dn.bv_val, op->oq_bind.rb_method, op->oq_bind.rb_cred.bv_len, op->oq_bind.rb_cred.bv_val);
Tcl_Free (suf_tcl.bv_val);
ldap_pvt_thread_mutex_lock (&tcl_interpreter_mutex);
code = Tcl_GlobalEval (ti->ti_ii->interp, command);
results = (char *) ch_strdup (ti->ti_ii->interp->result);
ldap_pvt_thread_mutex_unlock (&tcl_interpreter_mutex);
free (command);
if (code != TCL_OK) {
rs->sr_err = LDAP_OTHER;
Debug (LDAP_DEBUG_SHELL, "tcl_bind_error: %s\n", results, 0, 0);
} else {
rs->sr_err = interp_send_results (op, rs, results);
}
if (rs->sr_err != LDAP_SUCCESS) {
rs->sr_text = "internal backend error";
send_ldap_result (op, rs);
}
free (results);
return (rs->sr_err);
}

View file

@ -1,82 +0,0 @@
/* $OpenLDAP$ */
/* close.c - tcl close routines
*
* 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 "slap.h"
#include "tcl_back.h"
int
tcl_back_close (
BackendInfo * bi
)
{
Tcl_DeleteInterp (global_i->interp);
return (0);
}
int
tcl_back_destroy (
BackendInfo * bi
)
{
free (global_i->interp);
free (global_i);
ldap_pvt_thread_mutex_destroy (&tcl_interpreter_mutex);
return (0);
}
int
tcl_back_db_close (
BackendDB * bd
)
{
struct tclinfo *ti = (struct tclinfo *) bd->be_private;
struct i_info *ti_tmp;
/* Disable the interp and associated struct */
ti->ti_ii->count--;
if (!ti->ti_ii->count && strcasecmp ("default", ti->ti_ii->name)) {
/* no more db's using this and it's not the default */
for (ti_tmp = global_i; ti_tmp->next != ti->ti_ii; ti_tmp
= ti_tmp->next);
/* This bypasses this interp struct in the global hash */
ti_tmp->next = ti->ti_ii->next;
Tcl_DeleteInterp (ti->ti_ii->interp);
}
return (0);
}
int
tcl_back_db_destroy (
BackendDB * bd
)
{
struct tclinfo *ti = (struct tclinfo *) bd->be_private;
/*
* Now free up the allocated memory used
*/
ti->ti_ii->count--;
if (!ti->ti_ii->count && strcasecmp ("default", ti->ti_ii->name)) {
free (ti->ti_ii->interp);
free (ti->ti_ii);
free (ti);
}
free (bd->be_private);
bd->be_private = NULL;
return (0);
}

View file

@ -1,71 +0,0 @@
/* $OpenLDAP$ */
/* compare.c - tcl compare routines
*
* 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 "slap.h"
#include "tcl_back.h"
int
tcl_back_compare (
Operation * op,
SlapReply * rs
)
{
char *command, *results;
struct berval suf_tcl;
int code;
struct tclinfo *ti = (struct tclinfo *) op->o_bd->be_private;
if (ti->ti_compare.bv_len == 0) {
send_ldap_error (op, rs, LDAP_UNWILLING_TO_PERFORM,
"compare not implemented" );
return (-1);
}
if (tcl_merge_bvlist (op->o_bd->be_suffix, &suf_tcl) == NULL) {
send_ldap_error (op, rs, LDAP_OTHER, NULL );
return (-1);
}
command = (char *) ch_malloc (ti->ti_compare.bv_len +
suf_tcl.bv_len + op->o_req_dn.bv_len + op->oq_compare.rs_ava->aa_desc->ad_cname.bv_len +
op->oq_compare.rs_ava->aa_value.bv_len + 84);
sprintf (command, "%s COMPARE {%ld/%ld} {%s} {%s} {%s: %s}",
ti->ti_compare.bv_val, op->o_connid, (long) op->o_msgid,
suf_tcl.bv_val, op->o_req_dn.bv_val,
op->oq_compare.rs_ava->aa_desc->ad_cname.bv_val, op->oq_compare.rs_ava->aa_value.bv_val);
Tcl_Free (suf_tcl.bv_val);
ldap_pvt_thread_mutex_lock (&tcl_interpreter_mutex);
code = Tcl_GlobalEval (ti->ti_ii->interp, command);
results = (char *) ch_strdup (ti->ti_ii->interp->result);
ldap_pvt_thread_mutex_unlock (&tcl_interpreter_mutex);
free (command);
if (code != TCL_OK) {
rs->sr_err = LDAP_OTHER;
Debug (LDAP_DEBUG_SHELL, "tcl_compare_error: %s\n", results,
0, 0);
} else {
interp_send_results (op, rs, results);
}
if (rs->sr_err != LDAP_SUCCESS) {
rs->sr_text = "internal backend error";
send_ldap_result (op, rs);
}
free (results);
return (rs->sr_err);
}

View file

@ -1,181 +0,0 @@
/* $OpenLDAP$ */
/* config.c - tcl backend configuration file routine
*
* 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 "slap.h"
#include "tcl_back.h"
struct i_info *global_i;
int
tcl_back_db_config (
BackendDB * bd,
const char *fname,
int lineno,
int argc,
char **argv
)
{
struct tclinfo *ti = (struct tclinfo *) bd->be_private;
if (ti == NULL) {
fprintf (stderr,
"%s: line %d: tcl backend info is null!\n", fname,
lineno);
return (1);
}
if (ti->ti_ii == NULL) {
ti->ti_ii = global_i;
}
/* Script to load */
if (strcasecmp (argv[0], "scriptpath") == 0) {
if (argc < 2) {
Debug (LDAP_DEBUG_CONFIG,
"%s: line %d: missing script in \"scriptpath <script>\" line\n",
fname, lineno, 0);
return (1);
}
ber_str2bv( argv[1], 0, 1, &ti->ti_script_path );
/* use local interpreter */
} else if (strcasecmp (argv[0], "tclrealm") == 0) {
struct i_info *ii;
if (argc < 2) {
Debug (LDAP_DEBUG_CONFIG,
"%s: line %d: missing script in \"tclrealm <name>\" line\n",
fname, lineno, 0);
return (1);
}
ti->ti_ii = NULL;
ii = global_i;
/* Try to see if it already exists */
do {
if (ii != NULL && !strcasecmp (ii->name, argv[1]))
ti->ti_ii = ii;
if (ii->next != NULL)
ii = ii->next;
} while (ii->next != NULL);
if (ti->ti_ii == NULL) { /* we need to make a new one */
ii->next = (struct i_info *) ch_malloc
(sizeof (struct i_info));
ii->next->count = 0;
ii->next->name = (char *) ch_strdup (argv[1]);
ii->next->interp = NULL;
ii->next->next = NULL;
ti->ti_ii = ii->next;
}
/* proc for binds */
} else if (strcasecmp (argv[0], "bind") == 0) {
if (argc < 2) {
Debug (LDAP_DEBUG_CONFIG,
"%s: line %d: missing proc in \"bind <proc>\" line\n",
fname, lineno, 0);
return (1);
}
ber_str2bv( argv[1], 0, 1, &ti->ti_bind );
/* proc for unbinds */
} else if (strcasecmp (argv[0], "unbind") == 0) {
if (argc < 2) {
Debug (LDAP_DEBUG_CONFIG,
"%s: line %d: missing proc in \"unbind <proc>\" line\n",
fname, lineno, 0);
return (1);
}
ber_str2bv( argv[1], 0, 1, &ti->ti_unbind );
/* proc for search */
} else if (strcasecmp (argv[0], "search") == 0) {
if (argc < 2) {
Debug (LDAP_DEBUG_CONFIG,
"%s: line %d: missing proc in \"search <proc>\" line\n",
fname, lineno, 0);
return (1);
}
ber_str2bv( argv[1], 0, 1, &ti->ti_search );
/* proc for compares */
} else if (strcasecmp (argv[0], "compare") == 0) {
if (argc < 2) {
Debug (LDAP_DEBUG_CONFIG,
"%s: line %d: missing proc in \"compare <proc>\" line\n",
fname, lineno, 0);
return (1);
}
ber_str2bv( argv[1], 0, 1, &ti->ti_compare );
/* proc for modify */
} else if (strcasecmp (argv[0], "modify") == 0) {
if (argc < 2) {
Debug (LDAP_DEBUG_CONFIG,
"%s: line %d: missing proc in \"modify <proc>\" line\n",
fname, lineno, 0);
return (1);
}
ber_str2bv( argv[1], 0, 1, &ti->ti_modify );
/* proc for modrdn */
} else if (strcasecmp (argv[0], "modrdn") == 0) {
if (argc < 2) {
Debug (LDAP_DEBUG_CONFIG,
"%s: line %d: missing proc in \"modrdn <proc>\" line\n",
fname, lineno, 0);
return (1);
}
ber_str2bv( argv[1], 0, 1, &ti->ti_modrdn );
/* proc for add */
} else if (strcasecmp (argv[0], "add") == 0) {
if (argc < 2) {
Debug (LDAP_DEBUG_CONFIG,
"%s: line %d: missing proc in \"add <proc>\" line\n",
fname, lineno, 0);
return (1);
}
ber_str2bv( argv[1], 0, 1, &ti->ti_add );
/* proc for delete */
} else if (strcasecmp (argv[0], "delete") == 0) {
if (argc < 2) {
Debug (LDAP_DEBUG_CONFIG,
"%s: line %d: missing proc in \"delete <proc>\" line\n",
fname, lineno, 0);
return (1);
}
ber_str2bv( argv[1], 0, 1, &ti->ti_delete );
/* proc for abandon */
} else if (strcasecmp (argv[0], "abandon") == 0) {
if (argc < 2) {
Debug (LDAP_DEBUG_CONFIG,
"%s: line %d: missing proc in \"abandon <proc>\" line\n",
fname, lineno, 0);
return (1);
}
ber_str2bv( argv[1], 0, 1, &ti->ti_abandon );
} else {
Debug (LDAP_DEBUG_CONFIG,
"Unknown tcl backend config: %s\n", argv[0], 0, 0);
return (1);
}
return 0;
}

View file

@ -1,69 +0,0 @@
/* $OpenLDAP$ */
/* delete.c - tcl delete routines
*
* 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 "slap.h"
#include "tcl_back.h"
int
tcl_back_delete (
Operation * op,
SlapReply * rs
)
{
char *command, *results;
struct berval suf_tcl;
int code, err = 0;
struct tclinfo *ti = (struct tclinfo *) op->o_bd->be_private;
if (ti->ti_delete.bv_len == 0) {
send_ldap_error (op, rs, LDAP_UNWILLING_TO_PERFORM,
"delete not implemented" );
return (-1);
}
if (tcl_merge_bvlist (op->o_bd->be_suffix, &suf_tcl) == NULL) {
send_ldap_error (op, rs, LDAP_OTHER, NULL);
return (-1);
}
command = (char *) ch_malloc (ti->ti_delete.bv_len + suf_tcl.bv_len
+ op->o_req_dn.bv_len + 84);
sprintf (command, "%s DELETE {%ld/%ld} {%s} {%s}",
ti->ti_delete.bv_val, op->o_connid, (long) op->o_msgid,
suf_tcl.bv_val, op->o_req_dn.bv_val);
Tcl_Free (suf_tcl.bv_val);
ldap_pvt_thread_mutex_lock (&tcl_interpreter_mutex);
code = Tcl_GlobalEval (ti->ti_ii->interp, command);
results = (char *) ch_strdup (ti->ti_ii->interp->result);
ldap_pvt_thread_mutex_unlock (&tcl_interpreter_mutex);
free (command);
if (code != TCL_OK) {
rs->sr_err = LDAP_OTHER;
Debug (LDAP_DEBUG_SHELL, "tcl_delete_error: %s\n", results,
0, 0);
} else {
interp_send_results (op, rs, results);
}
if (rs->sr_err != LDAP_SUCCESS) {
rs->sr_text = "internal backend error";
send_ldap_result (op, rs);
}
free (results);
return (rs->sr_err);
}

View file

@ -1,174 +0,0 @@
/* $OpenLDAP$ */
/* tcl_init.c - tcl backend initialization
*
* 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/socket.h>
#include "slap.h"
#include "tcl_back.h"
ldap_pvt_thread_mutex_t tcl_interpreter_mutex;
#ifdef SLAPD_TCL_DYNAMIC
void init_module(int argc, char *argv[]) {
BackendInfo bi;
memset( &bi, '\0', sizeof(bi) );
bi.bi_type = "tcl";
bi.bi_init = tcl_back_initialize;
backend_add(&bi);
}
#endif /* SLAPD_TCL_DYNAMIC */
int
tcl_back_initialize (
BackendInfo * bi
)
{
/* Initialize the global interpreter array */
global_i = (struct i_info *) ch_malloc (sizeof (struct i_info));
global_i->count = 0;
global_i->name = "default";
global_i->next = NULL;
global_i->interp = Tcl_CreateInterp ();
Tcl_Init (global_i->interp);
/* Initialize the global interpreter lock */
ldap_pvt_thread_mutex_init (&tcl_interpreter_mutex);
bi->bi_open = tcl_back_open;
bi->bi_config = 0;
bi->bi_close = tcl_back_close;
bi->bi_destroy = tcl_back_destroy;
bi->bi_db_init = tcl_back_db_init;
bi->bi_db_config = tcl_back_db_config;
bi->bi_db_open = tcl_back_db_open;
bi->bi_db_close = tcl_back_db_close;
bi->bi_db_destroy = tcl_back_db_destroy;
bi->bi_op_bind = tcl_back_bind;
bi->bi_op_unbind = tcl_back_unbind;
bi->bi_op_search = tcl_back_search;
bi->bi_op_compare = tcl_back_compare;
bi->bi_op_modify = tcl_back_modify;
bi->bi_op_modrdn = tcl_back_modrdn;
bi->bi_op_add = tcl_back_add;
bi->bi_op_delete = tcl_back_delete;
bi->bi_op_abandon = tcl_back_abandon;
bi->bi_chk_referrals = 0;
bi->bi_connection_init = 0;
bi->bi_connection_destroy = 0;
return 0;
}
int
tcl_back_open (
BackendInfo * bi
)
{
/* Initialize the global interpreter array */
global_i = (struct i_info *) ch_malloc (sizeof (struct i_info));
global_i->count = 0;
global_i->name = "default";
global_i->next = NULL;
global_i->interp = Tcl_CreateInterp ();
Tcl_Init (global_i->interp);
/* Initialize the global interpreter lock */
ldap_pvt_thread_mutex_init (&tcl_interpreter_mutex);
return (0);
}
int
tcl_back_db_init (
Backend * be
)
{
struct tclinfo *ti;
ti = (struct tclinfo *) ch_calloc (1, sizeof (struct tclinfo));
ti->ti_script_path.bv_len = 0;
ti->ti_script_path.bv_val = NULL;
/*
* For some reason this causes problems
* specifically set to NULL
*/
ti->ti_bind.bv_len = 0;
ti->ti_bind.bv_val = NULL;
ti->ti_unbind.bv_len = 0;
ti->ti_unbind.bv_val = NULL;
ti->ti_search.bv_len = 0;
ti->ti_search.bv_val = NULL;
ti->ti_compare.bv_len = 0;
ti->ti_compare.bv_val = NULL;
ti->ti_modify.bv_len = 0;
ti->ti_modify.bv_val = NULL;
ti->ti_modrdn.bv_len = 0;
ti->ti_modrdn.bv_val = NULL;
ti->ti_add.bv_len = 0;
ti->ti_add.bv_val = NULL;
ti->ti_delete.bv_len = 0;
ti->ti_delete.bv_val = NULL;
ti->ti_abandon.bv_len = 0;
ti->ti_abandon.bv_val = NULL;
be->be_private = ti;
return ti == NULL;
}
int
tcl_back_db_open (
BackendDB * bd
)
{
struct tclinfo *ti = (struct tclinfo *) bd->be_private;
if (ti->ti_ii->interp == NULL) { /* we need to make a new one */
ti->ti_ii->interp = Tcl_CreateInterp ();
Tcl_Init (ti->ti_ii->interp);
}
/* raise that count for the interpreter */
ti->ti_ii->count++;
/* now let's (try to) load the script */
readtclscript (ti->ti_script_path.bv_val, ti->ti_ii->interp);
/* install the debug command */
Tcl_CreateCommand (ti->ti_ii->interp, "ldap:debug", &tcl_ldap_debug,
NULL, NULL);
return 0;
}

View file

@ -1,125 +0,0 @@
/* $OpenLDAP$ */
/* modify.c - tcl modify routines
*
* 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 "slap.h"
#include "tcl_back.h"
int
tcl_back_modify (
Operation * op,
SlapReply * rs
)
{
char *command, *bp, *tcl_mods, *results;
struct berval suf_tcl;
int i, code, len, bsize;
struct tclinfo *ti = (struct tclinfo *) op->o_bd->be_private;
Modifications *modlist = op->oq_modify.rs_modlist;
if (ti->ti_modify.bv_len == 0) {
send_ldap_error (op, rs, LDAP_UNWILLING_TO_PERFORM,
"modify not implemented" );
return (-1);
}
if (tcl_merge_bvlist (op->o_bd->be_suffix, &suf_tcl) == NULL) {
send_ldap_error (op, rs, LDAP_OTHER, NULL);
return (-1);
}
tcl_mods = (char *) ch_malloc (BUFSIZ);
tcl_mods[0] = '\0';
bsize = BUFSIZ;
bp = tcl_mods;
for (; modlist != NULL; modlist = modlist->sml_next) {
Modification *mods = &modlist->sml_mod;
const struct berval
op_add = { sizeof("add") - 1, "add" },
op_delete = { sizeof("delete") - 1, "delete" },
op_replace = { sizeof("replace") - 1, "replace" },
*op = NULL;
switch (mods->sm_op & ~LDAP_MOD_BVALUES) {
case LDAP_MOD_ADD:
op = &op_add;
break;
case LDAP_MOD_DELETE:
op = &op_delete;
break;
case LDAP_MOD_REPLACE:
op = &op_replace;
break;
default:
assert(0);
}
len = mods->sm_type.bv_len + op->bv_len + 7;
while (bp + len - tcl_mods > bsize) {
bsize += BUFSIZ;
tcl_mods = (char *) ch_realloc (tcl_mods, bsize);
}
sprintf (bp, "{ {%s: %s} ", op->bv_val, mods->sm_type.bv_val);
bp += len;
for (i = 0;
mods->sm_bvalues != NULL && mods->sm_bvalues[i].bv_val
!= NULL;
i++) {
len = mods->sm_type.bv_len +
mods->sm_bvalues[i].bv_len + 5 +
(mods->sm_bvalues[i + 1].bv_val == NULL ? 2 : 0);
while (bp + len - tcl_mods > bsize) {
bsize += BUFSIZ;
tcl_mods = (char *) ch_realloc (tcl_mods, bsize);
}
sprintf (bp, "{%s: %s} %s", mods->sm_type.bv_val,
mods->sm_bvalues[i].bv_val,
mods->sm_bvalues[i + 1].bv_val ==
NULL ? "} " : "");
bp += len;
}
}
command = (char *) ch_malloc (ti->ti_modify.bv_len + suf_tcl.bv_len
+ op->o_req_dn.bv_len + strlen (tcl_mods) + 84);
/* This space is simply for aesthetics--\ */
sprintf (command, "%s MODIFY {%ld/%ld} {%s} {%s} { %s}",
ti->ti_modify.bv_val, op->o_connid, (long) op->o_msgid,
suf_tcl.bv_val, op->o_req_dn.bv_val, tcl_mods);
Tcl_Free (suf_tcl.bv_val);
free (tcl_mods);
ldap_pvt_thread_mutex_lock (&tcl_interpreter_mutex);
code = Tcl_GlobalEval (ti->ti_ii->interp, command);
results = (char *) ch_strdup (ti->ti_ii->interp->result);
ldap_pvt_thread_mutex_unlock (&tcl_interpreter_mutex);
free (command);
if (code != TCL_OK) {
rs->sr_err = LDAP_OTHER;
Debug (LDAP_DEBUG_SHELL, "tcl_modify_error: %s\n", results,
0, 0);
} else {
interp_send_results (op, rs, results);
}
if (rs->sr_err != LDAP_SUCCESS) {
rs->sr_text = "internal backend error";
send_ldap_result (op, rs);
}
free (results);
return (rs->sr_err);
}

View file

@ -1,93 +0,0 @@
/* $OpenLDAP$ */
/* modrdn.c - tcl modify rdn routines
*
* 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.
*/
/*
* LDAP v3 newSuperior support.
*
* Copyright 1999, Juan C. Gomez, All rights reserved.
* This software is not subject to any license of Silicon Graphics
* Inc. or Purdue University.
*
* Redistribution and use in source and binary forms are permitted
* without restriction or fee of any kind as long as this notice
* is preserved.
*
*/
#include "portable.h"
#include <stdio.h>
#include "slap.h"
#include "tcl_back.h"
int
tcl_back_modrdn (
Operation * op,
SlapReply * rs
)
{
char *command, *results;
struct berval suf_tcl;
int code;
struct tclinfo *ti = (struct tclinfo *) op->o_bd->be_private;
if (ti->ti_modrdn.bv_len == 0) {
send_ldap_error (op, rs, LDAP_UNWILLING_TO_PERFORM,
"modrdn not implemented" );
return (-1);
}
if (tcl_merge_bvlist (op->o_bd->be_suffix, &suf_tcl) == NULL) {
send_ldap_error (op, rs, LDAP_OTHER, NULL);
return (-1);
}
command = (char *) ch_malloc (ti->ti_modrdn.bv_len + suf_tcl.bv_len
+ op->o_req_dn.bv_len + op->oq_modrdn.rs_newrdn.bv_len
+ (op->oq_modrdn.rs_newSup ? op->oq_modrdn.rs_newSup->bv_len : 0) + 84);
if ( op->oq_modrdn.rs_newSup ) {
sprintf (command, "%s MODRDN {%ld/%ld} {%s} {%s} {%s} %d {%s}",
ti->ti_modrdn.bv_val,
op->o_connid, (long) op->o_msgid,
suf_tcl.bv_val, op->o_req_dn.bv_val,
op->oq_modrdn.rs_newrdn.bv_val, op->oq_modrdn.rs_deleteoldrdn ? 1 : 0,
op->oq_modrdn.rs_newSup->bv_val );
} else {
sprintf (command, "%s MODRDN {%ld} {%s} {%s} {%s} %d",
ti->ti_modrdn.bv_val, (long) op->o_msgid,
suf_tcl.bv_val, op->o_req_dn.bv_val,
op->oq_modrdn.rs_newrdn.bv_val, op->oq_modrdn.rs_deleteoldrdn ? 1 : 0 );
}
Tcl_Free (suf_tcl.bv_val);
ldap_pvt_thread_mutex_lock (&tcl_interpreter_mutex);
code = Tcl_GlobalEval (ti->ti_ii->interp, command);
results = (char *) ch_strdup (ti->ti_ii->interp->result);
ldap_pvt_thread_mutex_unlock (&tcl_interpreter_mutex);
free (command);
if (code != TCL_OK) {
rs->sr_err = LDAP_OTHER;
Debug (LDAP_DEBUG_SHELL, "tcl_modrdn_error: %s\n", results,
0, 0);
} else {
interp_send_results (op, rs, results);
}
if (rs->sr_err != LDAP_SUCCESS) {
rs->sr_text = "internal backend error";
send_ldap_result (op, rs);
}
free (results);
return (rs->sr_err);
}

View file

@ -1,85 +0,0 @@
/* $OpenLDAP$ */
/* search.c - tcl search routines
*
* 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 "slap.h"
#include "tcl_back.h"
int
tcl_back_search (
Operation * op,
SlapReply * rs )
{
char *attrs_tcl = NULL, *results, *command;
struct berval suf_tcl;
int i, code;
struct tclinfo *ti = (struct tclinfo *) op->o_bd->be_private;
AttributeName *an;
if (ti->ti_search.bv_len == 0) {
send_ldap_error (op, rs, LDAP_UNWILLING_TO_PERFORM,
"search not implemented" );
return (-1);
}
for (i = 0, an = op->oq_search.rs_attrs; an && an->an_name.bv_val; an++, i++);
if (i > 0) {
char **sattrs = ch_malloc( (i+1) * sizeof(char *));
for (i = 0, an = op->oq_search.rs_attrs; an->an_name.bv_val; an++, i++)
sattrs[i] = an->an_name.bv_val;
sattrs[i] = NULL;
attrs_tcl = Tcl_Merge (i, sattrs);
ch_free(sattrs);
}
if (tcl_merge_bvlist (op->o_bd->be_suffix, &suf_tcl) == NULL) {
Tcl_Free (attrs_tcl);
send_ldap_error (op, rs, LDAP_OTHER, NULL);
return (-1);
}
command = (char *) ch_malloc (ti->ti_search.bv_len + suf_tcl.bv_len
+ op->o_req_dn.bv_len + 60 + op->oq_search.rs_filterstr.bv_len +
(attrs_tcl == NULL ? 5 : strlen (attrs_tcl)) + 72);
sprintf (command,
"%s SEARCH {%ld/%ld} {%s} {%s} {%d} {%d} {%d} {%d} {%s} {%d} {%s}",
ti->ti_search.bv_val, op->o_connid, (long) op->o_msgid,
suf_tcl.bv_val, op->o_req_dn.bv_val, op->oq_search.rs_scope, op->oq_search.rs_deref,
op->oq_search.rs_slimit, op->oq_search.rs_tlimit, op->oq_search.rs_filterstr.bv_val,
op->oq_search.rs_attrsonly ? 1 : 0, attrs_tcl == NULL ? "{all}" : attrs_tcl);
Tcl_Free (attrs_tcl);
Tcl_Free (suf_tcl.bv_val);
ldap_pvt_thread_mutex_lock (&tcl_interpreter_mutex);
code = Tcl_GlobalEval (ti->ti_ii->interp, command);
results = (char *) ch_strdup (ti->ti_ii->interp->result);
ldap_pvt_thread_mutex_unlock (&tcl_interpreter_mutex);
free (command);
if (code != TCL_OK) {
rs->sr_err = LDAP_OTHER;
Debug (LDAP_DEBUG_SHELL, "tcl_search_error: %s\n", results,
0, 0);
} else {
interp_send_results (op, rs, results );
}
if (rs->sr_err != LDAP_SUCCESS) {
rs->sr_text = "internal backend error";
send_ldap_result (op, rs );
}
free (results);
return (rs->sr_err);
}

View file

@ -1,58 +0,0 @@
/* $OpenLDAP$ */
/* unbind.c - tcl unbind routines
*
* 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 "slap.h"
#include "tcl_back.h"
int
tcl_back_unbind (
Operation * op,
SlapReply * rs
)
{
char *command, *results;
struct berval suf_tcl;
int code, err = 0;
struct tclinfo *ti = (struct tclinfo *) op->o_bd->be_private;
if (ti->ti_unbind.bv_len == 0) {
return (-1);
}
if (tcl_merge_bvlist (op->o_bd->be_suffix, &suf_tcl) == NULL) {
return (-1);
}
command = (char *) ch_malloc (ti->ti_unbind.bv_len + suf_tcl.bv_len
+ op->o_conn->c_dn.bv_len + 84);
sprintf (command, "%s UNBIND {%ld/%ld} {%s} {%s}",
ti->ti_unbind.bv_val, op->o_connid, (long) op->o_msgid,
suf_tcl.bv_val, op->o_conn->c_dn.bv_val ? op->o_conn->c_dn.bv_val : "");
Tcl_Free (suf_tcl.bv_val);
ldap_pvt_thread_mutex_lock (&tcl_interpreter_mutex);
code = Tcl_GlobalEval (ti->ti_ii->interp, command);
results = (char *) ch_strdup (ti->ti_ii->interp->result);
ldap_pvt_thread_mutex_unlock (&tcl_interpreter_mutex);
free (command);
if (code != TCL_OK) {
Debug (LDAP_DEBUG_SHELL, "tcl_unbind_error: %s\n", results,
0, 0);
}
free (results);
return (err);
}

View file

@ -1,231 +0,0 @@
/* $OpenLDAP$ */
/* result.c - tcl backend utility functions
*
* 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
interp_send_results (
Operation * op,
SlapReply * rs,
char *result
)
{
int bsize, len, argcPtr, i, code;
char *buf, *bp, **argvPtr, *line;
struct tclinfo *ti = (struct tclinfo *) op->o_bd->be_private;
/*
* read in the result and send it along
*/
buf = (char *) ch_malloc (BUFSIZ);
buf[0] = '\0';
bsize = BUFSIZ;
bp = buf;
code = Tcl_SplitList (ti->ti_ii->interp, result, &argcPtr, &argvPtr);
if (code != TCL_OK) {
argcPtr = 0;
send_ldap_error (op, rs, LDAP_UNWILLING_TO_PERFORM,
"internal backend error" );
return -1;
}
for (i = 0; i < argcPtr; i++) {
line = argvPtr[i];
/*
* ignore lines beginning with DEBUG:
*/
if (strncasecmp (line, "DEBUG:", 6) == 0) {
continue;
}
len = strlen (line) + 1;
while (bp + len - buf > bsize) {
bsize += BUFSIZ;
buf = (char *) ch_realloc (buf, bsize);
}
sprintf (bp, "%s\n", line);
bp += len;
/*
* line marked the end of an entry or result
*/
if (line[0] == '\0') {
if (strncasecmp (buf, "RESULT", 6) == 0) {
break;
}
if ((rs->sr_entry = str2entry (buf)) == NULL) {
Debug (LDAP_DEBUG_SHELL,
"str2entry(%s) failed\n",
buf, 0, 0);
} else {
rs->sr_attrs = op->oq_search.rs_attrs;
send_search_entry (op, rs);
entry_free (rs->sr_entry);
}
bp = buf;
}
}
(void) str2result (buf, &rs->sr_err, (char **)&rs->sr_matched, (char **)&rs->sr_text);
/*
* otherwise, front end will send this result
*/
if (rs->sr_err != 0 || op->o_tag != LDAP_REQ_BIND) {
send_ldap_result (op, rs);
}
free (buf);
Tcl_Free ((char *) argvPtr);
return (rs->sr_err);
}
char *
tcl_clean_entry (
Entry * e
)
{
char *entrystr, *mark1, *mark2, *buf, *bp, *dup;
int len, bsize;
ldap_pvt_thread_mutex_lock(&entry2str_mutex);
entrystr = entry2str (e, &len);
buf = (char *) ch_malloc (BUFSIZ);
buf[0] = '\0';
bsize = BUFSIZ;
bp = buf;
bp++[0] = ' ';
mark1 = entrystr;
do {
if (mark1[0] == '\n') {
mark1++;
}
dup = (char *) ch_strdup (mark1);
if (dup[0] != '\0') {
if ((mark2 = (char *) strchr (dup, '\n')) != NULL) {
mark2[0] = '\0';
}
len = strlen (dup) + 3;
while (bp + len - buf > bsize) {
bsize += BUFSIZ;
buf = (char *) ch_realloc (buf, bsize);
}
if (mark1[0] == '\0') {
sprintf (bp, "{} ");
} else {
sprintf (bp, "{%s} ", dup);
}
bp += len;
if (mark2 != NULL) {
mark2[0] = '\n';
}
}
free (dup);
} while ((mark1 = (char *) strchr (mark1, '\n')) != NULL);
ldap_pvt_thread_mutex_unlock (&entry2str_mutex);
return buf;
}
int
tcl_ldap_debug (
ClientData clientData,
Tcl_Interp * interp,
int argc,
char *argv[]
)
{
if (argv[1] != NULL) {
Debug (LDAP_DEBUG_SHELL, "tcl_debug: %s\n", argv[1], 0, 0);
}
return TCL_OK;
}
void
readtclscript (
char *script,
Tcl_Interp * my_tcl)
{
int code;
FILE *f;
f = fopen (script, "r");
if (f == NULL) {
Debug (LDAP_DEBUG_SHELL, "Could not open scriptpath %s\n", script,
0, 0);
return;
}
fclose (f);
code = Tcl_EvalFile (my_tcl, script);
if (code != TCL_OK) {
Debug (LDAP_DEBUG_SHELL, "%s: %s\n", script,
Tcl_GetVar (my_tcl, "errorInfo", TCL_GLOBAL_ONLY), 0);
Debug (LDAP_DEBUG_SHELL, "%s: error at line\n", script,
my_tcl->errorLine, 0);
return;
}
}
struct berval *
tcl_merge_bvlist(
BerVarray bvlist, struct berval *out)
{
struct berval *ret = NULL;
int i;
if (bvlist == NULL)
return NULL;
if (out == NULL) {
ret = (struct berval *)ch_malloc(sizeof(struct berval));
if (ret == NULL) {
return NULL;
}
} else {
ret = out;
}
ret->bv_len = 0;
ret->bv_val = NULL;
for (i = 0; bvlist[i].bv_val != NULL; i++);
if (i) {
char **strlist = ch_malloc ((i + 1) * sizeof(char *));
if (strlist == NULL) {
if (out == NULL)
ch_free (ret);
return NULL;
}
for (i = 0; bvlist[i].bv_val != NULL; i++) {
strlist[i] = bvlist[i].bv_val;
}
strlist[i] = NULL;
ret->bv_val = Tcl_Merge(i, strlist);
ret->bv_len = ret->bv_val ? strlen(ret->bv_val) : 0;
ch_free (strlist);
}
return ret;
}