1 /* bconfig.c - the config backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005-2013 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was originally developed by Howard Chu for inclusion
18 * in OpenLDAP Software.
24 #include <ac/string.h>
28 #include <ac/unistd.h>
33 #include "slapi/slapi.h"
41 #define CONFIG_RDN "cn=config"
42 #define SCHEMA_RDN "cn=schema"
44 static struct berval config_rdn = BER_BVC(CONFIG_RDN);
45 static struct berval schema_rdn = BER_BVC(SCHEMA_RDN);
47 extern int slap_DN_strict; /* dn.c */
50 typedef struct modpath_s {
51 struct modpath_s *mp_next;
52 struct berval mp_path;
56 static ModPaths modpaths, *modlast = &modpaths, *modcur = &modpaths;
59 typedef struct ConfigFile {
60 struct ConfigFile *c_sibs;
61 struct ConfigFile *c_kids;
63 AttributeType *c_at_head, *c_at_tail;
64 ContentRule *c_cr_head, *c_cr_tail;
65 ObjectClass *c_oc_head, *c_oc_tail;
66 OidMacro *c_om_head, *c_om_tail;
67 Syntax *c_syn_head, *c_syn_tail;
72 ConfigFile *cb_config;
74 BackendDB cb_db; /* underlying database */
79 static CfBackInfo cfBackInfo;
81 static char *passwd_salt;
83 static char *logfileName;
84 #ifdef SLAP_AUTH_REWRITE
85 static BerVarray authz_rewrites;
87 static AccessControl *defacl_parsed = NULL;
89 static struct berval cfdir;
92 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
93 *cfAd_include, *cfAd_attr, *cfAd_oc, *cfAd_om, *cfAd_syntax;
95 static ConfigFile *cfn;
97 static Avlnode *CfOcTree;
99 /* System schema state */
100 extern AttributeType *at_sys_tail; /* at.c */
101 extern ObjectClass *oc_sys_tail; /* oc.c */
102 extern OidMacro *om_sys_tail; /* oidm.c */
103 extern Syntax *syn_sys_tail; /* syntax.c */
104 static AttributeType *cf_at_tail;
105 static ObjectClass *cf_oc_tail;
106 static OidMacro *cf_om_tail;
107 static Syntax *cf_syn_tail;
109 static int config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca,
110 SlapReply *rs, int *renumber, Operation *op );
112 static int config_check_schema( Operation *op, CfBackInfo *cfb );
114 static ConfigDriver config_fname;
115 static ConfigDriver config_cfdir;
116 static ConfigDriver config_generic;
117 static ConfigDriver config_search_base;
118 static ConfigDriver config_passwd_hash;
119 static ConfigDriver config_schema_dn;
120 static ConfigDriver config_sizelimit;
121 static ConfigDriver config_timelimit;
122 static ConfigDriver config_overlay;
123 static ConfigDriver config_subordinate;
124 static ConfigDriver config_suffix;
125 #ifdef LDAP_TCP_BUFFER
126 static ConfigDriver config_tcp_buffer;
127 #endif /* LDAP_TCP_BUFFER */
128 static ConfigDriver config_rootdn;
129 static ConfigDriver config_rootpw;
130 static ConfigDriver config_restrict;
131 static ConfigDriver config_allows;
132 static ConfigDriver config_disallows;
133 static ConfigDriver config_requires;
134 static ConfigDriver config_security;
135 static ConfigDriver config_referral;
136 static ConfigDriver config_loglevel;
137 static ConfigDriver config_updatedn;
138 static ConfigDriver config_updateref;
139 static ConfigDriver config_extra_attrs;
140 static ConfigDriver config_include;
141 static ConfigDriver config_obsolete;
143 static ConfigDriver config_tls_option;
144 static ConfigDriver config_tls_config;
146 extern ConfigDriver syncrepl_config;
154 CFG_TLS_PROTOCOL_MIN,
210 static OidRec OidMacros[] = {
211 /* OpenLDAProot:1.12.2 */
212 { "OLcfg", "1.3.6.1.4.1.4203.1.12.2" },
213 { "OLcfgAt", "OLcfg:3" },
214 { "OLcfgGlAt", "OLcfgAt:0" },
215 { "OLcfgBkAt", "OLcfgAt:1" },
216 { "OLcfgDbAt", "OLcfgAt:2" },
217 { "OLcfgOvAt", "OLcfgAt:3" },
218 { "OLcfgCtAt", "OLcfgAt:4" }, /* contrib modules */
219 { "OLcfgOc", "OLcfg:4" },
220 { "OLcfgGlOc", "OLcfgOc:0" },
221 { "OLcfgBkOc", "OLcfgOc:1" },
222 { "OLcfgDbOc", "OLcfgOc:2" },
223 { "OLcfgOvOc", "OLcfgOc:3" },
224 { "OLcfgCtOc", "OLcfgOc:4" }, /* contrib modules */
226 /* Syntaxes. We should just start using the standard names and
227 * document that they are predefined and available for users
228 * to reference in their own schema. Defining schema without
229 * OID macros is for masochists...
231 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
232 { "OMsBoolean", "OMsyn:7" },
233 { "OMsDN", "OMsyn:12" },
234 { "OMsDirectoryString", "OMsyn:15" },
235 { "OMsIA5String", "OMsyn:26" },
236 { "OMsInteger", "OMsyn:27" },
237 { "OMsOID", "OMsyn:38" },
238 { "OMsOctetString", "OMsyn:40" },
243 * Backend/Database registry
245 * OLcfg{Bk|Db}{Oc|At}:0 -> common
246 * OLcfg{Bk|Db}{Oc|At}:1 -> back-bdb(/back-hdb)
247 * OLcfg{Bk|Db}{Oc|At}:2 -> back-ldif
248 * OLcfg{Bk|Db}{Oc|At}:3 -> back-ldap/meta
249 * OLcfg{Bk|Db}{Oc|At}:4 -> back-monitor
250 * OLcfg{Bk|Db}{Oc|At}:5 -> back-relay
251 * OLcfg{Bk|Db}{Oc|At}:6 -> back-sql(/back-ndb)
252 * OLcfg{Bk|Db}{Oc|At}:7 -> back-sock
253 * OLcfg{Bk|Db}{Oc|At}:8 -> back-null
254 * OLcfg{Bk|Db}{Oc|At}:9 -> back-passwd
255 * OLcfg{Bk|Db}{Oc|At}:10 -> back-shell
256 * OLcfg{Bk|Db}{Oc|At}:11 -> back-perl
257 * OLcfg{Bk|Db}{Oc|At}:12 -> back-mdb
263 * OLcfgOv{Oc|At}:1 -> syncprov
264 * OLcfgOv{Oc|At}:2 -> pcache
265 * OLcfgOv{Oc|At}:3 -> chain
266 * OLcfgOv{Oc|At}:4 -> accesslog
267 * OLcfgOv{Oc|At}:5 -> valsort
268 * OLcfgOv{Oc|At}:7 -> distproc
269 * OLcfgOv{Oc|At}:8 -> dynlist
270 * OLcfgOv{Oc|At}:9 -> dds
271 * OLcfgOv{Oc|At}:10 -> unique
272 * OLcfgOv{Oc|At}:11 -> refint
273 * OLcfgOv{Oc|At}:12 -> ppolicy
274 * OLcfgOv{Oc|At}:13 -> constraint
275 * OLcfgOv{Oc|At}:14 -> translucent
276 * OLcfgOv{Oc|At}:15 -> auditlog
277 * OLcfgOv{Oc|At}:16 -> rwm
278 * OLcfgOv{Oc|At}:17 -> dyngroup
279 * OLcfgOv{Oc|At}:18 -> memberof
280 * OLcfgOv{Oc|At}:19 -> collect
281 * OLcfgOv{Oc|At}:20 -> retcode
282 * OLcfgOv{Oc|At}:21 -> sssvlv
285 /* alphabetical ordering */
287 static ConfigTable config_back_cf_table[] = {
288 /* This attr is read-only */
289 { "", "", 0, 0, 0, ARG_MAGIC,
290 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
291 "DESC 'File for slapd configuration directives' "
292 "EQUALITY caseIgnoreMatch "
293 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
294 { "", "", 0, 0, 0, ARG_MAGIC,
295 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
296 "DESC 'Directory for slapd configuration backend' "
297 "EQUALITY caseIgnoreMatch "
298 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
299 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
300 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
301 "DESC 'Access Control List' "
302 "EQUALITY caseIgnoreMatch "
303 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
304 { "add_content_acl", NULL, 0, 0, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_ACL_ADD,
305 &config_generic, "( OLcfgGlAt:86 NAME 'olcAddContentAcl' "
306 "DESC 'Check ACLs against content of Add ops' "
307 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
308 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
309 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
310 "DESC 'Allowed set of deprecated features' "
311 "EQUALITY caseIgnoreMatch "
312 "SYNTAX OMsDirectoryString )", NULL, NULL },
313 { "argsfile", "file", 2, 2, 0, ARG_STRING,
314 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
315 "DESC 'File for slapd command line options' "
316 "EQUALITY caseIgnoreMatch "
317 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
318 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
319 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
320 "EQUALITY caseIgnoreMatch "
321 "SYNTAX OMsDirectoryString )", NULL, NULL },
322 { "attribute", "attribute", 2, 0, STRLENOF( "attribute" ),
323 ARG_PAREN|ARG_MAGIC|CFG_ATTR,
324 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
325 "DESC 'OpenLDAP attributeTypes' "
326 "EQUALITY caseIgnoreMatch "
327 "SUBSTR caseIgnoreSubstringsMatch "
328 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
330 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
331 #ifdef SLAP_AUTH_REWRITE
332 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
336 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
337 "EQUALITY caseIgnoreMatch "
338 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
339 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
340 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
341 "EQUALITY caseIgnoreMatch "
342 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
343 { "authz-regexp", "regexp> <DN", 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
344 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
345 "EQUALITY caseIgnoreMatch "
346 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
347 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
348 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
349 "DESC 'A type of backend' "
350 "EQUALITY caseIgnoreMatch "
351 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
353 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
354 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
355 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
356 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
357 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
358 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
359 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
360 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
361 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
362 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
363 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
364 "DESC 'The backend type for a database instance' "
365 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
366 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
367 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
368 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
369 { "disabled", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_DISABLED,
370 &config_generic, "( OLcfgDbAt:0.21 NAME 'olcDisabled' "
371 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
372 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
373 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
374 "EQUALITY caseIgnoreMatch "
375 "SYNTAX OMsDirectoryString )", NULL, NULL },
376 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
377 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
378 "DESC 'OpenLDAP DIT content rules' "
379 "EQUALITY caseIgnoreMatch "
380 "SUBSTR caseIgnoreSubstringsMatch "
381 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
383 { "extra_attrs", "attrlist", 2, 2, 0, ARG_DB|ARG_MAGIC,
384 &config_extra_attrs, "( OLcfgDbAt:0.20 NAME 'olcExtraAttrs' "
385 "EQUALITY caseIgnoreMatch "
386 "SYNTAX OMsDirectoryString )", NULL, NULL },
387 { "gentlehup", "on|off", 2, 2, 0,
389 ARG_ON_OFF, &global_gentlehup,
393 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
394 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
395 { "hidden", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_HIDDEN,
396 &config_generic, "( OLcfgDbAt:0.17 NAME 'olcHidden' "
397 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
398 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
399 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
400 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
401 { "include", "file", 2, 2, 0, ARG_MAGIC,
402 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
403 "SUP labeledURI )", NULL, NULL },
404 { "index_hash64", "on|off", 2, 2, 0, ARG_ON_OFF|ARG_MAGIC|CFG_IX_HASH64,
405 &config_generic, "( OLcfgGlAt:94 NAME 'olcIndexHash64' "
406 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
407 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
408 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
409 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
410 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
411 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
412 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
413 { "index_substr_any_len", "len", 2, 2, 0, ARG_UINT|ARG_NONZERO,
414 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
415 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
416 { "index_substr_any_step", "step", 2, 2, 0, ARG_UINT|ARG_NONZERO,
417 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
418 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
419 { "index_intlen", "len", 2, 2, 0, ARG_UINT|ARG_MAGIC|CFG_IX_INTLEN,
420 &config_generic, "( OLcfgGlAt:84 NAME 'olcIndexIntLen' "
421 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
422 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
423 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
424 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
425 { "ldapsyntax", "syntax", 2, 0, 0,
426 ARG_PAREN|ARG_MAGIC|CFG_SYNTAX,
427 &config_generic, "( OLcfgGlAt:85 NAME 'olcLdapSyntaxes' "
428 "DESC 'OpenLDAP ldapSyntax' "
429 "EQUALITY caseIgnoreMatch "
430 "SUBSTR caseIgnoreSubstringsMatch "
431 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
433 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
434 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
435 "EQUALITY caseIgnoreMatch "
436 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
437 { "listener-threads", "count", 2, 0, 0,
441 ARG_UINT|ARG_MAGIC|CFG_LTHREADS, &config_generic,
443 "( OLcfgGlAt:93 NAME 'olcListenerThreads' "
444 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
445 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
446 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
447 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
448 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
449 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
450 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
451 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
452 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
453 "EQUALITY caseIgnoreMatch "
454 "SYNTAX OMsDirectoryString )", NULL, NULL },
455 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
456 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
457 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
458 { "mirrormode", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_MIRRORMODE,
459 &config_generic, "( OLcfgDbAt:0.16 NAME 'olcMirrorMode' "
460 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
461 { "moduleload", "file", 2, 0, 0,
463 ARG_MAGIC|CFG_MODLOAD|ARG_NO_DELETE, &config_generic,
467 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
468 "EQUALITY caseIgnoreMatch "
469 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
470 { "modulepath", "path", 2, 2, 0,
472 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
476 "( OLcfgGlAt:31 NAME 'olcModulePath' "
477 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
478 { "monitoring", "TRUE|FALSE", 2, 2, 0,
479 ARG_MAGIC|CFG_MONITORING|ARG_DB|ARG_ON_OFF, &config_generic,
480 "( OLcfgDbAt:0.18 NAME 'olcMonitoring' "
481 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
482 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
483 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
484 "DESC 'OpenLDAP object classes' "
485 "EQUALITY caseIgnoreMatch "
486 "SUBSTR caseIgnoreSubstringsMatch "
487 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
489 { "objectidentifier", "name> <oid", 3, 3, 0, ARG_MAGIC|CFG_OID,
490 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
491 "EQUALITY caseIgnoreMatch "
492 "SUBSTR caseIgnoreSubstringsMatch "
493 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
494 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
495 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
496 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
497 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
498 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
499 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
500 { "password-hash", "hash", 2, 0, 0, ARG_MAGIC,
501 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
502 "EQUALITY caseIgnoreMatch "
503 "SYNTAX OMsDirectoryString )", NULL, NULL },
504 { "pidfile", "file", 2, 2, 0, ARG_STRING,
505 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
506 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
507 { "plugin", NULL, 0, 0, 0,
509 ARG_MAGIC|CFG_PLUGIN, &config_generic,
513 "( OLcfgGlAt:38 NAME 'olcPlugin' "
514 "EQUALITY caseIgnoreMatch "
515 "SYNTAX OMsDirectoryString )", NULL, NULL },
516 { "pluginlog", "filename", 2, 2, 0,
518 ARG_STRING, &slapi_log_file,
522 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
523 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
524 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
525 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
526 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
527 { "referral", "url", 2, 2, 0, ARG_MAGIC,
528 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
529 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
530 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
531 &config_obsolete, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
532 "EQUALITY caseIgnoreMatch "
533 "SUP labeledURI X-ORDERED 'VALUES' )", NULL, NULL },
534 { "replica-argsfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
535 &config_obsolete, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
536 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
537 { "replica-pidfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
538 &config_obsolete, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
539 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
540 { "replicationInterval", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
541 &config_obsolete, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
542 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
543 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC,
544 &config_obsolete, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
545 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
546 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
547 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
548 "EQUALITY caseIgnoreMatch "
549 "SYNTAX OMsDirectoryString )", NULL, NULL },
550 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
551 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
552 "EQUALITY caseIgnoreMatch "
553 "SYNTAX OMsDirectoryString )", NULL, NULL },
554 { "reverse-lookup", "on|off", 2, 2, 0,
555 #ifdef SLAPD_RLOOKUPS
556 ARG_ON_OFF, &use_reverse_lookup,
560 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
561 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
562 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
563 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
564 "EQUALITY distinguishedNameMatch "
565 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
566 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
567 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
568 "EQUALITY caseIgnoreMatch "
569 "SYNTAX OMsDirectoryString )", NULL, NULL },
570 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
571 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
572 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
573 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
574 &config_generic, NULL, NULL, NULL },
575 { "sasl-auxprops", NULL, 2, 0, 0,
576 #ifdef HAVE_CYRUS_SASL
577 ARG_STRING|ARG_UNIQUE, &slap_sasl_auxprops,
581 "( OLcfgGlAt:89 NAME 'olcSaslAuxprops' "
582 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
583 { "sasl-auxprops-dontusecopy", NULL, 2, 0, 0,
584 #if defined(HAVE_CYRUS_SASL) && defined(SLAP_AUXPROP_DONTUSECOPY)
585 ARG_MAGIC|CFG_AZDUC, &config_generic,
589 "( OLcfgGlAt:91 NAME 'olcSaslAuxpropsDontUseCopy' "
590 "EQUALITY caseIgnoreMatch "
591 "SYNTAX OMsDirectoryString )", NULL, NULL },
592 { "sasl-auxprops-dontusecopy-ignore", "true|FALSE", 2, 0, 0,
593 #if defined(HAVE_CYRUS_SASL) && defined(SLAP_AUXPROP_DONTUSECOPY)
594 ARG_ON_OFF|CFG_AZDUC_IGNORE, &slap_dontUseCopy_ignore,
598 "( OLcfgGlAt:92 NAME 'olcSaslAuxpropsDontUseCopyIgnore' "
599 "EQUALITY booleanMatch "
600 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
601 { "sasl-host", "host", 2, 2, 0,
602 #ifdef HAVE_CYRUS_SASL
603 ARG_STRING|ARG_UNIQUE, &sasl_host,
607 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
608 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
609 { "sasl-realm", "realm", 2, 2, 0,
610 #ifdef HAVE_CYRUS_SASL
611 ARG_STRING|ARG_UNIQUE, &global_realm,
615 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
616 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
617 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
618 &config_generic, NULL, NULL, NULL },
619 { "sasl-secprops", "properties", 2, 2, 0,
620 #ifdef HAVE_CYRUS_SASL
621 ARG_MAGIC|CFG_SASLSECP, &config_generic,
625 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
626 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
627 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
628 &config_generic, NULL, NULL, NULL },
629 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
630 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
631 "EQUALITY distinguishedNameMatch "
632 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
633 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
634 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
635 "EQUALITY caseIgnoreMatch "
636 "SYNTAX OMsDirectoryString )", NULL, NULL },
637 { "serverID", "number> <[URI]", 2, 3, 0, ARG_MAGIC|CFG_SERVERID,
638 &config_generic, "( OLcfgGlAt:81 NAME 'olcServerID' "
639 "EQUALITY caseIgnoreMatch "
640 "SYNTAX OMsDirectoryString )", NULL, NULL },
641 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
642 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
643 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
644 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
645 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
646 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
647 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
648 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
649 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
650 { "sortvals", "attr", 2, 0, 0, ARG_MAGIC|CFG_SORTVALS,
651 &config_generic, "( OLcfgGlAt:83 NAME 'olcSortVals' "
652 "DESC 'Attributes whose values will always be sorted' "
653 "EQUALITY caseIgnoreMatch "
654 "SYNTAX OMsDirectoryString )", NULL, NULL },
655 { "subordinate", "[advertise]", 1, 2, 0, ARG_DB|ARG_MAGIC,
656 &config_subordinate, "( OLcfgDbAt:0.15 NAME 'olcSubordinate' "
657 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
658 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
659 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
660 "EQUALITY distinguishedNameMatch "
661 "SYNTAX OMsDN )", NULL, NULL },
662 { "sync_use_subentry", NULL, 0, 0, 0, ARG_ON_OFF|ARG_DB|ARG_MAGIC|CFG_SYNC_SUBENTRY,
663 &config_generic, "( OLcfgDbAt:0.19 NAME 'olcSyncUseSubentry' "
664 "DESC 'Store sync context in a subentry' "
665 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
666 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
667 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
668 "EQUALITY caseIgnoreMatch "
669 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
670 { "tcp-buffer", "[listener=<listener>] [{read|write}=]size", 0, 0, 0,
671 #ifndef LDAP_TCP_BUFFER
673 #else /* LDAP_TCP_BUFFER */
674 ARG_MAGIC, &config_tcp_buffer,
675 #endif /* LDAP_TCP_BUFFER */
676 "( OLcfgGlAt:90 NAME 'olcTCPBuffer' "
677 "DESC 'Custom TCP buffer size' "
678 "SYNTAX OMsDirectoryString )", NULL, NULL },
679 { "threads", "count", 2, 2, 0,
683 ARG_INT|ARG_MAGIC|CFG_THREADS, &config_generic,
685 "( OLcfgGlAt:66 NAME 'olcThreads' "
686 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
687 { "threadqueues", "count", 2, 2, 0,
691 ARG_INT|ARG_MAGIC|CFG_THREADQS, &config_generic,
693 "( OLcfgGlAt:95 NAME 'olcThreadQueues' "
694 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
695 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
696 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
697 "SYNTAX OMsDirectoryString )", NULL, NULL },
698 { "TLSCACertificateFile", NULL, 2, 2, 0,
700 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
704 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
705 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
706 { "TLSCACertificatePath", NULL, 2, 2, 0,
708 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
712 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
713 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
714 { "TLSCertificateFile", NULL, 2, 2, 0,
716 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
720 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
721 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
722 { "TLSCertificateKeyFile", NULL, 2, 2, 0,
724 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
728 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
729 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
730 { "TLSCipherSuite", NULL, 2, 2, 0,
732 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
736 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
737 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
738 { "TLSCRLCheck", NULL, 2, 2, 0,
739 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
740 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
744 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
745 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
746 { "TLSCRLFile", NULL, 2, 2, 0,
747 #if defined(HAVE_GNUTLS)
748 CFG_TLS_CRL_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
752 "( OLcfgGlAt:82 NAME 'olcTLSCRLFile' "
753 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
754 { "TLSRandFile", NULL, 2, 2, 0,
756 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
760 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
761 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
762 { "TLSVerifyClient", NULL, 2, 2, 0,
764 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
768 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
769 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
770 { "TLSDHParamFile", NULL, 2, 2, 0,
772 CFG_TLS_DH_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
776 "( OLcfgGlAt:77 NAME 'olcTLSDHParamFile' "
777 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
778 { "TLSProtocolMin", NULL, 2, 2, 0,
780 CFG_TLS_PROTOCOL_MIN|ARG_STRING|ARG_MAGIC, &config_tls_config,
784 "( OLcfgGlAt:87 NAME 'olcTLSProtocolMin' "
785 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
786 { "tool-threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_TTHREADS,
787 &config_generic, "( OLcfgGlAt:80 NAME 'olcToolThreads' "
788 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
789 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
790 NULL, NULL, NULL, NULL },
791 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
792 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
793 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
794 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
795 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
796 "EQUALITY caseIgnoreMatch "
797 "SUP labeledURI )", NULL, NULL },
798 { "writetimeout", "timeout", 2, 2, 0, ARG_INT,
799 &global_writetimeout, "( OLcfgGlAt:88 NAME 'olcWriteTimeout' "
800 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
801 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
802 NULL, NULL, NULL, NULL }
805 /* Need to no-op this keyword for dynamic config */
806 ConfigTable olcDatabaseDummy[] = {
807 { "", "", 0, 0, 0, ARG_IGNORED,
808 NULL, "( OLcfgGlAt:13 NAME 'olcDatabase' "
809 "DESC 'The backend type for a database instance' "
810 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
811 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
814 /* Routines to check if a child can be added to this type */
815 static ConfigLDAPadd cfAddSchema, cfAddInclude, cfAddDatabase,
816 cfAddBackend, cfAddModule, cfAddOverlay;
818 /* NOTE: be careful when defining array members
819 * that can be conditionally compiled */
820 #define CFOC_GLOBAL cf_ocs[1]
821 #define CFOC_SCHEMA cf_ocs[2]
822 #define CFOC_BACKEND cf_ocs[3]
823 #define CFOC_DATABASE cf_ocs[4]
824 #define CFOC_OVERLAY cf_ocs[5]
825 #define CFOC_INCLUDE cf_ocs[6]
826 #define CFOC_FRONTEND cf_ocs[7]
828 #define CFOC_MODULE cf_ocs[8]
829 #endif /* SLAPD_MODULES */
831 static ConfigOCs cf_ocs[] = {
834 "DESC 'OpenLDAP configuration object' "
835 "ABSTRACT SUP top )", Cft_Abstract, NULL },
838 "DESC 'OpenLDAP Global configuration options' "
839 "SUP olcConfig STRUCTURAL "
840 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
841 "olcAttributeOptions $ olcAuthIDRewrite $ "
842 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
843 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
844 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
845 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
846 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcIndexHash64 $ "
848 "olcListenerThreads $ olcLocalSSF $ olcLogFile $ olcLogLevel $ "
849 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
850 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
851 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
853 "olcSaslAuxprops $ olcSaslAuxpropsDontUseCopy $ olcSaslAuxpropsDontUseCopyIgnore $ "
854 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
855 "olcSecurity $ olcServerID $ olcSizeLimit $ "
856 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ "
858 "olcThreads $ olcThreadQueues $ "
859 "olcTimeLimit $ olcTLSCACertificateFile $ "
860 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
861 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
862 "olcTLSRandFile $ olcTLSVerifyClient $ olcTLSDHParamFile $ "
863 "olcTLSCRLFile $ olcToolThreads $ olcWriteTimeout $ "
864 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
865 "olcDitContentRules $ olcLdapSyntaxes ) )", Cft_Global },
867 "NAME 'olcSchemaConfig' "
868 "DESC 'OpenLDAP schema object' "
869 "SUP olcConfig STRUCTURAL "
870 "MAY ( cn $ olcObjectIdentifier $ olcLdapSyntaxes $ "
871 "olcAttributeTypes $ olcObjectClasses $ olcDitContentRules ) )",
872 Cft_Schema, NULL, cfAddSchema },
874 "NAME 'olcBackendConfig' "
875 "DESC 'OpenLDAP Backend-specific options' "
876 "SUP olcConfig STRUCTURAL "
877 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
879 "NAME 'olcDatabaseConfig' "
880 "DESC 'OpenLDAP Database-specific options' "
881 "SUP olcConfig STRUCTURAL "
883 "MAY ( olcDisabled $ olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
884 "olcAddContentAcl $ olcLastMod $ olcLimits $ "
885 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
886 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
887 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
888 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncUseSubentry $ olcSyncrepl $ "
889 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef $ olcMirrorMode $ "
890 "olcMonitoring $ olcExtraAttrs ) )",
891 Cft_Database, NULL, cfAddDatabase },
893 "NAME 'olcOverlayConfig' "
894 "DESC 'OpenLDAP Overlay-specific options' "
895 "SUP olcConfig STRUCTURAL "
897 "MAY olcDisabled )", Cft_Overlay, NULL, cfAddOverlay },
899 "NAME 'olcIncludeFile' "
900 "DESC 'OpenLDAP configuration include file' "
901 "SUP olcConfig STRUCTURAL "
903 "MAY ( cn $ olcRootDSE ) )",
904 /* Used to be Cft_Include, that def has been removed */
905 Cft_Abstract, NULL, cfAddInclude },
906 /* This should be STRUCTURAL like all the other database classes, but
907 * that would mean inheriting all of the olcDatabaseConfig attributes,
908 * which causes them to be merged twice in config_build_entry.
911 "NAME 'olcFrontendConfig' "
912 "DESC 'OpenLDAP frontend configuration' "
914 "MAY ( olcDefaultSearchBase $ olcPasswordHash $ olcSortVals ) )",
915 Cft_Database, NULL, NULL },
918 "NAME 'olcModuleList' "
919 "DESC 'OpenLDAP dynamic module info' "
920 "SUP olcConfig STRUCTURAL "
921 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
922 Cft_Module, NULL, cfAddModule },
927 typedef struct ServerID {
928 struct ServerID *si_next;
929 struct berval si_url;
933 static ServerID *sid_list;
934 static ServerID *sid_set;
936 typedef struct voidList {
937 struct voidList *vl_next;
941 typedef struct ADlist {
942 struct ADlist *al_next;
943 AttributeDescription *al_desc;
946 static ADlist *sortVals;
949 config_generic(ConfigArgs *c) {
952 if ( c->op == SLAP_CONFIG_EMIT ) {
956 c->value_int = ldap_pvt_thread_get_concurrency();
959 c->value_int = connection_pool_max;
962 c->value_int = connection_pool_queues;
965 c->value_int = slap_tool_thread_max;
968 c->value_uint = slapd_daemon_threads;
972 c->value_string = ch_strdup( passwd_salt );
977 if ( c->be->be_limits ) {
981 for ( i=0; c->be->be_limits[i]; i++ ) {
982 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
983 if ( bv.bv_len >= sizeof( buf ) ) {
984 ber_bvarray_free_x( c->rvalue_vals, NULL );
985 c->rvalue_vals = NULL;
989 bv.bv_val = buf + bv.bv_len;
990 limits_unparse( c->be->be_limits[i], &bv,
991 sizeof( buf ) - ( bv.bv_val - buf ) );
992 bv.bv_len += bv.bv_val - buf;
994 value_add_one( &c->rvalue_vals, &bv );
997 if ( !c->rvalue_vals ) rc = 1;
1000 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_READONLY);
1003 c->value_string = ch_strdup( slap_sasl_getpolicy());
1006 slap_sasl_regexp_unparse( &c->rvalue_vals );
1007 if ( !c->rvalue_vals ) rc = 1;
1009 #ifdef HAVE_CYRUS_SASL
1010 #ifdef SLAP_AUXPROP_DONTUSECOPY
1012 static int duc_done = 0;
1014 /* take the opportunity to initialize with known values */
1016 struct berval duc[] = { BER_BVC("cmusaslsecretOTP"), BER_BVNULL };
1019 for ( i = 0; !BER_BVISNULL( &duc[ i ] ); i++ ) {
1020 const char *text = NULL;
1021 AttributeDescription *ad = NULL;
1023 if ( slap_bv2ad( &duc[ i ], &ad, &text ) == LDAP_SUCCESS ) {
1025 if ( slap_dontUseCopy_propnames ) {
1028 for ( j = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ j ] ); j++ ) {
1029 if ( bvmatch( &slap_dontUseCopy_propnames[ j ], &ad->ad_cname ) ) {
1036 value_add_one( &slap_dontUseCopy_propnames, &ad->ad_cname );
1044 if ( slap_dontUseCopy_propnames != NULL ) {
1045 ber_bvarray_dup_x( &c->rvalue_vals, slap_dontUseCopy_propnames, NULL );
1050 #endif /* SLAP_AUXPROP_DONTUSECOPY */
1051 case CFG_SASLSECP: {
1052 struct berval bv = BER_BVNULL;
1053 slap_sasl_secprops_unparse( &bv );
1054 if ( !BER_BVISNULL( &bv )) {
1055 ber_bvarray_add( &c->rvalue_vals, &bv );
1063 c->value_int = c->be->be_max_deref_depth;
1068 if ( c->bi->bi_flags & SLAPO_BFLAG_DISABLED ) {
1075 if ( SLAP_DBDISABLED( c->be )) {
1083 if ( SLAP_DBHIDDEN( c->be )) {
1090 ConfigFile *cf = c->ca_private;
1092 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1093 else if ( cf->c_om_head )
1094 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
1096 if ( !c->rvalue_vals )
1101 ad_unparse_options( &c->rvalue_vals );
1104 ConfigFile *cf = c->ca_private;
1106 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1107 else if ( cf->c_oc_head )
1108 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
1110 if ( !c->rvalue_vals )
1115 ConfigFile *cf = c->ca_private;
1117 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1118 else if ( cf->c_at_head )
1119 at_unparse( &c->rvalue_vals, cf->c_at_head,
1121 if ( !c->rvalue_vals )
1126 ConfigFile *cf = c->ca_private;
1128 syn_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1129 else if ( cf->c_syn_head )
1130 syn_unparse( &c->rvalue_vals, cf->c_syn_head,
1131 cf->c_syn_tail, 0 );
1132 if ( !c->rvalue_vals )
1137 ConfigFile *cf = c->ca_private;
1139 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1140 else if ( cf->c_cr_head )
1141 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
1143 if ( !c->rvalue_vals )
1150 char *src, *dst, ibuf[11];
1151 struct berval bv, abv;
1152 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
1153 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1154 if ( abv.bv_len >= sizeof( ibuf ) ) {
1155 ber_bvarray_free_x( c->rvalue_vals, NULL );
1156 c->rvalue_vals = NULL;
1160 acl_unparse( a, &bv );
1161 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
1162 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
1163 /* Turn TAB / EOL into plain space */
1164 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
1165 if (isspace((unsigned char)*src)) *dst++ = ' ';
1169 if (dst[-1] == ' ') {
1173 abv.bv_len = dst - abv.bv_val;
1174 ber_bvarray_add( &c->rvalue_vals, &abv );
1180 c->value_int = (SLAP_DBACL_ADD(c->be) != 0);
1183 ConfigFile *cf = c->ca_private;
1184 if ( cf->c_dseFiles ) {
1185 value_add( &c->rvalue_vals, cf->c_dseFiles );
1196 for ( si = sid_list; si; si=si->si_next ) {
1197 assert( si->si_num >= 0 && si->si_num <= SLAP_SYNC_SID_MAX );
1198 if ( !BER_BVISEMPTY( &si->si_url )) {
1199 bv.bv_len = si->si_url.bv_len + 6;
1200 bv.bv_val = ch_malloc( bv.bv_len );
1201 bv.bv_len = sprintf( bv.bv_val, "%d %s", si->si_num,
1202 si->si_url.bv_val );
1203 ber_bvarray_add( &c->rvalue_vals, &bv );
1207 bv.bv_len = sprintf( buf, "%d", si->si_num );
1208 value_add_one( &c->rvalue_vals, &bv );
1217 c->value_string = ch_strdup( logfileName );
1222 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1224 case CFG_SYNC_SUBENTRY:
1225 c->value_int = (SLAP_SYNC_SUBENTRY(c->be) != 0);
1227 case CFG_MIRRORMODE:
1228 if ( SLAP_SHADOW(c->be))
1229 c->value_int = (SLAP_MULTIMASTER(c->be) != 0);
1233 case CFG_MONITORING:
1234 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
1236 case CFG_SSTR_IF_MAX:
1237 c->value_uint = index_substr_if_maxlen;
1239 case CFG_SSTR_IF_MIN:
1240 c->value_uint = index_substr_if_minlen;
1243 c->value_int = slap_hash64( -1 );
1246 c->value_int = index_intlen;
1248 case CFG_SORTVALS: {
1251 for ( sv = sortVals; sv; sv = sv->al_next ) {
1252 value_add_one( &c->rvalue_vals, &sv->al_desc->ad_cname );
1256 #ifdef SLAPD_MODULES
1258 ModPaths *mp = c->ca_private;
1261 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
1264 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
1265 SLAP_X_ORDERED_FMT "%s", i,
1266 mp->mp_loads[i].bv_val );
1267 if ( bv.bv_len >= sizeof( c->log ) ) {
1268 ber_bvarray_free_x( c->rvalue_vals, NULL );
1269 c->rvalue_vals = NULL;
1272 value_add_one( &c->rvalue_vals, &bv );
1276 rc = c->rvalue_vals ? 0 : 1;
1280 ModPaths *mp = c->ca_private;
1281 if ( !BER_BVISNULL( &mp->mp_path ))
1282 value_add_one( &c->rvalue_vals, &mp->mp_path );
1284 rc = c->rvalue_vals ? 0 : 1;
1290 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1291 if ( !c->rvalue_vals ) rc = 1;
1294 #ifdef SLAP_AUTH_REWRITE
1296 if ( authz_rewrites ) {
1297 struct berval bv, idx;
1302 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1303 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1304 if ( idx.bv_len >= sizeof( ibuf ) ) {
1305 ber_bvarray_free_x( c->rvalue_vals, NULL );
1306 c->rvalue_vals = NULL;
1309 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1310 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1311 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1312 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1313 authz_rewrites[i].bv_val,
1314 authz_rewrites[i].bv_len + 1 );
1315 ber_bvarray_add( &c->rvalue_vals, &bv );
1318 if ( !c->rvalue_vals ) rc = 1;
1325 } else if ( c->op == LDAP_MOD_DELETE ) {
1328 /* single-valued attrs, no-ops */
1338 case CFG_MONITORING:
1340 case CFG_SSTR_IF_MAX:
1341 case CFG_SSTR_IF_MIN:
1343 case CFG_SYNC_SUBENTRY:
1346 /* no-ops, requires slapd restart */
1351 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1354 case CFG_MIRRORMODE:
1355 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MULTI_SHADOW;
1356 if(SLAP_SHADOW(c->be))
1357 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1360 #if defined(HAVE_CYRUS_SASL) && defined(SLAP_AUXPROP_DONTUSECOPY)
1362 if ( c->valx < 0 ) {
1363 if ( slap_dontUseCopy_propnames != NULL ) {
1364 ber_bvarray_free( slap_dontUseCopy_propnames );
1365 slap_dontUseCopy_propnames = NULL;
1371 if ( slap_dontUseCopy_propnames == NULL ) {
1376 for ( i = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ i ] ) && i < c->valx; i++ );
1377 if ( i < c->valx ) {
1381 ber_memfree( slap_dontUseCopy_propnames[ i ].bv_val );
1382 for ( ; !BER_BVISNULL( &slap_dontUseCopy_propnames[ i + 1 ] ); i++ ) {
1383 slap_dontUseCopy_propnames[ i ] = slap_dontUseCopy_propnames[ i + 1 ];
1385 BER_BVZERO( &slap_dontUseCopy_propnames[ i ] );
1388 #endif /* SLAP_AUXPROP_DONTUSECOPY */
1390 ch_free( passwd_salt );
1395 ch_free( logfileName );
1403 case CFG_SERVERID: {
1404 ServerID *si, **sip;
1406 for ( i=0, si = sid_list, sip = &sid_list;
1407 si; si = *sip, i++ ) {
1408 if ( c->valx == -1 || i == c->valx ) {
1410 if ( sid_set == si )
1422 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1427 c->bi->bi_flags &= ~SLAP_DBFLAG_DISABLED;
1428 if ( c->bi->bi_db_open ) {
1429 BackendInfo *bi_orig = c->be->bd_info;
1430 c->be->bd_info = c->bi;
1431 rc = c->bi->bi_db_open( c->be, &c->reply );
1432 c->be->bd_info = bi_orig;
1435 c->be->be_flags &= ~SLAP_DBFLAG_DISABLED;
1436 rc = backend_startup_one( c->be, &c->reply );
1445 index_intlen = SLAP_INDEX_INTLEN_DEFAULT;
1446 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1447 SLAP_INDEX_INTLEN_DEFAULT );
1451 if ( c->valx < 0 ) {
1452 acl_destroy( c->be->be_acl );
1453 c->be->be_acl = NULL;
1456 AccessControl **prev, *a;
1458 for (i=0, prev = &c->be->be_acl; i < c->valx;
1461 prev = &a->acl_next;
1464 *prev = a->acl_next;
1467 if ( SLAP_CONFIG( c->be ) && !c->be->be_acl ) {
1468 Debug( LDAP_DEBUG_CONFIG, "config_generic (CFG_ACL): "
1469 "Last explicit ACL for back-config removed. "
1470 "Using hardcoded default\n", 0, 0, 0 );
1471 c->be->be_acl = defacl_parsed;
1477 /* Can be NULL when undoing a failed add */
1478 if ( c->ca_entry ) {
1479 ce = c->ca_entry->e_private;
1480 /* can't modify the hardcoded schema */
1481 if ( ce->ce_parent->ce_type == Cft_Global )
1485 cfn = c->ca_private;
1486 if ( c->valx < 0 ) {
1489 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1491 if ( oc == cfn->c_oc_tail )
1494 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1496 ObjectClass *oc, *prev = NULL;
1498 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1503 if ( cfn->c_oc_tail == oc ) {
1504 cfn->c_oc_tail = prev;
1506 if ( cfn->c_oc_head == oc ) {
1508 cfn->c_oc_head = oc;
1515 /* Can be NULL when undoing a failed add */
1516 if ( c->ca_entry ) {
1517 ce = c->ca_entry->e_private;
1518 /* can't modify the hardcoded schema */
1519 if ( ce->ce_parent->ce_type == Cft_Global )
1523 cfn = c->ca_private;
1524 if ( c->valx < 0 ) {
1527 for( at = cfn->c_at_head; at; at_next( &at )) {
1529 if ( at == cfn->c_at_tail )
1532 cfn->c_at_head = cfn->c_at_tail = NULL;
1534 AttributeType *at, *prev = NULL;
1536 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1541 if ( cfn->c_at_tail == at ) {
1542 cfn->c_at_tail = prev;
1544 if ( cfn->c_at_head == at ) {
1546 cfn->c_at_head = at;
1553 /* Can be NULL when undoing a failed add */
1554 if ( c->ca_entry ) {
1555 ce = c->ca_entry->e_private;
1556 /* can't modify the hardcoded schema */
1557 if ( ce->ce_parent->ce_type == Cft_Global )
1561 cfn = c->ca_private;
1562 if ( c->valx < 0 ) {
1565 for( syn = cfn->c_syn_head; syn; syn_next( &syn )) {
1567 if ( syn == cfn->c_syn_tail )
1570 cfn->c_syn_head = cfn->c_syn_tail = NULL;
1572 Syntax *syn, *prev = NULL;
1574 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++) {
1579 if ( cfn->c_syn_tail == syn ) {
1580 cfn->c_syn_tail = prev;
1582 if ( cfn->c_syn_head == syn ) {
1584 cfn->c_syn_head = syn;
1589 if ( c->valx < 0 ) {
1591 for ( sv = sortVals; sv; sv = sortVals ) {
1592 sortVals = sv->al_next;
1593 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1600 for ( prev = &sortVals, sv = sortVals; i < c->valx; i++ ) {
1601 prev = &sv->al_next;
1604 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1605 *prev = sv->al_next;
1611 /* FIXME: there is no limits_free function */
1612 if ( c->valx < 0 ) {
1613 limits_destroy( c->be->be_limits );
1614 c->be->be_limits = NULL;
1619 if ( c->be->be_limits ) {
1620 for ( num = 0; c->be->be_limits[ num ]; num++ )
1624 if ( c->valx >= num ) {
1629 limits_destroy( c->be->be_limits );
1630 c->be->be_limits = NULL;
1633 limits_free_one( c->be->be_limits[ c->valx ] );
1635 for ( cnt = c->valx; cnt < num; cnt++ ) {
1636 c->be->be_limits[ cnt ] = c->be->be_limits[ cnt + 1 ];
1643 /* FIXME: there is no ad_option_free function */
1645 /* FIXME: there is no way to remove attributes added by
1659 if(!(c->bi = backend_info(c->argv[1]))) {
1660 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1661 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1662 c->log, c->cr_msg, c->argv[1] );
1669 /* NOTE: config is always the first backend!
1671 if ( !strcasecmp( c->argv[1], "config" )) {
1672 c->be = LDAP_STAILQ_FIRST(&backendDB);
1673 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1676 c->be = backend_db_init(c->argv[1], NULL, c->valx, &c->reply);
1678 if ( c->cr_msg[0] == 0 )
1679 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1680 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n", c->log, c->cr_msg, c->argv[1] );
1687 ldap_pvt_thread_set_concurrency(c->value_int);
1691 if ( c->value_int < 2 ) {
1692 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1693 "threads=%d smaller than minimum value 2",
1695 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1696 c->log, c->cr_msg, 0 );
1699 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1700 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1701 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1702 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1703 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1704 c->log, c->cr_msg, 0 );
1706 if ( slapMode & SLAP_SERVER_MODE )
1707 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1708 connection_pool_max = c->value_int; /* save for reference */
1712 if ( c->value_int < 1 ) {
1713 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1714 "threadqueuess=%d smaller than minimum value 1",
1716 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1717 c->log, c->cr_msg, 0 );
1720 connection_pool_queues = c->value_int; /* save for reference */
1724 if ( slapMode & SLAP_TOOL_MODE )
1725 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1726 slap_tool_thread_max = c->value_int; /* save for reference */
1731 /* use a power of two */
1732 while (c->value_uint > 1) {
1733 c->value_uint >>= 1;
1737 slapd_daemon_mask = mask;
1738 slapd_daemon_threads = mask+1;
1743 if ( passwd_salt ) ch_free( passwd_salt );
1744 passwd_salt = c->value_string;
1745 lutil_salt_format(passwd_salt);
1749 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1755 c->be->be_restrictops |= SLAP_RESTRICT_READONLY;
1757 c->be->be_restrictops &= ~SLAP_RESTRICT_READONLY;
1761 ch_free(c->value_string);
1762 if (slap_sasl_setpolicy( c->argv[1] )) {
1763 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
1764 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1765 c->log, c->cr_msg, c->argv[1] );
1771 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1775 #ifdef HAVE_CYRUS_SASL
1776 #ifdef SLAP_AUXPROP_DONTUSECOPY
1780 for ( arg = 1; arg < c->argc; arg++ ) {
1781 int duplicate = 0, err;
1782 AttributeDescription *ad = NULL;
1783 const char *text = NULL;
1785 err = slap_str2ad( c->argv[ arg ], &ad, &text );
1786 if ( err != LDAP_SUCCESS ) {
1787 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s>: attr #%d (\"%s\") unknown (err=%d \"%s\"; ignored)",
1788 c->argv[0], arg, c->argv[ arg ], err, text );
1789 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1790 c->log, c->cr_msg, 0 );
1793 if ( slap_dontUseCopy_propnames != NULL ) {
1794 for ( cnt = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ cnt ] ); cnt++ ) {
1795 if ( bvmatch( &slap_dontUseCopy_propnames[ cnt ], &ad->ad_cname ) ) {
1803 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s>: attr #%d (\"%s\") already defined (ignored)",
1804 c->argv[0], arg, ad->ad_cname.bv_val);
1805 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1806 c->log, c->cr_msg, 0 );
1810 value_add_one( &slap_dontUseCopy_propnames, &ad->ad_cname );
1815 #endif /* SLAP_AUXPROP_DONTUSECOPY */
1819 char *txt = slap_sasl_secprops( c->argv[1] );
1821 snprintf( c->cr_msg, sizeof(c->cr_msg), "<%s> %s",
1823 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0 );
1831 c->be->be_max_deref_depth = c->value_int;
1837 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1838 cfn = c->ca_private;
1839 if(parse_oidm(c, 1, &om))
1841 if (!cfn->c_om_head) cfn->c_om_head = om;
1842 cfn->c_om_tail = om;
1847 ObjectClass *oc, *prev;
1849 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1850 cfn = c->ca_private;
1851 if ( c->valx < 0 ) {
1852 prev = cfn->c_oc_tail;
1855 /* If adding anything after the first, prev is easy */
1858 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
1860 if ( !oc_next( &oc ))
1864 /* If adding the first, and head exists, find its prev */
1865 if (cfn->c_oc_head) {
1866 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
1871 /* else prev is NULL, append to end of global list */
1873 if(parse_oc(c, &oc, prev)) return(1);
1874 if (!cfn->c_oc_head || !c->valx) cfn->c_oc_head = oc;
1875 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
1880 AttributeType *at, *prev;
1882 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1883 cfn = c->ca_private;
1884 if ( c->valx < 0 ) {
1885 prev = cfn->c_at_tail;
1888 /* If adding anything after the first, prev is easy */
1891 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
1893 if ( !at_next( &at ))
1897 /* If adding the first, and head exists, find its prev */
1898 if (cfn->c_at_head) {
1899 for ( at_start( &at ); at != cfn->c_at_head; ) {
1904 /* else prev is NULL, append to end of global list */
1906 if(parse_at(c, &at, prev)) return(1);
1907 if (!cfn->c_at_head || !c->valx) cfn->c_at_head = at;
1908 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
1915 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1916 cfn = c->ca_private;
1917 if ( c->valx < 0 ) {
1918 prev = cfn->c_syn_tail;
1921 /* If adding anything after the first, prev is easy */
1924 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++ ) {
1926 if ( !syn_next( &syn ))
1930 /* If adding the first, and head exists, find its prev */
1931 if (cfn->c_syn_head) {
1932 for ( syn_start( &syn ); syn != cfn->c_syn_head; ) {
1937 /* else prev is NULL, append to end of global list */
1939 if ( parse_syn( c, &syn, prev ) ) return(1);
1940 if ( !cfn->c_syn_head || !c->valx ) cfn->c_syn_head = syn;
1941 if ( cfn->c_syn_tail == prev ) cfn->c_syn_tail = syn;
1948 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1949 cfn = c->ca_private;
1950 if(parse_cr(c, &cr)) return(1);
1951 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1952 cfn->c_cr_tail = cr;
1957 ad_define_option(NULL, NULL, 0);
1958 for(i = 1; i < c->argc; i++)
1959 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1964 if ( slap_hash64( c->value_int != 0 ))
1969 if ( c->value_int < SLAP_INDEX_INTLEN_DEFAULT )
1970 c->value_int = SLAP_INDEX_INTLEN_DEFAULT;
1971 else if ( c->value_int > 255 )
1973 index_intlen = c->value_int;
1974 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1978 case CFG_SORTVALS: {
1979 ADlist *svnew = NULL, *svtail, *sv;
1981 for ( i = 1; i < c->argc; i++ ) {
1982 AttributeDescription *ad = NULL;
1986 rc = slap_str2ad( c->argv[i], &ad, &text );
1988 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown attribute type #%d",
1991 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1992 c->log, c->cr_msg, c->argv[i] );
1993 for ( sv = svnew; sv; sv = svnew ) {
1994 svnew = sv->al_next;
1999 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) ||
2000 ad->ad_type->sat_single_value ) {
2001 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> inappropriate attribute type #%d",
2003 goto sortval_reject;
2005 sv = ch_malloc( sizeof( ADlist ));
2010 svtail->al_next = sv;
2015 for ( sv = svnew; sv; sv = sv->al_next )
2016 sv->al_desc->ad_type->sat_flags |= SLAP_AT_SORTED_VAL;
2017 for ( sv = sortVals; sv && sv->al_next; sv = sv->al_next );
2019 sv->al_next = svnew;
2026 if ( SLAP_CONFIG( c->be ) && c->be->be_acl == defacl_parsed) {
2027 c->be->be_acl = NULL;
2029 /* Don't append to the global ACL if we're on a specific DB */
2031 if ( c->valx == -1 ) {
2034 for ( a=c->be->be_acl; a; a = a->acl_next )
2037 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
2038 if ( SLAP_CONFIG( c->be ) && !c->be->be_acl) {
2039 c->be->be_acl = defacl_parsed;
2047 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_ACL_ADD;
2049 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_ACL_ADD;
2053 if(root_dse_read_file(c->argv[1])) {
2054 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> could not read file", c->argv[0] );
2055 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2056 c->log, c->cr_msg, c->argv[1] );
2061 ber_str2bv( c->argv[1], 0, 1, &bv );
2062 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
2063 cfn = c->ca_private;
2064 ber_bvarray_add( &cfn->c_dseFiles, &bv );
2070 ServerID *si, **sip;
2073 if (( lutil_atoi( &num, c->argv[1] ) &&
2074 lutil_atoix( &num, c->argv[1], 16 )) ||
2075 num < 0 || num > SLAP_SYNC_SID_MAX )
2077 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2078 "<%s> illegal server ID", c->argv[0] );
2079 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2080 c->log, c->cr_msg, c->argv[1] );
2083 /* only one value allowed if no URL is given */
2084 if ( c->argc > 2 ) {
2087 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
2088 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2089 "<%s> only one server ID allowed now", c->argv[0] );
2090 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2091 c->log, c->cr_msg, c->argv[1] );
2095 if ( ldap_url_parse( c->argv[2], &lud )) {
2096 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2097 "<%s> invalid URL", c->argv[0] );
2098 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2099 c->log, c->cr_msg, c->argv[2] );
2102 len = strlen( c->argv[2] );
2103 si = ch_malloc( sizeof(ServerID) + len + 1 );
2104 si->si_url.bv_val = (char *)(si+1);
2105 si->si_url.bv_len = len;
2106 strcpy( si->si_url.bv_val, c->argv[2] );
2109 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2110 "<%s> unqualified server ID not allowed now", c->argv[0] );
2111 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2112 c->log, c->cr_msg, c->argv[1] );
2115 si = ch_malloc( sizeof(ServerID) );
2116 BER_BVZERO( &si->si_url );
2117 slap_serverID = num;
2118 Debug( LDAP_DEBUG_CONFIG,
2120 c->log, slap_serverID, 0 );
2125 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
2128 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
2129 Listener *l = config_check_my_url( c->argv[2], lud );
2132 ldap_free_urldesc( lud );
2133 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2134 "<%s> multiple server ID URLs matched, only one is allowed", c->argv[0] );
2135 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2136 c->log, c->cr_msg, c->argv[1] );
2139 slap_serverID = si->si_num;
2140 Debug( LDAP_DEBUG_CONFIG,
2141 "%s: SID=0x%03x (listener=%s)\n",
2142 c->log, slap_serverID,
2148 ldap_free_urldesc( lud );
2152 if ( logfileName ) ch_free( logfileName );
2153 logfileName = c->value_string;
2154 logfile = fopen(logfileName, "w");
2155 if(logfile) lutil_debug_file(logfile);
2159 if(SLAP_NOLASTMODCMD(c->be)) {
2160 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> not available for %s database",
2161 c->argv[0], c->be->bd_info->bi_type );
2162 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2163 c->log, c->cr_msg, 0 );
2167 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
2169 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
2172 case CFG_MIRRORMODE:
2173 if(c->value_int && !SLAP_SHADOW(c->be)) {
2174 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database is not a shadow",
2176 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2177 c->log, c->cr_msg, 0 );
2181 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
2182 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MULTI_SHADOW;
2184 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
2185 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MULTI_SHADOW;
2189 case CFG_MONITORING:
2191 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
2193 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
2199 if ( c->bi->bi_db_close ) {
2200 BackendInfo *bi_orig = c->be->bd_info;
2201 c->be->bd_info = c->bi;
2202 c->bi->bi_db_close( c->be, &c->reply );
2203 c->be->bd_info = bi_orig;
2205 c->bi->bi_flags |= SLAPO_BFLAG_DISABLED;
2207 c->bi->bi_flags &= ~SLAPO_BFLAG_DISABLED;
2211 backend_shutdown( c->be );
2212 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_DISABLED;
2214 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_DISABLED;
2221 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
2223 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
2226 case CFG_SYNC_SUBENTRY:
2228 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SYNC_SUBENTRY;
2230 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SYNC_SUBENTRY;
2233 case CFG_SSTR_IF_MAX:
2234 if (c->value_uint < index_substr_if_minlen) {
2235 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
2236 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
2237 c->log, c->cr_msg, c->value_int );
2240 index_substr_if_maxlen = c->value_uint;
2243 case CFG_SSTR_IF_MIN:
2244 if (c->value_uint > index_substr_if_maxlen) {
2245 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
2246 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
2247 c->log, c->cr_msg, c->value_int );
2250 index_substr_if_minlen = c->value_uint;
2253 #ifdef SLAPD_MODULES
2255 /* If we're just adding a module on an existing modpath,
2256 * make sure we've selected the current path.
2258 if ( c->op == LDAP_MOD_ADD && c->ca_private && modcur != c->ca_private ) {
2259 modcur = c->ca_private;
2260 /* This should never fail */
2261 if ( module_path( modcur->mp_path.bv_val )) {
2262 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> module path no longer valid",
2264 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2265 c->log, c->cr_msg, modcur->mp_path.bv_val );
2269 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
2271 /* Record this load on the current path */
2275 if ( c->op == SLAP_CONFIG_ADD ) {
2276 ptr = c->line + STRLENOF("moduleload");
2277 while (!isspace((unsigned char) *ptr)) ptr++;
2278 while (isspace((unsigned char) *ptr)) ptr++;
2282 ber_str2bv(ptr, 0, 1, &bv);
2283 ber_bvarray_add( &modcur->mp_loads, &bv );
2285 /* Check for any new hardcoded schema */
2286 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
2287 config_check_schema( NULL, &cfBackInfo );
2292 if(module_path(c->argv[1])) return(1);
2293 /* Record which path was used with each module */
2297 if (!modpaths.mp_loads) {
2300 mp = ch_malloc( sizeof( ModPaths ));
2301 modlast->mp_next = mp;
2303 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
2305 mp->mp_loads = NULL;
2316 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
2318 slapi_plugins_used++;
2322 #ifdef SLAP_AUTH_REWRITE
2328 if ( c->op == LDAP_MOD_ADD ) {
2332 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
2336 if ( c->argc > 1 ) {
2339 /* quote all args but the first */
2340 line = ldap_charray2str( c->argv, "\" \"" );
2341 ber_str2bv( line, 0, 0, &bv );
2342 s = ber_bvchr( &bv, '"' );
2343 assert( s != NULL );
2344 /* move the trailing quote of argv[0] to the end */
2345 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
2346 bv.bv_val[ bv.bv_len - 1 ] = '"';
2349 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
2352 ber_bvarray_add( &authz_rewrites, &bv );
2354 if ( c->op == LDAP_MOD_ADD ) {
2364 Debug( LDAP_DEBUG_ANY,
2365 "%s: unknown CFG_TYPE %d.\n",
2366 c->log, c->type, 0 );
2375 config_fname(ConfigArgs *c) {
2376 if(c->op == SLAP_CONFIG_EMIT) {
2377 if (c->ca_private) {
2378 ConfigFile *cf = c->ca_private;
2379 value_add_one( &c->rvalue_vals, &cf->c_file );
2388 config_cfdir(ConfigArgs *c) {
2389 if(c->op == SLAP_CONFIG_EMIT) {
2390 if ( !BER_BVISEMPTY( &cfdir )) {
2391 value_add_one( &c->rvalue_vals, &cfdir );
2400 config_search_base(ConfigArgs *c) {
2401 if(c->op == SLAP_CONFIG_EMIT) {
2403 if (!BER_BVISEMPTY(&default_search_base)) {
2404 value_add_one(&c->rvalue_vals, &default_search_base);
2405 value_add_one(&c->rvalue_nvals, &default_search_nbase);
2409 } else if( c->op == LDAP_MOD_DELETE ) {
2410 ch_free( default_search_base.bv_val );
2411 ch_free( default_search_nbase.bv_val );
2412 BER_BVZERO( &default_search_base );
2413 BER_BVZERO( &default_search_nbase );
2417 if(c->bi || c->be != frontendDB) {
2418 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
2419 "prior to any backend or database definition\n",
2424 if(default_search_nbase.bv_len) {
2425 free(default_search_base.bv_val);
2426 free(default_search_nbase.bv_val);
2429 default_search_base = c->value_dn;
2430 default_search_nbase = c->value_ndn;
2434 /* For RE23 compatibility we allow this in the global entry
2435 * but we now defer it to the frontend entry to allow modules
2436 * to load new hash types.
2439 config_passwd_hash(ConfigArgs *c) {
2441 if (c->op == SLAP_CONFIG_EMIT) {
2443 /* Don't generate it in the global entry */
2444 if ( c->table == Cft_Global )
2446 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
2447 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
2448 value_add_one(&c->rvalue_vals, &bv);
2451 } else if ( c->op == LDAP_MOD_DELETE ) {
2452 /* Deleting from global is a no-op, only the frontendDB entry matters */
2453 if ( c->table == Cft_Global )
2455 if ( c->valx < 0 ) {
2456 ldap_charray_free( default_passwd_hash );
2457 default_passwd_hash = NULL;
2460 ch_free( default_passwd_hash[i] );
2461 for (; default_passwd_hash[i]; i++ )
2462 default_passwd_hash[i] = default_passwd_hash[i+1];
2466 for(i = 1; i < c->argc; i++) {
2467 if(!lutil_passwd_scheme(c->argv[i])) {
2468 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> scheme not available", c->argv[0] );
2469 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2470 c->log, c->cr_msg, c->argv[i]);
2472 ldap_charray_add(&default_passwd_hash, c->argv[i]);
2475 if(!default_passwd_hash) {
2476 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> no valid hashes found", c->argv[0] );
2477 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2478 c->log, c->cr_msg, 0 );
2485 config_schema_dn(ConfigArgs *c) {
2486 if ( c->op == SLAP_CONFIG_EMIT ) {
2488 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
2489 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
2490 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
2494 } else if ( c->op == LDAP_MOD_DELETE ) {
2495 ch_free( c->be->be_schemadn.bv_val );
2496 ch_free( c->be->be_schemandn.bv_val );
2497 BER_BVZERO( &c->be->be_schemadn );
2498 BER_BVZERO( &c->be->be_schemandn );
2501 ch_free( c->be->be_schemadn.bv_val );
2502 ch_free( c->be->be_schemandn.bv_val );
2503 c->be->be_schemadn = c->value_dn;
2504 c->be->be_schemandn = c->value_ndn;
2509 config_sizelimit(ConfigArgs *c) {
2511 struct slap_limits_set *lim = &c->be->be_def_limit;
2512 if (c->op == SLAP_CONFIG_EMIT) {
2517 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
2518 if ( !BER_BVISEMPTY( &bv ))
2519 value_add_one( &c->rvalue_vals, &bv );
2523 } else if ( c->op == LDAP_MOD_DELETE ) {
2524 /* Reset to defaults or values from frontend */
2525 if ( c->be == frontendDB ) {
2526 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
2527 lim->lms_s_hard = 0;
2528 lim->lms_s_unchecked = -1;
2530 lim->lms_s_pr_hide = 0;
2531 lim->lms_s_pr_total = 0;
2533 lim->lms_s_soft = frontendDB->be_def_limit.lms_s_soft;
2534 lim->lms_s_hard = frontendDB->be_def_limit.lms_s_hard;
2535 lim->lms_s_unchecked = frontendDB->be_def_limit.lms_s_unchecked;
2536 lim->lms_s_pr = frontendDB->be_def_limit.lms_s_pr;
2537 lim->lms_s_pr_hide = frontendDB->be_def_limit.lms_s_pr_hide;
2538 lim->lms_s_pr_total = frontendDB->be_def_limit.lms_s_pr_total;
2542 for(i = 1; i < c->argc; i++) {
2543 if(!strncasecmp(c->argv[i], "size", 4)) {
2544 rc = limits_parse_one(c->argv[i], lim);
2546 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2547 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2548 c->log, c->cr_msg, c->argv[i]);
2552 if(!strcasecmp(c->argv[i], "unlimited")) {
2553 lim->lms_s_soft = -1;
2555 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
2556 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2557 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2558 c->log, c->cr_msg, c->argv[i]);
2562 lim->lms_s_hard = 0;
2567 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2568 /* This is a modification to the global limits apply it to
2569 * the other databases as needed */
2570 AttributeDescription *ad=NULL;
2571 const char *text = NULL;
2572 CfEntryInfo *ce = c->ca_entry->e_private;
2574 slap_str2ad(c->argv[0], &ad, &text);
2575 /* if we got here... */
2576 assert( ad != NULL );
2578 if ( ce->ce_type == Cft_Global ){
2581 for (; ce; ce=ce->ce_sibs) {
2582 Entry *dbe = ce->ce_entry;
2583 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2584 && (!attr_find(dbe->e_attrs, ad)) ) {
2585 ce->ce_be->be_def_limit.lms_s_soft = lim->lms_s_soft;
2586 ce->ce_be->be_def_limit.lms_s_hard = lim->lms_s_hard;
2587 ce->ce_be->be_def_limit.lms_s_unchecked =lim->lms_s_unchecked;
2588 ce->ce_be->be_def_limit.lms_s_pr =lim->lms_s_pr;
2589 ce->ce_be->be_def_limit.lms_s_pr_hide =lim->lms_s_pr_hide;
2590 ce->ce_be->be_def_limit.lms_s_pr_total =lim->lms_s_pr_total;
2598 config_timelimit(ConfigArgs *c) {
2600 struct slap_limits_set *lim = &c->be->be_def_limit;
2601 if (c->op == SLAP_CONFIG_EMIT) {
2606 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
2607 if ( !BER_BVISEMPTY( &bv ))
2608 value_add_one( &c->rvalue_vals, &bv );
2612 } else if ( c->op == LDAP_MOD_DELETE ) {
2613 /* Reset to defaults or values from frontend */
2614 if ( c->be == frontendDB ) {
2615 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
2616 lim->lms_t_hard = 0;
2618 lim->lms_t_soft = frontendDB->be_def_limit.lms_t_soft;
2619 lim->lms_t_hard = frontendDB->be_def_limit.lms_t_hard;
2623 for(i = 1; i < c->argc; i++) {
2624 if(!strncasecmp(c->argv[i], "time", 4)) {
2625 rc = limits_parse_one(c->argv[i], lim);
2627 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2628 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2629 c->log, c->cr_msg, c->argv[i]);
2633 if(!strcasecmp(c->argv[i], "unlimited")) {
2634 lim->lms_t_soft = -1;
2636 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
2637 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2638 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2639 c->log, c->cr_msg, c->argv[i]);
2643 lim->lms_t_hard = 0;
2648 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2649 /* This is a modification to the global limits apply it to
2650 * the other databases as needed */
2651 AttributeDescription *ad=NULL;
2652 const char *text = NULL;
2653 CfEntryInfo *ce = c->ca_entry->e_private;
2655 slap_str2ad(c->argv[0], &ad, &text);
2656 /* if we got here... */
2657 assert( ad != NULL );
2659 if ( ce->ce_type == Cft_Global ){
2662 for (; ce; ce=ce->ce_sibs) {
2663 Entry *dbe = ce->ce_entry;
2664 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2665 && (!attr_find(dbe->e_attrs, ad)) ) {
2666 ce->ce_be->be_def_limit.lms_t_soft = lim->lms_t_soft;
2667 ce->ce_be->be_def_limit.lms_t_hard = lim->lms_t_hard;
2675 config_overlay(ConfigArgs *c) {
2676 if (c->op == SLAP_CONFIG_EMIT) {
2678 } else if ( c->op == LDAP_MOD_DELETE ) {
2681 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2682 c->valx, &c->bi, &c->reply)) {
2684 Debug( LDAP_DEBUG_ANY,
2685 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2686 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2688 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi, &c->reply)) {
2695 config_subordinate(ConfigArgs *c)
2701 case SLAP_CONFIG_EMIT:
2702 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2705 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2706 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2709 value_add_one( &c->rvalue_vals, &bv );
2713 case LDAP_MOD_DELETE:
2714 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2715 glue_sub_del( c->be );
2717 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2722 case SLAP_CONFIG_ADD:
2723 if ( c->be->be_nsuffix == NULL ) {
2725 snprintf( c->cr_msg, sizeof( c->cr_msg),
2726 "subordinate configuration needs a suffix" );
2727 Debug( LDAP_DEBUG_ANY,
2729 c->log, c->cr_msg, 0 );
2734 if ( c->argc == 2 ) {
2735 if ( strcasecmp( c->argv[1], "advertise" ) == 0 ) {
2738 } else if ( strcasecmp( c->argv[1], "TRUE" ) != 0 ) {
2740 snprintf( c->cr_msg, sizeof( c->cr_msg),
2741 "subordinate must be \"TRUE\" or \"advertise\"" );
2742 Debug( LDAP_DEBUG_ANY,
2743 "%s: suffix \"%s\": %s.\n",
2744 c->log, c->be->be_suffix[0].bv_val, c->cr_msg );
2750 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2758 * [listener=<listener>] [{read|write}=]<size>
2761 #ifdef LDAP_TCP_BUFFER
2762 static BerVarray tcp_buffer;
2765 #define SLAP_TCP_RMEM (0x1U)
2766 #define SLAP_TCP_WMEM (0x2U)
2769 tcp_buffer_parse( struct berval *val, int argc, char **argv,
2770 int *size, int *rw, Listener **l )
2772 int i, rc = LDAP_SUCCESS;
2773 LDAPURLDesc *lud = NULL;
2776 if ( val != NULL && argv == NULL ) {
2777 char *s = val->bv_val;
2779 argv = ldap_str2charray( s, " \t" );
2780 if ( argv == NULL ) {
2786 if ( strncasecmp( argv[ i ], "listener=", STRLENOF( "listener=" ) )
2789 char *url = argv[ i ] + STRLENOF( "listener=" );
2791 if ( ldap_url_parse( url, &lud ) ) {
2792 rc = LDAP_INVALID_SYNTAX;
2796 *l = config_check_my_url( url, lud );
2798 rc = LDAP_NO_SUCH_ATTRIBUTE;
2806 if ( strncasecmp( ptr, "read=", STRLENOF( "read=" ) ) == 0 ) {
2807 *rw |= SLAP_TCP_RMEM;
2808 ptr += STRLENOF( "read=" );
2810 } else if ( strncasecmp( ptr, "write=", STRLENOF( "write=" ) ) == 0 ) {
2811 *rw |= SLAP_TCP_WMEM;
2812 ptr += STRLENOF( "write=" );
2815 *rw |= ( SLAP_TCP_RMEM | SLAP_TCP_WMEM );
2818 /* accept any base */
2819 if ( lutil_atoix( size, ptr, 0 ) ) {
2820 rc = LDAP_INVALID_SYNTAX;
2825 if ( val != NULL && argv != NULL ) {
2826 ldap_charray_free( argv );
2829 if ( lud != NULL ) {
2830 ldap_free_urldesc( lud );
2837 tcp_buffer_delete_one( struct berval *val )
2840 int size = -1, rw = 0;
2843 rc = tcp_buffer_parse( val, 0, NULL, &size, &rw, &l );
2850 Listener **ll = slapd_get_listeners();
2852 for ( i = 0; ll[ i ] != NULL; i++ ) {
2853 if ( ll[ i ] == l ) break;
2856 if ( ll[ i ] == NULL ) {
2857 return LDAP_NO_SUCH_ATTRIBUTE;
2860 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = -1;
2861 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = -1;
2863 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2864 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = -1;
2865 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = -1;
2869 /* NOTE: this affects listeners without a specific setting,
2870 * does not reset all listeners. If a listener without
2871 * specific settings was assigned a buffer because of
2872 * a global setting, it will not be reset. In any case,
2873 * buffer changes will only take place at restart. */
2874 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = -1;
2875 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = -1;
2882 tcp_buffer_delete( BerVarray vals )
2886 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
2887 tcp_buffer_delete_one( &vals[ i ] );
2894 tcp_buffer_unparse( int size, int rw, Listener *l, struct berval *val )
2896 char buf[sizeof("2147483648")], *ptr;
2898 /* unparse for later use */
2899 val->bv_len = snprintf( buf, sizeof( buf ), "%d", size );
2901 val->bv_len += STRLENOF( "listener=" " " ) + l->sl_url.bv_len;
2904 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2905 if ( rw & SLAP_TCP_RMEM ) {
2906 val->bv_len += STRLENOF( "read=" );
2907 } else if ( rw & SLAP_TCP_WMEM ) {
2908 val->bv_len += STRLENOF( "write=" );
2912 val->bv_val = SLAP_MALLOC( val->bv_len + 1 );
2917 ptr = lutil_strcopy( ptr, "listener=" );
2918 ptr = lutil_strncopy( ptr, l->sl_url.bv_val, l->sl_url.bv_len );
2922 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2923 if ( rw & SLAP_TCP_RMEM ) {
2924 ptr = lutil_strcopy( ptr, "read=" );
2925 } else if ( rw & SLAP_TCP_WMEM ) {
2926 ptr = lutil_strcopy( ptr, "write=" );
2930 ptr = lutil_strcopy( ptr, buf );
2933 assert( val->bv_val + val->bv_len == ptr );
2935 return LDAP_SUCCESS;
2939 tcp_buffer_add_one( int argc, char **argv )
2942 int size = -1, rw = 0;
2948 rc = tcp_buffer_parse( NULL, argc, argv, &size, &rw, &l );
2953 /* unparse for later use */
2954 rc = tcp_buffer_unparse( size, rw, l, &val );
2955 if ( rc != LDAP_SUCCESS ) {
2959 /* use parsed values */
2962 Listener **ll = slapd_get_listeners();
2964 for ( i = 0; ll[ i ] != NULL; i++ ) {
2965 if ( ll[ i ] == l ) break;
2968 if ( ll[ i ] == NULL ) {
2969 return LDAP_NO_SUCH_ATTRIBUTE;
2972 /* buffer only applies to TCP listeners;
2973 * we do not do any check here, and delegate them
2974 * to setsockopt(2) */
2975 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = size;
2976 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = size;
2978 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2979 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = size;
2980 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = size;
2984 /* NOTE: this affects listeners without a specific setting,
2985 * does not set all listeners */
2986 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = size;
2987 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = size;
2990 tcp_buffer = SLAP_REALLOC( tcp_buffer, sizeof( struct berval ) * ( tcp_buffer_num + 2 ) );
2992 tcp_buffer[ tcp_buffer_num ] = val;
2995 BER_BVZERO( &tcp_buffer[ tcp_buffer_num ] );
3001 config_tcp_buffer( ConfigArgs *c )
3003 if ( c->op == SLAP_CONFIG_EMIT ) {
3004 if ( tcp_buffer == NULL || BER_BVISNULL( &tcp_buffer[ 0 ] ) ) {
3007 value_add( &c->rvalue_vals, tcp_buffer );
3008 value_add( &c->rvalue_nvals, tcp_buffer );
3010 } else if ( c->op == LDAP_MOD_DELETE ) {
3012 tcp_buffer_delete( tcp_buffer );
3013 ber_bvarray_free( tcp_buffer );
3019 int size = -1, rw = 0;
3022 struct berval val = BER_BVNULL;
3026 if ( tcp_buffer_num == 0 ) {
3031 rc = tcp_buffer_parse( NULL, c->argc - 1, &c->argv[ 1 ], &size, &rw, &l );
3036 /* unparse for later use */
3037 rc = tcp_buffer_unparse( size, rw, l, &val );
3038 if ( rc != LDAP_SUCCESS ) {
3042 for ( i = 0; !BER_BVISNULL( &tcp_buffer[ i ] ); i++ ) {
3043 if ( bvmatch( &tcp_buffer[ i ], &val ) ) {
3048 if ( BER_BVISNULL( &tcp_buffer[ i ] ) ) {
3054 tcp_buffer_delete_one( &tcp_buffer[ i ] );
3055 ber_memfree( tcp_buffer[ i ].bv_val );
3056 for ( ; i < tcp_buffer_num; i++ ) {
3057 tcp_buffer[ i ] = tcp_buffer[ i + 1 ];
3062 if ( !BER_BVISNULL( &val ) ) {
3063 SLAP_FREE( val.bv_val );
3071 rc = tcp_buffer_add_one( c->argc - 1, &c->argv[ 1 ] );
3073 snprintf( c->cr_msg, sizeof( c->cr_msg ),
3074 "<%s> unable to add value #%d",
3075 c->argv[0], tcp_buffer_num );
3076 Debug( LDAP_DEBUG_ANY, "%s: %s\n",
3077 c->log, c->cr_msg, 0 );
3084 #endif /* LDAP_TCP_BUFFER */
3087 config_suffix(ConfigArgs *c)
3090 struct berval pdn, ndn;
3091 char *notallowed = NULL;
3093 if ( c->be == frontendDB ) {
3094 notallowed = "frontend";
3096 } else if ( SLAP_MONITOR(c->be) ) {
3097 notallowed = "monitor";
3099 } else if ( SLAP_CONFIG(c->be) ) {
3100 notallowed = "config";
3103 if ( notallowed != NULL ) {
3104 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
3108 case LDAP_MOD_DELETE:
3109 case LDAP_MOD_REPLACE:
3110 case LDAP_MOD_INCREMENT:
3111 case SLAP_CONFIG_ADD:
3112 if ( !BER_BVISNULL( &c->value_dn ) ) {
3113 snprintf( buf, sizeof( buf ), "<%s> ",
3114 c->value_dn.bv_val );
3117 Debug(LDAP_DEBUG_ANY,
3118 "%s: suffix %snot allowed in %s database.\n",
3119 c->log, buf, notallowed );
3122 case SLAP_CONFIG_EMIT:
3123 /* don't complain when emitting... */
3127 /* FIXME: don't know what values may be valid;
3128 * please remove assertion, or add legal values
3129 * to either block */
3137 if (c->op == SLAP_CONFIG_EMIT) {
3138 if ( c->be->be_suffix == NULL
3139 || BER_BVISNULL( &c->be->be_suffix[0] ) )
3143 value_add( &c->rvalue_vals, c->be->be_suffix );
3144 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
3147 } else if ( c->op == LDAP_MOD_DELETE ) {
3148 if ( c->valx < 0 ) {
3149 ber_bvarray_free( c->be->be_suffix );
3150 ber_bvarray_free( c->be->be_nsuffix );
3151 c->be->be_suffix = NULL;
3152 c->be->be_nsuffix = NULL;
3155 ch_free( c->be->be_suffix[i].bv_val );
3156 ch_free( c->be->be_nsuffix[i].bv_val );
3158 c->be->be_suffix[i] = c->be->be_suffix[i+1];
3159 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
3161 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
3166 #ifdef SLAPD_MONITOR_DN
3167 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
3168 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> DN is reserved for monitoring slapd",
3170 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3171 c->log, c->cr_msg, SLAPD_MONITOR_DN);
3176 if (SLAP_DB_ONE_SUFFIX( c->be ) && c->be->be_suffix &&
3177 !BER_BVISNULL( &c->be->be_suffix[0] )) {
3178 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> Only one suffix is allowed on this %s backend",
3179 c->argv[0], c->be->bd_info->bi_type );
3180 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3181 c->log, c->cr_msg, 0);
3188 if (SLAP_DBHIDDEN( c->be ))
3191 tbe = select_backend(&ndn, 0);
3193 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
3199 BackendDB *b2 = tbe;
3201 /* Does tbe precede be? */
3202 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
3205 char *type = tbe->bd_info->bi_type;
3207 if ( overlay_is_over( tbe ) ) {
3208 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
3209 type = oi->oi_orig->bi_type;
3212 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> namingContext \"%s\" "
3213 "already served by a preceding %s database",
3214 c->argv[0], pdn.bv_val, type );
3215 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
3216 c->log, c->cr_msg, tbe->be_suffix[0].bv_val);
3222 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
3223 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
3224 "base provided \"%s\" (assuming okay)\n",
3225 c->log, default_search_base.bv_val, 0);
3227 ber_bvarray_add(&c->be->be_suffix, &pdn);
3228 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
3233 config_rootdn(ConfigArgs *c) {
3234 if (c->op == SLAP_CONFIG_EMIT) {
3235 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
3236 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
3237 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
3242 } else if ( c->op == LDAP_MOD_DELETE ) {
3243 ch_free( c->be->be_rootdn.bv_val );
3244 ch_free( c->be->be_rootndn.bv_val );
3245 BER_BVZERO( &c->be->be_rootdn );
3246 BER_BVZERO( &c->be->be_rootndn );
3249 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
3250 ch_free( c->be->be_rootdn.bv_val );
3251 ch_free( c->be->be_rootndn.bv_val );
3253 c->be->be_rootdn = c->value_dn;
3254 c->be->be_rootndn = c->value_ndn;
3259 config_rootpw(ConfigArgs *c) {
3262 if (c->op == SLAP_CONFIG_EMIT) {
3263 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
3264 /* don't copy, because "rootpw" is marked
3266 c->value_bv = c->be->be_rootpw;
3270 } else if ( c->op == LDAP_MOD_DELETE ) {
3271 ch_free( c->be->be_rootpw.bv_val );
3272 BER_BVZERO( &c->be->be_rootpw );
3276 tbe = select_backend(&c->be->be_rootndn, 0);
3278 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> can only be set when rootdn is under suffix",
3280 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3281 c->log, c->cr_msg, 0);
3284 if ( !BER_BVISNULL( &c->be->be_rootpw ))
3285 ch_free( c->be->be_rootpw.bv_val );
3286 c->be->be_rootpw = c->value_bv;
3291 config_restrict(ConfigArgs *c) {
3292 slap_mask_t restrictops = 0;
3294 slap_verbmasks restrictable_ops[] = {
3295 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
3296 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
3297 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
3298 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
3299 { BER_BVC("modrdn"), 0 },
3300 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
3301 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
3302 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
3303 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
3304 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
3305 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
3306 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
3307 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
3308 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
3309 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
3310 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
3314 if (c->op == SLAP_CONFIG_EMIT) {
3315 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
3317 } else if ( c->op == LDAP_MOD_DELETE ) {
3319 c->be->be_restrictops = 0;
3321 i = verb_to_mask( c->line, restrictable_ops );
3322 c->be->be_restrictops &= ~restrictable_ops[i].mask;
3326 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
3328 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown operation", c->argv[0] );
3329 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3330 c->log, c->cr_msg, c->argv[i]);
3333 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
3334 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
3335 c->be->be_restrictops |= restrictops;
3340 config_allows(ConfigArgs *c) {
3341 slap_mask_t allows = 0;
3343 slap_verbmasks allowable_ops[] = {
3344 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
3345 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
3346 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
3347 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
3348 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
3351 if (c->op == SLAP_CONFIG_EMIT) {
3352 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
3353 } else if ( c->op == LDAP_MOD_DELETE ) {
3357 i = verb_to_mask( c->line, allowable_ops );
3358 global_allows &= ~allowable_ops[i].mask;
3362 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
3364 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3365 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3366 c->log, c->cr_msg, c->argv[i]);
3369 global_allows |= allows;
3374 config_disallows(ConfigArgs *c) {
3375 slap_mask_t disallows = 0;
3377 slap_verbmasks disallowable_ops[] = {
3378 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
3379 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
3380 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
3381 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
3382 { BER_BVC("proxy_authz_non_critical"), SLAP_DISALLOW_PROXY_AUTHZ_N_CRIT },
3383 { BER_BVC("dontusecopy_non_critical"), SLAP_DISALLOW_DONTUSECOPY_N_CRIT },
3386 if (c->op == SLAP_CONFIG_EMIT) {
3387 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
3388 } else if ( c->op == LDAP_MOD_DELETE ) {
3390 global_disallows = 0;
3392 i = verb_to_mask( c->line, disallowable_ops );
3393 global_disallows &= ~disallowable_ops[i].mask;
3397 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
3399 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3400 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3401 c->log, c->cr_msg, c->argv[i]);
3404 global_disallows |= disallows;
3409 config_requires(ConfigArgs *c) {
3410 slap_mask_t requires = frontendDB->be_requires;
3411 int i, argc = c->argc;
3412 char **argv = c->argv;
3414 slap_verbmasks requires_ops[] = {
3415 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
3416 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
3417 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
3418 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
3419 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
3422 if (c->op == SLAP_CONFIG_EMIT) {
3423 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
3424 } else if ( c->op == LDAP_MOD_DELETE ) {
3426 c->be->be_requires = 0;
3428 i = verb_to_mask( c->line, requires_ops );
3429 c->be->be_requires &= ~requires_ops[i].mask;
3433 /* "none" can only be first, to wipe out default/global values */
3434 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
3439 i = verbs_to_mask(argc, argv, requires_ops, &requires);
3441 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
3442 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
3443 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3444 c->log, c->cr_msg, 0);
3446 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
3447 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3448 c->log, c->cr_msg, c->argv[i]);
3452 c->be->be_requires = requires;
3457 config_extra_attrs(ConfigArgs *c)
3459 assert( c->be != NULL );
3461 if ( c->op == SLAP_CONFIG_EMIT ) {
3464 if ( c->be->be_extra_anlist == NULL ) {
3468 for ( i = 0; !BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ); i++ ) {
3469 value_add_one( &c->rvalue_vals, &c->be->be_extra_anlist[i].an_name );
3472 } else if ( c->op == LDAP_MOD_DELETE ) {
3473 if ( c->be->be_extra_anlist == NULL ) {
3477 if ( c->valx < 0 ) {
3478 anlist_free( c->be->be_extra_anlist, 1, NULL );
3479 c->be->be_extra_anlist = NULL;
3484 for ( i = 0; i < c->valx && !BER_BVISNULL( &c->be->be_extra_anlist[i + 1].an_name ); i++ )
3487 if ( BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ) ) {
3491 ch_free( c->be->be_extra_anlist[i].an_name.bv_val );
3493 for ( ; !BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ); i++ ) {
3494 c->be->be_extra_anlist[i] = c->be->be_extra_anlist[i + 1];
3499 c->be->be_extra_anlist = str2anlist( c->be->be_extra_anlist, c->argv[1], " ,\t" );
3500 if ( c->be->be_extra_anlist == NULL ) {
3508 static slap_verbmasks *loglevel_ops;
3511 loglevel_init( void )
3513 slap_verbmasks lo[] = {
3514 { BER_BVC("Any"), (slap_mask_t) LDAP_DEBUG_ANY },
3515 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
3516 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
3517 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
3518 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
3519 { BER_BVC("BER"), LDAP_DEBUG_BER },
3520 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
3521 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
3522 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
3523 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
3524 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
3525 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
3526 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
3527 #if 0 /* no longer used (nor supported) */
3528 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
3529 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
3531 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
3532 { BER_BVC("None"), LDAP_DEBUG_NONE },
3536 return slap_verbmasks_init( &loglevel_ops, lo );
3540 loglevel_destroy( void )
3542 if ( loglevel_ops ) {
3543 (void)slap_verbmasks_destroy( loglevel_ops );
3545 loglevel_ops = NULL;
3548 static slap_mask_t loglevel_ignore[] = { -1, 0 };
3551 slap_loglevel_register( slap_mask_t m, struct berval *s )
3555 if ( loglevel_ops == NULL ) {
3559 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
3562 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
3570 slap_loglevel_get( struct berval *s, int *l )
3575 if ( loglevel_ops == NULL ) {
3579 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3580 m |= loglevel_ops[ i ].mask;
3583 for ( i = 1; m & i; i <<= 1 )
3590 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
3593 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
3604 str2loglevel( const char *s, int *l )
3608 if ( loglevel_ops == NULL ) {
3612 i = verb_to_mask( s, loglevel_ops );
3614 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
3618 *l = loglevel_ops[ i ].mask;
3624 loglevel2str( int l )
3626 struct berval bv = BER_BVNULL;
3628 loglevel2bv( l, &bv );
3634 loglevel2bv( int l, struct berval *bv )
3636 if ( loglevel_ops == NULL ) {
3642 return enum_to_verb( loglevel_ops, l, bv ) == -1;
3646 loglevel2bvarray( int l, BerVarray *bva )
3648 if ( loglevel_ops == NULL ) {
3653 return value_add_one( bva, ber_bvstr( "0" ) );
3656 return mask_to_verbs( loglevel_ops, l, bva );
3660 loglevel_print( FILE *out )
3664 if ( loglevel_ops == NULL ) {
3668 fprintf( out, "Installed log subsystems:\n\n" );
3669 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3670 unsigned mask = loglevel_ops[ i ].mask & 0xffffffffUL;
3672 (mask == ((slap_mask_t) -1 & 0xffffffffUL)
3673 ? "\t%-30s (-1, 0xffffffff)\n" : "\t%-30s (%u, 0x%x)\n"),
3674 loglevel_ops[ i ].word.bv_val, mask, mask );
3677 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
3678 "by specific code\n\n" );
3683 static int config_syslog;
3686 config_loglevel(ConfigArgs *c) {
3689 if ( loglevel_ops == NULL ) {
3693 if (c->op == SLAP_CONFIG_EMIT) {
3694 /* Get default or commandline slapd setting */
3695 if ( ldap_syslog && !config_syslog )
3696 config_syslog = ldap_syslog;
3697 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
3699 } else if ( c->op == LDAP_MOD_DELETE ) {
3703 i = verb_to_mask( c->line, loglevel_ops );
3704 config_syslog &= ~loglevel_ops[i].mask;
3706 if ( slapMode & SLAP_SERVER_MODE ) {
3707 ldap_syslog = config_syslog;
3712 for( i=1; i < c->argc; i++ ) {
3715 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
3716 if( lutil_atoix( &level, c->argv[i], 0 ) != 0 ) {
3717 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse level", c->argv[0] );
3718 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3719 c->log, c->cr_msg, c->argv[i]);
3723 if ( str2loglevel( c->argv[i], &level ) ) {
3724 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown level", c->argv[0] );
3725 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3726 c->log, c->cr_msg, c->argv[i]);
3730 /* Explicitly setting a zero clears all the levels */
3732 config_syslog |= level;
3736 if ( slapMode & SLAP_SERVER_MODE ) {
3737 ldap_syslog = config_syslog;
3743 config_referral(ConfigArgs *c) {
3745 if (c->op == SLAP_CONFIG_EMIT) {
3746 if ( default_referral ) {
3747 value_add( &c->rvalue_vals, default_referral );
3752 } else if ( c->op == LDAP_MOD_DELETE ) {
3753 if ( c->valx < 0 ) {
3754 ber_bvarray_free( default_referral );
3755 default_referral = NULL;
3758 ch_free( default_referral[i].bv_val );
3759 for (; default_referral[i].bv_val; i++ )
3760 default_referral[i] = default_referral[i+1];
3764 if(validate_global_referral(c->argv[1])) {
3765 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3766 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3767 c->log, c->cr_msg, c->argv[1]);
3771 ber_str2bv(c->argv[1], 0, 0, &val);
3772 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
3780 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
3781 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
3782 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
3783 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
3784 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
3785 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
3786 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
3787 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
3788 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
3793 config_security(ConfigArgs *c) {
3794 slap_ssf_set_t *set = &c->be->be_ssf_set;
3797 if (c->op == SLAP_CONFIG_EMIT) {
3803 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
3804 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
3807 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
3808 if ( bv.bv_len >= sizeof( numbuf ) ) {
3809 ber_bvarray_free_x( c->rvalue_vals, NULL );
3810 c->rvalue_vals = NULL;
3814 bv.bv_len += sec_keys[i].key.bv_len;
3815 bv.bv_val = ch_malloc( bv.bv_len + 1);
3816 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
3817 strcpy( next, numbuf );
3818 ber_bvarray_add( &c->rvalue_vals, &bv );
3823 for(i = 1; i < c->argc; i++) {
3824 slap_ssf_t *tgt = NULL;
3826 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
3827 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
3828 sec_keys[j].key.bv_len)) {
3829 src = c->argv[i] + sec_keys[j].key.bv_len;
3830 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
3835 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown factor", c->argv[0] );
3836 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3837 c->log, c->cr_msg, c->argv[i]);
3841 if ( lutil_atou( tgt, src ) != 0 ) {
3842 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse factor", c->argv[0] );
3843 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3844 c->log, c->cr_msg, c->argv[i]);
3852 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
3856 for (; !BER_BVISNULL( &an->an_name ); an++) {
3857 /* if buflen == 0, assume the buffer size has been
3858 * already checked otherwise */
3859 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
3860 if ( comma ) *ptr++ = ',';
3861 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
3868 config_updatedn(ConfigArgs *c) {
3869 if (c->op == SLAP_CONFIG_EMIT) {
3870 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
3871 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
3872 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
3876 } else if ( c->op == LDAP_MOD_DELETE ) {
3877 ch_free( c->be->be_update_ndn.bv_val );
3878 BER_BVZERO( &c->be->be_update_ndn );
3879 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
3882 if(SLAP_SHADOW(c->be)) {
3883 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database already shadowed", c->argv[0] );
3884 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3885 c->log, c->cr_msg, 0);
3889 ber_memfree_x( c->value_dn.bv_val, NULL );
3890 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
3891 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
3893 c->be->be_update_ndn = c->value_ndn;
3894 BER_BVZERO( &c->value_dn );
3895 BER_BVZERO( &c->value_ndn );
3897 return config_slurp_shadow( c );
3901 config_shadow( ConfigArgs *c, slap_mask_t flag )
3903 char *notallowed = NULL;
3905 if ( c->be == frontendDB ) {
3906 notallowed = "frontend";
3908 } else if ( SLAP_MONITOR(c->be) ) {
3909 notallowed = "monitor";
3912 if ( notallowed != NULL ) {
3913 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
3917 if ( SLAP_SHADOW(c->be) ) {
3918 /* if already shadow, only check consistency */
3919 if ( ( SLAP_DBFLAGS(c->be) & flag ) != flag ) {
3920 Debug( LDAP_DEBUG_ANY, "%s: inconsistent shadow flag 0x%lx.\n",
3926 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | flag);
3927 if ( !SLAP_MULTIMASTER( c->be ))
3928 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
3935 config_updateref(ConfigArgs *c) {
3937 if (c->op == SLAP_CONFIG_EMIT) {
3938 if ( c->be->be_update_refs ) {
3939 value_add( &c->rvalue_vals, c->be->be_update_refs );
3944 } else if ( c->op == LDAP_MOD_DELETE ) {
3945 if ( c->valx < 0 ) {
3946 ber_bvarray_free( c->be->be_update_refs );
3947 c->be->be_update_refs = NULL;
3950 ch_free( c->be->be_update_refs[i].bv_val );
3951 for (; c->be->be_update_refs[i].bv_val; i++)
3952 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
3956 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
3957 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must appear after syncrepl or updatedn",
3959 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3960 c->log, c->cr_msg, 0);
3964 if(validate_global_referral(c->argv[1])) {
3965 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3966 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3967 c->log, c->cr_msg, c->argv[1]);
3970 ber_str2bv(c->argv[1], 0, 0, &val);
3971 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
3976 config_obsolete(ConfigArgs *c) {
3977 if (c->op == SLAP_CONFIG_EMIT)
3980 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> keyword is obsolete (ignored)",
3982 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0);
3987 config_include(ConfigArgs *c) {
3988 int savelineno = c->lineno;
3991 ConfigFile *cfsave = cfn;
3992 ConfigFile *cf2 = NULL;
3994 /* Leftover from RE23. No dynamic config for include files */
3995 if ( c->op == SLAP_CONFIG_EMIT || c->op == LDAP_MOD_DELETE )
3998 cf = ch_calloc( 1, sizeof(ConfigFile));
3999 if ( cfn->c_kids ) {
4000 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
4006 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
4007 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
4008 c->lineno = savelineno - 1;
4011 if ( cf2 ) cf2->c_sibs = NULL;
4012 else cfn->c_kids = NULL;
4013 ch_free( cf->c_file.bv_val );
4023 config_tls_cleanup(ConfigArgs *c) {
4026 if ( slap_tls_ld ) {
4029 ldap_pvt_tls_ctx_free( slap_tls_ctx );
4030 slap_tls_ctx = NULL;
4032 /* Force new ctx to be created */
4033 rc = ldap_pvt_tls_set_option( slap_tls_ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
4035 /* The ctx's refcount is bumped up here */
4036 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CTX, &slap_tls_ctx );
4037 /* This is a no-op if it's already loaded */
4038 load_extop( &slap_EXOP_START_TLS, 0, starttls_extop );
4040 if ( rc == LDAP_NOT_SUPPORTED )
4041 rc = LDAP_UNWILLING_TO_PERFORM;
4050 config_tls_option(ConfigArgs *c) {
4052 LDAP *ld = slap_tls_ld;
4054 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
4055 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
4056 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
4057 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
4058 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
4059 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
4060 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
4062 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
4064 default: Debug(LDAP_DEBUG_ANY, "%s: "
4065 "unknown tls_option <0x%x>\n",
4066 c->log, c->type, 0);
4069 if (c->op == SLAP_CONFIG_EMIT) {
4070 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
4071 } else if ( c->op == LDAP_MOD_DELETE ) {
4072 c->cleanup = config_tls_cleanup;
4073 return ldap_pvt_tls_set_option( ld, flag, NULL );
4075 ch_free(c->value_string);
4076 c->cleanup = config_tls_cleanup;
4077 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
4080 /* FIXME: this ought to be provided by libldap */
4082 config_tls_config(ConfigArgs *c) {
4085 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
4086 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
4087 case CFG_TLS_PROTOCOL_MIN: flag = LDAP_OPT_X_TLS_PROTOCOL_MIN; break;
4089 Debug(LDAP_DEBUG_ANY, "%s: "
4090 "unknown tls_option <0x%x>\n",
4091 c->log, c->type, 0);
4094 if (c->op == SLAP_CONFIG_EMIT) {
4095 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
4096 } else if ( c->op == LDAP_MOD_DELETE ) {
4098 c->cleanup = config_tls_cleanup;
4099 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
4101 ch_free( c->value_string );
4102 c->cleanup = config_tls_cleanup;
4103 if ( isdigit( (unsigned char)c->argv[1][0] ) && c->type != CFG_TLS_PROTOCOL_MIN ) {
4104 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
4105 Debug(LDAP_DEBUG_ANY, "%s: "
4106 "unable to parse %s \"%s\"\n",
4107 c->log, c->argv[0], c->argv[1] );
4110 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
4112 return(ldap_pvt_tls_config(slap_tls_ld, flag, c->argv[1]));
4117 static CfEntryInfo *
4118 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
4128 if ( dn_match( &root->ce_entry->e_nname, dn ))
4131 c = dn->bv_val+dn->bv_len;
4132 for (;*c != ',';c--);
4136 for (--c;c>dn->bv_val && *c != ',';c--);
4140 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
4142 root = root->ce_kids;
4144 for (;root;root=root->ce_sibs) {
4145 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
4146 if ( cdn.bv_val == dn->bv_val ) {
4156 typedef struct setup_cookie {
4166 config_ldif_resp( Operation *op, SlapReply *rs )
4168 if ( rs->sr_type == REP_SEARCH ) {
4169 setup_cookie *sc = op->o_callback->sc_private;
4172 sc->cfb->cb_got_ldif = 1;
4173 /* Does the frontend exist? */
4174 if ( !sc->got_frontend ) {
4175 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
4176 "olcDatabase", STRLENOF( "olcDatabase" )))
4178 if ( strncmp( rs->sr_entry->e_nname.bv_val +
4179 STRLENOF( "olcDatabase" ), "={-1}frontend",
4180 STRLENOF( "={-1}frontend" )))
4184 sc->ca->be = frontendDB;
4185 sc->ca->bi = frontendDB->bd_info;
4186 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
4187 rdn.bv_val = sc->ca->log;
4188 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
4189 "%s=" SLAP_X_ORDERED_FMT "%s",
4190 cfAd_database->ad_cname.bv_val, -1,
4191 sc->ca->bi->bi_type);
4193 sc->frontend = config_build_entry( op, rs,
4194 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
4195 sc->ca->be->be_cf_ocs );
4205 dnParent( &rs->sr_entry->e_nname, &pdn );
4207 /* Does the configDB exist? */
4208 if ( sc->got_frontend && !sc->got_config &&
4209 !strncmp( rs->sr_entry->e_nname.bv_val,
4210 "olcDatabase", STRLENOF( "olcDatabase" )) &&
4211 dn_match( &config_rdn, &pdn ) )
4213 if ( strncmp( rs->sr_entry->e_nname.bv_val +
4214 STRLENOF( "olcDatabase" ), "={0}config",
4215 STRLENOF( "={0}config" )))
4219 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
4220 sc->ca->bi = sc->ca->be->bd_info;
4221 rdn.bv_val = sc->ca->log;
4222 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
4223 "%s=" SLAP_X_ORDERED_FMT "%s",
4224 cfAd_database->ad_cname.bv_val, 0,
4225 sc->ca->bi->bi_type);
4227 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
4228 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
4235 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
4236 if ( rs->sr_err != LDAP_SUCCESS ) {
4237 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
4238 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg, 0 );
4244 /* Configure and read the underlying back-ldif store */
4246 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
4247 CfBackInfo *cfb = be->be_private;
4253 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
4254 Connection conn = {0};
4255 OperationBuffer opbuf;
4257 SlapReply rs = {REP_RESULT};
4258 Filter filter = { LDAP_FILTER_PRESENT };
4259 struct berval filterstr = BER_BVC("(objectclass=*)");
4262 /* Is the config directory available? */
4263 if ( stat( dir, &st ) < 0 ) {
4264 /* No, so don't bother using the backing store.
4265 * All changes will be in-memory only.
4270 cfb->cb_db.bd_info = backend_info( "ldif" );
4271 if ( !cfb->cb_db.bd_info )
4272 return 0; /* FIXME: eventually this will be a fatal error */
4274 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
4277 cfb->cb_db.be_suffix = be->be_suffix;
4278 cfb->cb_db.be_nsuffix = be->be_nsuffix;
4280 /* The suffix is always "cn=config". The underlying DB's rootdn
4281 * is always the same as the suffix.
4283 cfb->cb_db.be_rootdn = be->be_suffix[0];
4284 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
4286 ber_str2bv( dir, 0, 1, &cfdir );
4291 argv[0] = "directory";
4292 argv[1] = (char *)dir;
4297 c.table = Cft_Database;
4299 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
4303 if ( config_add_vals( ct, &c ))
4306 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
4310 void *thrctx = ldap_pvt_thread_pool_context();
4313 connection_fake_init( &conn, &opbuf, thrctx );
4316 filter.f_desc = slap_schema.si_ad_objectClass;
4318 op->o_tag = LDAP_REQ_SEARCH;
4320 op->ors_filter = &filter;
4321 op->ors_filterstr = filterstr;
4322 op->ors_scope = LDAP_SCOPE_SUBTREE;
4324 op->o_dn = c.be->be_rootdn;
4325 op->o_ndn = c.be->be_rootndn;
4327 op->o_req_dn = be->be_suffix[0];
4328 op->o_req_ndn = be->be_nsuffix[0];
4330 op->ors_tlimit = SLAP_NO_LIMIT;
4331 op->ors_slimit = SLAP_NO_LIMIT;
4333 op->ors_attrs = slap_anlist_all_attributes;
4334 op->ors_attrsonly = 0;
4336 op->o_callback = &cb;
4339 cb.sc_private = ≻
4340 sc.got_frontend = 0;
4345 op->o_bd = &cfb->cb_db;
4347 /* Allow unknown attrs in DNs */
4348 prev_DN_strict = slap_DN_strict;
4351 rc = op->o_bd->be_search( op, &rs );
4353 /* Restore normal DN validation */
4354 slap_DN_strict = prev_DN_strict;
4356 op->o_tag = LDAP_REQ_ADD;
4357 if ( rc == LDAP_SUCCESS && sc.frontend ) {
4358 rs_reinit( &rs, REP_RESULT );
4359 op->ora_e = sc.frontend;
4360 rc = op->o_bd->be_add( op, &rs );
4362 if ( rc == LDAP_SUCCESS && sc.config ) {
4363 rs_reinit( &rs, REP_RESULT );
4364 op->ora_e = sc.config;
4365 rc = op->o_bd->be_add( op, &rs );
4367 ldap_pvt_thread_pool_context_reset( thrctx );
4370 /* ITS#4194 - only use if it's present, or we're converting. */
4371 if ( !readit || rc == LDAP_SUCCESS )
4372 cfb->cb_use_ldif = 1;
4378 CfOc_cmp( const void *c1, const void *c2 ) {
4379 const ConfigOCs *co1 = c1;
4380 const ConfigOCs *co2 = c2;
4382 return ber_bvcmp( co1->co_name, co2->co_name );
4386 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
4389 i = init_config_attrs( ct );
4392 /* set up the objectclasses */
4393 i = init_config_ocs( ocs );
4396 for (i=0; ocs[i].co_def; i++) {
4397 if ( ocs[i].co_oc ) {
4398 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
4399 if ( !ocs[i].co_table )
4400 ocs[i].co_table = ct;
4401 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
4408 read_config(const char *fname, const char *dir) {
4411 const char *cfdir, *cfname;
4414 /* Setup the config backend */
4415 be = backend_db_init( "config", NULL, 0, NULL );
4419 cfb = be->be_private;
4420 be->be_dfltaccess = ACL_NONE;
4422 /* If no .conf, or a dir was specified, setup the dir */
4423 if ( !fname || dir ) {
4425 /* If explicitly given, check for existence */
4428 if ( stat( dir, &st ) < 0 ) {
4429 Debug( LDAP_DEBUG_ANY,
4430 "invalid config directory %s, error %d\n",
4436 cfdir = SLAPD_DEFAULT_CONFIGDIR;
4438 /* if fname is defaulted, try reading .d */
4439 rc = config_setup_ldif( be, cfdir, !fname );
4442 /* It may be OK if the base object doesn't exist yet. */
4443 if ( rc != LDAP_NO_SUCH_OBJECT )
4445 /* ITS#4194: But if dir was specified and no fname,
4446 * then we were supposed to read the dir. Unless we're
4447 * trying to slapadd the dir...
4449 if ( dir && !fname ) {
4450 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
4452 /* Assume it's slapadd with a config dir, let it continue */
4454 cfb->cb_got_ldif = 1;
4455 cfb->cb_use_ldif = 1;
4460 /* If we read the config from back-ldif, nothing to do here */
4461 if ( cfb->cb_got_ldif ) {
4470 cfname = SLAPD_DEFAULT_CONFIGFILE;
4472 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
4475 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
4478 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
4479 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
4480 &frontendDB->be_schemadn );
4481 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
4482 if ( rc != LDAP_SUCCESS ) {
4483 Debug(LDAP_DEBUG_ANY, "read_config: "
4484 "unable to normalize default schema DN \"%s\"\n",
4485 frontendDB->be_schemadn.bv_val, 0, 0 );
4486 /* must not happen */
4490 if ( rc == 0 && ( slapMode & SLAP_SERVER_MODE ) && sid_list ) {
4491 if ( !BER_BVISEMPTY( &sid_list->si_url ) && !sid_set ) {
4492 Debug(LDAP_DEBUG_ANY, "read_config: no serverID / URL match found. "
4493 "Check slapd -h arguments.\n", 0,0,0 );
4501 config_back_bind( Operation *op, SlapReply *rs )
4503 if ( be_isroot_pw( op ) ) {
4504 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
4505 /* frontend sends result */
4506 return LDAP_SUCCESS;
4509 rs->sr_err = LDAP_INVALID_CREDENTIALS;
4510 send_ldap_result( op, rs );
4516 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
4520 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
4522 rs->sr_attrs = op->ors_attrs;
4523 rs->sr_entry = ce->ce_entry;
4525 rc = send_search_entry( op, rs );
4526 if ( rc != LDAP_SUCCESS ) {
4530 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
4531 if ( ce->ce_kids ) {
4532 rc = config_send( op, rs, ce->ce_kids, 1 );
4533 if ( rc ) return rc;
4536 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
4537 rc = config_send( op, rs, ce, 0 );
4545 static ConfigTable *
4546 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
4551 for (j=0; j<nocs; j++) {
4552 for (i=0; colst[j]->co_table[i].name; i++)
4553 if ( colst[j]->co_table[i].ad == ad ) {
4554 ca->table = colst[j]->co_type;
4555 return &colst[j]->co_table[i];
4561 /* Sort the attributes of the entry according to the order defined
4562 * in the objectclass, with required attributes occurring before
4563 * allowed attributes. For any attributes with sequencing dependencies
4564 * (e.g., rootDN must be defined after suffix) the objectclass must
4565 * list the attributes in the desired sequence.
4568 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
4570 Attribute *a, *head = NULL, *tail = NULL, **prev;
4573 for (i=0; i<nocs; i++) {
4574 if ( colst[i]->co_oc->soc_required ) {
4575 AttributeType **at = colst[i]->co_oc->soc_required;
4576 for (j=0; at[j]; j++) {
4577 for (a=e->e_attrs, prev=&e->e_attrs; a;
4578 prev = &(*prev)->a_next, a=a->a_next) {
4579 if ( a->a_desc == at[j]->sat_ad ) {
4593 if ( colst[i]->co_oc->soc_allowed ) {
4594 AttributeType **at = colst[i]->co_oc->soc_allowed;
4595 for (j=0; at[j]; j++) {
4596 for (a=e->e_attrs, prev=&e->e_attrs; a;
4597 prev = &(*prev)->a_next, a=a->a_next) {
4598 if ( a->a_desc == at[j]->sat_ad ) {
4614 tail->a_next = e->e_attrs;
4620 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
4622 Attribute *a = NULL;
4623 AttributeDescription *ad;
4633 Modifications *ml = ptr;
4635 vals = ml->sml_values;
4638 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
4639 rc = ordered_value_sort( a, 1 );
4641 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
4642 ad->ad_cname.bv_val );
4646 for ( i=0; vals[i].bv_val; i++ ) {
4647 ca->line = vals[i].bv_val;
4648 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
4649 ca->line[0] == '{' ) {
4650 char *idx = strchr( ca->line, '}' );
4651 if ( idx ) ca->line = idx+1;
4653 rc = config_parse_vals( ct, ca, i );
4662 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
4665 struct berval rtype, rval;
4667 AttributeDescription *ad = NULL;
4669 dnRdn( &e->e_name, rdn );
4670 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
4671 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
4672 rtype.bv_val = rdn->bv_val;
4673 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
4676 slap_bv2ad( &rtype, &ad, &rs->sr_text );
4677 a = attr_find( e->e_attrs, ad );
4678 if (!a ) return LDAP_NAMING_VIOLATION;
4685 config_rename_kids( CfEntryInfo *ce )
4688 struct berval rdn, nrdn;
4690 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
4691 struct berval newdn, newndn;
4692 dnRdn ( &ce2->ce_entry->e_name, &rdn );
4693 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
4694 build_new_dn( &newdn, &ce->ce_entry->e_name, &rdn, NULL );
4695 build_new_dn( &newndn, &ce->ce_entry->e_nname, &nrdn, NULL );
4696 free( ce2->ce_entry->e_name.bv_val );
4697 free( ce2->ce_entry->e_nname.bv_val );
4698 ce2->ce_entry->e_name = newdn;
4699 ce2->ce_entry->e_nname = newndn;
4700 config_rename_kids( ce2 );
4705 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
4706 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
4707 struct berval *nnewrdn, int use_ldif )
4711 struct berval odn, ondn;
4715 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
4716 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
4719 free( a->a_vals[0].bv_val );
4720 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
4721 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
4722 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
4723 strcpy( a->a_vals[0].bv_val, ptr1 );
4725 if ( a->a_nvals != a->a_vals ) {
4726 free( a->a_nvals[0].bv_val );
4727 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
4728 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
4729 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
4730 strcpy( a->a_nvals[0].bv_val, ptr1 );
4733 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
4734 BackendDB *be = op->o_bd;
4735 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4736 struct berval dn, ndn, xdn, xndn;
4738 op->o_bd = &cfb->cb_db;
4740 /* Save current rootdn; use the underlying DB's rootdn */
4744 xndn = op->o_req_ndn;
4745 op->o_dn = op->o_bd->be_rootdn;
4746 op->o_ndn = op->o_bd->be_rootndn;
4748 op->o_req_ndn = ondn;
4750 scp = op->o_callback;
4751 op->o_callback = ≻
4752 op->orr_newrdn = *newrdn;
4753 op->orr_nnewrdn = *nnewrdn;
4754 op->orr_newSup = NULL;
4755 op->orr_nnewSup = NULL;
4756 op->orr_deleteoldrdn = 1;
4757 op->orr_modlist = NULL;
4758 slap_modrdn2mods( op, rs );
4759 slap_mods_opattrs( op, &op->orr_modlist, 1 );
4760 rc = op->o_bd->be_modrdn( op, rs );
4761 slap_mods_free( op->orr_modlist, 1 );
4764 op->o_callback = scp;
4768 op->o_req_ndn = xndn;
4771 free( ondn.bv_val );
4773 config_rename_kids( e->e_private );
4778 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
4779 Entry *e, int idx, int tailindex, int use_ldif )
4781 struct berval ival, newrdn, nnewrdn;
4784 char ibuf[32], *ptr1, *ptr2 = NULL;
4787 rc = config_rename_attr( rs, e, &rdn, &a );
4788 if ( rc ) return rc;
4791 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
4792 if ( ival.bv_len >= sizeof( ibuf ) ) {
4793 return LDAP_NAMING_VIOLATION;
4796 newrdn.bv_len = rdn.bv_len + ival.bv_len;
4797 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
4800 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
4801 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4804 ptr2 = ber_bvchr( &rdn, '}' );
4808 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
4810 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
4811 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
4812 a->a_desc->ad_cname.bv_len );
4814 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4815 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
4819 /* Do the equivalent of ModRDN */
4820 /* Replace DN / NDN */
4821 newrdn.bv_len = ptr1 - newrdn.bv_val;
4822 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
4823 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
4825 free( nnewrdn.bv_val );
4826 free( newrdn.bv_val );
4831 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
4832 SlapReply *rs, int *renum, int *ibase )
4835 int index = -1, gotindex = 0, nsibs, rc = 0;
4836 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
4837 char *ptr1, *ptr2 = NULL;
4840 if ( renum ) *renum = 0;
4842 /* These entries don't get indexed/renumbered */
4843 if ( ce_type == Cft_Global ) return 0;
4844 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
4846 if ( ce_type == Cft_Module )
4849 /* See if the rdn has an index already */
4850 dnRdn( &e->e_name, &rdn );
4851 if ( ce_type == Cft_Database ) {
4852 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
4853 "frontend", STRLENOF("frontend") ))
4855 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
4856 "config", STRLENOF("config") ))
4859 ptr1 = ber_bvchr( &e->e_name, '{' );
4860 if ( ptr1 && ptr1 < &e->e_name.bv_val[ rdn.bv_len ] ) {
4862 ptr2 = strchr( ptr1, '}' );
4863 if ( !ptr2 || ptr2 > &e->e_name.bv_val[ rdn.bv_len ] )
4864 return LDAP_NAMING_VIOLATION;
4865 if ( ptr2-ptr1 == 1)
4866 return LDAP_NAMING_VIOLATION;
4868 index = strtol( ptr1 + 1, &next, 10 );
4869 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
4870 return LDAP_NAMING_VIOLATION;
4873 /* Special case, we allow -1 for the frontendDB */
4874 if ( index != -1 || !isfrontend )
4875 return LDAP_NAMING_VIOLATION;
4877 if ( isconfig && index != 0 ){
4878 return LDAP_NAMING_VIOLATION;
4882 /* count related kids.
4883 * For entries of type Cft_Misc, only count siblings with same RDN type
4885 if ( ce_type == Cft_Misc ) {
4886 rdn.bv_val = e->e_nname.bv_val;
4887 ptr1 = strchr( rdn.bv_val, '=' );
4888 assert( ptr1 != NULL );
4890 rdn.bv_len = ptr1 - rdn.bv_val;
4892 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
4894 if ( ce->ce_type != ce_type )
4897 dnRdn( &ce->ce_entry->e_nname, &rdn2 );
4899 ptr1 = strchr( rdn2.bv_val, '=' );
4900 assert( ptr1 != NULL );
4902 rdn2.bv_len = ptr1 - rdn2.bv_val;
4903 if ( bvmatch( &rdn, &rdn2 ))
4907 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
4908 if ( ce->ce_type == ce_type ) nsibs++;
4912 /* account for -1 frontend */
4913 if ( ce_type == Cft_Database )
4916 if ( index != nsibs ) {
4918 if ( index < nsibs ) {
4919 if ( tailindex ) return LDAP_NAMING_VIOLATION;
4920 /* Siblings need to be renumbered */
4921 if ( index != -1 || !isfrontend )
4925 /* config DB is always "0" */
4926 if ( isconfig && index == -1 ) {
4929 if (( !isfrontend && index == -1 ) || ( index > nsibs ) ){
4933 /* just make index = nsibs */
4935 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
4938 if ( ibase ) *ibase = index;
4939 if ( renum ) *renum = renumber;
4943 /* Insert all superior classes of the given class */
4945 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
4950 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
4951 if ( count_oc( *sups, copp, nocs ) ) {
4956 co.co_name = &oc->soc_cname;
4957 cop = avl_find( CfOcTree, &co, CfOc_cmp );
4961 /* check for duplicates */
4962 for ( i = 0; i < *nocs; i++ ) {
4963 if ( *copp && (*copp)[i] == cop ) {
4969 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
4970 if ( tmp == NULL ) {
4974 (*copp)[*nocs] = cop;
4982 /* Find all superior classes of the given objectclasses,
4983 * return list in order of most-subordinate first.
4985 * Special / auxiliary / Cft_Misc classes always take precedence.
4988 count_ocs( Attribute *oc_at, int *nocs )
4990 int i, j, misc = -1;
4991 ConfigOCs **colst = NULL;
4995 for ( i = oc_at->a_numvals; i--; ) {
4996 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
4998 assert( oc != NULL );
4999 if ( count_oc( oc, &colst, nocs ) ) {
5009 ConfigOCs *tmp = colst[i];
5010 colst[i] = colst[j];
5012 if (tmp->co_type == Cft_Misc)
5016 /* Move misc class to front of list */
5018 ConfigOCs *tmp = colst[misc];
5019 for (i=misc; i>0; i--)
5020 colst[i] = colst[i-1];
5028 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
5030 /* Leftover from RE23. Never parse this entry */
5031 return LDAP_COMPARE_TRUE;
5035 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
5039 /* This entry is hardcoded, don't re-parse it */
5040 if ( p->ce_type == Cft_Global ) {
5041 cfn = p->ce_private;
5042 ca->ca_private = cfn;
5043 return LDAP_COMPARE_TRUE;
5045 if ( p->ce_type != Cft_Schema )
5046 return LDAP_CONSTRAINT_VIOLATION;
5048 cfn = ch_calloc( 1, sizeof(ConfigFile) );
5049 ca->ca_private = cfn;
5050 cfo = p->ce_private;
5051 cfn->c_sibs = cfo->c_kids;
5053 return LDAP_SUCCESS;
5057 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
5059 if ( p->ce_type != Cft_Global ) {
5060 return LDAP_CONSTRAINT_VIOLATION;
5062 /* config must be {0}, nothing else allowed */
5063 if ( !strncmp( e->e_nname.bv_val, "olcDatabase={0}", STRLENOF("olcDatabase={0}")) &&
5064 strncmp( e->e_nname.bv_val + STRLENOF("olcDatabase={0}"), "config,", STRLENOF("config,") )) {
5065 return LDAP_CONSTRAINT_VIOLATION;
5067 ca->be = frontendDB; /* just to get past check_vals */
5068 return LDAP_SUCCESS;
5072 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
5074 if ( p->ce_type != Cft_Global ) {
5075 return LDAP_CONSTRAINT_VIOLATION;
5077 return LDAP_SUCCESS;
5081 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
5083 if ( p->ce_type != Cft_Global ) {
5084 return LDAP_CONSTRAINT_VIOLATION;
5086 return LDAP_SUCCESS;
5090 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
5092 if ( p->ce_type != Cft_Database ) {
5093 return LDAP_CONSTRAINT_VIOLATION;
5096 return LDAP_SUCCESS;
5100 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
5105 AttributeDescription *ad;
5111 if ( cfn->c_cr_head ) {
5112 struct berval bv = BER_BVC("olcDitContentRules");
5114 slap_bv2ad( &bv, &ad, &text );
5115 ct = config_find_table( colst, nocs, ad, ca );
5116 config_del_vals( ct, ca );
5118 if ( cfn->c_oc_head ) {
5119 struct berval bv = BER_BVC("olcObjectClasses");
5121 slap_bv2ad( &bv, &ad, &text );
5122 ct = config_find_table( colst, nocs, ad, ca );
5123 config_del_vals( ct, ca );
5125 if ( cfn->c_at_head ) {
5126 struct berval bv = BER_BVC("olcAttributeTypes");
5128 slap_bv2ad( &bv, &ad, &text );
5129 ct = config_find_table( colst, nocs, ad, ca );
5130 config_del_vals( ct, ca );
5132 if ( cfn->c_syn_head ) {
5133 struct berval bv = BER_BVC("olcLdapSyntaxes");
5135 slap_bv2ad( &bv, &ad, &text );
5136 ct = config_find_table( colst, nocs, ad, ca );
5137 config_del_vals( ct, ca );
5139 if ( cfn->c_om_head ) {
5140 struct berval bv = BER_BVC("olcObjectIdentifier");
5142 slap_bv2ad( &bv, &ad, &text );
5143 ct = config_find_table( colst, nocs, ad, ca );
5144 config_del_vals( ct, ca );
5146 cfo = p->ce_private;
5147 cfo->c_kids = cfn->c_sibs;
5152 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
5154 int rc = LDAP_CONSTRAINT_VIOLATION;
5157 if ( (*cop)->co_ldadd ) {
5158 rc = (*cop)->co_ldadd( last, e, ca );
5159 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
5164 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
5165 ConfigOCs co = { 0 };
5167 co.co_name = &(*ocp)->soc_cname;
5168 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
5169 if ( *cop == NULL ) {
5173 rc = config_add_oc( cop, last, e, ca );
5174 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
5182 /* Parse an LDAP entry into config directives */
5184 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
5185 int *renum, Operation *op )
5187 CfEntryInfo *ce, *last = NULL;
5188 ConfigOCs co, *coptr, **colst;
5189 Attribute *a, *oc_at, *soc_at;
5190 int i, ibase = -1, nocs, rc = 0;
5193 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
5195 memset( ca, 0, sizeof(ConfigArgs));
5197 /* Make sure parent exists and entry does not. But allow
5198 * Databases and Overlays to be inserted. Don't do any
5199 * auto-renumbering if manageDSAit control is present.
5201 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
5203 if ( ( op && op->o_managedsait ) ||
5204 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
5205 ce->ce_type != Cft_Module ) )
5207 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5208 "DN=\"%s\" already exists\n",
5209 log_prefix, e->e_name.bv_val, 0 );
5210 /* global schema ignores all writes */
5211 if ( ce->ce_type == Cft_Schema && ce->ce_parent->ce_type == Cft_Global )
5212 return LDAP_COMPARE_TRUE;
5213 return LDAP_ALREADY_EXISTS;
5217 dnParent( &e->e_nname, &pdn );
5219 /* If last is NULL, the new entry is the root/suffix entry,
5220 * otherwise last should be the parent.
5222 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
5224 rs->sr_matched = last->ce_entry->e_name.bv_val;
5226 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5227 "DN=\"%s\" not child of DN=\"%s\"\n",
5228 log_prefix, e->e_name.bv_val,
5229 last->ce_entry->e_name.bv_val );
5230 return LDAP_NO_SUCH_OBJECT;
5234 /* No parent, must be root. This will never happen... */
5235 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
5236 return LDAP_NO_SUCH_OBJECT;
5239 if ( last && !access_allowed( op, last->ce_entry,
5240 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
5242 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5243 "DN=\"%s\" no write access to \"children\" of parent\n",
5244 log_prefix, e->e_name.bv_val, 0 );
5245 return LDAP_INSUFFICIENT_ACCESS;
5249 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5251 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5252 "DN=\"%s\" no objectClass\n",
5253 log_prefix, e->e_name.bv_val, 0 );
5254 return LDAP_OBJECT_CLASS_VIOLATION;
5257 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
5259 ObjectClass *soc = NULL;
5260 char textbuf[ SLAP_TEXT_BUFLEN ];
5261 const char *text = textbuf;
5263 /* FIXME: check result */
5264 rc = structural_class( oc_at->a_nvals, &soc, NULL,
5265 &text, textbuf, sizeof(textbuf), NULL );
5266 if ( rc != LDAP_SUCCESS ) {
5267 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5268 "DN=\"%s\" no structural objectClass (%s)\n",
5269 log_prefix, e->e_name.bv_val, text );
5272 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
5273 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
5274 if ( soc_at == NULL ) {
5275 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5276 "DN=\"%s\" no structural objectClass; "
5277 "unable to merge computed class %s\n",
5278 log_prefix, e->e_name.bv_val,
5279 soc->soc_cname.bv_val );
5280 return LDAP_OBJECT_CLASS_VIOLATION;
5283 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5284 "DN=\"%s\" no structural objectClass; "
5285 "computed objectClass %s merged\n",
5286 log_prefix, e->e_name.bv_val,
5287 soc->soc_cname.bv_val );
5290 /* Fake the coordinates based on whether we're part of an
5291 * LDAP Add or if reading the config dir
5294 ca->fname = "slapd";
5297 ca->fname = cfdir.bv_val;
5302 co.co_name = &soc_at->a_nvals[0];
5303 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
5304 if ( coptr == NULL ) {
5305 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5306 "DN=\"%s\" no structural objectClass in configuration table\n",
5307 log_prefix, e->e_name.bv_val, 0 );
5308 return LDAP_OBJECT_CLASS_VIOLATION;
5311 /* Only the root can be Cft_Global, everything else must
5312 * have a parent. Only limited nesting arrangements are allowed.
5314 rc = LDAP_CONSTRAINT_VIOLATION;
5315 if ( coptr->co_type == Cft_Global && !last ) {
5316 cfn = cfb->cb_config;
5317 ca->ca_private = cfn;
5318 ca->be = frontendDB; /* just to get past check_vals */
5322 colst = count_ocs( oc_at, &nocs );
5324 /* Check whether the Add is allowed by its parent, and do
5325 * any necessary arg setup
5328 rc = config_add_oc( &coptr, last, e, ca );
5329 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
5330 for ( i = 0; i<nocs; i++ ) {
5331 /* Already checked these */
5332 if ( colst[i]->co_oc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
5334 if ( colst[i]->co_ldadd &&
5335 ( rc = colst[i]->co_ldadd( last, e, ca ))
5336 != LDAP_CONSTRAINT_VIOLATION ) {
5342 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
5343 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5344 "DN=\"%s\" no structural objectClass add function\n",
5345 log_prefix, e->e_name.bv_val, 0 );
5346 return LDAP_OBJECT_CLASS_VIOLATION;
5350 /* Add the entry but don't parse it, we already have its contents */
5351 if ( rc == LDAP_COMPARE_TRUE ) {
5356 if ( rc != LDAP_SUCCESS )
5359 /* Parse all the values and check for simple syntax errors before
5360 * performing any set actions.
5362 * If doing an LDAPadd, check for indexed names and any necessary
5363 * renaming/renumbering. Entries that don't need indexed names are
5364 * ignored. Entries that need an indexed name and arrive without one
5365 * are assigned to the end. Entries that arrive with an index may
5366 * cause the following entries to be renumbered/bumped down.
5368 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
5369 * don't allow Adding an entry with an index that's already in use.
5370 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
5372 * These entries can have auto-assigned indexes (appended to the end)
5373 * but only the other types support auto-renumbering of siblings.
5376 rc = check_name_index( last, coptr->co_type, e, rs, renum,
5381 if ( renum && *renum && coptr->co_type != Cft_Database &&
5382 coptr->co_type != Cft_Overlay )
5384 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
5385 "operation requires sibling renumbering" );
5386 rc = LDAP_UNWILLING_TO_PERFORM;
5391 init_config_argv( ca );
5393 /* Make sure we process attrs in the required order */
5394 sort_attrs( e, colst, nocs );
5396 for ( a = e->e_attrs; a; a = a->a_next ) {
5397 if ( a == oc_at ) continue;
5398 ct = config_find_table( colst, nocs, a->a_desc, ca );
5399 if ( !ct ) continue; /* user data? */
5400 rc = check_vals( ct, ca, a, 1 );
5401 if ( rc ) goto done_noop;
5404 /* Basic syntax checks are OK. Do the actual settings. */
5405 for ( a=e->e_attrs; a; a=a->a_next ) {
5406 if ( a == oc_at ) continue;
5407 ct = config_find_table( colst, nocs, a->a_desc, ca );
5408 if ( !ct ) continue; /* user data? */
5409 for (i=0; a->a_vals[i].bv_val; i++) {
5412 ca->line = a->a_vals[i].bv_val;
5413 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
5414 ptr = strchr( ca->line, '}' );
5416 iptr = strchr( ca->line, '{' );
5420 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
5422 ca->valx = strtol( iptr+1, NULL, 0 );
5427 rc = config_parse_add( ct, ca, i );
5435 /* Newly added databases and overlays need to be started up */
5436 if ( CONFIG_ONLINE_ADD( ca )) {
5437 if ( coptr->co_type == Cft_Database ) {
5438 rc = backend_startup_one( ca->be, &ca->reply );
5440 } else if ( coptr->co_type == Cft_Overlay ) {
5441 if ( ca->bi->bi_db_open ) {
5442 BackendInfo *bi_orig = ca->be->bd_info;
5443 ca->be->bd_info = ca->bi;
5444 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
5445 ca->be->bd_info = bi_orig;
5447 } else if ( ca->cleanup ) {
5448 rc = ca->cleanup( ca );
5451 if (ca->cr_msg[0] == '\0')
5452 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
5454 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
5455 ca->log, ca->cr_msg, ca->argv[1] );
5462 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5463 ce->ce_parent = last;
5464 ce->ce_entry = entry_dup( e );
5465 ce->ce_entry->e_private = ce;
5466 ce->ce_type = coptr->co_type;
5469 ce->ce_private = ca->ca_private;
5470 ca->ca_entry = ce->ce_entry;
5473 } else if ( last->ce_kids ) {
5474 CfEntryInfo *c2, **cprev;
5476 /* Advance to first of this type */
5477 cprev = &last->ce_kids;
5478 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
5479 cprev = &c2->ce_sibs;
5482 /* Account for the (-1) frontendDB entry */
5483 if ( ce->ce_type == Cft_Database ) {
5484 if ( ca->be == frontendDB )
5486 else if ( ibase != -1 )
5491 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
5492 cprev = &c2->ce_sibs;
5498 for ( i=0; i<ibase; i++ ) {
5500 cprev = &c2->ce_sibs;
5503 ce->ce_sibs = *cprev;
5511 if ( (coptr->co_type == Cft_Database) && ca->be ) {
5512 if ( ca->be != frontendDB )
5513 backend_destroy_one( ca->be, 1 );
5514 } else if ( (coptr->co_type == Cft_Overlay) && ca->bi ) {
5515 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
5516 } else if ( coptr->co_type == Cft_Schema ) {
5517 schema_destroy_one( ca, colst, nocs, last );
5522 ch_free( ca->argv );
5523 if ( colst ) ch_free( colst );
5527 #define BIGTMP 10000
5529 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5530 int base, int rebase, int max, int use_ldif )
5532 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
5533 ConfigType etype = ce->ce_type;
5534 int count = 0, rc = 0;
5536 /* Reverse ce list */
5537 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
5538 if (ce2->ce_type != etype) {
5543 ce2->ce_sibs = cetmp;
5546 if ( max && count >= max ) {
5552 /* Move original to a temp name until increments are done */
5554 ce->ce_entry->e_private = NULL;
5555 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5556 base+BIGTMP, 0, use_ldif );
5557 ce->ce_entry->e_private = ce;
5559 /* start incrementing */
5560 for (ce2=cetmp; ce2; ce2=ce3) {
5562 ce2->ce_sibs = cerem;
5565 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5566 count+base, 0, use_ldif );
5570 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5571 base, 0, use_ldif );
5576 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5577 CfEntryInfo *ce2, int old, int use_ldif )
5581 /* Renumber original to a temp value */
5582 ce->ce_entry->e_private = NULL;
5583 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5584 old+BIGTMP, 0, use_ldif );
5585 ce->ce_entry->e_private = ce;
5587 /* start decrementing */
5588 for (; ce2 != ce; ce2=ce2->ce_sibs) {
5589 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5590 count+old, 0, use_ldif );
5593 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5594 count+old, 0, use_ldif );
5597 /* Parse an LDAP entry into config directives, then store in underlying
5601 config_back_add( Operation *op, SlapReply *rs )
5607 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
5608 NULL, ACL_WADD, NULL )) {
5609 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5614 * Check for attribute ACL
5616 if ( !acl_check_modlist( op, op->ora_e, op->orm_modlist )) {
5617 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5618 rs->sr_text = "no write access to attribute";
5622 cfb = (CfBackInfo *)op->o_bd->be_private;
5624 /* add opattrs for syncprov */
5626 char textbuf[SLAP_TEXT_BUFLEN];
5627 size_t textlen = sizeof textbuf;
5628 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1, NULL,
5629 &rs->sr_text, textbuf, sizeof( textbuf ) );
5630 if ( rs->sr_err != LDAP_SUCCESS )
5632 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
5633 if ( rs->sr_err != LDAP_SUCCESS ) {
5634 Debug( LDAP_DEBUG_TRACE,
5635 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
5636 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
5641 if ( op->o_abandon ) {
5642 rs->sr_err = SLAPD_ABANDON;
5645 ldap_pvt_thread_pool_pause( &connection_pool );
5648 * 1) check for existence of entry
5649 * 2) check for sibling renumbering
5650 * 3) perform internal add
5651 * 4) perform any necessary renumbering
5652 * 5) store entry in underlying database
5654 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
5655 if ( rs->sr_err != LDAP_SUCCESS ) {
5656 rs->sr_text = ca.cr_msg;
5661 CfEntryInfo *ce = ca.ca_entry->e_private;
5662 req_add_s addr = op->oq_add;
5663 op->o_tag = LDAP_REQ_MODRDN;
5664 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
5665 op->o_tag = LDAP_REQ_ADD;
5667 if ( rs->sr_err != LDAP_SUCCESS ) {
5672 if ( cfb->cb_use_ldif ) {
5673 BackendDB *be = op->o_bd;
5674 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5675 struct berval dn, ndn;
5677 op->o_bd = &cfb->cb_db;
5679 /* Save current rootdn; use the underlying DB's rootdn */
5682 op->o_dn = op->o_bd->be_rootdn;
5683 op->o_ndn = op->o_bd->be_rootndn;
5685 scp = op->o_callback;
5686 op->o_callback = ≻
5687 op->o_bd->be_add( op, rs );
5689 op->o_callback = scp;
5695 ldap_pvt_thread_pool_resume( &connection_pool );
5698 { int repl = op->o_dont_replicate;
5699 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
5700 rs->sr_text = NULL; /* Set after config_add_internal */
5701 rs->sr_err = LDAP_SUCCESS;
5702 op->o_dont_replicate = 1;
5704 send_ldap_result( op, rs );
5705 op->o_dont_replicate = repl;
5707 slap_graduate_commit_csn( op );
5711 typedef struct delrec {
5712 struct delrec *next;
5718 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
5724 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
5725 ca->line[0] == '{' )
5727 char *ptr = strchr( ca->line + 1, '}' );
5731 ca->valx = strtol( ca->line + 1, &next, 0 );
5732 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
5738 rc = config_parse_add( ct, ca, i );
5746 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
5749 int rc = LDAP_UNWILLING_TO_PERFORM;
5751 Entry *e = ce->ce_entry;
5752 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
5757 delrec *dels = NULL, *deltail = NULL;
5759 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5760 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
5762 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5763 if (ml->sml_desc == slap_schema.si_ad_objectClass)
5767 colst = count_ocs( oc_at, &nocs );
5769 /* make sure add/del flags are clear; should always be true */
5770 for ( s = save_attrs; s; s = s->a_next ) {
5771 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
5774 e->e_attrs = attrs_dup( e->e_attrs );
5776 init_config_argv( ca );
5779 ca->ca_private = ce->ce_private;
5781 ca->fname = "slapd";
5783 strcpy( ca->log, "back-config" );
5785 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5786 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5787 switch (ml->sml_op) {
5788 case LDAP_MOD_DELETE:
5789 case LDAP_MOD_REPLACE:
5790 case SLAP_MOD_SOFTDEL:
5792 BerVarray vals = NULL, nvals = NULL;
5794 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
5796 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
5797 ml->sml_desc->ad_cname.bv_val );
5800 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5801 vals = ml->sml_values;
5802 nvals = ml->sml_nvalues;
5803 ml->sml_values = NULL;
5804 ml->sml_nvalues = NULL;
5806 /* If we're deleting by values, remember the indexes of the
5807 * values we deleted.
5809 if ( ct && ml->sml_values ) {
5811 i = ml->sml_numvals;
5812 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
5823 rc = modify_delete_vindex(e, &ml->sml_mod,
5824 get_permissiveModify(op),
5825 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
5826 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5827 ml->sml_values = vals;
5828 ml->sml_nvalues = nvals;
5830 if ( rc == LDAP_NO_SUCH_ATTRIBUTE && ml->sml_op == SLAP_MOD_SOFTDEL )
5834 /* FIXME: check rc before fallthru? */
5838 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5840 case SLAP_MOD_ADD_IF_NOT_PRESENT:
5841 if ( ml->sml_op == SLAP_MOD_ADD_IF_NOT_PRESENT
5842 && attr_find( e->e_attrs, ml->sml_desc ) )
5849 case SLAP_MOD_SOFTADD: {
5850 int mop = ml->sml_op;
5852 ml->sml_op = LDAP_MOD_ADD;
5854 if ( ct->arg_type & ARG_NO_INSERT ) {
5855 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
5857 navals = a->a_numvals;
5860 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
5861 if ( ml->sml_values[i].bv_val[0] == '{' &&
5864 char *next, *val = ml->sml_values[i].bv_val + 1;
5867 j = strtol( val, &next, 0 );
5868 if ( next == val || next[ 0 ] != '}' || j < navals ) {
5870 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
5871 ml->sml_desc->ad_cname.bv_val );
5875 rc = check_vals( ct, ca, ml, 0 );
5876 if ( rc ) goto out_noop;
5879 rc = modify_add_values(e, &ml->sml_mod,
5880 get_permissiveModify(op),
5881 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5883 /* If value already exists, show success here
5884 * and ignore this operation down below.
5886 if ( mop == SLAP_MOD_SOFTADD ) {
5887 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
5897 case LDAP_MOD_INCREMENT: /* FIXME */
5902 if(rc != LDAP_SUCCESS) break;
5905 if ( rc == LDAP_SUCCESS) {
5906 /* check that the entry still obeys the schema */
5907 rc = entry_schema_check(op, e, NULL, 0, 0, NULL,
5908 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5910 if ( rc ) goto out_noop;
5912 /* Basic syntax checks are OK. Do the actual settings. */
5913 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5914 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5915 if ( !ct ) continue;
5917 s = attr_find( save_attrs, ml->sml_desc );
5918 a = attr_find( e->e_attrs, ml->sml_desc );
5920 switch (ml->sml_op) {
5921 case LDAP_MOD_DELETE:
5922 case LDAP_MOD_REPLACE: {
5923 BerVarray vals = NULL, nvals = NULL;
5926 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5927 vals = ml->sml_values;
5928 nvals = ml->sml_nvalues;
5929 ml->sml_values = NULL;
5930 ml->sml_nvalues = NULL;
5933 if ( ml->sml_values )
5936 /* If we didn't delete the whole attribute */
5937 if ( ml->sml_values && a ) {
5938 struct berval *mvals;
5941 if ( ml->sml_nvalues )
5942 mvals = ml->sml_nvalues;
5944 mvals = ml->sml_values;
5946 /* use the indexes we saved up above */
5947 for (i=0; i < d->nidx; i++) {
5948 struct berval bv = *mvals++;
5949 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
5950 bv.bv_val[0] == '{' ) {
5951 ptr = strchr( bv.bv_val, '}' ) + 1;
5952 bv.bv_len -= ptr - bv.bv_val;
5955 ca->line = bv.bv_val;
5956 ca->valx = d->idx[i];
5957 config_parse_vals(ct, ca, d->idx[i] );
5958 rc = config_del_vals( ct, ca );
5959 if ( rc != LDAP_SUCCESS ) break;
5961 s->a_flags |= SLAP_ATTR_IXDEL;
5962 for (j=i+1; j < d->nidx; j++)
5963 if ( d->idx[j] >d->idx[i] )
5970 rc = config_del_vals( ct, ca );
5971 if ( rc ) rc = LDAP_OTHER;
5973 s->a_flags |= SLAP_ATTR_IXDEL;
5975 if ( ml->sml_values ) {
5980 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5981 ml->sml_values = vals;
5982 ml->sml_nvalues = nvals;
5984 if ( !vals || rc != LDAP_SUCCESS )
5987 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5992 for (i=0; ml->sml_values[i].bv_val; i++) {
5993 ca->line = ml->sml_values[i].bv_val;
5995 rc = config_modify_add( ct, ca, ml->sml_desc, i );
5998 a->a_flags |= SLAP_ATTR_IXADD;
6005 /* Undo for a failed operation */
6006 if ( rc != LDAP_SUCCESS ) {
6007 ConfigReply msg = ca->reply;
6008 for ( s = save_attrs; s; s = s->a_next ) {
6009 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
6010 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
6011 ct = config_find_table( colst, nocs, s->a_desc, ca );
6012 a = attr_find( e->e_attrs, s->a_desc );
6014 /* clear the flag so the add check below will skip it */
6015 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
6019 config_del_vals( ct, ca );
6021 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
6022 ca->line = s->a_vals[i].bv_val;
6024 config_modify_add( ct, ca, s->a_desc, i );
6028 for ( a = e->e_attrs; a; a = a->a_next ) {
6029 if ( a->a_flags & SLAP_ATTR_IXADD ) {
6030 ct = config_find_table( colst, nocs, a->a_desc, ca );
6034 config_del_vals( ct, ca );
6035 s = attr_find( save_attrs, a->a_desc );
6037 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
6038 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
6039 ca->line = s->a_vals[i].bv_val;
6041 config_modify_add( ct, ca, s->a_desc, i );
6049 if ( ca->cleanup ) {
6050 i = ca->cleanup( ca );
6051 if (rc == LDAP_SUCCESS)
6055 if ( rc == LDAP_SUCCESS ) {
6056 attrs_free( save_attrs );
6059 attrs_free( e->e_attrs );
6060 e->e_attrs = save_attrs;
6062 ch_free( ca->argv );
6063 if ( colst ) ch_free( colst );
6065 deltail = dels->next;
6074 config_back_modify( Operation *op, SlapReply *rs )
6077 CfEntryInfo *ce, *last;
6079 ConfigArgs ca = {0};
6082 AttributeDescription *rad = NULL;
6085 cfb = (CfBackInfo *)op->o_bd->be_private;
6087 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6090 rs->sr_matched = last->ce_entry->e_name.bv_val;
6091 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6095 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
6096 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6100 /* Get type of RDN */
6101 rdn = ce->ce_entry->e_nname;
6102 ptr = strchr( rdn.bv_val, '=' );
6103 rdn.bv_len = ptr - rdn.bv_val;
6104 rs->sr_err = slap_bv2ad( &rdn, &rad, &rs->sr_text );
6105 if ( rs->sr_err != LDAP_SUCCESS ) {
6109 /* Some basic validation... */
6110 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
6111 /* Don't allow Modify of RDN; must use ModRdn for that. */
6112 if ( ml->sml_desc == rad ) {
6113 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
6114 rs->sr_text = "Use modrdn to change the entry name";
6117 /* Internal update of contextCSN? */
6118 if ( ml->sml_desc == slap_schema.si_ad_contextCSN && op->o_conn->c_conn_idx == -1 ) {
6124 slap_mods_opattrs( op, &op->orm_modlist, 1 );
6127 if ( op->o_abandon ) {
6128 rs->sr_err = SLAPD_ABANDON;
6131 ldap_pvt_thread_pool_pause( &connection_pool );
6135 * 1) perform the Modify on the cached Entry.
6136 * 2) verify that the Entry still satisfies the schema.
6137 * 3) perform the individual config operations.
6138 * 4) store Modified entry in underlying LDIF backend.
6140 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
6142 rs->sr_text = ca.cr_msg;
6143 } else if ( cfb->cb_use_ldif ) {
6144 BackendDB *be = op->o_bd;
6145 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
6146 struct berval dn, ndn;
6148 op->o_bd = &cfb->cb_db;
6152 op->o_dn = op->o_bd->be_rootdn;
6153 op->o_ndn = op->o_bd->be_rootndn;
6155 scp = op->o_callback;
6156 op->o_callback = ≻
6157 op->o_bd->be_modify( op, rs );
6159 op->o_callback = scp;
6165 ldap_pvt_thread_pool_resume( &connection_pool );
6167 send_ldap_result( op, rs );
6168 slap_graduate_commit_csn( op );
6173 config_back_modrdn( Operation *op, SlapReply *rs )
6176 CfEntryInfo *ce, *last;
6180 cfb = (CfBackInfo *)op->o_bd->be_private;
6182 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6185 rs->sr_matched = last->ce_entry->e_name.bv_val;
6186 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6189 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
6190 NULL, ACL_WRITE, NULL )) {
6191 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6195 if ( ce->ce_parent )
6196 parent = ce->ce_parent->ce_entry;
6198 parent = (Entry *)&slap_entry_root;
6199 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
6200 NULL, ACL_WRITE, NULL )) {
6201 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6206 /* We don't allow moving objects to new parents.
6207 * Generally we only allow reordering a set of ordered entries.
6209 if ( op->orr_newSup ) {
6210 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6214 /* If newRDN == oldRDN, quietly succeed */
6215 dnRdn( &op->o_req_ndn, &rdn );
6216 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
6217 rs->sr_err = LDAP_SUCCESS;
6221 /* Current behavior, subject to change as needed:
6223 * For backends and overlays, we only allow renumbering.
6224 * For schema, we allow renaming with the same number.
6225 * Otherwise, the op is not allowed.
6228 if ( ce->ce_type == Cft_Schema ) {
6232 /* Can't alter the main cn=schema entry */
6233 if ( ce->ce_parent->ce_type == Cft_Global ) {
6234 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6235 rs->sr_text = "renaming not allowed for this entry";
6239 /* We could support this later if desired */
6240 ptr1 = ber_bvchr( &rdn, '}' );
6241 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
6242 len = ptr1 - rdn.bv_val;
6243 if ( len != ptr2 - op->orr_newrdn.bv_val ||
6244 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
6245 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6246 rs->sr_text = "schema reordering not supported";
6249 } else if ( ce->ce_type == Cft_Database ||
6250 ce->ce_type == Cft_Overlay ) {
6251 char *ptr1, *ptr2, *iptr1, *iptr2;
6254 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
6255 if ( *iptr2 != '{' ) {
6256 rs->sr_err = LDAP_NAMING_VIOLATION;
6257 rs->sr_text = "new ordering index is required";
6261 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
6262 ptr1 = ber_bvchr( &rdn, '}' );
6263 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
6265 rs->sr_err = LDAP_NAMING_VIOLATION;
6266 rs->sr_text = "new ordering index is required";
6270 len1 = ptr1 - rdn.bv_val;
6271 len2 = ptr2 - op->orr_newrdn.bv_val;
6273 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
6274 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
6275 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6276 rs->sr_text = "changing database/overlay type not allowed";
6279 ixold = strtol( iptr1, NULL, 0 );
6280 ixnew = strtol( iptr2, &ptr1, 0 );
6281 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
6282 rs->sr_err = LDAP_NAMING_VIOLATION;
6285 /* config DB is always 0, cannot be changed */
6286 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
6287 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
6291 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6292 rs->sr_text = "renaming not supported for this entry";
6296 if ( op->o_abandon ) {
6297 rs->sr_err = SLAPD_ABANDON;
6300 ldap_pvt_thread_pool_pause( &connection_pool );
6302 if ( ce->ce_type == Cft_Schema ) {
6303 req_modrdn_s modr = op->oq_modrdn;
6306 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
6307 if ( rs->sr_err == LDAP_SUCCESS ) {
6308 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
6309 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
6312 op->oq_modrdn = modr;
6314 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
6315 req_modrdn_s modr = op->oq_modrdn;
6318 /* Advance to first of this type */
6319 cprev = &ce->ce_parent->ce_kids;
6320 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
6321 cprev = &ce2->ce_sibs;
6324 /* Skip the -1 entry */
6325 if ( ce->ce_type == Cft_Database ) {
6326 cprev = &ce2->ce_sibs;
6332 /* Remove from old slot */
6333 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
6334 cprev = &ce2->ce_sibs;
6335 *cprev = ce->ce_sibs;
6336 ceold = ce->ce_sibs;
6338 /* Insert into new slot */
6340 for ( i=0; i<ixnew; i++ ) {
6344 cprev = &ce2->ce_sibs;
6346 ce->ce_sibs = *cprev;
6351 /* NOTE: These should be encoded in the OC tables, not inline here */
6352 if ( ce->ce_type == Cft_Database )
6353 backend_db_move( ce->ce_be, ixnew );
6354 else if ( ce->ce_type == Cft_Overlay )
6355 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
6357 if ( ixold < ixnew ) {
6358 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
6361 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
6362 ixold - ixnew, cfb->cb_use_ldif );
6364 op->oq_modrdn = modr;
6367 ldap_pvt_thread_pool_resume( &connection_pool );
6369 send_ldap_result( op, rs );
6374 config_back_delete( Operation *op, SlapReply *rs )
6376 #ifdef SLAP_CONFIG_DELETE
6378 CfEntryInfo *ce, *last, *ce2;
6380 cfb = (CfBackInfo *)op->o_bd->be_private;
6382 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6385 rs->sr_matched = last->ce_entry->e_name.bv_val;
6386 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6387 } else if ( ce->ce_kids ) {
6388 rs->sr_err = LDAP_NOT_ALLOWED_ON_NONLEAF;
6389 } else if ( op->o_abandon ) {
6390 rs->sr_err = SLAPD_ABANDON;
6391 } else if ( ce->ce_type == Cft_Overlay ||
6392 ce->ce_type == Cft_Database ||
6393 ce->ce_type == Cft_Misc ){
6397 ldap_pvt_thread_pool_pause( &connection_pool );
6399 if ( ce->ce_type == Cft_Overlay ){
6400 overlay_remove( ce->ce_be, (slap_overinst *)ce->ce_bi, op );
6401 } else if ( ce->ce_type == Cft_Misc ) {
6403 * only Cft_Misc objects that have a co_lddel handler set in
6404 * the ConfigOCs struct can be deleted. This code also
6405 * assumes that the entry can be only have one objectclass
6406 * with co_type == Cft_Misc
6408 ConfigOCs co, *coptr;
6412 oc_at = attr_find( ce->ce_entry->e_attrs,
6413 slap_schema.si_ad_objectClass );
6415 rs->sr_err = LDAP_OTHER;
6416 rs->sr_text = "objectclass not found";
6417 ldap_pvt_thread_pool_resume( &connection_pool );
6420 for ( i=0; !BER_BVISNULL(&oc_at->a_nvals[i]); i++ ) {
6421 co.co_name = &oc_at->a_nvals[i];
6422 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
6423 if ( coptr == NULL || coptr->co_type != Cft_Misc ) {
6426 if ( ! coptr->co_lddel || coptr->co_lddel( ce, op ) ){
6427 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6428 if ( ! coptr->co_lddel ) {
6429 rs->sr_text = "No delete handler found";
6431 rs->sr_err = LDAP_OTHER;
6432 /* FIXME: We should return a helpful error message
6435 ldap_pvt_thread_pool_resume( &connection_pool );
6440 } else if (ce->ce_type == Cft_Database ) {
6441 if ( ce->ce_be == frontendDB || ce->ce_be == op->o_bd ){
6442 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6443 rs->sr_text = "Cannot delete config or frontend database";
6444 ldap_pvt_thread_pool_resume( &connection_pool );
6447 if ( ce->ce_be->bd_info->bi_db_close ) {
6448 ce->ce_be->bd_info->bi_db_close( ce->ce_be, NULL );
6450 backend_destroy_one( ce->ce_be, 1);
6453 /* remove CfEntryInfo from the siblings list */
6454 if ( ce->ce_parent->ce_kids == ce ) {
6455 ce->ce_parent->ce_kids = ce->ce_sibs;
6457 for ( ce2 = ce->ce_parent->ce_kids ; ce2; ce2 = ce2->ce_sibs ) {
6458 if ( ce2->ce_sibs == ce ) {
6459 ce2->ce_sibs = ce->ce_sibs;
6465 /* remove from underlying database */
6466 if ( cfb->cb_use_ldif ) {
6467 BackendDB *be = op->o_bd;
6468 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
6469 struct berval dn, ndn, req_dn, req_ndn;
6471 op->o_bd = &cfb->cb_db;
6475 req_dn = op->o_req_dn;
6476 req_ndn = op->o_req_ndn;
6478 op->o_dn = op->o_bd->be_rootdn;
6479 op->o_ndn = op->o_bd->be_rootndn;
6480 op->o_req_dn = ce->ce_entry->e_name;
6481 op->o_req_ndn = ce->ce_entry->e_nname;
6483 scp = op->o_callback;
6484 op->o_callback = ≻
6485 op->o_bd->be_delete( op, rs );
6487 op->o_callback = scp;
6490 op->o_req_dn = req_dn;
6491 op->o_req_ndn = req_ndn;
6494 /* renumber siblings */
6495 iptr = ber_bvchr( &op->o_req_ndn, '{' ) + 1;
6496 ixold = strtol( iptr, NULL, 0 );
6497 for (ce2 = ce->ce_sibs, count=0; ce2; ce2=ce2->ce_sibs) {
6498 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
6499 count+ixold, 0, cfb->cb_use_ldif );
6503 ce->ce_entry->e_private=NULL;
6504 entry_free(ce->ce_entry);
6506 ldap_pvt_thread_pool_resume( &connection_pool );
6508 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6512 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6513 #endif /* SLAP_CONFIG_DELETE */
6514 send_ldap_result( op, rs );
6519 config_back_search( Operation *op, SlapReply *rs )
6522 CfEntryInfo *ce, *last;
6525 cfb = (CfBackInfo *)op->o_bd->be_private;
6527 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6530 rs->sr_matched = last->ce_entry->e_name.bv_val;
6531 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6534 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
6535 ACL_SEARCH, NULL, &mask ))
6537 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
6538 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6540 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6544 switch ( op->ors_scope ) {
6545 case LDAP_SCOPE_BASE:
6546 case LDAP_SCOPE_SUBTREE:
6547 rs->sr_err = config_send( op, rs, ce, 0 );
6550 case LDAP_SCOPE_ONELEVEL:
6551 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
6552 rs->sr_err = config_send( op, rs, ce, 1 );
6561 send_ldap_result( op, rs );
6565 /* no-op, we never free entries */
6566 int config_entry_release(
6571 if ( !e->e_private ) {
6574 return LDAP_SUCCESS;
6577 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
6579 int config_back_entry_get(
6583 AttributeDescription *at,
6588 CfEntryInfo *ce, *last;
6589 int rc = LDAP_NO_SUCH_OBJECT;
6591 cfb = (CfBackInfo *)op->o_bd->be_private;
6593 ce = config_find_base( cfb->cb_root, ndn, &last );
6595 *ent = ce->ce_entry;
6598 if ( oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
6599 rc = LDAP_NO_SUCH_ATTRIBUTE;
6609 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
6610 ConfigTable *ct, ConfigArgs *c )
6614 for (; at && *at; at++) {
6615 /* Skip the naming attr */
6616 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
6618 for (i=0;ct[i].name;i++) {
6619 if (ct[i].ad == (*at)->sat_ad) {
6620 rc = config_get_vals(&ct[i], c);
6621 /* NOTE: tolerate that config_get_vals()
6622 * returns success with no values */
6623 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
6624 if ( c->rvalue_nvals )
6625 rc = attr_merge(e, ct[i].ad, c->rvalue_vals,
6628 slap_syntax_validate_func *validate =
6629 ct[i].ad->ad_type->sat_syntax->ssyn_validate;
6632 for ( j=0; c->rvalue_vals[j].bv_val; j++ ) {
6633 rc = ordered_value_validate( ct[i].ad,
6634 &c->rvalue_vals[j], LDAP_MOD_ADD );
6636 Debug( LDAP_DEBUG_ANY,
6637 "config_build_attrs: error %d on %s value #%d\n",
6638 rc, ct[i].ad->ad_cname.bv_val, j );
6644 rc = attr_merge_normalize(e, ct[i].ad,
6645 c->rvalue_vals, NULL);
6647 ber_bvarray_free( c->rvalue_nvals );
6648 ber_bvarray_free( c->rvalue_vals );
6650 Debug( LDAP_DEBUG_ANY,
6651 "config_build_attrs: error %d on %s\n",
6652 rc, ct[i].ad->ad_cname.bv_val, 0 );
6663 /* currently (2010) does not access rs except possibly writing rs->sr_err */
6666 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
6667 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
6669 Entry *e = entry_alloc();
6670 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
6672 struct berval ad_name;
6673 AttributeDescription *ad = NULL;
6676 const char *text = "";
6680 CfEntryInfo *ceprev = NULL;
6682 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
6685 ce->ce_type = main->co_type;
6686 ce->ce_parent = parent;
6688 pdn = parent->ce_entry->e_nname;
6689 if ( parent->ce_kids && parent->ce_kids->ce_type <= ce->ce_type )
6690 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
6691 ceprev->ce_type <= ce->ce_type;
6692 ceprev = ceprev->ce_sibs );
6697 ce->ce_private = c->ca_private;
6701 build_new_dn( &e->e_name, &pdn, rdn, NULL );
6702 ber_dupbv( &e->e_nname, &e->e_name );
6704 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6705 main->co_name, NULL );
6707 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6708 extra->co_name, NULL );
6709 ptr = strchr(rdn->bv_val, '=');
6710 ad_name.bv_val = rdn->bv_val;
6711 ad_name.bv_len = ptr - rdn->bv_val;
6712 rc = slap_bv2ad( &ad_name, &ad, &text );
6717 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
6718 attr_merge_normalize_one(e, ad, &val, NULL );
6721 c->table = main->co_type;
6722 if ( oc->soc_required ) {
6723 rc = config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
6724 if ( rc ) goto fail;
6727 if ( oc->soc_allowed ) {
6728 rc = config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
6729 if ( rc ) goto fail;
6734 c->table = extra->co_type;
6735 if ( oc->soc_required ) {
6736 rc = config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
6737 if ( rc ) goto fail;
6740 if ( oc->soc_allowed ) {
6741 rc = config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
6742 if ( rc ) goto fail;
6746 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
6747 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
6748 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
6749 if ( rc != LDAP_SUCCESS ) {
6751 Debug( LDAP_DEBUG_ANY,
6752 "config_build_entry: build \"%s\" failed: \"%s\"\n",
6753 rdn->bv_val, text, 0);
6756 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
6759 op->ora_modlist = NULL;
6760 slap_add_opattrs( op, NULL, NULL, 0, 0 );
6761 if ( !op->o_noop ) {
6762 SlapReply rs2 = {REP_RESULT};
6763 op->o_bd->be_add( op, &rs2 );
6764 rs->sr_err = rs2.sr_err;
6765 rs_assert_done( &rs2 );
6766 if ( ( rs2.sr_err != LDAP_SUCCESS )
6767 && (rs2.sr_err != LDAP_ALREADY_EXISTS) ) {
6773 ce->ce_sibs = ceprev->ce_sibs;
6774 ceprev->ce_sibs = ce;
6775 } else if ( parent ) {
6776 ce->ce_sibs = parent->ce_kids;
6777 parent->ce_kids = ce;
6784 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
6785 Operation *op, SlapReply *rs )
6788 ConfigFile *cf = c->ca_private;
6790 struct berval bv, rdn;
6792 for (; cf; cf=cf->c_sibs, c->depth++) {
6793 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
6794 !cf->c_om_head && !cf->c_syn_head ) continue;
6795 c->value_dn.bv_val = c->log;
6796 LUTIL_SLASHPATH( cf->c_file.bv_val );
6797 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
6802 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
6804 ptr = strchr( bv.bv_val, '.' );
6806 bv.bv_len = ptr - bv.bv_val;
6807 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
6808 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6809 /* FIXME: how can indicate error? */
6812 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
6814 c->value_dn.bv_len += bv.bv_len;
6815 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
6816 rdnNormalize( 0, NULL, NULL, &c->value_dn, &rdn, NULL );
6819 e = config_build_entry( op, rs, ceparent, c, &rdn,
6820 &CFOC_SCHEMA, NULL );
6821 ch_free( rdn.bv_val );
6824 } else if ( e && cf->c_kids ) {
6825 c->ca_private = cf->c_kids;
6826 config_build_schema_inc( c, e->e_private, op, rs );
6832 #ifdef SLAPD_MODULES
6835 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
6836 Operation *op, SlapReply *rs )
6841 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
6842 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
6844 c->value_dn.bv_val = c->log;
6845 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
6846 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6847 /* FIXME: how can indicate error? */
6851 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
6860 config_check_schema(Operation *op, CfBackInfo *cfb)
6862 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
6864 CfEntryInfo *ce, *last;
6867 /* If there's no root entry, we must be in the midst of converting */
6868 if ( !cfb->cb_root )
6871 /* Make sure the main schema entry exists */
6872 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
6879 /* Make sure it's up to date */
6880 if ( cf_om_tail != om_sys_tail ) {
6881 a = attr_find( e->e_attrs, cfAd_om );
6883 if ( a->a_nvals != a->a_vals )
6884 ber_bvarray_free( a->a_nvals );
6885 ber_bvarray_free( a->a_vals );
6890 oidm_unparse( &bv, NULL, NULL, 1 );
6891 attr_merge_normalize( e, cfAd_om, bv, NULL );
6892 ber_bvarray_free( bv );
6893 cf_om_tail = om_sys_tail;
6895 if ( cf_at_tail != at_sys_tail ) {
6896 a = attr_find( e->e_attrs, cfAd_attr );
6898 if ( a->a_nvals != a->a_vals )
6899 ber_bvarray_free( a->a_nvals );
6900 ber_bvarray_free( a->a_vals );
6905 at_unparse( &bv, NULL, NULL, 1 );
6906 attr_merge_normalize( e, cfAd_attr, bv, NULL );
6907 ber_bvarray_free( bv );
6908 cf_at_tail = at_sys_tail;
6910 if ( cf_oc_tail != oc_sys_tail ) {
6911 a = attr_find( e->e_attrs, cfAd_oc );
6913 if ( a->a_nvals != a->a_vals )
6914 ber_bvarray_free( a->a_nvals );
6915 ber_bvarray_free( a->a_vals );
6920 oc_unparse( &bv, NULL, NULL, 1 );
6921 attr_merge_normalize( e, cfAd_oc, bv, NULL );
6922 ber_bvarray_free( bv );
6923 cf_oc_tail = oc_sys_tail;
6925 if ( cf_syn_tail != syn_sys_tail ) {
6926 a = attr_find( e->e_attrs, cfAd_syntax );
6928 if ( a->a_nvals != a->a_vals )
6929 ber_bvarray_free( a->a_nvals );
6930 ber_bvarray_free( a->a_vals );
6935 syn_unparse( &bv, NULL, NULL, 1 );
6936 attr_merge_normalize( e, cfAd_syntax, bv, NULL );
6937 ber_bvarray_free( bv );
6938 cf_syn_tail = syn_sys_tail;
6941 SlapReply rs = {REP_RESULT};
6942 c.ca_private = NULL;
6943 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
6944 &CFOC_SCHEMA, NULL );
6949 ce->ce_private = cfb->cb_config;
6950 cf_at_tail = at_sys_tail;
6951 cf_oc_tail = oc_sys_tail;
6952 cf_om_tail = om_sys_tail;
6953 cf_syn_tail = syn_sys_tail;
6958 static const char *defacl[] = {
6959 NULL, "to", "*", "by", "*", "none", NULL
6963 config_back_db_open( BackendDB *be, ConfigReply *cr )
6965 CfBackInfo *cfb = be->be_private;
6968 CfEntryInfo *ce, *ceparent;
6972 Connection conn = {0};
6973 OperationBuffer opbuf;
6975 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
6976 SlapReply rs = {REP_RESULT};
6977 void *thrctx = NULL;
6978 AccessControl *save_access;
6980 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
6982 /* If we have no explicitly configured ACLs, don't just use
6983 * the global ACLs. Explicitly deny access to everything.
6985 save_access = be->bd_self->be_acl;
6986 be->bd_self->be_acl = NULL;
6987 parse_acl(be->bd_self, "config_back_db_open", 0, 6, (char **)defacl, 0 );
6988 defacl_parsed = be->bd_self->be_acl;
6989 if ( save_access ) {
6990 be->bd_self->be_acl = save_access;
6992 Debug( LDAP_DEBUG_CONFIG, "config_back_db_open: "
6993 "No explicit ACL for back-config configured. "
6994 "Using hardcoded default\n", 0, 0, 0 );
6997 thrctx = ldap_pvt_thread_pool_context();
6998 connection_fake_init( &conn, &opbuf, thrctx );
7001 op->o_tag = LDAP_REQ_ADD;
7002 op->o_callback = &cb;
7003 op->o_bd = &cfb->cb_db;
7004 op->o_dn = op->o_bd->be_rootdn;
7005 op->o_ndn = op->o_bd->be_rootndn;
7007 if ( !cfb->cb_use_ldif ) {
7011 /* If we read the config from back-ldif, do some quick sanity checks */
7012 if ( cfb->cb_got_ldif ) {
7013 return config_check_schema( op, cfb );
7016 /* create root of tree */
7018 c.ca_private = cfb->cb_config;
7020 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
7030 #ifdef SLAPD_MODULES
7031 /* Create Module nodes... */
7032 if ( modpaths.mp_loads ) {
7033 if ( config_build_modules( &c, ceparent, op, &rs ) ){
7039 /* Create schema nodes... cn=schema will contain the hardcoded core
7040 * schema, read-only. Child objects will contain runtime loaded schema
7044 c.ca_private = NULL;
7045 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
7050 ce->ce_private = cfb->cb_config;
7051 cf_at_tail = at_sys_tail;
7052 cf_oc_tail = oc_sys_tail;
7053 cf_om_tail = om_sys_tail;
7054 cf_syn_tail = syn_sys_tail;
7056 /* Create schema nodes for included schema... */
7057 if ( cfb->cb_config->c_kids ) {
7060 c.ca_private = cfb->cb_config->c_kids;
7061 rc = config_build_schema_inc( &c, ce, op, &rs );
7067 /* Create backend nodes. Skip if they don't provide a cf_table.
7068 * There usually aren't any of these.
7072 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
7073 if (!bi->bi_cf_ocs) {
7074 /* If it only supports the old config mech, complain. */
7075 if ( bi->bi_config ) {
7076 Debug( LDAP_DEBUG_ANY,
7077 "WARNING: No dynamic config support for backend %s.\n",
7078 bi->bi_type, 0, 0 );
7083 if (!bi->bi_private) continue;
7086 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
7087 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
7088 if ( rdn.bv_len >= sizeof( c.log ) ) {
7089 /* FIXME: holler ... */ ;
7092 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
7099 /* Create database nodes... */
7100 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
7101 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
7102 for ( i = -1, be = frontendDB ; be;
7103 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
7104 slap_overinfo *oi = NULL;
7106 if ( overlay_is_over( be )) {
7107 oi = be->bd_info->bi_private;
7113 /* If this backend supports the old config mechanism, but not
7114 * the new mech, complain.
7116 if ( !be->be_cf_ocs && bi->bi_db_config ) {
7117 Debug( LDAP_DEBUG_ANY,
7118 "WARNING: No dynamic config support for database %s.\n",
7119 bi->bi_type, 0, 0 );
7123 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
7124 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
7126 if ( rdn.bv_len >= sizeof( c.log ) ) {
7127 /* FIXME: holler ... */ ;
7131 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
7137 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd ) {
7138 rs_reinit( &rs, REP_RESULT );
7139 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
7141 /* Iterate through overlays */
7146 voidList *vl, *v0 = NULL;
7148 /* overlays are in LIFO order, must reverse stack */
7149 for (on=oi->oi_list; on; on=on->on_next) {
7150 vl = ch_malloc( sizeof( voidList ));
7155 for (j=0; vl; j++,vl=v0) {
7159 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
7160 Debug( LDAP_DEBUG_ANY,
7161 "WARNING: No dynamic config support for overlay %s.\n",
7162 on->on_bi.bi_type, 0, 0 );
7166 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
7167 "%s=" SLAP_X_ORDERED_FMT "%s",
7168 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
7169 if ( rdn.bv_len >= sizeof( c.log ) ) {
7170 /* FIXME: holler ... */ ;
7174 oe = config_build_entry( op, &rs, ce, &c, &rdn,
7175 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
7179 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd ) {
7180 rs_reinit( &rs, REP_RESULT );
7181 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
7187 ldap_pvt_thread_pool_context_reset( thrctx );
7189 if ( unsupp && cfb->cb_use_ldif ) {
7190 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
7191 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
7198 cfb_free_cffile( ConfigFile *cf )
7202 for (; cf; cf=next) {
7205 cfb_free_cffile( cf->c_kids );
7206 ch_free( cf->c_file.bv_val );
7207 ber_bvarray_free( cf->c_dseFiles );
7213 cfb_free_entries( CfEntryInfo *ce )
7217 for (; ce; ce=next) {
7220 cfb_free_entries( ce->ce_kids );
7221 ce->ce_entry->e_private = NULL;
7222 entry_free( ce->ce_entry );
7228 config_back_db_close( BackendDB *be, ConfigReply *cr )
7230 CfBackInfo *cfb = be->be_private;
7232 cfb_free_entries( cfb->cb_root );
7233 cfb->cb_root = NULL;
7235 if ( cfb->cb_db.bd_info ) {
7236 backend_shutdown( &cfb->cb_db );
7239 if ( defacl_parsed && be->be_acl != defacl_parsed ) {
7240 acl_free( defacl_parsed );
7241 defacl_parsed = NULL;
7248 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
7250 CfBackInfo *cfb = be->be_private;
7252 cfb_free_cffile( cfb->cb_config );
7254 ch_free( cfdir.bv_val );
7256 avl_free( CfOcTree, NULL );
7258 if ( cfb->cb_db.bd_info ) {
7259 cfb->cb_db.be_suffix = NULL;
7260 cfb->cb_db.be_nsuffix = NULL;
7261 BER_BVZERO( &cfb->cb_db.be_rootdn );
7262 BER_BVZERO( &cfb->cb_db.be_rootndn );
7264 backend_destroy_one( &cfb->cb_db, 0 );
7273 config_back_db_init( BackendDB *be, ConfigReply* cr )
7279 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
7280 cfn = cfb->cb_config;
7281 be->be_private = cfb;
7283 ber_dupbv( &be->be_rootdn, &config_rdn );
7284 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
7285 ber_dupbv( &dn, &be->be_rootdn );
7286 ber_bvarray_add( &be->be_suffix, &dn );
7287 ber_dupbv( &dn, &be->be_rootdn );
7288 ber_bvarray_add( &be->be_nsuffix, &dn );
7290 /* Hide from namingContexts */
7291 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
7293 /* Check ACLs on content of Adds by default */
7294 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_ACL_ADD;
7300 config_back_destroy( BackendInfo *bi )
7302 ldif_must_b64_encode_release();
7307 config_tool_entry_open( BackendDB *be, int mode )
7309 CfBackInfo *cfb = be->be_private;
7310 BackendInfo *bi = cfb->cb_db.bd_info;
7312 if ( bi && bi->bi_tool_entry_open )
7313 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
7320 config_tool_entry_close( BackendDB *be )
7322 CfBackInfo *cfb = be->be_private;
7323 BackendInfo *bi = cfb->cb_db.bd_info;
7325 if ( bi && bi->bi_tool_entry_close )
7326 return bi->bi_tool_entry_close( &cfb->cb_db );
7332 config_tool_entry_first( BackendDB *be )
7334 CfBackInfo *cfb = be->be_private;
7335 BackendInfo *bi = cfb->cb_db.bd_info;
7337 if ( bi && bi->bi_tool_entry_first ) {
7338 return bi->bi_tool_entry_first( &cfb->cb_db );
7340 if ( bi && bi->bi_tool_entry_first_x ) {
7341 return bi->bi_tool_entry_first_x( &cfb->cb_db,
7342 NULL, LDAP_SCOPE_DEFAULT, NULL );
7348 config_tool_entry_first_x(
7350 struct berval *base,
7354 CfBackInfo *cfb = be->be_private;
7355 BackendInfo *bi = cfb->cb_db.bd_info;
7357 if ( bi && bi->bi_tool_entry_first_x ) {
7358 return bi->bi_tool_entry_first_x( &cfb->cb_db, base, scope, f );
7364 config_tool_entry_next( BackendDB *be )
7366 CfBackInfo *cfb = be->be_private;
7367 BackendInfo *bi = cfb->cb_db.bd_info;
7369 if ( bi && bi->bi_tool_entry_next )
7370 return bi->bi_tool_entry_next( &cfb->cb_db );
7376 config_tool_entry_get( BackendDB *be, ID id )
7378 CfBackInfo *cfb = be->be_private;
7379 BackendInfo *bi = cfb->cb_db.bd_info;
7381 if ( bi && bi->bi_tool_entry_get )
7382 return bi->bi_tool_entry_get( &cfb->cb_db, id );
7387 static int entry_put_got_frontend=0;
7388 static int entry_put_got_config=0;
7390 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
7392 CfBackInfo *cfb = be->be_private;
7393 BackendInfo *bi = cfb->cb_db.bd_info;
7395 struct berval rdn, vals[ 2 ];
7397 OperationBuffer opbuf;
7399 Connection conn = {0};
7400 Operation *op = NULL;
7403 int isFrontendChild = 0;
7405 /* Create entry for frontend database if it does not exist already */
7406 if ( !entry_put_got_frontend ) {
7407 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
7408 STRLENOF( "olcDatabase" ))) {
7409 if ( strncmp( e->e_nname.bv_val +
7410 STRLENOF( "olcDatabase" ), "={-1}frontend",
7411 STRLENOF( "={-1}frontend" )) &&
7412 strncmp( e->e_nname.bv_val +
7413 STRLENOF( "olcDatabase" ), "=frontend",
7414 STRLENOF( "=frontend" ))) {
7416 vals[1].bv_val = NULL;
7417 memset( &ca, 0, sizeof(ConfigArgs));
7419 ca.bi = frontendDB->bd_info;
7420 ca.be->be_cf_ocs = &CFOC_FRONTEND;
7421 rdn.bv_val = ca.log;
7422 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7423 "%s=" SLAP_X_ORDERED_FMT "%s",
7424 cfAd_database->ad_cname.bv_val, -1,
7426 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
7427 &CFOC_DATABASE, ca.be->be_cf_ocs );
7428 thrctx = ldap_pvt_thread_pool_context();
7429 connection_fake_init2( &conn, &opbuf, thrctx,0 );
7431 op->o_bd = &cfb->cb_db;
7432 op->o_tag = LDAP_REQ_ADD;
7434 op->o_dn = be->be_rootdn;
7435 op->o_ndn = be->be_rootndn;
7436 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
7437 if ( rc != LDAP_SUCCESS ) {
7438 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
7439 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
7443 if ( ce && bi && bi->bi_tool_entry_put &&
7444 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
7445 entry_put_got_frontend++;
7447 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
7448 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
7452 if ( !strncmp( e->e_nname.bv_val +
7453 STRLENOF( "olcDatabase" ), "=frontend",
7454 STRLENOF( "=frontend" ) ) )
7456 struct berval rdn, pdn, ndn;
7457 dnParent( &e->e_nname, &pdn );
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,
7462 frontendDB->bd_info->bi_type );
7463 build_new_dn( &ndn, &pdn, &rdn, NULL );
7464 ber_memfree( e->e_name.bv_val );
7466 ber_bvreplace( &e->e_nname, &e->e_name );
7468 entry_put_got_frontend++;
7474 /* Child entries of the frontend database, e.g. slapo-chain's back-ldap
7475 * instances, may appear before the config database entry in the ldif, skip
7476 * auto-creation of olcDatabase={0}config in such a case */
7477 if ( !entry_put_got_config &&
7478 !strncmp( e->e_nname.bv_val, "olcDatabase", STRLENOF( "olcDatabase" ))) {
7480 dnParent( &e->e_nname, &pdn );
7481 while ( pdn.bv_len ) {
7482 if ( !strncmp( pdn.bv_val, "olcDatabase",
7483 STRLENOF( "olcDatabase" ))) {
7484 if ( !strncmp( pdn.bv_val +
7485 STRLENOF( "olcDatabase" ), "={-1}frontend",
7486 STRLENOF( "={-1}frontend" )) ||
7487 !strncmp( pdn.bv_val +
7488 STRLENOF( "olcDatabase" ), "=frontend",
7489 STRLENOF( "=frontend" ))) {
7491 isFrontendChild = 1;
7495 dnParent( &pdn, &pdn );
7499 /* Create entry for config database if it does not exist already */
7500 if ( !entry_put_got_config && !isFrontend && !isFrontendChild ) {
7501 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
7502 STRLENOF( "olcDatabase" ))) {
7503 if ( strncmp( e->e_nname.bv_val +
7504 STRLENOF( "olcDatabase" ), "={0}config",
7505 STRLENOF( "={0}config" )) &&
7506 strncmp( e->e_nname.bv_val +
7507 STRLENOF( "olcDatabase" ), "=config",
7508 STRLENOF( "=config" )) ) {
7510 vals[1].bv_val = NULL;
7511 memset( &ca, 0, sizeof(ConfigArgs));
7512 ca.be = LDAP_STAILQ_FIRST( &backendDB );
7513 ca.bi = ca.be->bd_info;
7514 rdn.bv_val = ca.log;
7515 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7516 "%s=" SLAP_X_ORDERED_FMT "%s",
7517 cfAd_database->ad_cname.bv_val, 0,
7519 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
7522 thrctx = ldap_pvt_thread_pool_context();
7523 connection_fake_init2( &conn, &opbuf, thrctx,0 );
7525 op->o_bd = &cfb->cb_db;
7526 op->o_tag = LDAP_REQ_ADD;
7527 op->o_dn = be->be_rootdn;
7528 op->o_ndn = be->be_rootndn;
7531 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
7532 if ( rc != LDAP_SUCCESS ) {
7533 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
7534 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7537 if (ce && bi && bi->bi_tool_entry_put &&
7538 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
7539 entry_put_got_config++;
7541 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
7542 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7546 entry_put_got_config++;
7550 if ( bi && bi->bi_tool_entry_put &&
7551 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
7552 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
7559 AttributeDescription **desc;
7561 { "attribute", &cfAd_attr },
7562 { "backend", &cfAd_backend },
7563 { "database", &cfAd_database },
7564 { "include", &cfAd_include },
7565 { "ldapsyntax", &cfAd_syntax },
7566 { "objectclass", &cfAd_oc },
7567 { "objectidentifier", &cfAd_om },
7568 { "overlay", &cfAd_overlay },
7573 * add / delete: all types that may be added or deleted must use an
7574 * X-ORDERED attributeType for their RDN. Adding and deleting entries
7575 * should automatically renumber the index of any siblings as needed,
7576 * so that no gaps in the numbering sequence exist after the add/delete
7578 * What can be added:
7580 * backend objects for backend-specific config directives
7584 * delete: probably no support this time around.
7586 * modrdn: generally not done. Will be invoked automatically by add/
7587 * delete to update numbering sequence. Perform as an explicit operation
7588 * so that the renumbering effect may be replicated. Subtree rename must
7589 * be supported, since renumbering a database will affect all its child
7592 * modify: must be fully supported.
7596 config_back_initialize( BackendInfo *bi )
7598 ConfigTable *ct = config_back_cf_table;
7602 AttributeDescription *ad = NULL;
7604 static char *controls[] = {
7605 LDAP_CONTROL_MANAGEDSAIT,
7609 /* Make sure we don't exceed the bits reserved for userland */
7610 config_check_userland( CFG_LAST );
7612 bi->bi_controls = controls;
7617 bi->bi_destroy = config_back_destroy;
7619 bi->bi_db_init = config_back_db_init;
7620 bi->bi_db_config = 0;
7621 bi->bi_db_open = config_back_db_open;
7622 bi->bi_db_close = config_back_db_close;
7623 bi->bi_db_destroy = config_back_db_destroy;
7625 bi->bi_op_bind = config_back_bind;
7626 bi->bi_op_unbind = 0;
7627 bi->bi_op_search = config_back_search;
7628 bi->bi_op_compare = 0;
7629 bi->bi_op_modify = config_back_modify;
7630 bi->bi_op_modrdn = config_back_modrdn;
7631 bi->bi_op_add = config_back_add;
7632 bi->bi_op_delete = config_back_delete;
7633 bi->bi_op_abandon = 0;
7635 bi->bi_extended = 0;
7637 bi->bi_chk_referrals = 0;
7639 bi->bi_access_allowed = slap_access_allowed;
7641 bi->bi_connection_init = 0;
7642 bi->bi_connection_destroy = 0;
7644 bi->bi_entry_release_rw = config_entry_release;
7645 bi->bi_entry_get_rw = config_back_entry_get;
7647 bi->bi_tool_entry_open = config_tool_entry_open;
7648 bi->bi_tool_entry_close = config_tool_entry_close;
7649 bi->bi_tool_entry_first = config_tool_entry_first;
7650 bi->bi_tool_entry_first_x = config_tool_entry_first_x;
7651 bi->bi_tool_entry_next = config_tool_entry_next;
7652 bi->bi_tool_entry_get = config_tool_entry_get;
7653 bi->bi_tool_entry_put = config_tool_entry_put;
7656 argv[ 0 ] = "slapd";
7662 for (i=0; OidMacros[i].name; i++ ) {
7663 argv[1] = OidMacros[i].name;
7664 argv[2] = OidMacros[i].oid;
7665 parse_oidm( &ca, 0, NULL );
7668 bi->bi_cf_ocs = cf_ocs;
7670 i = config_register_schema( ct, cf_ocs );
7673 i = slap_str2ad( "olcDatabase", &olcDatabaseDummy[0].ad, &text );
7676 /* setup olcRootPW to be base64-encoded when written in LDIF form;
7677 * basically, we don't care if it fails */
7678 i = slap_str2ad( "olcRootPW", &ad, &text );
7680 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
7681 "warning, unable to get \"olcRootPW\" "
7682 "attribute description: %d: %s\n",
7685 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
7686 ad->ad_type->sat_oid );
7689 /* set up the notable AttributeDescriptions */
7691 for (;ct->name;ct++) {
7692 if (strcmp(ct->name, ads[i].name)) continue;
7693 *ads[i].desc = ct->ad;
7695 if (!ads[i].name) break;