]> git.sur5r.net Git - openldap/blob - servers/slapd/back-tcl/tcl_config.c
ba32b9a3badf32ddb4cffc110c949f7c208a9577
[openldap] / servers / slapd / back-tcl / tcl_config.c
1 /* config.c - tcl backend configuration file routine
2  *
3  * $Id: tcl_config.c,v 1.5 1999/02/19 06:55:20 bcollins Exp $
4  *
5  * Copyright 1999, Ben Collins <bcollins@debian.org>, All rights reserved.
6  *
7  * Redistribution and use in source and binary forms are permitted only
8  * as authorized by the OpenLDAP Public License.  A copy of this
9  * license is available at http://www.OpenLDAP.org/license.html or
10  * in file LICENSE in the top-level directory of the distribution.
11  */
12
13 #include "portable.h"
14
15 #include <stdio.h>
16
17 #include "slap.h"
18 #include "tcl_back.h"
19
20 struct i_info *global_i;
21
22 int
23 tcl_back_db_config (
24         BackendDB * bd,
25         char *fname,
26         int lineno,
27         int argc,
28         char **argv
29 )
30 {
31         struct tclinfo *ti = (struct tclinfo *) bd->be_private;
32         int script_loaded = 0;
33
34         if (ti == NULL) {
35                 fprintf (stderr,
36                         "%s: line %d: tcl backend info is null!\n", fname,
37                         lineno);
38                 return (1);
39         }
40         if (ti->ti_ii == NULL) {
41                 ti->ti_ii = global_i;
42         }
43
44         /* Script to load */
45         if (strcasecmp (argv[0], "scriptpath") == 0) {
46                 if (argc < 2) {
47                         Debug (LDAP_DEBUG_CONFIG,
48                                 "%s: line %d: missing script in \"scriptpath <script>\" line\n",
49                                 fname, lineno, 0);
50                         return (1);
51                 }
52                 ti->script_path = (char *) ch_strdup (argv[1]);
53
54                 /* use local interpreter */
55         } else if (strcasecmp (argv[0], "tclrealm") == 0) {
56                 struct i_info *ii;
57
58                 if (argc < 2) {
59                         Debug (LDAP_DEBUG_CONFIG,
60                                 "%s: line %d: missing script in \"tclrealm <name>\" line\n",
61                                 fname, lineno, 0);
62                         return (1);
63                 }
64                 ti->ti_ii = NULL;
65
66                 ii = global_i;
67                 /* Try to see if it already exists */
68                 do {
69                         if (ii != NULL && !strcasecmp (ii->name, argv[1]))
70                                 ti->ti_ii = ii;
71                         if (ii->next != NULL)
72                                 ii = ii->next;
73                 } while (ii->next != NULL);
74
75                 if (ti->ti_ii == NULL) {        /* we need to make a new one */
76                         ii->next = (struct i_info *) ch_malloc
77                                 (sizeof (struct i_info));
78
79                         ii->next->count = 0;
80                         ii->next->name = (char *) ch_strdup (argv[1]);
81                         ii->next->interp = NULL;
82                         ii->next->next = NULL;
83                         ti->ti_ii = ii->next;
84                 }
85
86                 /* proc for binds */
87         } else if (strcasecmp (argv[0], "bind") == 0) {
88                 if (argc < 2) {
89                         Debug (LDAP_DEBUG_CONFIG,
90                                 "%s: line %d: missing proc in \"bind <proc>\" line\n",
91                                 fname, lineno, 0);
92                         return (1);
93                 }
94                 ti->ti_bind = (char *) ch_strdup (argv[1]);
95
96                 /* proc for unbinds */
97         } else if (strcasecmp (argv[0], "unbind") == 0) {
98                 if (argc < 2) {
99                         Debug (LDAP_DEBUG_CONFIG,
100                                 "%s: line %d: missing proc in \"unbind <proc>\" line\n",
101                                 fname, lineno, 0);
102                         return (1);
103                 }
104                 ti->ti_unbind = (char *) ch_strdup (argv[1]);
105
106                 /* proc for search */
107         } else if (strcasecmp (argv[0], "search") == 0) {
108                 if (argc < 2) {
109                         Debug (LDAP_DEBUG_CONFIG,
110                                 "%s: line %d: missing proc in \"search <proc>\" line\n",
111                                 fname, lineno, 0);
112                         return (1);
113                 }
114                 ti->ti_search = (char *) ch_strdup (argv[1]);
115
116                 /* proc for compares */
117         } else if (strcasecmp (argv[0], "compare") == 0) {
118                 if (argc < 2) {
119                         Debug (LDAP_DEBUG_CONFIG,
120                                 "%s: line %d: missing proc in \"compare <proc>\" line\n",
121                                 fname, lineno, 0);
122                         return (1);
123                 }
124                 ti->ti_compare = (char *) ch_strdup (argv[1]);
125
126                 /* proc for modify */
127         } else if (strcasecmp (argv[0], "modify") == 0) {
128                 if (argc < 2) {
129                         Debug (LDAP_DEBUG_CONFIG,
130                                 "%s: line %d: missing proc in \"modify <proc>\" line\n",
131                                 fname, lineno, 0);
132                         return (1);
133                 }
134                 ti->ti_modify = (char *) ch_strdup (argv[1]);
135
136                 /* proc for modrdn */
137         } else if (strcasecmp (argv[0], "modrdn") == 0) {
138                 if (argc < 2) {
139                         Debug (LDAP_DEBUG_CONFIG,
140                                 "%s: line %d: missing proc in \"modrdn <proc>\" line\n",
141                                 fname, lineno, 0);
142                         return (1);
143                 }
144                 ti->ti_modrdn = (char *) ch_strdup (argv[1]);
145
146                 /* proc for add */
147         } else if (strcasecmp (argv[0], "add") == 0) {
148                 if (argc < 2) {
149                         Debug (LDAP_DEBUG_CONFIG,
150                                 "%s: line %d: missing proc in \"add <proc>\" line\n",
151                                 fname, lineno, 0);
152                         return (1);
153                 }
154                 ti->ti_add = (char *) ch_strdup (argv[1]);
155
156                 /* proc for delete */
157         } else if (strcasecmp (argv[0], "delete") == 0) {
158                 if (argc < 2) {
159                         Debug (LDAP_DEBUG_CONFIG,
160                                 "%s: line %d: missing proc in \"delete <proc>\" line\n",
161                                 fname, lineno, 0);
162                         return (1);
163                 }
164                 ti->ti_delete = (char *) ch_strdup (argv[1]);
165
166                 /* proc for abandon */
167         } else if (strcasecmp (argv[0], "abandon") == 0) {
168                 if (argc < 2) {
169                         Debug (LDAP_DEBUG_CONFIG,
170                                 "%s: line %d: missing proc in \"abandon <proc>\" line\n",
171                                 fname, lineno, 0);
172                         return (1);
173                 }
174                 ti->ti_search = (char *) ch_strdup (argv[1]);
175
176         } else {
177                 Debug (LDAP_DEBUG_CONFIG,
178                         "Unknown tcl backend config: %s\n", argv[0], 0, 0);
179                 return (1);
180         }
181
182         return 0;
183 }