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>
32 #include "slapi/slapi.h"
39 static struct berval config_rdn = BER_BVC("cn=config");
40 static struct berval schema_rdn = BER_BVC("cn=schema");
45 typedef struct modpath_s {
46 struct modpath_s *mp_next;
47 struct berval mp_path;
51 static ModPaths modpaths, *modlast = &modpaths, *modcur = &modpaths;
54 typedef struct ConfigFile {
55 struct ConfigFile *c_sibs;
56 struct ConfigFile *c_kids;
58 AttributeType *c_at_head, *c_at_tail;
59 ContentRule *c_cr_head, *c_cr_tail;
60 ObjectClass *c_oc_head, *c_oc_tail;
61 OidMacro *c_om_head, *c_om_tail;
65 typedef struct CfOcInfo {
66 struct berval *co_name;
67 ConfigTable *co_table;
72 typedef struct CfEntryInfo {
73 struct CfEntryInfo *ce_parent;
74 struct CfEntryInfo *ce_sibs;
75 struct CfEntryInfo *ce_kids;
84 ConfigFile *cb_config;
86 BackendDB cb_db; /* underlying database */
91 /* These do nothing in slapd, they're kept only to make them
94 static char *replica_pidFile, *replica_argsFile;
95 static int replicationInterval;
97 static char *passwd_salt;
98 static char *logfileName;
99 static BerVarray authz_rewrites;
101 static struct berval cfdir;
104 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
107 static ObjectClass *cfOc_schema, *cfOc_global, *cfOc_backend, *cfOc_database,
108 *cfOc_include, *cfOc_overlay, *cfOc_module;
110 static ConfigFile cf_prv, *cfn = &cf_prv;
112 static Avlnode *CfOcTree;
114 static int config_add_internal( CfBackInfo *cfb, Entry *e, SlapReply *rs,
117 static ConfigDriver config_fname;
118 static ConfigDriver config_cfdir;
119 static ConfigDriver config_generic;
120 static ConfigDriver config_search_base;
121 static ConfigDriver config_passwd_hash;
122 static ConfigDriver config_schema_dn;
123 static ConfigDriver config_sizelimit;
124 static ConfigDriver config_timelimit;
125 static ConfigDriver config_limits;
126 static ConfigDriver config_overlay;
127 static ConfigDriver config_suffix;
128 static ConfigDriver config_deref_depth;
129 static ConfigDriver config_rootdn;
130 static ConfigDriver config_rootpw;
131 static ConfigDriver config_restrict;
132 static ConfigDriver config_allows;
133 static ConfigDriver config_disallows;
134 static ConfigDriver config_requires;
135 static ConfigDriver config_security;
136 static ConfigDriver config_referral;
137 static ConfigDriver config_loglevel;
138 static ConfigDriver config_replica;
139 static ConfigDriver config_updatedn;
140 static ConfigDriver config_updateref;
141 static ConfigDriver config_include;
143 static ConfigDriver config_tls_option;
144 static ConfigDriver config_tls_config;
146 extern ConfigDriver syncrepl_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 { "OLcfgGlAt", "OLcfgAt:0" },
196 { "OLcfgBkAt", "OLcfgAt:1" },
197 { "OLcfgDbAt", "OLcfgAt:2" },
198 { "OLcfgOvAt", "OLcfgAt:3" },
199 { "OLcfgOc", "OLcfg:4" },
200 { "OLcfgGlOc", "OLcfgOc:0" },
201 { "OLcfgBkOc", "OLcfgOc:1" },
202 { "OLcfgDbOc", "OLcfgOc:2" },
203 { "OLcfgOvOc", "OLcfgOc:3" },
204 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
205 { "OMsInteger", "OMsyn:27" },
206 { "OMsBoolean", "OMsyn:7" },
207 { "OMsDN", "OMsyn:12" },
208 { "OMsDirectoryString", "OMsyn:15" },
209 { "OMsOctetString", "OMsyn:40" },
214 * OLcfg{Bk|Db}{Oc|At}:0 -> common
215 * OLcfg{Bk|Db}{Oc|At}:1 -> bdb
216 * OLcfg{Bk|Db}{Oc|At}:2 -> ldif
217 * OLcfg{Bk|Db}{Oc|At}:3 -> ldap?
220 /* alphabetical ordering */
222 ConfigTable config_back_cf_table[] = {
223 /* This attr is read-only */
224 { "", "", 0, 0, 0, ARG_MAGIC,
225 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
226 "DESC 'File for slapd configuration directives' "
227 "EQUALITY caseIgnoreMatch "
228 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
229 { "", "", 0, 0, 0, ARG_MAGIC,
230 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
231 "DESC 'Directory for slapd configuration backend' "
232 "EQUALITY caseIgnoreMatch "
233 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
234 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
235 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
236 "DESC 'Access Control List' "
237 "EQUALITY caseIgnoreMatch "
238 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
239 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
240 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
241 "DESC 'Allowed set of deprecated features' "
242 "EQUALITY caseIgnoreMatch "
243 "SYNTAX OMsDirectoryString )", NULL, NULL },
244 { "argsfile", "file", 2, 2, 0, ARG_STRING,
245 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
246 "DESC 'File for slapd command line options' "
247 "EQUALITY caseIgnoreMatch "
248 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
249 { "attribute", "attribute", 2, 0, 9,
250 ARG_PAREN|ARG_MAGIC|CFG_ATTR|ARG_NO_DELETE|ARG_NO_INSERT,
251 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
252 "DESC 'OpenLDAP attributeTypes' "
253 "EQUALITY caseIgnoreMatch "
254 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
256 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
257 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
258 "EQUALITY caseIgnoreMatch "
259 "SYNTAX OMsDirectoryString )", NULL, NULL },
260 { "authid-rewrite", NULL, 2, 0, 0,
261 #ifdef SLAP_AUTH_REWRITE
262 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
266 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
267 "EQUALITY caseIgnoreMatch "
268 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
269 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
270 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
271 "EQUALITY caseIgnoreMatch "
272 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
273 { "authz-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
274 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
275 "EQUALITY caseIgnoreMatch "
276 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
277 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
278 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
279 "DESC 'A type of backend' "
280 "EQUALITY caseIgnoreMatch "
281 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
283 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
284 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
285 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
286 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
287 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
288 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
289 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
290 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
291 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
292 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
293 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
294 "DESC 'The backend type for a database instance' "
295 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
296 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_MAGIC,
297 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
298 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
299 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
300 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
301 "EQUALITY caseIgnoreMatch "
302 "SYNTAX OMsDirectoryString )", NULL, NULL },
303 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
304 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
305 "DESC 'OpenLDAP DIT content rules' "
306 "EQUALITY caseIgnoreMatch "
307 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
309 { "gentlehup", "on|off", 2, 2, 0,
311 ARG_ON_OFF, &global_gentlehup,
315 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
316 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
317 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
318 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
319 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
320 { "include", "file", 2, 2, 0, ARG_MAGIC,
321 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
322 "SUP labeledURI )", NULL, NULL },
323 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
324 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
325 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
326 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
327 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
328 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
329 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
330 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
331 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
332 { "index_substr_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
333 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
334 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
335 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
336 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
337 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
338 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
339 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
340 "SYNTAX OMsDirectoryString )", NULL, NULL },
341 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
342 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
343 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
344 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
345 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
346 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
347 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
348 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
349 "SYNTAX OMsDirectoryString )", NULL, NULL },
350 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
351 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
352 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
353 { "moduleload", "file", 2, 0, 0,
355 ARG_MAGIC|CFG_MODLOAD, &config_generic,
359 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
360 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
361 { "modulepath", "path", 2, 2, 0,
363 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
367 "( OLcfgGlAt:31 NAME 'olcModulePath' "
368 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
369 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC|ARG_NO_DELETE|ARG_NO_INSERT,
370 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
371 "DESC 'OpenLDAP object classes' "
372 "EQUALITY caseIgnoreMatch "
373 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
375 { "objectidentifier", NULL, 0, 0, 0, ARG_MAGIC|CFG_OID,
376 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
377 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
378 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
379 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
380 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
381 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
382 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
383 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
384 { "password-hash", "hash", 2, 2, 0, ARG_MAGIC,
385 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
386 "SYNTAX OMsDirectoryString )", NULL, NULL },
387 { "pidfile", "file", 2, 2, 0, ARG_STRING,
388 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
389 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
390 { "plugin", NULL, 0, 0, 0,
392 ARG_MAGIC|CFG_PLUGIN, &config_generic,
396 "( OLcfgGlAt:38 NAME 'olcPlugin' "
397 "SYNTAX OMsDirectoryString )", NULL, NULL },
398 { "pluginlog", "filename", 2, 2, 0,
400 ARG_STRING, &slapi_log_file,
404 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
405 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
406 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
407 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
408 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
409 { "referral", "url", 2, 2, 0, ARG_MAGIC,
410 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
411 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
412 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
413 &config_replica, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
414 "SUP labeledURI )", NULL, NULL },
415 { "replica-argsfile", NULL, 0, 0, 0, ARG_STRING,
416 &replica_argsFile, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
417 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
418 { "replica-pidfile", NULL, 0, 0, 0, ARG_STRING,
419 &replica_pidFile, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
420 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
421 { "replicationInterval", NULL, 0, 0, 0, ARG_INT,
422 &replicationInterval, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
423 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
424 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC|ARG_STRING|CFG_REPLOG,
425 &config_generic, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
426 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
427 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
428 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
429 "SYNTAX OMsDirectoryString )", NULL, NULL },
430 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
431 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
432 "SYNTAX OMsDirectoryString )", NULL, NULL },
433 { "reverse-lookup", "on|off", 2, 2, 0,
434 #ifdef SLAPD_RLOOKUPS
435 ARG_ON_OFF, &use_reverse_lookup,
439 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
440 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
441 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_MAGIC,
442 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
443 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
444 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
445 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
446 "SYNTAX OMsDirectoryString )", NULL, NULL },
447 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
448 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
449 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
450 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
451 &config_generic, NULL, NULL, NULL },
452 { "sasl-host", "host", 2, 2, 0,
453 #ifdef HAVE_CYRUS_SASL
454 ARG_STRING|ARG_UNIQUE, &global_host,
458 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
459 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
460 { "sasl-realm", "realm", 2, 2, 0,
461 #ifdef HAVE_CYRUS_SASL
462 ARG_STRING|ARG_UNIQUE, &global_realm,
466 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
467 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
468 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
469 &config_generic, NULL, NULL, NULL },
470 { "sasl-secprops", "properties", 2, 2, 0,
471 #ifdef HAVE_CYRUS_SASL
472 ARG_MAGIC|CFG_SASLSECP, &config_generic,
476 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
477 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
478 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
479 &config_generic, NULL, NULL, NULL },
480 { "schemacheck", "on|off", 2, 2, 0, ARG_ON_OFF|ARG_MAGIC|CFG_CHECK,
481 &config_generic, "( OLcfgGlAt:57 NAME 'olcSchemaCheck' "
482 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
483 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_MAGIC,
484 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
485 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
486 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
487 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
488 "SYNTAX OMsDirectoryString )", NULL, NULL },
489 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
490 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
491 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
492 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
493 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
494 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
495 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
496 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
497 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
498 { "srvtab", "file", 2, 2, 0,
499 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
500 ARG_STRING, &ldap_srvtab,
504 "( OLcfgGlAt:63 NAME 'olcSrvtab' "
505 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
506 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_MAGIC,
507 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
508 "SYNTAX OMsDN )", NULL, NULL },
509 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
510 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
511 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
512 { "threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_THREADS,
513 &config_generic, "( OLcfgGlAt:66 NAME 'olcThreads' "
514 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
515 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
516 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
517 "SYNTAX OMsDirectoryString )", NULL, NULL },
518 { "TLSCACertificateFile", NULL, 0, 0, 0,
520 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
524 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
525 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
526 { "TLSCACertificatePath", NULL, 0, 0, 0,
528 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
532 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
533 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
534 { "TLSCertificateFile", NULL, 0, 0, 0,
536 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
540 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
541 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
542 { "TLSCertificateKeyFile", NULL, 0, 0, 0,
544 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
548 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
549 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
550 { "TLSCipherSuite", NULL, 0, 0, 0,
552 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
556 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
557 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
558 { "TLSCRLCheck", NULL, 0, 0, 0,
559 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
560 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
564 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
565 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
566 { "TLSRandFile", NULL, 0, 0, 0,
568 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
572 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
573 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
574 { "TLSVerifyClient", NULL, 0, 0, 0,
576 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
580 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
581 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
582 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
583 NULL, NULL, NULL, NULL },
584 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_MAGIC,
585 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
586 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
587 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
588 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
589 "SUP labeledURI )", NULL, NULL },
590 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
591 NULL, NULL, NULL, NULL }
594 static ConfigOCs cf_ocs[] = {
597 "DESC 'OpenLDAP configuration object' "
598 "ABSTRACT SUP top )", Cft_Abstract, NULL },
601 "DESC 'OpenLDAP Global configuration options' "
602 "SUP olcConfig STRUCTURAL "
603 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
604 "olcAttributeOptions $ olcAuthIDRewrite $ "
605 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
606 "olcConnMaxPending $ olcConnMaxPendingAuth $ olcDefaultSearchBase $ "
607 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
608 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
609 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcLocalSSF $ "
611 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
612 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
613 "olcReplicaPidFile $ olcReplicaArgsFile $ olcReplicationInterval $ "
614 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
615 "olcRootDSE $ olcRootPW $ "
616 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
617 "olcSchemaCheck $ olcSecurity $ olcSizeLimit $ "
618 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ olcSrvtab $ "
619 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
620 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
621 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
622 "olcTLSRandFile $ olcTLSVerifyClient $ "
623 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
624 "olcDitContentRules ) )", Cft_Global, &cfOc_global },
626 "NAME 'olcSchemaConfig' "
627 "DESC 'OpenLDAP schema object' "
628 "SUP olcConfig STRUCTURAL "
629 "MAY ( cn $ olcObjectIdentifier $ olcAttributeTypes $ "
630 "olcObjectClasses $ olcDitContentRules ) )",
631 Cft_Schema, &cfOc_schema },
633 "NAME 'olcBackendConfig' "
634 "DESC 'OpenLDAP Backend-specific options' "
635 "SUP olcConfig STRUCTURAL "
636 "MUST olcBackend )", Cft_Backend, &cfOc_backend },
638 "NAME 'olcDatabaseConfig' "
639 "DESC 'OpenLDAP Database-specific options' "
640 "SUP olcConfig STRUCTURAL "
642 "MAY ( olcSuffix $ olcAccess $ olcLastMod $ olcLimits $ "
643 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
644 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
645 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncrepl $ "
646 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef ) )",
647 Cft_Database, &cfOc_database },
649 "NAME 'olcOverlayConfig' "
650 "DESC 'OpenLDAP Overlay-specific options' "
651 "SUP olcConfig STRUCTURAL "
652 "MUST olcOverlay )", Cft_Overlay, &cfOc_overlay },
654 "NAME 'olcIncludeFile' "
655 "DESC 'OpenLDAP configuration include file' "
656 "SUP olcConfig STRUCTURAL "
658 "MAY ( cn $ olcRootDSE ) )",
659 Cft_Include, &cfOc_include },
662 "NAME 'olcModuleList' "
663 "DESC 'OpenLDAP dynamic module info' "
664 "SUP olcConfig STRUCTURAL "
665 "MUST ( olcModulePath $ olcModuleLoad ) "
666 "MAY cn )", Cft_Module, &cfOc_module },
672 config_generic(ConfigArgs *c) {
676 if ( c->op == SLAP_CONFIG_EMIT ) {
680 c->value_int = ldap_pvt_thread_get_concurrency();
683 c->value_int = connection_pool_max;
687 c->value_string = ch_strdup( passwd_salt );
692 if ( c->be->be_limits ) {
697 for ( i=0; c->be->be_limits[i]; i++ ) {
698 bv.bv_len = sprintf( buf, IFMT, i );
699 bv.bv_val = buf+bv.bv_len;
700 limits_unparse( c->be->be_limits[i], &bv );
701 bv.bv_len += bv.bv_val - buf;
703 value_add_one( &c->rvalue_vals, &bv );
706 if ( !c->rvalue_vals ) rc = 1;
709 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_OP_WRITES) != 0;
712 c->value_string = ch_strdup( slap_sasl_getpolicy());
715 slap_sasl_regexp_unparse( &c->rvalue_vals );
716 if ( !c->rvalue_vals ) rc = 1;
718 #ifdef HAVE_CYRUS_SASL
720 struct berval bv = BER_BVNULL;
721 slap_sasl_secprops_unparse( &bv );
722 if ( !BER_BVISNULL( &bv )) {
723 ber_bvarray_add( &c->rvalue_vals, &bv );
731 c->value_int = c->be->be_max_deref_depth;
734 ConfigFile *cf = c->private;
736 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
737 else if ( cf->c_om_head )
738 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
740 if ( !c->rvalue_vals )
745 ConfigFile *cf = c->private;
747 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
748 else if ( cf->c_oc_head )
749 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
751 if ( !c->rvalue_vals )
756 ConfigFile *cf = c->private;
758 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
759 else if ( cf->c_at_head )
760 at_unparse( &c->rvalue_vals, cf->c_at_head,
762 if ( !c->rvalue_vals )
767 ConfigFile *cf = c->private;
769 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
770 else if ( cf->c_cr_head )
771 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
773 if ( !c->rvalue_vals )
779 c->value_int = global_schemacheck;
783 char *src, *dst, ibuf[11];
784 struct berval bv, abv;
785 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
786 abv.bv_len = sprintf( ibuf, IFMT, i );
787 acl_unparse( a, &bv );
788 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
789 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
790 /* Turn TAB / EOL into plain space */
791 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
792 if (isspace(*src)) *dst++ = ' ';
796 if (dst[-1] == ' ') {
800 abv.bv_len = dst - abv.bv_val;
801 ber_bvarray_add( &c->rvalue_vals, &abv );
807 if ( c->be->be_replogfile )
808 c->value_string = ch_strdup( c->be->be_replogfile );
811 ConfigFile *cf = c->private;
812 if ( cf->c_dseFiles ) {
813 value_add( &c->rvalue_vals, cf->c_dseFiles );
821 c->value_string = ch_strdup( logfileName );
826 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
828 case CFG_SSTR_IF_MAX:
829 c->value_int = index_substr_if_maxlen;
831 case CFG_SSTR_IF_MIN:
832 c->value_int = index_substr_if_minlen;
836 ModPaths *mp = c->private;
839 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
842 bv.bv_len = sprintf( bv.bv_val, IFMT "%s", i,
843 mp->mp_loads[i].bv_val );
844 value_add_one( &c->rvalue_vals, &bv );
848 rc = c->rvalue_vals ? 0 : 1;
852 ModPaths *mp = c->private;
853 value_add_one( &c->rvalue_vals, &mp->mp_path );
855 rc = c->rvalue_vals ? 0 : 1;
861 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
862 if ( !c->rvalue_vals ) rc = 1;
865 #ifdef SLAP_AUTH_REWRITE
867 if ( authz_rewrites ) {
868 struct berval bv, idx;
873 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
874 idx.bv_len = sprintf( idx.bv_val, IFMT, i );
875 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
876 bv.bv_val = ch_malloc( bv.bv_len + 1 );
877 strcpy( bv.bv_val, idx.bv_val );
878 strcpy( bv.bv_val+idx.bv_len, authz_rewrites[i].bv_val );
879 ber_bvarray_add( &c->rvalue_vals, &bv );
882 if ( !c->rvalue_vals ) rc = 1;
889 } else if ( c->op == LDAP_MOD_DELETE ) {
892 /* single-valued attrs, no-ops */
901 case CFG_SSTR_IF_MAX:
902 case CFG_SSTR_IF_MIN:
905 /* no-ops, requires slapd restart */
910 sprintf(c->log, "change requires slapd restart");
914 ch_free( passwd_salt );
919 ch_free( c->be->be_replogfile );
920 c->be->be_replogfile = NULL;
924 ch_free( logfileName );
931 if ( c->be == frontendDB )
934 end = frontendDB->be_acl;
935 acl_destroy( c->be->be_acl, end );
937 AccessControl **prev, *a;
939 for (i=0, prev = &c->be->be_acl; i < c->valx;
951 /* FIXME: there is no limits_free function */
953 /* FIXME: there is no ad_option_free function */
955 /* FIXME: there is no way to remove attributes added by
969 p = strchr(c->line,'(' /*')'*/);
973 if(!(c->bi = backend_info(c->argv[1]))) {
974 sprintf( c->msg, "<%s> failed init", c->argv[0] );
975 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
976 c->log, c->msg, c->argv[1] );
983 /* NOTE: config is always the first backend!
985 if ( !strcasecmp( c->argv[1], "config" )) {
986 c->be = LDAP_STAILQ_FIRST(&backendDB);
987 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
989 } else if(!(c->be = backend_db_init(c->argv[1]))) {
990 sprintf( c->msg, "<%s> failed init", c->argv[0] );
991 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
992 c->log, c->msg, c->argv[1] );
998 ldap_pvt_thread_set_concurrency(c->value_int);
1002 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1003 connection_pool_max = c->value_int; /* save for reference */
1007 if ( passwd_salt ) ch_free( passwd_salt );
1008 passwd_salt = c->value_string;
1009 lutil_salt_format(passwd_salt);
1013 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1019 c->be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1021 c->be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1025 ch_free(c->value_string);
1026 if (slap_sasl_setpolicy( c->argv[1] )) {
1027 sprintf( c->msg, "<%s> unable to parse value", c->argv[0] );
1028 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1029 c->log, c->msg, c->argv[1] );
1035 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1039 #ifdef HAVE_CYRUS_SASL
1042 char *txt = slap_sasl_secprops( c->argv[1] );
1044 snprintf( c->msg, sizeof(c->msg), "<%s> %s",
1046 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
1054 c->be->be_max_deref_depth = c->value_int;
1060 if(parse_oidm(c->fname, c->lineno, c->argc, c->argv, 1, &om))
1062 if (!cfn->c_om_head) cfn->c_om_head = om;
1063 cfn->c_om_tail = om;
1070 if(parse_oc(c->fname, c->lineno, p, c->argv, &oc)) return(1);
1071 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1072 cfn->c_oc_tail = oc;
1079 if(parse_cr(c->fname, c->lineno, p, c->argv, &cr)) return(1);
1080 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1081 cfn->c_cr_tail = cr;
1088 if(parse_at(c->fname, c->lineno, p, c->argv, &at)) return(1);
1089 if (!cfn->c_at_head) cfn->c_at_head = at;
1090 cfn->c_at_tail = at;
1095 ad_define_option(NULL, NULL, 0);
1096 for(i = 1; i < c->argc; i++)
1097 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1102 global_schemacheck = c->value_int;
1103 if(!global_schemacheck) Debug(LDAP_DEBUG_ANY, "%s: "
1104 "schema checking disabled! your mileage may vary!\n",
1109 parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, c->valx);
1113 if(SLAP_MONITOR(c->be)) {
1114 Debug(LDAP_DEBUG_ANY, "%s: "
1115 "\"replogfile\" should not be used "
1116 "inside monitor database\n",
1118 return(0); /* FIXME: should this be an error? */
1121 c->be->be_replogfile = c->value_string;
1125 if(read_root_dse_file(c->argv[1])) {
1126 sprintf( c->msg, "<%s> could not read file", c->argv[0] );
1127 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1128 c->log, c->msg, c->argv[1] );
1133 ber_str2bv( c->argv[1], 0, 1, &bv );
1134 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1140 if ( logfileName ) ch_free( logfileName );
1141 logfileName = c->value_string;
1142 logfile = fopen(logfileName, "w");
1143 if(logfile) lutil_debug_file(logfile);
1147 if(SLAP_NOLASTMODCMD(c->be)) {
1148 sprintf( c->msg, "<%s> not available for %s database",
1149 c->argv[0], c->be->bd_info->bi_type );
1150 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1151 c->log, c->msg, 0 );
1155 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1157 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1160 case CFG_SSTR_IF_MAX:
1161 if (c->value_int < index_substr_if_minlen) {
1162 sprintf( c->msg, "<%s> invalid value", c->argv[0] );
1163 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1164 c->log, c->msg, c->value_int );
1167 index_substr_if_maxlen = c->value_int;
1170 case CFG_SSTR_IF_MIN:
1171 if (c->value_int > index_substr_if_maxlen) {
1172 sprintf( c->msg, "<%s> invalid value", c->argv[0] );
1173 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1174 c->log, c->msg, c->value_int );
1177 index_substr_if_minlen = c->value_int;
1180 #ifdef SLAPD_MODULES
1182 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1184 /* Record this load on the current path */
1188 char *ptr = c->line + STRLENOF("moduleload");
1189 while (!isspace(*ptr)) ptr++;
1190 while (isspace(*ptr)) ptr++;
1191 ber_str2bv(ptr, 0, 1, &bv);
1192 if ( c->op == SLAP_CONFIG_ADD )
1196 ber_bvarray_add( &mp->mp_loads, &bv );
1201 if(module_path(c->argv[1])) return(1);
1202 /* Record which path was used with each module */
1206 if (!modpaths.mp_loads) {
1209 mp = ch_malloc( sizeof( ModPaths ));
1210 modlast->mp_next = mp;
1212 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1214 mp->mp_loads = NULL;
1217 if ( c->op == SLAP_CONFIG_ADD )
1226 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
1228 slapi_plugins_used++;
1232 #ifdef SLAP_AUTH_REWRITE
1235 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
1237 ber_str2bv( c->line, 0, 1, &bv );
1238 ber_bvarray_add( &authz_rewrites, &bv );
1245 Debug(LDAP_DEBUG_ANY, "%s: unknown CFG_TYPE %d"
1246 "(ignored)\n", c->log, c->type, 0);
1254 config_fname(ConfigArgs *c) {
1255 if(c->op == SLAP_CONFIG_EMIT) {
1257 ConfigFile *cf = c->private;
1258 value_add_one( &c->rvalue_vals, &cf->c_file );
1267 config_cfdir(ConfigArgs *c) {
1268 if(c->op == SLAP_CONFIG_EMIT) {
1269 if ( !BER_BVISEMPTY( &cfdir )) {
1270 value_add_one( &c->rvalue_vals, &cfdir );
1279 config_search_base(ConfigArgs *c) {
1282 if(c->op == SLAP_CONFIG_EMIT) {
1284 if (!BER_BVISEMPTY(&default_search_base)) {
1285 value_add_one(&c->rvalue_vals, &default_search_base);
1286 value_add_one(&c->rvalue_nvals, &default_search_nbase);
1290 } else if( c->op == LDAP_MOD_DELETE ) {
1291 ch_free( default_search_base.bv_val );
1292 ch_free( default_search_nbase.bv_val );
1293 BER_BVZERO( &default_search_base );
1294 BER_BVZERO( &default_search_nbase );
1298 if(c->bi || c->be != frontendDB) {
1299 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
1300 "prior to any backend or database definition\n",
1305 if(default_search_nbase.bv_len) {
1306 free(default_search_base.bv_val);
1307 free(default_search_nbase.bv_val);
1310 default_search_base = c->value_dn;
1311 default_search_nbase = c->value_ndn;
1316 config_passwd_hash(ConfigArgs *c) {
1318 if (c->op == SLAP_CONFIG_EMIT) {
1320 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
1321 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
1322 value_add_one(&c->rvalue_vals, &bv);
1325 } else if ( c->op == LDAP_MOD_DELETE ) {
1326 if ( c->valx < 0 ) {
1327 ldap_charray_free( default_passwd_hash );
1328 default_passwd_hash = NULL;
1331 ch_free( default_passwd_hash[i] );
1332 for (; default_passwd_hash[i]; i++ )
1333 default_passwd_hash[i] = default_passwd_hash[i+1];
1337 if(default_passwd_hash) {
1338 Debug(LDAP_DEBUG_ANY, "%s: "
1339 "already set default password_hash\n",
1343 for(i = 1; i < c->argc; i++) {
1344 if(!lutil_passwd_scheme(c->argv[i])) {
1345 sprintf( c->msg, "<%s> schema not available", c->argv[0] );
1346 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1347 c->log, c->msg, c->argv[i]);
1349 ldap_charray_add(&default_passwd_hash, c->argv[i]);
1351 if(!default_passwd_hash) {
1352 sprintf( c->msg, "<%s> no valid hashes found", c->argv[0] );
1353 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1354 c->log, c->msg, 0 );
1362 config_schema_dn(ConfigArgs *c) {
1363 if ( c->op == SLAP_CONFIG_EMIT ) {
1365 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
1366 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
1367 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
1371 } else if ( c->op == LDAP_MOD_DELETE ) {
1372 ch_free( c->be->be_schemadn.bv_val );
1373 ch_free( c->be->be_schemandn.bv_val );
1374 BER_BVZERO( &c->be->be_schemadn );
1375 BER_BVZERO( &c->be->be_schemandn );
1378 ch_free( c->be->be_schemadn.bv_val );
1379 ch_free( c->be->be_schemandn.bv_val );
1380 c->be->be_schemadn = c->value_dn;
1381 c->be->be_schemandn = c->value_ndn;
1386 config_sizelimit(ConfigArgs *c) {
1389 struct slap_limits_set *lim = &c->be->be_def_limit;
1390 if (c->op == SLAP_CONFIG_EMIT) {
1395 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv );
1396 if ( !BER_BVISEMPTY( &bv ))
1397 value_add_one( &c->rvalue_vals, &bv );
1401 } else if ( c->op == LDAP_MOD_DELETE ) {
1402 /* Reset to defaults */
1403 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
1404 lim->lms_s_hard = 0;
1405 lim->lms_s_unchecked = -1;
1407 lim->lms_s_pr_hide = 0;
1408 lim->lms_s_pr_total = 0;
1411 for(i = 1; i < c->argc; i++) {
1412 if(!strncasecmp(c->argv[i], "size", 4)) {
1413 rc = limits_parse_one(c->argv[i], lim);
1415 sprintf( c->msg, "<%s> unable to parse value", c->argv[0] );
1416 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1417 c->log, c->msg, c->argv[i]);
1421 if(!strcasecmp(c->argv[i], "unlimited")) {
1422 lim->lms_s_soft = -1;
1424 lim->lms_s_soft = strtol(c->argv[i], &next, 0);
1425 if(next == c->argv[i]) {
1426 sprintf( c->msg, "<%s> unable to parse limit", c->argv[0]);
1427 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1428 c->log, c->msg, c->argv[i]);
1430 } else if(next[0] != '\0') {
1431 Debug(LDAP_DEBUG_ANY, "%s: "
1432 "trailing chars \"%s\" in \"sizelimit <limit>\" line (ignored)\n",
1436 lim->lms_s_hard = 0;
1443 config_timelimit(ConfigArgs *c) {
1446 struct slap_limits_set *lim = &c->be->be_def_limit;
1447 if (c->op == SLAP_CONFIG_EMIT) {
1452 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv );
1453 if ( !BER_BVISEMPTY( &bv ))
1454 value_add_one( &c->rvalue_vals, &bv );
1458 } else if ( c->op == LDAP_MOD_DELETE ) {
1459 /* Reset to defaults */
1460 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
1461 lim->lms_t_hard = 0;
1464 for(i = 1; i < c->argc; i++) {
1465 if(!strncasecmp(c->argv[i], "time", 4)) {
1466 rc = limits_parse_one(c->argv[i], lim);
1468 sprintf( c->msg, "<%s> unable to parse value", c->argv[0] );
1469 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1470 c->log, c->msg, c->argv[i]);
1474 if(!strcasecmp(c->argv[i], "unlimited")) {
1475 lim->lms_t_soft = -1;
1477 lim->lms_t_soft = strtol(c->argv[i], &next, 0);
1478 if(next == c->argv[i]) {
1479 sprintf( c->msg, "<%s> unable to parse limit", c->argv[0]);
1480 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1481 c->log, c->msg, c->argv[i]);
1483 } else if(next[0] != '\0') {
1484 Debug(LDAP_DEBUG_ANY, "%s: "
1485 "trailing chars \"%s\" in \"timelimit <limit>\" line (ignored)\n",
1489 lim->lms_t_hard = 0;
1496 config_overlay(ConfigArgs *c) {
1497 if (c->op == SLAP_CONFIG_EMIT) {
1499 } else if ( c->op == LDAP_MOD_DELETE ) {
1502 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1])) {
1504 Debug(LDAP_DEBUG_ANY, "%s: (optional) %s overlay \"%s\" configuration failed (ignored)\n",
1505 c->log, c->be == frontendDB ? "global " : "", c->argv[1][1]);
1506 } else if(overlay_config(c->be, c->argv[1])) {
1513 config_suffix(ConfigArgs *c) {
1515 struct berval pdn, ndn;
1518 if (c->be == frontendDB || SLAP_MONITOR(c->be) ||
1519 SLAP_CONFIG(c->be)) return 1;
1521 if (c->op == SLAP_CONFIG_EMIT) {
1522 if ( c->be->be_suffix == NULL
1523 || BER_BVISNULL( &c->be->be_suffix[0] ) )
1527 value_add( &c->rvalue_vals, c->be->be_suffix );
1528 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
1531 } else if ( c->op == LDAP_MOD_DELETE ) {
1532 if ( c->valx < 0 ) {
1533 ber_bvarray_free( c->be->be_suffix );
1534 ber_bvarray_free( c->be->be_nsuffix );
1535 c->be->be_suffix = NULL;
1536 c->be->be_nsuffix = NULL;
1539 ch_free( c->be->be_suffix[i].bv_val );
1540 ch_free( c->be->be_nsuffix[i].bv_val );
1541 for (; c->be->be_suffix[i].bv_val; i++) {
1542 c->be->be_suffix[i] = c->be->be_suffix[i+1];
1543 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
1548 #ifdef SLAPD_MONITOR_DN
1549 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
1550 sprintf( c->msg, "<%s> DN is reserved for monitoring slapd",
1552 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1553 c->log, c->msg, SLAPD_MONITOR_DN);
1560 tbe = select_backend(&ndn, 0, 0);
1562 Debug(LDAP_DEBUG_ANY, "%s: suffix already served by this backend! (ignored)\n",
1567 sprintf( c->msg, "<%s> suffix already served by a preceding backend",
1569 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1570 c->log, c->msg, tbe->be_suffix[0].bv_val);
1574 } else if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
1575 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
1576 "base provided \"%s\" (assuming okay)\n",
1577 c->log, default_search_base.bv_val, 0);
1579 ber_bvarray_add(&c->be->be_suffix, &pdn);
1580 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
1585 config_rootdn(ConfigArgs *c) {
1586 if (c->op == SLAP_CONFIG_EMIT) {
1587 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
1588 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
1589 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
1594 } else if ( c->op == LDAP_MOD_DELETE ) {
1595 ch_free( c->be->be_rootdn.bv_val );
1596 ch_free( c->be->be_rootndn.bv_val );
1597 BER_BVZERO( &c->be->be_rootdn );
1598 BER_BVZERO( &c->be->be_rootndn );
1601 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
1602 ch_free( c->be->be_rootdn.bv_val );
1603 ch_free( c->be->be_rootndn.bv_val );
1605 c->be->be_rootdn = c->value_dn;
1606 c->be->be_rootndn = c->value_ndn;
1611 config_rootpw(ConfigArgs *c) {
1613 if (c->op == SLAP_CONFIG_EMIT) {
1614 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
1615 ber_dupbv( &c->value_bv, &c->be->be_rootpw);
1619 } else if ( c->op == LDAP_MOD_DELETE ) {
1620 ch_free( c->be->be_rootpw.bv_val );
1621 BER_BVZERO( &c->be->be_rootpw );
1625 tbe = select_backend(&c->be->be_rootndn, 0, 0);
1627 sprintf( c->msg, "<%s> can only be set when rootdn is under suffix",
1629 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1633 if ( !BER_BVISNULL( &c->be->be_rootpw ))
1634 ch_free( c->be->be_rootpw.bv_val );
1635 c->be->be_rootpw = c->value_bv;
1640 config_restrict(ConfigArgs *c) {
1641 slap_mask_t restrictops = 0;
1643 slap_verbmasks restrictable_ops[] = {
1644 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
1645 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
1646 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
1647 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
1648 { BER_BVC("modrdn"), 0 },
1649 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
1650 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
1651 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
1652 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
1653 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
1654 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
1655 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
1656 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
1657 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
1658 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
1662 if (c->op == SLAP_CONFIG_EMIT) {
1663 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
1665 } else if ( c->op == LDAP_MOD_DELETE ) {
1667 c->be->be_restrictops = 0;
1669 restrictops = verb_to_mask( c->line, restrictable_ops );
1670 c->be->be_restrictops ^= restrictops;
1674 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
1676 sprintf( c->msg, "<%s> unknown operation", c->argv[0] );
1677 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1678 c->log, c->msg, c->argv[i]);
1681 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
1682 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
1683 c->be->be_restrictops |= restrictops;
1688 config_allows(ConfigArgs *c) {
1689 slap_mask_t allows = 0;
1691 slap_verbmasks allowable_ops[] = {
1692 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
1693 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
1694 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
1695 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
1698 if (c->op == SLAP_CONFIG_EMIT) {
1699 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
1700 } else if ( c->op == LDAP_MOD_DELETE ) {
1704 allows = verb_to_mask( c->line, allowable_ops );
1705 global_allows ^= allows;
1709 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
1711 sprintf( c->msg, "<%s> unknown feature", c->argv[0] );
1712 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1713 c->log, c->msg, c->argv[i]);
1716 global_allows |= allows;
1721 config_disallows(ConfigArgs *c) {
1722 slap_mask_t disallows = 0;
1724 slap_verbmasks disallowable_ops[] = {
1725 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
1726 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
1727 { BER_BVC("bind_krb4"), SLAP_DISALLOW_BIND_KRBV4 },
1728 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
1729 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
1732 if (c->op == SLAP_CONFIG_EMIT) {
1733 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
1734 } else if ( c->op == LDAP_MOD_DELETE ) {
1736 global_disallows = 0;
1738 disallows = verb_to_mask( c->line, disallowable_ops );
1739 global_disallows ^= disallows;
1743 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
1745 sprintf( c->msg, "<%s> unknown feature", c->argv[0] );
1746 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1747 c->log, c->msg, c->argv[i]);
1750 global_disallows |= disallows;
1755 config_requires(ConfigArgs *c) {
1756 slap_mask_t requires = 0;
1758 slap_verbmasks requires_ops[] = {
1759 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
1760 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
1761 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
1762 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
1763 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
1766 if (c->op == SLAP_CONFIG_EMIT) {
1767 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
1768 } else if ( c->op == LDAP_MOD_DELETE ) {
1770 c->be->be_requires = 0;
1772 requires = verb_to_mask( c->line, requires_ops );
1773 c->be->be_requires ^= requires;
1777 i = verbs_to_mask(c->argc, c->argv, requires_ops, &requires);
1779 sprintf( c->msg, "<%s> unknown feature", c->argv[0] );
1780 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1781 c->log, c->msg, c->argv[i]);
1784 c->be->be_requires = requires;
1789 config_loglevel(ConfigArgs *c) {
1792 slap_verbmasks loglevel_ops[] = {
1793 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
1794 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
1795 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
1796 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
1797 { BER_BVC("BER"), LDAP_DEBUG_BER },
1798 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
1799 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
1800 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
1801 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
1802 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
1803 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
1804 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
1805 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
1806 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
1807 { BER_BVC("Any"), -1 },
1811 if (c->op == SLAP_CONFIG_EMIT) {
1812 return mask_to_verbs( loglevel_ops, ldap_syslog, &c->rvalue_vals );
1813 } else if ( c->op == LDAP_MOD_DELETE ) {
1817 int level = verb_to_mask( c->line, loglevel_ops );
1818 ldap_syslog ^= level;
1825 for( i=1; i < c->argc; i++ ) {
1828 if ( isdigit( c->argv[i][0] ) ) {
1829 level = strtol( c->argv[i], &next, 10 );
1830 if ( next == NULL || next[0] != '\0' ) {
1831 sprintf( c->msg, "<%s> unable to parse level", c->argv[0] );
1832 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1833 c->log, c->msg, c->argv[i]);
1837 int j = verb_to_mask(c->argv[i], loglevel_ops);
1838 if(BER_BVISNULL(&loglevel_ops[j].word)) {
1839 sprintf( c->msg, "<%s> unknown level", c->argv[0] );
1840 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1841 c->log, c->msg, c->argv[i]);
1844 level = loglevel_ops[j].mask;
1846 ldap_syslog |= level;
1852 config_referral(ConfigArgs *c) {
1854 if (c->op == SLAP_CONFIG_EMIT) {
1855 if ( default_referral ) {
1856 value_add( &c->rvalue_vals, default_referral );
1861 } else if ( c->op == LDAP_MOD_DELETE ) {
1862 if ( c->valx < 0 ) {
1863 ber_bvarray_free( default_referral );
1864 default_referral = NULL;
1867 ch_free( default_referral[i].bv_val );
1868 for (; default_referral[i].bv_val; i++ )
1869 default_referral[i] = default_referral[i+1];
1873 if(validate_global_referral(c->argv[1])) {
1874 sprintf( c->msg, "<%s> invalid URL", c->argv[0] );
1875 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1876 c->log, c->msg, c->argv[1]);
1880 ber_str2bv(c->argv[1], 0, 0, &val);
1881 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
1889 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
1890 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
1891 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
1892 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
1893 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
1894 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
1895 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
1896 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
1897 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
1902 config_security(ConfigArgs *c) {
1903 slap_ssf_set_t *set = &c->be->be_ssf_set;
1906 if (c->op == SLAP_CONFIG_EMIT) {
1912 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
1913 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
1916 bv.bv_len = sprintf( numbuf, "%u", *tgt );
1917 bv.bv_len += sec_keys[i].key.bv_len;
1918 bv.bv_val = ch_malloc( bv.bv_len + 1);
1919 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
1920 strcpy( next, numbuf );
1921 ber_bvarray_add( &c->rvalue_vals, &bv );
1926 for(i = 1; i < c->argc; i++) {
1927 slap_ssf_t *tgt = NULL;
1929 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
1930 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
1931 sec_keys[j].key.bv_len)) {
1932 src = c->argv[i] + sec_keys[j].key.bv_len;
1933 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
1938 sprintf( c->msg, "<%s> unknown factor", c->argv[0] );
1939 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1940 c->log, c->msg, c->argv[i]);
1944 *tgt = strtol(src, &next, 10);
1945 if(next == NULL || next[0] != '\0' ) {
1946 sprintf( c->msg, "<%s> unable to parse factor", c->argv[0] );
1947 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1948 c->log, c->msg, c->argv[i]);
1956 anlist_unparse( AttributeName *an, char *ptr ) {
1959 for (; !BER_BVISNULL( &an->an_name ); an++) {
1960 if ( comma ) *ptr++ = ',';
1961 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
1968 replica_unparse( struct slap_replica_info *ri, int i, struct berval *bv )
1972 struct berval bc = {0};
1975 len = sprintf(numbuf, IFMT, i );
1977 len += strlen( ri->ri_uri ) + STRLENOF("uri=");
1978 if ( ri->ri_nsuffix ) {
1979 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
1980 len += ri->ri_nsuffix[i].bv_len + STRLENOF(" suffix=\"\"");
1983 if ( ri->ri_attrs ) {
1984 len += STRLENOF("attr");
1985 if ( ri->ri_exclude ) len++;
1986 for (i=0; !BER_BVISNULL( &ri->ri_attrs[i].an_name ); i++) {
1987 len += 1 + ri->ri_attrs[i].an_name.bv_len;
1990 bindconf_unparse( &ri->ri_bindconf, &bc );
1993 bv->bv_val = ch_malloc(len + 1);
1996 ptr = lutil_strcopy( bv->bv_val, numbuf );
1997 ptr = lutil_strcopy( ptr, "uri=" );
1998 ptr = lutil_strcopy( ptr, ri->ri_uri );
2000 if ( ri->ri_nsuffix ) {
2001 for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) {
2002 ptr = lutil_strcopy( ptr, " suffix=\"" );
2003 ptr = lutil_strcopy( ptr, ri->ri_nsuffix[i].bv_val );
2007 if ( ri->ri_attrs ) {
2008 ptr = lutil_strcopy( ptr, "attr" );
2009 if ( ri->ri_exclude ) *ptr++ = '!';
2011 ptr = anlist_unparse( ri->ri_attrs, ptr );
2014 strcpy( ptr, bc.bv_val );
2015 ch_free( bc.bv_val );
2020 config_replica(ConfigArgs *c) {
2021 int i, nr = -1, len;
2022 char *replicahost, *replicauri;
2025 if (c->op == SLAP_CONFIG_EMIT) {
2026 if (c->be->be_replica) {
2028 for (i=0;c->be->be_replica[i]; i++) {
2029 replica_unparse( c->be->be_replica[i], i, &bv );
2030 ber_bvarray_add( &c->rvalue_vals, &bv );
2035 } else if ( c->op == LDAP_MOD_DELETE ) {
2036 /* FIXME: there is no replica_free function */
2037 if ( c->valx < 0 ) {
2041 if(SLAP_MONITOR(c->be)) {
2042 Debug(LDAP_DEBUG_ANY, "%s: "
2043 "\"replica\" should not be used inside monitor database\n",
2045 return(0); /* FIXME: should this be an error? */
2048 for(i = 1; i < c->argc; i++) {
2049 if(!strncasecmp(c->argv[i], "host=", STRLENOF("host="))) {
2050 replicahost = c->argv[i] + STRLENOF("host=");
2051 len = strlen( replicahost );
2052 replicauri = ch_malloc( len + STRLENOF("ldap://") + 1 );
2053 sprintf( replicauri, "ldap://%s", replicahost );
2054 replicahost = replicauri + STRLENOF( "ldap://");
2055 nr = add_replica_info(c->be, replicauri, replicahost);
2057 } else if(!strncasecmp(c->argv[i], "uri=", STRLENOF("uri="))) {
2058 if(ldap_url_parse(c->argv[i] + STRLENOF("uri="), &ludp) != LDAP_SUCCESS) {
2059 sprintf( c->msg, "<%s> invalid uri", c->argv[0] );
2060 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
2063 if(!ludp->lud_host) {
2064 sprintf( c->msg, "<%s> invalid uri - missing hostname",
2066 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
2069 ldap_free_urldesc(ludp);
2070 replicauri = c->argv[i] + STRLENOF("uri=");
2071 replicauri = ch_strdup( replicauri );
2072 replicahost = strchr( replicauri, '/' );
2074 nr = add_replica_info(c->be, replicauri, replicahost);
2079 sprintf( c->msg, "<%s> missing host or uri", c->argv[0] );
2080 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
2082 } else if(nr == -1) {
2083 sprintf( c->msg, "<%s> unable to add replica", c->argv[0] );
2084 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n", c->log, c->msg, replicauri );
2087 for(i = 1; i < c->argc; i++) {
2088 if(!strncasecmp(c->argv[i], "suffix=", STRLENOF( "suffix="))) {
2089 switch(add_replica_suffix(c->be, nr, c->argv[i] + STRLENOF("suffix="))) {
2091 Debug(LDAP_DEBUG_ANY, "%s: "
2092 "suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
2093 c->log, c->argv[i] + STRLENOF("suffix="), 0);
2096 Debug(LDAP_DEBUG_ANY, "%s: "
2097 "unable to normalize suffix in \"replica\" line (ignored)\n",
2102 } else if(!strncasecmp(c->argv[i], "attr", STRLENOF("attr"))) {
2104 char *arg = c->argv[i] + STRLENOF("attr");
2112 if(add_replica_attrs(c->be, nr, arg + 1, exclude)) {
2113 sprintf( c->msg, "<%s> unknown attribute", c->argv[0] );
2114 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2115 c->log, c->msg, arg + 1);
2118 } else if ( bindconf_parse( c->argv[i],
2119 &c->be->be_replica[nr]->ri_bindconf ) ) {
2128 config_updatedn(ConfigArgs *c) {
2131 if (c->op == SLAP_CONFIG_EMIT) {
2132 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
2133 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
2134 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
2138 } else if ( c->op == LDAP_MOD_DELETE ) {
2139 ch_free( c->be->be_update_ndn.bv_val );
2140 c->be->be_update_ndn.bv_val = NULL;
2141 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
2144 if(SLAP_SHADOW(c->be)) {
2145 sprintf( c->msg, "<%s> database already shadowed", c->argv[0] );
2146 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2151 ber_str2bv(c->argv[1], 0, 0, &dn);
2153 rc = dnNormalize(0, NULL, NULL, &dn, &c->be->be_update_ndn, NULL);
2155 if(rc != LDAP_SUCCESS) {
2156 sprintf( c->msg, "<%s> invalid DN %d (%s)", c->argv[0],
2157 rc, ldap_err2string(rc));
2158 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2159 c->log, c->msg, 0 );
2163 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
2168 config_updateref(ConfigArgs *c) {
2170 if (c->op == SLAP_CONFIG_EMIT) {
2171 if ( c->be->be_update_refs ) {
2172 value_add( &c->rvalue_vals, c->be->be_update_refs );
2177 } else if ( c->op == LDAP_MOD_DELETE ) {
2178 if ( c->valx < 0 ) {
2179 ber_bvarray_free( c->be->be_update_refs );
2180 c->be->be_update_refs = NULL;
2183 ch_free( c->be->be_update_refs[i].bv_val );
2184 for (; c->be->be_update_refs[i].bv_val; i++)
2185 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
2189 if(!SLAP_SHADOW(c->be)) {
2190 sprintf( c->msg, "<%s> must appear after syncrepl or updatedn",
2192 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2197 if(validate_global_referral(c->argv[1])) {
2198 sprintf( c->msg, "<%s> invalid URL", c->argv[0] );
2199 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2200 c->log, c->msg, c->argv[1]);
2203 ber_str2bv(c->argv[1], 0, 0, &val);
2204 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
2209 config_include(ConfigArgs *c) {
2210 unsigned long savelineno = c->lineno;
2213 ConfigFile *cfsave = cfn;
2214 ConfigFile *cf2 = NULL;
2215 if (c->op == SLAP_CONFIG_EMIT) {
2217 ConfigFile *cf = c->private;
2218 value_add_one( &c->rvalue_vals, &cf->c_file );
2222 } else if ( c->op == LDAP_MOD_DELETE ) {
2224 cf = ch_calloc( 1, sizeof(ConfigFile));
2225 if ( cfn->c_kids ) {
2226 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
2232 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
2233 rc = read_config_file(c->argv[1], c->depth + 1, c);
2234 c->lineno = savelineno - 1;
2237 if ( cf2 ) cf2->c_sibs = NULL;
2238 else cfn->c_kids = NULL;
2239 ch_free( cf->c_file.bv_val );
2249 config_tls_option(ConfigArgs *c) {
2252 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; break;
2253 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
2254 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
2255 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
2256 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
2257 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
2258 default: Debug(LDAP_DEBUG_ANY, "%s: "
2259 "unknown tls_option <0x%x>\n",
2260 c->log, c->type, 0);
2262 if (c->op == SLAP_CONFIG_EMIT) {
2263 return ldap_pvt_tls_get_option( NULL, flag, &c->value_string );
2264 } else if ( c->op == LDAP_MOD_DELETE ) {
2265 return ldap_pvt_tls_set_option( NULL, flag, NULL );
2267 ch_free(c->value_string);
2268 return(ldap_pvt_tls_set_option(NULL, flag, c->argv[1]));
2271 /* FIXME: this ought to be provided by libldap */
2273 config_tls_config(ConfigArgs *c) {
2275 slap_verbmasks crlkeys[] = {
2276 { BER_BVC("none"), LDAP_OPT_X_TLS_CRL_NONE },
2277 { BER_BVC("peer"), LDAP_OPT_X_TLS_CRL_PEER },
2278 { BER_BVC("all"), LDAP_OPT_X_TLS_CRL_ALL },
2281 slap_verbmasks vfykeys[] = {
2282 { BER_BVC("never"), LDAP_OPT_X_TLS_NEVER },
2283 { BER_BVC("demand"), LDAP_OPT_X_TLS_DEMAND },
2284 { BER_BVC("try"), LDAP_OPT_X_TLS_TRY },
2285 { BER_BVC("hard"), LDAP_OPT_X_TLS_HARD },
2289 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; keys = crlkeys; break;
2290 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; keys = vfykeys; break;
2292 Debug(LDAP_DEBUG_ANY, "%s: "
2293 "unknown tls_option <0x%x>\n",
2294 c->log, c->type, 0);
2296 if (c->op == SLAP_CONFIG_EMIT) {
2297 ldap_pvt_tls_get_option( NULL, flag, &c->value_int );
2298 for (i=0; !BER_BVISNULL(&keys[i].word); i++) {
2299 if (keys[i].mask == c->value_int) {
2300 c->value_string = ch_strdup( keys[i].word.bv_val );
2305 } else if ( c->op == LDAP_MOD_DELETE ) {
2307 return ldap_pvt_tls_set_option( NULL, flag, &i );
2309 ch_free( c->value_string );
2310 if(isdigit((unsigned char)c->argv[1][0])) {
2311 i = atoi(c->argv[1]);
2312 return(ldap_pvt_tls_set_option(NULL, flag, &i));
2314 return(ldap_int_tls_config(NULL, flag, c->argv[1]));
2319 static CfEntryInfo *
2320 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
2330 if ( dn_match( &root->ce_entry->e_nname, dn ))
2333 c = dn->bv_val+dn->bv_len;
2334 for (;*c != ',';c--);
2338 for (--c;c>dn->bv_val && *c != ',';c--);
2342 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
2344 root = root->ce_kids;
2346 for (;root;root=root->ce_sibs) {
2347 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
2348 if ( cdn.bv_val == dn->bv_val ) {
2359 config_ldif_resp( Operation *op, SlapReply *rs )
2361 if ( rs->sr_type == REP_SEARCH ) {
2362 CfBackInfo *cfb = op->o_callback->sc_private;
2364 cfb->cb_got_ldif = 1;
2365 rs->sr_err = config_add_internal( cfb, rs->sr_entry, NULL, NULL );
2370 /* Configure and read the underlying back-ldif store */
2372 config_setup_ldif( BackendDB *be, const char *dir ) {
2373 CfBackInfo *cfb = be->be_private;
2378 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
2379 Connection conn = {0};
2380 char opbuf[OPERATION_BUFFER_SIZE];
2382 SlapReply rs = {REP_RESULT};
2383 Filter filter = { LDAP_FILTER_PRESENT };
2384 struct berval filterstr = BER_BVC("(objectclass=*)");
2387 /* Is the config directory available? */
2388 if ( stat( dir, &st ) < 0 ) {
2389 /* No, so don't bother using the backing store.
2390 * All changes will be in-memory only.
2395 cfb->cb_db.bd_info = backend_info( "ldif" );
2396 if ( !cfb->cb_db.bd_info )
2397 return 0; /* FIXME: eventually this will be a fatal error */
2399 if ( cfb->cb_db.bd_info->bi_db_init( &cfb->cb_db )) return 1;
2401 /* Mark that back-ldif type is in use */
2402 cfb->cb_db.bd_info->bi_nDB++;
2404 cfb->cb_db.be_suffix = be->be_suffix;
2405 cfb->cb_db.be_nsuffix = be->be_nsuffix;
2406 cfb->cb_db.be_rootdn = be->be_rootdn;
2407 cfb->cb_db.be_rootndn = be->be_rootndn;
2409 ber_str2bv( dir, 0, 1, &cfdir );
2414 argv[0] = "directory";
2415 argv[1] = (char *)dir;
2419 ct = config_find_keyword( c.be->be_cf_table, &c );
2423 if ( config_add_vals( ct, &c ))
2426 if ( backend_startup_one( &cfb->cb_db ))
2429 op = (Operation *)opbuf;
2430 connection_fake_init( &conn, op, cfb );
2432 filter.f_desc = slap_schema.si_ad_objectClass;
2434 op->o_tag = LDAP_REQ_SEARCH;
2436 op->ors_filter = &filter;
2437 op->ors_filterstr = filterstr;
2438 op->ors_scope = LDAP_SCOPE_SUBTREE;
2440 op->o_dn = be->be_rootdn;
2441 op->o_ndn = be->be_rootndn;
2443 op->o_req_dn = be->be_suffix[0];
2444 op->o_req_ndn = be->be_nsuffix[0];
2446 op->ors_tlimit = SLAP_NO_LIMIT;
2447 op->ors_slimit = SLAP_NO_LIMIT;
2449 op->ors_attrs = slap_anlist_all_attributes;
2450 op->ors_attrsonly = 0;
2452 op->o_callback = &cb;
2453 cb.sc_private = cfb;
2455 op->o_bd = &cfb->cb_db;
2456 op->o_bd->be_search( op, &rs );
2458 cfb->cb_use_ldif = 1;
2464 CfOcInfo_cmp( const void *c1, const void *c2 ) {
2465 const CfOcInfo *co1 = c1;
2466 const CfOcInfo *co2 = c2;
2468 return ber_bvcmp( co1->co_name, co2->co_name );
2472 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
2476 i = init_config_attrs( ct );
2479 /* set up the objectclasses */
2480 i = init_config_ocs( ocs );
2483 for (i=0; ocs[i].def; i++) {
2485 co = ch_malloc( sizeof(CfOcInfo) );
2486 co->co_oc = *ocs[i].oc;
2487 co->co_name = &co->co_oc->soc_cname;
2489 co->co_type = ocs[i].cft;
2490 avl_insert( &CfOcTree, co, CfOcInfo_cmp, avl_dup_error );
2497 read_config(const char *fname, const char *dir) {
2501 /* Setup the config backend */
2502 be = backend_db_init( "config" );
2506 cfb = be->be_private;
2508 /* Setup the underlying back-ldif backend */
2509 if ( config_setup_ldif( be, dir ))
2512 #ifdef SLAP_USE_CONFDIR
2513 /* If we read the config from back-ldif, nothing to do here */
2514 if ( cfb->cb_got_ldif )
2517 ber_str2bv( fname, 0, 1, &cf_prv.c_file );
2519 return read_config_file(fname, 0, NULL);
2523 config_back_bind( Operation *op, SlapReply *rs )
2525 if ( op->orb_method == LDAP_AUTH_SIMPLE && be_isroot_pw( op )) {
2526 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
2527 /* frontend sends result */
2528 return LDAP_SUCCESS;
2531 rs->sr_err = LDAP_INVALID_CREDENTIALS;
2532 send_ldap_result( op, rs );
2538 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
2542 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
2544 rs->sr_attrs = op->ors_attrs;
2545 rs->sr_entry = ce->ce_entry;
2546 rc = send_search_entry( op, rs );
2548 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
2549 if ( ce->ce_kids ) {
2550 rc = config_send( op, rs, ce->ce_kids, 1 );
2551 if ( rc ) return rc;
2554 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
2555 rc = config_send( op, rs, ce, 0 );
2563 static ConfigTable *
2564 config_find_table( CfOcInfo **colst, int nocs, AttributeDescription *ad )
2568 for (j=0; j<nocs; j++) {
2569 for (i=0; colst[j]->co_table[i].name; i++)
2570 if ( colst[j]->co_table[i].ad == ad )
2571 return &colst[j]->co_table[i];
2576 /* Sort the attributes of the entry according to the order defined
2577 * in the objectclass, with required attributes occurring before
2578 * allowed attributes. For any attributes with sequencing dependencies
2579 * (e.g., rootDN must be defined after suffix) the objectclass must
2580 * list the attributes in the desired sequence.
2583 sort_attrs( Entry *e, CfOcInfo **colst, int nocs )
2585 Attribute *a, *head = NULL, *tail = NULL, **prev;
2588 for (i=0; i<nocs; i++) {
2589 if ( colst[i]->co_oc->soc_required ) {
2590 AttributeType **at = colst[i]->co_oc->soc_required;
2591 for (j=0; at[j]; j++) {
2592 for (a=e->e_attrs, prev=&e->e_attrs; a;
2593 prev = &(*prev)->a_next, a=a->a_next) {
2594 if ( a->a_desc == at[j]->sat_ad ) {
2608 if ( colst[i]->co_oc->soc_allowed ) {
2609 AttributeType **at = colst[i]->co_oc->soc_allowed;
2610 for (j=0; at[j]; j++) {
2611 for (a=e->e_attrs, prev=&e->e_attrs; a;
2612 prev = &(*prev)->a_next, a=a->a_next) {
2613 if ( a->a_desc == at[j]->sat_ad ) {
2629 tail->a_next = e->e_attrs;
2635 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
2637 Attribute *a = NULL;
2638 AttributeDescription *ad;
2641 int i, rc = 0, sort = 0;
2648 Modifications *ml = ptr;
2650 vals = ml->sml_values;
2653 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
2655 rc = ordered_value_sort( a, 1 );
2659 for ( i=0; vals[i].bv_val; i++ ) {
2660 ca->line = vals[i].bv_val;
2662 char *idx = strchr( ca->line, '}' );
2663 if ( idx ) ca->line = idx+1;
2665 rc = config_parse_vals( ct, ca, i );
2673 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
2674 SlapReply *rs, int *renum )
2677 int index = -1, gotindex = 0, nsibs;
2678 int renumber = 0, tailindex = 0;
2682 if ( renum ) *renum = 0;
2684 /* These entries don't get indexed/renumbered */
2685 if ( ce_type == Cft_Global ) return 0;
2686 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
2688 if ( ce_type == Cft_Include || ce_type == Cft_Module )
2691 /* See if the rdn has an index already */
2692 dnRdn( &e->e_name, &rdn );
2693 ptr1 = strchr( e->e_name.bv_val, '{' );
2694 if ( ptr1 && ptr1 - e->e_name.bv_val < rdn.bv_len ) {
2695 ptr2 = strchr( ptr1, '}' );
2696 if (!ptr2 || ptr2 - e->e_name.bv_val > rdn.bv_len)
2697 return LDAP_NAMING_VIOLATION;
2698 if ( ptr2-ptr1 == 1)
2699 return LDAP_NAMING_VIOLATION;
2701 index = atoi(ptr1+1);
2703 return LDAP_NAMING_VIOLATION;
2706 /* count related kids */
2707 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
2708 if ( ce->ce_type == ce_type ) nsibs++;
2711 if ( index != nsibs ) {
2713 if ( index < nsibs ) {
2714 if ( tailindex ) return LDAP_NAMING_VIOLATION;
2715 /* Siblings need to be renumbered */
2720 struct berval ival, newrdn, nnewrdn;
2721 struct berval rtype, rval;
2723 AttributeDescription *ad = NULL;
2727 rval.bv_val = strchr(rdn.bv_val, '=' ) + 1;
2728 rval.bv_len = rdn.bv_len - (rval.bv_val - rdn.bv_val);
2729 rtype.bv_val = rdn.bv_val;
2730 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
2733 slap_bv2ad( &rtype, &ad, &text );
2734 a = attr_find( e->e_attrs, ad );
2735 if (!a ) return LDAP_NAMING_VIOLATION;
2738 ival.bv_len = sprintf( ibuf, IFMT, nsibs );
2740 newrdn.bv_len = rdn.bv_len + ival.bv_len;
2741 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
2744 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
2745 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
2752 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
2754 ptr1 = lutil_strncopy( newrdn.bv_val, rtype.bv_val,
2757 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
2758 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
2762 /* Do the equivalent of ModRDN */
2763 /* Replace DN / NDN */
2764 newrdn.bv_len = ptr1 - newrdn.bv_val;
2765 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
2766 free( e->e_name.bv_val );
2767 build_new_dn( &e->e_name, &parent->ce_entry->e_name,
2769 free( e->e_nname.bv_val );
2770 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname,
2774 free( a->a_vals[0].bv_val );
2775 ptr1 = strchr( newrdn.bv_val, '=' ) + 1;
2776 a->a_vals[0].bv_len = newrdn.bv_len - (ptr1 - newrdn.bv_val);
2777 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
2778 strcpy( a->a_vals[0].bv_val, ptr1 );
2780 if ( a->a_nvals != a->a_vals ) {
2781 free( a->a_nvals[0].bv_val );
2782 ptr1 = strchr( nnewrdn.bv_val, '=' ) + 1;
2783 a->a_nvals[0].bv_len = nnewrdn.bv_len - (ptr1 - nnewrdn.bv_val);
2784 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
2785 strcpy( a->a_nvals[0].bv_val, ptr1 );
2787 free( nnewrdn.bv_val );
2788 free( newrdn.bv_val );
2791 if ( renum ) *renum = renumber;
2796 count_ocs( Attribute *oc_at, int *nocs )
2799 CfOcInfo co, *coptr, **colst;
2801 /* count the objectclasses */
2802 for ( i=0; oc_at->a_nvals[i].bv_val; i++ );
2804 colst = (CfOcInfo **)ch_malloc( n * sizeof(CfOcInfo *));
2806 for ( i=0, j=0; i<n; i++) {
2807 co.co_name = &oc_at->a_nvals[i];
2808 coptr = avl_find( CfOcTree, &co, CfOcInfo_cmp );
2810 /* ignore non-config objectclasses. probably should be
2811 * an error, general data doesn't belong here.
2813 if ( !coptr ) continue;
2815 /* Ignore the root objectclass, it has no implementation.
2817 if ( coptr->co_type == Cft_Abstract ) continue;
2824 /* Parse an LDAP entry into config directives */
2826 config_add_internal( CfBackInfo *cfb, Entry *e, SlapReply *rs, int *renum )
2828 CfEntryInfo *ce, *last;
2830 Attribute *a, *oc_at, *type_attr;
2831 AttributeDescription *type_ad = NULL;
2833 ConfigArgs ca = {0};
2835 ConfigTable *ct, *type_ct = NULL;
2838 /* Make sure parent exists and entry does not */
2839 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
2841 return LDAP_ALREADY_EXISTS;
2843 dnParent( &e->e_nname, &pdn );
2845 /* If last is NULL, the new entry is the root/suffix entry,
2846 * otherwise last should be the parent.
2848 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn )) {
2850 rs->sr_matched = last->ce_entry->e_name.bv_val;
2851 return LDAP_NO_SUCH_OBJECT;
2854 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
2855 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
2857 colst = count_ocs( oc_at, &nocs );
2859 /* Only the root can be Cft_Global, everything else must
2860 * have a parent. Only limited nesting arrangements are allowed.
2862 switch( colst[0]->co_type ) {
2865 rc = LDAP_CONSTRAINT_VIOLATION;
2873 if ( !last || ( last->ce_type != Cft_Global &&
2874 last->ce_type != colst[0]->co_type )) {
2875 rc = LDAP_CONSTRAINT_VIOLATION;
2880 if ( !last || ( last->ce_type != Cft_Global &&
2881 last->ce_type != Cft_Database &&
2882 last->ce_type != colst[0]->co_type )) {
2883 rc = LDAP_CONSTRAINT_VIOLATION;
2887 #ifdef SLAPD_MODULES
2889 if ( !last || last->ce_type != Cft_Global ) {
2890 rc = LDAP_CONSTRAINT_VIOLATION;
2897 sort_attrs( e, colst, nocs );
2899 /* Parse all the values and check for simple syntax errors before
2900 * performing any set actions.
2902 switch (colst[0]->co_type) {
2904 /* The cn=schema entry is all hardcoded, so never reparse it */
2905 if (last->ce_type == Cft_Global )
2908 ca.private = ch_calloc( 1, sizeof(ConfigFile) );
2911 ca.be = LDAP_STAILQ_FIRST(&backendDB);
2915 if ( last->ce_type == Cft_Backend )
2916 ca.bi = last->ce_bi;
2918 type_ad = cfAd_backend;
2921 if ( last->ce_type == Cft_Database ) {
2922 ca.be = last->ce_be;
2924 type_ad = cfAd_database;
2925 /* dummy, just to get past check_attr */
2931 ca.be = last->ce_be;
2932 type_ad = cfAd_overlay;
2937 nocs = 0; /* ignored */
2940 if ( last->ce_type == Cft_Global )
2943 cfn = last->ce_private;
2944 type_ad = cfAd_include;
2946 #ifdef SLAPD_MODULES
2951 ptr = strchr( e->e_name.bv_val, '{' );
2953 rc = LDAP_NAMING_VIOLATION;
2957 for (i=0, mp=&modpaths; mp && i<j; mp=mp->mp_next);
2958 /* There is no corresponding modpath for this load? */
2960 rc = LDAP_NAMING_VIOLATION;
2963 module_path( mp->mp_path.bv_val );
2971 /* If doing an LDAPadd, check for indexed names and any necessary
2972 * renaming/renumbering. Entries that don't need indexed names are
2973 * ignored. Entries that need an indexed name and arrive without one
2974 * are assigned to the end. Entries that arrive with an index may
2975 * cause the following entries to be renumbered/bumped down.
2977 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
2978 * don't allow Adding an entry with an index that's already in use.
2979 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
2981 * These entries can have auto-assigned indexes (appended to the end)
2982 * but only the other types support auto-renumbering of siblings.
2984 rc = check_name_index( last, colst[0]->co_type, e, rs, renum );
2988 init_config_argv( &ca );
2990 type_attr = attr_find( e->e_attrs, type_ad );
2992 rc = LDAP_OBJECT_CLASS_VIOLATION;
2995 type_ct = config_find_table( colst, nocs, type_ad );
2997 rc = LDAP_OBJECT_CLASS_VIOLATION;
3000 rc = check_vals( type_ct, &ca, type_attr, 1);
3001 if ( rc ) goto leave;
3003 for ( a=e->e_attrs; a; a=a->a_next ) {
3004 if ( a == type_attr || a == oc_at ) continue;
3005 ct = config_find_table( colst, nocs, a->a_desc );
3006 if ( !ct ) continue; /* user data? */
3007 rc = check_vals( ct, &ca, a, 1 );
3008 if ( rc ) goto leave;
3011 /* Basic syntax checks are OK. Do the actual settings. */
3013 ca.line = type_attr->a_vals[0].bv_val;
3014 if ( type_ad->ad_type->sat_flags & SLAP_AT_ORDERED ) {
3015 ptr = strchr( ca.line, '}' );
3016 if ( ptr ) ca.line = ptr+1;
3019 rc = config_parse_add( type_ct, &ca );
3025 for ( a=e->e_attrs; a; a=a->a_next ) {
3026 if ( a == type_attr || a == oc_at ) continue;
3027 ct = config_find_table( colst, nocs, a->a_desc );
3028 if ( !ct ) continue; /* user data? */
3029 for (i=0; a->a_vals[i].bv_val; i++) {
3030 ca.line = a->a_vals[i].bv_val;
3031 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
3032 ptr = strchr( ca.line, '}' );
3033 if ( ptr ) ca.line = ptr+1;
3036 rc = config_parse_add( ct, &ca );
3044 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
3045 ce->ce_parent = last;
3046 ce->ce_entry = entry_dup( e );
3047 ce->ce_entry->e_private = ce;
3048 ce->ce_type = colst[0]->co_type;
3051 ce->ce_private = ca.private;
3054 } else if ( last->ce_kids ) {
3057 for (c2=last->ce_kids; c2 && c2->ce_sibs; c2 = c2->ce_sibs);
3066 if ( colst ) ch_free( colst );
3070 /* Parse an LDAP entry into config directives, then store in underlying
3074 config_back_add( Operation *op, SlapReply *rs )
3077 CfEntryInfo *ce, *last;
3080 if ( !be_isroot( op ) ) {
3081 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3085 cfb = (CfBackInfo *)op->o_bd->be_private;
3087 ldap_pvt_thread_pool_pause( &connection_pool );
3090 * 1) check for existence of entry
3091 * 2) check for sibling renumbering
3092 * 3) perform internal add
3093 * 4) store entry in underlying database
3094 * 5) perform any necessary renumbering
3096 rs->sr_err = config_add_internal( cfb, op->ora_e, rs, &renumber );
3097 if ( rs->sr_err == LDAP_SUCCESS && cfb->cb_use_ldif ) {
3098 BackendDB *be = op->o_bd;
3099 slap_callback sc = { NULL, slap_null_cb, NULL, NULL };
3100 op->o_bd = &cfb->cb_db;
3101 sc.sc_next = op->o_callback;
3102 op->o_callback = ≻
3103 op->o_bd->be_add( op, rs );
3105 op->o_callback = sc.sc_next;
3110 ldap_pvt_thread_pool_resume( &connection_pool );
3113 send_ldap_result( op, rs );
3117 typedef struct delrec {
3118 struct delrec *next;
3124 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
3127 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
3128 int rc = LDAP_UNWILLING_TO_PERFORM;
3130 Entry *e = ce->ce_entry;
3131 Attribute *save_attrs = e->e_attrs, *oc_at;
3136 delrec *dels = NULL, *deltail = NULL;
3138 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
3139 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
3141 colst = count_ocs( oc_at, &nocs );
3143 e->e_attrs = attrs_dup( e->e_attrs );
3145 init_config_argv( ca );
3148 ca->private = ce->ce_private;
3149 strcpy( ca->log, "back-config" );
3151 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
3152 ct = config_find_table( colst, nocs, ml->sml_desc );
3153 switch (ml->sml_op) {
3154 case LDAP_MOD_DELETE:
3155 case LDAP_MOD_REPLACE: {
3156 BerVarray vals = NULL, nvals;
3158 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
3160 snprintf( ca->msg, sizeof(ca->msg),
3161 "<%s> cannot be deleted" );
3162 snprintf(ca->msg, sizeof(ca->msg), "cannot delete %s",
3163 ml->sml_desc->ad_cname.bv_val );
3166 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3167 vals = ml->sml_values;
3168 nvals = ml->sml_nvalues;
3169 ml->sml_values = NULL;
3170 ml->sml_nvalues = NULL;
3172 /* If we're deleting by values, remember the indexes of the
3173 * values we deleted.
3175 if ( ct && ml->sml_values ) {
3177 for (i=0; ml->sml_values[i].bv_val; i++);
3178 d = ch_malloc( sizeof(delrec) + i * sizeof(int));
3189 rc = modify_delete_vindex(e, &ml->sml_mod,
3190 get_permissiveModify(op),
3191 &rs->sr_text, ca->msg, sizeof(ca->msg), idx );
3192 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3193 ml->sml_values = vals;
3194 ml->sml_nvalues = nvals;
3199 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
3202 case SLAP_MOD_SOFTADD: {
3203 int mop = ml->sml_op;
3205 ml->sml_op = LDAP_MOD_ADD;
3207 if ( ct->arg_type & ARG_NO_INSERT ) {
3208 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
3210 for (i = 0; a->a_vals[i].bv_val; i++ );
3214 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
3215 if ( ml->sml_values[i].bv_val[0] == '{' &&
3217 int j = strtol( ml->sml_values[i].bv_val+1, NULL, 0 );
3220 snprintf(ca->msg, sizeof(ca->msg), "cannot insert %s",
3221 ml->sml_desc->ad_cname.bv_val );
3225 rc = check_vals( ct, ca, ml, 0 );
3229 rc = modify_add_values(e, &ml->sml_mod,
3230 get_permissiveModify(op),
3231 &rs->sr_text, ca->msg, sizeof(ca->msg) );
3233 /* If value already exists, show success here
3234 * and ignore this operation down below.
3236 if ( mop == SLAP_MOD_SOFTADD ) {
3237 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
3247 case LDAP_MOD_INCREMENT: /* FIXME */
3252 if(rc != LDAP_SUCCESS) break;
3255 if(rc == LDAP_SUCCESS) {
3256 /* check that the entry still obeys the schema */
3257 rc = entry_schema_check(op->o_bd, e, NULL,
3258 &rs->sr_text, ca->msg, sizeof(ca->msg) );
3260 if ( rc == LDAP_SUCCESS ) {
3261 /* Basic syntax checks are OK. Do the actual settings. */
3262 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
3263 ct = config_find_table( colst, nocs, ml->sml_desc );
3264 if ( !ct ) continue;
3266 switch (ml->sml_op) {
3267 case LDAP_MOD_DELETE:
3268 case LDAP_MOD_REPLACE: {
3269 BerVarray vals = NULL, nvals;
3273 a = attr_find( e->e_attrs, ml->sml_desc );
3275 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3276 vals = ml->sml_values;
3277 nvals = ml->sml_nvalues;
3278 ml->sml_values = NULL;
3279 ml->sml_nvalues = NULL;
3282 if ( ml->sml_values )
3285 /* If we didn't delete the whole attribute */
3286 if ( ml->sml_values && a ) {
3287 struct berval *mvals;
3290 if ( ml->sml_nvalues )
3291 mvals = ml->sml_nvalues;
3293 mvals = ml->sml_values;
3295 /* use the indexes we saved up above */
3296 for (i=0; i < d->nidx; i++) {
3297 struct berval bv = *mvals++;
3298 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
3299 bv.bv_val[0] == '{' ) {
3300 ptr = strchr( bv.bv_val, '}' ) + 1;
3301 bv.bv_len -= ptr - bv.bv_val;
3304 ca->line = bv.bv_val;
3305 ca->valx = d->idx[i];
3306 rc = config_del_vals( ct, ca );
3307 if ( rc != LDAP_SUCCESS ) break;
3308 for (j=i+1; j < d->nidx; j++)
3309 if ( d->idx[j] >d->idx[i] )
3315 rc = config_del_vals( ct, ca );
3316 if ( rc ) rc = LDAP_OTHER;
3318 if ( ml->sml_values ) {
3322 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3323 ml->sml_values = vals;
3324 ml->sml_nvalues = nvals;
3326 if ( !vals || rc != LDAP_SUCCESS )
3329 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
3332 for (i=0; ml->sml_values[i].bv_val; i++) {
3333 ca->line = ml->sml_values[i].bv_val;
3335 if ( ml->sml_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
3336 ca->line[0] == '{' ) {
3337 ptr = strchr( ca->line, '}' );
3339 ca->valx = strtol( ca->line+1, NULL, 0 );
3343 rc = config_parse_add( ct, ca );
3358 if ( rc == LDAP_SUCCESS ) {
3359 attrs_free( save_attrs );
3361 attrs_free( e->e_attrs );
3362 e->e_attrs = save_attrs;
3364 ch_free( ca->argv );
3365 if ( colst ) ch_free( colst );
3371 config_back_modify( Operation *op, SlapReply *rs )
3374 CfEntryInfo *ce, *last;
3376 ConfigArgs ca = {0};
3379 AttributeDescription *rad = NULL;
3381 if ( !be_isroot( op ) ) {
3382 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3386 cfb = (CfBackInfo *)op->o_bd->be_private;
3388 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3391 rs->sr_matched = last->ce_entry->e_name.bv_val;
3392 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3396 /* Get type of RDN */
3397 rdn = ce->ce_entry->e_nname;
3398 ptr = strchr( rdn.bv_val, '=' );
3399 rdn.bv_len = ptr - rdn.bv_val;
3400 slap_bv2ad( &rdn, &rad, &rs->sr_text );
3402 /* Some basic validation... */
3403 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
3404 /* Don't allow Modify of RDN; must use ModRdn for that. */
3405 if ( ml->sml_desc == rad ) {
3406 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
3407 rs->sr_text = "Use modrdn to change the entry name";
3412 ldap_pvt_thread_pool_pause( &connection_pool );
3415 * 1) perform the Modify on the cached Entry.
3416 * 2) verify that the Entry still satisfies the schema.
3417 * 3) perform the individual config operations.
3418 * 4) store Modified entry in underlying LDIF backend.
3420 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
3422 rs->sr_text = ca.msg;
3423 } else if ( cfb->cb_use_ldif ) {
3424 BackendDB *be = op->o_bd;
3425 slap_callback sc = { NULL, slap_null_cb, NULL, NULL };
3426 op->o_bd = &cfb->cb_db;
3427 sc.sc_next = op->o_callback;
3428 op->o_callback = ≻
3429 op->o_bd->be_modify( op, rs );
3431 op->o_callback = sc.sc_next;
3434 ldap_pvt_thread_pool_resume( &connection_pool );
3436 send_ldap_result( op, rs );
3441 config_back_modrdn( Operation *op, SlapReply *rs )
3444 CfEntryInfo *ce, *last;
3446 if ( !be_isroot( op ) ) {
3447 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3451 cfb = (CfBackInfo *)op->o_bd->be_private;
3453 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3456 rs->sr_matched = last->ce_entry->e_name.bv_val;
3457 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3461 /* We don't allow moving objects to new parents.
3462 * Generally we only allow reordering a set of ordered entries.
3464 if ( op->orr_newSup ) {
3465 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
3468 ldap_pvt_thread_pool_pause( &connection_pool );
3470 ldap_pvt_thread_pool_resume( &connection_pool );
3472 send_ldap_result( op, rs );
3477 config_back_search( Operation *op, SlapReply *rs )
3480 CfEntryInfo *ce, *last;
3483 if ( !be_isroot( op ) ) {
3484 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3488 cfb = (CfBackInfo *)op->o_bd->be_private;
3490 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3493 rs->sr_matched = last->ce_entry->e_name.bv_val;
3494 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3497 switch ( op->ors_scope ) {
3498 case LDAP_SCOPE_BASE:
3499 case LDAP_SCOPE_SUBTREE:
3500 config_send( op, rs, ce, 0 );
3503 case LDAP_SCOPE_ONELEVEL:
3504 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
3505 config_send( op, rs, ce, 1 );
3510 rs->sr_err = LDAP_SUCCESS;
3512 send_ldap_result( op, rs );
3517 config_alloc_entry( CfEntryInfo *parent, struct berval *rdn )
3519 Entry *e = ch_calloc( 1, sizeof(Entry) );
3520 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
3525 ce->ce_parent = parent;
3527 pdn = parent->ce_entry->e_nname;
3532 build_new_dn( &e->e_name, &pdn, rdn, NULL );
3533 ber_dupbv( &e->e_nname, &e->e_name );
3542 config_build_entry( ConfigArgs *c, Entry *e, ObjectClass *oc,
3543 struct berval *rdn, ConfigTable *ct, int table )
3546 struct berval ad_name;
3547 AttributeDescription *ad = NULL;
3554 val = oc->soc_cname;
3555 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass, &val, NULL );
3556 ptr = strchr(rdn->bv_val, '=');
3557 ad_name.bv_val = rdn->bv_val;
3558 ad_name.bv_len = ptr - rdn->bv_val;
3559 rc = slap_bv2ad( &ad_name, &ad, &text );
3564 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
3565 attr_merge_normalize_one(e, ad, &val, NULL );
3567 for (at=oc->soc_required; at && *at; at++) {
3568 /* Skip the naming attr */
3569 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
3571 for (i=0;ct[i].name;i++) {
3572 if (ct[i].ad == (*at)->sat_ad) {
3573 rc = config_get_vals(&ct[i], c);
3574 if (rc == LDAP_SUCCESS) {
3575 if ( c->rvalue_nvals )
3576 attr_merge(e, ct[i].ad, c->rvalue_vals,
3579 attr_merge_normalize(e, ct[i].ad,
3580 c->rvalue_vals, NULL);
3581 ber_bvarray_free( c->rvalue_nvals );
3582 ber_bvarray_free( c->rvalue_vals );
3589 for (at=oc->soc_allowed; at && *at; at++) {
3590 /* Skip the naming attr */
3591 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
3593 for (i=0;ct[i].name;i++) {
3594 if (ct[i].ad == (*at)->sat_ad) {
3595 rc = config_get_vals(&ct[i], c);
3596 if (rc == LDAP_SUCCESS) {
3597 if ( c->rvalue_nvals )
3598 attr_merge(e, ct[i].ad, c->rvalue_vals, c->rvalue_nvals);
3600 attr_merge_normalize(e, ct[i].ad, c->rvalue_vals, NULL);
3601 ber_bvarray_free( c->rvalue_nvals );
3602 ber_bvarray_free( c->rvalue_vals );
3610 if ( table == BI_TABLE )
3611 ct = c->bi->bi_cf_table;
3613 ct = c->be->be_cf_table;
3614 for (;ct && ct->name;ct++) {
3615 if (!ct->ad) continue;
3616 rc = config_get_vals(ct, c);
3617 if (rc == LDAP_SUCCESS) {
3618 if ( c->rvalue_nvals )
3619 attr_merge(e, ct->ad, c->rvalue_vals, c->rvalue_nvals);
3621 attr_merge_normalize(e, ct->ad, c->rvalue_vals, NULL);
3625 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
3626 rc = structural_class(oc_at->a_vals, &val, NULL, &text, c->msg,
3628 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &val, NULL );
3634 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
3635 Operation *op, SlapReply *rs )
3638 ConfigFile *cf = c->private;
3639 CfEntryInfo *ce, *ceprev;
3643 if ( ceparent->ce_kids ) {
3644 for ( ceprev = ceparent->ce_kids; ceprev->ce_sibs;
3645 ceprev = ceprev->ce_sibs );
3648 for (; cf; cf=cf->c_sibs, c->depth++) {
3649 c->value_dn.bv_val = c->log;
3650 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
3655 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
3657 ptr = strchr( bv.bv_val, '.' );
3659 bv.bv_len = ptr - bv.bv_val;
3660 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=" IFMT, c->depth);
3661 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
3663 c->value_dn.bv_len += bv.bv_len;
3664 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
3666 e = config_alloc_entry( ceparent, &c->value_dn );
3668 config_build_entry( c, e, cfOc_schema, &c->value_dn,
3669 c->bi->bi_cf_table, NO_TABLE );
3671 ce->ce_private = cf;
3672 ce->ce_type = Cft_Schema;
3675 op->o_bd->be_add( op, rs );
3678 if ( !ceparent->ce_kids ) {
3679 ceparent->ce_kids = ce;
3681 ceprev->ce_sibs = ce;
3685 c->private = cf->c_kids;
3686 config_build_schema_inc( c, ceparent, op, rs );
3691 static CfEntryInfo *
3692 config_build_includes( ConfigArgs *c, CfEntryInfo *ceparent,
3693 Operation *op, SlapReply *rs )
3697 ConfigFile *cf = c->private;
3698 CfEntryInfo *ce, *ceprev;
3700 if ( ceparent->ce_kids ) {
3701 for ( ceprev = ceparent->ce_kids; ceprev->ce_sibs;
3702 ceprev = ceprev->ce_sibs );
3705 for (i=0; cf; cf=cf->c_sibs, i++) {
3706 c->value_dn.bv_val = c->log;
3707 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=include" IFMT, i);
3708 e = config_alloc_entry( ceparent, &c->value_dn );
3710 config_build_entry( c, e, cfOc_include, &c->value_dn,
3711 c->bi->bi_cf_table, NO_TABLE );
3714 op->o_bd->be_add( op, rs );
3717 ce->ce_private = cf;
3718 ce->ce_type = Cft_Include;
3720 if ( !ceparent->ce_kids ) {
3721 ceparent->ce_kids = ce;
3723 ceprev->ce_sibs = ce;
3727 c->private = cf->c_kids;
3728 config_build_includes( c, ce, op, rs );
3734 #ifdef SLAPD_MODULES
3736 static CfEntryInfo *
3737 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
3738 Operation *op, SlapReply *rs )
3742 CfEntryInfo *ce, *ceprev;
3745 if ( ceparent->ce_kids ) {
3746 for ( ceprev = ceparent->ce_kids; ceprev->ce_sibs;
3747 ceprev = ceprev->ce_sibs );
3750 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
3751 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
3753 c->value_dn.bv_val = c->log;
3754 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=module" IFMT, i);
3755 e = config_alloc_entry( ceparent, &c->value_dn );
3757 ce->ce_type = Cft_Include;
3759 ce->ce_private = mp;
3760 config_build_entry( c, e, cfOc_module, &c->value_dn,
3761 c->bi->bi_cf_table, NO_TABLE );
3764 op->o_bd->be_add( op, rs );
3767 if ( !ceparent->ce_kids ) {
3768 ceparent->ce_kids = ce;
3770 ceprev->ce_sibs = ce;
3779 config_back_db_open( BackendDB *be )
3781 CfBackInfo *cfb = be->be_private;
3784 CfEntryInfo *ce, *ceparent, *ceprev;
3790 Connection conn = {0};
3791 char opbuf[OPERATION_BUFFER_SIZE];
3793 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
3794 SlapReply rs = {REP_RESULT};
3796 /* If we read the config from back-ldif, nothing to do here */
3797 if ( cfb->cb_got_ldif )
3800 if ( cfb->cb_use_ldif ) {
3801 op = (Operation *)opbuf;
3802 connection_fake_init( &conn, op, cfb );
3804 op->o_dn = be->be_rootdn;
3805 op->o_ndn = be->be_rootndn;
3807 op->o_tag = LDAP_REQ_ADD;
3808 op->o_callback = &cb;
3809 op->o_bd = &cfb->cb_db;
3814 /* create root of tree */
3816 e = config_alloc_entry( NULL, &rdn );
3818 ce->ce_type = Cft_Global;
3822 c.private = cfb->cb_config;
3823 ct = c.bi->bi_cf_table;
3824 ce->ce_private = c.private;
3825 config_build_entry( &c, e, cfOc_global, &rdn, ct, NO_TABLE );
3828 op->o_bd->be_add( op, &rs );
3835 /* Create schema nodes... cn=schema will contain the hardcoded core
3836 * schema, read-only. Child objects will contain runtime loaded schema
3840 e = config_alloc_entry( ceparent, &rdn );
3842 ce->ce_type = Cft_Schema;
3844 config_build_entry( &c, e, cfOc_schema, &rdn, ct, NO_TABLE );
3847 op->o_bd->be_add( op, &rs );
3849 if ( !ceparent->ce_kids ) {
3850 ceparent->ce_kids = ce;
3852 ceprev->ce_sibs = ce;
3856 /* Create includeFile nodes and schema nodes for included schema... */
3857 if ( cfb->cb_config->c_kids ) {
3859 c.private = cfb->cb_config->c_kids;
3860 config_build_schema_inc( &c, ce, op, &rs );
3861 c.private = cfb->cb_config->c_kids;
3862 ceprev = config_build_includes( &c, ceparent, op, &rs );
3865 #ifdef SLAPD_MODULES
3866 /* Create Module nodes... */
3867 if ( modpaths.mp_loads ) {
3868 ceprev = config_build_modules( &c, ceparent, op, &rs );
3872 /* Create backend nodes. Skip if they don't provide a cf_table.
3873 * There usually aren't any of these.
3877 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
3878 if (!bi->bi_cf_table) continue;
3879 if (!bi->bi_private) continue;
3882 rdn.bv_len = sprintf(rdn.bv_val, "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
3883 e = config_alloc_entry( ceparent, &rdn );
3885 ce->ce_type = Cft_Backend;
3888 config_build_entry( &c, e, cfOc_backend, &rdn, ct, BI_TABLE );
3891 op->o_bd->be_add( op, &rs );
3893 if ( !ceparent->ce_kids ) {
3894 ceparent->ce_kids = ce;
3896 ceprev->ce_sibs = ce;
3901 /* Create database nodes... */
3903 LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
3904 slap_overinfo *oi = NULL;
3911 if ( overlay_is_over( bptr )) {
3912 oi = bptr->bd_info->bi_private;
3918 rdn.bv_len = sprintf(rdn.bv_val, "%s=" IFMT "%s", cfAd_database->ad_cname.bv_val,
3920 e = config_alloc_entry( ceparent, &rdn );
3924 ce->ce_type = Cft_Database;
3927 config_build_entry( &c, e, cfOc_database, &rdn, ct, BE_TABLE );
3930 op->o_bd->be_add( op, &rs );
3932 if ( !ceparent->ce_kids ) {
3933 ceparent->ce_kids = ce;
3935 ceprev->ce_sibs = ce;
3938 /* Iterate through overlays */
3942 CfEntryInfo *opar = ce, *oprev = NULL;
3945 for (j=0,on=oi->oi_list; on; j++,on=on->on_next) {
3947 rdn.bv_len = sprintf(rdn.bv_val, "%s=" IFMT "%s",
3948 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
3949 oe = config_alloc_entry( opar, &rdn );
3953 ce->ce_type = Cft_Overlay;
3956 config_build_entry( &c, oe, cfOc_overlay, &rdn, ct, BI_TABLE );
3959 op->o_bd->be_add( op, &rs );
3961 if ( !opar->ce_kids ) {
3964 oprev->ce_sibs = ce;
3975 config_back_db_destroy( Backend *be )
3977 free( be->be_private );
3982 config_back_db_init( Backend *be )
3987 cfb = ch_calloc( 1, sizeof(CfBackInfo));
3988 cfb->cb_config = &cf_prv;
3989 be->be_private = cfb;
3991 ber_dupbv( &be->be_rootdn, &config_rdn );
3992 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
3993 ber_dupbv( &dn, &be->be_rootdn );
3994 ber_bvarray_add( &be->be_suffix, &dn );
3995 ber_dupbv( &dn, &be->be_rootdn );
3996 ber_bvarray_add( &be->be_nsuffix, &dn );
3998 /* Hide from namingContexts */
3999 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
4005 config_back_destroy( BackendInfo *bi )
4007 ldif_must_b64_encode_release();
4013 AttributeDescription **desc;
4015 { "backend", &cfAd_backend },
4016 { "database", &cfAd_database },
4017 { "include", &cfAd_include },
4018 { "overlay", &cfAd_overlay },
4023 * add / delete: all types that may be added or deleted must use an
4024 * X-ORDERED attributeType for their RDN. Adding and deleting entries
4025 * should automatically renumber the index of any siblings as needed,
4026 * so that no gaps in the numbering sequence exist after the add/delete
4028 * What can be added:
4030 * backend objects for backend-specific config directives
4034 * delete: probably no support this time around.
4036 * modrdn: generally not done. Will be invoked automatically by add/
4037 * delete to update numbering sequence. Perform as an explicit operation
4038 * so that the renumbering effect may be replicated. Subtree rename must
4039 * be supported, since renumbering a database will affect all its child
4042 * modify: must be fully supported.
4046 config_back_initialize( BackendInfo *bi )
4048 ConfigTable *ct = config_back_cf_table;
4051 AttributeDescription *ad = NULL;
4053 static char *controls[] = {
4054 LDAP_CONTROL_MANAGEDSAIT,
4058 bi->bi_controls = controls;
4063 bi->bi_destroy = config_back_destroy;
4065 bi->bi_db_init = config_back_db_init;
4066 bi->bi_db_config = 0;
4067 bi->bi_db_open = config_back_db_open;
4068 bi->bi_db_close = 0;
4069 bi->bi_db_destroy = config_back_db_destroy;
4071 bi->bi_op_bind = config_back_bind;
4072 bi->bi_op_unbind = 0;
4073 bi->bi_op_search = config_back_search;
4074 bi->bi_op_compare = 0;
4075 bi->bi_op_modify = config_back_modify;
4076 bi->bi_op_modrdn = config_back_modrdn;
4077 bi->bi_op_add = config_back_add;
4078 bi->bi_op_delete = 0;
4079 bi->bi_op_abandon = 0;
4081 bi->bi_extended = 0;
4083 bi->bi_chk_referrals = 0;
4085 #ifdef SLAP_OVERLAY_ACCESS
4086 bi->bi_access_allowed = slap_access_always_allowed;
4087 #endif /* SLAP_OVERLAY_ACCESS */
4089 bi->bi_connection_init = 0;
4090 bi->bi_connection_destroy = 0;
4093 for (i=0; OidMacros[i].name; i++ ) {
4094 argv[1] = OidMacros[i].name;
4095 argv[2] = OidMacros[i].oid;
4096 parse_oidm( "slapd", i, 3, argv, 0, NULL );
4099 bi->bi_cf_table = ct;
4101 i = config_register_schema( ct, cf_ocs );
4104 /* setup olcRootPW to be base64-encoded when written in LDIF form;
4105 * basically, we don't care if it fails */
4106 i = slap_str2ad( "olcRootPW", &ad, &text );
4108 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
4109 "warning, unable to get \"olcRootPW\" "
4110 "attribute description: %d: %s\n",
4113 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
4114 ad->ad_type->sat_oid );
4117 /* set up the notable AttributeDescriptions */
4119 for (;ct->name;ct++) {
4120 if (strcmp(ct->name, ads[i].name)) continue;
4121 *ads[i].desc = ct->ad;
4123 if (!ads[i].name) break;