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