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;
80 int slapi_plugins_used = 0;
83 static int fp_getline(FILE *fp, ConfigArgs *c);
84 static void fp_getline_init(ConfigArgs *c);
85 static int fp_parse_line(ConfigArgs *c);
87 static char *strtok_quote(char *line, char *sep);
89 static int load_ucdata(char *path);
92 int read_config_file(const char *fname, int depth, ConfigArgs *cf);
94 static int add_syncrepl LDAP_P(( Backend *, char **, int ));
95 static int parse_syncrepl_line LDAP_P(( char **, int, syncinfo_t *));
97 int config_generic(ConfigArgs *c);
98 int config_search_base(ConfigArgs *c);
99 int config_passwd_hash(ConfigArgs *c);
100 int config_schema_dn(ConfigArgs *c);
101 int config_sizelimit(ConfigArgs *c);
102 int config_timelimit(ConfigArgs *c);
103 int config_limits(ConfigArgs *c);
104 int config_overlay(ConfigArgs *c);
105 int config_suffix(ConfigArgs *c);
106 int config_deref_depth(ConfigArgs *c);
107 int config_rootdn(ConfigArgs *c);
108 int config_rootpw(ConfigArgs *c);
109 int config_restrict(ConfigArgs *c);
110 int config_allows(ConfigArgs *c);
111 int config_disallows(ConfigArgs *c);
112 int config_requires(ConfigArgs *c);
113 int config_security(ConfigArgs *c);
114 int config_referral(ConfigArgs *c);
115 int config_loglevel(ConfigArgs *c);
116 int config_syncrepl(ConfigArgs *c);
117 int config_replica(ConfigArgs *c);
118 int config_updatedn(ConfigArgs *c);
119 int config_updateref(ConfigArgs *c);
120 int config_include(ConfigArgs *c);
122 int config_tls_option(ConfigArgs *c);
123 int config_tls_verify(ConfigArgs *c);
126 int config_plugin(ConfigArgs *c);
128 int config_pluginlog(ConfigArgs *c);
174 static OidRec OidMacros[] = {
175 { "OLcfg", "1.3.6.1.4.1.4203.666.11.1" },
176 { "OLcfgAt", "OLcfg:3" },
177 { "OLcfgOc", "OLcfg:4" },
178 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
179 { "OMsInteger", "OMsyn:2" },
180 { "OMsBoolean", "OMsyn:7" },
181 { "OMsDN", "OMsyn:12" },
182 { "OMsDirectoryString", "OMsyn:15" },
183 { "OMsOctetString", "OMsyn:40" },
187 /* alphabetical ordering */
189 ConfigTable SystemConfiguration[] = {
190 { "access", NULL, 0, 0, 0, ARG_MAGIC|CFG_ACL,
191 &config_generic, "( OLcfgAt:1 NAME 'olcAccess' "
192 "DESC 'Access Control List' "
193 "EQUALITY caseIgnoreMatch "
194 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
195 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
196 &config_allows, "( OLcfgAt:2 NAME 'olcAllows' "
197 "DESC 'Allowed set of deprecated features' "
198 "EQUALITY caseIgnoreMatch "
199 "SYNTAX OMsDirectoryString )", NULL, NULL },
200 { "argsfile", "file", 2, 2, 0, ARG_STRING,
201 &slapd_args_file, "( OLcfgAt:3 NAME 'olcArgsFile' "
202 "DESC 'File for slapd command line options' "
203 "EQUALITY caseIgnoreMatch "
204 "SYNTAX OMsDirectoryString )", NULL, NULL },
205 /* Use standard 'attributeTypes' attr */
206 { "attribute", "attribute", 2, 0, 9, ARG_PAREN|ARG_MAGIC|CFG_ATTR,
207 &config_generic, NULL, NULL, NULL },
208 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
209 &config_generic, "( OLcfgAt:5 NAME 'olcAttributeOptions' "
210 "EQUALITY caseIgnoreMatch "
211 "SYNTAX OMsDirectoryString )", NULL, NULL },
212 #ifdef SLAP_AUTH_REWRITE
213 { "auth-rewrite", NULL, 2, 2, 14, ARG_MAGIC|CFG_REWRITE,
214 &config_generic, "( OLcfgAt:6 NAME 'olcAuthRewrite' "
215 "EQUALITY caseIgnoreMatch "
216 "SYNTAX OMsDirectoryString )", NULL, NULL },
218 { "authz-policy", "policy", 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
219 &config_generic, "( OLcfgAt:7 NAME 'olcAuthzPolicy' "
220 "EQUALITY caseIgnoreMatch "
221 "SYNTAX OMsDirectoryString )", NULL, NULL },
222 { "authz-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
223 &config_generic, "( OLcfgAt:8 NAME 'olcAuthzRegexp' "
224 "EQUALITY caseIgnoreMatch "
225 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
226 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
227 &config_generic, "( OLcfgAt:9 NAME 'olcBackend' "
228 "DESC 'A type of backend' "
229 "EQUALITY caseIgnoreMatch "
230 "SYNTAX OMsDirectoryString )", NULL, NULL },
231 { "concurrency", "level", 2, 2, 0, ARG_LONG|ARG_NONZERO|ARG_MAGIC|CFG_CONCUR,
232 &config_generic, "( OLcfgAt:10 NAME 'olcConcurrency' "
233 "SYNTAX OMsInteger )", NULL, NULL },
234 { "conn_max_pending", "max", 2, 2, 0, ARG_LONG,
235 &slap_conn_max_pending, "( OLcfgAt:11 NAME 'olcConnMaxPending' "
236 "SYNTAX OMsInteger )", NULL, NULL },
237 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_LONG,
238 &slap_conn_max_pending_auth, "( OLcfgAt:12 NAME 'olcConnMaxPendingAuth' "
239 "SYNTAX OMsInteger )", NULL, NULL },
240 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
241 &config_generic, "( OLcfgAt:13 NAME 'olcDatabase' "
242 "DESC 'The backend type for a database instance' "
243 "SUP olcBackend )", NULL, NULL },
244 { "defaultSearchBase", "dn", 2, 2, 0, ARG_DN|ARG_MAGIC,
245 &config_search_base, "( OLcfgAt:14 NAME 'olcDefaultSearchBase' "
246 "SYNTAX OMsDN )", NULL, NULL },
247 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
248 &config_disallows, "( OLcfgAt:15 NAME 'olcDisallows' "
249 "EQUALITY caseIgnoreMatch "
250 "SYNTAX OMsDirectoryString )", NULL, NULL },
251 /* use standard schema */
252 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT,
253 &config_generic, NULL, NULL, NULL },
255 { "gentlehup", "on|off", 2, 2, 0, ARG_ON_OFF,
256 &global_gentlehup, "( OLcfgAt:17 NAME 'olcGentleHUP' "
257 "SYNTAX OMsBoolean )", NULL, NULL },
259 { "gentlehup", NULL, 2, 2, 0, ARG_IGNORED,
260 NULL, NULL, NULL, NULL },
262 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
263 &global_idletimeout, "( OLcfgAt:18 NAME 'olcIdleTimeout' "
264 "SYNTAX OMsInteger )", NULL, NULL },
265 /* XXX -- special case? */
266 { "include", "file", 2, 2, 0, ARG_MAGIC,
267 &config_include, "( OLcfgAt:19 NAME 'olcInclude' "
268 "SUP labeledURI )", NULL, NULL },
269 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_INT|ARG_NONZERO,
270 &index_substr_if_minlen, "( OLcfgAt:20 NAME 'olcIndexSubstrIfMinLen' "
271 "SYNTAX OMsInteger )", NULL, NULL },
272 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_SPECIAL,
273 &index_substr_if_maxlen, "( OLcfgAt:21 NAME 'olcIndexSubstrIfMaxLen' "
274 "SYNTAX OMsInteger )", NULL, NULL },
275 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
276 &index_substr_any_len, "( OLcfgAt:22 NAME 'olcIndexSubstrAnyLen' "
277 "SYNTAX OMsInteger )", NULL, NULL },
278 { "index_substr_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
279 &index_substr_any_step, "( OLcfgAt:23 NAME 'olcIndexSubstrAnyStep' "
280 "SYNTAX OMsInteger )", NULL, NULL },
281 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
282 &config_generic, "( OLcfgAt:24 NAME 'olcLastMod' "
283 "SYNTAX OMsBoolean )", NULL, NULL },
284 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
285 &config_generic, "( OLcfgAt:25 NAME 'olcLimits' "
286 "SYNTAX OMsDirectoryString )", NULL, NULL },
287 { "localSSF", "ssf", 2, 2, 0, ARG_LONG,
288 &local_ssf, "( OLcfgAt:26 NAME 'olcLocalSSF' "
289 "SYNTAX OMsInteger )", NULL, NULL },
290 { "logfile", "file", 2, 2, 0, ARG_MAGIC|CFG_LOGFILE,
291 &config_generic, "( OLcfgAt:27 NAME 'olcLogFile' "
292 "SYNTAX OMsDirectoryString )", NULL, NULL },
293 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
294 &config_loglevel, "( OLcfgAt:28 NAME 'olcLogLevel' "
295 "SYNTAX OMsDirectoryString )", NULL, NULL },
296 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
297 &config_generic, "( OLcfgAt:29 NAME 'olcMaxDerefDepth' "
298 "SYNTAX OMsInteger )", NULL, NULL },
300 { "moduleload", "file", 2, 2, 0, ARG_MAGIC|CFG_MODLOAD,
301 &config_generic, "( OLcfgAt:30 NAME 'olcModuleLoad' "
302 "SYNTAX OMsDirectoryString )", NULL, NULL },
303 { "modulepath", "path", 2, 2, 0, ARG_MAGIC|CFG_MODPATH,
304 &config_generic, "( OLcfgAt:31 NAME 'olcModulePath' "
305 "SYNTAX OMsDirectoryString )", NULL, NULL },
307 /* use standard schema */
308 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
309 &config_generic, NULL, NULL, NULL },
310 { "objectidentifier", NULL, 0, 0, 0, ARG_MAGIC|CFG_OID,
311 &config_generic, "( OLcfgAt:33 NAME 'olcObjectIdentifier' "
312 "SYNTAX OMsDirectoryString )", NULL, NULL },
313 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
314 &config_overlay, "( OLcfgAt:34 NAME 'olcOverlay' "
315 "SUP olcDatabase )", NULL, NULL },
316 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_MAGIC|CFG_SALT,
317 &config_generic, "( OLcfgAt:35 NAME 'olcPasswordCryptSaltFormat' "
318 "SYNTAX OMsDirectoryString )", NULL, NULL },
319 { "password-hash", "hash", 2, 2, 0, ARG_MAGIC,
320 &config_passwd_hash, "( OLcfgAt:36 NAME 'olcPasswordHash' "
321 "SYNTAX OMsDirectoryString )", NULL, NULL },
322 { "pidfile", "file", 2, 2, 0, ARG_STRING,
323 &slapd_pid_file, "( OLcfgAt:37 NAME 'olcPidFile' "
324 "SYNTAX OMsDirectoryString )", NULL, NULL },
326 { "plugin", NULL, 0, 0, 0, ARG_MAGIC|CFG_PLUGIN,
327 &config_generic, "( OLcfgAt:38 NAME 'olcPlugin' "
328 "SYNTAX OMsDirectoryString )", NULL, NULL },
329 { "pluginlog", "filename", 2, 2, 0, ARG_STRING,
330 &slapi_log_file, "( OLcfgAt:39 NAME 'olcPluginLogFile' "
331 "SYNTAX OMsDirectoryString )", NULL, NULL },
333 { "plugin", NULL, 0, 0, 0, ARG_IGNORED,
334 NULL, NULL, NULL, NULL },
335 { "pluginlog", NULL, 0, 0, 0, ARG_IGNORED,
336 NULL, NULL, NULL, NULL },
338 { "readonly", "on|off", 2, 2, 0, ARG_ON_OFF|ARG_MAGIC|CFG_RO,
339 &config_generic, "( OLcfgAt:40 NAME 'olcReadOnly' "
340 "SYNTAX OMsBoolean )", NULL, NULL },
341 { "referral", "url", 2, 2, 0, ARG_MAGIC,
342 &config_referral, "( OLcfgAt:41 NAME 'olcReferral' "
343 "SUP labeledURI )", NULL, NULL },
344 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
345 &config_replica, "( OLcfgAt:42 NAME 'olcReplica' "
346 "SUP labeledURI )", NULL, NULL },
347 { "replica-pidfile", NULL, 0, 0, 0, ARG_IGNORED,
348 NULL, "( OLcfgAt:43 NAME 'olcReplicaPidFile' "
349 "SYNTAX OMsDirectoryString )", NULL, NULL },
350 { "replica-argsfile", NULL, 0, 0, 0, ARG_IGNORED,
351 NULL, "( OLcfgAt:44 NAME 'olcReplicaArgsFile' "
352 "SYNTAX OMsDirectoryString )", NULL, NULL },
353 { "replicationInterval", NULL, 0, 0, 0, ARG_IGNORED,
354 NULL, "( OLcfgAt:45 NAME 'olcReplicationInterval' "
355 "SYNTAX OMsInteger )", NULL, NULL },
356 { "replogfile", "filename", 2, 2, 0, ARG_MAGIC|ARG_STRING|CFG_REPLOG,
357 &config_generic, "( OLcfgAt:46 NAME 'olcReplogFile' "
358 "SYNTAX OMsDirectoryString )", NULL, NULL },
359 { "require", "features", 2, 0, 7, ARG_MAGIC,
360 &config_requires, "( OLcfgAt:47 NAME 'olcRequires' "
361 "SYNTAX OMsDirectoryString )", NULL, NULL },
362 { "restrict", "op_list", 2, 0, 0, ARG_MAGIC,
363 &config_restrict, "( OLcfgAt:48 NAME 'olcRestrict' "
364 "SYNTAX OMsDirectoryString )", NULL, NULL },
365 #ifdef SLAPD_RLOOKUPS
366 { "reverse-lookup", "on|off", 2, 2, 0, ARG_ON_OFF,
367 &use_reverse_lookup, "( OLcfgAt:49 NAME 'olcReverseLookup' "
368 "SYNTAX OMsBoolean )", NULL, NULL },
370 { "reverse-lookup", NULL, 2, 2, 0, ARG_IGNORED,
371 NULL, NULL, NULL, NULL },
373 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_MAGIC,
374 &config_rootdn, "( OLcfgAt:50 NAME 'olcRootDN' "
375 "SYNTAX OMsDN )", NULL, NULL },
376 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
377 &config_generic, "( OLcfgAt:51 NAME 'olcRootDSE' "
378 "SYNTAX OMsDirectoryString )", NULL, NULL },
379 { "rootpw", "password", 2, 2, 0, ARG_DB|ARG_MAGIC,
380 &config_rootpw, "( OLcfgAt:52 NAME 'olcRootPW' "
381 "SYNTAX OMsOctetString )", NULL, NULL },
382 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
383 &config_generic, NULL, NULL, NULL },
384 #ifdef HAVE_CYRUS_SASL
385 { "sasl-host", "host", 2, 2, 0, ARG_STRING|ARG_UNIQUE,
386 &global_host, "( OLcfgAt:53 NAME 'olcSaslHost' "
387 "SYNTAX OMsDirectoryString )", NULL, NULL },
388 { "sasl-realm", "realm", 2, 2, 0, ARG_STRING|ARG_UNIQUE,
389 &global_realm, "( OLcfgAt:54 NAME 'olcSaslRealm' "
390 "SYNTAX OMsDirectoryString )", NULL, NULL },
391 { "sasl-regexp", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZREGEXP,
392 &config_generic, NULL, NULL, NULL },
393 { "sasl-secprops", "properties", 2, 2, 0, ARG_MAGIC|CFG_SASLSECP,
394 &config_generic, "( OLcfgAt:56 NAME 'olcSaslSecProps' "
395 "SYNTAX OMsDirectoryString )", NULL, NULL },
397 { "sasl-host", NULL, 2, 2, 0, ARG_IGNORED,
398 NULL, NULL, NULL, NULL },
399 { "sasl-realm", NULL, 2, 2, 0, ARG_IGNORED,
400 NULL, NULL, NULL, NULL },
401 { "sasl-regexp", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZREGEXP,
402 &config_generic, NULL, NULL, NULL },
403 { "sasl-secprops", NULL, 2, 2, 0, ARG_IGNORED,
404 NULL, NULL, NULL, NULL },
406 { "saslRegexp", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZREGEXP,
407 &config_generic, NULL, NULL, NULL },
408 { "schemacheck", "on|off", 2, 2, 0, ARG_ON_OFF|ARG_MAGIC|CFG_CHECK,
409 &config_generic, "( OLcfgAt:57 NAME 'olcSchemaCheck' "
410 "SYNTAX OMsBoolean )", NULL, NULL },
411 { "schemadn", "dn", 2, 2, 0, ARG_DN|ARG_MAGIC,
412 &config_schema_dn, "( OLcfgAt:58 NAME 'olcSchemaDN' "
413 "SYNTAX OMsDN )", NULL, NULL },
414 { "security", "factors", 2, 0, 0, ARG_MAGIC,
415 &config_security, "( OLcfgAt:59 NAME 'olcSecurity' "
416 "SYNTAX OMsDirectoryString )", NULL, NULL },
417 { "sizelimit", "limit", 2, 2, 0, ARG_MAGIC|CFG_SIZE,
418 &config_sizelimit, "( OLcfgAt:60 NAME 'olcSizeLimit' "
419 "SYNTAX OMsInteger )", NULL, NULL },
420 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_LONG,
421 &sockbuf_max_incoming, "( OLcfgAt:61 NAME 'olcSockbufMaxIncoming' "
422 "SYNTAX OMsInteger )", NULL, NULL },
423 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_LONG,
424 &sockbuf_max_incoming_auth, "( OLcfgAt:62 NAME 'olcSuckbufMaxIncomingAuth' "
425 "SYNTAX OMsInteger )", NULL, NULL },
426 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
427 { "srvtab", "file", 2, 2, 0, ARG_STRING,
428 &ldap_srvtab, "( OLcfgAt:63 NAME 'olcSrvtab' "
429 "SYNTAX OMsDirectoryString )", NULL, NULL },
431 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_MAGIC,
432 &config_suffix, "( OLcfgAt:64 NAME 'olcSuffix' "
433 "SYNTAX OMsDN )", NULL, NULL },
434 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
435 &config_syncrepl, "( OLcfgAt:65 NAME 'olcSyncrepl' "
436 "SYNTAX OMsDirectoryString )", NULL, NULL },
437 { "threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_THREADS,
438 &config_generic, "( OLcfgAt:66 NAME 'olcThreads' "
439 "SYNTAX OMsInteger )", NULL, NULL },
440 { "timelimit", "limit", 2, 2, 0, ARG_MAGIC|CFG_TIME,
441 &config_timelimit, "( OLcfgAt:67 NAME 'olcTimeLimit' "
442 "SYNTAX OMsInteger )", NULL, NULL },
444 { "TLSCACertificateFile", NULL, 0, 0, 0, CFG_TLS_CA_FILE|ARG_MAGIC,
445 &config_tls_option, "( OLcfgAt:68 NAME 'olcTLSCACertificateFile' "
446 "SYNTAX OMsDirectoryString )", NULL, NULL },
447 { "TLSCACertificatePath", NULL, 0, 0, 0, CFG_TLS_CA_PATH|ARG_MAGIC,
448 &config_tls_option, "( OLcfgAt:69 NAME 'olcTLSCACertificatePath' "
449 "SYNTAX OMsDirectoryString )", NULL, NULL },
450 { "TLSCertificateFile", NULL, 0, 0, 0, CFG_TLS_CERT_FILE|ARG_MAGIC,
451 &config_tls_option, "( OLcfgAt:70 NAME 'olcTLSCertificateFile' "
452 "SYNTAX OMsDirectoryString )", NULL, NULL },
453 { "TLSCertificateKeyFile", NULL, 0, 0, 0, CFG_TLS_CERT_KEY|ARG_MAGIC,
454 &config_tls_option, "( OLcfgAt:71 NAME 'olcTLSCertificateKeyFile' "
455 "SYNTAX OMsDirectoryString )", NULL, NULL },
456 { "TLSCipherSuite", NULL, 0, 0, 0, CFG_TLS_CIPHER|ARG_MAGIC,
457 &config_tls_option, "( OLcfgAt:72 NAME 'olcTLSCipherSuite' "
458 "SYNTAX OMsDirectoryString )", NULL, NULL },
459 { "TLSCRLCheck", NULL, 0, 0, 0, CFG_TLS_CRLCHECK|ARG_MAGIC,
460 &config_tls_option, "( OLcfgAt:73 NAME 'olcTLSCRLCheck' "
461 "SYNTAX OMsDirectoryString )", NULL, NULL },
462 { "TLSRandFile", NULL, 0, 0, 0, CFG_TLS_RAND|ARG_MAGIC,
463 &config_tls_option, "( OLcfgAt:74 NAME 'olcTLSRandFile' "
464 "SYNTAX OMsDirectoryString )", NULL, NULL },
465 { "TLSVerifyClient", NULL, 0, 0, 0, CFG_TLS_VERIFY|ARG_MAGIC,
466 &config_tls_verify, "( OLcfgAt:75 NAME 'olcTLSVerifyClient' "
467 "SYNTAX OMsDirectoryString )", NULL, NULL },
469 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
470 NULL, NULL, NULL, NULL },
471 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_MAGIC,
472 &config_updatedn, "( OLcfgAt:76 NAME 'olcUpdateDN' "
473 "SYNTAX OMsDN )", NULL, NULL },
474 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
475 &config_updateref, "( OLcfgAt:77 NAME 'olcUpdateRef' "
476 "SUP labeledURI )", NULL, NULL },
477 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
478 NULL, NULL, NULL, NULL }
483 new_config_args( BackendDB *be, const char *fname, int lineno, int argc, char **argv )
486 c = ch_calloc( 1, sizeof( ConfigArgs ) );
487 if ( c == NULL ) return(NULL);
493 snprintf( c->log, sizeof( c->log ), "%s: line %lu", fname, lineno );
497 int parse_config_table(ConfigTable *Conf, ConfigArgs *c) {
498 int i, rc, arg_user, arg_type, iarg;
501 for(i = 0; Conf[i].name; i++)
502 if( (Conf[i].length && (!strncasecmp(c->argv[0], Conf[i].name, Conf[i].length))) ||
503 (!strcasecmp(c->argv[0], Conf[i].name)) ) break;
504 if(!Conf[i].name) return(ARG_UNKNOWN);
505 arg_type = Conf[i].arg_type;
506 if(arg_type == ARG_IGNORED) {
507 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> ignored\n",
508 c->log, Conf[i].name, 0);
511 if(Conf[i].min_args && (c->argc < Conf[i].min_args)) {
512 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> missing <%s> argument\n",
513 c->log, Conf[i].name, Conf[i].what);
514 return(ARG_BAD_CONF);
516 if(Conf[i].max_args && (c->argc > Conf[i].max_args)) {
517 Debug(LDAP_DEBUG_CONFIG, "%s: extra cruft after <%s> in <%s> line (ignored)\n",
518 c->log, Conf[i].what, Conf[i].name);
520 if((arg_type & ARG_DB) && !c->be) {
521 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> allowed only within database declaration\n",
522 c->log, Conf[i].name, 0);
523 return(ARG_BAD_CONF);
525 if((arg_type & ARG_PRE_DB) && c->be) {
526 Debug(LDAP_DEBUG_CONFIG, "%s: keyword <%s> must appear before any database declaration\n",
527 c->log, Conf[i].name, 0);
528 return(ARG_BAD_CONF);
530 if((arg_type & ARG_PAREN) && *c->argv[1] != '(' /*')'*/) {
531 Debug(LDAP_DEBUG_CONFIG, "%s: old <%s> format not supported\n",
532 c->log, Conf[i].name, 0);
533 return(ARG_BAD_CONF);
535 if((arg_type & ARGS_POINTER) && !Conf[i].arg_item) {
536 Debug(LDAP_DEBUG_CONFIG, "%s: null arg_item for <%s>\n",
537 c->log, Conf[i].name, 0);
538 return(ARG_BAD_CONF);
540 c->type = arg_user = (arg_type & ARGS_USERLAND);
541 c->value_int = c->value_long = c->value_ber_t = 0;
542 c->value_string = NULL;
543 BER_BVZERO( &c->value_dn );
544 BER_BVZERO( &c->value_ndn );
545 if(arg_type & ARGS_NUMERIC) {
547 iarg = 0; larg = 0; barg = 0;
548 switch(arg_type & ARGS_NUMERIC) {
549 case ARG_INT: iarg = atoi(c->argv[1]); break;
550 case ARG_LONG: larg = atol(c->argv[1]); break;
551 case ARG_BER_LEN_T: barg = (ber_len_t)atol(c->argv[1]); break;
553 if(!strcasecmp(c->argv[1], "on")) {
555 } else if(!strcasecmp(c->argv[1], "off")) {
558 Debug(LDAP_DEBUG_CONFIG, "%s: ignoring ", c->log, 0, 0);
559 Debug(LDAP_DEBUG_CONFIG, "invalid %s value (%s) in <%s> line\n",
560 Conf[i].what, c->argv[1], Conf[i].name);
565 j = (arg_type & ARG_NONZERO) ? 1 : 0;
566 rc = (Conf == SystemConfiguration) ? ((arg_type & ARG_SPECIAL) && (larg < index_substr_if_maxlen)) : 0;
567 if(iarg < j || larg < j || barg < j || rc) {
568 larg = larg ? larg : (barg ? barg : iarg);
569 Debug(LDAP_DEBUG_CONFIG, "%s: " , c->log, 0, 0);
570 Debug(LDAP_DEBUG_CONFIG, "invalid %s value (%ld) in <%s> line\n", Conf[i].what, larg, Conf[i].name);
571 return(ARG_BAD_CONF);
574 c->value_long = larg;
575 c->value_ber_t = barg;
577 if(arg_type & ARG_STRING) c->value_string = ch_strdup(c->argv[1]);
578 if(arg_type & ARG_DN) {
580 ber_str2bv( c->argv[1], 0, 0, &bv );
581 rc = dnPrettyNormal( NULL, &bv, &c->value_dn, &c->value_ndn, NULL );
582 if ( rc != LDAP_SUCCESS ) {
583 Debug(LDAP_DEBUG_CONFIG, "%s: " , c->log, 0, 0);
584 Debug(LDAP_DEBUG_CONFIG, "%s DN is invalid %d (%s)\n",
585 Conf[i].name, rc, ldap_err2string( rc ));
586 return(ARG_BAD_CONF);
589 if(arg_type & ARG_MAGIC) {
590 if(!c->be) c->be = frontendDB;
591 rc = (*((ConfigDriver*)Conf[i].arg_item))(c);
592 if(c->be == frontendDB) c->be = NULL;
594 Debug(LDAP_DEBUG_CONFIG, "%s: handler for <%s> exited with %d!",
595 c->log, Conf[i].name, rc);
596 return(ARG_BAD_CONF);
600 if(arg_type & ARGS_POINTER) switch(arg_type & ARGS_POINTER) {
602 case ARG_INT: *((int*)Conf[i].arg_item) = iarg; break;
603 case ARG_LONG: *((long*)Conf[i].arg_item) = larg; break;
604 case ARG_BER_LEN_T: *((ber_len_t*)Conf[i].arg_item) = barg; break;
606 char *cc = *((char**)Conf[i].arg_item);
608 if (arg_type & ARG_UNIQUE) {
609 Debug(LDAP_DEBUG_CONFIG, "%s: already set %s!\n",
610 c->log, Conf[i].name, 0 );
611 return(ARG_BAD_CONF);
613 ch_free(cc); /* potential memory leak */
615 *(char **)Conf[i].arg_item = c->value_string;
623 init_config_schema(ConfigTable *ct) {
624 LDAPAttributeType *at;
628 for (i=0; ct[i].name; i++ ) {
629 if ( !ct[i].attribute ) continue;
630 at = ldap_str2attributetype( ct[i].attribute,
631 &code, &err, LDAP_SCHEMA_ALLOW_ALL );
633 fprintf( stderr, "init_config_schema: AttributeType \"%s\": %s, %s\n",
634 ct[i].attribute, ldap_scherr2str(code), err );
637 code = at_add( at, &err );
639 fprintf( stderr, "init_config_schema: AttributeType \"%s\": %s, %s\n",
640 ct[i].attribute, scherr2str(code), err );
643 code = slap_str2ad( at->at_names[0], &ct[i].ad, &err );
645 fprintf( stderr, "init_config_schema: AttributeType \"%s\": %s\n",
646 ct[i].attribute, err );
653 read_config(const char *fname, int depth) {
657 for (i=0; OidMacros[i].name; i++ ) {
658 argv[1] = OidMacros[i].name;
659 argv[2] = OidMacros[i].oid;
660 parse_oidm( "slapd", i, 3, argv );
662 i = init_config_schema(SystemConfiguration);
664 return read_config_file(fname, depth, NULL);
668 read_config_file(const char *fname, int depth, ConfigArgs *cf)
674 c = ch_calloc( 1, sizeof( ConfigArgs ) );
680 memcpy( c, cf, sizeof( ConfigArgs ) );
682 c->depth = depth; /* XXX */
688 c->argv = ch_calloc( ARGS_STEP + 1, sizeof( *c->argv ) );
689 c->argv_size = ARGS_STEP + 1;
691 fp = fopen( fname, "r" );
694 Debug(LDAP_DEBUG_ANY,
695 "could not open config file \"%s\": %s (%d)\n",
696 fname, strerror(errno), errno);
700 Debug(LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0);
704 while ( fp_getline( fp, c ) ) {
705 /* skip comments and blank lines */
706 if ( c->line[0] == '#' || c->line[0] == '\0' ) {
710 snprintf( c->log, sizeof( c->log ), "%s: line %lu",
711 c->fname, c->lineno );
713 if ( fp_parse_line( c ) ) {
718 Debug(LDAP_DEBUG_CONFIG, "%s: bad config line (ignored)\n", c->log, 0, 0);
722 rc = parse_config_table( SystemConfiguration, c );
726 if ( rc & ARGS_USERLAND ) {
727 switch(rc) { /* XXX a usertype would be opaque here */
729 Debug(LDAP_DEBUG_CONFIG, "%s: unknown user type <%d>\n",
730 c->log, *c->argv, 0);
734 } else if ( rc == ARG_BAD_CONF || rc != ARG_UNKNOWN ) {
737 } else if ( c->bi && c->bi->bi_config ) { /* XXX to check: could both be/bi_config? oops */
738 rc = (*c->bi->bi_config)(c->bi, c->fname, c->lineno, c->argc, c->argv);
741 case SLAP_CONF_UNKNOWN:
742 Debug(LDAP_DEBUG_CONFIG, "%s: "
743 "unknown directive <%s> inside backend info definition (ignored)\n",
744 c->log, *c->argv, 0);
751 } else if ( c->be && c->be->be_config ) {
752 rc = (*c->be->be_config)(c->be, c->fname, c->lineno, c->argc, c->argv);
755 case SLAP_CONF_UNKNOWN:
756 Debug( LDAP_DEBUG_CONFIG, "%s: "
757 "unknown directive <%s> inside backend database definition (ignored)\n",
758 c->log, *c->argv, 0);
765 } else if ( frontendDB->be_config ) {
766 rc = (*frontendDB->be_config)(frontendDB, c->fname, (int)c->lineno, c->argc, c->argv);
769 case SLAP_CONF_UNKNOWN:
770 Debug( LDAP_DEBUG_CONFIG, "%s: "
771 "unknown directive <%s> inside global database definition (ignored)\n",
772 c->log, *c->argv, 0);
780 Debug(LDAP_DEBUG_CONFIG, "%s: "
781 "unknown directive <%s> outside backend info and database definitions (ignored)\n",
782 c->log, *c->argv, 0);
790 if ( BER_BVISNULL( &frontendDB->be_schemadn ) ) {
791 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
792 &frontendDB->be_schemadn );
793 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
794 if ( rc != LDAP_SUCCESS ) {
795 Debug(LDAP_DEBUG_ANY, "%s: "
796 "unable to normalize default schema DN \"%s\"\n",
797 c->log, frontendDB->be_schemadn.bv_val, 0 );
798 /* must not happen */
815 config_generic(ConfigArgs *c) {
816 char *p = strchr(c->line,'(' /*')'*/);
821 if(!(c->bi = backend_info(c->argv[1]))) {
822 Debug(LDAP_DEBUG_ANY, "%s: "
823 "backend %s failed init!\n", c->log, c->argv[1], 0);
830 if(!(c->be = backend_db_init(c->argv[1]))) {
831 Debug(LDAP_DEBUG_ANY, "%s: "
832 "database %s failed init!\n", c->log, c->argv[1], 0);
838 ldap_pvt_thread_set_concurrency(c->value_long);
842 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
843 connection_pool_max = c->value_int; /* save for reference */
847 lutil_salt_format(c->argv[1]);
851 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
857 c->be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
859 c->be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
863 if (slap_sasl_setpolicy( c->argv[1] )) {
864 Debug(LDAP_DEBUG_ANY, "%s: unable to parse value \"%s\" in"
865 " \"authz-policy <policy>\"\n",
866 c->log, c->argv[1], 0 );
872 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
876 #ifdef HAVE_CYRUS_SASL
879 char *txt = slap_sasl_secprops( c->argv[1] );
881 Debug(LDAP_DEBUG_ANY, "%s: sasl-secprops: %s\n",
889 c->be->be_max_deref_depth = c->value_int;
893 if(parse_oidm(c->fname, c->lineno, c->argc, c->argv)) return(1);
897 if(parse_oc(c->fname, c->lineno, p, c->argv)) return(1);
901 if(parse_cr(c->fname, c->lineno, p, c->argv)) return(1);
905 if(parse_at(c->fname, c->lineno, p, c->argv)) return(1);
909 ad_define_option(NULL, NULL, 0);
910 for(i = 1; i < c->argc; i++)
911 if(ad_define_option(c->argv[i], c->fname, c->lineno))
916 global_schemacheck = c->value_int;
917 if(!global_schemacheck) Debug(LDAP_DEBUG_ANY, "%s: "
918 "schema checking disabled! your mileage may vary!\n",
923 parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv);
928 c->be->be_auditlogfile = c->value_string;
933 if(SLAP_MONITOR(c->be)) {
934 Debug(LDAP_DEBUG_ANY, "%s: "
935 "\"replogfile\" should not be used "
936 "inside monitor database\n",
938 return(0); /* FIXME: should this be an error? */
941 c->be->be_replogfile = c->value_string;
945 if(read_root_dse_file(c->argv[1])) {
946 Debug(LDAP_DEBUG_ANY, "%s: "
947 "could not read \"rootDSE <filename>\" line\n",
954 FILE *logfile = fopen(c->argv[1], "w");
955 if(logfile) lutil_debug_file(logfile);
960 if(SLAP_NOLASTMODCMD(c->be)) {
961 Debug(LDAP_DEBUG_ANY, "%s: "
962 "lastmod not available for %s databases\n",
963 c->log, c->be->bd_info->bi_type, 0);
967 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
969 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
974 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
979 if(module_path(c->argv[1])) return(1);
985 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
987 slapi_plugins_used++;
991 #ifdef SLAP_AUTH_REWRITE
993 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
1000 Debug(LDAP_DEBUG_ANY, "%s: unknown CFG_TYPE %d"
1001 "(ignored)\n", c->log, c->type, 0);
1009 config_search_base(ConfigArgs *c) {
1012 if(c->bi || c->be != frontendDB) {
1013 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
1014 "prior to any backend or database definition\n",
1019 if(default_search_nbase.bv_len) {
1020 Debug(LDAP_DEBUG_ANY, "%s: "
1021 "default search base \"%s\" already defined "
1022 "(discarding old)\n",
1023 c->log, default_search_base.bv_val, 0);
1024 free(default_search_base.bv_val);
1025 free(default_search_nbase.bv_val);
1028 default_search_base = c->value_dn;
1029 default_search_nbase = c->value_ndn;
1034 config_passwd_hash(ConfigArgs *c) {
1036 if(default_passwd_hash) {
1037 Debug(LDAP_DEBUG_ANY, "%s: "
1038 "already set default password_hash\n",
1042 for(i = 1; i < c->argc; i++) {
1043 if(!lutil_passwd_scheme(c->argv[i])) {
1044 Debug(LDAP_DEBUG_ANY, "%s: "
1045 "password scheme \"%s\" not available\n",
1046 c->log, c->argv[i], 0);
1048 ldap_charray_add(&default_passwd_hash, c->argv[i]);
1050 if(!default_passwd_hash) {
1051 Debug(LDAP_DEBUG_ANY, "%s: no valid hashes found\n",
1060 config_schema_dn(ConfigArgs *c) {
1063 c->be->be_schemadn = c->value_dn;
1064 c->be->be_schemandn = c->value_ndn;
1069 config_sizelimit(ConfigArgs *c) {
1072 struct slap_limits_set *lim = &c->be->be_def_limit;
1073 for(i = 1; i < c->argc; i++) {
1074 if(!strncasecmp(c->argv[i], "size", 4)) {
1075 rc = limits_parse_one(c->argv[i], lim);
1077 Debug(LDAP_DEBUG_ANY, "%s: "
1078 "unable to parse value \"%s\" in \"sizelimit <limit>\" line\n",
1079 c->log, c->argv[i], 0);
1083 if(!strcasecmp(c->argv[i], "unlimited")) {
1084 lim->lms_s_soft = -1;
1086 lim->lms_s_soft = strtol(c->argv[i], &next, 0);
1087 if(next == c->argv[i]) {
1088 Debug(LDAP_DEBUG_ANY, "%s: "
1089 "unable to parse limit \"%s\" in \"sizelimit <limit>\" line\n",
1090 c->log, c->argv[i], 0);
1092 } else if(next[0] != '\0') {
1093 Debug(LDAP_DEBUG_ANY, "%s: "
1094 "trailing chars \"%s\" in \"sizelimit <limit>\" line (ignored)\n",
1098 lim->lms_s_hard = 0;
1105 config_timelimit(ConfigArgs *c) {
1108 struct slap_limits_set *lim = &c->be->be_def_limit;
1109 for(i = 1; i < c->argc; i++) {
1110 if(!strncasecmp(c->argv[i], "time", 4)) {
1111 rc = limits_parse_one(c->argv[i], lim);
1113 Debug(LDAP_DEBUG_ANY, "%s: "
1114 "unable to parse value \"%s\" in \"timelimit <limit>\" line\n",
1115 c->log, c->argv[i], 0);
1119 if(!strcasecmp(c->argv[i], "unlimited")) {
1120 lim->lms_t_soft = -1;
1122 lim->lms_t_soft = strtol(c->argv[i], &next, 0);
1123 if(next == c->argv[i]) {
1124 Debug(LDAP_DEBUG_ANY, "%s: "
1125 "unable to parse limit \"%s\" in \"timelimit <limit>\" line\n",
1126 c->log, c->argv[i], 0);
1128 } else if(next[0] != '\0') {
1129 Debug(LDAP_DEBUG_ANY, "%s: "
1130 "trailing chars \"%s\" in \"timelimit <limit>\" line (ignored)\n",
1134 lim->lms_t_hard = 0;
1141 config_overlay(ConfigArgs *c) {
1142 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1])) {
1144 Debug(LDAP_DEBUG_ANY, "%s: (optional) %s overlay \"%s\" configuration failed (ignored)\n",
1145 c->log, c->be == frontendDB ? "global " : "", c->argv[1][1]);
1146 } else if(overlay_config(c->be, c->argv[1])) {
1153 config_suffix(ConfigArgs *c) {
1155 struct berval pdn, ndn;
1157 #ifdef SLAPD_MONITOR_DN
1158 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
1159 Debug(LDAP_DEBUG_ANY, "%s: "
1160 "\"%s\" is reserved for monitoring slapd\n",
1161 c->log, SLAPD_MONITOR_DN, 0);
1168 tbe = select_backend(&ndn, 0, 0);
1170 Debug(LDAP_DEBUG_ANY, "%s: suffix already served by this backend! (ignored)\n",
1175 Debug(LDAP_DEBUG_ANY, "%s: suffix already served by a preceding backend \"%s\"\n",
1176 c->log, tbe->be_suffix[0].bv_val, 0);
1180 } else if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
1181 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
1182 "base provided \"%s\" (assuming okay)\n",
1183 c->log, default_search_base.bv_val, 0);
1185 ber_bvarray_add(&c->be->be_suffix, &pdn);
1186 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
1191 config_rootdn(ConfigArgs *c) {
1192 c->be->be_rootdn = c->value_dn;
1193 c->be->be_rootndn = c->value_ndn;
1198 config_rootpw(ConfigArgs *c) {
1199 Backend *tbe = select_backend(&c->be->be_rootndn, 0, 0);
1201 Debug(LDAP_DEBUG_ANY, "%s: "
1202 "rootpw can only be set when rootdn is under suffix\n",
1206 ber_str2bv(c->argv[1], 0, 1, &c->be->be_rootpw);
1210 /* restrictops, allows, disallows, requires, loglevel */
1212 struct verb_mask_list { char *word; int mask; };
1215 verb_to_mask(ConfigArgs *c, struct verb_mask_list *v, int word) {
1217 for(j = 0; v[j].word; j++)
1218 if(!strcasecmp(c->argv[word], v[j].word))
1224 verbs_to_mask(ConfigArgs *c, struct verb_mask_list *v, slap_mask_t *m) {
1226 for(i = 1; i < c->argc; i++) {
1227 j = verb_to_mask(c, v, i);
1228 if(!v[j].word) return(1);
1235 config_restrict(ConfigArgs *c) {
1236 slap_mask_t restrictops = 0;
1238 struct verb_mask_list restrictable_exops[] = {
1239 { LDAP_EXOP_START_TLS, SLAP_RESTRICT_EXOP_START_TLS },
1240 { LDAP_EXOP_MODIFY_PASSWD, SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
1241 { LDAP_EXOP_X_WHO_AM_I, SLAP_RESTRICT_EXOP_WHOAMI },
1242 { LDAP_EXOP_X_CANCEL, SLAP_RESTRICT_EXOP_CANCEL },
1245 struct verb_mask_list restrictable_ops[] = {
1246 { "bind", SLAP_RESTRICT_OP_BIND },
1247 { "add", SLAP_RESTRICT_OP_ADD },
1248 { "modify", SLAP_RESTRICT_OP_MODIFY },
1249 { "modrdn", SLAP_RESTRICT_OP_RENAME },
1250 { "rename", SLAP_RESTRICT_OP_RENAME },
1251 { "delete", SLAP_RESTRICT_OP_DELETE },
1252 { "search", SLAP_RESTRICT_OP_SEARCH },
1253 { "compare", SLAP_RESTRICT_OP_COMPARE },
1254 { "read", SLAP_RESTRICT_OP_READS },
1255 { "write", SLAP_RESTRICT_OP_WRITES },
1259 for(i = 1; i < c->argc; i++) {
1260 j = verb_to_mask(c, restrictable_ops, i);
1261 if(restrictable_ops[j].word) {
1262 restrictops |= restrictable_ops[j].mask;
1264 } else if(!strncasecmp(c->argv[i], "extended", STRLENOF("extended"))) {
1265 char *e = c->argv[i] + STRLENOF("extended");
1267 int k = verb_to_mask(c, restrictable_exops, e[1]);
1268 if(restrictable_exops[k].word) {
1269 restrictops |= restrictable_exops[k].mask;
1273 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
1274 restrictops |= SLAP_RESTRICT_OP_EXTENDED;
1279 c->be->be_restrictops |= restrictops;
1282 Debug(LDAP_DEBUG_ANY, "%s: "
1283 "unknown operation %s in \"restrict <features>\" line\n",
1284 c->log, c->argv[i], 0);
1289 config_allows(ConfigArgs *c) {
1290 slap_mask_t allows = 0;
1292 struct verb_mask_list allowable_ops[] = {
1293 { "bind_v2", SLAP_ALLOW_BIND_V2 },
1294 { "bind_anon_cred", SLAP_ALLOW_BIND_ANON_CRED },
1295 { "bind_anon_dn", SLAP_ALLOW_BIND_ANON_DN },
1296 { "update_anon", SLAP_ALLOW_UPDATE_ANON },
1299 i = verbs_to_mask(c, allowable_ops, &allows);
1301 Debug(LDAP_DEBUG_ANY, "%s: "
1302 "unknown feature %s in \"allow <features>\" line\n",
1303 c->log, c->argv[i], 0);
1306 global_allows |= allows;
1311 config_disallows(ConfigArgs *c) {
1312 slap_mask_t disallows = 0;
1314 struct verb_mask_list disallowable_ops[] = {
1315 { "bind_anon", SLAP_DISALLOW_BIND_ANON },
1316 { "bind_simple", SLAP_DISALLOW_BIND_SIMPLE },
1317 { "bind_krb4", SLAP_DISALLOW_BIND_KRBV4 },
1318 { "tls_2_anon", SLAP_DISALLOW_TLS_2_ANON },
1319 { "tls_authc", SLAP_DISALLOW_TLS_AUTHC },
1322 i = verbs_to_mask(c, disallowable_ops, &disallows);
1324 Debug(LDAP_DEBUG_ANY, "%s: "
1325 "unknown feature %s in \"disallow <features>\" line\n",
1326 c->log, c->argv[i], 0);
1329 global_disallows |= disallows;
1334 config_requires(ConfigArgs *c) {
1335 slap_mask_t requires = 0;
1337 struct verb_mask_list requires_ops[] = {
1338 { "bind", SLAP_REQUIRE_BIND },
1339 { "LDAPv3", SLAP_REQUIRE_LDAP_V3 },
1340 { "authc", SLAP_REQUIRE_AUTHC },
1341 { "sasl", SLAP_REQUIRE_SASL },
1342 { "strong", SLAP_REQUIRE_STRONG },
1345 i = verbs_to_mask(c, requires_ops, &requires);
1347 Debug(LDAP_DEBUG_ANY, "%s: "
1348 "unknown feature %s in \"require <features>\" line\n",
1349 c->log, c->argv[i], 0);
1352 c->be->be_requires = requires;
1357 config_loglevel(ConfigArgs *c) {
1360 struct verb_mask_list loglevel_ops[] = {
1361 { "Trace", LDAP_DEBUG_TRACE },
1362 { "Packets", LDAP_DEBUG_PACKETS },
1363 { "Args", LDAP_DEBUG_ARGS },
1364 { "Conns", LDAP_DEBUG_CONNS },
1365 { "BER", LDAP_DEBUG_BER },
1366 { "Filter", LDAP_DEBUG_FILTER },
1367 { "Config", LDAP_DEBUG_CONFIG },
1368 { "ACL", LDAP_DEBUG_ACL },
1369 { "Stats", LDAP_DEBUG_STATS },
1370 { "Stats2", LDAP_DEBUG_STATS2 },
1371 { "Shell", LDAP_DEBUG_SHELL },
1372 { "Parse", LDAP_DEBUG_PARSE },
1373 { "Cache", LDAP_DEBUG_CACHE },
1374 { "Index", LDAP_DEBUG_INDEX },
1380 for( i=1; i < c->argc; i++ ) {
1383 if ( isdigit( c->argv[i][0] ) ) {
1384 level = strtol( c->argv[i], &next, 10 );
1385 if ( next == NULL || next[0] != '\0' ) {
1386 Debug( LDAP_DEBUG_ANY,
1387 "%s: unable to parse level \"%s\" "
1388 "in \"loglevel <level> [...]\" line.\n",
1389 c->log, c->argv[i], 0);
1393 int j = verb_to_mask(c, loglevel_ops, c->argv[i][0]);
1394 if(!loglevel_ops[j].word) {
1395 Debug( LDAP_DEBUG_ANY,
1396 "%s: unknown level \"%s\" "
1397 "in \"loglevel <level> [...]\" line.\n",
1398 c->log, c->argv[i], 0);
1401 level = loglevel_ops[j].mask;
1403 ldap_syslog |= level;
1409 config_syncrepl(ConfigArgs *c) {
1410 if(SLAP_SHADOW(c->be)) {
1411 Debug(LDAP_DEBUG_ANY, "%s: "
1412 "syncrepl: database already shadowed.\n",
1415 } else if(add_syncrepl(c->be, c->argv, c->argc)) {
1418 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SYNC_SHADOW);
1423 config_referral(ConfigArgs *c) {
1424 struct berval vals[2];
1425 if(validate_global_referral(c->argv[1])) {
1426 Debug(LDAP_DEBUG_ANY, "%s: "
1427 "invalid URL (%s) in \"referral\" line.\n",
1428 c->log, c->argv[1], 0);
1432 ber_str2bv(c->argv[1], 0, 1, &vals[0]);
1433 vals[1].bv_val = NULL; vals[1].bv_len = 0;
1434 if(value_add(&default_referral, vals)) return(LDAP_OTHER);
1439 config_security(ConfigArgs *c) {
1440 slap_ssf_set_t *set = &c->be->be_ssf_set;
1443 for(i = 1; i < c->argc; i++) {
1446 if(!strncasecmp(c->argv[i], "ssf=", 4)) {
1447 tgt = &set->sss_ssf;
1448 src = &c->argv[i][4];
1449 } else if(!strncasecmp(c->argv[i], "transport=", 10)) {
1450 tgt = &set->sss_transport;
1451 src = &c->argv[i][10];
1452 } else if(!strncasecmp(c->argv[i], "tls=", 4)) {
1453 tgt = &set->sss_tls;
1454 src = &c->argv[i][4];
1455 } else if(!strncasecmp(c->argv[i], "sasl=", 5)) {
1456 tgt = &set->sss_sasl;
1457 src = &c->argv[i][5];
1458 } else if(!strncasecmp(c->argv[i], "update_ssf=", 11)) {
1459 tgt = &set->sss_update_ssf;
1460 src = &c->argv[i][11];
1461 } else if(!strncasecmp(c->argv[i], "update_transport=", 17)) {
1462 tgt = &set->sss_update_transport;
1463 src = &c->argv[i][17];
1464 } else if(!strncasecmp(c->argv[i], "update_tls=", 11)) {
1465 tgt = &set->sss_update_tls;
1466 src = &c->argv[i][11];
1467 } else if(!strncasecmp(c->argv[i], "update_sasl=", 12)) {
1468 tgt = &set->sss_update_sasl;
1469 src = &c->argv[i][12];
1470 } else if(!strncasecmp(c->argv[i], "simple_bind=", 12)) {
1471 tgt = &set->sss_simple_bind;
1472 src = &c->argv[i][12];
1474 Debug(LDAP_DEBUG_ANY, "%s: "
1475 "unknown factor %s in \"security <factors>\" line\n",
1476 c->log, c->argv[i], 0);
1480 *tgt = strtol(src, &next, 10);
1481 if(next == NULL || next[0] != '\0' ) {
1482 Debug(LDAP_DEBUG_ANY, "%s: "
1483 "unable to parse factor \"%s\" in \"security <factors>\" line\n",
1484 c->log, c->argv[i], 0);
1492 config_replica(ConfigArgs *c) {
1494 char *replicahost, *replicalog = NULL;
1497 if(SLAP_MONITOR(c->be)) {
1498 Debug(LDAP_DEBUG_ANY, "%s: "
1499 "\"replica\" should not be used inside monitor database\n",
1501 return(0); /* FIXME: should this be an error? */
1504 for(i = 1; i < c->argc; i++) {
1505 if(!strncasecmp(c->argv[i], "host=", STRLENOF("host="))) {
1506 replicalog = c->argv[i] + STRLENOF("host=");
1507 nr = add_replica_info(c->be, c->argv[i] + STRLENOF("host="));
1509 } else if(!strncasecmp(c->argv[i], "uri=", STRLENOF("uri="))) {
1510 if(ldap_url_parse(c->argv[i] + STRLENOF("uri="), &ludp) != LDAP_SUCCESS) {
1511 Debug(LDAP_DEBUG_ANY, "%s: "
1512 "replica line contains invalid "
1513 "uri definition.\n", c->log, 0, 0);
1516 if(!ludp->lud_host) {
1517 Debug(LDAP_DEBUG_ANY, "%s: "
1518 "replica line contains invalid "
1519 "uri definition - missing hostname.\n",
1523 replicahost = ch_malloc(strlen(c->argv[i]));
1525 Debug(LDAP_DEBUG_ANY,
1526 "out of memory in read_config\n", 0, 0, 0);
1527 ldap_free_urldesc(ludp);
1530 sprintf(replicahost, "%s:%d", ludp->lud_host, ludp->lud_port);
1531 replicalog = c->argv[i] + STRLENOF("uri=");
1532 nr = add_replica_info(c->be, replicahost);
1533 ldap_free_urldesc(ludp);
1534 ch_free(replicahost);
1539 Debug(LDAP_DEBUG_ANY, "%s: "
1540 "missing host or uri in \"replica\" line\n",
1543 } else if(nr == -1) {
1544 Debug(LDAP_DEBUG_ANY, "%s: "
1545 "unable to add replica \"%s\"\n",
1546 c->log, replicalog, 0);
1549 for(i = 1; i < c->argc; i++) {
1550 if(!strncasecmp(c->argv[i], "suffix=", STRLENOF( "suffix="))) {
1551 switch(add_replica_suffix(c->be, nr, c->argv[i] + STRLENOF("suffix="))) {
1553 Debug(LDAP_DEBUG_ANY, "%s: "
1554 "suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
1555 c->log, c->argv[i] + STRLENOF("suffix="), 0);
1558 Debug(LDAP_DEBUG_ANY, "%s: "
1559 "unable to normalize suffix in \"replica\" line (ignored)\n",
1564 } else if(!strncasecmp(c->argv[i], "attr", STRLENOF("attr"))) {
1566 char *arg = c->argv[i] + STRLENOF("attr");
1574 if(add_replica_attrs(c->be, nr, arg + 1, exclude)) {
1575 Debug(LDAP_DEBUG_ANY, "%s: "
1576 "attribute \"%s\" in \"replica\" line is unknown\n",
1577 c->log, arg + 1, 0);
1587 config_updatedn(ConfigArgs *c) {
1590 if(SLAP_SHADOW(c->be)) {
1591 Debug(LDAP_DEBUG_ANY, "%s: "
1592 "updatedn: database already shadowed.\n",
1597 ber_str2bv(c->argv[1], 0, 0, &dn);
1599 rc = dnNormalize(0, NULL, NULL, &dn, &c->be->be_update_ndn, NULL);
1601 if(rc != LDAP_SUCCESS) {
1602 Debug(LDAP_DEBUG_ANY, "%s: "
1603 "updatedn DN is invalid: %d (%s)\n",
1604 c->log, rc, ldap_err2string( rc ));
1608 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
1613 config_updateref(ConfigArgs *c) {
1614 struct berval vals[2];
1615 if(!SLAP_SHADOW(c->be)) {
1616 Debug(LDAP_DEBUG_ANY, "%s: "
1617 "updateref line must after syncrepl or updatedn.\n",
1622 if(validate_global_referral(c->argv[1])) {
1623 Debug(LDAP_DEBUG_ANY, "%s: "
1624 "invalid URL (%s) in \"updateref\" line.\n",
1625 c->log, c->argv[1], 0);
1628 ber_str2bv(c->argv[1], 0, 0, &vals[0]);
1629 vals[1].bv_val = NULL;
1630 if(value_add(&c->be->be_update_refs, vals)) return(LDAP_OTHER);
1634 /* XXX meaningless in ldif */
1637 config_include(ConfigArgs *c) {
1638 char *savefname = ch_strdup(c->argv[1]);
1639 unsigned long savelineno = c->lineno;
1641 rc = read_config_file(savefname, c->depth + 1, c);
1643 c->lineno = savelineno - 1;
1649 config_tls_option(ConfigArgs *c) {
1652 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; break;
1653 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
1654 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
1655 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
1656 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
1657 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
1658 #ifdef HAVE_OPENSSL_CRL
1659 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
1661 default: Debug(LDAP_DEBUG_ANY, "%s: "
1662 "unknown tls_option <%x>\n",
1663 c->log, c->type, 0);
1665 return(ldap_pvt_tls_set_option(NULL, flag, c->argv[1]));
1669 config_tls_verify(ConfigArgs *c) {
1671 if(isdigit((unsigned char)c->argv[1][0])) {
1672 i = atoi(c->argv[1]);
1673 return(ldap_pvt_tls_set_option(NULL, LDAP_OPT_X_TLS_REQUIRE_CERT, &i));
1675 return(ldap_int_tls_config(NULL, LDAP_OPT_X_TLS_REQUIRE_CERT, c->argv[1]));
1680 /* -------------------------------------- */
1684 strtok_quote( char *line, char *sep )
1690 strtok_quote_ptr = NULL;
1691 if ( line != NULL ) {
1694 while ( *next && strchr( sep, *next ) ) {
1698 if ( *next == '\0' ) {
1704 for ( inquote = 0; *next; ) {
1712 AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
1718 next + 1, strlen( next + 1 ) + 1 );
1719 next++; /* dont parse the escaped character */
1724 if ( strchr( sep, *next ) != NULL ) {
1725 strtok_quote_ptr = next;
1738 static char buf[BUFSIZ];
1740 static size_t lmax, lcur;
1742 #define CATLINE( buf ) \
1744 size_t len = strlen( buf ); \
1745 while ( lcur + len + 1 > lmax ) { \
1747 line = (char *) ch_realloc( line, lmax ); \
1749 strcpy( line + lcur, buf ); \
1754 fp_getline_init(ConfigArgs *c) {
1760 fp_getline( FILE *fp, ConfigArgs *c )
1768 /* avoid stack of bufs */
1769 if ( strncasecmp( line, "include", STRLENOF( "include" ) ) == 0 ) {
1775 while ( fgets( buf, sizeof( buf ), fp ) ) {
1776 p = strchr( buf, '\n' );
1778 if ( p > buf && p[-1] == '\r' ) {
1786 && ( p = line + strlen( line ) - 1 )[0] == '\\'
1793 if ( !isspace( (unsigned char)buf[0] ) ) {
1804 return(line[0] ? 1 : 0);
1808 fp_parse_line(ConfigArgs *c)
1811 char *tline = ch_strdup(c->line);
1812 char *hide[] = { "rootpw", "replica", "bindpw", "pseudorootpw", "dbpasswd", '\0' };
1816 token = strtok_quote(tline, " \t");
1818 if(token) for(i = 0; hide[i]; i++) if(!strcasecmp(token, hide[i])) break;
1819 if(strtok_quote_ptr) *strtok_quote_ptr = ' ';
1820 Debug(LDAP_DEBUG_CONFIG, "line %lu (%s%s)\n", c->lineno, hide[i] ? hide[i] : c->line, hide[i] ? " ***" : "");
1821 if(strtok_quote_ptr) *strtok_quote_ptr = '\0';
1823 for(; token; token = strtok_quote(NULL, " \t")) {
1824 if(c->argc == c->argv_size - 1) {
1826 tmp = ch_realloc(c->argv, (c->argv_size + ARGS_STEP) * sizeof(*c->argv));
1828 Debug(LDAP_DEBUG_ANY, "line %lu: out of memory\n", c->lineno, 0, 0);
1832 c->argv_size += ARGS_STEP;
1834 c->argv[c->argc++] = token;
1836 c->argv[c->argc] = NULL;
1842 /* Loads ucdata, returns 1 if loading, 0 if already loaded, -1 on error */
1844 load_ucdata( char *path )
1847 static int loaded = 0;
1853 err = ucdata_load( path ? path : SLAPD_DEFAULT_UCDATA, UCDATA_ALL );
1855 Debug( LDAP_DEBUG_ANY, "error loading ucdata (error %d)\n",
1863 /* ucdata is now hardcoded */
1872 ucdata_unload( UCDATA_ALL );
1874 /* NOTE: in case of early exit, frontendDB can be NULL */
1875 if ( frontendDB->be_schemandn.bv_val )
1876 free( frontendDB->be_schemandn.bv_val );
1877 if ( frontendDB->be_schemadn.bv_val )
1878 free( frontendDB->be_schemadn.bv_val );
1879 if ( frontendDB->be_acl )
1880 acl_destroy( frontendDB->be_acl, NULL );
1883 if ( slapd_args_file )
1884 free ( slapd_args_file );
1885 if ( slapd_pid_file )
1886 free ( slapd_pid_file );
1887 if ( default_passwd_hash )
1888 ldap_charray_free( default_passwd_hash );
1901 si = (syncinfo_t *) ch_calloc( 1, sizeof( syncinfo_t ) );
1904 Debug( LDAP_DEBUG_ANY, "out of memory in add_syncrepl\n", 0, 0, 0 );
1908 si->si_tls = SYNCINFO_TLS_OFF;
1909 si->si_bindmethod = LDAP_AUTH_SIMPLE;
1910 si->si_schemachecking = 0;
1911 ber_str2bv( "(objectclass=*)", STRLENOF("(objectclass=*)"), 1,
1912 &si->si_filterstr );
1913 si->si_base.bv_val = NULL;
1914 si->si_scope = LDAP_SCOPE_SUBTREE;
1915 si->si_attrsonly = 0;
1916 si->si_anlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ));
1917 si->si_exanlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ));
1918 si->si_attrs = NULL;
1919 si->si_allattrs = 0;
1920 si->si_allopattrs = 0;
1921 si->si_exattrs = NULL;
1922 si->si_type = LDAP_SYNC_REFRESH_ONLY;
1923 si->si_interval = 86400;
1924 si->si_retryinterval = NULL;
1925 si->si_retrynum_init = NULL;
1926 si->si_retrynum = NULL;
1927 si->si_manageDSAit = 0;
1931 si->si_presentlist = NULL;
1932 LDAP_LIST_INIT( &si->si_nonpresentlist );
1933 ldap_pvt_thread_mutex_init( &si->si_mutex );
1935 rc = parse_syncrepl_line( cargv, cargc, si );
1938 Debug( LDAP_DEBUG_ANY, "failed to add syncinfo\n", 0, 0, 0 );
1939 syncinfo_free( si );
1942 Debug( LDAP_DEBUG_CONFIG,
1943 "Config: ** successfully added syncrepl \"%s\"\n",
1944 BER_BVISNULL( &si->si_provideruri ) ?
1945 "(null)" : si->si_provideruri.bv_val, 0, 0 );
1946 if ( !si->si_schemachecking ) {
1947 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NO_SCHEMA_CHECK;
1950 be->be_syncinfo = si;
1955 /* NOTE: used & documented in slapd.conf(5) */
1957 #define PROVIDERSTR "provider"
1958 #define TYPESTR "type"
1959 #define INTERVALSTR "interval"
1960 #define SEARCHBASESTR "searchbase"
1961 #define FILTERSTR "filter"
1962 #define SCOPESTR "scope"
1963 #define ATTRSSTR "attrs"
1964 #define ATTRSONLYSTR "attrsonly"
1965 #define SLIMITSTR "sizelimit"
1966 #define TLIMITSTR "timelimit"
1967 #define SCHEMASTR "schemachecking"
1968 #define BINDMETHSTR "bindmethod"
1969 #define SIMPLESTR "simple"
1970 #define SASLSTR "sasl"
1971 #define BINDDNSTR "binddn"
1972 #define SASLMECHSTR "saslmech"
1973 #define AUTHCSTR "authcID"
1974 #define AUTHZSTR "authzID"
1975 #define CREDSTR "credentials"
1976 #define REALMSTR "realm"
1977 #define SECPROPSSTR "secprops"
1979 /* FIXME: undocumented */
1980 #define OLDAUTHCSTR "bindprincipal"
1981 #define STARTTLSSTR "starttls"
1982 #define CRITICALSTR "critical"
1983 #define EXATTRSSTR "exattrs"
1984 #define MANAGEDSAITSTR "manageDSAit"
1985 #define RETRYSTR "retry"
1988 #define LASTMODSTR "lastmod"
1989 #define LMGENSTR "gen"
1990 #define LMNOSTR "no"
1991 #define LMREQSTR "req"
1992 #define SRVTABSTR "srvtab"
1993 #define SUFFIXSTR "suffix"
1994 #define UPDATEDNSTR "updatedn"
1997 #define GOT_ID 0x0001
1998 #define GOT_PROVIDER 0x0002
1999 #define GOT_METHOD 0x0004
2002 #define GOT_ALL (GOT_ID|GOT_PROVIDER|GOT_METHOD)
2005 parse_syncrepl_line(
2015 for ( i = 1; i < cargc; i++ ) {
2016 if ( !strncasecmp( cargv[ i ], IDSTR "=",
2017 STRLENOF( IDSTR "=" ) ) )
2020 /* '\0' string terminator accounts for '=' */
2021 val = cargv[ i ] + STRLENOF( IDSTR "=" );
2023 if ( tmp >= 1000 || tmp < 0 ) {
2024 fprintf( stderr, "Error: parse_syncrepl_line: "
2025 "syncrepl id %d is out of range [0..999]\n", tmp );
2030 } else if ( !strncasecmp( cargv[ i ], PROVIDERSTR "=",
2031 STRLENOF( PROVIDERSTR "=" ) ) )
2033 val = cargv[ i ] + STRLENOF( PROVIDERSTR "=" );
2034 ber_str2bv( val, 0, 1, &si->si_provideruri );
2035 gots |= GOT_PROVIDER;
2036 } else if ( !strncasecmp( cargv[ i ], STARTTLSSTR "=",
2037 STRLENOF(STARTTLSSTR "=") ) )
2039 val = cargv[ i ] + STRLENOF( STARTTLSSTR "=" );
2040 if( !strcasecmp( val, CRITICALSTR ) ) {
2041 si->si_tls = SYNCINFO_TLS_CRITICAL;
2043 si->si_tls = SYNCINFO_TLS_ON;
2045 } else if ( !strncasecmp( cargv[ i ], BINDMETHSTR "=",
2046 STRLENOF( BINDMETHSTR "=" ) ) )
2048 val = cargv[ i ] + STRLENOF( BINDMETHSTR "=" );
2049 if ( !strcasecmp( val, SIMPLESTR )) {
2050 si->si_bindmethod = LDAP_AUTH_SIMPLE;
2052 } else if ( !strcasecmp( val, SASLSTR )) {
2053 #ifdef HAVE_CYRUS_SASL
2054 si->si_bindmethod = LDAP_AUTH_SASL;
2056 #else /* HAVE_CYRUS_SASL */
2057 fprintf( stderr, "Error: parse_syncrepl_line: "
2058 "not compiled with SASL support\n" );
2060 #endif /* HAVE_CYRUS_SASL */
2062 si->si_bindmethod = -1;
2064 } else if ( !strncasecmp( cargv[ i ], BINDDNSTR "=",
2065 STRLENOF( BINDDNSTR "=" ) ) )
2067 val = cargv[ i ] + STRLENOF( BINDDNSTR "=" );
2068 si->si_binddn = ch_strdup( val );
2069 } else if ( !strncasecmp( cargv[ i ], CREDSTR "=",
2070 STRLENOF( CREDSTR "=" ) ) )
2072 val = cargv[ i ] + STRLENOF( CREDSTR "=" );
2073 si->si_passwd = ch_strdup( val );
2074 } else if ( !strncasecmp( cargv[ i ], SASLMECHSTR "=",
2075 STRLENOF( SASLMECHSTR "=" ) ) )
2077 val = cargv[ i ] + STRLENOF( SASLMECHSTR "=" );
2078 si->si_saslmech = ch_strdup( val );
2079 } else if ( !strncasecmp( cargv[ i ], SECPROPSSTR "=",
2080 STRLENOF( SECPROPSSTR "=" ) ) )
2082 val = cargv[ i ] + STRLENOF( SECPROPSSTR "=" );
2083 si->si_secprops = ch_strdup( val );
2084 } else if ( !strncasecmp( cargv[ i ], REALMSTR "=",
2085 STRLENOF( REALMSTR "=" ) ) )
2087 val = cargv[ i ] + STRLENOF( REALMSTR "=" );
2088 si->si_realm = ch_strdup( val );
2089 } else if ( !strncasecmp( cargv[ i ], AUTHCSTR "=",
2090 STRLENOF( AUTHCSTR "=" ) ) )
2092 val = cargv[ i ] + STRLENOF( AUTHCSTR "=" );
2093 if ( si->si_authcId )
2094 ch_free( si->si_authcId );
2095 si->si_authcId = ch_strdup( val );
2096 } else if ( !strncasecmp( cargv[ i ], OLDAUTHCSTR "=",
2097 STRLENOF( OLDAUTHCSTR "=" ) ) )
2099 /* Old authcID is provided for some backwards compatibility */
2100 val = cargv[ i ] + STRLENOF( OLDAUTHCSTR "=" );
2101 if ( si->si_authcId )
2102 ch_free( si->si_authcId );
2103 si->si_authcId = ch_strdup( val );
2104 } else if ( !strncasecmp( cargv[ i ], AUTHZSTR "=",
2105 STRLENOF( AUTHZSTR "=" ) ) )
2107 val = cargv[ i ] + STRLENOF( AUTHZSTR "=" );
2108 si->si_authzId = ch_strdup( val );
2109 } else if ( !strncasecmp( cargv[ i ], SCHEMASTR "=",
2110 STRLENOF( SCHEMASTR "=" ) ) )
2112 val = cargv[ i ] + STRLENOF( SCHEMASTR "=" );
2113 if ( !strncasecmp( val, "on", STRLENOF( "on" ) )) {
2114 si->si_schemachecking = 1;
2115 } else if ( !strncasecmp( val, "off", STRLENOF( "off" ) ) ) {
2116 si->si_schemachecking = 0;
2118 si->si_schemachecking = 1;
2120 } else if ( !strncasecmp( cargv[ i ], FILTERSTR "=",
2121 STRLENOF( FILTERSTR "=" ) ) )
2123 val = cargv[ i ] + STRLENOF( FILTERSTR "=" );
2124 ber_str2bv( val, 0, 1, &si->si_filterstr );
2125 } else if ( !strncasecmp( cargv[ i ], SEARCHBASESTR "=",
2126 STRLENOF( SEARCHBASESTR "=" ) ) )
2131 val = cargv[ i ] + STRLENOF( SEARCHBASESTR "=" );
2132 if ( si->si_base.bv_val ) {
2133 ch_free( si->si_base.bv_val );
2135 ber_str2bv( val, 0, 0, &bv );
2136 rc = dnNormalize( 0, NULL, NULL, &bv, &si->si_base, NULL );
2137 if ( rc != LDAP_SUCCESS ) {
2138 fprintf( stderr, "Invalid base DN \"%s\": %d (%s)\n",
2139 val, rc, ldap_err2string( rc ) );
2142 } else if ( !strncasecmp( cargv[ i ], SCOPESTR "=",
2143 STRLENOF( SCOPESTR "=" ) ) )
2145 val = cargv[ i ] + STRLENOF( SCOPESTR "=" );
2146 if ( !strncasecmp( val, "base", STRLENOF( "base" ) )) {
2147 si->si_scope = LDAP_SCOPE_BASE;
2148 } else if ( !strncasecmp( val, "one", STRLENOF( "one" ) )) {
2149 si->si_scope = LDAP_SCOPE_ONELEVEL;
2150 #ifdef LDAP_SCOPE_SUBORDINATE
2151 } else if ( !strcasecmp( val, "subordinate" ) ||
2152 !strcasecmp( val, "children" ))
2154 si->si_scope = LDAP_SCOPE_SUBORDINATE;
2156 } else if ( !strncasecmp( val, "sub", STRLENOF( "sub" ) )) {
2157 si->si_scope = LDAP_SCOPE_SUBTREE;
2159 fprintf( stderr, "Error: parse_syncrepl_line: "
2160 "unknown scope \"%s\"\n", val);
2163 } else if ( !strncasecmp( cargv[ i ], ATTRSONLYSTR "=",
2164 STRLENOF( ATTRSONLYSTR "=" ) ) )
2166 si->si_attrsonly = 1;
2167 } else if ( !strncasecmp( cargv[ i ], ATTRSSTR "=",
2168 STRLENOF( ATTRSSTR "=" ) ) )
2170 val = cargv[ i ] + STRLENOF( ATTRSSTR "=" );
2171 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") ) ) {
2173 attr_fname = ch_strdup( val + STRLENOF(":include:") );
2174 si->si_anlist = file2anlist( si->si_anlist, attr_fname, " ,\t" );
2175 if ( si->si_anlist == NULL ) {
2176 ch_free( attr_fname );
2179 ch_free( attr_fname );
2181 char *str, *s, *next;
2182 char delimstr[] = " ,\t";
2183 str = ch_strdup( val );
2184 for ( s = ldap_pvt_strtok( str, delimstr, &next );
2186 s = ldap_pvt_strtok( NULL, delimstr, &next ) )
2188 if ( strlen(s) == 1 && *s == '*' ) {
2189 si->si_allattrs = 1;
2190 *(val + ( s - str )) = delimstr[0];
2192 if ( strlen(s) == 1 && *s == '+' ) {
2193 si->si_allopattrs = 1;
2194 *(val + ( s - str )) = delimstr[0];
2198 si->si_anlist = str2anlist( si->si_anlist, val, " ,\t" );
2199 if ( si->si_anlist == NULL ) {
2203 } else if ( !strncasecmp( cargv[ i ], EXATTRSSTR "=",
2204 STRLENOF( EXATTRSSTR "=" ) ) )
2206 val = cargv[ i ] + STRLENOF( EXATTRSSTR "=" );
2207 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") )) {
2209 attr_fname = ch_strdup( val + STRLENOF(":include:") );
2210 si->si_exanlist = file2anlist(
2211 si->si_exanlist, attr_fname, " ,\t" );
2212 if ( si->si_exanlist == NULL ) {
2213 ch_free( attr_fname );
2216 ch_free( attr_fname );
2218 si->si_exanlist = str2anlist( si->si_exanlist, val, " ,\t" );
2219 if ( si->si_exanlist == NULL ) {
2223 } else if ( !strncasecmp( cargv[ i ], TYPESTR "=",
2224 STRLENOF( TYPESTR "=" ) ) )
2226 val = cargv[ i ] + STRLENOF( TYPESTR "=" );
2227 if ( !strncasecmp( val, "refreshOnly",
2228 STRLENOF("refreshOnly") ))
2230 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2231 } else if ( !strncasecmp( val, "refreshAndPersist",
2232 STRLENOF("refreshAndPersist") ))
2234 si->si_type = LDAP_SYNC_REFRESH_AND_PERSIST;
2235 si->si_interval = 60;
2237 fprintf( stderr, "Error: parse_syncrepl_line: "
2238 "unknown sync type \"%s\"\n", val);
2241 } else if ( !strncasecmp( cargv[ i ], INTERVALSTR "=",
2242 STRLENOF( INTERVALSTR "=" ) ) )
2244 val = cargv[ i ] + STRLENOF( INTERVALSTR "=" );
2245 if ( si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ) {
2246 si->si_interval = 0;
2254 hstr = strchr( dstr, ':' );
2255 if ( hstr == NULL ) {
2256 fprintf( stderr, "Error: parse_syncrepl_line: "
2257 "invalid interval \"%s\"\n", val );
2261 mstr = strchr( hstr, ':' );
2262 if ( mstr == NULL ) {
2263 fprintf( stderr, "Error: parse_syncrepl_line: "
2264 "invalid interval \"%s\"\n", val );
2268 sstr = strchr( mstr, ':' );
2269 if ( sstr == NULL ) {
2270 fprintf( stderr, "Error: parse_syncrepl_line: "
2271 "invalid interval \"%s\"\n", val );
2280 if (( hh > 24 ) || ( hh < 0 ) ||
2281 ( mm > 60 ) || ( mm < 0 ) ||
2282 ( ss > 60 ) || ( ss < 0 ) || ( dd < 0 )) {
2283 fprintf( stderr, "Error: parse_syncrepl_line: "
2284 "invalid interval \"%s\"\n", val );
2287 si->si_interval = (( dd * 24 + hh ) * 60 + mm ) * 60 + ss;
2289 if ( si->si_interval < 0 ) {
2290 fprintf( stderr, "Error: parse_syncrepl_line: "
2291 "invalid interval \"%ld\"\n",
2292 (long) si->si_interval);
2295 } else if ( !strncasecmp( cargv[ i ], RETRYSTR "=",
2296 STRLENOF( RETRYSTR "=" ) ) )
2301 val = cargv[ i ] + STRLENOF( RETRYSTR "=" );
2302 retry_list = (char **) ch_calloc( 1, sizeof( char * ));
2303 retry_list[0] = NULL;
2305 slap_str2clist( &retry_list, val, " ,\t" );
2307 for ( k = 0; retry_list && retry_list[k]; k++ ) ;
2311 "Error: incomplete syncrepl retry list\n" );
2312 for ( k = 0; retry_list && retry_list[k]; k++ ) {
2313 ch_free( retry_list[k] );
2315 ch_free( retry_list );
2316 exit( EXIT_FAILURE );
2318 si->si_retryinterval = (time_t *) ch_calloc( n + 1, sizeof( time_t ));
2319 si->si_retrynum = (int *) ch_calloc( n + 1, sizeof( int ));
2320 si->si_retrynum_init = (int *) ch_calloc( n + 1, sizeof( int ));
2321 for ( j = 0; j < n; j++ ) {
2322 si->si_retryinterval[j] = atoi( retry_list[j*2] );
2323 if ( *retry_list[j*2+1] == '+' ) {
2324 si->si_retrynum_init[j] = -1;
2325 si->si_retrynum[j] = -1;
2329 si->si_retrynum_init[j] = atoi( retry_list[j*2+1] );
2330 si->si_retrynum[j] = atoi( retry_list[j*2+1] );
2333 si->si_retrynum_init[j] = -2;
2334 si->si_retrynum[j] = -2;
2335 si->si_retryinterval[j] = 0;
2337 for ( k = 0; retry_list && retry_list[k]; k++ ) {
2338 ch_free( retry_list[k] );
2340 ch_free( retry_list );
2341 } else if ( !strncasecmp( cargv[ i ], MANAGEDSAITSTR "=",
2342 STRLENOF( MANAGEDSAITSTR "=" ) ) )
2344 val = cargv[ i ] + STRLENOF( MANAGEDSAITSTR "=" );
2345 si->si_manageDSAit = atoi( val );
2346 } else if ( !strncasecmp( cargv[ i ], SLIMITSTR "=",
2347 STRLENOF( SLIMITSTR "=") ) )
2349 val = cargv[ i ] + STRLENOF( SLIMITSTR "=" );
2350 si->si_slimit = atoi( val );
2351 } else if ( !strncasecmp( cargv[ i ], TLIMITSTR "=",
2352 STRLENOF( TLIMITSTR "=" ) ) )
2354 val = cargv[ i ] + STRLENOF( TLIMITSTR "=" );
2355 si->si_tlimit = atoi( val );
2357 fprintf( stderr, "Error: parse_syncrepl_line: "
2358 "unknown keyword \"%s\"\n", cargv[ i ] );
2363 if ( gots != GOT_ALL ) {
2365 "Error: Malformed \"syncrepl\" line in slapd config file" );
2373 slap_str2clist( char ***out, char *in, const char *brkstr )
2381 /* find last element in list */
2382 for (i = 0; *out && (*out)[i]; i++);
2384 /* protect the input string from strtok */
2385 str = ch_strdup( in );
2387 if ( *str == '\0' ) {
2392 /* Count words in string */
2394 for ( s = str; *s; s++ ) {
2395 if ( strchr( brkstr, *s ) != NULL ) {
2400 *out = ch_realloc( *out, ( i + j + 1 ) * sizeof( char * ) );
2402 for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
2404 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
2406 *new = ch_strdup( s );