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");
39 static struct berval schema_rdn = BER_BVC("cn=schema");
42 typedef struct modpath_s {
43 struct modpath_s *mp_next;
44 struct berval mp_path;
48 static ModPaths modpaths, *modlast = &modpaths, *modcur = &modpaths;
51 typedef struct ConfigFile {
52 struct ConfigFile *c_sibs;
53 struct ConfigFile *c_kids;
55 AttributeType *c_at_head, *c_at_tail;
56 ContentRule *c_cr_head, *c_cr_tail;
57 ObjectClass *c_oc_head, *c_oc_tail;
58 OidMacro *c_om_head, *c_om_tail;
62 typedef struct CfOcInfo {
63 struct berval *co_name;
64 ConfigTable *co_table;
68 typedef struct CfEntryInfo {
69 struct CfEntryInfo *ce_parent;
70 struct CfEntryInfo *ce_sibs;
71 struct CfEntryInfo *ce_kids;
79 ConfigFile *cb_config;
81 BackendDB *cb_be; /* config backend */
82 BackendDB cb_db; /* underlying database */
86 /* These do nothing in slapd, they're kept only to make them
89 static char *replica_pidFile, *replica_argsFile;
90 static int replicationInterval;
92 static char *passwd_salt;
93 static char *logfileName;
94 static BerVarray authz_rewrites;
96 static struct berval cfdir;
99 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
102 static ObjectClass *cfOc_schema, *cfOc_global, *cfOc_backend, *cfOc_database,
103 *cfOc_include, *cfOc_overlay, *cfOc_module;
105 static ConfigFile cf_prv, *cfn = &cf_prv;
107 static Avlnode *CfOcTree;
109 static int add_syncrepl LDAP_P(( Backend *, char **, int ));
110 static int parse_syncrepl_line LDAP_P(( char **, int, syncinfo_t *));
111 static void syncrepl_unparse LDAP_P (( syncinfo_t *, struct berval *));
112 static int config_add_internal( CfBackInfo *cfb, Entry *e, SlapReply *rs );
114 static ConfigDriver config_fname;
115 static ConfigDriver config_cfdir;
116 static ConfigDriver config_generic;
117 static ConfigDriver config_search_base;
118 static ConfigDriver config_passwd_hash;
119 static ConfigDriver config_schema_dn;
120 static ConfigDriver config_sizelimit;
121 static ConfigDriver config_timelimit;
122 static ConfigDriver config_limits;
123 static ConfigDriver config_overlay;
124 static ConfigDriver config_suffix;
125 static ConfigDriver config_deref_depth;
126 static ConfigDriver config_rootdn;
127 static ConfigDriver config_rootpw;
128 static ConfigDriver config_restrict;
129 static ConfigDriver config_allows;
130 static ConfigDriver config_disallows;
131 static ConfigDriver config_requires;
132 static ConfigDriver config_security;
133 static ConfigDriver config_referral;
134 static ConfigDriver config_loglevel;
135 static ConfigDriver config_syncrepl;
136 static ConfigDriver config_replica;
137 static ConfigDriver config_updatedn;
138 static ConfigDriver config_updateref;
139 static ConfigDriver config_include;
141 static ConfigDriver config_tls_option;
142 static ConfigDriver config_tls_config;
191 static OidRec OidMacros[] = {
192 /* OpenLDAProot:666.11.1 */
193 { "OLcfg", "1.3.6.1.4.1.4203.666.11.1" },
194 { "OLcfgAt", "OLcfg:3" },
195 { "OLcfgOc", "OLcfg:4" },
196 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
197 { "OMsInteger", "OMsyn:2" },
198 { "OMsBoolean", "OMsyn:7" },
199 { "OMsDN", "OMsyn:12" },
200 { "OMsDirectoryString", "OMsyn:15" },
201 { "OMsOctetString", "OMsyn:40" },
205 /* alphabetical ordering */
207 ConfigTable config_back_cf_table[] = {
208 /* This attr is read-only */
209 { "", "", 0, 0, 0, ARG_MAGIC,
210 &config_fname, "( OLcfgAt:78 NAME 'olcConfigFile' "
211 "DESC 'File for slapd configuration directives' "
212 "EQUALITY caseIgnoreMatch "
213 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
214 { "", "", 0, 0, 0, ARG_MAGIC,
215 &config_cfdir, "( OLcfgAt:79 NAME 'olcConfigDir' "
216 "DESC 'Directory for slapd configuration backend' "
217 "EQUALITY caseIgnoreMatch "
218 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
219 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
220 &config_generic, "( OLcfgAt:1 NAME 'olcAccess' "
221 "DESC 'Access Control List' "
222 "EQUALITY caseIgnoreMatch "
223 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
224 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
225 &config_allows, "( OLcfgAt:2 NAME 'olcAllows' "
226 "DESC 'Allowed set of deprecated features' "
227 "EQUALITY caseIgnoreMatch "
228 "SYNTAX OMsDirectoryString )", NULL, NULL },
229 { "argsfile", "file", 2, 2, 0, ARG_STRING,
230 &slapd_args_file, "( OLcfgAt:3 NAME 'olcArgsFile' "
231 "DESC 'File for slapd command line options' "
232 "EQUALITY caseIgnoreMatch "
233 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
234 { "attribute", "attribute", 2, 0, 9, ARG_PAREN|ARG_MAGIC|CFG_ATTR,
235 &config_generic, "( OLcfgAt:4 NAME 'olcAttributeTypes' "
236 "DESC 'OpenLDAP attributeTypes' "
237 "EQUALITY caseIgnoreMatch "
238 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
240 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
241 &config_generic, "( OLcfgAt:5 NAME 'olcAttributeOptions' "
242 "EQUALITY caseIgnoreMatch "
243 "SYNTAX OMsDirectoryString )", NULL, NULL },
244 { "authid-rewrite", NULL, 2, 0, 0,
245 #ifdef SLAP_AUTH_REWRITE
246 ARG_MAGIC|CFG_REWRITE, &config_generic,
250 "( OLcfgAt:6 NAME 'olcAuthIDRewrite' "
251 "EQUALITY caseIgnoreMatch "
252 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
253 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
254 &config_generic, "( OLcfgAt:7 NAME 'olcAuthzPolicy' "
255 "EQUALITY caseIgnoreMatch "
256 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
257 { "authz-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
258 &config_generic, "( OLcfgAt:8 NAME 'olcAuthzRegexp' "
259 "EQUALITY caseIgnoreMatch "
260 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
261 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
262 &config_generic, "( OLcfgAt:9 NAME 'olcBackend' "
263 "DESC 'A type of backend' "
264 "EQUALITY caseIgnoreMatch "
265 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
266 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
267 &config_generic, "( OLcfgAt:10 NAME 'olcConcurrency' "
268 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
269 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
270 &slap_conn_max_pending, "( OLcfgAt:11 NAME 'olcConnMaxPending' "
271 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
272 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
273 &slap_conn_max_pending_auth, "( OLcfgAt:12 NAME 'olcConnMaxPendingAuth' "
274 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
275 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
276 &config_generic, "( OLcfgAt:13 NAME 'olcDatabase' "
277 "DESC 'The backend type for a database instance' "
278 "SUP olcBackend X-ORDERED 'VALUES' )", NULL, NULL },
279 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_MAGIC,
280 &config_search_base, "( OLcfgAt:14 NAME 'olcDefaultSearchBase' "
281 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
282 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
283 &config_disallows, "( OLcfgAt:15 NAME 'olcDisallows' "
284 "EQUALITY caseIgnoreMatch "
285 "SYNTAX OMsDirectoryString )", NULL, NULL },
286 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT,
287 &config_generic, "( OLcfgAt:16 NAME 'olcDitContentRules' "
288 "DESC 'OpenLDAP DIT content rules' "
289 "EQUALITY caseIgnoreMatch "
290 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
292 { "gentlehup", "on|off", 2, 2, 0,
294 ARG_ON_OFF, &global_gentlehup,
298 "( OLcfgAt:17 NAME 'olcGentleHUP' "
299 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
300 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
301 &global_idletimeout, "( OLcfgAt:18 NAME 'olcIdleTimeout' "
302 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
303 /* XXX -- special case? */
304 { "include", "file", 2, 2, 0, ARG_MAGIC,
305 &config_include, "( OLcfgAt:19 NAME 'olcInclude' "
306 "SUP labeledURI )", NULL, NULL },
307 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
308 &config_generic, "( OLcfgAt:20 NAME 'olcIndexSubstrIfMinLen' "
309 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
310 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
311 &config_generic, "( OLcfgAt:21 NAME 'olcIndexSubstrIfMaxLen' "
312 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
313 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
314 &index_substr_any_len, "( OLcfgAt:22 NAME 'olcIndexSubstrAnyLen' "
315 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
316 { "index_substr_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
317 &index_substr_any_step, "( OLcfgAt:23 NAME 'olcIndexSubstrAnyStep' "
318 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
319 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
320 &config_generic, "( OLcfgAt:24 NAME 'olcLastMod' "
321 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
322 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
323 &config_generic, "( OLcfgAt:25 NAME 'olcLimits' "
324 "SYNTAX OMsDirectoryString )", NULL, NULL },
325 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
326 &local_ssf, "( OLcfgAt:26 NAME 'olcLocalSSF' "
327 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
328 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
329 &config_generic, "( OLcfgAt:27 NAME 'olcLogFile' "
330 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
331 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
332 &config_loglevel, "( OLcfgAt:28 NAME 'olcLogLevel' "
333 "SYNTAX OMsDirectoryString )", NULL, NULL },
334 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
335 &config_generic, "( OLcfgAt:29 NAME 'olcMaxDerefDepth' "
336 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
337 { "moduleload", "file", 2, 0, 0,
339 ARG_MAGIC|CFG_MODLOAD, &config_generic,
343 "( OLcfgAt:30 NAME 'olcModuleLoad' "
344 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
345 { "modulepath", "path", 2, 2, 0,
347 ARG_MAGIC|CFG_MODPATH, &config_generic,
351 "( OLcfgAt:31 NAME 'olcModulePath' "
352 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
353 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
354 &config_generic, "( OLcfgAt:32 NAME 'olcObjectClasses' "
355 "DESC 'OpenLDAP object classes' "
356 "EQUALITY caseIgnoreMatch "
357 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
359 { "objectidentifier", NULL, 0, 0, 0, ARG_MAGIC|CFG_OID,
360 &config_generic, "( OLcfgAt:33 NAME 'olcObjectIdentifier' "
361 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
362 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
363 &config_overlay, "( OLcfgAt:34 NAME 'olcOverlay' "
364 "SUP olcDatabase X-ORDERED 'VALUES' )", NULL, NULL },
365 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
366 &config_generic, "( OLcfgAt:35 NAME 'olcPasswordCryptSaltFormat' "
367 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
368 { "password-hash", "hash", 2, 2, 0, ARG_MAGIC,
369 &config_passwd_hash, "( OLcfgAt:36 NAME 'olcPasswordHash' "
370 "SYNTAX OMsDirectoryString )", NULL, NULL },
371 { "pidfile", "file", 2, 2, 0, ARG_STRING,
372 &slapd_pid_file, "( OLcfgAt:37 NAME 'olcPidFile' "
373 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
374 { "plugin", NULL, 0, 0, 0,
376 ARG_MAGIC|CFG_PLUGIN, &config_generic,
380 "( OLcfgAt:38 NAME 'olcPlugin' "
381 "SYNTAX OMsDirectoryString )", NULL, NULL },
382 { "pluginlog", "filename", 2, 2, 0,
384 ARG_STRING, &slapi_log_file,
388 "( OLcfgAt:39 NAME 'olcPluginLogFile' "
389 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
390 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
391 &config_generic, "( OLcfgAt:40 NAME 'olcReadOnly' "
392 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
393 { "referral", "url", 2, 2, 0, ARG_MAGIC,
394 &config_referral, "( OLcfgAt:41 NAME 'olcReferral' "
395 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
396 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
397 &config_replica, "( OLcfgAt:42 NAME 'olcReplica' "
398 "SUP labeledURI )", NULL, NULL },
399 { "replica-argsfile", NULL, 0, 0, 0, ARG_STRING,
400 &replica_argsFile, "( OLcfgAt:43 NAME 'olcReplicaArgsFile' "
401 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
402 { "replica-pidfile", NULL, 0, 0, 0, ARG_STRING,
403 &replica_pidFile, "( OLcfgAt:44 NAME 'olcReplicaPidFile' "
404 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
405 { "replicationInterval", NULL, 0, 0, 0, ARG_INT,
406 &replicationInterval, "( OLcfgAt:45 NAME 'olcReplicationInterval' "
407 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
408 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC|ARG_STRING|CFG_REPLOG,
409 &config_generic, "( OLcfgAt:46 NAME 'olcReplogFile' "
410 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
411 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
412 &config_requires, "( OLcfgAt:47 NAME 'olcRequires' "
413 "SYNTAX OMsDirectoryString )", NULL, NULL },
414 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
415 &config_restrict, "( OLcfgAt:48 NAME 'olcRestrict' "
416 "SYNTAX OMsDirectoryString )", NULL, NULL },
417 { "reverse-lookup", "on|off", 2, 2, 0,
418 #ifdef SLAPD_RLOOKUPS
419 ARG_ON_OFF, &use_reverse_lookup,
423 "( OLcfgAt:49 NAME 'olcReverseLookup' "
424 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
425 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_MAGIC,
426 &config_rootdn, "( OLcfgAt:50 NAME 'olcRootDN' "
427 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
428 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
429 &config_generic, "( OLcfgAt:51 NAME 'olcRootDSE' "
430 "SYNTAX OMsDirectoryString )", NULL, NULL },
431 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
432 &config_rootpw, "( OLcfgAt:52 NAME 'olcRootPW' "
433 "SYNTAX OMsOctetString SINGLE-VALUE )", NULL, NULL },
434 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
435 &config_generic, NULL, NULL, NULL },
436 { "sasl-host", "host", 2, 2, 0,
437 #ifdef HAVE_CYRUS_SASL
438 ARG_STRING|ARG_UNIQUE, &global_host,
442 "( OLcfgAt:53 NAME 'olcSaslHost' "
443 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
444 { "sasl-realm", "realm", 2, 2, 0,
445 #ifdef HAVE_CYRUS_SASL
446 ARG_STRING|ARG_UNIQUE, &global_realm,
450 "( OLcfgAt:54 NAME 'olcSaslRealm' "
451 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
452 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
453 &config_generic, NULL, NULL, NULL },
454 { "sasl-secprops", "properties", 2, 2, 0,
455 #ifdef HAVE_CYRUS_SASL
456 ARG_MAGIC|CFG_SASLSECP, &config_generic,
460 "( OLcfgAt:56 NAME 'olcSaslSecProps' "
461 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
462 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
463 &config_generic, NULL, NULL, NULL },
464 { "schemacheck", "on|off", 2, 2, 0, ARG_ON_OFF|ARG_MAGIC|CFG_CHECK,
465 &config_generic, "( OLcfgAt:57 NAME 'olcSchemaCheck' "
466 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
467 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_MAGIC,
468 &config_schema_dn, "( OLcfgAt:58 NAME 'olcSchemaDN' "
469 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
470 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
471 &config_security, "( OLcfgAt:59 NAME 'olcSecurity' "
472 "SYNTAX OMsDirectoryString )", NULL, NULL },
473 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_SIZE,
474 &config_sizelimit, "( OLcfgAt:60 NAME 'olcSizeLimit' "
475 "SYNTAX OMsInteger )", NULL, NULL },
476 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
477 &sockbuf_max_incoming, "( OLcfgAt:61 NAME 'olcSockbufMaxIncoming' "
478 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
479 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
480 &sockbuf_max_incoming_auth, "( OLcfgAt:62 NAME 'olcSockbufMaxIncomingAuth' "
481 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
482 { "srvtab", "file", 2, 2, 0,
483 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
484 ARG_STRING, &ldap_srvtab,
488 "( OLcfgAt:63 NAME 'olcSrvtab' "
489 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
490 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_MAGIC,
491 &config_suffix, "( OLcfgAt:64 NAME 'olcSuffix' "
492 "SYNTAX OMsDN )", NULL, NULL },
493 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
494 &config_syncrepl, "( OLcfgAt:65 NAME 'olcSyncrepl' "
495 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
496 { "threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_THREADS,
497 &config_generic, "( OLcfgAt:66 NAME 'olcThreads' "
498 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
499 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_TIME,
500 &config_timelimit, "( OLcfgAt:67 NAME 'olcTimeLimit' "
501 "SYNTAX OMsInteger )", NULL, NULL },
502 { "TLSCACertificateFile", NULL, 0, 0, 0,
504 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
508 "( OLcfgAt:68 NAME 'olcTLSCACertificateFile' "
509 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
510 { "TLSCACertificatePath", NULL, 0, 0, 0,
512 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
516 "( OLcfgAt:69 NAME 'olcTLSCACertificatePath' "
517 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
518 { "TLSCertificateFile", NULL, 0, 0, 0,
520 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
524 "( OLcfgAt:70 NAME 'olcTLSCertificateFile' "
525 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
526 { "TLSCertificateKeyFile", NULL, 0, 0, 0,
528 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
532 "( OLcfgAt:71 NAME 'olcTLSCertificateKeyFile' "
533 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
534 { "TLSCipherSuite", NULL, 0, 0, 0,
536 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
540 "( OLcfgAt:72 NAME 'olcTLSCipherSuite' "
541 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
542 { "TLSCRLCheck", NULL, 0, 0, 0,
544 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
548 "( OLcfgAt:73 NAME 'olcTLSCRLCheck' "
549 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
550 { "TLSRandFile", NULL, 0, 0, 0,
552 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
556 "( OLcfgAt:74 NAME 'olcTLSRandFile' "
557 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
558 { "TLSVerifyClient", NULL, 0, 0, 0,
560 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
564 "( OLcfgAt:75 NAME 'olcTLSVerifyClient' "
565 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
566 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
567 NULL, NULL, NULL, NULL },
568 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_MAGIC,
569 &config_updatedn, "( OLcfgAt:76 NAME 'olcUpdateDN' "
570 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
571 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
572 &config_updateref, "( OLcfgAt:77 NAME 'olcUpdateRef' "
573 "SUP labeledURI )", NULL, NULL },
574 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
575 NULL, NULL, NULL, NULL }
578 static ConfigOCs cf_ocs[] = {
581 "DESC 'OpenLDAP configuration object' "
583 "MAY cn )", Cft_Abstract, NULL },
586 "DESC 'OpenLDAP Global configuration options' "
587 "SUP olcConfig STRUCTURAL "
588 "MAY ( olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
589 "olcAttributeOptions $ olcAttributeTypes $ olcAuthIDRewrite $ "
590 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
591 "olcConnMaxPending $ olcConnMaxPendingAuth $ olcDefaultSearchBase $ "
592 "olcDisallows $ olcDitContentRules $ olcGentleHUP $ olcIdleTimeout $ "
593 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
594 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcLocalSSF $ "
595 "olcLogLevel $ olcModulePath $ olcObjectClasses $ "
596 "olcObjectIdentifier $ "
597 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
598 "olcPlugin $ olcPluginLogFile $ olcReadOnly $ olcReferral $ "
599 "olcReplicaPidFile $ olcReplicaArgsFile $ olcReplicationInterval $ "
600 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
601 "olcRootDSE $ olcRootPW $ "
602 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
603 "olcSchemaCheck $ olcSchemaDN $ olcSecurity $ olcSizeLimit $ "
604 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ olcSrvtab $ "
605 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
606 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
607 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
608 "olcTLSRandFile $ olcTLSVerifyClient ) )", Cft_Global, &cfOc_global },
610 "NAME 'olcSchemaConfig' "
611 "DESC 'OpenLDAP schema object' "
612 "SUP olcConfig STRUCTURAL "
613 "MAY ( olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
614 "olcDitContentRules ) )", Cft_Schema, &cfOc_schema },
616 "NAME 'olcBackendConfig' "
617 "DESC 'OpenLDAP Backend-specific options' "
618 "SUP olcConfig STRUCTURAL "
619 "MAY ( olcBackend ) )", Cft_Backend, &cfOc_backend },
621 "NAME 'olcDatabaseConfig' "
622 "DESC 'OpenLDAP Database-specific options' "
623 "SUP olcConfig STRUCTURAL "
624 "MAY ( olcDatabase $ olcAccess $ olcLastMod $ olcLimits $ "
625 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
626 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
627 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSuffix $ olcSyncrepl $ "
628 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef ) )",
629 Cft_Database, &cfOc_database },
631 "NAME 'olcOverlayConfig' "
632 "DESC 'OpenLDAP Overlay-specific options' "
633 "SUP olcConfig STRUCTURAL "
634 "MAY ( olcOverlay ) )", Cft_Overlay, &cfOc_overlay },
636 "NAME 'olcIncludeFile' "
637 "DESC 'OpenLDAP configuration include file' "
638 "SUP olcConfig STRUCTURAL "
639 "MAY ( olcInclude $ olcConfigFile $ olcRootDSE ) )",
640 Cft_Include, &cfOc_include },
643 "NAME 'olcModuleList' "
644 "DESC 'OpenLDAP dynamic module info' "
645 "SUP olcConfig STRUCTURAL "
646 "MUST olcModuleLoad )",
647 Cft_Module, &cfOc_module },
653 config_generic(ConfigArgs *c) {
657 if ( c->op == SLAP_CONFIG_EMIT ) {
661 c->value_int = ldap_pvt_thread_get_concurrency();
664 c->value_int = connection_pool_max;
668 c->value_string = ch_strdup( passwd_salt );
673 if ( c->be->be_limits ) {
678 for ( i=0; c->be->be_limits[i]; i++ ) {
679 bv.bv_len = sprintf( buf, "{%d}", i );
680 bv.bv_val = buf+bv.bv_len;
681 limits_unparse( c->be->be_limits[i], &bv );
682 bv.bv_len += bv.bv_val - buf;
684 value_add_one( &c->rvalue_vals, &bv );
687 if ( !c->rvalue_vals ) rc = 1;
690 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_OP_WRITES) != 0;
693 c->value_string = ch_strdup( slap_sasl_getpolicy());
696 slap_sasl_regexp_unparse( &c->rvalue_vals );
697 if ( !c->rvalue_vals ) rc = 1;
699 #ifdef HAVE_CYRUS_SASL
701 struct berval bv = BER_BVNULL;
702 slap_sasl_secprops_unparse( &bv );
703 if ( !BER_BVISNULL( &bv )) {
704 ber_bvarray_add( &c->rvalue_vals, &bv );
712 c->value_int = c->be->be_max_deref_depth;
715 ConfigFile *cf = c->private;
717 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
718 else if ( cf->c_om_head )
719 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
721 if ( !c->rvalue_vals )
726 ConfigFile *cf = c->private;
728 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
729 else if ( cf->c_oc_head )
730 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
732 if ( !c->rvalue_vals )
737 ConfigFile *cf = c->private;
739 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
740 else if ( cf->c_at_head )
741 at_unparse( &c->rvalue_vals, cf->c_at_head,
743 if ( !c->rvalue_vals )
748 ConfigFile *cf = c->private;
750 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
751 else if ( cf->c_cr_head )
752 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
754 if ( !c->rvalue_vals )
760 c->value_int = global_schemacheck;
764 char *src, *dst, ibuf[11];
765 struct berval bv, abv;
766 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
767 abv.bv_len = sprintf( ibuf, "{%x}", i );
768 acl_unparse( a, &bv );
769 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
770 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
771 /* Turn TAB / EOL into plain space */
772 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
773 if (isspace(*src)) *dst++ = ' ';
777 if (dst[-1] == ' ') {
781 abv.bv_len = dst - abv.bv_val;
782 ber_bvarray_add( &c->rvalue_vals, &abv );
788 if ( c->be->be_replogfile )
789 c->value_string = ch_strdup( c->be->be_replogfile );
792 ConfigFile *cf = c->private;
793 if ( cf->c_dseFiles ) {
794 value_add( &c->rvalue_vals, cf->c_dseFiles );
802 c->value_string = ch_strdup( logfileName );
807 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
809 case CFG_SSTR_IF_MAX:
810 c->value_int = index_substr_if_maxlen;
812 case CFG_SSTR_IF_MIN:
813 c->value_int = index_substr_if_minlen;
817 ModPaths *mp = c->private;
820 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
823 bv.bv_len = sprintf( bv.bv_val, "{%d}%s", i,
824 mp->mp_loads[i].bv_val );
825 value_add_one( &c->rvalue_vals, &bv );
829 rc = c->rvalue_vals ? 0 : 1;
834 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
836 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
839 bv.bv_len = sprintf( bv.bv_val, "{%d}%s", i,
840 mp->mp_path.bv_val );
841 value_add_one( &c->rvalue_vals, &bv );
843 rc = c->rvalue_vals ? 0 : 1;
849 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
850 if ( !c->rvalue_vals ) rc = 1;
853 #ifdef SLAP_AUTH_REWRITE
855 if ( authz_rewrites ) {
856 struct berval bv, idx;
861 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
862 idx.bv_len = sprintf( idx.bv_val, "{%d}", i );
863 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
864 bv.bv_val = ch_malloc( bv.bv_len + 1 );
865 strcpy( bv.bv_val, idx.bv_val );
866 strcpy( bv.bv_val+idx.bv_len, authz_rewrites[i].bv_val );
867 ber_bvarray_add( &c->rvalue_vals, &bv );
870 if ( !c->rvalue_vals ) rc = 1;
879 p = strchr(c->line,'(' /*')'*/);
882 if(!(c->bi = backend_info(c->argv[1]))) {
883 Debug(LDAP_DEBUG_ANY, "%s: "
884 "backend %s failed init!\n", c->log, c->argv[1], 0);
891 /* NOTE: config is always the first backend!
893 if ( !strcasecmp( c->argv[1], "config" )) {
895 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
897 } else if(!(c->be = backend_db_init(c->argv[1]))) {
898 Debug(LDAP_DEBUG_ANY, "%s: "
899 "database %s failed init!\n", c->log, c->argv[1], 0);
905 ldap_pvt_thread_set_concurrency(c->value_int);
909 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
910 connection_pool_max = c->value_int; /* save for reference */
914 if ( passwd_salt ) ch_free( passwd_salt );
915 passwd_salt = c->value_string;
916 lutil_salt_format(passwd_salt);
920 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
926 c->be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
928 c->be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
932 ch_free(c->value_string);
933 if (slap_sasl_setpolicy( c->argv[1] )) {
934 Debug(LDAP_DEBUG_ANY, "%s: unable to parse value \"%s\" in"
935 " \"authz-policy <policy>\"\n",
936 c->log, c->argv[1], 0 );
942 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
946 #ifdef HAVE_CYRUS_SASL
949 char *txt = slap_sasl_secprops( c->argv[1] );
951 Debug(LDAP_DEBUG_ANY, "%s: sasl-secprops: %s\n",
960 c->be->be_max_deref_depth = c->value_int;
966 if(parse_oidm(c->fname, c->lineno, c->argc, c->argv, 1, &om))
968 if (!cfn->c_om_head) cfn->c_om_head = om;
976 if(parse_oc(c->fname, c->lineno, p, c->argv, &oc)) return(1);
977 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
985 if(parse_cr(c->fname, c->lineno, p, c->argv, &cr)) return(1);
986 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
994 if(parse_at(c->fname, c->lineno, p, c->argv, &at)) return(1);
995 if (!cfn->c_at_head) cfn->c_at_head = at;
1001 ad_define_option(NULL, NULL, 0);
1002 for(i = 1; i < c->argc; i++)
1003 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1008 global_schemacheck = c->value_int;
1009 if(!global_schemacheck) Debug(LDAP_DEBUG_ANY, "%s: "
1010 "schema checking disabled! your mileage may vary!\n",
1015 parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv);
1019 if(SLAP_MONITOR(c->be)) {
1020 Debug(LDAP_DEBUG_ANY, "%s: "
1021 "\"replogfile\" should not be used "
1022 "inside monitor database\n",
1024 return(0); /* FIXME: should this be an error? */
1027 c->be->be_replogfile = c->value_string;
1031 if(read_root_dse_file(c->argv[1])) {
1032 Debug(LDAP_DEBUG_ANY, "%s: "
1033 "could not read \"rootDSE <filename>\" line\n",
1039 ber_str2bv( c->argv[1], 0, 1, &bv );
1040 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1046 if ( logfileName ) ch_free( logfileName );
1047 logfileName = c->value_string;
1048 logfile = fopen(logfileName, "w");
1049 if(logfile) lutil_debug_file(logfile);
1053 if(SLAP_NOLASTMODCMD(c->be)) {
1054 Debug(LDAP_DEBUG_ANY, "%s: "
1055 "lastmod not available for %s databases\n",
1056 c->log, c->be->bd_info->bi_type, 0);
1060 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1062 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1065 case CFG_SSTR_IF_MAX:
1066 if (c->value_int < index_substr_if_minlen) {
1067 Debug(LDAP_DEBUG_ANY, "%s: "
1068 "invalid max value (%d)\n",
1069 c->log, c->value_int, 0 );
1072 index_substr_if_maxlen = c->value_int;
1075 case CFG_SSTR_IF_MIN:
1076 if (c->value_int > index_substr_if_maxlen) {
1077 Debug(LDAP_DEBUG_ANY, "%s: "
1078 "invalid min value (%d)\n",
1079 c->log, c->value_int, 0 );
1082 index_substr_if_minlen = c->value_int;
1085 #ifdef SLAPD_MODULES
1087 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1089 /* Record this load on the current path */
1092 ber_str2bv(c->line, 0, 1, &bv);
1093 ber_bvarray_add( &modcur->mp_loads, &bv );
1098 if(module_path(c->argv[1])) return(1);
1099 /* Record which path was used with each module */
1103 if (!modpaths.mp_loads) {
1106 mp = ch_malloc( sizeof( ModPaths ));
1107 modlast->mp_next = mp;
1109 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1111 mp->mp_loads = NULL;
1113 if ( c->op == SLAP_CONFIG_ADD )
1122 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
1124 slapi_plugins_used++;
1128 #ifdef SLAP_AUTH_REWRITE
1131 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
1133 ber_str2bv( c->line, 0, 1, &bv );
1134 ber_bvarray_add( &authz_rewrites, &bv );
1141 Debug(LDAP_DEBUG_ANY, "%s: unknown CFG_TYPE %d"
1142 "(ignored)\n", c->log, c->type, 0);
1150 config_fname(ConfigArgs *c) {
1151 if(c->op == SLAP_CONFIG_EMIT) {
1153 ConfigFile *cf = c->private;
1154 value_add_one( &c->rvalue_vals, &cf->c_file );
1163 config_cfdir(ConfigArgs *c) {
1164 if(c->op == SLAP_CONFIG_EMIT) {
1165 value_add_one( &c->rvalue_vals, &cfdir );
1172 config_search_base(ConfigArgs *c) {
1175 if(c->op == SLAP_CONFIG_EMIT) {
1177 if (!BER_BVISEMPTY(&default_search_base)) {
1178 value_add_one(&c->rvalue_vals, &default_search_base);
1179 value_add_one(&c->rvalue_nvals, &default_search_nbase);
1185 if(c->bi || c->be != frontendDB) {
1186 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
1187 "prior to any backend or database definition\n",
1192 if(default_search_nbase.bv_len) {
1193 Debug(LDAP_DEBUG_ANY, "%s: "
1194 "default search base \"%s\" already defined "
1195 "(discarding old)\n",
1196 c->log, default_search_base.bv_val, 0);
1197 free(default_search_base.bv_val);
1198 free(default_search_nbase.bv_val);
1201 default_search_base = c->value_dn;
1202 default_search_nbase = c->value_ndn;
1207 config_passwd_hash(ConfigArgs *c) {
1209 if (c->op == SLAP_CONFIG_EMIT) {
1211 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
1212 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
1213 value_add_one(&c->rvalue_vals, &bv);
1217 if(default_passwd_hash) {
1218 Debug(LDAP_DEBUG_ANY, "%s: "
1219 "already set default password_hash\n",
1223 for(i = 1; i < c->argc; i++) {
1224 if(!lutil_passwd_scheme(c->argv[i])) {
1225 Debug(LDAP_DEBUG_ANY, "%s: "
1226 "password scheme \"%s\" not available\n",
1227 c->log, c->argv[i], 0);
1229 ldap_charray_add(&default_passwd_hash, c->argv[i]);
1231 if(!default_passwd_hash) {
1232 Debug(LDAP_DEBUG_ANY, "%s: no valid hashes found\n",
1241 config_schema_dn(ConfigArgs *c) {
1242 if ( c->op == SLAP_CONFIG_EMIT ) {
1244 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
1245 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
1246 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
1251 c->be->be_schemadn = c->value_dn;
1252 c->be->be_schemandn = c->value_ndn;
1257 config_sizelimit(ConfigArgs *c) {
1260 struct slap_limits_set *lim = &c->be->be_def_limit;
1261 if (c->op == SLAP_CONFIG_EMIT) {
1266 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv );
1267 if ( !BER_BVISEMPTY( &bv ))
1268 value_add_one( &c->rvalue_vals, &bv );
1273 for(i = 1; i < c->argc; i++) {
1274 if(!strncasecmp(c->argv[i], "size", 4)) {
1275 rc = limits_parse_one(c->argv[i], lim);
1277 Debug(LDAP_DEBUG_ANY, "%s: "
1278 "unable to parse value \"%s\" in \"sizelimit <limit>\" line\n",
1279 c->log, c->argv[i], 0);
1283 if(!strcasecmp(c->argv[i], "unlimited")) {
1284 lim->lms_s_soft = -1;
1286 lim->lms_s_soft = strtol(c->argv[i], &next, 0);
1287 if(next == c->argv[i]) {
1288 Debug(LDAP_DEBUG_ANY, "%s: "
1289 "unable to parse limit \"%s\" in \"sizelimit <limit>\" line\n",
1290 c->log, c->argv[i], 0);
1292 } else if(next[0] != '\0') {
1293 Debug(LDAP_DEBUG_ANY, "%s: "
1294 "trailing chars \"%s\" in \"sizelimit <limit>\" line (ignored)\n",
1298 lim->lms_s_hard = 0;
1305 config_timelimit(ConfigArgs *c) {
1308 struct slap_limits_set *lim = &c->be->be_def_limit;
1309 if (c->op == SLAP_CONFIG_EMIT) {
1314 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv );
1315 if ( !BER_BVISEMPTY( &bv ))
1316 value_add_one( &c->rvalue_vals, &bv );
1321 for(i = 1; i < c->argc; i++) {
1322 if(!strncasecmp(c->argv[i], "time", 4)) {
1323 rc = limits_parse_one(c->argv[i], lim);
1325 Debug(LDAP_DEBUG_ANY, "%s: "
1326 "unable to parse value \"%s\" in \"timelimit <limit>\" line\n",
1327 c->log, c->argv[i], 0);
1331 if(!strcasecmp(c->argv[i], "unlimited")) {
1332 lim->lms_t_soft = -1;
1334 lim->lms_t_soft = strtol(c->argv[i], &next, 0);
1335 if(next == c->argv[i]) {
1336 Debug(LDAP_DEBUG_ANY, "%s: "
1337 "unable to parse limit \"%s\" in \"timelimit <limit>\" line\n",
1338 c->log, c->argv[i], 0);
1340 } else if(next[0] != '\0') {
1341 Debug(LDAP_DEBUG_ANY, "%s: "
1342 "trailing chars \"%s\" in \"timelimit <limit>\" line (ignored)\n",
1346 lim->lms_t_hard = 0;
1353 config_overlay(ConfigArgs *c) {
1354 if (c->op == SLAP_CONFIG_EMIT) {
1357 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1])) {
1359 Debug(LDAP_DEBUG_ANY, "%s: (optional) %s overlay \"%s\" configuration failed (ignored)\n",
1360 c->log, c->be == frontendDB ? "global " : "", c->argv[1][1]);
1361 } else if(overlay_config(c->be, c->argv[1])) {
1368 config_suffix(ConfigArgs *c) {
1370 struct berval pdn, ndn;
1373 if (c->be == frontendDB) return 1;
1375 if (c->op == SLAP_CONFIG_EMIT) {
1376 if (!BER_BVISNULL( &c->be->be_suffix[0] )) {
1377 value_add( &c->rvalue_vals, c->be->be_suffix );
1378 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
1384 #ifdef SLAPD_MONITOR_DN
1385 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
1386 Debug(LDAP_DEBUG_ANY, "%s: "
1387 "\"%s\" is reserved for monitoring slapd\n",
1388 c->log, SLAPD_MONITOR_DN, 0);
1395 tbe = select_backend(&ndn, 0, 0);
1397 Debug(LDAP_DEBUG_ANY, "%s: suffix already served by this backend! (ignored)\n",
1402 Debug(LDAP_DEBUG_ANY, "%s: suffix already served by a preceding backend \"%s\"\n",
1403 c->log, tbe->be_suffix[0].bv_val, 0);
1407 } else if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
1408 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
1409 "base provided \"%s\" (assuming okay)\n",
1410 c->log, default_search_base.bv_val, 0);
1412 ber_bvarray_add(&c->be->be_suffix, &pdn);
1413 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
1418 config_rootdn(ConfigArgs *c) {
1419 if (c->op == SLAP_CONFIG_EMIT) {
1420 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
1421 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
1422 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
1428 c->be->be_rootdn = c->value_dn;
1429 c->be->be_rootndn = c->value_ndn;
1434 config_rootpw(ConfigArgs *c) {
1436 if (c->op == SLAP_CONFIG_EMIT) {
1437 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
1438 ber_dupbv( &c->value_bv, &c->be->be_rootpw);
1444 tbe = select_backend(&c->be->be_rootndn, 0, 0);
1446 Debug(LDAP_DEBUG_ANY, "%s: "
1447 "rootpw can only be set when rootdn is under suffix\n",
1451 c->be->be_rootpw = c->value_bv;
1456 config_restrict(ConfigArgs *c) {
1457 slap_mask_t restrictops = 0;
1459 slap_verbmasks restrictable_ops[] = {
1460 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
1461 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
1462 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
1463 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
1464 { BER_BVC("modrdn"), 0 },
1465 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
1466 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
1467 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
1468 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
1469 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
1470 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
1471 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
1472 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
1473 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
1474 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
1478 if (c->op == SLAP_CONFIG_EMIT) {
1479 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
1482 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
1484 Debug(LDAP_DEBUG_ANY, "%s: "
1485 "unknown operation %s in \"restrict <features>\" line\n",
1486 c->log, c->argv[i], 0);
1489 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
1490 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
1491 c->be->be_restrictops |= restrictops;
1496 config_allows(ConfigArgs *c) {
1497 slap_mask_t allows = 0;
1499 slap_verbmasks allowable_ops[] = {
1500 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
1501 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
1502 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
1503 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
1506 if (c->op == SLAP_CONFIG_EMIT) {
1507 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
1509 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
1511 Debug(LDAP_DEBUG_ANY, "%s: "
1512 "unknown feature %s in \"allow <features>\" line\n",
1513 c->log, c->argv[i], 0);
1516 global_allows |= allows;
1521 config_disallows(ConfigArgs *c) {
1522 slap_mask_t disallows = 0;
1524 slap_verbmasks disallowable_ops[] = {
1525 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
1526 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
1527 { BER_BVC("bind_krb4"), SLAP_DISALLOW_BIND_KRBV4 },
1528 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
1529 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
1532 if (c->op == SLAP_CONFIG_EMIT) {
1533 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
1535 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
1537 Debug(LDAP_DEBUG_ANY, "%s: "
1538 "unknown feature %s in \"disallow <features>\" line\n",
1539 c->log, c->argv[i], 0);
1542 global_disallows |= disallows;
1547 config_requires(ConfigArgs *c) {
1548 slap_mask_t requires = 0;
1550 slap_verbmasks requires_ops[] = {
1551 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
1552 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
1553 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
1554 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
1555 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
1558 if (c->op == SLAP_CONFIG_EMIT) {
1559 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
1561 i = verbs_to_mask(c->argc, c->argv, requires_ops, &requires);
1563 Debug(LDAP_DEBUG_ANY, "%s: "
1564 "unknown feature %s in \"require <features>\" line\n",
1565 c->log, c->argv[i], 0);
1568 c->be->be_requires = requires;
1573 config_loglevel(ConfigArgs *c) {
1576 slap_verbmasks loglevel_ops[] = {
1577 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
1578 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
1579 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
1580 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
1581 { BER_BVC("BER"), LDAP_DEBUG_BER },
1582 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
1583 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
1584 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
1585 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
1586 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
1587 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
1588 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
1589 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
1590 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
1591 { BER_BVC("Any"), -1 },
1595 if (c->op == SLAP_CONFIG_EMIT) {
1596 return mask_to_verbs( loglevel_ops, ldap_syslog, &c->rvalue_vals );
1601 for( i=1; i < c->argc; i++ ) {
1604 if ( isdigit( c->argv[i][0] ) ) {
1605 level = strtol( c->argv[i], &next, 10 );
1606 if ( next == NULL || next[0] != '\0' ) {
1607 Debug( LDAP_DEBUG_ANY,
1608 "%s: unable to parse level \"%s\" "
1609 "in \"loglevel <level> [...]\" line.\n",
1610 c->log, c->argv[i], 0);
1614 int j = verb_to_mask(c->argv[i], loglevel_ops);
1615 if(BER_BVISNULL(&loglevel_ops[j].word)) {
1616 Debug( LDAP_DEBUG_ANY,
1617 "%s: unknown level \"%s\" "
1618 "in \"loglevel <level> [...]\" line.\n",
1619 c->log, c->argv[i], 0);
1622 level = loglevel_ops[j].mask;
1624 ldap_syslog |= level;
1630 config_syncrepl(ConfigArgs *c) {
1631 if (c->op == SLAP_CONFIG_EMIT) {
1632 if ( c->be->be_syncinfo ) {
1634 syncrepl_unparse( c->be->be_syncinfo, &bv );
1635 ber_bvarray_add( &c->rvalue_vals, &bv );
1640 if(SLAP_SHADOW(c->be)) {
1641 Debug(LDAP_DEBUG_ANY, "%s: "
1642 "syncrepl: database already shadowed.\n",
1645 } else if(add_syncrepl(c->be, c->argv, c->argc)) {
1648 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SYNC_SHADOW);
1653 config_referral(ConfigArgs *c) {
1654 struct berval vals[2];
1655 if (c->op == SLAP_CONFIG_EMIT) {
1656 if ( default_referral ) {
1657 value_add( &c->rvalue_vals, default_referral );
1663 if(validate_global_referral(c->argv[1])) {
1664 Debug(LDAP_DEBUG_ANY, "%s: "
1665 "invalid URL (%s) in \"referral\" line.\n",
1666 c->log, c->argv[1], 0);
1670 ber_str2bv(c->argv[1], 0, 0, &vals[0]);
1671 vals[1].bv_val = NULL; vals[1].bv_len = 0;
1672 if(value_add(&default_referral, vals)) return(LDAP_OTHER);
1680 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
1681 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
1682 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
1683 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
1684 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
1685 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
1686 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
1687 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
1688 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
1693 config_security(ConfigArgs *c) {
1694 slap_ssf_set_t *set = &c->be->be_ssf_set;
1697 if (c->op == SLAP_CONFIG_EMIT) {
1703 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
1704 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
1707 bv.bv_len = sprintf( numbuf, "%u", *tgt );
1708 bv.bv_len += sec_keys[i].key.bv_len;
1709 bv.bv_val = ch_malloc( bv.bv_len + 1);
1710 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
1711 strcpy( next, numbuf );
1712 ber_bvarray_add( &c->rvalue_vals, &bv );
1717 for(i = 1; i < c->argc; i++) {
1718 slap_ssf_t *tgt = NULL;
1720 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
1721 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
1722 sec_keys[j].key.bv_len)) {
1723 src = c->argv[i] + sec_keys[j].key.bv_len;
1724 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
1729 Debug(LDAP_DEBUG_ANY, "%s: "
1730 "unknown factor %s in \"security <factors>\" line\n",
1731 c->log, c->argv[i], 0);
1735 *tgt = strtol(src, &next, 10);
1736 if(next == NULL || next[0] != '\0' ) {
1737 Debug(LDAP_DEBUG_ANY, "%s: "
1738 "unable to parse factor \"%s\" in \"security <factors>\" line\n",
1739 c->log, c->argv[i], 0);
1747 anlist_unparse( AttributeName *an, char *ptr ) {
1750 for (; !BER_BVISNULL( &an->an_name ); an++) {
1751 if ( comma ) *ptr++ = ',';
1752 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
1759 replica_unparse( struct slap_replica_info *ri, int i, struct berval *bv )
1763 struct berval bc = {0};
1766 len = sprintf(numbuf, "{%d}", i );
1768 len += strlen( ri->ri_uri ) + STRLENOF("uri=");
1769 if ( ri->ri_nsuffix ) {
1770 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
1771 len += ri->ri_nsuffix[i].bv_len + STRLENOF(" suffix=\"\"");
1774 if ( ri->ri_attrs ) {
1775 len += STRLENOF("attr");
1776 if ( ri->ri_exclude ) len++;
1777 for (i=0; !BER_BVISNULL( &ri->ri_attrs[i].an_name ); i++) {
1778 len += 1 + ri->ri_attrs[i].an_name.bv_len;
1781 bindconf_unparse( &ri->ri_bindconf, &bc );
1784 bv->bv_val = ch_malloc(len + 1);
1787 ptr = lutil_strcopy( bv->bv_val, numbuf );
1788 ptr = lutil_strcopy( ptr, "uri=" );
1789 ptr = lutil_strcopy( ptr, ri->ri_uri );
1791 if ( ri->ri_nsuffix ) {
1792 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
1793 ptr = lutil_strcopy( ptr, " suffix=\"" );
1794 ptr = lutil_strcopy( ptr, ri->ri_nsuffix[i].bv_val );
1798 if ( ri->ri_attrs ) {
1799 ptr = lutil_strcopy( ptr, "attr" );
1800 if ( ri->ri_exclude ) *ptr++ = '!';
1802 ptr = anlist_unparse( ri->ri_attrs, ptr );
1805 strcpy( ptr, bc.bv_val );
1806 ch_free( bc.bv_val );
1811 config_replica(ConfigArgs *c) {
1812 int i, nr = -1, len;
1813 char *replicahost, *replicauri;
1816 if (c->op == SLAP_CONFIG_EMIT) {
1817 if (c->be->be_replica) {
1819 for (i=0;c->be->be_replica[i]; i++) {
1820 replica_unparse( c->be->be_replica[i], i, &bv );
1821 ber_bvarray_add( &c->rvalue_vals, &bv );
1827 if(SLAP_MONITOR(c->be)) {
1828 Debug(LDAP_DEBUG_ANY, "%s: "
1829 "\"replica\" should not be used inside monitor database\n",
1831 return(0); /* FIXME: should this be an error? */
1834 for(i = 1; i < c->argc; i++) {
1835 if(!strncasecmp(c->argv[i], "host=", STRLENOF("host="))) {
1836 replicahost = c->argv[i] + STRLENOF("host=");
1837 len = strlen( replicahost );
1838 replicauri = ch_malloc( len + STRLENOF("ldap://") + 1 );
1839 sprintf( replicauri, "ldap://%s", replicahost );
1840 replicahost = replicauri + STRLENOF( "ldap://");
1841 nr = add_replica_info(c->be, replicauri, replicahost);
1843 } else if(!strncasecmp(c->argv[i], "uri=", STRLENOF("uri="))) {
1844 if(ldap_url_parse(c->argv[i] + STRLENOF("uri="), &ludp) != LDAP_SUCCESS) {
1845 Debug(LDAP_DEBUG_ANY, "%s: "
1846 "replica line contains invalid "
1847 "uri definition.\n", c->log, 0, 0);
1850 if(!ludp->lud_host) {
1851 Debug(LDAP_DEBUG_ANY, "%s: "
1852 "replica line contains invalid "
1853 "uri definition - missing hostname.\n",
1857 ldap_free_urldesc(ludp);
1858 replicauri = c->argv[i] + STRLENOF("uri=");
1859 replicauri = ch_strdup( replicauri );
1860 replicahost = strchr( replicauri, '/' );
1862 nr = add_replica_info(c->be, replicauri, replicahost);
1867 Debug(LDAP_DEBUG_ANY, "%s: "
1868 "missing host or uri in \"replica\" line\n",
1871 } else if(nr == -1) {
1872 Debug(LDAP_DEBUG_ANY, "%s: "
1873 "unable to add replica \"%s\"\n",
1874 c->log, replicauri, 0);
1877 for(i = 1; i < c->argc; i++) {
1878 if(!strncasecmp(c->argv[i], "suffix=", STRLENOF( "suffix="))) {
1879 switch(add_replica_suffix(c->be, nr, c->argv[i] + STRLENOF("suffix="))) {
1881 Debug(LDAP_DEBUG_ANY, "%s: "
1882 "suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
1883 c->log, c->argv[i] + STRLENOF("suffix="), 0);
1886 Debug(LDAP_DEBUG_ANY, "%s: "
1887 "unable to normalize suffix in \"replica\" line (ignored)\n",
1892 } else if(!strncasecmp(c->argv[i], "attr", STRLENOF("attr"))) {
1894 char *arg = c->argv[i] + STRLENOF("attr");
1902 if(add_replica_attrs(c->be, nr, arg + 1, exclude)) {
1903 Debug(LDAP_DEBUG_ANY, "%s: "
1904 "attribute \"%s\" in \"replica\" line is unknown\n",
1905 c->log, arg + 1, 0);
1908 } else if ( bindconf_parse( c->argv[i],
1909 &c->be->be_replica[nr]->ri_bindconf ) ) {
1918 config_updatedn(ConfigArgs *c) {
1921 if (c->op == SLAP_CONFIG_EMIT) {
1922 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
1923 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
1924 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
1929 if(SLAP_SHADOW(c->be)) {
1930 Debug(LDAP_DEBUG_ANY, "%s: "
1931 "updatedn: database already shadowed.\n",
1936 ber_str2bv(c->argv[1], 0, 0, &dn);
1938 rc = dnNormalize(0, NULL, NULL, &dn, &c->be->be_update_ndn, NULL);
1940 if(rc != LDAP_SUCCESS) {
1941 Debug(LDAP_DEBUG_ANY, "%s: "
1942 "updatedn DN is invalid: %d (%s)\n",
1943 c->log, rc, ldap_err2string( rc ));
1947 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
1952 config_updateref(ConfigArgs *c) {
1953 struct berval vals[2];
1954 if (c->op == SLAP_CONFIG_EMIT) {
1955 if ( c->be->be_update_refs ) {
1956 value_add( &c->rvalue_vals, c->be->be_update_refs );
1962 if(!SLAP_SHADOW(c->be)) {
1963 Debug(LDAP_DEBUG_ANY, "%s: "
1964 "updateref line must come after syncrepl or updatedn.\n",
1969 if(validate_global_referral(c->argv[1])) {
1970 Debug(LDAP_DEBUG_ANY, "%s: "
1971 "invalid URL (%s) in \"updateref\" line.\n",
1972 c->log, c->argv[1], 0);
1975 ber_str2bv(c->argv[1], 0, 0, &vals[0]);
1976 vals[1].bv_val = NULL;
1977 if(value_add(&c->be->be_update_refs, vals)) return(LDAP_OTHER);
1982 config_include(ConfigArgs *c) {
1983 unsigned long savelineno = c->lineno;
1986 ConfigFile *cfsave = cfn;
1987 ConfigFile *cf2 = NULL;
1988 if (c->op == SLAP_CONFIG_EMIT) {
1991 cf = ch_calloc( 1, sizeof(ConfigFile));
1992 if ( cfn->c_kids ) {
1993 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
1999 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
2000 rc = read_config_file(c->argv[1], c->depth + 1, c);
2001 c->lineno = savelineno - 1;
2004 if ( cf2 ) cf2->c_sibs = NULL;
2005 else cfn->c_kids = NULL;
2006 ch_free( cf->c_file.bv_val );
2014 config_tls_option(ConfigArgs *c) {
2017 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; break;
2018 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
2019 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
2020 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
2021 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
2022 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
2023 default: Debug(LDAP_DEBUG_ANY, "%s: "
2024 "unknown tls_option <%x>\n",
2025 c->log, c->type, 0);
2027 if (c->op == SLAP_CONFIG_EMIT) {
2028 return ldap_pvt_tls_get_option( NULL, flag, &c->value_string );
2030 ch_free(c->value_string);
2031 return(ldap_pvt_tls_set_option(NULL, flag, c->argv[1]));
2034 /* FIXME: this ought to be provided by libldap */
2036 config_tls_config(ConfigArgs *c) {
2038 slap_verbmasks crlkeys[] = {
2039 { BER_BVC("none"), LDAP_OPT_X_TLS_CRL_NONE },
2040 { BER_BVC("peer"), LDAP_OPT_X_TLS_CRL_PEER },
2041 { BER_BVC("all"), LDAP_OPT_X_TLS_CRL_ALL },
2044 slap_verbmasks vfykeys[] = {
2045 { BER_BVC("never"), LDAP_OPT_X_TLS_NEVER },
2046 { BER_BVC("demand"), LDAP_OPT_X_TLS_DEMAND },
2047 { BER_BVC("try"), LDAP_OPT_X_TLS_TRY },
2048 { BER_BVC("hard"), LDAP_OPT_X_TLS_HARD },
2052 #ifdef HAVE_OPENSSL_CRL
2053 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; keys = crlkeys;
2056 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; keys = vfykeys;
2058 default: Debug(LDAP_DEBUG_ANY, "%s: "
2059 "unknown tls_option <%x>\n",
2060 c->log, c->type, 0);
2062 if (c->op == SLAP_CONFIG_EMIT) {
2063 ldap_pvt_tls_get_option( NULL, flag, &c->value_int );
2064 for (i=0; !BER_BVISNULL(&keys[i].word); i++) {
2065 if (keys[i].mask == c->value_int) {
2066 c->value_string = ch_strdup( keys[i].word.bv_val );
2072 ch_free( c->value_string );
2073 if(isdigit((unsigned char)c->argv[1][0])) {
2074 i = atoi(c->argv[1]);
2075 return(ldap_pvt_tls_set_option(NULL, flag, &i));
2077 return(ldap_int_tls_config(NULL, flag, c->argv[1]));
2092 si = (syncinfo_t *) ch_calloc( 1, sizeof( syncinfo_t ) );
2095 Debug( LDAP_DEBUG_ANY, "out of memory in add_syncrepl\n", 0, 0, 0 );
2099 si->si_bindconf.sb_tls = SB_TLS_OFF;
2100 si->si_bindconf.sb_method = LDAP_AUTH_SIMPLE;
2101 si->si_schemachecking = 0;
2102 ber_str2bv( "(objectclass=*)", STRLENOF("(objectclass=*)"), 1,
2103 &si->si_filterstr );
2104 si->si_base.bv_val = NULL;
2105 si->si_scope = LDAP_SCOPE_SUBTREE;
2106 si->si_attrsonly = 0;
2107 si->si_anlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ));
2108 si->si_exanlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ));
2109 si->si_attrs = NULL;
2110 si->si_allattrs = 0;
2111 si->si_allopattrs = 0;
2112 si->si_exattrs = NULL;
2113 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2114 si->si_interval = 86400;
2115 si->si_retryinterval = NULL;
2116 si->si_retrynum_init = NULL;
2117 si->si_retrynum = NULL;
2118 si->si_manageDSAit = 0;
2122 si->si_presentlist = NULL;
2123 LDAP_LIST_INIT( &si->si_nonpresentlist );
2124 ldap_pvt_thread_mutex_init( &si->si_mutex );
2126 rc = parse_syncrepl_line( cargv, cargc, si );
2129 Debug( LDAP_DEBUG_ANY, "failed to add syncinfo\n", 0, 0, 0 );
2130 syncinfo_free( si );
2133 Debug( LDAP_DEBUG_CONFIG,
2134 "Config: ** successfully added syncrepl \"%s\"\n",
2135 BER_BVISNULL( &si->si_provideruri ) ?
2136 "(null)" : si->si_provideruri.bv_val, 0, 0 );
2137 if ( !si->si_schemachecking ) {
2138 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NO_SCHEMA_CHECK;
2141 be->be_syncinfo = si;
2146 /* NOTE: used & documented in slapd.conf(5) */
2148 #define PROVIDERSTR "provider"
2149 #define TYPESTR "type"
2150 #define INTERVALSTR "interval"
2151 #define SEARCHBASESTR "searchbase"
2152 #define FILTERSTR "filter"
2153 #define SCOPESTR "scope"
2154 #define ATTRSSTR "attrs"
2155 #define ATTRSONLYSTR "attrsonly"
2156 #define SLIMITSTR "sizelimit"
2157 #define TLIMITSTR "timelimit"
2158 #define SCHEMASTR "schemachecking"
2160 /* FIXME: undocumented */
2161 #define OLDAUTHCSTR "bindprincipal"
2162 #define EXATTRSSTR "exattrs"
2163 #define RETRYSTR "retry"
2166 #define LASTMODSTR "lastmod"
2167 #define LMGENSTR "gen"
2168 #define LMNOSTR "no"
2169 #define LMREQSTR "req"
2170 #define SRVTABSTR "srvtab"
2171 #define SUFFIXSTR "suffix"
2172 #define MANAGEDSAITSTR "manageDSAit"
2175 #define GOT_ID 0x0001
2176 #define GOT_PROVIDER 0x0002
2179 #define GOT_ALL (GOT_ID|GOT_PROVIDER)
2185 { BER_BVC("base"), LDAP_SCOPE_BASE },
2186 { BER_BVC("one"), LDAP_SCOPE_ONELEVEL },
2187 #ifdef LDAP_SCOPE_SUBORDINATE
2188 { BER_BVC("children"), LDAP_SCOPE_SUBORDINATE },
2189 { BER_BVC("subordinate"), 0 },
2191 { BER_BVC("sub"), LDAP_SCOPE_SUBTREE },
2196 parse_syncrepl_line(
2206 for ( i = 1; i < cargc; i++ ) {
2207 if ( !strncasecmp( cargv[ i ], IDSTR "=",
2208 STRLENOF( IDSTR "=" ) ) )
2211 /* '\0' string terminator accounts for '=' */
2212 val = cargv[ i ] + STRLENOF( IDSTR "=" );
2214 if ( tmp >= 1000 || tmp < 0 ) {
2215 fprintf( stderr, "Error: parse_syncrepl_line: "
2216 "syncrepl id %d is out of range [0..999]\n", tmp );
2221 } else if ( !strncasecmp( cargv[ i ], PROVIDERSTR "=",
2222 STRLENOF( PROVIDERSTR "=" ) ) )
2224 val = cargv[ i ] + STRLENOF( PROVIDERSTR "=" );
2225 ber_str2bv( val, 0, 1, &si->si_provideruri );
2226 gots |= GOT_PROVIDER;
2227 } else if ( !strncasecmp( cargv[ i ], SCHEMASTR "=",
2228 STRLENOF( SCHEMASTR "=" ) ) )
2230 val = cargv[ i ] + STRLENOF( SCHEMASTR "=" );
2231 if ( !strncasecmp( val, "on", STRLENOF( "on" ) )) {
2232 si->si_schemachecking = 1;
2233 } else if ( !strncasecmp( val, "off", STRLENOF( "off" ) ) ) {
2234 si->si_schemachecking = 0;
2236 si->si_schemachecking = 1;
2238 } else if ( !strncasecmp( cargv[ i ], FILTERSTR "=",
2239 STRLENOF( FILTERSTR "=" ) ) )
2241 val = cargv[ i ] + STRLENOF( FILTERSTR "=" );
2242 ber_str2bv( val, 0, 1, &si->si_filterstr );
2243 } else if ( !strncasecmp( cargv[ i ], SEARCHBASESTR "=",
2244 STRLENOF( SEARCHBASESTR "=" ) ) )
2249 val = cargv[ i ] + STRLENOF( SEARCHBASESTR "=" );
2250 if ( si->si_base.bv_val ) {
2251 ch_free( si->si_base.bv_val );
2253 ber_str2bv( val, 0, 0, &bv );
2254 rc = dnNormalize( 0, NULL, NULL, &bv, &si->si_base, NULL );
2255 if ( rc != LDAP_SUCCESS ) {
2256 fprintf( stderr, "Invalid base DN \"%s\": %d (%s)\n",
2257 val, rc, ldap_err2string( rc ) );
2260 } else if ( !strncasecmp( cargv[ i ], SCOPESTR "=",
2261 STRLENOF( SCOPESTR "=" ) ) )
2264 val = cargv[ i ] + STRLENOF( SCOPESTR "=" );
2265 for ( j=0; !BER_BVISNULL(&scopes[j].key); j++ ) {
2266 if (!strncasecmp( val, scopes[j].key.bv_val,
2267 scopes[j].key.bv_len )) {
2268 while (!scopes[j].val) j--;
2269 si->si_scope = scopes[j].val;
2273 if ( BER_BVISNULL(&scopes[j].key) ) {
2274 fprintf( stderr, "Error: parse_syncrepl_line: "
2275 "unknown scope \"%s\"\n", val);
2278 } else if ( !strncasecmp( cargv[ i ], ATTRSONLYSTR "=",
2279 STRLENOF( ATTRSONLYSTR "=" ) ) )
2281 si->si_attrsonly = 1;
2282 } else if ( !strncasecmp( cargv[ i ], ATTRSSTR "=",
2283 STRLENOF( ATTRSSTR "=" ) ) )
2285 val = cargv[ i ] + STRLENOF( ATTRSSTR "=" );
2286 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") ) ) {
2288 attr_fname = ch_strdup( val + STRLENOF(":include:") );
2289 si->si_anlist = file2anlist( si->si_anlist, attr_fname, " ,\t" );
2290 if ( si->si_anlist == NULL ) {
2291 ch_free( attr_fname );
2294 si->si_anfile = attr_fname;
2296 char *str, *s, *next;
2297 char delimstr[] = " ,\t";
2298 str = ch_strdup( val );
2299 for ( s = ldap_pvt_strtok( str, delimstr, &next );
2301 s = ldap_pvt_strtok( NULL, delimstr, &next ) )
2303 if ( strlen(s) == 1 && *s == '*' ) {
2304 si->si_allattrs = 1;
2305 *(val + ( s - str )) = delimstr[0];
2307 if ( strlen(s) == 1 && *s == '+' ) {
2308 si->si_allopattrs = 1;
2309 *(val + ( s - str )) = delimstr[0];
2313 si->si_anlist = str2anlist( si->si_anlist, val, " ,\t" );
2314 if ( si->si_anlist == NULL ) {
2318 } else if ( !strncasecmp( cargv[ i ], EXATTRSSTR "=",
2319 STRLENOF( EXATTRSSTR "=" ) ) )
2321 val = cargv[ i ] + STRLENOF( EXATTRSSTR "=" );
2322 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") )) {
2324 attr_fname = ch_strdup( val + STRLENOF(":include:") );
2325 si->si_exanlist = file2anlist(
2326 si->si_exanlist, attr_fname, " ,\t" );
2327 if ( si->si_exanlist == NULL ) {
2328 ch_free( attr_fname );
2331 ch_free( attr_fname );
2333 si->si_exanlist = str2anlist( si->si_exanlist, val, " ,\t" );
2334 if ( si->si_exanlist == NULL ) {
2338 } else if ( !strncasecmp( cargv[ i ], TYPESTR "=",
2339 STRLENOF( TYPESTR "=" ) ) )
2341 val = cargv[ i ] + STRLENOF( TYPESTR "=" );
2342 if ( !strncasecmp( val, "refreshOnly",
2343 STRLENOF("refreshOnly") ))
2345 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2346 } else if ( !strncasecmp( val, "refreshAndPersist",
2347 STRLENOF("refreshAndPersist") ))
2349 si->si_type = LDAP_SYNC_REFRESH_AND_PERSIST;
2350 si->si_interval = 60;
2352 fprintf( stderr, "Error: parse_syncrepl_line: "
2353 "unknown sync type \"%s\"\n", val);
2356 } else if ( !strncasecmp( cargv[ i ], INTERVALSTR "=",
2357 STRLENOF( INTERVALSTR "=" ) ) )
2359 val = cargv[ i ] + STRLENOF( INTERVALSTR "=" );
2360 if ( si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ) {
2361 si->si_interval = 0;
2369 hstr = strchr( dstr, ':' );
2370 if ( hstr == NULL ) {
2371 fprintf( stderr, "Error: parse_syncrepl_line: "
2372 "invalid interval \"%s\"\n", val );
2376 mstr = strchr( hstr, ':' );
2377 if ( mstr == NULL ) {
2378 fprintf( stderr, "Error: parse_syncrepl_line: "
2379 "invalid interval \"%s\"\n", val );
2383 sstr = strchr( mstr, ':' );
2384 if ( sstr == NULL ) {
2385 fprintf( stderr, "Error: parse_syncrepl_line: "
2386 "invalid interval \"%s\"\n", val );
2395 if (( hh > 24 ) || ( hh < 0 ) ||
2396 ( mm > 60 ) || ( mm < 0 ) ||
2397 ( ss > 60 ) || ( ss < 0 ) || ( dd < 0 )) {
2398 fprintf( stderr, "Error: parse_syncrepl_line: "
2399 "invalid interval \"%s\"\n", val );
2402 si->si_interval = (( dd * 24 + hh ) * 60 + mm ) * 60 + ss;
2404 if ( si->si_interval < 0 ) {
2405 fprintf( stderr, "Error: parse_syncrepl_line: "
2406 "invalid interval \"%ld\"\n",
2407 (long) si->si_interval);
2410 } else if ( !strncasecmp( cargv[ i ], RETRYSTR "=",
2411 STRLENOF( RETRYSTR "=" ) ) )
2416 val = cargv[ i ] + STRLENOF( RETRYSTR "=" );
2417 retry_list = (char **) ch_calloc( 1, sizeof( char * ));
2418 retry_list[0] = NULL;
2420 slap_str2clist( &retry_list, val, " ,\t" );
2422 for ( k = 0; retry_list && retry_list[k]; k++ ) ;
2426 "Error: incomplete syncrepl retry list\n" );
2427 for ( k = 0; retry_list && retry_list[k]; k++ ) {
2428 ch_free( retry_list[k] );
2430 ch_free( retry_list );
2431 exit( EXIT_FAILURE );
2433 si->si_retryinterval = (time_t *) ch_calloc( n + 1, sizeof( time_t ));
2434 si->si_retrynum = (int *) ch_calloc( n + 1, sizeof( int ));
2435 si->si_retrynum_init = (int *) ch_calloc( n + 1, sizeof( int ));
2436 for ( j = 0; j < n; j++ ) {
2437 si->si_retryinterval[j] = atoi( retry_list[j*2] );
2438 if ( *retry_list[j*2+1] == '+' ) {
2439 si->si_retrynum_init[j] = -1;
2440 si->si_retrynum[j] = -1;
2444 si->si_retrynum_init[j] = atoi( retry_list[j*2+1] );
2445 si->si_retrynum[j] = atoi( retry_list[j*2+1] );
2448 si->si_retrynum_init[j] = -2;
2449 si->si_retrynum[j] = -2;
2450 si->si_retryinterval[j] = 0;
2452 for ( k = 0; retry_list && retry_list[k]; k++ ) {
2453 ch_free( retry_list[k] );
2455 ch_free( retry_list );
2456 } else if ( !strncasecmp( cargv[ i ], MANAGEDSAITSTR "=",
2457 STRLENOF( MANAGEDSAITSTR "=" ) ) )
2459 val = cargv[ i ] + STRLENOF( MANAGEDSAITSTR "=" );
2460 si->si_manageDSAit = atoi( val );
2461 } else if ( !strncasecmp( cargv[ i ], SLIMITSTR "=",
2462 STRLENOF( SLIMITSTR "=") ) )
2464 val = cargv[ i ] + STRLENOF( SLIMITSTR "=" );
2465 si->si_slimit = atoi( val );
2466 } else if ( !strncasecmp( cargv[ i ], TLIMITSTR "=",
2467 STRLENOF( TLIMITSTR "=" ) ) )
2469 val = cargv[ i ] + STRLENOF( TLIMITSTR "=" );
2470 si->si_tlimit = atoi( val );
2471 } else if ( bindconf_parse( cargv[i], &si->si_bindconf )) {
2472 fprintf( stderr, "Error: parse_syncrepl_line: "
2473 "unknown keyword \"%s\"\n", cargv[ i ] );
2478 if ( gots != GOT_ALL ) {
2480 "Error: Malformed \"syncrepl\" line in slapd config file" );
2488 syncrepl_unparse( syncinfo_t *si, struct berval *bv )
2491 char buf[BUFSIZ*2], *ptr;
2494 bindconf_unparse( &si->si_bindconf, &bc );
2496 ptr += sprintf( ptr, IDSTR "=%03d " PROVIDERSTR "=%s",
2497 si->si_rid, si->si_provideruri.bv_val );
2498 if ( !BER_BVISNULL( &bc )) {
2499 ptr = lutil_strcopy( ptr, bc.bv_val );
2502 if ( !BER_BVISEMPTY( &si->si_filterstr )) {
2503 ptr = lutil_strcopy( ptr, " " FILTERSTR "=\"" );
2504 ptr = lutil_strcopy( ptr, si->si_filterstr.bv_val );
2507 if ( !BER_BVISNULL( &si->si_base )) {
2508 ptr = lutil_strcopy( ptr, " " SEARCHBASESTR "=\"" );
2509 ptr = lutil_strcopy( ptr, si->si_base.bv_val );
2512 for (i=0; !BER_BVISNULL(&scopes[i].key);i++) {
2513 if ( si->si_scope == scopes[i].val ) {
2514 ptr = lutil_strcopy( ptr, " " SCOPESTR "=" );
2515 ptr = lutil_strcopy( ptr, scopes[i].key.bv_val );
2519 if ( si->si_attrsonly ) {
2520 ptr = lutil_strcopy( ptr, " " ATTRSONLYSTR "=yes" );
2522 if ( si->si_anfile ) {
2523 ptr = lutil_strcopy( ptr, " " ATTRSSTR "=:include:" );
2524 ptr = lutil_strcopy( ptr, si->si_anfile );
2525 } else if ( si->si_allattrs || si->si_allopattrs ||
2526 ( si->si_anlist && !BER_BVISNULL(&si->si_anlist[0].an_name) )) {
2528 ptr = lutil_strcopy( ptr, " " ATTRSSTR "=\"" );
2530 ptr = anlist_unparse( si->si_anlist, ptr );
2531 if ( si->si_allattrs ) {
2532 if ( old != ptr ) *ptr++ = ',';
2535 if ( si->si_allopattrs ) {
2536 if ( old != ptr ) *ptr++ = ',';
2541 if ( si->si_exanlist && !BER_BVISNULL(&si->si_exanlist[0].an_name) ) {
2542 ptr = lutil_strcopy( ptr, " " EXATTRSSTR "=" );
2543 ptr = anlist_unparse( si->si_exanlist, ptr );
2545 ptr = lutil_strcopy( ptr, " " SCHEMASTR "=" );
2546 ptr = lutil_strcopy( ptr, si->si_schemachecking ? "on" : "off" );
2548 ptr = lutil_strcopy( ptr, " " TYPESTR "=" );
2549 ptr = lutil_strcopy( ptr, si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ?
2550 "refreshAndPersist" : "refreshOnly" );
2552 if ( si->si_type == LDAP_SYNC_REFRESH_ONLY ) {
2555 dd = si->si_interval;
2562 ptr = lutil_strcopy( ptr, " " INTERVALSTR "=" );
2563 ptr += sprintf( ptr, "%02d:%02d:%02d:%02d", dd, hh, mm, ss );
2564 } else if ( si->si_retryinterval ) {
2566 ptr = lutil_strcopy( ptr, " " RETRYSTR "=\"" );
2567 for (i=0; si->si_retryinterval[i]; i++) {
2568 if ( space ) *ptr++ = ' ';
2570 ptr += sprintf( ptr, "%d", si->si_retryinterval[i] );
2571 if ( si->si_retrynum_init[i] == -1 )
2574 ptr += sprintf( ptr, "%d", si->si_retrynum_init );
2579 #if 0 /* FIXME: unused in syncrepl.c, should remove it */
2580 ptr = lutil_strcopy( ptr, " " MANAGEDSAITSTR "=" );
2581 ptr += sprintf( ptr, "%d", si->si_manageDSAit );
2584 if ( si->si_slimit ) {
2585 ptr = lutil_strcopy( ptr, " " SLIMITSTR "=" );
2586 ptr += sprintf( ptr, "%d", si->si_slimit );
2589 if ( si->si_tlimit ) {
2590 ptr = lutil_strcopy( ptr, " " TLIMITSTR "=" );
2591 ptr += sprintf( ptr, "%d", si->si_tlimit );
2593 bc.bv_len = ptr - buf;
2595 ber_dupbv( bv, &bc );
2598 static CfEntryInfo *
2599 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
2609 if ( dn_match( &root->ce_entry->e_nname, dn ))
2612 c = dn->bv_val+dn->bv_len;
2613 for (;*c != ',';c--);
2617 for (--c;c>dn->bv_val && *c != ',';c--);
2621 cdn.bv_len = dn->bv_len - (c-dn->bv_val);
2623 root = root->ce_kids;
2625 for (;root;root=root->ce_sibs) {
2626 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
2627 if ( cdn.bv_val == dn->bv_val ) {
2638 config_ldif_resp( Operation *op, SlapReply *rs )
2640 if ( rs->sr_type == REP_SEARCH ) {
2641 CfBackInfo *cfb = op->o_callback->sc_private;
2643 cfb->cb_got_ldif = 1;
2644 rs->sr_err = config_add_internal( cfb, rs->sr_entry, NULL );
2649 /* Configure and read the underlying back-ldif store */
2651 config_setup_ldif( BackendDB *be, const char *dir ) {
2652 CfBackInfo *cfb = be->be_private;
2657 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
2658 Connection conn = {0};
2659 char opbuf[OPERATION_BUFFER_SIZE];
2661 SlapReply rs = {REP_RESULT};
2662 Filter filter = { LDAP_FILTER_PRESENT };
2663 struct berval filterstr = BER_BVC("(objectclass=*)");
2665 cfb->cb_db.bd_info = backend_info( "ldif" );
2666 if ( !cfb->cb_db.bd_info )
2667 return 0; /* FIXME: eventually this will be a fatal error */
2669 if ( cfb->cb_db.bd_info->bi_db_init( &cfb->cb_db )) return 1;
2671 /* Mark that back-ldif type is in use */
2672 cfb->cb_db.bd_info->bi_nDB++;
2674 cfb->cb_db.be_suffix = be->be_suffix;
2675 cfb->cb_db.be_nsuffix = be->be_nsuffix;
2676 cfb->cb_db.be_rootdn = be->be_rootdn;
2677 cfb->cb_db.be_rootndn = be->be_rootndn;
2679 ber_str2bv( dir, 0, 1, &cfdir );
2684 argv[0] = "directory";
2685 argv[1] = (char *)dir;
2689 ct = config_find_keyword( c.be->be_cf_table, &c );
2693 if ( config_add_vals( ct, &c ))
2696 if ( backend_startup_one( &cfb->cb_db ))
2699 op = (Operation *)opbuf;
2700 connection_fake_init( &conn, op, cfb );
2702 filter.f_desc = slap_schema.si_ad_objectClass;
2704 op->o_tag = LDAP_REQ_SEARCH;
2706 op->ors_filter = &filter;
2707 op->ors_filterstr = filterstr;
2708 op->ors_scope = LDAP_SCOPE_SUBTREE;
2710 op->o_dn = be->be_rootdn;
2711 op->o_ndn = be->be_rootndn;
2713 op->o_req_dn = be->be_suffix[0];
2714 op->o_req_ndn = be->be_nsuffix[0];
2716 op->ors_tlimit = SLAP_NO_LIMIT;
2717 op->ors_slimit = SLAP_NO_LIMIT;
2719 op->ors_attrs = slap_anlist_all_attributes;
2720 op->ors_attrsonly = 0;
2722 op->o_callback = &cb;
2723 cb.sc_private = cfb;
2725 op->o_bd = &cfb->cb_db;
2726 op->o_bd->be_search( op, &rs );
2732 CfOcInfo_cmp( const void *c1, const void *c2 ) {
2733 const CfOcInfo *co1 = c1;
2734 const CfOcInfo *co2 = c2;
2736 return ber_bvcmp( co1->co_name, co2->co_name );
2740 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
2744 i = init_config_attrs( ct );
2747 /* set up the objectclasses */
2748 i = init_config_ocs( ocs );
2751 for (i=0; ocs[i].def; i++) {
2753 co = ch_malloc( sizeof(CfOcInfo) );
2754 co->co_name = &(*ocs[i].oc)->soc_cname;
2756 co->co_type = ocs[i].cft;
2757 avl_insert( &CfOcTree, co, CfOcInfo_cmp, avl_dup_error );
2764 read_config(const char *fname, const char *dir) {
2768 /* Setup the config backend */
2769 be = backend_db_init( "config" );
2773 cfb = be->be_private;
2775 /* Setup the underlying back-ldif backend */
2776 if ( config_setup_ldif( be, dir ))
2780 /* If we read the config from back-ldif, nothing to do here */
2781 if ( cfb->cb_got_ldif )
2784 ber_str2bv( fname, 0, 1, &cf_prv.c_file );
2786 return read_config_file(fname, 0, NULL);
2790 config_back_bind( Operation *op, SlapReply *rs )
2792 if ( op->orb_method == LDAP_AUTH_SIMPLE && be_isroot_pw( op )) {
2793 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
2794 /* frontend sends result */
2795 return LDAP_SUCCESS;
2798 rs->sr_err = LDAP_INVALID_CREDENTIALS;
2799 send_ldap_result( op, rs );
2805 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
2809 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
2811 rs->sr_attrs = op->ors_attrs;
2812 rs->sr_entry = ce->ce_entry;
2813 rc = send_search_entry( op, rs );
2815 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
2816 if ( ce->ce_kids ) {
2817 rc = config_send( op, rs, ce->ce_kids, 1 );
2818 if ( rc ) return rc;
2821 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
2822 rc = config_send( op, rs, ce, 0 );
2830 static ConfigTable *
2831 config_find_table( CfOcInfo *co, AttributeDescription *ad )
2835 for (i=0; co->co_table[i].name; i++)
2836 if ( co->co_table[i].ad == ad )
2837 return &co->co_table[i];
2841 /* Sort the values in an X-ORDERED attribute.
2842 * If the values have no index, leave them in their given order.
2843 * If the values have indexes, sort them and then strip the index.
2844 * If some are indexed and some are not, return Error.
2846 * FIXME: This function probably belongs in the frontend somewhere,
2847 * like slap_mods_check.
2850 sort_vals( Attribute *a )
2853 int index = 0, noindex = 0;
2855 /* count attrs, look for index */
2856 for (i=0; a->a_vals[i].bv_val; i++) {
2857 if ( a->a_vals[i].bv_val[0] == '{' ) {
2860 ptr = strchr( a->a_vals[i].bv_val, '}' );
2861 if ( !ptr || !ptr[1] )
2862 return LDAP_INVALID_SYNTAX;
2864 return LDAP_INVALID_SYNTAX;
2868 return LDAP_INVALID_SYNTAX;
2873 int vals = i, *indexes, j, idx;
2874 struct berval tmp, ntmp;
2877 /* Strip index from normalized values */
2878 if ( !a->a_nvals || a->a_vals == a->a_nvals ) {
2879 a->a_nvals = ch_malloc( (vals+1)*sizeof(struct berval));
2880 BER_BVZERO(a->a_nvals+vals);
2881 for ( i=0; i<vals; i++ ) {
2882 ptr = strchr(a->a_vals[i].bv_val, '}') + 1;
2883 a->a_nvals[i].bv_len = a->a_vals[i].bv_len -
2884 (ptr - a->a_vals[i].bv_val);
2885 a->a_nvals[i].bv_val = ch_malloc( a->a_nvals[i].bv_len + 1);
2886 strcpy(a->a_nvals[i].bv_val, ptr );
2889 for ( i=0; i<vals; i++ ) {
2890 ptr = strchr(a->a_nvals[i].bv_val, '}') + 1;
2891 a->a_nvals[i].bv_len -= ptr - a->a_nvals[i].bv_val;
2892 strcpy(a->a_nvals[i].bv_val, ptr);
2896 indexes = ch_malloc( vals * sizeof(int) );
2897 for ( i=0; i<vals; i++)
2898 indexes[i] = atoi(a->a_vals[i].bv_val+1);
2900 /* Insertion sort */
2901 for ( i=1; i<vals; i++ ) {
2904 ntmp = a->a_nvals[i];
2906 while ((j > 0) && (indexes[j-1] > idx)) {
2907 indexes[j] = indexes[j-1];
2908 a->a_vals[j] = a->a_vals[j-1];
2909 a->a_nvals[j] = a->a_nvals[j-1];
2914 a->a_nvals[j] = ntmp;
2921 check_attr( ConfigTable *ct, ConfigArgs *ca, Attribute *a )
2925 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
2926 rc = sort_vals( a );
2930 for ( i=0; a->a_nvals[i].bv_val; i++ ) {
2931 ca->line = a->a_nvals[i].bv_val;
2932 rc = config_parse_vals( ct, ca, i );
2939 /* Parse an LDAP entry into config directives */
2941 config_add_internal( CfBackInfo *cfb, Entry *e, SlapReply *rs )
2943 CfEntryInfo *ce, *last;
2944 CfOcInfo co, *coptr, **colst = NULL;
2945 Attribute *a, *oc_at, *type_attr;
2946 AttributeDescription *type_ad = NULL;
2948 ConfigArgs ca = {0};
2951 ConfigTable *ct, *type_ct = NULL;
2953 /* Make sure parent exists and entry does not */
2954 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
2956 return LDAP_ALREADY_EXISTS;
2958 dnParent( &e->e_nname, &pdn );
2960 /* If last is NULL, the new entry is the root/suffix entry,
2961 * otherwise last should be the parent.
2963 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn )) {
2965 rs->sr_matched = last->ce_entry->e_name.bv_val;
2966 return LDAP_NO_SUCH_OBJECT;
2969 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
2970 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
2972 /* count the objectclasses */
2973 for ( i=0; oc_at->a_nvals[i].bv_val; i++ );
2975 colst = (CfOcInfo **)ch_malloc( nocs * sizeof(CfOcInfo *));
2977 for ( i=0, j=0; i<nocs; i++) {
2978 co.co_name = &oc_at->a_nvals[i];
2979 coptr = avl_find( CfOcTree, &co, CfOcInfo_cmp );
2981 /* ignore non-config objectclasses. probably should be
2982 * an error, general data doesn't belong here.
2984 if ( !coptr ) continue;
2986 /* Ignore the root objectclass, it has no implementation.
2988 if ( coptr->co_type == Cft_Abstract ) continue;
2993 /* Only the root can be Cft_Global, everything else must
2994 * have a parent. Only limited nesting arrangements are allowed.
2996 switch( colst[0]->co_type ) {
2999 rc = LDAP_CONSTRAINT_VIOLATION;
3007 if ( !last || ( last->ce_type != Cft_Global &&
3008 last->ce_type != colst[0]->co_type )) {
3009 rc = LDAP_CONSTRAINT_VIOLATION;
3014 if ( !last || ( last->ce_type != Cft_Global &&
3015 last->ce_type != Cft_Database &&
3016 last->ce_type != colst[0]->co_type )) {
3017 rc = LDAP_CONSTRAINT_VIOLATION;
3020 #ifdef SLAPD_MODULES
3022 if ( !last || last->ce_type != Cft_Global ) {
3023 rc = LDAP_CONSTRAINT_VIOLATION;
3030 /* Parse all the values and check for simple syntax errors before
3031 * performing any set actions.
3033 switch (colst[0]->co_type) {
3035 /* The cn=schema entry is all hardcoded, so never reparse it */
3036 if (last->ce_type == Cft_Global )
3044 if ( last->ce_type == Cft_Backend )
3045 ca.bi = last->ce_bi;
3047 type_ad = cfAd_backend;
3050 if ( last->ce_type == Cft_Database ) {
3051 ca.be = last->ce_be;
3053 type_ad = cfAd_database;
3054 /* dummy, just to get past check_attr */
3060 ca.be = last->ce_be;
3061 type_ad = cfAd_overlay;
3064 if ( !rs ) /* ignored */
3066 type_ad = cfAd_include;
3067 #ifdef SLAPD_MODULES
3071 ptr = strchr( e->e_name.bv_val, '{' );
3073 rc = LDAP_NAMING_VIOLATION;
3077 for (i=0, mp=&modpaths; mp && i<j; mp=mp->mp_next);
3078 /* There is no corresponding modpath for this load? */
3080 rc = LDAP_NAMING_VIOLATION;
3083 module_path( mp->mp_path.bv_val );
3089 init_config_argv( &ca );
3091 type_attr = attr_find( e->e_attrs, type_ad );
3093 rc = LDAP_OBJECT_CLASS_VIOLATION;
3096 for ( i=0; i<nocs; i++ ) {
3097 type_ct = config_find_table( colst[i], type_ad );
3098 if ( type_ct ) break;
3101 rc = LDAP_OBJECT_CLASS_VIOLATION;
3104 rc = check_attr( type_ct, &ca, type_attr );
3105 if ( rc ) goto leave;
3107 for ( a=e->e_attrs; a; a=a->a_next ) {
3108 if ( a == type_attr || a == oc_at ) continue;
3110 for ( i=0; i<nocs; i++ ) {
3111 ct = config_find_table( colst[i], a->a_desc );
3114 if ( !ct ) continue; /* user data? */
3115 rc = check_attr( ct, &ca, a );
3116 if ( rc ) goto leave;
3119 /* Basic syntax checks are OK. Do the actual settings. */
3121 ca.line = type_attr->a_nvals[0].bv_val;
3122 rc = config_parse_add( type_ct, &ca, 0 );
3123 if ( rc ) goto leave;
3125 for ( a=e->e_attrs; a; a=a->a_next ) {
3126 if ( a == type_attr || a == oc_at ) continue;
3128 for ( i=0; i<nocs; i++ ) {
3129 ct = config_find_table( colst[i], a->a_desc );
3132 if ( !ct ) continue; /* user data? */
3133 for (i=0; a->a_nvals[i].bv_val; i++) {
3134 ca.line = a->a_nvals[i].bv_val;
3135 rc = config_parse_add( ct, &ca, i );
3136 if ( rc ) goto leave;
3140 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
3141 ce->ce_parent = last;
3142 ce->ce_entry = entry_dup( e );
3143 ce->ce_entry->e_private = ce;
3144 ce->ce_type = colst[0]->co_type;
3147 } else if ( last->ce_kids ) {
3150 for (c2=last->ce_kids; c2 && c2->ce_sibs; c2 = c2->ce_sibs);
3158 if ( colst ) ch_free( colst );
3162 /* Parse an LDAP entry into config directives, then store in underlying
3166 config_back_add( Operation *op, SlapReply *rs )
3169 CfEntryInfo *ce, *last;
3171 if ( !be_isroot( op ) ) {
3172 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3173 send_ldap_result( op, rs );
3176 cfb = (CfBackInfo *)op->o_bd->be_private;
3178 ldap_pvt_thread_pool_pause( &connection_pool );
3181 * 1) check for existence of entry
3182 * 2) perform internal add
3183 * 3) store entry in underlying database
3186 ldap_pvt_thread_pool_resume( &connection_pool );
3189 send_ldap_result( op, rs );
3194 config_back_modify( Operation *op, SlapReply *rs )
3197 CfEntryInfo *ce, *last;
3199 if ( !be_isroot( op ) ) {
3200 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3201 send_ldap_result( op, rs );
3204 cfb = (CfBackInfo *)op->o_bd->be_private;
3206 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3209 rs->sr_matched = last->ce_entry->e_name.bv_val;
3210 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3213 ldap_pvt_thread_pool_pause( &connection_pool );
3216 * 1) perform the Modify on the cached Entry.
3217 * 2) verify that the Entry still satisfies the schema.
3218 * 3) perform the individual config operations.
3219 * 4) store Modified entry in underlying LDIF backend.
3221 ldap_pvt_thread_pool_resume( &connection_pool );
3223 send_ldap_result( op, rs );
3228 config_back_search( Operation *op, SlapReply *rs )
3231 CfEntryInfo *ce, *last;
3234 if ( !be_isroot( op ) ) {
3235 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3236 send_ldap_result( op, rs );
3239 cfb = (CfBackInfo *)op->o_bd->be_private;
3241 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3244 rs->sr_matched = last->ce_entry->e_name.bv_val;
3245 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3248 switch ( op->ors_scope ) {
3249 case LDAP_SCOPE_BASE:
3250 case LDAP_SCOPE_SUBTREE:
3251 config_send( op, rs, ce, 0 );
3254 case LDAP_SCOPE_ONELEVEL:
3255 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
3256 config_send( op, rs, ce, 1 );
3261 rs->sr_err = LDAP_SUCCESS;
3263 send_ldap_result( op, rs );
3268 config_alloc_entry( CfEntryInfo *parent, struct berval *rdn )
3270 Entry *e = ch_calloc( 1, sizeof(Entry) );
3271 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
3276 ce->ce_parent = parent;
3278 pdn = parent->ce_entry->e_nname;
3283 build_new_dn( &e->e_name, &pdn, rdn, NULL );
3284 ber_dupbv( &e->e_nname, &e->e_name );
3293 config_build_entry( ConfigArgs *c, Entry *e, ObjectClass *oc,
3294 struct berval *rdn, ConfigTable *ct, int table )
3296 struct berval vals[2];
3297 struct berval ad_name;
3298 AttributeDescription *ad = NULL;
3302 char textbuf[SLAP_TEXT_BUFLEN];
3303 size_t textlen = sizeof(textbuf);
3307 BER_BVZERO( &vals[1] );
3309 vals[0] = oc->soc_cname;
3310 attr_merge(e, slap_schema.si_ad_objectClass, vals, NULL );
3311 ptr = strchr(rdn->bv_val, '=');
3312 ad_name.bv_val = rdn->bv_val;
3313 ad_name.bv_len = ptr - rdn->bv_val;
3314 rc = slap_bv2ad( &ad_name, &ad, &text );
3318 vals[0].bv_val = ptr+1;
3319 vals[0].bv_len = rdn->bv_len - (vals[0].bv_val - rdn->bv_val);
3320 attr_merge(e, ad, vals, NULL );
3322 for (at=oc->soc_required; at && *at; at++) {
3323 /* Skip the naming attr */
3324 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
3326 for (i=0;ct[i].name;i++) {
3327 if (ct[i].ad == (*at)->sat_ad) {
3328 rc = config_get_vals(&ct[i], c);
3329 if (rc == LDAP_SUCCESS) {
3330 attr_merge(e, ct[i].ad, c->rvalue_vals, c->rvalue_nvals);
3331 ber_bvarray_free( c->rvalue_nvals );
3332 ber_bvarray_free( c->rvalue_vals );
3339 for (at=oc->soc_allowed; at && *at; at++) {
3340 /* Skip the naming attr */
3341 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
3343 for (i=0;ct[i].name;i++) {
3344 if (ct[i].ad == (*at)->sat_ad) {
3345 rc = config_get_vals(&ct[i], c);
3346 if (rc == LDAP_SUCCESS) {
3347 attr_merge(e, ct[i].ad, c->rvalue_vals, c->rvalue_nvals);
3348 ber_bvarray_free( c->rvalue_nvals );
3349 ber_bvarray_free( c->rvalue_vals );
3357 if ( table == BI_TABLE )
3358 ct = c->bi->bi_cf_table;
3360 ct = c->be->be_cf_table;
3361 for (;ct && ct->name;ct++) {
3362 if (!ct->ad) continue;
3363 rc = config_get_vals(ct, c);
3364 if (rc == LDAP_SUCCESS) {
3365 attr_merge(e, ct->ad, c->rvalue_vals, c->rvalue_nvals);
3369 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
3370 rc = structural_class(oc_at->a_vals, vals, NULL, &text, textbuf, textlen);
3371 BER_BVZERO( &vals[1] );
3372 attr_merge(e, slap_schema.si_ad_structuralObjectClass, vals, NULL );
3378 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
3379 Operation *op, SlapReply *rs )
3382 ConfigFile *cf = c->private;
3383 CfEntryInfo *ce, *ceprev;
3387 if ( ceparent->ce_kids ) {
3388 for ( ceprev = ceparent->ce_kids; ceprev->ce_sibs;
3389 ceprev = ceprev->ce_sibs );
3392 for (; cf; cf=cf->c_sibs, c->depth++) {
3393 c->value_dn.bv_val = c->log;
3394 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
3399 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
3401 ptr = strchr( bv.bv_val, '.' );
3403 bv.bv_len = ptr - bv.bv_val;
3404 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn={%02d}", c->depth);
3405 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
3407 c->value_dn.bv_len += bv.bv_len;
3408 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
3410 e = config_alloc_entry( ceparent, &c->value_dn );
3412 config_build_entry( c, e, cfOc_schema, &c->value_dn,
3413 c->bi->bi_cf_table, NO_TABLE );
3415 ce->ce_type = Cft_Schema;
3417 op->o_bd->be_add( op, rs );
3419 if ( !ceparent->ce_kids ) {
3420 ceparent->ce_kids = ce;
3422 ceprev->ce_sibs = ce;
3426 c->private = cf->c_kids;
3427 config_build_schema_inc( c, ceparent, op, rs );
3432 static CfEntryInfo *
3433 config_build_includes( ConfigArgs *c, CfEntryInfo *ceparent,
3434 Operation *op, SlapReply *rs )
3438 ConfigFile *cf = c->private;
3439 CfEntryInfo *ce, *ceprev;
3441 if ( ceparent->ce_kids ) {
3442 for ( ceprev = ceparent->ce_kids; ceprev->ce_sibs;
3443 ceprev = ceprev->ce_sibs );
3446 for (i=0; cf; cf=cf->c_sibs, i++) {
3447 c->value_dn.bv_val = c->log;
3448 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=include{%02d}", i);
3449 e = config_alloc_entry( ceparent, &c->value_dn );
3451 config_build_entry( c, e, cfOc_include, &c->value_dn,
3452 c->bi->bi_cf_table, NO_TABLE );
3454 op->o_bd->be_add( op, rs );
3456 ce->ce_type = Cft_Include;
3458 if ( !ceparent->ce_kids ) {
3459 ceparent->ce_kids = ce;
3461 ceprev->ce_sibs = ce;
3465 c->private = cf->c_kids;
3466 config_build_includes( c, ce, op, rs );
3472 #ifdef SLAPD_MODULES
3474 static CfEntryInfo *
3475 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
3476 Operation *op, SlapReply *rs )
3480 CfEntryInfo *ce, *ceprev;
3483 if ( ceparent->ce_kids ) {
3484 for ( ceprev = ceparent->ce_kids; ceprev->ce_sibs;
3485 ceprev = ceprev->ce_sibs );
3488 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
3489 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
3491 c->value_dn.bv_val = c->log;
3492 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=module{%02d}", i);
3493 e = config_alloc_entry( ceparent, &c->value_dn );
3495 ce->ce_type = Cft_Include;
3497 config_build_entry( c, e, cfOc_module, &c->value_dn,
3498 c->bi->bi_cf_table, NO_TABLE );
3500 op->o_bd->be_add( op, rs );
3502 if ( !ceparent->ce_kids ) {
3503 ceparent->ce_kids = ce;
3505 ceprev->ce_sibs = ce;
3514 config_back_db_open( BackendDB *be )
3516 CfBackInfo *cfb = be->be_private;
3519 CfEntryInfo *ce, *ceparent, *ceprev;
3525 Connection conn = {0};
3526 char opbuf[OPERATION_BUFFER_SIZE];
3528 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
3529 SlapReply rs = {REP_RESULT};
3531 /* If we read the config from back-ldif, nothing to do here */
3532 if ( cfb->cb_got_ldif )
3535 op = (Operation *)opbuf;
3536 connection_fake_init( &conn, op, cfb );
3538 op->o_dn = be->be_rootdn;
3539 op->o_ndn = be->be_rootndn;
3541 op->o_tag = LDAP_REQ_ADD;
3542 op->o_callback = &cb;
3543 op->o_bd = &cfb->cb_db;
3545 /* create root of tree */
3547 e = config_alloc_entry( NULL, &rdn );
3549 ce->ce_type = Cft_Global;
3553 c.private = cfb->cb_config;
3554 ct = c.bi->bi_cf_table;
3555 config_build_entry( &c, e, cfOc_global, &rdn, ct, NO_TABLE );
3557 op->o_bd->be_add( op, &rs );
3563 /* Create schema nodes... cn=schema will contain the hardcoded core
3564 * schema, read-only. Child objects will contain runtime loaded schema
3568 e = config_alloc_entry( ceparent, &rdn );
3570 ce->ce_type = Cft_Schema;
3572 config_build_entry( &c, e, cfOc_schema, &rdn, ct, NO_TABLE );
3574 op->o_bd->be_add( op, &rs );
3575 if ( !ceparent->ce_kids ) {
3576 ceparent->ce_kids = ce;
3578 ceprev->ce_sibs = ce;
3582 /* Create includeFile nodes and schema nodes for included schema... */
3583 if ( cfb->cb_config->c_kids ) {
3585 c.private = cfb->cb_config->c_kids;
3586 config_build_schema_inc( &c, ce, op, &rs );
3587 c.private = cfb->cb_config->c_kids;
3588 ceprev = config_build_includes( &c, ceparent, op, &rs );
3591 #ifdef SLAPD_MODULES
3592 /* Create Module nodes... */
3593 if ( modpaths.mp_loads ) {
3594 ceprev = config_build_includes( &c, ceparent, op, &rs );
3598 /* Create backend nodes. Skip if they don't provide a cf_table.
3599 * There usually aren't any of these.
3604 for (i=0; i<nBackendInfo; i++, bi++) {
3605 if (!bi->bi_cf_table) continue;
3606 if (!bi->bi_private) continue;
3609 rdn.bv_len = sprintf(rdn.bv_val, "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
3610 e = config_alloc_entry( ceparent, &rdn );
3612 ce->ce_type = Cft_Backend;
3615 config_build_entry( &c, e, cfOc_backend, &rdn, ct, BI_TABLE );
3617 op->o_bd->be_add( op, &rs );
3618 if ( !ceparent->ce_kids ) {
3619 ceparent->ce_kids = ce;
3621 ceprev->ce_sibs = ce;
3626 /* Create database nodes... */
3627 for (i=0; i<nBackendDB; i++) {
3628 slap_overinfo *oi = NULL;
3632 bptr = &backendDB[i];
3634 if ( overlay_is_over( bptr )) {
3635 oi = bptr->bd_info->bi_private;
3641 rdn.bv_len = sprintf(rdn.bv_val, "%s={%0x}%s", cfAd_database->ad_cname.bv_val,
3643 e = config_alloc_entry( ceparent, &rdn );
3647 ce->ce_type = Cft_Database;
3650 config_build_entry( &c, e, cfOc_database, &rdn, ct, BE_TABLE );
3652 op->o_bd->be_add( op, &rs );
3653 if ( !ceparent->ce_kids ) {
3654 ceparent->ce_kids = ce;
3656 ceprev->ce_sibs = ce;
3659 /* Iterate through overlays */
3663 CfEntryInfo *opar = ce, *oprev = NULL;
3666 for (j=0,on=oi->oi_list; on; j++,on=on->on_next) {
3668 rdn.bv_len = sprintf(rdn.bv_val, "%s={%0x}%s",
3669 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
3670 oe = config_alloc_entry( opar, &rdn );
3674 ce->ce_type = Cft_Overlay;
3677 config_build_entry( &c, oe, cfOc_overlay, &rdn, ct, BI_TABLE );
3679 op->o_bd->be_add( op, &rs );
3680 if ( !opar->ce_kids ) {
3683 oprev->ce_sibs = ce;
3694 config_back_db_destroy( Backend *be )
3696 free( be->be_private );
3701 config_back_db_init( Backend *be )
3706 cfb = ch_calloc( 1, sizeof(CfBackInfo));
3707 cfb->cb_config = &cf_prv;
3709 be->be_private = cfb;
3711 ber_dupbv( &be->be_rootdn, &config_rdn );
3712 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
3713 ber_dupbv( &dn, &be->be_rootdn );
3714 ber_bvarray_add( &be->be_suffix, &dn );
3715 ber_dupbv( &dn, &be->be_rootdn );
3716 ber_bvarray_add( &be->be_nsuffix, &dn );
3718 /* Hide from namingContexts */
3719 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
3726 AttributeDescription **desc;
3728 { "backend", &cfAd_backend },
3729 { "database", &cfAd_database },
3730 { "include", &cfAd_include },
3731 { "overlay", &cfAd_overlay },
3732 { NULL, NULL, NULL }
3736 * add / delete: all types that may be added or deleted must use an
3737 * X-ORDERED attributeType for their RDN. Adding and deleting entries
3738 * should automatically renumber the index of any siblings as needed,
3739 * so that no gaps in the numbering sequence exist after the add/delete
3741 * What can be added:
3743 * backend objects for backend-specific config directives
3747 * delete: probably no support this time around.
3749 * modrdn: generally not done. Will be invoked automatically by add/
3750 * delete to update numbering sequence. Perform as an explicit operation
3751 * so that the renumbering effect may be replicated. Subtree rename must
3752 * be supported, since renumbering a database will affect all its child
3755 * modify: must be fully supported.
3759 config_back_initialize( BackendInfo *bi )
3761 ConfigTable *ct = config_back_cf_table;
3770 bi->bi_db_init = config_back_db_init;
3771 bi->bi_db_config = 0;
3772 bi->bi_db_open = config_back_db_open;
3773 bi->bi_db_close = 0;
3774 bi->bi_db_destroy = config_back_db_destroy;
3776 bi->bi_op_bind = config_back_bind;
3777 bi->bi_op_unbind = 0;
3778 bi->bi_op_search = config_back_search;
3779 bi->bi_op_compare = 0;
3780 bi->bi_op_modify = config_back_modify;
3781 bi->bi_op_modrdn = 0;
3783 bi->bi_op_delete = 0;
3784 bi->bi_op_abandon = 0;
3786 bi->bi_extended = 0;
3788 bi->bi_chk_referrals = 0;
3790 bi->bi_connection_init = 0;
3791 bi->bi_connection_destroy = 0;
3794 for (i=0; OidMacros[i].name; i++ ) {
3795 argv[1] = OidMacros[i].name;
3796 argv[2] = OidMacros[i].oid;
3797 parse_oidm( "slapd", i, 3, argv, 0, NULL );
3800 bi->bi_cf_table = ct;
3802 i = config_register_schema( ct, cf_ocs );
3805 /* set up the notable AttributeDescriptions */
3807 for (;ct->name;ct++) {
3808 if (strcmp(ct->name, ads[i].name)) continue;
3809 *ads[i].desc = ct->ad;
3811 if (!ads[i].name) break;