]> git.sur5r.net Git - openldap/blob - servers/slapd/config.c
f4fb95618cfb60b7ca7bdebb0b8e458e44b60fe2
[openldap] / servers / slapd / config.c
1 /* config.c - configuration file handling routines */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 1998-2007 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
17  * All rights reserved.
18  *
19  * Redistribution and use in source and binary forms are permitted
20  * provided that this notice is preserved and that due credit is given
21  * to the University of Michigan at Ann Arbor. The name of the University
22  * may not be used to endorse or promote products derived from this
23  * software without specific prior written permission. This software
24  * is provided ``as is'' without express or implied warranty.
25  */
26
27 #include "portable.h"
28
29 #include <stdio.h>
30
31 #include <ac/string.h>
32 #include <ac/ctype.h>
33 #include <ac/signal.h>
34 #include <ac/socket.h>
35 #include <ac/errno.h>
36
37 #include <sys/types.h>
38 #include <sys/stat.h>
39
40 #ifndef S_ISREG
41 #define S_ISREG(m)      (((m) & _S_IFMT) == _S_IFREG)
42 #endif
43
44 #if HAVE_UNISTD_H
45 #include <unistd.h>
46 #endif
47
48 #include "slap.h"
49 #ifdef LDAP_SLAPI
50 #include "slapi/slapi.h"
51 #endif
52 #include "lutil.h"
53 #include "lutil_ldap.h"
54 #include "config.h"
55
56 #ifdef HAVE_TLS
57 #include <openssl/ssl.h>
58 #endif
59
60 #define ARGS_STEP       512
61
62 /*
63  * defaults for various global variables
64  */
65 slap_mask_t             global_allows = 0;
66 slap_mask_t             global_disallows = 0;
67 int             global_gentlehup = 0;
68 int             global_idletimeout = 0;
69 char    *global_host = NULL;
70 char    *global_realm = NULL;
71 char            *ldap_srvtab = "";
72 char            **default_passwd_hash = NULL;
73 struct berval default_search_base = BER_BVNULL;
74 struct berval default_search_nbase = BER_BVNULL;
75
76 ber_len_t sockbuf_max_incoming = SLAP_SB_MAX_INCOMING_DEFAULT;
77 ber_len_t sockbuf_max_incoming_auth= SLAP_SB_MAX_INCOMING_AUTH;
78
79 int     slap_conn_max_pending = SLAP_CONN_MAX_PENDING_DEFAULT;
80 int     slap_conn_max_pending_auth = SLAP_CONN_MAX_PENDING_AUTH;
81
82 char   *slapd_pid_file  = NULL;
83 char   *slapd_args_file = NULL;
84
85 int use_reverse_lookup = 0;
86
87 #ifdef LDAP_SLAPI
88 int slapi_plugins_used = 0;
89 #endif
90
91 static int fp_getline(FILE *fp, ConfigArgs *c);
92 static void fp_getline_init(ConfigArgs *c);
93 static int fp_parse_line(ConfigArgs *c);
94
95 static char     *strtok_quote(char *line, char *sep, char **quote_ptr);
96 static char *strtok_quote_ldif(char **line);
97
98 ConfigArgs *
99 new_config_args( BackendDB *be, const char *fname, int lineno, int argc, char **argv )
100 {
101         ConfigArgs *c;
102         c = ch_calloc( 1, sizeof( ConfigArgs ) );
103         if ( c == NULL ) return(NULL);
104         c->be     = be; 
105         c->fname  = fname;
106         c->argc   = argc;
107         c->argv   = argv; 
108         c->lineno = lineno;
109         snprintf( c->log, sizeof( c->log ), "%s: line %d", fname, lineno );
110         return(c);
111 }
112
113 void
114 init_config_argv( ConfigArgs *c )
115 {
116         c->argv = ch_calloc( ARGS_STEP + 1, sizeof( *c->argv ) );
117         c->argv_size = ARGS_STEP + 1;
118 }
119
120 ConfigTable *config_find_keyword(ConfigTable *Conf, ConfigArgs *c) {
121         int i;
122
123         for(i = 0; Conf[i].name; i++)
124                 if( (Conf[i].length && (!strncasecmp(c->argv[0], Conf[i].name, Conf[i].length))) ||
125                         (!strcasecmp(c->argv[0], Conf[i].name)) ) break;
126         if ( !Conf[i].name ) return NULL;
127         return Conf+i;
128 }
129
130 int config_check_vals(ConfigTable *Conf, ConfigArgs *c, int check_only ) {
131         int rc, arg_user, arg_type, arg_syn, iarg;
132         long larg;
133         ber_len_t barg;
134         
135         if(Conf->arg_type == ARG_IGNORED) {
136                 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> ignored\n",
137                         c->log, Conf->name, 0);
138                 return(0);
139         }
140         arg_type = Conf->arg_type & ARGS_TYPES;
141         arg_user = Conf->arg_type & ARGS_USERLAND;
142         arg_syn = Conf->arg_type & ARGS_SYNTAX;
143
144         if((arg_type == ARG_DN) && c->argc == 1) {
145                 c->argc = 2;
146                 c->argv[1] = "";
147         }
148         if(Conf->min_args && (c->argc < Conf->min_args)) {
149                 snprintf( c->msg, sizeof( c->msg ), "<%s> missing <%s> argument",
150                         c->argv[0], Conf->what );
151                 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: keyword %s\n", c->log, c->msg, 0 );
152                 return(ARG_BAD_CONF);
153         }
154         if(Conf->max_args && (c->argc > Conf->max_args)) {
155                 char    *ignored = " ignored";
156
157                 snprintf( c->msg, sizeof( c->msg ), "<%s> extra cruft after <%s>",
158                         c->argv[0], Conf->what );
159
160                 ignored = "";
161                 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s%s.\n",
162                                 c->log, c->msg, ignored );
163                 return(ARG_BAD_CONF);
164         }
165         if((arg_syn & ARG_DB) && !c->be) {
166                 snprintf( c->msg, sizeof( c->msg ), "<%s> only allowed within database declaration",
167                         c->argv[0] );
168                 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: keyword %s\n",
169                         c->log, c->msg, 0);
170                 return(ARG_BAD_CONF);
171         }
172         if((arg_syn & ARG_PRE_BI) && c->bi) {
173                 snprintf( c->msg, sizeof( c->msg ), "<%s> must occur before any backend %sdeclaration",
174                         c->argv[0], (arg_syn & ARG_PRE_DB) ? "or database " : "" );
175                 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: keyword %s\n",
176                         c->log, c->msg, 0 );
177                 return(ARG_BAD_CONF);
178         }
179         if((arg_syn & ARG_PRE_DB) && c->be && c->be != frontendDB) {
180                 snprintf( c->msg, sizeof( c->msg ), "<%s> must occur before any database declaration",
181                         c->argv[0] );
182                 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: keyword %s\n",
183                         c->log, c->msg, 0);
184                 return(ARG_BAD_CONF);
185         }
186         if((arg_syn & ARG_PAREN) && *c->argv[1] != '(' /*')'*/) {
187                 snprintf( c->msg, sizeof( c->msg ), "<%s> old format not supported", c->argv[0] );
188                 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s\n",
189                         c->log, c->msg, 0);
190                 return(ARG_BAD_CONF);
191         }
192         if(arg_type && !Conf->arg_item && !(arg_syn & ARG_OFFSET)) {
193                 snprintf( c->msg, sizeof( c->msg ), "<%s> invalid config_table, arg_item is NULL",
194                         c->argv[0] );
195                 Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s\n",
196                         c->log, c->msg, 0);
197                 return(ARG_BAD_CONF);
198         }
199         c->type = arg_user;
200         memset(&c->values, 0, sizeof(c->values));
201         if(arg_type == ARG_STRING) {
202                 if ( !check_only )
203                         c->value_string = ch_strdup(c->argv[1]);
204         } else if(arg_type == ARG_BERVAL) {
205                 if ( !check_only )
206                         ber_str2bv( c->argv[1], 0, 1, &c->value_bv );
207         } else if(arg_type == ARG_DN) {
208                 struct berval bv;
209                 ber_str2bv( c->argv[1], 0, 0, &bv );
210                 rc = dnPrettyNormal( NULL, &bv, &c->value_dn, &c->value_ndn, NULL );
211                 if ( rc != LDAP_SUCCESS ) {
212                         snprintf( c->msg, sizeof( c->msg ), "<%s> invalid DN %d (%s)",
213                                 c->argv[0], rc, ldap_err2string( rc ));
214                         Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s\n" , c->log, c->msg, 0);
215                         return(ARG_BAD_CONF);
216                 }
217                 if ( check_only ) {
218                         ch_free( c->value_ndn.bv_val );
219                         ch_free( c->value_dn.bv_val );
220                 }
221         } else {        /* all numeric */
222                 int j;
223                 iarg = 0; larg = 0; barg = 0;
224                 switch(arg_type) {
225                         case ARG_INT:
226                                 if ( lutil_atoix( &iarg, c->argv[1], 0 ) != 0 ) {
227                                         snprintf( c->msg, sizeof( c->msg ),
228                                                 "<%s> unable to parse \"%s\" as int",
229                                                 c->argv[0], c->argv[1] );
230                                         Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s\n",
231                                                 c->log, c->msg, 0);
232                                         return(ARG_BAD_CONF);
233                                 }
234                                 break;
235                         case ARG_LONG:
236                                 if ( lutil_atolx( &larg, c->argv[1], 0 ) != 0 ) {
237                                         snprintf( c->msg, sizeof( c->msg ),
238                                                 "<%s> unable to parse \"%s\" as long",
239                                                 c->argv[0], c->argv[1] );
240                                         Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s\n",
241                                                 c->log, c->msg, 0);
242                                         return(ARG_BAD_CONF);
243                                 }
244                                 break;
245                         case ARG_BER_LEN_T: {
246                                 unsigned long   l;
247                                 if ( lutil_atoulx( &l, c->argv[1], 0 ) != 0 ) {
248                                         snprintf( c->msg, sizeof( c->msg ),
249                                                 "<%s> unable to parse \"%s\" as ber_len_t",
250                                                 c->argv[0], c->argv[1] );
251                                         Debug(LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "%s: %s\n",
252                                                 c->log, c->msg, 0);
253                                         return(ARG_BAD_CONF);
254                                 }
255                                 barg = (ber_len_t)l;
256                                 } break;
257                         case ARG_ON_OFF:
258                                 if (c->argc == 1) {
259                                         iarg = 1;
260                                 } else if ( !strcasecmp(c->argv[1], "on") ||
261                                         !strcasecmp(c->argv[1], "true") ||
262                                         !strcasecmp(c->argv[1], "yes") )
263                                 {
264                                         iarg = 1;
265                                 } else if ( !strcasecmp(c->argv[1], "off") ||
266                                         !strcasecmp(c->argv[1], "false") ||
267                                         !strcasecmp(c->argv[1], "no") )
268                                 {
269                                         iarg = 0;
270                                 } else {
271                                         snprintf( c->msg, sizeof( c->msg ), "<%s> invalid value",
272                                                 c->argv[0] );
273                                         Debug(LDAP_DEBUG_ANY|LDAP_DEBUG_NONE, "%s: %s\n",
274                                                 c->log, c->msg, 0 );
275                                         return(ARG_BAD_CONF);
276                                 }
277                                 break;
278                 }
279                 j = (arg_type & ARG_NONZERO) ? 1 : 0;
280                 if(iarg < j && larg < j && barg < j ) {
281                         larg = larg ? larg : (barg ? barg : iarg);
282                         snprintf( c->msg, sizeof( c->msg ), "<%s> invalid value",
283                                 c->argv[0] );
284                         Debug(LDAP_DEBUG_ANY|LDAP_DEBUG_NONE, "%s: %s\n",
285                                 c->log, c->msg, 0 );
286                         return(ARG_BAD_CONF);
287                 }
288                 switch(arg_type) {
289                         case ARG_ON_OFF:
290                         case ARG_INT:           c->value_int = iarg;            break;
291                         case ARG_LONG:          c->value_long = larg;           break;
292                         case ARG_BER_LEN_T:     c->value_ber_t = barg;          break;
293                 }
294         }
295         return 0;
296 }
297
298 int config_set_vals(ConfigTable *Conf, ConfigArgs *c) {
299         int rc, arg_type;
300         void *ptr = NULL;
301
302         arg_type = Conf->arg_type;
303         if(arg_type & ARG_MAGIC) {
304                 if(!c->be) c->be = frontendDB;
305                 c->msg[0] = '\0';
306                 rc = (*((ConfigDriver*)Conf->arg_item))(c);
307 #if 0
308                 if(c->be == frontendDB) c->be = NULL;
309 #endif
310                 if(rc) {
311                         if ( !c->msg[0] ) {
312                                 snprintf( c->msg, sizeof( c->msg ), "<%s> handler exited with %d",
313                                         c->argv[0], rc );
314                                 Debug(LDAP_DEBUG_CONFIG, "%s: %s!\n",
315                                         c->log, c->msg, 0 );
316                         }
317                         return(ARG_BAD_CONF);
318                 }
319                 return(0);
320         }
321         if(arg_type & ARG_OFFSET) {
322                 if (c->be && (!overlay_is_over(c->be) || 
323                         ((slap_overinfo *)c->be->bd_info)->oi_orig == c->bi))
324                         ptr = c->be->be_private;
325                 else if (c->bi)
326                         ptr = c->bi->bi_private;
327                 else {
328                         snprintf( c->msg, sizeof( c->msg ), "<%s> offset is missing base pointer",
329                                 c->argv[0] );
330                         Debug(LDAP_DEBUG_CONFIG, "%s: %s!\n",
331                                 c->log, c->msg, 0);
332                         return(ARG_BAD_CONF);
333                 }
334                 ptr = (void *)((char *)ptr + (long)Conf->arg_item);
335         } else if (arg_type & ARGS_TYPES) {
336                 ptr = Conf->arg_item;
337         }
338         if(arg_type & ARGS_TYPES)
339                 switch(arg_type & ARGS_TYPES) {
340                         case ARG_ON_OFF:
341                         case ARG_INT:           *(int*)ptr = c->value_int;                      break;
342                         case ARG_LONG:          *(long*)ptr = c->value_long;                    break;
343                         case ARG_BER_LEN_T:     *(ber_len_t*)ptr = c->value_ber_t;                      break;
344                         case ARG_STRING: {
345                                 char *cc = *(char**)ptr;
346                                 if(cc) {
347                                         if ((arg_type & ARG_UNIQUE) && c->op == SLAP_CONFIG_ADD ) {
348                                                 Debug(LDAP_DEBUG_CONFIG, "%s: already set %s!\n",
349                                                         c->log, Conf->name, 0 );
350                                                 return(ARG_BAD_CONF);
351                                         }
352                                         ch_free(cc);
353                                 }
354                                 *(char **)ptr = c->value_string;
355                                 break;
356                                 }
357                         case ARG_BERVAL:
358                                 *(struct berval *)ptr = c->value_bv;
359                                 break;
360                 }
361         return(0);
362 }
363
364 int config_add_vals(ConfigTable *Conf, ConfigArgs *c) {
365         int rc, arg_type;
366
367         arg_type = Conf->arg_type;
368         if(arg_type == ARG_IGNORED) {
369                 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> ignored\n",
370                         c->log, Conf->name, 0);
371                 return(0);
372         }
373         rc = config_check_vals( Conf, c, 0 );
374         if ( rc ) return rc;
375         return config_set_vals( Conf, c );
376 }
377
378 int
379 config_del_vals(ConfigTable *cf, ConfigArgs *c)
380 {
381         int rc = 0;
382
383         /* If there is no handler, just ignore it */
384         if ( cf->arg_type & ARG_MAGIC ) {
385                 c->op = LDAP_MOD_DELETE;
386                 c->type = cf->arg_type & ARGS_USERLAND;
387                 rc = (*((ConfigDriver*)cf->arg_item))(c);
388         }
389         return rc;
390 }
391
392 int
393 config_get_vals(ConfigTable *cf, ConfigArgs *c)
394 {
395         int rc = 0;
396         struct berval bv;
397         void *ptr;
398
399         if ( cf->arg_type & ARG_IGNORED ) {
400                 return 1;
401         }
402
403         memset(&c->values, 0, sizeof(c->values));
404         c->rvalue_vals = NULL;
405         c->rvalue_nvals = NULL;
406         c->op = SLAP_CONFIG_EMIT;
407         c->type = cf->arg_type & ARGS_USERLAND;
408
409         if ( cf->arg_type & ARG_MAGIC ) {
410                 rc = (*((ConfigDriver*)cf->arg_item))(c);
411                 if ( rc ) return rc;
412         } else {
413                 if ( cf->arg_type & ARG_OFFSET ) {
414                         if (c->be && (!overlay_is_over(c->be) || 
415                                 ((slap_overinfo *)c->be->bd_info)->oi_orig == c->bi))
416                                 ptr = c->be->be_private;
417                         else if ( c->bi )
418                                 ptr = c->bi->bi_private;
419                         else
420                                 return 1;
421                         ptr = (void *)((char *)ptr + (long)cf->arg_item);
422                 } else {
423                         ptr = cf->arg_item;
424                 }
425                 
426                 switch(cf->arg_type & ARGS_TYPES) {
427                 case ARG_ON_OFF:
428                 case ARG_INT:   c->value_int = *(int *)ptr; break;
429                 case ARG_LONG:  c->value_long = *(long *)ptr; break;
430                 case ARG_BER_LEN_T:     c->value_ber_t = *(ber_len_t *)ptr; break;
431                 case ARG_STRING:
432                         if ( *(char **)ptr )
433                                 c->value_string = ch_strdup(*(char **)ptr);
434                         break;
435                 case ARG_BERVAL:
436                         ber_dupbv( &c->value_bv, (struct berval *)ptr ); break;
437                 }
438         }
439         if ( cf->arg_type & ARGS_TYPES) {
440                 bv.bv_len = 0;
441                 bv.bv_val = c->log;
442                 switch(cf->arg_type & ARGS_TYPES) {
443                 case ARG_INT: bv.bv_len = snprintf(bv.bv_val, sizeof( c->log ), "%d", c->value_int); break;
444                 case ARG_LONG: bv.bv_len = snprintf(bv.bv_val, sizeof( c->log ), "%ld", c->value_long); break;
445                 case ARG_BER_LEN_T: bv.bv_len = snprintf(bv.bv_val, sizeof( c->log ), "%ld", c->value_ber_t); break;
446                 case ARG_ON_OFF: bv.bv_len = snprintf(bv.bv_val, sizeof( c->log ), "%s",
447                         c->value_int ? "TRUE" : "FALSE"); break;
448                 case ARG_STRING:
449                         if ( c->value_string && c->value_string[0]) {
450                                 ber_str2bv( c->value_string, 0, 0, &bv);
451                         } else {
452                                 return 1;
453                         }
454                         break;
455                 case ARG_BERVAL:
456                         if ( !BER_BVISEMPTY( &c->value_bv )) {
457                                 bv = c->value_bv;
458                         } else {
459                                 return 1;
460                         }
461                         break;
462                 default:
463                         bv.bv_val = NULL;
464                         break;
465                 }
466                 if (bv.bv_val == c->log && bv.bv_len >= sizeof( c->log ) ) {
467                         return 1;
468                 }
469                 if (( cf->arg_type & ARGS_TYPES ) == ARG_STRING ) {
470                         ber_bvarray_add(&c->rvalue_vals, &bv);
471                 } else if ( !BER_BVISNULL( &bv ) ) {
472                         value_add_one(&c->rvalue_vals, &bv);
473                 }
474                 /* else: maybe c->rvalue_vals already set? */
475         }
476         return rc;
477 }
478
479 int
480 init_config_attrs(ConfigTable *ct) {
481         int i, code;
482
483         for (i=0; ct[i].name; i++ ) {
484                 if ( !ct[i].attribute ) continue;
485                 code = register_at( ct[i].attribute, &ct[i].ad, 1 );
486                 if ( code ) {
487                         fprintf( stderr, "init_config_attrs: register_at failed\n" );
488                         return code;
489                 }
490 #ifndef LDAP_DEVEL
491                 ct[i].ad->ad_type->sat_flags |= SLAP_AT_HIDE;
492 #endif
493         }
494
495         return 0;
496 }
497
498 int
499 init_config_ocs( ConfigOCs *ocs ) {
500         int i, code;
501
502         for (i=0;ocs[i].co_def;i++) {
503                 code = register_oc( ocs[i].co_def, &ocs[i].co_oc, 1 );
504                 if ( code ) {
505                         fprintf( stderr, "init_config_ocs: register_oc failed\n" );
506                         return code;
507                 }
508 #ifndef LDAP_DEVEL
509                 ocs[i].co_oc->soc_flags |= SLAP_OC_HIDE;
510 #endif
511         }
512         return 0;
513 }
514
515 /* Split an LDIF line into space-separated tokens. Words may be grouped
516  * by quotes. A quoted string may begin in the middle of a word, but must
517  * end at the end of the word (be followed by whitespace or EOS). Any other
518  * quotes are passed through unchanged. All other characters are passed
519  * through unchanged.
520  */
521 static char *
522 strtok_quote_ldif( char **line )
523 {
524         char *beg, *ptr, *quote=NULL;
525         int inquote=0;
526
527         ptr = *line;
528
529         if ( !ptr || !*ptr )
530                 return NULL;
531
532         while( isspace( (unsigned char) *ptr )) ptr++;
533
534         if ( *ptr == '"' ) {
535                 inquote = 1;
536                 ptr++;
537         }
538
539         beg = ptr;
540
541         for (;*ptr;ptr++) {
542                 if ( *ptr == '"' ) {
543                         if ( inquote && ( !ptr[1] || isspace((unsigned char) ptr[1]))) {
544                                 *ptr++ = '\0';
545                                 break;
546                         }
547                         inquote = 1;
548                         quote = ptr;
549                         continue;
550                 }
551                 if ( inquote )
552                         continue;
553                 if ( isspace( (unsigned char) *ptr )) {
554                         *ptr++ = '\0';
555                         break;
556                 }
557         }
558         if ( quote ) {
559                 while ( quote < ptr ) {
560                         *quote = quote[1];
561                         quote++;
562                 }
563         }
564         if ( !*ptr ) {
565                 *line = NULL;
566         } else {
567                 while ( isspace( (unsigned char) *ptr )) ptr++;
568                 *line = ptr;
569         }
570         return beg;
571 }
572
573 static void
574 config_parse_ldif( ConfigArgs *c )
575 {
576         char *next;
577         c->tline = ch_strdup(c->line);
578         next = c->tline;
579
580         while ((c->argv[c->argc] = strtok_quote_ldif( &next )) != NULL) {
581                 c->argc++;
582                 if ( c->argc >= c->argv_size ) {
583                         char **tmp = ch_realloc( c->argv, (c->argv_size + ARGS_STEP) *
584                                 sizeof( *c->argv ));
585                         c->argv = tmp;
586                         c->argv_size += ARGS_STEP;
587                 }
588         }
589         c->argv[c->argc] = NULL;
590 }
591
592 int
593 config_parse_vals(ConfigTable *ct, ConfigArgs *c, int valx)
594 {
595         int     rc = 0;
596
597         snprintf( c->log, sizeof( c->log ), "%s: value #%d",
598                 ct->ad->ad_cname.bv_val, valx );
599         c->argc = 1;
600         c->argv[0] = ct->ad->ad_cname.bv_val;
601
602         if ( ( ct->arg_type & ARG_QUOTE ) && c->line[ 0 ] != '"' ) {
603                 c->argv[c->argc] = c->line;
604                 c->argc++;
605                 c->argv[c->argc] = NULL;
606                 c->tline = NULL;
607         } else {
608                 config_parse_ldif( c );
609         }
610         rc = config_check_vals( ct, c, 1 );
611         ch_free( c->tline );
612         c->tline = NULL;
613
614         if ( rc )
615                 rc = LDAP_CONSTRAINT_VIOLATION;
616
617         return rc;
618 }
619
620 int
621 config_parse_add(ConfigTable *ct, ConfigArgs *c, int valx)
622 {
623         int     rc = 0;
624
625         snprintf( c->log, sizeof( c->log ), "%s: value #%d",
626                 ct->ad->ad_cname.bv_val, valx );
627         c->argc = 1;
628         c->argv[0] = ct->ad->ad_cname.bv_val;
629
630         if ( ( ct->arg_type & ARG_QUOTE ) && c->line[ 0 ] != '"' ) {
631                 c->argv[c->argc] = c->line;
632                 c->argc++;
633                 c->argv[c->argc] = NULL;
634                 c->tline = NULL;
635         } else {
636                 config_parse_ldif( c );
637         }
638         c->op = LDAP_MOD_ADD;
639         rc = config_add_vals( ct, c );
640         ch_free( c->tline );
641
642         return rc;
643 }
644
645 int
646 read_config_file(const char *fname, int depth, ConfigArgs *cf, ConfigTable *cft)
647 {
648         FILE *fp;
649         ConfigTable *ct;
650         ConfigArgs *c;
651         int rc;
652         struct stat s;
653
654         c = ch_calloc( 1, sizeof( ConfigArgs ) );
655         if ( c == NULL ) {
656                 return 1;
657         }
658
659         if ( depth ) {
660                 memcpy( c, cf, sizeof( ConfigArgs ) );
661         } else {
662                 c->depth = depth; /* XXX */
663                 c->bi = NULL;
664                 c->be = NULL;
665         }
666
667         c->valx = -1;
668         c->fname = fname;
669         init_config_argv( c );
670
671         if ( stat( fname, &s ) != 0 ) {
672                 ldap_syslog = 1;
673                 Debug(LDAP_DEBUG_ANY,
674                     "could not stat config file \"%s\": %s (%d)\n",
675                     fname, strerror(errno), errno);
676                 ch_free( c );
677                 return(1);
678         }
679
680         if ( !S_ISREG( s.st_mode ) ) {
681                 ldap_syslog = 1;
682                 Debug(LDAP_DEBUG_ANY,
683                     "regular file expected, got \"%s\"\n",
684                     fname, 0, 0 );
685                 ch_free( c );
686                 return(1);
687         }
688
689         fp = fopen( fname, "r" );
690         if ( fp == NULL ) {
691                 ldap_syslog = 1;
692                 Debug(LDAP_DEBUG_ANY,
693                     "could not open config file \"%s\": %s (%d)\n",
694                     fname, strerror(errno), errno);
695                 ch_free( c );
696                 return(1);
697         }
698
699         Debug(LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0);
700
701         fp_getline_init(c);
702
703         c->tline = NULL;
704
705         while ( fp_getline( fp, c ) ) {
706                 /* skip comments and blank lines */
707                 if ( c->line[0] == '#' || c->line[0] == '\0' ) {
708                         continue;
709                 }
710
711                 snprintf( c->log, sizeof( c->log ), "%s: line %d",
712                                 c->fname, c->lineno );
713
714                 c->argc = 0;
715                 ch_free( c->tline );
716                 if ( fp_parse_line( c ) ) {
717                         rc = 1;
718                         goto done;
719                 }
720
721                 if ( c->argc < 1 ) {
722                         Debug( LDAP_DEBUG_ANY, "%s: bad config line.\n",
723                                 c->log, 0, 0);
724                         rc = 1;
725                         goto done;
726                 }
727
728                 c->op = SLAP_CONFIG_ADD;
729
730                 ct = config_find_keyword( cft, c );
731                 if ( ct ) {
732                         rc = config_add_vals( ct, c );
733                         if ( !rc ) continue;
734
735                         if ( rc & ARGS_USERLAND ) {
736                                 /* XXX a usertype would be opaque here */
737                                 Debug(LDAP_DEBUG_CONFIG, "%s: unknown user type <%s>\n",
738                                         c->log, c->argv[0], 0);
739                                 rc = 1;
740                                 goto done;
741
742                         } else if ( rc == ARG_BAD_CONF ) {
743                                 rc = 1;
744                                 goto done;
745                         }
746                         
747                 } else if ( c->bi && !c->be ) {
748                         rc = SLAP_CONF_UNKNOWN;
749                         if ( c->bi->bi_cf_ocs ) {
750                                 ct = config_find_keyword( c->bi->bi_cf_ocs->co_table, c );
751                                 if ( ct ) {
752                                         rc = config_add_vals( ct, c );
753                                 }
754                         }
755                         if ( c->bi->bi_config && rc == SLAP_CONF_UNKNOWN ) {
756                                 rc = (*c->bi->bi_config)(c->bi, c->fname, c->lineno,
757                                         c->argc, c->argv);
758                         }
759                         if ( rc ) {
760                                 switch(rc) {
761                                 case SLAP_CONF_UNKNOWN:
762                                         Debug( LDAP_DEBUG_ANY, "%s: unknown directive "
763                                                 "<%s> inside backend info definition.\n",
764                                                 c->log, *c->argv, 0);
765                                 default:
766                                         rc = 1;
767                                         goto done;
768                                 }
769                         }
770
771                 } else if ( c->be && c->be != frontendDB ) {
772                         rc = SLAP_CONF_UNKNOWN;
773                         if ( c->be->be_cf_ocs ) {
774                                 ct = config_find_keyword( c->be->be_cf_ocs->co_table, c );
775                                 if ( ct ) {
776                                         rc = config_add_vals( ct, c );
777                                 }
778                         }
779                         if ( c->be->be_config && rc == SLAP_CONF_UNKNOWN ) {
780                                 rc = (*c->be->be_config)(c->be, c->fname, c->lineno,
781                                         c->argc, c->argv);
782                         }
783                         if ( rc == SLAP_CONF_UNKNOWN && SLAP_ISGLOBALOVERLAY( frontendDB ) )
784                         {
785                                 /* global overlays may need 
786                                  * definitions inside other databases...
787                                  */
788                                 rc = (*frontendDB->be_config)( frontendDB,
789                                         c->fname, (int)c->lineno, c->argc, c->argv );
790                         }
791
792                         switch ( rc ) {
793                         case 0:
794                                 break;
795
796                         case SLAP_CONF_UNKNOWN:
797                                 Debug( LDAP_DEBUG_ANY, "%s: unknown directive "
798                                         "<%s> inside backend database definition.\n",
799                                         c->log, *c->argv, 0);
800                                 
801                         default:
802                                 rc = 1;
803                                 goto done;
804                         }
805
806                 } else if ( frontendDB->be_config ) {
807                         rc = (*frontendDB->be_config)( frontendDB,
808                                 c->fname, (int)c->lineno, c->argc, c->argv);
809                         if ( rc ) {
810                                 switch(rc) {
811                                 case SLAP_CONF_UNKNOWN:
812                                         Debug( LDAP_DEBUG_ANY, "%s: unknown directive "
813                                                 "<%s> inside global database definition.\n",
814                                                 c->log, *c->argv, 0);
815
816                                 default:
817                                         rc = 1;
818                                         goto done;
819                                 }
820                         }
821                         
822                 } else {
823                         Debug( LDAP_DEBUG_ANY, "%s: unknown directive "
824                                 "<%s> outside backend info and database definitions.\n",
825                                 c->log, *c->argv, 0);
826                         rc = 1;
827                         goto done;
828                 }
829         }
830
831         rc = 0;
832
833 done:
834         ch_free(c->tline);
835         fclose(fp);
836         ch_free(c->argv);
837         ch_free(c);
838         return(rc);
839 }
840
841 /* restrictops, allows, disallows, requires, loglevel */
842
843 int
844 bverb_to_mask(struct berval *bword, slap_verbmasks *v) {
845         int i;
846         for(i = 0; !BER_BVISNULL(&v[i].word); i++) {
847                 if(!ber_bvstrcasecmp(bword, &v[i].word)) break;
848         }
849         return(i);
850 }
851
852 int
853 verb_to_mask(const char *word, slap_verbmasks *v) {
854         struct berval   bword;
855         ber_str2bv( word, 0, 0, &bword );
856         return bverb_to_mask( &bword, v );
857 }
858
859 int
860 verbs_to_mask(int argc, char *argv[], slap_verbmasks *v, slap_mask_t *m) {
861         int i, j;
862         for(i = 1; i < argc; i++) {
863                 j = verb_to_mask(argv[i], v);
864                 if(BER_BVISNULL(&v[j].word)) return i;
865                 while (!v[j].mask) j--;
866                 *m |= v[j].mask;
867         }
868         return(0);
869 }
870
871 /* Mask keywords that represent multiple bits should occur before single
872  * bit keywords in the verbmasks array.
873  */
874 int
875 mask_to_verbs(slap_verbmasks *v, slap_mask_t m, BerVarray *bva) {
876         int i, rc = 1;
877
878         if (m) {
879                 for (i=0; !BER_BVISNULL(&v[i].word); i++) {
880                         if (!v[i].mask) continue;
881                         if (( m & v[i].mask ) == v[i].mask ) {
882                                 value_add_one( bva, &v[i].word );
883                                 rc = 0;
884                                 m ^= v[i].mask;
885                                 if ( !m ) break;
886                         }
887                 }
888         }
889         return rc;
890 }
891
892 int
893 slap_verbmasks_init( slap_verbmasks **vp, slap_verbmasks *v )
894 {
895         int             i;
896
897         assert( *vp == NULL );
898
899         for ( i = 0; !BER_BVISNULL( &v[ i ].word ); i++ ) /* EMPTY */;
900
901         *vp = ch_calloc( i + 1, sizeof( slap_verbmasks ) );
902
903         for ( i = 0; !BER_BVISNULL( &v[ i ].word ); i++ ) {
904                 ber_dupbv( &(*vp)[ i ].word, &v[ i ].word );
905                 *((slap_mask_t *)&(*vp)[ i ].mask) = v[ i ].mask;
906         }
907
908         BER_BVZERO( &(*vp)[ i ].word );
909
910         return 0;               
911 }
912
913 int
914 slap_verbmasks_destroy( slap_verbmasks *v )
915 {
916         int             i;
917
918         assert( v != NULL );
919
920         for ( i = 0; !BER_BVISNULL( &v[ i ].word ); i++ ) {
921                 ch_free( v[ i ].word.bv_val );
922         }
923
924         ch_free( v );
925
926         return 0;
927 }
928
929 int
930 slap_verbmasks_append(
931         slap_verbmasks  **vp,
932         slap_mask_t     m,
933         struct berval   *v,
934         slap_mask_t     *ignore )
935 {
936         int     i;
937
938         if ( !m ) {
939                 return LDAP_OPERATIONS_ERROR;
940         }
941
942         for ( i = 0; !BER_BVISNULL( &(*vp)[ i ].word ); i++ ) {
943                 if ( !(*vp)[ i ].mask ) continue;
944
945                 if ( ignore != NULL ) {
946                         int     j;
947
948                         for ( j = 0; ignore[ j ] != 0; j++ ) {
949                                 if ( (*vp)[ i ].mask == ignore[ j ] ) {
950                                         goto check_next;
951                                 }
952                         }
953                 }
954
955                 if ( ( m & (*vp)[ i ].mask ) == (*vp)[ i ].mask ) {
956                         if ( ber_bvstrcasecmp( v, &(*vp)[ i ].word ) == 0 ) {
957                                 /* already set; ignore */
958                                 return LDAP_SUCCESS;
959                         }
960                         /* conflicts */
961                         return LDAP_TYPE_OR_VALUE_EXISTS;
962                 }
963
964                 if ( m & (*vp)[ i ].mask ) {
965                         /* conflicts */
966                         return LDAP_CONSTRAINT_VIOLATION;
967                 }
968 check_next:;
969         }
970
971         *vp = ch_realloc( *vp, sizeof( slap_verbmasks ) * ( i + 2 ) );
972         ber_dupbv( &(*vp)[ i ].word, v );
973         *((slap_mask_t *)&(*vp)[ i ].mask) = m;
974         BER_BVZERO( &(*vp)[ i + 1 ].word );
975
976         return LDAP_SUCCESS;
977 }
978
979 int
980 enum_to_verb(slap_verbmasks *v, slap_mask_t m, struct berval *bv) {
981         int i;
982
983         for (i=0; !BER_BVISNULL(&v[i].word); i++) {
984                 if ( m == v[i].mask ) {
985                         if ( bv != NULL ) {
986                                 *bv = v[i].word;
987                         }
988                         return i;
989                 }
990         }
991         return -1;
992 }
993
994 #ifdef HAVE_TLS
995 static slap_verbmasks tlskey[] = {
996         { BER_BVC("no"),        SB_TLS_OFF },
997         { BER_BVC("yes"),       SB_TLS_ON },
998         { BER_BVC("critical"),  SB_TLS_CRITICAL },
999         { BER_BVNULL, 0 }
1000 };
1001
1002 static slap_verbmasks crlkeys[] = {
1003                 { BER_BVC("none"),      LDAP_OPT_X_TLS_CRL_NONE },
1004                 { BER_BVC("peer"),      LDAP_OPT_X_TLS_CRL_PEER },
1005                 { BER_BVC("all"),       LDAP_OPT_X_TLS_CRL_ALL },
1006                 { BER_BVNULL, 0 }
1007         };
1008
1009 static slap_verbmasks vfykeys[] = {
1010                 { BER_BVC("never"),     LDAP_OPT_X_TLS_NEVER },
1011                 { BER_BVC("demand"),    LDAP_OPT_X_TLS_DEMAND },
1012                 { BER_BVC("try"),       LDAP_OPT_X_TLS_TRY },
1013                 { BER_BVC("hard"),      LDAP_OPT_X_TLS_HARD },
1014                 { BER_BVNULL, 0 }
1015         };
1016 #endif
1017
1018 static slap_verbmasks methkey[] = {
1019         { BER_BVC("none"),      LDAP_AUTH_NONE },
1020         { BER_BVC("simple"),    LDAP_AUTH_SIMPLE },
1021 #ifdef HAVE_CYRUS_SASL
1022         { BER_BVC("sasl"),      LDAP_AUTH_SASL },
1023 #endif
1024         { BER_BVNULL, 0 }
1025 };
1026
1027 static slap_verbmasks versionkey[] = {
1028         { BER_BVC("2"),         LDAP_VERSION2 },
1029         { BER_BVC("3"),         LDAP_VERSION3 },
1030         { BER_BVNULL, 0 }
1031 };
1032
1033 static slap_cf_aux_table bindkey[] = {
1034         { BER_BVC("uri="), offsetof(slap_bindconf, sb_uri), 'b', 1, NULL },
1035         { BER_BVC("version="), offsetof(slap_bindconf, sb_version), 'i', 0, versionkey },
1036         { BER_BVC("bindmethod="), offsetof(slap_bindconf, sb_method), 'i', 0, methkey },
1037         { BER_BVC("binddn="), offsetof(slap_bindconf, sb_binddn), 'b', 1, (slap_verbmasks *)dnNormalize },
1038         { BER_BVC("credentials="), offsetof(slap_bindconf, sb_cred), 'b', 1, NULL },
1039         { BER_BVC("saslmech="), offsetof(slap_bindconf, sb_saslmech), 'b', 0, NULL },
1040         { BER_BVC("secprops="), offsetof(slap_bindconf, sb_secprops), 's', 0, NULL },
1041         { BER_BVC("realm="), offsetof(slap_bindconf, sb_realm), 'b', 0, NULL },
1042         { BER_BVC("authcID="), offsetof(slap_bindconf, sb_authcId), 'b', 0, (slap_verbmasks *)authzNormalize },
1043         { BER_BVC("authzID="), offsetof(slap_bindconf, sb_authzId), 'b', 1, (slap_verbmasks *)authzNormalize },
1044 #ifdef HAVE_TLS
1045         { BER_BVC("starttls="), offsetof(slap_bindconf, sb_tls), 'i', 0, tlskey },
1046
1047         /* NOTE: replace "11" with the actual index
1048          * of the first TLS-related line */
1049 #define aux_TLS (bindkey+11)    /* beginning of TLS keywords */
1050
1051         { BER_BVC("tls_cert="), offsetof(slap_bindconf, sb_tls_cert), 's', 1, NULL },
1052         { BER_BVC("tls_key="), offsetof(slap_bindconf, sb_tls_key), 's', 1, NULL },
1053         { BER_BVC("tls_cacert="), offsetof(slap_bindconf, sb_tls_cacert), 's', 1, NULL },
1054         { BER_BVC("tls_cacertdir="), offsetof(slap_bindconf, sb_tls_cacertdir), 's', 1, NULL },
1055         { BER_BVC("tls_reqcert="), offsetof(slap_bindconf, sb_tls_reqcert), 's', 1, NULL },
1056         { BER_BVC("tls_cipher_suite="), offsetof(slap_bindconf, sb_tls_cipher_suite), 's', 1, NULL },
1057 #ifdef HAVE_OPENSSL_CRL
1058         { BER_BVC("tls_crlcheck="), offsetof(slap_bindconf, sb_tls_crlcheck), 's', 1, NULL },
1059 #endif
1060 #endif
1061         { BER_BVNULL, 0, 0, 0, NULL }
1062 };
1063
1064 /*
1065  * 's': char *
1066  * 'b': struct berval; if !NULL, normalize using ((slap_mr_normalize_func *)aux)
1067  * 'i': int; if !NULL, compute using ((slap_verbmasks *)aux)
1068  * 'u': unsigned
1069  * 'I': long
1070  * 'U': unsigned long
1071  */
1072
1073 int
1074 slap_cf_aux_table_parse( const char *word, void *dst, slap_cf_aux_table *tab0, LDAP_CONST char *tabmsg )
1075 {
1076         int rc = SLAP_CONF_UNKNOWN;
1077         slap_cf_aux_table *tab;
1078
1079         for ( tab = tab0; !BER_BVISNULL( &tab->key ); tab++ ) {
1080                 if ( !strncasecmp( word, tab->key.bv_val, tab->key.bv_len ) ) {
1081                         char **cptr;
1082                         int *iptr, j;
1083                         unsigned *uptr;
1084                         long *lptr;
1085                         unsigned long *ulptr;
1086                         struct berval *bptr;
1087                         const char *val = word + tab->key.bv_len;
1088
1089                         switch ( tab->type ) {
1090                         case 's':
1091                                 cptr = (char **)((char *)dst + tab->off);
1092                                 *cptr = ch_strdup( val );
1093                                 rc = 0;
1094                                 break;
1095
1096                         case 'b':
1097                                 bptr = (struct berval *)((char *)dst + tab->off);
1098                                 if ( tab->aux != NULL ) {
1099                                         struct berval   dn;
1100                                         slap_mr_normalize_func *normalize = (slap_mr_normalize_func *)tab->aux;
1101
1102                                         ber_str2bv( val, 0, 0, &dn );
1103                                         rc = normalize( 0, NULL, NULL, &dn, bptr, NULL );
1104
1105                                 } else {
1106                                         ber_str2bv( val, 0, 1, bptr );
1107                                         rc = 0;
1108                                 }
1109                                 break;
1110
1111                         case 'i':
1112                                 iptr = (int *)((char *)dst + tab->off);
1113
1114                                 if ( tab->aux != NULL ) {
1115                                         slap_verbmasks *aux = (slap_verbmasks *)tab->aux;
1116
1117                                         assert( aux != NULL );
1118
1119                                         rc = 1;
1120                                         for ( j = 0; !BER_BVISNULL( &aux[j].word ); j++ ) {
1121                                                 if ( !strcasecmp( val, aux[j].word.bv_val ) ) {
1122                                                         *iptr = aux[j].mask;
1123                                                         rc = 0;
1124                                                         break;
1125                                                 }
1126                                         }
1127
1128                                 } else {
1129                                         rc = lutil_atoix( iptr, val, 0 );
1130                                 }
1131                                 break;
1132
1133                         case 'u':
1134                                 uptr = (unsigned *)((char *)dst + tab->off);
1135
1136                                 rc = lutil_atoux( uptr, val, 0 );
1137                                 break;
1138
1139                         case 'I':
1140                                 lptr = (long *)((char *)dst + tab->off);
1141
1142                                 rc = lutil_atolx( lptr, val, 0 );
1143                                 break;
1144
1145                         case 'U':
1146                                 ulptr = (unsigned long *)((char *)dst + tab->off);
1147
1148                                 rc = lutil_atoulx( ulptr, val, 0 );
1149                                 break;
1150                         }
1151
1152                         if ( rc ) {
1153                                 Debug( LDAP_DEBUG_ANY, "invalid %s value %s\n",
1154                                         tabmsg, word, 0 );
1155                         }
1156                         
1157                         return rc;
1158                 }
1159         }
1160
1161         return rc;
1162 }
1163
1164 int
1165 slap_cf_aux_table_unparse( void *src, struct berval *bv, slap_cf_aux_table *tab0 )
1166 {
1167         char buf[AC_LINE_MAX], *ptr;
1168         slap_cf_aux_table *tab;
1169         struct berval tmp;
1170
1171         ptr = buf;
1172         for (tab = tab0; !BER_BVISNULL(&tab->key); tab++ ) {
1173                 char **cptr;
1174                 int *iptr, i;
1175                 unsigned *uptr;
1176                 long *lptr;
1177                 unsigned long *ulptr;
1178                 struct berval *bptr;
1179
1180                 cptr = (char **)((char *)src + tab->off);
1181
1182                 switch ( tab->type ) {
1183                 case 'b':
1184                         bptr = (struct berval *)((char *)src + tab->off);
1185                         cptr = &bptr->bv_val;
1186
1187                 case 's':
1188                         if ( *cptr ) {
1189                                 *ptr++ = ' ';
1190                                 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1191                                 if ( tab->quote ) *ptr++ = '"';
1192                                 ptr = lutil_strcopy( ptr, *cptr );
1193                                 if ( tab->quote ) *ptr++ = '"';
1194                         }
1195                         break;
1196
1197                 case 'i':
1198                         iptr = (int *)((char *)src + tab->off);
1199
1200                         if ( tab->aux != NULL ) {
1201                                 slap_verbmasks *aux = (slap_verbmasks *)tab->aux;
1202
1203                                 for ( i = 0; !BER_BVISNULL( &aux[i].word ); i++ ) {
1204                                         if ( *iptr == aux[i].mask ) {
1205                                                 *ptr++ = ' ';
1206                                                 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1207                                                 ptr = lutil_strcopy( ptr, aux[i].word.bv_val );
1208                                                 break;
1209                                         }
1210                                 }
1211
1212                         } else {
1213                                 *ptr++ = ' ';
1214                                 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1215                                 ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%d", *iptr );
1216                         }
1217                         break;
1218
1219                 case 'u':
1220                         uptr = (unsigned *)((char *)src + tab->off);
1221                         *ptr++ = ' ';
1222                         ptr = lutil_strcopy( ptr, tab->key.bv_val );
1223                         ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%u", *uptr );
1224                         break;
1225
1226                 case 'I':
1227                         lptr = (long *)((char *)src + tab->off);
1228                         *ptr++ = ' ';
1229                         ptr = lutil_strcopy( ptr, tab->key.bv_val );
1230                         ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%ld", *lptr );
1231                         break;
1232
1233                 case 'U':
1234                         ulptr = (unsigned long *)((char *)src + tab->off);
1235                         *ptr++ = ' ';
1236                         ptr = lutil_strcopy( ptr, tab->key.bv_val );
1237                         ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%lu", *ulptr );
1238                         break;
1239
1240                 default:
1241                         assert( 0 );
1242                 }
1243         }
1244         tmp.bv_val = buf;
1245         tmp.bv_len = ptr - buf;
1246         ber_dupbv( bv, &tmp );
1247         return 0;
1248 }
1249
1250 int
1251 slap_tls_get_config( LDAP *ld, int opt, char **val )
1252 {
1253         slap_verbmasks *keys;
1254         int i, ival;
1255
1256         *val = NULL;
1257         switch( opt ) {
1258         case LDAP_OPT_X_TLS_CRLCHECK:
1259                 keys = crlkeys;
1260                 break;
1261         case LDAP_OPT_X_TLS_REQUIRE_CERT:
1262                 keys = vfykeys;
1263                 break;
1264         default:
1265                 return -1;
1266         }
1267         ldap_pvt_tls_get_option( ld, opt, &ival );
1268         for (i=0; !BER_BVISNULL(&keys[i].word); i++) {
1269                 if (keys[i].mask == ival) {
1270                         *val = ch_strdup( keys[i].word.bv_val );
1271                         return 0;
1272                 }
1273         }
1274         return -1;
1275 }
1276
1277 int
1278 bindconf_parse( const char *word, slap_bindconf *bc )
1279 {
1280 #ifdef HAVE_TLS
1281         /* Detect TLS config changes explicitly */
1282         if ( slap_cf_aux_table_parse( word, bc, aux_TLS, "tls config" ) == 0 ) {
1283                 bc->sb_tls_do_init = 1;
1284                 return 0;
1285         }
1286 #endif
1287         return slap_cf_aux_table_parse( word, bc, bindkey, "bind config" );
1288 }
1289
1290 int
1291 bindconf_unparse( slap_bindconf *bc, struct berval *bv )
1292 {
1293         return slap_cf_aux_table_unparse( bc, bv, bindkey );
1294 }
1295
1296 void bindconf_free( slap_bindconf *bc ) {
1297         if ( !BER_BVISNULL( &bc->sb_uri ) ) {
1298                 ch_free( bc->sb_uri.bv_val );
1299                 BER_BVZERO( &bc->sb_uri );
1300         }
1301         if ( !BER_BVISNULL( &bc->sb_binddn ) ) {
1302                 ch_free( bc->sb_binddn.bv_val );
1303                 BER_BVZERO( &bc->sb_binddn );
1304         }
1305         if ( !BER_BVISNULL( &bc->sb_cred ) ) {
1306                 ch_free( bc->sb_cred.bv_val );
1307                 BER_BVZERO( &bc->sb_cred );
1308         }
1309         if ( !BER_BVISNULL( &bc->sb_saslmech ) ) {
1310                 ch_free( bc->sb_saslmech.bv_val );
1311                 BER_BVZERO( &bc->sb_saslmech );
1312         }
1313         if ( bc->sb_secprops ) {
1314                 ch_free( bc->sb_secprops );
1315                 bc->sb_secprops = NULL;
1316         }
1317         if ( !BER_BVISNULL( &bc->sb_realm ) ) {
1318                 ch_free( bc->sb_realm.bv_val );
1319                 BER_BVZERO( &bc->sb_realm );
1320         }
1321         if ( !BER_BVISNULL( &bc->sb_authcId ) ) {
1322                 ch_free( bc->sb_authcId.bv_val );
1323                 BER_BVZERO( &bc->sb_authcId );
1324         }
1325         if ( !BER_BVISNULL( &bc->sb_authzId ) ) {
1326                 ch_free( bc->sb_authzId.bv_val );
1327                 BER_BVZERO( &bc->sb_authzId );
1328         }
1329 #ifdef HAVE_TLS
1330 #if 0
1331         if ( bc->sb_tls_ctx ) {
1332                 SSL_CTX_free( bc->sb_tls_ctx );
1333                 bc->sb_tls_ctx = NULL;
1334         }
1335 #endif
1336         if ( bc->sb_tls_cert ) {
1337                 ch_free( bc->sb_tls_cert );
1338                 bc->sb_tls_cert = NULL;
1339         }
1340         if ( bc->sb_tls_key ) {
1341                 ch_free( bc->sb_tls_key );
1342                 bc->sb_tls_key = NULL;
1343         }
1344         if ( bc->sb_tls_cacert ) {
1345                 ch_free( bc->sb_tls_cacert );
1346                 bc->sb_tls_cacert = NULL;
1347         }
1348         if ( bc->sb_tls_cacertdir ) {
1349                 ch_free( bc->sb_tls_cacertdir );
1350                 bc->sb_tls_cacertdir = NULL;
1351         }
1352         if ( bc->sb_tls_reqcert ) {
1353                 ch_free( bc->sb_tls_reqcert );
1354                 bc->sb_tls_reqcert = NULL;
1355         }
1356         if ( bc->sb_tls_cipher_suite ) {
1357                 ch_free( bc->sb_tls_cipher_suite );
1358                 bc->sb_tls_cipher_suite = NULL;
1359         }
1360 #ifdef HAVE_OPENSSL_CRL
1361         if ( bc->sb_tls_crlcheck ) {
1362                 ch_free( bc->sb_tls_crlcheck );
1363                 bc->sb_tls_crlcheck = NULL;
1364         }
1365 #endif
1366 #endif
1367 }
1368
1369 void
1370 bindconf_tls_defaults( slap_bindconf *bc )
1371 {
1372 #ifdef HAVE_TLS
1373         if ( bc->sb_tls_do_init ) {
1374                 if ( !bc->sb_tls_cacert )
1375                         ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CACERTFILE,
1376                                 &bc->sb_tls_cacert );
1377                 if ( !bc->sb_tls_cacertdir )
1378                         ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CACERTDIR,
1379                                 &bc->sb_tls_cacertdir );
1380                 if ( !bc->sb_tls_cert )
1381                         ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CERTFILE,
1382                                 &bc->sb_tls_cert );
1383                 if ( !bc->sb_tls_key )
1384                         ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_KEYFILE,
1385                                 &bc->sb_tls_key );
1386                 if ( !bc->sb_tls_cipher_suite )
1387                         ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CIPHER_SUITE,
1388                                 &bc->sb_tls_cipher_suite );
1389                 if ( !bc->sb_tls_reqcert )
1390                         bc->sb_tls_reqcert = ch_strdup("demand");
1391 #ifdef HAVE_OPENSSL_CRL
1392                 if ( !bc->sb_tls_crlcheck )
1393                         slap_tls_get_config( slap_tls_ld, LDAP_OPT_X_TLS_CRLCHECK,
1394                                 &bc->sb_tls_crlcheck );
1395 #endif
1396         }
1397 #endif
1398 }
1399
1400 #ifdef HAVE_TLS
1401 static struct {
1402         const char *key;
1403         size_t offset;
1404         int opt;
1405 } bindtlsopts[] = {
1406         { "tls_cert", offsetof(slap_bindconf, sb_tls_cert), LDAP_OPT_X_TLS_CERTFILE },
1407         { "tls_key", offsetof(slap_bindconf, sb_tls_key), LDAP_OPT_X_TLS_KEYFILE },
1408         { "tls_cacert", offsetof(slap_bindconf, sb_tls_cacert), LDAP_OPT_X_TLS_CACERTFILE },
1409         { "tls_cacertdir", offsetof(slap_bindconf, sb_tls_cacertdir), LDAP_OPT_X_TLS_CACERTDIR },
1410         { "tls_cipher_suite", offsetof(slap_bindconf, sb_tls_cipher_suite), LDAP_OPT_X_TLS_CIPHER_SUITE },
1411         {0, 0}
1412 };
1413
1414 int bindconf_tls_set( slap_bindconf *bc, LDAP *ld )
1415 {
1416         int i, rc, newctx = 0, res = 0;
1417         char *ptr = (char *)bc, **word;
1418
1419         bc->sb_tls_do_init = 0;
1420
1421         for (i=0; bindtlsopts[i].opt; i++) {
1422                 word = (char **)(ptr + bindtlsopts[i].offset);
1423                 if ( *word ) {
1424                         rc = ldap_set_option( ld, bindtlsopts[i].opt, *word );
1425                         if ( rc ) {
1426                                 Debug( LDAP_DEBUG_ANY,
1427                                         "bindconf_tls_set: failed to set %s to %s\n",
1428                                                 bindtlsopts[i].key, *word, 0 );
1429                                 res = -1;
1430                         } else
1431                                 newctx = 1;
1432                 }
1433         }
1434         if ( bc->sb_tls_reqcert ) {
1435                 rc = ldap_int_tls_config( ld, LDAP_OPT_X_TLS_REQUIRE_CERT,
1436                         bc->sb_tls_reqcert );
1437                 if ( rc ) {
1438                         Debug( LDAP_DEBUG_ANY,
1439                                 "bindconf_tls_set: failed to set tls_reqcert to %s\n",
1440                                         bc->sb_tls_reqcert, 0, 0 );
1441                         res = -1;
1442                 } else
1443                         newctx = 1;
1444         }
1445 #ifdef HAVE_OPENSSL_CRL
1446         if ( bc->sb_tls_crlcheck ) {
1447                 rc = ldap_int_tls_config( ld, LDAP_OPT_X_TLS_CRLCHECK,
1448                         bc->sb_tls_crlcheck );
1449                 if ( rc ) {
1450                         Debug( LDAP_DEBUG_ANY,
1451                                 "bindconf_tls_set: failed to set tls_crlcheck to %s\n",
1452                                         bc->sb_tls_crlcheck, 0, 0 );
1453                         res = -1;
1454                 } else
1455                         newctx = 1;
1456         }
1457 #endif
1458         if ( newctx ) {
1459                 int opt = 0;
1460
1461                 if ( bc->sb_tls_ctx ) {
1462                         SSL_CTX_free( bc->sb_tls_ctx );
1463                         bc->sb_tls_ctx = NULL;
1464                 }
1465                 rc = ldap_set_option( ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
1466                 if ( rc )
1467                         res = rc;
1468                 else
1469                         ldap_get_option( ld, LDAP_OPT_X_TLS_CTX, &bc->sb_tls_ctx );
1470         }
1471         
1472         return res;
1473 }
1474 #endif
1475
1476 /*
1477  * connect to a client using the bindconf data
1478  * note: should move "version" into bindconf...
1479  */
1480 int
1481 slap_client_connect( LDAP **ldp, slap_bindconf *sb )
1482 {
1483         LDAP            *ld = NULL;
1484         int             rc;
1485
1486         /* Init connection to master */
1487         rc = ldap_initialize( &ld, sb->sb_uri.bv_val );
1488         if ( rc != LDAP_SUCCESS ) {
1489                 Debug( LDAP_DEBUG_ANY,
1490                         "slap_client_connect: "
1491                         "ldap_initialize(%s) failed (%d)\n",
1492                         sb->sb_uri.bv_val, rc, 0 );
1493                 return rc;
1494         }
1495
1496         if ( sb->sb_version != 0 ) {
1497                 ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION,
1498                         (const void *)&sb->sb_version );
1499         }
1500
1501 #ifdef HAVE_TLS
1502         if ( sb->sb_tls_do_init ) {
1503                 rc = bindconf_tls_set( sb, ld );
1504
1505         } else if ( sb->sb_tls_ctx ) {
1506                 rc = ldap_set_option( ld, LDAP_OPT_X_TLS_CTX,
1507                         sb->sb_tls_ctx );
1508         }
1509
1510         if ( rc ) {
1511                 Debug( LDAP_DEBUG_ANY,
1512                         "slap_client_connect: "
1513                         "URI=%s TLS context initialization failed (%d)\n",
1514                         sb->sb_uri.bv_val, rc, 0 );
1515                 return rc;
1516         }
1517 #endif
1518
1519         /* Bind */
1520         if ( sb->sb_tls ) {
1521                 rc = ldap_start_tls_s( ld, NULL, NULL );
1522                 if ( rc != LDAP_SUCCESS ) {
1523                         Debug( LDAP_DEBUG_ANY,
1524                                 "slap_client_connect: URI=%s "
1525                                 "%s, ldap_start_tls failed (%d)\n",
1526                                 sb->sb_uri.bv_val,
1527                                 sb->sb_tls == SB_TLS_CRITICAL ?
1528                                         "Error" : "Warning",
1529                                 rc );
1530                         if ( sb->sb_tls == SB_TLS_CRITICAL ) {
1531                                 goto done;
1532                         }
1533                 }
1534         }
1535
1536         if ( sb->sb_method == LDAP_AUTH_SASL ) {
1537 #ifdef HAVE_CYRUS_SASL
1538                 void *defaults;
1539
1540                 if ( sb->sb_secprops != NULL ) {
1541                         rc = ldap_set_option( ld,
1542                                 LDAP_OPT_X_SASL_SECPROPS, sb->sb_secprops);
1543
1544                         if( rc != LDAP_OPT_SUCCESS ) {
1545                                 Debug( LDAP_DEBUG_ANY,
1546                                         "slap_client_connect: "
1547                                         "error, ldap_set_option "
1548                                         "(%s,SECPROPS,\"%s\") failed!\n",
1549                                         sb->sb_uri.bv_val, sb->sb_secprops, 0 );
1550                                 goto done;
1551                         }
1552                 }
1553
1554                 defaults = lutil_sasl_defaults( ld,
1555                         sb->sb_saslmech.bv_val,
1556                         sb->sb_realm.bv_val,
1557                         sb->sb_authcId.bv_val,
1558                         sb->sb_cred.bv_val,
1559                         sb->sb_authzId.bv_val );
1560
1561                 rc = ldap_sasl_interactive_bind_s( ld,
1562                                 sb->sb_binddn.bv_val,
1563                                 sb->sb_saslmech.bv_val,
1564                                 NULL, NULL,
1565                                 LDAP_SASL_QUIET,
1566                                 lutil_sasl_interact,
1567                                 defaults );
1568
1569                 lutil_sasl_freedefs( defaults );
1570
1571                 /* FIXME: different error behaviors according to
1572                  *      1) return code
1573                  *      2) on err policy : exit, retry, backoff ...
1574                  */
1575                 if ( rc != LDAP_SUCCESS ) {
1576                         static struct berval bv_GSSAPI = BER_BVC( "GSSAPI" );
1577
1578                         Debug( LDAP_DEBUG_ANY, "slap_client_connect: URI=%s "
1579                                 "ldap_sasl_interactive_bind_s failed (%d)\n",
1580                                 sb->sb_uri.bv_val, rc, 0 );
1581
1582                         /* FIXME (see above comment) */
1583                         /* if Kerberos credentials cache is not active, retry */
1584                         if ( ber_bvcmp( &sb->sb_saslmech, &bv_GSSAPI ) == 0 &&
1585                                 rc == LDAP_LOCAL_ERROR )
1586                         {
1587                                 rc = LDAP_SERVER_DOWN;
1588                         }
1589
1590                         goto done;
1591                 }
1592 #else /* HAVE_CYRUS_SASL */
1593                 /* Should never get here, we trapped this at config time */
1594                 assert(0);
1595                 Debug( LDAP_DEBUG_SYNC, "not compiled with SASL support\n", 0, 0, 0 );
1596                 rc = LDAP_OTHER;
1597                 goto done;
1598 #endif
1599
1600         } else if ( sb->sb_method == LDAP_AUTH_SIMPLE ) {
1601                 rc = ldap_sasl_bind_s( ld,
1602                         sb->sb_binddn.bv_val, LDAP_SASL_SIMPLE,
1603                         &sb->sb_cred, NULL, NULL, NULL );
1604                 if ( rc != LDAP_SUCCESS ) {
1605                         Debug( LDAP_DEBUG_ANY, "slap_client_connect: "
1606                                 "URI=%s DN=\"%s\" "
1607                                 "ldap_sasl_bind_s failed (%d)\n",
1608                                 sb->sb_uri.bv_val, sb->sb_binddn.bv_val, rc );
1609                         goto done;
1610                 }
1611         }
1612
1613 done:;
1614         if ( rc ) {
1615                 if ( ld ) {
1616                         ldap_unbind_ext( ld, NULL, NULL );
1617                         *ldp = NULL;
1618                 }
1619
1620         } else {
1621                 *ldp = ld;
1622         }
1623
1624         return rc;
1625 }
1626
1627 /* -------------------------------------- */
1628
1629
1630 static char *
1631 strtok_quote( char *line, char *sep, char **quote_ptr )
1632 {
1633         int             inquote;
1634         char            *tmp;
1635         static char     *next;
1636
1637         *quote_ptr = NULL;
1638         if ( line != NULL ) {
1639                 next = line;
1640         }
1641         while ( *next && strchr( sep, *next ) ) {
1642                 next++;
1643         }
1644
1645         if ( *next == '\0' ) {
1646                 next = NULL;
1647                 return( NULL );
1648         }
1649         tmp = next;
1650
1651         for ( inquote = 0; *next; ) {
1652                 switch ( *next ) {
1653                 case '"':
1654                         if ( inquote ) {
1655                                 inquote = 0;
1656                         } else {
1657                                 inquote = 1;
1658                         }
1659                         AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
1660                         break;
1661
1662                 case '\\':
1663                         if ( next[1] )
1664                                 AC_MEMCPY( next,
1665                                             next + 1, strlen( next + 1 ) + 1 );
1666                         next++;         /* dont parse the escaped character */
1667                         break;
1668
1669                 default:
1670                         if ( ! inquote ) {
1671                                 if ( strchr( sep, *next ) != NULL ) {
1672                                         *quote_ptr = next;
1673                                         *next++ = '\0';
1674                                         return( tmp );
1675                                 }
1676                         }
1677                         next++;
1678                         break;
1679                 }
1680         }
1681
1682         return( tmp );
1683 }
1684
1685 static char     buf[AC_LINE_MAX];
1686 static char     *line;
1687 static size_t lmax, lcur;
1688
1689 #define CATLINE( buf ) \
1690         do { \
1691                 size_t len = strlen( buf ); \
1692                 while ( lcur + len + 1 > lmax ) { \
1693                         lmax += AC_LINE_MAX; \
1694                         line = (char *) ch_realloc( line, lmax ); \
1695                 } \
1696                 strcpy( line + lcur, buf ); \
1697                 lcur += len; \
1698         } while( 0 )
1699
1700 static void
1701 fp_getline_init(ConfigArgs *c) {
1702         c->lineno = -1;
1703         buf[0] = '\0';
1704 }
1705
1706 static int
1707 fp_getline( FILE *fp, ConfigArgs *c )
1708 {
1709         char    *p;
1710
1711         lcur = 0;
1712         CATLINE(buf);
1713         c->lineno++;
1714
1715         /* avoid stack of bufs */
1716         if ( strncasecmp( line, "include", STRLENOF( "include" ) ) == 0 ) {
1717                 buf[0] = '\0';
1718                 c->line = line;
1719                 return(1);
1720         }
1721
1722         while ( fgets( buf, sizeof( buf ), fp ) ) {
1723                 p = strchr( buf, '\n' );
1724                 if ( p ) {
1725                         if ( p > buf && p[-1] == '\r' ) {
1726                                 --p;
1727                         }
1728                         *p = '\0';
1729                 }
1730                 /* XXX ugly */
1731                 c->line = line;
1732                 if ( line[0]
1733                                 && ( p = line + strlen( line ) - 1 )[0] == '\\'
1734                                 && p[-1] != '\\' )
1735                 {
1736                         p[0] = '\0';
1737                         lcur--;
1738                         
1739                 } else {
1740                         if ( !isspace( (unsigned char)buf[0] ) ) {
1741                                 return(1);
1742                         }
1743                         buf[0] = ' ';
1744                 }
1745                 CATLINE(buf);
1746                 c->lineno++;
1747         }
1748
1749         buf[0] = '\0';
1750         c->line = line;
1751         return(line[0] ? 1 : 0);
1752 }
1753
1754 static int
1755 fp_parse_line(ConfigArgs *c)
1756 {
1757         char *token;
1758         static char *const hide[] = {
1759                 "rootpw", "replica", "syncrepl",  /* in slapd */
1760                 "acl-bind", "acl-method", "idassert-bind",  /* in back-ldap */
1761                 "acl-passwd", "bindpw",  /* in back-<ldap/meta> */
1762                 "pseudorootpw",  /* in back-meta */
1763                 "dbpasswd",  /* in back-sql */
1764                 NULL
1765         };
1766         char *quote_ptr;
1767         int i = (int)(sizeof(hide)/sizeof(hide[0])) - 1;
1768
1769         c->tline = ch_strdup(c->line);
1770         token = strtok_quote(c->tline, " \t", &quote_ptr);
1771
1772         if(token) for(i = 0; hide[i]; i++) if(!strcasecmp(token, hide[i])) break;
1773         if(quote_ptr) *quote_ptr = ' ';
1774         Debug(LDAP_DEBUG_CONFIG, "line %d (%s%s)\n", c->lineno,
1775                 hide[i] ? hide[i] : c->line, hide[i] ? " ***" : "");
1776         if(quote_ptr) *quote_ptr = '\0';
1777
1778         for(;; token = strtok_quote(NULL, " \t", &quote_ptr)) {
1779                 if(c->argc >= c->argv_size) {
1780                         char **tmp;
1781                         tmp = ch_realloc(c->argv, (c->argv_size + ARGS_STEP) * sizeof(*c->argv));
1782                         if(!tmp) {
1783                                 Debug(LDAP_DEBUG_ANY, "line %d: out of memory\n", c->lineno, 0, 0);
1784                                 return -1;
1785                         }
1786                         c->argv = tmp;
1787                         c->argv_size += ARGS_STEP;
1788                 }
1789                 if(token == NULL)
1790                         break;
1791                 c->argv[c->argc++] = token;
1792         }
1793         c->argv[c->argc] = NULL;
1794         return(0);
1795 }
1796
1797 void
1798 config_destroy( )
1799 {
1800         ucdata_unload( UCDATA_ALL );
1801         if ( frontendDB ) {
1802                 /* NOTE: in case of early exit, frontendDB can be NULL */
1803                 if ( frontendDB->be_schemandn.bv_val )
1804                         free( frontendDB->be_schemandn.bv_val );
1805                 if ( frontendDB->be_schemadn.bv_val )
1806                         free( frontendDB->be_schemadn.bv_val );
1807                 if ( frontendDB->be_acl )
1808                         acl_destroy( frontendDB->be_acl, NULL );
1809         }
1810         free( line );
1811         if ( slapd_args_file )
1812                 free ( slapd_args_file );
1813         if ( slapd_pid_file )
1814                 free ( slapd_pid_file );
1815         if ( default_passwd_hash )
1816                 ldap_charray_free( default_passwd_hash );
1817 }
1818
1819 char **
1820 slap_str2clist( char ***out, char *in, const char *brkstr )
1821 {
1822         char    *str;
1823         char    *s;
1824         char    *lasts;
1825         int     i, j;
1826         char    **new;
1827
1828         /* find last element in list */
1829         for (i = 0; *out && (*out)[i]; i++);
1830
1831         /* protect the input string from strtok */
1832         str = ch_strdup( in );
1833
1834         if ( *str == '\0' ) {
1835                 free( str );
1836                 return( *out );
1837         }
1838
1839         /* Count words in string */
1840         j=1;
1841         for ( s = str; *s; s++ ) {
1842                 if ( strchr( brkstr, *s ) != NULL ) {
1843                         j++;
1844                 }
1845         }
1846
1847         *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
1848         new = *out + i;
1849         for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
1850                 s != NULL;
1851                 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
1852         {
1853                 *new = ch_strdup( s );
1854                 new++;
1855         }
1856
1857         *new = NULL;
1858         free( str );
1859         return( *out );
1860 }
1861
1862 int config_generic_wrapper( Backend *be, const char *fname, int lineno,
1863         int argc, char **argv )
1864 {
1865         ConfigArgs c = { 0 };
1866         ConfigTable *ct;
1867         int rc;
1868
1869         c.be = be;
1870         c.fname = fname;
1871         c.lineno = lineno;
1872         c.argc = argc;
1873         c.argv = argv;
1874         c.valx = -1;
1875         c.line = line;
1876         c.op = SLAP_CONFIG_ADD;
1877         snprintf( c.log, sizeof( c.log ), "%s: line %d", fname, lineno );
1878
1879         rc = SLAP_CONF_UNKNOWN;
1880         ct = config_find_keyword( be->be_cf_ocs->co_table, &c );
1881         if ( ct )
1882                 rc = config_add_vals( ct, &c );
1883         return rc;
1884 }