]> git.sur5r.net Git - openldap/blob - servers/slapd/config.c
Add schema checks.
[openldap] / servers / slapd / config.c
1 /* config.c - configuration file handling routines */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11 #ifdef HAVE_LOCALE_H
12 #include <locale.h>
13 #endif
14
15 #include <ac/string.h>
16 #include <ac/ctype.h>
17 #include <ac/socket.h>
18
19 #include "ldap_pvt.h"
20 #include "slap.h"
21
22 #define MAXARGS 100
23
24 /*
25  * defaults for various global variables
26  */
27 int             defsize = SLAPD_DEFAULT_SIZELIMIT;
28 int             deftime = SLAPD_DEFAULT_TIMELIMIT;
29 AccessControl   *global_acl = NULL;
30 slap_access_t           global_default_access = ACL_READ;
31 int             global_readonly = 0;
32 char            *replogfile;
33 int             global_lastmod = ON;
34 int             global_idletimeout = 0;
35 char    *global_realm = NULL;
36 char            *ldap_srvtab = "";
37 char            *default_passwd_hash;
38
39 char   *slapd_pid_file  = NULL;
40 char   *slapd_args_file = NULL;
41
42 static char     *fp_getline(FILE *fp, int *lineno);
43 static void     fp_getline_init(int *lineno);
44 static int      fp_parse_line(char *line, int *argcp, char **argv);
45
46 static char     *strtok_quote(char *line, char *sep);
47
48 int
49 read_config( const char *fname )
50 {
51         FILE    *fp;
52         char    *line, *savefname, *saveline;
53         int     cargc, savelineno;
54         char    *cargv[MAXARGS];
55         int     lineno, i;
56 #ifdef HAVE_TLS
57         int rc;
58 #endif
59         struct berval *vals[2];
60         struct berval val;
61
62         static BackendInfo *bi = NULL;
63         static BackendDB        *be = NULL;
64
65         vals[0] = &val;
66         vals[1] = NULL;
67
68         if ( (fp = fopen( fname, "r" )) == NULL ) {
69                 ldap_syslog = 1;
70                 Debug( LDAP_DEBUG_ANY,
71                     "could not open config file \"%s\" - absolute path?\n",
72                     fname, 0, 0 );
73                 perror( fname );
74                 return 1;
75         }
76
77         Debug( LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0 );
78
79         fp_getline_init( &lineno );
80
81         while ( (line = fp_getline( fp, &lineno )) != NULL ) {
82                 /* skip comments and blank lines */
83                 if ( line[0] == '#' || line[0] == '\0' ) {
84                         continue;
85                 }
86
87                 Debug( LDAP_DEBUG_CONFIG, "line %d (%s)\n", lineno, line, 0 );
88
89                 /* fp_parse_line is destructive, we save a copy */
90                 saveline = ch_strdup( line );
91
92                 if ( fp_parse_line( line, &cargc, cargv ) != 0 ) {
93                         return( 1 );
94                 }
95
96                 if ( cargc < 1 ) {
97                         Debug( LDAP_DEBUG_ANY,
98                             "%s: line %d: bad config line (ignored)\n",
99                             fname, lineno, 0 );
100                         continue;
101                 }
102
103                 if ( strcasecmp( cargv[0], "backend" ) == 0 ) {
104                         if ( cargc < 2 ) {
105                                 Debug( LDAP_DEBUG_ANY,
106                 "%s: line %d: missing type in \"backend <type>\" line\n",
107                                     fname, lineno, 0 );
108                                 return( 1 );
109                         }
110
111                         if( be != NULL ) {
112                                 Debug( LDAP_DEBUG_ANY,
113 "%s: line %d: backend line must appear before any database definition\n",
114                                     fname, lineno, 0 );
115                                 return( 1 );
116                         }
117
118                         bi = backend_info( cargv[1] );
119
120                         if( bi == NULL ) {
121                                 Debug( LDAP_DEBUG_ANY,
122                                         "backend %s initialization failed.n",
123                                     cargv[1], 0, 0 );
124                                 return( 1 );
125                         }
126
127                 /* start of a new database definition */
128                 } else if ( strcasecmp( cargv[0], "database" ) == 0 ) {
129                         if ( cargc < 2 ) {
130                                 Debug( LDAP_DEBUG_ANY,
131                 "%s: line %d: missing type in \"database <type>\" line\n",
132                                     fname, lineno, 0 );
133                                 return( 1 );
134                         }
135
136                         bi = NULL;
137                         be = backend_db_init( cargv[1] );
138
139                         if( be == NULL ) {
140                                 Debug( LDAP_DEBUG_ANY,
141                                         "database %s initialization failed.n",
142                                     cargv[1], 0, 0 );
143                                 return( 1 );
144                         }
145
146                 /* set thread concurrency */
147                 } else if ( strcasecmp( cargv[0], "concurrency" ) == 0 ) {
148                         int c;
149                         if ( cargc < 2 ) {
150                                 Debug( LDAP_DEBUG_ANY,
151             "%s: line %d: missing level in \"concurrency <level>\" line\n",
152                                     fname, lineno, 0 );
153                                 return( 1 );
154                         }
155
156                         c = atoi( cargv[1] );
157
158                         if( c < 1 ) {
159                                 Debug( LDAP_DEBUG_ANY,
160             "%s: line %d: invalid level (%d) in \"concurrency <level>\" line\n",
161                                     fname, lineno, c );
162                                 return( 1 );
163                         }
164
165                         ldap_pvt_thread_set_concurrency( c );
166
167                 /* get pid file name */
168                 } else if ( strcasecmp( cargv[0], "pidfile" ) == 0 ) {
169                         if ( cargc < 2 ) {
170                                 Debug( LDAP_DEBUG_ANY,
171             "%s: line %d: missing file name in \"pidfile <file>\" line\n",
172                                     fname, lineno, 0 );
173                                 return( 1 );
174                         }
175
176                         slapd_pid_file = ch_strdup( cargv[1] );
177
178                 /* get args file name */
179                 } else if ( strcasecmp( cargv[0], "argsfile" ) == 0 ) {
180                         if ( cargc < 2 ) {
181                                 Debug( LDAP_DEBUG_ANY,
182             "%s: line %d: missing file name in \"argsfile <file>\" line\n",
183                                     fname, lineno, 0 );
184                                 return( 1 );
185                         }
186
187                         slapd_args_file = ch_strdup( cargv[1] );
188
189                 /* default password hash */
190                 } else if ( strcasecmp( cargv[0], "password-hash" ) == 0 ) {
191                         if ( cargc < 2 ) {
192                                 Debug( LDAP_DEBUG_ANY,
193             "%s: line %d: missing realm in \"password-hash <hash>\" line\n",
194                                     fname, lineno, 0 );
195                                 return( 1 );
196                         }
197                         if ( default_passwd_hash != NULL ) {
198                                 Debug( LDAP_DEBUG_ANY,
199                                         "%s: line %d: already set default password_hash!\n",
200                                         fname, lineno, 0 );
201                                 return 1;
202
203                         } else {
204                                 default_passwd_hash = ch_strdup( cargv[1] );
205                         }
206
207                 /* set DIGEST realm */
208                 } else if ( strcasecmp( cargv[0], "digest-realm" ) == 0 ) {
209                         if ( cargc < 2 ) {
210                                 Debug( LDAP_DEBUG_ANY,
211             "%s: line %d: missing realm in \"digest-realm <realm>\" line\n",
212                                     fname, lineno, 0 );
213                                 return( 1 );
214                         }
215                         if ( be != NULL ) {
216                                 be->be_realm = ch_strdup( cargv[1] );
217
218                         } else if ( global_realm != NULL ) {
219                                 Debug( LDAP_DEBUG_ANY,
220                                         "%s: line %d: already set global realm!\n",
221                                         fname, lineno, 0 );
222                                 return 1;
223
224                         } else {
225                                 global_realm = ch_strdup( cargv[1] );
226                         }
227
228                 /* set time limit */
229                 } else if ( strcasecmp( cargv[0], "sizelimit" ) == 0 ) {
230                         if ( cargc < 2 ) {
231                                 Debug( LDAP_DEBUG_ANY,
232             "%s: line %d: missing limit in \"sizelimit <limit>\" line\n",
233                                     fname, lineno, 0 );
234                                 return( 1 );
235                         }
236                         if ( be == NULL ) {
237                                 defsize = atoi( cargv[1] );
238                         } else {
239                                 be->be_sizelimit = atoi( cargv[1] );
240                         }
241
242                 /* set time limit */
243                 } else if ( strcasecmp( cargv[0], "timelimit" ) == 0 ) {
244                         if ( cargc < 2 ) {
245                                 Debug( LDAP_DEBUG_ANY,
246             "%s: line %d: missing limit in \"timelimit <limit>\" line\n",
247                                     fname, lineno, 0 );
248                                 return( 1 );
249                         }
250                         if ( be == NULL ) {
251                                 deftime = atoi( cargv[1] );
252                         } else {
253                                 be->be_timelimit = atoi( cargv[1] );
254                         }
255
256                 /* set database suffix */
257                 } else if ( strcasecmp( cargv[0], "suffix" ) == 0 ) {
258                         Backend *tmp_be;
259                         if ( cargc < 2 ) {
260                                 Debug( LDAP_DEBUG_ANY,
261                     "%s: line %d: missing dn in \"suffix <dn>\" line\n",
262                                     fname, lineno, 0 );
263                                 return( 1 );
264                         } else if ( cargc > 2 ) {
265                                 Debug( LDAP_DEBUG_ANY,
266     "%s: line %d: extra cruft after <dn> in \"suffix %s\" line (ignored)\n",
267                                     fname, lineno, cargv[1] );
268                         }
269                         if ( be == NULL ) {
270                                 Debug( LDAP_DEBUG_ANY,
271 "%s: line %d: suffix line must appear inside a database definition (ignored)\n",
272                                     fname, lineno, 0 );
273                         } else if ( ( tmp_be = select_backend( cargv[1] ) ) == be ) {
274                                 Debug( LDAP_DEBUG_ANY,
275 "%s: line %d: suffix already served by this backend (ignored)\n",
276                                     fname, lineno, 0 );
277                         } else if ( tmp_be  != NULL ) {
278                                 Debug( LDAP_DEBUG_ANY,
279 "%s: line %d: suffix already served by a preceeding backend \"%s\" (ignored)\n",
280                                     fname, lineno, tmp_be->be_suffix[0] );
281                         } else {
282                                 char *dn = ch_strdup( cargv[1] );
283                                 (void) dn_validate( dn );
284                                 charray_add( &be->be_suffix, dn );
285                                 (void) ldap_pvt_str2upper( dn );
286                                 charray_add( &be->be_nsuffix, dn );
287                                 free( dn );
288                         }
289
290                 /* set database suffixAlias */
291                 } else if ( strcasecmp( cargv[0], "suffixAlias" ) == 0 ) {
292                         Backend *tmp_be;
293                         if ( cargc < 2 ) {
294                                 Debug( LDAP_DEBUG_ANY,
295 "%s: line %d: missing alias and aliased_dn in \"suffixAlias <alias> <aliased_dn>\" line\n",
296                                         fname, lineno, 0 );
297                                 return( 1 );
298                         } else if ( cargc < 3 ) {
299                                 Debug( LDAP_DEBUG_ANY,
300 "%s: line %d: missing aliased_dn in \"suffixAlias <alias> <aliased_dn>\" line\n",
301                                 fname, lineno, 0 );
302                                 return( 1 );
303                         } else if ( cargc > 3 ) {
304                                 Debug( LDAP_DEBUG_ANY,
305                                         "%s: line %d: extra cruft in suffixAlias line (ignored)\n",
306                                 fname, lineno, 0 );
307                         }
308
309                         if ( be == NULL ) {
310                                 Debug( LDAP_DEBUG_ANY,
311                                         "%s: line %d: suffixAlias line"
312                                         " must appear inside a database definition (ignored)\n",
313                                         fname, lineno, 0 );
314                         } else if ( (tmp_be = select_backend( cargv[1] )) != NULL ) {
315                                 Debug( LDAP_DEBUG_ANY,
316                                         "%s: line %d: suffixAlias served by"
317                                         "  a preceeding backend \"%s\" (ignored)\n",
318                                         fname, lineno, tmp_be->be_suffix[0] );
319
320                         } else if ( (tmp_be = select_backend( cargv[2] )) != NULL ) {
321                                 Debug( LDAP_DEBUG_ANY,
322                                         "%s: line %d: suffixAlias derefs to differnet backend"
323                                         "  a preceeding backend \"%s\" (ignored)\n",
324                                         fname, lineno, tmp_be->be_suffix[0] );
325
326                         } else {
327                                 char *alias, *aliased_dn;
328
329                                 alias = ch_strdup( cargv[1] );
330                                 (void) dn_normalize( alias );
331
332                                 aliased_dn = ch_strdup( cargv[2] );
333                                 (void) dn_normalize( aliased_dn );
334
335                                 charray_add( &be->be_suffixAlias, alias );
336                                 charray_add( &be->be_suffixAlias, aliased_dn );
337
338                                 free(alias);
339                                 free(aliased_dn);
340                         }
341
342                /* set max deref depth */
343                } else if ( strcasecmp( cargv[0], "maxDerefDepth" ) == 0 ) {
344                                         int i;
345                        if ( cargc < 2 ) {
346                                Debug( LDAP_DEBUG_ANY,
347                    "%s: line %d: missing depth in \"maxDerefDepth <depth>\" line\n",
348                                    fname, lineno, 0 );
349                                return( 1 );
350                        }
351                        if ( be == NULL ) {
352                                Debug( LDAP_DEBUG_ANY,
353 "%s: line %d: depth line must appear inside a database definition (ignored)\n",
354                                    fname, lineno, 0 );
355                        } else if ((i = atoi(cargv[1])) < 0) {
356                                Debug( LDAP_DEBUG_ANY,
357 "%s: line %d: depth must be positive (ignored)\n",
358                                    fname, lineno, 0 );
359
360                        } else {
361                            be->be_max_deref_depth = i;
362                                            }
363
364
365                 /* set magic "root" dn for this database */
366                 } else if ( strcasecmp( cargv[0], "rootdn" ) == 0 ) {
367                         if ( cargc < 2 ) {
368                                 Debug( LDAP_DEBUG_ANY,
369                     "%s: line %d: missing dn in \"rootdn <dn>\" line\n",
370                                     fname, lineno, 0 );
371                                 return( 1 );
372                         }
373                         if ( be == NULL ) {
374                                 Debug( LDAP_DEBUG_ANY,
375 "%s: line %d: rootdn line must appear inside a database definition (ignored)\n",
376                                     fname, lineno, 0 );
377                         } else {
378                                 be->be_root_dn = ch_strdup( cargv[1] );
379                                 be->be_root_ndn = ch_strdup( cargv[1] );
380
381                                 if( dn_normalize( be->be_root_ndn ) == NULL ) {
382                                         free( be->be_root_dn );
383                                         free( be->be_root_ndn );
384                                         Debug( LDAP_DEBUG_ANY,
385 "%s: line %d: rootdn DN is invalid\n",
386                                            fname, lineno, 0 );
387                                         return( 1 );
388                                 }
389                         }
390
391                 /* set super-secret magic database password */
392                 } else if ( strcasecmp( cargv[0], "rootpw" ) == 0 ) {
393                         if ( cargc < 2 ) {
394                                 Debug( LDAP_DEBUG_ANY,
395             "%s: line %d: missing passwd in \"rootpw <passwd>\" line\n",
396                                     fname, lineno, 0 );
397                                 return( 1 );
398                         }
399                         if ( be == NULL ) {
400                                 Debug( LDAP_DEBUG_ANY,
401 "%s: line %d: rootpw line must appear inside a database definition (ignored)\n",
402                                     fname, lineno, 0 );
403                         } else {
404                                 be->be_root_pw.bv_val = ch_strdup( cargv[1] );
405                                 be->be_root_pw.bv_len = strlen( be->be_root_pw.bv_val );
406                         }
407
408                 /* make this database read-only */
409                 } else if ( strcasecmp( cargv[0], "readonly" ) == 0 ) {
410                         if ( cargc < 2 ) {
411                                 Debug( LDAP_DEBUG_ANY,
412             "%s: line %d: missing on|off in \"readonly <on|off>\" line\n",
413                                     fname, lineno, 0 );
414                                 return( 1 );
415                         }
416                         if ( be == NULL ) {
417                                 global_readonly = (strcasecmp( cargv[1], "on" ) == 0);
418                         } else {
419                                 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
420                                         be->be_readonly = 1;
421                                 } else {
422                                         be->be_readonly = 0;
423                                 }
424                         }
425
426                 /* where to send clients when we don't hold it */
427                 } else if ( strcasecmp( cargv[0], "referral" ) == 0 ) {
428                         if ( cargc < 2 ) {
429                                 Debug( LDAP_DEBUG_ANY,
430                     "%s: line %d: missing URL in \"referral <URL>\" line\n",
431                                     fname, lineno, 0 );
432                                 return( 1 );
433                         }
434
435                         vals[0]->bv_val = cargv[1];
436                         vals[0]->bv_len = strlen( vals[0]->bv_val );
437                         value_add( &default_referral, vals );
438
439                 /* specify locale */
440                 } else if ( strcasecmp( cargv[0], "locale" ) == 0 ) {
441 #ifdef HAVE_LOCALE_H
442                         char *locale;
443                         if ( cargc < 2 ) {
444                                 Debug( LDAP_DEBUG_ANY,
445         "%s: line %d: missing locale in \"locale <name | on | off>\" line\n",
446                                        fname, lineno, 0 );
447                                 return( 1 );
448                         }
449
450                         locale = (strcasecmp(   cargv[1], "on"  ) == 0 ? ""
451                                   : strcasecmp( cargv[1], "off" ) == 0 ? "C"
452                                   : ch_strdup( cargv[1] )                    );
453
454                         if ( setlocale( LC_CTYPE, locale ) == 0 ) {
455                                 Debug( LDAP_DEBUG_ANY,
456                                        (*locale
457                                         ? "%s: line %d: bad locale \"%s\"\n"
458                                         : "%s: line %d: bad locale\n"),
459                                        fname, lineno, locale );
460                                 return( 1 );
461                         }
462 #else
463                         Debug( LDAP_DEBUG_ANY,
464                                "%s: line %d: \"locale\" unsupported\n",
465                                fname, lineno, 0 );
466                         return( 1 );
467 #endif
468                 /* specify an Object Identifier macro */
469                 } else if ( strcasecmp( cargv[0], "objectidentifier" ) == 0 ) {
470                         parse_oidm( fname, lineno, cargc, cargv );
471
472                 /* specify an objectclass */
473                 } else if ( strcasecmp( cargv[0], "objectclass" ) == 0 ) {
474                         if ( *cargv[1] == '(' ) {
475                                 char * p;
476                                 p = strchr(saveline,'(');
477                                 parse_oc( fname, lineno, p, cargv );
478                         } else {
479                                 Debug( LDAP_DEBUG_ANY,
480     "%s: line %d: old objectclass format not supported.\n",
481                                     fname, lineno, 0 );
482                         }
483
484                 /* specify an attribute type */
485                 } else if (( strcasecmp( cargv[0], "attributetype" ) == 0 )
486                         || ( strcasecmp( cargv[0], "attribute" ) == 0 ))
487                 {
488                         if ( *cargv[1] == '(' ) {
489                                 char * p;
490                                 p = strchr(saveline,'(');
491                                 parse_at( fname, lineno, p, cargv );
492                         } else {
493                                 Debug( LDAP_DEBUG_ANY,
494     "%s: line %d: old attribute type format not supported.\n",
495                                     fname, lineno, 0 );
496                         }
497
498                 /* turn on/off schema checking */
499                 } else if ( strcasecmp( cargv[0], "schemacheck" ) == 0 ) {
500                         if ( cargc < 2 ) {
501                                 Debug( LDAP_DEBUG_ANY,
502     "%s: line %d: missing on|off in \"schemacheck <on|off>\" line\n",
503                                     fname, lineno, 0 );
504                                 return( 1 );
505                         }
506                         if ( strcasecmp( cargv[1], "off" ) == 0 ) {
507                                 global_schemacheck = 0;
508                         } else {
509                                 global_schemacheck = 1;
510                         }
511
512                 /* specify access control info */
513                 } else if ( strcasecmp( cargv[0], "access" ) == 0 ) {
514                         parse_acl( be, fname, lineno, cargc, cargv );
515
516                 /* specify default access control info */
517                 } else if ( strcasecmp( cargv[0], "defaultaccess" ) == 0 ) {
518                         slap_access_t access;
519
520                         if ( cargc < 2 ) {
521                                 Debug( LDAP_DEBUG_ANY,
522             "%s: line %d: missing limit in \"defaultaccess <access>\" line\n",
523                                     fname, lineno, 0 );
524                                 return( 1 );
525                         }
526
527                         access = str2access( cargv[1] );
528
529                         if ( access == ACL_INVALID_ACCESS ) {
530                                 Debug( LDAP_DEBUG_ANY,
531                                         "%s: line %d: bad access level \"%s\", "
532                                         "expecting none|auth|compare|search|read|write\n",
533                                     fname, lineno, cargv[1] );
534                                 return( 1 );
535                         }
536
537                         if ( be == NULL ) {
538                                 global_default_access = access;
539                         } else {
540                                 be->be_dfltaccess = access;
541                         }
542
543                 /* debug level to log things to syslog */
544                 } else if ( strcasecmp( cargv[0], "loglevel" ) == 0 ) {
545                         if ( cargc < 2 ) {
546                                 Debug( LDAP_DEBUG_ANY,
547                     "%s: line %d: missing level in \"loglevel <level>\" line\n",
548                                     fname, lineno, 0 );
549                                 return( 1 );
550                         }
551                         ldap_syslog = atoi( cargv[1] );
552
553                 /* list of replicas of the data in this backend (master only) */
554                 } else if ( strcasecmp( cargv[0], "replica" ) == 0 ) {
555                         if ( cargc < 2 ) {
556                                 Debug( LDAP_DEBUG_ANY,
557             "%s: line %d: missing host in \"replica <host[:port]>\" line\n",
558                                     fname, lineno, 0 );
559                                 return( 1 );
560                         }
561                         if ( be == NULL ) {
562                                 Debug( LDAP_DEBUG_ANY,
563 "%s: line %d: replica line must appear inside a database definition (ignored)\n",
564                                     fname, lineno, 0 );
565                         } else {
566                                 for ( i = 1; i < cargc; i++ ) {
567                                         if ( strncasecmp( cargv[i], "host=", 5 )
568                                             == 0 ) {
569                                                 charray_add( &be->be_replica,
570                                                              cargv[i] + 5 );
571                                                 break;
572                                         }
573                                 }
574                                 if ( i == cargc ) {
575                                         Debug( LDAP_DEBUG_ANY,
576                     "%s: line %d: missing host in \"replica\" line (ignored)\n",
577                                             fname, lineno, 0 );
578                                 }
579                         }
580
581                 /* dn of master entity allowed to write to replica */
582                 } else if ( strcasecmp( cargv[0], "updatedn" ) == 0 ) {
583                         if ( cargc < 2 ) {
584                                 Debug( LDAP_DEBUG_ANY,
585                     "%s: line %d: missing dn in \"updatedn <dn>\" line\n",
586                                     fname, lineno, 0 );
587                                 return( 1 );
588                         }
589                         if ( be == NULL ) {
590                                 Debug( LDAP_DEBUG_ANY,
591 "%s: line %d: updatedn line must appear inside a database definition (ignored)\n",
592                                     fname, lineno, 0 );
593                         } else {
594                                 be->be_update_ndn = ch_strdup( cargv[1] );
595                                 if( dn_normalize( be->be_update_ndn ) == NULL ) {
596                                         Debug( LDAP_DEBUG_ANY,
597 "%s: line %d: updatedn DN is invalid\n",
598                                             fname, lineno, 0 );
599                                         return 1;
600                                 }
601                         }
602
603                 } else if ( strcasecmp( cargv[0], "updateref" ) == 0 ) {
604                         if ( cargc < 2 ) {
605                                 Debug( LDAP_DEBUG_ANY,
606                     "%s: line %d: missing dn in \"updateref <ldapurl>\" line\n",
607                                     fname, lineno, 0 );
608                                 return( 1 );
609                         }
610                         if ( be == NULL ) {
611                                 Debug( LDAP_DEBUG_ANY,
612 "%s: line %d: updateref line must appear inside a database definition (ignored)\n",
613                                     fname, lineno, 0 );
614                         } else if ( be->be_update_ndn == NULL ) {
615                                 Debug( LDAP_DEBUG_ANY,
616 "%s: line %d: updateref line must after updatedn (ignored)\n",
617                                     fname, lineno, 0 );
618                         } else {
619                                 vals[0]->bv_val = cargv[1];
620                                 vals[0]->bv_len = strlen( vals[0]->bv_val );
621                                 value_add( &be->be_update_refs, vals );
622                         }
623
624                 /* replication log file to which changes are appended */
625                 } else if ( strcasecmp( cargv[0], "replogfile" ) == 0 ) {
626                         if ( cargc < 2 ) {
627                                 Debug( LDAP_DEBUG_ANY,
628             "%s: line %d: missing dn in \"replogfile <filename>\" line\n",
629                                     fname, lineno, 0 );
630                                 return( 1 );
631                         }
632                         if ( be ) {
633                                 be->be_replogfile = ch_strdup( cargv[1] );
634                         } else {
635                                 replogfile = ch_strdup( cargv[1] );
636                         }
637
638                 /* maintain lastmodified{by,time} attributes */
639                 } else if ( strcasecmp( cargv[0], "lastmod" ) == 0 ) {
640                         if ( cargc < 2 ) {
641                                 Debug( LDAP_DEBUG_ANY,
642             "%s: line %d: missing on|off in \"lastmod <on|off>\" line\n",
643                                     fname, lineno, 0 );
644                                 return( 1 );
645                         }
646                         if ( strcasecmp( cargv[1], "on" ) == 0 ) {
647                                 if ( be )
648                                         be->be_lastmod = ON;
649                                 else
650                                         global_lastmod = ON;
651                         } else {
652                                 if ( be )
653                                         be->be_lastmod = OFF;
654                                 else
655                                         global_lastmod = OFF;
656                         }
657
658                 /* set idle timeout value */
659                 } else if ( strcasecmp( cargv[0], "idletimeout" ) == 0 ) {
660                         int i;
661                         if ( cargc < 2 ) {
662                                 Debug( LDAP_DEBUG_ANY,
663             "%s: line %d: missing timeout value in \"idletimeout <seconds>\" line\n",
664                                     fname, lineno, 0 );
665                                 return( 1 );
666                         }
667
668                         i = atoi( cargv[1] );
669
670                         if( i < 0 ) {
671                                 Debug( LDAP_DEBUG_ANY,
672             "%s: line %d: timeout value (%d) invalid \"idletimeout <seconds>\" line\n",
673                                     fname, lineno, i );
674                                 return( 1 );
675                         }
676
677                         global_idletimeout = i;
678
679                 /* include another config file */
680                 } else if ( strcasecmp( cargv[0], "include" ) == 0 ) {
681                         if ( cargc < 2 ) {
682                                 Debug( LDAP_DEBUG_ANY,
683     "%s: line %d: missing filename in \"include <filename>\" line\n",
684                                     fname, lineno, 0 );
685                                 return( 1 );
686                         }
687                         savefname = ch_strdup( cargv[1] );
688                         savelineno = lineno;
689
690                         if ( read_config( savefname ) != 0 ) {
691                                 return( 1 );
692                         }
693
694                         free( savefname );
695                         lineno = savelineno - 1;
696
697                 /* location of kerberos srvtab file */
698                 } else if ( strcasecmp( cargv[0], "srvtab" ) == 0 ) {
699                         if ( cargc < 2 ) {
700                                 Debug( LDAP_DEBUG_ANY,
701             "%s: line %d: missing filename in \"srvtab <filename>\" line\n",
702                                     fname, lineno, 0 );
703                                 return( 1 );
704                         }
705                         ldap_srvtab = ch_strdup( cargv[1] );
706
707 #ifdef SLAPD_MODULES
708                 } else if (strcasecmp( cargv[0], "moduleload") == 0 ) {
709                    if ( cargc < 2 ) {
710                       Debug( LDAP_DEBUG_ANY,
711                              "%s: line %d: missing filename in \"moduleload <filename>\" line\n",
712                              fname, lineno, 0 );
713                       exit( EXIT_FAILURE );
714                    }
715                    if (module_load(cargv[1], cargc - 2, (cargc > 2) ? cargv + 2 : NULL)) {
716                       Debug( LDAP_DEBUG_ANY,
717                              "%s: line %d: failed to load or initialize module %s\n",
718                              fname, lineno, cargv[1]);
719                       exit( EXIT_FAILURE );
720                    }
721                 } else if (strcasecmp( cargv[0], "modulepath") == 0 ) {
722                    if ( cargc != 2 ) {
723                       Debug( LDAP_DEBUG_ANY,
724                              "%s: line %d: missing path in \"modulepath <path>\" line\n",
725                              fname, lineno, 0 );
726                       exit( EXIT_FAILURE );
727                    }
728                    if (module_path( cargv[1] )) {
729                       Debug( LDAP_DEBUG_ANY,
730                              "%s: line %d: failed to set module search path to %s\n",
731                              fname, lineno, cargv[1]);
732                       exit( EXIT_FAILURE );
733                    }
734                    
735 #endif /*SLAPD_MODULES*/
736
737 #ifdef HAVE_TLS
738                 } else if ( !strcasecmp( cargv[0], "TLSProtocol" ) ) {
739                         rc = ldap_pvt_tls_set_option( NULL,
740                                                       LDAP_OPT_X_TLS_PROTOCOL,
741                                                       cargv[1] );
742                         if ( rc )
743                                 return rc;
744
745                 } else if ( !strcasecmp( cargv[0], "TLSCipherSuite" ) ) {
746                         rc = ldap_pvt_tls_set_option( NULL,
747                                                       LDAP_OPT_X_TLS_CIPHER_SUITE,
748                                                       cargv[1] );
749                         if ( rc )
750                                 return rc;
751
752                 } else if ( !strcasecmp( cargv[0], "TLSCertificateFile" ) ) {
753                         rc = ldap_pvt_tls_set_option( NULL,
754                                                       LDAP_OPT_X_TLS_CERTFILE,
755                                                       cargv[1] );
756                         if ( rc )
757                                 return rc;
758
759                 } else if ( !strcasecmp( cargv[0], "TLSCertificateKeyFile" ) ) {
760                         rc = ldap_pvt_tls_set_option( NULL,
761                                                       LDAP_OPT_X_TLS_KEYFILE,
762                                                       cargv[1] );
763                         if ( rc )
764                                 return rc;
765
766                 } else if ( !strcasecmp( cargv[0], "TLSCACertificatePath" ) ) {
767                         rc = ldap_pvt_tls_set_option( NULL,
768                                                       LDAP_OPT_X_TLS_CACERTDIR,
769                                                       cargv[1] );
770                         if ( rc )
771                                 return rc;
772
773                 } else if ( !strcasecmp( cargv[0], "TLSCACertificateFile" ) ) {
774                         rc = ldap_pvt_tls_set_option( NULL,
775                                                       LDAP_OPT_X_TLS_CACERTFILE,
776                                                       cargv[1] );
777                         if ( rc )
778                                 return rc;
779                 } else if ( !strcasecmp( cargv[0], "TLSVerifyClient" ) ) {
780                         rc = ldap_pvt_tls_set_option( NULL,
781                                                       LDAP_OPT_X_TLS_REQUIRE_CERT,
782                                                       cargv[1] );
783                         if ( rc )
784                                 return rc;
785
786 #endif
787
788                 /* pass anything else to the current backend info/db config routine */
789                 } else {
790                         if ( bi != NULL ) {
791                                 if ( bi->bi_config == 0 ) {
792                                         Debug( LDAP_DEBUG_ANY,
793 "%s: line %d: unknown directive \"%s\" inside backend info definition (ignored)\n",
794                                                 fname, lineno, cargv[0] );
795                                 } else {
796                                         if ( (*bi->bi_config)( bi, fname, lineno, cargc, cargv )
797                                                 != 0 )
798                                         {
799                                                 return( 1 );
800                                         }
801                                 }
802                         } else if ( be != NULL ) {
803                                 if ( be->be_config == 0 ) {
804                                         Debug( LDAP_DEBUG_ANY,
805 "%s: line %d: unknown directive \"%s\" inside backend database definition (ignored)\n",
806                                         fname, lineno, cargv[0] );
807                                 } else {
808                                         if ( (*be->be_config)( be, fname, lineno, cargc, cargv )
809                                                 != 0 )
810                                         {
811                                                 return( 1 );
812                                         }
813                                 }
814                         } else {
815                                 Debug( LDAP_DEBUG_ANY,
816 "%s: line %d: unknown directive \"%s\" outside backend info and database definitions (ignored)\n",
817                                     fname, lineno, cargv[0] );
818                         }
819                 }
820                 free( saveline );
821         }
822         fclose( fp );
823         return( 0 );
824 }
825
826 static int
827 fp_parse_line(
828     char        *line,
829     int         *argcp,
830     char        **argv
831 )
832 {
833         char *  token;
834
835         *argcp = 0;
836         for ( token = strtok_quote( line, " \t" ); token != NULL;
837             token = strtok_quote( NULL, " \t" ) ) {
838                 if ( *argcp == MAXARGS ) {
839                         Debug( LDAP_DEBUG_ANY, "Too many tokens (max %d)\n",
840                             MAXARGS, 0, 0 );
841                         return( 1 );
842                 }
843                 argv[(*argcp)++] = token;
844         }
845         argv[*argcp] = NULL;
846         return 0;
847 }
848
849 static char *
850 strtok_quote( char *line, char *sep )
851 {
852         int             inquote;
853         char            *tmp;
854         static char     *next;
855
856         if ( line != NULL ) {
857                 next = line;
858         }
859         while ( *next && strchr( sep, *next ) ) {
860                 next++;
861         }
862
863         if ( *next == '\0' ) {
864                 next = NULL;
865                 return( NULL );
866         }
867         tmp = next;
868
869         for ( inquote = 0; *next; ) {
870                 switch ( *next ) {
871                 case '"':
872                         if ( inquote ) {
873                                 inquote = 0;
874                         } else {
875                                 inquote = 1;
876                         }
877                         SAFEMEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
878                         break;
879
880                 case '\\':
881                         if ( next[1] )
882                                 SAFEMEMCPY( next,
883                                             next + 1, strlen( next + 1 ) + 1 );
884                         next++;         /* dont parse the escaped character */
885                         break;
886
887                 default:
888                         if ( ! inquote ) {
889                                 if ( strchr( sep, *next ) != NULL ) {
890                                         *next++ = '\0';
891                                         return( tmp );
892                                 }
893                         }
894                         next++;
895                         break;
896                 }
897         }
898
899         return( tmp );
900 }
901
902 static char     buf[BUFSIZ];
903 static char     *line;
904 static int      lmax, lcur;
905
906 #define CATLINE( buf )  { \
907         int     len; \
908         len = strlen( buf ); \
909         while ( lcur + len + 1 > lmax ) { \
910                 lmax += BUFSIZ; \
911                 line = (char *) ch_realloc( line, lmax ); \
912         } \
913         strcpy( line + lcur, buf ); \
914         lcur += len; \
915 }
916
917 static char *
918 fp_getline( FILE *fp, int *lineno )
919 {
920         char            *p;
921
922         lcur = 0;
923         CATLINE( buf );
924         (*lineno)++;
925
926         /* hack attack - keeps us from having to keep a stack of bufs... */
927         if ( strncasecmp( line, "include", 7 ) == 0 ) {
928                 buf[0] = '\0';
929                 return( line );
930         }
931
932         while ( fgets( buf, sizeof(buf), fp ) != NULL ) {
933                 if ( (p = strchr( buf, '\n' )) != NULL ) {
934                         *p = '\0';
935                 }
936                 if ( ! isspace( (unsigned char) buf[0] ) ) {
937                         return( line );
938                 }
939
940                 CATLINE( buf );
941                 (*lineno)++;
942         }
943         buf[0] = '\0';
944
945         return( line[0] ? line : NULL );
946 }
947
948 static void
949 fp_getline_init( int *lineno )
950 {
951         *lineno = -1;
952         buf[0] = '\0';
953 }