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.
23 struct i_info *global_i;
25 int tcl_back_db_config (
33 struct tclinfo *ti = (struct tclinfo *) bd->be_private;
34 int script_loaded = 0;
37 fprintf (stderr, "%s: line %d: tcl backend info is null!\n", fname,
41 if (ti->ti_ii == NULL) {
46 if (strcasecmp (argv[0], "scriptpath") == 0) {
48 Debug (LDAP_DEBUG_ANY,
49 "%s: line %d: missing script in \"scriptpath <script>\" line\n",
53 ti->script_path = (char *) strdup (argv[1]);
55 /* use local interpreter */
56 } else if (strcasecmp (argv[0], "tclrealm") == 0) {
60 Debug (LDAP_DEBUG_ANY,
61 "%s: line %d: missing script in \"tclrealm <name>\" line\n",
69 if (ii != NULL && !strcasecmp (ii->name, argv[1]))
73 } while (ii->next != NULL);
75 if (ti->ti_ii == NULL) { /* we need to make a new one */
76 ii->next = (struct i_info *) ch_malloc (sizeof (struct i_info));
79 ii->next->name = (char *) strdup (argv[1]);
80 ii->next->next = NULL;
81 ii->next->interp = Tcl_CreateInterp ();
82 Tcl_Init (ii->next->interp);
87 } else if (strcasecmp (argv[0], "bind") == 0) {
89 Debug (LDAP_DEBUG_ANY,
90 "%s: line %d: missing proc in \"bind <proc>\" line\n",
94 ti->ti_bind = (char *) strdup (argv[1]);
96 /* proc for unbinds */
97 } else if (strcasecmp (argv[0], "unbind") == 0) {
99 Debug (LDAP_DEBUG_ANY,
100 "%s: line %d: missing proc in \"unbind <proc>\" line\n",
104 ti->ti_unbind = (char *) strdup (argv[1]);
106 /* proc for search */
107 } else if (strcasecmp (argv[0], "search") == 0) {
109 Debug (LDAP_DEBUG_ANY,
110 "%s: line %d: missing proc in \"search <proc>\" line\n",
114 ti->ti_search = (char *) strdup (argv[1]);
116 /* proc for compares */
117 } else if (strcasecmp (argv[0], "compare") == 0) {
119 Debug (LDAP_DEBUG_ANY,
120 "%s: line %d: missing proc in \"compare <proc>\" line\n",
124 ti->ti_compare = (char *) strdup (argv[1]);
126 /* proc for modify */
127 } else if (strcasecmp (argv[0], "modify") == 0) {
129 Debug (LDAP_DEBUG_ANY,
130 "%s: line %d: missing proc in \"modify <proc>\" line\n",
134 ti->ti_modify = (char *) strdup (argv[1]);
136 /* proc for modrdn */
137 } else if (strcasecmp (argv[0], "modrdn") == 0) {
139 Debug (LDAP_DEBUG_ANY,
140 "%s: line %d: missing proc in \"modrdn <proc>\" line\n",
144 ti->ti_modrdn = (char *) strdup (argv[1]);
147 } else if (strcasecmp (argv[0], "add") == 0) {
149 Debug (LDAP_DEBUG_ANY,
150 "%s: line %d: missing proc in \"add <proc>\" line\n",
154 ti->ti_add = (char *) strdup (argv[1]);
156 /* proc for delete */
157 } else if (strcasecmp (argv[0], "delete") == 0) {
159 Debug (LDAP_DEBUG_ANY,
160 "%s: line %d: missing proc in \"delete <proc>\" line\n",
164 ti->ti_delete = (char *) strdup (argv[1]);
166 /* proc for abandon */
167 } else if (strcasecmp (argv[0], "abandon") == 0) {
169 Debug (LDAP_DEBUG_ANY,
170 "%s: line %d: missing proc in \"abandon <proc>\" line\n",
174 ti->ti_search = (char *) strdup (argv[1]);
177 Debug (LDAP_DEBUG_ANY,
178 "Unknown tcl backend config: %s\n", argv[0], 0, 0);
185 int tcl_back_db_open (
189 struct tclinfo *ti = (struct tclinfo *) bd->be_private;
191 /* raise that count for the interpreter */
194 /* now let's (try to) load the script */
195 readtclscript (ti->script_path, ti->ti_ii->interp);
197 /* Intall the debug command */
198 Tcl_CreateCommand( ti->ti_ii->interp, "ldap:debug", &tcl_ldap_debug,
204 void readtclscript (char *script, Tcl_Interp * my_tcl)
208 f = fopen (script, "r");
210 Debug (LDAP_DEBUG_ANY, "Could not open scriptpath %s\n", script,
215 code = Tcl_EvalFile (my_tcl, script);
216 if (code != TCL_OK) {
217 Debug (LDAP_DEBUG_ANY, "%s: %s\n", script,
218 Tcl_GetVar (my_tcl, "errorInfo", TCL_GLOBAL_ONLY), 0);
219 Debug (LDAP_DEBUG_ANY, "%s: error at line\n", script,
220 my_tcl->errorLine, 0);