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