]> git.sur5r.net Git - openldap/blob - servers/slapd/config.c
unifdef -DSLAPD_SCHEMA_NOT_COMPAT -USLAPD_SCHEMA_COMPAT
[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                                 Debug( LDAP_DEBUG_ANY,
459     "%s: line %d: old objectclass format not supported.\n",
460                                     fname, lineno, 0 );
461                         }
462
463                 /* specify an attribute type */
464                 } else if (( strcasecmp( cargv[0], "attributetype" ) == 0 )
465                         || ( strcasecmp( cargv[0], "attribute" ) == 0 ))
466                 {
467                         if ( *cargv[1] == '(' ) {
468                                 char * p;
469                                 p = strchr(saveline,'(');
470                                 parse_at( fname, lineno, p, cargv );
471                         } else {
472                                 Debug( LDAP_DEBUG_ANY,
473     "%s: line %d: old attribute type format not supported.\n",
474                                     fname, lineno, 0 );
475                         }
476
477                 /* turn on/off schema checking */
478                 } else if ( strcasecmp( cargv[0], "schemacheck" ) == 0 ) {
479                         if ( cargc < 2 ) {
480                                 Debug( LDAP_DEBUG_ANY,
481     "%s: line %d: missing on|off in \"schemacheck <on|off>\" line\n",
482                                     fname, lineno, 0 );
483                                 return( 1 );
484                         }
485                         if ( strcasecmp( cargv[1], "off" ) == 0 ) {
486                                 global_schemacheck = 0;
487                         } else {
488                                 global_schemacheck = 1;
489                         }
490
491                 /* specify access control info */
492                 } else if ( strcasecmp( cargv[0], "access" ) == 0 ) {
493                         parse_acl( be, fname, lineno, cargc, cargv );
494
495                 /* specify default access control info */
496                 } else if ( strcasecmp( cargv[0], "defaultaccess" ) == 0 ) {
497                         slap_access_t access;
498
499                         if ( cargc < 2 ) {
500                                 Debug( LDAP_DEBUG_ANY,
501             "%s: line %d: missing limit in \"defaultaccess <access>\" line\n",
502                                     fname, lineno, 0 );
503                                 return( 1 );
504                         }
505
506                         access = str2access( cargv[1] );
507
508                         if ( access == ACL_INVALID_ACCESS ) {
509                                 Debug( LDAP_DEBUG_ANY,
510                                         "%s: line %d: bad access level \"%s\", "
511                                         "expecting none|auth|compare|search|read|write\n",
512                                     fname, lineno, cargv[1] );
513                                 return( 1 );
514                         }
515
516                         if ( be == NULL ) {
517                                 global_default_access = access;
518                         } else {
519                                 be->be_dfltaccess = access;
520                         }
521
522                 /* debug level to log things to syslog */
523                 } else if ( strcasecmp( cargv[0], "loglevel" ) == 0 ) {
524                         if ( cargc < 2 ) {
525                                 Debug( LDAP_DEBUG_ANY,
526                     "%s: line %d: missing level in \"loglevel <level>\" line\n",
527                                     fname, lineno, 0 );
528                                 return( 1 );
529                         }
530                         ldap_syslog = atoi( cargv[1] );
531
532                 /* list of replicas of the data in this backend (master only) */
533                 } else if ( strcasecmp( cargv[0], "replica" ) == 0 ) {
534                         if ( cargc < 2 ) {
535                                 Debug( LDAP_DEBUG_ANY,
536             "%s: line %d: missing host in \"replica <host[:port]>\" line\n",
537                                     fname, lineno, 0 );
538                                 return( 1 );
539                         }
540                         if ( be == NULL ) {
541                                 Debug( LDAP_DEBUG_ANY,
542 "%s: line %d: replica line must appear inside a database definition (ignored)\n",
543                                     fname, lineno, 0 );
544                         } else {
545                                 for ( i = 1; i < cargc; i++ ) {
546                                         if ( strncasecmp( cargv[i], "host=", 5 )
547                                             == 0 ) {
548                                                 charray_add( &be->be_replica,
549                                                              cargv[i] + 5 );
550                                                 break;
551                                         }
552                                 }
553                                 if ( i == cargc ) {
554                                         Debug( LDAP_DEBUG_ANY,
555                     "%s: line %d: missing host in \"replica\" line (ignored)\n",
556                                             fname, lineno, 0 );
557                                 }
558                         }
559
560                 /* dn of master entity allowed to write to replica */
561                 } else if ( strcasecmp( cargv[0], "updatedn" ) == 0 ) {
562                         if ( cargc < 2 ) {
563                                 Debug( LDAP_DEBUG_ANY,
564                     "%s: line %d: missing dn in \"updatedn <dn>\" line\n",
565                                     fname, lineno, 0 );
566                                 return( 1 );
567                         }
568                         if ( be == NULL ) {
569                                 Debug( LDAP_DEBUG_ANY,
570 "%s: line %d: updatedn line must appear inside a database definition (ignored)\n",
571                                     fname, lineno, 0 );
572                         } else {
573                                 be->be_update_ndn = ch_strdup( cargv[1] );
574                                 if( dn_normalize( be->be_update_ndn ) == NULL ) {
575                                         Debug( LDAP_DEBUG_ANY,
576 "%s: line %d: updatedn DN is invalid\n",
577                                             fname, lineno, 0 );
578                                         return 1;
579                                 }
580                         }
581
582                 } else if ( strcasecmp( cargv[0], "updateref" ) == 0 ) {
583                         if ( cargc < 2 ) {
584                                 Debug( LDAP_DEBUG_ANY,
585                     "%s: line %d: missing dn in \"updateref <ldapurl>\" line\n",
586                                     fname, lineno, 0 );
587                                 return( 1 );
588                         }
589                         if ( be == NULL ) {
590                                 Debug( LDAP_DEBUG_ANY,
591 "%s: line %d: updateref line must appear inside a database definition (ignored)\n",
592                                     fname, lineno, 0 );
593                         } else if ( be->be_update_ndn == NULL ) {
594                                 Debug( LDAP_DEBUG_ANY,
595 "%s: line %d: updateref line must after updatedn (ignored)\n",
596                                     fname, lineno, 0 );
597                         } else {
598                                 vals[0]->bv_val = cargv[1];
599                                 vals[0]->bv_len = strlen( vals[0]->bv_val );
600                                 value_add( &be->be_update_refs, vals );
601                         }
602
603                 /* replication log file to which changes are appended */
604                 } else if ( strcasecmp( cargv[0], "replogfile" ) == 0 ) {
605                         if ( cargc < 2 ) {
606                                 Debug( LDAP_DEBUG_ANY,
607             "%s: line %d: missing dn in \"replogfile <filename>\" line\n",
608                                     fname, lineno, 0 );
609                                 return( 1 );
610                         }
611                         if ( be ) {
612                                 be->be_replogfile = ch_strdup( cargv[1] );
613                         } else {
614                                 replogfile = ch_strdup( cargv[1] );
615                         }
616
617                 /* maintain lastmodified{by,time} attributes */
618                 } else if ( strcasecmp( cargv[0], "lastmod" ) == 0 ) {
619                         if ( cargc < 2 ) {
620                                 Debug( LDAP_DEBUG_ANY,
621             "%s: line %d: missing on|off in \"lastmod <on|off>\" line\n",
622                                     fname, lineno, 0 );
623                                 return( 1 );
624                         }
625                         if ( strcasecmp( cargv[1], "on" ) == 0 ) {
626                                 if ( be )
627                                         be->be_lastmod = ON;
628                                 else
629                                         global_lastmod = ON;
630                         } else {
631                                 if ( be )
632                                         be->be_lastmod = OFF;
633                                 else
634                                         global_lastmod = OFF;
635                         }
636
637                 /* set idle timeout value */
638                 } else if ( strcasecmp( cargv[0], "idletimeout" ) == 0 ) {
639                         int i;
640                         if ( cargc < 2 ) {
641                                 Debug( LDAP_DEBUG_ANY,
642             "%s: line %d: missing timeout value in \"idletimeout <seconds>\" line\n",
643                                     fname, lineno, 0 );
644                                 return( 1 );
645                         }
646
647                         i = atoi( cargv[1] );
648
649                         if( i < 0 ) {
650                                 Debug( LDAP_DEBUG_ANY,
651             "%s: line %d: timeout value (%d) invalid \"idletimeout <seconds>\" line\n",
652                                     fname, lineno, i );
653                                 return( 1 );
654                         }
655
656                         global_idletimeout = i;
657
658                 /* include another config file */
659                 } else if ( strcasecmp( cargv[0], "include" ) == 0 ) {
660                         if ( cargc < 2 ) {
661                                 Debug( LDAP_DEBUG_ANY,
662     "%s: line %d: missing filename in \"include <filename>\" line\n",
663                                     fname, lineno, 0 );
664                                 return( 1 );
665                         }
666                         savefname = ch_strdup( cargv[1] );
667                         savelineno = lineno;
668
669                         if ( read_config( savefname ) != 0 ) {
670                                 return( 1 );
671                         }
672
673                         free( savefname );
674                         lineno = savelineno - 1;
675
676                 /* location of kerberos srvtab file */
677                 } else if ( strcasecmp( cargv[0], "srvtab" ) == 0 ) {
678                         if ( cargc < 2 ) {
679                                 Debug( LDAP_DEBUG_ANY,
680             "%s: line %d: missing filename in \"srvtab <filename>\" line\n",
681                                     fname, lineno, 0 );
682                                 return( 1 );
683                         }
684                         ldap_srvtab = ch_strdup( cargv[1] );
685
686 #ifdef SLAPD_MODULES
687                 } else if (strcasecmp( cargv[0], "moduleload") == 0 ) {
688                    if ( cargc < 2 ) {
689                       Debug( LDAP_DEBUG_ANY,
690                              "%s: line %d: missing filename in \"moduleload <filename>\" line\n",
691                              fname, lineno, 0 );
692                       exit( EXIT_FAILURE );
693                    }
694                    if (module_load(cargv[1], cargc - 2, (cargc > 2) ? cargv + 2 : NULL)) {
695                       Debug( LDAP_DEBUG_ANY,
696                              "%s: line %d: failed to load or initialize module %s\n",
697                              fname, lineno, cargv[1]);
698                       exit( EXIT_FAILURE );
699                    }
700                 } else if (strcasecmp( cargv[0], "modulepath") == 0 ) {
701                    if ( cargc != 2 ) {
702                       Debug( LDAP_DEBUG_ANY,
703                              "%s: line %d: missing path in \"modulepath <path>\" line\n",
704                              fname, lineno, 0 );
705                       exit( EXIT_FAILURE );
706                    }
707                    if (module_path( cargv[1] )) {
708                       Debug( LDAP_DEBUG_ANY,
709                              "%s: line %d: failed to set module search path to %s\n",
710                              fname, lineno, cargv[1]);
711                       exit( EXIT_FAILURE );
712                    }
713                    
714 #endif /*SLAPD_MODULES*/
715
716 #ifdef HAVE_TLS
717                 } else if ( !strcasecmp( cargv[0], "TLSProtocol" ) ) {
718                         rc = ldap_pvt_tls_set_option( NULL,
719                                                       LDAP_OPT_X_TLS_PROTOCOL,
720                                                       cargv[1] );
721                         if ( rc )
722                                 return rc;
723
724                 } else if ( !strcasecmp( cargv[0], "TLSCipherSuite" ) ) {
725                         rc = ldap_pvt_tls_set_option( NULL,
726                                                       LDAP_OPT_X_TLS_CIPHER_SUITE,
727                                                       cargv[1] );
728                         if ( rc )
729                                 return rc;
730
731                 } else if ( !strcasecmp( cargv[0], "TLSCertificateFile" ) ) {
732                         rc = ldap_pvt_tls_set_option( NULL,
733                                                       LDAP_OPT_X_TLS_CERTFILE,
734                                                       cargv[1] );
735                         if ( rc )
736                                 return rc;
737
738                 } else if ( !strcasecmp( cargv[0], "TLSCertificateKeyFile" ) ) {
739                         rc = ldap_pvt_tls_set_option( NULL,
740                                                       LDAP_OPT_X_TLS_KEYFILE,
741                                                       cargv[1] );
742                         if ( rc )
743                                 return rc;
744
745                 } else if ( !strcasecmp( cargv[0], "TLSCACertificatePath" ) ) {
746                         rc = ldap_pvt_tls_set_option( NULL,
747                                                       LDAP_OPT_X_TLS_CACERTDIR,
748                                                       cargv[1] );
749                         if ( rc )
750                                 return rc;
751
752                 } else if ( !strcasecmp( cargv[0], "TLSCACertificateFile" ) ) {
753                         rc = ldap_pvt_tls_set_option( NULL,
754                                                       LDAP_OPT_X_TLS_CACERTFILE,
755                                                       cargv[1] );
756                         if ( rc )
757                                 return rc;
758                 } else if ( !strcasecmp( cargv[0], "TLSVerifyClient" ) ) {
759                         rc = ldap_pvt_tls_set_option( NULL,
760                                                       LDAP_OPT_X_TLS_REQUIRE_CERT,
761                                                       cargv[1] );
762                         if ( rc )
763                                 return rc;
764
765 #endif
766
767                 /* pass anything else to the current backend info/db config routine */
768                 } else {
769                         if ( bi != NULL ) {
770                                 if ( bi->bi_config == 0 ) {
771                                         Debug( LDAP_DEBUG_ANY,
772 "%s: line %d: unknown directive \"%s\" inside backend info definition (ignored)\n",
773                                                 fname, lineno, cargv[0] );
774                                 } else {
775                                         if ( (*bi->bi_config)( bi, fname, lineno, cargc, cargv )
776                                                 != 0 )
777                                         {
778                                                 return( 1 );
779                                         }
780                                 }
781                         } else if ( be != NULL ) {
782                                 if ( be->be_config == 0 ) {
783                                         Debug( LDAP_DEBUG_ANY,
784 "%s: line %d: unknown directive \"%s\" inside backend database definition (ignored)\n",
785                                         fname, lineno, cargv[0] );
786                                 } else {
787                                         if ( (*be->be_config)( be, fname, lineno, cargc, cargv )
788                                                 != 0 )
789                                         {
790                                                 return( 1 );
791                                         }
792                                 }
793                         } else {
794                                 Debug( LDAP_DEBUG_ANY,
795 "%s: line %d: unknown directive \"%s\" outside backend info and database definitions (ignored)\n",
796                                     fname, lineno, cargv[0] );
797                         }
798                 }
799                 free( saveline );
800         }
801         fclose( fp );
802         return( 0 );
803 }
804
805 static int
806 fp_parse_line(
807     char        *line,
808     int         *argcp,
809     char        **argv
810 )
811 {
812         char *  token;
813
814         *argcp = 0;
815         for ( token = strtok_quote( line, " \t" ); token != NULL;
816             token = strtok_quote( NULL, " \t" ) ) {
817                 if ( *argcp == MAXARGS ) {
818                         Debug( LDAP_DEBUG_ANY, "Too many tokens (max %d)\n",
819                             MAXARGS, 0, 0 );
820                         return( 1 );
821                 }
822                 argv[(*argcp)++] = token;
823         }
824         argv[*argcp] = NULL;
825         return 0;
826 }
827
828 static char *
829 strtok_quote( char *line, char *sep )
830 {
831         int             inquote;
832         char            *tmp;
833         static char     *next;
834
835         if ( line != NULL ) {
836                 next = line;
837         }
838         while ( *next && strchr( sep, *next ) ) {
839                 next++;
840         }
841
842         if ( *next == '\0' ) {
843                 next = NULL;
844                 return( NULL );
845         }
846         tmp = next;
847
848         for ( inquote = 0; *next; ) {
849                 switch ( *next ) {
850                 case '"':
851                         if ( inquote ) {
852                                 inquote = 0;
853                         } else {
854                                 inquote = 1;
855                         }
856                         SAFEMEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
857                         break;
858
859                 case '\\':
860                         if ( next[1] )
861                                 SAFEMEMCPY( next,
862                                             next + 1, strlen( next + 1 ) + 1 );
863                         next++;         /* dont parse the escaped character */
864                         break;
865
866                 default:
867                         if ( ! inquote ) {
868                                 if ( strchr( sep, *next ) != NULL ) {
869                                         *next++ = '\0';
870                                         return( tmp );
871                                 }
872                         }
873                         next++;
874                         break;
875                 }
876         }
877
878         return( tmp );
879 }
880
881 static char     buf[BUFSIZ];
882 static char     *line;
883 static int      lmax, lcur;
884
885 #define CATLINE( buf )  { \
886         int     len; \
887         len = strlen( buf ); \
888         while ( lcur + len + 1 > lmax ) { \
889                 lmax += BUFSIZ; \
890                 line = (char *) ch_realloc( line, lmax ); \
891         } \
892         strcpy( line + lcur, buf ); \
893         lcur += len; \
894 }
895
896 static char *
897 fp_getline( FILE *fp, int *lineno )
898 {
899         char            *p;
900
901         lcur = 0;
902         CATLINE( buf );
903         (*lineno)++;
904
905         /* hack attack - keeps us from having to keep a stack of bufs... */
906         if ( strncasecmp( line, "include", 7 ) == 0 ) {
907                 buf[0] = '\0';
908                 return( line );
909         }
910
911         while ( fgets( buf, sizeof(buf), fp ) != NULL ) {
912                 if ( (p = strchr( buf, '\n' )) != NULL ) {
913                         *p = '\0';
914                 }
915                 if ( ! isspace( (unsigned char) buf[0] ) ) {
916                         return( line );
917                 }
918
919                 CATLINE( buf );
920                 (*lineno)++;
921         }
922         buf[0] = '\0';
923
924         return( line[0] ? line : NULL );
925 }
926
927 static void
928 fp_getline_init( int *lineno )
929 {
930         *lineno = -1;
931         buf[0] = '\0';
932 }