]> git.sur5r.net Git - openldap/blob - servers/slapd/config.c
honor signedness
[openldap] / servers / slapd / config.c
1 /* config.c - configuration file handling routines */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 1998-2004 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
17  * All rights reserved.
18  *
19  * Redistribution and use in source and binary forms are permitted
20  * provided that this notice is preserved and that due credit is given
21  * to the University of Michigan at Ann Arbor. The name of the University
22  * may not be used to endorse or promote products derived from this
23  * software without specific prior written permission. This software
24  * is provided ``as is'' without express or implied warranty.
25  */
26
27 #include "portable.h"
28
29 #include <stdio.h>
30
31 #include <ac/string.h>
32 #include <ac/ctype.h>
33 #include <ac/signal.h>
34 #include <ac/socket.h>
35 #include <ac/errno.h>
36
37 #include "ldap_pvt.h"
38 #include "slap.h"
39 #ifdef LDAP_SLAPI
40 #include "slapi/slapi.h"
41 #endif
42 #include "lutil.h"
43
44 #define ARGS_STEP       512
45
46 /*
47  * defaults for various global variables
48  */
49 struct slap_limits_set deflimit = {
50         SLAPD_DEFAULT_TIMELIMIT,        /* backward compatible limits */
51         0,
52
53         SLAPD_DEFAULT_SIZELIMIT,        /* backward compatible limits */
54         0,
55         -1,                             /* no limit on unchecked size */
56         0,                              /* page limit */
57         0,                              /* hide number of entries left */
58         0                               /* number of total entries returned by pagedResults equal to hard limit */
59 };
60
61 AccessControl   *global_acl = NULL;
62 slap_access_t           global_default_access = ACL_READ;
63 slap_mask_t             global_restrictops = 0;
64 slap_mask_t             global_allows = 0;
65 slap_mask_t             global_disallows = 0;
66 slap_mask_t             global_requires = 0;
67 slap_ssf_set_t  global_ssf_set;
68 char            *replogfile;
69 int             global_gentlehup = 0;
70 int             global_idletimeout = 0;
71 char    *global_host = NULL;
72 char    *global_realm = NULL;
73 char            *ldap_srvtab = "";
74 char            **default_passwd_hash = NULL;
75 int             cargc = 0, cargv_size = 0;
76 char    **cargv;
77 struct berval default_search_base = BER_BVNULL;
78 struct berval default_search_nbase = BER_BVNULL;
79 unsigned                num_subordinates = 0;
80 struct berval global_schemadn = BER_BVNULL;
81 struct berval global_schemandn = BER_BVNULL;
82
83 ber_len_t sockbuf_max_incoming = SLAP_SB_MAX_INCOMING_DEFAULT;
84 ber_len_t sockbuf_max_incoming_auth= SLAP_SB_MAX_INCOMING_AUTH;
85
86 int     slap_conn_max_pending = SLAP_CONN_MAX_PENDING_DEFAULT;
87 int     slap_conn_max_pending_auth = SLAP_CONN_MAX_PENDING_AUTH;
88
89 char   *slapd_pid_file  = NULL;
90 char   *slapd_args_file = NULL;
91
92 char   *strtok_quote_ptr;
93
94 int use_reverse_lookup = 0;
95
96 #ifdef LDAP_SLAPI
97 int slapi_plugins_used = 0;
98 #endif
99
100 static char *fp_getline(FILE *fp, int *lineno);
101 static void fp_getline_init(int *lineno);
102 static int fp_parse_line(int lineno, char *line);
103
104 static char     *strtok_quote(char *line, char *sep);
105 static int load_ucdata(char *path);
106
107 static int add_syncrepl LDAP_P(( Backend *, char **, int ));
108 static int parse_syncrepl_line LDAP_P(( char **, int, syncinfo_t *));
109
110 int
111 read_config( const char *fname, int depth )
112 {
113         FILE    *fp;
114         char    *line, *savefname, *saveline;
115         int savelineno;
116         int     lineno, i;
117         int rc;
118         struct berval vals[2];
119         char *replicahost;
120         LDAPURLDesc *ludp;
121         static BackendInfo *bi = NULL;
122         static BackendDB        *be = NULL;
123         char    *next;
124
125
126         vals[1].bv_val = NULL;
127
128         if ( depth == 0 ) {
129                 cargv = ch_calloc( ARGS_STEP + 1, sizeof(*cargv) );
130                 cargv_size = ARGS_STEP + 1;
131         }
132
133         if ( (fp = fopen( fname, "r" )) == NULL ) {
134                 ldap_syslog = 1;
135 #ifdef NEW_LOGGING
136                 LDAP_LOG( CONFIG, ENTRY, 
137                         "read_config: " "could not open config file \"%s\": %s (%d)\n",
138                     fname, strerror(errno), errno );
139 #else
140                 Debug( LDAP_DEBUG_ANY,
141                     "could not open config file \"%s\": %s (%d)\n",
142                     fname, strerror(errno), errno );
143 #endif
144                 return 1;
145         }
146
147 #ifdef NEW_LOGGING
148         LDAP_LOG( CONFIG, ENTRY, 
149                 "read_config: reading config file %s\n", fname, 0, 0 );
150 #else
151         Debug( LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0 );
152 #endif
153
154
155         fp_getline_init( &lineno );
156
157         while ( (line = fp_getline( fp, &lineno )) != NULL ) {
158                 /* skip comments and blank lines */
159                 if ( line[0] == '#' || line[0] == '\0' ) {
160                         continue;
161                 }
162
163                 /* fp_parse_line is destructive, we save a copy */
164                 saveline = ch_strdup( line );
165
166                 if ( fp_parse_line( lineno, line ) != 0 ) {
167                         return( 1 );
168                 }
169
170                 if ( cargc < 1 ) {
171 #ifdef NEW_LOGGING
172                         LDAP_LOG( CONFIG, INFO, 
173                                 "%s: line %d: bad config line (ignored)\n", fname, lineno, 0 );
174 #else
175                         Debug( LDAP_DEBUG_ANY,
176                             "%s: line %d: bad config line (ignored)\n",
177                             fname, lineno, 0 );
178 #endif
179
180                         continue;
181                 }
182
183                 if ( strcasecmp( cargv[0], "backend" ) == 0 ) {
184                         if ( cargc < 2 ) {
185 #ifdef NEW_LOGGING
186                                 LDAP_LOG( CONFIG, CRIT, 
187                                            "%s : line %d: missing type in \"backend\" line.\n",
188                                            fname, lineno, 0 );
189 #else
190                                 Debug( LDAP_DEBUG_ANY,
191                 "%s: line %d: missing type in \"backend <type>\" line\n",
192                                     fname, lineno, 0 );
193 #endif
194
195                                 return( 1 );
196                         }
197
198                         if( be != NULL ) {
199 #ifdef NEW_LOGGING
200                                 LDAP_LOG( CONFIG, CRIT, 
201                                            "%s: line %d: backend line must appear before any "
202                                            "database definition.\n", fname, lineno , 0 );
203 #else
204                                 Debug( LDAP_DEBUG_ANY,
205 "%s: line %d: backend line must appear before any database definition\n",
206                                     fname, lineno, 0 );
207 #endif
208
209                                 return( 1 );
210                         }
211
212                         bi = backend_info( cargv[1] );
213
214                         if( bi == NULL ) {
215 #ifdef NEW_LOGGING
216                                 LDAP_LOG( CONFIG, CRIT, 
217                                            "read_config: backend %s initialization failed.\n",
218                                            cargv[1], 0, 0 );
219 #else
220                                 Debug( LDAP_DEBUG_ANY,
221                                         "backend %s initialization failed.\n",
222                                     cargv[1], 0, 0 );
223 #endif
224
225                                 return( 1 );
226                         }
227                 } else if ( strcasecmp( cargv[0], "database" ) == 0 ) {
228                         if ( cargc < 2 ) {
229 #ifdef NEW_LOGGING
230                                 LDAP_LOG( CONFIG, CRIT, 
231                                         "%s: line %d: missing type in \"database <type>\" line\n",
232                                         fname, lineno, 0 );
233 #else
234                                 Debug( LDAP_DEBUG_ANY,
235                 "%s: line %d: missing type in \"database <type>\" line\n",
236                                     fname, lineno, 0 );
237 #endif
238
239                                 return( 1 );
240                         }
241
242                         bi = NULL;
243                         be = backend_db_init( cargv[1] );
244
245                         if( be == NULL ) {
246 #ifdef NEW_LOGGING
247                                 LDAP_LOG( CONFIG, CRIT, 
248                                         "database %s initialization failed.\n", cargv[1], 0, 0 );
249 #else
250                                 Debug( LDAP_DEBUG_ANY,
251                                         "database %s initialization failed.\n",
252                                     cargv[1], 0, 0 );
253 #endif
254
255                                 return( 1 );
256                         }
257
258                 /* set thread concurrency */
259                 } else if ( strcasecmp( cargv[0], "concurrency" ) == 0 ) {
260                         int c;
261                         if ( cargc < 2 ) {
262 #ifdef NEW_LOGGING
263                                 LDAP_LOG( CONFIG, CRIT, 
264                                         "%s: line %d: missing level in \"concurrency <level>\" "
265                                         " line\n", fname, lineno, 0 );
266 #else
267                                 Debug( LDAP_DEBUG_ANY,
268             "%s: line %d: missing level in \"concurrency <level>\" line\n",
269                                     fname, lineno, 0 );
270 #endif
271
272                                 return( 1 );
273                         }
274
275                         c = strtol( cargv[1], &next, 10 );
276                         if ( next == NULL || next[0] != '\0' ) {
277 #ifdef NEW_LOGGING
278                                 LDAP_LOG( CONFIG, CRIT, 
279                                         "%s: line %d: unable to parse level \"%s\" in \"concurrency <level>\" "
280                                         " line\n", fname, lineno, cargv[1] );
281 #else
282                                 Debug( LDAP_DEBUG_ANY,
283             "%s: line %d: unable to parse level \"%s\" in \"concurrency <level>\" line\n",
284                                     fname, lineno, cargv[1] );
285 #endif
286                                 return( 1 );
287                         }
288
289                         if( c < 1 ) {
290 #ifdef NEW_LOGGING
291                                 LDAP_LOG( CONFIG, CRIT, 
292                                         "%s: line %d: invalid level (%d) in "
293                                         "\"concurrency <level>\" line.\n", fname, lineno, c );
294 #else
295                                 Debug( LDAP_DEBUG_ANY,
296             "%s: line %d: invalid level (%d) in \"concurrency <level>\" line\n",
297                                     fname, lineno, c );
298 #endif
299
300                                 return( 1 );
301                         }
302
303                         ldap_pvt_thread_set_concurrency( c );
304
305                 /* set sockbuf max */
306                 } else if ( strcasecmp( cargv[0], "sockbuf_max_incoming" ) == 0 ) {
307                         long max;
308                         if ( cargc < 2 ) {
309 #ifdef NEW_LOGGING
310                                 LDAP_LOG( CONFIG, CRIT, 
311                                    "%s: line %d: missing max in \"sockbuf_max_incoming "
312                                    "<bytes>\" line\n", fname, lineno, 0 );
313 #else
314                                 Debug( LDAP_DEBUG_ANY,
315                                            "%s: line %d: missing max in \"sockbuf_max_incoming <bytes>\" line\n",
316                                     fname, lineno, 0 );
317 #endif
318
319                                 return( 1 );
320                         }
321
322                         max = atol( cargv[1] );
323
324                         if( max < 0 ) {
325 #ifdef NEW_LOGGING
326                                 LDAP_LOG( CONFIG, CRIT, 
327                                            "%s: line %d: invalid max value (%ld) in "
328                                            "\"sockbuf_max_incoming <bytes>\" line.\n",
329                                            fname, lineno, max );
330 #else
331                                 Debug( LDAP_DEBUG_ANY,
332                                         "%s: line %d: invalid max value (%ld) in "
333                                         "\"sockbuf_max_incoming <bytes>\" line.\n",
334                                     fname, lineno, max );
335 #endif
336
337                                 return( 1 );
338                         }
339
340                         sockbuf_max_incoming = max;
341
342                 /* set sockbuf max authenticated */
343                 } else if ( strcasecmp( cargv[0], "sockbuf_max_incoming_auth" ) == 0 ) {
344                         long max;
345                         if ( cargc < 2 ) {
346 #ifdef NEW_LOGGING
347                                 LDAP_LOG( CONFIG, CRIT, 
348                                    "%s: line %d: missing max in \"sockbuf_max_incoming_auth "
349                                    "<bytes>\" line\n", fname, lineno, 0 );
350 #else
351                                 Debug( LDAP_DEBUG_ANY,
352                                            "%s: line %d: missing max in \"sockbuf_max_incoming_auth <bytes>\" line\n",
353                                     fname, lineno, 0 );
354 #endif
355
356                                 return( 1 );
357                         }
358
359                         max = atol( cargv[1] );
360
361                         if( max < 0 ) {
362 #ifdef NEW_LOGGING
363                                 LDAP_LOG( CONFIG, CRIT, 
364                                            "%s: line %d: invalid max value (%ld) in "
365                                            "\"sockbuf_max_incoming_auth <bytes>\" line.\n",
366                                            fname, lineno, max );
367 #else
368                                 Debug( LDAP_DEBUG_ANY,
369                                         "%s: line %d: invalid max value (%ld) in "
370                                         "\"sockbuf_max_incoming_auth <bytes>\" line.\n",
371                                     fname, lineno, max );
372 #endif
373
374                                 return( 1 );
375                         }
376
377                         sockbuf_max_incoming_auth = max;
378
379                 /* set conn pending max */
380                 } else if ( strcasecmp( cargv[0], "conn_max_pending" ) == 0 ) {
381                         long max;
382                         if ( cargc < 2 ) {
383 #ifdef NEW_LOGGING
384                                 LDAP_LOG( CONFIG, CRIT, 
385                                    "%s: line %d: missing max in \"conn_max_pending "
386                                    "<requests>\" line\n", fname, lineno, 0 );
387 #else
388                                 Debug( LDAP_DEBUG_ANY,
389                                            "%s: line %d: missing max in \"conn_max_pending <requests>\" line\n",
390                                     fname, lineno, 0 );
391 #endif
392
393                                 return( 1 );
394                         }
395
396                         max = atol( cargv[1] );
397
398                         if( max < 0 ) {
399 #ifdef NEW_LOGGING
400                                 LDAP_LOG( CONFIG, CRIT, 
401                                            "%s: line %d: invalid max value (%ld) in "
402                                            "\"conn_max_pending <requests>\" line.\n",
403                                            fname, lineno, max );
404 #else
405                                 Debug( LDAP_DEBUG_ANY,
406                                         "%s: line %d: invalid max value (%ld) in "
407                                         "\"conn_max_pending <requests>\" line.\n",
408                                     fname, lineno, max );
409 #endif
410
411                                 return( 1 );
412                         }
413
414                         slap_conn_max_pending = max;
415
416                 /* set conn pending max authenticated */
417                 } else if ( strcasecmp( cargv[0], "conn_max_pending_auth" ) == 0 ) {
418                         long max;
419                         if ( cargc < 2 ) {
420 #ifdef NEW_LOGGING
421                                 LDAP_LOG( CONFIG, CRIT, 
422                                    "%s: line %d: missing max in \"conn_max_pending_auth "
423                                    "<requests>\" line\n", fname, lineno, 0 );
424 #else
425                                 Debug( LDAP_DEBUG_ANY,
426                                            "%s: line %d: missing max in \"conn_max_pending_auth <requests>\" line\n",
427                                     fname, lineno, 0 );
428 #endif
429
430                                 return( 1 );
431                         }
432
433                         max = atol( cargv[1] );
434
435                         if( max < 0 ) {
436 #ifdef NEW_LOGGING
437                                 LDAP_LOG( CONFIG, CRIT, 
438                                            "%s: line %d: invalid max value (%ld) in "
439                                            "\"conn_max_pending_auth <requests>\" line.\n",
440                                            fname, lineno, max );
441 #else
442                                 Debug( LDAP_DEBUG_ANY,
443                                         "%s: line %d: invalid max value (%ld) in "
444                                         "\"conn_max_pending_auth <requests>\" line.\n",
445                                     fname, lineno, max );
446 #endif
447
448                                 return( 1 );
449                         }
450
451                         slap_conn_max_pending_auth = max;
452
453                 /* default search base */
454                 } else if ( strcasecmp( cargv[0], "defaultSearchBase" ) == 0 ) {
455                         if ( cargc < 2 ) {
456 #ifdef NEW_LOGGING
457                                 LDAP_LOG( CONFIG, CRIT, 
458                                         "%s: line %d: missing dn in \"defaultSearchBase <dn\" "
459                                         "line\n", fname, lineno, 0 );
460 #else
461                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
462                                         "missing dn in \"defaultSearchBase <dn>\" line\n",
463                                         fname, lineno, 0 );
464 #endif
465
466                                 return 1;
467
468                         } else if ( cargc > 2 ) {
469 #ifdef NEW_LOGGING
470                                 LDAP_LOG( CONFIG, INFO, 
471                                         "%s: line %d: extra cruft after <dn> in "
472                                         "\"defaultSearchBase %s\" line (ignored)\n",
473                                         fname, lineno, cargv[1] );
474 #else
475                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
476                                         "extra cruft after <dn> in \"defaultSearchBase %s\", "
477                                         "line (ignored)\n",
478                                         fname, lineno, cargv[1] );
479 #endif
480                         }
481
482                         if ( bi != NULL || be != NULL ) {
483 #ifdef NEW_LOGGING
484                                 LDAP_LOG( CONFIG, CRIT, 
485                                         "%s: line %d: defaultSearchBase line must appear "
486                                         "prior to any backend or database definitions\n",
487                                         fname, lineno, 0 );
488 #else
489                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
490                                         "defaultSearchBaase line must appear prior to "
491                                         "any backend or database definition\n",
492                                     fname, lineno, 0 );
493 #endif
494
495                                 return 1;
496                         }
497
498                         if ( default_search_nbase.bv_len ) {
499 #ifdef NEW_LOGGING
500                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
501                                         "default search base \"%s\" already defined "
502                                         "(discarding old)\n", fname, lineno,
503                                         default_search_base.bv_val );
504 #else
505                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
506                                         "default search base \"%s\" already defined "
507                                         "(discarding old)\n",
508                                         fname, lineno, default_search_base.bv_val );
509 #endif
510
511                                 free( default_search_base.bv_val );
512                                 free( default_search_nbase.bv_val );
513                         }
514
515                         if ( load_ucdata( NULL ) < 0 ) return 1;
516
517                         {
518                                 struct berval dn;
519
520                                 dn.bv_val = cargv[1];
521                                 dn.bv_len = strlen( dn.bv_val );
522
523                                 rc = dnPrettyNormal( NULL, &dn,
524                                         &default_search_base,
525                                         &default_search_nbase, NULL );
526
527                                 if( rc != LDAP_SUCCESS ) {
528 #ifdef NEW_LOGGING
529                                         LDAP_LOG( CONFIG, CRIT, 
530                                                 "%s: line %d: defaultSearchBase DN is invalid.\n",
531                                                 fname, lineno, 0 );
532 #else
533                                         Debug( LDAP_DEBUG_ANY,
534                                                 "%s: line %d: defaultSearchBase DN is invalid\n",
535                                            fname, lineno, 0 );
536 #endif
537                                         return( 1 );
538                                 }
539                         }
540
541                 /* set maximum threads in thread pool */
542                 } else if ( strcasecmp( cargv[0], "threads" ) == 0 ) {
543                         int c;
544                         if ( cargc < 2 ) {
545 #ifdef NEW_LOGGING
546                                 LDAP_LOG( CONFIG, CRIT, 
547                                         "%s: line %d: missing count in \"threads <count>\" line\n",
548                                         fname, lineno, 0 );
549 #else
550                                 Debug( LDAP_DEBUG_ANY,
551             "%s: line %d: missing count in \"threads <count>\" line\n",
552                                     fname, lineno, 0 );
553 #endif
554
555                                 return( 1 );
556                         }
557
558                         c = strtol( cargv[1], &next, 10 );
559                         if (next == NULL || next[0] != '\0' ) {
560 #ifdef NEW_LOGGING
561                                 LDAP_LOG( CONFIG, CRIT, 
562                                         "%s: line %d: unable to parse count \"%s\" in \"threads <count>\" line\n",
563                                         fname, lineno, cargv[1] );
564 #else
565                                 Debug( LDAP_DEBUG_ANY,
566             "%s: line %d: unable to parse count \"%s\" in \"threads <count>\" line\n",
567                                     fname, lineno, cargv[1] );
568 #endif
569                                 return( 1 );
570                         }
571
572                         if( c < 0 ) {
573 #ifdef NEW_LOGGING
574                                 LDAP_LOG( CONFIG, CRIT, 
575                                            "%s: line %d: invalid level (%d) in \"threads <count>\""
576                                            "line\n", fname, lineno, c );
577 #else
578                                 Debug( LDAP_DEBUG_ANY,
579             "%s: line %d: invalid level (%d) in \"threads <count>\" line\n",
580                                     fname, lineno, c );
581 #endif
582
583                                 return( 1 );
584                         }
585
586                         ldap_pvt_thread_pool_maxthreads( &connection_pool, c );
587
588                         /* save for later use */
589                         connection_pool_max = c;
590
591                 /* get pid file name */
592                 } else if ( strcasecmp( cargv[0], "pidfile" ) == 0 ) {
593                         if ( cargc < 2 ) {
594 #ifdef NEW_LOGGING
595                                 LDAP_LOG( CONFIG, CRIT, 
596                                         "%s: line %d missing file name in \"pidfile <file>\" "
597                                         "line.\n", fname, lineno, 0 );
598 #else
599                                 Debug( LDAP_DEBUG_ANY,
600             "%s: line %d: missing file name in \"pidfile <file>\" line\n",
601                                     fname, lineno, 0 );
602 #endif
603
604                                 return( 1 );
605                         }
606
607                         slapd_pid_file = ch_strdup( cargv[1] );
608
609                 /* get args file name */
610                 } else if ( strcasecmp( cargv[0], "argsfile" ) == 0 ) {
611                         if ( cargc < 2 ) {
612 #ifdef NEW_LOGGING
613                                 LDAP_LOG( CONFIG, CRIT, 
614                                            "%s: %d: missing file name in "
615                                            "\"argsfile <file>\" line.\n",
616                                            fname, lineno, 0 );
617 #else
618                                 Debug( LDAP_DEBUG_ANY,
619             "%s: line %d: missing file name in \"argsfile <file>\" line\n",
620                                     fname, lineno, 0 );
621 #endif
622
623                                 return( 1 );
624                         }
625
626                         slapd_args_file = ch_strdup( cargv[1] );
627
628                 } else if ( strcasecmp( cargv[0], "replica-pidfile" ) == 0 ) {
629                         /* ignore */ ;
630
631                 } else if ( strcasecmp( cargv[0], "replica-argsfile" ) == 0 ) {
632                         /* ignore */ ;
633
634                 /* default password hash */
635                 } else if ( strcasecmp( cargv[0], "password-hash" ) == 0 ) {
636                         if ( cargc < 2 ) {
637 #ifdef NEW_LOGGING
638                                 LDAP_LOG( CONFIG, CRIT, 
639                                            "%s: line %d: missing hash in "
640                                            "\"password-hash <hash>\" line.\n",
641                                            fname, lineno, 0 );
642 #else
643                                 Debug( LDAP_DEBUG_ANY,
644             "%s: line %d: missing hash in \"password-hash <hash>\" line\n",
645                                     fname, lineno, 0 );
646 #endif
647
648                                 return( 1 );
649                         }
650                         if ( default_passwd_hash != NULL ) {
651 #ifdef NEW_LOGGING
652                                 LDAP_LOG( CONFIG, CRIT, 
653                                            "%s: line %d: already set default password_hash!\n",
654                                            fname, lineno, 0 );
655 #else
656                                 Debug( LDAP_DEBUG_ANY,
657                                         "%s: line %d: already set default password_hash!\n",
658                                         fname, lineno, 0 );
659 #endif
660
661                                 return 1;
662
663                         }
664                         for(i = 1; i < cargc; i++) {
665                                 if ( lutil_passwd_scheme( cargv[i] ) == 0 ) {
666 #ifdef NEW_LOGGING
667                                         LDAP_LOG( CONFIG, CRIT, 
668                                                 "%s: line %d: password scheme \"%s\" not available\n",
669                                                 fname, lineno, cargv[i] );
670 #else
671                                         Debug( LDAP_DEBUG_ANY,
672                                                 "%s: line %d: password scheme \"%s\" not available\n",
673                                                 fname, lineno, cargv[i] );
674 #endif
675                                 } else {
676                                         ldap_charray_add( &default_passwd_hash, cargv[i] );
677                                 }
678                         }
679                         if( !default_passwd_hash ) {
680 #ifdef NEW_LOGGING
681                                 LDAP_LOG( CONFIG, CRIT, 
682                                         "%s: line %d: no valid hashes found\n",
683                                         fname, lineno, 0 );
684 #else
685                                 Debug( LDAP_DEBUG_ANY,
686                                         "%s: line %d: no valid hashes found\n",
687                                         fname, lineno, 0 );
688                                 return 1;
689 #endif
690                         }
691
692                 } else if ( strcasecmp( cargv[0], "password-crypt-salt-format" ) == 0 ) 
693                 {
694                         if ( cargc < 2 ) {
695 #ifdef NEW_LOGGING
696                                 LDAP_LOG( CONFIG, CRIT, 
697                                         "%s: line %d: missing format in "
698                                         "\"password-crypt-salt-format <format>\" line\n",
699                                         fname, lineno, 0 );
700 #else
701                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: missing format in "
702                                         "\"password-crypt-salt-format <format>\" line\n",
703                                     fname, lineno, 0 );
704 #endif
705
706                                 return 1;
707                         }
708
709                         lutil_salt_format( cargv[1] );
710
711 #ifdef SLAP_AUTH_REWRITE
712                 /* use authid rewrite instead of sasl regexp */
713                 } else if ( strncasecmp( cargv[0], "auth-rewrite",
714                         STRLENOF("auth-rewrite") ) == 0 )
715                 {
716                         int rc = slap_sasl_rewrite_config( fname, lineno,
717                                         cargc, cargv );
718                         if ( rc ) {
719                                 return rc;
720                         }
721 #endif /* SLAP_AUTH_REWRITE */
722
723                 /* Auth + SASL config options */
724                 } else if ( !strncasecmp( cargv[0], "auth", STRLENOF("auth") ) ||
725                         !strncasecmp( cargv[0], "sasl", STRLENOF("sasl") ))
726                 {
727                         if ( slap_sasl_config( cargc, cargv, line, fname, lineno ) )
728                                 return 1;
729
730
731                 } else if ( strcasecmp( cargv[0], "schemadn" ) == 0 ) {
732                         struct berval dn;
733                         if ( cargc < 2 ) {
734 #ifdef NEW_LOGGING
735                                 LDAP_LOG( CONFIG, CRIT, 
736                                            "%s: line %d: missing dn in "
737                                            "\"schemadn <dn>\" line.\n", fname, lineno, 0  );
738 #else
739                                 Debug( LDAP_DEBUG_ANY,
740             "%s: line %d: missing dn in \"schemadn <dn>\" line\n",
741                                     fname, lineno, 0 );
742 #endif
743                                 return 1 ;
744                         }
745                         ber_str2bv( cargv[1], 0, 0, &dn );
746                         if ( be ) {
747                                 rc = dnPrettyNormal( NULL, &dn, &be->be_schemadn,
748                                         &be->be_schemandn, NULL );
749                         } else {
750                                 rc = dnPrettyNormal( NULL, &dn, &global_schemadn,
751                                         &global_schemandn, NULL );
752                         }
753                         if ( rc != LDAP_SUCCESS ) {
754 #ifdef NEW_LOGGING
755                                 LDAP_LOG( CONFIG, CRIT, 
756                                         "%s: line %d: schemadn DN is invalid.\n",
757                                         fname, lineno , 0 );
758 #else
759                                 Debug( LDAP_DEBUG_ANY,
760                                         "%s: line %d: schemadn DN is invalid\n",
761                                         fname, lineno, 0 );
762 #endif
763                                 return 1;
764                         }
765
766                 /* set UCDATA path */
767                 } else if ( strcasecmp( cargv[0], "ucdata-path" ) == 0 ) {
768                         int err;
769                         if ( cargc < 2 ) {
770 #ifdef NEW_LOGGING
771                                 LDAP_LOG( CONFIG, CRIT, 
772                                            "%s: line %d: missing path in "
773                                            "\"ucdata-path <path>\" line.\n", fname, lineno, 0  );
774 #else
775                                 Debug( LDAP_DEBUG_ANY,
776             "%s: line %d: missing path in \"ucdata-path <path>\" line\n",
777                                     fname, lineno, 0 );
778 #endif
779
780                                 return( 1 );
781                         }
782
783                         err = load_ucdata( cargv[1] );
784                         if ( err <= 0 ) {
785                                 if ( err == 0 ) {
786 #ifdef NEW_LOGGING
787                                         LDAP_LOG( CONFIG, CRIT, 
788                                                    "%s: line %d: ucdata already loaded, ucdata-path "
789                                                    "must be set earlier in the file and/or be "
790                                                    "specified only once!\n", fname, lineno, 0 );
791 #else
792                                         Debug( LDAP_DEBUG_ANY,
793                                                "%s: line %d: ucdata already loaded, ucdata-path must be set earlier in the file and/or be specified only once!\n",
794                                                fname, lineno, 0 );
795 #endif
796
797                                 }
798                                 return( 1 );
799                         }
800
801                 /* set size limit */
802                 } else if ( strcasecmp( cargv[0], "sizelimit" ) == 0 ) {
803                         int rc = 0, i;
804                         struct slap_limits_set *lim;
805                         
806                         if ( cargc < 2 ) {
807 #ifdef NEW_LOGGING
808                                 LDAP_LOG( CONFIG, CRIT, 
809                                    "%s: line %d: missing limit in \"sizelimit <limit>\" "
810                                    "line.\n", fname, lineno, 0 );
811 #else
812                                 Debug( LDAP_DEBUG_ANY,
813             "%s: line %d: missing limit in \"sizelimit <limit>\" line\n",
814                                     fname, lineno, 0 );
815 #endif
816
817                                 return( 1 );
818                         }
819
820                         if ( be == NULL ) {
821                                 lim = &deflimit;
822                         } else {
823                                 lim = &be->be_def_limit;
824                         }
825
826                         for ( i = 1; i < cargc; i++ ) {
827                                 if ( strncasecmp( cargv[i], "size", 4 ) == 0 ) {
828                                         rc = limits_parse_one( cargv[i], lim );
829                                         if ( rc ) {
830 #ifdef NEW_LOGGING
831                                                 LDAP_LOG( CONFIG, CRIT, 
832                                                         "%s: line %d: unable "
833                                                            "to parse value \"%s\" in \"sizelimit "
834                                                            "<limit>\" line.\n", fname, lineno, cargv[i] );
835 #else
836                                                 Debug( LDAP_DEBUG_ANY,
837                                                         "%s: line %d: unable "
838                                                         "to parse value \"%s\" "
839                                                         "in \"sizelimit "
840                                                         "<limit>\" line\n",
841                                                         fname, lineno, cargv[i] );
842 #endif
843                                                 return( 1 );
844                                         }
845
846                                 } else {
847                                         if ( strcasecmp( cargv[i], "unlimited" ) == 0 ) {
848                                                 lim->lms_s_soft = -1;
849                                         } else {
850                                                 lim->lms_s_soft = strtol( cargv[i] , &next, 0 );
851                                                 if ( next == cargv[i] ) {
852 #ifdef NEW_LOGGING
853                                                         LDAP_LOG( CONFIG, CRIT, 
854                                                            "%s: line %d: unable to parse limit \"%s\" in \"sizelimit <limit>\" "
855                                                            "line.\n", fname, lineno, cargv[i] );
856 #else
857                                                         Debug( LDAP_DEBUG_ANY,
858                                                             "%s: line %d: unable to parse limit \"%s\" in \"sizelimit <limit>\" line\n",
859                                                             fname, lineno, cargv[i] );
860 #endif
861                                                         return( 1 );
862
863                                                 } else if ( next[0] != '\0' ) {
864 #ifdef NEW_LOGGING
865                                                         LDAP_LOG( CONFIG, CRIT, 
866                                                            "%s: line %d: trailing chars \"%s\" in \"sizelimit <limit>\" "
867                                                            "line ignored.\n", fname, lineno, next );
868 #else
869                                                         Debug( LDAP_DEBUG_ANY,
870                                                             "%s: line %d: trailing chars \"%s\" in \"sizelimit <limit>\" line ignored\n",
871                                                             fname, lineno, next );
872 #endif
873                                                 }
874                                         }
875                                         lim->lms_s_hard = 0;
876                                 }
877                         }
878
879                 /* set time limit */
880                 } else if ( strcasecmp( cargv[0], "timelimit" ) == 0 ) {
881                         int rc = 0, i;
882                         struct slap_limits_set *lim;
883                         
884                         if ( cargc < 2 ) {
885 #ifdef NEW_LOGGING
886                                 LDAP_LOG( CONFIG, CRIT, 
887                                         "%s: line %d missing limit in \"timelimit <limit>\" "
888                                         "line.\n", fname, lineno, 0 );
889 #else
890                                 Debug( LDAP_DEBUG_ANY,
891             "%s: line %d: missing limit in \"timelimit <limit>\" line\n",
892                                     fname, lineno, 0 );
893 #endif
894
895                                 return( 1 );
896                         }
897                         
898                         if ( be == NULL ) {
899                                 lim = &deflimit;
900                         } else {
901                                 lim = &be->be_def_limit;
902                         }
903
904                         for ( i = 1; i < cargc; i++ ) {
905                                 if ( strncasecmp( cargv[i], "time", 4 ) == 0 ) {
906                                         rc = limits_parse_one( cargv[i], lim );
907                                         if ( rc ) {
908 #ifdef NEW_LOGGING
909                                                 LDAP_LOG( CONFIG, CRIT, 
910                                                             "%s: line %d: unable to parse value \"%s\" "
911                                                            "in \"timelimit <limit>\" line.\n",
912                                                            fname, lineno, cargv[i] );
913 #else
914                                                 Debug( LDAP_DEBUG_ANY,
915                                                         "%s: line %d: unable "
916                                                         "to parse value \"%s\" "
917                                                         "in \"timelimit "
918                                                         "<limit>\" line\n",
919                                                         fname, lineno, cargv[i] );
920 #endif
921                                                 return( 1 );
922                                         }
923
924                                 } else {
925                                         if ( strcasecmp( cargv[i], "unlimited" ) == 0 ) {
926                                                 lim->lms_t_soft = -1;
927                                         } else {
928                                                 lim->lms_t_soft = strtol( cargv[i] , &next, 0 );
929                                                 if ( next == cargv[i] ) {
930 #ifdef NEW_LOGGING
931                                                         LDAP_LOG( CONFIG, CRIT, 
932                                                            "%s: line %d: unable to parse limit \"%s\" in \"timelimit <limit>\" "
933                                                            "line.\n", fname, lineno, cargv[i] );
934 #else
935                                                         Debug( LDAP_DEBUG_ANY,
936                                                             "%s: line %d: unable to parse limit \"%s\" in \"timelimit <limit>\" line\n",
937                                                             fname, lineno, cargv[i] );
938 #endif
939                                                         return( 1 );
940
941                                                 } else if ( next[0] != '\0' ) {
942 #ifdef NEW_LOGGING
943                                                         LDAP_LOG( CONFIG, CRIT, 
944                                                            "%s: line %d: trailing chars \"%s\" in \"timelimit <limit>\" "
945                                                            "line ignored.\n", fname, lineno, next );
946 #else
947                                                         Debug( LDAP_DEBUG_ANY,
948                                                             "%s: line %d: trailing chars \"%s\" in \"timelimit <limit>\" line ignored\n",
949                                                             fname, lineno, next );
950 #endif
951                                                 }
952                                         }
953                                         lim->lms_t_hard = 0;
954                                 }
955                         }
956
957                 /* set regex-based limits */
958                 } else if ( strcasecmp( cargv[0], "limits" ) == 0 ) {
959                         if ( be == NULL ) {
960 #ifdef NEW_LOGGING
961                                 LDAP_LOG( CONFIG, WARNING, 
962                                            "%s: line %d \"limits\" allowed only in database "
963                                            "environment.\n", fname, lineno, 0 );
964 #else
965                                 Debug( LDAP_DEBUG_ANY,
966         "%s: line %d \"limits\" allowed only in database environment.\n%s",
967                                         fname, lineno, "" );
968 #endif
969                                 return( 1 );
970                         }
971
972                         if ( limits_parse( be, fname, lineno, cargc, cargv ) ) {
973                                 return( 1 );
974                         }
975
976                 /* mark this as a subordinate database */
977                 } else if ( strcasecmp( cargv[0], "subordinate" ) == 0 ) {
978                         if ( be == NULL ) {
979 #ifdef NEW_LOGGING
980                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
981                                         "subordinate keyword must appear inside a database "
982                                         "definition.\n", fname, lineno, 0 );
983 #else
984                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: subordinate keyword "
985                                         "must appear inside a database definition.\n",
986                                     fname, lineno, 0 );
987 #endif
988                                 return 1;
989
990                         } else {
991                                 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_GLUE_SUBORDINATE;
992                                 num_subordinates++;
993                         }
994
995                 /* add an overlay to this backend */
996                 } else if ( strcasecmp( cargv[0], "overlay" ) == 0 ) {
997                         if ( be == NULL ) {
998 #ifdef NEW_LOGGING
999                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
1000                                         "overlay keyword must appear inside a database "
1001                                         "definition.\n", fname, lineno, 0 );
1002 #else
1003                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: overlay keyword "
1004                                         "must appear inside a database definition.\n",
1005                                     fname, lineno, 0 );
1006 #endif
1007                                 return 1;
1008
1009                         } else {
1010                                 if ( cargv[1][0] == '-' && overlay_config( be, &cargv[1][1] ) ) {
1011                                         /* log error */
1012 #ifdef NEW_LOGGING
1013                                         LDAP_LOG( CONFIG, INFO, "%s: line %d: "
1014                                                 "(optional) overlay \"%s\" configuration "
1015                                                 "failed (ignored)\n", fname, lineno, &cargv[1][1] );
1016 #else
1017                                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1018                                                 "(optional) overlay \"%s\" configuration "
1019                                                 "failed (ignored)\n", fname, lineno, &cargv[1][1] );
1020 #endif
1021                                 } else if ( overlay_config( be, cargv[1] ) ) {
1022                                         return 1;
1023                                 }
1024                         }
1025
1026                 /* set database suffix */
1027                 } else if ( strcasecmp( cargv[0], "suffix" ) == 0 ) {
1028                         Backend *tmp_be;
1029                         struct berval dn, pdn, ndn;
1030
1031                         if ( cargc < 2 ) {
1032 #ifdef NEW_LOGGING
1033                                 LDAP_LOG( CONFIG, CRIT, 
1034                                         "%s: line %d: missing dn in \"suffix <dn>\" line.\n",
1035                                         fname, lineno, 0 );
1036 #else
1037                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1038                                         "missing dn in \"suffix <dn>\" line\n",
1039                                     fname, lineno, 0 );
1040 #endif
1041
1042                                 return( 1 );
1043
1044                         } else if ( cargc > 2 ) {
1045 #ifdef NEW_LOGGING
1046                                 LDAP_LOG( CONFIG, INFO, 
1047                                         "%s: line %d: extra cruft after <dn> in \"suffix %s\""
1048                                         " line (ignored).\n", fname, lineno, cargv[1] );
1049 #else
1050                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: extra cruft "
1051                                         "after <dn> in \"suffix %s\" line (ignored)\n",
1052                                     fname, lineno, cargv[1] );
1053 #endif
1054                         }
1055
1056                         if ( be == NULL ) {
1057 #ifdef NEW_LOGGING
1058                                 LDAP_LOG( CONFIG, INFO, 
1059                                         "%s: line %d: suffix line must appear inside a database "
1060                                         "definition.\n", fname, lineno, 0 );
1061 #else
1062                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix line "
1063                                         "must appear inside a database definition\n",
1064                                     fname, lineno, 0 );
1065 #endif
1066                                 return( 1 );
1067
1068 #if defined(SLAPD_MONITOR_DN)
1069                         /* "cn=Monitor" is reserved for monitoring slap */
1070                         } else if ( strcasecmp( cargv[1], SLAPD_MONITOR_DN ) == 0 ) {
1071 #ifdef NEW_LOGGING
1072                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: \""
1073                                         "%s\" is reserved for monitoring slapd\n", 
1074                                         fname, lineno, SLAPD_MONITOR_DN );
1075 #else
1076                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: \""
1077                                         "%s\" is reserved for monitoring slapd\n", 
1078                                         fname, lineno, SLAPD_MONITOR_DN );
1079 #endif
1080                                 return( 1 );
1081 #endif /* SLAPD_MONITOR_DN */
1082                         }
1083
1084                         if ( load_ucdata( NULL ) < 0 ) return 1;
1085
1086                         dn.bv_val = cargv[1];
1087                         dn.bv_len = strlen( cargv[1] );
1088
1089                         rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
1090                         if( rc != LDAP_SUCCESS ) {
1091 #ifdef NEW_LOGGING
1092                                 LDAP_LOG( CONFIG, CRIT, 
1093                                         "%s: line %d: suffix DN is invalid.\n",
1094                                         fname, lineno, 0 );
1095 #else
1096                                 Debug( LDAP_DEBUG_ANY,
1097                                         "%s: line %d: suffix DN is invalid\n",
1098                                    fname, lineno, 0 );
1099 #endif
1100                                 return( 1 );
1101                         }
1102
1103                         tmp_be = select_backend( &ndn, 0, 0 );
1104                         if ( tmp_be == be ) {
1105 #ifdef NEW_LOGGING
1106                                 LDAP_LOG( CONFIG, INFO, 
1107                                         "%s: line %d: suffix already served by this backend "
1108                                         "(ignored)\n", fname, lineno, 0 );
1109 #else
1110                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix "
1111                                         "already served by this backend (ignored)\n",
1112                                     fname, lineno, 0 );
1113 #endif
1114                                 free( pdn.bv_val );
1115                                 free( ndn.bv_val );
1116
1117                         } else if ( tmp_be  != NULL ) {
1118 #ifdef NEW_LOGGING
1119                                 LDAP_LOG( CONFIG, INFO, 
1120                                         "%s: line %d: suffix already served by a preceding "
1121                                         "backend \"%s\"\n", fname, lineno,
1122                                         tmp_be->be_suffix[0].bv_val );
1123 #else
1124                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix "
1125                                         "already served by a preceeding backend \"%s\"\n",
1126                                     fname, lineno, tmp_be->be_suffix[0].bv_val );
1127 #endif
1128                                 free( pdn.bv_val );
1129                                 free( ndn.bv_val );
1130                                 return( 1 );
1131
1132                         } else if( pdn.bv_len == 0 && default_search_nbase.bv_len ) {
1133 #ifdef NEW_LOGGING
1134                                         LDAP_LOG( CONFIG, INFO, 
1135                                                 "%s: line %d: suffix DN empty and default search "
1136                                                 "base provided \"%s\" (assuming okay).\n",
1137                                                 fname, lineno, default_search_base.bv_val );
1138 #else
1139                                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1140                                                 "suffix DN empty and default "
1141                                                 "search base provided \"%s\" (assuming okay)\n",
1142                                         fname, lineno, default_search_base.bv_val );
1143 #endif
1144                         }
1145
1146                         ber_bvarray_add( &be->be_suffix, &pdn );
1147                         ber_bvarray_add( &be->be_nsuffix, &ndn );
1148
1149                /* set max deref depth */
1150                } else if ( strcasecmp( cargv[0], "maxDerefDepth" ) == 0 ) {
1151                                         int i;
1152                        if ( cargc < 2 ) {
1153 #ifdef NEW_LOGGING
1154                                LDAP_LOG( CONFIG, CRIT, 
1155                                           "%s: line %d: missing depth in \"maxDerefDepth <depth>\""
1156                                           " line\n", fname, lineno, 0 );
1157 #else
1158                                Debug( LDAP_DEBUG_ANY,
1159                    "%s: line %d: missing depth in \"maxDerefDepth <depth>\" line\n",
1160                                    fname, lineno, 0 );
1161 #endif
1162
1163                                return( 1 );
1164                        }
1165                        if ( be == NULL ) {
1166 #ifdef NEW_LOGGING
1167                                LDAP_LOG( CONFIG, INFO, 
1168                                           "%s: line %d: depth line must appear inside a database "
1169                                           "definition.\n", fname, lineno ,0 );
1170 #else
1171                                Debug( LDAP_DEBUG_ANY,
1172 "%s: line %d: depth line must appear inside a database definition.\n",
1173                                    fname, lineno, 0 );
1174 #endif
1175                                 return 1;
1176                        }
1177
1178                        i = strtol( cargv[1], &next, 10 );
1179                        if ( next == NULL || next[0] != '\0' ) {
1180 #ifdef NEW_LOGGING
1181                                LDAP_LOG( CONFIG, INFO, 
1182                                           "%s: line %d: unable to parse depth \"%s\" in \"maxDerefDepth <depth>\" "
1183                                           "line.\n", fname, lineno, cargv[1] );
1184 #else
1185                                Debug( LDAP_DEBUG_ANY,
1186                                           "%s: line %d: unable to parse depth \"%s\" in \"maxDerefDepth <depth>\" "
1187                                           "line.\n", fname, lineno, cargv[1] );
1188 #endif
1189                                 return 1;
1190                        }
1191
1192                        if (i < 0) {
1193 #ifdef NEW_LOGGING
1194                                LDAP_LOG( CONFIG, INFO, 
1195                                           "%s: line %d: depth must be positive.\n",
1196                                           fname, lineno, 0 );
1197 #else
1198                                Debug( LDAP_DEBUG_ANY,
1199 "%s: line %d: depth must be positive.\n",
1200                                    fname, lineno, 0 );
1201 #endif
1202                                 return 1;
1203
1204
1205                        }
1206                        be->be_max_deref_depth = i;
1207
1208                 /* set magic "root" dn for this database */
1209                 } else if ( strcasecmp( cargv[0], "rootdn" ) == 0 ) {
1210                         if ( cargc < 2 ) {
1211 #ifdef NEW_LOGGING
1212                                 LDAP_LOG( CONFIG, INFO, 
1213                                            "%s: line %d: missing dn in \"rootdn <dn>\" line.\n",
1214                                            fname, lineno ,0 );
1215 #else
1216                                 Debug( LDAP_DEBUG_ANY,
1217                     "%s: line %d: missing dn in \"rootdn <dn>\" line\n",
1218                                     fname, lineno, 0 );
1219 #endif
1220
1221                                 return( 1 );
1222                         }
1223
1224                         if ( be == NULL ) {
1225 #ifdef NEW_LOGGING
1226                                 LDAP_LOG( CONFIG, INFO, 
1227                                            "%s: line %d: rootdn line must appear inside a database "
1228                                            "definition.\n", fname, lineno ,0 );
1229 #else
1230                                 Debug( LDAP_DEBUG_ANY,
1231 "%s: line %d: rootdn line must appear inside a database definition.\n",
1232                                     fname, lineno, 0 );
1233 #endif
1234                                 return 1;
1235
1236                         } else {
1237                                 struct berval dn;
1238                                 
1239                                 if ( load_ucdata( NULL ) < 0 ) return 1;
1240
1241                                 dn.bv_val = cargv[1];
1242                                 dn.bv_len = strlen( cargv[1] );
1243
1244                                 rc = dnPrettyNormal( NULL, &dn,
1245                                         &be->be_rootdn,
1246                                         &be->be_rootndn, NULL );
1247
1248                                 if( rc != LDAP_SUCCESS ) {
1249 #ifdef NEW_LOGGING
1250                                         LDAP_LOG( CONFIG, CRIT, 
1251                                                 "%s: line %d: rootdn DN is invalid.\n", 
1252                                                 fname, lineno ,0 );
1253 #else
1254                                         Debug( LDAP_DEBUG_ANY,
1255                                                 "%s: line %d: rootdn DN is invalid\n",
1256                                            fname, lineno, 0 );
1257 #endif
1258                                         return( 1 );
1259                                 }
1260                         }
1261
1262                 /* set super-secret magic database password */
1263                 } else if ( strcasecmp( cargv[0], "rootpw" ) == 0 ) {
1264                         if ( cargc < 2 ) {
1265 #ifdef NEW_LOGGING
1266                                 LDAP_LOG( CONFIG, CRIT, 
1267                                         "%s: line %d: missing passwd in \"rootpw <passwd>\""
1268                                         " line\n", fname, lineno ,0 );
1269 #else
1270                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1271                                         "missing passwd in \"rootpw <passwd>\" line\n",
1272                                     fname, lineno, 0 );
1273 #endif
1274
1275                                 return( 1 );
1276                         }
1277
1278                         if ( be == NULL ) {
1279 #ifdef NEW_LOGGING
1280                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
1281                                         "rootpw line must appear inside a database "
1282                                         "definition.\n", fname, lineno ,0 );
1283 #else
1284                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1285                                         "rootpw line must appear inside a database "
1286                                         "definition.\n",
1287                                     fname, lineno, 0 );
1288 #endif
1289                                 return 1;
1290
1291                         } else {
1292                                 Backend *tmp_be = select_backend( &be->be_rootndn, 0, 0 );
1293
1294                                 if( tmp_be != be ) {
1295 #ifdef NEW_LOGGING
1296                                         LDAP_LOG( CONFIG, INFO,
1297                                                 "%s: line %d: "
1298                                                 "rootpw can only be set when rootdn is under suffix\n",
1299                                                 fname, lineno, "" );
1300 #else
1301                                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1302                                                 "rootpw can only be set when rootdn is under suffix\n",
1303                                         fname, lineno, 0 );
1304 #endif
1305                                         return 1;
1306                                 }
1307
1308                                 be->be_rootpw.bv_val = ch_strdup( cargv[1] );
1309                                 be->be_rootpw.bv_len = strlen( be->be_rootpw.bv_val );
1310                         }
1311
1312                 /* make this database read-only */
1313                 } else if ( strcasecmp( cargv[0], "readonly" ) == 0 ) {
1314                         if ( cargc < 2 ) {
1315 #ifdef NEW_LOGGING
1316                                 LDAP_LOG( CONFIG, CRIT, 
1317                                         "%s: line %d: missing on|off in \"readonly <on|off>\" "
1318                                         "line.\n", fname, lineno ,0 );
1319 #else
1320                                 Debug( LDAP_DEBUG_ANY,
1321             "%s: line %d: missing on|off in \"readonly <on|off>\" line\n",
1322                                     fname, lineno, 0 );
1323 #endif
1324
1325                                 return( 1 );
1326                         }
1327                         if ( be == NULL ) {
1328                                 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
1329                                         global_restrictops |= SLAP_RESTRICT_OP_WRITES;
1330                                 } else {
1331                                         global_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1332                                 }
1333                         } else {
1334                                 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
1335                                         be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1336                                 } else {
1337                                         be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1338                                 }
1339                         }
1340
1341                 /* restricts specific operations */
1342                 } else if ( strcasecmp( cargv[0], "restrict" ) == 0 ) {
1343                         slap_mask_t     restrict = 0;
1344                         struct restrictable_exops_t {
1345                                 char    *name;
1346                                 int     flag;
1347                         } restrictable_exops[] = {
1348                                 { LDAP_EXOP_START_TLS,          SLAP_RESTRICT_EXOP_START_TLS },
1349                                 { LDAP_EXOP_MODIFY_PASSWD,      SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
1350                                 { LDAP_EXOP_X_WHO_AM_I,         SLAP_RESTRICT_EXOP_WHOAMI },
1351                                 { LDAP_EXOP_X_CANCEL,           SLAP_RESTRICT_EXOP_CANCEL },
1352                                 { NULL,                         0 }
1353                         };
1354                         int             i;
1355
1356                         if ( cargc < 2 ) {
1357 #ifdef NEW_LOGGING
1358                                 LDAP_LOG( CONFIG, CRIT, 
1359                                         "%s: line %d: missing <op_list> in \"restrict <op_list>\" "
1360                                         "line.\n", fname, lineno ,0 );
1361 #else
1362                                 Debug( LDAP_DEBUG_ANY,
1363                                         "%s: line %d: missing <op_list> in \"restrict <op_list>\" "
1364                                         "line.\n", fname, lineno, 0 );
1365 #endif
1366
1367                                 return( 1 );
1368                         }
1369
1370                         for ( i = 1; i < cargc; i++ ) {
1371                                 if ( strcasecmp( cargv[ i ], "read" ) == 0 ) {
1372                                         restrict |= SLAP_RESTRICT_OP_READS;
1373
1374                                 } else if ( strcasecmp( cargv[ i ], "write" ) == 0 ) {
1375                                         restrict |= SLAP_RESTRICT_OP_WRITES;
1376
1377                                 } else if ( strcasecmp( cargv[ i ], "add" ) == 0 ) {
1378                                         restrict |= SLAP_RESTRICT_OP_ADD;
1379
1380                                 } else if ( strcasecmp( cargv[ i ], "bind" ) == 0 ) {
1381                                         restrict |= SLAP_RESTRICT_OP_BIND;
1382
1383                                 } else if ( strcasecmp( cargv[ i ], "compare" ) == 0 ) {
1384                                         restrict |= SLAP_RESTRICT_OP_COMPARE;
1385
1386                                 } else if ( strcasecmp( cargv[ i ], "delete" ) == 0 ) {
1387                                         restrict |= SLAP_RESTRICT_OP_DELETE;
1388
1389                                 } else if ( strncasecmp( cargv[ i ], "extended",
1390                                                         STRLENOF( "extended" ) ) == 0 ) {
1391                                         char    *e = cargv[ i ] + STRLENOF( "extended" );
1392
1393                                         if ( e[0] == '=' ) {
1394                                                 int     j;
1395
1396                                                 e++;
1397                                                 for ( j = 0; restrictable_exops[ j ].name; j++ ) {
1398                                                         if ( strcmp( e, restrictable_exops[ j ].name ) == 0 ) {
1399                                                                 restrict |= restrictable_exops[ j ].flag;
1400                                                                 break;
1401                                                         }
1402                                                 }
1403
1404                                                 if ( restrictable_exops[ j ].name == NULL ) {
1405                                                         goto restrict_unknown;
1406                                                 }
1407
1408                                                 restrict &= ~SLAP_RESTRICT_OP_EXTENDED;
1409
1410                                         } else if ( e[0] == '\0' ) {
1411                                                 restrict &= ~SLAP_RESTRICT_EXOP_MASK;
1412                                                 restrict |= SLAP_RESTRICT_OP_EXTENDED;
1413                                                 
1414                                         } else {
1415                                                 goto restrict_unknown;
1416                                         }
1417
1418                                 } else if ( strcasecmp( cargv[ i ], "modify" ) == 0 ) {
1419                                         restrict |= SLAP_RESTRICT_OP_MODIFY;
1420
1421                                 } else if ( strcasecmp( cargv[ i ], "rename" ) == 0
1422                                                 || strcasecmp( cargv[ i ], "modrdn" ) == 0 ) {
1423                                         restrict |= SLAP_RESTRICT_OP_RENAME;
1424
1425                                 } else if ( strcasecmp( cargv[ i ], "search" ) == 0 ) {
1426                                         restrict |= SLAP_RESTRICT_OP_SEARCH;
1427
1428                                 } else {
1429 restrict_unknown:;
1430
1431 #ifdef NEW_LOGGING
1432                                         LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
1433                                                 "unknown operation %s in \"allow <features>\" line.\n",
1434                                                 fname, lineno, cargv[i] );
1435 #else
1436                                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1437                                                 "unknown operation %s in \"allow <features>\" line\n",
1438                                                 fname, lineno, cargv[i] );
1439 #endif
1440                                         return 1;
1441                                 }
1442                         }
1443
1444                         if ( be == NULL ) {
1445                                 global_restrictops |= restrict;
1446
1447                         } else {
1448                                 be->be_restrictops |= restrict;
1449                         }
1450
1451                 /* allow these features */
1452                 } else if ( strcasecmp( cargv[0], "allows" ) == 0 ||
1453                         strcasecmp( cargv[0], "allow" ) == 0 )
1454                 {
1455                         slap_mask_t     allows;
1456
1457                         if ( be != NULL ) {
1458 #ifdef NEW_LOGGING
1459                                 LDAP_LOG( CONFIG, INFO, 
1460                                            "%s: line %d: allow line must appear prior to "
1461                                            "database definitions.\n", fname, lineno ,0 );
1462 #else
1463                                 Debug( LDAP_DEBUG_ANY,
1464 "%s: line %d: allow line must appear prior to database definitions\n",
1465                                     fname, lineno, 0 );
1466 #endif
1467
1468                         }
1469
1470                         if ( cargc < 2 ) {
1471 #ifdef NEW_LOGGING
1472                                 LDAP_LOG( CONFIG, CRIT, 
1473                                            "%s: line %d: missing feature(s) in \"allow <features>\""
1474                                            " line\n", fname, lineno ,0 );
1475 #else
1476                                 Debug( LDAP_DEBUG_ANY,
1477             "%s: line %d: missing feature(s) in \"allow <features>\" line\n",
1478                                     fname, lineno, 0 );
1479 #endif
1480
1481                                 return( 1 );
1482                         }
1483
1484                         allows = 0;
1485
1486                         for( i=1; i < cargc; i++ ) {
1487                                 if( strcasecmp( cargv[i], "bind_v2" ) == 0 ) {
1488                                         allows |= SLAP_ALLOW_BIND_V2;
1489
1490                                 } else if( strcasecmp( cargv[i], "bind_anon_cred" ) == 0 ) {
1491                                         allows |= SLAP_ALLOW_BIND_ANON_CRED;
1492
1493                                 } else if( strcasecmp( cargv[i], "bind_anon_dn" ) == 0 ) {
1494                                         allows |= SLAP_ALLOW_BIND_ANON_DN;
1495
1496                                 } else if( strcasecmp( cargv[i], "update_anon" ) == 0 ) {
1497                                         allows |= SLAP_ALLOW_UPDATE_ANON;
1498
1499                                 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1500 #ifdef NEW_LOGGING
1501                                         LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
1502                                                 "unknown feature %s in \"allow <features>\" line.\n",
1503                                                 fname, lineno, cargv[i] );
1504 #else
1505                                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1506                                                 "unknown feature %s in \"allow <features>\" line\n",
1507                                                 fname, lineno, cargv[i] );
1508 #endif
1509
1510                                         return( 1 );
1511                                 }
1512                         }
1513
1514                         global_allows = allows;
1515
1516                 /* disallow these features */
1517                 } else if ( strcasecmp( cargv[0], "disallows" ) == 0 ||
1518                         strcasecmp( cargv[0], "disallow" ) == 0 )
1519                 {
1520                         slap_mask_t     disallows;
1521
1522                         if ( be != NULL ) {
1523 #ifdef NEW_LOGGING
1524                                 LDAP_LOG( CONFIG, INFO, 
1525                                            "%s: line %d: disallow line must appear prior to "
1526                                            "database definitions.\n", fname, lineno ,0 );
1527 #else
1528                                 Debug( LDAP_DEBUG_ANY,
1529 "%s: line %d: disallow line must appear prior to database definitions\n",
1530                                     fname, lineno, 0 );
1531 #endif
1532
1533                         }
1534
1535                         if ( cargc < 2 ) {
1536 #ifdef NEW_LOGGING
1537                                 LDAP_LOG( CONFIG, CRIT, 
1538                                         "%s: line %d: missing feature(s) in \"disallow <features>\""
1539                                         " line.\n", fname, lineno ,0 );
1540 #else
1541                                 Debug( LDAP_DEBUG_ANY,
1542             "%s: line %d: missing feature(s) in \"disallow <features>\" line\n",
1543                                     fname, lineno, 0 );
1544 #endif
1545
1546                                 return( 1 );
1547                         }
1548
1549                         disallows = 0;
1550
1551                         for( i=1; i < cargc; i++ ) {
1552                                 if( strcasecmp( cargv[i], "bind_anon" ) == 0 ) {
1553                                         disallows |= SLAP_DISALLOW_BIND_ANON;
1554
1555                                 } else if( strcasecmp( cargv[i], "bind_simple" ) == 0 ) {
1556                                         disallows |= SLAP_DISALLOW_BIND_SIMPLE;
1557
1558                                 } else if( strcasecmp( cargv[i], "bind_krbv4" ) == 0 ) {
1559                                         disallows |= SLAP_DISALLOW_BIND_KRBV4;
1560
1561                                 } else if( strcasecmp( cargv[i], "tls_2_anon" ) == 0 ) {
1562                                         disallows |= SLAP_DISALLOW_TLS_2_ANON;
1563
1564                                 } else if( strcasecmp( cargv[i], "tls_authc" ) == 0 ) {
1565                                         disallows |= SLAP_DISALLOW_TLS_AUTHC;
1566
1567                                 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1568 #ifdef NEW_LOGGING
1569                                         LDAP_LOG( CONFIG, CRIT, 
1570                                                 "%s: line %d: unknown feature %s in "
1571                                                 "\"disallow <features>\" line.\n",
1572                                                 fname, lineno, cargv[i] );
1573 #else
1574                                         Debug( LDAP_DEBUG_ANY,
1575                     "%s: line %d: unknown feature %s in \"disallow <features>\" line\n",
1576                                             fname, lineno, cargv[i] );
1577 #endif
1578
1579                                         return( 1 );
1580                                 }
1581                         }
1582
1583                         global_disallows = disallows;
1584
1585                 /* require these features */
1586                 } else if ( strcasecmp( cargv[0], "requires" ) == 0 ||
1587                         strcasecmp( cargv[0], "require" ) == 0 )
1588                 {
1589                         slap_mask_t     requires;
1590
1591                         if ( cargc < 2 ) {
1592 #ifdef NEW_LOGGING
1593                                 LDAP_LOG( CONFIG, CRIT, 
1594                                            "%s: line %d: missing feature(s) in "
1595                                            "\"require <features>\" line.\n", fname, lineno ,0 );
1596 #else
1597                                 Debug( LDAP_DEBUG_ANY,
1598             "%s: line %d: missing feature(s) in \"require <features>\" line\n",
1599                                     fname, lineno, 0 );
1600 #endif
1601
1602                                 return( 1 );
1603                         }
1604
1605                         requires = 0;
1606
1607                         for( i=1; i < cargc; i++ ) {
1608                                 if( strcasecmp( cargv[i], "bind" ) == 0 ) {
1609                                         requires |= SLAP_REQUIRE_BIND;
1610
1611                                 } else if( strcasecmp( cargv[i], "LDAPv3" ) == 0 ) {
1612                                         requires |= SLAP_REQUIRE_LDAP_V3;
1613
1614                                 } else if( strcasecmp( cargv[i], "authc" ) == 0 ) {
1615                                         requires |= SLAP_REQUIRE_AUTHC;
1616
1617                                 } else if( strcasecmp( cargv[i], "SASL" ) == 0 ) {
1618                                         requires |= SLAP_REQUIRE_SASL;
1619
1620                                 } else if( strcasecmp( cargv[i], "strong" ) == 0 ) {
1621                                         requires |= SLAP_REQUIRE_STRONG;
1622
1623                                 } else if( strcasecmp( cargv[i], "none" ) != 0 ) {
1624 #ifdef NEW_LOGGING
1625                                         LDAP_LOG( CONFIG, CRIT, 
1626                                                    "%s: line %d: unknown feature %s in "
1627                                                    "\"require <features>\" line.\n", 
1628                                                    fname, lineno , cargv[i] );
1629 #else
1630                                         Debug( LDAP_DEBUG_ANY,
1631                     "%s: line %d: unknown feature %s in \"require <features>\" line\n",
1632                                             fname, lineno, cargv[i] );
1633 #endif
1634
1635                                         return( 1 );
1636                                 }
1637                         }
1638
1639                         if ( be == NULL ) {
1640                                 global_requires = requires;
1641                         } else {
1642                                 be->be_requires = requires;
1643                         }
1644
1645                 /* required security factors */
1646                 } else if ( strcasecmp( cargv[0], "security" ) == 0 ) {
1647                         slap_ssf_set_t *set;
1648
1649                         if ( cargc < 2 ) {
1650 #ifdef NEW_LOGGING
1651                                 LDAP_LOG( CONFIG, CRIT, 
1652                                         "%s: line %d: missing factor(s) in \"security <factors>\""
1653                                         " line.\n", fname, lineno ,0 );
1654 #else
1655                                 Debug( LDAP_DEBUG_ANY,
1656             "%s: line %d: missing factor(s) in \"security <factors>\" line\n",
1657                                     fname, lineno, 0 );
1658 #endif
1659
1660                                 return( 1 );
1661                         }
1662
1663                         if ( be == NULL ) {
1664                                 set = &global_ssf_set;
1665                         } else {
1666                                 set = &be->be_ssf_set;
1667                         }
1668
1669                         for( i=1; i < cargc; i++ ) {
1670                                 slap_ssf_t      *tgt;
1671                                 char            *src;
1672
1673                                 if ( strncasecmp( cargv[i], "ssf=",
1674                                                 STRLENOF("ssf=") ) == 0 )
1675                                 {
1676                                         tgt = &set->sss_ssf;
1677                                         src = &cargv[i][STRLENOF("ssf=")];
1678
1679                                 } else if ( strncasecmp( cargv[i], "transport=",
1680                                                 STRLENOF("transport=") ) == 0 )
1681                                 {
1682                                         tgt = &set->sss_transport;
1683                                         src = &cargv[i][STRLENOF("transport=")];
1684
1685                                 } else if ( strncasecmp( cargv[i], "tls=",
1686                                                 STRLENOF("tls=") ) == 0 )
1687                                 {
1688                                         tgt = &set->sss_tls;
1689                                         src = &cargv[i][STRLENOF("tls=")];
1690
1691                                 } else if ( strncasecmp( cargv[i], "sasl=",
1692                                                 STRLENOF("sasl=") ) == 0 )
1693                                 {
1694                                         tgt = &set->sss_sasl;
1695                                         src = &cargv[i][STRLENOF("sasl=")];
1696
1697                                 } else if ( strncasecmp( cargv[i], "update_ssf=",
1698                                                 STRLENOF("update_ssf=") ) == 0 )
1699                                 {
1700                                         tgt = &set->sss_update_ssf;
1701                                         src = &cargv[i][STRLENOF("update_ssf=")];
1702
1703                                 } else if ( strncasecmp( cargv[i], "update_transport=",
1704                                                 STRLENOF("update_transport=") ) == 0 )
1705                                 {
1706                                         tgt = &set->sss_update_transport;
1707                                         src = &cargv[i][STRLENOF("update_transport=")];
1708
1709                                 } else if ( strncasecmp( cargv[i], "update_tls=",
1710                                                 STRLENOF("update_tls=") ) == 0 )
1711                                 {
1712                                         tgt = &set->sss_update_tls;
1713                                         src = &cargv[i][STRLENOF("update_tls=")];
1714
1715                                 } else if ( strncasecmp( cargv[i], "update_sasl=",
1716                                                 STRLENOF("update_sasl=") ) == 0 )
1717                                 {
1718                                         tgt = &set->sss_update_sasl;
1719                                         src = &cargv[i][STRLENOF("update_sasl=")];
1720
1721                                 } else if ( strncasecmp( cargv[i], "simple_bind=",
1722                                                 STRLENOF("simple_bind=") ) == 0 )
1723                                 {
1724                                         tgt = &set->sss_simple_bind;
1725                                         src = &cargv[i][STRLENOF("simple_bind=")];
1726
1727                                 } else {
1728 #ifdef NEW_LOGGING
1729                                         LDAP_LOG( CONFIG, CRIT, 
1730                                                    "%s: line %d: unknown factor %s in "
1731                                                    "\"security <factors>\" line.\n",
1732                                                    fname, lineno, cargv[1] );
1733 #else
1734                                         Debug( LDAP_DEBUG_ANY,
1735                     "%s: line %d: unknown factor %s in \"security <factors>\" line\n",
1736                                             fname, lineno, cargv[i] );
1737 #endif
1738
1739                                         return( 1 );
1740                                 }
1741
1742                                 *tgt = strtol( src, &next, 10 );
1743                                 if ( next == NULL || next[0] != '\0' ) {
1744 #ifdef NEW_LOGGING
1745                                         LDAP_LOG( CONFIG, CRIT, 
1746                                                    "%s: line %d: unable to parse factor \"%s\" in "
1747                                                    "\"security <factors>\" line.\n",
1748                                                    fname, lineno, cargv[1] );
1749 #else
1750                                         Debug( LDAP_DEBUG_ANY,
1751                     "%s: line %d: unable to parse factor \"%s\" in \"security <factors>\" line\n",
1752                                             fname, lineno, cargv[i] );
1753 #endif
1754
1755                                         return( 1 );
1756                                 }
1757                         }
1758
1759                 /* where to send clients when we don't hold it */
1760                 } else if ( strcasecmp( cargv[0], "referral" ) == 0 ) {
1761                         if ( cargc < 2 ) {
1762 #ifdef NEW_LOGGING
1763                                 LDAP_LOG( CONFIG, CRIT, 
1764                                         "%s: line %d: missing URL in \"referral <URL>\""
1765                                         " line.\n", fname, lineno , 0 );
1766 #else
1767                                 Debug( LDAP_DEBUG_ANY,
1768                     "%s: line %d: missing URL in \"referral <URL>\" line\n",
1769                                     fname, lineno, 0 );
1770 #endif
1771
1772                                 return( 1 );
1773                         }
1774
1775                         if( validate_global_referral( cargv[1] ) ) {
1776 #ifdef NEW_LOGGING
1777                                 LDAP_LOG( CONFIG, CRIT, 
1778                                         "%s: line %d: invalid URL (%s) in \"referral\" line.\n",
1779                                         fname, lineno, cargv[1]  );
1780 #else
1781                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1782                                         "invalid URL (%s) in \"referral\" line.\n",
1783                                     fname, lineno, cargv[1] );
1784 #endif
1785                                 return 1;
1786                         }
1787
1788                         vals[0].bv_val = cargv[1];
1789                         vals[0].bv_len = strlen( vals[0].bv_val );
1790                         if( value_add( &default_referral, vals ) )
1791                                 return LDAP_OTHER;
1792
1793 #ifdef NEW_LOGGING
1794                 } else if ( strcasecmp( cargv[0], "logfile" ) == 0 ) {
1795                         FILE *logfile;
1796                         if ( cargc < 2 ) {
1797 #ifdef NEW_LOGGING
1798                                 LDAP_LOG( CONFIG, CRIT, 
1799                                         "%s: line %d: Error in logfile directive, "
1800                                         "\"logfile <filename>\"\n", fname, lineno , 0 );
1801 #else
1802                                 Debug( LDAP_DEBUG_ANY,
1803                                        "%s: line %d: Error in logfile directive, \"logfile filename\"\n",
1804                                        fname, lineno, 0 );
1805 #endif
1806
1807                                 return( 1 );
1808                         }
1809                         logfile = fopen( cargv[1], "w" );
1810                         if ( logfile != NULL ) lutil_debug_file( logfile  );
1811
1812 #endif
1813                 /* start of a new database definition */
1814                 } else if ( strcasecmp( cargv[0], "debug" ) == 0 ) {
1815                         int level;
1816                         if ( cargc < 3 ) {
1817 #ifdef NEW_LOGGING
1818                                 LDAP_LOG( CONFIG, CRIT, 
1819                                            "%s: line %d: Error in debug directive, "
1820                                            "\"debug <subsys> <level>\"\n", fname, lineno , 0 );
1821 #else
1822                                 Debug( LDAP_DEBUG_ANY,
1823                                         "%s: line %d: Error in debug directive, \"debug subsys level\"\n",
1824                                         fname, lineno, 0 );
1825 #endif
1826                                 return( 1 );
1827                         }
1828                         level = strtol( cargv[2], &next, 10 );
1829                         if ( next == NULL || next[0] != '\0' ){
1830 #ifdef NEW_LOGGING
1831                                 LDAP_LOG( CONFIG, CRIT, 
1832                                            "%s: line %d: unable to parse level \"%s\" in debug directive, "
1833                                            "\"debug <subsys> <level>\"\n", fname, lineno , cargv[2] );
1834 #else
1835                                 Debug( LDAP_DEBUG_ANY,
1836                                            "%s: line %d: unable to parse level \"%s\" in debug directive, "
1837                                            "\"debug <subsys> <level>\"\n", fname, lineno , cargv[2] );
1838 #endif
1839                                 return( 1 );
1840                         }
1841
1842                         if ( level <= 0 ) level = lutil_mnem2level( cargv[2] );
1843                         lutil_set_debug_level( cargv[1], level );
1844                 /* specify an Object Identifier macro */
1845                 } else if ( strcasecmp( cargv[0], "objectidentifier" ) == 0 ) {
1846                         rc = parse_oidm( fname, lineno, cargc, cargv );
1847                         if( rc ) return rc;
1848
1849                 /* specify an objectclass */
1850                 } else if ( strcasecmp( cargv[0], "objectclass" ) == 0 ) {
1851                         if ( cargc < 2 ) {
1852 #ifdef NEW_LOGGING
1853                                 LDAP_LOG( CONFIG, INFO, 
1854                                         "%s: line %d: illegal objectclass format.\n",
1855                                         fname, lineno , 0 );
1856 #else
1857                                 Debug( LDAP_DEBUG_ANY,
1858                                        "%s: line %d: illegal objectclass format.\n",
1859                                        fname, lineno, 0 );
1860 #endif
1861                                 return( 1 );
1862
1863                         } else if ( *cargv[1] == '('  /*')'*/) {
1864                                 char * p;
1865                                 p = strchr(saveline,'(' /*')'*/);
1866                                 rc = parse_oc( fname, lineno, p, cargv );
1867                                 if( rc ) return rc;
1868
1869                         } else {
1870 #ifdef NEW_LOGGING
1871                                 LDAP_LOG( CONFIG, INFO, 
1872                                         "%s: line %d: old objectclass format not supported\n",
1873                                         fname, lineno , 0 );
1874 #else
1875                                 Debug( LDAP_DEBUG_ANY,
1876                                        "%s: line %d: old objectclass format not supported.\n",
1877                                        fname, lineno, 0 );
1878 #endif
1879                         }
1880
1881                 } else if ( strcasecmp( cargv[0], "ditcontentrule" ) == 0 ) {
1882                         char * p;
1883                         p = strchr(saveline,'(' /*')'*/);
1884                         rc = parse_cr( fname, lineno, p, cargv );
1885                         if( rc ) return rc;
1886
1887                 /* specify an attribute type */
1888                 } else if (( strcasecmp( cargv[0], "attributetype" ) == 0 )
1889                         || ( strcasecmp( cargv[0], "attribute" ) == 0 ))
1890                 {
1891                         if ( cargc < 2 ) {
1892 #ifdef NEW_LOGGING
1893                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
1894                                         "illegal attribute type format.\n",
1895                                         fname, lineno , 0 );
1896 #else
1897                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1898                                         "illegal attribute type format.\n",
1899                                         fname, lineno, 0 );
1900 #endif
1901                                 return( 1 );
1902
1903                         } else if ( *cargv[1] == '(' /*')'*/) {
1904                                 char * p;
1905                                 p = strchr(saveline,'(' /*')'*/);
1906                                 rc = parse_at( fname, lineno, p, cargv );
1907                                 if( rc ) return rc;
1908
1909                         } else {
1910 #ifdef NEW_LOGGING
1911                                 LDAP_LOG( CONFIG, INFO, 
1912                                         "%s: line %d: old attribute type format not supported.\n",
1913                                         fname, lineno , 0 );
1914 #else
1915                                 Debug( LDAP_DEBUG_ANY,
1916     "%s: line %d: old attribute type format not supported.\n",
1917                                     fname, lineno, 0 );
1918 #endif
1919
1920                         }
1921
1922                 /* define attribute option(s) */
1923                 } else if ( strcasecmp( cargv[0], "attributeoptions" ) == 0 ) {
1924                         ad_define_option( NULL, NULL, 0 );
1925                         for ( i = 1; i < cargc; i++ )
1926                                 if ( ad_define_option( cargv[i], fname, lineno ) != 0 )
1927                                         return 1;
1928
1929                 /* turn on/off schema checking */
1930                 } else if ( strcasecmp( cargv[0], "schemacheck" ) == 0 ) {
1931                         if ( cargc < 2 ) {
1932 #ifdef NEW_LOGGING
1933                                 LDAP_LOG( CONFIG, CRIT, 
1934                                         "%s: line %d: missing on|off in \"schemacheck <on|off>\""
1935                                         " line.\n", fname, lineno , 0 );
1936 #else
1937                                 Debug( LDAP_DEBUG_ANY,
1938     "%s: line %d: missing on|off in \"schemacheck <on|off>\" line\n",
1939                                     fname, lineno, 0 );
1940 #endif
1941
1942                                 return( 1 );
1943                         }
1944                         if ( strcasecmp( cargv[1], "off" ) == 0 ) {
1945 #ifdef NEW_LOGGING
1946                                 LDAP_LOG( CONFIG, CRIT, 
1947                                         "%s: line %d: schema checking disabled! your mileage may "
1948                                         "vary!\n", fname, lineno , 0 );
1949 #else
1950                                 Debug( LDAP_DEBUG_ANY,
1951                                         "%s: line %d: schema checking disabled! your mileage may vary!\n",
1952                                     fname, lineno, 0 );
1953 #endif
1954                                 global_schemacheck = 0;
1955                         } else {
1956                                 global_schemacheck = 1;
1957                         }
1958
1959                 /* specify access control info */
1960                 } else if ( strcasecmp( cargv[0], "access" ) == 0 ) {
1961                         parse_acl( be, fname, lineno, cargc, cargv );
1962
1963                 /* debug level to log things to syslog */
1964                 } else if ( strcasecmp( cargv[0], "loglevel" ) == 0 ) {
1965                         if ( cargc < 2 ) {
1966 #ifdef NEW_LOGGING
1967                                 LDAP_LOG( CONFIG, CRIT, 
1968                                         "%s: line %d: missing level(s) in \"loglevel <level> [...]\""
1969                                         " line.\n", fname, lineno , 0 );
1970 #else
1971                                 Debug( LDAP_DEBUG_ANY,
1972                     "%s: line %d: missing level(s) in \"loglevel <level> [...]\" line\n",
1973                                     fname, lineno, 0 );
1974 #endif
1975
1976                                 return( 1 );
1977                         }
1978
1979                         ldap_syslog = 0;
1980
1981                         for( i=1; i < cargc; i++ ) {
1982                                 int     level = strtol( cargv[i], &next, 10 );
1983                                 if ( next == NULL || next[0] != '\0' ) {
1984 #ifdef NEW_LOGGING
1985                                         LDAP_LOG( CONFIG, CRIT, 
1986                                                 "%s: line %d: unable to parse level \"%s\" in \"loglevel <level> [...]\""
1987                                                 " line.\n", fname, lineno , cargv[i] );
1988 #else
1989                                         Debug( LDAP_DEBUG_ANY,
1990                                                 "%s: line %d: unable to parse level \"%s\" in \"loglevel <level> [...]\""
1991                                                 " line.\n", fname, lineno , cargv[i] );
1992 #endif
1993                                         return( 1 );
1994                                 }
1995
1996                                 ldap_syslog |= level;
1997                         }
1998
1999                 /* list of sync replication information in this backend (slave only) */
2000                 } else if ( strcasecmp( cargv[0], "syncrepl" ) == 0 ) {
2001
2002                         if ( be == NULL ) {
2003 #ifdef NEW_LOGGING
2004                                 LDAP_LOG( CONFIG, INFO, 
2005                                             "%s: line %d: syncrepl line must appear inside "
2006                                             "a database definition.\n", fname, lineno, 0);
2007 #else
2008                                 Debug( LDAP_DEBUG_ANY,
2009                                             "%s: line %d: syncrepl line must appear inside "
2010                                             "a database definition.\n", fname, lineno, 0);
2011 #endif
2012                                 return 1;
2013
2014                         } else if ( SLAP_SHADOW( be )) {
2015 #ifdef NEW_LOGGING
2016                                 LDAP_LOG( CONFIG, INFO, 
2017                                         "%s: line %d: syncrepl: database already shadowed.\n",
2018                                         fname, lineno, 0);
2019 #else
2020                                 Debug( LDAP_DEBUG_ANY,
2021                                         "%s: line %d: syncrepl: database already shadowed.\n",
2022                                         fname, lineno, 0);
2023 #endif
2024                                 return 1;
2025
2026                         } else if ( add_syncrepl( be, cargv, cargc )) {
2027                                 return 1;
2028                         }
2029
2030                         SLAP_DBFLAGS(be) |= ( SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SYNC_SHADOW );
2031
2032                 /* list of replicas of the data in this backend (master only) */
2033                 } else if ( strcasecmp( cargv[0], "replica" ) == 0 ) {
2034                         if ( cargc < 2 ) {
2035 #ifdef NEW_LOGGING
2036                                 LDAP_LOG( CONFIG, CRIT, 
2037                                         "%s: line %d: missing host or uri in \"replica "
2038                                         " <host[:port]\" line\n", fname, lineno , 0 );
2039 #else
2040                                 Debug( LDAP_DEBUG_ANY,
2041             "%s: line %d: missing host or uri in \"replica <host[:port]>\" line\n",
2042                                     fname, lineno, 0 );
2043 #endif
2044
2045                                 return( 1 );
2046                         }
2047                         if ( be == NULL ) {
2048 #ifdef NEW_LOGGING
2049                                 LDAP_LOG( CONFIG, INFO, 
2050                                             "%s: line %d: replica line must appear inside "
2051                                             "a database definition.\n", fname, lineno, 0);
2052 #else
2053                                 Debug( LDAP_DEBUG_ANY,
2054 "%s: line %d: replica line must appear inside a database definition\n",
2055                                     fname, lineno, 0 );
2056 #endif
2057                                 return 1;
2058
2059                         } else {
2060                                 int nr = -1;
2061
2062                                 for ( i = 1; i < cargc; i++ ) {
2063                                         if ( strncasecmp( cargv[i], "host=", 5 )
2064                                             == 0 ) {
2065                                                 nr = add_replica_info( be, 
2066                                                         cargv[i] + 5 );
2067                                                 break;
2068                                         } else if (strncasecmp( cargv[i], "uri=", 4 )
2069                                             == 0 ) {
2070                                             if ( ldap_url_parse( cargv[ i ] + 4, &ludp )
2071                                                 != LDAP_SUCCESS ) {
2072 #ifdef NEW_LOGGING
2073                                                         LDAP_LOG( CONFIG, INFO, 
2074                                                         "%s: line %d: replica line contains invalid "
2075                                                         "uri definition.\n", fname, lineno, 0);
2076 #else
2077                                                         Debug( LDAP_DEBUG_ANY,
2078                                                         "%s: line %d: replica line contains invalid "
2079                                                         "uri definition.\n", fname, lineno, 0);
2080 #endif
2081                                                         return 1;
2082                                                 }
2083                                                 if (ludp->lud_host == NULL ) {
2084 #ifdef NEW_LOGGING
2085                                                         LDAP_LOG( CONFIG, INFO, 
2086                                                         "%s: line %d: replica line contains invalid "
2087                                                         "uri definition - missing hostname.\n", 
2088                                                         fname, lineno, 0);
2089 #else
2090                                                         Debug( LDAP_DEBUG_ANY,
2091                                                         "%s: line %d: replica line contains invalid "
2092                                                         "uri definition - missing hostname.\n", fname, lineno, 0);
2093 #endif
2094                                                         return 1;
2095                                                 }
2096                                         replicahost = ch_malloc( strlen( cargv[ i ] ) );
2097                                                 if ( replicahost == NULL ) {
2098 #ifdef NEW_LOGGING
2099                                                         LDAP_LOG( CONFIG, ERR, 
2100                                                         "out of memory in read_config\n", 0, 0,0 );
2101 #else
2102                                                         Debug( LDAP_DEBUG_ANY, 
2103                                                         "out of memory in read_config\n", 0, 0, 0 );
2104 #endif
2105                                                         ldap_free_urldesc( ludp );                              
2106                                                         exit( EXIT_FAILURE );
2107                                                 }
2108                                                 sprintf(replicahost, "%s:%d", 
2109                                                         ludp->lud_host, ludp->lud_port);
2110                                                 nr = add_replica_info( be, replicahost );
2111                                                 ldap_free_urldesc( ludp );                              
2112                                                 ch_free(replicahost);
2113                                                 break;
2114                                         }
2115                                 }
2116                                 if ( i == cargc ) {
2117 #ifdef NEW_LOGGING
2118                                         LDAP_LOG( CONFIG, INFO, 
2119                                                 "%s: line %d: missing host or uri in \"replica\" line\n", 
2120                                                 fname, lineno , 0 );
2121 #else
2122                                         Debug( LDAP_DEBUG_ANY,
2123                     "%s: line %d: missing host or uri in \"replica\" line\n",
2124                                             fname, lineno, 0 );
2125 #endif
2126                                         return 1;
2127
2128                                 } else if ( nr == -1 ) {
2129 #ifdef NEW_LOGGING
2130                                         LDAP_LOG( CONFIG, INFO, 
2131                                                    "%s: line %d: unable to add"
2132                                                    " replica \"%s\"\n",
2133                                                    fname, lineno, 
2134                                                    cargv[i] + 5 );
2135 #else
2136                                         Debug( LDAP_DEBUG_ANY,
2137                 "%s: line %d: unable to add replica \"%s\"\n",
2138                                                 fname, lineno, cargv[i] + 5 );
2139 #endif
2140                                         return 1;
2141                                 } else {
2142                                         for ( i = 1; i < cargc; i++ ) {
2143                                                 if ( strncasecmp( cargv[i], "suffix=", 7 ) == 0 ) {
2144
2145                                                         switch ( add_replica_suffix( be, nr, cargv[i] + 7 ) ) {
2146                                                         case 1:
2147 #ifdef NEW_LOGGING
2148                                                                 LDAP_LOG( CONFIG, INFO, 
2149                                                                         "%s: line %d: suffix \"%s\" in \"replica\""
2150                                                                         " line is not valid for backend(ignored)\n",
2151                                                                         fname, lineno, cargv[i] + 7 );
2152 #else
2153                                                                 Debug( LDAP_DEBUG_ANY,
2154                                                                                 "%s: line %d: suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
2155                                                                                 fname, lineno, cargv[i] + 7 );
2156 #endif
2157                                                                 break;
2158
2159                                                         case 2:
2160 #ifdef NEW_LOGGING
2161                                                                 LDAP_LOG( CONFIG, INFO, 
2162                                                                         "%s: line %d: unable to normalize suffix"
2163                                                                         " in \"replica\" line (ignored)\n",
2164                                                                         fname, lineno , 0 );
2165 #else
2166                                                                 Debug( LDAP_DEBUG_ANY,
2167                                                                                  "%s: line %d: unable to normalize suffix in \"replica\" line (ignored)\n",
2168                                                                                  fname, lineno, 0 );
2169 #endif
2170                                                                 break;
2171                                                         }
2172
2173                                                 } else if ( strncasecmp( cargv[i], "attr", 4 ) == 0 ) {
2174                                                         int exclude = 0;
2175                                                         char *arg = cargv[i] + 4;
2176
2177                                                         if ( arg[0] == '!' ) {
2178                                                                 arg++;
2179                                                                 exclude = 1;
2180                                                         }
2181
2182                                                         if ( arg[0] != '=' ) {
2183                                                                 continue;
2184                                                         }
2185
2186                                                         if ( add_replica_attrs( be, nr, arg + 1, exclude ) ) {
2187 #ifdef NEW_LOGGING
2188                                                                 LDAP_LOG( CONFIG, INFO, 
2189                                                                         "%s: line %d: attribute \"%s\" in "
2190                                                                         "\"replica\" line is unknown\n",
2191                                                                         fname, lineno, arg + 1 ); 
2192 #else
2193                                                                 Debug( LDAP_DEBUG_ANY,
2194                                                                                 "%s: line %d: attribute \"%s\" in \"replica\" line is unknown\n",
2195                                                                                 fname, lineno, arg + 1 );
2196 #endif
2197                                                                 return( 1 );
2198                                                         }
2199                                                 }
2200                                         }
2201                                 }
2202                         }
2203
2204                 } else if ( strcasecmp( cargv[0], "replicationInterval" ) == 0 ) {
2205                         /* ignore */
2206
2207                 /* dn of slave entity allowed to write to replica */
2208                 } else if ( strcasecmp( cargv[0], "updatedn" ) == 0 ) {
2209                         if ( cargc < 2 ) {
2210 #ifdef NEW_LOGGING
2211                                 LDAP_LOG( CONFIG, CRIT, 
2212                                         "%s: line %d: missing dn in \"updatedn <dn>\""
2213                                         " line.\n", fname, lineno , 0 );
2214 #else
2215                                 Debug( LDAP_DEBUG_ANY,
2216                     "%s: line %d: missing dn in \"updatedn <dn>\" line\n",
2217                                     fname, lineno, 0 );
2218 #endif
2219
2220                                 return( 1 );
2221                         }
2222                         if ( be == NULL ) {
2223 #ifdef NEW_LOGGING
2224                                 LDAP_LOG( CONFIG, INFO, 
2225                                         "%s: line %d: updatedn line must appear inside "
2226                                         "a database definition\n", 
2227                                         fname, lineno , 0 );
2228 #else
2229                                 Debug( LDAP_DEBUG_ANY,
2230 "%s: line %d: updatedn line must appear inside a database definition\n",
2231                                     fname, lineno, 0 );
2232 #endif
2233                                 return 1;
2234
2235                         } else if ( SLAP_SHADOW(be) ) {
2236 #ifdef NEW_LOGGING
2237                                 LDAP_LOG( CONFIG, INFO, 
2238                                         "%s: line %d: updatedn: database already shadowed.\n",
2239                                         fname, lineno, 0);
2240 #else
2241                                 Debug( LDAP_DEBUG_ANY,
2242                                         "%s: line %d: updatedn: database already shadowed.\n",
2243                                         fname, lineno, 0);
2244 #endif
2245                                 return 1;
2246
2247                         } else {
2248                                 struct berval dn;
2249
2250                                 if ( load_ucdata( NULL ) < 0 ) return 1;
2251
2252                                 dn.bv_val = cargv[1];
2253                                 dn.bv_len = strlen( cargv[1] );
2254
2255                                 rc = dnNormalize( 0, NULL, NULL, &dn, &be->be_update_ndn, NULL );
2256                                 if( rc != LDAP_SUCCESS ) {
2257 #ifdef NEW_LOGGING
2258                                         LDAP_LOG( CONFIG, CRIT, 
2259                                                 "%s: line %d: updatedn DN is invalid.\n",
2260                                                 fname, lineno , 0 );
2261 #else
2262                                         Debug( LDAP_DEBUG_ANY,
2263                                                 "%s: line %d: updatedn DN is invalid\n",
2264                                             fname, lineno, 0 );
2265 #endif
2266                                         return 1;
2267                                 }
2268
2269                         }
2270                         SLAP_DBFLAGS(be) |= ( SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW );
2271
2272                 } else if ( strcasecmp( cargv[0], "updateref" ) == 0 ) {
2273                         if ( cargc < 2 ) {
2274 #ifdef NEW_LOGGING
2275                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2276                                         "missing url in \"updateref <ldapurl>\" line.\n",
2277                                         fname, lineno , 0 );
2278 #else
2279                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2280                                         "missing url in \"updateref <ldapurl>\" line\n",
2281                                     fname, lineno, 0 );
2282 #endif
2283
2284                                 return( 1 );
2285                         }
2286                         if ( be == NULL ) {
2287 #ifdef NEW_LOGGING
2288                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: updateref"
2289                                         " line must appear inside a database definition\n",
2290                                         fname, lineno , 0 );
2291 #else
2292                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: updateref"
2293                                         " line must appear inside a database definition\n",
2294                                         fname, lineno, 0 );
2295 #endif
2296                                 return 1;
2297
2298                         } else if ( !SLAP_SHADOW(be) ) {
2299 #ifdef NEW_LOGGING
2300                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: "
2301                                         "updateref line must come after syncrepl or updatedn.\n",
2302                                         fname, lineno , 0 );
2303 #else
2304                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2305                                         "updateref line must after syncrepl or updatedn.\n",
2306                                     fname, lineno, 0 );
2307 #endif
2308                                 return 1;
2309                         }
2310
2311                         if( validate_global_referral( cargv[1] ) ) {
2312 #ifdef NEW_LOGGING
2313                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2314                                         "invalid URL (%s) in \"updateref\" line.\n",
2315                                         fname, lineno, cargv[1] );
2316 #else
2317                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2318                                         "invalid URL (%s) in \"updateref\" line.\n",
2319                                     fname, lineno, cargv[1] );
2320 #endif
2321                                 return 1;
2322                         }
2323
2324                         vals[0].bv_val = cargv[1];
2325                         vals[0].bv_len = strlen( vals[0].bv_val );
2326                         if( value_add( &be->be_update_refs, vals ) ) {
2327                                 return LDAP_OTHER;
2328                         }
2329
2330                 /* replication log file to which changes are appended */
2331                 } else if ( strcasecmp( cargv[0], "replogfile" ) == 0 ) {
2332                         if ( cargc < 2 ) {
2333 #ifdef NEW_LOGGING
2334                                 LDAP_LOG( CONFIG, CRIT, 
2335                                         "%s: line %d: missing filename in \"replogfile <filename>\""
2336                                         " line.\n", fname, lineno , 0 );
2337 #else
2338                                 Debug( LDAP_DEBUG_ANY,
2339             "%s: line %d: missing filename in \"replogfile <filename>\" line\n",
2340                                     fname, lineno, 0 );
2341 #endif
2342
2343                                 return( 1 );
2344                         }
2345                         if ( be ) {
2346                                 be->be_replogfile = ch_strdup( cargv[1] );
2347                         } else {
2348                                 replogfile = ch_strdup( cargv[1] );
2349                         }
2350
2351                 /* file from which to read additional rootdse attrs */
2352                 } else if ( strcasecmp( cargv[0], "rootDSE" ) == 0) {
2353                         if ( cargc < 2 ) {
2354 #ifdef NEW_LOGGING
2355                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2356                                         "missing filename in \"rootDSE <filename>\" line.\n",
2357                                         fname, lineno , 0 );
2358 #else
2359                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2360                                         "missing filename in \"rootDSE <filename>\" line.\n",
2361                                     fname, lineno, 0 );
2362 #endif
2363                                 return 1;
2364                         }
2365
2366                         if( read_root_dse_file( cargv[1] ) ) {
2367 #ifdef NEW_LOGGING
2368                                 LDAP_LOG( CONFIG, CRIT, "%s: line %d: "
2369                                         "could not read \"rootDSE <filename>\" line.\n",
2370                                         fname, lineno , 0 );
2371 #else
2372                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
2373                                         "could not read \"rootDSE <filename>\" line\n",
2374                                     fname, lineno, 0 );
2375 #endif
2376                                 return 1;
2377                         }
2378
2379                 /* maintain lastmodified{by,time} attributes */
2380                 } else if ( strcasecmp( cargv[0], "lastmod" ) == 0 ) {
2381                         if ( cargc < 2 ) {
2382 #ifdef NEW_LOGGING
2383                                 LDAP_LOG( CONFIG, CRIT, 
2384                                            "%s: line %d: missing on|off in \"lastmod <on|off>\""
2385                                            " line.\n", fname, lineno , 0 );
2386 #else
2387                                 Debug( LDAP_DEBUG_ANY,
2388             "%s: line %d: missing on|off in \"lastmod <on|off>\" line\n",
2389                                     fname, lineno, 0 );
2390 #endif
2391
2392                                 return( 1 );
2393                         }
2394
2395                         if ( be == NULL ) {
2396 #ifdef NEW_LOGGING
2397                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: lastmod"
2398                                         " line must appear inside a database definition\n",
2399                                         fname, lineno , 0 );
2400 #else
2401                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: lastmod"
2402                                         " line must appear inside a database definition\n",
2403                                         fname, lineno, 0 );
2404 #endif
2405                                 return 1;
2406
2407                         } else if ( SLAP_NOLASTMODCMD(be) ) {
2408 #ifdef NEW_LOGGING
2409                                 LDAP_LOG( CONFIG, INFO, "%s: line %d: lastmod"
2410                                         " not available for %s database\n",
2411                                         fname, lineno , be->bd_info->bi_type );
2412 #else
2413                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: lastmod"
2414                                         " not available for %s databases\n",
2415                                         fname, lineno, be->bd_info->bi_type );
2416 #endif
2417                                 return 1;
2418                         }
2419
2420                         if ( strcasecmp( cargv[1], "on" ) == 0 ) {
2421                                 SLAP_DBFLAGS(be) &= ~SLAP_DBFLAG_NOLASTMOD;
2422                         } else {
2423                                 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NOLASTMOD;
2424                         }
2425
2426 #ifdef SIGHUP
2427                 /* turn on/off gentle SIGHUP handling */
2428                 } else if ( strcasecmp( cargv[0], "gentlehup" ) == 0 ) {
2429                         if ( cargc < 2 ) {
2430                                 Debug( LDAP_DEBUG_ANY,
2431     "%s: line %d: missing on|off in \"gentlehup <on|off>\" line\n",
2432                                     fname, lineno, 0 );
2433                                 return( 1 );
2434                         }
2435                         if ( strcasecmp( cargv[1], "off" ) == 0 ) {
2436                                 global_gentlehup = 0;
2437                         } else {
2438                                 global_gentlehup = 1;
2439                         }
2440 #endif
2441
2442                 /* set idle timeout value */
2443                 } else if ( strcasecmp( cargv[0], "idletimeout" ) == 0 ) {
2444                         int i;
2445                         if ( cargc < 2 ) {
2446 #ifdef NEW_LOGGING
2447                                 LDAP_LOG( CONFIG, CRIT, 
2448                                         "%s: line %d: missing timeout value in "
2449                                         "\"idletimeout <seconds>\" line.\n", fname, lineno , 0 );
2450 #else
2451                                 Debug( LDAP_DEBUG_ANY,
2452             "%s: line %d: missing timeout value in \"idletimeout <seconds>\" line\n",
2453                                     fname, lineno, 0 );
2454 #endif
2455
2456                                 return( 1 );
2457                         }
2458
2459                         i = atoi( cargv[1] );
2460
2461                         if( i < 0 ) {
2462 #ifdef NEW_LOGGING
2463                                 LDAP_LOG( CONFIG, CRIT, 
2464                                         "%s: line %d: timeout value (%d) invalid "
2465                                         "\"idletimeout <seconds>\" line.\n", fname, lineno, i );
2466 #else
2467                                 Debug( LDAP_DEBUG_ANY,
2468             "%s: line %d: timeout value (%d) invalid \"idletimeout <seconds>\" line\n",
2469                                     fname, lineno, i );
2470 #endif
2471
2472                                 return( 1 );
2473                         }
2474
2475                         global_idletimeout = i;
2476
2477                 /* include another config file */
2478                 } else if ( strcasecmp( cargv[0], "include" ) == 0 ) {
2479                         if ( cargc < 2 ) {
2480 #ifdef NEW_LOGGING
2481                                 LDAP_LOG( CONFIG, CRIT, 
2482                                         "%s: line %d: missing filename in \"include "
2483                                         "<filename>\" line.\n", fname, lineno , 0 );
2484 #else
2485                                 Debug( LDAP_DEBUG_ANY,
2486     "%s: line %d: missing filename in \"include <filename>\" line\n",
2487                                     fname, lineno, 0 );
2488 #endif
2489
2490                                 return( 1 );
2491                         }
2492                         savefname = ch_strdup( cargv[1] );
2493                         savelineno = lineno;
2494
2495                         if ( read_config( savefname, depth+1 ) != 0 ) {
2496                                 return( 1 );
2497                         }
2498
2499                         free( savefname );
2500                         lineno = savelineno - 1;
2501
2502                 /* location of kerberos srvtab file */
2503                 } else if ( strcasecmp( cargv[0], "srvtab" ) == 0 ) {
2504                         if ( cargc < 2 ) {
2505 #ifdef NEW_LOGGING
2506                                 LDAP_LOG( CONFIG, CRIT, 
2507                                         "%s: line %d: missing filename in \"srvtab "
2508                                         "<filename>\" line.\n", fname, lineno , 0 );
2509 #else
2510                                 Debug( LDAP_DEBUG_ANY,
2511             "%s: line %d: missing filename in \"srvtab <filename>\" line\n",
2512                                     fname, lineno, 0 );
2513 #endif
2514
2515                                 return( 1 );
2516                         }
2517                         ldap_srvtab = ch_strdup( cargv[1] );
2518
2519 #ifdef SLAPD_MODULES
2520                 } else if (strcasecmp( cargv[0], "moduleload") == 0 ) {
2521                    if ( cargc < 2 ) {
2522 #ifdef NEW_LOGGING
2523                            LDAP_LOG( CONFIG, INFO, 
2524                                    "%s: line %d: missing filename in \"moduleload "
2525                                    "<filename>\" line.\n", fname, lineno , 0 );
2526 #else
2527                       Debug( LDAP_DEBUG_ANY,
2528                              "%s: line %d: missing filename in \"moduleload <filename>\" line\n",
2529                              fname, lineno, 0 );
2530 #endif
2531
2532                       exit( EXIT_FAILURE );
2533                    }
2534                    if (module_load(cargv[1], cargc - 2, (cargc > 2) ? cargv + 2 : NULL)) {
2535 #ifdef NEW_LOGGING
2536                            LDAP_LOG( CONFIG, CRIT, 
2537                                    "%s: line %d: failed to load or initialize module %s\n",
2538                                    fname, lineno, cargv[1] );
2539 #else
2540                       Debug( LDAP_DEBUG_ANY,
2541                              "%s: line %d: failed to load or initialize module %s\n",
2542                              fname, lineno, cargv[1]);
2543 #endif
2544
2545                       exit( EXIT_FAILURE );
2546                    }
2547                 } else if (strcasecmp( cargv[0], "modulepath") == 0 ) {
2548                    if ( cargc != 2 ) {
2549 #ifdef NEW_LOGGING
2550                            LDAP_LOG( CONFIG, INFO, 
2551                                   "%s: line %d: missing path in \"modulepath <path>\""
2552                                   " line\n", fname, lineno , 0 );
2553 #else
2554                       Debug( LDAP_DEBUG_ANY,
2555                              "%s: line %d: missing path in \"modulepath <path>\" line\n",
2556                              fname, lineno, 0 );
2557 #endif
2558
2559                       exit( EXIT_FAILURE );
2560                    }
2561                    if (module_path( cargv[1] )) {
2562 #ifdef NEW_LOGGING
2563                            LDAP_LOG( CONFIG, CRIT, 
2564                                   "%s: line %d: failed to set module search path to %s.\n",
2565                                   fname, lineno, cargv[1] );
2566 #else
2567                            Debug( LDAP_DEBUG_ANY,
2568                                   "%s: line %d: failed to set module search path to %s\n",
2569                                   fname, lineno, cargv[1]);
2570 #endif
2571
2572                       exit( EXIT_FAILURE );
2573                    }
2574                    
2575 #endif /*SLAPD_MODULES*/
2576
2577 #ifdef HAVE_TLS
2578                 } else if ( !strcasecmp( cargv[0], "TLSRandFile" ) ) {
2579                         rc = ldap_pvt_tls_set_option( NULL,
2580                                                       LDAP_OPT_X_TLS_RANDOM_FILE,
2581                                                       cargv[1] );
2582                         if ( rc )
2583                                 return rc;
2584
2585                 } else if ( !strcasecmp( cargv[0], "TLSCipherSuite" ) ) {
2586                         rc = ldap_pvt_tls_set_option( NULL,
2587                                                       LDAP_OPT_X_TLS_CIPHER_SUITE,
2588                                                       cargv[1] );
2589                         if ( rc )
2590                                 return rc;
2591
2592                 } else if ( !strcasecmp( cargv[0], "TLSCertificateFile" ) ) {
2593                         rc = ldap_pvt_tls_set_option( NULL,
2594                                                       LDAP_OPT_X_TLS_CERTFILE,
2595                                                       cargv[1] );
2596                         if ( rc )
2597                                 return rc;
2598
2599                 } else if ( !strcasecmp( cargv[0], "TLSCertificateKeyFile" ) ) {
2600                         rc = ldap_pvt_tls_set_option( NULL,
2601                                                       LDAP_OPT_X_TLS_KEYFILE,
2602                                                       cargv[1] );
2603                         if ( rc )
2604                                 return rc;
2605
2606                 } else if ( !strcasecmp( cargv[0], "TLSCACertificatePath" ) ) {
2607                         rc = ldap_pvt_tls_set_option( NULL,
2608                                                       LDAP_OPT_X_TLS_CACERTDIR,
2609                                                       cargv[1] );
2610                         if ( rc )
2611                                 return rc;
2612
2613                 } else if ( !strcasecmp( cargv[0], "TLSCACertificateFile" ) ) {
2614                         rc = ldap_pvt_tls_set_option( NULL,
2615                                                       LDAP_OPT_X_TLS_CACERTFILE,
2616                                                       cargv[1] );
2617                         if ( rc )
2618                                 return rc;
2619                 } else if ( !strcasecmp( cargv[0], "TLSVerifyClient" ) ) {
2620                         if ( isdigit( (unsigned char) cargv[1][0] ) ) {
2621                                 i = atoi(cargv[1]);
2622                                 rc = ldap_pvt_tls_set_option( NULL,
2623                                                       LDAP_OPT_X_TLS_REQUIRE_CERT,
2624                                                       &i );
2625                         } else {
2626                                 rc = ldap_int_tls_config( NULL,
2627                                                       LDAP_OPT_X_TLS_REQUIRE_CERT,
2628                                                       cargv[1] );
2629                         }
2630
2631                         if ( rc )
2632                                 return rc;
2633
2634 #endif
2635
2636                 } else if ( !strcasecmp( cargv[0], "reverse-lookup" ) ) {
2637 #ifdef SLAPD_RLOOKUPS
2638                         if ( cargc < 2 ) {
2639 #ifdef NEW_LOGGING
2640                                 LDAP_LOG( CONFIG, INFO, 
2641                                         "%s: line %d: reverse-lookup: missing \"on\" or \"off\"\n",
2642                                         fname, lineno , 0 );
2643 #else
2644                                 Debug( LDAP_DEBUG_ANY,
2645 "%s: line %d: reverse-lookup: missing \"on\" or \"off\"\n",
2646                                         fname, lineno, 0 );
2647 #endif
2648                                 return( 1 );
2649                         }
2650
2651                         if ( !strcasecmp( cargv[1], "on" ) ) {
2652                                 use_reverse_lookup = 1;
2653                         } else if ( !strcasecmp( cargv[1], "off" ) ) {
2654                                 use_reverse_lookup = 0;
2655                         } else {
2656 #ifdef NEW_LOGGING
2657                                 LDAP_LOG( CONFIG, INFO, 
2658                                         "%s: line %d: reverse-lookup: "
2659                                         "must be \"on\" (default) or \"off\"\n", fname, lineno, 0 );
2660 #else
2661                                 Debug( LDAP_DEBUG_ANY,
2662 "%s: line %d: reverse-lookup: must be \"on\" (default) or \"off\"\n",
2663                                         fname, lineno, 0 );
2664 #endif
2665                                 return( 1 );
2666                         }
2667
2668 #else /* !SLAPD_RLOOKUPS */
2669 #ifdef NEW_LOGGING
2670                         LDAP_LOG( CONFIG, INFO, 
2671                                 "%s: line %d: reverse lookups "
2672                                 "are not configured (ignored).\n", fname, lineno , 0 );
2673 #else
2674                         Debug( LDAP_DEBUG_ANY,
2675 "%s: line %d: reverse lookups are not configured (ignored).\n",
2676                                 fname, lineno, 0 );
2677 #endif
2678 #endif /* !SLAPD_RLOOKUPS */
2679
2680                 /* Netscape plugins */
2681                 } else if ( strcasecmp( cargv[0], "plugin" ) == 0 ) {
2682 #if defined( LDAP_SLAPI )
2683
2684 #ifdef notdef /* allow global plugins, too */
2685                         /*
2686                          * a "plugin" line must be inside a database
2687                          * definition, since we implement pre-,post- 
2688                          * and extended operation plugins
2689                          */
2690                         if ( be == NULL ) {
2691 #ifdef NEW_LOGGING
2692                                 LDAP_LOG( CONFIG, INFO, 
2693                                         "%s: line %d: plugin line must appear "
2694                                         "insid a database definition.\n",
2695                                         fname, lineno, 0 );
2696 #else
2697                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: plugin "
2698                                     "line must appear inside a database "
2699                                     "definition\n", fname, lineno, 0 );
2700 #endif
2701                                 return( 1 );
2702                         }
2703 #endif /* notdef */
2704
2705                         if ( slapi_int_read_config( be, fname, lineno, cargc, cargv ) 
2706                                         != LDAP_SUCCESS )
2707                         {
2708 #ifdef NEW_LOGGING
2709                                 LDAP_LOG( CONFIG, INFO,
2710                                                 "%s: line %d: SLAPI config read failed.\n",
2711                                                 fname, lineno, 0 );
2712 #else
2713                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: SLAPI "
2714                                                 "config read failed.\n", fname, lineno, 0 );
2715 #endif
2716                                 return( 1 );
2717                         }
2718                         slapi_plugins_used++;
2719
2720 #else /* !defined( LDAP_SLAPI ) */
2721 #ifdef NEW_LOGGING
2722                         LDAP_LOG( CONFIG, INFO, 
2723                                 "%s: line %d: SLAPI not supported.\n",
2724                                 fname, lineno, 0 );
2725 #else
2726                         Debug( LDAP_DEBUG_ANY, "%s: line %d: SLAPI "
2727                             "not supported.\n", fname, lineno, 0 );
2728 #endif
2729                         return( 1 );
2730                         
2731 #endif /* !defined( LDAP_SLAPI ) */
2732
2733                 /* Netscape plugins */
2734                 } else if ( strcasecmp( cargv[0], "pluginlog" ) == 0 ) {
2735 #if defined( LDAP_SLAPI )
2736                         if ( cargc < 2 ) {
2737 #ifdef NEW_LOGGING
2738                                 LDAP_LOG( CONFIG, INFO, 
2739                                         "%s: line %d: missing file name "
2740                                         "in pluginlog <filename> line.\n",
2741                                         fname, lineno, 0 );
2742 #else
2743                                 Debug( LDAP_DEBUG_ANY, 
2744                                         "%s: line %d: missing file name "
2745                                         "in pluginlog <filename> line.\n",
2746                                         fname, lineno, 0 );
2747 #endif
2748                                 return( 1 );
2749                         }
2750
2751                         if ( slapi_log_file != NULL ) {
2752                                 ch_free( slapi_log_file );
2753                         }
2754
2755                         slapi_log_file = ch_strdup( cargv[1] );
2756 #endif /* !defined( LDAP_SLAPI ) */
2757
2758                 /* pass anything else to the current backend info/db config routine */
2759                 } else {
2760                         if ( bi != NULL ) {
2761                                 if ( bi->bi_config ) {
2762                                         rc = (*bi->bi_config)( bi, fname, lineno, cargc, cargv );
2763
2764                                         switch ( rc ) {
2765                                         case 0:
2766                                                 break;
2767
2768                                         case SLAP_CONF_UNKNOWN:
2769 #ifdef NEW_LOGGING
2770                                                 LDAP_LOG( CONFIG, INFO, 
2771                                                         "%s: line %d: unknown directive \"%s\" inside "
2772                                                         "backend info definition (ignored).\n",
2773                                                         fname, lineno, cargv[0] );
2774 #else
2775                                                 Debug( LDAP_DEBUG_ANY,
2776 "%s: line %d: unknown directive \"%s\" inside backend info definition (ignored)\n",
2777                                                         fname, lineno, cargv[0] );
2778 #endif
2779                                                 break;
2780
2781                                         default:
2782                                                 return 1;
2783                                         }
2784                                 }
2785
2786                         } else if ( be != NULL ) {
2787                                 if ( be->be_config ) {
2788                                         rc = (*be->be_config)( be, fname, lineno, cargc, cargv );
2789
2790                                         switch ( rc ) {
2791                                         case 0:
2792                                                 break;
2793
2794                                         case SLAP_CONF_UNKNOWN:
2795 #ifdef NEW_LOGGING
2796                                                 LDAP_LOG( CONFIG, INFO, 
2797                                                         "%s: line %d: unknown directive \"%s\" inside "
2798                                                         "backend database definition (ignored).\n",
2799                                                         fname, lineno, cargv[0] );
2800 #else
2801                                                 Debug( LDAP_DEBUG_ANY,
2802 "%s: line %d: unknown directive \"%s\" inside backend database definition (ignored)\n",
2803                                                         fname, lineno, cargv[0] );
2804 #endif
2805                                                 break;
2806
2807                                         default:
2808                                                 return 1;
2809                                         }
2810                                 }
2811
2812                         } else {
2813 #ifdef NEW_LOGGING
2814                                 LDAP_LOG( CONFIG, INFO, 
2815                                         "%s: line %d: unknown directive \"%s\" outside backend "
2816                                         "info and database definitions (ignored).\n",
2817                                         fname, lineno, cargv[0] );
2818 #else
2819                                 Debug( LDAP_DEBUG_ANY,
2820 "%s: line %d: unknown directive \"%s\" outside backend info and database definitions (ignored)\n",
2821                                     fname, lineno, cargv[0] );
2822 #endif
2823
2824                         }
2825                 }
2826                 free( saveline );
2827         }
2828         fclose( fp );
2829
2830         if ( depth == 0 ) ch_free( cargv );
2831
2832         if ( !global_schemadn.bv_val ) {
2833                 ber_str2bv( SLAPD_SCHEMA_DN, sizeof(SLAPD_SCHEMA_DN)-1, 1,
2834                         &global_schemadn );
2835                 dnNormalize( 0, NULL, NULL, &global_schemadn, &global_schemandn, NULL );
2836         }
2837
2838         if ( load_ucdata( NULL ) < 0 ) return 1;
2839         return( 0 );
2840 }
2841
2842 static int
2843 fp_parse_line(
2844     int         lineno,
2845     char        *line
2846 )
2847 {
2848         char *  token;
2849         char *  logline;
2850         char    logbuf[sizeof("pseudorootpw ***")];
2851
2852         cargc = 0;
2853         token = strtok_quote( line, " \t" );
2854
2855         logline = line;
2856
2857         if ( token && ( strcasecmp( token, "rootpw" ) == 0 ||
2858                 strcasecmp( token, "replica" ) == 0 ||          /* contains "credentials" */
2859                 strcasecmp( token, "bindpw" ) == 0 ||           /* used in back-ldap */
2860                 strcasecmp( token, "pseudorootpw" ) == 0 ||     /* used in back-meta */
2861                 strcasecmp( token, "dbpasswd" ) == 0 ) )        /* used in back-sql */
2862         {
2863                 snprintf( logline = logbuf, sizeof logbuf, "%s ***", token );
2864         }
2865
2866         if ( strtok_quote_ptr ) {
2867                 *strtok_quote_ptr = ' ';
2868         }
2869
2870 #ifdef NEW_LOGGING
2871         LDAP_LOG( CONFIG, DETAIL1, "line %d (%s)\n", lineno, logline , 0 );
2872 #else
2873         Debug( LDAP_DEBUG_CONFIG, "line %d (%s)\n", lineno, logline, 0 );
2874 #endif
2875
2876         if ( strtok_quote_ptr ) {
2877                 *strtok_quote_ptr = '\0';
2878         }
2879
2880         for ( ; token != NULL; token = strtok_quote( NULL, " \t" ) ) {
2881                 if ( cargc == cargv_size - 1 ) {
2882                         char **tmp;
2883                         tmp = ch_realloc( cargv, (cargv_size + ARGS_STEP) *
2884                                             sizeof(*cargv) );
2885                         if ( tmp == NULL ) {
2886 #ifdef NEW_LOGGING
2887                                 LDAP_LOG( CONFIG, ERR, "line %d: out of memory\n", lineno, 0,0 );
2888 #else
2889                                 Debug( LDAP_DEBUG_ANY, 
2890                                                 "line %d: out of memory\n", 
2891                                                 lineno, 0, 0 );
2892 #endif
2893                                 return -1;
2894                         }
2895                         cargv = tmp;
2896                         cargv_size += ARGS_STEP;
2897                 }
2898                 cargv[cargc++] = token;
2899         }
2900         cargv[cargc] = NULL;
2901         return 0;
2902 }
2903
2904 static char *
2905 strtok_quote( char *line, char *sep )
2906 {
2907         int             inquote;
2908         char            *tmp;
2909         static char     *next;
2910
2911         strtok_quote_ptr = NULL;
2912         if ( line != NULL ) {
2913                 next = line;
2914         }
2915         while ( *next && strchr( sep, *next ) ) {
2916                 next++;
2917         }
2918
2919         if ( *next == '\0' ) {
2920                 next = NULL;
2921                 return( NULL );
2922         }
2923         tmp = next;
2924
2925         for ( inquote = 0; *next; ) {
2926                 switch ( *next ) {
2927                 case '"':
2928                         if ( inquote ) {
2929                                 inquote = 0;
2930                         } else {
2931                                 inquote = 1;
2932                         }
2933                         AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
2934                         break;
2935
2936                 case '\\':
2937                         if ( next[1] )
2938                                 AC_MEMCPY( next,
2939                                             next + 1, strlen( next + 1 ) + 1 );
2940                         next++;         /* dont parse the escaped character */
2941                         break;
2942
2943                 default:
2944                         if ( ! inquote ) {
2945                                 if ( strchr( sep, *next ) != NULL ) {
2946                                         strtok_quote_ptr = next;
2947                                         *next++ = '\0';
2948                                         return( tmp );
2949                                 }
2950                         }
2951                         next++;
2952                         break;
2953                 }
2954         }
2955
2956         return( tmp );
2957 }
2958
2959 static char     buf[BUFSIZ];
2960 static char     *line;
2961 static size_t lmax, lcur;
2962
2963 #define CATLINE( buf ) \
2964         do { \
2965                 size_t len = strlen( buf ); \
2966                 while ( lcur + len + 1 > lmax ) { \
2967                         lmax += BUFSIZ; \
2968                         line = (char *) ch_realloc( line, lmax ); \
2969                 } \
2970                 strcpy( line + lcur, buf ); \
2971                 lcur += len; \
2972         } while( 0 )
2973
2974 static char *
2975 fp_getline( FILE *fp, int *lineno )
2976 {
2977         char            *p;
2978
2979         lcur = 0;
2980         CATLINE( buf );
2981         (*lineno)++;
2982
2983         /* hack attack - keeps us from having to keep a stack of bufs... */
2984         if ( strncasecmp( line, "include", 7 ) == 0 ) {
2985                 buf[0] = '\0';
2986                 return( line );
2987         }
2988
2989         while ( fgets( buf, sizeof(buf), fp ) != NULL ) {
2990                 /* trim off \r\n or \n */
2991                 if ( (p = strchr( buf, '\n' )) != NULL ) {
2992                         if( p > buf && p[-1] == '\r' ) --p;
2993                         *p = '\0';
2994                 }
2995                 
2996                 /* trim off trailing \ and append the next line */
2997                 if ( line[ 0 ] != '\0' 
2998                                 && (p = line + strlen( line ) - 1)[ 0 ] == '\\'
2999                                 && p[ -1 ] != '\\' ) {
3000                         p[ 0 ] = '\0';
3001                         lcur--;
3002
3003                 } else {
3004                         if ( ! isspace( (unsigned char) buf[0] ) ) {
3005                                 return( line );
3006                         }
3007
3008                         /* change leading whitespace to a space */
3009                         buf[0] = ' ';
3010                 }
3011
3012                 CATLINE( buf );
3013                 (*lineno)++;
3014         }
3015         buf[0] = '\0';
3016
3017         return( line[0] ? line : NULL );
3018 }
3019
3020 static void
3021 fp_getline_init( int *lineno )
3022 {
3023         *lineno = -1;
3024         buf[0] = '\0';
3025 }
3026
3027 /* Loads ucdata, returns 1 if loading, 0 if already loaded, -1 on error */
3028 static int
3029 load_ucdata( char *path )
3030 {
3031 #if 0
3032         static int loaded = 0;
3033         int err;
3034         
3035         if ( loaded ) {
3036                 return( 0 );
3037         }
3038         err = ucdata_load( path ? path : SLAPD_DEFAULT_UCDATA, UCDATA_ALL );
3039         if ( err ) {
3040 #ifdef NEW_LOGGING
3041                 LDAP_LOG( CONFIG, CRIT, 
3042                         "load_ucdata: Error %d loading ucdata.\n", err, 0,0 );
3043 #else
3044                 Debug( LDAP_DEBUG_ANY, "error loading ucdata (error %d)\n",
3045                        err, 0, 0 );
3046 #endif
3047
3048                 return( -1 );
3049         }
3050         loaded = 1;
3051         return( 1 );
3052 #else
3053         /* ucdata is now hardcoded */
3054         return( 0 );
3055 #endif
3056 }
3057
3058 void
3059 config_destroy( )
3060 {
3061         ucdata_unload( UCDATA_ALL );
3062         free( global_schemandn.bv_val );
3063         free( global_schemadn.bv_val );
3064         free( line );
3065         if ( slapd_args_file )
3066                 free ( slapd_args_file );
3067         if ( slapd_pid_file )
3068                 free ( slapd_pid_file );
3069         if ( default_passwd_hash )
3070                 ldap_charray_free( default_passwd_hash );
3071         acl_destroy( global_acl, NULL );
3072 }
3073
3074 static int
3075 add_syncrepl(
3076         Backend *be,
3077         char    **cargv,
3078         int     cargc
3079 )
3080 {
3081         syncinfo_t *si;
3082         syncinfo_t *si_entry;
3083         int     rc = 0;
3084         int duplicated_replica_id = 0;
3085
3086         si = (syncinfo_t *) ch_calloc( 1, sizeof( syncinfo_t ) );
3087
3088         if ( si == NULL ) {
3089 #ifdef NEW_LOGGING
3090                 LDAP_LOG( CONFIG, ERR, "out of memory in add_syncrepl\n", 0, 0,0 );
3091 #else
3092                 Debug( LDAP_DEBUG_ANY, "out of memory in add_syncrepl\n", 0, 0, 0 );
3093 #endif
3094                 return 1;
3095         }
3096
3097         si->si_tls = SYNCINFO_TLS_OFF;
3098         if ( be->be_rootndn.bv_val ) {
3099                 ber_dupbv( &si->si_updatedn, &be->be_rootndn );
3100         }
3101         si->si_bindmethod = LDAP_AUTH_SIMPLE;
3102         si->si_schemachecking = 0;
3103         ber_str2bv( "(objectclass=*)", STRLENOF("(objectclass=*)"), 0,
3104                 &si->si_filterstr );
3105         si->si_base.bv_val = NULL;
3106         si->si_scope = LDAP_SCOPE_SUBTREE;
3107         si->si_attrsonly = 0;
3108         si->si_attrs = (char **) ch_calloc( 1, sizeof( char * ));
3109         si->si_attrs[0] = NULL;
3110         si->si_type = LDAP_SYNC_REFRESH_ONLY;
3111         si->si_interval = 86400;
3112         si->si_retryinterval = 0;
3113         si->si_retrynum_init = 0;
3114         si->si_retrynum = 0;
3115         si->si_syncCookie.ctxcsn = NULL;
3116         si->si_syncCookie.octet_str = NULL;
3117         si->si_syncCookie.sid = -1;
3118         si->si_manageDSAit = 0;
3119         si->si_tlimit = 0;
3120         si->si_slimit = 0;
3121         si->si_syncUUID_ndn.bv_val = NULL;
3122         si->si_syncUUID_ndn.bv_len = 0;
3123
3124         si->si_presentlist = NULL;
3125         LDAP_LIST_INIT( &si->si_nonpresentlist );
3126
3127         rc = parse_syncrepl_line( cargv, cargc, si );
3128
3129         LDAP_STAILQ_FOREACH( si_entry, &be->be_syncinfo, si_next ) {
3130                 if ( si->si_rid == si_entry->si_rid ) {
3131 #ifdef NEW_LOGGING
3132                         LDAP_LOG( CONFIG, ERR,
3133                                 "add_syncrepl: duplicated replica id\n", 0, 0,0 );
3134 #else
3135                         Debug( LDAP_DEBUG_ANY,
3136                                 "add_syncrepl: duplicated replica id\n",0, 0, 0 );
3137 #endif
3138                         duplicated_replica_id = 1;
3139                         break;
3140                 }
3141         }
3142
3143         if ( rc < 0 || duplicated_replica_id ) {
3144                 syncinfo_t *si_entry;
3145                 /* Something bad happened - back out */
3146 #ifdef NEW_LOGGING
3147                 LDAP_LOG( CONFIG, ERR, "failed to add syncinfo\n", 0, 0,0 );
3148 #else
3149                 Debug( LDAP_DEBUG_ANY, "failed to add syncinfo\n", 0, 0, 0 );
3150 #endif
3151
3152                 /* If error, remove all syncinfo */
3153                 LDAP_STAILQ_FOREACH( si_entry, &be->be_syncinfo, si_next ) {
3154                         if ( si_entry->si_updatedn.bv_val ) {
3155                                 ch_free( si->si_updatedn.bv_val );
3156                         }
3157                         if ( si_entry->si_filterstr.bv_val ) {
3158                                 ch_free( si->si_filterstr.bv_val );
3159                         }
3160                         if ( si_entry->si_attrs ) {
3161                                 int i = 0;
3162                                 while ( si_entry->si_attrs[i] != NULL ) {
3163                                         ch_free( si_entry->si_attrs[i] );
3164                                         i++;
3165                                 }
3166                                 ch_free( si_entry->si_attrs );
3167                         }
3168                 }
3169
3170                 while ( !LDAP_STAILQ_EMPTY( &be->be_syncinfo )) {
3171                         si_entry = LDAP_STAILQ_FIRST( &be->be_syncinfo );
3172                         LDAP_STAILQ_REMOVE_HEAD( &be->be_syncinfo, si_next );
3173                         ch_free( si_entry );
3174                 }
3175                 LDAP_STAILQ_INIT( &be->be_syncinfo );
3176                 return 1;
3177         } else {
3178 #ifdef NEW_LOGGING
3179                 LDAP_LOG ( CONFIG, RESULTS,
3180                         "add_syncrepl: Config: ** successfully added syncrepl \"%s\"\n",
3181                         si->si_provideruri == NULL ? "(null)" : si->si_provideruri, 0, 0 );
3182 #else
3183                 Debug( LDAP_DEBUG_CONFIG,
3184                         "Config: ** successfully added syncrepl \"%s\"\n",
3185                         si->si_provideruri == NULL ? "(null)" : si->si_provideruri, 0, 0 );
3186 #endif
3187                 if ( !si->si_schemachecking ) {
3188                         SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NO_SCHEMA_CHECK;
3189                 }
3190                 si->si_be = be;
3191                 LDAP_STAILQ_INSERT_TAIL( &be->be_syncinfo, si, si_next );
3192                 return 0;
3193         }
3194 }
3195
3196 #define IDSTR                   "rid"
3197 #define PROVIDERSTR             "provider"
3198 #define SUFFIXSTR               "suffix"
3199 #define UPDATEDNSTR             "updatedn"
3200 #define BINDMETHSTR             "bindmethod"
3201 #define SIMPLESTR               "simple"
3202 #define SASLSTR                 "sasl"
3203 #define BINDDNSTR               "binddn"
3204 #define CREDSTR                 "credentials"
3205 #define OLDAUTHCSTR             "bindprincipal"
3206 #define AUTHCSTR                "authcID"
3207 #define AUTHZSTR                "authzID"
3208 #define SRVTABSTR               "srvtab"
3209 #define SASLMECHSTR             "saslmech"
3210 #define REALMSTR                "realm"
3211 #define SECPROPSSTR             "secprops"
3212 #define STARTTLSSTR             "starttls"
3213 #define CRITICALSTR             "critical"
3214
3215 #define SCHEMASTR               "schemachecking"
3216 #define FILTERSTR               "filter"
3217 #define SEARCHBASESTR   "searchbase"
3218 #define SCOPESTR                "scope"
3219 #define ATTRSSTR                "attrs"
3220 #define ATTRSONLYSTR    "attrsonly"
3221 #define TYPESTR                 "type"
3222 #define INTERVALSTR             "interval"
3223 #define LASTMODSTR              "lastmod"
3224 #define LMREQSTR                "req"
3225 #define LMGENSTR                "gen"
3226 #define LMNOSTR                 "no"
3227 #define MANAGEDSAITSTR  "manageDSAit"
3228 #define SLIMITSTR               "sizelimit"
3229 #define TLIMITSTR               "timelimit"
3230
3231 #define RETRYSTR                "retry"
3232
3233 #define GOT_ID                  0x0001
3234 #define GOT_PROVIDER    0x0002
3235 #define GOT_METHOD              0x0004
3236 #define GOT_ALL                 0x0007
3237
3238 static int
3239 parse_syncrepl_line(
3240         char            **cargv,
3241         int             cargc,
3242         syncinfo_t      *si
3243 )
3244 {
3245         int     gots = 0;
3246         int     i, j;
3247         char    *hp, *val;
3248         int     nr_attr = 0;
3249
3250         for ( i = 1; i < cargc; i++ ) {
3251                 if ( !strncasecmp( cargv[ i ], IDSTR, sizeof( IDSTR ) - 1 )) {
3252                         int tmp;
3253                         /* '\0' string terminator accounts for '=' */
3254                         val = cargv[ i ] + sizeof( IDSTR );
3255                         tmp= atoi( val );
3256                         if ( tmp >= 1000 || tmp < 0 ) {
3257                                 fprintf( stderr, "Error: parse_syncrepl_line: "
3258                                          "syncrepl id %d is out of range [0..999]\n", tmp );
3259                                 return -1;
3260                         }
3261                         si->si_rid = tmp;
3262                         gots |= GOT_ID;
3263                 } else if ( !strncasecmp( cargv[ i ], PROVIDERSTR,
3264                                         sizeof( PROVIDERSTR ) - 1 )) {
3265                         val = cargv[ i ] + sizeof( PROVIDERSTR );
3266                         si->si_provideruri = ch_strdup( val );
3267                         si->si_provideruri_bv = (BerVarray)
3268                                 ch_calloc( 2, sizeof( struct berval ));
3269                         ber_str2bv( si->si_provideruri, strlen( si->si_provideruri ),
3270                                 0, &si->si_provideruri_bv[0] );
3271                         si->si_provideruri_bv[1].bv_len = 0;
3272                         si->si_provideruri_bv[1].bv_val = NULL;
3273                         gots |= GOT_PROVIDER;
3274                 } else if ( !strncasecmp( cargv[ i ], STARTTLSSTR,
3275                         sizeof(STARTTLSSTR) - 1 ) )
3276                 {
3277                         val = cargv[ i ] + sizeof( STARTTLSSTR );
3278                         if( !strcasecmp( val, CRITICALSTR ) ) {
3279                                 si->si_tls = SYNCINFO_TLS_CRITICAL;
3280                         } else {
3281                                 si->si_tls = SYNCINFO_TLS_ON;
3282                         }
3283                 } else if ( !strncasecmp( cargv[ i ],
3284                         UPDATEDNSTR, sizeof( UPDATEDNSTR ) - 1 ) )
3285                 {
3286                         struct berval updatedn = {0, NULL};
3287                         val = cargv[ i ] + sizeof( UPDATEDNSTR );
3288                         ber_str2bv( val, 0, 0, &updatedn );
3289                         ch_free( si->si_updatedn.bv_val );
3290                         dnNormalize( 0, NULL, NULL, &updatedn, &si->si_updatedn, NULL );
3291                 } else if ( !strncasecmp( cargv[ i ], BINDMETHSTR,
3292                                 sizeof( BINDMETHSTR ) - 1 ) )
3293                 {
3294                         val = cargv[ i ] + sizeof( BINDMETHSTR );
3295                         if ( !strcasecmp( val, SIMPLESTR )) {
3296                                 si->si_bindmethod = LDAP_AUTH_SIMPLE;
3297                                 gots |= GOT_METHOD;
3298                         } else if ( !strcasecmp( val, SASLSTR )) {
3299 #ifdef HAVE_CYRUS_SASL
3300                                 si->si_bindmethod = LDAP_AUTH_SASL;
3301                                 gots |= GOT_METHOD;
3302 #else /* HAVE_CYRUS_SASL */
3303                                 fprintf( stderr, "Error: parse_syncrepl_line: "
3304                                         "not compiled with SASL support\n" );
3305                                 return 1;
3306 #endif /* HAVE_CYRUS_SASL */
3307                         } else {
3308                                 si->si_bindmethod = -1;
3309                         }
3310                 } else if ( !strncasecmp( cargv[ i ],
3311                                 BINDDNSTR, sizeof( BINDDNSTR ) - 1 ) ) {
3312                         val = cargv[ i ] + sizeof( BINDDNSTR );
3313                         si->si_binddn = ch_strdup( val );
3314                 } else if ( !strncasecmp( cargv[ i ],
3315                                 CREDSTR, sizeof( CREDSTR ) - 1 ) ) {
3316                         val = cargv[ i ] + sizeof( CREDSTR );
3317                         si->si_passwd = ch_strdup( val );
3318                 } else if ( !strncasecmp( cargv[ i ],
3319                                 SASLMECHSTR, sizeof( SASLMECHSTR ) - 1 ) ) {
3320                         val = cargv[ i ] + sizeof( SASLMECHSTR );
3321                         si->si_saslmech = ch_strdup( val );
3322                 } else if ( !strncasecmp( cargv[ i ],
3323                                 SECPROPSSTR, sizeof( SECPROPSSTR ) - 1 ) ) {
3324                         val = cargv[ i ] + sizeof( SECPROPSSTR );
3325                         si->si_secprops = ch_strdup( val );
3326                 } else if ( !strncasecmp( cargv[ i ],
3327                                 REALMSTR, sizeof( REALMSTR ) - 1 ) ) {
3328                         val = cargv[ i ] + sizeof( REALMSTR );
3329                         si->si_realm = ch_strdup( val );
3330                 } else if ( !strncasecmp( cargv[ i ],
3331                                 AUTHCSTR, sizeof( AUTHCSTR ) - 1 ) ) {
3332                         val = cargv[ i ] + sizeof( AUTHCSTR );
3333                         si->si_authcId = ch_strdup( val );
3334                 } else if ( !strncasecmp( cargv[ i ],
3335                                 OLDAUTHCSTR, sizeof( OLDAUTHCSTR ) - 1 ) ) {
3336                         /* Old authcID is provided for some backwards compatibility */
3337                         val = cargv[ i ] + sizeof( OLDAUTHCSTR );
3338                         si->si_authcId = ch_strdup( val );
3339                 } else if ( !strncasecmp( cargv[ i ],
3340                                 AUTHZSTR, sizeof( AUTHZSTR ) - 1 ) ) {
3341                         val = cargv[ i ] + sizeof( AUTHZSTR );
3342                         si->si_authzId = ch_strdup( val );
3343                 } else if ( !strncasecmp( cargv[ i ],
3344                                 SCHEMASTR, sizeof( SCHEMASTR ) - 1 ) )
3345                 {
3346                         val = cargv[ i ] + sizeof( SCHEMASTR );
3347                         if ( !strncasecmp( val, "on", STRLENOF( "on" ) )) {
3348                                 si->si_schemachecking = 1;
3349                         } else if ( !strncasecmp( val, "off", STRLENOF( "off" ) ) ) {
3350                                 si->si_schemachecking = 0;
3351                         } else {
3352                                 si->si_schemachecking = 1;
3353                         }
3354                 } else if ( !strncasecmp( cargv[ i ],
3355                         FILTERSTR, sizeof( FILTERSTR ) - 1 ) )
3356                 {
3357                         val = cargv[ i ] + sizeof( FILTERSTR );
3358                         ber_str2bv( val, 0, 1, &si->si_filterstr );
3359                 } else if ( !strncasecmp( cargv[ i ],
3360                         SEARCHBASESTR, sizeof( SEARCHBASESTR ) - 1 ) )
3361                 {
3362                         struct berval bv;
3363                         val = cargv[ i ] + sizeof( SEARCHBASESTR );
3364                         if ( si->si_base.bv_val ) {
3365                                 ch_free( si->si_base.bv_val );
3366                         }
3367                         ber_str2bv( val, 0, 0, &bv );
3368                         if ( dnNormalize( 0, NULL, NULL, &bv, &si->si_base, NULL )) {
3369                                 fprintf( stderr, "Invalid base DN \"%s\"\n", val );
3370                                 return 1;
3371                         }
3372                 } else if ( !strncasecmp( cargv[ i ],
3373                         SCOPESTR, sizeof( SCOPESTR ) - 1 ) )
3374                 {
3375                         val = cargv[ i ] + sizeof( SCOPESTR );
3376                         if ( !strncasecmp( val, "base", STRLENOF( "base" ) )) {
3377                                 si->si_scope = LDAP_SCOPE_BASE;
3378                         } else if ( !strncasecmp( val, "one", STRLENOF( "one" ) )) {
3379                                 si->si_scope = LDAP_SCOPE_ONELEVEL;
3380 #ifdef LDAP_SCOPE_SUBORDINATE
3381                         } else if ( !strcasecmp( val, "subordinate" ) ||
3382                                 !strcasecmp( val, "children" ))
3383                         {
3384                                 si->si_scope = LDAP_SCOPE_SUBORDINATE;
3385 #endif
3386                         } else if ( !strncasecmp( val, "sub", STRLENOF( "sub" ) )) {
3387                                 si->si_scope = LDAP_SCOPE_SUBTREE;
3388                         } else {
3389                                 fprintf( stderr, "Error: parse_syncrepl_line: "
3390                                         "unknown scope \"%s\"\n", val);
3391                                 return 1;
3392                         }
3393                 } else if ( !strncasecmp( cargv[ i ],
3394                         ATTRSONLYSTR, sizeof( ATTRSONLYSTR ) - 1 ) )
3395                 {
3396                         si->si_attrsonly = 1;
3397                 } else if ( !strncasecmp( cargv[ i ],
3398                         ATTRSSTR, sizeof( ATTRSSTR ) - 1 ) )
3399                 {
3400                         val = cargv[ i ] + sizeof( ATTRSSTR );
3401                         str2clist( &si->si_attrs, val, "," );
3402                 } else if ( !strncasecmp( cargv[ i ],
3403                         TYPESTR, sizeof( TYPESTR ) - 1 ) )
3404                 {
3405                         val = cargv[ i ] + sizeof( TYPESTR );
3406                         if ( !strncasecmp( val, "refreshOnly", STRLENOF("refreshOnly") )) {
3407                                 si->si_type = LDAP_SYNC_REFRESH_ONLY;
3408                         } else if ( !strncasecmp( val, "refreshAndPersist",
3409                                 STRLENOF("refreshAndPersist") ))
3410                         {
3411                                 si->si_type = LDAP_SYNC_REFRESH_AND_PERSIST;
3412                                 si->si_interval = 60;
3413                         } else {
3414                                 fprintf( stderr, "Error: parse_syncrepl_line: "
3415                                         "unknown sync type \"%s\"\n", val);
3416                                 return 1;
3417                         }
3418                 } else if ( !strncasecmp( cargv[ i ],
3419                         INTERVALSTR, sizeof( INTERVALSTR ) - 1 ) )
3420                 {
3421                         val = cargv[ i ] + sizeof( INTERVALSTR );
3422                         if ( si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ) {
3423                                 si->si_interval = 0;
3424                         } else {
3425                                 char *hstr;
3426                                 char *mstr;
3427                                 char *dstr;
3428                                 char *sstr;
3429                                 int dd, hh, mm, ss;
3430                                 dstr = val;
3431                                 hstr = strchr( dstr, ':' );
3432                                 if ( hstr == NULL ) {
3433                                         fprintf( stderr, "Error: parse_syncrepl_line: "
3434                                                 "invalid interval \"%s\"\n", val );
3435                                         return 1;
3436                                 }
3437                                 *hstr++ = '\0';
3438                                 mstr = strchr( hstr, ':' );
3439                                 if ( mstr == NULL ) {
3440                                         fprintf( stderr, "Error: parse_syncrepl_line: "
3441                                                 "invalid interval \"%s\"\n", val );
3442                                         return 1;
3443                                 }
3444                                 *mstr++ = '\0';
3445                                 sstr = strchr( mstr, ':' );
3446                                 if ( sstr == NULL ) {
3447                                         fprintf( stderr, "Error: parse_syncrepl_line: "
3448                                                 "invalid interval \"%s\"\n", val );
3449                                         return 1;
3450                                 }
3451                                 *sstr++ = '\0';
3452
3453                                 dd = atoi( dstr );
3454                                 hh = atoi( hstr );
3455                                 mm = atoi( mstr );
3456                                 ss = atoi( sstr );
3457                                 if (( hh > 24 ) || ( hh < 0 ) ||
3458                                         ( mm > 60 ) || ( mm < 0 ) ||
3459                                         ( ss > 60 ) || ( ss < 0 ) || ( dd < 0 )) {
3460                                         fprintf( stderr, "Error: parse_syncrepl_line: "
3461                                                 "invalid interval \"%s\"\n", val );
3462                                         return 1;
3463                                 }
3464                                 si->si_interval = (( dd * 24 + hh ) * 60 + mm ) * 60 + ss;
3465                         }
3466                         if ( si->si_interval < 0 ) {
3467                                 fprintf( stderr, "Error: parse_syncrepl_line: "
3468                                         "invalid interval \"%ld\"\n",
3469                                         (long) si->si_interval);
3470                                 return 1;
3471                         }
3472                 } else if ( !strncasecmp( cargv[ i ],
3473                         RETRYSTR, sizeof( RETRYSTR ) - 1 ) )
3474                 {
3475                         char *str;
3476                         char **retry_list;
3477                         int j, k, n;
3478
3479                         val = cargv[ i ] + sizeof( RETRYSTR );
3480                         retry_list = (char **) ch_calloc( 1, sizeof( char * ));
3481                         retry_list[0] = NULL;
3482
3483                         str2clist( &retry_list, val, " ,\t" );
3484
3485                         for ( k = 0; retry_list && retry_list[k]; k++ ) ;
3486                         n = k / 2;
3487                         if ( k % 2 ) {
3488                                 fprintf( stderr,
3489                                                 "Error: incomplete syncrepl retry list\n" );
3490                                 for ( k = 0; retry_list && retry_list[k]; k++ ) {
3491                                         ch_free( retry_list[k] );
3492                                 }
3493                                 ch_free( retry_list );
3494                                 exit( EXIT_FAILURE );
3495                         }
3496                         si->si_retryinterval = (time_t *) ch_calloc( n + 1, sizeof( time_t ));
3497                         si->si_retrynum = (int *) ch_calloc( n + 1, sizeof( int ));
3498                         si->si_retrynum_init = (int *) ch_calloc( n + 1, sizeof( int ));
3499                         for ( j = 0; j < n; j++ ) {
3500                                 si->si_retryinterval[j] = atoi( retry_list[j*2] );
3501                                 if ( *retry_list[j*2+1] == '+' ) {
3502                                         si->si_retrynum_init[j] = -1;
3503                                         si->si_retrynum[j] = -1;
3504                                         j++;
3505                                         break;
3506                                 } else {
3507                                         si->si_retrynum_init[j] = atoi( retry_list[j*2+1] );
3508                                         si->si_retrynum[j] = atoi( retry_list[j*2+1] );
3509                                 }
3510                         }
3511                         si->si_retrynum_init[j] = -2;
3512                         si->si_retrynum[j] = -2;
3513                         si->si_retryinterval[j] = 0;
3514                         
3515                         for ( k = 0; retry_list && retry_list[k]; k++ ) {
3516                                 ch_free( retry_list[k] );
3517                         }
3518                         ch_free( retry_list );
3519                 } else if ( !strncasecmp( cargv[ i ],
3520                         MANAGEDSAITSTR, sizeof( MANAGEDSAITSTR ) - 1 ) )
3521                 {
3522                         val = cargv[ i ] + sizeof( MANAGEDSAITSTR );
3523                         si->si_manageDSAit = atoi( val );
3524                 } else if ( !strncasecmp( cargv[ i ],
3525                         SLIMITSTR, sizeof( SLIMITSTR ) - 1 ) )
3526                 {
3527                         val = cargv[ i ] + sizeof( SLIMITSTR );
3528                         si->si_slimit = atoi( val );
3529                 } else if ( !strncasecmp( cargv[ i ],
3530                         TLIMITSTR, sizeof( TLIMITSTR ) - 1 ) )
3531                 {
3532                         val = cargv[ i ] + sizeof( TLIMITSTR );
3533                         si->si_tlimit = atoi( val );
3534                 } else {
3535                         fprintf( stderr, "Error: parse_syncrepl_line: "
3536                                 "unknown keyword \"%s\"\n", cargv[ i ] );
3537                 }
3538         }
3539
3540         if ( gots != GOT_ALL ) {
3541                 fprintf( stderr,
3542                         "Error: Malformed \"syncrepl\" line in slapd config file" );
3543                 return -1;
3544         }
3545
3546         return 0;
3547 }
3548
3549 char **
3550 str2clist( char ***out, char *in, const char *brkstr )
3551 {
3552         char    *str;
3553         char    *s;
3554         char    *lasts;
3555         int     i, j;
3556         const char *text;
3557         char    **new;
3558
3559         /* find last element in list */
3560         for (i = 0; *out && *out[i]; i++);
3561
3562         /* protect the input string from strtok */
3563         str = ch_strdup( in );
3564
3565         if ( *str == '\0' ) {
3566                 free( str );
3567                 return( *out );
3568         }
3569
3570         /* Count words in string */
3571         j=1;
3572         for ( s = str; *s; s++ ) {
3573                 if ( strchr( brkstr, *s ) != NULL ) {
3574                         j++;
3575                 }
3576         }
3577
3578         *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
3579         new = *out + i;
3580         for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
3581                 s != NULL;
3582                 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
3583         {
3584                 *new = ch_strdup( s );
3585                 new++;
3586         }
3587
3588         *new = NULL;
3589         free( str );
3590         return( *out );
3591 }