2 * config.c - tcl backend configuration file routine
4 * Copyright 1999, Ben Collins <bcollins@debian.org>, All rights reserved.
6 * Redistribution and use in source and binary forms are permitted only
7 * as authorized by the OpenLDAP Public License. A copy of this
8 * license is available at http://www.OpenLDAP.org/license.html or
9 * in file LICENSE in the top-level directory of the distribution.
19 struct i_info *global_i;
21 int tcl_back_db_config (
29 struct tclinfo *ti = (struct tclinfo *) bd->be_private;
30 int script_loaded = 0;
33 fprintf (stderr, "%s: line %d: tcl backend info is null!\n", fname,
37 if (ti->ti_ii == NULL) {
42 if (strcasecmp (argv[0], "scriptpath") == 0) {
44 Debug (LDAP_DEBUG_ANY,
45 "%s: line %d: missing script in \"scriptpath <script>\" line\n",
49 ti->script_path = (char *) strdup (argv[1]);
51 /* use local interpreter */
52 } else if (strcasecmp (argv[0], "tclrealm") == 0) {
56 Debug (LDAP_DEBUG_ANY,
57 "%s: line %d: missing script in \"tclrealm <name>\" line\n",
65 if (ii != NULL && !strcasecmp (ii->name, argv[1]))
69 } while (ii->next != NULL);
71 if (ti->ti_ii == NULL) { /* we need to make a new one */
72 ii->next = (struct i_info *) ch_malloc (sizeof (struct i_info));
75 ii->next->name = (char *) strdup (argv[1]);
76 ii->next->next = NULL;
77 ii->next->interp = Tcl_CreateInterp ();
78 Tcl_Init (ii->next->interp);
83 } else if (strcasecmp (argv[0], "bind") == 0) {
85 Debug (LDAP_DEBUG_ANY,
86 "%s: line %d: missing proc in \"bind <proc>\" line\n",
90 ti->ti_bind = (char *) strdup (argv[1]);
92 /* proc for unbinds */
93 } else if (strcasecmp (argv[0], "unbind") == 0) {
95 Debug (LDAP_DEBUG_ANY,
96 "%s: line %d: missing proc in \"unbind <proc>\" line\n",
100 ti->ti_unbind = (char *) strdup (argv[1]);
102 /* proc for search */
103 } else if (strcasecmp (argv[0], "search") == 0) {
105 Debug (LDAP_DEBUG_ANY,
106 "%s: line %d: missing proc in \"search <proc>\" line\n",
110 ti->ti_search = (char *) strdup (argv[1]);
112 /* proc for compares */
113 } else if (strcasecmp (argv[0], "compare") == 0) {
115 Debug (LDAP_DEBUG_ANY,
116 "%s: line %d: missing proc in \"compare <proc>\" line\n",
120 ti->ti_compare = (char *) strdup (argv[1]);
122 /* proc for modify */
123 } else if (strcasecmp (argv[0], "modify") == 0) {
125 Debug (LDAP_DEBUG_ANY,
126 "%s: line %d: missing proc in \"modify <proc>\" line\n",
130 ti->ti_modify = (char *) strdup (argv[1]);
132 /* proc for modrdn */
133 } else if (strcasecmp (argv[0], "modrdn") == 0) {
135 Debug (LDAP_DEBUG_ANY,
136 "%s: line %d: missing proc in \"modrdn <proc>\" line\n",
140 ti->ti_modrdn = (char *) strdup (argv[1]);
143 } else if (strcasecmp (argv[0], "add") == 0) {
145 Debug (LDAP_DEBUG_ANY,
146 "%s: line %d: missing proc in \"add <proc>\" line\n",
150 ti->ti_add = (char *) strdup (argv[1]);
152 /* proc for delete */
153 } else if (strcasecmp (argv[0], "delete") == 0) {
155 Debug (LDAP_DEBUG_ANY,
156 "%s: line %d: missing proc in \"delete <proc>\" line\n",
160 ti->ti_delete = (char *) strdup (argv[1]);
162 /* proc for abandon */
163 } else if (strcasecmp (argv[0], "abandon") == 0) {
165 Debug (LDAP_DEBUG_ANY,
166 "%s: line %d: missing proc in \"abandon <proc>\" line\n",
170 ti->ti_search = (char *) strdup (argv[1]);
174 "Unknown tcl backend config: %s\n", argv[0]);
181 int tcl_back_db_open (
185 struct tclinfo *ti = (struct tclinfo *) bd->be_private;
187 /* raise that count for the interpreter */
190 /* now let's (try to) load the script */
191 readtclscript (ti->script_path, ti->ti_ii->interp);
193 /* Intall the debug command */
194 Tcl_CreateCommand( ti->ti_ii->interp, "ldap:debug", &tcl_ldap_debug,
200 void readtclscript (char *script, Tcl_Interp * my_tcl)
204 f = fopen (script, "r");
206 Debug (LDAP_DEBUG_ANY, "Could not open scriptpath %s\n", script,
211 code = Tcl_EvalFile (my_tcl, script);
212 if (code != TCL_OK) {
213 Debug (LDAP_DEBUG_ANY, "%s: %s\n", script,
214 Tcl_GetVar (my_tcl, "errorInfo", TCL_GLOBAL_ONLY), 0);
215 Debug (LDAP_DEBUG_ANY, "%s: error at line\n", script,
216 my_tcl->errorLine, 0);