From 8667671d1733b344c51150e28a3090bc4d64feb2 Mon Sep 17 00:00:00 2001 From: Ben Collins <bcollins@openldap.org> Date: Thu, 18 Feb 1999 02:18:39 +0000 Subject: [PATCH] * Removed uneeded cvs keywords * Fixed unfree'd 'char *results' in all tcl_* functions (only unfree'd in certain cases, moved the free to the actual function) so no more mem leaks. Tested this with over 500,000 access's for testing :) * Miscellaneous source style and tabulation fixes --- servers/slapd/back-tcl/TODO | 2 - servers/slapd/back-tcl/Version.c | 3 +- servers/slapd/back-tcl/external.h | 73 ++++++----- servers/slapd/back-tcl/tcl_abandon.c | 59 ++++----- servers/slapd/back-tcl/tcl_add.c | 48 +++---- servers/slapd/back-tcl/tcl_back.h | 67 +++++----- servers/slapd/back-tcl/tcl_bind.c | 47 +++---- servers/slapd/back-tcl/tcl_close.c | 64 +++++----- servers/slapd/back-tcl/tcl_compare.c | 47 ++++--- servers/slapd/back-tcl/tcl_config.c | 95 ++++++-------- servers/slapd/back-tcl/tcl_delete.c | 43 ++++--- servers/slapd/back-tcl/tcl_init.c | 47 ++++--- servers/slapd/back-tcl/tcl_modify.c | 87 ++++++------- servers/slapd/back-tcl/tcl_modrdn.c | 49 ++++---- servers/slapd/back-tcl/tcl_search.c | 58 ++++----- servers/slapd/back-tcl/tcl_unbind.c | 47 +++---- servers/slapd/back-tcl/tcl_util.c | 182 ++++++++++++++++----------- 17 files changed, 508 insertions(+), 510 deletions(-) diff --git a/servers/slapd/back-tcl/TODO b/servers/slapd/back-tcl/TODO index 2a85e15e92..f118d731e1 100644 --- a/servers/slapd/back-tcl/TODO +++ b/servers/slapd/back-tcl/TODO @@ -2,5 +2,3 @@ * Add a version, callable from the tcl script for checking features -* don't expand tabs for spaces... - diff --git a/servers/slapd/back-tcl/Version.c b/servers/slapd/back-tcl/Version.c index 7518460f36..ad78076533 100644 --- a/servers/slapd/back-tcl/Version.c +++ b/servers/slapd/back-tcl/Version.c @@ -1,4 +1,5 @@ -/* +/* $Id$ + * * Copyright 1999, Ben Collins <bcollins@debian.org>, All rights reserved. * * Redistribution and use in source and binary forms are permitted only diff --git a/servers/slapd/back-tcl/external.h b/servers/slapd/back-tcl/external.h index e65fb2edc7..62b75e8018 100644 --- a/servers/slapd/back-tcl/external.h +++ b/servers/slapd/back-tcl/external.h @@ -1,59 +1,56 @@ -/* - * $Id: external.h,v 1.3 1999/02/16 23:26:05 bcollins Exp $ - */ +/* $Id: external.h,v 1.4 1999/02/17 00:55:03 bcollins Exp $ */ #ifndef _TCL_EXTERNAL_H #define _TCL_EXTERNAL_H LDAP_BEGIN_DECL -extern int tcl_back_initialize LDAP_P(( BackendInfo *bi )); -extern int tcl_back_open LDAP_P(( BackendInfo *bi )); -extern int tcl_back_close LDAP_P(( BackendInfo *bi )); -extern int tcl_back_destroy LDAP_P(( BackendInfo *bi )); +extern int tcl_back_initialize LDAP_P ((BackendInfo * bi)); +extern int tcl_back_open LDAP_P ((BackendInfo * bi)); +extern int tcl_back_close LDAP_P ((BackendInfo * bi)); +extern int tcl_back_destroy LDAP_P ((BackendInfo * bi)); -extern int tcl_back_db_init LDAP_P(( BackendDB *bd )); -extern int tcl_back_db_open LDAP_P(( BackendDB *bd )); -extern int tcl_back_db_close LDAP_P(( BackendDB *bd )); -extern int tcl_back_db_destroy LDAP_P(( BackendDB *bd )); +extern int tcl_back_db_init LDAP_P ((BackendDB * bd)); +extern int tcl_back_db_open LDAP_P ((BackendDB * bd)); +extern int tcl_back_db_close LDAP_P ((BackendDB * bd)); +extern int tcl_back_db_destroy LDAP_P ((BackendDB * bd)); -extern int tcl_back_db_config LDAP_P(( BackendDB *bd, - char *fname, int lineno, int argc, char **argv )); +extern int tcl_back_db_config LDAP_P ((BackendDB * bd, + char *fname, int lineno, int argc, char **argv)); -extern int tcl_back_bind LDAP_P(( BackendDB *bd, - Connection *conn, Operation *op, - char *dn, int method, struct berval *cred, char** edn )); +extern int tcl_back_bind LDAP_P ((BackendDB * bd, + Connection * conn, Operation * op, + char *dn, int method, struct berval * cred, char **edn)); -extern int tcl_back_unbind LDAP_P(( BackendDB *bd, - Connection *conn, Operation *op )); +extern int tcl_back_unbind LDAP_P ((BackendDB * bd, + Connection * conn, Operation * op)); -extern int tcl_back_search LDAP_P(( BackendDB *bd, - Connection *conn, Operation *op, - char *base, int scope, int deref, int sizelimit, int timelimit, - Filter *filter, char *filterstr, char **attrs, int attrsonly )); +extern int tcl_back_search LDAP_P ((BackendDB * bd, + Connection * conn, Operation * op, + char *base, int scope, int deref, int sizelimit, int timelimit, + Filter * filter, char *filterstr, char **attrs, int attrsonly)); -extern int tcl_back_compare LDAP_P((BackendDB *bd, - Connection *conn, Operation *op, - char *dn, Ava *ava )); +extern int tcl_back_compare LDAP_P ((BackendDB * bd, + Connection * conn, Operation * op, + char *dn, Ava * ava)); -extern int tcl_back_modify LDAP_P(( BackendDB *bd, - Connection *conn, Operation *op, - char *dn, LDAPModList *ml )); +extern int tcl_back_modify LDAP_P ((BackendDB * bd, + Connection * conn, Operation * op, + char *dn, LDAPModList * ml)); -extern int tcl_back_modrdn LDAP_P(( BackendDB *bd, - Connection *conn, Operation *op, - char *dn, char*newrdn, int deleteoldrdn )); +extern int tcl_back_modrdn LDAP_P ((BackendDB * bd, + Connection * conn, Operation * op, + char *dn, char *newrdn, int deleteoldrdn)); -extern int tcl_back_add LDAP_P(( BackendDB *bd, - Connection *conn, Operation *op, Entry *e )); +extern int tcl_back_add LDAP_P ((BackendDB * bd, + Connection * conn, Operation * op, Entry * e)); -extern int tcl_back_delete LDAP_P(( BackendDB *bd, - Connection *conn, Operation *op, char *dn )); +extern int tcl_back_delete LDAP_P ((BackendDB * bd, + Connection * conn, Operation * op, char *dn)); -extern int tcl_back_abandon LDAP_P(( BackendDB *bd, - Connection *conn, Operation *op, int msgid )); +extern int tcl_back_abandon LDAP_P ((BackendDB * bd, + Connection * conn, Operation * op, int msgid)); LDAP_END_DECL #endif /* _TCL_EXTERNAL_H */ - diff --git a/servers/slapd/back-tcl/tcl_abandon.c b/servers/slapd/back-tcl/tcl_abandon.c index b563e1b8d8..dcd07cca81 100644 --- a/servers/slapd/back-tcl/tcl_abandon.c +++ b/servers/slapd/back-tcl/tcl_abandon.c @@ -1,5 +1,6 @@ -/* - * abandon.c - tcl abandon routine +/* abandon.c - tcl abandon routine + * + * $Id: tcl_abandon.c,v 1.2 1999/02/16 23:32:49 bcollins Exp $ * * Copyright 1999, Ben Collins <bcollins@debian.org>, All rights reserved. * @@ -7,10 +8,6 @@ * 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. - * - * $Id$ - * - * $Log$ */ #include "portable.h" @@ -20,11 +17,12 @@ #include "slap.h" #include "tcl_back.h" -int tcl_back_abandon ( - Backend *be, - Connection *conn, - Operation *op, - int msgid +int +tcl_back_abandon ( + Backend * be, + Connection * conn, + Operation * op, + int msgid ) { char *suf_tcl, *results, *command; @@ -32,27 +30,30 @@ int tcl_back_abandon ( struct tclinfo *ti = (struct tclinfo *) be->be_private; if (ti->ti_abandon == NULL) { - return; + return (-1); } - for ( i = 0; be->be_suffix[i] != NULL; i++ ) - ; - suf_tcl = Tcl_Merge(i, be->be_suffix); + for (i = 0; be->be_suffix[i] != NULL; i++); + suf_tcl = Tcl_Merge (i, be->be_suffix); - command = (char *) ch_malloc (strlen(ti->ti_abandon) + strlen(suf_tcl) + command = (char *) ch_malloc (strlen (ti->ti_abandon) + strlen (suf_tcl) + 20); - sprintf(command, "%s ABANDON {%ld} {%s}", + sprintf (command, "%s ABANDON {%ld} {%s}", ti->ti_abandon, op->o_msgid, suf_tcl); - Tcl_Free(suf_tcl); - - ldap_pvt_thread_mutex_lock( &tcl_interpreter_mutex ); - code = Tcl_GlobalEval(ti->ti_ii->interp, command); - results = (char *) strdup(ti->ti_ii->interp->result); - ldap_pvt_thread_mutex_unlock( &tcl_interpreter_mutex ); - free(command); - - if (code != TCL_OK) { - Debug(LDAP_DEBUG_ANY, "tcl_abandon_error: %s\n", results, 0, 0); - } - return( 0 ); + Tcl_Free (suf_tcl); + + ldap_pvt_thread_mutex_lock (&tcl_interpreter_mutex); + code = Tcl_GlobalEval (ti->ti_ii->interp, command); + results = (char *) strdup (ti->ti_ii->interp->result); + ldap_pvt_thread_mutex_unlock (&tcl_interpreter_mutex); + free (command); + + if (code != TCL_OK) { + err = LDAP_OPERATIONS_ERROR; + Debug (LDAP_DEBUG_ANY, "tcl_abandon_error: %s\n", results, + 0, 0); + } + + free(results); + return (err); } diff --git a/servers/slapd/back-tcl/tcl_add.c b/servers/slapd/back-tcl/tcl_add.c index 531ef0a390..2eb0406674 100644 --- a/servers/slapd/back-tcl/tcl_add.c +++ b/servers/slapd/back-tcl/tcl_add.c @@ -1,5 +1,6 @@ -/* - * add.c - tcl add routine +/* add.c - tcl add routine + * + * $Id: tcl_add.c,v 1.2 1999/02/17 01:05:28 bcollins Exp $ * * Copyright 1999, Ben Collins <bcollins@debian.org>, All rights reserved. * @@ -7,10 +8,6 @@ * 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. - * - * $Id$ - * - * $Log$ */ #include "portable.h" @@ -20,7 +17,8 @@ #include "slap.h" #include "tcl_back.h" -int tcl_back_add ( +int +tcl_back_add ( Backend * be, Connection * conn, Operation * op, @@ -37,34 +35,36 @@ int tcl_back_add ( return (-1); } - for ( i = 0; be->be_suffix[i] != NULL; i++ ) - ; - suf_tcl = Tcl_Merge(i, be->be_suffix); + for (i = 0; be->be_suffix[i] != NULL; i++); + suf_tcl = Tcl_Merge (i, be->be_suffix); - entrystr = tcl_clean_entry(e); + entrystr = tcl_clean_entry (e); - command = (char *) ch_malloc (strlen(ti->ti_add) + strlen(suf_tcl) + - strlen(entrystr) + 32); - sprintf(command, "%s ADD {%ld} {%s} {%s}", + command = (char *) ch_malloc (strlen (ti->ti_add) + strlen + (suf_tcl) + + strlen (entrystr) + 32); + sprintf (command, "%s ADD {%ld} {%s} {%s}", ti->ti_add, op->o_msgid, suf_tcl, entrystr); - Tcl_Free(suf_tcl); + Tcl_Free (suf_tcl); free (entrystr); - ldap_pvt_thread_mutex_lock( &tcl_interpreter_mutex ); - code = Tcl_GlobalEval(ti->ti_ii->interp, command); - results = (char *) strdup(ti->ti_ii->interp->result); - ldap_pvt_thread_mutex_unlock( &tcl_interpreter_mutex ); - free(command); + ldap_pvt_thread_mutex_lock (&tcl_interpreter_mutex); + code = Tcl_GlobalEval (ti->ti_ii->interp, command); + results = (char *) strdup (ti->ti_ii->interp->result); + ldap_pvt_thread_mutex_unlock (&tcl_interpreter_mutex); + free (command); if (code != TCL_OK) { err = LDAP_OPERATIONS_ERROR; - Debug(LDAP_DEBUG_ANY, "tcl_add_error: %s\n", results, 0, 0); + Debug (LDAP_DEBUG_ANY, "tcl_add_error: %s\n", results, 0, 0); } else { - interp_send_results ( be, conn, op, results, NULL, 0 ); + interp_send_results (be, conn, op, results, NULL, 0); } if (err != LDAP_SUCCESS) - send_ldap_result (conn, op, err, NULL, "internal backend error"); + send_ldap_result (conn, op, err, NULL, + "internal backend error"); + + free(results); return (err); } - diff --git a/servers/slapd/back-tcl/tcl_back.h b/servers/slapd/back-tcl/tcl_back.h index 60e6cd00dc..3ad290e240 100644 --- a/servers/slapd/back-tcl/tcl_back.h +++ b/servers/slapd/back-tcl/tcl_back.h @@ -1,5 +1,6 @@ -/* - * tcl_back.h - tcl backend header (structs, functions) +/* tcl_back.h - tcl backend header (structs, functions) + * + * $Id: tcl_back.h,v 1.1 1999/02/17 01:23:18 bcollins Exp $ * * Copyright 1999, Ben Collins <bcollins@debian.org>, All rights reserved. * @@ -7,10 +8,6 @@ * 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. - * - * $Id$ - * - * $Log$ */ #include <tcl.h> @@ -21,48 +18,48 @@ #include <ldap_cdefs.h> #include "external.h" -extern ldap_pvt_thread_mutex_t tcl_interpreter_mutex; +extern ldap_pvt_thread_mutex_t tcl_interpreter_mutex; struct i_info { - Tcl_Interp *interp; - char *name; - struct i_info *next; - int count; + Tcl_Interp *interp; + char *name; + struct i_info *next; + int count; }; extern struct i_info *global_i; struct tclinfo { - char *script_path; - struct i_info *ti_ii; - char *ti_bind; - char *ti_unbind; - char *ti_search; - char *ti_compare; - char *ti_modify; - char *ti_modrdn; - char *ti_add; - char *ti_delete; - char *ti_abandon; + char *script_path; + struct i_info *ti_ii; + char *ti_bind; + char *ti_unbind; + char *ti_search; + char *ti_compare; + char *ti_modify; + char *ti_modrdn; + char *ti_add; + char *ti_delete; + char *ti_abandon; }; void readtclscript (char *script, Tcl_Interp * my_tcl); -char *tcl_clean_entry (Entry *e); +char *tcl_clean_entry (Entry * e); + int tcl_ldap_debug ( - ClientData clientData, - Tcl_Interp *interp, - int argc, - char *argv[] + ClientData clientData, + Tcl_Interp * interp, + int argc, + char *argv[] ); -int interp_send_results( - Backend *be, - Connection *conn, - Operation *op, - char *result, - char **attrs, - int attrsonly +int interp_send_results ( + Backend * be, + Connection * conn, + Operation * op, + char *result, + char **attrs, + int attrsonly ); #endif - diff --git a/servers/slapd/back-tcl/tcl_bind.c b/servers/slapd/back-tcl/tcl_bind.c index f758bf7773..20b4dae301 100644 --- a/servers/slapd/back-tcl/tcl_bind.c +++ b/servers/slapd/back-tcl/tcl_bind.c @@ -1,5 +1,6 @@ -/* - * bind.c - tcl bind routines +/* bind.c - tcl bind routines + * + * $Id: tcl_bind.c,v 1.2 1999/02/17 01:05:28 bcollins Exp $ * * Copyright 1999, Ben Collins <bcollins@debian.org>, All rights reserved. * @@ -7,10 +8,6 @@ * 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. - * - * $Id$ - * - * $Log$ */ #include "portable.h" @@ -20,14 +17,15 @@ #include "slap.h" #include "tcl_back.h" -int tcl_back_bind ( +int +tcl_back_bind ( Backend * be, Connection * conn, Operation * op, char *dn, int method, struct berval *cred, - char** edn + char **edn ) { char *command, *suf_tcl, *results; @@ -42,31 +40,34 @@ int tcl_back_bind ( return (-1); } - for ( i = 0; be->be_suffix[i] != NULL; i++ ) - ; - suf_tcl = Tcl_Merge(i, be->be_suffix); + for (i = 0; be->be_suffix[i] != NULL; i++); + suf_tcl = Tcl_Merge (i, be->be_suffix); - command = (char *) ch_malloc (strlen(ti->ti_bind) + strlen(suf_tcl) + - strlen(dn) + strlen(cred->bv_val) + 64); - sprintf(command, "%s BIND {%ld} {%s} {%s} {%d} {%lu} {%s}", + command = (char *) ch_malloc (strlen (ti->ti_bind) + strlen + (suf_tcl) + + strlen (dn) + strlen (cred->bv_val) + 64); + sprintf (command, "%s BIND {%ld} {%s} {%s} {%d} {%lu} {%s}", ti->ti_bind, op->o_msgid, suf_tcl, dn, method, cred->bv_len, cred->bv_val); - Tcl_Free(suf_tcl); + Tcl_Free (suf_tcl); - ldap_pvt_thread_mutex_lock( &tcl_interpreter_mutex ); - code = Tcl_GlobalEval(ti->ti_ii->interp, command); - results = (char *) strdup(ti->ti_ii->interp->result); - ldap_pvt_thread_mutex_unlock( &tcl_interpreter_mutex ); - free(command); + ldap_pvt_thread_mutex_lock (&tcl_interpreter_mutex); + code = Tcl_GlobalEval (ti->ti_ii->interp, command); + results = (char *) strdup (ti->ti_ii->interp->result); + ldap_pvt_thread_mutex_unlock (&tcl_interpreter_mutex); + free (command); if (code != TCL_OK) { err = LDAP_OPERATIONS_ERROR; - Debug(LDAP_DEBUG_ANY, "tcl_bind_error: %s\n", results, 0, 0); + Debug (LDAP_DEBUG_ANY, "tcl_bind_error: %s\n", results, 0, 0); } else { - err = interp_send_results ( be, conn, op, results, NULL, 0 ); + err = interp_send_results (be, conn, op, results, NULL, 0); } if (err != LDAP_SUCCESS) - send_ldap_result (conn, op, err, NULL, "internal backend error"); + send_ldap_result (conn, op, err, NULL, + "internal backend error"); + + free(results); return (err); } diff --git a/servers/slapd/back-tcl/tcl_close.c b/servers/slapd/back-tcl/tcl_close.c index 7f9726f684..f01b9eefa6 100644 --- a/servers/slapd/back-tcl/tcl_close.c +++ b/servers/slapd/back-tcl/tcl_close.c @@ -1,5 +1,6 @@ -/* - * close.c - tcl close routines +/* close.c - tcl close routines + * + * $Id: tcl_close.c,v 1.3 1999/02/17 01:02:11 bcollins Exp $ * * Copyright 1999, Ben Collins <bcollins@debian.org>, All rights reserved. * @@ -7,13 +8,6 @@ * 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. - * - * $Id: tcl_close.c,v 1.2 1999/02/17 00:55:03 bcollins Exp $ - * - * $Log: tcl_close.c,v $ - * Revision 1.2 1999/02/17 00:55:03 bcollins - * Implemented all of the (db_)destroy and (db_)close functions - * */ #include "portable.h" @@ -28,26 +22,26 @@ tcl_back_close ( BackendInfo * bi ) { - Tcl_DeleteInterp(global_i->interp); + Tcl_DeleteInterp (global_i->interp); - return( 0 ); + return (0); } int -tcl_back_destroy( - BackendInfo *bi +tcl_back_destroy ( + BackendInfo * bi ) { - Tcl_Free(global_i->interp); - free(global_i); - ldap_pvt_thread_mutex_destroy( &tcl_interpreter_mutex ); + free (global_i->interp); + free (global_i); + ldap_pvt_thread_mutex_destroy (&tcl_interpreter_mutex); - return( 0 ); + return (0); } int -tcl_back_db_close( - BackendDB *bd +tcl_back_db_close ( + BackendDB * bd ) { struct tclinfo *ti = (struct tclinfo *) bd->be_private; @@ -55,35 +49,35 @@ tcl_back_db_close( /* Disable the interp and associated struct */ ti->ti_ii->count--; - if (!ti->ti_ii->count && strcasecmp("default", ti->ti_ii->name)) { + 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) - ; + 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); + Tcl_DeleteInterp (ti->ti_ii->interp); } - return( 0 ); + return (0); } int -tcl_back_db_destroy( - BackendDB *bd +tcl_back_db_destroy ( + BackendDB * bd ) { struct tclinfo *ti = (struct tclinfo *) bd->be_private; - /* - * Now free up the allocated memory used - */ + /* + * Now free up the allocated memory used + */ ti->ti_ii->count--; - if (!ti->ti_ii->count && strcasecmp("default", ti->ti_ii->name)) { - Tcl_Free(ti->ti_ii->interp); - free(ti->ti_ii); - free(ti); + 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 ); + free (bd->be_private); bd->be_private = NULL; - return( 0 ); + return (0); } diff --git a/servers/slapd/back-tcl/tcl_compare.c b/servers/slapd/back-tcl/tcl_compare.c index 599fa09239..1882605e12 100644 --- a/servers/slapd/back-tcl/tcl_compare.c +++ b/servers/slapd/back-tcl/tcl_compare.c @@ -1,5 +1,6 @@ -/* - * compare.c - tcl compare routines +/* compare.c - tcl compare routines + * + * $Id: tcl_compare.c,v 1.2 1999/02/17 01:05:28 bcollins Exp $ * * Copyright 1999, Ben Collins <bcollins@debian.org>, All rights reserved. * @@ -7,10 +8,6 @@ * 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. - * - * $Id$ - * - * $Log$ */ #include "portable.h" @@ -39,33 +36,35 @@ tcl_back_compare ( return (-1); } - for ( i = 0; be->be_suffix[i] != NULL; i++ ) - ; - suf_tcl = Tcl_Merge(i, be->be_suffix); + for (i = 0; be->be_suffix[i] != NULL; i++); + suf_tcl = Tcl_Merge (i, be->be_suffix); - command = (char *) ch_malloc (strlen(ti->ti_compare) + - strlen(suf_tcl) + strlen(dn) + strlen(ava->ava_type) + - strlen(ava->ava_value.bv_val) + 64); - sprintf(command, "%s COMPARE {%ld} {%s} {%s} {%s: %s}", + command = (char *) ch_malloc (strlen (ti->ti_compare) + + strlen (suf_tcl) + strlen (dn) + strlen (ava->ava_type) + + strlen (ava->ava_value.bv_val) + 64); + sprintf (command, "%s COMPARE {%ld} {%s} {%s} {%s: %s}", ti->ti_compare, op->o_msgid, suf_tcl, dn, ava->ava_type, - ava->ava_value.bv_val); - Tcl_Free(suf_tcl); + ava->ava_value.bv_val); + Tcl_Free (suf_tcl); - ldap_pvt_thread_mutex_lock( &tcl_interpreter_mutex ); - code = Tcl_GlobalEval(ti->ti_ii->interp, command); - results = (char *) strdup(ti->ti_ii->interp->result); - ldap_pvt_thread_mutex_unlock( &tcl_interpreter_mutex ); - free(command); + ldap_pvt_thread_mutex_lock (&tcl_interpreter_mutex); + code = Tcl_GlobalEval (ti->ti_ii->interp, command); + results = (char *) strdup (ti->ti_ii->interp->result); + ldap_pvt_thread_mutex_unlock (&tcl_interpreter_mutex); + free (command); if (code != TCL_OK) { err = LDAP_OPERATIONS_ERROR; - Debug(LDAP_DEBUG_ANY, "tcl_compare_error: %s\n", results, 0, 0); + Debug (LDAP_DEBUG_ANY, "tcl_compare_error: %s\n", results, + 0, 0); } else { - interp_send_results ( be, conn, op, results, NULL, 0 ); + interp_send_results (be, conn, op, results, NULL, 0); } if (err != LDAP_SUCCESS) - send_ldap_result (conn, op, err, NULL, "internal backend error"); - return (0); + send_ldap_result (conn, op, err, NULL, + "internal backend error"); + free(results); + return (err); } diff --git a/servers/slapd/back-tcl/tcl_config.c b/servers/slapd/back-tcl/tcl_config.c index 2b083c9ef7..d5378e36a7 100644 --- a/servers/slapd/back-tcl/tcl_config.c +++ b/servers/slapd/back-tcl/tcl_config.c @@ -1,5 +1,6 @@ -/* - * config.c - tcl backend configuration file routine +/* config.c - tcl backend configuration file routine + * + * $Id: tcl_config.c,v 1.3 1999/02/17 00:53:59 bcollins Exp $ * * Copyright 1999, Ben Collins <bcollins@debian.org>, All rights reserved. * @@ -7,13 +8,6 @@ * 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. - * - * $Id: tcl_config.c,v 1.2 1999/02/16 23:30:36 bcollins Exp $ - * - * $Log: tcl_config.c,v $ - * Revision 1.2 1999/02/16 23:30:36 bcollins - * fixed exit()'s to be return()'s - * */ #include "portable.h" @@ -25,7 +19,8 @@ struct i_info *global_i; -int tcl_back_db_config ( +int +tcl_back_db_config ( BackendDB * bd, char *fname, int lineno, @@ -37,9 +32,10 @@ int tcl_back_db_config ( int script_loaded = 0; if (ti == NULL) { - fprintf (stderr, "%s: line %d: tcl backend info is null!\n", fname, + fprintf (stderr, + "%s: line %d: tcl backend info is null!\n", fname, lineno); - return( 1 ); + return (1); } if (ti->ti_ii == NULL) { ti->ti_ii = global_i; @@ -51,11 +47,11 @@ int tcl_back_db_config ( Debug (LDAP_DEBUG_ANY, "%s: line %d: missing script in \"scriptpath <script>\" line\n", fname, lineno, 0); - return( 1 ); + return (1); } ti->script_path = (char *) strdup (argv[1]); - /* use local interpreter */ + /* use local interpreter */ } else if (strcasecmp (argv[0], "tclrealm") == 0) { struct i_info *ii; @@ -63,7 +59,7 @@ int tcl_back_db_config ( Debug (LDAP_DEBUG_ANY, "%s: line %d: missing script in \"tclrealm <name>\" line\n", fname, lineno, 0); - return( 1 ); + return (1); } ti->ti_ii = NULL; @@ -71,12 +67,12 @@ int tcl_back_db_config ( /* Try to see if it already exists */ do { if (ii != NULL && !strcasecmp (ii->name, argv[1])) - ti->ti_ii = ii; + ti->ti_ii = ii; if (ii->next != NULL) - ii = ii->next; + ii = ii->next; } while (ii->next != NULL); - if (ti->ti_ii == NULL) { /* we need to make a new one */ + if (ti->ti_ii == NULL) { /* we need to make a new one */ ii->next = (struct i_info *) ch_malloc (sizeof (struct i_info)); @@ -87,122 +83,101 @@ int tcl_back_db_config ( ti->ti_ii = ii->next; } - /* proc for binds */ + /* proc for binds */ } else if (strcasecmp (argv[0], "bind") == 0) { if (argc < 2) { Debug (LDAP_DEBUG_ANY, "%s: line %d: missing proc in \"bind <proc>\" line\n", fname, lineno, 0); - return( 1 ); + return (1); } ti->ti_bind = (char *) strdup (argv[1]); - /* proc for unbinds */ + /* proc for unbinds */ } else if (strcasecmp (argv[0], "unbind") == 0) { if (argc < 2) { Debug (LDAP_DEBUG_ANY, - "%s: line %d: missing proc in \"unbind <proc>\" line\n", - fname, lineno, 0); - return( 1 ); + "%s: line %d: missing proc in \"unbind <proc>\" line\n", + fname, lineno, 0); + return (1); } ti->ti_unbind = (char *) strdup (argv[1]); - /* proc for search */ + /* proc for search */ } else if (strcasecmp (argv[0], "search") == 0) { if (argc < 2) { Debug (LDAP_DEBUG_ANY, "%s: line %d: missing proc in \"search <proc>\" line\n", fname, lineno, 0); - return( 1 ); + return (1); } ti->ti_search = (char *) strdup (argv[1]); - /* proc for compares */ + /* proc for compares */ } else if (strcasecmp (argv[0], "compare") == 0) { if (argc < 2) { Debug (LDAP_DEBUG_ANY, "%s: line %d: missing proc in \"compare <proc>\" line\n", fname, lineno, 0); - return( 1 ); + return (1); } ti->ti_compare = (char *) strdup (argv[1]); - /* proc for modify */ + /* proc for modify */ } else if (strcasecmp (argv[0], "modify") == 0) { if (argc < 2) { Debug (LDAP_DEBUG_ANY, "%s: line %d: missing proc in \"modify <proc>\" line\n", fname, lineno, 0); - return( 1 ); + return (1); } ti->ti_modify = (char *) strdup (argv[1]); - /* proc for modrdn */ + /* proc for modrdn */ } else if (strcasecmp (argv[0], "modrdn") == 0) { if (argc < 2) { Debug (LDAP_DEBUG_ANY, "%s: line %d: missing proc in \"modrdn <proc>\" line\n", fname, lineno, 0); - return( 1 ); + return (1); } ti->ti_modrdn = (char *) strdup (argv[1]); - /* proc for add */ + /* proc for add */ } else if (strcasecmp (argv[0], "add") == 0) { if (argc < 2) { Debug (LDAP_DEBUG_ANY, "%s: line %d: missing proc in \"add <proc>\" line\n", fname, lineno, 0); - return( 1 ); + return (1); } ti->ti_add = (char *) strdup (argv[1]); - /* proc for delete */ + /* proc for delete */ } else if (strcasecmp (argv[0], "delete") == 0) { if (argc < 2) { Debug (LDAP_DEBUG_ANY, "%s: line %d: missing proc in \"delete <proc>\" line\n", fname, lineno, 0); - return( 1 ); + return (1); } ti->ti_delete = (char *) strdup (argv[1]); - /* proc for abandon */ + /* proc for abandon */ } else if (strcasecmp (argv[0], "abandon") == 0) { if (argc < 2) { Debug (LDAP_DEBUG_ANY, "%s: line %d: missing proc in \"abandon <proc>\" line\n", fname, lineno, 0); - return( 1 ); + return (1); } ti->ti_search = (char *) strdup (argv[1]); } else { Debug (LDAP_DEBUG_ANY, "Unknown tcl backend config: %s\n", argv[0], 0, 0); - return( 1 ); + return (1); } return 0; } - -void readtclscript (char *script, Tcl_Interp * my_tcl) -{ - int code; - FILE *f; - f = fopen (script, "r"); - if (f == NULL) { - Debug (LDAP_DEBUG_ANY, "Could not open scriptpath %s\n", script, - 0, 0); - return( 1 ); - } - fclose (f); - code = Tcl_EvalFile (my_tcl, script); - if (code != TCL_OK) { - Debug (LDAP_DEBUG_ANY, "%s: %s\n", script, - Tcl_GetVar (my_tcl, "errorInfo", TCL_GLOBAL_ONLY), 0); - Debug (LDAP_DEBUG_ANY, "%s: error at line\n", script, - my_tcl->errorLine, 0); - return( 1 ); - } -} diff --git a/servers/slapd/back-tcl/tcl_delete.c b/servers/slapd/back-tcl/tcl_delete.c index 5b9a60ace4..167e28ab80 100644 --- a/servers/slapd/back-tcl/tcl_delete.c +++ b/servers/slapd/back-tcl/tcl_delete.c @@ -1,5 +1,6 @@ -/* - * delete.c - tcl delete routines +/* delete.c - tcl delete routines + * + * $Id: tcl_delete.c,v 1.2 1999/02/17 01:05:28 bcollins Exp $ * * Copyright 1999, Ben Collins <bcollins@debian.org>, All rights reserved. * @@ -7,10 +8,6 @@ * 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. - * - * $Id$ - * - * $Log$ */ #include "portable.h" @@ -37,31 +34,33 @@ tcl_back_delete ( return (-1); } - for ( i = 0; be->be_suffix[i] != NULL; i++ ) - ; - suf_tcl = Tcl_Merge(i, be->be_suffix); + for (i = 0; be->be_suffix[i] != NULL; i++); + suf_tcl = Tcl_Merge (i, be->be_suffix); - command = (char *) ch_malloc (strlen(ti->ti_delete) + strlen(suf_tcl) - + strlen(dn) + 64); - sprintf(command, "%s DELETE {%ld} {%s} {%s}", + command = (char *) ch_malloc (strlen (ti->ti_delete) + strlen (suf_tcl) + + strlen (dn) + 64); + sprintf (command, "%s DELETE {%ld} {%s} {%s}", ti->ti_delete, op->o_msgid, suf_tcl, dn); - Tcl_Free(suf_tcl); + Tcl_Free (suf_tcl); - ldap_pvt_thread_mutex_lock( &tcl_interpreter_mutex ); - code = Tcl_GlobalEval(ti->ti_ii->interp, command); - results = (char *) strdup(ti->ti_ii->interp->result); - ldap_pvt_thread_mutex_unlock( &tcl_interpreter_mutex ); - free(command); + ldap_pvt_thread_mutex_lock (&tcl_interpreter_mutex); + code = Tcl_GlobalEval (ti->ti_ii->interp, command); + results = (char *) strdup (ti->ti_ii->interp->result); + ldap_pvt_thread_mutex_unlock (&tcl_interpreter_mutex); + free (command); if (code != TCL_OK) { err = LDAP_OPERATIONS_ERROR; - Debug(LDAP_DEBUG_ANY, "tcl_delete_error: %s\n", results, 0, 0); + Debug (LDAP_DEBUG_ANY, "tcl_delete_error: %s\n", results, + 0, 0); } else { - interp_send_results ( be, conn, op, results, NULL, 0 ); + interp_send_results (be, conn, op, results, NULL, 0); } if (err != LDAP_SUCCESS) - send_ldap_result (conn, op, err, NULL, "internal backend error"); + send_ldap_result (conn, op, err, NULL, + "internal backend error"); - return (0); + free(results); + return (err); } diff --git a/servers/slapd/back-tcl/tcl_init.c b/servers/slapd/back-tcl/tcl_init.c index 402676dc09..d28b23c796 100644 --- a/servers/slapd/back-tcl/tcl_init.c +++ b/servers/slapd/back-tcl/tcl_init.c @@ -1,5 +1,6 @@ -/* - * tcl_init.c - tcl backend initialization +/* tcl_init.c - tcl backend initialization + * + * $Id: tcl_init.c,v 1.3 1999/02/17 01:02:11 bcollins Exp $ * * Copyright 1999, Ben Collins <bcollins@debian.org>, All rights reserved. * @@ -7,13 +8,6 @@ * 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. - * - * $Id: tcl_init.c,v 1.2 1999/02/17 00:55:54 bcollins Exp $ - * - * $Log: tcl_init.c,v $ - * Revision 1.2 1999/02/17 00:55:54 bcollins - * Implemented the open, init functions correctly - * */ #include "portable.h" @@ -28,12 +22,13 @@ ldap_pvt_thread_mutex_t tcl_interpreter_mutex; int -tcl_back_initialize( - BackendInfo *bi +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; @@ -41,7 +36,7 @@ tcl_back_initialize( Tcl_Init (global_i->interp); /* Initialize the global interpreter lock */ - ldap_pvt_thread_mutex_init( &tcl_interpreter_mutex ); + ldap_pvt_thread_mutex_init (&tcl_interpreter_mutex); bi->bi_open = tcl_back_open; bi->bi_config = NULL; @@ -70,12 +65,13 @@ tcl_back_initialize( } int -tcl_back_open( - BackendInfo *bi +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; @@ -83,19 +79,19 @@ tcl_back_open( Tcl_Init (global_i->interp); /* Initialize the global interpreter lock */ - ldap_pvt_thread_mutex_init( &tcl_interpreter_mutex ); + ldap_pvt_thread_mutex_init (&tcl_interpreter_mutex); - return( 0 ); + return (0); } int -tcl_back_db_init( - Backend *be +tcl_back_db_init ( + Backend * be ) { - struct tclinfo *ti; + struct tclinfo *ti; - ti = (struct tclinfo *) ch_calloc( 1, sizeof(struct tclinfo) ); + ti = (struct tclinfo *) ch_calloc (1, sizeof (struct tclinfo)); /* * For some reason this causes problems @@ -116,15 +112,16 @@ tcl_back_db_init( return ti == NULL; } -int tcl_back_db_open ( - BackendDB * bd +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 */ + if (ti->ti_ii->interp == NULL) { /* we need to make a new one */ ti->ti_ii->interp = Tcl_CreateInterp (); - Tcl_Init (ti->interp); + Tcl_Init (ti->ti_ii->interp); } /* raise that count for the interpreter */ @@ -134,7 +131,7 @@ int tcl_back_db_open ( readtclscript (ti->script_path, ti->ti_ii->interp); /* Intall the debug command */ - Tcl_CreateCommand( ti->ti_ii->interp, "ldap:debug", &tcl_ldap_debug, + Tcl_CreateCommand (ti->ti_ii->interp, "ldap:debug", &tcl_ldap_debug, NULL, NULL); return 0; diff --git a/servers/slapd/back-tcl/tcl_modify.c b/servers/slapd/back-tcl/tcl_modify.c index d9d380157e..2bed7731e3 100644 --- a/servers/slapd/back-tcl/tcl_modify.c +++ b/servers/slapd/back-tcl/tcl_modify.c @@ -1,5 +1,6 @@ -/* - * modify.c - tcl modify routines +/* modify.c - tcl modify routines + * + * $Id: tcl_modify.c,v 1.2 1999/02/17 01:05:28 bcollins Exp $ * * Copyright 1999, Ben Collins <bcollins@debian.org>, All rights reserved. * @@ -7,10 +8,6 @@ * 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. - * - * $Id$ - * - * $Log$ */ #include "portable.h" @@ -20,7 +17,8 @@ #include "slap.h" #include "tcl_back.h" -int tcl_back_modify ( +int +tcl_back_modify ( Backend * be, Connection * conn, Operation * op, @@ -38,20 +36,19 @@ int tcl_back_modify ( return (-1); } - for ( i = 0; be->be_suffix[i] != NULL; i++ ) - ; - suf_tcl = Tcl_Merge(i, be->be_suffix); + for (i = 0; be->be_suffix[i] != NULL; i++); + suf_tcl = Tcl_Merge (i, be->be_suffix); - tcl_mods = (char *) ch_malloc( BUFSIZ ); + tcl_mods = (char *) ch_malloc (BUFSIZ); tcl_mods[0] = '\0'; bsize = BUFSIZ; bp = tcl_mods; - for ( ; modlist != NULL; modlist = modlist->ml_next ) { + for (; modlist != NULL; modlist = modlist->ml_next) { LDAPMod *mods = &modlist->ml_mod; char *op = NULL; - switch ( mods->mod_op & ~LDAP_MOD_BVALUES ) { + switch (mods->mod_op & ~LDAP_MOD_BVALUES) { case LDAP_MOD_ADD: op = "add"; break; @@ -63,54 +60,58 @@ int tcl_back_modify ( break; } - len = strlen( mods->mod_type ) + strlen ( op ) + 7; - while ( bp + len - tcl_mods > bsize ) { + len = strlen (mods->mod_type) + strlen (op) + 7; + while (bp + len - tcl_mods > bsize) { bsize += BUFSIZ; - tcl_mods = (char *) ch_realloc( tcl_mods, bsize ); + tcl_mods = (char *) ch_realloc (tcl_mods, bsize); } - sprintf(bp, "{ {%s: %s} ", op, mods->mod_type); + sprintf (bp, "{ {%s: %s} ", op, mods->mod_type); bp += len; - for( i = 0; - mods->mod_bvalues != NULL && mods->mod_bvalues[i] != NULL; - i++ ) - { - len = strlen( mods->mod_type ) + strlen ( - mods->mod_bvalues[i]->bv_val ) + 5 + - (mods->mod_bvalues[i+1] == NULL ? 2 : 0); - while ( bp + len - tcl_mods > bsize ) { + for (i = 0; + mods->mod_bvalues != NULL && mods->mod_bvalues[i] + != NULL; + i++) { + len = strlen (mods->mod_type) + strlen ( + mods->mod_bvalues[i]->bv_val) + 5 + + (mods->mod_bvalues[i + 1] == NULL ? 2 : 0); + while (bp + len - tcl_mods > bsize) { bsize += BUFSIZ; - tcl_mods = (char *) ch_realloc( tcl_mods, bsize ); + tcl_mods = (char *) ch_realloc (tcl_mods, bsize); } - sprintf(bp, "{%s: %s} %s", mods->mod_type, - mods->mod_bvalues[i]->bv_val, mods->mod_bvalues[i+1] == - NULL ? "} " : ""); + sprintf (bp, "{%s: %s} %s", mods->mod_type, + mods->mod_bvalues[i]->bv_val, + mods->mod_bvalues[i + 1] == + NULL ? "} " : ""); bp += len; } } - command = (char *) ch_malloc (strlen(ti->ti_modify) + strlen(suf_tcl) - + strlen(dn) + strlen(tcl_mods) + 64); + command = (char *) ch_malloc (strlen (ti->ti_modify) + strlen (suf_tcl) + + strlen (dn) + strlen (tcl_mods) + 64); /* This space is simply for aesthetics--\ */ - sprintf(command, "%s MODIFY {%ld} {%s} {%s} { %s}", + sprintf (command, "%s MODIFY {%ld} {%s} {%s} { %s}", ti->ti_modify, op->o_msgid, suf_tcl, dn, tcl_mods); - Tcl_Free(suf_tcl); - free(tcl_mods); + Tcl_Free (suf_tcl); + free (tcl_mods); - ldap_pvt_thread_mutex_lock( &tcl_interpreter_mutex ); - code = Tcl_GlobalEval(ti->ti_ii->interp, command); - results = (char *) strdup(ti->ti_ii->interp->result); - ldap_pvt_thread_mutex_unlock( &tcl_interpreter_mutex ); - free(command); + ldap_pvt_thread_mutex_lock (&tcl_interpreter_mutex); + code = Tcl_GlobalEval (ti->ti_ii->interp, command); + results = (char *) strdup (ti->ti_ii->interp->result); + ldap_pvt_thread_mutex_unlock (&tcl_interpreter_mutex); + free (command); if (code != TCL_OK) { err = LDAP_OPERATIONS_ERROR; - Debug(LDAP_DEBUG_ANY, "tcl_modify_error: %s\n", results, 0, 0); + Debug (LDAP_DEBUG_ANY, "tcl_modify_error: %s\n", results, + 0, 0); } else { - interp_send_results ( be, conn, op, results, NULL, 0 ); + interp_send_results (be, conn, op, results, NULL, 0); } if (err != LDAP_SUCCESS) - send_ldap_result (conn, op, err, NULL, "internal backend error"); + send_ldap_result (conn, op, err, NULL, + "internal backend error"); - return (0); + free(results); + return (err); } diff --git a/servers/slapd/back-tcl/tcl_modrdn.c b/servers/slapd/back-tcl/tcl_modrdn.c index 907cf369a1..ef979fb339 100644 --- a/servers/slapd/back-tcl/tcl_modrdn.c +++ b/servers/slapd/back-tcl/tcl_modrdn.c @@ -1,5 +1,6 @@ -/* - * modrdn.c - tcl modify rdn routines +/* modrdn.c - tcl modify rdn routines + * + * $Id: tcl_modrdn.c,v 1.2 1999/02/17 01:05:28 bcollins Exp $ * * Copyright 1999, Ben Collins <bcollins@debian.org>, All rights reserved. * @@ -7,10 +8,6 @@ * 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. - * - * $Id$ - * - * $Log$ */ #include "portable.h" @@ -20,7 +17,8 @@ #include "slap.h" #include "tcl_back.h" -int tcl_back_modrdn ( +int +tcl_back_modrdn ( Backend * be, Connection * conn, Operation * op, @@ -39,31 +37,34 @@ int tcl_back_modrdn ( return (-1); } - for ( i = 0; be->be_suffix[i] != NULL; i++ ) - ; - suf_tcl = Tcl_Merge(i, be->be_suffix); + for (i = 0; be->be_suffix[i] != NULL; i++); + suf_tcl = Tcl_Merge (i, be->be_suffix); - command = (char *) ch_malloc (strlen(ti->ti_modrdn) + strlen(suf_tcl) - + strlen(dn) + strlen(newrdn) + 64); - sprintf(command, "%s MODRDN {%ld} {%s} {%s} {%s} %d", - ti->ti_add, op->o_msgid, suf_tcl, dn, newrdn, deleteoldrdn ? 1 : 0); - Tcl_Free(suf_tcl); + command = (char *) ch_malloc (strlen (ti->ti_modrdn) + strlen (suf_tcl) + + strlen (dn) + strlen (newrdn) + 64); + sprintf (command, "%s MODRDN {%ld} {%s} {%s} {%s} %d", + ti->ti_add, op->o_msgid, suf_tcl, dn, newrdn, deleteoldrdn + ? 1 : 0); + Tcl_Free (suf_tcl); - ldap_pvt_thread_mutex_lock( &tcl_interpreter_mutex ); - code = Tcl_GlobalEval(ti->ti_ii->interp, command); - results = (char *) strdup(ti->ti_ii->interp->result); - ldap_pvt_thread_mutex_unlock( &tcl_interpreter_mutex ); - free(command); + ldap_pvt_thread_mutex_lock (&tcl_interpreter_mutex); + code = Tcl_GlobalEval (ti->ti_ii->interp, command); + results = (char *) strdup (ti->ti_ii->interp->result); + ldap_pvt_thread_mutex_unlock (&tcl_interpreter_mutex); + free (command); if (code != TCL_OK) { err = LDAP_OPERATIONS_ERROR; - Debug(LDAP_DEBUG_ANY, "tcl_modrdn_error: %s\n", results, 0, 0); + Debug (LDAP_DEBUG_ANY, "tcl_modrdn_error: %s\n", results, + 0, 0); } else { - interp_send_results ( be, conn, op, results, NULL, 0 ); + interp_send_results (be, conn, op, results, NULL, 0); } if (err != LDAP_SUCCESS) - send_ldap_result (conn, op, err, NULL, "internal backend error"); + send_ldap_result (conn, op, err, NULL, + "internal backend error"); - return (0); + free(results); + return (err); } diff --git a/servers/slapd/back-tcl/tcl_search.c b/servers/slapd/back-tcl/tcl_search.c index 36796345f2..054d855a3d 100644 --- a/servers/slapd/back-tcl/tcl_search.c +++ b/servers/slapd/back-tcl/tcl_search.c @@ -1,5 +1,6 @@ -/* - * search.c - tcl search routines +/* search.c - tcl search routines + * + * $Id: tcl_search.c,v 1.2 1999/02/17 01:05:28 bcollins Exp $ * * Copyright 1999, Ben Collins <bcollins@debian.org>, All rights reserved. * @@ -7,10 +8,6 @@ * 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. - * - * $Id$ - * - * $Log$ */ #include "portable.h" @@ -20,7 +17,8 @@ #include "slap.h" #include "tcl_back.h" -int tcl_back_search ( +int +tcl_back_search ( Backend * be, Connection * conn, Operation * op, @@ -46,40 +44,44 @@ int tcl_back_search ( return (-1); } - for ( i = 0; attrs != NULL && attrs[i] != NULL; i++ ) - ; + for (i = 0; attrs != NULL && attrs[i] != NULL; i++); if (i > 0) - attrs_tcl = Tcl_Merge(i, attrs); + attrs_tcl = Tcl_Merge (i, attrs); - for ( i = 0; be->be_suffix[i] != NULL; i++ ) - ; - suf_tcl = Tcl_Merge(i, be->be_suffix); + for (i = 0; be->be_suffix[i] != NULL; i++); + suf_tcl = Tcl_Merge (i, be->be_suffix); - command = (char *) ch_malloc (strlen(ti->ti_search) + strlen(suf_tcl) - + strlen(base) + 40 + strlen(filterstr) + (attrs_tcl == NULL ? 5 - : strlen(attrs_tcl)) + 72); - sprintf(command, "%s SEARCH {%ld} {%s} {%s} {%d} {%d} {%d} {%d} {%s} {%d} {%s}", + command = (char *) ch_malloc (strlen (ti->ti_search) + strlen (suf_tcl) + + strlen (base) + 40 + strlen (filterstr) + (attrs_tcl == + NULL ? 5 + : strlen (attrs_tcl)) + 72); + sprintf (command, + "%s SEARCH {%ld} {%s} {%s} {%d} {%d} {%d} {%d} {%s} {%d} {%s}", ti->ti_search, op->o_msgid, suf_tcl, base, scope, deref, - sizelimit, timelimit, filterstr, attrsonly ? 1 : 0, attrs_tcl == + sizelimit, timelimit, filterstr, attrsonly ? 1 : 0, + attrs_tcl == NULL ? "{all}" : attrs_tcl); - Tcl_Free( attrs_tcl ); - Tcl_Free( suf_tcl ); + Tcl_Free (attrs_tcl); + Tcl_Free (suf_tcl); - ldap_pvt_thread_mutex_lock( &tcl_interpreter_mutex ); - code = Tcl_GlobalEval(ti->ti_ii->interp, command); + ldap_pvt_thread_mutex_lock (&tcl_interpreter_mutex); + code = Tcl_GlobalEval (ti->ti_ii->interp, command); results = (char *) strdup(ti->ti_ii->interp->result); - ldap_pvt_thread_mutex_unlock( &tcl_interpreter_mutex ); - free(command); + ldap_pvt_thread_mutex_unlock (&tcl_interpreter_mutex); + free (command); if (code != TCL_OK) { err = LDAP_OPERATIONS_ERROR; - Debug(LDAP_DEBUG_ANY, "tcl_search_error: %s\n", results, 0, 0); + Debug (LDAP_DEBUG_ANY, "tcl_search_error: %s\n", results, + 0, 0); } else { - interp_send_results ( be, conn, op, results, NULL, 0 ); + interp_send_results (be, conn, op, results, NULL, 0); } if (err != LDAP_SUCCESS) - send_ldap_result (conn, op, err, NULL, "internal backend error"); - return (0); + send_ldap_result (conn, op, err, NULL, + "internal backend error"); + free(results); + return (err); } diff --git a/servers/slapd/back-tcl/tcl_unbind.c b/servers/slapd/back-tcl/tcl_unbind.c index ac67581571..dbd6a7d668 100644 --- a/servers/slapd/back-tcl/tcl_unbind.c +++ b/servers/slapd/back-tcl/tcl_unbind.c @@ -1,5 +1,6 @@ -/* - * unbind.c - tcl unbind routines +/* unbind.c - tcl unbind routines + * + * $Id: tcl_unbind.c,v 1.2 1999/02/17 01:05:28 bcollins Exp $ * * Copyright 1999, Ben Collins <bcollins@debian.org>, All rights reserved. * @@ -7,10 +8,6 @@ * 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. - * - * $Id$ - * - * $Log$ */ #include "portable.h" @@ -20,7 +17,8 @@ #include "slap.h" #include "tcl_back.h" -int tcl_back_unbind ( +int +tcl_back_unbind ( Backend * be, Connection * conn, Operation * op @@ -33,27 +31,30 @@ int tcl_back_unbind ( if (ti->ti_unbind == NULL) { send_ldap_result (conn, op, LDAP_UNWILLING_TO_PERFORM, NULL, "unbind not implemented"); - return; + return(-1); } - for ( i = 0; be->be_suffix[i] != NULL; i++ ) - ; - suf_tcl = Tcl_Merge(i, be->be_suffix); + for (i = 0; be->be_suffix[i] != NULL; i++); + suf_tcl = Tcl_Merge (i, be->be_suffix); - command = (char *) ch_malloc (strlen(ti->ti_unbind) + strlen(suf_tcl) - + strlen(conn->c_dn ? conn->c_dn : "") + 64); - sprintf(command, "%s UNBIND {%ld} {%s} {%s}", - ti->ti_unbind, op->o_msgid, suf_tcl, conn->c_dn ? conn->c_dn : ""); - Tcl_Free(suf_tcl); + command = (char *) ch_malloc (strlen (ti->ti_unbind) + strlen (suf_tcl) + + strlen (conn->c_dn ? conn->c_dn : "") + 64); + sprintf (command, "%s UNBIND {%ld} {%s} {%s}", + ti->ti_unbind, op->o_msgid, suf_tcl, conn->c_dn ? + conn->c_dn : ""); + Tcl_Free (suf_tcl); - ldap_pvt_thread_mutex_lock( &tcl_interpreter_mutex ); - code = Tcl_GlobalEval(ti->ti_ii->interp, command); - results = (char *) strdup(ti->ti_ii->interp->result); - ldap_pvt_thread_mutex_unlock( &tcl_interpreter_mutex ); - free(command); + ldap_pvt_thread_mutex_lock (&tcl_interpreter_mutex); + code = Tcl_GlobalEval (ti->ti_ii->interp, command); + results = (char *) strdup (ti->ti_ii->interp->result); + ldap_pvt_thread_mutex_unlock (&tcl_interpreter_mutex); + free (command); if (code != TCL_OK) { - Debug(LDAP_DEBUG_ANY, "tcl_unbind_error: %s\n", results, 0, 0); + Debug (LDAP_DEBUG_ANY, "tcl_unbind_error: %s\n", results, + 0, 0); } - return 0; + + free(results); + return (err); } diff --git a/servers/slapd/back-tcl/tcl_util.c b/servers/slapd/back-tcl/tcl_util.c index ad2dc9fda4..342e75c5f8 100644 --- a/servers/slapd/back-tcl/tcl_util.c +++ b/servers/slapd/back-tcl/tcl_util.c @@ -1,5 +1,6 @@ -/* - * result.c - tcl backend utility functions +/* result.c - tcl backend utility functions + * + * $Id: tcl_util.c,v 1.2 1999/02/17 01:05:28 bcollins Exp $ * * Copyright 1999, Ben Collins <bcollins@debian.org>, All rights reserved. * @@ -7,10 +8,6 @@ * 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. - * - * $Id$ - * - * $Log$ */ #include "portable.h" @@ -25,88 +22,99 @@ #include "tcl_back.h" int -interp_send_results( - Backend *be, - Connection *conn, - Operation *op, - char *result, - char **attrs, - int attrsonly +interp_send_results ( + Backend * be, + Connection * conn, + Operation * op, + char *result, + char **attrs, + int attrsonly ) { - int bsize, len, argcPtr, i, err, code; - char *buf, *bp, **argvPtr, *line, *matched, *info; - Entry *e; + int bsize, len, argcPtr, i, err, code; + char *buf, *bp, **argvPtr, *line, *matched, *info; + Entry *e; struct tclinfo *ti = (struct tclinfo *) be->be_private; - /* read in the result and send it along */ - buf = (char *) ch_malloc( BUFSIZ ); + + /* + * 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); + code = Tcl_SplitList (ti->ti_ii->interp, result, &argcPtr, &argvPtr); if (code != TCL_OK) { argcPtr = 0; send_ldap_result (conn, op, LDAP_UNWILLING_TO_PERFORM, NULL, "internal backend error"); return -1; } - for ( i = 0 ; i < argcPtr ; i++ ) { + for (i = 0; i < argcPtr; i++) { line = argvPtr[i]; - Debug( LDAP_DEBUG_ANY, "tcl search reading line (%s)\n", - line, 0, 0 ); - /* ignore lines beginning with DEBUG: */ - if ( strncasecmp( line, "DEBUG:", 6 ) == 0 ) { + + /* + * ignore lines beginning with DEBUG: + */ + if (strncasecmp (line, "DEBUG:", 6) == 0) { continue; } - len = strlen( line ) + 1; - while ( bp + len - buf > bsize ) { + len = strlen (line) + 1; + while (bp + len - buf > bsize) { bsize += BUFSIZ; - buf = (char *) ch_realloc( buf, bsize ); + buf = (char *) ch_realloc (buf, bsize); } - sprintf( bp, "%s\n", line ); + 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 ) { + /* + * line marked the end of an entry or result + */ + if (line[0] == '\0') { + if (strncasecmp (buf, "RESULT", 6) == 0) { break; } - if ( (e = str2entry( buf )) == NULL ) { - Debug( LDAP_DEBUG_ANY, "str2entry(%s) failed\n", - buf, 0, 0 ); + if ((e = str2entry (buf)) == NULL) { + Debug (LDAP_DEBUG_ANY, + "str2entry(%s) failed\n", + buf, 0, 0); } else { - send_search_entry( be, conn, op, e, attrs, - attrsonly ); - entry_free( e ); + send_search_entry (be, conn, op, e, attrs, + attrsonly); + entry_free (e); } bp = buf; } } - (void) str2result( buf, &err, &matched, &info ); + (void) str2result (buf, &err, &matched, &info); - /* otherwise, front end will send this result */ - if ( err != 0 || op->o_tag != LDAP_REQ_BIND ) { - send_ldap_result( conn, op, err, matched, info ); + /* + * otherwise, front end will send this result + */ + if (err != 0 || op->o_tag != LDAP_REQ_BIND) { + send_ldap_result (conn, op, err, matched, info); } - free( buf ); - Tcl_Free( result ); - Tcl_Free( (char *) argvPtr ); - return( err ); + free (buf); + Tcl_Free ((char *) argvPtr); + return (err); } -char *tcl_clean_entry (Entry *e) +char * +tcl_clean_entry ( + Entry * e +) { char *entrystr, *mark1, *mark2, *buf, *bp, *dup; int len, bsize; - pthread_mutex_lock( &entry2str_mutex ); - entrystr = entry2str( e, &len, 0 ); - pthread_mutex_unlock( &entry2str_mutex ); + pthread_mutex_lock (&entry2str_mutex); + entrystr = entry2str (e, &len, 0); + pthread_mutex_unlock (&entry2str_mutex); - buf = (char *) ch_malloc( BUFSIZ ); + buf = (char *) ch_malloc (BUFSIZ); buf[0] = '\0'; bsize = BUFSIZ; bp = buf; @@ -115,42 +123,68 @@ char *tcl_clean_entry (Entry *e) mark1 = entrystr; do { if (mark1[0] == '\n') { - mark1++; + mark1++; } - dup = (char *) strdup(mark1); - if (dup[0] != '\0') { - if ((mark2 = (char *) strchr (dup, '\n')) != NULL) { + dup = (char *) 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 ) { + } + 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) { + 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); + free (dup); } while ((mark1 = (char *) strchr (mark1, '\n')) != NULL); return buf; } -int tcl_ldap_debug ( - ClientData clientData, - Tcl_Interp *interp, - int argc, - char *argv[] +int +tcl_ldap_debug ( + ClientData clientData, + Tcl_Interp * interp, + int argc, + char *argv[] ) { if (argv[1] != NULL) { - Debug(LDAP_DEBUG_ANY, "tcl_debug: %s\n", argv[1], 0, 0); + Debug (LDAP_DEBUG_ANY, "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_ANY, "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_ANY, "%s: %s\n", script, + Tcl_GetVar (my_tcl, "errorInfo", TCL_GLOBAL_ONLY), 0); + Debug (LDAP_DEBUG_ANY, "%s: error at line\n", script, + my_tcl->errorLine, 0); + return; + } +} -- GitLab