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