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