1 /* bconfig.c - the config backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005-2014 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was originally developed by Howard Chu for inclusion
18 * in OpenLDAP Software.
24 #include <ac/string.h>
28 #include <ac/unistd.h>
33 #include "slapi/slapi.h"
41 #define CONFIG_RDN "cn=config"
42 #define SCHEMA_RDN "cn=schema"
44 static struct berval config_rdn = BER_BVC(CONFIG_RDN);
45 static struct berval schema_rdn = BER_BVC(SCHEMA_RDN);
47 extern int slap_DN_strict; /* dn.c */
50 typedef struct modpath_s {
51 struct modpath_s *mp_next;
52 struct berval mp_path;
56 static ModPaths modpaths, *modlast = &modpaths, *modcur = &modpaths;
59 typedef struct ConfigFile {
60 struct ConfigFile *c_sibs;
61 struct ConfigFile *c_kids;
63 AttributeType *c_at_head, *c_at_tail;
64 ContentRule *c_cr_head, *c_cr_tail;
65 ObjectClass *c_oc_head, *c_oc_tail;
66 OidMacro *c_om_head, *c_om_tail;
67 Syntax *c_syn_head, *c_syn_tail;
72 ConfigFile *cb_config;
74 BackendDB cb_db; /* underlying database */
79 static CfBackInfo cfBackInfo;
81 static char *passwd_salt;
83 static char *logfileName;
84 #ifdef SLAP_AUTH_REWRITE
85 static BerVarray authz_rewrites;
87 static AccessControl *defacl_parsed = NULL;
89 static struct berval cfdir;
92 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
93 *cfAd_include, *cfAd_attr, *cfAd_oc, *cfAd_om, *cfAd_syntax;
95 static ConfigFile *cfn;
97 static Avlnode *CfOcTree;
99 /* System schema state */
100 extern AttributeType *at_sys_tail; /* at.c */
101 extern ObjectClass *oc_sys_tail; /* oc.c */
102 extern OidMacro *om_sys_tail; /* oidm.c */
103 extern Syntax *syn_sys_tail; /* syntax.c */
104 static AttributeType *cf_at_tail;
105 static ObjectClass *cf_oc_tail;
106 static OidMacro *cf_om_tail;
107 static Syntax *cf_syn_tail;
109 static int config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca,
110 SlapReply *rs, int *renumber, Operation *op );
112 static int config_check_schema( Operation *op, CfBackInfo *cfb );
114 static ConfigDriver config_fname;
115 static ConfigDriver config_cfdir;
116 static ConfigDriver config_generic;
117 static ConfigDriver config_search_base;
118 static ConfigDriver config_passwd_hash;
119 static ConfigDriver config_schema_dn;
120 static ConfigDriver config_sizelimit;
121 static ConfigDriver config_timelimit;
122 static ConfigDriver config_overlay;
123 static ConfigDriver config_subordinate;
124 static ConfigDriver config_suffix;
125 #ifdef LDAP_TCP_BUFFER
126 static ConfigDriver config_tcp_buffer;
127 #endif /* LDAP_TCP_BUFFER */
128 static ConfigDriver config_rootdn;
129 static ConfigDriver config_rootpw;
130 static ConfigDriver config_restrict;
131 static ConfigDriver config_allows;
132 static ConfigDriver config_disallows;
133 static ConfigDriver config_requires;
134 static ConfigDriver config_security;
135 static ConfigDriver config_referral;
136 static ConfigDriver config_loglevel;
137 static ConfigDriver config_updatedn;
138 static ConfigDriver config_updateref;
139 static ConfigDriver config_extra_attrs;
140 static ConfigDriver config_include;
141 static ConfigDriver config_obsolete;
143 static ConfigDriver config_tls_option;
144 static ConfigDriver config_tls_config;
146 extern ConfigDriver syncrepl_config;
154 CFG_TLS_PROTOCOL_MIN,
211 static OidRec OidMacros[] = {
212 /* OpenLDAProot:1.12.2 */
213 { "OLcfg", "1.3.6.1.4.1.4203.1.12.2" },
214 { "OLcfgAt", "OLcfg:3" },
215 { "OLcfgGlAt", "OLcfgAt:0" },
216 { "OLcfgBkAt", "OLcfgAt:1" },
217 { "OLcfgDbAt", "OLcfgAt:2" },
218 { "OLcfgOvAt", "OLcfgAt:3" },
219 { "OLcfgCtAt", "OLcfgAt:4" }, /* contrib modules */
220 { "OLcfgOc", "OLcfg:4" },
221 { "OLcfgGlOc", "OLcfgOc:0" },
222 { "OLcfgBkOc", "OLcfgOc:1" },
223 { "OLcfgDbOc", "OLcfgOc:2" },
224 { "OLcfgOvOc", "OLcfgOc:3" },
225 { "OLcfgCtOc", "OLcfgOc:4" }, /* contrib modules */
227 /* Syntaxes. We should just start using the standard names and
228 * document that they are predefined and available for users
229 * to reference in their own schema. Defining schema without
230 * OID macros is for masochists...
232 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
233 { "OMsBoolean", "OMsyn:7" },
234 { "OMsDN", "OMsyn:12" },
235 { "OMsDirectoryString", "OMsyn:15" },
236 { "OMsIA5String", "OMsyn:26" },
237 { "OMsInteger", "OMsyn:27" },
238 { "OMsOID", "OMsyn:38" },
239 { "OMsOctetString", "OMsyn:40" },
244 * Backend/Database registry
246 * OLcfg{Bk|Db}{Oc|At}:0 -> common
247 * OLcfg{Bk|Db}{Oc|At}:1 -> back-bdb(/back-hdb)
248 * OLcfg{Bk|Db}{Oc|At}:2 -> back-ldif
249 * OLcfg{Bk|Db}{Oc|At}:3 -> back-ldap/meta
250 * OLcfg{Bk|Db}{Oc|At}:4 -> back-monitor
251 * OLcfg{Bk|Db}{Oc|At}:5 -> back-relay
252 * OLcfg{Bk|Db}{Oc|At}:6 -> back-sql(/back-ndb)
253 * OLcfg{Bk|Db}{Oc|At}:7 -> back-sock
254 * OLcfg{Bk|Db}{Oc|At}:8 -> back-null
255 * OLcfg{Bk|Db}{Oc|At}:9 -> back-passwd
256 * OLcfg{Bk|Db}{Oc|At}:10 -> back-shell
257 * OLcfg{Bk|Db}{Oc|At}:11 -> back-perl
258 * OLcfg{Bk|Db}{Oc|At}:12 -> back-mdb
264 * OLcfgOv{Oc|At}:1 -> syncprov
265 * OLcfgOv{Oc|At}:2 -> pcache
266 * OLcfgOv{Oc|At}:3 -> chain
267 * OLcfgOv{Oc|At}:4 -> accesslog
268 * OLcfgOv{Oc|At}:5 -> valsort
269 * OLcfgOv{Oc|At}:7 -> distproc
270 * OLcfgOv{Oc|At}:8 -> dynlist
271 * OLcfgOv{Oc|At}:9 -> dds
272 * OLcfgOv{Oc|At}:10 -> unique
273 * OLcfgOv{Oc|At}:11 -> refint
274 * OLcfgOv{Oc|At}:12 -> ppolicy
275 * OLcfgOv{Oc|At}:13 -> constraint
276 * OLcfgOv{Oc|At}:14 -> translucent
277 * OLcfgOv{Oc|At}:15 -> auditlog
278 * OLcfgOv{Oc|At}:16 -> rwm
279 * OLcfgOv{Oc|At}:17 -> dyngroup
280 * OLcfgOv{Oc|At}:18 -> memberof
281 * OLcfgOv{Oc|At}:19 -> collect
282 * OLcfgOv{Oc|At}:20 -> retcode
283 * OLcfgOv{Oc|At}:21 -> sssvlv
286 /* alphabetical ordering */
288 static ConfigTable config_back_cf_table[] = {
289 /* This attr is read-only */
290 { "", "", 0, 0, 0, ARG_MAGIC,
291 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
292 "DESC 'File for slapd configuration directives' "
293 "EQUALITY caseIgnoreMatch "
294 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
295 { "", "", 0, 0, 0, ARG_MAGIC,
296 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
297 "DESC 'Directory for slapd configuration backend' "
298 "EQUALITY caseIgnoreMatch "
299 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
300 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
301 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
302 "DESC 'Access Control List' "
303 "EQUALITY caseIgnoreMatch "
304 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
305 { "add_content_acl", NULL, 0, 0, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_ACL_ADD,
306 &config_generic, "( OLcfgGlAt:86 NAME 'olcAddContentAcl' "
307 "DESC 'Check ACLs against content of Add ops' "
308 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
309 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
310 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
311 "DESC 'Allowed set of deprecated features' "
312 "EQUALITY caseIgnoreMatch "
313 "SYNTAX OMsDirectoryString )", NULL, NULL },
314 { "argsfile", "file", 2, 2, 0, ARG_STRING,
315 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
316 "DESC 'File for slapd command line options' "
317 "EQUALITY caseIgnoreMatch "
318 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
319 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
320 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
321 "EQUALITY caseIgnoreMatch "
322 "SYNTAX OMsDirectoryString )", NULL, NULL },
323 { "attribute", "attribute", 2, 0, STRLENOF( "attribute" ),
324 ARG_PAREN|ARG_MAGIC|CFG_ATTR,
325 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
326 "DESC 'OpenLDAP attributeTypes' "
327 "EQUALITY caseIgnoreMatch "
328 "SUBSTR caseIgnoreSubstringsMatch "
329 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
331 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
332 #ifdef SLAP_AUTH_REWRITE
333 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
337 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
338 "EQUALITY caseIgnoreMatch "
339 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
340 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
341 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
342 "EQUALITY caseIgnoreMatch "
343 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
344 { "authz-regexp", "regexp> <DN", 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
345 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
346 "EQUALITY caseIgnoreMatch "
347 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
348 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
349 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
350 "DESC 'A type of backend' "
351 "EQUALITY caseIgnoreMatch "
352 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
354 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
355 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
356 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
357 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
358 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
359 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
360 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
361 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
362 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
363 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
364 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
365 "DESC 'The backend type for a database instance' "
366 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
367 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
368 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
369 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
370 { "disabled", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_DISABLED,
371 &config_generic, "( OLcfgDbAt:0.21 NAME 'olcDisabled' "
372 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
373 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
374 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
375 "EQUALITY caseIgnoreMatch "
376 "SYNTAX OMsDirectoryString )", NULL, NULL },
377 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
378 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
379 "DESC 'OpenLDAP DIT content rules' "
380 "EQUALITY caseIgnoreMatch "
381 "SUBSTR caseIgnoreSubstringsMatch "
382 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
384 { "extra_attrs", "attrlist", 2, 2, 0, ARG_DB|ARG_MAGIC,
385 &config_extra_attrs, "( OLcfgDbAt:0.20 NAME 'olcExtraAttrs' "
386 "EQUALITY caseIgnoreMatch "
387 "SYNTAX OMsDirectoryString )", NULL, NULL },
388 { "gentlehup", "on|off", 2, 2, 0,
390 ARG_ON_OFF, &global_gentlehup,
394 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
395 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
396 { "hidden", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_HIDDEN,
397 &config_generic, "( OLcfgDbAt:0.17 NAME 'olcHidden' "
398 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
399 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
400 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
401 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
402 { "include", "file", 2, 2, 0, ARG_MAGIC,
403 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
404 "SUP labeledURI )", NULL, NULL },
405 { "index_hash64", "on|off", 2, 2, 0, ARG_ON_OFF|ARG_MAGIC|CFG_IX_HASH64,
406 &config_generic, "( OLcfgGlAt:94 NAME 'olcIndexHash64' "
407 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
408 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
409 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
410 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
411 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
412 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
413 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
414 { "index_substr_any_len", "len", 2, 2, 0, ARG_UINT|ARG_NONZERO,
415 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
416 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
417 { "index_substr_any_step", "step", 2, 2, 0, ARG_UINT|ARG_NONZERO,
418 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
419 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
420 { "index_intlen", "len", 2, 2, 0, ARG_UINT|ARG_MAGIC|CFG_IX_INTLEN,
421 &config_generic, "( OLcfgGlAt:84 NAME 'olcIndexIntLen' "
422 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
423 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
424 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
425 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
426 { "ldapsyntax", "syntax", 2, 0, 0,
427 ARG_PAREN|ARG_MAGIC|CFG_SYNTAX,
428 &config_generic, "( OLcfgGlAt:85 NAME 'olcLdapSyntaxes' "
429 "DESC 'OpenLDAP ldapSyntax' "
430 "EQUALITY caseIgnoreMatch "
431 "SUBSTR caseIgnoreSubstringsMatch "
432 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
434 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
435 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
436 "EQUALITY caseIgnoreMatch "
437 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
438 { "listener-threads", "count", 2, 0, 0,
442 ARG_UINT|ARG_MAGIC|CFG_LTHREADS, &config_generic,
444 "( OLcfgGlAt:93 NAME 'olcListenerThreads' "
445 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
446 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
447 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
448 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
449 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
450 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
451 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
452 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
453 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
454 "EQUALITY caseIgnoreMatch "
455 "SYNTAX OMsDirectoryString )", NULL, NULL },
456 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
457 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
458 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
459 { "mirrormode", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_MIRRORMODE,
460 &config_generic, "( OLcfgDbAt:0.16 NAME 'olcMirrorMode' "
461 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
462 { "moduleload", "file", 2, 0, 0,
464 ARG_MAGIC|CFG_MODLOAD|ARG_NO_DELETE, &config_generic,
468 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
469 "EQUALITY caseIgnoreMatch "
470 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
471 { "modulepath", "path", 2, 2, 0,
473 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
477 "( OLcfgGlAt:31 NAME 'olcModulePath' "
478 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
479 { "monitoring", "TRUE|FALSE", 2, 2, 0,
480 ARG_MAGIC|CFG_MONITORING|ARG_DB|ARG_ON_OFF, &config_generic,
481 "( OLcfgDbAt:0.18 NAME 'olcMonitoring' "
482 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
483 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
484 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
485 "DESC 'OpenLDAP object classes' "
486 "EQUALITY caseIgnoreMatch "
487 "SUBSTR caseIgnoreSubstringsMatch "
488 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
490 { "objectidentifier", "name> <oid", 3, 3, 0, ARG_MAGIC|CFG_OID,
491 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
492 "EQUALITY caseIgnoreMatch "
493 "SUBSTR caseIgnoreSubstringsMatch "
494 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
495 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
496 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
497 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
498 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
499 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
500 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
501 { "password-hash", "hash", 2, 0, 0, ARG_MAGIC,
502 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
503 "EQUALITY caseIgnoreMatch "
504 "SYNTAX OMsDirectoryString )", NULL, NULL },
505 { "pidfile", "file", 2, 2, 0, ARG_STRING,
506 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
507 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
508 { "plugin", NULL, 0, 0, 0,
510 ARG_MAGIC|CFG_PLUGIN, &config_generic,
514 "( OLcfgGlAt:38 NAME 'olcPlugin' "
515 "EQUALITY caseIgnoreMatch "
516 "SYNTAX OMsDirectoryString )", NULL, NULL },
517 { "pluginlog", "filename", 2, 2, 0,
519 ARG_STRING, &slapi_log_file,
523 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
524 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
525 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
526 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
527 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
528 { "referral", "url", 2, 2, 0, ARG_MAGIC,
529 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
530 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
531 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
532 &config_obsolete, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
533 "EQUALITY caseIgnoreMatch "
534 "SUP labeledURI X-ORDERED 'VALUES' )", NULL, NULL },
535 { "replica-argsfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
536 &config_obsolete, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
537 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
538 { "replica-pidfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
539 &config_obsolete, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
540 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
541 { "replicationInterval", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
542 &config_obsolete, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
543 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
544 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC,
545 &config_obsolete, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
546 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
547 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
548 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
549 "EQUALITY caseIgnoreMatch "
550 "SYNTAX OMsDirectoryString )", NULL, NULL },
551 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
552 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
553 "EQUALITY caseIgnoreMatch "
554 "SYNTAX OMsDirectoryString )", NULL, NULL },
555 { "reverse-lookup", "on|off", 2, 2, 0,
556 #ifdef SLAPD_RLOOKUPS
557 ARG_ON_OFF, &use_reverse_lookup,
561 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
562 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
563 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
564 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
565 "EQUALITY distinguishedNameMatch "
566 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
567 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
568 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
569 "EQUALITY caseIgnoreMatch "
570 "SYNTAX OMsDirectoryString )", NULL, NULL },
571 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
572 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
573 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
574 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
575 &config_generic, NULL, NULL, NULL },
576 { "sasl-auxprops", NULL, 2, 0, 0,
577 #ifdef HAVE_CYRUS_SASL
578 ARG_STRING|ARG_UNIQUE, &slap_sasl_auxprops,
582 "( OLcfgGlAt:89 NAME 'olcSaslAuxprops' "
583 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
584 { "sasl-auxprops-dontusecopy", NULL, 2, 0, 0,
585 #if defined(HAVE_CYRUS_SASL) && defined(SLAP_AUXPROP_DONTUSECOPY)
586 ARG_MAGIC|CFG_AZDUC, &config_generic,
590 "( OLcfgGlAt:91 NAME 'olcSaslAuxpropsDontUseCopy' "
591 "EQUALITY caseIgnoreMatch "
592 "SYNTAX OMsDirectoryString )", NULL, NULL },
593 { "sasl-auxprops-dontusecopy-ignore", "true|FALSE", 2, 0, 0,
594 #if defined(HAVE_CYRUS_SASL) && defined(SLAP_AUXPROP_DONTUSECOPY)
595 ARG_ON_OFF|CFG_AZDUC_IGNORE, &slap_dontUseCopy_ignore,
599 "( OLcfgGlAt:92 NAME 'olcSaslAuxpropsDontUseCopyIgnore' "
600 "EQUALITY booleanMatch "
601 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
602 { "sasl-host", "host", 2, 2, 0,
603 #ifdef HAVE_CYRUS_SASL
604 ARG_STRING|ARG_UNIQUE, &sasl_host,
608 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
609 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
610 { "sasl-realm", "realm", 2, 2, 0,
611 #ifdef HAVE_CYRUS_SASL
612 ARG_STRING|ARG_UNIQUE, &global_realm,
616 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
617 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
618 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
619 &config_generic, NULL, NULL, NULL },
620 { "sasl-secprops", "properties", 2, 2, 0,
621 #ifdef HAVE_CYRUS_SASL
622 ARG_MAGIC|CFG_SASLSECP, &config_generic,
626 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
627 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
628 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
629 &config_generic, NULL, NULL, NULL },
630 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
631 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
632 "EQUALITY distinguishedNameMatch "
633 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
634 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
635 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
636 "EQUALITY caseIgnoreMatch "
637 "SYNTAX OMsDirectoryString )", NULL, NULL },
638 { "serverID", "number> <[URI]", 2, 3, 0, ARG_MAGIC|CFG_SERVERID,
639 &config_generic, "( OLcfgGlAt:81 NAME 'olcServerID' "
640 "EQUALITY caseIgnoreMatch "
641 "SYNTAX OMsDirectoryString )", NULL, NULL },
642 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
643 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
644 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
645 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
646 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
647 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
648 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
649 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
650 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
651 { "sortvals", "attr", 2, 0, 0, ARG_MAGIC|CFG_SORTVALS,
652 &config_generic, "( OLcfgGlAt:83 NAME 'olcSortVals' "
653 "DESC 'Attributes whose values will always be sorted' "
654 "EQUALITY caseIgnoreMatch "
655 "SYNTAX OMsDirectoryString )", NULL, NULL },
656 { "subordinate", "[advertise]", 1, 2, 0, ARG_DB|ARG_MAGIC,
657 &config_subordinate, "( OLcfgDbAt:0.15 NAME 'olcSubordinate' "
658 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
659 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
660 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
661 "EQUALITY distinguishedNameMatch "
662 "SYNTAX OMsDN )", NULL, NULL },
663 { "sync_use_subentry", NULL, 0, 0, 0, ARG_ON_OFF|ARG_DB|ARG_MAGIC|CFG_SYNC_SUBENTRY,
664 &config_generic, "( OLcfgDbAt:0.19 NAME 'olcSyncUseSubentry' "
665 "DESC 'Store sync context in a subentry' "
666 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
667 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
668 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
669 "EQUALITY caseIgnoreMatch "
670 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
671 { "tcp-buffer", "[listener=<listener>] [{read|write}=]size", 0, 0, 0,
672 #ifndef LDAP_TCP_BUFFER
674 #else /* LDAP_TCP_BUFFER */
675 ARG_MAGIC, &config_tcp_buffer,
676 #endif /* LDAP_TCP_BUFFER */
677 "( OLcfgGlAt:90 NAME 'olcTCPBuffer' "
678 "DESC 'Custom TCP buffer size' "
679 "SYNTAX OMsDirectoryString )", NULL, NULL },
680 { "threads", "count", 2, 2, 0,
684 ARG_INT|ARG_MAGIC|CFG_THREADS, &config_generic,
686 "( OLcfgGlAt:66 NAME 'olcThreads' "
687 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
688 { "threadqueues", "count", 2, 2, 0,
692 ARG_INT|ARG_MAGIC|CFG_THREADQS, &config_generic,
694 "( OLcfgGlAt:95 NAME 'olcThreadQueues' "
695 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
696 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
697 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
698 "SYNTAX OMsDirectoryString )", NULL, NULL },
699 { "TLSCACertificateFile", NULL, 2, 2, 0,
701 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
705 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
706 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
707 { "TLSCACertificatePath", NULL, 2, 2, 0,
709 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
713 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
714 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
715 { "TLSCertificateFile", NULL, 2, 2, 0,
717 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
721 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
722 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
723 { "TLSCertificateKeyFile", NULL, 2, 2, 0,
725 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
729 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
730 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
731 { "TLSCipherSuite", NULL, 2, 2, 0,
733 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
737 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
738 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
739 { "TLSCRLCheck", NULL, 2, 2, 0,
740 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
741 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
745 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
746 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
747 { "TLSCRLFile", NULL, 2, 2, 0,
748 #if defined(HAVE_GNUTLS)
749 CFG_TLS_CRL_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
753 "( OLcfgGlAt:82 NAME 'olcTLSCRLFile' "
754 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
755 { "TLSRandFile", NULL, 2, 2, 0,
757 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
761 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
762 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
763 { "TLSVerifyClient", NULL, 2, 2, 0,
765 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
769 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
770 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
771 { "TLSDHParamFile", NULL, 2, 2, 0,
773 CFG_TLS_DH_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
777 "( OLcfgGlAt:77 NAME 'olcTLSDHParamFile' "
778 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
779 { "TLSECName", NULL, 2, 2, 0,
781 CFG_TLS_ECNAME|ARG_STRING|ARG_MAGIC, &config_tls_option,
785 "( OLcfgGlAt:96 NAME 'olcTLSECName' "
786 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
787 { "TLSProtocolMin", NULL, 2, 2, 0,
789 CFG_TLS_PROTOCOL_MIN|ARG_STRING|ARG_MAGIC, &config_tls_config,
793 "( OLcfgGlAt:87 NAME 'olcTLSProtocolMin' "
794 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
795 { "tool-threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_TTHREADS,
796 &config_generic, "( OLcfgGlAt:80 NAME 'olcToolThreads' "
797 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
798 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
799 NULL, NULL, NULL, NULL },
800 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
801 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
802 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
803 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
804 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
805 "EQUALITY caseIgnoreMatch "
806 "SUP labeledURI )", NULL, NULL },
807 { "writetimeout", "timeout", 2, 2, 0, ARG_INT,
808 &global_writetimeout, "( OLcfgGlAt:88 NAME 'olcWriteTimeout' "
809 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
810 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
811 NULL, NULL, NULL, NULL }
814 /* Need to no-op this keyword for dynamic config */
815 ConfigTable olcDatabaseDummy[] = {
816 { "", "", 0, 0, 0, ARG_IGNORED,
817 NULL, "( OLcfgGlAt:13 NAME 'olcDatabase' "
818 "DESC 'The backend type for a database instance' "
819 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
820 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
823 /* Routines to check if a child can be added to this type */
824 static ConfigLDAPadd cfAddSchema, cfAddInclude, cfAddDatabase,
825 cfAddBackend, cfAddModule, cfAddOverlay;
827 /* NOTE: be careful when defining array members
828 * that can be conditionally compiled */
829 #define CFOC_GLOBAL cf_ocs[1]
830 #define CFOC_SCHEMA cf_ocs[2]
831 #define CFOC_BACKEND cf_ocs[3]
832 #define CFOC_DATABASE cf_ocs[4]
833 #define CFOC_OVERLAY cf_ocs[5]
834 #define CFOC_INCLUDE cf_ocs[6]
835 #define CFOC_FRONTEND cf_ocs[7]
837 #define CFOC_MODULE cf_ocs[8]
838 #endif /* SLAPD_MODULES */
840 static ConfigOCs cf_ocs[] = {
843 "DESC 'OpenLDAP configuration object' "
844 "ABSTRACT SUP top )", Cft_Abstract, NULL },
847 "DESC 'OpenLDAP Global configuration options' "
848 "SUP olcConfig STRUCTURAL "
849 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
850 "olcAttributeOptions $ olcAuthIDRewrite $ "
851 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
852 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
853 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
854 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
855 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcIndexHash64 $ "
857 "olcListenerThreads $ olcLocalSSF $ olcLogFile $ olcLogLevel $ "
858 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
859 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
860 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
862 "olcSaslAuxprops $ olcSaslAuxpropsDontUseCopy $ olcSaslAuxpropsDontUseCopyIgnore $ "
863 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
864 "olcSecurity $ olcServerID $ olcSizeLimit $ "
865 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ "
867 "olcThreads $ olcThreadQueues $ "
868 "olcTimeLimit $ olcTLSCACertificateFile $ "
869 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
870 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
871 "olcTLSRandFile $ olcTLSVerifyClient $ olcTLSDHParamFile $ olcTLSECName $ "
872 "olcTLSCRLFile $ olcTLSProtocolMin $ olcToolThreads $ olcWriteTimeout $ "
873 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
874 "olcDitContentRules $ olcLdapSyntaxes ) )", Cft_Global },
876 "NAME 'olcSchemaConfig' "
877 "DESC 'OpenLDAP schema object' "
878 "SUP olcConfig STRUCTURAL "
879 "MAY ( cn $ olcObjectIdentifier $ olcLdapSyntaxes $ "
880 "olcAttributeTypes $ olcObjectClasses $ olcDitContentRules ) )",
881 Cft_Schema, NULL, cfAddSchema },
883 "NAME 'olcBackendConfig' "
884 "DESC 'OpenLDAP Backend-specific options' "
885 "SUP olcConfig STRUCTURAL "
886 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
888 "NAME 'olcDatabaseConfig' "
889 "DESC 'OpenLDAP Database-specific options' "
890 "SUP olcConfig STRUCTURAL "
892 "MAY ( olcDisabled $ olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
893 "olcAddContentAcl $ olcLastMod $ olcLimits $ "
894 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
895 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
896 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
897 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncUseSubentry $ olcSyncrepl $ "
898 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef $ olcMirrorMode $ "
899 "olcMonitoring $ olcExtraAttrs ) )",
900 Cft_Database, NULL, cfAddDatabase },
902 "NAME 'olcOverlayConfig' "
903 "DESC 'OpenLDAP Overlay-specific options' "
904 "SUP olcConfig STRUCTURAL "
906 "MAY olcDisabled )", Cft_Overlay, NULL, cfAddOverlay },
908 "NAME 'olcIncludeFile' "
909 "DESC 'OpenLDAP configuration include file' "
910 "SUP olcConfig STRUCTURAL "
912 "MAY ( cn $ olcRootDSE ) )",
913 /* Used to be Cft_Include, that def has been removed */
914 Cft_Abstract, NULL, cfAddInclude },
915 /* This should be STRUCTURAL like all the other database classes, but
916 * that would mean inheriting all of the olcDatabaseConfig attributes,
917 * which causes them to be merged twice in config_build_entry.
920 "NAME 'olcFrontendConfig' "
921 "DESC 'OpenLDAP frontend configuration' "
923 "MAY ( olcDefaultSearchBase $ olcPasswordHash $ olcSortVals ) )",
924 Cft_Database, NULL, NULL },
927 "NAME 'olcModuleList' "
928 "DESC 'OpenLDAP dynamic module info' "
929 "SUP olcConfig STRUCTURAL "
930 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
931 Cft_Module, NULL, cfAddModule },
936 typedef struct ServerID {
937 struct ServerID *si_next;
938 struct berval si_url;
942 static ServerID *sid_list;
943 static ServerID *sid_set;
945 typedef struct voidList {
946 struct voidList *vl_next;
950 typedef struct ADlist {
951 struct ADlist *al_next;
952 AttributeDescription *al_desc;
955 static ADlist *sortVals;
958 config_generic(ConfigArgs *c) {
961 if ( c->op == SLAP_CONFIG_EMIT ) {
965 c->value_int = ldap_pvt_thread_get_concurrency();
968 c->value_int = connection_pool_max;
971 c->value_int = connection_pool_queues;
974 c->value_int = slap_tool_thread_max;
977 c->value_uint = slapd_daemon_threads;
981 c->value_string = ch_strdup( passwd_salt );
986 if ( c->be->be_limits ) {
990 for ( i=0; c->be->be_limits[i]; i++ ) {
991 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
992 if ( bv.bv_len >= sizeof( buf ) ) {
993 ber_bvarray_free_x( c->rvalue_vals, NULL );
994 c->rvalue_vals = NULL;
998 bv.bv_val = buf + bv.bv_len;
999 limits_unparse( c->be->be_limits[i], &bv,
1000 sizeof( buf ) - ( bv.bv_val - buf ) );
1001 bv.bv_len += bv.bv_val - buf;
1003 value_add_one( &c->rvalue_vals, &bv );
1006 if ( !c->rvalue_vals ) rc = 1;
1009 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_READONLY);
1012 c->value_string = ch_strdup( slap_sasl_getpolicy());
1015 slap_sasl_regexp_unparse( &c->rvalue_vals );
1016 if ( !c->rvalue_vals ) rc = 1;
1018 #ifdef HAVE_CYRUS_SASL
1019 #ifdef SLAP_AUXPROP_DONTUSECOPY
1021 static int duc_done = 0;
1023 /* take the opportunity to initialize with known values */
1025 struct berval duc[] = { BER_BVC("cmusaslsecretOTP"), BER_BVNULL };
1028 for ( i = 0; !BER_BVISNULL( &duc[ i ] ); i++ ) {
1029 const char *text = NULL;
1030 AttributeDescription *ad = NULL;
1032 if ( slap_bv2ad( &duc[ i ], &ad, &text ) == LDAP_SUCCESS ) {
1034 if ( slap_dontUseCopy_propnames ) {
1037 for ( j = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ j ] ); j++ ) {
1038 if ( bvmatch( &slap_dontUseCopy_propnames[ j ], &ad->ad_cname ) ) {
1045 value_add_one( &slap_dontUseCopy_propnames, &ad->ad_cname );
1053 if ( slap_dontUseCopy_propnames != NULL ) {
1054 ber_bvarray_dup_x( &c->rvalue_vals, slap_dontUseCopy_propnames, NULL );
1059 #endif /* SLAP_AUXPROP_DONTUSECOPY */
1060 case CFG_SASLSECP: {
1061 struct berval bv = BER_BVNULL;
1062 slap_sasl_secprops_unparse( &bv );
1063 if ( !BER_BVISNULL( &bv )) {
1064 ber_bvarray_add( &c->rvalue_vals, &bv );
1072 c->value_int = c->be->be_max_deref_depth;
1077 if ( c->bi->bi_flags & SLAPO_BFLAG_DISABLED ) {
1084 if ( SLAP_DBDISABLED( c->be )) {
1092 if ( SLAP_DBHIDDEN( c->be )) {
1099 ConfigFile *cf = c->ca_private;
1101 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1102 else if ( cf->c_om_head )
1103 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
1105 if ( !c->rvalue_vals )
1110 ad_unparse_options( &c->rvalue_vals );
1113 ConfigFile *cf = c->ca_private;
1115 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1116 else if ( cf->c_oc_head )
1117 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
1119 if ( !c->rvalue_vals )
1124 ConfigFile *cf = c->ca_private;
1126 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1127 else if ( cf->c_at_head )
1128 at_unparse( &c->rvalue_vals, cf->c_at_head,
1130 if ( !c->rvalue_vals )
1135 ConfigFile *cf = c->ca_private;
1137 syn_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1138 else if ( cf->c_syn_head )
1139 syn_unparse( &c->rvalue_vals, cf->c_syn_head,
1140 cf->c_syn_tail, 0 );
1141 if ( !c->rvalue_vals )
1146 ConfigFile *cf = c->ca_private;
1148 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1149 else if ( cf->c_cr_head )
1150 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
1152 if ( !c->rvalue_vals )
1159 char *src, *dst, ibuf[11];
1160 struct berval bv, abv;
1161 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
1162 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1163 if ( abv.bv_len >= sizeof( ibuf ) ) {
1164 ber_bvarray_free_x( c->rvalue_vals, NULL );
1165 c->rvalue_vals = NULL;
1169 acl_unparse( a, &bv );
1170 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
1171 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
1172 /* Turn TAB / EOL into plain space */
1173 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
1174 if (isspace((unsigned char)*src)) *dst++ = ' ';
1178 if (dst[-1] == ' ') {
1182 abv.bv_len = dst - abv.bv_val;
1183 ber_bvarray_add( &c->rvalue_vals, &abv );
1189 c->value_int = (SLAP_DBACL_ADD(c->be) != 0);
1192 ConfigFile *cf = c->ca_private;
1193 if ( cf->c_dseFiles ) {
1194 value_add( &c->rvalue_vals, cf->c_dseFiles );
1205 for ( si = sid_list; si; si=si->si_next ) {
1206 assert( si->si_num >= 0 && si->si_num <= SLAP_SYNC_SID_MAX );
1207 if ( !BER_BVISEMPTY( &si->si_url )) {
1208 bv.bv_len = si->si_url.bv_len + 6;
1209 bv.bv_val = ch_malloc( bv.bv_len );
1210 bv.bv_len = sprintf( bv.bv_val, "%d %s", si->si_num,
1211 si->si_url.bv_val );
1212 ber_bvarray_add( &c->rvalue_vals, &bv );
1216 bv.bv_len = sprintf( buf, "%d", si->si_num );
1217 value_add_one( &c->rvalue_vals, &bv );
1226 c->value_string = ch_strdup( logfileName );
1231 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1233 case CFG_SYNC_SUBENTRY:
1234 c->value_int = (SLAP_SYNC_SUBENTRY(c->be) != 0);
1236 case CFG_MIRRORMODE:
1237 if ( SLAP_SHADOW(c->be))
1238 c->value_int = (SLAP_MULTIMASTER(c->be) != 0);
1242 case CFG_MONITORING:
1243 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
1245 case CFG_SSTR_IF_MAX:
1246 c->value_uint = index_substr_if_maxlen;
1248 case CFG_SSTR_IF_MIN:
1249 c->value_uint = index_substr_if_minlen;
1252 c->value_int = slap_hash64( -1 );
1255 c->value_int = index_intlen;
1257 case CFG_SORTVALS: {
1260 for ( sv = sortVals; sv; sv = sv->al_next ) {
1261 value_add_one( &c->rvalue_vals, &sv->al_desc->ad_cname );
1265 #ifdef SLAPD_MODULES
1267 ModPaths *mp = c->ca_private;
1270 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
1273 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
1274 SLAP_X_ORDERED_FMT "%s", i,
1275 mp->mp_loads[i].bv_val );
1276 if ( bv.bv_len >= sizeof( c->log ) ) {
1277 ber_bvarray_free_x( c->rvalue_vals, NULL );
1278 c->rvalue_vals = NULL;
1281 value_add_one( &c->rvalue_vals, &bv );
1285 rc = c->rvalue_vals ? 0 : 1;
1289 ModPaths *mp = c->ca_private;
1290 if ( !BER_BVISNULL( &mp->mp_path ))
1291 value_add_one( &c->rvalue_vals, &mp->mp_path );
1293 rc = c->rvalue_vals ? 0 : 1;
1299 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1300 if ( !c->rvalue_vals ) rc = 1;
1303 #ifdef SLAP_AUTH_REWRITE
1305 if ( authz_rewrites ) {
1306 struct berval bv, idx;
1311 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1312 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1313 if ( idx.bv_len >= sizeof( ibuf ) ) {
1314 ber_bvarray_free_x( c->rvalue_vals, NULL );
1315 c->rvalue_vals = NULL;
1318 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1319 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1320 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1321 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1322 authz_rewrites[i].bv_val,
1323 authz_rewrites[i].bv_len + 1 );
1324 ber_bvarray_add( &c->rvalue_vals, &bv );
1327 if ( !c->rvalue_vals ) rc = 1;
1334 } else if ( c->op == LDAP_MOD_DELETE ) {
1337 /* single-valued attrs, no-ops */
1347 case CFG_MONITORING:
1349 case CFG_SSTR_IF_MAX:
1350 case CFG_SSTR_IF_MIN:
1352 case CFG_SYNC_SUBENTRY:
1355 /* no-ops, requires slapd restart */
1360 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1363 case CFG_MIRRORMODE:
1364 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MULTI_SHADOW;
1365 if(SLAP_SHADOW(c->be))
1366 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1369 #if defined(HAVE_CYRUS_SASL) && defined(SLAP_AUXPROP_DONTUSECOPY)
1371 if ( c->valx < 0 ) {
1372 if ( slap_dontUseCopy_propnames != NULL ) {
1373 ber_bvarray_free( slap_dontUseCopy_propnames );
1374 slap_dontUseCopy_propnames = NULL;
1380 if ( slap_dontUseCopy_propnames == NULL ) {
1385 for ( i = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ i ] ) && i < c->valx; i++ );
1386 if ( i < c->valx ) {
1390 ber_memfree( slap_dontUseCopy_propnames[ i ].bv_val );
1391 for ( ; !BER_BVISNULL( &slap_dontUseCopy_propnames[ i + 1 ] ); i++ ) {
1392 slap_dontUseCopy_propnames[ i ] = slap_dontUseCopy_propnames[ i + 1 ];
1394 BER_BVZERO( &slap_dontUseCopy_propnames[ i ] );
1397 #endif /* SLAP_AUXPROP_DONTUSECOPY */
1399 ch_free( passwd_salt );
1404 ch_free( logfileName );
1412 case CFG_SERVERID: {
1413 ServerID *si, **sip;
1415 for ( i=0, si = sid_list, sip = &sid_list;
1416 si; si = *sip, i++ ) {
1417 if ( c->valx == -1 || i == c->valx ) {
1419 if ( sid_set == si )
1431 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1436 c->bi->bi_flags &= ~SLAP_DBFLAG_DISABLED;
1437 if ( c->bi->bi_db_open ) {
1438 BackendInfo *bi_orig = c->be->bd_info;
1439 c->be->bd_info = c->bi;
1440 rc = c->bi->bi_db_open( c->be, &c->reply );
1441 c->be->bd_info = bi_orig;
1444 c->be->be_flags &= ~SLAP_DBFLAG_DISABLED;
1445 rc = backend_startup_one( c->be, &c->reply );
1454 index_intlen = SLAP_INDEX_INTLEN_DEFAULT;
1455 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1456 SLAP_INDEX_INTLEN_DEFAULT );
1460 if ( c->valx < 0 ) {
1461 acl_destroy( c->be->be_acl );
1462 c->be->be_acl = NULL;
1465 AccessControl **prev, *a;
1467 for (i=0, prev = &c->be->be_acl; i < c->valx;
1470 prev = &a->acl_next;
1473 *prev = a->acl_next;
1476 if ( SLAP_CONFIG( c->be ) && !c->be->be_acl ) {
1477 Debug( LDAP_DEBUG_CONFIG, "config_generic (CFG_ACL): "
1478 "Last explicit ACL for back-config removed. "
1479 "Using hardcoded default\n", 0, 0, 0 );
1480 c->be->be_acl = defacl_parsed;
1486 /* Can be NULL when undoing a failed add */
1487 if ( c->ca_entry ) {
1488 ce = c->ca_entry->e_private;
1489 /* can't modify the hardcoded schema */
1490 if ( ce->ce_parent->ce_type == Cft_Global )
1494 cfn = c->ca_private;
1495 if ( c->valx < 0 ) {
1498 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1500 if ( oc == cfn->c_oc_tail )
1503 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1505 ObjectClass *oc, *prev = NULL;
1507 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1512 if ( cfn->c_oc_tail == oc ) {
1513 cfn->c_oc_tail = prev;
1515 if ( cfn->c_oc_head == oc ) {
1517 cfn->c_oc_head = oc;
1524 /* Can be NULL when undoing a failed add */
1525 if ( c->ca_entry ) {
1526 ce = c->ca_entry->e_private;
1527 /* can't modify the hardcoded schema */
1528 if ( ce->ce_parent->ce_type == Cft_Global )
1532 cfn = c->ca_private;
1533 if ( c->valx < 0 ) {
1536 for( at = cfn->c_at_head; at; at_next( &at )) {
1538 if ( at == cfn->c_at_tail )
1541 cfn->c_at_head = cfn->c_at_tail = NULL;
1543 AttributeType *at, *prev = NULL;
1545 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1550 if ( cfn->c_at_tail == at ) {
1551 cfn->c_at_tail = prev;
1553 if ( cfn->c_at_head == at ) {
1555 cfn->c_at_head = at;
1562 /* Can be NULL when undoing a failed add */
1563 if ( c->ca_entry ) {
1564 ce = c->ca_entry->e_private;
1565 /* can't modify the hardcoded schema */
1566 if ( ce->ce_parent->ce_type == Cft_Global )
1570 cfn = c->ca_private;
1571 if ( c->valx < 0 ) {
1574 for( syn = cfn->c_syn_head; syn; syn_next( &syn )) {
1576 if ( syn == cfn->c_syn_tail )
1579 cfn->c_syn_head = cfn->c_syn_tail = NULL;
1581 Syntax *syn, *prev = NULL;
1583 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++) {
1588 if ( cfn->c_syn_tail == syn ) {
1589 cfn->c_syn_tail = prev;
1591 if ( cfn->c_syn_head == syn ) {
1593 cfn->c_syn_head = syn;
1598 if ( c->valx < 0 ) {
1600 for ( sv = sortVals; sv; sv = sortVals ) {
1601 sortVals = sv->al_next;
1602 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1609 for ( prev = &sortVals, sv = sortVals; i < c->valx; i++ ) {
1610 prev = &sv->al_next;
1613 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1614 *prev = sv->al_next;
1620 /* FIXME: there is no limits_free function */
1621 if ( c->valx < 0 ) {
1622 limits_destroy( c->be->be_limits );
1623 c->be->be_limits = NULL;
1628 if ( c->be->be_limits ) {
1629 for ( num = 0; c->be->be_limits[ num ]; num++ )
1633 if ( c->valx >= num ) {
1638 limits_destroy( c->be->be_limits );
1639 c->be->be_limits = NULL;
1642 limits_free_one( c->be->be_limits[ c->valx ] );
1644 for ( cnt = c->valx; cnt < num; cnt++ ) {
1645 c->be->be_limits[ cnt ] = c->be->be_limits[ cnt + 1 ];
1652 /* FIXME: there is no ad_option_free function */
1654 /* FIXME: there is no way to remove attributes added by
1668 if(!(c->bi = backend_info(c->argv[1]))) {
1669 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1670 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1671 c->log, c->cr_msg, c->argv[1] );
1678 /* NOTE: config is always the first backend!
1680 if ( !strcasecmp( c->argv[1], "config" )) {
1681 c->be = LDAP_STAILQ_FIRST(&backendDB);
1682 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1685 c->be = backend_db_init(c->argv[1], NULL, c->valx, &c->reply);
1687 if ( c->cr_msg[0] == 0 )
1688 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1689 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n", c->log, c->cr_msg, c->argv[1] );
1696 ldap_pvt_thread_set_concurrency(c->value_int);
1700 if ( c->value_int < 2 ) {
1701 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1702 "threads=%d smaller than minimum value 2",
1704 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1705 c->log, c->cr_msg, 0 );
1708 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1709 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1710 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1711 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1712 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1713 c->log, c->cr_msg, 0 );
1715 if ( slapMode & SLAP_SERVER_MODE )
1716 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1717 connection_pool_max = c->value_int; /* save for reference */
1721 if ( c->value_int < 1 ) {
1722 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1723 "threadqueuess=%d smaller than minimum value 1",
1725 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1726 c->log, c->cr_msg, 0 );
1729 if ( slapMode & SLAP_SERVER_MODE )
1730 ldap_pvt_thread_pool_queues(&connection_pool, c->value_int);
1731 connection_pool_queues = c->value_int; /* save for reference */
1735 if ( slapMode & SLAP_TOOL_MODE )
1736 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1737 slap_tool_thread_max = c->value_int; /* save for reference */
1742 /* use a power of two */
1743 while (c->value_uint > 1) {
1744 c->value_uint >>= 1;
1748 slapd_daemon_mask = mask;
1749 slapd_daemon_threads = mask+1;
1754 if ( passwd_salt ) ch_free( passwd_salt );
1755 passwd_salt = c->value_string;
1756 lutil_salt_format(passwd_salt);
1760 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1766 c->be->be_restrictops |= SLAP_RESTRICT_READONLY;
1768 c->be->be_restrictops &= ~SLAP_RESTRICT_READONLY;
1772 ch_free(c->value_string);
1773 if (slap_sasl_setpolicy( c->argv[1] )) {
1774 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
1775 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1776 c->log, c->cr_msg, c->argv[1] );
1782 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1786 #ifdef HAVE_CYRUS_SASL
1787 #ifdef SLAP_AUXPROP_DONTUSECOPY
1791 for ( arg = 1; arg < c->argc; arg++ ) {
1792 int duplicate = 0, err;
1793 AttributeDescription *ad = NULL;
1794 const char *text = NULL;
1796 err = slap_str2ad( c->argv[ arg ], &ad, &text );
1797 if ( err != LDAP_SUCCESS ) {
1798 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s>: attr #%d (\"%s\") unknown (err=%d \"%s\"; ignored)",
1799 c->argv[0], arg, c->argv[ arg ], err, text );
1800 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1801 c->log, c->cr_msg, 0 );
1804 if ( slap_dontUseCopy_propnames != NULL ) {
1805 for ( cnt = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ cnt ] ); cnt++ ) {
1806 if ( bvmatch( &slap_dontUseCopy_propnames[ cnt ], &ad->ad_cname ) ) {
1814 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s>: attr #%d (\"%s\") already defined (ignored)",
1815 c->argv[0], arg, ad->ad_cname.bv_val);
1816 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1817 c->log, c->cr_msg, 0 );
1821 value_add_one( &slap_dontUseCopy_propnames, &ad->ad_cname );
1826 #endif /* SLAP_AUXPROP_DONTUSECOPY */
1830 char *txt = slap_sasl_secprops( c->argv[1] );
1832 snprintf( c->cr_msg, sizeof(c->cr_msg), "<%s> %s",
1834 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0 );
1842 c->be->be_max_deref_depth = c->value_int;
1848 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1849 cfn = c->ca_private;
1850 if(parse_oidm(c, 1, &om))
1852 if (!cfn->c_om_head) cfn->c_om_head = om;
1853 cfn->c_om_tail = om;
1858 ObjectClass *oc, *prev;
1860 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1861 cfn = c->ca_private;
1862 if ( c->valx < 0 ) {
1863 prev = cfn->c_oc_tail;
1866 /* If adding anything after the first, prev is easy */
1869 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
1871 if ( !oc_next( &oc ))
1875 /* If adding the first, and head exists, find its prev */
1876 if (cfn->c_oc_head) {
1877 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
1882 /* else prev is NULL, append to end of global list */
1884 if(parse_oc(c, &oc, prev)) return(1);
1885 if (!cfn->c_oc_head || !c->valx) cfn->c_oc_head = oc;
1886 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
1891 AttributeType *at, *prev;
1893 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1894 cfn = c->ca_private;
1895 if ( c->valx < 0 ) {
1896 prev = cfn->c_at_tail;
1899 /* If adding anything after the first, prev is easy */
1902 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
1904 if ( !at_next( &at ))
1908 /* If adding the first, and head exists, find its prev */
1909 if (cfn->c_at_head) {
1910 for ( at_start( &at ); at != cfn->c_at_head; ) {
1915 /* else prev is NULL, append to end of global list */
1917 if(parse_at(c, &at, prev)) return(1);
1918 if (!cfn->c_at_head || !c->valx) cfn->c_at_head = at;
1919 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
1926 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1927 cfn = c->ca_private;
1928 if ( c->valx < 0 ) {
1929 prev = cfn->c_syn_tail;
1932 /* If adding anything after the first, prev is easy */
1935 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++ ) {
1937 if ( !syn_next( &syn ))
1941 /* If adding the first, and head exists, find its prev */
1942 if (cfn->c_syn_head) {
1943 for ( syn_start( &syn ); syn != cfn->c_syn_head; ) {
1948 /* else prev is NULL, append to end of global list */
1950 if ( parse_syn( c, &syn, prev ) ) return(1);
1951 if ( !cfn->c_syn_head || !c->valx ) cfn->c_syn_head = syn;
1952 if ( cfn->c_syn_tail == prev ) cfn->c_syn_tail = syn;
1959 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1960 cfn = c->ca_private;
1961 if(parse_cr(c, &cr)) return(1);
1962 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1963 cfn->c_cr_tail = cr;
1968 ad_define_option(NULL, NULL, 0);
1969 for(i = 1; i < c->argc; i++)
1970 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1975 if ( slap_hash64( c->value_int != 0 ))
1980 if ( c->value_int < SLAP_INDEX_INTLEN_DEFAULT )
1981 c->value_int = SLAP_INDEX_INTLEN_DEFAULT;
1982 else if ( c->value_int > 255 )
1984 index_intlen = c->value_int;
1985 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1989 case CFG_SORTVALS: {
1990 ADlist *svnew = NULL, *svtail, *sv;
1992 for ( i = 1; i < c->argc; i++ ) {
1993 AttributeDescription *ad = NULL;
1997 rc = slap_str2ad( c->argv[i], &ad, &text );
1999 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown attribute type #%d",
2002 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2003 c->log, c->cr_msg, c->argv[i] );
2004 for ( sv = svnew; sv; sv = svnew ) {
2005 svnew = sv->al_next;
2010 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) ||
2011 ad->ad_type->sat_single_value ) {
2012 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> inappropriate attribute type #%d",
2014 goto sortval_reject;
2016 sv = ch_malloc( sizeof( ADlist ));
2021 svtail->al_next = sv;
2026 for ( sv = svnew; sv; sv = sv->al_next )
2027 sv->al_desc->ad_type->sat_flags |= SLAP_AT_SORTED_VAL;
2028 for ( sv = sortVals; sv && sv->al_next; sv = sv->al_next );
2030 sv->al_next = svnew;
2037 if ( SLAP_CONFIG( c->be ) && c->be->be_acl == defacl_parsed) {
2038 c->be->be_acl = NULL;
2040 /* Don't append to the global ACL if we're on a specific DB */
2042 if ( c->valx == -1 ) {
2045 for ( a=c->be->be_acl; a; a = a->acl_next )
2048 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
2049 if ( SLAP_CONFIG( c->be ) && !c->be->be_acl) {
2050 c->be->be_acl = defacl_parsed;
2058 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_ACL_ADD;
2060 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_ACL_ADD;
2064 if(root_dse_read_file(c->argv[1])) {
2065 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> could not read file", c->argv[0] );
2066 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2067 c->log, c->cr_msg, c->argv[1] );
2072 ber_str2bv( c->argv[1], 0, 1, &bv );
2073 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
2074 cfn = c->ca_private;
2075 ber_bvarray_add( &cfn->c_dseFiles, &bv );
2081 ServerID *si, **sip;
2084 if (( lutil_atoi( &num, c->argv[1] ) &&
2085 lutil_atoix( &num, c->argv[1], 16 )) ||
2086 num < 0 || num > SLAP_SYNC_SID_MAX )
2088 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2089 "<%s> illegal server ID", c->argv[0] );
2090 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2091 c->log, c->cr_msg, c->argv[1] );
2094 /* only one value allowed if no URL is given */
2095 if ( c->argc > 2 ) {
2098 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
2099 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2100 "<%s> only one server ID allowed now", c->argv[0] );
2101 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2102 c->log, c->cr_msg, c->argv[1] );
2106 if ( ldap_url_parse( c->argv[2], &lud )) {
2107 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2108 "<%s> invalid URL", c->argv[0] );
2109 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2110 c->log, c->cr_msg, c->argv[2] );
2113 len = strlen( c->argv[2] );
2114 si = ch_malloc( sizeof(ServerID) + len + 1 );
2115 si->si_url.bv_val = (char *)(si+1);
2116 si->si_url.bv_len = len;
2117 strcpy( si->si_url.bv_val, c->argv[2] );
2120 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2121 "<%s> unqualified server ID not allowed now", c->argv[0] );
2122 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2123 c->log, c->cr_msg, c->argv[1] );
2126 si = ch_malloc( sizeof(ServerID) );
2127 BER_BVZERO( &si->si_url );
2128 slap_serverID = num;
2129 Debug( LDAP_DEBUG_CONFIG,
2131 c->log, slap_serverID, 0 );
2136 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
2139 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
2140 Listener *l = config_check_my_url( c->argv[2], lud );
2143 ldap_free_urldesc( lud );
2144 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2145 "<%s> multiple server ID URLs matched, only one is allowed", c->argv[0] );
2146 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2147 c->log, c->cr_msg, c->argv[1] );
2150 slap_serverID = si->si_num;
2151 Debug( LDAP_DEBUG_CONFIG,
2152 "%s: SID=0x%03x (listener=%s)\n",
2153 c->log, slap_serverID,
2159 ldap_free_urldesc( lud );
2163 if ( logfileName ) ch_free( logfileName );
2164 logfileName = c->value_string;
2165 logfile = fopen(logfileName, "w");
2166 if(logfile) lutil_debug_file(logfile);
2170 if(SLAP_NOLASTMODCMD(c->be)) {
2171 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> not available for %s database",
2172 c->argv[0], c->be->bd_info->bi_type );
2173 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2174 c->log, c->cr_msg, 0 );
2178 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
2180 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
2183 case CFG_MIRRORMODE:
2184 if(c->value_int && !SLAP_SHADOW(c->be)) {
2185 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database is not a shadow",
2187 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2188 c->log, c->cr_msg, 0 );
2192 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
2193 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MULTI_SHADOW;
2195 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
2196 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MULTI_SHADOW;
2200 case CFG_MONITORING:
2202 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
2204 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
2210 if ( c->bi->bi_db_close ) {
2211 BackendInfo *bi_orig = c->be->bd_info;
2212 c->be->bd_info = c->bi;
2213 c->bi->bi_db_close( c->be, &c->reply );
2214 c->be->bd_info = bi_orig;
2216 c->bi->bi_flags |= SLAPO_BFLAG_DISABLED;
2218 c->bi->bi_flags &= ~SLAPO_BFLAG_DISABLED;
2222 backend_shutdown( c->be );
2223 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_DISABLED;
2225 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_DISABLED;
2232 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
2234 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
2237 case CFG_SYNC_SUBENTRY:
2239 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SYNC_SUBENTRY;
2241 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SYNC_SUBENTRY;
2244 case CFG_SSTR_IF_MAX:
2245 if (c->value_uint < index_substr_if_minlen) {
2246 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
2247 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
2248 c->log, c->cr_msg, c->value_int );
2251 index_substr_if_maxlen = c->value_uint;
2254 case CFG_SSTR_IF_MIN:
2255 if (c->value_uint > index_substr_if_maxlen) {
2256 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
2257 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
2258 c->log, c->cr_msg, c->value_int );
2261 index_substr_if_minlen = c->value_uint;
2264 #ifdef SLAPD_MODULES
2266 /* If we're just adding a module on an existing modpath,
2267 * make sure we've selected the current path.
2269 if ( c->op == LDAP_MOD_ADD && c->ca_private && modcur != c->ca_private ) {
2270 modcur = c->ca_private;
2271 /* This should never fail */
2272 if ( module_path( modcur->mp_path.bv_val )) {
2273 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> module path no longer valid",
2275 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2276 c->log, c->cr_msg, modcur->mp_path.bv_val );
2280 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
2282 /* Record this load on the current path */
2286 if ( c->op == SLAP_CONFIG_ADD ) {
2287 ptr = c->line + STRLENOF("moduleload");
2288 while (!isspace((unsigned char) *ptr)) ptr++;
2289 while (isspace((unsigned char) *ptr)) ptr++;
2293 ber_str2bv(ptr, 0, 1, &bv);
2294 ber_bvarray_add( &modcur->mp_loads, &bv );
2296 /* Check for any new hardcoded schema */
2297 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
2298 config_check_schema( NULL, &cfBackInfo );
2303 if(module_path(c->argv[1])) return(1);
2304 /* Record which path was used with each module */
2308 if (!modpaths.mp_loads) {
2311 mp = ch_malloc( sizeof( ModPaths ));
2312 modlast->mp_next = mp;
2314 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
2316 mp->mp_loads = NULL;
2327 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
2329 slapi_plugins_used++;
2333 #ifdef SLAP_AUTH_REWRITE
2339 if ( c->op == LDAP_MOD_ADD ) {
2343 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
2347 if ( c->argc > 1 ) {
2350 /* quote all args but the first */
2351 line = ldap_charray2str( c->argv, "\" \"" );
2352 ber_str2bv( line, 0, 0, &bv );
2353 s = ber_bvchr( &bv, '"' );
2354 assert( s != NULL );
2355 /* move the trailing quote of argv[0] to the end */
2356 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
2357 bv.bv_val[ bv.bv_len - 1 ] = '"';
2360 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
2363 ber_bvarray_add( &authz_rewrites, &bv );
2365 if ( c->op == LDAP_MOD_ADD ) {
2375 Debug( LDAP_DEBUG_ANY,
2376 "%s: unknown CFG_TYPE %d.\n",
2377 c->log, c->type, 0 );
2386 config_fname(ConfigArgs *c) {
2387 if(c->op == SLAP_CONFIG_EMIT) {
2388 if (c->ca_private) {
2389 ConfigFile *cf = c->ca_private;
2390 value_add_one( &c->rvalue_vals, &cf->c_file );
2399 config_cfdir(ConfigArgs *c) {
2400 if(c->op == SLAP_CONFIG_EMIT) {
2401 if ( !BER_BVISEMPTY( &cfdir )) {
2402 value_add_one( &c->rvalue_vals, &cfdir );
2411 config_search_base(ConfigArgs *c) {
2412 if(c->op == SLAP_CONFIG_EMIT) {
2414 if (!BER_BVISEMPTY(&default_search_base)) {
2415 value_add_one(&c->rvalue_vals, &default_search_base);
2416 value_add_one(&c->rvalue_nvals, &default_search_nbase);
2420 } else if( c->op == LDAP_MOD_DELETE ) {
2421 ch_free( default_search_base.bv_val );
2422 ch_free( default_search_nbase.bv_val );
2423 BER_BVZERO( &default_search_base );
2424 BER_BVZERO( &default_search_nbase );
2428 if(c->bi || c->be != frontendDB) {
2429 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
2430 "prior to any backend or database definition\n",
2435 if(default_search_nbase.bv_len) {
2436 free(default_search_base.bv_val);
2437 free(default_search_nbase.bv_val);
2440 default_search_base = c->value_dn;
2441 default_search_nbase = c->value_ndn;
2445 /* For RE23 compatibility we allow this in the global entry
2446 * but we now defer it to the frontend entry to allow modules
2447 * to load new hash types.
2450 config_passwd_hash(ConfigArgs *c) {
2452 if (c->op == SLAP_CONFIG_EMIT) {
2454 /* Don't generate it in the global entry */
2455 if ( c->table == Cft_Global )
2457 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
2458 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
2459 value_add_one(&c->rvalue_vals, &bv);
2462 } else if ( c->op == LDAP_MOD_DELETE ) {
2463 /* Deleting from global is a no-op, only the frontendDB entry matters */
2464 if ( c->table == Cft_Global )
2466 if ( c->valx < 0 ) {
2467 ldap_charray_free( default_passwd_hash );
2468 default_passwd_hash = NULL;
2471 ch_free( default_passwd_hash[i] );
2472 for (; default_passwd_hash[i]; i++ )
2473 default_passwd_hash[i] = default_passwd_hash[i+1];
2477 for(i = 1; i < c->argc; i++) {
2478 if(!lutil_passwd_scheme(c->argv[i])) {
2479 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> scheme not available", c->argv[0] );
2480 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2481 c->log, c->cr_msg, c->argv[i]);
2483 ldap_charray_add(&default_passwd_hash, c->argv[i]);
2486 if(!default_passwd_hash) {
2487 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> no valid hashes found", c->argv[0] );
2488 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2489 c->log, c->cr_msg, 0 );
2496 config_schema_dn(ConfigArgs *c) {
2497 if ( c->op == SLAP_CONFIG_EMIT ) {
2499 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
2500 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
2501 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
2505 } else if ( c->op == LDAP_MOD_DELETE ) {
2506 ch_free( c->be->be_schemadn.bv_val );
2507 ch_free( c->be->be_schemandn.bv_val );
2508 BER_BVZERO( &c->be->be_schemadn );
2509 BER_BVZERO( &c->be->be_schemandn );
2512 ch_free( c->be->be_schemadn.bv_val );
2513 ch_free( c->be->be_schemandn.bv_val );
2514 c->be->be_schemadn = c->value_dn;
2515 c->be->be_schemandn = c->value_ndn;
2520 config_sizelimit(ConfigArgs *c) {
2522 struct slap_limits_set *lim = &c->be->be_def_limit;
2523 if (c->op == SLAP_CONFIG_EMIT) {
2528 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
2529 if ( !BER_BVISEMPTY( &bv ))
2530 value_add_one( &c->rvalue_vals, &bv );
2534 } else if ( c->op == LDAP_MOD_DELETE ) {
2535 /* Reset to defaults or values from frontend */
2536 if ( c->be == frontendDB ) {
2537 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
2538 lim->lms_s_hard = 0;
2539 lim->lms_s_unchecked = -1;
2541 lim->lms_s_pr_hide = 0;
2542 lim->lms_s_pr_total = 0;
2544 lim->lms_s_soft = frontendDB->be_def_limit.lms_s_soft;
2545 lim->lms_s_hard = frontendDB->be_def_limit.lms_s_hard;
2546 lim->lms_s_unchecked = frontendDB->be_def_limit.lms_s_unchecked;
2547 lim->lms_s_pr = frontendDB->be_def_limit.lms_s_pr;
2548 lim->lms_s_pr_hide = frontendDB->be_def_limit.lms_s_pr_hide;
2549 lim->lms_s_pr_total = frontendDB->be_def_limit.lms_s_pr_total;
2553 for(i = 1; i < c->argc; i++) {
2554 if(!strncasecmp(c->argv[i], "size", 4)) {
2555 rc = limits_parse_one(c->argv[i], lim);
2557 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2558 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2559 c->log, c->cr_msg, c->argv[i]);
2563 if(!strcasecmp(c->argv[i], "unlimited")) {
2564 lim->lms_s_soft = -1;
2566 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
2567 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2568 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2569 c->log, c->cr_msg, c->argv[i]);
2573 lim->lms_s_hard = 0;
2578 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2579 /* This is a modification to the global limits apply it to
2580 * the other databases as needed */
2581 AttributeDescription *ad=NULL;
2582 const char *text = NULL;
2583 CfEntryInfo *ce = c->ca_entry->e_private;
2585 slap_str2ad(c->argv[0], &ad, &text);
2586 /* if we got here... */
2587 assert( ad != NULL );
2589 if ( ce->ce_type == Cft_Global ){
2592 for (; ce; ce=ce->ce_sibs) {
2593 Entry *dbe = ce->ce_entry;
2594 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2595 && (!attr_find(dbe->e_attrs, ad)) ) {
2596 ce->ce_be->be_def_limit.lms_s_soft = lim->lms_s_soft;
2597 ce->ce_be->be_def_limit.lms_s_hard = lim->lms_s_hard;
2598 ce->ce_be->be_def_limit.lms_s_unchecked =lim->lms_s_unchecked;
2599 ce->ce_be->be_def_limit.lms_s_pr =lim->lms_s_pr;
2600 ce->ce_be->be_def_limit.lms_s_pr_hide =lim->lms_s_pr_hide;
2601 ce->ce_be->be_def_limit.lms_s_pr_total =lim->lms_s_pr_total;
2609 config_timelimit(ConfigArgs *c) {
2611 struct slap_limits_set *lim = &c->be->be_def_limit;
2612 if (c->op == SLAP_CONFIG_EMIT) {
2617 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
2618 if ( !BER_BVISEMPTY( &bv ))
2619 value_add_one( &c->rvalue_vals, &bv );
2623 } else if ( c->op == LDAP_MOD_DELETE ) {
2624 /* Reset to defaults or values from frontend */
2625 if ( c->be == frontendDB ) {
2626 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
2627 lim->lms_t_hard = 0;
2629 lim->lms_t_soft = frontendDB->be_def_limit.lms_t_soft;
2630 lim->lms_t_hard = frontendDB->be_def_limit.lms_t_hard;
2634 for(i = 1; i < c->argc; i++) {
2635 if(!strncasecmp(c->argv[i], "time", 4)) {
2636 rc = limits_parse_one(c->argv[i], lim);
2638 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2639 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2640 c->log, c->cr_msg, c->argv[i]);
2644 if(!strcasecmp(c->argv[i], "unlimited")) {
2645 lim->lms_t_soft = -1;
2647 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
2648 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2649 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2650 c->log, c->cr_msg, c->argv[i]);
2654 lim->lms_t_hard = 0;
2659 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2660 /* This is a modification to the global limits apply it to
2661 * the other databases as needed */
2662 AttributeDescription *ad=NULL;
2663 const char *text = NULL;
2664 CfEntryInfo *ce = c->ca_entry->e_private;
2666 slap_str2ad(c->argv[0], &ad, &text);
2667 /* if we got here... */
2668 assert( ad != NULL );
2670 if ( ce->ce_type == Cft_Global ){
2673 for (; ce; ce=ce->ce_sibs) {
2674 Entry *dbe = ce->ce_entry;
2675 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2676 && (!attr_find(dbe->e_attrs, ad)) ) {
2677 ce->ce_be->be_def_limit.lms_t_soft = lim->lms_t_soft;
2678 ce->ce_be->be_def_limit.lms_t_hard = lim->lms_t_hard;
2686 config_overlay(ConfigArgs *c) {
2687 if (c->op == SLAP_CONFIG_EMIT) {
2689 } else if ( c->op == LDAP_MOD_DELETE ) {
2692 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2693 c->valx, &c->bi, &c->reply)) {
2695 Debug( LDAP_DEBUG_ANY,
2696 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2697 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2699 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi, &c->reply)) {
2706 config_subordinate(ConfigArgs *c)
2712 case SLAP_CONFIG_EMIT:
2713 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2716 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2717 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2720 value_add_one( &c->rvalue_vals, &bv );
2724 case LDAP_MOD_DELETE:
2725 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2726 glue_sub_del( c->be );
2728 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2733 case SLAP_CONFIG_ADD:
2734 if ( c->be->be_nsuffix == NULL ) {
2736 snprintf( c->cr_msg, sizeof( c->cr_msg),
2737 "subordinate configuration needs a suffix" );
2738 Debug( LDAP_DEBUG_ANY,
2740 c->log, c->cr_msg, 0 );
2745 if ( c->argc == 2 ) {
2746 if ( strcasecmp( c->argv[1], "advertise" ) == 0 ) {
2749 } else if ( strcasecmp( c->argv[1], "TRUE" ) != 0 ) {
2751 snprintf( c->cr_msg, sizeof( c->cr_msg),
2752 "subordinate must be \"TRUE\" or \"advertise\"" );
2753 Debug( LDAP_DEBUG_ANY,
2754 "%s: suffix \"%s\": %s.\n",
2755 c->log, c->be->be_suffix[0].bv_val, c->cr_msg );
2761 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2769 * [listener=<listener>] [{read|write}=]<size>
2772 #ifdef LDAP_TCP_BUFFER
2773 static BerVarray tcp_buffer;
2776 #define SLAP_TCP_RMEM (0x1U)
2777 #define SLAP_TCP_WMEM (0x2U)
2780 tcp_buffer_parse( struct berval *val, int argc, char **argv,
2781 int *size, int *rw, Listener **l )
2783 int i, rc = LDAP_SUCCESS;
2784 LDAPURLDesc *lud = NULL;
2787 if ( val != NULL && argv == NULL ) {
2788 char *s = val->bv_val;
2790 argv = ldap_str2charray( s, " \t" );
2791 if ( argv == NULL ) {
2797 if ( strncasecmp( argv[ i ], "listener=", STRLENOF( "listener=" ) )
2800 char *url = argv[ i ] + STRLENOF( "listener=" );
2802 if ( ldap_url_parse( url, &lud ) ) {
2803 rc = LDAP_INVALID_SYNTAX;
2807 *l = config_check_my_url( url, lud );
2809 rc = LDAP_NO_SUCH_ATTRIBUTE;
2817 if ( strncasecmp( ptr, "read=", STRLENOF( "read=" ) ) == 0 ) {
2818 *rw |= SLAP_TCP_RMEM;
2819 ptr += STRLENOF( "read=" );
2821 } else if ( strncasecmp( ptr, "write=", STRLENOF( "write=" ) ) == 0 ) {
2822 *rw |= SLAP_TCP_WMEM;
2823 ptr += STRLENOF( "write=" );
2826 *rw |= ( SLAP_TCP_RMEM | SLAP_TCP_WMEM );
2829 /* accept any base */
2830 if ( lutil_atoix( size, ptr, 0 ) ) {
2831 rc = LDAP_INVALID_SYNTAX;
2836 if ( val != NULL && argv != NULL ) {
2837 ldap_charray_free( argv );
2840 if ( lud != NULL ) {
2841 ldap_free_urldesc( lud );
2848 tcp_buffer_delete_one( struct berval *val )
2851 int size = -1, rw = 0;
2854 rc = tcp_buffer_parse( val, 0, NULL, &size, &rw, &l );
2861 Listener **ll = slapd_get_listeners();
2863 for ( i = 0; ll[ i ] != NULL; i++ ) {
2864 if ( ll[ i ] == l ) break;
2867 if ( ll[ i ] == NULL ) {
2868 return LDAP_NO_SUCH_ATTRIBUTE;
2871 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = -1;
2872 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = -1;
2874 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2875 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = -1;
2876 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = -1;
2880 /* NOTE: this affects listeners without a specific setting,
2881 * does not reset all listeners. If a listener without
2882 * specific settings was assigned a buffer because of
2883 * a global setting, it will not be reset. In any case,
2884 * buffer changes will only take place at restart. */
2885 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = -1;
2886 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = -1;
2893 tcp_buffer_delete( BerVarray vals )
2897 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
2898 tcp_buffer_delete_one( &vals[ i ] );
2905 tcp_buffer_unparse( int size, int rw, Listener *l, struct berval *val )
2907 char buf[sizeof("2147483648")], *ptr;
2909 /* unparse for later use */
2910 val->bv_len = snprintf( buf, sizeof( buf ), "%d", size );
2912 val->bv_len += STRLENOF( "listener=" " " ) + l->sl_url.bv_len;
2915 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2916 if ( rw & SLAP_TCP_RMEM ) {
2917 val->bv_len += STRLENOF( "read=" );
2918 } else if ( rw & SLAP_TCP_WMEM ) {
2919 val->bv_len += STRLENOF( "write=" );
2923 val->bv_val = SLAP_MALLOC( val->bv_len + 1 );
2928 ptr = lutil_strcopy( ptr, "listener=" );
2929 ptr = lutil_strncopy( ptr, l->sl_url.bv_val, l->sl_url.bv_len );
2933 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2934 if ( rw & SLAP_TCP_RMEM ) {
2935 ptr = lutil_strcopy( ptr, "read=" );
2936 } else if ( rw & SLAP_TCP_WMEM ) {
2937 ptr = lutil_strcopy( ptr, "write=" );
2941 ptr = lutil_strcopy( ptr, buf );
2944 assert( val->bv_val + val->bv_len == ptr );
2946 return LDAP_SUCCESS;
2950 tcp_buffer_add_one( int argc, char **argv )
2953 int size = -1, rw = 0;
2959 rc = tcp_buffer_parse( NULL, argc, argv, &size, &rw, &l );
2964 /* unparse for later use */
2965 rc = tcp_buffer_unparse( size, rw, l, &val );
2966 if ( rc != LDAP_SUCCESS ) {
2970 /* use parsed values */
2973 Listener **ll = slapd_get_listeners();
2975 for ( i = 0; ll[ i ] != NULL; i++ ) {
2976 if ( ll[ i ] == l ) break;
2979 if ( ll[ i ] == NULL ) {
2980 return LDAP_NO_SUCH_ATTRIBUTE;
2983 /* buffer only applies to TCP listeners;
2984 * we do not do any check here, and delegate them
2985 * to setsockopt(2) */
2986 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = size;
2987 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = size;
2989 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2990 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = size;
2991 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = size;
2995 /* NOTE: this affects listeners without a specific setting,
2996 * does not set all listeners */
2997 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = size;
2998 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = size;
3001 tcp_buffer = SLAP_REALLOC( tcp_buffer, sizeof( struct berval ) * ( tcp_buffer_num + 2 ) );
3003 tcp_buffer[ tcp_buffer_num ] = val;
3006 BER_BVZERO( &tcp_buffer[ tcp_buffer_num ] );
3012 config_tcp_buffer( ConfigArgs *c )
3014 if ( c->op == SLAP_CONFIG_EMIT ) {
3015 if ( tcp_buffer == NULL || BER_BVISNULL( &tcp_buffer[ 0 ] ) ) {
3018 value_add( &c->rvalue_vals, tcp_buffer );
3019 value_add( &c->rvalue_nvals, tcp_buffer );
3021 } else if ( c->op == LDAP_MOD_DELETE ) {
3023 tcp_buffer_delete( tcp_buffer );
3024 ber_bvarray_free( tcp_buffer );
3030 int size = -1, rw = 0;
3033 struct berval val = BER_BVNULL;
3037 if ( tcp_buffer_num == 0 ) {
3042 rc = tcp_buffer_parse( NULL, c->argc - 1, &c->argv[ 1 ], &size, &rw, &l );
3047 /* unparse for later use */
3048 rc = tcp_buffer_unparse( size, rw, l, &val );
3049 if ( rc != LDAP_SUCCESS ) {
3053 for ( i = 0; !BER_BVISNULL( &tcp_buffer[ i ] ); i++ ) {
3054 if ( bvmatch( &tcp_buffer[ i ], &val ) ) {
3059 if ( BER_BVISNULL( &tcp_buffer[ i ] ) ) {
3065 tcp_buffer_delete_one( &tcp_buffer[ i ] );
3066 ber_memfree( tcp_buffer[ i ].bv_val );
3067 for ( ; i < tcp_buffer_num; i++ ) {
3068 tcp_buffer[ i ] = tcp_buffer[ i + 1 ];
3073 if ( !BER_BVISNULL( &val ) ) {
3074 SLAP_FREE( val.bv_val );
3082 rc = tcp_buffer_add_one( c->argc - 1, &c->argv[ 1 ] );
3084 snprintf( c->cr_msg, sizeof( c->cr_msg ),
3085 "<%s> unable to add value #%d",
3086 c->argv[0], tcp_buffer_num );
3087 Debug( LDAP_DEBUG_ANY, "%s: %s\n",
3088 c->log, c->cr_msg, 0 );
3095 #endif /* LDAP_TCP_BUFFER */
3098 config_suffix(ConfigArgs *c)
3101 struct berval pdn, ndn;
3102 char *notallowed = NULL;
3104 if ( c->be == frontendDB ) {
3105 notallowed = "frontend";
3107 } else if ( SLAP_MONITOR(c->be) ) {
3108 notallowed = "monitor";
3110 } else if ( SLAP_CONFIG(c->be) ) {
3111 notallowed = "config";
3114 if ( notallowed != NULL ) {
3115 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
3119 case LDAP_MOD_DELETE:
3120 case LDAP_MOD_REPLACE:
3121 case LDAP_MOD_INCREMENT:
3122 case SLAP_CONFIG_ADD:
3123 if ( !BER_BVISNULL( &c->value_dn ) ) {
3124 snprintf( buf, sizeof( buf ), "<%s> ",
3125 c->value_dn.bv_val );
3128 Debug(LDAP_DEBUG_ANY,
3129 "%s: suffix %snot allowed in %s database.\n",
3130 c->log, buf, notallowed );
3133 case SLAP_CONFIG_EMIT:
3134 /* don't complain when emitting... */
3138 /* FIXME: don't know what values may be valid;
3139 * please remove assertion, or add legal values
3140 * to either block */
3148 if (c->op == SLAP_CONFIG_EMIT) {
3149 if ( c->be->be_suffix == NULL
3150 || BER_BVISNULL( &c->be->be_suffix[0] ) )
3154 value_add( &c->rvalue_vals, c->be->be_suffix );
3155 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
3158 } else if ( c->op == LDAP_MOD_DELETE ) {
3159 if ( c->valx < 0 ) {
3160 ber_bvarray_free( c->be->be_suffix );
3161 ber_bvarray_free( c->be->be_nsuffix );
3162 c->be->be_suffix = NULL;
3163 c->be->be_nsuffix = NULL;
3166 ch_free( c->be->be_suffix[i].bv_val );
3167 ch_free( c->be->be_nsuffix[i].bv_val );
3169 c->be->be_suffix[i] = c->be->be_suffix[i+1];
3170 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
3172 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
3177 #ifdef SLAPD_MONITOR_DN
3178 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
3179 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> DN is reserved for monitoring slapd",
3181 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3182 c->log, c->cr_msg, SLAPD_MONITOR_DN);
3187 if (SLAP_DB_ONE_SUFFIX( c->be ) && c->be->be_suffix &&
3188 !BER_BVISNULL( &c->be->be_suffix[0] )) {
3189 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> Only one suffix is allowed on this %s backend",
3190 c->argv[0], c->be->bd_info->bi_type );
3191 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3192 c->log, c->cr_msg, 0);
3199 if (SLAP_DBHIDDEN( c->be ))
3202 tbe = select_backend(&ndn, 0);
3204 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
3210 BackendDB *b2 = tbe;
3212 /* Does tbe precede be? */
3213 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
3216 char *type = tbe->bd_info->bi_type;
3218 if ( overlay_is_over( tbe ) ) {
3219 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
3220 type = oi->oi_orig->bi_type;
3223 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> namingContext \"%s\" "
3224 "already served by a preceding %s database",
3225 c->argv[0], pdn.bv_val, type );
3226 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
3227 c->log, c->cr_msg, tbe->be_suffix[0].bv_val);
3233 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
3234 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
3235 "base provided \"%s\" (assuming okay)\n",
3236 c->log, default_search_base.bv_val, 0);
3238 ber_bvarray_add(&c->be->be_suffix, &pdn);
3239 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
3244 config_rootdn(ConfigArgs *c) {
3245 if (c->op == SLAP_CONFIG_EMIT) {
3246 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
3247 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
3248 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
3253 } else if ( c->op == LDAP_MOD_DELETE ) {
3254 ch_free( c->be->be_rootdn.bv_val );
3255 ch_free( c->be->be_rootndn.bv_val );
3256 BER_BVZERO( &c->be->be_rootdn );
3257 BER_BVZERO( &c->be->be_rootndn );
3260 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
3261 ch_free( c->be->be_rootdn.bv_val );
3262 ch_free( c->be->be_rootndn.bv_val );
3264 c->be->be_rootdn = c->value_dn;
3265 c->be->be_rootndn = c->value_ndn;
3270 config_rootpw(ConfigArgs *c) {
3273 if (c->op == SLAP_CONFIG_EMIT) {
3274 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
3275 /* don't copy, because "rootpw" is marked
3277 c->value_bv = c->be->be_rootpw;
3281 } else if ( c->op == LDAP_MOD_DELETE ) {
3282 ch_free( c->be->be_rootpw.bv_val );
3283 BER_BVZERO( &c->be->be_rootpw );
3287 tbe = select_backend(&c->be->be_rootndn, 0);
3289 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> can only be set when rootdn is under suffix",
3291 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3292 c->log, c->cr_msg, 0);
3295 if ( !BER_BVISNULL( &c->be->be_rootpw ))
3296 ch_free( c->be->be_rootpw.bv_val );
3297 c->be->be_rootpw = c->value_bv;
3302 config_restrict(ConfigArgs *c) {
3303 slap_mask_t restrictops = 0;
3305 slap_verbmasks restrictable_ops[] = {
3306 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
3307 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
3308 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
3309 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
3310 { BER_BVC("modrdn"), 0 },
3311 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
3312 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
3313 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
3314 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
3315 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
3316 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
3317 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
3318 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
3319 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
3320 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
3321 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
3325 if (c->op == SLAP_CONFIG_EMIT) {
3326 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
3328 } else if ( c->op == LDAP_MOD_DELETE ) {
3330 c->be->be_restrictops = 0;
3332 i = verb_to_mask( c->line, restrictable_ops );
3333 c->be->be_restrictops &= ~restrictable_ops[i].mask;
3337 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
3339 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown operation", c->argv[0] );
3340 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3341 c->log, c->cr_msg, c->argv[i]);
3344 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
3345 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
3346 c->be->be_restrictops |= restrictops;
3351 config_allows(ConfigArgs *c) {
3352 slap_mask_t allows = 0;
3354 slap_verbmasks allowable_ops[] = {
3355 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
3356 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
3357 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
3358 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
3359 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
3362 if (c->op == SLAP_CONFIG_EMIT) {
3363 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
3364 } else if ( c->op == LDAP_MOD_DELETE ) {
3368 i = verb_to_mask( c->line, allowable_ops );
3369 global_allows &= ~allowable_ops[i].mask;
3373 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
3375 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3376 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3377 c->log, c->cr_msg, c->argv[i]);
3380 global_allows |= allows;
3385 config_disallows(ConfigArgs *c) {
3386 slap_mask_t disallows = 0;
3388 slap_verbmasks disallowable_ops[] = {
3389 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
3390 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
3391 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
3392 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
3393 { BER_BVC("proxy_authz_non_critical"), SLAP_DISALLOW_PROXY_AUTHZ_N_CRIT },
3394 { BER_BVC("dontusecopy_non_critical"), SLAP_DISALLOW_DONTUSECOPY_N_CRIT },
3397 if (c->op == SLAP_CONFIG_EMIT) {
3398 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
3399 } else if ( c->op == LDAP_MOD_DELETE ) {
3401 global_disallows = 0;
3403 i = verb_to_mask( c->line, disallowable_ops );
3404 global_disallows &= ~disallowable_ops[i].mask;
3408 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
3410 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3411 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3412 c->log, c->cr_msg, c->argv[i]);
3415 global_disallows |= disallows;
3420 config_requires(ConfigArgs *c) {
3421 slap_mask_t requires = frontendDB->be_requires;
3422 int i, argc = c->argc;
3423 char **argv = c->argv;
3425 slap_verbmasks requires_ops[] = {
3426 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
3427 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
3428 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
3429 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
3430 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
3433 if (c->op == SLAP_CONFIG_EMIT) {
3434 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
3435 } else if ( c->op == LDAP_MOD_DELETE ) {
3437 c->be->be_requires = 0;
3439 i = verb_to_mask( c->line, requires_ops );
3440 c->be->be_requires &= ~requires_ops[i].mask;
3444 /* "none" can only be first, to wipe out default/global values */
3445 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
3450 i = verbs_to_mask(argc, argv, requires_ops, &requires);
3452 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
3453 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
3454 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3455 c->log, c->cr_msg, 0);
3457 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
3458 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3459 c->log, c->cr_msg, c->argv[i]);
3463 c->be->be_requires = requires;
3468 config_extra_attrs(ConfigArgs *c)
3470 assert( c->be != NULL );
3472 if ( c->op == SLAP_CONFIG_EMIT ) {
3475 if ( c->be->be_extra_anlist == NULL ) {
3479 for ( i = 0; !BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ); i++ ) {
3480 value_add_one( &c->rvalue_vals, &c->be->be_extra_anlist[i].an_name );
3483 } else if ( c->op == LDAP_MOD_DELETE ) {
3484 if ( c->be->be_extra_anlist == NULL ) {
3488 if ( c->valx < 0 ) {
3489 anlist_free( c->be->be_extra_anlist, 1, NULL );
3490 c->be->be_extra_anlist = NULL;
3495 for ( i = 0; i < c->valx && !BER_BVISNULL( &c->be->be_extra_anlist[i + 1].an_name ); i++ )
3498 if ( BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ) ) {
3502 ch_free( c->be->be_extra_anlist[i].an_name.bv_val );
3504 for ( ; !BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ); i++ ) {
3505 c->be->be_extra_anlist[i] = c->be->be_extra_anlist[i + 1];
3510 c->be->be_extra_anlist = str2anlist( c->be->be_extra_anlist, c->argv[1], " ,\t" );
3511 if ( c->be->be_extra_anlist == NULL ) {
3519 static slap_verbmasks *loglevel_ops;
3522 loglevel_init( void )
3524 slap_verbmasks lo[] = {
3525 { BER_BVC("Any"), (slap_mask_t) LDAP_DEBUG_ANY },
3526 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
3527 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
3528 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
3529 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
3530 { BER_BVC("BER"), LDAP_DEBUG_BER },
3531 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
3532 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
3533 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
3534 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
3535 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
3536 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
3537 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
3538 #if 0 /* no longer used (nor supported) */
3539 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
3540 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
3542 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
3543 { BER_BVC("None"), LDAP_DEBUG_NONE },
3547 return slap_verbmasks_init( &loglevel_ops, lo );
3551 loglevel_destroy( void )
3553 if ( loglevel_ops ) {
3554 (void)slap_verbmasks_destroy( loglevel_ops );
3556 loglevel_ops = NULL;
3559 static slap_mask_t loglevel_ignore[] = { -1, 0 };
3562 slap_loglevel_register( slap_mask_t m, struct berval *s )
3566 if ( loglevel_ops == NULL ) {
3570 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
3573 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
3581 slap_loglevel_get( struct berval *s, int *l )
3586 if ( loglevel_ops == NULL ) {
3590 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3591 m |= loglevel_ops[ i ].mask;
3594 for ( i = 1; m & i; i <<= 1 )
3601 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
3604 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
3615 str2loglevel( const char *s, int *l )
3619 if ( loglevel_ops == NULL ) {
3623 i = verb_to_mask( s, loglevel_ops );
3625 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
3629 *l = loglevel_ops[ i ].mask;
3635 loglevel2str( int l )
3637 struct berval bv = BER_BVNULL;
3639 loglevel2bv( l, &bv );
3645 loglevel2bv( int l, struct berval *bv )
3647 if ( loglevel_ops == NULL ) {
3653 return enum_to_verb( loglevel_ops, l, bv ) == -1;
3657 loglevel2bvarray( int l, BerVarray *bva )
3659 if ( loglevel_ops == NULL ) {
3664 struct berval bv = BER_BVC("0");
3665 return value_add_one( bva, &bv );
3668 return mask_to_verbs( loglevel_ops, l, bva );
3672 loglevel_print( FILE *out )
3676 if ( loglevel_ops == NULL ) {
3680 fprintf( out, "Installed log subsystems:\n\n" );
3681 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3682 unsigned mask = loglevel_ops[ i ].mask & 0xffffffffUL;
3684 (mask == ((slap_mask_t) -1 & 0xffffffffUL)
3685 ? "\t%-30s (-1, 0xffffffff)\n" : "\t%-30s (%u, 0x%x)\n"),
3686 loglevel_ops[ i ].word.bv_val, mask, mask );
3689 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
3690 "by specific code\n\n" );
3695 static int config_syslog;
3698 config_loglevel(ConfigArgs *c) {
3701 if ( loglevel_ops == NULL ) {
3705 if (c->op == SLAP_CONFIG_EMIT) {
3706 /* Get default or commandline slapd setting */
3707 if ( ldap_syslog && !config_syslog )
3708 config_syslog = ldap_syslog;
3709 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
3711 } else if ( c->op == LDAP_MOD_DELETE ) {
3715 i = verb_to_mask( c->line, loglevel_ops );
3716 config_syslog &= ~loglevel_ops[i].mask;
3718 if ( slapMode & SLAP_SERVER_MODE ) {
3719 ldap_syslog = config_syslog;
3724 for( i=1; i < c->argc; i++ ) {
3727 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
3728 if( lutil_atoix( &level, c->argv[i], 0 ) != 0 ) {
3729 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse level", c->argv[0] );
3730 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3731 c->log, c->cr_msg, c->argv[i]);
3735 if ( str2loglevel( c->argv[i], &level ) ) {
3736 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown level", c->argv[0] );
3737 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3738 c->log, c->cr_msg, c->argv[i]);
3742 /* Explicitly setting a zero clears all the levels */
3744 config_syslog |= level;
3748 if ( slapMode & SLAP_SERVER_MODE ) {
3749 ldap_syslog = config_syslog;
3755 config_referral(ConfigArgs *c) {
3757 if (c->op == SLAP_CONFIG_EMIT) {
3758 if ( default_referral ) {
3759 value_add( &c->rvalue_vals, default_referral );
3764 } else if ( c->op == LDAP_MOD_DELETE ) {
3765 if ( c->valx < 0 ) {
3766 ber_bvarray_free( default_referral );
3767 default_referral = NULL;
3770 ch_free( default_referral[i].bv_val );
3771 for (; default_referral[i].bv_val; i++ )
3772 default_referral[i] = default_referral[i+1];
3776 if(validate_global_referral(c->argv[1])) {
3777 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3778 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3779 c->log, c->cr_msg, c->argv[1]);
3783 ber_str2bv(c->argv[1], 0, 0, &val);
3784 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
3792 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
3793 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
3794 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
3795 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
3796 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
3797 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
3798 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
3799 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
3800 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
3805 config_security(ConfigArgs *c) {
3806 slap_ssf_set_t *set = &c->be->be_ssf_set;
3809 if (c->op == SLAP_CONFIG_EMIT) {
3815 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
3816 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
3819 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
3820 if ( bv.bv_len >= sizeof( numbuf ) ) {
3821 ber_bvarray_free_x( c->rvalue_vals, NULL );
3822 c->rvalue_vals = NULL;
3826 bv.bv_len += sec_keys[i].key.bv_len;
3827 bv.bv_val = ch_malloc( bv.bv_len + 1);
3828 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
3829 strcpy( next, numbuf );
3830 ber_bvarray_add( &c->rvalue_vals, &bv );
3835 for(i = 1; i < c->argc; i++) {
3836 slap_ssf_t *tgt = NULL;
3838 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
3839 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
3840 sec_keys[j].key.bv_len)) {
3841 src = c->argv[i] + sec_keys[j].key.bv_len;
3842 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
3847 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown factor", c->argv[0] );
3848 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3849 c->log, c->cr_msg, c->argv[i]);
3853 if ( lutil_atou( tgt, src ) != 0 ) {
3854 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse factor", c->argv[0] );
3855 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3856 c->log, c->cr_msg, c->argv[i]);
3864 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
3868 for (; !BER_BVISNULL( &an->an_name ); an++) {
3869 /* if buflen == 0, assume the buffer size has been
3870 * already checked otherwise */
3871 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
3872 if ( comma ) *ptr++ = ',';
3873 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
3880 config_updatedn(ConfigArgs *c) {
3881 if (c->op == SLAP_CONFIG_EMIT) {
3882 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
3883 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
3884 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
3888 } else if ( c->op == LDAP_MOD_DELETE ) {
3889 ch_free( c->be->be_update_ndn.bv_val );
3890 BER_BVZERO( &c->be->be_update_ndn );
3891 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
3894 if(SLAP_SHADOW(c->be)) {
3895 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database already shadowed", c->argv[0] );
3896 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3897 c->log, c->cr_msg, 0);
3901 ber_memfree_x( c->value_dn.bv_val, NULL );
3902 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
3903 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
3905 c->be->be_update_ndn = c->value_ndn;
3906 BER_BVZERO( &c->value_dn );
3907 BER_BVZERO( &c->value_ndn );
3909 return config_slurp_shadow( c );
3913 config_shadow( ConfigArgs *c, slap_mask_t flag )
3915 char *notallowed = NULL;
3917 if ( c->be == frontendDB ) {
3918 notallowed = "frontend";
3920 } else if ( SLAP_MONITOR(c->be) ) {
3921 notallowed = "monitor";
3924 if ( notallowed != NULL ) {
3925 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
3929 if ( SLAP_SHADOW(c->be) ) {
3930 /* if already shadow, only check consistency */
3931 if ( ( SLAP_DBFLAGS(c->be) & flag ) != flag ) {
3932 Debug( LDAP_DEBUG_ANY, "%s: inconsistent shadow flag 0x%lx.\n",
3938 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | flag);
3939 if ( !SLAP_MULTIMASTER( c->be ))
3940 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
3947 config_updateref(ConfigArgs *c) {
3949 if (c->op == SLAP_CONFIG_EMIT) {
3950 if ( c->be->be_update_refs ) {
3951 value_add( &c->rvalue_vals, c->be->be_update_refs );
3956 } else if ( c->op == LDAP_MOD_DELETE ) {
3957 if ( c->valx < 0 ) {
3958 ber_bvarray_free( c->be->be_update_refs );
3959 c->be->be_update_refs = NULL;
3962 ch_free( c->be->be_update_refs[i].bv_val );
3963 for (; c->be->be_update_refs[i].bv_val; i++)
3964 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
3968 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
3969 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must appear after syncrepl or updatedn",
3971 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3972 c->log, c->cr_msg, 0);
3976 if(validate_global_referral(c->argv[1])) {
3977 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3978 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3979 c->log, c->cr_msg, c->argv[1]);
3982 ber_str2bv(c->argv[1], 0, 0, &val);
3983 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
3988 config_obsolete(ConfigArgs *c) {
3989 if (c->op == SLAP_CONFIG_EMIT)
3992 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> keyword is obsolete (ignored)",
3994 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0);
3999 config_include(ConfigArgs *c) {
4000 int savelineno = c->lineno;
4003 ConfigFile *cfsave = cfn;
4004 ConfigFile *cf2 = NULL;
4006 /* Leftover from RE23. No dynamic config for include files */
4007 if ( c->op == SLAP_CONFIG_EMIT || c->op == LDAP_MOD_DELETE )
4010 cf = ch_calloc( 1, sizeof(ConfigFile));
4011 if ( cfn->c_kids ) {
4012 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
4018 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
4019 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
4020 c->lineno = savelineno - 1;
4023 if ( cf2 ) cf2->c_sibs = NULL;
4024 else cfn->c_kids = NULL;
4025 ch_free( cf->c_file.bv_val );
4035 config_tls_cleanup(ConfigArgs *c) {
4038 if ( slap_tls_ld ) {
4041 ldap_pvt_tls_ctx_free( slap_tls_ctx );
4042 slap_tls_ctx = NULL;
4044 /* Force new ctx to be created */
4045 rc = ldap_pvt_tls_set_option( slap_tls_ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
4047 /* The ctx's refcount is bumped up here */
4048 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CTX, &slap_tls_ctx );
4049 /* This is a no-op if it's already loaded */
4050 load_extop( &slap_EXOP_START_TLS, 0, starttls_extop );
4052 if ( rc == LDAP_NOT_SUPPORTED )
4053 rc = LDAP_UNWILLING_TO_PERFORM;
4062 config_tls_option(ConfigArgs *c) {
4064 LDAP *ld = slap_tls_ld;
4066 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
4067 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
4068 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
4069 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
4070 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
4071 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
4072 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
4073 case CFG_TLS_ECNAME: flag = LDAP_OPT_X_TLS_ECNAME; break;
4075 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
4077 default: Debug(LDAP_DEBUG_ANY, "%s: "
4078 "unknown tls_option <0x%x>\n",
4079 c->log, c->type, 0);
4082 if (c->op == SLAP_CONFIG_EMIT) {
4083 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
4084 } else if ( c->op == LDAP_MOD_DELETE ) {
4085 c->cleanup = config_tls_cleanup;
4086 return ldap_pvt_tls_set_option( ld, flag, NULL );
4088 ch_free(c->value_string);
4089 c->cleanup = config_tls_cleanup;
4090 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
4093 /* FIXME: this ought to be provided by libldap */
4095 config_tls_config(ConfigArgs *c) {
4098 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
4099 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
4100 case CFG_TLS_PROTOCOL_MIN: flag = LDAP_OPT_X_TLS_PROTOCOL_MIN; break;
4102 Debug(LDAP_DEBUG_ANY, "%s: "
4103 "unknown tls_option <0x%x>\n",
4104 c->log, c->type, 0);
4107 if (c->op == SLAP_CONFIG_EMIT) {
4108 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
4109 } else if ( c->op == LDAP_MOD_DELETE ) {
4111 c->cleanup = config_tls_cleanup;
4112 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
4114 ch_free( c->value_string );
4115 c->cleanup = config_tls_cleanup;
4116 if ( isdigit( (unsigned char)c->argv[1][0] ) && c->type != CFG_TLS_PROTOCOL_MIN ) {
4117 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
4118 Debug(LDAP_DEBUG_ANY, "%s: "
4119 "unable to parse %s \"%s\"\n",
4120 c->log, c->argv[0], c->argv[1] );
4123 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
4125 return(ldap_pvt_tls_config(slap_tls_ld, flag, c->argv[1]));
4130 static CfEntryInfo *
4131 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
4141 if ( dn_match( &root->ce_entry->e_nname, dn ))
4144 c = dn->bv_val+dn->bv_len;
4145 for (;*c != ',';c--);
4149 for (--c;c>dn->bv_val && *c != ',';c--);
4153 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
4155 root = root->ce_kids;
4157 for (;root;root=root->ce_sibs) {
4158 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
4159 if ( cdn.bv_val == dn->bv_val ) {
4169 typedef struct setup_cookie {
4179 config_ldif_resp( Operation *op, SlapReply *rs )
4181 if ( rs->sr_type == REP_SEARCH ) {
4182 setup_cookie *sc = op->o_callback->sc_private;
4185 sc->cfb->cb_got_ldif = 1;
4186 /* Does the frontend exist? */
4187 if ( !sc->got_frontend ) {
4188 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
4189 "olcDatabase", STRLENOF( "olcDatabase" )))
4191 if ( strncmp( rs->sr_entry->e_nname.bv_val +
4192 STRLENOF( "olcDatabase" ), "={-1}frontend",
4193 STRLENOF( "={-1}frontend" )))
4197 sc->ca->be = frontendDB;
4198 sc->ca->bi = frontendDB->bd_info;
4199 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
4200 rdn.bv_val = sc->ca->log;
4201 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
4202 "%s=" SLAP_X_ORDERED_FMT "%s",
4203 cfAd_database->ad_cname.bv_val, -1,
4204 sc->ca->bi->bi_type);
4206 sc->frontend = config_build_entry( op, rs,
4207 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
4208 sc->ca->be->be_cf_ocs );
4218 dnParent( &rs->sr_entry->e_nname, &pdn );
4220 /* Does the configDB exist? */
4221 if ( sc->got_frontend && !sc->got_config &&
4222 !strncmp( rs->sr_entry->e_nname.bv_val,
4223 "olcDatabase", STRLENOF( "olcDatabase" )) &&
4224 dn_match( &config_rdn, &pdn ) )
4226 if ( strncmp( rs->sr_entry->e_nname.bv_val +
4227 STRLENOF( "olcDatabase" ), "={0}config",
4228 STRLENOF( "={0}config" )))
4232 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
4233 sc->ca->bi = sc->ca->be->bd_info;
4234 rdn.bv_val = sc->ca->log;
4235 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
4236 "%s=" SLAP_X_ORDERED_FMT "%s",
4237 cfAd_database->ad_cname.bv_val, 0,
4238 sc->ca->bi->bi_type);
4240 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
4241 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
4248 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
4249 if ( rs->sr_err != LDAP_SUCCESS ) {
4250 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
4251 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg, 0 );
4257 /* Configure and read the underlying back-ldif store */
4259 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
4260 CfBackInfo *cfb = be->be_private;
4266 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
4267 Connection conn = {0};
4268 OperationBuffer opbuf;
4270 SlapReply rs = {REP_RESULT};
4271 Filter filter = { LDAP_FILTER_PRESENT };
4272 struct berval filterstr = BER_BVC("(objectclass=*)");
4275 /* Is the config directory available? */
4276 if ( stat( dir, &st ) < 0 ) {
4277 /* No, so don't bother using the backing store.
4278 * All changes will be in-memory only.
4283 cfb->cb_db.bd_info = backend_info( "ldif" );
4284 if ( !cfb->cb_db.bd_info )
4285 return 0; /* FIXME: eventually this will be a fatal error */
4287 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
4290 cfb->cb_db.be_suffix = be->be_suffix;
4291 cfb->cb_db.be_nsuffix = be->be_nsuffix;
4293 /* The suffix is always "cn=config". The underlying DB's rootdn
4294 * is always the same as the suffix.
4296 cfb->cb_db.be_rootdn = be->be_suffix[0];
4297 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
4299 ber_str2bv( dir, 0, 1, &cfdir );
4304 argv[0] = "directory";
4305 argv[1] = (char *)dir;
4310 c.table = Cft_Database;
4312 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
4316 if ( config_add_vals( ct, &c ))
4319 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
4323 void *thrctx = ldap_pvt_thread_pool_context();
4326 connection_fake_init( &conn, &opbuf, thrctx );
4329 filter.f_desc = slap_schema.si_ad_objectClass;
4331 op->o_tag = LDAP_REQ_SEARCH;
4333 op->ors_filter = &filter;
4334 op->ors_filterstr = filterstr;
4335 op->ors_scope = LDAP_SCOPE_SUBTREE;
4337 op->o_dn = c.be->be_rootdn;
4338 op->o_ndn = c.be->be_rootndn;
4340 op->o_req_dn = be->be_suffix[0];
4341 op->o_req_ndn = be->be_nsuffix[0];
4343 op->ors_tlimit = SLAP_NO_LIMIT;
4344 op->ors_slimit = SLAP_NO_LIMIT;
4346 op->ors_attrs = slap_anlist_all_attributes;
4347 op->ors_attrsonly = 0;
4349 op->o_callback = &cb;
4352 cb.sc_private = ≻
4353 sc.got_frontend = 0;
4358 op->o_bd = &cfb->cb_db;
4360 /* Allow unknown attrs in DNs */
4361 prev_DN_strict = slap_DN_strict;
4364 rc = op->o_bd->be_search( op, &rs );
4366 /* Restore normal DN validation */
4367 slap_DN_strict = prev_DN_strict;
4369 op->o_tag = LDAP_REQ_ADD;
4370 if ( rc == LDAP_SUCCESS && sc.frontend ) {
4371 rs_reinit( &rs, REP_RESULT );
4372 op->ora_e = sc.frontend;
4373 rc = op->o_bd->be_add( op, &rs );
4375 if ( rc == LDAP_SUCCESS && sc.config ) {
4376 rs_reinit( &rs, REP_RESULT );
4377 op->ora_e = sc.config;
4378 rc = op->o_bd->be_add( op, &rs );
4380 ldap_pvt_thread_pool_context_reset( thrctx );
4383 /* ITS#4194 - only use if it's present, or we're converting. */
4384 if ( !readit || rc == LDAP_SUCCESS )
4385 cfb->cb_use_ldif = 1;
4391 CfOc_cmp( const void *c1, const void *c2 ) {
4392 const ConfigOCs *co1 = c1;
4393 const ConfigOCs *co2 = c2;
4395 return ber_bvcmp( co1->co_name, co2->co_name );
4399 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
4402 i = init_config_attrs( ct );
4405 /* set up the objectclasses */
4406 i = init_config_ocs( ocs );
4409 for (i=0; ocs[i].co_def; i++) {
4410 if ( ocs[i].co_oc ) {
4411 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
4412 if ( !ocs[i].co_table )
4413 ocs[i].co_table = ct;
4414 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
4421 read_config(const char *fname, const char *dir) {
4424 const char *cfdir, *cfname;
4427 /* Setup the config backend */
4428 be = backend_db_init( "config", NULL, 0, NULL );
4432 cfb = be->be_private;
4433 be->be_dfltaccess = ACL_NONE;
4435 /* If no .conf, or a dir was specified, setup the dir */
4436 if ( !fname || dir ) {
4438 /* If explicitly given, check for existence */
4441 if ( stat( dir, &st ) < 0 ) {
4442 Debug( LDAP_DEBUG_ANY,
4443 "invalid config directory %s, error %d\n",
4449 cfdir = SLAPD_DEFAULT_CONFIGDIR;
4451 /* if fname is defaulted, try reading .d */
4452 rc = config_setup_ldif( be, cfdir, !fname );
4455 /* It may be OK if the base object doesn't exist yet. */
4456 if ( rc != LDAP_NO_SUCH_OBJECT )
4458 /* ITS#4194: But if dir was specified and no fname,
4459 * then we were supposed to read the dir. Unless we're
4460 * trying to slapadd the dir...
4462 if ( dir && !fname ) {
4463 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
4465 /* Assume it's slapadd with a config dir, let it continue */
4467 cfb->cb_got_ldif = 1;
4468 cfb->cb_use_ldif = 1;
4473 /* If we read the config from back-ldif, nothing to do here */
4474 if ( cfb->cb_got_ldif ) {
4483 cfname = SLAPD_DEFAULT_CONFIGFILE;
4485 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
4488 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
4491 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
4492 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
4493 &frontendDB->be_schemadn );
4494 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
4495 if ( rc != LDAP_SUCCESS ) {
4496 Debug(LDAP_DEBUG_ANY, "read_config: "
4497 "unable to normalize default schema DN \"%s\"\n",
4498 frontendDB->be_schemadn.bv_val, 0, 0 );
4499 /* must not happen */
4503 if ( rc == 0 && ( slapMode & SLAP_SERVER_MODE ) && sid_list ) {
4504 if ( !BER_BVISEMPTY( &sid_list->si_url ) && !sid_set ) {
4505 Debug(LDAP_DEBUG_ANY, "read_config: no serverID / URL match found. "
4506 "Check slapd -h arguments.\n", 0,0,0 );
4514 config_back_bind( Operation *op, SlapReply *rs )
4516 if ( be_isroot_pw( op ) ) {
4517 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
4518 /* frontend sends result */
4519 return LDAP_SUCCESS;
4522 rs->sr_err = LDAP_INVALID_CREDENTIALS;
4523 send_ldap_result( op, rs );
4529 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
4533 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
4535 rs->sr_attrs = op->ors_attrs;
4536 rs->sr_entry = ce->ce_entry;
4538 rc = send_search_entry( op, rs );
4539 if ( rc != LDAP_SUCCESS ) {
4543 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
4544 if ( ce->ce_kids ) {
4545 rc = config_send( op, rs, ce->ce_kids, 1 );
4546 if ( rc ) return rc;
4549 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
4550 rc = config_send( op, rs, ce, 0 );
4558 static ConfigTable *
4559 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
4564 for (j=0; j<nocs; j++) {
4565 for (i=0; colst[j]->co_table[i].name; i++)
4566 if ( colst[j]->co_table[i].ad == ad ) {
4567 ca->table = colst[j]->co_type;
4568 return &colst[j]->co_table[i];
4574 /* Sort the attributes of the entry according to the order defined
4575 * in the objectclass, with required attributes occurring before
4576 * allowed attributes. For any attributes with sequencing dependencies
4577 * (e.g., rootDN must be defined after suffix) the objectclass must
4578 * list the attributes in the desired sequence.
4581 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
4583 Attribute *a, *head = NULL, *tail = NULL, **prev;
4586 for (i=0; i<nocs; i++) {
4587 if ( colst[i]->co_oc->soc_required ) {
4588 AttributeType **at = colst[i]->co_oc->soc_required;
4589 for (j=0; at[j]; j++) {
4590 for (a=e->e_attrs, prev=&e->e_attrs; a;
4591 prev = &(*prev)->a_next, a=a->a_next) {
4592 if ( a->a_desc == at[j]->sat_ad ) {
4606 if ( colst[i]->co_oc->soc_allowed ) {
4607 AttributeType **at = colst[i]->co_oc->soc_allowed;
4608 for (j=0; at[j]; j++) {
4609 for (a=e->e_attrs, prev=&e->e_attrs; a;
4610 prev = &(*prev)->a_next, a=a->a_next) {
4611 if ( a->a_desc == at[j]->sat_ad ) {
4627 tail->a_next = e->e_attrs;
4633 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
4635 Attribute *a = NULL;
4636 AttributeDescription *ad;
4646 Modifications *ml = ptr;
4648 vals = ml->sml_values;
4651 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
4652 rc = ordered_value_sort( a, 1 );
4654 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
4655 ad->ad_cname.bv_val );
4659 for ( i=0; vals[i].bv_val; i++ ) {
4660 ca->line = vals[i].bv_val;
4661 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
4662 ca->line[0] == '{' ) {
4663 char *idx = strchr( ca->line, '}' );
4664 if ( idx ) ca->line = idx+1;
4666 rc = config_parse_vals( ct, ca, i );
4675 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
4678 struct berval rtype, rval;
4680 AttributeDescription *ad = NULL;
4682 dnRdn( &e->e_name, rdn );
4683 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
4684 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
4685 rtype.bv_val = rdn->bv_val;
4686 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
4689 slap_bv2ad( &rtype, &ad, &rs->sr_text );
4690 a = attr_find( e->e_attrs, ad );
4691 if (!a ) return LDAP_NAMING_VIOLATION;
4698 config_rename_kids( CfEntryInfo *ce )
4701 struct berval rdn, nrdn;
4703 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
4704 struct berval newdn, newndn;
4705 dnRdn ( &ce2->ce_entry->e_name, &rdn );
4706 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
4707 build_new_dn( &newdn, &ce->ce_entry->e_name, &rdn, NULL );
4708 build_new_dn( &newndn, &ce->ce_entry->e_nname, &nrdn, NULL );
4709 free( ce2->ce_entry->e_name.bv_val );
4710 free( ce2->ce_entry->e_nname.bv_val );
4711 ce2->ce_entry->e_name = newdn;
4712 ce2->ce_entry->e_nname = newndn;
4713 config_rename_kids( ce2 );
4718 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
4719 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
4720 struct berval *nnewrdn, int use_ldif )
4724 struct berval odn, ondn;
4728 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
4729 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
4732 free( a->a_vals[0].bv_val );
4733 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
4734 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
4735 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
4736 strcpy( a->a_vals[0].bv_val, ptr1 );
4738 if ( a->a_nvals != a->a_vals ) {
4739 free( a->a_nvals[0].bv_val );
4740 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
4741 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
4742 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
4743 strcpy( a->a_nvals[0].bv_val, ptr1 );
4746 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
4747 BackendDB *be = op->o_bd;
4748 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4749 struct berval dn, ndn, xdn, xndn;
4751 op->o_bd = &cfb->cb_db;
4753 /* Save current rootdn; use the underlying DB's rootdn */
4757 xndn = op->o_req_ndn;
4758 op->o_dn = op->o_bd->be_rootdn;
4759 op->o_ndn = op->o_bd->be_rootndn;
4761 op->o_req_ndn = ondn;
4763 scp = op->o_callback;
4764 op->o_callback = ≻
4765 op->orr_newrdn = *newrdn;
4766 op->orr_nnewrdn = *nnewrdn;
4767 op->orr_newSup = NULL;
4768 op->orr_nnewSup = NULL;
4769 op->orr_deleteoldrdn = 1;
4770 op->orr_modlist = NULL;
4771 slap_modrdn2mods( op, rs );
4772 slap_mods_opattrs( op, &op->orr_modlist, 1 );
4773 rc = op->o_bd->be_modrdn( op, rs );
4774 slap_mods_free( op->orr_modlist, 1 );
4777 op->o_callback = scp;
4781 op->o_req_ndn = xndn;
4784 free( ondn.bv_val );
4786 config_rename_kids( e->e_private );
4791 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
4792 Entry *e, int idx, int tailindex, int use_ldif )
4794 struct berval ival, newrdn, nnewrdn;
4797 char ibuf[32], *ptr1, *ptr2 = NULL;
4800 rc = config_rename_attr( rs, e, &rdn, &a );
4801 if ( rc ) return rc;
4804 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
4805 if ( ival.bv_len >= sizeof( ibuf ) ) {
4806 return LDAP_NAMING_VIOLATION;
4809 newrdn.bv_len = rdn.bv_len + ival.bv_len;
4810 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
4813 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
4814 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4817 ptr2 = ber_bvchr( &rdn, '}' );
4821 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
4823 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
4824 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
4825 a->a_desc->ad_cname.bv_len );
4827 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4828 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
4832 /* Do the equivalent of ModRDN */
4833 /* Replace DN / NDN */
4834 newrdn.bv_len = ptr1 - newrdn.bv_val;
4835 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
4836 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
4838 free( nnewrdn.bv_val );
4839 free( newrdn.bv_val );
4844 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
4845 SlapReply *rs, int *renum, int *ibase )
4848 int index = -1, gotindex = 0, nsibs, rc = 0;
4849 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
4850 char *ptr1, *ptr2 = NULL;
4853 if ( renum ) *renum = 0;
4855 /* These entries don't get indexed/renumbered */
4856 if ( ce_type == Cft_Global ) return 0;
4857 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
4859 if ( ce_type == Cft_Module )
4862 /* See if the rdn has an index already */
4863 dnRdn( &e->e_name, &rdn );
4864 if ( ce_type == Cft_Database ) {
4865 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
4866 "frontend", STRLENOF("frontend") ))
4868 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
4869 "config", STRLENOF("config") ))
4872 ptr1 = ber_bvchr( &e->e_name, '{' );
4873 if ( ptr1 && ptr1 < &e->e_name.bv_val[ rdn.bv_len ] ) {
4875 ptr2 = strchr( ptr1, '}' );
4876 if ( !ptr2 || ptr2 > &e->e_name.bv_val[ rdn.bv_len ] )
4877 return LDAP_NAMING_VIOLATION;
4878 if ( ptr2-ptr1 == 1)
4879 return LDAP_NAMING_VIOLATION;
4881 index = strtol( ptr1 + 1, &next, 10 );
4882 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
4883 return LDAP_NAMING_VIOLATION;
4886 /* Special case, we allow -1 for the frontendDB */
4887 if ( index != -1 || !isfrontend )
4888 return LDAP_NAMING_VIOLATION;
4890 if ( isconfig && index != 0 ){
4891 return LDAP_NAMING_VIOLATION;
4895 /* count related kids.
4896 * For entries of type Cft_Misc, only count siblings with same RDN type
4898 if ( ce_type == Cft_Misc ) {
4899 rdn.bv_val = e->e_nname.bv_val;
4900 ptr1 = strchr( rdn.bv_val, '=' );
4901 assert( ptr1 != NULL );
4903 rdn.bv_len = ptr1 - rdn.bv_val;
4905 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
4907 if ( ce->ce_type != ce_type )
4910 dnRdn( &ce->ce_entry->e_nname, &rdn2 );
4912 ptr1 = strchr( rdn2.bv_val, '=' );
4913 assert( ptr1 != NULL );
4915 rdn2.bv_len = ptr1 - rdn2.bv_val;
4916 if ( bvmatch( &rdn, &rdn2 ))
4920 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
4921 if ( ce->ce_type == ce_type ) nsibs++;
4925 /* account for -1 frontend */
4926 if ( ce_type == Cft_Database )
4929 if ( index != nsibs ) {
4931 if ( index < nsibs ) {
4932 if ( tailindex ) return LDAP_NAMING_VIOLATION;
4933 /* Siblings need to be renumbered */
4934 if ( index != -1 || !isfrontend )
4938 /* config DB is always "0" */
4939 if ( isconfig && index == -1 ) {
4942 if (( !isfrontend && index == -1 ) || ( index > nsibs ) ){
4946 /* just make index = nsibs */
4948 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
4951 if ( ibase ) *ibase = index;
4952 if ( renum ) *renum = renumber;
4956 /* Insert all superior classes of the given class */
4958 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
4963 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
4964 if ( count_oc( *sups, copp, nocs ) ) {
4969 co.co_name = &oc->soc_cname;
4970 cop = avl_find( CfOcTree, &co, CfOc_cmp );
4974 /* check for duplicates */
4975 for ( i = 0; i < *nocs; i++ ) {
4976 if ( *copp && (*copp)[i] == cop ) {
4982 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
4983 if ( tmp == NULL ) {
4987 (*copp)[*nocs] = cop;
4995 /* Find all superior classes of the given objectclasses,
4996 * return list in order of most-subordinate first.
4998 * Special / auxiliary / Cft_Misc classes always take precedence.
5001 count_ocs( Attribute *oc_at, int *nocs )
5003 int i, j, misc = -1;
5004 ConfigOCs **colst = NULL;
5008 for ( i = oc_at->a_numvals; i--; ) {
5009 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
5011 assert( oc != NULL );
5012 if ( count_oc( oc, &colst, nocs ) ) {
5022 ConfigOCs *tmp = colst[i];
5023 colst[i] = colst[j];
5025 if (tmp->co_type == Cft_Misc)
5029 /* Move misc class to front of list */
5031 ConfigOCs *tmp = colst[misc];
5032 for (i=misc; i>0; i--)
5033 colst[i] = colst[i-1];
5041 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
5043 /* Leftover from RE23. Never parse this entry */
5044 return LDAP_COMPARE_TRUE;
5048 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
5052 /* This entry is hardcoded, don't re-parse it */
5053 if ( p->ce_type == Cft_Global ) {
5054 cfn = p->ce_private;
5055 ca->ca_private = cfn;
5056 return LDAP_COMPARE_TRUE;
5058 if ( p->ce_type != Cft_Schema )
5059 return LDAP_CONSTRAINT_VIOLATION;
5061 cfn = ch_calloc( 1, sizeof(ConfigFile) );
5062 ca->ca_private = cfn;
5063 cfo = p->ce_private;
5064 cfn->c_sibs = cfo->c_kids;
5066 return LDAP_SUCCESS;
5070 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
5072 if ( p->ce_type != Cft_Global ) {
5073 return LDAP_CONSTRAINT_VIOLATION;
5075 /* config must be {0}, nothing else allowed */
5076 if ( !strncmp( e->e_nname.bv_val, "olcDatabase={0}", STRLENOF("olcDatabase={0}")) &&
5077 strncmp( e->e_nname.bv_val + STRLENOF("olcDatabase={0}"), "config,", STRLENOF("config,") )) {
5078 return LDAP_CONSTRAINT_VIOLATION;
5080 ca->be = frontendDB; /* just to get past check_vals */
5081 return LDAP_SUCCESS;
5085 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
5087 if ( p->ce_type != Cft_Global ) {
5088 return LDAP_CONSTRAINT_VIOLATION;
5090 return LDAP_SUCCESS;
5094 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
5096 if ( p->ce_type != Cft_Global ) {
5097 return LDAP_CONSTRAINT_VIOLATION;
5099 return LDAP_SUCCESS;
5103 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
5105 if ( p->ce_type != Cft_Database ) {
5106 return LDAP_CONSTRAINT_VIOLATION;
5109 return LDAP_SUCCESS;
5113 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
5118 AttributeDescription *ad;
5124 if ( cfn->c_cr_head ) {
5125 struct berval bv = BER_BVC("olcDitContentRules");
5127 slap_bv2ad( &bv, &ad, &text );
5128 ct = config_find_table( colst, nocs, ad, ca );
5129 config_del_vals( ct, ca );
5131 if ( cfn->c_oc_head ) {
5132 struct berval bv = BER_BVC("olcObjectClasses");
5134 slap_bv2ad( &bv, &ad, &text );
5135 ct = config_find_table( colst, nocs, ad, ca );
5136 config_del_vals( ct, ca );
5138 if ( cfn->c_at_head ) {
5139 struct berval bv = BER_BVC("olcAttributeTypes");
5141 slap_bv2ad( &bv, &ad, &text );
5142 ct = config_find_table( colst, nocs, ad, ca );
5143 config_del_vals( ct, ca );
5145 if ( cfn->c_syn_head ) {
5146 struct berval bv = BER_BVC("olcLdapSyntaxes");
5148 slap_bv2ad( &bv, &ad, &text );
5149 ct = config_find_table( colst, nocs, ad, ca );
5150 config_del_vals( ct, ca );
5152 if ( cfn->c_om_head ) {
5153 struct berval bv = BER_BVC("olcObjectIdentifier");
5155 slap_bv2ad( &bv, &ad, &text );
5156 ct = config_find_table( colst, nocs, ad, ca );
5157 config_del_vals( ct, ca );
5159 cfo = p->ce_private;
5160 cfo->c_kids = cfn->c_sibs;
5165 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
5167 int rc = LDAP_CONSTRAINT_VIOLATION;
5170 if ( (*cop)->co_ldadd ) {
5171 rc = (*cop)->co_ldadd( last, e, ca );
5172 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
5177 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
5178 ConfigOCs co = { 0 };
5180 co.co_name = &(*ocp)->soc_cname;
5181 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
5182 if ( *cop == NULL ) {
5186 rc = config_add_oc( cop, last, e, ca );
5187 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
5195 /* Parse an LDAP entry into config directives */
5197 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
5198 int *renum, Operation *op )
5200 CfEntryInfo *ce, *last = NULL;
5201 ConfigOCs co, *coptr, **colst;
5202 Attribute *a, *oc_at, *soc_at;
5203 int i, ibase = -1, nocs, rc = 0;
5206 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
5208 memset( ca, 0, sizeof(ConfigArgs));
5210 /* Make sure parent exists and entry does not. But allow
5211 * Databases and Overlays to be inserted. Don't do any
5212 * auto-renumbering if manageDSAit control is present.
5214 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
5216 if ( ( op && op->o_managedsait ) ||
5217 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
5218 ce->ce_type != Cft_Module ) )
5220 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5221 "DN=\"%s\" already exists\n",
5222 log_prefix, e->e_name.bv_val, 0 );
5223 /* global schema ignores all writes */
5224 if ( ce->ce_type == Cft_Schema && ce->ce_parent->ce_type == Cft_Global )
5225 return LDAP_COMPARE_TRUE;
5226 return LDAP_ALREADY_EXISTS;
5230 dnParent( &e->e_nname, &pdn );
5232 /* If last is NULL, the new entry is the root/suffix entry,
5233 * otherwise last should be the parent.
5235 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
5237 rs->sr_matched = last->ce_entry->e_name.bv_val;
5239 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5240 "DN=\"%s\" not child of DN=\"%s\"\n",
5241 log_prefix, e->e_name.bv_val,
5242 last->ce_entry->e_name.bv_val );
5243 return LDAP_NO_SUCH_OBJECT;
5247 /* No parent, must be root. This will never happen... */
5248 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
5249 return LDAP_NO_SUCH_OBJECT;
5252 if ( last && !access_allowed( op, last->ce_entry,
5253 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
5255 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5256 "DN=\"%s\" no write access to \"children\" of parent\n",
5257 log_prefix, e->e_name.bv_val, 0 );
5258 return LDAP_INSUFFICIENT_ACCESS;
5262 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5264 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5265 "DN=\"%s\" no objectClass\n",
5266 log_prefix, e->e_name.bv_val, 0 );
5267 return LDAP_OBJECT_CLASS_VIOLATION;
5270 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
5272 ObjectClass *soc = NULL;
5273 char textbuf[ SLAP_TEXT_BUFLEN ];
5274 const char *text = textbuf;
5276 /* FIXME: check result */
5277 rc = structural_class( oc_at->a_nvals, &soc, NULL,
5278 &text, textbuf, sizeof(textbuf), NULL );
5279 if ( rc != LDAP_SUCCESS ) {
5280 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5281 "DN=\"%s\" no structural objectClass (%s)\n",
5282 log_prefix, e->e_name.bv_val, text );
5285 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
5286 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
5287 if ( soc_at == NULL ) {
5288 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5289 "DN=\"%s\" no structural objectClass; "
5290 "unable to merge computed class %s\n",
5291 log_prefix, e->e_name.bv_val,
5292 soc->soc_cname.bv_val );
5293 return LDAP_OBJECT_CLASS_VIOLATION;
5296 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5297 "DN=\"%s\" no structural objectClass; "
5298 "computed objectClass %s merged\n",
5299 log_prefix, e->e_name.bv_val,
5300 soc->soc_cname.bv_val );
5303 /* Fake the coordinates based on whether we're part of an
5304 * LDAP Add or if reading the config dir
5307 ca->fname = "slapd";
5310 ca->fname = cfdir.bv_val;
5315 co.co_name = &soc_at->a_nvals[0];
5316 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
5317 if ( coptr == NULL ) {
5318 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5319 "DN=\"%s\" no structural objectClass in configuration table\n",
5320 log_prefix, e->e_name.bv_val, 0 );
5321 return LDAP_OBJECT_CLASS_VIOLATION;
5324 /* Only the root can be Cft_Global, everything else must
5325 * have a parent. Only limited nesting arrangements are allowed.
5327 rc = LDAP_CONSTRAINT_VIOLATION;
5328 if ( coptr->co_type == Cft_Global && !last ) {
5329 cfn = cfb->cb_config;
5330 ca->ca_private = cfn;
5331 ca->be = frontendDB; /* just to get past check_vals */
5335 colst = count_ocs( oc_at, &nocs );
5337 /* Check whether the Add is allowed by its parent, and do
5338 * any necessary arg setup
5341 rc = config_add_oc( &coptr, last, e, ca );
5342 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
5343 for ( i = 0; i<nocs; i++ ) {
5344 /* Already checked these */
5345 if ( colst[i]->co_oc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
5347 if ( colst[i]->co_ldadd &&
5348 ( rc = colst[i]->co_ldadd( last, e, ca ))
5349 != LDAP_CONSTRAINT_VIOLATION ) {
5355 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
5356 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5357 "DN=\"%s\" no structural objectClass add function\n",
5358 log_prefix, e->e_name.bv_val, 0 );
5359 return LDAP_OBJECT_CLASS_VIOLATION;
5363 /* Add the entry but don't parse it, we already have its contents */
5364 if ( rc == LDAP_COMPARE_TRUE ) {
5369 if ( rc != LDAP_SUCCESS )
5372 /* Parse all the values and check for simple syntax errors before
5373 * performing any set actions.
5375 * If doing an LDAPadd, check for indexed names and any necessary
5376 * renaming/renumbering. Entries that don't need indexed names are
5377 * ignored. Entries that need an indexed name and arrive without one
5378 * are assigned to the end. Entries that arrive with an index may
5379 * cause the following entries to be renumbered/bumped down.
5381 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
5382 * don't allow Adding an entry with an index that's already in use.
5383 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
5385 * These entries can have auto-assigned indexes (appended to the end)
5386 * but only the other types support auto-renumbering of siblings.
5389 rc = check_name_index( last, coptr->co_type, e, rs, renum,
5394 if ( renum && *renum && coptr->co_type != Cft_Database &&
5395 coptr->co_type != Cft_Overlay )
5397 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
5398 "operation requires sibling renumbering" );
5399 rc = LDAP_UNWILLING_TO_PERFORM;
5404 init_config_argv( ca );
5406 /* Make sure we process attrs in the required order */
5407 sort_attrs( e, colst, nocs );
5409 for ( a = e->e_attrs; a; a = a->a_next ) {
5410 if ( a == oc_at ) continue;
5411 ct = config_find_table( colst, nocs, a->a_desc, ca );
5412 if ( !ct ) continue; /* user data? */
5413 rc = check_vals( ct, ca, a, 1 );
5414 if ( rc ) goto done_noop;
5417 /* Basic syntax checks are OK. Do the actual settings. */
5418 for ( a=e->e_attrs; a; a=a->a_next ) {
5419 if ( a == oc_at ) continue;
5420 ct = config_find_table( colst, nocs, a->a_desc, ca );
5421 if ( !ct ) continue; /* user data? */
5422 for (i=0; a->a_vals[i].bv_val; i++) {
5425 ca->line = a->a_vals[i].bv_val;
5426 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
5427 ptr = strchr( ca->line, '}' );
5429 iptr = strchr( ca->line, '{' );
5433 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
5435 ca->valx = strtol( iptr+1, NULL, 0 );
5440 rc = config_parse_add( ct, ca, i );
5448 /* Newly added databases and overlays need to be started up */
5449 if ( CONFIG_ONLINE_ADD( ca )) {
5450 if ( coptr->co_type == Cft_Database ) {
5451 rc = backend_startup_one( ca->be, &ca->reply );
5453 } else if ( coptr->co_type == Cft_Overlay ) {
5454 if ( ca->bi->bi_db_open ) {
5455 BackendInfo *bi_orig = ca->be->bd_info;
5456 ca->be->bd_info = ca->bi;
5457 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
5458 ca->be->bd_info = bi_orig;
5460 } else if ( ca->cleanup ) {
5461 rc = ca->cleanup( ca );
5464 if (ca->cr_msg[0] == '\0')
5465 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
5467 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
5468 ca->log, ca->cr_msg, ca->argv[1] );
5475 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5476 ce->ce_parent = last;
5477 ce->ce_entry = entry_dup( e );
5478 ce->ce_entry->e_private = ce;
5479 ce->ce_type = coptr->co_type;
5482 ce->ce_private = ca->ca_private;
5483 ca->ca_entry = ce->ce_entry;
5486 } else if ( last->ce_kids ) {
5487 CfEntryInfo *c2, **cprev;
5489 /* Advance to first of this type */
5490 cprev = &last->ce_kids;
5491 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
5492 cprev = &c2->ce_sibs;
5495 /* Account for the (-1) frontendDB entry */
5496 if ( ce->ce_type == Cft_Database ) {
5497 if ( ca->be == frontendDB )
5499 else if ( ibase != -1 )
5504 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
5505 cprev = &c2->ce_sibs;
5511 for ( i=0; i<ibase; i++ ) {
5513 cprev = &c2->ce_sibs;
5516 ce->ce_sibs = *cprev;
5524 if ( (coptr->co_type == Cft_Database) && ca->be ) {
5525 if ( ca->be != frontendDB )
5526 backend_destroy_one( ca->be, 1 );
5527 } else if ( (coptr->co_type == Cft_Overlay) && ca->bi ) {
5528 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
5529 } else if ( coptr->co_type == Cft_Schema ) {
5530 schema_destroy_one( ca, colst, nocs, last );
5535 ch_free( ca->argv );
5536 if ( colst ) ch_free( colst );
5540 #define BIGTMP 10000
5542 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5543 int base, int rebase, int max, int use_ldif )
5545 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
5546 ConfigType etype = ce->ce_type;
5547 int count = 0, rc = 0;
5549 /* Reverse ce list */
5550 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
5551 if (ce2->ce_type != etype) {
5556 ce2->ce_sibs = cetmp;
5559 if ( max && count >= max ) {
5565 /* Move original to a temp name until increments are done */
5567 ce->ce_entry->e_private = NULL;
5568 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5569 base+BIGTMP, 0, use_ldif );
5570 ce->ce_entry->e_private = ce;
5572 /* start incrementing */
5573 for (ce2=cetmp; ce2; ce2=ce3) {
5575 ce2->ce_sibs = cerem;
5578 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5579 count+base, 0, use_ldif );
5583 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5584 base, 0, use_ldif );
5589 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5590 CfEntryInfo *ce2, int old, int use_ldif )
5594 /* Renumber original to a temp value */
5595 ce->ce_entry->e_private = NULL;
5596 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5597 old+BIGTMP, 0, use_ldif );
5598 ce->ce_entry->e_private = ce;
5600 /* start decrementing */
5601 for (; ce2 != ce; ce2=ce2->ce_sibs) {
5602 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5603 count+old, 0, use_ldif );
5606 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5607 count+old, 0, use_ldif );
5610 /* Parse an LDAP entry into config directives, then store in underlying
5614 config_back_add( Operation *op, SlapReply *rs )
5620 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
5621 NULL, ACL_WADD, NULL )) {
5622 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5627 * Check for attribute ACL
5629 if ( !acl_check_modlist( op, op->ora_e, op->orm_modlist )) {
5630 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5631 rs->sr_text = "no write access to attribute";
5635 cfb = (CfBackInfo *)op->o_bd->be_private;
5637 /* add opattrs for syncprov */
5639 char textbuf[SLAP_TEXT_BUFLEN];
5640 size_t textlen = sizeof textbuf;
5641 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1, NULL,
5642 &rs->sr_text, textbuf, sizeof( textbuf ) );
5643 if ( rs->sr_err != LDAP_SUCCESS )
5645 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
5646 if ( rs->sr_err != LDAP_SUCCESS ) {
5647 Debug( LDAP_DEBUG_TRACE,
5648 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
5649 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
5654 if ( op->o_abandon ) {
5655 rs->sr_err = SLAPD_ABANDON;
5658 ldap_pvt_thread_pool_pause( &connection_pool );
5661 * 1) check for existence of entry
5662 * 2) check for sibling renumbering
5663 * 3) perform internal add
5664 * 4) perform any necessary renumbering
5665 * 5) store entry in underlying database
5667 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
5668 if ( rs->sr_err != LDAP_SUCCESS ) {
5669 rs->sr_text = ca.cr_msg;
5674 CfEntryInfo *ce = ca.ca_entry->e_private;
5675 req_add_s addr = op->oq_add;
5676 op->o_tag = LDAP_REQ_MODRDN;
5677 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
5678 op->o_tag = LDAP_REQ_ADD;
5680 if ( rs->sr_err != LDAP_SUCCESS ) {
5685 if ( cfb->cb_use_ldif ) {
5686 BackendDB *be = op->o_bd;
5687 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5688 struct berval dn, ndn;
5690 op->o_bd = &cfb->cb_db;
5692 /* Save current rootdn; use the underlying DB's rootdn */
5695 op->o_dn = op->o_bd->be_rootdn;
5696 op->o_ndn = op->o_bd->be_rootndn;
5698 scp = op->o_callback;
5699 op->o_callback = ≻
5700 op->o_bd->be_add( op, rs );
5702 op->o_callback = scp;
5708 ldap_pvt_thread_pool_resume( &connection_pool );
5711 { int repl = op->o_dont_replicate;
5712 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
5713 rs->sr_text = NULL; /* Set after config_add_internal */
5714 rs->sr_err = LDAP_SUCCESS;
5715 op->o_dont_replicate = 1;
5717 send_ldap_result( op, rs );
5718 op->o_dont_replicate = repl;
5720 slap_graduate_commit_csn( op );
5724 typedef struct delrec {
5725 struct delrec *next;
5731 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
5737 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
5738 ca->line[0] == '{' )
5740 char *ptr = strchr( ca->line + 1, '}' );
5744 ca->valx = strtol( ca->line + 1, &next, 0 );
5745 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
5751 rc = config_parse_add( ct, ca, i );
5759 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
5762 int rc = LDAP_UNWILLING_TO_PERFORM;
5764 Entry *e = ce->ce_entry;
5765 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
5770 delrec *dels = NULL, *deltail = NULL;
5772 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5773 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
5775 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5776 if (ml->sml_desc == slap_schema.si_ad_objectClass)
5780 colst = count_ocs( oc_at, &nocs );
5782 /* make sure add/del flags are clear; should always be true */
5783 for ( s = save_attrs; s; s = s->a_next ) {
5784 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
5787 e->e_attrs = attrs_dup( e->e_attrs );
5789 init_config_argv( ca );
5792 ca->ca_private = ce->ce_private;
5794 ca->fname = "slapd";
5796 strcpy( ca->log, "back-config" );
5798 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5799 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5800 switch (ml->sml_op) {
5801 case LDAP_MOD_DELETE:
5802 case LDAP_MOD_REPLACE:
5803 case SLAP_MOD_SOFTDEL:
5805 BerVarray vals = NULL, nvals = NULL;
5807 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
5809 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
5810 ml->sml_desc->ad_cname.bv_val );
5813 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5814 vals = ml->sml_values;
5815 nvals = ml->sml_nvalues;
5816 ml->sml_values = NULL;
5817 ml->sml_nvalues = NULL;
5819 /* If we're deleting by values, remember the indexes of the
5820 * values we deleted.
5822 if ( ct && ml->sml_values ) {
5824 i = ml->sml_numvals;
5825 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
5836 rc = modify_delete_vindex(e, &ml->sml_mod,
5837 get_permissiveModify(op),
5838 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
5839 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5840 ml->sml_values = vals;
5841 ml->sml_nvalues = nvals;
5843 if ( rc == LDAP_NO_SUCH_ATTRIBUTE && ml->sml_op == SLAP_MOD_SOFTDEL )
5847 /* FIXME: check rc before fallthru? */
5851 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5853 case SLAP_MOD_ADD_IF_NOT_PRESENT:
5854 if ( ml->sml_op == SLAP_MOD_ADD_IF_NOT_PRESENT
5855 && attr_find( e->e_attrs, ml->sml_desc ) )
5862 case SLAP_MOD_SOFTADD: {
5863 int mop = ml->sml_op;
5865 ml->sml_op = LDAP_MOD_ADD;
5867 if ( ct->arg_type & ARG_NO_INSERT ) {
5868 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
5870 navals = a->a_numvals;
5873 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
5874 if ( ml->sml_values[i].bv_val[0] == '{' &&
5877 char *next, *val = ml->sml_values[i].bv_val + 1;
5880 j = strtol( val, &next, 0 );
5881 if ( next == val || next[ 0 ] != '}' || j < navals ) {
5883 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
5884 ml->sml_desc->ad_cname.bv_val );
5888 rc = check_vals( ct, ca, ml, 0 );
5889 if ( rc ) goto out_noop;
5892 rc = modify_add_values(e, &ml->sml_mod,
5893 get_permissiveModify(op),
5894 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5896 /* If value already exists, show success here
5897 * and ignore this operation down below.
5899 if ( mop == SLAP_MOD_SOFTADD ) {
5900 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
5910 case LDAP_MOD_INCREMENT: /* FIXME */
5915 if(rc != LDAP_SUCCESS) break;
5918 if ( rc == LDAP_SUCCESS) {
5919 /* check that the entry still obeys the schema */
5920 rc = entry_schema_check(op, e, NULL, 0, 0, NULL,
5921 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5923 if ( rc ) goto out_noop;
5925 /* Basic syntax checks are OK. Do the actual settings. */
5926 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5927 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5928 if ( !ct ) continue;
5930 s = attr_find( save_attrs, ml->sml_desc );
5931 a = attr_find( e->e_attrs, ml->sml_desc );
5933 switch (ml->sml_op) {
5934 case LDAP_MOD_DELETE:
5935 case LDAP_MOD_REPLACE: {
5936 BerVarray vals = NULL, nvals = NULL;
5939 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5940 vals = ml->sml_values;
5941 nvals = ml->sml_nvalues;
5942 ml->sml_values = NULL;
5943 ml->sml_nvalues = NULL;
5946 if ( ml->sml_values )
5949 /* If we didn't delete the whole attribute */
5950 if ( ml->sml_values && a ) {
5951 struct berval *mvals;
5954 if ( ml->sml_nvalues )
5955 mvals = ml->sml_nvalues;
5957 mvals = ml->sml_values;
5959 /* use the indexes we saved up above */
5960 for (i=0; i < d->nidx; i++) {
5961 struct berval bv = *mvals++;
5962 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
5963 bv.bv_val[0] == '{' ) {
5964 ptr = strchr( bv.bv_val, '}' ) + 1;
5965 bv.bv_len -= ptr - bv.bv_val;
5968 ca->line = bv.bv_val;
5969 ca->valx = d->idx[i];
5970 config_parse_vals(ct, ca, d->idx[i] );
5971 rc = config_del_vals( ct, ca );
5972 if ( rc != LDAP_SUCCESS ) break;
5974 s->a_flags |= SLAP_ATTR_IXDEL;
5975 for (j=i+1; j < d->nidx; j++)
5976 if ( d->idx[j] >d->idx[i] )
5983 rc = config_del_vals( ct, ca );
5984 if ( rc ) rc = LDAP_OTHER;
5986 s->a_flags |= SLAP_ATTR_IXDEL;
5988 if ( ml->sml_values ) {
5993 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5994 ml->sml_values = vals;
5995 ml->sml_nvalues = nvals;
5997 if ( !vals || rc != LDAP_SUCCESS )
6000 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
6005 for (i=0; ml->sml_values[i].bv_val; i++) {
6006 ca->line = ml->sml_values[i].bv_val;
6008 rc = config_modify_add( ct, ca, ml->sml_desc, i );
6011 a->a_flags |= SLAP_ATTR_IXADD;
6018 /* Undo for a failed operation */
6019 if ( rc != LDAP_SUCCESS ) {
6020 ConfigReply msg = ca->reply;
6021 for ( s = save_attrs; s; s = s->a_next ) {
6022 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
6023 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
6024 ct = config_find_table( colst, nocs, s->a_desc, ca );
6025 a = attr_find( e->e_attrs, s->a_desc );
6027 /* clear the flag so the add check below will skip it */
6028 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
6032 config_del_vals( ct, ca );
6034 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
6035 ca->line = s->a_vals[i].bv_val;
6037 config_modify_add( ct, ca, s->a_desc, i );
6041 for ( a = e->e_attrs; a; a = a->a_next ) {
6042 if ( a->a_flags & SLAP_ATTR_IXADD ) {
6043 ct = config_find_table( colst, nocs, a->a_desc, ca );
6047 config_del_vals( ct, ca );
6048 s = attr_find( save_attrs, a->a_desc );
6050 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
6051 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
6052 ca->line = s->a_vals[i].bv_val;
6054 config_modify_add( ct, ca, s->a_desc, i );
6062 if ( ca->cleanup ) {
6063 i = ca->cleanup( ca );
6064 if (rc == LDAP_SUCCESS)
6068 if ( rc == LDAP_SUCCESS ) {
6069 attrs_free( save_attrs );
6072 attrs_free( e->e_attrs );
6073 e->e_attrs = save_attrs;
6075 ch_free( ca->argv );
6076 if ( colst ) ch_free( colst );
6078 deltail = dels->next;
6087 config_back_modify( Operation *op, SlapReply *rs )
6090 CfEntryInfo *ce, *last;
6092 ConfigArgs ca = {0};
6095 AttributeDescription *rad = NULL;
6098 cfb = (CfBackInfo *)op->o_bd->be_private;
6100 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6103 rs->sr_matched = last->ce_entry->e_name.bv_val;
6104 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6108 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
6109 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6113 /* Get type of RDN */
6114 rdn = ce->ce_entry->e_nname;
6115 ptr = strchr( rdn.bv_val, '=' );
6116 rdn.bv_len = ptr - rdn.bv_val;
6117 rs->sr_err = slap_bv2ad( &rdn, &rad, &rs->sr_text );
6118 if ( rs->sr_err != LDAP_SUCCESS ) {
6122 /* Some basic validation... */
6123 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
6124 /* Don't allow Modify of RDN; must use ModRdn for that. */
6125 if ( ml->sml_desc == rad ) {
6126 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
6127 rs->sr_text = "Use modrdn to change the entry name";
6130 /* Internal update of contextCSN? */
6131 if ( ml->sml_desc == slap_schema.si_ad_contextCSN && op->o_conn->c_conn_idx == -1 ) {
6137 slap_mods_opattrs( op, &op->orm_modlist, 1 );
6140 if ( op->o_abandon ) {
6141 rs->sr_err = SLAPD_ABANDON;
6144 ldap_pvt_thread_pool_pause( &connection_pool );
6148 * 1) perform the Modify on the cached Entry.
6149 * 2) verify that the Entry still satisfies the schema.
6150 * 3) perform the individual config operations.
6151 * 4) store Modified entry in underlying LDIF backend.
6153 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
6155 rs->sr_text = ca.cr_msg;
6156 } else if ( cfb->cb_use_ldif ) {
6157 BackendDB *be = op->o_bd;
6158 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
6159 struct berval dn, ndn;
6161 op->o_bd = &cfb->cb_db;
6165 op->o_dn = op->o_bd->be_rootdn;
6166 op->o_ndn = op->o_bd->be_rootndn;
6168 scp = op->o_callback;
6169 op->o_callback = ≻
6170 op->o_bd->be_modify( op, rs );
6172 op->o_callback = scp;
6178 ldap_pvt_thread_pool_resume( &connection_pool );
6180 send_ldap_result( op, rs );
6181 slap_graduate_commit_csn( op );
6186 config_back_modrdn( Operation *op, SlapReply *rs )
6189 CfEntryInfo *ce, *last;
6193 cfb = (CfBackInfo *)op->o_bd->be_private;
6195 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6198 rs->sr_matched = last->ce_entry->e_name.bv_val;
6199 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6202 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
6203 NULL, ACL_WRITE, NULL )) {
6204 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6208 if ( ce->ce_parent )
6209 parent = ce->ce_parent->ce_entry;
6211 parent = (Entry *)&slap_entry_root;
6212 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
6213 NULL, ACL_WRITE, NULL )) {
6214 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6219 /* We don't allow moving objects to new parents.
6220 * Generally we only allow reordering a set of ordered entries.
6222 if ( op->orr_newSup ) {
6223 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6227 /* If newRDN == oldRDN, quietly succeed */
6228 dnRdn( &op->o_req_ndn, &rdn );
6229 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
6230 rs->sr_err = LDAP_SUCCESS;
6234 /* Current behavior, subject to change as needed:
6236 * For backends and overlays, we only allow renumbering.
6237 * For schema, we allow renaming with the same number.
6238 * Otherwise, the op is not allowed.
6241 if ( ce->ce_type == Cft_Schema ) {
6245 /* Can't alter the main cn=schema entry */
6246 if ( ce->ce_parent->ce_type == Cft_Global ) {
6247 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6248 rs->sr_text = "renaming not allowed for this entry";
6252 /* We could support this later if desired */
6253 ptr1 = ber_bvchr( &rdn, '}' );
6254 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
6255 len = ptr1 - rdn.bv_val;
6256 if ( len != ptr2 - op->orr_newrdn.bv_val ||
6257 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
6258 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6259 rs->sr_text = "schema reordering not supported";
6262 } else if ( ce->ce_type == Cft_Database ||
6263 ce->ce_type == Cft_Overlay ) {
6264 char *ptr1, *ptr2, *iptr1, *iptr2;
6267 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
6268 if ( *iptr2 != '{' ) {
6269 rs->sr_err = LDAP_NAMING_VIOLATION;
6270 rs->sr_text = "new ordering index is required";
6274 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
6275 ptr1 = ber_bvchr( &rdn, '}' );
6276 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
6278 rs->sr_err = LDAP_NAMING_VIOLATION;
6279 rs->sr_text = "new ordering index is required";
6283 len1 = ptr1 - rdn.bv_val;
6284 len2 = ptr2 - op->orr_newrdn.bv_val;
6286 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
6287 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
6288 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6289 rs->sr_text = "changing database/overlay type not allowed";
6292 ixold = strtol( iptr1, NULL, 0 );
6293 ixnew = strtol( iptr2, &ptr1, 0 );
6294 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
6295 rs->sr_err = LDAP_NAMING_VIOLATION;
6298 /* config DB is always 0, cannot be changed */
6299 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
6300 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
6304 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6305 rs->sr_text = "renaming not supported for this entry";
6309 if ( op->o_abandon ) {
6310 rs->sr_err = SLAPD_ABANDON;
6313 ldap_pvt_thread_pool_pause( &connection_pool );
6315 if ( ce->ce_type == Cft_Schema ) {
6316 req_modrdn_s modr = op->oq_modrdn;
6319 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
6320 if ( rs->sr_err == LDAP_SUCCESS ) {
6321 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
6322 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
6325 op->oq_modrdn = modr;
6327 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
6328 req_modrdn_s modr = op->oq_modrdn;
6331 /* Advance to first of this type */
6332 cprev = &ce->ce_parent->ce_kids;
6333 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
6334 cprev = &ce2->ce_sibs;
6337 /* Skip the -1 entry */
6338 if ( ce->ce_type == Cft_Database ) {
6339 cprev = &ce2->ce_sibs;
6345 /* Remove from old slot */
6346 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
6347 cprev = &ce2->ce_sibs;
6348 *cprev = ce->ce_sibs;
6349 ceold = ce->ce_sibs;
6351 /* Insert into new slot */
6353 for ( i=0; i<ixnew; i++ ) {
6357 cprev = &ce2->ce_sibs;
6359 ce->ce_sibs = *cprev;
6364 /* NOTE: These should be encoded in the OC tables, not inline here */
6365 if ( ce->ce_type == Cft_Database )
6366 backend_db_move( ce->ce_be, ixnew );
6367 else if ( ce->ce_type == Cft_Overlay )
6368 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
6370 if ( ixold < ixnew ) {
6371 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
6374 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
6375 ixold - ixnew, cfb->cb_use_ldif );
6377 op->oq_modrdn = modr;
6380 ldap_pvt_thread_pool_resume( &connection_pool );
6382 send_ldap_result( op, rs );
6387 config_back_delete( Operation *op, SlapReply *rs )
6389 #ifdef SLAP_CONFIG_DELETE
6391 CfEntryInfo *ce, *last, *ce2;
6393 cfb = (CfBackInfo *)op->o_bd->be_private;
6395 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6398 rs->sr_matched = last->ce_entry->e_name.bv_val;
6399 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6400 } else if ( ce->ce_kids ) {
6401 rs->sr_err = LDAP_NOT_ALLOWED_ON_NONLEAF;
6402 } else if ( op->o_abandon ) {
6403 rs->sr_err = SLAPD_ABANDON;
6404 } else if ( ce->ce_type == Cft_Overlay ||
6405 ce->ce_type == Cft_Database ||
6406 ce->ce_type == Cft_Misc ){
6410 ldap_pvt_thread_pool_pause( &connection_pool );
6412 if ( ce->ce_type == Cft_Overlay ){
6413 overlay_remove( ce->ce_be, (slap_overinst *)ce->ce_bi, op );
6414 } else if ( ce->ce_type == Cft_Misc ) {
6416 * only Cft_Misc objects that have a co_lddel handler set in
6417 * the ConfigOCs struct can be deleted. This code also
6418 * assumes that the entry can be only have one objectclass
6419 * with co_type == Cft_Misc
6421 ConfigOCs co, *coptr;
6425 oc_at = attr_find( ce->ce_entry->e_attrs,
6426 slap_schema.si_ad_objectClass );
6428 rs->sr_err = LDAP_OTHER;
6429 rs->sr_text = "objectclass not found";
6430 ldap_pvt_thread_pool_resume( &connection_pool );
6433 for ( i=0; !BER_BVISNULL(&oc_at->a_nvals[i]); i++ ) {
6434 co.co_name = &oc_at->a_nvals[i];
6435 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
6436 if ( coptr == NULL || coptr->co_type != Cft_Misc ) {
6439 if ( ! coptr->co_lddel || coptr->co_lddel( ce, op ) ){
6440 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6441 if ( ! coptr->co_lddel ) {
6442 rs->sr_text = "No delete handler found";
6444 rs->sr_err = LDAP_OTHER;
6445 /* FIXME: We should return a helpful error message
6448 ldap_pvt_thread_pool_resume( &connection_pool );
6453 } else if (ce->ce_type == Cft_Database ) {
6454 if ( ce->ce_be == frontendDB || ce->ce_be == op->o_bd ){
6455 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6456 rs->sr_text = "Cannot delete config or frontend database";
6457 ldap_pvt_thread_pool_resume( &connection_pool );
6460 if ( ce->ce_be->bd_info->bi_db_close ) {
6461 ce->ce_be->bd_info->bi_db_close( ce->ce_be, NULL );
6463 backend_destroy_one( ce->ce_be, 1);
6466 /* remove CfEntryInfo from the siblings list */
6467 if ( ce->ce_parent->ce_kids == ce ) {
6468 ce->ce_parent->ce_kids = ce->ce_sibs;
6470 for ( ce2 = ce->ce_parent->ce_kids ; ce2; ce2 = ce2->ce_sibs ) {
6471 if ( ce2->ce_sibs == ce ) {
6472 ce2->ce_sibs = ce->ce_sibs;
6478 /* remove from underlying database */
6479 if ( cfb->cb_use_ldif ) {
6480 BackendDB *be = op->o_bd;
6481 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
6482 struct berval dn, ndn, req_dn, req_ndn;
6484 op->o_bd = &cfb->cb_db;
6488 req_dn = op->o_req_dn;
6489 req_ndn = op->o_req_ndn;
6491 op->o_dn = op->o_bd->be_rootdn;
6492 op->o_ndn = op->o_bd->be_rootndn;
6493 op->o_req_dn = ce->ce_entry->e_name;
6494 op->o_req_ndn = ce->ce_entry->e_nname;
6496 scp = op->o_callback;
6497 op->o_callback = ≻
6498 op->o_bd->be_delete( op, rs );
6500 op->o_callback = scp;
6503 op->o_req_dn = req_dn;
6504 op->o_req_ndn = req_ndn;
6507 /* renumber siblings */
6508 iptr = ber_bvchr( &op->o_req_ndn, '{' ) + 1;
6509 ixold = strtol( iptr, NULL, 0 );
6510 for (ce2 = ce->ce_sibs, count=0; ce2; ce2=ce2->ce_sibs) {
6511 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
6512 count+ixold, 0, cfb->cb_use_ldif );
6516 ce->ce_entry->e_private=NULL;
6517 entry_free(ce->ce_entry);
6519 ldap_pvt_thread_pool_resume( &connection_pool );
6521 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6525 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6526 #endif /* SLAP_CONFIG_DELETE */
6527 send_ldap_result( op, rs );
6532 config_back_search( Operation *op, SlapReply *rs )
6535 CfEntryInfo *ce, *last;
6538 cfb = (CfBackInfo *)op->o_bd->be_private;
6540 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6543 rs->sr_matched = last->ce_entry->e_name.bv_val;
6544 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6547 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
6548 ACL_SEARCH, NULL, &mask ))
6550 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
6551 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6553 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6557 switch ( op->ors_scope ) {
6558 case LDAP_SCOPE_BASE:
6559 case LDAP_SCOPE_SUBTREE:
6560 rs->sr_err = config_send( op, rs, ce, 0 );
6563 case LDAP_SCOPE_ONELEVEL:
6564 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
6565 rs->sr_err = config_send( op, rs, ce, 1 );
6574 send_ldap_result( op, rs );
6578 /* no-op, we never free entries */
6579 int config_entry_release(
6584 int rc = LDAP_SUCCESS;
6586 if ( !e->e_private ) {
6587 BackendDB *be = op->o_bd;
6588 CfBackInfo *cfb = be->be_private;
6589 BackendInfo *bi = cfb->cb_db.bd_info;
6591 if ( bi && bi->bi_entry_release_rw ) {
6592 op->o_bd = &cfb->cb_db;
6593 rc = bi->bi_entry_release_rw( op, e, rw );
6602 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
6604 int config_back_entry_get(
6608 AttributeDescription *at,
6613 CfEntryInfo *ce, *last;
6614 int rc = LDAP_NO_SUCH_OBJECT;
6616 cfb = (CfBackInfo *)op->o_bd->be_private;
6618 ce = config_find_base( cfb->cb_root, ndn, &last );
6620 *ent = ce->ce_entry;
6623 if ( oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
6624 rc = LDAP_NO_SUCH_ATTRIBUTE;
6634 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
6635 ConfigTable *ct, ConfigArgs *c )
6639 for (; at && *at; at++) {
6640 /* Skip the naming attr */
6641 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
6643 for (i=0;ct[i].name;i++) {
6644 if (ct[i].ad == (*at)->sat_ad) {
6645 rc = config_get_vals(&ct[i], c);
6646 /* NOTE: tolerate that config_get_vals()
6647 * returns success with no values */
6648 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
6649 if ( c->rvalue_nvals )
6650 rc = attr_merge(e, ct[i].ad, c->rvalue_vals,
6653 slap_syntax_validate_func *validate =
6654 ct[i].ad->ad_type->sat_syntax->ssyn_validate;
6657 for ( j=0; c->rvalue_vals[j].bv_val; j++ ) {
6658 rc = ordered_value_validate( ct[i].ad,
6659 &c->rvalue_vals[j], LDAP_MOD_ADD );
6661 Debug( LDAP_DEBUG_ANY,
6662 "config_build_attrs: error %d on %s value #%d\n",
6663 rc, ct[i].ad->ad_cname.bv_val, j );
6669 rc = attr_merge_normalize(e, ct[i].ad,
6670 c->rvalue_vals, NULL);
6672 ber_bvarray_free( c->rvalue_nvals );
6673 ber_bvarray_free( c->rvalue_vals );
6675 Debug( LDAP_DEBUG_ANY,
6676 "config_build_attrs: error %d on %s\n",
6677 rc, ct[i].ad->ad_cname.bv_val, 0 );
6688 /* currently (2010) does not access rs except possibly writing rs->sr_err */
6691 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
6692 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
6694 Entry *e = entry_alloc();
6695 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
6697 struct berval ad_name;
6698 AttributeDescription *ad = NULL;
6701 const char *text = "";
6705 CfEntryInfo *ceprev = NULL;
6707 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
6710 ce->ce_type = main->co_type;
6711 ce->ce_parent = parent;
6713 pdn = parent->ce_entry->e_nname;
6714 if ( parent->ce_kids && parent->ce_kids->ce_type <= ce->ce_type )
6715 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
6716 ceprev->ce_type <= ce->ce_type;
6717 ceprev = ceprev->ce_sibs );
6722 ce->ce_private = c->ca_private;
6726 build_new_dn( &e->e_name, &pdn, rdn, NULL );
6727 ber_dupbv( &e->e_nname, &e->e_name );
6729 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6730 main->co_name, NULL );
6732 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6733 extra->co_name, NULL );
6734 ptr = strchr(rdn->bv_val, '=');
6735 ad_name.bv_val = rdn->bv_val;
6736 ad_name.bv_len = ptr - rdn->bv_val;
6737 rc = slap_bv2ad( &ad_name, &ad, &text );
6742 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
6743 attr_merge_normalize_one(e, ad, &val, NULL );
6746 c->table = main->co_type;
6747 if ( oc->soc_required ) {
6748 rc = config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
6749 if ( rc ) goto fail;
6752 if ( oc->soc_allowed ) {
6753 rc = config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
6754 if ( rc ) goto fail;
6759 c->table = extra->co_type;
6760 if ( oc->soc_required ) {
6761 rc = config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
6762 if ( rc ) goto fail;
6765 if ( oc->soc_allowed ) {
6766 rc = config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
6767 if ( rc ) goto fail;
6771 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
6772 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
6773 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
6774 if ( rc != LDAP_SUCCESS ) {
6776 Debug( LDAP_DEBUG_ANY,
6777 "config_build_entry: build \"%s\" failed: \"%s\"\n",
6778 rdn->bv_val, text, 0);
6781 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
6784 op->ora_modlist = NULL;
6785 slap_add_opattrs( op, NULL, NULL, 0, 0 );
6786 if ( !op->o_noop ) {
6787 SlapReply rs2 = {REP_RESULT};
6788 op->o_bd->be_add( op, &rs2 );
6789 rs->sr_err = rs2.sr_err;
6790 rs_assert_done( &rs2 );
6791 if ( ( rs2.sr_err != LDAP_SUCCESS )
6792 && (rs2.sr_err != LDAP_ALREADY_EXISTS) ) {
6798 ce->ce_sibs = ceprev->ce_sibs;
6799 ceprev->ce_sibs = ce;
6800 } else if ( parent ) {
6801 ce->ce_sibs = parent->ce_kids;
6802 parent->ce_kids = ce;
6809 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
6810 Operation *op, SlapReply *rs )
6813 ConfigFile *cf = c->ca_private;
6815 struct berval bv, rdn;
6817 for (; cf; cf=cf->c_sibs, c->depth++) {
6818 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
6819 !cf->c_om_head && !cf->c_syn_head && !cf->c_kids ) continue;
6820 c->value_dn.bv_val = c->log;
6821 LUTIL_SLASHPATH( cf->c_file.bv_val );
6822 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
6827 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
6829 ptr = strchr( bv.bv_val, '.' );
6831 bv.bv_len = ptr - bv.bv_val;
6832 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
6833 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6834 /* FIXME: how can indicate error? */
6837 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
6839 c->value_dn.bv_len += bv.bv_len;
6840 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
6841 rdnNormalize( 0, NULL, NULL, &c->value_dn, &rdn, NULL );
6844 e = config_build_entry( op, rs, ceparent, c, &rdn,
6845 &CFOC_SCHEMA, NULL );
6846 ch_free( rdn.bv_val );
6849 } else if ( e && cf->c_kids ) {
6850 c->ca_private = cf->c_kids;
6851 config_build_schema_inc( c, e->e_private, op, rs );
6857 #ifdef SLAPD_MODULES
6860 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
6861 Operation *op, SlapReply *rs )
6866 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
6867 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
6869 c->value_dn.bv_val = c->log;
6870 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
6871 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6872 /* FIXME: how can indicate error? */
6876 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
6885 config_check_schema(Operation *op, CfBackInfo *cfb)
6887 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
6889 CfEntryInfo *ce, *last;
6892 /* If there's no root entry, we must be in the midst of converting */
6893 if ( !cfb->cb_root )
6896 /* Make sure the main schema entry exists */
6897 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
6904 /* Make sure it's up to date */
6905 if ( cf_om_tail != om_sys_tail ) {
6906 a = attr_find( e->e_attrs, cfAd_om );
6908 if ( a->a_nvals != a->a_vals )
6909 ber_bvarray_free( a->a_nvals );
6910 ber_bvarray_free( a->a_vals );
6915 oidm_unparse( &bv, NULL, NULL, 1 );
6916 attr_merge_normalize( e, cfAd_om, bv, NULL );
6917 ber_bvarray_free( bv );
6918 cf_om_tail = om_sys_tail;
6920 if ( cf_at_tail != at_sys_tail ) {
6921 a = attr_find( e->e_attrs, cfAd_attr );
6923 if ( a->a_nvals != a->a_vals )
6924 ber_bvarray_free( a->a_nvals );
6925 ber_bvarray_free( a->a_vals );
6930 at_unparse( &bv, NULL, NULL, 1 );
6931 attr_merge_normalize( e, cfAd_attr, bv, NULL );
6932 ber_bvarray_free( bv );
6933 cf_at_tail = at_sys_tail;
6935 if ( cf_oc_tail != oc_sys_tail ) {
6936 a = attr_find( e->e_attrs, cfAd_oc );
6938 if ( a->a_nvals != a->a_vals )
6939 ber_bvarray_free( a->a_nvals );
6940 ber_bvarray_free( a->a_vals );
6945 oc_unparse( &bv, NULL, NULL, 1 );
6946 attr_merge_normalize( e, cfAd_oc, bv, NULL );
6947 ber_bvarray_free( bv );
6948 cf_oc_tail = oc_sys_tail;
6950 if ( cf_syn_tail != syn_sys_tail ) {
6951 a = attr_find( e->e_attrs, cfAd_syntax );
6953 if ( a->a_nvals != a->a_vals )
6954 ber_bvarray_free( a->a_nvals );
6955 ber_bvarray_free( a->a_vals );
6960 syn_unparse( &bv, NULL, NULL, 1 );
6961 attr_merge_normalize( e, cfAd_syntax, bv, NULL );
6962 ber_bvarray_free( bv );
6963 cf_syn_tail = syn_sys_tail;
6966 SlapReply rs = {REP_RESULT};
6967 c.ca_private = NULL;
6968 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
6969 &CFOC_SCHEMA, NULL );
6974 ce->ce_private = cfb->cb_config;
6975 cf_at_tail = at_sys_tail;
6976 cf_oc_tail = oc_sys_tail;
6977 cf_om_tail = om_sys_tail;
6978 cf_syn_tail = syn_sys_tail;
6983 static const char *defacl[] = {
6984 NULL, "to", "*", "by", "*", "none", NULL
6988 config_back_db_open( BackendDB *be, ConfigReply *cr )
6990 CfBackInfo *cfb = be->be_private;
6993 CfEntryInfo *ce, *ceparent;
6997 Connection conn = {0};
6998 OperationBuffer opbuf;
7000 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
7001 SlapReply rs = {REP_RESULT};
7002 void *thrctx = NULL;
7003 AccessControl *save_access;
7005 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
7007 /* If we have no explicitly configured ACLs, don't just use
7008 * the global ACLs. Explicitly deny access to everything.
7010 save_access = be->bd_self->be_acl;
7011 be->bd_self->be_acl = NULL;
7012 parse_acl(be->bd_self, "config_back_db_open", 0, 6, (char **)defacl, 0 );
7013 defacl_parsed = be->bd_self->be_acl;
7014 if ( save_access ) {
7015 be->bd_self->be_acl = save_access;
7017 Debug( LDAP_DEBUG_CONFIG, "config_back_db_open: "
7018 "No explicit ACL for back-config configured. "
7019 "Using hardcoded default\n", 0, 0, 0 );
7022 thrctx = ldap_pvt_thread_pool_context();
7023 connection_fake_init( &conn, &opbuf, thrctx );
7026 op->o_tag = LDAP_REQ_ADD;
7027 op->o_callback = &cb;
7028 op->o_bd = &cfb->cb_db;
7029 op->o_dn = op->o_bd->be_rootdn;
7030 op->o_ndn = op->o_bd->be_rootndn;
7032 if ( !cfb->cb_use_ldif ) {
7036 /* If we read the config from back-ldif, do some quick sanity checks */
7037 if ( cfb->cb_got_ldif ) {
7038 return config_check_schema( op, cfb );
7041 /* create root of tree */
7043 c.ca_private = cfb->cb_config;
7045 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
7055 #ifdef SLAPD_MODULES
7056 /* Create Module nodes... */
7057 if ( modpaths.mp_loads ) {
7058 if ( config_build_modules( &c, ceparent, op, &rs ) ){
7064 /* Create schema nodes... cn=schema will contain the hardcoded core
7065 * schema, read-only. Child objects will contain runtime loaded schema
7069 c.ca_private = NULL;
7070 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
7075 ce->ce_private = cfb->cb_config;
7076 cf_at_tail = at_sys_tail;
7077 cf_oc_tail = oc_sys_tail;
7078 cf_om_tail = om_sys_tail;
7079 cf_syn_tail = syn_sys_tail;
7081 /* Create schema nodes for included schema... */
7082 if ( cfb->cb_config->c_kids ) {
7085 c.ca_private = cfb->cb_config->c_kids;
7086 rc = config_build_schema_inc( &c, ce, op, &rs );
7092 /* Create backend nodes. Skip if they don't provide a cf_table.
7093 * There usually aren't any of these.
7097 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
7098 if (!bi->bi_cf_ocs) {
7099 /* If it only supports the old config mech, complain. */
7100 if ( bi->bi_config ) {
7101 Debug( LDAP_DEBUG_ANY,
7102 "WARNING: No dynamic config support for backend %s.\n",
7103 bi->bi_type, 0, 0 );
7108 if (!bi->bi_private) continue;
7111 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
7112 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
7113 if ( rdn.bv_len >= sizeof( c.log ) ) {
7114 /* FIXME: holler ... */ ;
7117 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
7124 /* Create database nodes... */
7125 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
7126 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
7127 for ( i = -1, be = frontendDB ; be;
7128 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
7129 slap_overinfo *oi = NULL;
7131 if ( overlay_is_over( be )) {
7132 oi = be->bd_info->bi_private;
7138 /* If this backend supports the old config mechanism, but not
7139 * the new mech, complain.
7141 if ( !be->be_cf_ocs && bi->bi_db_config ) {
7142 Debug( LDAP_DEBUG_ANY,
7143 "WARNING: No dynamic config support for database %s.\n",
7144 bi->bi_type, 0, 0 );
7148 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
7149 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
7151 if ( rdn.bv_len >= sizeof( c.log ) ) {
7152 /* FIXME: holler ... */ ;
7156 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
7162 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd ) {
7163 rs_reinit( &rs, REP_RESULT );
7164 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
7166 /* Iterate through overlays */
7171 voidList *vl, *v0 = NULL;
7173 /* overlays are in LIFO order, must reverse stack */
7174 for (on=oi->oi_list; on; on=on->on_next) {
7175 vl = ch_malloc( sizeof( voidList ));
7180 for (j=0; vl; j++,vl=v0) {
7184 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
7185 Debug( LDAP_DEBUG_ANY,
7186 "WARNING: No dynamic config support for overlay %s.\n",
7187 on->on_bi.bi_type, 0, 0 );
7191 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
7192 "%s=" SLAP_X_ORDERED_FMT "%s",
7193 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
7194 if ( rdn.bv_len >= sizeof( c.log ) ) {
7195 /* FIXME: holler ... */ ;
7199 oe = config_build_entry( op, &rs, ce, &c, &rdn,
7200 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
7204 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd ) {
7205 rs_reinit( &rs, REP_RESULT );
7206 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
7212 ldap_pvt_thread_pool_context_reset( thrctx );
7214 if ( unsupp && cfb->cb_use_ldif ) {
7215 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
7216 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
7223 cfb_free_cffile( ConfigFile *cf )
7227 for (; cf; cf=next) {
7230 cfb_free_cffile( cf->c_kids );
7231 ch_free( cf->c_file.bv_val );
7232 ber_bvarray_free( cf->c_dseFiles );
7238 cfb_free_entries( CfEntryInfo *ce )
7242 for (; ce; ce=next) {
7245 cfb_free_entries( ce->ce_kids );
7246 ce->ce_entry->e_private = NULL;
7247 entry_free( ce->ce_entry );
7253 config_back_db_close( BackendDB *be, ConfigReply *cr )
7255 CfBackInfo *cfb = be->be_private;
7257 cfb_free_entries( cfb->cb_root );
7258 cfb->cb_root = NULL;
7260 if ( cfb->cb_db.bd_info ) {
7261 backend_shutdown( &cfb->cb_db );
7264 if ( defacl_parsed && be->be_acl != defacl_parsed ) {
7265 acl_free( defacl_parsed );
7266 defacl_parsed = NULL;
7273 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
7275 CfBackInfo *cfb = be->be_private;
7277 cfb_free_cffile( cfb->cb_config );
7279 ch_free( cfdir.bv_val );
7281 avl_free( CfOcTree, NULL );
7283 if ( cfb->cb_db.bd_info ) {
7284 cfb->cb_db.be_suffix = NULL;
7285 cfb->cb_db.be_nsuffix = NULL;
7286 BER_BVZERO( &cfb->cb_db.be_rootdn );
7287 BER_BVZERO( &cfb->cb_db.be_rootndn );
7289 backend_destroy_one( &cfb->cb_db, 0 );
7298 config_back_db_init( BackendDB *be, ConfigReply* cr )
7304 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
7305 cfn = cfb->cb_config;
7306 be->be_private = cfb;
7308 ber_dupbv( &be->be_rootdn, &config_rdn );
7309 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
7310 ber_dupbv( &dn, &be->be_rootdn );
7311 ber_bvarray_add( &be->be_suffix, &dn );
7312 ber_dupbv( &dn, &be->be_rootdn );
7313 ber_bvarray_add( &be->be_nsuffix, &dn );
7315 /* Hide from namingContexts */
7316 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
7318 /* Check ACLs on content of Adds by default */
7319 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_ACL_ADD;
7325 config_back_destroy( BackendInfo *bi )
7327 ldif_must_b64_encode_release();
7332 config_tool_entry_open( BackendDB *be, int mode )
7334 CfBackInfo *cfb = be->be_private;
7335 BackendInfo *bi = cfb->cb_db.bd_info;
7337 if ( bi && bi->bi_tool_entry_open )
7338 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
7345 config_tool_entry_close( BackendDB *be )
7347 CfBackInfo *cfb = be->be_private;
7348 BackendInfo *bi = cfb->cb_db.bd_info;
7350 if ( bi && bi->bi_tool_entry_close )
7351 return bi->bi_tool_entry_close( &cfb->cb_db );
7357 config_tool_entry_first( BackendDB *be )
7359 CfBackInfo *cfb = be->be_private;
7360 BackendInfo *bi = cfb->cb_db.bd_info;
7362 if ( bi && bi->bi_tool_entry_first ) {
7363 return bi->bi_tool_entry_first( &cfb->cb_db );
7365 if ( bi && bi->bi_tool_entry_first_x ) {
7366 return bi->bi_tool_entry_first_x( &cfb->cb_db,
7367 NULL, LDAP_SCOPE_DEFAULT, NULL );
7373 config_tool_entry_first_x(
7375 struct berval *base,
7379 CfBackInfo *cfb = be->be_private;
7380 BackendInfo *bi = cfb->cb_db.bd_info;
7382 if ( bi && bi->bi_tool_entry_first_x ) {
7383 return bi->bi_tool_entry_first_x( &cfb->cb_db, base, scope, f );
7389 config_tool_entry_next( BackendDB *be )
7391 CfBackInfo *cfb = be->be_private;
7392 BackendInfo *bi = cfb->cb_db.bd_info;
7394 if ( bi && bi->bi_tool_entry_next )
7395 return bi->bi_tool_entry_next( &cfb->cb_db );
7401 config_tool_dn2id_get( Backend *be, struct berval *dn )
7403 CfBackInfo *cfb = be->be_private;
7404 BackendInfo *bi = cfb->cb_db.bd_info;
7406 if ( bi && bi->bi_tool_dn2id_get )
7407 return bi->bi_tool_dn2id_get( &cfb->cb_db, dn );
7413 config_tool_entry_get( BackendDB *be, ID id )
7415 CfBackInfo *cfb = be->be_private;
7416 BackendInfo *bi = cfb->cb_db.bd_info;
7418 if ( bi && bi->bi_tool_entry_get )
7419 return bi->bi_tool_entry_get( &cfb->cb_db, id );
7424 static int entry_put_got_frontend=0;
7425 static int entry_put_got_config=0;
7427 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
7429 CfBackInfo *cfb = be->be_private;
7430 BackendInfo *bi = cfb->cb_db.bd_info;
7432 struct berval rdn, vals[ 2 ];
7434 OperationBuffer opbuf;
7436 Connection conn = {0};
7437 Operation *op = NULL;
7440 int isFrontendChild = 0;
7442 /* Create entry for frontend database if it does not exist already */
7443 if ( !entry_put_got_frontend ) {
7444 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
7445 STRLENOF( "olcDatabase" ))) {
7446 if ( strncmp( e->e_nname.bv_val +
7447 STRLENOF( "olcDatabase" ), "={-1}frontend",
7448 STRLENOF( "={-1}frontend" )) &&
7449 strncmp( e->e_nname.bv_val +
7450 STRLENOF( "olcDatabase" ), "=frontend",
7451 STRLENOF( "=frontend" ))) {
7453 vals[1].bv_val = NULL;
7454 memset( &ca, 0, sizeof(ConfigArgs));
7456 ca.bi = frontendDB->bd_info;
7457 ca.be->be_cf_ocs = &CFOC_FRONTEND;
7458 rdn.bv_val = ca.log;
7459 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7460 "%s=" SLAP_X_ORDERED_FMT "%s",
7461 cfAd_database->ad_cname.bv_val, -1,
7463 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
7464 &CFOC_DATABASE, ca.be->be_cf_ocs );
7465 thrctx = ldap_pvt_thread_pool_context();
7466 connection_fake_init2( &conn, &opbuf, thrctx,0 );
7468 op->o_bd = &cfb->cb_db;
7469 op->o_tag = LDAP_REQ_ADD;
7471 op->o_dn = be->be_rootdn;
7472 op->o_ndn = be->be_rootndn;
7473 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
7474 if ( rc != LDAP_SUCCESS ) {
7475 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
7476 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
7480 if ( ce && bi && bi->bi_tool_entry_put &&
7481 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
7482 entry_put_got_frontend++;
7484 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
7485 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
7489 if ( !strncmp( e->e_nname.bv_val +
7490 STRLENOF( "olcDatabase" ), "=frontend",
7491 STRLENOF( "=frontend" ) ) )
7493 struct berval rdn, pdn, ndn;
7494 dnParent( &e->e_nname, &pdn );
7495 rdn.bv_val = ca.log;
7496 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7497 "%s=" SLAP_X_ORDERED_FMT "%s",
7498 cfAd_database->ad_cname.bv_val, -1,
7499 frontendDB->bd_info->bi_type );
7500 build_new_dn( &ndn, &pdn, &rdn, NULL );
7501 ber_memfree( e->e_name.bv_val );
7503 ber_bvreplace( &e->e_nname, &e->e_name );
7505 entry_put_got_frontend++;
7511 /* Child entries of the frontend database, e.g. slapo-chain's back-ldap
7512 * instances, may appear before the config database entry in the ldif, skip
7513 * auto-creation of olcDatabase={0}config in such a case */
7514 if ( !entry_put_got_config &&
7515 !strncmp( e->e_nname.bv_val, "olcDatabase", STRLENOF( "olcDatabase" ))) {
7517 dnParent( &e->e_nname, &pdn );
7518 while ( pdn.bv_len ) {
7519 if ( !strncmp( pdn.bv_val, "olcDatabase",
7520 STRLENOF( "olcDatabase" ))) {
7521 if ( !strncmp( pdn.bv_val +
7522 STRLENOF( "olcDatabase" ), "={-1}frontend",
7523 STRLENOF( "={-1}frontend" )) ||
7524 !strncmp( pdn.bv_val +
7525 STRLENOF( "olcDatabase" ), "=frontend",
7526 STRLENOF( "=frontend" ))) {
7528 isFrontendChild = 1;
7532 dnParent( &pdn, &pdn );
7536 /* Create entry for config database if it does not exist already */
7537 if ( !entry_put_got_config && !isFrontend && !isFrontendChild ) {
7538 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
7539 STRLENOF( "olcDatabase" ))) {
7540 if ( strncmp( e->e_nname.bv_val +
7541 STRLENOF( "olcDatabase" ), "={0}config",
7542 STRLENOF( "={0}config" )) &&
7543 strncmp( e->e_nname.bv_val +
7544 STRLENOF( "olcDatabase" ), "=config",
7545 STRLENOF( "=config" )) ) {
7547 vals[1].bv_val = NULL;
7548 memset( &ca, 0, sizeof(ConfigArgs));
7549 ca.be = LDAP_STAILQ_FIRST( &backendDB );
7550 ca.bi = ca.be->bd_info;
7551 rdn.bv_val = ca.log;
7552 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7553 "%s=" SLAP_X_ORDERED_FMT "%s",
7554 cfAd_database->ad_cname.bv_val, 0,
7556 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
7559 thrctx = ldap_pvt_thread_pool_context();
7560 connection_fake_init2( &conn, &opbuf, thrctx,0 );
7562 op->o_bd = &cfb->cb_db;
7563 op->o_tag = LDAP_REQ_ADD;
7564 op->o_dn = be->be_rootdn;
7565 op->o_ndn = be->be_rootndn;
7568 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
7569 if ( rc != LDAP_SUCCESS ) {
7570 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
7571 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7574 if (ce && bi && bi->bi_tool_entry_put &&
7575 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
7576 entry_put_got_config++;
7578 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
7579 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7583 entry_put_got_config++;
7587 if ( bi && bi->bi_tool_entry_put &&
7588 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
7589 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
7595 config_tool_entry_modify( BackendDB *be, Entry *e, struct berval *text )
7597 CfBackInfo *cfb = be->be_private;
7598 BackendInfo *bi = cfb->cb_db.bd_info;
7599 CfEntryInfo *ce, *last;
7600 ConfigArgs ca = {0};
7602 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
7604 if ( ce && bi && bi->bi_tool_entry_modify )
7605 return bi->bi_tool_entry_modify( &cfb->cb_db, e, text );
7612 AttributeDescription **desc;
7614 { "attribute", &cfAd_attr },
7615 { "backend", &cfAd_backend },
7616 { "database", &cfAd_database },
7617 { "include", &cfAd_include },
7618 { "ldapsyntax", &cfAd_syntax },
7619 { "objectclass", &cfAd_oc },
7620 { "objectidentifier", &cfAd_om },
7621 { "overlay", &cfAd_overlay },
7626 * add / delete: all types that may be added or deleted must use an
7627 * X-ORDERED attributeType for their RDN. Adding and deleting entries
7628 * should automatically renumber the index of any siblings as needed,
7629 * so that no gaps in the numbering sequence exist after the add/delete
7631 * What can be added:
7633 * backend objects for backend-specific config directives
7637 * delete: probably no support this time around.
7639 * modrdn: generally not done. Will be invoked automatically by add/
7640 * delete to update numbering sequence. Perform as an explicit operation
7641 * so that the renumbering effect may be replicated. Subtree rename must
7642 * be supported, since renumbering a database will affect all its child
7645 * modify: must be fully supported.
7649 config_back_initialize( BackendInfo *bi )
7651 ConfigTable *ct = config_back_cf_table;
7655 AttributeDescription *ad = NULL;
7657 static char *controls[] = {
7658 LDAP_CONTROL_MANAGEDSAIT,
7662 /* Make sure we don't exceed the bits reserved for userland */
7663 config_check_userland( CFG_LAST );
7665 bi->bi_controls = controls;
7670 bi->bi_destroy = config_back_destroy;
7672 bi->bi_db_init = config_back_db_init;
7673 bi->bi_db_config = 0;
7674 bi->bi_db_open = config_back_db_open;
7675 bi->bi_db_close = config_back_db_close;
7676 bi->bi_db_destroy = config_back_db_destroy;
7678 bi->bi_op_bind = config_back_bind;
7679 bi->bi_op_unbind = 0;
7680 bi->bi_op_search = config_back_search;
7681 bi->bi_op_compare = 0;
7682 bi->bi_op_modify = config_back_modify;
7683 bi->bi_op_modrdn = config_back_modrdn;
7684 bi->bi_op_add = config_back_add;
7685 bi->bi_op_delete = config_back_delete;
7686 bi->bi_op_abandon = 0;
7688 bi->bi_extended = 0;
7690 bi->bi_chk_referrals = 0;
7692 bi->bi_access_allowed = slap_access_allowed;
7694 bi->bi_connection_init = 0;
7695 bi->bi_connection_destroy = 0;
7697 bi->bi_entry_release_rw = config_entry_release;
7698 bi->bi_entry_get_rw = config_back_entry_get;
7700 bi->bi_tool_entry_open = config_tool_entry_open;
7701 bi->bi_tool_entry_close = config_tool_entry_close;
7702 bi->bi_tool_entry_first = config_tool_entry_first;
7703 bi->bi_tool_entry_first_x = config_tool_entry_first_x;
7704 bi->bi_tool_entry_next = config_tool_entry_next;
7705 bi->bi_tool_dn2id_get = config_tool_dn2id_get;
7706 bi->bi_tool_entry_get = config_tool_entry_get;
7707 bi->bi_tool_entry_put = config_tool_entry_put;
7708 bi->bi_tool_entry_modify = config_tool_entry_modify;
7711 argv[ 0 ] = "slapd";
7717 for (i=0; OidMacros[i].name; i++ ) {
7718 argv[1] = OidMacros[i].name;
7719 argv[2] = OidMacros[i].oid;
7720 parse_oidm( &ca, 0, NULL );
7723 bi->bi_cf_ocs = cf_ocs;
7725 i = config_register_schema( ct, cf_ocs );
7728 i = slap_str2ad( "olcDatabase", &olcDatabaseDummy[0].ad, &text );
7731 /* setup olcRootPW to be base64-encoded when written in LDIF form;
7732 * basically, we don't care if it fails */
7733 i = slap_str2ad( "olcRootPW", &ad, &text );
7735 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
7736 "warning, unable to get \"olcRootPW\" "
7737 "attribute description: %d: %s\n",
7740 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
7741 ad->ad_type->sat_oid );
7744 /* set up the notable AttributeDescriptions */
7746 for (;ct->name;ct++) {
7747 if (strcmp(ct->name, ads[i].name)) continue;
7748 *ads[i].desc = ct->ad;
7750 if (!ads[i].name) break;