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