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,
209 static OidRec OidMacros[] = {
210 /* OpenLDAProot:1.12.2 */
211 { "OLcfg", "1.3.6.1.4.1.4203.1.12.2" },
212 { "OLcfgAt", "OLcfg:3" },
213 { "OLcfgGlAt", "OLcfgAt:0" },
214 { "OLcfgBkAt", "OLcfgAt:1" },
215 { "OLcfgDbAt", "OLcfgAt:2" },
216 { "OLcfgOvAt", "OLcfgAt:3" },
217 { "OLcfgCtAt", "OLcfgAt:4" }, /* contrib modules */
218 { "OLcfgOc", "OLcfg:4" },
219 { "OLcfgGlOc", "OLcfgOc:0" },
220 { "OLcfgBkOc", "OLcfgOc:1" },
221 { "OLcfgDbOc", "OLcfgOc:2" },
222 { "OLcfgOvOc", "OLcfgOc:3" },
223 { "OLcfgCtOc", "OLcfgOc:4" }, /* contrib modules */
225 /* Syntaxes. We should just start using the standard names and
226 * document that they are predefined and available for users
227 * to reference in their own schema. Defining schema without
228 * OID macros is for masochists...
230 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
231 { "OMsBoolean", "OMsyn:7" },
232 { "OMsDN", "OMsyn:12" },
233 { "OMsDirectoryString", "OMsyn:15" },
234 { "OMsIA5String", "OMsyn:26" },
235 { "OMsInteger", "OMsyn:27" },
236 { "OMsOID", "OMsyn:38" },
237 { "OMsOctetString", "OMsyn:40" },
242 * Backend/Database registry
244 * OLcfg{Bk|Db}{Oc|At}:0 -> common
245 * OLcfg{Bk|Db}{Oc|At}:1 -> back-bdb(/back-hdb)
246 * OLcfg{Bk|Db}{Oc|At}:2 -> back-ldif
247 * OLcfg{Bk|Db}{Oc|At}:3 -> back-ldap/meta
248 * OLcfg{Bk|Db}{Oc|At}:4 -> back-monitor
249 * OLcfg{Bk|Db}{Oc|At}:5 -> back-relay
250 * OLcfg{Bk|Db}{Oc|At}:6 -> back-sql(/back-ndb)
251 * OLcfg{Bk|Db}{Oc|At}:7 -> back-sock
252 * OLcfg{Bk|Db}{Oc|At}:8 -> back-null
253 * OLcfg{Bk|Db}{Oc|At}:9 -> back-passwd
254 * OLcfg{Bk|Db}{Oc|At}:10 -> back-shell
255 * OLcfg{Bk|Db}{Oc|At}:11 -> back-perl
256 * OLcfg{Bk|Db}{Oc|At}:12 -> back-mdb
262 * OLcfgOv{Oc|At}:1 -> syncprov
263 * OLcfgOv{Oc|At}:2 -> pcache
264 * OLcfgOv{Oc|At}:3 -> chain
265 * OLcfgOv{Oc|At}:4 -> accesslog
266 * OLcfgOv{Oc|At}:5 -> valsort
267 * OLcfgOv{Oc|At}:7 -> distproc
268 * OLcfgOv{Oc|At}:8 -> dynlist
269 * OLcfgOv{Oc|At}:9 -> dds
270 * OLcfgOv{Oc|At}:10 -> unique
271 * OLcfgOv{Oc|At}:11 -> refint
272 * OLcfgOv{Oc|At}:12 -> ppolicy
273 * OLcfgOv{Oc|At}:13 -> constraint
274 * OLcfgOv{Oc|At}:14 -> translucent
275 * OLcfgOv{Oc|At}:15 -> auditlog
276 * OLcfgOv{Oc|At}:16 -> rwm
277 * OLcfgOv{Oc|At}:17 -> dyngroup
278 * OLcfgOv{Oc|At}:18 -> memberof
279 * OLcfgOv{Oc|At}:19 -> collect
280 * OLcfgOv{Oc|At}:20 -> retcode
281 * OLcfgOv{Oc|At}:21 -> sssvlv
284 /* alphabetical ordering */
286 static ConfigTable config_back_cf_table[] = {
287 /* This attr is read-only */
288 { "", "", 0, 0, 0, ARG_MAGIC,
289 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
290 "DESC 'File for slapd configuration directives' "
291 "EQUALITY caseIgnoreMatch "
292 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
293 { "", "", 0, 0, 0, ARG_MAGIC,
294 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
295 "DESC 'Directory for slapd configuration backend' "
296 "EQUALITY caseIgnoreMatch "
297 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
298 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
299 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
300 "DESC 'Access Control List' "
301 "EQUALITY caseIgnoreMatch "
302 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
303 { "add_content_acl", NULL, 0, 0, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_ACL_ADD,
304 &config_generic, "( OLcfgGlAt:86 NAME 'olcAddContentAcl' "
305 "DESC 'Check ACLs against content of Add ops' "
306 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
307 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
308 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
309 "DESC 'Allowed set of deprecated features' "
310 "EQUALITY caseIgnoreMatch "
311 "SYNTAX OMsDirectoryString )", NULL, NULL },
312 { "argsfile", "file", 2, 2, 0, ARG_STRING,
313 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
314 "DESC 'File for slapd command line options' "
315 "EQUALITY caseIgnoreMatch "
316 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
317 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
318 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
319 "EQUALITY caseIgnoreMatch "
320 "SYNTAX OMsDirectoryString )", NULL, NULL },
321 { "attribute", "attribute", 2, 0, STRLENOF( "attribute" ),
322 ARG_PAREN|ARG_MAGIC|CFG_ATTR,
323 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
324 "DESC 'OpenLDAP attributeTypes' "
325 "EQUALITY caseIgnoreMatch "
326 "SUBSTR caseIgnoreSubstringsMatch "
327 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
329 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
330 #ifdef SLAP_AUTH_REWRITE
331 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
335 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
336 "EQUALITY caseIgnoreMatch "
337 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
338 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
339 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
340 "EQUALITY caseIgnoreMatch "
341 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
342 { "authz-regexp", "regexp> <DN", 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
343 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
344 "EQUALITY caseIgnoreMatch "
345 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
346 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
347 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
348 "DESC 'A type of backend' "
349 "EQUALITY caseIgnoreMatch "
350 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
352 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
353 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
354 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
355 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
356 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
357 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
358 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
359 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
360 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
361 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
362 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
363 "DESC 'The backend type for a database instance' "
364 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
365 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
366 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
367 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
368 { "disabled", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_DISABLED,
369 &config_generic, "( OLcfgDbAt:0.21 NAME 'olcDisabled' "
370 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
371 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
372 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
373 "EQUALITY caseIgnoreMatch "
374 "SYNTAX OMsDirectoryString )", NULL, NULL },
375 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
376 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
377 "DESC 'OpenLDAP DIT content rules' "
378 "EQUALITY caseIgnoreMatch "
379 "SUBSTR caseIgnoreSubstringsMatch "
380 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
382 { "extra_attrs", "attrlist", 2, 2, 0, ARG_DB|ARG_MAGIC,
383 &config_extra_attrs, "( OLcfgDbAt:0.20 NAME 'olcExtraAttrs' "
384 "EQUALITY caseIgnoreMatch "
385 "SYNTAX OMsDirectoryString )", NULL, NULL },
386 { "gentlehup", "on|off", 2, 2, 0,
388 ARG_ON_OFF, &global_gentlehup,
392 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
393 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
394 { "hidden", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_HIDDEN,
395 &config_generic, "( OLcfgDbAt:0.17 NAME 'olcHidden' "
396 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
397 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
398 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
399 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
400 { "include", "file", 2, 2, 0, ARG_MAGIC,
401 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
402 "SUP labeledURI )", NULL, NULL },
403 { "index_hash64", "on|off", 2, 2, 0, ARG_ON_OFF|ARG_MAGIC|CFG_IX_HASH64,
404 &config_generic, "( OLcfgGlAt:94 NAME 'olcIndexHash64' "
405 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
406 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
407 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
408 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
409 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
410 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
411 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
412 { "index_substr_any_len", "len", 2, 2, 0, ARG_UINT|ARG_NONZERO,
413 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
414 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
415 { "index_substr_any_step", "step", 2, 2, 0, ARG_UINT|ARG_NONZERO,
416 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
417 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
418 { "index_intlen", "len", 2, 2, 0, ARG_UINT|ARG_MAGIC|CFG_IX_INTLEN,
419 &config_generic, "( OLcfgGlAt:84 NAME 'olcIndexIntLen' "
420 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
421 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
422 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
423 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
424 { "ldapsyntax", "syntax", 2, 0, 0,
425 ARG_PAREN|ARG_MAGIC|CFG_SYNTAX,
426 &config_generic, "( OLcfgGlAt:85 NAME 'olcLdapSyntaxes' "
427 "DESC 'OpenLDAP ldapSyntax' "
428 "EQUALITY caseIgnoreMatch "
429 "SUBSTR caseIgnoreSubstringsMatch "
430 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
432 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
433 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
434 "EQUALITY caseIgnoreMatch "
435 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
436 { "listener-threads", "count", 2, 0, 0,
440 ARG_UINT|ARG_MAGIC|CFG_LTHREADS, &config_generic,
442 "( OLcfgGlAt:93 NAME 'olcListenerThreads' "
443 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
444 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
445 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
446 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
447 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
448 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
449 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
450 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
451 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
452 "EQUALITY caseIgnoreMatch "
453 "SYNTAX OMsDirectoryString )", NULL, NULL },
454 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
455 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
456 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
457 { "mirrormode", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_MIRRORMODE,
458 &config_generic, "( OLcfgDbAt:0.16 NAME 'olcMirrorMode' "
459 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
460 { "moduleload", "file", 2, 0, 0,
462 ARG_MAGIC|CFG_MODLOAD|ARG_NO_DELETE, &config_generic,
466 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
467 "EQUALITY caseIgnoreMatch "
468 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
469 { "modulepath", "path", 2, 2, 0,
471 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
475 "( OLcfgGlAt:31 NAME 'olcModulePath' "
476 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
477 { "monitoring", "TRUE|FALSE", 2, 2, 0,
478 ARG_MAGIC|CFG_MONITORING|ARG_DB|ARG_ON_OFF, &config_generic,
479 "( OLcfgDbAt:0.18 NAME 'olcMonitoring' "
480 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
481 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
482 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
483 "DESC 'OpenLDAP object classes' "
484 "EQUALITY caseIgnoreMatch "
485 "SUBSTR caseIgnoreSubstringsMatch "
486 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
488 { "objectidentifier", "name> <oid", 3, 3, 0, ARG_MAGIC|CFG_OID,
489 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
490 "EQUALITY caseIgnoreMatch "
491 "SUBSTR caseIgnoreSubstringsMatch "
492 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
493 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
494 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
495 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
496 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
497 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
498 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
499 { "password-hash", "hash", 2, 0, 0, ARG_MAGIC,
500 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
501 "EQUALITY caseIgnoreMatch "
502 "SYNTAX OMsDirectoryString )", NULL, NULL },
503 { "pidfile", "file", 2, 2, 0, ARG_STRING,
504 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
505 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
506 { "plugin", NULL, 0, 0, 0,
508 ARG_MAGIC|CFG_PLUGIN, &config_generic,
512 "( OLcfgGlAt:38 NAME 'olcPlugin' "
513 "EQUALITY caseIgnoreMatch "
514 "SYNTAX OMsDirectoryString )", NULL, NULL },
515 { "pluginlog", "filename", 2, 2, 0,
517 ARG_STRING, &slapi_log_file,
521 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
522 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
523 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
524 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
525 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
526 { "referral", "url", 2, 2, 0, ARG_MAGIC,
527 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
528 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
529 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
530 &config_obsolete, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
531 "EQUALITY caseIgnoreMatch "
532 "SUP labeledURI X-ORDERED 'VALUES' )", NULL, NULL },
533 { "replica-argsfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
534 &config_obsolete, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
535 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
536 { "replica-pidfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
537 &config_obsolete, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
538 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
539 { "replicationInterval", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
540 &config_obsolete, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
541 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
542 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC,
543 &config_obsolete, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
544 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
545 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
546 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
547 "EQUALITY caseIgnoreMatch "
548 "SYNTAX OMsDirectoryString )", NULL, NULL },
549 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
550 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
551 "EQUALITY caseIgnoreMatch "
552 "SYNTAX OMsDirectoryString )", NULL, NULL },
553 { "reverse-lookup", "on|off", 2, 2, 0,
554 #ifdef SLAPD_RLOOKUPS
555 ARG_ON_OFF, &use_reverse_lookup,
559 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
560 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
561 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
562 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
563 "EQUALITY distinguishedNameMatch "
564 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
565 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
566 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
567 "EQUALITY caseIgnoreMatch "
568 "SYNTAX OMsDirectoryString )", NULL, NULL },
569 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
570 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
571 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
572 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
573 &config_generic, NULL, NULL, NULL },
574 { "sasl-auxprops", NULL, 2, 0, 0,
575 #ifdef HAVE_CYRUS_SASL
576 ARG_STRING|ARG_UNIQUE, &slap_sasl_auxprops,
580 "( OLcfgGlAt:89 NAME 'olcSaslAuxprops' "
581 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
582 { "sasl-auxprops-dontusecopy", NULL, 2, 0, 0,
583 #if defined(HAVE_CYRUS_SASL) && defined(SLAP_AUXPROP_DONTUSECOPY)
584 ARG_MAGIC|CFG_AZDUC, &config_generic,
588 "( OLcfgGlAt:91 NAME 'olcSaslAuxpropsDontUseCopy' "
589 "EQUALITY caseIgnoreMatch "
590 "SYNTAX OMsDirectoryString )", NULL, NULL },
591 { "sasl-auxprops-dontusecopy-ignore", "true|FALSE", 2, 0, 0,
592 #if defined(HAVE_CYRUS_SASL) && defined(SLAP_AUXPROP_DONTUSECOPY)
593 ARG_ON_OFF|CFG_AZDUC_IGNORE, &slap_dontUseCopy_ignore,
597 "( OLcfgGlAt:92 NAME 'olcSaslAuxpropsDontUseCopyIgnore' "
598 "EQUALITY booleanMatch "
599 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
600 { "sasl-host", "host", 2, 2, 0,
601 #ifdef HAVE_CYRUS_SASL
602 ARG_STRING|ARG_UNIQUE, &sasl_host,
606 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
607 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
608 { "sasl-realm", "realm", 2, 2, 0,
609 #ifdef HAVE_CYRUS_SASL
610 ARG_STRING|ARG_UNIQUE, &global_realm,
614 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
615 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
616 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
617 &config_generic, NULL, NULL, NULL },
618 { "sasl-secprops", "properties", 2, 2, 0,
619 #ifdef HAVE_CYRUS_SASL
620 ARG_MAGIC|CFG_SASLSECP, &config_generic,
624 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
625 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
626 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
627 &config_generic, NULL, NULL, NULL },
628 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
629 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
630 "EQUALITY distinguishedNameMatch "
631 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
632 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
633 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
634 "EQUALITY caseIgnoreMatch "
635 "SYNTAX OMsDirectoryString )", NULL, NULL },
636 { "serverID", "number> <[URI]", 2, 3, 0, ARG_MAGIC|CFG_SERVERID,
637 &config_generic, "( OLcfgGlAt:81 NAME 'olcServerID' "
638 "EQUALITY caseIgnoreMatch "
639 "SYNTAX OMsDirectoryString )", NULL, NULL },
640 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
641 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
642 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
643 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
644 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
645 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
646 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
647 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
648 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
649 { "sortvals", "attr", 2, 0, 0, ARG_MAGIC|CFG_SORTVALS,
650 &config_generic, "( OLcfgGlAt:83 NAME 'olcSortVals' "
651 "DESC 'Attributes whose values will always be sorted' "
652 "EQUALITY caseIgnoreMatch "
653 "SYNTAX OMsDirectoryString )", NULL, NULL },
654 { "subordinate", "[advertise]", 1, 2, 0, ARG_DB|ARG_MAGIC,
655 &config_subordinate, "( OLcfgDbAt:0.15 NAME 'olcSubordinate' "
656 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
657 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
658 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
659 "EQUALITY distinguishedNameMatch "
660 "SYNTAX OMsDN )", NULL, NULL },
661 { "sync_use_subentry", NULL, 0, 0, 0, ARG_ON_OFF|ARG_DB|ARG_MAGIC|CFG_SYNC_SUBENTRY,
662 &config_generic, "( OLcfgDbAt:0.19 NAME 'olcSyncUseSubentry' "
663 "DESC 'Store sync context in a subentry' "
664 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
665 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
666 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
667 "EQUALITY caseIgnoreMatch "
668 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
669 { "tcp-buffer", "[listener=<listener>] [{read|write}=]size", 0, 0, 0,
670 #ifndef LDAP_TCP_BUFFER
672 #else /* LDAP_TCP_BUFFER */
673 ARG_MAGIC, &config_tcp_buffer,
674 #endif /* LDAP_TCP_BUFFER */
675 "( OLcfgGlAt:90 NAME 'olcTCPBuffer' "
676 "DESC 'Custom TCP buffer size' "
677 "SYNTAX OMsDirectoryString )", NULL, NULL },
678 { "threads", "count", 2, 2, 0,
682 ARG_INT|ARG_MAGIC|CFG_THREADS, &config_generic,
684 "( OLcfgGlAt:66 NAME 'olcThreads' "
685 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
686 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
687 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
688 "SYNTAX OMsDirectoryString )", NULL, NULL },
689 { "TLSCACertificateFile", NULL, 2, 2, 0,
691 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
695 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
696 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
697 { "TLSCACertificatePath", NULL, 2, 2, 0,
699 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
703 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
704 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
705 { "TLSCertificateFile", NULL, 2, 2, 0,
707 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
711 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
712 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
713 { "TLSCertificateKeyFile", NULL, 2, 2, 0,
715 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
719 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
720 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
721 { "TLSCipherSuite", NULL, 2, 2, 0,
723 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
727 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
728 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
729 { "TLSCRLCheck", NULL, 2, 2, 0,
730 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
731 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
735 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
736 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
737 { "TLSCRLFile", NULL, 2, 2, 0,
738 #if defined(HAVE_GNUTLS)
739 CFG_TLS_CRL_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
743 "( OLcfgGlAt:82 NAME 'olcTLSCRLFile' "
744 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
745 { "TLSRandFile", NULL, 2, 2, 0,
747 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
751 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
752 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
753 { "TLSVerifyClient", NULL, 2, 2, 0,
755 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
759 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
760 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
761 { "TLSDHParamFile", NULL, 2, 2, 0,
763 CFG_TLS_DH_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
767 "( OLcfgGlAt:77 NAME 'olcTLSDHParamFile' "
768 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
769 { "TLSProtocolMin", NULL, 2, 2, 0,
771 CFG_TLS_PROTOCOL_MIN|ARG_STRING|ARG_MAGIC, &config_tls_config,
775 "( OLcfgGlAt:87 NAME 'olcTLSProtocolMin' "
776 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
777 { "tool-threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_TTHREADS,
778 &config_generic, "( OLcfgGlAt:80 NAME 'olcToolThreads' "
779 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
780 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
781 NULL, NULL, NULL, NULL },
782 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
783 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
784 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
785 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
786 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
787 "EQUALITY caseIgnoreMatch "
788 "SUP labeledURI )", NULL, NULL },
789 { "writetimeout", "timeout", 2, 2, 0, ARG_INT,
790 &global_writetimeout, "( OLcfgGlAt:88 NAME 'olcWriteTimeout' "
791 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
792 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
793 NULL, NULL, NULL, NULL }
796 /* Need to no-op this keyword for dynamic config */
797 ConfigTable olcDatabaseDummy[] = {
798 { "", "", 0, 0, 0, ARG_IGNORED,
799 NULL, "( OLcfgGlAt:13 NAME 'olcDatabase' "
800 "DESC 'The backend type for a database instance' "
801 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
802 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
805 /* Routines to check if a child can be added to this type */
806 static ConfigLDAPadd cfAddSchema, cfAddInclude, cfAddDatabase,
807 cfAddBackend, cfAddModule, cfAddOverlay;
809 /* NOTE: be careful when defining array members
810 * that can be conditionally compiled */
811 #define CFOC_GLOBAL cf_ocs[1]
812 #define CFOC_SCHEMA cf_ocs[2]
813 #define CFOC_BACKEND cf_ocs[3]
814 #define CFOC_DATABASE cf_ocs[4]
815 #define CFOC_OVERLAY cf_ocs[5]
816 #define CFOC_INCLUDE cf_ocs[6]
817 #define CFOC_FRONTEND cf_ocs[7]
819 #define CFOC_MODULE cf_ocs[8]
820 #endif /* SLAPD_MODULES */
822 static ConfigOCs cf_ocs[] = {
825 "DESC 'OpenLDAP configuration object' "
826 "ABSTRACT SUP top )", Cft_Abstract, NULL },
829 "DESC 'OpenLDAP Global configuration options' "
830 "SUP olcConfig STRUCTURAL "
831 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
832 "olcAttributeOptions $ olcAuthIDRewrite $ "
833 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
834 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
835 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
836 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
837 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcIndexHash64 $ "
838 "olcIndexIntLen $ olcLocalSSF $ olcLogFile $ olcLogLevel $ "
839 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
840 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
841 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
843 "olcSaslAuxprops $ olcSaslAuxpropsDontUseCopy $ olcSaslAuxpropsDontUseCopyIgnore $ "
844 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
845 "olcSecurity $ olcServerID $ olcSizeLimit $ "
846 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ "
848 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
849 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
850 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
851 "olcTLSRandFile $ olcTLSVerifyClient $ olcTLSDHParamFile $ "
852 "olcTLSCRLFile $ olcToolThreads $ olcWriteTimeout $ "
853 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
854 "olcDitContentRules $ olcLdapSyntaxes ) )", Cft_Global },
856 "NAME 'olcSchemaConfig' "
857 "DESC 'OpenLDAP schema object' "
858 "SUP olcConfig STRUCTURAL "
859 "MAY ( cn $ olcObjectIdentifier $ olcLdapSyntaxes $ "
860 "olcAttributeTypes $ olcObjectClasses $ olcDitContentRules ) )",
861 Cft_Schema, NULL, cfAddSchema },
863 "NAME 'olcBackendConfig' "
864 "DESC 'OpenLDAP Backend-specific options' "
865 "SUP olcConfig STRUCTURAL "
866 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
868 "NAME 'olcDatabaseConfig' "
869 "DESC 'OpenLDAP Database-specific options' "
870 "SUP olcConfig STRUCTURAL "
872 "MAY ( olcDisabled $ olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
873 "olcAddContentAcl $ olcLastMod $ olcLimits $ "
874 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
875 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
876 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
877 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncUseSubentry $ olcSyncrepl $ "
878 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef $ olcMirrorMode $ "
879 "olcMonitoring $ olcExtraAttrs ) )",
880 Cft_Database, NULL, cfAddDatabase },
882 "NAME 'olcOverlayConfig' "
883 "DESC 'OpenLDAP Overlay-specific options' "
884 "SUP olcConfig STRUCTURAL "
886 "MAY olcDisabled )", Cft_Overlay, NULL, cfAddOverlay },
888 "NAME 'olcIncludeFile' "
889 "DESC 'OpenLDAP configuration include file' "
890 "SUP olcConfig STRUCTURAL "
892 "MAY ( cn $ olcRootDSE ) )",
893 /* Used to be Cft_Include, that def has been removed */
894 Cft_Abstract, NULL, cfAddInclude },
895 /* This should be STRUCTURAL like all the other database classes, but
896 * that would mean inheriting all of the olcDatabaseConfig attributes,
897 * which causes them to be merged twice in config_build_entry.
900 "NAME 'olcFrontendConfig' "
901 "DESC 'OpenLDAP frontend configuration' "
903 "MAY ( olcDefaultSearchBase $ olcPasswordHash $ olcSortVals ) )",
904 Cft_Database, NULL, NULL },
907 "NAME 'olcModuleList' "
908 "DESC 'OpenLDAP dynamic module info' "
909 "SUP olcConfig STRUCTURAL "
910 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
911 Cft_Module, NULL, cfAddModule },
916 typedef struct ServerID {
917 struct ServerID *si_next;
918 struct berval si_url;
922 static ServerID *sid_list;
923 static ServerID *sid_set;
925 typedef struct voidList {
926 struct voidList *vl_next;
930 typedef struct ADlist {
931 struct ADlist *al_next;
932 AttributeDescription *al_desc;
935 static ADlist *sortVals;
938 config_generic(ConfigArgs *c) {
941 if ( c->op == SLAP_CONFIG_EMIT ) {
945 c->value_int = ldap_pvt_thread_get_concurrency();
948 c->value_int = connection_pool_max;
951 c->value_int = slap_tool_thread_max;
954 c->value_uint = slapd_daemon_threads;
958 c->value_string = ch_strdup( passwd_salt );
963 if ( c->be->be_limits ) {
967 for ( i=0; c->be->be_limits[i]; i++ ) {
968 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
969 if ( bv.bv_len >= sizeof( buf ) ) {
970 ber_bvarray_free_x( c->rvalue_vals, NULL );
971 c->rvalue_vals = NULL;
975 bv.bv_val = buf + bv.bv_len;
976 limits_unparse( c->be->be_limits[i], &bv,
977 sizeof( buf ) - ( bv.bv_val - buf ) );
978 bv.bv_len += bv.bv_val - buf;
980 value_add_one( &c->rvalue_vals, &bv );
983 if ( !c->rvalue_vals ) rc = 1;
986 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_READONLY);
989 c->value_string = ch_strdup( slap_sasl_getpolicy());
992 slap_sasl_regexp_unparse( &c->rvalue_vals );
993 if ( !c->rvalue_vals ) rc = 1;
995 #ifdef HAVE_CYRUS_SASL
996 #ifdef SLAP_AUXPROP_DONTUSECOPY
998 static int duc_done = 0;
1000 /* take the opportunity to initialize with known values */
1002 struct berval duc[] = { BER_BVC("cmusaslsecretOTP"), BER_BVNULL };
1005 for ( i = 0; !BER_BVISNULL( &duc[ i ] ); i++ ) {
1006 const char *text = NULL;
1007 AttributeDescription *ad = NULL;
1009 if ( slap_bv2ad( &duc[ i ], &ad, &text ) == LDAP_SUCCESS ) {
1011 if ( slap_dontUseCopy_propnames ) {
1014 for ( j = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ j ] ); j++ ) {
1015 if ( bvmatch( &slap_dontUseCopy_propnames[ j ], &ad->ad_cname ) ) {
1022 value_add_one( &slap_dontUseCopy_propnames, &ad->ad_cname );
1030 if ( slap_dontUseCopy_propnames != NULL ) {
1031 ber_bvarray_dup_x( &c->rvalue_vals, slap_dontUseCopy_propnames, NULL );
1036 #endif /* SLAP_AUXPROP_DONTUSECOPY */
1037 case CFG_SASLSECP: {
1038 struct berval bv = BER_BVNULL;
1039 slap_sasl_secprops_unparse( &bv );
1040 if ( !BER_BVISNULL( &bv )) {
1041 ber_bvarray_add( &c->rvalue_vals, &bv );
1049 c->value_int = c->be->be_max_deref_depth;
1054 if ( c->bi->bi_flags & SLAPO_BFLAG_DISABLED ) {
1061 if ( SLAP_DBDISABLED( c->be )) {
1069 if ( SLAP_DBHIDDEN( c->be )) {
1076 ConfigFile *cf = c->ca_private;
1078 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1079 else if ( cf->c_om_head )
1080 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
1082 if ( !c->rvalue_vals )
1087 ad_unparse_options( &c->rvalue_vals );
1090 ConfigFile *cf = c->ca_private;
1092 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1093 else if ( cf->c_oc_head )
1094 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
1096 if ( !c->rvalue_vals )
1101 ConfigFile *cf = c->ca_private;
1103 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1104 else if ( cf->c_at_head )
1105 at_unparse( &c->rvalue_vals, cf->c_at_head,
1107 if ( !c->rvalue_vals )
1112 ConfigFile *cf = c->ca_private;
1114 syn_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1115 else if ( cf->c_syn_head )
1116 syn_unparse( &c->rvalue_vals, cf->c_syn_head,
1117 cf->c_syn_tail, 0 );
1118 if ( !c->rvalue_vals )
1123 ConfigFile *cf = c->ca_private;
1125 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1126 else if ( cf->c_cr_head )
1127 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
1129 if ( !c->rvalue_vals )
1136 char *src, *dst, ibuf[11];
1137 struct berval bv, abv;
1138 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
1139 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1140 if ( abv.bv_len >= sizeof( ibuf ) ) {
1141 ber_bvarray_free_x( c->rvalue_vals, NULL );
1142 c->rvalue_vals = NULL;
1146 acl_unparse( a, &bv );
1147 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
1148 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
1149 /* Turn TAB / EOL into plain space */
1150 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
1151 if (isspace((unsigned char)*src)) *dst++ = ' ';
1155 if (dst[-1] == ' ') {
1159 abv.bv_len = dst - abv.bv_val;
1160 ber_bvarray_add( &c->rvalue_vals, &abv );
1166 c->value_int = (SLAP_DBACL_ADD(c->be) != 0);
1169 ConfigFile *cf = c->ca_private;
1170 if ( cf->c_dseFiles ) {
1171 value_add( &c->rvalue_vals, cf->c_dseFiles );
1182 for ( si = sid_list; si; si=si->si_next ) {
1183 assert( si->si_num >= 0 && si->si_num <= SLAP_SYNC_SID_MAX );
1184 if ( !BER_BVISEMPTY( &si->si_url )) {
1185 bv.bv_len = si->si_url.bv_len + 6;
1186 bv.bv_val = ch_malloc( bv.bv_len );
1187 bv.bv_len = sprintf( bv.bv_val, "%d %s", si->si_num,
1188 si->si_url.bv_val );
1189 ber_bvarray_add( &c->rvalue_vals, &bv );
1193 bv.bv_len = sprintf( buf, "%d", si->si_num );
1194 value_add_one( &c->rvalue_vals, &bv );
1203 c->value_string = ch_strdup( logfileName );
1208 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1210 case CFG_SYNC_SUBENTRY:
1211 c->value_int = (SLAP_SYNC_SUBENTRY(c->be) != 0);
1213 case CFG_MIRRORMODE:
1214 if ( SLAP_SHADOW(c->be))
1215 c->value_int = (SLAP_MULTIMASTER(c->be) != 0);
1219 case CFG_MONITORING:
1220 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
1222 case CFG_SSTR_IF_MAX:
1223 c->value_uint = index_substr_if_maxlen;
1225 case CFG_SSTR_IF_MIN:
1226 c->value_uint = index_substr_if_minlen;
1229 c->value_int = slap_hash64( -1 );
1232 c->value_int = index_intlen;
1234 case CFG_SORTVALS: {
1237 for ( sv = sortVals; sv; sv = sv->al_next ) {
1238 value_add_one( &c->rvalue_vals, &sv->al_desc->ad_cname );
1242 #ifdef SLAPD_MODULES
1244 ModPaths *mp = c->ca_private;
1247 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
1250 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
1251 SLAP_X_ORDERED_FMT "%s", i,
1252 mp->mp_loads[i].bv_val );
1253 if ( bv.bv_len >= sizeof( c->log ) ) {
1254 ber_bvarray_free_x( c->rvalue_vals, NULL );
1255 c->rvalue_vals = NULL;
1258 value_add_one( &c->rvalue_vals, &bv );
1262 rc = c->rvalue_vals ? 0 : 1;
1266 ModPaths *mp = c->ca_private;
1267 if ( !BER_BVISNULL( &mp->mp_path ))
1268 value_add_one( &c->rvalue_vals, &mp->mp_path );
1270 rc = c->rvalue_vals ? 0 : 1;
1276 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1277 if ( !c->rvalue_vals ) rc = 1;
1280 #ifdef SLAP_AUTH_REWRITE
1282 if ( authz_rewrites ) {
1283 struct berval bv, idx;
1288 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1289 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1290 if ( idx.bv_len >= sizeof( ibuf ) ) {
1291 ber_bvarray_free_x( c->rvalue_vals, NULL );
1292 c->rvalue_vals = NULL;
1295 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1296 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1297 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1298 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1299 authz_rewrites[i].bv_val,
1300 authz_rewrites[i].bv_len + 1 );
1301 ber_bvarray_add( &c->rvalue_vals, &bv );
1304 if ( !c->rvalue_vals ) rc = 1;
1311 } else if ( c->op == LDAP_MOD_DELETE ) {
1314 /* single-valued attrs, no-ops */
1323 case CFG_MONITORING:
1325 case CFG_SSTR_IF_MAX:
1326 case CFG_SSTR_IF_MIN:
1328 case CFG_SYNC_SUBENTRY:
1331 /* no-ops, requires slapd restart */
1336 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1339 case CFG_MIRRORMODE:
1340 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MULTI_SHADOW;
1341 if(SLAP_SHADOW(c->be))
1342 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1345 #if defined(HAVE_CYRUS_SASL) && defined(SLAP_AUXPROP_DONTUSECOPY)
1347 if ( c->valx < 0 ) {
1348 if ( slap_dontUseCopy_propnames != NULL ) {
1349 ber_bvarray_free( slap_dontUseCopy_propnames );
1350 slap_dontUseCopy_propnames = NULL;
1356 if ( slap_dontUseCopy_propnames == NULL ) {
1361 for ( i = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ i ] ) && i < c->valx; i++ );
1362 if ( i < c->valx ) {
1366 ber_memfree( slap_dontUseCopy_propnames[ i ].bv_val );
1367 for ( ; !BER_BVISNULL( &slap_dontUseCopy_propnames[ i + 1 ] ); i++ ) {
1368 slap_dontUseCopy_propnames[ i ] = slap_dontUseCopy_propnames[ i + 1 ];
1370 BER_BVZERO( &slap_dontUseCopy_propnames[ i ] );
1373 #endif /* SLAP_AUXPROP_DONTUSECOPY */
1375 ch_free( passwd_salt );
1380 ch_free( logfileName );
1388 case CFG_SERVERID: {
1389 ServerID *si, **sip;
1391 for ( i=0, si = sid_list, sip = &sid_list;
1392 si; si = *sip, i++ ) {
1393 if ( c->valx == -1 || i == c->valx ) {
1395 if ( sid_set == si )
1407 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1412 c->bi->bi_flags &= ~SLAP_DBFLAG_DISABLED;
1413 if ( c->bi->bi_db_open ) {
1414 BackendInfo *bi_orig = c->be->bd_info;
1415 c->be->bd_info = c->bi;
1416 rc = c->bi->bi_db_open( c->be, &c->reply );
1417 c->be->bd_info = bi_orig;
1420 c->be->be_flags &= ~SLAP_DBFLAG_DISABLED;
1421 rc = backend_startup_one( c->be, &c->reply );
1430 index_intlen = SLAP_INDEX_INTLEN_DEFAULT;
1431 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1432 SLAP_INDEX_INTLEN_DEFAULT );
1436 if ( c->valx < 0 ) {
1437 acl_destroy( c->be->be_acl );
1438 c->be->be_acl = NULL;
1441 AccessControl **prev, *a;
1443 for (i=0, prev = &c->be->be_acl; i < c->valx;
1446 prev = &a->acl_next;
1449 *prev = a->acl_next;
1452 if ( SLAP_CONFIG( c->be ) && !c->be->be_acl ) {
1453 Debug( LDAP_DEBUG_CONFIG, "config_generic (CFG_ACL): "
1454 "Last explicit ACL for back-config removed. "
1455 "Using hardcoded default\n", 0, 0, 0 );
1456 c->be->be_acl = defacl_parsed;
1462 /* Can be NULL when undoing a failed add */
1463 if ( c->ca_entry ) {
1464 ce = c->ca_entry->e_private;
1465 /* can't modify the hardcoded schema */
1466 if ( ce->ce_parent->ce_type == Cft_Global )
1470 cfn = c->ca_private;
1471 if ( c->valx < 0 ) {
1474 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1476 if ( oc == cfn->c_oc_tail )
1479 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1481 ObjectClass *oc, *prev = NULL;
1483 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1488 if ( cfn->c_oc_tail == oc ) {
1489 cfn->c_oc_tail = prev;
1491 if ( cfn->c_oc_head == oc ) {
1493 cfn->c_oc_head = oc;
1500 /* Can be NULL when undoing a failed add */
1501 if ( c->ca_entry ) {
1502 ce = c->ca_entry->e_private;
1503 /* can't modify the hardcoded schema */
1504 if ( ce->ce_parent->ce_type == Cft_Global )
1508 cfn = c->ca_private;
1509 if ( c->valx < 0 ) {
1512 for( at = cfn->c_at_head; at; at_next( &at )) {
1514 if ( at == cfn->c_at_tail )
1517 cfn->c_at_head = cfn->c_at_tail = NULL;
1519 AttributeType *at, *prev = NULL;
1521 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1526 if ( cfn->c_at_tail == at ) {
1527 cfn->c_at_tail = prev;
1529 if ( cfn->c_at_head == at ) {
1531 cfn->c_at_head = at;
1538 /* Can be NULL when undoing a failed add */
1539 if ( c->ca_entry ) {
1540 ce = c->ca_entry->e_private;
1541 /* can't modify the hardcoded schema */
1542 if ( ce->ce_parent->ce_type == Cft_Global )
1546 cfn = c->ca_private;
1547 if ( c->valx < 0 ) {
1550 for( syn = cfn->c_syn_head; syn; syn_next( &syn )) {
1552 if ( syn == cfn->c_syn_tail )
1555 cfn->c_syn_head = cfn->c_syn_tail = NULL;
1557 Syntax *syn, *prev = NULL;
1559 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++) {
1564 if ( cfn->c_syn_tail == syn ) {
1565 cfn->c_syn_tail = prev;
1567 if ( cfn->c_syn_head == syn ) {
1569 cfn->c_syn_head = syn;
1574 if ( c->valx < 0 ) {
1576 for ( sv = sortVals; sv; sv = sortVals ) {
1577 sortVals = sv->al_next;
1578 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1585 for ( prev = &sortVals, sv = sortVals; i < c->valx; i++ ) {
1586 prev = &sv->al_next;
1589 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1590 *prev = sv->al_next;
1596 /* FIXME: there is no limits_free function */
1597 if ( c->valx < 0 ) {
1598 limits_destroy( c->be->be_limits );
1599 c->be->be_limits = NULL;
1604 if ( c->be->be_limits ) {
1605 for ( num = 0; c->be->be_limits[ num ]; num++ )
1609 if ( c->valx >= num ) {
1614 limits_destroy( c->be->be_limits );
1615 c->be->be_limits = NULL;
1618 limits_free_one( c->be->be_limits[ c->valx ] );
1620 for ( cnt = c->valx; cnt < num; cnt++ ) {
1621 c->be->be_limits[ cnt ] = c->be->be_limits[ cnt + 1 ];
1628 /* FIXME: there is no ad_option_free function */
1630 /* FIXME: there is no way to remove attributes added by
1644 if(!(c->bi = backend_info(c->argv[1]))) {
1645 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1646 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1647 c->log, c->cr_msg, c->argv[1] );
1654 /* NOTE: config is always the first backend!
1656 if ( !strcasecmp( c->argv[1], "config" )) {
1657 c->be = LDAP_STAILQ_FIRST(&backendDB);
1658 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1661 c->be = backend_db_init(c->argv[1], NULL, c->valx, &c->reply);
1663 if ( c->cr_msg[0] == 0 )
1664 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1665 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n", c->log, c->cr_msg, c->argv[1] );
1672 ldap_pvt_thread_set_concurrency(c->value_int);
1676 if ( c->value_int < 2 ) {
1677 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1678 "threads=%d smaller than minimum value 2",
1680 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1681 c->log, c->cr_msg, 0 );
1684 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1685 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1686 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1687 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1688 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1689 c->log, c->cr_msg, 0 );
1691 if ( slapMode & SLAP_SERVER_MODE )
1692 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1693 connection_pool_max = c->value_int; /* save for reference */
1697 if ( slapMode & SLAP_TOOL_MODE )
1698 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1699 slap_tool_thread_max = c->value_int; /* save for reference */
1704 /* use a power of two */
1705 while (c->value_uint > 1) {
1706 c->value_uint >>= 1;
1710 slapd_daemon_mask = mask;
1711 slapd_daemon_threads = mask+1;
1716 if ( passwd_salt ) ch_free( passwd_salt );
1717 passwd_salt = c->value_string;
1718 lutil_salt_format(passwd_salt);
1722 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1728 c->be->be_restrictops |= SLAP_RESTRICT_READONLY;
1730 c->be->be_restrictops &= ~SLAP_RESTRICT_READONLY;
1734 ch_free(c->value_string);
1735 if (slap_sasl_setpolicy( c->argv[1] )) {
1736 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
1737 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1738 c->log, c->cr_msg, c->argv[1] );
1744 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1748 #ifdef HAVE_CYRUS_SASL
1749 #ifdef SLAP_AUXPROP_DONTUSECOPY
1753 for ( arg = 1; arg < c->argc; arg++ ) {
1754 int duplicate = 0, err;
1755 AttributeDescription *ad = NULL;
1756 const char *text = NULL;
1758 err = slap_str2ad( c->argv[ arg ], &ad, &text );
1759 if ( err != LDAP_SUCCESS ) {
1760 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s>: attr #%d (\"%s\") unknown (err=%d \"%s\"; ignored)",
1761 c->argv[0], arg, c->argv[ arg ], err, text );
1762 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1763 c->log, c->cr_msg, 0 );
1766 if ( slap_dontUseCopy_propnames != NULL ) {
1767 for ( cnt = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ cnt ] ); cnt++ ) {
1768 if ( bvmatch( &slap_dontUseCopy_propnames[ cnt ], &ad->ad_cname ) ) {
1776 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s>: attr #%d (\"%s\") already defined (ignored)",
1777 c->argv[0], arg, ad->ad_cname.bv_val);
1778 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1779 c->log, c->cr_msg, 0 );
1783 value_add_one( &slap_dontUseCopy_propnames, &ad->ad_cname );
1788 #endif /* SLAP_AUXPROP_DONTUSECOPY */
1792 char *txt = slap_sasl_secprops( c->argv[1] );
1794 snprintf( c->cr_msg, sizeof(c->cr_msg), "<%s> %s",
1796 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0 );
1804 c->be->be_max_deref_depth = c->value_int;
1810 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1811 cfn = c->ca_private;
1812 if(parse_oidm(c, 1, &om))
1814 if (!cfn->c_om_head) cfn->c_om_head = om;
1815 cfn->c_om_tail = om;
1820 ObjectClass *oc, *prev;
1822 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1823 cfn = c->ca_private;
1824 if ( c->valx < 0 ) {
1825 prev = cfn->c_oc_tail;
1828 /* If adding anything after the first, prev is easy */
1831 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
1833 if ( !oc_next( &oc ))
1837 /* If adding the first, and head exists, find its prev */
1838 if (cfn->c_oc_head) {
1839 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
1844 /* else prev is NULL, append to end of global list */
1846 if(parse_oc(c, &oc, prev)) return(1);
1847 if (!cfn->c_oc_head || !c->valx) cfn->c_oc_head = oc;
1848 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
1853 AttributeType *at, *prev;
1855 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1856 cfn = c->ca_private;
1857 if ( c->valx < 0 ) {
1858 prev = cfn->c_at_tail;
1861 /* If adding anything after the first, prev is easy */
1864 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
1866 if ( !at_next( &at ))
1870 /* If adding the first, and head exists, find its prev */
1871 if (cfn->c_at_head) {
1872 for ( at_start( &at ); at != cfn->c_at_head; ) {
1877 /* else prev is NULL, append to end of global list */
1879 if(parse_at(c, &at, prev)) return(1);
1880 if (!cfn->c_at_head || !c->valx) cfn->c_at_head = at;
1881 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
1888 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1889 cfn = c->ca_private;
1890 if ( c->valx < 0 ) {
1891 prev = cfn->c_syn_tail;
1894 /* If adding anything after the first, prev is easy */
1897 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++ ) {
1899 if ( !syn_next( &syn ))
1903 /* If adding the first, and head exists, find its prev */
1904 if (cfn->c_syn_head) {
1905 for ( syn_start( &syn ); syn != cfn->c_syn_head; ) {
1910 /* else prev is NULL, append to end of global list */
1912 if ( parse_syn( c, &syn, prev ) ) return(1);
1913 if ( !cfn->c_syn_head || !c->valx ) cfn->c_syn_head = syn;
1914 if ( cfn->c_syn_tail == prev ) cfn->c_syn_tail = syn;
1921 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1922 cfn = c->ca_private;
1923 if(parse_cr(c, &cr)) return(1);
1924 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1925 cfn->c_cr_tail = cr;
1930 ad_define_option(NULL, NULL, 0);
1931 for(i = 1; i < c->argc; i++)
1932 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1937 if ( slap_hash64( c->value_int != 0 ))
1942 if ( c->value_int < SLAP_INDEX_INTLEN_DEFAULT )
1943 c->value_int = SLAP_INDEX_INTLEN_DEFAULT;
1944 else if ( c->value_int > 255 )
1946 index_intlen = c->value_int;
1947 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1951 case CFG_SORTVALS: {
1952 ADlist *svnew = NULL, *svtail, *sv;
1954 for ( i = 1; i < c->argc; i++ ) {
1955 AttributeDescription *ad = NULL;
1959 rc = slap_str2ad( c->argv[i], &ad, &text );
1961 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown attribute type #%d",
1964 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1965 c->log, c->cr_msg, c->argv[i] );
1966 for ( sv = svnew; sv; sv = svnew ) {
1967 svnew = sv->al_next;
1972 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) ||
1973 ad->ad_type->sat_single_value ) {
1974 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> inappropriate attribute type #%d",
1976 goto sortval_reject;
1978 sv = ch_malloc( sizeof( ADlist ));
1983 svtail->al_next = sv;
1988 for ( sv = svnew; sv; sv = sv->al_next )
1989 sv->al_desc->ad_type->sat_flags |= SLAP_AT_SORTED_VAL;
1990 for ( sv = sortVals; sv && sv->al_next; sv = sv->al_next );
1992 sv->al_next = svnew;
1999 if ( SLAP_CONFIG( c->be ) && c->be->be_acl == defacl_parsed) {
2000 c->be->be_acl = NULL;
2002 /* Don't append to the global ACL if we're on a specific DB */
2004 if ( c->valx == -1 ) {
2007 for ( a=c->be->be_acl; a; a = a->acl_next )
2010 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
2011 if ( SLAP_CONFIG( c->be ) && !c->be->be_acl) {
2012 c->be->be_acl = defacl_parsed;
2020 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_ACL_ADD;
2022 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_ACL_ADD;
2026 if(root_dse_read_file(c->argv[1])) {
2027 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> could not read file", c->argv[0] );
2028 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2029 c->log, c->cr_msg, c->argv[1] );
2034 ber_str2bv( c->argv[1], 0, 1, &bv );
2035 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
2036 cfn = c->ca_private;
2037 ber_bvarray_add( &cfn->c_dseFiles, &bv );
2043 ServerID *si, **sip;
2046 if (( lutil_atoi( &num, c->argv[1] ) &&
2047 lutil_atoix( &num, c->argv[1], 16 )) ||
2048 num < 0 || num > SLAP_SYNC_SID_MAX )
2050 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2051 "<%s> illegal server ID", c->argv[0] );
2052 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2053 c->log, c->cr_msg, c->argv[1] );
2056 /* only one value allowed if no URL is given */
2057 if ( c->argc > 2 ) {
2060 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
2061 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2062 "<%s> only one server ID allowed now", c->argv[0] );
2063 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2064 c->log, c->cr_msg, c->argv[1] );
2068 if ( ldap_url_parse( c->argv[2], &lud )) {
2069 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2070 "<%s> invalid URL", c->argv[0] );
2071 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2072 c->log, c->cr_msg, c->argv[2] );
2075 len = strlen( c->argv[2] );
2076 si = ch_malloc( sizeof(ServerID) + len + 1 );
2077 si->si_url.bv_val = (char *)(si+1);
2078 si->si_url.bv_len = len;
2079 strcpy( si->si_url.bv_val, c->argv[2] );
2082 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2083 "<%s> unqualified server ID not allowed now", c->argv[0] );
2084 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2085 c->log, c->cr_msg, c->argv[1] );
2088 si = ch_malloc( sizeof(ServerID) );
2089 BER_BVZERO( &si->si_url );
2090 slap_serverID = num;
2091 Debug( LDAP_DEBUG_CONFIG,
2093 c->log, slap_serverID, 0 );
2098 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
2101 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
2102 Listener *l = config_check_my_url( c->argv[2], lud );
2105 ldap_free_urldesc( lud );
2106 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2107 "<%s> multiple server ID URLs matched, only one is allowed", c->argv[0] );
2108 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2109 c->log, c->cr_msg, c->argv[1] );
2112 slap_serverID = si->si_num;
2113 Debug( LDAP_DEBUG_CONFIG,
2114 "%s: SID=0x%03x (listener=%s)\n",
2115 c->log, slap_serverID,
2121 ldap_free_urldesc( lud );
2125 if ( logfileName ) ch_free( logfileName );
2126 logfileName = c->value_string;
2127 logfile = fopen(logfileName, "w");
2128 if(logfile) lutil_debug_file(logfile);
2132 if(SLAP_NOLASTMODCMD(c->be)) {
2133 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> not available for %s database",
2134 c->argv[0], c->be->bd_info->bi_type );
2135 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2136 c->log, c->cr_msg, 0 );
2140 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
2142 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
2145 case CFG_MIRRORMODE:
2146 if(c->value_int && !SLAP_SHADOW(c->be)) {
2147 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database is not a shadow",
2149 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2150 c->log, c->cr_msg, 0 );
2154 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
2155 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MULTI_SHADOW;
2157 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
2158 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MULTI_SHADOW;
2162 case CFG_MONITORING:
2164 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
2166 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
2172 if ( c->bi->bi_db_close ) {
2173 BackendInfo *bi_orig = c->be->bd_info;
2174 c->be->bd_info = c->bi;
2175 c->bi->bi_db_close( c->be, &c->reply );
2176 c->be->bd_info = bi_orig;
2178 c->bi->bi_flags |= SLAPO_BFLAG_DISABLED;
2180 c->bi->bi_flags &= ~SLAPO_BFLAG_DISABLED;
2184 backend_shutdown( c->be );
2185 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_DISABLED;
2187 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_DISABLED;
2194 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
2196 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
2199 case CFG_SYNC_SUBENTRY:
2201 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SYNC_SUBENTRY;
2203 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SYNC_SUBENTRY;
2206 case CFG_SSTR_IF_MAX:
2207 if (c->value_uint < index_substr_if_minlen) {
2208 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
2209 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
2210 c->log, c->cr_msg, c->value_int );
2213 index_substr_if_maxlen = c->value_uint;
2216 case CFG_SSTR_IF_MIN:
2217 if (c->value_uint > index_substr_if_maxlen) {
2218 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
2219 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
2220 c->log, c->cr_msg, c->value_int );
2223 index_substr_if_minlen = c->value_uint;
2226 #ifdef SLAPD_MODULES
2228 /* If we're just adding a module on an existing modpath,
2229 * make sure we've selected the current path.
2231 if ( c->op == LDAP_MOD_ADD && c->ca_private && modcur != c->ca_private ) {
2232 modcur = c->ca_private;
2233 /* This should never fail */
2234 if ( module_path( modcur->mp_path.bv_val )) {
2235 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> module path no longer valid",
2237 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2238 c->log, c->cr_msg, modcur->mp_path.bv_val );
2242 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
2244 /* Record this load on the current path */
2248 if ( c->op == SLAP_CONFIG_ADD ) {
2249 ptr = c->line + STRLENOF("moduleload");
2250 while (!isspace((unsigned char) *ptr)) ptr++;
2251 while (isspace((unsigned char) *ptr)) ptr++;
2255 ber_str2bv(ptr, 0, 1, &bv);
2256 ber_bvarray_add( &modcur->mp_loads, &bv );
2258 /* Check for any new hardcoded schema */
2259 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
2260 config_check_schema( NULL, &cfBackInfo );
2265 if(module_path(c->argv[1])) return(1);
2266 /* Record which path was used with each module */
2270 if (!modpaths.mp_loads) {
2273 mp = ch_malloc( sizeof( ModPaths ));
2274 modlast->mp_next = mp;
2276 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
2278 mp->mp_loads = NULL;
2289 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
2291 slapi_plugins_used++;
2295 #ifdef SLAP_AUTH_REWRITE
2301 if ( c->op == LDAP_MOD_ADD ) {
2305 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
2309 if ( c->argc > 1 ) {
2312 /* quote all args but the first */
2313 line = ldap_charray2str( c->argv, "\" \"" );
2314 ber_str2bv( line, 0, 0, &bv );
2315 s = ber_bvchr( &bv, '"' );
2316 assert( s != NULL );
2317 /* move the trailing quote of argv[0] to the end */
2318 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
2319 bv.bv_val[ bv.bv_len - 1 ] = '"';
2322 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
2325 ber_bvarray_add( &authz_rewrites, &bv );
2327 if ( c->op == LDAP_MOD_ADD ) {
2337 Debug( LDAP_DEBUG_ANY,
2338 "%s: unknown CFG_TYPE %d.\n",
2339 c->log, c->type, 0 );
2348 config_fname(ConfigArgs *c) {
2349 if(c->op == SLAP_CONFIG_EMIT) {
2350 if (c->ca_private) {
2351 ConfigFile *cf = c->ca_private;
2352 value_add_one( &c->rvalue_vals, &cf->c_file );
2361 config_cfdir(ConfigArgs *c) {
2362 if(c->op == SLAP_CONFIG_EMIT) {
2363 if ( !BER_BVISEMPTY( &cfdir )) {
2364 value_add_one( &c->rvalue_vals, &cfdir );
2373 config_search_base(ConfigArgs *c) {
2374 if(c->op == SLAP_CONFIG_EMIT) {
2376 if (!BER_BVISEMPTY(&default_search_base)) {
2377 value_add_one(&c->rvalue_vals, &default_search_base);
2378 value_add_one(&c->rvalue_nvals, &default_search_nbase);
2382 } else if( c->op == LDAP_MOD_DELETE ) {
2383 ch_free( default_search_base.bv_val );
2384 ch_free( default_search_nbase.bv_val );
2385 BER_BVZERO( &default_search_base );
2386 BER_BVZERO( &default_search_nbase );
2390 if(c->bi || c->be != frontendDB) {
2391 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
2392 "prior to any backend or database definition\n",
2397 if(default_search_nbase.bv_len) {
2398 free(default_search_base.bv_val);
2399 free(default_search_nbase.bv_val);
2402 default_search_base = c->value_dn;
2403 default_search_nbase = c->value_ndn;
2407 /* For RE23 compatibility we allow this in the global entry
2408 * but we now defer it to the frontend entry to allow modules
2409 * to load new hash types.
2412 config_passwd_hash(ConfigArgs *c) {
2414 if (c->op == SLAP_CONFIG_EMIT) {
2416 /* Don't generate it in the global entry */
2417 if ( c->table == Cft_Global )
2419 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
2420 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
2421 value_add_one(&c->rvalue_vals, &bv);
2424 } else if ( c->op == LDAP_MOD_DELETE ) {
2425 /* Deleting from global is a no-op, only the frontendDB entry matters */
2426 if ( c->table == Cft_Global )
2428 if ( c->valx < 0 ) {
2429 ldap_charray_free( default_passwd_hash );
2430 default_passwd_hash = NULL;
2433 ch_free( default_passwd_hash[i] );
2434 for (; default_passwd_hash[i]; i++ )
2435 default_passwd_hash[i] = default_passwd_hash[i+1];
2439 for(i = 1; i < c->argc; i++) {
2440 if(!lutil_passwd_scheme(c->argv[i])) {
2441 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> scheme not available", c->argv[0] );
2442 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2443 c->log, c->cr_msg, c->argv[i]);
2445 ldap_charray_add(&default_passwd_hash, c->argv[i]);
2448 if(!default_passwd_hash) {
2449 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> no valid hashes found", c->argv[0] );
2450 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2451 c->log, c->cr_msg, 0 );
2458 config_schema_dn(ConfigArgs *c) {
2459 if ( c->op == SLAP_CONFIG_EMIT ) {
2461 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
2462 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
2463 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
2467 } else if ( c->op == LDAP_MOD_DELETE ) {
2468 ch_free( c->be->be_schemadn.bv_val );
2469 ch_free( c->be->be_schemandn.bv_val );
2470 BER_BVZERO( &c->be->be_schemadn );
2471 BER_BVZERO( &c->be->be_schemandn );
2474 ch_free( c->be->be_schemadn.bv_val );
2475 ch_free( c->be->be_schemandn.bv_val );
2476 c->be->be_schemadn = c->value_dn;
2477 c->be->be_schemandn = c->value_ndn;
2482 config_sizelimit(ConfigArgs *c) {
2484 struct slap_limits_set *lim = &c->be->be_def_limit;
2485 if (c->op == SLAP_CONFIG_EMIT) {
2490 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
2491 if ( !BER_BVISEMPTY( &bv ))
2492 value_add_one( &c->rvalue_vals, &bv );
2496 } else if ( c->op == LDAP_MOD_DELETE ) {
2497 /* Reset to defaults or values from frontend */
2498 if ( c->be == frontendDB ) {
2499 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
2500 lim->lms_s_hard = 0;
2501 lim->lms_s_unchecked = -1;
2503 lim->lms_s_pr_hide = 0;
2504 lim->lms_s_pr_total = 0;
2506 lim->lms_s_soft = frontendDB->be_def_limit.lms_s_soft;
2507 lim->lms_s_hard = frontendDB->be_def_limit.lms_s_hard;
2508 lim->lms_s_unchecked = frontendDB->be_def_limit.lms_s_unchecked;
2509 lim->lms_s_pr = frontendDB->be_def_limit.lms_s_pr;
2510 lim->lms_s_pr_hide = frontendDB->be_def_limit.lms_s_pr_hide;
2511 lim->lms_s_pr_total = frontendDB->be_def_limit.lms_s_pr_total;
2515 for(i = 1; i < c->argc; i++) {
2516 if(!strncasecmp(c->argv[i], "size", 4)) {
2517 rc = limits_parse_one(c->argv[i], lim);
2519 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2520 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2521 c->log, c->cr_msg, c->argv[i]);
2525 if(!strcasecmp(c->argv[i], "unlimited")) {
2526 lim->lms_s_soft = -1;
2528 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
2529 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2530 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2531 c->log, c->cr_msg, c->argv[i]);
2535 lim->lms_s_hard = 0;
2540 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2541 /* This is a modification to the global limits apply it to
2542 * the other databases as needed */
2543 AttributeDescription *ad=NULL;
2544 const char *text = NULL;
2545 CfEntryInfo *ce = c->ca_entry->e_private;
2547 slap_str2ad(c->argv[0], &ad, &text);
2548 /* if we got here... */
2549 assert( ad != NULL );
2551 if ( ce->ce_type == Cft_Global ){
2554 for (; ce; ce=ce->ce_sibs) {
2555 Entry *dbe = ce->ce_entry;
2556 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2557 && (!attr_find(dbe->e_attrs, ad)) ) {
2558 ce->ce_be->be_def_limit.lms_s_soft = lim->lms_s_soft;
2559 ce->ce_be->be_def_limit.lms_s_hard = lim->lms_s_hard;
2560 ce->ce_be->be_def_limit.lms_s_unchecked =lim->lms_s_unchecked;
2561 ce->ce_be->be_def_limit.lms_s_pr =lim->lms_s_pr;
2562 ce->ce_be->be_def_limit.lms_s_pr_hide =lim->lms_s_pr_hide;
2563 ce->ce_be->be_def_limit.lms_s_pr_total =lim->lms_s_pr_total;
2571 config_timelimit(ConfigArgs *c) {
2573 struct slap_limits_set *lim = &c->be->be_def_limit;
2574 if (c->op == SLAP_CONFIG_EMIT) {
2579 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
2580 if ( !BER_BVISEMPTY( &bv ))
2581 value_add_one( &c->rvalue_vals, &bv );
2585 } else if ( c->op == LDAP_MOD_DELETE ) {
2586 /* Reset to defaults or values from frontend */
2587 if ( c->be == frontendDB ) {
2588 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
2589 lim->lms_t_hard = 0;
2591 lim->lms_t_soft = frontendDB->be_def_limit.lms_t_soft;
2592 lim->lms_t_hard = frontendDB->be_def_limit.lms_t_hard;
2596 for(i = 1; i < c->argc; i++) {
2597 if(!strncasecmp(c->argv[i], "time", 4)) {
2598 rc = limits_parse_one(c->argv[i], lim);
2600 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2601 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2602 c->log, c->cr_msg, c->argv[i]);
2606 if(!strcasecmp(c->argv[i], "unlimited")) {
2607 lim->lms_t_soft = -1;
2609 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
2610 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2611 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2612 c->log, c->cr_msg, c->argv[i]);
2616 lim->lms_t_hard = 0;
2621 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2622 /* This is a modification to the global limits apply it to
2623 * the other databases as needed */
2624 AttributeDescription *ad=NULL;
2625 const char *text = NULL;
2626 CfEntryInfo *ce = c->ca_entry->e_private;
2628 slap_str2ad(c->argv[0], &ad, &text);
2629 /* if we got here... */
2630 assert( ad != NULL );
2632 if ( ce->ce_type == Cft_Global ){
2635 for (; ce; ce=ce->ce_sibs) {
2636 Entry *dbe = ce->ce_entry;
2637 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2638 && (!attr_find(dbe->e_attrs, ad)) ) {
2639 ce->ce_be->be_def_limit.lms_t_soft = lim->lms_t_soft;
2640 ce->ce_be->be_def_limit.lms_t_hard = lim->lms_t_hard;
2648 config_overlay(ConfigArgs *c) {
2649 if (c->op == SLAP_CONFIG_EMIT) {
2651 } else if ( c->op == LDAP_MOD_DELETE ) {
2654 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2655 c->valx, &c->bi, &c->reply)) {
2657 Debug( LDAP_DEBUG_ANY,
2658 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2659 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2661 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi, &c->reply)) {
2668 config_subordinate(ConfigArgs *c)
2674 case SLAP_CONFIG_EMIT:
2675 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2678 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2679 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2682 value_add_one( &c->rvalue_vals, &bv );
2686 case LDAP_MOD_DELETE:
2687 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2688 glue_sub_del( c->be );
2690 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2695 case SLAP_CONFIG_ADD:
2696 if ( c->be->be_nsuffix == NULL ) {
2698 snprintf( c->cr_msg, sizeof( c->cr_msg),
2699 "subordinate configuration needs a suffix" );
2700 Debug( LDAP_DEBUG_ANY,
2702 c->log, c->cr_msg, 0 );
2707 if ( c->argc == 2 ) {
2708 if ( strcasecmp( c->argv[1], "advertise" ) == 0 ) {
2711 } else if ( strcasecmp( c->argv[1], "TRUE" ) != 0 ) {
2713 snprintf( c->cr_msg, sizeof( c->cr_msg),
2714 "subordinate must be \"TRUE\" or \"advertise\"" );
2715 Debug( LDAP_DEBUG_ANY,
2716 "%s: suffix \"%s\": %s.\n",
2717 c->log, c->be->be_suffix[0].bv_val, c->cr_msg );
2723 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2731 * [listener=<listener>] [{read|write}=]<size>
2734 #ifdef LDAP_TCP_BUFFER
2735 static BerVarray tcp_buffer;
2738 #define SLAP_TCP_RMEM (0x1U)
2739 #define SLAP_TCP_WMEM (0x2U)
2742 tcp_buffer_parse( struct berval *val, int argc, char **argv,
2743 int *size, int *rw, Listener **l )
2745 int i, rc = LDAP_SUCCESS;
2746 LDAPURLDesc *lud = NULL;
2749 if ( val != NULL && argv == NULL ) {
2750 char *s = val->bv_val;
2752 argv = ldap_str2charray( s, " \t" );
2753 if ( argv == NULL ) {
2759 if ( strncasecmp( argv[ i ], "listener=", STRLENOF( "listener=" ) )
2762 char *url = argv[ i ] + STRLENOF( "listener=" );
2764 if ( ldap_url_parse( url, &lud ) ) {
2765 rc = LDAP_INVALID_SYNTAX;
2769 *l = config_check_my_url( url, lud );
2771 rc = LDAP_NO_SUCH_ATTRIBUTE;
2779 if ( strncasecmp( ptr, "read=", STRLENOF( "read=" ) ) == 0 ) {
2780 *rw |= SLAP_TCP_RMEM;
2781 ptr += STRLENOF( "read=" );
2783 } else if ( strncasecmp( ptr, "write=", STRLENOF( "write=" ) ) == 0 ) {
2784 *rw |= SLAP_TCP_WMEM;
2785 ptr += STRLENOF( "write=" );
2788 *rw |= ( SLAP_TCP_RMEM | SLAP_TCP_WMEM );
2791 /* accept any base */
2792 if ( lutil_atoix( size, ptr, 0 ) ) {
2793 rc = LDAP_INVALID_SYNTAX;
2798 if ( val != NULL && argv != NULL ) {
2799 ldap_charray_free( argv );
2802 if ( lud != NULL ) {
2803 ldap_free_urldesc( lud );
2810 tcp_buffer_delete_one( struct berval *val )
2813 int size = -1, rw = 0;
2816 rc = tcp_buffer_parse( val, 0, NULL, &size, &rw, &l );
2823 Listener **ll = slapd_get_listeners();
2825 for ( i = 0; ll[ i ] != NULL; i++ ) {
2826 if ( ll[ i ] == l ) break;
2829 if ( ll[ i ] == NULL ) {
2830 return LDAP_NO_SUCH_ATTRIBUTE;
2833 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = -1;
2834 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = -1;
2836 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2837 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = -1;
2838 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = -1;
2842 /* NOTE: this affects listeners without a specific setting,
2843 * does not reset all listeners. If a listener without
2844 * specific settings was assigned a buffer because of
2845 * a global setting, it will not be reset. In any case,
2846 * buffer changes will only take place at restart. */
2847 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = -1;
2848 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = -1;
2855 tcp_buffer_delete( BerVarray vals )
2859 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
2860 tcp_buffer_delete_one( &vals[ i ] );
2867 tcp_buffer_unparse( int size, int rw, Listener *l, struct berval *val )
2869 char buf[sizeof("2147483648")], *ptr;
2871 /* unparse for later use */
2872 val->bv_len = snprintf( buf, sizeof( buf ), "%d", size );
2874 val->bv_len += STRLENOF( "listener=" " " ) + l->sl_url.bv_len;
2877 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2878 if ( rw & SLAP_TCP_RMEM ) {
2879 val->bv_len += STRLENOF( "read=" );
2880 } else if ( rw & SLAP_TCP_WMEM ) {
2881 val->bv_len += STRLENOF( "write=" );
2885 val->bv_val = SLAP_MALLOC( val->bv_len + 1 );
2890 ptr = lutil_strcopy( ptr, "listener=" );
2891 ptr = lutil_strncopy( ptr, l->sl_url.bv_val, l->sl_url.bv_len );
2895 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2896 if ( rw & SLAP_TCP_RMEM ) {
2897 ptr = lutil_strcopy( ptr, "read=" );
2898 } else if ( rw & SLAP_TCP_WMEM ) {
2899 ptr = lutil_strcopy( ptr, "write=" );
2903 ptr = lutil_strcopy( ptr, buf );
2906 assert( val->bv_val + val->bv_len == ptr );
2908 return LDAP_SUCCESS;
2912 tcp_buffer_add_one( int argc, char **argv )
2915 int size = -1, rw = 0;
2921 rc = tcp_buffer_parse( NULL, argc, argv, &size, &rw, &l );
2926 /* unparse for later use */
2927 rc = tcp_buffer_unparse( size, rw, l, &val );
2928 if ( rc != LDAP_SUCCESS ) {
2932 /* use parsed values */
2935 Listener **ll = slapd_get_listeners();
2937 for ( i = 0; ll[ i ] != NULL; i++ ) {
2938 if ( ll[ i ] == l ) break;
2941 if ( ll[ i ] == NULL ) {
2942 return LDAP_NO_SUCH_ATTRIBUTE;
2945 /* buffer only applies to TCP listeners;
2946 * we do not do any check here, and delegate them
2947 * to setsockopt(2) */
2948 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = size;
2949 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = size;
2951 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2952 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = size;
2953 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = size;
2957 /* NOTE: this affects listeners without a specific setting,
2958 * does not set all listeners */
2959 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = size;
2960 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = size;
2963 tcp_buffer = SLAP_REALLOC( tcp_buffer, sizeof( struct berval ) * ( tcp_buffer_num + 2 ) );
2965 tcp_buffer[ tcp_buffer_num ] = val;
2968 BER_BVZERO( &tcp_buffer[ tcp_buffer_num ] );
2974 config_tcp_buffer( ConfigArgs *c )
2976 if ( c->op == SLAP_CONFIG_EMIT ) {
2977 if ( tcp_buffer == NULL || BER_BVISNULL( &tcp_buffer[ 0 ] ) ) {
2980 value_add( &c->rvalue_vals, tcp_buffer );
2981 value_add( &c->rvalue_nvals, tcp_buffer );
2983 } else if ( c->op == LDAP_MOD_DELETE ) {
2985 tcp_buffer_delete( tcp_buffer );
2986 ber_bvarray_free( tcp_buffer );
2992 int size = -1, rw = 0;
2995 struct berval val = BER_BVNULL;
2999 if ( tcp_buffer_num == 0 ) {
3004 rc = tcp_buffer_parse( NULL, c->argc - 1, &c->argv[ 1 ], &size, &rw, &l );
3009 /* unparse for later use */
3010 rc = tcp_buffer_unparse( size, rw, l, &val );
3011 if ( rc != LDAP_SUCCESS ) {
3015 for ( i = 0; !BER_BVISNULL( &tcp_buffer[ i ] ); i++ ) {
3016 if ( bvmatch( &tcp_buffer[ i ], &val ) ) {
3021 if ( BER_BVISNULL( &tcp_buffer[ i ] ) ) {
3027 tcp_buffer_delete_one( &tcp_buffer[ i ] );
3028 ber_memfree( tcp_buffer[ i ].bv_val );
3029 for ( ; i < tcp_buffer_num; i++ ) {
3030 tcp_buffer[ i ] = tcp_buffer[ i + 1 ];
3035 if ( !BER_BVISNULL( &val ) ) {
3036 SLAP_FREE( val.bv_val );
3044 rc = tcp_buffer_add_one( c->argc - 1, &c->argv[ 1 ] );
3046 snprintf( c->cr_msg, sizeof( c->cr_msg ),
3047 "<%s> unable to add value #%d",
3048 c->argv[0], tcp_buffer_num );
3049 Debug( LDAP_DEBUG_ANY, "%s: %s\n",
3050 c->log, c->cr_msg, 0 );
3057 #endif /* LDAP_TCP_BUFFER */
3060 config_suffix(ConfigArgs *c)
3063 struct berval pdn, ndn;
3064 char *notallowed = NULL;
3066 if ( c->be == frontendDB ) {
3067 notallowed = "frontend";
3069 } else if ( SLAP_MONITOR(c->be) ) {
3070 notallowed = "monitor";
3072 } else if ( SLAP_CONFIG(c->be) ) {
3073 notallowed = "config";
3076 if ( notallowed != NULL ) {
3077 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
3081 case LDAP_MOD_DELETE:
3082 case LDAP_MOD_REPLACE:
3083 case LDAP_MOD_INCREMENT:
3084 case SLAP_CONFIG_ADD:
3085 if ( !BER_BVISNULL( &c->value_dn ) ) {
3086 snprintf( buf, sizeof( buf ), "<%s> ",
3087 c->value_dn.bv_val );
3090 Debug(LDAP_DEBUG_ANY,
3091 "%s: suffix %snot allowed in %s database.\n",
3092 c->log, buf, notallowed );
3095 case SLAP_CONFIG_EMIT:
3096 /* don't complain when emitting... */
3100 /* FIXME: don't know what values may be valid;
3101 * please remove assertion, or add legal values
3102 * to either block */
3110 if (c->op == SLAP_CONFIG_EMIT) {
3111 if ( c->be->be_suffix == NULL
3112 || BER_BVISNULL( &c->be->be_suffix[0] ) )
3116 value_add( &c->rvalue_vals, c->be->be_suffix );
3117 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
3120 } else if ( c->op == LDAP_MOD_DELETE ) {
3121 if ( c->valx < 0 ) {
3122 ber_bvarray_free( c->be->be_suffix );
3123 ber_bvarray_free( c->be->be_nsuffix );
3124 c->be->be_suffix = NULL;
3125 c->be->be_nsuffix = NULL;
3128 ch_free( c->be->be_suffix[i].bv_val );
3129 ch_free( c->be->be_nsuffix[i].bv_val );
3131 c->be->be_suffix[i] = c->be->be_suffix[i+1];
3132 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
3134 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
3139 #ifdef SLAPD_MONITOR_DN
3140 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
3141 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> DN is reserved for monitoring slapd",
3143 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3144 c->log, c->cr_msg, SLAPD_MONITOR_DN);
3149 if (SLAP_DB_ONE_SUFFIX( c->be ) && c->be->be_suffix &&
3150 !BER_BVISNULL( &c->be->be_suffix[0] )) {
3151 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> Only one suffix is allowed on this %s backend",
3152 c->argv[0], c->be->bd_info->bi_type );
3153 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3154 c->log, c->cr_msg, 0);
3161 if (SLAP_DBHIDDEN( c->be ))
3164 tbe = select_backend(&ndn, 0);
3166 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
3172 BackendDB *b2 = tbe;
3174 /* Does tbe precede be? */
3175 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
3178 char *type = tbe->bd_info->bi_type;
3180 if ( overlay_is_over( tbe ) ) {
3181 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
3182 type = oi->oi_orig->bi_type;
3185 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> namingContext \"%s\" "
3186 "already served by a preceding %s database",
3187 c->argv[0], pdn.bv_val, type );
3188 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
3189 c->log, c->cr_msg, tbe->be_suffix[0].bv_val);
3195 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
3196 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
3197 "base provided \"%s\" (assuming okay)\n",
3198 c->log, default_search_base.bv_val, 0);
3200 ber_bvarray_add(&c->be->be_suffix, &pdn);
3201 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
3206 config_rootdn(ConfigArgs *c) {
3207 if (c->op == SLAP_CONFIG_EMIT) {
3208 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
3209 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
3210 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
3215 } else if ( c->op == LDAP_MOD_DELETE ) {
3216 ch_free( c->be->be_rootdn.bv_val );
3217 ch_free( c->be->be_rootndn.bv_val );
3218 BER_BVZERO( &c->be->be_rootdn );
3219 BER_BVZERO( &c->be->be_rootndn );
3222 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
3223 ch_free( c->be->be_rootdn.bv_val );
3224 ch_free( c->be->be_rootndn.bv_val );
3226 c->be->be_rootdn = c->value_dn;
3227 c->be->be_rootndn = c->value_ndn;
3232 config_rootpw(ConfigArgs *c) {
3235 if (c->op == SLAP_CONFIG_EMIT) {
3236 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
3237 /* don't copy, because "rootpw" is marked
3239 c->value_bv = c->be->be_rootpw;
3243 } else if ( c->op == LDAP_MOD_DELETE ) {
3244 ch_free( c->be->be_rootpw.bv_val );
3245 BER_BVZERO( &c->be->be_rootpw );
3249 tbe = select_backend(&c->be->be_rootndn, 0);
3251 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> can only be set when rootdn is under suffix",
3253 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3254 c->log, c->cr_msg, 0);
3257 if ( !BER_BVISNULL( &c->be->be_rootpw ))
3258 ch_free( c->be->be_rootpw.bv_val );
3259 c->be->be_rootpw = c->value_bv;
3264 config_restrict(ConfigArgs *c) {
3265 slap_mask_t restrictops = 0;
3267 slap_verbmasks restrictable_ops[] = {
3268 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
3269 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
3270 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
3271 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
3272 { BER_BVC("modrdn"), 0 },
3273 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
3274 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
3275 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
3276 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
3277 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
3278 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
3279 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
3280 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
3281 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
3282 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
3283 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
3287 if (c->op == SLAP_CONFIG_EMIT) {
3288 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
3290 } else if ( c->op == LDAP_MOD_DELETE ) {
3292 c->be->be_restrictops = 0;
3294 i = verb_to_mask( c->line, restrictable_ops );
3295 c->be->be_restrictops &= ~restrictable_ops[i].mask;
3299 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
3301 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown operation", c->argv[0] );
3302 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3303 c->log, c->cr_msg, c->argv[i]);
3306 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
3307 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
3308 c->be->be_restrictops |= restrictops;
3313 config_allows(ConfigArgs *c) {
3314 slap_mask_t allows = 0;
3316 slap_verbmasks allowable_ops[] = {
3317 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
3318 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
3319 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
3320 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
3321 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
3324 if (c->op == SLAP_CONFIG_EMIT) {
3325 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
3326 } else if ( c->op == LDAP_MOD_DELETE ) {
3330 i = verb_to_mask( c->line, allowable_ops );
3331 global_allows &= ~allowable_ops[i].mask;
3335 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
3337 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3338 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3339 c->log, c->cr_msg, c->argv[i]);
3342 global_allows |= allows;
3347 config_disallows(ConfigArgs *c) {
3348 slap_mask_t disallows = 0;
3350 slap_verbmasks disallowable_ops[] = {
3351 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
3352 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
3353 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
3354 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
3355 { BER_BVC("proxy_authz_non_critical"), SLAP_DISALLOW_PROXY_AUTHZ_N_CRIT },
3356 { BER_BVC("dontusecopy_non_critical"), SLAP_DISALLOW_DONTUSECOPY_N_CRIT },
3359 if (c->op == SLAP_CONFIG_EMIT) {
3360 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
3361 } else if ( c->op == LDAP_MOD_DELETE ) {
3363 global_disallows = 0;
3365 i = verb_to_mask( c->line, disallowable_ops );
3366 global_disallows &= ~disallowable_ops[i].mask;
3370 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
3372 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3373 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3374 c->log, c->cr_msg, c->argv[i]);
3377 global_disallows |= disallows;
3382 config_requires(ConfigArgs *c) {
3383 slap_mask_t requires = frontendDB->be_requires;
3384 int i, argc = c->argc;
3385 char **argv = c->argv;
3387 slap_verbmasks requires_ops[] = {
3388 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
3389 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
3390 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
3391 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
3392 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
3395 if (c->op == SLAP_CONFIG_EMIT) {
3396 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
3397 } else if ( c->op == LDAP_MOD_DELETE ) {
3399 c->be->be_requires = 0;
3401 i = verb_to_mask( c->line, requires_ops );
3402 c->be->be_requires &= ~requires_ops[i].mask;
3406 /* "none" can only be first, to wipe out default/global values */
3407 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
3412 i = verbs_to_mask(argc, argv, requires_ops, &requires);
3414 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
3415 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
3416 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3417 c->log, c->cr_msg, 0);
3419 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
3420 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3421 c->log, c->cr_msg, c->argv[i]);
3425 c->be->be_requires = requires;
3430 config_extra_attrs(ConfigArgs *c)
3432 assert( c->be != NULL );
3434 if ( c->op == SLAP_CONFIG_EMIT ) {
3437 if ( c->be->be_extra_anlist == NULL ) {
3441 for ( i = 0; !BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ); i++ ) {
3442 value_add_one( &c->rvalue_vals, &c->be->be_extra_anlist[i].an_name );
3445 } else if ( c->op == LDAP_MOD_DELETE ) {
3446 if ( c->be->be_extra_anlist == NULL ) {
3450 if ( c->valx < 0 ) {
3451 anlist_free( c->be->be_extra_anlist, 1, NULL );
3452 c->be->be_extra_anlist = NULL;
3457 for ( i = 0; i < c->valx && !BER_BVISNULL( &c->be->be_extra_anlist[i + 1].an_name ); i++ )
3460 if ( BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ) ) {
3464 ch_free( c->be->be_extra_anlist[i].an_name.bv_val );
3466 for ( ; !BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ); i++ ) {
3467 c->be->be_extra_anlist[i] = c->be->be_extra_anlist[i + 1];
3472 c->be->be_extra_anlist = str2anlist( c->be->be_extra_anlist, c->argv[1], " ,\t" );
3473 if ( c->be->be_extra_anlist == NULL ) {
3481 static slap_verbmasks *loglevel_ops;
3484 loglevel_init( void )
3486 slap_verbmasks lo[] = {
3487 { BER_BVC("Any"), (slap_mask_t) LDAP_DEBUG_ANY },
3488 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
3489 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
3490 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
3491 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
3492 { BER_BVC("BER"), LDAP_DEBUG_BER },
3493 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
3494 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
3495 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
3496 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
3497 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
3498 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
3499 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
3500 #if 0 /* no longer used (nor supported) */
3501 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
3502 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
3504 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
3505 { BER_BVC("None"), LDAP_DEBUG_NONE },
3509 return slap_verbmasks_init( &loglevel_ops, lo );
3513 loglevel_destroy( void )
3515 if ( loglevel_ops ) {
3516 (void)slap_verbmasks_destroy( loglevel_ops );
3518 loglevel_ops = NULL;
3521 static slap_mask_t loglevel_ignore[] = { -1, 0 };
3524 slap_loglevel_register( slap_mask_t m, struct berval *s )
3528 if ( loglevel_ops == NULL ) {
3532 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
3535 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
3543 slap_loglevel_get( struct berval *s, int *l )
3548 if ( loglevel_ops == NULL ) {
3552 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3553 m |= loglevel_ops[ i ].mask;
3556 for ( i = 1; m & i; i <<= 1 )
3563 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
3566 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
3577 str2loglevel( const char *s, int *l )
3581 if ( loglevel_ops == NULL ) {
3585 i = verb_to_mask( s, loglevel_ops );
3587 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
3591 *l = loglevel_ops[ i ].mask;
3597 loglevel2str( int l )
3599 struct berval bv = BER_BVNULL;
3601 loglevel2bv( l, &bv );
3607 loglevel2bv( int l, struct berval *bv )
3609 if ( loglevel_ops == NULL ) {
3615 return enum_to_verb( loglevel_ops, l, bv ) == -1;
3619 loglevel2bvarray( int l, BerVarray *bva )
3621 if ( loglevel_ops == NULL ) {
3626 return value_add_one( bva, ber_bvstr( "0" ) );
3629 return mask_to_verbs( loglevel_ops, l, bva );
3633 loglevel_print( FILE *out )
3637 if ( loglevel_ops == NULL ) {
3641 fprintf( out, "Installed log subsystems:\n\n" );
3642 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3643 unsigned mask = loglevel_ops[ i ].mask & 0xffffffffUL;
3645 (mask == ((slap_mask_t) -1 & 0xffffffffUL)
3646 ? "\t%-30s (-1, 0xffffffff)\n" : "\t%-30s (%u, 0x%x)\n"),
3647 loglevel_ops[ i ].word.bv_val, mask, mask );
3650 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
3651 "by specific code\n\n" );
3656 static int config_syslog;
3659 config_loglevel(ConfigArgs *c) {
3662 if ( loglevel_ops == NULL ) {
3666 if (c->op == SLAP_CONFIG_EMIT) {
3667 /* Get default or commandline slapd setting */
3668 if ( ldap_syslog && !config_syslog )
3669 config_syslog = ldap_syslog;
3670 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
3672 } else if ( c->op == LDAP_MOD_DELETE ) {
3676 i = verb_to_mask( c->line, loglevel_ops );
3677 config_syslog &= ~loglevel_ops[i].mask;
3679 if ( slapMode & SLAP_SERVER_MODE ) {
3680 ldap_syslog = config_syslog;
3685 for( i=1; i < c->argc; i++ ) {
3688 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
3689 if( lutil_atoix( &level, c->argv[i], 0 ) != 0 ) {
3690 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse level", c->argv[0] );
3691 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3692 c->log, c->cr_msg, c->argv[i]);
3696 if ( str2loglevel( c->argv[i], &level ) ) {
3697 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown level", c->argv[0] );
3698 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3699 c->log, c->cr_msg, c->argv[i]);
3703 /* Explicitly setting a zero clears all the levels */
3705 config_syslog |= level;
3709 if ( slapMode & SLAP_SERVER_MODE ) {
3710 ldap_syslog = config_syslog;
3716 config_referral(ConfigArgs *c) {
3718 if (c->op == SLAP_CONFIG_EMIT) {
3719 if ( default_referral ) {
3720 value_add( &c->rvalue_vals, default_referral );
3725 } else if ( c->op == LDAP_MOD_DELETE ) {
3726 if ( c->valx < 0 ) {
3727 ber_bvarray_free( default_referral );
3728 default_referral = NULL;
3731 ch_free( default_referral[i].bv_val );
3732 for (; default_referral[i].bv_val; i++ )
3733 default_referral[i] = default_referral[i+1];
3737 if(validate_global_referral(c->argv[1])) {
3738 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3739 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3740 c->log, c->cr_msg, c->argv[1]);
3744 ber_str2bv(c->argv[1], 0, 0, &val);
3745 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
3753 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
3754 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
3755 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
3756 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
3757 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
3758 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
3759 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
3760 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
3761 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
3766 config_security(ConfigArgs *c) {
3767 slap_ssf_set_t *set = &c->be->be_ssf_set;
3770 if (c->op == SLAP_CONFIG_EMIT) {
3776 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
3777 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
3780 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
3781 if ( bv.bv_len >= sizeof( numbuf ) ) {
3782 ber_bvarray_free_x( c->rvalue_vals, NULL );
3783 c->rvalue_vals = NULL;
3787 bv.bv_len += sec_keys[i].key.bv_len;
3788 bv.bv_val = ch_malloc( bv.bv_len + 1);
3789 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
3790 strcpy( next, numbuf );
3791 ber_bvarray_add( &c->rvalue_vals, &bv );
3796 for(i = 1; i < c->argc; i++) {
3797 slap_ssf_t *tgt = NULL;
3799 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
3800 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
3801 sec_keys[j].key.bv_len)) {
3802 src = c->argv[i] + sec_keys[j].key.bv_len;
3803 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
3808 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown factor", c->argv[0] );
3809 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3810 c->log, c->cr_msg, c->argv[i]);
3814 if ( lutil_atou( tgt, src ) != 0 ) {
3815 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse factor", c->argv[0] );
3816 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3817 c->log, c->cr_msg, c->argv[i]);
3825 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
3829 for (; !BER_BVISNULL( &an->an_name ); an++) {
3830 /* if buflen == 0, assume the buffer size has been
3831 * already checked otherwise */
3832 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
3833 if ( comma ) *ptr++ = ',';
3834 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
3841 config_updatedn(ConfigArgs *c) {
3842 if (c->op == SLAP_CONFIG_EMIT) {
3843 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
3844 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
3845 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
3849 } else if ( c->op == LDAP_MOD_DELETE ) {
3850 ch_free( c->be->be_update_ndn.bv_val );
3851 BER_BVZERO( &c->be->be_update_ndn );
3852 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
3855 if(SLAP_SHADOW(c->be)) {
3856 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database already shadowed", c->argv[0] );
3857 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3858 c->log, c->cr_msg, 0);
3862 ber_memfree_x( c->value_dn.bv_val, NULL );
3863 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
3864 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
3866 c->be->be_update_ndn = c->value_ndn;
3867 BER_BVZERO( &c->value_dn );
3868 BER_BVZERO( &c->value_ndn );
3870 return config_slurp_shadow( c );
3874 config_shadow( ConfigArgs *c, slap_mask_t flag )
3876 char *notallowed = NULL;
3878 if ( c->be == frontendDB ) {
3879 notallowed = "frontend";
3881 } else if ( SLAP_MONITOR(c->be) ) {
3882 notallowed = "monitor";
3885 if ( notallowed != NULL ) {
3886 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
3890 if ( SLAP_SHADOW(c->be) ) {
3891 /* if already shadow, only check consistency */
3892 if ( ( SLAP_DBFLAGS(c->be) & flag ) != flag ) {
3893 Debug( LDAP_DEBUG_ANY, "%s: inconsistent shadow flag 0x%lx.\n",
3899 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | flag);
3900 if ( !SLAP_MULTIMASTER( c->be ))
3901 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
3908 config_updateref(ConfigArgs *c) {
3910 if (c->op == SLAP_CONFIG_EMIT) {
3911 if ( c->be->be_update_refs ) {
3912 value_add( &c->rvalue_vals, c->be->be_update_refs );
3917 } else if ( c->op == LDAP_MOD_DELETE ) {
3918 if ( c->valx < 0 ) {
3919 ber_bvarray_free( c->be->be_update_refs );
3920 c->be->be_update_refs = NULL;
3923 ch_free( c->be->be_update_refs[i].bv_val );
3924 for (; c->be->be_update_refs[i].bv_val; i++)
3925 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
3929 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
3930 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must appear after syncrepl or updatedn",
3932 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3933 c->log, c->cr_msg, 0);
3937 if(validate_global_referral(c->argv[1])) {
3938 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3939 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3940 c->log, c->cr_msg, c->argv[1]);
3943 ber_str2bv(c->argv[1], 0, 0, &val);
3944 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
3949 config_obsolete(ConfigArgs *c) {
3950 if (c->op == SLAP_CONFIG_EMIT)
3953 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> keyword is obsolete (ignored)",
3955 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0);
3960 config_include(ConfigArgs *c) {
3961 int savelineno = c->lineno;
3964 ConfigFile *cfsave = cfn;
3965 ConfigFile *cf2 = NULL;
3967 /* Leftover from RE23. No dynamic config for include files */
3968 if ( c->op == SLAP_CONFIG_EMIT || c->op == LDAP_MOD_DELETE )
3971 cf = ch_calloc( 1, sizeof(ConfigFile));
3972 if ( cfn->c_kids ) {
3973 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
3979 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
3980 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
3981 c->lineno = savelineno - 1;
3984 if ( cf2 ) cf2->c_sibs = NULL;
3985 else cfn->c_kids = NULL;
3986 ch_free( cf->c_file.bv_val );
3996 config_tls_cleanup(ConfigArgs *c) {
3999 if ( slap_tls_ld ) {
4002 ldap_pvt_tls_ctx_free( slap_tls_ctx );
4004 /* Force new ctx to be created */
4005 rc = ldap_pvt_tls_set_option( slap_tls_ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
4007 /* The ctx's refcount is bumped up here */
4008 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CTX, &slap_tls_ctx );
4009 /* This is a no-op if it's already loaded */
4010 load_extop( &slap_EXOP_START_TLS, 0, starttls_extop );
4017 config_tls_option(ConfigArgs *c) {
4019 LDAP *ld = slap_tls_ld;
4021 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
4022 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
4023 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
4024 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
4025 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
4026 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
4027 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
4029 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
4031 default: Debug(LDAP_DEBUG_ANY, "%s: "
4032 "unknown tls_option <0x%x>\n",
4033 c->log, c->type, 0);
4036 if (c->op == SLAP_CONFIG_EMIT) {
4037 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
4038 } else if ( c->op == LDAP_MOD_DELETE ) {
4039 c->cleanup = config_tls_cleanup;
4040 return ldap_pvt_tls_set_option( ld, flag, NULL );
4042 ch_free(c->value_string);
4043 c->cleanup = config_tls_cleanup;
4044 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
4047 /* FIXME: this ought to be provided by libldap */
4049 config_tls_config(ConfigArgs *c) {
4052 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
4053 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
4054 case CFG_TLS_PROTOCOL_MIN: flag = LDAP_OPT_X_TLS_PROTOCOL_MIN; break;
4056 Debug(LDAP_DEBUG_ANY, "%s: "
4057 "unknown tls_option <0x%x>\n",
4058 c->log, c->type, 0);
4061 if (c->op == SLAP_CONFIG_EMIT) {
4062 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
4063 } else if ( c->op == LDAP_MOD_DELETE ) {
4065 c->cleanup = config_tls_cleanup;
4066 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
4068 ch_free( c->value_string );
4069 c->cleanup = config_tls_cleanup;
4070 if ( isdigit( (unsigned char)c->argv[1][0] ) && c->type != CFG_TLS_PROTOCOL_MIN ) {
4071 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
4072 Debug(LDAP_DEBUG_ANY, "%s: "
4073 "unable to parse %s \"%s\"\n",
4074 c->log, c->argv[0], c->argv[1] );
4077 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
4079 return(ldap_pvt_tls_config(slap_tls_ld, flag, c->argv[1]));
4084 static CfEntryInfo *
4085 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
4095 if ( dn_match( &root->ce_entry->e_nname, dn ))
4098 c = dn->bv_val+dn->bv_len;
4099 for (;*c != ',';c--);
4103 for (--c;c>dn->bv_val && *c != ',';c--);
4107 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
4109 root = root->ce_kids;
4111 for (;root;root=root->ce_sibs) {
4112 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
4113 if ( cdn.bv_val == dn->bv_val ) {
4123 typedef struct setup_cookie {
4133 config_ldif_resp( Operation *op, SlapReply *rs )
4135 if ( rs->sr_type == REP_SEARCH ) {
4136 setup_cookie *sc = op->o_callback->sc_private;
4139 sc->cfb->cb_got_ldif = 1;
4140 /* Does the frontend exist? */
4141 if ( !sc->got_frontend ) {
4142 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
4143 "olcDatabase", STRLENOF( "olcDatabase" )))
4145 if ( strncmp( rs->sr_entry->e_nname.bv_val +
4146 STRLENOF( "olcDatabase" ), "={-1}frontend",
4147 STRLENOF( "={-1}frontend" )))
4151 sc->ca->be = frontendDB;
4152 sc->ca->bi = frontendDB->bd_info;
4153 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
4154 rdn.bv_val = sc->ca->log;
4155 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
4156 "%s=" SLAP_X_ORDERED_FMT "%s",
4157 cfAd_database->ad_cname.bv_val, -1,
4158 sc->ca->bi->bi_type);
4160 sc->frontend = config_build_entry( op, rs,
4161 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
4162 sc->ca->be->be_cf_ocs );
4172 dnParent( &rs->sr_entry->e_nname, &pdn );
4174 /* Does the configDB exist? */
4175 if ( sc->got_frontend && !sc->got_config &&
4176 !strncmp( rs->sr_entry->e_nname.bv_val,
4177 "olcDatabase", STRLENOF( "olcDatabase" )) &&
4178 dn_match( &config_rdn, &pdn ) )
4180 if ( strncmp( rs->sr_entry->e_nname.bv_val +
4181 STRLENOF( "olcDatabase" ), "={0}config",
4182 STRLENOF( "={0}config" )))
4186 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
4187 sc->ca->bi = sc->ca->be->bd_info;
4188 rdn.bv_val = sc->ca->log;
4189 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
4190 "%s=" SLAP_X_ORDERED_FMT "%s",
4191 cfAd_database->ad_cname.bv_val, 0,
4192 sc->ca->bi->bi_type);
4194 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
4195 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
4202 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
4203 if ( rs->sr_err != LDAP_SUCCESS ) {
4204 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
4205 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg, 0 );
4211 /* Configure and read the underlying back-ldif store */
4213 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
4214 CfBackInfo *cfb = be->be_private;
4220 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
4221 Connection conn = {0};
4222 OperationBuffer opbuf;
4224 SlapReply rs = {REP_RESULT};
4225 Filter filter = { LDAP_FILTER_PRESENT };
4226 struct berval filterstr = BER_BVC("(objectclass=*)");
4229 /* Is the config directory available? */
4230 if ( stat( dir, &st ) < 0 ) {
4231 /* No, so don't bother using the backing store.
4232 * All changes will be in-memory only.
4237 cfb->cb_db.bd_info = backend_info( "ldif" );
4238 if ( !cfb->cb_db.bd_info )
4239 return 0; /* FIXME: eventually this will be a fatal error */
4241 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
4244 cfb->cb_db.be_suffix = be->be_suffix;
4245 cfb->cb_db.be_nsuffix = be->be_nsuffix;
4247 /* The suffix is always "cn=config". The underlying DB's rootdn
4248 * is always the same as the suffix.
4250 cfb->cb_db.be_rootdn = be->be_suffix[0];
4251 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
4253 ber_str2bv( dir, 0, 1, &cfdir );
4258 argv[0] = "directory";
4259 argv[1] = (char *)dir;
4264 c.table = Cft_Database;
4266 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
4270 if ( config_add_vals( ct, &c ))
4273 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
4277 void *thrctx = ldap_pvt_thread_pool_context();
4280 connection_fake_init( &conn, &opbuf, thrctx );
4283 filter.f_desc = slap_schema.si_ad_objectClass;
4285 op->o_tag = LDAP_REQ_SEARCH;
4287 op->ors_filter = &filter;
4288 op->ors_filterstr = filterstr;
4289 op->ors_scope = LDAP_SCOPE_SUBTREE;
4291 op->o_dn = c.be->be_rootdn;
4292 op->o_ndn = c.be->be_rootndn;
4294 op->o_req_dn = be->be_suffix[0];
4295 op->o_req_ndn = be->be_nsuffix[0];
4297 op->ors_tlimit = SLAP_NO_LIMIT;
4298 op->ors_slimit = SLAP_NO_LIMIT;
4300 op->ors_attrs = slap_anlist_all_attributes;
4301 op->ors_attrsonly = 0;
4303 op->o_callback = &cb;
4306 cb.sc_private = ≻
4307 sc.got_frontend = 0;
4312 op->o_bd = &cfb->cb_db;
4314 /* Allow unknown attrs in DNs */
4315 prev_DN_strict = slap_DN_strict;
4318 rc = op->o_bd->be_search( op, &rs );
4320 /* Restore normal DN validation */
4321 slap_DN_strict = prev_DN_strict;
4323 op->o_tag = LDAP_REQ_ADD;
4324 if ( rc == LDAP_SUCCESS && sc.frontend ) {
4325 rs_reinit( &rs, REP_RESULT );
4326 op->ora_e = sc.frontend;
4327 rc = op->o_bd->be_add( op, &rs );
4329 if ( rc == LDAP_SUCCESS && sc.config ) {
4330 rs_reinit( &rs, REP_RESULT );
4331 op->ora_e = sc.config;
4332 rc = op->o_bd->be_add( op, &rs );
4334 ldap_pvt_thread_pool_context_reset( thrctx );
4337 /* ITS#4194 - only use if it's present, or we're converting. */
4338 if ( !readit || rc == LDAP_SUCCESS )
4339 cfb->cb_use_ldif = 1;
4345 CfOc_cmp( const void *c1, const void *c2 ) {
4346 const ConfigOCs *co1 = c1;
4347 const ConfigOCs *co2 = c2;
4349 return ber_bvcmp( co1->co_name, co2->co_name );
4353 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
4356 i = init_config_attrs( ct );
4359 /* set up the objectclasses */
4360 i = init_config_ocs( ocs );
4363 for (i=0; ocs[i].co_def; i++) {
4364 if ( ocs[i].co_oc ) {
4365 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
4366 if ( !ocs[i].co_table )
4367 ocs[i].co_table = ct;
4368 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
4375 read_config(const char *fname, const char *dir) {
4378 const char *cfdir, *cfname;
4381 /* Setup the config backend */
4382 be = backend_db_init( "config", NULL, 0, NULL );
4386 cfb = be->be_private;
4387 be->be_dfltaccess = ACL_NONE;
4389 /* If no .conf, or a dir was specified, setup the dir */
4390 if ( !fname || dir ) {
4392 /* If explicitly given, check for existence */
4395 if ( stat( dir, &st ) < 0 ) {
4396 Debug( LDAP_DEBUG_ANY,
4397 "invalid config directory %s, error %d\n",
4403 cfdir = SLAPD_DEFAULT_CONFIGDIR;
4405 /* if fname is defaulted, try reading .d */
4406 rc = config_setup_ldif( be, cfdir, !fname );
4409 /* It may be OK if the base object doesn't exist yet. */
4410 if ( rc != LDAP_NO_SUCH_OBJECT )
4412 /* ITS#4194: But if dir was specified and no fname,
4413 * then we were supposed to read the dir. Unless we're
4414 * trying to slapadd the dir...
4416 if ( dir && !fname ) {
4417 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
4419 /* Assume it's slapadd with a config dir, let it continue */
4421 cfb->cb_got_ldif = 1;
4422 cfb->cb_use_ldif = 1;
4427 /* If we read the config from back-ldif, nothing to do here */
4428 if ( cfb->cb_got_ldif ) {
4437 cfname = SLAPD_DEFAULT_CONFIGFILE;
4439 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
4442 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
4445 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
4446 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
4447 &frontendDB->be_schemadn );
4448 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
4449 if ( rc != LDAP_SUCCESS ) {
4450 Debug(LDAP_DEBUG_ANY, "read_config: "
4451 "unable to normalize default schema DN \"%s\"\n",
4452 frontendDB->be_schemadn.bv_val, 0, 0 );
4453 /* must not happen */
4457 if ( rc == 0 && ( slapMode & SLAP_SERVER_MODE ) && sid_list ) {
4458 if ( !BER_BVISEMPTY( &sid_list->si_url ) && !sid_set ) {
4459 Debug(LDAP_DEBUG_ANY, "read_config: no serverID / URL match found. "
4460 "Check slapd -h arguments.\n", 0,0,0 );
4468 config_back_bind( Operation *op, SlapReply *rs )
4470 if ( be_isroot_pw( op ) ) {
4471 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
4472 /* frontend sends result */
4473 return LDAP_SUCCESS;
4476 rs->sr_err = LDAP_INVALID_CREDENTIALS;
4477 send_ldap_result( op, rs );
4483 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
4487 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
4489 rs->sr_attrs = op->ors_attrs;
4490 rs->sr_entry = ce->ce_entry;
4492 rc = send_search_entry( op, rs );
4493 if ( rc != LDAP_SUCCESS ) {
4497 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
4498 if ( ce->ce_kids ) {
4499 rc = config_send( op, rs, ce->ce_kids, 1 );
4500 if ( rc ) return rc;
4503 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
4504 rc = config_send( op, rs, ce, 0 );
4512 static ConfigTable *
4513 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
4518 for (j=0; j<nocs; j++) {
4519 for (i=0; colst[j]->co_table[i].name; i++)
4520 if ( colst[j]->co_table[i].ad == ad ) {
4521 ca->table = colst[j]->co_type;
4522 return &colst[j]->co_table[i];
4528 /* Sort the attributes of the entry according to the order defined
4529 * in the objectclass, with required attributes occurring before
4530 * allowed attributes. For any attributes with sequencing dependencies
4531 * (e.g., rootDN must be defined after suffix) the objectclass must
4532 * list the attributes in the desired sequence.
4535 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
4537 Attribute *a, *head = NULL, *tail = NULL, **prev;
4540 for (i=0; i<nocs; i++) {
4541 if ( colst[i]->co_oc->soc_required ) {
4542 AttributeType **at = colst[i]->co_oc->soc_required;
4543 for (j=0; at[j]; j++) {
4544 for (a=e->e_attrs, prev=&e->e_attrs; a;
4545 prev = &(*prev)->a_next, a=a->a_next) {
4546 if ( a->a_desc == at[j]->sat_ad ) {
4560 if ( colst[i]->co_oc->soc_allowed ) {
4561 AttributeType **at = colst[i]->co_oc->soc_allowed;
4562 for (j=0; at[j]; j++) {
4563 for (a=e->e_attrs, prev=&e->e_attrs; a;
4564 prev = &(*prev)->a_next, a=a->a_next) {
4565 if ( a->a_desc == at[j]->sat_ad ) {
4581 tail->a_next = e->e_attrs;
4587 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
4589 Attribute *a = NULL;
4590 AttributeDescription *ad;
4600 Modifications *ml = ptr;
4602 vals = ml->sml_values;
4605 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
4606 rc = ordered_value_sort( a, 1 );
4608 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
4609 ad->ad_cname.bv_val );
4613 for ( i=0; vals[i].bv_val; i++ ) {
4614 ca->line = vals[i].bv_val;
4615 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
4616 ca->line[0] == '{' ) {
4617 char *idx = strchr( ca->line, '}' );
4618 if ( idx ) ca->line = idx+1;
4620 rc = config_parse_vals( ct, ca, i );
4629 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
4632 struct berval rtype, rval;
4634 AttributeDescription *ad = NULL;
4636 dnRdn( &e->e_name, rdn );
4637 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
4638 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
4639 rtype.bv_val = rdn->bv_val;
4640 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
4643 slap_bv2ad( &rtype, &ad, &rs->sr_text );
4644 a = attr_find( e->e_attrs, ad );
4645 if (!a ) return LDAP_NAMING_VIOLATION;
4652 config_rename_kids( CfEntryInfo *ce )
4655 struct berval rdn, nrdn;
4657 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
4658 struct berval newdn, newndn;
4659 dnRdn ( &ce2->ce_entry->e_name, &rdn );
4660 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
4661 build_new_dn( &newdn, &ce->ce_entry->e_name, &rdn, NULL );
4662 build_new_dn( &newndn, &ce->ce_entry->e_nname, &nrdn, NULL );
4663 free( ce2->ce_entry->e_name.bv_val );
4664 free( ce2->ce_entry->e_nname.bv_val );
4665 ce2->ce_entry->e_name = newdn;
4666 ce2->ce_entry->e_nname = newndn;
4667 config_rename_kids( ce2 );
4672 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
4673 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
4674 struct berval *nnewrdn, int use_ldif )
4678 struct berval odn, ondn;
4682 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
4683 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
4686 free( a->a_vals[0].bv_val );
4687 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
4688 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
4689 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
4690 strcpy( a->a_vals[0].bv_val, ptr1 );
4692 if ( a->a_nvals != a->a_vals ) {
4693 free( a->a_nvals[0].bv_val );
4694 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
4695 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
4696 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
4697 strcpy( a->a_nvals[0].bv_val, ptr1 );
4700 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
4701 BackendDB *be = op->o_bd;
4702 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4703 struct berval dn, ndn, xdn, xndn;
4705 op->o_bd = &cfb->cb_db;
4707 /* Save current rootdn; use the underlying DB's rootdn */
4711 xndn = op->o_req_ndn;
4712 op->o_dn = op->o_bd->be_rootdn;
4713 op->o_ndn = op->o_bd->be_rootndn;
4715 op->o_req_ndn = ondn;
4717 scp = op->o_callback;
4718 op->o_callback = ≻
4719 op->orr_newrdn = *newrdn;
4720 op->orr_nnewrdn = *nnewrdn;
4721 op->orr_newSup = NULL;
4722 op->orr_nnewSup = NULL;
4723 op->orr_deleteoldrdn = 1;
4724 op->orr_modlist = NULL;
4725 slap_modrdn2mods( op, rs );
4726 slap_mods_opattrs( op, &op->orr_modlist, 1 );
4727 rc = op->o_bd->be_modrdn( op, rs );
4728 slap_mods_free( op->orr_modlist, 1 );
4731 op->o_callback = scp;
4735 op->o_req_ndn = xndn;
4738 free( ondn.bv_val );
4740 config_rename_kids( e->e_private );
4745 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
4746 Entry *e, int idx, int tailindex, int use_ldif )
4748 struct berval ival, newrdn, nnewrdn;
4751 char ibuf[32], *ptr1, *ptr2 = NULL;
4754 rc = config_rename_attr( rs, e, &rdn, &a );
4755 if ( rc ) return rc;
4758 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
4759 if ( ival.bv_len >= sizeof( ibuf ) ) {
4760 return LDAP_NAMING_VIOLATION;
4763 newrdn.bv_len = rdn.bv_len + ival.bv_len;
4764 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
4767 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
4768 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4771 ptr2 = ber_bvchr( &rdn, '}' );
4775 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
4777 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
4778 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
4779 a->a_desc->ad_cname.bv_len );
4781 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4782 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
4786 /* Do the equivalent of ModRDN */
4787 /* Replace DN / NDN */
4788 newrdn.bv_len = ptr1 - newrdn.bv_val;
4789 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
4790 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
4792 free( nnewrdn.bv_val );
4793 free( newrdn.bv_val );
4798 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
4799 SlapReply *rs, int *renum, int *ibase )
4802 int index = -1, gotindex = 0, nsibs, rc = 0;
4803 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
4804 char *ptr1, *ptr2 = NULL;
4807 if ( renum ) *renum = 0;
4809 /* These entries don't get indexed/renumbered */
4810 if ( ce_type == Cft_Global ) return 0;
4811 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
4813 if ( ce_type == Cft_Module )
4816 /* See if the rdn has an index already */
4817 dnRdn( &e->e_name, &rdn );
4818 if ( ce_type == Cft_Database ) {
4819 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
4820 "frontend", STRLENOF("frontend") ))
4822 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
4823 "config", STRLENOF("config") ))
4826 ptr1 = ber_bvchr( &e->e_name, '{' );
4827 if ( ptr1 && ptr1 < &e->e_name.bv_val[ rdn.bv_len ] ) {
4829 ptr2 = strchr( ptr1, '}' );
4830 if ( !ptr2 || ptr2 > &e->e_name.bv_val[ rdn.bv_len ] )
4831 return LDAP_NAMING_VIOLATION;
4832 if ( ptr2-ptr1 == 1)
4833 return LDAP_NAMING_VIOLATION;
4835 index = strtol( ptr1 + 1, &next, 10 );
4836 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
4837 return LDAP_NAMING_VIOLATION;
4840 /* Special case, we allow -1 for the frontendDB */
4841 if ( index != -1 || !isfrontend )
4842 return LDAP_NAMING_VIOLATION;
4844 if ( isconfig && index != 0 ){
4845 return LDAP_NAMING_VIOLATION;
4849 /* count related kids.
4850 * For entries of type Cft_Misc, only count siblings with same RDN type
4852 if ( ce_type == Cft_Misc ) {
4853 rdn.bv_val = e->e_nname.bv_val;
4854 ptr1 = strchr( rdn.bv_val, '=' );
4855 assert( ptr1 != NULL );
4857 rdn.bv_len = ptr1 - rdn.bv_val;
4859 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
4861 if ( ce->ce_type != ce_type )
4864 dnRdn( &ce->ce_entry->e_nname, &rdn2 );
4866 ptr1 = strchr( rdn2.bv_val, '=' );
4867 assert( ptr1 != NULL );
4869 rdn2.bv_len = ptr1 - rdn2.bv_val;
4870 if ( bvmatch( &rdn, &rdn2 ))
4874 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
4875 if ( ce->ce_type == ce_type ) nsibs++;
4879 /* account for -1 frontend */
4880 if ( ce_type == Cft_Database )
4883 if ( index != nsibs ) {
4885 if ( index < nsibs ) {
4886 if ( tailindex ) return LDAP_NAMING_VIOLATION;
4887 /* Siblings need to be renumbered */
4888 if ( index != -1 || !isfrontend )
4892 /* config DB is always "0" */
4893 if ( isconfig && index == -1 ) {
4896 if (( !isfrontend && index == -1 ) || ( index > nsibs ) ){
4900 /* just make index = nsibs */
4902 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
4905 if ( ibase ) *ibase = index;
4906 if ( renum ) *renum = renumber;
4910 /* Insert all superior classes of the given class */
4912 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
4917 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
4918 if ( count_oc( *sups, copp, nocs ) ) {
4923 co.co_name = &oc->soc_cname;
4924 cop = avl_find( CfOcTree, &co, CfOc_cmp );
4928 /* check for duplicates */
4929 for ( i = 0; i < *nocs; i++ ) {
4930 if ( *copp && (*copp)[i] == cop ) {
4936 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
4937 if ( tmp == NULL ) {
4941 (*copp)[*nocs] = cop;
4949 /* Find all superior classes of the given objectclasses,
4950 * return list in order of most-subordinate first.
4952 * Special / auxiliary / Cft_Misc classes always take precedence.
4955 count_ocs( Attribute *oc_at, int *nocs )
4957 int i, j, misc = -1;
4958 ConfigOCs **colst = NULL;
4962 for ( i = oc_at->a_numvals; i--; ) {
4963 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
4965 assert( oc != NULL );
4966 if ( count_oc( oc, &colst, nocs ) ) {
4976 ConfigOCs *tmp = colst[i];
4977 colst[i] = colst[j];
4979 if (tmp->co_type == Cft_Misc)
4983 /* Move misc class to front of list */
4985 ConfigOCs *tmp = colst[misc];
4986 for (i=misc; i>0; i--)
4987 colst[i] = colst[i-1];
4995 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4997 /* Leftover from RE23. Never parse this entry */
4998 return LDAP_COMPARE_TRUE;
5002 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
5006 /* This entry is hardcoded, don't re-parse it */
5007 if ( p->ce_type == Cft_Global ) {
5008 cfn = p->ce_private;
5009 ca->ca_private = cfn;
5010 return LDAP_COMPARE_TRUE;
5012 if ( p->ce_type != Cft_Schema )
5013 return LDAP_CONSTRAINT_VIOLATION;
5015 cfn = ch_calloc( 1, sizeof(ConfigFile) );
5016 ca->ca_private = cfn;
5017 cfo = p->ce_private;
5018 cfn->c_sibs = cfo->c_kids;
5020 return LDAP_SUCCESS;
5024 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
5026 if ( p->ce_type != Cft_Global ) {
5027 return LDAP_CONSTRAINT_VIOLATION;
5029 /* config must be {0}, nothing else allowed */
5030 if ( !strncmp( e->e_nname.bv_val, "olcDatabase={0}", STRLENOF("olcDatabase={0}")) &&
5031 strncmp( e->e_nname.bv_val + STRLENOF("olcDatabase={0}"), "config,", STRLENOF("config,") )) {
5032 return LDAP_CONSTRAINT_VIOLATION;
5034 ca->be = frontendDB; /* just to get past check_vals */
5035 return LDAP_SUCCESS;
5039 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
5041 if ( p->ce_type != Cft_Global ) {
5042 return LDAP_CONSTRAINT_VIOLATION;
5044 return LDAP_SUCCESS;
5048 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
5050 if ( p->ce_type != Cft_Global ) {
5051 return LDAP_CONSTRAINT_VIOLATION;
5053 return LDAP_SUCCESS;
5057 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
5059 if ( p->ce_type != Cft_Database ) {
5060 return LDAP_CONSTRAINT_VIOLATION;
5063 return LDAP_SUCCESS;
5067 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
5072 AttributeDescription *ad;
5078 if ( cfn->c_cr_head ) {
5079 struct berval bv = BER_BVC("olcDitContentRules");
5081 slap_bv2ad( &bv, &ad, &text );
5082 ct = config_find_table( colst, nocs, ad, ca );
5083 config_del_vals( ct, ca );
5085 if ( cfn->c_oc_head ) {
5086 struct berval bv = BER_BVC("olcObjectClasses");
5088 slap_bv2ad( &bv, &ad, &text );
5089 ct = config_find_table( colst, nocs, ad, ca );
5090 config_del_vals( ct, ca );
5092 if ( cfn->c_at_head ) {
5093 struct berval bv = BER_BVC("olcAttributeTypes");
5095 slap_bv2ad( &bv, &ad, &text );
5096 ct = config_find_table( colst, nocs, ad, ca );
5097 config_del_vals( ct, ca );
5099 if ( cfn->c_syn_head ) {
5100 struct berval bv = BER_BVC("olcLdapSyntaxes");
5102 slap_bv2ad( &bv, &ad, &text );
5103 ct = config_find_table( colst, nocs, ad, ca );
5104 config_del_vals( ct, ca );
5106 if ( cfn->c_om_head ) {
5107 struct berval bv = BER_BVC("olcObjectIdentifier");
5109 slap_bv2ad( &bv, &ad, &text );
5110 ct = config_find_table( colst, nocs, ad, ca );
5111 config_del_vals( ct, ca );
5113 cfo = p->ce_private;
5114 cfo->c_kids = cfn->c_sibs;
5119 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
5121 int rc = LDAP_CONSTRAINT_VIOLATION;
5124 if ( (*cop)->co_ldadd ) {
5125 rc = (*cop)->co_ldadd( last, e, ca );
5126 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
5131 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
5132 ConfigOCs co = { 0 };
5134 co.co_name = &(*ocp)->soc_cname;
5135 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
5136 if ( *cop == NULL ) {
5140 rc = config_add_oc( cop, last, e, ca );
5141 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
5149 /* Parse an LDAP entry into config directives */
5151 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
5152 int *renum, Operation *op )
5154 CfEntryInfo *ce, *last = NULL;
5155 ConfigOCs co, *coptr, **colst;
5156 Attribute *a, *oc_at, *soc_at;
5157 int i, ibase = -1, nocs, rc = 0;
5160 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
5162 memset( ca, 0, sizeof(ConfigArgs));
5164 /* Make sure parent exists and entry does not. But allow
5165 * Databases and Overlays to be inserted. Don't do any
5166 * auto-renumbering if manageDSAit control is present.
5168 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
5170 if ( ( op && op->o_managedsait ) ||
5171 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
5172 ce->ce_type != Cft_Module ) )
5174 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5175 "DN=\"%s\" already exists\n",
5176 log_prefix, e->e_name.bv_val, 0 );
5177 /* global schema ignores all writes */
5178 if ( ce->ce_type == Cft_Schema && ce->ce_parent->ce_type == Cft_Global )
5179 return LDAP_COMPARE_TRUE;
5180 return LDAP_ALREADY_EXISTS;
5184 dnParent( &e->e_nname, &pdn );
5186 /* If last is NULL, the new entry is the root/suffix entry,
5187 * otherwise last should be the parent.
5189 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
5191 rs->sr_matched = last->ce_entry->e_name.bv_val;
5193 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5194 "DN=\"%s\" not child of DN=\"%s\"\n",
5195 log_prefix, e->e_name.bv_val,
5196 last->ce_entry->e_name.bv_val );
5197 return LDAP_NO_SUCH_OBJECT;
5201 /* No parent, must be root. This will never happen... */
5202 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
5203 return LDAP_NO_SUCH_OBJECT;
5206 if ( last && !access_allowed( op, last->ce_entry,
5207 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
5209 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5210 "DN=\"%s\" no write access to \"children\" of parent\n",
5211 log_prefix, e->e_name.bv_val, 0 );
5212 return LDAP_INSUFFICIENT_ACCESS;
5216 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5218 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5219 "DN=\"%s\" no objectClass\n",
5220 log_prefix, e->e_name.bv_val, 0 );
5221 return LDAP_OBJECT_CLASS_VIOLATION;
5224 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
5226 ObjectClass *soc = NULL;
5227 char textbuf[ SLAP_TEXT_BUFLEN ];
5228 const char *text = textbuf;
5230 /* FIXME: check result */
5231 rc = structural_class( oc_at->a_nvals, &soc, NULL,
5232 &text, textbuf, sizeof(textbuf), NULL );
5233 if ( rc != LDAP_SUCCESS ) {
5234 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5235 "DN=\"%s\" no structural objectClass (%s)\n",
5236 log_prefix, e->e_name.bv_val, text );
5239 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
5240 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
5241 if ( soc_at == NULL ) {
5242 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5243 "DN=\"%s\" no structural objectClass; "
5244 "unable to merge computed class %s\n",
5245 log_prefix, e->e_name.bv_val,
5246 soc->soc_cname.bv_val );
5247 return LDAP_OBJECT_CLASS_VIOLATION;
5250 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5251 "DN=\"%s\" no structural objectClass; "
5252 "computed objectClass %s merged\n",
5253 log_prefix, e->e_name.bv_val,
5254 soc->soc_cname.bv_val );
5257 /* Fake the coordinates based on whether we're part of an
5258 * LDAP Add or if reading the config dir
5261 ca->fname = "slapd";
5264 ca->fname = cfdir.bv_val;
5269 co.co_name = &soc_at->a_nvals[0];
5270 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
5271 if ( coptr == NULL ) {
5272 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5273 "DN=\"%s\" no structural objectClass in configuration table\n",
5274 log_prefix, e->e_name.bv_val, 0 );
5275 return LDAP_OBJECT_CLASS_VIOLATION;
5278 /* Only the root can be Cft_Global, everything else must
5279 * have a parent. Only limited nesting arrangements are allowed.
5281 rc = LDAP_CONSTRAINT_VIOLATION;
5282 if ( coptr->co_type == Cft_Global && !last ) {
5283 cfn = cfb->cb_config;
5284 ca->ca_private = cfn;
5285 ca->be = frontendDB; /* just to get past check_vals */
5289 colst = count_ocs( oc_at, &nocs );
5291 /* Check whether the Add is allowed by its parent, and do
5292 * any necessary arg setup
5295 rc = config_add_oc( &coptr, last, e, ca );
5296 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
5297 for ( i = 0; i<nocs; i++ ) {
5298 /* Already checked these */
5299 if ( colst[i]->co_oc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
5301 if ( colst[i]->co_ldadd &&
5302 ( rc = colst[i]->co_ldadd( last, e, ca ))
5303 != LDAP_CONSTRAINT_VIOLATION ) {
5309 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
5310 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5311 "DN=\"%s\" no structural objectClass add function\n",
5312 log_prefix, e->e_name.bv_val, 0 );
5313 return LDAP_OBJECT_CLASS_VIOLATION;
5317 /* Add the entry but don't parse it, we already have its contents */
5318 if ( rc == LDAP_COMPARE_TRUE ) {
5323 if ( rc != LDAP_SUCCESS )
5326 /* Parse all the values and check for simple syntax errors before
5327 * performing any set actions.
5329 * If doing an LDAPadd, check for indexed names and any necessary
5330 * renaming/renumbering. Entries that don't need indexed names are
5331 * ignored. Entries that need an indexed name and arrive without one
5332 * are assigned to the end. Entries that arrive with an index may
5333 * cause the following entries to be renumbered/bumped down.
5335 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
5336 * don't allow Adding an entry with an index that's already in use.
5337 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
5339 * These entries can have auto-assigned indexes (appended to the end)
5340 * but only the other types support auto-renumbering of siblings.
5343 rc = check_name_index( last, coptr->co_type, e, rs, renum,
5348 if ( renum && *renum && coptr->co_type != Cft_Database &&
5349 coptr->co_type != Cft_Overlay )
5351 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
5352 "operation requires sibling renumbering" );
5353 rc = LDAP_UNWILLING_TO_PERFORM;
5358 init_config_argv( ca );
5360 /* Make sure we process attrs in the required order */
5361 sort_attrs( e, colst, nocs );
5363 for ( a = e->e_attrs; a; a = a->a_next ) {
5364 if ( a == oc_at ) continue;
5365 ct = config_find_table( colst, nocs, a->a_desc, ca );
5366 if ( !ct ) continue; /* user data? */
5367 rc = check_vals( ct, ca, a, 1 );
5368 if ( rc ) goto done_noop;
5371 /* Basic syntax checks are OK. Do the actual settings. */
5372 for ( a=e->e_attrs; a; a=a->a_next ) {
5373 if ( a == oc_at ) continue;
5374 ct = config_find_table( colst, nocs, a->a_desc, ca );
5375 if ( !ct ) continue; /* user data? */
5376 for (i=0; a->a_vals[i].bv_val; i++) {
5379 ca->line = a->a_vals[i].bv_val;
5380 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
5381 ptr = strchr( ca->line, '}' );
5383 iptr = strchr( ca->line, '{' );
5387 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
5389 ca->valx = strtol( iptr+1, NULL, 0 );
5394 rc = config_parse_add( ct, ca, i );
5402 /* Newly added databases and overlays need to be started up */
5403 if ( CONFIG_ONLINE_ADD( ca )) {
5404 if ( coptr->co_type == Cft_Database ) {
5405 rc = backend_startup_one( ca->be, &ca->reply );
5407 } else if ( coptr->co_type == Cft_Overlay ) {
5408 if ( ca->bi->bi_db_open ) {
5409 BackendInfo *bi_orig = ca->be->bd_info;
5410 ca->be->bd_info = ca->bi;
5411 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
5412 ca->be->bd_info = bi_orig;
5414 } else if ( ca->cleanup ) {
5415 rc = ca->cleanup( ca );
5418 if (ca->cr_msg[0] == '\0')
5419 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
5421 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
5422 ca->log, ca->cr_msg, ca->argv[1] );
5429 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5430 ce->ce_parent = last;
5431 ce->ce_entry = entry_dup( e );
5432 ce->ce_entry->e_private = ce;
5433 ce->ce_type = coptr->co_type;
5436 ce->ce_private = ca->ca_private;
5437 ca->ca_entry = ce->ce_entry;
5440 } else if ( last->ce_kids ) {
5441 CfEntryInfo *c2, **cprev;
5443 /* Advance to first of this type */
5444 cprev = &last->ce_kids;
5445 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
5446 cprev = &c2->ce_sibs;
5449 /* Account for the (-1) frontendDB entry */
5450 if ( ce->ce_type == Cft_Database ) {
5451 if ( ca->be == frontendDB )
5453 else if ( ibase != -1 )
5458 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
5459 cprev = &c2->ce_sibs;
5465 for ( i=0; i<ibase; i++ ) {
5467 cprev = &c2->ce_sibs;
5470 ce->ce_sibs = *cprev;
5478 if ( (coptr->co_type == Cft_Database) && ca->be ) {
5479 if ( ca->be != frontendDB )
5480 backend_destroy_one( ca->be, 1 );
5481 } else if ( (coptr->co_type == Cft_Overlay) && ca->bi ) {
5482 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
5483 } else if ( coptr->co_type == Cft_Schema ) {
5484 schema_destroy_one( ca, colst, nocs, last );
5489 ch_free( ca->argv );
5490 if ( colst ) ch_free( colst );
5494 #define BIGTMP 10000
5496 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5497 int base, int rebase, int max, int use_ldif )
5499 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
5500 ConfigType etype = ce->ce_type;
5501 int count = 0, rc = 0;
5503 /* Reverse ce list */
5504 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
5505 if (ce2->ce_type != etype) {
5510 ce2->ce_sibs = cetmp;
5513 if ( max && count >= max ) {
5519 /* Move original to a temp name until increments are done */
5521 ce->ce_entry->e_private = NULL;
5522 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5523 base+BIGTMP, 0, use_ldif );
5524 ce->ce_entry->e_private = ce;
5526 /* start incrementing */
5527 for (ce2=cetmp; ce2; ce2=ce3) {
5529 ce2->ce_sibs = cerem;
5532 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5533 count+base, 0, use_ldif );
5537 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5538 base, 0, use_ldif );
5543 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5544 CfEntryInfo *ce2, int old, int use_ldif )
5548 /* Renumber original to a temp value */
5549 ce->ce_entry->e_private = NULL;
5550 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5551 old+BIGTMP, 0, use_ldif );
5552 ce->ce_entry->e_private = ce;
5554 /* start decrementing */
5555 for (; ce2 != ce; ce2=ce2->ce_sibs) {
5556 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5557 count+old, 0, use_ldif );
5560 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5561 count+old, 0, use_ldif );
5564 /* Parse an LDAP entry into config directives, then store in underlying
5568 config_back_add( Operation *op, SlapReply *rs )
5574 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
5575 NULL, ACL_WADD, NULL )) {
5576 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5581 * Check for attribute ACL
5583 if ( !acl_check_modlist( op, op->ora_e, op->orm_modlist )) {
5584 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5585 rs->sr_text = "no write access to attribute";
5589 cfb = (CfBackInfo *)op->o_bd->be_private;
5591 /* add opattrs for syncprov */
5593 char textbuf[SLAP_TEXT_BUFLEN];
5594 size_t textlen = sizeof textbuf;
5595 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1, NULL,
5596 &rs->sr_text, textbuf, sizeof( textbuf ) );
5597 if ( rs->sr_err != LDAP_SUCCESS )
5599 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
5600 if ( rs->sr_err != LDAP_SUCCESS ) {
5601 Debug( LDAP_DEBUG_TRACE,
5602 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
5603 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
5608 if ( op->o_abandon ) {
5609 rs->sr_err = SLAPD_ABANDON;
5612 ldap_pvt_thread_pool_pause( &connection_pool );
5615 * 1) check for existence of entry
5616 * 2) check for sibling renumbering
5617 * 3) perform internal add
5618 * 4) perform any necessary renumbering
5619 * 5) store entry in underlying database
5621 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
5622 if ( rs->sr_err != LDAP_SUCCESS ) {
5623 rs->sr_text = ca.cr_msg;
5628 CfEntryInfo *ce = ca.ca_entry->e_private;
5629 req_add_s addr = op->oq_add;
5630 op->o_tag = LDAP_REQ_MODRDN;
5631 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
5632 op->o_tag = LDAP_REQ_ADD;
5634 if ( rs->sr_err != LDAP_SUCCESS ) {
5639 if ( cfb->cb_use_ldif ) {
5640 BackendDB *be = op->o_bd;
5641 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5642 struct berval dn, ndn;
5644 op->o_bd = &cfb->cb_db;
5646 /* Save current rootdn; use the underlying DB's rootdn */
5649 op->o_dn = op->o_bd->be_rootdn;
5650 op->o_ndn = op->o_bd->be_rootndn;
5652 scp = op->o_callback;
5653 op->o_callback = ≻
5654 op->o_bd->be_add( op, rs );
5656 op->o_callback = scp;
5662 ldap_pvt_thread_pool_resume( &connection_pool );
5665 { int repl = op->o_dont_replicate;
5666 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
5667 rs->sr_text = NULL; /* Set after config_add_internal */
5668 rs->sr_err = LDAP_SUCCESS;
5669 op->o_dont_replicate = 1;
5671 send_ldap_result( op, rs );
5672 op->o_dont_replicate = repl;
5674 slap_graduate_commit_csn( op );
5678 typedef struct delrec {
5679 struct delrec *next;
5685 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
5691 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
5692 ca->line[0] == '{' )
5694 char *ptr = strchr( ca->line + 1, '}' );
5698 ca->valx = strtol( ca->line + 1, &next, 0 );
5699 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
5705 rc = config_parse_add( ct, ca, i );
5713 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
5716 int rc = LDAP_UNWILLING_TO_PERFORM;
5718 Entry *e = ce->ce_entry;
5719 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
5724 delrec *dels = NULL, *deltail = NULL;
5726 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5727 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
5729 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5730 if (ml->sml_desc == slap_schema.si_ad_objectClass)
5734 colst = count_ocs( oc_at, &nocs );
5736 /* make sure add/del flags are clear; should always be true */
5737 for ( s = save_attrs; s; s = s->a_next ) {
5738 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
5741 e->e_attrs = attrs_dup( e->e_attrs );
5743 init_config_argv( ca );
5746 ca->ca_private = ce->ce_private;
5748 ca->fname = "slapd";
5750 strcpy( ca->log, "back-config" );
5752 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5753 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5754 switch (ml->sml_op) {
5755 case LDAP_MOD_DELETE:
5756 case LDAP_MOD_REPLACE:
5757 case SLAP_MOD_SOFTDEL:
5759 BerVarray vals = NULL, nvals = NULL;
5761 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
5763 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
5764 ml->sml_desc->ad_cname.bv_val );
5767 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5768 vals = ml->sml_values;
5769 nvals = ml->sml_nvalues;
5770 ml->sml_values = NULL;
5771 ml->sml_nvalues = NULL;
5773 /* If we're deleting by values, remember the indexes of the
5774 * values we deleted.
5776 if ( ct && ml->sml_values ) {
5778 i = ml->sml_numvals;
5779 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
5790 rc = modify_delete_vindex(e, &ml->sml_mod,
5791 get_permissiveModify(op),
5792 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
5793 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5794 ml->sml_values = vals;
5795 ml->sml_nvalues = nvals;
5797 if ( rc == LDAP_NO_SUCH_ATTRIBUTE && ml->sml_op == SLAP_MOD_SOFTDEL )
5801 /* FIXME: check rc before fallthru? */
5805 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5807 case SLAP_MOD_ADD_IF_NOT_PRESENT:
5808 if ( ml->sml_op == SLAP_MOD_ADD_IF_NOT_PRESENT
5809 && attr_find( e->e_attrs, ml->sml_desc ) )
5816 case SLAP_MOD_SOFTADD: {
5817 int mop = ml->sml_op;
5819 ml->sml_op = LDAP_MOD_ADD;
5821 if ( ct->arg_type & ARG_NO_INSERT ) {
5822 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
5824 navals = a->a_numvals;
5827 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
5828 if ( ml->sml_values[i].bv_val[0] == '{' &&
5831 char *next, *val = ml->sml_values[i].bv_val + 1;
5834 j = strtol( val, &next, 0 );
5835 if ( next == val || next[ 0 ] != '}' || j < navals ) {
5837 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
5838 ml->sml_desc->ad_cname.bv_val );
5842 rc = check_vals( ct, ca, ml, 0 );
5843 if ( rc ) goto out_noop;
5846 rc = modify_add_values(e, &ml->sml_mod,
5847 get_permissiveModify(op),
5848 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5850 /* If value already exists, show success here
5851 * and ignore this operation down below.
5853 if ( mop == SLAP_MOD_SOFTADD ) {
5854 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
5864 case LDAP_MOD_INCREMENT: /* FIXME */
5869 if(rc != LDAP_SUCCESS) break;
5872 if ( rc == LDAP_SUCCESS) {
5873 /* check that the entry still obeys the schema */
5874 rc = entry_schema_check(op, e, NULL, 0, 0, NULL,
5875 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5877 if ( rc ) goto out_noop;
5879 /* Basic syntax checks are OK. Do the actual settings. */
5880 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5881 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5882 if ( !ct ) continue;
5884 s = attr_find( save_attrs, ml->sml_desc );
5885 a = attr_find( e->e_attrs, ml->sml_desc );
5887 switch (ml->sml_op) {
5888 case LDAP_MOD_DELETE:
5889 case LDAP_MOD_REPLACE: {
5890 BerVarray vals = NULL, nvals = NULL;
5893 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5894 vals = ml->sml_values;
5895 nvals = ml->sml_nvalues;
5896 ml->sml_values = NULL;
5897 ml->sml_nvalues = NULL;
5900 if ( ml->sml_values )
5903 /* If we didn't delete the whole attribute */
5904 if ( ml->sml_values && a ) {
5905 struct berval *mvals;
5908 if ( ml->sml_nvalues )
5909 mvals = ml->sml_nvalues;
5911 mvals = ml->sml_values;
5913 /* use the indexes we saved up above */
5914 for (i=0; i < d->nidx; i++) {
5915 struct berval bv = *mvals++;
5916 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
5917 bv.bv_val[0] == '{' ) {
5918 ptr = strchr( bv.bv_val, '}' ) + 1;
5919 bv.bv_len -= ptr - bv.bv_val;
5922 ca->line = bv.bv_val;
5923 ca->valx = d->idx[i];
5924 config_parse_vals(ct, ca, d->idx[i] );
5925 rc = config_del_vals( ct, ca );
5926 if ( rc != LDAP_SUCCESS ) break;
5928 s->a_flags |= SLAP_ATTR_IXDEL;
5929 for (j=i+1; j < d->nidx; j++)
5930 if ( d->idx[j] >d->idx[i] )
5937 rc = config_del_vals( ct, ca );
5938 if ( rc ) rc = LDAP_OTHER;
5940 s->a_flags |= SLAP_ATTR_IXDEL;
5942 if ( ml->sml_values ) {
5947 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5948 ml->sml_values = vals;
5949 ml->sml_nvalues = nvals;
5951 if ( !vals || rc != LDAP_SUCCESS )
5954 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5959 for (i=0; ml->sml_values[i].bv_val; i++) {
5960 ca->line = ml->sml_values[i].bv_val;
5962 rc = config_modify_add( ct, ca, ml->sml_desc, i );
5965 a->a_flags |= SLAP_ATTR_IXADD;
5972 /* Undo for a failed operation */
5973 if ( rc != LDAP_SUCCESS ) {
5974 ConfigReply msg = ca->reply;
5975 for ( s = save_attrs; s; s = s->a_next ) {
5976 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
5977 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5978 ct = config_find_table( colst, nocs, s->a_desc, ca );
5979 a = attr_find( e->e_attrs, s->a_desc );
5981 /* clear the flag so the add check below will skip it */
5982 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5986 config_del_vals( ct, ca );
5988 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5989 ca->line = s->a_vals[i].bv_val;
5991 config_modify_add( ct, ca, s->a_desc, i );
5995 for ( a = e->e_attrs; a; a = a->a_next ) {
5996 if ( a->a_flags & SLAP_ATTR_IXADD ) {
5997 ct = config_find_table( colst, nocs, a->a_desc, ca );
6001 config_del_vals( ct, ca );
6002 s = attr_find( save_attrs, a->a_desc );
6004 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
6005 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
6006 ca->line = s->a_vals[i].bv_val;
6008 config_modify_add( ct, ca, s->a_desc, i );
6016 if ( ca->cleanup ) {
6017 i = ca->cleanup( ca );
6018 if (rc == LDAP_SUCCESS)
6022 if ( rc == LDAP_SUCCESS ) {
6023 attrs_free( save_attrs );
6026 attrs_free( e->e_attrs );
6027 e->e_attrs = save_attrs;
6029 ch_free( ca->argv );
6030 if ( colst ) ch_free( colst );
6032 deltail = dels->next;
6041 config_back_modify( Operation *op, SlapReply *rs )
6044 CfEntryInfo *ce, *last;
6046 ConfigArgs ca = {0};
6049 AttributeDescription *rad = NULL;
6052 cfb = (CfBackInfo *)op->o_bd->be_private;
6054 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6057 rs->sr_matched = last->ce_entry->e_name.bv_val;
6058 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6062 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
6063 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6067 /* Get type of RDN */
6068 rdn = ce->ce_entry->e_nname;
6069 ptr = strchr( rdn.bv_val, '=' );
6070 rdn.bv_len = ptr - rdn.bv_val;
6071 rs->sr_err = slap_bv2ad( &rdn, &rad, &rs->sr_text );
6072 if ( rs->sr_err != LDAP_SUCCESS ) {
6076 /* Some basic validation... */
6077 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
6078 /* Don't allow Modify of RDN; must use ModRdn for that. */
6079 if ( ml->sml_desc == rad ) {
6080 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
6081 rs->sr_text = "Use modrdn to change the entry name";
6084 /* Internal update of contextCSN? */
6085 if ( ml->sml_desc == slap_schema.si_ad_contextCSN && op->o_conn->c_conn_idx == -1 ) {
6091 slap_mods_opattrs( op, &op->orm_modlist, 1 );
6094 if ( op->o_abandon ) {
6095 rs->sr_err = SLAPD_ABANDON;
6098 ldap_pvt_thread_pool_pause( &connection_pool );
6102 * 1) perform the Modify on the cached Entry.
6103 * 2) verify that the Entry still satisfies the schema.
6104 * 3) perform the individual config operations.
6105 * 4) store Modified entry in underlying LDIF backend.
6107 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
6109 rs->sr_text = ca.cr_msg;
6110 } else if ( cfb->cb_use_ldif ) {
6111 BackendDB *be = op->o_bd;
6112 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
6113 struct berval dn, ndn;
6115 op->o_bd = &cfb->cb_db;
6119 op->o_dn = op->o_bd->be_rootdn;
6120 op->o_ndn = op->o_bd->be_rootndn;
6122 scp = op->o_callback;
6123 op->o_callback = ≻
6124 op->o_bd->be_modify( op, rs );
6126 op->o_callback = scp;
6132 ldap_pvt_thread_pool_resume( &connection_pool );
6134 send_ldap_result( op, rs );
6135 slap_graduate_commit_csn( op );
6140 config_back_modrdn( Operation *op, SlapReply *rs )
6143 CfEntryInfo *ce, *last;
6147 cfb = (CfBackInfo *)op->o_bd->be_private;
6149 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6152 rs->sr_matched = last->ce_entry->e_name.bv_val;
6153 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6156 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
6157 NULL, ACL_WRITE, NULL )) {
6158 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6162 if ( ce->ce_parent )
6163 parent = ce->ce_parent->ce_entry;
6165 parent = (Entry *)&slap_entry_root;
6166 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
6167 NULL, ACL_WRITE, NULL )) {
6168 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6173 /* We don't allow moving objects to new parents.
6174 * Generally we only allow reordering a set of ordered entries.
6176 if ( op->orr_newSup ) {
6177 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6181 /* If newRDN == oldRDN, quietly succeed */
6182 dnRdn( &op->o_req_ndn, &rdn );
6183 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
6184 rs->sr_err = LDAP_SUCCESS;
6188 /* Current behavior, subject to change as needed:
6190 * For backends and overlays, we only allow renumbering.
6191 * For schema, we allow renaming with the same number.
6192 * Otherwise, the op is not allowed.
6195 if ( ce->ce_type == Cft_Schema ) {
6199 /* Can't alter the main cn=schema entry */
6200 if ( ce->ce_parent->ce_type == Cft_Global ) {
6201 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6202 rs->sr_text = "renaming not allowed for this entry";
6206 /* We could support this later if desired */
6207 ptr1 = ber_bvchr( &rdn, '}' );
6208 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
6209 len = ptr1 - rdn.bv_val;
6210 if ( len != ptr2 - op->orr_newrdn.bv_val ||
6211 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
6212 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6213 rs->sr_text = "schema reordering not supported";
6216 } else if ( ce->ce_type == Cft_Database ||
6217 ce->ce_type == Cft_Overlay ) {
6218 char *ptr1, *ptr2, *iptr1, *iptr2;
6221 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
6222 if ( *iptr2 != '{' ) {
6223 rs->sr_err = LDAP_NAMING_VIOLATION;
6224 rs->sr_text = "new ordering index is required";
6228 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
6229 ptr1 = ber_bvchr( &rdn, '}' );
6230 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
6232 rs->sr_err = LDAP_NAMING_VIOLATION;
6233 rs->sr_text = "new ordering index is required";
6237 len1 = ptr1 - rdn.bv_val;
6238 len2 = ptr2 - op->orr_newrdn.bv_val;
6240 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
6241 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
6242 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6243 rs->sr_text = "changing database/overlay type not allowed";
6246 ixold = strtol( iptr1, NULL, 0 );
6247 ixnew = strtol( iptr2, &ptr1, 0 );
6248 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
6249 rs->sr_err = LDAP_NAMING_VIOLATION;
6252 /* config DB is always 0, cannot be changed */
6253 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
6254 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
6258 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6259 rs->sr_text = "renaming not supported for this entry";
6263 if ( op->o_abandon ) {
6264 rs->sr_err = SLAPD_ABANDON;
6267 ldap_pvt_thread_pool_pause( &connection_pool );
6269 if ( ce->ce_type == Cft_Schema ) {
6270 req_modrdn_s modr = op->oq_modrdn;
6273 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
6274 if ( rs->sr_err == LDAP_SUCCESS ) {
6275 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
6276 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
6279 op->oq_modrdn = modr;
6281 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
6282 req_modrdn_s modr = op->oq_modrdn;
6285 /* Advance to first of this type */
6286 cprev = &ce->ce_parent->ce_kids;
6287 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
6288 cprev = &ce2->ce_sibs;
6291 /* Skip the -1 entry */
6292 if ( ce->ce_type == Cft_Database ) {
6293 cprev = &ce2->ce_sibs;
6299 /* Remove from old slot */
6300 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
6301 cprev = &ce2->ce_sibs;
6302 *cprev = ce->ce_sibs;
6303 ceold = ce->ce_sibs;
6305 /* Insert into new slot */
6307 for ( i=0; i<ixnew; i++ ) {
6311 cprev = &ce2->ce_sibs;
6313 ce->ce_sibs = *cprev;
6318 /* NOTE: These should be encoded in the OC tables, not inline here */
6319 if ( ce->ce_type == Cft_Database )
6320 backend_db_move( ce->ce_be, ixnew );
6321 else if ( ce->ce_type == Cft_Overlay )
6322 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
6324 if ( ixold < ixnew ) {
6325 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
6328 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
6329 ixold - ixnew, cfb->cb_use_ldif );
6331 op->oq_modrdn = modr;
6334 ldap_pvt_thread_pool_resume( &connection_pool );
6336 send_ldap_result( op, rs );
6341 config_back_delete( Operation *op, SlapReply *rs )
6343 #ifdef SLAP_CONFIG_DELETE
6345 CfEntryInfo *ce, *last, *ce2;
6347 cfb = (CfBackInfo *)op->o_bd->be_private;
6349 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6352 rs->sr_matched = last->ce_entry->e_name.bv_val;
6353 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6354 } else if ( ce->ce_kids ) {
6355 rs->sr_err = LDAP_NOT_ALLOWED_ON_NONLEAF;
6356 } else if ( op->o_abandon ) {
6357 rs->sr_err = SLAPD_ABANDON;
6358 } else if ( ce->ce_type == Cft_Overlay ||
6359 ce->ce_type == Cft_Database ||
6360 ce->ce_type == Cft_Misc ){
6364 ldap_pvt_thread_pool_pause( &connection_pool );
6366 if ( ce->ce_type == Cft_Overlay ){
6367 overlay_remove( ce->ce_be, (slap_overinst *)ce->ce_bi, op );
6368 } else if ( ce->ce_type == Cft_Misc ) {
6370 * only Cft_Misc objects that have a co_lddel handler set in
6371 * the ConfigOCs struct can be deleted. This code also
6372 * assumes that the entry can be only have one objectclass
6373 * with co_type == Cft_Misc
6375 ConfigOCs co, *coptr;
6379 oc_at = attr_find( ce->ce_entry->e_attrs,
6380 slap_schema.si_ad_objectClass );
6382 rs->sr_err = LDAP_OTHER;
6383 rs->sr_text = "objectclass not found";
6384 ldap_pvt_thread_pool_resume( &connection_pool );
6387 for ( i=0; !BER_BVISNULL(&oc_at->a_nvals[i]); i++ ) {
6388 co.co_name = &oc_at->a_nvals[i];
6389 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
6390 if ( coptr == NULL || coptr->co_type != Cft_Misc ) {
6393 if ( ! coptr->co_lddel || coptr->co_lddel( ce, op ) ){
6394 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6395 if ( ! coptr->co_lddel ) {
6396 rs->sr_text = "No delete handler found";
6398 rs->sr_err = LDAP_OTHER;
6399 /* FIXME: We should return a helpful error message
6402 ldap_pvt_thread_pool_resume( &connection_pool );
6407 } else if (ce->ce_type == Cft_Database ) {
6408 if ( ce->ce_be == frontendDB || ce->ce_be == op->o_bd ){
6409 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6410 rs->sr_text = "Cannot delete config or frontend database";
6411 ldap_pvt_thread_pool_resume( &connection_pool );
6414 if ( ce->ce_be->bd_info->bi_db_close ) {
6415 ce->ce_be->bd_info->bi_db_close( ce->ce_be, NULL );
6417 backend_destroy_one( ce->ce_be, 1);
6420 /* remove CfEntryInfo from the siblings list */
6421 if ( ce->ce_parent->ce_kids == ce ) {
6422 ce->ce_parent->ce_kids = ce->ce_sibs;
6424 for ( ce2 = ce->ce_parent->ce_kids ; ce2; ce2 = ce2->ce_sibs ) {
6425 if ( ce2->ce_sibs == ce ) {
6426 ce2->ce_sibs = ce->ce_sibs;
6432 /* remove from underlying database */
6433 if ( cfb->cb_use_ldif ) {
6434 BackendDB *be = op->o_bd;
6435 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
6436 struct berval dn, ndn, req_dn, req_ndn;
6438 op->o_bd = &cfb->cb_db;
6442 req_dn = op->o_req_dn;
6443 req_ndn = op->o_req_ndn;
6445 op->o_dn = op->o_bd->be_rootdn;
6446 op->o_ndn = op->o_bd->be_rootndn;
6447 op->o_req_dn = ce->ce_entry->e_name;
6448 op->o_req_ndn = ce->ce_entry->e_nname;
6450 scp = op->o_callback;
6451 op->o_callback = ≻
6452 op->o_bd->be_delete( op, rs );
6454 op->o_callback = scp;
6457 op->o_req_dn = req_dn;
6458 op->o_req_ndn = req_ndn;
6461 /* renumber siblings */
6462 iptr = ber_bvchr( &op->o_req_ndn, '{' ) + 1;
6463 ixold = strtol( iptr, NULL, 0 );
6464 for (ce2 = ce->ce_sibs, count=0; ce2; ce2=ce2->ce_sibs) {
6465 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
6466 count+ixold, 0, cfb->cb_use_ldif );
6470 ce->ce_entry->e_private=NULL;
6471 entry_free(ce->ce_entry);
6473 ldap_pvt_thread_pool_resume( &connection_pool );
6475 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6479 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6480 #endif /* SLAP_CONFIG_DELETE */
6481 send_ldap_result( op, rs );
6486 config_back_search( Operation *op, SlapReply *rs )
6489 CfEntryInfo *ce, *last;
6492 cfb = (CfBackInfo *)op->o_bd->be_private;
6494 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6497 rs->sr_matched = last->ce_entry->e_name.bv_val;
6498 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6501 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
6502 ACL_SEARCH, NULL, &mask ))
6504 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
6505 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6507 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6511 switch ( op->ors_scope ) {
6512 case LDAP_SCOPE_BASE:
6513 case LDAP_SCOPE_SUBTREE:
6514 rs->sr_err = config_send( op, rs, ce, 0 );
6517 case LDAP_SCOPE_ONELEVEL:
6518 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
6519 rs->sr_err = config_send( op, rs, ce, 1 );
6528 send_ldap_result( op, rs );
6532 /* no-op, we never free entries */
6533 int config_entry_release(
6538 if ( !e->e_private ) {
6541 return LDAP_SUCCESS;
6544 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
6546 int config_back_entry_get(
6550 AttributeDescription *at,
6555 CfEntryInfo *ce, *last;
6556 int rc = LDAP_NO_SUCH_OBJECT;
6558 cfb = (CfBackInfo *)op->o_bd->be_private;
6560 ce = config_find_base( cfb->cb_root, ndn, &last );
6562 *ent = ce->ce_entry;
6565 if ( oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
6566 rc = LDAP_NO_SUCH_ATTRIBUTE;
6576 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
6577 ConfigTable *ct, ConfigArgs *c )
6581 for (; at && *at; at++) {
6582 /* Skip the naming attr */
6583 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
6585 for (i=0;ct[i].name;i++) {
6586 if (ct[i].ad == (*at)->sat_ad) {
6587 rc = config_get_vals(&ct[i], c);
6588 /* NOTE: tolerate that config_get_vals()
6589 * returns success with no values */
6590 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
6591 if ( c->rvalue_nvals )
6592 rc = attr_merge(e, ct[i].ad, c->rvalue_vals,
6595 slap_syntax_validate_func *validate =
6596 ct[i].ad->ad_type->sat_syntax->ssyn_validate;
6599 for ( j=0; c->rvalue_vals[j].bv_val; j++ ) {
6600 rc = ordered_value_validate( ct[i].ad,
6601 &c->rvalue_vals[j], LDAP_MOD_ADD );
6603 Debug( LDAP_DEBUG_ANY,
6604 "config_build_attrs: error %d on %s value #%d\n",
6605 rc, ct[i].ad->ad_cname.bv_val, j );
6611 rc = attr_merge_normalize(e, ct[i].ad,
6612 c->rvalue_vals, NULL);
6614 ber_bvarray_free( c->rvalue_nvals );
6615 ber_bvarray_free( c->rvalue_vals );
6617 Debug( LDAP_DEBUG_ANY,
6618 "config_build_attrs: error %d on %s\n",
6619 rc, ct[i].ad->ad_cname.bv_val, 0 );
6630 /* currently (2010) does not access rs except possibly writing rs->sr_err */
6633 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
6634 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
6636 Entry *e = entry_alloc();
6637 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
6639 struct berval ad_name;
6640 AttributeDescription *ad = NULL;
6643 const char *text = "";
6647 CfEntryInfo *ceprev = NULL;
6649 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
6652 ce->ce_type = main->co_type;
6653 ce->ce_parent = parent;
6655 pdn = parent->ce_entry->e_nname;
6656 if ( parent->ce_kids && parent->ce_kids->ce_type <= ce->ce_type )
6657 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
6658 ceprev->ce_type <= ce->ce_type;
6659 ceprev = ceprev->ce_sibs );
6664 ce->ce_private = c->ca_private;
6668 build_new_dn( &e->e_name, &pdn, rdn, NULL );
6669 ber_dupbv( &e->e_nname, &e->e_name );
6671 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6672 main->co_name, NULL );
6674 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6675 extra->co_name, NULL );
6676 ptr = strchr(rdn->bv_val, '=');
6677 ad_name.bv_val = rdn->bv_val;
6678 ad_name.bv_len = ptr - rdn->bv_val;
6679 rc = slap_bv2ad( &ad_name, &ad, &text );
6684 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
6685 attr_merge_normalize_one(e, ad, &val, NULL );
6688 c->table = main->co_type;
6689 if ( oc->soc_required ) {
6690 rc = config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
6691 if ( rc ) goto fail;
6694 if ( oc->soc_allowed ) {
6695 rc = config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
6696 if ( rc ) goto fail;
6701 c->table = extra->co_type;
6702 if ( oc->soc_required ) {
6703 rc = config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
6704 if ( rc ) goto fail;
6707 if ( oc->soc_allowed ) {
6708 rc = config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
6709 if ( rc ) goto fail;
6713 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
6714 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
6715 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
6716 if ( rc != LDAP_SUCCESS ) {
6718 Debug( LDAP_DEBUG_ANY,
6719 "config_build_entry: build \"%s\" failed: \"%s\"\n",
6720 rdn->bv_val, text, 0);
6723 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
6726 op->ora_modlist = NULL;
6727 slap_add_opattrs( op, NULL, NULL, 0, 0 );
6728 if ( !op->o_noop ) {
6729 SlapReply rs2 = {REP_RESULT};
6730 op->o_bd->be_add( op, &rs2 );
6731 rs->sr_err = rs2.sr_err;
6732 rs_assert_done( &rs2 );
6733 if ( ( rs2.sr_err != LDAP_SUCCESS )
6734 && (rs2.sr_err != LDAP_ALREADY_EXISTS) ) {
6740 ce->ce_sibs = ceprev->ce_sibs;
6741 ceprev->ce_sibs = ce;
6742 } else if ( parent ) {
6743 ce->ce_sibs = parent->ce_kids;
6744 parent->ce_kids = ce;
6751 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
6752 Operation *op, SlapReply *rs )
6755 ConfigFile *cf = c->ca_private;
6757 struct berval bv, rdn;
6759 for (; cf; cf=cf->c_sibs, c->depth++) {
6760 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
6761 !cf->c_om_head && !cf->c_syn_head ) continue;
6762 c->value_dn.bv_val = c->log;
6763 LUTIL_SLASHPATH( cf->c_file.bv_val );
6764 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
6769 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
6771 ptr = strchr( bv.bv_val, '.' );
6773 bv.bv_len = ptr - bv.bv_val;
6774 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
6775 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6776 /* FIXME: how can indicate error? */
6779 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
6781 c->value_dn.bv_len += bv.bv_len;
6782 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
6783 rdnNormalize( 0, NULL, NULL, &c->value_dn, &rdn, NULL );
6786 e = config_build_entry( op, rs, ceparent, c, &rdn,
6787 &CFOC_SCHEMA, NULL );
6788 ch_free( rdn.bv_val );
6791 } else if ( e && cf->c_kids ) {
6792 c->ca_private = cf->c_kids;
6793 config_build_schema_inc( c, e->e_private, op, rs );
6799 #ifdef SLAPD_MODULES
6802 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
6803 Operation *op, SlapReply *rs )
6808 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
6809 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
6811 c->value_dn.bv_val = c->log;
6812 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
6813 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6814 /* FIXME: how can indicate error? */
6818 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
6827 config_check_schema(Operation *op, CfBackInfo *cfb)
6829 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
6831 CfEntryInfo *ce, *last;
6834 /* If there's no root entry, we must be in the midst of converting */
6835 if ( !cfb->cb_root )
6838 /* Make sure the main schema entry exists */
6839 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
6846 /* Make sure it's up to date */
6847 if ( cf_om_tail != om_sys_tail ) {
6848 a = attr_find( e->e_attrs, cfAd_om );
6850 if ( a->a_nvals != a->a_vals )
6851 ber_bvarray_free( a->a_nvals );
6852 ber_bvarray_free( a->a_vals );
6857 oidm_unparse( &bv, NULL, NULL, 1 );
6858 attr_merge_normalize( e, cfAd_om, bv, NULL );
6859 ber_bvarray_free( bv );
6860 cf_om_tail = om_sys_tail;
6862 if ( cf_at_tail != at_sys_tail ) {
6863 a = attr_find( e->e_attrs, cfAd_attr );
6865 if ( a->a_nvals != a->a_vals )
6866 ber_bvarray_free( a->a_nvals );
6867 ber_bvarray_free( a->a_vals );
6872 at_unparse( &bv, NULL, NULL, 1 );
6873 attr_merge_normalize( e, cfAd_attr, bv, NULL );
6874 ber_bvarray_free( bv );
6875 cf_at_tail = at_sys_tail;
6877 if ( cf_oc_tail != oc_sys_tail ) {
6878 a = attr_find( e->e_attrs, cfAd_oc );
6880 if ( a->a_nvals != a->a_vals )
6881 ber_bvarray_free( a->a_nvals );
6882 ber_bvarray_free( a->a_vals );
6887 oc_unparse( &bv, NULL, NULL, 1 );
6888 attr_merge_normalize( e, cfAd_oc, bv, NULL );
6889 ber_bvarray_free( bv );
6890 cf_oc_tail = oc_sys_tail;
6892 if ( cf_syn_tail != syn_sys_tail ) {
6893 a = attr_find( e->e_attrs, cfAd_syntax );
6895 if ( a->a_nvals != a->a_vals )
6896 ber_bvarray_free( a->a_nvals );
6897 ber_bvarray_free( a->a_vals );
6902 syn_unparse( &bv, NULL, NULL, 1 );
6903 attr_merge_normalize( e, cfAd_syntax, bv, NULL );
6904 ber_bvarray_free( bv );
6905 cf_syn_tail = syn_sys_tail;
6908 SlapReply rs = {REP_RESULT};
6909 c.ca_private = NULL;
6910 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
6911 &CFOC_SCHEMA, NULL );
6916 ce->ce_private = cfb->cb_config;
6917 cf_at_tail = at_sys_tail;
6918 cf_oc_tail = oc_sys_tail;
6919 cf_om_tail = om_sys_tail;
6920 cf_syn_tail = syn_sys_tail;
6925 static const char *defacl[] = {
6926 NULL, "to", "*", "by", "*", "none", NULL
6930 config_back_db_open( BackendDB *be, ConfigReply *cr )
6932 CfBackInfo *cfb = be->be_private;
6935 CfEntryInfo *ce, *ceparent;
6939 Connection conn = {0};
6940 OperationBuffer opbuf;
6942 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
6943 SlapReply rs = {REP_RESULT};
6944 void *thrctx = NULL;
6945 AccessControl *save_access;
6947 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
6949 /* If we have no explicitly configured ACLs, don't just use
6950 * the global ACLs. Explicitly deny access to everything.
6952 save_access = be->bd_self->be_acl;
6953 be->bd_self->be_acl = NULL;
6954 parse_acl(be->bd_self, "config_back_db_open", 0, 6, (char **)defacl, 0 );
6955 defacl_parsed = be->bd_self->be_acl;
6956 if ( save_access ) {
6957 be->bd_self->be_acl = save_access;
6959 Debug( LDAP_DEBUG_CONFIG, "config_back_db_open: "
6960 "No explicit ACL for back-config configured. "
6961 "Using hardcoded default\n", 0, 0, 0 );
6964 thrctx = ldap_pvt_thread_pool_context();
6965 connection_fake_init( &conn, &opbuf, thrctx );
6968 op->o_tag = LDAP_REQ_ADD;
6969 op->o_callback = &cb;
6970 op->o_bd = &cfb->cb_db;
6971 op->o_dn = op->o_bd->be_rootdn;
6972 op->o_ndn = op->o_bd->be_rootndn;
6974 if ( !cfb->cb_use_ldif ) {
6978 /* If we read the config from back-ldif, do some quick sanity checks */
6979 if ( cfb->cb_got_ldif ) {
6980 return config_check_schema( op, cfb );
6983 /* create root of tree */
6985 c.ca_private = cfb->cb_config;
6987 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
6997 #ifdef SLAPD_MODULES
6998 /* Create Module nodes... */
6999 if ( modpaths.mp_loads ) {
7000 if ( config_build_modules( &c, ceparent, op, &rs ) ){
7006 /* Create schema nodes... cn=schema will contain the hardcoded core
7007 * schema, read-only. Child objects will contain runtime loaded schema
7011 c.ca_private = NULL;
7012 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
7017 ce->ce_private = cfb->cb_config;
7018 cf_at_tail = at_sys_tail;
7019 cf_oc_tail = oc_sys_tail;
7020 cf_om_tail = om_sys_tail;
7021 cf_syn_tail = syn_sys_tail;
7023 /* Create schema nodes for included schema... */
7024 if ( cfb->cb_config->c_kids ) {
7027 c.ca_private = cfb->cb_config->c_kids;
7028 rc = config_build_schema_inc( &c, ce, op, &rs );
7034 /* Create backend nodes. Skip if they don't provide a cf_table.
7035 * There usually aren't any of these.
7039 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
7040 if (!bi->bi_cf_ocs) {
7041 /* If it only supports the old config mech, complain. */
7042 if ( bi->bi_config ) {
7043 Debug( LDAP_DEBUG_ANY,
7044 "WARNING: No dynamic config support for backend %s.\n",
7045 bi->bi_type, 0, 0 );
7050 if (!bi->bi_private) continue;
7053 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
7054 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
7055 if ( rdn.bv_len >= sizeof( c.log ) ) {
7056 /* FIXME: holler ... */ ;
7059 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
7066 /* Create database nodes... */
7067 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
7068 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
7069 for ( i = -1, be = frontendDB ; be;
7070 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
7071 slap_overinfo *oi = NULL;
7073 if ( overlay_is_over( be )) {
7074 oi = be->bd_info->bi_private;
7080 /* If this backend supports the old config mechanism, but not
7081 * the new mech, complain.
7083 if ( !be->be_cf_ocs && bi->bi_db_config ) {
7084 Debug( LDAP_DEBUG_ANY,
7085 "WARNING: No dynamic config support for database %s.\n",
7086 bi->bi_type, 0, 0 );
7090 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
7091 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
7093 if ( rdn.bv_len >= sizeof( c.log ) ) {
7094 /* FIXME: holler ... */ ;
7098 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
7104 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd ) {
7105 rs_reinit( &rs, REP_RESULT );
7106 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
7108 /* Iterate through overlays */
7113 voidList *vl, *v0 = NULL;
7115 /* overlays are in LIFO order, must reverse stack */
7116 for (on=oi->oi_list; on; on=on->on_next) {
7117 vl = ch_malloc( sizeof( voidList ));
7122 for (j=0; vl; j++,vl=v0) {
7126 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
7127 Debug( LDAP_DEBUG_ANY,
7128 "WARNING: No dynamic config support for overlay %s.\n",
7129 on->on_bi.bi_type, 0, 0 );
7133 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
7134 "%s=" SLAP_X_ORDERED_FMT "%s",
7135 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
7136 if ( rdn.bv_len >= sizeof( c.log ) ) {
7137 /* FIXME: holler ... */ ;
7141 oe = config_build_entry( op, &rs, ce, &c, &rdn,
7142 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
7146 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd ) {
7147 rs_reinit( &rs, REP_RESULT );
7148 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
7154 ldap_pvt_thread_pool_context_reset( thrctx );
7156 if ( unsupp && cfb->cb_use_ldif ) {
7157 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
7158 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
7165 cfb_free_cffile( ConfigFile *cf )
7169 for (; cf; cf=next) {
7172 cfb_free_cffile( cf->c_kids );
7173 ch_free( cf->c_file.bv_val );
7174 ber_bvarray_free( cf->c_dseFiles );
7180 cfb_free_entries( CfEntryInfo *ce )
7184 for (; ce; ce=next) {
7187 cfb_free_entries( ce->ce_kids );
7188 ce->ce_entry->e_private = NULL;
7189 entry_free( ce->ce_entry );
7195 config_back_db_close( BackendDB *be, ConfigReply *cr )
7197 CfBackInfo *cfb = be->be_private;
7199 cfb_free_entries( cfb->cb_root );
7200 cfb->cb_root = NULL;
7202 if ( cfb->cb_db.bd_info ) {
7203 backend_shutdown( &cfb->cb_db );
7206 if ( defacl_parsed && be->be_acl != defacl_parsed ) {
7207 acl_free( defacl_parsed );
7208 defacl_parsed = NULL;
7215 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
7217 CfBackInfo *cfb = be->be_private;
7219 cfb_free_cffile( cfb->cb_config );
7221 ch_free( cfdir.bv_val );
7223 avl_free( CfOcTree, NULL );
7225 if ( cfb->cb_db.bd_info ) {
7226 cfb->cb_db.be_suffix = NULL;
7227 cfb->cb_db.be_nsuffix = NULL;
7228 BER_BVZERO( &cfb->cb_db.be_rootdn );
7229 BER_BVZERO( &cfb->cb_db.be_rootndn );
7231 backend_destroy_one( &cfb->cb_db, 0 );
7240 config_back_db_init( BackendDB *be, ConfigReply* cr )
7246 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
7247 cfn = cfb->cb_config;
7248 be->be_private = cfb;
7250 ber_dupbv( &be->be_rootdn, &config_rdn );
7251 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
7252 ber_dupbv( &dn, &be->be_rootdn );
7253 ber_bvarray_add( &be->be_suffix, &dn );
7254 ber_dupbv( &dn, &be->be_rootdn );
7255 ber_bvarray_add( &be->be_nsuffix, &dn );
7257 /* Hide from namingContexts */
7258 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
7260 /* Check ACLs on content of Adds by default */
7261 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_ACL_ADD;
7267 config_back_destroy( BackendInfo *bi )
7269 ldif_must_b64_encode_release();
7274 config_tool_entry_open( BackendDB *be, int mode )
7276 CfBackInfo *cfb = be->be_private;
7277 BackendInfo *bi = cfb->cb_db.bd_info;
7279 if ( bi && bi->bi_tool_entry_open )
7280 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
7287 config_tool_entry_close( BackendDB *be )
7289 CfBackInfo *cfb = be->be_private;
7290 BackendInfo *bi = cfb->cb_db.bd_info;
7292 if ( bi && bi->bi_tool_entry_close )
7293 return bi->bi_tool_entry_close( &cfb->cb_db );
7299 config_tool_entry_first( BackendDB *be )
7301 CfBackInfo *cfb = be->be_private;
7302 BackendInfo *bi = cfb->cb_db.bd_info;
7304 if ( bi && bi->bi_tool_entry_first ) {
7305 return bi->bi_tool_entry_first( &cfb->cb_db );
7307 if ( bi && bi->bi_tool_entry_first_x ) {
7308 return bi->bi_tool_entry_first_x( &cfb->cb_db,
7309 NULL, LDAP_SCOPE_DEFAULT, NULL );
7315 config_tool_entry_first_x(
7317 struct berval *base,
7321 CfBackInfo *cfb = be->be_private;
7322 BackendInfo *bi = cfb->cb_db.bd_info;
7324 if ( bi && bi->bi_tool_entry_first_x ) {
7325 return bi->bi_tool_entry_first_x( &cfb->cb_db, base, scope, f );
7331 config_tool_entry_next( BackendDB *be )
7333 CfBackInfo *cfb = be->be_private;
7334 BackendInfo *bi = cfb->cb_db.bd_info;
7336 if ( bi && bi->bi_tool_entry_next )
7337 return bi->bi_tool_entry_next( &cfb->cb_db );
7343 config_tool_entry_get( BackendDB *be, ID id )
7345 CfBackInfo *cfb = be->be_private;
7346 BackendInfo *bi = cfb->cb_db.bd_info;
7348 if ( bi && bi->bi_tool_entry_get )
7349 return bi->bi_tool_entry_get( &cfb->cb_db, id );
7354 static int entry_put_got_frontend=0;
7355 static int entry_put_got_config=0;
7357 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
7359 CfBackInfo *cfb = be->be_private;
7360 BackendInfo *bi = cfb->cb_db.bd_info;
7362 struct berval rdn, vals[ 2 ];
7364 OperationBuffer opbuf;
7366 Connection conn = {0};
7367 Operation *op = NULL;
7370 int isFrontendChild = 0;
7372 /* Create entry for frontend database if it does not exist already */
7373 if ( !entry_put_got_frontend ) {
7374 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
7375 STRLENOF( "olcDatabase" ))) {
7376 if ( strncmp( e->e_nname.bv_val +
7377 STRLENOF( "olcDatabase" ), "={-1}frontend",
7378 STRLENOF( "={-1}frontend" )) &&
7379 strncmp( e->e_nname.bv_val +
7380 STRLENOF( "olcDatabase" ), "=frontend",
7381 STRLENOF( "=frontend" ))) {
7383 vals[1].bv_val = NULL;
7384 memset( &ca, 0, sizeof(ConfigArgs));
7386 ca.bi = frontendDB->bd_info;
7387 ca.be->be_cf_ocs = &CFOC_FRONTEND;
7388 rdn.bv_val = ca.log;
7389 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7390 "%s=" SLAP_X_ORDERED_FMT "%s",
7391 cfAd_database->ad_cname.bv_val, -1,
7393 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
7394 &CFOC_DATABASE, ca.be->be_cf_ocs );
7395 thrctx = ldap_pvt_thread_pool_context();
7396 connection_fake_init2( &conn, &opbuf, thrctx,0 );
7398 op->o_bd = &cfb->cb_db;
7399 op->o_tag = LDAP_REQ_ADD;
7401 op->o_dn = be->be_rootdn;
7402 op->o_ndn = be->be_rootndn;
7403 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
7404 if ( rc != LDAP_SUCCESS ) {
7405 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
7406 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
7410 if ( ce && bi && bi->bi_tool_entry_put &&
7411 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
7412 entry_put_got_frontend++;
7414 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
7415 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
7419 if ( !strncmp( e->e_nname.bv_val +
7420 STRLENOF( "olcDatabase" ), "=frontend",
7421 STRLENOF( "=frontend" ) ) )
7423 struct berval rdn, pdn, ndn;
7424 dnParent( &e->e_nname, &pdn );
7425 rdn.bv_val = ca.log;
7426 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7427 "%s=" SLAP_X_ORDERED_FMT "%s",
7428 cfAd_database->ad_cname.bv_val, -1,
7429 frontendDB->bd_info->bi_type );
7430 build_new_dn( &ndn, &pdn, &rdn, NULL );
7431 ber_memfree( e->e_name.bv_val );
7433 ber_bvreplace( &e->e_nname, &e->e_name );
7435 entry_put_got_frontend++;
7441 /* Child entries of the frontend database, e.g. slapo-chain's back-ldap
7442 * instances, may appear before the config database entry in the ldif, skip
7443 * auto-creation of olcDatabase={0}config in such a case */
7444 if ( !entry_put_got_config &&
7445 !strncmp( e->e_nname.bv_val, "olcDatabase", STRLENOF( "olcDatabase" ))) {
7447 dnParent( &e->e_nname, &pdn );
7448 while ( pdn.bv_len ) {
7449 if ( !strncmp( pdn.bv_val, "olcDatabase",
7450 STRLENOF( "olcDatabase" ))) {
7451 if ( !strncmp( pdn.bv_val +
7452 STRLENOF( "olcDatabase" ), "={-1}frontend",
7453 STRLENOF( "={-1}frontend" )) ||
7454 !strncmp( pdn.bv_val +
7455 STRLENOF( "olcDatabase" ), "=frontend",
7456 STRLENOF( "=frontend" ))) {
7458 isFrontendChild = 1;
7462 dnParent( &pdn, &pdn );
7466 /* Create entry for config database if it does not exist already */
7467 if ( !entry_put_got_config && !isFrontend && !isFrontendChild ) {
7468 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
7469 STRLENOF( "olcDatabase" ))) {
7470 if ( strncmp( e->e_nname.bv_val +
7471 STRLENOF( "olcDatabase" ), "={0}config",
7472 STRLENOF( "={0}config" )) &&
7473 strncmp( e->e_nname.bv_val +
7474 STRLENOF( "olcDatabase" ), "=config",
7475 STRLENOF( "=config" )) ) {
7477 vals[1].bv_val = NULL;
7478 memset( &ca, 0, sizeof(ConfigArgs));
7479 ca.be = LDAP_STAILQ_FIRST( &backendDB );
7480 ca.bi = ca.be->bd_info;
7481 rdn.bv_val = ca.log;
7482 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7483 "%s=" SLAP_X_ORDERED_FMT "%s",
7484 cfAd_database->ad_cname.bv_val, 0,
7486 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
7489 thrctx = ldap_pvt_thread_pool_context();
7490 connection_fake_init2( &conn, &opbuf, thrctx,0 );
7492 op->o_bd = &cfb->cb_db;
7493 op->o_tag = LDAP_REQ_ADD;
7494 op->o_dn = be->be_rootdn;
7495 op->o_ndn = be->be_rootndn;
7498 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
7499 if ( rc != LDAP_SUCCESS ) {
7500 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
7501 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7504 if (ce && bi && bi->bi_tool_entry_put &&
7505 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
7506 entry_put_got_config++;
7508 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
7509 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7513 entry_put_got_config++;
7517 if ( bi && bi->bi_tool_entry_put &&
7518 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
7519 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
7526 AttributeDescription **desc;
7528 { "attribute", &cfAd_attr },
7529 { "backend", &cfAd_backend },
7530 { "database", &cfAd_database },
7531 { "include", &cfAd_include },
7532 { "ldapsyntax", &cfAd_syntax },
7533 { "objectclass", &cfAd_oc },
7534 { "objectidentifier", &cfAd_om },
7535 { "overlay", &cfAd_overlay },
7540 * add / delete: all types that may be added or deleted must use an
7541 * X-ORDERED attributeType for their RDN. Adding and deleting entries
7542 * should automatically renumber the index of any siblings as needed,
7543 * so that no gaps in the numbering sequence exist after the add/delete
7545 * What can be added:
7547 * backend objects for backend-specific config directives
7551 * delete: probably no support this time around.
7553 * modrdn: generally not done. Will be invoked automatically by add/
7554 * delete to update numbering sequence. Perform as an explicit operation
7555 * so that the renumbering effect may be replicated. Subtree rename must
7556 * be supported, since renumbering a database will affect all its child
7559 * modify: must be fully supported.
7563 config_back_initialize( BackendInfo *bi )
7565 ConfigTable *ct = config_back_cf_table;
7569 AttributeDescription *ad = NULL;
7571 static char *controls[] = {
7572 LDAP_CONTROL_MANAGEDSAIT,
7576 /* Make sure we don't exceed the bits reserved for userland */
7577 config_check_userland( CFG_LAST );
7579 bi->bi_controls = controls;
7584 bi->bi_destroy = config_back_destroy;
7586 bi->bi_db_init = config_back_db_init;
7587 bi->bi_db_config = 0;
7588 bi->bi_db_open = config_back_db_open;
7589 bi->bi_db_close = config_back_db_close;
7590 bi->bi_db_destroy = config_back_db_destroy;
7592 bi->bi_op_bind = config_back_bind;
7593 bi->bi_op_unbind = 0;
7594 bi->bi_op_search = config_back_search;
7595 bi->bi_op_compare = 0;
7596 bi->bi_op_modify = config_back_modify;
7597 bi->bi_op_modrdn = config_back_modrdn;
7598 bi->bi_op_add = config_back_add;
7599 bi->bi_op_delete = config_back_delete;
7600 bi->bi_op_abandon = 0;
7602 bi->bi_extended = 0;
7604 bi->bi_chk_referrals = 0;
7606 bi->bi_access_allowed = slap_access_allowed;
7608 bi->bi_connection_init = 0;
7609 bi->bi_connection_destroy = 0;
7611 bi->bi_entry_release_rw = config_entry_release;
7612 bi->bi_entry_get_rw = config_back_entry_get;
7614 bi->bi_tool_entry_open = config_tool_entry_open;
7615 bi->bi_tool_entry_close = config_tool_entry_close;
7616 bi->bi_tool_entry_first = config_tool_entry_first;
7617 bi->bi_tool_entry_first_x = config_tool_entry_first_x;
7618 bi->bi_tool_entry_next = config_tool_entry_next;
7619 bi->bi_tool_entry_get = config_tool_entry_get;
7620 bi->bi_tool_entry_put = config_tool_entry_put;
7623 argv[ 0 ] = "slapd";
7629 for (i=0; OidMacros[i].name; i++ ) {
7630 argv[1] = OidMacros[i].name;
7631 argv[2] = OidMacros[i].oid;
7632 parse_oidm( &ca, 0, NULL );
7635 bi->bi_cf_ocs = cf_ocs;
7637 i = config_register_schema( ct, cf_ocs );
7640 i = slap_str2ad( "olcDatabase", &olcDatabaseDummy[0].ad, &text );
7643 /* setup olcRootPW to be base64-encoded when written in LDIF form;
7644 * basically, we don't care if it fails */
7645 i = slap_str2ad( "olcRootPW", &ad, &text );
7647 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
7648 "warning, unable to get \"olcRootPW\" "
7649 "attribute description: %d: %s\n",
7652 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
7653 ad->ad_type->sat_oid );
7656 /* set up the notable AttributeDescriptions */
7658 for (;ct->name;ct++) {
7659 if (strcmp(ct->name, ads[i].name)) continue;
7660 *ads[i].desc = ct->ad;
7662 if (!ads[i].name) break;