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, int readit ) {
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 ))
2430 op = (Operation *)opbuf;
2431 connection_fake_init( &conn, op, cfb );
2433 filter.f_desc = slap_schema.si_ad_objectClass;
2435 op->o_tag = LDAP_REQ_SEARCH;
2437 op->ors_filter = &filter;
2438 op->ors_filterstr = filterstr;
2439 op->ors_scope = LDAP_SCOPE_SUBTREE;
2441 op->o_dn = be->be_rootdn;
2442 op->o_ndn = be->be_rootndn;
2444 op->o_req_dn = be->be_suffix[0];
2445 op->o_req_ndn = be->be_nsuffix[0];
2447 op->ors_tlimit = SLAP_NO_LIMIT;
2448 op->ors_slimit = SLAP_NO_LIMIT;
2450 op->ors_attrs = slap_anlist_all_attributes;
2451 op->ors_attrsonly = 0;
2453 op->o_callback = &cb;
2454 cb.sc_private = cfb;
2456 op->o_bd = &cfb->cb_db;
2457 op->o_bd->be_search( op, &rs );
2460 cfb->cb_use_ldif = 1;
2466 CfOcInfo_cmp( const void *c1, const void *c2 ) {
2467 const CfOcInfo *co1 = c1;
2468 const CfOcInfo *co2 = c2;
2470 return ber_bvcmp( co1->co_name, co2->co_name );
2474 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
2478 i = init_config_attrs( ct );
2481 /* set up the objectclasses */
2482 i = init_config_ocs( ocs );
2485 for (i=0; ocs[i].def; i++) {
2487 co = ch_malloc( sizeof(CfOcInfo) );
2488 co->co_oc = *ocs[i].oc;
2489 co->co_name = &co->co_oc->soc_cname;
2491 co->co_type = ocs[i].cft;
2492 avl_insert( &CfOcTree, co, CfOcInfo_cmp, avl_dup_error );
2499 read_config(const char *fname, const char *dir) {
2503 /* Setup the config backend */
2504 be = backend_db_init( "config" );
2508 cfb = be->be_private;
2510 /* If no .conf, or a dir was specified, setup the dir */
2511 if ( !fname || dir ) {
2513 /* If explicitly given, check for existence */
2516 if ( stat( dir, &st ) < 0 ) {
2517 Debug( LDAP_DEBUG_ANY,
2518 "invalid config directory %s, error %d\n",
2523 dir = SLAPD_DEFAULT_CONFIGDIR;
2525 /* if fname is defaulted, try reading .d */
2526 if ( config_setup_ldif( be, dir, !fname ))
2529 /* If we read the config from back-ldif, nothing to do here */
2530 if ( cfb->cb_got_ldif )
2535 fname = SLAPD_DEFAULT_CONFIGFILE;
2536 ber_str2bv( fname, 0, 1, &cf_prv.c_file );
2538 return read_config_file(fname, 0, NULL);
2542 config_back_bind( Operation *op, SlapReply *rs )
2544 if ( op->orb_method == LDAP_AUTH_SIMPLE && be_isroot_pw( op )) {
2545 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
2546 /* frontend sends result */
2547 return LDAP_SUCCESS;
2550 rs->sr_err = LDAP_INVALID_CREDENTIALS;
2551 send_ldap_result( op, rs );
2557 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
2561 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
2563 rs->sr_attrs = op->ors_attrs;
2564 rs->sr_entry = ce->ce_entry;
2565 rc = send_search_entry( op, rs );
2567 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
2568 if ( ce->ce_kids ) {
2569 rc = config_send( op, rs, ce->ce_kids, 1 );
2570 if ( rc ) return rc;
2573 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
2574 rc = config_send( op, rs, ce, 0 );
2582 static ConfigTable *
2583 config_find_table( CfOcInfo **colst, int nocs, AttributeDescription *ad )
2587 for (j=0; j<nocs; j++) {
2588 for (i=0; colst[j]->co_table[i].name; i++)
2589 if ( colst[j]->co_table[i].ad == ad )
2590 return &colst[j]->co_table[i];
2595 /* Sort the attributes of the entry according to the order defined
2596 * in the objectclass, with required attributes occurring before
2597 * allowed attributes. For any attributes with sequencing dependencies
2598 * (e.g., rootDN must be defined after suffix) the objectclass must
2599 * list the attributes in the desired sequence.
2602 sort_attrs( Entry *e, CfOcInfo **colst, int nocs )
2604 Attribute *a, *head = NULL, *tail = NULL, **prev;
2607 for (i=0; i<nocs; i++) {
2608 if ( colst[i]->co_oc->soc_required ) {
2609 AttributeType **at = colst[i]->co_oc->soc_required;
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 ) {
2627 if ( colst[i]->co_oc->soc_allowed ) {
2628 AttributeType **at = colst[i]->co_oc->soc_allowed;
2629 for (j=0; at[j]; j++) {
2630 for (a=e->e_attrs, prev=&e->e_attrs; a;
2631 prev = &(*prev)->a_next, a=a->a_next) {
2632 if ( a->a_desc == at[j]->sat_ad ) {
2648 tail->a_next = e->e_attrs;
2654 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
2656 Attribute *a = NULL;
2657 AttributeDescription *ad;
2660 int i, rc = 0, sort = 0;
2667 Modifications *ml = ptr;
2669 vals = ml->sml_values;
2672 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
2674 rc = ordered_value_sort( a, 1 );
2678 for ( i=0; vals[i].bv_val; i++ ) {
2679 ca->line = vals[i].bv_val;
2681 char *idx = strchr( ca->line, '}' );
2682 if ( idx ) ca->line = idx+1;
2684 rc = config_parse_vals( ct, ca, i );
2692 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
2693 SlapReply *rs, int *renum )
2696 int index = -1, gotindex = 0, nsibs;
2697 int renumber = 0, tailindex = 0;
2701 if ( renum ) *renum = 0;
2703 /* These entries don't get indexed/renumbered */
2704 if ( ce_type == Cft_Global ) return 0;
2705 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
2707 if ( ce_type == Cft_Include || ce_type == Cft_Module )
2710 /* See if the rdn has an index already */
2711 dnRdn( &e->e_name, &rdn );
2712 ptr1 = strchr( e->e_name.bv_val, '{' );
2713 if ( ptr1 && ptr1 - e->e_name.bv_val < rdn.bv_len ) {
2714 ptr2 = strchr( ptr1, '}' );
2715 if (!ptr2 || ptr2 - e->e_name.bv_val > rdn.bv_len)
2716 return LDAP_NAMING_VIOLATION;
2717 if ( ptr2-ptr1 == 1)
2718 return LDAP_NAMING_VIOLATION;
2720 index = atoi(ptr1+1);
2722 return LDAP_NAMING_VIOLATION;
2725 /* count related kids */
2726 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
2727 if ( ce->ce_type == ce_type ) nsibs++;
2730 if ( index != nsibs ) {
2732 if ( index < nsibs ) {
2733 if ( tailindex ) return LDAP_NAMING_VIOLATION;
2734 /* Siblings need to be renumbered */
2739 struct berval ival, newrdn, nnewrdn;
2740 struct berval rtype, rval;
2742 AttributeDescription *ad = NULL;
2746 rval.bv_val = strchr(rdn.bv_val, '=' ) + 1;
2747 rval.bv_len = rdn.bv_len - (rval.bv_val - rdn.bv_val);
2748 rtype.bv_val = rdn.bv_val;
2749 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
2752 slap_bv2ad( &rtype, &ad, &text );
2753 a = attr_find( e->e_attrs, ad );
2754 if (!a ) return LDAP_NAMING_VIOLATION;
2757 ival.bv_len = sprintf( ibuf, IFMT, nsibs );
2759 newrdn.bv_len = rdn.bv_len + ival.bv_len;
2760 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
2763 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
2764 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
2771 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
2773 ptr1 = lutil_strncopy( newrdn.bv_val, rtype.bv_val,
2776 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
2777 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
2781 /* Do the equivalent of ModRDN */
2782 /* Replace DN / NDN */
2783 newrdn.bv_len = ptr1 - newrdn.bv_val;
2784 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
2785 free( e->e_name.bv_val );
2786 build_new_dn( &e->e_name, &parent->ce_entry->e_name,
2788 free( e->e_nname.bv_val );
2789 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname,
2793 free( a->a_vals[0].bv_val );
2794 ptr1 = strchr( newrdn.bv_val, '=' ) + 1;
2795 a->a_vals[0].bv_len = newrdn.bv_len - (ptr1 - newrdn.bv_val);
2796 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
2797 strcpy( a->a_vals[0].bv_val, ptr1 );
2799 if ( a->a_nvals != a->a_vals ) {
2800 free( a->a_nvals[0].bv_val );
2801 ptr1 = strchr( nnewrdn.bv_val, '=' ) + 1;
2802 a->a_nvals[0].bv_len = nnewrdn.bv_len - (ptr1 - nnewrdn.bv_val);
2803 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
2804 strcpy( a->a_nvals[0].bv_val, ptr1 );
2806 free( nnewrdn.bv_val );
2807 free( newrdn.bv_val );
2810 if ( renum ) *renum = renumber;
2815 count_ocs( Attribute *oc_at, int *nocs )
2818 CfOcInfo co, *coptr, **colst;
2820 /* count the objectclasses */
2821 for ( i=0; oc_at->a_nvals[i].bv_val; i++ );
2823 colst = (CfOcInfo **)ch_malloc( n * sizeof(CfOcInfo *));
2825 for ( i=0, j=0; i<n; i++) {
2826 co.co_name = &oc_at->a_nvals[i];
2827 coptr = avl_find( CfOcTree, &co, CfOcInfo_cmp );
2829 /* ignore non-config objectclasses. probably should be
2830 * an error, general data doesn't belong here.
2832 if ( !coptr ) continue;
2834 /* Ignore the root objectclass, it has no implementation.
2836 if ( coptr->co_type == Cft_Abstract ) continue;
2843 /* Parse an LDAP entry into config directives */
2845 config_add_internal( CfBackInfo *cfb, Entry *e, SlapReply *rs, int *renum )
2847 CfEntryInfo *ce, *last;
2849 Attribute *a, *oc_at, *type_attr;
2850 AttributeDescription *type_ad = NULL;
2852 ConfigArgs ca = {0};
2854 ConfigTable *ct, *type_ct = NULL;
2857 /* Make sure parent exists and entry does not */
2858 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
2860 return LDAP_ALREADY_EXISTS;
2862 dnParent( &e->e_nname, &pdn );
2864 /* If last is NULL, the new entry is the root/suffix entry,
2865 * otherwise last should be the parent.
2867 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn )) {
2869 rs->sr_matched = last->ce_entry->e_name.bv_val;
2870 return LDAP_NO_SUCH_OBJECT;
2873 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
2874 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
2876 colst = count_ocs( oc_at, &nocs );
2878 /* Only the root can be Cft_Global, everything else must
2879 * have a parent. Only limited nesting arrangements are allowed.
2881 switch( colst[0]->co_type ) {
2884 rc = LDAP_CONSTRAINT_VIOLATION;
2892 if ( !last || ( last->ce_type != Cft_Global &&
2893 last->ce_type != colst[0]->co_type )) {
2894 rc = LDAP_CONSTRAINT_VIOLATION;
2899 if ( !last || ( last->ce_type != Cft_Global &&
2900 last->ce_type != Cft_Database &&
2901 last->ce_type != colst[0]->co_type )) {
2902 rc = LDAP_CONSTRAINT_VIOLATION;
2906 #ifdef SLAPD_MODULES
2908 if ( !last || last->ce_type != Cft_Global ) {
2909 rc = LDAP_CONSTRAINT_VIOLATION;
2916 sort_attrs( e, colst, nocs );
2918 /* Parse all the values and check for simple syntax errors before
2919 * performing any set actions.
2921 switch (colst[0]->co_type) {
2923 /* The cn=schema entry is all hardcoded, so never reparse it */
2924 if (last->ce_type == Cft_Global )
2927 ca.private = ch_calloc( 1, sizeof(ConfigFile) );
2930 ca.be = LDAP_STAILQ_FIRST(&backendDB);
2934 if ( last->ce_type == Cft_Backend )
2935 ca.bi = last->ce_bi;
2937 type_ad = cfAd_backend;
2940 if ( last->ce_type == Cft_Database ) {
2941 ca.be = last->ce_be;
2943 type_ad = cfAd_database;
2944 /* dummy, just to get past check_attr */
2950 ca.be = last->ce_be;
2951 type_ad = cfAd_overlay;
2956 nocs = 0; /* ignored */
2959 if ( last->ce_type == Cft_Global )
2962 cfn = last->ce_private;
2963 type_ad = cfAd_include;
2965 #ifdef SLAPD_MODULES
2970 ptr = strchr( e->e_name.bv_val, '{' );
2972 rc = LDAP_NAMING_VIOLATION;
2976 for (i=0, mp=&modpaths; mp && i<j; mp=mp->mp_next);
2977 /* There is no corresponding modpath for this load? */
2979 rc = LDAP_NAMING_VIOLATION;
2982 module_path( mp->mp_path.bv_val );
2990 /* If doing an LDAPadd, check for indexed names and any necessary
2991 * renaming/renumbering. Entries that don't need indexed names are
2992 * ignored. Entries that need an indexed name and arrive without one
2993 * are assigned to the end. Entries that arrive with an index may
2994 * cause the following entries to be renumbered/bumped down.
2996 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
2997 * don't allow Adding an entry with an index that's already in use.
2998 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
3000 * These entries can have auto-assigned indexes (appended to the end)
3001 * but only the other types support auto-renumbering of siblings.
3003 rc = check_name_index( last, colst[0]->co_type, e, rs, renum );
3007 init_config_argv( &ca );
3009 type_attr = attr_find( e->e_attrs, type_ad );
3011 rc = LDAP_OBJECT_CLASS_VIOLATION;
3014 type_ct = config_find_table( colst, nocs, type_ad );
3016 rc = LDAP_OBJECT_CLASS_VIOLATION;
3019 rc = check_vals( type_ct, &ca, type_attr, 1);
3020 if ( rc ) goto leave;
3022 for ( a=e->e_attrs; a; a=a->a_next ) {
3023 if ( a == type_attr || a == oc_at ) continue;
3024 ct = config_find_table( colst, nocs, a->a_desc );
3025 if ( !ct ) continue; /* user data? */
3026 rc = check_vals( ct, &ca, a, 1 );
3027 if ( rc ) goto leave;
3030 /* Basic syntax checks are OK. Do the actual settings. */
3032 ca.line = type_attr->a_vals[0].bv_val;
3033 if ( type_ad->ad_type->sat_flags & SLAP_AT_ORDERED ) {
3034 ptr = strchr( ca.line, '}' );
3035 if ( ptr ) ca.line = ptr+1;
3038 rc = config_parse_add( type_ct, &ca );
3044 for ( a=e->e_attrs; a; a=a->a_next ) {
3045 if ( a == type_attr || a == oc_at ) continue;
3046 ct = config_find_table( colst, nocs, a->a_desc );
3047 if ( !ct ) continue; /* user data? */
3048 for (i=0; a->a_vals[i].bv_val; i++) {
3049 ca.line = a->a_vals[i].bv_val;
3050 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
3051 ptr = strchr( ca.line, '}' );
3052 if ( ptr ) ca.line = ptr+1;
3055 rc = config_parse_add( ct, &ca );
3063 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
3064 ce->ce_parent = last;
3065 ce->ce_entry = entry_dup( e );
3066 ce->ce_entry->e_private = ce;
3067 ce->ce_type = colst[0]->co_type;
3070 ce->ce_private = ca.private;
3073 } else if ( last->ce_kids ) {
3076 for (c2=last->ce_kids; c2 && c2->ce_sibs; c2 = c2->ce_sibs);
3085 if ( colst ) ch_free( colst );
3089 /* Parse an LDAP entry into config directives, then store in underlying
3093 config_back_add( Operation *op, SlapReply *rs )
3096 CfEntryInfo *ce, *last;
3099 if ( !be_isroot( op ) ) {
3100 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3104 cfb = (CfBackInfo *)op->o_bd->be_private;
3106 ldap_pvt_thread_pool_pause( &connection_pool );
3109 * 1) check for existence of entry
3110 * 2) check for sibling renumbering
3111 * 3) perform internal add
3112 * 4) store entry in underlying database
3113 * 5) perform any necessary renumbering
3115 rs->sr_err = config_add_internal( cfb, op->ora_e, rs, &renumber );
3116 if ( rs->sr_err == LDAP_SUCCESS && cfb->cb_use_ldif ) {
3117 BackendDB *be = op->o_bd;
3118 slap_callback sc = { NULL, slap_null_cb, NULL, NULL };
3119 op->o_bd = &cfb->cb_db;
3120 sc.sc_next = op->o_callback;
3121 op->o_callback = ≻
3122 op->o_bd->be_add( op, rs );
3124 op->o_callback = sc.sc_next;
3129 ldap_pvt_thread_pool_resume( &connection_pool );
3132 send_ldap_result( op, rs );
3136 typedef struct delrec {
3137 struct delrec *next;
3143 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
3146 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
3147 int rc = LDAP_UNWILLING_TO_PERFORM;
3149 Entry *e = ce->ce_entry;
3150 Attribute *save_attrs = e->e_attrs, *oc_at;
3155 delrec *dels = NULL, *deltail = NULL;
3157 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
3158 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
3160 colst = count_ocs( oc_at, &nocs );
3162 e->e_attrs = attrs_dup( e->e_attrs );
3164 init_config_argv( ca );
3167 ca->private = ce->ce_private;
3168 strcpy( ca->log, "back-config" );
3170 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
3171 ct = config_find_table( colst, nocs, ml->sml_desc );
3172 switch (ml->sml_op) {
3173 case LDAP_MOD_DELETE:
3174 case LDAP_MOD_REPLACE: {
3175 BerVarray vals = NULL, nvals;
3177 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
3179 snprintf( ca->msg, sizeof(ca->msg),
3180 "<%s> cannot be deleted" );
3181 snprintf(ca->msg, sizeof(ca->msg), "cannot delete %s",
3182 ml->sml_desc->ad_cname.bv_val );
3185 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3186 vals = ml->sml_values;
3187 nvals = ml->sml_nvalues;
3188 ml->sml_values = NULL;
3189 ml->sml_nvalues = NULL;
3191 /* If we're deleting by values, remember the indexes of the
3192 * values we deleted.
3194 if ( ct && ml->sml_values ) {
3196 for (i=0; ml->sml_values[i].bv_val; i++);
3197 d = ch_malloc( sizeof(delrec) + i * sizeof(int));
3208 rc = modify_delete_vindex(e, &ml->sml_mod,
3209 get_permissiveModify(op),
3210 &rs->sr_text, ca->msg, sizeof(ca->msg), idx );
3211 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3212 ml->sml_values = vals;
3213 ml->sml_nvalues = nvals;
3218 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
3221 case SLAP_MOD_SOFTADD: {
3222 int mop = ml->sml_op;
3224 ml->sml_op = LDAP_MOD_ADD;
3226 if ( ct->arg_type & ARG_NO_INSERT ) {
3227 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
3229 for (i = 0; a->a_vals[i].bv_val; i++ );
3233 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
3234 if ( ml->sml_values[i].bv_val[0] == '{' &&
3236 int j = strtol( ml->sml_values[i].bv_val+1, NULL, 0 );
3239 snprintf(ca->msg, sizeof(ca->msg), "cannot insert %s",
3240 ml->sml_desc->ad_cname.bv_val );
3244 rc = check_vals( ct, ca, ml, 0 );
3248 rc = modify_add_values(e, &ml->sml_mod,
3249 get_permissiveModify(op),
3250 &rs->sr_text, ca->msg, sizeof(ca->msg) );
3252 /* If value already exists, show success here
3253 * and ignore this operation down below.
3255 if ( mop == SLAP_MOD_SOFTADD ) {
3256 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
3266 case LDAP_MOD_INCREMENT: /* FIXME */
3271 if(rc != LDAP_SUCCESS) break;
3274 if(rc == LDAP_SUCCESS) {
3275 /* check that the entry still obeys the schema */
3276 rc = entry_schema_check(op->o_bd, e, NULL,
3277 &rs->sr_text, ca->msg, sizeof(ca->msg) );
3279 if ( rc == LDAP_SUCCESS ) {
3280 /* Basic syntax checks are OK. Do the actual settings. */
3281 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
3282 ct = config_find_table( colst, nocs, ml->sml_desc );
3283 if ( !ct ) continue;
3285 switch (ml->sml_op) {
3286 case LDAP_MOD_DELETE:
3287 case LDAP_MOD_REPLACE: {
3288 BerVarray vals = NULL, nvals;
3292 a = attr_find( e->e_attrs, ml->sml_desc );
3294 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3295 vals = ml->sml_values;
3296 nvals = ml->sml_nvalues;
3297 ml->sml_values = NULL;
3298 ml->sml_nvalues = NULL;
3301 if ( ml->sml_values )
3304 /* If we didn't delete the whole attribute */
3305 if ( ml->sml_values && a ) {
3306 struct berval *mvals;
3309 if ( ml->sml_nvalues )
3310 mvals = ml->sml_nvalues;
3312 mvals = ml->sml_values;
3314 /* use the indexes we saved up above */
3315 for (i=0; i < d->nidx; i++) {
3316 struct berval bv = *mvals++;
3317 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
3318 bv.bv_val[0] == '{' ) {
3319 ptr = strchr( bv.bv_val, '}' ) + 1;
3320 bv.bv_len -= ptr - bv.bv_val;
3323 ca->line = bv.bv_val;
3324 ca->valx = d->idx[i];
3325 rc = config_del_vals( ct, ca );
3326 if ( rc != LDAP_SUCCESS ) break;
3327 for (j=i+1; j < d->nidx; j++)
3328 if ( d->idx[j] >d->idx[i] )
3334 rc = config_del_vals( ct, ca );
3335 if ( rc ) rc = LDAP_OTHER;
3337 if ( ml->sml_values ) {
3341 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
3342 ml->sml_values = vals;
3343 ml->sml_nvalues = nvals;
3345 if ( !vals || rc != LDAP_SUCCESS )
3348 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
3351 for (i=0; ml->sml_values[i].bv_val; i++) {
3352 ca->line = ml->sml_values[i].bv_val;
3354 if ( ml->sml_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
3355 ca->line[0] == '{' ) {
3356 ptr = strchr( ca->line, '}' );
3358 ca->valx = strtol( ca->line+1, NULL, 0 );
3362 rc = config_parse_add( ct, ca );
3377 if ( rc == LDAP_SUCCESS ) {
3378 attrs_free( save_attrs );
3380 attrs_free( e->e_attrs );
3381 e->e_attrs = save_attrs;
3383 ch_free( ca->argv );
3384 if ( colst ) ch_free( colst );
3390 config_back_modify( Operation *op, SlapReply *rs )
3393 CfEntryInfo *ce, *last;
3395 ConfigArgs ca = {0};
3398 AttributeDescription *rad = NULL;
3400 if ( !be_isroot( op ) ) {
3401 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3405 cfb = (CfBackInfo *)op->o_bd->be_private;
3407 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3410 rs->sr_matched = last->ce_entry->e_name.bv_val;
3411 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3415 /* Get type of RDN */
3416 rdn = ce->ce_entry->e_nname;
3417 ptr = strchr( rdn.bv_val, '=' );
3418 rdn.bv_len = ptr - rdn.bv_val;
3419 slap_bv2ad( &rdn, &rad, &rs->sr_text );
3421 /* Some basic validation... */
3422 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
3423 /* Don't allow Modify of RDN; must use ModRdn for that. */
3424 if ( ml->sml_desc == rad ) {
3425 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
3426 rs->sr_text = "Use modrdn to change the entry name";
3431 ldap_pvt_thread_pool_pause( &connection_pool );
3434 * 1) perform the Modify on the cached Entry.
3435 * 2) verify that the Entry still satisfies the schema.
3436 * 3) perform the individual config operations.
3437 * 4) store Modified entry in underlying LDIF backend.
3439 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
3441 rs->sr_text = ca.msg;
3442 } else if ( cfb->cb_use_ldif ) {
3443 BackendDB *be = op->o_bd;
3444 slap_callback sc = { NULL, slap_null_cb, NULL, NULL };
3445 op->o_bd = &cfb->cb_db;
3446 sc.sc_next = op->o_callback;
3447 op->o_callback = ≻
3448 op->o_bd->be_modify( op, rs );
3450 op->o_callback = sc.sc_next;
3453 ldap_pvt_thread_pool_resume( &connection_pool );
3455 send_ldap_result( op, rs );
3460 config_back_modrdn( Operation *op, SlapReply *rs )
3463 CfEntryInfo *ce, *last;
3465 if ( !be_isroot( op ) ) {
3466 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3470 cfb = (CfBackInfo *)op->o_bd->be_private;
3472 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3475 rs->sr_matched = last->ce_entry->e_name.bv_val;
3476 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3480 /* We don't allow moving objects to new parents.
3481 * Generally we only allow reordering a set of ordered entries.
3483 if ( op->orr_newSup ) {
3484 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
3487 ldap_pvt_thread_pool_pause( &connection_pool );
3489 ldap_pvt_thread_pool_resume( &connection_pool );
3491 send_ldap_result( op, rs );
3496 config_back_search( Operation *op, SlapReply *rs )
3499 CfEntryInfo *ce, *last;
3502 if ( !be_isroot( op ) ) {
3503 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
3507 cfb = (CfBackInfo *)op->o_bd->be_private;
3509 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
3512 rs->sr_matched = last->ce_entry->e_name.bv_val;
3513 rs->sr_err = LDAP_NO_SUCH_OBJECT;
3516 switch ( op->ors_scope ) {
3517 case LDAP_SCOPE_BASE:
3518 case LDAP_SCOPE_SUBTREE:
3519 config_send( op, rs, ce, 0 );
3522 case LDAP_SCOPE_ONELEVEL:
3523 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
3524 config_send( op, rs, ce, 1 );
3529 rs->sr_err = LDAP_SUCCESS;
3531 send_ldap_result( op, rs );
3536 config_alloc_entry( CfEntryInfo *parent, struct berval *rdn )
3538 Entry *e = ch_calloc( 1, sizeof(Entry) );
3539 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
3544 ce->ce_parent = parent;
3546 pdn = parent->ce_entry->e_nname;
3551 build_new_dn( &e->e_name, &pdn, rdn, NULL );
3552 ber_dupbv( &e->e_nname, &e->e_name );
3561 config_build_entry( ConfigArgs *c, Entry *e, ObjectClass *oc,
3562 struct berval *rdn, ConfigTable *ct, int table )
3565 struct berval ad_name;
3566 AttributeDescription *ad = NULL;
3573 val = oc->soc_cname;
3574 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass, &val, NULL );
3575 ptr = strchr(rdn->bv_val, '=');
3576 ad_name.bv_val = rdn->bv_val;
3577 ad_name.bv_len = ptr - rdn->bv_val;
3578 rc = slap_bv2ad( &ad_name, &ad, &text );
3583 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
3584 attr_merge_normalize_one(e, ad, &val, NULL );
3586 for (at=oc->soc_required; at && *at; at++) {
3587 /* Skip the naming attr */
3588 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
3590 for (i=0;ct[i].name;i++) {
3591 if (ct[i].ad == (*at)->sat_ad) {
3592 rc = config_get_vals(&ct[i], c);
3593 if (rc == LDAP_SUCCESS) {
3594 if ( c->rvalue_nvals )
3595 attr_merge(e, ct[i].ad, c->rvalue_vals,
3598 attr_merge_normalize(e, ct[i].ad,
3599 c->rvalue_vals, NULL);
3600 ber_bvarray_free( c->rvalue_nvals );
3601 ber_bvarray_free( c->rvalue_vals );
3608 for (at=oc->soc_allowed; at && *at; at++) {
3609 /* Skip the naming attr */
3610 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
3612 for (i=0;ct[i].name;i++) {
3613 if (ct[i].ad == (*at)->sat_ad) {
3614 rc = config_get_vals(&ct[i], c);
3615 if (rc == LDAP_SUCCESS) {
3616 if ( c->rvalue_nvals )
3617 attr_merge(e, ct[i].ad, c->rvalue_vals, c->rvalue_nvals);
3619 attr_merge_normalize(e, ct[i].ad, c->rvalue_vals, NULL);
3620 ber_bvarray_free( c->rvalue_nvals );
3621 ber_bvarray_free( c->rvalue_vals );
3629 if ( table == BI_TABLE )
3630 ct = c->bi->bi_cf_table;
3632 ct = c->be->be_cf_table;
3633 for (;ct && ct->name;ct++) {
3634 if (!ct->ad) continue;
3635 rc = config_get_vals(ct, c);
3636 if (rc == LDAP_SUCCESS) {
3637 if ( c->rvalue_nvals )
3638 attr_merge(e, ct->ad, c->rvalue_vals, c->rvalue_nvals);
3640 attr_merge_normalize(e, ct->ad, c->rvalue_vals, NULL);
3644 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
3645 rc = structural_class(oc_at->a_vals, &val, NULL, &text, c->msg,
3647 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &val, NULL );
3653 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
3654 Operation *op, SlapReply *rs )
3657 ConfigFile *cf = c->private;
3658 CfEntryInfo *ce, *ceprev;
3662 if ( ceparent->ce_kids ) {
3663 for ( ceprev = ceparent->ce_kids; ceprev->ce_sibs;
3664 ceprev = ceprev->ce_sibs );
3667 for (; cf; cf=cf->c_sibs, c->depth++) {
3668 c->value_dn.bv_val = c->log;
3669 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
3674 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
3676 ptr = strchr( bv.bv_val, '.' );
3678 bv.bv_len = ptr - bv.bv_val;
3679 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=" IFMT, c->depth);
3680 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
3682 c->value_dn.bv_len += bv.bv_len;
3683 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
3685 e = config_alloc_entry( ceparent, &c->value_dn );
3687 config_build_entry( c, e, cfOc_schema, &c->value_dn,
3688 c->bi->bi_cf_table, NO_TABLE );
3690 ce->ce_private = cf;
3691 ce->ce_type = Cft_Schema;
3694 op->o_bd->be_add( op, rs );
3697 if ( !ceparent->ce_kids ) {
3698 ceparent->ce_kids = ce;
3700 ceprev->ce_sibs = ce;
3704 c->private = cf->c_kids;
3705 config_build_schema_inc( c, ceparent, op, rs );
3710 static CfEntryInfo *
3711 config_build_includes( ConfigArgs *c, CfEntryInfo *ceparent,
3712 Operation *op, SlapReply *rs )
3716 ConfigFile *cf = c->private;
3717 CfEntryInfo *ce, *ceprev;
3719 if ( ceparent->ce_kids ) {
3720 for ( ceprev = ceparent->ce_kids; ceprev->ce_sibs;
3721 ceprev = ceprev->ce_sibs );
3724 for (i=0; cf; cf=cf->c_sibs, i++) {
3725 c->value_dn.bv_val = c->log;
3726 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=include" IFMT, i);
3727 e = config_alloc_entry( ceparent, &c->value_dn );
3729 config_build_entry( c, e, cfOc_include, &c->value_dn,
3730 c->bi->bi_cf_table, NO_TABLE );
3733 op->o_bd->be_add( op, rs );
3736 ce->ce_private = cf;
3737 ce->ce_type = Cft_Include;
3739 if ( !ceparent->ce_kids ) {
3740 ceparent->ce_kids = ce;
3742 ceprev->ce_sibs = ce;
3746 c->private = cf->c_kids;
3747 config_build_includes( c, ce, op, rs );
3753 #ifdef SLAPD_MODULES
3755 static CfEntryInfo *
3756 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
3757 Operation *op, SlapReply *rs )
3761 CfEntryInfo *ce, *ceprev;
3764 if ( ceparent->ce_kids ) {
3765 for ( ceprev = ceparent->ce_kids; ceprev->ce_sibs;
3766 ceprev = ceprev->ce_sibs );
3769 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
3770 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
3772 c->value_dn.bv_val = c->log;
3773 c->value_dn.bv_len = sprintf(c->value_dn.bv_val, "cn=module" IFMT, i);
3774 e = config_alloc_entry( ceparent, &c->value_dn );
3776 ce->ce_type = Cft_Include;
3778 ce->ce_private = mp;
3779 config_build_entry( c, e, cfOc_module, &c->value_dn,
3780 c->bi->bi_cf_table, NO_TABLE );
3783 op->o_bd->be_add( op, rs );
3786 if ( !ceparent->ce_kids ) {
3787 ceparent->ce_kids = ce;
3789 ceprev->ce_sibs = ce;
3798 config_back_db_open( BackendDB *be )
3800 CfBackInfo *cfb = be->be_private;
3803 CfEntryInfo *ce, *ceparent, *ceprev;
3809 Connection conn = {0};
3810 char opbuf[OPERATION_BUFFER_SIZE];
3812 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
3813 SlapReply rs = {REP_RESULT};
3815 /* If we read the config from back-ldif, nothing to do here */
3816 if ( cfb->cb_got_ldif )
3819 if ( cfb->cb_use_ldif ) {
3820 op = (Operation *)opbuf;
3821 connection_fake_init( &conn, op, cfb );
3823 op->o_dn = be->be_rootdn;
3824 op->o_ndn = be->be_rootndn;
3826 op->o_tag = LDAP_REQ_ADD;
3827 op->o_callback = &cb;
3828 op->o_bd = &cfb->cb_db;
3833 /* create root of tree */
3835 e = config_alloc_entry( NULL, &rdn );
3837 ce->ce_type = Cft_Global;
3841 c.private = cfb->cb_config;
3842 ct = c.bi->bi_cf_table;
3843 ce->ce_private = c.private;
3844 config_build_entry( &c, e, cfOc_global, &rdn, ct, NO_TABLE );
3847 op->o_bd->be_add( op, &rs );
3854 /* Create schema nodes... cn=schema will contain the hardcoded core
3855 * schema, read-only. Child objects will contain runtime loaded schema
3859 e = config_alloc_entry( ceparent, &rdn );
3861 ce->ce_type = Cft_Schema;
3863 config_build_entry( &c, e, cfOc_schema, &rdn, ct, NO_TABLE );
3866 op->o_bd->be_add( op, &rs );
3868 if ( !ceparent->ce_kids ) {
3869 ceparent->ce_kids = ce;
3871 ceprev->ce_sibs = ce;
3875 /* Create includeFile nodes and schema nodes for included schema... */
3876 if ( cfb->cb_config->c_kids ) {
3878 c.private = cfb->cb_config->c_kids;
3879 config_build_schema_inc( &c, ce, op, &rs );
3880 c.private = cfb->cb_config->c_kids;
3881 ceprev = config_build_includes( &c, ceparent, op, &rs );
3884 #ifdef SLAPD_MODULES
3885 /* Create Module nodes... */
3886 if ( modpaths.mp_loads ) {
3887 ceprev = config_build_modules( &c, ceparent, op, &rs );
3891 /* Create backend nodes. Skip if they don't provide a cf_table.
3892 * There usually aren't any of these.
3896 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
3897 if (!bi->bi_cf_table) continue;
3898 if (!bi->bi_private) continue;
3901 rdn.bv_len = sprintf(rdn.bv_val, "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
3902 e = config_alloc_entry( ceparent, &rdn );
3904 ce->ce_type = Cft_Backend;
3907 config_build_entry( &c, e, cfOc_backend, &rdn, ct, BI_TABLE );
3910 op->o_bd->be_add( op, &rs );
3912 if ( !ceparent->ce_kids ) {
3913 ceparent->ce_kids = ce;
3915 ceprev->ce_sibs = ce;
3920 /* Create database nodes... */
3922 LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
3923 slap_overinfo *oi = NULL;
3930 if ( overlay_is_over( bptr )) {
3931 oi = bptr->bd_info->bi_private;
3937 rdn.bv_len = sprintf(rdn.bv_val, "%s=" IFMT "%s", cfAd_database->ad_cname.bv_val,
3939 e = config_alloc_entry( ceparent, &rdn );
3943 ce->ce_type = Cft_Database;
3946 config_build_entry( &c, e, cfOc_database, &rdn, ct, BE_TABLE );
3949 op->o_bd->be_add( op, &rs );
3951 if ( !ceparent->ce_kids ) {
3952 ceparent->ce_kids = ce;
3954 ceprev->ce_sibs = ce;
3957 /* Iterate through overlays */
3961 CfEntryInfo *opar = ce, *oprev = NULL;
3964 for (j=0,on=oi->oi_list; on; j++,on=on->on_next) {
3966 rdn.bv_len = sprintf(rdn.bv_val, "%s=" IFMT "%s",
3967 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
3968 oe = config_alloc_entry( opar, &rdn );
3972 ce->ce_type = Cft_Overlay;
3975 config_build_entry( &c, oe, cfOc_overlay, &rdn, ct, BI_TABLE );
3978 op->o_bd->be_add( op, &rs );
3980 if ( !opar->ce_kids ) {
3983 oprev->ce_sibs = ce;
3994 config_back_db_destroy( Backend *be )
3996 free( be->be_private );
4001 config_back_db_init( Backend *be )
4006 cfb = ch_calloc( 1, sizeof(CfBackInfo));
4007 cfb->cb_config = &cf_prv;
4008 be->be_private = cfb;
4010 ber_dupbv( &be->be_rootdn, &config_rdn );
4011 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
4012 ber_dupbv( &dn, &be->be_rootdn );
4013 ber_bvarray_add( &be->be_suffix, &dn );
4014 ber_dupbv( &dn, &be->be_rootdn );
4015 ber_bvarray_add( &be->be_nsuffix, &dn );
4017 /* Hide from namingContexts */
4018 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
4024 config_back_destroy( BackendInfo *bi )
4026 ldif_must_b64_encode_release();
4032 AttributeDescription **desc;
4034 { "backend", &cfAd_backend },
4035 { "database", &cfAd_database },
4036 { "include", &cfAd_include },
4037 { "overlay", &cfAd_overlay },
4042 * add / delete: all types that may be added or deleted must use an
4043 * X-ORDERED attributeType for their RDN. Adding and deleting entries
4044 * should automatically renumber the index of any siblings as needed,
4045 * so that no gaps in the numbering sequence exist after the add/delete
4047 * What can be added:
4049 * backend objects for backend-specific config directives
4053 * delete: probably no support this time around.
4055 * modrdn: generally not done. Will be invoked automatically by add/
4056 * delete to update numbering sequence. Perform as an explicit operation
4057 * so that the renumbering effect may be replicated. Subtree rename must
4058 * be supported, since renumbering a database will affect all its child
4061 * modify: must be fully supported.
4065 config_back_initialize( BackendInfo *bi )
4067 ConfigTable *ct = config_back_cf_table;
4070 AttributeDescription *ad = NULL;
4072 static char *controls[] = {
4073 LDAP_CONTROL_MANAGEDSAIT,
4077 bi->bi_controls = controls;
4082 bi->bi_destroy = config_back_destroy;
4084 bi->bi_db_init = config_back_db_init;
4085 bi->bi_db_config = 0;
4086 bi->bi_db_open = config_back_db_open;
4087 bi->bi_db_close = 0;
4088 bi->bi_db_destroy = config_back_db_destroy;
4090 bi->bi_op_bind = config_back_bind;
4091 bi->bi_op_unbind = 0;
4092 bi->bi_op_search = config_back_search;
4093 bi->bi_op_compare = 0;
4094 bi->bi_op_modify = config_back_modify;
4095 bi->bi_op_modrdn = config_back_modrdn;
4096 bi->bi_op_add = config_back_add;
4097 bi->bi_op_delete = 0;
4098 bi->bi_op_abandon = 0;
4100 bi->bi_extended = 0;
4102 bi->bi_chk_referrals = 0;
4104 #ifdef SLAP_OVERLAY_ACCESS
4105 bi->bi_access_allowed = slap_access_always_allowed;
4106 #endif /* SLAP_OVERLAY_ACCESS */
4108 bi->bi_connection_init = 0;
4109 bi->bi_connection_destroy = 0;
4112 for (i=0; OidMacros[i].name; i++ ) {
4113 argv[1] = OidMacros[i].name;
4114 argv[2] = OidMacros[i].oid;
4115 parse_oidm( "slapd", i, 3, argv, 0, NULL );
4118 bi->bi_cf_table = ct;
4120 i = config_register_schema( ct, cf_ocs );
4123 /* setup olcRootPW to be base64-encoded when written in LDIF form;
4124 * basically, we don't care if it fails */
4125 i = slap_str2ad( "olcRootPW", &ad, &text );
4127 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
4128 "warning, unable to get \"olcRootPW\" "
4129 "attribute description: %d: %s\n",
4132 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
4133 ad->ad_type->sat_oid );
4136 /* set up the notable AttributeDescriptions */
4138 for (;ct->name;ct++) {
4139 if (strcmp(ct->name, ads[i].name)) continue;
4140 *ads[i].desc = ct->ad;
4142 if (!ads[i].name) break;