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;
80 static char *logfileName;
81 #ifdef SLAP_AUTH_REWRITE
82 static BerVarray authz_rewrites;
85 static struct berval cfdir;
88 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
89 *cfAd_include, *cfAd_attr, *cfAd_oc, *cfAd_om;
91 static ConfigFile *cfn;
93 static Avlnode *CfOcTree;
95 /* System schema state */
96 extern AttributeType *at_sys_tail; /* at.c */
97 extern ObjectClass *oc_sys_tail; /* oc.c */
98 extern OidMacro *om_sys_tail; /* oidm.c */
99 static AttributeType *cf_at_tail;
100 static ObjectClass *cf_oc_tail;
101 static OidMacro *cf_om_tail;
103 static int config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca,
104 SlapReply *rs, int *renumber, Operation *op );
106 static int config_check_schema( Operation *op, CfBackInfo *cfb );
108 static ConfigDriver config_fname;
109 static ConfigDriver config_cfdir;
110 static ConfigDriver config_generic;
111 static ConfigDriver config_search_base;
112 static ConfigDriver config_passwd_hash;
113 static ConfigDriver config_schema_dn;
114 static ConfigDriver config_sizelimit;
115 static ConfigDriver config_timelimit;
116 static ConfigDriver config_overlay;
117 static ConfigDriver config_subordinate;
118 static ConfigDriver config_suffix;
119 static ConfigDriver config_rootdn;
120 static ConfigDriver config_rootpw;
121 static ConfigDriver config_restrict;
122 static ConfigDriver config_allows;
123 static ConfigDriver config_disallows;
124 static ConfigDriver config_requires;
125 static ConfigDriver config_security;
126 static ConfigDriver config_referral;
127 static ConfigDriver config_loglevel;
128 static ConfigDriver config_updatedn;
129 static ConfigDriver config_updateref;
130 static ConfigDriver config_include;
131 static ConfigDriver config_obsolete;
133 static ConfigDriver config_tls_option;
134 static ConfigDriver config_tls_config;
136 extern ConfigDriver syncrepl_config;
188 static OidRec OidMacros[] = {
189 /* OpenLDAProot:666.11.1 */
190 { "OLcfg", "1.3.6.1.4.1.4203.666.11.1" },
191 { "OLcfgAt", "OLcfg:3" },
192 { "OLcfgGlAt", "OLcfgAt:0" },
193 { "OLcfgBkAt", "OLcfgAt:1" },
194 { "OLcfgDbAt", "OLcfgAt:2" },
195 { "OLcfgOvAt", "OLcfgAt:3" },
196 { "OLcfgCtAt", "OLcfgAt:4" }, /* contrib modules */
197 { "OLcfgOc", "OLcfg:4" },
198 { "OLcfgGlOc", "OLcfgOc:0" },
199 { "OLcfgBkOc", "OLcfgOc:1" },
200 { "OLcfgDbOc", "OLcfgOc:2" },
201 { "OLcfgOvOc", "OLcfgOc:3" },
202 { "OLcfgCtOc", "OLcfgOc:4" }, /* contrib modules */
204 /* Syntaxes. We should just start using the standard names and
205 * document that they are predefined and available for users
206 * to reference in their own schema. Defining schema without
207 * OID macros is for masochists...
209 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
210 { "OMsBoolean", "OMsyn:7" },
211 { "OMsDN", "OMsyn:12" },
212 { "OMsDirectoryString", "OMsyn:15" },
213 { "OMsIA5String", "OMsyn:26" },
214 { "OMsInteger", "OMsyn:27" },
215 { "OMsOID", "OMsyn:38" },
216 { "OMsOctetString", "OMsyn:40" },
221 * Backend/Database registry
223 * OLcfg{Bk|Db}{Oc|At}:0 -> common
224 * OLcfg{Bk|Db}{Oc|At}:1 -> back-bdb(/back-hdb)
225 * OLcfg{Bk|Db}{Oc|At}:2 -> back-ldif
226 * OLcfg{Bk|Db}{Oc|At}:3 -> back-ldap
227 * OLcfg{Bk|Db}{Oc|At}:4 -> back-monitor
228 * OLcfg{Bk|Db}{Oc|At}:5 -> back-relay
229 * OLcfg{Bk|Db}{Oc|At}:6 -> back-sql
235 * OLcfgOv{Oc|At}:1 -> syncprov
236 * OLcfgOv{Oc|At}:2 -> pcache
237 * OLcfgOv{Oc|At}:3 -> chain
238 * OLcfgOv{Oc|At}:4 -> accesslog
239 * OLcfgOv{Oc|At}:5 -> valsort
240 * OLcfgOv{Oc|At}:7 -> distproc
241 * OLcfgOv{Oc|At}:8 -> dynlist
242 * OLcfgOv{Oc|At}:9 -> dds
243 * OLcfgOv{Oc|At}:10 -> unique
244 * OLcfgOv{Oc|At}:11 -> refint
245 * OLcfgOv{Oc|At}:12 -> ppolicy
246 * OLcfgOv{Oc|At}:13 -> constraint
247 * OLcfgOv{Oc|At}:14 -> translucent
248 * OLcfgOv{Oc|At}:15 -> auditlog
249 * OLcfgOv{Oc|At}:16 -> rwm
250 * OLcfgOv{Oc|At}:17 -> dyngroup
251 * OLcfgOv{Oc|At}:18 -> memberof
252 * OLcfgOv{Oc|At}:19 -> collect
255 /* alphabetical ordering */
257 static ConfigTable config_back_cf_table[] = {
258 /* This attr is read-only */
259 { "", "", 0, 0, 0, ARG_MAGIC,
260 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
261 "DESC 'File for slapd configuration directives' "
262 "EQUALITY caseIgnoreMatch "
263 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
264 { "", "", 0, 0, 0, ARG_MAGIC,
265 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
266 "DESC 'Directory for slapd configuration backend' "
267 "EQUALITY caseIgnoreMatch "
268 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
269 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
270 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
271 "DESC 'Access Control List' "
272 "EQUALITY caseIgnoreMatch "
273 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
274 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
275 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
276 "DESC 'Allowed set of deprecated features' "
277 "EQUALITY caseIgnoreMatch "
278 "SYNTAX OMsDirectoryString )", NULL, NULL },
279 { "argsfile", "file", 2, 2, 0, ARG_STRING,
280 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
281 "DESC 'File for slapd command line options' "
282 "EQUALITY caseIgnoreMatch "
283 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
284 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
285 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
286 "EQUALITY caseIgnoreMatch "
287 "SYNTAX OMsDirectoryString )", NULL, NULL },
288 { "attribute", "attribute", 2, 0, STRLENOF( "attribute" ),
289 ARG_PAREN|ARG_MAGIC|CFG_ATTR,
290 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
291 "DESC 'OpenLDAP attributeTypes' "
292 "EQUALITY caseIgnoreMatch "
293 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
295 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
296 #ifdef SLAP_AUTH_REWRITE
297 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
301 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
302 "EQUALITY caseIgnoreMatch "
303 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
304 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
305 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
306 "EQUALITY caseIgnoreMatch "
307 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
308 { "authz-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
309 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
310 "EQUALITY caseIgnoreMatch "
311 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
312 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
313 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
314 "DESC 'A type of backend' "
315 "EQUALITY caseIgnoreMatch "
316 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
318 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
319 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
320 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
321 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
322 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
323 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
324 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
325 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
326 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
327 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
328 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
329 "DESC 'The backend type for a database instance' "
330 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
331 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
332 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
333 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
334 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
335 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
336 "EQUALITY caseIgnoreMatch "
337 "SYNTAX OMsDirectoryString )", NULL, NULL },
338 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
339 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
340 "DESC 'OpenLDAP DIT content rules' "
341 "EQUALITY caseIgnoreMatch "
342 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
344 { "gentlehup", "on|off", 2, 2, 0,
346 ARG_ON_OFF, &global_gentlehup,
350 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
351 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
352 { "hidden", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_HIDDEN,
353 &config_generic, "( OLcfgDbAt:0.17 NAME 'olcHidden' "
354 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
355 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
356 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
357 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
358 { "include", "file", 2, 2, 0, ARG_MAGIC,
359 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
360 "SUP labeledURI )", NULL, NULL },
361 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
362 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
363 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
364 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
365 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
366 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
367 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
368 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
369 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
370 { "index_substr_any_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
371 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
372 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
373 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
374 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
375 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
376 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
377 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
378 "EQUALITY caseIgnoreMatch "
379 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
380 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
381 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
382 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
383 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
384 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
385 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
386 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
387 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
388 "EQUALITY caseIgnoreMatch "
389 "SYNTAX OMsDirectoryString )", NULL, NULL },
390 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
391 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
392 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
393 { "mirrormode", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_MIRRORMODE,
394 &config_generic, "( OLcfgDbAt:0.16 NAME 'olcMirrorMode' "
395 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
396 { "moduleload", "file", 2, 0, 0,
398 ARG_MAGIC|CFG_MODLOAD|ARG_NO_DELETE, &config_generic,
402 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
403 "EQUALITY caseIgnoreMatch "
404 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
405 { "modulepath", "path", 2, 2, 0,
407 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
411 "( OLcfgGlAt:31 NAME 'olcModulePath' "
412 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
413 { "monitoring", "TRUE|FALSE", 2, 2, 0,
414 ARG_MAGIC|CFG_MONITORING|ARG_DB|ARG_ON_OFF, &config_generic,
415 "( OLcfgDbAt:0.18 NAME 'olcMonitoring' "
416 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
417 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
418 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
419 "DESC 'OpenLDAP object classes' "
420 "EQUALITY caseIgnoreMatch "
421 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
423 { "objectidentifier", "name> <oid", 3, 3, 0, ARG_MAGIC|CFG_OID,
424 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
425 "EQUALITY caseIgnoreMatch "
426 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
427 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
428 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
429 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
430 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
431 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
432 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
433 { "password-hash", "hash", 2, 2, 0, ARG_MAGIC,
434 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
435 "EQUALITY caseIgnoreMatch "
436 "SYNTAX OMsDirectoryString )", NULL, NULL },
437 { "pidfile", "file", 2, 2, 0, ARG_STRING,
438 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
439 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
440 { "plugin", NULL, 0, 0, 0,
442 ARG_MAGIC|CFG_PLUGIN, &config_generic,
446 "( OLcfgGlAt:38 NAME 'olcPlugin' "
447 "EQUALITY caseIgnoreMatch "
448 "SYNTAX OMsDirectoryString )", NULL, NULL },
449 { "pluginlog", "filename", 2, 2, 0,
451 ARG_STRING, &slapi_log_file,
455 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
456 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
457 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
458 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
459 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
460 { "referral", "url", 2, 2, 0, ARG_MAGIC,
461 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
462 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
463 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
464 &config_obsolete, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
465 "EQUALITY caseIgnoreMatch "
466 "SUP labeledURI X-ORDERED 'VALUES' )", NULL, NULL },
467 { "replica-argsfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
468 &config_obsolete, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
469 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
470 { "replica-pidfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
471 &config_obsolete, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
472 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
473 { "replicationInterval", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
474 &config_obsolete, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
475 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
476 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC,
477 &config_obsolete, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
478 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
479 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
480 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
481 "EQUALITY caseIgnoreMatch "
482 "SYNTAX OMsDirectoryString )", NULL, NULL },
483 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
484 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
485 "EQUALITY caseIgnoreMatch "
486 "SYNTAX OMsDirectoryString )", NULL, NULL },
487 { "reverse-lookup", "on|off", 2, 2, 0,
488 #ifdef SLAPD_RLOOKUPS
489 ARG_ON_OFF, &use_reverse_lookup,
493 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
494 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
495 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
496 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
497 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
498 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
499 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
500 "EQUALITY caseIgnoreMatch "
501 "SYNTAX OMsDirectoryString )", NULL, NULL },
502 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
503 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
504 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
505 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
506 &config_generic, NULL, NULL, NULL },
507 { "sasl-host", "host", 2, 2, 0,
508 #ifdef HAVE_CYRUS_SASL
509 ARG_STRING|ARG_UNIQUE, &global_host,
513 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
514 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
515 { "sasl-realm", "realm", 2, 2, 0,
516 #ifdef HAVE_CYRUS_SASL
517 ARG_STRING|ARG_UNIQUE, &global_realm,
521 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
522 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
523 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
524 &config_generic, NULL, NULL, NULL },
525 { "sasl-secprops", "properties", 2, 2, 0,
526 #ifdef HAVE_CYRUS_SASL
527 ARG_MAGIC|CFG_SASLSECP, &config_generic,
531 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
532 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
533 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
534 &config_generic, NULL, NULL, NULL },
535 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
536 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
537 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
538 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
539 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
540 "EQUALITY caseIgnoreMatch "
541 "SYNTAX OMsDirectoryString )", NULL, NULL },
542 { "serverID", "number> <[URI]", 2, 3, 0, ARG_MAGIC|CFG_SERVERID,
543 &config_generic, "( OLcfgGlAt:81 NAME 'olcServerID' "
544 "EQUALITY caseIgnoreMatch "
545 "SYNTAX OMsDirectoryString )", NULL, NULL },
546 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
547 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
548 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
549 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
550 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
551 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
552 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
553 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
554 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
555 { "subordinate", "[advertise]", 1, 2, 0, ARG_DB|ARG_MAGIC,
556 &config_subordinate, "( OLcfgDbAt:0.15 NAME 'olcSubordinate' "
557 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
558 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
559 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
560 "EQUALITY distinguishedNameMatch "
561 "SYNTAX OMsDN )", NULL, NULL },
562 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
563 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
564 "EQUALITY caseIgnoreMatch "
565 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
566 { "threads", "count", 2, 2, 0,
570 ARG_INT|ARG_MAGIC|CFG_THREADS, &config_generic,
572 "( OLcfgGlAt:66 NAME 'olcThreads' "
573 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
574 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
575 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
576 "SYNTAX OMsDirectoryString )", NULL, NULL },
577 { "TLSCACertificateFile", NULL, 0, 0, 0,
579 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
583 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
584 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
585 { "TLSCACertificatePath", NULL, 0, 0, 0,
587 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
591 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
592 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
593 { "TLSCertificateFile", NULL, 0, 0, 0,
595 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
599 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
600 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
601 { "TLSCertificateKeyFile", NULL, 0, 0, 0,
603 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
607 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
608 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
609 { "TLSCipherSuite", NULL, 0, 0, 0,
611 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
615 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
616 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
617 { "TLSCRLCheck", NULL, 0, 0, 0,
618 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
619 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
623 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
624 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
625 { "TLSCRLFile", NULL, 0, 0, 0,
626 #if defined(HAVE_GNUTLS)
627 CFG_TLS_CRL_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
631 "( OLcfgGlAt:82 NAME 'olcTLSCRLFile' "
632 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
633 { "TLSRandFile", NULL, 0, 0, 0,
635 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
639 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
640 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
641 { "TLSVerifyClient", NULL, 0, 0, 0,
643 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
647 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
648 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
649 { "TLSDHParamFile", NULL, 0, 0, 0,
651 CFG_TLS_DH_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
655 "( OLcfgGlAt:77 NAME 'olcTLSDHParamFile' "
656 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
657 { "tool-threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_TTHREADS,
658 &config_generic, "( OLcfgGlAt:80 NAME 'olcToolThreads' "
659 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
660 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
661 NULL, NULL, NULL, NULL },
662 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
663 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
664 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
665 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
666 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
667 "EQUALITY caseIgnoreMatch "
668 "SUP labeledURI )", NULL, NULL },
669 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
670 NULL, NULL, NULL, NULL }
673 /* Routines to check if a child can be added to this type */
674 static ConfigLDAPadd cfAddSchema, cfAddInclude, cfAddDatabase,
675 cfAddBackend, cfAddModule, cfAddOverlay;
677 /* NOTE: be careful when defining array members
678 * that can be conditionally compiled */
679 #define CFOC_GLOBAL cf_ocs[1]
680 #define CFOC_SCHEMA cf_ocs[2]
681 #define CFOC_BACKEND cf_ocs[3]
682 #define CFOC_DATABASE cf_ocs[4]
683 #define CFOC_OVERLAY cf_ocs[5]
684 #define CFOC_INCLUDE cf_ocs[6]
685 #define CFOC_FRONTEND cf_ocs[7]
687 #define CFOC_MODULE cf_ocs[8]
688 #endif /* SLAPD_MODULES */
690 static ConfigOCs cf_ocs[] = {
693 "DESC 'OpenLDAP configuration object' "
694 "ABSTRACT SUP top )", Cft_Abstract, NULL },
697 "DESC 'OpenLDAP Global configuration options' "
698 "SUP olcConfig STRUCTURAL "
699 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
700 "olcAttributeOptions $ olcAuthIDRewrite $ "
701 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
702 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
703 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
704 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
705 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcLocalSSF $ "
707 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
708 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
709 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
711 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
712 "olcSecurity $ olcServerID $ olcSizeLimit $ "
713 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ "
714 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
715 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
716 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
717 "olcTLSRandFile $ olcTLSVerifyClient $ olcTLSDHParamFile $ "
718 "olcTLSCRLFile $ olcToolThreads $ "
719 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
720 "olcDitContentRules ) )", Cft_Global },
722 "NAME 'olcSchemaConfig' "
723 "DESC 'OpenLDAP schema object' "
724 "SUP olcConfig STRUCTURAL "
725 "MAY ( cn $ olcObjectIdentifier $ olcAttributeTypes $ "
726 "olcObjectClasses $ olcDitContentRules ) )",
727 Cft_Schema, NULL, cfAddSchema },
729 "NAME 'olcBackendConfig' "
730 "DESC 'OpenLDAP Backend-specific options' "
731 "SUP olcConfig STRUCTURAL "
732 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
734 "NAME 'olcDatabaseConfig' "
735 "DESC 'OpenLDAP Database-specific options' "
736 "SUP olcConfig STRUCTURAL "
738 "MAY ( olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
739 "olcLastMod $ olcLimits $ "
740 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
741 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
742 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
743 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncrepl $ "
744 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef $ olcMirrorMode $ "
746 Cft_Database, NULL, cfAddDatabase },
748 "NAME 'olcOverlayConfig' "
749 "DESC 'OpenLDAP Overlay-specific options' "
750 "SUP olcConfig STRUCTURAL "
751 "MUST olcOverlay )", Cft_Overlay, NULL, cfAddOverlay },
753 "NAME 'olcIncludeFile' "
754 "DESC 'OpenLDAP configuration include file' "
755 "SUP olcConfig STRUCTURAL "
757 "MAY ( cn $ olcRootDSE ) )",
758 /* Used to be Cft_Include, that def has been removed */
759 Cft_Abstract, NULL, cfAddInclude },
760 /* This should be STRUCTURAL like all the other database classes, but
761 * that would mean inheriting all of the olcDatabaseConfig attributes,
762 * which causes them to be merged twice in config_build_entry.
765 "NAME 'olcFrontendConfig' "
766 "DESC 'OpenLDAP frontend configuration' "
768 "MAY ( olcDefaultSearchBase $ olcPasswordHash ) )",
769 Cft_Database, NULL, NULL },
772 "NAME 'olcModuleList' "
773 "DESC 'OpenLDAP dynamic module info' "
774 "SUP olcConfig STRUCTURAL "
775 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
776 Cft_Module, NULL, cfAddModule },
781 typedef struct ServerID {
782 struct ServerID *si_next;
783 struct berval si_url;
787 static ServerID *sid_list;
790 config_generic(ConfigArgs *c) {
793 if ( c->op == SLAP_CONFIG_EMIT ) {
797 c->value_int = ldap_pvt_thread_get_concurrency();
800 c->value_int = connection_pool_max;
803 c->value_int = slap_tool_thread_max;
807 c->value_string = ch_strdup( passwd_salt );
812 if ( c->be->be_limits ) {
816 for ( i=0; c->be->be_limits[i]; i++ ) {
817 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
818 if ( bv.bv_len >= sizeof( buf ) ) {
819 ber_bvarray_free_x( c->rvalue_vals, NULL );
820 c->rvalue_vals = NULL;
824 bv.bv_val = buf + bv.bv_len;
825 limits_unparse( c->be->be_limits[i], &bv,
826 sizeof( buf ) - ( bv.bv_val - buf ) );
827 bv.bv_len += bv.bv_val - buf;
829 value_add_one( &c->rvalue_vals, &bv );
832 if ( !c->rvalue_vals ) rc = 1;
835 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_OP_WRITES) ==
836 SLAP_RESTRICT_OP_WRITES;
839 c->value_string = ch_strdup( slap_sasl_getpolicy());
842 slap_sasl_regexp_unparse( &c->rvalue_vals );
843 if ( !c->rvalue_vals ) rc = 1;
845 #ifdef HAVE_CYRUS_SASL
847 struct berval bv = BER_BVNULL;
848 slap_sasl_secprops_unparse( &bv );
849 if ( !BER_BVISNULL( &bv )) {
850 ber_bvarray_add( &c->rvalue_vals, &bv );
858 c->value_int = c->be->be_max_deref_depth;
861 if ( SLAP_DBHIDDEN( c->be )) {
868 ConfigFile *cf = c->private;
870 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
871 else if ( cf->c_om_head )
872 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
874 if ( !c->rvalue_vals )
879 ad_unparse_options( &c->rvalue_vals );
882 ConfigFile *cf = c->private;
884 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
885 else if ( cf->c_oc_head )
886 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
888 if ( !c->rvalue_vals )
893 ConfigFile *cf = c->private;
895 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
896 else if ( cf->c_at_head )
897 at_unparse( &c->rvalue_vals, cf->c_at_head,
899 if ( !c->rvalue_vals )
904 ConfigFile *cf = c->private;
906 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
907 else if ( cf->c_cr_head )
908 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
910 if ( !c->rvalue_vals )
917 char *src, *dst, ibuf[11];
918 struct berval bv, abv;
919 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
920 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
921 if ( abv.bv_len >= sizeof( ibuf ) ) {
922 ber_bvarray_free_x( c->rvalue_vals, NULL );
923 c->rvalue_vals = NULL;
927 acl_unparse( a, &bv );
928 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
929 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
930 /* Turn TAB / EOL into plain space */
931 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
932 if (isspace((unsigned char)*src)) *dst++ = ' ';
936 if (dst[-1] == ' ') {
940 abv.bv_len = dst - abv.bv_val;
941 ber_bvarray_add( &c->rvalue_vals, &abv );
947 ConfigFile *cf = c->private;
948 if ( cf->c_dseFiles ) {
949 value_add( &c->rvalue_vals, cf->c_dseFiles );
960 for ( si = sid_list; si; si=si->si_next ) {
961 assert( si->si_num >= 0 && si->si_num <= SLAP_SYNC_SID_MAX );
962 if ( !BER_BVISEMPTY( &si->si_url )) {
963 bv.bv_len = si->si_url.bv_len + 6;
964 bv.bv_val = ch_malloc( bv.bv_len );
965 sprintf( bv.bv_val, "%d %s", si->si_num,
967 ber_bvarray_add( &c->rvalue_vals, &bv );
971 bv.bv_len = sprintf( buf, "%d", si->si_num );
972 value_add_one( &c->rvalue_vals, &bv );
981 c->value_string = ch_strdup( logfileName );
986 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
989 if ( SLAP_SHADOW(c->be))
990 c->value_int = (SLAP_SINGLE_SHADOW(c->be) == 0);
995 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
997 case CFG_SSTR_IF_MAX:
998 c->value_int = index_substr_if_maxlen;
1000 case CFG_SSTR_IF_MIN:
1001 c->value_int = index_substr_if_minlen;
1003 #ifdef SLAPD_MODULES
1005 ModPaths *mp = c->private;
1008 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
1011 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
1012 SLAP_X_ORDERED_FMT "%s", i,
1013 mp->mp_loads[i].bv_val );
1014 if ( bv.bv_len >= sizeof( c->log ) ) {
1015 ber_bvarray_free_x( c->rvalue_vals, NULL );
1016 c->rvalue_vals = NULL;
1019 value_add_one( &c->rvalue_vals, &bv );
1023 rc = c->rvalue_vals ? 0 : 1;
1027 ModPaths *mp = c->private;
1028 if ( !BER_BVISNULL( &mp->mp_path ))
1029 value_add_one( &c->rvalue_vals, &mp->mp_path );
1031 rc = c->rvalue_vals ? 0 : 1;
1037 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1038 if ( !c->rvalue_vals ) rc = 1;
1041 #ifdef SLAP_AUTH_REWRITE
1043 if ( authz_rewrites ) {
1044 struct berval bv, idx;
1049 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1050 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1051 if ( idx.bv_len >= sizeof( ibuf ) ) {
1052 ber_bvarray_free_x( c->rvalue_vals, NULL );
1053 c->rvalue_vals = NULL;
1056 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1057 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1058 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1059 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1060 authz_rewrites[i].bv_val,
1061 authz_rewrites[i].bv_len + 1 );
1062 ber_bvarray_add( &c->rvalue_vals, &bv );
1065 if ( !c->rvalue_vals ) rc = 1;
1072 } else if ( c->op == LDAP_MOD_DELETE ) {
1075 /* single-valued attrs, no-ops */
1083 case CFG_MIRRORMODE:
1084 case CFG_MONITORING:
1086 case CFG_SSTR_IF_MAX:
1087 case CFG_SSTR_IF_MIN:
1090 /* no-ops, requires slapd restart */
1095 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1099 ch_free( passwd_salt );
1104 ch_free( logfileName );
1108 case CFG_SERVERID: {
1109 ServerID *si, **sip;
1111 for ( i=0, si = sid_list, sip = &sid_list;
1112 si; si = *sip, i++ ) {
1113 if ( c->valx == -1 || i == c->valx ) {
1125 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1129 if ( c->valx < 0 ) {
1131 if ( c->be == frontendDB )
1134 end = frontendDB->be_acl;
1135 acl_destroy( c->be->be_acl, end );
1136 c->be->be_acl = end;
1139 AccessControl **prev, *a;
1141 for (i=0, prev = &c->be->be_acl; i < c->valx;
1144 prev = &a->acl_next;
1147 *prev = a->acl_next;
1154 /* Can be NULL when undoing a failed add */
1155 if ( c->ca_entry ) {
1156 ce = c->ca_entry->e_private;
1157 /* can't modify the hardcoded schema */
1158 if ( ce->ce_parent->ce_type == Cft_Global )
1163 if ( c->valx < 0 ) {
1166 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1168 if ( oc == cfn->c_oc_tail )
1171 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1173 ObjectClass *oc, *prev = NULL;
1175 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1180 if ( cfn->c_oc_tail == oc ) {
1181 cfn->c_oc_tail = prev;
1183 if ( cfn->c_oc_head == oc ) {
1185 cfn->c_oc_head = oc;
1192 /* Can be NULL when undoing a failed add */
1193 if ( c->ca_entry ) {
1194 ce = c->ca_entry->e_private;
1195 /* can't modify the hardcoded schema */
1196 if ( ce->ce_parent->ce_type == Cft_Global )
1201 if ( c->valx < 0 ) {
1204 for( at = cfn->c_at_head; at; at_next( &at )) {
1206 if ( at == cfn->c_at_tail )
1209 cfn->c_at_head = cfn->c_at_tail = NULL;
1211 AttributeType *at, *prev = NULL;
1213 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1218 if ( cfn->c_at_tail == at ) {
1219 cfn->c_at_tail = prev;
1221 if ( cfn->c_at_head == at ) {
1223 cfn->c_at_head = at;
1229 /* FIXME: there is no limits_free function */
1231 /* FIXME: there is no ad_option_free function */
1233 /* FIXME: there is no way to remove attributes added by
1247 if(!(c->bi = backend_info(c->argv[1]))) {
1248 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1249 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1250 c->log, c->cr_msg, c->argv[1] );
1257 /* NOTE: config is always the first backend!
1259 if ( !strcasecmp( c->argv[1], "config" )) {
1260 c->be = LDAP_STAILQ_FIRST(&backendDB);
1261 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1264 c->be = backend_db_init(c->argv[1], NULL, c->valx, &c->reply);
1266 if ( c->cr_msg[0] == 0 )
1267 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1268 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n", c->log, c->cr_msg, c->argv[1] );
1275 ldap_pvt_thread_set_concurrency(c->value_int);
1279 if ( c->value_int < 2 ) {
1280 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1281 "threads=%d smaller than minimum value 2",
1283 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1284 c->log, c->cr_msg, 0 );
1287 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1288 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1289 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1290 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1291 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1292 c->log, c->cr_msg, 0 );
1294 if ( slapMode & SLAP_SERVER_MODE )
1295 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1296 connection_pool_max = c->value_int; /* save for reference */
1300 if ( slapMode & SLAP_TOOL_MODE )
1301 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1302 slap_tool_thread_max = c->value_int; /* save for reference */
1306 if ( passwd_salt ) ch_free( passwd_salt );
1307 passwd_salt = c->value_string;
1308 lutil_salt_format(passwd_salt);
1312 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1318 c->be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1320 c->be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1324 ch_free(c->value_string);
1325 if (slap_sasl_setpolicy( c->argv[1] )) {
1326 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
1327 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1328 c->log, c->cr_msg, c->argv[1] );
1334 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1338 #ifdef HAVE_CYRUS_SASL
1341 char *txt = slap_sasl_secprops( c->argv[1] );
1343 snprintf( c->cr_msg, sizeof(c->cr_msg), "<%s> %s",
1345 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0 );
1353 c->be->be_max_deref_depth = c->value_int;
1359 if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private )
1361 if(parse_oidm(c, 1, &om))
1363 if (!cfn->c_om_head) cfn->c_om_head = om;
1364 cfn->c_om_tail = om;
1369 ObjectClass *oc, *prev;
1371 if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private )
1373 if ( c->valx < 0 ) {
1374 prev = cfn->c_oc_tail;
1377 /* If adding anything after the first, prev is easy */
1380 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
1385 /* If adding the first, and head exists, find its prev */
1386 if (cfn->c_oc_head) {
1387 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
1392 /* else prev is NULL, append to end of global list */
1394 if(parse_oc(c, &oc, prev)) return(1);
1395 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1396 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
1401 AttributeType *at, *prev;
1403 if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private )
1405 if ( c->valx < 0 ) {
1406 prev = cfn->c_at_tail;
1409 /* If adding anything after the first, prev is easy */
1412 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
1417 /* If adding the first, and head exists, find its prev */
1418 if (cfn->c_at_head) {
1419 for ( at_start( &at ); at != cfn->c_at_head; ) {
1424 /* else prev is NULL, append to end of global list */
1426 if(parse_at(c, &at, prev)) return(1);
1427 if (!cfn->c_at_head) cfn->c_at_head = at;
1428 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
1435 if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private )
1437 if(parse_cr(c, &cr)) return(1);
1438 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1439 cfn->c_cr_tail = cr;
1444 ad_define_option(NULL, NULL, 0);
1445 for(i = 1; i < c->argc; i++)
1446 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1451 /* Don't append to the global ACL if we're on a specific DB */
1453 if ( c->be != frontendDB && frontendDB->be_acl && c->valx == -1 ) {
1456 for ( a=c->be->be_acl; a && a != frontendDB->be_acl;
1460 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
1466 if(root_dse_read_file(c->argv[1])) {
1467 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> could not read file", c->argv[0] );
1468 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1469 c->log, c->cr_msg, c->argv[1] );
1474 ber_str2bv( c->argv[1], 0, 1, &bv );
1475 if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private )
1477 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1483 ServerID *si, **sip;
1486 if ( lutil_atoi( &num, c->argv[1] ) ||
1487 num < 0 || num > SLAP_SYNC_SID_MAX )
1489 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1490 "<%s> illegal server ID", c->argv[0] );
1491 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1492 c->log, c->cr_msg, c->argv[1] );
1495 /* only one value allowed if no URL is given */
1496 if ( c->argc > 2 ) {
1499 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
1500 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1501 "<%s> only one server ID allowed now", c->argv[0] );
1502 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1503 c->log, c->cr_msg, c->argv[1] );
1507 if ( ldap_url_parse( c->argv[2], &lud )) {
1508 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1509 "<%s> invalid URL", c->argv[0] );
1510 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1511 c->log, c->cr_msg, c->argv[2] );
1514 len = strlen( c->argv[2] );
1515 si = ch_malloc( sizeof(ServerID) + len + 1 );
1516 si->si_url.bv_val = (char *)(si+1);
1517 si->si_url.bv_len = len;
1518 strcpy( si->si_url.bv_val, c->argv[2] );
1521 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1522 "<%s> unqualified server ID not allowed now", c->argv[0] );
1523 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1524 c->log, c->cr_msg, c->argv[1] );
1527 si = ch_malloc( sizeof(ServerID) );
1528 BER_BVZERO( &si->si_url );
1529 slap_serverID = num;
1530 Debug( LDAP_DEBUG_CONFIG,
1532 c->log, slap_serverID, 0 );
1536 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
1539 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
1540 /* If hostname is empty, or is localhost, or matches
1541 * our hostname, this serverID refers to this host.
1542 * Compare it against listeners and ports.
1544 if ( !lud->lud_host || !lud->lud_host[0] ||
1545 !strncasecmp("localhost", lud->lud_host,
1546 STRLENOF("localhost")) ||
1547 !strcasecmp( global_host, lud->lud_host )) {
1548 Listener **l = slapd_get_listeners();
1551 for ( i=0; l[i]; i++ ) {
1554 ldap_url_parse( l[i]->sl_url.bv_val, &lu2 );
1556 if ( strcasecmp( lud->lud_scheme,
1559 if ( lud->lud_port != lu2->lud_port )
1561 /* Listener on ANY address */
1562 if ( !lu2->lud_host || !lu2->lud_host[0] ) {
1566 /* URL on ANY address */
1567 if ( !lud->lud_host || !lud->lud_host[0] ) {
1571 /* Listener has specific host, must
1574 if ( !strcasecmp( lud->lud_host,
1580 ldap_free_urldesc( lu2 );
1582 slap_serverID = si->si_num;
1583 Debug( LDAP_DEBUG_CONFIG,
1584 "%s: SID=%d (listener=%s)\n",
1585 c->log, slap_serverID,
1586 l[i]->sl_url.bv_val );
1593 ldap_free_urldesc( lud );
1598 if ( logfileName ) ch_free( logfileName );
1599 logfileName = c->value_string;
1600 logfile = fopen(logfileName, "w");
1601 if(logfile) lutil_debug_file(logfile);
1605 if(SLAP_NOLASTMODCMD(c->be)) {
1606 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> not available for %s database",
1607 c->argv[0], c->be->bd_info->bi_type );
1608 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1609 c->log, c->cr_msg, 0 );
1613 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1615 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1618 case CFG_MIRRORMODE:
1619 if(!SLAP_SHADOW(c->be)) {
1620 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database is not a shadow",
1622 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1623 c->log, c->cr_msg, 0 );
1627 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
1629 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1632 case CFG_MONITORING:
1634 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
1636 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
1641 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
1643 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
1646 case CFG_SSTR_IF_MAX:
1647 if (c->value_int < index_substr_if_minlen) {
1648 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1649 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1650 c->log, c->cr_msg, c->value_int );
1653 index_substr_if_maxlen = c->value_int;
1656 case CFG_SSTR_IF_MIN:
1657 if (c->value_int > index_substr_if_maxlen) {
1658 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1659 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1660 c->log, c->cr_msg, c->value_int );
1663 index_substr_if_minlen = c->value_int;
1666 #ifdef SLAPD_MODULES
1668 /* If we're just adding a module on an existing modpath,
1669 * make sure we've selected the current path.
1671 if ( c->op == LDAP_MOD_ADD && c->private && modcur != c->private ) {
1672 modcur = c->private;
1673 /* This should never fail */
1674 if ( module_path( modcur->mp_path.bv_val )) {
1675 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> module path no longer valid",
1677 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1678 c->log, c->cr_msg, modcur->mp_path.bv_val );
1682 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1684 /* Record this load on the current path */
1688 if ( c->op == SLAP_CONFIG_ADD ) {
1689 ptr = c->line + STRLENOF("moduleload");
1690 while (!isspace((unsigned char) *ptr)) ptr++;
1691 while (isspace((unsigned char) *ptr)) ptr++;
1695 ber_str2bv(ptr, 0, 1, &bv);
1696 ber_bvarray_add( &modcur->mp_loads, &bv );
1698 /* Check for any new hardcoded schema */
1699 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
1700 config_check_schema( NULL, &cfBackInfo );
1705 if(module_path(c->argv[1])) return(1);
1706 /* Record which path was used with each module */
1710 if (!modpaths.mp_loads) {
1713 mp = ch_malloc( sizeof( ModPaths ));
1714 modlast->mp_next = mp;
1716 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1718 mp->mp_loads = NULL;
1729 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
1731 slapi_plugins_used++;
1735 #ifdef SLAP_AUTH_REWRITE
1740 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
1743 if ( c->argc > 1 ) {
1746 /* quote all args but the first */
1747 line = ldap_charray2str( c->argv, "\" \"" );
1748 ber_str2bv( line, 0, 0, &bv );
1749 s = ber_bvchr( &bv, '"' );
1750 assert( s != NULL );
1751 /* move the trailing quote of argv[0] to the end */
1752 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
1753 bv.bv_val[ bv.bv_len - 1 ] = '"';
1756 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
1759 ber_bvarray_add( &authz_rewrites, &bv );
1766 Debug( LDAP_DEBUG_ANY,
1767 "%s: unknown CFG_TYPE %d.\n",
1768 c->log, c->type, 0 );
1777 config_fname(ConfigArgs *c) {
1778 if(c->op == SLAP_CONFIG_EMIT) {
1780 ConfigFile *cf = c->private;
1781 value_add_one( &c->rvalue_vals, &cf->c_file );
1790 config_cfdir(ConfigArgs *c) {
1791 if(c->op == SLAP_CONFIG_EMIT) {
1792 if ( !BER_BVISEMPTY( &cfdir )) {
1793 value_add_one( &c->rvalue_vals, &cfdir );
1802 config_search_base(ConfigArgs *c) {
1803 if(c->op == SLAP_CONFIG_EMIT) {
1805 if (!BER_BVISEMPTY(&default_search_base)) {
1806 value_add_one(&c->rvalue_vals, &default_search_base);
1807 value_add_one(&c->rvalue_nvals, &default_search_nbase);
1811 } else if( c->op == LDAP_MOD_DELETE ) {
1812 ch_free( default_search_base.bv_val );
1813 ch_free( default_search_nbase.bv_val );
1814 BER_BVZERO( &default_search_base );
1815 BER_BVZERO( &default_search_nbase );
1819 if(c->bi || c->be != frontendDB) {
1820 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
1821 "prior to any backend or database definition\n",
1826 if(default_search_nbase.bv_len) {
1827 free(default_search_base.bv_val);
1828 free(default_search_nbase.bv_val);
1831 default_search_base = c->value_dn;
1832 default_search_nbase = c->value_ndn;
1836 /* For RE23 compatibility we allow this in the global entry
1837 * but we now defer it to the frontend entry to allow modules
1838 * to load new hash types.
1841 config_passwd_hash(ConfigArgs *c) {
1843 if (c->op == SLAP_CONFIG_EMIT) {
1845 /* Don't generate it in the global entry */
1846 if ( c->table == Cft_Global )
1848 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
1849 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
1850 value_add_one(&c->rvalue_vals, &bv);
1853 } else if ( c->op == LDAP_MOD_DELETE ) {
1854 /* Deleting from global is a no-op, only the frontendDB entry matters */
1855 if ( c->table == Cft_Global )
1857 if ( c->valx < 0 ) {
1858 ldap_charray_free( default_passwd_hash );
1859 default_passwd_hash = NULL;
1862 ch_free( default_passwd_hash[i] );
1863 for (; default_passwd_hash[i]; i++ )
1864 default_passwd_hash[i] = default_passwd_hash[i+1];
1868 for(i = 1; i < c->argc; i++) {
1869 if(!lutil_passwd_scheme(c->argv[i])) {
1870 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> scheme not available", c->argv[0] );
1871 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1872 c->log, c->cr_msg, c->argv[i]);
1874 ldap_charray_add(&default_passwd_hash, c->argv[i]);
1877 if(!default_passwd_hash) {
1878 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> no valid hashes found", c->argv[0] );
1879 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1880 c->log, c->cr_msg, 0 );
1887 config_schema_dn(ConfigArgs *c) {
1888 if ( c->op == SLAP_CONFIG_EMIT ) {
1890 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
1891 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
1892 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
1896 } else if ( c->op == LDAP_MOD_DELETE ) {
1897 ch_free( c->be->be_schemadn.bv_val );
1898 ch_free( c->be->be_schemandn.bv_val );
1899 BER_BVZERO( &c->be->be_schemadn );
1900 BER_BVZERO( &c->be->be_schemandn );
1903 ch_free( c->be->be_schemadn.bv_val );
1904 ch_free( c->be->be_schemandn.bv_val );
1905 c->be->be_schemadn = c->value_dn;
1906 c->be->be_schemandn = c->value_ndn;
1911 config_sizelimit(ConfigArgs *c) {
1913 struct slap_limits_set *lim = &c->be->be_def_limit;
1914 if (c->op == SLAP_CONFIG_EMIT) {
1919 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
1920 if ( !BER_BVISEMPTY( &bv ))
1921 value_add_one( &c->rvalue_vals, &bv );
1925 } else if ( c->op == LDAP_MOD_DELETE ) {
1926 /* Reset to defaults */
1927 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
1928 lim->lms_s_hard = 0;
1929 lim->lms_s_unchecked = -1;
1931 lim->lms_s_pr_hide = 0;
1932 lim->lms_s_pr_total = 0;
1935 for(i = 1; i < c->argc; i++) {
1936 if(!strncasecmp(c->argv[i], "size", 4)) {
1937 rc = limits_parse_one(c->argv[i], lim);
1939 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
1940 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1941 c->log, c->cr_msg, c->argv[i]);
1945 if(!strcasecmp(c->argv[i], "unlimited")) {
1946 lim->lms_s_soft = -1;
1948 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
1949 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
1950 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1951 c->log, c->cr_msg, c->argv[i]);
1955 lim->lms_s_hard = 0;
1962 config_timelimit(ConfigArgs *c) {
1964 struct slap_limits_set *lim = &c->be->be_def_limit;
1965 if (c->op == SLAP_CONFIG_EMIT) {
1970 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
1971 if ( !BER_BVISEMPTY( &bv ))
1972 value_add_one( &c->rvalue_vals, &bv );
1976 } else if ( c->op == LDAP_MOD_DELETE ) {
1977 /* Reset to defaults */
1978 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
1979 lim->lms_t_hard = 0;
1982 for(i = 1; i < c->argc; i++) {
1983 if(!strncasecmp(c->argv[i], "time", 4)) {
1984 rc = limits_parse_one(c->argv[i], lim);
1986 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
1987 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1988 c->log, c->cr_msg, c->argv[i]);
1992 if(!strcasecmp(c->argv[i], "unlimited")) {
1993 lim->lms_t_soft = -1;
1995 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
1996 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
1997 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1998 c->log, c->cr_msg, c->argv[i]);
2002 lim->lms_t_hard = 0;
2009 config_overlay(ConfigArgs *c) {
2010 if (c->op == SLAP_CONFIG_EMIT) {
2012 } else if ( c->op == LDAP_MOD_DELETE ) {
2015 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2018 Debug( LDAP_DEBUG_ANY,
2019 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2020 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2022 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi)) {
2029 config_subordinate(ConfigArgs *c)
2035 case SLAP_CONFIG_EMIT:
2036 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2039 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2040 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2043 value_add_one( &c->rvalue_vals, &bv );
2047 case LDAP_MOD_DELETE:
2048 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2049 glue_sub_del( c->be );
2051 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2056 case SLAP_CONFIG_ADD:
2057 advertise = ( c->argc == 2 && !strcasecmp( c->argv[1], "advertise" ));
2058 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2065 config_suffix(ConfigArgs *c)
2068 struct berval pdn, ndn;
2069 char *notallowed = NULL;
2071 if ( c->be == frontendDB ) {
2072 notallowed = "frontend";
2074 } else if ( SLAP_MONITOR(c->be) ) {
2075 notallowed = "monitor";
2077 } else if ( SLAP_CONFIG(c->be) ) {
2078 notallowed = "config";
2081 if ( notallowed != NULL ) {
2082 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
2086 case LDAP_MOD_DELETE:
2087 case LDAP_MOD_REPLACE:
2088 case LDAP_MOD_INCREMENT:
2089 case SLAP_CONFIG_ADD:
2090 if ( !BER_BVISNULL( &c->value_dn ) ) {
2091 snprintf( buf, sizeof( buf ), "<%s> ",
2092 c->value_dn.bv_val );
2095 Debug(LDAP_DEBUG_ANY,
2096 "%s: suffix %snot allowed in %s database.\n",
2097 c->log, buf, notallowed );
2100 case SLAP_CONFIG_EMIT:
2101 /* don't complain when emitting... */
2105 /* FIXME: don't know what values may be valid;
2106 * please remove assertion, or add legal values
2107 * to either block */
2115 if (c->op == SLAP_CONFIG_EMIT) {
2116 if ( c->be->be_suffix == NULL
2117 || BER_BVISNULL( &c->be->be_suffix[0] ) )
2121 value_add( &c->rvalue_vals, c->be->be_suffix );
2122 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
2125 } else if ( c->op == LDAP_MOD_DELETE ) {
2126 if ( c->valx < 0 ) {
2127 ber_bvarray_free( c->be->be_suffix );
2128 ber_bvarray_free( c->be->be_nsuffix );
2129 c->be->be_suffix = NULL;
2130 c->be->be_nsuffix = NULL;
2133 ch_free( c->be->be_suffix[i].bv_val );
2134 ch_free( c->be->be_nsuffix[i].bv_val );
2136 c->be->be_suffix[i] = c->be->be_suffix[i+1];
2137 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
2139 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
2144 #ifdef SLAPD_MONITOR_DN
2145 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
2146 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> DN is reserved for monitoring slapd",
2148 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2149 c->log, c->cr_msg, SLAPD_MONITOR_DN);
2156 if (SLAP_DBHIDDEN( c->be ))
2159 tbe = select_backend(&ndn, 0);
2161 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
2167 BackendDB *b2 = tbe;
2169 /* Does tbe precede be? */
2170 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
2173 char *type = tbe->bd_info->bi_type;
2175 if ( overlay_is_over( tbe ) ) {
2176 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
2177 type = oi->oi_orig->bi_type;
2180 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> namingContext \"%s\" "
2181 "already served by a preceding %s database",
2182 c->argv[0], pdn.bv_val, type );
2183 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
2184 c->log, c->cr_msg, tbe->be_suffix[0].bv_val);
2190 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
2191 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
2192 "base provided \"%s\" (assuming okay)\n",
2193 c->log, default_search_base.bv_val, 0);
2195 ber_bvarray_add(&c->be->be_suffix, &pdn);
2196 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
2201 config_rootdn(ConfigArgs *c) {
2202 if (c->op == SLAP_CONFIG_EMIT) {
2203 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2204 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
2205 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
2210 } else if ( c->op == LDAP_MOD_DELETE ) {
2211 ch_free( c->be->be_rootdn.bv_val );
2212 ch_free( c->be->be_rootndn.bv_val );
2213 BER_BVZERO( &c->be->be_rootdn );
2214 BER_BVZERO( &c->be->be_rootndn );
2217 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2218 ch_free( c->be->be_rootdn.bv_val );
2219 ch_free( c->be->be_rootndn.bv_val );
2221 c->be->be_rootdn = c->value_dn;
2222 c->be->be_rootndn = c->value_ndn;
2227 config_rootpw(ConfigArgs *c) {
2230 if (c->op == SLAP_CONFIG_EMIT) {
2231 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
2232 /* don't copy, because "rootpw" is marked
2234 c->value_bv = c->be->be_rootpw;
2238 } else if ( c->op == LDAP_MOD_DELETE ) {
2239 ch_free( c->be->be_rootpw.bv_val );
2240 BER_BVZERO( &c->be->be_rootpw );
2244 tbe = select_backend(&c->be->be_rootndn, 0);
2246 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> can only be set when rootdn is under suffix",
2248 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2249 c->log, c->cr_msg, 0);
2252 if ( !BER_BVISNULL( &c->be->be_rootpw ))
2253 ch_free( c->be->be_rootpw.bv_val );
2254 c->be->be_rootpw = c->value_bv;
2259 config_restrict(ConfigArgs *c) {
2260 slap_mask_t restrictops = 0;
2262 slap_verbmasks restrictable_ops[] = {
2263 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
2264 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
2265 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
2266 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
2267 { BER_BVC("modrdn"), 0 },
2268 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
2269 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
2270 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
2271 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
2272 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
2273 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
2274 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
2275 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
2276 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
2277 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
2278 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
2282 if (c->op == SLAP_CONFIG_EMIT) {
2283 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
2285 } else if ( c->op == LDAP_MOD_DELETE ) {
2287 c->be->be_restrictops = 0;
2289 restrictops = verb_to_mask( c->line, restrictable_ops );
2290 c->be->be_restrictops ^= restrictops;
2294 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
2296 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown operation", c->argv[0] );
2297 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2298 c->log, c->cr_msg, c->argv[i]);
2301 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
2302 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
2303 c->be->be_restrictops |= restrictops;
2308 config_allows(ConfigArgs *c) {
2309 slap_mask_t allows = 0;
2311 slap_verbmasks allowable_ops[] = {
2312 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
2313 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
2314 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
2315 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
2316 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
2319 if (c->op == SLAP_CONFIG_EMIT) {
2320 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
2321 } else if ( c->op == LDAP_MOD_DELETE ) {
2325 allows = verb_to_mask( c->line, allowable_ops );
2326 global_allows ^= allows;
2330 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
2332 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
2333 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2334 c->log, c->cr_msg, c->argv[i]);
2337 global_allows |= allows;
2342 config_disallows(ConfigArgs *c) {
2343 slap_mask_t disallows = 0;
2345 slap_verbmasks disallowable_ops[] = {
2346 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
2347 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
2348 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
2349 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
2352 if (c->op == SLAP_CONFIG_EMIT) {
2353 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
2354 } else if ( c->op == LDAP_MOD_DELETE ) {
2356 global_disallows = 0;
2358 disallows = verb_to_mask( c->line, disallowable_ops );
2359 global_disallows ^= disallows;
2363 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
2365 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
2366 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2367 c->log, c->cr_msg, c->argv[i]);
2370 global_disallows |= disallows;
2375 config_requires(ConfigArgs *c) {
2376 slap_mask_t requires = frontendDB->be_requires;
2377 int i, argc = c->argc;
2378 char **argv = c->argv;
2380 slap_verbmasks requires_ops[] = {
2381 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
2382 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
2383 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
2384 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
2385 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
2388 if (c->op == SLAP_CONFIG_EMIT) {
2389 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
2390 } else if ( c->op == LDAP_MOD_DELETE ) {
2392 c->be->be_requires = 0;
2394 requires = verb_to_mask( c->line, requires_ops );
2395 c->be->be_requires ^= requires;
2399 /* "none" can only be first, to wipe out default/global values */
2400 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
2405 i = verbs_to_mask(argc, argv, requires_ops, &requires);
2407 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
2408 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
2409 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2410 c->log, c->cr_msg, 0);
2412 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
2413 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2414 c->log, c->cr_msg, c->argv[i]);
2418 c->be->be_requires = requires;
2422 static slap_verbmasks *loglevel_ops;
2425 loglevel_init( void )
2427 slap_verbmasks lo[] = {
2428 { BER_BVC("Any"), -1 },
2429 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
2430 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
2431 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
2432 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
2433 { BER_BVC("BER"), LDAP_DEBUG_BER },
2434 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
2435 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
2436 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
2437 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
2438 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
2439 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
2440 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
2441 #if 0 /* no longer used (nor supported) */
2442 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
2443 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
2445 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
2446 { BER_BVC("None"), LDAP_DEBUG_NONE },
2450 return slap_verbmasks_init( &loglevel_ops, lo );
2454 loglevel_destroy( void )
2456 if ( loglevel_ops ) {
2457 (void)slap_verbmasks_destroy( loglevel_ops );
2459 loglevel_ops = NULL;
2462 static slap_mask_t loglevel_ignore[] = { -1, 0 };
2465 slap_loglevel_register( slap_mask_t m, struct berval *s )
2469 if ( loglevel_ops == NULL ) {
2473 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
2476 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
2484 slap_loglevel_get( struct berval *s, int *l )
2489 if ( loglevel_ops == NULL ) {
2493 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
2494 m |= loglevel_ops[ i ].mask;
2497 for ( i = 1; m & i; i <<= 1 )
2504 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
2507 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
2518 str2loglevel( const char *s, int *l )
2522 if ( loglevel_ops == NULL ) {
2526 i = verb_to_mask( s, loglevel_ops );
2528 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
2532 *l = loglevel_ops[ i ].mask;
2538 loglevel2str( int l )
2540 struct berval bv = BER_BVNULL;
2542 loglevel2bv( l, &bv );
2548 loglevel2bv( int l, struct berval *bv )
2550 if ( loglevel_ops == NULL ) {
2556 return enum_to_verb( loglevel_ops, l, bv ) == -1;
2560 loglevel2bvarray( int l, BerVarray *bva )
2562 if ( loglevel_ops == NULL ) {
2566 return mask_to_verbs( loglevel_ops, l, bva );
2570 loglevel_print( FILE *out )
2574 if ( loglevel_ops == NULL ) {
2578 fprintf( out, "Installed log subsystems:\n\n" );
2579 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
2580 fprintf( out, "\t%-30s (%lu)\n",
2581 loglevel_ops[ i ].word.bv_val,
2582 loglevel_ops[ i ].mask );
2585 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
2586 "by specific code\n\n" );
2591 static int config_syslog;
2594 config_loglevel(ConfigArgs *c) {
2597 if ( loglevel_ops == NULL ) {
2601 if (c->op == SLAP_CONFIG_EMIT) {
2602 /* Get default or commandline slapd setting */
2603 if ( ldap_syslog && !config_syslog )
2604 config_syslog = ldap_syslog;
2605 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
2607 } else if ( c->op == LDAP_MOD_DELETE ) {
2611 int level = verb_to_mask( c->line, loglevel_ops );
2612 config_syslog ^= level;
2614 if ( slapMode & SLAP_SERVER_MODE ) {
2615 ldap_syslog = config_syslog;
2620 for( i=1; i < c->argc; i++ ) {
2623 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
2624 if( lutil_atoi( &level, c->argv[i] ) != 0 ) {
2625 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse level", c->argv[0] );
2626 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2627 c->log, c->cr_msg, c->argv[i]);
2631 if ( str2loglevel( c->argv[i], &level ) ) {
2632 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown level", c->argv[0] );
2633 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2634 c->log, c->cr_msg, c->argv[i]);
2638 /* Explicitly setting a zero clears all the levels */
2640 config_syslog |= level;
2644 if ( slapMode & SLAP_SERVER_MODE ) {
2645 ldap_syslog = config_syslog;
2651 config_referral(ConfigArgs *c) {
2653 if (c->op == SLAP_CONFIG_EMIT) {
2654 if ( default_referral ) {
2655 value_add( &c->rvalue_vals, default_referral );
2660 } else if ( c->op == LDAP_MOD_DELETE ) {
2661 if ( c->valx < 0 ) {
2662 ber_bvarray_free( default_referral );
2663 default_referral = NULL;
2666 ch_free( default_referral[i].bv_val );
2667 for (; default_referral[i].bv_val; i++ )
2668 default_referral[i] = default_referral[i+1];
2672 if(validate_global_referral(c->argv[1])) {
2673 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
2674 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2675 c->log, c->cr_msg, c->argv[1]);
2679 ber_str2bv(c->argv[1], 0, 0, &val);
2680 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
2688 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
2689 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
2690 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
2691 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
2692 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
2693 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
2694 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
2695 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
2696 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
2701 config_security(ConfigArgs *c) {
2702 slap_ssf_set_t *set = &c->be->be_ssf_set;
2705 if (c->op == SLAP_CONFIG_EMIT) {
2711 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
2712 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
2715 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
2716 if ( bv.bv_len >= sizeof( numbuf ) ) {
2717 ber_bvarray_free_x( c->rvalue_vals, NULL );
2718 c->rvalue_vals = NULL;
2722 bv.bv_len += sec_keys[i].key.bv_len;
2723 bv.bv_val = ch_malloc( bv.bv_len + 1);
2724 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
2725 strcpy( next, numbuf );
2726 ber_bvarray_add( &c->rvalue_vals, &bv );
2731 for(i = 1; i < c->argc; i++) {
2732 slap_ssf_t *tgt = NULL;
2734 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
2735 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
2736 sec_keys[j].key.bv_len)) {
2737 src = c->argv[i] + sec_keys[j].key.bv_len;
2738 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
2743 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown factor", c->argv[0] );
2744 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2745 c->log, c->cr_msg, c->argv[i]);
2749 if ( lutil_atou( tgt, src ) != 0 ) {
2750 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse factor", c->argv[0] );
2751 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2752 c->log, c->cr_msg, c->argv[i]);
2760 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
2764 for (; !BER_BVISNULL( &an->an_name ); an++) {
2765 /* if buflen == 0, assume the buffer size has been
2766 * already checked otherwise */
2767 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
2768 if ( comma ) *ptr++ = ',';
2769 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
2776 config_updatedn(ConfigArgs *c) {
2777 if (c->op == SLAP_CONFIG_EMIT) {
2778 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
2779 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
2780 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
2784 } else if ( c->op == LDAP_MOD_DELETE ) {
2785 ch_free( c->be->be_update_ndn.bv_val );
2786 BER_BVZERO( &c->be->be_update_ndn );
2787 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
2790 if(SLAP_SHADOW(c->be)) {
2791 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database already shadowed", c->argv[0] );
2792 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2793 c->log, c->cr_msg, 0);
2797 ber_memfree_x( c->value_dn.bv_val, NULL );
2798 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
2799 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
2801 c->be->be_update_ndn = c->value_ndn;
2802 BER_BVZERO( &c->value_dn );
2803 BER_BVZERO( &c->value_ndn );
2805 return config_slurp_shadow( c );
2809 config_shadow( ConfigArgs *c, int flag )
2811 char *notallowed = NULL;
2813 if ( c->be == frontendDB ) {
2814 notallowed = "frontend";
2816 } else if ( SLAP_MONITOR(c->be) ) {
2817 notallowed = "monitor";
2820 if ( notallowed != NULL ) {
2821 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
2825 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SINGLE_SHADOW | flag);
2831 config_updateref(ConfigArgs *c) {
2833 if (c->op == SLAP_CONFIG_EMIT) {
2834 if ( c->be->be_update_refs ) {
2835 value_add( &c->rvalue_vals, c->be->be_update_refs );
2840 } else if ( c->op == LDAP_MOD_DELETE ) {
2841 if ( c->valx < 0 ) {
2842 ber_bvarray_free( c->be->be_update_refs );
2843 c->be->be_update_refs = NULL;
2846 ch_free( c->be->be_update_refs[i].bv_val );
2847 for (; c->be->be_update_refs[i].bv_val; i++)
2848 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
2852 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
2853 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must appear after syncrepl or updatedn",
2855 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2856 c->log, c->cr_msg, 0);
2860 if(validate_global_referral(c->argv[1])) {
2861 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
2862 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2863 c->log, c->cr_msg, c->argv[1]);
2866 ber_str2bv(c->argv[1], 0, 0, &val);
2867 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
2872 config_obsolete(ConfigArgs *c) {
2873 if (c->op == SLAP_CONFIG_EMIT)
2876 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> keyword is obsolete (ignored)",
2878 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0);
2883 config_include(ConfigArgs *c) {
2884 int savelineno = c->lineno;
2887 ConfigFile *cfsave = cfn;
2888 ConfigFile *cf2 = NULL;
2890 /* Leftover from RE23. No dynamic config for include files */
2891 if ( c->op == SLAP_CONFIG_EMIT || c->op == LDAP_MOD_DELETE )
2894 cf = ch_calloc( 1, sizeof(ConfigFile));
2895 if ( cfn->c_kids ) {
2896 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
2902 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
2903 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
2904 c->lineno = savelineno - 1;
2907 if ( cf2 ) cf2->c_sibs = NULL;
2908 else cfn->c_kids = NULL;
2909 ch_free( cf->c_file.bv_val );
2919 config_tls_option(ConfigArgs *c) {
2921 LDAP *ld = slap_tls_ld;
2923 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
2924 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
2925 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
2926 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
2927 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
2928 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
2929 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
2931 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
2933 default: Debug(LDAP_DEBUG_ANY, "%s: "
2934 "unknown tls_option <0x%x>\n",
2935 c->log, c->type, 0);
2938 if (c->op == SLAP_CONFIG_EMIT) {
2939 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
2940 } else if ( c->op == LDAP_MOD_DELETE ) {
2941 return ldap_pvt_tls_set_option( ld, flag, NULL );
2943 ch_free(c->value_string);
2944 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
2947 /* FIXME: this ought to be provided by libldap */
2949 config_tls_config(ConfigArgs *c) {
2952 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
2953 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
2955 Debug(LDAP_DEBUG_ANY, "%s: "
2956 "unknown tls_option <0x%x>\n",
2957 c->log, c->type, 0);
2960 if (c->op == SLAP_CONFIG_EMIT) {
2961 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
2962 } else if ( c->op == LDAP_MOD_DELETE ) {
2964 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
2966 ch_free( c->value_string );
2967 if ( isdigit( (unsigned char)c->argv[1][0] ) ) {
2968 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
2969 Debug(LDAP_DEBUG_ANY, "%s: "
2970 "unable to parse %s \"%s\"\n",
2971 c->log, c->argv[0], c->argv[1] );
2974 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
2976 return(ldap_int_tls_config(slap_tls_ld, flag, c->argv[1]));
2981 static CfEntryInfo *
2982 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
2992 if ( dn_match( &root->ce_entry->e_nname, dn ))
2995 c = dn->bv_val+dn->bv_len;
2996 for (;*c != ',';c--);
3000 for (--c;c>dn->bv_val && *c != ',';c--);
3004 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
3006 root = root->ce_kids;
3008 for (;root;root=root->ce_sibs) {
3009 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
3010 if ( cdn.bv_val == dn->bv_val ) {
3020 typedef struct setup_cookie {
3030 config_ldif_resp( Operation *op, SlapReply *rs )
3032 if ( rs->sr_type == REP_SEARCH ) {
3033 setup_cookie *sc = op->o_callback->sc_private;
3035 sc->cfb->cb_got_ldif = 1;
3036 /* Does the frontend exist? */
3037 if ( !sc->got_frontend ) {
3038 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
3039 "olcDatabase", STRLENOF( "olcDatabase" ))) {
3040 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3041 STRLENOF( "olcDatabase" ), "={-1}frontend",
3042 STRLENOF( "={-1}frontend" ))) {
3045 sc->ca->be = frontendDB;
3046 sc->ca->bi = frontendDB->bd_info;
3047 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
3048 rdn.bv_val = sc->ca->log;
3049 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3050 "%s=" SLAP_X_ORDERED_FMT "%s",
3051 cfAd_database->ad_cname.bv_val, -1,
3052 sc->ca->bi->bi_type);
3054 sc->frontend = config_build_entry( op, rs,
3055 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
3056 sc->ca->be->be_cf_ocs );
3065 /* Does the configDB exist? */
3066 if ( sc->got_frontend && !sc->got_config &&
3067 !strncmp( rs->sr_entry->e_nname.bv_val,
3068 "olcDatabase", STRLENOF( "olcDatabase" ))) {
3069 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3070 STRLENOF( "olcDatabase" ), "={0}config",
3071 STRLENOF( "={0}config" ))) {
3074 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
3075 sc->ca->bi = sc->ca->be->bd_info;
3076 rdn.bv_val = sc->ca->log;
3077 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3078 "%s=" SLAP_X_ORDERED_FMT "%s",
3079 cfAd_database->ad_cname.bv_val, 0,
3080 sc->ca->bi->bi_type);
3082 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
3083 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
3090 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
3091 if ( rs->sr_err != LDAP_SUCCESS ) {
3092 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
3093 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg, 0 );
3099 /* Configure and read the underlying back-ldif store */
3101 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
3102 CfBackInfo *cfb = be->be_private;
3108 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
3109 Connection conn = {0};
3110 OperationBuffer opbuf;
3112 SlapReply rs = {REP_RESULT};
3113 Filter filter = { LDAP_FILTER_PRESENT };
3114 struct berval filterstr = BER_BVC("(objectclass=*)");
3117 /* Is the config directory available? */
3118 if ( stat( dir, &st ) < 0 ) {
3119 /* No, so don't bother using the backing store.
3120 * All changes will be in-memory only.
3125 cfb->cb_db.bd_info = backend_info( "ldif" );
3126 if ( !cfb->cb_db.bd_info )
3127 return 0; /* FIXME: eventually this will be a fatal error */
3129 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
3132 cfb->cb_db.be_suffix = be->be_suffix;
3133 cfb->cb_db.be_nsuffix = be->be_nsuffix;
3135 /* The suffix is always "cn=config". The underlying DB's rootdn
3136 * is always the same as the suffix.
3138 cfb->cb_db.be_rootdn = be->be_suffix[0];
3139 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
3141 ber_str2bv( dir, 0, 1, &cfdir );
3146 argv[0] = "directory";
3147 argv[1] = (char *)dir;
3152 c.table = Cft_Database;
3154 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
3158 if ( config_add_vals( ct, &c ))
3161 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
3165 void *thrctx = ldap_pvt_thread_pool_context();
3168 connection_fake_init( &conn, &opbuf, thrctx );
3171 filter.f_desc = slap_schema.si_ad_objectClass;
3173 op->o_tag = LDAP_REQ_SEARCH;
3175 op->ors_filter = &filter;
3176 op->ors_filterstr = filterstr;
3177 op->ors_scope = LDAP_SCOPE_SUBTREE;
3179 op->o_dn = c.be->be_rootdn;
3180 op->o_ndn = c.be->be_rootndn;
3182 op->o_req_dn = be->be_suffix[0];
3183 op->o_req_ndn = be->be_nsuffix[0];
3185 op->ors_tlimit = SLAP_NO_LIMIT;
3186 op->ors_slimit = SLAP_NO_LIMIT;
3188 op->ors_attrs = slap_anlist_all_attributes;
3189 op->ors_attrsonly = 0;
3191 op->o_callback = &cb;
3194 cb.sc_private = ≻
3195 sc.got_frontend = 0;
3200 op->o_bd = &cfb->cb_db;
3202 /* Allow unknown attrs in DNs */
3203 prev_DN_strict = slap_DN_strict;
3206 rc = op->o_bd->be_search( op, &rs );
3208 /* Restore normal DN validation */
3209 slap_DN_strict = prev_DN_strict;
3211 op->o_tag = LDAP_REQ_ADD;
3212 if ( rc == LDAP_SUCCESS && sc.frontend ) {
3213 op->ora_e = sc.frontend;
3214 rc = op->o_bd->be_add( op, &rs );
3216 if ( rc == LDAP_SUCCESS && sc.config ) {
3217 op->ora_e = sc.config;
3218 rc = op->o_bd->be_add( op, &rs );
3220 ldap_pvt_thread_pool_context_reset( thrctx );
3223 /* ITS#4194 - only use if it's present, or we're converting. */
3224 if ( !readit || rc == LDAP_SUCCESS )
3225 cfb->cb_use_ldif = 1;
3231 CfOc_cmp( const void *c1, const void *c2 ) {
3232 const ConfigOCs *co1 = c1;
3233 const ConfigOCs *co2 = c2;
3235 return ber_bvcmp( co1->co_name, co2->co_name );
3239 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
3242 i = init_config_attrs( ct );
3245 /* set up the objectclasses */
3246 i = init_config_ocs( ocs );
3249 for (i=0; ocs[i].co_def; i++) {
3250 if ( ocs[i].co_oc ) {
3251 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
3252 if ( !ocs[i].co_table )
3253 ocs[i].co_table = ct;
3254 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
3261 read_config(const char *fname, const char *dir) {
3264 const char *cfdir, *cfname;
3267 /* Setup the config backend */
3268 be = backend_db_init( "config", NULL, 0, NULL );
3272 cfb = be->be_private;
3273 be->be_dfltaccess = ACL_NONE;
3275 /* If no .conf, or a dir was specified, setup the dir */
3276 if ( !fname || dir ) {
3278 /* If explicitly given, check for existence */
3281 if ( stat( dir, &st ) < 0 ) {
3282 Debug( LDAP_DEBUG_ANY,
3283 "invalid config directory %s, error %d\n",
3289 cfdir = SLAPD_DEFAULT_CONFIGDIR;
3291 /* if fname is defaulted, try reading .d */
3292 rc = config_setup_ldif( be, cfdir, !fname );
3295 /* It may be OK if the base object doesn't exist yet. */
3296 if ( rc != LDAP_NO_SUCH_OBJECT )
3298 /* ITS#4194: But if dir was specified and no fname,
3299 * then we were supposed to read the dir. Unless we're
3300 * trying to slapadd the dir...
3302 if ( dir && !fname ) {
3303 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
3305 /* Assume it's slapadd with a config dir, let it continue */
3307 cfb->cb_got_ldif = 1;
3308 cfb->cb_use_ldif = 1;
3313 /* If we read the config from back-ldif, nothing to do here */
3314 if ( cfb->cb_got_ldif ) {
3323 cfname = SLAPD_DEFAULT_CONFIGFILE;
3325 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
3328 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
3331 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
3332 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
3333 &frontendDB->be_schemadn );
3334 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
3335 if ( rc != LDAP_SUCCESS ) {
3336 Debug(LDAP_DEBUG_ANY, "read_config: "
3337 "unable to normalize default schema DN \"%s\"\n",
3338 frontendDB->be_schemadn.bv_val, 0, 0 );
3339 /* must not happen */
3347 config_back_bind( Operation *op, SlapReply *rs )
3349 if ( be_isroot_pw( op ) ) {
3350 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
3351 /* frontend sends result */
3352 return LDAP_SUCCESS;
3355 rs->sr_err = LDAP_INVALID_CREDENTIALS;
3356 send_ldap_result( op, rs );
3362 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
3366 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
3368 rs->sr_attrs = op->ors_attrs;
3369 rs->sr_entry = ce->ce_entry;
3371 rc = send_search_entry( op, rs );
3373 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
3374 if ( ce->ce_kids ) {
3375 rc = config_send( op, rs, ce->ce_kids, 1 );
3376 if ( rc ) return rc;
3379 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
3380 rc = config_send( op, rs, ce, 0 );
3388 static ConfigTable *
3389 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
3394 for (j=0; j<nocs; j++) {
3395 for (i=0; colst[j]->co_table[i].name; i++)
3396 if ( colst[j]->co_table[i].ad == ad ) {
3397 ca->table = colst[j]->co_type;
3398 return &colst[j]->co_table[i];
3404 /* Sort the attributes of the entry according to the order defined
3405 * in the objectclass, with required attributes occurring before
3406 * allowed attributes. For any attributes with sequencing dependencies
3407 * (e.g., rootDN must be defined after suffix) the objectclass must
3408 * list the attributes in the desired sequence.
3411 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
3413 Attribute *a, *head = NULL, *tail = NULL, **prev;
3416 for (i=0; i<nocs; i++) {
3417 if ( colst[i]->co_oc->soc_required ) {
3418 AttributeType **at = colst[i]->co_oc->soc_required;
3419 for (j=0; at[j]; j++) {
3420 for (a=e->e_attrs, prev=&e->e_attrs; a;
3421 prev = &(*prev)->a_next, a=a->a_next) {
3422 if ( a->a_desc == at[j]->sat_ad ) {
3436 if ( colst[i]->co_oc->soc_allowed ) {
3437 AttributeType **at = colst[i]->co_oc->soc_allowed;
3438 for (j=0; at[j]; j++) {
3439 for (a=e->e_attrs, prev=&e->e_attrs; a;
3440 prev = &(*prev)->a_next, a=a->a_next) {
3441 if ( a->a_desc == at[j]->sat_ad ) {
3457 tail->a_next = e->e_attrs;
3463 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
3465 Attribute *a = NULL;
3466 AttributeDescription *ad;
3476 Modifications *ml = ptr;
3478 vals = ml->sml_values;
3481 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
3482 rc = ordered_value_sort( a, 1 );
3484 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
3485 ad->ad_cname.bv_val );
3489 for ( i=0; vals[i].bv_val; i++ ) {
3490 ca->line = vals[i].bv_val;
3491 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
3492 ca->line[0] == '{' ) {
3493 char *idx = strchr( ca->line, '}' );
3494 if ( idx ) ca->line = idx+1;
3496 rc = config_parse_vals( ct, ca, i );
3505 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
3508 struct berval rtype, rval;
3510 AttributeDescription *ad = NULL;
3512 dnRdn( &e->e_name, rdn );
3513 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
3514 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
3515 rtype.bv_val = rdn->bv_val;
3516 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
3519 slap_bv2ad( &rtype, &ad, &rs->sr_text );
3520 a = attr_find( e->e_attrs, ad );
3521 if (!a ) return LDAP_NAMING_VIOLATION;
3528 config_rename_kids( CfEntryInfo *ce )
3531 struct berval rdn, nrdn;
3533 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
3534 dnRdn ( &ce2->ce_entry->e_name, &rdn );
3535 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
3536 free( ce2->ce_entry->e_name.bv_val );
3537 free( ce2->ce_entry->e_nname.bv_val );
3538 build_new_dn( &ce2->ce_entry->e_name, &ce->ce_entry->e_name,
3540 build_new_dn( &ce2->ce_entry->e_nname, &ce->ce_entry->e_nname,
3542 config_rename_kids( ce2 );
3547 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
3548 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
3549 struct berval *nnewrdn, int use_ldif )
3553 struct berval odn, ondn;
3557 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
3558 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
3561 free( a->a_vals[0].bv_val );
3562 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
3563 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
3564 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
3565 strcpy( a->a_vals[0].bv_val, ptr1 );
3567 if ( a->a_nvals != a->a_vals ) {
3568 free( a->a_nvals[0].bv_val );
3569 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
3570 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
3571 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
3572 strcpy( a->a_nvals[0].bv_val, ptr1 );
3575 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
3576 BackendDB *be = op->o_bd;
3577 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
3578 struct berval dn, ndn, xdn, xndn;
3580 op->o_bd = &cfb->cb_db;
3582 /* Save current rootdn; use the underlying DB's rootdn */
3586 xndn = op->o_req_ndn;
3587 op->o_dn = op->o_bd->be_rootdn;
3588 op->o_ndn = op->o_bd->be_rootndn;
3590 op->o_req_ndn = ondn;
3592 scp = op->o_callback;
3593 op->o_callback = ≻
3594 op->orr_newrdn = *newrdn;
3595 op->orr_nnewrdn = *nnewrdn;
3596 op->orr_newSup = NULL;
3597 op->orr_nnewSup = NULL;
3598 op->orr_deleteoldrdn = 1;
3599 op->orr_modlist = NULL;
3600 slap_modrdn2mods( op, rs );
3601 slap_mods_opattrs( op, &op->orr_modlist, 1 );
3602 rc = op->o_bd->be_modrdn( op, rs );
3603 slap_mods_free( op->orr_modlist, 1 );
3606 op->o_callback = scp;
3610 op->o_req_ndn = xndn;
3613 free( ondn.bv_val );
3615 config_rename_kids( e->e_private );
3620 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
3621 Entry *e, int idx, int tailindex, int use_ldif )
3623 struct berval ival, newrdn, nnewrdn;
3626 char ibuf[32], *ptr1, *ptr2 = NULL;
3629 rc = config_rename_attr( rs, e, &rdn, &a );
3630 if ( rc ) return rc;
3633 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
3634 if ( ival.bv_len >= sizeof( ibuf ) ) {
3635 return LDAP_NAMING_VIOLATION;
3638 newrdn.bv_len = rdn.bv_len + ival.bv_len;
3639 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
3642 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
3643 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3646 ptr2 = ber_bvchr( &rdn, '}' );
3650 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
3652 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
3653 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
3654 a->a_desc->ad_cname.bv_len );
3656 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3657 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
3661 /* Do the equivalent of ModRDN */
3662 /* Replace DN / NDN */
3663 newrdn.bv_len = ptr1 - newrdn.bv_val;
3664 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
3665 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
3667 free( nnewrdn.bv_val );
3668 free( newrdn.bv_val );
3673 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
3674 SlapReply *rs, int *renum, int *ibase )
3677 int index = -1, gotindex = 0, nsibs, rc = 0;
3678 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
3679 char *ptr1, *ptr2 = NULL;
3682 if ( renum ) *renum = 0;
3684 /* These entries don't get indexed/renumbered */
3685 if ( ce_type == Cft_Global ) return 0;
3686 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
3688 if ( ce_type == Cft_Module )
3691 /* See if the rdn has an index already */
3692 dnRdn( &e->e_name, &rdn );
3693 if ( ce_type == Cft_Database ) {
3694 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
3695 "frontend", STRLENOF("frontend") ))
3697 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
3698 "config", STRLENOF("config") ))
3701 ptr1 = ber_bvchr( &e->e_name, '{' );
3702 if ( ptr1 && ptr1 - e->e_name.bv_val < rdn.bv_len ) {
3704 ptr2 = strchr( ptr1, '}' );
3705 if (!ptr2 || ptr2 - e->e_name.bv_val > rdn.bv_len)
3706 return LDAP_NAMING_VIOLATION;
3707 if ( ptr2-ptr1 == 1)
3708 return LDAP_NAMING_VIOLATION;
3710 index = strtol( ptr1 + 1, &next, 10 );
3711 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
3712 return LDAP_NAMING_VIOLATION;
3715 /* Special case, we allow -1 for the frontendDB */
3716 if ( index != -1 || !isfrontend )
3717 return LDAP_NAMING_VIOLATION;
3719 if ( isconfig && index != 0 ){
3720 return LDAP_NAMING_VIOLATION;
3724 /* count related kids */
3725 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
3726 if ( ce->ce_type == ce_type ) nsibs++;
3729 /* account for -1 frontend */
3730 if ( ce_type == Cft_Database )
3733 if ( index != nsibs ) {
3735 if ( index < nsibs ) {
3736 if ( tailindex ) return LDAP_NAMING_VIOLATION;
3737 /* Siblings need to be renumbered */
3738 if ( index != -1 || !isfrontend )
3742 /* config DB is always "0" */
3743 if ( isconfig && index == -1 ) {
3746 if ( !isfrontend && index == -1 ) {
3750 /* just make index = nsibs */
3752 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
3755 if ( ibase ) *ibase = index;
3756 if ( renum ) *renum = renumber;
3761 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
3766 co.co_name = &oc->soc_cname;
3767 cop = avl_find( CfOcTree, &co, CfOc_cmp );
3771 /* check for duplicates */
3772 for ( i = 0; i < *nocs; i++ ) {
3773 if ( *copp && (*copp)[i] == cop ) {
3779 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
3780 if ( tmp == NULL ) {
3784 (*copp)[*nocs] = cop;
3789 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
3790 if ( count_oc( *sups, copp, nocs ) ) {
3799 count_ocs( Attribute *oc_at, int *nocs )
3802 ConfigOCs **colst = NULL;
3806 for ( i = 0; !BER_BVISNULL( &oc_at->a_nvals[i] ); i++ )
3810 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
3812 assert( oc != NULL );
3813 if ( count_oc( oc, &colst, nocs ) ) {
3823 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
3825 /* Leftover from RE23. Never parse this entry */
3826 return LDAP_COMPARE_TRUE;
3830 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
3834 /* This entry is hardcoded, don't re-parse it */
3835 if ( p->ce_type == Cft_Global ) {
3836 cfn = p->ce_private;
3838 return LDAP_COMPARE_TRUE;
3840 if ( p->ce_type != Cft_Schema )
3841 return LDAP_CONSTRAINT_VIOLATION;
3843 cfn = ch_calloc( 1, sizeof(ConfigFile) );
3845 cfo = p->ce_private;
3846 cfn->c_sibs = cfo->c_kids;
3848 return LDAP_SUCCESS;
3852 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3854 if ( p->ce_type != Cft_Global ) {
3855 return LDAP_CONSTRAINT_VIOLATION;
3857 ca->be = frontendDB; /* just to get past check_vals */
3858 return LDAP_SUCCESS;
3862 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3864 if ( p->ce_type != Cft_Global ) {
3865 return LDAP_CONSTRAINT_VIOLATION;
3867 return LDAP_SUCCESS;
3871 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3873 if ( p->ce_type != Cft_Global ) {
3874 return LDAP_CONSTRAINT_VIOLATION;
3876 return LDAP_SUCCESS;
3880 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3882 if ( p->ce_type != Cft_Database ) {
3883 return LDAP_CONSTRAINT_VIOLATION;
3886 return LDAP_SUCCESS;
3890 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
3895 AttributeDescription *ad;
3900 if ( cfn->c_cr_head ) {
3901 struct berval bv = BER_BVC("olcDitContentRules");
3903 slap_bv2ad( &bv, &ad, &text );
3904 ct = config_find_table( colst, nocs, ad, ca );
3905 config_del_vals( ct, ca );
3907 if ( cfn->c_oc_head ) {
3908 struct berval bv = BER_BVC("olcObjectClasses");
3910 slap_bv2ad( &bv, &ad, &text );
3911 ct = config_find_table( colst, nocs, ad, ca );
3912 config_del_vals( ct, ca );
3914 if ( cfn->c_at_head ) {
3915 struct berval bv = BER_BVC("olcAttributeTypes");
3917 slap_bv2ad( &bv, &ad, &text );
3918 ct = config_find_table( colst, nocs, ad, ca );
3919 config_del_vals( ct, ca );
3921 if ( cfn->c_om_head ) {
3922 struct berval bv = BER_BVC("olcObjectIdentifier");
3924 slap_bv2ad( &bv, &ad, &text );
3925 ct = config_find_table( colst, nocs, ad, ca );
3926 config_del_vals( ct, ca );
3928 cfo = p->ce_private;
3929 cfo->c_kids = cfn->c_sibs;
3934 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
3936 int rc = LDAP_CONSTRAINT_VIOLATION;
3939 if ( (*cop)->co_ldadd ) {
3940 rc = (*cop)->co_ldadd( last, e, ca );
3941 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
3946 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
3947 ConfigOCs co = { 0 };
3949 co.co_name = &(*ocp)->soc_cname;
3950 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
3951 if ( *cop == NULL ) {
3955 rc = config_add_oc( cop, last, e, ca );
3956 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
3964 /* Parse an LDAP entry into config directives */
3966 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
3967 int *renum, Operation *op )
3969 CfEntryInfo *ce, *last = NULL;
3970 ConfigOCs co, *coptr, **colst;
3971 Attribute *a, *oc_at, *soc_at;
3972 int i, ibase = -1, nocs, rc = 0;
3975 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
3977 memset( ca, 0, sizeof(ConfigArgs));
3979 /* Make sure parent exists and entry does not. But allow
3980 * Databases and Overlays to be inserted. Don't do any
3981 * auto-renumbering if manageDSAit control is present.
3983 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
3985 if ( ( op && op->o_managedsait ) ||
3986 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
3987 ce->ce_type != Cft_Module ) )
3989 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
3990 "DN=\"%s\" already exists\n",
3991 log_prefix, e->e_name.bv_val, 0 );
3992 return LDAP_ALREADY_EXISTS;
3996 dnParent( &e->e_nname, &pdn );
3998 /* If last is NULL, the new entry is the root/suffix entry,
3999 * otherwise last should be the parent.
4001 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
4003 rs->sr_matched = last->ce_entry->e_name.bv_val;
4005 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4006 "DN=\"%s\" not child of DN=\"%s\"\n",
4007 log_prefix, e->e_name.bv_val,
4008 last->ce_entry->e_name.bv_val );
4009 return LDAP_NO_SUCH_OBJECT;
4013 /* No parent, must be root. This will never happen... */
4014 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
4015 return LDAP_NO_SUCH_OBJECT;
4018 if ( last && !access_allowed( op, last->ce_entry,
4019 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
4021 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4022 "DN=\"%s\" no write access to \"children\" of parent\n",
4023 log_prefix, e->e_name.bv_val, 0 );
4024 return LDAP_INSUFFICIENT_ACCESS;
4028 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4030 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4031 "DN=\"%s\" no objectClass\n",
4032 log_prefix, e->e_name.bv_val, 0 );
4033 return LDAP_OBJECT_CLASS_VIOLATION;
4036 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4038 ObjectClass *soc = NULL;
4039 char textbuf[ SLAP_TEXT_BUFLEN ];
4040 const char *text = textbuf;
4042 /* FIXME: check result */
4043 rc = structural_class( oc_at->a_nvals, &soc, NULL,
4044 &text, textbuf, sizeof(textbuf), NULL );
4045 if ( rc != LDAP_SUCCESS ) {
4046 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4047 "DN=\"%s\" no structural objectClass (%s)\n",
4048 log_prefix, e->e_name.bv_val, text );
4051 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
4052 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4053 if ( soc_at == NULL ) {
4054 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4055 "DN=\"%s\" no structural objectClass; "
4056 "unable to merge computed class %s\n",
4057 log_prefix, e->e_name.bv_val,
4058 soc->soc_cname.bv_val );
4059 return LDAP_OBJECT_CLASS_VIOLATION;
4062 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4063 "DN=\"%s\" no structural objectClass; "
4064 "computed objectClass %s merged\n",
4065 log_prefix, e->e_name.bv_val,
4066 soc->soc_cname.bv_val );
4069 /* Fake the coordinates based on whether we're part of an
4070 * LDAP Add or if reading the config dir
4073 ca->fname = "slapd";
4076 ca->fname = cfdir.bv_val;
4081 co.co_name = &soc_at->a_nvals[0];
4082 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
4083 if ( coptr == NULL ) {
4084 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4085 "DN=\"%s\" no structural objectClass in configuration table\n",
4086 log_prefix, e->e_name.bv_val, 0 );
4087 return LDAP_OBJECT_CLASS_VIOLATION;
4090 /* Only the root can be Cft_Global, everything else must
4091 * have a parent. Only limited nesting arrangements are allowed.
4093 rc = LDAP_CONSTRAINT_VIOLATION;
4094 if ( coptr->co_type == Cft_Global && !last ) {
4095 cfn = cfb->cb_config;
4097 ca->be = frontendDB; /* just to get past check_vals */
4101 /* Check whether the Add is allowed by its parent, and do
4102 * any necessary arg setup
4105 rc = config_add_oc( &coptr, last, e, ca );
4106 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4107 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4108 "DN=\"%s\" no structural objectClass add function\n",
4109 log_prefix, e->e_name.bv_val, 0 );
4110 return LDAP_OBJECT_CLASS_VIOLATION;
4114 colst = count_ocs( oc_at, &nocs );
4116 /* Add the entry but don't parse it, we already have its contents */
4117 if ( rc == LDAP_COMPARE_TRUE ) {
4122 if ( rc != LDAP_SUCCESS )
4125 /* Parse all the values and check for simple syntax errors before
4126 * performing any set actions.
4128 * If doing an LDAPadd, check for indexed names and any necessary
4129 * renaming/renumbering. Entries that don't need indexed names are
4130 * ignored. Entries that need an indexed name and arrive without one
4131 * are assigned to the end. Entries that arrive with an index may
4132 * cause the following entries to be renumbered/bumped down.
4134 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
4135 * don't allow Adding an entry with an index that's already in use.
4136 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
4138 * These entries can have auto-assigned indexes (appended to the end)
4139 * but only the other types support auto-renumbering of siblings.
4142 rc = check_name_index( last, coptr->co_type, e, rs, renum,
4147 if ( renum && *renum && coptr->co_type != Cft_Database &&
4148 coptr->co_type != Cft_Overlay )
4150 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
4151 "operation requires sibling renumbering" );
4152 rc = LDAP_UNWILLING_TO_PERFORM;
4157 init_config_argv( ca );
4159 /* Make sure we process attrs in the required order */
4160 sort_attrs( e, colst, nocs );
4162 for ( a = e->e_attrs; a; a = a->a_next ) {
4163 if ( a == oc_at ) continue;
4164 ct = config_find_table( colst, nocs, a->a_desc, ca );
4165 if ( !ct ) continue; /* user data? */
4166 rc = check_vals( ct, ca, a, 1 );
4167 if ( rc ) goto done_noop;
4170 /* Basic syntax checks are OK. Do the actual settings. */
4171 for ( a=e->e_attrs; a; a=a->a_next ) {
4172 if ( a == oc_at ) continue;
4173 ct = config_find_table( colst, nocs, a->a_desc, ca );
4174 if ( !ct ) continue; /* user data? */
4175 for (i=0; a->a_vals[i].bv_val; i++) {
4177 ca->line = a->a_vals[i].bv_val;
4178 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
4179 ptr = strchr( ca->line, '}' );
4181 iptr = strchr( ca->line, '{' );
4185 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
4187 ca->valx = strtol( iptr+1, NULL, 0 );
4194 rc = config_parse_add( ct, ca, i );
4202 /* Newly added databases and overlays need to be started up */
4203 if ( CONFIG_ONLINE_ADD( ca )) {
4204 if ( colst[0]->co_type == Cft_Database ) {
4205 rc = backend_startup_one( ca->be, &ca->reply );
4207 } else if ( colst[0]->co_type == Cft_Overlay ) {
4208 if ( ca->bi->bi_db_open ) {
4209 BackendInfo *bi_orig = ca->be->bd_info;
4210 ca->be->bd_info = ca->bi;
4211 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
4212 ca->be->bd_info = bi_orig;
4216 if (ca->cr_msg[0] == '\0')
4217 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
4219 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
4220 ca->log, ca->cr_msg, ca->argv[1] );
4227 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
4228 ce->ce_parent = last;
4229 ce->ce_entry = entry_dup( e );
4230 ce->ce_entry->e_private = ce;
4231 ce->ce_type = colst[0]->co_type;
4234 ce->ce_private = ca->private;
4235 ca->ca_entry = ce->ce_entry;
4238 } else if ( last->ce_kids ) {
4239 CfEntryInfo *c2, **cprev;
4241 /* Advance to first of this type */
4242 cprev = &last->ce_kids;
4243 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
4244 cprev = &c2->ce_sibs;
4247 /* Account for the (-1) frontendDB entry */
4248 if ( ce->ce_type == Cft_Database ) {
4249 if ( ca->be == frontendDB )
4251 else if ( ibase != -1 )
4256 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
4257 cprev = &c2->ce_sibs;
4263 for ( i=0; i<ibase; i++ ) {
4265 cprev = &c2->ce_sibs;
4268 ce->ce_sibs = *cprev;
4276 if ( (colst[0]->co_type == Cft_Database) && ca->be ) {
4277 if ( ca->be != frontendDB )
4278 backend_destroy_one( ca->be, 1 );
4279 } else if ( (colst[0]->co_type == Cft_Overlay) && ca->bi ) {
4280 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
4281 } else if ( colst[0]->co_type == Cft_Schema ) {
4282 schema_destroy_one( ca, colst, nocs, last );
4287 ch_free( ca->argv );
4288 if ( colst ) ch_free( colst );
4292 #define BIGTMP 10000
4294 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
4295 int base, int rebase, int max, int use_ldif )
4297 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
4298 ConfigType etype = ce->ce_type;
4299 int count = 0, rc = 0;
4301 /* Reverse ce list */
4302 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
4303 if (ce2->ce_type != etype) {
4308 ce2->ce_sibs = cetmp;
4311 if ( max && count >= max ) {
4317 /* Move original to a temp name until increments are done */
4319 ce->ce_entry->e_private = NULL;
4320 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4321 base+BIGTMP, 0, use_ldif );
4322 ce->ce_entry->e_private = ce;
4324 /* start incrementing */
4325 for (ce2=cetmp; ce2; ce2=ce3) {
4327 ce2->ce_sibs = cerem;
4330 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
4331 count+base, 0, use_ldif );
4335 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4336 base, 0, use_ldif );
4341 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
4342 CfEntryInfo *ce2, int old, int use_ldif )
4346 /* Renumber original to a temp value */
4347 ce->ce_entry->e_private = NULL;
4348 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4349 old+BIGTMP, 0, use_ldif );
4350 ce->ce_entry->e_private = ce;
4352 /* start decrementing */
4353 for (; ce2 != ce; ce2=ce2->ce_sibs) {
4354 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
4355 count+old, 0, use_ldif );
4358 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4359 count+old, 0, use_ldif );
4362 /* Parse an LDAP entry into config directives, then store in underlying
4366 config_back_add( Operation *op, SlapReply *rs )
4372 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
4373 NULL, ACL_WADD, NULL )) {
4374 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4378 cfb = (CfBackInfo *)op->o_bd->be_private;
4380 /* add opattrs for syncprov */
4382 char textbuf[SLAP_TEXT_BUFLEN];
4383 size_t textlen = sizeof textbuf;
4384 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1,
4385 &rs->sr_text, textbuf, sizeof( textbuf ) );
4386 if ( rs->sr_err != LDAP_SUCCESS )
4388 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
4389 if ( rs->sr_err != LDAP_SUCCESS ) {
4390 Debug( LDAP_DEBUG_TRACE,
4391 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
4392 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
4397 ldap_pvt_thread_pool_pause( &connection_pool );
4400 * 1) check for existence of entry
4401 * 2) check for sibling renumbering
4402 * 3) perform internal add
4403 * 4) perform any necessary renumbering
4404 * 5) store entry in underlying database
4406 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
4407 if ( rs->sr_err != LDAP_SUCCESS ) {
4408 rs->sr_text = ca.cr_msg;
4413 CfEntryInfo *ce = ca.ca_entry->e_private;
4414 req_add_s addr = op->oq_add;
4415 op->o_tag = LDAP_REQ_MODRDN;
4416 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
4417 op->o_tag = LDAP_REQ_ADD;
4419 if ( rs->sr_err != LDAP_SUCCESS ) {
4424 if ( cfb->cb_use_ldif ) {
4425 BackendDB *be = op->o_bd;
4426 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4427 struct berval dn, ndn;
4429 op->o_bd = &cfb->cb_db;
4431 /* Save current rootdn; use the underlying DB's rootdn */
4434 op->o_dn = op->o_bd->be_rootdn;
4435 op->o_ndn = op->o_bd->be_rootndn;
4437 scp = op->o_callback;
4438 op->o_callback = ≻
4439 op->o_bd->be_add( op, rs );
4441 op->o_callback = scp;
4447 ldap_pvt_thread_pool_resume( &connection_pool );
4450 send_ldap_result( op, rs );
4451 slap_graduate_commit_csn( op );
4455 typedef struct delrec {
4456 struct delrec *next;
4462 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
4467 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
4468 ca->line[0] == '{' )
4470 char *ptr = strchr( ca->line + 1, '}' );
4474 ca->valx = strtol( ca->line + 1, &next, 0 );
4475 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
4481 rc = config_parse_add( ct, ca, i );
4489 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
4492 int rc = LDAP_UNWILLING_TO_PERFORM;
4494 Entry *e = ce->ce_entry;
4495 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
4500 delrec *dels = NULL, *deltail = NULL;
4502 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4503 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
4505 colst = count_ocs( oc_at, &nocs );
4507 /* make sure add/del flags are clear; should always be true */
4508 for ( s = save_attrs; s; s = s->a_next ) {
4509 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
4512 e->e_attrs = attrs_dup( e->e_attrs );
4514 init_config_argv( ca );
4517 ca->private = ce->ce_private;
4519 ca->fname = "slapd";
4521 strcpy( ca->log, "back-config" );
4523 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
4524 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
4525 switch (ml->sml_op) {
4526 case LDAP_MOD_DELETE:
4527 case LDAP_MOD_REPLACE: {
4528 BerVarray vals = NULL, nvals = NULL;
4530 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
4532 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
4533 ml->sml_desc->ad_cname.bv_val );
4536 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4537 vals = ml->sml_values;
4538 nvals = ml->sml_nvalues;
4539 ml->sml_values = NULL;
4540 ml->sml_nvalues = NULL;
4542 /* If we're deleting by values, remember the indexes of the
4543 * values we deleted.
4545 if ( ct && ml->sml_values ) {
4547 for (i=0; ml->sml_values[i].bv_val; i++);
4548 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
4559 rc = modify_delete_vindex(e, &ml->sml_mod,
4560 get_permissiveModify(op),
4561 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
4562 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4563 ml->sml_values = vals;
4564 ml->sml_nvalues = nvals;
4569 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
4572 case SLAP_MOD_SOFTADD: {
4573 int mop = ml->sml_op;
4575 ml->sml_op = LDAP_MOD_ADD;
4577 if ( ct->arg_type & ARG_NO_INSERT ) {
4578 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
4580 for (i = 0; a->a_vals[i].bv_val; i++ );
4584 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
4585 if ( ml->sml_values[i].bv_val[0] == '{' &&
4588 char *next, *val = ml->sml_values[i].bv_val + 1;
4591 j = strtol( val, &next, 0 );
4592 if ( next == val || next[ 0 ] != '}' || j < navals ) {
4594 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
4595 ml->sml_desc->ad_cname.bv_val );
4599 rc = check_vals( ct, ca, ml, 0 );
4600 if ( rc ) goto out_noop;
4603 rc = modify_add_values(e, &ml->sml_mod,
4604 get_permissiveModify(op),
4605 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
4607 /* If value already exists, show success here
4608 * and ignore this operation down below.
4610 if ( mop == SLAP_MOD_SOFTADD ) {
4611 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
4621 case LDAP_MOD_INCREMENT: /* FIXME */
4626 if(rc != LDAP_SUCCESS) break;
4629 if ( rc == LDAP_SUCCESS) {
4630 /* check that the entry still obeys the schema */
4631 rc = entry_schema_check(op, e, NULL, 0, 0,
4632 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
4633 if ( rc ) goto out_noop;
4635 /* Basic syntax checks are OK. Do the actual settings. */
4636 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
4637 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
4638 if ( !ct ) continue;
4640 s = attr_find( save_attrs, ml->sml_desc );
4641 a = attr_find( e->e_attrs, ml->sml_desc );
4643 switch (ml->sml_op) {
4644 case LDAP_MOD_DELETE:
4645 case LDAP_MOD_REPLACE: {
4646 BerVarray vals = NULL, nvals = NULL;
4649 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4650 vals = ml->sml_values;
4651 nvals = ml->sml_nvalues;
4652 ml->sml_values = NULL;
4653 ml->sml_nvalues = NULL;
4656 if ( ml->sml_values )
4659 /* If we didn't delete the whole attribute */
4660 if ( ml->sml_values && a ) {
4661 struct berval *mvals;
4664 if ( ml->sml_nvalues )
4665 mvals = ml->sml_nvalues;
4667 mvals = ml->sml_values;
4669 /* use the indexes we saved up above */
4670 for (i=0; i < d->nidx; i++) {
4671 struct berval bv = *mvals++;
4672 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
4673 bv.bv_val[0] == '{' ) {
4674 ptr = strchr( bv.bv_val, '}' ) + 1;
4675 bv.bv_len -= ptr - bv.bv_val;
4678 ca->line = bv.bv_val;
4679 ca->valx = d->idx[i];
4680 rc = config_del_vals( ct, ca );
4681 if ( rc != LDAP_SUCCESS ) break;
4683 s->a_flags |= SLAP_ATTR_IXDEL;
4684 for (j=i+1; j < d->nidx; j++)
4685 if ( d->idx[j] >d->idx[i] )
4691 rc = config_del_vals( ct, ca );
4692 if ( rc ) rc = LDAP_OTHER;
4694 s->a_flags |= SLAP_ATTR_IXDEL;
4696 if ( ml->sml_values ) {
4701 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4702 ml->sml_values = vals;
4703 ml->sml_nvalues = nvals;
4705 if ( !vals || rc != LDAP_SUCCESS )
4708 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
4711 for (i=0; ml->sml_values[i].bv_val; i++) {
4712 ca->line = ml->sml_values[i].bv_val;
4714 rc = config_modify_add( ct, ca, ml->sml_desc, i );
4717 a->a_flags |= SLAP_ATTR_IXADD;
4724 /* Undo for a failed operation */
4725 if ( rc != LDAP_SUCCESS ) {
4726 for ( s = save_attrs; s; s = s->a_next ) {
4727 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
4728 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
4729 ct = config_find_table( colst, nocs, s->a_desc, ca );
4730 a = attr_find( e->e_attrs, s->a_desc );
4732 /* clear the flag so the add check below will skip it */
4733 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
4736 config_del_vals( ct, ca );
4738 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
4739 ca->line = s->a_vals[i].bv_val;
4741 config_modify_add( ct, ca, s->a_desc, i );
4745 for ( a = e->e_attrs; a; a = a->a_next ) {
4746 if ( a->a_flags & SLAP_ATTR_IXADD ) {
4747 ct = config_find_table( colst, nocs, a->a_desc, ca );
4750 config_del_vals( ct, ca );
4751 s = attr_find( save_attrs, a->a_desc );
4753 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
4754 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
4755 ca->line = s->a_vals[i].bv_val;
4757 config_modify_add( ct, ca, s->a_desc, i );
4767 if ( rc == LDAP_SUCCESS ) {
4768 attrs_free( save_attrs );
4770 attrs_free( e->e_attrs );
4771 e->e_attrs = save_attrs;
4773 ch_free( ca->argv );
4774 if ( colst ) ch_free( colst );
4776 deltail = dels->next;
4785 config_back_modify( Operation *op, SlapReply *rs )
4788 CfEntryInfo *ce, *last;
4790 ConfigArgs ca = {0};
4793 AttributeDescription *rad = NULL;
4795 cfb = (CfBackInfo *)op->o_bd->be_private;
4797 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
4800 rs->sr_matched = last->ce_entry->e_name.bv_val;
4801 rs->sr_err = LDAP_NO_SUCH_OBJECT;
4805 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
4806 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4810 /* Get type of RDN */
4811 rdn = ce->ce_entry->e_nname;
4812 ptr = strchr( rdn.bv_val, '=' );
4813 rdn.bv_len = ptr - rdn.bv_val;
4814 slap_bv2ad( &rdn, &rad, &rs->sr_text );
4816 /* Some basic validation... */
4817 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
4818 /* Don't allow Modify of RDN; must use ModRdn for that. */
4819 if ( ml->sml_desc == rad ) {
4820 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
4821 rs->sr_text = "Use modrdn to change the entry name";
4826 slap_mods_opattrs( op, &op->orm_modlist, 1 );
4828 if ( !slapd_shutdown )
4829 ldap_pvt_thread_pool_pause( &connection_pool );
4832 * 1) perform the Modify on the cached Entry.
4833 * 2) verify that the Entry still satisfies the schema.
4834 * 3) perform the individual config operations.
4835 * 4) store Modified entry in underlying LDIF backend.
4837 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
4839 rs->sr_text = ca.cr_msg;
4840 } else if ( cfb->cb_use_ldif ) {
4841 BackendDB *be = op->o_bd;
4842 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4843 struct berval dn, ndn;
4845 op->o_bd = &cfb->cb_db;
4849 op->o_dn = op->o_bd->be_rootdn;
4850 op->o_ndn = op->o_bd->be_rootndn;
4852 scp = op->o_callback;
4853 op->o_callback = ≻
4854 op->o_bd->be_modify( op, rs );
4856 op->o_callback = scp;
4861 if ( !slapd_shutdown )
4862 ldap_pvt_thread_pool_resume( &connection_pool );
4864 send_ldap_result( op, rs );
4865 slap_graduate_commit_csn( op );
4870 config_back_modrdn( Operation *op, SlapReply *rs )
4873 CfEntryInfo *ce, *last;
4877 cfb = (CfBackInfo *)op->o_bd->be_private;
4879 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
4882 rs->sr_matched = last->ce_entry->e_name.bv_val;
4883 rs->sr_err = LDAP_NO_SUCH_OBJECT;
4886 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
4887 NULL, ACL_WRITE, NULL )) {
4888 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4892 if ( ce->ce_parent )
4893 parent = ce->ce_parent->ce_entry;
4895 parent = (Entry *)&slap_entry_root;
4896 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
4897 NULL, ACL_WRITE, NULL )) {
4898 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4903 /* We don't allow moving objects to new parents.
4904 * Generally we only allow reordering a set of ordered entries.
4906 if ( op->orr_newSup ) {
4907 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
4911 /* If newRDN == oldRDN, quietly succeed */
4912 dnRdn( &op->o_req_ndn, &rdn );
4913 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
4914 rs->sr_err = LDAP_SUCCESS;
4918 /* Current behavior, subject to change as needed:
4920 * For backends and overlays, we only allow renumbering.
4921 * For schema, we allow renaming with the same number.
4922 * Otherwise, the op is not allowed.
4925 if ( ce->ce_type == Cft_Schema ) {
4929 /* Can't alter the main cn=schema entry */
4930 if ( ce->ce_parent->ce_type == Cft_Global ) {
4931 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
4932 rs->sr_text = "renaming not allowed for this entry";
4936 /* We could support this later if desired */
4937 ptr1 = ber_bvchr( &rdn, '}' );
4938 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
4939 len = ptr1 - rdn.bv_val;
4940 if ( len != ptr2 - op->orr_newrdn.bv_val ||
4941 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
4942 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
4943 rs->sr_text = "schema reordering not supported";
4946 } else if ( ce->ce_type == Cft_Database ||
4947 ce->ce_type == Cft_Overlay ) {
4948 char *ptr1, *ptr2, *iptr1, *iptr2;
4951 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
4952 if ( *iptr2 != '{' ) {
4953 rs->sr_err = LDAP_NAMING_VIOLATION;
4954 rs->sr_text = "new ordering index is required";
4958 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
4959 ptr1 = ber_bvchr( &rdn, '}' );
4960 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
4962 rs->sr_err = LDAP_NAMING_VIOLATION;
4963 rs->sr_text = "new ordering index is required";
4967 len1 = ptr1 - rdn.bv_val;
4968 len2 = ptr2 - op->orr_newrdn.bv_val;
4970 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
4971 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
4972 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
4973 rs->sr_text = "changing database/overlay type not allowed";
4976 ixold = strtol( iptr1, NULL, 0 );
4977 ixnew = strtol( iptr2, &ptr1, 0 );
4978 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
4979 rs->sr_err = LDAP_NAMING_VIOLATION;
4982 /* config DB is always 0, cannot be changed */
4983 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
4984 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
4988 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
4989 rs->sr_text = "renaming not supported for this entry";
4993 ldap_pvt_thread_pool_pause( &connection_pool );
4995 if ( ce->ce_type == Cft_Schema ) {
4996 req_modrdn_s modr = op->oq_modrdn;
4999 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
5000 if ( rs->sr_err == LDAP_SUCCESS ) {
5001 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
5002 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
5005 op->oq_modrdn = modr;
5007 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
5008 req_modrdn_s modr = op->oq_modrdn;
5011 /* Advance to first of this type */
5012 cprev = &ce->ce_parent->ce_kids;
5013 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
5014 cprev = &ce2->ce_sibs;
5017 /* Skip the -1 entry */
5018 if ( ce->ce_type == Cft_Database ) {
5019 cprev = &ce2->ce_sibs;
5025 /* Remove from old slot */
5026 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
5027 cprev = &ce2->ce_sibs;
5028 *cprev = ce->ce_sibs;
5029 ceold = ce->ce_sibs;
5031 /* Insert into new slot */
5033 for ( i=0; i<ixnew; i++ ) {
5037 cprev = &ce2->ce_sibs;
5039 ce->ce_sibs = *cprev;
5044 /* NOTE: These should be encoded in the OC tables, not inline here */
5045 if ( ce->ce_type == Cft_Database )
5046 backend_db_move( ce->ce_be, ixnew );
5047 else if ( ce->ce_type == Cft_Overlay )
5048 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
5050 if ( ixold < ixnew ) {
5051 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
5054 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
5055 ixold - ixnew, cfb->cb_use_ldif );
5057 op->oq_modrdn = modr;
5060 ldap_pvt_thread_pool_resume( &connection_pool );
5062 send_ldap_result( op, rs );
5067 config_back_delete( Operation *op, SlapReply *rs )
5069 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM, NULL );
5074 config_back_search( Operation *op, SlapReply *rs )
5077 CfEntryInfo *ce, *last;
5080 cfb = (CfBackInfo *)op->o_bd->be_private;
5082 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5085 rs->sr_matched = last->ce_entry->e_name.bv_val;
5086 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5089 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
5090 ACL_SEARCH, NULL, &mask ))
5092 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
5093 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5095 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5099 switch ( op->ors_scope ) {
5100 case LDAP_SCOPE_BASE:
5101 case LDAP_SCOPE_SUBTREE:
5102 config_send( op, rs, ce, 0 );
5105 case LDAP_SCOPE_ONELEVEL:
5106 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
5107 config_send( op, rs, ce, 1 );
5112 rs->sr_err = LDAP_SUCCESS;
5114 send_ldap_result( op, rs );
5118 /* no-op, we never free entries */
5119 int config_entry_release(
5124 if ( !e->e_private ) {
5127 return LDAP_SUCCESS;
5130 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
5132 int config_back_entry_get(
5136 AttributeDescription *at,
5141 CfEntryInfo *ce, *last;
5143 cfb = (CfBackInfo *)op->o_bd->be_private;
5145 ce = config_find_base( cfb->cb_root, ndn, &last );
5147 *ent = ce->ce_entry;
5148 if ( *ent && oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
5153 return ( *ent == NULL ? 1 : 0 );
5157 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
5158 ConfigTable *ct, ConfigArgs *c )
5162 for (; at && *at; at++) {
5163 /* Skip the naming attr */
5164 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
5166 for (i=0;ct[i].name;i++) {
5167 if (ct[i].ad == (*at)->sat_ad) {
5168 rc = config_get_vals(&ct[i], c);
5169 /* NOTE: tolerate that config_get_vals()
5170 * returns success with no values */
5171 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
5172 if ( c->rvalue_nvals )
5173 attr_merge(e, ct[i].ad, c->rvalue_vals,
5176 attr_merge_normalize(e, ct[i].ad,
5177 c->rvalue_vals, NULL);
5178 ber_bvarray_free( c->rvalue_nvals );
5179 ber_bvarray_free( c->rvalue_vals );
5188 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
5189 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
5191 Entry *e = entry_alloc();
5192 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5194 struct berval ad_name;
5195 AttributeDescription *ad = NULL;
5202 CfEntryInfo *ceprev = NULL;
5204 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
5207 ce->ce_type = main->co_type;
5208 ce->ce_parent = parent;
5210 pdn = parent->ce_entry->e_nname;
5211 if ( parent->ce_kids )
5212 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
5213 ceprev->ce_type <= ce->ce_type;
5214 ceprev = ceprev->ce_sibs );
5219 ce->ce_private = c->private;
5223 build_new_dn( &e->e_name, &pdn, rdn, NULL );
5224 ber_dupbv( &e->e_nname, &e->e_name );
5226 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
5227 main->co_name, NULL );
5229 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
5230 extra->co_name, NULL );
5231 ptr = strchr(rdn->bv_val, '=');
5232 ad_name.bv_val = rdn->bv_val;
5233 ad_name.bv_len = ptr - rdn->bv_val;
5234 rc = slap_bv2ad( &ad_name, &ad, &text );
5239 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
5240 attr_merge_normalize_one(e, ad, &val, NULL );
5243 c->table = main->co_type;
5244 if ( oc->soc_required )
5245 config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
5247 if ( oc->soc_allowed )
5248 config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
5252 c->table = extra->co_type;
5253 if ( oc->soc_required )
5254 config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
5256 if ( oc->soc_allowed )
5257 config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
5260 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5261 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
5262 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
5263 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
5264 if ( op && !op->o_noop ) {
5266 op->ora_modlist = NULL;
5267 op->o_bd->be_add( op, rs );
5268 if ( ( rs->sr_err != LDAP_SUCCESS )
5269 && (rs->sr_err != LDAP_ALREADY_EXISTS) ) {
5274 ce->ce_sibs = ceprev->ce_sibs;
5275 ceprev->ce_sibs = ce;
5276 } else if ( parent ) {
5277 ce->ce_sibs = parent->ce_kids;
5278 parent->ce_kids = ce;
5285 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
5286 Operation *op, SlapReply *rs )
5289 ConfigFile *cf = c->private;
5293 for (; cf; cf=cf->c_sibs, c->depth++) {
5294 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
5295 !cf->c_om_head ) continue;
5296 c->value_dn.bv_val = c->log;
5297 LUTIL_SLASHPATH( cf->c_file.bv_val );
5298 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
5303 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
5305 ptr = strchr( bv.bv_val, '.' );
5307 bv.bv_len = ptr - bv.bv_val;
5308 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
5309 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
5310 /* FIXME: how can indicate error? */
5313 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
5315 c->value_dn.bv_len += bv.bv_len;
5316 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
5319 e = config_build_entry( op, rs, ceparent, c, &c->value_dn,
5320 &CFOC_SCHEMA, NULL );
5323 } else if ( e && cf->c_kids ) {
5324 c->private = cf->c_kids;
5325 config_build_schema_inc( c, e->e_private, op, rs );
5331 #ifdef SLAPD_MODULES
5334 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
5335 Operation *op, SlapReply *rs )
5340 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
5341 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
5343 c->value_dn.bv_val = c->log;
5344 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
5345 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
5346 /* FIXME: how can indicate error? */
5350 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
5359 config_check_schema(Operation *op, CfBackInfo *cfb)
5361 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
5363 CfEntryInfo *ce, *last;
5366 /* If there's no root entry, we must be in the midst of converting */
5367 if ( !cfb->cb_root )
5370 /* Make sure the main schema entry exists */
5371 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
5378 /* Make sure it's up to date */
5379 if ( cf_om_tail != om_sys_tail ) {
5380 a = attr_find( e->e_attrs, cfAd_om );
5382 if ( a->a_nvals != a->a_vals )
5383 ber_bvarray_free( a->a_nvals );
5384 ber_bvarray_free( a->a_vals );
5388 oidm_unparse( &bv, NULL, NULL, 1 );
5389 attr_merge_normalize( e, cfAd_om, bv, NULL );
5390 ber_bvarray_free( bv );
5391 cf_om_tail = om_sys_tail;
5393 if ( cf_at_tail != at_sys_tail ) {
5394 a = attr_find( e->e_attrs, cfAd_attr );
5396 if ( a->a_nvals != a->a_vals )
5397 ber_bvarray_free( a->a_nvals );
5398 ber_bvarray_free( a->a_vals );
5402 at_unparse( &bv, NULL, NULL, 1 );
5403 attr_merge_normalize( e, cfAd_attr, bv, NULL );
5404 ber_bvarray_free( bv );
5405 cf_at_tail = at_sys_tail;
5407 if ( cf_oc_tail != oc_sys_tail ) {
5408 a = attr_find( e->e_attrs, cfAd_oc );
5410 if ( a->a_nvals != a->a_vals )
5411 ber_bvarray_free( a->a_nvals );
5412 ber_bvarray_free( a->a_vals );
5416 oc_unparse( &bv, NULL, NULL, 1 );
5417 attr_merge_normalize( e, cfAd_oc, bv, NULL );
5418 ber_bvarray_free( bv );
5419 cf_oc_tail = oc_sys_tail;
5422 SlapReply rs = {REP_RESULT};
5424 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
5425 &CFOC_SCHEMA, NULL );
5430 ce->ce_private = cfb->cb_config;
5431 cf_at_tail = at_sys_tail;
5432 cf_oc_tail = oc_sys_tail;
5433 cf_om_tail = om_sys_tail;
5438 static const char *defacl[] = {
5439 NULL, "to", "*", "by", "*", "none", NULL
5443 config_back_db_open( BackendDB *be, ConfigReply *cr )
5445 CfBackInfo *cfb = be->be_private;
5448 CfEntryInfo *ce, *ceparent;
5452 Connection conn = {0};
5453 OperationBuffer opbuf;
5455 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
5456 SlapReply rs = {REP_RESULT};
5457 void *thrctx = NULL;
5459 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
5461 /* If we have no explicitly configured ACLs, don't just use
5462 * the global ACLs. Explicitly deny access to everything.
5464 if ( frontendDB->be_acl && be->be_acl == frontendDB->be_acl ) {
5465 parse_acl(be, "config_back_db_open", 0, 6, (char **)defacl, 0 );
5468 thrctx = ldap_pvt_thread_pool_context();
5469 connection_fake_init( &conn, &opbuf, thrctx );
5472 op->o_tag = LDAP_REQ_ADD;
5473 op->o_callback = &cb;
5474 op->o_bd = &cfb->cb_db;
5475 op->o_dn = op->o_bd->be_rootdn;
5476 op->o_ndn = op->o_bd->be_rootndn;
5478 if ( !cfb->cb_use_ldif ) {
5482 /* If we read the config from back-ldif, do some quick sanity checks */
5483 if ( cfb->cb_got_ldif ) {
5484 return config_check_schema( op, cfb );
5487 /* create root of tree */
5489 c.private = cfb->cb_config;
5491 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
5501 #ifdef SLAPD_MODULES
5502 /* Create Module nodes... */
5503 if ( modpaths.mp_loads ) {
5504 if ( config_build_modules( &c, ceparent, op, &rs ) ){
5510 /* Create schema nodes... cn=schema will contain the hardcoded core
5511 * schema, read-only. Child objects will contain runtime loaded schema
5516 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
5521 ce->ce_private = cfb->cb_config;
5522 cf_at_tail = at_sys_tail;
5523 cf_oc_tail = oc_sys_tail;
5524 cf_om_tail = om_sys_tail;
5526 /* Create schema nodes for included schema... */
5527 if ( cfb->cb_config->c_kids ) {
5529 c.private = cfb->cb_config->c_kids;
5530 if (config_build_schema_inc( &c, ce, op, &rs )) {
5535 /* Create backend nodes. Skip if they don't provide a cf_table.
5536 * There usually aren't any of these.
5540 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
5541 if (!bi->bi_cf_ocs) {
5542 /* If it only supports the old config mech, complain. */
5543 if ( bi->bi_config ) {
5544 Debug( LDAP_DEBUG_ANY,
5545 "WARNING: No dynamic config support for backend %s.\n",
5546 bi->bi_type, 0, 0 );
5551 if (!bi->bi_private) continue;
5554 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
5555 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
5556 if ( rdn.bv_len >= sizeof( c.log ) ) {
5557 /* FIXME: holler ... */ ;
5560 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
5567 /* Create database nodes... */
5568 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
5569 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
5570 for ( i = -1, be = frontendDB ; be;
5571 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
5572 slap_overinfo *oi = NULL;
5574 if ( overlay_is_over( be )) {
5575 oi = be->bd_info->bi_private;
5581 /* If this backend supports the old config mechanism, but not
5582 * the new mech, complain.
5584 if ( !be->be_cf_ocs && bi->bi_db_config ) {
5585 Debug( LDAP_DEBUG_ANY,
5586 "WARNING: No dynamic config support for database %s.\n",
5587 bi->bi_type, 0, 0 );
5591 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
5592 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
5594 if ( rdn.bv_len >= sizeof( c.log ) ) {
5595 /* FIXME: holler ... */ ;
5599 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
5605 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd )
5606 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
5607 /* Iterate through overlays */
5613 for (j=0,on=oi->oi_list; on; j++,on=on->on_next) {
5614 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
5615 Debug( LDAP_DEBUG_ANY,
5616 "WARNING: No dynamic config support for overlay %s.\n",
5617 on->on_bi.bi_type, 0, 0 );
5621 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
5622 "%s=" SLAP_X_ORDERED_FMT "%s",
5623 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
5624 if ( rdn.bv_len >= sizeof( c.log ) ) {
5625 /* FIXME: holler ... */ ;
5629 oe = config_build_entry( op, &rs, ce, &c, &rdn,
5630 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
5634 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd )
5635 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
5640 ldap_pvt_thread_pool_context_reset( thrctx );
5642 if ( unsupp && cfb->cb_use_ldif ) {
5643 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
5644 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
5651 cfb_free_cffile( ConfigFile *cf )
5655 for (; cf; cf=next) {
5658 cfb_free_cffile( cf->c_kids );
5659 ch_free( cf->c_file.bv_val );
5660 ber_bvarray_free( cf->c_dseFiles );
5666 cfb_free_entries( CfEntryInfo *ce )
5670 for (; ce; ce=next) {
5673 cfb_free_entries( ce->ce_kids );
5674 ce->ce_entry->e_private = NULL;
5675 entry_free( ce->ce_entry );
5681 config_back_db_close( BackendDB *be, ConfigReply *cr )
5683 CfBackInfo *cfb = be->be_private;
5685 cfb_free_entries( cfb->cb_root );
5686 cfb->cb_root = NULL;
5688 if ( cfb->cb_db.bd_info ) {
5689 backend_shutdown( &cfb->cb_db );
5696 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
5698 CfBackInfo *cfb = be->be_private;
5700 cfb_free_cffile( cfb->cb_config );
5702 ch_free( cfdir.bv_val );
5704 avl_free( CfOcTree, NULL );
5706 if ( cfb->cb_db.bd_info ) {
5707 cfb->cb_db.be_suffix = NULL;
5708 cfb->cb_db.be_nsuffix = NULL;
5709 BER_BVZERO( &cfb->cb_db.be_rootdn );
5710 BER_BVZERO( &cfb->cb_db.be_rootndn );
5712 backend_destroy_one( &cfb->cb_db, 0 );
5721 config_back_db_init( BackendDB *be, ConfigReply* cr )
5727 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
5728 cfn = cfb->cb_config;
5729 be->be_private = cfb;
5731 ber_dupbv( &be->be_rootdn, &config_rdn );
5732 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
5733 ber_dupbv( &dn, &be->be_rootdn );
5734 ber_bvarray_add( &be->be_suffix, &dn );
5735 ber_dupbv( &dn, &be->be_rootdn );
5736 ber_bvarray_add( &be->be_nsuffix, &dn );
5738 /* Hide from namingContexts */
5739 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
5745 config_back_destroy( BackendInfo *bi )
5747 ldif_must_b64_encode_release();
5752 config_tool_entry_open( BackendDB *be, int mode )
5754 CfBackInfo *cfb = be->be_private;
5755 BackendInfo *bi = cfb->cb_db.bd_info;
5757 if ( bi && bi->bi_tool_entry_open )
5758 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
5765 config_tool_entry_close( BackendDB *be )
5767 CfBackInfo *cfb = be->be_private;
5768 BackendInfo *bi = cfb->cb_db.bd_info;
5770 if ( bi && bi->bi_tool_entry_close )
5771 return bi->bi_tool_entry_close( &cfb->cb_db );
5777 config_tool_entry_first( BackendDB *be )
5779 CfBackInfo *cfb = be->be_private;
5780 BackendInfo *bi = cfb->cb_db.bd_info;
5782 if ( bi && bi->bi_tool_entry_first )
5783 return bi->bi_tool_entry_first( &cfb->cb_db );
5789 config_tool_entry_next( BackendDB *be )
5791 CfBackInfo *cfb = be->be_private;
5792 BackendInfo *bi = cfb->cb_db.bd_info;
5794 if ( bi && bi->bi_tool_entry_next )
5795 return bi->bi_tool_entry_next( &cfb->cb_db );
5801 config_tool_entry_get( BackendDB *be, ID id )
5803 CfBackInfo *cfb = be->be_private;
5804 BackendInfo *bi = cfb->cb_db.bd_info;
5806 if ( bi && bi->bi_tool_entry_get )
5807 return bi->bi_tool_entry_get( &cfb->cb_db, id );
5812 static int entry_put_got_frontend=0;
5813 static int entry_put_got_config=0;
5815 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
5817 CfBackInfo *cfb = be->be_private;
5818 BackendInfo *bi = cfb->cb_db.bd_info;
5820 struct berval rdn, vals[ 2 ];
5822 OperationBuffer opbuf;
5824 Connection conn = {0};
5825 Operation *op = NULL;
5828 /* Create entry for frontend database if it does not exist already */
5829 if ( !entry_put_got_frontend ) {
5830 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
5831 STRLENOF( "olcDatabase" ))) {
5832 if ( strncmp( e->e_nname.bv_val +
5833 STRLENOF( "olcDatabase" ), "={-1}frontend",
5834 STRLENOF( "={-1}frontend" )) &&
5835 strncmp( e->e_nname.bv_val +
5836 STRLENOF( "olcDatabase" ), "=frontend",
5837 STRLENOF( "=frontend" ))) {
5839 vals[1].bv_val = NULL;
5840 memset( &ca, 0, sizeof(ConfigArgs));
5842 ca.bi = frontendDB->bd_info;
5843 ca.be->be_cf_ocs = &CFOC_FRONTEND;
5844 rdn.bv_val = ca.log;
5845 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
5846 "%s=" SLAP_X_ORDERED_FMT "%s",
5847 cfAd_database->ad_cname.bv_val, -1,
5849 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
5850 &CFOC_DATABASE, ca.be->be_cf_ocs );
5851 thrctx = ldap_pvt_thread_pool_context();
5852 connection_fake_init2( &conn, &opbuf, thrctx,0 );
5854 op->o_bd = &cfb->cb_db;
5855 op->o_tag = LDAP_REQ_ADD;
5857 op->o_dn = be->be_rootdn;
5858 op->o_ndn = be->be_rootndn;
5859 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
5860 if ( rc != LDAP_SUCCESS ) {
5861 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
5862 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
5866 if ( ce && bi && bi->bi_tool_entry_put &&
5867 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
5868 entry_put_got_frontend++;
5870 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
5871 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
5875 entry_put_got_frontend++;
5879 /* Create entry for config database if it does not exist already */
5880 if ( !entry_put_got_config ) {
5881 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
5882 STRLENOF( "olcDatabase" ))) {
5883 if ( strncmp( e->e_nname.bv_val +
5884 STRLENOF( "olcDatabase" ), "={0}config",
5885 STRLENOF( "={0}config" )) &&
5886 strncmp( e->e_nname.bv_val +
5887 STRLENOF( "olcDatabase" ), "=config",
5888 STRLENOF( "=config" )) ) {
5890 vals[1].bv_val = NULL;
5891 memset( &ca, 0, sizeof(ConfigArgs));
5892 ca.be = LDAP_STAILQ_FIRST( &backendDB );
5893 ca.bi = ca.be->bd_info;
5894 rdn.bv_val = ca.log;
5895 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
5896 "%s=" SLAP_X_ORDERED_FMT "%s",
5897 cfAd_database->ad_cname.bv_val, 0,
5899 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
5902 thrctx = ldap_pvt_thread_pool_context();
5903 connection_fake_init2( &conn, &opbuf, thrctx,0 );
5905 op->o_bd = &cfb->cb_db;
5906 op->o_tag = LDAP_REQ_ADD;
5907 op->o_dn = be->be_rootdn;
5908 op->o_ndn = be->be_rootndn;
5911 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
5912 if ( rc != LDAP_SUCCESS ) {
5913 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
5914 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
5917 if (ce && bi && bi->bi_tool_entry_put &&
5918 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
5919 entry_put_got_config++;
5921 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
5922 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
5926 entry_put_got_config++;
5930 if ( bi && bi->bi_tool_entry_put &&
5931 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
5932 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
5939 AttributeDescription **desc;
5941 { "attribute", &cfAd_attr },
5942 { "backend", &cfAd_backend },
5943 { "database", &cfAd_database },
5944 { "include", &cfAd_include },
5945 { "objectclass", &cfAd_oc },
5946 { "objectidentifier", &cfAd_om },
5947 { "overlay", &cfAd_overlay },
5952 * add / delete: all types that may be added or deleted must use an
5953 * X-ORDERED attributeType for their RDN. Adding and deleting entries
5954 * should automatically renumber the index of any siblings as needed,
5955 * so that no gaps in the numbering sequence exist after the add/delete
5957 * What can be added:
5959 * backend objects for backend-specific config directives
5963 * delete: probably no support this time around.
5965 * modrdn: generally not done. Will be invoked automatically by add/
5966 * delete to update numbering sequence. Perform as an explicit operation
5967 * so that the renumbering effect may be replicated. Subtree rename must
5968 * be supported, since renumbering a database will affect all its child
5971 * modify: must be fully supported.
5975 config_back_initialize( BackendInfo *bi )
5977 ConfigTable *ct = config_back_cf_table;
5981 AttributeDescription *ad = NULL;
5983 static char *controls[] = {
5984 LDAP_CONTROL_MANAGEDSAIT,
5988 /* Make sure we don't exceed the bits reserved for userland */
5989 config_check_userland( CFG_LAST );
5991 bi->bi_controls = controls;
5996 bi->bi_destroy = config_back_destroy;
5998 bi->bi_db_init = config_back_db_init;
5999 bi->bi_db_config = 0;
6000 bi->bi_db_open = config_back_db_open;
6001 bi->bi_db_close = config_back_db_close;
6002 bi->bi_db_destroy = config_back_db_destroy;
6004 bi->bi_op_bind = config_back_bind;
6005 bi->bi_op_unbind = 0;
6006 bi->bi_op_search = config_back_search;
6007 bi->bi_op_compare = 0;
6008 bi->bi_op_modify = config_back_modify;
6009 bi->bi_op_modrdn = config_back_modrdn;
6010 bi->bi_op_add = config_back_add;
6011 bi->bi_op_delete = config_back_delete;
6012 bi->bi_op_abandon = 0;
6014 bi->bi_extended = 0;
6016 bi->bi_chk_referrals = 0;
6018 bi->bi_access_allowed = slap_access_allowed;
6020 bi->bi_connection_init = 0;
6021 bi->bi_connection_destroy = 0;
6023 bi->bi_entry_release_rw = config_entry_release;
6024 bi->bi_entry_get_rw = config_back_entry_get;
6026 bi->bi_tool_entry_open = config_tool_entry_open;
6027 bi->bi_tool_entry_close = config_tool_entry_close;
6028 bi->bi_tool_entry_first = config_tool_entry_first;
6029 bi->bi_tool_entry_next = config_tool_entry_next;
6030 bi->bi_tool_entry_get = config_tool_entry_get;
6031 bi->bi_tool_entry_put = config_tool_entry_put;
6034 argv[ 0 ] = "slapd";
6040 for (i=0; OidMacros[i].name; i++ ) {
6041 argv[1] = OidMacros[i].name;
6042 argv[2] = OidMacros[i].oid;
6043 parse_oidm( &ca, 0, NULL );
6046 bi->bi_cf_ocs = cf_ocs;
6048 i = config_register_schema( ct, cf_ocs );
6051 /* setup olcRootPW to be base64-encoded when written in LDIF form;
6052 * basically, we don't care if it fails */
6053 i = slap_str2ad( "olcRootPW", &ad, &text );
6055 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
6056 "warning, unable to get \"olcRootPW\" "
6057 "attribute description: %d: %s\n",
6060 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
6061 ad->ad_type->sat_oid );
6064 /* set up the notable AttributeDescriptions */
6066 for (;ct->name;ct++) {
6067 if (strcmp(ct->name, ads[i].name)) continue;
6068 *ads[i].desc = ct->ad;
6070 if (!ads[i].name) break;