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