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.
11 * $Id: tcl_config.c,v 1.2 1999/02/16 23:30:36 bcollins Exp $
13 * $Log: tcl_config.c,v $
14 * Revision 1.2 1999/02/16 23:30:36 bcollins
15 * fixed exit()'s to be return()'s
26 struct i_info *global_i;
28 int tcl_back_db_config (
36 struct tclinfo *ti = (struct tclinfo *) bd->be_private;
37 int script_loaded = 0;
40 fprintf (stderr, "%s: line %d: tcl backend info is null!\n", fname,
44 if (ti->ti_ii == NULL) {
49 if (strcasecmp (argv[0], "scriptpath") == 0) {
51 Debug (LDAP_DEBUG_ANY,
52 "%s: line %d: missing script in \"scriptpath <script>\" line\n",
56 ti->script_path = (char *) strdup (argv[1]);
58 /* use local interpreter */
59 } else if (strcasecmp (argv[0], "tclrealm") == 0) {
63 Debug (LDAP_DEBUG_ANY,
64 "%s: line %d: missing script in \"tclrealm <name>\" line\n",
71 /* Try to see if it already exists */
73 if (ii != NULL && !strcasecmp (ii->name, argv[1]))
77 } while (ii->next != NULL);
79 if (ti->ti_ii == NULL) { /* we need to make a new one */
80 ii->next = (struct i_info *) ch_malloc
81 (sizeof (struct i_info));
84 ii->next->name = (char *) strdup (argv[1]);
85 ii->next->interp = NULL;
86 ii->next->next = NULL;
91 } else if (strcasecmp (argv[0], "bind") == 0) {
93 Debug (LDAP_DEBUG_ANY,
94 "%s: line %d: missing proc in \"bind <proc>\" line\n",
98 ti->ti_bind = (char *) strdup (argv[1]);
100 /* proc for unbinds */
101 } else if (strcasecmp (argv[0], "unbind") == 0) {
103 Debug (LDAP_DEBUG_ANY,
104 "%s: line %d: missing proc in \"unbind <proc>\" line\n",
108 ti->ti_unbind = (char *) strdup (argv[1]);
110 /* proc for search */
111 } else if (strcasecmp (argv[0], "search") == 0) {
113 Debug (LDAP_DEBUG_ANY,
114 "%s: line %d: missing proc in \"search <proc>\" line\n",
118 ti->ti_search = (char *) strdup (argv[1]);
120 /* proc for compares */
121 } else if (strcasecmp (argv[0], "compare") == 0) {
123 Debug (LDAP_DEBUG_ANY,
124 "%s: line %d: missing proc in \"compare <proc>\" line\n",
128 ti->ti_compare = (char *) strdup (argv[1]);
130 /* proc for modify */
131 } else if (strcasecmp (argv[0], "modify") == 0) {
133 Debug (LDAP_DEBUG_ANY,
134 "%s: line %d: missing proc in \"modify <proc>\" line\n",
138 ti->ti_modify = (char *) strdup (argv[1]);
140 /* proc for modrdn */
141 } else if (strcasecmp (argv[0], "modrdn") == 0) {
143 Debug (LDAP_DEBUG_ANY,
144 "%s: line %d: missing proc in \"modrdn <proc>\" line\n",
148 ti->ti_modrdn = (char *) strdup (argv[1]);
151 } else if (strcasecmp (argv[0], "add") == 0) {
153 Debug (LDAP_DEBUG_ANY,
154 "%s: line %d: missing proc in \"add <proc>\" line\n",
158 ti->ti_add = (char *) strdup (argv[1]);
160 /* proc for delete */
161 } else if (strcasecmp (argv[0], "delete") == 0) {
163 Debug (LDAP_DEBUG_ANY,
164 "%s: line %d: missing proc in \"delete <proc>\" line\n",
168 ti->ti_delete = (char *) strdup (argv[1]);
170 /* proc for abandon */
171 } else if (strcasecmp (argv[0], "abandon") == 0) {
173 Debug (LDAP_DEBUG_ANY,
174 "%s: line %d: missing proc in \"abandon <proc>\" line\n",
178 ti->ti_search = (char *) strdup (argv[1]);
181 Debug (LDAP_DEBUG_ANY,
182 "Unknown tcl backend config: %s\n", argv[0], 0, 0);
189 void readtclscript (char *script, Tcl_Interp * my_tcl)
193 f = fopen (script, "r");
195 Debug (LDAP_DEBUG_ANY, "Could not open scriptpath %s\n", script,
200 code = Tcl_EvalFile (my_tcl, script);
201 if (code != TCL_OK) {
202 Debug (LDAP_DEBUG_ANY, "%s: %s\n", script,
203 Tcl_GetVar (my_tcl, "errorInfo", TCL_GLOBAL_ONLY), 0);
204 Debug (LDAP_DEBUG_ANY, "%s: error at line\n", script,
205 my_tcl->errorLine, 0);