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