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
258 * OLcfgOv{Oc|At}:1 -> syncprov
259 * OLcfgOv{Oc|At}:2 -> pcache
260 * OLcfgOv{Oc|At}:3 -> chain
261 * OLcfgOv{Oc|At}:4 -> accesslog
262 * OLcfgOv{Oc|At}:5 -> valsort
263 * OLcfgOv{Oc|At}:7 -> distproc
264 * OLcfgOv{Oc|At}:8 -> dynlist
265 * OLcfgOv{Oc|At}:9 -> dds
266 * OLcfgOv{Oc|At}:10 -> unique
267 * OLcfgOv{Oc|At}:11 -> refint
268 * OLcfgOv{Oc|At}:12 -> ppolicy
269 * OLcfgOv{Oc|At}:13 -> constraint
270 * OLcfgOv{Oc|At}:14 -> translucent
271 * OLcfgOv{Oc|At}:15 -> auditlog
272 * OLcfgOv{Oc|At}:16 -> rwm
273 * OLcfgOv{Oc|At}:17 -> dyngroup
274 * OLcfgOv{Oc|At}:18 -> memberof
275 * OLcfgOv{Oc|At}:19 -> collect
276 * OLcfgOv{Oc|At}:20 -> retcode
277 * OLcfgOv{Oc|At}:21 -> sssvlv
280 /* alphabetical ordering */
282 static ConfigTable config_back_cf_table[] = {
283 /* This attr is read-only */
284 { "", "", 0, 0, 0, ARG_MAGIC,
285 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
286 "DESC 'File for slapd configuration directives' "
287 "EQUALITY caseIgnoreMatch "
288 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
289 { "", "", 0, 0, 0, ARG_MAGIC,
290 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
291 "DESC 'Directory for slapd configuration backend' "
292 "EQUALITY caseIgnoreMatch "
293 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
294 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
295 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
296 "DESC 'Access Control List' "
297 "EQUALITY caseIgnoreMatch "
298 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
299 { "add_content_acl", NULL, 0, 0, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_ACL_ADD,
300 &config_generic, "( OLcfgGlAt:86 NAME 'olcAddContentAcl' "
301 "DESC 'Check ACLs against content of Add ops' "
302 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
303 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
304 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
305 "DESC 'Allowed set of deprecated features' "
306 "EQUALITY caseIgnoreMatch "
307 "SYNTAX OMsDirectoryString )", NULL, NULL },
308 { "argsfile", "file", 2, 2, 0, ARG_STRING,
309 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
310 "DESC 'File for slapd command line options' "
311 "EQUALITY caseIgnoreMatch "
312 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
313 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
314 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
315 "EQUALITY caseIgnoreMatch "
316 "SYNTAX OMsDirectoryString )", NULL, NULL },
317 { "attribute", "attribute", 2, 0, STRLENOF( "attribute" ),
318 ARG_PAREN|ARG_MAGIC|CFG_ATTR,
319 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
320 "DESC 'OpenLDAP attributeTypes' "
321 "EQUALITY caseIgnoreMatch "
322 "SUBSTR caseIgnoreSubstringsMatch "
323 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
325 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
326 #ifdef SLAP_AUTH_REWRITE
327 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
331 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
332 "EQUALITY caseIgnoreMatch "
333 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
334 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
335 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
336 "EQUALITY caseIgnoreMatch "
337 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
338 { "authz-regexp", "regexp> <DN", 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
339 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
340 "EQUALITY caseIgnoreMatch "
341 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
342 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
343 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
344 "DESC 'A type of backend' "
345 "EQUALITY caseIgnoreMatch "
346 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
348 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
349 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
350 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
351 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
352 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
353 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
354 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
355 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
356 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
357 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
358 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
359 "DESC 'The backend type for a database instance' "
360 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
361 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
362 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
363 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
364 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
365 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
366 "EQUALITY caseIgnoreMatch "
367 "SYNTAX OMsDirectoryString )", NULL, NULL },
368 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
369 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
370 "DESC 'OpenLDAP DIT content rules' "
371 "EQUALITY caseIgnoreMatch "
372 "SUBSTR caseIgnoreSubstringsMatch "
373 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
375 { "extra_attrs", "attrlist", 2, 2, 0, ARG_DB|ARG_MAGIC,
376 &config_extra_attrs, "( OLcfgDbAt:0.20 NAME 'olcExtraAttrs' "
377 "EQUALITY caseIgnoreMatch "
378 "SYNTAX OMsDirectoryString )", NULL, NULL },
379 { "gentlehup", "on|off", 2, 2, 0,
381 ARG_ON_OFF, &global_gentlehup,
385 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
386 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
387 { "hidden", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_HIDDEN,
388 &config_generic, "( OLcfgDbAt:0.17 NAME 'olcHidden' "
389 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
390 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
391 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
392 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
393 { "include", "file", 2, 2, 0, ARG_MAGIC,
394 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
395 "SUP labeledURI )", NULL, NULL },
396 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
397 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
398 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
399 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_UINT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
400 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
401 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
402 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
403 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
404 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
405 { "index_substr_any_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
406 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
407 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
408 { "index_intlen", "len", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_IX_INTLEN,
409 &config_generic, "( OLcfgGlAt:84 NAME 'olcIndexIntLen' "
410 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
411 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
412 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
413 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
414 { "ldapsyntax", "syntax", 2, 0, 0,
415 ARG_PAREN|ARG_MAGIC|CFG_SYNTAX,
416 &config_generic, "( OLcfgGlAt:85 NAME 'olcLdapSyntaxes' "
417 "DESC 'OpenLDAP ldapSyntax' "
418 "EQUALITY caseIgnoreMatch "
419 "SUBSTR caseIgnoreSubstringsMatch "
420 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
422 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
423 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
424 "EQUALITY caseIgnoreMatch "
425 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
426 { "listener-threads", "count", 2, 0, 0,
430 ARG_UINT|ARG_MAGIC|CFG_LTHREADS, &config_generic,
432 "( OLcfgGlAt:93 NAME 'olcListenerThreads' "
433 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
434 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
435 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
436 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
437 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
438 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
439 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
440 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
441 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
442 "EQUALITY caseIgnoreMatch "
443 "SYNTAX OMsDirectoryString )", NULL, NULL },
444 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
445 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
446 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
447 { "mirrormode", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_MIRRORMODE,
448 &config_generic, "( OLcfgDbAt:0.16 NAME 'olcMirrorMode' "
449 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
450 { "moduleload", "file", 2, 0, 0,
452 ARG_MAGIC|CFG_MODLOAD|ARG_NO_DELETE, &config_generic,
456 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
457 "EQUALITY caseIgnoreMatch "
458 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
459 { "modulepath", "path", 2, 2, 0,
461 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
465 "( OLcfgGlAt:31 NAME 'olcModulePath' "
466 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
467 { "monitoring", "TRUE|FALSE", 2, 2, 0,
468 ARG_MAGIC|CFG_MONITORING|ARG_DB|ARG_ON_OFF, &config_generic,
469 "( OLcfgDbAt:0.18 NAME 'olcMonitoring' "
470 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
471 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
472 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
473 "DESC 'OpenLDAP object classes' "
474 "EQUALITY caseIgnoreMatch "
475 "SUBSTR caseIgnoreSubstringsMatch "
476 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
478 { "objectidentifier", "name> <oid", 3, 3, 0, ARG_MAGIC|CFG_OID,
479 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
480 "EQUALITY caseIgnoreMatch "
481 "SUBSTR caseIgnoreSubstringsMatch "
482 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
483 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
484 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
485 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
486 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
487 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
488 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
489 { "password-hash", "hash", 2, 0, 0, ARG_MAGIC,
490 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
491 "EQUALITY caseIgnoreMatch "
492 "SYNTAX OMsDirectoryString )", NULL, NULL },
493 { "pidfile", "file", 2, 2, 0, ARG_STRING,
494 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
495 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
496 { "plugin", NULL, 0, 0, 0,
498 ARG_MAGIC|CFG_PLUGIN, &config_generic,
502 "( OLcfgGlAt:38 NAME 'olcPlugin' "
503 "EQUALITY caseIgnoreMatch "
504 "SYNTAX OMsDirectoryString )", NULL, NULL },
505 { "pluginlog", "filename", 2, 2, 0,
507 ARG_STRING, &slapi_log_file,
511 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
512 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
513 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
514 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
515 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
516 { "referral", "url", 2, 2, 0, ARG_MAGIC,
517 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
518 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
519 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
520 &config_obsolete, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
521 "EQUALITY caseIgnoreMatch "
522 "SUP labeledURI X-ORDERED 'VALUES' )", NULL, NULL },
523 { "replica-argsfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
524 &config_obsolete, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
525 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
526 { "replica-pidfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
527 &config_obsolete, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
528 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
529 { "replicationInterval", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
530 &config_obsolete, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
531 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
532 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC,
533 &config_obsolete, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
534 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
535 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
536 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
537 "EQUALITY caseIgnoreMatch "
538 "SYNTAX OMsDirectoryString )", NULL, NULL },
539 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
540 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
541 "EQUALITY caseIgnoreMatch "
542 "SYNTAX OMsDirectoryString )", NULL, NULL },
543 { "reverse-lookup", "on|off", 2, 2, 0,
544 #ifdef SLAPD_RLOOKUPS
545 ARG_ON_OFF, &use_reverse_lookup,
549 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
550 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
551 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
552 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
553 "EQUALITY distinguishedNameMatch "
554 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
555 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
556 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
557 "EQUALITY caseIgnoreMatch "
558 "SYNTAX OMsDirectoryString )", NULL, NULL },
559 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
560 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
561 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
562 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
563 &config_generic, NULL, NULL, NULL },
564 { "sasl-auxprops", NULL, 2, 0, 0,
565 #ifdef HAVE_CYRUS_SASL
566 ARG_STRING|ARG_UNIQUE, &slap_sasl_auxprops,
570 "( OLcfgGlAt:89 NAME 'olcSaslAuxprops' "
571 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
572 { "sasl-auxprops-dontusecopy", NULL, 2, 0, 0,
573 #if defined(HAVE_CYRUS_SASL) && defined(SLAP_AUXPROP_DONTUSECOPY)
574 ARG_MAGIC|CFG_AZDUC, &config_generic,
578 "( OLcfgGlAt:91 NAME 'olcSaslAuxpropsDontUseCopy' "
579 "EQUALITY caseIgnoreMatch "
580 "SYNTAX OMsDirectoryString )", NULL, NULL },
581 { "sasl-auxprops-dontusecopy-ignore", "true|FALSE", 2, 0, 0,
582 #if defined(HAVE_CYRUS_SASL) && defined(SLAP_AUXPROP_DONTUSECOPY)
583 ARG_ON_OFF|CFG_AZDUC_IGNORE, &slap_dontUseCopy_ignore,
587 "( OLcfgGlAt:92 NAME 'olcSaslAuxpropsDontUseCopyIgnore' "
588 "EQUALITY booleanMatch "
589 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
590 { "sasl-host", "host", 2, 2, 0,
591 #ifdef HAVE_CYRUS_SASL
592 ARG_STRING|ARG_UNIQUE, &sasl_host,
596 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
597 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
598 { "sasl-realm", "realm", 2, 2, 0,
599 #ifdef HAVE_CYRUS_SASL
600 ARG_STRING|ARG_UNIQUE, &global_realm,
604 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
605 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
606 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
607 &config_generic, NULL, NULL, NULL },
608 { "sasl-secprops", "properties", 2, 2, 0,
609 #ifdef HAVE_CYRUS_SASL
610 ARG_MAGIC|CFG_SASLSECP, &config_generic,
614 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
615 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
616 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
617 &config_generic, NULL, NULL, NULL },
618 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
619 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
620 "EQUALITY distinguishedNameMatch "
621 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
622 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
623 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
624 "EQUALITY caseIgnoreMatch "
625 "SYNTAX OMsDirectoryString )", NULL, NULL },
626 { "serverID", "number> <[URI]", 2, 3, 0, ARG_MAGIC|CFG_SERVERID,
627 &config_generic, "( OLcfgGlAt:81 NAME 'olcServerID' "
628 "EQUALITY caseIgnoreMatch "
629 "SYNTAX OMsDirectoryString )", NULL, NULL },
630 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
631 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
632 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
633 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
634 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
635 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
636 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
637 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
638 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
639 { "sortvals", "attr", 2, 0, 0, ARG_MAGIC|CFG_SORTVALS,
640 &config_generic, "( OLcfgGlAt:83 NAME 'olcSortVals' "
641 "DESC 'Attributes whose values will always be sorted' "
642 "EQUALITY caseIgnoreMatch "
643 "SYNTAX OMsDirectoryString )", NULL, NULL },
644 { "subordinate", "[advertise]", 1, 2, 0, ARG_DB|ARG_MAGIC,
645 &config_subordinate, "( OLcfgDbAt:0.15 NAME 'olcSubordinate' "
646 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
647 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
648 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
649 "EQUALITY distinguishedNameMatch "
650 "SYNTAX OMsDN )", NULL, NULL },
651 { "sync_use_subentry", NULL, 0, 0, 0, ARG_ON_OFF|ARG_DB|ARG_MAGIC|CFG_SYNC_SUBENTRY,
652 &config_generic, "( OLcfgDbAt:0.19 NAME 'olcSyncUseSubentry' "
653 "DESC 'Store sync context in a subentry' "
654 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
655 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
656 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
657 "EQUALITY caseIgnoreMatch "
658 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
659 { "tcp-buffer", "[listener=<listener>] [{read|write}=]size", 0, 0, 0,
660 #ifndef LDAP_TCP_BUFFER
662 #else /* LDAP_TCP_BUFFER */
663 ARG_MAGIC, &config_tcp_buffer,
664 #endif /* LDAP_TCP_BUFFER */
665 "( OLcfgGlAt:90 NAME 'olcTCPBuffer' "
666 "DESC 'Custom TCP buffer size' "
667 "SYNTAX OMsDirectoryString )", NULL, NULL },
668 { "threads", "count", 2, 2, 0,
672 ARG_INT|ARG_MAGIC|CFG_THREADS, &config_generic,
674 "( OLcfgGlAt:66 NAME 'olcThreads' "
675 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
676 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
677 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
678 "SYNTAX OMsDirectoryString )", NULL, NULL },
679 { "TLSCACertificateFile", NULL, 2, 2, 0,
681 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
685 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
686 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
687 { "TLSCACertificatePath", NULL, 2, 2, 0,
689 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
693 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
694 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
695 { "TLSCertificateFile", NULL, 2, 2, 0,
697 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
701 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
702 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
703 { "TLSCertificateKeyFile", NULL, 2, 2, 0,
705 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
709 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
710 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
711 { "TLSCipherSuite", NULL, 2, 2, 0,
713 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
717 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
718 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
719 { "TLSCRLCheck", NULL, 2, 2, 0,
720 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
721 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
725 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
726 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
727 { "TLSCRLFile", NULL, 2, 2, 0,
728 #if defined(HAVE_GNUTLS)
729 CFG_TLS_CRL_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
733 "( OLcfgGlAt:82 NAME 'olcTLSCRLFile' "
734 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
735 { "TLSRandFile", NULL, 2, 2, 0,
737 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
741 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
742 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
743 { "TLSVerifyClient", NULL, 2, 2, 0,
745 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
749 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
750 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
751 { "TLSDHParamFile", NULL, 2, 2, 0,
753 CFG_TLS_DH_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
757 "( OLcfgGlAt:77 NAME 'olcTLSDHParamFile' "
758 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
759 { "TLSProtocolMin", NULL, 2, 2, 0,
761 CFG_TLS_PROTOCOL_MIN|ARG_STRING|ARG_MAGIC, &config_tls_config,
765 "( OLcfgGlAt:87 NAME 'olcTLSProtocolMin' "
766 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
767 { "tool-threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_TTHREADS,
768 &config_generic, "( OLcfgGlAt:80 NAME 'olcToolThreads' "
769 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
770 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
771 NULL, NULL, NULL, NULL },
772 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
773 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
774 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
775 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
776 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
777 "EQUALITY caseIgnoreMatch "
778 "SUP labeledURI )", NULL, NULL },
779 { "writetimeout", "timeout", 2, 2, 0, ARG_INT,
780 &global_writetimeout, "( OLcfgGlAt:88 NAME 'olcWriteTimeout' "
781 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
782 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
783 NULL, NULL, NULL, NULL }
786 /* Need to no-op this keyword for dynamic config */
787 ConfigTable olcDatabaseDummy[] = {
788 { "", "", 0, 0, 0, ARG_IGNORED,
789 NULL, "( OLcfgGlAt:13 NAME 'olcDatabase' "
790 "DESC 'The backend type for a database instance' "
791 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
792 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
795 /* Routines to check if a child can be added to this type */
796 static ConfigLDAPadd cfAddSchema, cfAddInclude, cfAddDatabase,
797 cfAddBackend, cfAddModule, cfAddOverlay;
799 /* NOTE: be careful when defining array members
800 * that can be conditionally compiled */
801 #define CFOC_GLOBAL cf_ocs[1]
802 #define CFOC_SCHEMA cf_ocs[2]
803 #define CFOC_BACKEND cf_ocs[3]
804 #define CFOC_DATABASE cf_ocs[4]
805 #define CFOC_OVERLAY cf_ocs[5]
806 #define CFOC_INCLUDE cf_ocs[6]
807 #define CFOC_FRONTEND cf_ocs[7]
809 #define CFOC_MODULE cf_ocs[8]
810 #endif /* SLAPD_MODULES */
812 static ConfigOCs cf_ocs[] = {
815 "DESC 'OpenLDAP configuration object' "
816 "ABSTRACT SUP top )", Cft_Abstract, NULL },
819 "DESC 'OpenLDAP Global configuration options' "
820 "SUP olcConfig STRUCTURAL "
821 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
822 "olcAttributeOptions $ olcAuthIDRewrite $ "
823 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
824 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
825 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
826 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
827 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcIndexIntLen $ "
828 "olcLocalSSF $ olcLogFile $ olcLogLevel $ "
829 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
830 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
831 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
833 "olcSaslAuxprops $ olcSaslAuxpropsDontUseCopy $ olcSaslAuxpropsDontUseCopyIgnore $ "
834 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
835 "olcSecurity $ olcServerID $ olcSizeLimit $ "
836 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ "
838 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
839 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
840 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
841 "olcTLSRandFile $ olcTLSVerifyClient $ olcTLSDHParamFile $ "
842 "olcTLSCRLFile $ olcToolThreads $ olcWriteTimeout $ "
843 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
844 "olcDitContentRules $ olcLdapSyntaxes ) )", Cft_Global },
846 "NAME 'olcSchemaConfig' "
847 "DESC 'OpenLDAP schema object' "
848 "SUP olcConfig STRUCTURAL "
849 "MAY ( cn $ olcObjectIdentifier $ olcAttributeTypes $ "
850 "olcObjectClasses $ olcDitContentRules $ olcLdapSyntaxes ) )",
851 Cft_Schema, NULL, cfAddSchema },
853 "NAME 'olcBackendConfig' "
854 "DESC 'OpenLDAP Backend-specific options' "
855 "SUP olcConfig STRUCTURAL "
856 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
858 "NAME 'olcDatabaseConfig' "
859 "DESC 'OpenLDAP Database-specific options' "
860 "SUP olcConfig STRUCTURAL "
862 "MAY ( olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
863 "olcAddContentAcl $ olcLastMod $ olcLimits $ "
864 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
865 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
866 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
867 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncUseSubentry $ olcSyncrepl $ "
868 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef $ olcMirrorMode $ "
869 "olcMonitoring $ olcExtraAttrs ) )",
870 Cft_Database, NULL, cfAddDatabase },
872 "NAME 'olcOverlayConfig' "
873 "DESC 'OpenLDAP Overlay-specific options' "
874 "SUP olcConfig STRUCTURAL "
875 "MUST olcOverlay )", Cft_Overlay, NULL, cfAddOverlay },
877 "NAME 'olcIncludeFile' "
878 "DESC 'OpenLDAP configuration include file' "
879 "SUP olcConfig STRUCTURAL "
881 "MAY ( cn $ olcRootDSE ) )",
882 /* Used to be Cft_Include, that def has been removed */
883 Cft_Abstract, NULL, cfAddInclude },
884 /* This should be STRUCTURAL like all the other database classes, but
885 * that would mean inheriting all of the olcDatabaseConfig attributes,
886 * which causes them to be merged twice in config_build_entry.
889 "NAME 'olcFrontendConfig' "
890 "DESC 'OpenLDAP frontend configuration' "
892 "MAY ( olcDefaultSearchBase $ olcPasswordHash $ olcSortVals ) )",
893 Cft_Database, NULL, NULL },
896 "NAME 'olcModuleList' "
897 "DESC 'OpenLDAP dynamic module info' "
898 "SUP olcConfig STRUCTURAL "
899 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
900 Cft_Module, NULL, cfAddModule },
905 typedef struct ServerID {
906 struct ServerID *si_next;
907 struct berval si_url;
911 static ServerID *sid_list;
913 typedef struct voidList {
914 struct voidList *vl_next;
918 typedef struct ADlist {
919 struct ADlist *al_next;
920 AttributeDescription *al_desc;
923 static ADlist *sortVals;
926 config_generic(ConfigArgs *c) {
929 if ( c->op == SLAP_CONFIG_EMIT ) {
933 c->value_int = ldap_pvt_thread_get_concurrency();
936 c->value_int = connection_pool_max;
939 c->value_int = slap_tool_thread_max;
942 c->value_uint = slapd_daemon_threads;
946 c->value_string = ch_strdup( passwd_salt );
951 if ( c->be->be_limits ) {
955 for ( i=0; c->be->be_limits[i]; i++ ) {
956 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
957 if ( bv.bv_len >= sizeof( buf ) ) {
958 ber_bvarray_free_x( c->rvalue_vals, NULL );
959 c->rvalue_vals = NULL;
963 bv.bv_val = buf + bv.bv_len;
964 limits_unparse( c->be->be_limits[i], &bv,
965 sizeof( buf ) - ( bv.bv_val - buf ) );
966 bv.bv_len += bv.bv_val - buf;
968 value_add_one( &c->rvalue_vals, &bv );
971 if ( !c->rvalue_vals ) rc = 1;
974 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_READONLY);
977 c->value_string = ch_strdup( slap_sasl_getpolicy());
980 slap_sasl_regexp_unparse( &c->rvalue_vals );
981 if ( !c->rvalue_vals ) rc = 1;
983 #ifdef HAVE_CYRUS_SASL
984 #ifdef SLAP_AUXPROP_DONTUSECOPY
986 static int duc_done = 0;
988 /* take the opportunity to initialize with known values */
990 struct berval duc[] = { BER_BVC("cmusaslsecretOTP"), BER_BVNULL };
993 for ( i = 0; !BER_BVISNULL( &duc[ i ] ); i++ ) {
994 const char *text = NULL;
995 AttributeDescription *ad = NULL;
997 if ( slap_bv2ad( &duc[ i ], &ad, &text ) == LDAP_SUCCESS ) {
999 if ( slap_dontUseCopy_propnames ) {
1002 for ( j = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ j ] ); j++ ) {
1003 if ( bvmatch( &slap_dontUseCopy_propnames[ j ], &ad->ad_cname ) ) {
1010 value_add_one( &slap_dontUseCopy_propnames, &ad->ad_cname );
1018 if ( slap_dontUseCopy_propnames != NULL ) {
1019 ber_bvarray_dup_x( &c->rvalue_vals, slap_dontUseCopy_propnames, NULL );
1024 #endif /* SLAP_AUXPROP_DONTUSECOPY */
1025 case CFG_SASLSECP: {
1026 struct berval bv = BER_BVNULL;
1027 slap_sasl_secprops_unparse( &bv );
1028 if ( !BER_BVISNULL( &bv )) {
1029 ber_bvarray_add( &c->rvalue_vals, &bv );
1037 c->value_int = c->be->be_max_deref_depth;
1040 if ( SLAP_DBHIDDEN( c->be )) {
1047 ConfigFile *cf = c->ca_private;
1049 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1050 else if ( cf->c_om_head )
1051 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
1053 if ( !c->rvalue_vals )
1058 ad_unparse_options( &c->rvalue_vals );
1061 ConfigFile *cf = c->ca_private;
1063 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1064 else if ( cf->c_oc_head )
1065 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
1067 if ( !c->rvalue_vals )
1072 ConfigFile *cf = c->ca_private;
1074 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1075 else if ( cf->c_at_head )
1076 at_unparse( &c->rvalue_vals, cf->c_at_head,
1078 if ( !c->rvalue_vals )
1083 ConfigFile *cf = c->ca_private;
1085 syn_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1086 else if ( cf->c_syn_head )
1087 syn_unparse( &c->rvalue_vals, cf->c_syn_head,
1088 cf->c_syn_tail, 0 );
1089 if ( !c->rvalue_vals )
1094 ConfigFile *cf = c->ca_private;
1096 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
1097 else if ( cf->c_cr_head )
1098 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
1100 if ( !c->rvalue_vals )
1107 char *src, *dst, ibuf[11];
1108 struct berval bv, abv;
1109 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
1110 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1111 if ( abv.bv_len >= sizeof( ibuf ) ) {
1112 ber_bvarray_free_x( c->rvalue_vals, NULL );
1113 c->rvalue_vals = NULL;
1117 acl_unparse( a, &bv );
1118 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
1119 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
1120 /* Turn TAB / EOL into plain space */
1121 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
1122 if (isspace((unsigned char)*src)) *dst++ = ' ';
1126 if (dst[-1] == ' ') {
1130 abv.bv_len = dst - abv.bv_val;
1131 ber_bvarray_add( &c->rvalue_vals, &abv );
1137 c->value_int = (SLAP_DBACL_ADD(c->be) != 0);
1140 ConfigFile *cf = c->ca_private;
1141 if ( cf->c_dseFiles ) {
1142 value_add( &c->rvalue_vals, cf->c_dseFiles );
1153 for ( si = sid_list; si; si=si->si_next ) {
1154 assert( si->si_num >= 0 && si->si_num <= SLAP_SYNC_SID_MAX );
1155 if ( !BER_BVISEMPTY( &si->si_url )) {
1156 bv.bv_len = si->si_url.bv_len + 6;
1157 bv.bv_val = ch_malloc( bv.bv_len );
1158 bv.bv_len = sprintf( bv.bv_val, "%d %s", si->si_num,
1159 si->si_url.bv_val );
1160 ber_bvarray_add( &c->rvalue_vals, &bv );
1164 bv.bv_len = sprintf( buf, "%d", si->si_num );
1165 value_add_one( &c->rvalue_vals, &bv );
1174 c->value_string = ch_strdup( logfileName );
1179 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1181 case CFG_SYNC_SUBENTRY:
1182 c->value_int = (SLAP_SYNC_SUBENTRY(c->be) != 0);
1184 case CFG_MIRRORMODE:
1185 if ( SLAP_SHADOW(c->be))
1186 c->value_int = (SLAP_SINGLE_SHADOW(c->be) == 0);
1190 case CFG_MONITORING:
1191 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
1193 case CFG_SSTR_IF_MAX:
1194 c->value_uint = index_substr_if_maxlen;
1196 case CFG_SSTR_IF_MIN:
1197 c->value_uint = index_substr_if_minlen;
1200 c->value_int = index_intlen;
1202 case CFG_SORTVALS: {
1205 for ( sv = sortVals; sv; sv = sv->al_next ) {
1206 value_add_one( &c->rvalue_vals, &sv->al_desc->ad_cname );
1210 #ifdef SLAPD_MODULES
1212 ModPaths *mp = c->ca_private;
1215 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
1218 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
1219 SLAP_X_ORDERED_FMT "%s", i,
1220 mp->mp_loads[i].bv_val );
1221 if ( bv.bv_len >= sizeof( c->log ) ) {
1222 ber_bvarray_free_x( c->rvalue_vals, NULL );
1223 c->rvalue_vals = NULL;
1226 value_add_one( &c->rvalue_vals, &bv );
1230 rc = c->rvalue_vals ? 0 : 1;
1234 ModPaths *mp = c->ca_private;
1235 if ( !BER_BVISNULL( &mp->mp_path ))
1236 value_add_one( &c->rvalue_vals, &mp->mp_path );
1238 rc = c->rvalue_vals ? 0 : 1;
1244 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1245 if ( !c->rvalue_vals ) rc = 1;
1248 #ifdef SLAP_AUTH_REWRITE
1250 if ( authz_rewrites ) {
1251 struct berval bv, idx;
1256 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1257 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1258 if ( idx.bv_len >= sizeof( ibuf ) ) {
1259 ber_bvarray_free_x( c->rvalue_vals, NULL );
1260 c->rvalue_vals = NULL;
1263 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1264 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1265 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1266 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1267 authz_rewrites[i].bv_val,
1268 authz_rewrites[i].bv_len + 1 );
1269 ber_bvarray_add( &c->rvalue_vals, &bv );
1272 if ( !c->rvalue_vals ) rc = 1;
1279 } else if ( c->op == LDAP_MOD_DELETE ) {
1282 /* single-valued attrs, no-ops */
1291 case CFG_MIRRORMODE:
1292 case CFG_MONITORING:
1294 case CFG_SSTR_IF_MAX:
1295 case CFG_SSTR_IF_MIN:
1297 case CFG_SYNC_SUBENTRY:
1300 /* no-ops, requires slapd restart */
1305 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1308 #if defined(HAVE_CYRUS_SASL) && defined(SLAP_AUXPROP_DONTUSECOPY)
1310 if ( c->valx < 0 ) {
1311 if ( slap_dontUseCopy_propnames != NULL ) {
1312 ber_bvarray_free( slap_dontUseCopy_propnames );
1313 slap_dontUseCopy_propnames = NULL;
1319 if ( slap_dontUseCopy_propnames == NULL ) {
1324 for ( i = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ i ] ) && i < c->valx; i++ );
1325 if ( i < c->valx ) {
1329 ber_memfree( slap_dontUseCopy_propnames[ i ].bv_val );
1330 for ( ; !BER_BVISNULL( &slap_dontUseCopy_propnames[ i + 1 ] ); i++ ) {
1331 slap_dontUseCopy_propnames[ i ] = slap_dontUseCopy_propnames[ i + 1 ];
1333 BER_BVZERO( &slap_dontUseCopy_propnames[ i ] );
1336 #endif /* SLAP_AUXPROP_DONTUSECOPY */
1338 ch_free( passwd_salt );
1343 ch_free( logfileName );
1351 case CFG_SERVERID: {
1352 ServerID *si, **sip;
1354 for ( i=0, si = sid_list, sip = &sid_list;
1355 si; si = *sip, i++ ) {
1356 if ( c->valx == -1 || i == c->valx ) {
1368 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1372 index_intlen = SLAP_INDEX_INTLEN_DEFAULT;
1373 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1374 SLAP_INDEX_INTLEN_DEFAULT );
1378 if ( c->valx < 0 ) {
1379 acl_destroy( c->be->be_acl );
1380 c->be->be_acl = NULL;
1383 AccessControl **prev, *a;
1385 for (i=0, prev = &c->be->be_acl; i < c->valx;
1388 prev = &a->acl_next;
1391 *prev = a->acl_next;
1398 /* Can be NULL when undoing a failed add */
1399 if ( c->ca_entry ) {
1400 ce = c->ca_entry->e_private;
1401 /* can't modify the hardcoded schema */
1402 if ( ce->ce_parent->ce_type == Cft_Global )
1406 cfn = c->ca_private;
1407 if ( c->valx < 0 ) {
1410 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1412 if ( oc == cfn->c_oc_tail )
1415 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1417 ObjectClass *oc, *prev = NULL;
1419 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1424 if ( cfn->c_oc_tail == oc ) {
1425 cfn->c_oc_tail = prev;
1427 if ( cfn->c_oc_head == oc ) {
1429 cfn->c_oc_head = oc;
1436 /* Can be NULL when undoing a failed add */
1437 if ( c->ca_entry ) {
1438 ce = c->ca_entry->e_private;
1439 /* can't modify the hardcoded schema */
1440 if ( ce->ce_parent->ce_type == Cft_Global )
1444 cfn = c->ca_private;
1445 if ( c->valx < 0 ) {
1448 for( at = cfn->c_at_head; at; at_next( &at )) {
1450 if ( at == cfn->c_at_tail )
1453 cfn->c_at_head = cfn->c_at_tail = NULL;
1455 AttributeType *at, *prev = NULL;
1457 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1462 if ( cfn->c_at_tail == at ) {
1463 cfn->c_at_tail = prev;
1465 if ( cfn->c_at_head == at ) {
1467 cfn->c_at_head = at;
1474 /* Can be NULL when undoing a failed add */
1475 if ( c->ca_entry ) {
1476 ce = c->ca_entry->e_private;
1477 /* can't modify the hardcoded schema */
1478 if ( ce->ce_parent->ce_type == Cft_Global )
1482 cfn = c->ca_private;
1483 if ( c->valx < 0 ) {
1486 for( syn = cfn->c_syn_head; syn; syn_next( &syn )) {
1488 if ( syn == cfn->c_syn_tail )
1491 cfn->c_syn_head = cfn->c_syn_tail = NULL;
1493 Syntax *syn, *prev = NULL;
1495 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++) {
1500 if ( cfn->c_syn_tail == syn ) {
1501 cfn->c_syn_tail = prev;
1503 if ( cfn->c_syn_head == syn ) {
1505 cfn->c_syn_head = syn;
1510 if ( c->valx < 0 ) {
1512 for ( sv = sortVals; sv; sv = sortVals ) {
1513 sortVals = sv->al_next;
1514 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1521 for ( prev = &sortVals, sv = sortVals; i < c->valx; i++ ) {
1522 prev = &sv->al_next;
1525 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1526 *prev = sv->al_next;
1532 /* FIXME: there is no limits_free function */
1533 if ( c->valx < 0 ) {
1534 limits_destroy( c->be->be_limits );
1535 c->be->be_limits = NULL;
1540 if ( c->be->be_limits ) {
1541 for ( num = 0; c->be->be_limits[ num ]; num++ )
1545 if ( c->valx >= num ) {
1550 limits_destroy( c->be->be_limits );
1551 c->be->be_limits = NULL;
1554 limits_free_one( c->be->be_limits[ c->valx ] );
1556 for ( cnt = c->valx; cnt < num; cnt++ ) {
1557 c->be->be_limits[ cnt ] = c->be->be_limits[ cnt + 1 ];
1564 /* FIXME: there is no ad_option_free function */
1566 /* FIXME: there is no way to remove attributes added by
1580 if(!(c->bi = backend_info(c->argv[1]))) {
1581 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1582 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1583 c->log, c->cr_msg, c->argv[1] );
1590 /* NOTE: config is always the first backend!
1592 if ( !strcasecmp( c->argv[1], "config" )) {
1593 c->be = LDAP_STAILQ_FIRST(&backendDB);
1594 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1597 c->be = backend_db_init(c->argv[1], NULL, c->valx, &c->reply);
1599 if ( c->cr_msg[0] == 0 )
1600 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1601 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n", c->log, c->cr_msg, c->argv[1] );
1608 ldap_pvt_thread_set_concurrency(c->value_int);
1612 if ( c->value_int < 2 ) {
1613 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1614 "threads=%d smaller than minimum value 2",
1616 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1617 c->log, c->cr_msg, 0 );
1620 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1621 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1622 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1623 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1624 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1625 c->log, c->cr_msg, 0 );
1627 if ( slapMode & SLAP_SERVER_MODE )
1628 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1629 connection_pool_max = c->value_int; /* save for reference */
1633 if ( slapMode & SLAP_TOOL_MODE )
1634 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1635 slap_tool_thread_max = c->value_int; /* save for reference */
1640 /* use a power of two */
1641 while (c->value_uint > 1) {
1642 c->value_uint >>= 1;
1646 slapd_daemon_mask = mask;
1647 slapd_daemon_threads = mask+1;
1652 if ( passwd_salt ) ch_free( passwd_salt );
1653 passwd_salt = c->value_string;
1654 lutil_salt_format(passwd_salt);
1658 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1664 c->be->be_restrictops |= SLAP_RESTRICT_READONLY;
1666 c->be->be_restrictops &= ~SLAP_RESTRICT_READONLY;
1670 ch_free(c->value_string);
1671 if (slap_sasl_setpolicy( c->argv[1] )) {
1672 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
1673 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1674 c->log, c->cr_msg, c->argv[1] );
1680 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1684 #ifdef HAVE_CYRUS_SASL
1685 #ifdef SLAP_AUXPROP_DONTUSECOPY
1689 for ( arg = 1; arg < c->argc; arg++ ) {
1690 int duplicate = 0, err;
1691 AttributeDescription *ad = NULL;
1692 const char *text = NULL;
1694 err = slap_str2ad( c->argv[ arg ], &ad, &text );
1695 if ( err != LDAP_SUCCESS ) {
1696 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s>: attr #%d (\"%s\") unknown (err=%d \"%s\"; ignored)",
1697 c->argv[0], arg, c->argv[ arg ], err, text );
1698 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1699 c->log, c->cr_msg, 0 );
1702 if ( slap_dontUseCopy_propnames != NULL ) {
1703 for ( cnt = 0; !BER_BVISNULL( &slap_dontUseCopy_propnames[ cnt ] ); cnt++ ) {
1704 if ( bvmatch( &slap_dontUseCopy_propnames[ cnt ], &ad->ad_cname ) ) {
1712 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s>: attr #%d (\"%s\") already defined (ignored)",
1713 c->argv[0], arg, ad->ad_cname.bv_val);
1714 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1715 c->log, c->cr_msg, 0 );
1719 value_add_one( &slap_dontUseCopy_propnames, &ad->ad_cname );
1724 #endif /* SLAP_AUXPROP_DONTUSECOPY */
1728 char *txt = slap_sasl_secprops( c->argv[1] );
1730 snprintf( c->cr_msg, sizeof(c->cr_msg), "<%s> %s",
1732 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0 );
1740 c->be->be_max_deref_depth = c->value_int;
1746 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1747 cfn = c->ca_private;
1748 if(parse_oidm(c, 1, &om))
1750 if (!cfn->c_om_head) cfn->c_om_head = om;
1751 cfn->c_om_tail = om;
1756 ObjectClass *oc, *prev;
1758 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1759 cfn = c->ca_private;
1760 if ( c->valx < 0 ) {
1761 prev = cfn->c_oc_tail;
1764 /* If adding anything after the first, prev is easy */
1767 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
1769 if ( !oc_next( &oc ))
1773 /* If adding the first, and head exists, find its prev */
1774 if (cfn->c_oc_head) {
1775 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
1780 /* else prev is NULL, append to end of global list */
1782 if(parse_oc(c, &oc, prev)) return(1);
1783 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1784 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
1789 AttributeType *at, *prev;
1791 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1792 cfn = c->ca_private;
1793 if ( c->valx < 0 ) {
1794 prev = cfn->c_at_tail;
1797 /* If adding anything after the first, prev is easy */
1800 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
1802 if ( !at_next( &at ))
1806 /* If adding the first, and head exists, find its prev */
1807 if (cfn->c_at_head) {
1808 for ( at_start( &at ); at != cfn->c_at_head; ) {
1813 /* else prev is NULL, append to end of global list */
1815 if(parse_at(c, &at, prev)) return(1);
1816 if (!cfn->c_at_head) cfn->c_at_head = at;
1817 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
1824 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1825 cfn = c->ca_private;
1826 if ( c->valx < 0 ) {
1827 prev = cfn->c_syn_tail;
1830 /* If adding anything after the first, prev is easy */
1833 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++ ) {
1835 if ( !syn_next( &syn ))
1839 /* If adding the first, and head exists, find its prev */
1840 if (cfn->c_syn_head) {
1841 for ( syn_start( &syn ); syn != cfn->c_syn_head; ) {
1846 /* else prev is NULL, append to end of global list */
1848 if ( parse_syn( c, &syn, prev ) ) return(1);
1849 if ( !cfn->c_syn_head ) cfn->c_syn_head = syn;
1850 if ( cfn->c_syn_tail == prev ) cfn->c_syn_tail = syn;
1857 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1858 cfn = c->ca_private;
1859 if(parse_cr(c, &cr)) return(1);
1860 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1861 cfn->c_cr_tail = cr;
1866 ad_define_option(NULL, NULL, 0);
1867 for(i = 1; i < c->argc; i++)
1868 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1873 if ( c->value_int < SLAP_INDEX_INTLEN_DEFAULT )
1874 c->value_int = SLAP_INDEX_INTLEN_DEFAULT;
1875 else if ( c->value_int > 255 )
1877 index_intlen = c->value_int;
1878 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1882 case CFG_SORTVALS: {
1883 ADlist *svnew = NULL, *svtail, *sv;
1885 for ( i = 1; i < c->argc; i++ ) {
1886 AttributeDescription *ad = NULL;
1890 rc = slap_str2ad( c->argv[i], &ad, &text );
1892 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown attribute type #%d",
1895 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1896 c->log, c->cr_msg, c->argv[i] );
1897 for ( sv = svnew; sv; sv = svnew ) {
1898 svnew = sv->al_next;
1903 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) ||
1904 ad->ad_type->sat_single_value ) {
1905 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> inappropriate attribute type #%d",
1907 goto sortval_reject;
1909 sv = ch_malloc( sizeof( ADlist ));
1914 svtail->al_next = sv;
1919 for ( sv = svnew; sv; sv = sv->al_next )
1920 sv->al_desc->ad_type->sat_flags |= SLAP_AT_SORTED_VAL;
1921 for ( sv = sortVals; sv && sv->al_next; sv = sv->al_next );
1923 sv->al_next = svnew;
1930 /* Don't append to the global ACL if we're on a specific DB */
1932 if ( c->valx == -1 ) {
1935 for ( a=c->be->be_acl; a; a = a->acl_next )
1938 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
1945 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_ACL_ADD;
1947 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_ACL_ADD;
1951 if(root_dse_read_file(c->argv[1])) {
1952 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> could not read file", c->argv[0] );
1953 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1954 c->log, c->cr_msg, c->argv[1] );
1959 ber_str2bv( c->argv[1], 0, 1, &bv );
1960 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1961 cfn = c->ca_private;
1962 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1968 ServerID *si, **sip;
1971 if (( lutil_atoi( &num, c->argv[1] ) &&
1972 lutil_atoix( &num, c->argv[1], 16 )) ||
1973 num < 0 || num > SLAP_SYNC_SID_MAX )
1975 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1976 "<%s> illegal server ID", c->argv[0] );
1977 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1978 c->log, c->cr_msg, c->argv[1] );
1981 /* only one value allowed if no URL is given */
1982 if ( c->argc > 2 ) {
1985 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
1986 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1987 "<%s> only one server ID allowed now", c->argv[0] );
1988 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1989 c->log, c->cr_msg, c->argv[1] );
1993 if ( ldap_url_parse( c->argv[2], &lud )) {
1994 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1995 "<%s> invalid URL", c->argv[0] );
1996 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1997 c->log, c->cr_msg, c->argv[2] );
2000 len = strlen( c->argv[2] );
2001 si = ch_malloc( sizeof(ServerID) + len + 1 );
2002 si->si_url.bv_val = (char *)(si+1);
2003 si->si_url.bv_len = len;
2004 strcpy( si->si_url.bv_val, c->argv[2] );
2007 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2008 "<%s> unqualified server ID not allowed now", c->argv[0] );
2009 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2010 c->log, c->cr_msg, c->argv[1] );
2013 si = ch_malloc( sizeof(ServerID) );
2014 BER_BVZERO( &si->si_url );
2015 slap_serverID = num;
2016 Debug( LDAP_DEBUG_CONFIG,
2018 c->log, slap_serverID, 0 );
2022 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
2025 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
2026 Listener *l = config_check_my_url( c->argv[2], lud );
2028 slap_serverID = si->si_num;
2029 Debug( LDAP_DEBUG_CONFIG,
2030 "%s: SID=0x%03x (listener=%s)\n",
2031 c->log, slap_serverID,
2036 ldap_free_urldesc( lud );
2040 if ( logfileName ) ch_free( logfileName );
2041 logfileName = c->value_string;
2042 logfile = fopen(logfileName, "w");
2043 if(logfile) lutil_debug_file(logfile);
2047 if(SLAP_NOLASTMODCMD(c->be)) {
2048 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> not available for %s database",
2049 c->argv[0], c->be->bd_info->bi_type );
2050 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2051 c->log, c->cr_msg, 0 );
2055 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
2057 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
2060 case CFG_MIRRORMODE:
2061 if(c->value_int && !SLAP_SHADOW(c->be)) {
2062 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database is not a shadow",
2064 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2065 c->log, c->cr_msg, 0 );
2069 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
2071 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
2074 case CFG_MONITORING:
2076 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
2078 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
2083 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
2085 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
2088 case CFG_SYNC_SUBENTRY:
2090 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SYNC_SUBENTRY;
2092 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SYNC_SUBENTRY;
2095 case CFG_SSTR_IF_MAX:
2096 if (c->value_uint < index_substr_if_minlen) {
2097 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
2098 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
2099 c->log, c->cr_msg, c->value_int );
2102 index_substr_if_maxlen = c->value_uint;
2105 case CFG_SSTR_IF_MIN:
2106 if (c->value_uint > index_substr_if_maxlen) {
2107 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
2108 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
2109 c->log, c->cr_msg, c->value_int );
2112 index_substr_if_minlen = c->value_uint;
2115 #ifdef SLAPD_MODULES
2117 /* If we're just adding a module on an existing modpath,
2118 * make sure we've selected the current path.
2120 if ( c->op == LDAP_MOD_ADD && c->ca_private && modcur != c->ca_private ) {
2121 modcur = c->ca_private;
2122 /* This should never fail */
2123 if ( module_path( modcur->mp_path.bv_val )) {
2124 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> module path no longer valid",
2126 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2127 c->log, c->cr_msg, modcur->mp_path.bv_val );
2131 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
2133 /* Record this load on the current path */
2137 if ( c->op == SLAP_CONFIG_ADD ) {
2138 ptr = c->line + STRLENOF("moduleload");
2139 while (!isspace((unsigned char) *ptr)) ptr++;
2140 while (isspace((unsigned char) *ptr)) ptr++;
2144 ber_str2bv(ptr, 0, 1, &bv);
2145 ber_bvarray_add( &modcur->mp_loads, &bv );
2147 /* Check for any new hardcoded schema */
2148 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
2149 config_check_schema( NULL, &cfBackInfo );
2154 if(module_path(c->argv[1])) return(1);
2155 /* Record which path was used with each module */
2159 if (!modpaths.mp_loads) {
2162 mp = ch_malloc( sizeof( ModPaths ));
2163 modlast->mp_next = mp;
2165 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
2167 mp->mp_loads = NULL;
2178 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
2180 slapi_plugins_used++;
2184 #ifdef SLAP_AUTH_REWRITE
2190 if ( c->op == LDAP_MOD_ADD ) {
2194 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
2198 if ( c->argc > 1 ) {
2201 /* quote all args but the first */
2202 line = ldap_charray2str( c->argv, "\" \"" );
2203 ber_str2bv( line, 0, 0, &bv );
2204 s = ber_bvchr( &bv, '"' );
2205 assert( s != NULL );
2206 /* move the trailing quote of argv[0] to the end */
2207 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
2208 bv.bv_val[ bv.bv_len - 1 ] = '"';
2211 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
2214 ber_bvarray_add( &authz_rewrites, &bv );
2216 if ( c->op == LDAP_MOD_ADD ) {
2226 Debug( LDAP_DEBUG_ANY,
2227 "%s: unknown CFG_TYPE %d.\n",
2228 c->log, c->type, 0 );
2237 config_fname(ConfigArgs *c) {
2238 if(c->op == SLAP_CONFIG_EMIT) {
2239 if (c->ca_private) {
2240 ConfigFile *cf = c->ca_private;
2241 value_add_one( &c->rvalue_vals, &cf->c_file );
2250 config_cfdir(ConfigArgs *c) {
2251 if(c->op == SLAP_CONFIG_EMIT) {
2252 if ( !BER_BVISEMPTY( &cfdir )) {
2253 value_add_one( &c->rvalue_vals, &cfdir );
2262 config_search_base(ConfigArgs *c) {
2263 if(c->op == SLAP_CONFIG_EMIT) {
2265 if (!BER_BVISEMPTY(&default_search_base)) {
2266 value_add_one(&c->rvalue_vals, &default_search_base);
2267 value_add_one(&c->rvalue_nvals, &default_search_nbase);
2271 } else if( c->op == LDAP_MOD_DELETE ) {
2272 ch_free( default_search_base.bv_val );
2273 ch_free( default_search_nbase.bv_val );
2274 BER_BVZERO( &default_search_base );
2275 BER_BVZERO( &default_search_nbase );
2279 if(c->bi || c->be != frontendDB) {
2280 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
2281 "prior to any backend or database definition\n",
2286 if(default_search_nbase.bv_len) {
2287 free(default_search_base.bv_val);
2288 free(default_search_nbase.bv_val);
2291 default_search_base = c->value_dn;
2292 default_search_nbase = c->value_ndn;
2296 /* For RE23 compatibility we allow this in the global entry
2297 * but we now defer it to the frontend entry to allow modules
2298 * to load new hash types.
2301 config_passwd_hash(ConfigArgs *c) {
2303 if (c->op == SLAP_CONFIG_EMIT) {
2305 /* Don't generate it in the global entry */
2306 if ( c->table == Cft_Global )
2308 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
2309 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
2310 value_add_one(&c->rvalue_vals, &bv);
2313 } else if ( c->op == LDAP_MOD_DELETE ) {
2314 /* Deleting from global is a no-op, only the frontendDB entry matters */
2315 if ( c->table == Cft_Global )
2317 if ( c->valx < 0 ) {
2318 ldap_charray_free( default_passwd_hash );
2319 default_passwd_hash = NULL;
2322 ch_free( default_passwd_hash[i] );
2323 for (; default_passwd_hash[i]; i++ )
2324 default_passwd_hash[i] = default_passwd_hash[i+1];
2328 for(i = 1; i < c->argc; i++) {
2329 if(!lutil_passwd_scheme(c->argv[i])) {
2330 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> scheme not available", c->argv[0] );
2331 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2332 c->log, c->cr_msg, c->argv[i]);
2334 ldap_charray_add(&default_passwd_hash, c->argv[i]);
2337 if(!default_passwd_hash) {
2338 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> no valid hashes found", c->argv[0] );
2339 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2340 c->log, c->cr_msg, 0 );
2347 config_schema_dn(ConfigArgs *c) {
2348 if ( c->op == SLAP_CONFIG_EMIT ) {
2350 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
2351 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
2352 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
2356 } else if ( c->op == LDAP_MOD_DELETE ) {
2357 ch_free( c->be->be_schemadn.bv_val );
2358 ch_free( c->be->be_schemandn.bv_val );
2359 BER_BVZERO( &c->be->be_schemadn );
2360 BER_BVZERO( &c->be->be_schemandn );
2363 ch_free( c->be->be_schemadn.bv_val );
2364 ch_free( c->be->be_schemandn.bv_val );
2365 c->be->be_schemadn = c->value_dn;
2366 c->be->be_schemandn = c->value_ndn;
2371 config_sizelimit(ConfigArgs *c) {
2373 struct slap_limits_set *lim = &c->be->be_def_limit;
2374 if (c->op == SLAP_CONFIG_EMIT) {
2379 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
2380 if ( !BER_BVISEMPTY( &bv ))
2381 value_add_one( &c->rvalue_vals, &bv );
2385 } else if ( c->op == LDAP_MOD_DELETE ) {
2386 /* Reset to defaults or values from frontend */
2387 if ( c->be == frontendDB ) {
2388 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
2389 lim->lms_s_hard = 0;
2390 lim->lms_s_unchecked = -1;
2392 lim->lms_s_pr_hide = 0;
2393 lim->lms_s_pr_total = 0;
2395 lim->lms_s_soft = frontendDB->be_def_limit.lms_s_soft;
2396 lim->lms_s_hard = frontendDB->be_def_limit.lms_s_hard;
2397 lim->lms_s_unchecked = frontendDB->be_def_limit.lms_s_unchecked;
2398 lim->lms_s_pr = frontendDB->be_def_limit.lms_s_pr;
2399 lim->lms_s_pr_hide = frontendDB->be_def_limit.lms_s_pr_hide;
2400 lim->lms_s_pr_total = frontendDB->be_def_limit.lms_s_pr_total;
2404 for(i = 1; i < c->argc; i++) {
2405 if(!strncasecmp(c->argv[i], "size", 4)) {
2406 rc = limits_parse_one(c->argv[i], lim);
2408 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2409 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2410 c->log, c->cr_msg, c->argv[i]);
2414 if(!strcasecmp(c->argv[i], "unlimited")) {
2415 lim->lms_s_soft = -1;
2417 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
2418 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2419 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2420 c->log, c->cr_msg, c->argv[i]);
2424 lim->lms_s_hard = 0;
2429 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2430 /* This is a modification to the global limits apply it to
2431 * the other databases as needed */
2432 AttributeDescription *ad=NULL;
2433 const char *text = NULL;
2434 CfEntryInfo *ce = c->ca_entry->e_private;
2436 slap_str2ad(c->argv[0], &ad, &text);
2437 /* if we got here... */
2438 assert( ad != NULL );
2440 if ( ce->ce_type == Cft_Global ){
2443 for (; ce; ce=ce->ce_sibs) {
2444 Entry *dbe = ce->ce_entry;
2445 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2446 && (!attr_find(dbe->e_attrs, ad)) ) {
2447 ce->ce_be->be_def_limit.lms_s_soft = lim->lms_s_soft;
2448 ce->ce_be->be_def_limit.lms_s_hard = lim->lms_s_hard;
2449 ce->ce_be->be_def_limit.lms_s_unchecked =lim->lms_s_unchecked;
2450 ce->ce_be->be_def_limit.lms_s_pr =lim->lms_s_pr;
2451 ce->ce_be->be_def_limit.lms_s_pr_hide =lim->lms_s_pr_hide;
2452 ce->ce_be->be_def_limit.lms_s_pr_total =lim->lms_s_pr_total;
2460 config_timelimit(ConfigArgs *c) {
2462 struct slap_limits_set *lim = &c->be->be_def_limit;
2463 if (c->op == SLAP_CONFIG_EMIT) {
2468 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
2469 if ( !BER_BVISEMPTY( &bv ))
2470 value_add_one( &c->rvalue_vals, &bv );
2474 } else if ( c->op == LDAP_MOD_DELETE ) {
2475 /* Reset to defaults or values from frontend */
2476 if ( c->be == frontendDB ) {
2477 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
2478 lim->lms_t_hard = 0;
2480 lim->lms_t_soft = frontendDB->be_def_limit.lms_t_soft;
2481 lim->lms_t_hard = frontendDB->be_def_limit.lms_t_hard;
2485 for(i = 1; i < c->argc; i++) {
2486 if(!strncasecmp(c->argv[i], "time", 4)) {
2487 rc = limits_parse_one(c->argv[i], lim);
2489 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2490 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2491 c->log, c->cr_msg, c->argv[i]);
2495 if(!strcasecmp(c->argv[i], "unlimited")) {
2496 lim->lms_t_soft = -1;
2498 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
2499 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2500 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2501 c->log, c->cr_msg, c->argv[i]);
2505 lim->lms_t_hard = 0;
2510 if ( ( c->be == frontendDB ) && ( c->ca_entry ) ) {
2511 /* This is a modification to the global limits apply it to
2512 * the other databases as needed */
2513 AttributeDescription *ad=NULL;
2514 const char *text = NULL;
2515 CfEntryInfo *ce = c->ca_entry->e_private;
2517 slap_str2ad(c->argv[0], &ad, &text);
2518 /* if we got here... */
2519 assert( ad != NULL );
2521 if ( ce->ce_type == Cft_Global ){
2524 for (; ce; ce=ce->ce_sibs) {
2525 Entry *dbe = ce->ce_entry;
2526 if ( (ce->ce_type == Cft_Database) && (ce->ce_be != frontendDB)
2527 && (!attr_find(dbe->e_attrs, ad)) ) {
2528 ce->ce_be->be_def_limit.lms_t_soft = lim->lms_t_soft;
2529 ce->ce_be->be_def_limit.lms_t_hard = lim->lms_t_hard;
2537 config_overlay(ConfigArgs *c) {
2538 if (c->op == SLAP_CONFIG_EMIT) {
2540 } else if ( c->op == LDAP_MOD_DELETE ) {
2543 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2544 c->valx, &c->bi, &c->reply)) {
2546 Debug( LDAP_DEBUG_ANY,
2547 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2548 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2550 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi, &c->reply)) {
2557 config_subordinate(ConfigArgs *c)
2563 case SLAP_CONFIG_EMIT:
2564 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2567 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2568 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2571 value_add_one( &c->rvalue_vals, &bv );
2575 case LDAP_MOD_DELETE:
2576 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2577 glue_sub_del( c->be );
2579 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2584 case SLAP_CONFIG_ADD:
2585 if ( c->be->be_nsuffix == NULL ) {
2587 snprintf( c->cr_msg, sizeof( c->cr_msg),
2588 "subordinate configuration needs a suffix" );
2589 Debug( LDAP_DEBUG_ANY,
2591 c->log, c->cr_msg, 0 );
2596 if ( c->argc == 2 ) {
2597 if ( strcasecmp( c->argv[1], "advertise" ) == 0 ) {
2600 } else if ( strcasecmp( c->argv[1], "TRUE" ) != 0 ) {
2602 snprintf( c->cr_msg, sizeof( c->cr_msg),
2603 "subordinate must be \"TRUE\" or \"advertise\"" );
2604 Debug( LDAP_DEBUG_ANY,
2605 "%s: suffix \"%s\": %s.\n",
2606 c->log, c->be->be_suffix[0].bv_val, c->cr_msg );
2612 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2620 * [listener=<listener>] [{read|write}=]<size>
2623 #ifdef LDAP_TCP_BUFFER
2624 static BerVarray tcp_buffer;
2627 #define SLAP_TCP_RMEM (0x1U)
2628 #define SLAP_TCP_WMEM (0x2U)
2631 tcp_buffer_parse( struct berval *val, int argc, char **argv,
2632 int *size, int *rw, Listener **l )
2634 int i, rc = LDAP_SUCCESS;
2635 LDAPURLDesc *lud = NULL;
2638 if ( val != NULL && argv == NULL ) {
2639 char *s = val->bv_val;
2641 argv = ldap_str2charray( s, " \t" );
2642 if ( argv == NULL ) {
2648 if ( strncasecmp( argv[ i ], "listener=", STRLENOF( "listener=" ) )
2651 char *url = argv[ i ] + STRLENOF( "listener=" );
2653 if ( ldap_url_parse( url, &lud ) ) {
2654 rc = LDAP_INVALID_SYNTAX;
2658 *l = config_check_my_url( url, lud );
2660 rc = LDAP_NO_SUCH_ATTRIBUTE;
2668 if ( strncasecmp( ptr, "read=", STRLENOF( "read=" ) ) == 0 ) {
2669 *rw |= SLAP_TCP_RMEM;
2670 ptr += STRLENOF( "read=" );
2672 } else if ( strncasecmp( ptr, "write=", STRLENOF( "write=" ) ) == 0 ) {
2673 *rw |= SLAP_TCP_WMEM;
2674 ptr += STRLENOF( "write=" );
2677 *rw |= ( SLAP_TCP_RMEM | SLAP_TCP_WMEM );
2680 /* accept any base */
2681 if ( lutil_atoix( size, ptr, 0 ) ) {
2682 rc = LDAP_INVALID_SYNTAX;
2687 if ( val != NULL && argv != NULL ) {
2688 ldap_charray_free( argv );
2691 if ( lud != NULL ) {
2692 ldap_free_urldesc( lud );
2699 tcp_buffer_delete_one( struct berval *val )
2702 int size = -1, rw = 0;
2705 rc = tcp_buffer_parse( val, 0, NULL, &size, &rw, &l );
2712 Listener **ll = slapd_get_listeners();
2714 for ( i = 0; ll[ i ] != NULL; i++ ) {
2715 if ( ll[ i ] == l ) break;
2718 if ( ll[ i ] == NULL ) {
2719 return LDAP_NO_SUCH_ATTRIBUTE;
2722 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = -1;
2723 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = -1;
2725 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2726 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = -1;
2727 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = -1;
2731 /* NOTE: this affects listeners without a specific setting,
2732 * does not reset all listeners. If a listener without
2733 * specific settings was assigned a buffer because of
2734 * a global setting, it will not be reset. In any case,
2735 * buffer changes will only take place at restart. */
2736 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = -1;
2737 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = -1;
2744 tcp_buffer_delete( BerVarray vals )
2748 for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
2749 tcp_buffer_delete_one( &vals[ i ] );
2756 tcp_buffer_unparse( int size, int rw, Listener *l, struct berval *val )
2758 char buf[sizeof("2147483648")], *ptr;
2760 /* unparse for later use */
2761 val->bv_len = snprintf( buf, sizeof( buf ), "%d", size );
2763 val->bv_len += STRLENOF( "listener=" " " ) + l->sl_url.bv_len;
2766 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2767 if ( rw & SLAP_TCP_RMEM ) {
2768 val->bv_len += STRLENOF( "read=" );
2769 } else if ( rw & SLAP_TCP_WMEM ) {
2770 val->bv_len += STRLENOF( "write=" );
2774 val->bv_val = SLAP_MALLOC( val->bv_len + 1 );
2779 ptr = lutil_strcopy( ptr, "listener=" );
2780 ptr = lutil_strncopy( ptr, l->sl_url.bv_val, l->sl_url.bv_len );
2784 if ( rw != ( SLAP_TCP_RMEM | SLAP_TCP_WMEM ) ) {
2785 if ( rw & SLAP_TCP_RMEM ) {
2786 ptr = lutil_strcopy( ptr, "read=" );
2787 } else if ( rw & SLAP_TCP_WMEM ) {
2788 ptr = lutil_strcopy( ptr, "write=" );
2792 ptr = lutil_strcopy( ptr, buf );
2795 assert( val->bv_val + val->bv_len == ptr );
2797 return LDAP_SUCCESS;
2801 tcp_buffer_add_one( int argc, char **argv )
2804 int size = -1, rw = 0;
2810 rc = tcp_buffer_parse( NULL, argc, argv, &size, &rw, &l );
2815 /* unparse for later use */
2816 rc = tcp_buffer_unparse( size, rw, l, &val );
2817 if ( rc != LDAP_SUCCESS ) {
2821 /* use parsed values */
2824 Listener **ll = slapd_get_listeners();
2826 for ( i = 0; ll[ i ] != NULL; i++ ) {
2827 if ( ll[ i ] == l ) break;
2830 if ( ll[ i ] == NULL ) {
2831 return LDAP_NO_SUCH_ATTRIBUTE;
2834 /* buffer only applies to TCP listeners;
2835 * we do not do any check here, and delegate them
2836 * to setsockopt(2) */
2837 if ( rw & SLAP_TCP_RMEM ) l->sl_tcp_rmem = size;
2838 if ( rw & SLAP_TCP_WMEM ) l->sl_tcp_wmem = size;
2840 for ( i++ ; ll[ i ] != NULL && bvmatch( &l->sl_url, &ll[ i ]->sl_url ); i++ ) {
2841 if ( rw & SLAP_TCP_RMEM ) ll[ i ]->sl_tcp_rmem = size;
2842 if ( rw & SLAP_TCP_WMEM ) ll[ i ]->sl_tcp_wmem = size;
2846 /* NOTE: this affects listeners without a specific setting,
2847 * does not set all listeners */
2848 if ( rw & SLAP_TCP_RMEM ) slapd_tcp_rmem = size;
2849 if ( rw & SLAP_TCP_WMEM ) slapd_tcp_wmem = size;
2852 tcp_buffer = SLAP_REALLOC( tcp_buffer, sizeof( struct berval ) * ( tcp_buffer_num + 2 ) );
2854 tcp_buffer[ tcp_buffer_num ] = val;
2857 BER_BVZERO( &tcp_buffer[ tcp_buffer_num ] );
2863 config_tcp_buffer( ConfigArgs *c )
2865 if ( c->op == SLAP_CONFIG_EMIT ) {
2866 if ( tcp_buffer == NULL || BER_BVISNULL( &tcp_buffer[ 0 ] ) ) {
2869 value_add( &c->rvalue_vals, tcp_buffer );
2870 value_add( &c->rvalue_nvals, tcp_buffer );
2872 } else if ( c->op == LDAP_MOD_DELETE ) {
2874 tcp_buffer_delete( tcp_buffer );
2875 ber_bvarray_free( tcp_buffer );
2881 int size = -1, rw = 0;
2884 struct berval val = BER_BVNULL;
2888 if ( tcp_buffer_num == 0 ) {
2893 rc = tcp_buffer_parse( NULL, c->argc - 1, &c->argv[ 1 ], &size, &rw, &l );
2898 /* unparse for later use */
2899 rc = tcp_buffer_unparse( size, rw, l, &val );
2900 if ( rc != LDAP_SUCCESS ) {
2904 for ( i = 0; !BER_BVISNULL( &tcp_buffer[ i ] ); i++ ) {
2905 if ( bvmatch( &tcp_buffer[ i ], &val ) ) {
2910 if ( BER_BVISNULL( &tcp_buffer[ i ] ) ) {
2916 tcp_buffer_delete_one( &tcp_buffer[ i ] );
2917 ber_memfree( tcp_buffer[ i ].bv_val );
2918 for ( ; i < tcp_buffer_num; i++ ) {
2919 tcp_buffer[ i ] = tcp_buffer[ i + 1 ];
2924 if ( !BER_BVISNULL( &val ) ) {
2925 SLAP_FREE( val.bv_val );
2933 rc = tcp_buffer_add_one( c->argc - 1, &c->argv[ 1 ] );
2935 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2936 "<%s> unable to add value #%d",
2937 c->argv[0], tcp_buffer_num );
2938 Debug( LDAP_DEBUG_ANY, "%s: %s\n",
2939 c->log, c->cr_msg, 0 );
2946 #endif /* LDAP_TCP_BUFFER */
2949 config_suffix(ConfigArgs *c)
2952 struct berval pdn, ndn;
2953 char *notallowed = NULL;
2955 if ( c->be == frontendDB ) {
2956 notallowed = "frontend";
2958 } else if ( SLAP_MONITOR(c->be) ) {
2959 notallowed = "monitor";
2961 } else if ( SLAP_CONFIG(c->be) ) {
2962 notallowed = "config";
2965 if ( notallowed != NULL ) {
2966 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
2970 case LDAP_MOD_DELETE:
2971 case LDAP_MOD_REPLACE:
2972 case LDAP_MOD_INCREMENT:
2973 case SLAP_CONFIG_ADD:
2974 if ( !BER_BVISNULL( &c->value_dn ) ) {
2975 snprintf( buf, sizeof( buf ), "<%s> ",
2976 c->value_dn.bv_val );
2979 Debug(LDAP_DEBUG_ANY,
2980 "%s: suffix %snot allowed in %s database.\n",
2981 c->log, buf, notallowed );
2984 case SLAP_CONFIG_EMIT:
2985 /* don't complain when emitting... */
2989 /* FIXME: don't know what values may be valid;
2990 * please remove assertion, or add legal values
2991 * to either block */
2999 if (c->op == SLAP_CONFIG_EMIT) {
3000 if ( c->be->be_suffix == NULL
3001 || BER_BVISNULL( &c->be->be_suffix[0] ) )
3005 value_add( &c->rvalue_vals, c->be->be_suffix );
3006 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
3009 } else if ( c->op == LDAP_MOD_DELETE ) {
3010 if ( c->valx < 0 ) {
3011 ber_bvarray_free( c->be->be_suffix );
3012 ber_bvarray_free( c->be->be_nsuffix );
3013 c->be->be_suffix = NULL;
3014 c->be->be_nsuffix = NULL;
3017 ch_free( c->be->be_suffix[i].bv_val );
3018 ch_free( c->be->be_nsuffix[i].bv_val );
3020 c->be->be_suffix[i] = c->be->be_suffix[i+1];
3021 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
3023 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
3028 #ifdef SLAPD_MONITOR_DN
3029 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
3030 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> DN is reserved for monitoring slapd",
3032 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3033 c->log, c->cr_msg, SLAPD_MONITOR_DN);
3038 if (SLAP_DB_ONE_SUFFIX( c->be ) && c->be->be_suffix ) {
3039 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> Only one suffix is allowed on this %s backend",
3040 c->argv[0], c->be->bd_info->bi_type );
3041 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3042 c->log, c->cr_msg, 0);
3049 if (SLAP_DBHIDDEN( c->be ))
3052 tbe = select_backend(&ndn, 0);
3054 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
3060 BackendDB *b2 = tbe;
3062 /* Does tbe precede be? */
3063 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
3066 char *type = tbe->bd_info->bi_type;
3068 if ( overlay_is_over( tbe ) ) {
3069 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
3070 type = oi->oi_orig->bi_type;
3073 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> namingContext \"%s\" "
3074 "already served by a preceding %s database",
3075 c->argv[0], pdn.bv_val, type );
3076 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
3077 c->log, c->cr_msg, tbe->be_suffix[0].bv_val);
3083 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
3084 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
3085 "base provided \"%s\" (assuming okay)\n",
3086 c->log, default_search_base.bv_val, 0);
3088 ber_bvarray_add(&c->be->be_suffix, &pdn);
3089 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
3094 config_rootdn(ConfigArgs *c) {
3095 if (c->op == SLAP_CONFIG_EMIT) {
3096 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
3097 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
3098 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
3103 } else if ( c->op == LDAP_MOD_DELETE ) {
3104 ch_free( c->be->be_rootdn.bv_val );
3105 ch_free( c->be->be_rootndn.bv_val );
3106 BER_BVZERO( &c->be->be_rootdn );
3107 BER_BVZERO( &c->be->be_rootndn );
3110 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
3111 ch_free( c->be->be_rootdn.bv_val );
3112 ch_free( c->be->be_rootndn.bv_val );
3114 c->be->be_rootdn = c->value_dn;
3115 c->be->be_rootndn = c->value_ndn;
3120 config_rootpw(ConfigArgs *c) {
3123 if (c->op == SLAP_CONFIG_EMIT) {
3124 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
3125 /* don't copy, because "rootpw" is marked
3127 c->value_bv = c->be->be_rootpw;
3131 } else if ( c->op == LDAP_MOD_DELETE ) {
3132 ch_free( c->be->be_rootpw.bv_val );
3133 BER_BVZERO( &c->be->be_rootpw );
3137 tbe = select_backend(&c->be->be_rootndn, 0);
3139 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> can only be set when rootdn is under suffix",
3141 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3142 c->log, c->cr_msg, 0);
3145 if ( !BER_BVISNULL( &c->be->be_rootpw ))
3146 ch_free( c->be->be_rootpw.bv_val );
3147 c->be->be_rootpw = c->value_bv;
3152 config_restrict(ConfigArgs *c) {
3153 slap_mask_t restrictops = 0;
3155 slap_verbmasks restrictable_ops[] = {
3156 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
3157 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
3158 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
3159 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
3160 { BER_BVC("modrdn"), 0 },
3161 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
3162 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
3163 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
3164 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
3165 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
3166 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
3167 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
3168 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
3169 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
3170 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
3171 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
3175 if (c->op == SLAP_CONFIG_EMIT) {
3176 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
3178 } else if ( c->op == LDAP_MOD_DELETE ) {
3180 c->be->be_restrictops = 0;
3182 restrictops = verb_to_mask( c->line, restrictable_ops );
3183 c->be->be_restrictops ^= restrictops;
3187 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
3189 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown operation", c->argv[0] );
3190 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3191 c->log, c->cr_msg, c->argv[i]);
3194 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
3195 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
3196 c->be->be_restrictops |= restrictops;
3201 config_allows(ConfigArgs *c) {
3202 slap_mask_t allows = 0;
3204 slap_verbmasks allowable_ops[] = {
3205 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
3206 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
3207 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
3208 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
3209 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
3212 if (c->op == SLAP_CONFIG_EMIT) {
3213 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
3214 } else if ( c->op == LDAP_MOD_DELETE ) {
3218 allows = verb_to_mask( c->line, allowable_ops );
3219 global_allows ^= allows;
3223 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
3225 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3226 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3227 c->log, c->cr_msg, c->argv[i]);
3230 global_allows |= allows;
3235 config_disallows(ConfigArgs *c) {
3236 slap_mask_t disallows = 0;
3238 slap_verbmasks disallowable_ops[] = {
3239 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
3240 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
3241 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
3242 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
3243 { BER_BVC("proxy_authz_non_critical"), SLAP_DISALLOW_PROXY_AUTHZ_N_CRIT },
3244 { BER_BVC("dontusecopy_non_critical"), SLAP_DISALLOW_DONTUSECOPY_N_CRIT },
3247 if (c->op == SLAP_CONFIG_EMIT) {
3248 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
3249 } else if ( c->op == LDAP_MOD_DELETE ) {
3251 global_disallows = 0;
3253 disallows = verb_to_mask( c->line, disallowable_ops );
3254 global_disallows ^= disallows;
3258 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
3260 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
3261 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3262 c->log, c->cr_msg, c->argv[i]);
3265 global_disallows |= disallows;
3270 config_requires(ConfigArgs *c) {
3271 slap_mask_t requires = frontendDB->be_requires;
3272 int i, argc = c->argc;
3273 char **argv = c->argv;
3275 slap_verbmasks requires_ops[] = {
3276 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
3277 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
3278 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
3279 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
3280 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
3283 if (c->op == SLAP_CONFIG_EMIT) {
3284 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
3285 } else if ( c->op == LDAP_MOD_DELETE ) {
3287 c->be->be_requires = 0;
3289 requires = verb_to_mask( c->line, requires_ops );
3290 c->be->be_requires ^= requires;
3294 /* "none" can only be first, to wipe out default/global values */
3295 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
3300 i = verbs_to_mask(argc, argv, requires_ops, &requires);
3302 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
3303 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
3304 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3305 c->log, c->cr_msg, 0);
3307 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
3308 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3309 c->log, c->cr_msg, c->argv[i]);
3313 c->be->be_requires = requires;
3318 config_extra_attrs(ConfigArgs *c)
3320 assert( c->be != NULL );
3322 if ( c->op == SLAP_CONFIG_EMIT ) {
3325 if ( c->be->be_extra_anlist == NULL ) {
3329 for ( i = 0; !BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ); i++ ) {
3330 value_add_one( &c->rvalue_vals, &c->be->be_extra_anlist[i].an_name );
3333 } else if ( c->op == LDAP_MOD_DELETE ) {
3334 if ( c->be->be_extra_anlist == NULL ) {
3338 if ( c->valx < 0 ) {
3339 anlist_free( c->be->be_extra_anlist, 1, NULL );
3340 c->be->be_extra_anlist = NULL;
3345 for ( i = 0; i < c->valx && !BER_BVISNULL( &c->be->be_extra_anlist[i + 1].an_name ); i++ )
3348 if ( BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ) ) {
3352 ch_free( c->be->be_extra_anlist[i].an_name.bv_val );
3354 for ( ; !BER_BVISNULL( &c->be->be_extra_anlist[i].an_name ); i++ ) {
3355 c->be->be_extra_anlist[i] = c->be->be_extra_anlist[i + 1];
3360 c->be->be_extra_anlist = str2anlist( c->be->be_extra_anlist, c->argv[1], " ,\t" );
3361 if ( c->be->be_extra_anlist == NULL ) {
3369 static slap_verbmasks *loglevel_ops;
3372 loglevel_init( void )
3374 slap_verbmasks lo[] = {
3375 { BER_BVC("Any"), (slap_mask_t) LDAP_DEBUG_ANY },
3376 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
3377 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
3378 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
3379 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
3380 { BER_BVC("BER"), LDAP_DEBUG_BER },
3381 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
3382 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
3383 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
3384 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
3385 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
3386 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
3387 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
3388 #if 0 /* no longer used (nor supported) */
3389 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
3390 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
3392 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
3393 { BER_BVC("None"), LDAP_DEBUG_NONE },
3397 return slap_verbmasks_init( &loglevel_ops, lo );
3401 loglevel_destroy( void )
3403 if ( loglevel_ops ) {
3404 (void)slap_verbmasks_destroy( loglevel_ops );
3406 loglevel_ops = NULL;
3409 static slap_mask_t loglevel_ignore[] = { -1, 0 };
3412 slap_loglevel_register( slap_mask_t m, struct berval *s )
3416 if ( loglevel_ops == NULL ) {
3420 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
3423 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
3431 slap_loglevel_get( struct berval *s, int *l )
3436 if ( loglevel_ops == NULL ) {
3440 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3441 m |= loglevel_ops[ i ].mask;
3444 for ( i = 1; m & i; i <<= 1 )
3451 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
3454 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
3465 str2loglevel( const char *s, int *l )
3469 if ( loglevel_ops == NULL ) {
3473 i = verb_to_mask( s, loglevel_ops );
3475 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
3479 *l = loglevel_ops[ i ].mask;
3485 loglevel2str( int l )
3487 struct berval bv = BER_BVNULL;
3489 loglevel2bv( l, &bv );
3495 loglevel2bv( int l, struct berval *bv )
3497 if ( loglevel_ops == NULL ) {
3503 return enum_to_verb( loglevel_ops, l, bv ) == -1;
3507 loglevel2bvarray( int l, BerVarray *bva )
3509 if ( loglevel_ops == NULL ) {
3513 return mask_to_verbs( loglevel_ops, l, bva );
3517 loglevel_print( FILE *out )
3521 if ( loglevel_ops == NULL ) {
3525 fprintf( out, "Installed log subsystems:\n\n" );
3526 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
3527 unsigned mask = loglevel_ops[ i ].mask & 0xffffffffUL;
3529 (mask == ((slap_mask_t) -1 & 0xffffffffUL)
3530 ? "\t%-30s (-1, 0xffffffff)\n" : "\t%-30s (%u, 0x%x)\n"),
3531 loglevel_ops[ i ].word.bv_val, mask, mask );
3534 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
3535 "by specific code\n\n" );
3540 static int config_syslog;
3543 config_loglevel(ConfigArgs *c) {
3546 if ( loglevel_ops == NULL ) {
3550 if (c->op == SLAP_CONFIG_EMIT) {
3551 /* Get default or commandline slapd setting */
3552 if ( ldap_syslog && !config_syslog )
3553 config_syslog = ldap_syslog;
3554 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
3556 } else if ( c->op == LDAP_MOD_DELETE ) {
3560 int level = verb_to_mask( c->line, loglevel_ops );
3561 config_syslog ^= level;
3563 if ( slapMode & SLAP_SERVER_MODE ) {
3564 ldap_syslog = config_syslog;
3569 for( i=1; i < c->argc; i++ ) {
3572 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
3573 if( lutil_atoix( &level, c->argv[i], 0 ) != 0 ) {
3574 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse level", c->argv[0] );
3575 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3576 c->log, c->cr_msg, c->argv[i]);
3580 if ( str2loglevel( c->argv[i], &level ) ) {
3581 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown level", c->argv[0] );
3582 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3583 c->log, c->cr_msg, c->argv[i]);
3587 /* Explicitly setting a zero clears all the levels */
3589 config_syslog |= level;
3593 if ( slapMode & SLAP_SERVER_MODE ) {
3594 ldap_syslog = config_syslog;
3600 config_referral(ConfigArgs *c) {
3602 if (c->op == SLAP_CONFIG_EMIT) {
3603 if ( default_referral ) {
3604 value_add( &c->rvalue_vals, default_referral );
3609 } else if ( c->op == LDAP_MOD_DELETE ) {
3610 if ( c->valx < 0 ) {
3611 ber_bvarray_free( default_referral );
3612 default_referral = NULL;
3615 ch_free( default_referral[i].bv_val );
3616 for (; default_referral[i].bv_val; i++ )
3617 default_referral[i] = default_referral[i+1];
3621 if(validate_global_referral(c->argv[1])) {
3622 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3623 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3624 c->log, c->cr_msg, c->argv[1]);
3628 ber_str2bv(c->argv[1], 0, 0, &val);
3629 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
3637 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
3638 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
3639 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
3640 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
3641 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
3642 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
3643 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
3644 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
3645 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
3650 config_security(ConfigArgs *c) {
3651 slap_ssf_set_t *set = &c->be->be_ssf_set;
3654 if (c->op == SLAP_CONFIG_EMIT) {
3660 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
3661 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
3664 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
3665 if ( bv.bv_len >= sizeof( numbuf ) ) {
3666 ber_bvarray_free_x( c->rvalue_vals, NULL );
3667 c->rvalue_vals = NULL;
3671 bv.bv_len += sec_keys[i].key.bv_len;
3672 bv.bv_val = ch_malloc( bv.bv_len + 1);
3673 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
3674 strcpy( next, numbuf );
3675 ber_bvarray_add( &c->rvalue_vals, &bv );
3680 for(i = 1; i < c->argc; i++) {
3681 slap_ssf_t *tgt = NULL;
3683 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
3684 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
3685 sec_keys[j].key.bv_len)) {
3686 src = c->argv[i] + sec_keys[j].key.bv_len;
3687 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
3692 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown factor", c->argv[0] );
3693 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3694 c->log, c->cr_msg, c->argv[i]);
3698 if ( lutil_atou( tgt, src ) != 0 ) {
3699 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse factor", c->argv[0] );
3700 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3701 c->log, c->cr_msg, c->argv[i]);
3709 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
3713 for (; !BER_BVISNULL( &an->an_name ); an++) {
3714 /* if buflen == 0, assume the buffer size has been
3715 * already checked otherwise */
3716 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
3717 if ( comma ) *ptr++ = ',';
3718 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
3725 config_updatedn(ConfigArgs *c) {
3726 if (c->op == SLAP_CONFIG_EMIT) {
3727 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
3728 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
3729 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
3733 } else if ( c->op == LDAP_MOD_DELETE ) {
3734 ch_free( c->be->be_update_ndn.bv_val );
3735 BER_BVZERO( &c->be->be_update_ndn );
3736 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
3739 if(SLAP_SHADOW(c->be)) {
3740 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database already shadowed", c->argv[0] );
3741 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3742 c->log, c->cr_msg, 0);
3746 ber_memfree_x( c->value_dn.bv_val, NULL );
3747 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
3748 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
3750 c->be->be_update_ndn = c->value_ndn;
3751 BER_BVZERO( &c->value_dn );
3752 BER_BVZERO( &c->value_ndn );
3754 return config_slurp_shadow( c );
3758 config_shadow( ConfigArgs *c, slap_mask_t flag )
3760 char *notallowed = NULL;
3762 if ( c->be == frontendDB ) {
3763 notallowed = "frontend";
3765 } else if ( SLAP_MONITOR(c->be) ) {
3766 notallowed = "monitor";
3769 if ( notallowed != NULL ) {
3770 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
3774 if ( SLAP_SHADOW(c->be) ) {
3775 /* if already shadow, only check consistency */
3776 if ( ( SLAP_DBFLAGS(c->be) & flag ) != flag ) {
3777 Debug( LDAP_DEBUG_ANY, "%s: inconsistent shadow flag 0x%lx.\n",
3783 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SINGLE_SHADOW | flag);
3790 config_updateref(ConfigArgs *c) {
3792 if (c->op == SLAP_CONFIG_EMIT) {
3793 if ( c->be->be_update_refs ) {
3794 value_add( &c->rvalue_vals, c->be->be_update_refs );
3799 } else if ( c->op == LDAP_MOD_DELETE ) {
3800 if ( c->valx < 0 ) {
3801 ber_bvarray_free( c->be->be_update_refs );
3802 c->be->be_update_refs = NULL;
3805 ch_free( c->be->be_update_refs[i].bv_val );
3806 for (; c->be->be_update_refs[i].bv_val; i++)
3807 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
3811 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
3812 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must appear after syncrepl or updatedn",
3814 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3815 c->log, c->cr_msg, 0);
3819 if(validate_global_referral(c->argv[1])) {
3820 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3821 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3822 c->log, c->cr_msg, c->argv[1]);
3825 ber_str2bv(c->argv[1], 0, 0, &val);
3826 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
3831 config_obsolete(ConfigArgs *c) {
3832 if (c->op == SLAP_CONFIG_EMIT)
3835 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> keyword is obsolete (ignored)",
3837 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0);
3842 config_include(ConfigArgs *c) {
3843 int savelineno = c->lineno;
3846 ConfigFile *cfsave = cfn;
3847 ConfigFile *cf2 = NULL;
3849 /* Leftover from RE23. No dynamic config for include files */
3850 if ( c->op == SLAP_CONFIG_EMIT || c->op == LDAP_MOD_DELETE )
3853 cf = ch_calloc( 1, sizeof(ConfigFile));
3854 if ( cfn->c_kids ) {
3855 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
3861 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
3862 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
3863 c->lineno = savelineno - 1;
3866 if ( cf2 ) cf2->c_sibs = NULL;
3867 else cfn->c_kids = NULL;
3868 ch_free( cf->c_file.bv_val );
3878 config_tls_cleanup(ConfigArgs *c) {
3881 if ( slap_tls_ld ) {
3884 ldap_pvt_tls_ctx_free( slap_tls_ctx );
3886 /* Force new ctx to be created */
3887 rc = ldap_pvt_tls_set_option( slap_tls_ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
3889 /* The ctx's refcount is bumped up here */
3890 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CTX, &slap_tls_ctx );
3891 /* This is a no-op if it's already loaded */
3892 load_extop( &slap_EXOP_START_TLS, 0, starttls_extop );
3899 config_tls_option(ConfigArgs *c) {
3901 LDAP *ld = slap_tls_ld;
3903 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
3904 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
3905 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
3906 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
3907 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
3908 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
3909 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
3911 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
3913 default: Debug(LDAP_DEBUG_ANY, "%s: "
3914 "unknown tls_option <0x%x>\n",
3915 c->log, c->type, 0);
3918 if (c->op == SLAP_CONFIG_EMIT) {
3919 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
3920 } else if ( c->op == LDAP_MOD_DELETE ) {
3921 c->cleanup = config_tls_cleanup;
3922 return ldap_pvt_tls_set_option( ld, flag, NULL );
3924 ch_free(c->value_string);
3925 c->cleanup = config_tls_cleanup;
3926 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
3929 /* FIXME: this ought to be provided by libldap */
3931 config_tls_config(ConfigArgs *c) {
3934 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
3935 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
3936 case CFG_TLS_PROTOCOL_MIN: flag = LDAP_OPT_X_TLS_PROTOCOL_MIN; break;
3938 Debug(LDAP_DEBUG_ANY, "%s: "
3939 "unknown tls_option <0x%x>\n",
3940 c->log, c->type, 0);
3943 if (c->op == SLAP_CONFIG_EMIT) {
3944 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
3945 } else if ( c->op == LDAP_MOD_DELETE ) {
3947 c->cleanup = config_tls_cleanup;
3948 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
3950 ch_free( c->value_string );
3951 c->cleanup = config_tls_cleanup;
3952 if ( isdigit( (unsigned char)c->argv[1][0] ) ) {
3953 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
3954 Debug(LDAP_DEBUG_ANY, "%s: "
3955 "unable to parse %s \"%s\"\n",
3956 c->log, c->argv[0], c->argv[1] );
3959 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
3961 return(ldap_pvt_tls_config(slap_tls_ld, flag, c->argv[1]));
3966 static CfEntryInfo *
3967 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
3977 if ( dn_match( &root->ce_entry->e_nname, dn ))
3980 c = dn->bv_val+dn->bv_len;
3981 for (;*c != ',';c--);
3985 for (--c;c>dn->bv_val && *c != ',';c--);
3989 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
3991 root = root->ce_kids;
3993 for (;root;root=root->ce_sibs) {
3994 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
3995 if ( cdn.bv_val == dn->bv_val ) {
4005 typedef struct setup_cookie {
4015 config_ldif_resp( Operation *op, SlapReply *rs )
4017 if ( rs->sr_type == REP_SEARCH ) {
4018 setup_cookie *sc = op->o_callback->sc_private;
4021 sc->cfb->cb_got_ldif = 1;
4022 /* Does the frontend exist? */
4023 if ( !sc->got_frontend ) {
4024 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
4025 "olcDatabase", STRLENOF( "olcDatabase" )))
4027 if ( strncmp( rs->sr_entry->e_nname.bv_val +
4028 STRLENOF( "olcDatabase" ), "={-1}frontend",
4029 STRLENOF( "={-1}frontend" )))
4033 sc->ca->be = frontendDB;
4034 sc->ca->bi = frontendDB->bd_info;
4035 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
4036 rdn.bv_val = sc->ca->log;
4037 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
4038 "%s=" SLAP_X_ORDERED_FMT "%s",
4039 cfAd_database->ad_cname.bv_val, -1,
4040 sc->ca->bi->bi_type);
4042 sc->frontend = config_build_entry( op, rs,
4043 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
4044 sc->ca->be->be_cf_ocs );
4054 dnParent( &rs->sr_entry->e_nname, &pdn );
4056 /* Does the configDB exist? */
4057 if ( sc->got_frontend && !sc->got_config &&
4058 !strncmp( rs->sr_entry->e_nname.bv_val,
4059 "olcDatabase", STRLENOF( "olcDatabase" )) &&
4060 dn_match( &config_rdn, &pdn ) )
4062 if ( strncmp( rs->sr_entry->e_nname.bv_val +
4063 STRLENOF( "olcDatabase" ), "={0}config",
4064 STRLENOF( "={0}config" )))
4068 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
4069 sc->ca->bi = sc->ca->be->bd_info;
4070 rdn.bv_val = sc->ca->log;
4071 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
4072 "%s=" SLAP_X_ORDERED_FMT "%s",
4073 cfAd_database->ad_cname.bv_val, 0,
4074 sc->ca->bi->bi_type);
4076 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
4077 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
4084 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
4085 if ( rs->sr_err != LDAP_SUCCESS ) {
4086 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
4087 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg, 0 );
4093 /* Configure and read the underlying back-ldif store */
4095 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
4096 CfBackInfo *cfb = be->be_private;
4102 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
4103 Connection conn = {0};
4104 OperationBuffer opbuf;
4106 SlapReply rs = {REP_RESULT};
4107 Filter filter = { LDAP_FILTER_PRESENT };
4108 struct berval filterstr = BER_BVC("(objectclass=*)");
4111 /* Is the config directory available? */
4112 if ( stat( dir, &st ) < 0 ) {
4113 /* No, so don't bother using the backing store.
4114 * All changes will be in-memory only.
4119 cfb->cb_db.bd_info = backend_info( "ldif" );
4120 if ( !cfb->cb_db.bd_info )
4121 return 0; /* FIXME: eventually this will be a fatal error */
4123 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
4126 cfb->cb_db.be_suffix = be->be_suffix;
4127 cfb->cb_db.be_nsuffix = be->be_nsuffix;
4129 /* The suffix is always "cn=config". The underlying DB's rootdn
4130 * is always the same as the suffix.
4132 cfb->cb_db.be_rootdn = be->be_suffix[0];
4133 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
4135 ber_str2bv( dir, 0, 1, &cfdir );
4140 argv[0] = "directory";
4141 argv[1] = (char *)dir;
4146 c.table = Cft_Database;
4148 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
4152 if ( config_add_vals( ct, &c ))
4155 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
4159 void *thrctx = ldap_pvt_thread_pool_context();
4162 connection_fake_init( &conn, &opbuf, thrctx );
4165 filter.f_desc = slap_schema.si_ad_objectClass;
4167 op->o_tag = LDAP_REQ_SEARCH;
4169 op->ors_filter = &filter;
4170 op->ors_filterstr = filterstr;
4171 op->ors_scope = LDAP_SCOPE_SUBTREE;
4173 op->o_dn = c.be->be_rootdn;
4174 op->o_ndn = c.be->be_rootndn;
4176 op->o_req_dn = be->be_suffix[0];
4177 op->o_req_ndn = be->be_nsuffix[0];
4179 op->ors_tlimit = SLAP_NO_LIMIT;
4180 op->ors_slimit = SLAP_NO_LIMIT;
4182 op->ors_attrs = slap_anlist_all_attributes;
4183 op->ors_attrsonly = 0;
4185 op->o_callback = &cb;
4188 cb.sc_private = ≻
4189 sc.got_frontend = 0;
4194 op->o_bd = &cfb->cb_db;
4196 /* Allow unknown attrs in DNs */
4197 prev_DN_strict = slap_DN_strict;
4200 rc = op->o_bd->be_search( op, &rs );
4202 /* Restore normal DN validation */
4203 slap_DN_strict = prev_DN_strict;
4205 op->o_tag = LDAP_REQ_ADD;
4206 if ( rc == LDAP_SUCCESS && sc.frontend ) {
4207 rs_reinit( &rs, REP_RESULT );
4208 op->ora_e = sc.frontend;
4209 rc = op->o_bd->be_add( op, &rs );
4211 if ( rc == LDAP_SUCCESS && sc.config ) {
4212 rs_reinit( &rs, REP_RESULT );
4213 op->ora_e = sc.config;
4214 rc = op->o_bd->be_add( op, &rs );
4216 ldap_pvt_thread_pool_context_reset( thrctx );
4219 /* ITS#4194 - only use if it's present, or we're converting. */
4220 if ( !readit || rc == LDAP_SUCCESS )
4221 cfb->cb_use_ldif = 1;
4227 CfOc_cmp( const void *c1, const void *c2 ) {
4228 const ConfigOCs *co1 = c1;
4229 const ConfigOCs *co2 = c2;
4231 return ber_bvcmp( co1->co_name, co2->co_name );
4235 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
4238 i = init_config_attrs( ct );
4241 /* set up the objectclasses */
4242 i = init_config_ocs( ocs );
4245 for (i=0; ocs[i].co_def; i++) {
4246 if ( ocs[i].co_oc ) {
4247 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
4248 if ( !ocs[i].co_table )
4249 ocs[i].co_table = ct;
4250 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
4257 read_config(const char *fname, const char *dir) {
4260 const char *cfdir, *cfname;
4263 /* Setup the config backend */
4264 be = backend_db_init( "config", NULL, 0, NULL );
4268 cfb = be->be_private;
4269 be->be_dfltaccess = ACL_NONE;
4271 /* If no .conf, or a dir was specified, setup the dir */
4272 if ( !fname || dir ) {
4274 /* If explicitly given, check for existence */
4277 if ( stat( dir, &st ) < 0 ) {
4278 Debug( LDAP_DEBUG_ANY,
4279 "invalid config directory %s, error %d\n",
4285 cfdir = SLAPD_DEFAULT_CONFIGDIR;
4287 /* if fname is defaulted, try reading .d */
4288 rc = config_setup_ldif( be, cfdir, !fname );
4291 /* It may be OK if the base object doesn't exist yet. */
4292 if ( rc != LDAP_NO_SUCH_OBJECT )
4294 /* ITS#4194: But if dir was specified and no fname,
4295 * then we were supposed to read the dir. Unless we're
4296 * trying to slapadd the dir...
4298 if ( dir && !fname ) {
4299 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
4301 /* Assume it's slapadd with a config dir, let it continue */
4303 cfb->cb_got_ldif = 1;
4304 cfb->cb_use_ldif = 1;
4309 /* If we read the config from back-ldif, nothing to do here */
4310 if ( cfb->cb_got_ldif ) {
4319 cfname = SLAPD_DEFAULT_CONFIGFILE;
4321 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
4324 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
4327 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
4328 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
4329 &frontendDB->be_schemadn );
4330 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
4331 if ( rc != LDAP_SUCCESS ) {
4332 Debug(LDAP_DEBUG_ANY, "read_config: "
4333 "unable to normalize default schema DN \"%s\"\n",
4334 frontendDB->be_schemadn.bv_val, 0, 0 );
4335 /* must not happen */
4343 config_back_bind( Operation *op, SlapReply *rs )
4345 if ( be_isroot_pw( op ) ) {
4346 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
4347 /* frontend sends result */
4348 return LDAP_SUCCESS;
4351 rs->sr_err = LDAP_INVALID_CREDENTIALS;
4352 send_ldap_result( op, rs );
4358 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
4362 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
4364 rs->sr_attrs = op->ors_attrs;
4365 rs->sr_entry = ce->ce_entry;
4367 rc = send_search_entry( op, rs );
4368 if ( rc != LDAP_SUCCESS ) {
4372 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
4373 if ( ce->ce_kids ) {
4374 rc = config_send( op, rs, ce->ce_kids, 1 );
4375 if ( rc ) return rc;
4378 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
4379 rc = config_send( op, rs, ce, 0 );
4387 static ConfigTable *
4388 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
4393 for (j=0; j<nocs; j++) {
4394 for (i=0; colst[j]->co_table[i].name; i++)
4395 if ( colst[j]->co_table[i].ad == ad ) {
4396 ca->table = colst[j]->co_type;
4397 return &colst[j]->co_table[i];
4403 /* Sort the attributes of the entry according to the order defined
4404 * in the objectclass, with required attributes occurring before
4405 * allowed attributes. For any attributes with sequencing dependencies
4406 * (e.g., rootDN must be defined after suffix) the objectclass must
4407 * list the attributes in the desired sequence.
4410 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
4412 Attribute *a, *head = NULL, *tail = NULL, **prev;
4415 for (i=0; i<nocs; i++) {
4416 if ( colst[i]->co_oc->soc_required ) {
4417 AttributeType **at = colst[i]->co_oc->soc_required;
4418 for (j=0; at[j]; j++) {
4419 for (a=e->e_attrs, prev=&e->e_attrs; a;
4420 prev = &(*prev)->a_next, a=a->a_next) {
4421 if ( a->a_desc == at[j]->sat_ad ) {
4435 if ( colst[i]->co_oc->soc_allowed ) {
4436 AttributeType **at = colst[i]->co_oc->soc_allowed;
4437 for (j=0; at[j]; j++) {
4438 for (a=e->e_attrs, prev=&e->e_attrs; a;
4439 prev = &(*prev)->a_next, a=a->a_next) {
4440 if ( a->a_desc == at[j]->sat_ad ) {
4456 tail->a_next = e->e_attrs;
4462 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
4464 Attribute *a = NULL;
4465 AttributeDescription *ad;
4475 Modifications *ml = ptr;
4477 vals = ml->sml_values;
4480 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
4481 rc = ordered_value_sort( a, 1 );
4483 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
4484 ad->ad_cname.bv_val );
4488 for ( i=0; vals[i].bv_val; i++ ) {
4489 ca->line = vals[i].bv_val;
4490 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
4491 ca->line[0] == '{' ) {
4492 char *idx = strchr( ca->line, '}' );
4493 if ( idx ) ca->line = idx+1;
4495 rc = config_parse_vals( ct, ca, i );
4504 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
4507 struct berval rtype, rval;
4509 AttributeDescription *ad = NULL;
4511 dnRdn( &e->e_name, rdn );
4512 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
4513 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
4514 rtype.bv_val = rdn->bv_val;
4515 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
4518 slap_bv2ad( &rtype, &ad, &rs->sr_text );
4519 a = attr_find( e->e_attrs, ad );
4520 if (!a ) return LDAP_NAMING_VIOLATION;
4527 config_rename_kids( CfEntryInfo *ce )
4530 struct berval rdn, nrdn;
4532 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
4533 struct berval newdn, newndn;
4534 dnRdn ( &ce2->ce_entry->e_name, &rdn );
4535 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
4536 build_new_dn( &newdn, &ce->ce_entry->e_name, &rdn, NULL );
4537 build_new_dn( &newndn, &ce->ce_entry->e_nname, &nrdn, NULL );
4538 free( ce2->ce_entry->e_name.bv_val );
4539 free( ce2->ce_entry->e_nname.bv_val );
4540 ce2->ce_entry->e_name = newdn;
4541 ce2->ce_entry->e_nname = newndn;
4542 config_rename_kids( ce2 );
4547 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
4548 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
4549 struct berval *nnewrdn, int use_ldif )
4553 struct berval odn, ondn;
4557 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
4558 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
4561 free( a->a_vals[0].bv_val );
4562 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
4563 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
4564 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
4565 strcpy( a->a_vals[0].bv_val, ptr1 );
4567 if ( a->a_nvals != a->a_vals ) {
4568 free( a->a_nvals[0].bv_val );
4569 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
4570 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
4571 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
4572 strcpy( a->a_nvals[0].bv_val, ptr1 );
4575 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
4576 BackendDB *be = op->o_bd;
4577 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4578 struct berval dn, ndn, xdn, xndn;
4580 op->o_bd = &cfb->cb_db;
4582 /* Save current rootdn; use the underlying DB's rootdn */
4586 xndn = op->o_req_ndn;
4587 op->o_dn = op->o_bd->be_rootdn;
4588 op->o_ndn = op->o_bd->be_rootndn;
4590 op->o_req_ndn = ondn;
4592 scp = op->o_callback;
4593 op->o_callback = ≻
4594 op->orr_newrdn = *newrdn;
4595 op->orr_nnewrdn = *nnewrdn;
4596 op->orr_newSup = NULL;
4597 op->orr_nnewSup = NULL;
4598 op->orr_deleteoldrdn = 1;
4599 op->orr_modlist = NULL;
4600 slap_modrdn2mods( op, rs );
4601 slap_mods_opattrs( op, &op->orr_modlist, 1 );
4602 rc = op->o_bd->be_modrdn( op, rs );
4603 slap_mods_free( op->orr_modlist, 1 );
4606 op->o_callback = scp;
4610 op->o_req_ndn = xndn;
4613 free( ondn.bv_val );
4615 config_rename_kids( e->e_private );
4620 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
4621 Entry *e, int idx, int tailindex, int use_ldif )
4623 struct berval ival, newrdn, nnewrdn;
4626 char ibuf[32], *ptr1, *ptr2 = NULL;
4629 rc = config_rename_attr( rs, e, &rdn, &a );
4630 if ( rc ) return rc;
4633 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
4634 if ( ival.bv_len >= sizeof( ibuf ) ) {
4635 return LDAP_NAMING_VIOLATION;
4638 newrdn.bv_len = rdn.bv_len + ival.bv_len;
4639 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
4642 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
4643 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4646 ptr2 = ber_bvchr( &rdn, '}' );
4650 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
4652 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
4653 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
4654 a->a_desc->ad_cname.bv_len );
4656 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
4657 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
4661 /* Do the equivalent of ModRDN */
4662 /* Replace DN / NDN */
4663 newrdn.bv_len = ptr1 - newrdn.bv_val;
4664 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
4665 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
4667 free( nnewrdn.bv_val );
4668 free( newrdn.bv_val );
4673 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
4674 SlapReply *rs, int *renum, int *ibase )
4677 int index = -1, gotindex = 0, nsibs, rc = 0;
4678 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
4679 char *ptr1, *ptr2 = NULL;
4682 if ( renum ) *renum = 0;
4684 /* These entries don't get indexed/renumbered */
4685 if ( ce_type == Cft_Global ) return 0;
4686 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
4688 if ( ce_type == Cft_Module )
4691 /* See if the rdn has an index already */
4692 dnRdn( &e->e_name, &rdn );
4693 if ( ce_type == Cft_Database ) {
4694 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
4695 "frontend", STRLENOF("frontend") ))
4697 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
4698 "config", STRLENOF("config") ))
4701 ptr1 = ber_bvchr( &e->e_name, '{' );
4702 if ( ptr1 && ptr1 < &e->e_name.bv_val[ rdn.bv_len ] ) {
4704 ptr2 = strchr( ptr1, '}' );
4705 if ( !ptr2 || ptr2 > &e->e_name.bv_val[ rdn.bv_len ] )
4706 return LDAP_NAMING_VIOLATION;
4707 if ( ptr2-ptr1 == 1)
4708 return LDAP_NAMING_VIOLATION;
4710 index = strtol( ptr1 + 1, &next, 10 );
4711 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
4712 return LDAP_NAMING_VIOLATION;
4715 /* Special case, we allow -1 for the frontendDB */
4716 if ( index != -1 || !isfrontend )
4717 return LDAP_NAMING_VIOLATION;
4719 if ( isconfig && index != 0 ){
4720 return LDAP_NAMING_VIOLATION;
4724 /* count related kids */
4725 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
4726 if ( ce->ce_type == ce_type ) nsibs++;
4729 /* account for -1 frontend */
4730 if ( ce_type == Cft_Database )
4733 if ( index != nsibs ) {
4735 if ( index < nsibs ) {
4736 if ( tailindex ) return LDAP_NAMING_VIOLATION;
4737 /* Siblings need to be renumbered */
4738 if ( index != -1 || !isfrontend )
4742 /* config DB is always "0" */
4743 if ( isconfig && index == -1 ) {
4746 if (( !isfrontend && index == -1 ) || ( index > nsibs ) ){
4750 /* just make index = nsibs */
4752 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
4755 if ( ibase ) *ibase = index;
4756 if ( renum ) *renum = renumber;
4760 /* Insert all superior classes of the given class */
4762 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
4767 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
4768 if ( count_oc( *sups, copp, nocs ) ) {
4773 co.co_name = &oc->soc_cname;
4774 cop = avl_find( CfOcTree, &co, CfOc_cmp );
4778 /* check for duplicates */
4779 for ( i = 0; i < *nocs; i++ ) {
4780 if ( *copp && (*copp)[i] == cop ) {
4786 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
4787 if ( tmp == NULL ) {
4791 (*copp)[*nocs] = cop;
4799 /* Find all superior classes of the given objectclasses,
4800 * return list in order of most-subordinate first.
4802 * Special / auxiliary / Cft_Misc classes always take precedence.
4805 count_ocs( Attribute *oc_at, int *nocs )
4807 int i, j, misc = -1;
4808 ConfigOCs **colst = NULL;
4812 for ( i = oc_at->a_numvals; i--; ) {
4813 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
4815 assert( oc != NULL );
4816 if ( count_oc( oc, &colst, nocs ) ) {
4826 ConfigOCs *tmp = colst[i];
4827 colst[i] = colst[j];
4829 if (tmp->co_type == Cft_Misc)
4833 /* Move misc class to front of list */
4835 ConfigOCs *tmp = colst[misc];
4836 for (i=misc; i>0; i--)
4837 colst[i] = colst[i-1];
4845 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4847 /* Leftover from RE23. Never parse this entry */
4848 return LDAP_COMPARE_TRUE;
4852 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4856 /* This entry is hardcoded, don't re-parse it */
4857 if ( p->ce_type == Cft_Global ) {
4858 cfn = p->ce_private;
4859 ca->ca_private = cfn;
4860 return LDAP_COMPARE_TRUE;
4862 if ( p->ce_type != Cft_Schema )
4863 return LDAP_CONSTRAINT_VIOLATION;
4865 cfn = ch_calloc( 1, sizeof(ConfigFile) );
4866 ca->ca_private = cfn;
4867 cfo = p->ce_private;
4868 cfn->c_sibs = cfo->c_kids;
4870 return LDAP_SUCCESS;
4874 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4876 if ( p->ce_type != Cft_Global ) {
4877 return LDAP_CONSTRAINT_VIOLATION;
4879 /* config must be {0}, nothing else allowed */
4880 if ( !strncmp( e->e_nname.bv_val, "olcDatabase={0}", STRLENOF("olcDatabase={0}")) &&
4881 strncmp( e->e_nname.bv_val + STRLENOF("olcDatabase={0}"), "config,", STRLENOF("config,") )) {
4882 return LDAP_CONSTRAINT_VIOLATION;
4884 ca->be = frontendDB; /* just to get past check_vals */
4885 return LDAP_SUCCESS;
4889 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4891 if ( p->ce_type != Cft_Global ) {
4892 return LDAP_CONSTRAINT_VIOLATION;
4894 return LDAP_SUCCESS;
4898 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4900 if ( p->ce_type != Cft_Global ) {
4901 return LDAP_CONSTRAINT_VIOLATION;
4903 return LDAP_SUCCESS;
4907 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4909 if ( p->ce_type != Cft_Database ) {
4910 return LDAP_CONSTRAINT_VIOLATION;
4913 return LDAP_SUCCESS;
4917 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
4922 AttributeDescription *ad;
4928 if ( cfn->c_cr_head ) {
4929 struct berval bv = BER_BVC("olcDitContentRules");
4931 slap_bv2ad( &bv, &ad, &text );
4932 ct = config_find_table( colst, nocs, ad, ca );
4933 config_del_vals( ct, ca );
4935 if ( cfn->c_oc_head ) {
4936 struct berval bv = BER_BVC("olcObjectClasses");
4938 slap_bv2ad( &bv, &ad, &text );
4939 ct = config_find_table( colst, nocs, ad, ca );
4940 config_del_vals( ct, ca );
4942 if ( cfn->c_at_head ) {
4943 struct berval bv = BER_BVC("olcAttributeTypes");
4945 slap_bv2ad( &bv, &ad, &text );
4946 ct = config_find_table( colst, nocs, ad, ca );
4947 config_del_vals( ct, ca );
4949 if ( cfn->c_syn_head ) {
4950 struct berval bv = BER_BVC("olcLdapSyntaxes");
4952 slap_bv2ad( &bv, &ad, &text );
4953 ct = config_find_table( colst, nocs, ad, ca );
4954 config_del_vals( ct, ca );
4956 if ( cfn->c_om_head ) {
4957 struct berval bv = BER_BVC("olcObjectIdentifier");
4959 slap_bv2ad( &bv, &ad, &text );
4960 ct = config_find_table( colst, nocs, ad, ca );
4961 config_del_vals( ct, ca );
4963 cfo = p->ce_private;
4964 cfo->c_kids = cfn->c_sibs;
4969 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
4971 int rc = LDAP_CONSTRAINT_VIOLATION;
4974 if ( (*cop)->co_ldadd ) {
4975 rc = (*cop)->co_ldadd( last, e, ca );
4976 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4981 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
4982 ConfigOCs co = { 0 };
4984 co.co_name = &(*ocp)->soc_cname;
4985 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
4986 if ( *cop == NULL ) {
4990 rc = config_add_oc( cop, last, e, ca );
4991 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4999 /* Parse an LDAP entry into config directives */
5001 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
5002 int *renum, Operation *op )
5004 CfEntryInfo *ce, *last = NULL;
5005 ConfigOCs co, *coptr, **colst;
5006 Attribute *a, *oc_at, *soc_at;
5007 int i, ibase = -1, nocs, rc = 0;
5010 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
5012 memset( ca, 0, sizeof(ConfigArgs));
5014 /* Make sure parent exists and entry does not. But allow
5015 * Databases and Overlays to be inserted. Don't do any
5016 * auto-renumbering if manageDSAit control is present.
5018 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
5020 if ( ( op && op->o_managedsait ) ||
5021 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
5022 ce->ce_type != Cft_Module ) )
5024 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5025 "DN=\"%s\" already exists\n",
5026 log_prefix, e->e_name.bv_val, 0 );
5027 /* global schema ignores all writes */
5028 if ( ce->ce_type == Cft_Schema && ce->ce_parent->ce_type == Cft_Global )
5029 return LDAP_COMPARE_TRUE;
5030 return LDAP_ALREADY_EXISTS;
5034 dnParent( &e->e_nname, &pdn );
5036 /* If last is NULL, the new entry is the root/suffix entry,
5037 * otherwise last should be the parent.
5039 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
5041 rs->sr_matched = last->ce_entry->e_name.bv_val;
5043 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5044 "DN=\"%s\" not child of DN=\"%s\"\n",
5045 log_prefix, e->e_name.bv_val,
5046 last->ce_entry->e_name.bv_val );
5047 return LDAP_NO_SUCH_OBJECT;
5051 /* No parent, must be root. This will never happen... */
5052 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
5053 return LDAP_NO_SUCH_OBJECT;
5056 if ( last && !access_allowed( op, last->ce_entry,
5057 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
5059 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5060 "DN=\"%s\" no write access to \"children\" of parent\n",
5061 log_prefix, e->e_name.bv_val, 0 );
5062 return LDAP_INSUFFICIENT_ACCESS;
5066 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5068 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5069 "DN=\"%s\" no objectClass\n",
5070 log_prefix, e->e_name.bv_val, 0 );
5071 return LDAP_OBJECT_CLASS_VIOLATION;
5074 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
5076 ObjectClass *soc = NULL;
5077 char textbuf[ SLAP_TEXT_BUFLEN ];
5078 const char *text = textbuf;
5080 /* FIXME: check result */
5081 rc = structural_class( oc_at->a_nvals, &soc, NULL,
5082 &text, textbuf, sizeof(textbuf), NULL );
5083 if ( rc != LDAP_SUCCESS ) {
5084 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5085 "DN=\"%s\" no structural objectClass (%s)\n",
5086 log_prefix, e->e_name.bv_val, text );
5089 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
5090 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
5091 if ( soc_at == NULL ) {
5092 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5093 "DN=\"%s\" no structural objectClass; "
5094 "unable to merge computed class %s\n",
5095 log_prefix, e->e_name.bv_val,
5096 soc->soc_cname.bv_val );
5097 return LDAP_OBJECT_CLASS_VIOLATION;
5100 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5101 "DN=\"%s\" no structural objectClass; "
5102 "computed objectClass %s merged\n",
5103 log_prefix, e->e_name.bv_val,
5104 soc->soc_cname.bv_val );
5107 /* Fake the coordinates based on whether we're part of an
5108 * LDAP Add or if reading the config dir
5111 ca->fname = "slapd";
5114 ca->fname = cfdir.bv_val;
5119 co.co_name = &soc_at->a_nvals[0];
5120 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
5121 if ( coptr == NULL ) {
5122 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5123 "DN=\"%s\" no structural objectClass in configuration table\n",
5124 log_prefix, e->e_name.bv_val, 0 );
5125 return LDAP_OBJECT_CLASS_VIOLATION;
5128 /* Only the root can be Cft_Global, everything else must
5129 * have a parent. Only limited nesting arrangements are allowed.
5131 rc = LDAP_CONSTRAINT_VIOLATION;
5132 if ( coptr->co_type == Cft_Global && !last ) {
5133 cfn = cfb->cb_config;
5134 ca->ca_private = cfn;
5135 ca->be = frontendDB; /* just to get past check_vals */
5139 colst = count_ocs( oc_at, &nocs );
5141 /* Check whether the Add is allowed by its parent, and do
5142 * any necessary arg setup
5145 rc = config_add_oc( &coptr, last, e, ca );
5146 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
5147 for ( i = 0; i<nocs; i++ ) {
5148 /* Already checked these */
5149 if ( colst[i]->co_oc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
5151 if ( colst[i]->co_ldadd &&
5152 ( rc = colst[i]->co_ldadd( last, e, ca ))
5153 != LDAP_CONSTRAINT_VIOLATION ) {
5159 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
5160 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
5161 "DN=\"%s\" no structural objectClass add function\n",
5162 log_prefix, e->e_name.bv_val, 0 );
5163 return LDAP_OBJECT_CLASS_VIOLATION;
5167 /* Add the entry but don't parse it, we already have its contents */
5168 if ( rc == LDAP_COMPARE_TRUE ) {
5173 if ( rc != LDAP_SUCCESS )
5176 /* Parse all the values and check for simple syntax errors before
5177 * performing any set actions.
5179 * If doing an LDAPadd, check for indexed names and any necessary
5180 * renaming/renumbering. Entries that don't need indexed names are
5181 * ignored. Entries that need an indexed name and arrive without one
5182 * are assigned to the end. Entries that arrive with an index may
5183 * cause the following entries to be renumbered/bumped down.
5185 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
5186 * don't allow Adding an entry with an index that's already in use.
5187 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
5189 * These entries can have auto-assigned indexes (appended to the end)
5190 * but only the other types support auto-renumbering of siblings.
5193 rc = check_name_index( last, coptr->co_type, e, rs, renum,
5198 if ( renum && *renum && coptr->co_type != Cft_Database &&
5199 coptr->co_type != Cft_Overlay )
5201 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
5202 "operation requires sibling renumbering" );
5203 rc = LDAP_UNWILLING_TO_PERFORM;
5208 init_config_argv( ca );
5210 /* Make sure we process attrs in the required order */
5211 sort_attrs( e, colst, nocs );
5213 for ( a = e->e_attrs; a; a = a->a_next ) {
5214 if ( a == oc_at ) continue;
5215 ct = config_find_table( colst, nocs, a->a_desc, ca );
5216 if ( !ct ) continue; /* user data? */
5217 rc = check_vals( ct, ca, a, 1 );
5218 if ( rc ) goto done_noop;
5221 /* Basic syntax checks are OK. Do the actual settings. */
5222 for ( a=e->e_attrs; a; a=a->a_next ) {
5223 if ( a == oc_at ) continue;
5224 ct = config_find_table( colst, nocs, a->a_desc, ca );
5225 if ( !ct ) continue; /* user data? */
5226 for (i=0; a->a_vals[i].bv_val; i++) {
5229 ca->line = a->a_vals[i].bv_val;
5230 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
5231 ptr = strchr( ca->line, '}' );
5233 iptr = strchr( ca->line, '{' );
5237 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
5239 ca->valx = strtol( iptr+1, NULL, 0 );
5244 rc = config_parse_add( ct, ca, i );
5252 /* Newly added databases and overlays need to be started up */
5253 if ( CONFIG_ONLINE_ADD( ca )) {
5254 if ( coptr->co_type == Cft_Database ) {
5255 rc = backend_startup_one( ca->be, &ca->reply );
5257 } else if ( coptr->co_type == Cft_Overlay ) {
5258 if ( ca->bi->bi_db_open ) {
5259 BackendInfo *bi_orig = ca->be->bd_info;
5260 ca->be->bd_info = ca->bi;
5261 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
5262 ca->be->bd_info = bi_orig;
5264 } else if ( ca->cleanup ) {
5265 rc = ca->cleanup( ca );
5268 if (ca->cr_msg[0] == '\0')
5269 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
5271 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
5272 ca->log, ca->cr_msg, ca->argv[1] );
5279 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5280 ce->ce_parent = last;
5281 ce->ce_entry = entry_dup( e );
5282 ce->ce_entry->e_private = ce;
5283 ce->ce_type = coptr->co_type;
5286 ce->ce_private = ca->ca_private;
5287 ca->ca_entry = ce->ce_entry;
5290 } else if ( last->ce_kids ) {
5291 CfEntryInfo *c2, **cprev;
5293 /* Advance to first of this type */
5294 cprev = &last->ce_kids;
5295 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
5296 cprev = &c2->ce_sibs;
5299 /* Account for the (-1) frontendDB entry */
5300 if ( ce->ce_type == Cft_Database ) {
5301 if ( ca->be == frontendDB )
5303 else if ( ibase != -1 )
5308 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
5309 cprev = &c2->ce_sibs;
5315 for ( i=0; i<ibase; i++ ) {
5317 cprev = &c2->ce_sibs;
5320 ce->ce_sibs = *cprev;
5328 if ( (coptr->co_type == Cft_Database) && ca->be ) {
5329 if ( ca->be != frontendDB )
5330 backend_destroy_one( ca->be, 1 );
5331 } else if ( (coptr->co_type == Cft_Overlay) && ca->bi ) {
5332 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
5333 } else if ( coptr->co_type == Cft_Schema ) {
5334 schema_destroy_one( ca, colst, nocs, last );
5339 ch_free( ca->argv );
5340 if ( colst ) ch_free( colst );
5344 #define BIGTMP 10000
5346 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5347 int base, int rebase, int max, int use_ldif )
5349 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
5350 ConfigType etype = ce->ce_type;
5351 int count = 0, rc = 0;
5353 /* Reverse ce list */
5354 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
5355 if (ce2->ce_type != etype) {
5360 ce2->ce_sibs = cetmp;
5363 if ( max && count >= max ) {
5369 /* Move original to a temp name until increments are done */
5371 ce->ce_entry->e_private = NULL;
5372 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5373 base+BIGTMP, 0, use_ldif );
5374 ce->ce_entry->e_private = ce;
5376 /* start incrementing */
5377 for (ce2=cetmp; ce2; ce2=ce3) {
5379 ce2->ce_sibs = cerem;
5382 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5383 count+base, 0, use_ldif );
5387 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5388 base, 0, use_ldif );
5393 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
5394 CfEntryInfo *ce2, int old, int use_ldif )
5398 /* Renumber original to a temp value */
5399 ce->ce_entry->e_private = NULL;
5400 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5401 old+BIGTMP, 0, use_ldif );
5402 ce->ce_entry->e_private = ce;
5404 /* start decrementing */
5405 for (; ce2 != ce; ce2=ce2->ce_sibs) {
5406 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5407 count+old, 0, use_ldif );
5410 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
5411 count+old, 0, use_ldif );
5414 /* Parse an LDAP entry into config directives, then store in underlying
5418 config_back_add( Operation *op, SlapReply *rs )
5424 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
5425 NULL, ACL_WADD, NULL )) {
5426 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5431 * Check for attribute ACL
5433 if ( !acl_check_modlist( op, op->ora_e, op->orm_modlist )) {
5434 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5435 rs->sr_text = "no write access to attribute";
5439 cfb = (CfBackInfo *)op->o_bd->be_private;
5441 /* add opattrs for syncprov */
5443 char textbuf[SLAP_TEXT_BUFLEN];
5444 size_t textlen = sizeof textbuf;
5445 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1, NULL,
5446 &rs->sr_text, textbuf, sizeof( textbuf ) );
5447 if ( rs->sr_err != LDAP_SUCCESS )
5449 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
5450 if ( rs->sr_err != LDAP_SUCCESS ) {
5451 Debug( LDAP_DEBUG_TRACE,
5452 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
5453 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
5458 if ( op->o_abandon ) {
5459 rs->sr_err = SLAPD_ABANDON;
5462 ldap_pvt_thread_pool_pause( &connection_pool );
5465 * 1) check for existence of entry
5466 * 2) check for sibling renumbering
5467 * 3) perform internal add
5468 * 4) perform any necessary renumbering
5469 * 5) store entry in underlying database
5471 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
5472 if ( rs->sr_err != LDAP_SUCCESS ) {
5473 rs->sr_text = ca.cr_msg;
5478 CfEntryInfo *ce = ca.ca_entry->e_private;
5479 req_add_s addr = op->oq_add;
5480 op->o_tag = LDAP_REQ_MODRDN;
5481 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
5482 op->o_tag = LDAP_REQ_ADD;
5484 if ( rs->sr_err != LDAP_SUCCESS ) {
5489 if ( cfb->cb_use_ldif ) {
5490 BackendDB *be = op->o_bd;
5491 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5492 struct berval dn, ndn;
5494 op->o_bd = &cfb->cb_db;
5496 /* Save current rootdn; use the underlying DB's rootdn */
5499 op->o_dn = op->o_bd->be_rootdn;
5500 op->o_ndn = op->o_bd->be_rootndn;
5502 scp = op->o_callback;
5503 op->o_callback = ≻
5504 op->o_bd->be_add( op, rs );
5506 op->o_callback = scp;
5512 ldap_pvt_thread_pool_resume( &connection_pool );
5515 { int repl = op->o_dont_replicate;
5516 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
5517 rs->sr_text = NULL; /* Set after config_add_internal */
5518 rs->sr_err = LDAP_SUCCESS;
5519 op->o_dont_replicate = 1;
5521 send_ldap_result( op, rs );
5522 op->o_dont_replicate = repl;
5524 slap_graduate_commit_csn( op );
5528 typedef struct delrec {
5529 struct delrec *next;
5535 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
5541 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
5542 ca->line[0] == '{' )
5544 char *ptr = strchr( ca->line + 1, '}' );
5548 ca->valx = strtol( ca->line + 1, &next, 0 );
5549 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
5555 rc = config_parse_add( ct, ca, i );
5563 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
5566 int rc = LDAP_UNWILLING_TO_PERFORM;
5568 Entry *e = ce->ce_entry;
5569 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
5574 delrec *dels = NULL, *deltail = NULL;
5576 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5577 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
5579 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5580 if (ml->sml_desc == slap_schema.si_ad_objectClass)
5584 colst = count_ocs( oc_at, &nocs );
5586 /* make sure add/del flags are clear; should always be true */
5587 for ( s = save_attrs; s; s = s->a_next ) {
5588 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
5591 e->e_attrs = attrs_dup( e->e_attrs );
5593 init_config_argv( ca );
5596 ca->ca_private = ce->ce_private;
5598 ca->fname = "slapd";
5600 strcpy( ca->log, "back-config" );
5602 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
5603 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5604 switch (ml->sml_op) {
5605 case LDAP_MOD_DELETE:
5606 case LDAP_MOD_REPLACE:
5607 case SLAP_MOD_SOFTDEL:
5609 BerVarray vals = NULL, nvals = NULL;
5611 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
5613 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
5614 ml->sml_desc->ad_cname.bv_val );
5617 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5618 vals = ml->sml_values;
5619 nvals = ml->sml_nvalues;
5620 ml->sml_values = NULL;
5621 ml->sml_nvalues = NULL;
5623 /* If we're deleting by values, remember the indexes of the
5624 * values we deleted.
5626 if ( ct && ml->sml_values ) {
5628 i = ml->sml_numvals;
5629 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
5640 rc = modify_delete_vindex(e, &ml->sml_mod,
5641 get_permissiveModify(op),
5642 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
5643 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5644 ml->sml_values = vals;
5645 ml->sml_nvalues = nvals;
5647 if ( rc == LDAP_NO_SUCH_ATTRIBUTE && ml->sml_op == SLAP_MOD_SOFTDEL )
5651 /* FIXME: check rc before fallthru? */
5655 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5657 case SLAP_MOD_ADD_IF_NOT_PRESENT:
5658 if ( ml->sml_op == SLAP_MOD_ADD_IF_NOT_PRESENT
5659 && attr_find( e->e_attrs, ml->sml_desc ) )
5666 case SLAP_MOD_SOFTADD: {
5667 int mop = ml->sml_op;
5669 ml->sml_op = LDAP_MOD_ADD;
5671 if ( ct->arg_type & ARG_NO_INSERT ) {
5672 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
5674 navals = a->a_numvals;
5677 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
5678 if ( ml->sml_values[i].bv_val[0] == '{' &&
5681 char *next, *val = ml->sml_values[i].bv_val + 1;
5684 j = strtol( val, &next, 0 );
5685 if ( next == val || next[ 0 ] != '}' || j < navals ) {
5687 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
5688 ml->sml_desc->ad_cname.bv_val );
5692 rc = check_vals( ct, ca, ml, 0 );
5693 if ( rc ) goto out_noop;
5696 rc = modify_add_values(e, &ml->sml_mod,
5697 get_permissiveModify(op),
5698 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5700 /* If value already exists, show success here
5701 * and ignore this operation down below.
5703 if ( mop == SLAP_MOD_SOFTADD ) {
5704 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
5714 case LDAP_MOD_INCREMENT: /* FIXME */
5719 if(rc != LDAP_SUCCESS) break;
5722 if ( rc == LDAP_SUCCESS) {
5723 /* check that the entry still obeys the schema */
5724 rc = entry_schema_check(op, e, NULL, 0, 0, NULL,
5725 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
5727 if ( rc ) goto out_noop;
5729 /* Basic syntax checks are OK. Do the actual settings. */
5730 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5731 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
5732 if ( !ct ) continue;
5734 s = attr_find( save_attrs, ml->sml_desc );
5735 a = attr_find( e->e_attrs, ml->sml_desc );
5737 switch (ml->sml_op) {
5738 case LDAP_MOD_DELETE:
5739 case LDAP_MOD_REPLACE: {
5740 BerVarray vals = NULL, nvals = NULL;
5743 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5744 vals = ml->sml_values;
5745 nvals = ml->sml_nvalues;
5746 ml->sml_values = NULL;
5747 ml->sml_nvalues = NULL;
5750 if ( ml->sml_values )
5753 /* If we didn't delete the whole attribute */
5754 if ( ml->sml_values && a ) {
5755 struct berval *mvals;
5758 if ( ml->sml_nvalues )
5759 mvals = ml->sml_nvalues;
5761 mvals = ml->sml_values;
5763 /* use the indexes we saved up above */
5764 for (i=0; i < d->nidx; i++) {
5765 struct berval bv = *mvals++;
5766 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
5767 bv.bv_val[0] == '{' ) {
5768 ptr = strchr( bv.bv_val, '}' ) + 1;
5769 bv.bv_len -= ptr - bv.bv_val;
5772 ca->line = bv.bv_val;
5773 ca->valx = d->idx[i];
5774 config_parse_vals(ct, ca, d->idx[i] );
5775 rc = config_del_vals( ct, ca );
5776 if ( rc != LDAP_SUCCESS ) break;
5778 s->a_flags |= SLAP_ATTR_IXDEL;
5779 for (j=i+1; j < d->nidx; j++)
5780 if ( d->idx[j] >d->idx[i] )
5787 rc = config_del_vals( ct, ca );
5788 if ( rc ) rc = LDAP_OTHER;
5790 s->a_flags |= SLAP_ATTR_IXDEL;
5792 if ( ml->sml_values ) {
5797 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5798 ml->sml_values = vals;
5799 ml->sml_nvalues = nvals;
5801 if ( !vals || rc != LDAP_SUCCESS )
5804 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5807 for (i=0; ml->sml_values[i].bv_val; i++) {
5808 ca->line = ml->sml_values[i].bv_val;
5810 rc = config_modify_add( ct, ca, ml->sml_desc, i );
5813 a->a_flags |= SLAP_ATTR_IXADD;
5820 /* Undo for a failed operation */
5821 if ( rc != LDAP_SUCCESS ) {
5822 ConfigReply msg = ca->reply;
5823 for ( s = save_attrs; s; s = s->a_next ) {
5824 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
5825 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5826 ct = config_find_table( colst, nocs, s->a_desc, ca );
5827 a = attr_find( e->e_attrs, s->a_desc );
5829 /* clear the flag so the add check below will skip it */
5830 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5834 config_del_vals( ct, ca );
5836 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5837 ca->line = s->a_vals[i].bv_val;
5839 config_modify_add( ct, ca, s->a_desc, i );
5843 for ( a = e->e_attrs; a; a = a->a_next ) {
5844 if ( a->a_flags & SLAP_ATTR_IXADD ) {
5845 ct = config_find_table( colst, nocs, a->a_desc, ca );
5849 config_del_vals( ct, ca );
5850 s = attr_find( save_attrs, a->a_desc );
5852 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5853 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5854 ca->line = s->a_vals[i].bv_val;
5856 config_modify_add( ct, ca, s->a_desc, i );
5867 if ( rc == LDAP_SUCCESS ) {
5868 attrs_free( save_attrs );
5871 attrs_free( e->e_attrs );
5872 e->e_attrs = save_attrs;
5874 ch_free( ca->argv );
5875 if ( colst ) ch_free( colst );
5877 deltail = dels->next;
5886 config_back_modify( Operation *op, SlapReply *rs )
5889 CfEntryInfo *ce, *last;
5891 ConfigArgs ca = {0};
5894 AttributeDescription *rad = NULL;
5897 cfb = (CfBackInfo *)op->o_bd->be_private;
5899 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5902 rs->sr_matched = last->ce_entry->e_name.bv_val;
5903 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5907 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
5908 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5912 /* Get type of RDN */
5913 rdn = ce->ce_entry->e_nname;
5914 ptr = strchr( rdn.bv_val, '=' );
5915 rdn.bv_len = ptr - rdn.bv_val;
5916 rs->sr_err = slap_bv2ad( &rdn, &rad, &rs->sr_text );
5917 if ( rs->sr_err != LDAP_SUCCESS ) {
5921 /* Some basic validation... */
5922 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5923 /* Don't allow Modify of RDN; must use ModRdn for that. */
5924 if ( ml->sml_desc == rad ) {
5925 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
5926 rs->sr_text = "Use modrdn to change the entry name";
5929 /* Internal update of contextCSN? */
5930 if ( ml->sml_desc == slap_schema.si_ad_contextCSN && op->o_conn->c_conn_idx == -1 ) {
5936 slap_mods_opattrs( op, &op->orm_modlist, 1 );
5939 if ( op->o_abandon ) {
5940 rs->sr_err = SLAPD_ABANDON;
5943 ldap_pvt_thread_pool_pause( &connection_pool );
5947 * 1) perform the Modify on the cached Entry.
5948 * 2) verify that the Entry still satisfies the schema.
5949 * 3) perform the individual config operations.
5950 * 4) store Modified entry in underlying LDIF backend.
5952 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
5954 rs->sr_text = ca.cr_msg;
5955 } else if ( cfb->cb_use_ldif ) {
5956 BackendDB *be = op->o_bd;
5957 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5958 struct berval dn, ndn;
5960 op->o_bd = &cfb->cb_db;
5964 op->o_dn = op->o_bd->be_rootdn;
5965 op->o_ndn = op->o_bd->be_rootndn;
5967 scp = op->o_callback;
5968 op->o_callback = ≻
5969 op->o_bd->be_modify( op, rs );
5971 op->o_callback = scp;
5977 ldap_pvt_thread_pool_resume( &connection_pool );
5979 send_ldap_result( op, rs );
5980 slap_graduate_commit_csn( op );
5985 config_back_modrdn( Operation *op, SlapReply *rs )
5988 CfEntryInfo *ce, *last;
5992 cfb = (CfBackInfo *)op->o_bd->be_private;
5994 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5997 rs->sr_matched = last->ce_entry->e_name.bv_val;
5998 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6001 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
6002 NULL, ACL_WRITE, NULL )) {
6003 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6007 if ( ce->ce_parent )
6008 parent = ce->ce_parent->ce_entry;
6010 parent = (Entry *)&slap_entry_root;
6011 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
6012 NULL, ACL_WRITE, NULL )) {
6013 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6018 /* We don't allow moving objects to new parents.
6019 * Generally we only allow reordering a set of ordered entries.
6021 if ( op->orr_newSup ) {
6022 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6026 /* If newRDN == oldRDN, quietly succeed */
6027 dnRdn( &op->o_req_ndn, &rdn );
6028 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
6029 rs->sr_err = LDAP_SUCCESS;
6033 /* Current behavior, subject to change as needed:
6035 * For backends and overlays, we only allow renumbering.
6036 * For schema, we allow renaming with the same number.
6037 * Otherwise, the op is not allowed.
6040 if ( ce->ce_type == Cft_Schema ) {
6044 /* Can't alter the main cn=schema entry */
6045 if ( ce->ce_parent->ce_type == Cft_Global ) {
6046 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6047 rs->sr_text = "renaming not allowed for this entry";
6051 /* We could support this later if desired */
6052 ptr1 = ber_bvchr( &rdn, '}' );
6053 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
6054 len = ptr1 - rdn.bv_val;
6055 if ( len != ptr2 - op->orr_newrdn.bv_val ||
6056 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
6057 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6058 rs->sr_text = "schema reordering not supported";
6061 } else if ( ce->ce_type == Cft_Database ||
6062 ce->ce_type == Cft_Overlay ) {
6063 char *ptr1, *ptr2, *iptr1, *iptr2;
6066 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
6067 if ( *iptr2 != '{' ) {
6068 rs->sr_err = LDAP_NAMING_VIOLATION;
6069 rs->sr_text = "new ordering index is required";
6073 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
6074 ptr1 = ber_bvchr( &rdn, '}' );
6075 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
6077 rs->sr_err = LDAP_NAMING_VIOLATION;
6078 rs->sr_text = "new ordering index is required";
6082 len1 = ptr1 - rdn.bv_val;
6083 len2 = ptr2 - op->orr_newrdn.bv_val;
6085 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
6086 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
6087 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6088 rs->sr_text = "changing database/overlay type not allowed";
6091 ixold = strtol( iptr1, NULL, 0 );
6092 ixnew = strtol( iptr2, &ptr1, 0 );
6093 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
6094 rs->sr_err = LDAP_NAMING_VIOLATION;
6097 /* config DB is always 0, cannot be changed */
6098 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
6099 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
6103 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6104 rs->sr_text = "renaming not supported for this entry";
6108 if ( op->o_abandon ) {
6109 rs->sr_err = SLAPD_ABANDON;
6112 ldap_pvt_thread_pool_pause( &connection_pool );
6114 if ( ce->ce_type == Cft_Schema ) {
6115 req_modrdn_s modr = op->oq_modrdn;
6118 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
6119 if ( rs->sr_err == LDAP_SUCCESS ) {
6120 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
6121 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
6124 op->oq_modrdn = modr;
6126 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
6127 req_modrdn_s modr = op->oq_modrdn;
6130 /* Advance to first of this type */
6131 cprev = &ce->ce_parent->ce_kids;
6132 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
6133 cprev = &ce2->ce_sibs;
6136 /* Skip the -1 entry */
6137 if ( ce->ce_type == Cft_Database ) {
6138 cprev = &ce2->ce_sibs;
6144 /* Remove from old slot */
6145 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
6146 cprev = &ce2->ce_sibs;
6147 *cprev = ce->ce_sibs;
6148 ceold = ce->ce_sibs;
6150 /* Insert into new slot */
6152 for ( i=0; i<ixnew; i++ ) {
6156 cprev = &ce2->ce_sibs;
6158 ce->ce_sibs = *cprev;
6163 /* NOTE: These should be encoded in the OC tables, not inline here */
6164 if ( ce->ce_type == Cft_Database )
6165 backend_db_move( ce->ce_be, ixnew );
6166 else if ( ce->ce_type == Cft_Overlay )
6167 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
6169 if ( ixold < ixnew ) {
6170 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
6173 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
6174 ixold - ixnew, cfb->cb_use_ldif );
6176 op->oq_modrdn = modr;
6179 ldap_pvt_thread_pool_resume( &connection_pool );
6181 send_ldap_result( op, rs );
6186 config_back_delete( Operation *op, SlapReply *rs )
6188 #ifdef SLAP_CONFIG_DELETE
6190 CfEntryInfo *ce, *last, *ce2;
6192 cfb = (CfBackInfo *)op->o_bd->be_private;
6194 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6197 rs->sr_matched = last->ce_entry->e_name.bv_val;
6198 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6199 } else if ( ce->ce_kids ) {
6200 rs->sr_err = LDAP_NOT_ALLOWED_ON_NONLEAF;
6201 } else if ( op->o_abandon ) {
6202 rs->sr_err = SLAPD_ABANDON;
6203 } else if ( ce->ce_type == Cft_Overlay ||
6204 ce->ce_type == Cft_Database ||
6205 ce->ce_type == Cft_Misc ){
6209 ldap_pvt_thread_pool_pause( &connection_pool );
6211 if ( ce->ce_type == Cft_Overlay ){
6212 overlay_remove( ce->ce_be, (slap_overinst *)ce->ce_bi, op );
6213 } else if ( ce->ce_type == Cft_Misc ) {
6215 * only Cft_Misc objects that have a co_lddel handler set in
6216 * the ConfigOCs struct can be deleted. This code also
6217 * assumes that the entry can be only have one objectclass
6218 * with co_type == Cft_Misc
6220 ConfigOCs co, *coptr;
6224 oc_at = attr_find( ce->ce_entry->e_attrs,
6225 slap_schema.si_ad_objectClass );
6227 rs->sr_err = LDAP_OTHER;
6228 rs->sr_text = "objectclass not found";
6229 ldap_pvt_thread_pool_resume( &connection_pool );
6232 for ( i=0; !BER_BVISNULL(&oc_at->a_nvals[i]); i++ ) {
6233 co.co_name = &oc_at->a_nvals[i];
6234 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
6235 if ( coptr == NULL || coptr->co_type != Cft_Misc ) {
6238 if ( ! coptr->co_lddel || coptr->co_lddel( ce, op ) ){
6239 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6240 if ( ! coptr->co_lddel ) {
6241 rs->sr_text = "No delete handler found";
6243 rs->sr_err = LDAP_OTHER;
6244 /* FIXME: We should return a helpful error message
6247 ldap_pvt_thread_pool_resume( &connection_pool );
6252 } else if (ce->ce_type == Cft_Database ) {
6253 if ( ce->ce_be == frontendDB || ce->ce_be == op->o_bd ){
6254 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6255 rs->sr_text = "Cannot delete config or frontend database";
6256 ldap_pvt_thread_pool_resume( &connection_pool );
6259 if ( ce->ce_be->bd_info->bi_db_close ) {
6260 ce->ce_be->bd_info->bi_db_close( ce->ce_be, NULL );
6262 backend_destroy_one( ce->ce_be, 1);
6265 /* remove CfEntryInfo from the siblings list */
6266 if ( ce->ce_parent->ce_kids == ce ) {
6267 ce->ce_parent->ce_kids = ce->ce_sibs;
6269 for ( ce2 = ce->ce_parent->ce_kids ; ce2; ce2 = ce2->ce_sibs ) {
6270 if ( ce2->ce_sibs == ce ) {
6271 ce2->ce_sibs = ce->ce_sibs;
6277 /* remove from underlying database */
6278 if ( cfb->cb_use_ldif ) {
6279 BackendDB *be = op->o_bd;
6280 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
6281 struct berval dn, ndn, req_dn, req_ndn;
6283 op->o_bd = &cfb->cb_db;
6287 req_dn = op->o_req_dn;
6288 req_ndn = op->o_req_ndn;
6290 op->o_dn = op->o_bd->be_rootdn;
6291 op->o_ndn = op->o_bd->be_rootndn;
6292 op->o_req_dn = ce->ce_entry->e_name;
6293 op->o_req_ndn = ce->ce_entry->e_nname;
6295 scp = op->o_callback;
6296 op->o_callback = ≻
6297 op->o_bd->be_delete( op, rs );
6299 op->o_callback = scp;
6302 op->o_req_dn = req_dn;
6303 op->o_req_ndn = req_ndn;
6306 /* renumber siblings */
6307 iptr = ber_bvchr( &op->o_req_ndn, '{' ) + 1;
6308 ixold = strtol( iptr, NULL, 0 );
6309 for (ce2 = ce->ce_sibs, count=0; ce2; ce2=ce2->ce_sibs) {
6310 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
6311 count+ixold, 0, cfb->cb_use_ldif );
6315 ce->ce_entry->e_private=NULL;
6316 entry_free(ce->ce_entry);
6318 ldap_pvt_thread_pool_resume( &connection_pool );
6320 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6324 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
6325 #endif /* SLAP_CONFIG_DELETE */
6326 send_ldap_result( op, rs );
6331 config_back_search( Operation *op, SlapReply *rs )
6334 CfEntryInfo *ce, *last;
6337 cfb = (CfBackInfo *)op->o_bd->be_private;
6339 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
6342 rs->sr_matched = last->ce_entry->e_name.bv_val;
6343 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6346 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
6347 ACL_SEARCH, NULL, &mask ))
6349 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
6350 rs->sr_err = LDAP_NO_SUCH_OBJECT;
6352 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
6356 switch ( op->ors_scope ) {
6357 case LDAP_SCOPE_BASE:
6358 case LDAP_SCOPE_SUBTREE:
6359 rs->sr_err = config_send( op, rs, ce, 0 );
6362 case LDAP_SCOPE_ONELEVEL:
6363 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
6364 rs->sr_err = config_send( op, rs, ce, 1 );
6373 send_ldap_result( op, rs );
6377 /* no-op, we never free entries */
6378 int config_entry_release(
6383 if ( !e->e_private ) {
6386 return LDAP_SUCCESS;
6389 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
6391 int config_back_entry_get(
6395 AttributeDescription *at,
6400 CfEntryInfo *ce, *last;
6401 int rc = LDAP_NO_SUCH_OBJECT;
6403 cfb = (CfBackInfo *)op->o_bd->be_private;
6405 ce = config_find_base( cfb->cb_root, ndn, &last );
6407 *ent = ce->ce_entry;
6410 if ( oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
6411 rc = LDAP_NO_SUCH_ATTRIBUTE;
6421 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
6422 ConfigTable *ct, ConfigArgs *c )
6426 for (; at && *at; at++) {
6427 /* Skip the naming attr */
6428 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
6430 for (i=0;ct[i].name;i++) {
6431 if (ct[i].ad == (*at)->sat_ad) {
6432 rc = config_get_vals(&ct[i], c);
6433 /* NOTE: tolerate that config_get_vals()
6434 * returns success with no values */
6435 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
6436 if ( c->rvalue_nvals )
6437 rc = attr_merge(e, ct[i].ad, c->rvalue_vals,
6440 slap_syntax_validate_func *validate =
6441 ct[i].ad->ad_type->sat_syntax->ssyn_validate;
6444 for ( j=0; c->rvalue_vals[j].bv_val; j++ ) {
6445 rc = ordered_value_validate( ct[i].ad,
6446 &c->rvalue_vals[j], LDAP_MOD_ADD );
6448 Debug( LDAP_DEBUG_ANY,
6449 "config_build_attrs: error %d on %s value #%d\n",
6450 rc, ct[i].ad->ad_cname.bv_val, j );
6456 rc = attr_merge_normalize(e, ct[i].ad,
6457 c->rvalue_vals, NULL);
6459 ber_bvarray_free( c->rvalue_nvals );
6460 ber_bvarray_free( c->rvalue_vals );
6462 Debug( LDAP_DEBUG_ANY,
6463 "config_build_attrs: error %d on %s\n",
6464 rc, ct[i].ad->ad_cname.bv_val, 0 );
6475 /* currently (2010) does not access rs except possibly writing rs->sr_err */
6478 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
6479 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
6481 Entry *e = entry_alloc();
6482 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
6484 struct berval ad_name;
6485 AttributeDescription *ad = NULL;
6488 const char *text = "";
6492 CfEntryInfo *ceprev = NULL;
6494 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
6497 ce->ce_type = main->co_type;
6498 ce->ce_parent = parent;
6500 pdn = parent->ce_entry->e_nname;
6501 if ( parent->ce_kids && parent->ce_kids->ce_type <= ce->ce_type )
6502 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
6503 ceprev->ce_type <= ce->ce_type;
6504 ceprev = ceprev->ce_sibs );
6509 ce->ce_private = c->ca_private;
6513 build_new_dn( &e->e_name, &pdn, rdn, NULL );
6514 ber_dupbv( &e->e_nname, &e->e_name );
6516 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6517 main->co_name, NULL );
6519 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
6520 extra->co_name, NULL );
6521 ptr = strchr(rdn->bv_val, '=');
6522 ad_name.bv_val = rdn->bv_val;
6523 ad_name.bv_len = ptr - rdn->bv_val;
6524 rc = slap_bv2ad( &ad_name, &ad, &text );
6529 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
6530 attr_merge_normalize_one(e, ad, &val, NULL );
6533 c->table = main->co_type;
6534 if ( oc->soc_required ) {
6535 rc = config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
6536 if ( rc ) goto fail;
6539 if ( oc->soc_allowed ) {
6540 rc = config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
6541 if ( rc ) goto fail;
6546 c->table = extra->co_type;
6547 if ( oc->soc_required ) {
6548 rc = config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
6549 if ( rc ) goto fail;
6552 if ( oc->soc_allowed ) {
6553 rc = config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
6554 if ( rc ) goto fail;
6558 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
6559 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
6560 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
6561 if ( rc != LDAP_SUCCESS ) {
6563 Debug( LDAP_DEBUG_ANY,
6564 "config_build_entry: build \"%s\" failed: \"%s\"\n",
6565 rdn->bv_val, text, 0);
6568 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
6571 op->ora_modlist = NULL;
6572 slap_add_opattrs( op, NULL, NULL, 0, 0 );
6573 if ( !op->o_noop ) {
6574 SlapReply rs2 = {REP_RESULT};
6575 op->o_bd->be_add( op, &rs2 );
6576 rs->sr_err = rs2.sr_err;
6577 rs_assert_done( &rs2 );
6578 if ( ( rs2.sr_err != LDAP_SUCCESS )
6579 && (rs2.sr_err != LDAP_ALREADY_EXISTS) ) {
6585 ce->ce_sibs = ceprev->ce_sibs;
6586 ceprev->ce_sibs = ce;
6587 } else if ( parent ) {
6588 ce->ce_sibs = parent->ce_kids;
6589 parent->ce_kids = ce;
6596 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
6597 Operation *op, SlapReply *rs )
6600 ConfigFile *cf = c->ca_private;
6602 struct berval bv, rdn;
6604 for (; cf; cf=cf->c_sibs, c->depth++) {
6605 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
6606 !cf->c_om_head && !cf->c_syn_head ) continue;
6607 c->value_dn.bv_val = c->log;
6608 LUTIL_SLASHPATH( cf->c_file.bv_val );
6609 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
6614 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
6616 ptr = strchr( bv.bv_val, '.' );
6618 bv.bv_len = ptr - bv.bv_val;
6619 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
6620 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6621 /* FIXME: how can indicate error? */
6624 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
6626 c->value_dn.bv_len += bv.bv_len;
6627 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
6628 rdnNormalize( 0, NULL, NULL, &c->value_dn, &rdn, NULL );
6631 e = config_build_entry( op, rs, ceparent, c, &rdn,
6632 &CFOC_SCHEMA, NULL );
6633 ch_free( rdn.bv_val );
6636 } else if ( e && cf->c_kids ) {
6637 c->ca_private = cf->c_kids;
6638 config_build_schema_inc( c, e->e_private, op, rs );
6644 #ifdef SLAPD_MODULES
6647 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
6648 Operation *op, SlapReply *rs )
6653 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
6654 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
6656 c->value_dn.bv_val = c->log;
6657 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
6658 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
6659 /* FIXME: how can indicate error? */
6663 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
6672 config_check_schema(Operation *op, CfBackInfo *cfb)
6674 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
6676 CfEntryInfo *ce, *last;
6679 /* If there's no root entry, we must be in the midst of converting */
6680 if ( !cfb->cb_root )
6683 /* Make sure the main schema entry exists */
6684 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
6691 /* Make sure it's up to date */
6692 if ( cf_om_tail != om_sys_tail ) {
6693 a = attr_find( e->e_attrs, cfAd_om );
6695 if ( a->a_nvals != a->a_vals )
6696 ber_bvarray_free( a->a_nvals );
6697 ber_bvarray_free( a->a_vals );
6702 oidm_unparse( &bv, NULL, NULL, 1 );
6703 attr_merge_normalize( e, cfAd_om, bv, NULL );
6704 ber_bvarray_free( bv );
6705 cf_om_tail = om_sys_tail;
6707 if ( cf_at_tail != at_sys_tail ) {
6708 a = attr_find( e->e_attrs, cfAd_attr );
6710 if ( a->a_nvals != a->a_vals )
6711 ber_bvarray_free( a->a_nvals );
6712 ber_bvarray_free( a->a_vals );
6717 at_unparse( &bv, NULL, NULL, 1 );
6718 attr_merge_normalize( e, cfAd_attr, bv, NULL );
6719 ber_bvarray_free( bv );
6720 cf_at_tail = at_sys_tail;
6722 if ( cf_oc_tail != oc_sys_tail ) {
6723 a = attr_find( e->e_attrs, cfAd_oc );
6725 if ( a->a_nvals != a->a_vals )
6726 ber_bvarray_free( a->a_nvals );
6727 ber_bvarray_free( a->a_vals );
6732 oc_unparse( &bv, NULL, NULL, 1 );
6733 attr_merge_normalize( e, cfAd_oc, bv, NULL );
6734 ber_bvarray_free( bv );
6735 cf_oc_tail = oc_sys_tail;
6737 if ( cf_syn_tail != syn_sys_tail ) {
6738 a = attr_find( e->e_attrs, cfAd_syntax );
6740 if ( a->a_nvals != a->a_vals )
6741 ber_bvarray_free( a->a_nvals );
6742 ber_bvarray_free( a->a_vals );
6747 syn_unparse( &bv, NULL, NULL, 1 );
6748 attr_merge_normalize( e, cfAd_syntax, bv, NULL );
6749 ber_bvarray_free( bv );
6750 cf_syn_tail = syn_sys_tail;
6753 SlapReply rs = {REP_RESULT};
6754 c.ca_private = NULL;
6755 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
6756 &CFOC_SCHEMA, NULL );
6761 ce->ce_private = cfb->cb_config;
6762 cf_at_tail = at_sys_tail;
6763 cf_oc_tail = oc_sys_tail;
6764 cf_om_tail = om_sys_tail;
6765 cf_syn_tail = syn_sys_tail;
6770 static const char *defacl[] = {
6771 NULL, "to", "*", "by", "*", "none", NULL
6775 config_back_db_open( BackendDB *be, ConfigReply *cr )
6777 CfBackInfo *cfb = be->be_private;
6780 CfEntryInfo *ce, *ceparent;
6784 Connection conn = {0};
6785 OperationBuffer opbuf;
6787 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
6788 SlapReply rs = {REP_RESULT};
6789 void *thrctx = NULL;
6791 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
6793 /* If we have no explicitly configured ACLs, don't just use
6794 * the global ACLs. Explicitly deny access to everything.
6796 if ( !be->bd_self->be_acl ) {
6797 parse_acl(be->bd_self, "config_back_db_open", 0, 6, (char **)defacl, 0 );
6800 thrctx = ldap_pvt_thread_pool_context();
6801 connection_fake_init( &conn, &opbuf, thrctx );
6804 op->o_tag = LDAP_REQ_ADD;
6805 op->o_callback = &cb;
6806 op->o_bd = &cfb->cb_db;
6807 op->o_dn = op->o_bd->be_rootdn;
6808 op->o_ndn = op->o_bd->be_rootndn;
6810 if ( !cfb->cb_use_ldif ) {
6814 /* If we read the config from back-ldif, do some quick sanity checks */
6815 if ( cfb->cb_got_ldif ) {
6816 return config_check_schema( op, cfb );
6819 /* create root of tree */
6821 c.ca_private = cfb->cb_config;
6823 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
6833 #ifdef SLAPD_MODULES
6834 /* Create Module nodes... */
6835 if ( modpaths.mp_loads ) {
6836 if ( config_build_modules( &c, ceparent, op, &rs ) ){
6842 /* Create schema nodes... cn=schema will contain the hardcoded core
6843 * schema, read-only. Child objects will contain runtime loaded schema
6847 c.ca_private = NULL;
6848 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
6853 ce->ce_private = cfb->cb_config;
6854 cf_at_tail = at_sys_tail;
6855 cf_oc_tail = oc_sys_tail;
6856 cf_om_tail = om_sys_tail;
6857 cf_syn_tail = syn_sys_tail;
6859 /* Create schema nodes for included schema... */
6860 if ( cfb->cb_config->c_kids ) {
6863 c.ca_private = cfb->cb_config->c_kids;
6864 rc = config_build_schema_inc( &c, ce, op, &rs );
6870 /* Create backend nodes. Skip if they don't provide a cf_table.
6871 * There usually aren't any of these.
6875 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
6876 if (!bi->bi_cf_ocs) {
6877 /* If it only supports the old config mech, complain. */
6878 if ( bi->bi_config ) {
6879 Debug( LDAP_DEBUG_ANY,
6880 "WARNING: No dynamic config support for backend %s.\n",
6881 bi->bi_type, 0, 0 );
6886 if (!bi->bi_private) continue;
6889 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6890 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
6891 if ( rdn.bv_len >= sizeof( c.log ) ) {
6892 /* FIXME: holler ... */ ;
6895 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
6902 /* Create database nodes... */
6903 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
6904 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
6905 for ( i = -1, be = frontendDB ; be;
6906 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
6907 slap_overinfo *oi = NULL;
6909 if ( overlay_is_over( be )) {
6910 oi = be->bd_info->bi_private;
6916 /* If this backend supports the old config mechanism, but not
6917 * the new mech, complain.
6919 if ( !be->be_cf_ocs && bi->bi_db_config ) {
6920 Debug( LDAP_DEBUG_ANY,
6921 "WARNING: No dynamic config support for database %s.\n",
6922 bi->bi_type, 0, 0 );
6926 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6927 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
6929 if ( rdn.bv_len >= sizeof( c.log ) ) {
6930 /* FIXME: holler ... */ ;
6934 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
6940 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd ) {
6941 rs_reinit( &rs, REP_RESULT );
6942 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
6944 /* Iterate through overlays */
6949 voidList *vl, *v0 = NULL;
6951 /* overlays are in LIFO order, must reverse stack */
6952 for (on=oi->oi_list; on; on=on->on_next) {
6953 vl = ch_malloc( sizeof( voidList ));
6958 for (j=0; vl; j++,vl=v0) {
6962 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
6963 Debug( LDAP_DEBUG_ANY,
6964 "WARNING: No dynamic config support for overlay %s.\n",
6965 on->on_bi.bi_type, 0, 0 );
6969 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6970 "%s=" SLAP_X_ORDERED_FMT "%s",
6971 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
6972 if ( rdn.bv_len >= sizeof( c.log ) ) {
6973 /* FIXME: holler ... */ ;
6977 oe = config_build_entry( op, &rs, ce, &c, &rdn,
6978 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
6982 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd ) {
6983 rs_reinit( &rs, REP_RESULT );
6984 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
6990 ldap_pvt_thread_pool_context_reset( thrctx );
6992 if ( unsupp && cfb->cb_use_ldif ) {
6993 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
6994 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
7001 cfb_free_cffile( ConfigFile *cf )
7005 for (; cf; cf=next) {
7008 cfb_free_cffile( cf->c_kids );
7009 ch_free( cf->c_file.bv_val );
7010 ber_bvarray_free( cf->c_dseFiles );
7016 cfb_free_entries( CfEntryInfo *ce )
7020 for (; ce; ce=next) {
7023 cfb_free_entries( ce->ce_kids );
7024 ce->ce_entry->e_private = NULL;
7025 entry_free( ce->ce_entry );
7031 config_back_db_close( BackendDB *be, ConfigReply *cr )
7033 CfBackInfo *cfb = be->be_private;
7035 cfb_free_entries( cfb->cb_root );
7036 cfb->cb_root = NULL;
7038 if ( cfb->cb_db.bd_info ) {
7039 backend_shutdown( &cfb->cb_db );
7046 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
7048 CfBackInfo *cfb = be->be_private;
7050 cfb_free_cffile( cfb->cb_config );
7052 ch_free( cfdir.bv_val );
7054 avl_free( CfOcTree, NULL );
7056 if ( cfb->cb_db.bd_info ) {
7057 cfb->cb_db.be_suffix = NULL;
7058 cfb->cb_db.be_nsuffix = NULL;
7059 BER_BVZERO( &cfb->cb_db.be_rootdn );
7060 BER_BVZERO( &cfb->cb_db.be_rootndn );
7062 backend_destroy_one( &cfb->cb_db, 0 );
7071 config_back_db_init( BackendDB *be, ConfigReply* cr )
7077 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
7078 cfn = cfb->cb_config;
7079 be->be_private = cfb;
7081 ber_dupbv( &be->be_rootdn, &config_rdn );
7082 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
7083 ber_dupbv( &dn, &be->be_rootdn );
7084 ber_bvarray_add( &be->be_suffix, &dn );
7085 ber_dupbv( &dn, &be->be_rootdn );
7086 ber_bvarray_add( &be->be_nsuffix, &dn );
7088 /* Hide from namingContexts */
7089 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
7091 /* Check ACLs on content of Adds by default */
7092 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_ACL_ADD;
7098 config_back_destroy( BackendInfo *bi )
7100 ldif_must_b64_encode_release();
7105 config_tool_entry_open( BackendDB *be, int mode )
7107 CfBackInfo *cfb = be->be_private;
7108 BackendInfo *bi = cfb->cb_db.bd_info;
7110 if ( bi && bi->bi_tool_entry_open )
7111 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
7118 config_tool_entry_close( BackendDB *be )
7120 CfBackInfo *cfb = be->be_private;
7121 BackendInfo *bi = cfb->cb_db.bd_info;
7123 if ( bi && bi->bi_tool_entry_close )
7124 return bi->bi_tool_entry_close( &cfb->cb_db );
7130 config_tool_entry_first( BackendDB *be )
7132 CfBackInfo *cfb = be->be_private;
7133 BackendInfo *bi = cfb->cb_db.bd_info;
7135 if ( bi && bi->bi_tool_entry_first ) {
7136 return bi->bi_tool_entry_first( &cfb->cb_db );
7138 if ( bi && bi->bi_tool_entry_first_x ) {
7139 return bi->bi_tool_entry_first_x( &cfb->cb_db,
7140 NULL, LDAP_SCOPE_DEFAULT, NULL );
7146 config_tool_entry_first_x(
7148 struct berval *base,
7152 CfBackInfo *cfb = be->be_private;
7153 BackendInfo *bi = cfb->cb_db.bd_info;
7155 if ( bi && bi->bi_tool_entry_first_x ) {
7156 return bi->bi_tool_entry_first_x( &cfb->cb_db, base, scope, f );
7162 config_tool_entry_next( BackendDB *be )
7164 CfBackInfo *cfb = be->be_private;
7165 BackendInfo *bi = cfb->cb_db.bd_info;
7167 if ( bi && bi->bi_tool_entry_next )
7168 return bi->bi_tool_entry_next( &cfb->cb_db );
7174 config_tool_entry_get( BackendDB *be, ID id )
7176 CfBackInfo *cfb = be->be_private;
7177 BackendInfo *bi = cfb->cb_db.bd_info;
7179 if ( bi && bi->bi_tool_entry_get )
7180 return bi->bi_tool_entry_get( &cfb->cb_db, id );
7185 static int entry_put_got_frontend=0;
7186 static int entry_put_got_config=0;
7188 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
7190 CfBackInfo *cfb = be->be_private;
7191 BackendInfo *bi = cfb->cb_db.bd_info;
7193 struct berval rdn, vals[ 2 ];
7195 OperationBuffer opbuf;
7197 Connection conn = {0};
7198 Operation *op = NULL;
7201 int isFrontendChild = 0;
7203 /* Create entry for frontend database if it does not exist already */
7204 if ( !entry_put_got_frontend ) {
7205 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
7206 STRLENOF( "olcDatabase" ))) {
7207 if ( strncmp( e->e_nname.bv_val +
7208 STRLENOF( "olcDatabase" ), "={-1}frontend",
7209 STRLENOF( "={-1}frontend" )) &&
7210 strncmp( e->e_nname.bv_val +
7211 STRLENOF( "olcDatabase" ), "=frontend",
7212 STRLENOF( "=frontend" ))) {
7214 vals[1].bv_val = NULL;
7215 memset( &ca, 0, sizeof(ConfigArgs));
7217 ca.bi = frontendDB->bd_info;
7218 ca.be->be_cf_ocs = &CFOC_FRONTEND;
7219 rdn.bv_val = ca.log;
7220 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7221 "%s=" SLAP_X_ORDERED_FMT "%s",
7222 cfAd_database->ad_cname.bv_val, -1,
7224 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
7225 &CFOC_DATABASE, ca.be->be_cf_ocs );
7226 thrctx = ldap_pvt_thread_pool_context();
7227 connection_fake_init2( &conn, &opbuf, thrctx,0 );
7229 op->o_bd = &cfb->cb_db;
7230 op->o_tag = LDAP_REQ_ADD;
7232 op->o_dn = be->be_rootdn;
7233 op->o_ndn = be->be_rootndn;
7234 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
7235 if ( rc != LDAP_SUCCESS ) {
7236 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
7237 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
7241 if ( ce && bi && bi->bi_tool_entry_put &&
7242 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
7243 entry_put_got_frontend++;
7245 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
7246 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
7250 entry_put_got_frontend++;
7256 /* Child entries of the frontend database, e.g. slapo-chain's back-ldap
7257 * instances, may appear before the config database entry in the ldif, skip
7258 * auto-creation of olcDatabase={0}config in such a case */
7259 if ( !entry_put_got_config &&
7260 !strncmp( e->e_nname.bv_val, "olcDatabase", STRLENOF( "olcDatabase" ))) {
7262 dnParent( &e->e_nname, &pdn );
7263 while ( pdn.bv_len ) {
7264 if ( !strncmp( pdn.bv_val, "olcDatabase",
7265 STRLENOF( "olcDatabase" ))) {
7266 if ( !strncmp( pdn.bv_val +
7267 STRLENOF( "olcDatabase" ), "={-1}frontend",
7268 STRLENOF( "={-1}frontend" )) ||
7269 !strncmp( pdn.bv_val +
7270 STRLENOF( "olcDatabase" ), "=frontend",
7271 STRLENOF( "=frontend" ))) {
7273 isFrontendChild = 1;
7277 dnParent( &pdn, &pdn );
7281 /* Create entry for config database if it does not exist already */
7282 if ( !entry_put_got_config && !isFrontend && !isFrontendChild ) {
7283 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
7284 STRLENOF( "olcDatabase" ))) {
7285 if ( strncmp( e->e_nname.bv_val +
7286 STRLENOF( "olcDatabase" ), "={0}config",
7287 STRLENOF( "={0}config" )) &&
7288 strncmp( e->e_nname.bv_val +
7289 STRLENOF( "olcDatabase" ), "=config",
7290 STRLENOF( "=config" )) ) {
7292 vals[1].bv_val = NULL;
7293 memset( &ca, 0, sizeof(ConfigArgs));
7294 ca.be = LDAP_STAILQ_FIRST( &backendDB );
7295 ca.bi = ca.be->bd_info;
7296 rdn.bv_val = ca.log;
7297 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
7298 "%s=" SLAP_X_ORDERED_FMT "%s",
7299 cfAd_database->ad_cname.bv_val, 0,
7301 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
7304 thrctx = ldap_pvt_thread_pool_context();
7305 connection_fake_init2( &conn, &opbuf, thrctx,0 );
7307 op->o_bd = &cfb->cb_db;
7308 op->o_tag = LDAP_REQ_ADD;
7309 op->o_dn = be->be_rootdn;
7310 op->o_ndn = be->be_rootndn;
7313 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
7314 if ( rc != LDAP_SUCCESS ) {
7315 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
7316 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7319 if (ce && bi && bi->bi_tool_entry_put &&
7320 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
7321 entry_put_got_config++;
7323 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
7324 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
7328 entry_put_got_config++;
7332 if ( bi && bi->bi_tool_entry_put &&
7333 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
7334 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
7341 AttributeDescription **desc;
7343 { "attribute", &cfAd_attr },
7344 { "backend", &cfAd_backend },
7345 { "database", &cfAd_database },
7346 { "include", &cfAd_include },
7347 { "ldapsyntax", &cfAd_syntax },
7348 { "objectclass", &cfAd_oc },
7349 { "objectidentifier", &cfAd_om },
7350 { "overlay", &cfAd_overlay },
7355 * add / delete: all types that may be added or deleted must use an
7356 * X-ORDERED attributeType for their RDN. Adding and deleting entries
7357 * should automatically renumber the index of any siblings as needed,
7358 * so that no gaps in the numbering sequence exist after the add/delete
7360 * What can be added:
7362 * backend objects for backend-specific config directives
7366 * delete: probably no support this time around.
7368 * modrdn: generally not done. Will be invoked automatically by add/
7369 * delete to update numbering sequence. Perform as an explicit operation
7370 * so that the renumbering effect may be replicated. Subtree rename must
7371 * be supported, since renumbering a database will affect all its child
7374 * modify: must be fully supported.
7378 config_back_initialize( BackendInfo *bi )
7380 ConfigTable *ct = config_back_cf_table;
7384 AttributeDescription *ad = NULL;
7386 static char *controls[] = {
7387 LDAP_CONTROL_MANAGEDSAIT,
7391 /* Make sure we don't exceed the bits reserved for userland */
7392 config_check_userland( CFG_LAST );
7394 bi->bi_controls = controls;
7399 bi->bi_destroy = config_back_destroy;
7401 bi->bi_db_init = config_back_db_init;
7402 bi->bi_db_config = 0;
7403 bi->bi_db_open = config_back_db_open;
7404 bi->bi_db_close = config_back_db_close;
7405 bi->bi_db_destroy = config_back_db_destroy;
7407 bi->bi_op_bind = config_back_bind;
7408 bi->bi_op_unbind = 0;
7409 bi->bi_op_search = config_back_search;
7410 bi->bi_op_compare = 0;
7411 bi->bi_op_modify = config_back_modify;
7412 bi->bi_op_modrdn = config_back_modrdn;
7413 bi->bi_op_add = config_back_add;
7414 bi->bi_op_delete = config_back_delete;
7415 bi->bi_op_abandon = 0;
7417 bi->bi_extended = 0;
7419 bi->bi_chk_referrals = 0;
7421 bi->bi_access_allowed = slap_access_allowed;
7423 bi->bi_connection_init = 0;
7424 bi->bi_connection_destroy = 0;
7426 bi->bi_entry_release_rw = config_entry_release;
7427 bi->bi_entry_get_rw = config_back_entry_get;
7429 bi->bi_tool_entry_open = config_tool_entry_open;
7430 bi->bi_tool_entry_close = config_tool_entry_close;
7431 bi->bi_tool_entry_first = config_tool_entry_first;
7432 bi->bi_tool_entry_first_x = config_tool_entry_first_x;
7433 bi->bi_tool_entry_next = config_tool_entry_next;
7434 bi->bi_tool_entry_get = config_tool_entry_get;
7435 bi->bi_tool_entry_put = config_tool_entry_put;
7438 argv[ 0 ] = "slapd";
7444 for (i=0; OidMacros[i].name; i++ ) {
7445 argv[1] = OidMacros[i].name;
7446 argv[2] = OidMacros[i].oid;
7447 parse_oidm( &ca, 0, NULL );
7450 bi->bi_cf_ocs = cf_ocs;
7452 i = config_register_schema( ct, cf_ocs );
7455 i = slap_str2ad( "olcDatabase", &olcDatabaseDummy[0].ad, &text );
7458 /* setup olcRootPW to be base64-encoded when written in LDIF form;
7459 * basically, we don't care if it fails */
7460 i = slap_str2ad( "olcRootPW", &ad, &text );
7462 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
7463 "warning, unable to get \"olcRootPW\" "
7464 "attribute description: %d: %s\n",
7467 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
7468 ad->ad_type->sat_oid );
7471 /* set up the notable AttributeDescriptions */
7473 for (;ct->name;ct++) {
7474 if (strcmp(ct->name, ads[i].name)) continue;
7475 *ads[i].desc = ct->ad;
7477 if (!ads[i].name) break;