1 /* bconfig.c - the config backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005-2012 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was originally developed by Howard Chu for inclusion
18 * in OpenLDAP Software.
24 #include <ac/string.h>
28 #include <ac/unistd.h>
33 #include "slapi/slapi.h"
41 #define CONFIG_RDN "cn=config"
42 #define SCHEMA_RDN "cn=schema"
44 static struct berval config_rdn = BER_BVC(CONFIG_RDN);
45 static struct berval schema_rdn = BER_BVC(SCHEMA_RDN);
47 extern int slap_DN_strict; /* dn.c */
50 typedef struct modpath_s {
51 struct modpath_s *mp_next;
52 struct berval mp_path;
56 static ModPaths modpaths, *modlast = &modpaths, *modcur = &modpaths;
59 typedef struct ConfigFile {
60 struct ConfigFile *c_sibs;
61 struct ConfigFile *c_kids;
63 AttributeType *c_at_head, *c_at_tail;
64 ContentRule *c_cr_head, *c_cr_tail;
65 ObjectClass *c_oc_head, *c_oc_tail;
66 OidMacro *c_om_head, *c_om_tail;
67 Syntax *c_syn_head, *c_syn_tail;
72 ConfigFile *cb_config;
74 BackendDB cb_db; /* underlying database */
79 static CfBackInfo cfBackInfo;
81 static char *passwd_salt;
83 static char *logfileName;
84 #ifdef SLAP_AUTH_REWRITE
85 static BerVarray authz_rewrites;
87 static AccessControl *defacl_parsed = NULL;
89 static struct berval cfdir;
92 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
93 *cfAd_include, *cfAd_attr, *cfAd_oc, *cfAd_om, *cfAd_syntax;
95 static ConfigFile *cfn;
97 static Avlnode *CfOcTree;
99 /* System schema state */
100 extern AttributeType *at_sys_tail; /* at.c */
101 extern ObjectClass *oc_sys_tail; /* oc.c */
102 extern OidMacro *om_sys_tail; /* oidm.c */
103 extern Syntax *syn_sys_tail; /* syntax.c */
104 static AttributeType *cf_at_tail;
105 static ObjectClass *cf_oc_tail;
106 static OidMacro *cf_om_tail;
107 static Syntax *cf_syn_tail;
109 static int config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca,
110 SlapReply *rs, int *renumber, Operation *op );
112 static int config_check_schema( Operation *op, CfBackInfo *cfb );
114 static ConfigDriver config_fname;
115 static ConfigDriver config_cfdir;
116 static ConfigDriver config_generic;
117 static ConfigDriver config_search_base;
118 static ConfigDriver config_passwd_hash;
119 static ConfigDriver config_schema_dn;
120 static ConfigDriver config_sizelimit;
121 static ConfigDriver config_timelimit;
122 static ConfigDriver config_overlay;
123 static ConfigDriver config_subordinate;
124 static ConfigDriver config_suffix;
125 #ifdef LDAP_TCP_BUFFER
126 static ConfigDriver config_tcp_buffer;
127 #endif /* LDAP_TCP_BUFFER */
128 static ConfigDriver config_rootdn;
129 static ConfigDriver config_rootpw;
130 static ConfigDriver config_restrict;
131 static ConfigDriver config_allows;
132 static ConfigDriver config_disallows;
133 static ConfigDriver config_requires;
134 static ConfigDriver config_security;
135 static ConfigDriver config_referral;
136 static ConfigDriver config_loglevel;
137 static ConfigDriver config_updatedn;
138 static ConfigDriver config_updateref;
139 static ConfigDriver config_extra_attrs;
140 static ConfigDriver config_include;
141 static ConfigDriver config_obsolete;
143 static ConfigDriver config_tls_option;
144 static ConfigDriver config_tls_config;
146 extern ConfigDriver syncrepl_config;
154 CFG_TLS_PROTOCOL_MIN,
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;
914 static ServerID *sid_set;
916 typedef struct voidList {
917 struct voidList *vl_next;
921 typedef struct ADlist {
922 struct ADlist *al_next;
923 AttributeDescription *al_desc;
926 static ADlist *sortVals;
929 config_generic(ConfigArgs *c) {
932 if ( c->op == SLAP_CONFIG_EMIT ) {
936 c->value_int = ldap_pvt_thread_get_concurrency();
939 c->value_int = connection_pool_max;
942 c->value_int = slap_tool_thread_max;
945 c->value_uint = slapd_daemon_threads;
949 c->value_string = ch_strdup( passwd_salt );
954 if ( c->be->be_limits ) {
958 for ( i=0; c->be->be_limits[i]; i++ ) {
959 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
960 if ( bv.bv_len >= sizeof( buf ) ) {
961 ber_bvarray_free_x( c->rvalue_vals, NULL );
962 c->rvalue_vals = NULL;
966 bv.bv_val = buf + bv.bv_len;
967 limits_unparse( c->be->be_limits[i], &bv,
968 sizeof( buf ) - ( bv.bv_val - buf ) );
969 bv.bv_len += bv.bv_val - buf;
971 value_add_one( &c->rvalue_vals, &bv );
974 if ( !c->rvalue_vals ) rc = 1;
977 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_READONLY);
980 c->value_string = ch_strdup( slap_sasl_getpolicy());
983 slap_sasl_regexp_unparse( &c->rvalue_vals );
984 if ( !c->rvalue_vals ) rc = 1;
986 #ifdef HAVE_CYRUS_SASL
987 #ifdef SLAP_AUXPROP_DONTUSECOPY
989 static int duc_done = 0;
991 /* take the opportunity to initialize with known values */
993 struct berval duc[] = { BER_BVC("cmusaslsecretOTP"), BER_BVNULL };
996 for ( i = 0; !BER_BVISNULL( &duc[ i ] ); i++ ) {
997 const char *text = NULL;
998 AttributeDescription *ad = NULL;
1000 if ( slap_bv2ad( &duc[ i ], &ad, &text ) == LDAP_SUCCESS ) {
1002 if ( slap_dontUseCopy_propnames ) {
1005 for ( j = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ j ] ); j++ ) {
1006 if ( bvmatch( &slap_dontUseCopy_propnames[ j ], &ad->ad_cname ) ) {
1013 value_add_one( &slap_dontUseCopy_propnames, &ad->ad_cname );
1021 if ( slap_dontUseCopy_propnames != NULL ) {
1022 ber_bvarray_dup_x( &c->rvalue_vals, slap_dontUseCopy_propnames, NULL );
1027 #endif /* SLAP_AUXPROP_DONTUSECOPY */
1028 case CFG_SASLSECP: {
1029 struct berval bv = BER_BVNULL;
1030 slap_sasl_secprops_unparse( &bv );
1031 if ( !BER_BVISNULL( &bv )) {
1032 ber_bvarray_add( &c->rvalue_vals, &bv );
1040 c->value_int = c->be->be_max_deref_depth;
1043 if ( SLAP_DBHIDDEN( c->be )) {
1050 ConfigFile *cf = c->ca_private;
1052 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1053 else if ( cf->c_om_head )
1054 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
1056 if ( !c->rvalue_vals )
1061 ad_unparse_options( &c->rvalue_vals );
1064 ConfigFile *cf = c->ca_private;
1066 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1067 else if ( cf->c_oc_head )
1068 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
1070 if ( !c->rvalue_vals )
1075 ConfigFile *cf = c->ca_private;
1077 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1078 else if ( cf->c_at_head )
1079 at_unparse( &c->rvalue_vals, cf->c_at_head,
1081 if ( !c->rvalue_vals )
1086 ConfigFile *cf = c->ca_private;
1088 syn_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1089 else if ( cf->c_syn_head )
1090 syn_unparse( &c->rvalue_vals, cf->c_syn_head,
1091 cf->c_syn_tail, 0 );
1092 if ( !c->rvalue_vals )
1097 ConfigFile *cf = c->ca_private;
1099 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1100 else if ( cf->c_cr_head )
1101 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
1103 if ( !c->rvalue_vals )
1110 char *src, *dst, ibuf[11];
1111 struct berval bv, abv;
1112 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
1113 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1114 if ( abv.bv_len >= sizeof( ibuf ) ) {
1115 ber_bvarray_free_x( c->rvalue_vals, NULL );
1116 c->rvalue_vals = NULL;
1120 acl_unparse( a, &bv );
1121 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
1122 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
1123 /* Turn TAB / EOL into plain space */
1124 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
1125 if (isspace((unsigned char)*src)) *dst++ = ' ';
1129 if (dst[-1] == ' ') {
1133 abv.bv_len = dst - abv.bv_val;
1134 ber_bvarray_add( &c->rvalue_vals, &abv );
1140 c->value_int = (SLAP_DBACL_ADD(c->be) != 0);
1143 ConfigFile *cf = c->ca_private;
1144 if ( cf->c_dseFiles ) {
1145 value_add( &c->rvalue_vals, cf->c_dseFiles );
1156 for ( si = sid_list; si; si=si->si_next ) {
1157 assert( si->si_num >= 0 && si->si_num <= SLAP_SYNC_SID_MAX );
1158 if ( !BER_BVISEMPTY( &si->si_url )) {
1159 bv.bv_len = si->si_url.bv_len + 6;
1160 bv.bv_val = ch_malloc( bv.bv_len );
1161 bv.bv_len = sprintf( bv.bv_val, "%d %s", si->si_num,
1162 si->si_url.bv_val );
1163 ber_bvarray_add( &c->rvalue_vals, &bv );
1167 bv.bv_len = sprintf( buf, "%d", si->si_num );
1168 value_add_one( &c->rvalue_vals, &bv );
1177 c->value_string = ch_strdup( logfileName );
1182 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1184 case CFG_SYNC_SUBENTRY:
1185 c->value_int = (SLAP_SYNC_SUBENTRY(c->be) != 0);
1187 case CFG_MIRRORMODE:
1188 if ( SLAP_SHADOW(c->be))
1189 c->value_int = (SLAP_MULTIMASTER(c->be) != 0);
1193 case CFG_MONITORING:
1194 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
1196 case CFG_SSTR_IF_MAX:
1197 c->value_uint = index_substr_if_maxlen;
1199 case CFG_SSTR_IF_MIN:
1200 c->value_uint = index_substr_if_minlen;
1203 c->value_int = index_intlen;
1205 case CFG_SORTVALS: {
1208 for ( sv = sortVals; sv; sv = sv->al_next ) {
1209 value_add_one( &c->rvalue_vals, &sv->al_desc->ad_cname );
1213 #ifdef SLAPD_MODULES
1215 ModPaths *mp = c->ca_private;
1218 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
1221 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
1222 SLAP_X_ORDERED_FMT "%s", i,
1223 mp->mp_loads[i].bv_val );
1224 if ( bv.bv_len >= sizeof( c->log ) ) {
1225 ber_bvarray_free_x( c->rvalue_vals, NULL );
1226 c->rvalue_vals = NULL;
1229 value_add_one( &c->rvalue_vals, &bv );
1233 rc = c->rvalue_vals ? 0 : 1;
1237 ModPaths *mp = c->ca_private;
1238 if ( !BER_BVISNULL( &mp->mp_path ))
1239 value_add_one( &c->rvalue_vals, &mp->mp_path );
1241 rc = c->rvalue_vals ? 0 : 1;
1247 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1248 if ( !c->rvalue_vals ) rc = 1;
1251 #ifdef SLAP_AUTH_REWRITE
1253 if ( authz_rewrites ) {
1254 struct berval bv, idx;
1259 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1260 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1261 if ( idx.bv_len >= sizeof( ibuf ) ) {
1262 ber_bvarray_free_x( c->rvalue_vals, NULL );
1263 c->rvalue_vals = NULL;
1266 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1267 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1268 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1269 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1270 authz_rewrites[i].bv_val,
1271 authz_rewrites[i].bv_len + 1 );
1272 ber_bvarray_add( &c->rvalue_vals, &bv );
1275 if ( !c->rvalue_vals ) rc = 1;
1282 } else if ( c->op == LDAP_MOD_DELETE ) {
1285 /* single-valued attrs, no-ops */
1294 case CFG_MONITORING:
1296 case CFG_SSTR_IF_MAX:
1297 case CFG_SSTR_IF_MIN:
1299 case CFG_SYNC_SUBENTRY:
1302 /* no-ops, requires slapd restart */
1307 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1310 case CFG_MIRRORMODE:
1311 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MULTI_SHADOW;
1312 if(SLAP_SHADOW(c->be))
1313 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1316 #if defined(HAVE_CYRUS_SASL) && defined(SLAP_AUXPROP_DONTUSECOPY)
1318 if ( c->valx < 0 ) {
1319 if ( slap_dontUseCopy_propnames != NULL ) {
1320 ber_bvarray_free( slap_dontUseCopy_propnames );
1321 slap_dontUseCopy_propnames = NULL;
1327 if ( slap_dontUseCopy_propnames == NULL ) {
1332 for ( i = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ i ] ) && i < c->valx; i++ );
1333 if ( i < c->valx ) {
1337 ber_memfree( slap_dontUseCopy_propnames[ i ].bv_val );
1338 for ( ; !BER_BVISNULL( &slap_dontUseCopy_propnames[ i + 1 ] ); i++ ) {
1339 slap_dontUseCopy_propnames[ i ] = slap_dontUseCopy_propnames[ i + 1 ];
1341 BER_BVZERO( &slap_dontUseCopy_propnames[ i ] );
1344 #endif /* SLAP_AUXPROP_DONTUSECOPY */
1346 ch_free( passwd_salt );
1351 ch_free( logfileName );
1359 case CFG_SERVERID: {
1360 ServerID *si, **sip;
1362 for ( i=0, si = sid_list, sip = &sid_list;
1363 si; si = *sip, i++ ) {
1364 if ( c->valx == -1 || i == c->valx ) {
1366 if ( sid_set == si )
1378 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1382 index_intlen = SLAP_INDEX_INTLEN_DEFAULT;
1383 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1384 SLAP_INDEX_INTLEN_DEFAULT );
1388 if ( c->valx < 0 ) {
1389 acl_destroy( c->be->be_acl );
1390 c->be->be_acl = NULL;
1393 AccessControl **prev, *a;
1395 for (i=0, prev = &c->be->be_acl; i < c->valx;
1398 prev = &a->acl_next;
1401 *prev = a->acl_next;
1404 if ( SLAP_CONFIG( c->be ) && !c->be->be_acl ) {
1405 Debug( LDAP_DEBUG_CONFIG, "config_generic (CFG_ACL): "
1406 "Last explicit ACL for back-config removed. "
1407 "Using hardcoded default\n", 0, 0, 0 );
1408 c->be->be_acl = defacl_parsed;
1414 /* Can be NULL when undoing a failed add */
1415 if ( c->ca_entry ) {
1416 ce = c->ca_entry->e_private;
1417 /* can't modify the hardcoded schema */
1418 if ( ce->ce_parent->ce_type == Cft_Global )
1422 cfn = c->ca_private;
1423 if ( c->valx < 0 ) {
1426 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1428 if ( oc == cfn->c_oc_tail )
1431 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1433 ObjectClass *oc, *prev = NULL;
1435 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1440 if ( cfn->c_oc_tail == oc ) {
1441 cfn->c_oc_tail = prev;
1443 if ( cfn->c_oc_head == oc ) {
1445 cfn->c_oc_head = oc;
1452 /* Can be NULL when undoing a failed add */
1453 if ( c->ca_entry ) {
1454 ce = c->ca_entry->e_private;
1455 /* can't modify the hardcoded schema */
1456 if ( ce->ce_parent->ce_type == Cft_Global )
1460 cfn = c->ca_private;
1461 if ( c->valx < 0 ) {
1464 for( at = cfn->c_at_head; at; at_next( &at )) {
1466 if ( at == cfn->c_at_tail )
1469 cfn->c_at_head = cfn->c_at_tail = NULL;
1471 AttributeType *at, *prev = NULL;
1473 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1478 if ( cfn->c_at_tail == at ) {
1479 cfn->c_at_tail = prev;
1481 if ( cfn->c_at_head == at ) {
1483 cfn->c_at_head = at;
1490 /* Can be NULL when undoing a failed add */
1491 if ( c->ca_entry ) {
1492 ce = c->ca_entry->e_private;
1493 /* can't modify the hardcoded schema */
1494 if ( ce->ce_parent->ce_type == Cft_Global )
1498 cfn = c->ca_private;
1499 if ( c->valx < 0 ) {
1502 for( syn = cfn->c_syn_head; syn; syn_next( &syn )) {
1504 if ( syn == cfn->c_syn_tail )
1507 cfn->c_syn_head = cfn->c_syn_tail = NULL;
1509 Syntax *syn, *prev = NULL;
1511 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++) {
1516 if ( cfn->c_syn_tail == syn ) {
1517 cfn->c_syn_tail = prev;
1519 if ( cfn->c_syn_head == syn ) {
1521 cfn->c_syn_head = syn;
1526 if ( c->valx < 0 ) {
1528 for ( sv = sortVals; sv; sv = sortVals ) {
1529 sortVals = sv->al_next;
1530 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1537 for ( prev = &sortVals, sv = sortVals; i < c->valx; i++ ) {
1538 prev = &sv->al_next;
1541 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1542 *prev = sv->al_next;
1548 /* FIXME: there is no limits_free function */
1549 if ( c->valx < 0 ) {
1550 limits_destroy( c->be->be_limits );
1551 c->be->be_limits = NULL;
1556 if ( c->be->be_limits ) {
1557 for ( num = 0; c->be->be_limits[ num ]; num++ )
1561 if ( c->valx >= num ) {
1566 limits_destroy( c->be->be_limits );
1567 c->be->be_limits = NULL;
1570 limits_free_one( c->be->be_limits[ c->valx ] );
1572 for ( cnt = c->valx; cnt < num; cnt++ ) {
1573 c->be->be_limits[ cnt ] = c->be->be_limits[ cnt + 1 ];
1580 /* FIXME: there is no ad_option_free function */
1582 /* FIXME: there is no way to remove attributes added by
1596 if(!(c->bi = backend_info(c->argv[1]))) {
1597 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1598 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1599 c->log, c->cr_msg, c->argv[1] );
1606 /* NOTE: config is always the first backend!
1608 if ( !strcasecmp( c->argv[1], "config" )) {
1609 c->be = LDAP_STAILQ_FIRST(&backendDB);
1610 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1613 c->be = backend_db_init(c->argv[1], NULL, c->valx, &c->reply);
1615 if ( c->cr_msg[0] == 0 )
1616 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1617 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n", c->log, c->cr_msg, c->argv[1] );
1624 ldap_pvt_thread_set_concurrency(c->value_int);
1628 if ( c->value_int < 2 ) {
1629 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1630 "threads=%d smaller than minimum value 2",
1632 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1633 c->log, c->cr_msg, 0 );
1636 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1637 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1638 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1639 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1640 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1641 c->log, c->cr_msg, 0 );
1643 if ( slapMode & SLAP_SERVER_MODE )
1644 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1645 connection_pool_max = c->value_int; /* save for reference */
1649 if ( slapMode & SLAP_TOOL_MODE )
1650 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1651 slap_tool_thread_max = c->value_int; /* save for reference */
1656 /* use a power of two */
1657 while (c->value_uint > 1) {
1658 c->value_uint >>= 1;
1662 slapd_daemon_mask = mask;
1663 slapd_daemon_threads = mask+1;
1668 if ( passwd_salt ) ch_free( passwd_salt );
1669 passwd_salt = c->value_string;
1670 lutil_salt_format(passwd_salt);
1674 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1680 c->be->be_restrictops |= SLAP_RESTRICT_READONLY;
1682 c->be->be_restrictops &= ~SLAP_RESTRICT_READONLY;
1686 ch_free(c->value_string);
1687 if (slap_sasl_setpolicy( c->argv[1] )) {
1688 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
1689 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1690 c->log, c->cr_msg, c->argv[1] );
1696 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1700 #ifdef HAVE_CYRUS_SASL
1701 #ifdef SLAP_AUXPROP_DONTUSECOPY
1705 for ( arg = 1; arg < c->argc; arg++ ) {
1706 int duplicate = 0, err;
1707 AttributeDescription *ad = NULL;
1708 const char *text = NULL;
1710 err = slap_str2ad( c->argv[ arg ], &ad, &text );
1711 if ( err != LDAP_SUCCESS ) {
1712 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s>: attr #%d (\"%s\") unknown (err=%d \"%s\"; ignored)",
1713 c->argv[0], arg, c->argv[ arg ], err, text );
1714 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1715 c->log, c->cr_msg, 0 );
1718 if ( slap_dontUseCopy_propnames != NULL ) {
1719 for ( cnt = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ cnt ] ); cnt++ ) {
1720 if ( bvmatch( &slap_dontUseCopy_propnames[ cnt ], &ad->ad_cname ) ) {
1728 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s>: attr #%d (\"%s\") already defined (ignored)",
1729 c->argv[0], arg, ad->ad_cname.bv_val);
1730 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1731 c->log, c->cr_msg, 0 );
1735 value_add_one( &slap_dontUseCopy_propnames, &ad->ad_cname );
1740 #endif /* SLAP_AUXPROP_DONTUSECOPY */
1744 char *txt = slap_sasl_secprops( c->argv[1] );
1746 snprintf( c->cr_msg, sizeof(c->cr_msg), "<%s> %s",
1748 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0 );
1756 c->be->be_max_deref_depth = c->value_int;
1762 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1763 cfn = c->ca_private;
1764 if(parse_oidm(c, 1, &om))
1766 if (!cfn->c_om_head) cfn->c_om_head = om;
1767 cfn->c_om_tail = om;
1772 ObjectClass *oc, *prev;
1774 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1775 cfn = c->ca_private;
1776 if ( c->valx < 0 ) {
1777 prev = cfn->c_oc_tail;
1780 /* If adding anything after the first, prev is easy */
1783 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
1785 if ( !oc_next( &oc ))
1789 /* If adding the first, and head exists, find its prev */
1790 if (cfn->c_oc_head) {
1791 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
1796 /* else prev is NULL, append to end of global list */
1798 if(parse_oc(c, &oc, prev)) return(1);
1799 if (!cfn->c_oc_head || !c->valx) cfn->c_oc_head = oc;
1800 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
1805 AttributeType *at, *prev;
1807 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1808 cfn = c->ca_private;
1809 if ( c->valx < 0 ) {
1810 prev = cfn->c_at_tail;
1813 /* If adding anything after the first, prev is easy */
1816 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
1818 if ( !at_next( &at ))
1822 /* If adding the first, and head exists, find its prev */
1823 if (cfn->c_at_head) {
1824 for ( at_start( &at ); at != cfn->c_at_head; ) {
1829 /* else prev is NULL, append to end of global list */
1831 if(parse_at(c, &at, prev)) return(1);
1832 if (!cfn->c_at_head || !c->valx) cfn->c_at_head = at;
1833 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
1840 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1841 cfn = c->ca_private;
1842 if ( c->valx < 0 ) {
1843 prev = cfn->c_syn_tail;
1846 /* If adding anything after the first, prev is easy */
1849 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++ ) {
1851 if ( !syn_next( &syn ))
1855 /* If adding the first, and head exists, find its prev */
1856 if (cfn->c_syn_head) {
1857 for ( syn_start( &syn ); syn != cfn->c_syn_head; ) {
1862 /* else prev is NULL, append to end of global list */
1864 if ( parse_syn( c, &syn, prev ) ) return(1);
1865 if ( !cfn->c_syn_head || !c->valx ) cfn->c_syn_head = syn;
1866 if ( cfn->c_syn_tail == prev ) cfn->c_syn_tail = syn;
1873 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1874 cfn = c->ca_private;
1875 if(parse_cr(c, &cr)) return(1);
1876 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1877 cfn->c_cr_tail = cr;
1882 ad_define_option(NULL, NULL, 0);
1883 for(i = 1; i < c->argc; i++)
1884 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1889 if ( c->value_int < SLAP_INDEX_INTLEN_DEFAULT )
1890 c->value_int = SLAP_INDEX_INTLEN_DEFAULT;
1891 else if ( c->value_int > 255 )
1893 index_intlen = c->value_int;
1894 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1898 case CFG_SORTVALS: {
1899 ADlist *svnew = NULL, *svtail, *sv;
1901 for ( i = 1; i < c->argc; i++ ) {
1902 AttributeDescription *ad = NULL;
1906 rc = slap_str2ad( c->argv[i], &ad, &text );
1908 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown attribute type #%d",
1911 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1912 c->log, c->cr_msg, c->argv[i] );
1913 for ( sv = svnew; sv; sv = svnew ) {
1914 svnew = sv->al_next;
1919 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) ||
1920 ad->ad_type->sat_single_value ) {
1921 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> inappropriate attribute type #%d",
1923 goto sortval_reject;
1925 sv = ch_malloc( sizeof( ADlist ));
1930 svtail->al_next = sv;
1935 for ( sv = svnew; sv; sv = sv->al_next )
1936 sv->al_desc->ad_type->sat_flags |= SLAP_AT_SORTED_VAL;
1937 for ( sv = sortVals; sv && sv->al_next; sv = sv->al_next );
1939 sv->al_next = svnew;
1946 if ( SLAP_CONFIG( c->be ) && c->be->be_acl == defacl_parsed) {
1947 c->be->be_acl = NULL;
1949 /* Don't append to the global ACL if we're on a specific DB */
1951 if ( c->valx == -1 ) {
1954 for ( a=c->be->be_acl; a; a = a->acl_next )
1957 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
1958 if ( SLAP_CONFIG( c->be ) && !c->be->be_acl) {
1959 c->be->be_acl = defacl_parsed;
1967 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_ACL_ADD;
1969 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_ACL_ADD;
1973 if(root_dse_read_file(c->argv[1])) {
1974 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> could not read file", c->argv[0] );
1975 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1976 c->log, c->cr_msg, c->argv[1] );
1981 ber_str2bv( c->argv[1], 0, 1, &bv );
1982 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1983 cfn = c->ca_private;
1984 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1990 ServerID *si, **sip;
1993 if (( lutil_atoi( &num, c->argv[1] ) &&
1994 lutil_atoix( &num, c->argv[1], 16 )) ||
1995 num < 0 || num > SLAP_SYNC_SID_MAX )
1997 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1998 "<%s> illegal server ID", c->argv[0] );
1999 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2000 c->log, c->cr_msg, c->argv[1] );
2003 /* only one value allowed if no URL is given */
2004 if ( c->argc > 2 ) {
2007 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
2008 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2009 "<%s> only one server ID allowed now", c->argv[0] );
2010 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2011 c->log, c->cr_msg, c->argv[1] );
2015 if ( ldap_url_parse( c->argv[2], &lud )) {
2016 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2017 "<%s> invalid URL", c->argv[0] );
2018 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2019 c->log, c->cr_msg, c->argv[2] );
2022 len = strlen( c->argv[2] );
2023 si = ch_malloc( sizeof(ServerID) + len + 1 );
2024 si->si_url.bv_val = (char *)(si+1);
2025 si->si_url.bv_len = len;
2026 strcpy( si->si_url.bv_val, c->argv[2] );
2029 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2030 "<%s> unqualified server ID not allowed now", c->argv[0] );
2031 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2032 c->log, c->cr_msg, c->argv[1] );
2035 si = ch_malloc( sizeof(ServerID) );
2036 BER_BVZERO( &si->si_url );
2037 slap_serverID = num;
2038 Debug( LDAP_DEBUG_CONFIG,
2040 c->log, slap_serverID, 0 );
2045 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
2048 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
2049 Listener *l = config_check_my_url( c->argv[2], lud );
2052 ldap_free_urldesc( lud );
2053 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2054 "<%s> multiple server ID URLs matched, only one is allowed", c->argv[0] );
2055 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2056 c->log, c->cr_msg, c->argv[1] );
2059 slap_serverID = si->si_num;
2060 Debug( LDAP_DEBUG_CONFIG,
2061 "%s: SID=0x%03x (listener=%s)\n",
2062 c->log, slap_serverID,
2068 ldap_free_urldesc( lud );
2072 if ( logfileName ) ch_free( logfileName );
2073 logfileName = c->value_string;
2074 logfile = fopen(logfileName, "w");
2075 if(logfile) lutil_debug_file(logfile);
2079 if(SLAP_NOLASTMODCMD(c->be)) {
2080 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> not available for %s database",
2081 c->argv[0], c->be->bd_info->bi_type );
2082 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2083 c->log, c->cr_msg, 0 );
2087 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
2089 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
2092 case CFG_MIRRORMODE:
2093 if(c->value_int && !SLAP_SHADOW(c->be)) {
2094 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database is not a shadow",
2096 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2097 c->log, c->cr_msg, 0 );
2101 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
2102 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MULTI_SHADOW;
2104 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
2105 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MULTI_SHADOW;
2109 case CFG_MONITORING:
2111 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
2113 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
2118 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
2120 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
2123 case CFG_SYNC_SUBENTRY:
2125 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SYNC_SUBENTRY;
2127 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SYNC_SUBENTRY;
2130 case CFG_SSTR_IF_MAX:
2131 if (c->value_uint < index_substr_if_minlen) {
2132 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
2133 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
2134 c->log, c->cr_msg, c->value_int );
2137 index_substr_if_maxlen = c->value_uint;
2140 case CFG_SSTR_IF_MIN:
2141 if (c->value_uint > index_substr_if_maxlen) {
2142 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
2143 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
2144 c->log, c->cr_msg, c->value_int );
2147 index_substr_if_minlen = c->value_uint;
2150 #ifdef SLAPD_MODULES
2152 /* If we're just adding a module on an existing modpath,
2153 * make sure we've selected the current path.
2155 if ( c->op == LDAP_MOD_ADD && c->ca_private && modcur != c->ca_private ) {
2156 modcur = c->ca_private;
2157 /* This should never fail */
2158 if ( module_path( modcur->mp_path.bv_val )) {
2159 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> module path no longer valid",
2161 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2162 c->log, c->cr_msg, modcur->mp_path.bv_val );
2166 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
2168 /* Record this load on the current path */
2172 if ( c->op == SLAP_CONFIG_ADD ) {
2173 ptr = c->line + STRLENOF("moduleload");
2174 while (!isspace((unsigned char) *ptr)) ptr++;
2175 while (isspace((unsigned char) *ptr)) ptr++;
2179 ber_str2bv(ptr, 0, 1, &bv);
2180 ber_bvarray_add( &modcur->mp_loads, &bv );
2182 /* Check for any new hardcoded schema */
2183 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
2184 config_check_schema( NULL, &cfBackInfo );
2189 if(module_path(c->argv[1])) return(1);
2190 /* Record which path was used with each module */
2194 if (!modpaths.mp_loads) {
2197 mp = ch_malloc( sizeof( ModPaths ));
2198 modlast->mp_next = mp;
2200 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
2202 mp->mp_loads = NULL;
2213 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
2215 slapi_plugins_used++;
2219 #ifdef SLAP_AUTH_REWRITE
2225 if ( c->op == LDAP_MOD_ADD ) {
2229 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
2233 if ( c->argc > 1 ) {
2236 /* quote all args but the first */
2237 line = ldap_charray2str( c->argv, "\" \"" );
2238 ber_str2bv( line, 0, 0, &bv );
2239 s = ber_bvchr( &bv, '"' );
2240 assert( s != NULL );
2241 /* move the trailing quote of argv[0] to the end */
2242 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
2243 bv.bv_val[ bv.bv_len - 1 ] = '"';
2246 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
2249 ber_bvarray_add( &authz_rewrites, &bv );
2251 if ( c->op == LDAP_MOD_ADD ) {
2261 Debug( LDAP_DEBUG_ANY,
2262 "%s: unknown CFG_TYPE %d.\n",
2263 c->log, c->type, 0 );
2272 config_fname(ConfigArgs *c) {
2273 if(c->op == SLAP_CONFIG_EMIT) {
2274 if (c->ca_private) {
2275 ConfigFile *cf = c->ca_private;
2276 value_add_one( &c->rvalue_vals, &cf->c_file );
2285 config_cfdir(ConfigArgs *c) {
2286 if(c->op == SLAP_CONFIG_EMIT) {
2287 if ( !BER_BVISEMPTY( &cfdir )) {
2288 value_add_one( &c->rvalue_vals, &cfdir );
2297 config_search_base(ConfigArgs *c) {
2298 if(c->op == SLAP_CONFIG_EMIT) {
2300 if (!BER_BVISEMPTY(&default_search_base)) {
2301 value_add_one(&c->rvalue_vals, &default_search_base);
2302 value_add_one(&c->rvalue_nvals, &default_search_nbase);
2306 } else if( c->op == LDAP_MOD_DELETE ) {
2307 ch_free( default_search_base.bv_val );
2308 ch_free( default_search_nbase.bv_val );
2309 BER_BVZERO( &default_search_base );
2310 BER_BVZERO( &default_search_nbase );
2314 if(c->bi || c->be != frontendDB) {
2315 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
2316 "prior to any backend or database definition\n",
2321 if(default_search_nbase.bv_len) {
2322 free(default_search_base.bv_val);
2323 free(default_search_nbase.bv_val);
2326 default_search_base = c->value_dn;
2327 default_search_nbase = c->value_ndn;
2331 /* For RE23 compatibility we allow this in the global entry
2332 * but we now defer it to the frontend entry to allow modules
2333 * to load new hash types.
2336 config_passwd_hash(ConfigArgs *c) {
2338 if (c->op == SLAP_CONFIG_EMIT) {
2340 /* Don't generate it in the global entry */
2341 if ( c->table == Cft_Global )
2343 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
2344 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
2345 value_add_one(&c->rvalue_vals, &bv);
2348 } else if ( c->op == LDAP_MOD_DELETE ) {
2349 /* Deleting from global is a no-op, only the frontendDB entry matters */
2350 if ( c->table == Cft_Global )
2352 if ( c->valx < 0 ) {
2353 ldap_charray_free( default_passwd_hash );
2354 default_passwd_hash = NULL;
2357 ch_free( default_passwd_hash[i] );
2358 for (; default_passwd_hash[i]; i++ )
2359 default_passwd_hash[i] = default_passwd_hash[i+1];
2363 for(i = 1; i < c->argc; i++) {
2364 if(!lutil_passwd_scheme(c->argv[i])) {
2365 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> scheme not available", c->argv[0] );
2366 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2367 c->log, c->cr_msg, c->argv[i]);
2369 ldap_charray_add(&default_passwd_hash, c->argv[i]);
2372 if(!default_passwd_hash) {
2373 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> no valid hashes found", c->argv[0] );
2374 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2375 c->log, c->cr_msg, 0 );
2382 config_schema_dn(ConfigArgs *c) {
2383 if ( c->op == SLAP_CONFIG_EMIT ) {
2385 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
2386 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
2387 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
2391 } else if ( c->op == LDAP_MOD_DELETE ) {
2392 ch_free( c->be->be_schemadn.bv_val );
2393 ch_free( c->be->be_schemandn.bv_val );
2394 BER_BVZERO( &c->be->be_schemadn );
2395 BER_BVZERO( &c->be->be_schemandn );
2398 ch_free( c->be->be_schemadn.bv_val );
2399 ch_free( c->be->be_schemandn.bv_val );
2400 c->be->be_schemadn = c->value_dn;
2401 c->be->be_schemandn = c->value_ndn;
2406 config_sizelimit(ConfigArgs *c) {
2408 struct slap_limits_set *lim = &c->be->be_def_limit;
2409 if (c->op == SLAP_CONFIG_EMIT) {
2414 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
2415 if ( !BER_BVISEMPTY( &bv ))
2416 value_add_one( &c->rvalue_vals, &bv );
2420 } else if ( c->op == LDAP_MOD_DELETE ) {
2421 /* Reset to defaults or values from frontend */
2422 if ( c->be == frontendDB ) {
2423 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
2424 lim->lms_s_hard = 0;
2425 lim->lms_s_unchecked = -1;
2427 lim->lms_s_pr_hide = 0;
2428 lim->lms_s_pr_total = 0;
2430 lim->lms_s_soft = frontendDB->be_def_limit.lms_s_soft;
2431 lim->lms_s_hard = frontendDB->be_def_limit.lms_s_hard;
2432 lim->lms_s_unchecked = frontendDB->be_def_limit.lms_s_unchecked;
2433 lim->lms_s_pr = frontendDB->be_def_limit.lms_s_pr;
2434 lim->lms_s_pr_hide = frontendDB->be_def_limit.lms_s_pr_hide;
2435 lim->lms_s_pr_total = frontendDB->be_def_limit.lms_s_pr_total;
2439 for(i = 1; i < c->argc; i++) {
2440 if(!strncasecmp(c->argv[i], "size", 4)) {
2441 rc = limits_parse_one(c->argv[i], lim);
2443 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2444 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2445 c->log, c->cr_msg, c->argv[i]);
2449 if(!strcasecmp(c->argv[i], "unlimited")) {
2450 lim->lms_s_soft = -1;
2452 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
2453 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2454 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2455 c->log, c->cr_msg, c->argv[i]);
2459 lim->lms_s_hard = 0;
2464 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2465 /* This is a modification to the global limits apply it to
2466 * the other databases as needed */
2467 AttributeDescription *ad=NULL;
2468 const char *text = NULL;
2469 CfEntryInfo *ce = c->ca_entry->e_private;
2471 slap_str2ad(c->argv[0], &ad, &text);
2472 /* if we got here... */
2473 assert( ad != NULL );
2475 if ( ce->ce_type == Cft_Global ){
2478 for (; ce; ce=ce->ce_sibs) {
2479 Entry *dbe = ce->ce_entry;
2480 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2481 && (!attr_find(dbe->e_attrs, ad)) ) {
2482 ce->ce_be->be_def_limit.lms_s_soft = lim->lms_s_soft;
2483 ce->ce_be->be_def_limit.lms_s_hard = lim->lms_s_hard;
2484 ce->ce_be->be_def_limit.lms_s_unchecked =lim->lms_s_unchecked;
2485 ce->ce_be->be_def_limit.lms_s_pr =lim->lms_s_pr;
2486 ce->ce_be->be_def_limit.lms_s_pr_hide =lim->lms_s_pr_hide;
2487 ce->ce_be->be_def_limit.lms_s_pr_total =lim->lms_s_pr_total;
2495 config_timelimit(ConfigArgs *c) {
2497 struct slap_limits_set *lim = &c->be->be_def_limit;
2498 if (c->op == SLAP_CONFIG_EMIT) {
2503 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
2504 if ( !BER_BVISEMPTY( &bv ))
2505 value_add_one( &c->rvalue_vals, &bv );
2509 } else if ( c->op == LDAP_MOD_DELETE ) {
2510 /* Reset to defaults or values from frontend */
2511 if ( c->be == frontendDB ) {
2512 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
2513 lim->lms_t_hard = 0;
2515 lim->lms_t_soft = frontendDB->be_def_limit.lms_t_soft;
2516 lim->lms_t_hard = frontendDB->be_def_limit.lms_t_hard;
2520 for(i = 1; i < c->argc; i++) {
2521 if(!strncasecmp(c->argv[i], "time", 4)) {
2522 rc = limits_parse_one(c->argv[i], lim);
2524 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2525 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2526 c->log, c->cr_msg, c->argv[i]);
2530 if(!strcasecmp(c->argv[i], "unlimited")) {
2531 lim->lms_t_soft = -1;
2533 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
2534 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2535 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2536 c->log, c->cr_msg, c->argv[i]);
2540 lim->lms_t_hard = 0;
2545 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2546 /* This is a modification to the global limits apply it to
2547 * the other databases as needed */
2548 AttributeDescription *ad=NULL;
2549 const char *text = NULL;
2550 CfEntryInfo *ce = c->ca_entry->e_private;
2552 slap_str2ad(c->argv[0], &ad, &text);
2553 /* if we got here... */
2554 assert( ad != NULL );
2556 if ( ce->ce_type == Cft_Global ){
2559 for (; ce; ce=ce->ce_sibs) {
2560 Entry *dbe = ce->ce_entry;
2561 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2562 && (!attr_find(dbe->e_attrs, ad)) ) {
2563 ce->ce_be->be_def_limit.lms_t_soft = lim->lms_t_soft;
2564 ce->ce_be->be_def_limit.lms_t_hard = lim->lms_t_hard;
2572 config_overlay(ConfigArgs *c) {
2573 if (c->op == SLAP_CONFIG_EMIT) {
2575 } else if ( c->op == LDAP_MOD_DELETE ) {
2578 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2579 c->valx, &c->bi, &c->reply)) {
2581 Debug( LDAP_DEBUG_ANY,
2582 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2583 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2585 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi, &c->reply)) {
2592 config_subordinate(ConfigArgs *c)
2598 case SLAP_CONFIG_EMIT:
2599 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2602 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2603 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2606 value_add_one( &c->rvalue_vals, &bv );
2610 case LDAP_MOD_DELETE:
2611 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2612 glue_sub_del( c->be );
2614 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2619 case SLAP_CONFIG_ADD:
2620 if ( c->be->be_nsuffix == NULL ) {
2622 snprintf( c->cr_msg, sizeof( c->cr_msg),
2623 "subordinate configuration needs a suffix" );
2624 Debug( LDAP_DEBUG_ANY,
2626 c->log, c->cr_msg, 0 );
2631 if ( c->argc == 2 ) {
2632 if ( strcasecmp( c->argv[1], "advertise" ) == 0 ) {
2635 } else if ( strcasecmp( c->argv[1], "TRUE" ) != 0 ) {
2637 snprintf( c->cr_msg, sizeof( c->cr_msg),
2638 "subordinate must be \"TRUE\" or \"advertise\"" );
2639 Debug( LDAP_DEBUG_ANY,
2640 "%s: suffix \"%s\": %s.\n",
2641 c->log, c->be->be_suffix[0].bv_val, c->cr_msg );
2647 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2655 * [listener=<listener>] [{read|write}=]<size>
2658 #ifdef LDAP_TCP_BUFFER
2659 static BerVarray tcp_buffer;
2662 #define SLAP_TCP_RMEM (0x1U)
2663 #define SLAP_TCP_WMEM (0x2U)
2666 tcp_buffer_parse( struct berval *val, int argc, char **argv,
2667 int *size, int *rw, Listener **l )
2669 int i, rc = LDAP_SUCCESS;
2670 LDAPURLDesc *lud = NULL;
2673 if ( val != NULL && argv == NULL ) {
2674 char *s = val->bv_val;
2676 argv = ldap_str2charray( s, " \t" );
2677 if ( argv == NULL ) {
2683 if ( strncasecmp( argv[ i ], "listener=", STRLENOF( "listener=" ) )
2686 char *url = argv[ i ] + STRLENOF( "listener=" );
2688 if ( ldap_url_parse( url, &lud ) ) {
2689 rc = LDAP_INVALID_SYNTAX;
2693 *l = config_check_my_url( url, lud );
2695 rc = LDAP_NO_SUCH_ATTRIBUTE;
2703 if ( strncasecmp( ptr, "read=", STRLENOF( "read=" ) ) == 0 ) {
2704 *rw |= SLAP_TCP_RMEM;
2705 ptr += STRLENOF( "read=" );
2707 } else if ( strncasecmp( ptr, "write=", STRLENOF( "write=" ) ) == 0 ) {
2708 *rw |= SLAP_TCP_WMEM;
2709 ptr += STRLENOF( "write=" );
2712 *rw |= ( SLAP_TCP_RMEM | SLAP_TCP_WMEM );
2715 /* accept any base */
2716 if ( lutil_atoix( size, ptr, 0 ) ) {
2717 rc = LDAP_INVALID_SYNTAX;
2722 if ( val != NULL && argv != NULL ) {
2723 ldap_charray_free( argv );
2726 if ( lud != NULL ) {
2727 ldap_free_urldesc( lud );
2734 tcp_buffer_delete_one( struct berval *val )
2737 int size = -1, rw = 0;
2740 rc = tcp_buffer_parse( val, 0, NULL, &size, &rw, &l );
2747 Listener **ll = slapd_get_listeners();
2749 for ( i = 0; ll[ i ] != NULL; i++ ) {
2750 if ( ll[ i ] == l ) break;
2753 if ( ll[ i ] == NULL ) {
2754 return LDAP_NO_SUCH_ATTRIBUTE;
2757 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = -1;
2758 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = -1;
2760 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2761 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = -1;
2762 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = -1;
2766 /* NOTE: this affects listeners without a specific setting,
2767 * does not reset all listeners. If a listener without
2768 * specific settings was assigned a buffer because of
2769 * a global setting, it will not be reset. In any case,
2770 * buffer changes will only take place at restart. */
2771 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = -1;
2772 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = -1;
2779 tcp_buffer_delete( BerVarray vals )
2783 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
2784 tcp_buffer_delete_one( &vals[ i ] );
2791 tcp_buffer_unparse( int size, int rw, Listener *l, struct berval *val )
2793 char buf[sizeof("2147483648")], *ptr;
2795 /* unparse for later use */
2796 val->bv_len = snprintf( buf, sizeof( buf ), "%d", size );
2798 val->bv_len += STRLENOF( "listener=" " " ) + l->sl_url.bv_len;
2801 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2802 if ( rw & SLAP_TCP_RMEM ) {
2803 val->bv_len += STRLENOF( "read=" );
2804 } else if ( rw & SLAP_TCP_WMEM ) {
2805 val->bv_len += STRLENOF( "write=" );
2809 val->bv_val = SLAP_MALLOC( val->bv_len + 1 );
2814 ptr = lutil_strcopy( ptr, "listener=" );
2815 ptr = lutil_strncopy( ptr, l->sl_url.bv_val, l->sl_url.bv_len );
2819 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2820 if ( rw & SLAP_TCP_RMEM ) {
2821 ptr = lutil_strcopy( ptr, "read=" );
2822 } else if ( rw & SLAP_TCP_WMEM ) {
2823 ptr = lutil_strcopy( ptr, "write=" );
2827 ptr = lutil_strcopy( ptr, buf );
2830 assert( val->bv_val + val->bv_len == ptr );
2832 return LDAP_SUCCESS;
2836 tcp_buffer_add_one( int argc, char **argv )
2839 int size = -1, rw = 0;
2845 rc = tcp_buffer_parse( NULL, argc, argv, &size, &rw, &l );
2850 /* unparse for later use */
2851 rc = tcp_buffer_unparse( size, rw, l, &val );
2852 if ( rc != LDAP_SUCCESS ) {
2856 /* use parsed values */
2859 Listener **ll = slapd_get_listeners();
2861 for ( i = 0; ll[ i ] != NULL; i++ ) {
2862 if ( ll[ i ] == l ) break;
2865 if ( ll[ i ] == NULL ) {
2866 return LDAP_NO_SUCH_ATTRIBUTE;
2869 /* buffer only applies to TCP listeners;
2870 * we do not do any check here, and delegate them
2871 * to setsockopt(2) */
2872 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = size;
2873 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = size;
2875 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2876 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = size;
2877 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = size;
2881 /* NOTE: this affects listeners without a specific setting,
2882 * does not set all listeners */
2883 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = size;
2884 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = size;
2887 tcp_buffer = SLAP_REALLOC( tcp_buffer, sizeof( struct berval ) * ( tcp_buffer_num + 2 ) );
2889 tcp_buffer[ tcp_buffer_num ] = val;
2892 BER_BVZERO( &tcp_buffer[ tcp_buffer_num ] );
2898 config_tcp_buffer( ConfigArgs *c )
2900 if ( c->op == SLAP_CONFIG_EMIT ) {
2901 if ( tcp_buffer == NULL || BER_BVISNULL( &tcp_buffer[ 0 ] ) ) {
2904 value_add( &c->rvalue_vals, tcp_buffer );
2905 value_add( &c->rvalue_nvals, tcp_buffer );
2907 } else if ( c->op == LDAP_MOD_DELETE ) {
2909 tcp_buffer_delete( tcp_buffer );
2910 ber_bvarray_free( tcp_buffer );
2916 int size = -1, rw = 0;
2919 struct berval val = BER_BVNULL;
2923 if ( tcp_buffer_num == 0 ) {
2928 rc = tcp_buffer_parse( NULL, c->argc - 1, &c->argv[ 1 ], &size, &rw, &l );
2933 /* unparse for later use */
2934 rc = tcp_buffer_unparse( size, rw, l, &val );
2935 if ( rc != LDAP_SUCCESS ) {
2939 for ( i = 0; !BER_BVISNULL( &tcp_buffer[ i ] ); i++ ) {
2940 if ( bvmatch( &tcp_buffer[ i ], &val ) ) {
2945 if ( BER_BVISNULL( &tcp_buffer[ i ] ) ) {
2951 tcp_buffer_delete_one( &tcp_buffer[ i ] );
2952 ber_memfree( tcp_buffer[ i ].bv_val );
2953 for ( ; i < tcp_buffer_num; i++ ) {
2954 tcp_buffer[ i ] = tcp_buffer[ i + 1 ];
2959 if ( !BER_BVISNULL( &val ) ) {
2960 SLAP_FREE( val.bv_val );
2968 rc = tcp_buffer_add_one( c->argc - 1, &c->argv[ 1 ] );
2970 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2971 "<%s> unable to add value #%d",
2972 c->argv[0], tcp_buffer_num );
2973 Debug( LDAP_DEBUG_ANY, "%s: %s\n",
2974 c->log, c->cr_msg, 0 );
2981 #endif /* LDAP_TCP_BUFFER */
2984 config_suffix(ConfigArgs *c)
2987 struct berval pdn, ndn;
2988 char *notallowed = NULL;
2990 if ( c->be == frontendDB ) {
2991 notallowed = "frontend";
2993 } else if ( SLAP_MONITOR(c->be) ) {
2994 notallowed = "monitor";
2996 } else if ( SLAP_CONFIG(c->be) ) {
2997 notallowed = "config";
3000 if ( notallowed != NULL ) {
3001 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
3005 case LDAP_MOD_DELETE:
3006 case LDAP_MOD_REPLACE:
3007 case LDAP_MOD_INCREMENT:
3008 case SLAP_CONFIG_ADD:
3009 if ( !BER_BVISNULL( &c->value_dn ) ) {
3010 snprintf( buf, sizeof( buf ), "<%s> ",
3011 c->value_dn.bv_val );
3014 Debug(LDAP_DEBUG_ANY,
3015 "%s: suffix %snot allowed in %s database.\n",
3016 c->log, buf, notallowed );
3019 case SLAP_CONFIG_EMIT:
3020 /* don't complain when emitting... */
3024 /* FIXME: don't know what values may be valid;
3025 * please remove assertion, or add legal values
3026 * to either block */
3034 if (c->op == SLAP_CONFIG_EMIT) {
3035 if ( c->be->be_suffix == NULL
3036 || BER_BVISNULL( &c->be->be_suffix[0] ) )
3040 value_add( &c->rvalue_vals, c->be->be_suffix );
3041 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
3044 } else if ( c->op == LDAP_MOD_DELETE ) {
3045 if ( c->valx < 0 ) {
3046 ber_bvarray_free( c->be->be_suffix );
3047 ber_bvarray_free( c->be->be_nsuffix );
3048 c->be->be_suffix = NULL;
3049 c->be->be_nsuffix = NULL;
3052 ch_free( c->be->be_suffix[i].bv_val );
3053 ch_free( c->be->be_nsuffix[i].bv_val );
3055 c->be->be_suffix[i] = c->be->be_suffix[i+1];
3056 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
3058 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
3063 #ifdef SLAPD_MONITOR_DN
3064 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
3065 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> DN is reserved for monitoring slapd",
3067 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3068 c->log, c->cr_msg, SLAPD_MONITOR_DN);
3073 if (SLAP_DB_ONE_SUFFIX( c->be ) && c->be->be_suffix &&
3074 !BER_BVISNULL( &c->be->be_suffix[0] )) {
3075 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> Only one suffix is allowed on this %s backend",
3076 c->argv[0], c->be->bd_info->bi_type );
3077 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3078 c->log, c->cr_msg, 0);
3085 if (SLAP_DBHIDDEN( c->be ))
3088 tbe = select_backend(&ndn, 0);
3090 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
3096 BackendDB *b2 = tbe;
3098 /* Does tbe precede be? */
3099 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
3102 char *type = tbe->bd_info->bi_type;
3104 if ( overlay_is_over( tbe ) ) {
3105 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
3106 type = oi->oi_orig->bi_type;
3109 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> namingContext \"%s\" "
3110 "already served by a preceding %s database",
3111 c->argv[0], pdn.bv_val, type );
3112 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
3113 c->log, c->cr_msg, tbe->be_suffix[0].bv_val);
3119 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
3120 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
3121 "base provided \"%s\" (assuming okay)\n",
3122 c->log, default_search_base.bv_val, 0);
3124 ber_bvarray_add(&c->be->be_suffix, &pdn);
3125 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
3130 config_rootdn(ConfigArgs *c) {
3131 if (c->op == SLAP_CONFIG_EMIT) {
3132 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
3133 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
3134 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
3139 } else if ( c->op == LDAP_MOD_DELETE ) {
3140 ch_free( c->be->be_rootdn.bv_val );
3141 ch_free( c->be->be_rootndn.bv_val );
3142 BER_BVZERO( &c->be->be_rootdn );
3143 BER_BVZERO( &c->be->be_rootndn );
3146 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
3147 ch_free( c->be->be_rootdn.bv_val );
3148 ch_free( c->be->be_rootndn.bv_val );
3150 c->be->be_rootdn = c->value_dn;
3151 c->be->be_rootndn = c->value_ndn;
3156 config_rootpw(ConfigArgs *c) {
3159 if (c->op == SLAP_CONFIG_EMIT) {
3160 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
3161 /* don't copy, because "rootpw" is marked
3163 c->value_bv = c->be->be_rootpw;
3167 } else if ( c->op == LDAP_MOD_DELETE ) {
3168 ch_free( c->be->be_rootpw.bv_val );
3169 BER_BVZERO( &c->be->be_rootpw );
3173 tbe = select_backend(&c->be->be_rootndn, 0);
3175 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> can only be set when rootdn is under suffix",
3177 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3178 c->log, c->cr_msg, 0);
3181 if ( !BER_BVISNULL( &c->be->be_rootpw ))
3182 ch_free( c->be->be_rootpw.bv_val );
3183 c->be->be_rootpw = c->value_bv;
3188 config_restrict(ConfigArgs *c) {
3189 slap_mask_t restrictops = 0;
3191 slap_verbmasks restrictable_ops[] = {
3192 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
3193 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
3194 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
3195 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
3196 { BER_BVC("modrdn"), 0 },
3197 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
3198 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
3199 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
3200 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
3201 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
3202 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
3203 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
3204 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
3205 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
3206 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
3207 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
3211 if (c->op == SLAP_CONFIG_EMIT) {
3212 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
3214 } else if ( c->op == LDAP_MOD_DELETE ) {
3216 c->be->be_restrictops = 0;
3218 i = verb_to_mask( c->line, restrictable_ops );
3219 c->be->be_restrictops &= ~restrictable_ops[i].mask;
3223 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
3225 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown operation", c->argv[0] );
3226 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3227 c->log, c->cr_msg, c->argv[i]);
3230 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
3231 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
3232 c->be->be_restrictops |= restrictops;
3237 config_allows(ConfigArgs *c) {
3238 slap_mask_t allows = 0;
3240 slap_verbmasks allowable_ops[] = {
3241 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
3242 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
3243 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
3244 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
3245 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
3248 if (c->op == SLAP_CONFIG_EMIT) {
3249 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
3250 } else if ( c->op == LDAP_MOD_DELETE ) {
3254 i = verb_to_mask( c->line, allowable_ops );
3255 global_allows &= ~allowable_ops[i].mask;
3259 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
3261 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3262 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3263 c->log, c->cr_msg, c->argv[i]);
3266 global_allows |= allows;
3271 config_disallows(ConfigArgs *c) {
3272 slap_mask_t disallows = 0;
3274 slap_verbmasks disallowable_ops[] = {
3275 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
3276 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
3277 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
3278 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
3279 { BER_BVC("proxy_authz_non_critical"), SLAP_DISALLOW_PROXY_AUTHZ_N_CRIT },
3280 { BER_BVC("dontusecopy_non_critical"), SLAP_DISALLOW_DONTUSECOPY_N_CRIT },
3283 if (c->op == SLAP_CONFIG_EMIT) {
3284 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
3285 } else if ( c->op == LDAP_MOD_DELETE ) {
3287 global_disallows = 0;
3289 i = verb_to_mask( c->line, disallowable_ops );
3290 global_disallows &= ~disallowable_ops[i].mask;
3294 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
3296 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3297 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3298 c->log, c->cr_msg, c->argv[i]);
3301 global_disallows |= disallows;
3306 config_requires(ConfigArgs *c) {
3307 slap_mask_t requires = frontendDB->be_requires;
3308 int i, argc = c->argc;
3309 char **argv = c->argv;
3311 slap_verbmasks requires_ops[] = {
3312 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
3313 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
3314 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
3315 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
3316 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
3319 if (c->op == SLAP_CONFIG_EMIT) {
3320 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
3321 } else if ( c->op == LDAP_MOD_DELETE ) {
3323 c->be->be_requires = 0;
3325 i = verb_to_mask( c->line, requires_ops );
3326 c->be->be_requires &= ~requires_ops[i].mask;
3330 /* "none" can only be first, to wipe out default/global values */
3331 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
3336 i = verbs_to_mask(argc, argv, requires_ops, &requires);
3338 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
3339 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
3340 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3341 c->log, c->cr_msg, 0);
3343 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
3344 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3345 c->log, c->cr_msg, c->argv[i]);
3349 c->be->be_requires = requires;
3354 config_extra_attrs(ConfigArgs *c)
3356 assert( c->be != NULL );
3358 if ( c->op == SLAP_CONFIG_EMIT ) {
3361 if ( c->be->be_extra_anlist == NULL ) {
3365 for ( i = 0; !BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ); i++ ) {
3366 value_add_one( &c->rvalue_vals, &c->be->be_extra_anlist[i].an_name );
3369 } else if ( c->op == LDAP_MOD_DELETE ) {
3370 if ( c->be->be_extra_anlist == NULL ) {
3374 if ( c->valx < 0 ) {
3375 anlist_free( c->be->be_extra_anlist, 1, NULL );
3376 c->be->be_extra_anlist = NULL;
3381 for ( i = 0; i < c->valx && !BER_BVISNULL( &c->be->be_extra_anlist[i + 1].an_name ); i++ )
3384 if ( BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ) ) {
3388 ch_free( c->be->be_extra_anlist[i].an_name.bv_val );
3390 for ( ; !BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ); i++ ) {
3391 c->be->be_extra_anlist[i] = c->be->be_extra_anlist[i + 1];
3396 c->be->be_extra_anlist = str2anlist( c->be->be_extra_anlist, c->argv[1], " ,\t" );
3397 if ( c->be->be_extra_anlist == NULL ) {
3405 static slap_verbmasks *loglevel_ops;
3408 loglevel_init( void )
3410 slap_verbmasks lo[] = {
3411 { BER_BVC("Any"), (slap_mask_t) LDAP_DEBUG_ANY },
3412 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
3413 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
3414 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
3415 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
3416 { BER_BVC("BER"), LDAP_DEBUG_BER },
3417 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
3418 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
3419 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
3420 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
3421 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
3422 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
3423 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
3424 #if 0 /* no longer used (nor supported) */
3425 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
3426 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
3428 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
3429 { BER_BVC("None"), LDAP_DEBUG_NONE },
3433 return slap_verbmasks_init( &loglevel_ops, lo );
3437 loglevel_destroy( void )
3439 if ( loglevel_ops ) {
3440 (void)slap_verbmasks_destroy( loglevel_ops );
3442 loglevel_ops = NULL;
3445 static slap_mask_t loglevel_ignore[] = { -1, 0 };
3448 slap_loglevel_register( slap_mask_t m, struct berval *s )
3452 if ( loglevel_ops == NULL ) {
3456 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
3459 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
3467 slap_loglevel_get( struct berval *s, int *l )
3472 if ( loglevel_ops == NULL ) {
3476 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3477 m |= loglevel_ops[ i ].mask;
3480 for ( i = 1; m & i; i <<= 1 )
3487 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
3490 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
3501 str2loglevel( const char *s, int *l )
3505 if ( loglevel_ops == NULL ) {
3509 i = verb_to_mask( s, loglevel_ops );
3511 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
3515 *l = loglevel_ops[ i ].mask;
3521 loglevel2str( int l )
3523 struct berval bv = BER_BVNULL;
3525 loglevel2bv( l, &bv );
3531 loglevel2bv( int l, struct berval *bv )
3533 if ( loglevel_ops == NULL ) {
3539 return enum_to_verb( loglevel_ops, l, bv ) == -1;
3543 loglevel2bvarray( int l, BerVarray *bva )
3545 if ( loglevel_ops == NULL ) {
3549 return mask_to_verbs( loglevel_ops, l, bva );
3553 loglevel_print( FILE *out )
3557 if ( loglevel_ops == NULL ) {
3561 fprintf( out, "Installed log subsystems:\n\n" );
3562 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3563 unsigned mask = loglevel_ops[ i ].mask & 0xffffffffUL;
3565 (mask == ((slap_mask_t) -1 & 0xffffffffUL)
3566 ? "\t%-30s (-1, 0xffffffff)\n" : "\t%-30s (%u, 0x%x)\n"),
3567 loglevel_ops[ i ].word.bv_val, mask, mask );
3570 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
3571 "by specific code\n\n" );
3576 static int config_syslog;
3579 config_loglevel(ConfigArgs *c) {
3582 if ( loglevel_ops == NULL ) {
3586 if (c->op == SLAP_CONFIG_EMIT) {
3587 /* Get default or commandline slapd setting */
3588 if ( ldap_syslog && !config_syslog )
3589 config_syslog = ldap_syslog;
3590 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
3592 } else if ( c->op == LDAP_MOD_DELETE ) {
3596 i = verb_to_mask( c->line, loglevel_ops );
3597 config_syslog &= ~loglevel_ops[i].mask;
3599 if ( slapMode & SLAP_SERVER_MODE ) {
3600 ldap_syslog = config_syslog;
3605 for( i=1; i < c->argc; i++ ) {
3608 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
3609 if( lutil_atoix( &level, c->argv[i], 0 ) != 0 ) {
3610 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse level", c->argv[0] );
3611 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3612 c->log, c->cr_msg, c->argv[i]);
3616 if ( str2loglevel( c->argv[i], &level ) ) {
3617 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown level", c->argv[0] );
3618 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3619 c->log, c->cr_msg, c->argv[i]);
3623 /* Explicitly setting a zero clears all the levels */
3625 config_syslog |= level;
3629 if ( slapMode & SLAP_SERVER_MODE ) {
3630 ldap_syslog = config_syslog;
3636 config_referral(ConfigArgs *c) {
3638 if (c->op == SLAP_CONFIG_EMIT) {
3639 if ( default_referral ) {
3640 value_add( &c->rvalue_vals, default_referral );
3645 } else if ( c->op == LDAP_MOD_DELETE ) {
3646 if ( c->valx < 0 ) {
3647 ber_bvarray_free( default_referral );
3648 default_referral = NULL;
3651 ch_free( default_referral[i].bv_val );
3652 for (; default_referral[i].bv_val; i++ )
3653 default_referral[i] = default_referral[i+1];
3657 if(validate_global_referral(c->argv[1])) {
3658 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3659 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3660 c->log, c->cr_msg, c->argv[1]);
3664 ber_str2bv(c->argv[1], 0, 0, &val);
3665 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
3673 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
3674 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
3675 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
3676 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
3677 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
3678 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
3679 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
3680 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
3681 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
3686 config_security(ConfigArgs *c) {
3687 slap_ssf_set_t *set = &c->be->be_ssf_set;
3690 if (c->op == SLAP_CONFIG_EMIT) {
3696 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
3697 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
3700 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
3701 if ( bv.bv_len >= sizeof( numbuf ) ) {
3702 ber_bvarray_free_x( c->rvalue_vals, NULL );
3703 c->rvalue_vals = NULL;
3707 bv.bv_len += sec_keys[i].key.bv_len;
3708 bv.bv_val = ch_malloc( bv.bv_len + 1);
3709 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
3710 strcpy( next, numbuf );
3711 ber_bvarray_add( &c->rvalue_vals, &bv );
3716 for(i = 1; i < c->argc; i++) {
3717 slap_ssf_t *tgt = NULL;
3719 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
3720 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
3721 sec_keys[j].key.bv_len)) {
3722 src = c->argv[i] + sec_keys[j].key.bv_len;
3723 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
3728 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown factor", c->argv[0] );
3729 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3730 c->log, c->cr_msg, c->argv[i]);
3734 if ( lutil_atou( tgt, src ) != 0 ) {
3735 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse factor", c->argv[0] );
3736 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3737 c->log, c->cr_msg, c->argv[i]);
3745 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
3749 for (; !BER_BVISNULL( &an->an_name ); an++) {
3750 /* if buflen == 0, assume the buffer size has been
3751 * already checked otherwise */
3752 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
3753 if ( comma ) *ptr++ = ',';
3754 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
3761 config_updatedn(ConfigArgs *c) {
3762 if (c->op == SLAP_CONFIG_EMIT) {
3763 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
3764 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
3765 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
3769 } else if ( c->op == LDAP_MOD_DELETE ) {
3770 ch_free( c->be->be_update_ndn.bv_val );
3771 BER_BVZERO( &c->be->be_update_ndn );
3772 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
3775 if(SLAP_SHADOW(c->be)) {
3776 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database already shadowed", c->argv[0] );
3777 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3778 c->log, c->cr_msg, 0);
3782 ber_memfree_x( c->value_dn.bv_val, NULL );
3783 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
3784 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
3786 c->be->be_update_ndn = c->value_ndn;
3787 BER_BVZERO( &c->value_dn );
3788 BER_BVZERO( &c->value_ndn );
3790 return config_slurp_shadow( c );
3794 config_shadow( ConfigArgs *c, slap_mask_t flag )
3796 char *notallowed = NULL;
3798 if ( c->be == frontendDB ) {
3799 notallowed = "frontend";
3801 } else if ( SLAP_MONITOR(c->be) ) {
3802 notallowed = "monitor";
3805 if ( notallowed != NULL ) {
3806 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
3810 if ( SLAP_SHADOW(c->be) ) {
3811 /* if already shadow, only check consistency */
3812 if ( ( SLAP_DBFLAGS(c->be) & flag ) != flag ) {
3813 Debug( LDAP_DEBUG_ANY, "%s: inconsistent shadow flag 0x%lx.\n",
3819 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | flag);
3820 if ( !SLAP_MULTIMASTER( c->be ))
3821 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
3828 config_updateref(ConfigArgs *c) {
3830 if (c->op == SLAP_CONFIG_EMIT) {
3831 if ( c->be->be_update_refs ) {
3832 value_add( &c->rvalue_vals, c->be->be_update_refs );
3837 } else if ( c->op == LDAP_MOD_DELETE ) {
3838 if ( c->valx < 0 ) {
3839 ber_bvarray_free( c->be->be_update_refs );
3840 c->be->be_update_refs = NULL;
3843 ch_free( c->be->be_update_refs[i].bv_val );
3844 for (; c->be->be_update_refs[i].bv_val; i++)
3845 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
3849 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
3850 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must appear after syncrepl or updatedn",
3852 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3853 c->log, c->cr_msg, 0);
3857 if(validate_global_referral(c->argv[1])) {
3858 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3859 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3860 c->log, c->cr_msg, c->argv[1]);
3863 ber_str2bv(c->argv[1], 0, 0, &val);
3864 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
3869 config_obsolete(ConfigArgs *c) {
3870 if (c->op == SLAP_CONFIG_EMIT)
3873 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> keyword is obsolete (ignored)",
3875 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0);
3880 config_include(ConfigArgs *c) {
3881 int savelineno = c->lineno;
3884 ConfigFile *cfsave = cfn;
3885 ConfigFile *cf2 = NULL;
3887 /* Leftover from RE23. No dynamic config for include files */
3888 if ( c->op == SLAP_CONFIG_EMIT || c->op == LDAP_MOD_DELETE )
3891 cf = ch_calloc( 1, sizeof(ConfigFile));
3892 if ( cfn->c_kids ) {
3893 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
3899 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
3900 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
3901 c->lineno = savelineno - 1;
3904 if ( cf2 ) cf2->c_sibs = NULL;
3905 else cfn->c_kids = NULL;
3906 ch_free( cf->c_file.bv_val );
3916 config_tls_cleanup(ConfigArgs *c) {
3919 if ( slap_tls_ld ) {
3922 ldap_pvt_tls_ctx_free( slap_tls_ctx );
3924 /* Force new ctx to be created */
3925 rc = ldap_pvt_tls_set_option( slap_tls_ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
3927 /* The ctx's refcount is bumped up here */
3928 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CTX, &slap_tls_ctx );
3929 /* This is a no-op if it's already loaded */
3930 load_extop( &slap_EXOP_START_TLS, 0, starttls_extop );
3937 config_tls_option(ConfigArgs *c) {
3939 LDAP *ld = slap_tls_ld;
3941 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
3942 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
3943 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
3944 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
3945 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
3946 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
3947 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
3949 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
3951 default: Debug(LDAP_DEBUG_ANY, "%s: "
3952 "unknown tls_option <0x%x>\n",
3953 c->log, c->type, 0);
3956 if (c->op == SLAP_CONFIG_EMIT) {
3957 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
3958 } else if ( c->op == LDAP_MOD_DELETE ) {
3959 c->cleanup = config_tls_cleanup;
3960 return ldap_pvt_tls_set_option( ld, flag, NULL );
3962 ch_free(c->value_string);
3963 c->cleanup = config_tls_cleanup;
3964 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
3967 /* FIXME: this ought to be provided by libldap */
3969 config_tls_config(ConfigArgs *c) {
3972 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
3973 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
3974 case CFG_TLS_PROTOCOL_MIN: flag = LDAP_OPT_X_TLS_PROTOCOL_MIN; break;
3976 Debug(LDAP_DEBUG_ANY, "%s: "
3977 "unknown tls_option <0x%x>\n",
3978 c->log, c->type, 0);
3981 if (c->op == SLAP_CONFIG_EMIT) {
3982 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
3983 } else if ( c->op == LDAP_MOD_DELETE ) {
3985 c->cleanup = config_tls_cleanup;
3986 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
3988 ch_free( c->value_string );
3989 c->cleanup = config_tls_cleanup;
3990 if ( isdigit( (unsigned char)c->argv[1][0] ) ) {
3991 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
3992 Debug(LDAP_DEBUG_ANY, "%s: "
3993 "unable to parse %s \"%s\"\n",
3994 c->log, c->argv[0], c->argv[1] );
3997 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
3999 return(ldap_pvt_tls_config(slap_tls_ld, flag, c->argv[1]));
4004 static CfEntryInfo *
4005 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
4015 if ( dn_match( &root->ce_entry->e_nname, dn ))
4018 c = dn->bv_val+dn->bv_len;
4019 for (;*c != ',';c--);
4023 for (--c;c>dn->bv_val && *c != ',';c--);
4027 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
4029 root = root->ce_kids;
4031 for (;root;root=root->ce_sibs) {
4032 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
4033 if ( cdn.bv_val == dn->bv_val ) {
4043 typedef struct setup_cookie {
4053 config_ldif_resp( Operation *op, SlapReply *rs )
4055 if ( rs->sr_type == REP_SEARCH ) {
4056 setup_cookie *sc = op->o_callback->sc_private;
4059 sc->cfb->cb_got_ldif = 1;
4060 /* Does the frontend exist? */
4061 if ( !sc->got_frontend ) {
4062 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
4063 "olcDatabase", STRLENOF( "olcDatabase" )))
4065 if ( strncmp( rs->sr_entry->e_nname.bv_val +
4066 STRLENOF( "olcDatabase" ), "={-1}frontend",
4067 STRLENOF( "={-1}frontend" )))
4071 sc->ca->be = frontendDB;
4072 sc->ca->bi = frontendDB->bd_info;
4073 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
4074 rdn.bv_val = sc->ca->log;
4075 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
4076 "%s=" SLAP_X_ORDERED_FMT "%s",
4077 cfAd_database->ad_cname.bv_val, -1,
4078 sc->ca->bi->bi_type);
4080 sc->frontend = config_build_entry( op, rs,
4081 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
4082 sc->ca->be->be_cf_ocs );
4092 dnParent( &rs->sr_entry->e_nname, &pdn );
4094 /* Does the configDB exist? */
4095 if ( sc->got_frontend && !sc->got_config &&
4096 !strncmp( rs->sr_entry->e_nname.bv_val,
4097 "olcDatabase", STRLENOF( "olcDatabase" )) &&
4098 dn_match( &config_rdn, &pdn ) )
4100 if ( strncmp( rs->sr_entry->e_nname.bv_val +
4101 STRLENOF( "olcDatabase" ), "={0}config",
4102 STRLENOF( "={0}config" )))
4106 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
4107 sc->ca->bi = sc->ca->be->bd_info;
4108 rdn.bv_val = sc->ca->log;
4109 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
4110 "%s=" SLAP_X_ORDERED_FMT "%s",
4111 cfAd_database->ad_cname.bv_val, 0,
4112 sc->ca->bi->bi_type);
4114 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
4115 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
4122 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
4123 if ( rs->sr_err != LDAP_SUCCESS ) {
4124 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
4125 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg, 0 );
4131 /* Configure and read the underlying back-ldif store */
4133 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
4134 CfBackInfo *cfb = be->be_private;
4140 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
4141 Connection conn = {0};
4142 OperationBuffer opbuf;
4144 SlapReply rs = {REP_RESULT};
4145 Filter filter = { LDAP_FILTER_PRESENT };
4146 struct berval filterstr = BER_BVC("(objectclass=*)");
4149 /* Is the config directory available? */
4150 if ( stat( dir, &st ) < 0 ) {
4151 /* No, so don't bother using the backing store.
4152 * All changes will be in-memory only.
4157 cfb->cb_db.bd_info = backend_info( "ldif" );
4158 if ( !cfb->cb_db.bd_info )
4159 return 0; /* FIXME: eventually this will be a fatal error */
4161 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
4164 cfb->cb_db.be_suffix = be->be_suffix;
4165 cfb->cb_db.be_nsuffix = be->be_nsuffix;
4167 /* The suffix is always "cn=config". The underlying DB's rootdn
4168 * is always the same as the suffix.
4170 cfb->cb_db.be_rootdn = be->be_suffix[0];
4171 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
4173 ber_str2bv( dir, 0, 1, &cfdir );
4178 argv[0] = "directory";
4179 argv[1] = (char *)dir;
4184 c.table = Cft_Database;
4186 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
4190 if ( config_add_vals( ct, &c ))
4193 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
4197 void *thrctx = ldap_pvt_thread_pool_context();
4200 connection_fake_init( &conn, &opbuf, thrctx );
4203 filter.f_desc = slap_schema.si_ad_objectClass;
4205 op->o_tag = LDAP_REQ_SEARCH;
4207 op->ors_filter = &filter;
4208 op->ors_filterstr = filterstr;
4209 op->ors_scope = LDAP_SCOPE_SUBTREE;
4211 op->o_dn = c.be->be_rootdn;
4212 op->o_ndn = c.be->be_rootndn;
4214 op->o_req_dn = be->be_suffix[0];
4215 op->o_req_ndn = be->be_nsuffix[0];
4217 op->ors_tlimit = SLAP_NO_LIMIT;
4218 op->ors_slimit = SLAP_NO_LIMIT;
4220 op->ors_attrs = slap_anlist_all_attributes;
4221 op->ors_attrsonly = 0;
4223 op->o_callback = &cb;
4226 cb.sc_private = ≻
4227 sc.got_frontend = 0;
4232 op->o_bd = &cfb->cb_db;
4234 /* Allow unknown attrs in DNs */
4235 prev_DN_strict = slap_DN_strict;
4238 rc = op->o_bd->be_search( op, &rs );
4240 /* Restore normal DN validation */
4241 slap_DN_strict = prev_DN_strict;
4243 op->o_tag = LDAP_REQ_ADD;
4244 if ( rc == LDAP_SUCCESS && sc.frontend ) {
4245 rs_reinit( &rs, REP_RESULT );
4246 op->ora_e = sc.frontend;
4247 rc = op->o_bd->be_add( op, &rs );
4249 if ( rc == LDAP_SUCCESS && sc.config ) {
4250 rs_reinit( &rs, REP_RESULT );
4251 op->ora_e = sc.config;
4252 rc = op->o_bd->be_add( op, &rs );
4254 ldap_pvt_thread_pool_context_reset( thrctx );
4257 /* ITS#4194 - only use if it's present, or we're converting. */
4258 if ( !readit || rc == LDAP_SUCCESS )
4259 cfb->cb_use_ldif = 1;
4265 CfOc_cmp( const void *c1, const void *c2 ) {
4266 const ConfigOCs *co1 = c1;
4267 const ConfigOCs *co2 = c2;
4269 return ber_bvcmp( co1->co_name, co2->co_name );
4273 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
4276 i = init_config_attrs( ct );
4279 /* set up the objectclasses */
4280 i = init_config_ocs( ocs );
4283 for (i=0; ocs[i].co_def; i++) {
4284 if ( ocs[i].co_oc ) {
4285 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
4286 if ( !ocs[i].co_table )
4287 ocs[i].co_table = ct;
4288 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
4295 read_config(const char *fname, const char *dir) {
4298 const char *cfdir, *cfname;
4301 /* Setup the config backend */
4302 be = backend_db_init( "config", NULL, 0, NULL );
4306 cfb = be->be_private;
4307 be->be_dfltaccess = ACL_NONE;
4309 /* If no .conf, or a dir was specified, setup the dir */
4310 if ( !fname || dir ) {
4312 /* If explicitly given, check for existence */
4315 if ( stat( dir, &st ) < 0 ) {
4316 Debug( LDAP_DEBUG_ANY,
4317 "invalid config directory %s, error %d\n",
4323 cfdir = SLAPD_DEFAULT_CONFIGDIR;
4325 /* if fname is defaulted, try reading .d */
4326 rc = config_setup_ldif( be, cfdir, !fname );
4329 /* It may be OK if the base object doesn't exist yet. */
4330 if ( rc != LDAP_NO_SUCH_OBJECT )
4332 /* ITS#4194: But if dir was specified and no fname,
4333 * then we were supposed to read the dir. Unless we're
4334 * trying to slapadd the dir...
4336 if ( dir && !fname ) {
4337 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
4339 /* Assume it's slapadd with a config dir, let it continue */
4341 cfb->cb_got_ldif = 1;
4342 cfb->cb_use_ldif = 1;
4347 /* If we read the config from back-ldif, nothing to do here */
4348 if ( cfb->cb_got_ldif ) {
4357 cfname = SLAPD_DEFAULT_CONFIGFILE;
4359 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
4362 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
4365 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
4366 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
4367 &frontendDB->be_schemadn );
4368 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
4369 if ( rc != LDAP_SUCCESS ) {
4370 Debug(LDAP_DEBUG_ANY, "read_config: "
4371 "unable to normalize default schema DN \"%s\"\n",
4372 frontendDB->be_schemadn.bv_val, 0, 0 );
4373 /* must not happen */
4377 if ( rc == 0 && ( slapMode & SLAP_SERVER_MODE ) && sid_list ) {
4378 if ( !BER_BVISEMPTY( &sid_list->si_url ) && !sid_set ) {
4379 Debug(LDAP_DEBUG_ANY, "read_config: no serverID / URL match found. "
4380 "Check slapd -h arguments.\n", 0,0,0 );
4388 config_back_bind( Operation *op, SlapReply *rs )
4390 if ( be_isroot_pw( op ) ) {
4391 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
4392 /* frontend sends result */
4393 return LDAP_SUCCESS;
4396 rs->sr_err = LDAP_INVALID_CREDENTIALS;
4397 send_ldap_result( op, rs );
4403 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
4407 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
4409 rs->sr_attrs = op->ors_attrs;
4410 rs->sr_entry = ce->ce_entry;
4412 rc = send_search_entry( op, rs );
4413 if ( rc != LDAP_SUCCESS ) {
4417 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
4418 if ( ce->ce_kids ) {
4419 rc = config_send( op, rs, ce->ce_kids, 1 );
4420 if ( rc ) return rc;
4423 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
4424 rc = config_send( op, rs, ce, 0 );
4432 static ConfigTable *
4433 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
4438 for (j=0; j<nocs; j++) {
4439 for (i=0; colst[j]->co_table[i].name; i++)
4440 if ( colst[j]->co_table[i].ad == ad ) {
4441 ca->table = colst[j]->co_type;
4442 return &colst[j]->co_table[i];
4448 /* Sort the attributes of the entry according to the order defined
4449 * in the objectclass, with required attributes occurring before
4450 * allowed attributes. For any attributes with sequencing dependencies
4451 * (e.g., rootDN must be defined after suffix) the objectclass must
4452 * list the attributes in the desired sequence.
4455 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
4457 Attribute *a, *head = NULL, *tail = NULL, **prev;
4460 for (i=0; i<nocs; i++) {
4461 if ( colst[i]->co_oc->soc_required ) {
4462 AttributeType **at = colst[i]->co_oc->soc_required;
4463 for (j=0; at[j]; j++) {
4464 for (a=e->e_attrs, prev=&e->e_attrs; a;
4465 prev = &(*prev)->a_next, a=a->a_next) {
4466 if ( a->a_desc == at[j]->sat_ad ) {
4480 if ( colst[i]->co_oc->soc_allowed ) {
4481 AttributeType **at = colst[i]->co_oc->soc_allowed;
4482 for (j=0; at[j]; j++) {
4483 for (a=e->e_attrs, prev=&e->e_attrs; a;
4484 prev = &(*prev)->a_next, a=a->a_next) {
4485 if ( a->a_desc == at[j]->sat_ad ) {
4501 tail->a_next = e->e_attrs;
4507 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
4509 Attribute *a = NULL;
4510 AttributeDescription *ad;
4520 Modifications *ml = ptr;
4522 vals = ml->sml_values;
4525 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
4526 rc = ordered_value_sort( a, 1 );
4528 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
4529 ad->ad_cname.bv_val );
4533 for ( i=0; vals[i].bv_val; i++ ) {
4534 ca->line = vals[i].bv_val;
4535 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
4536 ca->line[0] == '{' ) {
4537 char *idx = strchr( ca->line, '}' );
4538 if ( idx ) ca->line = idx+1;
4540 rc = config_parse_vals( ct, ca, i );
4549 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
4552 struct berval rtype, rval;
4554 AttributeDescription *ad = NULL;
4556 dnRdn( &e->e_name, rdn );
4557 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
4558 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
4559 rtype.bv_val = rdn->bv_val;
4560 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
4563 slap_bv2ad( &rtype, &ad, &rs->sr_text );
4564 a = attr_find( e->e_attrs, ad );
4565 if (!a ) return LDAP_NAMING_VIOLATION;
4572 config_rename_kids( CfEntryInfo *ce )
4575 struct berval rdn, nrdn;
4577 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
4578 struct berval newdn, newndn;
4579 dnRdn ( &ce2->ce_entry->e_name, &rdn );
4580 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
4581 build_new_dn( &newdn, &ce->ce_entry->e_name, &rdn, NULL );
4582 build_new_dn( &newndn, &ce->ce_entry->e_nname, &nrdn, NULL );
4583 free( ce2->ce_entry->e_name.bv_val );
4584 free( ce2->ce_entry->e_nname.bv_val );
4585 ce2->ce_entry->e_name = newdn;
4586 ce2->ce_entry->e_nname = newndn;
4587 config_rename_kids( ce2 );
4592 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
4593 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
4594 struct berval *nnewrdn, int use_ldif )
4598 struct berval odn, ondn;
4602 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
4603 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
4606 free( a->a_vals[0].bv_val );
4607 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
4608 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
4609 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
4610 strcpy( a->a_vals[0].bv_val, ptr1 );
4612 if ( a->a_nvals != a->a_vals ) {
4613 free( a->a_nvals[0].bv_val );
4614 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
4615 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
4616 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
4617 strcpy( a->a_nvals[0].bv_val, ptr1 );
4620 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
4621 BackendDB *be = op->o_bd;
4622 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4623 struct berval dn, ndn, xdn, xndn;
4625 op->o_bd = &cfb->cb_db;
4627 /* Save current rootdn; use the underlying DB's rootdn */
4631 xndn = op->o_req_ndn;
4632 op->o_dn = op->o_bd->be_rootdn;
4633 op->o_ndn = op->o_bd->be_rootndn;
4635 op->o_req_ndn = ondn;
4637 scp = op->o_callback;
4638 op->o_callback = ≻
4639 op->orr_newrdn = *newrdn;
4640 op->orr_nnewrdn = *nnewrdn;
4641 op->orr_newSup = NULL;
4642 op->orr_nnewSup = NULL;
4643 op->orr_deleteoldrdn = 1;
4644 op->orr_modlist = NULL;
4645 slap_modrdn2mods( op, rs );
4646 slap_mods_opattrs( op, &op->orr_modlist, 1 );
4647 rc = op->o_bd->be_modrdn( op, rs );
4648 slap_mods_free( op->orr_modlist, 1 );
4651 op->o_callback = scp;
4655 op->o_req_ndn = xndn;
4658 free( ondn.bv_val );
4660 config_rename_kids( e->e_private );
4665 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
4666 Entry *e, int idx, int tailindex, int use_ldif )
4668 struct berval ival, newrdn, nnewrdn;
4671 char ibuf[32], *ptr1, *ptr2 = NULL;
4674 rc = config_rename_attr( rs, e, &rdn, &a );
4675 if ( rc ) return rc;
4678 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
4679 if ( ival.bv_len >= sizeof( ibuf ) ) {
4680 return LDAP_NAMING_VIOLATION;
4683 newrdn.bv_len = rdn.bv_len + ival.bv_len;
4684 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
4687 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
4688 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4691 ptr2 = ber_bvchr( &rdn, '}' );
4695 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
4697 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
4698 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
4699 a->a_desc->ad_cname.bv_len );
4701 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4702 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
4706 /* Do the equivalent of ModRDN */
4707 /* Replace DN / NDN */
4708 newrdn.bv_len = ptr1 - newrdn.bv_val;
4709 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
4710 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
4712 free( nnewrdn.bv_val );
4713 free( newrdn.bv_val );
4718 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
4719 SlapReply *rs, int *renum, int *ibase )
4722 int index = -1, gotindex = 0, nsibs, rc = 0;
4723 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
4724 char *ptr1, *ptr2 = NULL;
4727 if ( renum ) *renum = 0;
4729 /* These entries don't get indexed/renumbered */
4730 if ( ce_type == Cft_Global ) return 0;
4731 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
4733 if ( ce_type == Cft_Module )
4736 /* See if the rdn has an index already */
4737 dnRdn( &e->e_name, &rdn );
4738 if ( ce_type == Cft_Database ) {
4739 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
4740 "frontend", STRLENOF("frontend") ))
4742 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
4743 "config", STRLENOF("config") ))
4746 ptr1 = ber_bvchr( &e->e_name, '{' );
4747 if ( ptr1 && ptr1 < &e->e_name.bv_val[ rdn.bv_len ] ) {
4749 ptr2 = strchr( ptr1, '}' );
4750 if ( !ptr2 || ptr2 > &e->e_name.bv_val[ rdn.bv_len ] )
4751 return LDAP_NAMING_VIOLATION;
4752 if ( ptr2-ptr1 == 1)
4753 return LDAP_NAMING_VIOLATION;
4755 index = strtol( ptr1 + 1, &next, 10 );
4756 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
4757 return LDAP_NAMING_VIOLATION;
4760 /* Special case, we allow -1 for the frontendDB */
4761 if ( index != -1 || !isfrontend )
4762 return LDAP_NAMING_VIOLATION;
4764 if ( isconfig && index != 0 ){
4765 return LDAP_NAMING_VIOLATION;
4769 /* count related kids.
4770 * For entries of type Cft_Misc, only count siblings with same RDN type
4772 if ( ce_type == Cft_Misc ) {
4773 rdn.bv_val = e->e_nname.bv_val;
4774 ptr1 = strchr( rdn.bv_val, '=' );
4775 assert( ptr1 != NULL );
4777 rdn.bv_len = ptr1 - rdn.bv_val;
4779 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
4781 if ( ce->ce_type != ce_type )
4784 dnRdn( &ce->ce_entry->e_nname, &rdn2 );
4786 ptr1 = strchr( rdn2.bv_val, '=' );
4787 assert( ptr1 != NULL );
4789 rdn2.bv_len = ptr1 - rdn2.bv_val;
4790 if ( bvmatch( &rdn, &rdn2 ))
4794 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
4795 if ( ce->ce_type == ce_type ) nsibs++;
4799 /* account for -1 frontend */
4800 if ( ce_type == Cft_Database )
4803 if ( index != nsibs ) {
4805 if ( index < nsibs ) {
4806 if ( tailindex ) return LDAP_NAMING_VIOLATION;
4807 /* Siblings need to be renumbered */
4808 if ( index != -1 || !isfrontend )
4812 /* config DB is always "0" */
4813 if ( isconfig && index == -1 ) {
4816 if (( !isfrontend && index == -1 ) || ( index > nsibs ) ){
4820 /* just make index = nsibs */
4822 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
4825 if ( ibase ) *ibase = index;
4826 if ( renum ) *renum = renumber;
4830 /* Insert all superior classes of the given class */
4832 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
4837 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
4838 if ( count_oc( *sups, copp, nocs ) ) {
4843 co.co_name = &oc->soc_cname;
4844 cop = avl_find( CfOcTree, &co, CfOc_cmp );
4848 /* check for duplicates */
4849 for ( i = 0; i < *nocs; i++ ) {
4850 if ( *copp && (*copp)[i] == cop ) {
4856 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
4857 if ( tmp == NULL ) {
4861 (*copp)[*nocs] = cop;
4869 /* Find all superior classes of the given objectclasses,
4870 * return list in order of most-subordinate first.
4872 * Special / auxiliary / Cft_Misc classes always take precedence.
4875 count_ocs( Attribute *oc_at, int *nocs )
4877 int i, j, misc = -1;
4878 ConfigOCs **colst = NULL;
4882 for ( i = oc_at->a_numvals; i--; ) {
4883 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
4885 assert( oc != NULL );
4886 if ( count_oc( oc, &colst, nocs ) ) {
4896 ConfigOCs *tmp = colst[i];
4897 colst[i] = colst[j];
4899 if (tmp->co_type == Cft_Misc)
4903 /* Move misc class to front of list */
4905 ConfigOCs *tmp = colst[misc];
4906 for (i=misc; i>0; i--)
4907 colst[i] = colst[i-1];
4915 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4917 /* Leftover from RE23. Never parse this entry */
4918 return LDAP_COMPARE_TRUE;
4922 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4926 /* This entry is hardcoded, don't re-parse it */
4927 if ( p->ce_type == Cft_Global ) {
4928 cfn = p->ce_private;
4929 ca->ca_private = cfn;
4930 return LDAP_COMPARE_TRUE;
4932 if ( p->ce_type != Cft_Schema )
4933 return LDAP_CONSTRAINT_VIOLATION;
4935 cfn = ch_calloc( 1, sizeof(ConfigFile) );
4936 ca->ca_private = cfn;
4937 cfo = p->ce_private;
4938 cfn->c_sibs = cfo->c_kids;
4940 return LDAP_SUCCESS;
4944 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4946 if ( p->ce_type != Cft_Global ) {
4947 return LDAP_CONSTRAINT_VIOLATION;
4949 /* config must be {0}, nothing else allowed */
4950 if ( !strncmp( e->e_nname.bv_val, "olcDatabase={0}", STRLENOF("olcDatabase={0}")) &&
4951 strncmp( e->e_nname.bv_val + STRLENOF("olcDatabase={0}"), "config,", STRLENOF("config,") )) {
4952 return LDAP_CONSTRAINT_VIOLATION;
4954 ca->be = frontendDB; /* just to get past check_vals */
4955 return LDAP_SUCCESS;
4959 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4961 if ( p->ce_type != Cft_Global ) {
4962 return LDAP_CONSTRAINT_VIOLATION;
4964 return LDAP_SUCCESS;
4968 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4970 if ( p->ce_type != Cft_Global ) {
4971 return LDAP_CONSTRAINT_VIOLATION;
4973 return LDAP_SUCCESS;
4977 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4979 if ( p->ce_type != Cft_Database ) {
4980 return LDAP_CONSTRAINT_VIOLATION;
4983 return LDAP_SUCCESS;
4987 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
4992 AttributeDescription *ad;
4998 if ( cfn->c_cr_head ) {
4999 struct berval bv = BER_BVC("olcDitContentRules");
5001 slap_bv2ad( &bv, &ad, &text );
5002 ct = config_find_table( colst, nocs, ad, ca );
5003 config_del_vals( ct, ca );
5005 if ( cfn->c_oc_head ) {
5006 struct berval bv = BER_BVC("olcObjectClasses");
5008 slap_bv2ad( &bv, &ad, &text );
5009 ct = config_find_table( colst, nocs, ad, ca );
5010 config_del_vals( ct, ca );
5012 if ( cfn->c_at_head ) {
5013 struct berval bv = BER_BVC("olcAttributeTypes");
5015 slap_bv2ad( &bv, &ad, &text );
5016 ct = config_find_table( colst, nocs, ad, ca );
5017 config_del_vals( ct, ca );
5019 if ( cfn->c_syn_head ) {
5020 struct berval bv = BER_BVC("olcLdapSyntaxes");
5022 slap_bv2ad( &bv, &ad, &text );
5023 ct = config_find_table( colst, nocs, ad, ca );
5024 config_del_vals( ct, ca );
5026 if ( cfn->c_om_head ) {
5027 struct berval bv = BER_BVC("olcObjectIdentifier");
5029 slap_bv2ad( &bv, &ad, &text );
5030 ct = config_find_table( colst, nocs, ad, ca );
5031 config_del_vals( ct, ca );
5033 cfo = p->ce_private;
5034 cfo->c_kids = cfn->c_sibs;
5039 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
5041 int rc = LDAP_CONSTRAINT_VIOLATION;
5044 if ( (*cop)->co_ldadd ) {
5045 rc = (*cop)->co_ldadd( last, e, ca );
5046 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
5051 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
5052 ConfigOCs co = { 0 };
5054 co.co_name = &(*ocp)->soc_cname;
5055 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
5056 if ( *cop == NULL ) {
5060 rc = config_add_oc( cop, last, e, ca );
5061 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
5069 /* Parse an LDAP entry into config directives */
5071 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
5072 int *renum, Operation *op )
5074 CfEntryInfo *ce, *last = NULL;
5075 ConfigOCs co, *coptr, **colst;
5076 Attribute *a, *oc_at, *soc_at;
5077 int i, ibase = -1, nocs, rc = 0;
5080 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
5082 memset( ca, 0, sizeof(ConfigArgs));
5084 /* Make sure parent exists and entry does not. But allow
5085 * Databases and Overlays to be inserted. Don't do any
5086 * auto-renumbering if manageDSAit control is present.
5088 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
5090 if ( ( op && op->o_managedsait ) ||
5091 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
5092 ce->ce_type != Cft_Module ) )
5094 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5095 "DN=\"%s\" already exists\n",
5096 log_prefix, e->e_name.bv_val, 0 );
5097 /* global schema ignores all writes */
5098 if ( ce->ce_type == Cft_Schema && ce->ce_parent->ce_type == Cft_Global )
5099 return LDAP_COMPARE_TRUE;
5100 return LDAP_ALREADY_EXISTS;
5104 dnParent( &e->e_nname, &pdn );
5106 /* If last is NULL, the new entry is the root/suffix entry,
5107 * otherwise last should be the parent.
5109 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
5111 rs->sr_matched = last->ce_entry->e_name.bv_val;
5113 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5114 "DN=\"%s\" not child of DN=\"%s\"\n",
5115 log_prefix, e->e_name.bv_val,
5116 last->ce_entry->e_name.bv_val );
5117 return LDAP_NO_SUCH_OBJECT;
5121 /* No parent, must be root. This will never happen... */
5122 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
5123 return LDAP_NO_SUCH_OBJECT;
5126 if ( last && !access_allowed( op, last->ce_entry,
5127 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
5129 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5130 "DN=\"%s\" no write access to \"children\" of parent\n",
5131 log_prefix, e->e_name.bv_val, 0 );
5132 return LDAP_INSUFFICIENT_ACCESS;
5136 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5138 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5139 "DN=\"%s\" no objectClass\n",
5140 log_prefix, e->e_name.bv_val, 0 );
5141 return LDAP_OBJECT_CLASS_VIOLATION;
5144 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
5146 ObjectClass *soc = NULL;
5147 char textbuf[ SLAP_TEXT_BUFLEN ];
5148 const char *text = textbuf;
5150 /* FIXME: check result */
5151 rc = structural_class( oc_at->a_nvals, &soc, NULL,
5152 &text, textbuf, sizeof(textbuf), NULL );
5153 if ( rc != LDAP_SUCCESS ) {
5154 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5155 "DN=\"%s\" no structural objectClass (%s)\n",
5156 log_prefix, e->e_name.bv_val, text );
5159 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
5160 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
5161 if ( soc_at == NULL ) {
5162 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5163 "DN=\"%s\" no structural objectClass; "
5164 "unable to merge computed class %s\n",
5165 log_prefix, e->e_name.bv_val,
5166 soc->soc_cname.bv_val );
5167 return LDAP_OBJECT_CLASS_VIOLATION;
5170 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5171 "DN=\"%s\" no structural objectClass; "
5172 "computed objectClass %s merged\n",
5173 log_prefix, e->e_name.bv_val,
5174 soc->soc_cname.bv_val );
5177 /* Fake the coordinates based on whether we're part of an
5178 * LDAP Add or if reading the config dir
5181 ca->fname = "slapd";
5184 ca->fname = cfdir.bv_val;
5189 co.co_name = &soc_at->a_nvals[0];
5190 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
5191 if ( coptr == NULL ) {
5192 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5193 "DN=\"%s\" no structural objectClass in configuration table\n",
5194 log_prefix, e->e_name.bv_val, 0 );
5195 return LDAP_OBJECT_CLASS_VIOLATION;
5198 /* Only the root can be Cft_Global, everything else must
5199 * have a parent. Only limited nesting arrangements are allowed.
5201 rc = LDAP_CONSTRAINT_VIOLATION;
5202 if ( coptr->co_type == Cft_Global && !last ) {
5203 cfn = cfb->cb_config;
5204 ca->ca_private = cfn;
5205 ca->be = frontendDB; /* just to get past check_vals */
5209 colst = count_ocs( oc_at, &nocs );
5211 /* Check whether the Add is allowed by its parent, and do
5212 * any necessary arg setup
5215 rc = config_add_oc( &coptr, last, e, ca );
5216 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
5217 for ( i = 0; i<nocs; i++ ) {
5218 /* Already checked these */
5219 if ( colst[i]->co_oc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
5221 if ( colst[i]->co_ldadd &&
5222 ( rc = colst[i]->co_ldadd( last, e, ca ))
5223 != LDAP_CONSTRAINT_VIOLATION ) {
5229 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
5230 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5231 "DN=\"%s\" no structural objectClass add function\n",
5232 log_prefix, e->e_name.bv_val, 0 );
5233 return LDAP_OBJECT_CLASS_VIOLATION;
5237 /* Add the entry but don't parse it, we already have its contents */
5238 if ( rc == LDAP_COMPARE_TRUE ) {
5243 if ( rc != LDAP_SUCCESS )
5246 /* Parse all the values and check for simple syntax errors before
5247 * performing any set actions.
5249 * If doing an LDAPadd, check for indexed names and any necessary
5250 * renaming/renumbering. Entries that don't need indexed names are
5251 * ignored. Entries that need an indexed name and arrive without one
5252 * are assigned to the end. Entries that arrive with an index may
5253 * cause the following entries to be renumbered/bumped down.
5255 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
5256 * don't allow Adding an entry with an index that's already in use.
5257 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
5259 * These entries can have auto-assigned indexes (appended to the end)
5260 * but only the other types support auto-renumbering of siblings.
5263 rc = check_name_index( last, coptr->co_type, e, rs, renum,
5268 if ( renum && *renum && coptr->co_type != Cft_Database &&
5269 coptr->co_type != Cft_Overlay )
5271 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
5272 "operation requires sibling renumbering" );
5273 rc = LDAP_UNWILLING_TO_PERFORM;
5278 init_config_argv( ca );
5280 /* Make sure we process attrs in the required order */
5281 sort_attrs( e, colst, nocs );
5283 for ( a = e->e_attrs; a; a = a->a_next ) {
5284 if ( a == oc_at ) continue;
5285 ct = config_find_table( colst, nocs, a->a_desc, ca );
5286 if ( !ct ) continue; /* user data? */
5287 rc = check_vals( ct, ca, a, 1 );
5288 if ( rc ) goto done_noop;
5291 /* Basic syntax checks are OK. Do the actual settings. */
5292 for ( a=e->e_attrs; a; a=a->a_next ) {
5293 if ( a == oc_at ) continue;
5294 ct = config_find_table( colst, nocs, a->a_desc, ca );
5295 if ( !ct ) continue; /* user data? */
5296 for (i=0; a->a_vals[i].bv_val; i++) {
5299 ca->line = a->a_vals[i].bv_val;
5300 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
5301 ptr = strchr( ca->line, '}' );
5303 iptr = strchr( ca->line, '{' );
5307 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
5309 ca->valx = strtol( iptr+1, NULL, 0 );
5314 rc = config_parse_add( ct, ca, i );
5322 /* Newly added databases and overlays need to be started up */
5323 if ( CONFIG_ONLINE_ADD( ca )) {
5324 if ( coptr->co_type == Cft_Database ) {
5325 rc = backend_startup_one( ca->be, &ca->reply );
5327 } else if ( coptr->co_type == Cft_Overlay ) {
5328 if ( ca->bi->bi_db_open ) {
5329 BackendInfo *bi_orig = ca->be->bd_info;
5330 ca->be->bd_info = ca->bi;
5331 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
5332 ca->be->bd_info = bi_orig;
5334 } else if ( ca->cleanup ) {
5335 rc = ca->cleanup( ca );
5338 if (ca->cr_msg[0] == '\0')
5339 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
5341 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
5342 ca->log, ca->cr_msg, ca->argv[1] );
5349 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5350 ce->ce_parent = last;
5351 ce->ce_entry = entry_dup( e );
5352 ce->ce_entry->e_private = ce;
5353 ce->ce_type = coptr->co_type;
5356 ce->ce_private = ca->ca_private;
5357 ca->ca_entry = ce->ce_entry;
5360 } else if ( last->ce_kids ) {
5361 CfEntryInfo *c2, **cprev;
5363 /* Advance to first of this type */
5364 cprev = &last->ce_kids;
5365 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
5366 cprev = &c2->ce_sibs;
5369 /* Account for the (-1) frontendDB entry */
5370 if ( ce->ce_type == Cft_Database ) {
5371 if ( ca->be == frontendDB )
5373 else if ( ibase != -1 )
5378 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
5379 cprev = &c2->ce_sibs;
5385 for ( i=0; i<ibase; i++ ) {
5387 cprev = &c2->ce_sibs;
5390 ce->ce_sibs = *cprev;
5398 if ( (coptr->co_type == Cft_Database) && ca->be ) {
5399 if ( ca->be != frontendDB )
5400 backend_destroy_one( ca->be, 1 );
5401 } else if ( (coptr->co_type == Cft_Overlay) && ca->bi ) {
5402 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
5403 } else if ( coptr->co_type == Cft_Schema ) {
5404 schema_destroy_one( ca, colst, nocs, last );
5409 ch_free( ca->argv );
5410 if ( colst ) ch_free( colst );
5414 #define BIGTMP 10000
5416 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5417 int base, int rebase, int max, int use_ldif )
5419 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
5420 ConfigType etype = ce->ce_type;
5421 int count = 0, rc = 0;
5423 /* Reverse ce list */
5424 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
5425 if (ce2->ce_type != etype) {
5430 ce2->ce_sibs = cetmp;
5433 if ( max && count >= max ) {
5439 /* Move original to a temp name until increments are done */
5441 ce->ce_entry->e_private = NULL;
5442 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5443 base+BIGTMP, 0, use_ldif );
5444 ce->ce_entry->e_private = ce;
5446 /* start incrementing */
5447 for (ce2=cetmp; ce2; ce2=ce3) {
5449 ce2->ce_sibs = cerem;
5452 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5453 count+base, 0, use_ldif );
5457 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5458 base, 0, use_ldif );
5463 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5464 CfEntryInfo *ce2, int old, int use_ldif )
5468 /* Renumber original to a temp value */
5469 ce->ce_entry->e_private = NULL;
5470 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5471 old+BIGTMP, 0, use_ldif );
5472 ce->ce_entry->e_private = ce;
5474 /* start decrementing */
5475 for (; ce2 != ce; ce2=ce2->ce_sibs) {
5476 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5477 count+old, 0, use_ldif );
5480 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5481 count+old, 0, use_ldif );
5484 /* Parse an LDAP entry into config directives, then store in underlying
5488 config_back_add( Operation *op, SlapReply *rs )
5494 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
5495 NULL, ACL_WADD, NULL )) {
5496 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5501 * Check for attribute ACL
5503 if ( !acl_check_modlist( op, op->ora_e, op->orm_modlist )) {
5504 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5505 rs->sr_text = "no write access to attribute";
5509 cfb = (CfBackInfo *)op->o_bd->be_private;
5511 /* add opattrs for syncprov */
5513 char textbuf[SLAP_TEXT_BUFLEN];
5514 size_t textlen = sizeof textbuf;
5515 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1, NULL,
5516 &rs->sr_text, textbuf, sizeof( textbuf ) );
5517 if ( rs->sr_err != LDAP_SUCCESS )
5519 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
5520 if ( rs->sr_err != LDAP_SUCCESS ) {
5521 Debug( LDAP_DEBUG_TRACE,
5522 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
5523 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
5528 if ( op->o_abandon ) {
5529 rs->sr_err = SLAPD_ABANDON;
5532 ldap_pvt_thread_pool_pause( &connection_pool );
5535 * 1) check for existence of entry
5536 * 2) check for sibling renumbering
5537 * 3) perform internal add
5538 * 4) perform any necessary renumbering
5539 * 5) store entry in underlying database
5541 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
5542 if ( rs->sr_err != LDAP_SUCCESS ) {
5543 rs->sr_text = ca.cr_msg;
5548 CfEntryInfo *ce = ca.ca_entry->e_private;
5549 req_add_s addr = op->oq_add;
5550 op->o_tag = LDAP_REQ_MODRDN;
5551 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
5552 op->o_tag = LDAP_REQ_ADD;
5554 if ( rs->sr_err != LDAP_SUCCESS ) {
5559 if ( cfb->cb_use_ldif ) {
5560 BackendDB *be = op->o_bd;
5561 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5562 struct berval dn, ndn;
5564 op->o_bd = &cfb->cb_db;
5566 /* Save current rootdn; use the underlying DB's rootdn */
5569 op->o_dn = op->o_bd->be_rootdn;
5570 op->o_ndn = op->o_bd->be_rootndn;
5572 scp = op->o_callback;
5573 op->o_callback = ≻
5574 op->o_bd->be_add( op, rs );
5576 op->o_callback = scp;
5582 ldap_pvt_thread_pool_resume( &connection_pool );
5585 { int repl = op->o_dont_replicate;
5586 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
5587 rs->sr_text = NULL; /* Set after config_add_internal */
5588 rs->sr_err = LDAP_SUCCESS;
5589 op->o_dont_replicate = 1;
5591 send_ldap_result( op, rs );
5592 op->o_dont_replicate = repl;
5594 slap_graduate_commit_csn( op );
5598 typedef struct delrec {
5599 struct delrec *next;
5605 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
5611 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
5612 ca->line[0] == '{' )
5614 char *ptr = strchr( ca->line + 1, '}' );
5618 ca->valx = strtol( ca->line + 1, &next, 0 );
5619 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
5625 rc = config_parse_add( ct, ca, i );
5633 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
5636 int rc = LDAP_UNWILLING_TO_PERFORM;
5638 Entry *e = ce->ce_entry;
5639 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
5644 delrec *dels = NULL, *deltail = NULL;
5646 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5647 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
5649 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5650 if (ml->sml_desc == slap_schema.si_ad_objectClass)
5654 colst = count_ocs( oc_at, &nocs );
5656 /* make sure add/del flags are clear; should always be true */
5657 for ( s = save_attrs; s; s = s->a_next ) {
5658 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
5661 e->e_attrs = attrs_dup( e->e_attrs );
5663 init_config_argv( ca );
5666 ca->ca_private = ce->ce_private;
5668 ca->fname = "slapd";
5670 strcpy( ca->log, "back-config" );
5672 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5673 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5674 switch (ml->sml_op) {
5675 case LDAP_MOD_DELETE:
5676 case LDAP_MOD_REPLACE:
5677 case SLAP_MOD_SOFTDEL:
5679 BerVarray vals = NULL, nvals = NULL;
5681 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
5683 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
5684 ml->sml_desc->ad_cname.bv_val );
5687 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5688 vals = ml->sml_values;
5689 nvals = ml->sml_nvalues;
5690 ml->sml_values = NULL;
5691 ml->sml_nvalues = NULL;
5693 /* If we're deleting by values, remember the indexes of the
5694 * values we deleted.
5696 if ( ct && ml->sml_values ) {
5698 i = ml->sml_numvals;
5699 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
5710 rc = modify_delete_vindex(e, &ml->sml_mod,
5711 get_permissiveModify(op),
5712 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
5713 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5714 ml->sml_values = vals;
5715 ml->sml_nvalues = nvals;
5717 if ( rc == LDAP_NO_SUCH_ATTRIBUTE && ml->sml_op == SLAP_MOD_SOFTDEL )
5721 /* FIXME: check rc before fallthru? */
5725 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5727 case SLAP_MOD_ADD_IF_NOT_PRESENT:
5728 if ( ml->sml_op == SLAP_MOD_ADD_IF_NOT_PRESENT
5729 && attr_find( e->e_attrs, ml->sml_desc ) )
5736 case SLAP_MOD_SOFTADD: {
5737 int mop = ml->sml_op;
5739 ml->sml_op = LDAP_MOD_ADD;
5741 if ( ct->arg_type & ARG_NO_INSERT ) {
5742 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
5744 navals = a->a_numvals;
5747 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
5748 if ( ml->sml_values[i].bv_val[0] == '{' &&
5751 char *next, *val = ml->sml_values[i].bv_val + 1;
5754 j = strtol( val, &next, 0 );
5755 if ( next == val || next[ 0 ] != '}' || j < navals ) {
5757 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
5758 ml->sml_desc->ad_cname.bv_val );
5762 rc = check_vals( ct, ca, ml, 0 );
5763 if ( rc ) goto out_noop;
5766 rc = modify_add_values(e, &ml->sml_mod,
5767 get_permissiveModify(op),
5768 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5770 /* If value already exists, show success here
5771 * and ignore this operation down below.
5773 if ( mop == SLAP_MOD_SOFTADD ) {
5774 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
5784 case LDAP_MOD_INCREMENT: /* FIXME */
5789 if(rc != LDAP_SUCCESS) break;
5792 if ( rc == LDAP_SUCCESS) {
5793 /* check that the entry still obeys the schema */
5794 rc = entry_schema_check(op, e, NULL, 0, 0, NULL,
5795 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5797 if ( rc ) goto out_noop;
5799 /* Basic syntax checks are OK. Do the actual settings. */
5800 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5801 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5802 if ( !ct ) continue;
5804 s = attr_find( save_attrs, ml->sml_desc );
5805 a = attr_find( e->e_attrs, ml->sml_desc );
5807 switch (ml->sml_op) {
5808 case LDAP_MOD_DELETE:
5809 case LDAP_MOD_REPLACE: {
5810 BerVarray vals = NULL, nvals = NULL;
5813 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5814 vals = ml->sml_values;
5815 nvals = ml->sml_nvalues;
5816 ml->sml_values = NULL;
5817 ml->sml_nvalues = NULL;
5820 if ( ml->sml_values )
5823 /* If we didn't delete the whole attribute */
5824 if ( ml->sml_values && a ) {
5825 struct berval *mvals;
5828 if ( ml->sml_nvalues )
5829 mvals = ml->sml_nvalues;
5831 mvals = ml->sml_values;
5833 /* use the indexes we saved up above */
5834 for (i=0; i < d->nidx; i++) {
5835 struct berval bv = *mvals++;
5836 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
5837 bv.bv_val[0] == '{' ) {
5838 ptr = strchr( bv.bv_val, '}' ) + 1;
5839 bv.bv_len -= ptr - bv.bv_val;
5842 ca->line = bv.bv_val;
5843 ca->valx = d->idx[i];
5844 config_parse_vals(ct, ca, d->idx[i] );
5845 rc = config_del_vals( ct, ca );
5846 if ( rc != LDAP_SUCCESS ) break;
5848 s->a_flags |= SLAP_ATTR_IXDEL;
5849 for (j=i+1; j < d->nidx; j++)
5850 if ( d->idx[j] >d->idx[i] )
5857 rc = config_del_vals( ct, ca );
5858 if ( rc ) rc = LDAP_OTHER;
5860 s->a_flags |= SLAP_ATTR_IXDEL;
5862 if ( ml->sml_values ) {
5867 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5868 ml->sml_values = vals;
5869 ml->sml_nvalues = nvals;
5871 if ( !vals || rc != LDAP_SUCCESS )
5874 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5879 for (i=0; ml->sml_values[i].bv_val; i++) {
5880 ca->line = ml->sml_values[i].bv_val;
5882 rc = config_modify_add( ct, ca, ml->sml_desc, i );
5885 a->a_flags |= SLAP_ATTR_IXADD;
5892 /* Undo for a failed operation */
5893 if ( rc != LDAP_SUCCESS ) {
5894 ConfigReply msg = ca->reply;
5895 for ( s = save_attrs; s; s = s->a_next ) {
5896 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
5897 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5898 ct = config_find_table( colst, nocs, s->a_desc, ca );
5899 a = attr_find( e->e_attrs, s->a_desc );
5901 /* clear the flag so the add check below will skip it */
5902 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5906 config_del_vals( ct, ca );
5908 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5909 ca->line = s->a_vals[i].bv_val;
5911 config_modify_add( ct, ca, s->a_desc, i );
5915 for ( a = e->e_attrs; a; a = a->a_next ) {
5916 if ( a->a_flags & SLAP_ATTR_IXADD ) {
5917 ct = config_find_table( colst, nocs, a->a_desc, ca );
5921 config_del_vals( ct, ca );
5922 s = attr_find( save_attrs, a->a_desc );
5924 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5925 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5926 ca->line = s->a_vals[i].bv_val;
5928 config_modify_add( ct, ca, s->a_desc, i );
5939 if ( rc == LDAP_SUCCESS ) {
5940 attrs_free( save_attrs );
5943 attrs_free( e->e_attrs );
5944 e->e_attrs = save_attrs;
5946 ch_free( ca->argv );
5947 if ( colst ) ch_free( colst );
5949 deltail = dels->next;
5958 config_back_modify( Operation *op, SlapReply *rs )
5961 CfEntryInfo *ce, *last;
5963 ConfigArgs ca = {0};
5966 AttributeDescription *rad = NULL;
5969 cfb = (CfBackInfo *)op->o_bd->be_private;
5971 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5974 rs->sr_matched = last->ce_entry->e_name.bv_val;
5975 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5979 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
5980 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5984 /* Get type of RDN */
5985 rdn = ce->ce_entry->e_nname;
5986 ptr = strchr( rdn.bv_val, '=' );
5987 rdn.bv_len = ptr - rdn.bv_val;
5988 rs->sr_err = slap_bv2ad( &rdn, &rad, &rs->sr_text );
5989 if ( rs->sr_err != LDAP_SUCCESS ) {
5993 /* Some basic validation... */
5994 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5995 /* Don't allow Modify of RDN; must use ModRdn for that. */
5996 if ( ml->sml_desc == rad ) {
5997 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
5998 rs->sr_text = "Use modrdn to change the entry name";
6001 /* Internal update of contextCSN? */
6002 if ( ml->sml_desc == slap_schema.si_ad_contextCSN && op->o_conn->c_conn_idx == -1 ) {
6008 slap_mods_opattrs( op, &op->orm_modlist, 1 );
6011 if ( op->o_abandon ) {
6012 rs->sr_err = SLAPD_ABANDON;
6015 ldap_pvt_thread_pool_pause( &connection_pool );
6019 * 1) perform the Modify on the cached Entry.
6020 * 2) verify that the Entry still satisfies the schema.
6021 * 3) perform the individual config operations.
6022 * 4) store Modified entry in underlying LDIF backend.
6024 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
6026 rs->sr_text = ca.cr_msg;
6027 } else if ( cfb->cb_use_ldif ) {
6028 BackendDB *be = op->o_bd;
6029 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
6030 struct berval dn, ndn;
6032 op->o_bd = &cfb->cb_db;
6036 op->o_dn = op->o_bd->be_rootdn;
6037 op->o_ndn = op->o_bd->be_rootndn;
6039 scp = op->o_callback;
6040 op->o_callback = ≻
6041 op->o_bd->be_modify( op, rs );
6043 op->o_callback = scp;
6049 ldap_pvt_thread_pool_resume( &connection_pool );
6051 send_ldap_result( op, rs );
6052 slap_graduate_commit_csn( op );
6057 config_back_modrdn( Operation *op, SlapReply *rs )
6060 CfEntryInfo *ce, *last;
6064 cfb = (CfBackInfo *)op->o_bd->be_private;
6066 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6069 rs->sr_matched = last->ce_entry->e_name.bv_val;
6070 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6073 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
6074 NULL, ACL_WRITE, NULL )) {
6075 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6079 if ( ce->ce_parent )
6080 parent = ce->ce_parent->ce_entry;
6082 parent = (Entry *)&slap_entry_root;
6083 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
6084 NULL, ACL_WRITE, NULL )) {
6085 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6090 /* We don't allow moving objects to new parents.
6091 * Generally we only allow reordering a set of ordered entries.
6093 if ( op->orr_newSup ) {
6094 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6098 /* If newRDN == oldRDN, quietly succeed */
6099 dnRdn( &op->o_req_ndn, &rdn );
6100 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
6101 rs->sr_err = LDAP_SUCCESS;
6105 /* Current behavior, subject to change as needed:
6107 * For backends and overlays, we only allow renumbering.
6108 * For schema, we allow renaming with the same number.
6109 * Otherwise, the op is not allowed.
6112 if ( ce->ce_type == Cft_Schema ) {
6116 /* Can't alter the main cn=schema entry */
6117 if ( ce->ce_parent->ce_type == Cft_Global ) {
6118 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6119 rs->sr_text = "renaming not allowed for this entry";
6123 /* We could support this later if desired */
6124 ptr1 = ber_bvchr( &rdn, '}' );
6125 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
6126 len = ptr1 - rdn.bv_val;
6127 if ( len != ptr2 - op->orr_newrdn.bv_val ||
6128 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
6129 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6130 rs->sr_text = "schema reordering not supported";
6133 } else if ( ce->ce_type == Cft_Database ||
6134 ce->ce_type == Cft_Overlay ) {
6135 char *ptr1, *ptr2, *iptr1, *iptr2;
6138 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
6139 if ( *iptr2 != '{' ) {
6140 rs->sr_err = LDAP_NAMING_VIOLATION;
6141 rs->sr_text = "new ordering index is required";
6145 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
6146 ptr1 = ber_bvchr( &rdn, '}' );
6147 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
6149 rs->sr_err = LDAP_NAMING_VIOLATION;
6150 rs->sr_text = "new ordering index is required";
6154 len1 = ptr1 - rdn.bv_val;
6155 len2 = ptr2 - op->orr_newrdn.bv_val;
6157 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
6158 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
6159 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6160 rs->sr_text = "changing database/overlay type not allowed";
6163 ixold = strtol( iptr1, NULL, 0 );
6164 ixnew = strtol( iptr2, &ptr1, 0 );
6165 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
6166 rs->sr_err = LDAP_NAMING_VIOLATION;
6169 /* config DB is always 0, cannot be changed */
6170 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
6171 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
6175 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6176 rs->sr_text = "renaming not supported for this entry";
6180 if ( op->o_abandon ) {
6181 rs->sr_err = SLAPD_ABANDON;
6184 ldap_pvt_thread_pool_pause( &connection_pool );
6186 if ( ce->ce_type == Cft_Schema ) {
6187 req_modrdn_s modr = op->oq_modrdn;
6190 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
6191 if ( rs->sr_err == LDAP_SUCCESS ) {
6192 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
6193 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
6196 op->oq_modrdn = modr;
6198 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
6199 req_modrdn_s modr = op->oq_modrdn;
6202 /* Advance to first of this type */
6203 cprev = &ce->ce_parent->ce_kids;
6204 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
6205 cprev = &ce2->ce_sibs;
6208 /* Skip the -1 entry */
6209 if ( ce->ce_type == Cft_Database ) {
6210 cprev = &ce2->ce_sibs;
6216 /* Remove from old slot */
6217 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
6218 cprev = &ce2->ce_sibs;
6219 *cprev = ce->ce_sibs;
6220 ceold = ce->ce_sibs;
6222 /* Insert into new slot */
6224 for ( i=0; i<ixnew; i++ ) {
6228 cprev = &ce2->ce_sibs;
6230 ce->ce_sibs = *cprev;
6235 /* NOTE: These should be encoded in the OC tables, not inline here */
6236 if ( ce->ce_type == Cft_Database )
6237 backend_db_move( ce->ce_be, ixnew );
6238 else if ( ce->ce_type == Cft_Overlay )
6239 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
6241 if ( ixold < ixnew ) {
6242 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
6245 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
6246 ixold - ixnew, cfb->cb_use_ldif );
6248 op->oq_modrdn = modr;
6251 ldap_pvt_thread_pool_resume( &connection_pool );
6253 send_ldap_result( op, rs );
6258 config_back_delete( Operation *op, SlapReply *rs )
6260 #ifdef SLAP_CONFIG_DELETE
6262 CfEntryInfo *ce, *last, *ce2;
6264 cfb = (CfBackInfo *)op->o_bd->be_private;
6266 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6269 rs->sr_matched = last->ce_entry->e_name.bv_val;
6270 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6271 } else if ( ce->ce_kids ) {
6272 rs->sr_err = LDAP_NOT_ALLOWED_ON_NONLEAF;
6273 } else if ( op->o_abandon ) {
6274 rs->sr_err = SLAPD_ABANDON;
6275 } else if ( ce->ce_type == Cft_Overlay ||
6276 ce->ce_type == Cft_Database ||
6277 ce->ce_type == Cft_Misc ){
6281 ldap_pvt_thread_pool_pause( &connection_pool );
6283 if ( ce->ce_type == Cft_Overlay ){
6284 overlay_remove( ce->ce_be, (slap_overinst *)ce->ce_bi, op );
6285 } else if ( ce->ce_type == Cft_Misc ) {
6287 * only Cft_Misc objects that have a co_lddel handler set in
6288 * the ConfigOCs struct can be deleted. This code also
6289 * assumes that the entry can be only have one objectclass
6290 * with co_type == Cft_Misc
6292 ConfigOCs co, *coptr;
6296 oc_at = attr_find( ce->ce_entry->e_attrs,
6297 slap_schema.si_ad_objectClass );
6299 rs->sr_err = LDAP_OTHER;
6300 rs->sr_text = "objectclass not found";
6301 ldap_pvt_thread_pool_resume( &connection_pool );
6304 for ( i=0; !BER_BVISNULL(&oc_at->a_nvals[i]); i++ ) {
6305 co.co_name = &oc_at->a_nvals[i];
6306 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
6307 if ( coptr == NULL || coptr->co_type != Cft_Misc ) {
6310 if ( ! coptr->co_lddel || coptr->co_lddel( ce, op ) ){
6311 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6312 if ( ! coptr->co_lddel ) {
6313 rs->sr_text = "No delete handler found";
6315 rs->sr_err = LDAP_OTHER;
6316 /* FIXME: We should return a helpful error message
6319 ldap_pvt_thread_pool_resume( &connection_pool );
6324 } else if (ce->ce_type == Cft_Database ) {
6325 if ( ce->ce_be == frontendDB || ce->ce_be == op->o_bd ){
6326 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6327 rs->sr_text = "Cannot delete config or frontend database";
6328 ldap_pvt_thread_pool_resume( &connection_pool );
6331 if ( ce->ce_be->bd_info->bi_db_close ) {
6332 ce->ce_be->bd_info->bi_db_close( ce->ce_be, NULL );
6334 backend_destroy_one( ce->ce_be, 1);
6337 /* remove CfEntryInfo from the siblings list */
6338 if ( ce->ce_parent->ce_kids == ce ) {
6339 ce->ce_parent->ce_kids = ce->ce_sibs;
6341 for ( ce2 = ce->ce_parent->ce_kids ; ce2; ce2 = ce2->ce_sibs ) {
6342 if ( ce2->ce_sibs == ce ) {
6343 ce2->ce_sibs = ce->ce_sibs;
6349 /* remove from underlying database */
6350 if ( cfb->cb_use_ldif ) {
6351 BackendDB *be = op->o_bd;
6352 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
6353 struct berval dn, ndn, req_dn, req_ndn;
6355 op->o_bd = &cfb->cb_db;
6359 req_dn = op->o_req_dn;
6360 req_ndn = op->o_req_ndn;
6362 op->o_dn = op->o_bd->be_rootdn;
6363 op->o_ndn = op->o_bd->be_rootndn;
6364 op->o_req_dn = ce->ce_entry->e_name;
6365 op->o_req_ndn = ce->ce_entry->e_nname;
6367 scp = op->o_callback;
6368 op->o_callback = ≻
6369 op->o_bd->be_delete( op, rs );
6371 op->o_callback = scp;
6374 op->o_req_dn = req_dn;
6375 op->o_req_ndn = req_ndn;
6378 /* renumber siblings */
6379 iptr = ber_bvchr( &op->o_req_ndn, '{' ) + 1;
6380 ixold = strtol( iptr, NULL, 0 );
6381 for (ce2 = ce->ce_sibs, count=0; ce2; ce2=ce2->ce_sibs) {
6382 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
6383 count+ixold, 0, cfb->cb_use_ldif );
6387 ce->ce_entry->e_private=NULL;
6388 entry_free(ce->ce_entry);
6390 ldap_pvt_thread_pool_resume( &connection_pool );
6392 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6396 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6397 #endif /* SLAP_CONFIG_DELETE */
6398 send_ldap_result( op, rs );
6403 config_back_search( Operation *op, SlapReply *rs )
6406 CfEntryInfo *ce, *last;
6409 cfb = (CfBackInfo *)op->o_bd->be_private;
6411 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6414 rs->sr_matched = last->ce_entry->e_name.bv_val;
6415 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6418 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
6419 ACL_SEARCH, NULL, &mask ))
6421 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
6422 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6424 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6428 switch ( op->ors_scope ) {
6429 case LDAP_SCOPE_BASE:
6430 case LDAP_SCOPE_SUBTREE:
6431 rs->sr_err = config_send( op, rs, ce, 0 );
6434 case LDAP_SCOPE_ONELEVEL:
6435 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
6436 rs->sr_err = config_send( op, rs, ce, 1 );
6445 send_ldap_result( op, rs );
6449 /* no-op, we never free entries */
6450 int config_entry_release(
6455 if ( !e->e_private ) {
6458 return LDAP_SUCCESS;
6461 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
6463 int config_back_entry_get(
6467 AttributeDescription *at,
6472 CfEntryInfo *ce, *last;
6473 int rc = LDAP_NO_SUCH_OBJECT;
6475 cfb = (CfBackInfo *)op->o_bd->be_private;
6477 ce = config_find_base( cfb->cb_root, ndn, &last );
6479 *ent = ce->ce_entry;
6482 if ( oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
6483 rc = LDAP_NO_SUCH_ATTRIBUTE;
6493 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
6494 ConfigTable *ct, ConfigArgs *c )
6498 for (; at && *at; at++) {
6499 /* Skip the naming attr */
6500 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
6502 for (i=0;ct[i].name;i++) {
6503 if (ct[i].ad == (*at)->sat_ad) {
6504 rc = config_get_vals(&ct[i], c);
6505 /* NOTE: tolerate that config_get_vals()
6506 * returns success with no values */
6507 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
6508 if ( c->rvalue_nvals )
6509 rc = attr_merge(e, ct[i].ad, c->rvalue_vals,
6512 slap_syntax_validate_func *validate =
6513 ct[i].ad->ad_type->sat_syntax->ssyn_validate;
6516 for ( j=0; c->rvalue_vals[j].bv_val; j++ ) {
6517 rc = ordered_value_validate( ct[i].ad,
6518 &c->rvalue_vals[j], LDAP_MOD_ADD );
6520 Debug( LDAP_DEBUG_ANY,
6521 "config_build_attrs: error %d on %s value #%d\n",
6522 rc, ct[i].ad->ad_cname.bv_val, j );
6528 rc = attr_merge_normalize(e, ct[i].ad,
6529 c->rvalue_vals, NULL);
6531 ber_bvarray_free( c->rvalue_nvals );
6532 ber_bvarray_free( c->rvalue_vals );
6534 Debug( LDAP_DEBUG_ANY,
6535 "config_build_attrs: error %d on %s\n",
6536 rc, ct[i].ad->ad_cname.bv_val, 0 );
6547 /* currently (2010) does not access rs except possibly writing rs->sr_err */
6550 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
6551 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
6553 Entry *e = entry_alloc();
6554 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
6556 struct berval ad_name;
6557 AttributeDescription *ad = NULL;
6560 const char *text = "";
6564 CfEntryInfo *ceprev = NULL;
6566 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
6569 ce->ce_type = main->co_type;
6570 ce->ce_parent = parent;
6572 pdn = parent->ce_entry->e_nname;
6573 if ( parent->ce_kids && parent->ce_kids->ce_type <= ce->ce_type )
6574 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
6575 ceprev->ce_type <= ce->ce_type;
6576 ceprev = ceprev->ce_sibs );
6581 ce->ce_private = c->ca_private;
6585 build_new_dn( &e->e_name, &pdn, rdn, NULL );
6586 ber_dupbv( &e->e_nname, &e->e_name );
6588 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6589 main->co_name, NULL );
6591 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6592 extra->co_name, NULL );
6593 ptr = strchr(rdn->bv_val, '=');
6594 ad_name.bv_val = rdn->bv_val;
6595 ad_name.bv_len = ptr - rdn->bv_val;
6596 rc = slap_bv2ad( &ad_name, &ad, &text );
6601 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
6602 attr_merge_normalize_one(e, ad, &val, NULL );
6605 c->table = main->co_type;
6606 if ( oc->soc_required ) {
6607 rc = config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
6608 if ( rc ) goto fail;
6611 if ( oc->soc_allowed ) {
6612 rc = config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
6613 if ( rc ) goto fail;
6618 c->table = extra->co_type;
6619 if ( oc->soc_required ) {
6620 rc = config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
6621 if ( rc ) goto fail;
6624 if ( oc->soc_allowed ) {
6625 rc = config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
6626 if ( rc ) goto fail;
6630 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
6631 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
6632 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
6633 if ( rc != LDAP_SUCCESS ) {
6635 Debug( LDAP_DEBUG_ANY,
6636 "config_build_entry: build \"%s\" failed: \"%s\"\n",
6637 rdn->bv_val, text, 0);
6640 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
6643 op->ora_modlist = NULL;
6644 slap_add_opattrs( op, NULL, NULL, 0, 0 );
6645 if ( !op->o_noop ) {
6646 SlapReply rs2 = {REP_RESULT};
6647 op->o_bd->be_add( op, &rs2 );
6648 rs->sr_err = rs2.sr_err;
6649 rs_assert_done( &rs2 );
6650 if ( ( rs2.sr_err != LDAP_SUCCESS )
6651 && (rs2.sr_err != LDAP_ALREADY_EXISTS) ) {
6657 ce->ce_sibs = ceprev->ce_sibs;
6658 ceprev->ce_sibs = ce;
6659 } else if ( parent ) {
6660 ce->ce_sibs = parent->ce_kids;
6661 parent->ce_kids = ce;
6668 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
6669 Operation *op, SlapReply *rs )
6672 ConfigFile *cf = c->ca_private;
6674 struct berval bv, rdn;
6676 for (; cf; cf=cf->c_sibs, c->depth++) {
6677 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
6678 !cf->c_om_head && !cf->c_syn_head ) continue;
6679 c->value_dn.bv_val = c->log;
6680 LUTIL_SLASHPATH( cf->c_file.bv_val );
6681 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
6686 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
6688 ptr = strchr( bv.bv_val, '.' );
6690 bv.bv_len = ptr - bv.bv_val;
6691 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
6692 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6693 /* FIXME: how can indicate error? */
6696 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
6698 c->value_dn.bv_len += bv.bv_len;
6699 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
6700 rdnNormalize( 0, NULL, NULL, &c->value_dn, &rdn, NULL );
6703 e = config_build_entry( op, rs, ceparent, c, &rdn,
6704 &CFOC_SCHEMA, NULL );
6705 ch_free( rdn.bv_val );
6708 } else if ( e && cf->c_kids ) {
6709 c->ca_private = cf->c_kids;
6710 config_build_schema_inc( c, e->e_private, op, rs );
6716 #ifdef SLAPD_MODULES
6719 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
6720 Operation *op, SlapReply *rs )
6725 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
6726 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
6728 c->value_dn.bv_val = c->log;
6729 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
6730 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6731 /* FIXME: how can indicate error? */
6735 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
6744 config_check_schema(Operation *op, CfBackInfo *cfb)
6746 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
6748 CfEntryInfo *ce, *last;
6751 /* If there's no root entry, we must be in the midst of converting */
6752 if ( !cfb->cb_root )
6755 /* Make sure the main schema entry exists */
6756 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
6763 /* Make sure it's up to date */
6764 if ( cf_om_tail != om_sys_tail ) {
6765 a = attr_find( e->e_attrs, cfAd_om );
6767 if ( a->a_nvals != a->a_vals )
6768 ber_bvarray_free( a->a_nvals );
6769 ber_bvarray_free( a->a_vals );
6774 oidm_unparse( &bv, NULL, NULL, 1 );
6775 attr_merge_normalize( e, cfAd_om, bv, NULL );
6776 ber_bvarray_free( bv );
6777 cf_om_tail = om_sys_tail;
6779 if ( cf_at_tail != at_sys_tail ) {
6780 a = attr_find( e->e_attrs, cfAd_attr );
6782 if ( a->a_nvals != a->a_vals )
6783 ber_bvarray_free( a->a_nvals );
6784 ber_bvarray_free( a->a_vals );
6789 at_unparse( &bv, NULL, NULL, 1 );
6790 attr_merge_normalize( e, cfAd_attr, bv, NULL );
6791 ber_bvarray_free( bv );
6792 cf_at_tail = at_sys_tail;
6794 if ( cf_oc_tail != oc_sys_tail ) {
6795 a = attr_find( e->e_attrs, cfAd_oc );
6797 if ( a->a_nvals != a->a_vals )
6798 ber_bvarray_free( a->a_nvals );
6799 ber_bvarray_free( a->a_vals );
6804 oc_unparse( &bv, NULL, NULL, 1 );
6805 attr_merge_normalize( e, cfAd_oc, bv, NULL );
6806 ber_bvarray_free( bv );
6807 cf_oc_tail = oc_sys_tail;
6809 if ( cf_syn_tail != syn_sys_tail ) {
6810 a = attr_find( e->e_attrs, cfAd_syntax );
6812 if ( a->a_nvals != a->a_vals )
6813 ber_bvarray_free( a->a_nvals );
6814 ber_bvarray_free( a->a_vals );
6819 syn_unparse( &bv, NULL, NULL, 1 );
6820 attr_merge_normalize( e, cfAd_syntax, bv, NULL );
6821 ber_bvarray_free( bv );
6822 cf_syn_tail = syn_sys_tail;
6825 SlapReply rs = {REP_RESULT};
6826 c.ca_private = NULL;
6827 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
6828 &CFOC_SCHEMA, NULL );
6833 ce->ce_private = cfb->cb_config;
6834 cf_at_tail = at_sys_tail;
6835 cf_oc_tail = oc_sys_tail;
6836 cf_om_tail = om_sys_tail;
6837 cf_syn_tail = syn_sys_tail;
6842 static const char *defacl[] = {
6843 NULL, "to", "*", "by", "*", "none", NULL
6847 config_back_db_open( BackendDB *be, ConfigReply *cr )
6849 CfBackInfo *cfb = be->be_private;
6852 CfEntryInfo *ce, *ceparent;
6856 Connection conn = {0};
6857 OperationBuffer opbuf;
6859 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
6860 SlapReply rs = {REP_RESULT};
6861 void *thrctx = NULL;
6862 AccessControl *save_access;
6864 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
6866 /* If we have no explicitly configured ACLs, don't just use
6867 * the global ACLs. Explicitly deny access to everything.
6869 save_access = be->bd_self->be_acl;
6870 be->bd_self->be_acl = NULL;
6871 parse_acl(be->bd_self, "config_back_db_open", 0, 6, (char **)defacl, 0 );
6872 defacl_parsed = be->bd_self->be_acl;
6873 if ( save_access ) {
6874 be->bd_self->be_acl = save_access;
6876 Debug( LDAP_DEBUG_CONFIG, "config_back_db_open: "
6877 "No explicit ACL for back-config configured. "
6878 "Using hardcoded default\n", 0, 0, 0 );
6881 thrctx = ldap_pvt_thread_pool_context();
6882 connection_fake_init( &conn, &opbuf, thrctx );
6885 op->o_tag = LDAP_REQ_ADD;
6886 op->o_callback = &cb;
6887 op->o_bd = &cfb->cb_db;
6888 op->o_dn = op->o_bd->be_rootdn;
6889 op->o_ndn = op->o_bd->be_rootndn;
6891 if ( !cfb->cb_use_ldif ) {
6895 /* If we read the config from back-ldif, do some quick sanity checks */
6896 if ( cfb->cb_got_ldif ) {
6897 return config_check_schema( op, cfb );
6900 /* create root of tree */
6902 c.ca_private = cfb->cb_config;
6904 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
6914 #ifdef SLAPD_MODULES
6915 /* Create Module nodes... */
6916 if ( modpaths.mp_loads ) {
6917 if ( config_build_modules( &c, ceparent, op, &rs ) ){
6923 /* Create schema nodes... cn=schema will contain the hardcoded core
6924 * schema, read-only. Child objects will contain runtime loaded schema
6928 c.ca_private = NULL;
6929 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
6934 ce->ce_private = cfb->cb_config;
6935 cf_at_tail = at_sys_tail;
6936 cf_oc_tail = oc_sys_tail;
6937 cf_om_tail = om_sys_tail;
6938 cf_syn_tail = syn_sys_tail;
6940 /* Create schema nodes for included schema... */
6941 if ( cfb->cb_config->c_kids ) {
6944 c.ca_private = cfb->cb_config->c_kids;
6945 rc = config_build_schema_inc( &c, ce, op, &rs );
6951 /* Create backend nodes. Skip if they don't provide a cf_table.
6952 * There usually aren't any of these.
6956 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
6957 if (!bi->bi_cf_ocs) {
6958 /* If it only supports the old config mech, complain. */
6959 if ( bi->bi_config ) {
6960 Debug( LDAP_DEBUG_ANY,
6961 "WARNING: No dynamic config support for backend %s.\n",
6962 bi->bi_type, 0, 0 );
6967 if (!bi->bi_private) continue;
6970 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6971 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
6972 if ( rdn.bv_len >= sizeof( c.log ) ) {
6973 /* FIXME: holler ... */ ;
6976 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
6983 /* Create database nodes... */
6984 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
6985 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
6986 for ( i = -1, be = frontendDB ; be;
6987 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
6988 slap_overinfo *oi = NULL;
6990 if ( overlay_is_over( be )) {
6991 oi = be->bd_info->bi_private;
6997 /* If this backend supports the old config mechanism, but not
6998 * the new mech, complain.
7000 if ( !be->be_cf_ocs && bi->bi_db_config ) {
7001 Debug( LDAP_DEBUG_ANY,
7002 "WARNING: No dynamic config support for database %s.\n",
7003 bi->bi_type, 0, 0 );
7007 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
7008 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
7010 if ( rdn.bv_len >= sizeof( c.log ) ) {
7011 /* FIXME: holler ... */ ;
7015 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
7021 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd ) {
7022 rs_reinit( &rs, REP_RESULT );
7023 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
7025 /* Iterate through overlays */
7030 voidList *vl, *v0 = NULL;
7032 /* overlays are in LIFO order, must reverse stack */
7033 for (on=oi->oi_list; on; on=on->on_next) {
7034 vl = ch_malloc( sizeof( voidList ));
7039 for (j=0; vl; j++,vl=v0) {
7043 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
7044 Debug( LDAP_DEBUG_ANY,
7045 "WARNING: No dynamic config support for overlay %s.\n",
7046 on->on_bi.bi_type, 0, 0 );
7050 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
7051 "%s=" SLAP_X_ORDERED_FMT "%s",
7052 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
7053 if ( rdn.bv_len >= sizeof( c.log ) ) {
7054 /* FIXME: holler ... */ ;
7058 oe = config_build_entry( op, &rs, ce, &c, &rdn,
7059 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
7063 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd ) {
7064 rs_reinit( &rs, REP_RESULT );
7065 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
7071 ldap_pvt_thread_pool_context_reset( thrctx );
7073 if ( unsupp && cfb->cb_use_ldif ) {
7074 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
7075 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
7082 cfb_free_cffile( ConfigFile *cf )
7086 for (; cf; cf=next) {
7089 cfb_free_cffile( cf->c_kids );
7090 ch_free( cf->c_file.bv_val );
7091 ber_bvarray_free( cf->c_dseFiles );
7097 cfb_free_entries( CfEntryInfo *ce )
7101 for (; ce; ce=next) {
7104 cfb_free_entries( ce->ce_kids );
7105 ce->ce_entry->e_private = NULL;
7106 entry_free( ce->ce_entry );
7112 config_back_db_close( BackendDB *be, ConfigReply *cr )
7114 CfBackInfo *cfb = be->be_private;
7116 cfb_free_entries( cfb->cb_root );
7117 cfb->cb_root = NULL;
7119 if ( cfb->cb_db.bd_info ) {
7120 backend_shutdown( &cfb->cb_db );
7123 if ( defacl_parsed && be->be_acl != defacl_parsed ) {
7124 acl_free( defacl_parsed );
7125 defacl_parsed = NULL;
7132 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
7134 CfBackInfo *cfb = be->be_private;
7136 cfb_free_cffile( cfb->cb_config );
7138 ch_free( cfdir.bv_val );
7140 avl_free( CfOcTree, NULL );
7142 if ( cfb->cb_db.bd_info ) {
7143 cfb->cb_db.be_suffix = NULL;
7144 cfb->cb_db.be_nsuffix = NULL;
7145 BER_BVZERO( &cfb->cb_db.be_rootdn );
7146 BER_BVZERO( &cfb->cb_db.be_rootndn );
7148 backend_destroy_one( &cfb->cb_db, 0 );
7157 config_back_db_init( BackendDB *be, ConfigReply* cr )
7163 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
7164 cfn = cfb->cb_config;
7165 be->be_private = cfb;
7167 ber_dupbv( &be->be_rootdn, &config_rdn );
7168 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
7169 ber_dupbv( &dn, &be->be_rootdn );
7170 ber_bvarray_add( &be->be_suffix, &dn );
7171 ber_dupbv( &dn, &be->be_rootdn );
7172 ber_bvarray_add( &be->be_nsuffix, &dn );
7174 /* Hide from namingContexts */
7175 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
7177 /* Check ACLs on content of Adds by default */
7178 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_ACL_ADD;
7184 config_back_destroy( BackendInfo *bi )
7186 ldif_must_b64_encode_release();
7191 config_tool_entry_open( BackendDB *be, int mode )
7193 CfBackInfo *cfb = be->be_private;
7194 BackendInfo *bi = cfb->cb_db.bd_info;
7196 if ( bi && bi->bi_tool_entry_open )
7197 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
7204 config_tool_entry_close( BackendDB *be )
7206 CfBackInfo *cfb = be->be_private;
7207 BackendInfo *bi = cfb->cb_db.bd_info;
7209 if ( bi && bi->bi_tool_entry_close )
7210 return bi->bi_tool_entry_close( &cfb->cb_db );
7216 config_tool_entry_first( BackendDB *be )
7218 CfBackInfo *cfb = be->be_private;
7219 BackendInfo *bi = cfb->cb_db.bd_info;
7221 if ( bi && bi->bi_tool_entry_first ) {
7222 return bi->bi_tool_entry_first( &cfb->cb_db );
7224 if ( bi && bi->bi_tool_entry_first_x ) {
7225 return bi->bi_tool_entry_first_x( &cfb->cb_db,
7226 NULL, LDAP_SCOPE_DEFAULT, NULL );
7232 config_tool_entry_first_x(
7234 struct berval *base,
7238 CfBackInfo *cfb = be->be_private;
7239 BackendInfo *bi = cfb->cb_db.bd_info;
7241 if ( bi && bi->bi_tool_entry_first_x ) {
7242 return bi->bi_tool_entry_first_x( &cfb->cb_db, base, scope, f );
7248 config_tool_entry_next( BackendDB *be )
7250 CfBackInfo *cfb = be->be_private;
7251 BackendInfo *bi = cfb->cb_db.bd_info;
7253 if ( bi && bi->bi_tool_entry_next )
7254 return bi->bi_tool_entry_next( &cfb->cb_db );
7260 config_tool_entry_get( BackendDB *be, ID id )
7262 CfBackInfo *cfb = be->be_private;
7263 BackendInfo *bi = cfb->cb_db.bd_info;
7265 if ( bi && bi->bi_tool_entry_get )
7266 return bi->bi_tool_entry_get( &cfb->cb_db, id );
7271 static int entry_put_got_frontend=0;
7272 static int entry_put_got_config=0;
7274 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
7276 CfBackInfo *cfb = be->be_private;
7277 BackendInfo *bi = cfb->cb_db.bd_info;
7279 struct berval rdn, vals[ 2 ];
7281 OperationBuffer opbuf;
7283 Connection conn = {0};
7284 Operation *op = NULL;
7287 int isFrontendChild = 0;
7289 /* Create entry for frontend database if it does not exist already */
7290 if ( !entry_put_got_frontend ) {
7291 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
7292 STRLENOF( "olcDatabase" ))) {
7293 if ( strncmp( e->e_nname.bv_val +
7294 STRLENOF( "olcDatabase" ), "={-1}frontend",
7295 STRLENOF( "={-1}frontend" )) &&
7296 strncmp( e->e_nname.bv_val +
7297 STRLENOF( "olcDatabase" ), "=frontend",
7298 STRLENOF( "=frontend" ))) {
7300 vals[1].bv_val = NULL;
7301 memset( &ca, 0, sizeof(ConfigArgs));
7303 ca.bi = frontendDB->bd_info;
7304 ca.be->be_cf_ocs = &CFOC_FRONTEND;
7305 rdn.bv_val = ca.log;
7306 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7307 "%s=" SLAP_X_ORDERED_FMT "%s",
7308 cfAd_database->ad_cname.bv_val, -1,
7310 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
7311 &CFOC_DATABASE, ca.be->be_cf_ocs );
7312 thrctx = ldap_pvt_thread_pool_context();
7313 connection_fake_init2( &conn, &opbuf, thrctx,0 );
7315 op->o_bd = &cfb->cb_db;
7316 op->o_tag = LDAP_REQ_ADD;
7318 op->o_dn = be->be_rootdn;
7319 op->o_ndn = be->be_rootndn;
7320 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
7321 if ( rc != LDAP_SUCCESS ) {
7322 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
7323 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
7327 if ( ce && bi && bi->bi_tool_entry_put &&
7328 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
7329 entry_put_got_frontend++;
7331 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
7332 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
7336 if ( !strncmp( e->e_nname.bv_val +
7337 STRLENOF( "olcDatabase" ), "=frontend",
7338 STRLENOF( "=frontend" ) ) )
7340 struct berval rdn, pdn, ndn;
7341 dnParent( &e->e_nname, &pdn );
7342 rdn.bv_val = ca.log;
7343 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7344 "%s=" SLAP_X_ORDERED_FMT "%s",
7345 cfAd_database->ad_cname.bv_val, -1,
7346 frontendDB->bd_info->bi_type );
7347 build_new_dn( &ndn, &pdn, &rdn, NULL );
7348 ber_memfree( e->e_name.bv_val );
7350 ber_bvreplace( &e->e_nname, &e->e_name );
7352 entry_put_got_frontend++;
7358 /* Child entries of the frontend database, e.g. slapo-chain's back-ldap
7359 * instances, may appear before the config database entry in the ldif, skip
7360 * auto-creation of olcDatabase={0}config in such a case */
7361 if ( !entry_put_got_config &&
7362 !strncmp( e->e_nname.bv_val, "olcDatabase", STRLENOF( "olcDatabase" ))) {
7364 dnParent( &e->e_nname, &pdn );
7365 while ( pdn.bv_len ) {
7366 if ( !strncmp( pdn.bv_val, "olcDatabase",
7367 STRLENOF( "olcDatabase" ))) {
7368 if ( !strncmp( pdn.bv_val +
7369 STRLENOF( "olcDatabase" ), "={-1}frontend",
7370 STRLENOF( "={-1}frontend" )) ||
7371 !strncmp( pdn.bv_val +
7372 STRLENOF( "olcDatabase" ), "=frontend",
7373 STRLENOF( "=frontend" ))) {
7375 isFrontendChild = 1;
7379 dnParent( &pdn, &pdn );
7383 /* Create entry for config database if it does not exist already */
7384 if ( !entry_put_got_config && !isFrontend && !isFrontendChild ) {
7385 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
7386 STRLENOF( "olcDatabase" ))) {
7387 if ( strncmp( e->e_nname.bv_val +
7388 STRLENOF( "olcDatabase" ), "={0}config",
7389 STRLENOF( "={0}config" )) &&
7390 strncmp( e->e_nname.bv_val +
7391 STRLENOF( "olcDatabase" ), "=config",
7392 STRLENOF( "=config" )) ) {
7394 vals[1].bv_val = NULL;
7395 memset( &ca, 0, sizeof(ConfigArgs));
7396 ca.be = LDAP_STAILQ_FIRST( &backendDB );
7397 ca.bi = ca.be->bd_info;
7398 rdn.bv_val = ca.log;
7399 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7400 "%s=" SLAP_X_ORDERED_FMT "%s",
7401 cfAd_database->ad_cname.bv_val, 0,
7403 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
7406 thrctx = ldap_pvt_thread_pool_context();
7407 connection_fake_init2( &conn, &opbuf, thrctx,0 );
7409 op->o_bd = &cfb->cb_db;
7410 op->o_tag = LDAP_REQ_ADD;
7411 op->o_dn = be->be_rootdn;
7412 op->o_ndn = be->be_rootndn;
7415 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
7416 if ( rc != LDAP_SUCCESS ) {
7417 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
7418 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7421 if (ce && bi && bi->bi_tool_entry_put &&
7422 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
7423 entry_put_got_config++;
7425 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
7426 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7430 entry_put_got_config++;
7434 if ( bi && bi->bi_tool_entry_put &&
7435 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
7436 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
7443 AttributeDescription **desc;
7445 { "attribute", &cfAd_attr },
7446 { "backend", &cfAd_backend },
7447 { "database", &cfAd_database },
7448 { "include", &cfAd_include },
7449 { "ldapsyntax", &cfAd_syntax },
7450 { "objectclass", &cfAd_oc },
7451 { "objectidentifier", &cfAd_om },
7452 { "overlay", &cfAd_overlay },
7457 * add / delete: all types that may be added or deleted must use an
7458 * X-ORDERED attributeType for their RDN. Adding and deleting entries
7459 * should automatically renumber the index of any siblings as needed,
7460 * so that no gaps in the numbering sequence exist after the add/delete
7462 * What can be added:
7464 * backend objects for backend-specific config directives
7468 * delete: probably no support this time around.
7470 * modrdn: generally not done. Will be invoked automatically by add/
7471 * delete to update numbering sequence. Perform as an explicit operation
7472 * so that the renumbering effect may be replicated. Subtree rename must
7473 * be supported, since renumbering a database will affect all its child
7476 * modify: must be fully supported.
7480 config_back_initialize( BackendInfo *bi )
7482 ConfigTable *ct = config_back_cf_table;
7486 AttributeDescription *ad = NULL;
7488 static char *controls[] = {
7489 LDAP_CONTROL_MANAGEDSAIT,
7493 /* Make sure we don't exceed the bits reserved for userland */
7494 config_check_userland( CFG_LAST );
7496 bi->bi_controls = controls;
7501 bi->bi_destroy = config_back_destroy;
7503 bi->bi_db_init = config_back_db_init;
7504 bi->bi_db_config = 0;
7505 bi->bi_db_open = config_back_db_open;
7506 bi->bi_db_close = config_back_db_close;
7507 bi->bi_db_destroy = config_back_db_destroy;
7509 bi->bi_op_bind = config_back_bind;
7510 bi->bi_op_unbind = 0;
7511 bi->bi_op_search = config_back_search;
7512 bi->bi_op_compare = 0;
7513 bi->bi_op_modify = config_back_modify;
7514 bi->bi_op_modrdn = config_back_modrdn;
7515 bi->bi_op_add = config_back_add;
7516 bi->bi_op_delete = config_back_delete;
7517 bi->bi_op_abandon = 0;
7519 bi->bi_extended = 0;
7521 bi->bi_chk_referrals = 0;
7523 bi->bi_access_allowed = slap_access_allowed;
7525 bi->bi_connection_init = 0;
7526 bi->bi_connection_destroy = 0;
7528 bi->bi_entry_release_rw = config_entry_release;
7529 bi->bi_entry_get_rw = config_back_entry_get;
7531 bi->bi_tool_entry_open = config_tool_entry_open;
7532 bi->bi_tool_entry_close = config_tool_entry_close;
7533 bi->bi_tool_entry_first = config_tool_entry_first;
7534 bi->bi_tool_entry_first_x = config_tool_entry_first_x;
7535 bi->bi_tool_entry_next = config_tool_entry_next;
7536 bi->bi_tool_entry_get = config_tool_entry_get;
7537 bi->bi_tool_entry_put = config_tool_entry_put;
7540 argv[ 0 ] = "slapd";
7546 for (i=0; OidMacros[i].name; i++ ) {
7547 argv[1] = OidMacros[i].name;
7548 argv[2] = OidMacros[i].oid;
7549 parse_oidm( &ca, 0, NULL );
7552 bi->bi_cf_ocs = cf_ocs;
7554 i = config_register_schema( ct, cf_ocs );
7557 i = slap_str2ad( "olcDatabase", &olcDatabaseDummy[0].ad, &text );
7560 /* setup olcRootPW to be base64-encoded when written in LDIF form;
7561 * basically, we don't care if it fails */
7562 i = slap_str2ad( "olcRootPW", &ad, &text );
7564 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
7565 "warning, unable to get \"olcRootPW\" "
7566 "attribute description: %d: %s\n",
7569 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
7570 ad->ad_type->sat_oid );
7573 /* set up the notable AttributeDescriptions */
7575 for (;ct->name;ct++) {
7576 if (strcmp(ct->name, ads[i].name)) continue;
7577 *ads[i].desc = ct->ad;
7579 if (!ads[i].name) break;