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