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