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 );
987 case CFG_LIMITS: /* FIXME */
991 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_OP_WRITES) != 0;
994 c->value_string = ch_strdup( slap_sasl_getpolicy());
997 slap_sasl_regexp_unparse( &c->rvalue_vals );
998 if ( !c->rvalue_vals ) rc = 1;
1000 #ifdef HAVE_CYRUS_SASL
1001 case CFG_SASLSECP: {
1002 struct berval bv = BER_BVNULL;
1003 slap_sasl_secprops_unparse( &bv );
1004 if ( !BER_BVISNULL( &bv )) {
1005 ber_bvarray_add( &c->rvalue_vals, &bv );
1013 c->value_int = c->be->be_max_deref_depth;
1016 oidm_unparse( &c->rvalue_vals );
1017 if ( !c->rvalue_vals )
1021 c->value_int = global_schemacheck;
1025 char *src, *dst, ibuf[11];
1026 struct berval bv, abv;
1027 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
1028 abv.bv_len = sprintf( ibuf, "{%x}", i );
1029 acl_unparse( a, &bv );
1030 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
1031 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
1032 /* Turn TAB / EOL into plain space */
1033 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
1034 if (isspace(*src)) *dst++ = ' ';
1038 if (dst[-1] == ' ') {
1042 abv.bv_len = dst - abv.bv_val;
1043 ber_bvarray_add( &c->rvalue_vals, &abv );
1049 if ( c->be->be_replogfile )
1050 c->value_string = ch_strdup( c->be->be_replogfile );
1053 ConfigFile *cf = (ConfigFile *)c->line;
1054 if ( cf->c_dseFiles ) {
1055 value_add( &c->rvalue_vals, cf->c_dseFiles );
1063 c->value_string = ch_strdup( logfileName );
1068 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1070 case CFG_SSTR_IF_MAX:
1071 c->value_int = index_substr_if_maxlen;
1073 case CFG_SSTR_IF_MIN:
1074 c->value_int = index_substr_if_minlen;
1076 #ifdef SLAPD_MODULES
1078 ConfigFile *cf = (ConfigFile *)c->line;
1080 for (i=0, mp=&cf->c_modpaths; mp; mp=mp->mp_next, i++) {
1082 if (!mp->mp_loads) continue;
1083 for (j=0; !BER_BVISNULL(&mp->mp_loads[j]); j++) {
1086 bv.bv_len = sprintf( bv.bv_val, "{%d}{%d}%s", i, j,
1087 mp->mp_loads[j].bv_val );
1088 value_add_one( &c->rvalue_vals, &bv );
1091 rc = c->rvalue_vals ? 0 : 1;
1095 ConfigFile *cf = (ConfigFile *)c->line;
1097 for (i=0, mp=&cf->c_modpaths; mp; mp=mp->mp_next, i++) {
1099 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
1102 bv.bv_len = sprintf( bv.bv_val, "{%d}%s", i,
1103 mp->mp_path.bv_val );
1104 value_add_one( &c->rvalue_vals, &bv );
1106 rc = c->rvalue_vals ? 0 : 1;
1112 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1113 if ( !c->rvalue_vals ) rc = 1;
1116 #ifdef SLAP_AUTH_REWRITE
1118 if ( authz_rewrites ) {
1119 struct berval bv, idx;
1124 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1125 idx.bv_len = sprintf( idx.bv_val, "{%d}", i );
1126 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1127 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1128 strcpy( bv.bv_val, idx.bv_val );
1129 strcpy( bv.bv_val+idx.bv_len, authz_rewrites[i].bv_val );
1130 ber_bvarray_add( &c->rvalue_vals, &bv );
1133 if ( !c->rvalue_vals ) rc = 1;
1142 p = strchr(c->line,'(' /*')'*/);
1145 if(!(c->bi = backend_info(c->argv[1]))) {
1146 Debug(LDAP_DEBUG_ANY, "%s: "
1147 "backend %s failed init!\n", c->log, c->argv[1], 0);
1154 /* NOTE: config is always the first backend!
1156 if ( !strcasecmp( c->argv[1], "config" )) {
1158 } else if(!(c->be = backend_db_init(c->argv[1]))) {
1159 Debug(LDAP_DEBUG_ANY, "%s: "
1160 "database %s failed init!\n", c->log, c->argv[1], 0);
1166 ldap_pvt_thread_set_concurrency(c->value_int);
1170 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1171 connection_pool_max = c->value_int; /* save for reference */
1175 if ( passwd_salt ) ch_free( passwd_salt );
1176 passwd_salt = c->value_string;
1177 lutil_salt_format(passwd_salt);
1181 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1187 c->be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1189 c->be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1193 ch_free(c->value_string);
1194 if (slap_sasl_setpolicy( c->argv[1] )) {
1195 Debug(LDAP_DEBUG_ANY, "%s: unable to parse value \"%s\" in"
1196 " \"authz-policy <policy>\"\n",
1197 c->log, c->argv[1], 0 );
1203 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1207 #ifdef HAVE_CYRUS_SASL
1210 char *txt = slap_sasl_secprops( c->argv[1] );
1212 Debug(LDAP_DEBUG_ANY, "%s: sasl-secprops: %s\n",
1221 c->be->be_max_deref_depth = c->value_int;
1225 if(parse_oidm(c->fname, c->lineno, c->argc, c->argv)) return(1);
1229 if(parse_oc(c->fname, c->lineno, p, c->argv)) return(1);
1233 if(parse_cr(c->fname, c->lineno, p, c->argv)) return(1);
1237 if(parse_at(c->fname, c->lineno, p, c->argv)) return(1);
1241 ad_define_option(NULL, NULL, 0);
1242 for(i = 1; i < c->argc; i++)
1243 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1248 global_schemacheck = c->value_int;
1249 if(!global_schemacheck) Debug(LDAP_DEBUG_ANY, "%s: "
1250 "schema checking disabled! your mileage may vary!\n",
1255 parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv);
1259 if(SLAP_MONITOR(c->be)) {
1260 Debug(LDAP_DEBUG_ANY, "%s: "
1261 "\"replogfile\" should not be used "
1262 "inside monitor database\n",
1264 return(0); /* FIXME: should this be an error? */
1267 c->be->be_replogfile = c->value_string;
1271 if(read_root_dse_file(c->argv[1])) {
1272 Debug(LDAP_DEBUG_ANY, "%s: "
1273 "could not read \"rootDSE <filename>\" line\n",
1279 ber_str2bv( c->argv[1], 0, 1, &bv );
1280 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1286 if ( logfileName ) ch_free( logfileName );
1287 logfileName = c->value_string;
1288 logfile = fopen(logfileName, "w");
1289 if(logfile) lutil_debug_file(logfile);
1293 if(SLAP_NOLASTMODCMD(c->be)) {
1294 Debug(LDAP_DEBUG_ANY, "%s: "
1295 "lastmod not available for %s databases\n",
1296 c->log, c->be->bd_info->bi_type, 0);
1300 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1302 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1305 case CFG_SSTR_IF_MAX:
1306 if (c->value_int < index_substr_if_minlen) {
1307 Debug(LDAP_DEBUG_ANY, "%s: "
1308 "invalid max value (%d)\n",
1309 c->log, c->value_int, 0 );
1312 index_substr_if_maxlen = c->value_int;
1315 case CFG_SSTR_IF_MIN:
1316 if (c->value_int > index_substr_if_maxlen) {
1317 Debug(LDAP_DEBUG_ANY, "%s: "
1318 "invalid min value (%d)\n",
1319 c->log, c->value_int, 0 );
1322 index_substr_if_minlen = c->value_int;
1325 #ifdef SLAPD_MODULES
1327 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1329 /* Record this load on the current path */
1332 ber_str2bv(c->line, 0, 1, &bv);
1333 ber_bvarray_add( &cfn->c_modlast->mp_loads, &bv );
1338 if(module_path(c->argv[1])) return(1);
1339 /* Record which path was used with each module */
1343 if (!cfn->c_modpaths.mp_loads) {
1344 mp = &cfn->c_modpaths;
1346 mp = ch_malloc( sizeof( ModPaths ));
1347 cfn->c_modlast->mp_next = mp;
1349 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1351 mp->mp_loads = NULL;
1352 cfn->c_modlast = mp;
1360 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
1362 slapi_plugins_used++;
1366 #ifdef SLAP_AUTH_REWRITE
1369 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
1371 ber_str2bv( c->line, 0, 1, &bv );
1372 ber_bvarray_add( &authz_rewrites, &bv );
1379 Debug(LDAP_DEBUG_ANY, "%s: unknown CFG_TYPE %d"
1380 "(ignored)\n", c->log, c->type, 0);
1388 config_fname(ConfigArgs *c) {
1389 if(c->emit && c->line) {
1390 ConfigFile *cf = (ConfigFile *)c->line;
1391 value_add_one( &c->rvalue_vals, &cf->c_file );
1398 config_search_base(ConfigArgs *c) {
1403 if (!BER_BVISEMPTY(&default_search_base)) {
1404 value_add_one(&c->rvalue_vals, &default_search_base);
1405 value_add_one(&c->rvalue_nvals, &default_search_nbase);
1411 if(c->bi || c->be != frontendDB) {
1412 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
1413 "prior to any backend or database definition\n",
1418 if(default_search_nbase.bv_len) {
1419 Debug(LDAP_DEBUG_ANY, "%s: "
1420 "default search base \"%s\" already defined "
1421 "(discarding old)\n",
1422 c->log, default_search_base.bv_val, 0);
1423 free(default_search_base.bv_val);
1424 free(default_search_nbase.bv_val);
1427 default_search_base = c->value_dn;
1428 default_search_nbase = c->value_ndn;
1433 config_passwd_hash(ConfigArgs *c) {
1437 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
1438 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
1439 value_add_one(&c->rvalue_vals, &bv);
1443 if(default_passwd_hash) {
1444 Debug(LDAP_DEBUG_ANY, "%s: "
1445 "already set default password_hash\n",
1449 for(i = 1; i < c->argc; i++) {
1450 if(!lutil_passwd_scheme(c->argv[i])) {
1451 Debug(LDAP_DEBUG_ANY, "%s: "
1452 "password scheme \"%s\" not available\n",
1453 c->log, c->argv[i], 0);
1455 ldap_charray_add(&default_passwd_hash, c->argv[i]);
1457 if(!default_passwd_hash) {
1458 Debug(LDAP_DEBUG_ANY, "%s: no valid hashes found\n",
1467 config_schema_dn(ConfigArgs *c) {
1471 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
1472 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
1475 c->be->be_schemadn = c->value_dn;
1476 c->be->be_schemandn = c->value_ndn;
1481 config_sizelimit(ConfigArgs *c) {
1484 struct slap_limits_set *lim = &c->be->be_def_limit;
1486 struct berval bv = BER_BVNULL;
1487 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv );
1488 if ( !BER_BVISEMPTY( &bv ))
1489 ber_bvarray_add( &c->rvalue_vals, &bv );
1494 for(i = 1; i < c->argc; i++) {
1495 if(!strncasecmp(c->argv[i], "size", 4)) {
1496 rc = limits_parse_one(c->argv[i], lim);
1498 Debug(LDAP_DEBUG_ANY, "%s: "
1499 "unable to parse value \"%s\" in \"sizelimit <limit>\" line\n",
1500 c->log, c->argv[i], 0);
1504 if(!strcasecmp(c->argv[i], "unlimited")) {
1505 lim->lms_s_soft = -1;
1507 lim->lms_s_soft = strtol(c->argv[i], &next, 0);
1508 if(next == c->argv[i]) {
1509 Debug(LDAP_DEBUG_ANY, "%s: "
1510 "unable to parse limit \"%s\" in \"sizelimit <limit>\" line\n",
1511 c->log, c->argv[i], 0);
1513 } else if(next[0] != '\0') {
1514 Debug(LDAP_DEBUG_ANY, "%s: "
1515 "trailing chars \"%s\" in \"sizelimit <limit>\" line (ignored)\n",
1519 lim->lms_s_hard = 0;
1526 config_timelimit(ConfigArgs *c) {
1529 struct slap_limits_set *lim = &c->be->be_def_limit;
1531 struct berval bv = BER_BVNULL;
1532 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv );
1533 if ( !BER_BVISEMPTY( &bv ))
1534 ber_bvarray_add( &c->rvalue_vals, &bv );
1539 for(i = 1; i < c->argc; i++) {
1540 if(!strncasecmp(c->argv[i], "time", 4)) {
1541 rc = limits_parse_one(c->argv[i], lim);
1543 Debug(LDAP_DEBUG_ANY, "%s: "
1544 "unable to parse value \"%s\" in \"timelimit <limit>\" line\n",
1545 c->log, c->argv[i], 0);
1549 if(!strcasecmp(c->argv[i], "unlimited")) {
1550 lim->lms_t_soft = -1;
1552 lim->lms_t_soft = strtol(c->argv[i], &next, 0);
1553 if(next == c->argv[i]) {
1554 Debug(LDAP_DEBUG_ANY, "%s: "
1555 "unable to parse limit \"%s\" in \"timelimit <limit>\" line\n",
1556 c->log, c->argv[i], 0);
1558 } else if(next[0] != '\0') {
1559 Debug(LDAP_DEBUG_ANY, "%s: "
1560 "trailing chars \"%s\" in \"timelimit <limit>\" line (ignored)\n",
1564 lim->lms_t_hard = 0;
1571 config_overlay(ConfigArgs *c) {
1575 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1])) {
1577 Debug(LDAP_DEBUG_ANY, "%s: (optional) %s overlay \"%s\" configuration failed (ignored)\n",
1578 c->log, c->be == frontendDB ? "global " : "", c->argv[1][1]);
1579 } else if(overlay_config(c->be, c->argv[1])) {
1586 config_suffix(ConfigArgs *c) {
1588 struct berval pdn, ndn;
1591 if ( !BER_BVISNULL( &c->be->be_suffix[0] )) {
1592 value_add( &c->rvalue_vals, c->be->be_suffix );
1593 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
1599 #ifdef SLAPD_MONITOR_DN
1600 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
1601 Debug(LDAP_DEBUG_ANY, "%s: "
1602 "\"%s\" is reserved for monitoring slapd\n",
1603 c->log, SLAPD_MONITOR_DN, 0);
1610 tbe = select_backend(&ndn, 0, 0);
1612 Debug(LDAP_DEBUG_ANY, "%s: suffix already served by this backend! (ignored)\n",
1617 Debug(LDAP_DEBUG_ANY, "%s: suffix already served by a preceding backend \"%s\"\n",
1618 c->log, tbe->be_suffix[0].bv_val, 0);
1622 } else if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
1623 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
1624 "base provided \"%s\" (assuming okay)\n",
1625 c->log, default_search_base.bv_val, 0);
1627 ber_bvarray_add(&c->be->be_suffix, &pdn);
1628 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
1633 config_rootdn(ConfigArgs *c) {
1635 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
1636 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
1637 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
1643 c->be->be_rootdn = c->value_dn;
1644 c->be->be_rootndn = c->value_ndn;
1649 config_rootpw(ConfigArgs *c) {
1652 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
1653 c->value_string=ch_strdup("*");
1659 tbe = select_backend(&c->be->be_rootndn, 0, 0);
1661 Debug(LDAP_DEBUG_ANY, "%s: "
1662 "rootpw can only be set when rootdn is under suffix\n",
1666 ber_str2bv(c->value_string, 0, 0, &c->be->be_rootpw);
1670 /* restrictops, allows, disallows, requires, loglevel */
1672 struct verb_mask_list { char *word; int mask; };
1675 verb_to_mask(ConfigArgs *c, struct verb_mask_list *v, int word) {
1677 for(j = 0; v[j].word; j++)
1678 if(!strcasecmp(c->argv[word], v[j].word))
1684 verbs_to_mask(ConfigArgs *c, struct verb_mask_list *v, slap_mask_t *m) {
1686 for(i = 1; i < c->argc; i++) {
1687 j = verb_to_mask(c, v, i);
1688 if(!v[j].word) return(1);
1689 while (!v[j].mask) j--;
1696 mask_to_verbs(ConfigArgs *c, struct verb_mask_list *v, slap_mask_t m) {
1701 for (i=0; v[i].word; i++) {
1702 if (!v[i].mask) continue;
1703 if (( m & v[i].mask ) == v[i].mask ) {
1704 ber_str2bv( v[i].word, 0, 0, &bv );
1705 value_add_one( &c->rvalue_vals, &bv );
1712 config_restrict(ConfigArgs *c) {
1713 slap_mask_t restrictops = 0;
1715 struct verb_mask_list restrictable_ops[] = {
1716 { "bind", SLAP_RESTRICT_OP_BIND },
1717 { "add", SLAP_RESTRICT_OP_ADD },
1718 { "modify", SLAP_RESTRICT_OP_MODIFY },
1719 { "rename", SLAP_RESTRICT_OP_RENAME },
1721 { "delete", SLAP_RESTRICT_OP_DELETE },
1722 { "search", SLAP_RESTRICT_OP_SEARCH },
1723 { "compare", SLAP_RESTRICT_OP_COMPARE },
1724 { "read", SLAP_RESTRICT_OP_READS },
1725 { "write", SLAP_RESTRICT_OP_WRITES },
1726 { "extended", SLAP_RESTRICT_OP_EXTENDED },
1727 { "extended=" LDAP_EXOP_START_TLS, SLAP_RESTRICT_EXOP_START_TLS },
1728 { "extended=" LDAP_EXOP_MODIFY_PASSWD, SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
1729 { "extended=" LDAP_EXOP_X_WHO_AM_I, SLAP_RESTRICT_EXOP_WHOAMI },
1730 { "extended=" LDAP_EXOP_X_CANCEL, SLAP_RESTRICT_EXOP_CANCEL },
1735 return mask_to_verbs( c, restrictable_ops, c->be->be_restrictops );
1737 i = verbs_to_mask( c, restrictable_ops, &restrictops );
1739 Debug(LDAP_DEBUG_ANY, "%s: "
1740 "unknown operation %s in \"restrict <features>\" line\n",
1741 c->log, c->argv[i], 0);
1744 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
1745 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
1746 c->be->be_restrictops |= restrictops;
1751 config_allows(ConfigArgs *c) {
1752 slap_mask_t allows = 0;
1754 struct verb_mask_list allowable_ops[] = {
1755 { "bind_v2", SLAP_ALLOW_BIND_V2 },
1756 { "bind_anon_cred", SLAP_ALLOW_BIND_ANON_CRED },
1757 { "bind_anon_dn", SLAP_ALLOW_BIND_ANON_DN },
1758 { "update_anon", SLAP_ALLOW_UPDATE_ANON },
1762 return mask_to_verbs( c, allowable_ops, global_allows );
1764 i = verbs_to_mask(c, allowable_ops, &allows);
1766 Debug(LDAP_DEBUG_ANY, "%s: "
1767 "unknown feature %s in \"allow <features>\" line\n",
1768 c->log, c->argv[i], 0);
1771 global_allows |= allows;
1776 config_disallows(ConfigArgs *c) {
1777 slap_mask_t disallows = 0;
1779 struct verb_mask_list disallowable_ops[] = {
1780 { "bind_anon", SLAP_DISALLOW_BIND_ANON },
1781 { "bind_simple", SLAP_DISALLOW_BIND_SIMPLE },
1782 { "bind_krb4", SLAP_DISALLOW_BIND_KRBV4 },
1783 { "tls_2_anon", SLAP_DISALLOW_TLS_2_ANON },
1784 { "tls_authc", SLAP_DISALLOW_TLS_AUTHC },
1788 return mask_to_verbs( c, disallowable_ops, global_disallows );
1790 i = verbs_to_mask(c, disallowable_ops, &disallows);
1792 Debug(LDAP_DEBUG_ANY, "%s: "
1793 "unknown feature %s in \"disallow <features>\" line\n",
1794 c->log, c->argv[i], 0);
1797 global_disallows |= disallows;
1802 config_requires(ConfigArgs *c) {
1803 slap_mask_t requires = 0;
1805 struct verb_mask_list requires_ops[] = {
1806 { "bind", SLAP_REQUIRE_BIND },
1807 { "LDAPv3", SLAP_REQUIRE_LDAP_V3 },
1808 { "authc", SLAP_REQUIRE_AUTHC },
1809 { "sasl", SLAP_REQUIRE_SASL },
1810 { "strong", SLAP_REQUIRE_STRONG },
1814 return mask_to_verbs( c, requires_ops, c->be->be_requires );
1816 i = verbs_to_mask(c, requires_ops, &requires);
1818 Debug(LDAP_DEBUG_ANY, "%s: "
1819 "unknown feature %s in \"require <features>\" line\n",
1820 c->log, c->argv[i], 0);
1823 c->be->be_requires = requires;
1828 config_loglevel(ConfigArgs *c) {
1831 struct verb_mask_list loglevel_ops[] = {
1832 { "Trace", LDAP_DEBUG_TRACE },
1833 { "Packets", LDAP_DEBUG_PACKETS },
1834 { "Args", LDAP_DEBUG_ARGS },
1835 { "Conns", LDAP_DEBUG_CONNS },
1836 { "BER", LDAP_DEBUG_BER },
1837 { "Filter", LDAP_DEBUG_FILTER },
1838 { "Config", LDAP_DEBUG_CONFIG },
1839 { "ACL", LDAP_DEBUG_ACL },
1840 { "Stats", LDAP_DEBUG_STATS },
1841 { "Stats2", LDAP_DEBUG_STATS2 },
1842 { "Shell", LDAP_DEBUG_SHELL },
1843 { "Parse", LDAP_DEBUG_PARSE },
1844 { "Cache", LDAP_DEBUG_CACHE },
1845 { "Index", LDAP_DEBUG_INDEX },
1851 return mask_to_verbs( c, loglevel_ops, ldap_syslog );
1856 for( i=1; i < c->argc; i++ ) {
1859 if ( isdigit( c->argv[i][0] ) ) {
1860 level = strtol( c->argv[i], &next, 10 );
1861 if ( next == NULL || next[0] != '\0' ) {
1862 Debug( LDAP_DEBUG_ANY,
1863 "%s: unable to parse level \"%s\" "
1864 "in \"loglevel <level> [...]\" line.\n",
1865 c->log, c->argv[i], 0);
1869 int j = verb_to_mask(c, loglevel_ops, c->argv[i][0]);
1870 if(!loglevel_ops[j].word) {
1871 Debug( LDAP_DEBUG_ANY,
1872 "%s: unknown level \"%s\" "
1873 "in \"loglevel <level> [...]\" line.\n",
1874 c->log, c->argv[i], 0);
1877 level = loglevel_ops[j].mask;
1879 ldap_syslog |= level;
1885 config_syncrepl(ConfigArgs *c) {
1887 if ( c->be->be_syncinfo ) {
1889 syncrepl_unparse( c->be->be_syncinfo, &bv );
1890 ber_bvarray_add( &c->rvalue_vals, &bv );
1895 if(SLAP_SHADOW(c->be)) {
1896 Debug(LDAP_DEBUG_ANY, "%s: "
1897 "syncrepl: database already shadowed.\n",
1900 } else if(add_syncrepl(c->be, c->argv, c->argc)) {
1903 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SYNC_SHADOW);
1908 config_referral(ConfigArgs *c) {
1909 struct berval vals[2];
1911 if ( default_referral ) {
1912 value_add( &c->rvalue_vals, default_referral );
1918 if(validate_global_referral(c->argv[1])) {
1919 Debug(LDAP_DEBUG_ANY, "%s: "
1920 "invalid URL (%s) in \"referral\" line.\n",
1921 c->log, c->argv[1], 0);
1925 ber_str2bv(c->argv[1], 0, 0, &vals[0]);
1926 vals[1].bv_val = NULL; vals[1].bv_len = 0;
1927 if(value_add(&default_referral, vals)) return(LDAP_OTHER);
1935 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
1936 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
1937 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
1938 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
1939 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
1940 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
1941 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
1942 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
1943 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
1948 config_security(ConfigArgs *c) {
1949 slap_ssf_set_t *set = &c->be->be_ssf_set;
1958 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
1959 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
1962 bv.bv_len = sprintf( numbuf, "%u", *tgt );
1963 bv.bv_len += sec_keys[i].key.bv_len;
1964 bv.bv_val = ch_malloc( bv.bv_len + 1);
1965 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
1966 strcpy( next, numbuf );
1967 ber_bvarray_add( &c->rvalue_vals, &bv );
1972 for(i = 1; i < c->argc; i++) {
1973 slap_ssf_t *tgt = NULL;
1975 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
1976 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
1977 sec_keys[j].key.bv_len)) {
1978 src = c->argv[i] + sec_keys[j].key.bv_len;
1979 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
1984 Debug(LDAP_DEBUG_ANY, "%s: "
1985 "unknown factor %s in \"security <factors>\" line\n",
1986 c->log, c->argv[i], 0);
1990 *tgt = strtol(src, &next, 10);
1991 if(next == NULL || next[0] != '\0' ) {
1992 Debug(LDAP_DEBUG_ANY, "%s: "
1993 "unable to parse factor \"%s\" in \"security <factors>\" line\n",
1994 c->log, c->argv[i], 0);
2001 static struct verb_mask_list tlskey[] = {
2002 { "no", SB_TLS_OFF },
2003 { "yes", SB_TLS_ON },
2004 { "critical", SB_TLS_CRITICAL }
2007 static struct verb_mask_list methkey[] = {
2008 { "simple", LDAP_AUTH_SIMPLE },
2009 #ifdef HAVE_CYRUS_SASL
2010 { "sasl", LDAP_AUTH_SASL },
2015 typedef struct cf_aux_table {
2019 struct verb_mask_list *aux;
2022 static cf_aux_table bindkey[] = {
2023 { BER_BVC("starttls="), offsetof(slap_bindconf, sb_tls), 0, tlskey },
2024 { BER_BVC("bindmethod="), offsetof(slap_bindconf, sb_method), 0, methkey },
2025 { BER_BVC("binddn="), offsetof(slap_bindconf, sb_binddn), 1, NULL },
2026 { BER_BVC("credentials="), offsetof(slap_bindconf, sb_cred), 1, NULL },
2027 { BER_BVC("saslmech="), offsetof(slap_bindconf, sb_saslmech), 0, NULL },
2028 { BER_BVC("secprops="), offsetof(slap_bindconf, sb_secprops), 0, NULL },
2029 { BER_BVC("realm="), offsetof(slap_bindconf, sb_realm), 0, NULL },
2030 { BER_BVC("authcID="), offsetof(slap_bindconf, sb_authcId), 0, NULL },
2031 { BER_BVC("authzID="), offsetof(slap_bindconf, sb_authzId), 1, NULL },
2032 { BER_BVNULL, 0, 0, NULL }
2035 int bindconf_parse( char *word, slap_bindconf *bc ) {
2040 for (tab = bindkey; !BER_BVISNULL(&tab->key); tab++) {
2041 if ( !strncasecmp( word, tab->key.bv_val, tab->key.bv_len )) {
2042 cptr = (char **)((char *)bc + tab->off);
2046 for (j=0; tab->aux[j].word; j++) {
2047 if (!strcasecmp(word+tab->key.bv_len, tab->aux[j].word)) {
2048 int *ptr = (int *)cptr;
2049 *ptr = tab->aux[j].mask;
2054 Debug(LDAP_DEBUG_ANY, "invalid bind config value %s\n",
2059 *cptr = ch_strdup(word+tab->key.bv_len);
2066 int bindconf_unparse( slap_bindconf *bc, struct berval *bv ) {
2067 char buf[BUFSIZ], *ptr;
2073 for (tab = bindkey; !BER_BVISNULL(&tab->key); tab++) {
2074 cptr = (char **)((char *)bc + tab->off);
2076 int *ip = (int *)cptr, i;
2077 for ( i=0; tab->aux[i].word; i++ ) {
2078 if ( *ip == tab->aux[i].mask ) {
2080 ptr = lutil_strcopy( ptr, tab->key.bv_val );
2081 ptr = lutil_strcopy( ptr, tab->aux[i].word );
2085 } else if ( *cptr ) {
2087 ptr = lutil_strcopy( ptr, tab->key.bv_val );
2088 if ( tab->quote ) *ptr++ = '"';
2089 ptr = lutil_strcopy( ptr, *cptr );
2090 if ( tab->quote ) *ptr++ = '"';
2094 tmp.bv_len = ptr - buf;
2095 ber_dupbv( bv, &tmp );
2099 void bindconf_free( slap_bindconf *bc ) {
2100 if ( bc->sb_binddn ) {
2101 ch_free( bc->sb_binddn );
2103 if ( bc->sb_cred ) {
2104 ch_free( bc->sb_cred );
2106 if ( bc->sb_saslmech ) {
2107 ch_free( bc->sb_saslmech );
2109 if ( bc->sb_secprops ) {
2110 ch_free( bc->sb_secprops );
2112 if ( bc->sb_realm ) {
2113 ch_free( bc->sb_realm );
2115 if ( bc->sb_authcId ) {
2116 ch_free( bc->sb_authcId );
2118 if ( bc->sb_authzId ) {
2119 ch_free( bc->sb_authzId );
2124 anlist_unparse( AttributeName *an, char *ptr ) {
2127 for (; !BER_BVISNULL( &an->an_name ); an++) {
2128 if ( comma ) *ptr++ = ',';
2129 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
2136 replica_unparse( struct slap_replica_info *ri, int i, struct berval *bv )
2140 struct berval bc = {0};
2143 len = sprintf(numbuf, "{%d}", i );
2145 len += strlen( ri->ri_uri ) + STRLENOF("uri=");
2146 if ( ri->ri_nsuffix ) {
2147 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
2148 len += ri->ri_nsuffix[i].bv_len + STRLENOF(" suffix=\"\"");
2151 if ( ri->ri_attrs ) {
2152 len += STRLENOF("attr");
2153 if ( ri->ri_exclude ) len++;
2154 for (i=0; !BER_BVISNULL( &ri->ri_attrs[i].an_name ); i++) {
2155 len += 1 + ri->ri_attrs[i].an_name.bv_len;
2158 bindconf_unparse( &ri->ri_bindconf, &bc );
2161 bv->bv_val = ch_malloc(len + 1);
2164 ptr = lutil_strcopy( bv->bv_val, numbuf );
2165 ptr = lutil_strcopy( ptr, "uri=" );
2166 ptr = lutil_strcopy( ptr, ri->ri_uri );
2168 if ( ri->ri_nsuffix ) {
2169 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
2170 ptr = lutil_strcopy( ptr, " suffix=\"" );
2171 ptr = lutil_strcopy( ptr, ri->ri_nsuffix[i].bv_val );
2175 if ( ri->ri_attrs ) {
2176 ptr = lutil_strcopy( ptr, "attr" );
2177 if ( ri->ri_exclude ) *ptr++ = '!';
2179 ptr = anlist_unparse( ri->ri_attrs, ptr );
2182 strcpy( ptr, bc.bv_val );
2183 ch_free( bc.bv_val );
2188 config_replica(ConfigArgs *c) {
2189 int i, nr = -1, len;
2190 char *replicahost, *replicauri;
2194 if (c->be->be_replica) {
2196 for (i=0;c->be->be_replica[i]; i++) {
2197 replica_unparse( c->be->be_replica[i], i, &bv );
2198 ber_bvarray_add( &c->rvalue_vals, &bv );
2204 if(SLAP_MONITOR(c->be)) {
2205 Debug(LDAP_DEBUG_ANY, "%s: "
2206 "\"replica\" should not be used inside monitor database\n",
2208 return(0); /* FIXME: should this be an error? */
2211 for(i = 1; i < c->argc; i++) {
2212 if(!strncasecmp(c->argv[i], "host=", STRLENOF("host="))) {
2213 replicahost = c->argv[i] + STRLENOF("host=");
2214 len = strlen( replicahost );
2215 replicauri = ch_malloc( len + STRLENOF("ldap://") + 1 );
2216 sprintf( replicauri, "ldap://%s", replicahost );
2217 replicahost = replicauri + STRLENOF( "ldap://");
2218 nr = add_replica_info(c->be, replicauri, replicahost);
2220 } else if(!strncasecmp(c->argv[i], "uri=", STRLENOF("uri="))) {
2221 if(ldap_url_parse(c->argv[i] + STRLENOF("uri="), &ludp) != LDAP_SUCCESS) {
2222 Debug(LDAP_DEBUG_ANY, "%s: "
2223 "replica line contains invalid "
2224 "uri definition.\n", c->log, 0, 0);
2227 if(!ludp->lud_host) {
2228 Debug(LDAP_DEBUG_ANY, "%s: "
2229 "replica line contains invalid "
2230 "uri definition - missing hostname.\n",
2234 ldap_free_urldesc(ludp);
2235 replicauri = c->argv[i] + STRLENOF("uri=");
2236 replicauri = ch_strdup( replicauri );
2237 replicahost = strchr( replicauri, '/' );
2239 nr = add_replica_info(c->be, replicauri, replicahost);
2244 Debug(LDAP_DEBUG_ANY, "%s: "
2245 "missing host or uri in \"replica\" line\n",
2248 } else if(nr == -1) {
2249 Debug(LDAP_DEBUG_ANY, "%s: "
2250 "unable to add replica \"%s\"\n",
2251 c->log, replicauri, 0);
2254 for(i = 1; i < c->argc; i++) {
2255 if(!strncasecmp(c->argv[i], "suffix=", STRLENOF( "suffix="))) {
2256 switch(add_replica_suffix(c->be, nr, c->argv[i] + STRLENOF("suffix="))) {
2258 Debug(LDAP_DEBUG_ANY, "%s: "
2259 "suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
2260 c->log, c->argv[i] + STRLENOF("suffix="), 0);
2263 Debug(LDAP_DEBUG_ANY, "%s: "
2264 "unable to normalize suffix in \"replica\" line (ignored)\n",
2269 } else if(!strncasecmp(c->argv[i], "attr", STRLENOF("attr"))) {
2271 char *arg = c->argv[i] + STRLENOF("attr");
2279 if(add_replica_attrs(c->be, nr, arg + 1, exclude)) {
2280 Debug(LDAP_DEBUG_ANY, "%s: "
2281 "attribute \"%s\" in \"replica\" line is unknown\n",
2282 c->log, arg + 1, 0);
2285 } else if ( bindconf_parse( c->argv[i],
2286 &c->be->be_replica[nr]->ri_bindconf ) ) {
2295 config_updatedn(ConfigArgs *c) {
2299 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
2300 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
2301 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
2306 if(SLAP_SHADOW(c->be)) {
2307 Debug(LDAP_DEBUG_ANY, "%s: "
2308 "updatedn: database already shadowed.\n",
2313 ber_str2bv(c->argv[1], 0, 0, &dn);
2315 rc = dnNormalize(0, NULL, NULL, &dn, &c->be->be_update_ndn, NULL);
2317 if(rc != LDAP_SUCCESS) {
2318 Debug(LDAP_DEBUG_ANY, "%s: "
2319 "updatedn DN is invalid: %d (%s)\n",
2320 c->log, rc, ldap_err2string( rc ));
2324 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
2329 config_updateref(ConfigArgs *c) {
2330 struct berval vals[2];
2332 if ( c->be->be_update_refs ) {
2333 value_add( &c->rvalue_vals, c->be->be_update_refs );
2339 if(!SLAP_SHADOW(c->be)) {
2340 Debug(LDAP_DEBUG_ANY, "%s: "
2341 "updateref line must come after syncrepl or updatedn.\n",
2346 if(validate_global_referral(c->argv[1])) {
2347 Debug(LDAP_DEBUG_ANY, "%s: "
2348 "invalid URL (%s) in \"updateref\" line.\n",
2349 c->log, c->argv[1], 0);
2352 ber_str2bv(c->argv[1], 0, 0, &vals[0]);
2353 vals[1].bv_val = NULL;
2354 if(value_add(&c->be->be_update_refs, vals)) return(LDAP_OTHER);
2359 config_include(ConfigArgs *c) {
2360 unsigned long savelineno = c->lineno;
2363 ConfigFile *cfsave = cfn;
2364 ConfigFile *cf2 = NULL;
2368 cf = ch_calloc( 1, sizeof(ConfigFile));
2369 if ( cfn->c_kids ) {
2370 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
2376 rc = read_config_file(c->argv[1], c->depth + 1, c);
2377 c->lineno = savelineno - 1;
2380 if ( cf2 ) cf2->c_sibs = NULL;
2381 else cfn->c_kids = NULL;
2389 config_tls_option(ConfigArgs *c) {
2392 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; break;
2393 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
2394 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
2395 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
2396 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
2397 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
2398 default: Debug(LDAP_DEBUG_ANY, "%s: "
2399 "unknown tls_option <%x>\n",
2400 c->log, c->type, 0);
2403 return ldap_pvt_tls_get_option( NULL, flag, &c->value_string );
2405 ch_free(c->value_string);
2406 return(ldap_pvt_tls_set_option(NULL, flag, c->argv[1]));
2409 /* FIXME: this ought to be provided by libldap */
2411 config_tls_config(ConfigArgs *c) {
2413 struct verb_mask_list crlkeys[] = {
2414 { "none", LDAP_OPT_X_TLS_CRL_NONE },
2415 { "peer", LDAP_OPT_X_TLS_CRL_PEER },
2416 { "all", LDAP_OPT_X_TLS_CRL_ALL },
2419 struct verb_mask_list vfykeys[] = {
2420 { "never", LDAP_OPT_X_TLS_NEVER },
2421 { "demand", LDAP_OPT_X_TLS_DEMAND },
2422 { "try", LDAP_OPT_X_TLS_TRY },
2423 { "hard", LDAP_OPT_X_TLS_HARD },
2427 #ifdef HAVE_OPENSSL_CRL
2428 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; keys = crlkeys;
2431 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; keys = vfykeys;
2433 default: Debug(LDAP_DEBUG_ANY, "%s: "
2434 "unknown tls_option <%x>\n",
2435 c->log, c->type, 0);
2438 ldap_pvt_tls_get_option( NULL, flag, &c->value_int );
2439 for (i=0; keys[i].word; i++) {
2440 if (keys[i].mask == c->value_int) {
2441 c->value_string = ch_strdup( keys[i].word );
2447 ch_free( c->value_string );
2448 if(isdigit((unsigned char)c->argv[1][0])) {
2449 i = atoi(c->argv[1]);
2450 return(ldap_pvt_tls_set_option(NULL, flag, &i));
2452 return(ldap_int_tls_config(NULL, flag, c->argv[1]));
2457 /* -------------------------------------- */
2461 strtok_quote( char *line, char *sep )
2467 strtok_quote_ptr = NULL;
2468 if ( line != NULL ) {
2471 while ( *next && strchr( sep, *next ) ) {
2475 if ( *next == '\0' ) {
2481 for ( inquote = 0; *next; ) {
2489 AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
2495 next + 1, strlen( next + 1 ) + 1 );
2496 next++; /* dont parse the escaped character */
2501 if ( strchr( sep, *next ) != NULL ) {
2502 strtok_quote_ptr = next;
2515 static char buf[BUFSIZ];
2517 static size_t lmax, lcur;
2519 #define CATLINE( buf ) \
2521 size_t len = strlen( buf ); \
2522 while ( lcur + len + 1 > lmax ) { \
2524 line = (char *) ch_realloc( line, lmax ); \
2526 strcpy( line + lcur, buf ); \
2531 fp_getline_init(ConfigArgs *c) {
2537 fp_getline( FILE *fp, ConfigArgs *c )
2545 /* avoid stack of bufs */
2546 if ( strncasecmp( line, "include", STRLENOF( "include" ) ) == 0 ) {
2552 while ( fgets( buf, sizeof( buf ), fp ) ) {
2553 p = strchr( buf, '\n' );
2555 if ( p > buf && p[-1] == '\r' ) {
2563 && ( p = line + strlen( line ) - 1 )[0] == '\\'
2570 if ( !isspace( (unsigned char)buf[0] ) ) {
2581 return(line[0] ? 1 : 0);
2585 fp_parse_line(ConfigArgs *c)
2588 char *tline = ch_strdup(c->line);
2589 char *hide[] = { "rootpw", "replica", "bindpw", "pseudorootpw", "dbpasswd", '\0' };
2593 token = strtok_quote(tline, " \t");
2595 if(token) for(i = 0; hide[i]; i++) if(!strcasecmp(token, hide[i])) break;
2596 if(strtok_quote_ptr) *strtok_quote_ptr = ' ';
2597 Debug(LDAP_DEBUG_CONFIG, "line %lu (%s%s)\n", c->lineno, hide[i] ? hide[i] : c->line, hide[i] ? " ***" : "");
2598 if(strtok_quote_ptr) *strtok_quote_ptr = '\0';
2600 for(; token; token = strtok_quote(NULL, " \t")) {
2601 if(c->argc == c->argv_size - 1) {
2603 tmp = ch_realloc(c->argv, (c->argv_size + ARGS_STEP) * sizeof(*c->argv));
2605 Debug(LDAP_DEBUG_ANY, "line %lu: out of memory\n", c->lineno, 0, 0);
2609 c->argv_size += ARGS_STEP;
2611 c->argv[c->argc++] = token;
2613 c->argv[c->argc] = NULL;
2620 ucdata_unload( UCDATA_ALL );
2622 /* NOTE: in case of early exit, frontendDB can be NULL */
2623 if ( frontendDB->be_schemandn.bv_val )
2624 free( frontendDB->be_schemandn.bv_val );
2625 if ( frontendDB->be_schemadn.bv_val )
2626 free( frontendDB->be_schemadn.bv_val );
2627 if ( frontendDB->be_acl )
2628 acl_destroy( frontendDB->be_acl, NULL );
2631 if ( slapd_args_file )
2632 free ( slapd_args_file );
2633 if ( slapd_pid_file )
2634 free ( slapd_pid_file );
2635 if ( default_passwd_hash )
2636 ldap_charray_free( default_passwd_hash );
2649 si = (syncinfo_t *) ch_calloc( 1, sizeof( syncinfo_t ) );
2652 Debug( LDAP_DEBUG_ANY, "out of memory in add_syncrepl\n", 0, 0, 0 );
2656 si->si_bindconf.sb_tls = SB_TLS_OFF;
2657 si->si_bindconf.sb_method = LDAP_AUTH_SIMPLE;
2658 si->si_schemachecking = 0;
2659 ber_str2bv( "(objectclass=*)", STRLENOF("(objectclass=*)"), 1,
2660 &si->si_filterstr );
2661 si->si_base.bv_val = NULL;
2662 si->si_scope = LDAP_SCOPE_SUBTREE;
2663 si->si_attrsonly = 0;
2664 si->si_anlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ));
2665 si->si_exanlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ));
2666 si->si_attrs = NULL;
2667 si->si_allattrs = 0;
2668 si->si_allopattrs = 0;
2669 si->si_exattrs = NULL;
2670 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2671 si->si_interval = 86400;
2672 si->si_retryinterval = NULL;
2673 si->si_retrynum_init = NULL;
2674 si->si_retrynum = NULL;
2675 si->si_manageDSAit = 0;
2679 si->si_presentlist = NULL;
2680 LDAP_LIST_INIT( &si->si_nonpresentlist );
2681 ldap_pvt_thread_mutex_init( &si->si_mutex );
2683 rc = parse_syncrepl_line( cargv, cargc, si );
2686 Debug( LDAP_DEBUG_ANY, "failed to add syncinfo\n", 0, 0, 0 );
2687 syncinfo_free( si );
2690 Debug( LDAP_DEBUG_CONFIG,
2691 "Config: ** successfully added syncrepl \"%s\"\n",
2692 BER_BVISNULL( &si->si_provideruri ) ?
2693 "(null)" : si->si_provideruri.bv_val, 0, 0 );
2694 if ( !si->si_schemachecking ) {
2695 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NO_SCHEMA_CHECK;
2698 be->be_syncinfo = si;
2703 /* NOTE: used & documented in slapd.conf(5) */
2705 #define PROVIDERSTR "provider"
2706 #define TYPESTR "type"
2707 #define INTERVALSTR "interval"
2708 #define SEARCHBASESTR "searchbase"
2709 #define FILTERSTR "filter"
2710 #define SCOPESTR "scope"
2711 #define ATTRSSTR "attrs"
2712 #define ATTRSONLYSTR "attrsonly"
2713 #define SLIMITSTR "sizelimit"
2714 #define TLIMITSTR "timelimit"
2715 #define SCHEMASTR "schemachecking"
2717 /* FIXME: undocumented */
2718 #define OLDAUTHCSTR "bindprincipal"
2719 #define EXATTRSSTR "exattrs"
2720 #define RETRYSTR "retry"
2723 #define LASTMODSTR "lastmod"
2724 #define LMGENSTR "gen"
2725 #define LMNOSTR "no"
2726 #define LMREQSTR "req"
2727 #define SRVTABSTR "srvtab"
2728 #define SUFFIXSTR "suffix"
2729 #define MANAGEDSAITSTR "manageDSAit"
2732 #define GOT_ID 0x0001
2733 #define GOT_PROVIDER 0x0002
2736 #define GOT_ALL (GOT_ID|GOT_PROVIDER)
2742 { BER_BVC("base"), LDAP_SCOPE_BASE },
2743 { BER_BVC("one"), LDAP_SCOPE_ONELEVEL },
2744 #ifdef LDAP_SCOPE_SUBORDINATE
2745 { BER_BVC("children"), LDAP_SCOPE_SUBORDINATE },
2746 { BER_BVC("subordinate"), 0 },
2748 { BER_BVC("sub"), LDAP_SCOPE_SUBTREE },
2753 parse_syncrepl_line(
2763 for ( i = 1; i < cargc; i++ ) {
2764 if ( !strncasecmp( cargv[ i ], IDSTR "=",
2765 STRLENOF( IDSTR "=" ) ) )
2768 /* '\0' string terminator accounts for '=' */
2769 val = cargv[ i ] + STRLENOF( IDSTR "=" );
2771 if ( tmp >= 1000 || tmp < 0 ) {
2772 fprintf( stderr, "Error: parse_syncrepl_line: "
2773 "syncrepl id %d is out of range [0..999]\n", tmp );
2778 } else if ( !strncasecmp( cargv[ i ], PROVIDERSTR "=",
2779 STRLENOF( PROVIDERSTR "=" ) ) )
2781 val = cargv[ i ] + STRLENOF( PROVIDERSTR "=" );
2782 ber_str2bv( val, 0, 1, &si->si_provideruri );
2783 gots |= GOT_PROVIDER;
2784 } else if ( !strncasecmp( cargv[ i ], SCHEMASTR "=",
2785 STRLENOF( SCHEMASTR "=" ) ) )
2787 val = cargv[ i ] + STRLENOF( SCHEMASTR "=" );
2788 if ( !strncasecmp( val, "on", STRLENOF( "on" ) )) {
2789 si->si_schemachecking = 1;
2790 } else if ( !strncasecmp( val, "off", STRLENOF( "off" ) ) ) {
2791 si->si_schemachecking = 0;
2793 si->si_schemachecking = 1;
2795 } else if ( !strncasecmp( cargv[ i ], FILTERSTR "=",
2796 STRLENOF( FILTERSTR "=" ) ) )
2798 val = cargv[ i ] + STRLENOF( FILTERSTR "=" );
2799 ber_str2bv( val, 0, 1, &si->si_filterstr );
2800 } else if ( !strncasecmp( cargv[ i ], SEARCHBASESTR "=",
2801 STRLENOF( SEARCHBASESTR "=" ) ) )
2806 val = cargv[ i ] + STRLENOF( SEARCHBASESTR "=" );
2807 if ( si->si_base.bv_val ) {
2808 ch_free( si->si_base.bv_val );
2810 ber_str2bv( val, 0, 0, &bv );
2811 rc = dnNormalize( 0, NULL, NULL, &bv, &si->si_base, NULL );
2812 if ( rc != LDAP_SUCCESS ) {
2813 fprintf( stderr, "Invalid base DN \"%s\": %d (%s)\n",
2814 val, rc, ldap_err2string( rc ) );
2817 } else if ( !strncasecmp( cargv[ i ], SCOPESTR "=",
2818 STRLENOF( SCOPESTR "=" ) ) )
2821 val = cargv[ i ] + STRLENOF( SCOPESTR "=" );
2822 for ( j=0; !BER_BVISNULL(&scopes[j].key); j++ ) {
2823 if (!strncasecmp( val, scopes[j].key.bv_val,
2824 scopes[j].key.bv_len )) {
2825 while (!scopes[j].val) j--;
2826 si->si_scope = scopes[j].val;
2830 if ( BER_BVISNULL(&scopes[j].key) ) {
2831 fprintf( stderr, "Error: parse_syncrepl_line: "
2832 "unknown scope \"%s\"\n", val);
2835 } else if ( !strncasecmp( cargv[ i ], ATTRSONLYSTR "=",
2836 STRLENOF( ATTRSONLYSTR "=" ) ) )
2838 si->si_attrsonly = 1;
2839 } else if ( !strncasecmp( cargv[ i ], ATTRSSTR "=",
2840 STRLENOF( ATTRSSTR "=" ) ) )
2842 val = cargv[ i ] + STRLENOF( ATTRSSTR "=" );
2843 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") ) ) {
2845 attr_fname = ch_strdup( val + STRLENOF(":include:") );
2846 si->si_anlist = file2anlist( si->si_anlist, attr_fname, " ,\t" );
2847 if ( si->si_anlist == NULL ) {
2848 ch_free( attr_fname );
2851 si->si_anfile = attr_fname;
2853 char *str, *s, *next;
2854 char delimstr[] = " ,\t";
2855 str = ch_strdup( val );
2856 for ( s = ldap_pvt_strtok( str, delimstr, &next );
2858 s = ldap_pvt_strtok( NULL, delimstr, &next ) )
2860 if ( strlen(s) == 1 && *s == '*' ) {
2861 si->si_allattrs = 1;
2862 *(val + ( s - str )) = delimstr[0];
2864 if ( strlen(s) == 1 && *s == '+' ) {
2865 si->si_allopattrs = 1;
2866 *(val + ( s - str )) = delimstr[0];
2870 si->si_anlist = str2anlist( si->si_anlist, val, " ,\t" );
2871 if ( si->si_anlist == NULL ) {
2875 } else if ( !strncasecmp( cargv[ i ], EXATTRSSTR "=",
2876 STRLENOF( EXATTRSSTR "=" ) ) )
2878 val = cargv[ i ] + STRLENOF( EXATTRSSTR "=" );
2879 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") )) {
2881 attr_fname = ch_strdup( val + STRLENOF(":include:") );
2882 si->si_exanlist = file2anlist(
2883 si->si_exanlist, attr_fname, " ,\t" );
2884 if ( si->si_exanlist == NULL ) {
2885 ch_free( attr_fname );
2888 ch_free( attr_fname );
2890 si->si_exanlist = str2anlist( si->si_exanlist, val, " ,\t" );
2891 if ( si->si_exanlist == NULL ) {
2895 } else if ( !strncasecmp( cargv[ i ], TYPESTR "=",
2896 STRLENOF( TYPESTR "=" ) ) )
2898 val = cargv[ i ] + STRLENOF( TYPESTR "=" );
2899 if ( !strncasecmp( val, "refreshOnly",
2900 STRLENOF("refreshOnly") ))
2902 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2903 } else if ( !strncasecmp( val, "refreshAndPersist",
2904 STRLENOF("refreshAndPersist") ))
2906 si->si_type = LDAP_SYNC_REFRESH_AND_PERSIST;
2907 si->si_interval = 60;
2909 fprintf( stderr, "Error: parse_syncrepl_line: "
2910 "unknown sync type \"%s\"\n", val);
2913 } else if ( !strncasecmp( cargv[ i ], INTERVALSTR "=",
2914 STRLENOF( INTERVALSTR "=" ) ) )
2916 val = cargv[ i ] + STRLENOF( INTERVALSTR "=" );
2917 if ( si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ) {
2918 si->si_interval = 0;
2926 hstr = strchr( dstr, ':' );
2927 if ( hstr == NULL ) {
2928 fprintf( stderr, "Error: parse_syncrepl_line: "
2929 "invalid interval \"%s\"\n", val );
2933 mstr = strchr( hstr, ':' );
2934 if ( mstr == NULL ) {
2935 fprintf( stderr, "Error: parse_syncrepl_line: "
2936 "invalid interval \"%s\"\n", val );
2940 sstr = strchr( mstr, ':' );
2941 if ( sstr == NULL ) {
2942 fprintf( stderr, "Error: parse_syncrepl_line: "
2943 "invalid interval \"%s\"\n", val );
2952 if (( hh > 24 ) || ( hh < 0 ) ||
2953 ( mm > 60 ) || ( mm < 0 ) ||
2954 ( ss > 60 ) || ( ss < 0 ) || ( dd < 0 )) {
2955 fprintf( stderr, "Error: parse_syncrepl_line: "
2956 "invalid interval \"%s\"\n", val );
2959 si->si_interval = (( dd * 24 + hh ) * 60 + mm ) * 60 + ss;
2961 if ( si->si_interval < 0 ) {
2962 fprintf( stderr, "Error: parse_syncrepl_line: "
2963 "invalid interval \"%ld\"\n",
2964 (long) si->si_interval);
2967 } else if ( !strncasecmp( cargv[ i ], RETRYSTR "=",
2968 STRLENOF( RETRYSTR "=" ) ) )
2973 val = cargv[ i ] + STRLENOF( RETRYSTR "=" );
2974 retry_list = (char **) ch_calloc( 1, sizeof( char * ));
2975 retry_list[0] = NULL;
2977 slap_str2clist( &retry_list, val, " ,\t" );
2979 for ( k = 0; retry_list && retry_list[k]; k++ ) ;
2983 "Error: incomplete syncrepl retry list\n" );
2984 for ( k = 0; retry_list && retry_list[k]; k++ ) {
2985 ch_free( retry_list[k] );
2987 ch_free( retry_list );
2988 exit( EXIT_FAILURE );
2990 si->si_retryinterval = (time_t *) ch_calloc( n + 1, sizeof( time_t ));
2991 si->si_retrynum = (int *) ch_calloc( n + 1, sizeof( int ));
2992 si->si_retrynum_init = (int *) ch_calloc( n + 1, sizeof( int ));
2993 for ( j = 0; j < n; j++ ) {
2994 si->si_retryinterval[j] = atoi( retry_list[j*2] );
2995 if ( *retry_list[j*2+1] == '+' ) {
2996 si->si_retrynum_init[j] = -1;
2997 si->si_retrynum[j] = -1;
3001 si->si_retrynum_init[j] = atoi( retry_list[j*2+1] );
3002 si->si_retrynum[j] = atoi( retry_list[j*2+1] );
3005 si->si_retrynum_init[j] = -2;
3006 si->si_retrynum[j] = -2;
3007 si->si_retryinterval[j] = 0;
3009 for ( k = 0; retry_list && retry_list[k]; k++ ) {
3010 ch_free( retry_list[k] );
3012 ch_free( retry_list );
3013 } else if ( !strncasecmp( cargv[ i ], MANAGEDSAITSTR "=",
3014 STRLENOF( MANAGEDSAITSTR "=" ) ) )
3016 val = cargv[ i ] + STRLENOF( MANAGEDSAITSTR "=" );
3017 si->si_manageDSAit = atoi( val );
3018 } else if ( !strncasecmp( cargv[ i ], SLIMITSTR "=",
3019 STRLENOF( SLIMITSTR "=") ) )
3021 val = cargv[ i ] + STRLENOF( SLIMITSTR "=" );
3022 si->si_slimit = atoi( val );
3023 } else if ( !strncasecmp( cargv[ i ], TLIMITSTR "=",
3024 STRLENOF( TLIMITSTR "=" ) ) )
3026 val = cargv[ i ] + STRLENOF( TLIMITSTR "=" );
3027 si->si_tlimit = atoi( val );
3028 } else if ( bindconf_parse( cargv[i], &si->si_bindconf )) {
3029 fprintf( stderr, "Error: parse_syncrepl_line: "
3030 "unknown keyword \"%s\"\n", cargv[ i ] );
3035 if ( gots != GOT_ALL ) {
3037 "Error: Malformed \"syncrepl\" line in slapd config file" );
3047 syncrepl_unparse( syncinfo_t *si, struct berval *bv )
3050 char buf[BUFSIZ*2], *ptr;
3053 bindconf_unparse( &si->si_bindconf, &bc );
3055 ptr += sprintf( ptr, IDSTR "=%03d " PROVIDERSTR "=%s",
3056 si->si_rid, si->si_provideruri.bv_val );
3057 if ( !BER_BVISNULL( &bc )) {
3058 ptr = lutil_strcopy( ptr, bc.bv_val );
3061 if ( !BER_BVISEMPTY( &si->si_filterstr )) {
3062 ptr = lutil_strcopy( ptr, " " FILTERSTR "=\"" );
3063 ptr = lutil_strcopy( ptr, si->si_filterstr.bv_val );
3066 if ( !BER_BVISNULL( &si->si_base )) {
3067 ptr = lutil_strcopy( ptr, " " SEARCHBASESTR "=\"" );
3068 ptr = lutil_strcopy( ptr, si->si_base.bv_val );
3071 for (i=0; !BER_BVISNULL(&scopes[i].key);i++) {
3072 if ( si->si_scope == scopes[i].val ) {
3073 ptr = lutil_strcopy( ptr, " " SCOPESTR "=" );
3074 ptr = lutil_strcopy( ptr, scopes[i].key.bv_val );
3078 if ( si->si_attrsonly ) {
3079 ptr = lutil_strcopy( ptr, " " ATTRSONLYSTR "=yes" );
3081 if ( si->si_anfile ) {
3082 ptr = lutil_strcopy( ptr, " " ATTRSSTR "=:include:" );
3083 ptr = lutil_strcopy( ptr, si->si_anfile );
3084 } else if ( si->si_allattrs || si->si_allopattrs ||
3085 ( si->si_anlist && !BER_BVISNULL(&si->si_anlist[0].an_name) )) {
3087 ptr = lutil_strcopy( ptr, " " ATTRSSTR "=\"" );
3089 ptr = anlist_unparse( si->si_anlist, ptr );
3090 if ( si->si_allattrs ) {
3091 if ( old != ptr ) *ptr++ = ',';
3094 if ( si->si_allopattrs ) {
3095 if ( old != ptr ) *ptr++ = ',';
3100 if ( si->si_exanlist && !BER_BVISNULL(&si->si_exanlist[0].an_name) ) {
3101 ptr = lutil_strcopy( ptr, " " EXATTRSSTR "=" );
3102 ptr = anlist_unparse( si->si_exanlist, ptr );
3104 ptr = lutil_strcopy( ptr, " " SCHEMASTR "=" );
3105 ptr = lutil_strcopy( ptr, si->si_schemachecking ? "on" : "off" );
3107 ptr = lutil_strcopy( ptr, " " TYPESTR "=" );
3108 ptr = lutil_strcopy( ptr, si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ?
3109 "refreshAndPersist" : "refreshOnly" );
3111 if ( si->si_type == LDAP_SYNC_REFRESH_ONLY ) {
3114 dd = si->si_interval;
3121 ptr = lutil_strcopy( ptr, " " INTERVALSTR "=" );
3122 ptr += sprintf( ptr, "%02d:%02d:%02d:%02d", dd, hh, mm, ss );
3123 } else if ( si->si_retryinterval ) {
3125 ptr = lutil_strcopy( ptr, " " RETRYSTR "=\"" );
3126 for (i=0; si->si_retryinterval[i]; i++) {
3127 if ( space ) *ptr++ = ' ';
3129 ptr += sprintf( ptr, "%d", si->si_retryinterval[i] );
3130 if ( si->si_retrynum_init[i] == -1 )
3133 ptr += sprintf( ptr, "%d", si->si_retrynum_init );
3138 #if 0 /* FIXME: unused in syncrepl.c, should remove it */
3139 ptr = lutil_strcopy( ptr, " " MANAGEDSAITSTR "=" );
3140 ptr += sprintf( ptr, "%d", si->si_manageDSAit );
3143 if ( si->si_slimit ) {
3144 ptr = lutil_strcopy( ptr, " " SLIMITSTR "=" );
3145 ptr += sprintf( ptr, "%d", si->si_slimit );
3148 if ( si->si_tlimit ) {
3149 ptr = lutil_strcopy( ptr, " " TLIMITSTR "=" );
3150 ptr += sprintf( ptr, "%d", si->si_tlimit );
3152 bc.bv_len = ptr - buf;
3154 ber_dupbv( bv, &bc );
3158 slap_str2clist( char ***out, char *in, const char *brkstr )
3166 /* find last element in list */
3167 for (i = 0; *out && (*out)[i]; i++);
3169 /* protect the input string from strtok */
3170 str = ch_strdup( in );
3172 if ( *str == '\0' ) {
3177 /* Count words in string */
3179 for ( s = str; *s; s++ ) {
3180 if ( strchr( brkstr, *s ) != NULL ) {
3185 *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
3187 for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
3189 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
3191 *new = ch_strdup( s );