1 /* bconfig.c - the config backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005-2012 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,
208 static OidRec OidMacros[] = {
209 /* OpenLDAProot:1.12.2 */
210 { "OLcfg", "1.3.6.1.4.1.4203.1.12.2" },
211 { "OLcfgAt", "OLcfg:3" },
212 { "OLcfgGlAt", "OLcfgAt:0" },
213 { "OLcfgBkAt", "OLcfgAt:1" },
214 { "OLcfgDbAt", "OLcfgAt:2" },
215 { "OLcfgOvAt", "OLcfgAt:3" },
216 { "OLcfgCtAt", "OLcfgAt:4" }, /* contrib modules */
217 { "OLcfgOc", "OLcfg:4" },
218 { "OLcfgGlOc", "OLcfgOc:0" },
219 { "OLcfgBkOc", "OLcfgOc:1" },
220 { "OLcfgDbOc", "OLcfgOc:2" },
221 { "OLcfgOvOc", "OLcfgOc:3" },
222 { "OLcfgCtOc", "OLcfgOc:4" }, /* contrib modules */
224 /* Syntaxes. We should just start using the standard names and
225 * document that they are predefined and available for users
226 * to reference in their own schema. Defining schema without
227 * OID macros is for masochists...
229 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
230 { "OMsBoolean", "OMsyn:7" },
231 { "OMsDN", "OMsyn:12" },
232 { "OMsDirectoryString", "OMsyn:15" },
233 { "OMsIA5String", "OMsyn:26" },
234 { "OMsInteger", "OMsyn:27" },
235 { "OMsOID", "OMsyn:38" },
236 { "OMsOctetString", "OMsyn:40" },
241 * Backend/Database registry
243 * OLcfg{Bk|Db}{Oc|At}:0 -> common
244 * OLcfg{Bk|Db}{Oc|At}:1 -> back-bdb(/back-hdb)
245 * OLcfg{Bk|Db}{Oc|At}:2 -> back-ldif
246 * OLcfg{Bk|Db}{Oc|At}:3 -> back-ldap/meta
247 * OLcfg{Bk|Db}{Oc|At}:4 -> back-monitor
248 * OLcfg{Bk|Db}{Oc|At}:5 -> back-relay
249 * OLcfg{Bk|Db}{Oc|At}:6 -> back-sql(/back-ndb)
250 * OLcfg{Bk|Db}{Oc|At}:7 -> back-sock
251 * OLcfg{Bk|Db}{Oc|At}:8 -> back-null
252 * OLcfg{Bk|Db}{Oc|At}:9 -> back-passwd
253 * OLcfg{Bk|Db}{Oc|At}:10 -> back-shell
254 * OLcfg{Bk|Db}{Oc|At}:11 -> back-perl
255 * OLcfg{Bk|Db}{Oc|At}:12 -> back-mdb
261 * OLcfgOv{Oc|At}:1 -> syncprov
262 * OLcfgOv{Oc|At}:2 -> pcache
263 * OLcfgOv{Oc|At}:3 -> chain
264 * OLcfgOv{Oc|At}:4 -> accesslog
265 * OLcfgOv{Oc|At}:5 -> valsort
266 * OLcfgOv{Oc|At}:7 -> distproc
267 * OLcfgOv{Oc|At}:8 -> dynlist
268 * OLcfgOv{Oc|At}:9 -> dds
269 * OLcfgOv{Oc|At}:10 -> unique
270 * OLcfgOv{Oc|At}:11 -> refint
271 * OLcfgOv{Oc|At}:12 -> ppolicy
272 * OLcfgOv{Oc|At}:13 -> constraint
273 * OLcfgOv{Oc|At}:14 -> translucent
274 * OLcfgOv{Oc|At}:15 -> auditlog
275 * OLcfgOv{Oc|At}:16 -> rwm
276 * OLcfgOv{Oc|At}:17 -> dyngroup
277 * OLcfgOv{Oc|At}:18 -> memberof
278 * OLcfgOv{Oc|At}:19 -> collect
279 * OLcfgOv{Oc|At}:20 -> retcode
280 * OLcfgOv{Oc|At}:21 -> sssvlv
283 /* alphabetical ordering */
285 static ConfigTable config_back_cf_table[] = {
286 /* This attr is read-only */
287 { "", "", 0, 0, 0, ARG_MAGIC,
288 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
289 "DESC 'File for slapd configuration directives' "
290 "EQUALITY caseIgnoreMatch "
291 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
292 { "", "", 0, 0, 0, ARG_MAGIC,
293 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
294 "DESC 'Directory for slapd configuration backend' "
295 "EQUALITY caseIgnoreMatch "
296 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
297 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
298 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
299 "DESC 'Access Control List' "
300 "EQUALITY caseIgnoreMatch "
301 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
302 { "add_content_acl", NULL, 0, 0, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_ACL_ADD,
303 &config_generic, "( OLcfgGlAt:86 NAME 'olcAddContentAcl' "
304 "DESC 'Check ACLs against content of Add ops' "
305 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
306 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
307 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
308 "DESC 'Allowed set of deprecated features' "
309 "EQUALITY caseIgnoreMatch "
310 "SYNTAX OMsDirectoryString )", NULL, NULL },
311 { "argsfile", "file", 2, 2, 0, ARG_STRING,
312 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
313 "DESC 'File for slapd command line options' "
314 "EQUALITY caseIgnoreMatch "
315 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
316 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
317 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
318 "EQUALITY caseIgnoreMatch "
319 "SYNTAX OMsDirectoryString )", NULL, NULL },
320 { "attribute", "attribute", 2, 0, STRLENOF( "attribute" ),
321 ARG_PAREN|ARG_MAGIC|CFG_ATTR,
322 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
323 "DESC 'OpenLDAP attributeTypes' "
324 "EQUALITY caseIgnoreMatch "
325 "SUBSTR caseIgnoreSubstringsMatch "
326 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
328 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
329 #ifdef SLAP_AUTH_REWRITE
330 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
334 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
335 "EQUALITY caseIgnoreMatch "
336 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
337 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
338 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
339 "EQUALITY caseIgnoreMatch "
340 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
341 { "authz-regexp", "regexp> <DN", 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
342 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
343 "EQUALITY caseIgnoreMatch "
344 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
345 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
346 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
347 "DESC 'A type of backend' "
348 "EQUALITY caseIgnoreMatch "
349 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
351 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
352 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
353 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
354 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
355 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
356 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
357 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
358 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
359 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
360 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
361 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
362 "DESC 'The backend type for a database instance' "
363 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
364 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
365 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
366 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
367 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
368 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
369 "EQUALITY caseIgnoreMatch "
370 "SYNTAX OMsDirectoryString )", NULL, NULL },
371 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
372 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
373 "DESC 'OpenLDAP DIT content rules' "
374 "EQUALITY caseIgnoreMatch "
375 "SUBSTR caseIgnoreSubstringsMatch "
376 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
378 { "extra_attrs", "attrlist", 2, 2, 0, ARG_DB|ARG_MAGIC,
379 &config_extra_attrs, "( OLcfgDbAt:0.20 NAME 'olcExtraAttrs' "
380 "EQUALITY caseIgnoreMatch "
381 "SYNTAX OMsDirectoryString )", NULL, NULL },
382 { "gentlehup", "on|off", 2, 2, 0,
384 ARG_ON_OFF, &global_gentlehup,
388 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
389 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
390 { "hidden", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_HIDDEN,
391 &config_generic, "( OLcfgDbAt:0.17 NAME 'olcHidden' "
392 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
393 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
394 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
395 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
396 { "include", "file", 2, 2, 0, ARG_MAGIC,
397 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
398 "SUP labeledURI )", NULL, NULL },
399 { "index_hash64", "on|off", 2, 2, 0, ARG_ON_OFF|ARG_MAGIC|CFG_IX_HASH64,
400 &config_generic, "( OLcfgGlAt:94 NAME 'olcIndexHash64' "
401 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
402 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
403 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
404 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
405 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
406 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
407 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
408 { "index_substr_any_len", "len", 2, 2, 0, ARG_UINT|ARG_NONZERO,
409 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
410 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
411 { "index_substr_any_step", "step", 2, 2, 0, ARG_UINT|ARG_NONZERO,
412 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
413 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
414 { "index_intlen", "len", 2, 2, 0, ARG_UINT|ARG_MAGIC|CFG_IX_INTLEN,
415 &config_generic, "( OLcfgGlAt:84 NAME 'olcIndexIntLen' "
416 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
417 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
418 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
419 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
420 { "ldapsyntax", "syntax", 2, 0, 0,
421 ARG_PAREN|ARG_MAGIC|CFG_SYNTAX,
422 &config_generic, "( OLcfgGlAt:85 NAME 'olcLdapSyntaxes' "
423 "DESC 'OpenLDAP ldapSyntax' "
424 "EQUALITY caseIgnoreMatch "
425 "SUBSTR caseIgnoreSubstringsMatch "
426 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
428 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
429 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
430 "EQUALITY caseIgnoreMatch "
431 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
432 { "listener-threads", "count", 2, 0, 0,
436 ARG_UINT|ARG_MAGIC|CFG_LTHREADS, &config_generic,
438 "( OLcfgGlAt:93 NAME 'olcListenerThreads' "
439 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
440 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
441 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
442 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
443 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
444 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
445 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
446 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
447 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
448 "EQUALITY caseIgnoreMatch "
449 "SYNTAX OMsDirectoryString )", NULL, NULL },
450 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
451 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
452 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
453 { "mirrormode", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_MIRRORMODE,
454 &config_generic, "( OLcfgDbAt:0.16 NAME 'olcMirrorMode' "
455 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
456 { "moduleload", "file", 2, 0, 0,
458 ARG_MAGIC|CFG_MODLOAD|ARG_NO_DELETE, &config_generic,
462 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
463 "EQUALITY caseIgnoreMatch "
464 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
465 { "modulepath", "path", 2, 2, 0,
467 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
471 "( OLcfgGlAt:31 NAME 'olcModulePath' "
472 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
473 { "monitoring", "TRUE|FALSE", 2, 2, 0,
474 ARG_MAGIC|CFG_MONITORING|ARG_DB|ARG_ON_OFF, &config_generic,
475 "( OLcfgDbAt:0.18 NAME 'olcMonitoring' "
476 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
477 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
478 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
479 "DESC 'OpenLDAP object classes' "
480 "EQUALITY caseIgnoreMatch "
481 "SUBSTR caseIgnoreSubstringsMatch "
482 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
484 { "objectidentifier", "name> <oid", 3, 3, 0, ARG_MAGIC|CFG_OID,
485 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
486 "EQUALITY caseIgnoreMatch "
487 "SUBSTR caseIgnoreSubstringsMatch "
488 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
489 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
490 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
491 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
492 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
493 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
494 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
495 { "password-hash", "hash", 2, 0, 0, ARG_MAGIC,
496 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
497 "EQUALITY caseIgnoreMatch "
498 "SYNTAX OMsDirectoryString )", NULL, NULL },
499 { "pidfile", "file", 2, 2, 0, ARG_STRING,
500 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
501 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
502 { "plugin", NULL, 0, 0, 0,
504 ARG_MAGIC|CFG_PLUGIN, &config_generic,
508 "( OLcfgGlAt:38 NAME 'olcPlugin' "
509 "EQUALITY caseIgnoreMatch "
510 "SYNTAX OMsDirectoryString )", NULL, NULL },
511 { "pluginlog", "filename", 2, 2, 0,
513 ARG_STRING, &slapi_log_file,
517 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
518 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
519 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
520 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
521 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
522 { "referral", "url", 2, 2, 0, ARG_MAGIC,
523 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
524 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
525 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
526 &config_obsolete, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
527 "EQUALITY caseIgnoreMatch "
528 "SUP labeledURI X-ORDERED 'VALUES' )", NULL, NULL },
529 { "replica-argsfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
530 &config_obsolete, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
531 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
532 { "replica-pidfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
533 &config_obsolete, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
534 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
535 { "replicationInterval", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
536 &config_obsolete, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
537 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
538 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC,
539 &config_obsolete, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
540 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
541 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
542 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
543 "EQUALITY caseIgnoreMatch "
544 "SYNTAX OMsDirectoryString )", NULL, NULL },
545 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
546 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
547 "EQUALITY caseIgnoreMatch "
548 "SYNTAX OMsDirectoryString )", NULL, NULL },
549 { "reverse-lookup", "on|off", 2, 2, 0,
550 #ifdef SLAPD_RLOOKUPS
551 ARG_ON_OFF, &use_reverse_lookup,
555 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
556 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
557 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
558 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
559 "EQUALITY distinguishedNameMatch "
560 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
561 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
562 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
563 "EQUALITY caseIgnoreMatch "
564 "SYNTAX OMsDirectoryString )", NULL, NULL },
565 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
566 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
567 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
568 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
569 &config_generic, NULL, NULL, NULL },
570 { "sasl-auxprops", NULL, 2, 0, 0,
571 #ifdef HAVE_CYRUS_SASL
572 ARG_STRING|ARG_UNIQUE, &slap_sasl_auxprops,
576 "( OLcfgGlAt:89 NAME 'olcSaslAuxprops' "
577 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
578 { "sasl-auxprops-dontusecopy", NULL, 2, 0, 0,
579 #if defined(HAVE_CYRUS_SASL) && defined(SLAP_AUXPROP_DONTUSECOPY)
580 ARG_MAGIC|CFG_AZDUC, &config_generic,
584 "( OLcfgGlAt:91 NAME 'olcSaslAuxpropsDontUseCopy' "
585 "EQUALITY caseIgnoreMatch "
586 "SYNTAX OMsDirectoryString )", NULL, NULL },
587 { "sasl-auxprops-dontusecopy-ignore", "true|FALSE", 2, 0, 0,
588 #if defined(HAVE_CYRUS_SASL) && defined(SLAP_AUXPROP_DONTUSECOPY)
589 ARG_ON_OFF|CFG_AZDUC_IGNORE, &slap_dontUseCopy_ignore,
593 "( OLcfgGlAt:92 NAME 'olcSaslAuxpropsDontUseCopyIgnore' "
594 "EQUALITY booleanMatch "
595 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
596 { "sasl-host", "host", 2, 2, 0,
597 #ifdef HAVE_CYRUS_SASL
598 ARG_STRING|ARG_UNIQUE, &sasl_host,
602 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
603 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
604 { "sasl-realm", "realm", 2, 2, 0,
605 #ifdef HAVE_CYRUS_SASL
606 ARG_STRING|ARG_UNIQUE, &global_realm,
610 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
611 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
612 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
613 &config_generic, NULL, NULL, NULL },
614 { "sasl-secprops", "properties", 2, 2, 0,
615 #ifdef HAVE_CYRUS_SASL
616 ARG_MAGIC|CFG_SASLSECP, &config_generic,
620 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
621 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
622 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
623 &config_generic, NULL, NULL, NULL },
624 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
625 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
626 "EQUALITY distinguishedNameMatch "
627 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
628 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
629 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
630 "EQUALITY caseIgnoreMatch "
631 "SYNTAX OMsDirectoryString )", NULL, NULL },
632 { "serverID", "number> <[URI]", 2, 3, 0, ARG_MAGIC|CFG_SERVERID,
633 &config_generic, "( OLcfgGlAt:81 NAME 'olcServerID' "
634 "EQUALITY caseIgnoreMatch "
635 "SYNTAX OMsDirectoryString )", NULL, NULL },
636 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
637 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
638 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
639 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
640 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
641 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
642 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
643 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
644 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
645 { "sortvals", "attr", 2, 0, 0, ARG_MAGIC|CFG_SORTVALS,
646 &config_generic, "( OLcfgGlAt:83 NAME 'olcSortVals' "
647 "DESC 'Attributes whose values will always be sorted' "
648 "EQUALITY caseIgnoreMatch "
649 "SYNTAX OMsDirectoryString )", NULL, NULL },
650 { "subordinate", "[advertise]", 1, 2, 0, ARG_DB|ARG_MAGIC,
651 &config_subordinate, "( OLcfgDbAt:0.15 NAME 'olcSubordinate' "
652 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
653 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
654 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
655 "EQUALITY distinguishedNameMatch "
656 "SYNTAX OMsDN )", NULL, NULL },
657 { "sync_use_subentry", NULL, 0, 0, 0, ARG_ON_OFF|ARG_DB|ARG_MAGIC|CFG_SYNC_SUBENTRY,
658 &config_generic, "( OLcfgDbAt:0.19 NAME 'olcSyncUseSubentry' "
659 "DESC 'Store sync context in a subentry' "
660 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
661 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
662 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
663 "EQUALITY caseIgnoreMatch "
664 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
665 { "tcp-buffer", "[listener=<listener>] [{read|write}=]size", 0, 0, 0,
666 #ifndef LDAP_TCP_BUFFER
668 #else /* LDAP_TCP_BUFFER */
669 ARG_MAGIC, &config_tcp_buffer,
670 #endif /* LDAP_TCP_BUFFER */
671 "( OLcfgGlAt:90 NAME 'olcTCPBuffer' "
672 "DESC 'Custom TCP buffer size' "
673 "SYNTAX OMsDirectoryString )", NULL, NULL },
674 { "threads", "count", 2, 2, 0,
678 ARG_INT|ARG_MAGIC|CFG_THREADS, &config_generic,
680 "( OLcfgGlAt:66 NAME 'olcThreads' "
681 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
682 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
683 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
684 "SYNTAX OMsDirectoryString )", NULL, NULL },
685 { "TLSCACertificateFile", NULL, 2, 2, 0,
687 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
691 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
692 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
693 { "TLSCACertificatePath", NULL, 2, 2, 0,
695 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
699 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
700 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
701 { "TLSCertificateFile", NULL, 2, 2, 0,
703 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
707 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
708 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
709 { "TLSCertificateKeyFile", NULL, 2, 2, 0,
711 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
715 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
716 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
717 { "TLSCipherSuite", NULL, 2, 2, 0,
719 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
723 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
724 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
725 { "TLSCRLCheck", NULL, 2, 2, 0,
726 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
727 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
731 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
732 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
733 { "TLSCRLFile", NULL, 2, 2, 0,
734 #if defined(HAVE_GNUTLS)
735 CFG_TLS_CRL_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
739 "( OLcfgGlAt:82 NAME 'olcTLSCRLFile' "
740 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
741 { "TLSRandFile", NULL, 2, 2, 0,
743 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
747 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
748 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
749 { "TLSVerifyClient", NULL, 2, 2, 0,
751 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
755 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
756 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
757 { "TLSDHParamFile", NULL, 2, 2, 0,
759 CFG_TLS_DH_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
763 "( OLcfgGlAt:77 NAME 'olcTLSDHParamFile' "
764 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
765 { "TLSProtocolMin", NULL, 2, 2, 0,
767 CFG_TLS_PROTOCOL_MIN|ARG_STRING|ARG_MAGIC, &config_tls_config,
771 "( OLcfgGlAt:87 NAME 'olcTLSProtocolMin' "
772 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
773 { "tool-threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_TTHREADS,
774 &config_generic, "( OLcfgGlAt:80 NAME 'olcToolThreads' "
775 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
776 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
777 NULL, NULL, NULL, NULL },
778 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
779 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
780 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
781 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
782 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
783 "EQUALITY caseIgnoreMatch "
784 "SUP labeledURI )", NULL, NULL },
785 { "writetimeout", "timeout", 2, 2, 0, ARG_INT,
786 &global_writetimeout, "( OLcfgGlAt:88 NAME 'olcWriteTimeout' "
787 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
788 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
789 NULL, NULL, NULL, NULL }
792 /* Need to no-op this keyword for dynamic config */
793 ConfigTable olcDatabaseDummy[] = {
794 { "", "", 0, 0, 0, ARG_IGNORED,
795 NULL, "( OLcfgGlAt:13 NAME 'olcDatabase' "
796 "DESC 'The backend type for a database instance' "
797 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
798 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
801 /* Routines to check if a child can be added to this type */
802 static ConfigLDAPadd cfAddSchema, cfAddInclude, cfAddDatabase,
803 cfAddBackend, cfAddModule, cfAddOverlay;
805 /* NOTE: be careful when defining array members
806 * that can be conditionally compiled */
807 #define CFOC_GLOBAL cf_ocs[1]
808 #define CFOC_SCHEMA cf_ocs[2]
809 #define CFOC_BACKEND cf_ocs[3]
810 #define CFOC_DATABASE cf_ocs[4]
811 #define CFOC_OVERLAY cf_ocs[5]
812 #define CFOC_INCLUDE cf_ocs[6]
813 #define CFOC_FRONTEND cf_ocs[7]
815 #define CFOC_MODULE cf_ocs[8]
816 #endif /* SLAPD_MODULES */
818 static ConfigOCs cf_ocs[] = {
821 "DESC 'OpenLDAP configuration object' "
822 "ABSTRACT SUP top )", Cft_Abstract, NULL },
825 "DESC 'OpenLDAP Global configuration options' "
826 "SUP olcConfig STRUCTURAL "
827 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
828 "olcAttributeOptions $ olcAuthIDRewrite $ "
829 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
830 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
831 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
832 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
833 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcIndexHash64 $ "
834 "olcIndexIntLen $ olcLocalSSF $ olcLogFile $ olcLogLevel $ "
835 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
836 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
837 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
839 "olcSaslAuxprops $ olcSaslAuxpropsDontUseCopy $ olcSaslAuxpropsDontUseCopyIgnore $ "
840 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
841 "olcSecurity $ olcServerID $ olcSizeLimit $ "
842 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ "
844 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
845 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
846 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
847 "olcTLSRandFile $ olcTLSVerifyClient $ olcTLSDHParamFile $ "
848 "olcTLSCRLFile $ olcToolThreads $ olcWriteTimeout $ "
849 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
850 "olcDitContentRules $ olcLdapSyntaxes ) )", Cft_Global },
852 "NAME 'olcSchemaConfig' "
853 "DESC 'OpenLDAP schema object' "
854 "SUP olcConfig STRUCTURAL "
855 "MAY ( cn $ olcObjectIdentifier $ olcLdapSyntaxes $ "
856 "olcAttributeTypes $ olcObjectClasses $ olcDitContentRules ) )",
857 Cft_Schema, NULL, cfAddSchema },
859 "NAME 'olcBackendConfig' "
860 "DESC 'OpenLDAP Backend-specific options' "
861 "SUP olcConfig STRUCTURAL "
862 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
864 "NAME 'olcDatabaseConfig' "
865 "DESC 'OpenLDAP Database-specific options' "
866 "SUP olcConfig STRUCTURAL "
868 "MAY ( olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
869 "olcAddContentAcl $ olcLastMod $ olcLimits $ "
870 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
871 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
872 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
873 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncUseSubentry $ olcSyncrepl $ "
874 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef $ olcMirrorMode $ "
875 "olcMonitoring $ olcExtraAttrs ) )",
876 Cft_Database, NULL, cfAddDatabase },
878 "NAME 'olcOverlayConfig' "
879 "DESC 'OpenLDAP Overlay-specific options' "
880 "SUP olcConfig STRUCTURAL "
881 "MUST olcOverlay )", Cft_Overlay, NULL, cfAddOverlay },
883 "NAME 'olcIncludeFile' "
884 "DESC 'OpenLDAP configuration include file' "
885 "SUP olcConfig STRUCTURAL "
887 "MAY ( cn $ olcRootDSE ) )",
888 /* Used to be Cft_Include, that def has been removed */
889 Cft_Abstract, NULL, cfAddInclude },
890 /* This should be STRUCTURAL like all the other database classes, but
891 * that would mean inheriting all of the olcDatabaseConfig attributes,
892 * which causes them to be merged twice in config_build_entry.
895 "NAME 'olcFrontendConfig' "
896 "DESC 'OpenLDAP frontend configuration' "
898 "MAY ( olcDefaultSearchBase $ olcPasswordHash $ olcSortVals ) )",
899 Cft_Database, NULL, NULL },
902 "NAME 'olcModuleList' "
903 "DESC 'OpenLDAP dynamic module info' "
904 "SUP olcConfig STRUCTURAL "
905 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
906 Cft_Module, NULL, cfAddModule },
911 typedef struct ServerID {
912 struct ServerID *si_next;
913 struct berval si_url;
917 static ServerID *sid_list;
918 static ServerID *sid_set;
920 typedef struct voidList {
921 struct voidList *vl_next;
925 typedef struct ADlist {
926 struct ADlist *al_next;
927 AttributeDescription *al_desc;
930 static ADlist *sortVals;
933 config_generic(ConfigArgs *c) {
936 if ( c->op == SLAP_CONFIG_EMIT ) {
940 c->value_int = ldap_pvt_thread_get_concurrency();
943 c->value_int = connection_pool_max;
946 c->value_int = slap_tool_thread_max;
949 c->value_uint = slapd_daemon_threads;
953 c->value_string = ch_strdup( passwd_salt );
958 if ( c->be->be_limits ) {
962 for ( i=0; c->be->be_limits[i]; i++ ) {
963 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
964 if ( bv.bv_len >= sizeof( buf ) ) {
965 ber_bvarray_free_x( c->rvalue_vals, NULL );
966 c->rvalue_vals = NULL;
970 bv.bv_val = buf + bv.bv_len;
971 limits_unparse( c->be->be_limits[i], &bv,
972 sizeof( buf ) - ( bv.bv_val - buf ) );
973 bv.bv_len += bv.bv_val - buf;
975 value_add_one( &c->rvalue_vals, &bv );
978 if ( !c->rvalue_vals ) rc = 1;
981 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_READONLY);
984 c->value_string = ch_strdup( slap_sasl_getpolicy());
987 slap_sasl_regexp_unparse( &c->rvalue_vals );
988 if ( !c->rvalue_vals ) rc = 1;
990 #ifdef HAVE_CYRUS_SASL
991 #ifdef SLAP_AUXPROP_DONTUSECOPY
993 static int duc_done = 0;
995 /* take the opportunity to initialize with known values */
997 struct berval duc[] = { BER_BVC("cmusaslsecretOTP"), BER_BVNULL };
1000 for ( i = 0; !BER_BVISNULL( &duc[ i ] ); i++ ) {
1001 const char *text = NULL;
1002 AttributeDescription *ad = NULL;
1004 if ( slap_bv2ad( &duc[ i ], &ad, &text ) == LDAP_SUCCESS ) {
1006 if ( slap_dontUseCopy_propnames ) {
1009 for ( j = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ j ] ); j++ ) {
1010 if ( bvmatch( &slap_dontUseCopy_propnames[ j ], &ad->ad_cname ) ) {
1017 value_add_one( &slap_dontUseCopy_propnames, &ad->ad_cname );
1025 if ( slap_dontUseCopy_propnames != NULL ) {
1026 ber_bvarray_dup_x( &c->rvalue_vals, slap_dontUseCopy_propnames, NULL );
1031 #endif /* SLAP_AUXPROP_DONTUSECOPY */
1032 case CFG_SASLSECP: {
1033 struct berval bv = BER_BVNULL;
1034 slap_sasl_secprops_unparse( &bv );
1035 if ( !BER_BVISNULL( &bv )) {
1036 ber_bvarray_add( &c->rvalue_vals, &bv );
1044 c->value_int = c->be->be_max_deref_depth;
1047 if ( SLAP_DBHIDDEN( c->be )) {
1054 ConfigFile *cf = c->ca_private;
1056 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1057 else if ( cf->c_om_head )
1058 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
1060 if ( !c->rvalue_vals )
1065 ad_unparse_options( &c->rvalue_vals );
1068 ConfigFile *cf = c->ca_private;
1070 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1071 else if ( cf->c_oc_head )
1072 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
1074 if ( !c->rvalue_vals )
1079 ConfigFile *cf = c->ca_private;
1081 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1082 else if ( cf->c_at_head )
1083 at_unparse( &c->rvalue_vals, cf->c_at_head,
1085 if ( !c->rvalue_vals )
1090 ConfigFile *cf = c->ca_private;
1092 syn_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1093 else if ( cf->c_syn_head )
1094 syn_unparse( &c->rvalue_vals, cf->c_syn_head,
1095 cf->c_syn_tail, 0 );
1096 if ( !c->rvalue_vals )
1101 ConfigFile *cf = c->ca_private;
1103 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1104 else if ( cf->c_cr_head )
1105 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
1107 if ( !c->rvalue_vals )
1114 char *src, *dst, ibuf[11];
1115 struct berval bv, abv;
1116 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
1117 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1118 if ( abv.bv_len >= sizeof( ibuf ) ) {
1119 ber_bvarray_free_x( c->rvalue_vals, NULL );
1120 c->rvalue_vals = NULL;
1124 acl_unparse( a, &bv );
1125 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
1126 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
1127 /* Turn TAB / EOL into plain space */
1128 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
1129 if (isspace((unsigned char)*src)) *dst++ = ' ';
1133 if (dst[-1] == ' ') {
1137 abv.bv_len = dst - abv.bv_val;
1138 ber_bvarray_add( &c->rvalue_vals, &abv );
1144 c->value_int = (SLAP_DBACL_ADD(c->be) != 0);
1147 ConfigFile *cf = c->ca_private;
1148 if ( cf->c_dseFiles ) {
1149 value_add( &c->rvalue_vals, cf->c_dseFiles );
1160 for ( si = sid_list; si; si=si->si_next ) {
1161 assert( si->si_num >= 0 && si->si_num <= SLAP_SYNC_SID_MAX );
1162 if ( !BER_BVISEMPTY( &si->si_url )) {
1163 bv.bv_len = si->si_url.bv_len + 6;
1164 bv.bv_val = ch_malloc( bv.bv_len );
1165 bv.bv_len = sprintf( bv.bv_val, "%d %s", si->si_num,
1166 si->si_url.bv_val );
1167 ber_bvarray_add( &c->rvalue_vals, &bv );
1171 bv.bv_len = sprintf( buf, "%d", si->si_num );
1172 value_add_one( &c->rvalue_vals, &bv );
1181 c->value_string = ch_strdup( logfileName );
1186 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1188 case CFG_SYNC_SUBENTRY:
1189 c->value_int = (SLAP_SYNC_SUBENTRY(c->be) != 0);
1191 case CFG_MIRRORMODE:
1192 if ( SLAP_SHADOW(c->be))
1193 c->value_int = (SLAP_MULTIMASTER(c->be) != 0);
1197 case CFG_MONITORING:
1198 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
1200 case CFG_SSTR_IF_MAX:
1201 c->value_uint = index_substr_if_maxlen;
1203 case CFG_SSTR_IF_MIN:
1204 c->value_uint = index_substr_if_minlen;
1207 c->value_int = slap_hash64( -1 );
1210 c->value_int = index_intlen;
1212 case CFG_SORTVALS: {
1215 for ( sv = sortVals; sv; sv = sv->al_next ) {
1216 value_add_one( &c->rvalue_vals, &sv->al_desc->ad_cname );
1220 #ifdef SLAPD_MODULES
1222 ModPaths *mp = c->ca_private;
1225 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
1228 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
1229 SLAP_X_ORDERED_FMT "%s", i,
1230 mp->mp_loads[i].bv_val );
1231 if ( bv.bv_len >= sizeof( c->log ) ) {
1232 ber_bvarray_free_x( c->rvalue_vals, NULL );
1233 c->rvalue_vals = NULL;
1236 value_add_one( &c->rvalue_vals, &bv );
1240 rc = c->rvalue_vals ? 0 : 1;
1244 ModPaths *mp = c->ca_private;
1245 if ( !BER_BVISNULL( &mp->mp_path ))
1246 value_add_one( &c->rvalue_vals, &mp->mp_path );
1248 rc = c->rvalue_vals ? 0 : 1;
1254 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1255 if ( !c->rvalue_vals ) rc = 1;
1258 #ifdef SLAP_AUTH_REWRITE
1260 if ( authz_rewrites ) {
1261 struct berval bv, idx;
1266 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1267 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1268 if ( idx.bv_len >= sizeof( ibuf ) ) {
1269 ber_bvarray_free_x( c->rvalue_vals, NULL );
1270 c->rvalue_vals = NULL;
1273 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1274 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1275 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1276 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1277 authz_rewrites[i].bv_val,
1278 authz_rewrites[i].bv_len + 1 );
1279 ber_bvarray_add( &c->rvalue_vals, &bv );
1282 if ( !c->rvalue_vals ) rc = 1;
1289 } else if ( c->op == LDAP_MOD_DELETE ) {
1292 /* single-valued attrs, no-ops */
1301 case CFG_MONITORING:
1303 case CFG_SSTR_IF_MAX:
1304 case CFG_SSTR_IF_MIN:
1306 case CFG_SYNC_SUBENTRY:
1309 /* no-ops, requires slapd restart */
1314 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1317 case CFG_MIRRORMODE:
1318 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MULTI_SHADOW;
1319 if(SLAP_SHADOW(c->be))
1320 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1323 #if defined(HAVE_CYRUS_SASL) && defined(SLAP_AUXPROP_DONTUSECOPY)
1325 if ( c->valx < 0 ) {
1326 if ( slap_dontUseCopy_propnames != NULL ) {
1327 ber_bvarray_free( slap_dontUseCopy_propnames );
1328 slap_dontUseCopy_propnames = NULL;
1334 if ( slap_dontUseCopy_propnames == NULL ) {
1339 for ( i = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ i ] ) && i < c->valx; i++ );
1340 if ( i < c->valx ) {
1344 ber_memfree( slap_dontUseCopy_propnames[ i ].bv_val );
1345 for ( ; !BER_BVISNULL( &slap_dontUseCopy_propnames[ i + 1 ] ); i++ ) {
1346 slap_dontUseCopy_propnames[ i ] = slap_dontUseCopy_propnames[ i + 1 ];
1348 BER_BVZERO( &slap_dontUseCopy_propnames[ i ] );
1351 #endif /* SLAP_AUXPROP_DONTUSECOPY */
1353 ch_free( passwd_salt );
1358 ch_free( logfileName );
1366 case CFG_SERVERID: {
1367 ServerID *si, **sip;
1369 for ( i=0, si = sid_list, sip = &sid_list;
1370 si; si = *sip, i++ ) {
1371 if ( c->valx == -1 || i == c->valx ) {
1373 if ( sid_set == si )
1385 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1393 index_intlen = SLAP_INDEX_INTLEN_DEFAULT;
1394 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1395 SLAP_INDEX_INTLEN_DEFAULT );
1399 if ( c->valx < 0 ) {
1400 acl_destroy( c->be->be_acl );
1401 c->be->be_acl = NULL;
1404 AccessControl **prev, *a;
1406 for (i=0, prev = &c->be->be_acl; i < c->valx;
1409 prev = &a->acl_next;
1412 *prev = a->acl_next;
1415 if ( SLAP_CONFIG( c->be ) && !c->be->be_acl ) {
1416 Debug( LDAP_DEBUG_CONFIG, "config_generic (CFG_ACL): "
1417 "Last explicit ACL for back-config removed. "
1418 "Using hardcoded default\n", 0, 0, 0 );
1419 c->be->be_acl = defacl_parsed;
1425 /* Can be NULL when undoing a failed add */
1426 if ( c->ca_entry ) {
1427 ce = c->ca_entry->e_private;
1428 /* can't modify the hardcoded schema */
1429 if ( ce->ce_parent->ce_type == Cft_Global )
1433 cfn = c->ca_private;
1434 if ( c->valx < 0 ) {
1437 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1439 if ( oc == cfn->c_oc_tail )
1442 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1444 ObjectClass *oc, *prev = NULL;
1446 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1451 if ( cfn->c_oc_tail == oc ) {
1452 cfn->c_oc_tail = prev;
1454 if ( cfn->c_oc_head == oc ) {
1456 cfn->c_oc_head = oc;
1463 /* Can be NULL when undoing a failed add */
1464 if ( c->ca_entry ) {
1465 ce = c->ca_entry->e_private;
1466 /* can't modify the hardcoded schema */
1467 if ( ce->ce_parent->ce_type == Cft_Global )
1471 cfn = c->ca_private;
1472 if ( c->valx < 0 ) {
1475 for( at = cfn->c_at_head; at; at_next( &at )) {
1477 if ( at == cfn->c_at_tail )
1480 cfn->c_at_head = cfn->c_at_tail = NULL;
1482 AttributeType *at, *prev = NULL;
1484 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1489 if ( cfn->c_at_tail == at ) {
1490 cfn->c_at_tail = prev;
1492 if ( cfn->c_at_head == at ) {
1494 cfn->c_at_head = at;
1501 /* Can be NULL when undoing a failed add */
1502 if ( c->ca_entry ) {
1503 ce = c->ca_entry->e_private;
1504 /* can't modify the hardcoded schema */
1505 if ( ce->ce_parent->ce_type == Cft_Global )
1509 cfn = c->ca_private;
1510 if ( c->valx < 0 ) {
1513 for( syn = cfn->c_syn_head; syn; syn_next( &syn )) {
1515 if ( syn == cfn->c_syn_tail )
1518 cfn->c_syn_head = cfn->c_syn_tail = NULL;
1520 Syntax *syn, *prev = NULL;
1522 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++) {
1527 if ( cfn->c_syn_tail == syn ) {
1528 cfn->c_syn_tail = prev;
1530 if ( cfn->c_syn_head == syn ) {
1532 cfn->c_syn_head = syn;
1537 if ( c->valx < 0 ) {
1539 for ( sv = sortVals; sv; sv = sortVals ) {
1540 sortVals = sv->al_next;
1541 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1548 for ( prev = &sortVals, sv = sortVals; i < c->valx; i++ ) {
1549 prev = &sv->al_next;
1552 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1553 *prev = sv->al_next;
1559 /* FIXME: there is no limits_free function */
1560 if ( c->valx < 0 ) {
1561 limits_destroy( c->be->be_limits );
1562 c->be->be_limits = NULL;
1567 if ( c->be->be_limits ) {
1568 for ( num = 0; c->be->be_limits[ num ]; num++ )
1572 if ( c->valx >= num ) {
1577 limits_destroy( c->be->be_limits );
1578 c->be->be_limits = NULL;
1581 limits_free_one( c->be->be_limits[ c->valx ] );
1583 for ( cnt = c->valx; cnt < num; cnt++ ) {
1584 c->be->be_limits[ cnt ] = c->be->be_limits[ cnt + 1 ];
1591 /* FIXME: there is no ad_option_free function */
1593 /* FIXME: there is no way to remove attributes added by
1607 if(!(c->bi = backend_info(c->argv[1]))) {
1608 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1609 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1610 c->log, c->cr_msg, c->argv[1] );
1617 /* NOTE: config is always the first backend!
1619 if ( !strcasecmp( c->argv[1], "config" )) {
1620 c->be = LDAP_STAILQ_FIRST(&backendDB);
1621 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1624 c->be = backend_db_init(c->argv[1], NULL, c->valx, &c->reply);
1626 if ( c->cr_msg[0] == 0 )
1627 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1628 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n", c->log, c->cr_msg, c->argv[1] );
1635 ldap_pvt_thread_set_concurrency(c->value_int);
1639 if ( c->value_int < 2 ) {
1640 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1641 "threads=%d smaller than minimum value 2",
1643 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1644 c->log, c->cr_msg, 0 );
1647 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1648 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1649 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1650 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1651 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1652 c->log, c->cr_msg, 0 );
1654 if ( slapMode & SLAP_SERVER_MODE )
1655 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1656 connection_pool_max = c->value_int; /* save for reference */
1660 if ( slapMode & SLAP_TOOL_MODE )
1661 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1662 slap_tool_thread_max = c->value_int; /* save for reference */
1667 /* use a power of two */
1668 while (c->value_uint > 1) {
1669 c->value_uint >>= 1;
1673 slapd_daemon_mask = mask;
1674 slapd_daemon_threads = mask+1;
1679 if ( passwd_salt ) ch_free( passwd_salt );
1680 passwd_salt = c->value_string;
1681 lutil_salt_format(passwd_salt);
1685 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1691 c->be->be_restrictops |= SLAP_RESTRICT_READONLY;
1693 c->be->be_restrictops &= ~SLAP_RESTRICT_READONLY;
1697 ch_free(c->value_string);
1698 if (slap_sasl_setpolicy( c->argv[1] )) {
1699 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
1700 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1701 c->log, c->cr_msg, c->argv[1] );
1707 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1711 #ifdef HAVE_CYRUS_SASL
1712 #ifdef SLAP_AUXPROP_DONTUSECOPY
1716 for ( arg = 1; arg < c->argc; arg++ ) {
1717 int duplicate = 0, err;
1718 AttributeDescription *ad = NULL;
1719 const char *text = NULL;
1721 err = slap_str2ad( c->argv[ arg ], &ad, &text );
1722 if ( err != LDAP_SUCCESS ) {
1723 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s>: attr #%d (\"%s\") unknown (err=%d \"%s\"; ignored)",
1724 c->argv[0], arg, c->argv[ arg ], err, text );
1725 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1726 c->log, c->cr_msg, 0 );
1729 if ( slap_dontUseCopy_propnames != NULL ) {
1730 for ( cnt = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ cnt ] ); cnt++ ) {
1731 if ( bvmatch( &slap_dontUseCopy_propnames[ cnt ], &ad->ad_cname ) ) {
1739 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s>: attr #%d (\"%s\") already defined (ignored)",
1740 c->argv[0], arg, ad->ad_cname.bv_val);
1741 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1742 c->log, c->cr_msg, 0 );
1746 value_add_one( &slap_dontUseCopy_propnames, &ad->ad_cname );
1751 #endif /* SLAP_AUXPROP_DONTUSECOPY */
1755 char *txt = slap_sasl_secprops( c->argv[1] );
1757 snprintf( c->cr_msg, sizeof(c->cr_msg), "<%s> %s",
1759 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0 );
1767 c->be->be_max_deref_depth = c->value_int;
1773 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1774 cfn = c->ca_private;
1775 if(parse_oidm(c, 1, &om))
1777 if (!cfn->c_om_head) cfn->c_om_head = om;
1778 cfn->c_om_tail = om;
1783 ObjectClass *oc, *prev;
1785 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1786 cfn = c->ca_private;
1787 if ( c->valx < 0 ) {
1788 prev = cfn->c_oc_tail;
1791 /* If adding anything after the first, prev is easy */
1794 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
1796 if ( !oc_next( &oc ))
1800 /* If adding the first, and head exists, find its prev */
1801 if (cfn->c_oc_head) {
1802 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
1807 /* else prev is NULL, append to end of global list */
1809 if(parse_oc(c, &oc, prev)) return(1);
1810 if (!cfn->c_oc_head || !c->valx) cfn->c_oc_head = oc;
1811 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
1816 AttributeType *at, *prev;
1818 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1819 cfn = c->ca_private;
1820 if ( c->valx < 0 ) {
1821 prev = cfn->c_at_tail;
1824 /* If adding anything after the first, prev is easy */
1827 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
1829 if ( !at_next( &at ))
1833 /* If adding the first, and head exists, find its prev */
1834 if (cfn->c_at_head) {
1835 for ( at_start( &at ); at != cfn->c_at_head; ) {
1840 /* else prev is NULL, append to end of global list */
1842 if(parse_at(c, &at, prev)) return(1);
1843 if (!cfn->c_at_head || !c->valx) cfn->c_at_head = at;
1844 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
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_syn_tail;
1857 /* If adding anything after the first, prev is easy */
1860 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++ ) {
1862 if ( !syn_next( &syn ))
1866 /* If adding the first, and head exists, find its prev */
1867 if (cfn->c_syn_head) {
1868 for ( syn_start( &syn ); syn != cfn->c_syn_head; ) {
1873 /* else prev is NULL, append to end of global list */
1875 if ( parse_syn( c, &syn, prev ) ) return(1);
1876 if ( !cfn->c_syn_head || !c->valx ) cfn->c_syn_head = syn;
1877 if ( cfn->c_syn_tail == prev ) cfn->c_syn_tail = syn;
1884 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1885 cfn = c->ca_private;
1886 if(parse_cr(c, &cr)) return(1);
1887 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1888 cfn->c_cr_tail = cr;
1893 ad_define_option(NULL, NULL, 0);
1894 for(i = 1; i < c->argc; i++)
1895 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1900 if ( slap_hash64( c->value_int != 0 ))
1905 if ( c->value_int < SLAP_INDEX_INTLEN_DEFAULT )
1906 c->value_int = SLAP_INDEX_INTLEN_DEFAULT;
1907 else if ( c->value_int > 255 )
1909 index_intlen = c->value_int;
1910 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1914 case CFG_SORTVALS: {
1915 ADlist *svnew = NULL, *svtail, *sv;
1917 for ( i = 1; i < c->argc; i++ ) {
1918 AttributeDescription *ad = NULL;
1922 rc = slap_str2ad( c->argv[i], &ad, &text );
1924 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown attribute type #%d",
1927 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1928 c->log, c->cr_msg, c->argv[i] );
1929 for ( sv = svnew; sv; sv = svnew ) {
1930 svnew = sv->al_next;
1935 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) ||
1936 ad->ad_type->sat_single_value ) {
1937 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> inappropriate attribute type #%d",
1939 goto sortval_reject;
1941 sv = ch_malloc( sizeof( ADlist ));
1946 svtail->al_next = sv;
1951 for ( sv = svnew; sv; sv = sv->al_next )
1952 sv->al_desc->ad_type->sat_flags |= SLAP_AT_SORTED_VAL;
1953 for ( sv = sortVals; sv && sv->al_next; sv = sv->al_next );
1955 sv->al_next = svnew;
1962 if ( SLAP_CONFIG( c->be ) && c->be->be_acl == defacl_parsed) {
1963 c->be->be_acl = NULL;
1965 /* Don't append to the global ACL if we're on a specific DB */
1967 if ( c->valx == -1 ) {
1970 for ( a=c->be->be_acl; a; a = a->acl_next )
1973 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
1974 if ( SLAP_CONFIG( c->be ) && !c->be->be_acl) {
1975 c->be->be_acl = defacl_parsed;
1983 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_ACL_ADD;
1985 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_ACL_ADD;
1989 if(root_dse_read_file(c->argv[1])) {
1990 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> could not read file", c->argv[0] );
1991 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1992 c->log, c->cr_msg, c->argv[1] );
1997 ber_str2bv( c->argv[1], 0, 1, &bv );
1998 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1999 cfn = c->ca_private;
2000 ber_bvarray_add( &cfn->c_dseFiles, &bv );
2006 ServerID *si, **sip;
2009 if (( lutil_atoi( &num, c->argv[1] ) &&
2010 lutil_atoix( &num, c->argv[1], 16 )) ||
2011 num < 0 || num > SLAP_SYNC_SID_MAX )
2013 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2014 "<%s> illegal server ID", c->argv[0] );
2015 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2016 c->log, c->cr_msg, c->argv[1] );
2019 /* only one value allowed if no URL is given */
2020 if ( c->argc > 2 ) {
2023 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
2024 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2025 "<%s> only one server ID allowed now", c->argv[0] );
2026 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2027 c->log, c->cr_msg, c->argv[1] );
2031 if ( ldap_url_parse( c->argv[2], &lud )) {
2032 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2033 "<%s> invalid URL", c->argv[0] );
2034 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2035 c->log, c->cr_msg, c->argv[2] );
2038 len = strlen( c->argv[2] );
2039 si = ch_malloc( sizeof(ServerID) + len + 1 );
2040 si->si_url.bv_val = (char *)(si+1);
2041 si->si_url.bv_len = len;
2042 strcpy( si->si_url.bv_val, c->argv[2] );
2045 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2046 "<%s> unqualified server ID not allowed now", c->argv[0] );
2047 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2048 c->log, c->cr_msg, c->argv[1] );
2051 si = ch_malloc( sizeof(ServerID) );
2052 BER_BVZERO( &si->si_url );
2053 slap_serverID = num;
2054 Debug( LDAP_DEBUG_CONFIG,
2056 c->log, slap_serverID, 0 );
2061 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
2064 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
2065 Listener *l = config_check_my_url( c->argv[2], lud );
2068 ldap_free_urldesc( lud );
2069 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2070 "<%s> multiple server ID URLs matched, only one is allowed", c->argv[0] );
2071 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2072 c->log, c->cr_msg, c->argv[1] );
2075 slap_serverID = si->si_num;
2076 Debug( LDAP_DEBUG_CONFIG,
2077 "%s: SID=0x%03x (listener=%s)\n",
2078 c->log, slap_serverID,
2084 ldap_free_urldesc( lud );
2088 if ( logfileName ) ch_free( logfileName );
2089 logfileName = c->value_string;
2090 logfile = fopen(logfileName, "w");
2091 if(logfile) lutil_debug_file(logfile);
2095 if(SLAP_NOLASTMODCMD(c->be)) {
2096 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> not available for %s database",
2097 c->argv[0], c->be->bd_info->bi_type );
2098 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2099 c->log, c->cr_msg, 0 );
2103 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
2105 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
2108 case CFG_MIRRORMODE:
2109 if(c->value_int && !SLAP_SHADOW(c->be)) {
2110 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database is not a shadow",
2112 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2113 c->log, c->cr_msg, 0 );
2117 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
2118 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MULTI_SHADOW;
2120 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
2121 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MULTI_SHADOW;
2125 case CFG_MONITORING:
2127 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
2129 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
2134 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
2136 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
2139 case CFG_SYNC_SUBENTRY:
2141 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SYNC_SUBENTRY;
2143 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SYNC_SUBENTRY;
2146 case CFG_SSTR_IF_MAX:
2147 if (c->value_uint < index_substr_if_minlen) {
2148 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
2149 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
2150 c->log, c->cr_msg, c->value_int );
2153 index_substr_if_maxlen = c->value_uint;
2156 case CFG_SSTR_IF_MIN:
2157 if (c->value_uint > index_substr_if_maxlen) {
2158 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
2159 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
2160 c->log, c->cr_msg, c->value_int );
2163 index_substr_if_minlen = c->value_uint;
2166 #ifdef SLAPD_MODULES
2168 /* If we're just adding a module on an existing modpath,
2169 * make sure we've selected the current path.
2171 if ( c->op == LDAP_MOD_ADD && c->ca_private && modcur != c->ca_private ) {
2172 modcur = c->ca_private;
2173 /* This should never fail */
2174 if ( module_path( modcur->mp_path.bv_val )) {
2175 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> module path no longer valid",
2177 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2178 c->log, c->cr_msg, modcur->mp_path.bv_val );
2182 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
2184 /* Record this load on the current path */
2188 if ( c->op == SLAP_CONFIG_ADD ) {
2189 ptr = c->line + STRLENOF("moduleload");
2190 while (!isspace((unsigned char) *ptr)) ptr++;
2191 while (isspace((unsigned char) *ptr)) ptr++;
2195 ber_str2bv(ptr, 0, 1, &bv);
2196 ber_bvarray_add( &modcur->mp_loads, &bv );
2198 /* Check for any new hardcoded schema */
2199 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
2200 config_check_schema( NULL, &cfBackInfo );
2205 if(module_path(c->argv[1])) return(1);
2206 /* Record which path was used with each module */
2210 if (!modpaths.mp_loads) {
2213 mp = ch_malloc( sizeof( ModPaths ));
2214 modlast->mp_next = mp;
2216 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
2218 mp->mp_loads = NULL;
2229 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
2231 slapi_plugins_used++;
2235 #ifdef SLAP_AUTH_REWRITE
2241 if ( c->op == LDAP_MOD_ADD ) {
2245 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
2249 if ( c->argc > 1 ) {
2252 /* quote all args but the first */
2253 line = ldap_charray2str( c->argv, "\" \"" );
2254 ber_str2bv( line, 0, 0, &bv );
2255 s = ber_bvchr( &bv, '"' );
2256 assert( s != NULL );
2257 /* move the trailing quote of argv[0] to the end */
2258 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
2259 bv.bv_val[ bv.bv_len - 1 ] = '"';
2262 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
2265 ber_bvarray_add( &authz_rewrites, &bv );
2267 if ( c->op == LDAP_MOD_ADD ) {
2277 Debug( LDAP_DEBUG_ANY,
2278 "%s: unknown CFG_TYPE %d.\n",
2279 c->log, c->type, 0 );
2288 config_fname(ConfigArgs *c) {
2289 if(c->op == SLAP_CONFIG_EMIT) {
2290 if (c->ca_private) {
2291 ConfigFile *cf = c->ca_private;
2292 value_add_one( &c->rvalue_vals, &cf->c_file );
2301 config_cfdir(ConfigArgs *c) {
2302 if(c->op == SLAP_CONFIG_EMIT) {
2303 if ( !BER_BVISEMPTY( &cfdir )) {
2304 value_add_one( &c->rvalue_vals, &cfdir );
2313 config_search_base(ConfigArgs *c) {
2314 if(c->op == SLAP_CONFIG_EMIT) {
2316 if (!BER_BVISEMPTY(&default_search_base)) {
2317 value_add_one(&c->rvalue_vals, &default_search_base);
2318 value_add_one(&c->rvalue_nvals, &default_search_nbase);
2322 } else if( c->op == LDAP_MOD_DELETE ) {
2323 ch_free( default_search_base.bv_val );
2324 ch_free( default_search_nbase.bv_val );
2325 BER_BVZERO( &default_search_base );
2326 BER_BVZERO( &default_search_nbase );
2330 if(c->bi || c->be != frontendDB) {
2331 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
2332 "prior to any backend or database definition\n",
2337 if(default_search_nbase.bv_len) {
2338 free(default_search_base.bv_val);
2339 free(default_search_nbase.bv_val);
2342 default_search_base = c->value_dn;
2343 default_search_nbase = c->value_ndn;
2347 /* For RE23 compatibility we allow this in the global entry
2348 * but we now defer it to the frontend entry to allow modules
2349 * to load new hash types.
2352 config_passwd_hash(ConfigArgs *c) {
2354 if (c->op == SLAP_CONFIG_EMIT) {
2356 /* Don't generate it in the global entry */
2357 if ( c->table == Cft_Global )
2359 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
2360 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
2361 value_add_one(&c->rvalue_vals, &bv);
2364 } else if ( c->op == LDAP_MOD_DELETE ) {
2365 /* Deleting from global is a no-op, only the frontendDB entry matters */
2366 if ( c->table == Cft_Global )
2368 if ( c->valx < 0 ) {
2369 ldap_charray_free( default_passwd_hash );
2370 default_passwd_hash = NULL;
2373 ch_free( default_passwd_hash[i] );
2374 for (; default_passwd_hash[i]; i++ )
2375 default_passwd_hash[i] = default_passwd_hash[i+1];
2379 for(i = 1; i < c->argc; i++) {
2380 if(!lutil_passwd_scheme(c->argv[i])) {
2381 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> scheme not available", c->argv[0] );
2382 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2383 c->log, c->cr_msg, c->argv[i]);
2385 ldap_charray_add(&default_passwd_hash, c->argv[i]);
2388 if(!default_passwd_hash) {
2389 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> no valid hashes found", c->argv[0] );
2390 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2391 c->log, c->cr_msg, 0 );
2398 config_schema_dn(ConfigArgs *c) {
2399 if ( c->op == SLAP_CONFIG_EMIT ) {
2401 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
2402 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
2403 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
2407 } else if ( c->op == LDAP_MOD_DELETE ) {
2408 ch_free( c->be->be_schemadn.bv_val );
2409 ch_free( c->be->be_schemandn.bv_val );
2410 BER_BVZERO( &c->be->be_schemadn );
2411 BER_BVZERO( &c->be->be_schemandn );
2414 ch_free( c->be->be_schemadn.bv_val );
2415 ch_free( c->be->be_schemandn.bv_val );
2416 c->be->be_schemadn = c->value_dn;
2417 c->be->be_schemandn = c->value_ndn;
2422 config_sizelimit(ConfigArgs *c) {
2424 struct slap_limits_set *lim = &c->be->be_def_limit;
2425 if (c->op == SLAP_CONFIG_EMIT) {
2430 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
2431 if ( !BER_BVISEMPTY( &bv ))
2432 value_add_one( &c->rvalue_vals, &bv );
2436 } else if ( c->op == LDAP_MOD_DELETE ) {
2437 /* Reset to defaults or values from frontend */
2438 if ( c->be == frontendDB ) {
2439 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
2440 lim->lms_s_hard = 0;
2441 lim->lms_s_unchecked = -1;
2443 lim->lms_s_pr_hide = 0;
2444 lim->lms_s_pr_total = 0;
2446 lim->lms_s_soft = frontendDB->be_def_limit.lms_s_soft;
2447 lim->lms_s_hard = frontendDB->be_def_limit.lms_s_hard;
2448 lim->lms_s_unchecked = frontendDB->be_def_limit.lms_s_unchecked;
2449 lim->lms_s_pr = frontendDB->be_def_limit.lms_s_pr;
2450 lim->lms_s_pr_hide = frontendDB->be_def_limit.lms_s_pr_hide;
2451 lim->lms_s_pr_total = frontendDB->be_def_limit.lms_s_pr_total;
2455 for(i = 1; i < c->argc; i++) {
2456 if(!strncasecmp(c->argv[i], "size", 4)) {
2457 rc = limits_parse_one(c->argv[i], lim);
2459 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2460 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2461 c->log, c->cr_msg, c->argv[i]);
2465 if(!strcasecmp(c->argv[i], "unlimited")) {
2466 lim->lms_s_soft = -1;
2468 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
2469 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2470 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2471 c->log, c->cr_msg, c->argv[i]);
2475 lim->lms_s_hard = 0;
2480 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2481 /* This is a modification to the global limits apply it to
2482 * the other databases as needed */
2483 AttributeDescription *ad=NULL;
2484 const char *text = NULL;
2485 CfEntryInfo *ce = c->ca_entry->e_private;
2487 slap_str2ad(c->argv[0], &ad, &text);
2488 /* if we got here... */
2489 assert( ad != NULL );
2491 if ( ce->ce_type == Cft_Global ){
2494 for (; ce; ce=ce->ce_sibs) {
2495 Entry *dbe = ce->ce_entry;
2496 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2497 && (!attr_find(dbe->e_attrs, ad)) ) {
2498 ce->ce_be->be_def_limit.lms_s_soft = lim->lms_s_soft;
2499 ce->ce_be->be_def_limit.lms_s_hard = lim->lms_s_hard;
2500 ce->ce_be->be_def_limit.lms_s_unchecked =lim->lms_s_unchecked;
2501 ce->ce_be->be_def_limit.lms_s_pr =lim->lms_s_pr;
2502 ce->ce_be->be_def_limit.lms_s_pr_hide =lim->lms_s_pr_hide;
2503 ce->ce_be->be_def_limit.lms_s_pr_total =lim->lms_s_pr_total;
2511 config_timelimit(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_TIME, &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_t_soft = SLAPD_DEFAULT_TIMELIMIT;
2529 lim->lms_t_hard = 0;
2531 lim->lms_t_soft = frontendDB->be_def_limit.lms_t_soft;
2532 lim->lms_t_hard = frontendDB->be_def_limit.lms_t_hard;
2536 for(i = 1; i < c->argc; i++) {
2537 if(!strncasecmp(c->argv[i], "time", 4)) {
2538 rc = limits_parse_one(c->argv[i], lim);
2540 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2541 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2542 c->log, c->cr_msg, c->argv[i]);
2546 if(!strcasecmp(c->argv[i], "unlimited")) {
2547 lim->lms_t_soft = -1;
2549 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
2550 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2551 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2552 c->log, c->cr_msg, c->argv[i]);
2556 lim->lms_t_hard = 0;
2561 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2562 /* This is a modification to the global limits apply it to
2563 * the other databases as needed */
2564 AttributeDescription *ad=NULL;
2565 const char *text = NULL;
2566 CfEntryInfo *ce = c->ca_entry->e_private;
2568 slap_str2ad(c->argv[0], &ad, &text);
2569 /* if we got here... */
2570 assert( ad != NULL );
2572 if ( ce->ce_type == Cft_Global ){
2575 for (; ce; ce=ce->ce_sibs) {
2576 Entry *dbe = ce->ce_entry;
2577 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2578 && (!attr_find(dbe->e_attrs, ad)) ) {
2579 ce->ce_be->be_def_limit.lms_t_soft = lim->lms_t_soft;
2580 ce->ce_be->be_def_limit.lms_t_hard = lim->lms_t_hard;
2588 config_overlay(ConfigArgs *c) {
2589 if (c->op == SLAP_CONFIG_EMIT) {
2591 } else if ( c->op == LDAP_MOD_DELETE ) {
2594 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2595 c->valx, &c->bi, &c->reply)) {
2597 Debug( LDAP_DEBUG_ANY,
2598 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2599 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2601 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi, &c->reply)) {
2608 config_subordinate(ConfigArgs *c)
2614 case SLAP_CONFIG_EMIT:
2615 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2618 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2619 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2622 value_add_one( &c->rvalue_vals, &bv );
2626 case LDAP_MOD_DELETE:
2627 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2628 glue_sub_del( c->be );
2630 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2635 case SLAP_CONFIG_ADD:
2636 if ( c->be->be_nsuffix == NULL ) {
2638 snprintf( c->cr_msg, sizeof( c->cr_msg),
2639 "subordinate configuration needs a suffix" );
2640 Debug( LDAP_DEBUG_ANY,
2642 c->log, c->cr_msg, 0 );
2647 if ( c->argc == 2 ) {
2648 if ( strcasecmp( c->argv[1], "advertise" ) == 0 ) {
2651 } else if ( strcasecmp( c->argv[1], "TRUE" ) != 0 ) {
2653 snprintf( c->cr_msg, sizeof( c->cr_msg),
2654 "subordinate must be \"TRUE\" or \"advertise\"" );
2655 Debug( LDAP_DEBUG_ANY,
2656 "%s: suffix \"%s\": %s.\n",
2657 c->log, c->be->be_suffix[0].bv_val, c->cr_msg );
2663 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2671 * [listener=<listener>] [{read|write}=]<size>
2674 #ifdef LDAP_TCP_BUFFER
2675 static BerVarray tcp_buffer;
2678 #define SLAP_TCP_RMEM (0x1U)
2679 #define SLAP_TCP_WMEM (0x2U)
2682 tcp_buffer_parse( struct berval *val, int argc, char **argv,
2683 int *size, int *rw, Listener **l )
2685 int i, rc = LDAP_SUCCESS;
2686 LDAPURLDesc *lud = NULL;
2689 if ( val != NULL && argv == NULL ) {
2690 char *s = val->bv_val;
2692 argv = ldap_str2charray( s, " \t" );
2693 if ( argv == NULL ) {
2699 if ( strncasecmp( argv[ i ], "listener=", STRLENOF( "listener=" ) )
2702 char *url = argv[ i ] + STRLENOF( "listener=" );
2704 if ( ldap_url_parse( url, &lud ) ) {
2705 rc = LDAP_INVALID_SYNTAX;
2709 *l = config_check_my_url( url, lud );
2711 rc = LDAP_NO_SUCH_ATTRIBUTE;
2719 if ( strncasecmp( ptr, "read=", STRLENOF( "read=" ) ) == 0 ) {
2720 *rw |= SLAP_TCP_RMEM;
2721 ptr += STRLENOF( "read=" );
2723 } else if ( strncasecmp( ptr, "write=", STRLENOF( "write=" ) ) == 0 ) {
2724 *rw |= SLAP_TCP_WMEM;
2725 ptr += STRLENOF( "write=" );
2728 *rw |= ( SLAP_TCP_RMEM | SLAP_TCP_WMEM );
2731 /* accept any base */
2732 if ( lutil_atoix( size, ptr, 0 ) ) {
2733 rc = LDAP_INVALID_SYNTAX;
2738 if ( val != NULL && argv != NULL ) {
2739 ldap_charray_free( argv );
2742 if ( lud != NULL ) {
2743 ldap_free_urldesc( lud );
2750 tcp_buffer_delete_one( struct berval *val )
2753 int size = -1, rw = 0;
2756 rc = tcp_buffer_parse( val, 0, NULL, &size, &rw, &l );
2763 Listener **ll = slapd_get_listeners();
2765 for ( i = 0; ll[ i ] != NULL; i++ ) {
2766 if ( ll[ i ] == l ) break;
2769 if ( ll[ i ] == NULL ) {
2770 return LDAP_NO_SUCH_ATTRIBUTE;
2773 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = -1;
2774 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = -1;
2776 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2777 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = -1;
2778 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = -1;
2782 /* NOTE: this affects listeners without a specific setting,
2783 * does not reset all listeners. If a listener without
2784 * specific settings was assigned a buffer because of
2785 * a global setting, it will not be reset. In any case,
2786 * buffer changes will only take place at restart. */
2787 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = -1;
2788 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = -1;
2795 tcp_buffer_delete( BerVarray vals )
2799 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
2800 tcp_buffer_delete_one( &vals[ i ] );
2807 tcp_buffer_unparse( int size, int rw, Listener *l, struct berval *val )
2809 char buf[sizeof("2147483648")], *ptr;
2811 /* unparse for later use */
2812 val->bv_len = snprintf( buf, sizeof( buf ), "%d", size );
2814 val->bv_len += STRLENOF( "listener=" " " ) + l->sl_url.bv_len;
2817 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2818 if ( rw & SLAP_TCP_RMEM ) {
2819 val->bv_len += STRLENOF( "read=" );
2820 } else if ( rw & SLAP_TCP_WMEM ) {
2821 val->bv_len += STRLENOF( "write=" );
2825 val->bv_val = SLAP_MALLOC( val->bv_len + 1 );
2830 ptr = lutil_strcopy( ptr, "listener=" );
2831 ptr = lutil_strncopy( ptr, l->sl_url.bv_val, l->sl_url.bv_len );
2835 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2836 if ( rw & SLAP_TCP_RMEM ) {
2837 ptr = lutil_strcopy( ptr, "read=" );
2838 } else if ( rw & SLAP_TCP_WMEM ) {
2839 ptr = lutil_strcopy( ptr, "write=" );
2843 ptr = lutil_strcopy( ptr, buf );
2846 assert( val->bv_val + val->bv_len == ptr );
2848 return LDAP_SUCCESS;
2852 tcp_buffer_add_one( int argc, char **argv )
2855 int size = -1, rw = 0;
2861 rc = tcp_buffer_parse( NULL, argc, argv, &size, &rw, &l );
2866 /* unparse for later use */
2867 rc = tcp_buffer_unparse( size, rw, l, &val );
2868 if ( rc != LDAP_SUCCESS ) {
2872 /* use parsed values */
2875 Listener **ll = slapd_get_listeners();
2877 for ( i = 0; ll[ i ] != NULL; i++ ) {
2878 if ( ll[ i ] == l ) break;
2881 if ( ll[ i ] == NULL ) {
2882 return LDAP_NO_SUCH_ATTRIBUTE;
2885 /* buffer only applies to TCP listeners;
2886 * we do not do any check here, and delegate them
2887 * to setsockopt(2) */
2888 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = size;
2889 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = size;
2891 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2892 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = size;
2893 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = size;
2897 /* NOTE: this affects listeners without a specific setting,
2898 * does not set all listeners */
2899 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = size;
2900 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = size;
2903 tcp_buffer = SLAP_REALLOC( tcp_buffer, sizeof( struct berval ) * ( tcp_buffer_num + 2 ) );
2905 tcp_buffer[ tcp_buffer_num ] = val;
2908 BER_BVZERO( &tcp_buffer[ tcp_buffer_num ] );
2914 config_tcp_buffer( ConfigArgs *c )
2916 if ( c->op == SLAP_CONFIG_EMIT ) {
2917 if ( tcp_buffer == NULL || BER_BVISNULL( &tcp_buffer[ 0 ] ) ) {
2920 value_add( &c->rvalue_vals, tcp_buffer );
2921 value_add( &c->rvalue_nvals, tcp_buffer );
2923 } else if ( c->op == LDAP_MOD_DELETE ) {
2925 tcp_buffer_delete( tcp_buffer );
2926 ber_bvarray_free( tcp_buffer );
2932 int size = -1, rw = 0;
2935 struct berval val = BER_BVNULL;
2939 if ( tcp_buffer_num == 0 ) {
2944 rc = tcp_buffer_parse( NULL, c->argc - 1, &c->argv[ 1 ], &size, &rw, &l );
2949 /* unparse for later use */
2950 rc = tcp_buffer_unparse( size, rw, l, &val );
2951 if ( rc != LDAP_SUCCESS ) {
2955 for ( i = 0; !BER_BVISNULL( &tcp_buffer[ i ] ); i++ ) {
2956 if ( bvmatch( &tcp_buffer[ i ], &val ) ) {
2961 if ( BER_BVISNULL( &tcp_buffer[ i ] ) ) {
2967 tcp_buffer_delete_one( &tcp_buffer[ i ] );
2968 ber_memfree( tcp_buffer[ i ].bv_val );
2969 for ( ; i < tcp_buffer_num; i++ ) {
2970 tcp_buffer[ i ] = tcp_buffer[ i + 1 ];
2975 if ( !BER_BVISNULL( &val ) ) {
2976 SLAP_FREE( val.bv_val );
2984 rc = tcp_buffer_add_one( c->argc - 1, &c->argv[ 1 ] );
2986 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2987 "<%s> unable to add value #%d",
2988 c->argv[0], tcp_buffer_num );
2989 Debug( LDAP_DEBUG_ANY, "%s: %s\n",
2990 c->log, c->cr_msg, 0 );
2997 #endif /* LDAP_TCP_BUFFER */
3000 config_suffix(ConfigArgs *c)
3003 struct berval pdn, ndn;
3004 char *notallowed = NULL;
3006 if ( c->be == frontendDB ) {
3007 notallowed = "frontend";
3009 } else if ( SLAP_MONITOR(c->be) ) {
3010 notallowed = "monitor";
3012 } else if ( SLAP_CONFIG(c->be) ) {
3013 notallowed = "config";
3016 if ( notallowed != NULL ) {
3017 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
3021 case LDAP_MOD_DELETE:
3022 case LDAP_MOD_REPLACE:
3023 case LDAP_MOD_INCREMENT:
3024 case SLAP_CONFIG_ADD:
3025 if ( !BER_BVISNULL( &c->value_dn ) ) {
3026 snprintf( buf, sizeof( buf ), "<%s> ",
3027 c->value_dn.bv_val );
3030 Debug(LDAP_DEBUG_ANY,
3031 "%s: suffix %snot allowed in %s database.\n",
3032 c->log, buf, notallowed );
3035 case SLAP_CONFIG_EMIT:
3036 /* don't complain when emitting... */
3040 /* FIXME: don't know what values may be valid;
3041 * please remove assertion, or add legal values
3042 * to either block */
3050 if (c->op == SLAP_CONFIG_EMIT) {
3051 if ( c->be->be_suffix == NULL
3052 || BER_BVISNULL( &c->be->be_suffix[0] ) )
3056 value_add( &c->rvalue_vals, c->be->be_suffix );
3057 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
3060 } else if ( c->op == LDAP_MOD_DELETE ) {
3061 if ( c->valx < 0 ) {
3062 ber_bvarray_free( c->be->be_suffix );
3063 ber_bvarray_free( c->be->be_nsuffix );
3064 c->be->be_suffix = NULL;
3065 c->be->be_nsuffix = NULL;
3068 ch_free( c->be->be_suffix[i].bv_val );
3069 ch_free( c->be->be_nsuffix[i].bv_val );
3071 c->be->be_suffix[i] = c->be->be_suffix[i+1];
3072 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
3074 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
3079 #ifdef SLAPD_MONITOR_DN
3080 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
3081 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> DN is reserved for monitoring slapd",
3083 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3084 c->log, c->cr_msg, SLAPD_MONITOR_DN);
3089 if (SLAP_DB_ONE_SUFFIX( c->be ) && c->be->be_suffix &&
3090 !BER_BVISNULL( &c->be->be_suffix[0] )) {
3091 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> Only one suffix is allowed on this %s backend",
3092 c->argv[0], c->be->bd_info->bi_type );
3093 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3094 c->log, c->cr_msg, 0);
3101 if (SLAP_DBHIDDEN( c->be ))
3104 tbe = select_backend(&ndn, 0);
3106 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
3112 BackendDB *b2 = tbe;
3114 /* Does tbe precede be? */
3115 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
3118 char *type = tbe->bd_info->bi_type;
3120 if ( overlay_is_over( tbe ) ) {
3121 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
3122 type = oi->oi_orig->bi_type;
3125 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> namingContext \"%s\" "
3126 "already served by a preceding %s database",
3127 c->argv[0], pdn.bv_val, type );
3128 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
3129 c->log, c->cr_msg, tbe->be_suffix[0].bv_val);
3135 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
3136 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
3137 "base provided \"%s\" (assuming okay)\n",
3138 c->log, default_search_base.bv_val, 0);
3140 ber_bvarray_add(&c->be->be_suffix, &pdn);
3141 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
3146 config_rootdn(ConfigArgs *c) {
3147 if (c->op == SLAP_CONFIG_EMIT) {
3148 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
3149 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
3150 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
3155 } else if ( c->op == LDAP_MOD_DELETE ) {
3156 ch_free( c->be->be_rootdn.bv_val );
3157 ch_free( c->be->be_rootndn.bv_val );
3158 BER_BVZERO( &c->be->be_rootdn );
3159 BER_BVZERO( &c->be->be_rootndn );
3162 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
3163 ch_free( c->be->be_rootdn.bv_val );
3164 ch_free( c->be->be_rootndn.bv_val );
3166 c->be->be_rootdn = c->value_dn;
3167 c->be->be_rootndn = c->value_ndn;
3172 config_rootpw(ConfigArgs *c) {
3175 if (c->op == SLAP_CONFIG_EMIT) {
3176 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
3177 /* don't copy, because "rootpw" is marked
3179 c->value_bv = c->be->be_rootpw;
3183 } else if ( c->op == LDAP_MOD_DELETE ) {
3184 ch_free( c->be->be_rootpw.bv_val );
3185 BER_BVZERO( &c->be->be_rootpw );
3189 tbe = select_backend(&c->be->be_rootndn, 0);
3191 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> can only be set when rootdn is under suffix",
3193 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3194 c->log, c->cr_msg, 0);
3197 if ( !BER_BVISNULL( &c->be->be_rootpw ))
3198 ch_free( c->be->be_rootpw.bv_val );
3199 c->be->be_rootpw = c->value_bv;
3204 config_restrict(ConfigArgs *c) {
3205 slap_mask_t restrictops = 0;
3207 slap_verbmasks restrictable_ops[] = {
3208 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
3209 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
3210 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
3211 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
3212 { BER_BVC("modrdn"), 0 },
3213 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
3214 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
3215 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
3216 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
3217 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
3218 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
3219 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
3220 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
3221 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
3222 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
3223 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
3227 if (c->op == SLAP_CONFIG_EMIT) {
3228 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
3230 } else if ( c->op == LDAP_MOD_DELETE ) {
3232 c->be->be_restrictops = 0;
3234 i = verb_to_mask( c->line, restrictable_ops );
3235 c->be->be_restrictops &= ~restrictable_ops[i].mask;
3239 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
3241 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown operation", c->argv[0] );
3242 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3243 c->log, c->cr_msg, c->argv[i]);
3246 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
3247 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
3248 c->be->be_restrictops |= restrictops;
3253 config_allows(ConfigArgs *c) {
3254 slap_mask_t allows = 0;
3256 slap_verbmasks allowable_ops[] = {
3257 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
3258 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
3259 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
3260 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
3261 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
3264 if (c->op == SLAP_CONFIG_EMIT) {
3265 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
3266 } else if ( c->op == LDAP_MOD_DELETE ) {
3270 i = verb_to_mask( c->line, allowable_ops );
3271 global_allows &= ~allowable_ops[i].mask;
3275 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
3277 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3278 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3279 c->log, c->cr_msg, c->argv[i]);
3282 global_allows |= allows;
3287 config_disallows(ConfigArgs *c) {
3288 slap_mask_t disallows = 0;
3290 slap_verbmasks disallowable_ops[] = {
3291 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
3292 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
3293 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
3294 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
3295 { BER_BVC("proxy_authz_non_critical"), SLAP_DISALLOW_PROXY_AUTHZ_N_CRIT },
3296 { BER_BVC("dontusecopy_non_critical"), SLAP_DISALLOW_DONTUSECOPY_N_CRIT },
3299 if (c->op == SLAP_CONFIG_EMIT) {
3300 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
3301 } else if ( c->op == LDAP_MOD_DELETE ) {
3303 global_disallows = 0;
3305 i = verb_to_mask( c->line, disallowable_ops );
3306 global_disallows &= ~disallowable_ops[i].mask;
3310 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
3312 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3313 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3314 c->log, c->cr_msg, c->argv[i]);
3317 global_disallows |= disallows;
3322 config_requires(ConfigArgs *c) {
3323 slap_mask_t requires = frontendDB->be_requires;
3324 int i, argc = c->argc;
3325 char **argv = c->argv;
3327 slap_verbmasks requires_ops[] = {
3328 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
3329 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
3330 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
3331 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
3332 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
3335 if (c->op == SLAP_CONFIG_EMIT) {
3336 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
3337 } else if ( c->op == LDAP_MOD_DELETE ) {
3339 c->be->be_requires = 0;
3341 i = verb_to_mask( c->line, requires_ops );
3342 c->be->be_requires &= ~requires_ops[i].mask;
3346 /* "none" can only be first, to wipe out default/global values */
3347 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
3352 i = verbs_to_mask(argc, argv, requires_ops, &requires);
3354 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
3355 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
3356 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3357 c->log, c->cr_msg, 0);
3359 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
3360 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3361 c->log, c->cr_msg, c->argv[i]);
3365 c->be->be_requires = requires;
3370 config_extra_attrs(ConfigArgs *c)
3372 assert( c->be != NULL );
3374 if ( c->op == SLAP_CONFIG_EMIT ) {
3377 if ( c->be->be_extra_anlist == NULL ) {
3381 for ( i = 0; !BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ); i++ ) {
3382 value_add_one( &c->rvalue_vals, &c->be->be_extra_anlist[i].an_name );
3385 } else if ( c->op == LDAP_MOD_DELETE ) {
3386 if ( c->be->be_extra_anlist == NULL ) {
3390 if ( c->valx < 0 ) {
3391 anlist_free( c->be->be_extra_anlist, 1, NULL );
3392 c->be->be_extra_anlist = NULL;
3397 for ( i = 0; i < c->valx && !BER_BVISNULL( &c->be->be_extra_anlist[i + 1].an_name ); i++ )
3400 if ( BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ) ) {
3404 ch_free( c->be->be_extra_anlist[i].an_name.bv_val );
3406 for ( ; !BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ); i++ ) {
3407 c->be->be_extra_anlist[i] = c->be->be_extra_anlist[i + 1];
3412 c->be->be_extra_anlist = str2anlist( c->be->be_extra_anlist, c->argv[1], " ,\t" );
3413 if ( c->be->be_extra_anlist == NULL ) {
3421 static slap_verbmasks *loglevel_ops;
3424 loglevel_init( void )
3426 slap_verbmasks lo[] = {
3427 { BER_BVC("Any"), (slap_mask_t) LDAP_DEBUG_ANY },
3428 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
3429 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
3430 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
3431 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
3432 { BER_BVC("BER"), LDAP_DEBUG_BER },
3433 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
3434 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
3435 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
3436 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
3437 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
3438 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
3439 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
3440 #if 0 /* no longer used (nor supported) */
3441 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
3442 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
3444 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
3445 { BER_BVC("None"), LDAP_DEBUG_NONE },
3449 return slap_verbmasks_init( &loglevel_ops, lo );
3453 loglevel_destroy( void )
3455 if ( loglevel_ops ) {
3456 (void)slap_verbmasks_destroy( loglevel_ops );
3458 loglevel_ops = NULL;
3461 static slap_mask_t loglevel_ignore[] = { -1, 0 };
3464 slap_loglevel_register( slap_mask_t m, struct berval *s )
3468 if ( loglevel_ops == NULL ) {
3472 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
3475 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
3483 slap_loglevel_get( struct berval *s, int *l )
3488 if ( loglevel_ops == NULL ) {
3492 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3493 m |= loglevel_ops[ i ].mask;
3496 for ( i = 1; m & i; i <<= 1 )
3503 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
3506 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
3517 str2loglevel( const char *s, int *l )
3521 if ( loglevel_ops == NULL ) {
3525 i = verb_to_mask( s, loglevel_ops );
3527 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
3531 *l = loglevel_ops[ i ].mask;
3537 loglevel2str( int l )
3539 struct berval bv = BER_BVNULL;
3541 loglevel2bv( l, &bv );
3547 loglevel2bv( int l, struct berval *bv )
3549 if ( loglevel_ops == NULL ) {
3555 return enum_to_verb( loglevel_ops, l, bv ) == -1;
3559 loglevel2bvarray( int l, BerVarray *bva )
3561 if ( loglevel_ops == NULL ) {
3565 return mask_to_verbs( loglevel_ops, l, bva );
3569 loglevel_print( FILE *out )
3573 if ( loglevel_ops == NULL ) {
3577 fprintf( out, "Installed log subsystems:\n\n" );
3578 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3579 unsigned mask = loglevel_ops[ i ].mask & 0xffffffffUL;
3581 (mask == ((slap_mask_t) -1 & 0xffffffffUL)
3582 ? "\t%-30s (-1, 0xffffffff)\n" : "\t%-30s (%u, 0x%x)\n"),
3583 loglevel_ops[ i ].word.bv_val, mask, mask );
3586 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
3587 "by specific code\n\n" );
3592 static int config_syslog;
3595 config_loglevel(ConfigArgs *c) {
3598 if ( loglevel_ops == NULL ) {
3602 if (c->op == SLAP_CONFIG_EMIT) {
3603 /* Get default or commandline slapd setting */
3604 if ( ldap_syslog && !config_syslog )
3605 config_syslog = ldap_syslog;
3606 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
3608 } else if ( c->op == LDAP_MOD_DELETE ) {
3612 i = verb_to_mask( c->line, loglevel_ops );
3613 config_syslog &= ~loglevel_ops[i].mask;
3615 if ( slapMode & SLAP_SERVER_MODE ) {
3616 ldap_syslog = config_syslog;
3621 for( i=1; i < c->argc; i++ ) {
3624 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
3625 if( lutil_atoix( &level, c->argv[i], 0 ) != 0 ) {
3626 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse level", c->argv[0] );
3627 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3628 c->log, c->cr_msg, c->argv[i]);
3632 if ( str2loglevel( c->argv[i], &level ) ) {
3633 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown level", c->argv[0] );
3634 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3635 c->log, c->cr_msg, c->argv[i]);
3639 /* Explicitly setting a zero clears all the levels */
3641 config_syslog |= level;
3645 if ( slapMode & SLAP_SERVER_MODE ) {
3646 ldap_syslog = config_syslog;
3652 config_referral(ConfigArgs *c) {
3654 if (c->op == SLAP_CONFIG_EMIT) {
3655 if ( default_referral ) {
3656 value_add( &c->rvalue_vals, default_referral );
3661 } else if ( c->op == LDAP_MOD_DELETE ) {
3662 if ( c->valx < 0 ) {
3663 ber_bvarray_free( default_referral );
3664 default_referral = NULL;
3667 ch_free( default_referral[i].bv_val );
3668 for (; default_referral[i].bv_val; i++ )
3669 default_referral[i] = default_referral[i+1];
3673 if(validate_global_referral(c->argv[1])) {
3674 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3675 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3676 c->log, c->cr_msg, c->argv[1]);
3680 ber_str2bv(c->argv[1], 0, 0, &val);
3681 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
3689 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
3690 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
3691 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
3692 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
3693 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
3694 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
3695 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
3696 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
3697 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
3702 config_security(ConfigArgs *c) {
3703 slap_ssf_set_t *set = &c->be->be_ssf_set;
3706 if (c->op == SLAP_CONFIG_EMIT) {
3712 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
3713 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
3716 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
3717 if ( bv.bv_len >= sizeof( numbuf ) ) {
3718 ber_bvarray_free_x( c->rvalue_vals, NULL );
3719 c->rvalue_vals = NULL;
3723 bv.bv_len += sec_keys[i].key.bv_len;
3724 bv.bv_val = ch_malloc( bv.bv_len + 1);
3725 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
3726 strcpy( next, numbuf );
3727 ber_bvarray_add( &c->rvalue_vals, &bv );
3732 for(i = 1; i < c->argc; i++) {
3733 slap_ssf_t *tgt = NULL;
3735 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
3736 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
3737 sec_keys[j].key.bv_len)) {
3738 src = c->argv[i] + sec_keys[j].key.bv_len;
3739 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
3744 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown factor", c->argv[0] );
3745 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3746 c->log, c->cr_msg, c->argv[i]);
3750 if ( lutil_atou( tgt, src ) != 0 ) {
3751 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse factor", c->argv[0] );
3752 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3753 c->log, c->cr_msg, c->argv[i]);
3761 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
3765 for (; !BER_BVISNULL( &an->an_name ); an++) {
3766 /* if buflen == 0, assume the buffer size has been
3767 * already checked otherwise */
3768 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
3769 if ( comma ) *ptr++ = ',';
3770 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
3777 config_updatedn(ConfigArgs *c) {
3778 if (c->op == SLAP_CONFIG_EMIT) {
3779 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
3780 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
3781 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
3785 } else if ( c->op == LDAP_MOD_DELETE ) {
3786 ch_free( c->be->be_update_ndn.bv_val );
3787 BER_BVZERO( &c->be->be_update_ndn );
3788 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
3791 if(SLAP_SHADOW(c->be)) {
3792 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database already shadowed", c->argv[0] );
3793 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3794 c->log, c->cr_msg, 0);
3798 ber_memfree_x( c->value_dn.bv_val, NULL );
3799 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
3800 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
3802 c->be->be_update_ndn = c->value_ndn;
3803 BER_BVZERO( &c->value_dn );
3804 BER_BVZERO( &c->value_ndn );
3806 return config_slurp_shadow( c );
3810 config_shadow( ConfigArgs *c, slap_mask_t flag )
3812 char *notallowed = NULL;
3814 if ( c->be == frontendDB ) {
3815 notallowed = "frontend";
3817 } else if ( SLAP_MONITOR(c->be) ) {
3818 notallowed = "monitor";
3821 if ( notallowed != NULL ) {
3822 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
3826 if ( SLAP_SHADOW(c->be) ) {
3827 /* if already shadow, only check consistency */
3828 if ( ( SLAP_DBFLAGS(c->be) & flag ) != flag ) {
3829 Debug( LDAP_DEBUG_ANY, "%s: inconsistent shadow flag 0x%lx.\n",
3835 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | flag);
3836 if ( !SLAP_MULTIMASTER( c->be ))
3837 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
3844 config_updateref(ConfigArgs *c) {
3846 if (c->op == SLAP_CONFIG_EMIT) {
3847 if ( c->be->be_update_refs ) {
3848 value_add( &c->rvalue_vals, c->be->be_update_refs );
3853 } else if ( c->op == LDAP_MOD_DELETE ) {
3854 if ( c->valx < 0 ) {
3855 ber_bvarray_free( c->be->be_update_refs );
3856 c->be->be_update_refs = NULL;
3859 ch_free( c->be->be_update_refs[i].bv_val );
3860 for (; c->be->be_update_refs[i].bv_val; i++)
3861 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
3865 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
3866 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must appear after syncrepl or updatedn",
3868 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3869 c->log, c->cr_msg, 0);
3873 if(validate_global_referral(c->argv[1])) {
3874 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3875 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3876 c->log, c->cr_msg, c->argv[1]);
3879 ber_str2bv(c->argv[1], 0, 0, &val);
3880 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
3885 config_obsolete(ConfigArgs *c) {
3886 if (c->op == SLAP_CONFIG_EMIT)
3889 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> keyword is obsolete (ignored)",
3891 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0);
3896 config_include(ConfigArgs *c) {
3897 int savelineno = c->lineno;
3900 ConfigFile *cfsave = cfn;
3901 ConfigFile *cf2 = NULL;
3903 /* Leftover from RE23. No dynamic config for include files */
3904 if ( c->op == SLAP_CONFIG_EMIT || c->op == LDAP_MOD_DELETE )
3907 cf = ch_calloc( 1, sizeof(ConfigFile));
3908 if ( cfn->c_kids ) {
3909 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
3915 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
3916 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
3917 c->lineno = savelineno - 1;
3920 if ( cf2 ) cf2->c_sibs = NULL;
3921 else cfn->c_kids = NULL;
3922 ch_free( cf->c_file.bv_val );
3932 config_tls_cleanup(ConfigArgs *c) {
3935 if ( slap_tls_ld ) {
3938 ldap_pvt_tls_ctx_free( slap_tls_ctx );
3940 /* Force new ctx to be created */
3941 rc = ldap_pvt_tls_set_option( slap_tls_ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
3943 /* The ctx's refcount is bumped up here */
3944 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CTX, &slap_tls_ctx );
3945 /* This is a no-op if it's already loaded */
3946 load_extop( &slap_EXOP_START_TLS, 0, starttls_extop );
3953 config_tls_option(ConfigArgs *c) {
3955 LDAP *ld = slap_tls_ld;
3957 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
3958 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
3959 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
3960 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
3961 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
3962 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
3963 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
3965 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
3967 default: Debug(LDAP_DEBUG_ANY, "%s: "
3968 "unknown tls_option <0x%x>\n",
3969 c->log, c->type, 0);
3972 if (c->op == SLAP_CONFIG_EMIT) {
3973 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
3974 } else if ( c->op == LDAP_MOD_DELETE ) {
3975 c->cleanup = config_tls_cleanup;
3976 return ldap_pvt_tls_set_option( ld, flag, NULL );
3978 ch_free(c->value_string);
3979 c->cleanup = config_tls_cleanup;
3980 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
3983 /* FIXME: this ought to be provided by libldap */
3985 config_tls_config(ConfigArgs *c) {
3988 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
3989 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
3990 case CFG_TLS_PROTOCOL_MIN: flag = LDAP_OPT_X_TLS_PROTOCOL_MIN; break;
3992 Debug(LDAP_DEBUG_ANY, "%s: "
3993 "unknown tls_option <0x%x>\n",
3994 c->log, c->type, 0);
3997 if (c->op == SLAP_CONFIG_EMIT) {
3998 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
3999 } else if ( c->op == LDAP_MOD_DELETE ) {
4001 c->cleanup = config_tls_cleanup;
4002 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
4004 ch_free( c->value_string );
4005 c->cleanup = config_tls_cleanup;
4006 if ( isdigit( (unsigned char)c->argv[1][0] ) ) {
4007 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
4008 Debug(LDAP_DEBUG_ANY, "%s: "
4009 "unable to parse %s \"%s\"\n",
4010 c->log, c->argv[0], c->argv[1] );
4013 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
4015 return(ldap_pvt_tls_config(slap_tls_ld, flag, c->argv[1]));
4020 static CfEntryInfo *
4021 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
4031 if ( dn_match( &root->ce_entry->e_nname, dn ))
4034 c = dn->bv_val+dn->bv_len;
4035 for (;*c != ',';c--);
4039 for (--c;c>dn->bv_val && *c != ',';c--);
4043 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
4045 root = root->ce_kids;
4047 for (;root;root=root->ce_sibs) {
4048 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
4049 if ( cdn.bv_val == dn->bv_val ) {
4059 typedef struct setup_cookie {
4069 config_ldif_resp( Operation *op, SlapReply *rs )
4071 if ( rs->sr_type == REP_SEARCH ) {
4072 setup_cookie *sc = op->o_callback->sc_private;
4075 sc->cfb->cb_got_ldif = 1;
4076 /* Does the frontend exist? */
4077 if ( !sc->got_frontend ) {
4078 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
4079 "olcDatabase", STRLENOF( "olcDatabase" )))
4081 if ( strncmp( rs->sr_entry->e_nname.bv_val +
4082 STRLENOF( "olcDatabase" ), "={-1}frontend",
4083 STRLENOF( "={-1}frontend" )))
4087 sc->ca->be = frontendDB;
4088 sc->ca->bi = frontendDB->bd_info;
4089 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
4090 rdn.bv_val = sc->ca->log;
4091 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
4092 "%s=" SLAP_X_ORDERED_FMT "%s",
4093 cfAd_database->ad_cname.bv_val, -1,
4094 sc->ca->bi->bi_type);
4096 sc->frontend = config_build_entry( op, rs,
4097 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
4098 sc->ca->be->be_cf_ocs );
4108 dnParent( &rs->sr_entry->e_nname, &pdn );
4110 /* Does the configDB exist? */
4111 if ( sc->got_frontend && !sc->got_config &&
4112 !strncmp( rs->sr_entry->e_nname.bv_val,
4113 "olcDatabase", STRLENOF( "olcDatabase" )) &&
4114 dn_match( &config_rdn, &pdn ) )
4116 if ( strncmp( rs->sr_entry->e_nname.bv_val +
4117 STRLENOF( "olcDatabase" ), "={0}config",
4118 STRLENOF( "={0}config" )))
4122 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
4123 sc->ca->bi = sc->ca->be->bd_info;
4124 rdn.bv_val = sc->ca->log;
4125 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
4126 "%s=" SLAP_X_ORDERED_FMT "%s",
4127 cfAd_database->ad_cname.bv_val, 0,
4128 sc->ca->bi->bi_type);
4130 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
4131 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
4138 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
4139 if ( rs->sr_err != LDAP_SUCCESS ) {
4140 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
4141 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg, 0 );
4147 /* Configure and read the underlying back-ldif store */
4149 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
4150 CfBackInfo *cfb = be->be_private;
4156 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
4157 Connection conn = {0};
4158 OperationBuffer opbuf;
4160 SlapReply rs = {REP_RESULT};
4161 Filter filter = { LDAP_FILTER_PRESENT };
4162 struct berval filterstr = BER_BVC("(objectclass=*)");
4165 /* Is the config directory available? */
4166 if ( stat( dir, &st ) < 0 ) {
4167 /* No, so don't bother using the backing store.
4168 * All changes will be in-memory only.
4173 cfb->cb_db.bd_info = backend_info( "ldif" );
4174 if ( !cfb->cb_db.bd_info )
4175 return 0; /* FIXME: eventually this will be a fatal error */
4177 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
4180 cfb->cb_db.be_suffix = be->be_suffix;
4181 cfb->cb_db.be_nsuffix = be->be_nsuffix;
4183 /* The suffix is always "cn=config". The underlying DB's rootdn
4184 * is always the same as the suffix.
4186 cfb->cb_db.be_rootdn = be->be_suffix[0];
4187 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
4189 ber_str2bv( dir, 0, 1, &cfdir );
4194 argv[0] = "directory";
4195 argv[1] = (char *)dir;
4200 c.table = Cft_Database;
4202 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
4206 if ( config_add_vals( ct, &c ))
4209 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
4213 void *thrctx = ldap_pvt_thread_pool_context();
4216 connection_fake_init( &conn, &opbuf, thrctx );
4219 filter.f_desc = slap_schema.si_ad_objectClass;
4221 op->o_tag = LDAP_REQ_SEARCH;
4223 op->ors_filter = &filter;
4224 op->ors_filterstr = filterstr;
4225 op->ors_scope = LDAP_SCOPE_SUBTREE;
4227 op->o_dn = c.be->be_rootdn;
4228 op->o_ndn = c.be->be_rootndn;
4230 op->o_req_dn = be->be_suffix[0];
4231 op->o_req_ndn = be->be_nsuffix[0];
4233 op->ors_tlimit = SLAP_NO_LIMIT;
4234 op->ors_slimit = SLAP_NO_LIMIT;
4236 op->ors_attrs = slap_anlist_all_attributes;
4237 op->ors_attrsonly = 0;
4239 op->o_callback = &cb;
4242 cb.sc_private = ≻
4243 sc.got_frontend = 0;
4248 op->o_bd = &cfb->cb_db;
4250 /* Allow unknown attrs in DNs */
4251 prev_DN_strict = slap_DN_strict;
4254 rc = op->o_bd->be_search( op, &rs );
4256 /* Restore normal DN validation */
4257 slap_DN_strict = prev_DN_strict;
4259 op->o_tag = LDAP_REQ_ADD;
4260 if ( rc == LDAP_SUCCESS && sc.frontend ) {
4261 rs_reinit( &rs, REP_RESULT );
4262 op->ora_e = sc.frontend;
4263 rc = op->o_bd->be_add( op, &rs );
4265 if ( rc == LDAP_SUCCESS && sc.config ) {
4266 rs_reinit( &rs, REP_RESULT );
4267 op->ora_e = sc.config;
4268 rc = op->o_bd->be_add( op, &rs );
4270 ldap_pvt_thread_pool_context_reset( thrctx );
4273 /* ITS#4194 - only use if it's present, or we're converting. */
4274 if ( !readit || rc == LDAP_SUCCESS )
4275 cfb->cb_use_ldif = 1;
4281 CfOc_cmp( const void *c1, const void *c2 ) {
4282 const ConfigOCs *co1 = c1;
4283 const ConfigOCs *co2 = c2;
4285 return ber_bvcmp( co1->co_name, co2->co_name );
4289 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
4292 i = init_config_attrs( ct );
4295 /* set up the objectclasses */
4296 i = init_config_ocs( ocs );
4299 for (i=0; ocs[i].co_def; i++) {
4300 if ( ocs[i].co_oc ) {
4301 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
4302 if ( !ocs[i].co_table )
4303 ocs[i].co_table = ct;
4304 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
4311 read_config(const char *fname, const char *dir) {
4314 const char *cfdir, *cfname;
4317 /* Setup the config backend */
4318 be = backend_db_init( "config", NULL, 0, NULL );
4322 cfb = be->be_private;
4323 be->be_dfltaccess = ACL_NONE;
4325 /* If no .conf, or a dir was specified, setup the dir */
4326 if ( !fname || dir ) {
4328 /* If explicitly given, check for existence */
4331 if ( stat( dir, &st ) < 0 ) {
4332 Debug( LDAP_DEBUG_ANY,
4333 "invalid config directory %s, error %d\n",
4339 cfdir = SLAPD_DEFAULT_CONFIGDIR;
4341 /* if fname is defaulted, try reading .d */
4342 rc = config_setup_ldif( be, cfdir, !fname );
4345 /* It may be OK if the base object doesn't exist yet. */
4346 if ( rc != LDAP_NO_SUCH_OBJECT )
4348 /* ITS#4194: But if dir was specified and no fname,
4349 * then we were supposed to read the dir. Unless we're
4350 * trying to slapadd the dir...
4352 if ( dir && !fname ) {
4353 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
4355 /* Assume it's slapadd with a config dir, let it continue */
4357 cfb->cb_got_ldif = 1;
4358 cfb->cb_use_ldif = 1;
4363 /* If we read the config from back-ldif, nothing to do here */
4364 if ( cfb->cb_got_ldif ) {
4373 cfname = SLAPD_DEFAULT_CONFIGFILE;
4375 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
4378 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
4381 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
4382 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
4383 &frontendDB->be_schemadn );
4384 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
4385 if ( rc != LDAP_SUCCESS ) {
4386 Debug(LDAP_DEBUG_ANY, "read_config: "
4387 "unable to normalize default schema DN \"%s\"\n",
4388 frontendDB->be_schemadn.bv_val, 0, 0 );
4389 /* must not happen */
4393 if ( rc == 0 && ( slapMode & SLAP_SERVER_MODE ) && sid_list ) {
4394 if ( !BER_BVISEMPTY( &sid_list->si_url ) && !sid_set ) {
4395 Debug(LDAP_DEBUG_ANY, "read_config: no serverID / URL match found. "
4396 "Check slapd -h arguments.\n", 0,0,0 );
4404 config_back_bind( Operation *op, SlapReply *rs )
4406 if ( be_isroot_pw( op ) ) {
4407 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
4408 /* frontend sends result */
4409 return LDAP_SUCCESS;
4412 rs->sr_err = LDAP_INVALID_CREDENTIALS;
4413 send_ldap_result( op, rs );
4419 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
4423 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
4425 rs->sr_attrs = op->ors_attrs;
4426 rs->sr_entry = ce->ce_entry;
4428 rc = send_search_entry( op, rs );
4429 if ( rc != LDAP_SUCCESS ) {
4433 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
4434 if ( ce->ce_kids ) {
4435 rc = config_send( op, rs, ce->ce_kids, 1 );
4436 if ( rc ) return rc;
4439 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
4440 rc = config_send( op, rs, ce, 0 );
4448 static ConfigTable *
4449 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
4454 for (j=0; j<nocs; j++) {
4455 for (i=0; colst[j]->co_table[i].name; i++)
4456 if ( colst[j]->co_table[i].ad == ad ) {
4457 ca->table = colst[j]->co_type;
4458 return &colst[j]->co_table[i];
4464 /* Sort the attributes of the entry according to the order defined
4465 * in the objectclass, with required attributes occurring before
4466 * allowed attributes. For any attributes with sequencing dependencies
4467 * (e.g., rootDN must be defined after suffix) the objectclass must
4468 * list the attributes in the desired sequence.
4471 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
4473 Attribute *a, *head = NULL, *tail = NULL, **prev;
4476 for (i=0; i<nocs; i++) {
4477 if ( colst[i]->co_oc->soc_required ) {
4478 AttributeType **at = colst[i]->co_oc->soc_required;
4479 for (j=0; at[j]; j++) {
4480 for (a=e->e_attrs, prev=&e->e_attrs; a;
4481 prev = &(*prev)->a_next, a=a->a_next) {
4482 if ( a->a_desc == at[j]->sat_ad ) {
4496 if ( colst[i]->co_oc->soc_allowed ) {
4497 AttributeType **at = colst[i]->co_oc->soc_allowed;
4498 for (j=0; at[j]; j++) {
4499 for (a=e->e_attrs, prev=&e->e_attrs; a;
4500 prev = &(*prev)->a_next, a=a->a_next) {
4501 if ( a->a_desc == at[j]->sat_ad ) {
4517 tail->a_next = e->e_attrs;
4523 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
4525 Attribute *a = NULL;
4526 AttributeDescription *ad;
4536 Modifications *ml = ptr;
4538 vals = ml->sml_values;
4541 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
4542 rc = ordered_value_sort( a, 1 );
4544 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
4545 ad->ad_cname.bv_val );
4549 for ( i=0; vals[i].bv_val; i++ ) {
4550 ca->line = vals[i].bv_val;
4551 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
4552 ca->line[0] == '{' ) {
4553 char *idx = strchr( ca->line, '}' );
4554 if ( idx ) ca->line = idx+1;
4556 rc = config_parse_vals( ct, ca, i );
4565 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
4568 struct berval rtype, rval;
4570 AttributeDescription *ad = NULL;
4572 dnRdn( &e->e_name, rdn );
4573 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
4574 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
4575 rtype.bv_val = rdn->bv_val;
4576 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
4579 slap_bv2ad( &rtype, &ad, &rs->sr_text );
4580 a = attr_find( e->e_attrs, ad );
4581 if (!a ) return LDAP_NAMING_VIOLATION;
4588 config_rename_kids( CfEntryInfo *ce )
4591 struct berval rdn, nrdn;
4593 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
4594 struct berval newdn, newndn;
4595 dnRdn ( &ce2->ce_entry->e_name, &rdn );
4596 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
4597 build_new_dn( &newdn, &ce->ce_entry->e_name, &rdn, NULL );
4598 build_new_dn( &newndn, &ce->ce_entry->e_nname, &nrdn, NULL );
4599 free( ce2->ce_entry->e_name.bv_val );
4600 free( ce2->ce_entry->e_nname.bv_val );
4601 ce2->ce_entry->e_name = newdn;
4602 ce2->ce_entry->e_nname = newndn;
4603 config_rename_kids( ce2 );
4608 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
4609 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
4610 struct berval *nnewrdn, int use_ldif )
4614 struct berval odn, ondn;
4618 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
4619 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
4622 free( a->a_vals[0].bv_val );
4623 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
4624 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
4625 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
4626 strcpy( a->a_vals[0].bv_val, ptr1 );
4628 if ( a->a_nvals != a->a_vals ) {
4629 free( a->a_nvals[0].bv_val );
4630 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
4631 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
4632 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
4633 strcpy( a->a_nvals[0].bv_val, ptr1 );
4636 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
4637 BackendDB *be = op->o_bd;
4638 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4639 struct berval dn, ndn, xdn, xndn;
4641 op->o_bd = &cfb->cb_db;
4643 /* Save current rootdn; use the underlying DB's rootdn */
4647 xndn = op->o_req_ndn;
4648 op->o_dn = op->o_bd->be_rootdn;
4649 op->o_ndn = op->o_bd->be_rootndn;
4651 op->o_req_ndn = ondn;
4653 scp = op->o_callback;
4654 op->o_callback = ≻
4655 op->orr_newrdn = *newrdn;
4656 op->orr_nnewrdn = *nnewrdn;
4657 op->orr_newSup = NULL;
4658 op->orr_nnewSup = NULL;
4659 op->orr_deleteoldrdn = 1;
4660 op->orr_modlist = NULL;
4661 slap_modrdn2mods( op, rs );
4662 slap_mods_opattrs( op, &op->orr_modlist, 1 );
4663 rc = op->o_bd->be_modrdn( op, rs );
4664 slap_mods_free( op->orr_modlist, 1 );
4667 op->o_callback = scp;
4671 op->o_req_ndn = xndn;
4674 free( ondn.bv_val );
4676 config_rename_kids( e->e_private );
4681 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
4682 Entry *e, int idx, int tailindex, int use_ldif )
4684 struct berval ival, newrdn, nnewrdn;
4687 char ibuf[32], *ptr1, *ptr2 = NULL;
4690 rc = config_rename_attr( rs, e, &rdn, &a );
4691 if ( rc ) return rc;
4694 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
4695 if ( ival.bv_len >= sizeof( ibuf ) ) {
4696 return LDAP_NAMING_VIOLATION;
4699 newrdn.bv_len = rdn.bv_len + ival.bv_len;
4700 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
4703 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
4704 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4707 ptr2 = ber_bvchr( &rdn, '}' );
4711 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
4713 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
4714 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
4715 a->a_desc->ad_cname.bv_len );
4717 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4718 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
4722 /* Do the equivalent of ModRDN */
4723 /* Replace DN / NDN */
4724 newrdn.bv_len = ptr1 - newrdn.bv_val;
4725 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
4726 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
4728 free( nnewrdn.bv_val );
4729 free( newrdn.bv_val );
4734 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
4735 SlapReply *rs, int *renum, int *ibase )
4738 int index = -1, gotindex = 0, nsibs, rc = 0;
4739 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
4740 char *ptr1, *ptr2 = NULL;
4743 if ( renum ) *renum = 0;
4745 /* These entries don't get indexed/renumbered */
4746 if ( ce_type == Cft_Global ) return 0;
4747 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
4749 if ( ce_type == Cft_Module )
4752 /* See if the rdn has an index already */
4753 dnRdn( &e->e_name, &rdn );
4754 if ( ce_type == Cft_Database ) {
4755 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
4756 "frontend", STRLENOF("frontend") ))
4758 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
4759 "config", STRLENOF("config") ))
4762 ptr1 = ber_bvchr( &e->e_name, '{' );
4763 if ( ptr1 && ptr1 < &e->e_name.bv_val[ rdn.bv_len ] ) {
4765 ptr2 = strchr( ptr1, '}' );
4766 if ( !ptr2 || ptr2 > &e->e_name.bv_val[ rdn.bv_len ] )
4767 return LDAP_NAMING_VIOLATION;
4768 if ( ptr2-ptr1 == 1)
4769 return LDAP_NAMING_VIOLATION;
4771 index = strtol( ptr1 + 1, &next, 10 );
4772 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
4773 return LDAP_NAMING_VIOLATION;
4776 /* Special case, we allow -1 for the frontendDB */
4777 if ( index != -1 || !isfrontend )
4778 return LDAP_NAMING_VIOLATION;
4780 if ( isconfig && index != 0 ){
4781 return LDAP_NAMING_VIOLATION;
4785 /* count related kids.
4786 * For entries of type Cft_Misc, only count siblings with same RDN type
4788 if ( ce_type == Cft_Misc ) {
4789 rdn.bv_val = e->e_nname.bv_val;
4790 ptr1 = strchr( rdn.bv_val, '=' );
4791 assert( ptr1 != NULL );
4793 rdn.bv_len = ptr1 - rdn.bv_val;
4795 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
4797 if ( ce->ce_type != ce_type )
4800 dnRdn( &ce->ce_entry->e_nname, &rdn2 );
4802 ptr1 = strchr( rdn2.bv_val, '=' );
4803 assert( ptr1 != NULL );
4805 rdn2.bv_len = ptr1 - rdn2.bv_val;
4806 if ( bvmatch( &rdn, &rdn2 ))
4810 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
4811 if ( ce->ce_type == ce_type ) nsibs++;
4815 /* account for -1 frontend */
4816 if ( ce_type == Cft_Database )
4819 if ( index != nsibs ) {
4821 if ( index < nsibs ) {
4822 if ( tailindex ) return LDAP_NAMING_VIOLATION;
4823 /* Siblings need to be renumbered */
4824 if ( index != -1 || !isfrontend )
4828 /* config DB is always "0" */
4829 if ( isconfig && index == -1 ) {
4832 if (( !isfrontend && index == -1 ) || ( index > nsibs ) ){
4836 /* just make index = nsibs */
4838 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
4841 if ( ibase ) *ibase = index;
4842 if ( renum ) *renum = renumber;
4846 /* Insert all superior classes of the given class */
4848 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
4853 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
4854 if ( count_oc( *sups, copp, nocs ) ) {
4859 co.co_name = &oc->soc_cname;
4860 cop = avl_find( CfOcTree, &co, CfOc_cmp );
4864 /* check for duplicates */
4865 for ( i = 0; i < *nocs; i++ ) {
4866 if ( *copp && (*copp)[i] == cop ) {
4872 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
4873 if ( tmp == NULL ) {
4877 (*copp)[*nocs] = cop;
4885 /* Find all superior classes of the given objectclasses,
4886 * return list in order of most-subordinate first.
4888 * Special / auxiliary / Cft_Misc classes always take precedence.
4891 count_ocs( Attribute *oc_at, int *nocs )
4893 int i, j, misc = -1;
4894 ConfigOCs **colst = NULL;
4898 for ( i = oc_at->a_numvals; i--; ) {
4899 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
4901 assert( oc != NULL );
4902 if ( count_oc( oc, &colst, nocs ) ) {
4912 ConfigOCs *tmp = colst[i];
4913 colst[i] = colst[j];
4915 if (tmp->co_type == Cft_Misc)
4919 /* Move misc class to front of list */
4921 ConfigOCs *tmp = colst[misc];
4922 for (i=misc; i>0; i--)
4923 colst[i] = colst[i-1];
4931 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4933 /* Leftover from RE23. Never parse this entry */
4934 return LDAP_COMPARE_TRUE;
4938 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4942 /* This entry is hardcoded, don't re-parse it */
4943 if ( p->ce_type == Cft_Global ) {
4944 cfn = p->ce_private;
4945 ca->ca_private = cfn;
4946 return LDAP_COMPARE_TRUE;
4948 if ( p->ce_type != Cft_Schema )
4949 return LDAP_CONSTRAINT_VIOLATION;
4951 cfn = ch_calloc( 1, sizeof(ConfigFile) );
4952 ca->ca_private = cfn;
4953 cfo = p->ce_private;
4954 cfn->c_sibs = cfo->c_kids;
4956 return LDAP_SUCCESS;
4960 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4962 if ( p->ce_type != Cft_Global ) {
4963 return LDAP_CONSTRAINT_VIOLATION;
4965 /* config must be {0}, nothing else allowed */
4966 if ( !strncmp( e->e_nname.bv_val, "olcDatabase={0}", STRLENOF("olcDatabase={0}")) &&
4967 strncmp( e->e_nname.bv_val + STRLENOF("olcDatabase={0}"), "config,", STRLENOF("config,") )) {
4968 return LDAP_CONSTRAINT_VIOLATION;
4970 ca->be = frontendDB; /* just to get past check_vals */
4971 return LDAP_SUCCESS;
4975 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4977 if ( p->ce_type != Cft_Global ) {
4978 return LDAP_CONSTRAINT_VIOLATION;
4980 return LDAP_SUCCESS;
4984 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4986 if ( p->ce_type != Cft_Global ) {
4987 return LDAP_CONSTRAINT_VIOLATION;
4989 return LDAP_SUCCESS;
4993 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4995 if ( p->ce_type != Cft_Database ) {
4996 return LDAP_CONSTRAINT_VIOLATION;
4999 return LDAP_SUCCESS;
5003 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
5008 AttributeDescription *ad;
5014 if ( cfn->c_cr_head ) {
5015 struct berval bv = BER_BVC("olcDitContentRules");
5017 slap_bv2ad( &bv, &ad, &text );
5018 ct = config_find_table( colst, nocs, ad, ca );
5019 config_del_vals( ct, ca );
5021 if ( cfn->c_oc_head ) {
5022 struct berval bv = BER_BVC("olcObjectClasses");
5024 slap_bv2ad( &bv, &ad, &text );
5025 ct = config_find_table( colst, nocs, ad, ca );
5026 config_del_vals( ct, ca );
5028 if ( cfn->c_at_head ) {
5029 struct berval bv = BER_BVC("olcAttributeTypes");
5031 slap_bv2ad( &bv, &ad, &text );
5032 ct = config_find_table( colst, nocs, ad, ca );
5033 config_del_vals( ct, ca );
5035 if ( cfn->c_syn_head ) {
5036 struct berval bv = BER_BVC("olcLdapSyntaxes");
5038 slap_bv2ad( &bv, &ad, &text );
5039 ct = config_find_table( colst, nocs, ad, ca );
5040 config_del_vals( ct, ca );
5042 if ( cfn->c_om_head ) {
5043 struct berval bv = BER_BVC("olcObjectIdentifier");
5045 slap_bv2ad( &bv, &ad, &text );
5046 ct = config_find_table( colst, nocs, ad, ca );
5047 config_del_vals( ct, ca );
5049 cfo = p->ce_private;
5050 cfo->c_kids = cfn->c_sibs;
5055 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
5057 int rc = LDAP_CONSTRAINT_VIOLATION;
5060 if ( (*cop)->co_ldadd ) {
5061 rc = (*cop)->co_ldadd( last, e, ca );
5062 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
5067 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
5068 ConfigOCs co = { 0 };
5070 co.co_name = &(*ocp)->soc_cname;
5071 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
5072 if ( *cop == NULL ) {
5076 rc = config_add_oc( cop, last, e, ca );
5077 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
5085 /* Parse an LDAP entry into config directives */
5087 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
5088 int *renum, Operation *op )
5090 CfEntryInfo *ce, *last = NULL;
5091 ConfigOCs co, *coptr, **colst;
5092 Attribute *a, *oc_at, *soc_at;
5093 int i, ibase = -1, nocs, rc = 0;
5096 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
5098 memset( ca, 0, sizeof(ConfigArgs));
5100 /* Make sure parent exists and entry does not. But allow
5101 * Databases and Overlays to be inserted. Don't do any
5102 * auto-renumbering if manageDSAit control is present.
5104 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
5106 if ( ( op && op->o_managedsait ) ||
5107 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
5108 ce->ce_type != Cft_Module ) )
5110 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5111 "DN=\"%s\" already exists\n",
5112 log_prefix, e->e_name.bv_val, 0 );
5113 /* global schema ignores all writes */
5114 if ( ce->ce_type == Cft_Schema && ce->ce_parent->ce_type == Cft_Global )
5115 return LDAP_COMPARE_TRUE;
5116 return LDAP_ALREADY_EXISTS;
5120 dnParent( &e->e_nname, &pdn );
5122 /* If last is NULL, the new entry is the root/suffix entry,
5123 * otherwise last should be the parent.
5125 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
5127 rs->sr_matched = last->ce_entry->e_name.bv_val;
5129 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5130 "DN=\"%s\" not child of DN=\"%s\"\n",
5131 log_prefix, e->e_name.bv_val,
5132 last->ce_entry->e_name.bv_val );
5133 return LDAP_NO_SUCH_OBJECT;
5137 /* No parent, must be root. This will never happen... */
5138 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
5139 return LDAP_NO_SUCH_OBJECT;
5142 if ( last && !access_allowed( op, last->ce_entry,
5143 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
5145 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5146 "DN=\"%s\" no write access to \"children\" of parent\n",
5147 log_prefix, e->e_name.bv_val, 0 );
5148 return LDAP_INSUFFICIENT_ACCESS;
5152 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5154 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5155 "DN=\"%s\" no objectClass\n",
5156 log_prefix, e->e_name.bv_val, 0 );
5157 return LDAP_OBJECT_CLASS_VIOLATION;
5160 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
5162 ObjectClass *soc = NULL;
5163 char textbuf[ SLAP_TEXT_BUFLEN ];
5164 const char *text = textbuf;
5166 /* FIXME: check result */
5167 rc = structural_class( oc_at->a_nvals, &soc, NULL,
5168 &text, textbuf, sizeof(textbuf), NULL );
5169 if ( rc != LDAP_SUCCESS ) {
5170 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5171 "DN=\"%s\" no structural objectClass (%s)\n",
5172 log_prefix, e->e_name.bv_val, text );
5175 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
5176 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
5177 if ( soc_at == NULL ) {
5178 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5179 "DN=\"%s\" no structural objectClass; "
5180 "unable to merge computed class %s\n",
5181 log_prefix, e->e_name.bv_val,
5182 soc->soc_cname.bv_val );
5183 return LDAP_OBJECT_CLASS_VIOLATION;
5186 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5187 "DN=\"%s\" no structural objectClass; "
5188 "computed objectClass %s merged\n",
5189 log_prefix, e->e_name.bv_val,
5190 soc->soc_cname.bv_val );
5193 /* Fake the coordinates based on whether we're part of an
5194 * LDAP Add or if reading the config dir
5197 ca->fname = "slapd";
5200 ca->fname = cfdir.bv_val;
5205 co.co_name = &soc_at->a_nvals[0];
5206 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
5207 if ( coptr == NULL ) {
5208 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5209 "DN=\"%s\" no structural objectClass in configuration table\n",
5210 log_prefix, e->e_name.bv_val, 0 );
5211 return LDAP_OBJECT_CLASS_VIOLATION;
5214 /* Only the root can be Cft_Global, everything else must
5215 * have a parent. Only limited nesting arrangements are allowed.
5217 rc = LDAP_CONSTRAINT_VIOLATION;
5218 if ( coptr->co_type == Cft_Global && !last ) {
5219 cfn = cfb->cb_config;
5220 ca->ca_private = cfn;
5221 ca->be = frontendDB; /* just to get past check_vals */
5225 colst = count_ocs( oc_at, &nocs );
5227 /* Check whether the Add is allowed by its parent, and do
5228 * any necessary arg setup
5231 rc = config_add_oc( &coptr, last, e, ca );
5232 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
5233 for ( i = 0; i<nocs; i++ ) {
5234 /* Already checked these */
5235 if ( colst[i]->co_oc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
5237 if ( colst[i]->co_ldadd &&
5238 ( rc = colst[i]->co_ldadd( last, e, ca ))
5239 != LDAP_CONSTRAINT_VIOLATION ) {
5245 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
5246 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5247 "DN=\"%s\" no structural objectClass add function\n",
5248 log_prefix, e->e_name.bv_val, 0 );
5249 return LDAP_OBJECT_CLASS_VIOLATION;
5253 /* Add the entry but don't parse it, we already have its contents */
5254 if ( rc == LDAP_COMPARE_TRUE ) {
5259 if ( rc != LDAP_SUCCESS )
5262 /* Parse all the values and check for simple syntax errors before
5263 * performing any set actions.
5265 * If doing an LDAPadd, check for indexed names and any necessary
5266 * renaming/renumbering. Entries that don't need indexed names are
5267 * ignored. Entries that need an indexed name and arrive without one
5268 * are assigned to the end. Entries that arrive with an index may
5269 * cause the following entries to be renumbered/bumped down.
5271 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
5272 * don't allow Adding an entry with an index that's already in use.
5273 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
5275 * These entries can have auto-assigned indexes (appended to the end)
5276 * but only the other types support auto-renumbering of siblings.
5279 rc = check_name_index( last, coptr->co_type, e, rs, renum,
5284 if ( renum && *renum && coptr->co_type != Cft_Database &&
5285 coptr->co_type != Cft_Overlay )
5287 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
5288 "operation requires sibling renumbering" );
5289 rc = LDAP_UNWILLING_TO_PERFORM;
5294 init_config_argv( ca );
5296 /* Make sure we process attrs in the required order */
5297 sort_attrs( e, colst, nocs );
5299 for ( a = e->e_attrs; a; a = a->a_next ) {
5300 if ( a == oc_at ) continue;
5301 ct = config_find_table( colst, nocs, a->a_desc, ca );
5302 if ( !ct ) continue; /* user data? */
5303 rc = check_vals( ct, ca, a, 1 );
5304 if ( rc ) goto done_noop;
5307 /* Basic syntax checks are OK. Do the actual settings. */
5308 for ( a=e->e_attrs; a; a=a->a_next ) {
5309 if ( a == oc_at ) continue;
5310 ct = config_find_table( colst, nocs, a->a_desc, ca );
5311 if ( !ct ) continue; /* user data? */
5312 for (i=0; a->a_vals[i].bv_val; i++) {
5315 ca->line = a->a_vals[i].bv_val;
5316 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
5317 ptr = strchr( ca->line, '}' );
5319 iptr = strchr( ca->line, '{' );
5323 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
5325 ca->valx = strtol( iptr+1, NULL, 0 );
5330 rc = config_parse_add( ct, ca, i );
5338 /* Newly added databases and overlays need to be started up */
5339 if ( CONFIG_ONLINE_ADD( ca )) {
5340 if ( coptr->co_type == Cft_Database ) {
5341 rc = backend_startup_one( ca->be, &ca->reply );
5343 } else if ( coptr->co_type == Cft_Overlay ) {
5344 if ( ca->bi->bi_db_open ) {
5345 BackendInfo *bi_orig = ca->be->bd_info;
5346 ca->be->bd_info = ca->bi;
5347 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
5348 ca->be->bd_info = bi_orig;
5350 } else if ( ca->cleanup ) {
5351 rc = ca->cleanup( ca );
5354 if (ca->cr_msg[0] == '\0')
5355 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
5357 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
5358 ca->log, ca->cr_msg, ca->argv[1] );
5365 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5366 ce->ce_parent = last;
5367 ce->ce_entry = entry_dup( e );
5368 ce->ce_entry->e_private = ce;
5369 ce->ce_type = coptr->co_type;
5372 ce->ce_private = ca->ca_private;
5373 ca->ca_entry = ce->ce_entry;
5376 } else if ( last->ce_kids ) {
5377 CfEntryInfo *c2, **cprev;
5379 /* Advance to first of this type */
5380 cprev = &last->ce_kids;
5381 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
5382 cprev = &c2->ce_sibs;
5385 /* Account for the (-1) frontendDB entry */
5386 if ( ce->ce_type == Cft_Database ) {
5387 if ( ca->be == frontendDB )
5389 else if ( ibase != -1 )
5394 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
5395 cprev = &c2->ce_sibs;
5401 for ( i=0; i<ibase; i++ ) {
5403 cprev = &c2->ce_sibs;
5406 ce->ce_sibs = *cprev;
5414 if ( (coptr->co_type == Cft_Database) && ca->be ) {
5415 if ( ca->be != frontendDB )
5416 backend_destroy_one( ca->be, 1 );
5417 } else if ( (coptr->co_type == Cft_Overlay) && ca->bi ) {
5418 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
5419 } else if ( coptr->co_type == Cft_Schema ) {
5420 schema_destroy_one( ca, colst, nocs, last );
5425 ch_free( ca->argv );
5426 if ( colst ) ch_free( colst );
5430 #define BIGTMP 10000
5432 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5433 int base, int rebase, int max, int use_ldif )
5435 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
5436 ConfigType etype = ce->ce_type;
5437 int count = 0, rc = 0;
5439 /* Reverse ce list */
5440 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
5441 if (ce2->ce_type != etype) {
5446 ce2->ce_sibs = cetmp;
5449 if ( max && count >= max ) {
5455 /* Move original to a temp name until increments are done */
5457 ce->ce_entry->e_private = NULL;
5458 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5459 base+BIGTMP, 0, use_ldif );
5460 ce->ce_entry->e_private = ce;
5462 /* start incrementing */
5463 for (ce2=cetmp; ce2; ce2=ce3) {
5465 ce2->ce_sibs = cerem;
5468 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5469 count+base, 0, use_ldif );
5473 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5474 base, 0, use_ldif );
5479 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5480 CfEntryInfo *ce2, int old, int use_ldif )
5484 /* Renumber original to a temp value */
5485 ce->ce_entry->e_private = NULL;
5486 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5487 old+BIGTMP, 0, use_ldif );
5488 ce->ce_entry->e_private = ce;
5490 /* start decrementing */
5491 for (; ce2 != ce; ce2=ce2->ce_sibs) {
5492 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5493 count+old, 0, use_ldif );
5496 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5497 count+old, 0, use_ldif );
5500 /* Parse an LDAP entry into config directives, then store in underlying
5504 config_back_add( Operation *op, SlapReply *rs )
5510 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
5511 NULL, ACL_WADD, NULL )) {
5512 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5517 * Check for attribute ACL
5519 if ( !acl_check_modlist( op, op->ora_e, op->orm_modlist )) {
5520 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5521 rs->sr_text = "no write access to attribute";
5525 cfb = (CfBackInfo *)op->o_bd->be_private;
5527 /* add opattrs for syncprov */
5529 char textbuf[SLAP_TEXT_BUFLEN];
5530 size_t textlen = sizeof textbuf;
5531 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1, NULL,
5532 &rs->sr_text, textbuf, sizeof( textbuf ) );
5533 if ( rs->sr_err != LDAP_SUCCESS )
5535 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
5536 if ( rs->sr_err != LDAP_SUCCESS ) {
5537 Debug( LDAP_DEBUG_TRACE,
5538 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
5539 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
5544 if ( op->o_abandon ) {
5545 rs->sr_err = SLAPD_ABANDON;
5548 ldap_pvt_thread_pool_pause( &connection_pool );
5551 * 1) check for existence of entry
5552 * 2) check for sibling renumbering
5553 * 3) perform internal add
5554 * 4) perform any necessary renumbering
5555 * 5) store entry in underlying database
5557 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
5558 if ( rs->sr_err != LDAP_SUCCESS ) {
5559 rs->sr_text = ca.cr_msg;
5564 CfEntryInfo *ce = ca.ca_entry->e_private;
5565 req_add_s addr = op->oq_add;
5566 op->o_tag = LDAP_REQ_MODRDN;
5567 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
5568 op->o_tag = LDAP_REQ_ADD;
5570 if ( rs->sr_err != LDAP_SUCCESS ) {
5575 if ( cfb->cb_use_ldif ) {
5576 BackendDB *be = op->o_bd;
5577 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5578 struct berval dn, ndn;
5580 op->o_bd = &cfb->cb_db;
5582 /* Save current rootdn; use the underlying DB's rootdn */
5585 op->o_dn = op->o_bd->be_rootdn;
5586 op->o_ndn = op->o_bd->be_rootndn;
5588 scp = op->o_callback;
5589 op->o_callback = ≻
5590 op->o_bd->be_add( op, rs );
5592 op->o_callback = scp;
5598 ldap_pvt_thread_pool_resume( &connection_pool );
5601 { int repl = op->o_dont_replicate;
5602 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
5603 rs->sr_text = NULL; /* Set after config_add_internal */
5604 rs->sr_err = LDAP_SUCCESS;
5605 op->o_dont_replicate = 1;
5607 send_ldap_result( op, rs );
5608 op->o_dont_replicate = repl;
5610 slap_graduate_commit_csn( op );
5614 typedef struct delrec {
5615 struct delrec *next;
5621 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
5627 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
5628 ca->line[0] == '{' )
5630 char *ptr = strchr( ca->line + 1, '}' );
5634 ca->valx = strtol( ca->line + 1, &next, 0 );
5635 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
5641 rc = config_parse_add( ct, ca, i );
5649 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
5652 int rc = LDAP_UNWILLING_TO_PERFORM;
5654 Entry *e = ce->ce_entry;
5655 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
5660 delrec *dels = NULL, *deltail = NULL;
5662 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5663 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
5665 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5666 if (ml->sml_desc == slap_schema.si_ad_objectClass)
5670 colst = count_ocs( oc_at, &nocs );
5672 /* make sure add/del flags are clear; should always be true */
5673 for ( s = save_attrs; s; s = s->a_next ) {
5674 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
5677 e->e_attrs = attrs_dup( e->e_attrs );
5679 init_config_argv( ca );
5682 ca->ca_private = ce->ce_private;
5684 ca->fname = "slapd";
5686 strcpy( ca->log, "back-config" );
5688 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5689 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5690 switch (ml->sml_op) {
5691 case LDAP_MOD_DELETE:
5692 case LDAP_MOD_REPLACE:
5693 case SLAP_MOD_SOFTDEL:
5695 BerVarray vals = NULL, nvals = NULL;
5697 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
5699 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
5700 ml->sml_desc->ad_cname.bv_val );
5703 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5704 vals = ml->sml_values;
5705 nvals = ml->sml_nvalues;
5706 ml->sml_values = NULL;
5707 ml->sml_nvalues = NULL;
5709 /* If we're deleting by values, remember the indexes of the
5710 * values we deleted.
5712 if ( ct && ml->sml_values ) {
5714 i = ml->sml_numvals;
5715 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
5726 rc = modify_delete_vindex(e, &ml->sml_mod,
5727 get_permissiveModify(op),
5728 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
5729 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5730 ml->sml_values = vals;
5731 ml->sml_nvalues = nvals;
5733 if ( rc == LDAP_NO_SUCH_ATTRIBUTE && ml->sml_op == SLAP_MOD_SOFTDEL )
5737 /* FIXME: check rc before fallthru? */
5741 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5743 case SLAP_MOD_ADD_IF_NOT_PRESENT:
5744 if ( ml->sml_op == SLAP_MOD_ADD_IF_NOT_PRESENT
5745 && attr_find( e->e_attrs, ml->sml_desc ) )
5752 case SLAP_MOD_SOFTADD: {
5753 int mop = ml->sml_op;
5755 ml->sml_op = LDAP_MOD_ADD;
5757 if ( ct->arg_type & ARG_NO_INSERT ) {
5758 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
5760 navals = a->a_numvals;
5763 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
5764 if ( ml->sml_values[i].bv_val[0] == '{' &&
5767 char *next, *val = ml->sml_values[i].bv_val + 1;
5770 j = strtol( val, &next, 0 );
5771 if ( next == val || next[ 0 ] != '}' || j < navals ) {
5773 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
5774 ml->sml_desc->ad_cname.bv_val );
5778 rc = check_vals( ct, ca, ml, 0 );
5779 if ( rc ) goto out_noop;
5782 rc = modify_add_values(e, &ml->sml_mod,
5783 get_permissiveModify(op),
5784 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5786 /* If value already exists, show success here
5787 * and ignore this operation down below.
5789 if ( mop == SLAP_MOD_SOFTADD ) {
5790 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
5800 case LDAP_MOD_INCREMENT: /* FIXME */
5805 if(rc != LDAP_SUCCESS) break;
5808 if ( rc == LDAP_SUCCESS) {
5809 /* check that the entry still obeys the schema */
5810 rc = entry_schema_check(op, e, NULL, 0, 0, NULL,
5811 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5813 if ( rc ) goto out_noop;
5815 /* Basic syntax checks are OK. Do the actual settings. */
5816 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5817 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5818 if ( !ct ) continue;
5820 s = attr_find( save_attrs, ml->sml_desc );
5821 a = attr_find( e->e_attrs, ml->sml_desc );
5823 switch (ml->sml_op) {
5824 case LDAP_MOD_DELETE:
5825 case LDAP_MOD_REPLACE: {
5826 BerVarray vals = NULL, nvals = NULL;
5829 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5830 vals = ml->sml_values;
5831 nvals = ml->sml_nvalues;
5832 ml->sml_values = NULL;
5833 ml->sml_nvalues = NULL;
5836 if ( ml->sml_values )
5839 /* If we didn't delete the whole attribute */
5840 if ( ml->sml_values && a ) {
5841 struct berval *mvals;
5844 if ( ml->sml_nvalues )
5845 mvals = ml->sml_nvalues;
5847 mvals = ml->sml_values;
5849 /* use the indexes we saved up above */
5850 for (i=0; i < d->nidx; i++) {
5851 struct berval bv = *mvals++;
5852 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
5853 bv.bv_val[0] == '{' ) {
5854 ptr = strchr( bv.bv_val, '}' ) + 1;
5855 bv.bv_len -= ptr - bv.bv_val;
5858 ca->line = bv.bv_val;
5859 ca->valx = d->idx[i];
5860 config_parse_vals(ct, ca, d->idx[i] );
5861 rc = config_del_vals( ct, ca );
5862 if ( rc != LDAP_SUCCESS ) break;
5864 s->a_flags |= SLAP_ATTR_IXDEL;
5865 for (j=i+1; j < d->nidx; j++)
5866 if ( d->idx[j] >d->idx[i] )
5873 rc = config_del_vals( ct, ca );
5874 if ( rc ) rc = LDAP_OTHER;
5876 s->a_flags |= SLAP_ATTR_IXDEL;
5878 if ( ml->sml_values ) {
5883 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5884 ml->sml_values = vals;
5885 ml->sml_nvalues = nvals;
5887 if ( !vals || rc != LDAP_SUCCESS )
5890 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5895 for (i=0; ml->sml_values[i].bv_val; i++) {
5896 ca->line = ml->sml_values[i].bv_val;
5898 rc = config_modify_add( ct, ca, ml->sml_desc, i );
5901 a->a_flags |= SLAP_ATTR_IXADD;
5908 /* Undo for a failed operation */
5909 if ( rc != LDAP_SUCCESS ) {
5910 ConfigReply msg = ca->reply;
5911 for ( s = save_attrs; s; s = s->a_next ) {
5912 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
5913 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5914 ct = config_find_table( colst, nocs, s->a_desc, ca );
5915 a = attr_find( e->e_attrs, s->a_desc );
5917 /* clear the flag so the add check below will skip it */
5918 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5922 config_del_vals( ct, ca );
5924 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5925 ca->line = s->a_vals[i].bv_val;
5927 config_modify_add( ct, ca, s->a_desc, i );
5931 for ( a = e->e_attrs; a; a = a->a_next ) {
5932 if ( a->a_flags & SLAP_ATTR_IXADD ) {
5933 ct = config_find_table( colst, nocs, a->a_desc, ca );
5937 config_del_vals( ct, ca );
5938 s = attr_find( save_attrs, a->a_desc );
5940 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5941 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5942 ca->line = s->a_vals[i].bv_val;
5944 config_modify_add( ct, ca, s->a_desc, i );
5955 if ( rc == LDAP_SUCCESS ) {
5956 attrs_free( save_attrs );
5959 attrs_free( e->e_attrs );
5960 e->e_attrs = save_attrs;
5962 ch_free( ca->argv );
5963 if ( colst ) ch_free( colst );
5965 deltail = dels->next;
5974 config_back_modify( Operation *op, SlapReply *rs )
5977 CfEntryInfo *ce, *last;
5979 ConfigArgs ca = {0};
5982 AttributeDescription *rad = NULL;
5985 cfb = (CfBackInfo *)op->o_bd->be_private;
5987 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5990 rs->sr_matched = last->ce_entry->e_name.bv_val;
5991 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5995 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
5996 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6000 /* Get type of RDN */
6001 rdn = ce->ce_entry->e_nname;
6002 ptr = strchr( rdn.bv_val, '=' );
6003 rdn.bv_len = ptr - rdn.bv_val;
6004 rs->sr_err = slap_bv2ad( &rdn, &rad, &rs->sr_text );
6005 if ( rs->sr_err != LDAP_SUCCESS ) {
6009 /* Some basic validation... */
6010 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
6011 /* Don't allow Modify of RDN; must use ModRdn for that. */
6012 if ( ml->sml_desc == rad ) {
6013 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
6014 rs->sr_text = "Use modrdn to change the entry name";
6017 /* Internal update of contextCSN? */
6018 if ( ml->sml_desc == slap_schema.si_ad_contextCSN && op->o_conn->c_conn_idx == -1 ) {
6024 slap_mods_opattrs( op, &op->orm_modlist, 1 );
6027 if ( op->o_abandon ) {
6028 rs->sr_err = SLAPD_ABANDON;
6031 ldap_pvt_thread_pool_pause( &connection_pool );
6035 * 1) perform the Modify on the cached Entry.
6036 * 2) verify that the Entry still satisfies the schema.
6037 * 3) perform the individual config operations.
6038 * 4) store Modified entry in underlying LDIF backend.
6040 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
6042 rs->sr_text = ca.cr_msg;
6043 } else if ( cfb->cb_use_ldif ) {
6044 BackendDB *be = op->o_bd;
6045 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
6046 struct berval dn, ndn;
6048 op->o_bd = &cfb->cb_db;
6052 op->o_dn = op->o_bd->be_rootdn;
6053 op->o_ndn = op->o_bd->be_rootndn;
6055 scp = op->o_callback;
6056 op->o_callback = ≻
6057 op->o_bd->be_modify( op, rs );
6059 op->o_callback = scp;
6065 ldap_pvt_thread_pool_resume( &connection_pool );
6067 send_ldap_result( op, rs );
6068 slap_graduate_commit_csn( op );
6073 config_back_modrdn( Operation *op, SlapReply *rs )
6076 CfEntryInfo *ce, *last;
6080 cfb = (CfBackInfo *)op->o_bd->be_private;
6082 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6085 rs->sr_matched = last->ce_entry->e_name.bv_val;
6086 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6089 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
6090 NULL, ACL_WRITE, NULL )) {
6091 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6095 if ( ce->ce_parent )
6096 parent = ce->ce_parent->ce_entry;
6098 parent = (Entry *)&slap_entry_root;
6099 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
6100 NULL, ACL_WRITE, NULL )) {
6101 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6106 /* We don't allow moving objects to new parents.
6107 * Generally we only allow reordering a set of ordered entries.
6109 if ( op->orr_newSup ) {
6110 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6114 /* If newRDN == oldRDN, quietly succeed */
6115 dnRdn( &op->o_req_ndn, &rdn );
6116 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
6117 rs->sr_err = LDAP_SUCCESS;
6121 /* Current behavior, subject to change as needed:
6123 * For backends and overlays, we only allow renumbering.
6124 * For schema, we allow renaming with the same number.
6125 * Otherwise, the op is not allowed.
6128 if ( ce->ce_type == Cft_Schema ) {
6132 /* Can't alter the main cn=schema entry */
6133 if ( ce->ce_parent->ce_type == Cft_Global ) {
6134 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6135 rs->sr_text = "renaming not allowed for this entry";
6139 /* We could support this later if desired */
6140 ptr1 = ber_bvchr( &rdn, '}' );
6141 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
6142 len = ptr1 - rdn.bv_val;
6143 if ( len != ptr2 - op->orr_newrdn.bv_val ||
6144 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
6145 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6146 rs->sr_text = "schema reordering not supported";
6149 } else if ( ce->ce_type == Cft_Database ||
6150 ce->ce_type == Cft_Overlay ) {
6151 char *ptr1, *ptr2, *iptr1, *iptr2;
6154 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
6155 if ( *iptr2 != '{' ) {
6156 rs->sr_err = LDAP_NAMING_VIOLATION;
6157 rs->sr_text = "new ordering index is required";
6161 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
6162 ptr1 = ber_bvchr( &rdn, '}' );
6163 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
6165 rs->sr_err = LDAP_NAMING_VIOLATION;
6166 rs->sr_text = "new ordering index is required";
6170 len1 = ptr1 - rdn.bv_val;
6171 len2 = ptr2 - op->orr_newrdn.bv_val;
6173 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
6174 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
6175 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6176 rs->sr_text = "changing database/overlay type not allowed";
6179 ixold = strtol( iptr1, NULL, 0 );
6180 ixnew = strtol( iptr2, &ptr1, 0 );
6181 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
6182 rs->sr_err = LDAP_NAMING_VIOLATION;
6185 /* config DB is always 0, cannot be changed */
6186 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
6187 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
6191 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6192 rs->sr_text = "renaming not supported for this entry";
6196 if ( op->o_abandon ) {
6197 rs->sr_err = SLAPD_ABANDON;
6200 ldap_pvt_thread_pool_pause( &connection_pool );
6202 if ( ce->ce_type == Cft_Schema ) {
6203 req_modrdn_s modr = op->oq_modrdn;
6206 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
6207 if ( rs->sr_err == LDAP_SUCCESS ) {
6208 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
6209 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
6212 op->oq_modrdn = modr;
6214 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
6215 req_modrdn_s modr = op->oq_modrdn;
6218 /* Advance to first of this type */
6219 cprev = &ce->ce_parent->ce_kids;
6220 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
6221 cprev = &ce2->ce_sibs;
6224 /* Skip the -1 entry */
6225 if ( ce->ce_type == Cft_Database ) {
6226 cprev = &ce2->ce_sibs;
6232 /* Remove from old slot */
6233 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
6234 cprev = &ce2->ce_sibs;
6235 *cprev = ce->ce_sibs;
6236 ceold = ce->ce_sibs;
6238 /* Insert into new slot */
6240 for ( i=0; i<ixnew; i++ ) {
6244 cprev = &ce2->ce_sibs;
6246 ce->ce_sibs = *cprev;
6251 /* NOTE: These should be encoded in the OC tables, not inline here */
6252 if ( ce->ce_type == Cft_Database )
6253 backend_db_move( ce->ce_be, ixnew );
6254 else if ( ce->ce_type == Cft_Overlay )
6255 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
6257 if ( ixold < ixnew ) {
6258 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
6261 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
6262 ixold - ixnew, cfb->cb_use_ldif );
6264 op->oq_modrdn = modr;
6267 ldap_pvt_thread_pool_resume( &connection_pool );
6269 send_ldap_result( op, rs );
6274 config_back_delete( Operation *op, SlapReply *rs )
6276 #ifdef SLAP_CONFIG_DELETE
6278 CfEntryInfo *ce, *last, *ce2;
6280 cfb = (CfBackInfo *)op->o_bd->be_private;
6282 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6285 rs->sr_matched = last->ce_entry->e_name.bv_val;
6286 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6287 } else if ( ce->ce_kids ) {
6288 rs->sr_err = LDAP_NOT_ALLOWED_ON_NONLEAF;
6289 } else if ( op->o_abandon ) {
6290 rs->sr_err = SLAPD_ABANDON;
6291 } else if ( ce->ce_type == Cft_Overlay ||
6292 ce->ce_type == Cft_Database ||
6293 ce->ce_type == Cft_Misc ){
6297 ldap_pvt_thread_pool_pause( &connection_pool );
6299 if ( ce->ce_type == Cft_Overlay ){
6300 overlay_remove( ce->ce_be, (slap_overinst *)ce->ce_bi, op );
6301 } else if ( ce->ce_type == Cft_Misc ) {
6303 * only Cft_Misc objects that have a co_lddel handler set in
6304 * the ConfigOCs struct can be deleted. This code also
6305 * assumes that the entry can be only have one objectclass
6306 * with co_type == Cft_Misc
6308 ConfigOCs co, *coptr;
6312 oc_at = attr_find( ce->ce_entry->e_attrs,
6313 slap_schema.si_ad_objectClass );
6315 rs->sr_err = LDAP_OTHER;
6316 rs->sr_text = "objectclass not found";
6317 ldap_pvt_thread_pool_resume( &connection_pool );
6320 for ( i=0; !BER_BVISNULL(&oc_at->a_nvals[i]); i++ ) {
6321 co.co_name = &oc_at->a_nvals[i];
6322 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
6323 if ( coptr == NULL || coptr->co_type != Cft_Misc ) {
6326 if ( ! coptr->co_lddel || coptr->co_lddel( ce, op ) ){
6327 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6328 if ( ! coptr->co_lddel ) {
6329 rs->sr_text = "No delete handler found";
6331 rs->sr_err = LDAP_OTHER;
6332 /* FIXME: We should return a helpful error message
6335 ldap_pvt_thread_pool_resume( &connection_pool );
6340 } else if (ce->ce_type == Cft_Database ) {
6341 if ( ce->ce_be == frontendDB || ce->ce_be == op->o_bd ){
6342 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6343 rs->sr_text = "Cannot delete config or frontend database";
6344 ldap_pvt_thread_pool_resume( &connection_pool );
6347 if ( ce->ce_be->bd_info->bi_db_close ) {
6348 ce->ce_be->bd_info->bi_db_close( ce->ce_be, NULL );
6350 backend_destroy_one( ce->ce_be, 1);
6353 /* remove CfEntryInfo from the siblings list */
6354 if ( ce->ce_parent->ce_kids == ce ) {
6355 ce->ce_parent->ce_kids = ce->ce_sibs;
6357 for ( ce2 = ce->ce_parent->ce_kids ; ce2; ce2 = ce2->ce_sibs ) {
6358 if ( ce2->ce_sibs == ce ) {
6359 ce2->ce_sibs = ce->ce_sibs;
6365 /* remove from underlying database */
6366 if ( cfb->cb_use_ldif ) {
6367 BackendDB *be = op->o_bd;
6368 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
6369 struct berval dn, ndn, req_dn, req_ndn;
6371 op->o_bd = &cfb->cb_db;
6375 req_dn = op->o_req_dn;
6376 req_ndn = op->o_req_ndn;
6378 op->o_dn = op->o_bd->be_rootdn;
6379 op->o_ndn = op->o_bd->be_rootndn;
6380 op->o_req_dn = ce->ce_entry->e_name;
6381 op->o_req_ndn = ce->ce_entry->e_nname;
6383 scp = op->o_callback;
6384 op->o_callback = ≻
6385 op->o_bd->be_delete( op, rs );
6387 op->o_callback = scp;
6390 op->o_req_dn = req_dn;
6391 op->o_req_ndn = req_ndn;
6394 /* renumber siblings */
6395 iptr = ber_bvchr( &op->o_req_ndn, '{' ) + 1;
6396 ixold = strtol( iptr, NULL, 0 );
6397 for (ce2 = ce->ce_sibs, count=0; ce2; ce2=ce2->ce_sibs) {
6398 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
6399 count+ixold, 0, cfb->cb_use_ldif );
6403 ce->ce_entry->e_private=NULL;
6404 entry_free(ce->ce_entry);
6406 ldap_pvt_thread_pool_resume( &connection_pool );
6408 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6412 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6413 #endif /* SLAP_CONFIG_DELETE */
6414 send_ldap_result( op, rs );
6419 config_back_search( Operation *op, SlapReply *rs )
6422 CfEntryInfo *ce, *last;
6425 cfb = (CfBackInfo *)op->o_bd->be_private;
6427 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6430 rs->sr_matched = last->ce_entry->e_name.bv_val;
6431 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6434 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
6435 ACL_SEARCH, NULL, &mask ))
6437 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
6438 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6440 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6444 switch ( op->ors_scope ) {
6445 case LDAP_SCOPE_BASE:
6446 case LDAP_SCOPE_SUBTREE:
6447 rs->sr_err = config_send( op, rs, ce, 0 );
6450 case LDAP_SCOPE_ONELEVEL:
6451 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
6452 rs->sr_err = config_send( op, rs, ce, 1 );
6461 send_ldap_result( op, rs );
6465 /* no-op, we never free entries */
6466 int config_entry_release(
6471 if ( !e->e_private ) {
6474 return LDAP_SUCCESS;
6477 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
6479 int config_back_entry_get(
6483 AttributeDescription *at,
6488 CfEntryInfo *ce, *last;
6489 int rc = LDAP_NO_SUCH_OBJECT;
6491 cfb = (CfBackInfo *)op->o_bd->be_private;
6493 ce = config_find_base( cfb->cb_root, ndn, &last );
6495 *ent = ce->ce_entry;
6498 if ( oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
6499 rc = LDAP_NO_SUCH_ATTRIBUTE;
6509 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
6510 ConfigTable *ct, ConfigArgs *c )
6514 for (; at && *at; at++) {
6515 /* Skip the naming attr */
6516 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
6518 for (i=0;ct[i].name;i++) {
6519 if (ct[i].ad == (*at)->sat_ad) {
6520 rc = config_get_vals(&ct[i], c);
6521 /* NOTE: tolerate that config_get_vals()
6522 * returns success with no values */
6523 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
6524 if ( c->rvalue_nvals )
6525 rc = attr_merge(e, ct[i].ad, c->rvalue_vals,
6528 slap_syntax_validate_func *validate =
6529 ct[i].ad->ad_type->sat_syntax->ssyn_validate;
6532 for ( j=0; c->rvalue_vals[j].bv_val; j++ ) {
6533 rc = ordered_value_validate( ct[i].ad,
6534 &c->rvalue_vals[j], LDAP_MOD_ADD );
6536 Debug( LDAP_DEBUG_ANY,
6537 "config_build_attrs: error %d on %s value #%d\n",
6538 rc, ct[i].ad->ad_cname.bv_val, j );
6544 rc = attr_merge_normalize(e, ct[i].ad,
6545 c->rvalue_vals, NULL);
6547 ber_bvarray_free( c->rvalue_nvals );
6548 ber_bvarray_free( c->rvalue_vals );
6550 Debug( LDAP_DEBUG_ANY,
6551 "config_build_attrs: error %d on %s\n",
6552 rc, ct[i].ad->ad_cname.bv_val, 0 );
6563 /* currently (2010) does not access rs except possibly writing rs->sr_err */
6566 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
6567 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
6569 Entry *e = entry_alloc();
6570 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
6572 struct berval ad_name;
6573 AttributeDescription *ad = NULL;
6576 const char *text = "";
6580 CfEntryInfo *ceprev = NULL;
6582 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
6585 ce->ce_type = main->co_type;
6586 ce->ce_parent = parent;
6588 pdn = parent->ce_entry->e_nname;
6589 if ( parent->ce_kids && parent->ce_kids->ce_type <= ce->ce_type )
6590 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
6591 ceprev->ce_type <= ce->ce_type;
6592 ceprev = ceprev->ce_sibs );
6597 ce->ce_private = c->ca_private;
6601 build_new_dn( &e->e_name, &pdn, rdn, NULL );
6602 ber_dupbv( &e->e_nname, &e->e_name );
6604 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6605 main->co_name, NULL );
6607 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6608 extra->co_name, NULL );
6609 ptr = strchr(rdn->bv_val, '=');
6610 ad_name.bv_val = rdn->bv_val;
6611 ad_name.bv_len = ptr - rdn->bv_val;
6612 rc = slap_bv2ad( &ad_name, &ad, &text );
6617 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
6618 attr_merge_normalize_one(e, ad, &val, NULL );
6621 c->table = main->co_type;
6622 if ( oc->soc_required ) {
6623 rc = config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
6624 if ( rc ) goto fail;
6627 if ( oc->soc_allowed ) {
6628 rc = config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
6629 if ( rc ) goto fail;
6634 c->table = extra->co_type;
6635 if ( oc->soc_required ) {
6636 rc = config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
6637 if ( rc ) goto fail;
6640 if ( oc->soc_allowed ) {
6641 rc = config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
6642 if ( rc ) goto fail;
6646 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
6647 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
6648 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
6649 if ( rc != LDAP_SUCCESS ) {
6651 Debug( LDAP_DEBUG_ANY,
6652 "config_build_entry: build \"%s\" failed: \"%s\"\n",
6653 rdn->bv_val, text, 0);
6656 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
6659 op->ora_modlist = NULL;
6660 slap_add_opattrs( op, NULL, NULL, 0, 0 );
6661 if ( !op->o_noop ) {
6662 SlapReply rs2 = {REP_RESULT};
6663 op->o_bd->be_add( op, &rs2 );
6664 rs->sr_err = rs2.sr_err;
6665 rs_assert_done( &rs2 );
6666 if ( ( rs2.sr_err != LDAP_SUCCESS )
6667 && (rs2.sr_err != LDAP_ALREADY_EXISTS) ) {
6673 ce->ce_sibs = ceprev->ce_sibs;
6674 ceprev->ce_sibs = ce;
6675 } else if ( parent ) {
6676 ce->ce_sibs = parent->ce_kids;
6677 parent->ce_kids = ce;
6684 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
6685 Operation *op, SlapReply *rs )
6688 ConfigFile *cf = c->ca_private;
6690 struct berval bv, rdn;
6692 for (; cf; cf=cf->c_sibs, c->depth++) {
6693 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
6694 !cf->c_om_head && !cf->c_syn_head ) continue;
6695 c->value_dn.bv_val = c->log;
6696 LUTIL_SLASHPATH( cf->c_file.bv_val );
6697 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
6702 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
6704 ptr = strchr( bv.bv_val, '.' );
6706 bv.bv_len = ptr - bv.bv_val;
6707 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
6708 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6709 /* FIXME: how can indicate error? */
6712 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
6714 c->value_dn.bv_len += bv.bv_len;
6715 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
6716 rdnNormalize( 0, NULL, NULL, &c->value_dn, &rdn, NULL );
6719 e = config_build_entry( op, rs, ceparent, c, &rdn,
6720 &CFOC_SCHEMA, NULL );
6721 ch_free( rdn.bv_val );
6724 } else if ( e && cf->c_kids ) {
6725 c->ca_private = cf->c_kids;
6726 config_build_schema_inc( c, e->e_private, op, rs );
6732 #ifdef SLAPD_MODULES
6735 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
6736 Operation *op, SlapReply *rs )
6741 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
6742 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
6744 c->value_dn.bv_val = c->log;
6745 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
6746 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6747 /* FIXME: how can indicate error? */
6751 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
6760 config_check_schema(Operation *op, CfBackInfo *cfb)
6762 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
6764 CfEntryInfo *ce, *last;
6767 /* If there's no root entry, we must be in the midst of converting */
6768 if ( !cfb->cb_root )
6771 /* Make sure the main schema entry exists */
6772 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
6779 /* Make sure it's up to date */
6780 if ( cf_om_tail != om_sys_tail ) {
6781 a = attr_find( e->e_attrs, cfAd_om );
6783 if ( a->a_nvals != a->a_vals )
6784 ber_bvarray_free( a->a_nvals );
6785 ber_bvarray_free( a->a_vals );
6790 oidm_unparse( &bv, NULL, NULL, 1 );
6791 attr_merge_normalize( e, cfAd_om, bv, NULL );
6792 ber_bvarray_free( bv );
6793 cf_om_tail = om_sys_tail;
6795 if ( cf_at_tail != at_sys_tail ) {
6796 a = attr_find( e->e_attrs, cfAd_attr );
6798 if ( a->a_nvals != a->a_vals )
6799 ber_bvarray_free( a->a_nvals );
6800 ber_bvarray_free( a->a_vals );
6805 at_unparse( &bv, NULL, NULL, 1 );
6806 attr_merge_normalize( e, cfAd_attr, bv, NULL );
6807 ber_bvarray_free( bv );
6808 cf_at_tail = at_sys_tail;
6810 if ( cf_oc_tail != oc_sys_tail ) {
6811 a = attr_find( e->e_attrs, cfAd_oc );
6813 if ( a->a_nvals != a->a_vals )
6814 ber_bvarray_free( a->a_nvals );
6815 ber_bvarray_free( a->a_vals );
6820 oc_unparse( &bv, NULL, NULL, 1 );
6821 attr_merge_normalize( e, cfAd_oc, bv, NULL );
6822 ber_bvarray_free( bv );
6823 cf_oc_tail = oc_sys_tail;
6825 if ( cf_syn_tail != syn_sys_tail ) {
6826 a = attr_find( e->e_attrs, cfAd_syntax );
6828 if ( a->a_nvals != a->a_vals )
6829 ber_bvarray_free( a->a_nvals );
6830 ber_bvarray_free( a->a_vals );
6835 syn_unparse( &bv, NULL, NULL, 1 );
6836 attr_merge_normalize( e, cfAd_syntax, bv, NULL );
6837 ber_bvarray_free( bv );
6838 cf_syn_tail = syn_sys_tail;
6841 SlapReply rs = {REP_RESULT};
6842 c.ca_private = NULL;
6843 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
6844 &CFOC_SCHEMA, NULL );
6849 ce->ce_private = cfb->cb_config;
6850 cf_at_tail = at_sys_tail;
6851 cf_oc_tail = oc_sys_tail;
6852 cf_om_tail = om_sys_tail;
6853 cf_syn_tail = syn_sys_tail;
6858 static const char *defacl[] = {
6859 NULL, "to", "*", "by", "*", "none", NULL
6863 config_back_db_open( BackendDB *be, ConfigReply *cr )
6865 CfBackInfo *cfb = be->be_private;
6868 CfEntryInfo *ce, *ceparent;
6872 Connection conn = {0};
6873 OperationBuffer opbuf;
6875 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
6876 SlapReply rs = {REP_RESULT};
6877 void *thrctx = NULL;
6878 AccessControl *save_access;
6880 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
6882 /* If we have no explicitly configured ACLs, don't just use
6883 * the global ACLs. Explicitly deny access to everything.
6885 save_access = be->bd_self->be_acl;
6886 be->bd_self->be_acl = NULL;
6887 parse_acl(be->bd_self, "config_back_db_open", 0, 6, (char **)defacl, 0 );
6888 defacl_parsed = be->bd_self->be_acl;
6889 if ( save_access ) {
6890 be->bd_self->be_acl = save_access;
6892 Debug( LDAP_DEBUG_CONFIG, "config_back_db_open: "
6893 "No explicit ACL for back-config configured. "
6894 "Using hardcoded default\n", 0, 0, 0 );
6897 thrctx = ldap_pvt_thread_pool_context();
6898 connection_fake_init( &conn, &opbuf, thrctx );
6901 op->o_tag = LDAP_REQ_ADD;
6902 op->o_callback = &cb;
6903 op->o_bd = &cfb->cb_db;
6904 op->o_dn = op->o_bd->be_rootdn;
6905 op->o_ndn = op->o_bd->be_rootndn;
6907 if ( !cfb->cb_use_ldif ) {
6911 /* If we read the config from back-ldif, do some quick sanity checks */
6912 if ( cfb->cb_got_ldif ) {
6913 return config_check_schema( op, cfb );
6916 /* create root of tree */
6918 c.ca_private = cfb->cb_config;
6920 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
6930 #ifdef SLAPD_MODULES
6931 /* Create Module nodes... */
6932 if ( modpaths.mp_loads ) {
6933 if ( config_build_modules( &c, ceparent, op, &rs ) ){
6939 /* Create schema nodes... cn=schema will contain the hardcoded core
6940 * schema, read-only. Child objects will contain runtime loaded schema
6944 c.ca_private = NULL;
6945 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
6950 ce->ce_private = cfb->cb_config;
6951 cf_at_tail = at_sys_tail;
6952 cf_oc_tail = oc_sys_tail;
6953 cf_om_tail = om_sys_tail;
6954 cf_syn_tail = syn_sys_tail;
6956 /* Create schema nodes for included schema... */
6957 if ( cfb->cb_config->c_kids ) {
6960 c.ca_private = cfb->cb_config->c_kids;
6961 rc = config_build_schema_inc( &c, ce, op, &rs );
6967 /* Create backend nodes. Skip if they don't provide a cf_table.
6968 * There usually aren't any of these.
6972 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
6973 if (!bi->bi_cf_ocs) {
6974 /* If it only supports the old config mech, complain. */
6975 if ( bi->bi_config ) {
6976 Debug( LDAP_DEBUG_ANY,
6977 "WARNING: No dynamic config support for backend %s.\n",
6978 bi->bi_type, 0, 0 );
6983 if (!bi->bi_private) continue;
6986 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6987 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
6988 if ( rdn.bv_len >= sizeof( c.log ) ) {
6989 /* FIXME: holler ... */ ;
6992 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
6999 /* Create database nodes... */
7000 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
7001 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
7002 for ( i = -1, be = frontendDB ; be;
7003 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
7004 slap_overinfo *oi = NULL;
7006 if ( overlay_is_over( be )) {
7007 oi = be->bd_info->bi_private;
7013 /* If this backend supports the old config mechanism, but not
7014 * the new mech, complain.
7016 if ( !be->be_cf_ocs && bi->bi_db_config ) {
7017 Debug( LDAP_DEBUG_ANY,
7018 "WARNING: No dynamic config support for database %s.\n",
7019 bi->bi_type, 0, 0 );
7023 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
7024 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
7026 if ( rdn.bv_len >= sizeof( c.log ) ) {
7027 /* FIXME: holler ... */ ;
7031 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
7037 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd ) {
7038 rs_reinit( &rs, REP_RESULT );
7039 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
7041 /* Iterate through overlays */
7046 voidList *vl, *v0 = NULL;
7048 /* overlays are in LIFO order, must reverse stack */
7049 for (on=oi->oi_list; on; on=on->on_next) {
7050 vl = ch_malloc( sizeof( voidList ));
7055 for (j=0; vl; j++,vl=v0) {
7059 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
7060 Debug( LDAP_DEBUG_ANY,
7061 "WARNING: No dynamic config support for overlay %s.\n",
7062 on->on_bi.bi_type, 0, 0 );
7066 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
7067 "%s=" SLAP_X_ORDERED_FMT "%s",
7068 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
7069 if ( rdn.bv_len >= sizeof( c.log ) ) {
7070 /* FIXME: holler ... */ ;
7074 oe = config_build_entry( op, &rs, ce, &c, &rdn,
7075 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
7079 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd ) {
7080 rs_reinit( &rs, REP_RESULT );
7081 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
7087 ldap_pvt_thread_pool_context_reset( thrctx );
7089 if ( unsupp && cfb->cb_use_ldif ) {
7090 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
7091 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
7098 cfb_free_cffile( ConfigFile *cf )
7102 for (; cf; cf=next) {
7105 cfb_free_cffile( cf->c_kids );
7106 ch_free( cf->c_file.bv_val );
7107 ber_bvarray_free( cf->c_dseFiles );
7113 cfb_free_entries( CfEntryInfo *ce )
7117 for (; ce; ce=next) {
7120 cfb_free_entries( ce->ce_kids );
7121 ce->ce_entry->e_private = NULL;
7122 entry_free( ce->ce_entry );
7128 config_back_db_close( BackendDB *be, ConfigReply *cr )
7130 CfBackInfo *cfb = be->be_private;
7132 cfb_free_entries( cfb->cb_root );
7133 cfb->cb_root = NULL;
7135 if ( cfb->cb_db.bd_info ) {
7136 backend_shutdown( &cfb->cb_db );
7139 if ( defacl_parsed && be->be_acl != defacl_parsed ) {
7140 acl_free( defacl_parsed );
7141 defacl_parsed = NULL;
7148 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
7150 CfBackInfo *cfb = be->be_private;
7152 cfb_free_cffile( cfb->cb_config );
7154 ch_free( cfdir.bv_val );
7156 avl_free( CfOcTree, NULL );
7158 if ( cfb->cb_db.bd_info ) {
7159 cfb->cb_db.be_suffix = NULL;
7160 cfb->cb_db.be_nsuffix = NULL;
7161 BER_BVZERO( &cfb->cb_db.be_rootdn );
7162 BER_BVZERO( &cfb->cb_db.be_rootndn );
7164 backend_destroy_one( &cfb->cb_db, 0 );
7173 config_back_db_init( BackendDB *be, ConfigReply* cr )
7179 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
7180 cfn = cfb->cb_config;
7181 be->be_private = cfb;
7183 ber_dupbv( &be->be_rootdn, &config_rdn );
7184 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
7185 ber_dupbv( &dn, &be->be_rootdn );
7186 ber_bvarray_add( &be->be_suffix, &dn );
7187 ber_dupbv( &dn, &be->be_rootdn );
7188 ber_bvarray_add( &be->be_nsuffix, &dn );
7190 /* Hide from namingContexts */
7191 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
7193 /* Check ACLs on content of Adds by default */
7194 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_ACL_ADD;
7200 config_back_destroy( BackendInfo *bi )
7202 ldif_must_b64_encode_release();
7207 config_tool_entry_open( BackendDB *be, int mode )
7209 CfBackInfo *cfb = be->be_private;
7210 BackendInfo *bi = cfb->cb_db.bd_info;
7212 if ( bi && bi->bi_tool_entry_open )
7213 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
7220 config_tool_entry_close( BackendDB *be )
7222 CfBackInfo *cfb = be->be_private;
7223 BackendInfo *bi = cfb->cb_db.bd_info;
7225 if ( bi && bi->bi_tool_entry_close )
7226 return bi->bi_tool_entry_close( &cfb->cb_db );
7232 config_tool_entry_first( BackendDB *be )
7234 CfBackInfo *cfb = be->be_private;
7235 BackendInfo *bi = cfb->cb_db.bd_info;
7237 if ( bi && bi->bi_tool_entry_first ) {
7238 return bi->bi_tool_entry_first( &cfb->cb_db );
7240 if ( bi && bi->bi_tool_entry_first_x ) {
7241 return bi->bi_tool_entry_first_x( &cfb->cb_db,
7242 NULL, LDAP_SCOPE_DEFAULT, NULL );
7248 config_tool_entry_first_x(
7250 struct berval *base,
7254 CfBackInfo *cfb = be->be_private;
7255 BackendInfo *bi = cfb->cb_db.bd_info;
7257 if ( bi && bi->bi_tool_entry_first_x ) {
7258 return bi->bi_tool_entry_first_x( &cfb->cb_db, base, scope, f );
7264 config_tool_entry_next( BackendDB *be )
7266 CfBackInfo *cfb = be->be_private;
7267 BackendInfo *bi = cfb->cb_db.bd_info;
7269 if ( bi && bi->bi_tool_entry_next )
7270 return bi->bi_tool_entry_next( &cfb->cb_db );
7276 config_tool_entry_get( BackendDB *be, ID id )
7278 CfBackInfo *cfb = be->be_private;
7279 BackendInfo *bi = cfb->cb_db.bd_info;
7281 if ( bi && bi->bi_tool_entry_get )
7282 return bi->bi_tool_entry_get( &cfb->cb_db, id );
7287 static int entry_put_got_frontend=0;
7288 static int entry_put_got_config=0;
7290 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
7292 CfBackInfo *cfb = be->be_private;
7293 BackendInfo *bi = cfb->cb_db.bd_info;
7295 struct berval rdn, vals[ 2 ];
7297 OperationBuffer opbuf;
7299 Connection conn = {0};
7300 Operation *op = NULL;
7303 int isFrontendChild = 0;
7305 /* Create entry for frontend database if it does not exist already */
7306 if ( !entry_put_got_frontend ) {
7307 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
7308 STRLENOF( "olcDatabase" ))) {
7309 if ( strncmp( e->e_nname.bv_val +
7310 STRLENOF( "olcDatabase" ), "={-1}frontend",
7311 STRLENOF( "={-1}frontend" )) &&
7312 strncmp( e->e_nname.bv_val +
7313 STRLENOF( "olcDatabase" ), "=frontend",
7314 STRLENOF( "=frontend" ))) {
7316 vals[1].bv_val = NULL;
7317 memset( &ca, 0, sizeof(ConfigArgs));
7319 ca.bi = frontendDB->bd_info;
7320 ca.be->be_cf_ocs = &CFOC_FRONTEND;
7321 rdn.bv_val = ca.log;
7322 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7323 "%s=" SLAP_X_ORDERED_FMT "%s",
7324 cfAd_database->ad_cname.bv_val, -1,
7326 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
7327 &CFOC_DATABASE, ca.be->be_cf_ocs );
7328 thrctx = ldap_pvt_thread_pool_context();
7329 connection_fake_init2( &conn, &opbuf, thrctx,0 );
7331 op->o_bd = &cfb->cb_db;
7332 op->o_tag = LDAP_REQ_ADD;
7334 op->o_dn = be->be_rootdn;
7335 op->o_ndn = be->be_rootndn;
7336 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
7337 if ( rc != LDAP_SUCCESS ) {
7338 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
7339 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
7343 if ( ce && bi && bi->bi_tool_entry_put &&
7344 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
7345 entry_put_got_frontend++;
7347 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
7348 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
7352 if ( !strncmp( e->e_nname.bv_val +
7353 STRLENOF( "olcDatabase" ), "=frontend",
7354 STRLENOF( "=frontend" ) ) )
7356 struct berval rdn, pdn, ndn;
7357 dnParent( &e->e_nname, &pdn );
7358 rdn.bv_val = ca.log;
7359 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7360 "%s=" SLAP_X_ORDERED_FMT "%s",
7361 cfAd_database->ad_cname.bv_val, -1,
7362 frontendDB->bd_info->bi_type );
7363 build_new_dn( &ndn, &pdn, &rdn, NULL );
7364 ber_memfree( e->e_name.bv_val );
7366 ber_bvreplace( &e->e_nname, &e->e_name );
7368 entry_put_got_frontend++;
7374 /* Child entries of the frontend database, e.g. slapo-chain's back-ldap
7375 * instances, may appear before the config database entry in the ldif, skip
7376 * auto-creation of olcDatabase={0}config in such a case */
7377 if ( !entry_put_got_config &&
7378 !strncmp( e->e_nname.bv_val, "olcDatabase", STRLENOF( "olcDatabase" ))) {
7380 dnParent( &e->e_nname, &pdn );
7381 while ( pdn.bv_len ) {
7382 if ( !strncmp( pdn.bv_val, "olcDatabase",
7383 STRLENOF( "olcDatabase" ))) {
7384 if ( !strncmp( pdn.bv_val +
7385 STRLENOF( "olcDatabase" ), "={-1}frontend",
7386 STRLENOF( "={-1}frontend" )) ||
7387 !strncmp( pdn.bv_val +
7388 STRLENOF( "olcDatabase" ), "=frontend",
7389 STRLENOF( "=frontend" ))) {
7391 isFrontendChild = 1;
7395 dnParent( &pdn, &pdn );
7399 /* Create entry for config database if it does not exist already */
7400 if ( !entry_put_got_config && !isFrontend && !isFrontendChild ) {
7401 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
7402 STRLENOF( "olcDatabase" ))) {
7403 if ( strncmp( e->e_nname.bv_val +
7404 STRLENOF( "olcDatabase" ), "={0}config",
7405 STRLENOF( "={0}config" )) &&
7406 strncmp( e->e_nname.bv_val +
7407 STRLENOF( "olcDatabase" ), "=config",
7408 STRLENOF( "=config" )) ) {
7410 vals[1].bv_val = NULL;
7411 memset( &ca, 0, sizeof(ConfigArgs));
7412 ca.be = LDAP_STAILQ_FIRST( &backendDB );
7413 ca.bi = ca.be->bd_info;
7414 rdn.bv_val = ca.log;
7415 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7416 "%s=" SLAP_X_ORDERED_FMT "%s",
7417 cfAd_database->ad_cname.bv_val, 0,
7419 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
7422 thrctx = ldap_pvt_thread_pool_context();
7423 connection_fake_init2( &conn, &opbuf, thrctx,0 );
7425 op->o_bd = &cfb->cb_db;
7426 op->o_tag = LDAP_REQ_ADD;
7427 op->o_dn = be->be_rootdn;
7428 op->o_ndn = be->be_rootndn;
7431 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
7432 if ( rc != LDAP_SUCCESS ) {
7433 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
7434 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7437 if (ce && bi && bi->bi_tool_entry_put &&
7438 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
7439 entry_put_got_config++;
7441 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
7442 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7446 entry_put_got_config++;
7450 if ( bi && bi->bi_tool_entry_put &&
7451 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
7452 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
7459 AttributeDescription **desc;
7461 { "attribute", &cfAd_attr },
7462 { "backend", &cfAd_backend },
7463 { "database", &cfAd_database },
7464 { "include", &cfAd_include },
7465 { "ldapsyntax", &cfAd_syntax },
7466 { "objectclass", &cfAd_oc },
7467 { "objectidentifier", &cfAd_om },
7468 { "overlay", &cfAd_overlay },
7473 * add / delete: all types that may be added or deleted must use an
7474 * X-ORDERED attributeType for their RDN. Adding and deleting entries
7475 * should automatically renumber the index of any siblings as needed,
7476 * so that no gaps in the numbering sequence exist after the add/delete
7478 * What can be added:
7480 * backend objects for backend-specific config directives
7484 * delete: probably no support this time around.
7486 * modrdn: generally not done. Will be invoked automatically by add/
7487 * delete to update numbering sequence. Perform as an explicit operation
7488 * so that the renumbering effect may be replicated. Subtree rename must
7489 * be supported, since renumbering a database will affect all its child
7492 * modify: must be fully supported.
7496 config_back_initialize( BackendInfo *bi )
7498 ConfigTable *ct = config_back_cf_table;
7502 AttributeDescription *ad = NULL;
7504 static char *controls[] = {
7505 LDAP_CONTROL_MANAGEDSAIT,
7509 /* Make sure we don't exceed the bits reserved for userland */
7510 config_check_userland( CFG_LAST );
7512 bi->bi_controls = controls;
7517 bi->bi_destroy = config_back_destroy;
7519 bi->bi_db_init = config_back_db_init;
7520 bi->bi_db_config = 0;
7521 bi->bi_db_open = config_back_db_open;
7522 bi->bi_db_close = config_back_db_close;
7523 bi->bi_db_destroy = config_back_db_destroy;
7525 bi->bi_op_bind = config_back_bind;
7526 bi->bi_op_unbind = 0;
7527 bi->bi_op_search = config_back_search;
7528 bi->bi_op_compare = 0;
7529 bi->bi_op_modify = config_back_modify;
7530 bi->bi_op_modrdn = config_back_modrdn;
7531 bi->bi_op_add = config_back_add;
7532 bi->bi_op_delete = config_back_delete;
7533 bi->bi_op_abandon = 0;
7535 bi->bi_extended = 0;
7537 bi->bi_chk_referrals = 0;
7539 bi->bi_access_allowed = slap_access_allowed;
7541 bi->bi_connection_init = 0;
7542 bi->bi_connection_destroy = 0;
7544 bi->bi_entry_release_rw = config_entry_release;
7545 bi->bi_entry_get_rw = config_back_entry_get;
7547 bi->bi_tool_entry_open = config_tool_entry_open;
7548 bi->bi_tool_entry_close = config_tool_entry_close;
7549 bi->bi_tool_entry_first = config_tool_entry_first;
7550 bi->bi_tool_entry_first_x = config_tool_entry_first_x;
7551 bi->bi_tool_entry_next = config_tool_entry_next;
7552 bi->bi_tool_entry_get = config_tool_entry_get;
7553 bi->bi_tool_entry_put = config_tool_entry_put;
7556 argv[ 0 ] = "slapd";
7562 for (i=0; OidMacros[i].name; i++ ) {
7563 argv[1] = OidMacros[i].name;
7564 argv[2] = OidMacros[i].oid;
7565 parse_oidm( &ca, 0, NULL );
7568 bi->bi_cf_ocs = cf_ocs;
7570 i = config_register_schema( ct, cf_ocs );
7573 i = slap_str2ad( "olcDatabase", &olcDatabaseDummy[0].ad, &text );
7576 /* setup olcRootPW to be base64-encoded when written in LDIF form;
7577 * basically, we don't care if it fails */
7578 i = slap_str2ad( "olcRootPW", &ad, &text );
7580 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
7581 "warning, unable to get \"olcRootPW\" "
7582 "attribute description: %d: %s\n",
7585 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
7586 ad->ad_type->sat_oid );
7589 /* set up the notable AttributeDescriptions */
7591 for (;ct->name;ct++) {
7592 if (strcmp(ct->name, ads[i].name)) continue;
7593 *ads[i].desc = ct->ad;
7595 if (!ads[i].name) break;