1 /* bconfig.c - the config backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005-2007 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>
32 #include "slapi/slapi.h"
40 #define CONFIG_RDN "cn=config"
41 #define SCHEMA_RDN "cn=schema"
43 static struct berval config_rdn = BER_BVC(CONFIG_RDN);
44 static struct berval schema_rdn = BER_BVC(SCHEMA_RDN);
46 extern int slap_DN_strict; /* dn.c */
49 typedef struct modpath_s {
50 struct modpath_s *mp_next;
51 struct berval mp_path;
55 static ModPaths modpaths, *modlast = &modpaths, *modcur = &modpaths;
58 typedef struct ConfigFile {
59 struct ConfigFile *c_sibs;
60 struct ConfigFile *c_kids;
62 AttributeType *c_at_head, *c_at_tail;
63 ContentRule *c_cr_head, *c_cr_tail;
64 ObjectClass *c_oc_head, *c_oc_tail;
65 OidMacro *c_om_head, *c_om_tail;
70 ConfigFile *cb_config;
72 BackendDB cb_db; /* underlying database */
77 static CfBackInfo cfBackInfo;
79 static char *passwd_salt;
81 static char *logfileName;
82 #ifdef SLAP_AUTH_REWRITE
83 static BerVarray authz_rewrites;
86 static struct berval cfdir;
89 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
90 *cfAd_include, *cfAd_attr, *cfAd_oc, *cfAd_om;
92 static ConfigFile *cfn;
94 static Avlnode *CfOcTree;
96 /* System schema state */
97 extern AttributeType *at_sys_tail; /* at.c */
98 extern ObjectClass *oc_sys_tail; /* oc.c */
99 extern OidMacro *om_sys_tail; /* oidm.c */
100 static AttributeType *cf_at_tail;
101 static ObjectClass *cf_oc_tail;
102 static OidMacro *cf_om_tail;
104 static int config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca,
105 SlapReply *rs, int *renumber, Operation *op );
107 static int config_check_schema( Operation *op, CfBackInfo *cfb );
109 static ConfigDriver config_fname;
110 static ConfigDriver config_cfdir;
111 static ConfigDriver config_generic;
112 static ConfigDriver config_search_base;
113 static ConfigDriver config_passwd_hash;
114 static ConfigDriver config_schema_dn;
115 static ConfigDriver config_sizelimit;
116 static ConfigDriver config_timelimit;
117 static ConfigDriver config_overlay;
118 static ConfigDriver config_subordinate;
119 static ConfigDriver config_suffix;
120 static ConfigDriver config_rootdn;
121 static ConfigDriver config_rootpw;
122 static ConfigDriver config_restrict;
123 static ConfigDriver config_allows;
124 static ConfigDriver config_disallows;
125 static ConfigDriver config_requires;
126 static ConfigDriver config_security;
127 static ConfigDriver config_referral;
128 static ConfigDriver config_loglevel;
129 static ConfigDriver config_updatedn;
130 static ConfigDriver config_updateref;
131 static ConfigDriver config_include;
132 static ConfigDriver config_obsolete;
134 static ConfigDriver config_tls_option;
135 static ConfigDriver config_tls_config;
137 extern ConfigDriver syncrepl_config;
190 static OidRec OidMacros[] = {
191 /* OpenLDAProot:666.11.1 */
192 { "OLcfg", "1.3.6.1.4.1.4203.666.11.1" },
193 { "OLcfgAt", "OLcfg:3" },
194 { "OLcfgGlAt", "OLcfgAt:0" },
195 { "OLcfgBkAt", "OLcfgAt:1" },
196 { "OLcfgDbAt", "OLcfgAt:2" },
197 { "OLcfgOvAt", "OLcfgAt:3" },
198 { "OLcfgCtAt", "OLcfgAt:4" }, /* contrib modules */
199 { "OLcfgOc", "OLcfg:4" },
200 { "OLcfgGlOc", "OLcfgOc:0" },
201 { "OLcfgBkOc", "OLcfgOc:1" },
202 { "OLcfgDbOc", "OLcfgOc:2" },
203 { "OLcfgOvOc", "OLcfgOc:3" },
204 { "OLcfgCtOc", "OLcfgOc:4" }, /* contrib modules */
206 /* Syntaxes. We should just start using the standard names and
207 * document that they are predefined and available for users
208 * to reference in their own schema. Defining schema without
209 * OID macros is for masochists...
211 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
212 { "OMsBoolean", "OMsyn:7" },
213 { "OMsDN", "OMsyn:12" },
214 { "OMsDirectoryString", "OMsyn:15" },
215 { "OMsIA5String", "OMsyn:26" },
216 { "OMsInteger", "OMsyn:27" },
217 { "OMsOID", "OMsyn:38" },
218 { "OMsOctetString", "OMsyn:40" },
223 * Backend/Database registry
225 * OLcfg{Bk|Db}{Oc|At}:0 -> common
226 * OLcfg{Bk|Db}{Oc|At}:1 -> back-bdb(/back-hdb)
227 * OLcfg{Bk|Db}{Oc|At}:2 -> back-ldif
228 * OLcfg{Bk|Db}{Oc|At}:3 -> back-ldap
229 * OLcfg{Bk|Db}{Oc|At}:4 -> back-monitor
230 * OLcfg{Bk|Db}{Oc|At}:5 -> back-relay
231 * OLcfg{Bk|Db}{Oc|At}:6 -> back-sql
237 * OLcfgOv{Oc|At}:1 -> syncprov
238 * OLcfgOv{Oc|At}:2 -> pcache
239 * OLcfgOv{Oc|At}:3 -> chain
240 * OLcfgOv{Oc|At}:4 -> accesslog
241 * OLcfgOv{Oc|At}:5 -> valsort
242 * OLcfgOv{Oc|At}:7 -> distproc
243 * OLcfgOv{Oc|At}:8 -> dynlist
244 * OLcfgOv{Oc|At}:9 -> dds
245 * OLcfgOv{Oc|At}:10 -> unique
246 * OLcfgOv{Oc|At}:11 -> refint
247 * OLcfgOv{Oc|At}:12 -> ppolicy
248 * OLcfgOv{Oc|At}:13 -> constraint
249 * OLcfgOv{Oc|At}:14 -> translucent
250 * OLcfgOv{Oc|At}:15 -> auditlog
251 * OLcfgOv{Oc|At}:16 -> rwm
252 * OLcfgOv{Oc|At}:17 -> dyngroup
253 * OLcfgOv{Oc|At}:18 -> memberof
254 * OLcfgOv{Oc|At}:19 -> collect
257 /* alphabetical ordering */
259 static ConfigTable config_back_cf_table[] = {
260 /* This attr is read-only */
261 { "", "", 0, 0, 0, ARG_MAGIC,
262 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
263 "DESC 'File for slapd configuration directives' "
264 "EQUALITY caseIgnoreMatch "
265 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
266 { "", "", 0, 0, 0, ARG_MAGIC,
267 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
268 "DESC 'Directory for slapd configuration backend' "
269 "EQUALITY caseIgnoreMatch "
270 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
271 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
272 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
273 "DESC 'Access Control List' "
274 "EQUALITY caseIgnoreMatch "
275 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
276 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
277 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
278 "DESC 'Allowed set of deprecated features' "
279 "EQUALITY caseIgnoreMatch "
280 "SYNTAX OMsDirectoryString )", NULL, NULL },
281 { "argsfile", "file", 2, 2, 0, ARG_STRING,
282 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
283 "DESC 'File for slapd command line options' "
284 "EQUALITY caseIgnoreMatch "
285 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
286 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
287 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
288 "EQUALITY caseIgnoreMatch "
289 "SYNTAX OMsDirectoryString )", NULL, NULL },
290 { "attribute", "attribute", 2, 0, STRLENOF( "attribute" ),
291 ARG_PAREN|ARG_MAGIC|CFG_ATTR,
292 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
293 "DESC 'OpenLDAP attributeTypes' "
294 "EQUALITY caseIgnoreMatch "
295 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
297 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
298 #ifdef SLAP_AUTH_REWRITE
299 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
303 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
304 "EQUALITY caseIgnoreMatch "
305 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
306 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
307 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
308 "EQUALITY caseIgnoreMatch "
309 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
310 { "authz-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
311 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
312 "EQUALITY caseIgnoreMatch "
313 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
314 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
315 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
316 "DESC 'A type of backend' "
317 "EQUALITY caseIgnoreMatch "
318 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
320 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
321 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
322 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
323 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
324 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
325 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
326 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
327 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
328 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
329 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
330 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
331 "DESC 'The backend type for a database instance' "
332 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
333 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
334 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
335 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
336 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
337 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
338 "EQUALITY caseIgnoreMatch "
339 "SYNTAX OMsDirectoryString )", NULL, NULL },
340 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
341 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
342 "DESC 'OpenLDAP DIT content rules' "
343 "EQUALITY caseIgnoreMatch "
344 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
346 { "gentlehup", "on|off", 2, 2, 0,
348 ARG_ON_OFF, &global_gentlehup,
352 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
353 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
354 { "hidden", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_HIDDEN,
355 &config_generic, "( OLcfgDbAt:0.17 NAME 'olcHidden' "
356 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
357 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
358 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
359 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
360 { "include", "file", 2, 2, 0, ARG_MAGIC,
361 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
362 "SUP labeledURI )", NULL, NULL },
363 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
364 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
365 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
366 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
367 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
368 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
369 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
370 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
371 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
372 { "index_substr_any_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
373 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
374 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
375 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
376 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
377 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
378 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
379 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
380 "EQUALITY caseIgnoreMatch "
381 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
382 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
383 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
384 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
385 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
386 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
387 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
388 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
389 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
390 "EQUALITY caseIgnoreMatch "
391 "SYNTAX OMsDirectoryString )", NULL, NULL },
392 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
393 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
394 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
395 { "mirrormode", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_MIRRORMODE,
396 &config_generic, "( OLcfgDbAt:0.16 NAME 'olcMirrorMode' "
397 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
398 { "moduleload", "file", 2, 0, 0,
400 ARG_MAGIC|CFG_MODLOAD|ARG_NO_DELETE, &config_generic,
404 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
405 "EQUALITY caseIgnoreMatch "
406 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
407 { "modulepath", "path", 2, 2, 0,
409 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
413 "( OLcfgGlAt:31 NAME 'olcModulePath' "
414 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
415 { "monitoring", "TRUE|FALSE", 2, 2, 0,
416 ARG_MAGIC|CFG_MONITORING|ARG_DB|ARG_ON_OFF, &config_generic,
417 "( OLcfgDbAt:0.18 NAME 'olcMonitoring' "
418 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
419 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
420 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
421 "DESC 'OpenLDAP object classes' "
422 "EQUALITY caseIgnoreMatch "
423 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
425 { "objectidentifier", "name> <oid", 3, 3, 0, ARG_MAGIC|CFG_OID,
426 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
427 "EQUALITY caseIgnoreMatch "
428 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
429 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
430 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
431 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
432 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
433 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
434 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
435 { "password-hash", "hash", 2, 2, 0, ARG_MAGIC,
436 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
437 "EQUALITY caseIgnoreMatch "
438 "SYNTAX OMsDirectoryString )", NULL, NULL },
439 { "pidfile", "file", 2, 2, 0, ARG_STRING,
440 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
441 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
442 { "plugin", NULL, 0, 0, 0,
444 ARG_MAGIC|CFG_PLUGIN, &config_generic,
448 "( OLcfgGlAt:38 NAME 'olcPlugin' "
449 "EQUALITY caseIgnoreMatch "
450 "SYNTAX OMsDirectoryString )", NULL, NULL },
451 { "pluginlog", "filename", 2, 2, 0,
453 ARG_STRING, &slapi_log_file,
457 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
458 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
459 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
460 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
461 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
462 { "referral", "url", 2, 2, 0, ARG_MAGIC,
463 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
464 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
465 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
466 &config_obsolete, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
467 "EQUALITY caseIgnoreMatch "
468 "SUP labeledURI X-ORDERED 'VALUES' )", NULL, NULL },
469 { "replica-argsfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
470 &config_obsolete, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
471 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
472 { "replica-pidfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
473 &config_obsolete, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
474 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
475 { "replicationInterval", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
476 &config_obsolete, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
477 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
478 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC,
479 &config_obsolete, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
480 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
481 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
482 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
483 "EQUALITY caseIgnoreMatch "
484 "SYNTAX OMsDirectoryString )", NULL, NULL },
485 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
486 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
487 "EQUALITY caseIgnoreMatch "
488 "SYNTAX OMsDirectoryString )", NULL, NULL },
489 { "reverse-lookup", "on|off", 2, 2, 0,
490 #ifdef SLAPD_RLOOKUPS
491 ARG_ON_OFF, &use_reverse_lookup,
495 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
496 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
497 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
498 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
499 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
500 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
501 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
502 "EQUALITY caseIgnoreMatch "
503 "SYNTAX OMsDirectoryString )", NULL, NULL },
504 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
505 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
506 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
507 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
508 &config_generic, NULL, NULL, NULL },
509 { "sasl-host", "host", 2, 2, 0,
510 #ifdef HAVE_CYRUS_SASL
511 ARG_STRING|ARG_UNIQUE, &sasl_host,
515 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
516 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
517 { "sasl-realm", "realm", 2, 2, 0,
518 #ifdef HAVE_CYRUS_SASL
519 ARG_STRING|ARG_UNIQUE, &global_realm,
523 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
524 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
525 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
526 &config_generic, NULL, NULL, NULL },
527 { "sasl-secprops", "properties", 2, 2, 0,
528 #ifdef HAVE_CYRUS_SASL
529 ARG_MAGIC|CFG_SASLSECP, &config_generic,
533 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
534 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
535 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
536 &config_generic, NULL, NULL, NULL },
537 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
538 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
539 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
540 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
541 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
542 "EQUALITY caseIgnoreMatch "
543 "SYNTAX OMsDirectoryString )", NULL, NULL },
544 { "serverID", "number> <[URI]", 2, 3, 0, ARG_MAGIC|CFG_SERVERID,
545 &config_generic, "( OLcfgGlAt:81 NAME 'olcServerID' "
546 "EQUALITY caseIgnoreMatch "
547 "SYNTAX OMsDirectoryString )", NULL, NULL },
548 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
549 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
550 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
551 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
552 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
553 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
554 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
555 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
556 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
557 { "sortvals", "attr", 2, 0, 0, ARG_MAGIC|CFG_SORTVALS,
558 &config_generic, "( OLcfgGlAt:83 NAME 'olcSortVals' "
559 "DESC 'Attributes whose values will always be sorted' "
560 "EQUALITY caseIgnoreMatch "
561 "SYNTAX OMsDirectoryString )", NULL, NULL },
562 { "subordinate", "[advertise]", 1, 2, 0, ARG_DB|ARG_MAGIC,
563 &config_subordinate, "( OLcfgDbAt:0.15 NAME 'olcSubordinate' "
564 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
565 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
566 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
567 "EQUALITY distinguishedNameMatch "
568 "SYNTAX OMsDN )", NULL, NULL },
569 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
570 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
571 "EQUALITY caseIgnoreMatch "
572 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
573 { "threads", "count", 2, 2, 0,
577 ARG_INT|ARG_MAGIC|CFG_THREADS, &config_generic,
579 "( OLcfgGlAt:66 NAME 'olcThreads' "
580 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
581 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
582 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
583 "SYNTAX OMsDirectoryString )", NULL, NULL },
584 { "TLSCACertificateFile", NULL, 0, 0, 0,
586 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
590 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
591 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
592 { "TLSCACertificatePath", NULL, 0, 0, 0,
594 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
598 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
599 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
600 { "TLSCertificateFile", NULL, 0, 0, 0,
602 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
606 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
607 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
608 { "TLSCertificateKeyFile", NULL, 0, 0, 0,
610 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
614 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
615 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
616 { "TLSCipherSuite", NULL, 0, 0, 0,
618 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
622 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
623 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
624 { "TLSCRLCheck", NULL, 0, 0, 0,
625 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
626 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
630 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
631 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
632 { "TLSCRLFile", NULL, 0, 0, 0,
633 #if defined(HAVE_GNUTLS)
634 CFG_TLS_CRL_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
638 "( OLcfgGlAt:82 NAME 'olcTLSCRLFile' "
639 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
640 { "TLSRandFile", NULL, 0, 0, 0,
642 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
646 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
647 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
648 { "TLSVerifyClient", NULL, 0, 0, 0,
650 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
654 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
655 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
656 { "TLSDHParamFile", NULL, 0, 0, 0,
658 CFG_TLS_DH_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
662 "( OLcfgGlAt:77 NAME 'olcTLSDHParamFile' "
663 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
664 { "tool-threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_TTHREADS,
665 &config_generic, "( OLcfgGlAt:80 NAME 'olcToolThreads' "
666 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
667 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
668 NULL, NULL, NULL, NULL },
669 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
670 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
671 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
672 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
673 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
674 "EQUALITY caseIgnoreMatch "
675 "SUP labeledURI )", NULL, NULL },
676 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
677 NULL, NULL, NULL, NULL }
680 /* Routines to check if a child can be added to this type */
681 static ConfigLDAPadd cfAddSchema, cfAddInclude, cfAddDatabase,
682 cfAddBackend, cfAddModule, cfAddOverlay;
684 /* NOTE: be careful when defining array members
685 * that can be conditionally compiled */
686 #define CFOC_GLOBAL cf_ocs[1]
687 #define CFOC_SCHEMA cf_ocs[2]
688 #define CFOC_BACKEND cf_ocs[3]
689 #define CFOC_DATABASE cf_ocs[4]
690 #define CFOC_OVERLAY cf_ocs[5]
691 #define CFOC_INCLUDE cf_ocs[6]
692 #define CFOC_FRONTEND cf_ocs[7]
694 #define CFOC_MODULE cf_ocs[8]
695 #endif /* SLAPD_MODULES */
697 static ConfigOCs cf_ocs[] = {
700 "DESC 'OpenLDAP configuration object' "
701 "ABSTRACT SUP top )", Cft_Abstract, NULL },
704 "DESC 'OpenLDAP Global configuration options' "
705 "SUP olcConfig STRUCTURAL "
706 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
707 "olcAttributeOptions $ olcAuthIDRewrite $ "
708 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
709 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
710 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
711 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
712 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcLocalSSF $ "
714 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
715 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
716 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
718 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
719 "olcSecurity $ olcServerID $ olcSizeLimit $ "
720 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ "
721 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
722 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
723 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
724 "olcTLSRandFile $ olcTLSVerifyClient $ olcTLSDHParamFile $ "
725 "olcTLSCRLFile $ olcToolThreads $ "
726 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
727 "olcDitContentRules ) )", Cft_Global },
729 "NAME 'olcSchemaConfig' "
730 "DESC 'OpenLDAP schema object' "
731 "SUP olcConfig STRUCTURAL "
732 "MAY ( cn $ olcObjectIdentifier $ olcAttributeTypes $ "
733 "olcObjectClasses $ olcDitContentRules ) )",
734 Cft_Schema, NULL, cfAddSchema },
736 "NAME 'olcBackendConfig' "
737 "DESC 'OpenLDAP Backend-specific options' "
738 "SUP olcConfig STRUCTURAL "
739 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
741 "NAME 'olcDatabaseConfig' "
742 "DESC 'OpenLDAP Database-specific options' "
743 "SUP olcConfig STRUCTURAL "
745 "MAY ( olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
746 "olcLastMod $ olcLimits $ "
747 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
748 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
749 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
750 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncrepl $ "
751 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef $ olcMirrorMode $ "
753 Cft_Database, NULL, cfAddDatabase },
755 "NAME 'olcOverlayConfig' "
756 "DESC 'OpenLDAP Overlay-specific options' "
757 "SUP olcConfig STRUCTURAL "
758 "MUST olcOverlay )", Cft_Overlay, NULL, cfAddOverlay },
760 "NAME 'olcIncludeFile' "
761 "DESC 'OpenLDAP configuration include file' "
762 "SUP olcConfig STRUCTURAL "
764 "MAY ( cn $ olcRootDSE ) )",
765 /* Used to be Cft_Include, that def has been removed */
766 Cft_Abstract, NULL, cfAddInclude },
767 /* This should be STRUCTURAL like all the other database classes, but
768 * that would mean inheriting all of the olcDatabaseConfig attributes,
769 * which causes them to be merged twice in config_build_entry.
772 "NAME 'olcFrontendConfig' "
773 "DESC 'OpenLDAP frontend configuration' "
775 "MAY ( olcDefaultSearchBase $ olcPasswordHash $ olcSortVals ) )",
776 Cft_Database, NULL, NULL },
779 "NAME 'olcModuleList' "
780 "DESC 'OpenLDAP dynamic module info' "
781 "SUP olcConfig STRUCTURAL "
782 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
783 Cft_Module, NULL, cfAddModule },
788 typedef struct ServerID {
789 struct ServerID *si_next;
790 struct berval si_url;
794 static ServerID *sid_list;
796 typedef struct ADlist {
797 struct ADlist *al_next;
798 AttributeDescription *al_desc;
801 static ADlist *sortVals;
804 config_generic(ConfigArgs *c) {
807 if ( c->op == SLAP_CONFIG_EMIT ) {
811 c->value_int = ldap_pvt_thread_get_concurrency();
814 c->value_int = connection_pool_max;
817 c->value_int = slap_tool_thread_max;
821 c->value_string = ch_strdup( passwd_salt );
826 if ( c->be->be_limits ) {
830 for ( i=0; c->be->be_limits[i]; i++ ) {
831 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
832 if ( bv.bv_len >= sizeof( buf ) ) {
833 ber_bvarray_free_x( c->rvalue_vals, NULL );
834 c->rvalue_vals = NULL;
838 bv.bv_val = buf + bv.bv_len;
839 limits_unparse( c->be->be_limits[i], &bv,
840 sizeof( buf ) - ( bv.bv_val - buf ) );
841 bv.bv_len += bv.bv_val - buf;
843 value_add_one( &c->rvalue_vals, &bv );
846 if ( !c->rvalue_vals ) rc = 1;
849 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_OP_WRITES) ==
850 SLAP_RESTRICT_OP_WRITES;
853 c->value_string = ch_strdup( slap_sasl_getpolicy());
856 slap_sasl_regexp_unparse( &c->rvalue_vals );
857 if ( !c->rvalue_vals ) rc = 1;
859 #ifdef HAVE_CYRUS_SASL
861 struct berval bv = BER_BVNULL;
862 slap_sasl_secprops_unparse( &bv );
863 if ( !BER_BVISNULL( &bv )) {
864 ber_bvarray_add( &c->rvalue_vals, &bv );
872 c->value_int = c->be->be_max_deref_depth;
875 if ( SLAP_DBHIDDEN( c->be )) {
882 ConfigFile *cf = c->private;
884 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
885 else if ( cf->c_om_head )
886 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
888 if ( !c->rvalue_vals )
893 ad_unparse_options( &c->rvalue_vals );
896 ConfigFile *cf = c->private;
898 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
899 else if ( cf->c_oc_head )
900 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
902 if ( !c->rvalue_vals )
907 ConfigFile *cf = c->private;
909 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
910 else if ( cf->c_at_head )
911 at_unparse( &c->rvalue_vals, cf->c_at_head,
913 if ( !c->rvalue_vals )
918 ConfigFile *cf = c->private;
920 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
921 else if ( cf->c_cr_head )
922 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
924 if ( !c->rvalue_vals )
931 char *src, *dst, ibuf[11];
932 struct berval bv, abv;
933 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
934 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
935 if ( abv.bv_len >= sizeof( ibuf ) ) {
936 ber_bvarray_free_x( c->rvalue_vals, NULL );
937 c->rvalue_vals = NULL;
941 acl_unparse( a, &bv );
942 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
943 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
944 /* Turn TAB / EOL into plain space */
945 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
946 if (isspace((unsigned char)*src)) *dst++ = ' ';
950 if (dst[-1] == ' ') {
954 abv.bv_len = dst - abv.bv_val;
955 ber_bvarray_add( &c->rvalue_vals, &abv );
961 ConfigFile *cf = c->private;
962 if ( cf->c_dseFiles ) {
963 value_add( &c->rvalue_vals, cf->c_dseFiles );
974 for ( si = sid_list; si; si=si->si_next ) {
975 assert( si->si_num >= 0 && si->si_num <= SLAP_SYNC_SID_MAX );
976 if ( !BER_BVISEMPTY( &si->si_url )) {
977 bv.bv_len = si->si_url.bv_len + 6;
978 bv.bv_val = ch_malloc( bv.bv_len );
979 sprintf( bv.bv_val, "%d %s", si->si_num,
981 ber_bvarray_add( &c->rvalue_vals, &bv );
985 bv.bv_len = sprintf( buf, "%d", si->si_num );
986 value_add_one( &c->rvalue_vals, &bv );
995 c->value_string = ch_strdup( logfileName );
1000 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1002 case CFG_MIRRORMODE:
1003 if ( SLAP_SHADOW(c->be))
1004 c->value_int = (SLAP_SINGLE_SHADOW(c->be) == 0);
1008 case CFG_MONITORING:
1009 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
1011 case CFG_SSTR_IF_MAX:
1012 c->value_int = index_substr_if_maxlen;
1014 case CFG_SSTR_IF_MIN:
1015 c->value_int = index_substr_if_minlen;
1017 case CFG_SORTVALS: {
1020 for ( sv = sortVals; sv; sv = sv->al_next ) {
1021 value_add_one( &c->rvalue_vals, &sv->al_desc->ad_cname );
1025 #ifdef SLAPD_MODULES
1027 ModPaths *mp = c->private;
1030 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
1033 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
1034 SLAP_X_ORDERED_FMT "%s", i,
1035 mp->mp_loads[i].bv_val );
1036 if ( bv.bv_len >= sizeof( c->log ) ) {
1037 ber_bvarray_free_x( c->rvalue_vals, NULL );
1038 c->rvalue_vals = NULL;
1041 value_add_one( &c->rvalue_vals, &bv );
1045 rc = c->rvalue_vals ? 0 : 1;
1049 ModPaths *mp = c->private;
1050 if ( !BER_BVISNULL( &mp->mp_path ))
1051 value_add_one( &c->rvalue_vals, &mp->mp_path );
1053 rc = c->rvalue_vals ? 0 : 1;
1059 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1060 if ( !c->rvalue_vals ) rc = 1;
1063 #ifdef SLAP_AUTH_REWRITE
1065 if ( authz_rewrites ) {
1066 struct berval bv, idx;
1071 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1072 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1073 if ( idx.bv_len >= sizeof( ibuf ) ) {
1074 ber_bvarray_free_x( c->rvalue_vals, NULL );
1075 c->rvalue_vals = NULL;
1078 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1079 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1080 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1081 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1082 authz_rewrites[i].bv_val,
1083 authz_rewrites[i].bv_len + 1 );
1084 ber_bvarray_add( &c->rvalue_vals, &bv );
1087 if ( !c->rvalue_vals ) rc = 1;
1094 } else if ( c->op == LDAP_MOD_DELETE ) {
1097 /* single-valued attrs, no-ops */
1105 case CFG_MIRRORMODE:
1106 case CFG_MONITORING:
1108 case CFG_SSTR_IF_MAX:
1109 case CFG_SSTR_IF_MIN:
1112 /* no-ops, requires slapd restart */
1117 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1121 ch_free( passwd_salt );
1126 ch_free( logfileName );
1134 case CFG_SERVERID: {
1135 ServerID *si, **sip;
1137 for ( i=0, si = sid_list, sip = &sid_list;
1138 si; si = *sip, i++ ) {
1139 if ( c->valx == -1 || i == c->valx ) {
1151 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1155 if ( c->valx < 0 ) {
1157 if ( c->be == frontendDB )
1160 end = frontendDB->be_acl;
1161 acl_destroy( c->be->be_acl, end );
1162 c->be->be_acl = end;
1165 AccessControl **prev, *a;
1167 for (i=0, prev = &c->be->be_acl; i < c->valx;
1170 prev = &a->acl_next;
1173 *prev = a->acl_next;
1180 /* Can be NULL when undoing a failed add */
1181 if ( c->ca_entry ) {
1182 ce = c->ca_entry->e_private;
1183 /* can't modify the hardcoded schema */
1184 if ( ce->ce_parent->ce_type == Cft_Global )
1189 if ( c->valx < 0 ) {
1192 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1194 if ( oc == cfn->c_oc_tail )
1197 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1199 ObjectClass *oc, *prev = NULL;
1201 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1206 if ( cfn->c_oc_tail == oc ) {
1207 cfn->c_oc_tail = prev;
1209 if ( cfn->c_oc_head == oc ) {
1211 cfn->c_oc_head = oc;
1218 /* Can be NULL when undoing a failed add */
1219 if ( c->ca_entry ) {
1220 ce = c->ca_entry->e_private;
1221 /* can't modify the hardcoded schema */
1222 if ( ce->ce_parent->ce_type == Cft_Global )
1227 if ( c->valx < 0 ) {
1230 for( at = cfn->c_at_head; at; at_next( &at )) {
1232 if ( at == cfn->c_at_tail )
1235 cfn->c_at_head = cfn->c_at_tail = NULL;
1237 AttributeType *at, *prev = NULL;
1239 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1244 if ( cfn->c_at_tail == at ) {
1245 cfn->c_at_tail = prev;
1247 if ( cfn->c_at_head == at ) {
1249 cfn->c_at_head = at;
1254 if ( c->valx < 0 ) {
1256 for ( sv = sortVals; sv; sv = sortVals ) {
1257 sortVals = sv->al_next;
1258 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1265 for ( prev = &sortVals, sv = sortVals; i < c->valx; i++ ) {
1266 prev = &sv->al_next;
1269 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1270 *prev = sv->al_next;
1276 /* FIXME: there is no limits_free function */
1278 /* FIXME: there is no ad_option_free function */
1280 /* FIXME: there is no way to remove attributes added by
1294 if(!(c->bi = backend_info(c->argv[1]))) {
1295 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1296 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1297 c->log, c->cr_msg, c->argv[1] );
1304 /* NOTE: config is always the first backend!
1306 if ( !strcasecmp( c->argv[1], "config" )) {
1307 c->be = LDAP_STAILQ_FIRST(&backendDB);
1308 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1311 c->be = backend_db_init(c->argv[1], NULL, c->valx, &c->reply);
1313 if ( c->cr_msg[0] == 0 )
1314 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1315 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n", c->log, c->cr_msg, c->argv[1] );
1322 ldap_pvt_thread_set_concurrency(c->value_int);
1326 if ( c->value_int < 2 ) {
1327 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1328 "threads=%d smaller than minimum value 2",
1330 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1331 c->log, c->cr_msg, 0 );
1334 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1335 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1336 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1337 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1338 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1339 c->log, c->cr_msg, 0 );
1341 if ( slapMode & SLAP_SERVER_MODE )
1342 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1343 connection_pool_max = c->value_int; /* save for reference */
1347 if ( slapMode & SLAP_TOOL_MODE )
1348 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1349 slap_tool_thread_max = c->value_int; /* save for reference */
1353 if ( passwd_salt ) ch_free( passwd_salt );
1354 passwd_salt = c->value_string;
1355 lutil_salt_format(passwd_salt);
1359 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1365 c->be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1367 c->be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1371 ch_free(c->value_string);
1372 if (slap_sasl_setpolicy( c->argv[1] )) {
1373 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
1374 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1375 c->log, c->cr_msg, c->argv[1] );
1381 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1385 #ifdef HAVE_CYRUS_SASL
1388 char *txt = slap_sasl_secprops( c->argv[1] );
1390 snprintf( c->cr_msg, sizeof(c->cr_msg), "<%s> %s",
1392 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0 );
1400 c->be->be_max_deref_depth = c->value_int;
1406 if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private )
1408 if(parse_oidm(c, 1, &om))
1410 if (!cfn->c_om_head) cfn->c_om_head = om;
1411 cfn->c_om_tail = om;
1416 ObjectClass *oc, *prev;
1418 if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private )
1420 if ( c->valx < 0 ) {
1421 prev = cfn->c_oc_tail;
1424 /* If adding anything after the first, prev is easy */
1427 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
1432 /* If adding the first, and head exists, find its prev */
1433 if (cfn->c_oc_head) {
1434 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
1439 /* else prev is NULL, append to end of global list */
1441 if(parse_oc(c, &oc, prev)) return(1);
1442 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1443 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
1448 AttributeType *at, *prev;
1450 if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private )
1452 if ( c->valx < 0 ) {
1453 prev = cfn->c_at_tail;
1456 /* If adding anything after the first, prev is easy */
1459 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
1464 /* If adding the first, and head exists, find its prev */
1465 if (cfn->c_at_head) {
1466 for ( at_start( &at ); at != cfn->c_at_head; ) {
1471 /* else prev is NULL, append to end of global list */
1473 if(parse_at(c, &at, prev)) return(1);
1474 if (!cfn->c_at_head) cfn->c_at_head = at;
1475 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
1482 if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private )
1484 if(parse_cr(c, &cr)) return(1);
1485 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1486 cfn->c_cr_tail = cr;
1491 ad_define_option(NULL, NULL, 0);
1492 for(i = 1; i < c->argc; i++)
1493 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1497 case CFG_SORTVALS: {
1498 ADlist *svnew = NULL, *svtail, *sv;
1500 for ( i = 1; i < c->argc; i++ ) {
1501 AttributeDescription *ad = NULL;
1505 rc = slap_str2ad( c->argv[i], &ad, &text );
1507 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown attribute type #%d",
1510 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1511 c->log, c->cr_msg, c->argv[i] );
1512 for ( sv = svnew; sv; sv = svnew ) {
1513 svnew = sv->al_next;
1518 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) ||
1519 ad->ad_type->sat_single_value ) {
1520 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> inappropriate attribute type #%d",
1522 goto sortval_reject;
1524 sv = ch_malloc( sizeof( ADlist ));
1529 svtail->al_next = sv;
1534 for ( sv = svnew; sv; sv = sv->al_next )
1535 sv->al_desc->ad_type->sat_flags |= SLAP_AT_SORTED_VAL;
1536 for ( sv = sortVals; sv && sv->al_next; sv = sv->al_next );
1538 sv->al_next = svnew;
1545 /* Don't append to the global ACL if we're on a specific DB */
1547 if ( c->be != frontendDB && frontendDB->be_acl && c->valx == -1 ) {
1550 for ( a=c->be->be_acl; a && a != frontendDB->be_acl;
1554 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
1560 if(root_dse_read_file(c->argv[1])) {
1561 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> could not read file", c->argv[0] );
1562 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1563 c->log, c->cr_msg, c->argv[1] );
1568 ber_str2bv( c->argv[1], 0, 1, &bv );
1569 if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private )
1571 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1577 ServerID *si, **sip;
1580 if ( lutil_atoi( &num, c->argv[1] ) ||
1581 num < 0 || num > SLAP_SYNC_SID_MAX )
1583 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1584 "<%s> illegal server ID", c->argv[0] );
1585 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1586 c->log, c->cr_msg, c->argv[1] );
1589 /* only one value allowed if no URL is given */
1590 if ( c->argc > 2 ) {
1593 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
1594 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1595 "<%s> only one server ID allowed now", c->argv[0] );
1596 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1597 c->log, c->cr_msg, c->argv[1] );
1601 if ( ldap_url_parse( c->argv[2], &lud )) {
1602 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1603 "<%s> invalid URL", c->argv[0] );
1604 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1605 c->log, c->cr_msg, c->argv[2] );
1608 len = strlen( c->argv[2] );
1609 si = ch_malloc( sizeof(ServerID) + len + 1 );
1610 si->si_url.bv_val = (char *)(si+1);
1611 si->si_url.bv_len = len;
1612 strcpy( si->si_url.bv_val, c->argv[2] );
1615 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1616 "<%s> unqualified server ID not allowed now", c->argv[0] );
1617 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1618 c->log, c->cr_msg, c->argv[1] );
1621 si = ch_malloc( sizeof(ServerID) );
1622 BER_BVZERO( &si->si_url );
1623 slap_serverID = num;
1624 Debug( LDAP_DEBUG_CONFIG,
1626 c->log, slap_serverID, 0 );
1630 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
1633 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
1634 /* If hostname is empty, or is localhost, or matches
1635 * our hostname, this serverID refers to this host.
1636 * Compare it against listeners and ports.
1638 if ( !lud->lud_host || !lud->lud_host[0] ||
1639 !strncasecmp("localhost", lud->lud_host,
1640 STRLENOF("localhost")) ||
1641 !strcasecmp( global_host, lud->lud_host )) {
1642 Listener **l = slapd_get_listeners();
1645 for ( i=0; l[i]; i++ ) {
1648 ldap_url_parse( l[i]->sl_url.bv_val, &lu2 );
1650 if ( strcasecmp( lud->lud_scheme,
1653 if ( lud->lud_port != lu2->lud_port )
1655 /* Listener on ANY address */
1656 if ( !lu2->lud_host || !lu2->lud_host[0] ) {
1660 /* URL on ANY address */
1661 if ( !lud->lud_host || !lud->lud_host[0] ) {
1665 /* Listener has specific host, must
1668 if ( !strcasecmp( lud->lud_host,
1674 ldap_free_urldesc( lu2 );
1676 slap_serverID = si->si_num;
1677 Debug( LDAP_DEBUG_CONFIG,
1678 "%s: SID=%d (listener=%s)\n",
1679 c->log, slap_serverID,
1680 l[i]->sl_url.bv_val );
1687 ldap_free_urldesc( lud );
1691 if ( logfileName ) ch_free( logfileName );
1692 logfileName = c->value_string;
1693 logfile = fopen(logfileName, "w");
1694 if(logfile) lutil_debug_file(logfile);
1698 if(SLAP_NOLASTMODCMD(c->be)) {
1699 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> not available for %s database",
1700 c->argv[0], c->be->bd_info->bi_type );
1701 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1702 c->log, c->cr_msg, 0 );
1706 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1708 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1711 case CFG_MIRRORMODE:
1712 if(!SLAP_SHADOW(c->be)) {
1713 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database is not a shadow",
1715 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1716 c->log, c->cr_msg, 0 );
1720 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
1722 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1725 case CFG_MONITORING:
1727 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
1729 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
1734 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
1736 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
1739 case CFG_SSTR_IF_MAX:
1740 if (c->value_int < index_substr_if_minlen) {
1741 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1742 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1743 c->log, c->cr_msg, c->value_int );
1746 index_substr_if_maxlen = c->value_int;
1749 case CFG_SSTR_IF_MIN:
1750 if (c->value_int > index_substr_if_maxlen) {
1751 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1752 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1753 c->log, c->cr_msg, c->value_int );
1756 index_substr_if_minlen = c->value_int;
1759 #ifdef SLAPD_MODULES
1761 /* If we're just adding a module on an existing modpath,
1762 * make sure we've selected the current path.
1764 if ( c->op == LDAP_MOD_ADD && c->private && modcur != c->private ) {
1765 modcur = c->private;
1766 /* This should never fail */
1767 if ( module_path( modcur->mp_path.bv_val )) {
1768 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> module path no longer valid",
1770 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1771 c->log, c->cr_msg, modcur->mp_path.bv_val );
1775 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1777 /* Record this load on the current path */
1781 if ( c->op == SLAP_CONFIG_ADD ) {
1782 ptr = c->line + STRLENOF("moduleload");
1783 while (!isspace((unsigned char) *ptr)) ptr++;
1784 while (isspace((unsigned char) *ptr)) ptr++;
1788 ber_str2bv(ptr, 0, 1, &bv);
1789 ber_bvarray_add( &modcur->mp_loads, &bv );
1791 /* Check for any new hardcoded schema */
1792 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
1793 config_check_schema( NULL, &cfBackInfo );
1798 if(module_path(c->argv[1])) return(1);
1799 /* Record which path was used with each module */
1803 if (!modpaths.mp_loads) {
1806 mp = ch_malloc( sizeof( ModPaths ));
1807 modlast->mp_next = mp;
1809 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1811 mp->mp_loads = NULL;
1822 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
1824 slapi_plugins_used++;
1828 #ifdef SLAP_AUTH_REWRITE
1833 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
1836 if ( c->argc > 1 ) {
1839 /* quote all args but the first */
1840 line = ldap_charray2str( c->argv, "\" \"" );
1841 ber_str2bv( line, 0, 0, &bv );
1842 s = ber_bvchr( &bv, '"' );
1843 assert( s != NULL );
1844 /* move the trailing quote of argv[0] to the end */
1845 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
1846 bv.bv_val[ bv.bv_len - 1 ] = '"';
1849 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
1852 ber_bvarray_add( &authz_rewrites, &bv );
1859 Debug( LDAP_DEBUG_ANY,
1860 "%s: unknown CFG_TYPE %d.\n",
1861 c->log, c->type, 0 );
1870 config_fname(ConfigArgs *c) {
1871 if(c->op == SLAP_CONFIG_EMIT) {
1873 ConfigFile *cf = c->private;
1874 value_add_one( &c->rvalue_vals, &cf->c_file );
1883 config_cfdir(ConfigArgs *c) {
1884 if(c->op == SLAP_CONFIG_EMIT) {
1885 if ( !BER_BVISEMPTY( &cfdir )) {
1886 value_add_one( &c->rvalue_vals, &cfdir );
1895 config_search_base(ConfigArgs *c) {
1896 if(c->op == SLAP_CONFIG_EMIT) {
1898 if (!BER_BVISEMPTY(&default_search_base)) {
1899 value_add_one(&c->rvalue_vals, &default_search_base);
1900 value_add_one(&c->rvalue_nvals, &default_search_nbase);
1904 } else if( c->op == LDAP_MOD_DELETE ) {
1905 ch_free( default_search_base.bv_val );
1906 ch_free( default_search_nbase.bv_val );
1907 BER_BVZERO( &default_search_base );
1908 BER_BVZERO( &default_search_nbase );
1912 if(c->bi || c->be != frontendDB) {
1913 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
1914 "prior to any backend or database definition\n",
1919 if(default_search_nbase.bv_len) {
1920 free(default_search_base.bv_val);
1921 free(default_search_nbase.bv_val);
1924 default_search_base = c->value_dn;
1925 default_search_nbase = c->value_ndn;
1929 /* For RE23 compatibility we allow this in the global entry
1930 * but we now defer it to the frontend entry to allow modules
1931 * to load new hash types.
1934 config_passwd_hash(ConfigArgs *c) {
1936 if (c->op == SLAP_CONFIG_EMIT) {
1938 /* Don't generate it in the global entry */
1939 if ( c->table == Cft_Global )
1941 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
1942 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
1943 value_add_one(&c->rvalue_vals, &bv);
1946 } else if ( c->op == LDAP_MOD_DELETE ) {
1947 /* Deleting from global is a no-op, only the frontendDB entry matters */
1948 if ( c->table == Cft_Global )
1950 if ( c->valx < 0 ) {
1951 ldap_charray_free( default_passwd_hash );
1952 default_passwd_hash = NULL;
1955 ch_free( default_passwd_hash[i] );
1956 for (; default_passwd_hash[i]; i++ )
1957 default_passwd_hash[i] = default_passwd_hash[i+1];
1961 for(i = 1; i < c->argc; i++) {
1962 if(!lutil_passwd_scheme(c->argv[i])) {
1963 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> scheme not available", c->argv[0] );
1964 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1965 c->log, c->cr_msg, c->argv[i]);
1967 ldap_charray_add(&default_passwd_hash, c->argv[i]);
1970 if(!default_passwd_hash) {
1971 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> no valid hashes found", c->argv[0] );
1972 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1973 c->log, c->cr_msg, 0 );
1980 config_schema_dn(ConfigArgs *c) {
1981 if ( c->op == SLAP_CONFIG_EMIT ) {
1983 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
1984 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
1985 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
1989 } else if ( c->op == LDAP_MOD_DELETE ) {
1990 ch_free( c->be->be_schemadn.bv_val );
1991 ch_free( c->be->be_schemandn.bv_val );
1992 BER_BVZERO( &c->be->be_schemadn );
1993 BER_BVZERO( &c->be->be_schemandn );
1996 ch_free( c->be->be_schemadn.bv_val );
1997 ch_free( c->be->be_schemandn.bv_val );
1998 c->be->be_schemadn = c->value_dn;
1999 c->be->be_schemandn = c->value_ndn;
2004 config_sizelimit(ConfigArgs *c) {
2006 struct slap_limits_set *lim = &c->be->be_def_limit;
2007 if (c->op == SLAP_CONFIG_EMIT) {
2012 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
2013 if ( !BER_BVISEMPTY( &bv ))
2014 value_add_one( &c->rvalue_vals, &bv );
2018 } else if ( c->op == LDAP_MOD_DELETE ) {
2019 /* Reset to defaults */
2020 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
2021 lim->lms_s_hard = 0;
2022 lim->lms_s_unchecked = -1;
2024 lim->lms_s_pr_hide = 0;
2025 lim->lms_s_pr_total = 0;
2028 for(i = 1; i < c->argc; i++) {
2029 if(!strncasecmp(c->argv[i], "size", 4)) {
2030 rc = limits_parse_one(c->argv[i], lim);
2032 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2033 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2034 c->log, c->cr_msg, c->argv[i]);
2038 if(!strcasecmp(c->argv[i], "unlimited")) {
2039 lim->lms_s_soft = -1;
2041 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
2042 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2043 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2044 c->log, c->cr_msg, c->argv[i]);
2048 lim->lms_s_hard = 0;
2055 config_timelimit(ConfigArgs *c) {
2057 struct slap_limits_set *lim = &c->be->be_def_limit;
2058 if (c->op == SLAP_CONFIG_EMIT) {
2063 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
2064 if ( !BER_BVISEMPTY( &bv ))
2065 value_add_one( &c->rvalue_vals, &bv );
2069 } else if ( c->op == LDAP_MOD_DELETE ) {
2070 /* Reset to defaults */
2071 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
2072 lim->lms_t_hard = 0;
2075 for(i = 1; i < c->argc; i++) {
2076 if(!strncasecmp(c->argv[i], "time", 4)) {
2077 rc = limits_parse_one(c->argv[i], lim);
2079 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2080 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2081 c->log, c->cr_msg, c->argv[i]);
2085 if(!strcasecmp(c->argv[i], "unlimited")) {
2086 lim->lms_t_soft = -1;
2088 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
2089 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2090 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2091 c->log, c->cr_msg, c->argv[i]);
2095 lim->lms_t_hard = 0;
2102 config_overlay(ConfigArgs *c) {
2103 if (c->op == SLAP_CONFIG_EMIT) {
2105 } else if ( c->op == LDAP_MOD_DELETE ) {
2108 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2111 Debug( LDAP_DEBUG_ANY,
2112 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2113 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2115 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi)) {
2122 config_subordinate(ConfigArgs *c)
2128 case SLAP_CONFIG_EMIT:
2129 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2132 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2133 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2136 value_add_one( &c->rvalue_vals, &bv );
2140 case LDAP_MOD_DELETE:
2141 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2142 glue_sub_del( c->be );
2144 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2149 case SLAP_CONFIG_ADD:
2150 advertise = ( c->argc == 2 && !strcasecmp( c->argv[1], "advertise" ));
2151 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2158 config_suffix(ConfigArgs *c)
2161 struct berval pdn, ndn;
2162 char *notallowed = NULL;
2164 if ( c->be == frontendDB ) {
2165 notallowed = "frontend";
2167 } else if ( SLAP_MONITOR(c->be) ) {
2168 notallowed = "monitor";
2170 } else if ( SLAP_CONFIG(c->be) ) {
2171 notallowed = "config";
2174 if ( notallowed != NULL ) {
2175 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
2179 case LDAP_MOD_DELETE:
2180 case LDAP_MOD_REPLACE:
2181 case LDAP_MOD_INCREMENT:
2182 case SLAP_CONFIG_ADD:
2183 if ( !BER_BVISNULL( &c->value_dn ) ) {
2184 snprintf( buf, sizeof( buf ), "<%s> ",
2185 c->value_dn.bv_val );
2188 Debug(LDAP_DEBUG_ANY,
2189 "%s: suffix %snot allowed in %s database.\n",
2190 c->log, buf, notallowed );
2193 case SLAP_CONFIG_EMIT:
2194 /* don't complain when emitting... */
2198 /* FIXME: don't know what values may be valid;
2199 * please remove assertion, or add legal values
2200 * to either block */
2208 if (c->op == SLAP_CONFIG_EMIT) {
2209 if ( c->be->be_suffix == NULL
2210 || BER_BVISNULL( &c->be->be_suffix[0] ) )
2214 value_add( &c->rvalue_vals, c->be->be_suffix );
2215 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
2218 } else if ( c->op == LDAP_MOD_DELETE ) {
2219 if ( c->valx < 0 ) {
2220 ber_bvarray_free( c->be->be_suffix );
2221 ber_bvarray_free( c->be->be_nsuffix );
2222 c->be->be_suffix = NULL;
2223 c->be->be_nsuffix = NULL;
2226 ch_free( c->be->be_suffix[i].bv_val );
2227 ch_free( c->be->be_nsuffix[i].bv_val );
2229 c->be->be_suffix[i] = c->be->be_suffix[i+1];
2230 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
2232 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
2237 #ifdef SLAPD_MONITOR_DN
2238 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
2239 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> DN is reserved for monitoring slapd",
2241 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2242 c->log, c->cr_msg, SLAPD_MONITOR_DN);
2247 if (SLAP_DB_ONE_SUFFIX( c->be ) && c->be->be_suffix ) {
2248 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> Only one suffix is allowed on this %s backend",
2249 c->argv[0], c->be->bd_info->bi_type );
2250 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2251 c->log, c->cr_msg, 0);
2258 if (SLAP_DBHIDDEN( c->be ))
2261 tbe = select_backend(&ndn, 0);
2263 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
2269 BackendDB *b2 = tbe;
2271 /* Does tbe precede be? */
2272 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
2275 char *type = tbe->bd_info->bi_type;
2277 if ( overlay_is_over( tbe ) ) {
2278 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
2279 type = oi->oi_orig->bi_type;
2282 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> namingContext \"%s\" "
2283 "already served by a preceding %s database",
2284 c->argv[0], pdn.bv_val, type );
2285 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
2286 c->log, c->cr_msg, tbe->be_suffix[0].bv_val);
2292 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
2293 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
2294 "base provided \"%s\" (assuming okay)\n",
2295 c->log, default_search_base.bv_val, 0);
2297 ber_bvarray_add(&c->be->be_suffix, &pdn);
2298 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
2303 config_rootdn(ConfigArgs *c) {
2304 if (c->op == SLAP_CONFIG_EMIT) {
2305 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2306 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
2307 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
2312 } else if ( c->op == LDAP_MOD_DELETE ) {
2313 ch_free( c->be->be_rootdn.bv_val );
2314 ch_free( c->be->be_rootndn.bv_val );
2315 BER_BVZERO( &c->be->be_rootdn );
2316 BER_BVZERO( &c->be->be_rootndn );
2319 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2320 ch_free( c->be->be_rootdn.bv_val );
2321 ch_free( c->be->be_rootndn.bv_val );
2323 c->be->be_rootdn = c->value_dn;
2324 c->be->be_rootndn = c->value_ndn;
2329 config_rootpw(ConfigArgs *c) {
2332 if (c->op == SLAP_CONFIG_EMIT) {
2333 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
2334 /* don't copy, because "rootpw" is marked
2336 c->value_bv = c->be->be_rootpw;
2340 } else if ( c->op == LDAP_MOD_DELETE ) {
2341 ch_free( c->be->be_rootpw.bv_val );
2342 BER_BVZERO( &c->be->be_rootpw );
2346 tbe = select_backend(&c->be->be_rootndn, 0);
2348 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> can only be set when rootdn is under suffix",
2350 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2351 c->log, c->cr_msg, 0);
2354 if ( !BER_BVISNULL( &c->be->be_rootpw ))
2355 ch_free( c->be->be_rootpw.bv_val );
2356 c->be->be_rootpw = c->value_bv;
2361 config_restrict(ConfigArgs *c) {
2362 slap_mask_t restrictops = 0;
2364 slap_verbmasks restrictable_ops[] = {
2365 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
2366 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
2367 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
2368 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
2369 { BER_BVC("modrdn"), 0 },
2370 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
2371 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
2372 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
2373 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
2374 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
2375 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
2376 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
2377 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
2378 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
2379 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
2380 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
2384 if (c->op == SLAP_CONFIG_EMIT) {
2385 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
2387 } else if ( c->op == LDAP_MOD_DELETE ) {
2389 c->be->be_restrictops = 0;
2391 restrictops = verb_to_mask( c->line, restrictable_ops );
2392 c->be->be_restrictops ^= restrictops;
2396 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
2398 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown operation", c->argv[0] );
2399 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2400 c->log, c->cr_msg, c->argv[i]);
2403 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
2404 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
2405 c->be->be_restrictops |= restrictops;
2410 config_allows(ConfigArgs *c) {
2411 slap_mask_t allows = 0;
2413 slap_verbmasks allowable_ops[] = {
2414 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
2415 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
2416 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
2417 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
2418 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
2421 if (c->op == SLAP_CONFIG_EMIT) {
2422 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
2423 } else if ( c->op == LDAP_MOD_DELETE ) {
2427 allows = verb_to_mask( c->line, allowable_ops );
2428 global_allows ^= allows;
2432 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
2434 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
2435 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2436 c->log, c->cr_msg, c->argv[i]);
2439 global_allows |= allows;
2444 config_disallows(ConfigArgs *c) {
2445 slap_mask_t disallows = 0;
2447 slap_verbmasks disallowable_ops[] = {
2448 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
2449 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
2450 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
2451 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
2454 if (c->op == SLAP_CONFIG_EMIT) {
2455 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
2456 } else if ( c->op == LDAP_MOD_DELETE ) {
2458 global_disallows = 0;
2460 disallows = verb_to_mask( c->line, disallowable_ops );
2461 global_disallows ^= disallows;
2465 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
2467 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
2468 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2469 c->log, c->cr_msg, c->argv[i]);
2472 global_disallows |= disallows;
2477 config_requires(ConfigArgs *c) {
2478 slap_mask_t requires = frontendDB->be_requires;
2479 int i, argc = c->argc;
2480 char **argv = c->argv;
2482 slap_verbmasks requires_ops[] = {
2483 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
2484 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
2485 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
2486 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
2487 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
2490 if (c->op == SLAP_CONFIG_EMIT) {
2491 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
2492 } else if ( c->op == LDAP_MOD_DELETE ) {
2494 c->be->be_requires = 0;
2496 requires = verb_to_mask( c->line, requires_ops );
2497 c->be->be_requires ^= requires;
2501 /* "none" can only be first, to wipe out default/global values */
2502 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
2507 i = verbs_to_mask(argc, argv, requires_ops, &requires);
2509 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
2510 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
2511 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2512 c->log, c->cr_msg, 0);
2514 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
2515 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2516 c->log, c->cr_msg, c->argv[i]);
2520 c->be->be_requires = requires;
2524 static slap_verbmasks *loglevel_ops;
2527 loglevel_init( void )
2529 slap_verbmasks lo[] = {
2530 { BER_BVC("Any"), -1 },
2531 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
2532 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
2533 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
2534 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
2535 { BER_BVC("BER"), LDAP_DEBUG_BER },
2536 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
2537 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
2538 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
2539 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
2540 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
2541 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
2542 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
2543 #if 0 /* no longer used (nor supported) */
2544 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
2545 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
2547 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
2548 { BER_BVC("None"), LDAP_DEBUG_NONE },
2552 return slap_verbmasks_init( &loglevel_ops, lo );
2556 loglevel_destroy( void )
2558 if ( loglevel_ops ) {
2559 (void)slap_verbmasks_destroy( loglevel_ops );
2561 loglevel_ops = NULL;
2564 static slap_mask_t loglevel_ignore[] = { -1, 0 };
2567 slap_loglevel_register( slap_mask_t m, struct berval *s )
2571 if ( loglevel_ops == NULL ) {
2575 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
2578 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
2586 slap_loglevel_get( struct berval *s, int *l )
2591 if ( loglevel_ops == NULL ) {
2595 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
2596 m |= loglevel_ops[ i ].mask;
2599 for ( i = 1; m & i; i <<= 1 )
2606 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
2609 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
2620 str2loglevel( const char *s, int *l )
2624 if ( loglevel_ops == NULL ) {
2628 i = verb_to_mask( s, loglevel_ops );
2630 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
2634 *l = loglevel_ops[ i ].mask;
2640 loglevel2str( int l )
2642 struct berval bv = BER_BVNULL;
2644 loglevel2bv( l, &bv );
2650 loglevel2bv( int l, struct berval *bv )
2652 if ( loglevel_ops == NULL ) {
2658 return enum_to_verb( loglevel_ops, l, bv ) == -1;
2662 loglevel2bvarray( int l, BerVarray *bva )
2664 if ( loglevel_ops == NULL ) {
2668 return mask_to_verbs( loglevel_ops, l, bva );
2672 loglevel_print( FILE *out )
2676 if ( loglevel_ops == NULL ) {
2680 fprintf( out, "Installed log subsystems:\n\n" );
2681 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
2682 fprintf( out, "\t%-30s (%lu)\n",
2683 loglevel_ops[ i ].word.bv_val,
2684 loglevel_ops[ i ].mask );
2687 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
2688 "by specific code\n\n" );
2693 static int config_syslog;
2696 config_loglevel(ConfigArgs *c) {
2699 if ( loglevel_ops == NULL ) {
2703 if (c->op == SLAP_CONFIG_EMIT) {
2704 /* Get default or commandline slapd setting */
2705 if ( ldap_syslog && !config_syslog )
2706 config_syslog = ldap_syslog;
2707 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
2709 } else if ( c->op == LDAP_MOD_DELETE ) {
2713 int level = verb_to_mask( c->line, loglevel_ops );
2714 config_syslog ^= level;
2716 if ( slapMode & SLAP_SERVER_MODE ) {
2717 ldap_syslog = config_syslog;
2722 for( i=1; i < c->argc; i++ ) {
2725 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
2726 if( lutil_atoi( &level, c->argv[i] ) != 0 ) {
2727 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse level", c->argv[0] );
2728 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2729 c->log, c->cr_msg, c->argv[i]);
2733 if ( str2loglevel( c->argv[i], &level ) ) {
2734 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown level", c->argv[0] );
2735 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2736 c->log, c->cr_msg, c->argv[i]);
2740 /* Explicitly setting a zero clears all the levels */
2742 config_syslog |= level;
2746 if ( slapMode & SLAP_SERVER_MODE ) {
2747 ldap_syslog = config_syslog;
2753 config_referral(ConfigArgs *c) {
2755 if (c->op == SLAP_CONFIG_EMIT) {
2756 if ( default_referral ) {
2757 value_add( &c->rvalue_vals, default_referral );
2762 } else if ( c->op == LDAP_MOD_DELETE ) {
2763 if ( c->valx < 0 ) {
2764 ber_bvarray_free( default_referral );
2765 default_referral = NULL;
2768 ch_free( default_referral[i].bv_val );
2769 for (; default_referral[i].bv_val; i++ )
2770 default_referral[i] = default_referral[i+1];
2774 if(validate_global_referral(c->argv[1])) {
2775 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
2776 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2777 c->log, c->cr_msg, c->argv[1]);
2781 ber_str2bv(c->argv[1], 0, 0, &val);
2782 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
2790 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
2791 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
2792 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
2793 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
2794 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
2795 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
2796 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
2797 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
2798 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
2803 config_security(ConfigArgs *c) {
2804 slap_ssf_set_t *set = &c->be->be_ssf_set;
2807 if (c->op == SLAP_CONFIG_EMIT) {
2813 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
2814 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
2817 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
2818 if ( bv.bv_len >= sizeof( numbuf ) ) {
2819 ber_bvarray_free_x( c->rvalue_vals, NULL );
2820 c->rvalue_vals = NULL;
2824 bv.bv_len += sec_keys[i].key.bv_len;
2825 bv.bv_val = ch_malloc( bv.bv_len + 1);
2826 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
2827 strcpy( next, numbuf );
2828 ber_bvarray_add( &c->rvalue_vals, &bv );
2833 for(i = 1; i < c->argc; i++) {
2834 slap_ssf_t *tgt = NULL;
2836 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
2837 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
2838 sec_keys[j].key.bv_len)) {
2839 src = c->argv[i] + sec_keys[j].key.bv_len;
2840 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
2845 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown factor", c->argv[0] );
2846 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2847 c->log, c->cr_msg, c->argv[i]);
2851 if ( lutil_atou( tgt, src ) != 0 ) {
2852 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse factor", c->argv[0] );
2853 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2854 c->log, c->cr_msg, c->argv[i]);
2862 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
2866 for (; !BER_BVISNULL( &an->an_name ); an++) {
2867 /* if buflen == 0, assume the buffer size has been
2868 * already checked otherwise */
2869 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
2870 if ( comma ) *ptr++ = ',';
2871 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
2878 config_updatedn(ConfigArgs *c) {
2879 if (c->op == SLAP_CONFIG_EMIT) {
2880 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
2881 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
2882 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
2886 } else if ( c->op == LDAP_MOD_DELETE ) {
2887 ch_free( c->be->be_update_ndn.bv_val );
2888 BER_BVZERO( &c->be->be_update_ndn );
2889 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
2892 if(SLAP_SHADOW(c->be)) {
2893 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database already shadowed", c->argv[0] );
2894 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2895 c->log, c->cr_msg, 0);
2899 ber_memfree_x( c->value_dn.bv_val, NULL );
2900 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
2901 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
2903 c->be->be_update_ndn = c->value_ndn;
2904 BER_BVZERO( &c->value_dn );
2905 BER_BVZERO( &c->value_ndn );
2907 return config_slurp_shadow( c );
2911 config_shadow( ConfigArgs *c, int flag )
2913 char *notallowed = NULL;
2915 if ( c->be == frontendDB ) {
2916 notallowed = "frontend";
2918 } else if ( SLAP_MONITOR(c->be) ) {
2919 notallowed = "monitor";
2922 if ( notallowed != NULL ) {
2923 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
2927 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SINGLE_SHADOW | flag);
2933 config_updateref(ConfigArgs *c) {
2935 if (c->op == SLAP_CONFIG_EMIT) {
2936 if ( c->be->be_update_refs ) {
2937 value_add( &c->rvalue_vals, c->be->be_update_refs );
2942 } else if ( c->op == LDAP_MOD_DELETE ) {
2943 if ( c->valx < 0 ) {
2944 ber_bvarray_free( c->be->be_update_refs );
2945 c->be->be_update_refs = NULL;
2948 ch_free( c->be->be_update_refs[i].bv_val );
2949 for (; c->be->be_update_refs[i].bv_val; i++)
2950 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
2954 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
2955 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must appear after syncrepl or updatedn",
2957 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2958 c->log, c->cr_msg, 0);
2962 if(validate_global_referral(c->argv[1])) {
2963 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
2964 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2965 c->log, c->cr_msg, c->argv[1]);
2968 ber_str2bv(c->argv[1], 0, 0, &val);
2969 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
2974 config_obsolete(ConfigArgs *c) {
2975 if (c->op == SLAP_CONFIG_EMIT)
2978 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> keyword is obsolete (ignored)",
2980 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0);
2985 config_include(ConfigArgs *c) {
2986 int savelineno = c->lineno;
2989 ConfigFile *cfsave = cfn;
2990 ConfigFile *cf2 = NULL;
2992 /* Leftover from RE23. No dynamic config for include files */
2993 if ( c->op == SLAP_CONFIG_EMIT || c->op == LDAP_MOD_DELETE )
2996 cf = ch_calloc( 1, sizeof(ConfigFile));
2997 if ( cfn->c_kids ) {
2998 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
3004 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
3005 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
3006 c->lineno = savelineno - 1;
3009 if ( cf2 ) cf2->c_sibs = NULL;
3010 else cfn->c_kids = NULL;
3011 ch_free( cf->c_file.bv_val );
3021 config_tls_option(ConfigArgs *c) {
3023 LDAP *ld = slap_tls_ld;
3025 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
3026 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
3027 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
3028 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
3029 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
3030 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
3031 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
3033 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
3035 default: Debug(LDAP_DEBUG_ANY, "%s: "
3036 "unknown tls_option <0x%x>\n",
3037 c->log, c->type, 0);
3040 if (c->op == SLAP_CONFIG_EMIT) {
3041 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
3042 } else if ( c->op == LDAP_MOD_DELETE ) {
3043 return ldap_pvt_tls_set_option( ld, flag, NULL );
3045 ch_free(c->value_string);
3046 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
3049 /* FIXME: this ought to be provided by libldap */
3051 config_tls_config(ConfigArgs *c) {
3054 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
3055 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
3057 Debug(LDAP_DEBUG_ANY, "%s: "
3058 "unknown tls_option <0x%x>\n",
3059 c->log, c->type, 0);
3062 if (c->op == SLAP_CONFIG_EMIT) {
3063 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
3064 } else if ( c->op == LDAP_MOD_DELETE ) {
3066 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
3068 ch_free( c->value_string );
3069 if ( isdigit( (unsigned char)c->argv[1][0] ) ) {
3070 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
3071 Debug(LDAP_DEBUG_ANY, "%s: "
3072 "unable to parse %s \"%s\"\n",
3073 c->log, c->argv[0], c->argv[1] );
3076 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
3078 return(ldap_int_tls_config(slap_tls_ld, flag, c->argv[1]));
3083 static CfEntryInfo *
3084 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
3094 if ( dn_match( &root->ce_entry->e_nname, dn ))
3097 c = dn->bv_val+dn->bv_len;
3098 for (;*c != ',';c--);
3102 for (--c;c>dn->bv_val && *c != ',';c--);
3106 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
3108 root = root->ce_kids;
3110 for (;root;root=root->ce_sibs) {
3111 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
3112 if ( cdn.bv_val == dn->bv_val ) {
3122 typedef struct setup_cookie {
3132 config_ldif_resp( Operation *op, SlapReply *rs )
3134 if ( rs->sr_type == REP_SEARCH ) {
3135 setup_cookie *sc = op->o_callback->sc_private;
3137 sc->cfb->cb_got_ldif = 1;
3138 /* Does the frontend exist? */
3139 if ( !sc->got_frontend ) {
3140 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
3141 "olcDatabase", STRLENOF( "olcDatabase" ))) {
3142 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3143 STRLENOF( "olcDatabase" ), "={-1}frontend",
3144 STRLENOF( "={-1}frontend" ))) {
3147 sc->ca->be = frontendDB;
3148 sc->ca->bi = frontendDB->bd_info;
3149 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
3150 rdn.bv_val = sc->ca->log;
3151 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3152 "%s=" SLAP_X_ORDERED_FMT "%s",
3153 cfAd_database->ad_cname.bv_val, -1,
3154 sc->ca->bi->bi_type);
3156 sc->frontend = config_build_entry( op, rs,
3157 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
3158 sc->ca->be->be_cf_ocs );
3167 /* Does the configDB exist? */
3168 if ( sc->got_frontend && !sc->got_config &&
3169 !strncmp( rs->sr_entry->e_nname.bv_val,
3170 "olcDatabase", STRLENOF( "olcDatabase" ))) {
3171 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3172 STRLENOF( "olcDatabase" ), "={0}config",
3173 STRLENOF( "={0}config" ))) {
3176 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
3177 sc->ca->bi = sc->ca->be->bd_info;
3178 rdn.bv_val = sc->ca->log;
3179 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3180 "%s=" SLAP_X_ORDERED_FMT "%s",
3181 cfAd_database->ad_cname.bv_val, 0,
3182 sc->ca->bi->bi_type);
3184 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
3185 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
3192 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
3193 if ( rs->sr_err != LDAP_SUCCESS ) {
3194 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
3195 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg, 0 );
3201 /* Configure and read the underlying back-ldif store */
3203 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
3204 CfBackInfo *cfb = be->be_private;
3210 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
3211 Connection conn = {0};
3212 OperationBuffer opbuf;
3214 SlapReply rs = {REP_RESULT};
3215 Filter filter = { LDAP_FILTER_PRESENT };
3216 struct berval filterstr = BER_BVC("(objectclass=*)");
3219 /* Is the config directory available? */
3220 if ( stat( dir, &st ) < 0 ) {
3221 /* No, so don't bother using the backing store.
3222 * All changes will be in-memory only.
3227 cfb->cb_db.bd_info = backend_info( "ldif" );
3228 if ( !cfb->cb_db.bd_info )
3229 return 0; /* FIXME: eventually this will be a fatal error */
3231 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
3234 cfb->cb_db.be_suffix = be->be_suffix;
3235 cfb->cb_db.be_nsuffix = be->be_nsuffix;
3237 /* The suffix is always "cn=config". The underlying DB's rootdn
3238 * is always the same as the suffix.
3240 cfb->cb_db.be_rootdn = be->be_suffix[0];
3241 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
3243 ber_str2bv( dir, 0, 1, &cfdir );
3248 argv[0] = "directory";
3249 argv[1] = (char *)dir;
3254 c.table = Cft_Database;
3256 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
3260 if ( config_add_vals( ct, &c ))
3263 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
3267 void *thrctx = ldap_pvt_thread_pool_context();
3270 connection_fake_init( &conn, &opbuf, thrctx );
3273 filter.f_desc = slap_schema.si_ad_objectClass;
3275 op->o_tag = LDAP_REQ_SEARCH;
3277 op->ors_filter = &filter;
3278 op->ors_filterstr = filterstr;
3279 op->ors_scope = LDAP_SCOPE_SUBTREE;
3281 op->o_dn = c.be->be_rootdn;
3282 op->o_ndn = c.be->be_rootndn;
3284 op->o_req_dn = be->be_suffix[0];
3285 op->o_req_ndn = be->be_nsuffix[0];
3287 op->ors_tlimit = SLAP_NO_LIMIT;
3288 op->ors_slimit = SLAP_NO_LIMIT;
3290 op->ors_attrs = slap_anlist_all_attributes;
3291 op->ors_attrsonly = 0;
3293 op->o_callback = &cb;
3296 cb.sc_private = ≻
3297 sc.got_frontend = 0;
3302 op->o_bd = &cfb->cb_db;
3304 /* Allow unknown attrs in DNs */
3305 prev_DN_strict = slap_DN_strict;
3308 rc = op->o_bd->be_search( op, &rs );
3310 /* Restore normal DN validation */
3311 slap_DN_strict = prev_DN_strict;
3313 op->o_tag = LDAP_REQ_ADD;
3314 if ( rc == LDAP_SUCCESS && sc.frontend ) {
3315 op->ora_e = sc.frontend;
3316 rc = op->o_bd->be_add( op, &rs );
3318 if ( rc == LDAP_SUCCESS && sc.config ) {
3319 op->ora_e = sc.config;
3320 rc = op->o_bd->be_add( op, &rs );
3322 ldap_pvt_thread_pool_context_reset( thrctx );
3325 /* ITS#4194 - only use if it's present, or we're converting. */
3326 if ( !readit || rc == LDAP_SUCCESS )
3327 cfb->cb_use_ldif = 1;
3333 CfOc_cmp( const void *c1, const void *c2 ) {
3334 const ConfigOCs *co1 = c1;
3335 const ConfigOCs *co2 = c2;
3337 return ber_bvcmp( co1->co_name, co2->co_name );
3341 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
3344 i = init_config_attrs( ct );
3347 /* set up the objectclasses */
3348 i = init_config_ocs( ocs );
3351 for (i=0; ocs[i].co_def; i++) {
3352 if ( ocs[i].co_oc ) {
3353 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
3354 if ( !ocs[i].co_table )
3355 ocs[i].co_table = ct;
3356 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
3363 read_config(const char *fname, const char *dir) {
3366 const char *cfdir, *cfname;
3369 /* Setup the config backend */
3370 be = backend_db_init( "config", NULL, 0, NULL );
3374 cfb = be->be_private;
3375 be->be_dfltaccess = ACL_NONE;
3377 /* If no .conf, or a dir was specified, setup the dir */
3378 if ( !fname || dir ) {
3380 /* If explicitly given, check for existence */
3383 if ( stat( dir, &st ) < 0 ) {
3384 Debug( LDAP_DEBUG_ANY,
3385 "invalid config directory %s, error %d\n",
3391 cfdir = SLAPD_DEFAULT_CONFIGDIR;
3393 /* if fname is defaulted, try reading .d */
3394 rc = config_setup_ldif( be, cfdir, !fname );
3397 /* It may be OK if the base object doesn't exist yet. */
3398 if ( rc != LDAP_NO_SUCH_OBJECT )
3400 /* ITS#4194: But if dir was specified and no fname,
3401 * then we were supposed to read the dir. Unless we're
3402 * trying to slapadd the dir...
3404 if ( dir && !fname ) {
3405 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
3407 /* Assume it's slapadd with a config dir, let it continue */
3409 cfb->cb_got_ldif = 1;
3410 cfb->cb_use_ldif = 1;
3415 /* If we read the config from back-ldif, nothing to do here */
3416 if ( cfb->cb_got_ldif ) {
3425 cfname = SLAPD_DEFAULT_CONFIGFILE;
3427 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
3430 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
3433 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
3434 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
3435 &frontendDB->be_schemadn );
3436 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
3437 if ( rc != LDAP_SUCCESS ) {
3438 Debug(LDAP_DEBUG_ANY, "read_config: "
3439 "unable to normalize default schema DN \"%s\"\n",
3440 frontendDB->be_schemadn.bv_val, 0, 0 );
3441 /* must not happen */
3449 config_back_bind( Operation *op, SlapReply *rs )
3451 if ( be_isroot_pw( op ) ) {
3452 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
3453 /* frontend sends result */
3454 return LDAP_SUCCESS;
3457 rs->sr_err = LDAP_INVALID_CREDENTIALS;
3458 send_ldap_result( op, rs );
3464 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
3468 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
3470 rs->sr_attrs = op->ors_attrs;
3471 rs->sr_entry = ce->ce_entry;
3473 rc = send_search_entry( op, rs );
3475 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
3476 if ( ce->ce_kids ) {
3477 rc = config_send( op, rs, ce->ce_kids, 1 );
3478 if ( rc ) return rc;
3481 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
3482 rc = config_send( op, rs, ce, 0 );
3490 static ConfigTable *
3491 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
3496 for (j=0; j<nocs; j++) {
3497 for (i=0; colst[j]->co_table[i].name; i++)
3498 if ( colst[j]->co_table[i].ad == ad ) {
3499 ca->table = colst[j]->co_type;
3500 return &colst[j]->co_table[i];
3506 /* Sort the attributes of the entry according to the order defined
3507 * in the objectclass, with required attributes occurring before
3508 * allowed attributes. For any attributes with sequencing dependencies
3509 * (e.g., rootDN must be defined after suffix) the objectclass must
3510 * list the attributes in the desired sequence.
3513 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
3515 Attribute *a, *head = NULL, *tail = NULL, **prev;
3518 for (i=0; i<nocs; i++) {
3519 if ( colst[i]->co_oc->soc_required ) {
3520 AttributeType **at = colst[i]->co_oc->soc_required;
3521 for (j=0; at[j]; j++) {
3522 for (a=e->e_attrs, prev=&e->e_attrs; a;
3523 prev = &(*prev)->a_next, a=a->a_next) {
3524 if ( a->a_desc == at[j]->sat_ad ) {
3538 if ( colst[i]->co_oc->soc_allowed ) {
3539 AttributeType **at = colst[i]->co_oc->soc_allowed;
3540 for (j=0; at[j]; j++) {
3541 for (a=e->e_attrs, prev=&e->e_attrs; a;
3542 prev = &(*prev)->a_next, a=a->a_next) {
3543 if ( a->a_desc == at[j]->sat_ad ) {
3559 tail->a_next = e->e_attrs;
3565 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
3567 Attribute *a = NULL;
3568 AttributeDescription *ad;
3578 Modifications *ml = ptr;
3580 vals = ml->sml_values;
3583 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
3584 rc = ordered_value_sort( a, 1 );
3586 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
3587 ad->ad_cname.bv_val );
3591 for ( i=0; vals[i].bv_val; i++ ) {
3592 ca->line = vals[i].bv_val;
3593 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
3594 ca->line[0] == '{' ) {
3595 char *idx = strchr( ca->line, '}' );
3596 if ( idx ) ca->line = idx+1;
3598 rc = config_parse_vals( ct, ca, i );
3607 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
3610 struct berval rtype, rval;
3612 AttributeDescription *ad = NULL;
3614 dnRdn( &e->e_name, rdn );
3615 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
3616 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
3617 rtype.bv_val = rdn->bv_val;
3618 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
3621 slap_bv2ad( &rtype, &ad, &rs->sr_text );
3622 a = attr_find( e->e_attrs, ad );
3623 if (!a ) return LDAP_NAMING_VIOLATION;
3630 config_rename_kids( CfEntryInfo *ce )
3633 struct berval rdn, nrdn;
3635 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
3636 dnRdn ( &ce2->ce_entry->e_name, &rdn );
3637 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
3638 free( ce2->ce_entry->e_name.bv_val );
3639 free( ce2->ce_entry->e_nname.bv_val );
3640 build_new_dn( &ce2->ce_entry->e_name, &ce->ce_entry->e_name,
3642 build_new_dn( &ce2->ce_entry->e_nname, &ce->ce_entry->e_nname,
3644 config_rename_kids( ce2 );
3649 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
3650 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
3651 struct berval *nnewrdn, int use_ldif )
3655 struct berval odn, ondn;
3659 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
3660 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
3663 free( a->a_vals[0].bv_val );
3664 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
3665 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
3666 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
3667 strcpy( a->a_vals[0].bv_val, ptr1 );
3669 if ( a->a_nvals != a->a_vals ) {
3670 free( a->a_nvals[0].bv_val );
3671 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
3672 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
3673 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
3674 strcpy( a->a_nvals[0].bv_val, ptr1 );
3677 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
3678 BackendDB *be = op->o_bd;
3679 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
3680 struct berval dn, ndn, xdn, xndn;
3682 op->o_bd = &cfb->cb_db;
3684 /* Save current rootdn; use the underlying DB's rootdn */
3688 xndn = op->o_req_ndn;
3689 op->o_dn = op->o_bd->be_rootdn;
3690 op->o_ndn = op->o_bd->be_rootndn;
3692 op->o_req_ndn = ondn;
3694 scp = op->o_callback;
3695 op->o_callback = ≻
3696 op->orr_newrdn = *newrdn;
3697 op->orr_nnewrdn = *nnewrdn;
3698 op->orr_newSup = NULL;
3699 op->orr_nnewSup = NULL;
3700 op->orr_deleteoldrdn = 1;
3701 op->orr_modlist = NULL;
3702 slap_modrdn2mods( op, rs );
3703 slap_mods_opattrs( op, &op->orr_modlist, 1 );
3704 rc = op->o_bd->be_modrdn( op, rs );
3705 slap_mods_free( op->orr_modlist, 1 );
3708 op->o_callback = scp;
3712 op->o_req_ndn = xndn;
3715 free( ondn.bv_val );
3717 config_rename_kids( e->e_private );
3722 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
3723 Entry *e, int idx, int tailindex, int use_ldif )
3725 struct berval ival, newrdn, nnewrdn;
3728 char ibuf[32], *ptr1, *ptr2 = NULL;
3731 rc = config_rename_attr( rs, e, &rdn, &a );
3732 if ( rc ) return rc;
3735 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
3736 if ( ival.bv_len >= sizeof( ibuf ) ) {
3737 return LDAP_NAMING_VIOLATION;
3740 newrdn.bv_len = rdn.bv_len + ival.bv_len;
3741 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
3744 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
3745 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3748 ptr2 = ber_bvchr( &rdn, '}' );
3752 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
3754 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
3755 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
3756 a->a_desc->ad_cname.bv_len );
3758 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3759 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
3763 /* Do the equivalent of ModRDN */
3764 /* Replace DN / NDN */
3765 newrdn.bv_len = ptr1 - newrdn.bv_val;
3766 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
3767 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
3769 free( nnewrdn.bv_val );
3770 free( newrdn.bv_val );
3775 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
3776 SlapReply *rs, int *renum, int *ibase )
3779 int index = -1, gotindex = 0, nsibs, rc = 0;
3780 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
3781 char *ptr1, *ptr2 = NULL;
3784 if ( renum ) *renum = 0;
3786 /* These entries don't get indexed/renumbered */
3787 if ( ce_type == Cft_Global ) return 0;
3788 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
3790 if ( ce_type == Cft_Module )
3793 /* See if the rdn has an index already */
3794 dnRdn( &e->e_name, &rdn );
3795 if ( ce_type == Cft_Database ) {
3796 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
3797 "frontend", STRLENOF("frontend") ))
3799 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
3800 "config", STRLENOF("config") ))
3803 ptr1 = ber_bvchr( &e->e_name, '{' );
3804 if ( ptr1 && ptr1 - e->e_name.bv_val < rdn.bv_len ) {
3806 ptr2 = strchr( ptr1, '}' );
3807 if (!ptr2 || ptr2 - e->e_name.bv_val > rdn.bv_len)
3808 return LDAP_NAMING_VIOLATION;
3809 if ( ptr2-ptr1 == 1)
3810 return LDAP_NAMING_VIOLATION;
3812 index = strtol( ptr1 + 1, &next, 10 );
3813 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
3814 return LDAP_NAMING_VIOLATION;
3817 /* Special case, we allow -1 for the frontendDB */
3818 if ( index != -1 || !isfrontend )
3819 return LDAP_NAMING_VIOLATION;
3821 if ( isconfig && index != 0 ){
3822 return LDAP_NAMING_VIOLATION;
3826 /* count related kids */
3827 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
3828 if ( ce->ce_type == ce_type ) nsibs++;
3831 /* account for -1 frontend */
3832 if ( ce_type == Cft_Database )
3835 if ( index != nsibs ) {
3837 if ( index < nsibs ) {
3838 if ( tailindex ) return LDAP_NAMING_VIOLATION;
3839 /* Siblings need to be renumbered */
3840 if ( index != -1 || !isfrontend )
3844 /* config DB is always "0" */
3845 if ( isconfig && index == -1 ) {
3848 if ( !isfrontend && index == -1 ) {
3852 /* just make index = nsibs */
3854 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
3857 if ( ibase ) *ibase = index;
3858 if ( renum ) *renum = renumber;
3863 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
3868 co.co_name = &oc->soc_cname;
3869 cop = avl_find( CfOcTree, &co, CfOc_cmp );
3873 /* check for duplicates */
3874 for ( i = 0; i < *nocs; i++ ) {
3875 if ( *copp && (*copp)[i] == cop ) {
3881 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
3882 if ( tmp == NULL ) {
3886 (*copp)[*nocs] = cop;
3891 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
3892 if ( count_oc( *sups, copp, nocs ) ) {
3901 count_ocs( Attribute *oc_at, int *nocs )
3904 ConfigOCs **colst = NULL;
3908 for ( i = 0; !BER_BVISNULL( &oc_at->a_nvals[i] ); i++ )
3912 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
3914 assert( oc != NULL );
3915 if ( count_oc( oc, &colst, nocs ) ) {
3925 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
3927 /* Leftover from RE23. Never parse this entry */
3928 return LDAP_COMPARE_TRUE;
3932 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
3936 /* This entry is hardcoded, don't re-parse it */
3937 if ( p->ce_type == Cft_Global ) {
3938 cfn = p->ce_private;
3940 return LDAP_COMPARE_TRUE;
3942 if ( p->ce_type != Cft_Schema )
3943 return LDAP_CONSTRAINT_VIOLATION;
3945 cfn = ch_calloc( 1, sizeof(ConfigFile) );
3947 cfo = p->ce_private;
3948 cfn->c_sibs = cfo->c_kids;
3950 return LDAP_SUCCESS;
3954 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3956 if ( p->ce_type != Cft_Global ) {
3957 return LDAP_CONSTRAINT_VIOLATION;
3959 ca->be = frontendDB; /* just to get past check_vals */
3960 return LDAP_SUCCESS;
3964 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3966 if ( p->ce_type != Cft_Global ) {
3967 return LDAP_CONSTRAINT_VIOLATION;
3969 return LDAP_SUCCESS;
3973 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3975 if ( p->ce_type != Cft_Global ) {
3976 return LDAP_CONSTRAINT_VIOLATION;
3978 return LDAP_SUCCESS;
3982 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3984 if ( p->ce_type != Cft_Database ) {
3985 return LDAP_CONSTRAINT_VIOLATION;
3988 return LDAP_SUCCESS;
3992 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
3997 AttributeDescription *ad;
4002 if ( cfn->c_cr_head ) {
4003 struct berval bv = BER_BVC("olcDitContentRules");
4005 slap_bv2ad( &bv, &ad, &text );
4006 ct = config_find_table( colst, nocs, ad, ca );
4007 config_del_vals( ct, ca );
4009 if ( cfn->c_oc_head ) {
4010 struct berval bv = BER_BVC("olcObjectClasses");
4012 slap_bv2ad( &bv, &ad, &text );
4013 ct = config_find_table( colst, nocs, ad, ca );
4014 config_del_vals( ct, ca );
4016 if ( cfn->c_at_head ) {
4017 struct berval bv = BER_BVC("olcAttributeTypes");
4019 slap_bv2ad( &bv, &ad, &text );
4020 ct = config_find_table( colst, nocs, ad, ca );
4021 config_del_vals( ct, ca );
4023 if ( cfn->c_om_head ) {
4024 struct berval bv = BER_BVC("olcObjectIdentifier");
4026 slap_bv2ad( &bv, &ad, &text );
4027 ct = config_find_table( colst, nocs, ad, ca );
4028 config_del_vals( ct, ca );
4030 cfo = p->ce_private;
4031 cfo->c_kids = cfn->c_sibs;
4036 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
4038 int rc = LDAP_CONSTRAINT_VIOLATION;
4041 if ( (*cop)->co_ldadd ) {
4042 rc = (*cop)->co_ldadd( last, e, ca );
4043 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4048 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
4049 ConfigOCs co = { 0 };
4051 co.co_name = &(*ocp)->soc_cname;
4052 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
4053 if ( *cop == NULL ) {
4057 rc = config_add_oc( cop, last, e, ca );
4058 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4066 /* Parse an LDAP entry into config directives */
4068 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
4069 int *renum, Operation *op )
4071 CfEntryInfo *ce, *last = NULL;
4072 ConfigOCs co, *coptr, **colst;
4073 Attribute *a, *oc_at, *soc_at;
4074 int i, ibase = -1, nocs, rc = 0;
4077 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
4079 memset( ca, 0, sizeof(ConfigArgs));
4081 /* Make sure parent exists and entry does not. But allow
4082 * Databases and Overlays to be inserted. Don't do any
4083 * auto-renumbering if manageDSAit control is present.
4085 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
4087 if ( ( op && op->o_managedsait ) ||
4088 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
4089 ce->ce_type != Cft_Module ) )
4091 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4092 "DN=\"%s\" already exists\n",
4093 log_prefix, e->e_name.bv_val, 0 );
4094 return LDAP_ALREADY_EXISTS;
4098 dnParent( &e->e_nname, &pdn );
4100 /* If last is NULL, the new entry is the root/suffix entry,
4101 * otherwise last should be the parent.
4103 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
4105 rs->sr_matched = last->ce_entry->e_name.bv_val;
4107 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4108 "DN=\"%s\" not child of DN=\"%s\"\n",
4109 log_prefix, e->e_name.bv_val,
4110 last->ce_entry->e_name.bv_val );
4111 return LDAP_NO_SUCH_OBJECT;
4115 /* No parent, must be root. This will never happen... */
4116 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
4117 return LDAP_NO_SUCH_OBJECT;
4120 if ( last && !access_allowed( op, last->ce_entry,
4121 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
4123 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4124 "DN=\"%s\" no write access to \"children\" of parent\n",
4125 log_prefix, e->e_name.bv_val, 0 );
4126 return LDAP_INSUFFICIENT_ACCESS;
4130 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4132 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4133 "DN=\"%s\" no objectClass\n",
4134 log_prefix, e->e_name.bv_val, 0 );
4135 return LDAP_OBJECT_CLASS_VIOLATION;
4138 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4140 ObjectClass *soc = NULL;
4141 char textbuf[ SLAP_TEXT_BUFLEN ];
4142 const char *text = textbuf;
4144 /* FIXME: check result */
4145 rc = structural_class( oc_at->a_nvals, &soc, NULL,
4146 &text, textbuf, sizeof(textbuf), NULL );
4147 if ( rc != LDAP_SUCCESS ) {
4148 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4149 "DN=\"%s\" no structural objectClass (%s)\n",
4150 log_prefix, e->e_name.bv_val, text );
4153 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
4154 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4155 if ( soc_at == NULL ) {
4156 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4157 "DN=\"%s\" no structural objectClass; "
4158 "unable to merge computed class %s\n",
4159 log_prefix, e->e_name.bv_val,
4160 soc->soc_cname.bv_val );
4161 return LDAP_OBJECT_CLASS_VIOLATION;
4164 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4165 "DN=\"%s\" no structural objectClass; "
4166 "computed objectClass %s merged\n",
4167 log_prefix, e->e_name.bv_val,
4168 soc->soc_cname.bv_val );
4171 /* Fake the coordinates based on whether we're part of an
4172 * LDAP Add or if reading the config dir
4175 ca->fname = "slapd";
4178 ca->fname = cfdir.bv_val;
4183 co.co_name = &soc_at->a_nvals[0];
4184 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
4185 if ( coptr == NULL ) {
4186 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4187 "DN=\"%s\" no structural objectClass in configuration table\n",
4188 log_prefix, e->e_name.bv_val, 0 );
4189 return LDAP_OBJECT_CLASS_VIOLATION;
4192 /* Only the root can be Cft_Global, everything else must
4193 * have a parent. Only limited nesting arrangements are allowed.
4195 rc = LDAP_CONSTRAINT_VIOLATION;
4196 if ( coptr->co_type == Cft_Global && !last ) {
4197 cfn = cfb->cb_config;
4199 ca->be = frontendDB; /* just to get past check_vals */
4203 colst = count_ocs( oc_at, &nocs );
4205 /* Check whether the Add is allowed by its parent, and do
4206 * any necessary arg setup
4209 rc = config_add_oc( &coptr, last, e, ca );
4210 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4211 for ( i = 0; i<nocs; i++ ) {
4212 /* Already checked these */
4213 if ( colst[i]->co_oc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
4215 if ( colst[i]->co_ldadd &&
4216 ( rc = colst[i]->co_ldadd( last, e, ca ))
4217 != LDAP_CONSTRAINT_VIOLATION ) {
4223 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4224 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4225 "DN=\"%s\" no structural objectClass add function\n",
4226 log_prefix, e->e_name.bv_val, 0 );
4227 return LDAP_OBJECT_CLASS_VIOLATION;
4231 /* Add the entry but don't parse it, we already have its contents */
4232 if ( rc == LDAP_COMPARE_TRUE ) {
4237 if ( rc != LDAP_SUCCESS )
4240 /* Parse all the values and check for simple syntax errors before
4241 * performing any set actions.
4243 * If doing an LDAPadd, check for indexed names and any necessary
4244 * renaming/renumbering. Entries that don't need indexed names are
4245 * ignored. Entries that need an indexed name and arrive without one
4246 * are assigned to the end. Entries that arrive with an index may
4247 * cause the following entries to be renumbered/bumped down.
4249 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
4250 * don't allow Adding an entry with an index that's already in use.
4251 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
4253 * These entries can have auto-assigned indexes (appended to the end)
4254 * but only the other types support auto-renumbering of siblings.
4257 rc = check_name_index( last, coptr->co_type, e, rs, renum,
4262 if ( renum && *renum && coptr->co_type != Cft_Database &&
4263 coptr->co_type != Cft_Overlay )
4265 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
4266 "operation requires sibling renumbering" );
4267 rc = LDAP_UNWILLING_TO_PERFORM;
4272 init_config_argv( ca );
4274 /* Make sure we process attrs in the required order */
4275 sort_attrs( e, colst, nocs );
4277 for ( a = e->e_attrs; a; a = a->a_next ) {
4278 if ( a == oc_at ) continue;
4279 ct = config_find_table( colst, nocs, a->a_desc, ca );
4280 if ( !ct ) continue; /* user data? */
4281 rc = check_vals( ct, ca, a, 1 );
4282 if ( rc ) goto done_noop;
4285 /* Basic syntax checks are OK. Do the actual settings. */
4286 for ( a=e->e_attrs; a; a=a->a_next ) {
4287 if ( a == oc_at ) continue;
4288 ct = config_find_table( colst, nocs, a->a_desc, ca );
4289 if ( !ct ) continue; /* user data? */
4290 for (i=0; a->a_vals[i].bv_val; i++) {
4292 ca->line = a->a_vals[i].bv_val;
4293 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
4294 ptr = strchr( ca->line, '}' );
4296 iptr = strchr( ca->line, '{' );
4300 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
4302 ca->valx = strtol( iptr+1, NULL, 0 );
4309 rc = config_parse_add( ct, ca, i );
4317 /* Newly added databases and overlays need to be started up */
4318 if ( CONFIG_ONLINE_ADD( ca )) {
4319 if ( colst[0]->co_type == Cft_Database ) {
4320 rc = backend_startup_one( ca->be, &ca->reply );
4322 } else if ( colst[0]->co_type == Cft_Overlay ) {
4323 if ( ca->bi->bi_db_open ) {
4324 BackendInfo *bi_orig = ca->be->bd_info;
4325 ca->be->bd_info = ca->bi;
4326 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
4327 ca->be->bd_info = bi_orig;
4329 } else if ( ca->cleanup ) {
4330 rc = ca->cleanup( ca );
4333 if (ca->cr_msg[0] == '\0')
4334 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
4336 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
4337 ca->log, ca->cr_msg, ca->argv[1] );
4344 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
4345 ce->ce_parent = last;
4346 ce->ce_entry = entry_dup( e );
4347 ce->ce_entry->e_private = ce;
4348 ce->ce_type = colst[0]->co_type;
4351 ce->ce_private = ca->private;
4352 ca->ca_entry = ce->ce_entry;
4355 } else if ( last->ce_kids ) {
4356 CfEntryInfo *c2, **cprev;
4358 /* Advance to first of this type */
4359 cprev = &last->ce_kids;
4360 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
4361 cprev = &c2->ce_sibs;
4364 /* Account for the (-1) frontendDB entry */
4365 if ( ce->ce_type == Cft_Database ) {
4366 if ( ca->be == frontendDB )
4368 else if ( ibase != -1 )
4373 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
4374 cprev = &c2->ce_sibs;
4380 for ( i=0; i<ibase; i++ ) {
4382 cprev = &c2->ce_sibs;
4385 ce->ce_sibs = *cprev;
4393 if ( (colst[0]->co_type == Cft_Database) && ca->be ) {
4394 if ( ca->be != frontendDB )
4395 backend_destroy_one( ca->be, 1 );
4396 } else if ( (colst[0]->co_type == Cft_Overlay) && ca->bi ) {
4397 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
4398 } else if ( colst[0]->co_type == Cft_Schema ) {
4399 schema_destroy_one( ca, colst, nocs, last );
4404 ch_free( ca->argv );
4405 if ( colst ) ch_free( colst );
4409 #define BIGTMP 10000
4411 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
4412 int base, int rebase, int max, int use_ldif )
4414 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
4415 ConfigType etype = ce->ce_type;
4416 int count = 0, rc = 0;
4418 /* Reverse ce list */
4419 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
4420 if (ce2->ce_type != etype) {
4425 ce2->ce_sibs = cetmp;
4428 if ( max && count >= max ) {
4434 /* Move original to a temp name until increments are done */
4436 ce->ce_entry->e_private = NULL;
4437 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4438 base+BIGTMP, 0, use_ldif );
4439 ce->ce_entry->e_private = ce;
4441 /* start incrementing */
4442 for (ce2=cetmp; ce2; ce2=ce3) {
4444 ce2->ce_sibs = cerem;
4447 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
4448 count+base, 0, use_ldif );
4452 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4453 base, 0, use_ldif );
4458 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
4459 CfEntryInfo *ce2, int old, int use_ldif )
4463 /* Renumber original to a temp value */
4464 ce->ce_entry->e_private = NULL;
4465 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4466 old+BIGTMP, 0, use_ldif );
4467 ce->ce_entry->e_private = ce;
4469 /* start decrementing */
4470 for (; ce2 != ce; ce2=ce2->ce_sibs) {
4471 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
4472 count+old, 0, use_ldif );
4475 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4476 count+old, 0, use_ldif );
4479 /* Parse an LDAP entry into config directives, then store in underlying
4483 config_back_add( Operation *op, SlapReply *rs )
4489 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
4490 NULL, ACL_WADD, NULL )) {
4491 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4495 cfb = (CfBackInfo *)op->o_bd->be_private;
4497 /* add opattrs for syncprov */
4499 char textbuf[SLAP_TEXT_BUFLEN];
4500 size_t textlen = sizeof textbuf;
4501 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1,
4502 &rs->sr_text, textbuf, sizeof( textbuf ) );
4503 if ( rs->sr_err != LDAP_SUCCESS )
4505 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
4506 if ( rs->sr_err != LDAP_SUCCESS ) {
4507 Debug( LDAP_DEBUG_TRACE,
4508 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
4509 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
4514 ldap_pvt_thread_pool_pause( &connection_pool );
4517 * 1) check for existence of entry
4518 * 2) check for sibling renumbering
4519 * 3) perform internal add
4520 * 4) perform any necessary renumbering
4521 * 5) store entry in underlying database
4523 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
4524 if ( rs->sr_err != LDAP_SUCCESS ) {
4525 rs->sr_text = ca.cr_msg;
4530 CfEntryInfo *ce = ca.ca_entry->e_private;
4531 req_add_s addr = op->oq_add;
4532 op->o_tag = LDAP_REQ_MODRDN;
4533 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
4534 op->o_tag = LDAP_REQ_ADD;
4536 if ( rs->sr_err != LDAP_SUCCESS ) {
4541 if ( cfb->cb_use_ldif ) {
4542 BackendDB *be = op->o_bd;
4543 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4544 struct berval dn, ndn;
4546 op->o_bd = &cfb->cb_db;
4548 /* Save current rootdn; use the underlying DB's rootdn */
4551 op->o_dn = op->o_bd->be_rootdn;
4552 op->o_ndn = op->o_bd->be_rootndn;
4554 scp = op->o_callback;
4555 op->o_callback = ≻
4556 op->o_bd->be_add( op, rs );
4558 op->o_callback = scp;
4564 ldap_pvt_thread_pool_resume( &connection_pool );
4567 send_ldap_result( op, rs );
4568 slap_graduate_commit_csn( op );
4572 typedef struct delrec {
4573 struct delrec *next;
4579 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
4584 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
4585 ca->line[0] == '{' )
4587 char *ptr = strchr( ca->line + 1, '}' );
4591 ca->valx = strtol( ca->line + 1, &next, 0 );
4592 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
4598 rc = config_parse_add( ct, ca, i );
4606 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
4609 int rc = LDAP_UNWILLING_TO_PERFORM;
4611 Entry *e = ce->ce_entry;
4612 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
4617 delrec *dels = NULL, *deltail = NULL;
4619 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4620 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
4622 colst = count_ocs( oc_at, &nocs );
4624 /* make sure add/del flags are clear; should always be true */
4625 for ( s = save_attrs; s; s = s->a_next ) {
4626 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
4629 e->e_attrs = attrs_dup( e->e_attrs );
4631 init_config_argv( ca );
4634 ca->private = ce->ce_private;
4636 ca->fname = "slapd";
4638 strcpy( ca->log, "back-config" );
4640 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
4641 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
4642 switch (ml->sml_op) {
4643 case LDAP_MOD_DELETE:
4644 case LDAP_MOD_REPLACE: {
4645 BerVarray vals = NULL, nvals = NULL;
4647 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
4649 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
4650 ml->sml_desc->ad_cname.bv_val );
4653 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4654 vals = ml->sml_values;
4655 nvals = ml->sml_nvalues;
4656 ml->sml_values = NULL;
4657 ml->sml_nvalues = NULL;
4659 /* If we're deleting by values, remember the indexes of the
4660 * values we deleted.
4662 if ( ct && ml->sml_values ) {
4664 i = ml->sml_numvals;
4665 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
4676 rc = modify_delete_vindex(e, &ml->sml_mod,
4677 get_permissiveModify(op),
4678 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
4679 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4680 ml->sml_values = vals;
4681 ml->sml_nvalues = nvals;
4686 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
4689 case SLAP_MOD_SOFTADD: {
4690 int mop = ml->sml_op;
4692 ml->sml_op = LDAP_MOD_ADD;
4694 if ( ct->arg_type & ARG_NO_INSERT ) {
4695 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
4697 navals = a->a_numvals;
4700 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
4701 if ( ml->sml_values[i].bv_val[0] == '{' &&
4704 char *next, *val = ml->sml_values[i].bv_val + 1;
4707 j = strtol( val, &next, 0 );
4708 if ( next == val || next[ 0 ] != '}' || j < navals ) {
4710 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
4711 ml->sml_desc->ad_cname.bv_val );
4715 rc = check_vals( ct, ca, ml, 0 );
4716 if ( rc ) goto out_noop;
4719 rc = modify_add_values(e, &ml->sml_mod,
4720 get_permissiveModify(op),
4721 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
4723 /* If value already exists, show success here
4724 * and ignore this operation down below.
4726 if ( mop == SLAP_MOD_SOFTADD ) {
4727 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
4737 case LDAP_MOD_INCREMENT: /* FIXME */
4742 if(rc != LDAP_SUCCESS) break;
4745 if ( rc == LDAP_SUCCESS) {
4746 /* check that the entry still obeys the schema */
4747 rc = entry_schema_check(op, e, NULL, 0, 0,
4748 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
4749 if ( rc ) goto out_noop;
4751 /* Basic syntax checks are OK. Do the actual settings. */
4752 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
4753 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
4754 if ( !ct ) continue;
4756 s = attr_find( save_attrs, ml->sml_desc );
4757 a = attr_find( e->e_attrs, ml->sml_desc );
4759 switch (ml->sml_op) {
4760 case LDAP_MOD_DELETE:
4761 case LDAP_MOD_REPLACE: {
4762 BerVarray vals = NULL, nvals = NULL;
4765 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4766 vals = ml->sml_values;
4767 nvals = ml->sml_nvalues;
4768 ml->sml_values = NULL;
4769 ml->sml_nvalues = NULL;
4772 if ( ml->sml_values )
4775 /* If we didn't delete the whole attribute */
4776 if ( ml->sml_values && a ) {
4777 struct berval *mvals;
4780 if ( ml->sml_nvalues )
4781 mvals = ml->sml_nvalues;
4783 mvals = ml->sml_values;
4785 /* use the indexes we saved up above */
4786 for (i=0; i < d->nidx; i++) {
4787 struct berval bv = *mvals++;
4788 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
4789 bv.bv_val[0] == '{' ) {
4790 ptr = strchr( bv.bv_val, '}' ) + 1;
4791 bv.bv_len -= ptr - bv.bv_val;
4794 ca->line = bv.bv_val;
4795 ca->valx = d->idx[i];
4796 rc = config_del_vals( ct, ca );
4797 if ( rc != LDAP_SUCCESS ) break;
4799 s->a_flags |= SLAP_ATTR_IXDEL;
4800 for (j=i+1; j < d->nidx; j++)
4801 if ( d->idx[j] >d->idx[i] )
4807 rc = config_del_vals( ct, ca );
4808 if ( rc ) rc = LDAP_OTHER;
4810 s->a_flags |= SLAP_ATTR_IXDEL;
4812 if ( ml->sml_values ) {
4817 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4818 ml->sml_values = vals;
4819 ml->sml_nvalues = nvals;
4821 if ( !vals || rc != LDAP_SUCCESS )
4824 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
4827 for (i=0; ml->sml_values[i].bv_val; i++) {
4828 ca->line = ml->sml_values[i].bv_val;
4830 rc = config_modify_add( ct, ca, ml->sml_desc, i );
4833 a->a_flags |= SLAP_ATTR_IXADD;
4840 /* Undo for a failed operation */
4841 if ( rc != LDAP_SUCCESS ) {
4842 ConfigReply msg = ca->reply;
4843 for ( s = save_attrs; s; s = s->a_next ) {
4844 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
4845 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
4846 ct = config_find_table( colst, nocs, s->a_desc, ca );
4847 a = attr_find( e->e_attrs, s->a_desc );
4849 /* clear the flag so the add check below will skip it */
4850 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
4853 config_del_vals( ct, ca );
4855 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
4856 ca->line = s->a_vals[i].bv_val;
4858 config_modify_add( ct, ca, s->a_desc, i );
4862 for ( a = e->e_attrs; a; a = a->a_next ) {
4863 if ( a->a_flags & SLAP_ATTR_IXADD ) {
4864 ct = config_find_table( colst, nocs, a->a_desc, ca );
4867 config_del_vals( ct, ca );
4868 s = attr_find( save_attrs, a->a_desc );
4870 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
4871 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
4872 ca->line = s->a_vals[i].bv_val;
4874 config_modify_add( ct, ca, s->a_desc, i );
4885 if ( rc == LDAP_SUCCESS ) {
4886 attrs_free( save_attrs );
4888 attrs_free( e->e_attrs );
4889 e->e_attrs = save_attrs;
4891 ch_free( ca->argv );
4892 if ( colst ) ch_free( colst );
4894 deltail = dels->next;
4903 config_back_modify( Operation *op, SlapReply *rs )
4906 CfEntryInfo *ce, *last;
4908 ConfigArgs ca = {0};
4911 AttributeDescription *rad = NULL;
4914 cfb = (CfBackInfo *)op->o_bd->be_private;
4916 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
4919 rs->sr_matched = last->ce_entry->e_name.bv_val;
4920 rs->sr_err = LDAP_NO_SUCH_OBJECT;
4924 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
4925 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4929 /* Get type of RDN */
4930 rdn = ce->ce_entry->e_nname;
4931 ptr = strchr( rdn.bv_val, '=' );
4932 rdn.bv_len = ptr - rdn.bv_val;
4933 slap_bv2ad( &rdn, &rad, &rs->sr_text );
4935 /* Some basic validation... */
4936 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
4937 /* Don't allow Modify of RDN; must use ModRdn for that. */
4938 if ( ml->sml_desc == rad ) {
4939 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
4940 rs->sr_text = "Use modrdn to change the entry name";
4943 /* Internal update of contextCSN? */
4944 if ( ml->sml_desc == slap_schema.si_ad_contextCSN && op->o_conn->c_conn_idx == -1 ) {
4950 slap_mods_opattrs( op, &op->orm_modlist, 1 );
4953 ldap_pvt_thread_pool_pause( &connection_pool );
4956 * 1) perform the Modify on the cached Entry.
4957 * 2) verify that the Entry still satisfies the schema.
4958 * 3) perform the individual config operations.
4959 * 4) store Modified entry in underlying LDIF backend.
4961 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
4963 rs->sr_text = ca.cr_msg;
4964 } else if ( cfb->cb_use_ldif ) {
4965 BackendDB *be = op->o_bd;
4966 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4967 struct berval dn, ndn;
4969 op->o_bd = &cfb->cb_db;
4973 op->o_dn = op->o_bd->be_rootdn;
4974 op->o_ndn = op->o_bd->be_rootndn;
4976 scp = op->o_callback;
4977 op->o_callback = ≻
4978 op->o_bd->be_modify( op, rs );
4980 op->o_callback = scp;
4986 ldap_pvt_thread_pool_resume( &connection_pool );
4988 send_ldap_result( op, rs );
4989 slap_graduate_commit_csn( op );
4994 config_back_modrdn( Operation *op, SlapReply *rs )
4997 CfEntryInfo *ce, *last;
5001 cfb = (CfBackInfo *)op->o_bd->be_private;
5003 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5006 rs->sr_matched = last->ce_entry->e_name.bv_val;
5007 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5010 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
5011 NULL, ACL_WRITE, NULL )) {
5012 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5016 if ( ce->ce_parent )
5017 parent = ce->ce_parent->ce_entry;
5019 parent = (Entry *)&slap_entry_root;
5020 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
5021 NULL, ACL_WRITE, NULL )) {
5022 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5027 /* We don't allow moving objects to new parents.
5028 * Generally we only allow reordering a set of ordered entries.
5030 if ( op->orr_newSup ) {
5031 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5035 /* If newRDN == oldRDN, quietly succeed */
5036 dnRdn( &op->o_req_ndn, &rdn );
5037 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
5038 rs->sr_err = LDAP_SUCCESS;
5042 /* Current behavior, subject to change as needed:
5044 * For backends and overlays, we only allow renumbering.
5045 * For schema, we allow renaming with the same number.
5046 * Otherwise, the op is not allowed.
5049 if ( ce->ce_type == Cft_Schema ) {
5053 /* Can't alter the main cn=schema entry */
5054 if ( ce->ce_parent->ce_type == Cft_Global ) {
5055 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5056 rs->sr_text = "renaming not allowed for this entry";
5060 /* We could support this later if desired */
5061 ptr1 = ber_bvchr( &rdn, '}' );
5062 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5063 len = ptr1 - rdn.bv_val;
5064 if ( len != ptr2 - op->orr_newrdn.bv_val ||
5065 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
5066 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5067 rs->sr_text = "schema reordering not supported";
5070 } else if ( ce->ce_type == Cft_Database ||
5071 ce->ce_type == Cft_Overlay ) {
5072 char *ptr1, *ptr2, *iptr1, *iptr2;
5075 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
5076 if ( *iptr2 != '{' ) {
5077 rs->sr_err = LDAP_NAMING_VIOLATION;
5078 rs->sr_text = "new ordering index is required";
5082 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
5083 ptr1 = ber_bvchr( &rdn, '}' );
5084 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5086 rs->sr_err = LDAP_NAMING_VIOLATION;
5087 rs->sr_text = "new ordering index is required";
5091 len1 = ptr1 - rdn.bv_val;
5092 len2 = ptr2 - op->orr_newrdn.bv_val;
5094 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
5095 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
5096 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5097 rs->sr_text = "changing database/overlay type not allowed";
5100 ixold = strtol( iptr1, NULL, 0 );
5101 ixnew = strtol( iptr2, &ptr1, 0 );
5102 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
5103 rs->sr_err = LDAP_NAMING_VIOLATION;
5106 /* config DB is always 0, cannot be changed */
5107 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
5108 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
5112 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5113 rs->sr_text = "renaming not supported for this entry";
5117 ldap_pvt_thread_pool_pause( &connection_pool );
5119 if ( ce->ce_type == Cft_Schema ) {
5120 req_modrdn_s modr = op->oq_modrdn;
5123 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
5124 if ( rs->sr_err == LDAP_SUCCESS ) {
5125 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
5126 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
5129 op->oq_modrdn = modr;
5131 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
5132 req_modrdn_s modr = op->oq_modrdn;
5135 /* Advance to first of this type */
5136 cprev = &ce->ce_parent->ce_kids;
5137 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
5138 cprev = &ce2->ce_sibs;
5141 /* Skip the -1 entry */
5142 if ( ce->ce_type == Cft_Database ) {
5143 cprev = &ce2->ce_sibs;
5149 /* Remove from old slot */
5150 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
5151 cprev = &ce2->ce_sibs;
5152 *cprev = ce->ce_sibs;
5153 ceold = ce->ce_sibs;
5155 /* Insert into new slot */
5157 for ( i=0; i<ixnew; i++ ) {
5161 cprev = &ce2->ce_sibs;
5163 ce->ce_sibs = *cprev;
5168 /* NOTE: These should be encoded in the OC tables, not inline here */
5169 if ( ce->ce_type == Cft_Database )
5170 backend_db_move( ce->ce_be, ixnew );
5171 else if ( ce->ce_type == Cft_Overlay )
5172 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
5174 if ( ixold < ixnew ) {
5175 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
5178 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
5179 ixold - ixnew, cfb->cb_use_ldif );
5181 op->oq_modrdn = modr;
5184 ldap_pvt_thread_pool_resume( &connection_pool );
5186 send_ldap_result( op, rs );
5191 config_back_delete( Operation *op, SlapReply *rs )
5193 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM, NULL );
5198 config_back_search( Operation *op, SlapReply *rs )
5201 CfEntryInfo *ce, *last;
5204 cfb = (CfBackInfo *)op->o_bd->be_private;
5206 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5209 rs->sr_matched = last->ce_entry->e_name.bv_val;
5210 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5213 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
5214 ACL_SEARCH, NULL, &mask ))
5216 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
5217 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5219 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5223 switch ( op->ors_scope ) {
5224 case LDAP_SCOPE_BASE:
5225 case LDAP_SCOPE_SUBTREE:
5226 config_send( op, rs, ce, 0 );
5229 case LDAP_SCOPE_ONELEVEL:
5230 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
5231 config_send( op, rs, ce, 1 );
5236 rs->sr_err = LDAP_SUCCESS;
5238 send_ldap_result( op, rs );
5242 /* no-op, we never free entries */
5243 int config_entry_release(
5248 if ( !e->e_private ) {
5251 return LDAP_SUCCESS;
5254 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
5256 int config_back_entry_get(
5260 AttributeDescription *at,
5265 CfEntryInfo *ce, *last;
5267 cfb = (CfBackInfo *)op->o_bd->be_private;
5269 ce = config_find_base( cfb->cb_root, ndn, &last );
5271 *ent = ce->ce_entry;
5272 if ( *ent && oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
5277 return ( *ent == NULL ? 1 : 0 );
5281 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
5282 ConfigTable *ct, ConfigArgs *c )
5286 for (; at && *at; at++) {
5287 /* Skip the naming attr */
5288 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
5290 for (i=0;ct[i].name;i++) {
5291 if (ct[i].ad == (*at)->sat_ad) {
5292 rc = config_get_vals(&ct[i], c);
5293 /* NOTE: tolerate that config_get_vals()
5294 * returns success with no values */
5295 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
5296 if ( c->rvalue_nvals )
5297 attr_merge(e, ct[i].ad, c->rvalue_vals,
5300 attr_merge_normalize(e, ct[i].ad,
5301 c->rvalue_vals, NULL);
5302 ber_bvarray_free( c->rvalue_nvals );
5303 ber_bvarray_free( c->rvalue_vals );
5312 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
5313 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
5315 Entry *e = entry_alloc();
5316 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5318 struct berval ad_name;
5319 AttributeDescription *ad = NULL;
5326 CfEntryInfo *ceprev = NULL;
5328 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
5331 ce->ce_type = main->co_type;
5332 ce->ce_parent = parent;
5334 pdn = parent->ce_entry->e_nname;
5335 if ( parent->ce_kids )
5336 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
5337 ceprev->ce_type <= ce->ce_type;
5338 ceprev = ceprev->ce_sibs );
5343 ce->ce_private = c->private;
5347 build_new_dn( &e->e_name, &pdn, rdn, NULL );
5348 ber_dupbv( &e->e_nname, &e->e_name );
5350 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
5351 main->co_name, NULL );
5353 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
5354 extra->co_name, NULL );
5355 ptr = strchr(rdn->bv_val, '=');
5356 ad_name.bv_val = rdn->bv_val;
5357 ad_name.bv_len = ptr - rdn->bv_val;
5358 rc = slap_bv2ad( &ad_name, &ad, &text );
5363 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
5364 attr_merge_normalize_one(e, ad, &val, NULL );
5367 c->table = main->co_type;
5368 if ( oc->soc_required )
5369 config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
5371 if ( oc->soc_allowed )
5372 config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
5376 c->table = extra->co_type;
5377 if ( oc->soc_required )
5378 config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
5380 if ( oc->soc_allowed )
5381 config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
5384 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5385 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
5386 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
5387 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
5388 if ( op && !op->o_noop ) {
5390 op->ora_modlist = NULL;
5391 op->o_bd->be_add( op, rs );
5392 if ( ( rs->sr_err != LDAP_SUCCESS )
5393 && (rs->sr_err != LDAP_ALREADY_EXISTS) ) {
5398 ce->ce_sibs = ceprev->ce_sibs;
5399 ceprev->ce_sibs = ce;
5400 } else if ( parent ) {
5401 ce->ce_sibs = parent->ce_kids;
5402 parent->ce_kids = ce;
5409 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
5410 Operation *op, SlapReply *rs )
5413 ConfigFile *cf = c->private;
5417 for (; cf; cf=cf->c_sibs, c->depth++) {
5418 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
5419 !cf->c_om_head ) continue;
5420 c->value_dn.bv_val = c->log;
5421 LUTIL_SLASHPATH( cf->c_file.bv_val );
5422 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
5427 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
5429 ptr = strchr( bv.bv_val, '.' );
5431 bv.bv_len = ptr - bv.bv_val;
5432 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
5433 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
5434 /* FIXME: how can indicate error? */
5437 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
5439 c->value_dn.bv_len += bv.bv_len;
5440 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
5443 e = config_build_entry( op, rs, ceparent, c, &c->value_dn,
5444 &CFOC_SCHEMA, NULL );
5447 } else if ( e && cf->c_kids ) {
5448 c->private = cf->c_kids;
5449 config_build_schema_inc( c, e->e_private, op, rs );
5455 #ifdef SLAPD_MODULES
5458 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
5459 Operation *op, SlapReply *rs )
5464 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
5465 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
5467 c->value_dn.bv_val = c->log;
5468 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
5469 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
5470 /* FIXME: how can indicate error? */
5474 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
5483 config_check_schema(Operation *op, CfBackInfo *cfb)
5485 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
5487 CfEntryInfo *ce, *last;
5490 /* If there's no root entry, we must be in the midst of converting */
5491 if ( !cfb->cb_root )
5494 /* Make sure the main schema entry exists */
5495 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
5502 /* Make sure it's up to date */
5503 if ( cf_om_tail != om_sys_tail ) {
5504 a = attr_find( e->e_attrs, cfAd_om );
5506 if ( a->a_nvals != a->a_vals )
5507 ber_bvarray_free( a->a_nvals );
5508 ber_bvarray_free( a->a_vals );
5513 oidm_unparse( &bv, NULL, NULL, 1 );
5514 attr_merge_normalize( e, cfAd_om, bv, NULL );
5515 ber_bvarray_free( bv );
5516 cf_om_tail = om_sys_tail;
5518 if ( cf_at_tail != at_sys_tail ) {
5519 a = attr_find( e->e_attrs, cfAd_attr );
5521 if ( a->a_nvals != a->a_vals )
5522 ber_bvarray_free( a->a_nvals );
5523 ber_bvarray_free( a->a_vals );
5528 at_unparse( &bv, NULL, NULL, 1 );
5529 attr_merge_normalize( e, cfAd_attr, bv, NULL );
5530 ber_bvarray_free( bv );
5531 cf_at_tail = at_sys_tail;
5533 if ( cf_oc_tail != oc_sys_tail ) {
5534 a = attr_find( e->e_attrs, cfAd_oc );
5536 if ( a->a_nvals != a->a_vals )
5537 ber_bvarray_free( a->a_nvals );
5538 ber_bvarray_free( a->a_vals );
5543 oc_unparse( &bv, NULL, NULL, 1 );
5544 attr_merge_normalize( e, cfAd_oc, bv, NULL );
5545 ber_bvarray_free( bv );
5546 cf_oc_tail = oc_sys_tail;
5549 SlapReply rs = {REP_RESULT};
5551 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
5552 &CFOC_SCHEMA, NULL );
5557 ce->ce_private = cfb->cb_config;
5558 cf_at_tail = at_sys_tail;
5559 cf_oc_tail = oc_sys_tail;
5560 cf_om_tail = om_sys_tail;
5565 static const char *defacl[] = {
5566 NULL, "to", "*", "by", "*", "none", NULL
5570 config_back_db_open( BackendDB *be, ConfigReply *cr )
5572 CfBackInfo *cfb = be->be_private;
5575 CfEntryInfo *ce, *ceparent;
5579 Connection conn = {0};
5580 OperationBuffer opbuf;
5582 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
5583 SlapReply rs = {REP_RESULT};
5584 void *thrctx = NULL;
5586 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
5588 /* If we have no explicitly configured ACLs, don't just use
5589 * the global ACLs. Explicitly deny access to everything.
5591 if ( frontendDB->be_acl && be->be_acl == frontendDB->be_acl ) {
5592 parse_acl(be, "config_back_db_open", 0, 6, (char **)defacl, 0 );
5595 thrctx = ldap_pvt_thread_pool_context();
5596 connection_fake_init( &conn, &opbuf, thrctx );
5599 op->o_tag = LDAP_REQ_ADD;
5600 op->o_callback = &cb;
5601 op->o_bd = &cfb->cb_db;
5602 op->o_dn = op->o_bd->be_rootdn;
5603 op->o_ndn = op->o_bd->be_rootndn;
5605 if ( !cfb->cb_use_ldif ) {
5609 /* If we read the config from back-ldif, do some quick sanity checks */
5610 if ( cfb->cb_got_ldif ) {
5611 return config_check_schema( op, cfb );
5614 /* create root of tree */
5616 c.private = cfb->cb_config;
5618 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
5628 #ifdef SLAPD_MODULES
5629 /* Create Module nodes... */
5630 if ( modpaths.mp_loads ) {
5631 if ( config_build_modules( &c, ceparent, op, &rs ) ){
5637 /* Create schema nodes... cn=schema will contain the hardcoded core
5638 * schema, read-only. Child objects will contain runtime loaded schema
5643 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
5648 ce->ce_private = cfb->cb_config;
5649 cf_at_tail = at_sys_tail;
5650 cf_oc_tail = oc_sys_tail;
5651 cf_om_tail = om_sys_tail;
5653 /* Create schema nodes for included schema... */
5654 if ( cfb->cb_config->c_kids ) {
5656 c.private = cfb->cb_config->c_kids;
5657 if (config_build_schema_inc( &c, ce, op, &rs )) {
5662 /* Create backend nodes. Skip if they don't provide a cf_table.
5663 * There usually aren't any of these.
5667 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
5668 if (!bi->bi_cf_ocs) {
5669 /* If it only supports the old config mech, complain. */
5670 if ( bi->bi_config ) {
5671 Debug( LDAP_DEBUG_ANY,
5672 "WARNING: No dynamic config support for backend %s.\n",
5673 bi->bi_type, 0, 0 );
5678 if (!bi->bi_private) continue;
5681 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
5682 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
5683 if ( rdn.bv_len >= sizeof( c.log ) ) {
5684 /* FIXME: holler ... */ ;
5687 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
5694 /* Create database nodes... */
5695 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
5696 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
5697 for ( i = -1, be = frontendDB ; be;
5698 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
5699 slap_overinfo *oi = NULL;
5701 if ( overlay_is_over( be )) {
5702 oi = be->bd_info->bi_private;
5708 /* If this backend supports the old config mechanism, but not
5709 * the new mech, complain.
5711 if ( !be->be_cf_ocs && bi->bi_db_config ) {
5712 Debug( LDAP_DEBUG_ANY,
5713 "WARNING: No dynamic config support for database %s.\n",
5714 bi->bi_type, 0, 0 );
5718 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
5719 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
5721 if ( rdn.bv_len >= sizeof( c.log ) ) {
5722 /* FIXME: holler ... */ ;
5726 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
5732 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd )
5733 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
5734 /* Iterate through overlays */
5740 for (j=0,on=oi->oi_list; on; j++,on=on->on_next) {
5741 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
5742 Debug( LDAP_DEBUG_ANY,
5743 "WARNING: No dynamic config support for overlay %s.\n",
5744 on->on_bi.bi_type, 0, 0 );
5748 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
5749 "%s=" SLAP_X_ORDERED_FMT "%s",
5750 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
5751 if ( rdn.bv_len >= sizeof( c.log ) ) {
5752 /* FIXME: holler ... */ ;
5756 oe = config_build_entry( op, &rs, ce, &c, &rdn,
5757 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
5761 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd )
5762 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
5767 ldap_pvt_thread_pool_context_reset( thrctx );
5769 if ( unsupp && cfb->cb_use_ldif ) {
5770 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
5771 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
5778 cfb_free_cffile( ConfigFile *cf )
5782 for (; cf; cf=next) {
5785 cfb_free_cffile( cf->c_kids );
5786 ch_free( cf->c_file.bv_val );
5787 ber_bvarray_free( cf->c_dseFiles );
5793 cfb_free_entries( CfEntryInfo *ce )
5797 for (; ce; ce=next) {
5800 cfb_free_entries( ce->ce_kids );
5801 ce->ce_entry->e_private = NULL;
5802 entry_free( ce->ce_entry );
5808 config_back_db_close( BackendDB *be, ConfigReply *cr )
5810 CfBackInfo *cfb = be->be_private;
5812 cfb_free_entries( cfb->cb_root );
5813 cfb->cb_root = NULL;
5815 if ( cfb->cb_db.bd_info ) {
5816 backend_shutdown( &cfb->cb_db );
5823 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
5825 CfBackInfo *cfb = be->be_private;
5827 cfb_free_cffile( cfb->cb_config );
5829 ch_free( cfdir.bv_val );
5831 avl_free( CfOcTree, NULL );
5833 if ( cfb->cb_db.bd_info ) {
5834 cfb->cb_db.be_suffix = NULL;
5835 cfb->cb_db.be_nsuffix = NULL;
5836 BER_BVZERO( &cfb->cb_db.be_rootdn );
5837 BER_BVZERO( &cfb->cb_db.be_rootndn );
5839 backend_destroy_one( &cfb->cb_db, 0 );
5848 config_back_db_init( BackendDB *be, ConfigReply* cr )
5854 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
5855 cfn = cfb->cb_config;
5856 be->be_private = cfb;
5858 ber_dupbv( &be->be_rootdn, &config_rdn );
5859 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
5860 ber_dupbv( &dn, &be->be_rootdn );
5861 ber_bvarray_add( &be->be_suffix, &dn );
5862 ber_dupbv( &dn, &be->be_rootdn );
5863 ber_bvarray_add( &be->be_nsuffix, &dn );
5865 /* Hide from namingContexts */
5866 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
5872 config_back_destroy( BackendInfo *bi )
5874 ldif_must_b64_encode_release();
5879 config_tool_entry_open( BackendDB *be, int mode )
5881 CfBackInfo *cfb = be->be_private;
5882 BackendInfo *bi = cfb->cb_db.bd_info;
5884 if ( bi && bi->bi_tool_entry_open )
5885 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
5892 config_tool_entry_close( BackendDB *be )
5894 CfBackInfo *cfb = be->be_private;
5895 BackendInfo *bi = cfb->cb_db.bd_info;
5897 if ( bi && bi->bi_tool_entry_close )
5898 return bi->bi_tool_entry_close( &cfb->cb_db );
5904 config_tool_entry_first( BackendDB *be )
5906 CfBackInfo *cfb = be->be_private;
5907 BackendInfo *bi = cfb->cb_db.bd_info;
5909 if ( bi && bi->bi_tool_entry_first )
5910 return bi->bi_tool_entry_first( &cfb->cb_db );
5916 config_tool_entry_next( BackendDB *be )
5918 CfBackInfo *cfb = be->be_private;
5919 BackendInfo *bi = cfb->cb_db.bd_info;
5921 if ( bi && bi->bi_tool_entry_next )
5922 return bi->bi_tool_entry_next( &cfb->cb_db );
5928 config_tool_entry_get( BackendDB *be, ID id )
5930 CfBackInfo *cfb = be->be_private;
5931 BackendInfo *bi = cfb->cb_db.bd_info;
5933 if ( bi && bi->bi_tool_entry_get )
5934 return bi->bi_tool_entry_get( &cfb->cb_db, id );
5939 static int entry_put_got_frontend=0;
5940 static int entry_put_got_config=0;
5942 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
5944 CfBackInfo *cfb = be->be_private;
5945 BackendInfo *bi = cfb->cb_db.bd_info;
5947 struct berval rdn, vals[ 2 ];
5949 OperationBuffer opbuf;
5951 Connection conn = {0};
5952 Operation *op = NULL;
5956 /* Create entry for frontend database if it does not exist already */
5957 if ( !entry_put_got_frontend ) {
5958 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
5959 STRLENOF( "olcDatabase" ))) {
5960 if ( strncmp( e->e_nname.bv_val +
5961 STRLENOF( "olcDatabase" ), "={-1}frontend",
5962 STRLENOF( "={-1}frontend" )) &&
5963 strncmp( e->e_nname.bv_val +
5964 STRLENOF( "olcDatabase" ), "=frontend",
5965 STRLENOF( "=frontend" ))) {
5967 vals[1].bv_val = NULL;
5968 memset( &ca, 0, sizeof(ConfigArgs));
5970 ca.bi = frontendDB->bd_info;
5971 ca.be->be_cf_ocs = &CFOC_FRONTEND;
5972 rdn.bv_val = ca.log;
5973 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
5974 "%s=" SLAP_X_ORDERED_FMT "%s",
5975 cfAd_database->ad_cname.bv_val, -1,
5977 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
5978 &CFOC_DATABASE, ca.be->be_cf_ocs );
5979 thrctx = ldap_pvt_thread_pool_context();
5980 connection_fake_init2( &conn, &opbuf, thrctx,0 );
5982 op->o_bd = &cfb->cb_db;
5983 op->o_tag = LDAP_REQ_ADD;
5985 op->o_dn = be->be_rootdn;
5986 op->o_ndn = be->be_rootndn;
5987 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
5988 if ( rc != LDAP_SUCCESS ) {
5989 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
5990 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
5994 if ( ce && bi && bi->bi_tool_entry_put &&
5995 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
5996 entry_put_got_frontend++;
5998 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
5999 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
6003 entry_put_got_frontend++;
6008 /* Create entry for config database if it does not exist already */
6009 if ( !entry_put_got_config && !isFrontend ) {
6010 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
6011 STRLENOF( "olcDatabase" ))) {
6012 if ( strncmp( e->e_nname.bv_val +
6013 STRLENOF( "olcDatabase" ), "={0}config",
6014 STRLENOF( "={0}config" )) &&
6015 strncmp( e->e_nname.bv_val +
6016 STRLENOF( "olcDatabase" ), "=config",
6017 STRLENOF( "=config" )) ) {
6019 vals[1].bv_val = NULL;
6020 memset( &ca, 0, sizeof(ConfigArgs));
6021 ca.be = LDAP_STAILQ_FIRST( &backendDB );
6022 ca.bi = ca.be->bd_info;
6023 rdn.bv_val = ca.log;
6024 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
6025 "%s=" SLAP_X_ORDERED_FMT "%s",
6026 cfAd_database->ad_cname.bv_val, 0,
6028 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
6031 thrctx = ldap_pvt_thread_pool_context();
6032 connection_fake_init2( &conn, &opbuf, thrctx,0 );
6034 op->o_bd = &cfb->cb_db;
6035 op->o_tag = LDAP_REQ_ADD;
6036 op->o_dn = be->be_rootdn;
6037 op->o_ndn = be->be_rootndn;
6040 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
6041 if ( rc != LDAP_SUCCESS ) {
6042 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
6043 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
6046 if (ce && bi && bi->bi_tool_entry_put &&
6047 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
6048 entry_put_got_config++;
6050 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
6051 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
6055 entry_put_got_config++;
6059 if ( bi && bi->bi_tool_entry_put &&
6060 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
6061 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
6068 AttributeDescription **desc;
6070 { "attribute", &cfAd_attr },
6071 { "backend", &cfAd_backend },
6072 { "database", &cfAd_database },
6073 { "include", &cfAd_include },
6074 { "objectclass", &cfAd_oc },
6075 { "objectidentifier", &cfAd_om },
6076 { "overlay", &cfAd_overlay },
6081 * add / delete: all types that may be added or deleted must use an
6082 * X-ORDERED attributeType for their RDN. Adding and deleting entries
6083 * should automatically renumber the index of any siblings as needed,
6084 * so that no gaps in the numbering sequence exist after the add/delete
6086 * What can be added:
6088 * backend objects for backend-specific config directives
6092 * delete: probably no support this time around.
6094 * modrdn: generally not done. Will be invoked automatically by add/
6095 * delete to update numbering sequence. Perform as an explicit operation
6096 * so that the renumbering effect may be replicated. Subtree rename must
6097 * be supported, since renumbering a database will affect all its child
6100 * modify: must be fully supported.
6104 config_back_initialize( BackendInfo *bi )
6106 ConfigTable *ct = config_back_cf_table;
6110 AttributeDescription *ad = NULL;
6112 static char *controls[] = {
6113 LDAP_CONTROL_MANAGEDSAIT,
6117 /* Make sure we don't exceed the bits reserved for userland */
6118 config_check_userland( CFG_LAST );
6120 bi->bi_controls = controls;
6125 bi->bi_destroy = config_back_destroy;
6127 bi->bi_db_init = config_back_db_init;
6128 bi->bi_db_config = 0;
6129 bi->bi_db_open = config_back_db_open;
6130 bi->bi_db_close = config_back_db_close;
6131 bi->bi_db_destroy = config_back_db_destroy;
6133 bi->bi_op_bind = config_back_bind;
6134 bi->bi_op_unbind = 0;
6135 bi->bi_op_search = config_back_search;
6136 bi->bi_op_compare = 0;
6137 bi->bi_op_modify = config_back_modify;
6138 bi->bi_op_modrdn = config_back_modrdn;
6139 bi->bi_op_add = config_back_add;
6140 bi->bi_op_delete = config_back_delete;
6141 bi->bi_op_abandon = 0;
6143 bi->bi_extended = 0;
6145 bi->bi_chk_referrals = 0;
6147 bi->bi_access_allowed = slap_access_allowed;
6149 bi->bi_connection_init = 0;
6150 bi->bi_connection_destroy = 0;
6152 bi->bi_entry_release_rw = config_entry_release;
6153 bi->bi_entry_get_rw = config_back_entry_get;
6155 bi->bi_tool_entry_open = config_tool_entry_open;
6156 bi->bi_tool_entry_close = config_tool_entry_close;
6157 bi->bi_tool_entry_first = config_tool_entry_first;
6158 bi->bi_tool_entry_next = config_tool_entry_next;
6159 bi->bi_tool_entry_get = config_tool_entry_get;
6160 bi->bi_tool_entry_put = config_tool_entry_put;
6163 argv[ 0 ] = "slapd";
6169 for (i=0; OidMacros[i].name; i++ ) {
6170 argv[1] = OidMacros[i].name;
6171 argv[2] = OidMacros[i].oid;
6172 parse_oidm( &ca, 0, NULL );
6175 bi->bi_cf_ocs = cf_ocs;
6177 i = config_register_schema( ct, cf_ocs );
6180 /* setup olcRootPW to be base64-encoded when written in LDIF form;
6181 * basically, we don't care if it fails */
6182 i = slap_str2ad( "olcRootPW", &ad, &text );
6184 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
6185 "warning, unable to get \"olcRootPW\" "
6186 "attribute description: %d: %s\n",
6189 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
6190 ad->ad_type->sat_oid );
6193 /* set up the notable AttributeDescriptions */
6195 for (;ct->name;ct++) {
6196 if (strcmp(ct->name, ads[i].name)) continue;
6197 *ads[i].desc = ct->ad;
6199 if (!ads[i].name) break;