1 /* bconfig.c - the config backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005-2013 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was originally developed by Howard Chu for inclusion
18 * in OpenLDAP Software.
24 #include <ac/string.h>
28 #include <ac/unistd.h>
33 #include "slapi/slapi.h"
41 #define CONFIG_RDN "cn=config"
42 #define SCHEMA_RDN "cn=schema"
44 static struct berval config_rdn = BER_BVC(CONFIG_RDN);
45 static struct berval schema_rdn = BER_BVC(SCHEMA_RDN);
47 extern int slap_DN_strict; /* dn.c */
50 typedef struct modpath_s {
51 struct modpath_s *mp_next;
52 struct berval mp_path;
56 static ModPaths modpaths, *modlast = &modpaths, *modcur = &modpaths;
59 typedef struct ConfigFile {
60 struct ConfigFile *c_sibs;
61 struct ConfigFile *c_kids;
63 AttributeType *c_at_head, *c_at_tail;
64 ContentRule *c_cr_head, *c_cr_tail;
65 ObjectClass *c_oc_head, *c_oc_tail;
66 OidMacro *c_om_head, *c_om_tail;
67 Syntax *c_syn_head, *c_syn_tail;
72 ConfigFile *cb_config;
74 BackendDB cb_db; /* underlying database */
79 static CfBackInfo cfBackInfo;
81 static char *passwd_salt;
83 static char *logfileName;
84 #ifdef SLAP_AUTH_REWRITE
85 static BerVarray authz_rewrites;
87 static AccessControl *defacl_parsed = NULL;
89 static struct berval cfdir;
92 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
93 *cfAd_include, *cfAd_attr, *cfAd_oc, *cfAd_om, *cfAd_syntax;
95 static ConfigFile *cfn;
97 static Avlnode *CfOcTree;
99 /* System schema state */
100 extern AttributeType *at_sys_tail; /* at.c */
101 extern ObjectClass *oc_sys_tail; /* oc.c */
102 extern OidMacro *om_sys_tail; /* oidm.c */
103 extern Syntax *syn_sys_tail; /* syntax.c */
104 static AttributeType *cf_at_tail;
105 static ObjectClass *cf_oc_tail;
106 static OidMacro *cf_om_tail;
107 static Syntax *cf_syn_tail;
109 static int config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca,
110 SlapReply *rs, int *renumber, Operation *op );
112 static int config_check_schema( Operation *op, CfBackInfo *cfb );
114 static ConfigDriver config_fname;
115 static ConfigDriver config_cfdir;
116 static ConfigDriver config_generic;
117 static ConfigDriver config_search_base;
118 static ConfigDriver config_passwd_hash;
119 static ConfigDriver config_schema_dn;
120 static ConfigDriver config_sizelimit;
121 static ConfigDriver config_timelimit;
122 static ConfigDriver config_overlay;
123 static ConfigDriver config_subordinate;
124 static ConfigDriver config_suffix;
125 #ifdef LDAP_TCP_BUFFER
126 static ConfigDriver config_tcp_buffer;
127 #endif /* LDAP_TCP_BUFFER */
128 static ConfigDriver config_rootdn;
129 static ConfigDriver config_rootpw;
130 static ConfigDriver config_restrict;
131 static ConfigDriver config_allows;
132 static ConfigDriver config_disallows;
133 static ConfigDriver config_requires;
134 static ConfigDriver config_security;
135 static ConfigDriver config_referral;
136 static ConfigDriver config_loglevel;
137 static ConfigDriver config_updatedn;
138 static ConfigDriver config_updateref;
139 static ConfigDriver config_extra_attrs;
140 static ConfigDriver config_include;
141 static ConfigDriver config_obsolete;
143 static ConfigDriver config_tls_option;
144 static ConfigDriver config_tls_config;
146 extern ConfigDriver syncrepl_config;
154 CFG_TLS_PROTOCOL_MIN,
210 static OidRec OidMacros[] = {
211 /* OpenLDAProot:1.12.2 */
212 { "OLcfg", "1.3.6.1.4.1.4203.1.12.2" },
213 { "OLcfgAt", "OLcfg:3" },
214 { "OLcfgGlAt", "OLcfgAt:0" },
215 { "OLcfgBkAt", "OLcfgAt:1" },
216 { "OLcfgDbAt", "OLcfgAt:2" },
217 { "OLcfgOvAt", "OLcfgAt:3" },
218 { "OLcfgCtAt", "OLcfgAt:4" }, /* contrib modules */
219 { "OLcfgOc", "OLcfg:4" },
220 { "OLcfgGlOc", "OLcfgOc:0" },
221 { "OLcfgBkOc", "OLcfgOc:1" },
222 { "OLcfgDbOc", "OLcfgOc:2" },
223 { "OLcfgOvOc", "OLcfgOc:3" },
224 { "OLcfgCtOc", "OLcfgOc:4" }, /* contrib modules */
226 /* Syntaxes. We should just start using the standard names and
227 * document that they are predefined and available for users
228 * to reference in their own schema. Defining schema without
229 * OID macros is for masochists...
231 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
232 { "OMsBoolean", "OMsyn:7" },
233 { "OMsDN", "OMsyn:12" },
234 { "OMsDirectoryString", "OMsyn:15" },
235 { "OMsIA5String", "OMsyn:26" },
236 { "OMsInteger", "OMsyn:27" },
237 { "OMsOID", "OMsyn:38" },
238 { "OMsOctetString", "OMsyn:40" },
243 * Backend/Database registry
245 * OLcfg{Bk|Db}{Oc|At}:0 -> common
246 * OLcfg{Bk|Db}{Oc|At}:1 -> back-bdb(/back-hdb)
247 * OLcfg{Bk|Db}{Oc|At}:2 -> back-ldif
248 * OLcfg{Bk|Db}{Oc|At}:3 -> back-ldap/meta
249 * OLcfg{Bk|Db}{Oc|At}:4 -> back-monitor
250 * OLcfg{Bk|Db}{Oc|At}:5 -> back-relay
251 * OLcfg{Bk|Db}{Oc|At}:6 -> back-sql(/back-ndb)
252 * OLcfg{Bk|Db}{Oc|At}:7 -> back-sock
253 * OLcfg{Bk|Db}{Oc|At}:8 -> back-null
254 * OLcfg{Bk|Db}{Oc|At}:9 -> back-passwd
255 * OLcfg{Bk|Db}{Oc|At}:10 -> back-shell
256 * OLcfg{Bk|Db}{Oc|At}:11 -> back-perl
257 * OLcfg{Bk|Db}{Oc|At}:12 -> back-mdb
263 * OLcfgOv{Oc|At}:1 -> syncprov
264 * OLcfgOv{Oc|At}:2 -> pcache
265 * OLcfgOv{Oc|At}:3 -> chain
266 * OLcfgOv{Oc|At}:4 -> accesslog
267 * OLcfgOv{Oc|At}:5 -> valsort
268 * OLcfgOv{Oc|At}:7 -> distproc
269 * OLcfgOv{Oc|At}:8 -> dynlist
270 * OLcfgOv{Oc|At}:9 -> dds
271 * OLcfgOv{Oc|At}:10 -> unique
272 * OLcfgOv{Oc|At}:11 -> refint
273 * OLcfgOv{Oc|At}:12 -> ppolicy
274 * OLcfgOv{Oc|At}:13 -> constraint
275 * OLcfgOv{Oc|At}:14 -> translucent
276 * OLcfgOv{Oc|At}:15 -> auditlog
277 * OLcfgOv{Oc|At}:16 -> rwm
278 * OLcfgOv{Oc|At}:17 -> dyngroup
279 * OLcfgOv{Oc|At}:18 -> memberof
280 * OLcfgOv{Oc|At}:19 -> collect
281 * OLcfgOv{Oc|At}:20 -> retcode
282 * OLcfgOv{Oc|At}:21 -> sssvlv
285 /* alphabetical ordering */
287 static ConfigTable config_back_cf_table[] = {
288 /* This attr is read-only */
289 { "", "", 0, 0, 0, ARG_MAGIC,
290 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
291 "DESC 'File for slapd configuration directives' "
292 "EQUALITY caseIgnoreMatch "
293 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
294 { "", "", 0, 0, 0, ARG_MAGIC,
295 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
296 "DESC 'Directory for slapd configuration backend' "
297 "EQUALITY caseIgnoreMatch "
298 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
299 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
300 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
301 "DESC 'Access Control List' "
302 "EQUALITY caseIgnoreMatch "
303 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
304 { "add_content_acl", NULL, 0, 0, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_ACL_ADD,
305 &config_generic, "( OLcfgGlAt:86 NAME 'olcAddContentAcl' "
306 "DESC 'Check ACLs against content of Add ops' "
307 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
308 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
309 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
310 "DESC 'Allowed set of deprecated features' "
311 "EQUALITY caseIgnoreMatch "
312 "SYNTAX OMsDirectoryString )", NULL, NULL },
313 { "argsfile", "file", 2, 2, 0, ARG_STRING,
314 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
315 "DESC 'File for slapd command line options' "
316 "EQUALITY caseIgnoreMatch "
317 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
318 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
319 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
320 "EQUALITY caseIgnoreMatch "
321 "SYNTAX OMsDirectoryString )", NULL, NULL },
322 { "attribute", "attribute", 2, 0, STRLENOF( "attribute" ),
323 ARG_PAREN|ARG_MAGIC|CFG_ATTR,
324 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
325 "DESC 'OpenLDAP attributeTypes' "
326 "EQUALITY caseIgnoreMatch "
327 "SUBSTR caseIgnoreSubstringsMatch "
328 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
330 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
331 #ifdef SLAP_AUTH_REWRITE
332 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
336 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
337 "EQUALITY caseIgnoreMatch "
338 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
339 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
340 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
341 "EQUALITY caseIgnoreMatch "
342 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
343 { "authz-regexp", "regexp> <DN", 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
344 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
345 "EQUALITY caseIgnoreMatch "
346 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
347 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
348 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
349 "DESC 'A type of backend' "
350 "EQUALITY caseIgnoreMatch "
351 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
353 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
354 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
355 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
356 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
357 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
358 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
359 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
360 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
361 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
362 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
363 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
364 "DESC 'The backend type for a database instance' "
365 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
366 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
367 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
368 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
369 { "disabled", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_DISABLED,
370 &config_generic, "( OLcfgDbAt:0.21 NAME 'olcDisabled' "
371 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
372 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
373 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
374 "EQUALITY caseIgnoreMatch "
375 "SYNTAX OMsDirectoryString )", NULL, NULL },
376 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
377 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
378 "DESC 'OpenLDAP DIT content rules' "
379 "EQUALITY caseIgnoreMatch "
380 "SUBSTR caseIgnoreSubstringsMatch "
381 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
383 { "extra_attrs", "attrlist", 2, 2, 0, ARG_DB|ARG_MAGIC,
384 &config_extra_attrs, "( OLcfgDbAt:0.20 NAME 'olcExtraAttrs' "
385 "EQUALITY caseIgnoreMatch "
386 "SYNTAX OMsDirectoryString )", NULL, NULL },
387 { "gentlehup", "on|off", 2, 2, 0,
389 ARG_ON_OFF, &global_gentlehup,
393 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
394 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
395 { "hidden", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_HIDDEN,
396 &config_generic, "( OLcfgDbAt:0.17 NAME 'olcHidden' "
397 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
398 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
399 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
400 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
401 { "include", "file", 2, 2, 0, ARG_MAGIC,
402 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
403 "SUP labeledURI )", NULL, NULL },
404 { "index_hash64", "on|off", 2, 2, 0, ARG_ON_OFF|ARG_MAGIC|CFG_IX_HASH64,
405 &config_generic, "( OLcfgGlAt:94 NAME 'olcIndexHash64' "
406 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
407 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
408 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
409 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
410 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
411 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
412 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
413 { "index_substr_any_len", "len", 2, 2, 0, ARG_UINT|ARG_NONZERO,
414 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
415 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
416 { "index_substr_any_step", "step", 2, 2, 0, ARG_UINT|ARG_NONZERO,
417 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
418 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
419 { "index_intlen", "len", 2, 2, 0, ARG_UINT|ARG_MAGIC|CFG_IX_INTLEN,
420 &config_generic, "( OLcfgGlAt:84 NAME 'olcIndexIntLen' "
421 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
422 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
423 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
424 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
425 { "ldapsyntax", "syntax", 2, 0, 0,
426 ARG_PAREN|ARG_MAGIC|CFG_SYNTAX,
427 &config_generic, "( OLcfgGlAt:85 NAME 'olcLdapSyntaxes' "
428 "DESC 'OpenLDAP ldapSyntax' "
429 "EQUALITY caseIgnoreMatch "
430 "SUBSTR caseIgnoreSubstringsMatch "
431 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
433 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
434 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
435 "EQUALITY caseIgnoreMatch "
436 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
437 { "listener-threads", "count", 2, 0, 0,
441 ARG_UINT|ARG_MAGIC|CFG_LTHREADS, &config_generic,
443 "( OLcfgGlAt:93 NAME 'olcListenerThreads' "
444 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
445 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
446 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
447 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
448 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
449 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
450 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
451 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
452 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
453 "EQUALITY caseIgnoreMatch "
454 "SYNTAX OMsDirectoryString )", NULL, NULL },
455 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
456 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
457 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
458 { "mirrormode", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_MIRRORMODE,
459 &config_generic, "( OLcfgDbAt:0.16 NAME 'olcMirrorMode' "
460 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
461 { "moduleload", "file", 2, 0, 0,
463 ARG_MAGIC|CFG_MODLOAD|ARG_NO_DELETE, &config_generic,
467 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
468 "EQUALITY caseIgnoreMatch "
469 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
470 { "modulepath", "path", 2, 2, 0,
472 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
476 "( OLcfgGlAt:31 NAME 'olcModulePath' "
477 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
478 { "monitoring", "TRUE|FALSE", 2, 2, 0,
479 ARG_MAGIC|CFG_MONITORING|ARG_DB|ARG_ON_OFF, &config_generic,
480 "( OLcfgDbAt:0.18 NAME 'olcMonitoring' "
481 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
482 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
483 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
484 "DESC 'OpenLDAP object classes' "
485 "EQUALITY caseIgnoreMatch "
486 "SUBSTR caseIgnoreSubstringsMatch "
487 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
489 { "objectidentifier", "name> <oid", 3, 3, 0, ARG_MAGIC|CFG_OID,
490 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
491 "EQUALITY caseIgnoreMatch "
492 "SUBSTR caseIgnoreSubstringsMatch "
493 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
494 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
495 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
496 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
497 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
498 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
499 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
500 { "password-hash", "hash", 2, 0, 0, ARG_MAGIC,
501 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
502 "EQUALITY caseIgnoreMatch "
503 "SYNTAX OMsDirectoryString )", NULL, NULL },
504 { "pidfile", "file", 2, 2, 0, ARG_STRING,
505 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
506 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
507 { "plugin", NULL, 0, 0, 0,
509 ARG_MAGIC|CFG_PLUGIN, &config_generic,
513 "( OLcfgGlAt:38 NAME 'olcPlugin' "
514 "EQUALITY caseIgnoreMatch "
515 "SYNTAX OMsDirectoryString )", NULL, NULL },
516 { "pluginlog", "filename", 2, 2, 0,
518 ARG_STRING, &slapi_log_file,
522 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
523 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
524 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
525 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
526 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
527 { "referral", "url", 2, 2, 0, ARG_MAGIC,
528 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
529 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
530 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
531 &config_obsolete, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
532 "EQUALITY caseIgnoreMatch "
533 "SUP labeledURI X-ORDERED 'VALUES' )", NULL, NULL },
534 { "replica-argsfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
535 &config_obsolete, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
536 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
537 { "replica-pidfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
538 &config_obsolete, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
539 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
540 { "replicationInterval", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
541 &config_obsolete, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
542 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
543 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC,
544 &config_obsolete, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
545 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
546 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
547 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
548 "EQUALITY caseIgnoreMatch "
549 "SYNTAX OMsDirectoryString )", NULL, NULL },
550 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
551 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
552 "EQUALITY caseIgnoreMatch "
553 "SYNTAX OMsDirectoryString )", NULL, NULL },
554 { "reverse-lookup", "on|off", 2, 2, 0,
555 #ifdef SLAPD_RLOOKUPS
556 ARG_ON_OFF, &use_reverse_lookup,
560 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
561 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
562 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
563 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
564 "EQUALITY distinguishedNameMatch "
565 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
566 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
567 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
568 "EQUALITY caseIgnoreMatch "
569 "SYNTAX OMsDirectoryString )", NULL, NULL },
570 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
571 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
572 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
573 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
574 &config_generic, NULL, NULL, NULL },
575 { "sasl-auxprops", NULL, 2, 0, 0,
576 #ifdef HAVE_CYRUS_SASL
577 ARG_STRING|ARG_UNIQUE, &slap_sasl_auxprops,
581 "( OLcfgGlAt:89 NAME 'olcSaslAuxprops' "
582 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
583 { "sasl-auxprops-dontusecopy", NULL, 2, 0, 0,
584 #if defined(HAVE_CYRUS_SASL) && defined(SLAP_AUXPROP_DONTUSECOPY)
585 ARG_MAGIC|CFG_AZDUC, &config_generic,
589 "( OLcfgGlAt:91 NAME 'olcSaslAuxpropsDontUseCopy' "
590 "EQUALITY caseIgnoreMatch "
591 "SYNTAX OMsDirectoryString )", NULL, NULL },
592 { "sasl-auxprops-dontusecopy-ignore", "true|FALSE", 2, 0, 0,
593 #if defined(HAVE_CYRUS_SASL) && defined(SLAP_AUXPROP_DONTUSECOPY)
594 ARG_ON_OFF|CFG_AZDUC_IGNORE, &slap_dontUseCopy_ignore,
598 "( OLcfgGlAt:92 NAME 'olcSaslAuxpropsDontUseCopyIgnore' "
599 "EQUALITY booleanMatch "
600 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
601 { "sasl-host", "host", 2, 2, 0,
602 #ifdef HAVE_CYRUS_SASL
603 ARG_STRING|ARG_UNIQUE, &sasl_host,
607 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
608 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
609 { "sasl-realm", "realm", 2, 2, 0,
610 #ifdef HAVE_CYRUS_SASL
611 ARG_STRING|ARG_UNIQUE, &global_realm,
615 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
616 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
617 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
618 &config_generic, NULL, NULL, NULL },
619 { "sasl-secprops", "properties", 2, 2, 0,
620 #ifdef HAVE_CYRUS_SASL
621 ARG_MAGIC|CFG_SASLSECP, &config_generic,
625 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
626 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
627 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
628 &config_generic, NULL, NULL, NULL },
629 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
630 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
631 "EQUALITY distinguishedNameMatch "
632 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
633 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
634 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
635 "EQUALITY caseIgnoreMatch "
636 "SYNTAX OMsDirectoryString )", NULL, NULL },
637 { "serverID", "number> <[URI]", 2, 3, 0, ARG_MAGIC|CFG_SERVERID,
638 &config_generic, "( OLcfgGlAt:81 NAME 'olcServerID' "
639 "EQUALITY caseIgnoreMatch "
640 "SYNTAX OMsDirectoryString )", NULL, NULL },
641 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
642 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
643 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
644 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
645 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
646 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
647 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
648 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
649 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
650 { "sortvals", "attr", 2, 0, 0, ARG_MAGIC|CFG_SORTVALS,
651 &config_generic, "( OLcfgGlAt:83 NAME 'olcSortVals' "
652 "DESC 'Attributes whose values will always be sorted' "
653 "EQUALITY caseIgnoreMatch "
654 "SYNTAX OMsDirectoryString )", NULL, NULL },
655 { "subordinate", "[advertise]", 1, 2, 0, ARG_DB|ARG_MAGIC,
656 &config_subordinate, "( OLcfgDbAt:0.15 NAME 'olcSubordinate' "
657 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
658 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
659 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
660 "EQUALITY distinguishedNameMatch "
661 "SYNTAX OMsDN )", NULL, NULL },
662 { "sync_use_subentry", NULL, 0, 0, 0, ARG_ON_OFF|ARG_DB|ARG_MAGIC|CFG_SYNC_SUBENTRY,
663 &config_generic, "( OLcfgDbAt:0.19 NAME 'olcSyncUseSubentry' "
664 "DESC 'Store sync context in a subentry' "
665 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
666 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
667 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
668 "EQUALITY caseIgnoreMatch "
669 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
670 { "tcp-buffer", "[listener=<listener>] [{read|write}=]size", 0, 0, 0,
671 #ifndef LDAP_TCP_BUFFER
673 #else /* LDAP_TCP_BUFFER */
674 ARG_MAGIC, &config_tcp_buffer,
675 #endif /* LDAP_TCP_BUFFER */
676 "( OLcfgGlAt:90 NAME 'olcTCPBuffer' "
677 "DESC 'Custom TCP buffer size' "
678 "SYNTAX OMsDirectoryString )", NULL, NULL },
679 { "threads", "count", 2, 2, 0,
683 ARG_INT|ARG_MAGIC|CFG_THREADS, &config_generic,
685 "( OLcfgGlAt:66 NAME 'olcThreads' "
686 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
687 { "threadqueues", "count", 2, 2, 0,
691 ARG_INT|ARG_MAGIC|CFG_THREADQS, &config_generic,
693 "( OLcfgGlAt:95 NAME 'olcThreadQueues' "
694 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
695 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
696 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
697 "SYNTAX OMsDirectoryString )", NULL, NULL },
698 { "TLSCACertificateFile", NULL, 2, 2, 0,
700 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
704 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
705 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
706 { "TLSCACertificatePath", NULL, 2, 2, 0,
708 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
712 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
713 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
714 { "TLSCertificateFile", NULL, 2, 2, 0,
716 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
720 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
721 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
722 { "TLSCertificateKeyFile", NULL, 2, 2, 0,
724 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
728 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
729 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
730 { "TLSCipherSuite", NULL, 2, 2, 0,
732 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
736 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
737 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
738 { "TLSCRLCheck", NULL, 2, 2, 0,
739 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
740 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
744 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
745 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
746 { "TLSCRLFile", NULL, 2, 2, 0,
747 #if defined(HAVE_GNUTLS)
748 CFG_TLS_CRL_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
752 "( OLcfgGlAt:82 NAME 'olcTLSCRLFile' "
753 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
754 { "TLSRandFile", NULL, 2, 2, 0,
756 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
760 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
761 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
762 { "TLSVerifyClient", NULL, 2, 2, 0,
764 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
768 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
769 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
770 { "TLSDHParamFile", NULL, 2, 2, 0,
772 CFG_TLS_DH_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
776 "( OLcfgGlAt:77 NAME 'olcTLSDHParamFile' "
777 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
778 { "TLSProtocolMin", NULL, 2, 2, 0,
780 CFG_TLS_PROTOCOL_MIN|ARG_STRING|ARG_MAGIC, &config_tls_config,
784 "( OLcfgGlAt:87 NAME 'olcTLSProtocolMin' "
785 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
786 { "tool-threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_TTHREADS,
787 &config_generic, "( OLcfgGlAt:80 NAME 'olcToolThreads' "
788 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
789 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
790 NULL, NULL, NULL, NULL },
791 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
792 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
793 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
794 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
795 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
796 "EQUALITY caseIgnoreMatch "
797 "SUP labeledURI )", NULL, NULL },
798 { "writetimeout", "timeout", 2, 2, 0, ARG_INT,
799 &global_writetimeout, "( OLcfgGlAt:88 NAME 'olcWriteTimeout' "
800 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
801 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
802 NULL, NULL, NULL, NULL }
805 /* Need to no-op this keyword for dynamic config */
806 ConfigTable olcDatabaseDummy[] = {
807 { "", "", 0, 0, 0, ARG_IGNORED,
808 NULL, "( OLcfgGlAt:13 NAME 'olcDatabase' "
809 "DESC 'The backend type for a database instance' "
810 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
811 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
814 /* Routines to check if a child can be added to this type */
815 static ConfigLDAPadd cfAddSchema, cfAddInclude, cfAddDatabase,
816 cfAddBackend, cfAddModule, cfAddOverlay;
818 /* NOTE: be careful when defining array members
819 * that can be conditionally compiled */
820 #define CFOC_GLOBAL cf_ocs[1]
821 #define CFOC_SCHEMA cf_ocs[2]
822 #define CFOC_BACKEND cf_ocs[3]
823 #define CFOC_DATABASE cf_ocs[4]
824 #define CFOC_OVERLAY cf_ocs[5]
825 #define CFOC_INCLUDE cf_ocs[6]
826 #define CFOC_FRONTEND cf_ocs[7]
828 #define CFOC_MODULE cf_ocs[8]
829 #endif /* SLAPD_MODULES */
831 static ConfigOCs cf_ocs[] = {
834 "DESC 'OpenLDAP configuration object' "
835 "ABSTRACT SUP top )", Cft_Abstract, NULL },
838 "DESC 'OpenLDAP Global configuration options' "
839 "SUP olcConfig STRUCTURAL "
840 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
841 "olcAttributeOptions $ olcAuthIDRewrite $ "
842 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
843 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
844 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
845 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
846 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcIndexHash64 $ "
848 "olcListenerThreads $ olcLocalSSF $ olcLogFile $ olcLogLevel $ "
849 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
850 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
851 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
853 "olcSaslAuxprops $ olcSaslAuxpropsDontUseCopy $ olcSaslAuxpropsDontUseCopyIgnore $ "
854 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
855 "olcSecurity $ olcServerID $ olcSizeLimit $ "
856 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ "
858 "olcThreads $ olcThreadQueues $ "
859 "olcTimeLimit $ olcTLSCACertificateFile $ "
860 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
861 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
862 "olcTLSRandFile $ olcTLSVerifyClient $ olcTLSDHParamFile $ "
863 "olcTLSCRLFile $ olcToolThreads $ olcWriteTimeout $ "
864 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
865 "olcDitContentRules $ olcLdapSyntaxes ) )", Cft_Global },
867 "NAME 'olcSchemaConfig' "
868 "DESC 'OpenLDAP schema object' "
869 "SUP olcConfig STRUCTURAL "
870 "MAY ( cn $ olcObjectIdentifier $ olcLdapSyntaxes $ "
871 "olcAttributeTypes $ olcObjectClasses $ olcDitContentRules ) )",
872 Cft_Schema, NULL, cfAddSchema },
874 "NAME 'olcBackendConfig' "
875 "DESC 'OpenLDAP Backend-specific options' "
876 "SUP olcConfig STRUCTURAL "
877 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
879 "NAME 'olcDatabaseConfig' "
880 "DESC 'OpenLDAP Database-specific options' "
881 "SUP olcConfig STRUCTURAL "
883 "MAY ( olcDisabled $ olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
884 "olcAddContentAcl $ olcLastMod $ olcLimits $ "
885 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
886 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
887 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
888 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncUseSubentry $ olcSyncrepl $ "
889 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef $ olcMirrorMode $ "
890 "olcMonitoring $ olcExtraAttrs ) )",
891 Cft_Database, NULL, cfAddDatabase },
893 "NAME 'olcOverlayConfig' "
894 "DESC 'OpenLDAP Overlay-specific options' "
895 "SUP olcConfig STRUCTURAL "
897 "MAY olcDisabled )", Cft_Overlay, NULL, cfAddOverlay },
899 "NAME 'olcIncludeFile' "
900 "DESC 'OpenLDAP configuration include file' "
901 "SUP olcConfig STRUCTURAL "
903 "MAY ( cn $ olcRootDSE ) )",
904 /* Used to be Cft_Include, that def has been removed */
905 Cft_Abstract, NULL, cfAddInclude },
906 /* This should be STRUCTURAL like all the other database classes, but
907 * that would mean inheriting all of the olcDatabaseConfig attributes,
908 * which causes them to be merged twice in config_build_entry.
911 "NAME 'olcFrontendConfig' "
912 "DESC 'OpenLDAP frontend configuration' "
914 "MAY ( olcDefaultSearchBase $ olcPasswordHash $ olcSortVals ) )",
915 Cft_Database, NULL, NULL },
918 "NAME 'olcModuleList' "
919 "DESC 'OpenLDAP dynamic module info' "
920 "SUP olcConfig STRUCTURAL "
921 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
922 Cft_Module, NULL, cfAddModule },
927 typedef struct ServerID {
928 struct ServerID *si_next;
929 struct berval si_url;
933 static ServerID *sid_list;
934 static ServerID *sid_set;
936 typedef struct voidList {
937 struct voidList *vl_next;
941 typedef struct ADlist {
942 struct ADlist *al_next;
943 AttributeDescription *al_desc;
946 static ADlist *sortVals;
949 config_generic(ConfigArgs *c) {
952 if ( c->op == SLAP_CONFIG_EMIT ) {
956 c->value_int = ldap_pvt_thread_get_concurrency();
959 c->value_int = connection_pool_max;
962 c->value_int = connection_pool_queues;
965 c->value_int = slap_tool_thread_max;
968 c->value_uint = slapd_daemon_threads;
972 c->value_string = ch_strdup( passwd_salt );
977 if ( c->be->be_limits ) {
981 for ( i=0; c->be->be_limits[i]; i++ ) {
982 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
983 if ( bv.bv_len >= sizeof( buf ) ) {
984 ber_bvarray_free_x( c->rvalue_vals, NULL );
985 c->rvalue_vals = NULL;
989 bv.bv_val = buf + bv.bv_len;
990 limits_unparse( c->be->be_limits[i], &bv,
991 sizeof( buf ) - ( bv.bv_val - buf ) );
992 bv.bv_len += bv.bv_val - buf;
994 value_add_one( &c->rvalue_vals, &bv );
997 if ( !c->rvalue_vals ) rc = 1;
1000 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_READONLY);
1003 c->value_string = ch_strdup( slap_sasl_getpolicy());
1006 slap_sasl_regexp_unparse( &c->rvalue_vals );
1007 if ( !c->rvalue_vals ) rc = 1;
1009 #ifdef HAVE_CYRUS_SASL
1010 #ifdef SLAP_AUXPROP_DONTUSECOPY
1012 static int duc_done = 0;
1014 /* take the opportunity to initialize with known values */
1016 struct berval duc[] = { BER_BVC("cmusaslsecretOTP"), BER_BVNULL };
1019 for ( i = 0; !BER_BVISNULL( &duc[ i ] ); i++ ) {
1020 const char *text = NULL;
1021 AttributeDescription *ad = NULL;
1023 if ( slap_bv2ad( &duc[ i ], &ad, &text ) == LDAP_SUCCESS ) {
1025 if ( slap_dontUseCopy_propnames ) {
1028 for ( j = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ j ] ); j++ ) {
1029 if ( bvmatch( &slap_dontUseCopy_propnames[ j ], &ad->ad_cname ) ) {
1036 value_add_one( &slap_dontUseCopy_propnames, &ad->ad_cname );
1044 if ( slap_dontUseCopy_propnames != NULL ) {
1045 ber_bvarray_dup_x( &c->rvalue_vals, slap_dontUseCopy_propnames, NULL );
1050 #endif /* SLAP_AUXPROP_DONTUSECOPY */
1051 case CFG_SASLSECP: {
1052 struct berval bv = BER_BVNULL;
1053 slap_sasl_secprops_unparse( &bv );
1054 if ( !BER_BVISNULL( &bv )) {
1055 ber_bvarray_add( &c->rvalue_vals, &bv );
1063 c->value_int = c->be->be_max_deref_depth;
1068 if ( c->bi->bi_flags & SLAPO_BFLAG_DISABLED ) {
1075 if ( SLAP_DBDISABLED( c->be )) {
1083 if ( SLAP_DBHIDDEN( c->be )) {
1090 ConfigFile *cf = c->ca_private;
1092 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1093 else if ( cf->c_om_head )
1094 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
1096 if ( !c->rvalue_vals )
1101 ad_unparse_options( &c->rvalue_vals );
1104 ConfigFile *cf = c->ca_private;
1106 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1107 else if ( cf->c_oc_head )
1108 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
1110 if ( !c->rvalue_vals )
1115 ConfigFile *cf = c->ca_private;
1117 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1118 else if ( cf->c_at_head )
1119 at_unparse( &c->rvalue_vals, cf->c_at_head,
1121 if ( !c->rvalue_vals )
1126 ConfigFile *cf = c->ca_private;
1128 syn_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1129 else if ( cf->c_syn_head )
1130 syn_unparse( &c->rvalue_vals, cf->c_syn_head,
1131 cf->c_syn_tail, 0 );
1132 if ( !c->rvalue_vals )
1137 ConfigFile *cf = c->ca_private;
1139 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1140 else if ( cf->c_cr_head )
1141 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
1143 if ( !c->rvalue_vals )
1150 char *src, *dst, ibuf[11];
1151 struct berval bv, abv;
1152 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
1153 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1154 if ( abv.bv_len >= sizeof( ibuf ) ) {
1155 ber_bvarray_free_x( c->rvalue_vals, NULL );
1156 c->rvalue_vals = NULL;
1160 acl_unparse( a, &bv );
1161 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
1162 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
1163 /* Turn TAB / EOL into plain space */
1164 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
1165 if (isspace((unsigned char)*src)) *dst++ = ' ';
1169 if (dst[-1] == ' ') {
1173 abv.bv_len = dst - abv.bv_val;
1174 ber_bvarray_add( &c->rvalue_vals, &abv );
1180 c->value_int = (SLAP_DBACL_ADD(c->be) != 0);
1183 ConfigFile *cf = c->ca_private;
1184 if ( cf->c_dseFiles ) {
1185 value_add( &c->rvalue_vals, cf->c_dseFiles );
1196 for ( si = sid_list; si; si=si->si_next ) {
1197 assert( si->si_num >= 0 && si->si_num <= SLAP_SYNC_SID_MAX );
1198 if ( !BER_BVISEMPTY( &si->si_url )) {
1199 bv.bv_len = si->si_url.bv_len + 6;
1200 bv.bv_val = ch_malloc( bv.bv_len );
1201 bv.bv_len = sprintf( bv.bv_val, "%d %s", si->si_num,
1202 si->si_url.bv_val );
1203 ber_bvarray_add( &c->rvalue_vals, &bv );
1207 bv.bv_len = sprintf( buf, "%d", si->si_num );
1208 value_add_one( &c->rvalue_vals, &bv );
1217 c->value_string = ch_strdup( logfileName );
1222 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1224 case CFG_SYNC_SUBENTRY:
1225 c->value_int = (SLAP_SYNC_SUBENTRY(c->be) != 0);
1227 case CFG_MIRRORMODE:
1228 if ( SLAP_SHADOW(c->be))
1229 c->value_int = (SLAP_MULTIMASTER(c->be) != 0);
1233 case CFG_MONITORING:
1234 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
1236 case CFG_SSTR_IF_MAX:
1237 c->value_uint = index_substr_if_maxlen;
1239 case CFG_SSTR_IF_MIN:
1240 c->value_uint = index_substr_if_minlen;
1243 c->value_int = slap_hash64( -1 );
1246 c->value_int = index_intlen;
1248 case CFG_SORTVALS: {
1251 for ( sv = sortVals; sv; sv = sv->al_next ) {
1252 value_add_one( &c->rvalue_vals, &sv->al_desc->ad_cname );
1256 #ifdef SLAPD_MODULES
1258 ModPaths *mp = c->ca_private;
1261 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
1264 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
1265 SLAP_X_ORDERED_FMT "%s", i,
1266 mp->mp_loads[i].bv_val );
1267 if ( bv.bv_len >= sizeof( c->log ) ) {
1268 ber_bvarray_free_x( c->rvalue_vals, NULL );
1269 c->rvalue_vals = NULL;
1272 value_add_one( &c->rvalue_vals, &bv );
1276 rc = c->rvalue_vals ? 0 : 1;
1280 ModPaths *mp = c->ca_private;
1281 if ( !BER_BVISNULL( &mp->mp_path ))
1282 value_add_one( &c->rvalue_vals, &mp->mp_path );
1284 rc = c->rvalue_vals ? 0 : 1;
1290 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1291 if ( !c->rvalue_vals ) rc = 1;
1294 #ifdef SLAP_AUTH_REWRITE
1296 if ( authz_rewrites ) {
1297 struct berval bv, idx;
1302 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1303 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1304 if ( idx.bv_len >= sizeof( ibuf ) ) {
1305 ber_bvarray_free_x( c->rvalue_vals, NULL );
1306 c->rvalue_vals = NULL;
1309 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1310 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1311 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1312 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1313 authz_rewrites[i].bv_val,
1314 authz_rewrites[i].bv_len + 1 );
1315 ber_bvarray_add( &c->rvalue_vals, &bv );
1318 if ( !c->rvalue_vals ) rc = 1;
1325 } else if ( c->op == LDAP_MOD_DELETE ) {
1328 /* single-valued attrs, no-ops */
1338 case CFG_MONITORING:
1340 case CFG_SSTR_IF_MAX:
1341 case CFG_SSTR_IF_MIN:
1343 case CFG_SYNC_SUBENTRY:
1346 /* no-ops, requires slapd restart */
1351 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1354 case CFG_MIRRORMODE:
1355 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MULTI_SHADOW;
1356 if(SLAP_SHADOW(c->be))
1357 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1360 #if defined(HAVE_CYRUS_SASL) && defined(SLAP_AUXPROP_DONTUSECOPY)
1362 if ( c->valx < 0 ) {
1363 if ( slap_dontUseCopy_propnames != NULL ) {
1364 ber_bvarray_free( slap_dontUseCopy_propnames );
1365 slap_dontUseCopy_propnames = NULL;
1371 if ( slap_dontUseCopy_propnames == NULL ) {
1376 for ( i = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ i ] ) && i < c->valx; i++ );
1377 if ( i < c->valx ) {
1381 ber_memfree( slap_dontUseCopy_propnames[ i ].bv_val );
1382 for ( ; !BER_BVISNULL( &slap_dontUseCopy_propnames[ i + 1 ] ); i++ ) {
1383 slap_dontUseCopy_propnames[ i ] = slap_dontUseCopy_propnames[ i + 1 ];
1385 BER_BVZERO( &slap_dontUseCopy_propnames[ i ] );
1388 #endif /* SLAP_AUXPROP_DONTUSECOPY */
1390 ch_free( passwd_salt );
1395 ch_free( logfileName );
1403 case CFG_SERVERID: {
1404 ServerID *si, **sip;
1406 for ( i=0, si = sid_list, sip = &sid_list;
1407 si; si = *sip, i++ ) {
1408 if ( c->valx == -1 || i == c->valx ) {
1410 if ( sid_set == si )
1422 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1427 c->bi->bi_flags &= ~SLAP_DBFLAG_DISABLED;
1428 if ( c->bi->bi_db_open ) {
1429 BackendInfo *bi_orig = c->be->bd_info;
1430 c->be->bd_info = c->bi;
1431 rc = c->bi->bi_db_open( c->be, &c->reply );
1432 c->be->bd_info = bi_orig;
1435 c->be->be_flags &= ~SLAP_DBFLAG_DISABLED;
1436 rc = backend_startup_one( c->be, &c->reply );
1445 index_intlen = SLAP_INDEX_INTLEN_DEFAULT;
1446 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1447 SLAP_INDEX_INTLEN_DEFAULT );
1451 if ( c->valx < 0 ) {
1452 acl_destroy( c->be->be_acl );
1453 c->be->be_acl = NULL;
1456 AccessControl **prev, *a;
1458 for (i=0, prev = &c->be->be_acl; i < c->valx;
1461 prev = &a->acl_next;
1464 *prev = a->acl_next;
1467 if ( SLAP_CONFIG( c->be ) && !c->be->be_acl ) {
1468 Debug( LDAP_DEBUG_CONFIG, "config_generic (CFG_ACL): "
1469 "Last explicit ACL for back-config removed. "
1470 "Using hardcoded default\n", 0, 0, 0 );
1471 c->be->be_acl = defacl_parsed;
1477 /* Can be NULL when undoing a failed add */
1478 if ( c->ca_entry ) {
1479 ce = c->ca_entry->e_private;
1480 /* can't modify the hardcoded schema */
1481 if ( ce->ce_parent->ce_type == Cft_Global )
1485 cfn = c->ca_private;
1486 if ( c->valx < 0 ) {
1489 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1491 if ( oc == cfn->c_oc_tail )
1494 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1496 ObjectClass *oc, *prev = NULL;
1498 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1503 if ( cfn->c_oc_tail == oc ) {
1504 cfn->c_oc_tail = prev;
1506 if ( cfn->c_oc_head == oc ) {
1508 cfn->c_oc_head = oc;
1515 /* Can be NULL when undoing a failed add */
1516 if ( c->ca_entry ) {
1517 ce = c->ca_entry->e_private;
1518 /* can't modify the hardcoded schema */
1519 if ( ce->ce_parent->ce_type == Cft_Global )
1523 cfn = c->ca_private;
1524 if ( c->valx < 0 ) {
1527 for( at = cfn->c_at_head; at; at_next( &at )) {
1529 if ( at == cfn->c_at_tail )
1532 cfn->c_at_head = cfn->c_at_tail = NULL;
1534 AttributeType *at, *prev = NULL;
1536 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1541 if ( cfn->c_at_tail == at ) {
1542 cfn->c_at_tail = prev;
1544 if ( cfn->c_at_head == at ) {
1546 cfn->c_at_head = at;
1553 /* Can be NULL when undoing a failed add */
1554 if ( c->ca_entry ) {
1555 ce = c->ca_entry->e_private;
1556 /* can't modify the hardcoded schema */
1557 if ( ce->ce_parent->ce_type == Cft_Global )
1561 cfn = c->ca_private;
1562 if ( c->valx < 0 ) {
1565 for( syn = cfn->c_syn_head; syn; syn_next( &syn )) {
1567 if ( syn == cfn->c_syn_tail )
1570 cfn->c_syn_head = cfn->c_syn_tail = NULL;
1572 Syntax *syn, *prev = NULL;
1574 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++) {
1579 if ( cfn->c_syn_tail == syn ) {
1580 cfn->c_syn_tail = prev;
1582 if ( cfn->c_syn_head == syn ) {
1584 cfn->c_syn_head = syn;
1589 if ( c->valx < 0 ) {
1591 for ( sv = sortVals; sv; sv = sortVals ) {
1592 sortVals = sv->al_next;
1593 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1600 for ( prev = &sortVals, sv = sortVals; i < c->valx; i++ ) {
1601 prev = &sv->al_next;
1604 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1605 *prev = sv->al_next;
1611 /* FIXME: there is no limits_free function */
1612 if ( c->valx < 0 ) {
1613 limits_destroy( c->be->be_limits );
1614 c->be->be_limits = NULL;
1619 if ( c->be->be_limits ) {
1620 for ( num = 0; c->be->be_limits[ num ]; num++ )
1624 if ( c->valx >= num ) {
1629 limits_destroy( c->be->be_limits );
1630 c->be->be_limits = NULL;
1633 limits_free_one( c->be->be_limits[ c->valx ] );
1635 for ( cnt = c->valx; cnt < num; cnt++ ) {
1636 c->be->be_limits[ cnt ] = c->be->be_limits[ cnt + 1 ];
1643 /* FIXME: there is no ad_option_free function */
1645 /* FIXME: there is no way to remove attributes added by
1659 if(!(c->bi = backend_info(c->argv[1]))) {
1660 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1661 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1662 c->log, c->cr_msg, c->argv[1] );
1669 /* NOTE: config is always the first backend!
1671 if ( !strcasecmp( c->argv[1], "config" )) {
1672 c->be = LDAP_STAILQ_FIRST(&backendDB);
1673 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1676 c->be = backend_db_init(c->argv[1], NULL, c->valx, &c->reply);
1678 if ( c->cr_msg[0] == 0 )
1679 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1680 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n", c->log, c->cr_msg, c->argv[1] );
1687 ldap_pvt_thread_set_concurrency(c->value_int);
1691 if ( c->value_int < 2 ) {
1692 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1693 "threads=%d smaller than minimum value 2",
1695 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1696 c->log, c->cr_msg, 0 );
1699 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1700 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1701 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1702 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1703 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1704 c->log, c->cr_msg, 0 );
1706 if ( slapMode & SLAP_SERVER_MODE )
1707 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1708 connection_pool_max = c->value_int; /* save for reference */
1712 if ( c->value_int < 1 ) {
1713 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1714 "threadqueuess=%d smaller than minimum value 1",
1716 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1717 c->log, c->cr_msg, 0 );
1720 if ( slapMode & SLAP_SERVER_MODE )
1721 ldap_pvt_thread_pool_queues(&connection_pool, c->value_int);
1722 connection_pool_queues = c->value_int; /* save for reference */
1726 if ( slapMode & SLAP_TOOL_MODE )
1727 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1728 slap_tool_thread_max = c->value_int; /* save for reference */
1733 /* use a power of two */
1734 while (c->value_uint > 1) {
1735 c->value_uint >>= 1;
1739 slapd_daemon_mask = mask;
1740 slapd_daemon_threads = mask+1;
1745 if ( passwd_salt ) ch_free( passwd_salt );
1746 passwd_salt = c->value_string;
1747 lutil_salt_format(passwd_salt);
1751 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1757 c->be->be_restrictops |= SLAP_RESTRICT_READONLY;
1759 c->be->be_restrictops &= ~SLAP_RESTRICT_READONLY;
1763 ch_free(c->value_string);
1764 if (slap_sasl_setpolicy( c->argv[1] )) {
1765 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
1766 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1767 c->log, c->cr_msg, c->argv[1] );
1773 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1777 #ifdef HAVE_CYRUS_SASL
1778 #ifdef SLAP_AUXPROP_DONTUSECOPY
1782 for ( arg = 1; arg < c->argc; arg++ ) {
1783 int duplicate = 0, err;
1784 AttributeDescription *ad = NULL;
1785 const char *text = NULL;
1787 err = slap_str2ad( c->argv[ arg ], &ad, &text );
1788 if ( err != LDAP_SUCCESS ) {
1789 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s>: attr #%d (\"%s\") unknown (err=%d \"%s\"; ignored)",
1790 c->argv[0], arg, c->argv[ arg ], err, text );
1791 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1792 c->log, c->cr_msg, 0 );
1795 if ( slap_dontUseCopy_propnames != NULL ) {
1796 for ( cnt = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ cnt ] ); cnt++ ) {
1797 if ( bvmatch( &slap_dontUseCopy_propnames[ cnt ], &ad->ad_cname ) ) {
1805 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s>: attr #%d (\"%s\") already defined (ignored)",
1806 c->argv[0], arg, ad->ad_cname.bv_val);
1807 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1808 c->log, c->cr_msg, 0 );
1812 value_add_one( &slap_dontUseCopy_propnames, &ad->ad_cname );
1817 #endif /* SLAP_AUXPROP_DONTUSECOPY */
1821 char *txt = slap_sasl_secprops( c->argv[1] );
1823 snprintf( c->cr_msg, sizeof(c->cr_msg), "<%s> %s",
1825 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0 );
1833 c->be->be_max_deref_depth = c->value_int;
1839 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1840 cfn = c->ca_private;
1841 if(parse_oidm(c, 1, &om))
1843 if (!cfn->c_om_head) cfn->c_om_head = om;
1844 cfn->c_om_tail = om;
1849 ObjectClass *oc, *prev;
1851 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1852 cfn = c->ca_private;
1853 if ( c->valx < 0 ) {
1854 prev = cfn->c_oc_tail;
1857 /* If adding anything after the first, prev is easy */
1860 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
1862 if ( !oc_next( &oc ))
1866 /* If adding the first, and head exists, find its prev */
1867 if (cfn->c_oc_head) {
1868 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
1873 /* else prev is NULL, append to end of global list */
1875 if(parse_oc(c, &oc, prev)) return(1);
1876 if (!cfn->c_oc_head || !c->valx) cfn->c_oc_head = oc;
1877 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
1882 AttributeType *at, *prev;
1884 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1885 cfn = c->ca_private;
1886 if ( c->valx < 0 ) {
1887 prev = cfn->c_at_tail;
1890 /* If adding anything after the first, prev is easy */
1893 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
1895 if ( !at_next( &at ))
1899 /* If adding the first, and head exists, find its prev */
1900 if (cfn->c_at_head) {
1901 for ( at_start( &at ); at != cfn->c_at_head; ) {
1906 /* else prev is NULL, append to end of global list */
1908 if(parse_at(c, &at, prev)) return(1);
1909 if (!cfn->c_at_head || !c->valx) cfn->c_at_head = at;
1910 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
1917 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1918 cfn = c->ca_private;
1919 if ( c->valx < 0 ) {
1920 prev = cfn->c_syn_tail;
1923 /* If adding anything after the first, prev is easy */
1926 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++ ) {
1928 if ( !syn_next( &syn ))
1932 /* If adding the first, and head exists, find its prev */
1933 if (cfn->c_syn_head) {
1934 for ( syn_start( &syn ); syn != cfn->c_syn_head; ) {
1939 /* else prev is NULL, append to end of global list */
1941 if ( parse_syn( c, &syn, prev ) ) return(1);
1942 if ( !cfn->c_syn_head || !c->valx ) cfn->c_syn_head = syn;
1943 if ( cfn->c_syn_tail == prev ) cfn->c_syn_tail = syn;
1950 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1951 cfn = c->ca_private;
1952 if(parse_cr(c, &cr)) return(1);
1953 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1954 cfn->c_cr_tail = cr;
1959 ad_define_option(NULL, NULL, 0);
1960 for(i = 1; i < c->argc; i++)
1961 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1966 if ( slap_hash64( c->value_int != 0 ))
1971 if ( c->value_int < SLAP_INDEX_INTLEN_DEFAULT )
1972 c->value_int = SLAP_INDEX_INTLEN_DEFAULT;
1973 else if ( c->value_int > 255 )
1975 index_intlen = c->value_int;
1976 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1980 case CFG_SORTVALS: {
1981 ADlist *svnew = NULL, *svtail, *sv;
1983 for ( i = 1; i < c->argc; i++ ) {
1984 AttributeDescription *ad = NULL;
1988 rc = slap_str2ad( c->argv[i], &ad, &text );
1990 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown attribute type #%d",
1993 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1994 c->log, c->cr_msg, c->argv[i] );
1995 for ( sv = svnew; sv; sv = svnew ) {
1996 svnew = sv->al_next;
2001 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) ||
2002 ad->ad_type->sat_single_value ) {
2003 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> inappropriate attribute type #%d",
2005 goto sortval_reject;
2007 sv = ch_malloc( sizeof( ADlist ));
2012 svtail->al_next = sv;
2017 for ( sv = svnew; sv; sv = sv->al_next )
2018 sv->al_desc->ad_type->sat_flags |= SLAP_AT_SORTED_VAL;
2019 for ( sv = sortVals; sv && sv->al_next; sv = sv->al_next );
2021 sv->al_next = svnew;
2028 if ( SLAP_CONFIG( c->be ) && c->be->be_acl == defacl_parsed) {
2029 c->be->be_acl = NULL;
2031 /* Don't append to the global ACL if we're on a specific DB */
2033 if ( c->valx == -1 ) {
2036 for ( a=c->be->be_acl; a; a = a->acl_next )
2039 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
2040 if ( SLAP_CONFIG( c->be ) && !c->be->be_acl) {
2041 c->be->be_acl = defacl_parsed;
2049 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_ACL_ADD;
2051 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_ACL_ADD;
2055 if(root_dse_read_file(c->argv[1])) {
2056 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> could not read file", c->argv[0] );
2057 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2058 c->log, c->cr_msg, c->argv[1] );
2063 ber_str2bv( c->argv[1], 0, 1, &bv );
2064 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
2065 cfn = c->ca_private;
2066 ber_bvarray_add( &cfn->c_dseFiles, &bv );
2072 ServerID *si, **sip;
2075 if (( lutil_atoi( &num, c->argv[1] ) &&
2076 lutil_atoix( &num, c->argv[1], 16 )) ||
2077 num < 0 || num > SLAP_SYNC_SID_MAX )
2079 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2080 "<%s> illegal server ID", c->argv[0] );
2081 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2082 c->log, c->cr_msg, c->argv[1] );
2085 /* only one value allowed if no URL is given */
2086 if ( c->argc > 2 ) {
2089 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
2090 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2091 "<%s> only one server ID allowed now", c->argv[0] );
2092 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2093 c->log, c->cr_msg, c->argv[1] );
2097 if ( ldap_url_parse( c->argv[2], &lud )) {
2098 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2099 "<%s> invalid URL", c->argv[0] );
2100 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2101 c->log, c->cr_msg, c->argv[2] );
2104 len = strlen( c->argv[2] );
2105 si = ch_malloc( sizeof(ServerID) + len + 1 );
2106 si->si_url.bv_val = (char *)(si+1);
2107 si->si_url.bv_len = len;
2108 strcpy( si->si_url.bv_val, c->argv[2] );
2111 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2112 "<%s> unqualified server ID not allowed now", c->argv[0] );
2113 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2114 c->log, c->cr_msg, c->argv[1] );
2117 si = ch_malloc( sizeof(ServerID) );
2118 BER_BVZERO( &si->si_url );
2119 slap_serverID = num;
2120 Debug( LDAP_DEBUG_CONFIG,
2122 c->log, slap_serverID, 0 );
2127 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
2130 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
2131 Listener *l = config_check_my_url( c->argv[2], lud );
2134 ldap_free_urldesc( lud );
2135 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2136 "<%s> multiple server ID URLs matched, only one is allowed", c->argv[0] );
2137 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2138 c->log, c->cr_msg, c->argv[1] );
2141 slap_serverID = si->si_num;
2142 Debug( LDAP_DEBUG_CONFIG,
2143 "%s: SID=0x%03x (listener=%s)\n",
2144 c->log, slap_serverID,
2150 ldap_free_urldesc( lud );
2154 if ( logfileName ) ch_free( logfileName );
2155 logfileName = c->value_string;
2156 logfile = fopen(logfileName, "w");
2157 if(logfile) lutil_debug_file(logfile);
2161 if(SLAP_NOLASTMODCMD(c->be)) {
2162 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> not available for %s database",
2163 c->argv[0], c->be->bd_info->bi_type );
2164 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2165 c->log, c->cr_msg, 0 );
2169 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
2171 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
2174 case CFG_MIRRORMODE:
2175 if(c->value_int && !SLAP_SHADOW(c->be)) {
2176 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database is not a shadow",
2178 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2179 c->log, c->cr_msg, 0 );
2183 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
2184 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MULTI_SHADOW;
2186 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
2187 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MULTI_SHADOW;
2191 case CFG_MONITORING:
2193 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
2195 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
2201 if ( c->bi->bi_db_close ) {
2202 BackendInfo *bi_orig = c->be->bd_info;
2203 c->be->bd_info = c->bi;
2204 c->bi->bi_db_close( c->be, &c->reply );
2205 c->be->bd_info = bi_orig;
2207 c->bi->bi_flags |= SLAPO_BFLAG_DISABLED;
2209 c->bi->bi_flags &= ~SLAPO_BFLAG_DISABLED;
2213 backend_shutdown( c->be );
2214 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_DISABLED;
2216 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_DISABLED;
2223 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
2225 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
2228 case CFG_SYNC_SUBENTRY:
2230 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SYNC_SUBENTRY;
2232 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SYNC_SUBENTRY;
2235 case CFG_SSTR_IF_MAX:
2236 if (c->value_uint < index_substr_if_minlen) {
2237 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
2238 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
2239 c->log, c->cr_msg, c->value_int );
2242 index_substr_if_maxlen = c->value_uint;
2245 case CFG_SSTR_IF_MIN:
2246 if (c->value_uint > index_substr_if_maxlen) {
2247 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
2248 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
2249 c->log, c->cr_msg, c->value_int );
2252 index_substr_if_minlen = c->value_uint;
2255 #ifdef SLAPD_MODULES
2257 /* If we're just adding a module on an existing modpath,
2258 * make sure we've selected the current path.
2260 if ( c->op == LDAP_MOD_ADD && c->ca_private && modcur != c->ca_private ) {
2261 modcur = c->ca_private;
2262 /* This should never fail */
2263 if ( module_path( modcur->mp_path.bv_val )) {
2264 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> module path no longer valid",
2266 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2267 c->log, c->cr_msg, modcur->mp_path.bv_val );
2271 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
2273 /* Record this load on the current path */
2277 if ( c->op == SLAP_CONFIG_ADD ) {
2278 ptr = c->line + STRLENOF("moduleload");
2279 while (!isspace((unsigned char) *ptr)) ptr++;
2280 while (isspace((unsigned char) *ptr)) ptr++;
2284 ber_str2bv(ptr, 0, 1, &bv);
2285 ber_bvarray_add( &modcur->mp_loads, &bv );
2287 /* Check for any new hardcoded schema */
2288 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
2289 config_check_schema( NULL, &cfBackInfo );
2294 if(module_path(c->argv[1])) return(1);
2295 /* Record which path was used with each module */
2299 if (!modpaths.mp_loads) {
2302 mp = ch_malloc( sizeof( ModPaths ));
2303 modlast->mp_next = mp;
2305 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
2307 mp->mp_loads = NULL;
2318 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
2320 slapi_plugins_used++;
2324 #ifdef SLAP_AUTH_REWRITE
2330 if ( c->op == LDAP_MOD_ADD ) {
2334 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
2338 if ( c->argc > 1 ) {
2341 /* quote all args but the first */
2342 line = ldap_charray2str( c->argv, "\" \"" );
2343 ber_str2bv( line, 0, 0, &bv );
2344 s = ber_bvchr( &bv, '"' );
2345 assert( s != NULL );
2346 /* move the trailing quote of argv[0] to the end */
2347 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
2348 bv.bv_val[ bv.bv_len - 1 ] = '"';
2351 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
2354 ber_bvarray_add( &authz_rewrites, &bv );
2356 if ( c->op == LDAP_MOD_ADD ) {
2366 Debug( LDAP_DEBUG_ANY,
2367 "%s: unknown CFG_TYPE %d.\n",
2368 c->log, c->type, 0 );
2377 config_fname(ConfigArgs *c) {
2378 if(c->op == SLAP_CONFIG_EMIT) {
2379 if (c->ca_private) {
2380 ConfigFile *cf = c->ca_private;
2381 value_add_one( &c->rvalue_vals, &cf->c_file );
2390 config_cfdir(ConfigArgs *c) {
2391 if(c->op == SLAP_CONFIG_EMIT) {
2392 if ( !BER_BVISEMPTY( &cfdir )) {
2393 value_add_one( &c->rvalue_vals, &cfdir );
2402 config_search_base(ConfigArgs *c) {
2403 if(c->op == SLAP_CONFIG_EMIT) {
2405 if (!BER_BVISEMPTY(&default_search_base)) {
2406 value_add_one(&c->rvalue_vals, &default_search_base);
2407 value_add_one(&c->rvalue_nvals, &default_search_nbase);
2411 } else if( c->op == LDAP_MOD_DELETE ) {
2412 ch_free( default_search_base.bv_val );
2413 ch_free( default_search_nbase.bv_val );
2414 BER_BVZERO( &default_search_base );
2415 BER_BVZERO( &default_search_nbase );
2419 if(c->bi || c->be != frontendDB) {
2420 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
2421 "prior to any backend or database definition\n",
2426 if(default_search_nbase.bv_len) {
2427 free(default_search_base.bv_val);
2428 free(default_search_nbase.bv_val);
2431 default_search_base = c->value_dn;
2432 default_search_nbase = c->value_ndn;
2436 /* For RE23 compatibility we allow this in the global entry
2437 * but we now defer it to the frontend entry to allow modules
2438 * to load new hash types.
2441 config_passwd_hash(ConfigArgs *c) {
2443 if (c->op == SLAP_CONFIG_EMIT) {
2445 /* Don't generate it in the global entry */
2446 if ( c->table == Cft_Global )
2448 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
2449 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
2450 value_add_one(&c->rvalue_vals, &bv);
2453 } else if ( c->op == LDAP_MOD_DELETE ) {
2454 /* Deleting from global is a no-op, only the frontendDB entry matters */
2455 if ( c->table == Cft_Global )
2457 if ( c->valx < 0 ) {
2458 ldap_charray_free( default_passwd_hash );
2459 default_passwd_hash = NULL;
2462 ch_free( default_passwd_hash[i] );
2463 for (; default_passwd_hash[i]; i++ )
2464 default_passwd_hash[i] = default_passwd_hash[i+1];
2468 for(i = 1; i < c->argc; i++) {
2469 if(!lutil_passwd_scheme(c->argv[i])) {
2470 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> scheme not available", c->argv[0] );
2471 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2472 c->log, c->cr_msg, c->argv[i]);
2474 ldap_charray_add(&default_passwd_hash, c->argv[i]);
2477 if(!default_passwd_hash) {
2478 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> no valid hashes found", c->argv[0] );
2479 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2480 c->log, c->cr_msg, 0 );
2487 config_schema_dn(ConfigArgs *c) {
2488 if ( c->op == SLAP_CONFIG_EMIT ) {
2490 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
2491 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
2492 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
2496 } else if ( c->op == LDAP_MOD_DELETE ) {
2497 ch_free( c->be->be_schemadn.bv_val );
2498 ch_free( c->be->be_schemandn.bv_val );
2499 BER_BVZERO( &c->be->be_schemadn );
2500 BER_BVZERO( &c->be->be_schemandn );
2503 ch_free( c->be->be_schemadn.bv_val );
2504 ch_free( c->be->be_schemandn.bv_val );
2505 c->be->be_schemadn = c->value_dn;
2506 c->be->be_schemandn = c->value_ndn;
2511 config_sizelimit(ConfigArgs *c) {
2513 struct slap_limits_set *lim = &c->be->be_def_limit;
2514 if (c->op == SLAP_CONFIG_EMIT) {
2519 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
2520 if ( !BER_BVISEMPTY( &bv ))
2521 value_add_one( &c->rvalue_vals, &bv );
2525 } else if ( c->op == LDAP_MOD_DELETE ) {
2526 /* Reset to defaults or values from frontend */
2527 if ( c->be == frontendDB ) {
2528 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
2529 lim->lms_s_hard = 0;
2530 lim->lms_s_unchecked = -1;
2532 lim->lms_s_pr_hide = 0;
2533 lim->lms_s_pr_total = 0;
2535 lim->lms_s_soft = frontendDB->be_def_limit.lms_s_soft;
2536 lim->lms_s_hard = frontendDB->be_def_limit.lms_s_hard;
2537 lim->lms_s_unchecked = frontendDB->be_def_limit.lms_s_unchecked;
2538 lim->lms_s_pr = frontendDB->be_def_limit.lms_s_pr;
2539 lim->lms_s_pr_hide = frontendDB->be_def_limit.lms_s_pr_hide;
2540 lim->lms_s_pr_total = frontendDB->be_def_limit.lms_s_pr_total;
2544 for(i = 1; i < c->argc; i++) {
2545 if(!strncasecmp(c->argv[i], "size", 4)) {
2546 rc = limits_parse_one(c->argv[i], lim);
2548 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2549 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2550 c->log, c->cr_msg, c->argv[i]);
2554 if(!strcasecmp(c->argv[i], "unlimited")) {
2555 lim->lms_s_soft = -1;
2557 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
2558 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2559 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2560 c->log, c->cr_msg, c->argv[i]);
2564 lim->lms_s_hard = 0;
2569 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2570 /* This is a modification to the global limits apply it to
2571 * the other databases as needed */
2572 AttributeDescription *ad=NULL;
2573 const char *text = NULL;
2574 CfEntryInfo *ce = c->ca_entry->e_private;
2576 slap_str2ad(c->argv[0], &ad, &text);
2577 /* if we got here... */
2578 assert( ad != NULL );
2580 if ( ce->ce_type == Cft_Global ){
2583 for (; ce; ce=ce->ce_sibs) {
2584 Entry *dbe = ce->ce_entry;
2585 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2586 && (!attr_find(dbe->e_attrs, ad)) ) {
2587 ce->ce_be->be_def_limit.lms_s_soft = lim->lms_s_soft;
2588 ce->ce_be->be_def_limit.lms_s_hard = lim->lms_s_hard;
2589 ce->ce_be->be_def_limit.lms_s_unchecked =lim->lms_s_unchecked;
2590 ce->ce_be->be_def_limit.lms_s_pr =lim->lms_s_pr;
2591 ce->ce_be->be_def_limit.lms_s_pr_hide =lim->lms_s_pr_hide;
2592 ce->ce_be->be_def_limit.lms_s_pr_total =lim->lms_s_pr_total;
2600 config_timelimit(ConfigArgs *c) {
2602 struct slap_limits_set *lim = &c->be->be_def_limit;
2603 if (c->op == SLAP_CONFIG_EMIT) {
2608 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
2609 if ( !BER_BVISEMPTY( &bv ))
2610 value_add_one( &c->rvalue_vals, &bv );
2614 } else if ( c->op == LDAP_MOD_DELETE ) {
2615 /* Reset to defaults or values from frontend */
2616 if ( c->be == frontendDB ) {
2617 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
2618 lim->lms_t_hard = 0;
2620 lim->lms_t_soft = frontendDB->be_def_limit.lms_t_soft;
2621 lim->lms_t_hard = frontendDB->be_def_limit.lms_t_hard;
2625 for(i = 1; i < c->argc; i++) {
2626 if(!strncasecmp(c->argv[i], "time", 4)) {
2627 rc = limits_parse_one(c->argv[i], lim);
2629 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2630 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2631 c->log, c->cr_msg, c->argv[i]);
2635 if(!strcasecmp(c->argv[i], "unlimited")) {
2636 lim->lms_t_soft = -1;
2638 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
2639 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2640 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2641 c->log, c->cr_msg, c->argv[i]);
2645 lim->lms_t_hard = 0;
2650 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2651 /* This is a modification to the global limits apply it to
2652 * the other databases as needed */
2653 AttributeDescription *ad=NULL;
2654 const char *text = NULL;
2655 CfEntryInfo *ce = c->ca_entry->e_private;
2657 slap_str2ad(c->argv[0], &ad, &text);
2658 /* if we got here... */
2659 assert( ad != NULL );
2661 if ( ce->ce_type == Cft_Global ){
2664 for (; ce; ce=ce->ce_sibs) {
2665 Entry *dbe = ce->ce_entry;
2666 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2667 && (!attr_find(dbe->e_attrs, ad)) ) {
2668 ce->ce_be->be_def_limit.lms_t_soft = lim->lms_t_soft;
2669 ce->ce_be->be_def_limit.lms_t_hard = lim->lms_t_hard;
2677 config_overlay(ConfigArgs *c) {
2678 if (c->op == SLAP_CONFIG_EMIT) {
2680 } else if ( c->op == LDAP_MOD_DELETE ) {
2683 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2684 c->valx, &c->bi, &c->reply)) {
2686 Debug( LDAP_DEBUG_ANY,
2687 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2688 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2690 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi, &c->reply)) {
2697 config_subordinate(ConfigArgs *c)
2703 case SLAP_CONFIG_EMIT:
2704 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2707 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2708 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2711 value_add_one( &c->rvalue_vals, &bv );
2715 case LDAP_MOD_DELETE:
2716 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2717 glue_sub_del( c->be );
2719 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2724 case SLAP_CONFIG_ADD:
2725 if ( c->be->be_nsuffix == NULL ) {
2727 snprintf( c->cr_msg, sizeof( c->cr_msg),
2728 "subordinate configuration needs a suffix" );
2729 Debug( LDAP_DEBUG_ANY,
2731 c->log, c->cr_msg, 0 );
2736 if ( c->argc == 2 ) {
2737 if ( strcasecmp( c->argv[1], "advertise" ) == 0 ) {
2740 } else if ( strcasecmp( c->argv[1], "TRUE" ) != 0 ) {
2742 snprintf( c->cr_msg, sizeof( c->cr_msg),
2743 "subordinate must be \"TRUE\" or \"advertise\"" );
2744 Debug( LDAP_DEBUG_ANY,
2745 "%s: suffix \"%s\": %s.\n",
2746 c->log, c->be->be_suffix[0].bv_val, c->cr_msg );
2752 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2760 * [listener=<listener>] [{read|write}=]<size>
2763 #ifdef LDAP_TCP_BUFFER
2764 static BerVarray tcp_buffer;
2767 #define SLAP_TCP_RMEM (0x1U)
2768 #define SLAP_TCP_WMEM (0x2U)
2771 tcp_buffer_parse( struct berval *val, int argc, char **argv,
2772 int *size, int *rw, Listener **l )
2774 int i, rc = LDAP_SUCCESS;
2775 LDAPURLDesc *lud = NULL;
2778 if ( val != NULL && argv == NULL ) {
2779 char *s = val->bv_val;
2781 argv = ldap_str2charray( s, " \t" );
2782 if ( argv == NULL ) {
2788 if ( strncasecmp( argv[ i ], "listener=", STRLENOF( "listener=" ) )
2791 char *url = argv[ i ] + STRLENOF( "listener=" );
2793 if ( ldap_url_parse( url, &lud ) ) {
2794 rc = LDAP_INVALID_SYNTAX;
2798 *l = config_check_my_url( url, lud );
2800 rc = LDAP_NO_SUCH_ATTRIBUTE;
2808 if ( strncasecmp( ptr, "read=", STRLENOF( "read=" ) ) == 0 ) {
2809 *rw |= SLAP_TCP_RMEM;
2810 ptr += STRLENOF( "read=" );
2812 } else if ( strncasecmp( ptr, "write=", STRLENOF( "write=" ) ) == 0 ) {
2813 *rw |= SLAP_TCP_WMEM;
2814 ptr += STRLENOF( "write=" );
2817 *rw |= ( SLAP_TCP_RMEM | SLAP_TCP_WMEM );
2820 /* accept any base */
2821 if ( lutil_atoix( size, ptr, 0 ) ) {
2822 rc = LDAP_INVALID_SYNTAX;
2827 if ( val != NULL && argv != NULL ) {
2828 ldap_charray_free( argv );
2831 if ( lud != NULL ) {
2832 ldap_free_urldesc( lud );
2839 tcp_buffer_delete_one( struct berval *val )
2842 int size = -1, rw = 0;
2845 rc = tcp_buffer_parse( val, 0, NULL, &size, &rw, &l );
2852 Listener **ll = slapd_get_listeners();
2854 for ( i = 0; ll[ i ] != NULL; i++ ) {
2855 if ( ll[ i ] == l ) break;
2858 if ( ll[ i ] == NULL ) {
2859 return LDAP_NO_SUCH_ATTRIBUTE;
2862 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = -1;
2863 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = -1;
2865 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2866 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = -1;
2867 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = -1;
2871 /* NOTE: this affects listeners without a specific setting,
2872 * does not reset all listeners. If a listener without
2873 * specific settings was assigned a buffer because of
2874 * a global setting, it will not be reset. In any case,
2875 * buffer changes will only take place at restart. */
2876 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = -1;
2877 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = -1;
2884 tcp_buffer_delete( BerVarray vals )
2888 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
2889 tcp_buffer_delete_one( &vals[ i ] );
2896 tcp_buffer_unparse( int size, int rw, Listener *l, struct berval *val )
2898 char buf[sizeof("2147483648")], *ptr;
2900 /* unparse for later use */
2901 val->bv_len = snprintf( buf, sizeof( buf ), "%d", size );
2903 val->bv_len += STRLENOF( "listener=" " " ) + l->sl_url.bv_len;
2906 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2907 if ( rw & SLAP_TCP_RMEM ) {
2908 val->bv_len += STRLENOF( "read=" );
2909 } else if ( rw & SLAP_TCP_WMEM ) {
2910 val->bv_len += STRLENOF( "write=" );
2914 val->bv_val = SLAP_MALLOC( val->bv_len + 1 );
2919 ptr = lutil_strcopy( ptr, "listener=" );
2920 ptr = lutil_strncopy( ptr, l->sl_url.bv_val, l->sl_url.bv_len );
2924 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2925 if ( rw & SLAP_TCP_RMEM ) {
2926 ptr = lutil_strcopy( ptr, "read=" );
2927 } else if ( rw & SLAP_TCP_WMEM ) {
2928 ptr = lutil_strcopy( ptr, "write=" );
2932 ptr = lutil_strcopy( ptr, buf );
2935 assert( val->bv_val + val->bv_len == ptr );
2937 return LDAP_SUCCESS;
2941 tcp_buffer_add_one( int argc, char **argv )
2944 int size = -1, rw = 0;
2950 rc = tcp_buffer_parse( NULL, argc, argv, &size, &rw, &l );
2955 /* unparse for later use */
2956 rc = tcp_buffer_unparse( size, rw, l, &val );
2957 if ( rc != LDAP_SUCCESS ) {
2961 /* use parsed values */
2964 Listener **ll = slapd_get_listeners();
2966 for ( i = 0; ll[ i ] != NULL; i++ ) {
2967 if ( ll[ i ] == l ) break;
2970 if ( ll[ i ] == NULL ) {
2971 return LDAP_NO_SUCH_ATTRIBUTE;
2974 /* buffer only applies to TCP listeners;
2975 * we do not do any check here, and delegate them
2976 * to setsockopt(2) */
2977 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = size;
2978 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = size;
2980 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2981 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = size;
2982 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = size;
2986 /* NOTE: this affects listeners without a specific setting,
2987 * does not set all listeners */
2988 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = size;
2989 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = size;
2992 tcp_buffer = SLAP_REALLOC( tcp_buffer, sizeof( struct berval ) * ( tcp_buffer_num + 2 ) );
2994 tcp_buffer[ tcp_buffer_num ] = val;
2997 BER_BVZERO( &tcp_buffer[ tcp_buffer_num ] );
3003 config_tcp_buffer( ConfigArgs *c )
3005 if ( c->op == SLAP_CONFIG_EMIT ) {
3006 if ( tcp_buffer == NULL || BER_BVISNULL( &tcp_buffer[ 0 ] ) ) {
3009 value_add( &c->rvalue_vals, tcp_buffer );
3010 value_add( &c->rvalue_nvals, tcp_buffer );
3012 } else if ( c->op == LDAP_MOD_DELETE ) {
3014 tcp_buffer_delete( tcp_buffer );
3015 ber_bvarray_free( tcp_buffer );
3021 int size = -1, rw = 0;
3024 struct berval val = BER_BVNULL;
3028 if ( tcp_buffer_num == 0 ) {
3033 rc = tcp_buffer_parse( NULL, c->argc - 1, &c->argv[ 1 ], &size, &rw, &l );
3038 /* unparse for later use */
3039 rc = tcp_buffer_unparse( size, rw, l, &val );
3040 if ( rc != LDAP_SUCCESS ) {
3044 for ( i = 0; !BER_BVISNULL( &tcp_buffer[ i ] ); i++ ) {
3045 if ( bvmatch( &tcp_buffer[ i ], &val ) ) {
3050 if ( BER_BVISNULL( &tcp_buffer[ i ] ) ) {
3056 tcp_buffer_delete_one( &tcp_buffer[ i ] );
3057 ber_memfree( tcp_buffer[ i ].bv_val );
3058 for ( ; i < tcp_buffer_num; i++ ) {
3059 tcp_buffer[ i ] = tcp_buffer[ i + 1 ];
3064 if ( !BER_BVISNULL( &val ) ) {
3065 SLAP_FREE( val.bv_val );
3073 rc = tcp_buffer_add_one( c->argc - 1, &c->argv[ 1 ] );
3075 snprintf( c->cr_msg, sizeof( c->cr_msg ),
3076 "<%s> unable to add value #%d",
3077 c->argv[0], tcp_buffer_num );
3078 Debug( LDAP_DEBUG_ANY, "%s: %s\n",
3079 c->log, c->cr_msg, 0 );
3086 #endif /* LDAP_TCP_BUFFER */
3089 config_suffix(ConfigArgs *c)
3092 struct berval pdn, ndn;
3093 char *notallowed = NULL;
3095 if ( c->be == frontendDB ) {
3096 notallowed = "frontend";
3098 } else if ( SLAP_MONITOR(c->be) ) {
3099 notallowed = "monitor";
3101 } else if ( SLAP_CONFIG(c->be) ) {
3102 notallowed = "config";
3105 if ( notallowed != NULL ) {
3106 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
3110 case LDAP_MOD_DELETE:
3111 case LDAP_MOD_REPLACE:
3112 case LDAP_MOD_INCREMENT:
3113 case SLAP_CONFIG_ADD:
3114 if ( !BER_BVISNULL( &c->value_dn ) ) {
3115 snprintf( buf, sizeof( buf ), "<%s> ",
3116 c->value_dn.bv_val );
3119 Debug(LDAP_DEBUG_ANY,
3120 "%s: suffix %snot allowed in %s database.\n",
3121 c->log, buf, notallowed );
3124 case SLAP_CONFIG_EMIT:
3125 /* don't complain when emitting... */
3129 /* FIXME: don't know what values may be valid;
3130 * please remove assertion, or add legal values
3131 * to either block */
3139 if (c->op == SLAP_CONFIG_EMIT) {
3140 if ( c->be->be_suffix == NULL
3141 || BER_BVISNULL( &c->be->be_suffix[0] ) )
3145 value_add( &c->rvalue_vals, c->be->be_suffix );
3146 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
3149 } else if ( c->op == LDAP_MOD_DELETE ) {
3150 if ( c->valx < 0 ) {
3151 ber_bvarray_free( c->be->be_suffix );
3152 ber_bvarray_free( c->be->be_nsuffix );
3153 c->be->be_suffix = NULL;
3154 c->be->be_nsuffix = NULL;
3157 ch_free( c->be->be_suffix[i].bv_val );
3158 ch_free( c->be->be_nsuffix[i].bv_val );
3160 c->be->be_suffix[i] = c->be->be_suffix[i+1];
3161 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
3163 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
3168 #ifdef SLAPD_MONITOR_DN
3169 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
3170 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> DN is reserved for monitoring slapd",
3172 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3173 c->log, c->cr_msg, SLAPD_MONITOR_DN);
3178 if (SLAP_DB_ONE_SUFFIX( c->be ) && c->be->be_suffix &&
3179 !BER_BVISNULL( &c->be->be_suffix[0] )) {
3180 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> Only one suffix is allowed on this %s backend",
3181 c->argv[0], c->be->bd_info->bi_type );
3182 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3183 c->log, c->cr_msg, 0);
3190 if (SLAP_DBHIDDEN( c->be ))
3193 tbe = select_backend(&ndn, 0);
3195 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
3201 BackendDB *b2 = tbe;
3203 /* Does tbe precede be? */
3204 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
3207 char *type = tbe->bd_info->bi_type;
3209 if ( overlay_is_over( tbe ) ) {
3210 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
3211 type = oi->oi_orig->bi_type;
3214 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> namingContext \"%s\" "
3215 "already served by a preceding %s database",
3216 c->argv[0], pdn.bv_val, type );
3217 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
3218 c->log, c->cr_msg, tbe->be_suffix[0].bv_val);
3224 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
3225 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
3226 "base provided \"%s\" (assuming okay)\n",
3227 c->log, default_search_base.bv_val, 0);
3229 ber_bvarray_add(&c->be->be_suffix, &pdn);
3230 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
3235 config_rootdn(ConfigArgs *c) {
3236 if (c->op == SLAP_CONFIG_EMIT) {
3237 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
3238 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
3239 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
3244 } else if ( c->op == LDAP_MOD_DELETE ) {
3245 ch_free( c->be->be_rootdn.bv_val );
3246 ch_free( c->be->be_rootndn.bv_val );
3247 BER_BVZERO( &c->be->be_rootdn );
3248 BER_BVZERO( &c->be->be_rootndn );
3251 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
3252 ch_free( c->be->be_rootdn.bv_val );
3253 ch_free( c->be->be_rootndn.bv_val );
3255 c->be->be_rootdn = c->value_dn;
3256 c->be->be_rootndn = c->value_ndn;
3261 config_rootpw(ConfigArgs *c) {
3264 if (c->op == SLAP_CONFIG_EMIT) {
3265 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
3266 /* don't copy, because "rootpw" is marked
3268 c->value_bv = c->be->be_rootpw;
3272 } else if ( c->op == LDAP_MOD_DELETE ) {
3273 ch_free( c->be->be_rootpw.bv_val );
3274 BER_BVZERO( &c->be->be_rootpw );
3278 tbe = select_backend(&c->be->be_rootndn, 0);
3280 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> can only be set when rootdn is under suffix",
3282 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3283 c->log, c->cr_msg, 0);
3286 if ( !BER_BVISNULL( &c->be->be_rootpw ))
3287 ch_free( c->be->be_rootpw.bv_val );
3288 c->be->be_rootpw = c->value_bv;
3293 config_restrict(ConfigArgs *c) {
3294 slap_mask_t restrictops = 0;
3296 slap_verbmasks restrictable_ops[] = {
3297 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
3298 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
3299 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
3300 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
3301 { BER_BVC("modrdn"), 0 },
3302 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
3303 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
3304 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
3305 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
3306 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
3307 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
3308 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
3309 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
3310 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
3311 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
3312 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
3316 if (c->op == SLAP_CONFIG_EMIT) {
3317 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
3319 } else if ( c->op == LDAP_MOD_DELETE ) {
3321 c->be->be_restrictops = 0;
3323 i = verb_to_mask( c->line, restrictable_ops );
3324 c->be->be_restrictops &= ~restrictable_ops[i].mask;
3328 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
3330 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown operation", c->argv[0] );
3331 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3332 c->log, c->cr_msg, c->argv[i]);
3335 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
3336 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
3337 c->be->be_restrictops |= restrictops;
3342 config_allows(ConfigArgs *c) {
3343 slap_mask_t allows = 0;
3345 slap_verbmasks allowable_ops[] = {
3346 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
3347 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
3348 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
3349 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
3350 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
3353 if (c->op == SLAP_CONFIG_EMIT) {
3354 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
3355 } else if ( c->op == LDAP_MOD_DELETE ) {
3359 i = verb_to_mask( c->line, allowable_ops );
3360 global_allows &= ~allowable_ops[i].mask;
3364 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
3366 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3367 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3368 c->log, c->cr_msg, c->argv[i]);
3371 global_allows |= allows;
3376 config_disallows(ConfigArgs *c) {
3377 slap_mask_t disallows = 0;
3379 slap_verbmasks disallowable_ops[] = {
3380 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
3381 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
3382 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
3383 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
3384 { BER_BVC("proxy_authz_non_critical"), SLAP_DISALLOW_PROXY_AUTHZ_N_CRIT },
3385 { BER_BVC("dontusecopy_non_critical"), SLAP_DISALLOW_DONTUSECOPY_N_CRIT },
3388 if (c->op == SLAP_CONFIG_EMIT) {
3389 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
3390 } else if ( c->op == LDAP_MOD_DELETE ) {
3392 global_disallows = 0;
3394 i = verb_to_mask( c->line, disallowable_ops );
3395 global_disallows &= ~disallowable_ops[i].mask;
3399 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
3401 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3402 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3403 c->log, c->cr_msg, c->argv[i]);
3406 global_disallows |= disallows;
3411 config_requires(ConfigArgs *c) {
3412 slap_mask_t requires = frontendDB->be_requires;
3413 int i, argc = c->argc;
3414 char **argv = c->argv;
3416 slap_verbmasks requires_ops[] = {
3417 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
3418 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
3419 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
3420 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
3421 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
3424 if (c->op == SLAP_CONFIG_EMIT) {
3425 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
3426 } else if ( c->op == LDAP_MOD_DELETE ) {
3428 c->be->be_requires = 0;
3430 i = verb_to_mask( c->line, requires_ops );
3431 c->be->be_requires &= ~requires_ops[i].mask;
3435 /* "none" can only be first, to wipe out default/global values */
3436 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
3441 i = verbs_to_mask(argc, argv, requires_ops, &requires);
3443 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
3444 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
3445 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3446 c->log, c->cr_msg, 0);
3448 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
3449 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3450 c->log, c->cr_msg, c->argv[i]);
3454 c->be->be_requires = requires;
3459 config_extra_attrs(ConfigArgs *c)
3461 assert( c->be != NULL );
3463 if ( c->op == SLAP_CONFIG_EMIT ) {
3466 if ( c->be->be_extra_anlist == NULL ) {
3470 for ( i = 0; !BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ); i++ ) {
3471 value_add_one( &c->rvalue_vals, &c->be->be_extra_anlist[i].an_name );
3474 } else if ( c->op == LDAP_MOD_DELETE ) {
3475 if ( c->be->be_extra_anlist == NULL ) {
3479 if ( c->valx < 0 ) {
3480 anlist_free( c->be->be_extra_anlist, 1, NULL );
3481 c->be->be_extra_anlist = NULL;
3486 for ( i = 0; i < c->valx && !BER_BVISNULL( &c->be->be_extra_anlist[i + 1].an_name ); i++ )
3489 if ( BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ) ) {
3493 ch_free( c->be->be_extra_anlist[i].an_name.bv_val );
3495 for ( ; !BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ); i++ ) {
3496 c->be->be_extra_anlist[i] = c->be->be_extra_anlist[i + 1];
3501 c->be->be_extra_anlist = str2anlist( c->be->be_extra_anlist, c->argv[1], " ,\t" );
3502 if ( c->be->be_extra_anlist == NULL ) {
3510 static slap_verbmasks *loglevel_ops;
3513 loglevel_init( void )
3515 slap_verbmasks lo[] = {
3516 { BER_BVC("Any"), (slap_mask_t) LDAP_DEBUG_ANY },
3517 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
3518 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
3519 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
3520 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
3521 { BER_BVC("BER"), LDAP_DEBUG_BER },
3522 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
3523 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
3524 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
3525 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
3526 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
3527 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
3528 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
3529 #if 0 /* no longer used (nor supported) */
3530 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
3531 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
3533 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
3534 { BER_BVC("None"), LDAP_DEBUG_NONE },
3538 return slap_verbmasks_init( &loglevel_ops, lo );
3542 loglevel_destroy( void )
3544 if ( loglevel_ops ) {
3545 (void)slap_verbmasks_destroy( loglevel_ops );
3547 loglevel_ops = NULL;
3550 static slap_mask_t loglevel_ignore[] = { -1, 0 };
3553 slap_loglevel_register( slap_mask_t m, struct berval *s )
3557 if ( loglevel_ops == NULL ) {
3561 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
3564 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
3572 slap_loglevel_get( struct berval *s, int *l )
3577 if ( loglevel_ops == NULL ) {
3581 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3582 m |= loglevel_ops[ i ].mask;
3585 for ( i = 1; m & i; i <<= 1 )
3592 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
3595 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
3606 str2loglevel( const char *s, int *l )
3610 if ( loglevel_ops == NULL ) {
3614 i = verb_to_mask( s, loglevel_ops );
3616 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
3620 *l = loglevel_ops[ i ].mask;
3626 loglevel2str( int l )
3628 struct berval bv = BER_BVNULL;
3630 loglevel2bv( l, &bv );
3636 loglevel2bv( int l, struct berval *bv )
3638 if ( loglevel_ops == NULL ) {
3644 return enum_to_verb( loglevel_ops, l, bv ) == -1;
3648 loglevel2bvarray( int l, BerVarray *bva )
3650 if ( loglevel_ops == NULL ) {
3655 return value_add_one( bva, ber_bvstr( "0" ) );
3658 return mask_to_verbs( loglevel_ops, l, bva );
3662 loglevel_print( FILE *out )
3666 if ( loglevel_ops == NULL ) {
3670 fprintf( out, "Installed log subsystems:\n\n" );
3671 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3672 unsigned mask = loglevel_ops[ i ].mask & 0xffffffffUL;
3674 (mask == ((slap_mask_t) -1 & 0xffffffffUL)
3675 ? "\t%-30s (-1, 0xffffffff)\n" : "\t%-30s (%u, 0x%x)\n"),
3676 loglevel_ops[ i ].word.bv_val, mask, mask );
3679 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
3680 "by specific code\n\n" );
3685 static int config_syslog;
3688 config_loglevel(ConfigArgs *c) {
3691 if ( loglevel_ops == NULL ) {
3695 if (c->op == SLAP_CONFIG_EMIT) {
3696 /* Get default or commandline slapd setting */
3697 if ( ldap_syslog && !config_syslog )
3698 config_syslog = ldap_syslog;
3699 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
3701 } else if ( c->op == LDAP_MOD_DELETE ) {
3705 i = verb_to_mask( c->line, loglevel_ops );
3706 config_syslog &= ~loglevel_ops[i].mask;
3708 if ( slapMode & SLAP_SERVER_MODE ) {
3709 ldap_syslog = config_syslog;
3714 for( i=1; i < c->argc; i++ ) {
3717 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
3718 if( lutil_atoix( &level, c->argv[i], 0 ) != 0 ) {
3719 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse level", c->argv[0] );
3720 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3721 c->log, c->cr_msg, c->argv[i]);
3725 if ( str2loglevel( c->argv[i], &level ) ) {
3726 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown level", c->argv[0] );
3727 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3728 c->log, c->cr_msg, c->argv[i]);
3732 /* Explicitly setting a zero clears all the levels */
3734 config_syslog |= level;
3738 if ( slapMode & SLAP_SERVER_MODE ) {
3739 ldap_syslog = config_syslog;
3745 config_referral(ConfigArgs *c) {
3747 if (c->op == SLAP_CONFIG_EMIT) {
3748 if ( default_referral ) {
3749 value_add( &c->rvalue_vals, default_referral );
3754 } else if ( c->op == LDAP_MOD_DELETE ) {
3755 if ( c->valx < 0 ) {
3756 ber_bvarray_free( default_referral );
3757 default_referral = NULL;
3760 ch_free( default_referral[i].bv_val );
3761 for (; default_referral[i].bv_val; i++ )
3762 default_referral[i] = default_referral[i+1];
3766 if(validate_global_referral(c->argv[1])) {
3767 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3768 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3769 c->log, c->cr_msg, c->argv[1]);
3773 ber_str2bv(c->argv[1], 0, 0, &val);
3774 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
3782 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
3783 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
3784 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
3785 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
3786 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
3787 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
3788 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
3789 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
3790 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
3795 config_security(ConfigArgs *c) {
3796 slap_ssf_set_t *set = &c->be->be_ssf_set;
3799 if (c->op == SLAP_CONFIG_EMIT) {
3805 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
3806 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
3809 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
3810 if ( bv.bv_len >= sizeof( numbuf ) ) {
3811 ber_bvarray_free_x( c->rvalue_vals, NULL );
3812 c->rvalue_vals = NULL;
3816 bv.bv_len += sec_keys[i].key.bv_len;
3817 bv.bv_val = ch_malloc( bv.bv_len + 1);
3818 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
3819 strcpy( next, numbuf );
3820 ber_bvarray_add( &c->rvalue_vals, &bv );
3825 for(i = 1; i < c->argc; i++) {
3826 slap_ssf_t *tgt = NULL;
3828 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
3829 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
3830 sec_keys[j].key.bv_len)) {
3831 src = c->argv[i] + sec_keys[j].key.bv_len;
3832 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
3837 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown factor", c->argv[0] );
3838 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3839 c->log, c->cr_msg, c->argv[i]);
3843 if ( lutil_atou( tgt, src ) != 0 ) {
3844 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse factor", c->argv[0] );
3845 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3846 c->log, c->cr_msg, c->argv[i]);
3854 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
3858 for (; !BER_BVISNULL( &an->an_name ); an++) {
3859 /* if buflen == 0, assume the buffer size has been
3860 * already checked otherwise */
3861 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
3862 if ( comma ) *ptr++ = ',';
3863 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
3870 config_updatedn(ConfigArgs *c) {
3871 if (c->op == SLAP_CONFIG_EMIT) {
3872 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
3873 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
3874 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
3878 } else if ( c->op == LDAP_MOD_DELETE ) {
3879 ch_free( c->be->be_update_ndn.bv_val );
3880 BER_BVZERO( &c->be->be_update_ndn );
3881 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
3884 if(SLAP_SHADOW(c->be)) {
3885 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database already shadowed", c->argv[0] );
3886 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3887 c->log, c->cr_msg, 0);
3891 ber_memfree_x( c->value_dn.bv_val, NULL );
3892 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
3893 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
3895 c->be->be_update_ndn = c->value_ndn;
3896 BER_BVZERO( &c->value_dn );
3897 BER_BVZERO( &c->value_ndn );
3899 return config_slurp_shadow( c );
3903 config_shadow( ConfigArgs *c, slap_mask_t flag )
3905 char *notallowed = NULL;
3907 if ( c->be == frontendDB ) {
3908 notallowed = "frontend";
3910 } else if ( SLAP_MONITOR(c->be) ) {
3911 notallowed = "monitor";
3914 if ( notallowed != NULL ) {
3915 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
3919 if ( SLAP_SHADOW(c->be) ) {
3920 /* if already shadow, only check consistency */
3921 if ( ( SLAP_DBFLAGS(c->be) & flag ) != flag ) {
3922 Debug( LDAP_DEBUG_ANY, "%s: inconsistent shadow flag 0x%lx.\n",
3928 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | flag);
3929 if ( !SLAP_MULTIMASTER( c->be ))
3930 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
3937 config_updateref(ConfigArgs *c) {
3939 if (c->op == SLAP_CONFIG_EMIT) {
3940 if ( c->be->be_update_refs ) {
3941 value_add( &c->rvalue_vals, c->be->be_update_refs );
3946 } else if ( c->op == LDAP_MOD_DELETE ) {
3947 if ( c->valx < 0 ) {
3948 ber_bvarray_free( c->be->be_update_refs );
3949 c->be->be_update_refs = NULL;
3952 ch_free( c->be->be_update_refs[i].bv_val );
3953 for (; c->be->be_update_refs[i].bv_val; i++)
3954 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
3958 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
3959 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must appear after syncrepl or updatedn",
3961 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3962 c->log, c->cr_msg, 0);
3966 if(validate_global_referral(c->argv[1])) {
3967 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3968 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3969 c->log, c->cr_msg, c->argv[1]);
3972 ber_str2bv(c->argv[1], 0, 0, &val);
3973 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
3978 config_obsolete(ConfigArgs *c) {
3979 if (c->op == SLAP_CONFIG_EMIT)
3982 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> keyword is obsolete (ignored)",
3984 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0);
3989 config_include(ConfigArgs *c) {
3990 int savelineno = c->lineno;
3993 ConfigFile *cfsave = cfn;
3994 ConfigFile *cf2 = NULL;
3996 /* Leftover from RE23. No dynamic config for include files */
3997 if ( c->op == SLAP_CONFIG_EMIT || c->op == LDAP_MOD_DELETE )
4000 cf = ch_calloc( 1, sizeof(ConfigFile));
4001 if ( cfn->c_kids ) {
4002 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
4008 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
4009 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
4010 c->lineno = savelineno - 1;
4013 if ( cf2 ) cf2->c_sibs = NULL;
4014 else cfn->c_kids = NULL;
4015 ch_free( cf->c_file.bv_val );
4025 config_tls_cleanup(ConfigArgs *c) {
4028 if ( slap_tls_ld ) {
4031 ldap_pvt_tls_ctx_free( slap_tls_ctx );
4032 slap_tls_ctx = NULL;
4034 /* Force new ctx to be created */
4035 rc = ldap_pvt_tls_set_option( slap_tls_ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
4037 /* The ctx's refcount is bumped up here */
4038 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CTX, &slap_tls_ctx );
4039 /* This is a no-op if it's already loaded */
4040 load_extop( &slap_EXOP_START_TLS, 0, starttls_extop );
4042 if ( rc == LDAP_NOT_SUPPORTED )
4043 rc = LDAP_UNWILLING_TO_PERFORM;
4052 config_tls_option(ConfigArgs *c) {
4054 LDAP *ld = slap_tls_ld;
4056 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
4057 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
4058 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
4059 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
4060 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
4061 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
4062 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
4064 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
4066 default: Debug(LDAP_DEBUG_ANY, "%s: "
4067 "unknown tls_option <0x%x>\n",
4068 c->log, c->type, 0);
4071 if (c->op == SLAP_CONFIG_EMIT) {
4072 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
4073 } else if ( c->op == LDAP_MOD_DELETE ) {
4074 c->cleanup = config_tls_cleanup;
4075 return ldap_pvt_tls_set_option( ld, flag, NULL );
4077 ch_free(c->value_string);
4078 c->cleanup = config_tls_cleanup;
4079 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
4082 /* FIXME: this ought to be provided by libldap */
4084 config_tls_config(ConfigArgs *c) {
4087 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
4088 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
4089 case CFG_TLS_PROTOCOL_MIN: flag = LDAP_OPT_X_TLS_PROTOCOL_MIN; break;
4091 Debug(LDAP_DEBUG_ANY, "%s: "
4092 "unknown tls_option <0x%x>\n",
4093 c->log, c->type, 0);
4096 if (c->op == SLAP_CONFIG_EMIT) {
4097 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
4098 } else if ( c->op == LDAP_MOD_DELETE ) {
4100 c->cleanup = config_tls_cleanup;
4101 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
4103 ch_free( c->value_string );
4104 c->cleanup = config_tls_cleanup;
4105 if ( isdigit( (unsigned char)c->argv[1][0] ) && c->type != CFG_TLS_PROTOCOL_MIN ) {
4106 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
4107 Debug(LDAP_DEBUG_ANY, "%s: "
4108 "unable to parse %s \"%s\"\n",
4109 c->log, c->argv[0], c->argv[1] );
4112 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
4114 return(ldap_pvt_tls_config(slap_tls_ld, flag, c->argv[1]));
4119 static CfEntryInfo *
4120 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
4130 if ( dn_match( &root->ce_entry->e_nname, dn ))
4133 c = dn->bv_val+dn->bv_len;
4134 for (;*c != ',';c--);
4138 for (--c;c>dn->bv_val && *c != ',';c--);
4142 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
4144 root = root->ce_kids;
4146 for (;root;root=root->ce_sibs) {
4147 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
4148 if ( cdn.bv_val == dn->bv_val ) {
4158 typedef struct setup_cookie {
4168 config_ldif_resp( Operation *op, SlapReply *rs )
4170 if ( rs->sr_type == REP_SEARCH ) {
4171 setup_cookie *sc = op->o_callback->sc_private;
4174 sc->cfb->cb_got_ldif = 1;
4175 /* Does the frontend exist? */
4176 if ( !sc->got_frontend ) {
4177 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
4178 "olcDatabase", STRLENOF( "olcDatabase" )))
4180 if ( strncmp( rs->sr_entry->e_nname.bv_val +
4181 STRLENOF( "olcDatabase" ), "={-1}frontend",
4182 STRLENOF( "={-1}frontend" )))
4186 sc->ca->be = frontendDB;
4187 sc->ca->bi = frontendDB->bd_info;
4188 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
4189 rdn.bv_val = sc->ca->log;
4190 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
4191 "%s=" SLAP_X_ORDERED_FMT "%s",
4192 cfAd_database->ad_cname.bv_val, -1,
4193 sc->ca->bi->bi_type);
4195 sc->frontend = config_build_entry( op, rs,
4196 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
4197 sc->ca->be->be_cf_ocs );
4207 dnParent( &rs->sr_entry->e_nname, &pdn );
4209 /* Does the configDB exist? */
4210 if ( sc->got_frontend && !sc->got_config &&
4211 !strncmp( rs->sr_entry->e_nname.bv_val,
4212 "olcDatabase", STRLENOF( "olcDatabase" )) &&
4213 dn_match( &config_rdn, &pdn ) )
4215 if ( strncmp( rs->sr_entry->e_nname.bv_val +
4216 STRLENOF( "olcDatabase" ), "={0}config",
4217 STRLENOF( "={0}config" )))
4221 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
4222 sc->ca->bi = sc->ca->be->bd_info;
4223 rdn.bv_val = sc->ca->log;
4224 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
4225 "%s=" SLAP_X_ORDERED_FMT "%s",
4226 cfAd_database->ad_cname.bv_val, 0,
4227 sc->ca->bi->bi_type);
4229 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
4230 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
4237 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
4238 if ( rs->sr_err != LDAP_SUCCESS ) {
4239 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
4240 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg, 0 );
4246 /* Configure and read the underlying back-ldif store */
4248 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
4249 CfBackInfo *cfb = be->be_private;
4255 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
4256 Connection conn = {0};
4257 OperationBuffer opbuf;
4259 SlapReply rs = {REP_RESULT};
4260 Filter filter = { LDAP_FILTER_PRESENT };
4261 struct berval filterstr = BER_BVC("(objectclass=*)");
4264 /* Is the config directory available? */
4265 if ( stat( dir, &st ) < 0 ) {
4266 /* No, so don't bother using the backing store.
4267 * All changes will be in-memory only.
4272 cfb->cb_db.bd_info = backend_info( "ldif" );
4273 if ( !cfb->cb_db.bd_info )
4274 return 0; /* FIXME: eventually this will be a fatal error */
4276 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
4279 cfb->cb_db.be_suffix = be->be_suffix;
4280 cfb->cb_db.be_nsuffix = be->be_nsuffix;
4282 /* The suffix is always "cn=config". The underlying DB's rootdn
4283 * is always the same as the suffix.
4285 cfb->cb_db.be_rootdn = be->be_suffix[0];
4286 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
4288 ber_str2bv( dir, 0, 1, &cfdir );
4293 argv[0] = "directory";
4294 argv[1] = (char *)dir;
4299 c.table = Cft_Database;
4301 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
4305 if ( config_add_vals( ct, &c ))
4308 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
4312 void *thrctx = ldap_pvt_thread_pool_context();
4315 connection_fake_init( &conn, &opbuf, thrctx );
4318 filter.f_desc = slap_schema.si_ad_objectClass;
4320 op->o_tag = LDAP_REQ_SEARCH;
4322 op->ors_filter = &filter;
4323 op->ors_filterstr = filterstr;
4324 op->ors_scope = LDAP_SCOPE_SUBTREE;
4326 op->o_dn = c.be->be_rootdn;
4327 op->o_ndn = c.be->be_rootndn;
4329 op->o_req_dn = be->be_suffix[0];
4330 op->o_req_ndn = be->be_nsuffix[0];
4332 op->ors_tlimit = SLAP_NO_LIMIT;
4333 op->ors_slimit = SLAP_NO_LIMIT;
4335 op->ors_attrs = slap_anlist_all_attributes;
4336 op->ors_attrsonly = 0;
4338 op->o_callback = &cb;
4341 cb.sc_private = ≻
4342 sc.got_frontend = 0;
4347 op->o_bd = &cfb->cb_db;
4349 /* Allow unknown attrs in DNs */
4350 prev_DN_strict = slap_DN_strict;
4353 rc = op->o_bd->be_search( op, &rs );
4355 /* Restore normal DN validation */
4356 slap_DN_strict = prev_DN_strict;
4358 op->o_tag = LDAP_REQ_ADD;
4359 if ( rc == LDAP_SUCCESS && sc.frontend ) {
4360 rs_reinit( &rs, REP_RESULT );
4361 op->ora_e = sc.frontend;
4362 rc = op->o_bd->be_add( op, &rs );
4364 if ( rc == LDAP_SUCCESS && sc.config ) {
4365 rs_reinit( &rs, REP_RESULT );
4366 op->ora_e = sc.config;
4367 rc = op->o_bd->be_add( op, &rs );
4369 ldap_pvt_thread_pool_context_reset( thrctx );
4372 /* ITS#4194 - only use if it's present, or we're converting. */
4373 if ( !readit || rc == LDAP_SUCCESS )
4374 cfb->cb_use_ldif = 1;
4380 CfOc_cmp( const void *c1, const void *c2 ) {
4381 const ConfigOCs *co1 = c1;
4382 const ConfigOCs *co2 = c2;
4384 return ber_bvcmp( co1->co_name, co2->co_name );
4388 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
4391 i = init_config_attrs( ct );
4394 /* set up the objectclasses */
4395 i = init_config_ocs( ocs );
4398 for (i=0; ocs[i].co_def; i++) {
4399 if ( ocs[i].co_oc ) {
4400 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
4401 if ( !ocs[i].co_table )
4402 ocs[i].co_table = ct;
4403 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
4410 read_config(const char *fname, const char *dir) {
4413 const char *cfdir, *cfname;
4416 /* Setup the config backend */
4417 be = backend_db_init( "config", NULL, 0, NULL );
4421 cfb = be->be_private;
4422 be->be_dfltaccess = ACL_NONE;
4424 /* If no .conf, or a dir was specified, setup the dir */
4425 if ( !fname || dir ) {
4427 /* If explicitly given, check for existence */
4430 if ( stat( dir, &st ) < 0 ) {
4431 Debug( LDAP_DEBUG_ANY,
4432 "invalid config directory %s, error %d\n",
4438 cfdir = SLAPD_DEFAULT_CONFIGDIR;
4440 /* if fname is defaulted, try reading .d */
4441 rc = config_setup_ldif( be, cfdir, !fname );
4444 /* It may be OK if the base object doesn't exist yet. */
4445 if ( rc != LDAP_NO_SUCH_OBJECT )
4447 /* ITS#4194: But if dir was specified and no fname,
4448 * then we were supposed to read the dir. Unless we're
4449 * trying to slapadd the dir...
4451 if ( dir && !fname ) {
4452 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
4454 /* Assume it's slapadd with a config dir, let it continue */
4456 cfb->cb_got_ldif = 1;
4457 cfb->cb_use_ldif = 1;
4462 /* If we read the config from back-ldif, nothing to do here */
4463 if ( cfb->cb_got_ldif ) {
4472 cfname = SLAPD_DEFAULT_CONFIGFILE;
4474 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
4477 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
4480 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
4481 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
4482 &frontendDB->be_schemadn );
4483 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
4484 if ( rc != LDAP_SUCCESS ) {
4485 Debug(LDAP_DEBUG_ANY, "read_config: "
4486 "unable to normalize default schema DN \"%s\"\n",
4487 frontendDB->be_schemadn.bv_val, 0, 0 );
4488 /* must not happen */
4492 if ( rc == 0 && ( slapMode & SLAP_SERVER_MODE ) && sid_list ) {
4493 if ( !BER_BVISEMPTY( &sid_list->si_url ) && !sid_set ) {
4494 Debug(LDAP_DEBUG_ANY, "read_config: no serverID / URL match found. "
4495 "Check slapd -h arguments.\n", 0,0,0 );
4503 config_back_bind( Operation *op, SlapReply *rs )
4505 if ( be_isroot_pw( op ) ) {
4506 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
4507 /* frontend sends result */
4508 return LDAP_SUCCESS;
4511 rs->sr_err = LDAP_INVALID_CREDENTIALS;
4512 send_ldap_result( op, rs );
4518 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
4522 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
4524 rs->sr_attrs = op->ors_attrs;
4525 rs->sr_entry = ce->ce_entry;
4527 rc = send_search_entry( op, rs );
4528 if ( rc != LDAP_SUCCESS ) {
4532 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
4533 if ( ce->ce_kids ) {
4534 rc = config_send( op, rs, ce->ce_kids, 1 );
4535 if ( rc ) return rc;
4538 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
4539 rc = config_send( op, rs, ce, 0 );
4547 static ConfigTable *
4548 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
4553 for (j=0; j<nocs; j++) {
4554 for (i=0; colst[j]->co_table[i].name; i++)
4555 if ( colst[j]->co_table[i].ad == ad ) {
4556 ca->table = colst[j]->co_type;
4557 return &colst[j]->co_table[i];
4563 /* Sort the attributes of the entry according to the order defined
4564 * in the objectclass, with required attributes occurring before
4565 * allowed attributes. For any attributes with sequencing dependencies
4566 * (e.g., rootDN must be defined after suffix) the objectclass must
4567 * list the attributes in the desired sequence.
4570 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
4572 Attribute *a, *head = NULL, *tail = NULL, **prev;
4575 for (i=0; i<nocs; i++) {
4576 if ( colst[i]->co_oc->soc_required ) {
4577 AttributeType **at = colst[i]->co_oc->soc_required;
4578 for (j=0; at[j]; j++) {
4579 for (a=e->e_attrs, prev=&e->e_attrs; a;
4580 prev = &(*prev)->a_next, a=a->a_next) {
4581 if ( a->a_desc == at[j]->sat_ad ) {
4595 if ( colst[i]->co_oc->soc_allowed ) {
4596 AttributeType **at = colst[i]->co_oc->soc_allowed;
4597 for (j=0; at[j]; j++) {
4598 for (a=e->e_attrs, prev=&e->e_attrs; a;
4599 prev = &(*prev)->a_next, a=a->a_next) {
4600 if ( a->a_desc == at[j]->sat_ad ) {
4616 tail->a_next = e->e_attrs;
4622 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
4624 Attribute *a = NULL;
4625 AttributeDescription *ad;
4635 Modifications *ml = ptr;
4637 vals = ml->sml_values;
4640 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
4641 rc = ordered_value_sort( a, 1 );
4643 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
4644 ad->ad_cname.bv_val );
4648 for ( i=0; vals[i].bv_val; i++ ) {
4649 ca->line = vals[i].bv_val;
4650 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
4651 ca->line[0] == '{' ) {
4652 char *idx = strchr( ca->line, '}' );
4653 if ( idx ) ca->line = idx+1;
4655 rc = config_parse_vals( ct, ca, i );
4664 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
4667 struct berval rtype, rval;
4669 AttributeDescription *ad = NULL;
4671 dnRdn( &e->e_name, rdn );
4672 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
4673 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
4674 rtype.bv_val = rdn->bv_val;
4675 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
4678 slap_bv2ad( &rtype, &ad, &rs->sr_text );
4679 a = attr_find( e->e_attrs, ad );
4680 if (!a ) return LDAP_NAMING_VIOLATION;
4687 config_rename_kids( CfEntryInfo *ce )
4690 struct berval rdn, nrdn;
4692 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
4693 struct berval newdn, newndn;
4694 dnRdn ( &ce2->ce_entry->e_name, &rdn );
4695 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
4696 build_new_dn( &newdn, &ce->ce_entry->e_name, &rdn, NULL );
4697 build_new_dn( &newndn, &ce->ce_entry->e_nname, &nrdn, NULL );
4698 free( ce2->ce_entry->e_name.bv_val );
4699 free( ce2->ce_entry->e_nname.bv_val );
4700 ce2->ce_entry->e_name = newdn;
4701 ce2->ce_entry->e_nname = newndn;
4702 config_rename_kids( ce2 );
4707 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
4708 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
4709 struct berval *nnewrdn, int use_ldif )
4713 struct berval odn, ondn;
4717 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
4718 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
4721 free( a->a_vals[0].bv_val );
4722 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
4723 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
4724 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
4725 strcpy( a->a_vals[0].bv_val, ptr1 );
4727 if ( a->a_nvals != a->a_vals ) {
4728 free( a->a_nvals[0].bv_val );
4729 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
4730 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
4731 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
4732 strcpy( a->a_nvals[0].bv_val, ptr1 );
4735 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
4736 BackendDB *be = op->o_bd;
4737 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4738 struct berval dn, ndn, xdn, xndn;
4740 op->o_bd = &cfb->cb_db;
4742 /* Save current rootdn; use the underlying DB's rootdn */
4746 xndn = op->o_req_ndn;
4747 op->o_dn = op->o_bd->be_rootdn;
4748 op->o_ndn = op->o_bd->be_rootndn;
4750 op->o_req_ndn = ondn;
4752 scp = op->o_callback;
4753 op->o_callback = ≻
4754 op->orr_newrdn = *newrdn;
4755 op->orr_nnewrdn = *nnewrdn;
4756 op->orr_newSup = NULL;
4757 op->orr_nnewSup = NULL;
4758 op->orr_deleteoldrdn = 1;
4759 op->orr_modlist = NULL;
4760 slap_modrdn2mods( op, rs );
4761 slap_mods_opattrs( op, &op->orr_modlist, 1 );
4762 rc = op->o_bd->be_modrdn( op, rs );
4763 slap_mods_free( op->orr_modlist, 1 );
4766 op->o_callback = scp;
4770 op->o_req_ndn = xndn;
4773 free( ondn.bv_val );
4775 config_rename_kids( e->e_private );
4780 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
4781 Entry *e, int idx, int tailindex, int use_ldif )
4783 struct berval ival, newrdn, nnewrdn;
4786 char ibuf[32], *ptr1, *ptr2 = NULL;
4789 rc = config_rename_attr( rs, e, &rdn, &a );
4790 if ( rc ) return rc;
4793 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
4794 if ( ival.bv_len >= sizeof( ibuf ) ) {
4795 return LDAP_NAMING_VIOLATION;
4798 newrdn.bv_len = rdn.bv_len + ival.bv_len;
4799 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
4802 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
4803 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4806 ptr2 = ber_bvchr( &rdn, '}' );
4810 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
4812 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
4813 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
4814 a->a_desc->ad_cname.bv_len );
4816 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4817 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
4821 /* Do the equivalent of ModRDN */
4822 /* Replace DN / NDN */
4823 newrdn.bv_len = ptr1 - newrdn.bv_val;
4824 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
4825 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
4827 free( nnewrdn.bv_val );
4828 free( newrdn.bv_val );
4833 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
4834 SlapReply *rs, int *renum, int *ibase )
4837 int index = -1, gotindex = 0, nsibs, rc = 0;
4838 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
4839 char *ptr1, *ptr2 = NULL;
4842 if ( renum ) *renum = 0;
4844 /* These entries don't get indexed/renumbered */
4845 if ( ce_type == Cft_Global ) return 0;
4846 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
4848 if ( ce_type == Cft_Module )
4851 /* See if the rdn has an index already */
4852 dnRdn( &e->e_name, &rdn );
4853 if ( ce_type == Cft_Database ) {
4854 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
4855 "frontend", STRLENOF("frontend") ))
4857 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
4858 "config", STRLENOF("config") ))
4861 ptr1 = ber_bvchr( &e->e_name, '{' );
4862 if ( ptr1 && ptr1 < &e->e_name.bv_val[ rdn.bv_len ] ) {
4864 ptr2 = strchr( ptr1, '}' );
4865 if ( !ptr2 || ptr2 > &e->e_name.bv_val[ rdn.bv_len ] )
4866 return LDAP_NAMING_VIOLATION;
4867 if ( ptr2-ptr1 == 1)
4868 return LDAP_NAMING_VIOLATION;
4870 index = strtol( ptr1 + 1, &next, 10 );
4871 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
4872 return LDAP_NAMING_VIOLATION;
4875 /* Special case, we allow -1 for the frontendDB */
4876 if ( index != -1 || !isfrontend )
4877 return LDAP_NAMING_VIOLATION;
4879 if ( isconfig && index != 0 ){
4880 return LDAP_NAMING_VIOLATION;
4884 /* count related kids.
4885 * For entries of type Cft_Misc, only count siblings with same RDN type
4887 if ( ce_type == Cft_Misc ) {
4888 rdn.bv_val = e->e_nname.bv_val;
4889 ptr1 = strchr( rdn.bv_val, '=' );
4890 assert( ptr1 != NULL );
4892 rdn.bv_len = ptr1 - rdn.bv_val;
4894 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
4896 if ( ce->ce_type != ce_type )
4899 dnRdn( &ce->ce_entry->e_nname, &rdn2 );
4901 ptr1 = strchr( rdn2.bv_val, '=' );
4902 assert( ptr1 != NULL );
4904 rdn2.bv_len = ptr1 - rdn2.bv_val;
4905 if ( bvmatch( &rdn, &rdn2 ))
4909 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
4910 if ( ce->ce_type == ce_type ) nsibs++;
4914 /* account for -1 frontend */
4915 if ( ce_type == Cft_Database )
4918 if ( index != nsibs ) {
4920 if ( index < nsibs ) {
4921 if ( tailindex ) return LDAP_NAMING_VIOLATION;
4922 /* Siblings need to be renumbered */
4923 if ( index != -1 || !isfrontend )
4927 /* config DB is always "0" */
4928 if ( isconfig && index == -1 ) {
4931 if (( !isfrontend && index == -1 ) || ( index > nsibs ) ){
4935 /* just make index = nsibs */
4937 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
4940 if ( ibase ) *ibase = index;
4941 if ( renum ) *renum = renumber;
4945 /* Insert all superior classes of the given class */
4947 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
4952 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
4953 if ( count_oc( *sups, copp, nocs ) ) {
4958 co.co_name = &oc->soc_cname;
4959 cop = avl_find( CfOcTree, &co, CfOc_cmp );
4963 /* check for duplicates */
4964 for ( i = 0; i < *nocs; i++ ) {
4965 if ( *copp && (*copp)[i] == cop ) {
4971 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
4972 if ( tmp == NULL ) {
4976 (*copp)[*nocs] = cop;
4984 /* Find all superior classes of the given objectclasses,
4985 * return list in order of most-subordinate first.
4987 * Special / auxiliary / Cft_Misc classes always take precedence.
4990 count_ocs( Attribute *oc_at, int *nocs )
4992 int i, j, misc = -1;
4993 ConfigOCs **colst = NULL;
4997 for ( i = oc_at->a_numvals; i--; ) {
4998 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
5000 assert( oc != NULL );
5001 if ( count_oc( oc, &colst, nocs ) ) {
5011 ConfigOCs *tmp = colst[i];
5012 colst[i] = colst[j];
5014 if (tmp->co_type == Cft_Misc)
5018 /* Move misc class to front of list */
5020 ConfigOCs *tmp = colst[misc];
5021 for (i=misc; i>0; i--)
5022 colst[i] = colst[i-1];
5030 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
5032 /* Leftover from RE23. Never parse this entry */
5033 return LDAP_COMPARE_TRUE;
5037 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
5041 /* This entry is hardcoded, don't re-parse it */
5042 if ( p->ce_type == Cft_Global ) {
5043 cfn = p->ce_private;
5044 ca->ca_private = cfn;
5045 return LDAP_COMPARE_TRUE;
5047 if ( p->ce_type != Cft_Schema )
5048 return LDAP_CONSTRAINT_VIOLATION;
5050 cfn = ch_calloc( 1, sizeof(ConfigFile) );
5051 ca->ca_private = cfn;
5052 cfo = p->ce_private;
5053 cfn->c_sibs = cfo->c_kids;
5055 return LDAP_SUCCESS;
5059 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
5061 if ( p->ce_type != Cft_Global ) {
5062 return LDAP_CONSTRAINT_VIOLATION;
5064 /* config must be {0}, nothing else allowed */
5065 if ( !strncmp( e->e_nname.bv_val, "olcDatabase={0}", STRLENOF("olcDatabase={0}")) &&
5066 strncmp( e->e_nname.bv_val + STRLENOF("olcDatabase={0}"), "config,", STRLENOF("config,") )) {
5067 return LDAP_CONSTRAINT_VIOLATION;
5069 ca->be = frontendDB; /* just to get past check_vals */
5070 return LDAP_SUCCESS;
5074 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
5076 if ( p->ce_type != Cft_Global ) {
5077 return LDAP_CONSTRAINT_VIOLATION;
5079 return LDAP_SUCCESS;
5083 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
5085 if ( p->ce_type != Cft_Global ) {
5086 return LDAP_CONSTRAINT_VIOLATION;
5088 return LDAP_SUCCESS;
5092 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
5094 if ( p->ce_type != Cft_Database ) {
5095 return LDAP_CONSTRAINT_VIOLATION;
5098 return LDAP_SUCCESS;
5102 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
5107 AttributeDescription *ad;
5113 if ( cfn->c_cr_head ) {
5114 struct berval bv = BER_BVC("olcDitContentRules");
5116 slap_bv2ad( &bv, &ad, &text );
5117 ct = config_find_table( colst, nocs, ad, ca );
5118 config_del_vals( ct, ca );
5120 if ( cfn->c_oc_head ) {
5121 struct berval bv = BER_BVC("olcObjectClasses");
5123 slap_bv2ad( &bv, &ad, &text );
5124 ct = config_find_table( colst, nocs, ad, ca );
5125 config_del_vals( ct, ca );
5127 if ( cfn->c_at_head ) {
5128 struct berval bv = BER_BVC("olcAttributeTypes");
5130 slap_bv2ad( &bv, &ad, &text );
5131 ct = config_find_table( colst, nocs, ad, ca );
5132 config_del_vals( ct, ca );
5134 if ( cfn->c_syn_head ) {
5135 struct berval bv = BER_BVC("olcLdapSyntaxes");
5137 slap_bv2ad( &bv, &ad, &text );
5138 ct = config_find_table( colst, nocs, ad, ca );
5139 config_del_vals( ct, ca );
5141 if ( cfn->c_om_head ) {
5142 struct berval bv = BER_BVC("olcObjectIdentifier");
5144 slap_bv2ad( &bv, &ad, &text );
5145 ct = config_find_table( colst, nocs, ad, ca );
5146 config_del_vals( ct, ca );
5148 cfo = p->ce_private;
5149 cfo->c_kids = cfn->c_sibs;
5154 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
5156 int rc = LDAP_CONSTRAINT_VIOLATION;
5159 if ( (*cop)->co_ldadd ) {
5160 rc = (*cop)->co_ldadd( last, e, ca );
5161 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
5166 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
5167 ConfigOCs co = { 0 };
5169 co.co_name = &(*ocp)->soc_cname;
5170 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
5171 if ( *cop == NULL ) {
5175 rc = config_add_oc( cop, last, e, ca );
5176 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
5184 /* Parse an LDAP entry into config directives */
5186 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
5187 int *renum, Operation *op )
5189 CfEntryInfo *ce, *last = NULL;
5190 ConfigOCs co, *coptr, **colst;
5191 Attribute *a, *oc_at, *soc_at;
5192 int i, ibase = -1, nocs, rc = 0;
5195 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
5197 memset( ca, 0, sizeof(ConfigArgs));
5199 /* Make sure parent exists and entry does not. But allow
5200 * Databases and Overlays to be inserted. Don't do any
5201 * auto-renumbering if manageDSAit control is present.
5203 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
5205 if ( ( op && op->o_managedsait ) ||
5206 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
5207 ce->ce_type != Cft_Module ) )
5209 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5210 "DN=\"%s\" already exists\n",
5211 log_prefix, e->e_name.bv_val, 0 );
5212 /* global schema ignores all writes */
5213 if ( ce->ce_type == Cft_Schema && ce->ce_parent->ce_type == Cft_Global )
5214 return LDAP_COMPARE_TRUE;
5215 return LDAP_ALREADY_EXISTS;
5219 dnParent( &e->e_nname, &pdn );
5221 /* If last is NULL, the new entry is the root/suffix entry,
5222 * otherwise last should be the parent.
5224 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
5226 rs->sr_matched = last->ce_entry->e_name.bv_val;
5228 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5229 "DN=\"%s\" not child of DN=\"%s\"\n",
5230 log_prefix, e->e_name.bv_val,
5231 last->ce_entry->e_name.bv_val );
5232 return LDAP_NO_SUCH_OBJECT;
5236 /* No parent, must be root. This will never happen... */
5237 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
5238 return LDAP_NO_SUCH_OBJECT;
5241 if ( last && !access_allowed( op, last->ce_entry,
5242 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
5244 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5245 "DN=\"%s\" no write access to \"children\" of parent\n",
5246 log_prefix, e->e_name.bv_val, 0 );
5247 return LDAP_INSUFFICIENT_ACCESS;
5251 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5253 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5254 "DN=\"%s\" no objectClass\n",
5255 log_prefix, e->e_name.bv_val, 0 );
5256 return LDAP_OBJECT_CLASS_VIOLATION;
5259 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
5261 ObjectClass *soc = NULL;
5262 char textbuf[ SLAP_TEXT_BUFLEN ];
5263 const char *text = textbuf;
5265 /* FIXME: check result */
5266 rc = structural_class( oc_at->a_nvals, &soc, NULL,
5267 &text, textbuf, sizeof(textbuf), NULL );
5268 if ( rc != LDAP_SUCCESS ) {
5269 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5270 "DN=\"%s\" no structural objectClass (%s)\n",
5271 log_prefix, e->e_name.bv_val, text );
5274 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
5275 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
5276 if ( soc_at == NULL ) {
5277 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5278 "DN=\"%s\" no structural objectClass; "
5279 "unable to merge computed class %s\n",
5280 log_prefix, e->e_name.bv_val,
5281 soc->soc_cname.bv_val );
5282 return LDAP_OBJECT_CLASS_VIOLATION;
5285 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5286 "DN=\"%s\" no structural objectClass; "
5287 "computed objectClass %s merged\n",
5288 log_prefix, e->e_name.bv_val,
5289 soc->soc_cname.bv_val );
5292 /* Fake the coordinates based on whether we're part of an
5293 * LDAP Add or if reading the config dir
5296 ca->fname = "slapd";
5299 ca->fname = cfdir.bv_val;
5304 co.co_name = &soc_at->a_nvals[0];
5305 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
5306 if ( coptr == NULL ) {
5307 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5308 "DN=\"%s\" no structural objectClass in configuration table\n",
5309 log_prefix, e->e_name.bv_val, 0 );
5310 return LDAP_OBJECT_CLASS_VIOLATION;
5313 /* Only the root can be Cft_Global, everything else must
5314 * have a parent. Only limited nesting arrangements are allowed.
5316 rc = LDAP_CONSTRAINT_VIOLATION;
5317 if ( coptr->co_type == Cft_Global && !last ) {
5318 cfn = cfb->cb_config;
5319 ca->ca_private = cfn;
5320 ca->be = frontendDB; /* just to get past check_vals */
5324 colst = count_ocs( oc_at, &nocs );
5326 /* Check whether the Add is allowed by its parent, and do
5327 * any necessary arg setup
5330 rc = config_add_oc( &coptr, last, e, ca );
5331 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
5332 for ( i = 0; i<nocs; i++ ) {
5333 /* Already checked these */
5334 if ( colst[i]->co_oc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
5336 if ( colst[i]->co_ldadd &&
5337 ( rc = colst[i]->co_ldadd( last, e, ca ))
5338 != LDAP_CONSTRAINT_VIOLATION ) {
5344 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
5345 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5346 "DN=\"%s\" no structural objectClass add function\n",
5347 log_prefix, e->e_name.bv_val, 0 );
5348 return LDAP_OBJECT_CLASS_VIOLATION;
5352 /* Add the entry but don't parse it, we already have its contents */
5353 if ( rc == LDAP_COMPARE_TRUE ) {
5358 if ( rc != LDAP_SUCCESS )
5361 /* Parse all the values and check for simple syntax errors before
5362 * performing any set actions.
5364 * If doing an LDAPadd, check for indexed names and any necessary
5365 * renaming/renumbering. Entries that don't need indexed names are
5366 * ignored. Entries that need an indexed name and arrive without one
5367 * are assigned to the end. Entries that arrive with an index may
5368 * cause the following entries to be renumbered/bumped down.
5370 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
5371 * don't allow Adding an entry with an index that's already in use.
5372 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
5374 * These entries can have auto-assigned indexes (appended to the end)
5375 * but only the other types support auto-renumbering of siblings.
5378 rc = check_name_index( last, coptr->co_type, e, rs, renum,
5383 if ( renum && *renum && coptr->co_type != Cft_Database &&
5384 coptr->co_type != Cft_Overlay )
5386 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
5387 "operation requires sibling renumbering" );
5388 rc = LDAP_UNWILLING_TO_PERFORM;
5393 init_config_argv( ca );
5395 /* Make sure we process attrs in the required order */
5396 sort_attrs( e, colst, nocs );
5398 for ( a = e->e_attrs; a; a = a->a_next ) {
5399 if ( a == oc_at ) continue;
5400 ct = config_find_table( colst, nocs, a->a_desc, ca );
5401 if ( !ct ) continue; /* user data? */
5402 rc = check_vals( ct, ca, a, 1 );
5403 if ( rc ) goto done_noop;
5406 /* Basic syntax checks are OK. Do the actual settings. */
5407 for ( a=e->e_attrs; a; a=a->a_next ) {
5408 if ( a == oc_at ) continue;
5409 ct = config_find_table( colst, nocs, a->a_desc, ca );
5410 if ( !ct ) continue; /* user data? */
5411 for (i=0; a->a_vals[i].bv_val; i++) {
5414 ca->line = a->a_vals[i].bv_val;
5415 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
5416 ptr = strchr( ca->line, '}' );
5418 iptr = strchr( ca->line, '{' );
5422 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
5424 ca->valx = strtol( iptr+1, NULL, 0 );
5429 rc = config_parse_add( ct, ca, i );
5437 /* Newly added databases and overlays need to be started up */
5438 if ( CONFIG_ONLINE_ADD( ca )) {
5439 if ( coptr->co_type == Cft_Database ) {
5440 rc = backend_startup_one( ca->be, &ca->reply );
5442 } else if ( coptr->co_type == Cft_Overlay ) {
5443 if ( ca->bi->bi_db_open ) {
5444 BackendInfo *bi_orig = ca->be->bd_info;
5445 ca->be->bd_info = ca->bi;
5446 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
5447 ca->be->bd_info = bi_orig;
5449 } else if ( ca->cleanup ) {
5450 rc = ca->cleanup( ca );
5453 if (ca->cr_msg[0] == '\0')
5454 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
5456 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
5457 ca->log, ca->cr_msg, ca->argv[1] );
5464 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5465 ce->ce_parent = last;
5466 ce->ce_entry = entry_dup( e );
5467 ce->ce_entry->e_private = ce;
5468 ce->ce_type = coptr->co_type;
5471 ce->ce_private = ca->ca_private;
5472 ca->ca_entry = ce->ce_entry;
5475 } else if ( last->ce_kids ) {
5476 CfEntryInfo *c2, **cprev;
5478 /* Advance to first of this type */
5479 cprev = &last->ce_kids;
5480 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
5481 cprev = &c2->ce_sibs;
5484 /* Account for the (-1) frontendDB entry */
5485 if ( ce->ce_type == Cft_Database ) {
5486 if ( ca->be == frontendDB )
5488 else if ( ibase != -1 )
5493 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
5494 cprev = &c2->ce_sibs;
5500 for ( i=0; i<ibase; i++ ) {
5502 cprev = &c2->ce_sibs;
5505 ce->ce_sibs = *cprev;
5513 if ( (coptr->co_type == Cft_Database) && ca->be ) {
5514 if ( ca->be != frontendDB )
5515 backend_destroy_one( ca->be, 1 );
5516 } else if ( (coptr->co_type == Cft_Overlay) && ca->bi ) {
5517 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
5518 } else if ( coptr->co_type == Cft_Schema ) {
5519 schema_destroy_one( ca, colst, nocs, last );
5524 ch_free( ca->argv );
5525 if ( colst ) ch_free( colst );
5529 #define BIGTMP 10000
5531 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5532 int base, int rebase, int max, int use_ldif )
5534 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
5535 ConfigType etype = ce->ce_type;
5536 int count = 0, rc = 0;
5538 /* Reverse ce list */
5539 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
5540 if (ce2->ce_type != etype) {
5545 ce2->ce_sibs = cetmp;
5548 if ( max && count >= max ) {
5554 /* Move original to a temp name until increments are done */
5556 ce->ce_entry->e_private = NULL;
5557 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5558 base+BIGTMP, 0, use_ldif );
5559 ce->ce_entry->e_private = ce;
5561 /* start incrementing */
5562 for (ce2=cetmp; ce2; ce2=ce3) {
5564 ce2->ce_sibs = cerem;
5567 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5568 count+base, 0, use_ldif );
5572 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5573 base, 0, use_ldif );
5578 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5579 CfEntryInfo *ce2, int old, int use_ldif )
5583 /* Renumber original to a temp value */
5584 ce->ce_entry->e_private = NULL;
5585 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5586 old+BIGTMP, 0, use_ldif );
5587 ce->ce_entry->e_private = ce;
5589 /* start decrementing */
5590 for (; ce2 != ce; ce2=ce2->ce_sibs) {
5591 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5592 count+old, 0, use_ldif );
5595 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5596 count+old, 0, use_ldif );
5599 /* Parse an LDAP entry into config directives, then store in underlying
5603 config_back_add( Operation *op, SlapReply *rs )
5609 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
5610 NULL, ACL_WADD, NULL )) {
5611 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5616 * Check for attribute ACL
5618 if ( !acl_check_modlist( op, op->ora_e, op->orm_modlist )) {
5619 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5620 rs->sr_text = "no write access to attribute";
5624 cfb = (CfBackInfo *)op->o_bd->be_private;
5626 /* add opattrs for syncprov */
5628 char textbuf[SLAP_TEXT_BUFLEN];
5629 size_t textlen = sizeof textbuf;
5630 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1, NULL,
5631 &rs->sr_text, textbuf, sizeof( textbuf ) );
5632 if ( rs->sr_err != LDAP_SUCCESS )
5634 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
5635 if ( rs->sr_err != LDAP_SUCCESS ) {
5636 Debug( LDAP_DEBUG_TRACE,
5637 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
5638 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
5643 if ( op->o_abandon ) {
5644 rs->sr_err = SLAPD_ABANDON;
5647 ldap_pvt_thread_pool_pause( &connection_pool );
5650 * 1) check for existence of entry
5651 * 2) check for sibling renumbering
5652 * 3) perform internal add
5653 * 4) perform any necessary renumbering
5654 * 5) store entry in underlying database
5656 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
5657 if ( rs->sr_err != LDAP_SUCCESS ) {
5658 rs->sr_text = ca.cr_msg;
5663 CfEntryInfo *ce = ca.ca_entry->e_private;
5664 req_add_s addr = op->oq_add;
5665 op->o_tag = LDAP_REQ_MODRDN;
5666 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
5667 op->o_tag = LDAP_REQ_ADD;
5669 if ( rs->sr_err != LDAP_SUCCESS ) {
5674 if ( cfb->cb_use_ldif ) {
5675 BackendDB *be = op->o_bd;
5676 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5677 struct berval dn, ndn;
5679 op->o_bd = &cfb->cb_db;
5681 /* Save current rootdn; use the underlying DB's rootdn */
5684 op->o_dn = op->o_bd->be_rootdn;
5685 op->o_ndn = op->o_bd->be_rootndn;
5687 scp = op->o_callback;
5688 op->o_callback = ≻
5689 op->o_bd->be_add( op, rs );
5691 op->o_callback = scp;
5697 ldap_pvt_thread_pool_resume( &connection_pool );
5700 { int repl = op->o_dont_replicate;
5701 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
5702 rs->sr_text = NULL; /* Set after config_add_internal */
5703 rs->sr_err = LDAP_SUCCESS;
5704 op->o_dont_replicate = 1;
5706 send_ldap_result( op, rs );
5707 op->o_dont_replicate = repl;
5709 slap_graduate_commit_csn( op );
5713 typedef struct delrec {
5714 struct delrec *next;
5720 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
5726 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
5727 ca->line[0] == '{' )
5729 char *ptr = strchr( ca->line + 1, '}' );
5733 ca->valx = strtol( ca->line + 1, &next, 0 );
5734 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
5740 rc = config_parse_add( ct, ca, i );
5748 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
5751 int rc = LDAP_UNWILLING_TO_PERFORM;
5753 Entry *e = ce->ce_entry;
5754 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
5759 delrec *dels = NULL, *deltail = NULL;
5761 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5762 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
5764 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5765 if (ml->sml_desc == slap_schema.si_ad_objectClass)
5769 colst = count_ocs( oc_at, &nocs );
5771 /* make sure add/del flags are clear; should always be true */
5772 for ( s = save_attrs; s; s = s->a_next ) {
5773 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
5776 e->e_attrs = attrs_dup( e->e_attrs );
5778 init_config_argv( ca );
5781 ca->ca_private = ce->ce_private;
5783 ca->fname = "slapd";
5785 strcpy( ca->log, "back-config" );
5787 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5788 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5789 switch (ml->sml_op) {
5790 case LDAP_MOD_DELETE:
5791 case LDAP_MOD_REPLACE:
5792 case SLAP_MOD_SOFTDEL:
5794 BerVarray vals = NULL, nvals = NULL;
5796 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
5798 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
5799 ml->sml_desc->ad_cname.bv_val );
5802 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5803 vals = ml->sml_values;
5804 nvals = ml->sml_nvalues;
5805 ml->sml_values = NULL;
5806 ml->sml_nvalues = NULL;
5808 /* If we're deleting by values, remember the indexes of the
5809 * values we deleted.
5811 if ( ct && ml->sml_values ) {
5813 i = ml->sml_numvals;
5814 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
5825 rc = modify_delete_vindex(e, &ml->sml_mod,
5826 get_permissiveModify(op),
5827 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
5828 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5829 ml->sml_values = vals;
5830 ml->sml_nvalues = nvals;
5832 if ( rc == LDAP_NO_SUCH_ATTRIBUTE && ml->sml_op == SLAP_MOD_SOFTDEL )
5836 /* FIXME: check rc before fallthru? */
5840 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5842 case SLAP_MOD_ADD_IF_NOT_PRESENT:
5843 if ( ml->sml_op == SLAP_MOD_ADD_IF_NOT_PRESENT
5844 && attr_find( e->e_attrs, ml->sml_desc ) )
5851 case SLAP_MOD_SOFTADD: {
5852 int mop = ml->sml_op;
5854 ml->sml_op = LDAP_MOD_ADD;
5856 if ( ct->arg_type & ARG_NO_INSERT ) {
5857 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
5859 navals = a->a_numvals;
5862 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
5863 if ( ml->sml_values[i].bv_val[0] == '{' &&
5866 char *next, *val = ml->sml_values[i].bv_val + 1;
5869 j = strtol( val, &next, 0 );
5870 if ( next == val || next[ 0 ] != '}' || j < navals ) {
5872 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
5873 ml->sml_desc->ad_cname.bv_val );
5877 rc = check_vals( ct, ca, ml, 0 );
5878 if ( rc ) goto out_noop;
5881 rc = modify_add_values(e, &ml->sml_mod,
5882 get_permissiveModify(op),
5883 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5885 /* If value already exists, show success here
5886 * and ignore this operation down below.
5888 if ( mop == SLAP_MOD_SOFTADD ) {
5889 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
5899 case LDAP_MOD_INCREMENT: /* FIXME */
5904 if(rc != LDAP_SUCCESS) break;
5907 if ( rc == LDAP_SUCCESS) {
5908 /* check that the entry still obeys the schema */
5909 rc = entry_schema_check(op, e, NULL, 0, 0, NULL,
5910 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5912 if ( rc ) goto out_noop;
5914 /* Basic syntax checks are OK. Do the actual settings. */
5915 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5916 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5917 if ( !ct ) continue;
5919 s = attr_find( save_attrs, ml->sml_desc );
5920 a = attr_find( e->e_attrs, ml->sml_desc );
5922 switch (ml->sml_op) {
5923 case LDAP_MOD_DELETE:
5924 case LDAP_MOD_REPLACE: {
5925 BerVarray vals = NULL, nvals = NULL;
5928 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5929 vals = ml->sml_values;
5930 nvals = ml->sml_nvalues;
5931 ml->sml_values = NULL;
5932 ml->sml_nvalues = NULL;
5935 if ( ml->sml_values )
5938 /* If we didn't delete the whole attribute */
5939 if ( ml->sml_values && a ) {
5940 struct berval *mvals;
5943 if ( ml->sml_nvalues )
5944 mvals = ml->sml_nvalues;
5946 mvals = ml->sml_values;
5948 /* use the indexes we saved up above */
5949 for (i=0; i < d->nidx; i++) {
5950 struct berval bv = *mvals++;
5951 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
5952 bv.bv_val[0] == '{' ) {
5953 ptr = strchr( bv.bv_val, '}' ) + 1;
5954 bv.bv_len -= ptr - bv.bv_val;
5957 ca->line = bv.bv_val;
5958 ca->valx = d->idx[i];
5959 config_parse_vals(ct, ca, d->idx[i] );
5960 rc = config_del_vals( ct, ca );
5961 if ( rc != LDAP_SUCCESS ) break;
5963 s->a_flags |= SLAP_ATTR_IXDEL;
5964 for (j=i+1; j < d->nidx; j++)
5965 if ( d->idx[j] >d->idx[i] )
5972 rc = config_del_vals( ct, ca );
5973 if ( rc ) rc = LDAP_OTHER;
5975 s->a_flags |= SLAP_ATTR_IXDEL;
5977 if ( ml->sml_values ) {
5982 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5983 ml->sml_values = vals;
5984 ml->sml_nvalues = nvals;
5986 if ( !vals || rc != LDAP_SUCCESS )
5989 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5994 for (i=0; ml->sml_values[i].bv_val; i++) {
5995 ca->line = ml->sml_values[i].bv_val;
5997 rc = config_modify_add( ct, ca, ml->sml_desc, i );
6000 a->a_flags |= SLAP_ATTR_IXADD;
6007 /* Undo for a failed operation */
6008 if ( rc != LDAP_SUCCESS ) {
6009 ConfigReply msg = ca->reply;
6010 for ( s = save_attrs; s; s = s->a_next ) {
6011 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
6012 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
6013 ct = config_find_table( colst, nocs, s->a_desc, ca );
6014 a = attr_find( e->e_attrs, s->a_desc );
6016 /* clear the flag so the add check below will skip it */
6017 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
6021 config_del_vals( ct, ca );
6023 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
6024 ca->line = s->a_vals[i].bv_val;
6026 config_modify_add( ct, ca, s->a_desc, i );
6030 for ( a = e->e_attrs; a; a = a->a_next ) {
6031 if ( a->a_flags & SLAP_ATTR_IXADD ) {
6032 ct = config_find_table( colst, nocs, a->a_desc, ca );
6036 config_del_vals( ct, ca );
6037 s = attr_find( save_attrs, a->a_desc );
6039 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
6040 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
6041 ca->line = s->a_vals[i].bv_val;
6043 config_modify_add( ct, ca, s->a_desc, i );
6051 if ( ca->cleanup ) {
6052 i = ca->cleanup( ca );
6053 if (rc == LDAP_SUCCESS)
6057 if ( rc == LDAP_SUCCESS ) {
6058 attrs_free( save_attrs );
6061 attrs_free( e->e_attrs );
6062 e->e_attrs = save_attrs;
6064 ch_free( ca->argv );
6065 if ( colst ) ch_free( colst );
6067 deltail = dels->next;
6076 config_back_modify( Operation *op, SlapReply *rs )
6079 CfEntryInfo *ce, *last;
6081 ConfigArgs ca = {0};
6084 AttributeDescription *rad = NULL;
6087 cfb = (CfBackInfo *)op->o_bd->be_private;
6089 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6092 rs->sr_matched = last->ce_entry->e_name.bv_val;
6093 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6097 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
6098 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6102 /* Get type of RDN */
6103 rdn = ce->ce_entry->e_nname;
6104 ptr = strchr( rdn.bv_val, '=' );
6105 rdn.bv_len = ptr - rdn.bv_val;
6106 rs->sr_err = slap_bv2ad( &rdn, &rad, &rs->sr_text );
6107 if ( rs->sr_err != LDAP_SUCCESS ) {
6111 /* Some basic validation... */
6112 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
6113 /* Don't allow Modify of RDN; must use ModRdn for that. */
6114 if ( ml->sml_desc == rad ) {
6115 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
6116 rs->sr_text = "Use modrdn to change the entry name";
6119 /* Internal update of contextCSN? */
6120 if ( ml->sml_desc == slap_schema.si_ad_contextCSN && op->o_conn->c_conn_idx == -1 ) {
6126 slap_mods_opattrs( op, &op->orm_modlist, 1 );
6129 if ( op->o_abandon ) {
6130 rs->sr_err = SLAPD_ABANDON;
6133 ldap_pvt_thread_pool_pause( &connection_pool );
6137 * 1) perform the Modify on the cached Entry.
6138 * 2) verify that the Entry still satisfies the schema.
6139 * 3) perform the individual config operations.
6140 * 4) store Modified entry in underlying LDIF backend.
6142 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
6144 rs->sr_text = ca.cr_msg;
6145 } else if ( cfb->cb_use_ldif ) {
6146 BackendDB *be = op->o_bd;
6147 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
6148 struct berval dn, ndn;
6150 op->o_bd = &cfb->cb_db;
6154 op->o_dn = op->o_bd->be_rootdn;
6155 op->o_ndn = op->o_bd->be_rootndn;
6157 scp = op->o_callback;
6158 op->o_callback = ≻
6159 op->o_bd->be_modify( op, rs );
6161 op->o_callback = scp;
6167 ldap_pvt_thread_pool_resume( &connection_pool );
6169 send_ldap_result( op, rs );
6170 slap_graduate_commit_csn( op );
6175 config_back_modrdn( Operation *op, SlapReply *rs )
6178 CfEntryInfo *ce, *last;
6182 cfb = (CfBackInfo *)op->o_bd->be_private;
6184 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6187 rs->sr_matched = last->ce_entry->e_name.bv_val;
6188 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6191 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
6192 NULL, ACL_WRITE, NULL )) {
6193 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6197 if ( ce->ce_parent )
6198 parent = ce->ce_parent->ce_entry;
6200 parent = (Entry *)&slap_entry_root;
6201 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
6202 NULL, ACL_WRITE, NULL )) {
6203 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6208 /* We don't allow moving objects to new parents.
6209 * Generally we only allow reordering a set of ordered entries.
6211 if ( op->orr_newSup ) {
6212 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6216 /* If newRDN == oldRDN, quietly succeed */
6217 dnRdn( &op->o_req_ndn, &rdn );
6218 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
6219 rs->sr_err = LDAP_SUCCESS;
6223 /* Current behavior, subject to change as needed:
6225 * For backends and overlays, we only allow renumbering.
6226 * For schema, we allow renaming with the same number.
6227 * Otherwise, the op is not allowed.
6230 if ( ce->ce_type == Cft_Schema ) {
6234 /* Can't alter the main cn=schema entry */
6235 if ( ce->ce_parent->ce_type == Cft_Global ) {
6236 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6237 rs->sr_text = "renaming not allowed for this entry";
6241 /* We could support this later if desired */
6242 ptr1 = ber_bvchr( &rdn, '}' );
6243 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
6244 len = ptr1 - rdn.bv_val;
6245 if ( len != ptr2 - op->orr_newrdn.bv_val ||
6246 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
6247 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6248 rs->sr_text = "schema reordering not supported";
6251 } else if ( ce->ce_type == Cft_Database ||
6252 ce->ce_type == Cft_Overlay ) {
6253 char *ptr1, *ptr2, *iptr1, *iptr2;
6256 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
6257 if ( *iptr2 != '{' ) {
6258 rs->sr_err = LDAP_NAMING_VIOLATION;
6259 rs->sr_text = "new ordering index is required";
6263 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
6264 ptr1 = ber_bvchr( &rdn, '}' );
6265 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
6267 rs->sr_err = LDAP_NAMING_VIOLATION;
6268 rs->sr_text = "new ordering index is required";
6272 len1 = ptr1 - rdn.bv_val;
6273 len2 = ptr2 - op->orr_newrdn.bv_val;
6275 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
6276 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
6277 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6278 rs->sr_text = "changing database/overlay type not allowed";
6281 ixold = strtol( iptr1, NULL, 0 );
6282 ixnew = strtol( iptr2, &ptr1, 0 );
6283 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
6284 rs->sr_err = LDAP_NAMING_VIOLATION;
6287 /* config DB is always 0, cannot be changed */
6288 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
6289 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
6293 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6294 rs->sr_text = "renaming not supported for this entry";
6298 if ( op->o_abandon ) {
6299 rs->sr_err = SLAPD_ABANDON;
6302 ldap_pvt_thread_pool_pause( &connection_pool );
6304 if ( ce->ce_type == Cft_Schema ) {
6305 req_modrdn_s modr = op->oq_modrdn;
6308 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
6309 if ( rs->sr_err == LDAP_SUCCESS ) {
6310 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
6311 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
6314 op->oq_modrdn = modr;
6316 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
6317 req_modrdn_s modr = op->oq_modrdn;
6320 /* Advance to first of this type */
6321 cprev = &ce->ce_parent->ce_kids;
6322 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
6323 cprev = &ce2->ce_sibs;
6326 /* Skip the -1 entry */
6327 if ( ce->ce_type == Cft_Database ) {
6328 cprev = &ce2->ce_sibs;
6334 /* Remove from old slot */
6335 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
6336 cprev = &ce2->ce_sibs;
6337 *cprev = ce->ce_sibs;
6338 ceold = ce->ce_sibs;
6340 /* Insert into new slot */
6342 for ( i=0; i<ixnew; i++ ) {
6346 cprev = &ce2->ce_sibs;
6348 ce->ce_sibs = *cprev;
6353 /* NOTE: These should be encoded in the OC tables, not inline here */
6354 if ( ce->ce_type == Cft_Database )
6355 backend_db_move( ce->ce_be, ixnew );
6356 else if ( ce->ce_type == Cft_Overlay )
6357 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
6359 if ( ixold < ixnew ) {
6360 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
6363 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
6364 ixold - ixnew, cfb->cb_use_ldif );
6366 op->oq_modrdn = modr;
6369 ldap_pvt_thread_pool_resume( &connection_pool );
6371 send_ldap_result( op, rs );
6376 config_back_delete( Operation *op, SlapReply *rs )
6378 #ifdef SLAP_CONFIG_DELETE
6380 CfEntryInfo *ce, *last, *ce2;
6382 cfb = (CfBackInfo *)op->o_bd->be_private;
6384 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6387 rs->sr_matched = last->ce_entry->e_name.bv_val;
6388 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6389 } else if ( ce->ce_kids ) {
6390 rs->sr_err = LDAP_NOT_ALLOWED_ON_NONLEAF;
6391 } else if ( op->o_abandon ) {
6392 rs->sr_err = SLAPD_ABANDON;
6393 } else if ( ce->ce_type == Cft_Overlay ||
6394 ce->ce_type == Cft_Database ||
6395 ce->ce_type == Cft_Misc ){
6399 ldap_pvt_thread_pool_pause( &connection_pool );
6401 if ( ce->ce_type == Cft_Overlay ){
6402 overlay_remove( ce->ce_be, (slap_overinst *)ce->ce_bi, op );
6403 } else if ( ce->ce_type == Cft_Misc ) {
6405 * only Cft_Misc objects that have a co_lddel handler set in
6406 * the ConfigOCs struct can be deleted. This code also
6407 * assumes that the entry can be only have one objectclass
6408 * with co_type == Cft_Misc
6410 ConfigOCs co, *coptr;
6414 oc_at = attr_find( ce->ce_entry->e_attrs,
6415 slap_schema.si_ad_objectClass );
6417 rs->sr_err = LDAP_OTHER;
6418 rs->sr_text = "objectclass not found";
6419 ldap_pvt_thread_pool_resume( &connection_pool );
6422 for ( i=0; !BER_BVISNULL(&oc_at->a_nvals[i]); i++ ) {
6423 co.co_name = &oc_at->a_nvals[i];
6424 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
6425 if ( coptr == NULL || coptr->co_type != Cft_Misc ) {
6428 if ( ! coptr->co_lddel || coptr->co_lddel( ce, op ) ){
6429 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6430 if ( ! coptr->co_lddel ) {
6431 rs->sr_text = "No delete handler found";
6433 rs->sr_err = LDAP_OTHER;
6434 /* FIXME: We should return a helpful error message
6437 ldap_pvt_thread_pool_resume( &connection_pool );
6442 } else if (ce->ce_type == Cft_Database ) {
6443 if ( ce->ce_be == frontendDB || ce->ce_be == op->o_bd ){
6444 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6445 rs->sr_text = "Cannot delete config or frontend database";
6446 ldap_pvt_thread_pool_resume( &connection_pool );
6449 if ( ce->ce_be->bd_info->bi_db_close ) {
6450 ce->ce_be->bd_info->bi_db_close( ce->ce_be, NULL );
6452 backend_destroy_one( ce->ce_be, 1);
6455 /* remove CfEntryInfo from the siblings list */
6456 if ( ce->ce_parent->ce_kids == ce ) {
6457 ce->ce_parent->ce_kids = ce->ce_sibs;
6459 for ( ce2 = ce->ce_parent->ce_kids ; ce2; ce2 = ce2->ce_sibs ) {
6460 if ( ce2->ce_sibs == ce ) {
6461 ce2->ce_sibs = ce->ce_sibs;
6467 /* remove from underlying database */
6468 if ( cfb->cb_use_ldif ) {
6469 BackendDB *be = op->o_bd;
6470 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
6471 struct berval dn, ndn, req_dn, req_ndn;
6473 op->o_bd = &cfb->cb_db;
6477 req_dn = op->o_req_dn;
6478 req_ndn = op->o_req_ndn;
6480 op->o_dn = op->o_bd->be_rootdn;
6481 op->o_ndn = op->o_bd->be_rootndn;
6482 op->o_req_dn = ce->ce_entry->e_name;
6483 op->o_req_ndn = ce->ce_entry->e_nname;
6485 scp = op->o_callback;
6486 op->o_callback = ≻
6487 op->o_bd->be_delete( op, rs );
6489 op->o_callback = scp;
6492 op->o_req_dn = req_dn;
6493 op->o_req_ndn = req_ndn;
6496 /* renumber siblings */
6497 iptr = ber_bvchr( &op->o_req_ndn, '{' ) + 1;
6498 ixold = strtol( iptr, NULL, 0 );
6499 for (ce2 = ce->ce_sibs, count=0; ce2; ce2=ce2->ce_sibs) {
6500 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
6501 count+ixold, 0, cfb->cb_use_ldif );
6505 ce->ce_entry->e_private=NULL;
6506 entry_free(ce->ce_entry);
6508 ldap_pvt_thread_pool_resume( &connection_pool );
6510 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6514 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6515 #endif /* SLAP_CONFIG_DELETE */
6516 send_ldap_result( op, rs );
6521 config_back_search( Operation *op, SlapReply *rs )
6524 CfEntryInfo *ce, *last;
6527 cfb = (CfBackInfo *)op->o_bd->be_private;
6529 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6532 rs->sr_matched = last->ce_entry->e_name.bv_val;
6533 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6536 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
6537 ACL_SEARCH, NULL, &mask ))
6539 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
6540 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6542 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6546 switch ( op->ors_scope ) {
6547 case LDAP_SCOPE_BASE:
6548 case LDAP_SCOPE_SUBTREE:
6549 rs->sr_err = config_send( op, rs, ce, 0 );
6552 case LDAP_SCOPE_ONELEVEL:
6553 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
6554 rs->sr_err = config_send( op, rs, ce, 1 );
6563 send_ldap_result( op, rs );
6567 /* no-op, we never free entries */
6568 int config_entry_release(
6573 if ( !e->e_private ) {
6576 return LDAP_SUCCESS;
6579 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
6581 int config_back_entry_get(
6585 AttributeDescription *at,
6590 CfEntryInfo *ce, *last;
6591 int rc = LDAP_NO_SUCH_OBJECT;
6593 cfb = (CfBackInfo *)op->o_bd->be_private;
6595 ce = config_find_base( cfb->cb_root, ndn, &last );
6597 *ent = ce->ce_entry;
6600 if ( oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
6601 rc = LDAP_NO_SUCH_ATTRIBUTE;
6611 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
6612 ConfigTable *ct, ConfigArgs *c )
6616 for (; at && *at; at++) {
6617 /* Skip the naming attr */
6618 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
6620 for (i=0;ct[i].name;i++) {
6621 if (ct[i].ad == (*at)->sat_ad) {
6622 rc = config_get_vals(&ct[i], c);
6623 /* NOTE: tolerate that config_get_vals()
6624 * returns success with no values */
6625 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
6626 if ( c->rvalue_nvals )
6627 rc = attr_merge(e, ct[i].ad, c->rvalue_vals,
6630 slap_syntax_validate_func *validate =
6631 ct[i].ad->ad_type->sat_syntax->ssyn_validate;
6634 for ( j=0; c->rvalue_vals[j].bv_val; j++ ) {
6635 rc = ordered_value_validate( ct[i].ad,
6636 &c->rvalue_vals[j], LDAP_MOD_ADD );
6638 Debug( LDAP_DEBUG_ANY,
6639 "config_build_attrs: error %d on %s value #%d\n",
6640 rc, ct[i].ad->ad_cname.bv_val, j );
6646 rc = attr_merge_normalize(e, ct[i].ad,
6647 c->rvalue_vals, NULL);
6649 ber_bvarray_free( c->rvalue_nvals );
6650 ber_bvarray_free( c->rvalue_vals );
6652 Debug( LDAP_DEBUG_ANY,
6653 "config_build_attrs: error %d on %s\n",
6654 rc, ct[i].ad->ad_cname.bv_val, 0 );
6665 /* currently (2010) does not access rs except possibly writing rs->sr_err */
6668 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
6669 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
6671 Entry *e = entry_alloc();
6672 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
6674 struct berval ad_name;
6675 AttributeDescription *ad = NULL;
6678 const char *text = "";
6682 CfEntryInfo *ceprev = NULL;
6684 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
6687 ce->ce_type = main->co_type;
6688 ce->ce_parent = parent;
6690 pdn = parent->ce_entry->e_nname;
6691 if ( parent->ce_kids && parent->ce_kids->ce_type <= ce->ce_type )
6692 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
6693 ceprev->ce_type <= ce->ce_type;
6694 ceprev = ceprev->ce_sibs );
6699 ce->ce_private = c->ca_private;
6703 build_new_dn( &e->e_name, &pdn, rdn, NULL );
6704 ber_dupbv( &e->e_nname, &e->e_name );
6706 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6707 main->co_name, NULL );
6709 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6710 extra->co_name, NULL );
6711 ptr = strchr(rdn->bv_val, '=');
6712 ad_name.bv_val = rdn->bv_val;
6713 ad_name.bv_len = ptr - rdn->bv_val;
6714 rc = slap_bv2ad( &ad_name, &ad, &text );
6719 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
6720 attr_merge_normalize_one(e, ad, &val, NULL );
6723 c->table = main->co_type;
6724 if ( oc->soc_required ) {
6725 rc = config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
6726 if ( rc ) goto fail;
6729 if ( oc->soc_allowed ) {
6730 rc = config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
6731 if ( rc ) goto fail;
6736 c->table = extra->co_type;
6737 if ( oc->soc_required ) {
6738 rc = config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
6739 if ( rc ) goto fail;
6742 if ( oc->soc_allowed ) {
6743 rc = config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
6744 if ( rc ) goto fail;
6748 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
6749 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
6750 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
6751 if ( rc != LDAP_SUCCESS ) {
6753 Debug( LDAP_DEBUG_ANY,
6754 "config_build_entry: build \"%s\" failed: \"%s\"\n",
6755 rdn->bv_val, text, 0);
6758 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
6761 op->ora_modlist = NULL;
6762 slap_add_opattrs( op, NULL, NULL, 0, 0 );
6763 if ( !op->o_noop ) {
6764 SlapReply rs2 = {REP_RESULT};
6765 op->o_bd->be_add( op, &rs2 );
6766 rs->sr_err = rs2.sr_err;
6767 rs_assert_done( &rs2 );
6768 if ( ( rs2.sr_err != LDAP_SUCCESS )
6769 && (rs2.sr_err != LDAP_ALREADY_EXISTS) ) {
6775 ce->ce_sibs = ceprev->ce_sibs;
6776 ceprev->ce_sibs = ce;
6777 } else if ( parent ) {
6778 ce->ce_sibs = parent->ce_kids;
6779 parent->ce_kids = ce;
6786 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
6787 Operation *op, SlapReply *rs )
6790 ConfigFile *cf = c->ca_private;
6792 struct berval bv, rdn;
6794 for (; cf; cf=cf->c_sibs, c->depth++) {
6795 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
6796 !cf->c_om_head && !cf->c_syn_head ) continue;
6797 c->value_dn.bv_val = c->log;
6798 LUTIL_SLASHPATH( cf->c_file.bv_val );
6799 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
6804 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
6806 ptr = strchr( bv.bv_val, '.' );
6808 bv.bv_len = ptr - bv.bv_val;
6809 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
6810 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6811 /* FIXME: how can indicate error? */
6814 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
6816 c->value_dn.bv_len += bv.bv_len;
6817 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
6818 rdnNormalize( 0, NULL, NULL, &c->value_dn, &rdn, NULL );
6821 e = config_build_entry( op, rs, ceparent, c, &rdn,
6822 &CFOC_SCHEMA, NULL );
6823 ch_free( rdn.bv_val );
6826 } else if ( e && cf->c_kids ) {
6827 c->ca_private = cf->c_kids;
6828 config_build_schema_inc( c, e->e_private, op, rs );
6834 #ifdef SLAPD_MODULES
6837 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
6838 Operation *op, SlapReply *rs )
6843 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
6844 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
6846 c->value_dn.bv_val = c->log;
6847 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
6848 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6849 /* FIXME: how can indicate error? */
6853 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
6862 config_check_schema(Operation *op, CfBackInfo *cfb)
6864 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
6866 CfEntryInfo *ce, *last;
6869 /* If there's no root entry, we must be in the midst of converting */
6870 if ( !cfb->cb_root )
6873 /* Make sure the main schema entry exists */
6874 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
6881 /* Make sure it's up to date */
6882 if ( cf_om_tail != om_sys_tail ) {
6883 a = attr_find( e->e_attrs, cfAd_om );
6885 if ( a->a_nvals != a->a_vals )
6886 ber_bvarray_free( a->a_nvals );
6887 ber_bvarray_free( a->a_vals );
6892 oidm_unparse( &bv, NULL, NULL, 1 );
6893 attr_merge_normalize( e, cfAd_om, bv, NULL );
6894 ber_bvarray_free( bv );
6895 cf_om_tail = om_sys_tail;
6897 if ( cf_at_tail != at_sys_tail ) {
6898 a = attr_find( e->e_attrs, cfAd_attr );
6900 if ( a->a_nvals != a->a_vals )
6901 ber_bvarray_free( a->a_nvals );
6902 ber_bvarray_free( a->a_vals );
6907 at_unparse( &bv, NULL, NULL, 1 );
6908 attr_merge_normalize( e, cfAd_attr, bv, NULL );
6909 ber_bvarray_free( bv );
6910 cf_at_tail = at_sys_tail;
6912 if ( cf_oc_tail != oc_sys_tail ) {
6913 a = attr_find( e->e_attrs, cfAd_oc );
6915 if ( a->a_nvals != a->a_vals )
6916 ber_bvarray_free( a->a_nvals );
6917 ber_bvarray_free( a->a_vals );
6922 oc_unparse( &bv, NULL, NULL, 1 );
6923 attr_merge_normalize( e, cfAd_oc, bv, NULL );
6924 ber_bvarray_free( bv );
6925 cf_oc_tail = oc_sys_tail;
6927 if ( cf_syn_tail != syn_sys_tail ) {
6928 a = attr_find( e->e_attrs, cfAd_syntax );
6930 if ( a->a_nvals != a->a_vals )
6931 ber_bvarray_free( a->a_nvals );
6932 ber_bvarray_free( a->a_vals );
6937 syn_unparse( &bv, NULL, NULL, 1 );
6938 attr_merge_normalize( e, cfAd_syntax, bv, NULL );
6939 ber_bvarray_free( bv );
6940 cf_syn_tail = syn_sys_tail;
6943 SlapReply rs = {REP_RESULT};
6944 c.ca_private = NULL;
6945 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
6946 &CFOC_SCHEMA, NULL );
6951 ce->ce_private = cfb->cb_config;
6952 cf_at_tail = at_sys_tail;
6953 cf_oc_tail = oc_sys_tail;
6954 cf_om_tail = om_sys_tail;
6955 cf_syn_tail = syn_sys_tail;
6960 static const char *defacl[] = {
6961 NULL, "to", "*", "by", "*", "none", NULL
6965 config_back_db_open( BackendDB *be, ConfigReply *cr )
6967 CfBackInfo *cfb = be->be_private;
6970 CfEntryInfo *ce, *ceparent;
6974 Connection conn = {0};
6975 OperationBuffer opbuf;
6977 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
6978 SlapReply rs = {REP_RESULT};
6979 void *thrctx = NULL;
6980 AccessControl *save_access;
6982 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
6984 /* If we have no explicitly configured ACLs, don't just use
6985 * the global ACLs. Explicitly deny access to everything.
6987 save_access = be->bd_self->be_acl;
6988 be->bd_self->be_acl = NULL;
6989 parse_acl(be->bd_self, "config_back_db_open", 0, 6, (char **)defacl, 0 );
6990 defacl_parsed = be->bd_self->be_acl;
6991 if ( save_access ) {
6992 be->bd_self->be_acl = save_access;
6994 Debug( LDAP_DEBUG_CONFIG, "config_back_db_open: "
6995 "No explicit ACL for back-config configured. "
6996 "Using hardcoded default\n", 0, 0, 0 );
6999 thrctx = ldap_pvt_thread_pool_context();
7000 connection_fake_init( &conn, &opbuf, thrctx );
7003 op->o_tag = LDAP_REQ_ADD;
7004 op->o_callback = &cb;
7005 op->o_bd = &cfb->cb_db;
7006 op->o_dn = op->o_bd->be_rootdn;
7007 op->o_ndn = op->o_bd->be_rootndn;
7009 if ( !cfb->cb_use_ldif ) {
7013 /* If we read the config from back-ldif, do some quick sanity checks */
7014 if ( cfb->cb_got_ldif ) {
7015 return config_check_schema( op, cfb );
7018 /* create root of tree */
7020 c.ca_private = cfb->cb_config;
7022 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
7032 #ifdef SLAPD_MODULES
7033 /* Create Module nodes... */
7034 if ( modpaths.mp_loads ) {
7035 if ( config_build_modules( &c, ceparent, op, &rs ) ){
7041 /* Create schema nodes... cn=schema will contain the hardcoded core
7042 * schema, read-only. Child objects will contain runtime loaded schema
7046 c.ca_private = NULL;
7047 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
7052 ce->ce_private = cfb->cb_config;
7053 cf_at_tail = at_sys_tail;
7054 cf_oc_tail = oc_sys_tail;
7055 cf_om_tail = om_sys_tail;
7056 cf_syn_tail = syn_sys_tail;
7058 /* Create schema nodes for included schema... */
7059 if ( cfb->cb_config->c_kids ) {
7062 c.ca_private = cfb->cb_config->c_kids;
7063 rc = config_build_schema_inc( &c, ce, op, &rs );
7069 /* Create backend nodes. Skip if they don't provide a cf_table.
7070 * There usually aren't any of these.
7074 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
7075 if (!bi->bi_cf_ocs) {
7076 /* If it only supports the old config mech, complain. */
7077 if ( bi->bi_config ) {
7078 Debug( LDAP_DEBUG_ANY,
7079 "WARNING: No dynamic config support for backend %s.\n",
7080 bi->bi_type, 0, 0 );
7085 if (!bi->bi_private) continue;
7088 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
7089 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
7090 if ( rdn.bv_len >= sizeof( c.log ) ) {
7091 /* FIXME: holler ... */ ;
7094 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
7101 /* Create database nodes... */
7102 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
7103 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
7104 for ( i = -1, be = frontendDB ; be;
7105 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
7106 slap_overinfo *oi = NULL;
7108 if ( overlay_is_over( be )) {
7109 oi = be->bd_info->bi_private;
7115 /* If this backend supports the old config mechanism, but not
7116 * the new mech, complain.
7118 if ( !be->be_cf_ocs && bi->bi_db_config ) {
7119 Debug( LDAP_DEBUG_ANY,
7120 "WARNING: No dynamic config support for database %s.\n",
7121 bi->bi_type, 0, 0 );
7125 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
7126 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
7128 if ( rdn.bv_len >= sizeof( c.log ) ) {
7129 /* FIXME: holler ... */ ;
7133 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
7139 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd ) {
7140 rs_reinit( &rs, REP_RESULT );
7141 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
7143 /* Iterate through overlays */
7148 voidList *vl, *v0 = NULL;
7150 /* overlays are in LIFO order, must reverse stack */
7151 for (on=oi->oi_list; on; on=on->on_next) {
7152 vl = ch_malloc( sizeof( voidList ));
7157 for (j=0; vl; j++,vl=v0) {
7161 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
7162 Debug( LDAP_DEBUG_ANY,
7163 "WARNING: No dynamic config support for overlay %s.\n",
7164 on->on_bi.bi_type, 0, 0 );
7168 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
7169 "%s=" SLAP_X_ORDERED_FMT "%s",
7170 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
7171 if ( rdn.bv_len >= sizeof( c.log ) ) {
7172 /* FIXME: holler ... */ ;
7176 oe = config_build_entry( op, &rs, ce, &c, &rdn,
7177 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
7181 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd ) {
7182 rs_reinit( &rs, REP_RESULT );
7183 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
7189 ldap_pvt_thread_pool_context_reset( thrctx );
7191 if ( unsupp && cfb->cb_use_ldif ) {
7192 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
7193 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
7200 cfb_free_cffile( ConfigFile *cf )
7204 for (; cf; cf=next) {
7207 cfb_free_cffile( cf->c_kids );
7208 ch_free( cf->c_file.bv_val );
7209 ber_bvarray_free( cf->c_dseFiles );
7215 cfb_free_entries( CfEntryInfo *ce )
7219 for (; ce; ce=next) {
7222 cfb_free_entries( ce->ce_kids );
7223 ce->ce_entry->e_private = NULL;
7224 entry_free( ce->ce_entry );
7230 config_back_db_close( BackendDB *be, ConfigReply *cr )
7232 CfBackInfo *cfb = be->be_private;
7234 cfb_free_entries( cfb->cb_root );
7235 cfb->cb_root = NULL;
7237 if ( cfb->cb_db.bd_info ) {
7238 backend_shutdown( &cfb->cb_db );
7241 if ( defacl_parsed && be->be_acl != defacl_parsed ) {
7242 acl_free( defacl_parsed );
7243 defacl_parsed = NULL;
7250 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
7252 CfBackInfo *cfb = be->be_private;
7254 cfb_free_cffile( cfb->cb_config );
7256 ch_free( cfdir.bv_val );
7258 avl_free( CfOcTree, NULL );
7260 if ( cfb->cb_db.bd_info ) {
7261 cfb->cb_db.be_suffix = NULL;
7262 cfb->cb_db.be_nsuffix = NULL;
7263 BER_BVZERO( &cfb->cb_db.be_rootdn );
7264 BER_BVZERO( &cfb->cb_db.be_rootndn );
7266 backend_destroy_one( &cfb->cb_db, 0 );
7275 config_back_db_init( BackendDB *be, ConfigReply* cr )
7281 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
7282 cfn = cfb->cb_config;
7283 be->be_private = cfb;
7285 ber_dupbv( &be->be_rootdn, &config_rdn );
7286 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
7287 ber_dupbv( &dn, &be->be_rootdn );
7288 ber_bvarray_add( &be->be_suffix, &dn );
7289 ber_dupbv( &dn, &be->be_rootdn );
7290 ber_bvarray_add( &be->be_nsuffix, &dn );
7292 /* Hide from namingContexts */
7293 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
7295 /* Check ACLs on content of Adds by default */
7296 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_ACL_ADD;
7302 config_back_destroy( BackendInfo *bi )
7304 ldif_must_b64_encode_release();
7309 config_tool_entry_open( BackendDB *be, int mode )
7311 CfBackInfo *cfb = be->be_private;
7312 BackendInfo *bi = cfb->cb_db.bd_info;
7314 if ( bi && bi->bi_tool_entry_open )
7315 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
7322 config_tool_entry_close( BackendDB *be )
7324 CfBackInfo *cfb = be->be_private;
7325 BackendInfo *bi = cfb->cb_db.bd_info;
7327 if ( bi && bi->bi_tool_entry_close )
7328 return bi->bi_tool_entry_close( &cfb->cb_db );
7334 config_tool_entry_first( BackendDB *be )
7336 CfBackInfo *cfb = be->be_private;
7337 BackendInfo *bi = cfb->cb_db.bd_info;
7339 if ( bi && bi->bi_tool_entry_first ) {
7340 return bi->bi_tool_entry_first( &cfb->cb_db );
7342 if ( bi && bi->bi_tool_entry_first_x ) {
7343 return bi->bi_tool_entry_first_x( &cfb->cb_db,
7344 NULL, LDAP_SCOPE_DEFAULT, NULL );
7350 config_tool_entry_first_x(
7352 struct berval *base,
7356 CfBackInfo *cfb = be->be_private;
7357 BackendInfo *bi = cfb->cb_db.bd_info;
7359 if ( bi && bi->bi_tool_entry_first_x ) {
7360 return bi->bi_tool_entry_first_x( &cfb->cb_db, base, scope, f );
7366 config_tool_entry_next( BackendDB *be )
7368 CfBackInfo *cfb = be->be_private;
7369 BackendInfo *bi = cfb->cb_db.bd_info;
7371 if ( bi && bi->bi_tool_entry_next )
7372 return bi->bi_tool_entry_next( &cfb->cb_db );
7378 config_tool_entry_get( BackendDB *be, ID id )
7380 CfBackInfo *cfb = be->be_private;
7381 BackendInfo *bi = cfb->cb_db.bd_info;
7383 if ( bi && bi->bi_tool_entry_get )
7384 return bi->bi_tool_entry_get( &cfb->cb_db, id );
7389 static int entry_put_got_frontend=0;
7390 static int entry_put_got_config=0;
7392 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
7394 CfBackInfo *cfb = be->be_private;
7395 BackendInfo *bi = cfb->cb_db.bd_info;
7397 struct berval rdn, vals[ 2 ];
7399 OperationBuffer opbuf;
7401 Connection conn = {0};
7402 Operation *op = NULL;
7405 int isFrontendChild = 0;
7407 /* Create entry for frontend database if it does not exist already */
7408 if ( !entry_put_got_frontend ) {
7409 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
7410 STRLENOF( "olcDatabase" ))) {
7411 if ( strncmp( e->e_nname.bv_val +
7412 STRLENOF( "olcDatabase" ), "={-1}frontend",
7413 STRLENOF( "={-1}frontend" )) &&
7414 strncmp( e->e_nname.bv_val +
7415 STRLENOF( "olcDatabase" ), "=frontend",
7416 STRLENOF( "=frontend" ))) {
7418 vals[1].bv_val = NULL;
7419 memset( &ca, 0, sizeof(ConfigArgs));
7421 ca.bi = frontendDB->bd_info;
7422 ca.be->be_cf_ocs = &CFOC_FRONTEND;
7423 rdn.bv_val = ca.log;
7424 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7425 "%s=" SLAP_X_ORDERED_FMT "%s",
7426 cfAd_database->ad_cname.bv_val, -1,
7428 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
7429 &CFOC_DATABASE, ca.be->be_cf_ocs );
7430 thrctx = ldap_pvt_thread_pool_context();
7431 connection_fake_init2( &conn, &opbuf, thrctx,0 );
7433 op->o_bd = &cfb->cb_db;
7434 op->o_tag = LDAP_REQ_ADD;
7436 op->o_dn = be->be_rootdn;
7437 op->o_ndn = be->be_rootndn;
7438 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
7439 if ( rc != LDAP_SUCCESS ) {
7440 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
7441 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
7445 if ( ce && bi && bi->bi_tool_entry_put &&
7446 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
7447 entry_put_got_frontend++;
7449 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
7450 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
7454 if ( !strncmp( e->e_nname.bv_val +
7455 STRLENOF( "olcDatabase" ), "=frontend",
7456 STRLENOF( "=frontend" ) ) )
7458 struct berval rdn, pdn, ndn;
7459 dnParent( &e->e_nname, &pdn );
7460 rdn.bv_val = ca.log;
7461 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7462 "%s=" SLAP_X_ORDERED_FMT "%s",
7463 cfAd_database->ad_cname.bv_val, -1,
7464 frontendDB->bd_info->bi_type );
7465 build_new_dn( &ndn, &pdn, &rdn, NULL );
7466 ber_memfree( e->e_name.bv_val );
7468 ber_bvreplace( &e->e_nname, &e->e_name );
7470 entry_put_got_frontend++;
7476 /* Child entries of the frontend database, e.g. slapo-chain's back-ldap
7477 * instances, may appear before the config database entry in the ldif, skip
7478 * auto-creation of olcDatabase={0}config in such a case */
7479 if ( !entry_put_got_config &&
7480 !strncmp( e->e_nname.bv_val, "olcDatabase", STRLENOF( "olcDatabase" ))) {
7482 dnParent( &e->e_nname, &pdn );
7483 while ( pdn.bv_len ) {
7484 if ( !strncmp( pdn.bv_val, "olcDatabase",
7485 STRLENOF( "olcDatabase" ))) {
7486 if ( !strncmp( pdn.bv_val +
7487 STRLENOF( "olcDatabase" ), "={-1}frontend",
7488 STRLENOF( "={-1}frontend" )) ||
7489 !strncmp( pdn.bv_val +
7490 STRLENOF( "olcDatabase" ), "=frontend",
7491 STRLENOF( "=frontend" ))) {
7493 isFrontendChild = 1;
7497 dnParent( &pdn, &pdn );
7501 /* Create entry for config database if it does not exist already */
7502 if ( !entry_put_got_config && !isFrontend && !isFrontendChild ) {
7503 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
7504 STRLENOF( "olcDatabase" ))) {
7505 if ( strncmp( e->e_nname.bv_val +
7506 STRLENOF( "olcDatabase" ), "={0}config",
7507 STRLENOF( "={0}config" )) &&
7508 strncmp( e->e_nname.bv_val +
7509 STRLENOF( "olcDatabase" ), "=config",
7510 STRLENOF( "=config" )) ) {
7512 vals[1].bv_val = NULL;
7513 memset( &ca, 0, sizeof(ConfigArgs));
7514 ca.be = LDAP_STAILQ_FIRST( &backendDB );
7515 ca.bi = ca.be->bd_info;
7516 rdn.bv_val = ca.log;
7517 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7518 "%s=" SLAP_X_ORDERED_FMT "%s",
7519 cfAd_database->ad_cname.bv_val, 0,
7521 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
7524 thrctx = ldap_pvt_thread_pool_context();
7525 connection_fake_init2( &conn, &opbuf, thrctx,0 );
7527 op->o_bd = &cfb->cb_db;
7528 op->o_tag = LDAP_REQ_ADD;
7529 op->o_dn = be->be_rootdn;
7530 op->o_ndn = be->be_rootndn;
7533 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
7534 if ( rc != LDAP_SUCCESS ) {
7535 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
7536 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7539 if (ce && bi && bi->bi_tool_entry_put &&
7540 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
7541 entry_put_got_config++;
7543 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
7544 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7548 entry_put_got_config++;
7552 if ( bi && bi->bi_tool_entry_put &&
7553 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
7554 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
7561 AttributeDescription **desc;
7563 { "attribute", &cfAd_attr },
7564 { "backend", &cfAd_backend },
7565 { "database", &cfAd_database },
7566 { "include", &cfAd_include },
7567 { "ldapsyntax", &cfAd_syntax },
7568 { "objectclass", &cfAd_oc },
7569 { "objectidentifier", &cfAd_om },
7570 { "overlay", &cfAd_overlay },
7575 * add / delete: all types that may be added or deleted must use an
7576 * X-ORDERED attributeType for their RDN. Adding and deleting entries
7577 * should automatically renumber the index of any siblings as needed,
7578 * so that no gaps in the numbering sequence exist after the add/delete
7580 * What can be added:
7582 * backend objects for backend-specific config directives
7586 * delete: probably no support this time around.
7588 * modrdn: generally not done. Will be invoked automatically by add/
7589 * delete to update numbering sequence. Perform as an explicit operation
7590 * so that the renumbering effect may be replicated. Subtree rename must
7591 * be supported, since renumbering a database will affect all its child
7594 * modify: must be fully supported.
7598 config_back_initialize( BackendInfo *bi )
7600 ConfigTable *ct = config_back_cf_table;
7604 AttributeDescription *ad = NULL;
7606 static char *controls[] = {
7607 LDAP_CONTROL_MANAGEDSAIT,
7611 /* Make sure we don't exceed the bits reserved for userland */
7612 config_check_userland( CFG_LAST );
7614 bi->bi_controls = controls;
7619 bi->bi_destroy = config_back_destroy;
7621 bi->bi_db_init = config_back_db_init;
7622 bi->bi_db_config = 0;
7623 bi->bi_db_open = config_back_db_open;
7624 bi->bi_db_close = config_back_db_close;
7625 bi->bi_db_destroy = config_back_db_destroy;
7627 bi->bi_op_bind = config_back_bind;
7628 bi->bi_op_unbind = 0;
7629 bi->bi_op_search = config_back_search;
7630 bi->bi_op_compare = 0;
7631 bi->bi_op_modify = config_back_modify;
7632 bi->bi_op_modrdn = config_back_modrdn;
7633 bi->bi_op_add = config_back_add;
7634 bi->bi_op_delete = config_back_delete;
7635 bi->bi_op_abandon = 0;
7637 bi->bi_extended = 0;
7639 bi->bi_chk_referrals = 0;
7641 bi->bi_access_allowed = slap_access_allowed;
7643 bi->bi_connection_init = 0;
7644 bi->bi_connection_destroy = 0;
7646 bi->bi_entry_release_rw = config_entry_release;
7647 bi->bi_entry_get_rw = config_back_entry_get;
7649 bi->bi_tool_entry_open = config_tool_entry_open;
7650 bi->bi_tool_entry_close = config_tool_entry_close;
7651 bi->bi_tool_entry_first = config_tool_entry_first;
7652 bi->bi_tool_entry_first_x = config_tool_entry_first_x;
7653 bi->bi_tool_entry_next = config_tool_entry_next;
7654 bi->bi_tool_entry_get = config_tool_entry_get;
7655 bi->bi_tool_entry_put = config_tool_entry_put;
7658 argv[ 0 ] = "slapd";
7664 for (i=0; OidMacros[i].name; i++ ) {
7665 argv[1] = OidMacros[i].name;
7666 argv[2] = OidMacros[i].oid;
7667 parse_oidm( &ca, 0, NULL );
7670 bi->bi_cf_ocs = cf_ocs;
7672 i = config_register_schema( ct, cf_ocs );
7675 i = slap_str2ad( "olcDatabase", &olcDatabaseDummy[0].ad, &text );
7678 /* setup olcRootPW to be base64-encoded when written in LDIF form;
7679 * basically, we don't care if it fails */
7680 i = slap_str2ad( "olcRootPW", &ad, &text );
7682 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
7683 "warning, unable to get \"olcRootPW\" "
7684 "attribute description: %d: %s\n",
7687 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
7688 ad->ad_type->sat_oid );
7691 /* set up the notable AttributeDescriptions */
7693 for (;ct->name;ct++) {
7694 if (strcmp(ct->name, ads[i].name)) continue;
7695 *ads[i].desc = ct->ad;
7697 if (!ads[i].name) break;