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