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