]> git.sur5r.net Git - openldap/blob - servers/slapd/config.c
a95f014157e458544a74d59ce276d926b9a4ea44
[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], "tls_authc" ) == 0 ) {
580                                         disallows |= SLAP_DISALLOW_TLS_AUTHC;
581
582                                 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
583                                         Debug( LDAP_DEBUG_ANY,
584                     "%s: line %d: unknown feature %s in \"disallow <features>\" line\n",
585                                             fname, lineno, cargv[i] );
586                                         return( 1 );
587                                 }
588                         }
589
590                         global_disallows = disallows;
591
592                 /* require these features */
593                 } else if ( strcasecmp( cargv[0], "requires" ) == 0 ||
594                         strcasecmp( cargv[0], "require" ) == 0 )
595                 {
596                         slap_mask_t     requires;
597
598                         if ( cargc < 2 ) {
599                                 Debug( LDAP_DEBUG_ANY,
600             "%s: line %d: missing feature(s) in \"require <features>\" line\n",
601                                     fname, lineno, 0 );
602                                 return( 1 );
603                         }
604
605                         requires = 0;
606
607                         for( i=1; i < cargc; i++ ) {
608                                 if( strcasecmp( cargv[i], "bind" ) == 0 ) {
609                                         requires |= SLAP_REQUIRE_BIND;
610
611                                 } else if( strcasecmp( cargv[i], "LDAPv3" ) == 0 ) {
612                                         requires |= SLAP_REQUIRE_LDAP_V3;
613
614                                 } else if( strcasecmp( cargv[i], "authc" ) == 0 ) {
615                                         requires |= SLAP_REQUIRE_AUTHC;
616
617                                 } else if( strcasecmp( cargv[i], "SASL" ) == 0 ) {
618                                         requires |= SLAP_REQUIRE_SASL;
619
620                                 } else if( strcasecmp( cargv[i], "strong" ) == 0 ) {
621                                         requires |= SLAP_REQUIRE_STRONG;
622
623                                 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
624                                         Debug( LDAP_DEBUG_ANY,
625                     "%s: line %d: unknown feature %s in \"require <features>\" line\n",
626                                             fname, lineno, cargv[i] );
627                                         return( 1 );
628                                 }
629                         }
630
631                         if ( be == NULL ) {
632                                 global_requires = requires;
633                         } else {
634                                 be->be_requires = requires;
635                         }
636
637                 /* required security factors */
638                 } else if ( strcasecmp( cargv[0], "security" ) == 0 ) {
639                         slap_ssf_set_t *set;
640
641                         if ( cargc < 2 ) {
642                                 Debug( LDAP_DEBUG_ANY,
643             "%s: line %d: missing factor(s) in \"security <factors>\" line\n",
644                                     fname, lineno, 0 );
645                                 return( 1 );
646                         }
647
648                         if ( be == NULL ) {
649                                 set = &global_ssf_set;
650                         } else {
651                                 set = &be->be_ssf_set;
652                         }
653
654                         for( i=1; i < cargc; i++ ) {
655                                 if( strncasecmp( cargv[i], "ssf=",
656                                         sizeof("ssf") ) == 0 )
657                                 {
658                                         set->sss_ssf =
659                                                 atoi( &cargv[i][sizeof("ssf")] );
660
661                                 } else if( strncasecmp( cargv[i], "transport=",
662                                         sizeof("transport") ) == 0 )
663                                 {
664                                         set->sss_transport =
665                                                 atoi( &cargv[i][sizeof("transport")] );
666
667                                 } else if( strncasecmp( cargv[i], "tls=",
668                                         sizeof("tls") ) == 0 )
669                                 {
670                                         set->sss_tls =
671                                                 atoi( &cargv[i][sizeof("tls")] );
672
673                                 } else if( strncasecmp( cargv[i], "sasl=",
674                                         sizeof("sasl") ) == 0 )
675                                 {
676                                         set->sss_sasl =
677                                                 atoi( &cargv[i][sizeof("sasl")] );
678
679                                 } else if( strncasecmp( cargv[i], "update_ssf=",
680                                         sizeof("update_ssf") ) == 0 )
681                                 {
682                                         set->sss_update_ssf =
683                                                 atoi( &cargv[i][sizeof("update_ssf")] );
684
685                                 } else if( strncasecmp( cargv[i], "update_transport=",
686                                         sizeof("update_transport") ) == 0 )
687                                 {
688                                         set->sss_update_transport =
689                                                 atoi( &cargv[i][sizeof("update_transport")] );
690
691                                 } else if( strncasecmp( cargv[i], "update_tls=",
692                                         sizeof("update_tls") ) == 0 )
693                                 {
694                                         set->sss_update_tls =
695                                                 atoi( &cargv[i][sizeof("update_tls")] );
696
697                                 } else if( strncasecmp( cargv[i], "update_sasl=",
698                                         sizeof("update_sasl") ) == 0 )
699                                 {
700                                         set->sss_update_sasl =
701                                                 atoi( &cargv[i][sizeof("update_sasl")] );
702
703                                 } else {
704                                         Debug( LDAP_DEBUG_ANY,
705                     "%s: line %d: unknown factor %s in \"security <factors>\" line\n",
706                                             fname, lineno, cargv[i] );
707                                         return( 1 );
708                                 }
709                         }
710
711                 
712                 /* where to send clients when we don't hold it */
713                 } else if ( strcasecmp( cargv[0], "referral" ) == 0 ) {
714                         if ( cargc < 2 ) {
715                                 Debug( LDAP_DEBUG_ANY,
716                     "%s: line %d: missing URL in \"referral <URL>\" line\n",
717                                     fname, lineno, 0 );
718                                 return( 1 );
719                         }
720
721                         vals[0]->bv_val = cargv[1];
722                         vals[0]->bv_len = strlen( vals[0]->bv_val );
723                         value_add( &default_referral, vals );
724
725                 /* specify an Object Identifier macro */
726                 } else if ( strcasecmp( cargv[0], "objectidentifier" ) == 0 ) {
727                         parse_oidm( fname, lineno, cargc, cargv );
728
729                 /* specify an objectclass */
730                 } else if ( strcasecmp( cargv[0], "objectclass" ) == 0 ) {
731                         if ( *cargv[1] == '(' ) {
732                                 char * p;
733                                 p = strchr(saveline,'(');
734                                 parse_oc( fname, lineno, p, cargv );
735                         } else {
736                                 Debug( LDAP_DEBUG_ANY,
737     "%s: line %d: old objectclass format not supported.\n",
738                                     fname, lineno, 0 );
739                         }
740
741                 /* specify an attribute type */
742                 } else if (( strcasecmp( cargv[0], "attributetype" ) == 0 )
743                         || ( strcasecmp( cargv[0], "attribute" ) == 0 ))
744                 {
745                         if ( *cargv[1] == '(' ) {
746                                 char * p;
747                                 p = strchr(saveline,'(');
748                                 parse_at( fname, lineno, p, cargv );
749                         } else {
750                                 Debug( LDAP_DEBUG_ANY,
751     "%s: line %d: old attribute type format not supported.\n",
752                                     fname, lineno, 0 );
753                         }
754
755                 /* turn on/off schema checking */
756                 } else if ( strcasecmp( cargv[0], "schemacheck" ) == 0 ) {
757                         if ( cargc < 2 ) {
758                                 Debug( LDAP_DEBUG_ANY,
759     "%s: line %d: missing on|off in \"schemacheck <on|off>\" line\n",
760                                     fname, lineno, 0 );
761                                 return( 1 );
762                         }
763                         if ( strcasecmp( cargv[1], "off" ) == 0 ) {
764                                 global_schemacheck = 0;
765                         } else {
766                                 global_schemacheck = 1;
767                         }
768
769                 /* specify access control info */
770                 } else if ( strcasecmp( cargv[0], "access" ) == 0 ) {
771                         parse_acl( be, fname, lineno, cargc, cargv );
772
773                 /* specify default access control info */
774                 } else if ( strcasecmp( cargv[0], "defaultaccess" ) == 0 ) {
775                         slap_access_t access;
776
777                         if ( cargc < 2 ) {
778                                 Debug( LDAP_DEBUG_ANY,
779             "%s: line %d: missing limit in \"defaultaccess <access>\" line\n",
780                                     fname, lineno, 0 );
781                                 return( 1 );
782                         }
783
784                         access = str2access( cargv[1] );
785
786                         if ( access == ACL_INVALID_ACCESS ) {
787                                 Debug( LDAP_DEBUG_ANY,
788                                         "%s: line %d: bad access level \"%s\", "
789                                         "expecting none|auth|compare|search|read|write\n",
790                                     fname, lineno, cargv[1] );
791                                 return( 1 );
792                         }
793
794                         if ( be == NULL ) {
795                                 global_default_access = access;
796                         } else {
797                                 be->be_dfltaccess = access;
798                         }
799
800                 /* debug level to log things to syslog */
801                 } else if ( strcasecmp( cargv[0], "loglevel" ) == 0 ) {
802                         if ( cargc < 2 ) {
803                                 Debug( LDAP_DEBUG_ANY,
804                     "%s: line %d: missing level in \"loglevel <level>\" line\n",
805                                     fname, lineno, 0 );
806                                 return( 1 );
807                         }
808
809                         ldap_syslog = 0;
810
811                         for( i=1; i < cargc; i++ ) {
812                                 ldap_syslog += atoi( cargv[1] );
813                         }
814
815                 /* list of replicas of the data in this backend (master only) */
816                 } else if ( strcasecmp( cargv[0], "replica" ) == 0 ) {
817                         if ( cargc < 2 ) {
818                                 Debug( LDAP_DEBUG_ANY,
819             "%s: line %d: missing host in \"replica <host[:port]>\" line\n",
820                                     fname, lineno, 0 );
821                                 return( 1 );
822                         }
823                         if ( be == NULL ) {
824                                 Debug( LDAP_DEBUG_ANY,
825 "%s: line %d: replica line must appear inside a database definition (ignored)\n",
826                                     fname, lineno, 0 );
827                         } else {
828                                 for ( i = 1; i < cargc; i++ ) {
829                                         if ( strncasecmp( cargv[i], "host=", 5 )
830                                             == 0 ) {
831                                                 charray_add( &be->be_replica,
832                                                              cargv[i] + 5 );
833                                                 break;
834                                         }
835                                 }
836                                 if ( i == cargc ) {
837                                         Debug( LDAP_DEBUG_ANY,
838                     "%s: line %d: missing host in \"replica\" line (ignored)\n",
839                                             fname, lineno, 0 );
840                                 }
841                         }
842
843                 /* dn of master entity allowed to write to replica */
844                 } else if ( strcasecmp( cargv[0], "updatedn" ) == 0 ) {
845                         if ( cargc < 2 ) {
846                                 Debug( LDAP_DEBUG_ANY,
847                     "%s: line %d: missing dn in \"updatedn <dn>\" line\n",
848                                     fname, lineno, 0 );
849                                 return( 1 );
850                         }
851                         if ( be == NULL ) {
852                                 Debug( LDAP_DEBUG_ANY,
853 "%s: line %d: updatedn line must appear inside a database definition (ignored)\n",
854                                     fname, lineno, 0 );
855                         } else {
856                                 be->be_update_ndn = ch_strdup( cargv[1] );
857                                 if( dn_normalize( be->be_update_ndn ) == NULL ) {
858                                         Debug( LDAP_DEBUG_ANY,
859 "%s: line %d: updatedn DN is invalid\n",
860                                             fname, lineno, 0 );
861                                         return 1;
862                                 }
863                         }
864
865                 } else if ( strcasecmp( cargv[0], "updateref" ) == 0 ) {
866                         if ( cargc < 2 ) {
867                                 Debug( LDAP_DEBUG_ANY,
868                     "%s: line %d: missing dn in \"updateref <ldapurl>\" line\n",
869                                     fname, lineno, 0 );
870                                 return( 1 );
871                         }
872                         if ( be == NULL ) {
873                                 Debug( LDAP_DEBUG_ANY,
874 "%s: line %d: updateref line must appear inside a database definition (ignored)\n",
875                                     fname, lineno, 0 );
876                         } else if ( be->be_update_ndn == NULL ) {
877                                 Debug( LDAP_DEBUG_ANY,
878 "%s: line %d: updateref line must after updatedn (ignored)\n",
879                                     fname, lineno, 0 );
880                         } else {
881                                 vals[0]->bv_val = cargv[1];
882                                 vals[0]->bv_len = strlen( vals[0]->bv_val );
883                                 value_add( &be->be_update_refs, vals );
884                         }
885
886                 /* replication log file to which changes are appended */
887                 } else if ( strcasecmp( cargv[0], "replogfile" ) == 0 ) {
888                         if ( cargc < 2 ) {
889                                 Debug( LDAP_DEBUG_ANY,
890             "%s: line %d: missing dn in \"replogfile <filename>\" line\n",
891                                     fname, lineno, 0 );
892                                 return( 1 );
893                         }
894                         if ( be ) {
895                                 be->be_replogfile = ch_strdup( cargv[1] );
896                         } else {
897                                 replogfile = ch_strdup( cargv[1] );
898                         }
899
900                 /* maintain lastmodified{by,time} attributes */
901                 } else if ( strcasecmp( cargv[0], "lastmod" ) == 0 ) {
902                         if ( cargc < 2 ) {
903                                 Debug( LDAP_DEBUG_ANY,
904             "%s: line %d: missing on|off in \"lastmod <on|off>\" line\n",
905                                     fname, lineno, 0 );
906                                 return( 1 );
907                         }
908                         if ( strcasecmp( cargv[1], "on" ) == 0 ) {
909                                 if ( be )
910                                         be->be_lastmod = ON;
911                                 else
912                                         global_lastmod = ON;
913                         } else {
914                                 if ( be )
915                                         be->be_lastmod = OFF;
916                                 else
917                                         global_lastmod = OFF;
918                         }
919
920                 /* set idle timeout value */
921                 } else if ( strcasecmp( cargv[0], "idletimeout" ) == 0 ) {
922                         int i;
923                         if ( cargc < 2 ) {
924                                 Debug( LDAP_DEBUG_ANY,
925             "%s: line %d: missing timeout value in \"idletimeout <seconds>\" line\n",
926                                     fname, lineno, 0 );
927                                 return( 1 );
928                         }
929
930                         i = atoi( cargv[1] );
931
932                         if( i < 0 ) {
933                                 Debug( LDAP_DEBUG_ANY,
934             "%s: line %d: timeout value (%d) invalid \"idletimeout <seconds>\" line\n",
935                                     fname, lineno, i );
936                                 return( 1 );
937                         }
938
939                         global_idletimeout = i;
940
941                 /* include another config file */
942                 } else if ( strcasecmp( cargv[0], "include" ) == 0 ) {
943                         if ( cargc < 2 ) {
944                                 Debug( LDAP_DEBUG_ANY,
945     "%s: line %d: missing filename in \"include <filename>\" line\n",
946                                     fname, lineno, 0 );
947                                 return( 1 );
948                         }
949                         savefname = ch_strdup( cargv[1] );
950                         savelineno = lineno;
951
952                         if ( read_config( savefname ) != 0 ) {
953                                 return( 1 );
954                         }
955
956                         free( savefname );
957                         lineno = savelineno - 1;
958
959                 /* location of kerberos srvtab file */
960                 } else if ( strcasecmp( cargv[0], "srvtab" ) == 0 ) {
961                         if ( cargc < 2 ) {
962                                 Debug( LDAP_DEBUG_ANY,
963             "%s: line %d: missing filename in \"srvtab <filename>\" line\n",
964                                     fname, lineno, 0 );
965                                 return( 1 );
966                         }
967                         ldap_srvtab = ch_strdup( cargv[1] );
968
969 #ifdef SLAPD_MODULES
970                 } else if (strcasecmp( cargv[0], "moduleload") == 0 ) {
971                    if ( cargc < 2 ) {
972                       Debug( LDAP_DEBUG_ANY,
973                              "%s: line %d: missing filename in \"moduleload <filename>\" line\n",
974                              fname, lineno, 0 );
975                       exit( EXIT_FAILURE );
976                    }
977                    if (module_load(cargv[1], cargc - 2, (cargc > 2) ? cargv + 2 : NULL)) {
978                       Debug( LDAP_DEBUG_ANY,
979                              "%s: line %d: failed to load or initialize module %s\n",
980                              fname, lineno, cargv[1]);
981                       exit( EXIT_FAILURE );
982                    }
983                 } else if (strcasecmp( cargv[0], "modulepath") == 0 ) {
984                    if ( cargc != 2 ) {
985                       Debug( LDAP_DEBUG_ANY,
986                              "%s: line %d: missing path in \"modulepath <path>\" line\n",
987                              fname, lineno, 0 );
988                       exit( EXIT_FAILURE );
989                    }
990                    if (module_path( cargv[1] )) {
991                       Debug( LDAP_DEBUG_ANY,
992                              "%s: line %d: failed to set module search path to %s\n",
993                              fname, lineno, cargv[1]);
994                       exit( EXIT_FAILURE );
995                    }
996                    
997 #endif /*SLAPD_MODULES*/
998
999 #ifdef HAVE_TLS
1000                 } else if ( !strcasecmp( cargv[0], "TLSProtocol" ) ) {
1001                         rc = ldap_pvt_tls_set_option( NULL,
1002                                                       LDAP_OPT_X_TLS_PROTOCOL,
1003                                                       cargv[1] );
1004                         if ( rc )
1005                                 return rc;
1006
1007                 } else if ( !strcasecmp( cargv[0], "TLSCipherSuite" ) ) {
1008                         rc = ldap_pvt_tls_set_option( NULL,
1009                                                       LDAP_OPT_X_TLS_CIPHER_SUITE,
1010                                                       cargv[1] );
1011                         if ( rc )
1012                                 return rc;
1013
1014                 } else if ( !strcasecmp( cargv[0], "TLSCertificateFile" ) ) {
1015                         rc = ldap_pvt_tls_set_option( NULL,
1016                                                       LDAP_OPT_X_TLS_CERTFILE,
1017                                                       cargv[1] );
1018                         if ( rc )
1019                                 return rc;
1020
1021                 } else if ( !strcasecmp( cargv[0], "TLSCertificateKeyFile" ) ) {
1022                         rc = ldap_pvt_tls_set_option( NULL,
1023                                                       LDAP_OPT_X_TLS_KEYFILE,
1024                                                       cargv[1] );
1025                         if ( rc )
1026                                 return rc;
1027
1028                 } else if ( !strcasecmp( cargv[0], "TLSCACertificatePath" ) ) {
1029                         rc = ldap_pvt_tls_set_option( NULL,
1030                                                       LDAP_OPT_X_TLS_CACERTDIR,
1031                                                       cargv[1] );
1032                         if ( rc )
1033                                 return rc;
1034
1035                 } else if ( !strcasecmp( cargv[0], "TLSCACertificateFile" ) ) {
1036                         rc = ldap_pvt_tls_set_option( NULL,
1037                                                       LDAP_OPT_X_TLS_CACERTFILE,
1038                                                       cargv[1] );
1039                         if ( rc )
1040                                 return rc;
1041                 } else if ( !strcasecmp( cargv[0], "TLSVerifyClient" ) ) {
1042                         rc = ldap_pvt_tls_set_option( NULL,
1043                                                       LDAP_OPT_X_TLS_REQUIRE_CERT,
1044                                                       cargv[1] );
1045                         if ( rc )
1046                                 return rc;
1047
1048 #endif
1049
1050                 /* pass anything else to the current backend info/db config routine */
1051                 } else {
1052                         if ( bi != NULL ) {
1053                                 if ( bi->bi_config == 0 ) {
1054                                         Debug( LDAP_DEBUG_ANY,
1055 "%s: line %d: unknown directive \"%s\" inside backend info definition (ignored)\n",
1056                                                 fname, lineno, cargv[0] );
1057                                 } else {
1058                                         if ( (*bi->bi_config)( bi, fname, lineno, cargc, cargv )
1059                                                 != 0 )
1060                                         {
1061                                                 return( 1 );
1062                                         }
1063                                 }
1064                         } else if ( be != NULL ) {
1065                                 if ( be->be_config == 0 ) {
1066                                         Debug( LDAP_DEBUG_ANY,
1067 "%s: line %d: unknown directive \"%s\" inside backend database definition (ignored)\n",
1068                                         fname, lineno, cargv[0] );
1069                                 } else {
1070                                         if ( (*be->be_config)( be, fname, lineno, cargc, cargv )
1071                                                 != 0 )
1072                                         {
1073                                                 return( 1 );
1074                                         }
1075                                 }
1076                         } else {
1077                                 Debug( LDAP_DEBUG_ANY,
1078 "%s: line %d: unknown directive \"%s\" outside backend info and database definitions (ignored)\n",
1079                                     fname, lineno, cargv[0] );
1080                         }
1081                 }
1082                 free( saveline );
1083         }
1084         fclose( fp );
1085         return( 0 );
1086 }
1087
1088 static int
1089 fp_parse_line(
1090     char        *line,
1091     int         *argcp,
1092     char        **argv
1093 )
1094 {
1095         char *  token;
1096
1097         *argcp = 0;
1098         for ( token = strtok_quote( line, " \t" ); token != NULL;
1099             token = strtok_quote( NULL, " \t" ) ) {
1100                 if ( *argcp == MAXARGS ) {
1101                         Debug( LDAP_DEBUG_ANY, "Too many tokens (max %d)\n",
1102                             MAXARGS, 0, 0 );
1103                         return( 1 );
1104                 }
1105                 argv[(*argcp)++] = token;
1106         }
1107         argv[*argcp] = NULL;
1108         return 0;
1109 }
1110
1111 static char *
1112 strtok_quote( char *line, char *sep )
1113 {
1114         int             inquote;
1115         char            *tmp;
1116         static char     *next;
1117
1118         if ( line != NULL ) {
1119                 next = line;
1120         }
1121         while ( *next && strchr( sep, *next ) ) {
1122                 next++;
1123         }
1124
1125         if ( *next == '\0' ) {
1126                 next = NULL;
1127                 return( NULL );
1128         }
1129         tmp = next;
1130
1131         for ( inquote = 0; *next; ) {
1132                 switch ( *next ) {
1133                 case '"':
1134                         if ( inquote ) {
1135                                 inquote = 0;
1136                         } else {
1137                                 inquote = 1;
1138                         }
1139                         AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
1140                         break;
1141
1142                 case '\\':
1143                         if ( next[1] )
1144                                 AC_MEMCPY( next,
1145                                             next + 1, strlen( next + 1 ) + 1 );
1146                         next++;         /* dont parse the escaped character */
1147                         break;
1148
1149                 default:
1150                         if ( ! inquote ) {
1151                                 if ( strchr( sep, *next ) != NULL ) {
1152                                         *next++ = '\0';
1153                                         return( tmp );
1154                                 }
1155                         }
1156                         next++;
1157                         break;
1158                 }
1159         }
1160
1161         return( tmp );
1162 }
1163
1164 static char     buf[BUFSIZ];
1165 static char     *line;
1166 static int      lmax, lcur;
1167
1168 #define CATLINE( buf )  { \
1169         int     len; \
1170         len = strlen( buf ); \
1171         while ( lcur + len + 1 > lmax ) { \
1172                 lmax += BUFSIZ; \
1173                 line = (char *) ch_realloc( line, lmax ); \
1174         } \
1175         strcpy( line + lcur, buf ); \
1176         lcur += len; \
1177 }
1178
1179 static char *
1180 fp_getline( FILE *fp, int *lineno )
1181 {
1182         char            *p;
1183
1184         lcur = 0;
1185         CATLINE( buf );
1186         (*lineno)++;
1187
1188         /* hack attack - keeps us from having to keep a stack of bufs... */
1189         if ( strncasecmp( line, "include", 7 ) == 0 ) {
1190                 buf[0] = '\0';
1191                 return( line );
1192         }
1193
1194         while ( fgets( buf, sizeof(buf), fp ) != NULL ) {
1195                 if ( (p = strchr( buf, '\n' )) != NULL ) {
1196                         *p = '\0';
1197                 }
1198                 if ( ! isspace( (unsigned char) buf[0] ) ) {
1199                         return( line );
1200                 }
1201
1202                 CATLINE( buf );
1203                 (*lineno)++;
1204         }
1205         buf[0] = '\0';
1206
1207         return( line[0] ? line : NULL );
1208 }
1209
1210 static void
1211 fp_getline_init( int *lineno )
1212 {
1213         *lineno = -1;
1214         buf[0] = '\0';
1215 }