1 /* bconfig.c - the config backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005-2011 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,
207 static OidRec OidMacros[] = {
208 /* OpenLDAProot:1.12.2 */
209 { "OLcfg", "1.3.6.1.4.1.4203.1.12.2" },
210 { "OLcfgAt", "OLcfg:3" },
211 { "OLcfgGlAt", "OLcfgAt:0" },
212 { "OLcfgBkAt", "OLcfgAt:1" },
213 { "OLcfgDbAt", "OLcfgAt:2" },
214 { "OLcfgOvAt", "OLcfgAt:3" },
215 { "OLcfgCtAt", "OLcfgAt:4" }, /* contrib modules */
216 { "OLcfgOc", "OLcfg:4" },
217 { "OLcfgGlOc", "OLcfgOc:0" },
218 { "OLcfgBkOc", "OLcfgOc:1" },
219 { "OLcfgDbOc", "OLcfgOc:2" },
220 { "OLcfgOvOc", "OLcfgOc:3" },
221 { "OLcfgCtOc", "OLcfgOc:4" }, /* contrib modules */
223 /* Syntaxes. We should just start using the standard names and
224 * document that they are predefined and available for users
225 * to reference in their own schema. Defining schema without
226 * OID macros is for masochists...
228 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
229 { "OMsBoolean", "OMsyn:7" },
230 { "OMsDN", "OMsyn:12" },
231 { "OMsDirectoryString", "OMsyn:15" },
232 { "OMsIA5String", "OMsyn:26" },
233 { "OMsInteger", "OMsyn:27" },
234 { "OMsOID", "OMsyn:38" },
235 { "OMsOctetString", "OMsyn:40" },
240 * Backend/Database registry
242 * OLcfg{Bk|Db}{Oc|At}:0 -> common
243 * OLcfg{Bk|Db}{Oc|At}:1 -> back-bdb(/back-hdb)
244 * OLcfg{Bk|Db}{Oc|At}:2 -> back-ldif
245 * OLcfg{Bk|Db}{Oc|At}:3 -> back-ldap
246 * OLcfg{Bk|Db}{Oc|At}:4 -> back-monitor
247 * OLcfg{Bk|Db}{Oc|At}:5 -> back-relay
248 * OLcfg{Bk|Db}{Oc|At}:6 -> back-sql(/back-ndb)
249 * OLcfg{Bk|Db}{Oc|At}:7 -> back-sock
250 * OLcfg{Bk|Db}{Oc|At}:8 -> back-null
251 * OLcfg{Bk|Db}{Oc|At}:9 -> back-passwd
252 * OLcfg{Bk|Db}{Oc|At}:10 -> back-shell
253 * OLcfg{Bk|Db}{Oc|At}:11 -> back-perl
254 * OLcfg{Bk|Db}{Oc|At}:12 -> back-mdb
260 * OLcfgOv{Oc|At}:1 -> syncprov
261 * OLcfgOv{Oc|At}:2 -> pcache
262 * OLcfgOv{Oc|At}:3 -> chain
263 * OLcfgOv{Oc|At}:4 -> accesslog
264 * OLcfgOv{Oc|At}:5 -> valsort
265 * OLcfgOv{Oc|At}:7 -> distproc
266 * OLcfgOv{Oc|At}:8 -> dynlist
267 * OLcfgOv{Oc|At}:9 -> dds
268 * OLcfgOv{Oc|At}:10 -> unique
269 * OLcfgOv{Oc|At}:11 -> refint
270 * OLcfgOv{Oc|At}:12 -> ppolicy
271 * OLcfgOv{Oc|At}:13 -> constraint
272 * OLcfgOv{Oc|At}:14 -> translucent
273 * OLcfgOv{Oc|At}:15 -> auditlog
274 * OLcfgOv{Oc|At}:16 -> rwm
275 * OLcfgOv{Oc|At}:17 -> dyngroup
276 * OLcfgOv{Oc|At}:18 -> memberof
277 * OLcfgOv{Oc|At}:19 -> collect
278 * OLcfgOv{Oc|At}:20 -> retcode
279 * OLcfgOv{Oc|At}:21 -> sssvlv
282 /* alphabetical ordering */
284 static ConfigTable config_back_cf_table[] = {
285 /* This attr is read-only */
286 { "", "", 0, 0, 0, ARG_MAGIC,
287 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
288 "DESC 'File for slapd configuration directives' "
289 "EQUALITY caseIgnoreMatch "
290 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
291 { "", "", 0, 0, 0, ARG_MAGIC,
292 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
293 "DESC 'Directory for slapd configuration backend' "
294 "EQUALITY caseIgnoreMatch "
295 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
296 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
297 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
298 "DESC 'Access Control List' "
299 "EQUALITY caseIgnoreMatch "
300 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
301 { "add_content_acl", NULL, 0, 0, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_ACL_ADD,
302 &config_generic, "( OLcfgGlAt:86 NAME 'olcAddContentAcl' "
303 "DESC 'Check ACLs against content of Add ops' "
304 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
305 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
306 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
307 "DESC 'Allowed set of deprecated features' "
308 "EQUALITY caseIgnoreMatch "
309 "SYNTAX OMsDirectoryString )", NULL, NULL },
310 { "argsfile", "file", 2, 2, 0, ARG_STRING,
311 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
312 "DESC 'File for slapd command line options' "
313 "EQUALITY caseIgnoreMatch "
314 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
315 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
316 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
317 "EQUALITY caseIgnoreMatch "
318 "SYNTAX OMsDirectoryString )", NULL, NULL },
319 { "attribute", "attribute", 2, 0, STRLENOF( "attribute" ),
320 ARG_PAREN|ARG_MAGIC|CFG_ATTR,
321 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
322 "DESC 'OpenLDAP attributeTypes' "
323 "EQUALITY caseIgnoreMatch "
324 "SUBSTR caseIgnoreSubstringsMatch "
325 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
327 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
328 #ifdef SLAP_AUTH_REWRITE
329 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
333 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
334 "EQUALITY caseIgnoreMatch "
335 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
336 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
337 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
338 "EQUALITY caseIgnoreMatch "
339 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
340 { "authz-regexp", "regexp> <DN", 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
341 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
342 "EQUALITY caseIgnoreMatch "
343 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
344 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
345 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
346 "DESC 'A type of backend' "
347 "EQUALITY caseIgnoreMatch "
348 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
350 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
351 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
352 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
353 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
354 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
355 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
356 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
357 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
358 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
359 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
360 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
361 "DESC 'The backend type for a database instance' "
362 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
363 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
364 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
365 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
366 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
367 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
368 "EQUALITY caseIgnoreMatch "
369 "SYNTAX OMsDirectoryString )", NULL, NULL },
370 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
371 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
372 "DESC 'OpenLDAP DIT content rules' "
373 "EQUALITY caseIgnoreMatch "
374 "SUBSTR caseIgnoreSubstringsMatch "
375 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
377 { "extra_attrs", "attrlist", 2, 2, 0, ARG_DB|ARG_MAGIC,
378 &config_extra_attrs, "( OLcfgDbAt:0.20 NAME 'olcExtraAttrs' "
379 "EQUALITY caseIgnoreMatch "
380 "SYNTAX OMsDirectoryString )", NULL, NULL },
381 { "gentlehup", "on|off", 2, 2, 0,
383 ARG_ON_OFF, &global_gentlehup,
387 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
388 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
389 { "hidden", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_HIDDEN,
390 &config_generic, "( OLcfgDbAt:0.17 NAME 'olcHidden' "
391 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
392 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
393 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
394 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
395 { "include", "file", 2, 2, 0, ARG_MAGIC,
396 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
397 "SUP labeledURI )", NULL, NULL },
398 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
399 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
400 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
401 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
402 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
403 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
404 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
405 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
406 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
407 { "index_substr_any_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
408 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
409 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
410 { "index_intlen", "len", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_IX_INTLEN,
411 &config_generic, "( OLcfgGlAt:84 NAME 'olcIndexIntLen' "
412 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
413 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
414 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
415 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
416 { "ldapsyntax", "syntax", 2, 0, 0,
417 ARG_PAREN|ARG_MAGIC|CFG_SYNTAX,
418 &config_generic, "( OLcfgGlAt:85 NAME 'olcLdapSyntaxes' "
419 "DESC 'OpenLDAP ldapSyntax' "
420 "EQUALITY caseIgnoreMatch "
421 "SUBSTR caseIgnoreSubstringsMatch "
422 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
424 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
425 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
426 "EQUALITY caseIgnoreMatch "
427 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
428 { "listener-threads", "count", 2, 0, 0,
432 ARG_UINT|ARG_MAGIC|CFG_LTHREADS, &config_generic,
434 "( OLcfgGlAt:93 NAME 'olcListenerThreads' "
435 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
436 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
437 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
438 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
439 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
440 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
441 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
442 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
443 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
444 "EQUALITY caseIgnoreMatch "
445 "SYNTAX OMsDirectoryString )", NULL, NULL },
446 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
447 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
448 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
449 { "mirrormode", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_MIRRORMODE,
450 &config_generic, "( OLcfgDbAt:0.16 NAME 'olcMirrorMode' "
451 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
452 { "moduleload", "file", 2, 0, 0,
454 ARG_MAGIC|CFG_MODLOAD|ARG_NO_DELETE, &config_generic,
458 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
459 "EQUALITY caseIgnoreMatch "
460 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
461 { "modulepath", "path", 2, 2, 0,
463 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
467 "( OLcfgGlAt:31 NAME 'olcModulePath' "
468 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
469 { "monitoring", "TRUE|FALSE", 2, 2, 0,
470 ARG_MAGIC|CFG_MONITORING|ARG_DB|ARG_ON_OFF, &config_generic,
471 "( OLcfgDbAt:0.18 NAME 'olcMonitoring' "
472 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
473 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
474 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
475 "DESC 'OpenLDAP object classes' "
476 "EQUALITY caseIgnoreMatch "
477 "SUBSTR caseIgnoreSubstringsMatch "
478 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
480 { "objectidentifier", "name> <oid", 3, 3, 0, ARG_MAGIC|CFG_OID,
481 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
482 "EQUALITY caseIgnoreMatch "
483 "SUBSTR caseIgnoreSubstringsMatch "
484 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
485 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
486 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
487 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
488 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
489 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
490 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
491 { "password-hash", "hash", 2, 0, 0, ARG_MAGIC,
492 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
493 "EQUALITY caseIgnoreMatch "
494 "SYNTAX OMsDirectoryString )", NULL, NULL },
495 { "pidfile", "file", 2, 2, 0, ARG_STRING,
496 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
497 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
498 { "plugin", NULL, 0, 0, 0,
500 ARG_MAGIC|CFG_PLUGIN, &config_generic,
504 "( OLcfgGlAt:38 NAME 'olcPlugin' "
505 "EQUALITY caseIgnoreMatch "
506 "SYNTAX OMsDirectoryString )", NULL, NULL },
507 { "pluginlog", "filename", 2, 2, 0,
509 ARG_STRING, &slapi_log_file,
513 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
514 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
515 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
516 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
517 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
518 { "referral", "url", 2, 2, 0, ARG_MAGIC,
519 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
520 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
521 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
522 &config_obsolete, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
523 "EQUALITY caseIgnoreMatch "
524 "SUP labeledURI X-ORDERED 'VALUES' )", NULL, NULL },
525 { "replica-argsfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
526 &config_obsolete, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
527 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
528 { "replica-pidfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
529 &config_obsolete, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
530 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
531 { "replicationInterval", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
532 &config_obsolete, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
533 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
534 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC,
535 &config_obsolete, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
536 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
537 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
538 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
539 "EQUALITY caseIgnoreMatch "
540 "SYNTAX OMsDirectoryString )", NULL, NULL },
541 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
542 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
543 "EQUALITY caseIgnoreMatch "
544 "SYNTAX OMsDirectoryString )", NULL, NULL },
545 { "reverse-lookup", "on|off", 2, 2, 0,
546 #ifdef SLAPD_RLOOKUPS
547 ARG_ON_OFF, &use_reverse_lookup,
551 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
552 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
553 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
554 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
555 "EQUALITY distinguishedNameMatch "
556 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
557 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
558 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
559 "EQUALITY caseIgnoreMatch "
560 "SYNTAX OMsDirectoryString )", NULL, NULL },
561 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
562 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
563 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
564 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
565 &config_generic, NULL, NULL, NULL },
566 { "sasl-auxprops", NULL, 2, 0, 0,
567 #ifdef HAVE_CYRUS_SASL
568 ARG_STRING|ARG_UNIQUE, &slap_sasl_auxprops,
572 "( OLcfgGlAt:89 NAME 'olcSaslAuxprops' "
573 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
574 { "sasl-auxprops-dontusecopy", NULL, 2, 0, 0,
575 #if defined(HAVE_CYRUS_SASL) && defined(SLAP_AUXPROP_DONTUSECOPY)
576 ARG_MAGIC|CFG_AZDUC, &config_generic,
580 "( OLcfgGlAt:91 NAME 'olcSaslAuxpropsDontUseCopy' "
581 "EQUALITY caseIgnoreMatch "
582 "SYNTAX OMsDirectoryString )", NULL, NULL },
583 { "sasl-auxprops-dontusecopy-ignore", "true|FALSE", 2, 0, 0,
584 #if defined(HAVE_CYRUS_SASL) && defined(SLAP_AUXPROP_DONTUSECOPY)
585 ARG_ON_OFF|CFG_AZDUC_IGNORE, &slap_dontUseCopy_ignore,
589 "( OLcfgGlAt:92 NAME 'olcSaslAuxpropsDontUseCopyIgnore' "
590 "EQUALITY booleanMatch "
591 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
592 { "sasl-host", "host", 2, 2, 0,
593 #ifdef HAVE_CYRUS_SASL
594 ARG_STRING|ARG_UNIQUE, &sasl_host,
598 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
599 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
600 { "sasl-realm", "realm", 2, 2, 0,
601 #ifdef HAVE_CYRUS_SASL
602 ARG_STRING|ARG_UNIQUE, &global_realm,
606 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
607 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
608 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
609 &config_generic, NULL, NULL, NULL },
610 { "sasl-secprops", "properties", 2, 2, 0,
611 #ifdef HAVE_CYRUS_SASL
612 ARG_MAGIC|CFG_SASLSECP, &config_generic,
616 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
617 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
618 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
619 &config_generic, NULL, NULL, NULL },
620 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
621 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
622 "EQUALITY distinguishedNameMatch "
623 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
624 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
625 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
626 "EQUALITY caseIgnoreMatch "
627 "SYNTAX OMsDirectoryString )", NULL, NULL },
628 { "serverID", "number> <[URI]", 2, 3, 0, ARG_MAGIC|CFG_SERVERID,
629 &config_generic, "( OLcfgGlAt:81 NAME 'olcServerID' "
630 "EQUALITY caseIgnoreMatch "
631 "SYNTAX OMsDirectoryString )", NULL, NULL },
632 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
633 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
634 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
635 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
636 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
637 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
638 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
639 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
640 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
641 { "sortvals", "attr", 2, 0, 0, ARG_MAGIC|CFG_SORTVALS,
642 &config_generic, "( OLcfgGlAt:83 NAME 'olcSortVals' "
643 "DESC 'Attributes whose values will always be sorted' "
644 "EQUALITY caseIgnoreMatch "
645 "SYNTAX OMsDirectoryString )", NULL, NULL },
646 { "subordinate", "[advertise]", 1, 2, 0, ARG_DB|ARG_MAGIC,
647 &config_subordinate, "( OLcfgDbAt:0.15 NAME 'olcSubordinate' "
648 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
649 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
650 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
651 "EQUALITY distinguishedNameMatch "
652 "SYNTAX OMsDN )", NULL, NULL },
653 { "sync_use_subentry", NULL, 0, 0, 0, ARG_ON_OFF|ARG_DB|ARG_MAGIC|CFG_SYNC_SUBENTRY,
654 &config_generic, "( OLcfgDbAt:0.19 NAME 'olcSyncUseSubentry' "
655 "DESC 'Store sync context in a subentry' "
656 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
657 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
658 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
659 "EQUALITY caseIgnoreMatch "
660 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
661 { "tcp-buffer", "[listener=<listener>] [{read|write}=]size", 0, 0, 0,
662 #ifndef LDAP_TCP_BUFFER
664 #else /* LDAP_TCP_BUFFER */
665 ARG_MAGIC, &config_tcp_buffer,
666 #endif /* LDAP_TCP_BUFFER */
667 "( OLcfgGlAt:90 NAME 'olcTCPBuffer' "
668 "DESC 'Custom TCP buffer size' "
669 "SYNTAX OMsDirectoryString )", NULL, NULL },
670 { "threads", "count", 2, 2, 0,
674 ARG_INT|ARG_MAGIC|CFG_THREADS, &config_generic,
676 "( OLcfgGlAt:66 NAME 'olcThreads' "
677 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
678 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
679 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
680 "SYNTAX OMsDirectoryString )", NULL, NULL },
681 { "TLSCACertificateFile", NULL, 2, 2, 0,
683 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
687 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
688 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
689 { "TLSCACertificatePath", NULL, 2, 2, 0,
691 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
695 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
696 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
697 { "TLSCertificateFile", NULL, 2, 2, 0,
699 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
703 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
704 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
705 { "TLSCertificateKeyFile", NULL, 2, 2, 0,
707 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
711 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
712 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
713 { "TLSCipherSuite", NULL, 2, 2, 0,
715 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
719 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
720 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
721 { "TLSCRLCheck", NULL, 2, 2, 0,
722 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
723 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
727 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
728 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
729 { "TLSCRLFile", NULL, 2, 2, 0,
730 #if defined(HAVE_GNUTLS)
731 CFG_TLS_CRL_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
735 "( OLcfgGlAt:82 NAME 'olcTLSCRLFile' "
736 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
737 { "TLSRandFile", NULL, 2, 2, 0,
739 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
743 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
744 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
745 { "TLSVerifyClient", NULL, 2, 2, 0,
747 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
751 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
752 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
753 { "TLSDHParamFile", NULL, 2, 2, 0,
755 CFG_TLS_DH_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
759 "( OLcfgGlAt:77 NAME 'olcTLSDHParamFile' "
760 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
761 { "TLSProtocolMin", NULL, 2, 2, 0,
763 CFG_TLS_PROTOCOL_MIN|ARG_STRING|ARG_MAGIC, &config_tls_config,
767 "( OLcfgGlAt:87 NAME 'olcTLSProtocolMin' "
768 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
769 { "tool-threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_TTHREADS,
770 &config_generic, "( OLcfgGlAt:80 NAME 'olcToolThreads' "
771 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
772 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
773 NULL, NULL, NULL, NULL },
774 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
775 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
776 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
777 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
778 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
779 "EQUALITY caseIgnoreMatch "
780 "SUP labeledURI )", NULL, NULL },
781 { "writetimeout", "timeout", 2, 2, 0, ARG_INT,
782 &global_writetimeout, "( OLcfgGlAt:88 NAME 'olcWriteTimeout' "
783 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
784 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
785 NULL, NULL, NULL, NULL }
788 /* Need to no-op this keyword for dynamic config */
789 ConfigTable olcDatabaseDummy[] = {
790 { "", "", 0, 0, 0, ARG_IGNORED,
791 NULL, "( OLcfgGlAt:13 NAME 'olcDatabase' "
792 "DESC 'The backend type for a database instance' "
793 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
794 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
797 /* Routines to check if a child can be added to this type */
798 static ConfigLDAPadd cfAddSchema, cfAddInclude, cfAddDatabase,
799 cfAddBackend, cfAddModule, cfAddOverlay;
801 /* NOTE: be careful when defining array members
802 * that can be conditionally compiled */
803 #define CFOC_GLOBAL cf_ocs[1]
804 #define CFOC_SCHEMA cf_ocs[2]
805 #define CFOC_BACKEND cf_ocs[3]
806 #define CFOC_DATABASE cf_ocs[4]
807 #define CFOC_OVERLAY cf_ocs[5]
808 #define CFOC_INCLUDE cf_ocs[6]
809 #define CFOC_FRONTEND cf_ocs[7]
811 #define CFOC_MODULE cf_ocs[8]
812 #endif /* SLAPD_MODULES */
814 static ConfigOCs cf_ocs[] = {
817 "DESC 'OpenLDAP configuration object' "
818 "ABSTRACT SUP top )", Cft_Abstract, NULL },
821 "DESC 'OpenLDAP Global configuration options' "
822 "SUP olcConfig STRUCTURAL "
823 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
824 "olcAttributeOptions $ olcAuthIDRewrite $ "
825 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
826 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
827 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
828 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
829 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcIndexIntLen $ "
830 "olcLocalSSF $ olcLogFile $ olcLogLevel $ "
831 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
832 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
833 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
835 "olcSaslAuxprops $ olcSaslAuxpropsDontUseCopy $ olcSaslAuxpropsDontUseCopyIgnore $ "
836 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
837 "olcSecurity $ olcServerID $ olcSizeLimit $ "
838 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ "
840 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
841 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
842 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
843 "olcTLSRandFile $ olcTLSVerifyClient $ olcTLSDHParamFile $ "
844 "olcTLSCRLFile $ olcToolThreads $ olcWriteTimeout $ "
845 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
846 "olcDitContentRules $ olcLdapSyntaxes ) )", Cft_Global },
848 "NAME 'olcSchemaConfig' "
849 "DESC 'OpenLDAP schema object' "
850 "SUP olcConfig STRUCTURAL "
851 "MAY ( cn $ olcObjectIdentifier $ olcLdapSyntaxes $ "
852 "olcAttributeTypes $ olcObjectClasses $ olcDitContentRules ) )",
853 Cft_Schema, NULL, cfAddSchema },
855 "NAME 'olcBackendConfig' "
856 "DESC 'OpenLDAP Backend-specific options' "
857 "SUP olcConfig STRUCTURAL "
858 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
860 "NAME 'olcDatabaseConfig' "
861 "DESC 'OpenLDAP Database-specific options' "
862 "SUP olcConfig STRUCTURAL "
864 "MAY ( olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
865 "olcAddContentAcl $ olcLastMod $ olcLimits $ "
866 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
867 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
868 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
869 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncUseSubentry $ olcSyncrepl $ "
870 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef $ olcMirrorMode $ "
871 "olcMonitoring $ olcExtraAttrs ) )",
872 Cft_Database, NULL, cfAddDatabase },
874 "NAME 'olcOverlayConfig' "
875 "DESC 'OpenLDAP Overlay-specific options' "
876 "SUP olcConfig STRUCTURAL "
877 "MUST olcOverlay )", Cft_Overlay, NULL, cfAddOverlay },
879 "NAME 'olcIncludeFile' "
880 "DESC 'OpenLDAP configuration include file' "
881 "SUP olcConfig STRUCTURAL "
883 "MAY ( cn $ olcRootDSE ) )",
884 /* Used to be Cft_Include, that def has been removed */
885 Cft_Abstract, NULL, cfAddInclude },
886 /* This should be STRUCTURAL like all the other database classes, but
887 * that would mean inheriting all of the olcDatabaseConfig attributes,
888 * which causes them to be merged twice in config_build_entry.
891 "NAME 'olcFrontendConfig' "
892 "DESC 'OpenLDAP frontend configuration' "
894 "MAY ( olcDefaultSearchBase $ olcPasswordHash $ olcSortVals ) )",
895 Cft_Database, NULL, NULL },
898 "NAME 'olcModuleList' "
899 "DESC 'OpenLDAP dynamic module info' "
900 "SUP olcConfig STRUCTURAL "
901 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
902 Cft_Module, NULL, cfAddModule },
907 typedef struct ServerID {
908 struct ServerID *si_next;
909 struct berval si_url;
913 static ServerID *sid_list;
915 typedef struct voidList {
916 struct voidList *vl_next;
920 typedef struct ADlist {
921 struct ADlist *al_next;
922 AttributeDescription *al_desc;
925 static ADlist *sortVals;
928 config_generic(ConfigArgs *c) {
931 if ( c->op == SLAP_CONFIG_EMIT ) {
935 c->value_int = ldap_pvt_thread_get_concurrency();
938 c->value_int = connection_pool_max;
941 c->value_int = slap_tool_thread_max;
944 c->value_uint = slapd_daemon_threads;
948 c->value_string = ch_strdup( passwd_salt );
953 if ( c->be->be_limits ) {
957 for ( i=0; c->be->be_limits[i]; i++ ) {
958 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
959 if ( bv.bv_len >= sizeof( buf ) ) {
960 ber_bvarray_free_x( c->rvalue_vals, NULL );
961 c->rvalue_vals = NULL;
965 bv.bv_val = buf + bv.bv_len;
966 limits_unparse( c->be->be_limits[i], &bv,
967 sizeof( buf ) - ( bv.bv_val - buf ) );
968 bv.bv_len += bv.bv_val - buf;
970 value_add_one( &c->rvalue_vals, &bv );
973 if ( !c->rvalue_vals ) rc = 1;
976 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_READONLY);
979 c->value_string = ch_strdup( slap_sasl_getpolicy());
982 slap_sasl_regexp_unparse( &c->rvalue_vals );
983 if ( !c->rvalue_vals ) rc = 1;
985 #ifdef HAVE_CYRUS_SASL
986 #ifdef SLAP_AUXPROP_DONTUSECOPY
988 static int duc_done = 0;
990 /* take the opportunity to initialize with known values */
992 struct berval duc[] = { BER_BVC("cmusaslsecretOTP"), BER_BVNULL };
995 for ( i = 0; !BER_BVISNULL( &duc[ i ] ); i++ ) {
996 const char *text = NULL;
997 AttributeDescription *ad = NULL;
999 if ( slap_bv2ad( &duc[ i ], &ad, &text ) == LDAP_SUCCESS ) {
1001 if ( slap_dontUseCopy_propnames ) {
1004 for ( j = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ j ] ); j++ ) {
1005 if ( bvmatch( &slap_dontUseCopy_propnames[ j ], &ad->ad_cname ) ) {
1012 value_add_one( &slap_dontUseCopy_propnames, &ad->ad_cname );
1020 if ( slap_dontUseCopy_propnames != NULL ) {
1021 ber_bvarray_dup_x( &c->rvalue_vals, slap_dontUseCopy_propnames, NULL );
1026 #endif /* SLAP_AUXPROP_DONTUSECOPY */
1027 case CFG_SASLSECP: {
1028 struct berval bv = BER_BVNULL;
1029 slap_sasl_secprops_unparse( &bv );
1030 if ( !BER_BVISNULL( &bv )) {
1031 ber_bvarray_add( &c->rvalue_vals, &bv );
1039 c->value_int = c->be->be_max_deref_depth;
1042 if ( SLAP_DBHIDDEN( c->be )) {
1049 ConfigFile *cf = c->ca_private;
1051 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1052 else if ( cf->c_om_head )
1053 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
1055 if ( !c->rvalue_vals )
1060 ad_unparse_options( &c->rvalue_vals );
1063 ConfigFile *cf = c->ca_private;
1065 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1066 else if ( cf->c_oc_head )
1067 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
1069 if ( !c->rvalue_vals )
1074 ConfigFile *cf = c->ca_private;
1076 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1077 else if ( cf->c_at_head )
1078 at_unparse( &c->rvalue_vals, cf->c_at_head,
1080 if ( !c->rvalue_vals )
1085 ConfigFile *cf = c->ca_private;
1087 syn_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1088 else if ( cf->c_syn_head )
1089 syn_unparse( &c->rvalue_vals, cf->c_syn_head,
1090 cf->c_syn_tail, 0 );
1091 if ( !c->rvalue_vals )
1096 ConfigFile *cf = c->ca_private;
1098 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1099 else if ( cf->c_cr_head )
1100 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
1102 if ( !c->rvalue_vals )
1109 char *src, *dst, ibuf[11];
1110 struct berval bv, abv;
1111 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
1112 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1113 if ( abv.bv_len >= sizeof( ibuf ) ) {
1114 ber_bvarray_free_x( c->rvalue_vals, NULL );
1115 c->rvalue_vals = NULL;
1119 acl_unparse( a, &bv );
1120 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
1121 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
1122 /* Turn TAB / EOL into plain space */
1123 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
1124 if (isspace((unsigned char)*src)) *dst++ = ' ';
1128 if (dst[-1] == ' ') {
1132 abv.bv_len = dst - abv.bv_val;
1133 ber_bvarray_add( &c->rvalue_vals, &abv );
1139 c->value_int = (SLAP_DBACL_ADD(c->be) != 0);
1142 ConfigFile *cf = c->ca_private;
1143 if ( cf->c_dseFiles ) {
1144 value_add( &c->rvalue_vals, cf->c_dseFiles );
1155 for ( si = sid_list; si; si=si->si_next ) {
1156 assert( si->si_num >= 0 && si->si_num <= SLAP_SYNC_SID_MAX );
1157 if ( !BER_BVISEMPTY( &si->si_url )) {
1158 bv.bv_len = si->si_url.bv_len + 6;
1159 bv.bv_val = ch_malloc( bv.bv_len );
1160 bv.bv_len = sprintf( bv.bv_val, "%d %s", si->si_num,
1161 si->si_url.bv_val );
1162 ber_bvarray_add( &c->rvalue_vals, &bv );
1166 bv.bv_len = sprintf( buf, "%d", si->si_num );
1167 value_add_one( &c->rvalue_vals, &bv );
1176 c->value_string = ch_strdup( logfileName );
1181 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1183 case CFG_SYNC_SUBENTRY:
1184 c->value_int = (SLAP_SYNC_SUBENTRY(c->be) != 0);
1186 case CFG_MIRRORMODE:
1187 if ( SLAP_SHADOW(c->be))
1188 c->value_int = (SLAP_MULTIMASTER(c->be) != 0);
1192 case CFG_MONITORING:
1193 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
1195 case CFG_SSTR_IF_MAX:
1196 c->value_uint = index_substr_if_maxlen;
1198 case CFG_SSTR_IF_MIN:
1199 c->value_uint = index_substr_if_minlen;
1202 c->value_int = index_intlen;
1204 case CFG_SORTVALS: {
1207 for ( sv = sortVals; sv; sv = sv->al_next ) {
1208 value_add_one( &c->rvalue_vals, &sv->al_desc->ad_cname );
1212 #ifdef SLAPD_MODULES
1214 ModPaths *mp = c->ca_private;
1217 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
1220 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
1221 SLAP_X_ORDERED_FMT "%s", i,
1222 mp->mp_loads[i].bv_val );
1223 if ( bv.bv_len >= sizeof( c->log ) ) {
1224 ber_bvarray_free_x( c->rvalue_vals, NULL );
1225 c->rvalue_vals = NULL;
1228 value_add_one( &c->rvalue_vals, &bv );
1232 rc = c->rvalue_vals ? 0 : 1;
1236 ModPaths *mp = c->ca_private;
1237 if ( !BER_BVISNULL( &mp->mp_path ))
1238 value_add_one( &c->rvalue_vals, &mp->mp_path );
1240 rc = c->rvalue_vals ? 0 : 1;
1246 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1247 if ( !c->rvalue_vals ) rc = 1;
1250 #ifdef SLAP_AUTH_REWRITE
1252 if ( authz_rewrites ) {
1253 struct berval bv, idx;
1258 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1259 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1260 if ( idx.bv_len >= sizeof( ibuf ) ) {
1261 ber_bvarray_free_x( c->rvalue_vals, NULL );
1262 c->rvalue_vals = NULL;
1265 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1266 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1267 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1268 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1269 authz_rewrites[i].bv_val,
1270 authz_rewrites[i].bv_len + 1 );
1271 ber_bvarray_add( &c->rvalue_vals, &bv );
1274 if ( !c->rvalue_vals ) rc = 1;
1281 } else if ( c->op == LDAP_MOD_DELETE ) {
1284 /* single-valued attrs, no-ops */
1293 case CFG_MONITORING:
1295 case CFG_SSTR_IF_MAX:
1296 case CFG_SSTR_IF_MIN:
1298 case CFG_SYNC_SUBENTRY:
1301 /* no-ops, requires slapd restart */
1306 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1309 case CFG_MIRRORMODE:
1310 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MULTI_SHADOW;
1311 if(SLAP_SHADOW(c->be))
1312 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1315 #if defined(HAVE_CYRUS_SASL) && defined(SLAP_AUXPROP_DONTUSECOPY)
1317 if ( c->valx < 0 ) {
1318 if ( slap_dontUseCopy_propnames != NULL ) {
1319 ber_bvarray_free( slap_dontUseCopy_propnames );
1320 slap_dontUseCopy_propnames = NULL;
1326 if ( slap_dontUseCopy_propnames == NULL ) {
1331 for ( i = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ i ] ) && i < c->valx; i++ );
1332 if ( i < c->valx ) {
1336 ber_memfree( slap_dontUseCopy_propnames[ i ].bv_val );
1337 for ( ; !BER_BVISNULL( &slap_dontUseCopy_propnames[ i + 1 ] ); i++ ) {
1338 slap_dontUseCopy_propnames[ i ] = slap_dontUseCopy_propnames[ i + 1 ];
1340 BER_BVZERO( &slap_dontUseCopy_propnames[ i ] );
1343 #endif /* SLAP_AUXPROP_DONTUSECOPY */
1345 ch_free( passwd_salt );
1350 ch_free( logfileName );
1358 case CFG_SERVERID: {
1359 ServerID *si, **sip;
1361 for ( i=0, si = sid_list, sip = &sid_list;
1362 si; si = *sip, i++ ) {
1363 if ( c->valx == -1 || i == c->valx ) {
1375 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1379 index_intlen = SLAP_INDEX_INTLEN_DEFAULT;
1380 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1381 SLAP_INDEX_INTLEN_DEFAULT );
1385 if ( c->valx < 0 ) {
1386 acl_destroy( c->be->be_acl );
1387 c->be->be_acl = NULL;
1390 AccessControl **prev, *a;
1392 for (i=0, prev = &c->be->be_acl; i < c->valx;
1395 prev = &a->acl_next;
1398 *prev = a->acl_next;
1401 if ( SLAP_CONFIG( c->be ) && !c->be->be_acl ) {
1402 Debug( LDAP_DEBUG_CONFIG, "config_generic (CFG_ACL): "
1403 "Last explicit ACL for back-config removed. "
1404 "Using hardcoded default\n", 0, 0, 0 );
1405 c->be->be_acl = defacl_parsed;
1411 /* Can be NULL when undoing a failed add */
1412 if ( c->ca_entry ) {
1413 ce = c->ca_entry->e_private;
1414 /* can't modify the hardcoded schema */
1415 if ( ce->ce_parent->ce_type == Cft_Global )
1419 cfn = c->ca_private;
1420 if ( c->valx < 0 ) {
1423 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1425 if ( oc == cfn->c_oc_tail )
1428 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1430 ObjectClass *oc, *prev = NULL;
1432 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1437 if ( cfn->c_oc_tail == oc ) {
1438 cfn->c_oc_tail = prev;
1440 if ( cfn->c_oc_head == oc ) {
1442 cfn->c_oc_head = oc;
1449 /* Can be NULL when undoing a failed add */
1450 if ( c->ca_entry ) {
1451 ce = c->ca_entry->e_private;
1452 /* can't modify the hardcoded schema */
1453 if ( ce->ce_parent->ce_type == Cft_Global )
1457 cfn = c->ca_private;
1458 if ( c->valx < 0 ) {
1461 for( at = cfn->c_at_head; at; at_next( &at )) {
1463 if ( at == cfn->c_at_tail )
1466 cfn->c_at_head = cfn->c_at_tail = NULL;
1468 AttributeType *at, *prev = NULL;
1470 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1475 if ( cfn->c_at_tail == at ) {
1476 cfn->c_at_tail = prev;
1478 if ( cfn->c_at_head == at ) {
1480 cfn->c_at_head = at;
1487 /* Can be NULL when undoing a failed add */
1488 if ( c->ca_entry ) {
1489 ce = c->ca_entry->e_private;
1490 /* can't modify the hardcoded schema */
1491 if ( ce->ce_parent->ce_type == Cft_Global )
1495 cfn = c->ca_private;
1496 if ( c->valx < 0 ) {
1499 for( syn = cfn->c_syn_head; syn; syn_next( &syn )) {
1501 if ( syn == cfn->c_syn_tail )
1504 cfn->c_syn_head = cfn->c_syn_tail = NULL;
1506 Syntax *syn, *prev = NULL;
1508 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++) {
1513 if ( cfn->c_syn_tail == syn ) {
1514 cfn->c_syn_tail = prev;
1516 if ( cfn->c_syn_head == syn ) {
1518 cfn->c_syn_head = syn;
1523 if ( c->valx < 0 ) {
1525 for ( sv = sortVals; sv; sv = sortVals ) {
1526 sortVals = sv->al_next;
1527 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1534 for ( prev = &sortVals, sv = sortVals; i < c->valx; i++ ) {
1535 prev = &sv->al_next;
1538 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1539 *prev = sv->al_next;
1545 /* FIXME: there is no limits_free function */
1546 if ( c->valx < 0 ) {
1547 limits_destroy( c->be->be_limits );
1548 c->be->be_limits = NULL;
1553 if ( c->be->be_limits ) {
1554 for ( num = 0; c->be->be_limits[ num ]; num++ )
1558 if ( c->valx >= num ) {
1563 limits_destroy( c->be->be_limits );
1564 c->be->be_limits = NULL;
1567 limits_free_one( c->be->be_limits[ c->valx ] );
1569 for ( cnt = c->valx; cnt < num; cnt++ ) {
1570 c->be->be_limits[ cnt ] = c->be->be_limits[ cnt + 1 ];
1577 /* FIXME: there is no ad_option_free function */
1579 /* FIXME: there is no way to remove attributes added by
1593 if(!(c->bi = backend_info(c->argv[1]))) {
1594 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1595 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1596 c->log, c->cr_msg, c->argv[1] );
1603 /* NOTE: config is always the first backend!
1605 if ( !strcasecmp( c->argv[1], "config" )) {
1606 c->be = LDAP_STAILQ_FIRST(&backendDB);
1607 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1610 c->be = backend_db_init(c->argv[1], NULL, c->valx, &c->reply);
1612 if ( c->cr_msg[0] == 0 )
1613 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1614 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n", c->log, c->cr_msg, c->argv[1] );
1621 ldap_pvt_thread_set_concurrency(c->value_int);
1625 if ( c->value_int < 2 ) {
1626 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1627 "threads=%d smaller than minimum value 2",
1629 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1630 c->log, c->cr_msg, 0 );
1633 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1634 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1635 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1636 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1637 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1638 c->log, c->cr_msg, 0 );
1640 if ( slapMode & SLAP_SERVER_MODE )
1641 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1642 connection_pool_max = c->value_int; /* save for reference */
1646 if ( slapMode & SLAP_TOOL_MODE )
1647 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1648 slap_tool_thread_max = c->value_int; /* save for reference */
1653 /* use a power of two */
1654 while (c->value_uint > 1) {
1655 c->value_uint >>= 1;
1659 slapd_daemon_mask = mask;
1660 slapd_daemon_threads = mask+1;
1665 if ( passwd_salt ) ch_free( passwd_salt );
1666 passwd_salt = c->value_string;
1667 lutil_salt_format(passwd_salt);
1671 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1677 c->be->be_restrictops |= SLAP_RESTRICT_READONLY;
1679 c->be->be_restrictops &= ~SLAP_RESTRICT_READONLY;
1683 ch_free(c->value_string);
1684 if (slap_sasl_setpolicy( c->argv[1] )) {
1685 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
1686 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1687 c->log, c->cr_msg, c->argv[1] );
1693 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1697 #ifdef HAVE_CYRUS_SASL
1698 #ifdef SLAP_AUXPROP_DONTUSECOPY
1702 for ( arg = 1; arg < c->argc; arg++ ) {
1703 int duplicate = 0, err;
1704 AttributeDescription *ad = NULL;
1705 const char *text = NULL;
1707 err = slap_str2ad( c->argv[ arg ], &ad, &text );
1708 if ( err != LDAP_SUCCESS ) {
1709 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s>: attr #%d (\"%s\") unknown (err=%d \"%s\"; ignored)",
1710 c->argv[0], arg, c->argv[ arg ], err, text );
1711 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1712 c->log, c->cr_msg, 0 );
1715 if ( slap_dontUseCopy_propnames != NULL ) {
1716 for ( cnt = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ cnt ] ); cnt++ ) {
1717 if ( bvmatch( &slap_dontUseCopy_propnames[ cnt ], &ad->ad_cname ) ) {
1725 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s>: attr #%d (\"%s\") already defined (ignored)",
1726 c->argv[0], arg, ad->ad_cname.bv_val);
1727 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1728 c->log, c->cr_msg, 0 );
1732 value_add_one( &slap_dontUseCopy_propnames, &ad->ad_cname );
1737 #endif /* SLAP_AUXPROP_DONTUSECOPY */
1741 char *txt = slap_sasl_secprops( c->argv[1] );
1743 snprintf( c->cr_msg, sizeof(c->cr_msg), "<%s> %s",
1745 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0 );
1753 c->be->be_max_deref_depth = c->value_int;
1759 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1760 cfn = c->ca_private;
1761 if(parse_oidm(c, 1, &om))
1763 if (!cfn->c_om_head) cfn->c_om_head = om;
1764 cfn->c_om_tail = om;
1769 ObjectClass *oc, *prev;
1771 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1772 cfn = c->ca_private;
1773 if ( c->valx < 0 ) {
1774 prev = cfn->c_oc_tail;
1777 /* If adding anything after the first, prev is easy */
1780 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
1782 if ( !oc_next( &oc ))
1786 /* If adding the first, and head exists, find its prev */
1787 if (cfn->c_oc_head) {
1788 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
1793 /* else prev is NULL, append to end of global list */
1795 if(parse_oc(c, &oc, prev)) return(1);
1796 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1797 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
1802 AttributeType *at, *prev;
1804 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1805 cfn = c->ca_private;
1806 if ( c->valx < 0 ) {
1807 prev = cfn->c_at_tail;
1810 /* If adding anything after the first, prev is easy */
1813 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
1815 if ( !at_next( &at ))
1819 /* If adding the first, and head exists, find its prev */
1820 if (cfn->c_at_head) {
1821 for ( at_start( &at ); at != cfn->c_at_head; ) {
1826 /* else prev is NULL, append to end of global list */
1828 if(parse_at(c, &at, prev)) return(1);
1829 if (!cfn->c_at_head) cfn->c_at_head = at;
1830 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
1837 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1838 cfn = c->ca_private;
1839 if ( c->valx < 0 ) {
1840 prev = cfn->c_syn_tail;
1843 /* If adding anything after the first, prev is easy */
1846 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++ ) {
1848 if ( !syn_next( &syn ))
1852 /* If adding the first, and head exists, find its prev */
1853 if (cfn->c_syn_head) {
1854 for ( syn_start( &syn ); syn != cfn->c_syn_head; ) {
1859 /* else prev is NULL, append to end of global list */
1861 if ( parse_syn( c, &syn, prev ) ) return(1);
1862 if ( !cfn->c_syn_head ) cfn->c_syn_head = syn;
1863 if ( cfn->c_syn_tail == prev ) cfn->c_syn_tail = syn;
1870 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1871 cfn = c->ca_private;
1872 if(parse_cr(c, &cr)) return(1);
1873 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1874 cfn->c_cr_tail = cr;
1879 ad_define_option(NULL, NULL, 0);
1880 for(i = 1; i < c->argc; i++)
1881 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1886 if ( c->value_int < SLAP_INDEX_INTLEN_DEFAULT )
1887 c->value_int = SLAP_INDEX_INTLEN_DEFAULT;
1888 else if ( c->value_int > 255 )
1890 index_intlen = c->value_int;
1891 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1895 case CFG_SORTVALS: {
1896 ADlist *svnew = NULL, *svtail, *sv;
1898 for ( i = 1; i < c->argc; i++ ) {
1899 AttributeDescription *ad = NULL;
1903 rc = slap_str2ad( c->argv[i], &ad, &text );
1905 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown attribute type #%d",
1908 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1909 c->log, c->cr_msg, c->argv[i] );
1910 for ( sv = svnew; sv; sv = svnew ) {
1911 svnew = sv->al_next;
1916 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) ||
1917 ad->ad_type->sat_single_value ) {
1918 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> inappropriate attribute type #%d",
1920 goto sortval_reject;
1922 sv = ch_malloc( sizeof( ADlist ));
1927 svtail->al_next = sv;
1932 for ( sv = svnew; sv; sv = sv->al_next )
1933 sv->al_desc->ad_type->sat_flags |= SLAP_AT_SORTED_VAL;
1934 for ( sv = sortVals; sv && sv->al_next; sv = sv->al_next );
1936 sv->al_next = svnew;
1943 if ( SLAP_CONFIG( c->be ) && c->be->be_acl == defacl_parsed) {
1944 c->be->be_acl = NULL;
1946 /* Don't append to the global ACL if we're on a specific DB */
1948 if ( c->valx == -1 ) {
1951 for ( a=c->be->be_acl; a; a = a->acl_next )
1954 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
1955 if ( SLAP_CONFIG( c->be ) && !c->be->be_acl) {
1956 c->be->be_acl = defacl_parsed;
1964 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_ACL_ADD;
1966 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_ACL_ADD;
1970 if(root_dse_read_file(c->argv[1])) {
1971 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> could not read file", c->argv[0] );
1972 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1973 c->log, c->cr_msg, c->argv[1] );
1978 ber_str2bv( c->argv[1], 0, 1, &bv );
1979 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1980 cfn = c->ca_private;
1981 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1987 ServerID *si, **sip;
1990 if (( lutil_atoi( &num, c->argv[1] ) &&
1991 lutil_atoix( &num, c->argv[1], 16 )) ||
1992 num < 0 || num > SLAP_SYNC_SID_MAX )
1994 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1995 "<%s> illegal server ID", c->argv[0] );
1996 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1997 c->log, c->cr_msg, c->argv[1] );
2000 /* only one value allowed if no URL is given */
2001 if ( c->argc > 2 ) {
2004 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
2005 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2006 "<%s> only one server ID allowed now", c->argv[0] );
2007 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2008 c->log, c->cr_msg, c->argv[1] );
2012 if ( ldap_url_parse( c->argv[2], &lud )) {
2013 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2014 "<%s> invalid URL", c->argv[0] );
2015 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2016 c->log, c->cr_msg, c->argv[2] );
2019 len = strlen( c->argv[2] );
2020 si = ch_malloc( sizeof(ServerID) + len + 1 );
2021 si->si_url.bv_val = (char *)(si+1);
2022 si->si_url.bv_len = len;
2023 strcpy( si->si_url.bv_val, c->argv[2] );
2026 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2027 "<%s> unqualified server ID not allowed now", c->argv[0] );
2028 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2029 c->log, c->cr_msg, c->argv[1] );
2032 si = ch_malloc( sizeof(ServerID) );
2033 BER_BVZERO( &si->si_url );
2034 slap_serverID = num;
2035 Debug( LDAP_DEBUG_CONFIG,
2037 c->log, slap_serverID, 0 );
2041 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
2044 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
2045 Listener *l = config_check_my_url( c->argv[2], lud );
2047 slap_serverID = si->si_num;
2048 Debug( LDAP_DEBUG_CONFIG,
2049 "%s: SID=0x%03x (listener=%s)\n",
2050 c->log, slap_serverID,
2055 ldap_free_urldesc( lud );
2059 if ( logfileName ) ch_free( logfileName );
2060 logfileName = c->value_string;
2061 logfile = fopen(logfileName, "w");
2062 if(logfile) lutil_debug_file(logfile);
2066 if(SLAP_NOLASTMODCMD(c->be)) {
2067 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> not available for %s database",
2068 c->argv[0], c->be->bd_info->bi_type );
2069 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2070 c->log, c->cr_msg, 0 );
2074 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
2076 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
2079 case CFG_MIRRORMODE:
2080 if(c->value_int && !SLAP_SHADOW(c->be)) {
2081 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database is not a shadow",
2083 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2084 c->log, c->cr_msg, 0 );
2088 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
2089 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MULTI_SHADOW;
2091 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
2092 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MULTI_SHADOW;
2096 case CFG_MONITORING:
2098 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
2100 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
2105 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
2107 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
2110 case CFG_SYNC_SUBENTRY:
2112 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SYNC_SUBENTRY;
2114 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SYNC_SUBENTRY;
2117 case CFG_SSTR_IF_MAX:
2118 if (c->value_uint < index_substr_if_minlen) {
2119 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
2120 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
2121 c->log, c->cr_msg, c->value_int );
2124 index_substr_if_maxlen = c->value_uint;
2127 case CFG_SSTR_IF_MIN:
2128 if (c->value_uint > index_substr_if_maxlen) {
2129 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
2130 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
2131 c->log, c->cr_msg, c->value_int );
2134 index_substr_if_minlen = c->value_uint;
2137 #ifdef SLAPD_MODULES
2139 /* If we're just adding a module on an existing modpath,
2140 * make sure we've selected the current path.
2142 if ( c->op == LDAP_MOD_ADD && c->ca_private && modcur != c->ca_private ) {
2143 modcur = c->ca_private;
2144 /* This should never fail */
2145 if ( module_path( modcur->mp_path.bv_val )) {
2146 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> module path no longer valid",
2148 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2149 c->log, c->cr_msg, modcur->mp_path.bv_val );
2153 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
2155 /* Record this load on the current path */
2159 if ( c->op == SLAP_CONFIG_ADD ) {
2160 ptr = c->line + STRLENOF("moduleload");
2161 while (!isspace((unsigned char) *ptr)) ptr++;
2162 while (isspace((unsigned char) *ptr)) ptr++;
2166 ber_str2bv(ptr, 0, 1, &bv);
2167 ber_bvarray_add( &modcur->mp_loads, &bv );
2169 /* Check for any new hardcoded schema */
2170 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
2171 config_check_schema( NULL, &cfBackInfo );
2176 if(module_path(c->argv[1])) return(1);
2177 /* Record which path was used with each module */
2181 if (!modpaths.mp_loads) {
2184 mp = ch_malloc( sizeof( ModPaths ));
2185 modlast->mp_next = mp;
2187 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
2189 mp->mp_loads = NULL;
2200 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
2202 slapi_plugins_used++;
2206 #ifdef SLAP_AUTH_REWRITE
2212 if ( c->op == LDAP_MOD_ADD ) {
2216 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
2220 if ( c->argc > 1 ) {
2223 /* quote all args but the first */
2224 line = ldap_charray2str( c->argv, "\" \"" );
2225 ber_str2bv( line, 0, 0, &bv );
2226 s = ber_bvchr( &bv, '"' );
2227 assert( s != NULL );
2228 /* move the trailing quote of argv[0] to the end */
2229 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
2230 bv.bv_val[ bv.bv_len - 1 ] = '"';
2233 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
2236 ber_bvarray_add( &authz_rewrites, &bv );
2238 if ( c->op == LDAP_MOD_ADD ) {
2248 Debug( LDAP_DEBUG_ANY,
2249 "%s: unknown CFG_TYPE %d.\n",
2250 c->log, c->type, 0 );
2259 config_fname(ConfigArgs *c) {
2260 if(c->op == SLAP_CONFIG_EMIT) {
2261 if (c->ca_private) {
2262 ConfigFile *cf = c->ca_private;
2263 value_add_one( &c->rvalue_vals, &cf->c_file );
2272 config_cfdir(ConfigArgs *c) {
2273 if(c->op == SLAP_CONFIG_EMIT) {
2274 if ( !BER_BVISEMPTY( &cfdir )) {
2275 value_add_one( &c->rvalue_vals, &cfdir );
2284 config_search_base(ConfigArgs *c) {
2285 if(c->op == SLAP_CONFIG_EMIT) {
2287 if (!BER_BVISEMPTY(&default_search_base)) {
2288 value_add_one(&c->rvalue_vals, &default_search_base);
2289 value_add_one(&c->rvalue_nvals, &default_search_nbase);
2293 } else if( c->op == LDAP_MOD_DELETE ) {
2294 ch_free( default_search_base.bv_val );
2295 ch_free( default_search_nbase.bv_val );
2296 BER_BVZERO( &default_search_base );
2297 BER_BVZERO( &default_search_nbase );
2301 if(c->bi || c->be != frontendDB) {
2302 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
2303 "prior to any backend or database definition\n",
2308 if(default_search_nbase.bv_len) {
2309 free(default_search_base.bv_val);
2310 free(default_search_nbase.bv_val);
2313 default_search_base = c->value_dn;
2314 default_search_nbase = c->value_ndn;
2318 /* For RE23 compatibility we allow this in the global entry
2319 * but we now defer it to the frontend entry to allow modules
2320 * to load new hash types.
2323 config_passwd_hash(ConfigArgs *c) {
2325 if (c->op == SLAP_CONFIG_EMIT) {
2327 /* Don't generate it in the global entry */
2328 if ( c->table == Cft_Global )
2330 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
2331 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
2332 value_add_one(&c->rvalue_vals, &bv);
2335 } else if ( c->op == LDAP_MOD_DELETE ) {
2336 /* Deleting from global is a no-op, only the frontendDB entry matters */
2337 if ( c->table == Cft_Global )
2339 if ( c->valx < 0 ) {
2340 ldap_charray_free( default_passwd_hash );
2341 default_passwd_hash = NULL;
2344 ch_free( default_passwd_hash[i] );
2345 for (; default_passwd_hash[i]; i++ )
2346 default_passwd_hash[i] = default_passwd_hash[i+1];
2350 for(i = 1; i < c->argc; i++) {
2351 if(!lutil_passwd_scheme(c->argv[i])) {
2352 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> scheme not available", c->argv[0] );
2353 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2354 c->log, c->cr_msg, c->argv[i]);
2356 ldap_charray_add(&default_passwd_hash, c->argv[i]);
2359 if(!default_passwd_hash) {
2360 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> no valid hashes found", c->argv[0] );
2361 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2362 c->log, c->cr_msg, 0 );
2369 config_schema_dn(ConfigArgs *c) {
2370 if ( c->op == SLAP_CONFIG_EMIT ) {
2372 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
2373 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
2374 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
2378 } else if ( c->op == LDAP_MOD_DELETE ) {
2379 ch_free( c->be->be_schemadn.bv_val );
2380 ch_free( c->be->be_schemandn.bv_val );
2381 BER_BVZERO( &c->be->be_schemadn );
2382 BER_BVZERO( &c->be->be_schemandn );
2385 ch_free( c->be->be_schemadn.bv_val );
2386 ch_free( c->be->be_schemandn.bv_val );
2387 c->be->be_schemadn = c->value_dn;
2388 c->be->be_schemandn = c->value_ndn;
2393 config_sizelimit(ConfigArgs *c) {
2395 struct slap_limits_set *lim = &c->be->be_def_limit;
2396 if (c->op == SLAP_CONFIG_EMIT) {
2401 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
2402 if ( !BER_BVISEMPTY( &bv ))
2403 value_add_one( &c->rvalue_vals, &bv );
2407 } else if ( c->op == LDAP_MOD_DELETE ) {
2408 /* Reset to defaults or values from frontend */
2409 if ( c->be == frontendDB ) {
2410 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
2411 lim->lms_s_hard = 0;
2412 lim->lms_s_unchecked = -1;
2414 lim->lms_s_pr_hide = 0;
2415 lim->lms_s_pr_total = 0;
2417 lim->lms_s_soft = frontendDB->be_def_limit.lms_s_soft;
2418 lim->lms_s_hard = frontendDB->be_def_limit.lms_s_hard;
2419 lim->lms_s_unchecked = frontendDB->be_def_limit.lms_s_unchecked;
2420 lim->lms_s_pr = frontendDB->be_def_limit.lms_s_pr;
2421 lim->lms_s_pr_hide = frontendDB->be_def_limit.lms_s_pr_hide;
2422 lim->lms_s_pr_total = frontendDB->be_def_limit.lms_s_pr_total;
2426 for(i = 1; i < c->argc; i++) {
2427 if(!strncasecmp(c->argv[i], "size", 4)) {
2428 rc = limits_parse_one(c->argv[i], lim);
2430 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2431 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2432 c->log, c->cr_msg, c->argv[i]);
2436 if(!strcasecmp(c->argv[i], "unlimited")) {
2437 lim->lms_s_soft = -1;
2439 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
2440 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2441 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2442 c->log, c->cr_msg, c->argv[i]);
2446 lim->lms_s_hard = 0;
2451 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2452 /* This is a modification to the global limits apply it to
2453 * the other databases as needed */
2454 AttributeDescription *ad=NULL;
2455 const char *text = NULL;
2456 CfEntryInfo *ce = c->ca_entry->e_private;
2458 slap_str2ad(c->argv[0], &ad, &text);
2459 /* if we got here... */
2460 assert( ad != NULL );
2462 if ( ce->ce_type == Cft_Global ){
2465 for (; ce; ce=ce->ce_sibs) {
2466 Entry *dbe = ce->ce_entry;
2467 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2468 && (!attr_find(dbe->e_attrs, ad)) ) {
2469 ce->ce_be->be_def_limit.lms_s_soft = lim->lms_s_soft;
2470 ce->ce_be->be_def_limit.lms_s_hard = lim->lms_s_hard;
2471 ce->ce_be->be_def_limit.lms_s_unchecked =lim->lms_s_unchecked;
2472 ce->ce_be->be_def_limit.lms_s_pr =lim->lms_s_pr;
2473 ce->ce_be->be_def_limit.lms_s_pr_hide =lim->lms_s_pr_hide;
2474 ce->ce_be->be_def_limit.lms_s_pr_total =lim->lms_s_pr_total;
2482 config_timelimit(ConfigArgs *c) {
2484 struct slap_limits_set *lim = &c->be->be_def_limit;
2485 if (c->op == SLAP_CONFIG_EMIT) {
2490 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
2491 if ( !BER_BVISEMPTY( &bv ))
2492 value_add_one( &c->rvalue_vals, &bv );
2496 } else if ( c->op == LDAP_MOD_DELETE ) {
2497 /* Reset to defaults or values from frontend */
2498 if ( c->be == frontendDB ) {
2499 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
2500 lim->lms_t_hard = 0;
2502 lim->lms_t_soft = frontendDB->be_def_limit.lms_t_soft;
2503 lim->lms_t_hard = frontendDB->be_def_limit.lms_t_hard;
2507 for(i = 1; i < c->argc; i++) {
2508 if(!strncasecmp(c->argv[i], "time", 4)) {
2509 rc = limits_parse_one(c->argv[i], lim);
2511 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2512 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2513 c->log, c->cr_msg, c->argv[i]);
2517 if(!strcasecmp(c->argv[i], "unlimited")) {
2518 lim->lms_t_soft = -1;
2520 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
2521 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2522 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2523 c->log, c->cr_msg, c->argv[i]);
2527 lim->lms_t_hard = 0;
2532 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2533 /* This is a modification to the global limits apply it to
2534 * the other databases as needed */
2535 AttributeDescription *ad=NULL;
2536 const char *text = NULL;
2537 CfEntryInfo *ce = c->ca_entry->e_private;
2539 slap_str2ad(c->argv[0], &ad, &text);
2540 /* if we got here... */
2541 assert( ad != NULL );
2543 if ( ce->ce_type == Cft_Global ){
2546 for (; ce; ce=ce->ce_sibs) {
2547 Entry *dbe = ce->ce_entry;
2548 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2549 && (!attr_find(dbe->e_attrs, ad)) ) {
2550 ce->ce_be->be_def_limit.lms_t_soft = lim->lms_t_soft;
2551 ce->ce_be->be_def_limit.lms_t_hard = lim->lms_t_hard;
2559 config_overlay(ConfigArgs *c) {
2560 if (c->op == SLAP_CONFIG_EMIT) {
2562 } else if ( c->op == LDAP_MOD_DELETE ) {
2565 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2566 c->valx, &c->bi, &c->reply)) {
2568 Debug( LDAP_DEBUG_ANY,
2569 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2570 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2572 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi, &c->reply)) {
2579 config_subordinate(ConfigArgs *c)
2585 case SLAP_CONFIG_EMIT:
2586 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2589 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2590 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2593 value_add_one( &c->rvalue_vals, &bv );
2597 case LDAP_MOD_DELETE:
2598 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2599 glue_sub_del( c->be );
2601 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2606 case SLAP_CONFIG_ADD:
2607 if ( c->be->be_nsuffix == NULL ) {
2609 snprintf( c->cr_msg, sizeof( c->cr_msg),
2610 "subordinate configuration needs a suffix" );
2611 Debug( LDAP_DEBUG_ANY,
2613 c->log, c->cr_msg, 0 );
2618 if ( c->argc == 2 ) {
2619 if ( strcasecmp( c->argv[1], "advertise" ) == 0 ) {
2622 } else if ( strcasecmp( c->argv[1], "TRUE" ) != 0 ) {
2624 snprintf( c->cr_msg, sizeof( c->cr_msg),
2625 "subordinate must be \"TRUE\" or \"advertise\"" );
2626 Debug( LDAP_DEBUG_ANY,
2627 "%s: suffix \"%s\": %s.\n",
2628 c->log, c->be->be_suffix[0].bv_val, c->cr_msg );
2634 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2642 * [listener=<listener>] [{read|write}=]<size>
2645 #ifdef LDAP_TCP_BUFFER
2646 static BerVarray tcp_buffer;
2649 #define SLAP_TCP_RMEM (0x1U)
2650 #define SLAP_TCP_WMEM (0x2U)
2653 tcp_buffer_parse( struct berval *val, int argc, char **argv,
2654 int *size, int *rw, Listener **l )
2656 int i, rc = LDAP_SUCCESS;
2657 LDAPURLDesc *lud = NULL;
2660 if ( val != NULL && argv == NULL ) {
2661 char *s = val->bv_val;
2663 argv = ldap_str2charray( s, " \t" );
2664 if ( argv == NULL ) {
2670 if ( strncasecmp( argv[ i ], "listener=", STRLENOF( "listener=" ) )
2673 char *url = argv[ i ] + STRLENOF( "listener=" );
2675 if ( ldap_url_parse( url, &lud ) ) {
2676 rc = LDAP_INVALID_SYNTAX;
2680 *l = config_check_my_url( url, lud );
2682 rc = LDAP_NO_SUCH_ATTRIBUTE;
2690 if ( strncasecmp( ptr, "read=", STRLENOF( "read=" ) ) == 0 ) {
2691 *rw |= SLAP_TCP_RMEM;
2692 ptr += STRLENOF( "read=" );
2694 } else if ( strncasecmp( ptr, "write=", STRLENOF( "write=" ) ) == 0 ) {
2695 *rw |= SLAP_TCP_WMEM;
2696 ptr += STRLENOF( "write=" );
2699 *rw |= ( SLAP_TCP_RMEM | SLAP_TCP_WMEM );
2702 /* accept any base */
2703 if ( lutil_atoix( size, ptr, 0 ) ) {
2704 rc = LDAP_INVALID_SYNTAX;
2709 if ( val != NULL && argv != NULL ) {
2710 ldap_charray_free( argv );
2713 if ( lud != NULL ) {
2714 ldap_free_urldesc( lud );
2721 tcp_buffer_delete_one( struct berval *val )
2724 int size = -1, rw = 0;
2727 rc = tcp_buffer_parse( val, 0, NULL, &size, &rw, &l );
2734 Listener **ll = slapd_get_listeners();
2736 for ( i = 0; ll[ i ] != NULL; i++ ) {
2737 if ( ll[ i ] == l ) break;
2740 if ( ll[ i ] == NULL ) {
2741 return LDAP_NO_SUCH_ATTRIBUTE;
2744 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = -1;
2745 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = -1;
2747 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2748 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = -1;
2749 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = -1;
2753 /* NOTE: this affects listeners without a specific setting,
2754 * does not reset all listeners. If a listener without
2755 * specific settings was assigned a buffer because of
2756 * a global setting, it will not be reset. In any case,
2757 * buffer changes will only take place at restart. */
2758 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = -1;
2759 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = -1;
2766 tcp_buffer_delete( BerVarray vals )
2770 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
2771 tcp_buffer_delete_one( &vals[ i ] );
2778 tcp_buffer_unparse( int size, int rw, Listener *l, struct berval *val )
2780 char buf[sizeof("2147483648")], *ptr;
2782 /* unparse for later use */
2783 val->bv_len = snprintf( buf, sizeof( buf ), "%d", size );
2785 val->bv_len += STRLENOF( "listener=" " " ) + l->sl_url.bv_len;
2788 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2789 if ( rw & SLAP_TCP_RMEM ) {
2790 val->bv_len += STRLENOF( "read=" );
2791 } else if ( rw & SLAP_TCP_WMEM ) {
2792 val->bv_len += STRLENOF( "write=" );
2796 val->bv_val = SLAP_MALLOC( val->bv_len + 1 );
2801 ptr = lutil_strcopy( ptr, "listener=" );
2802 ptr = lutil_strncopy( ptr, l->sl_url.bv_val, l->sl_url.bv_len );
2806 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2807 if ( rw & SLAP_TCP_RMEM ) {
2808 ptr = lutil_strcopy( ptr, "read=" );
2809 } else if ( rw & SLAP_TCP_WMEM ) {
2810 ptr = lutil_strcopy( ptr, "write=" );
2814 ptr = lutil_strcopy( ptr, buf );
2817 assert( val->bv_val + val->bv_len == ptr );
2819 return LDAP_SUCCESS;
2823 tcp_buffer_add_one( int argc, char **argv )
2826 int size = -1, rw = 0;
2832 rc = tcp_buffer_parse( NULL, argc, argv, &size, &rw, &l );
2837 /* unparse for later use */
2838 rc = tcp_buffer_unparse( size, rw, l, &val );
2839 if ( rc != LDAP_SUCCESS ) {
2843 /* use parsed values */
2846 Listener **ll = slapd_get_listeners();
2848 for ( i = 0; ll[ i ] != NULL; i++ ) {
2849 if ( ll[ i ] == l ) break;
2852 if ( ll[ i ] == NULL ) {
2853 return LDAP_NO_SUCH_ATTRIBUTE;
2856 /* buffer only applies to TCP listeners;
2857 * we do not do any check here, and delegate them
2858 * to setsockopt(2) */
2859 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = size;
2860 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = size;
2862 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2863 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = size;
2864 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = size;
2868 /* NOTE: this affects listeners without a specific setting,
2869 * does not set all listeners */
2870 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = size;
2871 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = size;
2874 tcp_buffer = SLAP_REALLOC( tcp_buffer, sizeof( struct berval ) * ( tcp_buffer_num + 2 ) );
2876 tcp_buffer[ tcp_buffer_num ] = val;
2879 BER_BVZERO( &tcp_buffer[ tcp_buffer_num ] );
2885 config_tcp_buffer( ConfigArgs *c )
2887 if ( c->op == SLAP_CONFIG_EMIT ) {
2888 if ( tcp_buffer == NULL || BER_BVISNULL( &tcp_buffer[ 0 ] ) ) {
2891 value_add( &c->rvalue_vals, tcp_buffer );
2892 value_add( &c->rvalue_nvals, tcp_buffer );
2894 } else if ( c->op == LDAP_MOD_DELETE ) {
2896 tcp_buffer_delete( tcp_buffer );
2897 ber_bvarray_free( tcp_buffer );
2903 int size = -1, rw = 0;
2906 struct berval val = BER_BVNULL;
2910 if ( tcp_buffer_num == 0 ) {
2915 rc = tcp_buffer_parse( NULL, c->argc - 1, &c->argv[ 1 ], &size, &rw, &l );
2920 /* unparse for later use */
2921 rc = tcp_buffer_unparse( size, rw, l, &val );
2922 if ( rc != LDAP_SUCCESS ) {
2926 for ( i = 0; !BER_BVISNULL( &tcp_buffer[ i ] ); i++ ) {
2927 if ( bvmatch( &tcp_buffer[ i ], &val ) ) {
2932 if ( BER_BVISNULL( &tcp_buffer[ i ] ) ) {
2938 tcp_buffer_delete_one( &tcp_buffer[ i ] );
2939 ber_memfree( tcp_buffer[ i ].bv_val );
2940 for ( ; i < tcp_buffer_num; i++ ) {
2941 tcp_buffer[ i ] = tcp_buffer[ i + 1 ];
2946 if ( !BER_BVISNULL( &val ) ) {
2947 SLAP_FREE( val.bv_val );
2955 rc = tcp_buffer_add_one( c->argc - 1, &c->argv[ 1 ] );
2957 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2958 "<%s> unable to add value #%d",
2959 c->argv[0], tcp_buffer_num );
2960 Debug( LDAP_DEBUG_ANY, "%s: %s\n",
2961 c->log, c->cr_msg, 0 );
2968 #endif /* LDAP_TCP_BUFFER */
2971 config_suffix(ConfigArgs *c)
2974 struct berval pdn, ndn;
2975 char *notallowed = NULL;
2977 if ( c->be == frontendDB ) {
2978 notallowed = "frontend";
2980 } else if ( SLAP_MONITOR(c->be) ) {
2981 notallowed = "monitor";
2983 } else if ( SLAP_CONFIG(c->be) ) {
2984 notallowed = "config";
2987 if ( notallowed != NULL ) {
2988 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
2992 case LDAP_MOD_DELETE:
2993 case LDAP_MOD_REPLACE:
2994 case LDAP_MOD_INCREMENT:
2995 case SLAP_CONFIG_ADD:
2996 if ( !BER_BVISNULL( &c->value_dn ) ) {
2997 snprintf( buf, sizeof( buf ), "<%s> ",
2998 c->value_dn.bv_val );
3001 Debug(LDAP_DEBUG_ANY,
3002 "%s: suffix %snot allowed in %s database.\n",
3003 c->log, buf, notallowed );
3006 case SLAP_CONFIG_EMIT:
3007 /* don't complain when emitting... */
3011 /* FIXME: don't know what values may be valid;
3012 * please remove assertion, or add legal values
3013 * to either block */
3021 if (c->op == SLAP_CONFIG_EMIT) {
3022 if ( c->be->be_suffix == NULL
3023 || BER_BVISNULL( &c->be->be_suffix[0] ) )
3027 value_add( &c->rvalue_vals, c->be->be_suffix );
3028 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
3031 } else if ( c->op == LDAP_MOD_DELETE ) {
3032 if ( c->valx < 0 ) {
3033 ber_bvarray_free( c->be->be_suffix );
3034 ber_bvarray_free( c->be->be_nsuffix );
3035 c->be->be_suffix = NULL;
3036 c->be->be_nsuffix = NULL;
3039 ch_free( c->be->be_suffix[i].bv_val );
3040 ch_free( c->be->be_nsuffix[i].bv_val );
3042 c->be->be_suffix[i] = c->be->be_suffix[i+1];
3043 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
3045 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
3050 #ifdef SLAPD_MONITOR_DN
3051 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
3052 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> DN is reserved for monitoring slapd",
3054 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3055 c->log, c->cr_msg, SLAPD_MONITOR_DN);
3060 if (SLAP_DB_ONE_SUFFIX( c->be ) && c->be->be_suffix ) {
3061 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> Only one suffix is allowed on this %s backend",
3062 c->argv[0], c->be->bd_info->bi_type );
3063 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3064 c->log, c->cr_msg, 0);
3071 if (SLAP_DBHIDDEN( c->be ))
3074 tbe = select_backend(&ndn, 0);
3076 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
3082 BackendDB *b2 = tbe;
3084 /* Does tbe precede be? */
3085 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
3088 char *type = tbe->bd_info->bi_type;
3090 if ( overlay_is_over( tbe ) ) {
3091 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
3092 type = oi->oi_orig->bi_type;
3095 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> namingContext \"%s\" "
3096 "already served by a preceding %s database",
3097 c->argv[0], pdn.bv_val, type );
3098 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
3099 c->log, c->cr_msg, tbe->be_suffix[0].bv_val);
3105 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
3106 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
3107 "base provided \"%s\" (assuming okay)\n",
3108 c->log, default_search_base.bv_val, 0);
3110 ber_bvarray_add(&c->be->be_suffix, &pdn);
3111 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
3116 config_rootdn(ConfigArgs *c) {
3117 if (c->op == SLAP_CONFIG_EMIT) {
3118 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
3119 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
3120 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
3125 } else if ( c->op == LDAP_MOD_DELETE ) {
3126 ch_free( c->be->be_rootdn.bv_val );
3127 ch_free( c->be->be_rootndn.bv_val );
3128 BER_BVZERO( &c->be->be_rootdn );
3129 BER_BVZERO( &c->be->be_rootndn );
3132 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
3133 ch_free( c->be->be_rootdn.bv_val );
3134 ch_free( c->be->be_rootndn.bv_val );
3136 c->be->be_rootdn = c->value_dn;
3137 c->be->be_rootndn = c->value_ndn;
3142 config_rootpw(ConfigArgs *c) {
3145 if (c->op == SLAP_CONFIG_EMIT) {
3146 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
3147 /* don't copy, because "rootpw" is marked
3149 c->value_bv = c->be->be_rootpw;
3153 } else if ( c->op == LDAP_MOD_DELETE ) {
3154 ch_free( c->be->be_rootpw.bv_val );
3155 BER_BVZERO( &c->be->be_rootpw );
3159 tbe = select_backend(&c->be->be_rootndn, 0);
3161 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> can only be set when rootdn is under suffix",
3163 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3164 c->log, c->cr_msg, 0);
3167 if ( !BER_BVISNULL( &c->be->be_rootpw ))
3168 ch_free( c->be->be_rootpw.bv_val );
3169 c->be->be_rootpw = c->value_bv;
3174 config_restrict(ConfigArgs *c) {
3175 slap_mask_t restrictops = 0;
3177 slap_verbmasks restrictable_ops[] = {
3178 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
3179 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
3180 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
3181 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
3182 { BER_BVC("modrdn"), 0 },
3183 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
3184 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
3185 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
3186 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
3187 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
3188 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
3189 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
3190 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
3191 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
3192 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
3193 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
3197 if (c->op == SLAP_CONFIG_EMIT) {
3198 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
3200 } else if ( c->op == LDAP_MOD_DELETE ) {
3202 c->be->be_restrictops = 0;
3204 i = verb_to_mask( c->line, restrictable_ops );
3205 c->be->be_restrictops &= ~restrictable_ops[i].mask;
3209 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
3211 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown operation", c->argv[0] );
3212 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3213 c->log, c->cr_msg, c->argv[i]);
3216 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
3217 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
3218 c->be->be_restrictops |= restrictops;
3223 config_allows(ConfigArgs *c) {
3224 slap_mask_t allows = 0;
3226 slap_verbmasks allowable_ops[] = {
3227 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
3228 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
3229 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
3230 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
3231 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
3234 if (c->op == SLAP_CONFIG_EMIT) {
3235 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
3236 } else if ( c->op == LDAP_MOD_DELETE ) {
3240 i = verb_to_mask( c->line, allowable_ops );
3241 global_allows &= ~allowable_ops[i].mask;
3245 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
3247 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3248 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3249 c->log, c->cr_msg, c->argv[i]);
3252 global_allows |= allows;
3257 config_disallows(ConfigArgs *c) {
3258 slap_mask_t disallows = 0;
3260 slap_verbmasks disallowable_ops[] = {
3261 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
3262 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
3263 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
3264 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
3265 { BER_BVC("proxy_authz_non_critical"), SLAP_DISALLOW_PROXY_AUTHZ_N_CRIT },
3266 { BER_BVC("dontusecopy_non_critical"), SLAP_DISALLOW_DONTUSECOPY_N_CRIT },
3269 if (c->op == SLAP_CONFIG_EMIT) {
3270 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
3271 } else if ( c->op == LDAP_MOD_DELETE ) {
3273 global_disallows = 0;
3275 i = verb_to_mask( c->line, disallowable_ops );
3276 global_disallows &= ~disallowable_ops[i].mask;
3280 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
3282 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3283 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3284 c->log, c->cr_msg, c->argv[i]);
3287 global_disallows |= disallows;
3292 config_requires(ConfigArgs *c) {
3293 slap_mask_t requires = frontendDB->be_requires;
3294 int i, argc = c->argc;
3295 char **argv = c->argv;
3297 slap_verbmasks requires_ops[] = {
3298 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
3299 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
3300 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
3301 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
3302 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
3305 if (c->op == SLAP_CONFIG_EMIT) {
3306 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
3307 } else if ( c->op == LDAP_MOD_DELETE ) {
3309 c->be->be_requires = 0;
3311 i = verb_to_mask( c->line, requires_ops );
3312 c->be->be_requires &= ~requires_ops[i].mask;
3316 /* "none" can only be first, to wipe out default/global values */
3317 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
3322 i = verbs_to_mask(argc, argv, requires_ops, &requires);
3324 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
3325 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
3326 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3327 c->log, c->cr_msg, 0);
3329 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
3330 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3331 c->log, c->cr_msg, c->argv[i]);
3335 c->be->be_requires = requires;
3340 config_extra_attrs(ConfigArgs *c)
3342 assert( c->be != NULL );
3344 if ( c->op == SLAP_CONFIG_EMIT ) {
3347 if ( c->be->be_extra_anlist == NULL ) {
3351 for ( i = 0; !BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ); i++ ) {
3352 value_add_one( &c->rvalue_vals, &c->be->be_extra_anlist[i].an_name );
3355 } else if ( c->op == LDAP_MOD_DELETE ) {
3356 if ( c->be->be_extra_anlist == NULL ) {
3360 if ( c->valx < 0 ) {
3361 anlist_free( c->be->be_extra_anlist, 1, NULL );
3362 c->be->be_extra_anlist = NULL;
3367 for ( i = 0; i < c->valx && !BER_BVISNULL( &c->be->be_extra_anlist[i + 1].an_name ); i++ )
3370 if ( BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ) ) {
3374 ch_free( c->be->be_extra_anlist[i].an_name.bv_val );
3376 for ( ; !BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ); i++ ) {
3377 c->be->be_extra_anlist[i] = c->be->be_extra_anlist[i + 1];
3382 c->be->be_extra_anlist = str2anlist( c->be->be_extra_anlist, c->argv[1], " ,\t" );
3383 if ( c->be->be_extra_anlist == NULL ) {
3391 static slap_verbmasks *loglevel_ops;
3394 loglevel_init( void )
3396 slap_verbmasks lo[] = {
3397 { BER_BVC("Any"), (slap_mask_t) LDAP_DEBUG_ANY },
3398 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
3399 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
3400 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
3401 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
3402 { BER_BVC("BER"), LDAP_DEBUG_BER },
3403 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
3404 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
3405 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
3406 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
3407 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
3408 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
3409 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
3410 #if 0 /* no longer used (nor supported) */
3411 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
3412 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
3414 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
3415 { BER_BVC("None"), LDAP_DEBUG_NONE },
3419 return slap_verbmasks_init( &loglevel_ops, lo );
3423 loglevel_destroy( void )
3425 if ( loglevel_ops ) {
3426 (void)slap_verbmasks_destroy( loglevel_ops );
3428 loglevel_ops = NULL;
3431 static slap_mask_t loglevel_ignore[] = { -1, 0 };
3434 slap_loglevel_register( slap_mask_t m, struct berval *s )
3438 if ( loglevel_ops == NULL ) {
3442 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
3445 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
3453 slap_loglevel_get( struct berval *s, int *l )
3458 if ( loglevel_ops == NULL ) {
3462 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3463 m |= loglevel_ops[ i ].mask;
3466 for ( i = 1; m & i; i <<= 1 )
3473 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
3476 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
3487 str2loglevel( const char *s, int *l )
3491 if ( loglevel_ops == NULL ) {
3495 i = verb_to_mask( s, loglevel_ops );
3497 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
3501 *l = loglevel_ops[ i ].mask;
3507 loglevel2str( int l )
3509 struct berval bv = BER_BVNULL;
3511 loglevel2bv( l, &bv );
3517 loglevel2bv( int l, struct berval *bv )
3519 if ( loglevel_ops == NULL ) {
3525 return enum_to_verb( loglevel_ops, l, bv ) == -1;
3529 loglevel2bvarray( int l, BerVarray *bva )
3531 if ( loglevel_ops == NULL ) {
3535 return mask_to_verbs( loglevel_ops, l, bva );
3539 loglevel_print( FILE *out )
3543 if ( loglevel_ops == NULL ) {
3547 fprintf( out, "Installed log subsystems:\n\n" );
3548 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3549 unsigned mask = loglevel_ops[ i ].mask & 0xffffffffUL;
3551 (mask == ((slap_mask_t) -1 & 0xffffffffUL)
3552 ? "\t%-30s (-1, 0xffffffff)\n" : "\t%-30s (%u, 0x%x)\n"),
3553 loglevel_ops[ i ].word.bv_val, mask, mask );
3556 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
3557 "by specific code\n\n" );
3562 static int config_syslog;
3565 config_loglevel(ConfigArgs *c) {
3568 if ( loglevel_ops == NULL ) {
3572 if (c->op == SLAP_CONFIG_EMIT) {
3573 /* Get default or commandline slapd setting */
3574 if ( ldap_syslog && !config_syslog )
3575 config_syslog = ldap_syslog;
3576 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
3578 } else if ( c->op == LDAP_MOD_DELETE ) {
3582 i = verb_to_mask( c->line, loglevel_ops );
3583 config_syslog &= ~loglevel_ops[i].mask;
3585 if ( slapMode & SLAP_SERVER_MODE ) {
3586 ldap_syslog = config_syslog;
3591 for( i=1; i < c->argc; i++ ) {
3594 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
3595 if( lutil_atoix( &level, c->argv[i], 0 ) != 0 ) {
3596 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse level", c->argv[0] );
3597 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3598 c->log, c->cr_msg, c->argv[i]);
3602 if ( str2loglevel( c->argv[i], &level ) ) {
3603 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown level", c->argv[0] );
3604 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3605 c->log, c->cr_msg, c->argv[i]);
3609 /* Explicitly setting a zero clears all the levels */
3611 config_syslog |= level;
3615 if ( slapMode & SLAP_SERVER_MODE ) {
3616 ldap_syslog = config_syslog;
3622 config_referral(ConfigArgs *c) {
3624 if (c->op == SLAP_CONFIG_EMIT) {
3625 if ( default_referral ) {
3626 value_add( &c->rvalue_vals, default_referral );
3631 } else if ( c->op == LDAP_MOD_DELETE ) {
3632 if ( c->valx < 0 ) {
3633 ber_bvarray_free( default_referral );
3634 default_referral = NULL;
3637 ch_free( default_referral[i].bv_val );
3638 for (; default_referral[i].bv_val; i++ )
3639 default_referral[i] = default_referral[i+1];
3643 if(validate_global_referral(c->argv[1])) {
3644 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3645 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3646 c->log, c->cr_msg, c->argv[1]);
3650 ber_str2bv(c->argv[1], 0, 0, &val);
3651 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
3659 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
3660 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
3661 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
3662 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
3663 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
3664 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
3665 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
3666 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
3667 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
3672 config_security(ConfigArgs *c) {
3673 slap_ssf_set_t *set = &c->be->be_ssf_set;
3676 if (c->op == SLAP_CONFIG_EMIT) {
3682 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
3683 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
3686 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
3687 if ( bv.bv_len >= sizeof( numbuf ) ) {
3688 ber_bvarray_free_x( c->rvalue_vals, NULL );
3689 c->rvalue_vals = NULL;
3693 bv.bv_len += sec_keys[i].key.bv_len;
3694 bv.bv_val = ch_malloc( bv.bv_len + 1);
3695 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
3696 strcpy( next, numbuf );
3697 ber_bvarray_add( &c->rvalue_vals, &bv );
3702 for(i = 1; i < c->argc; i++) {
3703 slap_ssf_t *tgt = NULL;
3705 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
3706 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
3707 sec_keys[j].key.bv_len)) {
3708 src = c->argv[i] + sec_keys[j].key.bv_len;
3709 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
3714 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown factor", c->argv[0] );
3715 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3716 c->log, c->cr_msg, c->argv[i]);
3720 if ( lutil_atou( tgt, src ) != 0 ) {
3721 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse factor", c->argv[0] );
3722 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3723 c->log, c->cr_msg, c->argv[i]);
3731 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
3735 for (; !BER_BVISNULL( &an->an_name ); an++) {
3736 /* if buflen == 0, assume the buffer size has been
3737 * already checked otherwise */
3738 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
3739 if ( comma ) *ptr++ = ',';
3740 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
3747 config_updatedn(ConfigArgs *c) {
3748 if (c->op == SLAP_CONFIG_EMIT) {
3749 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
3750 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
3751 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
3755 } else if ( c->op == LDAP_MOD_DELETE ) {
3756 ch_free( c->be->be_update_ndn.bv_val );
3757 BER_BVZERO( &c->be->be_update_ndn );
3758 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
3761 if(SLAP_SHADOW(c->be)) {
3762 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database already shadowed", c->argv[0] );
3763 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3764 c->log, c->cr_msg, 0);
3768 ber_memfree_x( c->value_dn.bv_val, NULL );
3769 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
3770 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
3772 c->be->be_update_ndn = c->value_ndn;
3773 BER_BVZERO( &c->value_dn );
3774 BER_BVZERO( &c->value_ndn );
3776 return config_slurp_shadow( c );
3780 config_shadow( ConfigArgs *c, slap_mask_t flag )
3782 char *notallowed = NULL;
3784 if ( c->be == frontendDB ) {
3785 notallowed = "frontend";
3787 } else if ( SLAP_MONITOR(c->be) ) {
3788 notallowed = "monitor";
3791 if ( notallowed != NULL ) {
3792 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
3796 if ( SLAP_SHADOW(c->be) ) {
3797 /* if already shadow, only check consistency */
3798 if ( ( SLAP_DBFLAGS(c->be) & flag ) != flag ) {
3799 Debug( LDAP_DEBUG_ANY, "%s: inconsistent shadow flag 0x%lx.\n",
3805 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | flag);
3806 if ( !SLAP_MULTIMASTER( c->be ))
3807 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
3814 config_updateref(ConfigArgs *c) {
3816 if (c->op == SLAP_CONFIG_EMIT) {
3817 if ( c->be->be_update_refs ) {
3818 value_add( &c->rvalue_vals, c->be->be_update_refs );
3823 } else if ( c->op == LDAP_MOD_DELETE ) {
3824 if ( c->valx < 0 ) {
3825 ber_bvarray_free( c->be->be_update_refs );
3826 c->be->be_update_refs = NULL;
3829 ch_free( c->be->be_update_refs[i].bv_val );
3830 for (; c->be->be_update_refs[i].bv_val; i++)
3831 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
3835 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
3836 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must appear after syncrepl or updatedn",
3838 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3839 c->log, c->cr_msg, 0);
3843 if(validate_global_referral(c->argv[1])) {
3844 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3845 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3846 c->log, c->cr_msg, c->argv[1]);
3849 ber_str2bv(c->argv[1], 0, 0, &val);
3850 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
3855 config_obsolete(ConfigArgs *c) {
3856 if (c->op == SLAP_CONFIG_EMIT)
3859 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> keyword is obsolete (ignored)",
3861 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0);
3866 config_include(ConfigArgs *c) {
3867 int savelineno = c->lineno;
3870 ConfigFile *cfsave = cfn;
3871 ConfigFile *cf2 = NULL;
3873 /* Leftover from RE23. No dynamic config for include files */
3874 if ( c->op == SLAP_CONFIG_EMIT || c->op == LDAP_MOD_DELETE )
3877 cf = ch_calloc( 1, sizeof(ConfigFile));
3878 if ( cfn->c_kids ) {
3879 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
3885 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
3886 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
3887 c->lineno = savelineno - 1;
3890 if ( cf2 ) cf2->c_sibs = NULL;
3891 else cfn->c_kids = NULL;
3892 ch_free( cf->c_file.bv_val );
3902 config_tls_cleanup(ConfigArgs *c) {
3905 if ( slap_tls_ld ) {
3908 ldap_pvt_tls_ctx_free( slap_tls_ctx );
3910 /* Force new ctx to be created */
3911 rc = ldap_pvt_tls_set_option( slap_tls_ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
3913 /* The ctx's refcount is bumped up here */
3914 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CTX, &slap_tls_ctx );
3915 /* This is a no-op if it's already loaded */
3916 load_extop( &slap_EXOP_START_TLS, 0, starttls_extop );
3923 config_tls_option(ConfigArgs *c) {
3925 LDAP *ld = slap_tls_ld;
3927 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
3928 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
3929 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
3930 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
3931 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
3932 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
3933 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
3935 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
3937 default: Debug(LDAP_DEBUG_ANY, "%s: "
3938 "unknown tls_option <0x%x>\n",
3939 c->log, c->type, 0);
3942 if (c->op == SLAP_CONFIG_EMIT) {
3943 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
3944 } else if ( c->op == LDAP_MOD_DELETE ) {
3945 c->cleanup = config_tls_cleanup;
3946 return ldap_pvt_tls_set_option( ld, flag, NULL );
3948 ch_free(c->value_string);
3949 c->cleanup = config_tls_cleanup;
3950 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
3953 /* FIXME: this ought to be provided by libldap */
3955 config_tls_config(ConfigArgs *c) {
3958 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
3959 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
3960 case CFG_TLS_PROTOCOL_MIN: flag = LDAP_OPT_X_TLS_PROTOCOL_MIN; break;
3962 Debug(LDAP_DEBUG_ANY, "%s: "
3963 "unknown tls_option <0x%x>\n",
3964 c->log, c->type, 0);
3967 if (c->op == SLAP_CONFIG_EMIT) {
3968 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
3969 } else if ( c->op == LDAP_MOD_DELETE ) {
3971 c->cleanup = config_tls_cleanup;
3972 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
3974 ch_free( c->value_string );
3975 c->cleanup = config_tls_cleanup;
3976 if ( isdigit( (unsigned char)c->argv[1][0] ) ) {
3977 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
3978 Debug(LDAP_DEBUG_ANY, "%s: "
3979 "unable to parse %s \"%s\"\n",
3980 c->log, c->argv[0], c->argv[1] );
3983 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
3985 return(ldap_pvt_tls_config(slap_tls_ld, flag, c->argv[1]));
3990 static CfEntryInfo *
3991 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
4001 if ( dn_match( &root->ce_entry->e_nname, dn ))
4004 c = dn->bv_val+dn->bv_len;
4005 for (;*c != ',';c--);
4009 for (--c;c>dn->bv_val && *c != ',';c--);
4013 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
4015 root = root->ce_kids;
4017 for (;root;root=root->ce_sibs) {
4018 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
4019 if ( cdn.bv_val == dn->bv_val ) {
4029 typedef struct setup_cookie {
4039 config_ldif_resp( Operation *op, SlapReply *rs )
4041 if ( rs->sr_type == REP_SEARCH ) {
4042 setup_cookie *sc = op->o_callback->sc_private;
4045 sc->cfb->cb_got_ldif = 1;
4046 /* Does the frontend exist? */
4047 if ( !sc->got_frontend ) {
4048 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
4049 "olcDatabase", STRLENOF( "olcDatabase" )))
4051 if ( strncmp( rs->sr_entry->e_nname.bv_val +
4052 STRLENOF( "olcDatabase" ), "={-1}frontend",
4053 STRLENOF( "={-1}frontend" )))
4057 sc->ca->be = frontendDB;
4058 sc->ca->bi = frontendDB->bd_info;
4059 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
4060 rdn.bv_val = sc->ca->log;
4061 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
4062 "%s=" SLAP_X_ORDERED_FMT "%s",
4063 cfAd_database->ad_cname.bv_val, -1,
4064 sc->ca->bi->bi_type);
4066 sc->frontend = config_build_entry( op, rs,
4067 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
4068 sc->ca->be->be_cf_ocs );
4078 dnParent( &rs->sr_entry->e_nname, &pdn );
4080 /* Does the configDB exist? */
4081 if ( sc->got_frontend && !sc->got_config &&
4082 !strncmp( rs->sr_entry->e_nname.bv_val,
4083 "olcDatabase", STRLENOF( "olcDatabase" )) &&
4084 dn_match( &config_rdn, &pdn ) )
4086 if ( strncmp( rs->sr_entry->e_nname.bv_val +
4087 STRLENOF( "olcDatabase" ), "={0}config",
4088 STRLENOF( "={0}config" )))
4092 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
4093 sc->ca->bi = sc->ca->be->bd_info;
4094 rdn.bv_val = sc->ca->log;
4095 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
4096 "%s=" SLAP_X_ORDERED_FMT "%s",
4097 cfAd_database->ad_cname.bv_val, 0,
4098 sc->ca->bi->bi_type);
4100 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
4101 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
4108 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
4109 if ( rs->sr_err != LDAP_SUCCESS ) {
4110 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
4111 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg, 0 );
4117 /* Configure and read the underlying back-ldif store */
4119 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
4120 CfBackInfo *cfb = be->be_private;
4126 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
4127 Connection conn = {0};
4128 OperationBuffer opbuf;
4130 SlapReply rs = {REP_RESULT};
4131 Filter filter = { LDAP_FILTER_PRESENT };
4132 struct berval filterstr = BER_BVC("(objectclass=*)");
4135 /* Is the config directory available? */
4136 if ( stat( dir, &st ) < 0 ) {
4137 /* No, so don't bother using the backing store.
4138 * All changes will be in-memory only.
4143 cfb->cb_db.bd_info = backend_info( "ldif" );
4144 if ( !cfb->cb_db.bd_info )
4145 return 0; /* FIXME: eventually this will be a fatal error */
4147 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
4150 cfb->cb_db.be_suffix = be->be_suffix;
4151 cfb->cb_db.be_nsuffix = be->be_nsuffix;
4153 /* The suffix is always "cn=config". The underlying DB's rootdn
4154 * is always the same as the suffix.
4156 cfb->cb_db.be_rootdn = be->be_suffix[0];
4157 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
4159 ber_str2bv( dir, 0, 1, &cfdir );
4164 argv[0] = "directory";
4165 argv[1] = (char *)dir;
4170 c.table = Cft_Database;
4172 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
4176 if ( config_add_vals( ct, &c ))
4179 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
4183 void *thrctx = ldap_pvt_thread_pool_context();
4186 connection_fake_init( &conn, &opbuf, thrctx );
4189 filter.f_desc = slap_schema.si_ad_objectClass;
4191 op->o_tag = LDAP_REQ_SEARCH;
4193 op->ors_filter = &filter;
4194 op->ors_filterstr = filterstr;
4195 op->ors_scope = LDAP_SCOPE_SUBTREE;
4197 op->o_dn = c.be->be_rootdn;
4198 op->o_ndn = c.be->be_rootndn;
4200 op->o_req_dn = be->be_suffix[0];
4201 op->o_req_ndn = be->be_nsuffix[0];
4203 op->ors_tlimit = SLAP_NO_LIMIT;
4204 op->ors_slimit = SLAP_NO_LIMIT;
4206 op->ors_attrs = slap_anlist_all_attributes;
4207 op->ors_attrsonly = 0;
4209 op->o_callback = &cb;
4212 cb.sc_private = ≻
4213 sc.got_frontend = 0;
4218 op->o_bd = &cfb->cb_db;
4220 /* Allow unknown attrs in DNs */
4221 prev_DN_strict = slap_DN_strict;
4224 rc = op->o_bd->be_search( op, &rs );
4226 /* Restore normal DN validation */
4227 slap_DN_strict = prev_DN_strict;
4229 op->o_tag = LDAP_REQ_ADD;
4230 if ( rc == LDAP_SUCCESS && sc.frontend ) {
4231 rs_reinit( &rs, REP_RESULT );
4232 op->ora_e = sc.frontend;
4233 rc = op->o_bd->be_add( op, &rs );
4235 if ( rc == LDAP_SUCCESS && sc.config ) {
4236 rs_reinit( &rs, REP_RESULT );
4237 op->ora_e = sc.config;
4238 rc = op->o_bd->be_add( op, &rs );
4240 ldap_pvt_thread_pool_context_reset( thrctx );
4243 /* ITS#4194 - only use if it's present, or we're converting. */
4244 if ( !readit || rc == LDAP_SUCCESS )
4245 cfb->cb_use_ldif = 1;
4251 CfOc_cmp( const void *c1, const void *c2 ) {
4252 const ConfigOCs *co1 = c1;
4253 const ConfigOCs *co2 = c2;
4255 return ber_bvcmp( co1->co_name, co2->co_name );
4259 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
4262 i = init_config_attrs( ct );
4265 /* set up the objectclasses */
4266 i = init_config_ocs( ocs );
4269 for (i=0; ocs[i].co_def; i++) {
4270 if ( ocs[i].co_oc ) {
4271 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
4272 if ( !ocs[i].co_table )
4273 ocs[i].co_table = ct;
4274 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
4281 read_config(const char *fname, const char *dir) {
4284 const char *cfdir, *cfname;
4287 /* Setup the config backend */
4288 be = backend_db_init( "config", NULL, 0, NULL );
4292 cfb = be->be_private;
4293 be->be_dfltaccess = ACL_NONE;
4295 /* If no .conf, or a dir was specified, setup the dir */
4296 if ( !fname || dir ) {
4298 /* If explicitly given, check for existence */
4301 if ( stat( dir, &st ) < 0 ) {
4302 Debug( LDAP_DEBUG_ANY,
4303 "invalid config directory %s, error %d\n",
4309 cfdir = SLAPD_DEFAULT_CONFIGDIR;
4311 /* if fname is defaulted, try reading .d */
4312 rc = config_setup_ldif( be, cfdir, !fname );
4315 /* It may be OK if the base object doesn't exist yet. */
4316 if ( rc != LDAP_NO_SUCH_OBJECT )
4318 /* ITS#4194: But if dir was specified and no fname,
4319 * then we were supposed to read the dir. Unless we're
4320 * trying to slapadd the dir...
4322 if ( dir && !fname ) {
4323 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
4325 /* Assume it's slapadd with a config dir, let it continue */
4327 cfb->cb_got_ldif = 1;
4328 cfb->cb_use_ldif = 1;
4333 /* If we read the config from back-ldif, nothing to do here */
4334 if ( cfb->cb_got_ldif ) {
4343 cfname = SLAPD_DEFAULT_CONFIGFILE;
4345 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
4348 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
4351 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
4352 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
4353 &frontendDB->be_schemadn );
4354 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
4355 if ( rc != LDAP_SUCCESS ) {
4356 Debug(LDAP_DEBUG_ANY, "read_config: "
4357 "unable to normalize default schema DN \"%s\"\n",
4358 frontendDB->be_schemadn.bv_val, 0, 0 );
4359 /* must not happen */
4367 config_back_bind( Operation *op, SlapReply *rs )
4369 if ( be_isroot_pw( op ) ) {
4370 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
4371 /* frontend sends result */
4372 return LDAP_SUCCESS;
4375 rs->sr_err = LDAP_INVALID_CREDENTIALS;
4376 send_ldap_result( op, rs );
4382 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
4386 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
4388 rs->sr_attrs = op->ors_attrs;
4389 rs->sr_entry = ce->ce_entry;
4391 rc = send_search_entry( op, rs );
4392 if ( rc != LDAP_SUCCESS ) {
4396 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
4397 if ( ce->ce_kids ) {
4398 rc = config_send( op, rs, ce->ce_kids, 1 );
4399 if ( rc ) return rc;
4402 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
4403 rc = config_send( op, rs, ce, 0 );
4411 static ConfigTable *
4412 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
4417 for (j=0; j<nocs; j++) {
4418 for (i=0; colst[j]->co_table[i].name; i++)
4419 if ( colst[j]->co_table[i].ad == ad ) {
4420 ca->table = colst[j]->co_type;
4421 return &colst[j]->co_table[i];
4427 /* Sort the attributes of the entry according to the order defined
4428 * in the objectclass, with required attributes occurring before
4429 * allowed attributes. For any attributes with sequencing dependencies
4430 * (e.g., rootDN must be defined after suffix) the objectclass must
4431 * list the attributes in the desired sequence.
4434 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
4436 Attribute *a, *head = NULL, *tail = NULL, **prev;
4439 for (i=0; i<nocs; i++) {
4440 if ( colst[i]->co_oc->soc_required ) {
4441 AttributeType **at = colst[i]->co_oc->soc_required;
4442 for (j=0; at[j]; j++) {
4443 for (a=e->e_attrs, prev=&e->e_attrs; a;
4444 prev = &(*prev)->a_next, a=a->a_next) {
4445 if ( a->a_desc == at[j]->sat_ad ) {
4459 if ( colst[i]->co_oc->soc_allowed ) {
4460 AttributeType **at = colst[i]->co_oc->soc_allowed;
4461 for (j=0; at[j]; j++) {
4462 for (a=e->e_attrs, prev=&e->e_attrs; a;
4463 prev = &(*prev)->a_next, a=a->a_next) {
4464 if ( a->a_desc == at[j]->sat_ad ) {
4480 tail->a_next = e->e_attrs;
4486 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
4488 Attribute *a = NULL;
4489 AttributeDescription *ad;
4499 Modifications *ml = ptr;
4501 vals = ml->sml_values;
4504 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
4505 rc = ordered_value_sort( a, 1 );
4507 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
4508 ad->ad_cname.bv_val );
4512 for ( i=0; vals[i].bv_val; i++ ) {
4513 ca->line = vals[i].bv_val;
4514 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
4515 ca->line[0] == '{' ) {
4516 char *idx = strchr( ca->line, '}' );
4517 if ( idx ) ca->line = idx+1;
4519 rc = config_parse_vals( ct, ca, i );
4528 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
4531 struct berval rtype, rval;
4533 AttributeDescription *ad = NULL;
4535 dnRdn( &e->e_name, rdn );
4536 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
4537 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
4538 rtype.bv_val = rdn->bv_val;
4539 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
4542 slap_bv2ad( &rtype, &ad, &rs->sr_text );
4543 a = attr_find( e->e_attrs, ad );
4544 if (!a ) return LDAP_NAMING_VIOLATION;
4551 config_rename_kids( CfEntryInfo *ce )
4554 struct berval rdn, nrdn;
4556 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
4557 struct berval newdn, newndn;
4558 dnRdn ( &ce2->ce_entry->e_name, &rdn );
4559 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
4560 build_new_dn( &newdn, &ce->ce_entry->e_name, &rdn, NULL );
4561 build_new_dn( &newndn, &ce->ce_entry->e_nname, &nrdn, NULL );
4562 free( ce2->ce_entry->e_name.bv_val );
4563 free( ce2->ce_entry->e_nname.bv_val );
4564 ce2->ce_entry->e_name = newdn;
4565 ce2->ce_entry->e_nname = newndn;
4566 config_rename_kids( ce2 );
4571 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
4572 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
4573 struct berval *nnewrdn, int use_ldif )
4577 struct berval odn, ondn;
4581 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
4582 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
4585 free( a->a_vals[0].bv_val );
4586 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
4587 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
4588 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
4589 strcpy( a->a_vals[0].bv_val, ptr1 );
4591 if ( a->a_nvals != a->a_vals ) {
4592 free( a->a_nvals[0].bv_val );
4593 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
4594 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
4595 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
4596 strcpy( a->a_nvals[0].bv_val, ptr1 );
4599 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
4600 BackendDB *be = op->o_bd;
4601 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4602 struct berval dn, ndn, xdn, xndn;
4604 op->o_bd = &cfb->cb_db;
4606 /* Save current rootdn; use the underlying DB's rootdn */
4610 xndn = op->o_req_ndn;
4611 op->o_dn = op->o_bd->be_rootdn;
4612 op->o_ndn = op->o_bd->be_rootndn;
4614 op->o_req_ndn = ondn;
4616 scp = op->o_callback;
4617 op->o_callback = ≻
4618 op->orr_newrdn = *newrdn;
4619 op->orr_nnewrdn = *nnewrdn;
4620 op->orr_newSup = NULL;
4621 op->orr_nnewSup = NULL;
4622 op->orr_deleteoldrdn = 1;
4623 op->orr_modlist = NULL;
4624 slap_modrdn2mods( op, rs );
4625 slap_mods_opattrs( op, &op->orr_modlist, 1 );
4626 rc = op->o_bd->be_modrdn( op, rs );
4627 slap_mods_free( op->orr_modlist, 1 );
4630 op->o_callback = scp;
4634 op->o_req_ndn = xndn;
4637 free( ondn.bv_val );
4639 config_rename_kids( e->e_private );
4644 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
4645 Entry *e, int idx, int tailindex, int use_ldif )
4647 struct berval ival, newrdn, nnewrdn;
4650 char ibuf[32], *ptr1, *ptr2 = NULL;
4653 rc = config_rename_attr( rs, e, &rdn, &a );
4654 if ( rc ) return rc;
4657 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
4658 if ( ival.bv_len >= sizeof( ibuf ) ) {
4659 return LDAP_NAMING_VIOLATION;
4662 newrdn.bv_len = rdn.bv_len + ival.bv_len;
4663 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
4666 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
4667 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4670 ptr2 = ber_bvchr( &rdn, '}' );
4674 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
4676 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
4677 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
4678 a->a_desc->ad_cname.bv_len );
4680 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4681 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
4685 /* Do the equivalent of ModRDN */
4686 /* Replace DN / NDN */
4687 newrdn.bv_len = ptr1 - newrdn.bv_val;
4688 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
4689 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
4691 free( nnewrdn.bv_val );
4692 free( newrdn.bv_val );
4697 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
4698 SlapReply *rs, int *renum, int *ibase )
4701 int index = -1, gotindex = 0, nsibs, rc = 0;
4702 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
4703 char *ptr1, *ptr2 = NULL;
4706 if ( renum ) *renum = 0;
4708 /* These entries don't get indexed/renumbered */
4709 if ( ce_type == Cft_Global ) return 0;
4710 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
4712 if ( ce_type == Cft_Module )
4715 /* See if the rdn has an index already */
4716 dnRdn( &e->e_name, &rdn );
4717 if ( ce_type == Cft_Database ) {
4718 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
4719 "frontend", STRLENOF("frontend") ))
4721 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
4722 "config", STRLENOF("config") ))
4725 ptr1 = ber_bvchr( &e->e_name, '{' );
4726 if ( ptr1 && ptr1 < &e->e_name.bv_val[ rdn.bv_len ] ) {
4728 ptr2 = strchr( ptr1, '}' );
4729 if ( !ptr2 || ptr2 > &e->e_name.bv_val[ rdn.bv_len ] )
4730 return LDAP_NAMING_VIOLATION;
4731 if ( ptr2-ptr1 == 1)
4732 return LDAP_NAMING_VIOLATION;
4734 index = strtol( ptr1 + 1, &next, 10 );
4735 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
4736 return LDAP_NAMING_VIOLATION;
4739 /* Special case, we allow -1 for the frontendDB */
4740 if ( index != -1 || !isfrontend )
4741 return LDAP_NAMING_VIOLATION;
4743 if ( isconfig && index != 0 ){
4744 return LDAP_NAMING_VIOLATION;
4748 /* count related kids */
4749 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
4750 if ( ce->ce_type == ce_type ) nsibs++;
4753 /* account for -1 frontend */
4754 if ( ce_type == Cft_Database )
4757 if ( index != nsibs ) {
4759 if ( index < nsibs ) {
4760 if ( tailindex ) return LDAP_NAMING_VIOLATION;
4761 /* Siblings need to be renumbered */
4762 if ( index != -1 || !isfrontend )
4766 /* config DB is always "0" */
4767 if ( isconfig && index == -1 ) {
4770 if (( !isfrontend && index == -1 ) || ( index > nsibs ) ){
4774 /* just make index = nsibs */
4776 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
4779 if ( ibase ) *ibase = index;
4780 if ( renum ) *renum = renumber;
4784 /* Insert all superior classes of the given class */
4786 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
4791 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
4792 if ( count_oc( *sups, copp, nocs ) ) {
4797 co.co_name = &oc->soc_cname;
4798 cop = avl_find( CfOcTree, &co, CfOc_cmp );
4802 /* check for duplicates */
4803 for ( i = 0; i < *nocs; i++ ) {
4804 if ( *copp && (*copp)[i] == cop ) {
4810 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
4811 if ( tmp == NULL ) {
4815 (*copp)[*nocs] = cop;
4823 /* Find all superior classes of the given objectclasses,
4824 * return list in order of most-subordinate first.
4826 * Special / auxiliary / Cft_Misc classes always take precedence.
4829 count_ocs( Attribute *oc_at, int *nocs )
4831 int i, j, misc = -1;
4832 ConfigOCs **colst = NULL;
4836 for ( i = oc_at->a_numvals; i--; ) {
4837 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
4839 assert( oc != NULL );
4840 if ( count_oc( oc, &colst, nocs ) ) {
4850 ConfigOCs *tmp = colst[i];
4851 colst[i] = colst[j];
4853 if (tmp->co_type == Cft_Misc)
4857 /* Move misc class to front of list */
4859 ConfigOCs *tmp = colst[misc];
4860 for (i=misc; i>0; i--)
4861 colst[i] = colst[i-1];
4869 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4871 /* Leftover from RE23. Never parse this entry */
4872 return LDAP_COMPARE_TRUE;
4876 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4880 /* This entry is hardcoded, don't re-parse it */
4881 if ( p->ce_type == Cft_Global ) {
4882 cfn = p->ce_private;
4883 ca->ca_private = cfn;
4884 return LDAP_COMPARE_TRUE;
4886 if ( p->ce_type != Cft_Schema )
4887 return LDAP_CONSTRAINT_VIOLATION;
4889 cfn = ch_calloc( 1, sizeof(ConfigFile) );
4890 ca->ca_private = cfn;
4891 cfo = p->ce_private;
4892 cfn->c_sibs = cfo->c_kids;
4894 return LDAP_SUCCESS;
4898 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4900 if ( p->ce_type != Cft_Global ) {
4901 return LDAP_CONSTRAINT_VIOLATION;
4903 /* config must be {0}, nothing else allowed */
4904 if ( !strncmp( e->e_nname.bv_val, "olcDatabase={0}", STRLENOF("olcDatabase={0}")) &&
4905 strncmp( e->e_nname.bv_val + STRLENOF("olcDatabase={0}"), "config,", STRLENOF("config,") )) {
4906 return LDAP_CONSTRAINT_VIOLATION;
4908 ca->be = frontendDB; /* just to get past check_vals */
4909 return LDAP_SUCCESS;
4913 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4915 if ( p->ce_type != Cft_Global ) {
4916 return LDAP_CONSTRAINT_VIOLATION;
4918 return LDAP_SUCCESS;
4922 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4924 if ( p->ce_type != Cft_Global ) {
4925 return LDAP_CONSTRAINT_VIOLATION;
4927 return LDAP_SUCCESS;
4931 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4933 if ( p->ce_type != Cft_Database ) {
4934 return LDAP_CONSTRAINT_VIOLATION;
4937 return LDAP_SUCCESS;
4941 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
4946 AttributeDescription *ad;
4952 if ( cfn->c_cr_head ) {
4953 struct berval bv = BER_BVC("olcDitContentRules");
4955 slap_bv2ad( &bv, &ad, &text );
4956 ct = config_find_table( colst, nocs, ad, ca );
4957 config_del_vals( ct, ca );
4959 if ( cfn->c_oc_head ) {
4960 struct berval bv = BER_BVC("olcObjectClasses");
4962 slap_bv2ad( &bv, &ad, &text );
4963 ct = config_find_table( colst, nocs, ad, ca );
4964 config_del_vals( ct, ca );
4966 if ( cfn->c_at_head ) {
4967 struct berval bv = BER_BVC("olcAttributeTypes");
4969 slap_bv2ad( &bv, &ad, &text );
4970 ct = config_find_table( colst, nocs, ad, ca );
4971 config_del_vals( ct, ca );
4973 if ( cfn->c_syn_head ) {
4974 struct berval bv = BER_BVC("olcLdapSyntaxes");
4976 slap_bv2ad( &bv, &ad, &text );
4977 ct = config_find_table( colst, nocs, ad, ca );
4978 config_del_vals( ct, ca );
4980 if ( cfn->c_om_head ) {
4981 struct berval bv = BER_BVC("olcObjectIdentifier");
4983 slap_bv2ad( &bv, &ad, &text );
4984 ct = config_find_table( colst, nocs, ad, ca );
4985 config_del_vals( ct, ca );
4987 cfo = p->ce_private;
4988 cfo->c_kids = cfn->c_sibs;
4993 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
4995 int rc = LDAP_CONSTRAINT_VIOLATION;
4998 if ( (*cop)->co_ldadd ) {
4999 rc = (*cop)->co_ldadd( last, e, ca );
5000 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
5005 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
5006 ConfigOCs co = { 0 };
5008 co.co_name = &(*ocp)->soc_cname;
5009 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
5010 if ( *cop == NULL ) {
5014 rc = config_add_oc( cop, last, e, ca );
5015 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
5023 /* Parse an LDAP entry into config directives */
5025 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
5026 int *renum, Operation *op )
5028 CfEntryInfo *ce, *last = NULL;
5029 ConfigOCs co, *coptr, **colst;
5030 Attribute *a, *oc_at, *soc_at;
5031 int i, ibase = -1, nocs, rc = 0;
5034 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
5036 memset( ca, 0, sizeof(ConfigArgs));
5038 /* Make sure parent exists and entry does not. But allow
5039 * Databases and Overlays to be inserted. Don't do any
5040 * auto-renumbering if manageDSAit control is present.
5042 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
5044 if ( ( op && op->o_managedsait ) ||
5045 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
5046 ce->ce_type != Cft_Module ) )
5048 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5049 "DN=\"%s\" already exists\n",
5050 log_prefix, e->e_name.bv_val, 0 );
5051 /* global schema ignores all writes */
5052 if ( ce->ce_type == Cft_Schema && ce->ce_parent->ce_type == Cft_Global )
5053 return LDAP_COMPARE_TRUE;
5054 return LDAP_ALREADY_EXISTS;
5058 dnParent( &e->e_nname, &pdn );
5060 /* If last is NULL, the new entry is the root/suffix entry,
5061 * otherwise last should be the parent.
5063 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
5065 rs->sr_matched = last->ce_entry->e_name.bv_val;
5067 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5068 "DN=\"%s\" not child of DN=\"%s\"\n",
5069 log_prefix, e->e_name.bv_val,
5070 last->ce_entry->e_name.bv_val );
5071 return LDAP_NO_SUCH_OBJECT;
5075 /* No parent, must be root. This will never happen... */
5076 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
5077 return LDAP_NO_SUCH_OBJECT;
5080 if ( last && !access_allowed( op, last->ce_entry,
5081 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
5083 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5084 "DN=\"%s\" no write access to \"children\" of parent\n",
5085 log_prefix, e->e_name.bv_val, 0 );
5086 return LDAP_INSUFFICIENT_ACCESS;
5090 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5092 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5093 "DN=\"%s\" no objectClass\n",
5094 log_prefix, e->e_name.bv_val, 0 );
5095 return LDAP_OBJECT_CLASS_VIOLATION;
5098 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
5100 ObjectClass *soc = NULL;
5101 char textbuf[ SLAP_TEXT_BUFLEN ];
5102 const char *text = textbuf;
5104 /* FIXME: check result */
5105 rc = structural_class( oc_at->a_nvals, &soc, NULL,
5106 &text, textbuf, sizeof(textbuf), NULL );
5107 if ( rc != LDAP_SUCCESS ) {
5108 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5109 "DN=\"%s\" no structural objectClass (%s)\n",
5110 log_prefix, e->e_name.bv_val, text );
5113 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
5114 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
5115 if ( soc_at == NULL ) {
5116 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5117 "DN=\"%s\" no structural objectClass; "
5118 "unable to merge computed class %s\n",
5119 log_prefix, e->e_name.bv_val,
5120 soc->soc_cname.bv_val );
5121 return LDAP_OBJECT_CLASS_VIOLATION;
5124 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5125 "DN=\"%s\" no structural objectClass; "
5126 "computed objectClass %s merged\n",
5127 log_prefix, e->e_name.bv_val,
5128 soc->soc_cname.bv_val );
5131 /* Fake the coordinates based on whether we're part of an
5132 * LDAP Add or if reading the config dir
5135 ca->fname = "slapd";
5138 ca->fname = cfdir.bv_val;
5143 co.co_name = &soc_at->a_nvals[0];
5144 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
5145 if ( coptr == NULL ) {
5146 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5147 "DN=\"%s\" no structural objectClass in configuration table\n",
5148 log_prefix, e->e_name.bv_val, 0 );
5149 return LDAP_OBJECT_CLASS_VIOLATION;
5152 /* Only the root can be Cft_Global, everything else must
5153 * have a parent. Only limited nesting arrangements are allowed.
5155 rc = LDAP_CONSTRAINT_VIOLATION;
5156 if ( coptr->co_type == Cft_Global && !last ) {
5157 cfn = cfb->cb_config;
5158 ca->ca_private = cfn;
5159 ca->be = frontendDB; /* just to get past check_vals */
5163 colst = count_ocs( oc_at, &nocs );
5165 /* Check whether the Add is allowed by its parent, and do
5166 * any necessary arg setup
5169 rc = config_add_oc( &coptr, last, e, ca );
5170 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
5171 for ( i = 0; i<nocs; i++ ) {
5172 /* Already checked these */
5173 if ( colst[i]->co_oc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
5175 if ( colst[i]->co_ldadd &&
5176 ( rc = colst[i]->co_ldadd( last, e, ca ))
5177 != LDAP_CONSTRAINT_VIOLATION ) {
5183 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
5184 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5185 "DN=\"%s\" no structural objectClass add function\n",
5186 log_prefix, e->e_name.bv_val, 0 );
5187 return LDAP_OBJECT_CLASS_VIOLATION;
5191 /* Add the entry but don't parse it, we already have its contents */
5192 if ( rc == LDAP_COMPARE_TRUE ) {
5197 if ( rc != LDAP_SUCCESS )
5200 /* Parse all the values and check for simple syntax errors before
5201 * performing any set actions.
5203 * If doing an LDAPadd, check for indexed names and any necessary
5204 * renaming/renumbering. Entries that don't need indexed names are
5205 * ignored. Entries that need an indexed name and arrive without one
5206 * are assigned to the end. Entries that arrive with an index may
5207 * cause the following entries to be renumbered/bumped down.
5209 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
5210 * don't allow Adding an entry with an index that's already in use.
5211 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
5213 * These entries can have auto-assigned indexes (appended to the end)
5214 * but only the other types support auto-renumbering of siblings.
5217 rc = check_name_index( last, coptr->co_type, e, rs, renum,
5222 if ( renum && *renum && coptr->co_type != Cft_Database &&
5223 coptr->co_type != Cft_Overlay )
5225 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
5226 "operation requires sibling renumbering" );
5227 rc = LDAP_UNWILLING_TO_PERFORM;
5232 init_config_argv( ca );
5234 /* Make sure we process attrs in the required order */
5235 sort_attrs( e, colst, nocs );
5237 for ( a = e->e_attrs; a; a = a->a_next ) {
5238 if ( a == oc_at ) continue;
5239 ct = config_find_table( colst, nocs, a->a_desc, ca );
5240 if ( !ct ) continue; /* user data? */
5241 rc = check_vals( ct, ca, a, 1 );
5242 if ( rc ) goto done_noop;
5245 /* Basic syntax checks are OK. Do the actual settings. */
5246 for ( a=e->e_attrs; a; a=a->a_next ) {
5247 if ( a == oc_at ) continue;
5248 ct = config_find_table( colst, nocs, a->a_desc, ca );
5249 if ( !ct ) continue; /* user data? */
5250 for (i=0; a->a_vals[i].bv_val; i++) {
5253 ca->line = a->a_vals[i].bv_val;
5254 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
5255 ptr = strchr( ca->line, '}' );
5257 iptr = strchr( ca->line, '{' );
5261 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
5263 ca->valx = strtol( iptr+1, NULL, 0 );
5268 rc = config_parse_add( ct, ca, i );
5276 /* Newly added databases and overlays need to be started up */
5277 if ( CONFIG_ONLINE_ADD( ca )) {
5278 if ( coptr->co_type == Cft_Database ) {
5279 rc = backend_startup_one( ca->be, &ca->reply );
5281 } else if ( coptr->co_type == Cft_Overlay ) {
5282 if ( ca->bi->bi_db_open ) {
5283 BackendInfo *bi_orig = ca->be->bd_info;
5284 ca->be->bd_info = ca->bi;
5285 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
5286 ca->be->bd_info = bi_orig;
5288 } else if ( ca->cleanup ) {
5289 rc = ca->cleanup( ca );
5292 if (ca->cr_msg[0] == '\0')
5293 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
5295 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
5296 ca->log, ca->cr_msg, ca->argv[1] );
5303 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5304 ce->ce_parent = last;
5305 ce->ce_entry = entry_dup( e );
5306 ce->ce_entry->e_private = ce;
5307 ce->ce_type = coptr->co_type;
5310 ce->ce_private = ca->ca_private;
5311 ca->ca_entry = ce->ce_entry;
5314 } else if ( last->ce_kids ) {
5315 CfEntryInfo *c2, **cprev;
5317 /* Advance to first of this type */
5318 cprev = &last->ce_kids;
5319 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
5320 cprev = &c2->ce_sibs;
5323 /* Account for the (-1) frontendDB entry */
5324 if ( ce->ce_type == Cft_Database ) {
5325 if ( ca->be == frontendDB )
5327 else if ( ibase != -1 )
5332 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
5333 cprev = &c2->ce_sibs;
5339 for ( i=0; i<ibase; i++ ) {
5341 cprev = &c2->ce_sibs;
5344 ce->ce_sibs = *cprev;
5352 if ( (coptr->co_type == Cft_Database) && ca->be ) {
5353 if ( ca->be != frontendDB )
5354 backend_destroy_one( ca->be, 1 );
5355 } else if ( (coptr->co_type == Cft_Overlay) && ca->bi ) {
5356 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
5357 } else if ( coptr->co_type == Cft_Schema ) {
5358 schema_destroy_one( ca, colst, nocs, last );
5363 ch_free( ca->argv );
5364 if ( colst ) ch_free( colst );
5368 #define BIGTMP 10000
5370 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5371 int base, int rebase, int max, int use_ldif )
5373 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
5374 ConfigType etype = ce->ce_type;
5375 int count = 0, rc = 0;
5377 /* Reverse ce list */
5378 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
5379 if (ce2->ce_type != etype) {
5384 ce2->ce_sibs = cetmp;
5387 if ( max && count >= max ) {
5393 /* Move original to a temp name until increments are done */
5395 ce->ce_entry->e_private = NULL;
5396 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5397 base+BIGTMP, 0, use_ldif );
5398 ce->ce_entry->e_private = ce;
5400 /* start incrementing */
5401 for (ce2=cetmp; ce2; ce2=ce3) {
5403 ce2->ce_sibs = cerem;
5406 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5407 count+base, 0, use_ldif );
5411 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5412 base, 0, use_ldif );
5417 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5418 CfEntryInfo *ce2, int old, int use_ldif )
5422 /* Renumber original to a temp value */
5423 ce->ce_entry->e_private = NULL;
5424 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5425 old+BIGTMP, 0, use_ldif );
5426 ce->ce_entry->e_private = ce;
5428 /* start decrementing */
5429 for (; ce2 != ce; ce2=ce2->ce_sibs) {
5430 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5431 count+old, 0, use_ldif );
5434 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5435 count+old, 0, use_ldif );
5438 /* Parse an LDAP entry into config directives, then store in underlying
5442 config_back_add( Operation *op, SlapReply *rs )
5448 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
5449 NULL, ACL_WADD, NULL )) {
5450 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5455 * Check for attribute ACL
5457 if ( !acl_check_modlist( op, op->ora_e, op->orm_modlist )) {
5458 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5459 rs->sr_text = "no write access to attribute";
5463 cfb = (CfBackInfo *)op->o_bd->be_private;
5465 /* add opattrs for syncprov */
5467 char textbuf[SLAP_TEXT_BUFLEN];
5468 size_t textlen = sizeof textbuf;
5469 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1, NULL,
5470 &rs->sr_text, textbuf, sizeof( textbuf ) );
5471 if ( rs->sr_err != LDAP_SUCCESS )
5473 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
5474 if ( rs->sr_err != LDAP_SUCCESS ) {
5475 Debug( LDAP_DEBUG_TRACE,
5476 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
5477 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
5482 if ( op->o_abandon ) {
5483 rs->sr_err = SLAPD_ABANDON;
5486 ldap_pvt_thread_pool_pause( &connection_pool );
5489 * 1) check for existence of entry
5490 * 2) check for sibling renumbering
5491 * 3) perform internal add
5492 * 4) perform any necessary renumbering
5493 * 5) store entry in underlying database
5495 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
5496 if ( rs->sr_err != LDAP_SUCCESS ) {
5497 rs->sr_text = ca.cr_msg;
5502 CfEntryInfo *ce = ca.ca_entry->e_private;
5503 req_add_s addr = op->oq_add;
5504 op->o_tag = LDAP_REQ_MODRDN;
5505 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
5506 op->o_tag = LDAP_REQ_ADD;
5508 if ( rs->sr_err != LDAP_SUCCESS ) {
5513 if ( cfb->cb_use_ldif ) {
5514 BackendDB *be = op->o_bd;
5515 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5516 struct berval dn, ndn;
5518 op->o_bd = &cfb->cb_db;
5520 /* Save current rootdn; use the underlying DB's rootdn */
5523 op->o_dn = op->o_bd->be_rootdn;
5524 op->o_ndn = op->o_bd->be_rootndn;
5526 scp = op->o_callback;
5527 op->o_callback = ≻
5528 op->o_bd->be_add( op, rs );
5530 op->o_callback = scp;
5536 ldap_pvt_thread_pool_resume( &connection_pool );
5539 { int repl = op->o_dont_replicate;
5540 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
5541 rs->sr_text = NULL; /* Set after config_add_internal */
5542 rs->sr_err = LDAP_SUCCESS;
5543 op->o_dont_replicate = 1;
5545 send_ldap_result( op, rs );
5546 op->o_dont_replicate = repl;
5548 slap_graduate_commit_csn( op );
5552 typedef struct delrec {
5553 struct delrec *next;
5559 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
5565 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
5566 ca->line[0] == '{' )
5568 char *ptr = strchr( ca->line + 1, '}' );
5572 ca->valx = strtol( ca->line + 1, &next, 0 );
5573 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
5579 rc = config_parse_add( ct, ca, i );
5587 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
5590 int rc = LDAP_UNWILLING_TO_PERFORM;
5592 Entry *e = ce->ce_entry;
5593 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
5598 delrec *dels = NULL, *deltail = NULL;
5600 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5601 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
5603 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5604 if (ml->sml_desc == slap_schema.si_ad_objectClass)
5608 colst = count_ocs( oc_at, &nocs );
5610 /* make sure add/del flags are clear; should always be true */
5611 for ( s = save_attrs; s; s = s->a_next ) {
5612 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
5615 e->e_attrs = attrs_dup( e->e_attrs );
5617 init_config_argv( ca );
5620 ca->ca_private = ce->ce_private;
5622 ca->fname = "slapd";
5624 strcpy( ca->log, "back-config" );
5626 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5627 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5628 switch (ml->sml_op) {
5629 case LDAP_MOD_DELETE:
5630 case LDAP_MOD_REPLACE:
5631 case SLAP_MOD_SOFTDEL:
5633 BerVarray vals = NULL, nvals = NULL;
5635 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
5637 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
5638 ml->sml_desc->ad_cname.bv_val );
5641 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5642 vals = ml->sml_values;
5643 nvals = ml->sml_nvalues;
5644 ml->sml_values = NULL;
5645 ml->sml_nvalues = NULL;
5647 /* If we're deleting by values, remember the indexes of the
5648 * values we deleted.
5650 if ( ct && ml->sml_values ) {
5652 i = ml->sml_numvals;
5653 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
5664 rc = modify_delete_vindex(e, &ml->sml_mod,
5665 get_permissiveModify(op),
5666 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
5667 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5668 ml->sml_values = vals;
5669 ml->sml_nvalues = nvals;
5671 if ( rc == LDAP_NO_SUCH_ATTRIBUTE && ml->sml_op == SLAP_MOD_SOFTDEL )
5675 /* FIXME: check rc before fallthru? */
5679 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5681 case SLAP_MOD_ADD_IF_NOT_PRESENT:
5682 if ( ml->sml_op == SLAP_MOD_ADD_IF_NOT_PRESENT
5683 && attr_find( e->e_attrs, ml->sml_desc ) )
5690 case SLAP_MOD_SOFTADD: {
5691 int mop = ml->sml_op;
5693 ml->sml_op = LDAP_MOD_ADD;
5695 if ( ct->arg_type & ARG_NO_INSERT ) {
5696 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
5698 navals = a->a_numvals;
5701 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
5702 if ( ml->sml_values[i].bv_val[0] == '{' &&
5705 char *next, *val = ml->sml_values[i].bv_val + 1;
5708 j = strtol( val, &next, 0 );
5709 if ( next == val || next[ 0 ] != '}' || j < navals ) {
5711 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
5712 ml->sml_desc->ad_cname.bv_val );
5716 rc = check_vals( ct, ca, ml, 0 );
5717 if ( rc ) goto out_noop;
5720 rc = modify_add_values(e, &ml->sml_mod,
5721 get_permissiveModify(op),
5722 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5724 /* If value already exists, show success here
5725 * and ignore this operation down below.
5727 if ( mop == SLAP_MOD_SOFTADD ) {
5728 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
5738 case LDAP_MOD_INCREMENT: /* FIXME */
5743 if(rc != LDAP_SUCCESS) break;
5746 if ( rc == LDAP_SUCCESS) {
5747 /* check that the entry still obeys the schema */
5748 rc = entry_schema_check(op, e, NULL, 0, 0, NULL,
5749 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5751 if ( rc ) goto out_noop;
5753 /* Basic syntax checks are OK. Do the actual settings. */
5754 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5755 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5756 if ( !ct ) continue;
5758 s = attr_find( save_attrs, ml->sml_desc );
5759 a = attr_find( e->e_attrs, ml->sml_desc );
5761 switch (ml->sml_op) {
5762 case LDAP_MOD_DELETE:
5763 case LDAP_MOD_REPLACE: {
5764 BerVarray vals = NULL, nvals = NULL;
5767 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5768 vals = ml->sml_values;
5769 nvals = ml->sml_nvalues;
5770 ml->sml_values = NULL;
5771 ml->sml_nvalues = NULL;
5774 if ( ml->sml_values )
5777 /* If we didn't delete the whole attribute */
5778 if ( ml->sml_values && a ) {
5779 struct berval *mvals;
5782 if ( ml->sml_nvalues )
5783 mvals = ml->sml_nvalues;
5785 mvals = ml->sml_values;
5787 /* use the indexes we saved up above */
5788 for (i=0; i < d->nidx; i++) {
5789 struct berval bv = *mvals++;
5790 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
5791 bv.bv_val[0] == '{' ) {
5792 ptr = strchr( bv.bv_val, '}' ) + 1;
5793 bv.bv_len -= ptr - bv.bv_val;
5796 ca->line = bv.bv_val;
5797 ca->valx = d->idx[i];
5798 config_parse_vals(ct, ca, d->idx[i] );
5799 rc = config_del_vals( ct, ca );
5800 if ( rc != LDAP_SUCCESS ) break;
5802 s->a_flags |= SLAP_ATTR_IXDEL;
5803 for (j=i+1; j < d->nidx; j++)
5804 if ( d->idx[j] >d->idx[i] )
5811 rc = config_del_vals( ct, ca );
5812 if ( rc ) rc = LDAP_OTHER;
5814 s->a_flags |= SLAP_ATTR_IXDEL;
5816 if ( ml->sml_values ) {
5821 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5822 ml->sml_values = vals;
5823 ml->sml_nvalues = nvals;
5825 if ( !vals || rc != LDAP_SUCCESS )
5828 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5833 for (i=0; ml->sml_values[i].bv_val; i++) {
5834 ca->line = ml->sml_values[i].bv_val;
5836 rc = config_modify_add( ct, ca, ml->sml_desc, i );
5839 a->a_flags |= SLAP_ATTR_IXADD;
5846 /* Undo for a failed operation */
5847 if ( rc != LDAP_SUCCESS ) {
5848 ConfigReply msg = ca->reply;
5849 for ( s = save_attrs; s; s = s->a_next ) {
5850 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
5851 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5852 ct = config_find_table( colst, nocs, s->a_desc, ca );
5853 a = attr_find( e->e_attrs, s->a_desc );
5855 /* clear the flag so the add check below will skip it */
5856 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5860 config_del_vals( ct, ca );
5862 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5863 ca->line = s->a_vals[i].bv_val;
5865 config_modify_add( ct, ca, s->a_desc, i );
5869 for ( a = e->e_attrs; a; a = a->a_next ) {
5870 if ( a->a_flags & SLAP_ATTR_IXADD ) {
5871 ct = config_find_table( colst, nocs, a->a_desc, ca );
5875 config_del_vals( ct, ca );
5876 s = attr_find( save_attrs, a->a_desc );
5878 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5879 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5880 ca->line = s->a_vals[i].bv_val;
5882 config_modify_add( ct, ca, s->a_desc, i );
5893 if ( rc == LDAP_SUCCESS ) {
5894 attrs_free( save_attrs );
5897 attrs_free( e->e_attrs );
5898 e->e_attrs = save_attrs;
5900 ch_free( ca->argv );
5901 if ( colst ) ch_free( colst );
5903 deltail = dels->next;
5912 config_back_modify( Operation *op, SlapReply *rs )
5915 CfEntryInfo *ce, *last;
5917 ConfigArgs ca = {0};
5920 AttributeDescription *rad = NULL;
5923 cfb = (CfBackInfo *)op->o_bd->be_private;
5925 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5928 rs->sr_matched = last->ce_entry->e_name.bv_val;
5929 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5933 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
5934 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5938 /* Get type of RDN */
5939 rdn = ce->ce_entry->e_nname;
5940 ptr = strchr( rdn.bv_val, '=' );
5941 rdn.bv_len = ptr - rdn.bv_val;
5942 rs->sr_err = slap_bv2ad( &rdn, &rad, &rs->sr_text );
5943 if ( rs->sr_err != LDAP_SUCCESS ) {
5947 /* Some basic validation... */
5948 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5949 /* Don't allow Modify of RDN; must use ModRdn for that. */
5950 if ( ml->sml_desc == rad ) {
5951 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
5952 rs->sr_text = "Use modrdn to change the entry name";
5955 /* Internal update of contextCSN? */
5956 if ( ml->sml_desc == slap_schema.si_ad_contextCSN && op->o_conn->c_conn_idx == -1 ) {
5962 slap_mods_opattrs( op, &op->orm_modlist, 1 );
5965 if ( op->o_abandon ) {
5966 rs->sr_err = SLAPD_ABANDON;
5969 ldap_pvt_thread_pool_pause( &connection_pool );
5973 * 1) perform the Modify on the cached Entry.
5974 * 2) verify that the Entry still satisfies the schema.
5975 * 3) perform the individual config operations.
5976 * 4) store Modified entry in underlying LDIF backend.
5978 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
5980 rs->sr_text = ca.cr_msg;
5981 } else if ( cfb->cb_use_ldif ) {
5982 BackendDB *be = op->o_bd;
5983 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5984 struct berval dn, ndn;
5986 op->o_bd = &cfb->cb_db;
5990 op->o_dn = op->o_bd->be_rootdn;
5991 op->o_ndn = op->o_bd->be_rootndn;
5993 scp = op->o_callback;
5994 op->o_callback = ≻
5995 op->o_bd->be_modify( op, rs );
5997 op->o_callback = scp;
6003 ldap_pvt_thread_pool_resume( &connection_pool );
6005 send_ldap_result( op, rs );
6006 slap_graduate_commit_csn( op );
6011 config_back_modrdn( Operation *op, SlapReply *rs )
6014 CfEntryInfo *ce, *last;
6018 cfb = (CfBackInfo *)op->o_bd->be_private;
6020 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6023 rs->sr_matched = last->ce_entry->e_name.bv_val;
6024 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6027 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
6028 NULL, ACL_WRITE, NULL )) {
6029 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6033 if ( ce->ce_parent )
6034 parent = ce->ce_parent->ce_entry;
6036 parent = (Entry *)&slap_entry_root;
6037 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
6038 NULL, ACL_WRITE, NULL )) {
6039 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6044 /* We don't allow moving objects to new parents.
6045 * Generally we only allow reordering a set of ordered entries.
6047 if ( op->orr_newSup ) {
6048 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6052 /* If newRDN == oldRDN, quietly succeed */
6053 dnRdn( &op->o_req_ndn, &rdn );
6054 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
6055 rs->sr_err = LDAP_SUCCESS;
6059 /* Current behavior, subject to change as needed:
6061 * For backends and overlays, we only allow renumbering.
6062 * For schema, we allow renaming with the same number.
6063 * Otherwise, the op is not allowed.
6066 if ( ce->ce_type == Cft_Schema ) {
6070 /* Can't alter the main cn=schema entry */
6071 if ( ce->ce_parent->ce_type == Cft_Global ) {
6072 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6073 rs->sr_text = "renaming not allowed for this entry";
6077 /* We could support this later if desired */
6078 ptr1 = ber_bvchr( &rdn, '}' );
6079 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
6080 len = ptr1 - rdn.bv_val;
6081 if ( len != ptr2 - op->orr_newrdn.bv_val ||
6082 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
6083 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6084 rs->sr_text = "schema reordering not supported";
6087 } else if ( ce->ce_type == Cft_Database ||
6088 ce->ce_type == Cft_Overlay ) {
6089 char *ptr1, *ptr2, *iptr1, *iptr2;
6092 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
6093 if ( *iptr2 != '{' ) {
6094 rs->sr_err = LDAP_NAMING_VIOLATION;
6095 rs->sr_text = "new ordering index is required";
6099 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
6100 ptr1 = ber_bvchr( &rdn, '}' );
6101 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
6103 rs->sr_err = LDAP_NAMING_VIOLATION;
6104 rs->sr_text = "new ordering index is required";
6108 len1 = ptr1 - rdn.bv_val;
6109 len2 = ptr2 - op->orr_newrdn.bv_val;
6111 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
6112 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
6113 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6114 rs->sr_text = "changing database/overlay type not allowed";
6117 ixold = strtol( iptr1, NULL, 0 );
6118 ixnew = strtol( iptr2, &ptr1, 0 );
6119 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
6120 rs->sr_err = LDAP_NAMING_VIOLATION;
6123 /* config DB is always 0, cannot be changed */
6124 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
6125 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
6129 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6130 rs->sr_text = "renaming not supported for this entry";
6134 if ( op->o_abandon ) {
6135 rs->sr_err = SLAPD_ABANDON;
6138 ldap_pvt_thread_pool_pause( &connection_pool );
6140 if ( ce->ce_type == Cft_Schema ) {
6141 req_modrdn_s modr = op->oq_modrdn;
6144 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
6145 if ( rs->sr_err == LDAP_SUCCESS ) {
6146 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
6147 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
6150 op->oq_modrdn = modr;
6152 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
6153 req_modrdn_s modr = op->oq_modrdn;
6156 /* Advance to first of this type */
6157 cprev = &ce->ce_parent->ce_kids;
6158 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
6159 cprev = &ce2->ce_sibs;
6162 /* Skip the -1 entry */
6163 if ( ce->ce_type == Cft_Database ) {
6164 cprev = &ce2->ce_sibs;
6170 /* Remove from old slot */
6171 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
6172 cprev = &ce2->ce_sibs;
6173 *cprev = ce->ce_sibs;
6174 ceold = ce->ce_sibs;
6176 /* Insert into new slot */
6178 for ( i=0; i<ixnew; i++ ) {
6182 cprev = &ce2->ce_sibs;
6184 ce->ce_sibs = *cprev;
6189 /* NOTE: These should be encoded in the OC tables, not inline here */
6190 if ( ce->ce_type == Cft_Database )
6191 backend_db_move( ce->ce_be, ixnew );
6192 else if ( ce->ce_type == Cft_Overlay )
6193 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
6195 if ( ixold < ixnew ) {
6196 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
6199 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
6200 ixold - ixnew, cfb->cb_use_ldif );
6202 op->oq_modrdn = modr;
6205 ldap_pvt_thread_pool_resume( &connection_pool );
6207 send_ldap_result( op, rs );
6212 config_back_delete( Operation *op, SlapReply *rs )
6214 #ifdef SLAP_CONFIG_DELETE
6216 CfEntryInfo *ce, *last, *ce2;
6218 cfb = (CfBackInfo *)op->o_bd->be_private;
6220 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6223 rs->sr_matched = last->ce_entry->e_name.bv_val;
6224 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6225 } else if ( ce->ce_kids ) {
6226 rs->sr_err = LDAP_NOT_ALLOWED_ON_NONLEAF;
6227 } else if ( op->o_abandon ) {
6228 rs->sr_err = SLAPD_ABANDON;
6229 } else if ( ce->ce_type == Cft_Overlay ||
6230 ce->ce_type == Cft_Database ||
6231 ce->ce_type == Cft_Misc ){
6235 ldap_pvt_thread_pool_pause( &connection_pool );
6237 if ( ce->ce_type == Cft_Overlay ){
6238 overlay_remove( ce->ce_be, (slap_overinst *)ce->ce_bi, op );
6239 } else if ( ce->ce_type == Cft_Misc ) {
6241 * only Cft_Misc objects that have a co_lddel handler set in
6242 * the ConfigOCs struct can be deleted. This code also
6243 * assumes that the entry can be only have one objectclass
6244 * with co_type == Cft_Misc
6246 ConfigOCs co, *coptr;
6250 oc_at = attr_find( ce->ce_entry->e_attrs,
6251 slap_schema.si_ad_objectClass );
6253 rs->sr_err = LDAP_OTHER;
6254 rs->sr_text = "objectclass not found";
6255 ldap_pvt_thread_pool_resume( &connection_pool );
6258 for ( i=0; !BER_BVISNULL(&oc_at->a_nvals[i]); i++ ) {
6259 co.co_name = &oc_at->a_nvals[i];
6260 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
6261 if ( coptr == NULL || coptr->co_type != Cft_Misc ) {
6264 if ( ! coptr->co_lddel || coptr->co_lddel( ce, op ) ){
6265 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6266 if ( ! coptr->co_lddel ) {
6267 rs->sr_text = "No delete handler found";
6269 rs->sr_err = LDAP_OTHER;
6270 /* FIXME: We should return a helpful error message
6273 ldap_pvt_thread_pool_resume( &connection_pool );
6278 } else if (ce->ce_type == Cft_Database ) {
6279 if ( ce->ce_be == frontendDB || ce->ce_be == op->o_bd ){
6280 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6281 rs->sr_text = "Cannot delete config or frontend database";
6282 ldap_pvt_thread_pool_resume( &connection_pool );
6285 if ( ce->ce_be->bd_info->bi_db_close ) {
6286 ce->ce_be->bd_info->bi_db_close( ce->ce_be, NULL );
6288 backend_destroy_one( ce->ce_be, 1);
6291 /* remove CfEntryInfo from the siblings list */
6292 if ( ce->ce_parent->ce_kids == ce ) {
6293 ce->ce_parent->ce_kids = ce->ce_sibs;
6295 for ( ce2 = ce->ce_parent->ce_kids ; ce2; ce2 = ce2->ce_sibs ) {
6296 if ( ce2->ce_sibs == ce ) {
6297 ce2->ce_sibs = ce->ce_sibs;
6303 /* remove from underlying database */
6304 if ( cfb->cb_use_ldif ) {
6305 BackendDB *be = op->o_bd;
6306 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
6307 struct berval dn, ndn, req_dn, req_ndn;
6309 op->o_bd = &cfb->cb_db;
6313 req_dn = op->o_req_dn;
6314 req_ndn = op->o_req_ndn;
6316 op->o_dn = op->o_bd->be_rootdn;
6317 op->o_ndn = op->o_bd->be_rootndn;
6318 op->o_req_dn = ce->ce_entry->e_name;
6319 op->o_req_ndn = ce->ce_entry->e_nname;
6321 scp = op->o_callback;
6322 op->o_callback = ≻
6323 op->o_bd->be_delete( op, rs );
6325 op->o_callback = scp;
6328 op->o_req_dn = req_dn;
6329 op->o_req_ndn = req_ndn;
6332 /* renumber siblings */
6333 iptr = ber_bvchr( &op->o_req_ndn, '{' ) + 1;
6334 ixold = strtol( iptr, NULL, 0 );
6335 for (ce2 = ce->ce_sibs, count=0; ce2; ce2=ce2->ce_sibs) {
6336 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
6337 count+ixold, 0, cfb->cb_use_ldif );
6341 ce->ce_entry->e_private=NULL;
6342 entry_free(ce->ce_entry);
6344 ldap_pvt_thread_pool_resume( &connection_pool );
6346 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6350 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6351 #endif /* SLAP_CONFIG_DELETE */
6352 send_ldap_result( op, rs );
6357 config_back_search( Operation *op, SlapReply *rs )
6360 CfEntryInfo *ce, *last;
6363 cfb = (CfBackInfo *)op->o_bd->be_private;
6365 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6368 rs->sr_matched = last->ce_entry->e_name.bv_val;
6369 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6372 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
6373 ACL_SEARCH, NULL, &mask ))
6375 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
6376 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6378 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6382 switch ( op->ors_scope ) {
6383 case LDAP_SCOPE_BASE:
6384 case LDAP_SCOPE_SUBTREE:
6385 rs->sr_err = config_send( op, rs, ce, 0 );
6388 case LDAP_SCOPE_ONELEVEL:
6389 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
6390 rs->sr_err = config_send( op, rs, ce, 1 );
6399 send_ldap_result( op, rs );
6403 /* no-op, we never free entries */
6404 int config_entry_release(
6409 if ( !e->e_private ) {
6412 return LDAP_SUCCESS;
6415 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
6417 int config_back_entry_get(
6421 AttributeDescription *at,
6426 CfEntryInfo *ce, *last;
6427 int rc = LDAP_NO_SUCH_OBJECT;
6429 cfb = (CfBackInfo *)op->o_bd->be_private;
6431 ce = config_find_base( cfb->cb_root, ndn, &last );
6433 *ent = ce->ce_entry;
6436 if ( oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
6437 rc = LDAP_NO_SUCH_ATTRIBUTE;
6447 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
6448 ConfigTable *ct, ConfigArgs *c )
6452 for (; at && *at; at++) {
6453 /* Skip the naming attr */
6454 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
6456 for (i=0;ct[i].name;i++) {
6457 if (ct[i].ad == (*at)->sat_ad) {
6458 rc = config_get_vals(&ct[i], c);
6459 /* NOTE: tolerate that config_get_vals()
6460 * returns success with no values */
6461 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
6462 if ( c->rvalue_nvals )
6463 rc = attr_merge(e, ct[i].ad, c->rvalue_vals,
6466 slap_syntax_validate_func *validate =
6467 ct[i].ad->ad_type->sat_syntax->ssyn_validate;
6470 for ( j=0; c->rvalue_vals[j].bv_val; j++ ) {
6471 rc = ordered_value_validate( ct[i].ad,
6472 &c->rvalue_vals[j], LDAP_MOD_ADD );
6474 Debug( LDAP_DEBUG_ANY,
6475 "config_build_attrs: error %d on %s value #%d\n",
6476 rc, ct[i].ad->ad_cname.bv_val, j );
6482 rc = attr_merge_normalize(e, ct[i].ad,
6483 c->rvalue_vals, NULL);
6485 ber_bvarray_free( c->rvalue_nvals );
6486 ber_bvarray_free( c->rvalue_vals );
6488 Debug( LDAP_DEBUG_ANY,
6489 "config_build_attrs: error %d on %s\n",
6490 rc, ct[i].ad->ad_cname.bv_val, 0 );
6501 /* currently (2010) does not access rs except possibly writing rs->sr_err */
6504 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
6505 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
6507 Entry *e = entry_alloc();
6508 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
6510 struct berval ad_name;
6511 AttributeDescription *ad = NULL;
6514 const char *text = "";
6518 CfEntryInfo *ceprev = NULL;
6520 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
6523 ce->ce_type = main->co_type;
6524 ce->ce_parent = parent;
6526 pdn = parent->ce_entry->e_nname;
6527 if ( parent->ce_kids && parent->ce_kids->ce_type <= ce->ce_type )
6528 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
6529 ceprev->ce_type <= ce->ce_type;
6530 ceprev = ceprev->ce_sibs );
6535 ce->ce_private = c->ca_private;
6539 build_new_dn( &e->e_name, &pdn, rdn, NULL );
6540 ber_dupbv( &e->e_nname, &e->e_name );
6542 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6543 main->co_name, NULL );
6545 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6546 extra->co_name, NULL );
6547 ptr = strchr(rdn->bv_val, '=');
6548 ad_name.bv_val = rdn->bv_val;
6549 ad_name.bv_len = ptr - rdn->bv_val;
6550 rc = slap_bv2ad( &ad_name, &ad, &text );
6555 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
6556 attr_merge_normalize_one(e, ad, &val, NULL );
6559 c->table = main->co_type;
6560 if ( oc->soc_required ) {
6561 rc = config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
6562 if ( rc ) goto fail;
6565 if ( oc->soc_allowed ) {
6566 rc = config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
6567 if ( rc ) goto fail;
6572 c->table = extra->co_type;
6573 if ( oc->soc_required ) {
6574 rc = config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
6575 if ( rc ) goto fail;
6578 if ( oc->soc_allowed ) {
6579 rc = config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
6580 if ( rc ) goto fail;
6584 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
6585 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
6586 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
6587 if ( rc != LDAP_SUCCESS ) {
6589 Debug( LDAP_DEBUG_ANY,
6590 "config_build_entry: build \"%s\" failed: \"%s\"\n",
6591 rdn->bv_val, text, 0);
6594 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
6597 op->ora_modlist = NULL;
6598 slap_add_opattrs( op, NULL, NULL, 0, 0 );
6599 if ( !op->o_noop ) {
6600 SlapReply rs2 = {REP_RESULT};
6601 op->o_bd->be_add( op, &rs2 );
6602 rs->sr_err = rs2.sr_err;
6603 rs_assert_done( &rs2 );
6604 if ( ( rs2.sr_err != LDAP_SUCCESS )
6605 && (rs2.sr_err != LDAP_ALREADY_EXISTS) ) {
6611 ce->ce_sibs = ceprev->ce_sibs;
6612 ceprev->ce_sibs = ce;
6613 } else if ( parent ) {
6614 ce->ce_sibs = parent->ce_kids;
6615 parent->ce_kids = ce;
6622 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
6623 Operation *op, SlapReply *rs )
6626 ConfigFile *cf = c->ca_private;
6628 struct berval bv, rdn;
6630 for (; cf; cf=cf->c_sibs, c->depth++) {
6631 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
6632 !cf->c_om_head && !cf->c_syn_head ) continue;
6633 c->value_dn.bv_val = c->log;
6634 LUTIL_SLASHPATH( cf->c_file.bv_val );
6635 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
6640 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
6642 ptr = strchr( bv.bv_val, '.' );
6644 bv.bv_len = ptr - bv.bv_val;
6645 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
6646 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6647 /* FIXME: how can indicate error? */
6650 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
6652 c->value_dn.bv_len += bv.bv_len;
6653 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
6654 rdnNormalize( 0, NULL, NULL, &c->value_dn, &rdn, NULL );
6657 e = config_build_entry( op, rs, ceparent, c, &rdn,
6658 &CFOC_SCHEMA, NULL );
6659 ch_free( rdn.bv_val );
6662 } else if ( e && cf->c_kids ) {
6663 c->ca_private = cf->c_kids;
6664 config_build_schema_inc( c, e->e_private, op, rs );
6670 #ifdef SLAPD_MODULES
6673 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
6674 Operation *op, SlapReply *rs )
6679 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
6680 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
6682 c->value_dn.bv_val = c->log;
6683 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
6684 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6685 /* FIXME: how can indicate error? */
6689 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
6698 config_check_schema(Operation *op, CfBackInfo *cfb)
6700 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
6702 CfEntryInfo *ce, *last;
6705 /* If there's no root entry, we must be in the midst of converting */
6706 if ( !cfb->cb_root )
6709 /* Make sure the main schema entry exists */
6710 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
6717 /* Make sure it's up to date */
6718 if ( cf_om_tail != om_sys_tail ) {
6719 a = attr_find( e->e_attrs, cfAd_om );
6721 if ( a->a_nvals != a->a_vals )
6722 ber_bvarray_free( a->a_nvals );
6723 ber_bvarray_free( a->a_vals );
6728 oidm_unparse( &bv, NULL, NULL, 1 );
6729 attr_merge_normalize( e, cfAd_om, bv, NULL );
6730 ber_bvarray_free( bv );
6731 cf_om_tail = om_sys_tail;
6733 if ( cf_at_tail != at_sys_tail ) {
6734 a = attr_find( e->e_attrs, cfAd_attr );
6736 if ( a->a_nvals != a->a_vals )
6737 ber_bvarray_free( a->a_nvals );
6738 ber_bvarray_free( a->a_vals );
6743 at_unparse( &bv, NULL, NULL, 1 );
6744 attr_merge_normalize( e, cfAd_attr, bv, NULL );
6745 ber_bvarray_free( bv );
6746 cf_at_tail = at_sys_tail;
6748 if ( cf_oc_tail != oc_sys_tail ) {
6749 a = attr_find( e->e_attrs, cfAd_oc );
6751 if ( a->a_nvals != a->a_vals )
6752 ber_bvarray_free( a->a_nvals );
6753 ber_bvarray_free( a->a_vals );
6758 oc_unparse( &bv, NULL, NULL, 1 );
6759 attr_merge_normalize( e, cfAd_oc, bv, NULL );
6760 ber_bvarray_free( bv );
6761 cf_oc_tail = oc_sys_tail;
6763 if ( cf_syn_tail != syn_sys_tail ) {
6764 a = attr_find( e->e_attrs, cfAd_syntax );
6766 if ( a->a_nvals != a->a_vals )
6767 ber_bvarray_free( a->a_nvals );
6768 ber_bvarray_free( a->a_vals );
6773 syn_unparse( &bv, NULL, NULL, 1 );
6774 attr_merge_normalize( e, cfAd_syntax, bv, NULL );
6775 ber_bvarray_free( bv );
6776 cf_syn_tail = syn_sys_tail;
6779 SlapReply rs = {REP_RESULT};
6780 c.ca_private = NULL;
6781 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
6782 &CFOC_SCHEMA, NULL );
6787 ce->ce_private = cfb->cb_config;
6788 cf_at_tail = at_sys_tail;
6789 cf_oc_tail = oc_sys_tail;
6790 cf_om_tail = om_sys_tail;
6791 cf_syn_tail = syn_sys_tail;
6796 static const char *defacl[] = {
6797 NULL, "to", "*", "by", "*", "none", NULL
6801 config_back_db_open( BackendDB *be, ConfigReply *cr )
6803 CfBackInfo *cfb = be->be_private;
6806 CfEntryInfo *ce, *ceparent;
6810 Connection conn = {0};
6811 OperationBuffer opbuf;
6813 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
6814 SlapReply rs = {REP_RESULT};
6815 void *thrctx = NULL;
6816 AccessControl *save_access;
6818 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
6820 /* If we have no explicitly configured ACLs, don't just use
6821 * the global ACLs. Explicitly deny access to everything.
6823 save_access = be->bd_self->be_acl;
6824 be->bd_self->be_acl = NULL;
6825 parse_acl(be->bd_self, "config_back_db_open", 0, 6, (char **)defacl, 0 );
6826 defacl_parsed = be->bd_self->be_acl;
6827 if ( save_access ) {
6828 be->bd_self->be_acl = save_access;
6830 Debug( LDAP_DEBUG_CONFIG, "config_back_db_open: "
6831 "No explicit ACL for back-config configured. "
6832 "Using hardcoded default\n", 0, 0, 0 );
6835 thrctx = ldap_pvt_thread_pool_context();
6836 connection_fake_init( &conn, &opbuf, thrctx );
6839 op->o_tag = LDAP_REQ_ADD;
6840 op->o_callback = &cb;
6841 op->o_bd = &cfb->cb_db;
6842 op->o_dn = op->o_bd->be_rootdn;
6843 op->o_ndn = op->o_bd->be_rootndn;
6845 if ( !cfb->cb_use_ldif ) {
6849 /* If we read the config from back-ldif, do some quick sanity checks */
6850 if ( cfb->cb_got_ldif ) {
6851 return config_check_schema( op, cfb );
6854 /* create root of tree */
6856 c.ca_private = cfb->cb_config;
6858 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
6868 #ifdef SLAPD_MODULES
6869 /* Create Module nodes... */
6870 if ( modpaths.mp_loads ) {
6871 if ( config_build_modules( &c, ceparent, op, &rs ) ){
6877 /* Create schema nodes... cn=schema will contain the hardcoded core
6878 * schema, read-only. Child objects will contain runtime loaded schema
6882 c.ca_private = NULL;
6883 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
6888 ce->ce_private = cfb->cb_config;
6889 cf_at_tail = at_sys_tail;
6890 cf_oc_tail = oc_sys_tail;
6891 cf_om_tail = om_sys_tail;
6892 cf_syn_tail = syn_sys_tail;
6894 /* Create schema nodes for included schema... */
6895 if ( cfb->cb_config->c_kids ) {
6898 c.ca_private = cfb->cb_config->c_kids;
6899 rc = config_build_schema_inc( &c, ce, op, &rs );
6905 /* Create backend nodes. Skip if they don't provide a cf_table.
6906 * There usually aren't any of these.
6910 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
6911 if (!bi->bi_cf_ocs) {
6912 /* If it only supports the old config mech, complain. */
6913 if ( bi->bi_config ) {
6914 Debug( LDAP_DEBUG_ANY,
6915 "WARNING: No dynamic config support for backend %s.\n",
6916 bi->bi_type, 0, 0 );
6921 if (!bi->bi_private) continue;
6924 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6925 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
6926 if ( rdn.bv_len >= sizeof( c.log ) ) {
6927 /* FIXME: holler ... */ ;
6930 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
6937 /* Create database nodes... */
6938 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
6939 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
6940 for ( i = -1, be = frontendDB ; be;
6941 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
6942 slap_overinfo *oi = NULL;
6944 if ( overlay_is_over( be )) {
6945 oi = be->bd_info->bi_private;
6951 /* If this backend supports the old config mechanism, but not
6952 * the new mech, complain.
6954 if ( !be->be_cf_ocs && bi->bi_db_config ) {
6955 Debug( LDAP_DEBUG_ANY,
6956 "WARNING: No dynamic config support for database %s.\n",
6957 bi->bi_type, 0, 0 );
6961 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6962 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
6964 if ( rdn.bv_len >= sizeof( c.log ) ) {
6965 /* FIXME: holler ... */ ;
6969 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
6975 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd ) {
6976 rs_reinit( &rs, REP_RESULT );
6977 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
6979 /* Iterate through overlays */
6984 voidList *vl, *v0 = NULL;
6986 /* overlays are in LIFO order, must reverse stack */
6987 for (on=oi->oi_list; on; on=on->on_next) {
6988 vl = ch_malloc( sizeof( voidList ));
6993 for (j=0; vl; j++,vl=v0) {
6997 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
6998 Debug( LDAP_DEBUG_ANY,
6999 "WARNING: No dynamic config support for overlay %s.\n",
7000 on->on_bi.bi_type, 0, 0 );
7004 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
7005 "%s=" SLAP_X_ORDERED_FMT "%s",
7006 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
7007 if ( rdn.bv_len >= sizeof( c.log ) ) {
7008 /* FIXME: holler ... */ ;
7012 oe = config_build_entry( op, &rs, ce, &c, &rdn,
7013 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
7017 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd ) {
7018 rs_reinit( &rs, REP_RESULT );
7019 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
7025 ldap_pvt_thread_pool_context_reset( thrctx );
7027 if ( unsupp && cfb->cb_use_ldif ) {
7028 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
7029 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
7036 cfb_free_cffile( ConfigFile *cf )
7040 for (; cf; cf=next) {
7043 cfb_free_cffile( cf->c_kids );
7044 ch_free( cf->c_file.bv_val );
7045 ber_bvarray_free( cf->c_dseFiles );
7051 cfb_free_entries( CfEntryInfo *ce )
7055 for (; ce; ce=next) {
7058 cfb_free_entries( ce->ce_kids );
7059 ce->ce_entry->e_private = NULL;
7060 entry_free( ce->ce_entry );
7066 config_back_db_close( BackendDB *be, ConfigReply *cr )
7068 CfBackInfo *cfb = be->be_private;
7070 cfb_free_entries( cfb->cb_root );
7071 cfb->cb_root = NULL;
7073 if ( cfb->cb_db.bd_info ) {
7074 backend_shutdown( &cfb->cb_db );
7077 if ( defacl_parsed && be->be_acl != defacl_parsed ) {
7078 acl_free( defacl_parsed );
7079 defacl_parsed = NULL;
7086 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
7088 CfBackInfo *cfb = be->be_private;
7090 cfb_free_cffile( cfb->cb_config );
7092 ch_free( cfdir.bv_val );
7094 avl_free( CfOcTree, NULL );
7096 if ( cfb->cb_db.bd_info ) {
7097 cfb->cb_db.be_suffix = NULL;
7098 cfb->cb_db.be_nsuffix = NULL;
7099 BER_BVZERO( &cfb->cb_db.be_rootdn );
7100 BER_BVZERO( &cfb->cb_db.be_rootndn );
7102 backend_destroy_one( &cfb->cb_db, 0 );
7111 config_back_db_init( BackendDB *be, ConfigReply* cr )
7117 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
7118 cfn = cfb->cb_config;
7119 be->be_private = cfb;
7121 ber_dupbv( &be->be_rootdn, &config_rdn );
7122 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
7123 ber_dupbv( &dn, &be->be_rootdn );
7124 ber_bvarray_add( &be->be_suffix, &dn );
7125 ber_dupbv( &dn, &be->be_rootdn );
7126 ber_bvarray_add( &be->be_nsuffix, &dn );
7128 /* Hide from namingContexts */
7129 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
7131 /* Check ACLs on content of Adds by default */
7132 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_ACL_ADD;
7138 config_back_destroy( BackendInfo *bi )
7140 ldif_must_b64_encode_release();
7145 config_tool_entry_open( BackendDB *be, int mode )
7147 CfBackInfo *cfb = be->be_private;
7148 BackendInfo *bi = cfb->cb_db.bd_info;
7150 if ( bi && bi->bi_tool_entry_open )
7151 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
7158 config_tool_entry_close( BackendDB *be )
7160 CfBackInfo *cfb = be->be_private;
7161 BackendInfo *bi = cfb->cb_db.bd_info;
7163 if ( bi && bi->bi_tool_entry_close )
7164 return bi->bi_tool_entry_close( &cfb->cb_db );
7170 config_tool_entry_first( BackendDB *be )
7172 CfBackInfo *cfb = be->be_private;
7173 BackendInfo *bi = cfb->cb_db.bd_info;
7175 if ( bi && bi->bi_tool_entry_first ) {
7176 return bi->bi_tool_entry_first( &cfb->cb_db );
7178 if ( bi && bi->bi_tool_entry_first_x ) {
7179 return bi->bi_tool_entry_first_x( &cfb->cb_db,
7180 NULL, LDAP_SCOPE_DEFAULT, NULL );
7186 config_tool_entry_first_x(
7188 struct berval *base,
7192 CfBackInfo *cfb = be->be_private;
7193 BackendInfo *bi = cfb->cb_db.bd_info;
7195 if ( bi && bi->bi_tool_entry_first_x ) {
7196 return bi->bi_tool_entry_first_x( &cfb->cb_db, base, scope, f );
7202 config_tool_entry_next( BackendDB *be )
7204 CfBackInfo *cfb = be->be_private;
7205 BackendInfo *bi = cfb->cb_db.bd_info;
7207 if ( bi && bi->bi_tool_entry_next )
7208 return bi->bi_tool_entry_next( &cfb->cb_db );
7214 config_tool_entry_get( BackendDB *be, ID id )
7216 CfBackInfo *cfb = be->be_private;
7217 BackendInfo *bi = cfb->cb_db.bd_info;
7219 if ( bi && bi->bi_tool_entry_get )
7220 return bi->bi_tool_entry_get( &cfb->cb_db, id );
7225 static int entry_put_got_frontend=0;
7226 static int entry_put_got_config=0;
7228 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
7230 CfBackInfo *cfb = be->be_private;
7231 BackendInfo *bi = cfb->cb_db.bd_info;
7233 struct berval rdn, vals[ 2 ];
7235 OperationBuffer opbuf;
7237 Connection conn = {0};
7238 Operation *op = NULL;
7241 int isFrontendChild = 0;
7243 /* Create entry for frontend database if it does not exist already */
7244 if ( !entry_put_got_frontend ) {
7245 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
7246 STRLENOF( "olcDatabase" ))) {
7247 if ( strncmp( e->e_nname.bv_val +
7248 STRLENOF( "olcDatabase" ), "={-1}frontend",
7249 STRLENOF( "={-1}frontend" )) &&
7250 strncmp( e->e_nname.bv_val +
7251 STRLENOF( "olcDatabase" ), "=frontend",
7252 STRLENOF( "=frontend" ))) {
7254 vals[1].bv_val = NULL;
7255 memset( &ca, 0, sizeof(ConfigArgs));
7257 ca.bi = frontendDB->bd_info;
7258 ca.be->be_cf_ocs = &CFOC_FRONTEND;
7259 rdn.bv_val = ca.log;
7260 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7261 "%s=" SLAP_X_ORDERED_FMT "%s",
7262 cfAd_database->ad_cname.bv_val, -1,
7264 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
7265 &CFOC_DATABASE, ca.be->be_cf_ocs );
7266 thrctx = ldap_pvt_thread_pool_context();
7267 connection_fake_init2( &conn, &opbuf, thrctx,0 );
7269 op->o_bd = &cfb->cb_db;
7270 op->o_tag = LDAP_REQ_ADD;
7272 op->o_dn = be->be_rootdn;
7273 op->o_ndn = be->be_rootndn;
7274 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
7275 if ( rc != LDAP_SUCCESS ) {
7276 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
7277 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
7281 if ( ce && bi && bi->bi_tool_entry_put &&
7282 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
7283 entry_put_got_frontend++;
7285 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
7286 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
7290 if ( !strncmp( e->e_nname.bv_val +
7291 STRLENOF( "olcDatabase" ), "=frontend",
7292 STRLENOF( "=frontend" ) ) )
7294 struct berval rdn, pdn, ndn;
7295 dnParent( &e->e_nname, &pdn );
7296 rdn.bv_val = ca.log;
7297 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7298 "%s=" SLAP_X_ORDERED_FMT "%s",
7299 cfAd_database->ad_cname.bv_val, -1,
7300 frontendDB->bd_info->bi_type );
7301 build_new_dn( &ndn, &pdn, &rdn, NULL );
7302 ber_memfree( e->e_name.bv_val );
7304 ber_bvreplace( &e->e_nname, &e->e_name );
7306 entry_put_got_frontend++;
7312 /* Child entries of the frontend database, e.g. slapo-chain's back-ldap
7313 * instances, may appear before the config database entry in the ldif, skip
7314 * auto-creation of olcDatabase={0}config in such a case */
7315 if ( !entry_put_got_config &&
7316 !strncmp( e->e_nname.bv_val, "olcDatabase", STRLENOF( "olcDatabase" ))) {
7318 dnParent( &e->e_nname, &pdn );
7319 while ( pdn.bv_len ) {
7320 if ( !strncmp( pdn.bv_val, "olcDatabase",
7321 STRLENOF( "olcDatabase" ))) {
7322 if ( !strncmp( pdn.bv_val +
7323 STRLENOF( "olcDatabase" ), "={-1}frontend",
7324 STRLENOF( "={-1}frontend" )) ||
7325 !strncmp( pdn.bv_val +
7326 STRLENOF( "olcDatabase" ), "=frontend",
7327 STRLENOF( "=frontend" ))) {
7329 isFrontendChild = 1;
7333 dnParent( &pdn, &pdn );
7337 /* Create entry for config database if it does not exist already */
7338 if ( !entry_put_got_config && !isFrontend && !isFrontendChild ) {
7339 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
7340 STRLENOF( "olcDatabase" ))) {
7341 if ( strncmp( e->e_nname.bv_val +
7342 STRLENOF( "olcDatabase" ), "={0}config",
7343 STRLENOF( "={0}config" )) &&
7344 strncmp( e->e_nname.bv_val +
7345 STRLENOF( "olcDatabase" ), "=config",
7346 STRLENOF( "=config" )) ) {
7348 vals[1].bv_val = NULL;
7349 memset( &ca, 0, sizeof(ConfigArgs));
7350 ca.be = LDAP_STAILQ_FIRST( &backendDB );
7351 ca.bi = ca.be->bd_info;
7352 rdn.bv_val = ca.log;
7353 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7354 "%s=" SLAP_X_ORDERED_FMT "%s",
7355 cfAd_database->ad_cname.bv_val, 0,
7357 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
7360 thrctx = ldap_pvt_thread_pool_context();
7361 connection_fake_init2( &conn, &opbuf, thrctx,0 );
7363 op->o_bd = &cfb->cb_db;
7364 op->o_tag = LDAP_REQ_ADD;
7365 op->o_dn = be->be_rootdn;
7366 op->o_ndn = be->be_rootndn;
7369 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
7370 if ( rc != LDAP_SUCCESS ) {
7371 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
7372 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7375 if (ce && bi && bi->bi_tool_entry_put &&
7376 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
7377 entry_put_got_config++;
7379 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
7380 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7384 entry_put_got_config++;
7388 if ( bi && bi->bi_tool_entry_put &&
7389 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
7390 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
7397 AttributeDescription **desc;
7399 { "attribute", &cfAd_attr },
7400 { "backend", &cfAd_backend },
7401 { "database", &cfAd_database },
7402 { "include", &cfAd_include },
7403 { "ldapsyntax", &cfAd_syntax },
7404 { "objectclass", &cfAd_oc },
7405 { "objectidentifier", &cfAd_om },
7406 { "overlay", &cfAd_overlay },
7411 * add / delete: all types that may be added or deleted must use an
7412 * X-ORDERED attributeType for their RDN. Adding and deleting entries
7413 * should automatically renumber the index of any siblings as needed,
7414 * so that no gaps in the numbering sequence exist after the add/delete
7416 * What can be added:
7418 * backend objects for backend-specific config directives
7422 * delete: probably no support this time around.
7424 * modrdn: generally not done. Will be invoked automatically by add/
7425 * delete to update numbering sequence. Perform as an explicit operation
7426 * so that the renumbering effect may be replicated. Subtree rename must
7427 * be supported, since renumbering a database will affect all its child
7430 * modify: must be fully supported.
7434 config_back_initialize( BackendInfo *bi )
7436 ConfigTable *ct = config_back_cf_table;
7440 AttributeDescription *ad = NULL;
7442 static char *controls[] = {
7443 LDAP_CONTROL_MANAGEDSAIT,
7447 /* Make sure we don't exceed the bits reserved for userland */
7448 config_check_userland( CFG_LAST );
7450 bi->bi_controls = controls;
7455 bi->bi_destroy = config_back_destroy;
7457 bi->bi_db_init = config_back_db_init;
7458 bi->bi_db_config = 0;
7459 bi->bi_db_open = config_back_db_open;
7460 bi->bi_db_close = config_back_db_close;
7461 bi->bi_db_destroy = config_back_db_destroy;
7463 bi->bi_op_bind = config_back_bind;
7464 bi->bi_op_unbind = 0;
7465 bi->bi_op_search = config_back_search;
7466 bi->bi_op_compare = 0;
7467 bi->bi_op_modify = config_back_modify;
7468 bi->bi_op_modrdn = config_back_modrdn;
7469 bi->bi_op_add = config_back_add;
7470 bi->bi_op_delete = config_back_delete;
7471 bi->bi_op_abandon = 0;
7473 bi->bi_extended = 0;
7475 bi->bi_chk_referrals = 0;
7477 bi->bi_access_allowed = slap_access_allowed;
7479 bi->bi_connection_init = 0;
7480 bi->bi_connection_destroy = 0;
7482 bi->bi_entry_release_rw = config_entry_release;
7483 bi->bi_entry_get_rw = config_back_entry_get;
7485 bi->bi_tool_entry_open = config_tool_entry_open;
7486 bi->bi_tool_entry_close = config_tool_entry_close;
7487 bi->bi_tool_entry_first = config_tool_entry_first;
7488 bi->bi_tool_entry_first_x = config_tool_entry_first_x;
7489 bi->bi_tool_entry_next = config_tool_entry_next;
7490 bi->bi_tool_entry_get = config_tool_entry_get;
7491 bi->bi_tool_entry_put = config_tool_entry_put;
7494 argv[ 0 ] = "slapd";
7500 for (i=0; OidMacros[i].name; i++ ) {
7501 argv[1] = OidMacros[i].name;
7502 argv[2] = OidMacros[i].oid;
7503 parse_oidm( &ca, 0, NULL );
7506 bi->bi_cf_ocs = cf_ocs;
7508 i = config_register_schema( ct, cf_ocs );
7511 i = slap_str2ad( "olcDatabase", &olcDatabaseDummy[0].ad, &text );
7514 /* setup olcRootPW to be base64-encoded when written in LDIF form;
7515 * basically, we don't care if it fails */
7516 i = slap_str2ad( "olcRootPW", &ad, &text );
7518 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
7519 "warning, unable to get \"olcRootPW\" "
7520 "attribute description: %d: %s\n",
7523 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
7524 ad->ad_type->sat_oid );
7527 /* set up the notable AttributeDescriptions */
7529 for (;ct->name;ct++) {
7530 if (strcmp(ct->name, ads[i].name)) continue;
7531 *ads[i].desc = ct->ad;
7533 if (!ads[i].name) break;