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_db; /* underlying database */
85 /* These do nothing in slapd, they're kept only to make them
88 static char *replica_pidFile, *replica_argsFile;
89 static int replicationInterval;
91 static char *passwd_salt;
92 static char *logfileName;
93 static BerVarray authz_rewrites;
95 static struct berval cfdir;
98 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
101 static ObjectClass *cfOc_schema, *cfOc_global, *cfOc_backend, *cfOc_database,
102 *cfOc_include, *cfOc_overlay, *cfOc_module;
104 static ConfigFile cf_prv, *cfn = &cf_prv;
106 static Avlnode *CfOcTree;
108 static int add_syncrepl LDAP_P(( Backend *, char **, int ));
109 static int parse_syncrepl_line LDAP_P(( char **, int, syncinfo_t *));
110 static void syncrepl_unparse LDAP_P (( syncinfo_t *, struct berval *));
111 static int config_add_internal( CfBackInfo *cfb, Entry *e, SlapReply *rs );
113 static ConfigDriver config_fname;
114 static ConfigDriver config_cfdir;
115 static ConfigDriver config_generic;
116 static ConfigDriver config_search_base;
117 static ConfigDriver config_passwd_hash;
118 static ConfigDriver config_schema_dn;
119 static ConfigDriver config_sizelimit;
120 static ConfigDriver config_timelimit;
121 static ConfigDriver config_limits;
122 static ConfigDriver config_overlay;
123 static ConfigDriver config_suffix;
124 static ConfigDriver config_deref_depth;
125 static ConfigDriver config_rootdn;
126 static ConfigDriver config_rootpw;
127 static ConfigDriver config_restrict;
128 static ConfigDriver config_allows;
129 static ConfigDriver config_disallows;
130 static ConfigDriver config_requires;
131 static ConfigDriver config_security;
132 static ConfigDriver config_referral;
133 static ConfigDriver config_loglevel;
134 static ConfigDriver config_syncrepl;
135 static ConfigDriver config_replica;
136 static ConfigDriver config_updatedn;
137 static ConfigDriver config_updateref;
138 static ConfigDriver config_include;
140 static ConfigDriver config_tls_option;
141 static ConfigDriver config_tls_config;
190 static OidRec OidMacros[] = {
191 /* OpenLDAProot:666.11.1 */
192 { "OLcfg", "1.3.6.1.4.1.4203.666.11.1" },
193 { "OLcfgAt", "OLcfg:3" },
194 { "OLcfgOc", "OLcfg:4" },
195 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
196 { "OMsInteger", "OMsyn:2" },
197 { "OMsBoolean", "OMsyn:7" },
198 { "OMsDN", "OMsyn:12" },
199 { "OMsDirectoryString", "OMsyn:15" },
200 { "OMsOctetString", "OMsyn:40" },
204 /* alphabetical ordering */
206 ConfigTable config_back_cf_table[] = {
207 /* This attr is read-only */
208 { "", "", 0, 0, 0, ARG_MAGIC,
209 &config_fname, "( OLcfgAt:78 NAME 'olcConfigFile' "
210 "DESC 'File for slapd configuration directives' "
211 "EQUALITY caseIgnoreMatch "
212 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
213 { "", "", 0, 0, 0, ARG_MAGIC,
214 &config_cfdir, "( OLcfgAt:79 NAME 'olcConfigDir' "
215 "DESC 'Directory for slapd configuration backend' "
216 "EQUALITY caseIgnoreMatch "
217 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
218 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
219 &config_generic, "( OLcfgAt:1 NAME 'olcAccess' "
220 "DESC 'Access Control List' "
221 "EQUALITY caseIgnoreMatch "
222 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
223 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
224 &config_allows, "( OLcfgAt:2 NAME 'olcAllows' "
225 "DESC 'Allowed set of deprecated features' "
226 "EQUALITY caseIgnoreMatch "
227 "SYNTAX OMsDirectoryString )", NULL, NULL },
228 { "argsfile", "file", 2, 2, 0, ARG_STRING,
229 &slapd_args_file, "( OLcfgAt:3 NAME 'olcArgsFile' "
230 "DESC 'File for slapd command line options' "
231 "EQUALITY caseIgnoreMatch "
232 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
233 { "attribute", "attribute", 2, 0, 9, ARG_PAREN|ARG_MAGIC|CFG_ATTR,
234 &config_generic, "( OLcfgAt:4 NAME 'olcAttributeTypes' "
235 "DESC 'OpenLDAP attributeTypes' "
236 "EQUALITY caseIgnoreMatch "
237 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
239 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
240 &config_generic, "( OLcfgAt:5 NAME 'olcAttributeOptions' "
241 "EQUALITY caseIgnoreMatch "
242 "SYNTAX OMsDirectoryString )", NULL, NULL },
243 { "authid-rewrite", NULL, 2, 0, 0,
244 #ifdef SLAP_AUTH_REWRITE
245 ARG_MAGIC|CFG_REWRITE, &config_generic,
249 "( OLcfgAt:6 NAME 'olcAuthIDRewrite' "
250 "EQUALITY caseIgnoreMatch "
251 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
252 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
253 &config_generic, "( OLcfgAt:7 NAME 'olcAuthzPolicy' "
254 "EQUALITY caseIgnoreMatch "
255 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
256 { "authz-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
257 &config_generic, "( OLcfgAt:8 NAME 'olcAuthzRegexp' "
258 "EQUALITY caseIgnoreMatch "
259 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
260 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
261 &config_generic, "( OLcfgAt:9 NAME 'olcBackend' "
262 "DESC 'A type of backend' "
263 "EQUALITY caseIgnoreMatch "
264 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
265 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
266 &config_generic, "( OLcfgAt:10 NAME 'olcConcurrency' "
267 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
268 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
269 &slap_conn_max_pending, "( OLcfgAt:11 NAME 'olcConnMaxPending' "
270 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
271 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
272 &slap_conn_max_pending_auth, "( OLcfgAt:12 NAME 'olcConnMaxPendingAuth' "
273 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
274 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
275 &config_generic, "( OLcfgAt:13 NAME 'olcDatabase' "
276 "DESC 'The backend type for a database instance' "
277 "SUP olcBackend X-ORDERED 'VALUES' )", NULL, NULL },
278 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_MAGIC,
279 &config_search_base, "( OLcfgAt:14 NAME 'olcDefaultSearchBase' "
280 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
281 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
282 &config_disallows, "( OLcfgAt:15 NAME 'olcDisallows' "
283 "EQUALITY caseIgnoreMatch "
284 "SYNTAX OMsDirectoryString )", NULL, NULL },
285 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT,
286 &config_generic, "( OLcfgAt:16 NAME 'olcDitContentRules' "
287 "DESC 'OpenLDAP DIT content rules' "
288 "EQUALITY caseIgnoreMatch "
289 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
291 { "gentlehup", "on|off", 2, 2, 0,
293 ARG_ON_OFF, &global_gentlehup,
297 "( OLcfgAt:17 NAME 'olcGentleHUP' "
298 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
299 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
300 &global_idletimeout, "( OLcfgAt:18 NAME 'olcIdleTimeout' "
301 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
302 /* XXX -- special case? */
303 { "include", "file", 2, 2, 0, ARG_MAGIC,
304 &config_include, "( OLcfgAt:19 NAME 'olcInclude' "
305 "SUP labeledURI )", NULL, NULL },
306 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
307 &config_generic, "( OLcfgAt:20 NAME 'olcIndexSubstrIfMinLen' "
308 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
309 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
310 &config_generic, "( OLcfgAt:21 NAME 'olcIndexSubstrIfMaxLen' "
311 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
312 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
313 &index_substr_any_len, "( OLcfgAt:22 NAME 'olcIndexSubstrAnyLen' "
314 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
315 { "index_substr_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
316 &index_substr_any_step, "( OLcfgAt:23 NAME 'olcIndexSubstrAnyStep' "
317 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
318 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
319 &config_generic, "( OLcfgAt:24 NAME 'olcLastMod' "
320 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
321 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
322 &config_generic, "( OLcfgAt:25 NAME 'olcLimits' "
323 "SYNTAX OMsDirectoryString )", NULL, NULL },
324 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
325 &local_ssf, "( OLcfgAt:26 NAME 'olcLocalSSF' "
326 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
327 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
328 &config_generic, "( OLcfgAt:27 NAME 'olcLogFile' "
329 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
330 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
331 &config_loglevel, "( OLcfgAt:28 NAME 'olcLogLevel' "
332 "SYNTAX OMsDirectoryString )", NULL, NULL },
333 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
334 &config_generic, "( OLcfgAt:29 NAME 'olcMaxDerefDepth' "
335 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
336 { "moduleload", "file", 2, 0, 0,
338 ARG_MAGIC|CFG_MODLOAD, &config_generic,
342 "( OLcfgAt:30 NAME 'olcModuleLoad' "
343 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
344 { "modulepath", "path", 2, 2, 0,
346 ARG_MAGIC|CFG_MODPATH, &config_generic,
350 "( OLcfgAt:31 NAME 'olcModulePath' "
351 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
352 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
353 &config_generic, "( OLcfgAt:32 NAME 'olcObjectClasses' "
354 "DESC 'OpenLDAP object classes' "
355 "EQUALITY caseIgnoreMatch "
356 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
358 { "objectidentifier", NULL, 0, 0, 0, ARG_MAGIC|CFG_OID,
359 &config_generic, "( OLcfgAt:33 NAME 'olcObjectIdentifier' "
360 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
361 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
362 &config_overlay, "( OLcfgAt:34 NAME 'olcOverlay' "
363 "SUP olcDatabase X-ORDERED 'VALUES' )", NULL, NULL },
364 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
365 &config_generic, "( OLcfgAt:35 NAME 'olcPasswordCryptSaltFormat' "
366 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
367 { "password-hash", "hash", 2, 2, 0, ARG_MAGIC,
368 &config_passwd_hash, "( OLcfgAt:36 NAME 'olcPasswordHash' "
369 "SYNTAX OMsDirectoryString )", NULL, NULL },
370 { "pidfile", "file", 2, 2, 0, ARG_STRING,
371 &slapd_pid_file, "( OLcfgAt:37 NAME 'olcPidFile' "
372 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
373 { "plugin", NULL, 0, 0, 0,
375 ARG_MAGIC|CFG_PLUGIN, &config_generic,
379 "( OLcfgAt:38 NAME 'olcPlugin' "
380 "SYNTAX OMsDirectoryString )", NULL, NULL },
381 { "pluginlog", "filename", 2, 2, 0,
383 ARG_STRING, &slapi_log_file,
387 "( OLcfgAt:39 NAME 'olcPluginLogFile' "
388 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
389 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
390 &config_generic, "( OLcfgAt:40 NAME 'olcReadOnly' "
391 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
392 { "referral", "url", 2, 2, 0, ARG_MAGIC,
393 &config_referral, "( OLcfgAt:41 NAME 'olcReferral' "
394 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
395 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
396 &config_replica, "( OLcfgAt:42 NAME 'olcReplica' "
397 "SUP labeledURI )", NULL, NULL },
398 { "replica-argsfile", NULL, 0, 0, 0, ARG_STRING,
399 &replica_argsFile, "( OLcfgAt:43 NAME 'olcReplicaArgsFile' "
400 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
401 { "replica-pidfile", NULL, 0, 0, 0, ARG_STRING,
402 &replica_pidFile, "( OLcfgAt:44 NAME 'olcReplicaPidFile' "
403 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
404 { "replicationInterval", NULL, 0, 0, 0, ARG_INT,
405 &replicationInterval, "( OLcfgAt:45 NAME 'olcReplicationInterval' "
406 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
407 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC|ARG_STRING|CFG_REPLOG,
408 &config_generic, "( OLcfgAt:46 NAME 'olcReplogFile' "
409 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
410 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
411 &config_requires, "( OLcfgAt:47 NAME 'olcRequires' "
412 "SYNTAX OMsDirectoryString )", NULL, NULL },
413 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
414 &config_restrict, "( OLcfgAt:48 NAME 'olcRestrict' "
415 "SYNTAX OMsDirectoryString )", NULL, NULL },
416 { "reverse-lookup", "on|off", 2, 2, 0,
417 #ifdef SLAPD_RLOOKUPS
418 ARG_ON_OFF, &use_reverse_lookup,
422 "( OLcfgAt:49 NAME 'olcReverseLookup' "
423 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
424 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_MAGIC,
425 &config_rootdn, "( OLcfgAt:50 NAME 'olcRootDN' "
426 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
427 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
428 &config_generic, "( OLcfgAt:51 NAME 'olcRootDSE' "
429 "SYNTAX OMsDirectoryString )", NULL, NULL },
430 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
431 &config_rootpw, "( OLcfgAt:52 NAME 'olcRootPW' "
432 "SYNTAX OMsOctetString SINGLE-VALUE )", NULL, NULL },
433 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
434 &config_generic, NULL, NULL, NULL },
435 { "sasl-host", "host", 2, 2, 0,
436 #ifdef HAVE_CYRUS_SASL
437 ARG_STRING|ARG_UNIQUE, &global_host,
441 "( OLcfgAt:53 NAME 'olcSaslHost' "
442 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
443 { "sasl-realm", "realm", 2, 2, 0,
444 #ifdef HAVE_CYRUS_SASL
445 ARG_STRING|ARG_UNIQUE, &global_realm,
449 "( OLcfgAt:54 NAME 'olcSaslRealm' "
450 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
451 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
452 &config_generic, NULL, NULL, NULL },
453 { "sasl-secprops", "properties", 2, 2, 0,
454 #ifdef HAVE_CYRUS_SASL
455 ARG_MAGIC|CFG_SASLSECP, &config_generic,
459 "( OLcfgAt:56 NAME 'olcSaslSecProps' "
460 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
461 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
462 &config_generic, NULL, NULL, NULL },
463 { "schemacheck", "on|off", 2, 2, 0, ARG_ON_OFF|ARG_MAGIC|CFG_CHECK,
464 &config_generic, "( OLcfgAt:57 NAME 'olcSchemaCheck' "
465 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
466 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_MAGIC,
467 &config_schema_dn, "( OLcfgAt:58 NAME 'olcSchemaDN' "
468 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
469 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
470 &config_security, "( OLcfgAt:59 NAME 'olcSecurity' "
471 "SYNTAX OMsDirectoryString )", NULL, NULL },
472 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_SIZE,
473 &config_sizelimit, "( OLcfgAt:60 NAME 'olcSizeLimit' "
474 "SYNTAX OMsInteger )", NULL, NULL },
475 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
476 &sockbuf_max_incoming, "( OLcfgAt:61 NAME 'olcSockbufMaxIncoming' "
477 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
478 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
479 &sockbuf_max_incoming_auth, "( OLcfgAt:62 NAME 'olcSockbufMaxIncomingAuth' "
480 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
481 { "srvtab", "file", 2, 2, 0,
482 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
483 ARG_STRING, &ldap_srvtab,
487 "( OLcfgAt:63 NAME 'olcSrvtab' "
488 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
489 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_MAGIC,
490 &config_suffix, "( OLcfgAt:64 NAME 'olcSuffix' "
491 "SYNTAX OMsDN )", NULL, NULL },
492 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
493 &config_syncrepl, "( OLcfgAt:65 NAME 'olcSyncrepl' "
494 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
495 { "threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_THREADS,
496 &config_generic, "( OLcfgAt:66 NAME 'olcThreads' "
497 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
498 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_TIME,
499 &config_timelimit, "( OLcfgAt:67 NAME 'olcTimeLimit' "
500 "SYNTAX OMsInteger )", NULL, NULL },
501 { "TLSCACertificateFile", NULL, 0, 0, 0,
503 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
507 "( OLcfgAt:68 NAME 'olcTLSCACertificateFile' "
508 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
509 { "TLSCACertificatePath", NULL, 0, 0, 0,
511 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
515 "( OLcfgAt:69 NAME 'olcTLSCACertificatePath' "
516 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
517 { "TLSCertificateFile", NULL, 0, 0, 0,
519 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
523 "( OLcfgAt:70 NAME 'olcTLSCertificateFile' "
524 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
525 { "TLSCertificateKeyFile", NULL, 0, 0, 0,
527 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
531 "( OLcfgAt:71 NAME 'olcTLSCertificateKeyFile' "
532 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
533 { "TLSCipherSuite", NULL, 0, 0, 0,
535 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
539 "( OLcfgAt:72 NAME 'olcTLSCipherSuite' "
540 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
541 { "TLSCRLCheck", NULL, 0, 0, 0,
543 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
547 "( OLcfgAt:73 NAME 'olcTLSCRLCheck' "
548 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
549 { "TLSRandFile", NULL, 0, 0, 0,
551 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
555 "( OLcfgAt:74 NAME 'olcTLSRandFile' "
556 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
557 { "TLSVerifyClient", NULL, 0, 0, 0,
559 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
563 "( OLcfgAt:75 NAME 'olcTLSVerifyClient' "
564 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
565 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
566 NULL, NULL, NULL, NULL },
567 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_MAGIC,
568 &config_updatedn, "( OLcfgAt:76 NAME 'olcUpdateDN' "
569 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
570 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
571 &config_updateref, "( OLcfgAt:77 NAME 'olcUpdateRef' "
572 "SUP labeledURI )", NULL, NULL },
573 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
574 NULL, NULL, NULL, NULL }
577 static ConfigOCs cf_ocs[] = {
580 "DESC 'OpenLDAP configuration object' "
582 "MAY cn )", Cft_Abstract, NULL },
585 "DESC 'OpenLDAP Global configuration options' "
586 "SUP olcConfig STRUCTURAL "
587 "MAY ( olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
588 "olcAttributeOptions $ olcAttributeTypes $ olcAuthIDRewrite $ "
589 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
590 "olcConnMaxPending $ olcConnMaxPendingAuth $ olcDefaultSearchBase $ "
591 "olcDisallows $ olcDitContentRules $ olcGentleHUP $ olcIdleTimeout $ "
592 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
593 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcLocalSSF $ "
594 "olcLogLevel $ olcModulePath $ olcObjectClasses $ "
595 "olcObjectIdentifier $ "
596 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
597 "olcPlugin $ olcPluginLogFile $ olcReadOnly $ olcReferral $ "
598 "olcReplicaPidFile $ olcReplicaArgsFile $ olcReplicationInterval $ "
599 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
600 "olcRootDSE $ olcRootPW $ "
601 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
602 "olcSchemaCheck $ olcSchemaDN $ olcSecurity $ olcSizeLimit $ "
603 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ olcSrvtab $ "
604 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
605 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
606 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
607 "olcTLSRandFile $ olcTLSVerifyClient ) )", Cft_Global, &cfOc_global },
609 "NAME 'olcSchemaConfig' "
610 "DESC 'OpenLDAP schema object' "
611 "SUP olcConfig STRUCTURAL "
612 "MAY ( olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
613 "olcDitContentRules ) )", Cft_Schema, &cfOc_schema },
615 "NAME 'olcBackendConfig' "
616 "DESC 'OpenLDAP Backend-specific options' "
617 "SUP olcConfig STRUCTURAL "
618 "MAY ( olcBackend ) )", Cft_Backend, &cfOc_backend },
620 "NAME 'olcDatabaseConfig' "
621 "DESC 'OpenLDAP Database-specific options' "
622 "SUP olcConfig STRUCTURAL "
623 "MAY ( olcDatabase $ olcSuffix $ olcAccess $ olcLastMod $ olcLimits $ "
624 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
625 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
626 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncrepl $ "
627 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef ) )",
628 Cft_Database, &cfOc_database },
630 "NAME 'olcOverlayConfig' "
631 "DESC 'OpenLDAP Overlay-specific options' "
632 "SUP olcConfig STRUCTURAL "
633 "MAY ( olcOverlay ) )", Cft_Overlay, &cfOc_overlay },
635 "NAME 'olcIncludeFile' "
636 "DESC 'OpenLDAP configuration include file' "
637 "SUP olcConfig STRUCTURAL "
638 "MAY ( olcInclude $ olcConfigFile $ olcRootDSE ) )",
639 Cft_Include, &cfOc_include },
642 "NAME 'olcModuleList' "
643 "DESC 'OpenLDAP dynamic module info' "
644 "SUP olcConfig STRUCTURAL "
645 "MUST olcModuleLoad )",
646 Cft_Module, &cfOc_module },
652 config_generic(ConfigArgs *c) {
656 if ( c->op == SLAP_CONFIG_EMIT ) {
660 c->value_int = ldap_pvt_thread_get_concurrency();
663 c->value_int = connection_pool_max;
667 c->value_string = ch_strdup( passwd_salt );
672 if ( c->be->be_limits ) {
677 for ( i=0; c->be->be_limits[i]; i++ ) {
678 bv.bv_len = sprintf( buf, "{%d}", i );
679 bv.bv_val = buf+bv.bv_len;
680 limits_unparse( c->be->be_limits[i], &bv );
681 bv.bv_len += bv.bv_val - buf;
683 value_add_one( &c->rvalue_vals, &bv );
686 if ( !c->rvalue_vals ) rc = 1;
689 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_OP_WRITES) != 0;
692 c->value_string = ch_strdup( slap_sasl_getpolicy());
695 slap_sasl_regexp_unparse( &c->rvalue_vals );
696 if ( !c->rvalue_vals ) rc = 1;
698 #ifdef HAVE_CYRUS_SASL
700 struct berval bv = BER_BVNULL;
701 slap_sasl_secprops_unparse( &bv );
702 if ( !BER_BVISNULL( &bv )) {
703 ber_bvarray_add( &c->rvalue_vals, &bv );
711 c->value_int = c->be->be_max_deref_depth;
714 ConfigFile *cf = c->private;
716 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
717 else if ( cf->c_om_head )
718 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
720 if ( !c->rvalue_vals )
725 ConfigFile *cf = c->private;
727 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
728 else if ( cf->c_oc_head )
729 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
731 if ( !c->rvalue_vals )
736 ConfigFile *cf = c->private;
738 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
739 else if ( cf->c_at_head )
740 at_unparse( &c->rvalue_vals, cf->c_at_head,
742 if ( !c->rvalue_vals )
747 ConfigFile *cf = c->private;
749 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
750 else if ( cf->c_cr_head )
751 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
753 if ( !c->rvalue_vals )
759 c->value_int = global_schemacheck;
763 char *src, *dst, ibuf[11];
764 struct berval bv, abv;
765 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
766 abv.bv_len = sprintf( ibuf, "{%x}", i );
767 acl_unparse( a, &bv );
768 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
769 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
770 /* Turn TAB / EOL into plain space */
771 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
772 if (isspace(*src)) *dst++ = ' ';
776 if (dst[-1] == ' ') {
780 abv.bv_len = dst - abv.bv_val;
781 ber_bvarray_add( &c->rvalue_vals, &abv );
787 if ( c->be->be_replogfile )
788 c->value_string = ch_strdup( c->be->be_replogfile );
791 ConfigFile *cf = c->private;
792 if ( cf->c_dseFiles ) {
793 value_add( &c->rvalue_vals, cf->c_dseFiles );
801 c->value_string = ch_strdup( logfileName );
806 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
808 case CFG_SSTR_IF_MAX:
809 c->value_int = index_substr_if_maxlen;
811 case CFG_SSTR_IF_MIN:
812 c->value_int = index_substr_if_minlen;
816 ModPaths *mp = c->private;
819 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
822 bv.bv_len = sprintf( bv.bv_val, "{%d}%s", i,
823 mp->mp_loads[i].bv_val );
824 value_add_one( &c->rvalue_vals, &bv );
828 rc = c->rvalue_vals ? 0 : 1;
833 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
835 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
838 bv.bv_len = sprintf( bv.bv_val, "{%d}%s", i,
839 mp->mp_path.bv_val );
840 value_add_one( &c->rvalue_vals, &bv );
842 rc = c->rvalue_vals ? 0 : 1;
848 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
849 if ( !c->rvalue_vals ) rc = 1;
852 #ifdef SLAP_AUTH_REWRITE
854 if ( authz_rewrites ) {
855 struct berval bv, idx;
860 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
861 idx.bv_len = sprintf( idx.bv_val, "{%d}", i );
862 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
863 bv.bv_val = ch_malloc( bv.bv_len + 1 );
864 strcpy( bv.bv_val, idx.bv_val );
865 strcpy( bv.bv_val+idx.bv_len, authz_rewrites[i].bv_val );
866 ber_bvarray_add( &c->rvalue_vals, &bv );
869 if ( !c->rvalue_vals ) rc = 1;
878 p = strchr(c->line,'(' /*')'*/);
881 if(!(c->bi = backend_info(c->argv[1]))) {
882 Debug(LDAP_DEBUG_ANY, "%s: "
883 "backend %s failed init!\n", c->log, c->argv[1], 0);
890 /* NOTE: config is always the first backend!
892 if ( !strcasecmp( c->argv[1], "config" )) {
894 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
896 } else if(!(c->be = backend_db_init(c->argv[1]))) {
897 Debug(LDAP_DEBUG_ANY, "%s: "
898 "database %s failed init!\n", c->log, c->argv[1], 0);
904 ldap_pvt_thread_set_concurrency(c->value_int);
908 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
909 connection_pool_max = c->value_int; /* save for reference */
913 if ( passwd_salt ) ch_free( passwd_salt );
914 passwd_salt = c->value_string;
915 lutil_salt_format(passwd_salt);
919 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
925 c->be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
927 c->be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
931 ch_free(c->value_string);
932 if (slap_sasl_setpolicy( c->argv[1] )) {
933 Debug(LDAP_DEBUG_ANY, "%s: unable to parse value \"%s\" in"
934 " \"authz-policy <policy>\"\n",
935 c->log, c->argv[1], 0 );
941 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
945 #ifdef HAVE_CYRUS_SASL
948 char *txt = slap_sasl_secprops( c->argv[1] );
950 Debug(LDAP_DEBUG_ANY, "%s: sasl-secprops: %s\n",
959 c->be->be_max_deref_depth = c->value_int;
965 if(parse_oidm(c->fname, c->lineno, c->argc, c->argv, 1, &om))
967 if (!cfn->c_om_head) cfn->c_om_head = om;
975 if(parse_oc(c->fname, c->lineno, p, c->argv, &oc)) return(1);
976 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
984 if(parse_cr(c->fname, c->lineno, p, c->argv, &cr)) return(1);
985 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
993 if(parse_at(c->fname, c->lineno, p, c->argv, &at)) return(1);
994 if (!cfn->c_at_head) cfn->c_at_head = at;
1000 ad_define_option(NULL, NULL, 0);
1001 for(i = 1; i < c->argc; i++)
1002 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1007 global_schemacheck = c->value_int;
1008 if(!global_schemacheck) Debug(LDAP_DEBUG_ANY, "%s: "
1009 "schema checking disabled! your mileage may vary!\n",
1014 parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv);
1018 if(SLAP_MONITOR(c->be)) {
1019 Debug(LDAP_DEBUG_ANY, "%s: "
1020 "\"replogfile\" should not be used "
1021 "inside monitor database\n",
1023 return(0); /* FIXME: should this be an error? */
1026 c->be->be_replogfile = c->value_string;
1030 if(read_root_dse_file(c->argv[1])) {
1031 Debug(LDAP_DEBUG_ANY, "%s: "
1032 "could not read \"rootDSE <filename>\" line\n",
1038 ber_str2bv( c->argv[1], 0, 1, &bv );
1039 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1045 if ( logfileName ) ch_free( logfileName );
1046 logfileName = c->value_string;
1047 logfile = fopen(logfileName, "w");
1048 if(logfile) lutil_debug_file(logfile);
1052 if(SLAP_NOLASTMODCMD(c->be)) {
1053 Debug(LDAP_DEBUG_ANY, "%s: "
1054 "lastmod not available for %s databases\n",
1055 c->log, c->be->bd_info->bi_type, 0);
1059 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1061 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1064 case CFG_SSTR_IF_MAX:
1065 if (c->value_int < index_substr_if_minlen) {
1066 Debug(LDAP_DEBUG_ANY, "%s: "
1067 "invalid max value (%d)\n",
1068 c->log, c->value_int, 0 );
1071 index_substr_if_maxlen = c->value_int;
1074 case CFG_SSTR_IF_MIN:
1075 if (c->value_int > index_substr_if_maxlen) {
1076 Debug(LDAP_DEBUG_ANY, "%s: "
1077 "invalid min value (%d)\n",
1078 c->log, c->value_int, 0 );
1081 index_substr_if_minlen = c->value_int;
1084 #ifdef SLAPD_MODULES
1086 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1088 /* Record this load on the current path */
1091 char *ptr = c->line + STRLENOF('moduleload');
1092 while (!isspace(*ptr)) ptr++;
1093 while (isspace(*ptr)) ptr++;
1094 ber_str2bv(ptr, 0, 1, &bv);
1095 ber_bvarray_add( &modcur->mp_loads, &bv );
1100 if(module_path(c->argv[1])) return(1);
1101 /* Record which path was used with each module */
1105 if (!modpaths.mp_loads) {
1108 mp = ch_malloc( sizeof( ModPaths ));
1109 modlast->mp_next = mp;
1111 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1113 mp->mp_loads = NULL;
1115 if ( c->op == SLAP_CONFIG_ADD )
1124 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
1126 slapi_plugins_used++;
1130 #ifdef SLAP_AUTH_REWRITE
1133 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
1135 ber_str2bv( c->line, 0, 1, &bv );
1136 ber_bvarray_add( &authz_rewrites, &bv );
1143 Debug(LDAP_DEBUG_ANY, "%s: unknown CFG_TYPE %d"
1144 "(ignored)\n", c->log, c->type, 0);
1152 config_fname(ConfigArgs *c) {
1153 if(c->op == SLAP_CONFIG_EMIT) {
1155 ConfigFile *cf = c->private;
1156 value_add_one( &c->rvalue_vals, &cf->c_file );
1165 config_cfdir(ConfigArgs *c) {
1166 if(c->op == SLAP_CONFIG_EMIT) {
1167 value_add_one( &c->rvalue_vals, &cfdir );
1174 config_search_base(ConfigArgs *c) {
1177 if(c->op == SLAP_CONFIG_EMIT) {
1179 if (!BER_BVISEMPTY(&default_search_base)) {
1180 value_add_one(&c->rvalue_vals, &default_search_base);
1181 value_add_one(&c->rvalue_nvals, &default_search_nbase);
1187 if(c->bi || c->be != frontendDB) {
1188 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
1189 "prior to any backend or database definition\n",
1194 if(default_search_nbase.bv_len) {
1195 Debug(LDAP_DEBUG_ANY, "%s: "
1196 "default search base \"%s\" already defined "
1197 "(discarding old)\n",
1198 c->log, default_search_base.bv_val, 0);
1199 free(default_search_base.bv_val);
1200 free(default_search_nbase.bv_val);
1203 default_search_base = c->value_dn;
1204 default_search_nbase = c->value_ndn;
1209 config_passwd_hash(ConfigArgs *c) {
1211 if (c->op == SLAP_CONFIG_EMIT) {
1213 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
1214 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
1215 value_add_one(&c->rvalue_vals, &bv);
1219 if(default_passwd_hash) {
1220 Debug(LDAP_DEBUG_ANY, "%s: "
1221 "already set default password_hash\n",
1225 for(i = 1; i < c->argc; i++) {
1226 if(!lutil_passwd_scheme(c->argv[i])) {
1227 Debug(LDAP_DEBUG_ANY, "%s: "
1228 "password scheme \"%s\" not available\n",
1229 c->log, c->argv[i], 0);
1231 ldap_charray_add(&default_passwd_hash, c->argv[i]);
1233 if(!default_passwd_hash) {
1234 Debug(LDAP_DEBUG_ANY, "%s: no valid hashes found\n",
1243 config_schema_dn(ConfigArgs *c) {
1244 if ( c->op == SLAP_CONFIG_EMIT ) {
1246 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
1247 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
1248 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
1253 c->be->be_schemadn = c->value_dn;
1254 c->be->be_schemandn = c->value_ndn;
1259 config_sizelimit(ConfigArgs *c) {
1262 struct slap_limits_set *lim = &c->be->be_def_limit;
1263 if (c->op == SLAP_CONFIG_EMIT) {
1268 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv );
1269 if ( !BER_BVISEMPTY( &bv ))
1270 value_add_one( &c->rvalue_vals, &bv );
1275 for(i = 1; i < c->argc; i++) {
1276 if(!strncasecmp(c->argv[i], "size", 4)) {
1277 rc = limits_parse_one(c->argv[i], lim);
1279 Debug(LDAP_DEBUG_ANY, "%s: "
1280 "unable to parse value \"%s\" in \"sizelimit <limit>\" line\n",
1281 c->log, c->argv[i], 0);
1285 if(!strcasecmp(c->argv[i], "unlimited")) {
1286 lim->lms_s_soft = -1;
1288 lim->lms_s_soft = strtol(c->argv[i], &next, 0);
1289 if(next == c->argv[i]) {
1290 Debug(LDAP_DEBUG_ANY, "%s: "
1291 "unable to parse limit \"%s\" in \"sizelimit <limit>\" line\n",
1292 c->log, c->argv[i], 0);
1294 } else if(next[0] != '\0') {
1295 Debug(LDAP_DEBUG_ANY, "%s: "
1296 "trailing chars \"%s\" in \"sizelimit <limit>\" line (ignored)\n",
1300 lim->lms_s_hard = 0;
1307 config_timelimit(ConfigArgs *c) {
1310 struct slap_limits_set *lim = &c->be->be_def_limit;
1311 if (c->op == SLAP_CONFIG_EMIT) {
1316 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv );
1317 if ( !BER_BVISEMPTY( &bv ))
1318 value_add_one( &c->rvalue_vals, &bv );
1323 for(i = 1; i < c->argc; i++) {
1324 if(!strncasecmp(c->argv[i], "time", 4)) {
1325 rc = limits_parse_one(c->argv[i], lim);
1327 Debug(LDAP_DEBUG_ANY, "%s: "
1328 "unable to parse value \"%s\" in \"timelimit <limit>\" line\n",
1329 c->log, c->argv[i], 0);
1333 if(!strcasecmp(c->argv[i], "unlimited")) {
1334 lim->lms_t_soft = -1;
1336 lim->lms_t_soft = strtol(c->argv[i], &next, 0);
1337 if(next == c->argv[i]) {
1338 Debug(LDAP_DEBUG_ANY, "%s: "
1339 "unable to parse limit \"%s\" in \"timelimit <limit>\" line\n",
1340 c->log, c->argv[i], 0);
1342 } else if(next[0] != '\0') {
1343 Debug(LDAP_DEBUG_ANY, "%s: "
1344 "trailing chars \"%s\" in \"timelimit <limit>\" line (ignored)\n",
1348 lim->lms_t_hard = 0;
1355 config_overlay(ConfigArgs *c) {
1356 if (c->op == SLAP_CONFIG_EMIT) {
1359 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1])) {
1361 Debug(LDAP_DEBUG_ANY, "%s: (optional) %s overlay \"%s\" configuration failed (ignored)\n",
1362 c->log, c->be == frontendDB ? "global " : "", c->argv[1][1]);
1363 } else if(overlay_config(c->be, c->argv[1])) {
1370 config_suffix(ConfigArgs *c) {
1372 struct berval pdn, ndn;
1375 if (c->be == frontendDB || SLAP_MONITOR(c->be) ||
1376 SLAP_CONFIG(c->be)) return 1;
1378 if (c->op == SLAP_CONFIG_EMIT) {
1379 if (!BER_BVISNULL( &c->be->be_suffix[0] )) {
1380 value_add( &c->rvalue_vals, c->be->be_suffix );
1381 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
1387 #ifdef SLAPD_MONITOR_DN
1388 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
1389 Debug(LDAP_DEBUG_ANY, "%s: "
1390 "\"%s\" is reserved for monitoring slapd\n",
1391 c->log, SLAPD_MONITOR_DN, 0);
1398 tbe = select_backend(&ndn, 0, 0);
1400 Debug(LDAP_DEBUG_ANY, "%s: suffix already served by this backend! (ignored)\n",
1405 Debug(LDAP_DEBUG_ANY, "%s: suffix already served by a preceding backend \"%s\"\n",
1406 c->log, tbe->be_suffix[0].bv_val, 0);
1410 } else if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
1411 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
1412 "base provided \"%s\" (assuming okay)\n",
1413 c->log, default_search_base.bv_val, 0);
1415 ber_bvarray_add(&c->be->be_suffix, &pdn);
1416 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
1421 config_rootdn(ConfigArgs *c) {
1422 if (c->op == SLAP_CONFIG_EMIT) {
1423 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
1424 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
1425 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
1431 c->be->be_rootdn = c->value_dn;
1432 c->be->be_rootndn = c->value_ndn;
1437 config_rootpw(ConfigArgs *c) {
1439 if (c->op == SLAP_CONFIG_EMIT) {
1440 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
1441 ber_dupbv( &c->value_bv, &c->be->be_rootpw);
1447 tbe = select_backend(&c->be->be_rootndn, 0, 0);
1449 Debug(LDAP_DEBUG_ANY, "%s: "
1450 "rootpw can only be set when rootdn is under suffix\n",
1454 c->be->be_rootpw = c->value_bv;
1459 config_restrict(ConfigArgs *c) {
1460 slap_mask_t restrictops = 0;
1462 slap_verbmasks restrictable_ops[] = {
1463 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
1464 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
1465 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
1466 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
1467 { BER_BVC("modrdn"), 0 },
1468 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
1469 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
1470 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
1471 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
1472 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
1473 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
1474 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
1475 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
1476 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
1477 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
1481 if (c->op == SLAP_CONFIG_EMIT) {
1482 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
1485 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
1487 Debug(LDAP_DEBUG_ANY, "%s: "
1488 "unknown operation %s in \"restrict <features>\" line\n",
1489 c->log, c->argv[i], 0);
1492 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
1493 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
1494 c->be->be_restrictops |= restrictops;
1499 config_allows(ConfigArgs *c) {
1500 slap_mask_t allows = 0;
1502 slap_verbmasks allowable_ops[] = {
1503 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
1504 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
1505 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
1506 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
1509 if (c->op == SLAP_CONFIG_EMIT) {
1510 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
1512 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
1514 Debug(LDAP_DEBUG_ANY, "%s: "
1515 "unknown feature %s in \"allow <features>\" line\n",
1516 c->log, c->argv[i], 0);
1519 global_allows |= allows;
1524 config_disallows(ConfigArgs *c) {
1525 slap_mask_t disallows = 0;
1527 slap_verbmasks disallowable_ops[] = {
1528 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
1529 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
1530 { BER_BVC("bind_krb4"), SLAP_DISALLOW_BIND_KRBV4 },
1531 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
1532 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
1535 if (c->op == SLAP_CONFIG_EMIT) {
1536 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
1538 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
1540 Debug(LDAP_DEBUG_ANY, "%s: "
1541 "unknown feature %s in \"disallow <features>\" line\n",
1542 c->log, c->argv[i], 0);
1545 global_disallows |= disallows;
1550 config_requires(ConfigArgs *c) {
1551 slap_mask_t requires = 0;
1553 slap_verbmasks requires_ops[] = {
1554 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
1555 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
1556 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
1557 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
1558 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
1561 if (c->op == SLAP_CONFIG_EMIT) {
1562 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
1564 i = verbs_to_mask(c->argc, c->argv, requires_ops, &requires);
1566 Debug(LDAP_DEBUG_ANY, "%s: "
1567 "unknown feature %s in \"require <features>\" line\n",
1568 c->log, c->argv[i], 0);
1571 c->be->be_requires = requires;
1576 config_loglevel(ConfigArgs *c) {
1579 slap_verbmasks loglevel_ops[] = {
1580 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
1581 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
1582 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
1583 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
1584 { BER_BVC("BER"), LDAP_DEBUG_BER },
1585 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
1586 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
1587 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
1588 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
1589 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
1590 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
1591 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
1592 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
1593 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
1594 { BER_BVC("Any"), -1 },
1598 if (c->op == SLAP_CONFIG_EMIT) {
1599 return mask_to_verbs( loglevel_ops, ldap_syslog, &c->rvalue_vals );
1604 for( i=1; i < c->argc; i++ ) {
1607 if ( isdigit( c->argv[i][0] ) ) {
1608 level = strtol( c->argv[i], &next, 10 );
1609 if ( next == NULL || next[0] != '\0' ) {
1610 Debug( LDAP_DEBUG_ANY,
1611 "%s: unable to parse level \"%s\" "
1612 "in \"loglevel <level> [...]\" line.\n",
1613 c->log, c->argv[i], 0);
1617 int j = verb_to_mask(c->argv[i], loglevel_ops);
1618 if(BER_BVISNULL(&loglevel_ops[j].word)) {
1619 Debug( LDAP_DEBUG_ANY,
1620 "%s: unknown level \"%s\" "
1621 "in \"loglevel <level> [...]\" line.\n",
1622 c->log, c->argv[i], 0);
1625 level = loglevel_ops[j].mask;
1627 ldap_syslog |= level;
1633 config_syncrepl(ConfigArgs *c) {
1634 if (c->op == SLAP_CONFIG_EMIT) {
1635 if ( c->be->be_syncinfo ) {
1637 syncrepl_unparse( c->be->be_syncinfo, &bv );
1638 ber_bvarray_add( &c->rvalue_vals, &bv );
1643 if(SLAP_SHADOW(c->be)) {
1644 Debug(LDAP_DEBUG_ANY, "%s: "
1645 "syncrepl: database already shadowed.\n",
1648 } else if(add_syncrepl(c->be, c->argv, c->argc)) {
1651 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SYNC_SHADOW);
1656 config_referral(ConfigArgs *c) {
1657 struct berval vals[2];
1658 if (c->op == SLAP_CONFIG_EMIT) {
1659 if ( default_referral ) {
1660 value_add( &c->rvalue_vals, default_referral );
1666 if(validate_global_referral(c->argv[1])) {
1667 Debug(LDAP_DEBUG_ANY, "%s: "
1668 "invalid URL (%s) in \"referral\" line.\n",
1669 c->log, c->argv[1], 0);
1673 ber_str2bv(c->argv[1], 0, 0, &vals[0]);
1674 vals[1].bv_val = NULL; vals[1].bv_len = 0;
1675 if(value_add(&default_referral, vals)) return(LDAP_OTHER);
1683 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
1684 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
1685 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
1686 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
1687 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
1688 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
1689 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
1690 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
1691 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
1696 config_security(ConfigArgs *c) {
1697 slap_ssf_set_t *set = &c->be->be_ssf_set;
1700 if (c->op == SLAP_CONFIG_EMIT) {
1706 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
1707 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
1710 bv.bv_len = sprintf( numbuf, "%u", *tgt );
1711 bv.bv_len += sec_keys[i].key.bv_len;
1712 bv.bv_val = ch_malloc( bv.bv_len + 1);
1713 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
1714 strcpy( next, numbuf );
1715 ber_bvarray_add( &c->rvalue_vals, &bv );
1720 for(i = 1; i < c->argc; i++) {
1721 slap_ssf_t *tgt = NULL;
1723 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
1724 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
1725 sec_keys[j].key.bv_len)) {
1726 src = c->argv[i] + sec_keys[j].key.bv_len;
1727 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
1732 Debug(LDAP_DEBUG_ANY, "%s: "
1733 "unknown factor %s in \"security <factors>\" line\n",
1734 c->log, c->argv[i], 0);
1738 *tgt = strtol(src, &next, 10);
1739 if(next == NULL || next[0] != '\0' ) {
1740 Debug(LDAP_DEBUG_ANY, "%s: "
1741 "unable to parse factor \"%s\" in \"security <factors>\" line\n",
1742 c->log, c->argv[i], 0);
1750 anlist_unparse( AttributeName *an, char *ptr ) {
1753 for (; !BER_BVISNULL( &an->an_name ); an++) {
1754 if ( comma ) *ptr++ = ',';
1755 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
1762 replica_unparse( struct slap_replica_info *ri, int i, struct berval *bv )
1766 struct berval bc = {0};
1769 len = sprintf(numbuf, "{%d}", i );
1771 len += strlen( ri->ri_uri ) + STRLENOF("uri=");
1772 if ( ri->ri_nsuffix ) {
1773 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
1774 len += ri->ri_nsuffix[i].bv_len + STRLENOF(" suffix=\"\"");
1777 if ( ri->ri_attrs ) {
1778 len += STRLENOF("attr");
1779 if ( ri->ri_exclude ) len++;
1780 for (i=0; !BER_BVISNULL( &ri->ri_attrs[i].an_name ); i++) {
1781 len += 1 + ri->ri_attrs[i].an_name.bv_len;
1784 bindconf_unparse( &ri->ri_bindconf, &bc );
1787 bv->bv_val = ch_malloc(len + 1);
1790 ptr = lutil_strcopy( bv->bv_val, numbuf );
1791 ptr = lutil_strcopy( ptr, "uri=" );
1792 ptr = lutil_strcopy( ptr, ri->ri_uri );
1794 if ( ri->ri_nsuffix ) {
1795 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
1796 ptr = lutil_strcopy( ptr, " suffix=\"" );
1797 ptr = lutil_strcopy( ptr, ri->ri_nsuffix[i].bv_val );
1801 if ( ri->ri_attrs ) {
1802 ptr = lutil_strcopy( ptr, "attr" );
1803 if ( ri->ri_exclude ) *ptr++ = '!';
1805 ptr = anlist_unparse( ri->ri_attrs, ptr );
1808 strcpy( ptr, bc.bv_val );
1809 ch_free( bc.bv_val );
1814 config_replica(ConfigArgs *c) {
1815 int i, nr = -1, len;
1816 char *replicahost, *replicauri;
1819 if (c->op == SLAP_CONFIG_EMIT) {
1820 if (c->be->be_replica) {
1822 for (i=0;c->be->be_replica[i]; i++) {
1823 replica_unparse( c->be->be_replica[i], i, &bv );
1824 ber_bvarray_add( &c->rvalue_vals, &bv );
1830 if(SLAP_MONITOR(c->be)) {
1831 Debug(LDAP_DEBUG_ANY, "%s: "
1832 "\"replica\" should not be used inside monitor database\n",
1834 return(0); /* FIXME: should this be an error? */
1837 for(i = 1; i < c->argc; i++) {
1838 if(!strncasecmp(c->argv[i], "host=", STRLENOF("host="))) {
1839 replicahost = c->argv[i] + STRLENOF("host=");
1840 len = strlen( replicahost );
1841 replicauri = ch_malloc( len + STRLENOF("ldap://") + 1 );
1842 sprintf( replicauri, "ldap://%s", replicahost );
1843 replicahost = replicauri + STRLENOF( "ldap://");
1844 nr = add_replica_info(c->be, replicauri, replicahost);
1846 } else if(!strncasecmp(c->argv[i], "uri=", STRLENOF("uri="))) {
1847 if(ldap_url_parse(c->argv[i] + STRLENOF("uri="), &ludp) != LDAP_SUCCESS) {
1848 Debug(LDAP_DEBUG_ANY, "%s: "
1849 "replica line contains invalid "
1850 "uri definition.\n", c->log, 0, 0);
1853 if(!ludp->lud_host) {
1854 Debug(LDAP_DEBUG_ANY, "%s: "
1855 "replica line contains invalid "
1856 "uri definition - missing hostname.\n",
1860 ldap_free_urldesc(ludp);
1861 replicauri = c->argv[i] + STRLENOF("uri=");
1862 replicauri = ch_strdup( replicauri );
1863 replicahost = strchr( replicauri, '/' );
1865 nr = add_replica_info(c->be, replicauri, replicahost);
1870 Debug(LDAP_DEBUG_ANY, "%s: "
1871 "missing host or uri in \"replica\" line\n",
1874 } else if(nr == -1) {
1875 Debug(LDAP_DEBUG_ANY, "%s: "
1876 "unable to add replica \"%s\"\n",
1877 c->log, replicauri, 0);
1880 for(i = 1; i < c->argc; i++) {
1881 if(!strncasecmp(c->argv[i], "suffix=", STRLENOF( "suffix="))) {
1882 switch(add_replica_suffix(c->be, nr, c->argv[i] + STRLENOF("suffix="))) {
1884 Debug(LDAP_DEBUG_ANY, "%s: "
1885 "suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
1886 c->log, c->argv[i] + STRLENOF("suffix="), 0);
1889 Debug(LDAP_DEBUG_ANY, "%s: "
1890 "unable to normalize suffix in \"replica\" line (ignored)\n",
1895 } else if(!strncasecmp(c->argv[i], "attr", STRLENOF("attr"))) {
1897 char *arg = c->argv[i] + STRLENOF("attr");
1905 if(add_replica_attrs(c->be, nr, arg + 1, exclude)) {
1906 Debug(LDAP_DEBUG_ANY, "%s: "
1907 "attribute \"%s\" in \"replica\" line is unknown\n",
1908 c->log, arg + 1, 0);
1911 } else if ( bindconf_parse( c->argv[i],
1912 &c->be->be_replica[nr]->ri_bindconf ) ) {
1921 config_updatedn(ConfigArgs *c) {
1924 if (c->op == SLAP_CONFIG_EMIT) {
1925 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
1926 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
1927 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
1932 if(SLAP_SHADOW(c->be)) {
1933 Debug(LDAP_DEBUG_ANY, "%s: "
1934 "updatedn: database already shadowed.\n",
1939 ber_str2bv(c->argv[1], 0, 0, &dn);
1941 rc = dnNormalize(0, NULL, NULL, &dn, &c->be->be_update_ndn, NULL);
1943 if(rc != LDAP_SUCCESS) {
1944 Debug(LDAP_DEBUG_ANY, "%s: "
1945 "updatedn DN is invalid: %d (%s)\n",
1946 c->log, rc, ldap_err2string( rc ));
1950 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
1955 config_updateref(ConfigArgs *c) {
1956 struct berval vals[2];
1957 if (c->op == SLAP_CONFIG_EMIT) {
1958 if ( c->be->be_update_refs ) {
1959 value_add( &c->rvalue_vals, c->be->be_update_refs );
1965 if(!SLAP_SHADOW(c->be)) {
1966 Debug(LDAP_DEBUG_ANY, "%s: "
1967 "updateref line must come after syncrepl or updatedn.\n",
1972 if(validate_global_referral(c->argv[1])) {
1973 Debug(LDAP_DEBUG_ANY, "%s: "
1974 "invalid URL (%s) in \"updateref\" line.\n",
1975 c->log, c->argv[1], 0);
1978 ber_str2bv(c->argv[1], 0, 0, &vals[0]);
1979 vals[1].bv_val = NULL;
1980 if(value_add(&c->be->be_update_refs, vals)) return(LDAP_OTHER);
1985 config_include(ConfigArgs *c) {
1986 unsigned long savelineno = c->lineno;
1989 ConfigFile *cfsave = cfn;
1990 ConfigFile *cf2 = NULL;
1991 if (c->op == SLAP_CONFIG_EMIT) {
1994 cf = ch_calloc( 1, sizeof(ConfigFile));
1995 if ( cfn->c_kids ) {
1996 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
2002 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
2003 rc = read_config_file(c->argv[1], c->depth + 1, c);
2004 c->lineno = savelineno - 1;
2007 if ( cf2 ) cf2->c_sibs = NULL;
2008 else cfn->c_kids = NULL;
2009 ch_free( cf->c_file.bv_val );
2017 config_tls_option(ConfigArgs *c) {
2020 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; break;
2021 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
2022 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
2023 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
2024 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
2025 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
2026 default: Debug(LDAP_DEBUG_ANY, "%s: "
2027 "unknown tls_option <%x>\n",
2028 c->log, c->type, 0);
2030 if (c->op == SLAP_CONFIG_EMIT) {
2031 return ldap_pvt_tls_get_option( NULL, flag, &c->value_string );
2033 ch_free(c->value_string);
2034 return(ldap_pvt_tls_set_option(NULL, flag, c->argv[1]));
2037 /* FIXME: this ought to be provided by libldap */
2039 config_tls_config(ConfigArgs *c) {
2041 slap_verbmasks crlkeys[] = {
2042 { BER_BVC("none"), LDAP_OPT_X_TLS_CRL_NONE },
2043 { BER_BVC("peer"), LDAP_OPT_X_TLS_CRL_PEER },
2044 { BER_BVC("all"), LDAP_OPT_X_TLS_CRL_ALL },
2047 slap_verbmasks vfykeys[] = {
2048 { BER_BVC("never"), LDAP_OPT_X_TLS_NEVER },
2049 { BER_BVC("demand"), LDAP_OPT_X_TLS_DEMAND },
2050 { BER_BVC("try"), LDAP_OPT_X_TLS_TRY },
2051 { BER_BVC("hard"), LDAP_OPT_X_TLS_HARD },
2055 #ifdef HAVE_OPENSSL_CRL
2056 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; keys = crlkeys;
2059 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; keys = vfykeys;
2061 default: Debug(LDAP_DEBUG_ANY, "%s: "
2062 "unknown tls_option <%x>\n",
2063 c->log, c->type, 0);
2065 if (c->op == SLAP_CONFIG_EMIT) {
2066 ldap_pvt_tls_get_option( NULL, flag, &c->value_int );
2067 for (i=0; !BER_BVISNULL(&keys[i].word); i++) {
2068 if (keys[i].mask == c->value_int) {
2069 c->value_string = ch_strdup( keys[i].word.bv_val );
2075 ch_free( c->value_string );
2076 if(isdigit((unsigned char)c->argv[1][0])) {
2077 i = atoi(c->argv[1]);
2078 return(ldap_pvt_tls_set_option(NULL, flag, &i));
2080 return(ldap_int_tls_config(NULL, flag, c->argv[1]));
2095 si = (syncinfo_t *) ch_calloc( 1, sizeof( syncinfo_t ) );
2098 Debug( LDAP_DEBUG_ANY, "out of memory in add_syncrepl\n", 0, 0, 0 );
2102 si->si_bindconf.sb_tls = SB_TLS_OFF;
2103 si->si_bindconf.sb_method = LDAP_AUTH_SIMPLE;
2104 si->si_schemachecking = 0;
2105 ber_str2bv( "(objectclass=*)", STRLENOF("(objectclass=*)"), 1,
2106 &si->si_filterstr );
2107 si->si_base.bv_val = NULL;
2108 si->si_scope = LDAP_SCOPE_SUBTREE;
2109 si->si_attrsonly = 0;
2110 si->si_anlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ));
2111 si->si_exanlist = (AttributeName *) ch_calloc( 1, sizeof( AttributeName ));
2112 si->si_attrs = NULL;
2113 si->si_allattrs = 0;
2114 si->si_allopattrs = 0;
2115 si->si_exattrs = NULL;
2116 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2117 si->si_interval = 86400;
2118 si->si_retryinterval = NULL;
2119 si->si_retrynum_init = NULL;
2120 si->si_retrynum = NULL;
2121 si->si_manageDSAit = 0;
2125 si->si_presentlist = NULL;
2126 LDAP_LIST_INIT( &si->si_nonpresentlist );
2127 ldap_pvt_thread_mutex_init( &si->si_mutex );
2129 rc = parse_syncrepl_line( cargv, cargc, si );
2132 Debug( LDAP_DEBUG_ANY, "failed to add syncinfo\n", 0, 0, 0 );
2133 syncinfo_free( si );
2136 Debug( LDAP_DEBUG_CONFIG,
2137 "Config: ** successfully added syncrepl \"%s\"\n",
2138 BER_BVISNULL( &si->si_provideruri ) ?
2139 "(null)" : si->si_provideruri.bv_val, 0, 0 );
2140 if ( !si->si_schemachecking ) {
2141 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NO_SCHEMA_CHECK;
2144 be->be_syncinfo = si;
2149 /* NOTE: used & documented in slapd.conf(5) */
2151 #define PROVIDERSTR "provider"
2152 #define TYPESTR "type"
2153 #define INTERVALSTR "interval"
2154 #define SEARCHBASESTR "searchbase"
2155 #define FILTERSTR "filter"
2156 #define SCOPESTR "scope"
2157 #define ATTRSSTR "attrs"
2158 #define ATTRSONLYSTR "attrsonly"
2159 #define SLIMITSTR "sizelimit"
2160 #define TLIMITSTR "timelimit"
2161 #define SCHEMASTR "schemachecking"
2163 /* FIXME: undocumented */
2164 #define OLDAUTHCSTR "bindprincipal"
2165 #define EXATTRSSTR "exattrs"
2166 #define RETRYSTR "retry"
2169 #define LASTMODSTR "lastmod"
2170 #define LMGENSTR "gen"
2171 #define LMNOSTR "no"
2172 #define LMREQSTR "req"
2173 #define SRVTABSTR "srvtab"
2174 #define SUFFIXSTR "suffix"
2175 #define MANAGEDSAITSTR "manageDSAit"
2178 #define GOT_ID 0x0001
2179 #define GOT_PROVIDER 0x0002
2182 #define GOT_ALL (GOT_ID|GOT_PROVIDER)
2188 { BER_BVC("base"), LDAP_SCOPE_BASE },
2189 { BER_BVC("one"), LDAP_SCOPE_ONELEVEL },
2190 #ifdef LDAP_SCOPE_SUBORDINATE
2191 { BER_BVC("children"), LDAP_SCOPE_SUBORDINATE },
2192 { BER_BVC("subordinate"), 0 },
2194 { BER_BVC("sub"), LDAP_SCOPE_SUBTREE },
2199 parse_syncrepl_line(
2209 for ( i = 1; i < cargc; i++ ) {
2210 if ( !strncasecmp( cargv[ i ], IDSTR "=",
2211 STRLENOF( IDSTR "=" ) ) )
2214 /* '\0' string terminator accounts for '=' */
2215 val = cargv[ i ] + STRLENOF( IDSTR "=" );
2217 if ( tmp >= 1000 || tmp < 0 ) {
2218 fprintf( stderr, "Error: parse_syncrepl_line: "
2219 "syncrepl id %d is out of range [0..999]\n", tmp );
2224 } else if ( !strncasecmp( cargv[ i ], PROVIDERSTR "=",
2225 STRLENOF( PROVIDERSTR "=" ) ) )
2227 val = cargv[ i ] + STRLENOF( PROVIDERSTR "=" );
2228 ber_str2bv( val, 0, 1, &si->si_provideruri );
2229 gots |= GOT_PROVIDER;
2230 } else if ( !strncasecmp( cargv[ i ], SCHEMASTR "=",
2231 STRLENOF( SCHEMASTR "=" ) ) )
2233 val = cargv[ i ] + STRLENOF( SCHEMASTR "=" );
2234 if ( !strncasecmp( val, "on", STRLENOF( "on" ) )) {
2235 si->si_schemachecking = 1;
2236 } else if ( !strncasecmp( val, "off", STRLENOF( "off" ) ) ) {
2237 si->si_schemachecking = 0;
2239 si->si_schemachecking = 1;
2241 } else if ( !strncasecmp( cargv[ i ], FILTERSTR "=",
2242 STRLENOF( FILTERSTR "=" ) ) )
2244 val = cargv[ i ] + STRLENOF( FILTERSTR "=" );
2245 ber_str2bv( val, 0, 1, &si->si_filterstr );
2246 } else if ( !strncasecmp( cargv[ i ], SEARCHBASESTR "=",
2247 STRLENOF( SEARCHBASESTR "=" ) ) )
2252 val = cargv[ i ] + STRLENOF( SEARCHBASESTR "=" );
2253 if ( si->si_base.bv_val ) {
2254 ch_free( si->si_base.bv_val );
2256 ber_str2bv( val, 0, 0, &bv );
2257 rc = dnNormalize( 0, NULL, NULL, &bv, &si->si_base, NULL );
2258 if ( rc != LDAP_SUCCESS ) {
2259 fprintf( stderr, "Invalid base DN \"%s\": %d (%s)\n",
2260 val, rc, ldap_err2string( rc ) );
2263 } else if ( !strncasecmp( cargv[ i ], SCOPESTR "=",
2264 STRLENOF( SCOPESTR "=" ) ) )
2267 val = cargv[ i ] + STRLENOF( SCOPESTR "=" );
2268 for ( j=0; !BER_BVISNULL(&scopes[j].key); j++ ) {
2269 if (!strncasecmp( val, scopes[j].key.bv_val,
2270 scopes[j].key.bv_len )) {
2271 while (!scopes[j].val) j--;
2272 si->si_scope = scopes[j].val;
2276 if ( BER_BVISNULL(&scopes[j].key) ) {
2277 fprintf( stderr, "Error: parse_syncrepl_line: "
2278 "unknown scope \"%s\"\n", val);
2281 } else if ( !strncasecmp( cargv[ i ], ATTRSONLYSTR "=",
2282 STRLENOF( ATTRSONLYSTR "=" ) ) )
2284 si->si_attrsonly = 1;
2285 } else if ( !strncasecmp( cargv[ i ], ATTRSSTR "=",
2286 STRLENOF( ATTRSSTR "=" ) ) )
2288 val = cargv[ i ] + STRLENOF( ATTRSSTR "=" );
2289 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") ) ) {
2291 attr_fname = ch_strdup( val + STRLENOF(":include:") );
2292 si->si_anlist = file2anlist( si->si_anlist, attr_fname, " ,\t" );
2293 if ( si->si_anlist == NULL ) {
2294 ch_free( attr_fname );
2297 si->si_anfile = attr_fname;
2299 char *str, *s, *next;
2300 char delimstr[] = " ,\t";
2301 str = ch_strdup( val );
2302 for ( s = ldap_pvt_strtok( str, delimstr, &next );
2304 s = ldap_pvt_strtok( NULL, delimstr, &next ) )
2306 if ( strlen(s) == 1 && *s == '*' ) {
2307 si->si_allattrs = 1;
2308 *(val + ( s - str )) = delimstr[0];
2310 if ( strlen(s) == 1 && *s == '+' ) {
2311 si->si_allopattrs = 1;
2312 *(val + ( s - str )) = delimstr[0];
2316 si->si_anlist = str2anlist( si->si_anlist, val, " ,\t" );
2317 if ( si->si_anlist == NULL ) {
2321 } else if ( !strncasecmp( cargv[ i ], EXATTRSSTR "=",
2322 STRLENOF( EXATTRSSTR "=" ) ) )
2324 val = cargv[ i ] + STRLENOF( EXATTRSSTR "=" );
2325 if ( !strncasecmp( val, ":include:", STRLENOF(":include:") )) {
2327 attr_fname = ch_strdup( val + STRLENOF(":include:") );
2328 si->si_exanlist = file2anlist(
2329 si->si_exanlist, attr_fname, " ,\t" );
2330 if ( si->si_exanlist == NULL ) {
2331 ch_free( attr_fname );
2334 ch_free( attr_fname );
2336 si->si_exanlist = str2anlist( si->si_exanlist, val, " ,\t" );
2337 if ( si->si_exanlist == NULL ) {
2341 } else if ( !strncasecmp( cargv[ i ], TYPESTR "=",
2342 STRLENOF( TYPESTR "=" ) ) )
2344 val = cargv[ i ] + STRLENOF( TYPESTR "=" );
2345 if ( !strncasecmp( val, "refreshOnly",
2346 STRLENOF("refreshOnly") ))
2348 si->si_type = LDAP_SYNC_REFRESH_ONLY;
2349 } else if ( !strncasecmp( val, "refreshAndPersist",
2350 STRLENOF("refreshAndPersist") ))
2352 si->si_type = LDAP_SYNC_REFRESH_AND_PERSIST;
2353 si->si_interval = 60;
2355 fprintf( stderr, "Error: parse_syncrepl_line: "
2356 "unknown sync type \"%s\"\n", val);
2359 } else if ( !strncasecmp( cargv[ i ], INTERVALSTR "=",
2360 STRLENOF( INTERVALSTR "=" ) ) )
2362 val = cargv[ i ] + STRLENOF( INTERVALSTR "=" );
2363 if ( si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ) {
2364 si->si_interval = 0;
2372 hstr = strchr( dstr, ':' );
2373 if ( hstr == NULL ) {
2374 fprintf( stderr, "Error: parse_syncrepl_line: "
2375 "invalid interval \"%s\"\n", val );
2379 mstr = strchr( hstr, ':' );
2380 if ( mstr == NULL ) {
2381 fprintf( stderr, "Error: parse_syncrepl_line: "
2382 "invalid interval \"%s\"\n", val );
2386 sstr = strchr( mstr, ':' );
2387 if ( sstr == NULL ) {
2388 fprintf( stderr, "Error: parse_syncrepl_line: "
2389 "invalid interval \"%s\"\n", val );
2398 if (( hh > 24 ) || ( hh < 0 ) ||
2399 ( mm > 60 ) || ( mm < 0 ) ||
2400 ( ss > 60 ) || ( ss < 0 ) || ( dd < 0 )) {
2401 fprintf( stderr, "Error: parse_syncrepl_line: "
2402 "invalid interval \"%s\"\n", val );
2405 si->si_interval = (( dd * 24 + hh ) * 60 + mm ) * 60 + ss;
2407 if ( si->si_interval < 0 ) {
2408 fprintf( stderr, "Error: parse_syncrepl_line: "
2409 "invalid interval \"%ld\"\n",
2410 (long) si->si_interval);
2413 } else if ( !strncasecmp( cargv[ i ], RETRYSTR "=",
2414 STRLENOF( RETRYSTR "=" ) ) )
2419 val = cargv[ i ] + STRLENOF( RETRYSTR "=" );
2420 retry_list = (char **) ch_calloc( 1, sizeof( char * ));
2421 retry_list[0] = NULL;
2423 slap_str2clist( &retry_list, val, " ,\t" );
2425 for ( k = 0; retry_list && retry_list[k]; k++ ) ;
2429 "Error: incomplete syncrepl retry list\n" );
2430 for ( k = 0; retry_list && retry_list[k]; k++ ) {
2431 ch_free( retry_list[k] );
2433 ch_free( retry_list );
2434 exit( EXIT_FAILURE );
2436 si->si_retryinterval = (time_t *) ch_calloc( n + 1, sizeof( time_t ));
2437 si->si_retrynum = (int *) ch_calloc( n + 1, sizeof( int ));
2438 si->si_retrynum_init = (int *) ch_calloc( n + 1, sizeof( int ));
2439 for ( j = 0; j < n; j++ ) {
2440 si->si_retryinterval[j] = atoi( retry_list[j*2] );
2441 if ( *retry_list[j*2+1] == '+' ) {
2442 si->si_retrynum_init[j] = -1;
2443 si->si_retrynum[j] = -1;
2447 si->si_retrynum_init[j] = atoi( retry_list[j*2+1] );
2448 si->si_retrynum[j] = atoi( retry_list[j*2+1] );
2451 si->si_retrynum_init[j] = -2;
2452 si->si_retrynum[j] = -2;
2453 si->si_retryinterval[j] = 0;
2455 for ( k = 0; retry_list && retry_list[k]; k++ ) {
2456 ch_free( retry_list[k] );
2458 ch_free( retry_list );
2459 } else if ( !strncasecmp( cargv[ i ], MANAGEDSAITSTR "=",
2460 STRLENOF( MANAGEDSAITSTR "=" ) ) )
2462 val = cargv[ i ] + STRLENOF( MANAGEDSAITSTR "=" );
2463 si->si_manageDSAit = atoi( val );
2464 } else if ( !strncasecmp( cargv[ i ], SLIMITSTR "=",
2465 STRLENOF( SLIMITSTR "=") ) )
2467 val = cargv[ i ] + STRLENOF( SLIMITSTR "=" );
2468 si->si_slimit = atoi( val );
2469 } else if ( !strncasecmp( cargv[ i ], TLIMITSTR "=",
2470 STRLENOF( TLIMITSTR "=" ) ) )
2472 val = cargv[ i ] + STRLENOF( TLIMITSTR "=" );
2473 si->si_tlimit = atoi( val );
2474 } else if ( bindconf_parse( cargv[i], &si->si_bindconf )) {
2475 fprintf( stderr, "Error: parse_syncrepl_line: "
2476 "unknown keyword \"%s\"\n", cargv[ i ] );
2481 if ( gots != GOT_ALL ) {
2483 "Error: Malformed \"syncrepl\" line in slapd config file" );
2491 syncrepl_unparse( syncinfo_t *si, struct berval *bv )
2494 char buf[BUFSIZ*2], *ptr;
2497 bindconf_unparse( &si->si_bindconf, &bc );
2499 ptr += sprintf( ptr, IDSTR "=%03d " PROVIDERSTR "=%s",
2500 si->si_rid, si->si_provideruri.bv_val );
2501 if ( !BER_BVISNULL( &bc )) {
2502 ptr = lutil_strcopy( ptr, bc.bv_val );
2505 if ( !BER_BVISEMPTY( &si->si_filterstr )) {
2506 ptr = lutil_strcopy( ptr, " " FILTERSTR "=\"" );
2507 ptr = lutil_strcopy( ptr, si->si_filterstr.bv_val );
2510 if ( !BER_BVISNULL( &si->si_base )) {
2511 ptr = lutil_strcopy( ptr, " " SEARCHBASESTR "=\"" );
2512 ptr = lutil_strcopy( ptr, si->si_base.bv_val );
2515 for (i=0; !BER_BVISNULL(&scopes[i].key);i++) {
2516 if ( si->si_scope == scopes[i].val ) {
2517 ptr = lutil_strcopy( ptr, " " SCOPESTR "=" );
2518 ptr = lutil_strcopy( ptr, scopes[i].key.bv_val );
2522 if ( si->si_attrsonly ) {
2523 ptr = lutil_strcopy( ptr, " " ATTRSONLYSTR "=yes" );
2525 if ( si->si_anfile ) {
2526 ptr = lutil_strcopy( ptr, " " ATTRSSTR "=:include:" );
2527 ptr = lutil_strcopy( ptr, si->si_anfile );
2528 } else if ( si->si_allattrs || si->si_allopattrs ||
2529 ( si->si_anlist && !BER_BVISNULL(&si->si_anlist[0].an_name) )) {
2531 ptr = lutil_strcopy( ptr, " " ATTRSSTR "=\"" );
2533 ptr = anlist_unparse( si->si_anlist, ptr );
2534 if ( si->si_allattrs ) {
2535 if ( old != ptr ) *ptr++ = ',';
2538 if ( si->si_allopattrs ) {
2539 if ( old != ptr ) *ptr++ = ',';
2544 if ( si->si_exanlist && !BER_BVISNULL(&si->si_exanlist[0].an_name) ) {
2545 ptr = lutil_strcopy( ptr, " " EXATTRSSTR "=" );
2546 ptr = anlist_unparse( si->si_exanlist, ptr );
2548 ptr = lutil_strcopy( ptr, " " SCHEMASTR "=" );
2549 ptr = lutil_strcopy( ptr, si->si_schemachecking ? "on" : "off" );
2551 ptr = lutil_strcopy( ptr, " " TYPESTR "=" );
2552 ptr = lutil_strcopy( ptr, si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ?
2553 "refreshAndPersist" : "refreshOnly" );
2555 if ( si->si_type == LDAP_SYNC_REFRESH_ONLY ) {
2558 dd = si->si_interval;
2565 ptr = lutil_strcopy( ptr, " " INTERVALSTR "=" );
2566 ptr += sprintf( ptr, "%02d:%02d:%02d:%02d", dd, hh, mm, ss );
2567 } else if ( si->si_retryinterval ) {
2569 ptr = lutil_strcopy( ptr, " " RETRYSTR "=\"" );
2570 for (i=0; si->si_retryinterval[i]; i++) {
2571 if ( space ) *ptr++ = ' ';
2573 ptr += sprintf( ptr, "%d", si->si_retryinterval[i] );
2574 if ( si->si_retrynum_init[i] == -1 )
2577 ptr += sprintf( ptr, "%d", si->si_retrynum_init );
2582 #if 0 /* FIXME: unused in syncrepl.c, should remove it */
2583 ptr = lutil_strcopy( ptr, " " MANAGEDSAITSTR "=" );
2584 ptr += sprintf( ptr, "%d", si->si_manageDSAit );
2587 if ( si->si_slimit ) {
2588 ptr = lutil_strcopy( ptr, " " SLIMITSTR "=" );
2589 ptr += sprintf( ptr, "%d", si->si_slimit );
2592 if ( si->si_tlimit ) {
2593 ptr = lutil_strcopy( ptr, " " TLIMITSTR "=" );
2594 ptr += sprintf( ptr, "%d", si->si_tlimit );
2596 bc.bv_len = ptr - buf;
2598 ber_dupbv( bv, &bc );
2601 static CfEntryInfo *
2602 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
2612 if ( dn_match( &root->ce_entry->e_nname, dn ))
2615 c = dn->bv_val+dn->bv_len;
2616 for (;*c != ',';c--);
2620 for (--c;c>dn->bv_val && *c != ',';c--);
2624 cdn.bv_len = dn->bv_len - (c-dn->bv_val);
2626 root = root->ce_kids;
2628 for (;root;root=root->ce_sibs) {
2629 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
2630 if ( cdn.bv_val == dn->bv_val ) {
2641 config_ldif_resp( Operation *op, SlapReply *rs )
2643 if ( rs->sr_type == REP_SEARCH ) {
2644 CfBackInfo *cfb = op->o_callback->sc_private;
2646 cfb->cb_got_ldif = 1;
2647 rs->sr_err = config_add_internal( cfb, rs->sr_entry, NULL );
2652 /* Configure and read the underlying back-ldif store */
2654 config_setup_ldif( BackendDB *be, const char *dir ) {
2655 CfBackInfo *cfb = be->be_private;
2660 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
2661 Connection conn = {0};
2662 char opbuf[OPERATION_BUFFER_SIZE];
2664 SlapReply rs = {REP_RESULT};
2665 Filter filter = { LDAP_FILTER_PRESENT };
2666 struct berval filterstr = BER_BVC("(objectclass=*)");
2668 cfb->cb_db.bd_info = backend_info( "ldif" );
2669 if ( !cfb->cb_db.bd_info )
2670 return 0; /* FIXME: eventually this will be a fatal error */
2672 if ( cfb->cb_db.bd_info->bi_db_init( &cfb->cb_db )) return 1;
2674 /* Mark that back-ldif type is in use */
2675 cfb->cb_db.bd_info->bi_nDB++;
2677 cfb->cb_db.be_suffix = be->be_suffix;
2678 cfb->cb_db.be_nsuffix = be->be_nsuffix;
2679 cfb->cb_db.be_rootdn = be->be_rootdn;
2680 cfb->cb_db.be_rootndn = be->be_rootndn;
2682 ber_str2bv( dir, 0, 1, &cfdir );
2687 argv[0] = "directory";
2688 argv[1] = (char *)dir;
2692 ct = config_find_keyword( c.be->be_cf_table, &c );
2696 if ( config_add_vals( ct, &c ))
2699 if ( backend_startup_one( &cfb->cb_db ))
2702 op = (Operation *)opbuf;
2703 connection_fake_init( &conn, op, cfb );
2705 filter.f_desc = slap_schema.si_ad_objectClass;
2707 op->o_tag = LDAP_REQ_SEARCH;
2709 op->ors_filter = &filter;
2710 op->ors_filterstr = filterstr;
2711 op->ors_scope = LDAP_SCOPE_SUBTREE;
2713 op->o_dn = be->be_rootdn;
2714 op->o_ndn = be->be_rootndn;
2716 op->o_req_dn = be->be_suffix[0];
2717 op->o_req_ndn = be->be_nsuffix[0];
2719 op->ors_tlimit = SLAP_NO_LIMIT;
2720 op->ors_slimit = SLAP_NO_LIMIT;
2722 op->ors_attrs = slap_anlist_all_attributes;
2723 op->ors_attrsonly = 0;
2725 op->o_callback = &cb;
2726 cb.sc_private = cfb;
2728 op->o_bd = &cfb->cb_db;
2729 op->o_bd->be_search( op, &rs );
2735 CfOcInfo_cmp( const void *c1, const void *c2 ) {
2736 const CfOcInfo *co1 = c1;
2737 const CfOcInfo *co2 = c2;
2739 return ber_bvcmp( co1->co_name, co2->co_name );
2743 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
2747 i = init_config_attrs( ct );
2750 /* set up the objectclasses */
2751 i = init_config_ocs( ocs );
2754 for (i=0; ocs[i].def; i++) {
2756 co = ch_malloc( sizeof(CfOcInfo) );
2757 co->co_name = &(*ocs[i].oc)->soc_cname;
2759 co->co_type = ocs[i].cft;
2760 avl_insert( &CfOcTree, co, CfOcInfo_cmp, avl_dup_error );
2767 read_config(const char *fname, const char *dir) {
2771 /* Setup the config backend */
2772 be = backend_db_init( "config" );
2776 cfb = be->be_private;
2778 /* Setup the underlying back-ldif backend */
2779 if ( config_setup_ldif( be, dir ))
2782 #ifdef SLAP_USE_CONFDIR
2783 /* If we read the config from back-ldif, nothing to do here */
2784 if ( cfb->cb_got_ldif )
2787 ber_str2bv( fname, 0, 1, &cf_prv.c_file );
2789 return read_config_file(fname, 0, NULL);
2793 config_back_bind( Operation *op, SlapReply *rs )
2795 if ( op->orb_method == LDAP_AUTH_SIMPLE && be_isroot_pw( op )) {
2796 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
2797 /* frontend sends result */
2798 return LDAP_SUCCESS;
2801 rs->sr_err = LDAP_INVALID_CREDENTIALS;
2802 send_ldap_result( op, rs );
2808 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
2812 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
2814 rs->sr_attrs = op->ors_attrs;
2815 rs->sr_entry = ce->ce_entry;
2816 rc = send_search_entry( op, rs );
2818 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
2819 if ( ce->ce_kids ) {
2820 rc = config_send( op, rs, ce->ce_kids, 1 );
2821 if ( rc ) return rc;
2824 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
2825 rc = config_send( op, rs, ce, 0 );
2833 static ConfigTable *
2834 config_find_table( CfOcInfo *co, AttributeDescription *ad )
2838 for (i=0; co->co_table[i].name; i++)
2839 if ( co->co_table[i].ad == ad )
2840 return &co->co_table[i];
2844 /* Sort the values in an X-ORDERED attribute.
2845 * If the values have no index, leave them in their given order.
2846 * If the values have indexes, sort them and then strip the index.
2847 * If some are indexed and some are not, return Error.
2849 * FIXME: This function probably belongs in the frontend somewhere,
2850 * like slap_mods_check.
2853 sort_vals( Attribute *a )
2856 int index = 0, noindex = 0;
2858 /* count attrs, look for index */
2859 for (i=0; a->a_vals[i].bv_val; i++) {
2860 if ( a->a_vals[i].bv_val[0] == '{' ) {
2863 ptr = strchr( a->a_vals[i].bv_val, '}' );
2864 if ( !ptr || !ptr[1] )
2865 return LDAP_INVALID_SYNTAX;
2867 return LDAP_INVALID_SYNTAX;
2871 return LDAP_INVALID_SYNTAX;
2876 int vals = i, *indexes, j, idx;
2877 struct berval tmp, ntmp;
2880 /* Strip index from normalized values */
2881 if ( !a->a_nvals || a->a_vals == a->a_nvals ) {
2882 a->a_nvals = ch_malloc( (vals+1)*sizeof(struct berval));
2883 BER_BVZERO(a->a_nvals+vals);
2884 for ( i=0; i<vals; i++ ) {
2885 ptr = strchr(a->a_vals[i].bv_val, '}') + 1;
2886 a->a_nvals[i].bv_len = a->a_vals[i].bv_len -
2887 (ptr - a->a_vals[i].bv_val);
2888 a->a_nvals[i].bv_val = ch_malloc( a->a_nvals[i].bv_len + 1);
2889 strcpy(a->a_nvals[i].bv_val, ptr );
2892 for ( i=0; i<vals; i++ ) {
2893 ptr = strchr(a->a_nvals[i].bv_val, '}') + 1;
2894 a->a_nvals[i].bv_len -= ptr - a->a_nvals[i].bv_val;
2895 strcpy(a->a_nvals[i].bv_val, ptr);
2899 indexes = ch_malloc( vals * sizeof(int) );
2900 for ( i=0; i<vals; i++)
2901 indexes[i] = atoi(a->a_vals[i].bv_val+1);
2903 /* Insertion sort */
2904 for ( i=1; i<vals; i++ ) {
2907 ntmp = a->a_nvals[i];
2909 while ((j > 0) && (indexes[j-1] > idx)) {
2910 indexes[j] = indexes[j-1];
2911 a->a_vals[j] = a->a_vals[j-1];
2912 a->a_nvals[j] = a->a_nvals[j-1];
2917 a->a_nvals[j] = ntmp;
2924 check_attr( ConfigTable *ct, ConfigArgs *ca, Attribute *a )
2928 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
2929 rc = sort_vals( a );
2933 for ( i=0; a->a_nvals[i].bv_val; i++ ) {
2934 ca->line = a->a_nvals[i].bv_val;
2935 rc = config_parse_vals( ct, ca, i );
2942 /* Parse an LDAP entry into config directives */
2944 config_add_internal( CfBackInfo *cfb, Entry *e, SlapReply *rs )
2946 CfEntryInfo *ce, *last;
2947 CfOcInfo co, *coptr, **colst = NULL;
2948 Attribute *a, *oc_at, *type_attr;
2949 AttributeDescription *type_ad = NULL;
2951 ConfigArgs ca = {0};
2954 ConfigTable *ct, *type_ct = NULL;
2956 /* Make sure parent exists and entry does not */
2957 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
2959 return LDAP_ALREADY_EXISTS;
2961 dnParent( &e->e_nname, &pdn );
2963 /* If last is NULL, the new entry is the root/suffix entry,
2964 * otherwise last should be the parent.
2966 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn )) {
2968 rs->sr_matched = last->ce_entry->e_name.bv_val;
2969 return LDAP_NO_SUCH_OBJECT;
2972 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
2973 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
2975 /* count the objectclasses */
2976 for ( i=0; oc_at->a_nvals[i].bv_val; i++ );
2978 colst = (CfOcInfo **)ch_malloc( nocs * sizeof(CfOcInfo *));
2980 for ( i=0, j=0; i<nocs; i++) {
2981 co.co_name = &oc_at->a_nvals[i];
2982 coptr = avl_find( CfOcTree, &co, CfOcInfo_cmp );
2984 /* ignore non-config objectclasses. probably should be
2985 * an error, general data doesn't belong here.
2987 if ( !coptr ) continue;
2989 /* Ignore the root objectclass, it has no implementation.
2991 if ( coptr->co_type == Cft_Abstract ) continue;
2996 /* Only the root can be Cft_Global, everything else must
2997 * have a parent. Only limited nesting arrangements are allowed.
2999 switch( colst[0]->co_type ) {
3002 rc = LDAP_CONSTRAINT_VIOLATION;
3010 if ( !last || ( last->ce_type != Cft_Global &&
3011 last->ce_type != colst[0]->co_type )) {
3012 rc = LDAP_CONSTRAINT_VIOLATION;
3017 if ( !last || ( last->ce_type != Cft_Global &&
3018 last->ce_type != Cft_Database &&
3019 last->ce_type != colst[0]->co_type )) {
3020 rc = LDAP_CONSTRAINT_VIOLATION;
3023 #ifdef SLAPD_MODULES
3025 if ( !last || last->ce_type != Cft_Global ) {
3026 rc = LDAP_CONSTRAINT_VIOLATION;
3033 /* Parse all the values and check for simple syntax errors before
3034 * performing any set actions.
3036 switch (colst[0]->co_type) {
3038 /* The cn=schema entry is all hardcoded, so never reparse it */
3039 if (last->ce_type == Cft_Global )
3047 if ( last->ce_type == Cft_Backend )
3048 ca.bi = last->ce_bi;
3050 type_ad = cfAd_backend;
3053 if ( last->ce_type == Cft_Database ) {
3054 ca.be = last->ce_be;
3056 type_ad = cfAd_database;
3057 /* dummy, just to get past check_attr */
3063 ca.be = last->ce_be;
3064 type_ad = cfAd_overlay;
3067 if ( !rs ) /* ignored */
3069 type_ad = cfAd_include;
3070 #ifdef SLAPD_MODULES
3074 ptr = strchr( e->e_name.bv_val, '{' );
3076 rc = LDAP_NAMING_VIOLATION;
3080 for (i=0, mp=&modpaths; mp && i<j; mp=mp->mp_next);
3081 /* There is no corresponding modpath for this load? */
3083 rc = LDAP_NAMING_VIOLATION;
3086 module_path( mp->mp_path.bv_val );
3092 init_config_argv( &ca );
3094 type_attr = attr_find( e->e_attrs, type_ad );
3096 rc = LDAP_OBJECT_CLASS_VIOLATION;
3099 for ( i=0; i<nocs; i++ ) {
3100 type_ct = config_find_table( colst[i], type_ad );
3101 if ( type_ct ) break;
3104 rc = LDAP_OBJECT_CLASS_VIOLATION;
3107 rc = check_attr( type_ct, &ca, type_attr );
3108 if ( rc ) goto leave;
3110 for ( a=e->e_attrs; a; a=a->a_next ) {
3111 if ( a == type_attr || a == oc_at ) continue;
3113 for ( i=0; i<nocs; i++ ) {
3114 ct = config_find_table( colst[i], a->a_desc );
3117 if ( !ct ) continue; /* user data? */
3118 rc = check_attr( ct, &ca, a );
3119 if ( rc ) goto leave;
3122 /* Basic syntax checks are OK. Do the actual settings. */
3124 ca.line = type_attr->a_nvals[0].bv_val;
3125 rc = config_parse_add( type_ct, &ca, 0 );
3126 if ( rc ) goto leave;
3128 for ( a=e->e_attrs; a; a=a->a_next ) {
3129 if ( a == type_attr || a == oc_at ) continue;
3131 for ( i=0; i<nocs; i++ ) {
3132 ct = config_find_table( colst[i], a->a_desc );
3135 if ( !ct ) continue; /* user data? */
3136 for (i=0; a->a_nvals[i].bv_val; i++) {
3137 ca.line = a->a_nvals[i].bv_val;
3138 rc = config_parse_add( ct, &ca, i );
3139 if ( rc ) goto leave;
3143 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
3144 ce->ce_parent = last;
3145 ce->ce_entry = entry_dup( e );
3146 ce->ce_entry->e_private = ce;
3147 ce->ce_type = colst[0]->co_type;
3150 } else if ( last->ce_kids ) {
3153 for (c2=last->ce_kids; c2 && c2->ce_sibs; c2 = c2->ce_sibs);
3161 if ( colst ) ch_free( colst );
3165 /* Parse an LDAP entry into config directives, then store in underlying
3169 config_back_add( Operation *op, SlapReply *rs )
3172 CfEntryInfo *ce, *last;
3174 if ( !be_isroot( op ) ) {
3175 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3176 send_ldap_result( op, rs );
3179 cfb = (CfBackInfo *)op->o_bd->be_private;
3181 ldap_pvt_thread_pool_pause( &connection_pool );
3184 * 1) check for existence of entry
3185 * 2) perform internal add
3186 * 3) store entry in underlying database
3189 ldap_pvt_thread_pool_resume( &connection_pool );
3192 send_ldap_result( op, rs );
3197 config_back_modify( Operation *op, SlapReply *rs )
3200 CfEntryInfo *ce, *last;
3202 if ( !be_isroot( op ) ) {
3203 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3204 send_ldap_result( op, rs );
3207 cfb = (CfBackInfo *)op->o_bd->be_private;
3209 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3212 rs->sr_matched = last->ce_entry->e_name.bv_val;
3213 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3216 ldap_pvt_thread_pool_pause( &connection_pool );
3219 * 1) perform the Modify on the cached Entry.
3220 * 2) verify that the Entry still satisfies the schema.
3221 * 3) perform the individual config operations.
3222 * 4) store Modified entry in underlying LDIF backend.
3224 ldap_pvt_thread_pool_resume( &connection_pool );
3226 send_ldap_result( op, rs );
3231 config_back_search( Operation *op, SlapReply *rs )
3234 CfEntryInfo *ce, *last;
3237 if ( !be_isroot( op ) ) {
3238 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3239 send_ldap_result( op, rs );
3242 cfb = (CfBackInfo *)op->o_bd->be_private;
3244 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3247 rs->sr_matched = last->ce_entry->e_name.bv_val;
3248 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3251 switch ( op->ors_scope ) {
3252 case LDAP_SCOPE_BASE:
3253 case LDAP_SCOPE_SUBTREE:
3254 config_send( op, rs, ce, 0 );
3257 case LDAP_SCOPE_ONELEVEL:
3258 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
3259 config_send( op, rs, ce, 1 );
3264 rs->sr_err = LDAP_SUCCESS;
3266 send_ldap_result( op, rs );
3271 config_alloc_entry( CfEntryInfo *parent, struct berval *rdn )
3273 Entry *e = ch_calloc( 1, sizeof(Entry) );
3274 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
3279 ce->ce_parent = parent;
3281 pdn = parent->ce_entry->e_nname;
3286 build_new_dn( &e->e_name, &pdn, rdn, NULL );
3287 ber_dupbv( &e->e_nname, &e->e_name );
3296 config_build_entry( ConfigArgs *c, Entry *e, ObjectClass *oc,
3297 struct berval *rdn, ConfigTable *ct, int table )
3299 struct berval vals[2];
3300 struct berval ad_name;
3301 AttributeDescription *ad = NULL;
3305 char textbuf[SLAP_TEXT_BUFLEN];
3306 size_t textlen = sizeof(textbuf);
3310 BER_BVZERO( &vals[1] );
3312 vals[0] = oc->soc_cname;
3313 attr_merge(e, slap_schema.si_ad_objectClass, vals, NULL );
3314 ptr = strchr(rdn->bv_val, '=');
3315 ad_name.bv_val = rdn->bv_val;
3316 ad_name.bv_len = ptr - rdn->bv_val;
3317 rc = slap_bv2ad( &ad_name, &ad, &text );
3321 vals[0].bv_val = ptr+1;
3322 vals[0].bv_len = rdn->bv_len - (vals[0].bv_val - rdn->bv_val);
3323 attr_merge(e, ad, vals, NULL );
3325 for (at=oc->soc_required; at && *at; at++) {
3326 /* Skip the naming attr */
3327 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
3329 for (i=0;ct[i].name;i++) {
3330 if (ct[i].ad == (*at)->sat_ad) {
3331 rc = config_get_vals(&ct[i], c);
3332 if (rc == LDAP_SUCCESS) {
3333 attr_merge(e, ct[i].ad, c->rvalue_vals, c->rvalue_nvals);
3334 ber_bvarray_free( c->rvalue_nvals );
3335 ber_bvarray_free( c->rvalue_vals );
3342 for (at=oc->soc_allowed; at && *at; at++) {
3343 /* Skip the naming attr */
3344 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
3346 for (i=0;ct[i].name;i++) {
3347 if (ct[i].ad == (*at)->sat_ad) {
3348 rc = config_get_vals(&ct[i], c);
3349 if (rc == LDAP_SUCCESS) {
3350 attr_merge(e, ct[i].ad, c->rvalue_vals, c->rvalue_nvals);
3351 ber_bvarray_free( c->rvalue_nvals );
3352 ber_bvarray_free( c->rvalue_vals );
3360 if ( table == BI_TABLE )
3361 ct = c->bi->bi_cf_table;
3363 ct = c->be->be_cf_table;
3364 for (;ct && ct->name;ct++) {
3365 if (!ct->ad) continue;
3366 rc = config_get_vals(ct, c);
3367 if (rc == LDAP_SUCCESS) {
3368 attr_merge(e, ct->ad, c->rvalue_vals, c->rvalue_nvals);
3372 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
3373 rc = structural_class(oc_at->a_vals, vals, NULL, &text, textbuf, textlen);
3374 BER_BVZERO( &vals[1] );
3375 attr_merge(e, slap_schema.si_ad_structuralObjectClass, vals, NULL );
3381 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
3382 Operation *op, SlapReply *rs )
3385 ConfigFile *cf = c->private;
3386 CfEntryInfo *ce, *ceprev;
3390 if ( ceparent->ce_kids ) {
3391 for ( ceprev = ceparent->ce_kids; ceprev->ce_sibs;
3392 ceprev = ceprev->ce_sibs );
3395 for (; cf; cf=cf->c_sibs, c->depth++) {
3396 c->value_dn.bv_val = c->log;
3397 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
3402 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
3404 ptr = strchr( bv.bv_val, '.' );
3406 bv.bv_len = ptr - bv.bv_val;
3407 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn={%02d}", c->depth);
3408 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
3410 c->value_dn.bv_len += bv.bv_len;
3411 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
3413 e = config_alloc_entry( ceparent, &c->value_dn );
3415 config_build_entry( c, e, cfOc_schema, &c->value_dn,
3416 c->bi->bi_cf_table, NO_TABLE );
3418 ce->ce_type = Cft_Schema;
3420 op->o_bd->be_add( op, rs );
3422 if ( !ceparent->ce_kids ) {
3423 ceparent->ce_kids = ce;
3425 ceprev->ce_sibs = ce;
3429 c->private = cf->c_kids;
3430 config_build_schema_inc( c, ceparent, op, rs );
3435 static CfEntryInfo *
3436 config_build_includes( ConfigArgs *c, CfEntryInfo *ceparent,
3437 Operation *op, SlapReply *rs )
3441 ConfigFile *cf = c->private;
3442 CfEntryInfo *ce, *ceprev;
3444 if ( ceparent->ce_kids ) {
3445 for ( ceprev = ceparent->ce_kids; ceprev->ce_sibs;
3446 ceprev = ceprev->ce_sibs );
3449 for (i=0; cf; cf=cf->c_sibs, i++) {
3450 c->value_dn.bv_val = c->log;
3451 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=include{%02d}", i);
3452 e = config_alloc_entry( ceparent, &c->value_dn );
3454 config_build_entry( c, e, cfOc_include, &c->value_dn,
3455 c->bi->bi_cf_table, NO_TABLE );
3457 op->o_bd->be_add( op, rs );
3459 ce->ce_type = Cft_Include;
3461 if ( !ceparent->ce_kids ) {
3462 ceparent->ce_kids = ce;
3464 ceprev->ce_sibs = ce;
3468 c->private = cf->c_kids;
3469 config_build_includes( c, ce, op, rs );
3475 #ifdef SLAPD_MODULES
3477 static CfEntryInfo *
3478 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
3479 Operation *op, SlapReply *rs )
3483 CfEntryInfo *ce, *ceprev;
3486 if ( ceparent->ce_kids ) {
3487 for ( ceprev = ceparent->ce_kids; ceprev->ce_sibs;
3488 ceprev = ceprev->ce_sibs );
3491 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
3492 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
3494 c->value_dn.bv_val = c->log;
3495 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=module{%02d}", i);
3496 e = config_alloc_entry( ceparent, &c->value_dn );
3498 ce->ce_type = Cft_Include;
3500 config_build_entry( c, e, cfOc_module, &c->value_dn,
3501 c->bi->bi_cf_table, NO_TABLE );
3503 op->o_bd->be_add( op, rs );
3505 if ( !ceparent->ce_kids ) {
3506 ceparent->ce_kids = ce;
3508 ceprev->ce_sibs = ce;
3517 config_back_db_open( BackendDB *be )
3519 CfBackInfo *cfb = be->be_private;
3522 CfEntryInfo *ce, *ceparent, *ceprev;
3528 Connection conn = {0};
3529 char opbuf[OPERATION_BUFFER_SIZE];
3531 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
3532 SlapReply rs = {REP_RESULT};
3534 /* If we read the config from back-ldif, nothing to do here */
3535 if ( cfb->cb_got_ldif )
3538 op = (Operation *)opbuf;
3539 connection_fake_init( &conn, op, cfb );
3541 op->o_dn = be->be_rootdn;
3542 op->o_ndn = be->be_rootndn;
3544 op->o_tag = LDAP_REQ_ADD;
3545 op->o_callback = &cb;
3546 op->o_bd = &cfb->cb_db;
3548 /* create root of tree */
3550 e = config_alloc_entry( NULL, &rdn );
3552 ce->ce_type = Cft_Global;
3556 c.private = cfb->cb_config;
3557 ct = c.bi->bi_cf_table;
3558 config_build_entry( &c, e, cfOc_global, &rdn, ct, NO_TABLE );
3560 op->o_bd->be_add( op, &rs );
3566 /* Create schema nodes... cn=schema will contain the hardcoded core
3567 * schema, read-only. Child objects will contain runtime loaded schema
3571 e = config_alloc_entry( ceparent, &rdn );
3573 ce->ce_type = Cft_Schema;
3575 config_build_entry( &c, e, cfOc_schema, &rdn, ct, NO_TABLE );
3577 op->o_bd->be_add( op, &rs );
3578 if ( !ceparent->ce_kids ) {
3579 ceparent->ce_kids = ce;
3581 ceprev->ce_sibs = ce;
3585 /* Create includeFile nodes and schema nodes for included schema... */
3586 if ( cfb->cb_config->c_kids ) {
3588 c.private = cfb->cb_config->c_kids;
3589 config_build_schema_inc( &c, ce, op, &rs );
3590 c.private = cfb->cb_config->c_kids;
3591 ceprev = config_build_includes( &c, ceparent, op, &rs );
3594 #ifdef SLAPD_MODULES
3595 /* Create Module nodes... */
3596 if ( modpaths.mp_loads ) {
3597 ceprev = config_build_modules( &c, ceparent, op, &rs );
3601 /* Create backend nodes. Skip if they don't provide a cf_table.
3602 * There usually aren't any of these.
3607 for (i=0; i<nBackendInfo; i++, bi++) {
3608 if (!bi->bi_cf_table) continue;
3609 if (!bi->bi_private) continue;
3612 rdn.bv_len = sprintf(rdn.bv_val, "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
3613 e = config_alloc_entry( ceparent, &rdn );
3615 ce->ce_type = Cft_Backend;
3618 config_build_entry( &c, e, cfOc_backend, &rdn, ct, BI_TABLE );
3620 op->o_bd->be_add( op, &rs );
3621 if ( !ceparent->ce_kids ) {
3622 ceparent->ce_kids = ce;
3624 ceprev->ce_sibs = ce;
3629 /* Create database nodes... */
3630 for (i=0; i<nBackendDB; i++) {
3631 slap_overinfo *oi = NULL;
3635 bptr = &backendDB[i];
3637 if ( overlay_is_over( bptr )) {
3638 oi = bptr->bd_info->bi_private;
3644 rdn.bv_len = sprintf(rdn.bv_val, "%s={%0x}%s", cfAd_database->ad_cname.bv_val,
3646 e = config_alloc_entry( ceparent, &rdn );
3650 ce->ce_type = Cft_Database;
3653 config_build_entry( &c, e, cfOc_database, &rdn, ct, BE_TABLE );
3655 op->o_bd->be_add( op, &rs );
3656 if ( !ceparent->ce_kids ) {
3657 ceparent->ce_kids = ce;
3659 ceprev->ce_sibs = ce;
3662 /* Iterate through overlays */
3666 CfEntryInfo *opar = ce, *oprev = NULL;
3669 for (j=0,on=oi->oi_list; on; j++,on=on->on_next) {
3671 rdn.bv_len = sprintf(rdn.bv_val, "%s={%0x}%s",
3672 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
3673 oe = config_alloc_entry( opar, &rdn );
3677 ce->ce_type = Cft_Overlay;
3680 config_build_entry( &c, oe, cfOc_overlay, &rdn, ct, BI_TABLE );
3682 op->o_bd->be_add( op, &rs );
3683 if ( !opar->ce_kids ) {
3686 oprev->ce_sibs = ce;
3697 config_back_db_destroy( Backend *be )
3699 free( be->be_private );
3704 config_back_db_init( Backend *be )
3709 cfb = ch_calloc( 1, sizeof(CfBackInfo));
3710 cfb->cb_config = &cf_prv;
3711 be->be_private = cfb;
3713 ber_dupbv( &be->be_rootdn, &config_rdn );
3714 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
3715 ber_dupbv( &dn, &be->be_rootdn );
3716 ber_bvarray_add( &be->be_suffix, &dn );
3717 ber_dupbv( &dn, &be->be_rootdn );
3718 ber_bvarray_add( &be->be_nsuffix, &dn );
3720 /* Hide from namingContexts */
3721 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
3728 AttributeDescription **desc;
3730 { "backend", &cfAd_backend },
3731 { "database", &cfAd_database },
3732 { "include", &cfAd_include },
3733 { "overlay", &cfAd_overlay },
3734 { NULL, NULL, NULL }
3738 * add / delete: all types that may be added or deleted must use an
3739 * X-ORDERED attributeType for their RDN. Adding and deleting entries
3740 * should automatically renumber the index of any siblings as needed,
3741 * so that no gaps in the numbering sequence exist after the add/delete
3743 * What can be added:
3745 * backend objects for backend-specific config directives
3749 * delete: probably no support this time around.
3751 * modrdn: generally not done. Will be invoked automatically by add/
3752 * delete to update numbering sequence. Perform as an explicit operation
3753 * so that the renumbering effect may be replicated. Subtree rename must
3754 * be supported, since renumbering a database will affect all its child
3757 * modify: must be fully supported.
3761 config_back_initialize( BackendInfo *bi )
3763 ConfigTable *ct = config_back_cf_table;
3772 bi->bi_db_init = config_back_db_init;
3773 bi->bi_db_config = 0;
3774 bi->bi_db_open = config_back_db_open;
3775 bi->bi_db_close = 0;
3776 bi->bi_db_destroy = config_back_db_destroy;
3778 bi->bi_op_bind = config_back_bind;
3779 bi->bi_op_unbind = 0;
3780 bi->bi_op_search = config_back_search;
3781 bi->bi_op_compare = 0;
3782 bi->bi_op_modify = config_back_modify;
3783 bi->bi_op_modrdn = 0;
3785 bi->bi_op_delete = 0;
3786 bi->bi_op_abandon = 0;
3788 bi->bi_extended = 0;
3790 bi->bi_chk_referrals = 0;
3792 bi->bi_connection_init = 0;
3793 bi->bi_connection_destroy = 0;
3796 for (i=0; OidMacros[i].name; i++ ) {
3797 argv[1] = OidMacros[i].name;
3798 argv[2] = OidMacros[i].oid;
3799 parse_oidm( "slapd", i, 3, argv, 0, NULL );
3802 bi->bi_cf_table = ct;
3804 i = config_register_schema( ct, cf_ocs );
3807 /* set up the notable AttributeDescriptions */
3809 for (;ct->name;ct++) {
3810 if (strcmp(ct->name, ads[i].name)) continue;
3811 *ads[i].desc = ct->ad;
3813 if (!ads[i].name) break;