1 /* bconfig.c - the config backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005-2011 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was originally developed by Howard Chu for inclusion
18 * in OpenLDAP Software.
24 #include <ac/string.h>
28 #include <ac/unistd.h>
33 #include "slapi/slapi.h"
41 #define CONFIG_RDN "cn=config"
42 #define SCHEMA_RDN "cn=schema"
44 static struct berval config_rdn = BER_BVC(CONFIG_RDN);
45 static struct berval schema_rdn = BER_BVC(SCHEMA_RDN);
47 extern int slap_DN_strict; /* dn.c */
50 typedef struct modpath_s {
51 struct modpath_s *mp_next;
52 struct berval mp_path;
56 static ModPaths modpaths, *modlast = &modpaths, *modcur = &modpaths;
59 typedef struct ConfigFile {
60 struct ConfigFile *c_sibs;
61 struct ConfigFile *c_kids;
63 AttributeType *c_at_head, *c_at_tail;
64 ContentRule *c_cr_head, *c_cr_tail;
65 ObjectClass *c_oc_head, *c_oc_tail;
66 OidMacro *c_om_head, *c_om_tail;
67 Syntax *c_syn_head, *c_syn_tail;
72 ConfigFile *cb_config;
74 BackendDB cb_db; /* underlying database */
79 static CfBackInfo cfBackInfo;
81 static char *passwd_salt;
83 static char *logfileName;
84 #ifdef SLAP_AUTH_REWRITE
85 static BerVarray authz_rewrites;
88 static struct berval cfdir;
91 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
92 *cfAd_include, *cfAd_attr, *cfAd_oc, *cfAd_om, *cfAd_syntax;
94 static ConfigFile *cfn;
96 static Avlnode *CfOcTree;
98 /* System schema state */
99 extern AttributeType *at_sys_tail; /* at.c */
100 extern ObjectClass *oc_sys_tail; /* oc.c */
101 extern OidMacro *om_sys_tail; /* oidm.c */
102 extern Syntax *syn_sys_tail; /* syntax.c */
103 static AttributeType *cf_at_tail;
104 static ObjectClass *cf_oc_tail;
105 static OidMacro *cf_om_tail;
106 static Syntax *cf_syn_tail;
108 static int config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca,
109 SlapReply *rs, int *renumber, Operation *op );
111 static int config_check_schema( Operation *op, CfBackInfo *cfb );
113 static ConfigDriver config_fname;
114 static ConfigDriver config_cfdir;
115 static ConfigDriver config_generic;
116 static ConfigDriver config_search_base;
117 static ConfigDriver config_passwd_hash;
118 static ConfigDriver config_schema_dn;
119 static ConfigDriver config_sizelimit;
120 static ConfigDriver config_timelimit;
121 static ConfigDriver config_overlay;
122 static ConfigDriver config_subordinate;
123 static ConfigDriver config_suffix;
124 #ifdef LDAP_TCP_BUFFER
125 static ConfigDriver config_tcp_buffer;
126 #endif /* LDAP_TCP_BUFFER */
127 static ConfigDriver config_rootdn;
128 static ConfigDriver config_rootpw;
129 static ConfigDriver config_restrict;
130 static ConfigDriver config_allows;
131 static ConfigDriver config_disallows;
132 static ConfigDriver config_requires;
133 static ConfigDriver config_security;
134 static ConfigDriver config_referral;
135 static ConfigDriver config_loglevel;
136 static ConfigDriver config_updatedn;
137 static ConfigDriver config_updateref;
138 static ConfigDriver config_extra_attrs;
139 static ConfigDriver config_include;
140 static ConfigDriver config_obsolete;
142 static ConfigDriver config_tls_option;
143 static ConfigDriver config_tls_config;
145 extern ConfigDriver syncrepl_config;
153 CFG_TLS_PROTOCOL_MIN,
206 static OidRec OidMacros[] = {
207 /* OpenLDAProot:1.12.2 */
208 { "OLcfg", "1.3.6.1.4.1.4203.1.12.2" },
209 { "OLcfgAt", "OLcfg:3" },
210 { "OLcfgGlAt", "OLcfgAt:0" },
211 { "OLcfgBkAt", "OLcfgAt:1" },
212 { "OLcfgDbAt", "OLcfgAt:2" },
213 { "OLcfgOvAt", "OLcfgAt:3" },
214 { "OLcfgCtAt", "OLcfgAt:4" }, /* contrib modules */
215 { "OLcfgOc", "OLcfg:4" },
216 { "OLcfgGlOc", "OLcfgOc:0" },
217 { "OLcfgBkOc", "OLcfgOc:1" },
218 { "OLcfgDbOc", "OLcfgOc:2" },
219 { "OLcfgOvOc", "OLcfgOc:3" },
220 { "OLcfgCtOc", "OLcfgOc:4" }, /* contrib modules */
222 /* Syntaxes. We should just start using the standard names and
223 * document that they are predefined and available for users
224 * to reference in their own schema. Defining schema without
225 * OID macros is for masochists...
227 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
228 { "OMsBoolean", "OMsyn:7" },
229 { "OMsDN", "OMsyn:12" },
230 { "OMsDirectoryString", "OMsyn:15" },
231 { "OMsIA5String", "OMsyn:26" },
232 { "OMsInteger", "OMsyn:27" },
233 { "OMsOID", "OMsyn:38" },
234 { "OMsOctetString", "OMsyn:40" },
239 * Backend/Database registry
241 * OLcfg{Bk|Db}{Oc|At}:0 -> common
242 * OLcfg{Bk|Db}{Oc|At}:1 -> back-bdb(/back-hdb)
243 * OLcfg{Bk|Db}{Oc|At}:2 -> back-ldif
244 * OLcfg{Bk|Db}{Oc|At}:3 -> back-ldap
245 * OLcfg{Bk|Db}{Oc|At}:4 -> back-monitor
246 * OLcfg{Bk|Db}{Oc|At}:5 -> back-relay
247 * OLcfg{Bk|Db}{Oc|At}:6 -> back-sql(/back-ndb)
248 * OLcfg{Bk|Db}{Oc|At}:7 -> back-sock
249 * OLcfg{Bk|Db}{Oc|At}:8 -> back-null
250 * OLcfg{Bk|Db}{Oc|At}:9 -> back-passwd
251 * OLcfg{Bk|Db}{Oc|At}:10 -> back-shell
252 * OLcfg{Bk|Db}{Oc|At}:11 -> back-perl
253 * OLcfg{Bk|Db}{Oc|At}:12 -> back-mdb
259 * OLcfgOv{Oc|At}:1 -> syncprov
260 * OLcfgOv{Oc|At}:2 -> pcache
261 * OLcfgOv{Oc|At}:3 -> chain
262 * OLcfgOv{Oc|At}:4 -> accesslog
263 * OLcfgOv{Oc|At}:5 -> valsort
264 * OLcfgOv{Oc|At}:7 -> distproc
265 * OLcfgOv{Oc|At}:8 -> dynlist
266 * OLcfgOv{Oc|At}:9 -> dds
267 * OLcfgOv{Oc|At}:10 -> unique
268 * OLcfgOv{Oc|At}:11 -> refint
269 * OLcfgOv{Oc|At}:12 -> ppolicy
270 * OLcfgOv{Oc|At}:13 -> constraint
271 * OLcfgOv{Oc|At}:14 -> translucent
272 * OLcfgOv{Oc|At}:15 -> auditlog
273 * OLcfgOv{Oc|At}:16 -> rwm
274 * OLcfgOv{Oc|At}:17 -> dyngroup
275 * OLcfgOv{Oc|At}:18 -> memberof
276 * OLcfgOv{Oc|At}:19 -> collect
277 * OLcfgOv{Oc|At}:20 -> retcode
278 * OLcfgOv{Oc|At}:21 -> sssvlv
281 /* alphabetical ordering */
283 static ConfigTable config_back_cf_table[] = {
284 /* This attr is read-only */
285 { "", "", 0, 0, 0, ARG_MAGIC,
286 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
287 "DESC 'File for slapd configuration directives' "
288 "EQUALITY caseIgnoreMatch "
289 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
290 { "", "", 0, 0, 0, ARG_MAGIC,
291 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
292 "DESC 'Directory for slapd configuration backend' "
293 "EQUALITY caseIgnoreMatch "
294 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
295 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
296 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
297 "DESC 'Access Control List' "
298 "EQUALITY caseIgnoreMatch "
299 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
300 { "add_content_acl", NULL, 0, 0, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_ACL_ADD,
301 &config_generic, "( OLcfgGlAt:86 NAME 'olcAddContentAcl' "
302 "DESC 'Check ACLs against content of Add ops' "
303 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
304 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
305 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
306 "DESC 'Allowed set of deprecated features' "
307 "EQUALITY caseIgnoreMatch "
308 "SYNTAX OMsDirectoryString )", NULL, NULL },
309 { "argsfile", "file", 2, 2, 0, ARG_STRING,
310 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
311 "DESC 'File for slapd command line options' "
312 "EQUALITY caseIgnoreMatch "
313 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
314 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
315 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
316 "EQUALITY caseIgnoreMatch "
317 "SYNTAX OMsDirectoryString )", NULL, NULL },
318 { "attribute", "attribute", 2, 0, STRLENOF( "attribute" ),
319 ARG_PAREN|ARG_MAGIC|CFG_ATTR,
320 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
321 "DESC 'OpenLDAP attributeTypes' "
322 "EQUALITY caseIgnoreMatch "
323 "SUBSTR caseIgnoreSubstringsMatch "
324 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
326 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
327 #ifdef SLAP_AUTH_REWRITE
328 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
332 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
333 "EQUALITY caseIgnoreMatch "
334 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
335 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
336 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
337 "EQUALITY caseIgnoreMatch "
338 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
339 { "authz-regexp", "regexp> <DN", 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
340 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
341 "EQUALITY caseIgnoreMatch "
342 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
343 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
344 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
345 "DESC 'A type of backend' "
346 "EQUALITY caseIgnoreMatch "
347 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
349 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
350 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
351 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
352 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
353 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
354 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
355 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
356 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
357 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
358 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
359 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
360 "DESC 'The backend type for a database instance' "
361 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
362 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
363 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
364 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
365 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
366 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
367 "EQUALITY caseIgnoreMatch "
368 "SYNTAX OMsDirectoryString )", NULL, NULL },
369 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
370 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
371 "DESC 'OpenLDAP DIT content rules' "
372 "EQUALITY caseIgnoreMatch "
373 "SUBSTR caseIgnoreSubstringsMatch "
374 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
376 { "extra_attrs", "attrlist", 2, 2, 0, ARG_DB|ARG_MAGIC,
377 &config_extra_attrs, "( OLcfgDbAt:0.20 NAME 'olcExtraAttrs' "
378 "EQUALITY caseIgnoreMatch "
379 "SYNTAX OMsDirectoryString )", NULL, NULL },
380 { "gentlehup", "on|off", 2, 2, 0,
382 ARG_ON_OFF, &global_gentlehup,
386 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
387 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
388 { "hidden", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_HIDDEN,
389 &config_generic, "( OLcfgDbAt:0.17 NAME 'olcHidden' "
390 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
391 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
392 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
393 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
394 { "include", "file", 2, 2, 0, ARG_MAGIC,
395 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
396 "SUP labeledURI )", NULL, NULL },
397 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
398 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
399 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
400 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
401 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
402 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
403 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
404 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
405 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
406 { "index_substr_any_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
407 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
408 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
409 { "index_intlen", "len", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_IX_INTLEN,
410 &config_generic, "( OLcfgGlAt:84 NAME 'olcIndexIntLen' "
411 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
412 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
413 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
414 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
415 { "ldapsyntax", "syntax", 2, 0, 0,
416 ARG_PAREN|ARG_MAGIC|CFG_SYNTAX,
417 &config_generic, "( OLcfgGlAt:85 NAME 'olcLdapSyntaxes' "
418 "DESC 'OpenLDAP ldapSyntax' "
419 "EQUALITY caseIgnoreMatch "
420 "SUBSTR caseIgnoreSubstringsMatch "
421 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
423 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
424 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
425 "EQUALITY caseIgnoreMatch "
426 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
427 { "listener-threads", "count", 2, 0, 0,
431 ARG_UINT|ARG_MAGIC|CFG_LTHREADS, &config_generic,
433 "( OLcfgGlAt:93 NAME 'olcListenerThreads' "
434 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
435 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
436 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
437 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
438 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
439 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
440 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
441 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
442 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
443 "EQUALITY caseIgnoreMatch "
444 "SYNTAX OMsDirectoryString )", NULL, NULL },
445 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
446 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
447 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
448 { "mirrormode", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_MIRRORMODE,
449 &config_generic, "( OLcfgDbAt:0.16 NAME 'olcMirrorMode' "
450 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
451 { "moduleload", "file", 2, 0, 0,
453 ARG_MAGIC|CFG_MODLOAD|ARG_NO_DELETE, &config_generic,
457 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
458 "EQUALITY caseIgnoreMatch "
459 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
460 { "modulepath", "path", 2, 2, 0,
462 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
466 "( OLcfgGlAt:31 NAME 'olcModulePath' "
467 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
468 { "monitoring", "TRUE|FALSE", 2, 2, 0,
469 ARG_MAGIC|CFG_MONITORING|ARG_DB|ARG_ON_OFF, &config_generic,
470 "( OLcfgDbAt:0.18 NAME 'olcMonitoring' "
471 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
472 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
473 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
474 "DESC 'OpenLDAP object classes' "
475 "EQUALITY caseIgnoreMatch "
476 "SUBSTR caseIgnoreSubstringsMatch "
477 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
479 { "objectidentifier", "name> <oid", 3, 3, 0, ARG_MAGIC|CFG_OID,
480 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
481 "EQUALITY caseIgnoreMatch "
482 "SUBSTR caseIgnoreSubstringsMatch "
483 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
484 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
485 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
486 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
487 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
488 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
489 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
490 { "password-hash", "hash", 2, 0, 0, ARG_MAGIC,
491 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
492 "EQUALITY caseIgnoreMatch "
493 "SYNTAX OMsDirectoryString )", NULL, NULL },
494 { "pidfile", "file", 2, 2, 0, ARG_STRING,
495 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
496 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
497 { "plugin", NULL, 0, 0, 0,
499 ARG_MAGIC|CFG_PLUGIN, &config_generic,
503 "( OLcfgGlAt:38 NAME 'olcPlugin' "
504 "EQUALITY caseIgnoreMatch "
505 "SYNTAX OMsDirectoryString )", NULL, NULL },
506 { "pluginlog", "filename", 2, 2, 0,
508 ARG_STRING, &slapi_log_file,
512 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
513 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
514 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
515 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
516 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
517 { "referral", "url", 2, 2, 0, ARG_MAGIC,
518 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
519 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
520 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
521 &config_obsolete, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
522 "EQUALITY caseIgnoreMatch "
523 "SUP labeledURI X-ORDERED 'VALUES' )", NULL, NULL },
524 { "replica-argsfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
525 &config_obsolete, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
526 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
527 { "replica-pidfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
528 &config_obsolete, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
529 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
530 { "replicationInterval", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
531 &config_obsolete, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
532 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
533 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC,
534 &config_obsolete, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
535 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
536 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
537 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
538 "EQUALITY caseIgnoreMatch "
539 "SYNTAX OMsDirectoryString )", NULL, NULL },
540 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
541 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
542 "EQUALITY caseIgnoreMatch "
543 "SYNTAX OMsDirectoryString )", NULL, NULL },
544 { "reverse-lookup", "on|off", 2, 2, 0,
545 #ifdef SLAPD_RLOOKUPS
546 ARG_ON_OFF, &use_reverse_lookup,
550 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
551 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
552 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
553 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
554 "EQUALITY distinguishedNameMatch "
555 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
556 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
557 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
558 "EQUALITY caseIgnoreMatch "
559 "SYNTAX OMsDirectoryString )", NULL, NULL },
560 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
561 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
562 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
563 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
564 &config_generic, NULL, NULL, NULL },
565 { "sasl-auxprops", NULL, 2, 0, 0,
566 #ifdef HAVE_CYRUS_SASL
567 ARG_STRING|ARG_UNIQUE, &slap_sasl_auxprops,
571 "( OLcfgGlAt:89 NAME 'olcSaslAuxprops' "
572 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
573 { "sasl-auxprops-dontusecopy", NULL, 2, 0, 0,
574 #if defined(HAVE_CYRUS_SASL) && defined(SLAP_AUXPROP_DONTUSECOPY)
575 ARG_MAGIC|CFG_AZDUC, &config_generic,
579 "( OLcfgGlAt:91 NAME 'olcSaslAuxpropsDontUseCopy' "
580 "EQUALITY caseIgnoreMatch "
581 "SYNTAX OMsDirectoryString )", NULL, NULL },
582 { "sasl-auxprops-dontusecopy-ignore", "true|FALSE", 2, 0, 0,
583 #if defined(HAVE_CYRUS_SASL) && defined(SLAP_AUXPROP_DONTUSECOPY)
584 ARG_ON_OFF|CFG_AZDUC_IGNORE, &slap_dontUseCopy_ignore,
588 "( OLcfgGlAt:92 NAME 'olcSaslAuxpropsDontUseCopyIgnore' "
589 "EQUALITY booleanMatch "
590 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
591 { "sasl-host", "host", 2, 2, 0,
592 #ifdef HAVE_CYRUS_SASL
593 ARG_STRING|ARG_UNIQUE, &sasl_host,
597 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
598 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
599 { "sasl-realm", "realm", 2, 2, 0,
600 #ifdef HAVE_CYRUS_SASL
601 ARG_STRING|ARG_UNIQUE, &global_realm,
605 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
606 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
607 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
608 &config_generic, NULL, NULL, NULL },
609 { "sasl-secprops", "properties", 2, 2, 0,
610 #ifdef HAVE_CYRUS_SASL
611 ARG_MAGIC|CFG_SASLSECP, &config_generic,
615 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
616 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
617 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
618 &config_generic, NULL, NULL, NULL },
619 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
620 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
621 "EQUALITY distinguishedNameMatch "
622 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
623 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
624 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
625 "EQUALITY caseIgnoreMatch "
626 "SYNTAX OMsDirectoryString )", NULL, NULL },
627 { "serverID", "number> <[URI]", 2, 3, 0, ARG_MAGIC|CFG_SERVERID,
628 &config_generic, "( OLcfgGlAt:81 NAME 'olcServerID' "
629 "EQUALITY caseIgnoreMatch "
630 "SYNTAX OMsDirectoryString )", NULL, NULL },
631 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
632 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
633 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
634 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
635 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
636 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
637 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
638 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
639 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
640 { "sortvals", "attr", 2, 0, 0, ARG_MAGIC|CFG_SORTVALS,
641 &config_generic, "( OLcfgGlAt:83 NAME 'olcSortVals' "
642 "DESC 'Attributes whose values will always be sorted' "
643 "EQUALITY caseIgnoreMatch "
644 "SYNTAX OMsDirectoryString )", NULL, NULL },
645 { "subordinate", "[advertise]", 1, 2, 0, ARG_DB|ARG_MAGIC,
646 &config_subordinate, "( OLcfgDbAt:0.15 NAME 'olcSubordinate' "
647 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
648 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
649 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
650 "EQUALITY distinguishedNameMatch "
651 "SYNTAX OMsDN )", NULL, NULL },
652 { "sync_use_subentry", NULL, 0, 0, 0, ARG_ON_OFF|ARG_DB|ARG_MAGIC|CFG_SYNC_SUBENTRY,
653 &config_generic, "( OLcfgDbAt:0.19 NAME 'olcSyncUseSubentry' "
654 "DESC 'Store sync context in a subentry' "
655 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
656 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
657 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
658 "EQUALITY caseIgnoreMatch "
659 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
660 { "tcp-buffer", "[listener=<listener>] [{read|write}=]size", 0, 0, 0,
661 #ifndef LDAP_TCP_BUFFER
663 #else /* LDAP_TCP_BUFFER */
664 ARG_MAGIC, &config_tcp_buffer,
665 #endif /* LDAP_TCP_BUFFER */
666 "( OLcfgGlAt:90 NAME 'olcTCPBuffer' "
667 "DESC 'Custom TCP buffer size' "
668 "SYNTAX OMsDirectoryString )", NULL, NULL },
669 { "threads", "count", 2, 2, 0,
673 ARG_INT|ARG_MAGIC|CFG_THREADS, &config_generic,
675 "( OLcfgGlAt:66 NAME 'olcThreads' "
676 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
677 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
678 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
679 "SYNTAX OMsDirectoryString )", NULL, NULL },
680 { "TLSCACertificateFile", NULL, 2, 2, 0,
682 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
686 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
687 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
688 { "TLSCACertificatePath", NULL, 2, 2, 0,
690 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
694 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
695 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
696 { "TLSCertificateFile", NULL, 2, 2, 0,
698 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
702 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
703 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
704 { "TLSCertificateKeyFile", NULL, 2, 2, 0,
706 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
710 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
711 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
712 { "TLSCipherSuite", NULL, 2, 2, 0,
714 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
718 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
719 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
720 { "TLSCRLCheck", NULL, 2, 2, 0,
721 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
722 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
726 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
727 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
728 { "TLSCRLFile", NULL, 2, 2, 0,
729 #if defined(HAVE_GNUTLS)
730 CFG_TLS_CRL_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
734 "( OLcfgGlAt:82 NAME 'olcTLSCRLFile' "
735 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
736 { "TLSRandFile", NULL, 2, 2, 0,
738 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
742 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
743 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
744 { "TLSVerifyClient", NULL, 2, 2, 0,
746 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
750 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
751 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
752 { "TLSDHParamFile", NULL, 2, 2, 0,
754 CFG_TLS_DH_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
758 "( OLcfgGlAt:77 NAME 'olcTLSDHParamFile' "
759 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
760 { "TLSProtocolMin", NULL, 2, 2, 0,
762 CFG_TLS_PROTOCOL_MIN|ARG_STRING|ARG_MAGIC, &config_tls_config,
766 "( OLcfgGlAt:87 NAME 'olcTLSProtocolMin' "
767 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
768 { "tool-threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_TTHREADS,
769 &config_generic, "( OLcfgGlAt:80 NAME 'olcToolThreads' "
770 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
771 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
772 NULL, NULL, NULL, NULL },
773 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
774 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
775 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
776 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
777 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
778 "EQUALITY caseIgnoreMatch "
779 "SUP labeledURI )", NULL, NULL },
780 { "writetimeout", "timeout", 2, 2, 0, ARG_INT,
781 &global_writetimeout, "( OLcfgGlAt:88 NAME 'olcWriteTimeout' "
782 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
783 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
784 NULL, NULL, NULL, NULL }
787 /* Need to no-op this keyword for dynamic config */
788 ConfigTable olcDatabaseDummy[] = {
789 { "", "", 0, 0, 0, ARG_IGNORED,
790 NULL, "( OLcfgGlAt:13 NAME 'olcDatabase' "
791 "DESC 'The backend type for a database instance' "
792 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
793 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
796 /* Routines to check if a child can be added to this type */
797 static ConfigLDAPadd cfAddSchema, cfAddInclude, cfAddDatabase,
798 cfAddBackend, cfAddModule, cfAddOverlay;
800 /* NOTE: be careful when defining array members
801 * that can be conditionally compiled */
802 #define CFOC_GLOBAL cf_ocs[1]
803 #define CFOC_SCHEMA cf_ocs[2]
804 #define CFOC_BACKEND cf_ocs[3]
805 #define CFOC_DATABASE cf_ocs[4]
806 #define CFOC_OVERLAY cf_ocs[5]
807 #define CFOC_INCLUDE cf_ocs[6]
808 #define CFOC_FRONTEND cf_ocs[7]
810 #define CFOC_MODULE cf_ocs[8]
811 #endif /* SLAPD_MODULES */
813 static ConfigOCs cf_ocs[] = {
816 "DESC 'OpenLDAP configuration object' "
817 "ABSTRACT SUP top )", Cft_Abstract, NULL },
820 "DESC 'OpenLDAP Global configuration options' "
821 "SUP olcConfig STRUCTURAL "
822 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
823 "olcAttributeOptions $ olcAuthIDRewrite $ "
824 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
825 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
826 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
827 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
828 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcIndexIntLen $ "
829 "olcLocalSSF $ olcLogFile $ olcLogLevel $ "
830 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
831 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
832 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
834 "olcSaslAuxprops $ olcSaslAuxpropsDontUseCopy $ olcSaslAuxpropsDontUseCopyIgnore $ "
835 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
836 "olcSecurity $ olcServerID $ olcSizeLimit $ "
837 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ "
839 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
840 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
841 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
842 "olcTLSRandFile $ olcTLSVerifyClient $ olcTLSDHParamFile $ "
843 "olcTLSCRLFile $ olcToolThreads $ olcWriteTimeout $ "
844 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
845 "olcDitContentRules $ olcLdapSyntaxes ) )", Cft_Global },
847 "NAME 'olcSchemaConfig' "
848 "DESC 'OpenLDAP schema object' "
849 "SUP olcConfig STRUCTURAL "
850 "MAY ( cn $ olcObjectIdentifier $ olcAttributeTypes $ "
851 "olcObjectClasses $ olcDitContentRules $ olcLdapSyntaxes ) )",
852 Cft_Schema, NULL, cfAddSchema },
854 "NAME 'olcBackendConfig' "
855 "DESC 'OpenLDAP Backend-specific options' "
856 "SUP olcConfig STRUCTURAL "
857 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
859 "NAME 'olcDatabaseConfig' "
860 "DESC 'OpenLDAP Database-specific options' "
861 "SUP olcConfig STRUCTURAL "
863 "MAY ( olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
864 "olcAddContentAcl $ olcLastMod $ olcLimits $ "
865 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
866 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
867 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
868 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncUseSubentry $ olcSyncrepl $ "
869 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef $ olcMirrorMode $ "
870 "olcMonitoring $ olcExtraAttrs ) )",
871 Cft_Database, NULL, cfAddDatabase },
873 "NAME 'olcOverlayConfig' "
874 "DESC 'OpenLDAP Overlay-specific options' "
875 "SUP olcConfig STRUCTURAL "
876 "MUST olcOverlay )", Cft_Overlay, NULL, cfAddOverlay },
878 "NAME 'olcIncludeFile' "
879 "DESC 'OpenLDAP configuration include file' "
880 "SUP olcConfig STRUCTURAL "
882 "MAY ( cn $ olcRootDSE ) )",
883 /* Used to be Cft_Include, that def has been removed */
884 Cft_Abstract, NULL, cfAddInclude },
885 /* This should be STRUCTURAL like all the other database classes, but
886 * that would mean inheriting all of the olcDatabaseConfig attributes,
887 * which causes them to be merged twice in config_build_entry.
890 "NAME 'olcFrontendConfig' "
891 "DESC 'OpenLDAP frontend configuration' "
893 "MAY ( olcDefaultSearchBase $ olcPasswordHash $ olcSortVals ) )",
894 Cft_Database, NULL, NULL },
897 "NAME 'olcModuleList' "
898 "DESC 'OpenLDAP dynamic module info' "
899 "SUP olcConfig STRUCTURAL "
900 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
901 Cft_Module, NULL, cfAddModule },
906 typedef struct ServerID {
907 struct ServerID *si_next;
908 struct berval si_url;
912 static ServerID *sid_list;
914 typedef struct voidList {
915 struct voidList *vl_next;
919 typedef struct ADlist {
920 struct ADlist *al_next;
921 AttributeDescription *al_desc;
924 static ADlist *sortVals;
927 config_generic(ConfigArgs *c) {
930 if ( c->op == SLAP_CONFIG_EMIT ) {
934 c->value_int = ldap_pvt_thread_get_concurrency();
937 c->value_int = connection_pool_max;
940 c->value_int = slap_tool_thread_max;
943 c->value_uint = slapd_daemon_threads;
947 c->value_string = ch_strdup( passwd_salt );
952 if ( c->be->be_limits ) {
956 for ( i=0; c->be->be_limits[i]; i++ ) {
957 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
958 if ( bv.bv_len >= sizeof( buf ) ) {
959 ber_bvarray_free_x( c->rvalue_vals, NULL );
960 c->rvalue_vals = NULL;
964 bv.bv_val = buf + bv.bv_len;
965 limits_unparse( c->be->be_limits[i], &bv,
966 sizeof( buf ) - ( bv.bv_val - buf ) );
967 bv.bv_len += bv.bv_val - buf;
969 value_add_one( &c->rvalue_vals, &bv );
972 if ( !c->rvalue_vals ) rc = 1;
975 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_READONLY);
978 c->value_string = ch_strdup( slap_sasl_getpolicy());
981 slap_sasl_regexp_unparse( &c->rvalue_vals );
982 if ( !c->rvalue_vals ) rc = 1;
984 #ifdef HAVE_CYRUS_SASL
985 #ifdef SLAP_AUXPROP_DONTUSECOPY
987 static int duc_done = 0;
989 /* take the opportunity to initialize with known values */
991 struct berval duc[] = { BER_BVC("cmusaslsecretOTP"), BER_BVNULL };
994 for ( i = 0; !BER_BVISNULL( &duc[ i ] ); i++ ) {
995 const char *text = NULL;
996 AttributeDescription *ad = NULL;
998 if ( slap_bv2ad( &duc[ i ], &ad, &text ) == LDAP_SUCCESS ) {
1000 if ( slap_dontUseCopy_propnames ) {
1003 for ( j = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ j ] ); j++ ) {
1004 if ( bvmatch( &slap_dontUseCopy_propnames[ j ], &ad->ad_cname ) ) {
1011 value_add_one( &slap_dontUseCopy_propnames, &ad->ad_cname );
1019 if ( slap_dontUseCopy_propnames != NULL ) {
1020 ber_bvarray_dup_x( &c->rvalue_vals, slap_dontUseCopy_propnames, NULL );
1025 #endif /* SLAP_AUXPROP_DONTUSECOPY */
1026 case CFG_SASLSECP: {
1027 struct berval bv = BER_BVNULL;
1028 slap_sasl_secprops_unparse( &bv );
1029 if ( !BER_BVISNULL( &bv )) {
1030 ber_bvarray_add( &c->rvalue_vals, &bv );
1038 c->value_int = c->be->be_max_deref_depth;
1041 if ( SLAP_DBHIDDEN( c->be )) {
1048 ConfigFile *cf = c->ca_private;
1050 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1051 else if ( cf->c_om_head )
1052 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
1054 if ( !c->rvalue_vals )
1059 ad_unparse_options( &c->rvalue_vals );
1062 ConfigFile *cf = c->ca_private;
1064 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1065 else if ( cf->c_oc_head )
1066 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
1068 if ( !c->rvalue_vals )
1073 ConfigFile *cf = c->ca_private;
1075 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1076 else if ( cf->c_at_head )
1077 at_unparse( &c->rvalue_vals, cf->c_at_head,
1079 if ( !c->rvalue_vals )
1084 ConfigFile *cf = c->ca_private;
1086 syn_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1087 else if ( cf->c_syn_head )
1088 syn_unparse( &c->rvalue_vals, cf->c_syn_head,
1089 cf->c_syn_tail, 0 );
1090 if ( !c->rvalue_vals )
1095 ConfigFile *cf = c->ca_private;
1097 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1098 else if ( cf->c_cr_head )
1099 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
1101 if ( !c->rvalue_vals )
1108 char *src, *dst, ibuf[11];
1109 struct berval bv, abv;
1110 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
1111 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1112 if ( abv.bv_len >= sizeof( ibuf ) ) {
1113 ber_bvarray_free_x( c->rvalue_vals, NULL );
1114 c->rvalue_vals = NULL;
1118 acl_unparse( a, &bv );
1119 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
1120 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
1121 /* Turn TAB / EOL into plain space */
1122 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
1123 if (isspace((unsigned char)*src)) *dst++ = ' ';
1127 if (dst[-1] == ' ') {
1131 abv.bv_len = dst - abv.bv_val;
1132 ber_bvarray_add( &c->rvalue_vals, &abv );
1138 c->value_int = (SLAP_DBACL_ADD(c->be) != 0);
1141 ConfigFile *cf = c->ca_private;
1142 if ( cf->c_dseFiles ) {
1143 value_add( &c->rvalue_vals, cf->c_dseFiles );
1154 for ( si = sid_list; si; si=si->si_next ) {
1155 assert( si->si_num >= 0 && si->si_num <= SLAP_SYNC_SID_MAX );
1156 if ( !BER_BVISEMPTY( &si->si_url )) {
1157 bv.bv_len = si->si_url.bv_len + 6;
1158 bv.bv_val = ch_malloc( bv.bv_len );
1159 bv.bv_len = sprintf( bv.bv_val, "%d %s", si->si_num,
1160 si->si_url.bv_val );
1161 ber_bvarray_add( &c->rvalue_vals, &bv );
1165 bv.bv_len = sprintf( buf, "%d", si->si_num );
1166 value_add_one( &c->rvalue_vals, &bv );
1175 c->value_string = ch_strdup( logfileName );
1180 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1182 case CFG_SYNC_SUBENTRY:
1183 c->value_int = (SLAP_SYNC_SUBENTRY(c->be) != 0);
1185 case CFG_MIRRORMODE:
1186 if ( SLAP_SHADOW(c->be))
1187 c->value_int = (SLAP_SINGLE_SHADOW(c->be) == 0);
1191 case CFG_MONITORING:
1192 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
1194 case CFG_SSTR_IF_MAX:
1195 c->value_uint = index_substr_if_maxlen;
1197 case CFG_SSTR_IF_MIN:
1198 c->value_uint = index_substr_if_minlen;
1201 c->value_int = index_intlen;
1203 case CFG_SORTVALS: {
1206 for ( sv = sortVals; sv; sv = sv->al_next ) {
1207 value_add_one( &c->rvalue_vals, &sv->al_desc->ad_cname );
1211 #ifdef SLAPD_MODULES
1213 ModPaths *mp = c->ca_private;
1216 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
1219 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
1220 SLAP_X_ORDERED_FMT "%s", i,
1221 mp->mp_loads[i].bv_val );
1222 if ( bv.bv_len >= sizeof( c->log ) ) {
1223 ber_bvarray_free_x( c->rvalue_vals, NULL );
1224 c->rvalue_vals = NULL;
1227 value_add_one( &c->rvalue_vals, &bv );
1231 rc = c->rvalue_vals ? 0 : 1;
1235 ModPaths *mp = c->ca_private;
1236 if ( !BER_BVISNULL( &mp->mp_path ))
1237 value_add_one( &c->rvalue_vals, &mp->mp_path );
1239 rc = c->rvalue_vals ? 0 : 1;
1245 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1246 if ( !c->rvalue_vals ) rc = 1;
1249 #ifdef SLAP_AUTH_REWRITE
1251 if ( authz_rewrites ) {
1252 struct berval bv, idx;
1257 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1258 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1259 if ( idx.bv_len >= sizeof( ibuf ) ) {
1260 ber_bvarray_free_x( c->rvalue_vals, NULL );
1261 c->rvalue_vals = NULL;
1264 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1265 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1266 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1267 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1268 authz_rewrites[i].bv_val,
1269 authz_rewrites[i].bv_len + 1 );
1270 ber_bvarray_add( &c->rvalue_vals, &bv );
1273 if ( !c->rvalue_vals ) rc = 1;
1280 } else if ( c->op == LDAP_MOD_DELETE ) {
1283 /* single-valued attrs, no-ops */
1292 case CFG_MIRRORMODE:
1293 case CFG_MONITORING:
1295 case CFG_SSTR_IF_MAX:
1296 case CFG_SSTR_IF_MIN:
1298 case CFG_SYNC_SUBENTRY:
1301 /* no-ops, requires slapd restart */
1306 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1309 #if defined(HAVE_CYRUS_SASL) && defined(SLAP_AUXPROP_DONTUSECOPY)
1311 if ( c->valx < 0 ) {
1312 if ( slap_dontUseCopy_propnames != NULL ) {
1313 ber_bvarray_free( slap_dontUseCopy_propnames );
1314 slap_dontUseCopy_propnames = NULL;
1320 if ( slap_dontUseCopy_propnames == NULL ) {
1325 for ( i = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ i ] ) && i < c->valx; i++ );
1326 if ( i < c->valx ) {
1330 ber_memfree( slap_dontUseCopy_propnames[ i ].bv_val );
1331 for ( ; !BER_BVISNULL( &slap_dontUseCopy_propnames[ i + 1 ] ); i++ ) {
1332 slap_dontUseCopy_propnames[ i ] = slap_dontUseCopy_propnames[ i + 1 ];
1334 BER_BVZERO( &slap_dontUseCopy_propnames[ i ] );
1337 #endif /* SLAP_AUXPROP_DONTUSECOPY */
1339 ch_free( passwd_salt );
1344 ch_free( logfileName );
1352 case CFG_SERVERID: {
1353 ServerID *si, **sip;
1355 for ( i=0, si = sid_list, sip = &sid_list;
1356 si; si = *sip, i++ ) {
1357 if ( c->valx == -1 || i == c->valx ) {
1369 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1373 index_intlen = SLAP_INDEX_INTLEN_DEFAULT;
1374 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1375 SLAP_INDEX_INTLEN_DEFAULT );
1379 if ( c->valx < 0 ) {
1380 acl_destroy( c->be->be_acl );
1381 c->be->be_acl = NULL;
1384 AccessControl **prev, *a;
1386 for (i=0, prev = &c->be->be_acl; i < c->valx;
1389 prev = &a->acl_next;
1392 *prev = a->acl_next;
1399 /* Can be NULL when undoing a failed add */
1400 if ( c->ca_entry ) {
1401 ce = c->ca_entry->e_private;
1402 /* can't modify the hardcoded schema */
1403 if ( ce->ce_parent->ce_type == Cft_Global )
1407 cfn = c->ca_private;
1408 if ( c->valx < 0 ) {
1411 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1413 if ( oc == cfn->c_oc_tail )
1416 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1418 ObjectClass *oc, *prev = NULL;
1420 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1425 if ( cfn->c_oc_tail == oc ) {
1426 cfn->c_oc_tail = prev;
1428 if ( cfn->c_oc_head == oc ) {
1430 cfn->c_oc_head = oc;
1437 /* Can be NULL when undoing a failed add */
1438 if ( c->ca_entry ) {
1439 ce = c->ca_entry->e_private;
1440 /* can't modify the hardcoded schema */
1441 if ( ce->ce_parent->ce_type == Cft_Global )
1445 cfn = c->ca_private;
1446 if ( c->valx < 0 ) {
1449 for( at = cfn->c_at_head; at; at_next( &at )) {
1451 if ( at == cfn->c_at_tail )
1454 cfn->c_at_head = cfn->c_at_tail = NULL;
1456 AttributeType *at, *prev = NULL;
1458 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1463 if ( cfn->c_at_tail == at ) {
1464 cfn->c_at_tail = prev;
1466 if ( cfn->c_at_head == at ) {
1468 cfn->c_at_head = at;
1475 /* Can be NULL when undoing a failed add */
1476 if ( c->ca_entry ) {
1477 ce = c->ca_entry->e_private;
1478 /* can't modify the hardcoded schema */
1479 if ( ce->ce_parent->ce_type == Cft_Global )
1483 cfn = c->ca_private;
1484 if ( c->valx < 0 ) {
1487 for( syn = cfn->c_syn_head; syn; syn_next( &syn )) {
1489 if ( syn == cfn->c_syn_tail )
1492 cfn->c_syn_head = cfn->c_syn_tail = NULL;
1494 Syntax *syn, *prev = NULL;
1496 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++) {
1501 if ( cfn->c_syn_tail == syn ) {
1502 cfn->c_syn_tail = prev;
1504 if ( cfn->c_syn_head == syn ) {
1506 cfn->c_syn_head = syn;
1511 if ( c->valx < 0 ) {
1513 for ( sv = sortVals; sv; sv = sortVals ) {
1514 sortVals = sv->al_next;
1515 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1522 for ( prev = &sortVals, sv = sortVals; i < c->valx; i++ ) {
1523 prev = &sv->al_next;
1526 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1527 *prev = sv->al_next;
1533 /* FIXME: there is no limits_free function */
1534 if ( c->valx < 0 ) {
1535 limits_destroy( c->be->be_limits );
1536 c->be->be_limits = NULL;
1541 if ( c->be->be_limits ) {
1542 for ( num = 0; c->be->be_limits[ num ]; num++ )
1546 if ( c->valx >= num ) {
1551 limits_destroy( c->be->be_limits );
1552 c->be->be_limits = NULL;
1555 limits_free_one( c->be->be_limits[ c->valx ] );
1557 for ( cnt = c->valx; cnt < num; cnt++ ) {
1558 c->be->be_limits[ cnt ] = c->be->be_limits[ cnt + 1 ];
1565 /* FIXME: there is no ad_option_free function */
1567 /* FIXME: there is no way to remove attributes added by
1581 if(!(c->bi = backend_info(c->argv[1]))) {
1582 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1583 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1584 c->log, c->cr_msg, c->argv[1] );
1591 /* NOTE: config is always the first backend!
1593 if ( !strcasecmp( c->argv[1], "config" )) {
1594 c->be = LDAP_STAILQ_FIRST(&backendDB);
1595 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1598 c->be = backend_db_init(c->argv[1], NULL, c->valx, &c->reply);
1600 if ( c->cr_msg[0] == 0 )
1601 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1602 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n", c->log, c->cr_msg, c->argv[1] );
1609 ldap_pvt_thread_set_concurrency(c->value_int);
1613 if ( c->value_int < 2 ) {
1614 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1615 "threads=%d smaller than minimum value 2",
1617 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1618 c->log, c->cr_msg, 0 );
1621 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1622 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1623 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1624 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1625 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1626 c->log, c->cr_msg, 0 );
1628 if ( slapMode & SLAP_SERVER_MODE )
1629 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1630 connection_pool_max = c->value_int; /* save for reference */
1634 if ( slapMode & SLAP_TOOL_MODE )
1635 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1636 slap_tool_thread_max = c->value_int; /* save for reference */
1641 /* use a power of two */
1642 while (c->value_uint > 1) {
1643 c->value_uint >>= 1;
1647 slapd_daemon_mask = mask;
1648 slapd_daemon_threads = mask+1;
1653 if ( passwd_salt ) ch_free( passwd_salt );
1654 passwd_salt = c->value_string;
1655 lutil_salt_format(passwd_salt);
1659 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1665 c->be->be_restrictops |= SLAP_RESTRICT_READONLY;
1667 c->be->be_restrictops &= ~SLAP_RESTRICT_READONLY;
1671 ch_free(c->value_string);
1672 if (slap_sasl_setpolicy( c->argv[1] )) {
1673 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
1674 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1675 c->log, c->cr_msg, c->argv[1] );
1681 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1685 #ifdef HAVE_CYRUS_SASL
1686 #ifdef SLAP_AUXPROP_DONTUSECOPY
1690 for ( arg = 1; arg < c->argc; arg++ ) {
1691 int duplicate = 0, err;
1692 AttributeDescription *ad = NULL;
1693 const char *text = NULL;
1695 err = slap_str2ad( c->argv[ arg ], &ad, &text );
1696 if ( err != LDAP_SUCCESS ) {
1697 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s>: attr #%d (\"%s\") unknown (err=%d \"%s\"; ignored)",
1698 c->argv[0], arg, c->argv[ arg ], err, text );
1699 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1700 c->log, c->cr_msg, 0 );
1703 if ( slap_dontUseCopy_propnames != NULL ) {
1704 for ( cnt = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ cnt ] ); cnt++ ) {
1705 if ( bvmatch( &slap_dontUseCopy_propnames[ cnt ], &ad->ad_cname ) ) {
1713 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s>: attr #%d (\"%s\") already defined (ignored)",
1714 c->argv[0], arg, ad->ad_cname.bv_val);
1715 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1716 c->log, c->cr_msg, 0 );
1720 value_add_one( &slap_dontUseCopy_propnames, &ad->ad_cname );
1725 #endif /* SLAP_AUXPROP_DONTUSECOPY */
1729 char *txt = slap_sasl_secprops( c->argv[1] );
1731 snprintf( c->cr_msg, sizeof(c->cr_msg), "<%s> %s",
1733 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0 );
1741 c->be->be_max_deref_depth = c->value_int;
1747 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1748 cfn = c->ca_private;
1749 if(parse_oidm(c, 1, &om))
1751 if (!cfn->c_om_head) cfn->c_om_head = om;
1752 cfn->c_om_tail = om;
1757 ObjectClass *oc, *prev;
1759 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1760 cfn = c->ca_private;
1761 if ( c->valx < 0 ) {
1762 prev = cfn->c_oc_tail;
1765 /* If adding anything after the first, prev is easy */
1768 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
1770 if ( !oc_next( &oc ))
1774 /* If adding the first, and head exists, find its prev */
1775 if (cfn->c_oc_head) {
1776 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
1781 /* else prev is NULL, append to end of global list */
1783 if(parse_oc(c, &oc, prev)) return(1);
1784 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1785 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
1790 AttributeType *at, *prev;
1792 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1793 cfn = c->ca_private;
1794 if ( c->valx < 0 ) {
1795 prev = cfn->c_at_tail;
1798 /* If adding anything after the first, prev is easy */
1801 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
1803 if ( !at_next( &at ))
1807 /* If adding the first, and head exists, find its prev */
1808 if (cfn->c_at_head) {
1809 for ( at_start( &at ); at != cfn->c_at_head; ) {
1814 /* else prev is NULL, append to end of global list */
1816 if(parse_at(c, &at, prev)) return(1);
1817 if (!cfn->c_at_head) cfn->c_at_head = at;
1818 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
1825 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1826 cfn = c->ca_private;
1827 if ( c->valx < 0 ) {
1828 prev = cfn->c_syn_tail;
1831 /* If adding anything after the first, prev is easy */
1834 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++ ) {
1836 if ( !syn_next( &syn ))
1840 /* If adding the first, and head exists, find its prev */
1841 if (cfn->c_syn_head) {
1842 for ( syn_start( &syn ); syn != cfn->c_syn_head; ) {
1847 /* else prev is NULL, append to end of global list */
1849 if ( parse_syn( c, &syn, prev ) ) return(1);
1850 if ( !cfn->c_syn_head ) cfn->c_syn_head = syn;
1851 if ( cfn->c_syn_tail == prev ) cfn->c_syn_tail = syn;
1858 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1859 cfn = c->ca_private;
1860 if(parse_cr(c, &cr)) return(1);
1861 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1862 cfn->c_cr_tail = cr;
1867 ad_define_option(NULL, NULL, 0);
1868 for(i = 1; i < c->argc; i++)
1869 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1874 if ( c->value_int < SLAP_INDEX_INTLEN_DEFAULT )
1875 c->value_int = SLAP_INDEX_INTLEN_DEFAULT;
1876 else if ( c->value_int > 255 )
1878 index_intlen = c->value_int;
1879 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1883 case CFG_SORTVALS: {
1884 ADlist *svnew = NULL, *svtail, *sv;
1886 for ( i = 1; i < c->argc; i++ ) {
1887 AttributeDescription *ad = NULL;
1891 rc = slap_str2ad( c->argv[i], &ad, &text );
1893 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown attribute type #%d",
1896 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1897 c->log, c->cr_msg, c->argv[i] );
1898 for ( sv = svnew; sv; sv = svnew ) {
1899 svnew = sv->al_next;
1904 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) ||
1905 ad->ad_type->sat_single_value ) {
1906 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> inappropriate attribute type #%d",
1908 goto sortval_reject;
1910 sv = ch_malloc( sizeof( ADlist ));
1915 svtail->al_next = sv;
1920 for ( sv = svnew; sv; sv = sv->al_next )
1921 sv->al_desc->ad_type->sat_flags |= SLAP_AT_SORTED_VAL;
1922 for ( sv = sortVals; sv && sv->al_next; sv = sv->al_next );
1924 sv->al_next = svnew;
1931 /* Don't append to the global ACL if we're on a specific DB */
1933 if ( c->valx == -1 ) {
1936 for ( a=c->be->be_acl; a; a = a->acl_next )
1939 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
1946 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_ACL_ADD;
1948 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_ACL_ADD;
1952 if(root_dse_read_file(c->argv[1])) {
1953 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> could not read file", c->argv[0] );
1954 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1955 c->log, c->cr_msg, c->argv[1] );
1960 ber_str2bv( c->argv[1], 0, 1, &bv );
1961 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1962 cfn = c->ca_private;
1963 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1969 ServerID *si, **sip;
1972 if (( lutil_atoi( &num, c->argv[1] ) &&
1973 lutil_atoix( &num, c->argv[1], 16 )) ||
1974 num < 0 || num > SLAP_SYNC_SID_MAX )
1976 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1977 "<%s> illegal server ID", c->argv[0] );
1978 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1979 c->log, c->cr_msg, c->argv[1] );
1982 /* only one value allowed if no URL is given */
1983 if ( c->argc > 2 ) {
1986 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
1987 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1988 "<%s> only one server ID allowed now", c->argv[0] );
1989 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1990 c->log, c->cr_msg, c->argv[1] );
1994 if ( ldap_url_parse( c->argv[2], &lud )) {
1995 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1996 "<%s> invalid URL", c->argv[0] );
1997 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1998 c->log, c->cr_msg, c->argv[2] );
2001 len = strlen( c->argv[2] );
2002 si = ch_malloc( sizeof(ServerID) + len + 1 );
2003 si->si_url.bv_val = (char *)(si+1);
2004 si->si_url.bv_len = len;
2005 strcpy( si->si_url.bv_val, c->argv[2] );
2008 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2009 "<%s> unqualified server ID not allowed now", c->argv[0] );
2010 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2011 c->log, c->cr_msg, c->argv[1] );
2014 si = ch_malloc( sizeof(ServerID) );
2015 BER_BVZERO( &si->si_url );
2016 slap_serverID = num;
2017 Debug( LDAP_DEBUG_CONFIG,
2019 c->log, slap_serverID, 0 );
2023 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
2026 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
2027 Listener *l = config_check_my_url( c->argv[2], lud );
2029 slap_serverID = si->si_num;
2030 Debug( LDAP_DEBUG_CONFIG,
2031 "%s: SID=0x%03x (listener=%s)\n",
2032 c->log, slap_serverID,
2037 ldap_free_urldesc( lud );
2041 if ( logfileName ) ch_free( logfileName );
2042 logfileName = c->value_string;
2043 logfile = fopen(logfileName, "w");
2044 if(logfile) lutil_debug_file(logfile);
2048 if(SLAP_NOLASTMODCMD(c->be)) {
2049 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> not available for %s database",
2050 c->argv[0], c->be->bd_info->bi_type );
2051 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2052 c->log, c->cr_msg, 0 );
2056 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
2058 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
2061 case CFG_MIRRORMODE:
2062 if(c->value_int && !SLAP_SHADOW(c->be)) {
2063 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database is not a shadow",
2065 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2066 c->log, c->cr_msg, 0 );
2070 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
2072 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
2075 case CFG_MONITORING:
2077 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
2079 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
2084 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
2086 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
2089 case CFG_SYNC_SUBENTRY:
2091 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SYNC_SUBENTRY;
2093 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SYNC_SUBENTRY;
2096 case CFG_SSTR_IF_MAX:
2097 if (c->value_uint < index_substr_if_minlen) {
2098 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
2099 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
2100 c->log, c->cr_msg, c->value_int );
2103 index_substr_if_maxlen = c->value_uint;
2106 case CFG_SSTR_IF_MIN:
2107 if (c->value_uint > index_substr_if_maxlen) {
2108 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
2109 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
2110 c->log, c->cr_msg, c->value_int );
2113 index_substr_if_minlen = c->value_uint;
2116 #ifdef SLAPD_MODULES
2118 /* If we're just adding a module on an existing modpath,
2119 * make sure we've selected the current path.
2121 if ( c->op == LDAP_MOD_ADD && c->ca_private && modcur != c->ca_private ) {
2122 modcur = c->ca_private;
2123 /* This should never fail */
2124 if ( module_path( modcur->mp_path.bv_val )) {
2125 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> module path no longer valid",
2127 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2128 c->log, c->cr_msg, modcur->mp_path.bv_val );
2132 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
2134 /* Record this load on the current path */
2138 if ( c->op == SLAP_CONFIG_ADD ) {
2139 ptr = c->line + STRLENOF("moduleload");
2140 while (!isspace((unsigned char) *ptr)) ptr++;
2141 while (isspace((unsigned char) *ptr)) ptr++;
2145 ber_str2bv(ptr, 0, 1, &bv);
2146 ber_bvarray_add( &modcur->mp_loads, &bv );
2148 /* Check for any new hardcoded schema */
2149 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
2150 config_check_schema( NULL, &cfBackInfo );
2155 if(module_path(c->argv[1])) return(1);
2156 /* Record which path was used with each module */
2160 if (!modpaths.mp_loads) {
2163 mp = ch_malloc( sizeof( ModPaths ));
2164 modlast->mp_next = mp;
2166 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
2168 mp->mp_loads = NULL;
2179 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
2181 slapi_plugins_used++;
2185 #ifdef SLAP_AUTH_REWRITE
2191 if ( c->op == LDAP_MOD_ADD ) {
2195 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
2199 if ( c->argc > 1 ) {
2202 /* quote all args but the first */
2203 line = ldap_charray2str( c->argv, "\" \"" );
2204 ber_str2bv( line, 0, 0, &bv );
2205 s = ber_bvchr( &bv, '"' );
2206 assert( s != NULL );
2207 /* move the trailing quote of argv[0] to the end */
2208 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
2209 bv.bv_val[ bv.bv_len - 1 ] = '"';
2212 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
2215 ber_bvarray_add( &authz_rewrites, &bv );
2217 if ( c->op == LDAP_MOD_ADD ) {
2227 Debug( LDAP_DEBUG_ANY,
2228 "%s: unknown CFG_TYPE %d.\n",
2229 c->log, c->type, 0 );
2238 config_fname(ConfigArgs *c) {
2239 if(c->op == SLAP_CONFIG_EMIT) {
2240 if (c->ca_private) {
2241 ConfigFile *cf = c->ca_private;
2242 value_add_one( &c->rvalue_vals, &cf->c_file );
2251 config_cfdir(ConfigArgs *c) {
2252 if(c->op == SLAP_CONFIG_EMIT) {
2253 if ( !BER_BVISEMPTY( &cfdir )) {
2254 value_add_one( &c->rvalue_vals, &cfdir );
2263 config_search_base(ConfigArgs *c) {
2264 if(c->op == SLAP_CONFIG_EMIT) {
2266 if (!BER_BVISEMPTY(&default_search_base)) {
2267 value_add_one(&c->rvalue_vals, &default_search_base);
2268 value_add_one(&c->rvalue_nvals, &default_search_nbase);
2272 } else if( c->op == LDAP_MOD_DELETE ) {
2273 ch_free( default_search_base.bv_val );
2274 ch_free( default_search_nbase.bv_val );
2275 BER_BVZERO( &default_search_base );
2276 BER_BVZERO( &default_search_nbase );
2280 if(c->bi || c->be != frontendDB) {
2281 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
2282 "prior to any backend or database definition\n",
2287 if(default_search_nbase.bv_len) {
2288 free(default_search_base.bv_val);
2289 free(default_search_nbase.bv_val);
2292 default_search_base = c->value_dn;
2293 default_search_nbase = c->value_ndn;
2297 /* For RE23 compatibility we allow this in the global entry
2298 * but we now defer it to the frontend entry to allow modules
2299 * to load new hash types.
2302 config_passwd_hash(ConfigArgs *c) {
2304 if (c->op == SLAP_CONFIG_EMIT) {
2306 /* Don't generate it in the global entry */
2307 if ( c->table == Cft_Global )
2309 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
2310 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
2311 value_add_one(&c->rvalue_vals, &bv);
2314 } else if ( c->op == LDAP_MOD_DELETE ) {
2315 /* Deleting from global is a no-op, only the frontendDB entry matters */
2316 if ( c->table == Cft_Global )
2318 if ( c->valx < 0 ) {
2319 ldap_charray_free( default_passwd_hash );
2320 default_passwd_hash = NULL;
2323 ch_free( default_passwd_hash[i] );
2324 for (; default_passwd_hash[i]; i++ )
2325 default_passwd_hash[i] = default_passwd_hash[i+1];
2329 for(i = 1; i < c->argc; i++) {
2330 if(!lutil_passwd_scheme(c->argv[i])) {
2331 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> scheme not available", c->argv[0] );
2332 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2333 c->log, c->cr_msg, c->argv[i]);
2335 ldap_charray_add(&default_passwd_hash, c->argv[i]);
2338 if(!default_passwd_hash) {
2339 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> no valid hashes found", c->argv[0] );
2340 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2341 c->log, c->cr_msg, 0 );
2348 config_schema_dn(ConfigArgs *c) {
2349 if ( c->op == SLAP_CONFIG_EMIT ) {
2351 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
2352 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
2353 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
2357 } else if ( c->op == LDAP_MOD_DELETE ) {
2358 ch_free( c->be->be_schemadn.bv_val );
2359 ch_free( c->be->be_schemandn.bv_val );
2360 BER_BVZERO( &c->be->be_schemadn );
2361 BER_BVZERO( &c->be->be_schemandn );
2364 ch_free( c->be->be_schemadn.bv_val );
2365 ch_free( c->be->be_schemandn.bv_val );
2366 c->be->be_schemadn = c->value_dn;
2367 c->be->be_schemandn = c->value_ndn;
2372 config_sizelimit(ConfigArgs *c) {
2374 struct slap_limits_set *lim = &c->be->be_def_limit;
2375 if (c->op == SLAP_CONFIG_EMIT) {
2380 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
2381 if ( !BER_BVISEMPTY( &bv ))
2382 value_add_one( &c->rvalue_vals, &bv );
2386 } else if ( c->op == LDAP_MOD_DELETE ) {
2387 /* Reset to defaults or values from frontend */
2388 if ( c->be == frontendDB ) {
2389 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
2390 lim->lms_s_hard = 0;
2391 lim->lms_s_unchecked = -1;
2393 lim->lms_s_pr_hide = 0;
2394 lim->lms_s_pr_total = 0;
2396 lim->lms_s_soft = frontendDB->be_def_limit.lms_s_soft;
2397 lim->lms_s_hard = frontendDB->be_def_limit.lms_s_hard;
2398 lim->lms_s_unchecked = frontendDB->be_def_limit.lms_s_unchecked;
2399 lim->lms_s_pr = frontendDB->be_def_limit.lms_s_pr;
2400 lim->lms_s_pr_hide = frontendDB->be_def_limit.lms_s_pr_hide;
2401 lim->lms_s_pr_total = frontendDB->be_def_limit.lms_s_pr_total;
2405 for(i = 1; i < c->argc; i++) {
2406 if(!strncasecmp(c->argv[i], "size", 4)) {
2407 rc = limits_parse_one(c->argv[i], lim);
2409 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2410 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2411 c->log, c->cr_msg, c->argv[i]);
2415 if(!strcasecmp(c->argv[i], "unlimited")) {
2416 lim->lms_s_soft = -1;
2418 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
2419 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2420 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2421 c->log, c->cr_msg, c->argv[i]);
2425 lim->lms_s_hard = 0;
2430 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2431 /* This is a modification to the global limits apply it to
2432 * the other databases as needed */
2433 AttributeDescription *ad=NULL;
2434 const char *text = NULL;
2435 CfEntryInfo *ce = c->ca_entry->e_private;
2437 slap_str2ad(c->argv[0], &ad, &text);
2438 /* if we got here... */
2439 assert( ad != NULL );
2441 if ( ce->ce_type == Cft_Global ){
2444 for (; ce; ce=ce->ce_sibs) {
2445 Entry *dbe = ce->ce_entry;
2446 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2447 && (!attr_find(dbe->e_attrs, ad)) ) {
2448 ce->ce_be->be_def_limit.lms_s_soft = lim->lms_s_soft;
2449 ce->ce_be->be_def_limit.lms_s_hard = lim->lms_s_hard;
2450 ce->ce_be->be_def_limit.lms_s_unchecked =lim->lms_s_unchecked;
2451 ce->ce_be->be_def_limit.lms_s_pr =lim->lms_s_pr;
2452 ce->ce_be->be_def_limit.lms_s_pr_hide =lim->lms_s_pr_hide;
2453 ce->ce_be->be_def_limit.lms_s_pr_total =lim->lms_s_pr_total;
2461 config_timelimit(ConfigArgs *c) {
2463 struct slap_limits_set *lim = &c->be->be_def_limit;
2464 if (c->op == SLAP_CONFIG_EMIT) {
2469 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
2470 if ( !BER_BVISEMPTY( &bv ))
2471 value_add_one( &c->rvalue_vals, &bv );
2475 } else if ( c->op == LDAP_MOD_DELETE ) {
2476 /* Reset to defaults or values from frontend */
2477 if ( c->be == frontendDB ) {
2478 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
2479 lim->lms_t_hard = 0;
2481 lim->lms_t_soft = frontendDB->be_def_limit.lms_t_soft;
2482 lim->lms_t_hard = frontendDB->be_def_limit.lms_t_hard;
2486 for(i = 1; i < c->argc; i++) {
2487 if(!strncasecmp(c->argv[i], "time", 4)) {
2488 rc = limits_parse_one(c->argv[i], lim);
2490 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2491 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2492 c->log, c->cr_msg, c->argv[i]);
2496 if(!strcasecmp(c->argv[i], "unlimited")) {
2497 lim->lms_t_soft = -1;
2499 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
2500 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2501 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2502 c->log, c->cr_msg, c->argv[i]);
2506 lim->lms_t_hard = 0;
2511 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2512 /* This is a modification to the global limits apply it to
2513 * the other databases as needed */
2514 AttributeDescription *ad=NULL;
2515 const char *text = NULL;
2516 CfEntryInfo *ce = c->ca_entry->e_private;
2518 slap_str2ad(c->argv[0], &ad, &text);
2519 /* if we got here... */
2520 assert( ad != NULL );
2522 if ( ce->ce_type == Cft_Global ){
2525 for (; ce; ce=ce->ce_sibs) {
2526 Entry *dbe = ce->ce_entry;
2527 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2528 && (!attr_find(dbe->e_attrs, ad)) ) {
2529 ce->ce_be->be_def_limit.lms_t_soft = lim->lms_t_soft;
2530 ce->ce_be->be_def_limit.lms_t_hard = lim->lms_t_hard;
2538 config_overlay(ConfigArgs *c) {
2539 if (c->op == SLAP_CONFIG_EMIT) {
2541 } else if ( c->op == LDAP_MOD_DELETE ) {
2544 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2545 c->valx, &c->bi, &c->reply)) {
2547 Debug( LDAP_DEBUG_ANY,
2548 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2549 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2551 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi, &c->reply)) {
2558 config_subordinate(ConfigArgs *c)
2564 case SLAP_CONFIG_EMIT:
2565 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2568 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2569 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2572 value_add_one( &c->rvalue_vals, &bv );
2576 case LDAP_MOD_DELETE:
2577 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2578 glue_sub_del( c->be );
2580 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2585 case SLAP_CONFIG_ADD:
2586 if ( c->be->be_nsuffix == NULL ) {
2588 snprintf( c->cr_msg, sizeof( c->cr_msg),
2589 "subordinate configuration needs a suffix" );
2590 Debug( LDAP_DEBUG_ANY,
2592 c->log, c->cr_msg, 0 );
2597 if ( c->argc == 2 ) {
2598 if ( strcasecmp( c->argv[1], "advertise" ) == 0 ) {
2601 } else if ( strcasecmp( c->argv[1], "TRUE" ) != 0 ) {
2603 snprintf( c->cr_msg, sizeof( c->cr_msg),
2604 "subordinate must be \"TRUE\" or \"advertise\"" );
2605 Debug( LDAP_DEBUG_ANY,
2606 "%s: suffix \"%s\": %s.\n",
2607 c->log, c->be->be_suffix[0].bv_val, c->cr_msg );
2613 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2621 * [listener=<listener>] [{read|write}=]<size>
2624 #ifdef LDAP_TCP_BUFFER
2625 static BerVarray tcp_buffer;
2628 #define SLAP_TCP_RMEM (0x1U)
2629 #define SLAP_TCP_WMEM (0x2U)
2632 tcp_buffer_parse( struct berval *val, int argc, char **argv,
2633 int *size, int *rw, Listener **l )
2635 int i, rc = LDAP_SUCCESS;
2636 LDAPURLDesc *lud = NULL;
2639 if ( val != NULL && argv == NULL ) {
2640 char *s = val->bv_val;
2642 argv = ldap_str2charray( s, " \t" );
2643 if ( argv == NULL ) {
2649 if ( strncasecmp( argv[ i ], "listener=", STRLENOF( "listener=" ) )
2652 char *url = argv[ i ] + STRLENOF( "listener=" );
2654 if ( ldap_url_parse( url, &lud ) ) {
2655 rc = LDAP_INVALID_SYNTAX;
2659 *l = config_check_my_url( url, lud );
2661 rc = LDAP_NO_SUCH_ATTRIBUTE;
2669 if ( strncasecmp( ptr, "read=", STRLENOF( "read=" ) ) == 0 ) {
2670 *rw |= SLAP_TCP_RMEM;
2671 ptr += STRLENOF( "read=" );
2673 } else if ( strncasecmp( ptr, "write=", STRLENOF( "write=" ) ) == 0 ) {
2674 *rw |= SLAP_TCP_WMEM;
2675 ptr += STRLENOF( "write=" );
2678 *rw |= ( SLAP_TCP_RMEM | SLAP_TCP_WMEM );
2681 /* accept any base */
2682 if ( lutil_atoix( size, ptr, 0 ) ) {
2683 rc = LDAP_INVALID_SYNTAX;
2688 if ( val != NULL && argv != NULL ) {
2689 ldap_charray_free( argv );
2692 if ( lud != NULL ) {
2693 ldap_free_urldesc( lud );
2700 tcp_buffer_delete_one( struct berval *val )
2703 int size = -1, rw = 0;
2706 rc = tcp_buffer_parse( val, 0, NULL, &size, &rw, &l );
2713 Listener **ll = slapd_get_listeners();
2715 for ( i = 0; ll[ i ] != NULL; i++ ) {
2716 if ( ll[ i ] == l ) break;
2719 if ( ll[ i ] == NULL ) {
2720 return LDAP_NO_SUCH_ATTRIBUTE;
2723 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = -1;
2724 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = -1;
2726 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2727 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = -1;
2728 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = -1;
2732 /* NOTE: this affects listeners without a specific setting,
2733 * does not reset all listeners. If a listener without
2734 * specific settings was assigned a buffer because of
2735 * a global setting, it will not be reset. In any case,
2736 * buffer changes will only take place at restart. */
2737 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = -1;
2738 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = -1;
2745 tcp_buffer_delete( BerVarray vals )
2749 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
2750 tcp_buffer_delete_one( &vals[ i ] );
2757 tcp_buffer_unparse( int size, int rw, Listener *l, struct berval *val )
2759 char buf[sizeof("2147483648")], *ptr;
2761 /* unparse for later use */
2762 val->bv_len = snprintf( buf, sizeof( buf ), "%d", size );
2764 val->bv_len += STRLENOF( "listener=" " " ) + l->sl_url.bv_len;
2767 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2768 if ( rw & SLAP_TCP_RMEM ) {
2769 val->bv_len += STRLENOF( "read=" );
2770 } else if ( rw & SLAP_TCP_WMEM ) {
2771 val->bv_len += STRLENOF( "write=" );
2775 val->bv_val = SLAP_MALLOC( val->bv_len + 1 );
2780 ptr = lutil_strcopy( ptr, "listener=" );
2781 ptr = lutil_strncopy( ptr, l->sl_url.bv_val, l->sl_url.bv_len );
2785 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2786 if ( rw & SLAP_TCP_RMEM ) {
2787 ptr = lutil_strcopy( ptr, "read=" );
2788 } else if ( rw & SLAP_TCP_WMEM ) {
2789 ptr = lutil_strcopy( ptr, "write=" );
2793 ptr = lutil_strcopy( ptr, buf );
2796 assert( val->bv_val + val->bv_len == ptr );
2798 return LDAP_SUCCESS;
2802 tcp_buffer_add_one( int argc, char **argv )
2805 int size = -1, rw = 0;
2811 rc = tcp_buffer_parse( NULL, argc, argv, &size, &rw, &l );
2816 /* unparse for later use */
2817 rc = tcp_buffer_unparse( size, rw, l, &val );
2818 if ( rc != LDAP_SUCCESS ) {
2822 /* use parsed values */
2825 Listener **ll = slapd_get_listeners();
2827 for ( i = 0; ll[ i ] != NULL; i++ ) {
2828 if ( ll[ i ] == l ) break;
2831 if ( ll[ i ] == NULL ) {
2832 return LDAP_NO_SUCH_ATTRIBUTE;
2835 /* buffer only applies to TCP listeners;
2836 * we do not do any check here, and delegate them
2837 * to setsockopt(2) */
2838 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = size;
2839 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = size;
2841 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2842 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = size;
2843 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = size;
2847 /* NOTE: this affects listeners without a specific setting,
2848 * does not set all listeners */
2849 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = size;
2850 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = size;
2853 tcp_buffer = SLAP_REALLOC( tcp_buffer, sizeof( struct berval ) * ( tcp_buffer_num + 2 ) );
2855 tcp_buffer[ tcp_buffer_num ] = val;
2858 BER_BVZERO( &tcp_buffer[ tcp_buffer_num ] );
2864 config_tcp_buffer( ConfigArgs *c )
2866 if ( c->op == SLAP_CONFIG_EMIT ) {
2867 if ( tcp_buffer == NULL || BER_BVISNULL( &tcp_buffer[ 0 ] ) ) {
2870 value_add( &c->rvalue_vals, tcp_buffer );
2871 value_add( &c->rvalue_nvals, tcp_buffer );
2873 } else if ( c->op == LDAP_MOD_DELETE ) {
2875 tcp_buffer_delete( tcp_buffer );
2876 ber_bvarray_free( tcp_buffer );
2882 int size = -1, rw = 0;
2885 struct berval val = BER_BVNULL;
2889 if ( tcp_buffer_num == 0 ) {
2894 rc = tcp_buffer_parse( NULL, c->argc - 1, &c->argv[ 1 ], &size, &rw, &l );
2899 /* unparse for later use */
2900 rc = tcp_buffer_unparse( size, rw, l, &val );
2901 if ( rc != LDAP_SUCCESS ) {
2905 for ( i = 0; !BER_BVISNULL( &tcp_buffer[ i ] ); i++ ) {
2906 if ( bvmatch( &tcp_buffer[ i ], &val ) ) {
2911 if ( BER_BVISNULL( &tcp_buffer[ i ] ) ) {
2917 tcp_buffer_delete_one( &tcp_buffer[ i ] );
2918 ber_memfree( tcp_buffer[ i ].bv_val );
2919 for ( ; i < tcp_buffer_num; i++ ) {
2920 tcp_buffer[ i ] = tcp_buffer[ i + 1 ];
2925 if ( !BER_BVISNULL( &val ) ) {
2926 SLAP_FREE( val.bv_val );
2934 rc = tcp_buffer_add_one( c->argc - 1, &c->argv[ 1 ] );
2936 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2937 "<%s> unable to add value #%d",
2938 c->argv[0], tcp_buffer_num );
2939 Debug( LDAP_DEBUG_ANY, "%s: %s\n",
2940 c->log, c->cr_msg, 0 );
2947 #endif /* LDAP_TCP_BUFFER */
2950 config_suffix(ConfigArgs *c)
2953 struct berval pdn, ndn;
2954 char *notallowed = NULL;
2956 if ( c->be == frontendDB ) {
2957 notallowed = "frontend";
2959 } else if ( SLAP_MONITOR(c->be) ) {
2960 notallowed = "monitor";
2962 } else if ( SLAP_CONFIG(c->be) ) {
2963 notallowed = "config";
2966 if ( notallowed != NULL ) {
2967 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
2971 case LDAP_MOD_DELETE:
2972 case LDAP_MOD_REPLACE:
2973 case LDAP_MOD_INCREMENT:
2974 case SLAP_CONFIG_ADD:
2975 if ( !BER_BVISNULL( &c->value_dn ) ) {
2976 snprintf( buf, sizeof( buf ), "<%s> ",
2977 c->value_dn.bv_val );
2980 Debug(LDAP_DEBUG_ANY,
2981 "%s: suffix %snot allowed in %s database.\n",
2982 c->log, buf, notallowed );
2985 case SLAP_CONFIG_EMIT:
2986 /* don't complain when emitting... */
2990 /* FIXME: don't know what values may be valid;
2991 * please remove assertion, or add legal values
2992 * to either block */
3000 if (c->op == SLAP_CONFIG_EMIT) {
3001 if ( c->be->be_suffix == NULL
3002 || BER_BVISNULL( &c->be->be_suffix[0] ) )
3006 value_add( &c->rvalue_vals, c->be->be_suffix );
3007 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
3010 } else if ( c->op == LDAP_MOD_DELETE ) {
3011 if ( c->valx < 0 ) {
3012 ber_bvarray_free( c->be->be_suffix );
3013 ber_bvarray_free( c->be->be_nsuffix );
3014 c->be->be_suffix = NULL;
3015 c->be->be_nsuffix = NULL;
3018 ch_free( c->be->be_suffix[i].bv_val );
3019 ch_free( c->be->be_nsuffix[i].bv_val );
3021 c->be->be_suffix[i] = c->be->be_suffix[i+1];
3022 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
3024 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
3029 #ifdef SLAPD_MONITOR_DN
3030 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
3031 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> DN is reserved for monitoring slapd",
3033 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3034 c->log, c->cr_msg, SLAPD_MONITOR_DN);
3039 if (SLAP_DB_ONE_SUFFIX( c->be ) && c->be->be_suffix ) {
3040 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> Only one suffix is allowed on this %s backend",
3041 c->argv[0], c->be->bd_info->bi_type );
3042 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3043 c->log, c->cr_msg, 0);
3050 if (SLAP_DBHIDDEN( c->be ))
3053 tbe = select_backend(&ndn, 0);
3055 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
3061 BackendDB *b2 = tbe;
3063 /* Does tbe precede be? */
3064 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
3067 char *type = tbe->bd_info->bi_type;
3069 if ( overlay_is_over( tbe ) ) {
3070 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
3071 type = oi->oi_orig->bi_type;
3074 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> namingContext \"%s\" "
3075 "already served by a preceding %s database",
3076 c->argv[0], pdn.bv_val, type );
3077 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
3078 c->log, c->cr_msg, tbe->be_suffix[0].bv_val);
3084 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
3085 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
3086 "base provided \"%s\" (assuming okay)\n",
3087 c->log, default_search_base.bv_val, 0);
3089 ber_bvarray_add(&c->be->be_suffix, &pdn);
3090 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
3095 config_rootdn(ConfigArgs *c) {
3096 if (c->op == SLAP_CONFIG_EMIT) {
3097 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
3098 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
3099 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
3104 } else if ( c->op == LDAP_MOD_DELETE ) {
3105 ch_free( c->be->be_rootdn.bv_val );
3106 ch_free( c->be->be_rootndn.bv_val );
3107 BER_BVZERO( &c->be->be_rootdn );
3108 BER_BVZERO( &c->be->be_rootndn );
3111 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
3112 ch_free( c->be->be_rootdn.bv_val );
3113 ch_free( c->be->be_rootndn.bv_val );
3115 c->be->be_rootdn = c->value_dn;
3116 c->be->be_rootndn = c->value_ndn;
3121 config_rootpw(ConfigArgs *c) {
3124 if (c->op == SLAP_CONFIG_EMIT) {
3125 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
3126 /* don't copy, because "rootpw" is marked
3128 c->value_bv = c->be->be_rootpw;
3132 } else if ( c->op == LDAP_MOD_DELETE ) {
3133 ch_free( c->be->be_rootpw.bv_val );
3134 BER_BVZERO( &c->be->be_rootpw );
3138 tbe = select_backend(&c->be->be_rootndn, 0);
3140 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> can only be set when rootdn is under suffix",
3142 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3143 c->log, c->cr_msg, 0);
3146 if ( !BER_BVISNULL( &c->be->be_rootpw ))
3147 ch_free( c->be->be_rootpw.bv_val );
3148 c->be->be_rootpw = c->value_bv;
3153 config_restrict(ConfigArgs *c) {
3154 slap_mask_t restrictops = 0;
3156 slap_verbmasks restrictable_ops[] = {
3157 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
3158 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
3159 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
3160 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
3161 { BER_BVC("modrdn"), 0 },
3162 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
3163 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
3164 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
3165 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
3166 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
3167 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
3168 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
3169 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
3170 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
3171 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
3172 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
3176 if (c->op == SLAP_CONFIG_EMIT) {
3177 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
3179 } else if ( c->op == LDAP_MOD_DELETE ) {
3181 c->be->be_restrictops = 0;
3183 restrictops = verb_to_mask( c->line, restrictable_ops );
3184 c->be->be_restrictops ^= restrictops;
3188 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
3190 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown operation", c->argv[0] );
3191 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3192 c->log, c->cr_msg, c->argv[i]);
3195 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
3196 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
3197 c->be->be_restrictops |= restrictops;
3202 config_allows(ConfigArgs *c) {
3203 slap_mask_t allows = 0;
3205 slap_verbmasks allowable_ops[] = {
3206 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
3207 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
3208 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
3209 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
3210 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
3213 if (c->op == SLAP_CONFIG_EMIT) {
3214 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
3215 } else if ( c->op == LDAP_MOD_DELETE ) {
3219 allows = verb_to_mask( c->line, allowable_ops );
3220 global_allows ^= allows;
3224 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
3226 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3227 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3228 c->log, c->cr_msg, c->argv[i]);
3231 global_allows |= allows;
3236 config_disallows(ConfigArgs *c) {
3237 slap_mask_t disallows = 0;
3239 slap_verbmasks disallowable_ops[] = {
3240 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
3241 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
3242 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
3243 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
3244 { BER_BVC("proxy_authz_non_critical"), SLAP_DISALLOW_PROXY_AUTHZ_N_CRIT },
3245 { BER_BVC("dontusecopy_non_critical"), SLAP_DISALLOW_DONTUSECOPY_N_CRIT },
3248 if (c->op == SLAP_CONFIG_EMIT) {
3249 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
3250 } else if ( c->op == LDAP_MOD_DELETE ) {
3252 global_disallows = 0;
3254 disallows = verb_to_mask( c->line, disallowable_ops );
3255 global_disallows ^= disallows;
3259 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
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_disallows |= disallows;
3271 config_requires(ConfigArgs *c) {
3272 slap_mask_t requires = frontendDB->be_requires;
3273 int i, argc = c->argc;
3274 char **argv = c->argv;
3276 slap_verbmasks requires_ops[] = {
3277 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
3278 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
3279 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
3280 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
3281 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
3284 if (c->op == SLAP_CONFIG_EMIT) {
3285 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
3286 } else if ( c->op == LDAP_MOD_DELETE ) {
3288 c->be->be_requires = 0;
3290 requires = verb_to_mask( c->line, requires_ops );
3291 c->be->be_requires ^= requires;
3295 /* "none" can only be first, to wipe out default/global values */
3296 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
3301 i = verbs_to_mask(argc, argv, requires_ops, &requires);
3303 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
3304 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
3305 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3306 c->log, c->cr_msg, 0);
3308 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
3309 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3310 c->log, c->cr_msg, c->argv[i]);
3314 c->be->be_requires = requires;
3319 config_extra_attrs(ConfigArgs *c)
3321 assert( c->be != NULL );
3323 if ( c->op == SLAP_CONFIG_EMIT ) {
3326 if ( c->be->be_extra_anlist == NULL ) {
3330 for ( i = 0; !BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ); i++ ) {
3331 value_add_one( &c->rvalue_vals, &c->be->be_extra_anlist[i].an_name );
3334 } else if ( c->op == LDAP_MOD_DELETE ) {
3335 if ( c->be->be_extra_anlist == NULL ) {
3339 if ( c->valx < 0 ) {
3340 anlist_free( c->be->be_extra_anlist, 1, NULL );
3341 c->be->be_extra_anlist = NULL;
3346 for ( i = 0; i < c->valx && !BER_BVISNULL( &c->be->be_extra_anlist[i + 1].an_name ); i++ )
3349 if ( BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ) ) {
3353 ch_free( c->be->be_extra_anlist[i].an_name.bv_val );
3355 for ( ; !BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ); i++ ) {
3356 c->be->be_extra_anlist[i] = c->be->be_extra_anlist[i + 1];
3361 c->be->be_extra_anlist = str2anlist( c->be->be_extra_anlist, c->argv[1], " ,\t" );
3362 if ( c->be->be_extra_anlist == NULL ) {
3370 static slap_verbmasks *loglevel_ops;
3373 loglevel_init( void )
3375 slap_verbmasks lo[] = {
3376 { BER_BVC("Any"), (slap_mask_t) LDAP_DEBUG_ANY },
3377 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
3378 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
3379 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
3380 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
3381 { BER_BVC("BER"), LDAP_DEBUG_BER },
3382 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
3383 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
3384 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
3385 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
3386 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
3387 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
3388 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
3389 #if 0 /* no longer used (nor supported) */
3390 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
3391 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
3393 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
3394 { BER_BVC("None"), LDAP_DEBUG_NONE },
3398 return slap_verbmasks_init( &loglevel_ops, lo );
3402 loglevel_destroy( void )
3404 if ( loglevel_ops ) {
3405 (void)slap_verbmasks_destroy( loglevel_ops );
3407 loglevel_ops = NULL;
3410 static slap_mask_t loglevel_ignore[] = { -1, 0 };
3413 slap_loglevel_register( slap_mask_t m, struct berval *s )
3417 if ( loglevel_ops == NULL ) {
3421 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
3424 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
3432 slap_loglevel_get( struct berval *s, int *l )
3437 if ( loglevel_ops == NULL ) {
3441 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3442 m |= loglevel_ops[ i ].mask;
3445 for ( i = 1; m & i; i <<= 1 )
3452 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
3455 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
3466 str2loglevel( const char *s, int *l )
3470 if ( loglevel_ops == NULL ) {
3474 i = verb_to_mask( s, loglevel_ops );
3476 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
3480 *l = loglevel_ops[ i ].mask;
3486 loglevel2str( int l )
3488 struct berval bv = BER_BVNULL;
3490 loglevel2bv( l, &bv );
3496 loglevel2bv( int l, struct berval *bv )
3498 if ( loglevel_ops == NULL ) {
3504 return enum_to_verb( loglevel_ops, l, bv ) == -1;
3508 loglevel2bvarray( int l, BerVarray *bva )
3510 if ( loglevel_ops == NULL ) {
3514 return mask_to_verbs( loglevel_ops, l, bva );
3518 loglevel_print( FILE *out )
3522 if ( loglevel_ops == NULL ) {
3526 fprintf( out, "Installed log subsystems:\n\n" );
3527 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3528 unsigned mask = loglevel_ops[ i ].mask & 0xffffffffUL;
3530 (mask == ((slap_mask_t) -1 & 0xffffffffUL)
3531 ? "\t%-30s (-1, 0xffffffff)\n" : "\t%-30s (%u, 0x%x)\n"),
3532 loglevel_ops[ i ].word.bv_val, mask, mask );
3535 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
3536 "by specific code\n\n" );
3541 static int config_syslog;
3544 config_loglevel(ConfigArgs *c) {
3547 if ( loglevel_ops == NULL ) {
3551 if (c->op == SLAP_CONFIG_EMIT) {
3552 /* Get default or commandline slapd setting */
3553 if ( ldap_syslog && !config_syslog )
3554 config_syslog = ldap_syslog;
3555 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
3557 } else if ( c->op == LDAP_MOD_DELETE ) {
3561 int level = verb_to_mask( c->line, loglevel_ops );
3562 config_syslog ^= level;
3564 if ( slapMode & SLAP_SERVER_MODE ) {
3565 ldap_syslog = config_syslog;
3570 for( i=1; i < c->argc; i++ ) {
3573 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
3574 if( lutil_atoix( &level, c->argv[i], 0 ) != 0 ) {
3575 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse level", c->argv[0] );
3576 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3577 c->log, c->cr_msg, c->argv[i]);
3581 if ( str2loglevel( c->argv[i], &level ) ) {
3582 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown level", c->argv[0] );
3583 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3584 c->log, c->cr_msg, c->argv[i]);
3588 /* Explicitly setting a zero clears all the levels */
3590 config_syslog |= level;
3594 if ( slapMode & SLAP_SERVER_MODE ) {
3595 ldap_syslog = config_syslog;
3601 config_referral(ConfigArgs *c) {
3603 if (c->op == SLAP_CONFIG_EMIT) {
3604 if ( default_referral ) {
3605 value_add( &c->rvalue_vals, default_referral );
3610 } else if ( c->op == LDAP_MOD_DELETE ) {
3611 if ( c->valx < 0 ) {
3612 ber_bvarray_free( default_referral );
3613 default_referral = NULL;
3616 ch_free( default_referral[i].bv_val );
3617 for (; default_referral[i].bv_val; i++ )
3618 default_referral[i] = default_referral[i+1];
3622 if(validate_global_referral(c->argv[1])) {
3623 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3624 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3625 c->log, c->cr_msg, c->argv[1]);
3629 ber_str2bv(c->argv[1], 0, 0, &val);
3630 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
3638 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
3639 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
3640 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
3641 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
3642 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
3643 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
3644 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
3645 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
3646 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
3651 config_security(ConfigArgs *c) {
3652 slap_ssf_set_t *set = &c->be->be_ssf_set;
3655 if (c->op == SLAP_CONFIG_EMIT) {
3661 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
3662 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
3665 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
3666 if ( bv.bv_len >= sizeof( numbuf ) ) {
3667 ber_bvarray_free_x( c->rvalue_vals, NULL );
3668 c->rvalue_vals = NULL;
3672 bv.bv_len += sec_keys[i].key.bv_len;
3673 bv.bv_val = ch_malloc( bv.bv_len + 1);
3674 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
3675 strcpy( next, numbuf );
3676 ber_bvarray_add( &c->rvalue_vals, &bv );
3681 for(i = 1; i < c->argc; i++) {
3682 slap_ssf_t *tgt = NULL;
3684 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
3685 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
3686 sec_keys[j].key.bv_len)) {
3687 src = c->argv[i] + sec_keys[j].key.bv_len;
3688 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
3693 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown factor", c->argv[0] );
3694 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3695 c->log, c->cr_msg, c->argv[i]);
3699 if ( lutil_atou( tgt, src ) != 0 ) {
3700 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse factor", c->argv[0] );
3701 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3702 c->log, c->cr_msg, c->argv[i]);
3710 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
3714 for (; !BER_BVISNULL( &an->an_name ); an++) {
3715 /* if buflen == 0, assume the buffer size has been
3716 * already checked otherwise */
3717 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
3718 if ( comma ) *ptr++ = ',';
3719 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
3726 config_updatedn(ConfigArgs *c) {
3727 if (c->op == SLAP_CONFIG_EMIT) {
3728 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
3729 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
3730 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
3734 } else if ( c->op == LDAP_MOD_DELETE ) {
3735 ch_free( c->be->be_update_ndn.bv_val );
3736 BER_BVZERO( &c->be->be_update_ndn );
3737 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
3740 if(SLAP_SHADOW(c->be)) {
3741 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database already shadowed", c->argv[0] );
3742 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3743 c->log, c->cr_msg, 0);
3747 ber_memfree_x( c->value_dn.bv_val, NULL );
3748 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
3749 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
3751 c->be->be_update_ndn = c->value_ndn;
3752 BER_BVZERO( &c->value_dn );
3753 BER_BVZERO( &c->value_ndn );
3755 return config_slurp_shadow( c );
3759 config_shadow( ConfigArgs *c, slap_mask_t flag )
3761 char *notallowed = NULL;
3763 if ( c->be == frontendDB ) {
3764 notallowed = "frontend";
3766 } else if ( SLAP_MONITOR(c->be) ) {
3767 notallowed = "monitor";
3770 if ( notallowed != NULL ) {
3771 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
3775 if ( SLAP_SHADOW(c->be) ) {
3776 /* if already shadow, only check consistency */
3777 if ( ( SLAP_DBFLAGS(c->be) & flag ) != flag ) {
3778 Debug( LDAP_DEBUG_ANY, "%s: inconsistent shadow flag 0x%lx.\n",
3784 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SINGLE_SHADOW | flag);
3791 config_updateref(ConfigArgs *c) {
3793 if (c->op == SLAP_CONFIG_EMIT) {
3794 if ( c->be->be_update_refs ) {
3795 value_add( &c->rvalue_vals, c->be->be_update_refs );
3800 } else if ( c->op == LDAP_MOD_DELETE ) {
3801 if ( c->valx < 0 ) {
3802 ber_bvarray_free( c->be->be_update_refs );
3803 c->be->be_update_refs = NULL;
3806 ch_free( c->be->be_update_refs[i].bv_val );
3807 for (; c->be->be_update_refs[i].bv_val; i++)
3808 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
3812 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
3813 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must appear after syncrepl or updatedn",
3815 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3816 c->log, c->cr_msg, 0);
3820 if(validate_global_referral(c->argv[1])) {
3821 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3822 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3823 c->log, c->cr_msg, c->argv[1]);
3826 ber_str2bv(c->argv[1], 0, 0, &val);
3827 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
3832 config_obsolete(ConfigArgs *c) {
3833 if (c->op == SLAP_CONFIG_EMIT)
3836 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> keyword is obsolete (ignored)",
3838 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0);
3843 config_include(ConfigArgs *c) {
3844 int savelineno = c->lineno;
3847 ConfigFile *cfsave = cfn;
3848 ConfigFile *cf2 = NULL;
3850 /* Leftover from RE23. No dynamic config for include files */
3851 if ( c->op == SLAP_CONFIG_EMIT || c->op == LDAP_MOD_DELETE )
3854 cf = ch_calloc( 1, sizeof(ConfigFile));
3855 if ( cfn->c_kids ) {
3856 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
3862 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
3863 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
3864 c->lineno = savelineno - 1;
3867 if ( cf2 ) cf2->c_sibs = NULL;
3868 else cfn->c_kids = NULL;
3869 ch_free( cf->c_file.bv_val );
3879 config_tls_cleanup(ConfigArgs *c) {
3882 if ( slap_tls_ld ) {
3885 ldap_pvt_tls_ctx_free( slap_tls_ctx );
3887 /* Force new ctx to be created */
3888 rc = ldap_pvt_tls_set_option( slap_tls_ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
3890 /* The ctx's refcount is bumped up here */
3891 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CTX, &slap_tls_ctx );
3892 /* This is a no-op if it's already loaded */
3893 load_extop( &slap_EXOP_START_TLS, 0, starttls_extop );
3900 config_tls_option(ConfigArgs *c) {
3902 LDAP *ld = slap_tls_ld;
3904 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
3905 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
3906 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
3907 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
3908 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
3909 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
3910 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
3912 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
3914 default: Debug(LDAP_DEBUG_ANY, "%s: "
3915 "unknown tls_option <0x%x>\n",
3916 c->log, c->type, 0);
3919 if (c->op == SLAP_CONFIG_EMIT) {
3920 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
3921 } else if ( c->op == LDAP_MOD_DELETE ) {
3922 c->cleanup = config_tls_cleanup;
3923 return ldap_pvt_tls_set_option( ld, flag, NULL );
3925 ch_free(c->value_string);
3926 c->cleanup = config_tls_cleanup;
3927 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
3930 /* FIXME: this ought to be provided by libldap */
3932 config_tls_config(ConfigArgs *c) {
3935 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
3936 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
3937 case CFG_TLS_PROTOCOL_MIN: flag = LDAP_OPT_X_TLS_PROTOCOL_MIN; break;
3939 Debug(LDAP_DEBUG_ANY, "%s: "
3940 "unknown tls_option <0x%x>\n",
3941 c->log, c->type, 0);
3944 if (c->op == SLAP_CONFIG_EMIT) {
3945 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
3946 } else if ( c->op == LDAP_MOD_DELETE ) {
3948 c->cleanup = config_tls_cleanup;
3949 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
3951 ch_free( c->value_string );
3952 c->cleanup = config_tls_cleanup;
3953 if ( isdigit( (unsigned char)c->argv[1][0] ) ) {
3954 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
3955 Debug(LDAP_DEBUG_ANY, "%s: "
3956 "unable to parse %s \"%s\"\n",
3957 c->log, c->argv[0], c->argv[1] );
3960 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
3962 return(ldap_pvt_tls_config(slap_tls_ld, flag, c->argv[1]));
3967 static CfEntryInfo *
3968 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
3978 if ( dn_match( &root->ce_entry->e_nname, dn ))
3981 c = dn->bv_val+dn->bv_len;
3982 for (;*c != ',';c--);
3986 for (--c;c>dn->bv_val && *c != ',';c--);
3990 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
3992 root = root->ce_kids;
3994 for (;root;root=root->ce_sibs) {
3995 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
3996 if ( cdn.bv_val == dn->bv_val ) {
4006 typedef struct setup_cookie {
4016 config_ldif_resp( Operation *op, SlapReply *rs )
4018 if ( rs->sr_type == REP_SEARCH ) {
4019 setup_cookie *sc = op->o_callback->sc_private;
4022 sc->cfb->cb_got_ldif = 1;
4023 /* Does the frontend exist? */
4024 if ( !sc->got_frontend ) {
4025 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
4026 "olcDatabase", STRLENOF( "olcDatabase" )))
4028 if ( strncmp( rs->sr_entry->e_nname.bv_val +
4029 STRLENOF( "olcDatabase" ), "={-1}frontend",
4030 STRLENOF( "={-1}frontend" )))
4034 sc->ca->be = frontendDB;
4035 sc->ca->bi = frontendDB->bd_info;
4036 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
4037 rdn.bv_val = sc->ca->log;
4038 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
4039 "%s=" SLAP_X_ORDERED_FMT "%s",
4040 cfAd_database->ad_cname.bv_val, -1,
4041 sc->ca->bi->bi_type);
4043 sc->frontend = config_build_entry( op, rs,
4044 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
4045 sc->ca->be->be_cf_ocs );
4055 dnParent( &rs->sr_entry->e_nname, &pdn );
4057 /* Does the configDB exist? */
4058 if ( sc->got_frontend && !sc->got_config &&
4059 !strncmp( rs->sr_entry->e_nname.bv_val,
4060 "olcDatabase", STRLENOF( "olcDatabase" )) &&
4061 dn_match( &config_rdn, &pdn ) )
4063 if ( strncmp( rs->sr_entry->e_nname.bv_val +
4064 STRLENOF( "olcDatabase" ), "={0}config",
4065 STRLENOF( "={0}config" )))
4069 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
4070 sc->ca->bi = sc->ca->be->bd_info;
4071 rdn.bv_val = sc->ca->log;
4072 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
4073 "%s=" SLAP_X_ORDERED_FMT "%s",
4074 cfAd_database->ad_cname.bv_val, 0,
4075 sc->ca->bi->bi_type);
4077 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
4078 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
4085 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
4086 if ( rs->sr_err != LDAP_SUCCESS ) {
4087 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
4088 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg, 0 );
4094 /* Configure and read the underlying back-ldif store */
4096 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
4097 CfBackInfo *cfb = be->be_private;
4103 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
4104 Connection conn = {0};
4105 OperationBuffer opbuf;
4107 SlapReply rs = {REP_RESULT};
4108 Filter filter = { LDAP_FILTER_PRESENT };
4109 struct berval filterstr = BER_BVC("(objectclass=*)");
4112 /* Is the config directory available? */
4113 if ( stat( dir, &st ) < 0 ) {
4114 /* No, so don't bother using the backing store.
4115 * All changes will be in-memory only.
4120 cfb->cb_db.bd_info = backend_info( "ldif" );
4121 if ( !cfb->cb_db.bd_info )
4122 return 0; /* FIXME: eventually this will be a fatal error */
4124 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
4127 cfb->cb_db.be_suffix = be->be_suffix;
4128 cfb->cb_db.be_nsuffix = be->be_nsuffix;
4130 /* The suffix is always "cn=config". The underlying DB's rootdn
4131 * is always the same as the suffix.
4133 cfb->cb_db.be_rootdn = be->be_suffix[0];
4134 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
4136 ber_str2bv( dir, 0, 1, &cfdir );
4141 argv[0] = "directory";
4142 argv[1] = (char *)dir;
4147 c.table = Cft_Database;
4149 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
4153 if ( config_add_vals( ct, &c ))
4156 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
4160 void *thrctx = ldap_pvt_thread_pool_context();
4163 connection_fake_init( &conn, &opbuf, thrctx );
4166 filter.f_desc = slap_schema.si_ad_objectClass;
4168 op->o_tag = LDAP_REQ_SEARCH;
4170 op->ors_filter = &filter;
4171 op->ors_filterstr = filterstr;
4172 op->ors_scope = LDAP_SCOPE_SUBTREE;
4174 op->o_dn = c.be->be_rootdn;
4175 op->o_ndn = c.be->be_rootndn;
4177 op->o_req_dn = be->be_suffix[0];
4178 op->o_req_ndn = be->be_nsuffix[0];
4180 op->ors_tlimit = SLAP_NO_LIMIT;
4181 op->ors_slimit = SLAP_NO_LIMIT;
4183 op->ors_attrs = slap_anlist_all_attributes;
4184 op->ors_attrsonly = 0;
4186 op->o_callback = &cb;
4189 cb.sc_private = ≻
4190 sc.got_frontend = 0;
4195 op->o_bd = &cfb->cb_db;
4197 /* Allow unknown attrs in DNs */
4198 prev_DN_strict = slap_DN_strict;
4201 rc = op->o_bd->be_search( op, &rs );
4203 /* Restore normal DN validation */
4204 slap_DN_strict = prev_DN_strict;
4206 op->o_tag = LDAP_REQ_ADD;
4207 if ( rc == LDAP_SUCCESS && sc.frontend ) {
4208 rs_reinit( &rs, REP_RESULT );
4209 op->ora_e = sc.frontend;
4210 rc = op->o_bd->be_add( op, &rs );
4212 if ( rc == LDAP_SUCCESS && sc.config ) {
4213 rs_reinit( &rs, REP_RESULT );
4214 op->ora_e = sc.config;
4215 rc = op->o_bd->be_add( op, &rs );
4217 ldap_pvt_thread_pool_context_reset( thrctx );
4220 /* ITS#4194 - only use if it's present, or we're converting. */
4221 if ( !readit || rc == LDAP_SUCCESS )
4222 cfb->cb_use_ldif = 1;
4228 CfOc_cmp( const void *c1, const void *c2 ) {
4229 const ConfigOCs *co1 = c1;
4230 const ConfigOCs *co2 = c2;
4232 return ber_bvcmp( co1->co_name, co2->co_name );
4236 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
4239 i = init_config_attrs( ct );
4242 /* set up the objectclasses */
4243 i = init_config_ocs( ocs );
4246 for (i=0; ocs[i].co_def; i++) {
4247 if ( ocs[i].co_oc ) {
4248 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
4249 if ( !ocs[i].co_table )
4250 ocs[i].co_table = ct;
4251 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
4258 read_config(const char *fname, const char *dir) {
4261 const char *cfdir, *cfname;
4264 /* Setup the config backend */
4265 be = backend_db_init( "config", NULL, 0, NULL );
4269 cfb = be->be_private;
4270 be->be_dfltaccess = ACL_NONE;
4272 /* If no .conf, or a dir was specified, setup the dir */
4273 if ( !fname || dir ) {
4275 /* If explicitly given, check for existence */
4278 if ( stat( dir, &st ) < 0 ) {
4279 Debug( LDAP_DEBUG_ANY,
4280 "invalid config directory %s, error %d\n",
4286 cfdir = SLAPD_DEFAULT_CONFIGDIR;
4288 /* if fname is defaulted, try reading .d */
4289 rc = config_setup_ldif( be, cfdir, !fname );
4292 /* It may be OK if the base object doesn't exist yet. */
4293 if ( rc != LDAP_NO_SUCH_OBJECT )
4295 /* ITS#4194: But if dir was specified and no fname,
4296 * then we were supposed to read the dir. Unless we're
4297 * trying to slapadd the dir...
4299 if ( dir && !fname ) {
4300 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
4302 /* Assume it's slapadd with a config dir, let it continue */
4304 cfb->cb_got_ldif = 1;
4305 cfb->cb_use_ldif = 1;
4310 /* If we read the config from back-ldif, nothing to do here */
4311 if ( cfb->cb_got_ldif ) {
4320 cfname = SLAPD_DEFAULT_CONFIGFILE;
4322 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
4325 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
4328 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
4329 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
4330 &frontendDB->be_schemadn );
4331 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
4332 if ( rc != LDAP_SUCCESS ) {
4333 Debug(LDAP_DEBUG_ANY, "read_config: "
4334 "unable to normalize default schema DN \"%s\"\n",
4335 frontendDB->be_schemadn.bv_val, 0, 0 );
4336 /* must not happen */
4344 config_back_bind( Operation *op, SlapReply *rs )
4346 if ( be_isroot_pw( op ) ) {
4347 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
4348 /* frontend sends result */
4349 return LDAP_SUCCESS;
4352 rs->sr_err = LDAP_INVALID_CREDENTIALS;
4353 send_ldap_result( op, rs );
4359 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
4363 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
4365 rs->sr_attrs = op->ors_attrs;
4366 rs->sr_entry = ce->ce_entry;
4368 rc = send_search_entry( op, rs );
4369 if ( rc != LDAP_SUCCESS ) {
4373 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
4374 if ( ce->ce_kids ) {
4375 rc = config_send( op, rs, ce->ce_kids, 1 );
4376 if ( rc ) return rc;
4379 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
4380 rc = config_send( op, rs, ce, 0 );
4388 static ConfigTable *
4389 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
4394 for (j=0; j<nocs; j++) {
4395 for (i=0; colst[j]->co_table[i].name; i++)
4396 if ( colst[j]->co_table[i].ad == ad ) {
4397 ca->table = colst[j]->co_type;
4398 return &colst[j]->co_table[i];
4404 /* Sort the attributes of the entry according to the order defined
4405 * in the objectclass, with required attributes occurring before
4406 * allowed attributes. For any attributes with sequencing dependencies
4407 * (e.g., rootDN must be defined after suffix) the objectclass must
4408 * list the attributes in the desired sequence.
4411 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
4413 Attribute *a, *head = NULL, *tail = NULL, **prev;
4416 for (i=0; i<nocs; i++) {
4417 if ( colst[i]->co_oc->soc_required ) {
4418 AttributeType **at = colst[i]->co_oc->soc_required;
4419 for (j=0; at[j]; j++) {
4420 for (a=e->e_attrs, prev=&e->e_attrs; a;
4421 prev = &(*prev)->a_next, a=a->a_next) {
4422 if ( a->a_desc == at[j]->sat_ad ) {
4436 if ( colst[i]->co_oc->soc_allowed ) {
4437 AttributeType **at = colst[i]->co_oc->soc_allowed;
4438 for (j=0; at[j]; j++) {
4439 for (a=e->e_attrs, prev=&e->e_attrs; a;
4440 prev = &(*prev)->a_next, a=a->a_next) {
4441 if ( a->a_desc == at[j]->sat_ad ) {
4457 tail->a_next = e->e_attrs;
4463 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
4465 Attribute *a = NULL;
4466 AttributeDescription *ad;
4476 Modifications *ml = ptr;
4478 vals = ml->sml_values;
4481 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
4482 rc = ordered_value_sort( a, 1 );
4484 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
4485 ad->ad_cname.bv_val );
4489 for ( i=0; vals[i].bv_val; i++ ) {
4490 ca->line = vals[i].bv_val;
4491 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
4492 ca->line[0] == '{' ) {
4493 char *idx = strchr( ca->line, '}' );
4494 if ( idx ) ca->line = idx+1;
4496 rc = config_parse_vals( ct, ca, i );
4505 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
4508 struct berval rtype, rval;
4510 AttributeDescription *ad = NULL;
4512 dnRdn( &e->e_name, rdn );
4513 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
4514 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
4515 rtype.bv_val = rdn->bv_val;
4516 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
4519 slap_bv2ad( &rtype, &ad, &rs->sr_text );
4520 a = attr_find( e->e_attrs, ad );
4521 if (!a ) return LDAP_NAMING_VIOLATION;
4528 config_rename_kids( CfEntryInfo *ce )
4531 struct berval rdn, nrdn;
4533 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
4534 struct berval newdn, newndn;
4535 dnRdn ( &ce2->ce_entry->e_name, &rdn );
4536 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
4537 build_new_dn( &newdn, &ce->ce_entry->e_name, &rdn, NULL );
4538 build_new_dn( &newndn, &ce->ce_entry->e_nname, &nrdn, NULL );
4539 free( ce2->ce_entry->e_name.bv_val );
4540 free( ce2->ce_entry->e_nname.bv_val );
4541 ce2->ce_entry->e_name = newdn;
4542 ce2->ce_entry->e_nname = newndn;
4543 config_rename_kids( ce2 );
4548 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
4549 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
4550 struct berval *nnewrdn, int use_ldif )
4554 struct berval odn, ondn;
4558 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
4559 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
4562 free( a->a_vals[0].bv_val );
4563 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
4564 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
4565 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
4566 strcpy( a->a_vals[0].bv_val, ptr1 );
4568 if ( a->a_nvals != a->a_vals ) {
4569 free( a->a_nvals[0].bv_val );
4570 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
4571 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
4572 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
4573 strcpy( a->a_nvals[0].bv_val, ptr1 );
4576 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
4577 BackendDB *be = op->o_bd;
4578 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4579 struct berval dn, ndn, xdn, xndn;
4581 op->o_bd = &cfb->cb_db;
4583 /* Save current rootdn; use the underlying DB's rootdn */
4587 xndn = op->o_req_ndn;
4588 op->o_dn = op->o_bd->be_rootdn;
4589 op->o_ndn = op->o_bd->be_rootndn;
4591 op->o_req_ndn = ondn;
4593 scp = op->o_callback;
4594 op->o_callback = ≻
4595 op->orr_newrdn = *newrdn;
4596 op->orr_nnewrdn = *nnewrdn;
4597 op->orr_newSup = NULL;
4598 op->orr_nnewSup = NULL;
4599 op->orr_deleteoldrdn = 1;
4600 op->orr_modlist = NULL;
4601 slap_modrdn2mods( op, rs );
4602 slap_mods_opattrs( op, &op->orr_modlist, 1 );
4603 rc = op->o_bd->be_modrdn( op, rs );
4604 slap_mods_free( op->orr_modlist, 1 );
4607 op->o_callback = scp;
4611 op->o_req_ndn = xndn;
4614 free( ondn.bv_val );
4616 config_rename_kids( e->e_private );
4621 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
4622 Entry *e, int idx, int tailindex, int use_ldif )
4624 struct berval ival, newrdn, nnewrdn;
4627 char ibuf[32], *ptr1, *ptr2 = NULL;
4630 rc = config_rename_attr( rs, e, &rdn, &a );
4631 if ( rc ) return rc;
4634 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
4635 if ( ival.bv_len >= sizeof( ibuf ) ) {
4636 return LDAP_NAMING_VIOLATION;
4639 newrdn.bv_len = rdn.bv_len + ival.bv_len;
4640 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
4643 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
4644 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4647 ptr2 = ber_bvchr( &rdn, '}' );
4651 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
4653 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
4654 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
4655 a->a_desc->ad_cname.bv_len );
4657 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4658 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
4662 /* Do the equivalent of ModRDN */
4663 /* Replace DN / NDN */
4664 newrdn.bv_len = ptr1 - newrdn.bv_val;
4665 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
4666 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
4668 free( nnewrdn.bv_val );
4669 free( newrdn.bv_val );
4674 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
4675 SlapReply *rs, int *renum, int *ibase )
4678 int index = -1, gotindex = 0, nsibs, rc = 0;
4679 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
4680 char *ptr1, *ptr2 = NULL;
4683 if ( renum ) *renum = 0;
4685 /* These entries don't get indexed/renumbered */
4686 if ( ce_type == Cft_Global ) return 0;
4687 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
4689 if ( ce_type == Cft_Module )
4692 /* See if the rdn has an index already */
4693 dnRdn( &e->e_name, &rdn );
4694 if ( ce_type == Cft_Database ) {
4695 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
4696 "frontend", STRLENOF("frontend") ))
4698 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
4699 "config", STRLENOF("config") ))
4702 ptr1 = ber_bvchr( &e->e_name, '{' );
4703 if ( ptr1 && ptr1 < &e->e_name.bv_val[ rdn.bv_len ] ) {
4705 ptr2 = strchr( ptr1, '}' );
4706 if ( !ptr2 || ptr2 > &e->e_name.bv_val[ rdn.bv_len ] )
4707 return LDAP_NAMING_VIOLATION;
4708 if ( ptr2-ptr1 == 1)
4709 return LDAP_NAMING_VIOLATION;
4711 index = strtol( ptr1 + 1, &next, 10 );
4712 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
4713 return LDAP_NAMING_VIOLATION;
4716 /* Special case, we allow -1 for the frontendDB */
4717 if ( index != -1 || !isfrontend )
4718 return LDAP_NAMING_VIOLATION;
4720 if ( isconfig && index != 0 ){
4721 return LDAP_NAMING_VIOLATION;
4725 /* count related kids */
4726 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
4727 if ( ce->ce_type == ce_type ) nsibs++;
4730 /* account for -1 frontend */
4731 if ( ce_type == Cft_Database )
4734 if ( index != nsibs ) {
4736 if ( index < nsibs ) {
4737 if ( tailindex ) return LDAP_NAMING_VIOLATION;
4738 /* Siblings need to be renumbered */
4739 if ( index != -1 || !isfrontend )
4743 /* config DB is always "0" */
4744 if ( isconfig && index == -1 ) {
4747 if (( !isfrontend && index == -1 ) || ( index > nsibs ) ){
4751 /* just make index = nsibs */
4753 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
4756 if ( ibase ) *ibase = index;
4757 if ( renum ) *renum = renumber;
4761 /* Insert all superior classes of the given class */
4763 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
4768 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
4769 if ( count_oc( *sups, copp, nocs ) ) {
4774 co.co_name = &oc->soc_cname;
4775 cop = avl_find( CfOcTree, &co, CfOc_cmp );
4779 /* check for duplicates */
4780 for ( i = 0; i < *nocs; i++ ) {
4781 if ( *copp && (*copp)[i] == cop ) {
4787 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
4788 if ( tmp == NULL ) {
4792 (*copp)[*nocs] = cop;
4800 /* Find all superior classes of the given objectclasses,
4801 * return list in order of most-subordinate first.
4803 * Special / auxiliary / Cft_Misc classes always take precedence.
4806 count_ocs( Attribute *oc_at, int *nocs )
4808 int i, j, misc = -1;
4809 ConfigOCs **colst = NULL;
4813 for ( i = oc_at->a_numvals; i--; ) {
4814 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
4816 assert( oc != NULL );
4817 if ( count_oc( oc, &colst, nocs ) ) {
4827 ConfigOCs *tmp = colst[i];
4828 colst[i] = colst[j];
4830 if (tmp->co_type == Cft_Misc)
4834 /* Move misc class to front of list */
4836 ConfigOCs *tmp = colst[misc];
4837 for (i=misc; i>0; i--)
4838 colst[i] = colst[i-1];
4846 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4848 /* Leftover from RE23. Never parse this entry */
4849 return LDAP_COMPARE_TRUE;
4853 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4857 /* This entry is hardcoded, don't re-parse it */
4858 if ( p->ce_type == Cft_Global ) {
4859 cfn = p->ce_private;
4860 ca->ca_private = cfn;
4861 return LDAP_COMPARE_TRUE;
4863 if ( p->ce_type != Cft_Schema )
4864 return LDAP_CONSTRAINT_VIOLATION;
4866 cfn = ch_calloc( 1, sizeof(ConfigFile) );
4867 ca->ca_private = cfn;
4868 cfo = p->ce_private;
4869 cfn->c_sibs = cfo->c_kids;
4871 return LDAP_SUCCESS;
4875 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4877 if ( p->ce_type != Cft_Global ) {
4878 return LDAP_CONSTRAINT_VIOLATION;
4880 /* config must be {0}, nothing else allowed */
4881 if ( !strncmp( e->e_nname.bv_val, "olcDatabase={0}", STRLENOF("olcDatabase={0}")) &&
4882 strncmp( e->e_nname.bv_val + STRLENOF("olcDatabase={0}"), "config,", STRLENOF("config,") )) {
4883 return LDAP_CONSTRAINT_VIOLATION;
4885 ca->be = frontendDB; /* just to get past check_vals */
4886 return LDAP_SUCCESS;
4890 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4892 if ( p->ce_type != Cft_Global ) {
4893 return LDAP_CONSTRAINT_VIOLATION;
4895 return LDAP_SUCCESS;
4899 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4901 if ( p->ce_type != Cft_Global ) {
4902 return LDAP_CONSTRAINT_VIOLATION;
4904 return LDAP_SUCCESS;
4908 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4910 if ( p->ce_type != Cft_Database ) {
4911 return LDAP_CONSTRAINT_VIOLATION;
4914 return LDAP_SUCCESS;
4918 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
4923 AttributeDescription *ad;
4929 if ( cfn->c_cr_head ) {
4930 struct berval bv = BER_BVC("olcDitContentRules");
4932 slap_bv2ad( &bv, &ad, &text );
4933 ct = config_find_table( colst, nocs, ad, ca );
4934 config_del_vals( ct, ca );
4936 if ( cfn->c_oc_head ) {
4937 struct berval bv = BER_BVC("olcObjectClasses");
4939 slap_bv2ad( &bv, &ad, &text );
4940 ct = config_find_table( colst, nocs, ad, ca );
4941 config_del_vals( ct, ca );
4943 if ( cfn->c_at_head ) {
4944 struct berval bv = BER_BVC("olcAttributeTypes");
4946 slap_bv2ad( &bv, &ad, &text );
4947 ct = config_find_table( colst, nocs, ad, ca );
4948 config_del_vals( ct, ca );
4950 if ( cfn->c_syn_head ) {
4951 struct berval bv = BER_BVC("olcLdapSyntaxes");
4953 slap_bv2ad( &bv, &ad, &text );
4954 ct = config_find_table( colst, nocs, ad, ca );
4955 config_del_vals( ct, ca );
4957 if ( cfn->c_om_head ) {
4958 struct berval bv = BER_BVC("olcObjectIdentifier");
4960 slap_bv2ad( &bv, &ad, &text );
4961 ct = config_find_table( colst, nocs, ad, ca );
4962 config_del_vals( ct, ca );
4964 cfo = p->ce_private;
4965 cfo->c_kids = cfn->c_sibs;
4970 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
4972 int rc = LDAP_CONSTRAINT_VIOLATION;
4975 if ( (*cop)->co_ldadd ) {
4976 rc = (*cop)->co_ldadd( last, e, ca );
4977 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4982 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
4983 ConfigOCs co = { 0 };
4985 co.co_name = &(*ocp)->soc_cname;
4986 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
4987 if ( *cop == NULL ) {
4991 rc = config_add_oc( cop, last, e, ca );
4992 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
5000 /* Parse an LDAP entry into config directives */
5002 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
5003 int *renum, Operation *op )
5005 CfEntryInfo *ce, *last = NULL;
5006 ConfigOCs co, *coptr, **colst;
5007 Attribute *a, *oc_at, *soc_at;
5008 int i, ibase = -1, nocs, rc = 0;
5011 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
5013 memset( ca, 0, sizeof(ConfigArgs));
5015 /* Make sure parent exists and entry does not. But allow
5016 * Databases and Overlays to be inserted. Don't do any
5017 * auto-renumbering if manageDSAit control is present.
5019 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
5021 if ( ( op && op->o_managedsait ) ||
5022 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
5023 ce->ce_type != Cft_Module ) )
5025 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5026 "DN=\"%s\" already exists\n",
5027 log_prefix, e->e_name.bv_val, 0 );
5028 /* global schema ignores all writes */
5029 if ( ce->ce_type == Cft_Schema && ce->ce_parent->ce_type == Cft_Global )
5030 return LDAP_COMPARE_TRUE;
5031 return LDAP_ALREADY_EXISTS;
5035 dnParent( &e->e_nname, &pdn );
5037 /* If last is NULL, the new entry is the root/suffix entry,
5038 * otherwise last should be the parent.
5040 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
5042 rs->sr_matched = last->ce_entry->e_name.bv_val;
5044 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5045 "DN=\"%s\" not child of DN=\"%s\"\n",
5046 log_prefix, e->e_name.bv_val,
5047 last->ce_entry->e_name.bv_val );
5048 return LDAP_NO_SUCH_OBJECT;
5052 /* No parent, must be root. This will never happen... */
5053 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
5054 return LDAP_NO_SUCH_OBJECT;
5057 if ( last && !access_allowed( op, last->ce_entry,
5058 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
5060 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5061 "DN=\"%s\" no write access to \"children\" of parent\n",
5062 log_prefix, e->e_name.bv_val, 0 );
5063 return LDAP_INSUFFICIENT_ACCESS;
5067 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5069 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5070 "DN=\"%s\" no objectClass\n",
5071 log_prefix, e->e_name.bv_val, 0 );
5072 return LDAP_OBJECT_CLASS_VIOLATION;
5075 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
5077 ObjectClass *soc = NULL;
5078 char textbuf[ SLAP_TEXT_BUFLEN ];
5079 const char *text = textbuf;
5081 /* FIXME: check result */
5082 rc = structural_class( oc_at->a_nvals, &soc, NULL,
5083 &text, textbuf, sizeof(textbuf), NULL );
5084 if ( rc != LDAP_SUCCESS ) {
5085 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5086 "DN=\"%s\" no structural objectClass (%s)\n",
5087 log_prefix, e->e_name.bv_val, text );
5090 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
5091 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
5092 if ( soc_at == NULL ) {
5093 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5094 "DN=\"%s\" no structural objectClass; "
5095 "unable to merge computed class %s\n",
5096 log_prefix, e->e_name.bv_val,
5097 soc->soc_cname.bv_val );
5098 return LDAP_OBJECT_CLASS_VIOLATION;
5101 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5102 "DN=\"%s\" no structural objectClass; "
5103 "computed objectClass %s merged\n",
5104 log_prefix, e->e_name.bv_val,
5105 soc->soc_cname.bv_val );
5108 /* Fake the coordinates based on whether we're part of an
5109 * LDAP Add or if reading the config dir
5112 ca->fname = "slapd";
5115 ca->fname = cfdir.bv_val;
5120 co.co_name = &soc_at->a_nvals[0];
5121 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
5122 if ( coptr == NULL ) {
5123 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5124 "DN=\"%s\" no structural objectClass in configuration table\n",
5125 log_prefix, e->e_name.bv_val, 0 );
5126 return LDAP_OBJECT_CLASS_VIOLATION;
5129 /* Only the root can be Cft_Global, everything else must
5130 * have a parent. Only limited nesting arrangements are allowed.
5132 rc = LDAP_CONSTRAINT_VIOLATION;
5133 if ( coptr->co_type == Cft_Global && !last ) {
5134 cfn = cfb->cb_config;
5135 ca->ca_private = cfn;
5136 ca->be = frontendDB; /* just to get past check_vals */
5140 colst = count_ocs( oc_at, &nocs );
5142 /* Check whether the Add is allowed by its parent, and do
5143 * any necessary arg setup
5146 rc = config_add_oc( &coptr, last, e, ca );
5147 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
5148 for ( i = 0; i<nocs; i++ ) {
5149 /* Already checked these */
5150 if ( colst[i]->co_oc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
5152 if ( colst[i]->co_ldadd &&
5153 ( rc = colst[i]->co_ldadd( last, e, ca ))
5154 != LDAP_CONSTRAINT_VIOLATION ) {
5160 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
5161 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5162 "DN=\"%s\" no structural objectClass add function\n",
5163 log_prefix, e->e_name.bv_val, 0 );
5164 return LDAP_OBJECT_CLASS_VIOLATION;
5168 /* Add the entry but don't parse it, we already have its contents */
5169 if ( rc == LDAP_COMPARE_TRUE ) {
5174 if ( rc != LDAP_SUCCESS )
5177 /* Parse all the values and check for simple syntax errors before
5178 * performing any set actions.
5180 * If doing an LDAPadd, check for indexed names and any necessary
5181 * renaming/renumbering. Entries that don't need indexed names are
5182 * ignored. Entries that need an indexed name and arrive without one
5183 * are assigned to the end. Entries that arrive with an index may
5184 * cause the following entries to be renumbered/bumped down.
5186 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
5187 * don't allow Adding an entry with an index that's already in use.
5188 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
5190 * These entries can have auto-assigned indexes (appended to the end)
5191 * but only the other types support auto-renumbering of siblings.
5194 rc = check_name_index( last, coptr->co_type, e, rs, renum,
5199 if ( renum && *renum && coptr->co_type != Cft_Database &&
5200 coptr->co_type != Cft_Overlay )
5202 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
5203 "operation requires sibling renumbering" );
5204 rc = LDAP_UNWILLING_TO_PERFORM;
5209 init_config_argv( ca );
5211 /* Make sure we process attrs in the required order */
5212 sort_attrs( e, colst, nocs );
5214 for ( a = e->e_attrs; a; a = a->a_next ) {
5215 if ( a == oc_at ) continue;
5216 ct = config_find_table( colst, nocs, a->a_desc, ca );
5217 if ( !ct ) continue; /* user data? */
5218 rc = check_vals( ct, ca, a, 1 );
5219 if ( rc ) goto done_noop;
5222 /* Basic syntax checks are OK. Do the actual settings. */
5223 for ( a=e->e_attrs; a; a=a->a_next ) {
5224 if ( a == oc_at ) continue;
5225 ct = config_find_table( colst, nocs, a->a_desc, ca );
5226 if ( !ct ) continue; /* user data? */
5227 for (i=0; a->a_vals[i].bv_val; i++) {
5230 ca->line = a->a_vals[i].bv_val;
5231 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
5232 ptr = strchr( ca->line, '}' );
5234 iptr = strchr( ca->line, '{' );
5238 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
5240 ca->valx = strtol( iptr+1, NULL, 0 );
5245 rc = config_parse_add( ct, ca, i );
5253 /* Newly added databases and overlays need to be started up */
5254 if ( CONFIG_ONLINE_ADD( ca )) {
5255 if ( coptr->co_type == Cft_Database ) {
5256 rc = backend_startup_one( ca->be, &ca->reply );
5258 } else if ( coptr->co_type == Cft_Overlay ) {
5259 if ( ca->bi->bi_db_open ) {
5260 BackendInfo *bi_orig = ca->be->bd_info;
5261 ca->be->bd_info = ca->bi;
5262 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
5263 ca->be->bd_info = bi_orig;
5265 } else if ( ca->cleanup ) {
5266 rc = ca->cleanup( ca );
5269 if (ca->cr_msg[0] == '\0')
5270 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
5272 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
5273 ca->log, ca->cr_msg, ca->argv[1] );
5280 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5281 ce->ce_parent = last;
5282 ce->ce_entry = entry_dup( e );
5283 ce->ce_entry->e_private = ce;
5284 ce->ce_type = coptr->co_type;
5287 ce->ce_private = ca->ca_private;
5288 ca->ca_entry = ce->ce_entry;
5291 } else if ( last->ce_kids ) {
5292 CfEntryInfo *c2, **cprev;
5294 /* Advance to first of this type */
5295 cprev = &last->ce_kids;
5296 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
5297 cprev = &c2->ce_sibs;
5300 /* Account for the (-1) frontendDB entry */
5301 if ( ce->ce_type == Cft_Database ) {
5302 if ( ca->be == frontendDB )
5304 else if ( ibase != -1 )
5309 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
5310 cprev = &c2->ce_sibs;
5316 for ( i=0; i<ibase; i++ ) {
5318 cprev = &c2->ce_sibs;
5321 ce->ce_sibs = *cprev;
5329 if ( (coptr->co_type == Cft_Database) && ca->be ) {
5330 if ( ca->be != frontendDB )
5331 backend_destroy_one( ca->be, 1 );
5332 } else if ( (coptr->co_type == Cft_Overlay) && ca->bi ) {
5333 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
5334 } else if ( coptr->co_type == Cft_Schema ) {
5335 schema_destroy_one( ca, colst, nocs, last );
5340 ch_free( ca->argv );
5341 if ( colst ) ch_free( colst );
5345 #define BIGTMP 10000
5347 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5348 int base, int rebase, int max, int use_ldif )
5350 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
5351 ConfigType etype = ce->ce_type;
5352 int count = 0, rc = 0;
5354 /* Reverse ce list */
5355 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
5356 if (ce2->ce_type != etype) {
5361 ce2->ce_sibs = cetmp;
5364 if ( max && count >= max ) {
5370 /* Move original to a temp name until increments are done */
5372 ce->ce_entry->e_private = NULL;
5373 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5374 base+BIGTMP, 0, use_ldif );
5375 ce->ce_entry->e_private = ce;
5377 /* start incrementing */
5378 for (ce2=cetmp; ce2; ce2=ce3) {
5380 ce2->ce_sibs = cerem;
5383 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5384 count+base, 0, use_ldif );
5388 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5389 base, 0, use_ldif );
5394 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5395 CfEntryInfo *ce2, int old, int use_ldif )
5399 /* Renumber original to a temp value */
5400 ce->ce_entry->e_private = NULL;
5401 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5402 old+BIGTMP, 0, use_ldif );
5403 ce->ce_entry->e_private = ce;
5405 /* start decrementing */
5406 for (; ce2 != ce; ce2=ce2->ce_sibs) {
5407 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5408 count+old, 0, use_ldif );
5411 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5412 count+old, 0, use_ldif );
5415 /* Parse an LDAP entry into config directives, then store in underlying
5419 config_back_add( Operation *op, SlapReply *rs )
5425 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
5426 NULL, ACL_WADD, NULL )) {
5427 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5432 * Check for attribute ACL
5434 if ( !acl_check_modlist( op, op->ora_e, op->orm_modlist )) {
5435 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5436 rs->sr_text = "no write access to attribute";
5440 cfb = (CfBackInfo *)op->o_bd->be_private;
5442 /* add opattrs for syncprov */
5444 char textbuf[SLAP_TEXT_BUFLEN];
5445 size_t textlen = sizeof textbuf;
5446 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1, NULL,
5447 &rs->sr_text, textbuf, sizeof( textbuf ) );
5448 if ( rs->sr_err != LDAP_SUCCESS )
5450 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
5451 if ( rs->sr_err != LDAP_SUCCESS ) {
5452 Debug( LDAP_DEBUG_TRACE,
5453 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
5454 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
5459 if ( op->o_abandon ) {
5460 rs->sr_err = SLAPD_ABANDON;
5463 ldap_pvt_thread_pool_pause( &connection_pool );
5466 * 1) check for existence of entry
5467 * 2) check for sibling renumbering
5468 * 3) perform internal add
5469 * 4) perform any necessary renumbering
5470 * 5) store entry in underlying database
5472 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
5473 if ( rs->sr_err != LDAP_SUCCESS ) {
5474 rs->sr_text = ca.cr_msg;
5479 CfEntryInfo *ce = ca.ca_entry->e_private;
5480 req_add_s addr = op->oq_add;
5481 op->o_tag = LDAP_REQ_MODRDN;
5482 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
5483 op->o_tag = LDAP_REQ_ADD;
5485 if ( rs->sr_err != LDAP_SUCCESS ) {
5490 if ( cfb->cb_use_ldif ) {
5491 BackendDB *be = op->o_bd;
5492 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5493 struct berval dn, ndn;
5495 op->o_bd = &cfb->cb_db;
5497 /* Save current rootdn; use the underlying DB's rootdn */
5500 op->o_dn = op->o_bd->be_rootdn;
5501 op->o_ndn = op->o_bd->be_rootndn;
5503 scp = op->o_callback;
5504 op->o_callback = ≻
5505 op->o_bd->be_add( op, rs );
5507 op->o_callback = scp;
5513 ldap_pvt_thread_pool_resume( &connection_pool );
5516 { int repl = op->o_dont_replicate;
5517 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
5518 rs->sr_text = NULL; /* Set after config_add_internal */
5519 rs->sr_err = LDAP_SUCCESS;
5520 op->o_dont_replicate = 1;
5522 send_ldap_result( op, rs );
5523 op->o_dont_replicate = repl;
5525 slap_graduate_commit_csn( op );
5529 typedef struct delrec {
5530 struct delrec *next;
5536 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
5542 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
5543 ca->line[0] == '{' )
5545 char *ptr = strchr( ca->line + 1, '}' );
5549 ca->valx = strtol( ca->line + 1, &next, 0 );
5550 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
5556 rc = config_parse_add( ct, ca, i );
5564 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
5567 int rc = LDAP_UNWILLING_TO_PERFORM;
5569 Entry *e = ce->ce_entry;
5570 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
5575 delrec *dels = NULL, *deltail = NULL;
5577 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5578 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
5580 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5581 if (ml->sml_desc == slap_schema.si_ad_objectClass)
5585 colst = count_ocs( oc_at, &nocs );
5587 /* make sure add/del flags are clear; should always be true */
5588 for ( s = save_attrs; s; s = s->a_next ) {
5589 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
5592 e->e_attrs = attrs_dup( e->e_attrs );
5594 init_config_argv( ca );
5597 ca->ca_private = ce->ce_private;
5599 ca->fname = "slapd";
5601 strcpy( ca->log, "back-config" );
5603 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5604 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5605 switch (ml->sml_op) {
5606 case LDAP_MOD_DELETE:
5607 case LDAP_MOD_REPLACE:
5608 case SLAP_MOD_SOFTDEL:
5610 BerVarray vals = NULL, nvals = NULL;
5612 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
5614 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
5615 ml->sml_desc->ad_cname.bv_val );
5618 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5619 vals = ml->sml_values;
5620 nvals = ml->sml_nvalues;
5621 ml->sml_values = NULL;
5622 ml->sml_nvalues = NULL;
5624 /* If we're deleting by values, remember the indexes of the
5625 * values we deleted.
5627 if ( ct && ml->sml_values ) {
5629 i = ml->sml_numvals;
5630 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
5641 rc = modify_delete_vindex(e, &ml->sml_mod,
5642 get_permissiveModify(op),
5643 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
5644 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5645 ml->sml_values = vals;
5646 ml->sml_nvalues = nvals;
5648 if ( rc == LDAP_NO_SUCH_ATTRIBUTE && ml->sml_op == SLAP_MOD_SOFTDEL )
5652 /* FIXME: check rc before fallthru? */
5656 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5658 case SLAP_MOD_ADD_IF_NOT_PRESENT:
5659 if ( ml->sml_op == SLAP_MOD_ADD_IF_NOT_PRESENT
5660 && attr_find( e->e_attrs, ml->sml_desc ) )
5667 case SLAP_MOD_SOFTADD: {
5668 int mop = ml->sml_op;
5670 ml->sml_op = LDAP_MOD_ADD;
5672 if ( ct->arg_type & ARG_NO_INSERT ) {
5673 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
5675 navals = a->a_numvals;
5678 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
5679 if ( ml->sml_values[i].bv_val[0] == '{' &&
5682 char *next, *val = ml->sml_values[i].bv_val + 1;
5685 j = strtol( val, &next, 0 );
5686 if ( next == val || next[ 0 ] != '}' || j < navals ) {
5688 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
5689 ml->sml_desc->ad_cname.bv_val );
5693 rc = check_vals( ct, ca, ml, 0 );
5694 if ( rc ) goto out_noop;
5697 rc = modify_add_values(e, &ml->sml_mod,
5698 get_permissiveModify(op),
5699 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5701 /* If value already exists, show success here
5702 * and ignore this operation down below.
5704 if ( mop == SLAP_MOD_SOFTADD ) {
5705 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
5715 case LDAP_MOD_INCREMENT: /* FIXME */
5720 if(rc != LDAP_SUCCESS) break;
5723 if ( rc == LDAP_SUCCESS) {
5724 /* check that the entry still obeys the schema */
5725 rc = entry_schema_check(op, e, NULL, 0, 0, NULL,
5726 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5728 if ( rc ) goto out_noop;
5730 /* Basic syntax checks are OK. Do the actual settings. */
5731 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5732 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5733 if ( !ct ) continue;
5735 s = attr_find( save_attrs, ml->sml_desc );
5736 a = attr_find( e->e_attrs, ml->sml_desc );
5738 switch (ml->sml_op) {
5739 case LDAP_MOD_DELETE:
5740 case LDAP_MOD_REPLACE: {
5741 BerVarray vals = NULL, nvals = NULL;
5744 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5745 vals = ml->sml_values;
5746 nvals = ml->sml_nvalues;
5747 ml->sml_values = NULL;
5748 ml->sml_nvalues = NULL;
5751 if ( ml->sml_values )
5754 /* If we didn't delete the whole attribute */
5755 if ( ml->sml_values && a ) {
5756 struct berval *mvals;
5759 if ( ml->sml_nvalues )
5760 mvals = ml->sml_nvalues;
5762 mvals = ml->sml_values;
5764 /* use the indexes we saved up above */
5765 for (i=0; i < d->nidx; i++) {
5766 struct berval bv = *mvals++;
5767 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
5768 bv.bv_val[0] == '{' ) {
5769 ptr = strchr( bv.bv_val, '}' ) + 1;
5770 bv.bv_len -= ptr - bv.bv_val;
5773 ca->line = bv.bv_val;
5774 ca->valx = d->idx[i];
5775 config_parse_vals(ct, ca, d->idx[i] );
5776 rc = config_del_vals( ct, ca );
5777 if ( rc != LDAP_SUCCESS ) break;
5779 s->a_flags |= SLAP_ATTR_IXDEL;
5780 for (j=i+1; j < d->nidx; j++)
5781 if ( d->idx[j] >d->idx[i] )
5788 rc = config_del_vals( ct, ca );
5789 if ( rc ) rc = LDAP_OTHER;
5791 s->a_flags |= SLAP_ATTR_IXDEL;
5793 if ( ml->sml_values ) {
5798 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5799 ml->sml_values = vals;
5800 ml->sml_nvalues = nvals;
5802 if ( !vals || rc != LDAP_SUCCESS )
5805 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5808 for (i=0; ml->sml_values[i].bv_val; i++) {
5809 ca->line = ml->sml_values[i].bv_val;
5811 rc = config_modify_add( ct, ca, ml->sml_desc, i );
5814 a->a_flags |= SLAP_ATTR_IXADD;
5821 /* Undo for a failed operation */
5822 if ( rc != LDAP_SUCCESS ) {
5823 ConfigReply msg = ca->reply;
5824 for ( s = save_attrs; s; s = s->a_next ) {
5825 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
5826 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5827 ct = config_find_table( colst, nocs, s->a_desc, ca );
5828 a = attr_find( e->e_attrs, s->a_desc );
5830 /* clear the flag so the add check below will skip it */
5831 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5835 config_del_vals( ct, ca );
5837 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5838 ca->line = s->a_vals[i].bv_val;
5840 config_modify_add( ct, ca, s->a_desc, i );
5844 for ( a = e->e_attrs; a; a = a->a_next ) {
5845 if ( a->a_flags & SLAP_ATTR_IXADD ) {
5846 ct = config_find_table( colst, nocs, a->a_desc, ca );
5850 config_del_vals( ct, ca );
5851 s = attr_find( save_attrs, a->a_desc );
5853 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5854 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5855 ca->line = s->a_vals[i].bv_val;
5857 config_modify_add( ct, ca, s->a_desc, i );
5868 if ( rc == LDAP_SUCCESS ) {
5869 attrs_free( save_attrs );
5872 attrs_free( e->e_attrs );
5873 e->e_attrs = save_attrs;
5875 ch_free( ca->argv );
5876 if ( colst ) ch_free( colst );
5878 deltail = dels->next;
5887 config_back_modify( Operation *op, SlapReply *rs )
5890 CfEntryInfo *ce, *last;
5892 ConfigArgs ca = {0};
5895 AttributeDescription *rad = NULL;
5898 cfb = (CfBackInfo *)op->o_bd->be_private;
5900 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5903 rs->sr_matched = last->ce_entry->e_name.bv_val;
5904 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5908 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
5909 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5913 /* Get type of RDN */
5914 rdn = ce->ce_entry->e_nname;
5915 ptr = strchr( rdn.bv_val, '=' );
5916 rdn.bv_len = ptr - rdn.bv_val;
5917 rs->sr_err = slap_bv2ad( &rdn, &rad, &rs->sr_text );
5918 if ( rs->sr_err != LDAP_SUCCESS ) {
5922 /* Some basic validation... */
5923 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5924 /* Don't allow Modify of RDN; must use ModRdn for that. */
5925 if ( ml->sml_desc == rad ) {
5926 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
5927 rs->sr_text = "Use modrdn to change the entry name";
5930 /* Internal update of contextCSN? */
5931 if ( ml->sml_desc == slap_schema.si_ad_contextCSN && op->o_conn->c_conn_idx == -1 ) {
5937 slap_mods_opattrs( op, &op->orm_modlist, 1 );
5940 if ( op->o_abandon ) {
5941 rs->sr_err = SLAPD_ABANDON;
5944 ldap_pvt_thread_pool_pause( &connection_pool );
5948 * 1) perform the Modify on the cached Entry.
5949 * 2) verify that the Entry still satisfies the schema.
5950 * 3) perform the individual config operations.
5951 * 4) store Modified entry in underlying LDIF backend.
5953 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
5955 rs->sr_text = ca.cr_msg;
5956 } else if ( cfb->cb_use_ldif ) {
5957 BackendDB *be = op->o_bd;
5958 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5959 struct berval dn, ndn;
5961 op->o_bd = &cfb->cb_db;
5965 op->o_dn = op->o_bd->be_rootdn;
5966 op->o_ndn = op->o_bd->be_rootndn;
5968 scp = op->o_callback;
5969 op->o_callback = ≻
5970 op->o_bd->be_modify( op, rs );
5972 op->o_callback = scp;
5978 ldap_pvt_thread_pool_resume( &connection_pool );
5980 send_ldap_result( op, rs );
5981 slap_graduate_commit_csn( op );
5986 config_back_modrdn( Operation *op, SlapReply *rs )
5989 CfEntryInfo *ce, *last;
5993 cfb = (CfBackInfo *)op->o_bd->be_private;
5995 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5998 rs->sr_matched = last->ce_entry->e_name.bv_val;
5999 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6002 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
6003 NULL, ACL_WRITE, NULL )) {
6004 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6008 if ( ce->ce_parent )
6009 parent = ce->ce_parent->ce_entry;
6011 parent = (Entry *)&slap_entry_root;
6012 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
6013 NULL, ACL_WRITE, NULL )) {
6014 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6019 /* We don't allow moving objects to new parents.
6020 * Generally we only allow reordering a set of ordered entries.
6022 if ( op->orr_newSup ) {
6023 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6027 /* If newRDN == oldRDN, quietly succeed */
6028 dnRdn( &op->o_req_ndn, &rdn );
6029 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
6030 rs->sr_err = LDAP_SUCCESS;
6034 /* Current behavior, subject to change as needed:
6036 * For backends and overlays, we only allow renumbering.
6037 * For schema, we allow renaming with the same number.
6038 * Otherwise, the op is not allowed.
6041 if ( ce->ce_type == Cft_Schema ) {
6045 /* Can't alter the main cn=schema entry */
6046 if ( ce->ce_parent->ce_type == Cft_Global ) {
6047 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6048 rs->sr_text = "renaming not allowed for this entry";
6052 /* We could support this later if desired */
6053 ptr1 = ber_bvchr( &rdn, '}' );
6054 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
6055 len = ptr1 - rdn.bv_val;
6056 if ( len != ptr2 - op->orr_newrdn.bv_val ||
6057 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
6058 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6059 rs->sr_text = "schema reordering not supported";
6062 } else if ( ce->ce_type == Cft_Database ||
6063 ce->ce_type == Cft_Overlay ) {
6064 char *ptr1, *ptr2, *iptr1, *iptr2;
6067 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
6068 if ( *iptr2 != '{' ) {
6069 rs->sr_err = LDAP_NAMING_VIOLATION;
6070 rs->sr_text = "new ordering index is required";
6074 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
6075 ptr1 = ber_bvchr( &rdn, '}' );
6076 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
6078 rs->sr_err = LDAP_NAMING_VIOLATION;
6079 rs->sr_text = "new ordering index is required";
6083 len1 = ptr1 - rdn.bv_val;
6084 len2 = ptr2 - op->orr_newrdn.bv_val;
6086 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
6087 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
6088 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6089 rs->sr_text = "changing database/overlay type not allowed";
6092 ixold = strtol( iptr1, NULL, 0 );
6093 ixnew = strtol( iptr2, &ptr1, 0 );
6094 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
6095 rs->sr_err = LDAP_NAMING_VIOLATION;
6098 /* config DB is always 0, cannot be changed */
6099 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
6100 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
6104 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6105 rs->sr_text = "renaming not supported for this entry";
6109 if ( op->o_abandon ) {
6110 rs->sr_err = SLAPD_ABANDON;
6113 ldap_pvt_thread_pool_pause( &connection_pool );
6115 if ( ce->ce_type == Cft_Schema ) {
6116 req_modrdn_s modr = op->oq_modrdn;
6119 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
6120 if ( rs->sr_err == LDAP_SUCCESS ) {
6121 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
6122 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
6125 op->oq_modrdn = modr;
6127 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
6128 req_modrdn_s modr = op->oq_modrdn;
6131 /* Advance to first of this type */
6132 cprev = &ce->ce_parent->ce_kids;
6133 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
6134 cprev = &ce2->ce_sibs;
6137 /* Skip the -1 entry */
6138 if ( ce->ce_type == Cft_Database ) {
6139 cprev = &ce2->ce_sibs;
6145 /* Remove from old slot */
6146 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
6147 cprev = &ce2->ce_sibs;
6148 *cprev = ce->ce_sibs;
6149 ceold = ce->ce_sibs;
6151 /* Insert into new slot */
6153 for ( i=0; i<ixnew; i++ ) {
6157 cprev = &ce2->ce_sibs;
6159 ce->ce_sibs = *cprev;
6164 /* NOTE: These should be encoded in the OC tables, not inline here */
6165 if ( ce->ce_type == Cft_Database )
6166 backend_db_move( ce->ce_be, ixnew );
6167 else if ( ce->ce_type == Cft_Overlay )
6168 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
6170 if ( ixold < ixnew ) {
6171 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
6174 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
6175 ixold - ixnew, cfb->cb_use_ldif );
6177 op->oq_modrdn = modr;
6180 ldap_pvt_thread_pool_resume( &connection_pool );
6182 send_ldap_result( op, rs );
6187 config_back_delete( Operation *op, SlapReply *rs )
6189 #ifdef SLAP_CONFIG_DELETE
6191 CfEntryInfo *ce, *last, *ce2;
6193 cfb = (CfBackInfo *)op->o_bd->be_private;
6195 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6198 rs->sr_matched = last->ce_entry->e_name.bv_val;
6199 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6200 } else if ( ce->ce_kids ) {
6201 rs->sr_err = LDAP_NOT_ALLOWED_ON_NONLEAF;
6202 } else if ( op->o_abandon ) {
6203 rs->sr_err = SLAPD_ABANDON;
6204 } else if ( ce->ce_type == Cft_Overlay ||
6205 ce->ce_type == Cft_Database ||
6206 ce->ce_type == Cft_Misc ){
6210 ldap_pvt_thread_pool_pause( &connection_pool );
6212 if ( ce->ce_type == Cft_Overlay ){
6213 overlay_remove( ce->ce_be, (slap_overinst *)ce->ce_bi, op );
6214 } else if ( ce->ce_type == Cft_Misc ) {
6216 * only Cft_Misc objects that have a co_lddel handler set in
6217 * the ConfigOCs struct can be deleted. This code also
6218 * assumes that the entry can be only have one objectclass
6219 * with co_type == Cft_Misc
6221 ConfigOCs co, *coptr;
6225 oc_at = attr_find( ce->ce_entry->e_attrs,
6226 slap_schema.si_ad_objectClass );
6228 rs->sr_err = LDAP_OTHER;
6229 rs->sr_text = "objectclass not found";
6230 ldap_pvt_thread_pool_resume( &connection_pool );
6233 for ( i=0; !BER_BVISNULL(&oc_at->a_nvals[i]); i++ ) {
6234 co.co_name = &oc_at->a_nvals[i];
6235 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
6236 if ( coptr == NULL || coptr->co_type != Cft_Misc ) {
6239 if ( ! coptr->co_lddel || coptr->co_lddel( ce, op ) ){
6240 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6241 if ( ! coptr->co_lddel ) {
6242 rs->sr_text = "No delete handler found";
6244 rs->sr_err = LDAP_OTHER;
6245 /* FIXME: We should return a helpful error message
6248 ldap_pvt_thread_pool_resume( &connection_pool );
6253 } else if (ce->ce_type == Cft_Database ) {
6254 if ( ce->ce_be == frontendDB || ce->ce_be == op->o_bd ){
6255 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6256 rs->sr_text = "Cannot delete config or frontend database";
6257 ldap_pvt_thread_pool_resume( &connection_pool );
6260 if ( ce->ce_be->bd_info->bi_db_close ) {
6261 ce->ce_be->bd_info->bi_db_close( ce->ce_be, NULL );
6263 backend_destroy_one( ce->ce_be, 1);
6266 /* remove CfEntryInfo from the siblings list */
6267 if ( ce->ce_parent->ce_kids == ce ) {
6268 ce->ce_parent->ce_kids = ce->ce_sibs;
6270 for ( ce2 = ce->ce_parent->ce_kids ; ce2; ce2 = ce2->ce_sibs ) {
6271 if ( ce2->ce_sibs == ce ) {
6272 ce2->ce_sibs = ce->ce_sibs;
6278 /* remove from underlying database */
6279 if ( cfb->cb_use_ldif ) {
6280 BackendDB *be = op->o_bd;
6281 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
6282 struct berval dn, ndn, req_dn, req_ndn;
6284 op->o_bd = &cfb->cb_db;
6288 req_dn = op->o_req_dn;
6289 req_ndn = op->o_req_ndn;
6291 op->o_dn = op->o_bd->be_rootdn;
6292 op->o_ndn = op->o_bd->be_rootndn;
6293 op->o_req_dn = ce->ce_entry->e_name;
6294 op->o_req_ndn = ce->ce_entry->e_nname;
6296 scp = op->o_callback;
6297 op->o_callback = ≻
6298 op->o_bd->be_delete( op, rs );
6300 op->o_callback = scp;
6303 op->o_req_dn = req_dn;
6304 op->o_req_ndn = req_ndn;
6307 /* renumber siblings */
6308 iptr = ber_bvchr( &op->o_req_ndn, '{' ) + 1;
6309 ixold = strtol( iptr, NULL, 0 );
6310 for (ce2 = ce->ce_sibs, count=0; ce2; ce2=ce2->ce_sibs) {
6311 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
6312 count+ixold, 0, cfb->cb_use_ldif );
6316 ce->ce_entry->e_private=NULL;
6317 entry_free(ce->ce_entry);
6319 ldap_pvt_thread_pool_resume( &connection_pool );
6321 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6325 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6326 #endif /* SLAP_CONFIG_DELETE */
6327 send_ldap_result( op, rs );
6332 config_back_search( Operation *op, SlapReply *rs )
6335 CfEntryInfo *ce, *last;
6338 cfb = (CfBackInfo *)op->o_bd->be_private;
6340 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6343 rs->sr_matched = last->ce_entry->e_name.bv_val;
6344 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6347 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
6348 ACL_SEARCH, NULL, &mask ))
6350 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
6351 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6353 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6357 switch ( op->ors_scope ) {
6358 case LDAP_SCOPE_BASE:
6359 case LDAP_SCOPE_SUBTREE:
6360 rs->sr_err = config_send( op, rs, ce, 0 );
6363 case LDAP_SCOPE_ONELEVEL:
6364 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
6365 rs->sr_err = config_send( op, rs, ce, 1 );
6374 send_ldap_result( op, rs );
6378 /* no-op, we never free entries */
6379 int config_entry_release(
6384 if ( !e->e_private ) {
6387 return LDAP_SUCCESS;
6390 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
6392 int config_back_entry_get(
6396 AttributeDescription *at,
6401 CfEntryInfo *ce, *last;
6402 int rc = LDAP_NO_SUCH_OBJECT;
6404 cfb = (CfBackInfo *)op->o_bd->be_private;
6406 ce = config_find_base( cfb->cb_root, ndn, &last );
6408 *ent = ce->ce_entry;
6411 if ( oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
6412 rc = LDAP_NO_SUCH_ATTRIBUTE;
6422 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
6423 ConfigTable *ct, ConfigArgs *c )
6427 for (; at && *at; at++) {
6428 /* Skip the naming attr */
6429 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
6431 for (i=0;ct[i].name;i++) {
6432 if (ct[i].ad == (*at)->sat_ad) {
6433 rc = config_get_vals(&ct[i], c);
6434 /* NOTE: tolerate that config_get_vals()
6435 * returns success with no values */
6436 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
6437 if ( c->rvalue_nvals )
6438 rc = attr_merge(e, ct[i].ad, c->rvalue_vals,
6441 slap_syntax_validate_func *validate =
6442 ct[i].ad->ad_type->sat_syntax->ssyn_validate;
6445 for ( j=0; c->rvalue_vals[j].bv_val; j++ ) {
6446 rc = ordered_value_validate( ct[i].ad,
6447 &c->rvalue_vals[j], LDAP_MOD_ADD );
6449 Debug( LDAP_DEBUG_ANY,
6450 "config_build_attrs: error %d on %s value #%d\n",
6451 rc, ct[i].ad->ad_cname.bv_val, j );
6457 rc = attr_merge_normalize(e, ct[i].ad,
6458 c->rvalue_vals, NULL);
6460 ber_bvarray_free( c->rvalue_nvals );
6461 ber_bvarray_free( c->rvalue_vals );
6463 Debug( LDAP_DEBUG_ANY,
6464 "config_build_attrs: error %d on %s\n",
6465 rc, ct[i].ad->ad_cname.bv_val, 0 );
6476 /* currently (2010) does not access rs except possibly writing rs->sr_err */
6479 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
6480 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
6482 Entry *e = entry_alloc();
6483 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
6485 struct berval ad_name;
6486 AttributeDescription *ad = NULL;
6489 const char *text = "";
6493 CfEntryInfo *ceprev = NULL;
6495 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
6498 ce->ce_type = main->co_type;
6499 ce->ce_parent = parent;
6501 pdn = parent->ce_entry->e_nname;
6502 if ( parent->ce_kids && parent->ce_kids->ce_type <= ce->ce_type )
6503 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
6504 ceprev->ce_type <= ce->ce_type;
6505 ceprev = ceprev->ce_sibs );
6510 ce->ce_private = c->ca_private;
6514 build_new_dn( &e->e_name, &pdn, rdn, NULL );
6515 ber_dupbv( &e->e_nname, &e->e_name );
6517 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6518 main->co_name, NULL );
6520 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6521 extra->co_name, NULL );
6522 ptr = strchr(rdn->bv_val, '=');
6523 ad_name.bv_val = rdn->bv_val;
6524 ad_name.bv_len = ptr - rdn->bv_val;
6525 rc = slap_bv2ad( &ad_name, &ad, &text );
6530 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
6531 attr_merge_normalize_one(e, ad, &val, NULL );
6534 c->table = main->co_type;
6535 if ( oc->soc_required ) {
6536 rc = config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
6537 if ( rc ) goto fail;
6540 if ( oc->soc_allowed ) {
6541 rc = config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
6542 if ( rc ) goto fail;
6547 c->table = extra->co_type;
6548 if ( oc->soc_required ) {
6549 rc = config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
6550 if ( rc ) goto fail;
6553 if ( oc->soc_allowed ) {
6554 rc = config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
6555 if ( rc ) goto fail;
6559 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
6560 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
6561 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
6562 if ( rc != LDAP_SUCCESS ) {
6564 Debug( LDAP_DEBUG_ANY,
6565 "config_build_entry: build \"%s\" failed: \"%s\"\n",
6566 rdn->bv_val, text, 0);
6569 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
6572 op->ora_modlist = NULL;
6573 slap_add_opattrs( op, NULL, NULL, 0, 0 );
6574 if ( !op->o_noop ) {
6575 SlapReply rs2 = {REP_RESULT};
6576 op->o_bd->be_add( op, &rs2 );
6577 rs->sr_err = rs2.sr_err;
6578 rs_assert_done( &rs2 );
6579 if ( ( rs2.sr_err != LDAP_SUCCESS )
6580 && (rs2.sr_err != LDAP_ALREADY_EXISTS) ) {
6586 ce->ce_sibs = ceprev->ce_sibs;
6587 ceprev->ce_sibs = ce;
6588 } else if ( parent ) {
6589 ce->ce_sibs = parent->ce_kids;
6590 parent->ce_kids = ce;
6597 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
6598 Operation *op, SlapReply *rs )
6601 ConfigFile *cf = c->ca_private;
6603 struct berval bv, rdn;
6605 for (; cf; cf=cf->c_sibs, c->depth++) {
6606 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
6607 !cf->c_om_head && !cf->c_syn_head ) continue;
6608 c->value_dn.bv_val = c->log;
6609 LUTIL_SLASHPATH( cf->c_file.bv_val );
6610 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
6615 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
6617 ptr = strchr( bv.bv_val, '.' );
6619 bv.bv_len = ptr - bv.bv_val;
6620 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
6621 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6622 /* FIXME: how can indicate error? */
6625 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
6627 c->value_dn.bv_len += bv.bv_len;
6628 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
6629 rdnNormalize( 0, NULL, NULL, &c->value_dn, &rdn, NULL );
6632 e = config_build_entry( op, rs, ceparent, c, &rdn,
6633 &CFOC_SCHEMA, NULL );
6634 ch_free( rdn.bv_val );
6637 } else if ( e && cf->c_kids ) {
6638 c->ca_private = cf->c_kids;
6639 config_build_schema_inc( c, e->e_private, op, rs );
6645 #ifdef SLAPD_MODULES
6648 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
6649 Operation *op, SlapReply *rs )
6654 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
6655 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
6657 c->value_dn.bv_val = c->log;
6658 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
6659 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6660 /* FIXME: how can indicate error? */
6664 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
6673 config_check_schema(Operation *op, CfBackInfo *cfb)
6675 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
6677 CfEntryInfo *ce, *last;
6680 /* If there's no root entry, we must be in the midst of converting */
6681 if ( !cfb->cb_root )
6684 /* Make sure the main schema entry exists */
6685 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
6692 /* Make sure it's up to date */
6693 if ( cf_om_tail != om_sys_tail ) {
6694 a = attr_find( e->e_attrs, cfAd_om );
6696 if ( a->a_nvals != a->a_vals )
6697 ber_bvarray_free( a->a_nvals );
6698 ber_bvarray_free( a->a_vals );
6703 oidm_unparse( &bv, NULL, NULL, 1 );
6704 attr_merge_normalize( e, cfAd_om, bv, NULL );
6705 ber_bvarray_free( bv );
6706 cf_om_tail = om_sys_tail;
6708 if ( cf_at_tail != at_sys_tail ) {
6709 a = attr_find( e->e_attrs, cfAd_attr );
6711 if ( a->a_nvals != a->a_vals )
6712 ber_bvarray_free( a->a_nvals );
6713 ber_bvarray_free( a->a_vals );
6718 at_unparse( &bv, NULL, NULL, 1 );
6719 attr_merge_normalize( e, cfAd_attr, bv, NULL );
6720 ber_bvarray_free( bv );
6721 cf_at_tail = at_sys_tail;
6723 if ( cf_oc_tail != oc_sys_tail ) {
6724 a = attr_find( e->e_attrs, cfAd_oc );
6726 if ( a->a_nvals != a->a_vals )
6727 ber_bvarray_free( a->a_nvals );
6728 ber_bvarray_free( a->a_vals );
6733 oc_unparse( &bv, NULL, NULL, 1 );
6734 attr_merge_normalize( e, cfAd_oc, bv, NULL );
6735 ber_bvarray_free( bv );
6736 cf_oc_tail = oc_sys_tail;
6738 if ( cf_syn_tail != syn_sys_tail ) {
6739 a = attr_find( e->e_attrs, cfAd_syntax );
6741 if ( a->a_nvals != a->a_vals )
6742 ber_bvarray_free( a->a_nvals );
6743 ber_bvarray_free( a->a_vals );
6748 syn_unparse( &bv, NULL, NULL, 1 );
6749 attr_merge_normalize( e, cfAd_syntax, bv, NULL );
6750 ber_bvarray_free( bv );
6751 cf_syn_tail = syn_sys_tail;
6754 SlapReply rs = {REP_RESULT};
6755 c.ca_private = NULL;
6756 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
6757 &CFOC_SCHEMA, NULL );
6762 ce->ce_private = cfb->cb_config;
6763 cf_at_tail = at_sys_tail;
6764 cf_oc_tail = oc_sys_tail;
6765 cf_om_tail = om_sys_tail;
6766 cf_syn_tail = syn_sys_tail;
6771 static const char *defacl[] = {
6772 NULL, "to", "*", "by", "*", "none", NULL
6776 config_back_db_open( BackendDB *be, ConfigReply *cr )
6778 CfBackInfo *cfb = be->be_private;
6781 CfEntryInfo *ce, *ceparent;
6785 Connection conn = {0};
6786 OperationBuffer opbuf;
6788 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
6789 SlapReply rs = {REP_RESULT};
6790 void *thrctx = NULL;
6792 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
6794 /* If we have no explicitly configured ACLs, don't just use
6795 * the global ACLs. Explicitly deny access to everything.
6797 if ( !be->bd_self->be_acl ) {
6798 parse_acl(be->bd_self, "config_back_db_open", 0, 6, (char **)defacl, 0 );
6801 thrctx = ldap_pvt_thread_pool_context();
6802 connection_fake_init( &conn, &opbuf, thrctx );
6805 op->o_tag = LDAP_REQ_ADD;
6806 op->o_callback = &cb;
6807 op->o_bd = &cfb->cb_db;
6808 op->o_dn = op->o_bd->be_rootdn;
6809 op->o_ndn = op->o_bd->be_rootndn;
6811 if ( !cfb->cb_use_ldif ) {
6815 /* If we read the config from back-ldif, do some quick sanity checks */
6816 if ( cfb->cb_got_ldif ) {
6817 return config_check_schema( op, cfb );
6820 /* create root of tree */
6822 c.ca_private = cfb->cb_config;
6824 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
6834 #ifdef SLAPD_MODULES
6835 /* Create Module nodes... */
6836 if ( modpaths.mp_loads ) {
6837 if ( config_build_modules( &c, ceparent, op, &rs ) ){
6843 /* Create schema nodes... cn=schema will contain the hardcoded core
6844 * schema, read-only. Child objects will contain runtime loaded schema
6848 c.ca_private = NULL;
6849 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
6854 ce->ce_private = cfb->cb_config;
6855 cf_at_tail = at_sys_tail;
6856 cf_oc_tail = oc_sys_tail;
6857 cf_om_tail = om_sys_tail;
6858 cf_syn_tail = syn_sys_tail;
6860 /* Create schema nodes for included schema... */
6861 if ( cfb->cb_config->c_kids ) {
6864 c.ca_private = cfb->cb_config->c_kids;
6865 rc = config_build_schema_inc( &c, ce, op, &rs );
6871 /* Create backend nodes. Skip if they don't provide a cf_table.
6872 * There usually aren't any of these.
6876 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
6877 if (!bi->bi_cf_ocs) {
6878 /* If it only supports the old config mech, complain. */
6879 if ( bi->bi_config ) {
6880 Debug( LDAP_DEBUG_ANY,
6881 "WARNING: No dynamic config support for backend %s.\n",
6882 bi->bi_type, 0, 0 );
6887 if (!bi->bi_private) continue;
6890 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6891 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
6892 if ( rdn.bv_len >= sizeof( c.log ) ) {
6893 /* FIXME: holler ... */ ;
6896 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
6903 /* Create database nodes... */
6904 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
6905 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
6906 for ( i = -1, be = frontendDB ; be;
6907 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
6908 slap_overinfo *oi = NULL;
6910 if ( overlay_is_over( be )) {
6911 oi = be->bd_info->bi_private;
6917 /* If this backend supports the old config mechanism, but not
6918 * the new mech, complain.
6920 if ( !be->be_cf_ocs && bi->bi_db_config ) {
6921 Debug( LDAP_DEBUG_ANY,
6922 "WARNING: No dynamic config support for database %s.\n",
6923 bi->bi_type, 0, 0 );
6927 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6928 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
6930 if ( rdn.bv_len >= sizeof( c.log ) ) {
6931 /* FIXME: holler ... */ ;
6935 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
6941 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd ) {
6942 rs_reinit( &rs, REP_RESULT );
6943 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
6945 /* Iterate through overlays */
6950 voidList *vl, *v0 = NULL;
6952 /* overlays are in LIFO order, must reverse stack */
6953 for (on=oi->oi_list; on; on=on->on_next) {
6954 vl = ch_malloc( sizeof( voidList ));
6959 for (j=0; vl; j++,vl=v0) {
6963 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
6964 Debug( LDAP_DEBUG_ANY,
6965 "WARNING: No dynamic config support for overlay %s.\n",
6966 on->on_bi.bi_type, 0, 0 );
6970 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6971 "%s=" SLAP_X_ORDERED_FMT "%s",
6972 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
6973 if ( rdn.bv_len >= sizeof( c.log ) ) {
6974 /* FIXME: holler ... */ ;
6978 oe = config_build_entry( op, &rs, ce, &c, &rdn,
6979 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
6983 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd ) {
6984 rs_reinit( &rs, REP_RESULT );
6985 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
6991 ldap_pvt_thread_pool_context_reset( thrctx );
6993 if ( unsupp && cfb->cb_use_ldif ) {
6994 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
6995 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
7002 cfb_free_cffile( ConfigFile *cf )
7006 for (; cf; cf=next) {
7009 cfb_free_cffile( cf->c_kids );
7010 ch_free( cf->c_file.bv_val );
7011 ber_bvarray_free( cf->c_dseFiles );
7017 cfb_free_entries( CfEntryInfo *ce )
7021 for (; ce; ce=next) {
7024 cfb_free_entries( ce->ce_kids );
7025 ce->ce_entry->e_private = NULL;
7026 entry_free( ce->ce_entry );
7032 config_back_db_close( BackendDB *be, ConfigReply *cr )
7034 CfBackInfo *cfb = be->be_private;
7036 cfb_free_entries( cfb->cb_root );
7037 cfb->cb_root = NULL;
7039 if ( cfb->cb_db.bd_info ) {
7040 backend_shutdown( &cfb->cb_db );
7047 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
7049 CfBackInfo *cfb = be->be_private;
7051 cfb_free_cffile( cfb->cb_config );
7053 ch_free( cfdir.bv_val );
7055 avl_free( CfOcTree, NULL );
7057 if ( cfb->cb_db.bd_info ) {
7058 cfb->cb_db.be_suffix = NULL;
7059 cfb->cb_db.be_nsuffix = NULL;
7060 BER_BVZERO( &cfb->cb_db.be_rootdn );
7061 BER_BVZERO( &cfb->cb_db.be_rootndn );
7063 backend_destroy_one( &cfb->cb_db, 0 );
7072 config_back_db_init( BackendDB *be, ConfigReply* cr )
7078 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
7079 cfn = cfb->cb_config;
7080 be->be_private = cfb;
7082 ber_dupbv( &be->be_rootdn, &config_rdn );
7083 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
7084 ber_dupbv( &dn, &be->be_rootdn );
7085 ber_bvarray_add( &be->be_suffix, &dn );
7086 ber_dupbv( &dn, &be->be_rootdn );
7087 ber_bvarray_add( &be->be_nsuffix, &dn );
7089 /* Hide from namingContexts */
7090 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
7092 /* Check ACLs on content of Adds by default */
7093 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_ACL_ADD;
7099 config_back_destroy( BackendInfo *bi )
7101 ldif_must_b64_encode_release();
7106 config_tool_entry_open( BackendDB *be, int mode )
7108 CfBackInfo *cfb = be->be_private;
7109 BackendInfo *bi = cfb->cb_db.bd_info;
7111 if ( bi && bi->bi_tool_entry_open )
7112 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
7119 config_tool_entry_close( BackendDB *be )
7121 CfBackInfo *cfb = be->be_private;
7122 BackendInfo *bi = cfb->cb_db.bd_info;
7124 if ( bi && bi->bi_tool_entry_close )
7125 return bi->bi_tool_entry_close( &cfb->cb_db );
7131 config_tool_entry_first( BackendDB *be )
7133 CfBackInfo *cfb = be->be_private;
7134 BackendInfo *bi = cfb->cb_db.bd_info;
7136 if ( bi && bi->bi_tool_entry_first ) {
7137 return bi->bi_tool_entry_first( &cfb->cb_db );
7139 if ( bi && bi->bi_tool_entry_first_x ) {
7140 return bi->bi_tool_entry_first_x( &cfb->cb_db,
7141 NULL, LDAP_SCOPE_DEFAULT, NULL );
7147 config_tool_entry_first_x(
7149 struct berval *base,
7153 CfBackInfo *cfb = be->be_private;
7154 BackendInfo *bi = cfb->cb_db.bd_info;
7156 if ( bi && bi->bi_tool_entry_first_x ) {
7157 return bi->bi_tool_entry_first_x( &cfb->cb_db, base, scope, f );
7163 config_tool_entry_next( BackendDB *be )
7165 CfBackInfo *cfb = be->be_private;
7166 BackendInfo *bi = cfb->cb_db.bd_info;
7168 if ( bi && bi->bi_tool_entry_next )
7169 return bi->bi_tool_entry_next( &cfb->cb_db );
7175 config_tool_entry_get( BackendDB *be, ID id )
7177 CfBackInfo *cfb = be->be_private;
7178 BackendInfo *bi = cfb->cb_db.bd_info;
7180 if ( bi && bi->bi_tool_entry_get )
7181 return bi->bi_tool_entry_get( &cfb->cb_db, id );
7186 static int entry_put_got_frontend=0;
7187 static int entry_put_got_config=0;
7189 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
7191 CfBackInfo *cfb = be->be_private;
7192 BackendInfo *bi = cfb->cb_db.bd_info;
7194 struct berval rdn, vals[ 2 ];
7196 OperationBuffer opbuf;
7198 Connection conn = {0};
7199 Operation *op = NULL;
7202 int isFrontendChild = 0;
7204 /* Create entry for frontend database if it does not exist already */
7205 if ( !entry_put_got_frontend ) {
7206 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
7207 STRLENOF( "olcDatabase" ))) {
7208 if ( strncmp( e->e_nname.bv_val +
7209 STRLENOF( "olcDatabase" ), "={-1}frontend",
7210 STRLENOF( "={-1}frontend" )) &&
7211 strncmp( e->e_nname.bv_val +
7212 STRLENOF( "olcDatabase" ), "=frontend",
7213 STRLENOF( "=frontend" ))) {
7215 vals[1].bv_val = NULL;
7216 memset( &ca, 0, sizeof(ConfigArgs));
7218 ca.bi = frontendDB->bd_info;
7219 ca.be->be_cf_ocs = &CFOC_FRONTEND;
7220 rdn.bv_val = ca.log;
7221 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7222 "%s=" SLAP_X_ORDERED_FMT "%s",
7223 cfAd_database->ad_cname.bv_val, -1,
7225 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
7226 &CFOC_DATABASE, ca.be->be_cf_ocs );
7227 thrctx = ldap_pvt_thread_pool_context();
7228 connection_fake_init2( &conn, &opbuf, thrctx,0 );
7230 op->o_bd = &cfb->cb_db;
7231 op->o_tag = LDAP_REQ_ADD;
7233 op->o_dn = be->be_rootdn;
7234 op->o_ndn = be->be_rootndn;
7235 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
7236 if ( rc != LDAP_SUCCESS ) {
7237 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
7238 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
7242 if ( ce && bi && bi->bi_tool_entry_put &&
7243 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
7244 entry_put_got_frontend++;
7246 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
7247 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
7251 if ( !strncmp( e->e_nname.bv_val +
7252 STRLENOF( "olcDatabase" ), "=frontend",
7253 STRLENOF( "=frontend" ) ) )
7255 struct berval rdn, pdn, ndn;
7256 dnParent( &e->e_nname, &pdn );
7257 rdn.bv_val = ca.log;
7258 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7259 "%s=" SLAP_X_ORDERED_FMT "%s",
7260 cfAd_database->ad_cname.bv_val, -1,
7261 frontendDB->bd_info->bi_type );
7262 build_new_dn( &ndn, &pdn, &rdn, NULL );
7263 ber_memfree( e->e_name.bv_val );
7265 ber_bvreplace( &e->e_nname, &e->e_name );
7267 entry_put_got_frontend++;
7273 /* Child entries of the frontend database, e.g. slapo-chain's back-ldap
7274 * instances, may appear before the config database entry in the ldif, skip
7275 * auto-creation of olcDatabase={0}config in such a case */
7276 if ( !entry_put_got_config &&
7277 !strncmp( e->e_nname.bv_val, "olcDatabase", STRLENOF( "olcDatabase" ))) {
7279 dnParent( &e->e_nname, &pdn );
7280 while ( pdn.bv_len ) {
7281 if ( !strncmp( pdn.bv_val, "olcDatabase",
7282 STRLENOF( "olcDatabase" ))) {
7283 if ( !strncmp( pdn.bv_val +
7284 STRLENOF( "olcDatabase" ), "={-1}frontend",
7285 STRLENOF( "={-1}frontend" )) ||
7286 !strncmp( pdn.bv_val +
7287 STRLENOF( "olcDatabase" ), "=frontend",
7288 STRLENOF( "=frontend" ))) {
7290 isFrontendChild = 1;
7294 dnParent( &pdn, &pdn );
7298 /* Create entry for config database if it does not exist already */
7299 if ( !entry_put_got_config && !isFrontend && !isFrontendChild ) {
7300 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
7301 STRLENOF( "olcDatabase" ))) {
7302 if ( strncmp( e->e_nname.bv_val +
7303 STRLENOF( "olcDatabase" ), "={0}config",
7304 STRLENOF( "={0}config" )) &&
7305 strncmp( e->e_nname.bv_val +
7306 STRLENOF( "olcDatabase" ), "=config",
7307 STRLENOF( "=config" )) ) {
7309 vals[1].bv_val = NULL;
7310 memset( &ca, 0, sizeof(ConfigArgs));
7311 ca.be = LDAP_STAILQ_FIRST( &backendDB );
7312 ca.bi = ca.be->bd_info;
7313 rdn.bv_val = ca.log;
7314 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7315 "%s=" SLAP_X_ORDERED_FMT "%s",
7316 cfAd_database->ad_cname.bv_val, 0,
7318 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
7321 thrctx = ldap_pvt_thread_pool_context();
7322 connection_fake_init2( &conn, &opbuf, thrctx,0 );
7324 op->o_bd = &cfb->cb_db;
7325 op->o_tag = LDAP_REQ_ADD;
7326 op->o_dn = be->be_rootdn;
7327 op->o_ndn = be->be_rootndn;
7330 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
7331 if ( rc != LDAP_SUCCESS ) {
7332 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
7333 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7336 if (ce && bi && bi->bi_tool_entry_put &&
7337 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
7338 entry_put_got_config++;
7340 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
7341 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7345 entry_put_got_config++;
7349 if ( bi && bi->bi_tool_entry_put &&
7350 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
7351 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
7358 AttributeDescription **desc;
7360 { "attribute", &cfAd_attr },
7361 { "backend", &cfAd_backend },
7362 { "database", &cfAd_database },
7363 { "include", &cfAd_include },
7364 { "ldapsyntax", &cfAd_syntax },
7365 { "objectclass", &cfAd_oc },
7366 { "objectidentifier", &cfAd_om },
7367 { "overlay", &cfAd_overlay },
7372 * add / delete: all types that may be added or deleted must use an
7373 * X-ORDERED attributeType for their RDN. Adding and deleting entries
7374 * should automatically renumber the index of any siblings as needed,
7375 * so that no gaps in the numbering sequence exist after the add/delete
7377 * What can be added:
7379 * backend objects for backend-specific config directives
7383 * delete: probably no support this time around.
7385 * modrdn: generally not done. Will be invoked automatically by add/
7386 * delete to update numbering sequence. Perform as an explicit operation
7387 * so that the renumbering effect may be replicated. Subtree rename must
7388 * be supported, since renumbering a database will affect all its child
7391 * modify: must be fully supported.
7395 config_back_initialize( BackendInfo *bi )
7397 ConfigTable *ct = config_back_cf_table;
7401 AttributeDescription *ad = NULL;
7403 static char *controls[] = {
7404 LDAP_CONTROL_MANAGEDSAIT,
7408 /* Make sure we don't exceed the bits reserved for userland */
7409 config_check_userland( CFG_LAST );
7411 bi->bi_controls = controls;
7416 bi->bi_destroy = config_back_destroy;
7418 bi->bi_db_init = config_back_db_init;
7419 bi->bi_db_config = 0;
7420 bi->bi_db_open = config_back_db_open;
7421 bi->bi_db_close = config_back_db_close;
7422 bi->bi_db_destroy = config_back_db_destroy;
7424 bi->bi_op_bind = config_back_bind;
7425 bi->bi_op_unbind = 0;
7426 bi->bi_op_search = config_back_search;
7427 bi->bi_op_compare = 0;
7428 bi->bi_op_modify = config_back_modify;
7429 bi->bi_op_modrdn = config_back_modrdn;
7430 bi->bi_op_add = config_back_add;
7431 bi->bi_op_delete = config_back_delete;
7432 bi->bi_op_abandon = 0;
7434 bi->bi_extended = 0;
7436 bi->bi_chk_referrals = 0;
7438 bi->bi_access_allowed = slap_access_allowed;
7440 bi->bi_connection_init = 0;
7441 bi->bi_connection_destroy = 0;
7443 bi->bi_entry_release_rw = config_entry_release;
7444 bi->bi_entry_get_rw = config_back_entry_get;
7446 bi->bi_tool_entry_open = config_tool_entry_open;
7447 bi->bi_tool_entry_close = config_tool_entry_close;
7448 bi->bi_tool_entry_first = config_tool_entry_first;
7449 bi->bi_tool_entry_first_x = config_tool_entry_first_x;
7450 bi->bi_tool_entry_next = config_tool_entry_next;
7451 bi->bi_tool_entry_get = config_tool_entry_get;
7452 bi->bi_tool_entry_put = config_tool_entry_put;
7455 argv[ 0 ] = "slapd";
7461 for (i=0; OidMacros[i].name; i++ ) {
7462 argv[1] = OidMacros[i].name;
7463 argv[2] = OidMacros[i].oid;
7464 parse_oidm( &ca, 0, NULL );
7467 bi->bi_cf_ocs = cf_ocs;
7469 i = config_register_schema( ct, cf_ocs );
7472 i = slap_str2ad( "olcDatabase", &olcDatabaseDummy[0].ad, &text );
7475 /* setup olcRootPW to be base64-encoded when written in LDIF form;
7476 * basically, we don't care if it fails */
7477 i = slap_str2ad( "olcRootPW", &ad, &text );
7479 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
7480 "warning, unable to get \"olcRootPW\" "
7481 "attribute description: %d: %s\n",
7484 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
7485 ad->ad_type->sat_oid );
7488 /* set up the notable AttributeDescriptions */
7490 for (;ct->name;ct++) {
7491 if (strcmp(ct->name, ads[i].name)) continue;
7492 *ads[i].desc = ct->ad;
7494 if (!ads[i].name) break;