1 /* bconfig.c - the config backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005-2017 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,
214 static OidRec OidMacros[] = {
215 /* OpenLDAProot:1.12.2 */
216 { "OLcfg", "1.3.6.1.4.1.4203.1.12.2" },
217 { "OLcfgAt", "OLcfg:3" },
218 { "OLcfgGlAt", "OLcfgAt:0" },
219 { "OLcfgBkAt", "OLcfgAt:1" },
220 { "OLcfgDbAt", "OLcfgAt:2" },
221 { "OLcfgOvAt", "OLcfgAt:3" },
222 { "OLcfgCtAt", "OLcfgAt:4" }, /* contrib modules */
223 { "OLcfgOc", "OLcfg:4" },
224 { "OLcfgGlOc", "OLcfgOc:0" },
225 { "OLcfgBkOc", "OLcfgOc:1" },
226 { "OLcfgDbOc", "OLcfgOc:2" },
227 { "OLcfgOvOc", "OLcfgOc:3" },
228 { "OLcfgCtOc", "OLcfgOc:4" }, /* contrib modules */
230 /* Syntaxes. We should just start using the standard names and
231 * document that they are predefined and available for users
232 * to reference in their own schema. Defining schema without
233 * OID macros is for masochists...
235 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
236 { "OMsBoolean", "OMsyn:7" },
237 { "OMsDN", "OMsyn:12" },
238 { "OMsDirectoryString", "OMsyn:15" },
239 { "OMsIA5String", "OMsyn:26" },
240 { "OMsInteger", "OMsyn:27" },
241 { "OMsOID", "OMsyn:38" },
242 { "OMsOctetString", "OMsyn:40" },
247 * Backend/Database registry
249 * OLcfg{Bk|Db}{Oc|At}:0 -> common
250 * OLcfg{Bk|Db}{Oc|At}:1 -> back-bdb(/back-hdb)
251 * OLcfg{Bk|Db}{Oc|At}:2 -> back-ldif
252 * OLcfg{Bk|Db}{Oc|At}:3 -> back-ldap/meta
253 * OLcfg{Bk|Db}{Oc|At}:4 -> back-monitor
254 * OLcfg{Bk|Db}{Oc|At}:5 -> back-relay
255 * OLcfg{Bk|Db}{Oc|At}:6 -> back-sql(/back-ndb)
256 * OLcfg{Bk|Db}{Oc|At}:7 -> back-sock
257 * OLcfg{Bk|Db}{Oc|At}:8 -> back-null
258 * OLcfg{Bk|Db}{Oc|At}:9 -> back-passwd
259 * OLcfg{Bk|Db}{Oc|At}:10 -> back-shell
260 * OLcfg{Bk|Db}{Oc|At}:11 -> back-perl
261 * OLcfg{Bk|Db}{Oc|At}:12 -> back-mdb
267 * OLcfgOv{Oc|At}:1 -> syncprov
268 * OLcfgOv{Oc|At}:2 -> pcache
269 * OLcfgOv{Oc|At}:3 -> chain
270 * OLcfgOv{Oc|At}:4 -> accesslog
271 * OLcfgOv{Oc|At}:5 -> valsort
272 * OLcfgOv{Oc|At}:7 -> distproc
273 * OLcfgOv{Oc|At}:8 -> dynlist
274 * OLcfgOv{Oc|At}:9 -> dds
275 * OLcfgOv{Oc|At}:10 -> unique
276 * OLcfgOv{Oc|At}:11 -> refint
277 * OLcfgOv{Oc|At}:12 -> ppolicy
278 * OLcfgOv{Oc|At}:13 -> constraint
279 * OLcfgOv{Oc|At}:14 -> translucent
280 * OLcfgOv{Oc|At}:15 -> auditlog
281 * OLcfgOv{Oc|At}:16 -> rwm
282 * OLcfgOv{Oc|At}:17 -> dyngroup
283 * OLcfgOv{Oc|At}:18 -> memberof
284 * OLcfgOv{Oc|At}:19 -> collect
285 * OLcfgOv{Oc|At}:20 -> retcode
286 * OLcfgOv{Oc|At}:21 -> sssvlv
289 /* alphabetical ordering */
291 static ConfigTable config_back_cf_table[] = {
292 /* This attr is read-only */
293 { "", "", 0, 0, 0, ARG_MAGIC,
294 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
295 "DESC 'File for slapd configuration directives' "
296 "EQUALITY caseIgnoreMatch "
297 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
298 { "", "", 0, 0, 0, ARG_MAGIC,
299 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
300 "DESC 'Directory for slapd configuration backend' "
301 "EQUALITY caseIgnoreMatch "
302 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
303 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
304 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
305 "DESC 'Access Control List' "
306 "EQUALITY caseIgnoreMatch "
307 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
308 { "add_content_acl", NULL, 0, 0, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_ACL_ADD,
309 &config_generic, "( OLcfgGlAt:86 NAME 'olcAddContentAcl' "
310 "DESC 'Check ACLs against content of Add ops' "
311 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
312 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
313 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
314 "DESC 'Allowed set of deprecated features' "
315 "EQUALITY caseIgnoreMatch "
316 "SYNTAX OMsDirectoryString )", NULL, NULL },
317 { "argsfile", "file", 2, 2, 0, ARG_STRING,
318 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
319 "DESC 'File for slapd command line options' "
320 "EQUALITY caseIgnoreMatch "
321 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
322 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
323 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
324 "EQUALITY caseIgnoreMatch "
325 "SYNTAX OMsDirectoryString )", NULL, NULL },
326 { "attribute", "attribute", 2, 0, STRLENOF( "attribute" ),
327 ARG_PAREN|ARG_MAGIC|CFG_ATTR,
328 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
329 "DESC 'OpenLDAP attributeTypes' "
330 "EQUALITY caseIgnoreMatch "
331 "SUBSTR caseIgnoreSubstringsMatch "
332 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
334 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
335 #ifdef SLAP_AUTH_REWRITE
336 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
340 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
341 "EQUALITY caseIgnoreMatch "
342 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
343 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
344 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
345 "EQUALITY caseIgnoreMatch "
346 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
347 { "authz-regexp", "regexp> <DN", 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
348 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
349 "EQUALITY caseIgnoreMatch "
350 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
351 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
352 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
353 "DESC 'A type of backend' "
354 "EQUALITY caseIgnoreMatch "
355 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
357 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
358 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
359 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
360 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
361 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
362 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
363 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
364 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
365 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
366 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
367 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
368 "DESC 'The backend type for a database instance' "
369 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
370 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
371 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
372 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
373 { "disabled", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_DISABLED,
374 &config_generic, "( OLcfgDbAt:0.21 NAME 'olcDisabled' "
375 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
376 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
377 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
378 "EQUALITY caseIgnoreMatch "
379 "SYNTAX OMsDirectoryString )", NULL, NULL },
380 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
381 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
382 "DESC 'OpenLDAP DIT content rules' "
383 "EQUALITY caseIgnoreMatch "
384 "SUBSTR caseIgnoreSubstringsMatch "
385 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
387 { "extra_attrs", "attrlist", 2, 2, 0, ARG_DB|ARG_MAGIC,
388 &config_extra_attrs, "( OLcfgDbAt:0.20 NAME 'olcExtraAttrs' "
389 "EQUALITY caseIgnoreMatch "
390 "SYNTAX OMsDirectoryString )", NULL, NULL },
391 { "gentlehup", "on|off", 2, 2, 0,
393 ARG_ON_OFF, &global_gentlehup,
397 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
398 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
399 { "hidden", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_HIDDEN,
400 &config_generic, "( OLcfgDbAt:0.17 NAME 'olcHidden' "
401 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
402 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
403 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
404 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
405 { "include", "file", 2, 2, 0, ARG_MAGIC,
406 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
407 "SUP labeledURI )", NULL, NULL },
408 { "index_hash64", "on|off", 2, 2, 0, ARG_ON_OFF|ARG_MAGIC|CFG_IX_HASH64,
409 &config_generic, "( OLcfgGlAt:94 NAME 'olcIndexHash64' "
410 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
411 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
412 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
413 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
414 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
415 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
416 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
417 { "index_substr_any_len", "len", 2, 2, 0, ARG_UINT|ARG_NONZERO,
418 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
419 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
420 { "index_substr_any_step", "step", 2, 2, 0, ARG_UINT|ARG_NONZERO,
421 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
422 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
423 { "index_intlen", "len", 2, 2, 0, ARG_UINT|ARG_MAGIC|CFG_IX_INTLEN,
424 &config_generic, "( OLcfgGlAt:84 NAME 'olcIndexIntLen' "
425 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
426 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
427 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
428 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
429 { "ldapsyntax", "syntax", 2, 0, 0,
430 ARG_PAREN|ARG_MAGIC|CFG_SYNTAX,
431 &config_generic, "( OLcfgGlAt:85 NAME 'olcLdapSyntaxes' "
432 "DESC 'OpenLDAP ldapSyntax' "
433 "EQUALITY caseIgnoreMatch "
434 "SUBSTR caseIgnoreSubstringsMatch "
435 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
437 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
438 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
439 "EQUALITY caseIgnoreMatch "
440 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
441 { "listener-threads", "count", 2, 0, 0,
445 ARG_UINT|ARG_MAGIC|CFG_LTHREADS, &config_generic,
447 "( OLcfgGlAt:93 NAME 'olcListenerThreads' "
448 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
449 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
450 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
451 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
452 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
453 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
454 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
455 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
456 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
457 "EQUALITY caseIgnoreMatch "
458 "SYNTAX OMsDirectoryString )", NULL, NULL },
459 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
460 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
461 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
462 { "mirrormode", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_MIRRORMODE,
463 &config_generic, "( OLcfgDbAt:0.16 NAME 'olcMirrorMode' "
464 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
465 { "moduleload", "file", 2, 0, 0,
467 ARG_MAGIC|CFG_MODLOAD|ARG_NO_DELETE, &config_generic,
471 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
472 "EQUALITY caseIgnoreMatch "
473 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
474 { "modulepath", "path", 2, 2, 0,
476 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
480 "( OLcfgGlAt:31 NAME 'olcModulePath' "
481 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
482 { "monitoring", "TRUE|FALSE", 2, 2, 0,
483 ARG_MAGIC|CFG_MONITORING|ARG_DB|ARG_ON_OFF, &config_generic,
484 "( OLcfgDbAt:0.18 NAME 'olcMonitoring' "
485 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
486 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
487 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
488 "DESC 'OpenLDAP object classes' "
489 "EQUALITY caseIgnoreMatch "
490 "SUBSTR caseIgnoreSubstringsMatch "
491 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
493 { "objectidentifier", "name> <oid", 3, 3, 0, ARG_MAGIC|CFG_OID,
494 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
495 "EQUALITY caseIgnoreMatch "
496 "SUBSTR caseIgnoreSubstringsMatch "
497 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
498 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
499 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
500 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
501 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
502 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
503 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
504 { "password-hash", "hash", 2, 0, 0, ARG_MAGIC,
505 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
506 "EQUALITY caseIgnoreMatch "
507 "SYNTAX OMsDirectoryString )", NULL, NULL },
508 { "pidfile", "file", 2, 2, 0, ARG_STRING,
509 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
510 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
511 { "plugin", NULL, 0, 0, 0,
513 ARG_MAGIC|CFG_PLUGIN, &config_generic,
517 "( OLcfgGlAt:38 NAME 'olcPlugin' "
518 "EQUALITY caseIgnoreMatch "
519 "SYNTAX OMsDirectoryString )", NULL, NULL },
520 { "pluginlog", "filename", 2, 2, 0,
522 ARG_STRING, &slapi_log_file,
526 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
527 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
528 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
529 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
530 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
531 { "referral", "url", 2, 2, 0, ARG_MAGIC,
532 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
533 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
534 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
535 &config_obsolete, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
536 "EQUALITY caseIgnoreMatch "
537 "SUP labeledURI X-ORDERED 'VALUES' )", NULL, NULL },
538 { "replica-argsfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
539 &config_obsolete, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
540 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
541 { "replica-pidfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
542 &config_obsolete, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
543 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
544 { "replicationInterval", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
545 &config_obsolete, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
546 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
547 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC,
548 &config_obsolete, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
549 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
550 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
551 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
552 "EQUALITY caseIgnoreMatch "
553 "SYNTAX OMsDirectoryString )", NULL, NULL },
554 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
555 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
556 "EQUALITY caseIgnoreMatch "
557 "SYNTAX OMsDirectoryString )", NULL, NULL },
558 { "reverse-lookup", "on|off", 2, 2, 0,
559 #ifdef SLAPD_RLOOKUPS
560 ARG_ON_OFF, &use_reverse_lookup,
564 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
565 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
566 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
567 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
568 "EQUALITY distinguishedNameMatch "
569 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
570 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
571 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
572 "EQUALITY caseIgnoreMatch "
573 "SYNTAX OMsDirectoryString )", NULL, NULL },
574 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
575 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
576 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
577 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
578 &config_generic, NULL, NULL, NULL },
579 { "sasl-auxprops", NULL, 2, 0, 0,
580 #ifdef HAVE_CYRUS_SASL
581 ARG_STRING|ARG_UNIQUE, &slap_sasl_auxprops,
585 "( OLcfgGlAt:89 NAME 'olcSaslAuxprops' "
586 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
587 { "sasl-auxprops-dontusecopy", NULL, 2, 0, 0,
588 #if defined(HAVE_CYRUS_SASL) && defined(SLAP_AUXPROP_DONTUSECOPY)
589 ARG_MAGIC|CFG_AZDUC, &config_generic,
593 "( OLcfgGlAt:91 NAME 'olcSaslAuxpropsDontUseCopy' "
594 "EQUALITY caseIgnoreMatch "
595 "SYNTAX OMsDirectoryString )", NULL, NULL },
596 { "sasl-auxprops-dontusecopy-ignore", "true|FALSE", 2, 0, 0,
597 #if defined(HAVE_CYRUS_SASL) && defined(SLAP_AUXPROP_DONTUSECOPY)
598 ARG_ON_OFF|CFG_AZDUC_IGNORE, &slap_dontUseCopy_ignore,
602 "( OLcfgGlAt:92 NAME 'olcSaslAuxpropsDontUseCopyIgnore' "
603 "EQUALITY booleanMatch "
604 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
605 { "sasl-host", "host", 2, 2, 0,
606 #ifdef HAVE_CYRUS_SASL
607 ARG_STRING|ARG_UNIQUE, &sasl_host,
611 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
612 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
613 { "sasl-realm", "realm", 2, 2, 0,
614 #ifdef HAVE_CYRUS_SASL
615 ARG_STRING|ARG_UNIQUE, &global_realm,
619 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
620 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
621 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
622 &config_generic, NULL, NULL, NULL },
623 { "sasl-secprops", "properties", 2, 2, 0,
624 #ifdef HAVE_CYRUS_SASL
625 ARG_MAGIC|CFG_SASLSECP, &config_generic,
629 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
630 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
631 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
632 &config_generic, NULL, NULL, NULL },
633 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
634 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
635 "EQUALITY distinguishedNameMatch "
636 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
637 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
638 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
639 "EQUALITY caseIgnoreMatch "
640 "SYNTAX OMsDirectoryString )", NULL, NULL },
641 { "serverID", "number> <[URI]", 2, 3, 0, ARG_MAGIC|CFG_SERVERID,
642 &config_generic, "( OLcfgGlAt:81 NAME 'olcServerID' "
643 "EQUALITY caseIgnoreMatch "
644 "SYNTAX OMsDirectoryString )", NULL, NULL },
645 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
646 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
647 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
648 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
649 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
650 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
651 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
652 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
653 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
654 { "sortvals", "attr", 2, 0, 0, ARG_MAGIC|CFG_SORTVALS,
655 &config_generic, "( OLcfgGlAt:83 NAME 'olcSortVals' "
656 "DESC 'Attributes whose values will always be sorted' "
657 "EQUALITY caseIgnoreMatch "
658 "SYNTAX OMsDirectoryString )", NULL, NULL },
659 { "subordinate", "[advertise]", 1, 2, 0, ARG_DB|ARG_MAGIC,
660 &config_subordinate, "( OLcfgDbAt:0.15 NAME 'olcSubordinate' "
661 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
662 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
663 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
664 "EQUALITY distinguishedNameMatch "
665 "SYNTAX OMsDN )", NULL, NULL },
666 { "sync_use_subentry", NULL, 0, 0, 0, ARG_ON_OFF|ARG_DB|ARG_MAGIC|CFG_SYNC_SUBENTRY,
667 &config_generic, "( OLcfgDbAt:0.19 NAME 'olcSyncUseSubentry' "
668 "DESC 'Store sync context in a subentry' "
669 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
670 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
671 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
672 "EQUALITY caseIgnoreMatch "
673 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
674 { "tcp-buffer", "[listener=<listener>] [{read|write}=]size", 0, 0, 0,
675 #ifndef LDAP_TCP_BUFFER
677 #else /* LDAP_TCP_BUFFER */
678 ARG_MAGIC, &config_tcp_buffer,
679 #endif /* LDAP_TCP_BUFFER */
680 "( OLcfgGlAt:90 NAME 'olcTCPBuffer' "
681 "DESC 'Custom TCP buffer size' "
682 "SYNTAX OMsDirectoryString )", NULL, NULL },
683 { "threads", "count", 2, 2, 0,
687 ARG_INT|ARG_MAGIC|CFG_THREADS, &config_generic,
689 "( OLcfgGlAt:66 NAME 'olcThreads' "
690 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
691 { "threadqueues", "count", 2, 2, 0,
695 ARG_INT|ARG_MAGIC|CFG_THREADQS, &config_generic,
697 "( OLcfgGlAt:95 NAME 'olcThreadQueues' "
698 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
699 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
700 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
701 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
702 { "TLSCACertificate", NULL, 2, 2, 0,
704 CFG_TLS_CACERT|ARG_BINARY|ARG_MAGIC, &config_tls_option,
708 "( OLcfgGlAt:97 NAME 'olcTLSCACertificate' "
709 "DESC 'X.509 certificate, must use ;binary' "
710 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.8 SINGLE-VALUE )", NULL, NULL },
711 { "TLSCACertificateFile", NULL, 2, 2, 0,
713 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
717 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
718 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
719 { "TLSCACertificatePath", NULL, 2, 2, 0,
721 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
725 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
726 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
727 { "TLSCertificate", NULL, 2, 2, 0,
729 CFG_TLS_CERT|ARG_BINARY|ARG_MAGIC, &config_tls_option,
733 "( OLcfgGlAt:98 NAME 'olcTLSCertificate' "
734 "DESC 'X.509 certificate, must use ;binary' "
735 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.8 SINGLE-VALUE )", NULL, NULL },
736 { "TLSCertificateFile", NULL, 2, 2, 0,
738 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
742 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
743 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
744 { "TLSCertificateKey", NULL, 2, 2, 0,
746 CFG_TLS_KEY|ARG_BINARY|ARG_MAGIC, &config_tls_option,
750 "( OLcfgGlAt:99 NAME 'olcTLSCertificateKey' "
751 "DESC 'X.509 privateKey, must use ;binary' "
752 "SYNTAX 1.3.6.1.4.1.4203.666.2.13 SINGLE-VALUE )", NULL, NULL },
753 { "TLSCertificateKeyFile", NULL, 2, 2, 0,
755 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
759 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
760 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
761 { "TLSCipherSuite", NULL, 2, 2, 0,
763 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
767 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
768 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
769 { "TLSCRLCheck", NULL, 2, 2, 0,
770 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
771 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
775 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
776 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
777 { "TLSCRLFile", NULL, 2, 2, 0,
778 #if defined(HAVE_GNUTLS)
779 CFG_TLS_CRL_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
783 "( OLcfgGlAt:82 NAME 'olcTLSCRLFile' "
784 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
785 { "TLSRandFile", NULL, 2, 2, 0,
787 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
791 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
792 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
793 { "TLSVerifyClient", NULL, 2, 2, 0,
795 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
799 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
800 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
801 { "TLSDHParamFile", NULL, 2, 2, 0,
803 CFG_TLS_DH_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
807 "( OLcfgGlAt:77 NAME 'olcTLSDHParamFile' "
808 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
809 { "TLSECName", NULL, 2, 2, 0,
811 CFG_TLS_ECNAME|ARG_STRING|ARG_MAGIC, &config_tls_option,
815 "( OLcfgGlAt:96 NAME 'olcTLSECName' "
816 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
817 { "TLSProtocolMin", NULL, 2, 2, 0,
819 CFG_TLS_PROTOCOL_MIN|ARG_STRING|ARG_MAGIC, &config_tls_config,
823 "( OLcfgGlAt:87 NAME 'olcTLSProtocolMin' "
824 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
825 { "tool-threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_TTHREADS,
826 &config_generic, "( OLcfgGlAt:80 NAME 'olcToolThreads' "
827 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
828 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
829 NULL, NULL, NULL, NULL },
830 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
831 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
832 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
833 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
834 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
835 "EQUALITY caseIgnoreMatch "
836 "SUP labeledURI )", NULL, NULL },
837 { "writetimeout", "timeout", 2, 2, 0, ARG_INT,
838 &global_writetimeout, "( OLcfgGlAt:88 NAME 'olcWriteTimeout' "
839 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
840 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
841 NULL, NULL, NULL, NULL }
844 /* Need to no-op this keyword for dynamic config */
845 ConfigTable olcDatabaseDummy[] = {
846 { "", "", 0, 0, 0, ARG_IGNORED,
847 NULL, "( OLcfgGlAt:13 NAME 'olcDatabase' "
848 "DESC 'The backend type for a database instance' "
849 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
850 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
853 /* Routines to check if a child can be added to this type */
854 static ConfigLDAPadd cfAddSchema, cfAddInclude, cfAddDatabase,
855 cfAddBackend, cfAddModule, cfAddOverlay;
857 /* NOTE: be careful when defining array members
858 * that can be conditionally compiled */
859 #define CFOC_GLOBAL cf_ocs[1]
860 #define CFOC_SCHEMA cf_ocs[2]
861 #define CFOC_BACKEND cf_ocs[3]
862 #define CFOC_DATABASE cf_ocs[4]
863 #define CFOC_OVERLAY cf_ocs[5]
864 #define CFOC_INCLUDE cf_ocs[6]
865 #define CFOC_FRONTEND cf_ocs[7]
867 #define CFOC_MODULE cf_ocs[8]
868 #endif /* SLAPD_MODULES */
870 static ConfigOCs cf_ocs[] = {
873 "DESC 'OpenLDAP configuration object' "
874 "ABSTRACT SUP top )", Cft_Abstract, NULL },
877 "DESC 'OpenLDAP Global configuration options' "
878 "SUP olcConfig STRUCTURAL "
879 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
880 "olcAttributeOptions $ olcAuthIDRewrite $ "
881 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
882 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
883 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
884 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
885 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcIndexHash64 $ "
887 "olcListenerThreads $ olcLocalSSF $ olcLogFile $ olcLogLevel $ "
888 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
889 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
890 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
892 "olcSaslAuxprops $ olcSaslAuxpropsDontUseCopy $ olcSaslAuxpropsDontUseCopyIgnore $ "
893 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
894 "olcSecurity $ olcServerID $ olcSizeLimit $ "
895 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ "
897 "olcThreads $ olcThreadQueues $ "
898 "olcTimeLimit $ olcTLSCACertificateFile $ "
899 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
900 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
901 "olcTLSCACertificate $ olcTLSCertificate $ olcTLSCertificateKey $ "
902 "olcTLSRandFile $ olcTLSVerifyClient $ olcTLSDHParamFile $ olcTLSECName $ "
903 "olcTLSCRLFile $ olcTLSProtocolMin $ olcToolThreads $ olcWriteTimeout $ "
904 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
905 "olcDitContentRules $ olcLdapSyntaxes ) )", Cft_Global },
907 "NAME 'olcSchemaConfig' "
908 "DESC 'OpenLDAP schema object' "
909 "SUP olcConfig STRUCTURAL "
910 "MAY ( cn $ olcObjectIdentifier $ olcLdapSyntaxes $ "
911 "olcAttributeTypes $ olcObjectClasses $ olcDitContentRules ) )",
912 Cft_Schema, NULL, cfAddSchema },
914 "NAME 'olcBackendConfig' "
915 "DESC 'OpenLDAP Backend-specific options' "
916 "SUP olcConfig STRUCTURAL "
917 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
919 "NAME 'olcDatabaseConfig' "
920 "DESC 'OpenLDAP Database-specific options' "
921 "SUP olcConfig STRUCTURAL "
923 "MAY ( olcDisabled $ olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
924 "olcAddContentAcl $ olcLastMod $ olcLimits $ "
925 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
926 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
927 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
928 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncUseSubentry $ olcSyncrepl $ "
929 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef $ olcMirrorMode $ "
930 "olcMonitoring $ olcExtraAttrs ) )",
931 Cft_Database, NULL, cfAddDatabase },
933 "NAME 'olcOverlayConfig' "
934 "DESC 'OpenLDAP Overlay-specific options' "
935 "SUP olcConfig STRUCTURAL "
937 "MAY olcDisabled )", Cft_Overlay, NULL, cfAddOverlay },
939 "NAME 'olcIncludeFile' "
940 "DESC 'OpenLDAP configuration include file' "
941 "SUP olcConfig STRUCTURAL "
943 "MAY ( cn $ olcRootDSE ) )",
944 /* Used to be Cft_Include, that def has been removed */
945 Cft_Abstract, NULL, cfAddInclude },
946 /* This should be STRUCTURAL like all the other database classes, but
947 * that would mean inheriting all of the olcDatabaseConfig attributes,
948 * which causes them to be merged twice in config_build_entry.
951 "NAME 'olcFrontendConfig' "
952 "DESC 'OpenLDAP frontend configuration' "
954 "MAY ( olcDefaultSearchBase $ olcPasswordHash $ olcSortVals ) )",
955 Cft_Database, NULL, NULL },
958 "NAME 'olcModuleList' "
959 "DESC 'OpenLDAP dynamic module info' "
960 "SUP olcConfig STRUCTURAL "
961 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
962 Cft_Module, NULL, cfAddModule },
967 typedef struct ServerID {
968 struct ServerID *si_next;
969 struct berval si_url;
973 static ServerID *sid_list;
974 static ServerID *sid_set;
976 typedef struct voidList {
977 struct voidList *vl_next;
981 typedef struct ADlist {
982 struct ADlist *al_next;
983 AttributeDescription *al_desc;
986 static ADlist *sortVals;
989 config_generic(ConfigArgs *c) {
992 if ( c->op == SLAP_CONFIG_EMIT ) {
996 c->value_int = ldap_pvt_thread_get_concurrency();
999 c->value_int = connection_pool_max;
1002 c->value_int = connection_pool_queues;
1005 c->value_int = slap_tool_thread_max;
1008 c->value_uint = slapd_daemon_threads;
1012 c->value_string = ch_strdup( passwd_salt );
1017 if ( c->be->be_limits ) {
1021 for ( i=0; c->be->be_limits[i]; i++ ) {
1022 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
1023 if ( bv.bv_len >= sizeof( buf ) ) {
1024 ber_bvarray_free_x( c->rvalue_vals, NULL );
1025 c->rvalue_vals = NULL;
1029 bv.bv_val = buf + bv.bv_len;
1030 limits_unparse( c->be->be_limits[i], &bv,
1031 sizeof( buf ) - ( bv.bv_val - buf ) );
1032 bv.bv_len += bv.bv_val - buf;
1034 value_add_one( &c->rvalue_vals, &bv );
1037 if ( !c->rvalue_vals ) rc = 1;
1040 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_READONLY);
1043 c->value_string = ch_strdup( slap_sasl_getpolicy());
1046 slap_sasl_regexp_unparse( &c->rvalue_vals );
1047 if ( !c->rvalue_vals ) rc = 1;
1049 #ifdef HAVE_CYRUS_SASL
1050 #ifdef SLAP_AUXPROP_DONTUSECOPY
1052 static int duc_done = 0;
1054 /* take the opportunity to initialize with known values */
1056 struct berval duc[] = { BER_BVC("cmusaslsecretOTP"), BER_BVNULL };
1059 for ( i = 0; !BER_BVISNULL( &duc[ i ] ); i++ ) {
1060 const char *text = NULL;
1061 AttributeDescription *ad = NULL;
1063 if ( slap_bv2ad( &duc[ i ], &ad, &text ) == LDAP_SUCCESS ) {
1065 if ( slap_dontUseCopy_propnames ) {
1068 for ( j = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ j ] ); j++ ) {
1069 if ( bvmatch( &slap_dontUseCopy_propnames[ j ], &ad->ad_cname ) ) {
1076 value_add_one( &slap_dontUseCopy_propnames, &ad->ad_cname );
1084 if ( slap_dontUseCopy_propnames != NULL ) {
1085 ber_bvarray_dup_x( &c->rvalue_vals, slap_dontUseCopy_propnames, NULL );
1090 #endif /* SLAP_AUXPROP_DONTUSECOPY */
1091 case CFG_SASLSECP: {
1092 struct berval bv = BER_BVNULL;
1093 slap_sasl_secprops_unparse( &bv );
1094 if ( !BER_BVISNULL( &bv )) {
1095 ber_bvarray_add( &c->rvalue_vals, &bv );
1103 c->value_int = c->be->be_max_deref_depth;
1108 if ( c->bi->bi_flags & SLAPO_BFLAG_DISABLED ) {
1115 if ( SLAP_DBDISABLED( c->be )) {
1123 if ( SLAP_DBHIDDEN( c->be )) {
1130 ConfigFile *cf = c->ca_private;
1132 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1133 else if ( cf->c_om_head )
1134 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
1136 if ( !c->rvalue_vals )
1141 ad_unparse_options( &c->rvalue_vals );
1144 ConfigFile *cf = c->ca_private;
1146 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1147 else if ( cf->c_oc_head )
1148 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
1150 if ( !c->rvalue_vals )
1155 ConfigFile *cf = c->ca_private;
1157 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1158 else if ( cf->c_at_head )
1159 at_unparse( &c->rvalue_vals, cf->c_at_head,
1161 if ( !c->rvalue_vals )
1166 ConfigFile *cf = c->ca_private;
1168 syn_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1169 else if ( cf->c_syn_head )
1170 syn_unparse( &c->rvalue_vals, cf->c_syn_head,
1171 cf->c_syn_tail, 0 );
1172 if ( !c->rvalue_vals )
1177 ConfigFile *cf = c->ca_private;
1179 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1180 else if ( cf->c_cr_head )
1181 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
1183 if ( !c->rvalue_vals )
1190 char *src, *dst, ibuf[11];
1191 struct berval bv, abv;
1192 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
1193 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1194 if ( abv.bv_len >= sizeof( ibuf ) ) {
1195 ber_bvarray_free_x( c->rvalue_vals, NULL );
1196 c->rvalue_vals = NULL;
1200 acl_unparse( a, &bv );
1201 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
1202 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
1203 /* Turn TAB / EOL into plain space */
1204 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
1205 if (isspace((unsigned char)*src)) *dst++ = ' ';
1209 if (dst[-1] == ' ') {
1213 abv.bv_len = dst - abv.bv_val;
1214 ber_bvarray_add( &c->rvalue_vals, &abv );
1220 c->value_int = (SLAP_DBACL_ADD(c->be) != 0);
1223 ConfigFile *cf = c->ca_private;
1224 if ( cf->c_dseFiles ) {
1225 value_add( &c->rvalue_vals, cf->c_dseFiles );
1236 for ( si = sid_list; si; si=si->si_next ) {
1237 assert( si->si_num >= 0 && si->si_num <= SLAP_SYNC_SID_MAX );
1238 if ( !BER_BVISEMPTY( &si->si_url )) {
1239 bv.bv_len = si->si_url.bv_len + 6;
1240 bv.bv_val = ch_malloc( bv.bv_len );
1241 bv.bv_len = sprintf( bv.bv_val, "%d %s", si->si_num,
1242 si->si_url.bv_val );
1243 ber_bvarray_add( &c->rvalue_vals, &bv );
1247 bv.bv_len = sprintf( buf, "%d", si->si_num );
1248 value_add_one( &c->rvalue_vals, &bv );
1257 c->value_string = ch_strdup( logfileName );
1262 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1264 case CFG_SYNC_SUBENTRY:
1265 c->value_int = (SLAP_SYNC_SUBENTRY(c->be) != 0);
1267 case CFG_MIRRORMODE:
1268 if ( SLAP_SHADOW(c->be))
1269 c->value_int = (SLAP_MULTIMASTER(c->be) != 0);
1273 case CFG_MONITORING:
1274 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
1276 case CFG_SSTR_IF_MAX:
1277 c->value_uint = index_substr_if_maxlen;
1279 case CFG_SSTR_IF_MIN:
1280 c->value_uint = index_substr_if_minlen;
1283 c->value_int = slap_hash64( -1 );
1286 c->value_int = index_intlen;
1288 case CFG_SORTVALS: {
1291 for ( sv = sortVals; sv; sv = sv->al_next ) {
1292 value_add_one( &c->rvalue_vals, &sv->al_desc->ad_cname );
1296 #ifdef SLAPD_MODULES
1298 ModPaths *mp = c->ca_private;
1301 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
1304 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
1305 SLAP_X_ORDERED_FMT "%s", i,
1306 mp->mp_loads[i].bv_val );
1307 if ( bv.bv_len >= sizeof( c->log ) ) {
1308 ber_bvarray_free_x( c->rvalue_vals, NULL );
1309 c->rvalue_vals = NULL;
1312 value_add_one( &c->rvalue_vals, &bv );
1316 rc = c->rvalue_vals ? 0 : 1;
1320 ModPaths *mp = c->ca_private;
1321 if ( !BER_BVISNULL( &mp->mp_path ))
1322 value_add_one( &c->rvalue_vals, &mp->mp_path );
1324 rc = c->rvalue_vals ? 0 : 1;
1330 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1331 if ( !c->rvalue_vals ) rc = 1;
1334 #ifdef SLAP_AUTH_REWRITE
1336 if ( authz_rewrites ) {
1337 struct berval bv, idx;
1342 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1343 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1344 if ( idx.bv_len >= sizeof( ibuf ) ) {
1345 ber_bvarray_free_x( c->rvalue_vals, NULL );
1346 c->rvalue_vals = NULL;
1349 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1350 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1351 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1352 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1353 authz_rewrites[i].bv_val,
1354 authz_rewrites[i].bv_len + 1 );
1355 ber_bvarray_add( &c->rvalue_vals, &bv );
1358 if ( !c->rvalue_vals ) rc = 1;
1365 } else if ( c->op == LDAP_MOD_DELETE ) {
1368 /* single-valued attrs, no-ops */
1378 case CFG_MONITORING:
1380 case CFG_SSTR_IF_MAX:
1381 case CFG_SSTR_IF_MIN:
1383 case CFG_SYNC_SUBENTRY:
1386 /* no-ops, requires slapd restart */
1391 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1394 case CFG_MIRRORMODE:
1395 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MULTI_SHADOW;
1396 if(SLAP_SHADOW(c->be))
1397 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1400 #if defined(HAVE_CYRUS_SASL) && defined(SLAP_AUXPROP_DONTUSECOPY)
1402 if ( c->valx < 0 ) {
1403 if ( slap_dontUseCopy_propnames != NULL ) {
1404 ber_bvarray_free( slap_dontUseCopy_propnames );
1405 slap_dontUseCopy_propnames = NULL;
1411 if ( slap_dontUseCopy_propnames == NULL ) {
1416 for ( i = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ i ] ) && i < c->valx; i++ );
1417 if ( i < c->valx ) {
1421 ber_memfree( slap_dontUseCopy_propnames[ i ].bv_val );
1422 for ( ; !BER_BVISNULL( &slap_dontUseCopy_propnames[ i + 1 ] ); i++ ) {
1423 slap_dontUseCopy_propnames[ i ] = slap_dontUseCopy_propnames[ i + 1 ];
1425 BER_BVZERO( &slap_dontUseCopy_propnames[ i ] );
1428 #endif /* SLAP_AUXPROP_DONTUSECOPY */
1430 ch_free( passwd_salt );
1435 ch_free( logfileName );
1443 case CFG_SERVERID: {
1444 ServerID *si, **sip;
1446 for ( i=0, si = sid_list, sip = &sid_list;
1447 si; si = *sip, i++ ) {
1448 if ( c->valx == -1 || i == c->valx ) {
1450 if ( sid_set == si )
1462 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1467 c->bi->bi_flags &= ~SLAP_DBFLAG_DISABLED;
1468 if ( c->bi->bi_db_open ) {
1469 BackendInfo *bi_orig = c->be->bd_info;
1470 c->be->bd_info = c->bi;
1471 rc = c->bi->bi_db_open( c->be, &c->reply );
1472 c->be->bd_info = bi_orig;
1475 c->be->be_flags &= ~SLAP_DBFLAG_DISABLED;
1476 rc = backend_startup_one( c->be, &c->reply );
1485 index_intlen = SLAP_INDEX_INTLEN_DEFAULT;
1486 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1487 SLAP_INDEX_INTLEN_DEFAULT );
1491 if ( c->valx < 0 ) {
1492 acl_destroy( c->be->be_acl );
1493 c->be->be_acl = NULL;
1496 AccessControl **prev, *a;
1498 for (i=0, prev = &c->be->be_acl; i < c->valx;
1501 prev = &a->acl_next;
1504 *prev = a->acl_next;
1507 if ( SLAP_CONFIG( c->be ) && !c->be->be_acl ) {
1508 Debug( LDAP_DEBUG_CONFIG, "config_generic (CFG_ACL): "
1509 "Last explicit ACL for back-config removed. "
1510 "Using hardcoded default\n", 0, 0, 0 );
1511 c->be->be_acl = defacl_parsed;
1517 /* Can be NULL when undoing a failed add */
1518 if ( c->ca_entry ) {
1519 ce = c->ca_entry->e_private;
1520 /* can't modify the hardcoded schema */
1521 if ( ce->ce_parent->ce_type == Cft_Global )
1525 cfn = c->ca_private;
1526 if ( c->valx < 0 ) {
1529 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1531 if ( oc == cfn->c_oc_tail )
1534 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1536 ObjectClass *oc, *prev = NULL;
1538 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1543 if ( cfn->c_oc_tail == oc ) {
1544 cfn->c_oc_tail = prev;
1546 if ( cfn->c_oc_head == oc ) {
1548 cfn->c_oc_head = oc;
1555 /* Can be NULL when undoing a failed add */
1556 if ( c->ca_entry ) {
1557 ce = c->ca_entry->e_private;
1558 /* can't modify the hardcoded schema */
1559 if ( ce->ce_parent->ce_type == Cft_Global )
1563 cfn = c->ca_private;
1564 if ( c->valx < 0 ) {
1567 for( at = cfn->c_at_head; at; at_next( &at )) {
1569 if ( at == cfn->c_at_tail )
1572 cfn->c_at_head = cfn->c_at_tail = NULL;
1574 AttributeType *at, *prev = NULL;
1576 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1581 if ( cfn->c_at_tail == at ) {
1582 cfn->c_at_tail = prev;
1584 if ( cfn->c_at_head == at ) {
1586 cfn->c_at_head = at;
1593 /* Can be NULL when undoing a failed add */
1594 if ( c->ca_entry ) {
1595 ce = c->ca_entry->e_private;
1596 /* can't modify the hardcoded schema */
1597 if ( ce->ce_parent->ce_type == Cft_Global )
1601 cfn = c->ca_private;
1602 if ( c->valx < 0 ) {
1605 for( syn = cfn->c_syn_head; syn; syn_next( &syn )) {
1607 if ( syn == cfn->c_syn_tail )
1610 cfn->c_syn_head = cfn->c_syn_tail = NULL;
1612 Syntax *syn, *prev = NULL;
1614 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++) {
1619 if ( cfn->c_syn_tail == syn ) {
1620 cfn->c_syn_tail = prev;
1622 if ( cfn->c_syn_head == syn ) {
1624 cfn->c_syn_head = syn;
1629 if ( c->valx < 0 ) {
1631 for ( sv = sortVals; sv; sv = sortVals ) {
1632 sortVals = sv->al_next;
1633 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1640 for ( prev = &sortVals, sv = sortVals; i < c->valx; i++ ) {
1641 prev = &sv->al_next;
1644 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1645 *prev = sv->al_next;
1651 /* FIXME: there is no limits_free function */
1652 if ( c->valx < 0 ) {
1653 limits_destroy( c->be->be_limits );
1654 c->be->be_limits = NULL;
1659 if ( c->be->be_limits ) {
1660 for ( num = 0; c->be->be_limits[ num ]; num++ )
1664 if ( c->valx >= num ) {
1669 limits_destroy( c->be->be_limits );
1670 c->be->be_limits = NULL;
1673 limits_free_one( c->be->be_limits[ c->valx ] );
1675 for ( cnt = c->valx; cnt < num; cnt++ ) {
1676 c->be->be_limits[ cnt ] = c->be->be_limits[ cnt + 1 ];
1683 /* FIXME: there is no ad_option_free function */
1685 /* FIXME: there is no way to remove attributes added by
1699 if(!(c->bi = backend_info(c->argv[1]))) {
1700 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1701 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1702 c->log, c->cr_msg, c->argv[1] );
1709 /* NOTE: config is always the first backend!
1711 if ( !strcasecmp( c->argv[1], "config" )) {
1712 c->be = LDAP_STAILQ_FIRST(&backendDB);
1713 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1716 c->be = backend_db_init(c->argv[1], NULL, c->valx, &c->reply);
1718 if ( c->cr_msg[0] == 0 )
1719 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1720 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n", c->log, c->cr_msg, c->argv[1] );
1727 ldap_pvt_thread_set_concurrency(c->value_int);
1731 if ( c->value_int < 2 ) {
1732 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1733 "threads=%d smaller than minimum value 2",
1735 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1736 c->log, c->cr_msg, 0 );
1739 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1740 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1741 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1742 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1743 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1744 c->log, c->cr_msg, 0 );
1746 if ( slapMode & SLAP_SERVER_MODE )
1747 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1748 connection_pool_max = c->value_int; /* save for reference */
1752 if ( c->value_int < 1 ) {
1753 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1754 "threadqueuess=%d smaller than minimum value 1",
1756 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1757 c->log, c->cr_msg, 0 );
1760 if ( slapMode & SLAP_SERVER_MODE )
1761 ldap_pvt_thread_pool_queues(&connection_pool, c->value_int);
1762 connection_pool_queues = c->value_int; /* save for reference */
1766 if ( slapMode & SLAP_TOOL_MODE )
1767 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1768 slap_tool_thread_max = c->value_int; /* save for reference */
1773 /* use a power of two */
1774 while (c->value_uint > 1) {
1775 c->value_uint >>= 1;
1779 slapd_daemon_mask = mask;
1780 slapd_daemon_threads = mask+1;
1785 if ( passwd_salt ) ch_free( passwd_salt );
1786 passwd_salt = c->value_string;
1787 lutil_salt_format(passwd_salt);
1791 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1797 c->be->be_restrictops |= SLAP_RESTRICT_READONLY;
1799 c->be->be_restrictops &= ~SLAP_RESTRICT_READONLY;
1803 ch_free(c->value_string);
1804 if (slap_sasl_setpolicy( c->argv[1] )) {
1805 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
1806 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1807 c->log, c->cr_msg, c->argv[1] );
1813 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1817 #ifdef HAVE_CYRUS_SASL
1818 #ifdef SLAP_AUXPROP_DONTUSECOPY
1822 for ( arg = 1; arg < c->argc; arg++ ) {
1823 int duplicate = 0, err;
1824 AttributeDescription *ad = NULL;
1825 const char *text = NULL;
1827 err = slap_str2ad( c->argv[ arg ], &ad, &text );
1828 if ( err != LDAP_SUCCESS ) {
1829 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s>: attr #%d (\"%s\") unknown (err=%d \"%s\"; ignored)",
1830 c->argv[0], arg, c->argv[ arg ], err, text );
1831 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1832 c->log, c->cr_msg, 0 );
1835 if ( slap_dontUseCopy_propnames != NULL ) {
1836 for ( cnt = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ cnt ] ); cnt++ ) {
1837 if ( bvmatch( &slap_dontUseCopy_propnames[ cnt ], &ad->ad_cname ) ) {
1845 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s>: attr #%d (\"%s\") already defined (ignored)",
1846 c->argv[0], arg, ad->ad_cname.bv_val);
1847 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1848 c->log, c->cr_msg, 0 );
1852 value_add_one( &slap_dontUseCopy_propnames, &ad->ad_cname );
1857 #endif /* SLAP_AUXPROP_DONTUSECOPY */
1861 char *txt = slap_sasl_secprops( c->argv[1] );
1863 snprintf( c->cr_msg, sizeof(c->cr_msg), "<%s> %s",
1865 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0 );
1873 c->be->be_max_deref_depth = c->value_int;
1879 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1880 cfn = c->ca_private;
1881 if(parse_oidm(c, 1, &om))
1883 if (!cfn->c_om_head) cfn->c_om_head = om;
1884 cfn->c_om_tail = om;
1889 ObjectClass *oc, *prev;
1891 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1892 cfn = c->ca_private;
1893 if ( c->valx < 0 ) {
1894 prev = cfn->c_oc_tail;
1897 /* If adding anything after the first, prev is easy */
1900 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
1902 if ( !oc_next( &oc ))
1906 /* If adding the first, and head exists, find its prev */
1907 if (cfn->c_oc_head) {
1908 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
1913 /* else prev is NULL, append to end of global list */
1915 if(parse_oc(c, &oc, prev)) return(1);
1916 if (!cfn->c_oc_head || !c->valx) cfn->c_oc_head = oc;
1917 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
1922 AttributeType *at, *prev;
1924 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1925 cfn = c->ca_private;
1926 if ( c->valx < 0 ) {
1927 prev = cfn->c_at_tail;
1930 /* If adding anything after the first, prev is easy */
1933 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
1935 if ( !at_next( &at ))
1939 /* If adding the first, and head exists, find its prev */
1940 if (cfn->c_at_head) {
1941 for ( at_start( &at ); at != cfn->c_at_head; ) {
1946 /* else prev is NULL, append to end of global list */
1948 if(parse_at(c, &at, prev)) return(1);
1949 if (!cfn->c_at_head || !c->valx) cfn->c_at_head = at;
1950 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
1957 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1958 cfn = c->ca_private;
1959 if ( c->valx < 0 ) {
1960 prev = cfn->c_syn_tail;
1963 /* If adding anything after the first, prev is easy */
1966 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++ ) {
1968 if ( !syn_next( &syn ))
1972 /* If adding the first, and head exists, find its prev */
1973 if (cfn->c_syn_head) {
1974 for ( syn_start( &syn ); syn != cfn->c_syn_head; ) {
1979 /* else prev is NULL, append to end of global list */
1981 if ( parse_syn( c, &syn, prev ) ) return(1);
1982 if ( !cfn->c_syn_head || !c->valx ) cfn->c_syn_head = syn;
1983 if ( cfn->c_syn_tail == prev ) cfn->c_syn_tail = syn;
1990 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1991 cfn = c->ca_private;
1992 if(parse_cr(c, &cr)) return(1);
1993 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1994 cfn->c_cr_tail = cr;
1999 ad_define_option(NULL, NULL, 0);
2000 for(i = 1; i < c->argc; i++)
2001 if(ad_define_option(c->argv[i], c->fname, c->lineno))
2006 if ( slap_hash64( c->value_int != 0 ))
2011 if ( c->value_int < SLAP_INDEX_INTLEN_DEFAULT )
2012 c->value_int = SLAP_INDEX_INTLEN_DEFAULT;
2013 else if ( c->value_int > 255 )
2015 index_intlen = c->value_int;
2016 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
2020 case CFG_SORTVALS: {
2021 ADlist *svnew = NULL, *svtail, *sv;
2023 for ( i = 1; i < c->argc; i++ ) {
2024 AttributeDescription *ad = NULL;
2028 rc = slap_str2ad( c->argv[i], &ad, &text );
2030 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown attribute type #%d",
2033 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2034 c->log, c->cr_msg, c->argv[i] );
2035 for ( sv = svnew; sv; sv = svnew ) {
2036 svnew = sv->al_next;
2041 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) ||
2042 ad->ad_type->sat_single_value ) {
2043 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> inappropriate attribute type #%d",
2045 goto sortval_reject;
2047 sv = ch_malloc( sizeof( ADlist ));
2052 svtail->al_next = sv;
2057 for ( sv = svnew; sv; sv = sv->al_next )
2058 sv->al_desc->ad_type->sat_flags |= SLAP_AT_SORTED_VAL;
2059 for ( sv = sortVals; sv && sv->al_next; sv = sv->al_next );
2061 sv->al_next = svnew;
2068 if ( SLAP_CONFIG( c->be ) && c->be->be_acl == defacl_parsed) {
2069 c->be->be_acl = NULL;
2071 /* Don't append to the global ACL if we're on a specific DB */
2073 if ( c->valx == -1 ) {
2076 for ( a=c->be->be_acl; a; a = a->acl_next )
2079 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
2080 if ( SLAP_CONFIG( c->be ) && !c->be->be_acl) {
2081 c->be->be_acl = defacl_parsed;
2089 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_ACL_ADD;
2091 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_ACL_ADD;
2095 if(root_dse_read_file(c->argv[1])) {
2096 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> could not read file", c->argv[0] );
2097 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2098 c->log, c->cr_msg, c->argv[1] );
2103 ber_str2bv( c->argv[1], 0, 1, &bv );
2104 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
2105 cfn = c->ca_private;
2106 ber_bvarray_add( &cfn->c_dseFiles, &bv );
2112 ServerID *si, **sip;
2115 if (( lutil_atoi( &num, c->argv[1] ) &&
2116 lutil_atoix( &num, c->argv[1], 16 )) ||
2117 num < 0 || num > SLAP_SYNC_SID_MAX )
2119 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2120 "<%s> illegal server ID", c->argv[0] );
2121 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2122 c->log, c->cr_msg, c->argv[1] );
2125 /* only one value allowed if no URL is given */
2126 if ( c->argc > 2 ) {
2129 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
2130 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2131 "<%s> only one server ID allowed now", c->argv[0] );
2132 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2133 c->log, c->cr_msg, c->argv[1] );
2137 if ( ldap_url_parse( c->argv[2], &lud )) {
2138 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2139 "<%s> invalid URL", c->argv[0] );
2140 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2141 c->log, c->cr_msg, c->argv[2] );
2144 len = strlen( c->argv[2] );
2145 si = ch_malloc( sizeof(ServerID) + len + 1 );
2146 si->si_url.bv_val = (char *)(si+1);
2147 si->si_url.bv_len = len;
2148 strcpy( si->si_url.bv_val, c->argv[2] );
2151 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2152 "<%s> unqualified server ID not allowed now", c->argv[0] );
2153 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2154 c->log, c->cr_msg, c->argv[1] );
2157 si = ch_malloc( sizeof(ServerID) );
2158 BER_BVZERO( &si->si_url );
2159 slap_serverID = num;
2160 Debug( LDAP_DEBUG_CONFIG,
2162 c->log, slap_serverID, 0 );
2167 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
2170 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
2171 Listener *l = config_check_my_url( c->argv[2], lud );
2174 ldap_free_urldesc( lud );
2175 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2176 "<%s> multiple server ID URLs matched, only one is allowed", c->argv[0] );
2177 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2178 c->log, c->cr_msg, c->argv[1] );
2181 slap_serverID = si->si_num;
2182 Debug( LDAP_DEBUG_CONFIG,
2183 "%s: SID=0x%03x (listener=%s)\n",
2184 c->log, slap_serverID,
2190 ldap_free_urldesc( lud );
2194 if ( logfileName ) ch_free( logfileName );
2195 logfileName = c->value_string;
2196 logfile = fopen(logfileName, "w");
2197 if(logfile) lutil_debug_file(logfile);
2201 if(SLAP_NOLASTMODCMD(c->be)) {
2202 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> not available for %s database",
2203 c->argv[0], c->be->bd_info->bi_type );
2204 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2205 c->log, c->cr_msg, 0 );
2209 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
2211 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
2214 case CFG_MIRRORMODE:
2215 if(c->value_int && !SLAP_SHADOW(c->be)) {
2216 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database is not a shadow",
2218 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2219 c->log, c->cr_msg, 0 );
2223 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
2224 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MULTI_SHADOW;
2226 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
2227 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MULTI_SHADOW;
2231 case CFG_MONITORING:
2233 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
2235 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
2241 if ( c->bi->bi_db_close ) {
2242 BackendInfo *bi_orig = c->be->bd_info;
2243 c->be->bd_info = c->bi;
2244 c->bi->bi_db_close( c->be, &c->reply );
2245 c->be->bd_info = bi_orig;
2247 c->bi->bi_flags |= SLAPO_BFLAG_DISABLED;
2249 c->bi->bi_flags &= ~SLAPO_BFLAG_DISABLED;
2253 backend_shutdown( c->be );
2254 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_DISABLED;
2256 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_DISABLED;
2263 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
2265 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
2268 case CFG_SYNC_SUBENTRY:
2270 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SYNC_SUBENTRY;
2272 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SYNC_SUBENTRY;
2275 case CFG_SSTR_IF_MAX:
2276 if (c->value_uint < index_substr_if_minlen) {
2277 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
2278 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
2279 c->log, c->cr_msg, c->value_int );
2282 index_substr_if_maxlen = c->value_uint;
2285 case CFG_SSTR_IF_MIN:
2286 if (c->value_uint > index_substr_if_maxlen) {
2287 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
2288 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
2289 c->log, c->cr_msg, c->value_int );
2292 index_substr_if_minlen = c->value_uint;
2295 #ifdef SLAPD_MODULES
2297 /* If we're just adding a module on an existing modpath,
2298 * make sure we've selected the current path.
2300 if ( c->op == LDAP_MOD_ADD && c->ca_private && modcur != c->ca_private ) {
2301 modcur = c->ca_private;
2302 /* This should never fail */
2303 if ( module_path( modcur->mp_path.bv_val )) {
2304 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> module path no longer valid",
2306 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2307 c->log, c->cr_msg, modcur->mp_path.bv_val );
2311 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
2313 /* Record this load on the current path */
2317 if ( c->op == SLAP_CONFIG_ADD ) {
2318 ptr = c->line + STRLENOF("moduleload");
2319 while (!isspace((unsigned char) *ptr)) ptr++;
2320 while (isspace((unsigned char) *ptr)) ptr++;
2324 ber_str2bv(ptr, 0, 1, &bv);
2325 ber_bvarray_add( &modcur->mp_loads, &bv );
2327 /* Check for any new hardcoded schema */
2328 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
2329 config_check_schema( NULL, &cfBackInfo );
2334 if(module_path(c->argv[1])) return(1);
2335 /* Record which path was used with each module */
2339 if (!modpaths.mp_loads) {
2342 mp = ch_malloc( sizeof( ModPaths ));
2343 modlast->mp_next = mp;
2345 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
2347 mp->mp_loads = NULL;
2358 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
2360 slapi_plugins_used++;
2364 #ifdef SLAP_AUTH_REWRITE
2370 if ( c->op == LDAP_MOD_ADD ) {
2374 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
2378 if ( c->argc > 1 ) {
2381 /* quote all args but the first */
2382 line = ldap_charray2str( c->argv, "\" \"" );
2383 ber_str2bv( line, 0, 0, &bv );
2384 s = ber_bvchr( &bv, '"' );
2385 assert( s != NULL );
2386 /* move the trailing quote of argv[0] to the end */
2387 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
2388 bv.bv_val[ bv.bv_len - 1 ] = '"';
2391 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
2394 ber_bvarray_add( &authz_rewrites, &bv );
2396 if ( c->op == LDAP_MOD_ADD ) {
2406 Debug( LDAP_DEBUG_ANY,
2407 "%s: unknown CFG_TYPE %d.\n",
2408 c->log, c->type, 0 );
2417 config_fname(ConfigArgs *c) {
2418 if(c->op == SLAP_CONFIG_EMIT) {
2419 if (c->ca_private) {
2420 ConfigFile *cf = c->ca_private;
2421 value_add_one( &c->rvalue_vals, &cf->c_file );
2430 config_cfdir(ConfigArgs *c) {
2431 if(c->op == SLAP_CONFIG_EMIT) {
2432 if ( !BER_BVISEMPTY( &cfdir )) {
2433 value_add_one( &c->rvalue_vals, &cfdir );
2442 config_search_base(ConfigArgs *c) {
2443 if(c->op == SLAP_CONFIG_EMIT) {
2445 if (!BER_BVISEMPTY(&default_search_base)) {
2446 value_add_one(&c->rvalue_vals, &default_search_base);
2447 value_add_one(&c->rvalue_nvals, &default_search_nbase);
2451 } else if( c->op == LDAP_MOD_DELETE ) {
2452 ch_free( default_search_base.bv_val );
2453 ch_free( default_search_nbase.bv_val );
2454 BER_BVZERO( &default_search_base );
2455 BER_BVZERO( &default_search_nbase );
2459 if(c->bi || c->be != frontendDB) {
2460 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
2461 "prior to any backend or database definition\n",
2466 if(default_search_nbase.bv_len) {
2467 free(default_search_base.bv_val);
2468 free(default_search_nbase.bv_val);
2471 default_search_base = c->value_dn;
2472 default_search_nbase = c->value_ndn;
2476 /* For RE23 compatibility we allow this in the global entry
2477 * but we now defer it to the frontend entry to allow modules
2478 * to load new hash types.
2481 config_passwd_hash(ConfigArgs *c) {
2483 if (c->op == SLAP_CONFIG_EMIT) {
2485 /* Don't generate it in the global entry */
2486 if ( c->table == Cft_Global )
2488 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
2489 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
2490 value_add_one(&c->rvalue_vals, &bv);
2493 } else if ( c->op == LDAP_MOD_DELETE ) {
2494 /* Deleting from global is a no-op, only the frontendDB entry matters */
2495 if ( c->table == Cft_Global )
2497 if ( c->valx < 0 ) {
2498 ldap_charray_free( default_passwd_hash );
2499 default_passwd_hash = NULL;
2502 ch_free( default_passwd_hash[i] );
2503 for (; default_passwd_hash[i]; i++ )
2504 default_passwd_hash[i] = default_passwd_hash[i+1];
2508 for(i = 1; i < c->argc; i++) {
2509 if(!lutil_passwd_scheme(c->argv[i])) {
2510 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> scheme not available", c->argv[0] );
2511 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2512 c->log, c->cr_msg, c->argv[i]);
2514 ldap_charray_add(&default_passwd_hash, c->argv[i]);
2517 if(!default_passwd_hash) {
2518 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> no valid hashes found", c->argv[0] );
2519 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2520 c->log, c->cr_msg, 0 );
2527 config_schema_dn(ConfigArgs *c) {
2528 if ( c->op == SLAP_CONFIG_EMIT ) {
2530 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
2531 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
2532 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
2536 } else if ( c->op == LDAP_MOD_DELETE ) {
2537 ch_free( c->be->be_schemadn.bv_val );
2538 ch_free( c->be->be_schemandn.bv_val );
2539 BER_BVZERO( &c->be->be_schemadn );
2540 BER_BVZERO( &c->be->be_schemandn );
2543 ch_free( c->be->be_schemadn.bv_val );
2544 ch_free( c->be->be_schemandn.bv_val );
2545 c->be->be_schemadn = c->value_dn;
2546 c->be->be_schemandn = c->value_ndn;
2551 config_sizelimit(ConfigArgs *c) {
2553 struct slap_limits_set *lim = &c->be->be_def_limit;
2554 if (c->op == SLAP_CONFIG_EMIT) {
2559 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
2560 if ( !BER_BVISEMPTY( &bv ))
2561 value_add_one( &c->rvalue_vals, &bv );
2565 } else if ( c->op == LDAP_MOD_DELETE ) {
2566 /* Reset to defaults or values from frontend */
2567 if ( c->be == frontendDB ) {
2568 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
2569 lim->lms_s_hard = 0;
2570 lim->lms_s_unchecked = -1;
2572 lim->lms_s_pr_hide = 0;
2573 lim->lms_s_pr_total = 0;
2575 lim->lms_s_soft = frontendDB->be_def_limit.lms_s_soft;
2576 lim->lms_s_hard = frontendDB->be_def_limit.lms_s_hard;
2577 lim->lms_s_unchecked = frontendDB->be_def_limit.lms_s_unchecked;
2578 lim->lms_s_pr = frontendDB->be_def_limit.lms_s_pr;
2579 lim->lms_s_pr_hide = frontendDB->be_def_limit.lms_s_pr_hide;
2580 lim->lms_s_pr_total = frontendDB->be_def_limit.lms_s_pr_total;
2584 for(i = 1; i < c->argc; i++) {
2585 if(!strncasecmp(c->argv[i], "size", 4)) {
2586 rc = limits_parse_one(c->argv[i], lim);
2588 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2589 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2590 c->log, c->cr_msg, c->argv[i]);
2594 if(!strcasecmp(c->argv[i], "unlimited")) {
2595 lim->lms_s_soft = -1;
2597 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
2598 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2599 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2600 c->log, c->cr_msg, c->argv[i]);
2604 lim->lms_s_hard = 0;
2609 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2610 /* This is a modification to the global limits apply it to
2611 * the other databases as needed */
2612 AttributeDescription *ad=NULL;
2613 const char *text = NULL;
2614 CfEntryInfo *ce = c->ca_entry->e_private;
2616 slap_str2ad(c->argv[0], &ad, &text);
2617 /* if we got here... */
2618 assert( ad != NULL );
2620 if ( ce->ce_type == Cft_Global ){
2623 for (; ce; ce=ce->ce_sibs) {
2624 Entry *dbe = ce->ce_entry;
2625 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2626 && (!attr_find(dbe->e_attrs, ad)) ) {
2627 ce->ce_be->be_def_limit.lms_s_soft = lim->lms_s_soft;
2628 ce->ce_be->be_def_limit.lms_s_hard = lim->lms_s_hard;
2629 ce->ce_be->be_def_limit.lms_s_unchecked =lim->lms_s_unchecked;
2630 ce->ce_be->be_def_limit.lms_s_pr =lim->lms_s_pr;
2631 ce->ce_be->be_def_limit.lms_s_pr_hide =lim->lms_s_pr_hide;
2632 ce->ce_be->be_def_limit.lms_s_pr_total =lim->lms_s_pr_total;
2640 config_timelimit(ConfigArgs *c) {
2642 struct slap_limits_set *lim = &c->be->be_def_limit;
2643 if (c->op == SLAP_CONFIG_EMIT) {
2648 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
2649 if ( !BER_BVISEMPTY( &bv ))
2650 value_add_one( &c->rvalue_vals, &bv );
2654 } else if ( c->op == LDAP_MOD_DELETE ) {
2655 /* Reset to defaults or values from frontend */
2656 if ( c->be == frontendDB ) {
2657 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
2658 lim->lms_t_hard = 0;
2660 lim->lms_t_soft = frontendDB->be_def_limit.lms_t_soft;
2661 lim->lms_t_hard = frontendDB->be_def_limit.lms_t_hard;
2665 for(i = 1; i < c->argc; i++) {
2666 if(!strncasecmp(c->argv[i], "time", 4)) {
2667 rc = limits_parse_one(c->argv[i], lim);
2669 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2670 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2671 c->log, c->cr_msg, c->argv[i]);
2675 if(!strcasecmp(c->argv[i], "unlimited")) {
2676 lim->lms_t_soft = -1;
2678 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
2679 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2680 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2681 c->log, c->cr_msg, c->argv[i]);
2685 lim->lms_t_hard = 0;
2690 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2691 /* This is a modification to the global limits apply it to
2692 * the other databases as needed */
2693 AttributeDescription *ad=NULL;
2694 const char *text = NULL;
2695 CfEntryInfo *ce = c->ca_entry->e_private;
2697 slap_str2ad(c->argv[0], &ad, &text);
2698 /* if we got here... */
2699 assert( ad != NULL );
2701 if ( ce->ce_type == Cft_Global ){
2704 for (; ce; ce=ce->ce_sibs) {
2705 Entry *dbe = ce->ce_entry;
2706 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2707 && (!attr_find(dbe->e_attrs, ad)) ) {
2708 ce->ce_be->be_def_limit.lms_t_soft = lim->lms_t_soft;
2709 ce->ce_be->be_def_limit.lms_t_hard = lim->lms_t_hard;
2717 config_overlay(ConfigArgs *c) {
2718 if (c->op == SLAP_CONFIG_EMIT) {
2720 } else if ( c->op == LDAP_MOD_DELETE ) {
2723 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2724 c->valx, &c->bi, &c->reply)) {
2726 Debug( LDAP_DEBUG_ANY,
2727 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2728 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2730 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi, &c->reply)) {
2737 config_subordinate(ConfigArgs *c)
2743 case SLAP_CONFIG_EMIT:
2744 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2747 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2748 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2751 value_add_one( &c->rvalue_vals, &bv );
2755 case LDAP_MOD_DELETE:
2756 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2757 glue_sub_del( c->be );
2759 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2764 case SLAP_CONFIG_ADD:
2765 if ( c->be->be_nsuffix == NULL ) {
2767 snprintf( c->cr_msg, sizeof( c->cr_msg),
2768 "subordinate configuration needs a suffix" );
2769 Debug( LDAP_DEBUG_ANY,
2771 c->log, c->cr_msg, 0 );
2776 if ( c->argc == 2 ) {
2777 if ( strcasecmp( c->argv[1], "advertise" ) == 0 ) {
2780 } else if ( strcasecmp( c->argv[1], "TRUE" ) != 0 ) {
2782 snprintf( c->cr_msg, sizeof( c->cr_msg),
2783 "subordinate must be \"TRUE\" or \"advertise\"" );
2784 Debug( LDAP_DEBUG_ANY,
2785 "%s: suffix \"%s\": %s.\n",
2786 c->log, c->be->be_suffix[0].bv_val, c->cr_msg );
2792 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2800 * [listener=<listener>] [{read|write}=]<size>
2803 #ifdef LDAP_TCP_BUFFER
2804 static BerVarray tcp_buffer;
2807 #define SLAP_TCP_RMEM (0x1U)
2808 #define SLAP_TCP_WMEM (0x2U)
2811 tcp_buffer_parse( struct berval *val, int argc, char **argv,
2812 int *size, int *rw, Listener **l )
2814 int i, rc = LDAP_SUCCESS;
2815 LDAPURLDesc *lud = NULL;
2818 if ( val != NULL && argv == NULL ) {
2819 char *s = val->bv_val;
2821 argv = ldap_str2charray( s, " \t" );
2822 if ( argv == NULL ) {
2828 if ( strncasecmp( argv[ i ], "listener=", STRLENOF( "listener=" ) )
2831 char *url = argv[ i ] + STRLENOF( "listener=" );
2833 if ( ldap_url_parse( url, &lud ) ) {
2834 rc = LDAP_INVALID_SYNTAX;
2838 *l = config_check_my_url( url, lud );
2840 rc = LDAP_NO_SUCH_ATTRIBUTE;
2848 if ( strncasecmp( ptr, "read=", STRLENOF( "read=" ) ) == 0 ) {
2849 *rw |= SLAP_TCP_RMEM;
2850 ptr += STRLENOF( "read=" );
2852 } else if ( strncasecmp( ptr, "write=", STRLENOF( "write=" ) ) == 0 ) {
2853 *rw |= SLAP_TCP_WMEM;
2854 ptr += STRLENOF( "write=" );
2857 *rw |= ( SLAP_TCP_RMEM | SLAP_TCP_WMEM );
2860 /* accept any base */
2861 if ( lutil_atoix( size, ptr, 0 ) ) {
2862 rc = LDAP_INVALID_SYNTAX;
2867 if ( val != NULL && argv != NULL ) {
2868 ldap_charray_free( argv );
2871 if ( lud != NULL ) {
2872 ldap_free_urldesc( lud );
2879 tcp_buffer_delete_one( struct berval *val )
2882 int size = -1, rw = 0;
2885 rc = tcp_buffer_parse( val, 0, NULL, &size, &rw, &l );
2892 Listener **ll = slapd_get_listeners();
2894 for ( i = 0; ll[ i ] != NULL; i++ ) {
2895 if ( ll[ i ] == l ) break;
2898 if ( ll[ i ] == NULL ) {
2899 return LDAP_NO_SUCH_ATTRIBUTE;
2902 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = -1;
2903 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = -1;
2905 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2906 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = -1;
2907 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = -1;
2911 /* NOTE: this affects listeners without a specific setting,
2912 * does not reset all listeners. If a listener without
2913 * specific settings was assigned a buffer because of
2914 * a global setting, it will not be reset. In any case,
2915 * buffer changes will only take place at restart. */
2916 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = -1;
2917 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = -1;
2924 tcp_buffer_delete( BerVarray vals )
2928 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
2929 tcp_buffer_delete_one( &vals[ i ] );
2936 tcp_buffer_unparse( int size, int rw, Listener *l, struct berval *val )
2938 char buf[sizeof("2147483648")], *ptr;
2940 /* unparse for later use */
2941 val->bv_len = snprintf( buf, sizeof( buf ), "%d", size );
2943 val->bv_len += STRLENOF( "listener=" " " ) + l->sl_url.bv_len;
2946 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2947 if ( rw & SLAP_TCP_RMEM ) {
2948 val->bv_len += STRLENOF( "read=" );
2949 } else if ( rw & SLAP_TCP_WMEM ) {
2950 val->bv_len += STRLENOF( "write=" );
2954 val->bv_val = SLAP_MALLOC( val->bv_len + 1 );
2959 ptr = lutil_strcopy( ptr, "listener=" );
2960 ptr = lutil_strncopy( ptr, l->sl_url.bv_val, l->sl_url.bv_len );
2964 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2965 if ( rw & SLAP_TCP_RMEM ) {
2966 ptr = lutil_strcopy( ptr, "read=" );
2967 } else if ( rw & SLAP_TCP_WMEM ) {
2968 ptr = lutil_strcopy( ptr, "write=" );
2972 ptr = lutil_strcopy( ptr, buf );
2975 assert( val->bv_val + val->bv_len == ptr );
2977 return LDAP_SUCCESS;
2981 tcp_buffer_add_one( int argc, char **argv )
2984 int size = -1, rw = 0;
2990 rc = tcp_buffer_parse( NULL, argc, argv, &size, &rw, &l );
2995 /* unparse for later use */
2996 rc = tcp_buffer_unparse( size, rw, l, &val );
2997 if ( rc != LDAP_SUCCESS ) {
3001 /* use parsed values */
3004 Listener **ll = slapd_get_listeners();
3006 for ( i = 0; ll[ i ] != NULL; i++ ) {
3007 if ( ll[ i ] == l ) break;
3010 if ( ll[ i ] == NULL ) {
3011 return LDAP_NO_SUCH_ATTRIBUTE;
3014 /* buffer only applies to TCP listeners;
3015 * we do not do any check here, and delegate them
3016 * to setsockopt(2) */
3017 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = size;
3018 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = size;
3020 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
3021 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = size;
3022 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = size;
3026 /* NOTE: this affects listeners without a specific setting,
3027 * does not set all listeners */
3028 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = size;
3029 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = size;
3032 tcp_buffer = SLAP_REALLOC( tcp_buffer, sizeof( struct berval ) * ( tcp_buffer_num + 2 ) );
3034 tcp_buffer[ tcp_buffer_num ] = val;
3037 BER_BVZERO( &tcp_buffer[ tcp_buffer_num ] );
3043 config_tcp_buffer( ConfigArgs *c )
3045 if ( c->op == SLAP_CONFIG_EMIT ) {
3046 if ( tcp_buffer == NULL || BER_BVISNULL( &tcp_buffer[ 0 ] ) ) {
3049 value_add( &c->rvalue_vals, tcp_buffer );
3050 value_add( &c->rvalue_nvals, tcp_buffer );
3052 } else if ( c->op == LDAP_MOD_DELETE ) {
3054 tcp_buffer_delete( tcp_buffer );
3055 ber_bvarray_free( tcp_buffer );
3061 int size = -1, rw = 0;
3064 struct berval val = BER_BVNULL;
3068 if ( tcp_buffer_num == 0 ) {
3073 rc = tcp_buffer_parse( NULL, c->argc - 1, &c->argv[ 1 ], &size, &rw, &l );
3078 /* unparse for later use */
3079 rc = tcp_buffer_unparse( size, rw, l, &val );
3080 if ( rc != LDAP_SUCCESS ) {
3084 for ( i = 0; !BER_BVISNULL( &tcp_buffer[ i ] ); i++ ) {
3085 if ( bvmatch( &tcp_buffer[ i ], &val ) ) {
3090 if ( BER_BVISNULL( &tcp_buffer[ i ] ) ) {
3096 tcp_buffer_delete_one( &tcp_buffer[ i ] );
3097 ber_memfree( tcp_buffer[ i ].bv_val );
3098 for ( ; i < tcp_buffer_num; i++ ) {
3099 tcp_buffer[ i ] = tcp_buffer[ i + 1 ];
3104 if ( !BER_BVISNULL( &val ) ) {
3105 SLAP_FREE( val.bv_val );
3113 rc = tcp_buffer_add_one( c->argc - 1, &c->argv[ 1 ] );
3115 snprintf( c->cr_msg, sizeof( c->cr_msg ),
3116 "<%s> unable to add value #%d",
3117 c->argv[0], tcp_buffer_num );
3118 Debug( LDAP_DEBUG_ANY, "%s: %s\n",
3119 c->log, c->cr_msg, 0 );
3126 #endif /* LDAP_TCP_BUFFER */
3129 config_suffix(ConfigArgs *c)
3132 struct berval pdn, ndn;
3133 char *notallowed = NULL;
3135 if ( c->be == frontendDB ) {
3136 notallowed = "frontend";
3138 } else if ( SLAP_MONITOR(c->be) ) {
3139 notallowed = "monitor";
3141 } else if ( SLAP_CONFIG(c->be) ) {
3142 notallowed = "config";
3145 if ( notallowed != NULL ) {
3146 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
3150 case LDAP_MOD_DELETE:
3151 case LDAP_MOD_REPLACE:
3152 case LDAP_MOD_INCREMENT:
3153 case SLAP_CONFIG_ADD:
3154 if ( !BER_BVISNULL( &c->value_dn ) ) {
3155 snprintf( buf, sizeof( buf ), "<%s> ",
3156 c->value_dn.bv_val );
3159 Debug(LDAP_DEBUG_ANY,
3160 "%s: suffix %snot allowed in %s database.\n",
3161 c->log, buf, notallowed );
3164 case SLAP_CONFIG_EMIT:
3165 /* don't complain when emitting... */
3169 /* FIXME: don't know what values may be valid;
3170 * please remove assertion, or add legal values
3171 * to either block */
3179 if (c->op == SLAP_CONFIG_EMIT) {
3180 if ( c->be->be_suffix == NULL
3181 || BER_BVISNULL( &c->be->be_suffix[0] ) )
3185 value_add( &c->rvalue_vals, c->be->be_suffix );
3186 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
3189 } else if ( c->op == LDAP_MOD_DELETE ) {
3190 if ( c->valx < 0 ) {
3191 ber_bvarray_free( c->be->be_suffix );
3192 ber_bvarray_free( c->be->be_nsuffix );
3193 c->be->be_suffix = NULL;
3194 c->be->be_nsuffix = NULL;
3197 ch_free( c->be->be_suffix[i].bv_val );
3198 ch_free( c->be->be_nsuffix[i].bv_val );
3200 c->be->be_suffix[i] = c->be->be_suffix[i+1];
3201 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
3203 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
3208 #ifdef SLAPD_MONITOR_DN
3209 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
3210 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> DN is reserved for monitoring slapd",
3212 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3213 c->log, c->cr_msg, SLAPD_MONITOR_DN);
3218 if (SLAP_DB_ONE_SUFFIX( c->be ) && c->be->be_suffix &&
3219 !BER_BVISNULL( &c->be->be_suffix[0] )) {
3220 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> Only one suffix is allowed on this %s backend",
3221 c->argv[0], c->be->bd_info->bi_type );
3222 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3223 c->log, c->cr_msg, 0);
3230 if (SLAP_DBHIDDEN( c->be ))
3233 tbe = select_backend(&ndn, 0);
3235 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
3241 BackendDB *b2 = tbe;
3243 /* Does tbe precede be? */
3244 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
3247 char *type = tbe->bd_info->bi_type;
3249 if ( overlay_is_over( tbe ) ) {
3250 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
3251 type = oi->oi_orig->bi_type;
3254 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> namingContext \"%s\" "
3255 "already served by a preceding %s database",
3256 c->argv[0], pdn.bv_val, type );
3257 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
3258 c->log, c->cr_msg, tbe->be_suffix[0].bv_val);
3264 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
3265 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
3266 "base provided \"%s\" (assuming okay)\n",
3267 c->log, default_search_base.bv_val, 0);
3269 ber_bvarray_add(&c->be->be_suffix, &pdn);
3270 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
3275 config_rootdn(ConfigArgs *c) {
3276 if (c->op == SLAP_CONFIG_EMIT) {
3277 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
3278 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
3279 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
3284 } else if ( c->op == LDAP_MOD_DELETE ) {
3285 ch_free( c->be->be_rootdn.bv_val );
3286 ch_free( c->be->be_rootndn.bv_val );
3287 BER_BVZERO( &c->be->be_rootdn );
3288 BER_BVZERO( &c->be->be_rootndn );
3291 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
3292 ch_free( c->be->be_rootdn.bv_val );
3293 ch_free( c->be->be_rootndn.bv_val );
3295 c->be->be_rootdn = c->value_dn;
3296 c->be->be_rootndn = c->value_ndn;
3301 config_rootpw(ConfigArgs *c) {
3304 if (c->op == SLAP_CONFIG_EMIT) {
3305 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
3306 /* don't copy, because "rootpw" is marked
3308 c->value_bv = c->be->be_rootpw;
3312 } else if ( c->op == LDAP_MOD_DELETE ) {
3313 ch_free( c->be->be_rootpw.bv_val );
3314 BER_BVZERO( &c->be->be_rootpw );
3318 tbe = select_backend(&c->be->be_rootndn, 0);
3319 if(tbe != c->be && !SLAP_DBHIDDEN( c->be )) {
3320 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> can only be set when rootdn is under suffix",
3322 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3323 c->log, c->cr_msg, 0);
3326 if ( !BER_BVISNULL( &c->be->be_rootpw ))
3327 ch_free( c->be->be_rootpw.bv_val );
3328 c->be->be_rootpw = c->value_bv;
3333 config_restrict(ConfigArgs *c) {
3334 slap_mask_t restrictops = 0;
3336 slap_verbmasks restrictable_ops[] = {
3337 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
3338 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
3339 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
3340 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
3341 { BER_BVC("modrdn"), 0 },
3342 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
3343 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
3344 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
3345 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
3346 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
3347 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
3348 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
3349 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
3350 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
3351 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
3352 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
3356 if (c->op == SLAP_CONFIG_EMIT) {
3357 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
3359 } else if ( c->op == LDAP_MOD_DELETE ) {
3361 c->be->be_restrictops = 0;
3363 i = verb_to_mask( c->line, restrictable_ops );
3364 c->be->be_restrictops &= ~restrictable_ops[i].mask;
3368 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
3370 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown operation", c->argv[0] );
3371 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3372 c->log, c->cr_msg, c->argv[i]);
3375 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
3376 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
3377 c->be->be_restrictops |= restrictops;
3382 config_allows(ConfigArgs *c) {
3383 slap_mask_t allows = 0;
3385 slap_verbmasks allowable_ops[] = {
3386 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
3387 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
3388 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
3389 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
3390 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
3393 if (c->op == SLAP_CONFIG_EMIT) {
3394 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
3395 } else if ( c->op == LDAP_MOD_DELETE ) {
3399 i = verb_to_mask( c->line, allowable_ops );
3400 global_allows &= ~allowable_ops[i].mask;
3404 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
3406 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3407 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3408 c->log, c->cr_msg, c->argv[i]);
3411 global_allows |= allows;
3416 config_disallows(ConfigArgs *c) {
3417 slap_mask_t disallows = 0;
3419 slap_verbmasks disallowable_ops[] = {
3420 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
3421 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
3422 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
3423 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
3424 { BER_BVC("proxy_authz_non_critical"), SLAP_DISALLOW_PROXY_AUTHZ_N_CRIT },
3425 { BER_BVC("dontusecopy_non_critical"), SLAP_DISALLOW_DONTUSECOPY_N_CRIT },
3428 if (c->op == SLAP_CONFIG_EMIT) {
3429 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
3430 } else if ( c->op == LDAP_MOD_DELETE ) {
3432 global_disallows = 0;
3434 i = verb_to_mask( c->line, disallowable_ops );
3435 global_disallows &= ~disallowable_ops[i].mask;
3439 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
3441 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3442 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3443 c->log, c->cr_msg, c->argv[i]);
3446 global_disallows |= disallows;
3451 config_requires(ConfigArgs *c) {
3452 slap_mask_t requires = frontendDB->be_requires;
3453 int i, argc = c->argc;
3454 char **argv = c->argv;
3456 slap_verbmasks requires_ops[] = {
3457 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
3458 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
3459 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
3460 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
3461 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
3464 if (c->op == SLAP_CONFIG_EMIT) {
3465 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
3466 } else if ( c->op == LDAP_MOD_DELETE ) {
3468 c->be->be_requires = 0;
3470 i = verb_to_mask( c->line, requires_ops );
3471 c->be->be_requires &= ~requires_ops[i].mask;
3475 /* "none" can only be first, to wipe out default/global values */
3476 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
3481 i = verbs_to_mask(argc, argv, requires_ops, &requires);
3483 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
3484 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
3485 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3486 c->log, c->cr_msg, 0);
3488 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
3489 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3490 c->log, c->cr_msg, c->argv[i]);
3494 c->be->be_requires = requires;
3499 config_extra_attrs(ConfigArgs *c)
3501 assert( c->be != NULL );
3503 if ( c->op == SLAP_CONFIG_EMIT ) {
3506 if ( c->be->be_extra_anlist == NULL ) {
3510 for ( i = 0; !BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ); i++ ) {
3511 value_add_one( &c->rvalue_vals, &c->be->be_extra_anlist[i].an_name );
3514 } else if ( c->op == LDAP_MOD_DELETE ) {
3515 if ( c->be->be_extra_anlist == NULL ) {
3519 if ( c->valx < 0 ) {
3520 anlist_free( c->be->be_extra_anlist, 1, NULL );
3521 c->be->be_extra_anlist = NULL;
3526 for ( i = 0; i < c->valx && !BER_BVISNULL( &c->be->be_extra_anlist[i + 1].an_name ); i++ )
3529 if ( BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ) ) {
3533 ch_free( c->be->be_extra_anlist[i].an_name.bv_val );
3535 for ( ; !BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ); i++ ) {
3536 c->be->be_extra_anlist[i] = c->be->be_extra_anlist[i + 1];
3541 c->be->be_extra_anlist = str2anlist( c->be->be_extra_anlist, c->argv[1], " ,\t" );
3542 if ( c->be->be_extra_anlist == NULL ) {
3550 static slap_verbmasks *loglevel_ops;
3553 loglevel_init( void )
3555 slap_verbmasks lo[] = {
3556 { BER_BVC("Any"), (slap_mask_t) LDAP_DEBUG_ANY },
3557 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
3558 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
3559 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
3560 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
3561 { BER_BVC("BER"), LDAP_DEBUG_BER },
3562 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
3563 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
3564 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
3565 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
3566 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
3567 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
3568 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
3569 #if 0 /* no longer used (nor supported) */
3570 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
3571 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
3573 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
3574 { BER_BVC("None"), LDAP_DEBUG_NONE },
3578 return slap_verbmasks_init( &loglevel_ops, lo );
3582 loglevel_destroy( void )
3584 if ( loglevel_ops ) {
3585 (void)slap_verbmasks_destroy( loglevel_ops );
3587 loglevel_ops = NULL;
3590 static slap_mask_t loglevel_ignore[] = { -1, 0 };
3593 slap_loglevel_register( slap_mask_t m, struct berval *s )
3597 if ( loglevel_ops == NULL ) {
3601 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
3604 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
3612 slap_loglevel_get( struct berval *s, int *l )
3617 if ( loglevel_ops == NULL ) {
3621 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3622 m |= loglevel_ops[ i ].mask;
3625 for ( i = 1; m & i; i <<= 1 )
3632 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
3635 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
3646 str2loglevel( const char *s, int *l )
3650 if ( loglevel_ops == NULL ) {
3654 i = verb_to_mask( s, loglevel_ops );
3656 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
3660 *l = loglevel_ops[ i ].mask;
3666 loglevel2str( int l )
3668 struct berval bv = BER_BVNULL;
3670 loglevel2bv( l, &bv );
3676 loglevel2bv( int l, struct berval *bv )
3678 if ( loglevel_ops == NULL ) {
3684 return enum_to_verb( loglevel_ops, l, bv ) == -1;
3688 loglevel2bvarray( int l, BerVarray *bva )
3690 if ( loglevel_ops == NULL ) {
3695 struct berval bv = BER_BVC("0");
3696 return value_add_one( bva, &bv );
3699 return mask_to_verbs( loglevel_ops, l, bva );
3703 loglevel_print( FILE *out )
3707 if ( loglevel_ops == NULL ) {
3711 fprintf( out, "Installed log subsystems:\n\n" );
3712 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3713 unsigned mask = loglevel_ops[ i ].mask & 0xffffffffUL;
3715 (mask == ((slap_mask_t) -1 & 0xffffffffUL)
3716 ? "\t%-30s (-1, 0xffffffff)\n" : "\t%-30s (%u, 0x%x)\n"),
3717 loglevel_ops[ i ].word.bv_val, mask, mask );
3720 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
3721 "by specific code\n\n" );
3726 static int config_syslog;
3729 config_loglevel(ConfigArgs *c) {
3732 if ( loglevel_ops == NULL ) {
3736 if (c->op == SLAP_CONFIG_EMIT) {
3737 /* Get default or commandline slapd setting */
3738 if ( ldap_syslog && !config_syslog )
3739 config_syslog = ldap_syslog;
3740 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
3742 } else if ( c->op == LDAP_MOD_DELETE ) {
3746 i = verb_to_mask( c->line, loglevel_ops );
3747 config_syslog &= ~loglevel_ops[i].mask;
3749 if ( slapMode & SLAP_SERVER_MODE ) {
3750 ldap_syslog = config_syslog;
3755 for( i=1; i < c->argc; i++ ) {
3758 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
3759 if( lutil_atoix( &level, c->argv[i], 0 ) != 0 ) {
3760 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse level", c->argv[0] );
3761 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3762 c->log, c->cr_msg, c->argv[i]);
3766 if ( str2loglevel( c->argv[i], &level ) ) {
3767 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown level", c->argv[0] );
3768 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3769 c->log, c->cr_msg, c->argv[i]);
3773 /* Explicitly setting a zero clears all the levels */
3775 config_syslog |= level;
3779 if ( slapMode & SLAP_SERVER_MODE ) {
3780 ldap_syslog = config_syslog;
3786 config_referral(ConfigArgs *c) {
3788 if (c->op == SLAP_CONFIG_EMIT) {
3789 if ( default_referral ) {
3790 value_add( &c->rvalue_vals, default_referral );
3795 } else if ( c->op == LDAP_MOD_DELETE ) {
3796 if ( c->valx < 0 ) {
3797 ber_bvarray_free( default_referral );
3798 default_referral = NULL;
3801 ch_free( default_referral[i].bv_val );
3802 for (; default_referral[i].bv_val; i++ )
3803 default_referral[i] = default_referral[i+1];
3807 if(validate_global_referral(c->argv[1])) {
3808 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3809 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3810 c->log, c->cr_msg, c->argv[1]);
3814 ber_str2bv(c->argv[1], 0, 0, &val);
3815 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
3823 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
3824 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
3825 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
3826 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
3827 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
3828 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
3829 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
3830 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
3831 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
3836 config_security(ConfigArgs *c) {
3837 slap_ssf_set_t *set = &c->be->be_ssf_set;
3840 if (c->op == SLAP_CONFIG_EMIT) {
3846 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
3847 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
3850 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
3851 if ( bv.bv_len >= sizeof( numbuf ) ) {
3852 ber_bvarray_free_x( c->rvalue_vals, NULL );
3853 c->rvalue_vals = NULL;
3857 bv.bv_len += sec_keys[i].key.bv_len;
3858 bv.bv_val = ch_malloc( bv.bv_len + 1);
3859 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
3860 strcpy( next, numbuf );
3861 ber_bvarray_add( &c->rvalue_vals, &bv );
3866 for(i = 1; i < c->argc; i++) {
3867 slap_ssf_t *tgt = NULL;
3869 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
3870 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
3871 sec_keys[j].key.bv_len)) {
3872 src = c->argv[i] + sec_keys[j].key.bv_len;
3873 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
3878 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown factor", c->argv[0] );
3879 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3880 c->log, c->cr_msg, c->argv[i]);
3884 if ( lutil_atou( tgt, src ) != 0 ) {
3885 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse factor", c->argv[0] );
3886 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3887 c->log, c->cr_msg, c->argv[i]);
3895 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
3899 for (; !BER_BVISNULL( &an->an_name ); an++) {
3900 /* if buflen == 0, assume the buffer size has been
3901 * already checked otherwise */
3902 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
3903 if ( comma ) *ptr++ = ',';
3904 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
3911 config_updatedn(ConfigArgs *c) {
3912 if (c->op == SLAP_CONFIG_EMIT) {
3913 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
3914 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
3915 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
3919 } else if ( c->op == LDAP_MOD_DELETE ) {
3920 ch_free( c->be->be_update_ndn.bv_val );
3921 BER_BVZERO( &c->be->be_update_ndn );
3922 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
3925 if(SLAP_SHADOW(c->be)) {
3926 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database already shadowed", c->argv[0] );
3927 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3928 c->log, c->cr_msg, 0);
3932 ber_memfree_x( c->value_dn.bv_val, NULL );
3933 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
3934 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
3936 c->be->be_update_ndn = c->value_ndn;
3937 BER_BVZERO( &c->value_dn );
3938 BER_BVZERO( &c->value_ndn );
3940 return config_slurp_shadow( c );
3944 config_shadow( ConfigArgs *c, slap_mask_t flag )
3946 char *notallowed = NULL;
3948 if ( c->be == frontendDB ) {
3949 notallowed = "frontend";
3951 } else if ( SLAP_MONITOR(c->be) ) {
3952 notallowed = "monitor";
3955 if ( notallowed != NULL ) {
3956 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
3960 if ( SLAP_SHADOW(c->be) ) {
3961 /* if already shadow, only check consistency */
3962 if ( ( SLAP_DBFLAGS(c->be) & flag ) != flag ) {
3963 Debug( LDAP_DEBUG_ANY, "%s: inconsistent shadow flag 0x%lx.\n",
3969 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | flag);
3970 if ( !SLAP_MULTIMASTER( c->be ))
3971 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
3978 config_updateref(ConfigArgs *c) {
3980 if (c->op == SLAP_CONFIG_EMIT) {
3981 if ( c->be->be_update_refs ) {
3982 value_add( &c->rvalue_vals, c->be->be_update_refs );
3987 } else if ( c->op == LDAP_MOD_DELETE ) {
3988 if ( c->valx < 0 ) {
3989 ber_bvarray_free( c->be->be_update_refs );
3990 c->be->be_update_refs = NULL;
3993 ch_free( c->be->be_update_refs[i].bv_val );
3994 for (; c->be->be_update_refs[i].bv_val; i++)
3995 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
3999 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
4000 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must appear after syncrepl or updatedn",
4002 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
4003 c->log, c->cr_msg, 0);
4007 if(validate_global_referral(c->argv[1])) {
4008 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
4009 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
4010 c->log, c->cr_msg, c->argv[1]);
4013 ber_str2bv(c->argv[1], 0, 0, &val);
4014 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
4019 config_obsolete(ConfigArgs *c) {
4020 if (c->op == SLAP_CONFIG_EMIT)
4023 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> keyword is obsolete (ignored)",
4025 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0);
4030 config_include(ConfigArgs *c) {
4031 int savelineno = c->lineno;
4034 ConfigFile *cfsave = cfn;
4035 ConfigFile *cf2 = NULL;
4037 /* Leftover from RE23. No dynamic config for include files */
4038 if ( c->op == SLAP_CONFIG_EMIT || c->op == LDAP_MOD_DELETE )
4041 cf = ch_calloc( 1, sizeof(ConfigFile));
4042 if ( cfn->c_kids ) {
4043 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
4049 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
4050 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
4051 c->lineno = savelineno - 1;
4054 if ( cf2 ) cf2->c_sibs = NULL;
4055 else cfn->c_kids = NULL;
4056 ch_free( cf->c_file.bv_val );
4066 config_tls_cleanup(ConfigArgs *c) {
4069 if ( slap_tls_ld ) {
4072 ldap_pvt_tls_ctx_free( slap_tls_ctx );
4073 slap_tls_ctx = NULL;
4075 /* Force new ctx to be created */
4076 rc = ldap_pvt_tls_set_option( slap_tls_ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
4078 /* The ctx's refcount is bumped up here */
4079 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CTX, &slap_tls_ctx );
4080 /* This is a no-op if it's already loaded */
4081 load_extop( &slap_EXOP_START_TLS, 0, starttls_extop );
4083 if ( rc == LDAP_NOT_SUPPORTED )
4084 rc = LDAP_UNWILLING_TO_PERFORM;
4093 config_tls_option(ConfigArgs *c) {
4096 LDAP *ld = slap_tls_ld;
4098 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
4099 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
4100 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
4101 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
4102 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
4103 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
4104 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
4105 case CFG_TLS_ECNAME: flag = LDAP_OPT_X_TLS_ECNAME; break;
4107 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
4109 case CFG_TLS_CACERT: flag = LDAP_OPT_X_TLS_CACERT; berval = 1; break;
4110 case CFG_TLS_CERT: flag = LDAP_OPT_X_TLS_CERT; berval = 1; break;
4111 case CFG_TLS_KEY: flag = LDAP_OPT_X_TLS_KEY; berval = 1; break;
4112 default: Debug(LDAP_DEBUG_ANY, "%s: "
4113 "unknown tls_option <0x%x>\n",
4114 c->log, c->type, 0);
4117 if (c->op == SLAP_CONFIG_EMIT) {
4118 return ldap_pvt_tls_get_option( ld, flag, berval ? (void *)&c->value_bv : (void *)&c->value_string );
4119 } else if ( c->op == LDAP_MOD_DELETE ) {
4120 c->cleanup = config_tls_cleanup;
4121 return ldap_pvt_tls_set_option( ld, flag, NULL );
4123 if ( !berval ) ch_free(c->value_string);
4124 c->cleanup = config_tls_cleanup;
4125 rc = ldap_pvt_tls_set_option(ld, flag, berval ? (void *)&c->value_bv : (void *)c->argv[1]);
4126 if ( berval ) ch_free(c->value_bv.bv_val);
4130 /* FIXME: this ought to be provided by libldap */
4132 config_tls_config(ConfigArgs *c) {
4135 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
4136 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
4137 case CFG_TLS_PROTOCOL_MIN: flag = LDAP_OPT_X_TLS_PROTOCOL_MIN; break;
4139 Debug(LDAP_DEBUG_ANY, "%s: "
4140 "unknown tls_option <0x%x>\n",
4141 c->log, c->type, 0);
4144 if (c->op == SLAP_CONFIG_EMIT) {
4145 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
4146 } else if ( c->op == LDAP_MOD_DELETE ) {
4148 c->cleanup = config_tls_cleanup;
4149 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
4151 ch_free( c->value_string );
4152 c->cleanup = config_tls_cleanup;
4153 if ( isdigit( (unsigned char)c->argv[1][0] ) && c->type != CFG_TLS_PROTOCOL_MIN ) {
4154 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
4155 Debug(LDAP_DEBUG_ANY, "%s: "
4156 "unable to parse %s \"%s\"\n",
4157 c->log, c->argv[0], c->argv[1] );
4160 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
4162 return(ldap_pvt_tls_config(slap_tls_ld, flag, c->argv[1]));
4167 static CfEntryInfo *
4168 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
4178 if ( dn_match( &root->ce_entry->e_nname, dn ))
4181 c = dn->bv_val+dn->bv_len;
4182 for (;*c != ',';c--);
4186 for (--c;c>dn->bv_val && *c != ',';c--);
4190 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
4192 root = root->ce_kids;
4194 for (;root;root=root->ce_sibs) {
4195 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
4196 if ( cdn.bv_val == dn->bv_val ) {
4206 typedef struct setup_cookie {
4216 config_ldif_resp( Operation *op, SlapReply *rs )
4218 if ( rs->sr_type == REP_SEARCH ) {
4219 setup_cookie *sc = op->o_callback->sc_private;
4222 sc->cfb->cb_got_ldif = 1;
4223 /* Does the frontend exist? */
4224 if ( !sc->got_frontend ) {
4225 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
4226 "olcDatabase", STRLENOF( "olcDatabase" )))
4228 if ( strncmp( rs->sr_entry->e_nname.bv_val +
4229 STRLENOF( "olcDatabase" ), "={-1}frontend",
4230 STRLENOF( "={-1}frontend" )))
4234 sc->ca->be = frontendDB;
4235 sc->ca->bi = frontendDB->bd_info;
4236 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
4237 rdn.bv_val = sc->ca->log;
4238 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
4239 "%s=" SLAP_X_ORDERED_FMT "%s",
4240 cfAd_database->ad_cname.bv_val, -1,
4241 sc->ca->bi->bi_type);
4243 sc->frontend = config_build_entry( op, rs,
4244 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
4245 sc->ca->be->be_cf_ocs );
4255 dnParent( &rs->sr_entry->e_nname, &pdn );
4257 /* Does the configDB exist? */
4258 if ( sc->got_frontend && !sc->got_config &&
4259 !strncmp( rs->sr_entry->e_nname.bv_val,
4260 "olcDatabase", STRLENOF( "olcDatabase" )) &&
4261 dn_match( &config_rdn, &pdn ) )
4263 if ( strncmp( rs->sr_entry->e_nname.bv_val +
4264 STRLENOF( "olcDatabase" ), "={0}config",
4265 STRLENOF( "={0}config" )))
4269 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
4270 sc->ca->bi = sc->ca->be->bd_info;
4271 rdn.bv_val = sc->ca->log;
4272 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
4273 "%s=" SLAP_X_ORDERED_FMT "%s",
4274 cfAd_database->ad_cname.bv_val, 0,
4275 sc->ca->bi->bi_type);
4277 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
4278 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
4285 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
4286 if ( rs->sr_err != LDAP_SUCCESS ) {
4287 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
4288 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg, 0 );
4294 /* Configure and read the underlying back-ldif store */
4296 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
4297 CfBackInfo *cfb = be->be_private;
4303 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
4304 Connection conn = {0};
4305 OperationBuffer opbuf;
4307 SlapReply rs = {REP_RESULT};
4308 Filter filter = { LDAP_FILTER_PRESENT };
4309 struct berval filterstr = BER_BVC("(objectclass=*)");
4312 /* Is the config directory available? */
4313 if ( stat( dir, &st ) < 0 ) {
4314 /* No, so don't bother using the backing store.
4315 * All changes will be in-memory only.
4320 cfb->cb_db.bd_info = backend_info( "ldif" );
4321 if ( !cfb->cb_db.bd_info )
4322 return 0; /* FIXME: eventually this will be a fatal error */
4324 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
4327 cfb->cb_db.be_suffix = be->be_suffix;
4328 cfb->cb_db.be_nsuffix = be->be_nsuffix;
4330 /* The suffix is always "cn=config". The underlying DB's rootdn
4331 * is always the same as the suffix.
4333 cfb->cb_db.be_rootdn = be->be_suffix[0];
4334 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
4336 ber_str2bv( dir, 0, 1, &cfdir );
4341 argv[0] = "directory";
4342 argv[1] = (char *)dir;
4347 c.table = Cft_Database;
4349 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
4353 if ( config_add_vals( ct, &c ))
4356 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
4360 void *thrctx = ldap_pvt_thread_pool_context();
4363 connection_fake_init( &conn, &opbuf, thrctx );
4366 filter.f_desc = slap_schema.si_ad_objectClass;
4368 op->o_tag = LDAP_REQ_SEARCH;
4370 op->ors_filter = &filter;
4371 op->ors_filterstr = filterstr;
4372 op->ors_scope = LDAP_SCOPE_SUBTREE;
4374 op->o_dn = c.be->be_rootdn;
4375 op->o_ndn = c.be->be_rootndn;
4377 op->o_req_dn = be->be_suffix[0];
4378 op->o_req_ndn = be->be_nsuffix[0];
4380 op->ors_tlimit = SLAP_NO_LIMIT;
4381 op->ors_slimit = SLAP_NO_LIMIT;
4383 op->ors_attrs = slap_anlist_all_attributes;
4384 op->ors_attrsonly = 0;
4386 op->o_callback = &cb;
4389 cb.sc_private = ≻
4390 sc.got_frontend = 0;
4395 op->o_bd = &cfb->cb_db;
4397 /* Allow unknown attrs in DNs */
4398 prev_DN_strict = slap_DN_strict;
4401 rc = op->o_bd->be_search( op, &rs );
4403 /* Restore normal DN validation */
4404 slap_DN_strict = prev_DN_strict;
4406 op->o_tag = LDAP_REQ_ADD;
4407 if ( rc == LDAP_SUCCESS && sc.frontend ) {
4408 rs_reinit( &rs, REP_RESULT );
4409 op->ora_e = sc.frontend;
4410 rc = op->o_bd->be_add( op, &rs );
4412 if ( rc == LDAP_SUCCESS && sc.config ) {
4413 rs_reinit( &rs, REP_RESULT );
4414 op->ora_e = sc.config;
4415 rc = op->o_bd->be_add( op, &rs );
4417 ldap_pvt_thread_pool_context_reset( thrctx );
4420 /* ITS#4194 - only use if it's present, or we're converting. */
4421 if ( !readit || rc == LDAP_SUCCESS )
4422 cfb->cb_use_ldif = 1;
4428 CfOc_cmp( const void *c1, const void *c2 ) {
4429 const ConfigOCs *co1 = c1;
4430 const ConfigOCs *co2 = c2;
4432 return ber_bvcmp( co1->co_name, co2->co_name );
4436 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
4439 i = init_config_attrs( ct );
4442 /* set up the objectclasses */
4443 i = init_config_ocs( ocs );
4446 for (i=0; ocs[i].co_def; i++) {
4447 if ( ocs[i].co_oc ) {
4448 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
4449 if ( !ocs[i].co_table )
4450 ocs[i].co_table = ct;
4451 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
4458 read_config(const char *fname, const char *dir) {
4461 const char *cfdir, *cfname;
4464 /* Setup the config backend */
4465 be = backend_db_init( "config", NULL, 0, NULL );
4469 cfb = be->be_private;
4470 be->be_dfltaccess = ACL_NONE;
4472 /* If no .conf, or a dir was specified, setup the dir */
4473 if ( !fname || dir ) {
4475 /* If explicitly given, check for existence */
4478 if ( stat( dir, &st ) < 0 ) {
4479 Debug( LDAP_DEBUG_ANY,
4480 "invalid config directory %s, error %d\n",
4486 cfdir = SLAPD_DEFAULT_CONFIGDIR;
4488 /* if fname is defaulted, try reading .d */
4489 rc = config_setup_ldif( be, cfdir, !fname );
4492 /* It may be OK if the base object doesn't exist yet. */
4493 if ( rc != LDAP_NO_SUCH_OBJECT )
4495 /* ITS#4194: But if dir was specified and no fname,
4496 * then we were supposed to read the dir. Unless we're
4497 * trying to slapadd the dir...
4499 if ( dir && !fname ) {
4500 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
4502 /* Assume it's slapadd with a config dir, let it continue */
4504 cfb->cb_got_ldif = 1;
4505 cfb->cb_use_ldif = 1;
4510 /* If we read the config from back-ldif, nothing to do here */
4511 if ( cfb->cb_got_ldif ) {
4520 cfname = SLAPD_DEFAULT_CONFIGFILE;
4522 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
4525 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
4528 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
4529 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
4530 &frontendDB->be_schemadn );
4531 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
4532 if ( rc != LDAP_SUCCESS ) {
4533 Debug(LDAP_DEBUG_ANY, "read_config: "
4534 "unable to normalize default schema DN \"%s\"\n",
4535 frontendDB->be_schemadn.bv_val, 0, 0 );
4536 /* must not happen */
4540 if ( rc == 0 && ( slapMode & SLAP_SERVER_MODE ) && sid_list ) {
4541 if ( !BER_BVISEMPTY( &sid_list->si_url ) && !sid_set ) {
4542 Debug(LDAP_DEBUG_ANY, "read_config: no serverID / URL match found. "
4543 "Check slapd -h arguments.\n", 0,0,0 );
4551 config_back_bind( Operation *op, SlapReply *rs )
4553 if ( be_isroot_pw( op ) ) {
4554 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
4555 /* frontend sends result */
4556 return LDAP_SUCCESS;
4559 rs->sr_err = LDAP_INVALID_CREDENTIALS;
4560 send_ldap_result( op, rs );
4566 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
4570 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
4572 rs->sr_attrs = op->ors_attrs;
4573 rs->sr_entry = ce->ce_entry;
4575 rc = send_search_entry( op, rs );
4576 if ( rc != LDAP_SUCCESS ) {
4580 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
4581 if ( ce->ce_kids ) {
4582 rc = config_send( op, rs, ce->ce_kids, 1 );
4583 if ( rc ) return rc;
4586 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
4587 rc = config_send( op, rs, ce, 0 );
4595 static ConfigTable *
4596 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
4600 if (ad->ad_flags & SLAP_DESC_BINARY)
4601 ad = ad->ad_type->sat_ad;
4603 for (j=0; j<nocs; j++) {
4604 for (i=0; colst[j]->co_table[i].name; i++)
4605 if ( colst[j]->co_table[i].ad == ad ) {
4606 ca->table = colst[j]->co_type;
4607 return &colst[j]->co_table[i];
4613 /* Sort the attributes of the entry according to the order defined
4614 * in the objectclass, with required attributes occurring before
4615 * allowed attributes. For any attributes with sequencing dependencies
4616 * (e.g., rootDN must be defined after suffix) the objectclass must
4617 * list the attributes in the desired sequence.
4620 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
4622 Attribute *a, *head = NULL, *tail = NULL, **prev;
4625 for (i=0; i<nocs; i++) {
4626 if ( colst[i]->co_oc->soc_required ) {
4627 AttributeType **at = colst[i]->co_oc->soc_required;
4628 for (j=0; at[j]; j++) {
4629 for (a=e->e_attrs, prev=&e->e_attrs; a;
4630 prev = &(*prev)->a_next, a=a->a_next) {
4631 if ( a->a_desc == at[j]->sat_ad ) {
4645 if ( colst[i]->co_oc->soc_allowed ) {
4646 AttributeType **at = colst[i]->co_oc->soc_allowed;
4647 for (j=0; at[j]; j++) {
4648 for (a=e->e_attrs, prev=&e->e_attrs; a;
4649 prev = &(*prev)->a_next, a=a->a_next) {
4650 if ( a->a_desc == at[j]->sat_ad ) {
4666 tail->a_next = e->e_attrs;
4672 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
4674 Attribute *a = NULL;
4675 AttributeDescription *ad;
4685 Modifications *ml = ptr;
4687 vals = ml->sml_values;
4690 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
4691 rc = ordered_value_sort( a, 1 );
4693 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
4694 ad->ad_cname.bv_val );
4698 for ( i=0; vals[i].bv_val; i++ ) {
4699 ca->line = vals[i].bv_val;
4700 ca->linelen = vals[i].bv_len;
4701 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
4702 ca->line[0] == '{' ) {
4703 char *idx = strchr( ca->line, '}' );
4705 ca->linelen -= (idx+1) - ca->line;
4709 rc = config_parse_vals( ct, ca, i );
4718 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
4721 struct berval rtype, rval;
4723 AttributeDescription *ad = NULL;
4725 dnRdn( &e->e_name, rdn );
4726 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
4727 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
4728 rtype.bv_val = rdn->bv_val;
4729 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
4732 slap_bv2ad( &rtype, &ad, &rs->sr_text );
4733 a = attr_find( e->e_attrs, ad );
4734 if (!a ) return LDAP_NAMING_VIOLATION;
4741 config_rename_kids( CfEntryInfo *ce )
4744 struct berval rdn, nrdn;
4746 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
4747 struct berval newdn, newndn;
4748 dnRdn ( &ce2->ce_entry->e_name, &rdn );
4749 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
4750 build_new_dn( &newdn, &ce->ce_entry->e_name, &rdn, NULL );
4751 build_new_dn( &newndn, &ce->ce_entry->e_nname, &nrdn, NULL );
4752 free( ce2->ce_entry->e_name.bv_val );
4753 free( ce2->ce_entry->e_nname.bv_val );
4754 ce2->ce_entry->e_name = newdn;
4755 ce2->ce_entry->e_nname = newndn;
4756 config_rename_kids( ce2 );
4761 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
4762 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
4763 struct berval *nnewrdn, int use_ldif )
4767 struct berval odn, ondn;
4768 const char *text = "";
4773 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
4774 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
4777 rc = ldap_bv2rdn( &e->e_name, &rDN, (char **)&text, LDAP_DN_FORMAT_LDAP );
4781 for ( cnt = 0; rDN[cnt]; cnt++ ) {
4782 AttributeDescription *ad = NULL;
4783 LDAPAVA *ava = rDN[cnt];
4785 rc = slap_bv2ad( &ava->la_attr, &ad, &text );
4790 if ( ad != a->a_desc ) continue;
4792 free( a->a_vals[0].bv_val );
4793 ber_dupbv( &a->a_vals[0], &ava->la_value );
4794 if ( a->a_nvals != a->a_vals ) {
4795 free( a->a_nvals[0].bv_val );
4796 rc = attr_normalize_one( ad, &ava->la_value, &a->a_nvals[0], NULL );
4802 /* attributes with X-ORDERED 'SIBLINGS' are single-valued, we're done */
4805 /* the attribute must be present in rDN */
4807 ldap_rdnfree( rDN );
4813 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
4814 BackendDB *be = op->o_bd;
4815 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4816 struct berval dn, ndn, xdn, xndn;
4818 op->o_bd = &cfb->cb_db;
4820 /* Save current rootdn; use the underlying DB's rootdn */
4824 xndn = op->o_req_ndn;
4825 op->o_dn = op->o_bd->be_rootdn;
4826 op->o_ndn = op->o_bd->be_rootndn;
4828 op->o_req_ndn = ondn;
4830 scp = op->o_callback;
4831 op->o_callback = ≻
4832 op->orr_newrdn = *newrdn;
4833 op->orr_nnewrdn = *nnewrdn;
4834 op->orr_newSup = NULL;
4835 op->orr_nnewSup = NULL;
4836 op->orr_deleteoldrdn = 1;
4837 op->orr_modlist = NULL;
4838 slap_modrdn2mods( op, rs );
4839 slap_mods_opattrs( op, &op->orr_modlist, 1 );
4840 rc = op->o_bd->be_modrdn( op, rs );
4841 slap_mods_free( op->orr_modlist, 1 );
4844 op->o_callback = scp;
4848 op->o_req_ndn = xndn;
4851 free( ondn.bv_val );
4853 config_rename_kids( e->e_private );
4858 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
4859 Entry *e, int idx, int tailindex, int use_ldif )
4861 struct berval ival, newrdn, nnewrdn;
4864 char ibuf[32], *ptr1, *ptr2 = NULL;
4867 rc = config_rename_attr( rs, e, &rdn, &a );
4868 if ( rc ) return rc;
4871 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
4872 if ( ival.bv_len >= sizeof( ibuf ) ) {
4873 return LDAP_NAMING_VIOLATION;
4876 newrdn.bv_len = rdn.bv_len + ival.bv_len;
4877 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
4880 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
4881 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4884 ptr2 = ber_bvchr( &rdn, '}' );
4888 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
4890 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
4891 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
4892 a->a_desc->ad_cname.bv_len );
4894 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4895 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
4899 /* Do the equivalent of ModRDN */
4900 /* Replace DN / NDN */
4901 newrdn.bv_len = ptr1 - newrdn.bv_val;
4902 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
4903 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
4905 free( nnewrdn.bv_val );
4906 free( newrdn.bv_val );
4911 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
4912 SlapReply *rs, int *renum, int *ibase )
4915 int index = -1, gotindex = 0, nsibs, rc = 0;
4916 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
4917 char *ptr1, *ptr2 = NULL;
4920 if ( renum ) *renum = 0;
4922 /* These entries don't get indexed/renumbered */
4923 if ( ce_type == Cft_Global ) return 0;
4924 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
4926 if ( ce_type == Cft_Module )
4929 /* See if the rdn has an index already */
4930 dnRdn( &e->e_name, &rdn );
4931 if ( ce_type == Cft_Database ) {
4932 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
4933 "frontend", STRLENOF("frontend") ))
4935 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
4936 "config", STRLENOF("config") ))
4939 ptr1 = ber_bvchr( &e->e_name, '{' );
4940 if ( ptr1 && ptr1 < &e->e_name.bv_val[ rdn.bv_len ] ) {
4942 ptr2 = strchr( ptr1, '}' );
4943 if ( !ptr2 || ptr2 > &e->e_name.bv_val[ rdn.bv_len ] )
4944 return LDAP_NAMING_VIOLATION;
4945 if ( ptr2-ptr1 == 1)
4946 return LDAP_NAMING_VIOLATION;
4948 index = strtol( ptr1 + 1, &next, 10 );
4949 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
4950 return LDAP_NAMING_VIOLATION;
4953 /* Special case, we allow -1 for the frontendDB */
4954 if ( index != -1 || !isfrontend )
4955 return LDAP_NAMING_VIOLATION;
4957 if ( isconfig && index != 0 ){
4958 return LDAP_NAMING_VIOLATION;
4962 /* count related kids.
4963 * For entries of type Cft_Misc, only count siblings with same RDN type
4965 if ( ce_type == Cft_Misc ) {
4966 rdn.bv_val = e->e_nname.bv_val;
4967 ptr1 = strchr( rdn.bv_val, '=' );
4968 assert( ptr1 != NULL );
4970 rdn.bv_len = ptr1 - rdn.bv_val;
4972 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
4974 if ( ce->ce_type != ce_type )
4977 dnRdn( &ce->ce_entry->e_nname, &rdn2 );
4979 ptr1 = strchr( rdn2.bv_val, '=' );
4980 assert( ptr1 != NULL );
4982 rdn2.bv_len = ptr1 - rdn2.bv_val;
4983 if ( bvmatch( &rdn, &rdn2 ))
4987 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
4988 if ( ce->ce_type == ce_type ) nsibs++;
4992 /* account for -1 frontend */
4993 if ( ce_type == Cft_Database )
4996 if ( index != nsibs || isfrontend ) {
4998 if ( index < nsibs ) {
4999 if ( tailindex ) return LDAP_NAMING_VIOLATION;
5000 /* Siblings need to be renumbered */
5001 if ( index != -1 || !isfrontend )
5005 /* config DB is always "0" */
5006 if ( isconfig && index == -1 ) {
5009 if (( !isfrontend && index == -1 ) || ( index > nsibs ) ){
5013 /* just make index = nsibs */
5015 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
5018 if ( ibase ) *ibase = index;
5019 if ( renum ) *renum = renumber;
5023 /* Insert all superior classes of the given class */
5025 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
5030 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
5031 if ( count_oc( *sups, copp, nocs ) ) {
5036 co.co_name = &oc->soc_cname;
5037 cop = avl_find( CfOcTree, &co, CfOc_cmp );
5041 /* check for duplicates */
5042 for ( i = 0; i < *nocs; i++ ) {
5043 if ( *copp && (*copp)[i] == cop ) {
5049 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
5050 if ( tmp == NULL ) {
5054 (*copp)[*nocs] = cop;
5062 /* Find all superior classes of the given objectclasses,
5063 * return list in order of most-subordinate first.
5065 * Special / auxiliary / Cft_Misc classes always take precedence.
5068 count_ocs( Attribute *oc_at, int *nocs )
5070 int i, j, misc = -1;
5071 ConfigOCs **colst = NULL;
5075 for ( i = oc_at->a_numvals; i--; ) {
5076 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
5078 assert( oc != NULL );
5079 if ( count_oc( oc, &colst, nocs ) ) {
5089 ConfigOCs *tmp = colst[i];
5090 colst[i] = colst[j];
5092 if (tmp->co_type == Cft_Misc)
5096 /* Move misc class to front of list */
5098 ConfigOCs *tmp = colst[misc];
5099 for (i=misc; i>0; i--)
5100 colst[i] = colst[i-1];
5108 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
5110 /* Leftover from RE23. Never parse this entry */
5111 return LDAP_COMPARE_TRUE;
5115 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
5119 /* This entry is hardcoded, don't re-parse it */
5120 if ( p->ce_type == Cft_Global ) {
5121 cfn = p->ce_private;
5122 ca->ca_private = cfn;
5123 return LDAP_COMPARE_TRUE;
5125 if ( p->ce_type != Cft_Schema )
5126 return LDAP_CONSTRAINT_VIOLATION;
5128 cfn = ch_calloc( 1, sizeof(ConfigFile) );
5129 ca->ca_private = cfn;
5130 cfo = p->ce_private;
5131 cfn->c_sibs = cfo->c_kids;
5133 return LDAP_SUCCESS;
5137 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
5139 if ( p->ce_type != Cft_Global ) {
5140 return LDAP_CONSTRAINT_VIOLATION;
5142 /* config must be {0}, nothing else allowed */
5143 if ( !strncmp( e->e_nname.bv_val, "olcDatabase={0}", STRLENOF("olcDatabase={0}")) &&
5144 strncmp( e->e_nname.bv_val + STRLENOF("olcDatabase={0}"), "config,", STRLENOF("config,") )) {
5145 return LDAP_CONSTRAINT_VIOLATION;
5147 ca->be = frontendDB; /* just to get past check_vals */
5148 return LDAP_SUCCESS;
5152 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
5154 if ( p->ce_type != Cft_Global ) {
5155 return LDAP_CONSTRAINT_VIOLATION;
5157 return LDAP_SUCCESS;
5161 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
5163 if ( p->ce_type != Cft_Global ) {
5164 return LDAP_CONSTRAINT_VIOLATION;
5166 return LDAP_SUCCESS;
5170 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
5172 if ( p->ce_type != Cft_Database ) {
5173 return LDAP_CONSTRAINT_VIOLATION;
5176 return LDAP_SUCCESS;
5180 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
5185 AttributeDescription *ad;
5191 if ( cfn->c_cr_head ) {
5192 struct berval bv = BER_BVC("olcDitContentRules");
5194 slap_bv2ad( &bv, &ad, &text );
5195 ct = config_find_table( colst, nocs, ad, ca );
5196 config_del_vals( ct, ca );
5198 if ( cfn->c_oc_head ) {
5199 struct berval bv = BER_BVC("olcObjectClasses");
5201 slap_bv2ad( &bv, &ad, &text );
5202 ct = config_find_table( colst, nocs, ad, ca );
5203 config_del_vals( ct, ca );
5205 if ( cfn->c_at_head ) {
5206 struct berval bv = BER_BVC("olcAttributeTypes");
5208 slap_bv2ad( &bv, &ad, &text );
5209 ct = config_find_table( colst, nocs, ad, ca );
5210 config_del_vals( ct, ca );
5212 if ( cfn->c_syn_head ) {
5213 struct berval bv = BER_BVC("olcLdapSyntaxes");
5215 slap_bv2ad( &bv, &ad, &text );
5216 ct = config_find_table( colst, nocs, ad, ca );
5217 config_del_vals( ct, ca );
5219 if ( cfn->c_om_head ) {
5220 struct berval bv = BER_BVC("olcObjectIdentifier");
5222 slap_bv2ad( &bv, &ad, &text );
5223 ct = config_find_table( colst, nocs, ad, ca );
5224 config_del_vals( ct, ca );
5226 cfo = p->ce_private;
5227 cfo->c_kids = cfn->c_sibs;
5232 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
5234 int rc = LDAP_CONSTRAINT_VIOLATION;
5237 if ( (*cop)->co_ldadd ) {
5238 rc = (*cop)->co_ldadd( last, e, ca );
5239 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
5244 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
5245 ConfigOCs co = { 0 };
5247 co.co_name = &(*ocp)->soc_cname;
5248 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
5249 if ( *cop == NULL ) {
5253 rc = config_add_oc( cop, last, e, ca );
5254 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
5262 /* Parse an LDAP entry into config directives */
5264 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
5265 int *renum, Operation *op )
5267 CfEntryInfo *ce, *last = NULL;
5268 ConfigOCs co, *coptr, **colst;
5269 Attribute *a, *oc_at, *soc_at;
5270 int i, ibase = -1, nocs, rc = 0;
5273 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
5275 memset( ca, 0, sizeof(ConfigArgs));
5277 /* Make sure parent exists and entry does not. But allow
5278 * Databases and Overlays to be inserted. Don't do any
5279 * auto-renumbering if manageDSAit control is present.
5281 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
5283 if ( ( op && op->o_managedsait ) ||
5284 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
5285 ce->ce_type != Cft_Module ) )
5287 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5288 "DN=\"%s\" already exists\n",
5289 log_prefix, e->e_name.bv_val, 0 );
5290 /* global schema ignores all writes */
5291 if ( ce->ce_type == Cft_Schema && ce->ce_parent->ce_type == Cft_Global )
5292 return LDAP_COMPARE_TRUE;
5293 return LDAP_ALREADY_EXISTS;
5297 dnParent( &e->e_nname, &pdn );
5299 /* If last is NULL, the new entry is the root/suffix entry,
5300 * otherwise last should be the parent.
5302 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
5304 rs->sr_matched = last->ce_entry->e_name.bv_val;
5306 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5307 "DN=\"%s\" not child of DN=\"%s\"\n",
5308 log_prefix, e->e_name.bv_val,
5309 last->ce_entry->e_name.bv_val );
5310 return LDAP_NO_SUCH_OBJECT;
5314 /* No parent, must be root. This will never happen... */
5315 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
5316 return LDAP_NO_SUCH_OBJECT;
5319 if ( last && !access_allowed( op, last->ce_entry,
5320 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
5322 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5323 "DN=\"%s\" no write access to \"children\" of parent\n",
5324 log_prefix, e->e_name.bv_val, 0 );
5325 return LDAP_INSUFFICIENT_ACCESS;
5329 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5331 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5332 "DN=\"%s\" no objectClass\n",
5333 log_prefix, e->e_name.bv_val, 0 );
5334 return LDAP_OBJECT_CLASS_VIOLATION;
5337 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
5339 ObjectClass *soc = NULL;
5340 char textbuf[ SLAP_TEXT_BUFLEN ];
5341 const char *text = textbuf;
5343 /* FIXME: check result */
5344 rc = structural_class( oc_at->a_nvals, &soc, NULL,
5345 &text, textbuf, sizeof(textbuf), NULL );
5346 if ( rc != LDAP_SUCCESS ) {
5347 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5348 "DN=\"%s\" no structural objectClass (%s)\n",
5349 log_prefix, e->e_name.bv_val, text );
5352 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
5353 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
5354 if ( soc_at == NULL ) {
5355 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5356 "DN=\"%s\" no structural objectClass; "
5357 "unable to merge computed class %s\n",
5358 log_prefix, e->e_name.bv_val,
5359 soc->soc_cname.bv_val );
5360 return LDAP_OBJECT_CLASS_VIOLATION;
5363 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5364 "DN=\"%s\" no structural objectClass; "
5365 "computed objectClass %s merged\n",
5366 log_prefix, e->e_name.bv_val,
5367 soc->soc_cname.bv_val );
5370 /* Fake the coordinates based on whether we're part of an
5371 * LDAP Add or if reading the config dir
5374 ca->fname = "slapd";
5377 ca->fname = cfdir.bv_val;
5382 co.co_name = &soc_at->a_nvals[0];
5383 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
5384 if ( coptr == NULL ) {
5385 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5386 "DN=\"%s\" no structural objectClass in configuration table\n",
5387 log_prefix, e->e_name.bv_val, 0 );
5388 return LDAP_OBJECT_CLASS_VIOLATION;
5391 /* Only the root can be Cft_Global, everything else must
5392 * have a parent. Only limited nesting arrangements are allowed.
5394 rc = LDAP_CONSTRAINT_VIOLATION;
5395 if ( coptr->co_type == Cft_Global && !last ) {
5396 cfn = cfb->cb_config;
5397 ca->ca_private = cfn;
5398 ca->be = frontendDB; /* just to get past check_vals */
5402 colst = count_ocs( oc_at, &nocs );
5404 /* Check whether the Add is allowed by its parent, and do
5405 * any necessary arg setup
5408 rc = config_add_oc( &coptr, last, e, ca );
5409 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
5410 for ( i = 0; i<nocs; i++ ) {
5411 /* Already checked these */
5412 if ( colst[i]->co_oc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
5414 if ( colst[i]->co_ldadd &&
5415 ( rc = colst[i]->co_ldadd( last, e, ca ))
5416 != LDAP_CONSTRAINT_VIOLATION ) {
5422 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
5423 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5424 "DN=\"%s\" no structural objectClass add function\n",
5425 log_prefix, e->e_name.bv_val, 0 );
5426 return LDAP_OBJECT_CLASS_VIOLATION;
5430 /* Add the entry but don't parse it, we already have its contents */
5431 if ( rc == LDAP_COMPARE_TRUE ) {
5436 if ( rc != LDAP_SUCCESS )
5439 /* Parse all the values and check for simple syntax errors before
5440 * performing any set actions.
5442 * If doing an LDAPadd, check for indexed names and any necessary
5443 * renaming/renumbering. Entries that don't need indexed names are
5444 * ignored. Entries that need an indexed name and arrive without one
5445 * are assigned to the end. Entries that arrive with an index may
5446 * cause the following entries to be renumbered/bumped down.
5448 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
5449 * don't allow Adding an entry with an index that's already in use.
5450 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
5452 * These entries can have auto-assigned indexes (appended to the end)
5453 * but only the other types support auto-renumbering of siblings.
5456 rc = check_name_index( last, coptr->co_type, e, rs, renum,
5461 if ( renum && *renum && coptr->co_type != Cft_Database &&
5462 coptr->co_type != Cft_Overlay )
5464 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
5465 "operation requires sibling renumbering" );
5466 rc = LDAP_UNWILLING_TO_PERFORM;
5471 init_config_argv( ca );
5473 /* Make sure we process attrs in the required order */
5474 sort_attrs( e, colst, nocs );
5476 for ( a = e->e_attrs; a; a = a->a_next ) {
5477 if ( a == oc_at ) continue;
5478 ct = config_find_table( colst, nocs, a->a_desc, ca );
5479 if ( !ct ) continue; /* user data? */
5480 rc = check_vals( ct, ca, a, 1 );
5481 if ( rc ) goto done_noop;
5484 /* Basic syntax checks are OK. Do the actual settings. */
5485 for ( a=e->e_attrs; a; a=a->a_next ) {
5486 if ( a == oc_at ) continue;
5487 ct = config_find_table( colst, nocs, a->a_desc, ca );
5488 if ( !ct ) continue; /* user data? */
5489 for (i=0; a->a_vals[i].bv_val; i++) {
5492 ca->line = a->a_vals[i].bv_val;
5493 ca->linelen = a->a_vals[i].bv_len;
5494 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
5495 ptr = strchr( ca->line, '}' );
5497 iptr = strchr( ca->line, '{' );
5498 ca->linelen -= (ptr+1) - ca->line;
5502 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
5504 ca->valx = strtol( iptr+1, NULL, 0 );
5509 rc = config_parse_add( ct, ca, i );
5517 /* Newly added databases and overlays need to be started up */
5518 if ( CONFIG_ONLINE_ADD( ca )) {
5519 if ( coptr->co_type == Cft_Database ) {
5520 rc = backend_startup_one( ca->be, &ca->reply );
5522 } else if ( coptr->co_type == Cft_Overlay ) {
5523 if ( ca->bi->bi_db_open ) {
5524 BackendInfo *bi_orig = ca->be->bd_info;
5525 ca->be->bd_info = ca->bi;
5526 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
5527 ca->be->bd_info = bi_orig;
5529 } else if ( ca->cleanup ) {
5530 rc = ca->cleanup( ca );
5533 if (ca->cr_msg[0] == '\0')
5534 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
5536 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
5537 ca->log, ca->cr_msg, ca->argv[1] );
5544 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5545 ce->ce_parent = last;
5546 ce->ce_entry = entry_dup( e );
5547 ce->ce_entry->e_private = ce;
5548 ce->ce_type = coptr->co_type;
5551 ce->ce_private = ca->ca_private;
5552 ca->ca_entry = ce->ce_entry;
5555 } else if ( last->ce_kids ) {
5556 CfEntryInfo *c2, **cprev;
5558 /* Advance to first of this type */
5559 cprev = &last->ce_kids;
5560 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
5561 cprev = &c2->ce_sibs;
5564 /* Account for the (-1) frontendDB entry */
5565 if ( ce->ce_type == Cft_Database ) {
5566 if ( ca->be == frontendDB )
5568 else if ( ibase != -1 )
5573 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
5574 cprev = &c2->ce_sibs;
5580 for ( i=0; i<ibase; i++ ) {
5582 cprev = &c2->ce_sibs;
5585 ce->ce_sibs = *cprev;
5593 if ( (coptr->co_type == Cft_Database) && ca->be ) {
5594 if ( ca->be != frontendDB )
5595 backend_destroy_one( ca->be, 1 );
5596 } else if ( (coptr->co_type == Cft_Overlay) && ca->bi ) {
5597 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
5598 } else if ( coptr->co_type == Cft_Schema ) {
5599 schema_destroy_one( ca, colst, nocs, last );
5604 ch_free( ca->argv );
5605 if ( colst ) ch_free( colst );
5609 #define BIGTMP 10000
5611 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5612 int base, int rebase, int max, int use_ldif )
5614 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
5615 ConfigType etype = ce->ce_type;
5616 int count = 0, rc = 0;
5618 /* Reverse ce list */
5619 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
5620 if (ce2->ce_type != etype) {
5625 ce2->ce_sibs = cetmp;
5628 if ( max && count >= max ) {
5634 /* Move original to a temp name until increments are done */
5636 ce->ce_entry->e_private = NULL;
5637 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5638 base+BIGTMP, 0, use_ldif );
5639 ce->ce_entry->e_private = ce;
5641 /* start incrementing */
5642 for (ce2=cetmp; ce2; ce2=ce3) {
5644 ce2->ce_sibs = cerem;
5647 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5648 count+base, 0, use_ldif );
5652 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5653 base, 0, use_ldif );
5658 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5659 CfEntryInfo *ce2, int old, int use_ldif )
5663 /* Renumber original to a temp value */
5664 ce->ce_entry->e_private = NULL;
5665 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5666 old+BIGTMP, 0, use_ldif );
5667 ce->ce_entry->e_private = ce;
5669 /* start decrementing */
5670 for (; ce2 != ce; ce2=ce2->ce_sibs) {
5671 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5672 count+old, 0, use_ldif );
5675 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5676 count+old, 0, use_ldif );
5679 /* Parse an LDAP entry into config directives, then store in underlying
5683 config_back_add( Operation *op, SlapReply *rs )
5686 int renumber, dopause = 1;
5689 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
5690 NULL, ACL_WADD, NULL )) {
5691 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5696 * Check for attribute ACL
5698 if ( !acl_check_modlist( op, op->ora_e, op->orm_modlist )) {
5699 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5700 rs->sr_text = "no write access to attribute";
5704 cfb = (CfBackInfo *)op->o_bd->be_private;
5706 /* add opattrs for syncprov */
5708 char textbuf[SLAP_TEXT_BUFLEN];
5709 size_t textlen = sizeof textbuf;
5710 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1, NULL,
5711 &rs->sr_text, textbuf, sizeof( textbuf ) );
5712 if ( rs->sr_err != LDAP_SUCCESS )
5714 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
5715 if ( rs->sr_err != LDAP_SUCCESS ) {
5716 Debug( LDAP_DEBUG_TRACE,
5717 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
5718 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
5723 if ( op->o_abandon ) {
5724 rs->sr_err = SLAPD_ABANDON;
5727 if ( ldap_pvt_thread_pool_pause( &connection_pool ) < 0 )
5731 * 1) check for existence of entry
5732 * 2) check for sibling renumbering
5733 * 3) perform internal add
5734 * 4) perform any necessary renumbering
5735 * 5) store entry in underlying database
5737 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
5738 if ( rs->sr_err != LDAP_SUCCESS ) {
5739 rs->sr_text = ca.cr_msg;
5744 CfEntryInfo *ce = ca.ca_entry->e_private;
5745 req_add_s addr = op->oq_add;
5746 op->o_tag = LDAP_REQ_MODRDN;
5747 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
5748 op->o_tag = LDAP_REQ_ADD;
5750 if ( rs->sr_err != LDAP_SUCCESS ) {
5755 if ( cfb->cb_use_ldif ) {
5756 BackendDB *be = op->o_bd;
5757 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5758 struct berval dn, ndn;
5760 op->o_bd = &cfb->cb_db;
5762 /* Save current rootdn; use the underlying DB's rootdn */
5765 op->o_dn = op->o_bd->be_rootdn;
5766 op->o_ndn = op->o_bd->be_rootndn;
5768 scp = op->o_callback;
5769 op->o_callback = ≻
5770 op->o_bd->be_add( op, rs );
5772 op->o_callback = scp;
5779 ldap_pvt_thread_pool_resume( &connection_pool );
5782 { int repl = op->o_dont_replicate;
5783 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
5784 rs->sr_text = NULL; /* Set after config_add_internal */
5785 rs->sr_err = LDAP_SUCCESS;
5786 op->o_dont_replicate = 1;
5788 send_ldap_result( op, rs );
5789 op->o_dont_replicate = repl;
5791 slap_graduate_commit_csn( op );
5795 typedef struct delrec {
5796 struct delrec *next;
5802 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
5808 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
5809 ca->line[0] == '{' )
5811 char *ptr = strchr( ca->line + 1, '}' );
5815 ca->valx = strtol( ca->line + 1, &next, 0 );
5816 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
5819 ca->linelen -= (ptr+1) - ca->line;
5823 rc = config_parse_add( ct, ca, i );
5831 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
5834 int rc = LDAP_UNWILLING_TO_PERFORM;
5836 Entry *e = ce->ce_entry;
5837 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
5842 delrec *dels = NULL, *deltail = NULL;
5844 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5845 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
5847 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5848 if (ml->sml_desc == slap_schema.si_ad_objectClass)
5852 colst = count_ocs( oc_at, &nocs );
5854 /* make sure add/del flags are clear; should always be true */
5855 for ( s = save_attrs; s; s = s->a_next ) {
5856 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
5859 e->e_attrs = attrs_dup( e->e_attrs );
5861 init_config_argv( ca );
5864 ca->ca_private = ce->ce_private;
5866 ca->fname = "slapd";
5868 strcpy( ca->log, "back-config" );
5870 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5871 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5872 switch (ml->sml_op) {
5873 case LDAP_MOD_DELETE:
5874 case LDAP_MOD_REPLACE:
5875 case SLAP_MOD_SOFTDEL:
5877 BerVarray vals = NULL, nvals = NULL;
5879 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
5881 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
5882 ml->sml_desc->ad_cname.bv_val );
5885 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5886 vals = ml->sml_values;
5887 nvals = ml->sml_nvalues;
5888 ml->sml_values = NULL;
5889 ml->sml_nvalues = NULL;
5891 /* If we're deleting by values, remember the indexes of the
5892 * values we deleted.
5894 if ( ct && ml->sml_values ) {
5896 i = ml->sml_numvals;
5897 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
5908 rc = modify_delete_vindex(e, &ml->sml_mod,
5909 get_permissiveModify(op),
5910 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
5911 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5912 ml->sml_values = vals;
5913 ml->sml_nvalues = nvals;
5915 if ( rc == LDAP_NO_SUCH_ATTRIBUTE && ml->sml_op == SLAP_MOD_SOFTDEL )
5919 /* FIXME: check rc before fallthru? */
5923 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5925 case SLAP_MOD_ADD_IF_NOT_PRESENT:
5926 if ( ml->sml_op == SLAP_MOD_ADD_IF_NOT_PRESENT
5927 && attr_find( e->e_attrs, ml->sml_desc ) )
5934 case SLAP_MOD_SOFTADD: {
5935 int mop = ml->sml_op;
5937 ml->sml_op = LDAP_MOD_ADD;
5939 if ( ct->arg_type & ARG_NO_INSERT ) {
5940 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
5942 navals = a->a_numvals;
5945 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
5946 if ( ml->sml_values[i].bv_val[0] == '{' &&
5949 char *next, *val = ml->sml_values[i].bv_val + 1;
5952 j = strtol( val, &next, 0 );
5953 if ( next == val || next[ 0 ] != '}' || j < navals ) {
5955 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
5956 ml->sml_desc->ad_cname.bv_val );
5960 rc = check_vals( ct, ca, ml, 0 );
5961 if ( rc ) goto out_noop;
5964 rc = modify_add_values(e, &ml->sml_mod,
5965 get_permissiveModify(op),
5966 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5968 /* If value already exists, show success here
5969 * and ignore this operation down below.
5971 if ( mop == SLAP_MOD_SOFTADD ) {
5972 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
5982 case LDAP_MOD_INCREMENT: /* FIXME */
5987 if(rc != LDAP_SUCCESS) break;
5990 if ( rc == LDAP_SUCCESS) {
5991 /* check that the entry still obeys the schema */
5992 rc = entry_schema_check(op, e, NULL, 0, 0, NULL,
5993 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5995 if ( rc ) goto out_noop;
5997 /* Basic syntax checks are OK. Do the actual settings. */
5998 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5999 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
6000 if ( !ct ) continue;
6002 s = attr_find( save_attrs, ml->sml_desc );
6003 a = attr_find( e->e_attrs, ml->sml_desc );
6005 switch (ml->sml_op) {
6006 case LDAP_MOD_DELETE:
6007 case LDAP_MOD_REPLACE: {
6008 BerVarray vals = NULL, nvals = NULL;
6011 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
6012 vals = ml->sml_values;
6013 nvals = ml->sml_nvalues;
6014 ml->sml_values = NULL;
6015 ml->sml_nvalues = NULL;
6018 if ( ml->sml_values )
6021 /* If we didn't delete the whole attribute */
6022 if ( ml->sml_values && a ) {
6023 struct berval *mvals;
6026 if ( ml->sml_nvalues )
6027 mvals = ml->sml_nvalues;
6029 mvals = ml->sml_values;
6031 /* use the indexes we saved up above */
6032 for (i=0; i < d->nidx; i++) {
6033 struct berval bv = *mvals++;
6034 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
6035 bv.bv_val[0] == '{' ) {
6036 ptr = strchr( bv.bv_val, '}' ) + 1;
6037 bv.bv_len -= ptr - bv.bv_val;
6040 ca->line = bv.bv_val;
6041 ca->linelen = bv.bv_len;
6042 ca->valx = d->idx[i];
6043 config_parse_vals(ct, ca, d->idx[i] );
6044 rc = config_del_vals( ct, ca );
6045 if ( rc != LDAP_SUCCESS ) break;
6047 s->a_flags |= SLAP_ATTR_IXDEL;
6048 for (j=i+1; j < d->nidx; j++)
6049 if ( d->idx[j] >d->idx[i] )
6056 rc = config_del_vals( ct, ca );
6057 if ( rc ) rc = LDAP_OTHER;
6059 s->a_flags |= SLAP_ATTR_IXDEL;
6061 if ( ml->sml_values ) {
6066 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
6067 ml->sml_values = vals;
6068 ml->sml_nvalues = nvals;
6070 if ( !vals || rc != LDAP_SUCCESS )
6073 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
6078 for (i=0; ml->sml_values[i].bv_val; i++) {
6079 ca->line = ml->sml_values[i].bv_val;
6080 ca->linelen = ml->sml_values[i].bv_len;
6082 rc = config_modify_add( ct, ca, ml->sml_desc, i );
6085 a->a_flags |= SLAP_ATTR_IXADD;
6092 /* Undo for a failed operation */
6093 if ( rc != LDAP_SUCCESS ) {
6094 ConfigReply msg = ca->reply;
6095 for ( s = save_attrs; s; s = s->a_next ) {
6096 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
6097 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
6098 ct = config_find_table( colst, nocs, s->a_desc, ca );
6099 a = attr_find( e->e_attrs, s->a_desc );
6101 /* clear the flag so the add check below will skip it */
6102 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
6106 config_del_vals( ct, ca );
6108 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
6109 ca->line = s->a_vals[i].bv_val;
6110 ca->linelen = s->a_vals[i].bv_len;
6112 config_modify_add( ct, ca, s->a_desc, i );
6116 for ( a = e->e_attrs; a; a = a->a_next ) {
6117 if ( a->a_flags & SLAP_ATTR_IXADD ) {
6118 ct = config_find_table( colst, nocs, a->a_desc, ca );
6122 config_del_vals( ct, ca );
6123 s = attr_find( save_attrs, a->a_desc );
6125 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
6126 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
6127 ca->line = s->a_vals[i].bv_val;
6128 ca->linelen = s->a_vals[i].bv_len;
6130 config_modify_add( ct, ca, s->a_desc, i );
6138 if ( ca->cleanup ) {
6139 i = ca->cleanup( ca );
6140 if (rc == LDAP_SUCCESS)
6144 if ( rc == LDAP_SUCCESS ) {
6145 attrs_free( save_attrs );
6148 attrs_free( e->e_attrs );
6149 e->e_attrs = save_attrs;
6151 ch_free( ca->argv );
6152 if ( colst ) ch_free( colst );
6154 deltail = dels->next;
6163 config_back_modify( Operation *op, SlapReply *rs )
6166 CfEntryInfo *ce, *last;
6168 ConfigArgs ca = {0};
6171 AttributeDescription *rad = NULL;
6174 cfb = (CfBackInfo *)op->o_bd->be_private;
6176 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6179 rs->sr_matched = last->ce_entry->e_name.bv_val;
6180 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6184 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
6185 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6189 /* Get type of RDN */
6190 rdn = ce->ce_entry->e_nname;
6191 ptr = strchr( rdn.bv_val, '=' );
6192 rdn.bv_len = ptr - rdn.bv_val;
6193 rs->sr_err = slap_bv2ad( &rdn, &rad, &rs->sr_text );
6194 if ( rs->sr_err != LDAP_SUCCESS ) {
6198 /* Some basic validation... */
6199 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
6200 /* Don't allow Modify of RDN; must use ModRdn for that. */
6201 if ( ml->sml_desc == rad ) {
6202 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
6203 rs->sr_text = "Use modrdn to change the entry name";
6206 /* Internal update of contextCSN? */
6207 if ( ml->sml_desc == slap_schema.si_ad_contextCSN && op->o_conn->c_conn_idx == -1 ) {
6213 slap_mods_opattrs( op, &op->orm_modlist, 1 );
6216 if ( op->o_abandon ) {
6217 rs->sr_err = SLAPD_ABANDON;
6220 if ( ldap_pvt_thread_pool_pause( &connection_pool ) < 0 )
6225 * 1) perform the Modify on the cached Entry.
6226 * 2) verify that the Entry still satisfies the schema.
6227 * 3) perform the individual config operations.
6228 * 4) store Modified entry in underlying LDIF backend.
6230 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
6232 rs->sr_text = ca.cr_msg;
6233 } else if ( cfb->cb_use_ldif ) {
6234 BackendDB *be = op->o_bd;
6235 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
6236 struct berval dn, ndn;
6238 op->o_bd = &cfb->cb_db;
6242 op->o_dn = op->o_bd->be_rootdn;
6243 op->o_ndn = op->o_bd->be_rootndn;
6245 scp = op->o_callback;
6246 op->o_callback = ≻
6247 op->o_bd->be_modify( op, rs );
6249 op->o_callback = scp;
6255 ldap_pvt_thread_pool_resume( &connection_pool );
6257 send_ldap_result( op, rs );
6258 slap_graduate_commit_csn( op );
6263 config_back_modrdn( Operation *op, SlapReply *rs )
6266 CfEntryInfo *ce, *last;
6268 int ixold, ixnew, dopause = 1;
6270 cfb = (CfBackInfo *)op->o_bd->be_private;
6272 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6275 rs->sr_matched = last->ce_entry->e_name.bv_val;
6276 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6279 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
6280 NULL, ACL_WRITE, NULL )) {
6281 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6285 if ( ce->ce_parent )
6286 parent = ce->ce_parent->ce_entry;
6288 parent = (Entry *)&slap_entry_root;
6289 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
6290 NULL, ACL_WRITE, NULL )) {
6291 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6296 /* We don't allow moving objects to new parents.
6297 * Generally we only allow reordering a set of ordered entries.
6299 if ( op->orr_newSup ) {
6300 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6304 /* If newRDN == oldRDN, quietly succeed */
6305 dnRdn( &op->o_req_ndn, &rdn );
6306 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
6307 rs->sr_err = LDAP_SUCCESS;
6311 /* Current behavior, subject to change as needed:
6313 * For backends and overlays, we only allow renumbering.
6314 * For schema, we allow renaming with the same number.
6315 * Otherwise, the op is not allowed.
6318 if ( ce->ce_type == Cft_Schema ) {
6322 /* Can't alter the main cn=schema entry */
6323 if ( ce->ce_parent->ce_type == Cft_Global ) {
6324 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6325 rs->sr_text = "renaming not allowed for this entry";
6329 /* We could support this later if desired */
6330 ptr1 = ber_bvchr( &rdn, '}' );
6331 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
6332 len = ptr1 - rdn.bv_val;
6333 if ( len != ptr2 - op->orr_newrdn.bv_val ||
6334 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
6335 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6336 rs->sr_text = "schema reordering not supported";
6339 } else if ( ce->ce_type == Cft_Database ||
6340 ce->ce_type == Cft_Overlay ) {
6341 char *ptr1, *ptr2, *iptr1, *iptr2;
6344 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
6345 if ( *iptr2 != '{' ) {
6346 rs->sr_err = LDAP_NAMING_VIOLATION;
6347 rs->sr_text = "new ordering index is required";
6351 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
6352 ptr1 = ber_bvchr( &rdn, '}' );
6353 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
6355 rs->sr_err = LDAP_NAMING_VIOLATION;
6356 rs->sr_text = "new ordering index is required";
6360 len1 = ptr1 - rdn.bv_val;
6361 len2 = ptr2 - op->orr_newrdn.bv_val;
6363 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
6364 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
6365 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6366 rs->sr_text = "changing database/overlay type not allowed";
6369 ixold = strtol( iptr1, NULL, 0 );
6370 ixnew = strtol( iptr2, &ptr1, 0 );
6371 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
6372 rs->sr_err = LDAP_NAMING_VIOLATION;
6375 /* config DB is always 0, cannot be changed */
6376 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
6377 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
6381 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6382 rs->sr_text = "renaming not supported for this entry";
6386 if ( op->o_abandon ) {
6387 rs->sr_err = SLAPD_ABANDON;
6390 if ( ldap_pvt_thread_pool_pause( &connection_pool ) < 0 )
6393 if ( ce->ce_type == Cft_Schema ) {
6394 req_modrdn_s modr = op->oq_modrdn;
6397 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
6398 if ( rs->sr_err == LDAP_SUCCESS ) {
6399 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
6400 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
6403 op->oq_modrdn = modr;
6405 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
6406 req_modrdn_s modr = op->oq_modrdn;
6409 /* Advance to first of this type */
6410 cprev = &ce->ce_parent->ce_kids;
6411 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
6412 cprev = &ce2->ce_sibs;
6415 /* Skip the -1 entry */
6416 if ( ce->ce_type == Cft_Database ) {
6417 cprev = &ce2->ce_sibs;
6423 /* Remove from old slot */
6424 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
6425 cprev = &ce2->ce_sibs;
6426 *cprev = ce->ce_sibs;
6427 ceold = ce->ce_sibs;
6429 /* Insert into new slot */
6431 for ( i=0; i<ixnew; i++ ) {
6435 cprev = &ce2->ce_sibs;
6437 ce->ce_sibs = *cprev;
6442 /* NOTE: These should be encoded in the OC tables, not inline here */
6443 if ( ce->ce_type == Cft_Database )
6444 backend_db_move( ce->ce_be, ixnew );
6445 else if ( ce->ce_type == Cft_Overlay )
6446 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
6448 if ( ixold < ixnew ) {
6449 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
6452 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
6453 ixold - ixnew, cfb->cb_use_ldif );
6455 op->oq_modrdn = modr;
6459 ldap_pvt_thread_pool_resume( &connection_pool );
6461 send_ldap_result( op, rs );
6466 config_back_delete( Operation *op, SlapReply *rs )
6468 #ifdef SLAP_CONFIG_DELETE
6470 CfEntryInfo *ce, *last, *ce2;
6473 cfb = (CfBackInfo *)op->o_bd->be_private;
6475 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6478 rs->sr_matched = last->ce_entry->e_name.bv_val;
6479 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6480 } else if ( ce->ce_kids ) {
6481 rs->sr_err = LDAP_NOT_ALLOWED_ON_NONLEAF;
6482 } else if ( op->o_abandon ) {
6483 rs->sr_err = SLAPD_ABANDON;
6484 } else if ( ce->ce_type == Cft_Overlay ||
6485 ce->ce_type == Cft_Database ||
6486 ce->ce_type == Cft_Misc ){
6490 if ( ldap_pvt_thread_pool_pause( &connection_pool ) < 0 )
6493 if ( ce->ce_type == Cft_Overlay ){
6494 overlay_remove( ce->ce_be, (slap_overinst *)ce->ce_bi, op );
6495 } else if ( ce->ce_type == Cft_Misc ) {
6497 * only Cft_Misc objects that have a co_lddel handler set in
6498 * the ConfigOCs struct can be deleted. This code also
6499 * assumes that the entry can be only have one objectclass
6500 * with co_type == Cft_Misc
6502 ConfigOCs co, *coptr;
6506 oc_at = attr_find( ce->ce_entry->e_attrs,
6507 slap_schema.si_ad_objectClass );
6509 rs->sr_err = LDAP_OTHER;
6510 rs->sr_text = "objectclass not found";
6511 if ( dopause ) ldap_pvt_thread_pool_resume( &connection_pool );
6514 for ( i=0; !BER_BVISNULL(&oc_at->a_nvals[i]); i++ ) {
6515 co.co_name = &oc_at->a_nvals[i];
6516 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
6517 if ( coptr == NULL || coptr->co_type != Cft_Misc ) {
6520 if ( ! coptr->co_lddel || coptr->co_lddel( ce, op ) ){
6521 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6522 if ( ! coptr->co_lddel ) {
6523 rs->sr_text = "No delete handler found";
6525 rs->sr_err = LDAP_OTHER;
6526 /* FIXME: We should return a helpful error message
6529 if ( dopause ) ldap_pvt_thread_pool_resume( &connection_pool );
6534 } else if (ce->ce_type == Cft_Database ) {
6535 if ( ce->ce_be == frontendDB || ce->ce_be == op->o_bd ){
6536 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6537 rs->sr_text = "Cannot delete config or frontend database";
6538 if ( dopause ) ldap_pvt_thread_pool_resume( &connection_pool );
6541 if ( ce->ce_be->bd_info->bi_db_close ) {
6542 ce->ce_be->bd_info->bi_db_close( ce->ce_be, NULL );
6544 backend_destroy_one( ce->ce_be, 1);
6547 /* remove CfEntryInfo from the siblings list */
6548 if ( ce->ce_parent->ce_kids == ce ) {
6549 ce->ce_parent->ce_kids = ce->ce_sibs;
6551 for ( ce2 = ce->ce_parent->ce_kids ; ce2; ce2 = ce2->ce_sibs ) {
6552 if ( ce2->ce_sibs == ce ) {
6553 ce2->ce_sibs = ce->ce_sibs;
6559 /* remove from underlying database */
6560 if ( cfb->cb_use_ldif ) {
6561 BackendDB *be = op->o_bd;
6562 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
6563 struct berval dn, ndn, req_dn, req_ndn;
6565 op->o_bd = &cfb->cb_db;
6569 req_dn = op->o_req_dn;
6570 req_ndn = op->o_req_ndn;
6572 op->o_dn = op->o_bd->be_rootdn;
6573 op->o_ndn = op->o_bd->be_rootndn;
6574 op->o_req_dn = ce->ce_entry->e_name;
6575 op->o_req_ndn = ce->ce_entry->e_nname;
6577 scp = op->o_callback;
6578 op->o_callback = ≻
6579 op->o_bd->be_delete( op, rs );
6581 op->o_callback = scp;
6584 op->o_req_dn = req_dn;
6585 op->o_req_ndn = req_ndn;
6588 /* renumber siblings */
6589 iptr = ber_bvchr( &op->o_req_ndn, '{' ) + 1;
6590 ixold = strtol( iptr, NULL, 0 );
6591 for (ce2 = ce->ce_sibs, count=0; ce2; ce2=ce2->ce_sibs) {
6592 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
6593 count+ixold, 0, cfb->cb_use_ldif );
6597 ce->ce_entry->e_private=NULL;
6598 entry_free(ce->ce_entry);
6600 if ( dopause ) ldap_pvt_thread_pool_resume( &connection_pool );
6602 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6606 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6607 #endif /* SLAP_CONFIG_DELETE */
6608 send_ldap_result( op, rs );
6613 config_back_search( Operation *op, SlapReply *rs )
6616 CfEntryInfo *ce, *last;
6619 cfb = (CfBackInfo *)op->o_bd->be_private;
6621 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6624 rs->sr_matched = last->ce_entry->e_name.bv_val;
6625 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6628 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
6629 ACL_SEARCH, NULL, &mask ))
6631 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
6632 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6634 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6638 switch ( op->ors_scope ) {
6639 case LDAP_SCOPE_BASE:
6640 case LDAP_SCOPE_SUBTREE:
6641 rs->sr_err = config_send( op, rs, ce, 0 );
6644 case LDAP_SCOPE_ONELEVEL:
6645 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
6646 rs->sr_err = config_send( op, rs, ce, 1 );
6655 send_ldap_result( op, rs );
6659 /* no-op, we never free entries */
6660 int config_entry_release(
6665 int rc = LDAP_SUCCESS;
6667 if ( !e->e_private ) {
6668 BackendDB *be = op->o_bd;
6669 CfBackInfo *cfb = be->be_private;
6670 BackendInfo *bi = cfb->cb_db.bd_info;
6672 if ( bi && bi->bi_entry_release_rw ) {
6673 op->o_bd = &cfb->cb_db;
6674 rc = bi->bi_entry_release_rw( op, e, rw );
6683 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
6685 int config_back_entry_get(
6689 AttributeDescription *at,
6694 CfEntryInfo *ce, *last;
6695 int rc = LDAP_NO_SUCH_OBJECT;
6697 cfb = (CfBackInfo *)op->o_bd->be_private;
6699 ce = config_find_base( cfb->cb_root, ndn, &last );
6701 *ent = ce->ce_entry;
6704 if ( oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
6705 rc = LDAP_NO_SUCH_ATTRIBUTE;
6715 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
6716 ConfigTable *ct, ConfigArgs *c )
6720 for (; at && *at; at++) {
6721 /* Skip the naming attr */
6722 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
6724 for (i=0;ct[i].name;i++) {
6725 if (ct[i].ad == (*at)->sat_ad) {
6726 rc = config_get_vals(&ct[i], c);
6727 /* NOTE: tolerate that config_get_vals()
6728 * returns success with no values */
6729 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
6730 if ( c->rvalue_nvals )
6731 rc = attr_merge(e, ct[i].ad, c->rvalue_vals,
6734 slap_syntax_validate_func *validate =
6735 ct[i].ad->ad_type->sat_syntax->ssyn_validate;
6738 for ( j=0; c->rvalue_vals[j].bv_val; j++ ) {
6739 rc = ordered_value_validate( ct[i].ad,
6740 &c->rvalue_vals[j], LDAP_MOD_ADD );
6742 Debug( LDAP_DEBUG_ANY,
6743 "config_build_attrs: error %d on %s value #%d\n",
6744 rc, ct[i].ad->ad_cname.bv_val, j );
6750 rc = attr_merge_normalize(e, ct[i].ad,
6751 c->rvalue_vals, NULL);
6753 ber_bvarray_free( c->rvalue_nvals );
6754 ber_bvarray_free( c->rvalue_vals );
6756 Debug( LDAP_DEBUG_ANY,
6757 "config_build_attrs: error %d on %s\n",
6758 rc, ct[i].ad->ad_cname.bv_val, 0 );
6769 /* currently (2010) does not access rs except possibly writing rs->sr_err */
6772 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
6773 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
6775 Entry *e = entry_alloc();
6776 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
6778 struct berval ad_name;
6779 AttributeDescription *ad = NULL;
6782 const char *text = "";
6786 CfEntryInfo *ceprev = NULL;
6789 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
6792 ce->ce_type = main->co_type;
6793 ce->ce_parent = parent;
6795 pdn = parent->ce_entry->e_nname;
6796 if ( parent->ce_kids && parent->ce_kids->ce_type <= ce->ce_type )
6797 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
6798 ceprev->ce_type <= ce->ce_type;
6799 ceprev = ceprev->ce_sibs );
6804 ce->ce_private = c->ca_private;
6808 build_new_dn( &e->e_name, &pdn, rdn, NULL );
6809 ber_dupbv( &e->e_nname, &e->e_name );
6811 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6812 main->co_name, NULL );
6814 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6815 extra->co_name, NULL );
6817 rc = ldap_bv2rdn( rdn, &rDN, (char **)&text, LDAP_DN_FORMAT_LDAP );
6821 for ( cnt = 0; rDN[cnt]; cnt++ ) {
6822 LDAPAVA *ava = rDN[cnt];
6825 rc = slap_bv2ad( &ava->la_attr, &ad, &text );
6829 if ( !ad->ad_type->sat_equality ) {
6830 rc = LDAP_CONSTRAINT_VIOLATION;
6831 text = "attribute has no equality matching rule";
6834 if ( !ad->ad_type->sat_equality->smr_match ) {
6835 rc = LDAP_CONSTRAINT_VIOLATION;
6836 text = "attribute has unsupported equality matching rule";
6839 attr_merge_normalize_one(e, ad, &ava->la_value, NULL );
6841 ldap_rdnfree( rDN );
6847 c->table = main->co_type;
6848 if ( oc->soc_required ) {
6849 rc = config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
6850 if ( rc ) goto fail;
6853 if ( oc->soc_allowed ) {
6854 rc = config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
6855 if ( rc ) goto fail;
6860 c->table = extra->co_type;
6861 if ( oc->soc_required ) {
6862 rc = config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
6863 if ( rc ) goto fail;
6866 if ( oc->soc_allowed ) {
6867 rc = config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
6868 if ( rc ) goto fail;
6872 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
6873 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
6874 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
6875 if ( rc != LDAP_SUCCESS ) {
6877 Debug( LDAP_DEBUG_ANY,
6878 "config_build_entry: build \"%s\" failed: \"%s\"\n",
6879 rdn->bv_val, text, 0);
6882 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
6885 op->ora_modlist = NULL;
6886 slap_add_opattrs( op, NULL, NULL, 0, 0 );
6887 if ( !op->o_noop ) {
6888 SlapReply rs2 = {REP_RESULT};
6889 op->o_bd->be_add( op, &rs2 );
6890 rs->sr_err = rs2.sr_err;
6891 rs_assert_done( &rs2 );
6892 if ( ( rs2.sr_err != LDAP_SUCCESS )
6893 && (rs2.sr_err != LDAP_ALREADY_EXISTS) ) {
6899 ce->ce_sibs = ceprev->ce_sibs;
6900 ceprev->ce_sibs = ce;
6901 } else if ( parent ) {
6902 ce->ce_sibs = parent->ce_kids;
6903 parent->ce_kids = ce;
6910 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
6911 Operation *op, SlapReply *rs )
6914 ConfigFile *cf = c->ca_private;
6916 struct berval bv, rdn;
6918 for (; cf; cf=cf->c_sibs, c->depth++) {
6919 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
6920 !cf->c_om_head && !cf->c_syn_head && !cf->c_kids ) continue;
6921 c->value_dn.bv_val = c->log;
6922 LUTIL_SLASHPATH( cf->c_file.bv_val );
6923 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
6928 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
6930 ptr = strchr( bv.bv_val, '.' );
6932 bv.bv_len = ptr - bv.bv_val;
6933 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
6934 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6935 /* FIXME: how can indicate error? */
6938 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
6940 c->value_dn.bv_len += bv.bv_len;
6941 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
6942 if ( rdnNormalize( 0, NULL, NULL, &c->value_dn, &rdn, NULL )) {
6943 Debug( LDAP_DEBUG_ANY,
6944 "config_build_schema_inc: invalid schema name \"%s\"\n",
6950 e = config_build_entry( op, rs, ceparent, c, &rdn,
6951 &CFOC_SCHEMA, NULL );
6952 ch_free( rdn.bv_val );
6955 } else if ( e && cf->c_kids ) {
6956 c->ca_private = cf->c_kids;
6957 config_build_schema_inc( c, e->e_private, op, rs );
6963 #ifdef SLAPD_MODULES
6966 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
6967 Operation *op, SlapReply *rs )
6972 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
6973 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
6975 c->value_dn.bv_val = c->log;
6976 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
6977 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6978 /* FIXME: how can indicate error? */
6982 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
6991 config_check_schema(Operation *op, CfBackInfo *cfb)
6993 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
6995 CfEntryInfo *ce, *last;
6998 /* If there's no root entry, we must be in the midst of converting */
6999 if ( !cfb->cb_root )
7002 /* Make sure the main schema entry exists */
7003 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
7010 /* Make sure it's up to date */
7011 if ( cf_om_tail != om_sys_tail ) {
7012 a = attr_find( e->e_attrs, cfAd_om );
7014 if ( a->a_nvals != a->a_vals )
7015 ber_bvarray_free( a->a_nvals );
7016 ber_bvarray_free( a->a_vals );
7021 oidm_unparse( &bv, NULL, NULL, 1 );
7022 attr_merge_normalize( e, cfAd_om, bv, NULL );
7023 ber_bvarray_free( bv );
7024 cf_om_tail = om_sys_tail;
7026 if ( cf_at_tail != at_sys_tail ) {
7027 a = attr_find( e->e_attrs, cfAd_attr );
7029 if ( a->a_nvals != a->a_vals )
7030 ber_bvarray_free( a->a_nvals );
7031 ber_bvarray_free( a->a_vals );
7036 at_unparse( &bv, NULL, NULL, 1 );
7037 attr_merge_normalize( e, cfAd_attr, bv, NULL );
7038 ber_bvarray_free( bv );
7039 cf_at_tail = at_sys_tail;
7041 if ( cf_oc_tail != oc_sys_tail ) {
7042 a = attr_find( e->e_attrs, cfAd_oc );
7044 if ( a->a_nvals != a->a_vals )
7045 ber_bvarray_free( a->a_nvals );
7046 ber_bvarray_free( a->a_vals );
7051 oc_unparse( &bv, NULL, NULL, 1 );
7052 attr_merge_normalize( e, cfAd_oc, bv, NULL );
7053 ber_bvarray_free( bv );
7054 cf_oc_tail = oc_sys_tail;
7056 if ( cf_syn_tail != syn_sys_tail ) {
7057 a = attr_find( e->e_attrs, cfAd_syntax );
7059 if ( a->a_nvals != a->a_vals )
7060 ber_bvarray_free( a->a_nvals );
7061 ber_bvarray_free( a->a_vals );
7066 syn_unparse( &bv, NULL, NULL, 1 );
7067 attr_merge_normalize( e, cfAd_syntax, bv, NULL );
7068 ber_bvarray_free( bv );
7069 cf_syn_tail = syn_sys_tail;
7072 SlapReply rs = {REP_RESULT};
7073 c.ca_private = NULL;
7074 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
7075 &CFOC_SCHEMA, NULL );
7080 ce->ce_private = cfb->cb_config;
7081 cf_at_tail = at_sys_tail;
7082 cf_oc_tail = oc_sys_tail;
7083 cf_om_tail = om_sys_tail;
7084 cf_syn_tail = syn_sys_tail;
7089 static const char *defacl[] = {
7090 NULL, "to", "*", "by", "*", "none", NULL
7094 config_back_db_open( BackendDB *be, ConfigReply *cr )
7096 CfBackInfo *cfb = be->be_private;
7099 CfEntryInfo *ce, *ceparent;
7103 Connection conn = {0};
7104 OperationBuffer opbuf;
7106 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
7107 SlapReply rs = {REP_RESULT};
7108 void *thrctx = NULL;
7109 AccessControl *save_access;
7111 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
7113 /* If we have no explicitly configured ACLs, don't just use
7114 * the global ACLs. Explicitly deny access to everything.
7116 save_access = be->bd_self->be_acl;
7117 be->bd_self->be_acl = NULL;
7118 parse_acl(be->bd_self, "config_back_db_open", 0, 6, (char **)defacl, 0 );
7119 defacl_parsed = be->bd_self->be_acl;
7120 if ( save_access ) {
7121 be->bd_self->be_acl = save_access;
7123 Debug( LDAP_DEBUG_CONFIG, "config_back_db_open: "
7124 "No explicit ACL for back-config configured. "
7125 "Using hardcoded default\n", 0, 0, 0 );
7128 thrctx = ldap_pvt_thread_pool_context();
7129 connection_fake_init( &conn, &opbuf, thrctx );
7132 op->o_tag = LDAP_REQ_ADD;
7133 op->o_callback = &cb;
7134 op->o_bd = &cfb->cb_db;
7135 op->o_dn = op->o_bd->be_rootdn;
7136 op->o_ndn = op->o_bd->be_rootndn;
7138 if ( !cfb->cb_use_ldif ) {
7142 /* If we read the config from back-ldif, do some quick sanity checks */
7143 if ( cfb->cb_got_ldif ) {
7144 return config_check_schema( op, cfb );
7147 /* create root of tree */
7149 c.ca_private = cfb->cb_config;
7151 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
7161 #ifdef SLAPD_MODULES
7162 /* Create Module nodes... */
7163 if ( modpaths.mp_loads ) {
7164 if ( config_build_modules( &c, ceparent, op, &rs ) ){
7170 /* Create schema nodes... cn=schema will contain the hardcoded core
7171 * schema, read-only. Child objects will contain runtime loaded schema
7175 c.ca_private = NULL;
7176 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
7181 ce->ce_private = cfb->cb_config;
7182 cf_at_tail = at_sys_tail;
7183 cf_oc_tail = oc_sys_tail;
7184 cf_om_tail = om_sys_tail;
7185 cf_syn_tail = syn_sys_tail;
7187 /* Create schema nodes for included schema... */
7188 if ( cfb->cb_config->c_kids ) {
7191 c.ca_private = cfb->cb_config->c_kids;
7192 rc = config_build_schema_inc( &c, ce, op, &rs );
7198 /* Create backend nodes. Skip if they don't provide a cf_table.
7199 * There usually aren't any of these.
7203 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
7204 if (!bi->bi_cf_ocs) {
7205 /* If it only supports the old config mech, complain. */
7206 if ( bi->bi_config ) {
7207 Debug( LDAP_DEBUG_ANY,
7208 "WARNING: No dynamic config support for backend %s.\n",
7209 bi->bi_type, 0, 0 );
7214 if (!bi->bi_private) continue;
7217 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
7218 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
7219 if ( rdn.bv_len >= sizeof( c.log ) ) {
7220 /* FIXME: holler ... */ ;
7223 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
7230 /* Create database nodes... */
7231 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
7232 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
7233 for ( i = -1, be = frontendDB ; be;
7234 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
7235 slap_overinfo *oi = NULL;
7237 if ( overlay_is_over( be )) {
7238 oi = be->bd_info->bi_private;
7244 /* If this backend supports the old config mechanism, but not
7245 * the new mech, complain.
7247 if ( !be->be_cf_ocs && bi->bi_db_config ) {
7248 Debug( LDAP_DEBUG_ANY,
7249 "WARNING: No dynamic config support for database %s.\n",
7250 bi->bi_type, 0, 0 );
7254 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
7255 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
7257 if ( rdn.bv_len >= sizeof( c.log ) ) {
7258 /* FIXME: holler ... */ ;
7262 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
7268 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd ) {
7269 rs_reinit( &rs, REP_RESULT );
7270 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
7272 /* Iterate through overlays */
7277 voidList *vl, *v0 = NULL;
7279 /* overlays are in LIFO order, must reverse stack */
7280 for (on=oi->oi_list; on; on=on->on_next) {
7281 vl = ch_malloc( sizeof( voidList ));
7286 for (j=0; vl; j++,vl=v0) {
7290 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
7291 Debug( LDAP_DEBUG_ANY,
7292 "WARNING: No dynamic config support for overlay %s.\n",
7293 on->on_bi.bi_type, 0, 0 );
7297 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
7298 "%s=" SLAP_X_ORDERED_FMT "%s",
7299 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
7300 if ( rdn.bv_len >= sizeof( c.log ) ) {
7301 /* FIXME: holler ... */ ;
7305 oe = config_build_entry( op, &rs, ce, &c, &rdn,
7306 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
7310 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd ) {
7311 rs_reinit( &rs, REP_RESULT );
7312 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
7318 ldap_pvt_thread_pool_context_reset( thrctx );
7320 if ( unsupp && cfb->cb_use_ldif ) {
7321 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
7322 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
7329 cfb_free_cffile( ConfigFile *cf )
7333 for (; cf; cf=next) {
7336 cfb_free_cffile( cf->c_kids );
7337 ch_free( cf->c_file.bv_val );
7338 ber_bvarray_free( cf->c_dseFiles );
7344 cfb_free_entries( CfEntryInfo *ce )
7348 for (; ce; ce=next) {
7351 cfb_free_entries( ce->ce_kids );
7352 ce->ce_entry->e_private = NULL;
7353 entry_free( ce->ce_entry );
7359 config_back_db_close( BackendDB *be, ConfigReply *cr )
7361 CfBackInfo *cfb = be->be_private;
7363 cfb_free_entries( cfb->cb_root );
7364 cfb->cb_root = NULL;
7366 if ( cfb->cb_db.bd_info ) {
7367 backend_shutdown( &cfb->cb_db );
7370 if ( defacl_parsed && be->be_acl != defacl_parsed ) {
7371 acl_free( defacl_parsed );
7372 defacl_parsed = NULL;
7379 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
7381 CfBackInfo *cfb = be->be_private;
7383 cfb_free_cffile( cfb->cb_config );
7385 ch_free( cfdir.bv_val );
7387 avl_free( CfOcTree, NULL );
7389 if ( cfb->cb_db.bd_info ) {
7390 cfb->cb_db.be_suffix = NULL;
7391 cfb->cb_db.be_nsuffix = NULL;
7392 BER_BVZERO( &cfb->cb_db.be_rootdn );
7393 BER_BVZERO( &cfb->cb_db.be_rootndn );
7395 backend_destroy_one( &cfb->cb_db, 0 );
7404 config_back_db_init( BackendDB *be, ConfigReply* cr )
7410 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
7411 cfn = cfb->cb_config;
7412 be->be_private = cfb;
7414 ber_dupbv( &be->be_rootdn, &config_rdn );
7415 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
7416 ber_dupbv( &dn, &be->be_rootdn );
7417 ber_bvarray_add( &be->be_suffix, &dn );
7418 ber_dupbv( &dn, &be->be_rootdn );
7419 ber_bvarray_add( &be->be_nsuffix, &dn );
7421 /* Hide from namingContexts */
7422 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
7424 /* Check ACLs on content of Adds by default */
7425 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_ACL_ADD;
7431 config_back_destroy( BackendInfo *bi )
7433 ldif_must_b64_encode_release();
7438 config_tool_entry_open( BackendDB *be, int mode )
7440 CfBackInfo *cfb = be->be_private;
7441 BackendInfo *bi = cfb->cb_db.bd_info;
7443 if ( bi && bi->bi_tool_entry_open )
7444 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
7451 config_tool_entry_close( BackendDB *be )
7453 CfBackInfo *cfb = be->be_private;
7454 BackendInfo *bi = cfb->cb_db.bd_info;
7456 if ( bi && bi->bi_tool_entry_close )
7457 return bi->bi_tool_entry_close( &cfb->cb_db );
7463 config_tool_entry_first( BackendDB *be )
7465 CfBackInfo *cfb = be->be_private;
7466 BackendInfo *bi = cfb->cb_db.bd_info;
7468 if ( bi && bi->bi_tool_entry_first ) {
7469 return bi->bi_tool_entry_first( &cfb->cb_db );
7471 if ( bi && bi->bi_tool_entry_first_x ) {
7472 return bi->bi_tool_entry_first_x( &cfb->cb_db,
7473 NULL, LDAP_SCOPE_DEFAULT, NULL );
7479 config_tool_entry_first_x(
7481 struct berval *base,
7485 CfBackInfo *cfb = be->be_private;
7486 BackendInfo *bi = cfb->cb_db.bd_info;
7488 if ( bi && bi->bi_tool_entry_first_x ) {
7489 return bi->bi_tool_entry_first_x( &cfb->cb_db, base, scope, f );
7495 config_tool_entry_next( BackendDB *be )
7497 CfBackInfo *cfb = be->be_private;
7498 BackendInfo *bi = cfb->cb_db.bd_info;
7500 if ( bi && bi->bi_tool_entry_next )
7501 return bi->bi_tool_entry_next( &cfb->cb_db );
7507 config_tool_dn2id_get( Backend *be, struct berval *dn )
7509 CfBackInfo *cfb = be->be_private;
7510 BackendInfo *bi = cfb->cb_db.bd_info;
7512 if ( bi && bi->bi_tool_dn2id_get )
7513 return bi->bi_tool_dn2id_get( &cfb->cb_db, dn );
7519 config_tool_entry_get( BackendDB *be, ID id )
7521 CfBackInfo *cfb = be->be_private;
7522 BackendInfo *bi = cfb->cb_db.bd_info;
7524 if ( bi && bi->bi_tool_entry_get )
7525 return bi->bi_tool_entry_get( &cfb->cb_db, id );
7530 static int entry_put_got_frontend=0;
7531 static int entry_put_got_config=0;
7533 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
7535 CfBackInfo *cfb = be->be_private;
7536 BackendInfo *bi = cfb->cb_db.bd_info;
7538 struct berval rdn, vals[ 2 ];
7540 OperationBuffer opbuf;
7542 Connection conn = {0};
7543 Operation *op = NULL;
7546 int isFrontendChild = 0;
7548 /* Create entry for frontend database if it does not exist already */
7549 if ( !entry_put_got_frontend ) {
7550 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
7551 STRLENOF( "olcDatabase" ))) {
7552 if ( strncmp( e->e_nname.bv_val +
7553 STRLENOF( "olcDatabase" ), "={-1}frontend",
7554 STRLENOF( "={-1}frontend" )) &&
7555 strncmp( e->e_nname.bv_val +
7556 STRLENOF( "olcDatabase" ), "=frontend",
7557 STRLENOF( "=frontend" ))) {
7559 vals[1].bv_val = NULL;
7560 memset( &ca, 0, sizeof(ConfigArgs));
7562 ca.bi = frontendDB->bd_info;
7563 ca.be->be_cf_ocs = &CFOC_FRONTEND;
7564 rdn.bv_val = ca.log;
7565 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7566 "%s=" SLAP_X_ORDERED_FMT "%s",
7567 cfAd_database->ad_cname.bv_val, -1,
7569 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
7570 &CFOC_DATABASE, ca.be->be_cf_ocs );
7571 thrctx = ldap_pvt_thread_pool_context();
7572 connection_fake_init2( &conn, &opbuf, thrctx,0 );
7574 op->o_bd = &cfb->cb_db;
7575 op->o_tag = LDAP_REQ_ADD;
7577 op->o_dn = be->be_rootdn;
7578 op->o_ndn = be->be_rootndn;
7579 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
7580 if ( rc != LDAP_SUCCESS ) {
7581 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
7582 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
7586 if ( ce && bi && bi->bi_tool_entry_put &&
7587 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
7588 entry_put_got_frontend++;
7590 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
7591 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
7595 entry_put_got_frontend++;
7601 /* Child entries of the frontend database, e.g. slapo-chain's back-ldap
7602 * instances, may appear before the config database entry in the ldif, skip
7603 * auto-creation of olcDatabase={0}config in such a case */
7604 if ( !entry_put_got_config &&
7605 !strncmp( e->e_nname.bv_val, "olcDatabase", STRLENOF( "olcDatabase" ))) {
7607 dnParent( &e->e_nname, &pdn );
7608 while ( pdn.bv_len ) {
7609 if ( !strncmp( pdn.bv_val, "olcDatabase",
7610 STRLENOF( "olcDatabase" ))) {
7611 if ( !strncmp( pdn.bv_val +
7612 STRLENOF( "olcDatabase" ), "={-1}frontend",
7613 STRLENOF( "={-1}frontend" )) ||
7614 !strncmp( pdn.bv_val +
7615 STRLENOF( "olcDatabase" ), "=frontend",
7616 STRLENOF( "=frontend" ))) {
7618 isFrontendChild = 1;
7622 dnParent( &pdn, &pdn );
7626 /* Create entry for config database if it does not exist already */
7627 if ( !entry_put_got_config && !isFrontend && !isFrontendChild ) {
7628 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
7629 STRLENOF( "olcDatabase" ))) {
7630 if ( strncmp( e->e_nname.bv_val +
7631 STRLENOF( "olcDatabase" ), "={0}config",
7632 STRLENOF( "={0}config" )) &&
7633 strncmp( e->e_nname.bv_val +
7634 STRLENOF( "olcDatabase" ), "=config",
7635 STRLENOF( "=config" )) ) {
7637 vals[1].bv_val = NULL;
7638 memset( &ca, 0, sizeof(ConfigArgs));
7639 ca.be = LDAP_STAILQ_FIRST( &backendDB );
7640 ca.bi = ca.be->bd_info;
7641 rdn.bv_val = ca.log;
7642 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7643 "%s=" SLAP_X_ORDERED_FMT "%s",
7644 cfAd_database->ad_cname.bv_val, 0,
7646 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
7649 thrctx = ldap_pvt_thread_pool_context();
7650 connection_fake_init2( &conn, &opbuf, thrctx,0 );
7652 op->o_bd = &cfb->cb_db;
7653 op->o_tag = LDAP_REQ_ADD;
7654 op->o_dn = be->be_rootdn;
7655 op->o_ndn = be->be_rootndn;
7658 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
7659 if ( rc != LDAP_SUCCESS ) {
7660 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
7661 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7664 if (ce && bi && bi->bi_tool_entry_put &&
7665 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
7666 entry_put_got_config++;
7668 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
7669 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7673 entry_put_got_config++;
7677 if ( bi && bi->bi_tool_entry_put &&
7678 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
7679 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
7685 config_tool_entry_modify( BackendDB *be, Entry *e, struct berval *text )
7687 CfBackInfo *cfb = be->be_private;
7688 BackendInfo *bi = cfb->cb_db.bd_info;
7689 CfEntryInfo *ce, *last;
7690 ConfigArgs ca = {0};
7692 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
7694 if ( ce && bi && bi->bi_tool_entry_modify )
7695 return bi->bi_tool_entry_modify( &cfb->cb_db, e, text );
7701 config_tool_entry_delete( BackendDB *be, struct berval *ndn, struct berval *text )
7703 CfBackInfo *cfb = be->be_private;
7704 BackendInfo *bi = cfb->cb_db.bd_info;
7705 CfEntryInfo *ce, *last;
7706 ConfigArgs ca = {0};
7708 ce = config_find_base( cfb->cb_root, ndn, &last );
7710 if ( ce && bi && bi->bi_tool_entry_delete )
7711 return bi->bi_tool_entry_delete( &cfb->cb_db, ndn, text );
7718 AttributeDescription **desc;
7720 { "attribute", &cfAd_attr },
7721 { "backend", &cfAd_backend },
7722 { "database", &cfAd_database },
7723 { "include", &cfAd_include },
7724 { "ldapsyntax", &cfAd_syntax },
7725 { "objectclass", &cfAd_oc },
7726 { "objectidentifier", &cfAd_om },
7727 { "overlay", &cfAd_overlay },
7732 * add / delete: all types that may be added or deleted must use an
7733 * X-ORDERED attributeType for their RDN. Adding and deleting entries
7734 * should automatically renumber the index of any siblings as needed,
7735 * so that no gaps in the numbering sequence exist after the add/delete
7737 * What can be added:
7739 * backend objects for backend-specific config directives
7743 * delete: probably no support this time around.
7745 * modrdn: generally not done. Will be invoked automatically by add/
7746 * delete to update numbering sequence. Perform as an explicit operation
7747 * so that the renumbering effect may be replicated. Subtree rename must
7748 * be supported, since renumbering a database will affect all its child
7751 * modify: must be fully supported.
7755 config_back_initialize( BackendInfo *bi )
7757 ConfigTable *ct = config_back_cf_table;
7761 AttributeDescription *ad = NULL;
7763 static char *controls[] = {
7764 LDAP_CONTROL_MANAGEDSAIT,
7768 /* Make sure we don't exceed the bits reserved for userland */
7769 config_check_userland( CFG_LAST );
7771 bi->bi_controls = controls;
7776 bi->bi_destroy = config_back_destroy;
7778 bi->bi_db_init = config_back_db_init;
7779 bi->bi_db_config = 0;
7780 bi->bi_db_open = config_back_db_open;
7781 bi->bi_db_close = config_back_db_close;
7782 bi->bi_db_destroy = config_back_db_destroy;
7784 bi->bi_op_bind = config_back_bind;
7785 bi->bi_op_unbind = 0;
7786 bi->bi_op_search = config_back_search;
7787 bi->bi_op_compare = 0;
7788 bi->bi_op_modify = config_back_modify;
7789 bi->bi_op_modrdn = config_back_modrdn;
7790 bi->bi_op_add = config_back_add;
7791 bi->bi_op_delete = config_back_delete;
7792 bi->bi_op_abandon = 0;
7794 bi->bi_extended = 0;
7796 bi->bi_chk_referrals = 0;
7798 bi->bi_access_allowed = slap_access_allowed;
7800 bi->bi_connection_init = 0;
7801 bi->bi_connection_destroy = 0;
7803 bi->bi_entry_release_rw = config_entry_release;
7804 bi->bi_entry_get_rw = config_back_entry_get;
7806 bi->bi_tool_entry_open = config_tool_entry_open;
7807 bi->bi_tool_entry_close = config_tool_entry_close;
7808 bi->bi_tool_entry_first = config_tool_entry_first;
7809 bi->bi_tool_entry_first_x = config_tool_entry_first_x;
7810 bi->bi_tool_entry_next = config_tool_entry_next;
7811 bi->bi_tool_dn2id_get = config_tool_dn2id_get;
7812 bi->bi_tool_entry_get = config_tool_entry_get;
7813 bi->bi_tool_entry_put = config_tool_entry_put;
7814 bi->bi_tool_entry_modify = config_tool_entry_modify;
7815 bi->bi_tool_entry_delete = config_tool_entry_delete;
7818 argv[ 0 ] = "slapd";
7824 for (i=0; OidMacros[i].name; i++ ) {
7825 argv[1] = OidMacros[i].name;
7826 argv[2] = OidMacros[i].oid;
7827 parse_oidm( &ca, 0, NULL );
7830 bi->bi_cf_ocs = cf_ocs;
7832 i = config_register_schema( ct, cf_ocs );
7835 i = slap_str2ad( "olcDatabase", &olcDatabaseDummy[0].ad, &text );
7838 /* setup olcRootPW to be base64-encoded when written in LDIF form;
7839 * basically, we don't care if it fails */
7840 i = slap_str2ad( "olcRootPW", &ad, &text );
7842 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
7843 "warning, unable to get \"olcRootPW\" "
7844 "attribute description: %d: %s\n",
7847 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
7848 ad->ad_type->sat_oid );
7851 /* set up the notable AttributeDescriptions */
7853 for (;ct->name;ct++) {
7854 if (strcmp(ct->name, ads[i].name)) continue;
7855 *ads[i].desc = ct->ad;
7857 if (!ads[i].name) break;