1 /* bconfig.c - the config backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005-2013 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>
28 #include <ac/unistd.h>
33 #include "slapi/slapi.h"
41 #define CONFIG_RDN "cn=config"
42 #define SCHEMA_RDN "cn=schema"
44 static struct berval config_rdn = BER_BVC(CONFIG_RDN);
45 static struct berval schema_rdn = BER_BVC(SCHEMA_RDN);
47 extern int slap_DN_strict; /* dn.c */
50 typedef struct modpath_s {
51 struct modpath_s *mp_next;
52 struct berval mp_path;
56 static ModPaths modpaths, *modlast = &modpaths, *modcur = &modpaths;
59 typedef struct ConfigFile {
60 struct ConfigFile *c_sibs;
61 struct ConfigFile *c_kids;
63 AttributeType *c_at_head, *c_at_tail;
64 ContentRule *c_cr_head, *c_cr_tail;
65 ObjectClass *c_oc_head, *c_oc_tail;
66 OidMacro *c_om_head, *c_om_tail;
67 Syntax *c_syn_head, *c_syn_tail;
72 ConfigFile *cb_config;
74 BackendDB cb_db; /* underlying database */
79 static CfBackInfo cfBackInfo;
81 static char *passwd_salt;
83 static char *logfileName;
84 #ifdef SLAP_AUTH_REWRITE
85 static BerVarray authz_rewrites;
87 static AccessControl *defacl_parsed = NULL;
89 static struct berval cfdir;
92 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
93 *cfAd_include, *cfAd_attr, *cfAd_oc, *cfAd_om, *cfAd_syntax;
95 static ConfigFile *cfn;
97 static Avlnode *CfOcTree;
99 /* System schema state */
100 extern AttributeType *at_sys_tail; /* at.c */
101 extern ObjectClass *oc_sys_tail; /* oc.c */
102 extern OidMacro *om_sys_tail; /* oidm.c */
103 extern Syntax *syn_sys_tail; /* syntax.c */
104 static AttributeType *cf_at_tail;
105 static ObjectClass *cf_oc_tail;
106 static OidMacro *cf_om_tail;
107 static Syntax *cf_syn_tail;
109 static int config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca,
110 SlapReply *rs, int *renumber, Operation *op );
112 static int config_check_schema( Operation *op, CfBackInfo *cfb );
114 static ConfigDriver config_fname;
115 static ConfigDriver config_cfdir;
116 static ConfigDriver config_generic;
117 static ConfigDriver config_search_base;
118 static ConfigDriver config_passwd_hash;
119 static ConfigDriver config_schema_dn;
120 static ConfigDriver config_sizelimit;
121 static ConfigDriver config_timelimit;
122 static ConfigDriver config_overlay;
123 static ConfigDriver config_subordinate;
124 static ConfigDriver config_suffix;
125 #ifdef LDAP_TCP_BUFFER
126 static ConfigDriver config_tcp_buffer;
127 #endif /* LDAP_TCP_BUFFER */
128 static ConfigDriver config_rootdn;
129 static ConfigDriver config_rootpw;
130 static ConfigDriver config_restrict;
131 static ConfigDriver config_allows;
132 static ConfigDriver config_disallows;
133 static ConfigDriver config_requires;
134 static ConfigDriver config_security;
135 static ConfigDriver config_referral;
136 static ConfigDriver config_loglevel;
137 static ConfigDriver config_updatedn;
138 static ConfigDriver config_updateref;
139 static ConfigDriver config_extra_attrs;
140 static ConfigDriver config_include;
141 static ConfigDriver config_obsolete;
143 static ConfigDriver config_tls_option;
144 static ConfigDriver config_tls_config;
146 extern ConfigDriver syncrepl_config;
154 CFG_TLS_PROTOCOL_MIN,
211 static OidRec OidMacros[] = {
212 /* OpenLDAProot:1.12.2 */
213 { "OLcfg", "1.3.6.1.4.1.4203.1.12.2" },
214 { "OLcfgAt", "OLcfg:3" },
215 { "OLcfgGlAt", "OLcfgAt:0" },
216 { "OLcfgBkAt", "OLcfgAt:1" },
217 { "OLcfgDbAt", "OLcfgAt:2" },
218 { "OLcfgOvAt", "OLcfgAt:3" },
219 { "OLcfgCtAt", "OLcfgAt:4" }, /* contrib modules */
220 { "OLcfgOc", "OLcfg:4" },
221 { "OLcfgGlOc", "OLcfgOc:0" },
222 { "OLcfgBkOc", "OLcfgOc:1" },
223 { "OLcfgDbOc", "OLcfgOc:2" },
224 { "OLcfgOvOc", "OLcfgOc:3" },
225 { "OLcfgCtOc", "OLcfgOc:4" }, /* contrib modules */
227 /* Syntaxes. We should just start using the standard names and
228 * document that they are predefined and available for users
229 * to reference in their own schema. Defining schema without
230 * OID macros is for masochists...
232 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
233 { "OMsBoolean", "OMsyn:7" },
234 { "OMsDN", "OMsyn:12" },
235 { "OMsDirectoryString", "OMsyn:15" },
236 { "OMsIA5String", "OMsyn:26" },
237 { "OMsInteger", "OMsyn:27" },
238 { "OMsOID", "OMsyn:38" },
239 { "OMsOctetString", "OMsyn:40" },
244 * Backend/Database registry
246 * OLcfg{Bk|Db}{Oc|At}:0 -> common
247 * OLcfg{Bk|Db}{Oc|At}:1 -> back-bdb(/back-hdb)
248 * OLcfg{Bk|Db}{Oc|At}:2 -> back-ldif
249 * OLcfg{Bk|Db}{Oc|At}:3 -> back-ldap/meta
250 * OLcfg{Bk|Db}{Oc|At}:4 -> back-monitor
251 * OLcfg{Bk|Db}{Oc|At}:5 -> back-relay
252 * OLcfg{Bk|Db}{Oc|At}:6 -> back-sql(/back-ndb)
253 * OLcfg{Bk|Db}{Oc|At}:7 -> back-sock
254 * OLcfg{Bk|Db}{Oc|At}:8 -> back-null
255 * OLcfg{Bk|Db}{Oc|At}:9 -> back-passwd
256 * OLcfg{Bk|Db}{Oc|At}:10 -> back-shell
257 * OLcfg{Bk|Db}{Oc|At}:11 -> back-perl
258 * OLcfg{Bk|Db}{Oc|At}:12 -> back-mdb
264 * OLcfgOv{Oc|At}:1 -> syncprov
265 * OLcfgOv{Oc|At}:2 -> pcache
266 * OLcfgOv{Oc|At}:3 -> chain
267 * OLcfgOv{Oc|At}:4 -> accesslog
268 * OLcfgOv{Oc|At}:5 -> valsort
269 * OLcfgOv{Oc|At}:7 -> distproc
270 * OLcfgOv{Oc|At}:8 -> dynlist
271 * OLcfgOv{Oc|At}:9 -> dds
272 * OLcfgOv{Oc|At}:10 -> unique
273 * OLcfgOv{Oc|At}:11 -> refint
274 * OLcfgOv{Oc|At}:12 -> ppolicy
275 * OLcfgOv{Oc|At}:13 -> constraint
276 * OLcfgOv{Oc|At}:14 -> translucent
277 * OLcfgOv{Oc|At}:15 -> auditlog
278 * OLcfgOv{Oc|At}:16 -> rwm
279 * OLcfgOv{Oc|At}:17 -> dyngroup
280 * OLcfgOv{Oc|At}:18 -> memberof
281 * OLcfgOv{Oc|At}:19 -> collect
282 * OLcfgOv{Oc|At}:20 -> retcode
283 * OLcfgOv{Oc|At}:21 -> sssvlv
286 /* alphabetical ordering */
288 static ConfigTable config_back_cf_table[] = {
289 /* This attr is read-only */
290 { "", "", 0, 0, 0, ARG_MAGIC,
291 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
292 "DESC 'File for slapd configuration directives' "
293 "EQUALITY caseIgnoreMatch "
294 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
295 { "", "", 0, 0, 0, ARG_MAGIC,
296 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
297 "DESC 'Directory for slapd configuration backend' "
298 "EQUALITY caseIgnoreMatch "
299 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
300 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
301 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
302 "DESC 'Access Control List' "
303 "EQUALITY caseIgnoreMatch "
304 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
305 { "add_content_acl", NULL, 0, 0, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_ACL_ADD,
306 &config_generic, "( OLcfgGlAt:86 NAME 'olcAddContentAcl' "
307 "DESC 'Check ACLs against content of Add ops' "
308 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
309 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
310 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
311 "DESC 'Allowed set of deprecated features' "
312 "EQUALITY caseIgnoreMatch "
313 "SYNTAX OMsDirectoryString )", NULL, NULL },
314 { "argsfile", "file", 2, 2, 0, ARG_STRING,
315 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
316 "DESC 'File for slapd command line options' "
317 "EQUALITY caseIgnoreMatch "
318 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
319 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
320 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
321 "EQUALITY caseIgnoreMatch "
322 "SYNTAX OMsDirectoryString )", NULL, NULL },
323 { "attribute", "attribute", 2, 0, STRLENOF( "attribute" ),
324 ARG_PAREN|ARG_MAGIC|CFG_ATTR,
325 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
326 "DESC 'OpenLDAP attributeTypes' "
327 "EQUALITY caseIgnoreMatch "
328 "SUBSTR caseIgnoreSubstringsMatch "
329 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
331 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
332 #ifdef SLAP_AUTH_REWRITE
333 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
337 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
338 "EQUALITY caseIgnoreMatch "
339 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
340 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
341 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
342 "EQUALITY caseIgnoreMatch "
343 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
344 { "authz-regexp", "regexp> <DN", 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
345 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
346 "EQUALITY caseIgnoreMatch "
347 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
348 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
349 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
350 "DESC 'A type of backend' "
351 "EQUALITY caseIgnoreMatch "
352 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
354 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
355 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
356 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
357 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
358 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
359 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
360 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
361 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
362 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
363 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
364 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
365 "DESC 'The backend type for a database instance' "
366 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
367 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
368 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
369 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
370 { "disabled", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_DISABLED,
371 &config_generic, "( OLcfgDbAt:0.21 NAME 'olcDisabled' "
372 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
373 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
374 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
375 "EQUALITY caseIgnoreMatch "
376 "SYNTAX OMsDirectoryString )", NULL, NULL },
377 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
378 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
379 "DESC 'OpenLDAP DIT content rules' "
380 "EQUALITY caseIgnoreMatch "
381 "SUBSTR caseIgnoreSubstringsMatch "
382 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
384 { "extra_attrs", "attrlist", 2, 2, 0, ARG_DB|ARG_MAGIC,
385 &config_extra_attrs, "( OLcfgDbAt:0.20 NAME 'olcExtraAttrs' "
386 "EQUALITY caseIgnoreMatch "
387 "SYNTAX OMsDirectoryString )", NULL, NULL },
388 { "gentlehup", "on|off", 2, 2, 0,
390 ARG_ON_OFF, &global_gentlehup,
394 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
395 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
396 { "hidden", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_HIDDEN,
397 &config_generic, "( OLcfgDbAt:0.17 NAME 'olcHidden' "
398 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
399 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
400 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
401 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
402 { "include", "file", 2, 2, 0, ARG_MAGIC,
403 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
404 "SUP labeledURI )", NULL, NULL },
405 { "index_hash64", "on|off", 2, 2, 0, ARG_ON_OFF|ARG_MAGIC|CFG_IX_HASH64,
406 &config_generic, "( OLcfgGlAt:94 NAME 'olcIndexHash64' "
407 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
408 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
409 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
410 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
411 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
412 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
413 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
414 { "index_substr_any_len", "len", 2, 2, 0, ARG_UINT|ARG_NONZERO,
415 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
416 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
417 { "index_substr_any_step", "step", 2, 2, 0, ARG_UINT|ARG_NONZERO,
418 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
419 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
420 { "index_intlen", "len", 2, 2, 0, ARG_UINT|ARG_MAGIC|CFG_IX_INTLEN,
421 &config_generic, "( OLcfgGlAt:84 NAME 'olcIndexIntLen' "
422 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
423 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
424 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
425 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
426 { "ldapsyntax", "syntax", 2, 0, 0,
427 ARG_PAREN|ARG_MAGIC|CFG_SYNTAX,
428 &config_generic, "( OLcfgGlAt:85 NAME 'olcLdapSyntaxes' "
429 "DESC 'OpenLDAP ldapSyntax' "
430 "EQUALITY caseIgnoreMatch "
431 "SUBSTR caseIgnoreSubstringsMatch "
432 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
434 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
435 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
436 "EQUALITY caseIgnoreMatch "
437 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
438 { "listener-threads", "count", 2, 0, 0,
442 ARG_UINT|ARG_MAGIC|CFG_LTHREADS, &config_generic,
444 "( OLcfgGlAt:93 NAME 'olcListenerThreads' "
445 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
446 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
447 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
448 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
449 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
450 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
451 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
452 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
453 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
454 "EQUALITY caseIgnoreMatch "
455 "SYNTAX OMsDirectoryString )", NULL, NULL },
456 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
457 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
458 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
459 { "mirrormode", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_MIRRORMODE,
460 &config_generic, "( OLcfgDbAt:0.16 NAME 'olcMirrorMode' "
461 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
462 { "moduleload", "file", 2, 0, 0,
464 ARG_MAGIC|CFG_MODLOAD|ARG_NO_DELETE, &config_generic,
468 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
469 "EQUALITY caseIgnoreMatch "
470 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
471 { "modulepath", "path", 2, 2, 0,
473 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
477 "( OLcfgGlAt:31 NAME 'olcModulePath' "
478 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
479 { "monitoring", "TRUE|FALSE", 2, 2, 0,
480 ARG_MAGIC|CFG_MONITORING|ARG_DB|ARG_ON_OFF, &config_generic,
481 "( OLcfgDbAt:0.18 NAME 'olcMonitoring' "
482 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
483 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
484 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
485 "DESC 'OpenLDAP object classes' "
486 "EQUALITY caseIgnoreMatch "
487 "SUBSTR caseIgnoreSubstringsMatch "
488 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
490 { "objectidentifier", "name> <oid", 3, 3, 0, ARG_MAGIC|CFG_OID,
491 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
492 "EQUALITY caseIgnoreMatch "
493 "SUBSTR caseIgnoreSubstringsMatch "
494 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
495 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
496 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
497 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
498 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
499 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
500 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
501 { "password-hash", "hash", 2, 0, 0, ARG_MAGIC,
502 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
503 "EQUALITY caseIgnoreMatch "
504 "SYNTAX OMsDirectoryString )", NULL, NULL },
505 { "pidfile", "file", 2, 2, 0, ARG_STRING,
506 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
507 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
508 { "plugin", NULL, 0, 0, 0,
510 ARG_MAGIC|CFG_PLUGIN, &config_generic,
514 "( OLcfgGlAt:38 NAME 'olcPlugin' "
515 "EQUALITY caseIgnoreMatch "
516 "SYNTAX OMsDirectoryString )", NULL, NULL },
517 { "pluginlog", "filename", 2, 2, 0,
519 ARG_STRING, &slapi_log_file,
523 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
524 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
525 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
526 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
527 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
528 { "referral", "url", 2, 2, 0, ARG_MAGIC,
529 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
530 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
531 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
532 &config_obsolete, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
533 "EQUALITY caseIgnoreMatch "
534 "SUP labeledURI X-ORDERED 'VALUES' )", NULL, NULL },
535 { "replica-argsfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
536 &config_obsolete, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
537 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
538 { "replica-pidfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
539 &config_obsolete, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
540 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
541 { "replicationInterval", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
542 &config_obsolete, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
543 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
544 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC,
545 &config_obsolete, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
546 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
547 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
548 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
549 "EQUALITY caseIgnoreMatch "
550 "SYNTAX OMsDirectoryString )", NULL, NULL },
551 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
552 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
553 "EQUALITY caseIgnoreMatch "
554 "SYNTAX OMsDirectoryString )", NULL, NULL },
555 { "reverse-lookup", "on|off", 2, 2, 0,
556 #ifdef SLAPD_RLOOKUPS
557 ARG_ON_OFF, &use_reverse_lookup,
561 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
562 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
563 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
564 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
565 "EQUALITY distinguishedNameMatch "
566 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
567 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
568 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
569 "EQUALITY caseIgnoreMatch "
570 "SYNTAX OMsDirectoryString )", NULL, NULL },
571 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
572 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
573 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
574 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
575 &config_generic, NULL, NULL, NULL },
576 { "sasl-auxprops", NULL, 2, 0, 0,
577 #ifdef HAVE_CYRUS_SASL
578 ARG_STRING|ARG_UNIQUE, &slap_sasl_auxprops,
582 "( OLcfgGlAt:89 NAME 'olcSaslAuxprops' "
583 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
584 { "sasl-auxprops-dontusecopy", NULL, 2, 0, 0,
585 #if defined(HAVE_CYRUS_SASL) && defined(SLAP_AUXPROP_DONTUSECOPY)
586 ARG_MAGIC|CFG_AZDUC, &config_generic,
590 "( OLcfgGlAt:91 NAME 'olcSaslAuxpropsDontUseCopy' "
591 "EQUALITY caseIgnoreMatch "
592 "SYNTAX OMsDirectoryString )", NULL, NULL },
593 { "sasl-auxprops-dontusecopy-ignore", "true|FALSE", 2, 0, 0,
594 #if defined(HAVE_CYRUS_SASL) && defined(SLAP_AUXPROP_DONTUSECOPY)
595 ARG_ON_OFF|CFG_AZDUC_IGNORE, &slap_dontUseCopy_ignore,
599 "( OLcfgGlAt:92 NAME 'olcSaslAuxpropsDontUseCopyIgnore' "
600 "EQUALITY booleanMatch "
601 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
602 { "sasl-host", "host", 2, 2, 0,
603 #ifdef HAVE_CYRUS_SASL
604 ARG_STRING|ARG_UNIQUE, &sasl_host,
608 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
609 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
610 { "sasl-realm", "realm", 2, 2, 0,
611 #ifdef HAVE_CYRUS_SASL
612 ARG_STRING|ARG_UNIQUE, &global_realm,
616 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
617 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
618 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
619 &config_generic, NULL, NULL, NULL },
620 { "sasl-secprops", "properties", 2, 2, 0,
621 #ifdef HAVE_CYRUS_SASL
622 ARG_MAGIC|CFG_SASLSECP, &config_generic,
626 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
627 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
628 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
629 &config_generic, NULL, NULL, NULL },
630 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
631 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
632 "EQUALITY distinguishedNameMatch "
633 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
634 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
635 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
636 "EQUALITY caseIgnoreMatch "
637 "SYNTAX OMsDirectoryString )", NULL, NULL },
638 { "serverID", "number> <[URI]", 2, 3, 0, ARG_MAGIC|CFG_SERVERID,
639 &config_generic, "( OLcfgGlAt:81 NAME 'olcServerID' "
640 "EQUALITY caseIgnoreMatch "
641 "SYNTAX OMsDirectoryString )", NULL, NULL },
642 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
643 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
644 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
645 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
646 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
647 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
648 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
649 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
650 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
651 { "sortvals", "attr", 2, 0, 0, ARG_MAGIC|CFG_SORTVALS,
652 &config_generic, "( OLcfgGlAt:83 NAME 'olcSortVals' "
653 "DESC 'Attributes whose values will always be sorted' "
654 "EQUALITY caseIgnoreMatch "
655 "SYNTAX OMsDirectoryString )", NULL, NULL },
656 { "subordinate", "[advertise]", 1, 2, 0, ARG_DB|ARG_MAGIC,
657 &config_subordinate, "( OLcfgDbAt:0.15 NAME 'olcSubordinate' "
658 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
659 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
660 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
661 "EQUALITY distinguishedNameMatch "
662 "SYNTAX OMsDN )", NULL, NULL },
663 { "sync_use_subentry", NULL, 0, 0, 0, ARG_ON_OFF|ARG_DB|ARG_MAGIC|CFG_SYNC_SUBENTRY,
664 &config_generic, "( OLcfgDbAt:0.19 NAME 'olcSyncUseSubentry' "
665 "DESC 'Store sync context in a subentry' "
666 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
667 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
668 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
669 "EQUALITY caseIgnoreMatch "
670 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
671 { "tcp-buffer", "[listener=<listener>] [{read|write}=]size", 0, 0, 0,
672 #ifndef LDAP_TCP_BUFFER
674 #else /* LDAP_TCP_BUFFER */
675 ARG_MAGIC, &config_tcp_buffer,
676 #endif /* LDAP_TCP_BUFFER */
677 "( OLcfgGlAt:90 NAME 'olcTCPBuffer' "
678 "DESC 'Custom TCP buffer size' "
679 "SYNTAX OMsDirectoryString )", NULL, NULL },
680 { "threads", "count", 2, 2, 0,
684 ARG_INT|ARG_MAGIC|CFG_THREADS, &config_generic,
686 "( OLcfgGlAt:66 NAME 'olcThreads' "
687 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
688 { "threadqueues", "count", 2, 2, 0,
692 ARG_INT|ARG_MAGIC|CFG_THREADQS, &config_generic,
694 "( OLcfgGlAt:95 NAME 'olcThreadQueues' "
695 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
696 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
697 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
698 "SYNTAX OMsDirectoryString )", NULL, NULL },
699 { "TLSCACertificateFile", NULL, 2, 2, 0,
701 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
705 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
706 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
707 { "TLSCACertificatePath", NULL, 2, 2, 0,
709 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
713 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
714 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
715 { "TLSCertificateFile", NULL, 2, 2, 0,
717 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
721 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
722 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
723 { "TLSCertificateKeyFile", NULL, 2, 2, 0,
725 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
729 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
730 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
731 { "TLSCipherSuite", NULL, 2, 2, 0,
733 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
737 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
738 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
739 { "TLSCRLCheck", NULL, 2, 2, 0,
740 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
741 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
745 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
746 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
747 { "TLSCRLFile", NULL, 2, 2, 0,
748 #if defined(HAVE_GNUTLS)
749 CFG_TLS_CRL_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
753 "( OLcfgGlAt:82 NAME 'olcTLSCRLFile' "
754 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
755 { "TLSRandFile", NULL, 2, 2, 0,
757 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
761 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
762 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
763 { "TLSVerifyClient", NULL, 2, 2, 0,
765 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
769 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
770 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
771 { "TLSDHParamFile", NULL, 2, 2, 0,
773 CFG_TLS_DH_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
777 "( OLcfgGlAt:77 NAME 'olcTLSDHParamFile' "
778 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
779 { "TLSECName", NULL, 2, 2, 0,
781 CFG_TLS_ECNAME|ARG_STRING|ARG_MAGIC, &config_tls_option,
785 "( OLcfgGlAt:96 NAME 'olcTLSECName' "
786 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
787 { "TLSProtocolMin", NULL, 2, 2, 0,
789 CFG_TLS_PROTOCOL_MIN|ARG_STRING|ARG_MAGIC, &config_tls_config,
793 "( OLcfgGlAt:87 NAME 'olcTLSProtocolMin' "
794 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
795 { "tool-threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_TTHREADS,
796 &config_generic, "( OLcfgGlAt:80 NAME 'olcToolThreads' "
797 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
798 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
799 NULL, NULL, NULL, NULL },
800 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
801 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
802 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
803 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
804 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
805 "EQUALITY caseIgnoreMatch "
806 "SUP labeledURI )", NULL, NULL },
807 { "writetimeout", "timeout", 2, 2, 0, ARG_INT,
808 &global_writetimeout, "( OLcfgGlAt:88 NAME 'olcWriteTimeout' "
809 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
810 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
811 NULL, NULL, NULL, NULL }
814 /* Need to no-op this keyword for dynamic config */
815 ConfigTable olcDatabaseDummy[] = {
816 { "", "", 0, 0, 0, ARG_IGNORED,
817 NULL, "( OLcfgGlAt:13 NAME 'olcDatabase' "
818 "DESC 'The backend type for a database instance' "
819 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
820 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
823 /* Routines to check if a child can be added to this type */
824 static ConfigLDAPadd cfAddSchema, cfAddInclude, cfAddDatabase,
825 cfAddBackend, cfAddModule, cfAddOverlay;
827 /* NOTE: be careful when defining array members
828 * that can be conditionally compiled */
829 #define CFOC_GLOBAL cf_ocs[1]
830 #define CFOC_SCHEMA cf_ocs[2]
831 #define CFOC_BACKEND cf_ocs[3]
832 #define CFOC_DATABASE cf_ocs[4]
833 #define CFOC_OVERLAY cf_ocs[5]
834 #define CFOC_INCLUDE cf_ocs[6]
835 #define CFOC_FRONTEND cf_ocs[7]
837 #define CFOC_MODULE cf_ocs[8]
838 #endif /* SLAPD_MODULES */
840 static ConfigOCs cf_ocs[] = {
843 "DESC 'OpenLDAP configuration object' "
844 "ABSTRACT SUP top )", Cft_Abstract, NULL },
847 "DESC 'OpenLDAP Global configuration options' "
848 "SUP olcConfig STRUCTURAL "
849 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
850 "olcAttributeOptions $ olcAuthIDRewrite $ "
851 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
852 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
853 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
854 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
855 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcIndexHash64 $ "
857 "olcListenerThreads $ olcLocalSSF $ olcLogFile $ olcLogLevel $ "
858 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
859 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
860 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
862 "olcSaslAuxprops $ olcSaslAuxpropsDontUseCopy $ olcSaslAuxpropsDontUseCopyIgnore $ "
863 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
864 "olcSecurity $ olcServerID $ olcSizeLimit $ "
865 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ "
867 "olcThreads $ olcThreadQueues $ "
868 "olcTimeLimit $ olcTLSCACertificateFile $ "
869 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
870 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
871 "olcTLSRandFile $ olcTLSVerifyClient $ olcTLSDHParamFile $ olcTLSECName $ "
872 "olcTLSCRLFile $ olcToolThreads $ olcWriteTimeout $ "
873 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
874 "olcDitContentRules $ olcLdapSyntaxes ) )", Cft_Global },
876 "NAME 'olcSchemaConfig' "
877 "DESC 'OpenLDAP schema object' "
878 "SUP olcConfig STRUCTURAL "
879 "MAY ( cn $ olcObjectIdentifier $ olcLdapSyntaxes $ "
880 "olcAttributeTypes $ olcObjectClasses $ olcDitContentRules ) )",
881 Cft_Schema, NULL, cfAddSchema },
883 "NAME 'olcBackendConfig' "
884 "DESC 'OpenLDAP Backend-specific options' "
885 "SUP olcConfig STRUCTURAL "
886 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
888 "NAME 'olcDatabaseConfig' "
889 "DESC 'OpenLDAP Database-specific options' "
890 "SUP olcConfig STRUCTURAL "
892 "MAY ( olcDisabled $ olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
893 "olcAddContentAcl $ olcLastMod $ olcLimits $ "
894 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
895 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
896 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
897 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncUseSubentry $ olcSyncrepl $ "
898 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef $ olcMirrorMode $ "
899 "olcMonitoring $ olcExtraAttrs ) )",
900 Cft_Database, NULL, cfAddDatabase },
902 "NAME 'olcOverlayConfig' "
903 "DESC 'OpenLDAP Overlay-specific options' "
904 "SUP olcConfig STRUCTURAL "
906 "MAY olcDisabled )", Cft_Overlay, NULL, cfAddOverlay },
908 "NAME 'olcIncludeFile' "
909 "DESC 'OpenLDAP configuration include file' "
910 "SUP olcConfig STRUCTURAL "
912 "MAY ( cn $ olcRootDSE ) )",
913 /* Used to be Cft_Include, that def has been removed */
914 Cft_Abstract, NULL, cfAddInclude },
915 /* This should be STRUCTURAL like all the other database classes, but
916 * that would mean inheriting all of the olcDatabaseConfig attributes,
917 * which causes them to be merged twice in config_build_entry.
920 "NAME 'olcFrontendConfig' "
921 "DESC 'OpenLDAP frontend configuration' "
923 "MAY ( olcDefaultSearchBase $ olcPasswordHash $ olcSortVals ) )",
924 Cft_Database, NULL, NULL },
927 "NAME 'olcModuleList' "
928 "DESC 'OpenLDAP dynamic module info' "
929 "SUP olcConfig STRUCTURAL "
930 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
931 Cft_Module, NULL, cfAddModule },
936 typedef struct ServerID {
937 struct ServerID *si_next;
938 struct berval si_url;
942 static ServerID *sid_list;
943 static ServerID *sid_set;
945 typedef struct voidList {
946 struct voidList *vl_next;
950 typedef struct ADlist {
951 struct ADlist *al_next;
952 AttributeDescription *al_desc;
955 static ADlist *sortVals;
958 config_generic(ConfigArgs *c) {
961 if ( c->op == SLAP_CONFIG_EMIT ) {
965 c->value_int = ldap_pvt_thread_get_concurrency();
968 c->value_int = connection_pool_max;
971 c->value_int = connection_pool_queues;
974 c->value_int = slap_tool_thread_max;
977 c->value_uint = slapd_daemon_threads;
981 c->value_string = ch_strdup( passwd_salt );
986 if ( c->be->be_limits ) {
990 for ( i=0; c->be->be_limits[i]; i++ ) {
991 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
992 if ( bv.bv_len >= sizeof( buf ) ) {
993 ber_bvarray_free_x( c->rvalue_vals, NULL );
994 c->rvalue_vals = NULL;
998 bv.bv_val = buf + bv.bv_len;
999 limits_unparse( c->be->be_limits[i], &bv,
1000 sizeof( buf ) - ( bv.bv_val - buf ) );
1001 bv.bv_len += bv.bv_val - buf;
1003 value_add_one( &c->rvalue_vals, &bv );
1006 if ( !c->rvalue_vals ) rc = 1;
1009 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_READONLY);
1012 c->value_string = ch_strdup( slap_sasl_getpolicy());
1015 slap_sasl_regexp_unparse( &c->rvalue_vals );
1016 if ( !c->rvalue_vals ) rc = 1;
1018 #ifdef HAVE_CYRUS_SASL
1019 #ifdef SLAP_AUXPROP_DONTUSECOPY
1021 static int duc_done = 0;
1023 /* take the opportunity to initialize with known values */
1025 struct berval duc[] = { BER_BVC("cmusaslsecretOTP"), BER_BVNULL };
1028 for ( i = 0; !BER_BVISNULL( &duc[ i ] ); i++ ) {
1029 const char *text = NULL;
1030 AttributeDescription *ad = NULL;
1032 if ( slap_bv2ad( &duc[ i ], &ad, &text ) == LDAP_SUCCESS ) {
1034 if ( slap_dontUseCopy_propnames ) {
1037 for ( j = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ j ] ); j++ ) {
1038 if ( bvmatch( &slap_dontUseCopy_propnames[ j ], &ad->ad_cname ) ) {
1045 value_add_one( &slap_dontUseCopy_propnames, &ad->ad_cname );
1053 if ( slap_dontUseCopy_propnames != NULL ) {
1054 ber_bvarray_dup_x( &c->rvalue_vals, slap_dontUseCopy_propnames, NULL );
1059 #endif /* SLAP_AUXPROP_DONTUSECOPY */
1060 case CFG_SASLSECP: {
1061 struct berval bv = BER_BVNULL;
1062 slap_sasl_secprops_unparse( &bv );
1063 if ( !BER_BVISNULL( &bv )) {
1064 ber_bvarray_add( &c->rvalue_vals, &bv );
1072 c->value_int = c->be->be_max_deref_depth;
1077 if ( c->bi->bi_flags & SLAPO_BFLAG_DISABLED ) {
1084 if ( SLAP_DBDISABLED( c->be )) {
1092 if ( SLAP_DBHIDDEN( c->be )) {
1099 ConfigFile *cf = c->ca_private;
1101 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1102 else if ( cf->c_om_head )
1103 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
1105 if ( !c->rvalue_vals )
1110 ad_unparse_options( &c->rvalue_vals );
1113 ConfigFile *cf = c->ca_private;
1115 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1116 else if ( cf->c_oc_head )
1117 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
1119 if ( !c->rvalue_vals )
1124 ConfigFile *cf = c->ca_private;
1126 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1127 else if ( cf->c_at_head )
1128 at_unparse( &c->rvalue_vals, cf->c_at_head,
1130 if ( !c->rvalue_vals )
1135 ConfigFile *cf = c->ca_private;
1137 syn_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1138 else if ( cf->c_syn_head )
1139 syn_unparse( &c->rvalue_vals, cf->c_syn_head,
1140 cf->c_syn_tail, 0 );
1141 if ( !c->rvalue_vals )
1146 ConfigFile *cf = c->ca_private;
1148 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1149 else if ( cf->c_cr_head )
1150 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
1152 if ( !c->rvalue_vals )
1159 char *src, *dst, ibuf[11];
1160 struct berval bv, abv;
1161 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
1162 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1163 if ( abv.bv_len >= sizeof( ibuf ) ) {
1164 ber_bvarray_free_x( c->rvalue_vals, NULL );
1165 c->rvalue_vals = NULL;
1169 acl_unparse( a, &bv );
1170 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
1171 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
1172 /* Turn TAB / EOL into plain space */
1173 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
1174 if (isspace((unsigned char)*src)) *dst++ = ' ';
1178 if (dst[-1] == ' ') {
1182 abv.bv_len = dst - abv.bv_val;
1183 ber_bvarray_add( &c->rvalue_vals, &abv );
1189 c->value_int = (SLAP_DBACL_ADD(c->be) != 0);
1192 ConfigFile *cf = c->ca_private;
1193 if ( cf->c_dseFiles ) {
1194 value_add( &c->rvalue_vals, cf->c_dseFiles );
1205 for ( si = sid_list; si; si=si->si_next ) {
1206 assert( si->si_num >= 0 && si->si_num <= SLAP_SYNC_SID_MAX );
1207 if ( !BER_BVISEMPTY( &si->si_url )) {
1208 bv.bv_len = si->si_url.bv_len + 6;
1209 bv.bv_val = ch_malloc( bv.bv_len );
1210 bv.bv_len = sprintf( bv.bv_val, "%d %s", si->si_num,
1211 si->si_url.bv_val );
1212 ber_bvarray_add( &c->rvalue_vals, &bv );
1216 bv.bv_len = sprintf( buf, "%d", si->si_num );
1217 value_add_one( &c->rvalue_vals, &bv );
1226 c->value_string = ch_strdup( logfileName );
1231 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1233 case CFG_SYNC_SUBENTRY:
1234 c->value_int = (SLAP_SYNC_SUBENTRY(c->be) != 0);
1236 case CFG_MIRRORMODE:
1237 if ( SLAP_SHADOW(c->be))
1238 c->value_int = (SLAP_MULTIMASTER(c->be) != 0);
1242 case CFG_MONITORING:
1243 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
1245 case CFG_SSTR_IF_MAX:
1246 c->value_uint = index_substr_if_maxlen;
1248 case CFG_SSTR_IF_MIN:
1249 c->value_uint = index_substr_if_minlen;
1252 c->value_int = slap_hash64( -1 );
1255 c->value_int = index_intlen;
1257 case CFG_SORTVALS: {
1260 for ( sv = sortVals; sv; sv = sv->al_next ) {
1261 value_add_one( &c->rvalue_vals, &sv->al_desc->ad_cname );
1265 #ifdef SLAPD_MODULES
1267 ModPaths *mp = c->ca_private;
1270 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
1273 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
1274 SLAP_X_ORDERED_FMT "%s", i,
1275 mp->mp_loads[i].bv_val );
1276 if ( bv.bv_len >= sizeof( c->log ) ) {
1277 ber_bvarray_free_x( c->rvalue_vals, NULL );
1278 c->rvalue_vals = NULL;
1281 value_add_one( &c->rvalue_vals, &bv );
1285 rc = c->rvalue_vals ? 0 : 1;
1289 ModPaths *mp = c->ca_private;
1290 if ( !BER_BVISNULL( &mp->mp_path ))
1291 value_add_one( &c->rvalue_vals, &mp->mp_path );
1293 rc = c->rvalue_vals ? 0 : 1;
1299 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1300 if ( !c->rvalue_vals ) rc = 1;
1303 #ifdef SLAP_AUTH_REWRITE
1305 if ( authz_rewrites ) {
1306 struct berval bv, idx;
1311 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1312 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1313 if ( idx.bv_len >= sizeof( ibuf ) ) {
1314 ber_bvarray_free_x( c->rvalue_vals, NULL );
1315 c->rvalue_vals = NULL;
1318 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1319 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1320 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1321 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1322 authz_rewrites[i].bv_val,
1323 authz_rewrites[i].bv_len + 1 );
1324 ber_bvarray_add( &c->rvalue_vals, &bv );
1327 if ( !c->rvalue_vals ) rc = 1;
1334 } else if ( c->op == LDAP_MOD_DELETE ) {
1337 /* single-valued attrs, no-ops */
1347 case CFG_MONITORING:
1349 case CFG_SSTR_IF_MAX:
1350 case CFG_SSTR_IF_MIN:
1352 case CFG_SYNC_SUBENTRY:
1355 /* no-ops, requires slapd restart */
1360 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1363 case CFG_MIRRORMODE:
1364 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MULTI_SHADOW;
1365 if(SLAP_SHADOW(c->be))
1366 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1369 #if defined(HAVE_CYRUS_SASL) && defined(SLAP_AUXPROP_DONTUSECOPY)
1371 if ( c->valx < 0 ) {
1372 if ( slap_dontUseCopy_propnames != NULL ) {
1373 ber_bvarray_free( slap_dontUseCopy_propnames );
1374 slap_dontUseCopy_propnames = NULL;
1380 if ( slap_dontUseCopy_propnames == NULL ) {
1385 for ( i = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ i ] ) && i < c->valx; i++ );
1386 if ( i < c->valx ) {
1390 ber_memfree( slap_dontUseCopy_propnames[ i ].bv_val );
1391 for ( ; !BER_BVISNULL( &slap_dontUseCopy_propnames[ i + 1 ] ); i++ ) {
1392 slap_dontUseCopy_propnames[ i ] = slap_dontUseCopy_propnames[ i + 1 ];
1394 BER_BVZERO( &slap_dontUseCopy_propnames[ i ] );
1397 #endif /* SLAP_AUXPROP_DONTUSECOPY */
1399 ch_free( passwd_salt );
1404 ch_free( logfileName );
1412 case CFG_SERVERID: {
1413 ServerID *si, **sip;
1415 for ( i=0, si = sid_list, sip = &sid_list;
1416 si; si = *sip, i++ ) {
1417 if ( c->valx == -1 || i == c->valx ) {
1419 if ( sid_set == si )
1431 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1436 c->bi->bi_flags &= ~SLAP_DBFLAG_DISABLED;
1437 if ( c->bi->bi_db_open ) {
1438 BackendInfo *bi_orig = c->be->bd_info;
1439 c->be->bd_info = c->bi;
1440 rc = c->bi->bi_db_open( c->be, &c->reply );
1441 c->be->bd_info = bi_orig;
1444 c->be->be_flags &= ~SLAP_DBFLAG_DISABLED;
1445 rc = backend_startup_one( c->be, &c->reply );
1454 index_intlen = SLAP_INDEX_INTLEN_DEFAULT;
1455 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1456 SLAP_INDEX_INTLEN_DEFAULT );
1460 if ( c->valx < 0 ) {
1461 acl_destroy( c->be->be_acl );
1462 c->be->be_acl = NULL;
1465 AccessControl **prev, *a;
1467 for (i=0, prev = &c->be->be_acl; i < c->valx;
1470 prev = &a->acl_next;
1473 *prev = a->acl_next;
1476 if ( SLAP_CONFIG( c->be ) && !c->be->be_acl ) {
1477 Debug( LDAP_DEBUG_CONFIG, "config_generic (CFG_ACL): "
1478 "Last explicit ACL for back-config removed. "
1479 "Using hardcoded default\n", 0, 0, 0 );
1480 c->be->be_acl = defacl_parsed;
1486 /* Can be NULL when undoing a failed add */
1487 if ( c->ca_entry ) {
1488 ce = c->ca_entry->e_private;
1489 /* can't modify the hardcoded schema */
1490 if ( ce->ce_parent->ce_type == Cft_Global )
1494 cfn = c->ca_private;
1495 if ( c->valx < 0 ) {
1498 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1500 if ( oc == cfn->c_oc_tail )
1503 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1505 ObjectClass *oc, *prev = NULL;
1507 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1512 if ( cfn->c_oc_tail == oc ) {
1513 cfn->c_oc_tail = prev;
1515 if ( cfn->c_oc_head == oc ) {
1517 cfn->c_oc_head = oc;
1524 /* Can be NULL when undoing a failed add */
1525 if ( c->ca_entry ) {
1526 ce = c->ca_entry->e_private;
1527 /* can't modify the hardcoded schema */
1528 if ( ce->ce_parent->ce_type == Cft_Global )
1532 cfn = c->ca_private;
1533 if ( c->valx < 0 ) {
1536 for( at = cfn->c_at_head; at; at_next( &at )) {
1538 if ( at == cfn->c_at_tail )
1541 cfn->c_at_head = cfn->c_at_tail = NULL;
1543 AttributeType *at, *prev = NULL;
1545 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1550 if ( cfn->c_at_tail == at ) {
1551 cfn->c_at_tail = prev;
1553 if ( cfn->c_at_head == at ) {
1555 cfn->c_at_head = at;
1562 /* Can be NULL when undoing a failed add */
1563 if ( c->ca_entry ) {
1564 ce = c->ca_entry->e_private;
1565 /* can't modify the hardcoded schema */
1566 if ( ce->ce_parent->ce_type == Cft_Global )
1570 cfn = c->ca_private;
1571 if ( c->valx < 0 ) {
1574 for( syn = cfn->c_syn_head; syn; syn_next( &syn )) {
1576 if ( syn == cfn->c_syn_tail )
1579 cfn->c_syn_head = cfn->c_syn_tail = NULL;
1581 Syntax *syn, *prev = NULL;
1583 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++) {
1588 if ( cfn->c_syn_tail == syn ) {
1589 cfn->c_syn_tail = prev;
1591 if ( cfn->c_syn_head == syn ) {
1593 cfn->c_syn_head = syn;
1598 if ( c->valx < 0 ) {
1600 for ( sv = sortVals; sv; sv = sortVals ) {
1601 sortVals = sv->al_next;
1602 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1609 for ( prev = &sortVals, sv = sortVals; i < c->valx; i++ ) {
1610 prev = &sv->al_next;
1613 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1614 *prev = sv->al_next;
1620 /* FIXME: there is no limits_free function */
1621 if ( c->valx < 0 ) {
1622 limits_destroy( c->be->be_limits );
1623 c->be->be_limits = NULL;
1628 if ( c->be->be_limits ) {
1629 for ( num = 0; c->be->be_limits[ num ]; num++ )
1633 if ( c->valx >= num ) {
1638 limits_destroy( c->be->be_limits );
1639 c->be->be_limits = NULL;
1642 limits_free_one( c->be->be_limits[ c->valx ] );
1644 for ( cnt = c->valx; cnt < num; cnt++ ) {
1645 c->be->be_limits[ cnt ] = c->be->be_limits[ cnt + 1 ];
1652 /* FIXME: there is no ad_option_free function */
1654 /* FIXME: there is no way to remove attributes added by
1668 if(!(c->bi = backend_info(c->argv[1]))) {
1669 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1670 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1671 c->log, c->cr_msg, c->argv[1] );
1678 /* NOTE: config is always the first backend!
1680 if ( !strcasecmp( c->argv[1], "config" )) {
1681 c->be = LDAP_STAILQ_FIRST(&backendDB);
1682 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1685 c->be = backend_db_init(c->argv[1], NULL, c->valx, &c->reply);
1687 if ( c->cr_msg[0] == 0 )
1688 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1689 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n", c->log, c->cr_msg, c->argv[1] );
1696 ldap_pvt_thread_set_concurrency(c->value_int);
1700 if ( c->value_int < 2 ) {
1701 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1702 "threads=%d smaller than minimum value 2",
1704 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1705 c->log, c->cr_msg, 0 );
1708 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1709 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1710 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1711 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1712 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1713 c->log, c->cr_msg, 0 );
1715 if ( slapMode & SLAP_SERVER_MODE )
1716 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1717 connection_pool_max = c->value_int; /* save for reference */
1721 if ( c->value_int < 1 ) {
1722 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1723 "threadqueuess=%d smaller than minimum value 1",
1725 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1726 c->log, c->cr_msg, 0 );
1729 if ( slapMode & SLAP_SERVER_MODE )
1730 ldap_pvt_thread_pool_queues(&connection_pool, c->value_int);
1731 connection_pool_queues = c->value_int; /* save for reference */
1735 if ( slapMode & SLAP_TOOL_MODE )
1736 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1737 slap_tool_thread_max = c->value_int; /* save for reference */
1742 /* use a power of two */
1743 while (c->value_uint > 1) {
1744 c->value_uint >>= 1;
1748 slapd_daemon_mask = mask;
1749 slapd_daemon_threads = mask+1;
1754 if ( passwd_salt ) ch_free( passwd_salt );
1755 passwd_salt = c->value_string;
1756 lutil_salt_format(passwd_salt);
1760 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1766 c->be->be_restrictops |= SLAP_RESTRICT_READONLY;
1768 c->be->be_restrictops &= ~SLAP_RESTRICT_READONLY;
1772 ch_free(c->value_string);
1773 if (slap_sasl_setpolicy( c->argv[1] )) {
1774 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
1775 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1776 c->log, c->cr_msg, c->argv[1] );
1782 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1786 #ifdef HAVE_CYRUS_SASL
1787 #ifdef SLAP_AUXPROP_DONTUSECOPY
1791 for ( arg = 1; arg < c->argc; arg++ ) {
1792 int duplicate = 0, err;
1793 AttributeDescription *ad = NULL;
1794 const char *text = NULL;
1796 err = slap_str2ad( c->argv[ arg ], &ad, &text );
1797 if ( err != LDAP_SUCCESS ) {
1798 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s>: attr #%d (\"%s\") unknown (err=%d \"%s\"; ignored)",
1799 c->argv[0], arg, c->argv[ arg ], err, text );
1800 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1801 c->log, c->cr_msg, 0 );
1804 if ( slap_dontUseCopy_propnames != NULL ) {
1805 for ( cnt = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ cnt ] ); cnt++ ) {
1806 if ( bvmatch( &slap_dontUseCopy_propnames[ cnt ], &ad->ad_cname ) ) {
1814 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s>: attr #%d (\"%s\") already defined (ignored)",
1815 c->argv[0], arg, ad->ad_cname.bv_val);
1816 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1817 c->log, c->cr_msg, 0 );
1821 value_add_one( &slap_dontUseCopy_propnames, &ad->ad_cname );
1826 #endif /* SLAP_AUXPROP_DONTUSECOPY */
1830 char *txt = slap_sasl_secprops( c->argv[1] );
1832 snprintf( c->cr_msg, sizeof(c->cr_msg), "<%s> %s",
1834 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0 );
1842 c->be->be_max_deref_depth = c->value_int;
1848 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1849 cfn = c->ca_private;
1850 if(parse_oidm(c, 1, &om))
1852 if (!cfn->c_om_head) cfn->c_om_head = om;
1853 cfn->c_om_tail = om;
1858 ObjectClass *oc, *prev;
1860 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1861 cfn = c->ca_private;
1862 if ( c->valx < 0 ) {
1863 prev = cfn->c_oc_tail;
1866 /* If adding anything after the first, prev is easy */
1869 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
1871 if ( !oc_next( &oc ))
1875 /* If adding the first, and head exists, find its prev */
1876 if (cfn->c_oc_head) {
1877 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
1882 /* else prev is NULL, append to end of global list */
1884 if(parse_oc(c, &oc, prev)) return(1);
1885 if (!cfn->c_oc_head || !c->valx) cfn->c_oc_head = oc;
1886 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
1891 AttributeType *at, *prev;
1893 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1894 cfn = c->ca_private;
1895 if ( c->valx < 0 ) {
1896 prev = cfn->c_at_tail;
1899 /* If adding anything after the first, prev is easy */
1902 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
1904 if ( !at_next( &at ))
1908 /* If adding the first, and head exists, find its prev */
1909 if (cfn->c_at_head) {
1910 for ( at_start( &at ); at != cfn->c_at_head; ) {
1915 /* else prev is NULL, append to end of global list */
1917 if(parse_at(c, &at, prev)) return(1);
1918 if (!cfn->c_at_head || !c->valx) cfn->c_at_head = at;
1919 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
1926 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1927 cfn = c->ca_private;
1928 if ( c->valx < 0 ) {
1929 prev = cfn->c_syn_tail;
1932 /* If adding anything after the first, prev is easy */
1935 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++ ) {
1937 if ( !syn_next( &syn ))
1941 /* If adding the first, and head exists, find its prev */
1942 if (cfn->c_syn_head) {
1943 for ( syn_start( &syn ); syn != cfn->c_syn_head; ) {
1948 /* else prev is NULL, append to end of global list */
1950 if ( parse_syn( c, &syn, prev ) ) return(1);
1951 if ( !cfn->c_syn_head || !c->valx ) cfn->c_syn_head = syn;
1952 if ( cfn->c_syn_tail == prev ) cfn->c_syn_tail = syn;
1959 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1960 cfn = c->ca_private;
1961 if(parse_cr(c, &cr)) return(1);
1962 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1963 cfn->c_cr_tail = cr;
1968 ad_define_option(NULL, NULL, 0);
1969 for(i = 1; i < c->argc; i++)
1970 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1975 if ( slap_hash64( c->value_int != 0 ))
1980 if ( c->value_int < SLAP_INDEX_INTLEN_DEFAULT )
1981 c->value_int = SLAP_INDEX_INTLEN_DEFAULT;
1982 else if ( c->value_int > 255 )
1984 index_intlen = c->value_int;
1985 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1989 case CFG_SORTVALS: {
1990 ADlist *svnew = NULL, *svtail, *sv;
1992 for ( i = 1; i < c->argc; i++ ) {
1993 AttributeDescription *ad = NULL;
1997 rc = slap_str2ad( c->argv[i], &ad, &text );
1999 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown attribute type #%d",
2002 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2003 c->log, c->cr_msg, c->argv[i] );
2004 for ( sv = svnew; sv; sv = svnew ) {
2005 svnew = sv->al_next;
2010 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) ||
2011 ad->ad_type->sat_single_value ) {
2012 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> inappropriate attribute type #%d",
2014 goto sortval_reject;
2016 sv = ch_malloc( sizeof( ADlist ));
2021 svtail->al_next = sv;
2026 for ( sv = svnew; sv; sv = sv->al_next )
2027 sv->al_desc->ad_type->sat_flags |= SLAP_AT_SORTED_VAL;
2028 for ( sv = sortVals; sv && sv->al_next; sv = sv->al_next );
2030 sv->al_next = svnew;
2037 if ( SLAP_CONFIG( c->be ) && c->be->be_acl == defacl_parsed) {
2038 c->be->be_acl = NULL;
2040 /* Don't append to the global ACL if we're on a specific DB */
2042 if ( c->valx == -1 ) {
2045 for ( a=c->be->be_acl; a; a = a->acl_next )
2048 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
2049 if ( SLAP_CONFIG( c->be ) && !c->be->be_acl) {
2050 c->be->be_acl = defacl_parsed;
2058 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_ACL_ADD;
2060 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_ACL_ADD;
2064 if(root_dse_read_file(c->argv[1])) {
2065 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> could not read file", c->argv[0] );
2066 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2067 c->log, c->cr_msg, c->argv[1] );
2072 ber_str2bv( c->argv[1], 0, 1, &bv );
2073 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
2074 cfn = c->ca_private;
2075 ber_bvarray_add( &cfn->c_dseFiles, &bv );
2081 ServerID *si, **sip;
2084 if (( lutil_atoi( &num, c->argv[1] ) &&
2085 lutil_atoix( &num, c->argv[1], 16 )) ||
2086 num < 0 || num > SLAP_SYNC_SID_MAX )
2088 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2089 "<%s> illegal server ID", c->argv[0] );
2090 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2091 c->log, c->cr_msg, c->argv[1] );
2094 /* only one value allowed if no URL is given */
2095 if ( c->argc > 2 ) {
2098 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
2099 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2100 "<%s> only one server ID allowed now", c->argv[0] );
2101 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2102 c->log, c->cr_msg, c->argv[1] );
2106 if ( ldap_url_parse( c->argv[2], &lud )) {
2107 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2108 "<%s> invalid URL", c->argv[0] );
2109 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2110 c->log, c->cr_msg, c->argv[2] );
2113 len = strlen( c->argv[2] );
2114 si = ch_malloc( sizeof(ServerID) + len + 1 );
2115 si->si_url.bv_val = (char *)(si+1);
2116 si->si_url.bv_len = len;
2117 strcpy( si->si_url.bv_val, c->argv[2] );
2120 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2121 "<%s> unqualified server ID not allowed now", c->argv[0] );
2122 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2123 c->log, c->cr_msg, c->argv[1] );
2126 si = ch_malloc( sizeof(ServerID) );
2127 BER_BVZERO( &si->si_url );
2128 slap_serverID = num;
2129 Debug( LDAP_DEBUG_CONFIG,
2131 c->log, slap_serverID, 0 );
2136 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
2139 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
2140 Listener *l = config_check_my_url( c->argv[2], lud );
2143 ldap_free_urldesc( lud );
2144 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2145 "<%s> multiple server ID URLs matched, only one is allowed", c->argv[0] );
2146 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2147 c->log, c->cr_msg, c->argv[1] );
2150 slap_serverID = si->si_num;
2151 Debug( LDAP_DEBUG_CONFIG,
2152 "%s: SID=0x%03x (listener=%s)\n",
2153 c->log, slap_serverID,
2159 ldap_free_urldesc( lud );
2163 if ( logfileName ) ch_free( logfileName );
2164 logfileName = c->value_string;
2165 logfile = fopen(logfileName, "w");
2166 if(logfile) lutil_debug_file(logfile);
2170 if(SLAP_NOLASTMODCMD(c->be)) {
2171 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> not available for %s database",
2172 c->argv[0], c->be->bd_info->bi_type );
2173 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2174 c->log, c->cr_msg, 0 );
2178 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
2180 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
2183 case CFG_MIRRORMODE:
2184 if(c->value_int && !SLAP_SHADOW(c->be)) {
2185 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database is not a shadow",
2187 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2188 c->log, c->cr_msg, 0 );
2192 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
2193 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MULTI_SHADOW;
2195 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
2196 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MULTI_SHADOW;
2200 case CFG_MONITORING:
2202 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
2204 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
2210 if ( c->bi->bi_db_close ) {
2211 BackendInfo *bi_orig = c->be->bd_info;
2212 c->be->bd_info = c->bi;
2213 c->bi->bi_db_close( c->be, &c->reply );
2214 c->be->bd_info = bi_orig;
2216 c->bi->bi_flags |= SLAPO_BFLAG_DISABLED;
2218 c->bi->bi_flags &= ~SLAPO_BFLAG_DISABLED;
2222 backend_shutdown( c->be );
2223 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_DISABLED;
2225 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_DISABLED;
2232 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
2234 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
2237 case CFG_SYNC_SUBENTRY:
2239 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SYNC_SUBENTRY;
2241 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SYNC_SUBENTRY;
2244 case CFG_SSTR_IF_MAX:
2245 if (c->value_uint < index_substr_if_minlen) {
2246 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
2247 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
2248 c->log, c->cr_msg, c->value_int );
2251 index_substr_if_maxlen = c->value_uint;
2254 case CFG_SSTR_IF_MIN:
2255 if (c->value_uint > index_substr_if_maxlen) {
2256 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
2257 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
2258 c->log, c->cr_msg, c->value_int );
2261 index_substr_if_minlen = c->value_uint;
2264 #ifdef SLAPD_MODULES
2266 /* If we're just adding a module on an existing modpath,
2267 * make sure we've selected the current path.
2269 if ( c->op == LDAP_MOD_ADD && c->ca_private && modcur != c->ca_private ) {
2270 modcur = c->ca_private;
2271 /* This should never fail */
2272 if ( module_path( modcur->mp_path.bv_val )) {
2273 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> module path no longer valid",
2275 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2276 c->log, c->cr_msg, modcur->mp_path.bv_val );
2280 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
2282 /* Record this load on the current path */
2286 if ( c->op == SLAP_CONFIG_ADD ) {
2287 ptr = c->line + STRLENOF("moduleload");
2288 while (!isspace((unsigned char) *ptr)) ptr++;
2289 while (isspace((unsigned char) *ptr)) ptr++;
2293 ber_str2bv(ptr, 0, 1, &bv);
2294 ber_bvarray_add( &modcur->mp_loads, &bv );
2296 /* Check for any new hardcoded schema */
2297 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
2298 config_check_schema( NULL, &cfBackInfo );
2303 if(module_path(c->argv[1])) return(1);
2304 /* Record which path was used with each module */
2308 if (!modpaths.mp_loads) {
2311 mp = ch_malloc( sizeof( ModPaths ));
2312 modlast->mp_next = mp;
2314 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
2316 mp->mp_loads = NULL;
2327 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
2329 slapi_plugins_used++;
2333 #ifdef SLAP_AUTH_REWRITE
2339 if ( c->op == LDAP_MOD_ADD ) {
2343 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
2347 if ( c->argc > 1 ) {
2350 /* quote all args but the first */
2351 line = ldap_charray2str( c->argv, "\" \"" );
2352 ber_str2bv( line, 0, 0, &bv );
2353 s = ber_bvchr( &bv, '"' );
2354 assert( s != NULL );
2355 /* move the trailing quote of argv[0] to the end */
2356 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
2357 bv.bv_val[ bv.bv_len - 1 ] = '"';
2360 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
2363 ber_bvarray_add( &authz_rewrites, &bv );
2365 if ( c->op == LDAP_MOD_ADD ) {
2375 Debug( LDAP_DEBUG_ANY,
2376 "%s: unknown CFG_TYPE %d.\n",
2377 c->log, c->type, 0 );
2386 config_fname(ConfigArgs *c) {
2387 if(c->op == SLAP_CONFIG_EMIT) {
2388 if (c->ca_private) {
2389 ConfigFile *cf = c->ca_private;
2390 value_add_one( &c->rvalue_vals, &cf->c_file );
2399 config_cfdir(ConfigArgs *c) {
2400 if(c->op == SLAP_CONFIG_EMIT) {
2401 if ( !BER_BVISEMPTY( &cfdir )) {
2402 value_add_one( &c->rvalue_vals, &cfdir );
2411 config_search_base(ConfigArgs *c) {
2412 if(c->op == SLAP_CONFIG_EMIT) {
2414 if (!BER_BVISEMPTY(&default_search_base)) {
2415 value_add_one(&c->rvalue_vals, &default_search_base);
2416 value_add_one(&c->rvalue_nvals, &default_search_nbase);
2420 } else if( c->op == LDAP_MOD_DELETE ) {
2421 ch_free( default_search_base.bv_val );
2422 ch_free( default_search_nbase.bv_val );
2423 BER_BVZERO( &default_search_base );
2424 BER_BVZERO( &default_search_nbase );
2428 if(c->bi || c->be != frontendDB) {
2429 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
2430 "prior to any backend or database definition\n",
2435 if(default_search_nbase.bv_len) {
2436 free(default_search_base.bv_val);
2437 free(default_search_nbase.bv_val);
2440 default_search_base = c->value_dn;
2441 default_search_nbase = c->value_ndn;
2445 /* For RE23 compatibility we allow this in the global entry
2446 * but we now defer it to the frontend entry to allow modules
2447 * to load new hash types.
2450 config_passwd_hash(ConfigArgs *c) {
2452 if (c->op == SLAP_CONFIG_EMIT) {
2454 /* Don't generate it in the global entry */
2455 if ( c->table == Cft_Global )
2457 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
2458 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
2459 value_add_one(&c->rvalue_vals, &bv);
2462 } else if ( c->op == LDAP_MOD_DELETE ) {
2463 /* Deleting from global is a no-op, only the frontendDB entry matters */
2464 if ( c->table == Cft_Global )
2466 if ( c->valx < 0 ) {
2467 ldap_charray_free( default_passwd_hash );
2468 default_passwd_hash = NULL;
2471 ch_free( default_passwd_hash[i] );
2472 for (; default_passwd_hash[i]; i++ )
2473 default_passwd_hash[i] = default_passwd_hash[i+1];
2477 for(i = 1; i < c->argc; i++) {
2478 if(!lutil_passwd_scheme(c->argv[i])) {
2479 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> scheme not available", c->argv[0] );
2480 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2481 c->log, c->cr_msg, c->argv[i]);
2483 ldap_charray_add(&default_passwd_hash, c->argv[i]);
2486 if(!default_passwd_hash) {
2487 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> no valid hashes found", c->argv[0] );
2488 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2489 c->log, c->cr_msg, 0 );
2496 config_schema_dn(ConfigArgs *c) {
2497 if ( c->op == SLAP_CONFIG_EMIT ) {
2499 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
2500 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
2501 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
2505 } else if ( c->op == LDAP_MOD_DELETE ) {
2506 ch_free( c->be->be_schemadn.bv_val );
2507 ch_free( c->be->be_schemandn.bv_val );
2508 BER_BVZERO( &c->be->be_schemadn );
2509 BER_BVZERO( &c->be->be_schemandn );
2512 ch_free( c->be->be_schemadn.bv_val );
2513 ch_free( c->be->be_schemandn.bv_val );
2514 c->be->be_schemadn = c->value_dn;
2515 c->be->be_schemandn = c->value_ndn;
2520 config_sizelimit(ConfigArgs *c) {
2522 struct slap_limits_set *lim = &c->be->be_def_limit;
2523 if (c->op == SLAP_CONFIG_EMIT) {
2528 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
2529 if ( !BER_BVISEMPTY( &bv ))
2530 value_add_one( &c->rvalue_vals, &bv );
2534 } else if ( c->op == LDAP_MOD_DELETE ) {
2535 /* Reset to defaults or values from frontend */
2536 if ( c->be == frontendDB ) {
2537 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
2538 lim->lms_s_hard = 0;
2539 lim->lms_s_unchecked = -1;
2541 lim->lms_s_pr_hide = 0;
2542 lim->lms_s_pr_total = 0;
2544 lim->lms_s_soft = frontendDB->be_def_limit.lms_s_soft;
2545 lim->lms_s_hard = frontendDB->be_def_limit.lms_s_hard;
2546 lim->lms_s_unchecked = frontendDB->be_def_limit.lms_s_unchecked;
2547 lim->lms_s_pr = frontendDB->be_def_limit.lms_s_pr;
2548 lim->lms_s_pr_hide = frontendDB->be_def_limit.lms_s_pr_hide;
2549 lim->lms_s_pr_total = frontendDB->be_def_limit.lms_s_pr_total;
2553 for(i = 1; i < c->argc; i++) {
2554 if(!strncasecmp(c->argv[i], "size", 4)) {
2555 rc = limits_parse_one(c->argv[i], lim);
2557 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2558 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2559 c->log, c->cr_msg, c->argv[i]);
2563 if(!strcasecmp(c->argv[i], "unlimited")) {
2564 lim->lms_s_soft = -1;
2566 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
2567 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2568 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2569 c->log, c->cr_msg, c->argv[i]);
2573 lim->lms_s_hard = 0;
2578 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2579 /* This is a modification to the global limits apply it to
2580 * the other databases as needed */
2581 AttributeDescription *ad=NULL;
2582 const char *text = NULL;
2583 CfEntryInfo *ce = c->ca_entry->e_private;
2585 slap_str2ad(c->argv[0], &ad, &text);
2586 /* if we got here... */
2587 assert( ad != NULL );
2589 if ( ce->ce_type == Cft_Global ){
2592 for (; ce; ce=ce->ce_sibs) {
2593 Entry *dbe = ce->ce_entry;
2594 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2595 && (!attr_find(dbe->e_attrs, ad)) ) {
2596 ce->ce_be->be_def_limit.lms_s_soft = lim->lms_s_soft;
2597 ce->ce_be->be_def_limit.lms_s_hard = lim->lms_s_hard;
2598 ce->ce_be->be_def_limit.lms_s_unchecked =lim->lms_s_unchecked;
2599 ce->ce_be->be_def_limit.lms_s_pr =lim->lms_s_pr;
2600 ce->ce_be->be_def_limit.lms_s_pr_hide =lim->lms_s_pr_hide;
2601 ce->ce_be->be_def_limit.lms_s_pr_total =lim->lms_s_pr_total;
2609 config_timelimit(ConfigArgs *c) {
2611 struct slap_limits_set *lim = &c->be->be_def_limit;
2612 if (c->op == SLAP_CONFIG_EMIT) {
2617 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
2618 if ( !BER_BVISEMPTY( &bv ))
2619 value_add_one( &c->rvalue_vals, &bv );
2623 } else if ( c->op == LDAP_MOD_DELETE ) {
2624 /* Reset to defaults or values from frontend */
2625 if ( c->be == frontendDB ) {
2626 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
2627 lim->lms_t_hard = 0;
2629 lim->lms_t_soft = frontendDB->be_def_limit.lms_t_soft;
2630 lim->lms_t_hard = frontendDB->be_def_limit.lms_t_hard;
2634 for(i = 1; i < c->argc; i++) {
2635 if(!strncasecmp(c->argv[i], "time", 4)) {
2636 rc = limits_parse_one(c->argv[i], lim);
2638 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2639 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2640 c->log, c->cr_msg, c->argv[i]);
2644 if(!strcasecmp(c->argv[i], "unlimited")) {
2645 lim->lms_t_soft = -1;
2647 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
2648 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2649 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2650 c->log, c->cr_msg, c->argv[i]);
2654 lim->lms_t_hard = 0;
2659 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2660 /* This is a modification to the global limits apply it to
2661 * the other databases as needed */
2662 AttributeDescription *ad=NULL;
2663 const char *text = NULL;
2664 CfEntryInfo *ce = c->ca_entry->e_private;
2666 slap_str2ad(c->argv[0], &ad, &text);
2667 /* if we got here... */
2668 assert( ad != NULL );
2670 if ( ce->ce_type == Cft_Global ){
2673 for (; ce; ce=ce->ce_sibs) {
2674 Entry *dbe = ce->ce_entry;
2675 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2676 && (!attr_find(dbe->e_attrs, ad)) ) {
2677 ce->ce_be->be_def_limit.lms_t_soft = lim->lms_t_soft;
2678 ce->ce_be->be_def_limit.lms_t_hard = lim->lms_t_hard;
2686 config_overlay(ConfigArgs *c) {
2687 if (c->op == SLAP_CONFIG_EMIT) {
2689 } else if ( c->op == LDAP_MOD_DELETE ) {
2692 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2693 c->valx, &c->bi, &c->reply)) {
2695 Debug( LDAP_DEBUG_ANY,
2696 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2697 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2699 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi, &c->reply)) {
2706 config_subordinate(ConfigArgs *c)
2712 case SLAP_CONFIG_EMIT:
2713 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2716 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2717 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2720 value_add_one( &c->rvalue_vals, &bv );
2724 case LDAP_MOD_DELETE:
2725 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2726 glue_sub_del( c->be );
2728 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2733 case SLAP_CONFIG_ADD:
2734 if ( c->be->be_nsuffix == NULL ) {
2736 snprintf( c->cr_msg, sizeof( c->cr_msg),
2737 "subordinate configuration needs a suffix" );
2738 Debug( LDAP_DEBUG_ANY,
2740 c->log, c->cr_msg, 0 );
2745 if ( c->argc == 2 ) {
2746 if ( strcasecmp( c->argv[1], "advertise" ) == 0 ) {
2749 } else if ( strcasecmp( c->argv[1], "TRUE" ) != 0 ) {
2751 snprintf( c->cr_msg, sizeof( c->cr_msg),
2752 "subordinate must be \"TRUE\" or \"advertise\"" );
2753 Debug( LDAP_DEBUG_ANY,
2754 "%s: suffix \"%s\": %s.\n",
2755 c->log, c->be->be_suffix[0].bv_val, c->cr_msg );
2761 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2769 * [listener=<listener>] [{read|write}=]<size>
2772 #ifdef LDAP_TCP_BUFFER
2773 static BerVarray tcp_buffer;
2776 #define SLAP_TCP_RMEM (0x1U)
2777 #define SLAP_TCP_WMEM (0x2U)
2780 tcp_buffer_parse( struct berval *val, int argc, char **argv,
2781 int *size, int *rw, Listener **l )
2783 int i, rc = LDAP_SUCCESS;
2784 LDAPURLDesc *lud = NULL;
2787 if ( val != NULL && argv == NULL ) {
2788 char *s = val->bv_val;
2790 argv = ldap_str2charray( s, " \t" );
2791 if ( argv == NULL ) {
2797 if ( strncasecmp( argv[ i ], "listener=", STRLENOF( "listener=" ) )
2800 char *url = argv[ i ] + STRLENOF( "listener=" );
2802 if ( ldap_url_parse( url, &lud ) ) {
2803 rc = LDAP_INVALID_SYNTAX;
2807 *l = config_check_my_url( url, lud );
2809 rc = LDAP_NO_SUCH_ATTRIBUTE;
2817 if ( strncasecmp( ptr, "read=", STRLENOF( "read=" ) ) == 0 ) {
2818 *rw |= SLAP_TCP_RMEM;
2819 ptr += STRLENOF( "read=" );
2821 } else if ( strncasecmp( ptr, "write=", STRLENOF( "write=" ) ) == 0 ) {
2822 *rw |= SLAP_TCP_WMEM;
2823 ptr += STRLENOF( "write=" );
2826 *rw |= ( SLAP_TCP_RMEM | SLAP_TCP_WMEM );
2829 /* accept any base */
2830 if ( lutil_atoix( size, ptr, 0 ) ) {
2831 rc = LDAP_INVALID_SYNTAX;
2836 if ( val != NULL && argv != NULL ) {
2837 ldap_charray_free( argv );
2840 if ( lud != NULL ) {
2841 ldap_free_urldesc( lud );
2848 tcp_buffer_delete_one( struct berval *val )
2851 int size = -1, rw = 0;
2854 rc = tcp_buffer_parse( val, 0, NULL, &size, &rw, &l );
2861 Listener **ll = slapd_get_listeners();
2863 for ( i = 0; ll[ i ] != NULL; i++ ) {
2864 if ( ll[ i ] == l ) break;
2867 if ( ll[ i ] == NULL ) {
2868 return LDAP_NO_SUCH_ATTRIBUTE;
2871 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = -1;
2872 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = -1;
2874 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2875 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = -1;
2876 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = -1;
2880 /* NOTE: this affects listeners without a specific setting,
2881 * does not reset all listeners. If a listener without
2882 * specific settings was assigned a buffer because of
2883 * a global setting, it will not be reset. In any case,
2884 * buffer changes will only take place at restart. */
2885 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = -1;
2886 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = -1;
2893 tcp_buffer_delete( BerVarray vals )
2897 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
2898 tcp_buffer_delete_one( &vals[ i ] );
2905 tcp_buffer_unparse( int size, int rw, Listener *l, struct berval *val )
2907 char buf[sizeof("2147483648")], *ptr;
2909 /* unparse for later use */
2910 val->bv_len = snprintf( buf, sizeof( buf ), "%d", size );
2912 val->bv_len += STRLENOF( "listener=" " " ) + l->sl_url.bv_len;
2915 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2916 if ( rw & SLAP_TCP_RMEM ) {
2917 val->bv_len += STRLENOF( "read=" );
2918 } else if ( rw & SLAP_TCP_WMEM ) {
2919 val->bv_len += STRLENOF( "write=" );
2923 val->bv_val = SLAP_MALLOC( val->bv_len + 1 );
2928 ptr = lutil_strcopy( ptr, "listener=" );
2929 ptr = lutil_strncopy( ptr, l->sl_url.bv_val, l->sl_url.bv_len );
2933 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2934 if ( rw & SLAP_TCP_RMEM ) {
2935 ptr = lutil_strcopy( ptr, "read=" );
2936 } else if ( rw & SLAP_TCP_WMEM ) {
2937 ptr = lutil_strcopy( ptr, "write=" );
2941 ptr = lutil_strcopy( ptr, buf );
2944 assert( val->bv_val + val->bv_len == ptr );
2946 return LDAP_SUCCESS;
2950 tcp_buffer_add_one( int argc, char **argv )
2953 int size = -1, rw = 0;
2959 rc = tcp_buffer_parse( NULL, argc, argv, &size, &rw, &l );
2964 /* unparse for later use */
2965 rc = tcp_buffer_unparse( size, rw, l, &val );
2966 if ( rc != LDAP_SUCCESS ) {
2970 /* use parsed values */
2973 Listener **ll = slapd_get_listeners();
2975 for ( i = 0; ll[ i ] != NULL; i++ ) {
2976 if ( ll[ i ] == l ) break;
2979 if ( ll[ i ] == NULL ) {
2980 return LDAP_NO_SUCH_ATTRIBUTE;
2983 /* buffer only applies to TCP listeners;
2984 * we do not do any check here, and delegate them
2985 * to setsockopt(2) */
2986 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = size;
2987 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = size;
2989 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2990 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = size;
2991 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = size;
2995 /* NOTE: this affects listeners without a specific setting,
2996 * does not set all listeners */
2997 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = size;
2998 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = size;
3001 tcp_buffer = SLAP_REALLOC( tcp_buffer, sizeof( struct berval ) * ( tcp_buffer_num + 2 ) );
3003 tcp_buffer[ tcp_buffer_num ] = val;
3006 BER_BVZERO( &tcp_buffer[ tcp_buffer_num ] );
3012 config_tcp_buffer( ConfigArgs *c )
3014 if ( c->op == SLAP_CONFIG_EMIT ) {
3015 if ( tcp_buffer == NULL || BER_BVISNULL( &tcp_buffer[ 0 ] ) ) {
3018 value_add( &c->rvalue_vals, tcp_buffer );
3019 value_add( &c->rvalue_nvals, tcp_buffer );
3021 } else if ( c->op == LDAP_MOD_DELETE ) {
3023 tcp_buffer_delete( tcp_buffer );
3024 ber_bvarray_free( tcp_buffer );
3030 int size = -1, rw = 0;
3033 struct berval val = BER_BVNULL;
3037 if ( tcp_buffer_num == 0 ) {
3042 rc = tcp_buffer_parse( NULL, c->argc - 1, &c->argv[ 1 ], &size, &rw, &l );
3047 /* unparse for later use */
3048 rc = tcp_buffer_unparse( size, rw, l, &val );
3049 if ( rc != LDAP_SUCCESS ) {
3053 for ( i = 0; !BER_BVISNULL( &tcp_buffer[ i ] ); i++ ) {
3054 if ( bvmatch( &tcp_buffer[ i ], &val ) ) {
3059 if ( BER_BVISNULL( &tcp_buffer[ i ] ) ) {
3065 tcp_buffer_delete_one( &tcp_buffer[ i ] );
3066 ber_memfree( tcp_buffer[ i ].bv_val );
3067 for ( ; i < tcp_buffer_num; i++ ) {
3068 tcp_buffer[ i ] = tcp_buffer[ i + 1 ];
3073 if ( !BER_BVISNULL( &val ) ) {
3074 SLAP_FREE( val.bv_val );
3082 rc = tcp_buffer_add_one( c->argc - 1, &c->argv[ 1 ] );
3084 snprintf( c->cr_msg, sizeof( c->cr_msg ),
3085 "<%s> unable to add value #%d",
3086 c->argv[0], tcp_buffer_num );
3087 Debug( LDAP_DEBUG_ANY, "%s: %s\n",
3088 c->log, c->cr_msg, 0 );
3095 #endif /* LDAP_TCP_BUFFER */
3098 config_suffix(ConfigArgs *c)
3101 struct berval pdn, ndn;
3102 char *notallowed = NULL;
3104 if ( c->be == frontendDB ) {
3105 notallowed = "frontend";
3107 } else if ( SLAP_MONITOR(c->be) ) {
3108 notallowed = "monitor";
3110 } else if ( SLAP_CONFIG(c->be) ) {
3111 notallowed = "config";
3114 if ( notallowed != NULL ) {
3115 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
3119 case LDAP_MOD_DELETE:
3120 case LDAP_MOD_REPLACE:
3121 case LDAP_MOD_INCREMENT:
3122 case SLAP_CONFIG_ADD:
3123 if ( !BER_BVISNULL( &c->value_dn ) ) {
3124 snprintf( buf, sizeof( buf ), "<%s> ",
3125 c->value_dn.bv_val );
3128 Debug(LDAP_DEBUG_ANY,
3129 "%s: suffix %snot allowed in %s database.\n",
3130 c->log, buf, notallowed );
3133 case SLAP_CONFIG_EMIT:
3134 /* don't complain when emitting... */
3138 /* FIXME: don't know what values may be valid;
3139 * please remove assertion, or add legal values
3140 * to either block */
3148 if (c->op == SLAP_CONFIG_EMIT) {
3149 if ( c->be->be_suffix == NULL
3150 || BER_BVISNULL( &c->be->be_suffix[0] ) )
3154 value_add( &c->rvalue_vals, c->be->be_suffix );
3155 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
3158 } else if ( c->op == LDAP_MOD_DELETE ) {
3159 if ( c->valx < 0 ) {
3160 ber_bvarray_free( c->be->be_suffix );
3161 ber_bvarray_free( c->be->be_nsuffix );
3162 c->be->be_suffix = NULL;
3163 c->be->be_nsuffix = NULL;
3166 ch_free( c->be->be_suffix[i].bv_val );
3167 ch_free( c->be->be_nsuffix[i].bv_val );
3169 c->be->be_suffix[i] = c->be->be_suffix[i+1];
3170 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
3172 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
3177 #ifdef SLAPD_MONITOR_DN
3178 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
3179 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> DN is reserved for monitoring slapd",
3181 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3182 c->log, c->cr_msg, SLAPD_MONITOR_DN);
3187 if (SLAP_DB_ONE_SUFFIX( c->be ) && c->be->be_suffix &&
3188 !BER_BVISNULL( &c->be->be_suffix[0] )) {
3189 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> Only one suffix is allowed on this %s backend",
3190 c->argv[0], c->be->bd_info->bi_type );
3191 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3192 c->log, c->cr_msg, 0);
3199 if (SLAP_DBHIDDEN( c->be ))
3202 tbe = select_backend(&ndn, 0);
3204 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
3210 BackendDB *b2 = tbe;
3212 /* Does tbe precede be? */
3213 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
3216 char *type = tbe->bd_info->bi_type;
3218 if ( overlay_is_over( tbe ) ) {
3219 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
3220 type = oi->oi_orig->bi_type;
3223 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> namingContext \"%s\" "
3224 "already served by a preceding %s database",
3225 c->argv[0], pdn.bv_val, type );
3226 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
3227 c->log, c->cr_msg, tbe->be_suffix[0].bv_val);
3233 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
3234 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
3235 "base provided \"%s\" (assuming okay)\n",
3236 c->log, default_search_base.bv_val, 0);
3238 ber_bvarray_add(&c->be->be_suffix, &pdn);
3239 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
3244 config_rootdn(ConfigArgs *c) {
3245 if (c->op == SLAP_CONFIG_EMIT) {
3246 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
3247 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
3248 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
3253 } else if ( c->op == LDAP_MOD_DELETE ) {
3254 ch_free( c->be->be_rootdn.bv_val );
3255 ch_free( c->be->be_rootndn.bv_val );
3256 BER_BVZERO( &c->be->be_rootdn );
3257 BER_BVZERO( &c->be->be_rootndn );
3260 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
3261 ch_free( c->be->be_rootdn.bv_val );
3262 ch_free( c->be->be_rootndn.bv_val );
3264 c->be->be_rootdn = c->value_dn;
3265 c->be->be_rootndn = c->value_ndn;
3270 config_rootpw(ConfigArgs *c) {
3273 if (c->op == SLAP_CONFIG_EMIT) {
3274 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
3275 /* don't copy, because "rootpw" is marked
3277 c->value_bv = c->be->be_rootpw;
3281 } else if ( c->op == LDAP_MOD_DELETE ) {
3282 ch_free( c->be->be_rootpw.bv_val );
3283 BER_BVZERO( &c->be->be_rootpw );
3287 tbe = select_backend(&c->be->be_rootndn, 0);
3289 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> can only be set when rootdn is under suffix",
3291 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3292 c->log, c->cr_msg, 0);
3295 if ( !BER_BVISNULL( &c->be->be_rootpw ))
3296 ch_free( c->be->be_rootpw.bv_val );
3297 c->be->be_rootpw = c->value_bv;
3302 config_restrict(ConfigArgs *c) {
3303 slap_mask_t restrictops = 0;
3305 slap_verbmasks restrictable_ops[] = {
3306 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
3307 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
3308 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
3309 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
3310 { BER_BVC("modrdn"), 0 },
3311 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
3312 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
3313 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
3314 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
3315 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
3316 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
3317 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
3318 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
3319 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
3320 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
3321 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
3325 if (c->op == SLAP_CONFIG_EMIT) {
3326 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
3328 } else if ( c->op == LDAP_MOD_DELETE ) {
3330 c->be->be_restrictops = 0;
3332 i = verb_to_mask( c->line, restrictable_ops );
3333 c->be->be_restrictops &= ~restrictable_ops[i].mask;
3337 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
3339 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown operation", c->argv[0] );
3340 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3341 c->log, c->cr_msg, c->argv[i]);
3344 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
3345 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
3346 c->be->be_restrictops |= restrictops;
3351 config_allows(ConfigArgs *c) {
3352 slap_mask_t allows = 0;
3354 slap_verbmasks allowable_ops[] = {
3355 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
3356 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
3357 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
3358 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
3359 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
3362 if (c->op == SLAP_CONFIG_EMIT) {
3363 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
3364 } else if ( c->op == LDAP_MOD_DELETE ) {
3368 i = verb_to_mask( c->line, allowable_ops );
3369 global_allows &= ~allowable_ops[i].mask;
3373 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
3375 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3376 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3377 c->log, c->cr_msg, c->argv[i]);
3380 global_allows |= allows;
3385 config_disallows(ConfigArgs *c) {
3386 slap_mask_t disallows = 0;
3388 slap_verbmasks disallowable_ops[] = {
3389 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
3390 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
3391 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
3392 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
3393 { BER_BVC("proxy_authz_non_critical"), SLAP_DISALLOW_PROXY_AUTHZ_N_CRIT },
3394 { BER_BVC("dontusecopy_non_critical"), SLAP_DISALLOW_DONTUSECOPY_N_CRIT },
3397 if (c->op == SLAP_CONFIG_EMIT) {
3398 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
3399 } else if ( c->op == LDAP_MOD_DELETE ) {
3401 global_disallows = 0;
3403 i = verb_to_mask( c->line, disallowable_ops );
3404 global_disallows &= ~disallowable_ops[i].mask;
3408 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
3410 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3411 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3412 c->log, c->cr_msg, c->argv[i]);
3415 global_disallows |= disallows;
3420 config_requires(ConfigArgs *c) {
3421 slap_mask_t requires = frontendDB->be_requires;
3422 int i, argc = c->argc;
3423 char **argv = c->argv;
3425 slap_verbmasks requires_ops[] = {
3426 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
3427 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
3428 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
3429 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
3430 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
3433 if (c->op == SLAP_CONFIG_EMIT) {
3434 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
3435 } else if ( c->op == LDAP_MOD_DELETE ) {
3437 c->be->be_requires = 0;
3439 i = verb_to_mask( c->line, requires_ops );
3440 c->be->be_requires &= ~requires_ops[i].mask;
3444 /* "none" can only be first, to wipe out default/global values */
3445 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
3450 i = verbs_to_mask(argc, argv, requires_ops, &requires);
3452 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
3453 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
3454 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3455 c->log, c->cr_msg, 0);
3457 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
3458 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3459 c->log, c->cr_msg, c->argv[i]);
3463 c->be->be_requires = requires;
3468 config_extra_attrs(ConfigArgs *c)
3470 assert( c->be != NULL );
3472 if ( c->op == SLAP_CONFIG_EMIT ) {
3475 if ( c->be->be_extra_anlist == NULL ) {
3479 for ( i = 0; !BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ); i++ ) {
3480 value_add_one( &c->rvalue_vals, &c->be->be_extra_anlist[i].an_name );
3483 } else if ( c->op == LDAP_MOD_DELETE ) {
3484 if ( c->be->be_extra_anlist == NULL ) {
3488 if ( c->valx < 0 ) {
3489 anlist_free( c->be->be_extra_anlist, 1, NULL );
3490 c->be->be_extra_anlist = NULL;
3495 for ( i = 0; i < c->valx && !BER_BVISNULL( &c->be->be_extra_anlist[i + 1].an_name ); i++ )
3498 if ( BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ) ) {
3502 ch_free( c->be->be_extra_anlist[i].an_name.bv_val );
3504 for ( ; !BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ); i++ ) {
3505 c->be->be_extra_anlist[i] = c->be->be_extra_anlist[i + 1];
3510 c->be->be_extra_anlist = str2anlist( c->be->be_extra_anlist, c->argv[1], " ,\t" );
3511 if ( c->be->be_extra_anlist == NULL ) {
3519 static slap_verbmasks *loglevel_ops;
3522 loglevel_init( void )
3524 slap_verbmasks lo[] = {
3525 { BER_BVC("Any"), (slap_mask_t) LDAP_DEBUG_ANY },
3526 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
3527 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
3528 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
3529 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
3530 { BER_BVC("BER"), LDAP_DEBUG_BER },
3531 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
3532 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
3533 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
3534 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
3535 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
3536 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
3537 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
3538 #if 0 /* no longer used (nor supported) */
3539 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
3540 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
3542 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
3543 { BER_BVC("None"), LDAP_DEBUG_NONE },
3547 return slap_verbmasks_init( &loglevel_ops, lo );
3551 loglevel_destroy( void )
3553 if ( loglevel_ops ) {
3554 (void)slap_verbmasks_destroy( loglevel_ops );
3556 loglevel_ops = NULL;
3559 static slap_mask_t loglevel_ignore[] = { -1, 0 };
3562 slap_loglevel_register( slap_mask_t m, struct berval *s )
3566 if ( loglevel_ops == NULL ) {
3570 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
3573 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
3581 slap_loglevel_get( struct berval *s, int *l )
3586 if ( loglevel_ops == NULL ) {
3590 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3591 m |= loglevel_ops[ i ].mask;
3594 for ( i = 1; m & i; i <<= 1 )
3601 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
3604 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
3615 str2loglevel( const char *s, int *l )
3619 if ( loglevel_ops == NULL ) {
3623 i = verb_to_mask( s, loglevel_ops );
3625 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
3629 *l = loglevel_ops[ i ].mask;
3635 loglevel2str( int l )
3637 struct berval bv = BER_BVNULL;
3639 loglevel2bv( l, &bv );
3645 loglevel2bv( int l, struct berval *bv )
3647 if ( loglevel_ops == NULL ) {
3653 return enum_to_verb( loglevel_ops, l, bv ) == -1;
3657 loglevel2bvarray( int l, BerVarray *bva )
3659 if ( loglevel_ops == NULL ) {
3664 return value_add_one( bva, ber_bvstr( "0" ) );
3667 return mask_to_verbs( loglevel_ops, l, bva );
3671 loglevel_print( FILE *out )
3675 if ( loglevel_ops == NULL ) {
3679 fprintf( out, "Installed log subsystems:\n\n" );
3680 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3681 unsigned mask = loglevel_ops[ i ].mask & 0xffffffffUL;
3683 (mask == ((slap_mask_t) -1 & 0xffffffffUL)
3684 ? "\t%-30s (-1, 0xffffffff)\n" : "\t%-30s (%u, 0x%x)\n"),
3685 loglevel_ops[ i ].word.bv_val, mask, mask );
3688 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
3689 "by specific code\n\n" );
3694 static int config_syslog;
3697 config_loglevel(ConfigArgs *c) {
3700 if ( loglevel_ops == NULL ) {
3704 if (c->op == SLAP_CONFIG_EMIT) {
3705 /* Get default or commandline slapd setting */
3706 if ( ldap_syslog && !config_syslog )
3707 config_syslog = ldap_syslog;
3708 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
3710 } else if ( c->op == LDAP_MOD_DELETE ) {
3714 i = verb_to_mask( c->line, loglevel_ops );
3715 config_syslog &= ~loglevel_ops[i].mask;
3717 if ( slapMode & SLAP_SERVER_MODE ) {
3718 ldap_syslog = config_syslog;
3723 for( i=1; i < c->argc; i++ ) {
3726 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
3727 if( lutil_atoix( &level, c->argv[i], 0 ) != 0 ) {
3728 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse level", c->argv[0] );
3729 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3730 c->log, c->cr_msg, c->argv[i]);
3734 if ( str2loglevel( c->argv[i], &level ) ) {
3735 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown level", c->argv[0] );
3736 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3737 c->log, c->cr_msg, c->argv[i]);
3741 /* Explicitly setting a zero clears all the levels */
3743 config_syslog |= level;
3747 if ( slapMode & SLAP_SERVER_MODE ) {
3748 ldap_syslog = config_syslog;
3754 config_referral(ConfigArgs *c) {
3756 if (c->op == SLAP_CONFIG_EMIT) {
3757 if ( default_referral ) {
3758 value_add( &c->rvalue_vals, default_referral );
3763 } else if ( c->op == LDAP_MOD_DELETE ) {
3764 if ( c->valx < 0 ) {
3765 ber_bvarray_free( default_referral );
3766 default_referral = NULL;
3769 ch_free( default_referral[i].bv_val );
3770 for (; default_referral[i].bv_val; i++ )
3771 default_referral[i] = default_referral[i+1];
3775 if(validate_global_referral(c->argv[1])) {
3776 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3777 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3778 c->log, c->cr_msg, c->argv[1]);
3782 ber_str2bv(c->argv[1], 0, 0, &val);
3783 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
3791 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
3792 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
3793 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
3794 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
3795 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
3796 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
3797 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
3798 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
3799 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
3804 config_security(ConfigArgs *c) {
3805 slap_ssf_set_t *set = &c->be->be_ssf_set;
3808 if (c->op == SLAP_CONFIG_EMIT) {
3814 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
3815 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
3818 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
3819 if ( bv.bv_len >= sizeof( numbuf ) ) {
3820 ber_bvarray_free_x( c->rvalue_vals, NULL );
3821 c->rvalue_vals = NULL;
3825 bv.bv_len += sec_keys[i].key.bv_len;
3826 bv.bv_val = ch_malloc( bv.bv_len + 1);
3827 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
3828 strcpy( next, numbuf );
3829 ber_bvarray_add( &c->rvalue_vals, &bv );
3834 for(i = 1; i < c->argc; i++) {
3835 slap_ssf_t *tgt = NULL;
3837 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
3838 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
3839 sec_keys[j].key.bv_len)) {
3840 src = c->argv[i] + sec_keys[j].key.bv_len;
3841 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
3846 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown factor", c->argv[0] );
3847 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3848 c->log, c->cr_msg, c->argv[i]);
3852 if ( lutil_atou( tgt, src ) != 0 ) {
3853 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse factor", c->argv[0] );
3854 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3855 c->log, c->cr_msg, c->argv[i]);
3863 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
3867 for (; !BER_BVISNULL( &an->an_name ); an++) {
3868 /* if buflen == 0, assume the buffer size has been
3869 * already checked otherwise */
3870 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
3871 if ( comma ) *ptr++ = ',';
3872 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
3879 config_updatedn(ConfigArgs *c) {
3880 if (c->op == SLAP_CONFIG_EMIT) {
3881 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
3882 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
3883 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
3887 } else if ( c->op == LDAP_MOD_DELETE ) {
3888 ch_free( c->be->be_update_ndn.bv_val );
3889 BER_BVZERO( &c->be->be_update_ndn );
3890 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
3893 if(SLAP_SHADOW(c->be)) {
3894 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database already shadowed", c->argv[0] );
3895 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3896 c->log, c->cr_msg, 0);
3900 ber_memfree_x( c->value_dn.bv_val, NULL );
3901 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
3902 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
3904 c->be->be_update_ndn = c->value_ndn;
3905 BER_BVZERO( &c->value_dn );
3906 BER_BVZERO( &c->value_ndn );
3908 return config_slurp_shadow( c );
3912 config_shadow( ConfigArgs *c, slap_mask_t flag )
3914 char *notallowed = NULL;
3916 if ( c->be == frontendDB ) {
3917 notallowed = "frontend";
3919 } else if ( SLAP_MONITOR(c->be) ) {
3920 notallowed = "monitor";
3923 if ( notallowed != NULL ) {
3924 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
3928 if ( SLAP_SHADOW(c->be) ) {
3929 /* if already shadow, only check consistency */
3930 if ( ( SLAP_DBFLAGS(c->be) & flag ) != flag ) {
3931 Debug( LDAP_DEBUG_ANY, "%s: inconsistent shadow flag 0x%lx.\n",
3937 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | flag);
3938 if ( !SLAP_MULTIMASTER( c->be ))
3939 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
3946 config_updateref(ConfigArgs *c) {
3948 if (c->op == SLAP_CONFIG_EMIT) {
3949 if ( c->be->be_update_refs ) {
3950 value_add( &c->rvalue_vals, c->be->be_update_refs );
3955 } else if ( c->op == LDAP_MOD_DELETE ) {
3956 if ( c->valx < 0 ) {
3957 ber_bvarray_free( c->be->be_update_refs );
3958 c->be->be_update_refs = NULL;
3961 ch_free( c->be->be_update_refs[i].bv_val );
3962 for (; c->be->be_update_refs[i].bv_val; i++)
3963 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
3967 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
3968 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must appear after syncrepl or updatedn",
3970 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3971 c->log, c->cr_msg, 0);
3975 if(validate_global_referral(c->argv[1])) {
3976 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3977 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3978 c->log, c->cr_msg, c->argv[1]);
3981 ber_str2bv(c->argv[1], 0, 0, &val);
3982 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
3987 config_obsolete(ConfigArgs *c) {
3988 if (c->op == SLAP_CONFIG_EMIT)
3991 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> keyword is obsolete (ignored)",
3993 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0);
3998 config_include(ConfigArgs *c) {
3999 int savelineno = c->lineno;
4002 ConfigFile *cfsave = cfn;
4003 ConfigFile *cf2 = NULL;
4005 /* Leftover from RE23. No dynamic config for include files */
4006 if ( c->op == SLAP_CONFIG_EMIT || c->op == LDAP_MOD_DELETE )
4009 cf = ch_calloc( 1, sizeof(ConfigFile));
4010 if ( cfn->c_kids ) {
4011 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
4017 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
4018 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
4019 c->lineno = savelineno - 1;
4022 if ( cf2 ) cf2->c_sibs = NULL;
4023 else cfn->c_kids = NULL;
4024 ch_free( cf->c_file.bv_val );
4034 config_tls_cleanup(ConfigArgs *c) {
4037 if ( slap_tls_ld ) {
4040 ldap_pvt_tls_ctx_free( slap_tls_ctx );
4041 slap_tls_ctx = NULL;
4043 /* Force new ctx to be created */
4044 rc = ldap_pvt_tls_set_option( slap_tls_ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
4046 /* The ctx's refcount is bumped up here */
4047 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CTX, &slap_tls_ctx );
4048 /* This is a no-op if it's already loaded */
4049 load_extop( &slap_EXOP_START_TLS, 0, starttls_extop );
4051 if ( rc == LDAP_NOT_SUPPORTED )
4052 rc = LDAP_UNWILLING_TO_PERFORM;
4061 config_tls_option(ConfigArgs *c) {
4063 LDAP *ld = slap_tls_ld;
4065 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
4066 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
4067 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
4068 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
4069 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
4070 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
4071 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
4072 case CFG_TLS_ECNAME: flag = LDAP_OPT_X_TLS_ECNAME; break;
4074 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
4076 default: Debug(LDAP_DEBUG_ANY, "%s: "
4077 "unknown tls_option <0x%x>\n",
4078 c->log, c->type, 0);
4081 if (c->op == SLAP_CONFIG_EMIT) {
4082 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
4083 } else if ( c->op == LDAP_MOD_DELETE ) {
4084 c->cleanup = config_tls_cleanup;
4085 return ldap_pvt_tls_set_option( ld, flag, NULL );
4087 ch_free(c->value_string);
4088 c->cleanup = config_tls_cleanup;
4089 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
4092 /* FIXME: this ought to be provided by libldap */
4094 config_tls_config(ConfigArgs *c) {
4097 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
4098 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
4099 case CFG_TLS_PROTOCOL_MIN: flag = LDAP_OPT_X_TLS_PROTOCOL_MIN; break;
4101 Debug(LDAP_DEBUG_ANY, "%s: "
4102 "unknown tls_option <0x%x>\n",
4103 c->log, c->type, 0);
4106 if (c->op == SLAP_CONFIG_EMIT) {
4107 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
4108 } else if ( c->op == LDAP_MOD_DELETE ) {
4110 c->cleanup = config_tls_cleanup;
4111 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
4113 ch_free( c->value_string );
4114 c->cleanup = config_tls_cleanup;
4115 if ( isdigit( (unsigned char)c->argv[1][0] ) && c->type != CFG_TLS_PROTOCOL_MIN ) {
4116 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
4117 Debug(LDAP_DEBUG_ANY, "%s: "
4118 "unable to parse %s \"%s\"\n",
4119 c->log, c->argv[0], c->argv[1] );
4122 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
4124 return(ldap_pvt_tls_config(slap_tls_ld, flag, c->argv[1]));
4129 static CfEntryInfo *
4130 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
4140 if ( dn_match( &root->ce_entry->e_nname, dn ))
4143 c = dn->bv_val+dn->bv_len;
4144 for (;*c != ',';c--);
4148 for (--c;c>dn->bv_val && *c != ',';c--);
4152 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
4154 root = root->ce_kids;
4156 for (;root;root=root->ce_sibs) {
4157 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
4158 if ( cdn.bv_val == dn->bv_val ) {
4168 typedef struct setup_cookie {
4178 config_ldif_resp( Operation *op, SlapReply *rs )
4180 if ( rs->sr_type == REP_SEARCH ) {
4181 setup_cookie *sc = op->o_callback->sc_private;
4184 sc->cfb->cb_got_ldif = 1;
4185 /* Does the frontend exist? */
4186 if ( !sc->got_frontend ) {
4187 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
4188 "olcDatabase", STRLENOF( "olcDatabase" )))
4190 if ( strncmp( rs->sr_entry->e_nname.bv_val +
4191 STRLENOF( "olcDatabase" ), "={-1}frontend",
4192 STRLENOF( "={-1}frontend" )))
4196 sc->ca->be = frontendDB;
4197 sc->ca->bi = frontendDB->bd_info;
4198 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
4199 rdn.bv_val = sc->ca->log;
4200 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
4201 "%s=" SLAP_X_ORDERED_FMT "%s",
4202 cfAd_database->ad_cname.bv_val, -1,
4203 sc->ca->bi->bi_type);
4205 sc->frontend = config_build_entry( op, rs,
4206 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
4207 sc->ca->be->be_cf_ocs );
4217 dnParent( &rs->sr_entry->e_nname, &pdn );
4219 /* Does the configDB exist? */
4220 if ( sc->got_frontend && !sc->got_config &&
4221 !strncmp( rs->sr_entry->e_nname.bv_val,
4222 "olcDatabase", STRLENOF( "olcDatabase" )) &&
4223 dn_match( &config_rdn, &pdn ) )
4225 if ( strncmp( rs->sr_entry->e_nname.bv_val +
4226 STRLENOF( "olcDatabase" ), "={0}config",
4227 STRLENOF( "={0}config" )))
4231 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
4232 sc->ca->bi = sc->ca->be->bd_info;
4233 rdn.bv_val = sc->ca->log;
4234 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
4235 "%s=" SLAP_X_ORDERED_FMT "%s",
4236 cfAd_database->ad_cname.bv_val, 0,
4237 sc->ca->bi->bi_type);
4239 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
4240 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
4247 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
4248 if ( rs->sr_err != LDAP_SUCCESS ) {
4249 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
4250 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg, 0 );
4256 /* Configure and read the underlying back-ldif store */
4258 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
4259 CfBackInfo *cfb = be->be_private;
4265 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
4266 Connection conn = {0};
4267 OperationBuffer opbuf;
4269 SlapReply rs = {REP_RESULT};
4270 Filter filter = { LDAP_FILTER_PRESENT };
4271 struct berval filterstr = BER_BVC("(objectclass=*)");
4274 /* Is the config directory available? */
4275 if ( stat( dir, &st ) < 0 ) {
4276 /* No, so don't bother using the backing store.
4277 * All changes will be in-memory only.
4282 cfb->cb_db.bd_info = backend_info( "ldif" );
4283 if ( !cfb->cb_db.bd_info )
4284 return 0; /* FIXME: eventually this will be a fatal error */
4286 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
4289 cfb->cb_db.be_suffix = be->be_suffix;
4290 cfb->cb_db.be_nsuffix = be->be_nsuffix;
4292 /* The suffix is always "cn=config". The underlying DB's rootdn
4293 * is always the same as the suffix.
4295 cfb->cb_db.be_rootdn = be->be_suffix[0];
4296 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
4298 ber_str2bv( dir, 0, 1, &cfdir );
4303 argv[0] = "directory";
4304 argv[1] = (char *)dir;
4309 c.table = Cft_Database;
4311 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
4315 if ( config_add_vals( ct, &c ))
4318 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
4322 void *thrctx = ldap_pvt_thread_pool_context();
4325 connection_fake_init( &conn, &opbuf, thrctx );
4328 filter.f_desc = slap_schema.si_ad_objectClass;
4330 op->o_tag = LDAP_REQ_SEARCH;
4332 op->ors_filter = &filter;
4333 op->ors_filterstr = filterstr;
4334 op->ors_scope = LDAP_SCOPE_SUBTREE;
4336 op->o_dn = c.be->be_rootdn;
4337 op->o_ndn = c.be->be_rootndn;
4339 op->o_req_dn = be->be_suffix[0];
4340 op->o_req_ndn = be->be_nsuffix[0];
4342 op->ors_tlimit = SLAP_NO_LIMIT;
4343 op->ors_slimit = SLAP_NO_LIMIT;
4345 op->ors_attrs = slap_anlist_all_attributes;
4346 op->ors_attrsonly = 0;
4348 op->o_callback = &cb;
4351 cb.sc_private = ≻
4352 sc.got_frontend = 0;
4357 op->o_bd = &cfb->cb_db;
4359 /* Allow unknown attrs in DNs */
4360 prev_DN_strict = slap_DN_strict;
4363 rc = op->o_bd->be_search( op, &rs );
4365 /* Restore normal DN validation */
4366 slap_DN_strict = prev_DN_strict;
4368 op->o_tag = LDAP_REQ_ADD;
4369 if ( rc == LDAP_SUCCESS && sc.frontend ) {
4370 rs_reinit( &rs, REP_RESULT );
4371 op->ora_e = sc.frontend;
4372 rc = op->o_bd->be_add( op, &rs );
4374 if ( rc == LDAP_SUCCESS && sc.config ) {
4375 rs_reinit( &rs, REP_RESULT );
4376 op->ora_e = sc.config;
4377 rc = op->o_bd->be_add( op, &rs );
4379 ldap_pvt_thread_pool_context_reset( thrctx );
4382 /* ITS#4194 - only use if it's present, or we're converting. */
4383 if ( !readit || rc == LDAP_SUCCESS )
4384 cfb->cb_use_ldif = 1;
4390 CfOc_cmp( const void *c1, const void *c2 ) {
4391 const ConfigOCs *co1 = c1;
4392 const ConfigOCs *co2 = c2;
4394 return ber_bvcmp( co1->co_name, co2->co_name );
4398 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
4401 i = init_config_attrs( ct );
4404 /* set up the objectclasses */
4405 i = init_config_ocs( ocs );
4408 for (i=0; ocs[i].co_def; i++) {
4409 if ( ocs[i].co_oc ) {
4410 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
4411 if ( !ocs[i].co_table )
4412 ocs[i].co_table = ct;
4413 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
4420 read_config(const char *fname, const char *dir) {
4423 const char *cfdir, *cfname;
4426 /* Setup the config backend */
4427 be = backend_db_init( "config", NULL, 0, NULL );
4431 cfb = be->be_private;
4432 be->be_dfltaccess = ACL_NONE;
4434 /* If no .conf, or a dir was specified, setup the dir */
4435 if ( !fname || dir ) {
4437 /* If explicitly given, check for existence */
4440 if ( stat( dir, &st ) < 0 ) {
4441 Debug( LDAP_DEBUG_ANY,
4442 "invalid config directory %s, error %d\n",
4448 cfdir = SLAPD_DEFAULT_CONFIGDIR;
4450 /* if fname is defaulted, try reading .d */
4451 rc = config_setup_ldif( be, cfdir, !fname );
4454 /* It may be OK if the base object doesn't exist yet. */
4455 if ( rc != LDAP_NO_SUCH_OBJECT )
4457 /* ITS#4194: But if dir was specified and no fname,
4458 * then we were supposed to read the dir. Unless we're
4459 * trying to slapadd the dir...
4461 if ( dir && !fname ) {
4462 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
4464 /* Assume it's slapadd with a config dir, let it continue */
4466 cfb->cb_got_ldif = 1;
4467 cfb->cb_use_ldif = 1;
4472 /* If we read the config from back-ldif, nothing to do here */
4473 if ( cfb->cb_got_ldif ) {
4482 cfname = SLAPD_DEFAULT_CONFIGFILE;
4484 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
4487 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
4490 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
4491 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
4492 &frontendDB->be_schemadn );
4493 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
4494 if ( rc != LDAP_SUCCESS ) {
4495 Debug(LDAP_DEBUG_ANY, "read_config: "
4496 "unable to normalize default schema DN \"%s\"\n",
4497 frontendDB->be_schemadn.bv_val, 0, 0 );
4498 /* must not happen */
4502 if ( rc == 0 && ( slapMode & SLAP_SERVER_MODE ) && sid_list ) {
4503 if ( !BER_BVISEMPTY( &sid_list->si_url ) && !sid_set ) {
4504 Debug(LDAP_DEBUG_ANY, "read_config: no serverID / URL match found. "
4505 "Check slapd -h arguments.\n", 0,0,0 );
4513 config_back_bind( Operation *op, SlapReply *rs )
4515 if ( be_isroot_pw( op ) ) {
4516 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
4517 /* frontend sends result */
4518 return LDAP_SUCCESS;
4521 rs->sr_err = LDAP_INVALID_CREDENTIALS;
4522 send_ldap_result( op, rs );
4528 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
4532 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
4534 rs->sr_attrs = op->ors_attrs;
4535 rs->sr_entry = ce->ce_entry;
4537 rc = send_search_entry( op, rs );
4538 if ( rc != LDAP_SUCCESS ) {
4542 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
4543 if ( ce->ce_kids ) {
4544 rc = config_send( op, rs, ce->ce_kids, 1 );
4545 if ( rc ) return rc;
4548 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
4549 rc = config_send( op, rs, ce, 0 );
4557 static ConfigTable *
4558 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
4563 for (j=0; j<nocs; j++) {
4564 for (i=0; colst[j]->co_table[i].name; i++)
4565 if ( colst[j]->co_table[i].ad == ad ) {
4566 ca->table = colst[j]->co_type;
4567 return &colst[j]->co_table[i];
4573 /* Sort the attributes of the entry according to the order defined
4574 * in the objectclass, with required attributes occurring before
4575 * allowed attributes. For any attributes with sequencing dependencies
4576 * (e.g., rootDN must be defined after suffix) the objectclass must
4577 * list the attributes in the desired sequence.
4580 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
4582 Attribute *a, *head = NULL, *tail = NULL, **prev;
4585 for (i=0; i<nocs; i++) {
4586 if ( colst[i]->co_oc->soc_required ) {
4587 AttributeType **at = colst[i]->co_oc->soc_required;
4588 for (j=0; at[j]; j++) {
4589 for (a=e->e_attrs, prev=&e->e_attrs; a;
4590 prev = &(*prev)->a_next, a=a->a_next) {
4591 if ( a->a_desc == at[j]->sat_ad ) {
4605 if ( colst[i]->co_oc->soc_allowed ) {
4606 AttributeType **at = colst[i]->co_oc->soc_allowed;
4607 for (j=0; at[j]; j++) {
4608 for (a=e->e_attrs, prev=&e->e_attrs; a;
4609 prev = &(*prev)->a_next, a=a->a_next) {
4610 if ( a->a_desc == at[j]->sat_ad ) {
4626 tail->a_next = e->e_attrs;
4632 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
4634 Attribute *a = NULL;
4635 AttributeDescription *ad;
4645 Modifications *ml = ptr;
4647 vals = ml->sml_values;
4650 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
4651 rc = ordered_value_sort( a, 1 );
4653 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
4654 ad->ad_cname.bv_val );
4658 for ( i=0; vals[i].bv_val; i++ ) {
4659 ca->line = vals[i].bv_val;
4660 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
4661 ca->line[0] == '{' ) {
4662 char *idx = strchr( ca->line, '}' );
4663 if ( idx ) ca->line = idx+1;
4665 rc = config_parse_vals( ct, ca, i );
4674 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
4677 struct berval rtype, rval;
4679 AttributeDescription *ad = NULL;
4681 dnRdn( &e->e_name, rdn );
4682 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
4683 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
4684 rtype.bv_val = rdn->bv_val;
4685 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
4688 slap_bv2ad( &rtype, &ad, &rs->sr_text );
4689 a = attr_find( e->e_attrs, ad );
4690 if (!a ) return LDAP_NAMING_VIOLATION;
4697 config_rename_kids( CfEntryInfo *ce )
4700 struct berval rdn, nrdn;
4702 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
4703 struct berval newdn, newndn;
4704 dnRdn ( &ce2->ce_entry->e_name, &rdn );
4705 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
4706 build_new_dn( &newdn, &ce->ce_entry->e_name, &rdn, NULL );
4707 build_new_dn( &newndn, &ce->ce_entry->e_nname, &nrdn, NULL );
4708 free( ce2->ce_entry->e_name.bv_val );
4709 free( ce2->ce_entry->e_nname.bv_val );
4710 ce2->ce_entry->e_name = newdn;
4711 ce2->ce_entry->e_nname = newndn;
4712 config_rename_kids( ce2 );
4717 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
4718 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
4719 struct berval *nnewrdn, int use_ldif )
4723 struct berval odn, ondn;
4727 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
4728 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
4731 free( a->a_vals[0].bv_val );
4732 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
4733 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
4734 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
4735 strcpy( a->a_vals[0].bv_val, ptr1 );
4737 if ( a->a_nvals != a->a_vals ) {
4738 free( a->a_nvals[0].bv_val );
4739 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
4740 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
4741 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
4742 strcpy( a->a_nvals[0].bv_val, ptr1 );
4745 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
4746 BackendDB *be = op->o_bd;
4747 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4748 struct berval dn, ndn, xdn, xndn;
4750 op->o_bd = &cfb->cb_db;
4752 /* Save current rootdn; use the underlying DB's rootdn */
4756 xndn = op->o_req_ndn;
4757 op->o_dn = op->o_bd->be_rootdn;
4758 op->o_ndn = op->o_bd->be_rootndn;
4760 op->o_req_ndn = ondn;
4762 scp = op->o_callback;
4763 op->o_callback = ≻
4764 op->orr_newrdn = *newrdn;
4765 op->orr_nnewrdn = *nnewrdn;
4766 op->orr_newSup = NULL;
4767 op->orr_nnewSup = NULL;
4768 op->orr_deleteoldrdn = 1;
4769 op->orr_modlist = NULL;
4770 slap_modrdn2mods( op, rs );
4771 slap_mods_opattrs( op, &op->orr_modlist, 1 );
4772 rc = op->o_bd->be_modrdn( op, rs );
4773 slap_mods_free( op->orr_modlist, 1 );
4776 op->o_callback = scp;
4780 op->o_req_ndn = xndn;
4783 free( ondn.bv_val );
4785 config_rename_kids( e->e_private );
4790 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
4791 Entry *e, int idx, int tailindex, int use_ldif )
4793 struct berval ival, newrdn, nnewrdn;
4796 char ibuf[32], *ptr1, *ptr2 = NULL;
4799 rc = config_rename_attr( rs, e, &rdn, &a );
4800 if ( rc ) return rc;
4803 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
4804 if ( ival.bv_len >= sizeof( ibuf ) ) {
4805 return LDAP_NAMING_VIOLATION;
4808 newrdn.bv_len = rdn.bv_len + ival.bv_len;
4809 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
4812 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
4813 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4816 ptr2 = ber_bvchr( &rdn, '}' );
4820 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
4822 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
4823 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
4824 a->a_desc->ad_cname.bv_len );
4826 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4827 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
4831 /* Do the equivalent of ModRDN */
4832 /* Replace DN / NDN */
4833 newrdn.bv_len = ptr1 - newrdn.bv_val;
4834 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
4835 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
4837 free( nnewrdn.bv_val );
4838 free( newrdn.bv_val );
4843 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
4844 SlapReply *rs, int *renum, int *ibase )
4847 int index = -1, gotindex = 0, nsibs, rc = 0;
4848 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
4849 char *ptr1, *ptr2 = NULL;
4852 if ( renum ) *renum = 0;
4854 /* These entries don't get indexed/renumbered */
4855 if ( ce_type == Cft_Global ) return 0;
4856 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
4858 if ( ce_type == Cft_Module )
4861 /* See if the rdn has an index already */
4862 dnRdn( &e->e_name, &rdn );
4863 if ( ce_type == Cft_Database ) {
4864 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
4865 "frontend", STRLENOF("frontend") ))
4867 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
4868 "config", STRLENOF("config") ))
4871 ptr1 = ber_bvchr( &e->e_name, '{' );
4872 if ( ptr1 && ptr1 < &e->e_name.bv_val[ rdn.bv_len ] ) {
4874 ptr2 = strchr( ptr1, '}' );
4875 if ( !ptr2 || ptr2 > &e->e_name.bv_val[ rdn.bv_len ] )
4876 return LDAP_NAMING_VIOLATION;
4877 if ( ptr2-ptr1 == 1)
4878 return LDAP_NAMING_VIOLATION;
4880 index = strtol( ptr1 + 1, &next, 10 );
4881 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
4882 return LDAP_NAMING_VIOLATION;
4885 /* Special case, we allow -1 for the frontendDB */
4886 if ( index != -1 || !isfrontend )
4887 return LDAP_NAMING_VIOLATION;
4889 if ( isconfig && index != 0 ){
4890 return LDAP_NAMING_VIOLATION;
4894 /* count related kids.
4895 * For entries of type Cft_Misc, only count siblings with same RDN type
4897 if ( ce_type == Cft_Misc ) {
4898 rdn.bv_val = e->e_nname.bv_val;
4899 ptr1 = strchr( rdn.bv_val, '=' );
4900 assert( ptr1 != NULL );
4902 rdn.bv_len = ptr1 - rdn.bv_val;
4904 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
4906 if ( ce->ce_type != ce_type )
4909 dnRdn( &ce->ce_entry->e_nname, &rdn2 );
4911 ptr1 = strchr( rdn2.bv_val, '=' );
4912 assert( ptr1 != NULL );
4914 rdn2.bv_len = ptr1 - rdn2.bv_val;
4915 if ( bvmatch( &rdn, &rdn2 ))
4919 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
4920 if ( ce->ce_type == ce_type ) nsibs++;
4924 /* account for -1 frontend */
4925 if ( ce_type == Cft_Database )
4928 if ( index != nsibs ) {
4930 if ( index < nsibs ) {
4931 if ( tailindex ) return LDAP_NAMING_VIOLATION;
4932 /* Siblings need to be renumbered */
4933 if ( index != -1 || !isfrontend )
4937 /* config DB is always "0" */
4938 if ( isconfig && index == -1 ) {
4941 if (( !isfrontend && index == -1 ) || ( index > nsibs ) ){
4945 /* just make index = nsibs */
4947 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
4950 if ( ibase ) *ibase = index;
4951 if ( renum ) *renum = renumber;
4955 /* Insert all superior classes of the given class */
4957 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
4962 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
4963 if ( count_oc( *sups, copp, nocs ) ) {
4968 co.co_name = &oc->soc_cname;
4969 cop = avl_find( CfOcTree, &co, CfOc_cmp );
4973 /* check for duplicates */
4974 for ( i = 0; i < *nocs; i++ ) {
4975 if ( *copp && (*copp)[i] == cop ) {
4981 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
4982 if ( tmp == NULL ) {
4986 (*copp)[*nocs] = cop;
4994 /* Find all superior classes of the given objectclasses,
4995 * return list in order of most-subordinate first.
4997 * Special / auxiliary / Cft_Misc classes always take precedence.
5000 count_ocs( Attribute *oc_at, int *nocs )
5002 int i, j, misc = -1;
5003 ConfigOCs **colst = NULL;
5007 for ( i = oc_at->a_numvals; i--; ) {
5008 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
5010 assert( oc != NULL );
5011 if ( count_oc( oc, &colst, nocs ) ) {
5021 ConfigOCs *tmp = colst[i];
5022 colst[i] = colst[j];
5024 if (tmp->co_type == Cft_Misc)
5028 /* Move misc class to front of list */
5030 ConfigOCs *tmp = colst[misc];
5031 for (i=misc; i>0; i--)
5032 colst[i] = colst[i-1];
5040 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
5042 /* Leftover from RE23. Never parse this entry */
5043 return LDAP_COMPARE_TRUE;
5047 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
5051 /* This entry is hardcoded, don't re-parse it */
5052 if ( p->ce_type == Cft_Global ) {
5053 cfn = p->ce_private;
5054 ca->ca_private = cfn;
5055 return LDAP_COMPARE_TRUE;
5057 if ( p->ce_type != Cft_Schema )
5058 return LDAP_CONSTRAINT_VIOLATION;
5060 cfn = ch_calloc( 1, sizeof(ConfigFile) );
5061 ca->ca_private = cfn;
5062 cfo = p->ce_private;
5063 cfn->c_sibs = cfo->c_kids;
5065 return LDAP_SUCCESS;
5069 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
5071 if ( p->ce_type != Cft_Global ) {
5072 return LDAP_CONSTRAINT_VIOLATION;
5074 /* config must be {0}, nothing else allowed */
5075 if ( !strncmp( e->e_nname.bv_val, "olcDatabase={0}", STRLENOF("olcDatabase={0}")) &&
5076 strncmp( e->e_nname.bv_val + STRLENOF("olcDatabase={0}"), "config,", STRLENOF("config,") )) {
5077 return LDAP_CONSTRAINT_VIOLATION;
5079 ca->be = frontendDB; /* just to get past check_vals */
5080 return LDAP_SUCCESS;
5084 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
5086 if ( p->ce_type != Cft_Global ) {
5087 return LDAP_CONSTRAINT_VIOLATION;
5089 return LDAP_SUCCESS;
5093 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
5095 if ( p->ce_type != Cft_Global ) {
5096 return LDAP_CONSTRAINT_VIOLATION;
5098 return LDAP_SUCCESS;
5102 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
5104 if ( p->ce_type != Cft_Database ) {
5105 return LDAP_CONSTRAINT_VIOLATION;
5108 return LDAP_SUCCESS;
5112 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
5117 AttributeDescription *ad;
5123 if ( cfn->c_cr_head ) {
5124 struct berval bv = BER_BVC("olcDitContentRules");
5126 slap_bv2ad( &bv, &ad, &text );
5127 ct = config_find_table( colst, nocs, ad, ca );
5128 config_del_vals( ct, ca );
5130 if ( cfn->c_oc_head ) {
5131 struct berval bv = BER_BVC("olcObjectClasses");
5133 slap_bv2ad( &bv, &ad, &text );
5134 ct = config_find_table( colst, nocs, ad, ca );
5135 config_del_vals( ct, ca );
5137 if ( cfn->c_at_head ) {
5138 struct berval bv = BER_BVC("olcAttributeTypes");
5140 slap_bv2ad( &bv, &ad, &text );
5141 ct = config_find_table( colst, nocs, ad, ca );
5142 config_del_vals( ct, ca );
5144 if ( cfn->c_syn_head ) {
5145 struct berval bv = BER_BVC("olcLdapSyntaxes");
5147 slap_bv2ad( &bv, &ad, &text );
5148 ct = config_find_table( colst, nocs, ad, ca );
5149 config_del_vals( ct, ca );
5151 if ( cfn->c_om_head ) {
5152 struct berval bv = BER_BVC("olcObjectIdentifier");
5154 slap_bv2ad( &bv, &ad, &text );
5155 ct = config_find_table( colst, nocs, ad, ca );
5156 config_del_vals( ct, ca );
5158 cfo = p->ce_private;
5159 cfo->c_kids = cfn->c_sibs;
5164 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
5166 int rc = LDAP_CONSTRAINT_VIOLATION;
5169 if ( (*cop)->co_ldadd ) {
5170 rc = (*cop)->co_ldadd( last, e, ca );
5171 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
5176 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
5177 ConfigOCs co = { 0 };
5179 co.co_name = &(*ocp)->soc_cname;
5180 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
5181 if ( *cop == NULL ) {
5185 rc = config_add_oc( cop, last, e, ca );
5186 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
5194 /* Parse an LDAP entry into config directives */
5196 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
5197 int *renum, Operation *op )
5199 CfEntryInfo *ce, *last = NULL;
5200 ConfigOCs co, *coptr, **colst;
5201 Attribute *a, *oc_at, *soc_at;
5202 int i, ibase = -1, nocs, rc = 0;
5205 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
5207 memset( ca, 0, sizeof(ConfigArgs));
5209 /* Make sure parent exists and entry does not. But allow
5210 * Databases and Overlays to be inserted. Don't do any
5211 * auto-renumbering if manageDSAit control is present.
5213 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
5215 if ( ( op && op->o_managedsait ) ||
5216 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
5217 ce->ce_type != Cft_Module ) )
5219 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5220 "DN=\"%s\" already exists\n",
5221 log_prefix, e->e_name.bv_val, 0 );
5222 /* global schema ignores all writes */
5223 if ( ce->ce_type == Cft_Schema && ce->ce_parent->ce_type == Cft_Global )
5224 return LDAP_COMPARE_TRUE;
5225 return LDAP_ALREADY_EXISTS;
5229 dnParent( &e->e_nname, &pdn );
5231 /* If last is NULL, the new entry is the root/suffix entry,
5232 * otherwise last should be the parent.
5234 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
5236 rs->sr_matched = last->ce_entry->e_name.bv_val;
5238 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5239 "DN=\"%s\" not child of DN=\"%s\"\n",
5240 log_prefix, e->e_name.bv_val,
5241 last->ce_entry->e_name.bv_val );
5242 return LDAP_NO_SUCH_OBJECT;
5246 /* No parent, must be root. This will never happen... */
5247 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
5248 return LDAP_NO_SUCH_OBJECT;
5251 if ( last && !access_allowed( op, last->ce_entry,
5252 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
5254 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5255 "DN=\"%s\" no write access to \"children\" of parent\n",
5256 log_prefix, e->e_name.bv_val, 0 );
5257 return LDAP_INSUFFICIENT_ACCESS;
5261 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5263 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5264 "DN=\"%s\" no objectClass\n",
5265 log_prefix, e->e_name.bv_val, 0 );
5266 return LDAP_OBJECT_CLASS_VIOLATION;
5269 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
5271 ObjectClass *soc = NULL;
5272 char textbuf[ SLAP_TEXT_BUFLEN ];
5273 const char *text = textbuf;
5275 /* FIXME: check result */
5276 rc = structural_class( oc_at->a_nvals, &soc, NULL,
5277 &text, textbuf, sizeof(textbuf), NULL );
5278 if ( rc != LDAP_SUCCESS ) {
5279 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5280 "DN=\"%s\" no structural objectClass (%s)\n",
5281 log_prefix, e->e_name.bv_val, text );
5284 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
5285 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
5286 if ( soc_at == NULL ) {
5287 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5288 "DN=\"%s\" no structural objectClass; "
5289 "unable to merge computed class %s\n",
5290 log_prefix, e->e_name.bv_val,
5291 soc->soc_cname.bv_val );
5292 return LDAP_OBJECT_CLASS_VIOLATION;
5295 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5296 "DN=\"%s\" no structural objectClass; "
5297 "computed objectClass %s merged\n",
5298 log_prefix, e->e_name.bv_val,
5299 soc->soc_cname.bv_val );
5302 /* Fake the coordinates based on whether we're part of an
5303 * LDAP Add or if reading the config dir
5306 ca->fname = "slapd";
5309 ca->fname = cfdir.bv_val;
5314 co.co_name = &soc_at->a_nvals[0];
5315 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
5316 if ( coptr == NULL ) {
5317 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5318 "DN=\"%s\" no structural objectClass in configuration table\n",
5319 log_prefix, e->e_name.bv_val, 0 );
5320 return LDAP_OBJECT_CLASS_VIOLATION;
5323 /* Only the root can be Cft_Global, everything else must
5324 * have a parent. Only limited nesting arrangements are allowed.
5326 rc = LDAP_CONSTRAINT_VIOLATION;
5327 if ( coptr->co_type == Cft_Global && !last ) {
5328 cfn = cfb->cb_config;
5329 ca->ca_private = cfn;
5330 ca->be = frontendDB; /* just to get past check_vals */
5334 colst = count_ocs( oc_at, &nocs );
5336 /* Check whether the Add is allowed by its parent, and do
5337 * any necessary arg setup
5340 rc = config_add_oc( &coptr, last, e, ca );
5341 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
5342 for ( i = 0; i<nocs; i++ ) {
5343 /* Already checked these */
5344 if ( colst[i]->co_oc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
5346 if ( colst[i]->co_ldadd &&
5347 ( rc = colst[i]->co_ldadd( last, e, ca ))
5348 != LDAP_CONSTRAINT_VIOLATION ) {
5354 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
5355 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5356 "DN=\"%s\" no structural objectClass add function\n",
5357 log_prefix, e->e_name.bv_val, 0 );
5358 return LDAP_OBJECT_CLASS_VIOLATION;
5362 /* Add the entry but don't parse it, we already have its contents */
5363 if ( rc == LDAP_COMPARE_TRUE ) {
5368 if ( rc != LDAP_SUCCESS )
5371 /* Parse all the values and check for simple syntax errors before
5372 * performing any set actions.
5374 * If doing an LDAPadd, check for indexed names and any necessary
5375 * renaming/renumbering. Entries that don't need indexed names are
5376 * ignored. Entries that need an indexed name and arrive without one
5377 * are assigned to the end. Entries that arrive with an index may
5378 * cause the following entries to be renumbered/bumped down.
5380 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
5381 * don't allow Adding an entry with an index that's already in use.
5382 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
5384 * These entries can have auto-assigned indexes (appended to the end)
5385 * but only the other types support auto-renumbering of siblings.
5388 rc = check_name_index( last, coptr->co_type, e, rs, renum,
5393 if ( renum && *renum && coptr->co_type != Cft_Database &&
5394 coptr->co_type != Cft_Overlay )
5396 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
5397 "operation requires sibling renumbering" );
5398 rc = LDAP_UNWILLING_TO_PERFORM;
5403 init_config_argv( ca );
5405 /* Make sure we process attrs in the required order */
5406 sort_attrs( e, colst, nocs );
5408 for ( a = e->e_attrs; a; a = a->a_next ) {
5409 if ( a == oc_at ) continue;
5410 ct = config_find_table( colst, nocs, a->a_desc, ca );
5411 if ( !ct ) continue; /* user data? */
5412 rc = check_vals( ct, ca, a, 1 );
5413 if ( rc ) goto done_noop;
5416 /* Basic syntax checks are OK. Do the actual settings. */
5417 for ( a=e->e_attrs; a; a=a->a_next ) {
5418 if ( a == oc_at ) continue;
5419 ct = config_find_table( colst, nocs, a->a_desc, ca );
5420 if ( !ct ) continue; /* user data? */
5421 for (i=0; a->a_vals[i].bv_val; i++) {
5424 ca->line = a->a_vals[i].bv_val;
5425 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
5426 ptr = strchr( ca->line, '}' );
5428 iptr = strchr( ca->line, '{' );
5432 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
5434 ca->valx = strtol( iptr+1, NULL, 0 );
5439 rc = config_parse_add( ct, ca, i );
5447 /* Newly added databases and overlays need to be started up */
5448 if ( CONFIG_ONLINE_ADD( ca )) {
5449 if ( coptr->co_type == Cft_Database ) {
5450 rc = backend_startup_one( ca->be, &ca->reply );
5452 } else if ( coptr->co_type == Cft_Overlay ) {
5453 if ( ca->bi->bi_db_open ) {
5454 BackendInfo *bi_orig = ca->be->bd_info;
5455 ca->be->bd_info = ca->bi;
5456 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
5457 ca->be->bd_info = bi_orig;
5459 } else if ( ca->cleanup ) {
5460 rc = ca->cleanup( ca );
5463 if (ca->cr_msg[0] == '\0')
5464 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
5466 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
5467 ca->log, ca->cr_msg, ca->argv[1] );
5474 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5475 ce->ce_parent = last;
5476 ce->ce_entry = entry_dup( e );
5477 ce->ce_entry->e_private = ce;
5478 ce->ce_type = coptr->co_type;
5481 ce->ce_private = ca->ca_private;
5482 ca->ca_entry = ce->ce_entry;
5485 } else if ( last->ce_kids ) {
5486 CfEntryInfo *c2, **cprev;
5488 /* Advance to first of this type */
5489 cprev = &last->ce_kids;
5490 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
5491 cprev = &c2->ce_sibs;
5494 /* Account for the (-1) frontendDB entry */
5495 if ( ce->ce_type == Cft_Database ) {
5496 if ( ca->be == frontendDB )
5498 else if ( ibase != -1 )
5503 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
5504 cprev = &c2->ce_sibs;
5510 for ( i=0; i<ibase; i++ ) {
5512 cprev = &c2->ce_sibs;
5515 ce->ce_sibs = *cprev;
5523 if ( (coptr->co_type == Cft_Database) && ca->be ) {
5524 if ( ca->be != frontendDB )
5525 backend_destroy_one( ca->be, 1 );
5526 } else if ( (coptr->co_type == Cft_Overlay) && ca->bi ) {
5527 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
5528 } else if ( coptr->co_type == Cft_Schema ) {
5529 schema_destroy_one( ca, colst, nocs, last );
5534 ch_free( ca->argv );
5535 if ( colst ) ch_free( colst );
5539 #define BIGTMP 10000
5541 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5542 int base, int rebase, int max, int use_ldif )
5544 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
5545 ConfigType etype = ce->ce_type;
5546 int count = 0, rc = 0;
5548 /* Reverse ce list */
5549 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
5550 if (ce2->ce_type != etype) {
5555 ce2->ce_sibs = cetmp;
5558 if ( max && count >= max ) {
5564 /* Move original to a temp name until increments are done */
5566 ce->ce_entry->e_private = NULL;
5567 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5568 base+BIGTMP, 0, use_ldif );
5569 ce->ce_entry->e_private = ce;
5571 /* start incrementing */
5572 for (ce2=cetmp; ce2; ce2=ce3) {
5574 ce2->ce_sibs = cerem;
5577 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5578 count+base, 0, use_ldif );
5582 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5583 base, 0, use_ldif );
5588 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5589 CfEntryInfo *ce2, int old, int use_ldif )
5593 /* Renumber original to a temp value */
5594 ce->ce_entry->e_private = NULL;
5595 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5596 old+BIGTMP, 0, use_ldif );
5597 ce->ce_entry->e_private = ce;
5599 /* start decrementing */
5600 for (; ce2 != ce; ce2=ce2->ce_sibs) {
5601 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5602 count+old, 0, use_ldif );
5605 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5606 count+old, 0, use_ldif );
5609 /* Parse an LDAP entry into config directives, then store in underlying
5613 config_back_add( Operation *op, SlapReply *rs )
5619 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
5620 NULL, ACL_WADD, NULL )) {
5621 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5626 * Check for attribute ACL
5628 if ( !acl_check_modlist( op, op->ora_e, op->orm_modlist )) {
5629 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5630 rs->sr_text = "no write access to attribute";
5634 cfb = (CfBackInfo *)op->o_bd->be_private;
5636 /* add opattrs for syncprov */
5638 char textbuf[SLAP_TEXT_BUFLEN];
5639 size_t textlen = sizeof textbuf;
5640 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1, NULL,
5641 &rs->sr_text, textbuf, sizeof( textbuf ) );
5642 if ( rs->sr_err != LDAP_SUCCESS )
5644 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
5645 if ( rs->sr_err != LDAP_SUCCESS ) {
5646 Debug( LDAP_DEBUG_TRACE,
5647 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
5648 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
5653 if ( op->o_abandon ) {
5654 rs->sr_err = SLAPD_ABANDON;
5657 ldap_pvt_thread_pool_pause( &connection_pool );
5660 * 1) check for existence of entry
5661 * 2) check for sibling renumbering
5662 * 3) perform internal add
5663 * 4) perform any necessary renumbering
5664 * 5) store entry in underlying database
5666 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
5667 if ( rs->sr_err != LDAP_SUCCESS ) {
5668 rs->sr_text = ca.cr_msg;
5673 CfEntryInfo *ce = ca.ca_entry->e_private;
5674 req_add_s addr = op->oq_add;
5675 op->o_tag = LDAP_REQ_MODRDN;
5676 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
5677 op->o_tag = LDAP_REQ_ADD;
5679 if ( rs->sr_err != LDAP_SUCCESS ) {
5684 if ( cfb->cb_use_ldif ) {
5685 BackendDB *be = op->o_bd;
5686 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5687 struct berval dn, ndn;
5689 op->o_bd = &cfb->cb_db;
5691 /* Save current rootdn; use the underlying DB's rootdn */
5694 op->o_dn = op->o_bd->be_rootdn;
5695 op->o_ndn = op->o_bd->be_rootndn;
5697 scp = op->o_callback;
5698 op->o_callback = ≻
5699 op->o_bd->be_add( op, rs );
5701 op->o_callback = scp;
5707 ldap_pvt_thread_pool_resume( &connection_pool );
5710 { int repl = op->o_dont_replicate;
5711 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
5712 rs->sr_text = NULL; /* Set after config_add_internal */
5713 rs->sr_err = LDAP_SUCCESS;
5714 op->o_dont_replicate = 1;
5716 send_ldap_result( op, rs );
5717 op->o_dont_replicate = repl;
5719 slap_graduate_commit_csn( op );
5723 typedef struct delrec {
5724 struct delrec *next;
5730 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
5736 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
5737 ca->line[0] == '{' )
5739 char *ptr = strchr( ca->line + 1, '}' );
5743 ca->valx = strtol( ca->line + 1, &next, 0 );
5744 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
5750 rc = config_parse_add( ct, ca, i );
5758 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
5761 int rc = LDAP_UNWILLING_TO_PERFORM;
5763 Entry *e = ce->ce_entry;
5764 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
5769 delrec *dels = NULL, *deltail = NULL;
5771 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5772 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
5774 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5775 if (ml->sml_desc == slap_schema.si_ad_objectClass)
5779 colst = count_ocs( oc_at, &nocs );
5781 /* make sure add/del flags are clear; should always be true */
5782 for ( s = save_attrs; s; s = s->a_next ) {
5783 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
5786 e->e_attrs = attrs_dup( e->e_attrs );
5788 init_config_argv( ca );
5791 ca->ca_private = ce->ce_private;
5793 ca->fname = "slapd";
5795 strcpy( ca->log, "back-config" );
5797 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5798 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5799 switch (ml->sml_op) {
5800 case LDAP_MOD_DELETE:
5801 case LDAP_MOD_REPLACE:
5802 case SLAP_MOD_SOFTDEL:
5804 BerVarray vals = NULL, nvals = NULL;
5806 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
5808 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
5809 ml->sml_desc->ad_cname.bv_val );
5812 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5813 vals = ml->sml_values;
5814 nvals = ml->sml_nvalues;
5815 ml->sml_values = NULL;
5816 ml->sml_nvalues = NULL;
5818 /* If we're deleting by values, remember the indexes of the
5819 * values we deleted.
5821 if ( ct && ml->sml_values ) {
5823 i = ml->sml_numvals;
5824 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
5835 rc = modify_delete_vindex(e, &ml->sml_mod,
5836 get_permissiveModify(op),
5837 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
5838 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5839 ml->sml_values = vals;
5840 ml->sml_nvalues = nvals;
5842 if ( rc == LDAP_NO_SUCH_ATTRIBUTE && ml->sml_op == SLAP_MOD_SOFTDEL )
5846 /* FIXME: check rc before fallthru? */
5850 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5852 case SLAP_MOD_ADD_IF_NOT_PRESENT:
5853 if ( ml->sml_op == SLAP_MOD_ADD_IF_NOT_PRESENT
5854 && attr_find( e->e_attrs, ml->sml_desc ) )
5861 case SLAP_MOD_SOFTADD: {
5862 int mop = ml->sml_op;
5864 ml->sml_op = LDAP_MOD_ADD;
5866 if ( ct->arg_type & ARG_NO_INSERT ) {
5867 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
5869 navals = a->a_numvals;
5872 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
5873 if ( ml->sml_values[i].bv_val[0] == '{' &&
5876 char *next, *val = ml->sml_values[i].bv_val + 1;
5879 j = strtol( val, &next, 0 );
5880 if ( next == val || next[ 0 ] != '}' || j < navals ) {
5882 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
5883 ml->sml_desc->ad_cname.bv_val );
5887 rc = check_vals( ct, ca, ml, 0 );
5888 if ( rc ) goto out_noop;
5891 rc = modify_add_values(e, &ml->sml_mod,
5892 get_permissiveModify(op),
5893 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5895 /* If value already exists, show success here
5896 * and ignore this operation down below.
5898 if ( mop == SLAP_MOD_SOFTADD ) {
5899 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
5909 case LDAP_MOD_INCREMENT: /* FIXME */
5914 if(rc != LDAP_SUCCESS) break;
5917 if ( rc == LDAP_SUCCESS) {
5918 /* check that the entry still obeys the schema */
5919 rc = entry_schema_check(op, e, NULL, 0, 0, NULL,
5920 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5922 if ( rc ) goto out_noop;
5924 /* Basic syntax checks are OK. Do the actual settings. */
5925 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5926 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5927 if ( !ct ) continue;
5929 s = attr_find( save_attrs, ml->sml_desc );
5930 a = attr_find( e->e_attrs, ml->sml_desc );
5932 switch (ml->sml_op) {
5933 case LDAP_MOD_DELETE:
5934 case LDAP_MOD_REPLACE: {
5935 BerVarray vals = NULL, nvals = NULL;
5938 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5939 vals = ml->sml_values;
5940 nvals = ml->sml_nvalues;
5941 ml->sml_values = NULL;
5942 ml->sml_nvalues = NULL;
5945 if ( ml->sml_values )
5948 /* If we didn't delete the whole attribute */
5949 if ( ml->sml_values && a ) {
5950 struct berval *mvals;
5953 if ( ml->sml_nvalues )
5954 mvals = ml->sml_nvalues;
5956 mvals = ml->sml_values;
5958 /* use the indexes we saved up above */
5959 for (i=0; i < d->nidx; i++) {
5960 struct berval bv = *mvals++;
5961 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
5962 bv.bv_val[0] == '{' ) {
5963 ptr = strchr( bv.bv_val, '}' ) + 1;
5964 bv.bv_len -= ptr - bv.bv_val;
5967 ca->line = bv.bv_val;
5968 ca->valx = d->idx[i];
5969 config_parse_vals(ct, ca, d->idx[i] );
5970 rc = config_del_vals( ct, ca );
5971 if ( rc != LDAP_SUCCESS ) break;
5973 s->a_flags |= SLAP_ATTR_IXDEL;
5974 for (j=i+1; j < d->nidx; j++)
5975 if ( d->idx[j] >d->idx[i] )
5982 rc = config_del_vals( ct, ca );
5983 if ( rc ) rc = LDAP_OTHER;
5985 s->a_flags |= SLAP_ATTR_IXDEL;
5987 if ( ml->sml_values ) {
5992 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5993 ml->sml_values = vals;
5994 ml->sml_nvalues = nvals;
5996 if ( !vals || rc != LDAP_SUCCESS )
5999 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
6004 for (i=0; ml->sml_values[i].bv_val; i++) {
6005 ca->line = ml->sml_values[i].bv_val;
6007 rc = config_modify_add( ct, ca, ml->sml_desc, i );
6010 a->a_flags |= SLAP_ATTR_IXADD;
6017 /* Undo for a failed operation */
6018 if ( rc != LDAP_SUCCESS ) {
6019 ConfigReply msg = ca->reply;
6020 for ( s = save_attrs; s; s = s->a_next ) {
6021 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
6022 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
6023 ct = config_find_table( colst, nocs, s->a_desc, ca );
6024 a = attr_find( e->e_attrs, s->a_desc );
6026 /* clear the flag so the add check below will skip it */
6027 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
6031 config_del_vals( ct, ca );
6033 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
6034 ca->line = s->a_vals[i].bv_val;
6036 config_modify_add( ct, ca, s->a_desc, i );
6040 for ( a = e->e_attrs; a; a = a->a_next ) {
6041 if ( a->a_flags & SLAP_ATTR_IXADD ) {
6042 ct = config_find_table( colst, nocs, a->a_desc, ca );
6046 config_del_vals( ct, ca );
6047 s = attr_find( save_attrs, a->a_desc );
6049 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
6050 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
6051 ca->line = s->a_vals[i].bv_val;
6053 config_modify_add( ct, ca, s->a_desc, i );
6061 if ( ca->cleanup ) {
6062 i = ca->cleanup( ca );
6063 if (rc == LDAP_SUCCESS)
6067 if ( rc == LDAP_SUCCESS ) {
6068 attrs_free( save_attrs );
6071 attrs_free( e->e_attrs );
6072 e->e_attrs = save_attrs;
6074 ch_free( ca->argv );
6075 if ( colst ) ch_free( colst );
6077 deltail = dels->next;
6086 config_back_modify( Operation *op, SlapReply *rs )
6089 CfEntryInfo *ce, *last;
6091 ConfigArgs ca = {0};
6094 AttributeDescription *rad = NULL;
6097 cfb = (CfBackInfo *)op->o_bd->be_private;
6099 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6102 rs->sr_matched = last->ce_entry->e_name.bv_val;
6103 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6107 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
6108 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6112 /* Get type of RDN */
6113 rdn = ce->ce_entry->e_nname;
6114 ptr = strchr( rdn.bv_val, '=' );
6115 rdn.bv_len = ptr - rdn.bv_val;
6116 rs->sr_err = slap_bv2ad( &rdn, &rad, &rs->sr_text );
6117 if ( rs->sr_err != LDAP_SUCCESS ) {
6121 /* Some basic validation... */
6122 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
6123 /* Don't allow Modify of RDN; must use ModRdn for that. */
6124 if ( ml->sml_desc == rad ) {
6125 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
6126 rs->sr_text = "Use modrdn to change the entry name";
6129 /* Internal update of contextCSN? */
6130 if ( ml->sml_desc == slap_schema.si_ad_contextCSN && op->o_conn->c_conn_idx == -1 ) {
6136 slap_mods_opattrs( op, &op->orm_modlist, 1 );
6139 if ( op->o_abandon ) {
6140 rs->sr_err = SLAPD_ABANDON;
6143 ldap_pvt_thread_pool_pause( &connection_pool );
6147 * 1) perform the Modify on the cached Entry.
6148 * 2) verify that the Entry still satisfies the schema.
6149 * 3) perform the individual config operations.
6150 * 4) store Modified entry in underlying LDIF backend.
6152 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
6154 rs->sr_text = ca.cr_msg;
6155 } else if ( cfb->cb_use_ldif ) {
6156 BackendDB *be = op->o_bd;
6157 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
6158 struct berval dn, ndn;
6160 op->o_bd = &cfb->cb_db;
6164 op->o_dn = op->o_bd->be_rootdn;
6165 op->o_ndn = op->o_bd->be_rootndn;
6167 scp = op->o_callback;
6168 op->o_callback = ≻
6169 op->o_bd->be_modify( op, rs );
6171 op->o_callback = scp;
6177 ldap_pvt_thread_pool_resume( &connection_pool );
6179 send_ldap_result( op, rs );
6180 slap_graduate_commit_csn( op );
6185 config_back_modrdn( Operation *op, SlapReply *rs )
6188 CfEntryInfo *ce, *last;
6192 cfb = (CfBackInfo *)op->o_bd->be_private;
6194 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6197 rs->sr_matched = last->ce_entry->e_name.bv_val;
6198 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6201 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
6202 NULL, ACL_WRITE, NULL )) {
6203 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6207 if ( ce->ce_parent )
6208 parent = ce->ce_parent->ce_entry;
6210 parent = (Entry *)&slap_entry_root;
6211 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
6212 NULL, ACL_WRITE, NULL )) {
6213 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6218 /* We don't allow moving objects to new parents.
6219 * Generally we only allow reordering a set of ordered entries.
6221 if ( op->orr_newSup ) {
6222 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6226 /* If newRDN == oldRDN, quietly succeed */
6227 dnRdn( &op->o_req_ndn, &rdn );
6228 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
6229 rs->sr_err = LDAP_SUCCESS;
6233 /* Current behavior, subject to change as needed:
6235 * For backends and overlays, we only allow renumbering.
6236 * For schema, we allow renaming with the same number.
6237 * Otherwise, the op is not allowed.
6240 if ( ce->ce_type == Cft_Schema ) {
6244 /* Can't alter the main cn=schema entry */
6245 if ( ce->ce_parent->ce_type == Cft_Global ) {
6246 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6247 rs->sr_text = "renaming not allowed for this entry";
6251 /* We could support this later if desired */
6252 ptr1 = ber_bvchr( &rdn, '}' );
6253 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
6254 len = ptr1 - rdn.bv_val;
6255 if ( len != ptr2 - op->orr_newrdn.bv_val ||
6256 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
6257 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6258 rs->sr_text = "schema reordering not supported";
6261 } else if ( ce->ce_type == Cft_Database ||
6262 ce->ce_type == Cft_Overlay ) {
6263 char *ptr1, *ptr2, *iptr1, *iptr2;
6266 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
6267 if ( *iptr2 != '{' ) {
6268 rs->sr_err = LDAP_NAMING_VIOLATION;
6269 rs->sr_text = "new ordering index is required";
6273 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
6274 ptr1 = ber_bvchr( &rdn, '}' );
6275 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
6277 rs->sr_err = LDAP_NAMING_VIOLATION;
6278 rs->sr_text = "new ordering index is required";
6282 len1 = ptr1 - rdn.bv_val;
6283 len2 = ptr2 - op->orr_newrdn.bv_val;
6285 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
6286 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
6287 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6288 rs->sr_text = "changing database/overlay type not allowed";
6291 ixold = strtol( iptr1, NULL, 0 );
6292 ixnew = strtol( iptr2, &ptr1, 0 );
6293 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
6294 rs->sr_err = LDAP_NAMING_VIOLATION;
6297 /* config DB is always 0, cannot be changed */
6298 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
6299 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
6303 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6304 rs->sr_text = "renaming not supported for this entry";
6308 if ( op->o_abandon ) {
6309 rs->sr_err = SLAPD_ABANDON;
6312 ldap_pvt_thread_pool_pause( &connection_pool );
6314 if ( ce->ce_type == Cft_Schema ) {
6315 req_modrdn_s modr = op->oq_modrdn;
6318 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
6319 if ( rs->sr_err == LDAP_SUCCESS ) {
6320 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
6321 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
6324 op->oq_modrdn = modr;
6326 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
6327 req_modrdn_s modr = op->oq_modrdn;
6330 /* Advance to first of this type */
6331 cprev = &ce->ce_parent->ce_kids;
6332 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
6333 cprev = &ce2->ce_sibs;
6336 /* Skip the -1 entry */
6337 if ( ce->ce_type == Cft_Database ) {
6338 cprev = &ce2->ce_sibs;
6344 /* Remove from old slot */
6345 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
6346 cprev = &ce2->ce_sibs;
6347 *cprev = ce->ce_sibs;
6348 ceold = ce->ce_sibs;
6350 /* Insert into new slot */
6352 for ( i=0; i<ixnew; i++ ) {
6356 cprev = &ce2->ce_sibs;
6358 ce->ce_sibs = *cprev;
6363 /* NOTE: These should be encoded in the OC tables, not inline here */
6364 if ( ce->ce_type == Cft_Database )
6365 backend_db_move( ce->ce_be, ixnew );
6366 else if ( ce->ce_type == Cft_Overlay )
6367 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
6369 if ( ixold < ixnew ) {
6370 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
6373 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
6374 ixold - ixnew, cfb->cb_use_ldif );
6376 op->oq_modrdn = modr;
6379 ldap_pvt_thread_pool_resume( &connection_pool );
6381 send_ldap_result( op, rs );
6386 config_back_delete( Operation *op, SlapReply *rs )
6388 #ifdef SLAP_CONFIG_DELETE
6390 CfEntryInfo *ce, *last, *ce2;
6392 cfb = (CfBackInfo *)op->o_bd->be_private;
6394 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6397 rs->sr_matched = last->ce_entry->e_name.bv_val;
6398 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6399 } else if ( ce->ce_kids ) {
6400 rs->sr_err = LDAP_NOT_ALLOWED_ON_NONLEAF;
6401 } else if ( op->o_abandon ) {
6402 rs->sr_err = SLAPD_ABANDON;
6403 } else if ( ce->ce_type == Cft_Overlay ||
6404 ce->ce_type == Cft_Database ||
6405 ce->ce_type == Cft_Misc ){
6409 ldap_pvt_thread_pool_pause( &connection_pool );
6411 if ( ce->ce_type == Cft_Overlay ){
6412 overlay_remove( ce->ce_be, (slap_overinst *)ce->ce_bi, op );
6413 } else if ( ce->ce_type == Cft_Misc ) {
6415 * only Cft_Misc objects that have a co_lddel handler set in
6416 * the ConfigOCs struct can be deleted. This code also
6417 * assumes that the entry can be only have one objectclass
6418 * with co_type == Cft_Misc
6420 ConfigOCs co, *coptr;
6424 oc_at = attr_find( ce->ce_entry->e_attrs,
6425 slap_schema.si_ad_objectClass );
6427 rs->sr_err = LDAP_OTHER;
6428 rs->sr_text = "objectclass not found";
6429 ldap_pvt_thread_pool_resume( &connection_pool );
6432 for ( i=0; !BER_BVISNULL(&oc_at->a_nvals[i]); i++ ) {
6433 co.co_name = &oc_at->a_nvals[i];
6434 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
6435 if ( coptr == NULL || coptr->co_type != Cft_Misc ) {
6438 if ( ! coptr->co_lddel || coptr->co_lddel( ce, op ) ){
6439 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6440 if ( ! coptr->co_lddel ) {
6441 rs->sr_text = "No delete handler found";
6443 rs->sr_err = LDAP_OTHER;
6444 /* FIXME: We should return a helpful error message
6447 ldap_pvt_thread_pool_resume( &connection_pool );
6452 } else if (ce->ce_type == Cft_Database ) {
6453 if ( ce->ce_be == frontendDB || ce->ce_be == op->o_bd ){
6454 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6455 rs->sr_text = "Cannot delete config or frontend database";
6456 ldap_pvt_thread_pool_resume( &connection_pool );
6459 if ( ce->ce_be->bd_info->bi_db_close ) {
6460 ce->ce_be->bd_info->bi_db_close( ce->ce_be, NULL );
6462 backend_destroy_one( ce->ce_be, 1);
6465 /* remove CfEntryInfo from the siblings list */
6466 if ( ce->ce_parent->ce_kids == ce ) {
6467 ce->ce_parent->ce_kids = ce->ce_sibs;
6469 for ( ce2 = ce->ce_parent->ce_kids ; ce2; ce2 = ce2->ce_sibs ) {
6470 if ( ce2->ce_sibs == ce ) {
6471 ce2->ce_sibs = ce->ce_sibs;
6477 /* remove from underlying database */
6478 if ( cfb->cb_use_ldif ) {
6479 BackendDB *be = op->o_bd;
6480 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
6481 struct berval dn, ndn, req_dn, req_ndn;
6483 op->o_bd = &cfb->cb_db;
6487 req_dn = op->o_req_dn;
6488 req_ndn = op->o_req_ndn;
6490 op->o_dn = op->o_bd->be_rootdn;
6491 op->o_ndn = op->o_bd->be_rootndn;
6492 op->o_req_dn = ce->ce_entry->e_name;
6493 op->o_req_ndn = ce->ce_entry->e_nname;
6495 scp = op->o_callback;
6496 op->o_callback = ≻
6497 op->o_bd->be_delete( op, rs );
6499 op->o_callback = scp;
6502 op->o_req_dn = req_dn;
6503 op->o_req_ndn = req_ndn;
6506 /* renumber siblings */
6507 iptr = ber_bvchr( &op->o_req_ndn, '{' ) + 1;
6508 ixold = strtol( iptr, NULL, 0 );
6509 for (ce2 = ce->ce_sibs, count=0; ce2; ce2=ce2->ce_sibs) {
6510 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
6511 count+ixold, 0, cfb->cb_use_ldif );
6515 ce->ce_entry->e_private=NULL;
6516 entry_free(ce->ce_entry);
6518 ldap_pvt_thread_pool_resume( &connection_pool );
6520 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6524 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6525 #endif /* SLAP_CONFIG_DELETE */
6526 send_ldap_result( op, rs );
6531 config_back_search( Operation *op, SlapReply *rs )
6534 CfEntryInfo *ce, *last;
6537 cfb = (CfBackInfo *)op->o_bd->be_private;
6539 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6542 rs->sr_matched = last->ce_entry->e_name.bv_val;
6543 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6546 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
6547 ACL_SEARCH, NULL, &mask ))
6549 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
6550 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6552 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6556 switch ( op->ors_scope ) {
6557 case LDAP_SCOPE_BASE:
6558 case LDAP_SCOPE_SUBTREE:
6559 rs->sr_err = config_send( op, rs, ce, 0 );
6562 case LDAP_SCOPE_ONELEVEL:
6563 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
6564 rs->sr_err = config_send( op, rs, ce, 1 );
6573 send_ldap_result( op, rs );
6577 /* no-op, we never free entries */
6578 int config_entry_release(
6583 if ( !e->e_private ) {
6586 return LDAP_SUCCESS;
6589 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
6591 int config_back_entry_get(
6595 AttributeDescription *at,
6600 CfEntryInfo *ce, *last;
6601 int rc = LDAP_NO_SUCH_OBJECT;
6603 cfb = (CfBackInfo *)op->o_bd->be_private;
6605 ce = config_find_base( cfb->cb_root, ndn, &last );
6607 *ent = ce->ce_entry;
6610 if ( oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
6611 rc = LDAP_NO_SUCH_ATTRIBUTE;
6621 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
6622 ConfigTable *ct, ConfigArgs *c )
6626 for (; at && *at; at++) {
6627 /* Skip the naming attr */
6628 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
6630 for (i=0;ct[i].name;i++) {
6631 if (ct[i].ad == (*at)->sat_ad) {
6632 rc = config_get_vals(&ct[i], c);
6633 /* NOTE: tolerate that config_get_vals()
6634 * returns success with no values */
6635 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
6636 if ( c->rvalue_nvals )
6637 rc = attr_merge(e, ct[i].ad, c->rvalue_vals,
6640 slap_syntax_validate_func *validate =
6641 ct[i].ad->ad_type->sat_syntax->ssyn_validate;
6644 for ( j=0; c->rvalue_vals[j].bv_val; j++ ) {
6645 rc = ordered_value_validate( ct[i].ad,
6646 &c->rvalue_vals[j], LDAP_MOD_ADD );
6648 Debug( LDAP_DEBUG_ANY,
6649 "config_build_attrs: error %d on %s value #%d\n",
6650 rc, ct[i].ad->ad_cname.bv_val, j );
6656 rc = attr_merge_normalize(e, ct[i].ad,
6657 c->rvalue_vals, NULL);
6659 ber_bvarray_free( c->rvalue_nvals );
6660 ber_bvarray_free( c->rvalue_vals );
6662 Debug( LDAP_DEBUG_ANY,
6663 "config_build_attrs: error %d on %s\n",
6664 rc, ct[i].ad->ad_cname.bv_val, 0 );
6675 /* currently (2010) does not access rs except possibly writing rs->sr_err */
6678 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
6679 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
6681 Entry *e = entry_alloc();
6682 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
6684 struct berval ad_name;
6685 AttributeDescription *ad = NULL;
6688 const char *text = "";
6692 CfEntryInfo *ceprev = NULL;
6694 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
6697 ce->ce_type = main->co_type;
6698 ce->ce_parent = parent;
6700 pdn = parent->ce_entry->e_nname;
6701 if ( parent->ce_kids && parent->ce_kids->ce_type <= ce->ce_type )
6702 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
6703 ceprev->ce_type <= ce->ce_type;
6704 ceprev = ceprev->ce_sibs );
6709 ce->ce_private = c->ca_private;
6713 build_new_dn( &e->e_name, &pdn, rdn, NULL );
6714 ber_dupbv( &e->e_nname, &e->e_name );
6716 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6717 main->co_name, NULL );
6719 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6720 extra->co_name, NULL );
6721 ptr = strchr(rdn->bv_val, '=');
6722 ad_name.bv_val = rdn->bv_val;
6723 ad_name.bv_len = ptr - rdn->bv_val;
6724 rc = slap_bv2ad( &ad_name, &ad, &text );
6729 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
6730 attr_merge_normalize_one(e, ad, &val, NULL );
6733 c->table = main->co_type;
6734 if ( oc->soc_required ) {
6735 rc = config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
6736 if ( rc ) goto fail;
6739 if ( oc->soc_allowed ) {
6740 rc = config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
6741 if ( rc ) goto fail;
6746 c->table = extra->co_type;
6747 if ( oc->soc_required ) {
6748 rc = config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
6749 if ( rc ) goto fail;
6752 if ( oc->soc_allowed ) {
6753 rc = config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
6754 if ( rc ) goto fail;
6758 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
6759 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
6760 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
6761 if ( rc != LDAP_SUCCESS ) {
6763 Debug( LDAP_DEBUG_ANY,
6764 "config_build_entry: build \"%s\" failed: \"%s\"\n",
6765 rdn->bv_val, text, 0);
6768 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
6771 op->ora_modlist = NULL;
6772 slap_add_opattrs( op, NULL, NULL, 0, 0 );
6773 if ( !op->o_noop ) {
6774 SlapReply rs2 = {REP_RESULT};
6775 op->o_bd->be_add( op, &rs2 );
6776 rs->sr_err = rs2.sr_err;
6777 rs_assert_done( &rs2 );
6778 if ( ( rs2.sr_err != LDAP_SUCCESS )
6779 && (rs2.sr_err != LDAP_ALREADY_EXISTS) ) {
6785 ce->ce_sibs = ceprev->ce_sibs;
6786 ceprev->ce_sibs = ce;
6787 } else if ( parent ) {
6788 ce->ce_sibs = parent->ce_kids;
6789 parent->ce_kids = ce;
6796 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
6797 Operation *op, SlapReply *rs )
6800 ConfigFile *cf = c->ca_private;
6802 struct berval bv, rdn;
6804 for (; cf; cf=cf->c_sibs, c->depth++) {
6805 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
6806 !cf->c_om_head && !cf->c_syn_head ) continue;
6807 c->value_dn.bv_val = c->log;
6808 LUTIL_SLASHPATH( cf->c_file.bv_val );
6809 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
6814 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
6816 ptr = strchr( bv.bv_val, '.' );
6818 bv.bv_len = ptr - bv.bv_val;
6819 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
6820 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6821 /* FIXME: how can indicate error? */
6824 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
6826 c->value_dn.bv_len += bv.bv_len;
6827 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
6828 rdnNormalize( 0, NULL, NULL, &c->value_dn, &rdn, NULL );
6831 e = config_build_entry( op, rs, ceparent, c, &rdn,
6832 &CFOC_SCHEMA, NULL );
6833 ch_free( rdn.bv_val );
6836 } else if ( e && cf->c_kids ) {
6837 c->ca_private = cf->c_kids;
6838 config_build_schema_inc( c, e->e_private, op, rs );
6844 #ifdef SLAPD_MODULES
6847 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
6848 Operation *op, SlapReply *rs )
6853 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
6854 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
6856 c->value_dn.bv_val = c->log;
6857 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
6858 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6859 /* FIXME: how can indicate error? */
6863 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
6872 config_check_schema(Operation *op, CfBackInfo *cfb)
6874 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
6876 CfEntryInfo *ce, *last;
6879 /* If there's no root entry, we must be in the midst of converting */
6880 if ( !cfb->cb_root )
6883 /* Make sure the main schema entry exists */
6884 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
6891 /* Make sure it's up to date */
6892 if ( cf_om_tail != om_sys_tail ) {
6893 a = attr_find( e->e_attrs, cfAd_om );
6895 if ( a->a_nvals != a->a_vals )
6896 ber_bvarray_free( a->a_nvals );
6897 ber_bvarray_free( a->a_vals );
6902 oidm_unparse( &bv, NULL, NULL, 1 );
6903 attr_merge_normalize( e, cfAd_om, bv, NULL );
6904 ber_bvarray_free( bv );
6905 cf_om_tail = om_sys_tail;
6907 if ( cf_at_tail != at_sys_tail ) {
6908 a = attr_find( e->e_attrs, cfAd_attr );
6910 if ( a->a_nvals != a->a_vals )
6911 ber_bvarray_free( a->a_nvals );
6912 ber_bvarray_free( a->a_vals );
6917 at_unparse( &bv, NULL, NULL, 1 );
6918 attr_merge_normalize( e, cfAd_attr, bv, NULL );
6919 ber_bvarray_free( bv );
6920 cf_at_tail = at_sys_tail;
6922 if ( cf_oc_tail != oc_sys_tail ) {
6923 a = attr_find( e->e_attrs, cfAd_oc );
6925 if ( a->a_nvals != a->a_vals )
6926 ber_bvarray_free( a->a_nvals );
6927 ber_bvarray_free( a->a_vals );
6932 oc_unparse( &bv, NULL, NULL, 1 );
6933 attr_merge_normalize( e, cfAd_oc, bv, NULL );
6934 ber_bvarray_free( bv );
6935 cf_oc_tail = oc_sys_tail;
6937 if ( cf_syn_tail != syn_sys_tail ) {
6938 a = attr_find( e->e_attrs, cfAd_syntax );
6940 if ( a->a_nvals != a->a_vals )
6941 ber_bvarray_free( a->a_nvals );
6942 ber_bvarray_free( a->a_vals );
6947 syn_unparse( &bv, NULL, NULL, 1 );
6948 attr_merge_normalize( e, cfAd_syntax, bv, NULL );
6949 ber_bvarray_free( bv );
6950 cf_syn_tail = syn_sys_tail;
6953 SlapReply rs = {REP_RESULT};
6954 c.ca_private = NULL;
6955 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
6956 &CFOC_SCHEMA, NULL );
6961 ce->ce_private = cfb->cb_config;
6962 cf_at_tail = at_sys_tail;
6963 cf_oc_tail = oc_sys_tail;
6964 cf_om_tail = om_sys_tail;
6965 cf_syn_tail = syn_sys_tail;
6970 static const char *defacl[] = {
6971 NULL, "to", "*", "by", "*", "none", NULL
6975 config_back_db_open( BackendDB *be, ConfigReply *cr )
6977 CfBackInfo *cfb = be->be_private;
6980 CfEntryInfo *ce, *ceparent;
6984 Connection conn = {0};
6985 OperationBuffer opbuf;
6987 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
6988 SlapReply rs = {REP_RESULT};
6989 void *thrctx = NULL;
6990 AccessControl *save_access;
6992 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
6994 /* If we have no explicitly configured ACLs, don't just use
6995 * the global ACLs. Explicitly deny access to everything.
6997 save_access = be->bd_self->be_acl;
6998 be->bd_self->be_acl = NULL;
6999 parse_acl(be->bd_self, "config_back_db_open", 0, 6, (char **)defacl, 0 );
7000 defacl_parsed = be->bd_self->be_acl;
7001 if ( save_access ) {
7002 be->bd_self->be_acl = save_access;
7004 Debug( LDAP_DEBUG_CONFIG, "config_back_db_open: "
7005 "No explicit ACL for back-config configured. "
7006 "Using hardcoded default\n", 0, 0, 0 );
7009 thrctx = ldap_pvt_thread_pool_context();
7010 connection_fake_init( &conn, &opbuf, thrctx );
7013 op->o_tag = LDAP_REQ_ADD;
7014 op->o_callback = &cb;
7015 op->o_bd = &cfb->cb_db;
7016 op->o_dn = op->o_bd->be_rootdn;
7017 op->o_ndn = op->o_bd->be_rootndn;
7019 if ( !cfb->cb_use_ldif ) {
7023 /* If we read the config from back-ldif, do some quick sanity checks */
7024 if ( cfb->cb_got_ldif ) {
7025 return config_check_schema( op, cfb );
7028 /* create root of tree */
7030 c.ca_private = cfb->cb_config;
7032 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
7042 #ifdef SLAPD_MODULES
7043 /* Create Module nodes... */
7044 if ( modpaths.mp_loads ) {
7045 if ( config_build_modules( &c, ceparent, op, &rs ) ){
7051 /* Create schema nodes... cn=schema will contain the hardcoded core
7052 * schema, read-only. Child objects will contain runtime loaded schema
7056 c.ca_private = NULL;
7057 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
7062 ce->ce_private = cfb->cb_config;
7063 cf_at_tail = at_sys_tail;
7064 cf_oc_tail = oc_sys_tail;
7065 cf_om_tail = om_sys_tail;
7066 cf_syn_tail = syn_sys_tail;
7068 /* Create schema nodes for included schema... */
7069 if ( cfb->cb_config->c_kids ) {
7072 c.ca_private = cfb->cb_config->c_kids;
7073 rc = config_build_schema_inc( &c, ce, op, &rs );
7079 /* Create backend nodes. Skip if they don't provide a cf_table.
7080 * There usually aren't any of these.
7084 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
7085 if (!bi->bi_cf_ocs) {
7086 /* If it only supports the old config mech, complain. */
7087 if ( bi->bi_config ) {
7088 Debug( LDAP_DEBUG_ANY,
7089 "WARNING: No dynamic config support for backend %s.\n",
7090 bi->bi_type, 0, 0 );
7095 if (!bi->bi_private) continue;
7098 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
7099 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
7100 if ( rdn.bv_len >= sizeof( c.log ) ) {
7101 /* FIXME: holler ... */ ;
7104 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
7111 /* Create database nodes... */
7112 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
7113 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
7114 for ( i = -1, be = frontendDB ; be;
7115 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
7116 slap_overinfo *oi = NULL;
7118 if ( overlay_is_over( be )) {
7119 oi = be->bd_info->bi_private;
7125 /* If this backend supports the old config mechanism, but not
7126 * the new mech, complain.
7128 if ( !be->be_cf_ocs && bi->bi_db_config ) {
7129 Debug( LDAP_DEBUG_ANY,
7130 "WARNING: No dynamic config support for database %s.\n",
7131 bi->bi_type, 0, 0 );
7135 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
7136 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
7138 if ( rdn.bv_len >= sizeof( c.log ) ) {
7139 /* FIXME: holler ... */ ;
7143 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
7149 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd ) {
7150 rs_reinit( &rs, REP_RESULT );
7151 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
7153 /* Iterate through overlays */
7158 voidList *vl, *v0 = NULL;
7160 /* overlays are in LIFO order, must reverse stack */
7161 for (on=oi->oi_list; on; on=on->on_next) {
7162 vl = ch_malloc( sizeof( voidList ));
7167 for (j=0; vl; j++,vl=v0) {
7171 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
7172 Debug( LDAP_DEBUG_ANY,
7173 "WARNING: No dynamic config support for overlay %s.\n",
7174 on->on_bi.bi_type, 0, 0 );
7178 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
7179 "%s=" SLAP_X_ORDERED_FMT "%s",
7180 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
7181 if ( rdn.bv_len >= sizeof( c.log ) ) {
7182 /* FIXME: holler ... */ ;
7186 oe = config_build_entry( op, &rs, ce, &c, &rdn,
7187 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
7191 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd ) {
7192 rs_reinit( &rs, REP_RESULT );
7193 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
7199 ldap_pvt_thread_pool_context_reset( thrctx );
7201 if ( unsupp && cfb->cb_use_ldif ) {
7202 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
7203 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
7210 cfb_free_cffile( ConfigFile *cf )
7214 for (; cf; cf=next) {
7217 cfb_free_cffile( cf->c_kids );
7218 ch_free( cf->c_file.bv_val );
7219 ber_bvarray_free( cf->c_dseFiles );
7225 cfb_free_entries( CfEntryInfo *ce )
7229 for (; ce; ce=next) {
7232 cfb_free_entries( ce->ce_kids );
7233 ce->ce_entry->e_private = NULL;
7234 entry_free( ce->ce_entry );
7240 config_back_db_close( BackendDB *be, ConfigReply *cr )
7242 CfBackInfo *cfb = be->be_private;
7244 cfb_free_entries( cfb->cb_root );
7245 cfb->cb_root = NULL;
7247 if ( cfb->cb_db.bd_info ) {
7248 backend_shutdown( &cfb->cb_db );
7251 if ( defacl_parsed && be->be_acl != defacl_parsed ) {
7252 acl_free( defacl_parsed );
7253 defacl_parsed = NULL;
7260 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
7262 CfBackInfo *cfb = be->be_private;
7264 cfb_free_cffile( cfb->cb_config );
7266 ch_free( cfdir.bv_val );
7268 avl_free( CfOcTree, NULL );
7270 if ( cfb->cb_db.bd_info ) {
7271 cfb->cb_db.be_suffix = NULL;
7272 cfb->cb_db.be_nsuffix = NULL;
7273 BER_BVZERO( &cfb->cb_db.be_rootdn );
7274 BER_BVZERO( &cfb->cb_db.be_rootndn );
7276 backend_destroy_one( &cfb->cb_db, 0 );
7285 config_back_db_init( BackendDB *be, ConfigReply* cr )
7291 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
7292 cfn = cfb->cb_config;
7293 be->be_private = cfb;
7295 ber_dupbv( &be->be_rootdn, &config_rdn );
7296 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
7297 ber_dupbv( &dn, &be->be_rootdn );
7298 ber_bvarray_add( &be->be_suffix, &dn );
7299 ber_dupbv( &dn, &be->be_rootdn );
7300 ber_bvarray_add( &be->be_nsuffix, &dn );
7302 /* Hide from namingContexts */
7303 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
7305 /* Check ACLs on content of Adds by default */
7306 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_ACL_ADD;
7312 config_back_destroy( BackendInfo *bi )
7314 ldif_must_b64_encode_release();
7319 config_tool_entry_open( BackendDB *be, int mode )
7321 CfBackInfo *cfb = be->be_private;
7322 BackendInfo *bi = cfb->cb_db.bd_info;
7324 if ( bi && bi->bi_tool_entry_open )
7325 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
7332 config_tool_entry_close( BackendDB *be )
7334 CfBackInfo *cfb = be->be_private;
7335 BackendInfo *bi = cfb->cb_db.bd_info;
7337 if ( bi && bi->bi_tool_entry_close )
7338 return bi->bi_tool_entry_close( &cfb->cb_db );
7344 config_tool_entry_first( BackendDB *be )
7346 CfBackInfo *cfb = be->be_private;
7347 BackendInfo *bi = cfb->cb_db.bd_info;
7349 if ( bi && bi->bi_tool_entry_first ) {
7350 return bi->bi_tool_entry_first( &cfb->cb_db );
7352 if ( bi && bi->bi_tool_entry_first_x ) {
7353 return bi->bi_tool_entry_first_x( &cfb->cb_db,
7354 NULL, LDAP_SCOPE_DEFAULT, NULL );
7360 config_tool_entry_first_x(
7362 struct berval *base,
7366 CfBackInfo *cfb = be->be_private;
7367 BackendInfo *bi = cfb->cb_db.bd_info;
7369 if ( bi && bi->bi_tool_entry_first_x ) {
7370 return bi->bi_tool_entry_first_x( &cfb->cb_db, base, scope, f );
7376 config_tool_entry_next( BackendDB *be )
7378 CfBackInfo *cfb = be->be_private;
7379 BackendInfo *bi = cfb->cb_db.bd_info;
7381 if ( bi && bi->bi_tool_entry_next )
7382 return bi->bi_tool_entry_next( &cfb->cb_db );
7388 config_tool_entry_get( BackendDB *be, ID id )
7390 CfBackInfo *cfb = be->be_private;
7391 BackendInfo *bi = cfb->cb_db.bd_info;
7393 if ( bi && bi->bi_tool_entry_get )
7394 return bi->bi_tool_entry_get( &cfb->cb_db, id );
7399 static int entry_put_got_frontend=0;
7400 static int entry_put_got_config=0;
7402 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
7404 CfBackInfo *cfb = be->be_private;
7405 BackendInfo *bi = cfb->cb_db.bd_info;
7407 struct berval rdn, vals[ 2 ];
7409 OperationBuffer opbuf;
7411 Connection conn = {0};
7412 Operation *op = NULL;
7415 int isFrontendChild = 0;
7417 /* Create entry for frontend database if it does not exist already */
7418 if ( !entry_put_got_frontend ) {
7419 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
7420 STRLENOF( "olcDatabase" ))) {
7421 if ( strncmp( e->e_nname.bv_val +
7422 STRLENOF( "olcDatabase" ), "={-1}frontend",
7423 STRLENOF( "={-1}frontend" )) &&
7424 strncmp( e->e_nname.bv_val +
7425 STRLENOF( "olcDatabase" ), "=frontend",
7426 STRLENOF( "=frontend" ))) {
7428 vals[1].bv_val = NULL;
7429 memset( &ca, 0, sizeof(ConfigArgs));
7431 ca.bi = frontendDB->bd_info;
7432 ca.be->be_cf_ocs = &CFOC_FRONTEND;
7433 rdn.bv_val = ca.log;
7434 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7435 "%s=" SLAP_X_ORDERED_FMT "%s",
7436 cfAd_database->ad_cname.bv_val, -1,
7438 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
7439 &CFOC_DATABASE, ca.be->be_cf_ocs );
7440 thrctx = ldap_pvt_thread_pool_context();
7441 connection_fake_init2( &conn, &opbuf, thrctx,0 );
7443 op->o_bd = &cfb->cb_db;
7444 op->o_tag = LDAP_REQ_ADD;
7446 op->o_dn = be->be_rootdn;
7447 op->o_ndn = be->be_rootndn;
7448 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
7449 if ( rc != LDAP_SUCCESS ) {
7450 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
7451 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
7455 if ( ce && bi && bi->bi_tool_entry_put &&
7456 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
7457 entry_put_got_frontend++;
7459 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
7460 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
7464 if ( !strncmp( e->e_nname.bv_val +
7465 STRLENOF( "olcDatabase" ), "=frontend",
7466 STRLENOF( "=frontend" ) ) )
7468 struct berval rdn, pdn, ndn;
7469 dnParent( &e->e_nname, &pdn );
7470 rdn.bv_val = ca.log;
7471 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7472 "%s=" SLAP_X_ORDERED_FMT "%s",
7473 cfAd_database->ad_cname.bv_val, -1,
7474 frontendDB->bd_info->bi_type );
7475 build_new_dn( &ndn, &pdn, &rdn, NULL );
7476 ber_memfree( e->e_name.bv_val );
7478 ber_bvreplace( &e->e_nname, &e->e_name );
7480 entry_put_got_frontend++;
7486 /* Child entries of the frontend database, e.g. slapo-chain's back-ldap
7487 * instances, may appear before the config database entry in the ldif, skip
7488 * auto-creation of olcDatabase={0}config in such a case */
7489 if ( !entry_put_got_config &&
7490 !strncmp( e->e_nname.bv_val, "olcDatabase", STRLENOF( "olcDatabase" ))) {
7492 dnParent( &e->e_nname, &pdn );
7493 while ( pdn.bv_len ) {
7494 if ( !strncmp( pdn.bv_val, "olcDatabase",
7495 STRLENOF( "olcDatabase" ))) {
7496 if ( !strncmp( pdn.bv_val +
7497 STRLENOF( "olcDatabase" ), "={-1}frontend",
7498 STRLENOF( "={-1}frontend" )) ||
7499 !strncmp( pdn.bv_val +
7500 STRLENOF( "olcDatabase" ), "=frontend",
7501 STRLENOF( "=frontend" ))) {
7503 isFrontendChild = 1;
7507 dnParent( &pdn, &pdn );
7511 /* Create entry for config database if it does not exist already */
7512 if ( !entry_put_got_config && !isFrontend && !isFrontendChild ) {
7513 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
7514 STRLENOF( "olcDatabase" ))) {
7515 if ( strncmp( e->e_nname.bv_val +
7516 STRLENOF( "olcDatabase" ), "={0}config",
7517 STRLENOF( "={0}config" )) &&
7518 strncmp( e->e_nname.bv_val +
7519 STRLENOF( "olcDatabase" ), "=config",
7520 STRLENOF( "=config" )) ) {
7522 vals[1].bv_val = NULL;
7523 memset( &ca, 0, sizeof(ConfigArgs));
7524 ca.be = LDAP_STAILQ_FIRST( &backendDB );
7525 ca.bi = ca.be->bd_info;
7526 rdn.bv_val = ca.log;
7527 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7528 "%s=" SLAP_X_ORDERED_FMT "%s",
7529 cfAd_database->ad_cname.bv_val, 0,
7531 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
7534 thrctx = ldap_pvt_thread_pool_context();
7535 connection_fake_init2( &conn, &opbuf, thrctx,0 );
7537 op->o_bd = &cfb->cb_db;
7538 op->o_tag = LDAP_REQ_ADD;
7539 op->o_dn = be->be_rootdn;
7540 op->o_ndn = be->be_rootndn;
7543 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
7544 if ( rc != LDAP_SUCCESS ) {
7545 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
7546 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7549 if (ce && bi && bi->bi_tool_entry_put &&
7550 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
7551 entry_put_got_config++;
7553 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
7554 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7558 entry_put_got_config++;
7562 if ( bi && bi->bi_tool_entry_put &&
7563 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
7564 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
7571 AttributeDescription **desc;
7573 { "attribute", &cfAd_attr },
7574 { "backend", &cfAd_backend },
7575 { "database", &cfAd_database },
7576 { "include", &cfAd_include },
7577 { "ldapsyntax", &cfAd_syntax },
7578 { "objectclass", &cfAd_oc },
7579 { "objectidentifier", &cfAd_om },
7580 { "overlay", &cfAd_overlay },
7585 * add / delete: all types that may be added or deleted must use an
7586 * X-ORDERED attributeType for their RDN. Adding and deleting entries
7587 * should automatically renumber the index of any siblings as needed,
7588 * so that no gaps in the numbering sequence exist after the add/delete
7590 * What can be added:
7592 * backend objects for backend-specific config directives
7596 * delete: probably no support this time around.
7598 * modrdn: generally not done. Will be invoked automatically by add/
7599 * delete to update numbering sequence. Perform as an explicit operation
7600 * so that the renumbering effect may be replicated. Subtree rename must
7601 * be supported, since renumbering a database will affect all its child
7604 * modify: must be fully supported.
7608 config_back_initialize( BackendInfo *bi )
7610 ConfigTable *ct = config_back_cf_table;
7614 AttributeDescription *ad = NULL;
7616 static char *controls[] = {
7617 LDAP_CONTROL_MANAGEDSAIT,
7621 /* Make sure we don't exceed the bits reserved for userland */
7622 config_check_userland( CFG_LAST );
7624 bi->bi_controls = controls;
7629 bi->bi_destroy = config_back_destroy;
7631 bi->bi_db_init = config_back_db_init;
7632 bi->bi_db_config = 0;
7633 bi->bi_db_open = config_back_db_open;
7634 bi->bi_db_close = config_back_db_close;
7635 bi->bi_db_destroy = config_back_db_destroy;
7637 bi->bi_op_bind = config_back_bind;
7638 bi->bi_op_unbind = 0;
7639 bi->bi_op_search = config_back_search;
7640 bi->bi_op_compare = 0;
7641 bi->bi_op_modify = config_back_modify;
7642 bi->bi_op_modrdn = config_back_modrdn;
7643 bi->bi_op_add = config_back_add;
7644 bi->bi_op_delete = config_back_delete;
7645 bi->bi_op_abandon = 0;
7647 bi->bi_extended = 0;
7649 bi->bi_chk_referrals = 0;
7651 bi->bi_access_allowed = slap_access_allowed;
7653 bi->bi_connection_init = 0;
7654 bi->bi_connection_destroy = 0;
7656 bi->bi_entry_release_rw = config_entry_release;
7657 bi->bi_entry_get_rw = config_back_entry_get;
7659 bi->bi_tool_entry_open = config_tool_entry_open;
7660 bi->bi_tool_entry_close = config_tool_entry_close;
7661 bi->bi_tool_entry_first = config_tool_entry_first;
7662 bi->bi_tool_entry_first_x = config_tool_entry_first_x;
7663 bi->bi_tool_entry_next = config_tool_entry_next;
7664 bi->bi_tool_entry_get = config_tool_entry_get;
7665 bi->bi_tool_entry_put = config_tool_entry_put;
7668 argv[ 0 ] = "slapd";
7674 for (i=0; OidMacros[i].name; i++ ) {
7675 argv[1] = OidMacros[i].name;
7676 argv[2] = OidMacros[i].oid;
7677 parse_oidm( &ca, 0, NULL );
7680 bi->bi_cf_ocs = cf_ocs;
7682 i = config_register_schema( ct, cf_ocs );
7685 i = slap_str2ad( "olcDatabase", &olcDatabaseDummy[0].ad, &text );
7688 /* setup olcRootPW to be base64-encoded when written in LDIF form;
7689 * basically, we don't care if it fails */
7690 i = slap_str2ad( "olcRootPW", &ad, &text );
7692 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
7693 "warning, unable to get \"olcRootPW\" "
7694 "attribute description: %d: %s\n",
7697 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
7698 ad->ad_type->sat_oid );
7701 /* set up the notable AttributeDescriptions */
7703 for (;ct->name;ct++) {
7704 if (strcmp(ct->name, ads[i].name)) continue;
7705 *ads[i].desc = ct->ad;
7707 if (!ads[i].name) break;