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;
87 static BerVarray authz_rewrites;
90 int slapi_plugins_used = 0;
93 static int fp_getline(FILE *fp, ConfigArgs *c);
94 static void fp_getline_init(ConfigArgs *c);
95 static int fp_parse_line(ConfigArgs *c);
97 static char *strtok_quote(char *line, char *sep);
100 int read_config_file(const char *fname, int depth, ConfigArgs *cf);
102 static int add_syncrepl LDAP_P(( Backend *, char **, int ));
103 static int parse_syncrepl_line LDAP_P(( char **, int, syncinfo_t *));
104 static void syncrepl_unparse LDAP_P (( syncinfo_t *, struct berval *));
106 /* All of these table entries and handlers really belong
107 * in back-config, only the parser/table engine belongs here.
109 /* state info for back-config */
110 static ConfigFile cf_prv, *cfn = &cf_prv;
112 static int config_fname(ConfigArgs *c);
113 static int config_generic(ConfigArgs *c);
114 static int config_search_base(ConfigArgs *c);
115 static int config_passwd_hash(ConfigArgs *c);
116 static int config_schema_dn(ConfigArgs *c);
117 static int config_sizelimit(ConfigArgs *c);
118 static int config_timelimit(ConfigArgs *c);
119 static int config_limits(ConfigArgs *c);
120 static int config_overlay(ConfigArgs *c);
121 static int config_suffix(ConfigArgs *c);
122 static int config_deref_depth(ConfigArgs *c);
123 static int config_rootdn(ConfigArgs *c);
124 static int config_rootpw(ConfigArgs *c);
125 static int config_restrict(ConfigArgs *c);
126 static int config_allows(ConfigArgs *c);
127 static int config_disallows(ConfigArgs *c);
128 static int config_requires(ConfigArgs *c);
129 static int config_security(ConfigArgs *c);
130 static int config_referral(ConfigArgs *c);
131 static int config_loglevel(ConfigArgs *c);
132 static int config_syncrepl(ConfigArgs *c);
133 static int config_replica(ConfigArgs *c);
134 static int config_updatedn(ConfigArgs *c);
135 static int config_updateref(ConfigArgs *c);
136 static int config_include(ConfigArgs *c);
138 static int config_tls_option(ConfigArgs *c);
139 static int config_tls_config(ConfigArgs *c);
188 static OidRec OidMacros[] = {
189 /* OpenLDAProot:666.11.1 */
190 { "OLcfg", "1.3.6.1.4.1.4203.666.11.1" },
191 { "OLcfgAt", "OLcfg:3" },
192 { "OLcfgOc", "OLcfg:4" },
193 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
194 { "OMsInteger", "OMsyn:2" },
195 { "OMsBoolean", "OMsyn:7" },
196 { "OMsDN", "OMsyn:12" },
197 { "OMsDirectoryString", "OMsyn:15" },
198 { "OMsOctetString", "OMsyn:40" },
202 /* alphabetical ordering */
204 static ConfigTable SystemConfiguration[] = {
205 /* This attr is read-only */
206 { "", "", 0, 0, 0, ARG_MAGIC,
207 &config_fname, "( OLcfgAt:78 NAME 'olcConfigFile' "
208 "DESC 'File for slapd configuration directives' "
209 "EQUALITY caseIgnoreMatch "
210 "SYNTAX OMsDirectoryString )", NULL, NULL },
211 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
212 &config_generic, "( OLcfgAt:1 NAME 'olcAccess' "
213 "DESC 'Access Control List' "
214 "EQUALITY caseIgnoreMatch "
215 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
216 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
217 &config_allows, "( OLcfgAt:2 NAME 'olcAllows' "
218 "DESC 'Allowed set of deprecated features' "
219 "EQUALITY caseIgnoreMatch "
220 "SYNTAX OMsDirectoryString )", NULL, NULL },
221 { "argsfile", "file", 2, 2, 0, ARG_STRING,
222 &slapd_args_file, "( OLcfgAt:3 NAME 'olcArgsFile' "
223 "DESC 'File for slapd command line options' "
224 "EQUALITY caseIgnoreMatch "
225 "SYNTAX OMsDirectoryString )", NULL, NULL },
226 /* Use standard 'attributeTypes' attr */
227 { "attribute", "attribute", 2, 0, 9, ARG_PAREN|ARG_MAGIC|CFG_ATTR,
228 &config_generic, NULL, NULL, NULL },
229 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
230 &config_generic, "( OLcfgAt:5 NAME 'olcAttributeOptions' "
231 "EQUALITY caseIgnoreMatch "
232 "SYNTAX OMsDirectoryString )", NULL, NULL },
233 { "authid-rewrite", NULL, 2, 0, 0,
234 #ifdef SLAP_AUTH_REWRITE
235 ARG_MAGIC|CFG_REWRITE, &config_generic,
239 "( OLcfgAt:6 NAME 'olcAuthIDRewrite' "
240 "EQUALITY caseIgnoreMatch "
241 "SYNTAX OMsDirectoryString )", NULL, NULL },
242 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
243 &config_generic, "( OLcfgAt:7 NAME 'olcAuthzPolicy' "
244 "EQUALITY caseIgnoreMatch "
245 "SYNTAX OMsDirectoryString )", NULL, NULL },
246 { "authz-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
247 &config_generic, "( OLcfgAt:8 NAME 'olcAuthzRegexp' "
248 "EQUALITY caseIgnoreMatch "
249 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
250 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
251 &config_generic, "( OLcfgAt:9 NAME 'olcBackend' "
252 "DESC 'A type of backend' "
253 "EQUALITY caseIgnoreMatch "
254 "SYNTAX OMsDirectoryString )", NULL, NULL },
255 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_CONCUR,
256 &config_generic, "( OLcfgAt:10 NAME 'olcConcurrency' "
257 "SYNTAX OMsInteger )", NULL, NULL },
258 { "conn_max_pending", "max", 2, 2, 0, ARG_LONG,
259 &slap_conn_max_pending, "( OLcfgAt:11 NAME 'olcConnMaxPending' "
260 "SYNTAX OMsInteger )", NULL, NULL },
261 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_LONG,
262 &slap_conn_max_pending_auth, "( OLcfgAt:12 NAME 'olcConnMaxPendingAuth' "
263 "SYNTAX OMsInteger )", NULL, NULL },
264 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
265 &config_generic, "( OLcfgAt:13 NAME 'olcDatabase' "
266 "DESC 'The backend type for a database instance' "
267 "SUP olcBackend )", NULL, NULL },
268 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_MAGIC,
269 &config_search_base, "( OLcfgAt:14 NAME 'olcDefaultSearchBase' "
270 "SYNTAX OMsDN )", NULL, NULL },
271 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
272 &config_disallows, "( OLcfgAt:15 NAME 'olcDisallows' "
273 "EQUALITY caseIgnoreMatch "
274 "SYNTAX OMsDirectoryString )", NULL, NULL },
275 /* use standard schema */
276 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT,
277 &config_generic, NULL, NULL, NULL },
278 { "gentlehup", "on|off", 2, 2, 0,
280 ARG_ON_OFF, &global_gentlehup,
284 "( OLcfgAt:17 NAME 'olcGentleHUP' "
285 "SYNTAX OMsBoolean )", NULL, NULL },
286 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
287 &global_idletimeout, "( OLcfgAt:18 NAME 'olcIdleTimeout' "
288 "SYNTAX OMsInteger )", NULL, NULL },
289 /* XXX -- special case? */
290 { "include", "file", 2, 2, 0, ARG_MAGIC,
291 &config_include, "( OLcfgAt:19 NAME 'olcInclude' "
292 "SUP labeledURI )", NULL, NULL },
293 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
294 &config_generic, "( OLcfgAt:20 NAME 'olcIndexSubstrIfMinLen' "
295 "SYNTAX OMsInteger )", NULL, NULL },
296 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
297 &config_generic, "( OLcfgAt:21 NAME 'olcIndexSubstrIfMaxLen' "
298 "SYNTAX OMsInteger )", NULL, NULL },
299 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
300 &index_substr_any_len, "( OLcfgAt:22 NAME 'olcIndexSubstrAnyLen' "
301 "SYNTAX OMsInteger )", NULL, NULL },
302 { "index_substr_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
303 &index_substr_any_step, "( OLcfgAt:23 NAME 'olcIndexSubstrAnyStep' "
304 "SYNTAX OMsInteger )", NULL, NULL },
305 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
306 &config_generic, "( OLcfgAt:24 NAME 'olcLastMod' "
307 "SYNTAX OMsBoolean )", NULL, NULL },
308 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
309 &config_generic, "( OLcfgAt:25 NAME 'olcLimits' "
310 "SYNTAX OMsDirectoryString )", NULL, NULL },
311 { "localSSF", "ssf", 2, 2, 0, ARG_LONG,
312 &local_ssf, "( OLcfgAt:26 NAME 'olcLocalSSF' "
313 "SYNTAX OMsInteger )", NULL, NULL },
314 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
315 &config_generic, "( OLcfgAt:27 NAME 'olcLogFile' "
316 "SYNTAX OMsDirectoryString )", NULL, NULL },
317 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
318 &config_loglevel, "( OLcfgAt:28 NAME 'olcLogLevel' "
319 "SYNTAX OMsDirectoryString )", NULL, NULL },
320 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
321 &config_generic, "( OLcfgAt:29 NAME 'olcMaxDerefDepth' "
322 "SYNTAX OMsInteger )", NULL, NULL },
323 { "moduleload", "file", 2, 0, 0,
325 ARG_MAGIC|CFG_MODLOAD, &config_generic,
329 "( OLcfgAt:30 NAME 'olcModuleLoad' "
330 "SYNTAX OMsDirectoryString )", NULL, NULL },
331 { "modulepath", "path", 2, 2, 0,
333 ARG_MAGIC|CFG_MODPATH, &config_generic,
337 "( OLcfgAt:31 NAME 'olcModulePath' "
338 "SYNTAX OMsDirectoryString )", NULL, NULL },
339 /* use standard schema */
340 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
341 &config_generic, NULL, NULL, NULL },
342 { "objectidentifier", NULL, 0, 0, 0, ARG_MAGIC|CFG_OID,
343 &config_generic, "( OLcfgAt:33 NAME 'olcObjectIdentifier' "
344 "SYNTAX OMsDirectoryString )", NULL, NULL },
345 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
346 &config_overlay, "( OLcfgAt:34 NAME 'olcOverlay' "
347 "SUP olcDatabase )", NULL, NULL },
348 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
349 &config_generic, "( OLcfgAt:35 NAME 'olcPasswordCryptSaltFormat' "
350 "SYNTAX OMsDirectoryString )", NULL, NULL },
351 { "password-hash", "hash", 2, 2, 0, ARG_MAGIC,
352 &config_passwd_hash, "( OLcfgAt:36 NAME 'olcPasswordHash' "
353 "SYNTAX OMsDirectoryString )", NULL, NULL },
354 { "pidfile", "file", 2, 2, 0, ARG_STRING,
355 &slapd_pid_file, "( OLcfgAt:37 NAME 'olcPidFile' "
356 "SYNTAX OMsDirectoryString )", NULL, NULL },
357 { "plugin", NULL, 0, 0, 0,
359 ARG_MAGIC|CFG_PLUGIN, &config_generic,
363 "( OLcfgAt:38 NAME 'olcPlugin' "
364 "SYNTAX OMsDirectoryString )", NULL, NULL },
365 { "pluginlog", "filename", 2, 2, 0,
367 ARG_STRING, &slapi_log_file,
371 "( OLcfgAt:39 NAME 'olcPluginLogFile' "
372 "SYNTAX OMsDirectoryString )", NULL, NULL },
373 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
374 &config_generic, "( OLcfgAt:40 NAME 'olcReadOnly' "
375 "SYNTAX OMsBoolean )", NULL, NULL },
376 { "referral", "url", 2, 2, 0, ARG_MAGIC,
377 &config_referral, "( OLcfgAt:41 NAME 'olcReferral' "
378 "SUP labeledURI )", NULL, NULL },
379 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
380 &config_replica, "( OLcfgAt:42 NAME 'olcReplica' "
381 "SUP labeledURI )", NULL, NULL },
382 { "replica-argsfile", NULL, 0, 0, 0, ARG_STRING,
383 &replica_argsFile, "( OLcfgAt:43 NAME 'olcReplicaArgsFile' "
384 "SYNTAX OMsDirectoryString )", NULL, NULL },
385 { "replica-pidfile", NULL, 0, 0, 0, ARG_STRING,
386 &replica_pidFile, "( OLcfgAt:44 NAME 'olcReplicaPidFile' "
387 "SYNTAX OMsDirectoryString )", NULL, NULL },
388 { "replicationInterval", NULL, 0, 0, 0, ARG_INT,
389 &replicationInterval, "( OLcfgAt:45 NAME 'olcReplicationInterval' "
390 "SYNTAX OMsInteger )", NULL, NULL },
391 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC|ARG_STRING|CFG_REPLOG,
392 &config_generic, "( OLcfgAt:46 NAME 'olcReplogFile' "
393 "SYNTAX OMsDirectoryString )", NULL, NULL },
394 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
395 &config_requires, "( OLcfgAt:47 NAME 'olcRequires' "
396 "SYNTAX OMsDirectoryString )", NULL, NULL },
397 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
398 &config_restrict, "( OLcfgAt:48 NAME 'olcRestrict' "
399 "SYNTAX OMsDirectoryString )", NULL, NULL },
400 { "reverse-lookup", "on|off", 2, 2, 0,
401 #ifdef SLAPD_RLOOKUPS
402 ARG_ON_OFF, &use_reverse_lookup,
406 "( OLcfgAt:49 NAME 'olcReverseLookup' "
407 "SYNTAX OMsBoolean )", NULL, NULL },
408 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_MAGIC,
409 &config_rootdn, "( OLcfgAt:50 NAME 'olcRootDN' "
410 "SYNTAX OMsDN )", NULL, NULL },
411 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
412 &config_generic, "( OLcfgAt:51 NAME 'olcRootDSE' "
413 "SYNTAX OMsDirectoryString )", NULL, NULL },
414 { "rootpw", "password", 2, 2, 0, ARG_STRING|ARG_DB|ARG_MAGIC,
415 &config_rootpw, "( OLcfgAt:52 NAME 'olcRootPW' "
416 "SYNTAX OMsOctetString )", NULL, NULL },
417 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
418 &config_generic, NULL, NULL, NULL },
419 { "sasl-host", "host", 2, 2, 0,
420 #ifdef HAVE_CYRUS_SASL
421 ARG_STRING|ARG_UNIQUE, &global_host,
425 "( OLcfgAt:53 NAME 'olcSaslHost' "
426 "SYNTAX OMsDirectoryString )", NULL, NULL },
427 { "sasl-realm", "realm", 2, 2, 0,
428 #ifdef HAVE_CYRUS_SASL
429 ARG_STRING|ARG_UNIQUE, &global_realm,
433 "( OLcfgAt:54 NAME 'olcSaslRealm' "
434 "SYNTAX OMsDirectoryString )", NULL, NULL },
435 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
436 &config_generic, NULL, NULL, NULL },
437 { "sasl-secprops", "properties", 2, 2, 0,
438 #ifdef HAVE_CYRUS_SASL
439 ARG_MAGIC|CFG_SASLSECP, &config_generic,
443 "( OLcfgAt:56 NAME 'olcSaslSecProps' "
444 "SYNTAX OMsDirectoryString )", NULL, NULL },
445 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
446 &config_generic, NULL, NULL, NULL },
447 { "schemacheck", "on|off", 2, 2, 0, ARG_ON_OFF|ARG_MAGIC|CFG_CHECK,
448 &config_generic, "( OLcfgAt:57 NAME 'olcSchemaCheck' "
449 "SYNTAX OMsBoolean )", NULL, NULL },
450 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_MAGIC,
451 &config_schema_dn, "( OLcfgAt:58 NAME 'olcSchemaDN' "
452 "SYNTAX OMsDN )", NULL, NULL },
453 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
454 &config_security, "( OLcfgAt:59 NAME 'olcSecurity' "
455 "SYNTAX OMsDirectoryString )", NULL, NULL },
456 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_SIZE,
457 &config_sizelimit, "( OLcfgAt:60 NAME 'olcSizeLimit' "
458 "SYNTAX OMsInteger )", NULL, NULL },
459 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_LONG,
460 &sockbuf_max_incoming, "( OLcfgAt:61 NAME 'olcSockbufMaxIncoming' "
461 "SYNTAX OMsInteger )", NULL, NULL },
462 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_LONG,
463 &sockbuf_max_incoming_auth, "( OLcfgAt:62 NAME 'olcSockbufMaxIncomingAuth' "
464 "SYNTAX OMsInteger )", NULL, NULL },
465 { "srvtab", "file", 2, 2, 0,
466 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
467 ARG_STRING, &ldap_srvtab,
471 "( OLcfgAt:63 NAME 'olcSrvtab' "
472 "SYNTAX OMsDirectoryString )", NULL, NULL },
473 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_MAGIC,
474 &config_suffix, "( OLcfgAt:64 NAME 'olcSuffix' "
475 "SYNTAX OMsDN )", NULL, NULL },
476 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
477 &config_syncrepl, "( OLcfgAt:65 NAME 'olcSyncrepl' "
478 "SYNTAX OMsDirectoryString )", NULL, NULL },
479 { "threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_THREADS,
480 &config_generic, "( OLcfgAt:66 NAME 'olcThreads' "
481 "SYNTAX OMsInteger )", NULL, NULL },
482 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_TIME,
483 &config_timelimit, "( OLcfgAt:67 NAME 'olcTimeLimit' "
484 "SYNTAX OMsInteger )", NULL, NULL },
485 { "TLSCACertificateFile", NULL, 0, 0, 0,
487 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
491 "( OLcfgAt:68 NAME 'olcTLSCACertificateFile' "
492 "SYNTAX OMsDirectoryString )", NULL, NULL },
493 { "TLSCACertificatePath", NULL, 0, 0, 0,
495 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
499 "( OLcfgAt:69 NAME 'olcTLSCACertificatePath' "
500 "SYNTAX OMsDirectoryString )", NULL, NULL },
501 { "TLSCertificateFile", NULL, 0, 0, 0,
503 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
507 "( OLcfgAt:70 NAME 'olcTLSCertificateFile' "
508 "SYNTAX OMsDirectoryString )", NULL, NULL },
509 { "TLSCertificateKeyFile", NULL, 0, 0, 0,
511 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
515 "( OLcfgAt:71 NAME 'olcTLSCertificateKeyFile' "
516 "SYNTAX OMsDirectoryString )", NULL, NULL },
517 { "TLSCipherSuite", NULL, 0, 0, 0,
519 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
523 "( OLcfgAt:72 NAME 'olcTLSCipherSuite' "
524 "SYNTAX OMsDirectoryString )", NULL, NULL },
525 { "TLSCRLCheck", NULL, 0, 0, 0,
527 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
531 "( OLcfgAt:73 NAME 'olcTLSCRLCheck' "
532 "SYNTAX OMsDirectoryString )", NULL, NULL },
533 { "TLSRandFile", NULL, 0, 0, 0,
535 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
539 "( OLcfgAt:74 NAME 'olcTLSRandFile' "
540 "SYNTAX OMsDirectoryString )", NULL, NULL },
541 { "TLSVerifyClient", NULL, 0, 0, 0,
543 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
547 "( OLcfgAt:75 NAME 'olcTLSVerifyClient' "
548 "SYNTAX OMsDirectoryString )", NULL, NULL },
549 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
550 NULL, NULL, NULL, NULL },
551 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_MAGIC,
552 &config_updatedn, "( OLcfgAt:76 NAME 'olcUpdateDN' "
553 "SYNTAX OMsDN )", NULL, NULL },
554 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
555 &config_updateref, "( OLcfgAt:77 NAME 'olcUpdateRef' "
556 "SUP labeledURI )", NULL, NULL },
557 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
558 NULL, NULL, NULL, NULL }
563 new_config_args( BackendDB *be, const char *fname, int lineno, int argc, char **argv )
566 c = ch_calloc( 1, sizeof( ConfigArgs ) );
567 if ( c == NULL ) return(NULL);
573 snprintf( c->log, sizeof( c->log ), "%s: line %lu", fname, lineno );
577 int parse_config_table(ConfigTable *Conf, ConfigArgs *c) {
578 int i, rc, arg_user, arg_type, iarg;
581 for(i = 0; Conf[i].name; i++)
582 if( (Conf[i].length && (!strncasecmp(c->argv[0], Conf[i].name, Conf[i].length))) ||
583 (!strcasecmp(c->argv[0], Conf[i].name)) ) break;
584 if(!Conf[i].name) return(ARG_UNKNOWN);
585 arg_type = Conf[i].arg_type;
586 if(arg_type == ARG_IGNORED) {
587 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> ignored\n",
588 c->log, Conf[i].name, 0);
591 if(Conf[i].min_args && (c->argc < Conf[i].min_args)) {
592 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> missing <%s> argument\n",
593 c->log, Conf[i].name, Conf[i].what);
594 return(ARG_BAD_CONF);
596 if(Conf[i].max_args && (c->argc > Conf[i].max_args)) {
597 Debug(LDAP_DEBUG_CONFIG, "%s: extra cruft after <%s> in <%s> line (ignored)\n",
598 c->log, Conf[i].what, Conf[i].name);
600 if((arg_type & ARG_DB) && !c->be) {
601 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> allowed only within database declaration\n",
602 c->log, Conf[i].name, 0);
603 return(ARG_BAD_CONF);
605 if((arg_type & ARG_PRE_BI) && c->bi) {
606 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> must appear before any backend %sdeclaration\n",
607 c->log, Conf[i].name, ((arg_type & ARG_PRE_DB)
608 ? "or database " : "") );
609 return(ARG_BAD_CONF);
611 if((arg_type & ARG_PRE_DB) && c->be && c->be != frontendDB) {
612 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> must appear before any database declaration\n",
613 c->log, Conf[i].name, 0);
614 return(ARG_BAD_CONF);
616 if((arg_type & ARG_PAREN) && *c->argv[1] != '(' /*')'*/) {
617 Debug(LDAP_DEBUG_CONFIG, "%s: old <%s> format not supported\n",
618 c->log, Conf[i].name, 0);
619 return(ARG_BAD_CONF);
621 if((arg_type & ARGS_POINTER) && !Conf[i].arg_item) {
622 Debug(LDAP_DEBUG_CONFIG, "%s: null arg_item for <%s>\n",
623 c->log, Conf[i].name, 0);
624 return(ARG_BAD_CONF);
626 c->type = arg_user = (arg_type & ARGS_USERLAND);
627 memset(&c->values, 0, sizeof(c->values));
628 if(arg_type & ARGS_NUMERIC) {
630 iarg = 0; larg = 0; barg = 0;
631 switch(arg_type & ARGS_NUMERIC) {
632 case ARG_INT: iarg = atoi(c->argv[1]); break;
633 case ARG_LONG: larg = atol(c->argv[1]); break;
634 case ARG_BER_LEN_T: barg = (ber_len_t)atol(c->argv[1]); break;
636 if(!strcasecmp(c->argv[1], "on") ||
637 !strcasecmp(c->argv[1], "true")) {
639 } else if(!strcasecmp(c->argv[1], "off") ||
640 !strcasecmp(c->argv[1], "false")) {
643 Debug(LDAP_DEBUG_CONFIG, "%s: ignoring ", c->log, 0, 0);
644 Debug(LDAP_DEBUG_CONFIG, "invalid %s value (%s) in <%s> line\n",
645 Conf[i].what, c->argv[1], Conf[i].name);
650 j = (arg_type & ARG_NONZERO) ? 1 : 0;
651 if(iarg < j || larg < j || barg < j ) {
652 larg = larg ? larg : (barg ? barg : iarg);
653 Debug(LDAP_DEBUG_CONFIG, "%s: " , c->log, 0, 0);
654 Debug(LDAP_DEBUG_CONFIG, "invalid %s value (%ld) in <%s> line\n", Conf[i].what, larg, Conf[i].name);
655 return(ARG_BAD_CONF);
657 switch(arg_type & ARGS_NUMERIC) {
659 case ARG_INT: c->value_int = iarg; break;
660 case ARG_LONG: c->value_long = larg; break;
661 case ARG_BER_LEN_T: c->value_ber_t = barg; break;
663 } else if(arg_type & ARG_STRING) {
664 c->value_string = ch_strdup(c->argv[1]);
665 } else if(arg_type & ARG_DN) {
667 ber_str2bv( c->argv[1], 0, 0, &bv );
668 rc = dnPrettyNormal( NULL, &bv, &c->value_dn, &c->value_ndn, NULL );
669 if ( rc != LDAP_SUCCESS ) {
670 Debug(LDAP_DEBUG_CONFIG, "%s: " , c->log, 0, 0);
671 Debug(LDAP_DEBUG_CONFIG, "%s DN is invalid %d (%s)\n",
672 Conf[i].name, rc, ldap_err2string( rc ));
673 return(ARG_BAD_CONF);
676 if(arg_type & ARG_MAGIC) {
677 if(!c->be) c->be = frontendDB;
678 rc = (*((ConfigDriver*)Conf[i].arg_item))(c);
679 if(c->be == frontendDB) c->be = NULL;
681 Debug(LDAP_DEBUG_CONFIG, "%s: handler for <%s> exited with %d!",
682 c->log, Conf[i].name, rc);
683 return(ARG_BAD_CONF);
687 if(arg_type & ARGS_POINTER) switch(arg_type & ARGS_POINTER) {
689 case ARG_INT: *((int*)Conf[i].arg_item) = iarg; break;
690 case ARG_LONG: *((long*)Conf[i].arg_item) = larg; break;
691 case ARG_BER_LEN_T: *((ber_len_t*)Conf[i].arg_item) = barg; break;
693 char *cc = *((char**)Conf[i].arg_item);
695 if (arg_type & ARG_UNIQUE) {
696 Debug(LDAP_DEBUG_CONFIG, "%s: already set %s!\n",
697 c->log, Conf[i].name, 0 );
698 return(ARG_BAD_CONF);
700 ch_free(cc); /* potential memory leak */
702 *(char **)Conf[i].arg_item = c->value_string;
710 config_get_vals(ConfigTable *cf, ConfigArgs *c)
715 if ( cf->arg_type & ARG_IGNORED ) {
719 memset(&c->values, 0, sizeof(c->values));
720 c->rvalue_vals = NULL;
721 c->rvalue_nvals = NULL;
723 c->type = cf->arg_type & ARGS_USERLAND;
725 if ( cf->arg_type & ARG_MAGIC ) {
726 rc = (*((ConfigDriver*)cf->arg_item))(c);
729 switch(cf->arg_type & ARGS_POINTER) {
731 case ARG_INT: c->value_int = *(int *)cf->arg_item; break;
732 case ARG_LONG: c->value_long = *(long *)cf->arg_item; break;
733 case ARG_BER_LEN_T: c->value_ber_t = *(ber_len_t *)cf->arg_item; break;
735 if ( *(char **)cf->arg_item )
736 c->value_string = ch_strdup(*(char **)cf->arg_item);
740 if ( cf->arg_type & ARGS_POINTER) {
742 switch(cf->arg_type & ARGS_POINTER) {
743 case ARG_INT: bv.bv_len = sprintf(bv.bv_val, "%d", c->value_int); break;
744 case ARG_LONG: bv.bv_len = sprintf(bv.bv_val, "%l", c->value_long); break;
745 case ARG_BER_LEN_T: bv.bv_len =sprintf(bv.bv_val, "%l",c->value_ber_t); break;
746 case ARG_ON_OFF: bv.bv_len = sprintf(bv.bv_val, "%s",
747 c->value_int ? "TRUE" : "FALSE"); break;
749 if ( c->value_string && c->value_string[0]) {
750 ber_str2bv( c->value_string, 0, 0, &bv);
756 if (( cf->arg_type & ARGS_POINTER ) == ARG_STRING )
757 ber_bvarray_add(&c->rvalue_vals, &bv);
759 value_add_one(&c->rvalue_vals, &bv);
765 init_config_attrs(ConfigTable *ct) {
766 LDAPAttributeType *at;
770 for (i=0; ct[i].name; i++ ) {
771 if ( !ct[i].attribute ) continue;
772 at = ldap_str2attributetype( ct[i].attribute,
773 &code, &err, LDAP_SCHEMA_ALLOW_ALL );
775 fprintf( stderr, "init_config_schema: AttributeType \"%s\": %s, %s\n",
776 ct[i].attribute, ldap_scherr2str(code), err );
779 code = at_add( at, &err );
781 fprintf( stderr, "init_config_schema: AttributeType \"%s\": %s, %s\n",
782 ct[i].attribute, scherr2str(code), err );
785 code = slap_str2ad( at->at_names[0], &ct[i].ad, &err );
787 fprintf( stderr, "init_config_schema: AttributeType \"%s\": %s\n",
788 ct[i].attribute, err );
798 read_config(const char *fname, int depth) {
802 /* Schema initialization should normally be part of bi_open */
803 for (i=0; OidMacros[i].name; i++ ) {
804 argv[1] = OidMacros[i].name;
805 argv[2] = OidMacros[i].oid;
806 parse_oidm( "slapd", i, 3, argv );
808 i = init_config_attrs(SystemConfiguration);
810 i = config_back_init( &cf_prv, SystemConfiguration );
812 return read_config_file(fname, depth, NULL);
816 read_config_file(const char *fname, int depth, ConfigArgs *cf)
822 c = ch_calloc( 1, sizeof( ConfigArgs ) );
828 memcpy( c, cf, sizeof( ConfigArgs ) );
830 c->depth = depth; /* XXX */
836 c->argv = ch_calloc( ARGS_STEP + 1, sizeof( *c->argv ) );
837 c->argv_size = ARGS_STEP + 1;
839 fp = fopen( fname, "r" );
842 Debug(LDAP_DEBUG_ANY,
843 "could not open config file \"%s\": %s (%d)\n",
844 fname, strerror(errno), errno);
848 cfn->c_modlast = &cfn->c_modpaths;
850 ber_str2bv( fname, 0, 1, &cfn->c_file );
851 fname = cfn->c_file.bv_val;
853 Debug(LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0);
857 while ( fp_getline( fp, c ) ) {
858 /* skip comments and blank lines */
859 if ( c->line[0] == '#' || c->line[0] == '\0' ) {
863 snprintf( c->log, sizeof( c->log ), "%s: line %lu",
864 c->fname, c->lineno );
866 if ( fp_parse_line( c ) ) {
871 Debug(LDAP_DEBUG_CONFIG, "%s: bad config line (ignored)\n", c->log, 0, 0);
875 rc = parse_config_table( SystemConfiguration, c );
879 if ( rc & ARGS_USERLAND ) {
880 switch(rc) { /* XXX a usertype would be opaque here */
882 Debug(LDAP_DEBUG_CONFIG, "%s: unknown user type <%d>\n",
883 c->log, *c->argv, 0);
887 } else if ( rc == ARG_BAD_CONF || rc != ARG_UNKNOWN ) {
890 } else if ( c->bi && c->bi->bi_config ) { /* XXX to check: could both be/bi_config? oops */
891 rc = (*c->bi->bi_config)(c->bi, c->fname, c->lineno, c->argc, c->argv);
894 case SLAP_CONF_UNKNOWN:
895 Debug(LDAP_DEBUG_CONFIG, "%s: "
896 "unknown directive <%s> inside backend info definition (ignored)\n",
897 c->log, *c->argv, 0);
904 } else if ( c->be && c->be->be_config ) {
905 rc = (*c->be->be_config)(c->be, c->fname, c->lineno, c->argc, c->argv);
908 case SLAP_CONF_UNKNOWN:
909 Debug( LDAP_DEBUG_CONFIG, "%s: "
910 "unknown directive <%s> inside backend database definition (ignored)\n",
911 c->log, *c->argv, 0);
918 } else if ( frontendDB->be_config ) {
919 rc = (*frontendDB->be_config)(frontendDB, c->fname, (int)c->lineno, c->argc, c->argv);
922 case SLAP_CONF_UNKNOWN:
923 Debug( LDAP_DEBUG_CONFIG, "%s: "
924 "unknown directive <%s> inside global database definition (ignored)\n",
925 c->log, *c->argv, 0);
933 Debug(LDAP_DEBUG_CONFIG, "%s: "
934 "unknown directive <%s> outside backend info and database definitions (ignored)\n",
935 c->log, *c->argv, 0);
943 if ( BER_BVISNULL( &frontendDB->be_schemadn ) ) {
944 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
945 &frontendDB->be_schemadn );
946 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
947 if ( rc != LDAP_SUCCESS ) {
948 Debug(LDAP_DEBUG_ANY, "%s: "
949 "unable to normalize default schema DN \"%s\"\n",
950 c->log, frontendDB->be_schemadn.bv_val, 0 );
951 /* must not happen */
968 config_generic(ConfigArgs *c) {
976 c->value_int = ldap_pvt_thread_get_concurrency();
979 c->value_int = connection_pool_max;
983 c->value_string = ch_strdup( passwd_salt );
988 if ( c->be->be_limits ) {
993 for ( i=0; c->be->be_limits[i]; i++ ) {
994 bv.bv_len = sprintf( buf, "{%d}", i );
995 bv.bv_val = buf+bv.bv_len;
996 limits_unparse( c->be->be_limits[i], &bv );
997 bv.bv_len += bv.bv_val - buf;
999 value_add_one( &c->rvalue_vals, &bv );
1002 if ( !c->rvalue_vals ) rc = 1;
1005 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_OP_WRITES) != 0;
1008 c->value_string = ch_strdup( slap_sasl_getpolicy());
1011 slap_sasl_regexp_unparse( &c->rvalue_vals );
1012 if ( !c->rvalue_vals ) rc = 1;
1014 #ifdef HAVE_CYRUS_SASL
1015 case CFG_SASLSECP: {
1016 struct berval bv = BER_BVNULL;
1017 slap_sasl_secprops_unparse( &bv );
1018 if ( !BER_BVISNULL( &bv )) {
1019 ber_bvarray_add( &c->rvalue_vals, &bv );
1027 c->value_int = c->be->be_max_deref_depth;
1030 oidm_unparse( &c->rvalue_vals );
1031 if ( !c->rvalue_vals )
1035 c->value_int = global_schemacheck;
1039 char *src, *dst, ibuf[11];
1040 struct berval bv, abv;
1041 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
1042 abv.bv_len = sprintf( ibuf, "{%x}", i );
1043 acl_unparse( a, &bv );
1044 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
1045 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
1046 /* Turn TAB / EOL into plain space */
1047 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
1048 if (isspace(*src)) *dst++ = ' ';
1052 if (dst[-1] == ' ') {
1056 abv.bv_len = dst - abv.bv_val;
1057 ber_bvarray_add( &c->rvalue_vals, &abv );
1063 if ( c->be->be_replogfile )
1064 c->value_string = ch_strdup( c->be->be_replogfile );
1067 ConfigFile *cf = (ConfigFile *)c->line;
1068 if ( cf->c_dseFiles ) {
1069 value_add( &c->rvalue_vals, cf->c_dseFiles );
1077 c->value_string = ch_strdup( logfileName );
1082 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1084 case CFG_SSTR_IF_MAX:
1085 c->value_int = index_substr_if_maxlen;
1087 case CFG_SSTR_IF_MIN:
1088 c->value_int = index_substr_if_minlen;
1090 #ifdef SLAPD_MODULES
1092 ConfigFile *cf = (ConfigFile *)c->line;
1094 for (i=0, mp=&cf->c_modpaths; mp; mp=mp->mp_next, i++) {
1096 if (!mp->mp_loads) continue;
1097 for (j=0; !BER_BVISNULL(&mp->mp_loads[j]); j++) {
1100 bv.bv_len = sprintf( bv.bv_val, "{%d}{%d}%s", i, j,
1101 mp->mp_loads[j].bv_val );
1102 value_add_one( &c->rvalue_vals, &bv );
1105 rc = c->rvalue_vals ? 0 : 1;
1109 ConfigFile *cf = (ConfigFile *)c->line;
1111 for (i=0, mp=&cf->c_modpaths; mp; mp=mp->mp_next, i++) {
1113 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
1116 bv.bv_len = sprintf( bv.bv_val, "{%d}%s", i,
1117 mp->mp_path.bv_val );
1118 value_add_one( &c->rvalue_vals, &bv );
1120 rc = c->rvalue_vals ? 0 : 1;
1126 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1127 if ( !c->rvalue_vals ) rc = 1;
1130 #ifdef SLAP_AUTH_REWRITE
1132 if ( authz_rewrites ) {
1133 struct berval bv, idx;
1138 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1139 idx.bv_len = sprintf( idx.bv_val, "{%d}", i );
1140 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1141 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1142 strcpy( bv.bv_val, idx.bv_val );
1143 strcpy( bv.bv_val+idx.bv_len, authz_rewrites[i].bv_val );
1144 ber_bvarray_add( &c->rvalue_vals, &bv );
1147 if ( !c->rvalue_vals ) rc = 1;
1156 p = strchr(c->line,'(' /*')'*/);
1159 if(!(c->bi = backend_info(c->argv[1]))) {
1160 Debug(LDAP_DEBUG_ANY, "%s: "
1161 "backend %s failed init!\n", c->log, c->argv[1], 0);
1168 /* NOTE: config is always the first backend!
1170 if ( !strcasecmp( c->argv[1], "config" )) {
1172 } else if(!(c->be = backend_db_init(c->argv[1]))) {
1173 Debug(LDAP_DEBUG_ANY, "%s: "
1174 "database %s failed init!\n", c->log, c->argv[1], 0);
1180 ldap_pvt_thread_set_concurrency(c->value_int);
1184 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1185 connection_pool_max = c->value_int; /* save for reference */
1189 if ( passwd_salt ) ch_free( passwd_salt );
1190 passwd_salt = c->value_string;
1191 lutil_salt_format(passwd_salt);
1195 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1201 c->be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1203 c->be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1207 ch_free(c->value_string);
1208 if (slap_sasl_setpolicy( c->argv[1] )) {
1209 Debug(LDAP_DEBUG_ANY, "%s: unable to parse value \"%s\" in"
1210 " \"authz-policy <policy>\"\n",
1211 c->log, c->argv[1], 0 );
1217 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1221 #ifdef HAVE_CYRUS_SASL
1224 char *txt = slap_sasl_secprops( c->argv[1] );
1226 Debug(LDAP_DEBUG_ANY, "%s: sasl-secprops: %s\n",
1235 c->be->be_max_deref_depth = c->value_int;
1239 if(parse_oidm(c->fname, c->lineno, c->argc, c->argv)) return(1);
1243 if(parse_oc(c->fname, c->lineno, p, c->argv)) return(1);
1247 if(parse_cr(c->fname, c->lineno, p, c->argv)) return(1);
1251 if(parse_at(c->fname, c->lineno, p, c->argv)) return(1);
1255 ad_define_option(NULL, NULL, 0);
1256 for(i = 1; i < c->argc; i++)
1257 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1262 global_schemacheck = c->value_int;
1263 if(!global_schemacheck) Debug(LDAP_DEBUG_ANY, "%s: "
1264 "schema checking disabled! your mileage may vary!\n",
1269 parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv);
1273 if(SLAP_MONITOR(c->be)) {
1274 Debug(LDAP_DEBUG_ANY, "%s: "
1275 "\"replogfile\" should not be used "
1276 "inside monitor database\n",
1278 return(0); /* FIXME: should this be an error? */
1281 c->be->be_replogfile = c->value_string;
1285 if(read_root_dse_file(c->argv[1])) {
1286 Debug(LDAP_DEBUG_ANY, "%s: "
1287 "could not read \"rootDSE <filename>\" line\n",
1293 ber_str2bv( c->argv[1], 0, 1, &bv );
1294 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1300 if ( logfileName ) ch_free( logfileName );
1301 logfileName = c->value_string;
1302 logfile = fopen(logfileName, "w");
1303 if(logfile) lutil_debug_file(logfile);
1307 if(SLAP_NOLASTMODCMD(c->be)) {
1308 Debug(LDAP_DEBUG_ANY, "%s: "
1309 "lastmod not available for %s databases\n",
1310 c->log, c->be->bd_info->bi_type, 0);
1314 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1316 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1319 case CFG_SSTR_IF_MAX:
1320 if (c->value_int < index_substr_if_minlen) {
1321 Debug(LDAP_DEBUG_ANY, "%s: "
1322 "invalid max value (%d)\n",
1323 c->log, c->value_int, 0 );
1326 index_substr_if_maxlen = c->value_int;
1329 case CFG_SSTR_IF_MIN:
1330 if (c->value_int > index_substr_if_maxlen) {
1331 Debug(LDAP_DEBUG_ANY, "%s: "
1332 "invalid min value (%d)\n",
1333 c->log, c->value_int, 0 );
1336 index_substr_if_minlen = c->value_int;
1339 #ifdef SLAPD_MODULES
1341 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1343 /* Record this load on the current path */
1346 ber_str2bv(c->line, 0, 1, &bv);
1347 ber_bvarray_add( &cfn->c_modlast->mp_loads, &bv );
1352 if(module_path(c->argv[1])) return(1);
1353 /* Record which path was used with each module */
1357 if (!cfn->c_modpaths.mp_loads) {
1358 mp = &cfn->c_modpaths;
1360 mp = ch_malloc( sizeof( ModPaths ));
1361 cfn->c_modlast->mp_next = mp;
1363 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1365 mp->mp_loads = NULL;
1366 cfn->c_modlast = mp;
1374 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
1376 slapi_plugins_used++;
1380 #ifdef SLAP_AUTH_REWRITE
1383 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
1385 ber_str2bv( c->line, 0, 1, &bv );
1386 ber_bvarray_add( &authz_rewrites, &bv );
1393 Debug(LDAP_DEBUG_ANY, "%s: unknown CFG_TYPE %d"
1394 "(ignored)\n", c->log, c->type, 0);
1402 config_fname(ConfigArgs *c) {
1403 if(c->emit && c->line) {
1404 ConfigFile *cf = (ConfigFile *)c->line;
1405 value_add_one( &c->rvalue_vals, &cf->c_file );
1412 config_search_base(ConfigArgs *c) {
1417 if (!BER_BVISEMPTY(&default_search_base)) {
1418 value_add_one(&c->rvalue_vals, &default_search_base);
1419 value_add_one(&c->rvalue_nvals, &default_search_nbase);
1425 if(c->bi || c->be != frontendDB) {
1426 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
1427 "prior to any backend or database definition\n",
1432 if(default_search_nbase.bv_len) {
1433 Debug(LDAP_DEBUG_ANY, "%s: "
1434 "default search base \"%s\" already defined "
1435 "(discarding old)\n",
1436 c->log, default_search_base.bv_val, 0);
1437 free(default_search_base.bv_val);
1438 free(default_search_nbase.bv_val);
1441 default_search_base = c->value_dn;
1442 default_search_nbase = c->value_ndn;
1447 config_passwd_hash(ConfigArgs *c) {
1451 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
1452 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
1453 value_add_one(&c->rvalue_vals, &bv);
1457 if(default_passwd_hash) {
1458 Debug(LDAP_DEBUG_ANY, "%s: "
1459 "already set default password_hash\n",
1463 for(i = 1; i < c->argc; i++) {
1464 if(!lutil_passwd_scheme(c->argv[i])) {
1465 Debug(LDAP_DEBUG_ANY, "%s: "
1466 "password scheme \"%s\" not available\n",
1467 c->log, c->argv[i], 0);
1469 ldap_charray_add(&default_passwd_hash, c->argv[i]);
1471 if(!default_passwd_hash) {
1472 Debug(LDAP_DEBUG_ANY, "%s: no valid hashes found\n",
1481 config_schema_dn(ConfigArgs *c) {
1485 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
1486 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
1489 c->be->be_schemadn = c->value_dn;
1490 c->be->be_schemandn = c->value_ndn;
1495 config_sizelimit(ConfigArgs *c) {
1498 struct slap_limits_set *lim = &c->be->be_def_limit;
1504 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv );
1505 if ( !BER_BVISEMPTY( &bv ))
1506 value_add_one( &c->rvalue_vals, &bv );
1511 for(i = 1; i < c->argc; i++) {
1512 if(!strncasecmp(c->argv[i], "size", 4)) {
1513 rc = limits_parse_one(c->argv[i], lim);
1515 Debug(LDAP_DEBUG_ANY, "%s: "
1516 "unable to parse value \"%s\" in \"sizelimit <limit>\" line\n",
1517 c->log, c->argv[i], 0);
1521 if(!strcasecmp(c->argv[i], "unlimited")) {
1522 lim->lms_s_soft = -1;
1524 lim->lms_s_soft = strtol(c->argv[i], &next, 0);
1525 if(next == c->argv[i]) {
1526 Debug(LDAP_DEBUG_ANY, "%s: "
1527 "unable to parse limit \"%s\" in \"sizelimit <limit>\" line\n",
1528 c->log, c->argv[i], 0);
1530 } else if(next[0] != '\0') {
1531 Debug(LDAP_DEBUG_ANY, "%s: "
1532 "trailing chars \"%s\" in \"sizelimit <limit>\" line (ignored)\n",
1536 lim->lms_s_hard = 0;
1543 config_timelimit(ConfigArgs *c) {
1546 struct slap_limits_set *lim = &c->be->be_def_limit;
1552 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv );
1553 if ( !BER_BVISEMPTY( &bv ))
1554 value_add_one( &c->rvalue_vals, &bv );
1559 for(i = 1; i < c->argc; i++) {
1560 if(!strncasecmp(c->argv[i], "time", 4)) {
1561 rc = limits_parse_one(c->argv[i], lim);
1563 Debug(LDAP_DEBUG_ANY, "%s: "
1564 "unable to parse value \"%s\" in \"timelimit <limit>\" line\n",
1565 c->log, c->argv[i], 0);
1569 if(!strcasecmp(c->argv[i], "unlimited")) {
1570 lim->lms_t_soft = -1;
1572 lim->lms_t_soft = strtol(c->argv[i], &next, 0);
1573 if(next == c->argv[i]) {
1574 Debug(LDAP_DEBUG_ANY, "%s: "
1575 "unable to parse limit \"%s\" in \"timelimit <limit>\" line\n",
1576 c->log, c->argv[i], 0);
1578 } else if(next[0] != '\0') {
1579 Debug(LDAP_DEBUG_ANY, "%s: "
1580 "trailing chars \"%s\" in \"timelimit <limit>\" line (ignored)\n",
1584 lim->lms_t_hard = 0;
1591 config_overlay(ConfigArgs *c) {
1595 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1])) {
1597 Debug(LDAP_DEBUG_ANY, "%s: (optional) %s overlay \"%s\" configuration failed (ignored)\n",
1598 c->log, c->be == frontendDB ? "global " : "", c->argv[1][1]);
1599 } else if(overlay_config(c->be, c->argv[1])) {
1606 config_suffix(ConfigArgs *c) {
1608 struct berval pdn, ndn;
1611 if ( !BER_BVISNULL( &c->be->be_suffix[0] )) {
1612 value_add( &c->rvalue_vals, c->be->be_suffix );
1613 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
1619 #ifdef SLAPD_MONITOR_DN
1620 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
1621 Debug(LDAP_DEBUG_ANY, "%s: "
1622 "\"%s\" is reserved for monitoring slapd\n",
1623 c->log, SLAPD_MONITOR_DN, 0);
1630 tbe = select_backend(&ndn, 0, 0);
1632 Debug(LDAP_DEBUG_ANY, "%s: suffix already served by this backend! (ignored)\n",
1637 Debug(LDAP_DEBUG_ANY, "%s: suffix already served by a preceding backend \"%s\"\n",
1638 c->log, tbe->be_suffix[0].bv_val, 0);
1642 } else if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
1643 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
1644 "base provided \"%s\" (assuming okay)\n",
1645 c->log, default_search_base.bv_val, 0);
1647 ber_bvarray_add(&c->be->be_suffix, &pdn);
1648 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
1653 config_rootdn(ConfigArgs *c) {
1655 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
1656 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
1657 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
1663 c->be->be_rootdn = c->value_dn;
1664 c->be->be_rootndn = c->value_ndn;
1669 config_rootpw(ConfigArgs *c) {
1672 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
1673 c->value_string=ch_strdup("*");
1679 tbe = select_backend(&c->be->be_rootndn, 0, 0);
1681 Debug(LDAP_DEBUG_ANY, "%s: "
1682 "rootpw can only be set when rootdn is under suffix\n",
1686 ber_str2bv(c->value_string, 0, 0, &c->be->be_rootpw);
1690 /* restrictops, allows, disallows, requires, loglevel */
1692 struct verb_mask_list { char *word; int mask; };
1695 verb_to_mask(ConfigArgs *c, struct verb_mask_list *v, int word) {
1697 for(j = 0; v[j].word; j++)
1698 if(!strcasecmp(c->argv[word], v[j].word))
1704 verbs_to_mask(ConfigArgs *c, struct verb_mask_list *v, slap_mask_t *m) {
1706 for(i = 1; i < c->argc; i++) {
1707 j = verb_to_mask(c, v, i);
1708 if(!v[j].word) return(1);
1709 while (!v[j].mask) j--;
1716 mask_to_verbs(ConfigArgs *c, struct verb_mask_list *v, slap_mask_t m) {
1721 for (i=0; v[i].word; i++) {
1722 if (!v[i].mask) continue;
1723 if (( m & v[i].mask ) == v[i].mask ) {
1724 ber_str2bv( v[i].word, 0, 0, &bv );
1725 value_add_one( &c->rvalue_vals, &bv );
1732 config_restrict(ConfigArgs *c) {
1733 slap_mask_t restrictops = 0;
1735 struct verb_mask_list restrictable_ops[] = {
1736 { "bind", SLAP_RESTRICT_OP_BIND },
1737 { "add", SLAP_RESTRICT_OP_ADD },
1738 { "modify", SLAP_RESTRICT_OP_MODIFY },
1739 { "rename", SLAP_RESTRICT_OP_RENAME },
1741 { "delete", SLAP_RESTRICT_OP_DELETE },
1742 { "search", SLAP_RESTRICT_OP_SEARCH },
1743 { "compare", SLAP_RESTRICT_OP_COMPARE },
1744 { "read", SLAP_RESTRICT_OP_READS },
1745 { "write", SLAP_RESTRICT_OP_WRITES },
1746 { "extended", SLAP_RESTRICT_OP_EXTENDED },
1747 { "extended=" LDAP_EXOP_START_TLS, SLAP_RESTRICT_EXOP_START_TLS },
1748 { "extended=" LDAP_EXOP_MODIFY_PASSWD, SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
1749 { "extended=" LDAP_EXOP_X_WHO_AM_I, SLAP_RESTRICT_EXOP_WHOAMI },
1750 { "extended=" LDAP_EXOP_X_CANCEL, SLAP_RESTRICT_EXOP_CANCEL },
1755 return mask_to_verbs( c, restrictable_ops, c->be->be_restrictops );
1757 i = verbs_to_mask( c, restrictable_ops, &restrictops );
1759 Debug(LDAP_DEBUG_ANY, "%s: "
1760 "unknown operation %s in \"restrict <features>\" line\n",
1761 c->log, c->argv[i], 0);
1764 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
1765 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
1766 c->be->be_restrictops |= restrictops;
1771 config_allows(ConfigArgs *c) {
1772 slap_mask_t allows = 0;
1774 struct verb_mask_list allowable_ops[] = {
1775 { "bind_v2", SLAP_ALLOW_BIND_V2 },
1776 { "bind_anon_cred", SLAP_ALLOW_BIND_ANON_CRED },
1777 { "bind_anon_dn", SLAP_ALLOW_BIND_ANON_DN },
1778 { "update_anon", SLAP_ALLOW_UPDATE_ANON },
1782 return mask_to_verbs( c, allowable_ops, global_allows );
1784 i = verbs_to_mask(c, allowable_ops, &allows);
1786 Debug(LDAP_DEBUG_ANY, "%s: "
1787 "unknown feature %s in \"allow <features>\" line\n",
1788 c->log, c->argv[i], 0);
1791 global_allows |= allows;
1796 config_disallows(ConfigArgs *c) {
1797 slap_mask_t disallows = 0;
1799 struct verb_mask_list disallowable_ops[] = {
1800 { "bind_anon", SLAP_DISALLOW_BIND_ANON },
1801 { "bind_simple", SLAP_DISALLOW_BIND_SIMPLE },
1802 { "bind_krb4", SLAP_DISALLOW_BIND_KRBV4 },
1803 { "tls_2_anon", SLAP_DISALLOW_TLS_2_ANON },
1804 { "tls_authc", SLAP_DISALLOW_TLS_AUTHC },
1808 return mask_to_verbs( c, disallowable_ops, global_disallows );
1810 i = verbs_to_mask(c, disallowable_ops, &disallows);
1812 Debug(LDAP_DEBUG_ANY, "%s: "
1813 "unknown feature %s in \"disallow <features>\" line\n",
1814 c->log, c->argv[i], 0);
1817 global_disallows |= disallows;
1822 config_requires(ConfigArgs *c) {
1823 slap_mask_t requires = 0;
1825 struct verb_mask_list requires_ops[] = {
1826 { "bind", SLAP_REQUIRE_BIND },
1827 { "LDAPv3", SLAP_REQUIRE_LDAP_V3 },
1828 { "authc", SLAP_REQUIRE_AUTHC },
1829 { "sasl", SLAP_REQUIRE_SASL },
1830 { "strong", SLAP_REQUIRE_STRONG },
1834 return mask_to_verbs( c, requires_ops, c->be->be_requires );
1836 i = verbs_to_mask(c, requires_ops, &requires);
1838 Debug(LDAP_DEBUG_ANY, "%s: "
1839 "unknown feature %s in \"require <features>\" line\n",
1840 c->log, c->argv[i], 0);
1843 c->be->be_requires = requires;
1848 config_loglevel(ConfigArgs *c) {
1851 struct verb_mask_list loglevel_ops[] = {
1852 { "Trace", LDAP_DEBUG_TRACE },
1853 { "Packets", LDAP_DEBUG_PACKETS },
1854 { "Args", LDAP_DEBUG_ARGS },
1855 { "Conns", LDAP_DEBUG_CONNS },
1856 { "BER", LDAP_DEBUG_BER },
1857 { "Filter", LDAP_DEBUG_FILTER },
1858 { "Config", LDAP_DEBUG_CONFIG },
1859 { "ACL", LDAP_DEBUG_ACL },
1860 { "Stats", LDAP_DEBUG_STATS },
1861 { "Stats2", LDAP_DEBUG_STATS2 },
1862 { "Shell", LDAP_DEBUG_SHELL },
1863 { "Parse", LDAP_DEBUG_PARSE },
1864 { "Cache", LDAP_DEBUG_CACHE },
1865 { "Index", LDAP_DEBUG_INDEX },
1871 return mask_to_verbs( c, loglevel_ops, ldap_syslog );
1876 for( i=1; i < c->argc; i++ ) {
1879 if ( isdigit( c->argv[i][0] ) ) {
1880 level = strtol( c->argv[i], &next, 10 );
1881 if ( next == NULL || next[0] != '\0' ) {
1882 Debug( LDAP_DEBUG_ANY,
1883 "%s: unable to parse level \"%s\" "
1884 "in \"loglevel <level> [...]\" line.\n",
1885 c->log, c->argv[i], 0);
1889 int j = verb_to_mask(c, loglevel_ops, c->argv[i][0]);
1890 if(!loglevel_ops[j].word) {
1891 Debug( LDAP_DEBUG_ANY,
1892 "%s: unknown level \"%s\" "
1893 "in \"loglevel <level> [...]\" line.\n",
1894 c->log, c->argv[i], 0);
1897 level = loglevel_ops[j].mask;
1899 ldap_syslog |= level;
1905 config_syncrepl(ConfigArgs *c) {
1907 if ( c->be->be_syncinfo ) {
1909 syncrepl_unparse( c->be->be_syncinfo, &bv );
1910 ber_bvarray_add( &c->rvalue_vals, &bv );
1915 if(SLAP_SHADOW(c->be)) {
1916 Debug(LDAP_DEBUG_ANY, "%s: "
1917 "syncrepl: database already shadowed.\n",
1920 } else if(add_syncrepl(c->be, c->argv, c->argc)) {
1923 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SYNC_SHADOW);
1928 config_referral(ConfigArgs *c) {
1929 struct berval vals[2];
1931 if ( default_referral ) {
1932 value_add( &c->rvalue_vals, default_referral );
1938 if(validate_global_referral(c->argv[1])) {
1939 Debug(LDAP_DEBUG_ANY, "%s: "
1940 "invalid URL (%s) in \"referral\" line.\n",
1941 c->log, c->argv[1], 0);
1945 ber_str2bv(c->argv[1], 0, 0, &vals[0]);
1946 vals[1].bv_val = NULL; vals[1].bv_len = 0;
1947 if(value_add(&default_referral, vals)) return(LDAP_OTHER);
1955 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
1956 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
1957 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
1958 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
1959 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
1960 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
1961 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
1962 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
1963 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
1968 config_security(ConfigArgs *c) {
1969 slap_ssf_set_t *set = &c->be->be_ssf_set;
1978 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
1979 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
1982 bv.bv_len = sprintf( numbuf, "%u", *tgt );
1983 bv.bv_len += sec_keys[i].key.bv_len;
1984 bv.bv_val = ch_malloc( bv.bv_len + 1);
1985 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
1986 strcpy( next, numbuf );
1987 ber_bvarray_add( &c->rvalue_vals, &bv );
1992 for(i = 1; i < c->argc; i++) {
1993 slap_ssf_t *tgt = NULL;
1995 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
1996 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
1997 sec_keys[j].key.bv_len)) {
1998 src = c->argv[i] + sec_keys[j].key.bv_len;
1999 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
2004 Debug(LDAP_DEBUG_ANY, "%s: "
2005 "unknown factor %s in \"security <factors>\" line\n",
2006 c->log, c->argv[i], 0);
2010 *tgt = strtol(src, &next, 10);
2011 if(next == NULL || next[0] != '\0' ) {
2012 Debug(LDAP_DEBUG_ANY, "%s: "
2013 "unable to parse factor \"%s\" in \"security <factors>\" line\n",
2014 c->log, c->argv[i], 0);
2021 static struct verb_mask_list tlskey[] = {
2022 { "no", SB_TLS_OFF },
2023 { "yes", SB_TLS_ON },
2024 { "critical", SB_TLS_CRITICAL }
2027 static struct verb_mask_list methkey[] = {
2028 { "simple", LDAP_AUTH_SIMPLE },
2029 #ifdef HAVE_CYRUS_SASL
2030 { "sasl", LDAP_AUTH_SASL },
2035 typedef struct cf_aux_table {
2039 struct verb_mask_list *aux;
2042 static cf_aux_table bindkey[] = {
2043 { BER_BVC("starttls="), offsetof(slap_bindconf, sb_tls), 0, tlskey },
2044 { BER_BVC("bindmethod="), offsetof(slap_bindconf, sb_method), 0, methkey },
2045 { BER_BVC("binddn="), offsetof(slap_bindconf, sb_binddn), 1, NULL },
2046 { BER_BVC("credentials="), offsetof(slap_bindconf, sb_cred), 1, NULL },
2047 { BER_BVC("saslmech="), offsetof(slap_bindconf, sb_saslmech), 0, NULL },
2048 { BER_BVC("secprops="), offsetof(slap_bindconf, sb_secprops), 0, NULL },
2049 { BER_BVC("realm="), offsetof(slap_bindconf, sb_realm), 0, NULL },
2050 { BER_BVC("authcID="), offsetof(slap_bindconf, sb_authcId), 0, NULL },
2051 { BER_BVC("authzID="), offsetof(slap_bindconf, sb_authzId), 1, NULL },
2052 { BER_BVNULL, 0, 0, NULL }
2055 int bindconf_parse( char *word, slap_bindconf *bc ) {
2060 for (tab = bindkey; !BER_BVISNULL(&tab->key); tab++) {
2061 if ( !strncasecmp( word, tab->key.bv_val, tab->key.bv_len )) {
2062 cptr = (char **)((char *)bc + tab->off);
2066 for (j=0; tab->aux[j].word; j++) {
2067 if (!strcasecmp(word+tab->key.bv_len, tab->aux[j].word)) {
2068 int *ptr = (int *)cptr;
2069 *ptr = tab->aux[j].mask;
2074 Debug(LDAP_DEBUG_ANY, "invalid bind config value %s\n",
2079 *cptr = ch_strdup(word+tab->key.bv_len);
2086 int bindconf_unparse( slap_bindconf *bc, struct berval *bv ) {
2087 char buf[BUFSIZ], *ptr;
2093 for (tab = bindkey; !BER_BVISNULL(&tab->key); tab++) {
2094 cptr = (char **)((char *)bc + tab->off);
2096 int *ip = (int *)cptr, i;
2097 for ( i=0; tab->aux[i].word; i++ ) {
2098 if ( *ip == tab->aux[i].mask ) {
2100 ptr = lutil_strcopy( ptr, tab->key.bv_val );
2101 ptr = lutil_strcopy( ptr, tab->aux[i].word );
2105 } else if ( *cptr ) {
2107 ptr = lutil_strcopy( ptr, tab->key.bv_val );
2108 if ( tab->quote ) *ptr++ = '"';
2109 ptr = lutil_strcopy( ptr, *cptr );
2110 if ( tab->quote ) *ptr++ = '"';
2114 tmp.bv_len = ptr - buf;
2115 ber_dupbv( bv, &tmp );
2119 void bindconf_free( slap_bindconf *bc ) {
2120 if ( bc->sb_binddn ) {
2121 ch_free( bc->sb_binddn );
2123 if ( bc->sb_cred ) {
2124 ch_free( bc->sb_cred );
2126 if ( bc->sb_saslmech ) {
2127 ch_free( bc->sb_saslmech );
2129 if ( bc->sb_secprops ) {
2130 ch_free( bc->sb_secprops );
2132 if ( bc->sb_realm ) {
2133 ch_free( bc->sb_realm );
2135 if ( bc->sb_authcId ) {
2136 ch_free( bc->sb_authcId );
2138 if ( bc->sb_authzId ) {
2139 ch_free( bc->sb_authzId );
2144 anlist_unparse( AttributeName *an, char *ptr ) {
2147 for (; !BER_BVISNULL( &an->an_name ); an++) {
2148 if ( comma ) *ptr++ = ',';
2149 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
2156 replica_unparse( struct slap_replica_info *ri, int i, struct berval *bv )
2160 struct berval bc = {0};
2163 len = sprintf(numbuf, "{%d}", i );
2165 len += strlen( ri->ri_uri ) + STRLENOF("uri=");
2166 if ( ri->ri_nsuffix ) {
2167 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
2168 len += ri->ri_nsuffix[i].bv_len + STRLENOF(" suffix=\"\"");
2171 if ( ri->ri_attrs ) {
2172 len += STRLENOF("attr");
2173 if ( ri->ri_exclude ) len++;
2174 for (i=0; !BER_BVISNULL( &ri->ri_attrs[i].an_name ); i++) {
2175 len += 1 + ri->ri_attrs[i].an_name.bv_len;
2178 bindconf_unparse( &ri->ri_bindconf, &bc );
2181 bv->bv_val = ch_malloc(len + 1);
2184 ptr = lutil_strcopy( bv->bv_val, numbuf );
2185 ptr = lutil_strcopy( ptr, "uri=" );
2186 ptr = lutil_strcopy( ptr, ri->ri_uri );
2188 if ( ri->ri_nsuffix ) {
2189 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
2190 ptr = lutil_strcopy( ptr, " suffix=\"" );
2191 ptr = lutil_strcopy( ptr, ri->ri_nsuffix[i].bv_val );
2195 if ( ri->ri_attrs ) {
2196 ptr = lutil_strcopy( ptr, "attr" );
2197 if ( ri->ri_exclude ) *ptr++ = '!';
2199 ptr = anlist_unparse( ri->ri_attrs, ptr );
2202 strcpy( ptr, bc.bv_val );
2203 ch_free( bc.bv_val );
2208 config_replica(ConfigArgs *c) {
2209 int i, nr = -1, len;
2210 char *replicahost, *replicauri;
2214 if (c->be->be_replica) {
2216 for (i=0;c->be->be_replica[i]; i++) {
2217 replica_unparse( c->be->be_replica[i], i, &bv );
2218 ber_bvarray_add( &c->rvalue_vals, &bv );
2224 if(SLAP_MONITOR(c->be)) {
2225 Debug(LDAP_DEBUG_ANY, "%s: "
2226 "\"replica\" should not be used inside monitor database\n",
2228 return(0); /* FIXME: should this be an error? */
2231 for(i = 1; i < c->argc; i++) {
2232 if(!strncasecmp(c->argv[i], "host=", STRLENOF("host="))) {
2233 replicahost = c->argv[i] + STRLENOF("host=");
2234 len = strlen( replicahost );
2235 replicauri = ch_malloc( len + STRLENOF("ldap://") + 1 );
2236 sprintf( replicauri, "ldap://%s", replicahost );
2237 replicahost = replicauri + STRLENOF( "ldap://");
2238 nr = add_replica_info(c->be, replicauri, replicahost);
2240 } else if(!strncasecmp(c->argv[i], "uri=", STRLENOF("uri="))) {
2241 if(ldap_url_parse(c->argv[i] + STRLENOF("uri="), &ludp) != LDAP_SUCCESS) {
2242 Debug(LDAP_DEBUG_ANY, "%s: "
2243 "replica line contains invalid "
2244 "uri definition.\n", c->log, 0, 0);
2247 if(!ludp->lud_host) {
2248 Debug(LDAP_DEBUG_ANY, "%s: "
2249 "replica line contains invalid "
2250 "uri definition - missing hostname.\n",
2254 ldap_free_urldesc(ludp);
2255 replicauri = c->argv[i] + STRLENOF("uri=");
2256 replicauri = ch_strdup( replicauri );
2257 replicahost = strchr( replicauri, '/' );
2259 nr = add_replica_info(c->be, replicauri, replicahost);
2264 Debug(LDAP_DEBUG_ANY, "%s: "
2265 "missing host or uri in \"replica\" line\n",
2268 } else if(nr == -1) {
2269 Debug(LDAP_DEBUG_ANY, "%s: "
2270 "unable to add replica \"%s\"\n",
2271 c->log, replicauri, 0);
2274 for(i = 1; i < c->argc; i++) {
2275 if(!strncasecmp(c->argv[i], "suffix=", STRLENOF( "suffix="))) {
2276 switch(add_replica_suffix(c->be, nr, c->argv[i] + STRLENOF("suffix="))) {
2278 Debug(LDAP_DEBUG_ANY, "%s: "
2279 "suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
2280 c->log, c->argv[i] + STRLENOF("suffix="), 0);
2283 Debug(LDAP_DEBUG_ANY, "%s: "
2284 "unable to normalize suffix in \"replica\" line (ignored)\n",
2289 } else if(!strncasecmp(c->argv[i], "attr", STRLENOF("attr"))) {
2291 char *arg = c->argv[i] + STRLENOF("attr");
2299 if(add_replica_attrs(c->be, nr, arg + 1, exclude)) {
2300 Debug(LDAP_DEBUG_ANY, "%s: "
2301 "attribute \"%s\" in \"replica\" line is unknown\n",
2302 c->log, arg + 1, 0);
2305 } else if ( bindconf_parse( c->argv[i],
2306 &c->be->be_replica[nr]->ri_bindconf ) ) {
2315 config_updatedn(ConfigArgs *c) {
2319 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
2320 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
2321 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
2326 if(SLAP_SHADOW(c->be)) {
2327 Debug(LDAP_DEBUG_ANY, "%s: "
2328 "updatedn: database already shadowed.\n",
2333 ber_str2bv(c->argv[1], 0, 0, &dn);
2335 rc = dnNormalize(0, NULL, NULL, &dn, &c->be->be_update_ndn, NULL);
2337 if(rc != LDAP_SUCCESS) {
2338 Debug(LDAP_DEBUG_ANY, "%s: "
2339 "updatedn DN is invalid: %d (%s)\n",
2340 c->log, rc, ldap_err2string( rc ));
2344 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
2349 config_updateref(ConfigArgs *c) {
2350 struct berval vals[2];
2352 if ( c->be->be_update_refs ) {
2353 value_add( &c->rvalue_vals, c->be->be_update_refs );
2359 if(!SLAP_SHADOW(c->be)) {
2360 Debug(LDAP_DEBUG_ANY, "%s: "
2361 "updateref line must come after syncrepl or updatedn.\n",
2366 if(validate_global_referral(c->argv[1])) {
2367 Debug(LDAP_DEBUG_ANY, "%s: "
2368 "invalid URL (%s) in \"updateref\" line.\n",
2369 c->log, c->argv[1], 0);
2372 ber_str2bv(c->argv[1], 0, 0, &vals[0]);
2373 vals[1].bv_val = NULL;
2374 if(value_add(&c->be->be_update_refs, vals)) return(LDAP_OTHER);
2379 config_include(ConfigArgs *c) {
2380 unsigned long savelineno = c->lineno;
2383 ConfigFile *cfsave = cfn;
2384 ConfigFile *cf2 = NULL;
2388 cf = ch_calloc( 1, sizeof(ConfigFile));
2389 if ( cfn->c_kids ) {
2390 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
2396 rc = read_config_file(c->argv[1], c->depth + 1, c);
2397 c->lineno = savelineno - 1;
2400 if ( cf2 ) cf2->c_sibs = NULL;
2401 else cfn->c_kids = NULL;
2409 config_tls_option(ConfigArgs *c) {
2412 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; break;
2413 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
2414 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
2415 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
2416 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
2417 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
2418 default: Debug(LDAP_DEBUG_ANY, "%s: "
2419 "unknown tls_option <%x>\n",
2420 c->log, c->type, 0);
2423 return ldap_pvt_tls_get_option( NULL, flag, &c->value_string );
2425 ch_free(c->value_string);
2426 return(ldap_pvt_tls_set_option(NULL, flag, c->argv[1]));
2429 /* FIXME: this ought to be provided by libldap */
2431 config_tls_config(ConfigArgs *c) {
2433 struct verb_mask_list crlkeys[] = {
2434 { "none", LDAP_OPT_X_TLS_CRL_NONE },
2435 { "peer", LDAP_OPT_X_TLS_CRL_PEER },
2436 { "all", LDAP_OPT_X_TLS_CRL_ALL },
2439 struct verb_mask_list vfykeys[] = {
2440 { "never", LDAP_OPT_X_TLS_NEVER },
2441 { "demand", LDAP_OPT_X_TLS_DEMAND },
2442 { "try", LDAP_OPT_X_TLS_TRY },
2443 { "hard", LDAP_OPT_X_TLS_HARD },
2447 #ifdef HAVE_OPENSSL_CRL
2448 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; keys = crlkeys;
2451 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; keys = vfykeys;
2453 default: Debug(LDAP_DEBUG_ANY, "%s: "
2454 "unknown tls_option <%x>\n",
2455 c->log, c->type, 0);
2458 ldap_pvt_tls_get_option( NULL, flag, &c->value_int );
2459 for (i=0; keys[i].word; i++) {
2460 if (keys[i].mask == c->value_int) {
2461 c->value_string = ch_strdup( keys[i].word );
2467 ch_free( c->value_string );
2468 if(isdigit((unsigned char)c->argv[1][0])) {
2469 i = atoi(c->argv[1]);
2470 return(ldap_pvt_tls_set_option(NULL, flag, &i));
2472 return(ldap_int_tls_config(NULL, flag, c->argv[1]));
2477 /* -------------------------------------- */
2481 strtok_quote( char *line, char *sep )
2487 strtok_quote_ptr = NULL;
2488 if ( line != NULL ) {
2491 while ( *next && strchr( sep, *next ) ) {
2495 if ( *next == '\0' ) {
2501 for ( inquote = 0; *next; ) {
2509 AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
2515 next + 1, strlen( next + 1 ) + 1 );
2516 next++; /* dont parse the escaped character */
2521 if ( strchr( sep, *next ) != NULL ) {
2522 strtok_quote_ptr = next;
2535 static char buf[BUFSIZ];
2537 static size_t lmax, lcur;
2539 #define CATLINE( buf ) \
2541 size_t len = strlen( buf ); \
2542 while ( lcur + len + 1 > lmax ) { \
2544 line = (char *) ch_realloc( line, lmax ); \
2546 strcpy( line + lcur, buf ); \
2551 fp_getline_init(ConfigArgs *c) {
2557 fp_getline( FILE *fp, ConfigArgs *c )
2565 /* avoid stack of bufs */
2566 if ( strncasecmp( line, "include", STRLENOF( "include" ) ) == 0 ) {
2572 while ( fgets( buf, sizeof( buf ), fp ) ) {
2573 p = strchr( buf, '\n' );
2575 if ( p > buf && p[-1] == '\r' ) {
2583 && ( p = line + strlen( line ) - 1 )[0] == '\\'
2590 if ( !isspace( (unsigned char)buf[0] ) ) {
2601 return(line[0] ? 1 : 0);
2605 fp_parse_line(ConfigArgs *c)
2608 char *tline = ch_strdup(c->line);
2609 char *hide[] = { "rootpw", "replica", "bindpw", "pseudorootpw", "dbpasswd", '\0' };
2613 token = strtok_quote(tline, " \t");
2615 if(token) for(i = 0; hide[i]; i++) if(!strcasecmp(token, hide[i])) break;
2616 if(strtok_quote_ptr) *strtok_quote_ptr = ' ';
2617 Debug(LDAP_DEBUG_CONFIG, "line %lu (%s%s)\n", c->lineno, hide[i] ? hide[i] : c->line, hide[i] ? " ***" : "");
2618 if(strtok_quote_ptr) *strtok_quote_ptr = '\0';
2620 for(; token; token = strtok_quote(NULL, " \t")) {
2621 if(c->argc == c->argv_size - 1) {
2623 tmp = ch_realloc(c->argv, (c->argv_size + ARGS_STEP) * sizeof(*c->argv));
2625 Debug(LDAP_DEBUG_ANY, "line %lu: out of memory\n", c->lineno, 0, 0);
2629 c->argv_size += ARGS_STEP;
2631 c->argv[c->argc++] = token;
2633 c->argv[c->argc] = NULL;
2640 ucdata_unload( UCDATA_ALL );
2642 /* NOTE: in case of early exit, frontendDB can be NULL */
2643 if ( frontendDB->be_schemandn.bv_val )
2644 free( frontendDB->be_schemandn.bv_val );
2645 if ( frontendDB->be_schemadn.bv_val )
2646 free( frontendDB->be_schemadn.bv_val );
2647 if ( frontendDB->be_acl )
2648 acl_destroy( frontendDB->be_acl, NULL );
2651 if ( slapd_args_file )
2652 free ( slapd_args_file );
2653 if ( slapd_pid_file )
2654 free ( slapd_pid_file );
2655 if ( default_passwd_hash )
2656 ldap_charray_free( default_passwd_hash );
2669 si = (syncinfo_t *) ch_calloc( 1, sizeof( syncinfo_t ) );
2672 Debug( LDAP_DEBUG_ANY, "out of memory in add_syncrepl\n", 0, 0, 0 );
2676 si->si_bindconf.sb_tls = SB_TLS_OFF;
2677 si->si_bindconf.sb_method = LDAP_AUTH_SIMPLE;
2678 si->si_schemachecking = 0;
2679 ber_str2bv( "(objectclass=*)", STRLENOF("(objectclass=*)"), 1,
2680 &si->si_filterstr );
2681 si->si_base.bv_val = NULL;
2682 si->si_scope = LDAP_SCOPE_SUBTREE;
2683 si->si_attrsonly = 0;
2684 si->si_anlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ));
2685 si->si_exanlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ));
2686 si->si_attrs = NULL;
2687 si->si_allattrs = 0;
2688 si->si_allopattrs = 0;
2689 si->si_exattrs = NULL;
2690 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2691 si->si_interval = 86400;
2692 si->si_retryinterval = NULL;
2693 si->si_retrynum_init = NULL;
2694 si->si_retrynum = NULL;
2695 si->si_manageDSAit = 0;
2699 si->si_presentlist = NULL;
2700 LDAP_LIST_INIT( &si->si_nonpresentlist );
2701 ldap_pvt_thread_mutex_init( &si->si_mutex );
2703 rc = parse_syncrepl_line( cargv, cargc, si );
2706 Debug( LDAP_DEBUG_ANY, "failed to add syncinfo\n", 0, 0, 0 );
2707 syncinfo_free( si );
2710 Debug( LDAP_DEBUG_CONFIG,
2711 "Config: ** successfully added syncrepl \"%s\"\n",
2712 BER_BVISNULL( &si->si_provideruri ) ?
2713 "(null)" : si->si_provideruri.bv_val, 0, 0 );
2714 if ( !si->si_schemachecking ) {
2715 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NO_SCHEMA_CHECK;
2718 be->be_syncinfo = si;
2723 /* NOTE: used & documented in slapd.conf(5) */
2725 #define PROVIDERSTR "provider"
2726 #define TYPESTR "type"
2727 #define INTERVALSTR "interval"
2728 #define SEARCHBASESTR "searchbase"
2729 #define FILTERSTR "filter"
2730 #define SCOPESTR "scope"
2731 #define ATTRSSTR "attrs"
2732 #define ATTRSONLYSTR "attrsonly"
2733 #define SLIMITSTR "sizelimit"
2734 #define TLIMITSTR "timelimit"
2735 #define SCHEMASTR "schemachecking"
2737 /* FIXME: undocumented */
2738 #define OLDAUTHCSTR "bindprincipal"
2739 #define EXATTRSSTR "exattrs"
2740 #define RETRYSTR "retry"
2743 #define LASTMODSTR "lastmod"
2744 #define LMGENSTR "gen"
2745 #define LMNOSTR "no"
2746 #define LMREQSTR "req"
2747 #define SRVTABSTR "srvtab"
2748 #define SUFFIXSTR "suffix"
2749 #define MANAGEDSAITSTR "manageDSAit"
2752 #define GOT_ID 0x0001
2753 #define GOT_PROVIDER 0x0002
2756 #define GOT_ALL (GOT_ID|GOT_PROVIDER)
2762 { BER_BVC("base"), LDAP_SCOPE_BASE },
2763 { BER_BVC("one"), LDAP_SCOPE_ONELEVEL },
2764 #ifdef LDAP_SCOPE_SUBORDINATE
2765 { BER_BVC("children"), LDAP_SCOPE_SUBORDINATE },
2766 { BER_BVC("subordinate"), 0 },
2768 { BER_BVC("sub"), LDAP_SCOPE_SUBTREE },
2773 parse_syncrepl_line(
2783 for ( i = 1; i < cargc; i++ ) {
2784 if ( !strncasecmp( cargv[ i ], IDSTR "=",
2785 STRLENOF( IDSTR "=" ) ) )
2788 /* '\0' string terminator accounts for '=' */
2789 val = cargv[ i ] + STRLENOF( IDSTR "=" );
2791 if ( tmp >= 1000 || tmp < 0 ) {
2792 fprintf( stderr, "Error: parse_syncrepl_line: "
2793 "syncrepl id %d is out of range [0..999]\n", tmp );
2798 } else if ( !strncasecmp( cargv[ i ], PROVIDERSTR "=",
2799 STRLENOF( PROVIDERSTR "=" ) ) )
2801 val = cargv[ i ] + STRLENOF( PROVIDERSTR "=" );
2802 ber_str2bv( val, 0, 1, &si->si_provideruri );
2803 gots |= GOT_PROVIDER;
2804 } else if ( !strncasecmp( cargv[ i ], SCHEMASTR "=",
2805 STRLENOF( SCHEMASTR "=" ) ) )
2807 val = cargv[ i ] + STRLENOF( SCHEMASTR "=" );
2808 if ( !strncasecmp( val, "on", STRLENOF( "on" ) )) {
2809 si->si_schemachecking = 1;
2810 } else if ( !strncasecmp( val, "off", STRLENOF( "off" ) ) ) {
2811 si->si_schemachecking = 0;
2813 si->si_schemachecking = 1;
2815 } else if ( !strncasecmp( cargv[ i ], FILTERSTR "=",
2816 STRLENOF( FILTERSTR "=" ) ) )
2818 val = cargv[ i ] + STRLENOF( FILTERSTR "=" );
2819 ber_str2bv( val, 0, 1, &si->si_filterstr );
2820 } else if ( !strncasecmp( cargv[ i ], SEARCHBASESTR "=",
2821 STRLENOF( SEARCHBASESTR "=" ) ) )
2826 val = cargv[ i ] + STRLENOF( SEARCHBASESTR "=" );
2827 if ( si->si_base.bv_val ) {
2828 ch_free( si->si_base.bv_val );
2830 ber_str2bv( val, 0, 0, &bv );
2831 rc = dnNormalize( 0, NULL, NULL, &bv, &si->si_base, NULL );
2832 if ( rc != LDAP_SUCCESS ) {
2833 fprintf( stderr, "Invalid base DN \"%s\": %d (%s)\n",
2834 val, rc, ldap_err2string( rc ) );
2837 } else if ( !strncasecmp( cargv[ i ], SCOPESTR "=",
2838 STRLENOF( SCOPESTR "=" ) ) )
2841 val = cargv[ i ] + STRLENOF( SCOPESTR "=" );
2842 for ( j=0; !BER_BVISNULL(&scopes[j].key); j++ ) {
2843 if (!strncasecmp( val, scopes[j].key.bv_val,
2844 scopes[j].key.bv_len )) {
2845 while (!scopes[j].val) j--;
2846 si->si_scope = scopes[j].val;
2850 if ( BER_BVISNULL(&scopes[j].key) ) {
2851 fprintf( stderr, "Error: parse_syncrepl_line: "
2852 "unknown scope \"%s\"\n", val);
2855 } else if ( !strncasecmp( cargv[ i ], ATTRSONLYSTR "=",
2856 STRLENOF( ATTRSONLYSTR "=" ) ) )
2858 si->si_attrsonly = 1;
2859 } else if ( !strncasecmp( cargv[ i ], ATTRSSTR "=",
2860 STRLENOF( ATTRSSTR "=" ) ) )
2862 val = cargv[ i ] + STRLENOF( ATTRSSTR "=" );
2863 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") ) ) {
2865 attr_fname = ch_strdup( val + STRLENOF(":include:") );
2866 si->si_anlist = file2anlist( si->si_anlist, attr_fname, " ,\t" );
2867 if ( si->si_anlist == NULL ) {
2868 ch_free( attr_fname );
2871 si->si_anfile = attr_fname;
2873 char *str, *s, *next;
2874 char delimstr[] = " ,\t";
2875 str = ch_strdup( val );
2876 for ( s = ldap_pvt_strtok( str, delimstr, &next );
2878 s = ldap_pvt_strtok( NULL, delimstr, &next ) )
2880 if ( strlen(s) == 1 && *s == '*' ) {
2881 si->si_allattrs = 1;
2882 *(val + ( s - str )) = delimstr[0];
2884 if ( strlen(s) == 1 && *s == '+' ) {
2885 si->si_allopattrs = 1;
2886 *(val + ( s - str )) = delimstr[0];
2890 si->si_anlist = str2anlist( si->si_anlist, val, " ,\t" );
2891 if ( si->si_anlist == NULL ) {
2895 } else if ( !strncasecmp( cargv[ i ], EXATTRSSTR "=",
2896 STRLENOF( EXATTRSSTR "=" ) ) )
2898 val = cargv[ i ] + STRLENOF( EXATTRSSTR "=" );
2899 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") )) {
2901 attr_fname = ch_strdup( val + STRLENOF(":include:") );
2902 si->si_exanlist = file2anlist(
2903 si->si_exanlist, attr_fname, " ,\t" );
2904 if ( si->si_exanlist == NULL ) {
2905 ch_free( attr_fname );
2908 ch_free( attr_fname );
2910 si->si_exanlist = str2anlist( si->si_exanlist, val, " ,\t" );
2911 if ( si->si_exanlist == NULL ) {
2915 } else if ( !strncasecmp( cargv[ i ], TYPESTR "=",
2916 STRLENOF( TYPESTR "=" ) ) )
2918 val = cargv[ i ] + STRLENOF( TYPESTR "=" );
2919 if ( !strncasecmp( val, "refreshOnly",
2920 STRLENOF("refreshOnly") ))
2922 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2923 } else if ( !strncasecmp( val, "refreshAndPersist",
2924 STRLENOF("refreshAndPersist") ))
2926 si->si_type = LDAP_SYNC_REFRESH_AND_PERSIST;
2927 si->si_interval = 60;
2929 fprintf( stderr, "Error: parse_syncrepl_line: "
2930 "unknown sync type \"%s\"\n", val);
2933 } else if ( !strncasecmp( cargv[ i ], INTERVALSTR "=",
2934 STRLENOF( INTERVALSTR "=" ) ) )
2936 val = cargv[ i ] + STRLENOF( INTERVALSTR "=" );
2937 if ( si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ) {
2938 si->si_interval = 0;
2946 hstr = strchr( dstr, ':' );
2947 if ( hstr == NULL ) {
2948 fprintf( stderr, "Error: parse_syncrepl_line: "
2949 "invalid interval \"%s\"\n", val );
2953 mstr = strchr( hstr, ':' );
2954 if ( mstr == NULL ) {
2955 fprintf( stderr, "Error: parse_syncrepl_line: "
2956 "invalid interval \"%s\"\n", val );
2960 sstr = strchr( mstr, ':' );
2961 if ( sstr == NULL ) {
2962 fprintf( stderr, "Error: parse_syncrepl_line: "
2963 "invalid interval \"%s\"\n", val );
2972 if (( hh > 24 ) || ( hh < 0 ) ||
2973 ( mm > 60 ) || ( mm < 0 ) ||
2974 ( ss > 60 ) || ( ss < 0 ) || ( dd < 0 )) {
2975 fprintf( stderr, "Error: parse_syncrepl_line: "
2976 "invalid interval \"%s\"\n", val );
2979 si->si_interval = (( dd * 24 + hh ) * 60 + mm ) * 60 + ss;
2981 if ( si->si_interval < 0 ) {
2982 fprintf( stderr, "Error: parse_syncrepl_line: "
2983 "invalid interval \"%ld\"\n",
2984 (long) si->si_interval);
2987 } else if ( !strncasecmp( cargv[ i ], RETRYSTR "=",
2988 STRLENOF( RETRYSTR "=" ) ) )
2993 val = cargv[ i ] + STRLENOF( RETRYSTR "=" );
2994 retry_list = (char **) ch_calloc( 1, sizeof( char * ));
2995 retry_list[0] = NULL;
2997 slap_str2clist( &retry_list, val, " ,\t" );
2999 for ( k = 0; retry_list && retry_list[k]; k++ ) ;
3003 "Error: incomplete syncrepl retry list\n" );
3004 for ( k = 0; retry_list && retry_list[k]; k++ ) {
3005 ch_free( retry_list[k] );
3007 ch_free( retry_list );
3008 exit( EXIT_FAILURE );
3010 si->si_retryinterval = (time_t *) ch_calloc( n + 1, sizeof( time_t ));
3011 si->si_retrynum = (int *) ch_calloc( n + 1, sizeof( int ));
3012 si->si_retrynum_init = (int *) ch_calloc( n + 1, sizeof( int ));
3013 for ( j = 0; j < n; j++ ) {
3014 si->si_retryinterval[j] = atoi( retry_list[j*2] );
3015 if ( *retry_list[j*2+1] == '+' ) {
3016 si->si_retrynum_init[j] = -1;
3017 si->si_retrynum[j] = -1;
3021 si->si_retrynum_init[j] = atoi( retry_list[j*2+1] );
3022 si->si_retrynum[j] = atoi( retry_list[j*2+1] );
3025 si->si_retrynum_init[j] = -2;
3026 si->si_retrynum[j] = -2;
3027 si->si_retryinterval[j] = 0;
3029 for ( k = 0; retry_list && retry_list[k]; k++ ) {
3030 ch_free( retry_list[k] );
3032 ch_free( retry_list );
3033 } else if ( !strncasecmp( cargv[ i ], MANAGEDSAITSTR "=",
3034 STRLENOF( MANAGEDSAITSTR "=" ) ) )
3036 val = cargv[ i ] + STRLENOF( MANAGEDSAITSTR "=" );
3037 si->si_manageDSAit = atoi( val );
3038 } else if ( !strncasecmp( cargv[ i ], SLIMITSTR "=",
3039 STRLENOF( SLIMITSTR "=") ) )
3041 val = cargv[ i ] + STRLENOF( SLIMITSTR "=" );
3042 si->si_slimit = atoi( val );
3043 } else if ( !strncasecmp( cargv[ i ], TLIMITSTR "=",
3044 STRLENOF( TLIMITSTR "=" ) ) )
3046 val = cargv[ i ] + STRLENOF( TLIMITSTR "=" );
3047 si->si_tlimit = atoi( val );
3048 } else if ( bindconf_parse( cargv[i], &si->si_bindconf )) {
3049 fprintf( stderr, "Error: parse_syncrepl_line: "
3050 "unknown keyword \"%s\"\n", cargv[ i ] );
3055 if ( gots != GOT_ALL ) {
3057 "Error: Malformed \"syncrepl\" line in slapd config file" );
3067 syncrepl_unparse( syncinfo_t *si, struct berval *bv )
3070 char buf[BUFSIZ*2], *ptr;
3073 bindconf_unparse( &si->si_bindconf, &bc );
3075 ptr += sprintf( ptr, IDSTR "=%03d " PROVIDERSTR "=%s",
3076 si->si_rid, si->si_provideruri.bv_val );
3077 if ( !BER_BVISNULL( &bc )) {
3078 ptr = lutil_strcopy( ptr, bc.bv_val );
3081 if ( !BER_BVISEMPTY( &si->si_filterstr )) {
3082 ptr = lutil_strcopy( ptr, " " FILTERSTR "=\"" );
3083 ptr = lutil_strcopy( ptr, si->si_filterstr.bv_val );
3086 if ( !BER_BVISNULL( &si->si_base )) {
3087 ptr = lutil_strcopy( ptr, " " SEARCHBASESTR "=\"" );
3088 ptr = lutil_strcopy( ptr, si->si_base.bv_val );
3091 for (i=0; !BER_BVISNULL(&scopes[i].key);i++) {
3092 if ( si->si_scope == scopes[i].val ) {
3093 ptr = lutil_strcopy( ptr, " " SCOPESTR "=" );
3094 ptr = lutil_strcopy( ptr, scopes[i].key.bv_val );
3098 if ( si->si_attrsonly ) {
3099 ptr = lutil_strcopy( ptr, " " ATTRSONLYSTR "=yes" );
3101 if ( si->si_anfile ) {
3102 ptr = lutil_strcopy( ptr, " " ATTRSSTR "=:include:" );
3103 ptr = lutil_strcopy( ptr, si->si_anfile );
3104 } else if ( si->si_allattrs || si->si_allopattrs ||
3105 ( si->si_anlist && !BER_BVISNULL(&si->si_anlist[0].an_name) )) {
3107 ptr = lutil_strcopy( ptr, " " ATTRSSTR "=\"" );
3109 ptr = anlist_unparse( si->si_anlist, ptr );
3110 if ( si->si_allattrs ) {
3111 if ( old != ptr ) *ptr++ = ',';
3114 if ( si->si_allopattrs ) {
3115 if ( old != ptr ) *ptr++ = ',';
3120 if ( si->si_exanlist && !BER_BVISNULL(&si->si_exanlist[0].an_name) ) {
3121 ptr = lutil_strcopy( ptr, " " EXATTRSSTR "=" );
3122 ptr = anlist_unparse( si->si_exanlist, ptr );
3124 ptr = lutil_strcopy( ptr, " " SCHEMASTR "=" );
3125 ptr = lutil_strcopy( ptr, si->si_schemachecking ? "on" : "off" );
3127 ptr = lutil_strcopy( ptr, " " TYPESTR "=" );
3128 ptr = lutil_strcopy( ptr, si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ?
3129 "refreshAndPersist" : "refreshOnly" );
3131 if ( si->si_type == LDAP_SYNC_REFRESH_ONLY ) {
3134 dd = si->si_interval;
3141 ptr = lutil_strcopy( ptr, " " INTERVALSTR "=" );
3142 ptr += sprintf( ptr, "%02d:%02d:%02d:%02d", dd, hh, mm, ss );
3143 } else if ( si->si_retryinterval ) {
3145 ptr = lutil_strcopy( ptr, " " RETRYSTR "=\"" );
3146 for (i=0; si->si_retryinterval[i]; i++) {
3147 if ( space ) *ptr++ = ' ';
3149 ptr += sprintf( ptr, "%d", si->si_retryinterval[i] );
3150 if ( si->si_retrynum_init[i] == -1 )
3153 ptr += sprintf( ptr, "%d", si->si_retrynum_init );
3158 #if 0 /* FIXME: unused in syncrepl.c, should remove it */
3159 ptr = lutil_strcopy( ptr, " " MANAGEDSAITSTR "=" );
3160 ptr += sprintf( ptr, "%d", si->si_manageDSAit );
3163 if ( si->si_slimit ) {
3164 ptr = lutil_strcopy( ptr, " " SLIMITSTR "=" );
3165 ptr += sprintf( ptr, "%d", si->si_slimit );
3168 if ( si->si_tlimit ) {
3169 ptr = lutil_strcopy( ptr, " " TLIMITSTR "=" );
3170 ptr += sprintf( ptr, "%d", si->si_tlimit );
3172 bc.bv_len = ptr - buf;
3174 ber_dupbv( bv, &bc );
3178 slap_str2clist( char ***out, char *in, const char *brkstr )
3186 /* find last element in list */
3187 for (i = 0; *out && (*out)[i]; i++);
3189 /* protect the input string from strtok */
3190 str = ch_strdup( in );
3192 if ( *str == '\0' ) {
3197 /* Count words in string */
3199 for ( s = str; *s; s++ ) {
3200 if ( strchr( brkstr, *s ) != NULL ) {
3205 *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
3207 for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
3209 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
3211 *new = ch_strdup( s );