]> git.sur5r.net Git - openldap/blob - servers/slapd/back-sql/config.c
7403cc1d6e9e33be40fff8ad64e9908848309888
[openldap] / servers / slapd / back-sql / config.c
1 /*
2  *       Copyright 1999, Dmitry Kovalev <mit@openldap.org>, All rights reserved.
3  *
4  *       Redistribution and use in source and binary forms are permitted only
5  *       as authorized by the OpenLDAP Public License.  A copy of this
6  *       license is available at http://www.OpenLDAP.org/license.html or
7  *       in file LICENSE in the top-level directory of the distribution.
8  */
9
10 #include "portable.h"
11
12 #ifdef SLAPD_SQL
13
14 #include <stdio.h>
15 #include <string.h>
16 #include <sys/types.h>
17 #include "slap.h"
18 #include "back-sql.h"
19 #include "sql-wrap.h"
20
21 int
22 backsql_db_config(
23         BackendDB       *be,
24         const char      *fname,
25         int             lineno,
26         int             argc,
27         char            **argv )
28 {
29         backsql_info    *si = (backsql_info *)be->be_private;
30
31         Debug( LDAP_DEBUG_TRACE, "==>backsql_db_config()\n", 0, 0, 0 );
32         assert( si );
33   
34         if ( !strcasecmp( argv[ 0 ], "dbhost" ) ) {
35                 if ( argc < 2 ) {
36                         Debug( LDAP_DEBUG_TRACE, 
37                                 "<==backsql_db_config (%s line %d): "
38                                 "missing hostname in dbhost directive\n",
39                                 fname, lineno, 0 );
40                         return 1;
41                 }
42                 si->dbhost = ch_strdup( argv[ 1 ] );
43                 Debug( LDAP_DEBUG_TRACE,
44                         "<==backsql_db_config(): hostname=%s\n",
45                         si->dbhost, 0, 0 );
46
47         } else if ( !strcasecmp( argv[ 0 ], "dbuser" ) ) {
48                 if ( argc < 2 ) {
49                         Debug( LDAP_DEBUG_TRACE, 
50                                 "<==backsql_db_config (%s line %d): "
51                                 "missing username in dbuser directive\n",
52                                 fname, lineno, 0 );
53                         return 1;
54                 }
55                 si->dbuser = ch_strdup( argv[ 1 ] );
56                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): dbuser=%s\n",
57                         si->dbuser, 0, 0 );
58
59         } else if ( !strcasecmp( argv[ 0 ], "dbpasswd" ) ) {
60                 if ( argc < 2 ) {
61                         Debug( LDAP_DEBUG_TRACE, 
62                                 "<==backsql_db_config (%s line %d): "
63                                 "missing password in dbpasswd directive\n",
64                                 fname, lineno, 0 );
65                         return 1;
66                 }
67                 si->dbpasswd = ch_strdup( argv[ 1 ] );
68                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
69                         "dbpasswd=%s\n", /* si->dbpasswd */ "xxxx", 0, 0 );
70
71         } else if ( !strcasecmp( argv[ 0 ], "dbname" ) ) {
72                 if ( argc < 2 ) {
73                         Debug( LDAP_DEBUG_TRACE, 
74                                 "<==backsql_db_config (%s line %d): "
75                                 "missing database name in dbname directive\n",
76                                 fname, lineno, 0 );
77                         return 1;
78                 }
79                 si->dbname = ch_strdup( argv[ 1 ] );
80                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): dbname=%s\n",
81                         si->dbname, 0, 0 );
82
83         } else if ( !strcasecmp( argv[ 0 ], "subtree_cond" ) ) {
84                 if ( argc < 2 ) {
85                         Debug( LDAP_DEBUG_TRACE, 
86                                 "<==backsql_db_config (%s line %d): "
87                                 "missing SQL condition "
88                                 "in subtree_cond directive\n",
89                                 fname, lineno, 0 );
90                         return 1;
91                 }
92                 si->subtree_cond = ch_strdup( argv[ 1 ] );
93                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
94                         "subtree_cond=%s\n", si->subtree_cond, 0, 0 );
95
96         } else if ( !strcasecmp( argv[ 0 ], "oc_query" ) ) {
97                 if ( argc < 2 ) {
98                         Debug( LDAP_DEBUG_TRACE, 
99                                 "<==backsql_db_config (%s line %d): "
100                                 "missing SQL statement "
101                                 "in oc_query directive\n",
102                                 fname, lineno, 0 );
103                         return 1;
104                 }
105                 si->oc_query = ch_strdup( argv[ 1 ] );
106                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
107                         "oc_query=%s\n", si->oc_query, 0, 0 );
108
109         } else if ( !strcasecmp( argv[ 0 ], "at_query" ) ) {
110                 if ( argc < 2 ) {
111                         Debug( LDAP_DEBUG_TRACE,
112                                 "<==backsql_db_config (%s line %d): "
113                                 "missing SQL statement "
114                                 "in at_query directive\n",
115                                 fname, lineno, 0 );
116                         return 1;
117                 }
118                 si->at_query = ch_strdup( argv[ 1 ] );
119                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
120                         "at_query=%s\n", si->at_query, 0, 0 );
121
122         } else if ( !strcasecmp( argv[ 0 ], "insentry_query" ) ) {
123                 if ( argc < 2 ) {
124                         Debug( LDAP_DEBUG_TRACE, 
125                                 "<==backsql_db_config (%s line %d): "
126                                 "missing SQL statement "
127                                 "in insentry_query directive\n",
128                                 fname, lineno, 0 );
129                         return 1;
130                 }
131                 si->insentry_query = ch_strdup( argv[ 1 ] );
132                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
133                         "insentry_query=%s\n", si->insentry_query, 0, 0 );
134
135         } else if ( !strcasecmp( argv[ 0 ], "upper_func" ) ) {
136                 if ( argc < 2 ) {
137                         Debug( LDAP_DEBUG_TRACE,
138                                 "<==backsql_db_config (%s line %d): "
139                                 "missing function name "
140                                 "in upper_func directive\n",
141                                 fname, lineno, 0 );
142                         return 1;
143                 }
144                 si->upper_func = ch_strdup( argv[ 1 ] );
145                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
146                         "upper_func=%s\n", si->upper_func, 0, 0 );
147
148         } else if ( !strcasecmp( argv[ 0 ], "strcast_func" ) ) {
149                 if ( argc < 2 ) {
150                         Debug( LDAP_DEBUG_TRACE,
151                                 "<==backsql_db_config (%s line %d): "
152                                 "missing function name "
153                                 "in strcast_func directive\n",
154                                 fname, lineno, 0 );
155                         return 1;
156                 }
157                 si->strcast_func = ch_strdup( argv[ 1 ] );
158                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
159                         "strcast_func=%s\n", si->strcast_func, 0, 0 );
160
161         } else if ( !strcasecmp( argv[ 0 ], "delentry_query" ) ) {
162                 if ( argc < 2 ) {
163                         Debug( LDAP_DEBUG_TRACE,
164                                 "<==backsql_db_config (%s line %d): "
165                                 "missing SQL statement "
166                                 "in delentry_query directive\n",
167                                 fname, lineno, 0 );
168                         return 1;
169                 }
170                 si->delentry_query = ch_strdup( argv[ 1 ] );
171                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
172                         "delentry_query=%s\n", si->delentry_query, 0, 0 );
173
174         } else if ( !strcasecmp( argv[ 0 ], "has_ldapinfo_dn_ru") ) {
175                 if ( argc < 2 ) {
176                         Debug( LDAP_DEBUG_TRACE,
177                                 "<==backsql_db_config (%s line %d): "
178                                 "missing { yes | no }"
179                                 "in has_ldapinfo_dn_ru directive\n",
180                                 fname, lineno, 0 );
181                         return 1;
182                 }
183
184                 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
185                         si->has_ldapinfo_dn_ru = 1;
186                 } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
187                         si->has_ldapinfo_dn_ru = 0;
188                 } else {
189                         Debug( LDAP_DEBUG_TRACE,
190                                 "<==backsql_db_config (%s line %d): "
191                                 "has_ldapinfo_dn_ru directive arg "
192                                 "must be \"yes\" or \"no\"\n",
193                                 fname, lineno, 0 );
194                         return 1;
195
196                 }
197                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
198                         "has_ldapinfo_dn_ru=%s\n", 
199                         si->has_ldapinfo_dn_ru == 0 ? "no" : "yes", 0, 0 );
200
201         } else {
202                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config (%s line %d): "
203                         "unknown directive '%s' (ignored)\n",
204                         fname, lineno, argv[ 0 ] );
205         }
206
207         return 0;
208 }
209
210 #endif /* SLAPD_SQL */
211