]> git.sur5r.net Git - openldap/blob - servers/slapd/config.c
Sync with HEAD
[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-2005 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 #include <unistd.h>
40
41 #include "slap.h"
42 #ifdef LDAP_SLAPI
43 #include "slapi/slapi.h"
44 #endif
45 #include "lutil.h"
46 #include "config.h"
47
48 #define ARGS_STEP       512
49
50 /*
51  * defaults for various global variables
52  */
53 slap_mask_t             global_allows = 0;
54 slap_mask_t             global_disallows = 0;
55 int             global_gentlehup = 0;
56 int             global_idletimeout = 0;
57 char    *global_host = NULL;
58 char    *global_realm = NULL;
59 char            *ldap_srvtab = "";
60 char            **default_passwd_hash = NULL;
61 struct berval default_search_base = BER_BVNULL;
62 struct berval default_search_nbase = BER_BVNULL;
63
64 ber_len_t sockbuf_max_incoming = SLAP_SB_MAX_INCOMING_DEFAULT;
65 ber_len_t sockbuf_max_incoming_auth= SLAP_SB_MAX_INCOMING_AUTH;
66
67 int     slap_conn_max_pending = SLAP_CONN_MAX_PENDING_DEFAULT;
68 int     slap_conn_max_pending_auth = SLAP_CONN_MAX_PENDING_AUTH;
69
70 char   *slapd_pid_file  = NULL;
71 char   *slapd_args_file = NULL;
72
73 int use_reverse_lookup = 0;
74
75 #ifdef LDAP_SLAPI
76 int slapi_plugins_used = 0;
77 #endif
78
79 static int fp_getline(FILE *fp, ConfigArgs *c);
80 static void fp_getline_init(ConfigArgs *c);
81 static int fp_parse_line(ConfigArgs *c);
82
83 static char     *strtok_quote(char *line, char *sep, char **quote_ptr);
84
85 ConfigArgs *
86 new_config_args( BackendDB *be, const char *fname, int lineno, int argc, char **argv )
87 {
88         ConfigArgs *c;
89         c = ch_calloc( 1, sizeof( ConfigArgs ) );
90         if ( c == NULL ) return(NULL);
91         c->be     = be; 
92         c->fname  = fname;
93         c->argc   = argc;
94         c->argv   = argv; 
95         c->lineno = lineno;
96         snprintf( c->log, sizeof( c->log ), "%s: line %d", fname, lineno );
97         return(c);
98 }
99
100 void
101 init_config_argv( ConfigArgs *c )
102 {
103         c->argv = ch_calloc( ARGS_STEP + 1, sizeof( *c->argv ) );
104         c->argv_size = ARGS_STEP + 1;
105 }
106
107 ConfigTable *config_find_keyword(ConfigTable *Conf, ConfigArgs *c) {
108         int i;
109
110         for(i = 0; Conf[i].name; i++)
111                 if( (Conf[i].length && (!strncasecmp(c->argv[0], Conf[i].name, Conf[i].length))) ||
112                         (!strcasecmp(c->argv[0], Conf[i].name)) ) break;
113         if ( !Conf[i].name ) return NULL;
114         return Conf+i;
115 }
116
117 int config_check_vals(ConfigTable *Conf, ConfigArgs *c, int check_only ) {
118         int rc, arg_user, arg_type, iarg;
119         long larg;
120         ber_len_t barg;
121         
122         arg_type = Conf->arg_type;
123         if(arg_type == ARG_IGNORED) {
124                 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> ignored\n",
125                         c->log, Conf->name, 0);
126                 return(0);
127         }
128         if((arg_type & ARG_DN) && c->argc == 1) {
129                 c->argc = 2;
130                 c->argv[1] = "";
131         }
132         if(Conf->min_args && (c->argc < Conf->min_args)) {
133                 sprintf( c->msg, "<%s> missing <%s> argument",
134                         c->argv[0], Conf->what );
135                 Debug(LDAP_DEBUG_CONFIG, "%s: keyword %s\n", c->log, c->msg, 0 );
136                 return(ARG_BAD_CONF);
137         }
138         if(Conf->max_args && (c->argc > Conf->max_args)) {
139                 char    *ignored = " ignored";
140
141                 sprintf( c->msg, "<%s> extra cruft after <%s>",
142                         c->argv[0], Conf->what );
143
144 #ifdef LDAP_DEVEL
145                 ignored = "";
146 #endif /* LDAP_DEVEL */
147                 Debug(LDAP_DEBUG_CONFIG, "%s: %s%s.\n",
148                                 c->log, c->msg, ignored );
149 #ifdef LDAP_DEVEL
150                 return(ARG_BAD_CONF);
151 #endif /* LDAP_DEVEL */
152         }
153         if((arg_type & ARG_DB) && !c->be) {
154                 sprintf( c->msg, "<%s> only allowed within database declaration",
155                         c->argv[0] );
156                 Debug(LDAP_DEBUG_CONFIG, "%s: keyword %s\n",
157                         c->log, c->msg, 0);
158                 return(ARG_BAD_CONF);
159         }
160         if((arg_type & ARG_PRE_BI) && c->bi) {
161                 sprintf( c->msg, "<%s> must occur before any backend %sdeclaration",
162                         c->argv[0], (arg_type & ARG_PRE_DB) ? "or database " : "" );
163                 Debug(LDAP_DEBUG_CONFIG, "%s: keyword %s\n",
164                         c->log, c->msg, 0 );
165                 return(ARG_BAD_CONF);
166         }
167         if((arg_type & ARG_PRE_DB) && c->be && c->be != frontendDB) {
168                 sprintf( c->msg, "<%s> must occur before any database declaration",
169                         c->argv[0] );
170                 Debug(LDAP_DEBUG_CONFIG, "%s: keyword %s\n",
171                         c->log, c->msg, 0);
172                 return(ARG_BAD_CONF);
173         }
174         if((arg_type & ARG_PAREN) && *c->argv[1] != '(' /*')'*/) {
175                 sprintf( c->msg, "<%s> old format not supported", c->argv[0] );
176                 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
177                         c->log, c->msg, 0);
178                 return(ARG_BAD_CONF);
179         }
180         if((arg_type & ARGS_POINTER) && !Conf->arg_item && !(arg_type & ARG_OFFSET)) {
181                 sprintf( c->msg, "<%s> invalid config_table, arg_item is NULL",
182                         c->argv[0] );
183                 Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
184                         c->log, c->msg, 0);
185                 return(ARG_BAD_CONF);
186         }
187         c->type = arg_user = (arg_type & ARGS_USERLAND);
188         memset(&c->values, 0, sizeof(c->values));
189         if(arg_type & ARGS_NUMERIC) {
190                 int j;
191                 iarg = 0; larg = 0; barg = 0;
192                 switch(arg_type & ARGS_NUMERIC) {
193                         case ARG_INT:           iarg = atoi(c->argv[1]);                break;
194                         case ARG_LONG:          larg = strtol(c->argv[1], NULL, 0);     break;
195                         case ARG_BER_LEN_T:     barg = (ber_len_t)atol(c->argv[1]);     break;
196                         case ARG_ON_OFF:
197                                 if(c->argc == 1) {
198                                         iarg = 1;
199                                 } else if(!strcasecmp(c->argv[1], "on") ||
200                                         !strcasecmp(c->argv[1], "true")) {
201                                         iarg = 1;
202                                 } else if(!strcasecmp(c->argv[1], "off") ||
203                                         !strcasecmp(c->argv[1], "false")) {
204                                         iarg = 0;
205                                 } else {
206                                         sprintf( c->msg, "<%s> invalid value, ignored",
207                                                 c->argv[0] );
208                                         Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
209                                                 c->log, c->msg, 0 );
210                                         return(0);
211                                 }
212                                 break;
213                 }
214                 j = (arg_type & ARG_NONZERO) ? 1 : 0;
215                 if(iarg < j && larg < j && barg < j ) {
216                         larg = larg ? larg : (barg ? barg : iarg);
217                         sprintf( c->msg, "<%s> invalid value, ignored",
218                                 c->argv[0] );
219                         Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
220                                 c->log, c->msg, 0 );
221                         return(ARG_BAD_CONF);
222                 }
223                 switch(arg_type & ARGS_NUMERIC) {
224                         case ARG_ON_OFF:
225                         case ARG_INT:           c->value_int = iarg;            break;
226                         case ARG_LONG:          c->value_long = larg;           break;
227                         case ARG_BER_LEN_T:     c->value_ber_t = barg;          break;
228                 }
229         } else if(arg_type & ARG_STRING) {
230                 if ( !check_only )
231                         c->value_string = ch_strdup(c->argv[1]);
232         } else if(arg_type & ARG_BERVAL) {
233                 if ( !check_only )
234                         ber_str2bv( c->argv[1], 0, 1, &c->value_bv );
235         } else if(arg_type & ARG_DN) {
236                 struct berval bv;
237                 ber_str2bv( c->argv[1], 0, 0, &bv );
238                 rc = dnPrettyNormal( NULL, &bv, &c->value_dn, &c->value_ndn, NULL );
239                 if ( rc != LDAP_SUCCESS ) {
240                         sprintf( c->msg, "<%s> invalid DN %d (%s)",
241                                 c->argv[0], rc, ldap_err2string( rc ));
242                         Debug(LDAP_DEBUG_CONFIG, "%s: %s\n" , c->log, c->msg, 0);
243                         return(ARG_BAD_CONF);
244                 }
245                 if ( check_only ) {
246                         ch_free( c->value_ndn.bv_val );
247                         ch_free( c->value_dn.bv_val );
248                 }
249         }
250         return 0;
251 }
252
253 int config_set_vals(ConfigTable *Conf, ConfigArgs *c) {
254         int rc, arg_type;
255         void *ptr = NULL;
256
257         arg_type = Conf->arg_type;
258         if(arg_type & ARG_MAGIC) {
259                 if(!c->be) c->be = frontendDB;
260                 c->msg[0] = '\0';
261                 rc = (*((ConfigDriver*)Conf->arg_item))(c);
262 #if 0
263                 if(c->be == frontendDB) c->be = NULL;
264 #endif
265                 if(rc) {
266                         if ( !c->msg[0] ) {
267                                 sprintf( c->msg, "<%s> handler exited with %d",
268                                         c->argv[0], rc );
269                                 Debug(LDAP_DEBUG_CONFIG, "%s: %s!\n",
270                                         c->log, c->msg, 0 );
271                         }
272                         return(ARG_BAD_CONF);
273                 }
274                 return(0);
275         }
276         if(arg_type & ARG_OFFSET) {
277                 if (c->be)
278                         ptr = c->be->be_private;
279                 else if (c->bi)
280                         ptr = c->bi->bi_private;
281                 else {
282                         sprintf( c->msg, "<%s> offset is missing base pointer",
283                                 c->argv[0] );
284                         Debug(LDAP_DEBUG_CONFIG, "%s: %s!\n",
285                                 c->log, c->msg, 0);
286                         return(ARG_BAD_CONF);
287                 }
288                 ptr = (void *)((char *)ptr + (int)Conf->arg_item);
289         } else if (arg_type & ARGS_POINTER) {
290                 ptr = Conf->arg_item;
291         }
292         if(arg_type & ARGS_POINTER)
293                 switch(arg_type & ARGS_POINTER) {
294                         case ARG_ON_OFF:
295                         case ARG_INT:           *(int*)ptr = c->value_int;                      break;
296                         case ARG_LONG:          *(long*)ptr = c->value_long;                    break;
297                         case ARG_BER_LEN_T:     *(ber_len_t*)ptr = c->value_ber_t;                      break;
298                         case ARG_STRING: {
299                                 char *cc = *(char**)ptr;
300                                 if(cc) {
301                                         if ((arg_type & ARG_UNIQUE) && c->op == SLAP_CONFIG_ADD ) {
302                                                 Debug(LDAP_DEBUG_CONFIG, "%s: already set %s!\n",
303                                                         c->log, Conf->name, 0 );
304                                                 return(ARG_BAD_CONF);
305                                         }
306                                         ch_free(cc);
307                                 }
308                                 *(char **)ptr = c->value_string;
309                                 break;
310                                 }
311                         case ARG_BERVAL:
312                                 *(struct berval *)ptr = c->value_bv;
313                                 break;
314                 }
315         return(0);
316 }
317
318 int config_add_vals(ConfigTable *Conf, ConfigArgs *c) {
319         int rc, arg_type;
320
321         arg_type = Conf->arg_type;
322         if(arg_type == ARG_IGNORED) {
323                 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> ignored\n",
324                         c->log, Conf->name, 0);
325                 return(0);
326         }
327         rc = config_check_vals( Conf, c, 0 );
328         if ( rc ) return rc;
329         return config_set_vals( Conf, c );
330 }
331
332 int
333 config_del_vals(ConfigTable *cf, ConfigArgs *c)
334 {
335         int rc = 0;
336
337         /* If there is no handler, just ignore it */
338         if ( cf->arg_type & ARG_MAGIC ) {
339                 c->op = LDAP_MOD_DELETE;
340                 c->type = cf->arg_type & ARGS_USERLAND;
341                 rc = (*((ConfigDriver*)cf->arg_item))(c);
342         }
343         return rc;
344 }
345
346 int
347 config_get_vals(ConfigTable *cf, ConfigArgs *c)
348 {
349         int rc = 0;
350         struct berval bv;
351         void *ptr;
352
353         if ( cf->arg_type & ARG_IGNORED ) {
354                 return 1;
355         }
356
357         memset(&c->values, 0, sizeof(c->values));
358         c->rvalue_vals = NULL;
359         c->rvalue_nvals = NULL;
360         c->op = SLAP_CONFIG_EMIT;
361         c->type = cf->arg_type & ARGS_USERLAND;
362
363         if ( cf->arg_type & ARG_MAGIC ) {
364                 rc = (*((ConfigDriver*)cf->arg_item))(c);
365                 if ( rc ) return rc;
366         } else {
367                 if ( cf->arg_type & ARG_OFFSET ) {
368                         if ( c->be )
369                                 ptr = c->be->be_private;
370                         else if ( c->bi )
371                                 ptr = c->bi->bi_private;
372                         else
373                                 return 1;
374                         ptr = (void *)((char *)ptr + (int)cf->arg_item);
375                 } else {
376                         ptr = cf->arg_item;
377                 }
378                 
379                 switch(cf->arg_type & ARGS_POINTER) {
380                 case ARG_ON_OFF:
381                 case ARG_INT:   c->value_int = *(int *)ptr; break;
382                 case ARG_LONG:  c->value_long = *(long *)ptr; break;
383                 case ARG_BER_LEN_T:     c->value_ber_t = *(ber_len_t *)ptr; break;
384                 case ARG_STRING:
385                         if ( *(char **)ptr )
386                                 c->value_string = ch_strdup(*(char **)ptr);
387                         break;
388                 case ARG_BERVAL:
389                         ber_dupbv( &c->value_bv, (struct berval *)ptr ); break;
390                 }
391         }
392         if ( cf->arg_type & ARGS_POINTER) {
393                 bv.bv_val = c->log;
394                 switch(cf->arg_type & ARGS_POINTER) {
395                 case ARG_INT: bv.bv_len = sprintf(bv.bv_val, "%d", c->value_int); break;
396                 case ARG_LONG: bv.bv_len = sprintf(bv.bv_val, "%ld", c->value_long); break;
397                 case ARG_BER_LEN_T: bv.bv_len = sprintf(bv.bv_val, "%ld", c->value_ber_t); break;
398                 case ARG_ON_OFF: bv.bv_len = sprintf(bv.bv_val, "%s",
399                         c->value_int ? "TRUE" : "FALSE"); break;
400                 case ARG_STRING:
401                         if ( c->value_string && c->value_string[0]) {
402                                 ber_str2bv( c->value_string, 0, 0, &bv);
403                         } else {
404                                 return 1;
405                         }
406                         break;
407                 case ARG_BERVAL:
408                         if ( !BER_BVISEMPTY( &c->value_bv )) {
409                                 bv = c->value_bv;
410                         } else {
411                                 return 1;
412                         }
413                         break;
414                 }
415                 if (( cf->arg_type & ARGS_POINTER ) == ARG_STRING )
416                         ber_bvarray_add(&c->rvalue_vals, &bv);
417                 else
418                         value_add_one(&c->rvalue_vals, &bv);
419         }
420         return rc;
421 }
422
423 int
424 init_config_attrs(ConfigTable *ct) {
425         LDAPAttributeType *at;
426         int i, code;
427         const char *err;
428
429         for (i=0; ct[i].name; i++ ) {
430                 int             freeit = 0;
431
432                 if ( !ct[i].attribute ) continue;
433                 at = ldap_str2attributetype( ct[i].attribute,
434                         &code, &err, LDAP_SCHEMA_ALLOW_ALL );
435                 if ( !at ) {
436                         fprintf( stderr, "init_config_attrs: AttributeType \"%s\": %s, %s\n",
437                                 ct[i].attribute, ldap_scherr2str(code), err );
438                         return code;
439                 }
440
441                 code = at_add( at, 0, NULL, &err );
442                 if ( code ) {
443                         if ( code == SLAP_SCHERR_ATTR_DUP ) {
444                                 freeit = 1;
445
446                         } else {
447                                 fprintf( stderr, "init_config_attrs: AttributeType \"%s\": %s, %s\n",
448                                         ct[i].attribute, scherr2str(code), err );
449                                 return code;
450                         }
451                 }
452                 code = slap_str2ad( at->at_names[0], &ct[i].ad, &err );
453                 if ( freeit ) {
454                         ldap_attributetype_free( at );
455                 } else {
456                         ldap_memfree( at );
457                 }
458                 if ( code ) {
459                         fprintf( stderr, "init_config_attrs: AttributeType \"%s\": %s\n",
460                                 ct[i].attribute, err );
461                         return code;
462                 }
463         }
464
465         return 0;
466 }
467
468 int
469 init_config_ocs( ConfigOCs *ocs ) {
470         int i;
471
472         for (i=0;ocs[i].co_def;i++) {
473                 LDAPObjectClass *oc;
474                 int code;
475                 const char *err;
476
477                 oc = ldap_str2objectclass( ocs[i].co_def, &code, &err,
478                         LDAP_SCHEMA_ALLOW_ALL );
479                 if ( !oc ) {
480                         fprintf( stderr, "init_config_ocs: objectclass \"%s\": %s, %s\n",
481                                 ocs[i].co_def, ldap_scherr2str(code), err );
482                         return code;
483                 }
484                 code = oc_add(oc,0,NULL,&err);
485                 if ( code && code != SLAP_SCHERR_CLASS_DUP ) {
486                         fprintf( stderr, "init_config_ocs: objectclass \"%s\": %s, %s\n",
487                                 ocs[i].co_def, scherr2str(code), err );
488                         return code;
489                 }
490                 ocs[i].co_oc = oc_find(oc->oc_names[0]);
491                 ldap_memfree(oc);
492         }
493         return 0;
494 }
495
496 int
497 config_parse_vals(ConfigTable *ct, ConfigArgs *c, int valx)
498 {
499         int     rc = 0;
500         char    *saveline = NULL;
501
502         snprintf( c->log, sizeof( c->log ), "%s: value #%d",
503                 ct->ad->ad_cname.bv_val, valx );
504         c->argc = 1;
505         c->argv[0] = ct->ad->ad_cname.bv_val;
506
507         if ( ( ct->arg_type & ARG_QUOTE ) && c->line[ 0 ] != '"' ) {
508                 ber_len_t       len;
509
510                 saveline = c->line;
511                 len = strlen( c->line );
512                 c->line = ch_malloc( len + STRLENOF( "\"\"" ) + 1 );
513                 sprintf( c->line, "\"%s\"", saveline );
514         }
515
516         if ( fp_parse_line( c ) ) {
517                 rc = 1;
518         } else {
519                 rc = config_check_vals( ct, c, 1 );
520         }
521
522         if ( saveline ) {
523                 ch_free( c->line );
524                 c->line = saveline;
525         }
526
527         if ( rc )
528                 rc = LDAP_CONSTRAINT_VIOLATION;
529
530         ch_free( c->tline );
531         return rc;
532 }
533
534 int
535 config_parse_add(ConfigTable *ct, ConfigArgs *c)
536 {
537         int     rc = 0;
538         char    *saveline = NULL;
539
540         snprintf( c->log, sizeof( c->log ), "%s: value #%d",
541                 ct->ad->ad_cname.bv_val, c->valx );
542         c->argc = 1;
543         c->argv[0] = ct->ad->ad_cname.bv_val;
544
545         if ( ( ct->arg_type & ARG_QUOTE ) && c->line[ 0 ] != '"' ) {
546                 ber_len_t       len;
547
548                 saveline = c->line;
549                 len = strlen( c->line );
550                         
551                 c->line = ch_malloc( len + STRLENOF( "\"\"" ) + 1 );
552                 sprintf( c->line, "\"%s\"", saveline );
553         }
554
555         if ( fp_parse_line( c ) ) {
556                 rc = 1;
557         } else {
558                 c->op = LDAP_MOD_ADD;
559                 rc = config_add_vals( ct, c );
560         }
561
562         if ( saveline ) {
563                 ch_free( c->line );
564                 c->line = saveline;
565         }
566
567         ch_free( c->tline );
568         return rc;
569 }
570
571 int
572 read_config_file(const char *fname, int depth, ConfigArgs *cf, ConfigTable *cft)
573 {
574         FILE *fp;
575         ConfigTable *ct;
576         ConfigArgs *c;
577         int rc;
578         struct stat s;
579
580         c = ch_calloc( 1, sizeof( ConfigArgs ) );
581         if ( c == NULL ) {
582                 return 1;
583         }
584
585         if ( depth ) {
586                 memcpy( c, cf, sizeof( ConfigArgs ) );
587         } else {
588                 c->depth = depth; /* XXX */
589                 c->bi = NULL;
590                 c->be = NULL;
591         }
592
593         c->valx = -1;
594         c->fname = fname;
595         init_config_argv( c );
596
597         if ( stat( fname, &s ) != 0 ) {
598                 ldap_syslog = 1;
599                 Debug(LDAP_DEBUG_ANY,
600                     "could not stat config file \"%s\": %s (%d)\n",
601                     fname, strerror(errno), errno);
602                 return(1);
603         }
604
605         if ( !S_ISREG( s.st_mode ) ) {
606                 ldap_syslog = 1;
607                 Debug(LDAP_DEBUG_ANY,
608                     "regular file expected, got \"%s\"\n",
609                     fname, 0, 0 );
610                 return(1);
611         }
612
613         fp = fopen( fname, "r" );
614         if ( fp == NULL ) {
615                 ldap_syslog = 1;
616                 Debug(LDAP_DEBUG_ANY,
617                     "could not open config file \"%s\": %s (%d)\n",
618                     fname, strerror(errno), errno);
619                 return(1);
620         }
621
622         Debug(LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0);
623
624         fp_getline_init(c);
625
626         c->tline = NULL;
627
628         while ( fp_getline( fp, c ) ) {
629                 /* skip comments and blank lines */
630                 if ( c->line[0] == '#' || c->line[0] == '\0' ) {
631                         continue;
632                 }
633
634                 snprintf( c->log, sizeof( c->log ), "%s: line %d",
635                                 c->fname, c->lineno );
636
637                 c->argc = 0;
638                 ch_free( c->tline );
639                 if ( fp_parse_line( c ) ) {
640                         rc = 1;
641                         goto leave;
642                 }
643
644                 if ( c->argc < 1 ) {
645                         Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: bad config line" 
646                                 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
647                                 c->log, 0, 0);
648 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
649                         rc = 1;
650                         goto leave;
651 #else /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
652                         continue;
653 #endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
654                 }
655
656                 c->op = SLAP_CONFIG_ADD;
657
658                 ct = config_find_keyword( cft, c );
659                 if ( ct ) {
660                         rc = config_add_vals( ct, c );
661                         if ( !rc ) continue;
662
663                         if ( rc & ARGS_USERLAND ) {
664                                 /* XXX a usertype would be opaque here */
665                                 Debug(LDAP_DEBUG_CONFIG, "%s: unknown user type <%s>\n",
666                                         c->log, c->argv[0], 0);
667                                 rc = 1;
668                                 goto leave;
669
670                         } else if ( rc == ARG_BAD_CONF ) {
671                                 rc = 1;
672                                 goto leave;
673                         }
674                         
675                 } else if ( c->bi && !c->be ) {
676                         rc = SLAP_CONF_UNKNOWN;
677                         if ( c->bi->bi_cf_ocs ) {
678                                 ct = config_find_keyword( c->bi->bi_cf_ocs->co_table, c );
679                                 if ( ct ) {
680                                         rc = config_add_vals( ct, c );
681                                 }
682                         }
683                         if ( c->bi->bi_config && rc == SLAP_CONF_UNKNOWN ) {
684                                 rc = (*c->bi->bi_config)(c->bi, c->fname, c->lineno,
685                                         c->argc, c->argv);
686                         }
687                         if ( rc ) {
688                                 switch(rc) {
689                                 case SLAP_CONF_UNKNOWN:
690                                         Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
691                                                 "unknown directive <%s> inside backend info definition"
692                                                 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
693                                                 c->log, *c->argv, 0);
694 #ifndef SLAPD_CONF_UNKNOWN_BAILOUT
695                                         continue;
696 #endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
697                                 default:
698                                         rc = 1;
699                                         goto leave;
700                                 }
701                         }
702
703                 } else if ( c->be ) {
704                         rc = SLAP_CONF_UNKNOWN;
705                         if ( c->be->be_cf_ocs ) {
706                                 ct = config_find_keyword( c->be->be_cf_ocs->co_table, c );
707                                 if ( ct ) {
708                                         rc = config_add_vals( ct, c );
709                                 }
710                         }
711                         if ( c->be->be_config && rc == SLAP_CONF_UNKNOWN ) {
712                                 rc = (*c->be->be_config)(c->be, c->fname, c->lineno,
713                                         c->argc, c->argv);
714                         }
715                         if ( rc ) {
716                                 switch(rc) {
717                                 case SLAP_CONF_UNKNOWN:
718                                         Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
719                                                 "unknown directive <%s> inside backend database "
720                                                 "definition" SLAPD_CONF_UNKNOWN_IGNORED ".\n",
721                                                 c->log, *c->argv, 0);
722 #ifndef SLAPD_CONF_UNKNOWN_BAILOUT
723                                         continue;
724 #endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
725                                 default:
726                                         rc = 1;
727                                         goto leave;
728                                 }
729                         }
730
731                 } else if ( frontendDB->be_config ) {
732                         rc = (*frontendDB->be_config)(frontendDB, c->fname, (int)c->lineno, c->argc, c->argv);
733                         if ( rc ) {
734                                 switch(rc) {
735                                 case SLAP_CONF_UNKNOWN:
736                                         Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
737                                                 "unknown directive <%s> inside global database definition"
738                                                 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
739                                                 c->log, *c->argv, 0);
740 #ifndef SLAPD_CONF_UNKNOWN_BAILOUT
741                                         continue;
742 #endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
743                                 default:
744                                         rc = 1;
745                                         goto leave;
746                                 }
747                         }
748                         
749                 } else {
750                         Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
751                                 "unknown directive <%s> outside backend info and database definitions"
752                                 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
753                                 c->log, *c->argv, 0);
754 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
755                         rc = 1;
756                         goto leave;
757 #else /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
758                         continue;
759 #endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
760                 }
761         }
762
763         rc = 0;
764
765 leave:
766         ch_free(c->tline);
767         fclose(fp);
768         ch_free(c->argv);
769         ch_free(c);
770         return(rc);
771 }
772
773 /* restrictops, allows, disallows, requires, loglevel */
774
775 int
776 verb_to_mask(const char *word, slap_verbmasks *v) {
777         int i;
778         for(i = 0; !BER_BVISNULL(&v[i].word); i++)
779                 if(!strcasecmp(word, v[i].word.bv_val))
780                         break;
781         return(i);
782 }
783
784 int
785 verbs_to_mask(int argc, char *argv[], slap_verbmasks *v, slap_mask_t *m) {
786         int i, j;
787         for(i = 1; i < argc; i++) {
788                 j = verb_to_mask(argv[i], v);
789                 if(BER_BVISNULL(&v[j].word)) return(1);
790                 while (!v[j].mask) j--;
791                 *m |= v[j].mask;
792         }
793         return(0);
794 }
795
796 /* Mask keywords that represent multiple bits should occur before single
797  * bit keywords in the verbmasks array.
798  */
799 int
800 mask_to_verbs(slap_verbmasks *v, slap_mask_t m, BerVarray *bva) {
801         int i;
802
803         if (!m) return 1;
804         for (i=0; !BER_BVISNULL(&v[i].word); i++) {
805                 if (!v[i].mask) continue;
806                 if (( m & v[i].mask ) == v[i].mask ) {
807                         value_add_one( bva, &v[i].word );
808                         m ^= v[i].mask;
809                         if ( !m ) break;
810                 }
811         }
812         return 0;
813 }
814
815 int
816 slap_verbmasks_init( slap_verbmasks **vp, slap_verbmasks *v )
817 {
818         int             i;
819
820         assert( *vp == NULL );
821
822         for ( i = 0; !BER_BVISNULL( &v[ i ].word ); i++ )
823                 ;
824
825         *vp = ch_calloc( i + 1, sizeof( slap_verbmasks ) );
826
827         for ( i = 0; !BER_BVISNULL( &v[ i ].word ); i++ ) {
828                 ber_dupbv( &(*vp)[ i ].word, &v[ i ].word );
829                 *((slap_mask_t *)&(*vp)[ i ].mask) = v[ i ].mask;
830         }
831
832         BER_BVZERO( &(*vp)[ i ].word );
833
834         return 0;               
835 }
836
837 int
838 slap_verbmasks_destroy( slap_verbmasks *v )
839 {
840         int             i;
841
842         assert( v != NULL );
843
844         for ( i = 0; !BER_BVISNULL( &v[ i ].word ); i++ ) {
845                 ch_free( v[ i ].word.bv_val );
846         }
847
848         ch_free( v );
849
850         return 0;
851 }
852
853 int
854 slap_verbmasks_append(
855         slap_verbmasks  **vp,
856         slap_mask_t     m,
857         struct berval   *v,
858         slap_mask_t     *ignore )
859 {
860         int     i;
861
862         if ( !m ) {
863                 return LDAP_OPERATIONS_ERROR;
864         }
865
866         for ( i = 0; !BER_BVISNULL( &(*vp)[ i ].word ); i++ ) {
867                 if ( !(*vp)[ i ].mask ) continue;
868
869                 if ( ignore != NULL ) {
870                         int     j;
871
872                         for ( j = 0; ignore[ j ] != 0; j++ ) {
873                                 if ( (*vp)[ i ].mask == ignore[ j ] ) {
874                                         goto check_next;
875                                 }
876                         }
877                 }
878
879                 if ( ( m & (*vp)[ i ].mask ) == (*vp)[ i ].mask ) {
880                         if ( ber_bvstrcasecmp( v, &(*vp)[ i ].word ) == 0 ) {
881                                 /* already set; ignore */
882                                 return LDAP_SUCCESS;
883                         }
884                         /* conflicts */
885                         return LDAP_TYPE_OR_VALUE_EXISTS;
886                 }
887
888                 if ( m & (*vp)[ i ].mask ) {
889                         /* conflicts */
890                         return LDAP_CONSTRAINT_VIOLATION;
891                 }
892 check_next:;
893         }
894
895         *vp = ch_realloc( *vp, sizeof( slap_verbmasks ) * ( i + 2 ) );
896         ber_dupbv( &(*vp)[ i ].word, v );
897         *((slap_mask_t *)&(*vp)[ i ].mask) = m;
898         BER_BVZERO( &(*vp)[ i + 1 ].word );
899
900         return LDAP_SUCCESS;
901 }
902
903 int
904 enum_to_verb(slap_verbmasks *v, slap_mask_t m, struct berval *bv) {
905         int i;
906
907         for (i=0; !BER_BVISNULL(&v[i].word); i++) {
908                 if ( m == v[i].mask ) {
909                         if ( bv != NULL ) {
910                                 *bv = v[i].word;
911                         }
912                         return i;
913                 }
914         }
915         return -1;
916 }
917
918 static slap_verbmasks tlskey[] = {
919         { BER_BVC("no"),        SB_TLS_OFF },
920         { BER_BVC("yes"),       SB_TLS_ON },
921         { BER_BVC("critical"),  SB_TLS_CRITICAL },
922         { BER_BVNULL, 0 }
923 };
924
925 static slap_verbmasks methkey[] = {
926         { BER_BVC("none"),      LDAP_AUTH_NONE },
927         { BER_BVC("simple"),    LDAP_AUTH_SIMPLE },
928 #ifdef HAVE_CYRUS_SASL
929         { BER_BVC("sasl"),      LDAP_AUTH_SASL },
930 #endif
931         { BER_BVNULL, 0 }
932 };
933
934 typedef struct cf_aux_table {
935         struct berval key;
936         int off;
937         char type;
938         char quote;
939         slap_verbmasks *aux;
940 } cf_aux_table;
941
942 static cf_aux_table bindkey[] = {
943         { BER_BVC("starttls="), offsetof(slap_bindconf, sb_tls), 'd', 0, tlskey },
944         { BER_BVC("bindmethod="), offsetof(slap_bindconf, sb_method), 'd', 0, methkey },
945         { BER_BVC("binddn="), offsetof(slap_bindconf, sb_binddn), 'b', 1, NULL },
946         { BER_BVC("credentials="), offsetof(slap_bindconf, sb_cred), 'b', 1, NULL },
947         { BER_BVC("saslmech="), offsetof(slap_bindconf, sb_saslmech), 'b', 0, NULL },
948         { BER_BVC("secprops="), offsetof(slap_bindconf, sb_secprops), 's', 0, NULL },
949         { BER_BVC("realm="), offsetof(slap_bindconf, sb_realm), 'b', 0, NULL },
950         { BER_BVC("authcID="), offsetof(slap_bindconf, sb_authcId), 'b', 0, NULL },
951         { BER_BVC("authzID="), offsetof(slap_bindconf, sb_authzId), 'b', 1, NULL },
952         { BER_BVNULL, 0, 0, 0, NULL }
953 };
954
955 int bindconf_parse( const char *word, slap_bindconf *bc ) {
956         int rc = 0;
957         cf_aux_table *tab;
958
959         for (tab = bindkey; !BER_BVISNULL(&tab->key); tab++) {
960                 if ( !strncasecmp( word, tab->key.bv_val, tab->key.bv_len )) {
961                         char **cptr;
962                         int *iptr, j;
963                         struct berval *bptr;
964                         const char *val = word + tab->key.bv_len;
965
966                         switch ( tab->type ) {
967                         case 's':
968                                 cptr = (char **)((char *)bc + tab->off);
969                                 *cptr = ch_strdup( val );
970                                 break;
971
972                         case 'b':
973                                 bptr = (struct berval *)((char *)bc + tab->off);
974                                 ber_str2bv( val, 0, 1, bptr );
975                                 break;
976
977                         case 'd':
978                                 assert( tab->aux != NULL );
979                                 iptr = (int *)((char *)bc + tab->off);
980
981                                 rc = 1;
982                                 for ( j = 0; !BER_BVISNULL( &tab->aux[j].word ); j++ ) {
983                                         if ( !strcasecmp( val, tab->aux[j].word.bv_val ) ) {
984                                                 *iptr = tab->aux[j].mask;
985                                                 rc = 0;
986                                         }
987                                 }
988                                 break;
989                         }
990
991                         if ( rc ) {
992                                 Debug( LDAP_DEBUG_ANY, "invalid bind config value %s\n",
993                                         word, 0, 0 );
994                         }
995                         
996                         return rc;
997                 }
998         }
999
1000         return rc;
1001 }
1002
1003 int bindconf_unparse( slap_bindconf *bc, struct berval *bv ) {
1004         char buf[BUFSIZ], *ptr;
1005         cf_aux_table *tab;
1006         struct berval tmp;
1007
1008         ptr = buf;
1009         for (tab = bindkey; !BER_BVISNULL(&tab->key); tab++) {
1010                 char **cptr;
1011                 int *iptr, i;
1012                 struct berval *bptr;
1013
1014                 cptr = (char **)((char *)bc + tab->off);
1015
1016                 switch ( tab->type ) {
1017                 case 'b':
1018                         bptr = (struct berval *)((char *)bc + tab->off);
1019                         cptr = &bptr->bv_val;
1020                 case 's':
1021                         if ( *cptr ) {
1022                                 *ptr++ = ' ';
1023                                 ptr = lutil_strcopy( ptr, tab->key.bv_val );
1024                                 if ( tab->quote ) *ptr++ = '"';
1025                                 ptr = lutil_strcopy( ptr, *cptr );
1026                                 if ( tab->quote ) *ptr++ = '"';
1027                         }
1028                         break;
1029
1030                 case 'd':
1031                         assert( tab->aux != NULL );
1032                         iptr = (int *)((char *)bc + tab->off);
1033                 
1034                         for ( i = 0; !BER_BVISNULL( &tab->aux[i].word ); i++ ) {
1035                                 if ( *iptr == tab->aux[i].mask ) {
1036                                         *ptr++ = ' ';
1037                                         ptr = lutil_strcopy( ptr, tab->key.bv_val );
1038                                         ptr = lutil_strcopy( ptr, tab->aux[i].word.bv_val );
1039                                         break;
1040                                 }
1041                         }
1042                         break;
1043                 }
1044         }
1045         tmp.bv_val = buf;
1046         tmp.bv_len = ptr - buf;
1047         ber_dupbv( bv, &tmp );
1048         return 0;
1049 }
1050
1051 void bindconf_free( slap_bindconf *bc ) {
1052         if ( !BER_BVISNULL( &bc->sb_binddn ) ) {
1053                 ch_free( bc->sb_binddn.bv_val );
1054                 BER_BVZERO( &bc->sb_binddn );
1055         }
1056         if ( !BER_BVISNULL( &bc->sb_cred ) ) {
1057                 ch_free( bc->sb_cred.bv_val );
1058                 BER_BVZERO( &bc->sb_cred );
1059         }
1060         if ( !BER_BVISNULL( &bc->sb_saslmech ) ) {
1061                 ch_free( bc->sb_saslmech.bv_val );
1062                 BER_BVZERO( &bc->sb_saslmech );
1063         }
1064         if ( bc->sb_secprops ) {
1065                 ch_free( bc->sb_secprops );
1066                 bc->sb_secprops = NULL;
1067         }
1068         if ( !BER_BVISNULL( &bc->sb_realm ) ) {
1069                 ch_free( bc->sb_realm.bv_val );
1070                 BER_BVZERO( &bc->sb_realm );
1071         }
1072         if ( !BER_BVISNULL( &bc->sb_authcId ) ) {
1073                 ch_free( bc->sb_authcId.bv_val );
1074                 BER_BVZERO( &bc->sb_authcId );
1075         }
1076         if ( !BER_BVISNULL( &bc->sb_authzId ) ) {
1077                 ch_free( bc->sb_authzId.bv_val );
1078                 BER_BVZERO( &bc->sb_authzId );
1079         }
1080 }
1081
1082
1083 /* -------------------------------------- */
1084
1085
1086 static char *
1087 strtok_quote( char *line, char *sep, char **quote_ptr )
1088 {
1089         int             inquote;
1090         char            *tmp;
1091         static char     *next;
1092
1093         *quote_ptr = NULL;
1094         if ( line != NULL ) {
1095                 next = line;
1096         }
1097         while ( *next && strchr( sep, *next ) ) {
1098                 next++;
1099         }
1100
1101         if ( *next == '\0' ) {
1102                 next = NULL;
1103                 return( NULL );
1104         }
1105         tmp = next;
1106
1107         for ( inquote = 0; *next; ) {
1108                 switch ( *next ) {
1109                 case '"':
1110                         if ( inquote ) {
1111                                 inquote = 0;
1112                         } else {
1113                                 inquote = 1;
1114                         }
1115                         AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
1116                         break;
1117
1118                 case '\\':
1119                         if ( next[1] )
1120                                 AC_MEMCPY( next,
1121                                             next + 1, strlen( next + 1 ) + 1 );
1122                         next++;         /* dont parse the escaped character */
1123                         break;
1124
1125                 default:
1126                         if ( ! inquote ) {
1127                                 if ( strchr( sep, *next ) != NULL ) {
1128                                         *quote_ptr = next;
1129                                         *next++ = '\0';
1130                                         return( tmp );
1131                                 }
1132                         }
1133                         next++;
1134                         break;
1135                 }
1136         }
1137
1138         return( tmp );
1139 }
1140
1141 static char     buf[BUFSIZ];
1142 static char     *line;
1143 static size_t lmax, lcur;
1144
1145 #define CATLINE( buf ) \
1146         do { \
1147                 size_t len = strlen( buf ); \
1148                 while ( lcur + len + 1 > lmax ) { \
1149                         lmax += BUFSIZ; \
1150                         line = (char *) ch_realloc( line, lmax ); \
1151                 } \
1152                 strcpy( line + lcur, buf ); \
1153                 lcur += len; \
1154         } while( 0 )
1155
1156 static void
1157 fp_getline_init(ConfigArgs *c) {
1158         c->lineno = -1;
1159         buf[0] = '\0';
1160 }
1161
1162 static int
1163 fp_getline( FILE *fp, ConfigArgs *c )
1164 {
1165         char    *p;
1166
1167         lcur = 0;
1168         CATLINE(buf);
1169         c->lineno++;
1170
1171         /* avoid stack of bufs */
1172         if ( strncasecmp( line, "include", STRLENOF( "include" ) ) == 0 ) {
1173                 buf[0] = '\0';
1174                 c->line = line;
1175                 return(1);
1176         }
1177
1178         while ( fgets( buf, sizeof( buf ), fp ) ) {
1179                 p = strchr( buf, '\n' );
1180                 if ( p ) {
1181                         if ( p > buf && p[-1] == '\r' ) {
1182                                 --p;
1183                         }
1184                         *p = '\0';
1185                 }
1186                 /* XXX ugly */
1187                 c->line = line;
1188                 if ( line[0]
1189                                 && ( p = line + strlen( line ) - 1 )[0] == '\\'
1190                                 && p[-1] != '\\' )
1191                 {
1192                         p[0] = '\0';
1193                         lcur--;
1194                         
1195                 } else {
1196                         if ( !isspace( (unsigned char)buf[0] ) ) {
1197                                 return(1);
1198                         }
1199                         buf[0] = ' ';
1200                 }
1201                 CATLINE(buf);
1202                 c->lineno++;
1203         }
1204
1205         buf[0] = '\0';
1206         c->line = line;
1207         return(line[0] ? 1 : 0);
1208 }
1209
1210 static int
1211 fp_parse_line(ConfigArgs *c)
1212 {
1213         char *token;
1214         static char *const hide[] = {
1215                 "rootpw", "replica", "syncrepl",  /* in slapd */
1216                 "acl-bind", "acl-method", "idassert-bind",  /* in back-ldap */
1217                 "acl-passwd", "bindpw",  /* in back-<ldap/meta> */
1218                 "pseudorootpw",  /* in back-meta */
1219                 "dbpasswd",  /* in back-sql */
1220                 NULL
1221         };
1222         char *quote_ptr;
1223         int i = (int)(sizeof(hide)/sizeof(hide[0])) - 1;
1224
1225         c->tline = ch_strdup(c->line);
1226         token = strtok_quote(c->tline, " \t", &quote_ptr);
1227
1228         if(token) for(i = 0; hide[i]; i++) if(!strcasecmp(token, hide[i])) break;
1229         if(quote_ptr) *quote_ptr = ' ';
1230         Debug(LDAP_DEBUG_CONFIG, "line %d (%s%s)\n", c->lineno,
1231                 hide[i] ? hide[i] : c->line, hide[i] ? " ***" : "");
1232         if(quote_ptr) *quote_ptr = '\0';
1233
1234         for(;; token = strtok_quote(NULL, " \t", &quote_ptr)) {
1235                 if(c->argc >= c->argv_size) {
1236                         char **tmp;
1237                         tmp = ch_realloc(c->argv, (c->argv_size + ARGS_STEP) * sizeof(*c->argv));
1238                         if(!tmp) {
1239                                 Debug(LDAP_DEBUG_ANY, "line %d: out of memory\n", c->lineno, 0, 0);
1240                                 return -1;
1241                         }
1242                         c->argv = tmp;
1243                         c->argv_size += ARGS_STEP;
1244                 }
1245                 if(token == NULL)
1246                         break;
1247                 c->argv[c->argc++] = token;
1248         }
1249         c->argv[c->argc] = NULL;
1250         return(0);
1251 }
1252
1253 void
1254 config_destroy( )
1255 {
1256         ucdata_unload( UCDATA_ALL );
1257         if ( frontendDB ) {
1258                 /* NOTE: in case of early exit, frontendDB can be NULL */
1259                 if ( frontendDB->be_schemandn.bv_val )
1260                         free( frontendDB->be_schemandn.bv_val );
1261                 if ( frontendDB->be_schemadn.bv_val )
1262                         free( frontendDB->be_schemadn.bv_val );
1263                 if ( frontendDB->be_acl )
1264                         acl_destroy( frontendDB->be_acl, NULL );
1265         }
1266         free( line );
1267         if ( slapd_args_file )
1268                 free ( slapd_args_file );
1269         if ( slapd_pid_file )
1270                 free ( slapd_pid_file );
1271         if ( default_passwd_hash )
1272                 ldap_charray_free( default_passwd_hash );
1273 }
1274
1275 char **
1276 slap_str2clist( char ***out, char *in, const char *brkstr )
1277 {
1278         char    *str;
1279         char    *s;
1280         char    *lasts;
1281         int     i, j;
1282         char    **new;
1283
1284         /* find last element in list */
1285         for (i = 0; *out && (*out)[i]; i++);
1286
1287         /* protect the input string from strtok */
1288         str = ch_strdup( in );
1289
1290         if ( *str == '\0' ) {
1291                 free( str );
1292                 return( *out );
1293         }
1294
1295         /* Count words in string */
1296         j=1;
1297         for ( s = str; *s; s++ ) {
1298                 if ( strchr( brkstr, *s ) != NULL ) {
1299                         j++;
1300                 }
1301         }
1302
1303         *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
1304         new = *out + i;
1305         for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
1306                 s != NULL;
1307                 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
1308         {
1309                 *new = ch_strdup( s );
1310                 new++;
1311         }
1312
1313         *new = NULL;
1314         free( str );
1315         return( *out );
1316 }
1317
1318 int config_generic_wrapper( Backend *be, const char *fname, int lineno,
1319         int argc, char **argv )
1320 {
1321         ConfigArgs c = { 0 };
1322         ConfigTable *ct;
1323         int rc;
1324
1325         c.be = be;
1326         c.fname = fname;
1327         c.lineno = lineno;
1328         c.argc = argc;
1329         c.argv = argv;
1330         c.valx = -1;
1331         sprintf( c.log, "%s: line %d", fname, lineno );
1332
1333         rc = SLAP_CONF_UNKNOWN;
1334         ct = config_find_keyword( be->be_cf_ocs->co_table, &c );
1335         if ( ct )
1336                 rc = config_add_vals( ct, &c );
1337         return rc;
1338 }