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 { "OLcfg", "1.3.6.1.4.1.4203.666.11.1" },
189 { "OLcfgAt", "OLcfg:3" },
190 { "OLcfgOc", "OLcfg:4" },
191 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
192 { "OMsInteger", "OMsyn:2" },
193 { "OMsBoolean", "OMsyn:7" },
194 { "OMsDN", "OMsyn:12" },
195 { "OMsDirectoryString", "OMsyn:15" },
196 { "OMsOctetString", "OMsyn:40" },
200 /* alphabetical ordering */
202 static ConfigTable SystemConfiguration[] = {
203 /* This attr is read-only */
204 { "", "", 0, 0, 0, ARG_MAGIC,
205 &config_fname, "( OLcfgAt:78 NAME 'olcConfigFile' "
206 "DESC 'File for slapd configuration directives' "
207 "EQUALITY caseIgnoreMatch "
208 "SYNTAX OMsDirectoryString )", NULL, NULL },
209 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
210 &config_generic, "( OLcfgAt:1 NAME 'olcAccess' "
211 "DESC 'Access Control List' "
212 "EQUALITY caseIgnoreMatch "
213 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
214 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
215 &config_allows, "( OLcfgAt:2 NAME 'olcAllows' "
216 "DESC 'Allowed set of deprecated features' "
217 "EQUALITY caseIgnoreMatch "
218 "SYNTAX OMsDirectoryString )", NULL, NULL },
219 { "argsfile", "file", 2, 2, 0, ARG_STRING,
220 &slapd_args_file, "( OLcfgAt:3 NAME 'olcArgsFile' "
221 "DESC 'File for slapd command line options' "
222 "EQUALITY caseIgnoreMatch "
223 "SYNTAX OMsDirectoryString )", NULL, NULL },
224 /* Use standard 'attributeTypes' attr */
225 { "attribute", "attribute", 2, 0, 9, ARG_PAREN|ARG_MAGIC|CFG_ATTR,
226 &config_generic, NULL, NULL, NULL },
227 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
228 &config_generic, "( OLcfgAt:5 NAME 'olcAttributeOptions' "
229 "EQUALITY caseIgnoreMatch "
230 "SYNTAX OMsDirectoryString )", NULL, NULL },
231 { "authid-rewrite", NULL, 2, 0, 0,
232 #ifdef SLAP_AUTH_REWRITE
233 ARG_MAGIC|CFG_REWRITE, &config_generic,
237 "( OLcfgAt:6 NAME 'olcAuthIDRewrite' "
238 "EQUALITY caseIgnoreMatch "
239 "SYNTAX OMsDirectoryString )", NULL, NULL },
240 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
241 &config_generic, "( OLcfgAt:7 NAME 'olcAuthzPolicy' "
242 "EQUALITY caseIgnoreMatch "
243 "SYNTAX OMsDirectoryString )", NULL, NULL },
244 { "authz-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
245 &config_generic, "( OLcfgAt:8 NAME 'olcAuthzRegexp' "
246 "EQUALITY caseIgnoreMatch "
247 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
248 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
249 &config_generic, "( OLcfgAt:9 NAME 'olcBackend' "
250 "DESC 'A type of backend' "
251 "EQUALITY caseIgnoreMatch "
252 "SYNTAX OMsDirectoryString )", NULL, NULL },
253 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_CONCUR,
254 &config_generic, "( OLcfgAt:10 NAME 'olcConcurrency' "
255 "SYNTAX OMsInteger )", NULL, NULL },
256 { "conn_max_pending", "max", 2, 2, 0, ARG_LONG,
257 &slap_conn_max_pending, "( OLcfgAt:11 NAME 'olcConnMaxPending' "
258 "SYNTAX OMsInteger )", NULL, NULL },
259 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_LONG,
260 &slap_conn_max_pending_auth, "( OLcfgAt:12 NAME 'olcConnMaxPendingAuth' "
261 "SYNTAX OMsInteger )", NULL, NULL },
262 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
263 &config_generic, "( OLcfgAt:13 NAME 'olcDatabase' "
264 "DESC 'The backend type for a database instance' "
265 "SUP olcBackend )", NULL, NULL },
266 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_MAGIC,
267 &config_search_base, "( OLcfgAt:14 NAME 'olcDefaultSearchBase' "
268 "SYNTAX OMsDN )", NULL, NULL },
269 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
270 &config_disallows, "( OLcfgAt:15 NAME 'olcDisallows' "
271 "EQUALITY caseIgnoreMatch "
272 "SYNTAX OMsDirectoryString )", NULL, NULL },
273 /* use standard schema */
274 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT,
275 &config_generic, NULL, NULL, NULL },
276 { "gentlehup", "on|off", 2, 2, 0,
278 ARG_ON_OFF, &global_gentlehup,
282 "( OLcfgAt:17 NAME 'olcGentleHUP' "
283 "SYNTAX OMsBoolean )", NULL, NULL },
284 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
285 &global_idletimeout, "( OLcfgAt:18 NAME 'olcIdleTimeout' "
286 "SYNTAX OMsInteger )", NULL, NULL },
287 /* XXX -- special case? */
288 { "include", "file", 2, 2, 0, ARG_MAGIC,
289 &config_include, "( OLcfgAt:19 NAME 'olcInclude' "
290 "SUP labeledURI )", NULL, NULL },
291 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
292 &config_generic, "( OLcfgAt:20 NAME 'olcIndexSubstrIfMinLen' "
293 "SYNTAX OMsInteger )", NULL, NULL },
294 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
295 &config_generic, "( OLcfgAt:21 NAME 'olcIndexSubstrIfMaxLen' "
296 "SYNTAX OMsInteger )", NULL, NULL },
297 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
298 &index_substr_any_len, "( OLcfgAt:22 NAME 'olcIndexSubstrAnyLen' "
299 "SYNTAX OMsInteger )", NULL, NULL },
300 { "index_substr_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
301 &index_substr_any_step, "( OLcfgAt:23 NAME 'olcIndexSubstrAnyStep' "
302 "SYNTAX OMsInteger )", NULL, NULL },
303 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
304 &config_generic, "( OLcfgAt:24 NAME 'olcLastMod' "
305 "SYNTAX OMsBoolean )", NULL, NULL },
306 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
307 &config_generic, "( OLcfgAt:25 NAME 'olcLimits' "
308 "SYNTAX OMsDirectoryString )", NULL, NULL },
309 { "localSSF", "ssf", 2, 2, 0, ARG_LONG,
310 &local_ssf, "( OLcfgAt:26 NAME 'olcLocalSSF' "
311 "SYNTAX OMsInteger )", NULL, NULL },
312 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
313 &config_generic, "( OLcfgAt:27 NAME 'olcLogFile' "
314 "SYNTAX OMsDirectoryString )", NULL, NULL },
315 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
316 &config_loglevel, "( OLcfgAt:28 NAME 'olcLogLevel' "
317 "SYNTAX OMsDirectoryString )", NULL, NULL },
318 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
319 &config_generic, "( OLcfgAt:29 NAME 'olcMaxDerefDepth' "
320 "SYNTAX OMsInteger )", NULL, NULL },
321 { "moduleload", "file", 2, 0, 0,
323 ARG_MAGIC|CFG_MODLOAD, &config_generic,
327 "( OLcfgAt:30 NAME 'olcModuleLoad' "
328 "SYNTAX OMsDirectoryString )", NULL, NULL },
329 { "modulepath", "path", 2, 2, 0,
331 ARG_MAGIC|CFG_MODPATH, &config_generic,
335 "( OLcfgAt:31 NAME 'olcModulePath' "
336 "SYNTAX OMsDirectoryString )", NULL, NULL },
337 /* use standard schema */
338 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
339 &config_generic, NULL, NULL, NULL },
340 { "objectidentifier", NULL, 0, 0, 0, ARG_MAGIC|CFG_OID,
341 &config_generic, "( OLcfgAt:33 NAME 'olcObjectIdentifier' "
342 "SYNTAX OMsDirectoryString )", NULL, NULL },
343 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
344 &config_overlay, "( OLcfgAt:34 NAME 'olcOverlay' "
345 "SUP olcDatabase )", NULL, NULL },
346 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
347 &config_generic, "( OLcfgAt:35 NAME 'olcPasswordCryptSaltFormat' "
348 "SYNTAX OMsDirectoryString )", NULL, NULL },
349 { "password-hash", "hash", 2, 2, 0, ARG_MAGIC,
350 &config_passwd_hash, "( OLcfgAt:36 NAME 'olcPasswordHash' "
351 "SYNTAX OMsDirectoryString )", NULL, NULL },
352 { "pidfile", "file", 2, 2, 0, ARG_STRING,
353 &slapd_pid_file, "( OLcfgAt:37 NAME 'olcPidFile' "
354 "SYNTAX OMsDirectoryString )", NULL, NULL },
355 { "plugin", NULL, 0, 0, 0,
357 ARG_MAGIC|CFG_PLUGIN, &config_generic,
361 "( OLcfgAt:38 NAME 'olcPlugin' "
362 "SYNTAX OMsDirectoryString )", NULL, NULL },
363 { "pluginlog", "filename", 2, 2, 0,
365 ARG_STRING, &slapi_log_file,
369 "( OLcfgAt:39 NAME 'olcPluginLogFile' "
370 "SYNTAX OMsDirectoryString )", NULL, NULL },
371 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
372 &config_generic, "( OLcfgAt:40 NAME 'olcReadOnly' "
373 "SYNTAX OMsBoolean )", NULL, NULL },
374 { "referral", "url", 2, 2, 0, ARG_MAGIC,
375 &config_referral, "( OLcfgAt:41 NAME 'olcReferral' "
376 "SUP labeledURI )", NULL, NULL },
377 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
378 &config_replica, "( OLcfgAt:42 NAME 'olcReplica' "
379 "SUP labeledURI )", NULL, NULL },
380 { "replica-argsfile", NULL, 0, 0, 0, ARG_STRING,
381 &replica_argsFile, "( OLcfgAt:43 NAME 'olcReplicaArgsFile' "
382 "SYNTAX OMsDirectoryString )", NULL, NULL },
383 { "replica-pidfile", NULL, 0, 0, 0, ARG_STRING,
384 &replica_pidFile, "( OLcfgAt:44 NAME 'olcReplicaPidFile' "
385 "SYNTAX OMsDirectoryString )", NULL, NULL },
386 { "replicationInterval", NULL, 0, 0, 0, ARG_INT,
387 &replicationInterval, "( OLcfgAt:45 NAME 'olcReplicationInterval' "
388 "SYNTAX OMsInteger )", NULL, NULL },
389 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC|ARG_STRING|CFG_REPLOG,
390 &config_generic, "( OLcfgAt:46 NAME 'olcReplogFile' "
391 "SYNTAX OMsDirectoryString )", NULL, NULL },
392 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
393 &config_requires, "( OLcfgAt:47 NAME 'olcRequires' "
394 "SYNTAX OMsDirectoryString )", NULL, NULL },
395 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
396 &config_restrict, "( OLcfgAt:48 NAME 'olcRestrict' "
397 "SYNTAX OMsDirectoryString )", NULL, NULL },
398 { "reverse-lookup", "on|off", 2, 2, 0,
399 #ifdef SLAPD_RLOOKUPS
400 ARG_ON_OFF, &use_reverse_lookup,
404 "( OLcfgAt:49 NAME 'olcReverseLookup' "
405 "SYNTAX OMsBoolean )", NULL, NULL },
406 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_MAGIC,
407 &config_rootdn, "( OLcfgAt:50 NAME 'olcRootDN' "
408 "SYNTAX OMsDN )", NULL, NULL },
409 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
410 &config_generic, "( OLcfgAt:51 NAME 'olcRootDSE' "
411 "SYNTAX OMsDirectoryString )", NULL, NULL },
412 { "rootpw", "password", 2, 2, 0, ARG_STRING|ARG_DB|ARG_MAGIC,
413 &config_rootpw, "( OLcfgAt:52 NAME 'olcRootPW' "
414 "SYNTAX OMsOctetString )", NULL, NULL },
415 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
416 &config_generic, NULL, NULL, NULL },
417 { "sasl-host", "host", 2, 2, 0,
418 #ifdef HAVE_CYRUS_SASL
419 ARG_STRING|ARG_UNIQUE, &global_host,
423 "( OLcfgAt:53 NAME 'olcSaslHost' "
424 "SYNTAX OMsDirectoryString )", NULL, NULL },
425 { "sasl-realm", "realm", 2, 2, 0,
426 #ifdef HAVE_CYRUS_SASL
427 ARG_STRING|ARG_UNIQUE, &global_realm,
431 "( OLcfgAt:54 NAME 'olcSaslRealm' "
432 "SYNTAX OMsDirectoryString )", NULL, NULL },
433 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
434 &config_generic, NULL, NULL, NULL },
435 { "sasl-secprops", "properties", 2, 2, 0,
436 #ifdef HAVE_CYRUS_SASL
437 ARG_MAGIC|CFG_SASLSECP, &config_generic,
441 "( OLcfgAt:56 NAME 'olcSaslSecProps' "
442 "SYNTAX OMsDirectoryString )", NULL, NULL },
443 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
444 &config_generic, NULL, NULL, NULL },
445 { "schemacheck", "on|off", 2, 2, 0, ARG_ON_OFF|ARG_MAGIC|CFG_CHECK,
446 &config_generic, "( OLcfgAt:57 NAME 'olcSchemaCheck' "
447 "SYNTAX OMsBoolean )", NULL, NULL },
448 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_MAGIC,
449 &config_schema_dn, "( OLcfgAt:58 NAME 'olcSchemaDN' "
450 "SYNTAX OMsDN )", NULL, NULL },
451 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
452 &config_security, "( OLcfgAt:59 NAME 'olcSecurity' "
453 "SYNTAX OMsDirectoryString )", NULL, NULL },
454 { "sizelimit", "limit", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC|CFG_SIZE,
455 &config_sizelimit, "( OLcfgAt:60 NAME 'olcSizeLimit' "
456 "SYNTAX OMsInteger )", NULL, NULL },
457 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_LONG,
458 &sockbuf_max_incoming, "( OLcfgAt:61 NAME 'olcSockbufMaxIncoming' "
459 "SYNTAX OMsInteger )", NULL, NULL },
460 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_LONG,
461 &sockbuf_max_incoming_auth, "( OLcfgAt:62 NAME 'olcSockbufMaxIncomingAuth' "
462 "SYNTAX OMsInteger )", NULL, NULL },
463 { "srvtab", "file", 2, 2, 0,
464 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
465 ARG_STRING, &ldap_srvtab,
469 "( OLcfgAt:63 NAME 'olcSrvtab' "
470 "SYNTAX OMsDirectoryString )", NULL, NULL },
471 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_MAGIC,
472 &config_suffix, "( OLcfgAt:64 NAME 'olcSuffix' "
473 "SYNTAX OMsDN )", NULL, NULL },
474 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
475 &config_syncrepl, "( OLcfgAt:65 NAME 'olcSyncrepl' "
476 "SYNTAX OMsDirectoryString )", NULL, NULL },
477 { "threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_THREADS,
478 &config_generic, "( OLcfgAt:66 NAME 'olcThreads' "
479 "SYNTAX OMsInteger )", NULL, NULL },
480 { "timelimit", "limit", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC|CFG_TIME,
481 &config_timelimit, "( OLcfgAt:67 NAME 'olcTimeLimit' "
482 "SYNTAX OMsInteger )", NULL, NULL },
483 { "TLSCACertificateFile", NULL, 0, 0, 0,
485 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
489 "( OLcfgAt:68 NAME 'olcTLSCACertificateFile' "
490 "SYNTAX OMsDirectoryString )", NULL, NULL },
491 { "TLSCACertificatePath", NULL, 0, 0, 0,
493 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
497 "( OLcfgAt:69 NAME 'olcTLSCACertificatePath' "
498 "SYNTAX OMsDirectoryString )", NULL, NULL },
499 { "TLSCertificateFile", NULL, 0, 0, 0,
501 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
505 "( OLcfgAt:70 NAME 'olcTLSCertificateFile' "
506 "SYNTAX OMsDirectoryString )", NULL, NULL },
507 { "TLSCertificateKeyFile", NULL, 0, 0, 0,
509 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
513 "( OLcfgAt:71 NAME 'olcTLSCertificateKeyFile' "
514 "SYNTAX OMsDirectoryString )", NULL, NULL },
515 { "TLSCipherSuite", NULL, 0, 0, 0,
517 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
521 "( OLcfgAt:72 NAME 'olcTLSCipherSuite' "
522 "SYNTAX OMsDirectoryString )", NULL, NULL },
523 { "TLSCRLCheck", NULL, 0, 0, 0,
525 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
529 "( OLcfgAt:73 NAME 'olcTLSCRLCheck' "
530 "SYNTAX OMsDirectoryString )", NULL, NULL },
531 { "TLSRandFile", NULL, 0, 0, 0,
533 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
537 "( OLcfgAt:74 NAME 'olcTLSRandFile' "
538 "SYNTAX OMsDirectoryString )", NULL, NULL },
539 { "TLSVerifyClient", NULL, 0, 0, 0,
541 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
545 "( OLcfgAt:75 NAME 'olcTLSVerifyClient' "
546 "SYNTAX OMsDirectoryString )", NULL, NULL },
547 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
548 NULL, NULL, NULL, NULL },
549 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_MAGIC,
550 &config_updatedn, "( OLcfgAt:76 NAME 'olcUpdateDN' "
551 "SYNTAX OMsDN )", NULL, NULL },
552 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
553 &config_updateref, "( OLcfgAt:77 NAME 'olcUpdateRef' "
554 "SUP labeledURI )", NULL, NULL },
555 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
556 NULL, NULL, NULL, NULL }
561 new_config_args( BackendDB *be, const char *fname, int lineno, int argc, char **argv )
564 c = ch_calloc( 1, sizeof( ConfigArgs ) );
565 if ( c == NULL ) return(NULL);
571 snprintf( c->log, sizeof( c->log ), "%s: line %lu", fname, lineno );
575 int parse_config_table(ConfigTable *Conf, ConfigArgs *c) {
576 int i, rc, arg_user, arg_type, iarg;
579 for(i = 0; Conf[i].name; i++)
580 if( (Conf[i].length && (!strncasecmp(c->argv[0], Conf[i].name, Conf[i].length))) ||
581 (!strcasecmp(c->argv[0], Conf[i].name)) ) break;
582 if(!Conf[i].name) return(ARG_UNKNOWN);
583 arg_type = Conf[i].arg_type;
584 if(arg_type == ARG_IGNORED) {
585 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> ignored\n",
586 c->log, Conf[i].name, 0);
589 if(Conf[i].min_args && (c->argc < Conf[i].min_args)) {
590 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> missing <%s> argument\n",
591 c->log, Conf[i].name, Conf[i].what);
592 return(ARG_BAD_CONF);
594 if(Conf[i].max_args && (c->argc > Conf[i].max_args)) {
595 Debug(LDAP_DEBUG_CONFIG, "%s: extra cruft after <%s> in <%s> line (ignored)\n",
596 c->log, Conf[i].what, Conf[i].name);
598 if((arg_type & ARG_DB) && !c->be) {
599 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> allowed only within database declaration\n",
600 c->log, Conf[i].name, 0);
601 return(ARG_BAD_CONF);
603 if((arg_type & ARG_PRE_BI) && c->bi) {
604 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> must appear before any backend %sdeclaration\n",
605 c->log, Conf[i].name, ((arg_type & ARG_PRE_DB)
606 ? "or database " : "") );
607 return(ARG_BAD_CONF);
609 if((arg_type & ARG_PRE_DB) && c->be && c->be != frontendDB) {
610 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> must appear before any database declaration\n",
611 c->log, Conf[i].name, 0);
612 return(ARG_BAD_CONF);
614 if((arg_type & ARG_PAREN) && *c->argv[1] != '(' /*')'*/) {
615 Debug(LDAP_DEBUG_CONFIG, "%s: old <%s> format not supported\n",
616 c->log, Conf[i].name, 0);
617 return(ARG_BAD_CONF);
619 if((arg_type & ARGS_POINTER) && !Conf[i].arg_item) {
620 Debug(LDAP_DEBUG_CONFIG, "%s: null arg_item for <%s>\n",
621 c->log, Conf[i].name, 0);
622 return(ARG_BAD_CONF);
624 c->type = arg_user = (arg_type & ARGS_USERLAND);
625 memset(&c->values, 0, sizeof(c->values));
626 if(arg_type & ARGS_NUMERIC) {
628 iarg = 0; larg = 0; barg = 0;
629 switch(arg_type & ARGS_NUMERIC) {
630 case ARG_INT: iarg = atoi(c->argv[1]); break;
631 case ARG_LONG: larg = atol(c->argv[1]); break;
632 case ARG_BER_LEN_T: barg = (ber_len_t)atol(c->argv[1]); break;
634 if(!strcasecmp(c->argv[1], "on") ||
635 !strcasecmp(c->argv[1], "true")) {
637 } else if(!strcasecmp(c->argv[1], "off") ||
638 !strcasecmp(c->argv[1], "false")) {
641 Debug(LDAP_DEBUG_CONFIG, "%s: ignoring ", c->log, 0, 0);
642 Debug(LDAP_DEBUG_CONFIG, "invalid %s value (%s) in <%s> line\n",
643 Conf[i].what, c->argv[1], Conf[i].name);
648 j = (arg_type & ARG_NONZERO) ? 1 : 0;
649 if(iarg < j || larg < j || barg < j ) {
650 larg = larg ? larg : (barg ? barg : iarg);
651 Debug(LDAP_DEBUG_CONFIG, "%s: " , c->log, 0, 0);
652 Debug(LDAP_DEBUG_CONFIG, "invalid %s value (%ld) in <%s> line\n", Conf[i].what, larg, Conf[i].name);
653 return(ARG_BAD_CONF);
655 switch(arg_type & ARGS_NUMERIC) {
657 case ARG_INT: c->value_int = iarg; break;
658 case ARG_LONG: c->value_long = larg; break;
659 case ARG_BER_LEN_T: c->value_ber_t = barg; break;
661 } else if(arg_type & ARG_STRING) {
662 c->value_string = ch_strdup(c->argv[1]);
663 } else if(arg_type & ARG_DN) {
665 ber_str2bv( c->argv[1], 0, 0, &bv );
666 rc = dnPrettyNormal( NULL, &bv, &c->value_dn, &c->value_ndn, NULL );
667 if ( rc != LDAP_SUCCESS ) {
668 Debug(LDAP_DEBUG_CONFIG, "%s: " , c->log, 0, 0);
669 Debug(LDAP_DEBUG_CONFIG, "%s DN is invalid %d (%s)\n",
670 Conf[i].name, rc, ldap_err2string( rc ));
671 return(ARG_BAD_CONF);
674 if(arg_type & ARG_MAGIC) {
675 if(!c->be) c->be = frontendDB;
676 rc = (*((ConfigDriver*)Conf[i].arg_item))(c);
677 if(c->be == frontendDB) c->be = NULL;
679 Debug(LDAP_DEBUG_CONFIG, "%s: handler for <%s> exited with %d!",
680 c->log, Conf[i].name, rc);
681 return(ARG_BAD_CONF);
685 if(arg_type & ARGS_POINTER) switch(arg_type & ARGS_POINTER) {
687 case ARG_INT: *((int*)Conf[i].arg_item) = iarg; break;
688 case ARG_LONG: *((long*)Conf[i].arg_item) = larg; break;
689 case ARG_BER_LEN_T: *((ber_len_t*)Conf[i].arg_item) = barg; break;
691 char *cc = *((char**)Conf[i].arg_item);
693 if (arg_type & ARG_UNIQUE) {
694 Debug(LDAP_DEBUG_CONFIG, "%s: already set %s!\n",
695 c->log, Conf[i].name, 0 );
696 return(ARG_BAD_CONF);
698 ch_free(cc); /* potential memory leak */
700 *(char **)Conf[i].arg_item = c->value_string;
708 config_get_vals(ConfigTable *cf, ConfigArgs *c)
713 if ( cf->arg_type & ARG_IGNORED ) {
717 memset(&c->values, 0, sizeof(c->values));
718 c->rvalue_vals = NULL;
719 c->rvalue_nvals = NULL;
721 c->type = cf->arg_type & ARGS_USERLAND;
723 if ( cf->arg_type & ARG_MAGIC ) {
724 rc = (*((ConfigDriver*)cf->arg_item))(c);
727 switch(cf->arg_type & ARGS_POINTER) {
729 case ARG_INT: c->value_int = *(int *)cf->arg_item; break;
730 case ARG_LONG: c->value_long = *(long *)cf->arg_item; break;
731 case ARG_BER_LEN_T: c->value_ber_t = *(ber_len_t *)cf->arg_item; break;
733 if ( *(char **)cf->arg_item )
734 c->value_string = ch_strdup(*(char **)cf->arg_item);
738 if ( cf->arg_type & ARGS_POINTER) {
740 switch(cf->arg_type & ARGS_POINTER) {
741 case ARG_INT: bv.bv_len = sprintf(bv.bv_val, "%d", c->value_int); break;
742 case ARG_LONG: bv.bv_len = sprintf(bv.bv_val, "%l", c->value_long); break;
743 case ARG_BER_LEN_T: bv.bv_len =sprintf(bv.bv_val, "%l",c->value_ber_t); break;
744 case ARG_ON_OFF: bv.bv_len = sprintf(bv.bv_val, "%s",
745 c->value_int ? "TRUE" : "FALSE"); break;
747 if ( c->value_string && c->value_string[0]) {
748 ber_str2bv( c->value_string, 0, 0, &bv);
754 if (( cf->arg_type & ARGS_POINTER ) == ARG_STRING )
755 ber_bvarray_add(&c->rvalue_vals, &bv);
757 value_add_one(&c->rvalue_vals, &bv);
763 init_config_attrs(ConfigTable *ct) {
764 LDAPAttributeType *at;
768 for (i=0; ct[i].name; i++ ) {
769 if ( !ct[i].attribute ) continue;
770 at = ldap_str2attributetype( ct[i].attribute,
771 &code, &err, LDAP_SCHEMA_ALLOW_ALL );
773 fprintf( stderr, "init_config_schema: AttributeType \"%s\": %s, %s\n",
774 ct[i].attribute, ldap_scherr2str(code), err );
777 code = at_add( at, &err );
779 fprintf( stderr, "init_config_schema: AttributeType \"%s\": %s, %s\n",
780 ct[i].attribute, scherr2str(code), err );
783 code = slap_str2ad( at->at_names[0], &ct[i].ad, &err );
785 fprintf( stderr, "init_config_schema: AttributeType \"%s\": %s\n",
786 ct[i].attribute, err );
796 read_config(const char *fname, int depth) {
800 /* Schema initialization should normally be part of bi_open */
801 for (i=0; OidMacros[i].name; i++ ) {
802 argv[1] = OidMacros[i].name;
803 argv[2] = OidMacros[i].oid;
804 parse_oidm( "slapd", i, 3, argv );
806 i = init_config_attrs(SystemConfiguration);
808 i = config_back_init( &cf_prv, SystemConfiguration );
810 return read_config_file(fname, depth, NULL);
814 read_config_file(const char *fname, int depth, ConfigArgs *cf)
820 c = ch_calloc( 1, sizeof( ConfigArgs ) );
826 memcpy( c, cf, sizeof( ConfigArgs ) );
828 c->depth = depth; /* XXX */
834 c->argv = ch_calloc( ARGS_STEP + 1, sizeof( *c->argv ) );
835 c->argv_size = ARGS_STEP + 1;
837 fp = fopen( fname, "r" );
840 Debug(LDAP_DEBUG_ANY,
841 "could not open config file \"%s\": %s (%d)\n",
842 fname, strerror(errno), errno);
846 cfn->c_modlast = &cfn->c_modpaths;
848 ber_str2bv( fname, 0, 1, &cfn->c_file );
849 fname = cfn->c_file.bv_val;
851 Debug(LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0);
855 while ( fp_getline( fp, c ) ) {
856 /* skip comments and blank lines */
857 if ( c->line[0] == '#' || c->line[0] == '\0' ) {
861 snprintf( c->log, sizeof( c->log ), "%s: line %lu",
862 c->fname, c->lineno );
864 if ( fp_parse_line( c ) ) {
869 Debug(LDAP_DEBUG_CONFIG, "%s: bad config line (ignored)\n", c->log, 0, 0);
873 rc = parse_config_table( SystemConfiguration, c );
877 if ( rc & ARGS_USERLAND ) {
878 switch(rc) { /* XXX a usertype would be opaque here */
880 Debug(LDAP_DEBUG_CONFIG, "%s: unknown user type <%d>\n",
881 c->log, *c->argv, 0);
885 } else if ( rc == ARG_BAD_CONF || rc != ARG_UNKNOWN ) {
888 } else if ( c->bi && c->bi->bi_config ) { /* XXX to check: could both be/bi_config? oops */
889 rc = (*c->bi->bi_config)(c->bi, c->fname, c->lineno, c->argc, c->argv);
892 case SLAP_CONF_UNKNOWN:
893 Debug(LDAP_DEBUG_CONFIG, "%s: "
894 "unknown directive <%s> inside backend info definition (ignored)\n",
895 c->log, *c->argv, 0);
902 } else if ( c->be && c->be->be_config ) {
903 rc = (*c->be->be_config)(c->be, c->fname, c->lineno, c->argc, c->argv);
906 case SLAP_CONF_UNKNOWN:
907 Debug( LDAP_DEBUG_CONFIG, "%s: "
908 "unknown directive <%s> inside backend database definition (ignored)\n",
909 c->log, *c->argv, 0);
916 } else if ( frontendDB->be_config ) {
917 rc = (*frontendDB->be_config)(frontendDB, c->fname, (int)c->lineno, c->argc, c->argv);
920 case SLAP_CONF_UNKNOWN:
921 Debug( LDAP_DEBUG_CONFIG, "%s: "
922 "unknown directive <%s> inside global database definition (ignored)\n",
923 c->log, *c->argv, 0);
931 Debug(LDAP_DEBUG_CONFIG, "%s: "
932 "unknown directive <%s> outside backend info and database definitions (ignored)\n",
933 c->log, *c->argv, 0);
941 if ( BER_BVISNULL( &frontendDB->be_schemadn ) ) {
942 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
943 &frontendDB->be_schemadn );
944 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
945 if ( rc != LDAP_SUCCESS ) {
946 Debug(LDAP_DEBUG_ANY, "%s: "
947 "unable to normalize default schema DN \"%s\"\n",
948 c->log, frontendDB->be_schemadn.bv_val, 0 );
949 /* must not happen */
966 config_generic(ConfigArgs *c) {
974 c->value_int = ldap_pvt_thread_get_concurrency();
977 c->value_int = connection_pool_max;
981 c->value_string = ch_strdup( passwd_salt );
985 case CFG_LIMITS: /* FIXME */
989 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_OP_WRITES) != 0;
992 c->value_string = ch_strdup( slap_sasl_getpolicy());
997 #ifdef HAVE_CYRUS_SASL
998 case CFG_SASLSECP: /* FIXME */
1003 c->value_int = c->be->be_max_deref_depth;
1005 case CFG_OID: /* FIXME */
1009 c->value_int = global_schemacheck;
1013 char *src, *dst, ibuf[11];
1014 struct berval bv, abv;
1015 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
1016 abv.bv_len = sprintf( ibuf, "{%x}", i );
1017 acl_unparse( a, &bv );
1018 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
1019 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
1020 /* Turn TAB / EOL into plain space */
1021 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
1022 if (isspace(*src)) *dst++ = ' ';
1026 if (dst[-1] == ' ') {
1030 abv.bv_len = dst - abv.bv_val;
1031 ber_bvarray_add( &c->rvalue_vals, &abv );
1037 if ( c->be->be_replogfile )
1038 c->value_string = ch_strdup( c->be->be_replogfile );
1041 ConfigFile *cf = (ConfigFile *)c->line;
1042 if ( cf->c_dseFiles ) {
1043 value_add( &c->rvalue_vals, cf->c_dseFiles );
1051 c->value_string = ch_strdup( logfileName );
1056 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1058 case CFG_SSTR_IF_MAX:
1059 c->value_int = index_substr_if_maxlen;
1061 case CFG_SSTR_IF_MIN:
1062 c->value_int = index_substr_if_minlen;
1064 #ifdef SLAPD_MODULES
1066 ConfigFile *cf = (ConfigFile *)c->line;
1068 for (i=0, mp=&cf->c_modpaths; mp; mp=mp->mp_next, i++) {
1070 if (!mp->mp_loads) continue;
1071 for (j=0; !BER_BVISNULL(&mp->mp_loads[j]); j++) {
1074 bv.bv_len = sprintf( bv.bv_val, "{%d}{%d}%s", i, j,
1075 mp->mp_loads[j].bv_val );
1076 value_add_one( &c->rvalue_vals, &bv );
1079 rc = c->rvalue_vals ? 0 : 1;
1083 ConfigFile *cf = (ConfigFile *)c->line;
1085 for (i=0, mp=&cf->c_modpaths; mp; mp=mp->mp_next, i++) {
1087 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
1090 bv.bv_len = sprintf( bv.bv_val, "{%d}%s", i,
1091 mp->mp_path.bv_val );
1092 value_add_one( &c->rvalue_vals, &bv );
1094 rc = c->rvalue_vals ? 0 : 1;
1099 case CFG_PLUGIN: /* FIXME */
1103 #ifdef SLAP_AUTH_REWRITE
1104 case CFG_REWRITE: /* FIXME */
1114 p = strchr(c->line,'(' /*')'*/);
1117 if(!(c->bi = backend_info(c->argv[1]))) {
1118 Debug(LDAP_DEBUG_ANY, "%s: "
1119 "backend %s failed init!\n", c->log, c->argv[1], 0);
1126 /* NOTE: config is always the first backend!
1128 if ( !strcasecmp( c->argv[1], "config" )) {
1130 } else if(!(c->be = backend_db_init(c->argv[1]))) {
1131 Debug(LDAP_DEBUG_ANY, "%s: "
1132 "database %s failed init!\n", c->log, c->argv[1], 0);
1138 ldap_pvt_thread_set_concurrency(c->value_int);
1142 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1143 connection_pool_max = c->value_int; /* save for reference */
1147 if ( passwd_salt ) ch_free( passwd_salt );
1148 passwd_salt = c->value_string;
1149 lutil_salt_format(passwd_salt);
1153 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1159 c->be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1161 c->be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1165 ch_free(c->value_string);
1166 if (slap_sasl_setpolicy( c->argv[1] )) {
1167 Debug(LDAP_DEBUG_ANY, "%s: unable to parse value \"%s\" in"
1168 " \"authz-policy <policy>\"\n",
1169 c->log, c->argv[1], 0 );
1175 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1179 #ifdef HAVE_CYRUS_SASL
1182 char *txt = slap_sasl_secprops( c->argv[1] );
1184 Debug(LDAP_DEBUG_ANY, "%s: sasl-secprops: %s\n",
1193 c->be->be_max_deref_depth = c->value_int;
1197 if(parse_oidm(c->fname, c->lineno, c->argc, c->argv)) return(1);
1201 if(parse_oc(c->fname, c->lineno, p, c->argv)) return(1);
1205 if(parse_cr(c->fname, c->lineno, p, c->argv)) return(1);
1209 if(parse_at(c->fname, c->lineno, p, c->argv)) return(1);
1213 ad_define_option(NULL, NULL, 0);
1214 for(i = 1; i < c->argc; i++)
1215 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1220 global_schemacheck = c->value_int;
1221 if(!global_schemacheck) Debug(LDAP_DEBUG_ANY, "%s: "
1222 "schema checking disabled! your mileage may vary!\n",
1227 parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv);
1231 if(SLAP_MONITOR(c->be)) {
1232 Debug(LDAP_DEBUG_ANY, "%s: "
1233 "\"replogfile\" should not be used "
1234 "inside monitor database\n",
1236 return(0); /* FIXME: should this be an error? */
1239 c->be->be_replogfile = c->value_string;
1243 if(read_root_dse_file(c->argv[1])) {
1244 Debug(LDAP_DEBUG_ANY, "%s: "
1245 "could not read \"rootDSE <filename>\" line\n",
1251 ber_str2bv( c->argv[1], 0, 1, &bv );
1252 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1258 if ( logfileName ) ch_free( logfileName );
1259 logfileName = c->value_string;
1260 logfile = fopen(logfileName, "w");
1261 if(logfile) lutil_debug_file(logfile);
1265 if(SLAP_NOLASTMODCMD(c->be)) {
1266 Debug(LDAP_DEBUG_ANY, "%s: "
1267 "lastmod not available for %s databases\n",
1268 c->log, c->be->bd_info->bi_type, 0);
1272 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1274 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1277 case CFG_SSTR_IF_MAX:
1278 if (c->value_int < index_substr_if_minlen) {
1279 Debug(LDAP_DEBUG_ANY, "%s: "
1280 "invalid max value (%d)\n",
1281 c->log, c->value_int, 0 );
1284 index_substr_if_maxlen = c->value_int;
1287 case CFG_SSTR_IF_MIN:
1288 if (c->value_int > index_substr_if_maxlen) {
1289 Debug(LDAP_DEBUG_ANY, "%s: "
1290 "invalid min value (%d)\n",
1291 c->log, c->value_int, 0 );
1294 index_substr_if_minlen = c->value_int;
1297 #ifdef SLAPD_MODULES
1299 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1301 /* Record this load on the current path */
1304 ber_str2bv(c->line, 0, 1, &bv);
1305 ber_bvarray_add( &cfn->c_modlast->mp_loads, &bv );
1310 if(module_path(c->argv[1])) return(1);
1311 /* Record which path was used with each module */
1315 if (!cfn->c_modpaths.mp_loads) {
1316 mp = &cfn->c_modpaths;
1318 mp = ch_malloc( sizeof( ModPaths ));
1319 cfn->c_modlast->mp_next = mp;
1321 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1323 mp->mp_loads = NULL;
1324 cfn->c_modlast = mp;
1332 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
1334 slapi_plugins_used++;
1338 #ifdef SLAP_AUTH_REWRITE
1340 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
1347 Debug(LDAP_DEBUG_ANY, "%s: unknown CFG_TYPE %d"
1348 "(ignored)\n", c->log, c->type, 0);
1356 config_fname(ConfigArgs *c) {
1357 if(c->emit && c->line) {
1358 ConfigFile *cf = (ConfigFile *)c->line;
1359 value_add_one( &c->rvalue_vals, &cf->c_file );
1366 config_search_base(ConfigArgs *c) {
1371 if (!BER_BVISEMPTY(&default_search_base)) {
1372 value_add_one(&c->rvalue_vals, &default_search_base);
1373 value_add_one(&c->rvalue_nvals, &default_search_nbase);
1379 if(c->bi || c->be != frontendDB) {
1380 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
1381 "prior to any backend or database definition\n",
1386 if(default_search_nbase.bv_len) {
1387 Debug(LDAP_DEBUG_ANY, "%s: "
1388 "default search base \"%s\" already defined "
1389 "(discarding old)\n",
1390 c->log, default_search_base.bv_val, 0);
1391 free(default_search_base.bv_val);
1392 free(default_search_nbase.bv_val);
1395 default_search_base = c->value_dn;
1396 default_search_nbase = c->value_ndn;
1401 config_passwd_hash(ConfigArgs *c) {
1405 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
1406 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
1407 value_add_one(&c->rvalue_vals, &bv);
1411 if(default_passwd_hash) {
1412 Debug(LDAP_DEBUG_ANY, "%s: "
1413 "already set default password_hash\n",
1417 for(i = 1; i < c->argc; i++) {
1418 if(!lutil_passwd_scheme(c->argv[i])) {
1419 Debug(LDAP_DEBUG_ANY, "%s: "
1420 "password scheme \"%s\" not available\n",
1421 c->log, c->argv[i], 0);
1423 ldap_charray_add(&default_passwd_hash, c->argv[i]);
1425 if(!default_passwd_hash) {
1426 Debug(LDAP_DEBUG_ANY, "%s: no valid hashes found\n",
1435 config_schema_dn(ConfigArgs *c) {
1439 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
1440 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
1443 c->be->be_schemadn = c->value_dn;
1444 c->be->be_schemandn = c->value_ndn;
1449 config_sizelimit(ConfigArgs *c) {
1452 struct slap_limits_set *lim = &c->be->be_def_limit;
1453 if (c->emit) { /* FIXME */
1456 for(i = 1; i < c->argc; i++) {
1457 if(!strncasecmp(c->argv[i], "size", 4)) {
1458 rc = limits_parse_one(c->argv[i], lim);
1460 Debug(LDAP_DEBUG_ANY, "%s: "
1461 "unable to parse value \"%s\" in \"sizelimit <limit>\" line\n",
1462 c->log, c->argv[i], 0);
1466 if(!strcasecmp(c->argv[i], "unlimited")) {
1467 lim->lms_s_soft = -1;
1469 lim->lms_s_soft = strtol(c->argv[i], &next, 0);
1470 if(next == c->argv[i]) {
1471 Debug(LDAP_DEBUG_ANY, "%s: "
1472 "unable to parse limit \"%s\" in \"sizelimit <limit>\" line\n",
1473 c->log, c->argv[i], 0);
1475 } else if(next[0] != '\0') {
1476 Debug(LDAP_DEBUG_ANY, "%s: "
1477 "trailing chars \"%s\" in \"sizelimit <limit>\" line (ignored)\n",
1481 lim->lms_s_hard = 0;
1488 config_timelimit(ConfigArgs *c) {
1491 struct slap_limits_set *lim = &c->be->be_def_limit;
1493 return 1; /* FIXME */
1495 for(i = 1; i < c->argc; i++) {
1496 if(!strncasecmp(c->argv[i], "time", 4)) {
1497 rc = limits_parse_one(c->argv[i], lim);
1499 Debug(LDAP_DEBUG_ANY, "%s: "
1500 "unable to parse value \"%s\" in \"timelimit <limit>\" line\n",
1501 c->log, c->argv[i], 0);
1505 if(!strcasecmp(c->argv[i], "unlimited")) {
1506 lim->lms_t_soft = -1;
1508 lim->lms_t_soft = strtol(c->argv[i], &next, 0);
1509 if(next == c->argv[i]) {
1510 Debug(LDAP_DEBUG_ANY, "%s: "
1511 "unable to parse limit \"%s\" in \"timelimit <limit>\" line\n",
1512 c->log, c->argv[i], 0);
1514 } else if(next[0] != '\0') {
1515 Debug(LDAP_DEBUG_ANY, "%s: "
1516 "trailing chars \"%s\" in \"timelimit <limit>\" line (ignored)\n",
1520 lim->lms_t_hard = 0;
1527 config_overlay(ConfigArgs *c) {
1531 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1])) {
1533 Debug(LDAP_DEBUG_ANY, "%s: (optional) %s overlay \"%s\" configuration failed (ignored)\n",
1534 c->log, c->be == frontendDB ? "global " : "", c->argv[1][1]);
1535 } else if(overlay_config(c->be, c->argv[1])) {
1542 config_suffix(ConfigArgs *c) {
1544 struct berval pdn, ndn;
1547 if ( !BER_BVISNULL( &c->be->be_suffix[0] )) {
1548 value_add( &c->rvalue_vals, c->be->be_suffix );
1549 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
1555 #ifdef SLAPD_MONITOR_DN
1556 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
1557 Debug(LDAP_DEBUG_ANY, "%s: "
1558 "\"%s\" is reserved for monitoring slapd\n",
1559 c->log, SLAPD_MONITOR_DN, 0);
1566 tbe = select_backend(&ndn, 0, 0);
1568 Debug(LDAP_DEBUG_ANY, "%s: suffix already served by this backend! (ignored)\n",
1573 Debug(LDAP_DEBUG_ANY, "%s: suffix already served by a preceding backend \"%s\"\n",
1574 c->log, tbe->be_suffix[0].bv_val, 0);
1578 } else if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
1579 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
1580 "base provided \"%s\" (assuming okay)\n",
1581 c->log, default_search_base.bv_val, 0);
1583 ber_bvarray_add(&c->be->be_suffix, &pdn);
1584 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
1589 config_rootdn(ConfigArgs *c) {
1591 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
1592 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
1593 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
1599 c->be->be_rootdn = c->value_dn;
1600 c->be->be_rootndn = c->value_ndn;
1605 config_rootpw(ConfigArgs *c) {
1608 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
1609 c->value_string=ch_strdup("*");
1615 tbe = select_backend(&c->be->be_rootndn, 0, 0);
1617 Debug(LDAP_DEBUG_ANY, "%s: "
1618 "rootpw can only be set when rootdn is under suffix\n",
1622 ber_str2bv(c->value_string, 0, 0, &c->be->be_rootpw);
1626 /* restrictops, allows, disallows, requires, loglevel */
1628 struct verb_mask_list { char *word; int mask; };
1631 verb_to_mask(ConfigArgs *c, struct verb_mask_list *v, int word) {
1633 for(j = 0; v[j].word; j++)
1634 if(!strcasecmp(c->argv[word], v[j].word))
1640 verbs_to_mask(ConfigArgs *c, struct verb_mask_list *v, slap_mask_t *m) {
1642 for(i = 1; i < c->argc; i++) {
1643 j = verb_to_mask(c, v, i);
1644 if(!v[j].word) return(1);
1645 while (!v[j].mask) j--;
1652 mask_to_verbs(ConfigArgs *c, struct verb_mask_list *v, slap_mask_t m) {
1657 for (i=0; v[i].word; i++) {
1658 if (!v[i].mask) continue;
1659 if (( m & v[i].mask ) == v[i].mask ) {
1660 ber_str2bv( v[i].word, 0, 0, &bv );
1661 value_add_one( &c->rvalue_vals, &bv );
1668 config_restrict(ConfigArgs *c) {
1669 slap_mask_t restrictops = 0;
1671 struct verb_mask_list restrictable_ops[] = {
1672 { "bind", SLAP_RESTRICT_OP_BIND },
1673 { "add", SLAP_RESTRICT_OP_ADD },
1674 { "modify", SLAP_RESTRICT_OP_MODIFY },
1675 { "rename", SLAP_RESTRICT_OP_RENAME },
1677 { "delete", SLAP_RESTRICT_OP_DELETE },
1678 { "search", SLAP_RESTRICT_OP_SEARCH },
1679 { "compare", SLAP_RESTRICT_OP_COMPARE },
1680 { "read", SLAP_RESTRICT_OP_READS },
1681 { "write", SLAP_RESTRICT_OP_WRITES },
1682 { "extended", SLAP_RESTRICT_OP_EXTENDED },
1683 { "extended=" LDAP_EXOP_START_TLS, SLAP_RESTRICT_EXOP_START_TLS },
1684 { "extended=" LDAP_EXOP_MODIFY_PASSWD, SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
1685 { "extended=" LDAP_EXOP_X_WHO_AM_I, SLAP_RESTRICT_EXOP_WHOAMI },
1686 { "extended=" LDAP_EXOP_X_CANCEL, SLAP_RESTRICT_EXOP_CANCEL },
1691 return mask_to_verbs( c, restrictable_ops, c->be->be_restrictops );
1693 i = verbs_to_mask( c, restrictable_ops, &restrictops );
1695 Debug(LDAP_DEBUG_ANY, "%s: "
1696 "unknown operation %s in \"restrict <features>\" line\n",
1697 c->log, c->argv[i], 0);
1700 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
1701 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
1702 c->be->be_restrictops |= restrictops;
1707 config_allows(ConfigArgs *c) {
1708 slap_mask_t allows = 0;
1710 struct verb_mask_list allowable_ops[] = {
1711 { "bind_v2", SLAP_ALLOW_BIND_V2 },
1712 { "bind_anon_cred", SLAP_ALLOW_BIND_ANON_CRED },
1713 { "bind_anon_dn", SLAP_ALLOW_BIND_ANON_DN },
1714 { "update_anon", SLAP_ALLOW_UPDATE_ANON },
1718 return mask_to_verbs( c, allowable_ops, global_allows );
1720 i = verbs_to_mask(c, allowable_ops, &allows);
1722 Debug(LDAP_DEBUG_ANY, "%s: "
1723 "unknown feature %s in \"allow <features>\" line\n",
1724 c->log, c->argv[i], 0);
1727 global_allows |= allows;
1732 config_disallows(ConfigArgs *c) {
1733 slap_mask_t disallows = 0;
1735 struct verb_mask_list disallowable_ops[] = {
1736 { "bind_anon", SLAP_DISALLOW_BIND_ANON },
1737 { "bind_simple", SLAP_DISALLOW_BIND_SIMPLE },
1738 { "bind_krb4", SLAP_DISALLOW_BIND_KRBV4 },
1739 { "tls_2_anon", SLAP_DISALLOW_TLS_2_ANON },
1740 { "tls_authc", SLAP_DISALLOW_TLS_AUTHC },
1744 return mask_to_verbs( c, disallowable_ops, global_disallows );
1746 i = verbs_to_mask(c, disallowable_ops, &disallows);
1748 Debug(LDAP_DEBUG_ANY, "%s: "
1749 "unknown feature %s in \"disallow <features>\" line\n",
1750 c->log, c->argv[i], 0);
1753 global_disallows |= disallows;
1758 config_requires(ConfigArgs *c) {
1759 slap_mask_t requires = 0;
1761 struct verb_mask_list requires_ops[] = {
1762 { "bind", SLAP_REQUIRE_BIND },
1763 { "LDAPv3", SLAP_REQUIRE_LDAP_V3 },
1764 { "authc", SLAP_REQUIRE_AUTHC },
1765 { "sasl", SLAP_REQUIRE_SASL },
1766 { "strong", SLAP_REQUIRE_STRONG },
1770 return mask_to_verbs( c, requires_ops, c->be->be_requires );
1772 i = verbs_to_mask(c, requires_ops, &requires);
1774 Debug(LDAP_DEBUG_ANY, "%s: "
1775 "unknown feature %s in \"require <features>\" line\n",
1776 c->log, c->argv[i], 0);
1779 c->be->be_requires = requires;
1784 config_loglevel(ConfigArgs *c) {
1787 struct verb_mask_list loglevel_ops[] = {
1788 { "Trace", LDAP_DEBUG_TRACE },
1789 { "Packets", LDAP_DEBUG_PACKETS },
1790 { "Args", LDAP_DEBUG_ARGS },
1791 { "Conns", LDAP_DEBUG_CONNS },
1792 { "BER", LDAP_DEBUG_BER },
1793 { "Filter", LDAP_DEBUG_FILTER },
1794 { "Config", LDAP_DEBUG_CONFIG },
1795 { "ACL", LDAP_DEBUG_ACL },
1796 { "Stats", LDAP_DEBUG_STATS },
1797 { "Stats2", LDAP_DEBUG_STATS2 },
1798 { "Shell", LDAP_DEBUG_SHELL },
1799 { "Parse", LDAP_DEBUG_PARSE },
1800 { "Cache", LDAP_DEBUG_CACHE },
1801 { "Index", LDAP_DEBUG_INDEX },
1807 return mask_to_verbs( c, loglevel_ops, ldap_syslog );
1812 for( i=1; i < c->argc; i++ ) {
1815 if ( isdigit( c->argv[i][0] ) ) {
1816 level = strtol( c->argv[i], &next, 10 );
1817 if ( next == NULL || next[0] != '\0' ) {
1818 Debug( LDAP_DEBUG_ANY,
1819 "%s: unable to parse level \"%s\" "
1820 "in \"loglevel <level> [...]\" line.\n",
1821 c->log, c->argv[i], 0);
1825 int j = verb_to_mask(c, loglevel_ops, c->argv[i][0]);
1826 if(!loglevel_ops[j].word) {
1827 Debug( LDAP_DEBUG_ANY,
1828 "%s: unknown level \"%s\" "
1829 "in \"loglevel <level> [...]\" line.\n",
1830 c->log, c->argv[i], 0);
1833 level = loglevel_ops[j].mask;
1835 ldap_syslog |= level;
1841 config_syncrepl(ConfigArgs *c) {
1843 if ( c->be->be_syncinfo ) {
1845 syncrepl_unparse( c->be->be_syncinfo, &bv );
1846 ber_bvarray_add( &c->rvalue_vals, &bv );
1851 if(SLAP_SHADOW(c->be)) {
1852 Debug(LDAP_DEBUG_ANY, "%s: "
1853 "syncrepl: database already shadowed.\n",
1856 } else if(add_syncrepl(c->be, c->argv, c->argc)) {
1859 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SYNC_SHADOW);
1864 config_referral(ConfigArgs *c) {
1865 struct berval vals[2];
1867 if ( default_referral ) {
1868 value_add( &c->rvalue_vals, default_referral );
1874 if(validate_global_referral(c->argv[1])) {
1875 Debug(LDAP_DEBUG_ANY, "%s: "
1876 "invalid URL (%s) in \"referral\" line.\n",
1877 c->log, c->argv[1], 0);
1881 ber_str2bv(c->argv[1], 0, 0, &vals[0]);
1882 vals[1].bv_val = NULL; vals[1].bv_len = 0;
1883 if(value_add(&default_referral, vals)) return(LDAP_OTHER);
1891 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
1892 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
1893 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
1894 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
1895 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
1896 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
1897 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
1898 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
1899 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
1904 config_security(ConfigArgs *c) {
1905 slap_ssf_set_t *set = &c->be->be_ssf_set;
1914 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
1915 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
1918 bv.bv_len = sprintf( numbuf, "%u", *tgt );
1919 bv.bv_len += sec_keys[i].key.bv_len;
1920 bv.bv_val = ch_malloc( bv.bv_len + 1);
1921 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
1922 strcpy( next, numbuf );
1923 ber_bvarray_add( &c->rvalue_vals, &bv );
1928 for(i = 1; i < c->argc; i++) {
1929 slap_ssf_t *tgt = NULL;
1931 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
1932 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
1933 sec_keys[j].key.bv_len)) {
1934 src = c->argv[i] + sec_keys[j].key.bv_len;
1935 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
1940 Debug(LDAP_DEBUG_ANY, "%s: "
1941 "unknown factor %s in \"security <factors>\" line\n",
1942 c->log, c->argv[i], 0);
1946 *tgt = strtol(src, &next, 10);
1947 if(next == NULL || next[0] != '\0' ) {
1948 Debug(LDAP_DEBUG_ANY, "%s: "
1949 "unable to parse factor \"%s\" in \"security <factors>\" line\n",
1950 c->log, c->argv[i], 0);
1957 static struct verb_mask_list tlskey[] = {
1958 { "no", SB_TLS_OFF },
1959 { "yes", SB_TLS_ON },
1960 { "critical", SB_TLS_CRITICAL }
1963 static struct verb_mask_list methkey[] = {
1964 { "simple", LDAP_AUTH_SIMPLE },
1965 #ifdef HAVE_CYRUS_SASL
1966 { "sasl", LDAP_AUTH_SASL },
1971 typedef struct cf_aux_table {
1975 struct verb_mask_list *aux;
1978 static cf_aux_table bindkey[] = {
1979 { BER_BVC("starttls="), offsetof(slap_bindconf, sb_tls), 0, tlskey },
1980 { BER_BVC("bindmethod="), offsetof(slap_bindconf, sb_method), 0, methkey },
1981 { BER_BVC("binddn="), offsetof(slap_bindconf, sb_binddn), 1, NULL },
1982 { BER_BVC("credentials="), offsetof(slap_bindconf, sb_cred), 1, NULL },
1983 { BER_BVC("saslmech="), offsetof(slap_bindconf, sb_saslmech), 0, NULL },
1984 { BER_BVC("secprops="), offsetof(slap_bindconf, sb_secprops), 0, NULL },
1985 { BER_BVC("realm="), offsetof(slap_bindconf, sb_realm), 0, NULL },
1986 { BER_BVC("authcID="), offsetof(slap_bindconf, sb_authcId), 0, NULL },
1987 { BER_BVC("authzID="), offsetof(slap_bindconf, sb_authzId), 1, NULL },
1988 { BER_BVNULL, 0, 0, NULL }
1991 int bindconf_parse( char *word, slap_bindconf *bc ) {
1996 for (tab = bindkey; !BER_BVISNULL(&tab->key); tab++) {
1997 if ( !strncasecmp( word, tab->key.bv_val, tab->key.bv_len )) {
1998 cptr = (char **)((char *)bc + tab->off);
2002 for (j=0; tab->aux[j].word; j++) {
2003 if (!strcasecmp(word+tab->key.bv_len, tab->aux[j].word)) {
2004 int *ptr = (int *)cptr;
2005 *ptr = tab->aux[j].mask;
2010 Debug(LDAP_DEBUG_ANY, "invalid bind config value %s\n",
2015 *cptr = ch_strdup(word+tab->key.bv_len);
2022 int bindconf_unparse( slap_bindconf *bc, struct berval *bv ) {
2023 char buf[BUFSIZ], *ptr;
2029 for (tab = bindkey; !BER_BVISNULL(&tab->key); tab++) {
2030 cptr = (char **)((char *)bc + tab->off);
2032 int *ip = (int *)cptr, i;
2033 for ( i=0; tab->aux[i].word; i++ ) {
2034 if ( *ip == tab->aux[i].mask ) {
2036 ptr = lutil_strcopy( ptr, tab->key.bv_val );
2037 ptr = lutil_strcopy( ptr, tab->aux[i].word );
2041 } else if ( *cptr ) {
2043 ptr = lutil_strcopy( ptr, tab->key.bv_val );
2044 if ( tab->quote ) *ptr++ = '"';
2045 ptr = lutil_strcopy( ptr, *cptr );
2046 if ( tab->quote ) *ptr++ = '"';
2050 tmp.bv_len = ptr - buf;
2051 ber_dupbv( bv, &tmp );
2055 void bindconf_free( slap_bindconf *bc ) {
2056 if ( bc->sb_binddn ) {
2057 ch_free( bc->sb_binddn );
2059 if ( bc->sb_cred ) {
2060 ch_free( bc->sb_cred );
2062 if ( bc->sb_saslmech ) {
2063 ch_free( bc->sb_saslmech );
2065 if ( bc->sb_secprops ) {
2066 ch_free( bc->sb_secprops );
2068 if ( bc->sb_realm ) {
2069 ch_free( bc->sb_realm );
2071 if ( bc->sb_authcId ) {
2072 ch_free( bc->sb_authcId );
2074 if ( bc->sb_authzId ) {
2075 ch_free( bc->sb_authzId );
2080 anlist_unparse( AttributeName *an, char *ptr ) {
2083 for (; !BER_BVISNULL( &an->an_name ); an++) {
2084 if ( comma ) *ptr++ = ',';
2085 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
2092 replica_unparse( struct slap_replica_info *ri, int i, struct berval *bv )
2096 struct berval bc = {0};
2099 len = sprintf(numbuf, "{%d}", i );
2101 len += strlen( ri->ri_uri ) + STRLENOF("uri=");
2102 if ( ri->ri_nsuffix ) {
2103 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
2104 len += ri->ri_nsuffix[i].bv_len + STRLENOF(" suffix=\"\"");
2107 if ( ri->ri_attrs ) {
2108 len += STRLENOF("attr");
2109 if ( ri->ri_exclude ) len++;
2110 for (i=0; !BER_BVISNULL( &ri->ri_attrs[i].an_name ); i++) {
2111 len += 1 + ri->ri_attrs[i].an_name.bv_len;
2114 bindconf_unparse( &ri->ri_bindconf, &bc );
2117 bv->bv_val = ch_malloc(len + 1);
2120 ptr = lutil_strcopy( bv->bv_val, numbuf );
2121 ptr = lutil_strcopy( ptr, "uri=" );
2122 ptr = lutil_strcopy( ptr, ri->ri_uri );
2124 if ( ri->ri_nsuffix ) {
2125 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
2126 ptr = lutil_strcopy( ptr, " suffix=\"" );
2127 ptr = lutil_strcopy( ptr, ri->ri_nsuffix[i].bv_val );
2131 if ( ri->ri_attrs ) {
2132 ptr = lutil_strcopy( ptr, "attr" );
2133 if ( ri->ri_exclude ) *ptr++ = '!';
2135 ptr = anlist_unparse( ri->ri_attrs, ptr );
2138 strcpy( ptr, bc.bv_val );
2139 ch_free( bc.bv_val );
2144 config_replica(ConfigArgs *c) {
2145 int i, nr = -1, len;
2146 char *replicahost, *replicauri;
2150 if (c->be->be_replica) {
2152 for (i=0;c->be->be_replica[i]; i++) {
2153 replica_unparse( c->be->be_replica[i], i, &bv );
2154 ber_bvarray_add( &c->rvalue_vals, &bv );
2160 if(SLAP_MONITOR(c->be)) {
2161 Debug(LDAP_DEBUG_ANY, "%s: "
2162 "\"replica\" should not be used inside monitor database\n",
2164 return(0); /* FIXME: should this be an error? */
2167 for(i = 1; i < c->argc; i++) {
2168 if(!strncasecmp(c->argv[i], "host=", STRLENOF("host="))) {
2169 replicahost = c->argv[i] + STRLENOF("host=");
2170 len = strlen( replicahost );
2171 replicauri = ch_malloc( len + STRLENOF("ldap://") + 1 );
2172 sprintf( replicauri, "ldap://%s", replicahost );
2173 replicahost = replicauri + STRLENOF( "ldap://");
2174 nr = add_replica_info(c->be, replicauri, replicahost);
2176 } else if(!strncasecmp(c->argv[i], "uri=", STRLENOF("uri="))) {
2177 if(ldap_url_parse(c->argv[i] + STRLENOF("uri="), &ludp) != LDAP_SUCCESS) {
2178 Debug(LDAP_DEBUG_ANY, "%s: "
2179 "replica line contains invalid "
2180 "uri definition.\n", c->log, 0, 0);
2183 if(!ludp->lud_host) {
2184 Debug(LDAP_DEBUG_ANY, "%s: "
2185 "replica line contains invalid "
2186 "uri definition - missing hostname.\n",
2190 ldap_free_urldesc(ludp);
2191 replicauri = c->argv[i] + STRLENOF("uri=");
2192 replicauri = ch_strdup( replicauri );
2193 replicahost = strchr( replicauri, '/' );
2195 nr = add_replica_info(c->be, replicauri, replicahost);
2200 Debug(LDAP_DEBUG_ANY, "%s: "
2201 "missing host or uri in \"replica\" line\n",
2204 } else if(nr == -1) {
2205 Debug(LDAP_DEBUG_ANY, "%s: "
2206 "unable to add replica \"%s\"\n",
2207 c->log, replicauri, 0);
2210 for(i = 1; i < c->argc; i++) {
2211 if(!strncasecmp(c->argv[i], "suffix=", STRLENOF( "suffix="))) {
2212 switch(add_replica_suffix(c->be, nr, c->argv[i] + STRLENOF("suffix="))) {
2214 Debug(LDAP_DEBUG_ANY, "%s: "
2215 "suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
2216 c->log, c->argv[i] + STRLENOF("suffix="), 0);
2219 Debug(LDAP_DEBUG_ANY, "%s: "
2220 "unable to normalize suffix in \"replica\" line (ignored)\n",
2225 } else if(!strncasecmp(c->argv[i], "attr", STRLENOF("attr"))) {
2227 char *arg = c->argv[i] + STRLENOF("attr");
2235 if(add_replica_attrs(c->be, nr, arg + 1, exclude)) {
2236 Debug(LDAP_DEBUG_ANY, "%s: "
2237 "attribute \"%s\" in \"replica\" line is unknown\n",
2238 c->log, arg + 1, 0);
2241 } else if ( bindconf_parse( c->argv[i],
2242 &c->be->be_replica[nr]->ri_bindconf ) ) {
2251 config_updatedn(ConfigArgs *c) {
2255 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
2256 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
2257 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
2262 if(SLAP_SHADOW(c->be)) {
2263 Debug(LDAP_DEBUG_ANY, "%s: "
2264 "updatedn: database already shadowed.\n",
2269 ber_str2bv(c->argv[1], 0, 0, &dn);
2271 rc = dnNormalize(0, NULL, NULL, &dn, &c->be->be_update_ndn, NULL);
2273 if(rc != LDAP_SUCCESS) {
2274 Debug(LDAP_DEBUG_ANY, "%s: "
2275 "updatedn DN is invalid: %d (%s)\n",
2276 c->log, rc, ldap_err2string( rc ));
2280 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
2285 config_updateref(ConfigArgs *c) {
2286 struct berval vals[2];
2288 if ( c->be->be_update_refs ) {
2289 value_add( &c->rvalue_vals, c->be->be_update_refs );
2295 if(!SLAP_SHADOW(c->be)) {
2296 Debug(LDAP_DEBUG_ANY, "%s: "
2297 "updateref line must come after syncrepl or updatedn.\n",
2302 if(validate_global_referral(c->argv[1])) {
2303 Debug(LDAP_DEBUG_ANY, "%s: "
2304 "invalid URL (%s) in \"updateref\" line.\n",
2305 c->log, c->argv[1], 0);
2308 ber_str2bv(c->argv[1], 0, 0, &vals[0]);
2309 vals[1].bv_val = NULL;
2310 if(value_add(&c->be->be_update_refs, vals)) return(LDAP_OTHER);
2315 config_include(ConfigArgs *c) {
2316 unsigned long savelineno = c->lineno;
2319 ConfigFile *cfsave = cfn;
2320 ConfigFile *cf2 = NULL;
2324 cf = ch_calloc( 1, sizeof(ConfigFile));
2325 if ( cfn->c_kids ) {
2326 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
2332 rc = read_config_file(c->argv[1], c->depth + 1, c);
2333 c->lineno = savelineno - 1;
2336 if ( cf2 ) cf2->c_sibs = NULL;
2337 else cfn->c_kids = NULL;
2345 config_tls_option(ConfigArgs *c) {
2348 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; break;
2349 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
2350 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
2351 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
2352 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
2353 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
2354 default: Debug(LDAP_DEBUG_ANY, "%s: "
2355 "unknown tls_option <%x>\n",
2356 c->log, c->type, 0);
2359 return ldap_pvt_tls_get_option( NULL, flag, &c->value_string );
2361 ch_free(c->value_string);
2362 return(ldap_pvt_tls_set_option(NULL, flag, c->argv[1]));
2365 /* FIXME: this ought to be provided by libldap */
2367 config_tls_config(ConfigArgs *c) {
2369 struct verb_mask_list crlkeys[] = {
2370 { "none", LDAP_OPT_X_TLS_CRL_NONE },
2371 { "peer", LDAP_OPT_X_TLS_CRL_PEER },
2372 { "all", LDAP_OPT_X_TLS_CRL_ALL },
2375 struct verb_mask_list vfykeys[] = {
2376 { "never", LDAP_OPT_X_TLS_NEVER },
2377 { "demand", LDAP_OPT_X_TLS_DEMAND },
2378 { "try", LDAP_OPT_X_TLS_TRY },
2379 { "hard", LDAP_OPT_X_TLS_HARD },
2383 #ifdef HAVE_OPENSSL_CRL
2384 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; keys = crlkeys;
2387 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; keys = vfykeys;
2389 default: Debug(LDAP_DEBUG_ANY, "%s: "
2390 "unknown tls_option <%x>\n",
2391 c->log, c->type, 0);
2394 ldap_pvt_tls_get_option( NULL, flag, &c->value_int );
2395 for (i=0; keys[i].word; i++) {
2396 if (keys[i].mask == c->value_int) {
2397 c->value_string = ch_strdup( keys[i].word );
2403 ch_free( c->value_string );
2404 if(isdigit((unsigned char)c->argv[1][0])) {
2405 i = atoi(c->argv[1]);
2406 return(ldap_pvt_tls_set_option(NULL, flag, &i));
2408 return(ldap_int_tls_config(NULL, flag, c->argv[1]));
2413 /* -------------------------------------- */
2417 strtok_quote( char *line, char *sep )
2423 strtok_quote_ptr = NULL;
2424 if ( line != NULL ) {
2427 while ( *next && strchr( sep, *next ) ) {
2431 if ( *next == '\0' ) {
2437 for ( inquote = 0; *next; ) {
2445 AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
2451 next + 1, strlen( next + 1 ) + 1 );
2452 next++; /* dont parse the escaped character */
2457 if ( strchr( sep, *next ) != NULL ) {
2458 strtok_quote_ptr = next;
2471 static char buf[BUFSIZ];
2473 static size_t lmax, lcur;
2475 #define CATLINE( buf ) \
2477 size_t len = strlen( buf ); \
2478 while ( lcur + len + 1 > lmax ) { \
2480 line = (char *) ch_realloc( line, lmax ); \
2482 strcpy( line + lcur, buf ); \
2487 fp_getline_init(ConfigArgs *c) {
2493 fp_getline( FILE *fp, ConfigArgs *c )
2501 /* avoid stack of bufs */
2502 if ( strncasecmp( line, "include", STRLENOF( "include" ) ) == 0 ) {
2508 while ( fgets( buf, sizeof( buf ), fp ) ) {
2509 p = strchr( buf, '\n' );
2511 if ( p > buf && p[-1] == '\r' ) {
2519 && ( p = line + strlen( line ) - 1 )[0] == '\\'
2526 if ( !isspace( (unsigned char)buf[0] ) ) {
2537 return(line[0] ? 1 : 0);
2541 fp_parse_line(ConfigArgs *c)
2544 char *tline = ch_strdup(c->line);
2545 char *hide[] = { "rootpw", "replica", "bindpw", "pseudorootpw", "dbpasswd", '\0' };
2549 token = strtok_quote(tline, " \t");
2551 if(token) for(i = 0; hide[i]; i++) if(!strcasecmp(token, hide[i])) break;
2552 if(strtok_quote_ptr) *strtok_quote_ptr = ' ';
2553 Debug(LDAP_DEBUG_CONFIG, "line %lu (%s%s)\n", c->lineno, hide[i] ? hide[i] : c->line, hide[i] ? " ***" : "");
2554 if(strtok_quote_ptr) *strtok_quote_ptr = '\0';
2556 for(; token; token = strtok_quote(NULL, " \t")) {
2557 if(c->argc == c->argv_size - 1) {
2559 tmp = ch_realloc(c->argv, (c->argv_size + ARGS_STEP) * sizeof(*c->argv));
2561 Debug(LDAP_DEBUG_ANY, "line %lu: out of memory\n", c->lineno, 0, 0);
2565 c->argv_size += ARGS_STEP;
2567 c->argv[c->argc++] = token;
2569 c->argv[c->argc] = NULL;
2576 ucdata_unload( UCDATA_ALL );
2578 /* NOTE: in case of early exit, frontendDB can be NULL */
2579 if ( frontendDB->be_schemandn.bv_val )
2580 free( frontendDB->be_schemandn.bv_val );
2581 if ( frontendDB->be_schemadn.bv_val )
2582 free( frontendDB->be_schemadn.bv_val );
2583 if ( frontendDB->be_acl )
2584 acl_destroy( frontendDB->be_acl, NULL );
2587 if ( slapd_args_file )
2588 free ( slapd_args_file );
2589 if ( slapd_pid_file )
2590 free ( slapd_pid_file );
2591 if ( default_passwd_hash )
2592 ldap_charray_free( default_passwd_hash );
2605 si = (syncinfo_t *) ch_calloc( 1, sizeof( syncinfo_t ) );
2608 Debug( LDAP_DEBUG_ANY, "out of memory in add_syncrepl\n", 0, 0, 0 );
2612 si->si_bindconf.sb_tls = SB_TLS_OFF;
2613 si->si_bindconf.sb_method = LDAP_AUTH_SIMPLE;
2614 si->si_schemachecking = 0;
2615 ber_str2bv( "(objectclass=*)", STRLENOF("(objectclass=*)"), 1,
2616 &si->si_filterstr );
2617 si->si_base.bv_val = NULL;
2618 si->si_scope = LDAP_SCOPE_SUBTREE;
2619 si->si_attrsonly = 0;
2620 si->si_anlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ));
2621 si->si_exanlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ));
2622 si->si_attrs = NULL;
2623 si->si_allattrs = 0;
2624 si->si_allopattrs = 0;
2625 si->si_exattrs = NULL;
2626 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2627 si->si_interval = 86400;
2628 si->si_retryinterval = NULL;
2629 si->si_retrynum_init = NULL;
2630 si->si_retrynum = NULL;
2631 si->si_manageDSAit = 0;
2635 si->si_presentlist = NULL;
2636 LDAP_LIST_INIT( &si->si_nonpresentlist );
2637 ldap_pvt_thread_mutex_init( &si->si_mutex );
2639 rc = parse_syncrepl_line( cargv, cargc, si );
2642 Debug( LDAP_DEBUG_ANY, "failed to add syncinfo\n", 0, 0, 0 );
2643 syncinfo_free( si );
2646 Debug( LDAP_DEBUG_CONFIG,
2647 "Config: ** successfully added syncrepl \"%s\"\n",
2648 BER_BVISNULL( &si->si_provideruri ) ?
2649 "(null)" : si->si_provideruri.bv_val, 0, 0 );
2650 if ( !si->si_schemachecking ) {
2651 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NO_SCHEMA_CHECK;
2654 be->be_syncinfo = si;
2659 /* NOTE: used & documented in slapd.conf(5) */
2661 #define PROVIDERSTR "provider"
2662 #define TYPESTR "type"
2663 #define INTERVALSTR "interval"
2664 #define SEARCHBASESTR "searchbase"
2665 #define FILTERSTR "filter"
2666 #define SCOPESTR "scope"
2667 #define ATTRSSTR "attrs"
2668 #define ATTRSONLYSTR "attrsonly"
2669 #define SLIMITSTR "sizelimit"
2670 #define TLIMITSTR "timelimit"
2671 #define SCHEMASTR "schemachecking"
2673 /* FIXME: undocumented */
2674 #define OLDAUTHCSTR "bindprincipal"
2675 #define EXATTRSSTR "exattrs"
2676 #define RETRYSTR "retry"
2679 #define LASTMODSTR "lastmod"
2680 #define LMGENSTR "gen"
2681 #define LMNOSTR "no"
2682 #define LMREQSTR "req"
2683 #define SRVTABSTR "srvtab"
2684 #define SUFFIXSTR "suffix"
2685 #define MANAGEDSAITSTR "manageDSAit"
2688 #define GOT_ID 0x0001
2689 #define GOT_PROVIDER 0x0002
2692 #define GOT_ALL (GOT_ID|GOT_PROVIDER)
2698 { BER_BVC("base"), LDAP_SCOPE_BASE },
2699 { BER_BVC("one"), LDAP_SCOPE_ONELEVEL },
2700 #ifdef LDAP_SCOPE_SUBORDINATE
2701 { BER_BVC("children"), LDAP_SCOPE_SUBORDINATE },
2702 { BER_BVC("subordinate"), 0 },
2704 { BER_BVC("sub"), LDAP_SCOPE_SUBTREE },
2709 parse_syncrepl_line(
2719 for ( i = 1; i < cargc; i++ ) {
2720 if ( !strncasecmp( cargv[ i ], IDSTR "=",
2721 STRLENOF( IDSTR "=" ) ) )
2724 /* '\0' string terminator accounts for '=' */
2725 val = cargv[ i ] + STRLENOF( IDSTR "=" );
2727 if ( tmp >= 1000 || tmp < 0 ) {
2728 fprintf( stderr, "Error: parse_syncrepl_line: "
2729 "syncrepl id %d is out of range [0..999]\n", tmp );
2734 } else if ( !strncasecmp( cargv[ i ], PROVIDERSTR "=",
2735 STRLENOF( PROVIDERSTR "=" ) ) )
2737 val = cargv[ i ] + STRLENOF( PROVIDERSTR "=" );
2738 ber_str2bv( val, 0, 1, &si->si_provideruri );
2739 gots |= GOT_PROVIDER;
2740 } else if ( !strncasecmp( cargv[ i ], SCHEMASTR "=",
2741 STRLENOF( SCHEMASTR "=" ) ) )
2743 val = cargv[ i ] + STRLENOF( SCHEMASTR "=" );
2744 if ( !strncasecmp( val, "on", STRLENOF( "on" ) )) {
2745 si->si_schemachecking = 1;
2746 } else if ( !strncasecmp( val, "off", STRLENOF( "off" ) ) ) {
2747 si->si_schemachecking = 0;
2749 si->si_schemachecking = 1;
2751 } else if ( !strncasecmp( cargv[ i ], FILTERSTR "=",
2752 STRLENOF( FILTERSTR "=" ) ) )
2754 val = cargv[ i ] + STRLENOF( FILTERSTR "=" );
2755 ber_str2bv( val, 0, 1, &si->si_filterstr );
2756 } else if ( !strncasecmp( cargv[ i ], SEARCHBASESTR "=",
2757 STRLENOF( SEARCHBASESTR "=" ) ) )
2762 val = cargv[ i ] + STRLENOF( SEARCHBASESTR "=" );
2763 if ( si->si_base.bv_val ) {
2764 ch_free( si->si_base.bv_val );
2766 ber_str2bv( val, 0, 0, &bv );
2767 rc = dnNormalize( 0, NULL, NULL, &bv, &si->si_base, NULL );
2768 if ( rc != LDAP_SUCCESS ) {
2769 fprintf( stderr, "Invalid base DN \"%s\": %d (%s)\n",
2770 val, rc, ldap_err2string( rc ) );
2773 } else if ( !strncasecmp( cargv[ i ], SCOPESTR "=",
2774 STRLENOF( SCOPESTR "=" ) ) )
2777 val = cargv[ i ] + STRLENOF( SCOPESTR "=" );
2778 for ( j=0; !BER_BVISNULL(&scopes[j].key); j++ ) {
2779 if (!strncasecmp( val, scopes[j].key.bv_val,
2780 scopes[j].key.bv_len )) {
2781 while (!scopes[j].val) j--;
2782 si->si_scope = scopes[j].val;
2786 if ( BER_BVISNULL(&scopes[j].key) ) {
2787 fprintf( stderr, "Error: parse_syncrepl_line: "
2788 "unknown scope \"%s\"\n", val);
2791 } else if ( !strncasecmp( cargv[ i ], ATTRSONLYSTR "=",
2792 STRLENOF( ATTRSONLYSTR "=" ) ) )
2794 si->si_attrsonly = 1;
2795 } else if ( !strncasecmp( cargv[ i ], ATTRSSTR "=",
2796 STRLENOF( ATTRSSTR "=" ) ) )
2798 val = cargv[ i ] + STRLENOF( ATTRSSTR "=" );
2799 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") ) ) {
2801 attr_fname = ch_strdup( val + STRLENOF(":include:") );
2802 si->si_anlist = file2anlist( si->si_anlist, attr_fname, " ,\t" );
2803 if ( si->si_anlist == NULL ) {
2804 ch_free( attr_fname );
2807 si->si_anfile = attr_fname;
2809 char *str, *s, *next;
2810 char delimstr[] = " ,\t";
2811 str = ch_strdup( val );
2812 for ( s = ldap_pvt_strtok( str, delimstr, &next );
2814 s = ldap_pvt_strtok( NULL, delimstr, &next ) )
2816 if ( strlen(s) == 1 && *s == '*' ) {
2817 si->si_allattrs = 1;
2818 *(val + ( s - str )) = delimstr[0];
2820 if ( strlen(s) == 1 && *s == '+' ) {
2821 si->si_allopattrs = 1;
2822 *(val + ( s - str )) = delimstr[0];
2826 si->si_anlist = str2anlist( si->si_anlist, val, " ,\t" );
2827 if ( si->si_anlist == NULL ) {
2831 } else if ( !strncasecmp( cargv[ i ], EXATTRSSTR "=",
2832 STRLENOF( EXATTRSSTR "=" ) ) )
2834 val = cargv[ i ] + STRLENOF( EXATTRSSTR "=" );
2835 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") )) {
2837 attr_fname = ch_strdup( val + STRLENOF(":include:") );
2838 si->si_exanlist = file2anlist(
2839 si->si_exanlist, attr_fname, " ,\t" );
2840 if ( si->si_exanlist == NULL ) {
2841 ch_free( attr_fname );
2844 ch_free( attr_fname );
2846 si->si_exanlist = str2anlist( si->si_exanlist, val, " ,\t" );
2847 if ( si->si_exanlist == NULL ) {
2851 } else if ( !strncasecmp( cargv[ i ], TYPESTR "=",
2852 STRLENOF( TYPESTR "=" ) ) )
2854 val = cargv[ i ] + STRLENOF( TYPESTR "=" );
2855 if ( !strncasecmp( val, "refreshOnly",
2856 STRLENOF("refreshOnly") ))
2858 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2859 } else if ( !strncasecmp( val, "refreshAndPersist",
2860 STRLENOF("refreshAndPersist") ))
2862 si->si_type = LDAP_SYNC_REFRESH_AND_PERSIST;
2863 si->si_interval = 60;
2865 fprintf( stderr, "Error: parse_syncrepl_line: "
2866 "unknown sync type \"%s\"\n", val);
2869 } else if ( !strncasecmp( cargv[ i ], INTERVALSTR "=",
2870 STRLENOF( INTERVALSTR "=" ) ) )
2872 val = cargv[ i ] + STRLENOF( INTERVALSTR "=" );
2873 if ( si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ) {
2874 si->si_interval = 0;
2882 hstr = strchr( dstr, ':' );
2883 if ( hstr == NULL ) {
2884 fprintf( stderr, "Error: parse_syncrepl_line: "
2885 "invalid interval \"%s\"\n", val );
2889 mstr = strchr( hstr, ':' );
2890 if ( mstr == NULL ) {
2891 fprintf( stderr, "Error: parse_syncrepl_line: "
2892 "invalid interval \"%s\"\n", val );
2896 sstr = strchr( mstr, ':' );
2897 if ( sstr == NULL ) {
2898 fprintf( stderr, "Error: parse_syncrepl_line: "
2899 "invalid interval \"%s\"\n", val );
2908 if (( hh > 24 ) || ( hh < 0 ) ||
2909 ( mm > 60 ) || ( mm < 0 ) ||
2910 ( ss > 60 ) || ( ss < 0 ) || ( dd < 0 )) {
2911 fprintf( stderr, "Error: parse_syncrepl_line: "
2912 "invalid interval \"%s\"\n", val );
2915 si->si_interval = (( dd * 24 + hh ) * 60 + mm ) * 60 + ss;
2917 if ( si->si_interval < 0 ) {
2918 fprintf( stderr, "Error: parse_syncrepl_line: "
2919 "invalid interval \"%ld\"\n",
2920 (long) si->si_interval);
2923 } else if ( !strncasecmp( cargv[ i ], RETRYSTR "=",
2924 STRLENOF( RETRYSTR "=" ) ) )
2929 val = cargv[ i ] + STRLENOF( RETRYSTR "=" );
2930 retry_list = (char **) ch_calloc( 1, sizeof( char * ));
2931 retry_list[0] = NULL;
2933 slap_str2clist( &retry_list, val, " ,\t" );
2935 for ( k = 0; retry_list && retry_list[k]; k++ ) ;
2939 "Error: incomplete syncrepl retry list\n" );
2940 for ( k = 0; retry_list && retry_list[k]; k++ ) {
2941 ch_free( retry_list[k] );
2943 ch_free( retry_list );
2944 exit( EXIT_FAILURE );
2946 si->si_retryinterval = (time_t *) ch_calloc( n + 1, sizeof( time_t ));
2947 si->si_retrynum = (int *) ch_calloc( n + 1, sizeof( int ));
2948 si->si_retrynum_init = (int *) ch_calloc( n + 1, sizeof( int ));
2949 for ( j = 0; j < n; j++ ) {
2950 si->si_retryinterval[j] = atoi( retry_list[j*2] );
2951 if ( *retry_list[j*2+1] == '+' ) {
2952 si->si_retrynum_init[j] = -1;
2953 si->si_retrynum[j] = -1;
2957 si->si_retrynum_init[j] = atoi( retry_list[j*2+1] );
2958 si->si_retrynum[j] = atoi( retry_list[j*2+1] );
2961 si->si_retrynum_init[j] = -2;
2962 si->si_retrynum[j] = -2;
2963 si->si_retryinterval[j] = 0;
2965 for ( k = 0; retry_list && retry_list[k]; k++ ) {
2966 ch_free( retry_list[k] );
2968 ch_free( retry_list );
2969 } else if ( !strncasecmp( cargv[ i ], MANAGEDSAITSTR "=",
2970 STRLENOF( MANAGEDSAITSTR "=" ) ) )
2972 val = cargv[ i ] + STRLENOF( MANAGEDSAITSTR "=" );
2973 si->si_manageDSAit = atoi( val );
2974 } else if ( !strncasecmp( cargv[ i ], SLIMITSTR "=",
2975 STRLENOF( SLIMITSTR "=") ) )
2977 val = cargv[ i ] + STRLENOF( SLIMITSTR "=" );
2978 si->si_slimit = atoi( val );
2979 } else if ( !strncasecmp( cargv[ i ], TLIMITSTR "=",
2980 STRLENOF( TLIMITSTR "=" ) ) )
2982 val = cargv[ i ] + STRLENOF( TLIMITSTR "=" );
2983 si->si_tlimit = atoi( val );
2984 } else if ( bindconf_parse( cargv[i], &si->si_bindconf )) {
2985 fprintf( stderr, "Error: parse_syncrepl_line: "
2986 "unknown keyword \"%s\"\n", cargv[ i ] );
2991 if ( gots != GOT_ALL ) {
2993 "Error: Malformed \"syncrepl\" line in slapd config file" );
3003 syncrepl_unparse( syncinfo_t *si, struct berval *bv )
3006 char buf[BUFSIZ*2], *ptr;
3009 bindconf_unparse( &si->si_bindconf, &bc );
3011 ptr += sprintf( ptr, IDSTR "=%03d " PROVIDERSTR "=%s",
3012 si->si_rid, si->si_provideruri.bv_val );
3013 if ( !BER_BVISNULL( &bc )) {
3014 ptr = lutil_strcopy( ptr, bc.bv_val );
3017 if ( !BER_BVISEMPTY( &si->si_filterstr )) {
3018 ptr = lutil_strcopy( ptr, " " FILTERSTR "=\"" );
3019 ptr = lutil_strcopy( ptr, si->si_filterstr.bv_val );
3022 if ( !BER_BVISNULL( &si->si_base )) {
3023 ptr = lutil_strcopy( ptr, " " SEARCHBASESTR "=\"" );
3024 ptr = lutil_strcopy( ptr, si->si_base.bv_val );
3027 for (i=0; !BER_BVISNULL(&scopes[i].key);i++) {
3028 if ( si->si_scope == scopes[i].val ) {
3029 ptr = lutil_strcopy( ptr, " " SCOPESTR "=" );
3030 ptr = lutil_strcopy( ptr, scopes[i].key.bv_val );
3034 if ( si->si_attrsonly ) {
3035 ptr = lutil_strcopy( ptr, " " ATTRSONLYSTR "=yes" );
3037 if ( si->si_anfile ) {
3038 ptr = lutil_strcopy( ptr, " " ATTRSSTR "=:include:" );
3039 ptr = lutil_strcopy( ptr, si->si_anfile );
3040 } else if ( si->si_allattrs || si->si_allopattrs ||
3041 ( si->si_anlist && !BER_BVISNULL(&si->si_anlist[0].an_name) )) {
3043 ptr = lutil_strcopy( ptr, " " ATTRSSTR "=\"" );
3045 ptr = anlist_unparse( si->si_anlist, ptr );
3046 if ( si->si_allattrs ) {
3047 if ( old != ptr ) *ptr++ = ',';
3050 if ( si->si_allopattrs ) {
3051 if ( old != ptr ) *ptr++ = ',';
3056 if ( si->si_exanlist && !BER_BVISNULL(&si->si_exanlist[0].an_name) ) {
3057 ptr = lutil_strcopy( ptr, " " EXATTRSSTR "=" );
3058 ptr = anlist_unparse( si->si_exanlist, ptr );
3060 ptr = lutil_strcopy( ptr, " " SCHEMASTR "=" );
3061 ptr = lutil_strcopy( ptr, si->si_schemachecking ? "on" : "off" );
3063 ptr = lutil_strcopy( ptr, " " TYPESTR "=" );
3064 ptr = lutil_strcopy( ptr, si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ?
3065 "refreshAndPersist" : "refreshOnly" );
3067 if ( si->si_type == LDAP_SYNC_REFRESH_ONLY ) {
3070 dd = si->si_interval;
3077 ptr = lutil_strcopy( ptr, " " INTERVALSTR "=" );
3078 ptr += sprintf( ptr, "%02d:%02d:%02d:%02d", dd, hh, mm, ss );
3079 } else if ( si->si_retryinterval ) {
3081 ptr = lutil_strcopy( ptr, " " RETRYSTR "=\"" );
3082 for (i=0; si->si_retryinterval[i]; i++) {
3083 if ( space ) *ptr++ = ' ';
3085 ptr += sprintf( ptr, "%d", si->si_retryinterval[i] );
3086 if ( si->si_retrynum_init[i] == -1 )
3089 ptr += sprintf( ptr, "%d", si->si_retrynum_init );
3094 #if 0 /* FIXME: unused in syncrepl.c, should remove it */
3095 ptr = lutil_strcopy( ptr, " " MANAGEDSAITSTR "=" );
3096 ptr += sprintf( ptr, "%d", si->si_manageDSAit );
3099 if ( si->si_slimit ) {
3100 ptr = lutil_strcopy( ptr, " " SLIMITSTR "=" );
3101 ptr += sprintf( ptr, "%d", si->si_slimit );
3104 if ( si->si_tlimit ) {
3105 ptr = lutil_strcopy( ptr, " " TLIMITSTR "=" );
3106 ptr += sprintf( ptr, "%d", si->si_tlimit );
3108 bc.bv_len = ptr - buf;
3110 ber_dupbv( bv, &bc );
3114 slap_str2clist( char ***out, char *in, const char *brkstr )
3122 /* find last element in list */
3123 for (i = 0; *out && (*out)[i]; i++);
3125 /* protect the input string from strtok */
3126 str = ch_strdup( in );
3128 if ( *str == '\0' ) {
3133 /* Count words in string */
3135 for ( s = str; *s; s++ ) {
3136 if ( strchr( brkstr, *s ) != NULL ) {
3141 *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
3143 for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
3145 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
3147 *new = ch_strdup( s );