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, &global_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);
2249 if (SLAP_DBHIDDEN( c->be ))
2252 tbe = select_backend(&ndn, 0);
2254 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
2260 BackendDB *b2 = tbe;
2262 /* Does tbe precede be? */
2263 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
2266 char *type = tbe->bd_info->bi_type;
2268 if ( overlay_is_over( tbe ) ) {
2269 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
2270 type = oi->oi_orig->bi_type;
2273 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> namingContext \"%s\" "
2274 "already served by a preceding %s database",
2275 c->argv[0], pdn.bv_val, type );
2276 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
2277 c->log, c->cr_msg, tbe->be_suffix[0].bv_val);
2283 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
2284 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
2285 "base provided \"%s\" (assuming okay)\n",
2286 c->log, default_search_base.bv_val, 0);
2288 ber_bvarray_add(&c->be->be_suffix, &pdn);
2289 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
2294 config_rootdn(ConfigArgs *c) {
2295 if (c->op == SLAP_CONFIG_EMIT) {
2296 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2297 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
2298 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
2303 } else if ( c->op == LDAP_MOD_DELETE ) {
2304 ch_free( c->be->be_rootdn.bv_val );
2305 ch_free( c->be->be_rootndn.bv_val );
2306 BER_BVZERO( &c->be->be_rootdn );
2307 BER_BVZERO( &c->be->be_rootndn );
2310 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2311 ch_free( c->be->be_rootdn.bv_val );
2312 ch_free( c->be->be_rootndn.bv_val );
2314 c->be->be_rootdn = c->value_dn;
2315 c->be->be_rootndn = c->value_ndn;
2320 config_rootpw(ConfigArgs *c) {
2323 if (c->op == SLAP_CONFIG_EMIT) {
2324 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
2325 /* don't copy, because "rootpw" is marked
2327 c->value_bv = c->be->be_rootpw;
2331 } else if ( c->op == LDAP_MOD_DELETE ) {
2332 ch_free( c->be->be_rootpw.bv_val );
2333 BER_BVZERO( &c->be->be_rootpw );
2337 tbe = select_backend(&c->be->be_rootndn, 0);
2339 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> can only be set when rootdn is under suffix",
2341 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2342 c->log, c->cr_msg, 0);
2345 if ( !BER_BVISNULL( &c->be->be_rootpw ))
2346 ch_free( c->be->be_rootpw.bv_val );
2347 c->be->be_rootpw = c->value_bv;
2352 config_restrict(ConfigArgs *c) {
2353 slap_mask_t restrictops = 0;
2355 slap_verbmasks restrictable_ops[] = {
2356 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
2357 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
2358 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
2359 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
2360 { BER_BVC("modrdn"), 0 },
2361 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
2362 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
2363 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
2364 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
2365 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
2366 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
2367 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
2368 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
2369 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
2370 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
2371 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
2375 if (c->op == SLAP_CONFIG_EMIT) {
2376 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
2378 } else if ( c->op == LDAP_MOD_DELETE ) {
2380 c->be->be_restrictops = 0;
2382 restrictops = verb_to_mask( c->line, restrictable_ops );
2383 c->be->be_restrictops ^= restrictops;
2387 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
2389 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown operation", c->argv[0] );
2390 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2391 c->log, c->cr_msg, c->argv[i]);
2394 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
2395 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
2396 c->be->be_restrictops |= restrictops;
2401 config_allows(ConfigArgs *c) {
2402 slap_mask_t allows = 0;
2404 slap_verbmasks allowable_ops[] = {
2405 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
2406 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
2407 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
2408 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
2409 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
2412 if (c->op == SLAP_CONFIG_EMIT) {
2413 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
2414 } else if ( c->op == LDAP_MOD_DELETE ) {
2418 allows = verb_to_mask( c->line, allowable_ops );
2419 global_allows ^= allows;
2423 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
2425 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
2426 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2427 c->log, c->cr_msg, c->argv[i]);
2430 global_allows |= allows;
2435 config_disallows(ConfigArgs *c) {
2436 slap_mask_t disallows = 0;
2438 slap_verbmasks disallowable_ops[] = {
2439 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
2440 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
2441 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
2442 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
2445 if (c->op == SLAP_CONFIG_EMIT) {
2446 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
2447 } else if ( c->op == LDAP_MOD_DELETE ) {
2449 global_disallows = 0;
2451 disallows = verb_to_mask( c->line, disallowable_ops );
2452 global_disallows ^= disallows;
2456 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
2458 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
2459 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2460 c->log, c->cr_msg, c->argv[i]);
2463 global_disallows |= disallows;
2468 config_requires(ConfigArgs *c) {
2469 slap_mask_t requires = frontendDB->be_requires;
2470 int i, argc = c->argc;
2471 char **argv = c->argv;
2473 slap_verbmasks requires_ops[] = {
2474 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
2475 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
2476 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
2477 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
2478 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
2481 if (c->op == SLAP_CONFIG_EMIT) {
2482 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
2483 } else if ( c->op == LDAP_MOD_DELETE ) {
2485 c->be->be_requires = 0;
2487 requires = verb_to_mask( c->line, requires_ops );
2488 c->be->be_requires ^= requires;
2492 /* "none" can only be first, to wipe out default/global values */
2493 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
2498 i = verbs_to_mask(argc, argv, requires_ops, &requires);
2500 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
2501 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
2502 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2503 c->log, c->cr_msg, 0);
2505 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
2506 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2507 c->log, c->cr_msg, c->argv[i]);
2511 c->be->be_requires = requires;
2515 static slap_verbmasks *loglevel_ops;
2518 loglevel_init( void )
2520 slap_verbmasks lo[] = {
2521 { BER_BVC("Any"), -1 },
2522 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
2523 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
2524 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
2525 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
2526 { BER_BVC("BER"), LDAP_DEBUG_BER },
2527 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
2528 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
2529 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
2530 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
2531 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
2532 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
2533 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
2534 #if 0 /* no longer used (nor supported) */
2535 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
2536 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
2538 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
2539 { BER_BVC("None"), LDAP_DEBUG_NONE },
2543 return slap_verbmasks_init( &loglevel_ops, lo );
2547 loglevel_destroy( void )
2549 if ( loglevel_ops ) {
2550 (void)slap_verbmasks_destroy( loglevel_ops );
2552 loglevel_ops = NULL;
2555 static slap_mask_t loglevel_ignore[] = { -1, 0 };
2558 slap_loglevel_register( slap_mask_t m, struct berval *s )
2562 if ( loglevel_ops == NULL ) {
2566 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
2569 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
2577 slap_loglevel_get( struct berval *s, int *l )
2582 if ( loglevel_ops == NULL ) {
2586 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
2587 m |= loglevel_ops[ i ].mask;
2590 for ( i = 1; m & i; i <<= 1 )
2597 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
2600 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
2611 str2loglevel( const char *s, int *l )
2615 if ( loglevel_ops == NULL ) {
2619 i = verb_to_mask( s, loglevel_ops );
2621 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
2625 *l = loglevel_ops[ i ].mask;
2631 loglevel2str( int l )
2633 struct berval bv = BER_BVNULL;
2635 loglevel2bv( l, &bv );
2641 loglevel2bv( int l, struct berval *bv )
2643 if ( loglevel_ops == NULL ) {
2649 return enum_to_verb( loglevel_ops, l, bv ) == -1;
2653 loglevel2bvarray( int l, BerVarray *bva )
2655 if ( loglevel_ops == NULL ) {
2659 return mask_to_verbs( loglevel_ops, l, bva );
2663 loglevel_print( FILE *out )
2667 if ( loglevel_ops == NULL ) {
2671 fprintf( out, "Installed log subsystems:\n\n" );
2672 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
2673 fprintf( out, "\t%-30s (%lu)\n",
2674 loglevel_ops[ i ].word.bv_val,
2675 loglevel_ops[ i ].mask );
2678 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
2679 "by specific code\n\n" );
2684 static int config_syslog;
2687 config_loglevel(ConfigArgs *c) {
2690 if ( loglevel_ops == NULL ) {
2694 if (c->op == SLAP_CONFIG_EMIT) {
2695 /* Get default or commandline slapd setting */
2696 if ( ldap_syslog && !config_syslog )
2697 config_syslog = ldap_syslog;
2698 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
2700 } else if ( c->op == LDAP_MOD_DELETE ) {
2704 int level = verb_to_mask( c->line, loglevel_ops );
2705 config_syslog ^= level;
2707 if ( slapMode & SLAP_SERVER_MODE ) {
2708 ldap_syslog = config_syslog;
2713 for( i=1; i < c->argc; i++ ) {
2716 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
2717 if( lutil_atoi( &level, c->argv[i] ) != 0 ) {
2718 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse level", c->argv[0] );
2719 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2720 c->log, c->cr_msg, c->argv[i]);
2724 if ( str2loglevel( c->argv[i], &level ) ) {
2725 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown level", c->argv[0] );
2726 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2727 c->log, c->cr_msg, c->argv[i]);
2731 /* Explicitly setting a zero clears all the levels */
2733 config_syslog |= level;
2737 if ( slapMode & SLAP_SERVER_MODE ) {
2738 ldap_syslog = config_syslog;
2744 config_referral(ConfigArgs *c) {
2746 if (c->op == SLAP_CONFIG_EMIT) {
2747 if ( default_referral ) {
2748 value_add( &c->rvalue_vals, default_referral );
2753 } else if ( c->op == LDAP_MOD_DELETE ) {
2754 if ( c->valx < 0 ) {
2755 ber_bvarray_free( default_referral );
2756 default_referral = NULL;
2759 ch_free( default_referral[i].bv_val );
2760 for (; default_referral[i].bv_val; i++ )
2761 default_referral[i] = default_referral[i+1];
2765 if(validate_global_referral(c->argv[1])) {
2766 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
2767 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2768 c->log, c->cr_msg, c->argv[1]);
2772 ber_str2bv(c->argv[1], 0, 0, &val);
2773 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
2781 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
2782 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
2783 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
2784 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
2785 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
2786 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
2787 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
2788 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
2789 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
2794 config_security(ConfigArgs *c) {
2795 slap_ssf_set_t *set = &c->be->be_ssf_set;
2798 if (c->op == SLAP_CONFIG_EMIT) {
2804 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
2805 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
2808 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
2809 if ( bv.bv_len >= sizeof( numbuf ) ) {
2810 ber_bvarray_free_x( c->rvalue_vals, NULL );
2811 c->rvalue_vals = NULL;
2815 bv.bv_len += sec_keys[i].key.bv_len;
2816 bv.bv_val = ch_malloc( bv.bv_len + 1);
2817 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
2818 strcpy( next, numbuf );
2819 ber_bvarray_add( &c->rvalue_vals, &bv );
2824 for(i = 1; i < c->argc; i++) {
2825 slap_ssf_t *tgt = NULL;
2827 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
2828 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
2829 sec_keys[j].key.bv_len)) {
2830 src = c->argv[i] + sec_keys[j].key.bv_len;
2831 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
2836 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown factor", c->argv[0] );
2837 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2838 c->log, c->cr_msg, c->argv[i]);
2842 if ( lutil_atou( tgt, src ) != 0 ) {
2843 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse factor", c->argv[0] );
2844 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2845 c->log, c->cr_msg, c->argv[i]);
2853 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
2857 for (; !BER_BVISNULL( &an->an_name ); an++) {
2858 /* if buflen == 0, assume the buffer size has been
2859 * already checked otherwise */
2860 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
2861 if ( comma ) *ptr++ = ',';
2862 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
2869 config_updatedn(ConfigArgs *c) {
2870 if (c->op == SLAP_CONFIG_EMIT) {
2871 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
2872 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
2873 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
2877 } else if ( c->op == LDAP_MOD_DELETE ) {
2878 ch_free( c->be->be_update_ndn.bv_val );
2879 BER_BVZERO( &c->be->be_update_ndn );
2880 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
2883 if(SLAP_SHADOW(c->be)) {
2884 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database already shadowed", c->argv[0] );
2885 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2886 c->log, c->cr_msg, 0);
2890 ber_memfree_x( c->value_dn.bv_val, NULL );
2891 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
2892 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
2894 c->be->be_update_ndn = c->value_ndn;
2895 BER_BVZERO( &c->value_dn );
2896 BER_BVZERO( &c->value_ndn );
2898 return config_slurp_shadow( c );
2902 config_shadow( ConfigArgs *c, int flag )
2904 char *notallowed = NULL;
2906 if ( c->be == frontendDB ) {
2907 notallowed = "frontend";
2909 } else if ( SLAP_MONITOR(c->be) ) {
2910 notallowed = "monitor";
2913 if ( notallowed != NULL ) {
2914 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
2918 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SINGLE_SHADOW | flag);
2924 config_updateref(ConfigArgs *c) {
2926 if (c->op == SLAP_CONFIG_EMIT) {
2927 if ( c->be->be_update_refs ) {
2928 value_add( &c->rvalue_vals, c->be->be_update_refs );
2933 } else if ( c->op == LDAP_MOD_DELETE ) {
2934 if ( c->valx < 0 ) {
2935 ber_bvarray_free( c->be->be_update_refs );
2936 c->be->be_update_refs = NULL;
2939 ch_free( c->be->be_update_refs[i].bv_val );
2940 for (; c->be->be_update_refs[i].bv_val; i++)
2941 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
2945 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
2946 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must appear after syncrepl or updatedn",
2948 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2949 c->log, c->cr_msg, 0);
2953 if(validate_global_referral(c->argv[1])) {
2954 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
2955 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2956 c->log, c->cr_msg, c->argv[1]);
2959 ber_str2bv(c->argv[1], 0, 0, &val);
2960 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
2965 config_obsolete(ConfigArgs *c) {
2966 if (c->op == SLAP_CONFIG_EMIT)
2969 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> keyword is obsolete (ignored)",
2971 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0);
2976 config_include(ConfigArgs *c) {
2977 int savelineno = c->lineno;
2980 ConfigFile *cfsave = cfn;
2981 ConfigFile *cf2 = NULL;
2983 /* Leftover from RE23. No dynamic config for include files */
2984 if ( c->op == SLAP_CONFIG_EMIT || c->op == LDAP_MOD_DELETE )
2987 cf = ch_calloc( 1, sizeof(ConfigFile));
2988 if ( cfn->c_kids ) {
2989 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
2995 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
2996 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
2997 c->lineno = savelineno - 1;
3000 if ( cf2 ) cf2->c_sibs = NULL;
3001 else cfn->c_kids = NULL;
3002 ch_free( cf->c_file.bv_val );
3012 config_tls_option(ConfigArgs *c) {
3014 LDAP *ld = slap_tls_ld;
3016 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
3017 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
3018 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
3019 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
3020 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
3021 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
3022 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
3024 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
3026 default: Debug(LDAP_DEBUG_ANY, "%s: "
3027 "unknown tls_option <0x%x>\n",
3028 c->log, c->type, 0);
3031 if (c->op == SLAP_CONFIG_EMIT) {
3032 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
3033 } else if ( c->op == LDAP_MOD_DELETE ) {
3034 return ldap_pvt_tls_set_option( ld, flag, NULL );
3036 ch_free(c->value_string);
3037 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
3040 /* FIXME: this ought to be provided by libldap */
3042 config_tls_config(ConfigArgs *c) {
3045 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
3046 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
3048 Debug(LDAP_DEBUG_ANY, "%s: "
3049 "unknown tls_option <0x%x>\n",
3050 c->log, c->type, 0);
3053 if (c->op == SLAP_CONFIG_EMIT) {
3054 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
3055 } else if ( c->op == LDAP_MOD_DELETE ) {
3057 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
3059 ch_free( c->value_string );
3060 if ( isdigit( (unsigned char)c->argv[1][0] ) ) {
3061 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
3062 Debug(LDAP_DEBUG_ANY, "%s: "
3063 "unable to parse %s \"%s\"\n",
3064 c->log, c->argv[0], c->argv[1] );
3067 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
3069 return(ldap_int_tls_config(slap_tls_ld, flag, c->argv[1]));
3074 static CfEntryInfo *
3075 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
3085 if ( dn_match( &root->ce_entry->e_nname, dn ))
3088 c = dn->bv_val+dn->bv_len;
3089 for (;*c != ',';c--);
3093 for (--c;c>dn->bv_val && *c != ',';c--);
3097 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
3099 root = root->ce_kids;
3101 for (;root;root=root->ce_sibs) {
3102 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
3103 if ( cdn.bv_val == dn->bv_val ) {
3113 typedef struct setup_cookie {
3123 config_ldif_resp( Operation *op, SlapReply *rs )
3125 if ( rs->sr_type == REP_SEARCH ) {
3126 setup_cookie *sc = op->o_callback->sc_private;
3128 sc->cfb->cb_got_ldif = 1;
3129 /* Does the frontend exist? */
3130 if ( !sc->got_frontend ) {
3131 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
3132 "olcDatabase", STRLENOF( "olcDatabase" ))) {
3133 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3134 STRLENOF( "olcDatabase" ), "={-1}frontend",
3135 STRLENOF( "={-1}frontend" ))) {
3138 sc->ca->be = frontendDB;
3139 sc->ca->bi = frontendDB->bd_info;
3140 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
3141 rdn.bv_val = sc->ca->log;
3142 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3143 "%s=" SLAP_X_ORDERED_FMT "%s",
3144 cfAd_database->ad_cname.bv_val, -1,
3145 sc->ca->bi->bi_type);
3147 sc->frontend = config_build_entry( op, rs,
3148 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
3149 sc->ca->be->be_cf_ocs );
3158 /* Does the configDB exist? */
3159 if ( sc->got_frontend && !sc->got_config &&
3160 !strncmp( rs->sr_entry->e_nname.bv_val,
3161 "olcDatabase", STRLENOF( "olcDatabase" ))) {
3162 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3163 STRLENOF( "olcDatabase" ), "={0}config",
3164 STRLENOF( "={0}config" ))) {
3167 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
3168 sc->ca->bi = sc->ca->be->bd_info;
3169 rdn.bv_val = sc->ca->log;
3170 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3171 "%s=" SLAP_X_ORDERED_FMT "%s",
3172 cfAd_database->ad_cname.bv_val, 0,
3173 sc->ca->bi->bi_type);
3175 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
3176 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
3183 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
3184 if ( rs->sr_err != LDAP_SUCCESS ) {
3185 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
3186 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg, 0 );
3192 /* Configure and read the underlying back-ldif store */
3194 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
3195 CfBackInfo *cfb = be->be_private;
3201 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
3202 Connection conn = {0};
3203 OperationBuffer opbuf;
3205 SlapReply rs = {REP_RESULT};
3206 Filter filter = { LDAP_FILTER_PRESENT };
3207 struct berval filterstr = BER_BVC("(objectclass=*)");
3210 /* Is the config directory available? */
3211 if ( stat( dir, &st ) < 0 ) {
3212 /* No, so don't bother using the backing store.
3213 * All changes will be in-memory only.
3218 cfb->cb_db.bd_info = backend_info( "ldif" );
3219 if ( !cfb->cb_db.bd_info )
3220 return 0; /* FIXME: eventually this will be a fatal error */
3222 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
3225 cfb->cb_db.be_suffix = be->be_suffix;
3226 cfb->cb_db.be_nsuffix = be->be_nsuffix;
3228 /* The suffix is always "cn=config". The underlying DB's rootdn
3229 * is always the same as the suffix.
3231 cfb->cb_db.be_rootdn = be->be_suffix[0];
3232 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
3234 ber_str2bv( dir, 0, 1, &cfdir );
3239 argv[0] = "directory";
3240 argv[1] = (char *)dir;
3245 c.table = Cft_Database;
3247 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
3251 if ( config_add_vals( ct, &c ))
3254 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
3258 void *thrctx = ldap_pvt_thread_pool_context();
3261 connection_fake_init( &conn, &opbuf, thrctx );
3264 filter.f_desc = slap_schema.si_ad_objectClass;
3266 op->o_tag = LDAP_REQ_SEARCH;
3268 op->ors_filter = &filter;
3269 op->ors_filterstr = filterstr;
3270 op->ors_scope = LDAP_SCOPE_SUBTREE;
3272 op->o_dn = c.be->be_rootdn;
3273 op->o_ndn = c.be->be_rootndn;
3275 op->o_req_dn = be->be_suffix[0];
3276 op->o_req_ndn = be->be_nsuffix[0];
3278 op->ors_tlimit = SLAP_NO_LIMIT;
3279 op->ors_slimit = SLAP_NO_LIMIT;
3281 op->ors_attrs = slap_anlist_all_attributes;
3282 op->ors_attrsonly = 0;
3284 op->o_callback = &cb;
3287 cb.sc_private = ≻
3288 sc.got_frontend = 0;
3293 op->o_bd = &cfb->cb_db;
3295 /* Allow unknown attrs in DNs */
3296 prev_DN_strict = slap_DN_strict;
3299 rc = op->o_bd->be_search( op, &rs );
3301 /* Restore normal DN validation */
3302 slap_DN_strict = prev_DN_strict;
3304 op->o_tag = LDAP_REQ_ADD;
3305 if ( rc == LDAP_SUCCESS && sc.frontend ) {
3306 op->ora_e = sc.frontend;
3307 rc = op->o_bd->be_add( op, &rs );
3309 if ( rc == LDAP_SUCCESS && sc.config ) {
3310 op->ora_e = sc.config;
3311 rc = op->o_bd->be_add( op, &rs );
3313 ldap_pvt_thread_pool_context_reset( thrctx );
3316 /* ITS#4194 - only use if it's present, or we're converting. */
3317 if ( !readit || rc == LDAP_SUCCESS )
3318 cfb->cb_use_ldif = 1;
3324 CfOc_cmp( const void *c1, const void *c2 ) {
3325 const ConfigOCs *co1 = c1;
3326 const ConfigOCs *co2 = c2;
3328 return ber_bvcmp( co1->co_name, co2->co_name );
3332 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
3335 i = init_config_attrs( ct );
3338 /* set up the objectclasses */
3339 i = init_config_ocs( ocs );
3342 for (i=0; ocs[i].co_def; i++) {
3343 if ( ocs[i].co_oc ) {
3344 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
3345 if ( !ocs[i].co_table )
3346 ocs[i].co_table = ct;
3347 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
3354 read_config(const char *fname, const char *dir) {
3357 const char *cfdir, *cfname;
3360 /* Setup the config backend */
3361 be = backend_db_init( "config", NULL, 0, NULL );
3365 cfb = be->be_private;
3366 be->be_dfltaccess = ACL_NONE;
3368 /* If no .conf, or a dir was specified, setup the dir */
3369 if ( !fname || dir ) {
3371 /* If explicitly given, check for existence */
3374 if ( stat( dir, &st ) < 0 ) {
3375 Debug( LDAP_DEBUG_ANY,
3376 "invalid config directory %s, error %d\n",
3382 cfdir = SLAPD_DEFAULT_CONFIGDIR;
3384 /* if fname is defaulted, try reading .d */
3385 rc = config_setup_ldif( be, cfdir, !fname );
3388 /* It may be OK if the base object doesn't exist yet. */
3389 if ( rc != LDAP_NO_SUCH_OBJECT )
3391 /* ITS#4194: But if dir was specified and no fname,
3392 * then we were supposed to read the dir. Unless we're
3393 * trying to slapadd the dir...
3395 if ( dir && !fname ) {
3396 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
3398 /* Assume it's slapadd with a config dir, let it continue */
3400 cfb->cb_got_ldif = 1;
3401 cfb->cb_use_ldif = 1;
3406 /* If we read the config from back-ldif, nothing to do here */
3407 if ( cfb->cb_got_ldif ) {
3416 cfname = SLAPD_DEFAULT_CONFIGFILE;
3418 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
3421 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
3424 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
3425 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
3426 &frontendDB->be_schemadn );
3427 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
3428 if ( rc != LDAP_SUCCESS ) {
3429 Debug(LDAP_DEBUG_ANY, "read_config: "
3430 "unable to normalize default schema DN \"%s\"\n",
3431 frontendDB->be_schemadn.bv_val, 0, 0 );
3432 /* must not happen */
3440 config_back_bind( Operation *op, SlapReply *rs )
3442 if ( be_isroot_pw( op ) ) {
3443 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
3444 /* frontend sends result */
3445 return LDAP_SUCCESS;
3448 rs->sr_err = LDAP_INVALID_CREDENTIALS;
3449 send_ldap_result( op, rs );
3455 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
3459 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
3461 rs->sr_attrs = op->ors_attrs;
3462 rs->sr_entry = ce->ce_entry;
3464 rc = send_search_entry( op, rs );
3466 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
3467 if ( ce->ce_kids ) {
3468 rc = config_send( op, rs, ce->ce_kids, 1 );
3469 if ( rc ) return rc;
3472 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
3473 rc = config_send( op, rs, ce, 0 );
3481 static ConfigTable *
3482 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
3487 for (j=0; j<nocs; j++) {
3488 for (i=0; colst[j]->co_table[i].name; i++)
3489 if ( colst[j]->co_table[i].ad == ad ) {
3490 ca->table = colst[j]->co_type;
3491 return &colst[j]->co_table[i];
3497 /* Sort the attributes of the entry according to the order defined
3498 * in the objectclass, with required attributes occurring before
3499 * allowed attributes. For any attributes with sequencing dependencies
3500 * (e.g., rootDN must be defined after suffix) the objectclass must
3501 * list the attributes in the desired sequence.
3504 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
3506 Attribute *a, *head = NULL, *tail = NULL, **prev;
3509 for (i=0; i<nocs; i++) {
3510 if ( colst[i]->co_oc->soc_required ) {
3511 AttributeType **at = colst[i]->co_oc->soc_required;
3512 for (j=0; at[j]; j++) {
3513 for (a=e->e_attrs, prev=&e->e_attrs; a;
3514 prev = &(*prev)->a_next, a=a->a_next) {
3515 if ( a->a_desc == at[j]->sat_ad ) {
3529 if ( colst[i]->co_oc->soc_allowed ) {
3530 AttributeType **at = colst[i]->co_oc->soc_allowed;
3531 for (j=0; at[j]; j++) {
3532 for (a=e->e_attrs, prev=&e->e_attrs; a;
3533 prev = &(*prev)->a_next, a=a->a_next) {
3534 if ( a->a_desc == at[j]->sat_ad ) {
3550 tail->a_next = e->e_attrs;
3556 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
3558 Attribute *a = NULL;
3559 AttributeDescription *ad;
3569 Modifications *ml = ptr;
3571 vals = ml->sml_values;
3574 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
3575 rc = ordered_value_sort( a, 1 );
3577 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
3578 ad->ad_cname.bv_val );
3582 for ( i=0; vals[i].bv_val; i++ ) {
3583 ca->line = vals[i].bv_val;
3584 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
3585 ca->line[0] == '{' ) {
3586 char *idx = strchr( ca->line, '}' );
3587 if ( idx ) ca->line = idx+1;
3589 rc = config_parse_vals( ct, ca, i );
3598 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
3601 struct berval rtype, rval;
3603 AttributeDescription *ad = NULL;
3605 dnRdn( &e->e_name, rdn );
3606 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
3607 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
3608 rtype.bv_val = rdn->bv_val;
3609 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
3612 slap_bv2ad( &rtype, &ad, &rs->sr_text );
3613 a = attr_find( e->e_attrs, ad );
3614 if (!a ) return LDAP_NAMING_VIOLATION;
3621 config_rename_kids( CfEntryInfo *ce )
3624 struct berval rdn, nrdn;
3626 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
3627 dnRdn ( &ce2->ce_entry->e_name, &rdn );
3628 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
3629 free( ce2->ce_entry->e_name.bv_val );
3630 free( ce2->ce_entry->e_nname.bv_val );
3631 build_new_dn( &ce2->ce_entry->e_name, &ce->ce_entry->e_name,
3633 build_new_dn( &ce2->ce_entry->e_nname, &ce->ce_entry->e_nname,
3635 config_rename_kids( ce2 );
3640 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
3641 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
3642 struct berval *nnewrdn, int use_ldif )
3646 struct berval odn, ondn;
3650 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
3651 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
3654 free( a->a_vals[0].bv_val );
3655 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
3656 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
3657 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
3658 strcpy( a->a_vals[0].bv_val, ptr1 );
3660 if ( a->a_nvals != a->a_vals ) {
3661 free( a->a_nvals[0].bv_val );
3662 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
3663 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
3664 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
3665 strcpy( a->a_nvals[0].bv_val, ptr1 );
3668 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
3669 BackendDB *be = op->o_bd;
3670 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
3671 struct berval dn, ndn, xdn, xndn;
3673 op->o_bd = &cfb->cb_db;
3675 /* Save current rootdn; use the underlying DB's rootdn */
3679 xndn = op->o_req_ndn;
3680 op->o_dn = op->o_bd->be_rootdn;
3681 op->o_ndn = op->o_bd->be_rootndn;
3683 op->o_req_ndn = ondn;
3685 scp = op->o_callback;
3686 op->o_callback = ≻
3687 op->orr_newrdn = *newrdn;
3688 op->orr_nnewrdn = *nnewrdn;
3689 op->orr_newSup = NULL;
3690 op->orr_nnewSup = NULL;
3691 op->orr_deleteoldrdn = 1;
3692 op->orr_modlist = NULL;
3693 slap_modrdn2mods( op, rs );
3694 slap_mods_opattrs( op, &op->orr_modlist, 1 );
3695 rc = op->o_bd->be_modrdn( op, rs );
3696 slap_mods_free( op->orr_modlist, 1 );
3699 op->o_callback = scp;
3703 op->o_req_ndn = xndn;
3706 free( ondn.bv_val );
3708 config_rename_kids( e->e_private );
3713 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
3714 Entry *e, int idx, int tailindex, int use_ldif )
3716 struct berval ival, newrdn, nnewrdn;
3719 char ibuf[32], *ptr1, *ptr2 = NULL;
3722 rc = config_rename_attr( rs, e, &rdn, &a );
3723 if ( rc ) return rc;
3726 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
3727 if ( ival.bv_len >= sizeof( ibuf ) ) {
3728 return LDAP_NAMING_VIOLATION;
3731 newrdn.bv_len = rdn.bv_len + ival.bv_len;
3732 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
3735 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
3736 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3739 ptr2 = ber_bvchr( &rdn, '}' );
3743 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
3745 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
3746 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
3747 a->a_desc->ad_cname.bv_len );
3749 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3750 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
3754 /* Do the equivalent of ModRDN */
3755 /* Replace DN / NDN */
3756 newrdn.bv_len = ptr1 - newrdn.bv_val;
3757 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
3758 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
3760 free( nnewrdn.bv_val );
3761 free( newrdn.bv_val );
3766 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
3767 SlapReply *rs, int *renum, int *ibase )
3770 int index = -1, gotindex = 0, nsibs, rc = 0;
3771 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
3772 char *ptr1, *ptr2 = NULL;
3775 if ( renum ) *renum = 0;
3777 /* These entries don't get indexed/renumbered */
3778 if ( ce_type == Cft_Global ) return 0;
3779 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
3781 if ( ce_type == Cft_Module )
3784 /* See if the rdn has an index already */
3785 dnRdn( &e->e_name, &rdn );
3786 if ( ce_type == Cft_Database ) {
3787 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
3788 "frontend", STRLENOF("frontend") ))
3790 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
3791 "config", STRLENOF("config") ))
3794 ptr1 = ber_bvchr( &e->e_name, '{' );
3795 if ( ptr1 && ptr1 - e->e_name.bv_val < rdn.bv_len ) {
3797 ptr2 = strchr( ptr1, '}' );
3798 if (!ptr2 || ptr2 - e->e_name.bv_val > rdn.bv_len)
3799 return LDAP_NAMING_VIOLATION;
3800 if ( ptr2-ptr1 == 1)
3801 return LDAP_NAMING_VIOLATION;
3803 index = strtol( ptr1 + 1, &next, 10 );
3804 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
3805 return LDAP_NAMING_VIOLATION;
3808 /* Special case, we allow -1 for the frontendDB */
3809 if ( index != -1 || !isfrontend )
3810 return LDAP_NAMING_VIOLATION;
3812 if ( isconfig && index != 0 ){
3813 return LDAP_NAMING_VIOLATION;
3817 /* count related kids */
3818 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
3819 if ( ce->ce_type == ce_type ) nsibs++;
3822 /* account for -1 frontend */
3823 if ( ce_type == Cft_Database )
3826 if ( index != nsibs ) {
3828 if ( index < nsibs ) {
3829 if ( tailindex ) return LDAP_NAMING_VIOLATION;
3830 /* Siblings need to be renumbered */
3831 if ( index != -1 || !isfrontend )
3835 /* config DB is always "0" */
3836 if ( isconfig && index == -1 ) {
3839 if ( !isfrontend && index == -1 ) {
3843 /* just make index = nsibs */
3845 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
3848 if ( ibase ) *ibase = index;
3849 if ( renum ) *renum = renumber;
3854 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
3859 co.co_name = &oc->soc_cname;
3860 cop = avl_find( CfOcTree, &co, CfOc_cmp );
3864 /* check for duplicates */
3865 for ( i = 0; i < *nocs; i++ ) {
3866 if ( *copp && (*copp)[i] == cop ) {
3872 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
3873 if ( tmp == NULL ) {
3877 (*copp)[*nocs] = cop;
3882 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
3883 if ( count_oc( *sups, copp, nocs ) ) {
3892 count_ocs( Attribute *oc_at, int *nocs )
3895 ConfigOCs **colst = NULL;
3899 for ( i = 0; !BER_BVISNULL( &oc_at->a_nvals[i] ); i++ )
3903 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
3905 assert( oc != NULL );
3906 if ( count_oc( oc, &colst, nocs ) ) {
3916 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
3918 /* Leftover from RE23. Never parse this entry */
3919 return LDAP_COMPARE_TRUE;
3923 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
3927 /* This entry is hardcoded, don't re-parse it */
3928 if ( p->ce_type == Cft_Global ) {
3929 cfn = p->ce_private;
3931 return LDAP_COMPARE_TRUE;
3933 if ( p->ce_type != Cft_Schema )
3934 return LDAP_CONSTRAINT_VIOLATION;
3936 cfn = ch_calloc( 1, sizeof(ConfigFile) );
3938 cfo = p->ce_private;
3939 cfn->c_sibs = cfo->c_kids;
3941 return LDAP_SUCCESS;
3945 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3947 if ( p->ce_type != Cft_Global ) {
3948 return LDAP_CONSTRAINT_VIOLATION;
3950 ca->be = frontendDB; /* just to get past check_vals */
3951 return LDAP_SUCCESS;
3955 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3957 if ( p->ce_type != Cft_Global ) {
3958 return LDAP_CONSTRAINT_VIOLATION;
3960 return LDAP_SUCCESS;
3964 cfAddModule( 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 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3975 if ( p->ce_type != Cft_Database ) {
3976 return LDAP_CONSTRAINT_VIOLATION;
3979 return LDAP_SUCCESS;
3983 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
3988 AttributeDescription *ad;
3993 if ( cfn->c_cr_head ) {
3994 struct berval bv = BER_BVC("olcDitContentRules");
3996 slap_bv2ad( &bv, &ad, &text );
3997 ct = config_find_table( colst, nocs, ad, ca );
3998 config_del_vals( ct, ca );
4000 if ( cfn->c_oc_head ) {
4001 struct berval bv = BER_BVC("olcObjectClasses");
4003 slap_bv2ad( &bv, &ad, &text );
4004 ct = config_find_table( colst, nocs, ad, ca );
4005 config_del_vals( ct, ca );
4007 if ( cfn->c_at_head ) {
4008 struct berval bv = BER_BVC("olcAttributeTypes");
4010 slap_bv2ad( &bv, &ad, &text );
4011 ct = config_find_table( colst, nocs, ad, ca );
4012 config_del_vals( ct, ca );
4014 if ( cfn->c_om_head ) {
4015 struct berval bv = BER_BVC("olcObjectIdentifier");
4017 slap_bv2ad( &bv, &ad, &text );
4018 ct = config_find_table( colst, nocs, ad, ca );
4019 config_del_vals( ct, ca );
4021 cfo = p->ce_private;
4022 cfo->c_kids = cfn->c_sibs;
4027 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
4029 int rc = LDAP_CONSTRAINT_VIOLATION;
4032 if ( (*cop)->co_ldadd ) {
4033 rc = (*cop)->co_ldadd( last, e, ca );
4034 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4039 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
4040 ConfigOCs co = { 0 };
4042 co.co_name = &(*ocp)->soc_cname;
4043 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
4044 if ( *cop == NULL ) {
4048 rc = config_add_oc( cop, last, e, ca );
4049 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4057 /* Parse an LDAP entry into config directives */
4059 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
4060 int *renum, Operation *op )
4062 CfEntryInfo *ce, *last = NULL;
4063 ConfigOCs co, *coptr, **colst;
4064 Attribute *a, *oc_at, *soc_at;
4065 int i, ibase = -1, nocs, rc = 0;
4068 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
4070 memset( ca, 0, sizeof(ConfigArgs));
4072 /* Make sure parent exists and entry does not. But allow
4073 * Databases and Overlays to be inserted. Don't do any
4074 * auto-renumbering if manageDSAit control is present.
4076 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
4078 if ( ( op && op->o_managedsait ) ||
4079 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
4080 ce->ce_type != Cft_Module ) )
4082 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4083 "DN=\"%s\" already exists\n",
4084 log_prefix, e->e_name.bv_val, 0 );
4085 return LDAP_ALREADY_EXISTS;
4089 dnParent( &e->e_nname, &pdn );
4091 /* If last is NULL, the new entry is the root/suffix entry,
4092 * otherwise last should be the parent.
4094 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
4096 rs->sr_matched = last->ce_entry->e_name.bv_val;
4098 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4099 "DN=\"%s\" not child of DN=\"%s\"\n",
4100 log_prefix, e->e_name.bv_val,
4101 last->ce_entry->e_name.bv_val );
4102 return LDAP_NO_SUCH_OBJECT;
4106 /* No parent, must be root. This will never happen... */
4107 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
4108 return LDAP_NO_SUCH_OBJECT;
4111 if ( last && !access_allowed( op, last->ce_entry,
4112 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
4114 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4115 "DN=\"%s\" no write access to \"children\" of parent\n",
4116 log_prefix, e->e_name.bv_val, 0 );
4117 return LDAP_INSUFFICIENT_ACCESS;
4121 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4123 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4124 "DN=\"%s\" no objectClass\n",
4125 log_prefix, e->e_name.bv_val, 0 );
4126 return LDAP_OBJECT_CLASS_VIOLATION;
4129 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4131 ObjectClass *soc = NULL;
4132 char textbuf[ SLAP_TEXT_BUFLEN ];
4133 const char *text = textbuf;
4135 /* FIXME: check result */
4136 rc = structural_class( oc_at->a_nvals, &soc, NULL,
4137 &text, textbuf, sizeof(textbuf), NULL );
4138 if ( rc != LDAP_SUCCESS ) {
4139 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4140 "DN=\"%s\" no structural objectClass (%s)\n",
4141 log_prefix, e->e_name.bv_val, text );
4144 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
4145 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4146 if ( soc_at == NULL ) {
4147 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4148 "DN=\"%s\" no structural objectClass; "
4149 "unable to merge computed class %s\n",
4150 log_prefix, e->e_name.bv_val,
4151 soc->soc_cname.bv_val );
4152 return LDAP_OBJECT_CLASS_VIOLATION;
4155 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4156 "DN=\"%s\" no structural objectClass; "
4157 "computed objectClass %s merged\n",
4158 log_prefix, e->e_name.bv_val,
4159 soc->soc_cname.bv_val );
4162 /* Fake the coordinates based on whether we're part of an
4163 * LDAP Add or if reading the config dir
4166 ca->fname = "slapd";
4169 ca->fname = cfdir.bv_val;
4174 co.co_name = &soc_at->a_nvals[0];
4175 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
4176 if ( coptr == NULL ) {
4177 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4178 "DN=\"%s\" no structural objectClass in configuration table\n",
4179 log_prefix, e->e_name.bv_val, 0 );
4180 return LDAP_OBJECT_CLASS_VIOLATION;
4183 /* Only the root can be Cft_Global, everything else must
4184 * have a parent. Only limited nesting arrangements are allowed.
4186 rc = LDAP_CONSTRAINT_VIOLATION;
4187 if ( coptr->co_type == Cft_Global && !last ) {
4188 cfn = cfb->cb_config;
4190 ca->be = frontendDB; /* just to get past check_vals */
4194 colst = count_ocs( oc_at, &nocs );
4196 /* Check whether the Add is allowed by its parent, and do
4197 * any necessary arg setup
4200 rc = config_add_oc( &coptr, last, e, ca );
4201 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4202 for ( i = 0; i<nocs; i++ ) {
4203 /* Already checked these */
4204 if ( colst[i]->co_oc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
4206 if ( colst[i]->co_ldadd &&
4207 ( rc = colst[i]->co_ldadd( last, e, ca ))
4208 != LDAP_CONSTRAINT_VIOLATION ) {
4214 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4215 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4216 "DN=\"%s\" no structural objectClass add function\n",
4217 log_prefix, e->e_name.bv_val, 0 );
4218 return LDAP_OBJECT_CLASS_VIOLATION;
4222 /* Add the entry but don't parse it, we already have its contents */
4223 if ( rc == LDAP_COMPARE_TRUE ) {
4228 if ( rc != LDAP_SUCCESS )
4231 /* Parse all the values and check for simple syntax errors before
4232 * performing any set actions.
4234 * If doing an LDAPadd, check for indexed names and any necessary
4235 * renaming/renumbering. Entries that don't need indexed names are
4236 * ignored. Entries that need an indexed name and arrive without one
4237 * are assigned to the end. Entries that arrive with an index may
4238 * cause the following entries to be renumbered/bumped down.
4240 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
4241 * don't allow Adding an entry with an index that's already in use.
4242 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
4244 * These entries can have auto-assigned indexes (appended to the end)
4245 * but only the other types support auto-renumbering of siblings.
4248 rc = check_name_index( last, coptr->co_type, e, rs, renum,
4253 if ( renum && *renum && coptr->co_type != Cft_Database &&
4254 coptr->co_type != Cft_Overlay )
4256 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
4257 "operation requires sibling renumbering" );
4258 rc = LDAP_UNWILLING_TO_PERFORM;
4263 init_config_argv( ca );
4265 /* Make sure we process attrs in the required order */
4266 sort_attrs( e, colst, nocs );
4268 for ( a = e->e_attrs; a; a = a->a_next ) {
4269 if ( a == oc_at ) continue;
4270 ct = config_find_table( colst, nocs, a->a_desc, ca );
4271 if ( !ct ) continue; /* user data? */
4272 rc = check_vals( ct, ca, a, 1 );
4273 if ( rc ) goto done_noop;
4276 /* Basic syntax checks are OK. Do the actual settings. */
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 for (i=0; a->a_vals[i].bv_val; i++) {
4283 ca->line = a->a_vals[i].bv_val;
4284 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
4285 ptr = strchr( ca->line, '}' );
4287 iptr = strchr( ca->line, '{' );
4291 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
4293 ca->valx = strtol( iptr+1, NULL, 0 );
4300 rc = config_parse_add( ct, ca, i );
4308 /* Newly added databases and overlays need to be started up */
4309 if ( CONFIG_ONLINE_ADD( ca )) {
4310 if ( colst[0]->co_type == Cft_Database ) {
4311 rc = backend_startup_one( ca->be, &ca->reply );
4313 } else if ( colst[0]->co_type == Cft_Overlay ) {
4314 if ( ca->bi->bi_db_open ) {
4315 BackendInfo *bi_orig = ca->be->bd_info;
4316 ca->be->bd_info = ca->bi;
4317 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
4318 ca->be->bd_info = bi_orig;
4320 } else if ( ca->cleanup ) {
4321 rc = ca->cleanup( ca );
4324 if (ca->cr_msg[0] == '\0')
4325 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
4327 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
4328 ca->log, ca->cr_msg, ca->argv[1] );
4335 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
4336 ce->ce_parent = last;
4337 ce->ce_entry = entry_dup( e );
4338 ce->ce_entry->e_private = ce;
4339 ce->ce_type = colst[0]->co_type;
4342 ce->ce_private = ca->private;
4343 ca->ca_entry = ce->ce_entry;
4346 } else if ( last->ce_kids ) {
4347 CfEntryInfo *c2, **cprev;
4349 /* Advance to first of this type */
4350 cprev = &last->ce_kids;
4351 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
4352 cprev = &c2->ce_sibs;
4355 /* Account for the (-1) frontendDB entry */
4356 if ( ce->ce_type == Cft_Database ) {
4357 if ( ca->be == frontendDB )
4359 else if ( ibase != -1 )
4364 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
4365 cprev = &c2->ce_sibs;
4371 for ( i=0; i<ibase; i++ ) {
4373 cprev = &c2->ce_sibs;
4376 ce->ce_sibs = *cprev;
4384 if ( (colst[0]->co_type == Cft_Database) && ca->be ) {
4385 if ( ca->be != frontendDB )
4386 backend_destroy_one( ca->be, 1 );
4387 } else if ( (colst[0]->co_type == Cft_Overlay) && ca->bi ) {
4388 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
4389 } else if ( colst[0]->co_type == Cft_Schema ) {
4390 schema_destroy_one( ca, colst, nocs, last );
4395 ch_free( ca->argv );
4396 if ( colst ) ch_free( colst );
4400 #define BIGTMP 10000
4402 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
4403 int base, int rebase, int max, int use_ldif )
4405 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
4406 ConfigType etype = ce->ce_type;
4407 int count = 0, rc = 0;
4409 /* Reverse ce list */
4410 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
4411 if (ce2->ce_type != etype) {
4416 ce2->ce_sibs = cetmp;
4419 if ( max && count >= max ) {
4425 /* Move original to a temp name until increments are done */
4427 ce->ce_entry->e_private = NULL;
4428 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4429 base+BIGTMP, 0, use_ldif );
4430 ce->ce_entry->e_private = ce;
4432 /* start incrementing */
4433 for (ce2=cetmp; ce2; ce2=ce3) {
4435 ce2->ce_sibs = cerem;
4438 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
4439 count+base, 0, use_ldif );
4443 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4444 base, 0, use_ldif );
4449 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
4450 CfEntryInfo *ce2, int old, int use_ldif )
4454 /* Renumber original to a temp value */
4455 ce->ce_entry->e_private = NULL;
4456 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4457 old+BIGTMP, 0, use_ldif );
4458 ce->ce_entry->e_private = ce;
4460 /* start decrementing */
4461 for (; ce2 != ce; ce2=ce2->ce_sibs) {
4462 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
4463 count+old, 0, use_ldif );
4466 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4467 count+old, 0, use_ldif );
4470 /* Parse an LDAP entry into config directives, then store in underlying
4474 config_back_add( Operation *op, SlapReply *rs )
4480 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
4481 NULL, ACL_WADD, NULL )) {
4482 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4486 cfb = (CfBackInfo *)op->o_bd->be_private;
4488 /* add opattrs for syncprov */
4490 char textbuf[SLAP_TEXT_BUFLEN];
4491 size_t textlen = sizeof textbuf;
4492 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1,
4493 &rs->sr_text, textbuf, sizeof( textbuf ) );
4494 if ( rs->sr_err != LDAP_SUCCESS )
4496 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
4497 if ( rs->sr_err != LDAP_SUCCESS ) {
4498 Debug( LDAP_DEBUG_TRACE,
4499 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
4500 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
4505 ldap_pvt_thread_pool_pause( &connection_pool );
4508 * 1) check for existence of entry
4509 * 2) check for sibling renumbering
4510 * 3) perform internal add
4511 * 4) perform any necessary renumbering
4512 * 5) store entry in underlying database
4514 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
4515 if ( rs->sr_err != LDAP_SUCCESS ) {
4516 rs->sr_text = ca.cr_msg;
4521 CfEntryInfo *ce = ca.ca_entry->e_private;
4522 req_add_s addr = op->oq_add;
4523 op->o_tag = LDAP_REQ_MODRDN;
4524 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
4525 op->o_tag = LDAP_REQ_ADD;
4527 if ( rs->sr_err != LDAP_SUCCESS ) {
4532 if ( cfb->cb_use_ldif ) {
4533 BackendDB *be = op->o_bd;
4534 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4535 struct berval dn, ndn;
4537 op->o_bd = &cfb->cb_db;
4539 /* Save current rootdn; use the underlying DB's rootdn */
4542 op->o_dn = op->o_bd->be_rootdn;
4543 op->o_ndn = op->o_bd->be_rootndn;
4545 scp = op->o_callback;
4546 op->o_callback = ≻
4547 op->o_bd->be_add( op, rs );
4549 op->o_callback = scp;
4555 ldap_pvt_thread_pool_resume( &connection_pool );
4558 send_ldap_result( op, rs );
4559 slap_graduate_commit_csn( op );
4563 typedef struct delrec {
4564 struct delrec *next;
4570 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
4575 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
4576 ca->line[0] == '{' )
4578 char *ptr = strchr( ca->line + 1, '}' );
4582 ca->valx = strtol( ca->line + 1, &next, 0 );
4583 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
4589 rc = config_parse_add( ct, ca, i );
4597 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
4600 int rc = LDAP_UNWILLING_TO_PERFORM;
4602 Entry *e = ce->ce_entry;
4603 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
4608 delrec *dels = NULL, *deltail = NULL;
4610 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4611 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
4613 colst = count_ocs( oc_at, &nocs );
4615 /* make sure add/del flags are clear; should always be true */
4616 for ( s = save_attrs; s; s = s->a_next ) {
4617 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
4620 e->e_attrs = attrs_dup( e->e_attrs );
4622 init_config_argv( ca );
4625 ca->private = ce->ce_private;
4627 ca->fname = "slapd";
4629 strcpy( ca->log, "back-config" );
4631 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
4632 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
4633 switch (ml->sml_op) {
4634 case LDAP_MOD_DELETE:
4635 case LDAP_MOD_REPLACE: {
4636 BerVarray vals = NULL, nvals = NULL;
4638 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
4640 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
4641 ml->sml_desc->ad_cname.bv_val );
4644 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4645 vals = ml->sml_values;
4646 nvals = ml->sml_nvalues;
4647 ml->sml_values = NULL;
4648 ml->sml_nvalues = NULL;
4650 /* If we're deleting by values, remember the indexes of the
4651 * values we deleted.
4653 if ( ct && ml->sml_values ) {
4655 i = ml->sml_numvals;
4656 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
4667 rc = modify_delete_vindex(e, &ml->sml_mod,
4668 get_permissiveModify(op),
4669 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
4670 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4671 ml->sml_values = vals;
4672 ml->sml_nvalues = nvals;
4677 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
4680 case SLAP_MOD_SOFTADD: {
4681 int mop = ml->sml_op;
4683 ml->sml_op = LDAP_MOD_ADD;
4685 if ( ct->arg_type & ARG_NO_INSERT ) {
4686 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
4688 navals = a->a_numvals;
4691 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
4692 if ( ml->sml_values[i].bv_val[0] == '{' &&
4695 char *next, *val = ml->sml_values[i].bv_val + 1;
4698 j = strtol( val, &next, 0 );
4699 if ( next == val || next[ 0 ] != '}' || j < navals ) {
4701 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
4702 ml->sml_desc->ad_cname.bv_val );
4706 rc = check_vals( ct, ca, ml, 0 );
4707 if ( rc ) goto out_noop;
4710 rc = modify_add_values(e, &ml->sml_mod,
4711 get_permissiveModify(op),
4712 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
4714 /* If value already exists, show success here
4715 * and ignore this operation down below.
4717 if ( mop == SLAP_MOD_SOFTADD ) {
4718 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
4728 case LDAP_MOD_INCREMENT: /* FIXME */
4733 if(rc != LDAP_SUCCESS) break;
4736 if ( rc == LDAP_SUCCESS) {
4737 /* check that the entry still obeys the schema */
4738 rc = entry_schema_check(op, e, NULL, 0, 0,
4739 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
4740 if ( rc ) goto out_noop;
4742 /* Basic syntax checks are OK. Do the actual settings. */
4743 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
4744 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
4745 if ( !ct ) continue;
4747 s = attr_find( save_attrs, ml->sml_desc );
4748 a = attr_find( e->e_attrs, ml->sml_desc );
4750 switch (ml->sml_op) {
4751 case LDAP_MOD_DELETE:
4752 case LDAP_MOD_REPLACE: {
4753 BerVarray vals = NULL, nvals = NULL;
4756 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4757 vals = ml->sml_values;
4758 nvals = ml->sml_nvalues;
4759 ml->sml_values = NULL;
4760 ml->sml_nvalues = NULL;
4763 if ( ml->sml_values )
4766 /* If we didn't delete the whole attribute */
4767 if ( ml->sml_values && a ) {
4768 struct berval *mvals;
4771 if ( ml->sml_nvalues )
4772 mvals = ml->sml_nvalues;
4774 mvals = ml->sml_values;
4776 /* use the indexes we saved up above */
4777 for (i=0; i < d->nidx; i++) {
4778 struct berval bv = *mvals++;
4779 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
4780 bv.bv_val[0] == '{' ) {
4781 ptr = strchr( bv.bv_val, '}' ) + 1;
4782 bv.bv_len -= ptr - bv.bv_val;
4785 ca->line = bv.bv_val;
4786 ca->valx = d->idx[i];
4787 rc = config_del_vals( ct, ca );
4788 if ( rc != LDAP_SUCCESS ) break;
4790 s->a_flags |= SLAP_ATTR_IXDEL;
4791 for (j=i+1; j < d->nidx; j++)
4792 if ( d->idx[j] >d->idx[i] )
4798 rc = config_del_vals( ct, ca );
4799 if ( rc ) rc = LDAP_OTHER;
4801 s->a_flags |= SLAP_ATTR_IXDEL;
4803 if ( ml->sml_values ) {
4808 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4809 ml->sml_values = vals;
4810 ml->sml_nvalues = nvals;
4812 if ( !vals || rc != LDAP_SUCCESS )
4815 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
4818 for (i=0; ml->sml_values[i].bv_val; i++) {
4819 ca->line = ml->sml_values[i].bv_val;
4821 rc = config_modify_add( ct, ca, ml->sml_desc, i );
4824 a->a_flags |= SLAP_ATTR_IXADD;
4831 /* Undo for a failed operation */
4832 if ( rc != LDAP_SUCCESS ) {
4833 ConfigReply msg = ca->reply;
4834 for ( s = save_attrs; s; s = s->a_next ) {
4835 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
4836 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
4837 ct = config_find_table( colst, nocs, s->a_desc, ca );
4838 a = attr_find( e->e_attrs, s->a_desc );
4840 /* clear the flag so the add check below will skip it */
4841 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
4844 config_del_vals( ct, ca );
4846 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
4847 ca->line = s->a_vals[i].bv_val;
4849 config_modify_add( ct, ca, s->a_desc, i );
4853 for ( a = e->e_attrs; a; a = a->a_next ) {
4854 if ( a->a_flags & SLAP_ATTR_IXADD ) {
4855 ct = config_find_table( colst, nocs, a->a_desc, ca );
4858 config_del_vals( ct, ca );
4859 s = attr_find( save_attrs, a->a_desc );
4861 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
4862 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
4863 ca->line = s->a_vals[i].bv_val;
4865 config_modify_add( ct, ca, s->a_desc, i );
4876 if ( rc == LDAP_SUCCESS ) {
4877 attrs_free( save_attrs );
4879 attrs_free( e->e_attrs );
4880 e->e_attrs = save_attrs;
4882 ch_free( ca->argv );
4883 if ( colst ) ch_free( colst );
4885 deltail = dels->next;
4894 config_back_modify( Operation *op, SlapReply *rs )
4897 CfEntryInfo *ce, *last;
4899 ConfigArgs ca = {0};
4902 AttributeDescription *rad = NULL;
4904 cfb = (CfBackInfo *)op->o_bd->be_private;
4906 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
4909 rs->sr_matched = last->ce_entry->e_name.bv_val;
4910 rs->sr_err = LDAP_NO_SUCH_OBJECT;
4914 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
4915 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4919 /* Get type of RDN */
4920 rdn = ce->ce_entry->e_nname;
4921 ptr = strchr( rdn.bv_val, '=' );
4922 rdn.bv_len = ptr - rdn.bv_val;
4923 slap_bv2ad( &rdn, &rad, &rs->sr_text );
4925 /* Some basic validation... */
4926 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
4927 /* Don't allow Modify of RDN; must use ModRdn for that. */
4928 if ( ml->sml_desc == rad ) {
4929 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
4930 rs->sr_text = "Use modrdn to change the entry name";
4935 slap_mods_opattrs( op, &op->orm_modlist, 1 );
4937 ldap_pvt_thread_pool_pause( &connection_pool );
4940 * 1) perform the Modify on the cached Entry.
4941 * 2) verify that the Entry still satisfies the schema.
4942 * 3) perform the individual config operations.
4943 * 4) store Modified entry in underlying LDIF backend.
4945 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
4947 rs->sr_text = ca.cr_msg;
4948 } else if ( cfb->cb_use_ldif ) {
4949 BackendDB *be = op->o_bd;
4950 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4951 struct berval dn, ndn;
4953 op->o_bd = &cfb->cb_db;
4957 op->o_dn = op->o_bd->be_rootdn;
4958 op->o_ndn = op->o_bd->be_rootndn;
4960 scp = op->o_callback;
4961 op->o_callback = ≻
4962 op->o_bd->be_modify( op, rs );
4964 op->o_callback = scp;
4969 ldap_pvt_thread_pool_resume( &connection_pool );
4971 send_ldap_result( op, rs );
4972 slap_graduate_commit_csn( op );
4977 config_back_modrdn( Operation *op, SlapReply *rs )
4980 CfEntryInfo *ce, *last;
4984 cfb = (CfBackInfo *)op->o_bd->be_private;
4986 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
4989 rs->sr_matched = last->ce_entry->e_name.bv_val;
4990 rs->sr_err = LDAP_NO_SUCH_OBJECT;
4993 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
4994 NULL, ACL_WRITE, NULL )) {
4995 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4999 if ( ce->ce_parent )
5000 parent = ce->ce_parent->ce_entry;
5002 parent = (Entry *)&slap_entry_root;
5003 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
5004 NULL, ACL_WRITE, NULL )) {
5005 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5010 /* We don't allow moving objects to new parents.
5011 * Generally we only allow reordering a set of ordered entries.
5013 if ( op->orr_newSup ) {
5014 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5018 /* If newRDN == oldRDN, quietly succeed */
5019 dnRdn( &op->o_req_ndn, &rdn );
5020 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
5021 rs->sr_err = LDAP_SUCCESS;
5025 /* Current behavior, subject to change as needed:
5027 * For backends and overlays, we only allow renumbering.
5028 * For schema, we allow renaming with the same number.
5029 * Otherwise, the op is not allowed.
5032 if ( ce->ce_type == Cft_Schema ) {
5036 /* Can't alter the main cn=schema entry */
5037 if ( ce->ce_parent->ce_type == Cft_Global ) {
5038 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5039 rs->sr_text = "renaming not allowed for this entry";
5043 /* We could support this later if desired */
5044 ptr1 = ber_bvchr( &rdn, '}' );
5045 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5046 len = ptr1 - rdn.bv_val;
5047 if ( len != ptr2 - op->orr_newrdn.bv_val ||
5048 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
5049 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5050 rs->sr_text = "schema reordering not supported";
5053 } else if ( ce->ce_type == Cft_Database ||
5054 ce->ce_type == Cft_Overlay ) {
5055 char *ptr1, *ptr2, *iptr1, *iptr2;
5058 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
5059 if ( *iptr2 != '{' ) {
5060 rs->sr_err = LDAP_NAMING_VIOLATION;
5061 rs->sr_text = "new ordering index is required";
5065 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
5066 ptr1 = ber_bvchr( &rdn, '}' );
5067 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5069 rs->sr_err = LDAP_NAMING_VIOLATION;
5070 rs->sr_text = "new ordering index is required";
5074 len1 = ptr1 - rdn.bv_val;
5075 len2 = ptr2 - op->orr_newrdn.bv_val;
5077 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
5078 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
5079 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5080 rs->sr_text = "changing database/overlay type not allowed";
5083 ixold = strtol( iptr1, NULL, 0 );
5084 ixnew = strtol( iptr2, &ptr1, 0 );
5085 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
5086 rs->sr_err = LDAP_NAMING_VIOLATION;
5089 /* config DB is always 0, cannot be changed */
5090 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
5091 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
5095 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5096 rs->sr_text = "renaming not supported for this entry";
5100 ldap_pvt_thread_pool_pause( &connection_pool );
5102 if ( ce->ce_type == Cft_Schema ) {
5103 req_modrdn_s modr = op->oq_modrdn;
5106 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
5107 if ( rs->sr_err == LDAP_SUCCESS ) {
5108 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
5109 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
5112 op->oq_modrdn = modr;
5114 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
5115 req_modrdn_s modr = op->oq_modrdn;
5118 /* Advance to first of this type */
5119 cprev = &ce->ce_parent->ce_kids;
5120 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
5121 cprev = &ce2->ce_sibs;
5124 /* Skip the -1 entry */
5125 if ( ce->ce_type == Cft_Database ) {
5126 cprev = &ce2->ce_sibs;
5132 /* Remove from old slot */
5133 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
5134 cprev = &ce2->ce_sibs;
5135 *cprev = ce->ce_sibs;
5136 ceold = ce->ce_sibs;
5138 /* Insert into new slot */
5140 for ( i=0; i<ixnew; i++ ) {
5144 cprev = &ce2->ce_sibs;
5146 ce->ce_sibs = *cprev;
5151 /* NOTE: These should be encoded in the OC tables, not inline here */
5152 if ( ce->ce_type == Cft_Database )
5153 backend_db_move( ce->ce_be, ixnew );
5154 else if ( ce->ce_type == Cft_Overlay )
5155 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
5157 if ( ixold < ixnew ) {
5158 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
5161 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
5162 ixold - ixnew, cfb->cb_use_ldif );
5164 op->oq_modrdn = modr;
5167 ldap_pvt_thread_pool_resume( &connection_pool );
5169 send_ldap_result( op, rs );
5174 config_back_delete( Operation *op, SlapReply *rs )
5176 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM, NULL );
5181 config_back_search( Operation *op, SlapReply *rs )
5184 CfEntryInfo *ce, *last;
5187 cfb = (CfBackInfo *)op->o_bd->be_private;
5189 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5192 rs->sr_matched = last->ce_entry->e_name.bv_val;
5193 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5196 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
5197 ACL_SEARCH, NULL, &mask ))
5199 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
5200 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5202 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5206 switch ( op->ors_scope ) {
5207 case LDAP_SCOPE_BASE:
5208 case LDAP_SCOPE_SUBTREE:
5209 config_send( op, rs, ce, 0 );
5212 case LDAP_SCOPE_ONELEVEL:
5213 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
5214 config_send( op, rs, ce, 1 );
5219 rs->sr_err = LDAP_SUCCESS;
5221 send_ldap_result( op, rs );
5225 /* no-op, we never free entries */
5226 int config_entry_release(
5231 if ( !e->e_private ) {
5234 return LDAP_SUCCESS;
5237 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
5239 int config_back_entry_get(
5243 AttributeDescription *at,
5248 CfEntryInfo *ce, *last;
5250 cfb = (CfBackInfo *)op->o_bd->be_private;
5252 ce = config_find_base( cfb->cb_root, ndn, &last );
5254 *ent = ce->ce_entry;
5255 if ( *ent && oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
5260 return ( *ent == NULL ? 1 : 0 );
5264 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
5265 ConfigTable *ct, ConfigArgs *c )
5269 for (; at && *at; at++) {
5270 /* Skip the naming attr */
5271 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
5273 for (i=0;ct[i].name;i++) {
5274 if (ct[i].ad == (*at)->sat_ad) {
5275 rc = config_get_vals(&ct[i], c);
5276 /* NOTE: tolerate that config_get_vals()
5277 * returns success with no values */
5278 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
5279 if ( c->rvalue_nvals )
5280 attr_merge(e, ct[i].ad, c->rvalue_vals,
5283 attr_merge_normalize(e, ct[i].ad,
5284 c->rvalue_vals, NULL);
5285 ber_bvarray_free( c->rvalue_nvals );
5286 ber_bvarray_free( c->rvalue_vals );
5295 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
5296 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
5298 Entry *e = entry_alloc();
5299 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5301 struct berval ad_name;
5302 AttributeDescription *ad = NULL;
5309 CfEntryInfo *ceprev = NULL;
5311 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
5314 ce->ce_type = main->co_type;
5315 ce->ce_parent = parent;
5317 pdn = parent->ce_entry->e_nname;
5318 if ( parent->ce_kids )
5319 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
5320 ceprev->ce_type <= ce->ce_type;
5321 ceprev = ceprev->ce_sibs );
5326 ce->ce_private = c->private;
5330 build_new_dn( &e->e_name, &pdn, rdn, NULL );
5331 ber_dupbv( &e->e_nname, &e->e_name );
5333 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
5334 main->co_name, NULL );
5336 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
5337 extra->co_name, NULL );
5338 ptr = strchr(rdn->bv_val, '=');
5339 ad_name.bv_val = rdn->bv_val;
5340 ad_name.bv_len = ptr - rdn->bv_val;
5341 rc = slap_bv2ad( &ad_name, &ad, &text );
5346 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
5347 attr_merge_normalize_one(e, ad, &val, NULL );
5350 c->table = main->co_type;
5351 if ( oc->soc_required )
5352 config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
5354 if ( oc->soc_allowed )
5355 config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
5359 c->table = extra->co_type;
5360 if ( oc->soc_required )
5361 config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
5363 if ( oc->soc_allowed )
5364 config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
5367 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5368 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
5369 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
5370 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
5371 if ( op && !op->o_noop ) {
5373 op->ora_modlist = NULL;
5374 op->o_bd->be_add( op, rs );
5375 if ( ( rs->sr_err != LDAP_SUCCESS )
5376 && (rs->sr_err != LDAP_ALREADY_EXISTS) ) {
5381 ce->ce_sibs = ceprev->ce_sibs;
5382 ceprev->ce_sibs = ce;
5383 } else if ( parent ) {
5384 ce->ce_sibs = parent->ce_kids;
5385 parent->ce_kids = ce;
5392 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
5393 Operation *op, SlapReply *rs )
5396 ConfigFile *cf = c->private;
5400 for (; cf; cf=cf->c_sibs, c->depth++) {
5401 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
5402 !cf->c_om_head ) continue;
5403 c->value_dn.bv_val = c->log;
5404 LUTIL_SLASHPATH( cf->c_file.bv_val );
5405 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
5410 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
5412 ptr = strchr( bv.bv_val, '.' );
5414 bv.bv_len = ptr - bv.bv_val;
5415 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
5416 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
5417 /* FIXME: how can indicate error? */
5420 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
5422 c->value_dn.bv_len += bv.bv_len;
5423 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
5426 e = config_build_entry( op, rs, ceparent, c, &c->value_dn,
5427 &CFOC_SCHEMA, NULL );
5430 } else if ( e && cf->c_kids ) {
5431 c->private = cf->c_kids;
5432 config_build_schema_inc( c, e->e_private, op, rs );
5438 #ifdef SLAPD_MODULES
5441 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
5442 Operation *op, SlapReply *rs )
5447 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
5448 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
5450 c->value_dn.bv_val = c->log;
5451 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
5452 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
5453 /* FIXME: how can indicate error? */
5457 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
5466 config_check_schema(Operation *op, CfBackInfo *cfb)
5468 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
5470 CfEntryInfo *ce, *last;
5473 /* If there's no root entry, we must be in the midst of converting */
5474 if ( !cfb->cb_root )
5477 /* Make sure the main schema entry exists */
5478 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
5485 /* Make sure it's up to date */
5486 if ( cf_om_tail != om_sys_tail ) {
5487 a = attr_find( e->e_attrs, cfAd_om );
5489 if ( a->a_nvals != a->a_vals )
5490 ber_bvarray_free( a->a_nvals );
5491 ber_bvarray_free( a->a_vals );
5496 oidm_unparse( &bv, NULL, NULL, 1 );
5497 attr_merge_normalize( e, cfAd_om, bv, NULL );
5498 ber_bvarray_free( bv );
5499 cf_om_tail = om_sys_tail;
5501 if ( cf_at_tail != at_sys_tail ) {
5502 a = attr_find( e->e_attrs, cfAd_attr );
5504 if ( a->a_nvals != a->a_vals )
5505 ber_bvarray_free( a->a_nvals );
5506 ber_bvarray_free( a->a_vals );
5511 at_unparse( &bv, NULL, NULL, 1 );
5512 attr_merge_normalize( e, cfAd_attr, bv, NULL );
5513 ber_bvarray_free( bv );
5514 cf_at_tail = at_sys_tail;
5516 if ( cf_oc_tail != oc_sys_tail ) {
5517 a = attr_find( e->e_attrs, cfAd_oc );
5519 if ( a->a_nvals != a->a_vals )
5520 ber_bvarray_free( a->a_nvals );
5521 ber_bvarray_free( a->a_vals );
5526 oc_unparse( &bv, NULL, NULL, 1 );
5527 attr_merge_normalize( e, cfAd_oc, bv, NULL );
5528 ber_bvarray_free( bv );
5529 cf_oc_tail = oc_sys_tail;
5532 SlapReply rs = {REP_RESULT};
5534 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
5535 &CFOC_SCHEMA, NULL );
5540 ce->ce_private = cfb->cb_config;
5541 cf_at_tail = at_sys_tail;
5542 cf_oc_tail = oc_sys_tail;
5543 cf_om_tail = om_sys_tail;
5548 static const char *defacl[] = {
5549 NULL, "to", "*", "by", "*", "none", NULL
5553 config_back_db_open( BackendDB *be, ConfigReply *cr )
5555 CfBackInfo *cfb = be->be_private;
5558 CfEntryInfo *ce, *ceparent;
5562 Connection conn = {0};
5563 OperationBuffer opbuf;
5565 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
5566 SlapReply rs = {REP_RESULT};
5567 void *thrctx = NULL;
5569 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
5571 /* If we have no explicitly configured ACLs, don't just use
5572 * the global ACLs. Explicitly deny access to everything.
5574 if ( frontendDB->be_acl && be->be_acl == frontendDB->be_acl ) {
5575 parse_acl(be, "config_back_db_open", 0, 6, (char **)defacl, 0 );
5578 thrctx = ldap_pvt_thread_pool_context();
5579 connection_fake_init( &conn, &opbuf, thrctx );
5582 op->o_tag = LDAP_REQ_ADD;
5583 op->o_callback = &cb;
5584 op->o_bd = &cfb->cb_db;
5585 op->o_dn = op->o_bd->be_rootdn;
5586 op->o_ndn = op->o_bd->be_rootndn;
5588 if ( !cfb->cb_use_ldif ) {
5592 /* If we read the config from back-ldif, do some quick sanity checks */
5593 if ( cfb->cb_got_ldif ) {
5594 return config_check_schema( op, cfb );
5597 /* create root of tree */
5599 c.private = cfb->cb_config;
5601 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
5611 #ifdef SLAPD_MODULES
5612 /* Create Module nodes... */
5613 if ( modpaths.mp_loads ) {
5614 if ( config_build_modules( &c, ceparent, op, &rs ) ){
5620 /* Create schema nodes... cn=schema will contain the hardcoded core
5621 * schema, read-only. Child objects will contain runtime loaded schema
5626 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
5631 ce->ce_private = cfb->cb_config;
5632 cf_at_tail = at_sys_tail;
5633 cf_oc_tail = oc_sys_tail;
5634 cf_om_tail = om_sys_tail;
5636 /* Create schema nodes for included schema... */
5637 if ( cfb->cb_config->c_kids ) {
5639 c.private = cfb->cb_config->c_kids;
5640 if (config_build_schema_inc( &c, ce, op, &rs )) {
5645 /* Create backend nodes. Skip if they don't provide a cf_table.
5646 * There usually aren't any of these.
5650 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
5651 if (!bi->bi_cf_ocs) {
5652 /* If it only supports the old config mech, complain. */
5653 if ( bi->bi_config ) {
5654 Debug( LDAP_DEBUG_ANY,
5655 "WARNING: No dynamic config support for backend %s.\n",
5656 bi->bi_type, 0, 0 );
5661 if (!bi->bi_private) continue;
5664 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
5665 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
5666 if ( rdn.bv_len >= sizeof( c.log ) ) {
5667 /* FIXME: holler ... */ ;
5670 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
5677 /* Create database nodes... */
5678 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
5679 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
5680 for ( i = -1, be = frontendDB ; be;
5681 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
5682 slap_overinfo *oi = NULL;
5684 if ( overlay_is_over( be )) {
5685 oi = be->bd_info->bi_private;
5691 /* If this backend supports the old config mechanism, but not
5692 * the new mech, complain.
5694 if ( !be->be_cf_ocs && bi->bi_db_config ) {
5695 Debug( LDAP_DEBUG_ANY,
5696 "WARNING: No dynamic config support for database %s.\n",
5697 bi->bi_type, 0, 0 );
5701 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
5702 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
5704 if ( rdn.bv_len >= sizeof( c.log ) ) {
5705 /* FIXME: holler ... */ ;
5709 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
5715 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd )
5716 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
5717 /* Iterate through overlays */
5723 for (j=0,on=oi->oi_list; on; j++,on=on->on_next) {
5724 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
5725 Debug( LDAP_DEBUG_ANY,
5726 "WARNING: No dynamic config support for overlay %s.\n",
5727 on->on_bi.bi_type, 0, 0 );
5731 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
5732 "%s=" SLAP_X_ORDERED_FMT "%s",
5733 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
5734 if ( rdn.bv_len >= sizeof( c.log ) ) {
5735 /* FIXME: holler ... */ ;
5739 oe = config_build_entry( op, &rs, ce, &c, &rdn,
5740 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
5744 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd )
5745 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
5750 ldap_pvt_thread_pool_context_reset( thrctx );
5752 if ( unsupp && cfb->cb_use_ldif ) {
5753 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
5754 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
5761 cfb_free_cffile( ConfigFile *cf )
5765 for (; cf; cf=next) {
5768 cfb_free_cffile( cf->c_kids );
5769 ch_free( cf->c_file.bv_val );
5770 ber_bvarray_free( cf->c_dseFiles );
5776 cfb_free_entries( CfEntryInfo *ce )
5780 for (; ce; ce=next) {
5783 cfb_free_entries( ce->ce_kids );
5784 ce->ce_entry->e_private = NULL;
5785 entry_free( ce->ce_entry );
5791 config_back_db_close( BackendDB *be, ConfigReply *cr )
5793 CfBackInfo *cfb = be->be_private;
5795 cfb_free_entries( cfb->cb_root );
5796 cfb->cb_root = NULL;
5798 if ( cfb->cb_db.bd_info ) {
5799 backend_shutdown( &cfb->cb_db );
5806 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
5808 CfBackInfo *cfb = be->be_private;
5810 cfb_free_cffile( cfb->cb_config );
5812 ch_free( cfdir.bv_val );
5814 avl_free( CfOcTree, NULL );
5816 if ( cfb->cb_db.bd_info ) {
5817 cfb->cb_db.be_suffix = NULL;
5818 cfb->cb_db.be_nsuffix = NULL;
5819 BER_BVZERO( &cfb->cb_db.be_rootdn );
5820 BER_BVZERO( &cfb->cb_db.be_rootndn );
5822 backend_destroy_one( &cfb->cb_db, 0 );
5831 config_back_db_init( BackendDB *be, ConfigReply* cr )
5837 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
5838 cfn = cfb->cb_config;
5839 be->be_private = cfb;
5841 ber_dupbv( &be->be_rootdn, &config_rdn );
5842 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
5843 ber_dupbv( &dn, &be->be_rootdn );
5844 ber_bvarray_add( &be->be_suffix, &dn );
5845 ber_dupbv( &dn, &be->be_rootdn );
5846 ber_bvarray_add( &be->be_nsuffix, &dn );
5848 /* Hide from namingContexts */
5849 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
5855 config_back_destroy( BackendInfo *bi )
5857 ldif_must_b64_encode_release();
5862 config_tool_entry_open( BackendDB *be, int mode )
5864 CfBackInfo *cfb = be->be_private;
5865 BackendInfo *bi = cfb->cb_db.bd_info;
5867 if ( bi && bi->bi_tool_entry_open )
5868 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
5875 config_tool_entry_close( BackendDB *be )
5877 CfBackInfo *cfb = be->be_private;
5878 BackendInfo *bi = cfb->cb_db.bd_info;
5880 if ( bi && bi->bi_tool_entry_close )
5881 return bi->bi_tool_entry_close( &cfb->cb_db );
5887 config_tool_entry_first( BackendDB *be )
5889 CfBackInfo *cfb = be->be_private;
5890 BackendInfo *bi = cfb->cb_db.bd_info;
5892 if ( bi && bi->bi_tool_entry_first )
5893 return bi->bi_tool_entry_first( &cfb->cb_db );
5899 config_tool_entry_next( BackendDB *be )
5901 CfBackInfo *cfb = be->be_private;
5902 BackendInfo *bi = cfb->cb_db.bd_info;
5904 if ( bi && bi->bi_tool_entry_next )
5905 return bi->bi_tool_entry_next( &cfb->cb_db );
5911 config_tool_entry_get( BackendDB *be, ID id )
5913 CfBackInfo *cfb = be->be_private;
5914 BackendInfo *bi = cfb->cb_db.bd_info;
5916 if ( bi && bi->bi_tool_entry_get )
5917 return bi->bi_tool_entry_get( &cfb->cb_db, id );
5922 static int entry_put_got_frontend=0;
5923 static int entry_put_got_config=0;
5925 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
5927 CfBackInfo *cfb = be->be_private;
5928 BackendInfo *bi = cfb->cb_db.bd_info;
5930 struct berval rdn, vals[ 2 ];
5932 OperationBuffer opbuf;
5934 Connection conn = {0};
5935 Operation *op = NULL;
5938 /* Create entry for frontend database if it does not exist already */
5939 if ( !entry_put_got_frontend ) {
5940 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
5941 STRLENOF( "olcDatabase" ))) {
5942 if ( strncmp( e->e_nname.bv_val +
5943 STRLENOF( "olcDatabase" ), "={-1}frontend",
5944 STRLENOF( "={-1}frontend" )) &&
5945 strncmp( e->e_nname.bv_val +
5946 STRLENOF( "olcDatabase" ), "=frontend",
5947 STRLENOF( "=frontend" ))) {
5949 vals[1].bv_val = NULL;
5950 memset( &ca, 0, sizeof(ConfigArgs));
5952 ca.bi = frontendDB->bd_info;
5953 ca.be->be_cf_ocs = &CFOC_FRONTEND;
5954 rdn.bv_val = ca.log;
5955 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
5956 "%s=" SLAP_X_ORDERED_FMT "%s",
5957 cfAd_database->ad_cname.bv_val, -1,
5959 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
5960 &CFOC_DATABASE, ca.be->be_cf_ocs );
5961 thrctx = ldap_pvt_thread_pool_context();
5962 connection_fake_init2( &conn, &opbuf, thrctx,0 );
5964 op->o_bd = &cfb->cb_db;
5965 op->o_tag = LDAP_REQ_ADD;
5967 op->o_dn = be->be_rootdn;
5968 op->o_ndn = be->be_rootndn;
5969 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
5970 if ( rc != LDAP_SUCCESS ) {
5971 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
5972 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
5976 if ( ce && bi && bi->bi_tool_entry_put &&
5977 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
5978 entry_put_got_frontend++;
5980 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
5981 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
5985 entry_put_got_frontend++;
5989 /* Create entry for config database if it does not exist already */
5990 if ( !entry_put_got_config ) {
5991 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
5992 STRLENOF( "olcDatabase" ))) {
5993 if ( strncmp( e->e_nname.bv_val +
5994 STRLENOF( "olcDatabase" ), "={0}config",
5995 STRLENOF( "={0}config" )) &&
5996 strncmp( e->e_nname.bv_val +
5997 STRLENOF( "olcDatabase" ), "=config",
5998 STRLENOF( "=config" )) ) {
6000 vals[1].bv_val = NULL;
6001 memset( &ca, 0, sizeof(ConfigArgs));
6002 ca.be = LDAP_STAILQ_FIRST( &backendDB );
6003 ca.bi = ca.be->bd_info;
6004 rdn.bv_val = ca.log;
6005 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
6006 "%s=" SLAP_X_ORDERED_FMT "%s",
6007 cfAd_database->ad_cname.bv_val, 0,
6009 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
6012 thrctx = ldap_pvt_thread_pool_context();
6013 connection_fake_init2( &conn, &opbuf, thrctx,0 );
6015 op->o_bd = &cfb->cb_db;
6016 op->o_tag = LDAP_REQ_ADD;
6017 op->o_dn = be->be_rootdn;
6018 op->o_ndn = be->be_rootndn;
6021 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
6022 if ( rc != LDAP_SUCCESS ) {
6023 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
6024 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
6027 if (ce && bi && bi->bi_tool_entry_put &&
6028 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
6029 entry_put_got_config++;
6031 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
6032 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
6036 entry_put_got_config++;
6040 if ( bi && bi->bi_tool_entry_put &&
6041 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
6042 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
6049 AttributeDescription **desc;
6051 { "attribute", &cfAd_attr },
6052 { "backend", &cfAd_backend },
6053 { "database", &cfAd_database },
6054 { "include", &cfAd_include },
6055 { "objectclass", &cfAd_oc },
6056 { "objectidentifier", &cfAd_om },
6057 { "overlay", &cfAd_overlay },
6062 * add / delete: all types that may be added or deleted must use an
6063 * X-ORDERED attributeType for their RDN. Adding and deleting entries
6064 * should automatically renumber the index of any siblings as needed,
6065 * so that no gaps in the numbering sequence exist after the add/delete
6067 * What can be added:
6069 * backend objects for backend-specific config directives
6073 * delete: probably no support this time around.
6075 * modrdn: generally not done. Will be invoked automatically by add/
6076 * delete to update numbering sequence. Perform as an explicit operation
6077 * so that the renumbering effect may be replicated. Subtree rename must
6078 * be supported, since renumbering a database will affect all its child
6081 * modify: must be fully supported.
6085 config_back_initialize( BackendInfo *bi )
6087 ConfigTable *ct = config_back_cf_table;
6091 AttributeDescription *ad = NULL;
6093 static char *controls[] = {
6094 LDAP_CONTROL_MANAGEDSAIT,
6098 /* Make sure we don't exceed the bits reserved for userland */
6099 config_check_userland( CFG_LAST );
6101 bi->bi_controls = controls;
6106 bi->bi_destroy = config_back_destroy;
6108 bi->bi_db_init = config_back_db_init;
6109 bi->bi_db_config = 0;
6110 bi->bi_db_open = config_back_db_open;
6111 bi->bi_db_close = config_back_db_close;
6112 bi->bi_db_destroy = config_back_db_destroy;
6114 bi->bi_op_bind = config_back_bind;
6115 bi->bi_op_unbind = 0;
6116 bi->bi_op_search = config_back_search;
6117 bi->bi_op_compare = 0;
6118 bi->bi_op_modify = config_back_modify;
6119 bi->bi_op_modrdn = config_back_modrdn;
6120 bi->bi_op_add = config_back_add;
6121 bi->bi_op_delete = config_back_delete;
6122 bi->bi_op_abandon = 0;
6124 bi->bi_extended = 0;
6126 bi->bi_chk_referrals = 0;
6128 bi->bi_access_allowed = slap_access_allowed;
6130 bi->bi_connection_init = 0;
6131 bi->bi_connection_destroy = 0;
6133 bi->bi_entry_release_rw = config_entry_release;
6134 bi->bi_entry_get_rw = config_back_entry_get;
6136 bi->bi_tool_entry_open = config_tool_entry_open;
6137 bi->bi_tool_entry_close = config_tool_entry_close;
6138 bi->bi_tool_entry_first = config_tool_entry_first;
6139 bi->bi_tool_entry_next = config_tool_entry_next;
6140 bi->bi_tool_entry_get = config_tool_entry_get;
6141 bi->bi_tool_entry_put = config_tool_entry_put;
6144 argv[ 0 ] = "slapd";
6150 for (i=0; OidMacros[i].name; i++ ) {
6151 argv[1] = OidMacros[i].name;
6152 argv[2] = OidMacros[i].oid;
6153 parse_oidm( &ca, 0, NULL );
6156 bi->bi_cf_ocs = cf_ocs;
6158 i = config_register_schema( ct, cf_ocs );
6161 /* setup olcRootPW to be base64-encoded when written in LDIF form;
6162 * basically, we don't care if it fails */
6163 i = slap_str2ad( "olcRootPW", &ad, &text );
6165 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
6166 "warning, unable to get \"olcRootPW\" "
6167 "attribute description: %d: %s\n",
6170 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
6171 ad->ad_type->sat_oid );
6174 /* set up the notable AttributeDescriptions */
6176 for (;ct->name;ct++) {
6177 if (strcmp(ct->name, ads[i].name)) continue;
6178 *ads[i].desc = ct->ad;
6180 if (!ads[i].name) break;