1 /* bconfig.c - the config backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 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>.
17 * This work was originally developed by Howard Chu for inclusion
18 * in OpenLDAP Software.
24 #include <ac/string.h>
31 #include "slapi/slapi.h"
38 static struct berval config_rdn = BER_BVC("cn=config");
41 typedef struct modpath_s {
42 struct modpath_s *mp_next;
43 struct berval mp_path;
48 typedef struct ConfigFile {
49 struct ConfigFile *c_sibs;
50 struct ConfigFile *c_kids;
59 typedef struct CfOcInfo {
60 struct berval *co_name;
61 ConfigTable *co_table;
72 typedef struct CfEntryInfo {
73 struct CfEntryInfo *ce_sibs;
74 struct CfEntryInfo *ce_kids;
82 ConfigFile *cb_config;
84 BackendDB cb_db; /* underlying database */
88 /* These do nothing in slapd, they're kept only to make them
91 static char *replica_pidFile, *replica_argsFile;
92 static int replicationInterval;
94 static char *passwd_salt;
95 static char *logfileName;
96 static BerVarray authz_rewrites;
98 static struct berval cfdir;
101 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
104 static ObjectClass *cfOc_global, *cfOc_backend, *cfOc_database,
105 *cfOc_include, *cfOc_overlay;
107 static ConfigFile cf_prv, *cfn = &cf_prv;
109 static Avlnode *CfOcTree;
111 static int add_syncrepl LDAP_P(( Backend *, char **, int ));
112 static int parse_syncrepl_line LDAP_P(( char **, int, syncinfo_t *));
113 static void syncrepl_unparse LDAP_P (( syncinfo_t *, struct berval *));
115 static ConfigDriver config_fname;
116 static ConfigDriver config_cfdir;
117 static ConfigDriver config_generic;
118 static ConfigDriver config_search_base;
119 static ConfigDriver config_passwd_hash;
120 static ConfigDriver config_schema_dn;
121 static ConfigDriver config_sizelimit;
122 static ConfigDriver config_timelimit;
123 static ConfigDriver config_limits;
124 static ConfigDriver config_overlay;
125 static ConfigDriver config_suffix;
126 static ConfigDriver config_deref_depth;
127 static ConfigDriver config_rootdn;
128 static ConfigDriver config_rootpw;
129 static ConfigDriver config_restrict;
130 static ConfigDriver config_allows;
131 static ConfigDriver config_disallows;
132 static ConfigDriver config_requires;
133 static ConfigDriver config_security;
134 static ConfigDriver config_referral;
135 static ConfigDriver config_loglevel;
136 static ConfigDriver config_syncrepl;
137 static ConfigDriver config_replica;
138 static ConfigDriver config_updatedn;
139 static ConfigDriver config_updateref;
140 static ConfigDriver config_include;
142 static ConfigDriver config_tls_option;
143 static ConfigDriver config_tls_config;
192 static OidRec OidMacros[] = {
193 /* OpenLDAProot:666.11.1 */
194 { "OLcfg", "1.3.6.1.4.1.4203.666.11.1" },
195 { "OLcfgAt", "OLcfg:3" },
196 { "OLcfgOc", "OLcfg:4" },
197 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
198 { "OMsInteger", "OMsyn:2" },
199 { "OMsBoolean", "OMsyn:7" },
200 { "OMsDN", "OMsyn:12" },
201 { "OMsDirectoryString", "OMsyn:15" },
202 { "OMsOctetString", "OMsyn:40" },
206 /* alphabetical ordering */
208 ConfigTable config_back_cf_table[] = {
209 /* This attr is read-only */
210 { "", "", 0, 0, 0, ARG_MAGIC,
211 &config_fname, "( OLcfgAt:78 NAME 'olcConfigFile' "
212 "DESC 'File for slapd configuration directives' "
213 "EQUALITY caseIgnoreMatch "
214 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
215 { "", "", 0, 0, 0, ARG_MAGIC,
216 &config_cfdir, "( OLcfgAt:79 NAME 'olcConfigDir' "
217 "DESC 'Directory for slapd configuration backend' "
218 "EQUALITY caseIgnoreMatch "
219 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
220 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
221 &config_generic, "( OLcfgAt:1 NAME 'olcAccess' "
222 "DESC 'Access Control List' "
223 "EQUALITY caseIgnoreMatch "
224 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
225 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
226 &config_allows, "( OLcfgAt:2 NAME 'olcAllows' "
227 "DESC 'Allowed set of deprecated features' "
228 "EQUALITY caseIgnoreMatch "
229 "SYNTAX OMsDirectoryString )", NULL, NULL },
230 { "argsfile", "file", 2, 2, 0, ARG_STRING,
231 &slapd_args_file, "( OLcfgAt:3 NAME 'olcArgsFile' "
232 "DESC 'File for slapd command line options' "
233 "EQUALITY caseIgnoreMatch "
234 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
235 /* Use standard 'attributeTypes' attr */
236 { "attribute", "attribute", 2, 0, 9, ARG_PAREN|ARG_MAGIC|CFG_ATTR,
237 &config_generic, NULL, NULL, NULL },
238 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
239 &config_generic, "( OLcfgAt:5 NAME 'olcAttributeOptions' "
240 "EQUALITY caseIgnoreMatch "
241 "SYNTAX OMsDirectoryString )", NULL, NULL },
242 { "authid-rewrite", NULL, 2, 0, 0,
243 #ifdef SLAP_AUTH_REWRITE
244 ARG_MAGIC|CFG_REWRITE, &config_generic,
248 "( OLcfgAt:6 NAME 'olcAuthIDRewrite' "
249 "EQUALITY caseIgnoreMatch "
250 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
251 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
252 &config_generic, "( OLcfgAt:7 NAME 'olcAuthzPolicy' "
253 "EQUALITY caseIgnoreMatch "
254 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
255 { "authz-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
256 &config_generic, "( OLcfgAt:8 NAME 'olcAuthzRegexp' "
257 "EQUALITY caseIgnoreMatch "
258 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
259 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
260 &config_generic, "( OLcfgAt:9 NAME 'olcBackend' "
261 "DESC 'A type of backend' "
262 "EQUALITY caseIgnoreMatch "
263 "SYNTAX OMsDirectoryString )", NULL, NULL },
264 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_CONCUR,
265 &config_generic, "( OLcfgAt:10 NAME 'olcConcurrency' "
266 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
267 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
268 &slap_conn_max_pending, "( OLcfgAt:11 NAME 'olcConnMaxPending' "
269 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
270 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
271 &slap_conn_max_pending_auth, "( OLcfgAt:12 NAME 'olcConnMaxPendingAuth' "
272 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
273 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
274 &config_generic, "( OLcfgAt:13 NAME 'olcDatabase' "
275 "DESC 'The backend type for a database instance' "
276 "SUP olcBackend )", NULL, NULL },
277 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_MAGIC,
278 &config_search_base, "( OLcfgAt:14 NAME 'olcDefaultSearchBase' "
279 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
280 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
281 &config_disallows, "( OLcfgAt:15 NAME 'olcDisallows' "
282 "EQUALITY caseIgnoreMatch "
283 "SYNTAX OMsDirectoryString )", NULL, NULL },
284 /* use standard schema */
285 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT,
286 &config_generic, NULL, NULL, NULL },
287 { "gentlehup", "on|off", 2, 2, 0,
289 ARG_ON_OFF, &global_gentlehup,
293 "( OLcfgAt:17 NAME 'olcGentleHUP' "
294 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
295 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
296 &global_idletimeout, "( OLcfgAt:18 NAME 'olcIdleTimeout' "
297 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
298 /* XXX -- special case? */
299 { "include", "file", 2, 2, 0, ARG_MAGIC,
300 &config_include, "( OLcfgAt:19 NAME 'olcInclude' "
301 "SUP labeledURI )", NULL, NULL },
302 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
303 &config_generic, "( OLcfgAt:20 NAME 'olcIndexSubstrIfMinLen' "
304 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
305 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
306 &config_generic, "( OLcfgAt:21 NAME 'olcIndexSubstrIfMaxLen' "
307 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
308 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
309 &index_substr_any_len, "( OLcfgAt:22 NAME 'olcIndexSubstrAnyLen' "
310 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
311 { "index_substr_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
312 &index_substr_any_step, "( OLcfgAt:23 NAME 'olcIndexSubstrAnyStep' "
313 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
314 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
315 &config_generic, "( OLcfgAt:24 NAME 'olcLastMod' "
316 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
317 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
318 &config_generic, "( OLcfgAt:25 NAME 'olcLimits' "
319 "SYNTAX OMsDirectoryString )", NULL, NULL },
320 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
321 &local_ssf, "( OLcfgAt:26 NAME 'olcLocalSSF' "
322 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
323 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
324 &config_generic, "( OLcfgAt:27 NAME 'olcLogFile' "
325 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
326 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
327 &config_loglevel, "( OLcfgAt:28 NAME 'olcLogLevel' "
328 "SYNTAX OMsDirectoryString )", NULL, NULL },
329 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
330 &config_generic, "( OLcfgAt:29 NAME 'olcMaxDerefDepth' "
331 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
332 { "moduleload", "file", 2, 0, 0,
334 ARG_MAGIC|CFG_MODLOAD, &config_generic,
338 "( OLcfgAt:30 NAME 'olcModuleLoad' "
339 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
340 { "modulepath", "path", 2, 2, 0,
342 ARG_MAGIC|CFG_MODPATH, &config_generic,
346 "( OLcfgAt:31 NAME 'olcModulePath' "
347 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
348 /* use standard schema */
349 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
350 &config_generic, NULL, NULL, NULL },
351 { "objectidentifier", NULL, 0, 0, 0, ARG_MAGIC|CFG_OID,
352 &config_generic, "( OLcfgAt:33 NAME 'olcObjectIdentifier' "
353 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
354 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
355 &config_overlay, "( OLcfgAt:34 NAME 'olcOverlay' "
356 "SUP olcDatabase )", NULL, NULL },
357 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
358 &config_generic, "( OLcfgAt:35 NAME 'olcPasswordCryptSaltFormat' "
359 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
360 { "password-hash", "hash", 2, 2, 0, ARG_MAGIC,
361 &config_passwd_hash, "( OLcfgAt:36 NAME 'olcPasswordHash' "
362 "SYNTAX OMsDirectoryString )", NULL, NULL },
363 { "pidfile", "file", 2, 2, 0, ARG_STRING,
364 &slapd_pid_file, "( OLcfgAt:37 NAME 'olcPidFile' "
365 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
366 { "plugin", NULL, 0, 0, 0,
368 ARG_MAGIC|CFG_PLUGIN, &config_generic,
372 "( OLcfgAt:38 NAME 'olcPlugin' "
373 "SYNTAX OMsDirectoryString )", NULL, NULL },
374 { "pluginlog", "filename", 2, 2, 0,
376 ARG_STRING, &slapi_log_file,
380 "( OLcfgAt:39 NAME 'olcPluginLogFile' "
381 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
382 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
383 &config_generic, "( OLcfgAt:40 NAME 'olcReadOnly' "
384 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
385 { "referral", "url", 2, 2, 0, ARG_MAGIC,
386 &config_referral, "( OLcfgAt:41 NAME 'olcReferral' "
387 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
388 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
389 &config_replica, "( OLcfgAt:42 NAME 'olcReplica' "
390 "SUP labeledURI )", NULL, NULL },
391 { "replica-argsfile", NULL, 0, 0, 0, ARG_STRING,
392 &replica_argsFile, "( OLcfgAt:43 NAME 'olcReplicaArgsFile' "
393 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
394 { "replica-pidfile", NULL, 0, 0, 0, ARG_STRING,
395 &replica_pidFile, "( OLcfgAt:44 NAME 'olcReplicaPidFile' "
396 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
397 { "replicationInterval", NULL, 0, 0, 0, ARG_INT,
398 &replicationInterval, "( OLcfgAt:45 NAME 'olcReplicationInterval' "
399 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
400 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC|ARG_STRING|CFG_REPLOG,
401 &config_generic, "( OLcfgAt:46 NAME 'olcReplogFile' "
402 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
403 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
404 &config_requires, "( OLcfgAt:47 NAME 'olcRequires' "
405 "SYNTAX OMsDirectoryString )", NULL, NULL },
406 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
407 &config_restrict, "( OLcfgAt:48 NAME 'olcRestrict' "
408 "SYNTAX OMsDirectoryString )", NULL, NULL },
409 { "reverse-lookup", "on|off", 2, 2, 0,
410 #ifdef SLAPD_RLOOKUPS
411 ARG_ON_OFF, &use_reverse_lookup,
415 "( OLcfgAt:49 NAME 'olcReverseLookup' "
416 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
417 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_MAGIC,
418 &config_rootdn, "( OLcfgAt:50 NAME 'olcRootDN' "
419 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
420 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
421 &config_generic, "( OLcfgAt:51 NAME 'olcRootDSE' "
422 "SYNTAX OMsDirectoryString )", NULL, NULL },
423 { "rootpw", "password", 2, 2, 0, ARG_STRING|ARG_DB|ARG_MAGIC,
424 &config_rootpw, "( OLcfgAt:52 NAME 'olcRootPW' "
425 "SYNTAX OMsOctetString SINGLE-VALUE )", NULL, NULL },
426 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
427 &config_generic, NULL, NULL, NULL },
428 { "sasl-host", "host", 2, 2, 0,
429 #ifdef HAVE_CYRUS_SASL
430 ARG_STRING|ARG_UNIQUE, &global_host,
434 "( OLcfgAt:53 NAME 'olcSaslHost' "
435 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
436 { "sasl-realm", "realm", 2, 2, 0,
437 #ifdef HAVE_CYRUS_SASL
438 ARG_STRING|ARG_UNIQUE, &global_realm,
442 "( OLcfgAt:54 NAME 'olcSaslRealm' "
443 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
444 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
445 &config_generic, NULL, NULL, NULL },
446 { "sasl-secprops", "properties", 2, 2, 0,
447 #ifdef HAVE_CYRUS_SASL
448 ARG_MAGIC|CFG_SASLSECP, &config_generic,
452 "( OLcfgAt:56 NAME 'olcSaslSecProps' "
453 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
454 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
455 &config_generic, NULL, NULL, NULL },
456 { "schemacheck", "on|off", 2, 2, 0, ARG_ON_OFF|ARG_MAGIC|CFG_CHECK,
457 &config_generic, "( OLcfgAt:57 NAME 'olcSchemaCheck' "
458 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
459 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_MAGIC,
460 &config_schema_dn, "( OLcfgAt:58 NAME 'olcSchemaDN' "
461 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
462 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
463 &config_security, "( OLcfgAt:59 NAME 'olcSecurity' "
464 "SYNTAX OMsDirectoryString )", NULL, NULL },
465 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_SIZE,
466 &config_sizelimit, "( OLcfgAt:60 NAME 'olcSizeLimit' "
467 "SYNTAX OMsInteger )", NULL, NULL },
468 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
469 &sockbuf_max_incoming, "( OLcfgAt:61 NAME 'olcSockbufMaxIncoming' "
470 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
471 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
472 &sockbuf_max_incoming_auth, "( OLcfgAt:62 NAME 'olcSockbufMaxIncomingAuth' "
473 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
474 { "srvtab", "file", 2, 2, 0,
475 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
476 ARG_STRING, &ldap_srvtab,
480 "( OLcfgAt:63 NAME 'olcSrvtab' "
481 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
482 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_MAGIC,
483 &config_suffix, "( OLcfgAt:64 NAME 'olcSuffix' "
484 "SYNTAX OMsDN )", NULL, NULL },
485 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
486 &config_syncrepl, "( OLcfgAt:65 NAME 'olcSyncrepl' "
487 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
488 { "threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_THREADS,
489 &config_generic, "( OLcfgAt:66 NAME 'olcThreads' "
490 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
491 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_TIME,
492 &config_timelimit, "( OLcfgAt:67 NAME 'olcTimeLimit' "
493 "SYNTAX OMsInteger )", NULL, NULL },
494 { "TLSCACertificateFile", NULL, 0, 0, 0,
496 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
500 "( OLcfgAt:68 NAME 'olcTLSCACertificateFile' "
501 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
502 { "TLSCACertificatePath", NULL, 0, 0, 0,
504 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
508 "( OLcfgAt:69 NAME 'olcTLSCACertificatePath' "
509 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
510 { "TLSCertificateFile", NULL, 0, 0, 0,
512 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
516 "( OLcfgAt:70 NAME 'olcTLSCertificateFile' "
517 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
518 { "TLSCertificateKeyFile", NULL, 0, 0, 0,
520 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
524 "( OLcfgAt:71 NAME 'olcTLSCertificateKeyFile' "
525 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
526 { "TLSCipherSuite", NULL, 0, 0, 0,
528 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
532 "( OLcfgAt:72 NAME 'olcTLSCipherSuite' "
533 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
534 { "TLSCRLCheck", NULL, 0, 0, 0,
536 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
540 "( OLcfgAt:73 NAME 'olcTLSCRLCheck' "
541 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
542 { "TLSRandFile", NULL, 0, 0, 0,
544 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
548 "( OLcfgAt:74 NAME 'olcTLSRandFile' "
549 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
550 { "TLSVerifyClient", NULL, 0, 0, 0,
552 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
556 "( OLcfgAt:75 NAME 'olcTLSVerifyClient' "
557 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
558 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
559 NULL, NULL, NULL, NULL },
560 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_MAGIC,
561 &config_updatedn, "( OLcfgAt:76 NAME 'olcUpdateDN' "
562 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
563 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
564 &config_updateref, "( OLcfgAt:77 NAME 'olcUpdateRef' "
565 "SUP labeledURI )", NULL, NULL },
566 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
567 NULL, NULL, NULL, NULL }
570 static ConfigOCs cf_ocs[] = {
573 "DESC 'OpenLDAP configuration object' "
575 "MAY ( cn $ olcConfigFile ) )", NULL },
578 "DESC 'OpenLDAP Global configuration options' "
579 "SUP olcConfig STRUCTURAL "
580 "MAY ( olcConfigDir $ olcAllows $ olcArgsFile $ olcAttributeOptions $ "
581 "olcAuthIDRewrite $ olcAuthzPolicy $ olcAuthzRegexp $ "
582 "olcConcurrency $ olcConnMaxPending $ olcConnMaxPendingAuth $ "
583 "olcDefaultSearchBase $ olcDisallows $ olcGentleHUP $ "
584 "olcIdleTimeout $ olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
585 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcLocalSSF $ "
586 "olcLogLevel $ olcModuleLoad $ olcModulePath $ olcObjectIdentifier $ "
587 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
588 "olcPlugin $ olcPluginLogFile $ olcReadOnly $ olcReferral $ "
589 "olcReplicaPidFile $ olcReplicaArgsFile $ olcReplicationInterval $ "
590 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
591 "olcRootDSE $ olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
592 "olcSchemaCheck $ olcSchemaDN $ olcSecurity $ olcSizeLimit $ "
593 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ olcSrvtab $ "
594 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
595 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
596 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
597 "olcTLSRandFile $ olcTLSVerifyClient ) )", &cfOc_global },
599 "NAME 'olcBackendConfig' "
600 "DESC 'OpenLDAP Backend-specific options' "
601 "SUP olcConfig STRUCTURAL "
602 "MAY ( olcBackend ) )", &cfOc_backend },
604 "NAME 'olcDatabaseConfig' "
605 "DESC 'OpenLDAP Database-specific options' "
606 "SUP olcConfig STRUCTURAL "
607 "MAY ( olcDatabase $ olcAccess $ olcLastMod $ olcLimits $ "
608 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
609 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
610 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSuffix $ olcSyncrepl $ "
611 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef ) )", &cfOc_database },
613 "NAME 'olcIncludeFile' "
614 "DESC 'OpenLDAP configuration include file' "
615 "SUP olcConfig STRUCTURAL "
616 "MAY ( olcInclude $ olcModuleLoad $ olcModulePath $ olcRootDSE ) )",
619 "NAME 'olcOverlayConfig' "
620 "DESC 'OpenLDAP Overlay-specific options' "
621 "SUP olcConfig STRUCTURAL "
622 "MAY ( olcOverlay ) )", &cfOc_overlay },
627 config_generic(ConfigArgs *c) {
631 if ( c->op == SLAP_CONFIG_EMIT ) {
635 c->value_int = ldap_pvt_thread_get_concurrency();
638 c->value_int = connection_pool_max;
642 c->value_string = ch_strdup( passwd_salt );
647 if ( c->be->be_limits ) {
652 for ( i=0; c->be->be_limits[i]; i++ ) {
653 bv.bv_len = sprintf( buf, "{%d}", i );
654 bv.bv_val = buf+bv.bv_len;
655 limits_unparse( c->be->be_limits[i], &bv );
656 bv.bv_len += bv.bv_val - buf;
658 value_add_one( &c->rvalue_vals, &bv );
661 if ( !c->rvalue_vals ) rc = 1;
664 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_OP_WRITES) != 0;
667 c->value_string = ch_strdup( slap_sasl_getpolicy());
670 slap_sasl_regexp_unparse( &c->rvalue_vals );
671 if ( !c->rvalue_vals ) rc = 1;
673 #ifdef HAVE_CYRUS_SASL
675 struct berval bv = BER_BVNULL;
676 slap_sasl_secprops_unparse( &bv );
677 if ( !BER_BVISNULL( &bv )) {
678 ber_bvarray_add( &c->rvalue_vals, &bv );
686 c->value_int = c->be->be_max_deref_depth;
689 oidm_unparse( &c->rvalue_vals );
690 if ( !c->rvalue_vals )
694 c->value_int = global_schemacheck;
698 char *src, *dst, ibuf[11];
699 struct berval bv, abv;
700 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
701 abv.bv_len = sprintf( ibuf, "{%x}", i );
702 acl_unparse( a, &bv );
703 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
704 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
705 /* Turn TAB / EOL into plain space */
706 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
707 if (isspace(*src)) *dst++ = ' ';
711 if (dst[-1] == ' ') {
715 abv.bv_len = dst - abv.bv_val;
716 ber_bvarray_add( &c->rvalue_vals, &abv );
722 if ( c->be->be_replogfile )
723 c->value_string = ch_strdup( c->be->be_replogfile );
726 ConfigFile *cf = (ConfigFile *)c->line;
727 if ( cf->c_dseFiles ) {
728 value_add( &c->rvalue_vals, cf->c_dseFiles );
736 c->value_string = ch_strdup( logfileName );
741 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
743 case CFG_SSTR_IF_MAX:
744 c->value_int = index_substr_if_maxlen;
746 case CFG_SSTR_IF_MIN:
747 c->value_int = index_substr_if_minlen;
751 ConfigFile *cf = (ConfigFile *)c->line;
753 for (i=0, mp=&cf->c_modpaths; mp; mp=mp->mp_next, i++) {
755 if (!mp->mp_loads) continue;
756 for (j=0; !BER_BVISNULL(&mp->mp_loads[j]); j++) {
759 bv.bv_len = sprintf( bv.bv_val, "{%d}{%d}%s", i, j,
760 mp->mp_loads[j].bv_val );
761 value_add_one( &c->rvalue_vals, &bv );
764 rc = c->rvalue_vals ? 0 : 1;
768 ConfigFile *cf = (ConfigFile *)c->line;
770 for (i=0, mp=&cf->c_modpaths; mp; mp=mp->mp_next, i++) {
772 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
775 bv.bv_len = sprintf( bv.bv_val, "{%d}%s", i,
776 mp->mp_path.bv_val );
777 value_add_one( &c->rvalue_vals, &bv );
779 rc = c->rvalue_vals ? 0 : 1;
785 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
786 if ( !c->rvalue_vals ) rc = 1;
789 #ifdef SLAP_AUTH_REWRITE
791 if ( authz_rewrites ) {
792 struct berval bv, idx;
797 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
798 idx.bv_len = sprintf( idx.bv_val, "{%d}", i );
799 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
800 bv.bv_val = ch_malloc( bv.bv_len + 1 );
801 strcpy( bv.bv_val, idx.bv_val );
802 strcpy( bv.bv_val+idx.bv_len, authz_rewrites[i].bv_val );
803 ber_bvarray_add( &c->rvalue_vals, &bv );
806 if ( !c->rvalue_vals ) rc = 1;
815 p = strchr(c->line,'(' /*')'*/);
818 if(!(c->bi = backend_info(c->argv[1]))) {
819 Debug(LDAP_DEBUG_ANY, "%s: "
820 "backend %s failed init!\n", c->log, c->argv[1], 0);
827 /* NOTE: config is always the first backend!
829 if ( !strcasecmp( c->argv[1], "config" )) {
831 } else if(!(c->be = backend_db_init(c->argv[1]))) {
832 Debug(LDAP_DEBUG_ANY, "%s: "
833 "database %s failed init!\n", c->log, c->argv[1], 0);
839 ldap_pvt_thread_set_concurrency(c->value_int);
843 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
844 connection_pool_max = c->value_int; /* save for reference */
848 if ( passwd_salt ) ch_free( passwd_salt );
849 passwd_salt = c->value_string;
850 lutil_salt_format(passwd_salt);
854 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
860 c->be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
862 c->be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
866 ch_free(c->value_string);
867 if (slap_sasl_setpolicy( c->argv[1] )) {
868 Debug(LDAP_DEBUG_ANY, "%s: unable to parse value \"%s\" in"
869 " \"authz-policy <policy>\"\n",
870 c->log, c->argv[1], 0 );
876 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
880 #ifdef HAVE_CYRUS_SASL
883 char *txt = slap_sasl_secprops( c->argv[1] );
885 Debug(LDAP_DEBUG_ANY, "%s: sasl-secprops: %s\n",
894 c->be->be_max_deref_depth = c->value_int;
898 if(parse_oidm(c->fname, c->lineno, c->argc, c->argv)) return(1);
902 if(parse_oc(c->fname, c->lineno, p, c->argv)) return(1);
906 if(parse_cr(c->fname, c->lineno, p, c->argv)) return(1);
910 if(parse_at(c->fname, c->lineno, p, c->argv)) return(1);
914 ad_define_option(NULL, NULL, 0);
915 for(i = 1; i < c->argc; i++)
916 if(ad_define_option(c->argv[i], c->fname, c->lineno))
921 global_schemacheck = c->value_int;
922 if(!global_schemacheck) Debug(LDAP_DEBUG_ANY, "%s: "
923 "schema checking disabled! your mileage may vary!\n",
928 parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv);
932 if(SLAP_MONITOR(c->be)) {
933 Debug(LDAP_DEBUG_ANY, "%s: "
934 "\"replogfile\" should not be used "
935 "inside monitor database\n",
937 return(0); /* FIXME: should this be an error? */
940 c->be->be_replogfile = c->value_string;
944 if(read_root_dse_file(c->argv[1])) {
945 Debug(LDAP_DEBUG_ANY, "%s: "
946 "could not read \"rootDSE <filename>\" line\n",
952 ber_str2bv( c->argv[1], 0, 1, &bv );
953 ber_bvarray_add( &cfn->c_dseFiles, &bv );
959 if ( logfileName ) ch_free( logfileName );
960 logfileName = c->value_string;
961 logfile = fopen(logfileName, "w");
962 if(logfile) lutil_debug_file(logfile);
966 if(SLAP_NOLASTMODCMD(c->be)) {
967 Debug(LDAP_DEBUG_ANY, "%s: "
968 "lastmod not available for %s databases\n",
969 c->log, c->be->bd_info->bi_type, 0);
973 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
975 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
978 case CFG_SSTR_IF_MAX:
979 if (c->value_int < index_substr_if_minlen) {
980 Debug(LDAP_DEBUG_ANY, "%s: "
981 "invalid max value (%d)\n",
982 c->log, c->value_int, 0 );
985 index_substr_if_maxlen = c->value_int;
988 case CFG_SSTR_IF_MIN:
989 if (c->value_int > index_substr_if_maxlen) {
990 Debug(LDAP_DEBUG_ANY, "%s: "
991 "invalid min value (%d)\n",
992 c->log, c->value_int, 0 );
995 index_substr_if_minlen = c->value_int;
1000 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1002 /* Record this load on the current path */
1005 ber_str2bv(c->line, 0, 1, &bv);
1006 ber_bvarray_add( &cfn->c_modlast->mp_loads, &bv );
1011 if(module_path(c->argv[1])) return(1);
1012 /* Record which path was used with each module */
1016 if (!cfn->c_modpaths.mp_loads) {
1017 mp = &cfn->c_modpaths;
1019 mp = ch_malloc( sizeof( ModPaths ));
1020 cfn->c_modlast->mp_next = mp;
1022 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1024 mp->mp_loads = NULL;
1025 cfn->c_modlast = mp;
1033 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
1035 slapi_plugins_used++;
1039 #ifdef SLAP_AUTH_REWRITE
1042 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
1044 ber_str2bv( c->line, 0, 1, &bv );
1045 ber_bvarray_add( &authz_rewrites, &bv );
1052 Debug(LDAP_DEBUG_ANY, "%s: unknown CFG_TYPE %d"
1053 "(ignored)\n", c->log, c->type, 0);
1061 config_fname(ConfigArgs *c) {
1062 if(c->op == SLAP_CONFIG_EMIT && c->line) {
1063 ConfigFile *cf = (ConfigFile *)c->line;
1064 value_add_one( &c->rvalue_vals, &cf->c_file );
1071 config_cfdir(ConfigArgs *c) {
1072 if(c->op == SLAP_CONFIG_EMIT) {
1073 value_add_one( &c->rvalue_vals, &cfdir );
1080 config_search_base(ConfigArgs *c) {
1083 if(c->op == SLAP_CONFIG_EMIT) {
1085 if (!BER_BVISEMPTY(&default_search_base)) {
1086 value_add_one(&c->rvalue_vals, &default_search_base);
1087 value_add_one(&c->rvalue_nvals, &default_search_nbase);
1093 if(c->bi || c->be != frontendDB) {
1094 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
1095 "prior to any backend or database definition\n",
1100 if(default_search_nbase.bv_len) {
1101 Debug(LDAP_DEBUG_ANY, "%s: "
1102 "default search base \"%s\" already defined "
1103 "(discarding old)\n",
1104 c->log, default_search_base.bv_val, 0);
1105 free(default_search_base.bv_val);
1106 free(default_search_nbase.bv_val);
1109 default_search_base = c->value_dn;
1110 default_search_nbase = c->value_ndn;
1115 config_passwd_hash(ConfigArgs *c) {
1117 if (c->op == SLAP_CONFIG_EMIT) {
1119 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
1120 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
1121 value_add_one(&c->rvalue_vals, &bv);
1125 if(default_passwd_hash) {
1126 Debug(LDAP_DEBUG_ANY, "%s: "
1127 "already set default password_hash\n",
1131 for(i = 1; i < c->argc; i++) {
1132 if(!lutil_passwd_scheme(c->argv[i])) {
1133 Debug(LDAP_DEBUG_ANY, "%s: "
1134 "password scheme \"%s\" not available\n",
1135 c->log, c->argv[i], 0);
1137 ldap_charray_add(&default_passwd_hash, c->argv[i]);
1139 if(!default_passwd_hash) {
1140 Debug(LDAP_DEBUG_ANY, "%s: no valid hashes found\n",
1149 config_schema_dn(ConfigArgs *c) {
1150 if ( c->op == SLAP_CONFIG_EMIT ) {
1152 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
1153 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
1154 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
1159 c->be->be_schemadn = c->value_dn;
1160 c->be->be_schemandn = c->value_ndn;
1165 config_sizelimit(ConfigArgs *c) {
1168 struct slap_limits_set *lim = &c->be->be_def_limit;
1169 if (c->op == SLAP_CONFIG_EMIT) {
1174 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv );
1175 if ( !BER_BVISEMPTY( &bv ))
1176 value_add_one( &c->rvalue_vals, &bv );
1181 for(i = 1; i < c->argc; i++) {
1182 if(!strncasecmp(c->argv[i], "size", 4)) {
1183 rc = limits_parse_one(c->argv[i], lim);
1185 Debug(LDAP_DEBUG_ANY, "%s: "
1186 "unable to parse value \"%s\" in \"sizelimit <limit>\" line\n",
1187 c->log, c->argv[i], 0);
1191 if(!strcasecmp(c->argv[i], "unlimited")) {
1192 lim->lms_s_soft = -1;
1194 lim->lms_s_soft = strtol(c->argv[i], &next, 0);
1195 if(next == c->argv[i]) {
1196 Debug(LDAP_DEBUG_ANY, "%s: "
1197 "unable to parse limit \"%s\" in \"sizelimit <limit>\" line\n",
1198 c->log, c->argv[i], 0);
1200 } else if(next[0] != '\0') {
1201 Debug(LDAP_DEBUG_ANY, "%s: "
1202 "trailing chars \"%s\" in \"sizelimit <limit>\" line (ignored)\n",
1206 lim->lms_s_hard = 0;
1213 config_timelimit(ConfigArgs *c) {
1216 struct slap_limits_set *lim = &c->be->be_def_limit;
1217 if (c->op == SLAP_CONFIG_EMIT) {
1222 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv );
1223 if ( !BER_BVISEMPTY( &bv ))
1224 value_add_one( &c->rvalue_vals, &bv );
1229 for(i = 1; i < c->argc; i++) {
1230 if(!strncasecmp(c->argv[i], "time", 4)) {
1231 rc = limits_parse_one(c->argv[i], lim);
1233 Debug(LDAP_DEBUG_ANY, "%s: "
1234 "unable to parse value \"%s\" in \"timelimit <limit>\" line\n",
1235 c->log, c->argv[i], 0);
1239 if(!strcasecmp(c->argv[i], "unlimited")) {
1240 lim->lms_t_soft = -1;
1242 lim->lms_t_soft = strtol(c->argv[i], &next, 0);
1243 if(next == c->argv[i]) {
1244 Debug(LDAP_DEBUG_ANY, "%s: "
1245 "unable to parse limit \"%s\" in \"timelimit <limit>\" line\n",
1246 c->log, c->argv[i], 0);
1248 } else if(next[0] != '\0') {
1249 Debug(LDAP_DEBUG_ANY, "%s: "
1250 "trailing chars \"%s\" in \"timelimit <limit>\" line (ignored)\n",
1254 lim->lms_t_hard = 0;
1261 config_overlay(ConfigArgs *c) {
1262 if (c->op == SLAP_CONFIG_EMIT) {
1265 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1])) {
1267 Debug(LDAP_DEBUG_ANY, "%s: (optional) %s overlay \"%s\" configuration failed (ignored)\n",
1268 c->log, c->be == frontendDB ? "global " : "", c->argv[1][1]);
1269 } else if(overlay_config(c->be, c->argv[1])) {
1276 config_suffix(ConfigArgs *c) {
1278 struct berval pdn, ndn;
1280 if (c->op == SLAP_CONFIG_EMIT) {
1281 if ( !BER_BVISNULL( &c->be->be_suffix[0] )) {
1282 value_add( &c->rvalue_vals, c->be->be_suffix );
1283 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
1289 #ifdef SLAPD_MONITOR_DN
1290 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
1291 Debug(LDAP_DEBUG_ANY, "%s: "
1292 "\"%s\" is reserved for monitoring slapd\n",
1293 c->log, SLAPD_MONITOR_DN, 0);
1300 tbe = select_backend(&ndn, 0, 0);
1302 Debug(LDAP_DEBUG_ANY, "%s: suffix already served by this backend! (ignored)\n",
1307 Debug(LDAP_DEBUG_ANY, "%s: suffix already served by a preceding backend \"%s\"\n",
1308 c->log, tbe->be_suffix[0].bv_val, 0);
1312 } else if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
1313 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
1314 "base provided \"%s\" (assuming okay)\n",
1315 c->log, default_search_base.bv_val, 0);
1317 ber_bvarray_add(&c->be->be_suffix, &pdn);
1318 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
1323 config_rootdn(ConfigArgs *c) {
1324 if (c->op == SLAP_CONFIG_EMIT) {
1325 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
1326 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
1327 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
1333 c->be->be_rootdn = c->value_dn;
1334 c->be->be_rootndn = c->value_ndn;
1339 config_rootpw(ConfigArgs *c) {
1341 if (c->op == SLAP_CONFIG_EMIT) {
1342 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
1343 c->value_string=ch_strdup("*");
1349 tbe = select_backend(&c->be->be_rootndn, 0, 0);
1351 Debug(LDAP_DEBUG_ANY, "%s: "
1352 "rootpw can only be set when rootdn is under suffix\n",
1356 ber_str2bv(c->value_string, 0, 0, &c->be->be_rootpw);
1361 config_restrict(ConfigArgs *c) {
1362 slap_mask_t restrictops = 0;
1364 slap_verbmasks restrictable_ops[] = {
1365 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
1366 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
1367 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
1368 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
1369 { BER_BVC("modrdn"), 0 },
1370 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
1371 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
1372 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
1373 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
1374 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
1375 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
1376 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
1377 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
1378 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
1379 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
1383 if (c->op == SLAP_CONFIG_EMIT) {
1384 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
1387 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
1389 Debug(LDAP_DEBUG_ANY, "%s: "
1390 "unknown operation %s in \"restrict <features>\" line\n",
1391 c->log, c->argv[i], 0);
1394 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
1395 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
1396 c->be->be_restrictops |= restrictops;
1401 config_allows(ConfigArgs *c) {
1402 slap_mask_t allows = 0;
1404 slap_verbmasks allowable_ops[] = {
1405 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
1406 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
1407 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
1408 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
1411 if (c->op == SLAP_CONFIG_EMIT) {
1412 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
1414 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
1416 Debug(LDAP_DEBUG_ANY, "%s: "
1417 "unknown feature %s in \"allow <features>\" line\n",
1418 c->log, c->argv[i], 0);
1421 global_allows |= allows;
1426 config_disallows(ConfigArgs *c) {
1427 slap_mask_t disallows = 0;
1429 slap_verbmasks disallowable_ops[] = {
1430 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
1431 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
1432 { BER_BVC("bind_krb4"), SLAP_DISALLOW_BIND_KRBV4 },
1433 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
1434 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
1437 if (c->op == SLAP_CONFIG_EMIT) {
1438 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
1440 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
1442 Debug(LDAP_DEBUG_ANY, "%s: "
1443 "unknown feature %s in \"disallow <features>\" line\n",
1444 c->log, c->argv[i], 0);
1447 global_disallows |= disallows;
1452 config_requires(ConfigArgs *c) {
1453 slap_mask_t requires = 0;
1455 slap_verbmasks requires_ops[] = {
1456 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
1457 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
1458 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
1459 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
1460 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
1463 if (c->op == SLAP_CONFIG_EMIT) {
1464 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
1466 i = verbs_to_mask(c->argc, c->argv, requires_ops, &requires);
1468 Debug(LDAP_DEBUG_ANY, "%s: "
1469 "unknown feature %s in \"require <features>\" line\n",
1470 c->log, c->argv[i], 0);
1473 c->be->be_requires = requires;
1478 config_loglevel(ConfigArgs *c) {
1481 slap_verbmasks loglevel_ops[] = {
1482 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
1483 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
1484 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
1485 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
1486 { BER_BVC("BER"), LDAP_DEBUG_BER },
1487 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
1488 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
1489 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
1490 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
1491 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
1492 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
1493 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
1494 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
1495 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
1496 { BER_BVC("Any"), -1 },
1500 if (c->op == SLAP_CONFIG_EMIT) {
1501 return mask_to_verbs( loglevel_ops, ldap_syslog, &c->rvalue_vals );
1506 for( i=1; i < c->argc; i++ ) {
1509 if ( isdigit( c->argv[i][0] ) ) {
1510 level = strtol( c->argv[i], &next, 10 );
1511 if ( next == NULL || next[0] != '\0' ) {
1512 Debug( LDAP_DEBUG_ANY,
1513 "%s: unable to parse level \"%s\" "
1514 "in \"loglevel <level> [...]\" line.\n",
1515 c->log, c->argv[i], 0);
1519 int j = verb_to_mask(c->argv[i], loglevel_ops);
1520 if(BER_BVISNULL(&loglevel_ops[j].word)) {
1521 Debug( LDAP_DEBUG_ANY,
1522 "%s: unknown level \"%s\" "
1523 "in \"loglevel <level> [...]\" line.\n",
1524 c->log, c->argv[i], 0);
1527 level = loglevel_ops[j].mask;
1529 ldap_syslog |= level;
1535 config_syncrepl(ConfigArgs *c) {
1536 if (c->op == SLAP_CONFIG_EMIT) {
1537 if ( c->be->be_syncinfo ) {
1539 syncrepl_unparse( c->be->be_syncinfo, &bv );
1540 ber_bvarray_add( &c->rvalue_vals, &bv );
1545 if(SLAP_SHADOW(c->be)) {
1546 Debug(LDAP_DEBUG_ANY, "%s: "
1547 "syncrepl: database already shadowed.\n",
1550 } else if(add_syncrepl(c->be, c->argv, c->argc)) {
1553 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SYNC_SHADOW);
1558 config_referral(ConfigArgs *c) {
1559 struct berval vals[2];
1560 if (c->op == SLAP_CONFIG_EMIT) {
1561 if ( default_referral ) {
1562 value_add( &c->rvalue_vals, default_referral );
1568 if(validate_global_referral(c->argv[1])) {
1569 Debug(LDAP_DEBUG_ANY, "%s: "
1570 "invalid URL (%s) in \"referral\" line.\n",
1571 c->log, c->argv[1], 0);
1575 ber_str2bv(c->argv[1], 0, 0, &vals[0]);
1576 vals[1].bv_val = NULL; vals[1].bv_len = 0;
1577 if(value_add(&default_referral, vals)) return(LDAP_OTHER);
1585 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
1586 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
1587 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
1588 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
1589 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
1590 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
1591 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
1592 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
1593 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
1598 config_security(ConfigArgs *c) {
1599 slap_ssf_set_t *set = &c->be->be_ssf_set;
1602 if (c->op == SLAP_CONFIG_EMIT) {
1608 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
1609 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
1612 bv.bv_len = sprintf( numbuf, "%u", *tgt );
1613 bv.bv_len += sec_keys[i].key.bv_len;
1614 bv.bv_val = ch_malloc( bv.bv_len + 1);
1615 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
1616 strcpy( next, numbuf );
1617 ber_bvarray_add( &c->rvalue_vals, &bv );
1622 for(i = 1; i < c->argc; i++) {
1623 slap_ssf_t *tgt = NULL;
1625 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
1626 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
1627 sec_keys[j].key.bv_len)) {
1628 src = c->argv[i] + sec_keys[j].key.bv_len;
1629 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
1634 Debug(LDAP_DEBUG_ANY, "%s: "
1635 "unknown factor %s in \"security <factors>\" line\n",
1636 c->log, c->argv[i], 0);
1640 *tgt = strtol(src, &next, 10);
1641 if(next == NULL || next[0] != '\0' ) {
1642 Debug(LDAP_DEBUG_ANY, "%s: "
1643 "unable to parse factor \"%s\" in \"security <factors>\" line\n",
1644 c->log, c->argv[i], 0);
1652 anlist_unparse( AttributeName *an, char *ptr ) {
1655 for (; !BER_BVISNULL( &an->an_name ); an++) {
1656 if ( comma ) *ptr++ = ',';
1657 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
1664 replica_unparse( struct slap_replica_info *ri, int i, struct berval *bv )
1668 struct berval bc = {0};
1671 len = sprintf(numbuf, "{%d}", i );
1673 len += strlen( ri->ri_uri ) + STRLENOF("uri=");
1674 if ( ri->ri_nsuffix ) {
1675 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
1676 len += ri->ri_nsuffix[i].bv_len + STRLENOF(" suffix=\"\"");
1679 if ( ri->ri_attrs ) {
1680 len += STRLENOF("attr");
1681 if ( ri->ri_exclude ) len++;
1682 for (i=0; !BER_BVISNULL( &ri->ri_attrs[i].an_name ); i++) {
1683 len += 1 + ri->ri_attrs[i].an_name.bv_len;
1686 bindconf_unparse( &ri->ri_bindconf, &bc );
1689 bv->bv_val = ch_malloc(len + 1);
1692 ptr = lutil_strcopy( bv->bv_val, numbuf );
1693 ptr = lutil_strcopy( ptr, "uri=" );
1694 ptr = lutil_strcopy( ptr, ri->ri_uri );
1696 if ( ri->ri_nsuffix ) {
1697 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
1698 ptr = lutil_strcopy( ptr, " suffix=\"" );
1699 ptr = lutil_strcopy( ptr, ri->ri_nsuffix[i].bv_val );
1703 if ( ri->ri_attrs ) {
1704 ptr = lutil_strcopy( ptr, "attr" );
1705 if ( ri->ri_exclude ) *ptr++ = '!';
1707 ptr = anlist_unparse( ri->ri_attrs, ptr );
1710 strcpy( ptr, bc.bv_val );
1711 ch_free( bc.bv_val );
1716 config_replica(ConfigArgs *c) {
1717 int i, nr = -1, len;
1718 char *replicahost, *replicauri;
1721 if (c->op == SLAP_CONFIG_EMIT) {
1722 if (c->be->be_replica) {
1724 for (i=0;c->be->be_replica[i]; i++) {
1725 replica_unparse( c->be->be_replica[i], i, &bv );
1726 ber_bvarray_add( &c->rvalue_vals, &bv );
1732 if(SLAP_MONITOR(c->be)) {
1733 Debug(LDAP_DEBUG_ANY, "%s: "
1734 "\"replica\" should not be used inside monitor database\n",
1736 return(0); /* FIXME: should this be an error? */
1739 for(i = 1; i < c->argc; i++) {
1740 if(!strncasecmp(c->argv[i], "host=", STRLENOF("host="))) {
1741 replicahost = c->argv[i] + STRLENOF("host=");
1742 len = strlen( replicahost );
1743 replicauri = ch_malloc( len + STRLENOF("ldap://") + 1 );
1744 sprintf( replicauri, "ldap://%s", replicahost );
1745 replicahost = replicauri + STRLENOF( "ldap://");
1746 nr = add_replica_info(c->be, replicauri, replicahost);
1748 } else if(!strncasecmp(c->argv[i], "uri=", STRLENOF("uri="))) {
1749 if(ldap_url_parse(c->argv[i] + STRLENOF("uri="), &ludp) != LDAP_SUCCESS) {
1750 Debug(LDAP_DEBUG_ANY, "%s: "
1751 "replica line contains invalid "
1752 "uri definition.\n", c->log, 0, 0);
1755 if(!ludp->lud_host) {
1756 Debug(LDAP_DEBUG_ANY, "%s: "
1757 "replica line contains invalid "
1758 "uri definition - missing hostname.\n",
1762 ldap_free_urldesc(ludp);
1763 replicauri = c->argv[i] + STRLENOF("uri=");
1764 replicauri = ch_strdup( replicauri );
1765 replicahost = strchr( replicauri, '/' );
1767 nr = add_replica_info(c->be, replicauri, replicahost);
1772 Debug(LDAP_DEBUG_ANY, "%s: "
1773 "missing host or uri in \"replica\" line\n",
1776 } else if(nr == -1) {
1777 Debug(LDAP_DEBUG_ANY, "%s: "
1778 "unable to add replica \"%s\"\n",
1779 c->log, replicauri, 0);
1782 for(i = 1; i < c->argc; i++) {
1783 if(!strncasecmp(c->argv[i], "suffix=", STRLENOF( "suffix="))) {
1784 switch(add_replica_suffix(c->be, nr, c->argv[i] + STRLENOF("suffix="))) {
1786 Debug(LDAP_DEBUG_ANY, "%s: "
1787 "suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
1788 c->log, c->argv[i] + STRLENOF("suffix="), 0);
1791 Debug(LDAP_DEBUG_ANY, "%s: "
1792 "unable to normalize suffix in \"replica\" line (ignored)\n",
1797 } else if(!strncasecmp(c->argv[i], "attr", STRLENOF("attr"))) {
1799 char *arg = c->argv[i] + STRLENOF("attr");
1807 if(add_replica_attrs(c->be, nr, arg + 1, exclude)) {
1808 Debug(LDAP_DEBUG_ANY, "%s: "
1809 "attribute \"%s\" in \"replica\" line is unknown\n",
1810 c->log, arg + 1, 0);
1813 } else if ( bindconf_parse( c->argv[i],
1814 &c->be->be_replica[nr]->ri_bindconf ) ) {
1823 config_updatedn(ConfigArgs *c) {
1826 if (c->op == SLAP_CONFIG_EMIT) {
1827 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
1828 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
1829 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
1834 if(SLAP_SHADOW(c->be)) {
1835 Debug(LDAP_DEBUG_ANY, "%s: "
1836 "updatedn: database already shadowed.\n",
1841 ber_str2bv(c->argv[1], 0, 0, &dn);
1843 rc = dnNormalize(0, NULL, NULL, &dn, &c->be->be_update_ndn, NULL);
1845 if(rc != LDAP_SUCCESS) {
1846 Debug(LDAP_DEBUG_ANY, "%s: "
1847 "updatedn DN is invalid: %d (%s)\n",
1848 c->log, rc, ldap_err2string( rc ));
1852 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
1857 config_updateref(ConfigArgs *c) {
1858 struct berval vals[2];
1859 if (c->op == SLAP_CONFIG_EMIT) {
1860 if ( c->be->be_update_refs ) {
1861 value_add( &c->rvalue_vals, c->be->be_update_refs );
1867 if(!SLAP_SHADOW(c->be)) {
1868 Debug(LDAP_DEBUG_ANY, "%s: "
1869 "updateref line must come after syncrepl or updatedn.\n",
1874 if(validate_global_referral(c->argv[1])) {
1875 Debug(LDAP_DEBUG_ANY, "%s: "
1876 "invalid URL (%s) in \"updateref\" line.\n",
1877 c->log, c->argv[1], 0);
1880 ber_str2bv(c->argv[1], 0, 0, &vals[0]);
1881 vals[1].bv_val = NULL;
1882 if(value_add(&c->be->be_update_refs, vals)) return(LDAP_OTHER);
1887 config_include(ConfigArgs *c) {
1888 unsigned long savelineno = c->lineno;
1891 ConfigFile *cfsave = cfn;
1892 ConfigFile *cf2 = NULL;
1893 if (c->op == SLAP_CONFIG_EMIT) {
1896 cf = ch_calloc( 1, sizeof(ConfigFile));
1897 #ifdef SLAPD_MODULES
1898 cf->c_modlast = &cf->c_modpaths;
1900 if ( cfn->c_kids ) {
1901 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
1907 rc = read_config_file(c->argv[1], c->depth + 1, c);
1908 c->lineno = savelineno - 1;
1911 if ( cf2 ) cf2->c_sibs = NULL;
1912 else cfn->c_kids = NULL;
1915 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
1922 config_tls_option(ConfigArgs *c) {
1925 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; break;
1926 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
1927 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
1928 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
1929 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
1930 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
1931 default: Debug(LDAP_DEBUG_ANY, "%s: "
1932 "unknown tls_option <%x>\n",
1933 c->log, c->type, 0);
1935 if (c->op == SLAP_CONFIG_EMIT) {
1936 return ldap_pvt_tls_get_option( NULL, flag, &c->value_string );
1938 ch_free(c->value_string);
1939 return(ldap_pvt_tls_set_option(NULL, flag, c->argv[1]));
1942 /* FIXME: this ought to be provided by libldap */
1944 config_tls_config(ConfigArgs *c) {
1946 slap_verbmasks crlkeys[] = {
1947 { BER_BVC("none"), LDAP_OPT_X_TLS_CRL_NONE },
1948 { BER_BVC("peer"), LDAP_OPT_X_TLS_CRL_PEER },
1949 { BER_BVC("all"), LDAP_OPT_X_TLS_CRL_ALL },
1952 slap_verbmasks vfykeys[] = {
1953 { BER_BVC("never"), LDAP_OPT_X_TLS_NEVER },
1954 { BER_BVC("demand"), LDAP_OPT_X_TLS_DEMAND },
1955 { BER_BVC("try"), LDAP_OPT_X_TLS_TRY },
1956 { BER_BVC("hard"), LDAP_OPT_X_TLS_HARD },
1960 #ifdef HAVE_OPENSSL_CRL
1961 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; keys = crlkeys;
1964 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; keys = vfykeys;
1966 default: Debug(LDAP_DEBUG_ANY, "%s: "
1967 "unknown tls_option <%x>\n",
1968 c->log, c->type, 0);
1970 if (c->op == SLAP_CONFIG_EMIT) {
1971 ldap_pvt_tls_get_option( NULL, flag, &c->value_int );
1972 for (i=0; !BER_BVISNULL(&keys[i].word); i++) {
1973 if (keys[i].mask == c->value_int) {
1974 c->value_string = ch_strdup( keys[i].word.bv_val );
1980 ch_free( c->value_string );
1981 if(isdigit((unsigned char)c->argv[1][0])) {
1982 i = atoi(c->argv[1]);
1983 return(ldap_pvt_tls_set_option(NULL, flag, &i));
1985 return(ldap_int_tls_config(NULL, flag, c->argv[1]));
2000 si = (syncinfo_t *) ch_calloc( 1, sizeof( syncinfo_t ) );
2003 Debug( LDAP_DEBUG_ANY, "out of memory in add_syncrepl\n", 0, 0, 0 );
2007 si->si_bindconf.sb_tls = SB_TLS_OFF;
2008 si->si_bindconf.sb_method = LDAP_AUTH_SIMPLE;
2009 si->si_schemachecking = 0;
2010 ber_str2bv( "(objectclass=*)", STRLENOF("(objectclass=*)"), 1,
2011 &si->si_filterstr );
2012 si->si_base.bv_val = NULL;
2013 si->si_scope = LDAP_SCOPE_SUBTREE;
2014 si->si_attrsonly = 0;
2015 si->si_anlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ));
2016 si->si_exanlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ));
2017 si->si_attrs = NULL;
2018 si->si_allattrs = 0;
2019 si->si_allopattrs = 0;
2020 si->si_exattrs = NULL;
2021 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2022 si->si_interval = 86400;
2023 si->si_retryinterval = NULL;
2024 si->si_retrynum_init = NULL;
2025 si->si_retrynum = NULL;
2026 si->si_manageDSAit = 0;
2030 si->si_presentlist = NULL;
2031 LDAP_LIST_INIT( &si->si_nonpresentlist );
2032 ldap_pvt_thread_mutex_init( &si->si_mutex );
2034 rc = parse_syncrepl_line( cargv, cargc, si );
2037 Debug( LDAP_DEBUG_ANY, "failed to add syncinfo\n", 0, 0, 0 );
2038 syncinfo_free( si );
2041 Debug( LDAP_DEBUG_CONFIG,
2042 "Config: ** successfully added syncrepl \"%s\"\n",
2043 BER_BVISNULL( &si->si_provideruri ) ?
2044 "(null)" : si->si_provideruri.bv_val, 0, 0 );
2045 if ( !si->si_schemachecking ) {
2046 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NO_SCHEMA_CHECK;
2049 be->be_syncinfo = si;
2054 /* NOTE: used & documented in slapd.conf(5) */
2056 #define PROVIDERSTR "provider"
2057 #define TYPESTR "type"
2058 #define INTERVALSTR "interval"
2059 #define SEARCHBASESTR "searchbase"
2060 #define FILTERSTR "filter"
2061 #define SCOPESTR "scope"
2062 #define ATTRSSTR "attrs"
2063 #define ATTRSONLYSTR "attrsonly"
2064 #define SLIMITSTR "sizelimit"
2065 #define TLIMITSTR "timelimit"
2066 #define SCHEMASTR "schemachecking"
2068 /* FIXME: undocumented */
2069 #define OLDAUTHCSTR "bindprincipal"
2070 #define EXATTRSSTR "exattrs"
2071 #define RETRYSTR "retry"
2074 #define LASTMODSTR "lastmod"
2075 #define LMGENSTR "gen"
2076 #define LMNOSTR "no"
2077 #define LMREQSTR "req"
2078 #define SRVTABSTR "srvtab"
2079 #define SUFFIXSTR "suffix"
2080 #define MANAGEDSAITSTR "manageDSAit"
2083 #define GOT_ID 0x0001
2084 #define GOT_PROVIDER 0x0002
2087 #define GOT_ALL (GOT_ID|GOT_PROVIDER)
2093 { BER_BVC("base"), LDAP_SCOPE_BASE },
2094 { BER_BVC("one"), LDAP_SCOPE_ONELEVEL },
2095 #ifdef LDAP_SCOPE_SUBORDINATE
2096 { BER_BVC("children"), LDAP_SCOPE_SUBORDINATE },
2097 { BER_BVC("subordinate"), 0 },
2099 { BER_BVC("sub"), LDAP_SCOPE_SUBTREE },
2104 parse_syncrepl_line(
2114 for ( i = 1; i < cargc; i++ ) {
2115 if ( !strncasecmp( cargv[ i ], IDSTR "=",
2116 STRLENOF( IDSTR "=" ) ) )
2119 /* '\0' string terminator accounts for '=' */
2120 val = cargv[ i ] + STRLENOF( IDSTR "=" );
2122 if ( tmp >= 1000 || tmp < 0 ) {
2123 fprintf( stderr, "Error: parse_syncrepl_line: "
2124 "syncrepl id %d is out of range [0..999]\n", tmp );
2129 } else if ( !strncasecmp( cargv[ i ], PROVIDERSTR "=",
2130 STRLENOF( PROVIDERSTR "=" ) ) )
2132 val = cargv[ i ] + STRLENOF( PROVIDERSTR "=" );
2133 ber_str2bv( val, 0, 1, &si->si_provideruri );
2134 gots |= GOT_PROVIDER;
2135 } else if ( !strncasecmp( cargv[ i ], SCHEMASTR "=",
2136 STRLENOF( SCHEMASTR "=" ) ) )
2138 val = cargv[ i ] + STRLENOF( SCHEMASTR "=" );
2139 if ( !strncasecmp( val, "on", STRLENOF( "on" ) )) {
2140 si->si_schemachecking = 1;
2141 } else if ( !strncasecmp( val, "off", STRLENOF( "off" ) ) ) {
2142 si->si_schemachecking = 0;
2144 si->si_schemachecking = 1;
2146 } else if ( !strncasecmp( cargv[ i ], FILTERSTR "=",
2147 STRLENOF( FILTERSTR "=" ) ) )
2149 val = cargv[ i ] + STRLENOF( FILTERSTR "=" );
2150 ber_str2bv( val, 0, 1, &si->si_filterstr );
2151 } else if ( !strncasecmp( cargv[ i ], SEARCHBASESTR "=",
2152 STRLENOF( SEARCHBASESTR "=" ) ) )
2157 val = cargv[ i ] + STRLENOF( SEARCHBASESTR "=" );
2158 if ( si->si_base.bv_val ) {
2159 ch_free( si->si_base.bv_val );
2161 ber_str2bv( val, 0, 0, &bv );
2162 rc = dnNormalize( 0, NULL, NULL, &bv, &si->si_base, NULL );
2163 if ( rc != LDAP_SUCCESS ) {
2164 fprintf( stderr, "Invalid base DN \"%s\": %d (%s)\n",
2165 val, rc, ldap_err2string( rc ) );
2168 } else if ( !strncasecmp( cargv[ i ], SCOPESTR "=",
2169 STRLENOF( SCOPESTR "=" ) ) )
2172 val = cargv[ i ] + STRLENOF( SCOPESTR "=" );
2173 for ( j=0; !BER_BVISNULL(&scopes[j].key); j++ ) {
2174 if (!strncasecmp( val, scopes[j].key.bv_val,
2175 scopes[j].key.bv_len )) {
2176 while (!scopes[j].val) j--;
2177 si->si_scope = scopes[j].val;
2181 if ( BER_BVISNULL(&scopes[j].key) ) {
2182 fprintf( stderr, "Error: parse_syncrepl_line: "
2183 "unknown scope \"%s\"\n", val);
2186 } else if ( !strncasecmp( cargv[ i ], ATTRSONLYSTR "=",
2187 STRLENOF( ATTRSONLYSTR "=" ) ) )
2189 si->si_attrsonly = 1;
2190 } else if ( !strncasecmp( cargv[ i ], ATTRSSTR "=",
2191 STRLENOF( ATTRSSTR "=" ) ) )
2193 val = cargv[ i ] + STRLENOF( ATTRSSTR "=" );
2194 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") ) ) {
2196 attr_fname = ch_strdup( val + STRLENOF(":include:") );
2197 si->si_anlist = file2anlist( si->si_anlist, attr_fname, " ,\t" );
2198 if ( si->si_anlist == NULL ) {
2199 ch_free( attr_fname );
2202 si->si_anfile = attr_fname;
2204 char *str, *s, *next;
2205 char delimstr[] = " ,\t";
2206 str = ch_strdup( val );
2207 for ( s = ldap_pvt_strtok( str, delimstr, &next );
2209 s = ldap_pvt_strtok( NULL, delimstr, &next ) )
2211 if ( strlen(s) == 1 && *s == '*' ) {
2212 si->si_allattrs = 1;
2213 *(val + ( s - str )) = delimstr[0];
2215 if ( strlen(s) == 1 && *s == '+' ) {
2216 si->si_allopattrs = 1;
2217 *(val + ( s - str )) = delimstr[0];
2221 si->si_anlist = str2anlist( si->si_anlist, val, " ,\t" );
2222 if ( si->si_anlist == NULL ) {
2226 } else if ( !strncasecmp( cargv[ i ], EXATTRSSTR "=",
2227 STRLENOF( EXATTRSSTR "=" ) ) )
2229 val = cargv[ i ] + STRLENOF( EXATTRSSTR "=" );
2230 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") )) {
2232 attr_fname = ch_strdup( val + STRLENOF(":include:") );
2233 si->si_exanlist = file2anlist(
2234 si->si_exanlist, attr_fname, " ,\t" );
2235 if ( si->si_exanlist == NULL ) {
2236 ch_free( attr_fname );
2239 ch_free( attr_fname );
2241 si->si_exanlist = str2anlist( si->si_exanlist, val, " ,\t" );
2242 if ( si->si_exanlist == NULL ) {
2246 } else if ( !strncasecmp( cargv[ i ], TYPESTR "=",
2247 STRLENOF( TYPESTR "=" ) ) )
2249 val = cargv[ i ] + STRLENOF( TYPESTR "=" );
2250 if ( !strncasecmp( val, "refreshOnly",
2251 STRLENOF("refreshOnly") ))
2253 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2254 } else if ( !strncasecmp( val, "refreshAndPersist",
2255 STRLENOF("refreshAndPersist") ))
2257 si->si_type = LDAP_SYNC_REFRESH_AND_PERSIST;
2258 si->si_interval = 60;
2260 fprintf( stderr, "Error: parse_syncrepl_line: "
2261 "unknown sync type \"%s\"\n", val);
2264 } else if ( !strncasecmp( cargv[ i ], INTERVALSTR "=",
2265 STRLENOF( INTERVALSTR "=" ) ) )
2267 val = cargv[ i ] + STRLENOF( INTERVALSTR "=" );
2268 if ( si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ) {
2269 si->si_interval = 0;
2277 hstr = strchr( dstr, ':' );
2278 if ( hstr == NULL ) {
2279 fprintf( stderr, "Error: parse_syncrepl_line: "
2280 "invalid interval \"%s\"\n", val );
2284 mstr = strchr( hstr, ':' );
2285 if ( mstr == NULL ) {
2286 fprintf( stderr, "Error: parse_syncrepl_line: "
2287 "invalid interval \"%s\"\n", val );
2291 sstr = strchr( mstr, ':' );
2292 if ( sstr == NULL ) {
2293 fprintf( stderr, "Error: parse_syncrepl_line: "
2294 "invalid interval \"%s\"\n", val );
2303 if (( hh > 24 ) || ( hh < 0 ) ||
2304 ( mm > 60 ) || ( mm < 0 ) ||
2305 ( ss > 60 ) || ( ss < 0 ) || ( dd < 0 )) {
2306 fprintf( stderr, "Error: parse_syncrepl_line: "
2307 "invalid interval \"%s\"\n", val );
2310 si->si_interval = (( dd * 24 + hh ) * 60 + mm ) * 60 + ss;
2312 if ( si->si_interval < 0 ) {
2313 fprintf( stderr, "Error: parse_syncrepl_line: "
2314 "invalid interval \"%ld\"\n",
2315 (long) si->si_interval);
2318 } else if ( !strncasecmp( cargv[ i ], RETRYSTR "=",
2319 STRLENOF( RETRYSTR "=" ) ) )
2324 val = cargv[ i ] + STRLENOF( RETRYSTR "=" );
2325 retry_list = (char **) ch_calloc( 1, sizeof( char * ));
2326 retry_list[0] = NULL;
2328 slap_str2clist( &retry_list, val, " ,\t" );
2330 for ( k = 0; retry_list && retry_list[k]; k++ ) ;
2334 "Error: incomplete syncrepl retry list\n" );
2335 for ( k = 0; retry_list && retry_list[k]; k++ ) {
2336 ch_free( retry_list[k] );
2338 ch_free( retry_list );
2339 exit( EXIT_FAILURE );
2341 si->si_retryinterval = (time_t *) ch_calloc( n + 1, sizeof( time_t ));
2342 si->si_retrynum = (int *) ch_calloc( n + 1, sizeof( int ));
2343 si->si_retrynum_init = (int *) ch_calloc( n + 1, sizeof( int ));
2344 for ( j = 0; j < n; j++ ) {
2345 si->si_retryinterval[j] = atoi( retry_list[j*2] );
2346 if ( *retry_list[j*2+1] == '+' ) {
2347 si->si_retrynum_init[j] = -1;
2348 si->si_retrynum[j] = -1;
2352 si->si_retrynum_init[j] = atoi( retry_list[j*2+1] );
2353 si->si_retrynum[j] = atoi( retry_list[j*2+1] );
2356 si->si_retrynum_init[j] = -2;
2357 si->si_retrynum[j] = -2;
2358 si->si_retryinterval[j] = 0;
2360 for ( k = 0; retry_list && retry_list[k]; k++ ) {
2361 ch_free( retry_list[k] );
2363 ch_free( retry_list );
2364 } else if ( !strncasecmp( cargv[ i ], MANAGEDSAITSTR "=",
2365 STRLENOF( MANAGEDSAITSTR "=" ) ) )
2367 val = cargv[ i ] + STRLENOF( MANAGEDSAITSTR "=" );
2368 si->si_manageDSAit = atoi( val );
2369 } else if ( !strncasecmp( cargv[ i ], SLIMITSTR "=",
2370 STRLENOF( SLIMITSTR "=") ) )
2372 val = cargv[ i ] + STRLENOF( SLIMITSTR "=" );
2373 si->si_slimit = atoi( val );
2374 } else if ( !strncasecmp( cargv[ i ], TLIMITSTR "=",
2375 STRLENOF( TLIMITSTR "=" ) ) )
2377 val = cargv[ i ] + STRLENOF( TLIMITSTR "=" );
2378 si->si_tlimit = atoi( val );
2379 } else if ( bindconf_parse( cargv[i], &si->si_bindconf )) {
2380 fprintf( stderr, "Error: parse_syncrepl_line: "
2381 "unknown keyword \"%s\"\n", cargv[ i ] );
2386 if ( gots != GOT_ALL ) {
2388 "Error: Malformed \"syncrepl\" line in slapd config file" );
2396 syncrepl_unparse( syncinfo_t *si, struct berval *bv )
2399 char buf[BUFSIZ*2], *ptr;
2402 bindconf_unparse( &si->si_bindconf, &bc );
2404 ptr += sprintf( ptr, IDSTR "=%03d " PROVIDERSTR "=%s",
2405 si->si_rid, si->si_provideruri.bv_val );
2406 if ( !BER_BVISNULL( &bc )) {
2407 ptr = lutil_strcopy( ptr, bc.bv_val );
2410 if ( !BER_BVISEMPTY( &si->si_filterstr )) {
2411 ptr = lutil_strcopy( ptr, " " FILTERSTR "=\"" );
2412 ptr = lutil_strcopy( ptr, si->si_filterstr.bv_val );
2415 if ( !BER_BVISNULL( &si->si_base )) {
2416 ptr = lutil_strcopy( ptr, " " SEARCHBASESTR "=\"" );
2417 ptr = lutil_strcopy( ptr, si->si_base.bv_val );
2420 for (i=0; !BER_BVISNULL(&scopes[i].key);i++) {
2421 if ( si->si_scope == scopes[i].val ) {
2422 ptr = lutil_strcopy( ptr, " " SCOPESTR "=" );
2423 ptr = lutil_strcopy( ptr, scopes[i].key.bv_val );
2427 if ( si->si_attrsonly ) {
2428 ptr = lutil_strcopy( ptr, " " ATTRSONLYSTR "=yes" );
2430 if ( si->si_anfile ) {
2431 ptr = lutil_strcopy( ptr, " " ATTRSSTR "=:include:" );
2432 ptr = lutil_strcopy( ptr, si->si_anfile );
2433 } else if ( si->si_allattrs || si->si_allopattrs ||
2434 ( si->si_anlist && !BER_BVISNULL(&si->si_anlist[0].an_name) )) {
2436 ptr = lutil_strcopy( ptr, " " ATTRSSTR "=\"" );
2438 ptr = anlist_unparse( si->si_anlist, ptr );
2439 if ( si->si_allattrs ) {
2440 if ( old != ptr ) *ptr++ = ',';
2443 if ( si->si_allopattrs ) {
2444 if ( old != ptr ) *ptr++ = ',';
2449 if ( si->si_exanlist && !BER_BVISNULL(&si->si_exanlist[0].an_name) ) {
2450 ptr = lutil_strcopy( ptr, " " EXATTRSSTR "=" );
2451 ptr = anlist_unparse( si->si_exanlist, ptr );
2453 ptr = lutil_strcopy( ptr, " " SCHEMASTR "=" );
2454 ptr = lutil_strcopy( ptr, si->si_schemachecking ? "on" : "off" );
2456 ptr = lutil_strcopy( ptr, " " TYPESTR "=" );
2457 ptr = lutil_strcopy( ptr, si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ?
2458 "refreshAndPersist" : "refreshOnly" );
2460 if ( si->si_type == LDAP_SYNC_REFRESH_ONLY ) {
2463 dd = si->si_interval;
2470 ptr = lutil_strcopy( ptr, " " INTERVALSTR "=" );
2471 ptr += sprintf( ptr, "%02d:%02d:%02d:%02d", dd, hh, mm, ss );
2472 } else if ( si->si_retryinterval ) {
2474 ptr = lutil_strcopy( ptr, " " RETRYSTR "=\"" );
2475 for (i=0; si->si_retryinterval[i]; i++) {
2476 if ( space ) *ptr++ = ' ';
2478 ptr += sprintf( ptr, "%d", si->si_retryinterval[i] );
2479 if ( si->si_retrynum_init[i] == -1 )
2482 ptr += sprintf( ptr, "%d", si->si_retrynum_init );
2487 #if 0 /* FIXME: unused in syncrepl.c, should remove it */
2488 ptr = lutil_strcopy( ptr, " " MANAGEDSAITSTR "=" );
2489 ptr += sprintf( ptr, "%d", si->si_manageDSAit );
2492 if ( si->si_slimit ) {
2493 ptr = lutil_strcopy( ptr, " " SLIMITSTR "=" );
2494 ptr += sprintf( ptr, "%d", si->si_slimit );
2497 if ( si->si_tlimit ) {
2498 ptr = lutil_strcopy( ptr, " " TLIMITSTR "=" );
2499 ptr += sprintf( ptr, "%d", si->si_tlimit );
2501 bc.bv_len = ptr - buf;
2503 ber_dupbv( bv, &bc );
2506 static CfEntryInfo *
2507 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
2517 if ( dn_match( &root->ce_entry->e_nname, dn ))
2520 c = dn->bv_val+dn->bv_len;
2521 for (;*c != ',';c--);
2525 for (--c;c>dn->bv_val && *c != ',';c--);
2529 cdn.bv_len = dn->bv_len - (c-dn->bv_val);
2531 root = root->ce_kids;
2533 for (;root;root=root->ce_sibs) {
2534 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
2535 if ( cdn.bv_val == dn->bv_val ) {
2546 config_ldif_resp( Operation *op, SlapReply *rs )
2548 if ( rs->sr_type == REP_SEARCH ) {
2549 CfBackInfo *cfb = op->o_callback->sc_private;
2550 CfEntryInfo *ce, *last;
2552 cfb->cb_got_ldif = 1;
2553 config_find_base( cfb->cb_root, &rs->sr_entry->e_nname, &last );
2554 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
2555 ce->ce_entry = entry_dup( rs->sr_entry );
2556 ce->ce_entry->e_private = ce;
2559 } else if ( last->ce_kids ) {
2562 for (c2=last->ce_kids; c2 && c2->ce_sibs; c2 = c2->ce_sibs);
2571 /* Configure and read the underlying back-ldif store */
2573 config_setup_ldif( BackendDB *be, const char *dir ) {
2574 CfBackInfo *cfb = be->be_private;
2579 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
2580 Connection conn = {0};
2581 char opbuf[OPERATION_BUFFER_SIZE];
2583 SlapReply rs = {REP_RESULT};
2584 Filter filter = { LDAP_FILTER_PRESENT };
2585 struct berval filterstr = BER_BVC("(objectclass=*)");
2587 cfb->cb_db.bd_info = backend_info( "ldif" );
2588 if ( !cfb->cb_db.bd_info )
2589 return 0; /* FIXME: eventually this will be a fatal error */
2591 if ( cfb->cb_db.bd_info->bi_db_init( &cfb->cb_db )) return 1;
2593 /* Mark that back-ldif type is in use */
2594 cfb->cb_db.bd_info->bi_nDB++;
2596 cfb->cb_db.be_suffix = be->be_suffix;
2597 cfb->cb_db.be_nsuffix = be->be_nsuffix;
2598 cfb->cb_db.be_rootdn = be->be_rootdn;
2599 cfb->cb_db.be_rootndn = be->be_rootndn;
2601 ber_str2bv( dir, 0, 1, &cfdir );
2606 argv[0] = "directory";
2607 argv[1] = (char *)dir;
2611 ct = config_find_keyword( c.be->be_cf_table, &c );
2615 if ( config_add_vals( ct, &c ))
2618 if ( backend_startup_one( &cfb->cb_db ))
2621 op = (Operation *)opbuf;
2622 connection_fake_init( &conn, op, cfb );
2624 filter.f_desc = slap_schema.si_ad_objectClass;
2626 op->o_tag = LDAP_REQ_SEARCH;
2628 op->ors_filter = &filter;
2629 op->ors_filterstr = filterstr;
2630 op->ors_scope = LDAP_SCOPE_SUBTREE;
2632 op->o_dn = be->be_rootdn;
2633 op->o_ndn = be->be_rootndn;
2635 op->o_req_dn = be->be_suffix[0];
2636 op->o_req_ndn = be->be_nsuffix[0];
2638 op->ors_tlimit = SLAP_NO_LIMIT;
2639 op->ors_slimit = SLAP_NO_LIMIT;
2641 op->ors_attrs = slap_anlist_all_attributes;
2642 op->ors_attrsonly = 0;
2644 op->o_callback = &cb;
2645 cb.sc_private = cfb;
2647 op->o_bd = &cfb->cb_db;
2648 op->o_bd->be_search( op, &rs );
2654 CfOcInfo_cmp( const void *c1, const void *c2 ) {
2655 const CfOcInfo *co1 = c1;
2656 const CfOcInfo *co2 = c2;
2658 return ber_bvcmp( co1->co_name, co2->co_name );
2662 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
2666 i = init_config_attrs( ct );
2669 /* set up the objectclasses */
2670 i = init_config_ocs( ocs );
2673 for (i=0; ocs[i].def; i++) {
2675 co = ch_malloc( sizeof(CfOcInfo) );
2676 co->co_name = &(*ocs[i].oc)->soc_cname;
2678 avl_insert( &CfOcTree, co, CfOcInfo_cmp, avl_dup_error );
2685 read_config(const char *fname, const char *dir) {
2688 /* Setup the config backend */
2689 be = backend_db_init( "config" );
2693 /* Setup the underlying back-ldif backend */
2694 if ( config_setup_ldif( be, dir ))
2698 /* If we read the config from back-ldif, nothing to do here */
2699 if ( cfb->cb_got_ldif )
2702 ber_str2bv( fname, 0, 1, &cf_prv.c_file );
2704 return read_config_file(fname, 0, NULL);
2708 config_back_bind( Operation *op, SlapReply *rs )
2710 if ( op->orb_method == LDAP_AUTH_SIMPLE && be_isroot_pw( op )) {
2711 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
2712 /* frontend sends result */
2713 return LDAP_SUCCESS;
2716 rs->sr_err = LDAP_INVALID_CREDENTIALS;
2717 send_ldap_result( op, rs );
2723 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
2727 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
2729 rs->sr_attrs = op->ors_attrs;
2730 rs->sr_entry = ce->ce_entry;
2731 rc = send_search_entry( op, rs );
2733 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
2734 if ( ce->ce_kids ) {
2735 rc = config_send( op, rs, ce->ce_kids, 1 );
2736 if ( rc ) return rc;
2739 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
2740 rc = config_send( op, rs, ce, 0 );
2749 config_back_modify( Operation *op, SlapReply *rs )
2752 CfEntryInfo *ce, *last;
2754 if ( !be_isroot( op ) ) {
2755 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
2756 send_ldap_result( op, rs );
2759 cfb = (CfBackInfo *)op->o_bd->be_private;
2761 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
2764 rs->sr_matched = last->ce_entry->e_name.bv_val;
2765 rs->sr_err = LDAP_NO_SUCH_OBJECT;
2768 ldap_pvt_thread_pool_pause( &connection_pool );
2771 * 1) perform the Modify on the cached Entry.
2772 * 2) verify that the Entry still satisfies the schema.
2773 * 3) perform the individual config operations.
2774 * 4) store Modified entry in underlying LDIF backend.
2776 ldap_pvt_thread_pool_resume( &connection_pool );
2778 send_ldap_result( op, rs );
2783 config_back_search( Operation *op, SlapReply *rs )
2786 CfEntryInfo *ce, *last;
2789 if ( !be_isroot( op ) ) {
2790 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
2791 send_ldap_result( op, rs );
2794 cfb = (CfBackInfo *)op->o_bd->be_private;
2796 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
2799 rs->sr_matched = last->ce_entry->e_name.bv_val;
2800 rs->sr_err = LDAP_NO_SUCH_OBJECT;
2803 switch ( op->ors_scope ) {
2804 case LDAP_SCOPE_BASE:
2805 case LDAP_SCOPE_SUBTREE:
2806 config_send( op, rs, ce, 0 );
2809 case LDAP_SCOPE_ONELEVEL:
2810 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
2811 config_send( op, rs, ce, 1 );
2816 rs->sr_err = LDAP_SUCCESS;
2818 send_ldap_result( op, rs );
2823 config_alloc_entry( struct berval *pdn, struct berval *rdn )
2825 Entry *e = ch_calloc( 1, sizeof(Entry) );
2826 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
2829 build_new_dn( &e->e_name, pdn, rdn, NULL );
2830 ber_dupbv( &e->e_nname, &e->e_name );
2839 config_build_entry( ConfigArgs *c, Entry *e, ObjectClass *oc,
2840 struct berval *rdn, ConfigTable *ct, int table )
2842 struct berval vals[2];
2843 struct berval ad_name;
2844 AttributeDescription *ad = NULL;
2850 BER_BVZERO( &vals[1] );
2852 vals[0] = oc->soc_cname;
2853 attr_merge(e, slap_schema.si_ad_objectClass, vals, NULL );
2854 attr_merge(e, slap_schema.si_ad_structuralObjectClass, vals, NULL );
2855 ptr = strchr(rdn->bv_val, '=');
2856 ad_name.bv_val = rdn->bv_val;
2857 ad_name.bv_len = ptr - rdn->bv_val;
2858 rc = slap_bv2ad( &ad_name, &ad, &text );
2862 vals[0].bv_val = ptr+1;
2863 vals[0].bv_len = rdn->bv_len - (vals[0].bv_val - rdn->bv_val);
2864 attr_merge(e, ad, vals, NULL );
2866 for (at=oc->soc_required; at && *at; at++) {
2867 /* Skip the naming attr */
2868 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
2870 for (i=0;ct[i].name;i++) {
2871 if (ct[i].ad == (*at)->sat_ad) {
2872 rc = config_get_vals(&ct[i], c);
2873 if (rc == LDAP_SUCCESS) {
2874 attr_merge(e, ct[i].ad, c->rvalue_vals, c->rvalue_nvals);
2875 ber_bvarray_free( c->rvalue_nvals );
2876 ber_bvarray_free( c->rvalue_vals );
2883 for (at=oc->soc_allowed; at && *at; at++) {
2884 /* Skip the naming attr */
2885 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
2887 for (i=0;ct[i].name;i++) {
2888 if (ct[i].ad == (*at)->sat_ad) {
2889 rc = config_get_vals(&ct[i], c);
2890 if (rc == LDAP_SUCCESS) {
2891 attr_merge(e, ct[i].ad, c->rvalue_vals, c->rvalue_nvals);
2892 ber_bvarray_free( c->rvalue_nvals );
2893 ber_bvarray_free( c->rvalue_vals );
2901 if ( table == BI_TABLE )
2902 ct = c->bi->bi_cf_table;
2904 ct = c->be->be_cf_table;
2905 for (;ct && ct->name;ct++) {
2906 if (!ct->ad) continue;
2907 rc = config_get_vals(ct, c);
2908 if (rc == LDAP_SUCCESS) {
2909 attr_merge(e, ct->ad, c->rvalue_vals, c->rvalue_nvals);
2917 static CfEntryInfo *
2918 config_build_includes( ConfigArgs *c, Entry *parent,
2919 Operation *op, SlapReply *rs )
2923 ConfigFile *cf = (ConfigFile *)c->line;
2924 CfEntryInfo *ce, *ceparent, *ceprev;
2926 ceparent = parent->e_private;
2928 for (i=0; cf; cf=cf->c_sibs, i++) {
2929 c->value_dn.bv_val = c->log;
2930 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=include{%d}", i);
2931 e = config_alloc_entry( &parent->e_nname, &c->value_dn );
2932 c->line = (char *)cf;
2933 config_build_entry( c, e, cfOc_include, &c->value_dn,
2934 c->bi->bi_cf_table, NO_TABLE );
2936 op->o_bd->be_add( op, rs );
2938 ce->ce_type = Cf_Include;
2940 if ( !ceparent->ce_kids ) {
2941 ceparent->ce_kids = ce;
2943 ceprev->ce_sibs = ce;
2947 c->line = (char *)cf->c_kids;
2948 config_build_includes( c, e, op, rs );
2955 config_back_db_open( BackendDB *be )
2957 CfBackInfo *cfb = be->be_private;
2960 CfEntryInfo *ce, *ceparent, *ceprev;
2966 Connection conn = {0};
2967 char opbuf[OPERATION_BUFFER_SIZE];
2969 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
2970 SlapReply rs = {REP_RESULT};
2972 /* If we read the config from back-ldif, nothing to do here */
2973 if ( cfb->cb_got_ldif )
2976 op = (Operation *)opbuf;
2977 connection_fake_init( &conn, op, cfb );
2979 op->o_dn = be->be_rootdn;
2980 op->o_ndn = be->be_rootndn;
2982 op->o_tag = LDAP_REQ_ADD;
2983 op->o_callback = &cb;
2984 op->o_bd = &cfb->cb_db;
2986 /* create root of tree */
2988 e = config_alloc_entry( NULL, &rdn );
2993 c.line = (char *)cfb->cb_config;
2994 ct = c.bi->bi_cf_table;
2995 config_build_entry( &c, e, cfOc_global, &rdn, ct, NO_TABLE );
2997 op->o_bd->be_add( op, &rs );
2998 ce->ce_type = Cf_Global;
3004 /* Create includeFile nodes... */
3005 if ( cfb->cb_config->c_kids ) {
3006 c.line = (char *)cfb->cb_config->c_kids;
3007 ceprev = config_build_includes( &c, parent, op, &rs );
3010 /* Create backend nodes. Skip if they don't provide a cf_table.
3011 * There usually aren't any of these.
3016 for (i=0; i<nBackendInfo; i++, bi++) {
3017 if (!bi->bi_cf_table) continue;
3018 if (!bi->bi_private) continue;
3021 rdn.bv_len = sprintf(rdn.bv_val, "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
3022 e = config_alloc_entry( &parent->e_nname, &rdn );
3024 ce->ce_type = Cf_Backend;
3027 config_build_entry( &c, e, cfOc_backend, &rdn, ct, BI_TABLE );
3029 op->o_bd->be_add( op, &rs );
3030 if ( !ceparent->ce_kids ) {
3031 ceparent->ce_kids = ce;
3033 ceprev->ce_sibs = ce;
3038 /* Create database nodes... */
3039 for (i=0; i<nBackendDB; i++) {
3040 slap_overinfo *oi = NULL;
3044 bptr = &backendDB[i];
3046 if ( overlay_is_over( bptr )) {
3047 oi = bptr->bd_info->bi_private;
3053 rdn.bv_len = sprintf(rdn.bv_val, "%s={%0x}%s", cfAd_database->ad_cname.bv_val,
3055 e = config_alloc_entry( &parent->e_nname, &rdn );
3059 ce->ce_type = Cf_Database;
3062 config_build_entry( &c, e, cfOc_database, &rdn, ct, BE_TABLE );
3064 op->o_bd->be_add( op, &rs );
3065 if ( !ceparent->ce_kids ) {
3066 ceparent->ce_kids = ce;
3068 ceprev->ce_sibs = ce;
3071 /* Iterate through overlays */
3075 CfEntryInfo *opar = ce, *oprev = NULL;
3078 for (j=0,on=oi->oi_list; on; j++,on=on->on_next) {
3080 rdn.bv_len = sprintf(rdn.bv_val, "%s={%0x}%s",
3081 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
3082 oe = config_alloc_entry( &e->e_nname, &rdn );
3086 ce->ce_type = Cf_Overlay;
3089 config_build_entry( &c, oe, cfOc_overlay, &rdn, ct, BI_TABLE );
3091 op->o_bd->be_add( op, &rs );
3092 if ( !opar->ce_kids ) {
3095 oprev->ce_sibs = ce;
3106 config_back_db_destroy( Backend *be )
3108 free( be->be_private );
3113 config_back_db_init( Backend *be )
3118 cfb = ch_calloc( 1, sizeof(CfBackInfo));
3119 cfb->cb_config = &cf_prv;
3120 be->be_private = cfb;
3122 ber_dupbv( &be->be_rootdn, &config_rdn );
3123 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
3124 ber_dupbv( &dn, &be->be_rootdn );
3125 ber_bvarray_add( &be->be_suffix, &dn );
3126 ber_dupbv( &dn, &be->be_rootdn );
3127 ber_bvarray_add( &be->be_nsuffix, &dn );
3129 /* Hide from namingContexts */
3130 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
3137 AttributeDescription **desc;
3138 AttributeDescription *sub;
3140 { "attribute", NULL, NULL },
3141 { "backend", &cfAd_backend, NULL },
3142 { "database", &cfAd_database, NULL },
3143 { "ditcontentrule", NULL, NULL },
3144 { "include", &cfAd_include, NULL },
3145 { "objectclass", NULL, NULL },
3146 { "overlay", &cfAd_overlay, NULL },
3147 { NULL, NULL, NULL }
3151 * add / delete: all types that may be added or deleted must use an
3152 * X-ORDERED attributeType for their RDN. Adding and deleting entries
3153 * should automatically renumber the index of any siblings as needed,
3154 * so that no gaps in the numbering sequence exist after the add/delete
3156 * What can be added:
3158 * backend objects for backend-specific config directives
3162 * delete: probably no support this time around.
3164 * modrdn: generally not done. Will be invoked automatically by add/
3165 * delete to update numbering sequence. Perform as an explicit operation
3166 * so that the renumbering effect may be replicated. Subtree rename must
3167 * be supported, since renumbering a database will affect all its child
3170 * modify: must be fully supported.
3174 config_back_initialize( BackendInfo *bi )
3176 ConfigTable *ct = config_back_cf_table;
3185 bi->bi_db_init = config_back_db_init;
3186 bi->bi_db_config = 0;
3187 bi->bi_db_open = config_back_db_open;
3188 bi->bi_db_close = 0;
3189 bi->bi_db_destroy = config_back_db_destroy;
3191 bi->bi_op_bind = config_back_bind;
3192 bi->bi_op_unbind = 0;
3193 bi->bi_op_search = config_back_search;
3194 bi->bi_op_compare = 0;
3195 bi->bi_op_modify = config_back_modify;
3196 bi->bi_op_modrdn = 0;
3198 bi->bi_op_delete = 0;
3199 bi->bi_op_abandon = 0;
3201 bi->bi_extended = 0;
3203 bi->bi_chk_referrals = 0;
3205 bi->bi_connection_init = 0;
3206 bi->bi_connection_destroy = 0;
3209 for (i=0; OidMacros[i].name; i++ ) {
3210 argv[1] = OidMacros[i].name;
3211 argv[2] = OidMacros[i].oid;
3212 parse_oidm( "slapd", i, 3, argv );
3215 bi->bi_cf_table = ct;
3217 i = config_register_schema( ct, cf_ocs );
3220 /* set up the notable AttributeDescriptions */
3221 ads[0].sub = slap_schema.si_ad_attributeTypes;
3222 ads[3].sub = slap_schema.si_ad_ditContentRules;
3223 ads[5].sub = slap_schema.si_ad_objectClasses;
3226 for (;ct->name;ct++) {
3227 if (strcmp(ct->name, ads[i].name)) continue;
3229 ct->ad = ads[i].sub;
3231 *ads[i].desc = ct->ad;
3234 if (!ads[i].name) break;