1 /* config.c - configuration file handling routines */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2005 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
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>.
16 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
17 * All rights reserved.
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.
31 #include <ac/string.h>
33 #include <ac/signal.h>
34 #include <ac/socket.h>
39 #include "slapi/slapi.h"
44 #endif /* HAVE_LIMITS_H */
47 #endif /* ! PATH_MAX */
53 * defaults for various global variables
55 slap_mask_t global_allows = 0;
56 slap_mask_t global_disallows = 0;
57 int global_gentlehup = 0;
58 int global_idletimeout = 0;
59 char *global_host = NULL;
60 char *global_realm = NULL;
61 char *ldap_srvtab = "";
62 char **default_passwd_hash = NULL;
63 struct berval default_search_base = BER_BVNULL;
64 struct berval default_search_nbase = BER_BVNULL;
66 ber_len_t sockbuf_max_incoming = SLAP_SB_MAX_INCOMING_DEFAULT;
67 ber_len_t sockbuf_max_incoming_auth= SLAP_SB_MAX_INCOMING_AUTH;
69 int slap_conn_max_pending = SLAP_CONN_MAX_PENDING_DEFAULT;
70 int slap_conn_max_pending_auth = SLAP_CONN_MAX_PENDING_AUTH;
72 char *slapd_pid_file = NULL;
73 char *slapd_args_file = NULL;
75 char *strtok_quote_ptr;
77 int use_reverse_lookup = 0;
79 /* These do nothing in slapd, they're kept only to make them
80 * editable in back-config
82 static char *replica_pidFile, *replica_argsFile;
83 static int replicationInterval;
85 static char *passwd_salt;
86 static char *logfileName;
89 int slapi_plugins_used = 0;
92 static int fp_getline(FILE *fp, ConfigArgs *c);
93 static void fp_getline_init(ConfigArgs *c);
94 static int fp_parse_line(ConfigArgs *c);
96 static char *strtok_quote(char *line, char *sep);
99 int read_config_file(const char *fname, int depth, ConfigArgs *cf);
101 static int add_syncrepl LDAP_P(( Backend *, char **, int ));
102 static int parse_syncrepl_line LDAP_P(( char **, int, syncinfo_t *));
103 static void syncrepl_unparse LDAP_P (( syncinfo_t *, struct berval *));
105 /* All of these table entries and handlers really belong
106 * in back-config, only the parser/table engine belongs here.
108 /* state info for back-config */
109 static ConfigFile cf_prv, *cfn = &cf_prv;
111 static int config_fname(ConfigArgs *c);
112 static int config_generic(ConfigArgs *c);
113 static int config_search_base(ConfigArgs *c);
114 static int config_passwd_hash(ConfigArgs *c);
115 static int config_schema_dn(ConfigArgs *c);
116 static int config_sizelimit(ConfigArgs *c);
117 static int config_timelimit(ConfigArgs *c);
118 static int config_limits(ConfigArgs *c);
119 static int config_overlay(ConfigArgs *c);
120 static int config_suffix(ConfigArgs *c);
121 static int config_deref_depth(ConfigArgs *c);
122 static int config_rootdn(ConfigArgs *c);
123 static int config_rootpw(ConfigArgs *c);
124 static int config_restrict(ConfigArgs *c);
125 static int config_allows(ConfigArgs *c);
126 static int config_disallows(ConfigArgs *c);
127 static int config_requires(ConfigArgs *c);
128 static int config_security(ConfigArgs *c);
129 static int config_referral(ConfigArgs *c);
130 static int config_loglevel(ConfigArgs *c);
131 static int config_syncrepl(ConfigArgs *c);
132 static int config_replica(ConfigArgs *c);
133 static int config_updatedn(ConfigArgs *c);
134 static int config_updateref(ConfigArgs *c);
135 static int config_include(ConfigArgs *c);
137 static int config_tls_option(ConfigArgs *c);
138 static int config_tls_config(ConfigArgs *c);
187 static OidRec OidMacros[] = {
188 /* OpenLDAProot:666.11.1 */
189 { "OLcfg", "1.3.6.1.4.1.4203.666.11.1" },
190 { "OLcfgAt", "OLcfg:3" },
191 { "OLcfgOc", "OLcfg:4" },
192 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
193 { "OMsInteger", "OMsyn:2" },
194 { "OMsBoolean", "OMsyn:7" },
195 { "OMsDN", "OMsyn:12" },
196 { "OMsDirectoryString", "OMsyn:15" },
197 { "OMsOctetString", "OMsyn:40" },
201 /* alphabetical ordering */
203 static ConfigTable SystemConfiguration[] = {
204 /* This attr is read-only */
205 { "", "", 0, 0, 0, ARG_MAGIC,
206 &config_fname, "( OLcfgAt:78 NAME 'olcConfigFile' "
207 "DESC 'File for slapd configuration directives' "
208 "EQUALITY caseIgnoreMatch "
209 "SYNTAX OMsDirectoryString )", NULL, NULL },
210 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
211 &config_generic, "( OLcfgAt:1 NAME 'olcAccess' "
212 "DESC 'Access Control List' "
213 "EQUALITY caseIgnoreMatch "
214 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
215 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
216 &config_allows, "( OLcfgAt:2 NAME 'olcAllows' "
217 "DESC 'Allowed set of deprecated features' "
218 "EQUALITY caseIgnoreMatch "
219 "SYNTAX OMsDirectoryString )", NULL, NULL },
220 { "argsfile", "file", 2, 2, 0, ARG_STRING,
221 &slapd_args_file, "( OLcfgAt:3 NAME 'olcArgsFile' "
222 "DESC 'File for slapd command line options' "
223 "EQUALITY caseIgnoreMatch "
224 "SYNTAX OMsDirectoryString )", NULL, NULL },
225 /* Use standard 'attributeTypes' attr */
226 { "attribute", "attribute", 2, 0, 9, ARG_PAREN|ARG_MAGIC|CFG_ATTR,
227 &config_generic, NULL, NULL, NULL },
228 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
229 &config_generic, "( OLcfgAt:5 NAME 'olcAttributeOptions' "
230 "EQUALITY caseIgnoreMatch "
231 "SYNTAX OMsDirectoryString )", NULL, NULL },
232 { "authid-rewrite", NULL, 2, 0, 0,
233 #ifdef SLAP_AUTH_REWRITE
234 ARG_MAGIC|CFG_REWRITE, &config_generic,
238 "( OLcfgAt:6 NAME 'olcAuthIDRewrite' "
239 "EQUALITY caseIgnoreMatch "
240 "SYNTAX OMsDirectoryString )", NULL, NULL },
241 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
242 &config_generic, "( OLcfgAt:7 NAME 'olcAuthzPolicy' "
243 "EQUALITY caseIgnoreMatch "
244 "SYNTAX OMsDirectoryString )", NULL, NULL },
245 { "authz-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
246 &config_generic, "( OLcfgAt:8 NAME 'olcAuthzRegexp' "
247 "EQUALITY caseIgnoreMatch "
248 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
249 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
250 &config_generic, "( OLcfgAt:9 NAME 'olcBackend' "
251 "DESC 'A type of backend' "
252 "EQUALITY caseIgnoreMatch "
253 "SYNTAX OMsDirectoryString )", NULL, NULL },
254 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_CONCUR,
255 &config_generic, "( OLcfgAt:10 NAME 'olcConcurrency' "
256 "SYNTAX OMsInteger )", NULL, NULL },
257 { "conn_max_pending", "max", 2, 2, 0, ARG_LONG,
258 &slap_conn_max_pending, "( OLcfgAt:11 NAME 'olcConnMaxPending' "
259 "SYNTAX OMsInteger )", NULL, NULL },
260 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_LONG,
261 &slap_conn_max_pending_auth, "( OLcfgAt:12 NAME 'olcConnMaxPendingAuth' "
262 "SYNTAX OMsInteger )", NULL, NULL },
263 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
264 &config_generic, "( OLcfgAt:13 NAME 'olcDatabase' "
265 "DESC 'The backend type for a database instance' "
266 "SUP olcBackend )", NULL, NULL },
267 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_MAGIC,
268 &config_search_base, "( OLcfgAt:14 NAME 'olcDefaultSearchBase' "
269 "SYNTAX OMsDN )", NULL, NULL },
270 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
271 &config_disallows, "( OLcfgAt:15 NAME 'olcDisallows' "
272 "EQUALITY caseIgnoreMatch "
273 "SYNTAX OMsDirectoryString )", NULL, NULL },
274 /* use standard schema */
275 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT,
276 &config_generic, NULL, NULL, NULL },
277 { "gentlehup", "on|off", 2, 2, 0,
279 ARG_ON_OFF, &global_gentlehup,
283 "( OLcfgAt:17 NAME 'olcGentleHUP' "
284 "SYNTAX OMsBoolean )", NULL, NULL },
285 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
286 &global_idletimeout, "( OLcfgAt:18 NAME 'olcIdleTimeout' "
287 "SYNTAX OMsInteger )", NULL, NULL },
288 /* XXX -- special case? */
289 { "include", "file", 2, 2, 0, ARG_MAGIC,
290 &config_include, "( OLcfgAt:19 NAME 'olcInclude' "
291 "SUP labeledURI )", NULL, NULL },
292 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
293 &config_generic, "( OLcfgAt:20 NAME 'olcIndexSubstrIfMinLen' "
294 "SYNTAX OMsInteger )", NULL, NULL },
295 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
296 &config_generic, "( OLcfgAt:21 NAME 'olcIndexSubstrIfMaxLen' "
297 "SYNTAX OMsInteger )", NULL, NULL },
298 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
299 &index_substr_any_len, "( OLcfgAt:22 NAME 'olcIndexSubstrAnyLen' "
300 "SYNTAX OMsInteger )", NULL, NULL },
301 { "index_substr_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
302 &index_substr_any_step, "( OLcfgAt:23 NAME 'olcIndexSubstrAnyStep' "
303 "SYNTAX OMsInteger )", NULL, NULL },
304 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
305 &config_generic, "( OLcfgAt:24 NAME 'olcLastMod' "
306 "SYNTAX OMsBoolean )", NULL, NULL },
307 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
308 &config_generic, "( OLcfgAt:25 NAME 'olcLimits' "
309 "SYNTAX OMsDirectoryString )", NULL, NULL },
310 { "localSSF", "ssf", 2, 2, 0, ARG_LONG,
311 &local_ssf, "( OLcfgAt:26 NAME 'olcLocalSSF' "
312 "SYNTAX OMsInteger )", NULL, NULL },
313 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
314 &config_generic, "( OLcfgAt:27 NAME 'olcLogFile' "
315 "SYNTAX OMsDirectoryString )", NULL, NULL },
316 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
317 &config_loglevel, "( OLcfgAt:28 NAME 'olcLogLevel' "
318 "SYNTAX OMsDirectoryString )", NULL, NULL },
319 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
320 &config_generic, "( OLcfgAt:29 NAME 'olcMaxDerefDepth' "
321 "SYNTAX OMsInteger )", NULL, NULL },
322 { "moduleload", "file", 2, 0, 0,
324 ARG_MAGIC|CFG_MODLOAD, &config_generic,
328 "( OLcfgAt:30 NAME 'olcModuleLoad' "
329 "SYNTAX OMsDirectoryString )", NULL, NULL },
330 { "modulepath", "path", 2, 2, 0,
332 ARG_MAGIC|CFG_MODPATH, &config_generic,
336 "( OLcfgAt:31 NAME 'olcModulePath' "
337 "SYNTAX OMsDirectoryString )", NULL, NULL },
338 /* use standard schema */
339 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
340 &config_generic, NULL, NULL, NULL },
341 { "objectidentifier", NULL, 0, 0, 0, ARG_MAGIC|CFG_OID,
342 &config_generic, "( OLcfgAt:33 NAME 'olcObjectIdentifier' "
343 "SYNTAX OMsDirectoryString )", NULL, NULL },
344 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
345 &config_overlay, "( OLcfgAt:34 NAME 'olcOverlay' "
346 "SUP olcDatabase )", NULL, NULL },
347 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
348 &config_generic, "( OLcfgAt:35 NAME 'olcPasswordCryptSaltFormat' "
349 "SYNTAX OMsDirectoryString )", NULL, NULL },
350 { "password-hash", "hash", 2, 2, 0, ARG_MAGIC,
351 &config_passwd_hash, "( OLcfgAt:36 NAME 'olcPasswordHash' "
352 "SYNTAX OMsDirectoryString )", NULL, NULL },
353 { "pidfile", "file", 2, 2, 0, ARG_STRING,
354 &slapd_pid_file, "( OLcfgAt:37 NAME 'olcPidFile' "
355 "SYNTAX OMsDirectoryString )", NULL, NULL },
356 { "plugin", NULL, 0, 0, 0,
358 ARG_MAGIC|CFG_PLUGIN, &config_generic,
362 "( OLcfgAt:38 NAME 'olcPlugin' "
363 "SYNTAX OMsDirectoryString )", NULL, NULL },
364 { "pluginlog", "filename", 2, 2, 0,
366 ARG_STRING, &slapi_log_file,
370 "( OLcfgAt:39 NAME 'olcPluginLogFile' "
371 "SYNTAX OMsDirectoryString )", NULL, NULL },
372 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
373 &config_generic, "( OLcfgAt:40 NAME 'olcReadOnly' "
374 "SYNTAX OMsBoolean )", NULL, NULL },
375 { "referral", "url", 2, 2, 0, ARG_MAGIC,
376 &config_referral, "( OLcfgAt:41 NAME 'olcReferral' "
377 "SUP labeledURI )", NULL, NULL },
378 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
379 &config_replica, "( OLcfgAt:42 NAME 'olcReplica' "
380 "SUP labeledURI )", NULL, NULL },
381 { "replica-argsfile", NULL, 0, 0, 0, ARG_STRING,
382 &replica_argsFile, "( OLcfgAt:43 NAME 'olcReplicaArgsFile' "
383 "SYNTAX OMsDirectoryString )", NULL, NULL },
384 { "replica-pidfile", NULL, 0, 0, 0, ARG_STRING,
385 &replica_pidFile, "( OLcfgAt:44 NAME 'olcReplicaPidFile' "
386 "SYNTAX OMsDirectoryString )", NULL, NULL },
387 { "replicationInterval", NULL, 0, 0, 0, ARG_INT,
388 &replicationInterval, "( OLcfgAt:45 NAME 'olcReplicationInterval' "
389 "SYNTAX OMsInteger )", NULL, NULL },
390 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC|ARG_STRING|CFG_REPLOG,
391 &config_generic, "( OLcfgAt:46 NAME 'olcReplogFile' "
392 "SYNTAX OMsDirectoryString )", NULL, NULL },
393 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
394 &config_requires, "( OLcfgAt:47 NAME 'olcRequires' "
395 "SYNTAX OMsDirectoryString )", NULL, NULL },
396 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
397 &config_restrict, "( OLcfgAt:48 NAME 'olcRestrict' "
398 "SYNTAX OMsDirectoryString )", NULL, NULL },
399 { "reverse-lookup", "on|off", 2, 2, 0,
400 #ifdef SLAPD_RLOOKUPS
401 ARG_ON_OFF, &use_reverse_lookup,
405 "( OLcfgAt:49 NAME 'olcReverseLookup' "
406 "SYNTAX OMsBoolean )", NULL, NULL },
407 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_MAGIC,
408 &config_rootdn, "( OLcfgAt:50 NAME 'olcRootDN' "
409 "SYNTAX OMsDN )", NULL, NULL },
410 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
411 &config_generic, "( OLcfgAt:51 NAME 'olcRootDSE' "
412 "SYNTAX OMsDirectoryString )", NULL, NULL },
413 { "rootpw", "password", 2, 2, 0, ARG_STRING|ARG_DB|ARG_MAGIC,
414 &config_rootpw, "( OLcfgAt:52 NAME 'olcRootPW' "
415 "SYNTAX OMsOctetString )", NULL, NULL },
416 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
417 &config_generic, NULL, NULL, NULL },
418 { "sasl-host", "host", 2, 2, 0,
419 #ifdef HAVE_CYRUS_SASL
420 ARG_STRING|ARG_UNIQUE, &global_host,
424 "( OLcfgAt:53 NAME 'olcSaslHost' "
425 "SYNTAX OMsDirectoryString )", NULL, NULL },
426 { "sasl-realm", "realm", 2, 2, 0,
427 #ifdef HAVE_CYRUS_SASL
428 ARG_STRING|ARG_UNIQUE, &global_realm,
432 "( OLcfgAt:54 NAME 'olcSaslRealm' "
433 "SYNTAX OMsDirectoryString )", NULL, NULL },
434 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
435 &config_generic, NULL, NULL, NULL },
436 { "sasl-secprops", "properties", 2, 2, 0,
437 #ifdef HAVE_CYRUS_SASL
438 ARG_MAGIC|CFG_SASLSECP, &config_generic,
442 "( OLcfgAt:56 NAME 'olcSaslSecProps' "
443 "SYNTAX OMsDirectoryString )", NULL, NULL },
444 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
445 &config_generic, NULL, NULL, NULL },
446 { "schemacheck", "on|off", 2, 2, 0, ARG_ON_OFF|ARG_MAGIC|CFG_CHECK,
447 &config_generic, "( OLcfgAt:57 NAME 'olcSchemaCheck' "
448 "SYNTAX OMsBoolean )", NULL, NULL },
449 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_MAGIC,
450 &config_schema_dn, "( OLcfgAt:58 NAME 'olcSchemaDN' "
451 "SYNTAX OMsDN )", NULL, NULL },
452 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
453 &config_security, "( OLcfgAt:59 NAME 'olcSecurity' "
454 "SYNTAX OMsDirectoryString )", NULL, NULL },
455 { "sizelimit", "limit", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC|CFG_SIZE,
456 &config_sizelimit, "( OLcfgAt:60 NAME 'olcSizeLimit' "
457 "SYNTAX OMsInteger )", NULL, NULL },
458 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_LONG,
459 &sockbuf_max_incoming, "( OLcfgAt:61 NAME 'olcSockbufMaxIncoming' "
460 "SYNTAX OMsInteger )", NULL, NULL },
461 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_LONG,
462 &sockbuf_max_incoming_auth, "( OLcfgAt:62 NAME 'olcSockbufMaxIncomingAuth' "
463 "SYNTAX OMsInteger )", NULL, NULL },
464 { "srvtab", "file", 2, 2, 0,
465 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
466 ARG_STRING, &ldap_srvtab,
470 "( OLcfgAt:63 NAME 'olcSrvtab' "
471 "SYNTAX OMsDirectoryString )", NULL, NULL },
472 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_MAGIC,
473 &config_suffix, "( OLcfgAt:64 NAME 'olcSuffix' "
474 "SYNTAX OMsDN )", NULL, NULL },
475 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
476 &config_syncrepl, "( OLcfgAt:65 NAME 'olcSyncrepl' "
477 "SYNTAX OMsDirectoryString )", NULL, NULL },
478 { "threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_THREADS,
479 &config_generic, "( OLcfgAt:66 NAME 'olcThreads' "
480 "SYNTAX OMsInteger )", NULL, NULL },
481 { "timelimit", "limit", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC|CFG_TIME,
482 &config_timelimit, "( OLcfgAt:67 NAME 'olcTimeLimit' "
483 "SYNTAX OMsInteger )", NULL, NULL },
484 { "TLSCACertificateFile", NULL, 0, 0, 0,
486 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
490 "( OLcfgAt:68 NAME 'olcTLSCACertificateFile' "
491 "SYNTAX OMsDirectoryString )", NULL, NULL },
492 { "TLSCACertificatePath", NULL, 0, 0, 0,
494 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
498 "( OLcfgAt:69 NAME 'olcTLSCACertificatePath' "
499 "SYNTAX OMsDirectoryString )", NULL, NULL },
500 { "TLSCertificateFile", NULL, 0, 0, 0,
502 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
506 "( OLcfgAt:70 NAME 'olcTLSCertificateFile' "
507 "SYNTAX OMsDirectoryString )", NULL, NULL },
508 { "TLSCertificateKeyFile", NULL, 0, 0, 0,
510 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
514 "( OLcfgAt:71 NAME 'olcTLSCertificateKeyFile' "
515 "SYNTAX OMsDirectoryString )", NULL, NULL },
516 { "TLSCipherSuite", NULL, 0, 0, 0,
518 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
522 "( OLcfgAt:72 NAME 'olcTLSCipherSuite' "
523 "SYNTAX OMsDirectoryString )", NULL, NULL },
524 { "TLSCRLCheck", NULL, 0, 0, 0,
526 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
530 "( OLcfgAt:73 NAME 'olcTLSCRLCheck' "
531 "SYNTAX OMsDirectoryString )", NULL, NULL },
532 { "TLSRandFile", NULL, 0, 0, 0,
534 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
538 "( OLcfgAt:74 NAME 'olcTLSRandFile' "
539 "SYNTAX OMsDirectoryString )", NULL, NULL },
540 { "TLSVerifyClient", NULL, 0, 0, 0,
542 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
546 "( OLcfgAt:75 NAME 'olcTLSVerifyClient' "
547 "SYNTAX OMsDirectoryString )", NULL, NULL },
548 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
549 NULL, NULL, NULL, NULL },
550 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_MAGIC,
551 &config_updatedn, "( OLcfgAt:76 NAME 'olcUpdateDN' "
552 "SYNTAX OMsDN )", NULL, NULL },
553 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
554 &config_updateref, "( OLcfgAt:77 NAME 'olcUpdateRef' "
555 "SUP labeledURI )", NULL, NULL },
556 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
557 NULL, NULL, NULL, NULL }
562 new_config_args( BackendDB *be, const char *fname, int lineno, int argc, char **argv )
565 c = ch_calloc( 1, sizeof( ConfigArgs ) );
566 if ( c == NULL ) return(NULL);
572 snprintf( c->log, sizeof( c->log ), "%s: line %lu", fname, lineno );
576 int parse_config_table(ConfigTable *Conf, ConfigArgs *c) {
577 int i, rc, arg_user, arg_type, iarg;
580 for(i = 0; Conf[i].name; i++)
581 if( (Conf[i].length && (!strncasecmp(c->argv[0], Conf[i].name, Conf[i].length))) ||
582 (!strcasecmp(c->argv[0], Conf[i].name)) ) break;
583 if(!Conf[i].name) return(ARG_UNKNOWN);
584 arg_type = Conf[i].arg_type;
585 if(arg_type == ARG_IGNORED) {
586 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> ignored\n",
587 c->log, Conf[i].name, 0);
590 if(Conf[i].min_args && (c->argc < Conf[i].min_args)) {
591 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> missing <%s> argument\n",
592 c->log, Conf[i].name, Conf[i].what);
593 return(ARG_BAD_CONF);
595 if(Conf[i].max_args && (c->argc > Conf[i].max_args)) {
596 Debug(LDAP_DEBUG_CONFIG, "%s: extra cruft after <%s> in <%s> line (ignored)\n",
597 c->log, Conf[i].what, Conf[i].name);
599 if((arg_type & ARG_DB) && !c->be) {
600 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> allowed only within database declaration\n",
601 c->log, Conf[i].name, 0);
602 return(ARG_BAD_CONF);
604 if((arg_type & ARG_PRE_BI) && c->bi) {
605 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> must appear before any backend %sdeclaration\n",
606 c->log, Conf[i].name, ((arg_type & ARG_PRE_DB)
607 ? "or database " : "") );
608 return(ARG_BAD_CONF);
610 if((arg_type & ARG_PRE_DB) && c->be && c->be != frontendDB) {
611 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> must appear before any database declaration\n",
612 c->log, Conf[i].name, 0);
613 return(ARG_BAD_CONF);
615 if((arg_type & ARG_PAREN) && *c->argv[1] != '(' /*')'*/) {
616 Debug(LDAP_DEBUG_CONFIG, "%s: old <%s> format not supported\n",
617 c->log, Conf[i].name, 0);
618 return(ARG_BAD_CONF);
620 if((arg_type & ARGS_POINTER) && !Conf[i].arg_item) {
621 Debug(LDAP_DEBUG_CONFIG, "%s: null arg_item for <%s>\n",
622 c->log, Conf[i].name, 0);
623 return(ARG_BAD_CONF);
625 c->type = arg_user = (arg_type & ARGS_USERLAND);
626 memset(&c->values, 0, sizeof(c->values));
627 if(arg_type & ARGS_NUMERIC) {
629 iarg = 0; larg = 0; barg = 0;
630 switch(arg_type & ARGS_NUMERIC) {
631 case ARG_INT: iarg = atoi(c->argv[1]); break;
632 case ARG_LONG: larg = atol(c->argv[1]); break;
633 case ARG_BER_LEN_T: barg = (ber_len_t)atol(c->argv[1]); break;
635 if(!strcasecmp(c->argv[1], "on") ||
636 !strcasecmp(c->argv[1], "true")) {
638 } else if(!strcasecmp(c->argv[1], "off") ||
639 !strcasecmp(c->argv[1], "false")) {
642 Debug(LDAP_DEBUG_CONFIG, "%s: ignoring ", c->log, 0, 0);
643 Debug(LDAP_DEBUG_CONFIG, "invalid %s value (%s) in <%s> line\n",
644 Conf[i].what, c->argv[1], Conf[i].name);
649 j = (arg_type & ARG_NONZERO) ? 1 : 0;
650 if(iarg < j || larg < j || barg < j ) {
651 larg = larg ? larg : (barg ? barg : iarg);
652 Debug(LDAP_DEBUG_CONFIG, "%s: " , c->log, 0, 0);
653 Debug(LDAP_DEBUG_CONFIG, "invalid %s value (%ld) in <%s> line\n", Conf[i].what, larg, Conf[i].name);
654 return(ARG_BAD_CONF);
656 switch(arg_type & ARGS_NUMERIC) {
658 case ARG_INT: c->value_int = iarg; break;
659 case ARG_LONG: c->value_long = larg; break;
660 case ARG_BER_LEN_T: c->value_ber_t = barg; break;
662 } else if(arg_type & ARG_STRING) {
663 c->value_string = ch_strdup(c->argv[1]);
664 } else if(arg_type & ARG_DN) {
666 ber_str2bv( c->argv[1], 0, 0, &bv );
667 rc = dnPrettyNormal( NULL, &bv, &c->value_dn, &c->value_ndn, NULL );
668 if ( rc != LDAP_SUCCESS ) {
669 Debug(LDAP_DEBUG_CONFIG, "%s: " , c->log, 0, 0);
670 Debug(LDAP_DEBUG_CONFIG, "%s DN is invalid %d (%s)\n",
671 Conf[i].name, rc, ldap_err2string( rc ));
672 return(ARG_BAD_CONF);
675 if(arg_type & ARG_MAGIC) {
676 if(!c->be) c->be = frontendDB;
677 rc = (*((ConfigDriver*)Conf[i].arg_item))(c);
678 if(c->be == frontendDB) c->be = NULL;
680 Debug(LDAP_DEBUG_CONFIG, "%s: handler for <%s> exited with %d!",
681 c->log, Conf[i].name, rc);
682 return(ARG_BAD_CONF);
686 if(arg_type & ARGS_POINTER) switch(arg_type & ARGS_POINTER) {
688 case ARG_INT: *((int*)Conf[i].arg_item) = iarg; break;
689 case ARG_LONG: *((long*)Conf[i].arg_item) = larg; break;
690 case ARG_BER_LEN_T: *((ber_len_t*)Conf[i].arg_item) = barg; break;
692 char *cc = *((char**)Conf[i].arg_item);
694 if (arg_type & ARG_UNIQUE) {
695 Debug(LDAP_DEBUG_CONFIG, "%s: already set %s!\n",
696 c->log, Conf[i].name, 0 );
697 return(ARG_BAD_CONF);
699 ch_free(cc); /* potential memory leak */
701 *(char **)Conf[i].arg_item = c->value_string;
709 config_get_vals(ConfigTable *cf, ConfigArgs *c)
714 if ( cf->arg_type & ARG_IGNORED ) {
718 memset(&c->values, 0, sizeof(c->values));
719 c->rvalue_vals = NULL;
720 c->rvalue_nvals = NULL;
722 c->type = cf->arg_type & ARGS_USERLAND;
724 if ( cf->arg_type & ARG_MAGIC ) {
725 rc = (*((ConfigDriver*)cf->arg_item))(c);
728 switch(cf->arg_type & ARGS_POINTER) {
730 case ARG_INT: c->value_int = *(int *)cf->arg_item; break;
731 case ARG_LONG: c->value_long = *(long *)cf->arg_item; break;
732 case ARG_BER_LEN_T: c->value_ber_t = *(ber_len_t *)cf->arg_item; break;
734 if ( *(char **)cf->arg_item )
735 c->value_string = ch_strdup(*(char **)cf->arg_item);
739 if ( cf->arg_type & ARGS_POINTER) {
741 switch(cf->arg_type & ARGS_POINTER) {
742 case ARG_INT: bv.bv_len = sprintf(bv.bv_val, "%d", c->value_int); break;
743 case ARG_LONG: bv.bv_len = sprintf(bv.bv_val, "%l", c->value_long); break;
744 case ARG_BER_LEN_T: bv.bv_len =sprintf(bv.bv_val, "%l",c->value_ber_t); break;
745 case ARG_ON_OFF: bv.bv_len = sprintf(bv.bv_val, "%s",
746 c->value_int ? "TRUE" : "FALSE"); break;
748 if ( c->value_string && c->value_string[0]) {
749 ber_str2bv( c->value_string, 0, 0, &bv);
755 if (( cf->arg_type & ARGS_POINTER ) == ARG_STRING )
756 ber_bvarray_add(&c->rvalue_vals, &bv);
758 value_add_one(&c->rvalue_vals, &bv);
764 init_config_attrs(ConfigTable *ct) {
765 LDAPAttributeType *at;
769 for (i=0; ct[i].name; i++ ) {
770 if ( !ct[i].attribute ) continue;
771 at = ldap_str2attributetype( ct[i].attribute,
772 &code, &err, LDAP_SCHEMA_ALLOW_ALL );
774 fprintf( stderr, "init_config_schema: AttributeType \"%s\": %s, %s\n",
775 ct[i].attribute, ldap_scherr2str(code), err );
778 code = at_add( at, &err );
780 fprintf( stderr, "init_config_schema: AttributeType \"%s\": %s, %s\n",
781 ct[i].attribute, scherr2str(code), err );
784 code = slap_str2ad( at->at_names[0], &ct[i].ad, &err );
786 fprintf( stderr, "init_config_schema: AttributeType \"%s\": %s\n",
787 ct[i].attribute, err );
797 read_config(const char *fname, int depth) {
801 /* Schema initialization should normally be part of bi_open */
802 for (i=0; OidMacros[i].name; i++ ) {
803 argv[1] = OidMacros[i].name;
804 argv[2] = OidMacros[i].oid;
805 parse_oidm( "slapd", i, 3, argv );
807 i = init_config_attrs(SystemConfiguration);
809 i = config_back_init( &cf_prv, SystemConfiguration );
811 return read_config_file(fname, depth, NULL);
815 read_config_file(const char *fname, int depth, ConfigArgs *cf)
821 c = ch_calloc( 1, sizeof( ConfigArgs ) );
827 memcpy( c, cf, sizeof( ConfigArgs ) );
829 c->depth = depth; /* XXX */
835 c->argv = ch_calloc( ARGS_STEP + 1, sizeof( *c->argv ) );
836 c->argv_size = ARGS_STEP + 1;
838 fp = fopen( fname, "r" );
841 Debug(LDAP_DEBUG_ANY,
842 "could not open config file \"%s\": %s (%d)\n",
843 fname, strerror(errno), errno);
847 cfn->c_modlast = &cfn->c_modpaths;
849 ber_str2bv( fname, 0, 1, &cfn->c_file );
850 fname = cfn->c_file.bv_val;
852 Debug(LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0);
856 while ( fp_getline( fp, c ) ) {
857 /* skip comments and blank lines */
858 if ( c->line[0] == '#' || c->line[0] == '\0' ) {
862 snprintf( c->log, sizeof( c->log ), "%s: line %lu",
863 c->fname, c->lineno );
865 if ( fp_parse_line( c ) ) {
870 Debug(LDAP_DEBUG_CONFIG, "%s: bad config line (ignored)\n", c->log, 0, 0);
874 rc = parse_config_table( SystemConfiguration, c );
878 if ( rc & ARGS_USERLAND ) {
879 switch(rc) { /* XXX a usertype would be opaque here */
881 Debug(LDAP_DEBUG_CONFIG, "%s: unknown user type <%d>\n",
882 c->log, *c->argv, 0);
886 } else if ( rc == ARG_BAD_CONF || rc != ARG_UNKNOWN ) {
889 } else if ( c->bi && c->bi->bi_config ) { /* XXX to check: could both be/bi_config? oops */
890 rc = (*c->bi->bi_config)(c->bi, c->fname, c->lineno, c->argc, c->argv);
893 case SLAP_CONF_UNKNOWN:
894 Debug(LDAP_DEBUG_CONFIG, "%s: "
895 "unknown directive <%s> inside backend info definition (ignored)\n",
896 c->log, *c->argv, 0);
903 } else if ( c->be && c->be->be_config ) {
904 rc = (*c->be->be_config)(c->be, c->fname, c->lineno, c->argc, c->argv);
907 case SLAP_CONF_UNKNOWN:
908 Debug( LDAP_DEBUG_CONFIG, "%s: "
909 "unknown directive <%s> inside backend database definition (ignored)\n",
910 c->log, *c->argv, 0);
917 } else if ( frontendDB->be_config ) {
918 rc = (*frontendDB->be_config)(frontendDB, c->fname, (int)c->lineno, c->argc, c->argv);
921 case SLAP_CONF_UNKNOWN:
922 Debug( LDAP_DEBUG_CONFIG, "%s: "
923 "unknown directive <%s> inside global database definition (ignored)\n",
924 c->log, *c->argv, 0);
932 Debug(LDAP_DEBUG_CONFIG, "%s: "
933 "unknown directive <%s> outside backend info and database definitions (ignored)\n",
934 c->log, *c->argv, 0);
942 if ( BER_BVISNULL( &frontendDB->be_schemadn ) ) {
943 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
944 &frontendDB->be_schemadn );
945 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
946 if ( rc != LDAP_SUCCESS ) {
947 Debug(LDAP_DEBUG_ANY, "%s: "
948 "unable to normalize default schema DN \"%s\"\n",
949 c->log, frontendDB->be_schemadn.bv_val, 0 );
950 /* must not happen */
967 config_generic(ConfigArgs *c) {
975 c->value_int = ldap_pvt_thread_get_concurrency();
978 c->value_int = connection_pool_max;
982 c->value_string = ch_strdup( passwd_salt );
986 case CFG_LIMITS: /* FIXME */
990 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_OP_WRITES) != 0;
993 c->value_string = ch_strdup( slap_sasl_getpolicy());
998 #ifdef HAVE_CYRUS_SASL
1000 struct berval bv = BER_BVNULL;
1001 slap_sasl_secprops_unparse( &bv );
1002 if ( !BER_BVISNULL( &bv )) {
1003 ber_bvarray_add( &c->rvalue_vals, &bv );
1011 c->value_int = c->be->be_max_deref_depth;
1014 oidm_unparse( &c->rvalue_vals );
1015 if ( !c->rvalue_vals )
1019 c->value_int = global_schemacheck;
1023 char *src, *dst, ibuf[11];
1024 struct berval bv, abv;
1025 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
1026 abv.bv_len = sprintf( ibuf, "{%x}", i );
1027 acl_unparse( a, &bv );
1028 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
1029 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
1030 /* Turn TAB / EOL into plain space */
1031 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
1032 if (isspace(*src)) *dst++ = ' ';
1036 if (dst[-1] == ' ') {
1040 abv.bv_len = dst - abv.bv_val;
1041 ber_bvarray_add( &c->rvalue_vals, &abv );
1047 if ( c->be->be_replogfile )
1048 c->value_string = ch_strdup( c->be->be_replogfile );
1051 ConfigFile *cf = (ConfigFile *)c->line;
1052 if ( cf->c_dseFiles ) {
1053 value_add( &c->rvalue_vals, cf->c_dseFiles );
1061 c->value_string = ch_strdup( logfileName );
1066 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1068 case CFG_SSTR_IF_MAX:
1069 c->value_int = index_substr_if_maxlen;
1071 case CFG_SSTR_IF_MIN:
1072 c->value_int = index_substr_if_minlen;
1074 #ifdef SLAPD_MODULES
1076 ConfigFile *cf = (ConfigFile *)c->line;
1078 for (i=0, mp=&cf->c_modpaths; mp; mp=mp->mp_next, i++) {
1080 if (!mp->mp_loads) continue;
1081 for (j=0; !BER_BVISNULL(&mp->mp_loads[j]); j++) {
1084 bv.bv_len = sprintf( bv.bv_val, "{%d}{%d}%s", i, j,
1085 mp->mp_loads[j].bv_val );
1086 value_add_one( &c->rvalue_vals, &bv );
1089 rc = c->rvalue_vals ? 0 : 1;
1093 ConfigFile *cf = (ConfigFile *)c->line;
1095 for (i=0, mp=&cf->c_modpaths; mp; mp=mp->mp_next, i++) {
1097 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
1100 bv.bv_len = sprintf( bv.bv_val, "{%d}%s", i,
1101 mp->mp_path.bv_val );
1102 value_add_one( &c->rvalue_vals, &bv );
1104 rc = c->rvalue_vals ? 0 : 1;
1109 case CFG_PLUGIN: /* FIXME */
1113 #ifdef SLAP_AUTH_REWRITE
1114 case CFG_REWRITE: /* FIXME */
1124 p = strchr(c->line,'(' /*')'*/);
1127 if(!(c->bi = backend_info(c->argv[1]))) {
1128 Debug(LDAP_DEBUG_ANY, "%s: "
1129 "backend %s failed init!\n", c->log, c->argv[1], 0);
1136 /* NOTE: config is always the first backend!
1138 if ( !strcasecmp( c->argv[1], "config" )) {
1140 } else if(!(c->be = backend_db_init(c->argv[1]))) {
1141 Debug(LDAP_DEBUG_ANY, "%s: "
1142 "database %s failed init!\n", c->log, c->argv[1], 0);
1148 ldap_pvt_thread_set_concurrency(c->value_int);
1152 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1153 connection_pool_max = c->value_int; /* save for reference */
1157 if ( passwd_salt ) ch_free( passwd_salt );
1158 passwd_salt = c->value_string;
1159 lutil_salt_format(passwd_salt);
1163 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1169 c->be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1171 c->be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1175 ch_free(c->value_string);
1176 if (slap_sasl_setpolicy( c->argv[1] )) {
1177 Debug(LDAP_DEBUG_ANY, "%s: unable to parse value \"%s\" in"
1178 " \"authz-policy <policy>\"\n",
1179 c->log, c->argv[1], 0 );
1185 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1189 #ifdef HAVE_CYRUS_SASL
1192 char *txt = slap_sasl_secprops( c->argv[1] );
1194 Debug(LDAP_DEBUG_ANY, "%s: sasl-secprops: %s\n",
1203 c->be->be_max_deref_depth = c->value_int;
1207 if(parse_oidm(c->fname, c->lineno, c->argc, c->argv)) return(1);
1211 if(parse_oc(c->fname, c->lineno, p, c->argv)) return(1);
1215 if(parse_cr(c->fname, c->lineno, p, c->argv)) return(1);
1219 if(parse_at(c->fname, c->lineno, p, c->argv)) return(1);
1223 ad_define_option(NULL, NULL, 0);
1224 for(i = 1; i < c->argc; i++)
1225 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1230 global_schemacheck = c->value_int;
1231 if(!global_schemacheck) Debug(LDAP_DEBUG_ANY, "%s: "
1232 "schema checking disabled! your mileage may vary!\n",
1237 parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv);
1241 if(SLAP_MONITOR(c->be)) {
1242 Debug(LDAP_DEBUG_ANY, "%s: "
1243 "\"replogfile\" should not be used "
1244 "inside monitor database\n",
1246 return(0); /* FIXME: should this be an error? */
1249 c->be->be_replogfile = c->value_string;
1253 if(read_root_dse_file(c->argv[1])) {
1254 Debug(LDAP_DEBUG_ANY, "%s: "
1255 "could not read \"rootDSE <filename>\" line\n",
1261 ber_str2bv( c->argv[1], 0, 1, &bv );
1262 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1268 if ( logfileName ) ch_free( logfileName );
1269 logfileName = c->value_string;
1270 logfile = fopen(logfileName, "w");
1271 if(logfile) lutil_debug_file(logfile);
1275 if(SLAP_NOLASTMODCMD(c->be)) {
1276 Debug(LDAP_DEBUG_ANY, "%s: "
1277 "lastmod not available for %s databases\n",
1278 c->log, c->be->bd_info->bi_type, 0);
1282 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1284 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1287 case CFG_SSTR_IF_MAX:
1288 if (c->value_int < index_substr_if_minlen) {
1289 Debug(LDAP_DEBUG_ANY, "%s: "
1290 "invalid max value (%d)\n",
1291 c->log, c->value_int, 0 );
1294 index_substr_if_maxlen = c->value_int;
1297 case CFG_SSTR_IF_MIN:
1298 if (c->value_int > index_substr_if_maxlen) {
1299 Debug(LDAP_DEBUG_ANY, "%s: "
1300 "invalid min value (%d)\n",
1301 c->log, c->value_int, 0 );
1304 index_substr_if_minlen = c->value_int;
1307 #ifdef SLAPD_MODULES
1309 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1311 /* Record this load on the current path */
1314 ber_str2bv(c->line, 0, 1, &bv);
1315 ber_bvarray_add( &cfn->c_modlast->mp_loads, &bv );
1320 if(module_path(c->argv[1])) return(1);
1321 /* Record which path was used with each module */
1325 if (!cfn->c_modpaths.mp_loads) {
1326 mp = &cfn->c_modpaths;
1328 mp = ch_malloc( sizeof( ModPaths ));
1329 cfn->c_modlast->mp_next = mp;
1331 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1333 mp->mp_loads = NULL;
1334 cfn->c_modlast = mp;
1342 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
1344 slapi_plugins_used++;
1348 #ifdef SLAP_AUTH_REWRITE
1350 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
1357 Debug(LDAP_DEBUG_ANY, "%s: unknown CFG_TYPE %d"
1358 "(ignored)\n", c->log, c->type, 0);
1366 config_fname(ConfigArgs *c) {
1367 if(c->emit && c->line) {
1368 ConfigFile *cf = (ConfigFile *)c->line;
1369 value_add_one( &c->rvalue_vals, &cf->c_file );
1376 config_search_base(ConfigArgs *c) {
1381 if (!BER_BVISEMPTY(&default_search_base)) {
1382 value_add_one(&c->rvalue_vals, &default_search_base);
1383 value_add_one(&c->rvalue_nvals, &default_search_nbase);
1389 if(c->bi || c->be != frontendDB) {
1390 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
1391 "prior to any backend or database definition\n",
1396 if(default_search_nbase.bv_len) {
1397 Debug(LDAP_DEBUG_ANY, "%s: "
1398 "default search base \"%s\" already defined "
1399 "(discarding old)\n",
1400 c->log, default_search_base.bv_val, 0);
1401 free(default_search_base.bv_val);
1402 free(default_search_nbase.bv_val);
1405 default_search_base = c->value_dn;
1406 default_search_nbase = c->value_ndn;
1411 config_passwd_hash(ConfigArgs *c) {
1415 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
1416 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
1417 value_add_one(&c->rvalue_vals, &bv);
1421 if(default_passwd_hash) {
1422 Debug(LDAP_DEBUG_ANY, "%s: "
1423 "already set default password_hash\n",
1427 for(i = 1; i < c->argc; i++) {
1428 if(!lutil_passwd_scheme(c->argv[i])) {
1429 Debug(LDAP_DEBUG_ANY, "%s: "
1430 "password scheme \"%s\" not available\n",
1431 c->log, c->argv[i], 0);
1433 ldap_charray_add(&default_passwd_hash, c->argv[i]);
1435 if(!default_passwd_hash) {
1436 Debug(LDAP_DEBUG_ANY, "%s: no valid hashes found\n",
1445 config_schema_dn(ConfigArgs *c) {
1449 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
1450 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
1453 c->be->be_schemadn = c->value_dn;
1454 c->be->be_schemandn = c->value_ndn;
1459 config_sizelimit(ConfigArgs *c) {
1462 struct slap_limits_set *lim = &c->be->be_def_limit;
1463 if (c->emit) { /* FIXME */
1466 for(i = 1; i < c->argc; i++) {
1467 if(!strncasecmp(c->argv[i], "size", 4)) {
1468 rc = limits_parse_one(c->argv[i], lim);
1470 Debug(LDAP_DEBUG_ANY, "%s: "
1471 "unable to parse value \"%s\" in \"sizelimit <limit>\" line\n",
1472 c->log, c->argv[i], 0);
1476 if(!strcasecmp(c->argv[i], "unlimited")) {
1477 lim->lms_s_soft = -1;
1479 lim->lms_s_soft = strtol(c->argv[i], &next, 0);
1480 if(next == c->argv[i]) {
1481 Debug(LDAP_DEBUG_ANY, "%s: "
1482 "unable to parse limit \"%s\" in \"sizelimit <limit>\" line\n",
1483 c->log, c->argv[i], 0);
1485 } else if(next[0] != '\0') {
1486 Debug(LDAP_DEBUG_ANY, "%s: "
1487 "trailing chars \"%s\" in \"sizelimit <limit>\" line (ignored)\n",
1491 lim->lms_s_hard = 0;
1498 config_timelimit(ConfigArgs *c) {
1501 struct slap_limits_set *lim = &c->be->be_def_limit;
1503 return 1; /* FIXME */
1505 for(i = 1; i < c->argc; i++) {
1506 if(!strncasecmp(c->argv[i], "time", 4)) {
1507 rc = limits_parse_one(c->argv[i], lim);
1509 Debug(LDAP_DEBUG_ANY, "%s: "
1510 "unable to parse value \"%s\" in \"timelimit <limit>\" line\n",
1511 c->log, c->argv[i], 0);
1515 if(!strcasecmp(c->argv[i], "unlimited")) {
1516 lim->lms_t_soft = -1;
1518 lim->lms_t_soft = strtol(c->argv[i], &next, 0);
1519 if(next == c->argv[i]) {
1520 Debug(LDAP_DEBUG_ANY, "%s: "
1521 "unable to parse limit \"%s\" in \"timelimit <limit>\" line\n",
1522 c->log, c->argv[i], 0);
1524 } else if(next[0] != '\0') {
1525 Debug(LDAP_DEBUG_ANY, "%s: "
1526 "trailing chars \"%s\" in \"timelimit <limit>\" line (ignored)\n",
1530 lim->lms_t_hard = 0;
1537 config_overlay(ConfigArgs *c) {
1541 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1])) {
1543 Debug(LDAP_DEBUG_ANY, "%s: (optional) %s overlay \"%s\" configuration failed (ignored)\n",
1544 c->log, c->be == frontendDB ? "global " : "", c->argv[1][1]);
1545 } else if(overlay_config(c->be, c->argv[1])) {
1552 config_suffix(ConfigArgs *c) {
1554 struct berval pdn, ndn;
1557 if ( !BER_BVISNULL( &c->be->be_suffix[0] )) {
1558 value_add( &c->rvalue_vals, c->be->be_suffix );
1559 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
1565 #ifdef SLAPD_MONITOR_DN
1566 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
1567 Debug(LDAP_DEBUG_ANY, "%s: "
1568 "\"%s\" is reserved for monitoring slapd\n",
1569 c->log, SLAPD_MONITOR_DN, 0);
1576 tbe = select_backend(&ndn, 0, 0);
1578 Debug(LDAP_DEBUG_ANY, "%s: suffix already served by this backend! (ignored)\n",
1583 Debug(LDAP_DEBUG_ANY, "%s: suffix already served by a preceding backend \"%s\"\n",
1584 c->log, tbe->be_suffix[0].bv_val, 0);
1588 } else if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
1589 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
1590 "base provided \"%s\" (assuming okay)\n",
1591 c->log, default_search_base.bv_val, 0);
1593 ber_bvarray_add(&c->be->be_suffix, &pdn);
1594 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
1599 config_rootdn(ConfigArgs *c) {
1601 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
1602 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
1603 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
1609 c->be->be_rootdn = c->value_dn;
1610 c->be->be_rootndn = c->value_ndn;
1615 config_rootpw(ConfigArgs *c) {
1618 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
1619 c->value_string=ch_strdup("*");
1625 tbe = select_backend(&c->be->be_rootndn, 0, 0);
1627 Debug(LDAP_DEBUG_ANY, "%s: "
1628 "rootpw can only be set when rootdn is under suffix\n",
1632 ber_str2bv(c->value_string, 0, 0, &c->be->be_rootpw);
1636 /* restrictops, allows, disallows, requires, loglevel */
1638 struct verb_mask_list { char *word; int mask; };
1641 verb_to_mask(ConfigArgs *c, struct verb_mask_list *v, int word) {
1643 for(j = 0; v[j].word; j++)
1644 if(!strcasecmp(c->argv[word], v[j].word))
1650 verbs_to_mask(ConfigArgs *c, struct verb_mask_list *v, slap_mask_t *m) {
1652 for(i = 1; i < c->argc; i++) {
1653 j = verb_to_mask(c, v, i);
1654 if(!v[j].word) return(1);
1655 while (!v[j].mask) j--;
1662 mask_to_verbs(ConfigArgs *c, struct verb_mask_list *v, slap_mask_t m) {
1667 for (i=0; v[i].word; i++) {
1668 if (!v[i].mask) continue;
1669 if (( m & v[i].mask ) == v[i].mask ) {
1670 ber_str2bv( v[i].word, 0, 0, &bv );
1671 value_add_one( &c->rvalue_vals, &bv );
1678 config_restrict(ConfigArgs *c) {
1679 slap_mask_t restrictops = 0;
1681 struct verb_mask_list restrictable_ops[] = {
1682 { "bind", SLAP_RESTRICT_OP_BIND },
1683 { "add", SLAP_RESTRICT_OP_ADD },
1684 { "modify", SLAP_RESTRICT_OP_MODIFY },
1685 { "rename", SLAP_RESTRICT_OP_RENAME },
1687 { "delete", SLAP_RESTRICT_OP_DELETE },
1688 { "search", SLAP_RESTRICT_OP_SEARCH },
1689 { "compare", SLAP_RESTRICT_OP_COMPARE },
1690 { "read", SLAP_RESTRICT_OP_READS },
1691 { "write", SLAP_RESTRICT_OP_WRITES },
1692 { "extended", SLAP_RESTRICT_OP_EXTENDED },
1693 { "extended=" LDAP_EXOP_START_TLS, SLAP_RESTRICT_EXOP_START_TLS },
1694 { "extended=" LDAP_EXOP_MODIFY_PASSWD, SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
1695 { "extended=" LDAP_EXOP_X_WHO_AM_I, SLAP_RESTRICT_EXOP_WHOAMI },
1696 { "extended=" LDAP_EXOP_X_CANCEL, SLAP_RESTRICT_EXOP_CANCEL },
1701 return mask_to_verbs( c, restrictable_ops, c->be->be_restrictops );
1703 i = verbs_to_mask( c, restrictable_ops, &restrictops );
1705 Debug(LDAP_DEBUG_ANY, "%s: "
1706 "unknown operation %s in \"restrict <features>\" line\n",
1707 c->log, c->argv[i], 0);
1710 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
1711 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
1712 c->be->be_restrictops |= restrictops;
1717 config_allows(ConfigArgs *c) {
1718 slap_mask_t allows = 0;
1720 struct verb_mask_list allowable_ops[] = {
1721 { "bind_v2", SLAP_ALLOW_BIND_V2 },
1722 { "bind_anon_cred", SLAP_ALLOW_BIND_ANON_CRED },
1723 { "bind_anon_dn", SLAP_ALLOW_BIND_ANON_DN },
1724 { "update_anon", SLAP_ALLOW_UPDATE_ANON },
1728 return mask_to_verbs( c, allowable_ops, global_allows );
1730 i = verbs_to_mask(c, allowable_ops, &allows);
1732 Debug(LDAP_DEBUG_ANY, "%s: "
1733 "unknown feature %s in \"allow <features>\" line\n",
1734 c->log, c->argv[i], 0);
1737 global_allows |= allows;
1742 config_disallows(ConfigArgs *c) {
1743 slap_mask_t disallows = 0;
1745 struct verb_mask_list disallowable_ops[] = {
1746 { "bind_anon", SLAP_DISALLOW_BIND_ANON },
1747 { "bind_simple", SLAP_DISALLOW_BIND_SIMPLE },
1748 { "bind_krb4", SLAP_DISALLOW_BIND_KRBV4 },
1749 { "tls_2_anon", SLAP_DISALLOW_TLS_2_ANON },
1750 { "tls_authc", SLAP_DISALLOW_TLS_AUTHC },
1754 return mask_to_verbs( c, disallowable_ops, global_disallows );
1756 i = verbs_to_mask(c, disallowable_ops, &disallows);
1758 Debug(LDAP_DEBUG_ANY, "%s: "
1759 "unknown feature %s in \"disallow <features>\" line\n",
1760 c->log, c->argv[i], 0);
1763 global_disallows |= disallows;
1768 config_requires(ConfigArgs *c) {
1769 slap_mask_t requires = 0;
1771 struct verb_mask_list requires_ops[] = {
1772 { "bind", SLAP_REQUIRE_BIND },
1773 { "LDAPv3", SLAP_REQUIRE_LDAP_V3 },
1774 { "authc", SLAP_REQUIRE_AUTHC },
1775 { "sasl", SLAP_REQUIRE_SASL },
1776 { "strong", SLAP_REQUIRE_STRONG },
1780 return mask_to_verbs( c, requires_ops, c->be->be_requires );
1782 i = verbs_to_mask(c, requires_ops, &requires);
1784 Debug(LDAP_DEBUG_ANY, "%s: "
1785 "unknown feature %s in \"require <features>\" line\n",
1786 c->log, c->argv[i], 0);
1789 c->be->be_requires = requires;
1794 config_loglevel(ConfigArgs *c) {
1797 struct verb_mask_list loglevel_ops[] = {
1798 { "Trace", LDAP_DEBUG_TRACE },
1799 { "Packets", LDAP_DEBUG_PACKETS },
1800 { "Args", LDAP_DEBUG_ARGS },
1801 { "Conns", LDAP_DEBUG_CONNS },
1802 { "BER", LDAP_DEBUG_BER },
1803 { "Filter", LDAP_DEBUG_FILTER },
1804 { "Config", LDAP_DEBUG_CONFIG },
1805 { "ACL", LDAP_DEBUG_ACL },
1806 { "Stats", LDAP_DEBUG_STATS },
1807 { "Stats2", LDAP_DEBUG_STATS2 },
1808 { "Shell", LDAP_DEBUG_SHELL },
1809 { "Parse", LDAP_DEBUG_PARSE },
1810 { "Cache", LDAP_DEBUG_CACHE },
1811 { "Index", LDAP_DEBUG_INDEX },
1817 return mask_to_verbs( c, loglevel_ops, ldap_syslog );
1822 for( i=1; i < c->argc; i++ ) {
1825 if ( isdigit( c->argv[i][0] ) ) {
1826 level = strtol( c->argv[i], &next, 10 );
1827 if ( next == NULL || next[0] != '\0' ) {
1828 Debug( LDAP_DEBUG_ANY,
1829 "%s: unable to parse level \"%s\" "
1830 "in \"loglevel <level> [...]\" line.\n",
1831 c->log, c->argv[i], 0);
1835 int j = verb_to_mask(c, loglevel_ops, c->argv[i][0]);
1836 if(!loglevel_ops[j].word) {
1837 Debug( LDAP_DEBUG_ANY,
1838 "%s: unknown level \"%s\" "
1839 "in \"loglevel <level> [...]\" line.\n",
1840 c->log, c->argv[i], 0);
1843 level = loglevel_ops[j].mask;
1845 ldap_syslog |= level;
1851 config_syncrepl(ConfigArgs *c) {
1853 if ( c->be->be_syncinfo ) {
1855 syncrepl_unparse( c->be->be_syncinfo, &bv );
1856 ber_bvarray_add( &c->rvalue_vals, &bv );
1861 if(SLAP_SHADOW(c->be)) {
1862 Debug(LDAP_DEBUG_ANY, "%s: "
1863 "syncrepl: database already shadowed.\n",
1866 } else if(add_syncrepl(c->be, c->argv, c->argc)) {
1869 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SYNC_SHADOW);
1874 config_referral(ConfigArgs *c) {
1875 struct berval vals[2];
1877 if ( default_referral ) {
1878 value_add( &c->rvalue_vals, default_referral );
1884 if(validate_global_referral(c->argv[1])) {
1885 Debug(LDAP_DEBUG_ANY, "%s: "
1886 "invalid URL (%s) in \"referral\" line.\n",
1887 c->log, c->argv[1], 0);
1891 ber_str2bv(c->argv[1], 0, 0, &vals[0]);
1892 vals[1].bv_val = NULL; vals[1].bv_len = 0;
1893 if(value_add(&default_referral, vals)) return(LDAP_OTHER);
1901 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
1902 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
1903 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
1904 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
1905 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
1906 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
1907 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
1908 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
1909 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
1914 config_security(ConfigArgs *c) {
1915 slap_ssf_set_t *set = &c->be->be_ssf_set;
1924 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
1925 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
1928 bv.bv_len = sprintf( numbuf, "%u", *tgt );
1929 bv.bv_len += sec_keys[i].key.bv_len;
1930 bv.bv_val = ch_malloc( bv.bv_len + 1);
1931 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
1932 strcpy( next, numbuf );
1933 ber_bvarray_add( &c->rvalue_vals, &bv );
1938 for(i = 1; i < c->argc; i++) {
1939 slap_ssf_t *tgt = NULL;
1941 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
1942 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
1943 sec_keys[j].key.bv_len)) {
1944 src = c->argv[i] + sec_keys[j].key.bv_len;
1945 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
1950 Debug(LDAP_DEBUG_ANY, "%s: "
1951 "unknown factor %s in \"security <factors>\" line\n",
1952 c->log, c->argv[i], 0);
1956 *tgt = strtol(src, &next, 10);
1957 if(next == NULL || next[0] != '\0' ) {
1958 Debug(LDAP_DEBUG_ANY, "%s: "
1959 "unable to parse factor \"%s\" in \"security <factors>\" line\n",
1960 c->log, c->argv[i], 0);
1967 static struct verb_mask_list tlskey[] = {
1968 { "no", SB_TLS_OFF },
1969 { "yes", SB_TLS_ON },
1970 { "critical", SB_TLS_CRITICAL }
1973 static struct verb_mask_list methkey[] = {
1974 { "simple", LDAP_AUTH_SIMPLE },
1975 #ifdef HAVE_CYRUS_SASL
1976 { "sasl", LDAP_AUTH_SASL },
1981 typedef struct cf_aux_table {
1985 struct verb_mask_list *aux;
1988 static cf_aux_table bindkey[] = {
1989 { BER_BVC("starttls="), offsetof(slap_bindconf, sb_tls), 0, tlskey },
1990 { BER_BVC("bindmethod="), offsetof(slap_bindconf, sb_method), 0, methkey },
1991 { BER_BVC("binddn="), offsetof(slap_bindconf, sb_binddn), 1, NULL },
1992 { BER_BVC("credentials="), offsetof(slap_bindconf, sb_cred), 1, NULL },
1993 { BER_BVC("saslmech="), offsetof(slap_bindconf, sb_saslmech), 0, NULL },
1994 { BER_BVC("secprops="), offsetof(slap_bindconf, sb_secprops), 0, NULL },
1995 { BER_BVC("realm="), offsetof(slap_bindconf, sb_realm), 0, NULL },
1996 { BER_BVC("authcID="), offsetof(slap_bindconf, sb_authcId), 0, NULL },
1997 { BER_BVC("authzID="), offsetof(slap_bindconf, sb_authzId), 1, NULL },
1998 { BER_BVNULL, 0, 0, NULL }
2001 int bindconf_parse( char *word, slap_bindconf *bc ) {
2006 for (tab = bindkey; !BER_BVISNULL(&tab->key); tab++) {
2007 if ( !strncasecmp( word, tab->key.bv_val, tab->key.bv_len )) {
2008 cptr = (char **)((char *)bc + tab->off);
2012 for (j=0; tab->aux[j].word; j++) {
2013 if (!strcasecmp(word+tab->key.bv_len, tab->aux[j].word)) {
2014 int *ptr = (int *)cptr;
2015 *ptr = tab->aux[j].mask;
2020 Debug(LDAP_DEBUG_ANY, "invalid bind config value %s\n",
2025 *cptr = ch_strdup(word+tab->key.bv_len);
2032 int bindconf_unparse( slap_bindconf *bc, struct berval *bv ) {
2033 char buf[BUFSIZ], *ptr;
2039 for (tab = bindkey; !BER_BVISNULL(&tab->key); tab++) {
2040 cptr = (char **)((char *)bc + tab->off);
2042 int *ip = (int *)cptr, i;
2043 for ( i=0; tab->aux[i].word; i++ ) {
2044 if ( *ip == tab->aux[i].mask ) {
2046 ptr = lutil_strcopy( ptr, tab->key.bv_val );
2047 ptr = lutil_strcopy( ptr, tab->aux[i].word );
2051 } else if ( *cptr ) {
2053 ptr = lutil_strcopy( ptr, tab->key.bv_val );
2054 if ( tab->quote ) *ptr++ = '"';
2055 ptr = lutil_strcopy( ptr, *cptr );
2056 if ( tab->quote ) *ptr++ = '"';
2060 tmp.bv_len = ptr - buf;
2061 ber_dupbv( bv, &tmp );
2065 void bindconf_free( slap_bindconf *bc ) {
2066 if ( bc->sb_binddn ) {
2067 ch_free( bc->sb_binddn );
2069 if ( bc->sb_cred ) {
2070 ch_free( bc->sb_cred );
2072 if ( bc->sb_saslmech ) {
2073 ch_free( bc->sb_saslmech );
2075 if ( bc->sb_secprops ) {
2076 ch_free( bc->sb_secprops );
2078 if ( bc->sb_realm ) {
2079 ch_free( bc->sb_realm );
2081 if ( bc->sb_authcId ) {
2082 ch_free( bc->sb_authcId );
2084 if ( bc->sb_authzId ) {
2085 ch_free( bc->sb_authzId );
2090 anlist_unparse( AttributeName *an, char *ptr ) {
2093 for (; !BER_BVISNULL( &an->an_name ); an++) {
2094 if ( comma ) *ptr++ = ',';
2095 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
2102 replica_unparse( struct slap_replica_info *ri, int i, struct berval *bv )
2106 struct berval bc = {0};
2109 len = sprintf(numbuf, "{%d}", i );
2111 len += strlen( ri->ri_uri ) + STRLENOF("uri=");
2112 if ( ri->ri_nsuffix ) {
2113 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
2114 len += ri->ri_nsuffix[i].bv_len + STRLENOF(" suffix=\"\"");
2117 if ( ri->ri_attrs ) {
2118 len += STRLENOF("attr");
2119 if ( ri->ri_exclude ) len++;
2120 for (i=0; !BER_BVISNULL( &ri->ri_attrs[i].an_name ); i++) {
2121 len += 1 + ri->ri_attrs[i].an_name.bv_len;
2124 bindconf_unparse( &ri->ri_bindconf, &bc );
2127 bv->bv_val = ch_malloc(len + 1);
2130 ptr = lutil_strcopy( bv->bv_val, numbuf );
2131 ptr = lutil_strcopy( ptr, "uri=" );
2132 ptr = lutil_strcopy( ptr, ri->ri_uri );
2134 if ( ri->ri_nsuffix ) {
2135 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
2136 ptr = lutil_strcopy( ptr, " suffix=\"" );
2137 ptr = lutil_strcopy( ptr, ri->ri_nsuffix[i].bv_val );
2141 if ( ri->ri_attrs ) {
2142 ptr = lutil_strcopy( ptr, "attr" );
2143 if ( ri->ri_exclude ) *ptr++ = '!';
2145 ptr = anlist_unparse( ri->ri_attrs, ptr );
2148 strcpy( ptr, bc.bv_val );
2149 ch_free( bc.bv_val );
2154 config_replica(ConfigArgs *c) {
2155 int i, nr = -1, len;
2156 char *replicahost, *replicauri;
2160 if (c->be->be_replica) {
2162 for (i=0;c->be->be_replica[i]; i++) {
2163 replica_unparse( c->be->be_replica[i], i, &bv );
2164 ber_bvarray_add( &c->rvalue_vals, &bv );
2170 if(SLAP_MONITOR(c->be)) {
2171 Debug(LDAP_DEBUG_ANY, "%s: "
2172 "\"replica\" should not be used inside monitor database\n",
2174 return(0); /* FIXME: should this be an error? */
2177 for(i = 1; i < c->argc; i++) {
2178 if(!strncasecmp(c->argv[i], "host=", STRLENOF("host="))) {
2179 replicahost = c->argv[i] + STRLENOF("host=");
2180 len = strlen( replicahost );
2181 replicauri = ch_malloc( len + STRLENOF("ldap://") + 1 );
2182 sprintf( replicauri, "ldap://%s", replicahost );
2183 replicahost = replicauri + STRLENOF( "ldap://");
2184 nr = add_replica_info(c->be, replicauri, replicahost);
2186 } else if(!strncasecmp(c->argv[i], "uri=", STRLENOF("uri="))) {
2187 if(ldap_url_parse(c->argv[i] + STRLENOF("uri="), &ludp) != LDAP_SUCCESS) {
2188 Debug(LDAP_DEBUG_ANY, "%s: "
2189 "replica line contains invalid "
2190 "uri definition.\n", c->log, 0, 0);
2193 if(!ludp->lud_host) {
2194 Debug(LDAP_DEBUG_ANY, "%s: "
2195 "replica line contains invalid "
2196 "uri definition - missing hostname.\n",
2200 ldap_free_urldesc(ludp);
2201 replicauri = c->argv[i] + STRLENOF("uri=");
2202 replicauri = ch_strdup( replicauri );
2203 replicahost = strchr( replicauri, '/' );
2205 nr = add_replica_info(c->be, replicauri, replicahost);
2210 Debug(LDAP_DEBUG_ANY, "%s: "
2211 "missing host or uri in \"replica\" line\n",
2214 } else if(nr == -1) {
2215 Debug(LDAP_DEBUG_ANY, "%s: "
2216 "unable to add replica \"%s\"\n",
2217 c->log, replicauri, 0);
2220 for(i = 1; i < c->argc; i++) {
2221 if(!strncasecmp(c->argv[i], "suffix=", STRLENOF( "suffix="))) {
2222 switch(add_replica_suffix(c->be, nr, c->argv[i] + STRLENOF("suffix="))) {
2224 Debug(LDAP_DEBUG_ANY, "%s: "
2225 "suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
2226 c->log, c->argv[i] + STRLENOF("suffix="), 0);
2229 Debug(LDAP_DEBUG_ANY, "%s: "
2230 "unable to normalize suffix in \"replica\" line (ignored)\n",
2235 } else if(!strncasecmp(c->argv[i], "attr", STRLENOF("attr"))) {
2237 char *arg = c->argv[i] + STRLENOF("attr");
2245 if(add_replica_attrs(c->be, nr, arg + 1, exclude)) {
2246 Debug(LDAP_DEBUG_ANY, "%s: "
2247 "attribute \"%s\" in \"replica\" line is unknown\n",
2248 c->log, arg + 1, 0);
2251 } else if ( bindconf_parse( c->argv[i],
2252 &c->be->be_replica[nr]->ri_bindconf ) ) {
2261 config_updatedn(ConfigArgs *c) {
2265 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
2266 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
2267 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
2272 if(SLAP_SHADOW(c->be)) {
2273 Debug(LDAP_DEBUG_ANY, "%s: "
2274 "updatedn: database already shadowed.\n",
2279 ber_str2bv(c->argv[1], 0, 0, &dn);
2281 rc = dnNormalize(0, NULL, NULL, &dn, &c->be->be_update_ndn, NULL);
2283 if(rc != LDAP_SUCCESS) {
2284 Debug(LDAP_DEBUG_ANY, "%s: "
2285 "updatedn DN is invalid: %d (%s)\n",
2286 c->log, rc, ldap_err2string( rc ));
2290 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
2295 config_updateref(ConfigArgs *c) {
2296 struct berval vals[2];
2298 if ( c->be->be_update_refs ) {
2299 value_add( &c->rvalue_vals, c->be->be_update_refs );
2305 if(!SLAP_SHADOW(c->be)) {
2306 Debug(LDAP_DEBUG_ANY, "%s: "
2307 "updateref line must come after syncrepl or updatedn.\n",
2312 if(validate_global_referral(c->argv[1])) {
2313 Debug(LDAP_DEBUG_ANY, "%s: "
2314 "invalid URL (%s) in \"updateref\" line.\n",
2315 c->log, c->argv[1], 0);
2318 ber_str2bv(c->argv[1], 0, 0, &vals[0]);
2319 vals[1].bv_val = NULL;
2320 if(value_add(&c->be->be_update_refs, vals)) return(LDAP_OTHER);
2325 config_include(ConfigArgs *c) {
2326 unsigned long savelineno = c->lineno;
2329 ConfigFile *cfsave = cfn;
2330 ConfigFile *cf2 = NULL;
2334 cf = ch_calloc( 1, sizeof(ConfigFile));
2335 if ( cfn->c_kids ) {
2336 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
2342 rc = read_config_file(c->argv[1], c->depth + 1, c);
2343 c->lineno = savelineno - 1;
2346 if ( cf2 ) cf2->c_sibs = NULL;
2347 else cfn->c_kids = NULL;
2355 config_tls_option(ConfigArgs *c) {
2358 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; break;
2359 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
2360 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
2361 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
2362 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
2363 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
2364 default: Debug(LDAP_DEBUG_ANY, "%s: "
2365 "unknown tls_option <%x>\n",
2366 c->log, c->type, 0);
2369 return ldap_pvt_tls_get_option( NULL, flag, &c->value_string );
2371 ch_free(c->value_string);
2372 return(ldap_pvt_tls_set_option(NULL, flag, c->argv[1]));
2375 /* FIXME: this ought to be provided by libldap */
2377 config_tls_config(ConfigArgs *c) {
2379 struct verb_mask_list crlkeys[] = {
2380 { "none", LDAP_OPT_X_TLS_CRL_NONE },
2381 { "peer", LDAP_OPT_X_TLS_CRL_PEER },
2382 { "all", LDAP_OPT_X_TLS_CRL_ALL },
2385 struct verb_mask_list vfykeys[] = {
2386 { "never", LDAP_OPT_X_TLS_NEVER },
2387 { "demand", LDAP_OPT_X_TLS_DEMAND },
2388 { "try", LDAP_OPT_X_TLS_TRY },
2389 { "hard", LDAP_OPT_X_TLS_HARD },
2393 #ifdef HAVE_OPENSSL_CRL
2394 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; keys = crlkeys;
2397 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; keys = vfykeys;
2399 default: Debug(LDAP_DEBUG_ANY, "%s: "
2400 "unknown tls_option <%x>\n",
2401 c->log, c->type, 0);
2404 ldap_pvt_tls_get_option( NULL, flag, &c->value_int );
2405 for (i=0; keys[i].word; i++) {
2406 if (keys[i].mask == c->value_int) {
2407 c->value_string = ch_strdup( keys[i].word );
2413 ch_free( c->value_string );
2414 if(isdigit((unsigned char)c->argv[1][0])) {
2415 i = atoi(c->argv[1]);
2416 return(ldap_pvt_tls_set_option(NULL, flag, &i));
2418 return(ldap_int_tls_config(NULL, flag, c->argv[1]));
2423 /* -------------------------------------- */
2427 strtok_quote( char *line, char *sep )
2433 strtok_quote_ptr = NULL;
2434 if ( line != NULL ) {
2437 while ( *next && strchr( sep, *next ) ) {
2441 if ( *next == '\0' ) {
2447 for ( inquote = 0; *next; ) {
2455 AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
2461 next + 1, strlen( next + 1 ) + 1 );
2462 next++; /* dont parse the escaped character */
2467 if ( strchr( sep, *next ) != NULL ) {
2468 strtok_quote_ptr = next;
2481 static char buf[BUFSIZ];
2483 static size_t lmax, lcur;
2485 #define CATLINE( buf ) \
2487 size_t len = strlen( buf ); \
2488 while ( lcur + len + 1 > lmax ) { \
2490 line = (char *) ch_realloc( line, lmax ); \
2492 strcpy( line + lcur, buf ); \
2497 fp_getline_init(ConfigArgs *c) {
2503 fp_getline( FILE *fp, ConfigArgs *c )
2511 /* avoid stack of bufs */
2512 if ( strncasecmp( line, "include", STRLENOF( "include" ) ) == 0 ) {
2518 while ( fgets( buf, sizeof( buf ), fp ) ) {
2519 p = strchr( buf, '\n' );
2521 if ( p > buf && p[-1] == '\r' ) {
2529 && ( p = line + strlen( line ) - 1 )[0] == '\\'
2536 if ( !isspace( (unsigned char)buf[0] ) ) {
2547 return(line[0] ? 1 : 0);
2551 fp_parse_line(ConfigArgs *c)
2554 char *tline = ch_strdup(c->line);
2555 char *hide[] = { "rootpw", "replica", "bindpw", "pseudorootpw", "dbpasswd", '\0' };
2559 token = strtok_quote(tline, " \t");
2561 if(token) for(i = 0; hide[i]; i++) if(!strcasecmp(token, hide[i])) break;
2562 if(strtok_quote_ptr) *strtok_quote_ptr = ' ';
2563 Debug(LDAP_DEBUG_CONFIG, "line %lu (%s%s)\n", c->lineno, hide[i] ? hide[i] : c->line, hide[i] ? " ***" : "");
2564 if(strtok_quote_ptr) *strtok_quote_ptr = '\0';
2566 for(; token; token = strtok_quote(NULL, " \t")) {
2567 if(c->argc == c->argv_size - 1) {
2569 tmp = ch_realloc(c->argv, (c->argv_size + ARGS_STEP) * sizeof(*c->argv));
2571 Debug(LDAP_DEBUG_ANY, "line %lu: out of memory\n", c->lineno, 0, 0);
2575 c->argv_size += ARGS_STEP;
2577 c->argv[c->argc++] = token;
2579 c->argv[c->argc] = NULL;
2586 ucdata_unload( UCDATA_ALL );
2588 /* NOTE: in case of early exit, frontendDB can be NULL */
2589 if ( frontendDB->be_schemandn.bv_val )
2590 free( frontendDB->be_schemandn.bv_val );
2591 if ( frontendDB->be_schemadn.bv_val )
2592 free( frontendDB->be_schemadn.bv_val );
2593 if ( frontendDB->be_acl )
2594 acl_destroy( frontendDB->be_acl, NULL );
2597 if ( slapd_args_file )
2598 free ( slapd_args_file );
2599 if ( slapd_pid_file )
2600 free ( slapd_pid_file );
2601 if ( default_passwd_hash )
2602 ldap_charray_free( default_passwd_hash );
2615 si = (syncinfo_t *) ch_calloc( 1, sizeof( syncinfo_t ) );
2618 Debug( LDAP_DEBUG_ANY, "out of memory in add_syncrepl\n", 0, 0, 0 );
2622 si->si_bindconf.sb_tls = SB_TLS_OFF;
2623 si->si_bindconf.sb_method = LDAP_AUTH_SIMPLE;
2624 si->si_schemachecking = 0;
2625 ber_str2bv( "(objectclass=*)", STRLENOF("(objectclass=*)"), 1,
2626 &si->si_filterstr );
2627 si->si_base.bv_val = NULL;
2628 si->si_scope = LDAP_SCOPE_SUBTREE;
2629 si->si_attrsonly = 0;
2630 si->si_anlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ));
2631 si->si_exanlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ));
2632 si->si_attrs = NULL;
2633 si->si_allattrs = 0;
2634 si->si_allopattrs = 0;
2635 si->si_exattrs = NULL;
2636 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2637 si->si_interval = 86400;
2638 si->si_retryinterval = NULL;
2639 si->si_retrynum_init = NULL;
2640 si->si_retrynum = NULL;
2641 si->si_manageDSAit = 0;
2645 si->si_presentlist = NULL;
2646 LDAP_LIST_INIT( &si->si_nonpresentlist );
2647 ldap_pvt_thread_mutex_init( &si->si_mutex );
2649 rc = parse_syncrepl_line( cargv, cargc, si );
2652 Debug( LDAP_DEBUG_ANY, "failed to add syncinfo\n", 0, 0, 0 );
2653 syncinfo_free( si );
2656 Debug( LDAP_DEBUG_CONFIG,
2657 "Config: ** successfully added syncrepl \"%s\"\n",
2658 BER_BVISNULL( &si->si_provideruri ) ?
2659 "(null)" : si->si_provideruri.bv_val, 0, 0 );
2660 if ( !si->si_schemachecking ) {
2661 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NO_SCHEMA_CHECK;
2664 be->be_syncinfo = si;
2669 /* NOTE: used & documented in slapd.conf(5) */
2671 #define PROVIDERSTR "provider"
2672 #define TYPESTR "type"
2673 #define INTERVALSTR "interval"
2674 #define SEARCHBASESTR "searchbase"
2675 #define FILTERSTR "filter"
2676 #define SCOPESTR "scope"
2677 #define ATTRSSTR "attrs"
2678 #define ATTRSONLYSTR "attrsonly"
2679 #define SLIMITSTR "sizelimit"
2680 #define TLIMITSTR "timelimit"
2681 #define SCHEMASTR "schemachecking"
2683 /* FIXME: undocumented */
2684 #define OLDAUTHCSTR "bindprincipal"
2685 #define EXATTRSSTR "exattrs"
2686 #define RETRYSTR "retry"
2689 #define LASTMODSTR "lastmod"
2690 #define LMGENSTR "gen"
2691 #define LMNOSTR "no"
2692 #define LMREQSTR "req"
2693 #define SRVTABSTR "srvtab"
2694 #define SUFFIXSTR "suffix"
2695 #define MANAGEDSAITSTR "manageDSAit"
2698 #define GOT_ID 0x0001
2699 #define GOT_PROVIDER 0x0002
2702 #define GOT_ALL (GOT_ID|GOT_PROVIDER)
2708 { BER_BVC("base"), LDAP_SCOPE_BASE },
2709 { BER_BVC("one"), LDAP_SCOPE_ONELEVEL },
2710 #ifdef LDAP_SCOPE_SUBORDINATE
2711 { BER_BVC("children"), LDAP_SCOPE_SUBORDINATE },
2712 { BER_BVC("subordinate"), 0 },
2714 { BER_BVC("sub"), LDAP_SCOPE_SUBTREE },
2719 parse_syncrepl_line(
2729 for ( i = 1; i < cargc; i++ ) {
2730 if ( !strncasecmp( cargv[ i ], IDSTR "=",
2731 STRLENOF( IDSTR "=" ) ) )
2734 /* '\0' string terminator accounts for '=' */
2735 val = cargv[ i ] + STRLENOF( IDSTR "=" );
2737 if ( tmp >= 1000 || tmp < 0 ) {
2738 fprintf( stderr, "Error: parse_syncrepl_line: "
2739 "syncrepl id %d is out of range [0..999]\n", tmp );
2744 } else if ( !strncasecmp( cargv[ i ], PROVIDERSTR "=",
2745 STRLENOF( PROVIDERSTR "=" ) ) )
2747 val = cargv[ i ] + STRLENOF( PROVIDERSTR "=" );
2748 ber_str2bv( val, 0, 1, &si->si_provideruri );
2749 gots |= GOT_PROVIDER;
2750 } else if ( !strncasecmp( cargv[ i ], SCHEMASTR "=",
2751 STRLENOF( SCHEMASTR "=" ) ) )
2753 val = cargv[ i ] + STRLENOF( SCHEMASTR "=" );
2754 if ( !strncasecmp( val, "on", STRLENOF( "on" ) )) {
2755 si->si_schemachecking = 1;
2756 } else if ( !strncasecmp( val, "off", STRLENOF( "off" ) ) ) {
2757 si->si_schemachecking = 0;
2759 si->si_schemachecking = 1;
2761 } else if ( !strncasecmp( cargv[ i ], FILTERSTR "=",
2762 STRLENOF( FILTERSTR "=" ) ) )
2764 val = cargv[ i ] + STRLENOF( FILTERSTR "=" );
2765 ber_str2bv( val, 0, 1, &si->si_filterstr );
2766 } else if ( !strncasecmp( cargv[ i ], SEARCHBASESTR "=",
2767 STRLENOF( SEARCHBASESTR "=" ) ) )
2772 val = cargv[ i ] + STRLENOF( SEARCHBASESTR "=" );
2773 if ( si->si_base.bv_val ) {
2774 ch_free( si->si_base.bv_val );
2776 ber_str2bv( val, 0, 0, &bv );
2777 rc = dnNormalize( 0, NULL, NULL, &bv, &si->si_base, NULL );
2778 if ( rc != LDAP_SUCCESS ) {
2779 fprintf( stderr, "Invalid base DN \"%s\": %d (%s)\n",
2780 val, rc, ldap_err2string( rc ) );
2783 } else if ( !strncasecmp( cargv[ i ], SCOPESTR "=",
2784 STRLENOF( SCOPESTR "=" ) ) )
2787 val = cargv[ i ] + STRLENOF( SCOPESTR "=" );
2788 for ( j=0; !BER_BVISNULL(&scopes[j].key); j++ ) {
2789 if (!strncasecmp( val, scopes[j].key.bv_val,
2790 scopes[j].key.bv_len )) {
2791 while (!scopes[j].val) j--;
2792 si->si_scope = scopes[j].val;
2796 if ( BER_BVISNULL(&scopes[j].key) ) {
2797 fprintf( stderr, "Error: parse_syncrepl_line: "
2798 "unknown scope \"%s\"\n", val);
2801 } else if ( !strncasecmp( cargv[ i ], ATTRSONLYSTR "=",
2802 STRLENOF( ATTRSONLYSTR "=" ) ) )
2804 si->si_attrsonly = 1;
2805 } else if ( !strncasecmp( cargv[ i ], ATTRSSTR "=",
2806 STRLENOF( ATTRSSTR "=" ) ) )
2808 val = cargv[ i ] + STRLENOF( ATTRSSTR "=" );
2809 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") ) ) {
2811 attr_fname = ch_strdup( val + STRLENOF(":include:") );
2812 si->si_anlist = file2anlist( si->si_anlist, attr_fname, " ,\t" );
2813 if ( si->si_anlist == NULL ) {
2814 ch_free( attr_fname );
2817 si->si_anfile = attr_fname;
2819 char *str, *s, *next;
2820 char delimstr[] = " ,\t";
2821 str = ch_strdup( val );
2822 for ( s = ldap_pvt_strtok( str, delimstr, &next );
2824 s = ldap_pvt_strtok( NULL, delimstr, &next ) )
2826 if ( strlen(s) == 1 && *s == '*' ) {
2827 si->si_allattrs = 1;
2828 *(val + ( s - str )) = delimstr[0];
2830 if ( strlen(s) == 1 && *s == '+' ) {
2831 si->si_allopattrs = 1;
2832 *(val + ( s - str )) = delimstr[0];
2836 si->si_anlist = str2anlist( si->si_anlist, val, " ,\t" );
2837 if ( si->si_anlist == NULL ) {
2841 } else if ( !strncasecmp( cargv[ i ], EXATTRSSTR "=",
2842 STRLENOF( EXATTRSSTR "=" ) ) )
2844 val = cargv[ i ] + STRLENOF( EXATTRSSTR "=" );
2845 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") )) {
2847 attr_fname = ch_strdup( val + STRLENOF(":include:") );
2848 si->si_exanlist = file2anlist(
2849 si->si_exanlist, attr_fname, " ,\t" );
2850 if ( si->si_exanlist == NULL ) {
2851 ch_free( attr_fname );
2854 ch_free( attr_fname );
2856 si->si_exanlist = str2anlist( si->si_exanlist, val, " ,\t" );
2857 if ( si->si_exanlist == NULL ) {
2861 } else if ( !strncasecmp( cargv[ i ], TYPESTR "=",
2862 STRLENOF( TYPESTR "=" ) ) )
2864 val = cargv[ i ] + STRLENOF( TYPESTR "=" );
2865 if ( !strncasecmp( val, "refreshOnly",
2866 STRLENOF("refreshOnly") ))
2868 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2869 } else if ( !strncasecmp( val, "refreshAndPersist",
2870 STRLENOF("refreshAndPersist") ))
2872 si->si_type = LDAP_SYNC_REFRESH_AND_PERSIST;
2873 si->si_interval = 60;
2875 fprintf( stderr, "Error: parse_syncrepl_line: "
2876 "unknown sync type \"%s\"\n", val);
2879 } else if ( !strncasecmp( cargv[ i ], INTERVALSTR "=",
2880 STRLENOF( INTERVALSTR "=" ) ) )
2882 val = cargv[ i ] + STRLENOF( INTERVALSTR "=" );
2883 if ( si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ) {
2884 si->si_interval = 0;
2892 hstr = strchr( dstr, ':' );
2893 if ( hstr == NULL ) {
2894 fprintf( stderr, "Error: parse_syncrepl_line: "
2895 "invalid interval \"%s\"\n", val );
2899 mstr = strchr( hstr, ':' );
2900 if ( mstr == NULL ) {
2901 fprintf( stderr, "Error: parse_syncrepl_line: "
2902 "invalid interval \"%s\"\n", val );
2906 sstr = strchr( mstr, ':' );
2907 if ( sstr == NULL ) {
2908 fprintf( stderr, "Error: parse_syncrepl_line: "
2909 "invalid interval \"%s\"\n", val );
2918 if (( hh > 24 ) || ( hh < 0 ) ||
2919 ( mm > 60 ) || ( mm < 0 ) ||
2920 ( ss > 60 ) || ( ss < 0 ) || ( dd < 0 )) {
2921 fprintf( stderr, "Error: parse_syncrepl_line: "
2922 "invalid interval \"%s\"\n", val );
2925 si->si_interval = (( dd * 24 + hh ) * 60 + mm ) * 60 + ss;
2927 if ( si->si_interval < 0 ) {
2928 fprintf( stderr, "Error: parse_syncrepl_line: "
2929 "invalid interval \"%ld\"\n",
2930 (long) si->si_interval);
2933 } else if ( !strncasecmp( cargv[ i ], RETRYSTR "=",
2934 STRLENOF( RETRYSTR "=" ) ) )
2939 val = cargv[ i ] + STRLENOF( RETRYSTR "=" );
2940 retry_list = (char **) ch_calloc( 1, sizeof( char * ));
2941 retry_list[0] = NULL;
2943 slap_str2clist( &retry_list, val, " ,\t" );
2945 for ( k = 0; retry_list && retry_list[k]; k++ ) ;
2949 "Error: incomplete syncrepl retry list\n" );
2950 for ( k = 0; retry_list && retry_list[k]; k++ ) {
2951 ch_free( retry_list[k] );
2953 ch_free( retry_list );
2954 exit( EXIT_FAILURE );
2956 si->si_retryinterval = (time_t *) ch_calloc( n + 1, sizeof( time_t ));
2957 si->si_retrynum = (int *) ch_calloc( n + 1, sizeof( int ));
2958 si->si_retrynum_init = (int *) ch_calloc( n + 1, sizeof( int ));
2959 for ( j = 0; j < n; j++ ) {
2960 si->si_retryinterval[j] = atoi( retry_list[j*2] );
2961 if ( *retry_list[j*2+1] == '+' ) {
2962 si->si_retrynum_init[j] = -1;
2963 si->si_retrynum[j] = -1;
2967 si->si_retrynum_init[j] = atoi( retry_list[j*2+1] );
2968 si->si_retrynum[j] = atoi( retry_list[j*2+1] );
2971 si->si_retrynum_init[j] = -2;
2972 si->si_retrynum[j] = -2;
2973 si->si_retryinterval[j] = 0;
2975 for ( k = 0; retry_list && retry_list[k]; k++ ) {
2976 ch_free( retry_list[k] );
2978 ch_free( retry_list );
2979 } else if ( !strncasecmp( cargv[ i ], MANAGEDSAITSTR "=",
2980 STRLENOF( MANAGEDSAITSTR "=" ) ) )
2982 val = cargv[ i ] + STRLENOF( MANAGEDSAITSTR "=" );
2983 si->si_manageDSAit = atoi( val );
2984 } else if ( !strncasecmp( cargv[ i ], SLIMITSTR "=",
2985 STRLENOF( SLIMITSTR "=") ) )
2987 val = cargv[ i ] + STRLENOF( SLIMITSTR "=" );
2988 si->si_slimit = atoi( val );
2989 } else if ( !strncasecmp( cargv[ i ], TLIMITSTR "=",
2990 STRLENOF( TLIMITSTR "=" ) ) )
2992 val = cargv[ i ] + STRLENOF( TLIMITSTR "=" );
2993 si->si_tlimit = atoi( val );
2994 } else if ( bindconf_parse( cargv[i], &si->si_bindconf )) {
2995 fprintf( stderr, "Error: parse_syncrepl_line: "
2996 "unknown keyword \"%s\"\n", cargv[ i ] );
3001 if ( gots != GOT_ALL ) {
3003 "Error: Malformed \"syncrepl\" line in slapd config file" );
3013 syncrepl_unparse( syncinfo_t *si, struct berval *bv )
3016 char buf[BUFSIZ*2], *ptr;
3019 bindconf_unparse( &si->si_bindconf, &bc );
3021 ptr += sprintf( ptr, IDSTR "=%03d " PROVIDERSTR "=%s",
3022 si->si_rid, si->si_provideruri.bv_val );
3023 if ( !BER_BVISNULL( &bc )) {
3024 ptr = lutil_strcopy( ptr, bc.bv_val );
3027 if ( !BER_BVISEMPTY( &si->si_filterstr )) {
3028 ptr = lutil_strcopy( ptr, " " FILTERSTR "=\"" );
3029 ptr = lutil_strcopy( ptr, si->si_filterstr.bv_val );
3032 if ( !BER_BVISNULL( &si->si_base )) {
3033 ptr = lutil_strcopy( ptr, " " SEARCHBASESTR "=\"" );
3034 ptr = lutil_strcopy( ptr, si->si_base.bv_val );
3037 for (i=0; !BER_BVISNULL(&scopes[i].key);i++) {
3038 if ( si->si_scope == scopes[i].val ) {
3039 ptr = lutil_strcopy( ptr, " " SCOPESTR "=" );
3040 ptr = lutil_strcopy( ptr, scopes[i].key.bv_val );
3044 if ( si->si_attrsonly ) {
3045 ptr = lutil_strcopy( ptr, " " ATTRSONLYSTR "=yes" );
3047 if ( si->si_anfile ) {
3048 ptr = lutil_strcopy( ptr, " " ATTRSSTR "=:include:" );
3049 ptr = lutil_strcopy( ptr, si->si_anfile );
3050 } else if ( si->si_allattrs || si->si_allopattrs ||
3051 ( si->si_anlist && !BER_BVISNULL(&si->si_anlist[0].an_name) )) {
3053 ptr = lutil_strcopy( ptr, " " ATTRSSTR "=\"" );
3055 ptr = anlist_unparse( si->si_anlist, ptr );
3056 if ( si->si_allattrs ) {
3057 if ( old != ptr ) *ptr++ = ',';
3060 if ( si->si_allopattrs ) {
3061 if ( old != ptr ) *ptr++ = ',';
3066 if ( si->si_exanlist && !BER_BVISNULL(&si->si_exanlist[0].an_name) ) {
3067 ptr = lutil_strcopy( ptr, " " EXATTRSSTR "=" );
3068 ptr = anlist_unparse( si->si_exanlist, ptr );
3070 ptr = lutil_strcopy( ptr, " " SCHEMASTR "=" );
3071 ptr = lutil_strcopy( ptr, si->si_schemachecking ? "on" : "off" );
3073 ptr = lutil_strcopy( ptr, " " TYPESTR "=" );
3074 ptr = lutil_strcopy( ptr, si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ?
3075 "refreshAndPersist" : "refreshOnly" );
3077 if ( si->si_type == LDAP_SYNC_REFRESH_ONLY ) {
3080 dd = si->si_interval;
3087 ptr = lutil_strcopy( ptr, " " INTERVALSTR "=" );
3088 ptr += sprintf( ptr, "%02d:%02d:%02d:%02d", dd, hh, mm, ss );
3089 } else if ( si->si_retryinterval ) {
3091 ptr = lutil_strcopy( ptr, " " RETRYSTR "=\"" );
3092 for (i=0; si->si_retryinterval[i]; i++) {
3093 if ( space ) *ptr++ = ' ';
3095 ptr += sprintf( ptr, "%d", si->si_retryinterval[i] );
3096 if ( si->si_retrynum_init[i] == -1 )
3099 ptr += sprintf( ptr, "%d", si->si_retrynum_init );
3104 #if 0 /* FIXME: unused in syncrepl.c, should remove it */
3105 ptr = lutil_strcopy( ptr, " " MANAGEDSAITSTR "=" );
3106 ptr += sprintf( ptr, "%d", si->si_manageDSAit );
3109 if ( si->si_slimit ) {
3110 ptr = lutil_strcopy( ptr, " " SLIMITSTR "=" );
3111 ptr += sprintf( ptr, "%d", si->si_slimit );
3114 if ( si->si_tlimit ) {
3115 ptr = lutil_strcopy( ptr, " " TLIMITSTR "=" );
3116 ptr += sprintf( ptr, "%d", si->si_tlimit );
3118 bc.bv_len = ptr - buf;
3120 ber_dupbv( bv, &bc );
3124 slap_str2clist( char ***out, char *in, const char *brkstr )
3132 /* find last element in list */
3133 for (i = 0; *out && (*out)[i]; i++);
3135 /* protect the input string from strtok */
3136 str = ch_strdup( in );
3138 if ( *str == '\0' ) {
3143 /* Count words in string */
3145 for ( s = str; *s; s++ ) {
3146 if ( strchr( brkstr, *s ) != NULL ) {
3151 *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
3153 for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
3155 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
3157 *new = ch_strdup( s );