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;
189 static OidRec OidMacros[] = {
190 /* OpenLDAProot:666.11.1 */
191 { "OLcfg", "1.3.6.1.4.1.4203.666.11.1" },
192 { "OLcfgAt", "OLcfg:3" },
193 { "OLcfgGlAt", "OLcfgAt:0" },
194 { "OLcfgBkAt", "OLcfgAt:1" },
195 { "OLcfgDbAt", "OLcfgAt:2" },
196 { "OLcfgOvAt", "OLcfgAt:3" },
197 { "OLcfgCtAt", "OLcfgAt:4" }, /* contrib modules */
198 { "OLcfgOc", "OLcfg:4" },
199 { "OLcfgGlOc", "OLcfgOc:0" },
200 { "OLcfgBkOc", "OLcfgOc:1" },
201 { "OLcfgDbOc", "OLcfgOc:2" },
202 { "OLcfgOvOc", "OLcfgOc:3" },
203 { "OLcfgCtOc", "OLcfgOc:4" }, /* contrib modules */
205 /* Syntaxes. We should just start using the standard names and
206 * document that they are predefined and available for users
207 * to reference in their own schema. Defining schema without
208 * OID macros is for masochists...
210 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
211 { "OMsBoolean", "OMsyn:7" },
212 { "OMsDN", "OMsyn:12" },
213 { "OMsDirectoryString", "OMsyn:15" },
214 { "OMsIA5String", "OMsyn:26" },
215 { "OMsInteger", "OMsyn:27" },
216 { "OMsOID", "OMsyn:38" },
217 { "OMsOctetString", "OMsyn:40" },
222 * Backend/Database registry
224 * OLcfg{Bk|Db}{Oc|At}:0 -> common
225 * OLcfg{Bk|Db}{Oc|At}:1 -> back-bdb(/back-hdb)
226 * OLcfg{Bk|Db}{Oc|At}:2 -> back-ldif
227 * OLcfg{Bk|Db}{Oc|At}:3 -> back-ldap
228 * OLcfg{Bk|Db}{Oc|At}:4 -> back-monitor
229 * OLcfg{Bk|Db}{Oc|At}:5 -> back-relay
230 * OLcfg{Bk|Db}{Oc|At}:6 -> back-sql
236 * OLcfgOv{Oc|At}:1 -> syncprov
237 * OLcfgOv{Oc|At}:2 -> pcache
238 * OLcfgOv{Oc|At}:3 -> chain
239 * OLcfgOv{Oc|At}:4 -> accesslog
240 * OLcfgOv{Oc|At}:5 -> valsort
241 * OLcfgOv{Oc|At}:7 -> distproc
242 * OLcfgOv{Oc|At}:8 -> dynlist
243 * OLcfgOv{Oc|At}:9 -> dds
244 * OLcfgOv{Oc|At}:10 -> unique
245 * OLcfgOv{Oc|At}:11 -> refint
246 * OLcfgOv{Oc|At}:12 -> ppolicy
247 * OLcfgOv{Oc|At}:13 -> constraint
248 * OLcfgOv{Oc|At}:14 -> translucent
249 * OLcfgOv{Oc|At}:15 -> auditlog
250 * OLcfgOv{Oc|At}:16 -> rwm
251 * OLcfgOv{Oc|At}:17 -> dyngroup
252 * OLcfgOv{Oc|At}:18 -> memberof
253 * OLcfgOv{Oc|At}:19 -> collect
256 /* alphabetical ordering */
258 static ConfigTable config_back_cf_table[] = {
259 /* This attr is read-only */
260 { "", "", 0, 0, 0, ARG_MAGIC,
261 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
262 "DESC 'File for slapd configuration directives' "
263 "EQUALITY caseIgnoreMatch "
264 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
265 { "", "", 0, 0, 0, ARG_MAGIC,
266 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
267 "DESC 'Directory for slapd configuration backend' "
268 "EQUALITY caseIgnoreMatch "
269 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
270 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
271 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
272 "DESC 'Access Control List' "
273 "EQUALITY caseIgnoreMatch "
274 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
275 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
276 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
277 "DESC 'Allowed set of deprecated features' "
278 "EQUALITY caseIgnoreMatch "
279 "SYNTAX OMsDirectoryString )", NULL, NULL },
280 { "argsfile", "file", 2, 2, 0, ARG_STRING,
281 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
282 "DESC 'File for slapd command line options' "
283 "EQUALITY caseIgnoreMatch "
284 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
285 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
286 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
287 "EQUALITY caseIgnoreMatch "
288 "SYNTAX OMsDirectoryString )", NULL, NULL },
289 { "attribute", "attribute", 2, 0, STRLENOF( "attribute" ),
290 ARG_PAREN|ARG_MAGIC|CFG_ATTR,
291 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
292 "DESC 'OpenLDAP attributeTypes' "
293 "EQUALITY caseIgnoreMatch "
294 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
296 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
297 #ifdef SLAP_AUTH_REWRITE
298 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
302 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
303 "EQUALITY caseIgnoreMatch "
304 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
305 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
306 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
307 "EQUALITY caseIgnoreMatch "
308 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
309 { "authz-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
310 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
311 "EQUALITY caseIgnoreMatch "
312 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
313 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
314 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
315 "DESC 'A type of backend' "
316 "EQUALITY caseIgnoreMatch "
317 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
319 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
320 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
321 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
322 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
323 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
324 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
325 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
326 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
327 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
328 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
329 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
330 "DESC 'The backend type for a database instance' "
331 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
332 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
333 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
334 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
335 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
336 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
337 "EQUALITY caseIgnoreMatch "
338 "SYNTAX OMsDirectoryString )", NULL, NULL },
339 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
340 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
341 "DESC 'OpenLDAP DIT content rules' "
342 "EQUALITY caseIgnoreMatch "
343 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
345 { "gentlehup", "on|off", 2, 2, 0,
347 ARG_ON_OFF, &global_gentlehup,
351 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
352 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
353 { "hidden", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_HIDDEN,
354 &config_generic, "( OLcfgDbAt:0.17 NAME 'olcHidden' "
355 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
356 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
357 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
358 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
359 { "include", "file", 2, 2, 0, ARG_MAGIC,
360 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
361 "SUP labeledURI )", NULL, NULL },
362 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
363 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
364 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
365 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
366 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
367 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
368 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
369 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
370 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
371 { "index_substr_any_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
372 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
373 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
374 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
375 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
376 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
377 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
378 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
379 "EQUALITY caseIgnoreMatch "
380 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
381 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
382 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
383 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
384 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
385 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
386 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
387 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
388 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
389 "EQUALITY caseIgnoreMatch "
390 "SYNTAX OMsDirectoryString )", NULL, NULL },
391 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
392 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
393 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
394 { "mirrormode", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_MIRRORMODE,
395 &config_generic, "( OLcfgDbAt:0.16 NAME 'olcMirrorMode' "
396 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
397 { "moduleload", "file", 2, 0, 0,
399 ARG_MAGIC|CFG_MODLOAD|ARG_NO_DELETE, &config_generic,
403 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
404 "EQUALITY caseIgnoreMatch "
405 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
406 { "modulepath", "path", 2, 2, 0,
408 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
412 "( OLcfgGlAt:31 NAME 'olcModulePath' "
413 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
414 { "monitoring", "TRUE|FALSE", 2, 2, 0,
415 ARG_MAGIC|CFG_MONITORING|ARG_DB|ARG_ON_OFF, &config_generic,
416 "( OLcfgDbAt:0.18 NAME 'olcMonitoring' "
417 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
418 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
419 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
420 "DESC 'OpenLDAP object classes' "
421 "EQUALITY caseIgnoreMatch "
422 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
424 { "objectidentifier", "name> <oid", 3, 3, 0, ARG_MAGIC|CFG_OID,
425 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
426 "EQUALITY caseIgnoreMatch "
427 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
428 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
429 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
430 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
431 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
432 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
433 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
434 { "password-hash", "hash", 2, 2, 0, ARG_MAGIC,
435 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
436 "EQUALITY caseIgnoreMatch "
437 "SYNTAX OMsDirectoryString )", NULL, NULL },
438 { "pidfile", "file", 2, 2, 0, ARG_STRING,
439 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
440 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
441 { "plugin", NULL, 0, 0, 0,
443 ARG_MAGIC|CFG_PLUGIN, &config_generic,
447 "( OLcfgGlAt:38 NAME 'olcPlugin' "
448 "EQUALITY caseIgnoreMatch "
449 "SYNTAX OMsDirectoryString )", NULL, NULL },
450 { "pluginlog", "filename", 2, 2, 0,
452 ARG_STRING, &slapi_log_file,
456 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
457 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
458 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
459 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
460 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
461 { "referral", "url", 2, 2, 0, ARG_MAGIC,
462 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
463 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
464 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
465 &config_obsolete, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
466 "EQUALITY caseIgnoreMatch "
467 "SUP labeledURI X-ORDERED 'VALUES' )", NULL, NULL },
468 { "replica-argsfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
469 &config_obsolete, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
470 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
471 { "replica-pidfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
472 &config_obsolete, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
473 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
474 { "replicationInterval", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
475 &config_obsolete, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
476 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
477 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC,
478 &config_obsolete, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
479 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
480 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
481 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
482 "EQUALITY caseIgnoreMatch "
483 "SYNTAX OMsDirectoryString )", NULL, NULL },
484 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
485 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
486 "EQUALITY caseIgnoreMatch "
487 "SYNTAX OMsDirectoryString )", NULL, NULL },
488 { "reverse-lookup", "on|off", 2, 2, 0,
489 #ifdef SLAPD_RLOOKUPS
490 ARG_ON_OFF, &use_reverse_lookup,
494 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
495 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
496 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
497 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
498 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
499 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
500 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
501 "EQUALITY caseIgnoreMatch "
502 "SYNTAX OMsDirectoryString )", NULL, NULL },
503 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
504 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
505 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
506 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
507 &config_generic, NULL, NULL, NULL },
508 { "sasl-host", "host", 2, 2, 0,
509 #ifdef HAVE_CYRUS_SASL
510 ARG_STRING|ARG_UNIQUE, &global_host,
514 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
515 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
516 { "sasl-realm", "realm", 2, 2, 0,
517 #ifdef HAVE_CYRUS_SASL
518 ARG_STRING|ARG_UNIQUE, &global_realm,
522 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
523 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
524 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
525 &config_generic, NULL, NULL, NULL },
526 { "sasl-secprops", "properties", 2, 2, 0,
527 #ifdef HAVE_CYRUS_SASL
528 ARG_MAGIC|CFG_SASLSECP, &config_generic,
532 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
533 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
534 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
535 &config_generic, NULL, NULL, NULL },
536 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
537 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
538 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
539 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
540 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
541 "EQUALITY caseIgnoreMatch "
542 "SYNTAX OMsDirectoryString )", NULL, NULL },
543 { "serverID", "number> <[URI]", 2, 3, 0, ARG_MAGIC|CFG_SERVERID,
544 &config_generic, "( OLcfgGlAt:81 NAME 'olcServerID' "
545 "EQUALITY caseIgnoreMatch "
546 "SYNTAX OMsDirectoryString )", NULL, NULL },
547 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
548 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
549 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
550 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
551 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
552 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
553 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
554 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
555 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
556 { "sortvals", "attr", 2, 0, 0, ARG_MAGIC|CFG_SORTVALS,
557 &config_generic, "( OLcfgGlAt:83 NAME 'olcSortVals' "
558 "DESC 'Attributes whose values will always be sorted' "
559 "EQUALITY caseIgnoreMatch "
560 "SYNTAX OMsDirectoryString )", NULL, NULL },
561 { "subordinate", "[advertise]", 1, 2, 0, ARG_DB|ARG_MAGIC,
562 &config_subordinate, "( OLcfgDbAt:0.15 NAME 'olcSubordinate' "
563 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
564 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
565 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
566 "EQUALITY distinguishedNameMatch "
567 "SYNTAX OMsDN )", NULL, NULL },
568 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
569 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
570 "EQUALITY caseIgnoreMatch "
571 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
572 { "threads", "count", 2, 2, 0,
576 ARG_INT|ARG_MAGIC|CFG_THREADS, &config_generic,
578 "( OLcfgGlAt:66 NAME 'olcThreads' "
579 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
580 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
581 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
582 "SYNTAX OMsDirectoryString )", NULL, NULL },
583 { "TLSCACertificateFile", NULL, 0, 0, 0,
585 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
589 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
590 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
591 { "TLSCACertificatePath", NULL, 0, 0, 0,
593 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
597 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
598 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
599 { "TLSCertificateFile", NULL, 0, 0, 0,
601 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
605 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
606 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
607 { "TLSCertificateKeyFile", NULL, 0, 0, 0,
609 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
613 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
614 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
615 { "TLSCipherSuite", NULL, 0, 0, 0,
617 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
621 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
622 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
623 { "TLSCRLCheck", NULL, 0, 0, 0,
624 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
625 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
629 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
630 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
631 { "TLSCRLFile", NULL, 0, 0, 0,
632 #if defined(HAVE_GNUTLS)
633 CFG_TLS_CRL_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
637 "( OLcfgGlAt:82 NAME 'olcTLSCRLFile' "
638 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
639 { "TLSRandFile", NULL, 0, 0, 0,
641 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
645 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
646 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
647 { "TLSVerifyClient", NULL, 0, 0, 0,
649 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
653 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
654 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
655 { "TLSDHParamFile", NULL, 0, 0, 0,
657 CFG_TLS_DH_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
661 "( OLcfgGlAt:77 NAME 'olcTLSDHParamFile' "
662 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
663 { "tool-threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_TTHREADS,
664 &config_generic, "( OLcfgGlAt:80 NAME 'olcToolThreads' "
665 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
666 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
667 NULL, NULL, NULL, NULL },
668 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
669 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
670 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
671 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
672 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
673 "EQUALITY caseIgnoreMatch "
674 "SUP labeledURI )", NULL, NULL },
675 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
676 NULL, NULL, NULL, NULL }
679 /* Routines to check if a child can be added to this type */
680 static ConfigLDAPadd cfAddSchema, cfAddInclude, cfAddDatabase,
681 cfAddBackend, cfAddModule, cfAddOverlay;
683 /* NOTE: be careful when defining array members
684 * that can be conditionally compiled */
685 #define CFOC_GLOBAL cf_ocs[1]
686 #define CFOC_SCHEMA cf_ocs[2]
687 #define CFOC_BACKEND cf_ocs[3]
688 #define CFOC_DATABASE cf_ocs[4]
689 #define CFOC_OVERLAY cf_ocs[5]
690 #define CFOC_INCLUDE cf_ocs[6]
691 #define CFOC_FRONTEND cf_ocs[7]
693 #define CFOC_MODULE cf_ocs[8]
694 #endif /* SLAPD_MODULES */
696 static ConfigOCs cf_ocs[] = {
699 "DESC 'OpenLDAP configuration object' "
700 "ABSTRACT SUP top )", Cft_Abstract, NULL },
703 "DESC 'OpenLDAP Global configuration options' "
704 "SUP olcConfig STRUCTURAL "
705 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
706 "olcAttributeOptions $ olcAuthIDRewrite $ "
707 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
708 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
709 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
710 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
711 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcLocalSSF $ "
713 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
714 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
715 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
717 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
718 "olcSecurity $ olcServerID $ olcSizeLimit $ "
719 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ "
720 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
721 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
722 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
723 "olcTLSRandFile $ olcTLSVerifyClient $ olcTLSDHParamFile $ "
724 "olcTLSCRLFile $ olcToolThreads $ "
725 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
726 "olcDitContentRules ) )", Cft_Global },
728 "NAME 'olcSchemaConfig' "
729 "DESC 'OpenLDAP schema object' "
730 "SUP olcConfig STRUCTURAL "
731 "MAY ( cn $ olcObjectIdentifier $ olcAttributeTypes $ "
732 "olcObjectClasses $ olcDitContentRules ) )",
733 Cft_Schema, NULL, cfAddSchema },
735 "NAME 'olcBackendConfig' "
736 "DESC 'OpenLDAP Backend-specific options' "
737 "SUP olcConfig STRUCTURAL "
738 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
740 "NAME 'olcDatabaseConfig' "
741 "DESC 'OpenLDAP Database-specific options' "
742 "SUP olcConfig STRUCTURAL "
744 "MAY ( olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
745 "olcLastMod $ olcLimits $ "
746 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
747 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
748 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
749 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncrepl $ "
750 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef $ olcMirrorMode $ "
752 Cft_Database, NULL, cfAddDatabase },
754 "NAME 'olcOverlayConfig' "
755 "DESC 'OpenLDAP Overlay-specific options' "
756 "SUP olcConfig STRUCTURAL "
757 "MUST olcOverlay )", Cft_Overlay, NULL, cfAddOverlay },
759 "NAME 'olcIncludeFile' "
760 "DESC 'OpenLDAP configuration include file' "
761 "SUP olcConfig STRUCTURAL "
763 "MAY ( cn $ olcRootDSE ) )",
764 /* Used to be Cft_Include, that def has been removed */
765 Cft_Abstract, NULL, cfAddInclude },
766 /* This should be STRUCTURAL like all the other database classes, but
767 * that would mean inheriting all of the olcDatabaseConfig attributes,
768 * which causes them to be merged twice in config_build_entry.
771 "NAME 'olcFrontendConfig' "
772 "DESC 'OpenLDAP frontend configuration' "
774 "MAY ( olcDefaultSearchBase $ olcPasswordHash $ olcSortVals ) )",
775 Cft_Database, NULL, NULL },
778 "NAME 'olcModuleList' "
779 "DESC 'OpenLDAP dynamic module info' "
780 "SUP olcConfig STRUCTURAL "
781 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
782 Cft_Module, NULL, cfAddModule },
787 typedef struct ServerID {
788 struct ServerID *si_next;
789 struct berval si_url;
793 static ServerID *sid_list;
795 typedef struct ADlist {
796 struct ADlist *al_next;
797 AttributeDescription *al_desc;
800 static ADlist *sortVals;
803 config_generic(ConfigArgs *c) {
806 if ( c->op == SLAP_CONFIG_EMIT ) {
810 c->value_int = ldap_pvt_thread_get_concurrency();
813 c->value_int = connection_pool_max;
816 c->value_int = slap_tool_thread_max;
820 c->value_string = ch_strdup( passwd_salt );
825 if ( c->be->be_limits ) {
829 for ( i=0; c->be->be_limits[i]; i++ ) {
830 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
831 if ( bv.bv_len >= sizeof( buf ) ) {
832 ber_bvarray_free_x( c->rvalue_vals, NULL );
833 c->rvalue_vals = NULL;
837 bv.bv_val = buf + bv.bv_len;
838 limits_unparse( c->be->be_limits[i], &bv,
839 sizeof( buf ) - ( bv.bv_val - buf ) );
840 bv.bv_len += bv.bv_val - buf;
842 value_add_one( &c->rvalue_vals, &bv );
845 if ( !c->rvalue_vals ) rc = 1;
848 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_OP_WRITES) ==
849 SLAP_RESTRICT_OP_WRITES;
852 c->value_string = ch_strdup( slap_sasl_getpolicy());
855 slap_sasl_regexp_unparse( &c->rvalue_vals );
856 if ( !c->rvalue_vals ) rc = 1;
858 #ifdef HAVE_CYRUS_SASL
860 struct berval bv = BER_BVNULL;
861 slap_sasl_secprops_unparse( &bv );
862 if ( !BER_BVISNULL( &bv )) {
863 ber_bvarray_add( &c->rvalue_vals, &bv );
871 c->value_int = c->be->be_max_deref_depth;
874 if ( SLAP_DBHIDDEN( c->be )) {
881 ConfigFile *cf = c->private;
883 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
884 else if ( cf->c_om_head )
885 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
887 if ( !c->rvalue_vals )
892 ad_unparse_options( &c->rvalue_vals );
895 ConfigFile *cf = c->private;
897 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
898 else if ( cf->c_oc_head )
899 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
901 if ( !c->rvalue_vals )
906 ConfigFile *cf = c->private;
908 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
909 else if ( cf->c_at_head )
910 at_unparse( &c->rvalue_vals, cf->c_at_head,
912 if ( !c->rvalue_vals )
917 ConfigFile *cf = c->private;
919 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
920 else if ( cf->c_cr_head )
921 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
923 if ( !c->rvalue_vals )
930 char *src, *dst, ibuf[11];
931 struct berval bv, abv;
932 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
933 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
934 if ( abv.bv_len >= sizeof( ibuf ) ) {
935 ber_bvarray_free_x( c->rvalue_vals, NULL );
936 c->rvalue_vals = NULL;
940 acl_unparse( a, &bv );
941 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
942 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
943 /* Turn TAB / EOL into plain space */
944 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
945 if (isspace((unsigned char)*src)) *dst++ = ' ';
949 if (dst[-1] == ' ') {
953 abv.bv_len = dst - abv.bv_val;
954 ber_bvarray_add( &c->rvalue_vals, &abv );
960 ConfigFile *cf = c->private;
961 if ( cf->c_dseFiles ) {
962 value_add( &c->rvalue_vals, cf->c_dseFiles );
973 for ( si = sid_list; si; si=si->si_next ) {
974 assert( si->si_num >= 0 && si->si_num <= SLAP_SYNC_SID_MAX );
975 if ( !BER_BVISEMPTY( &si->si_url )) {
976 bv.bv_len = si->si_url.bv_len + 6;
977 bv.bv_val = ch_malloc( bv.bv_len );
978 sprintf( bv.bv_val, "%d %s", si->si_num,
980 ber_bvarray_add( &c->rvalue_vals, &bv );
984 bv.bv_len = sprintf( buf, "%d", si->si_num );
985 value_add_one( &c->rvalue_vals, &bv );
994 c->value_string = ch_strdup( logfileName );
999 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1001 case CFG_MIRRORMODE:
1002 if ( SLAP_SHADOW(c->be))
1003 c->value_int = (SLAP_SINGLE_SHADOW(c->be) == 0);
1007 case CFG_MONITORING:
1008 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
1010 case CFG_SSTR_IF_MAX:
1011 c->value_int = index_substr_if_maxlen;
1013 case CFG_SSTR_IF_MIN:
1014 c->value_int = index_substr_if_minlen;
1016 case CFG_SORTVALS: {
1019 for ( sv = sortVals; sv; sv = sv->al_next ) {
1020 value_add_one( &c->rvalue_vals, &sv->al_desc->ad_cname );
1024 #ifdef SLAPD_MODULES
1026 ModPaths *mp = c->private;
1029 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
1032 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
1033 SLAP_X_ORDERED_FMT "%s", i,
1034 mp->mp_loads[i].bv_val );
1035 if ( bv.bv_len >= sizeof( c->log ) ) {
1036 ber_bvarray_free_x( c->rvalue_vals, NULL );
1037 c->rvalue_vals = NULL;
1040 value_add_one( &c->rvalue_vals, &bv );
1044 rc = c->rvalue_vals ? 0 : 1;
1048 ModPaths *mp = c->private;
1049 if ( !BER_BVISNULL( &mp->mp_path ))
1050 value_add_one( &c->rvalue_vals, &mp->mp_path );
1052 rc = c->rvalue_vals ? 0 : 1;
1058 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1059 if ( !c->rvalue_vals ) rc = 1;
1062 #ifdef SLAP_AUTH_REWRITE
1064 if ( authz_rewrites ) {
1065 struct berval bv, idx;
1070 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1071 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1072 if ( idx.bv_len >= sizeof( ibuf ) ) {
1073 ber_bvarray_free_x( c->rvalue_vals, NULL );
1074 c->rvalue_vals = NULL;
1077 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1078 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1079 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1080 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1081 authz_rewrites[i].bv_val,
1082 authz_rewrites[i].bv_len + 1 );
1083 ber_bvarray_add( &c->rvalue_vals, &bv );
1086 if ( !c->rvalue_vals ) rc = 1;
1093 } else if ( c->op == LDAP_MOD_DELETE ) {
1096 /* single-valued attrs, no-ops */
1104 case CFG_MIRRORMODE:
1105 case CFG_MONITORING:
1107 case CFG_SSTR_IF_MAX:
1108 case CFG_SSTR_IF_MIN:
1111 /* no-ops, requires slapd restart */
1116 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1120 ch_free( passwd_salt );
1125 ch_free( logfileName );
1129 case CFG_SERVERID: {
1130 ServerID *si, **sip;
1132 for ( i=0, si = sid_list, sip = &sid_list;
1133 si; si = *sip, i++ ) {
1134 if ( c->valx == -1 || i == c->valx ) {
1146 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1150 if ( c->valx < 0 ) {
1152 if ( c->be == frontendDB )
1155 end = frontendDB->be_acl;
1156 acl_destroy( c->be->be_acl, end );
1157 c->be->be_acl = end;
1160 AccessControl **prev, *a;
1162 for (i=0, prev = &c->be->be_acl; i < c->valx;
1165 prev = &a->acl_next;
1168 *prev = a->acl_next;
1175 /* Can be NULL when undoing a failed add */
1176 if ( c->ca_entry ) {
1177 ce = c->ca_entry->e_private;
1178 /* can't modify the hardcoded schema */
1179 if ( ce->ce_parent->ce_type == Cft_Global )
1184 if ( c->valx < 0 ) {
1187 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1189 if ( oc == cfn->c_oc_tail )
1192 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1194 ObjectClass *oc, *prev = NULL;
1196 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1201 if ( cfn->c_oc_tail == oc ) {
1202 cfn->c_oc_tail = prev;
1204 if ( cfn->c_oc_head == oc ) {
1206 cfn->c_oc_head = oc;
1213 /* Can be NULL when undoing a failed add */
1214 if ( c->ca_entry ) {
1215 ce = c->ca_entry->e_private;
1216 /* can't modify the hardcoded schema */
1217 if ( ce->ce_parent->ce_type == Cft_Global )
1222 if ( c->valx < 0 ) {
1225 for( at = cfn->c_at_head; at; at_next( &at )) {
1227 if ( at == cfn->c_at_tail )
1230 cfn->c_at_head = cfn->c_at_tail = NULL;
1232 AttributeType *at, *prev = NULL;
1234 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1239 if ( cfn->c_at_tail == at ) {
1240 cfn->c_at_tail = prev;
1242 if ( cfn->c_at_head == at ) {
1244 cfn->c_at_head = at;
1249 if ( c->valx < 0 ) {
1251 for ( sv = sortVals; sv; sv = sortVals ) {
1252 sortVals = sv->al_next;
1253 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1260 for ( prev = &sortVals, sv = sortVals; i < c->valx; i++ ) {
1261 prev = &sv->al_next;
1264 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1265 *prev = sv->al_next;
1271 /* FIXME: there is no limits_free function */
1273 /* FIXME: there is no ad_option_free function */
1275 /* FIXME: there is no way to remove attributes added by
1289 if(!(c->bi = backend_info(c->argv[1]))) {
1290 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1291 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1292 c->log, c->cr_msg, c->argv[1] );
1299 /* NOTE: config is always the first backend!
1301 if ( !strcasecmp( c->argv[1], "config" )) {
1302 c->be = LDAP_STAILQ_FIRST(&backendDB);
1303 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1306 c->be = backend_db_init(c->argv[1], NULL, c->valx, &c->reply);
1308 if ( c->cr_msg[0] == 0 )
1309 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1310 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n", c->log, c->cr_msg, c->argv[1] );
1317 ldap_pvt_thread_set_concurrency(c->value_int);
1321 if ( c->value_int < 2 ) {
1322 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1323 "threads=%d smaller than minimum value 2",
1325 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1326 c->log, c->cr_msg, 0 );
1329 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1330 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1331 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1332 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1333 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1334 c->log, c->cr_msg, 0 );
1336 if ( slapMode & SLAP_SERVER_MODE )
1337 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1338 connection_pool_max = c->value_int; /* save for reference */
1342 if ( slapMode & SLAP_TOOL_MODE )
1343 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1344 slap_tool_thread_max = c->value_int; /* save for reference */
1348 if ( passwd_salt ) ch_free( passwd_salt );
1349 passwd_salt = c->value_string;
1350 lutil_salt_format(passwd_salt);
1354 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1360 c->be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1362 c->be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1366 ch_free(c->value_string);
1367 if (slap_sasl_setpolicy( c->argv[1] )) {
1368 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
1369 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1370 c->log, c->cr_msg, c->argv[1] );
1376 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1380 #ifdef HAVE_CYRUS_SASL
1383 char *txt = slap_sasl_secprops( c->argv[1] );
1385 snprintf( c->cr_msg, sizeof(c->cr_msg), "<%s> %s",
1387 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0 );
1395 c->be->be_max_deref_depth = c->value_int;
1401 if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private )
1403 if(parse_oidm(c, 1, &om))
1405 if (!cfn->c_om_head) cfn->c_om_head = om;
1406 cfn->c_om_tail = om;
1411 ObjectClass *oc, *prev;
1413 if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private )
1415 if ( c->valx < 0 ) {
1416 prev = cfn->c_oc_tail;
1419 /* If adding anything after the first, prev is easy */
1422 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
1427 /* If adding the first, and head exists, find its prev */
1428 if (cfn->c_oc_head) {
1429 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
1434 /* else prev is NULL, append to end of global list */
1436 if(parse_oc(c, &oc, prev)) return(1);
1437 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1438 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
1443 AttributeType *at, *prev;
1445 if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private )
1447 if ( c->valx < 0 ) {
1448 prev = cfn->c_at_tail;
1451 /* If adding anything after the first, prev is easy */
1454 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
1459 /* If adding the first, and head exists, find its prev */
1460 if (cfn->c_at_head) {
1461 for ( at_start( &at ); at != cfn->c_at_head; ) {
1466 /* else prev is NULL, append to end of global list */
1468 if(parse_at(c, &at, prev)) return(1);
1469 if (!cfn->c_at_head) cfn->c_at_head = at;
1470 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
1477 if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private )
1479 if(parse_cr(c, &cr)) return(1);
1480 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1481 cfn->c_cr_tail = cr;
1486 ad_define_option(NULL, NULL, 0);
1487 for(i = 1; i < c->argc; i++)
1488 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1492 case CFG_SORTVALS: {
1493 ADlist *svnew = NULL, *svtail, *sv;
1495 for ( i = 1; i < c->argc; i++ ) {
1496 AttributeDescription *ad = NULL;
1500 rc = slap_str2ad( c->argv[i], &ad, &text );
1502 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown attribute type #%d",
1505 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1506 c->log, c->cr_msg, c->argv[i] );
1507 for ( sv = svnew; sv; sv = svnew ) {
1508 svnew = sv->al_next;
1513 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) ||
1514 ad->ad_type->sat_single_value ) {
1515 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> inappropriate attribute type #%d",
1517 goto sortval_reject;
1519 sv = ch_malloc( sizeof( ADlist ));
1524 svtail->al_next = sv;
1529 for ( sv = svnew; sv; sv = sv->al_next )
1530 sv->al_desc->ad_type->sat_flags |= SLAP_AT_SORTED_VAL;
1531 for ( sv = sortVals; sv && sv->al_next; sv = sv->al_next );
1533 sv->al_next = svnew;
1540 /* Don't append to the global ACL if we're on a specific DB */
1542 if ( c->be != frontendDB && frontendDB->be_acl && c->valx == -1 ) {
1545 for ( a=c->be->be_acl; a && a != frontendDB->be_acl;
1549 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
1555 if(root_dse_read_file(c->argv[1])) {
1556 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> could not read file", c->argv[0] );
1557 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1558 c->log, c->cr_msg, c->argv[1] );
1563 ber_str2bv( c->argv[1], 0, 1, &bv );
1564 if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private )
1566 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1572 ServerID *si, **sip;
1575 if ( lutil_atoi( &num, c->argv[1] ) ||
1576 num < 0 || num > SLAP_SYNC_SID_MAX )
1578 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1579 "<%s> illegal server ID", c->argv[0] );
1580 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1581 c->log, c->cr_msg, c->argv[1] );
1584 /* only one value allowed if no URL is given */
1585 if ( c->argc > 2 ) {
1588 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
1589 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1590 "<%s> only one server ID allowed now", c->argv[0] );
1591 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1592 c->log, c->cr_msg, c->argv[1] );
1596 if ( ldap_url_parse( c->argv[2], &lud )) {
1597 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1598 "<%s> invalid URL", c->argv[0] );
1599 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1600 c->log, c->cr_msg, c->argv[2] );
1603 len = strlen( c->argv[2] );
1604 si = ch_malloc( sizeof(ServerID) + len + 1 );
1605 si->si_url.bv_val = (char *)(si+1);
1606 si->si_url.bv_len = len;
1607 strcpy( si->si_url.bv_val, c->argv[2] );
1610 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1611 "<%s> unqualified server ID not allowed now", c->argv[0] );
1612 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1613 c->log, c->cr_msg, c->argv[1] );
1616 si = ch_malloc( sizeof(ServerID) );
1617 BER_BVZERO( &si->si_url );
1618 slap_serverID = num;
1619 Debug( LDAP_DEBUG_CONFIG,
1621 c->log, slap_serverID, 0 );
1625 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
1628 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
1629 /* If hostname is empty, or is localhost, or matches
1630 * our hostname, this serverID refers to this host.
1631 * Compare it against listeners and ports.
1633 if ( !lud->lud_host || !lud->lud_host[0] ||
1634 !strncasecmp("localhost", lud->lud_host,
1635 STRLENOF("localhost")) ||
1636 !strcasecmp( global_host, lud->lud_host )) {
1637 Listener **l = slapd_get_listeners();
1640 for ( i=0; l[i]; i++ ) {
1643 ldap_url_parse( l[i]->sl_url.bv_val, &lu2 );
1645 if ( strcasecmp( lud->lud_scheme,
1648 if ( lud->lud_port != lu2->lud_port )
1650 /* Listener on ANY address */
1651 if ( !lu2->lud_host || !lu2->lud_host[0] ) {
1655 /* URL on ANY address */
1656 if ( !lud->lud_host || !lud->lud_host[0] ) {
1660 /* Listener has specific host, must
1663 if ( !strcasecmp( lud->lud_host,
1669 ldap_free_urldesc( lu2 );
1671 slap_serverID = si->si_num;
1672 Debug( LDAP_DEBUG_CONFIG,
1673 "%s: SID=%d (listener=%s)\n",
1674 c->log, slap_serverID,
1675 l[i]->sl_url.bv_val );
1682 ldap_free_urldesc( lud );
1687 if ( logfileName ) ch_free( logfileName );
1688 logfileName = c->value_string;
1689 logfile = fopen(logfileName, "w");
1690 if(logfile) lutil_debug_file(logfile);
1694 if(SLAP_NOLASTMODCMD(c->be)) {
1695 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> not available for %s database",
1696 c->argv[0], c->be->bd_info->bi_type );
1697 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1698 c->log, c->cr_msg, 0 );
1702 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1704 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1707 case CFG_MIRRORMODE:
1708 if(!SLAP_SHADOW(c->be)) {
1709 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database is not a shadow",
1711 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1712 c->log, c->cr_msg, 0 );
1716 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
1718 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1721 case CFG_MONITORING:
1723 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
1725 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
1730 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
1732 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
1735 case CFG_SSTR_IF_MAX:
1736 if (c->value_int < index_substr_if_minlen) {
1737 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1738 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1739 c->log, c->cr_msg, c->value_int );
1742 index_substr_if_maxlen = c->value_int;
1745 case CFG_SSTR_IF_MIN:
1746 if (c->value_int > index_substr_if_maxlen) {
1747 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1748 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1749 c->log, c->cr_msg, c->value_int );
1752 index_substr_if_minlen = c->value_int;
1755 #ifdef SLAPD_MODULES
1757 /* If we're just adding a module on an existing modpath,
1758 * make sure we've selected the current path.
1760 if ( c->op == LDAP_MOD_ADD && c->private && modcur != c->private ) {
1761 modcur = c->private;
1762 /* This should never fail */
1763 if ( module_path( modcur->mp_path.bv_val )) {
1764 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> module path no longer valid",
1766 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1767 c->log, c->cr_msg, modcur->mp_path.bv_val );
1771 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1773 /* Record this load on the current path */
1777 if ( c->op == SLAP_CONFIG_ADD ) {
1778 ptr = c->line + STRLENOF("moduleload");
1779 while (!isspace((unsigned char) *ptr)) ptr++;
1780 while (isspace((unsigned char) *ptr)) ptr++;
1784 ber_str2bv(ptr, 0, 1, &bv);
1785 ber_bvarray_add( &modcur->mp_loads, &bv );
1787 /* Check for any new hardcoded schema */
1788 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
1789 config_check_schema( NULL, &cfBackInfo );
1794 if(module_path(c->argv[1])) return(1);
1795 /* Record which path was used with each module */
1799 if (!modpaths.mp_loads) {
1802 mp = ch_malloc( sizeof( ModPaths ));
1803 modlast->mp_next = mp;
1805 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1807 mp->mp_loads = NULL;
1818 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
1820 slapi_plugins_used++;
1824 #ifdef SLAP_AUTH_REWRITE
1829 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
1832 if ( c->argc > 1 ) {
1835 /* quote all args but the first */
1836 line = ldap_charray2str( c->argv, "\" \"" );
1837 ber_str2bv( line, 0, 0, &bv );
1838 s = ber_bvchr( &bv, '"' );
1839 assert( s != NULL );
1840 /* move the trailing quote of argv[0] to the end */
1841 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
1842 bv.bv_val[ bv.bv_len - 1 ] = '"';
1845 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
1848 ber_bvarray_add( &authz_rewrites, &bv );
1855 Debug( LDAP_DEBUG_ANY,
1856 "%s: unknown CFG_TYPE %d.\n",
1857 c->log, c->type, 0 );
1866 config_fname(ConfigArgs *c) {
1867 if(c->op == SLAP_CONFIG_EMIT) {
1869 ConfigFile *cf = c->private;
1870 value_add_one( &c->rvalue_vals, &cf->c_file );
1879 config_cfdir(ConfigArgs *c) {
1880 if(c->op == SLAP_CONFIG_EMIT) {
1881 if ( !BER_BVISEMPTY( &cfdir )) {
1882 value_add_one( &c->rvalue_vals, &cfdir );
1891 config_search_base(ConfigArgs *c) {
1892 if(c->op == SLAP_CONFIG_EMIT) {
1894 if (!BER_BVISEMPTY(&default_search_base)) {
1895 value_add_one(&c->rvalue_vals, &default_search_base);
1896 value_add_one(&c->rvalue_nvals, &default_search_nbase);
1900 } else if( c->op == LDAP_MOD_DELETE ) {
1901 ch_free( default_search_base.bv_val );
1902 ch_free( default_search_nbase.bv_val );
1903 BER_BVZERO( &default_search_base );
1904 BER_BVZERO( &default_search_nbase );
1908 if(c->bi || c->be != frontendDB) {
1909 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
1910 "prior to any backend or database definition\n",
1915 if(default_search_nbase.bv_len) {
1916 free(default_search_base.bv_val);
1917 free(default_search_nbase.bv_val);
1920 default_search_base = c->value_dn;
1921 default_search_nbase = c->value_ndn;
1925 /* For RE23 compatibility we allow this in the global entry
1926 * but we now defer it to the frontend entry to allow modules
1927 * to load new hash types.
1930 config_passwd_hash(ConfigArgs *c) {
1932 if (c->op == SLAP_CONFIG_EMIT) {
1934 /* Don't generate it in the global entry */
1935 if ( c->table == Cft_Global )
1937 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
1938 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
1939 value_add_one(&c->rvalue_vals, &bv);
1942 } else if ( c->op == LDAP_MOD_DELETE ) {
1943 /* Deleting from global is a no-op, only the frontendDB entry matters */
1944 if ( c->table == Cft_Global )
1946 if ( c->valx < 0 ) {
1947 ldap_charray_free( default_passwd_hash );
1948 default_passwd_hash = NULL;
1951 ch_free( default_passwd_hash[i] );
1952 for (; default_passwd_hash[i]; i++ )
1953 default_passwd_hash[i] = default_passwd_hash[i+1];
1957 for(i = 1; i < c->argc; i++) {
1958 if(!lutil_passwd_scheme(c->argv[i])) {
1959 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> scheme not available", c->argv[0] );
1960 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1961 c->log, c->cr_msg, c->argv[i]);
1963 ldap_charray_add(&default_passwd_hash, c->argv[i]);
1966 if(!default_passwd_hash) {
1967 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> no valid hashes found", c->argv[0] );
1968 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1969 c->log, c->cr_msg, 0 );
1976 config_schema_dn(ConfigArgs *c) {
1977 if ( c->op == SLAP_CONFIG_EMIT ) {
1979 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
1980 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
1981 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
1985 } else if ( c->op == LDAP_MOD_DELETE ) {
1986 ch_free( c->be->be_schemadn.bv_val );
1987 ch_free( c->be->be_schemandn.bv_val );
1988 BER_BVZERO( &c->be->be_schemadn );
1989 BER_BVZERO( &c->be->be_schemandn );
1992 ch_free( c->be->be_schemadn.bv_val );
1993 ch_free( c->be->be_schemandn.bv_val );
1994 c->be->be_schemadn = c->value_dn;
1995 c->be->be_schemandn = c->value_ndn;
2000 config_sizelimit(ConfigArgs *c) {
2002 struct slap_limits_set *lim = &c->be->be_def_limit;
2003 if (c->op == SLAP_CONFIG_EMIT) {
2008 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
2009 if ( !BER_BVISEMPTY( &bv ))
2010 value_add_one( &c->rvalue_vals, &bv );
2014 } else if ( c->op == LDAP_MOD_DELETE ) {
2015 /* Reset to defaults */
2016 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
2017 lim->lms_s_hard = 0;
2018 lim->lms_s_unchecked = -1;
2020 lim->lms_s_pr_hide = 0;
2021 lim->lms_s_pr_total = 0;
2024 for(i = 1; i < c->argc; i++) {
2025 if(!strncasecmp(c->argv[i], "size", 4)) {
2026 rc = limits_parse_one(c->argv[i], lim);
2028 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2029 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2030 c->log, c->cr_msg, c->argv[i]);
2034 if(!strcasecmp(c->argv[i], "unlimited")) {
2035 lim->lms_s_soft = -1;
2037 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
2038 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2039 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2040 c->log, c->cr_msg, c->argv[i]);
2044 lim->lms_s_hard = 0;
2051 config_timelimit(ConfigArgs *c) {
2053 struct slap_limits_set *lim = &c->be->be_def_limit;
2054 if (c->op == SLAP_CONFIG_EMIT) {
2059 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
2060 if ( !BER_BVISEMPTY( &bv ))
2061 value_add_one( &c->rvalue_vals, &bv );
2065 } else if ( c->op == LDAP_MOD_DELETE ) {
2066 /* Reset to defaults */
2067 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
2068 lim->lms_t_hard = 0;
2071 for(i = 1; i < c->argc; i++) {
2072 if(!strncasecmp(c->argv[i], "time", 4)) {
2073 rc = limits_parse_one(c->argv[i], lim);
2075 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2076 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2077 c->log, c->cr_msg, c->argv[i]);
2081 if(!strcasecmp(c->argv[i], "unlimited")) {
2082 lim->lms_t_soft = -1;
2084 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
2085 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2086 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2087 c->log, c->cr_msg, c->argv[i]);
2091 lim->lms_t_hard = 0;
2098 config_overlay(ConfigArgs *c) {
2099 if (c->op == SLAP_CONFIG_EMIT) {
2101 } else if ( c->op == LDAP_MOD_DELETE ) {
2104 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2107 Debug( LDAP_DEBUG_ANY,
2108 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2109 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2111 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi)) {
2118 config_subordinate(ConfigArgs *c)
2124 case SLAP_CONFIG_EMIT:
2125 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2128 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2129 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2132 value_add_one( &c->rvalue_vals, &bv );
2136 case LDAP_MOD_DELETE:
2137 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2138 glue_sub_del( c->be );
2140 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2145 case SLAP_CONFIG_ADD:
2146 advertise = ( c->argc == 2 && !strcasecmp( c->argv[1], "advertise" ));
2147 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2154 config_suffix(ConfigArgs *c)
2157 struct berval pdn, ndn;
2158 char *notallowed = NULL;
2160 if ( c->be == frontendDB ) {
2161 notallowed = "frontend";
2163 } else if ( SLAP_MONITOR(c->be) ) {
2164 notallowed = "monitor";
2166 } else if ( SLAP_CONFIG(c->be) ) {
2167 notallowed = "config";
2170 if ( notallowed != NULL ) {
2171 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
2175 case LDAP_MOD_DELETE:
2176 case LDAP_MOD_REPLACE:
2177 case LDAP_MOD_INCREMENT:
2178 case SLAP_CONFIG_ADD:
2179 if ( !BER_BVISNULL( &c->value_dn ) ) {
2180 snprintf( buf, sizeof( buf ), "<%s> ",
2181 c->value_dn.bv_val );
2184 Debug(LDAP_DEBUG_ANY,
2185 "%s: suffix %snot allowed in %s database.\n",
2186 c->log, buf, notallowed );
2189 case SLAP_CONFIG_EMIT:
2190 /* don't complain when emitting... */
2194 /* FIXME: don't know what values may be valid;
2195 * please remove assertion, or add legal values
2196 * to either block */
2204 if (c->op == SLAP_CONFIG_EMIT) {
2205 if ( c->be->be_suffix == NULL
2206 || BER_BVISNULL( &c->be->be_suffix[0] ) )
2210 value_add( &c->rvalue_vals, c->be->be_suffix );
2211 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
2214 } else if ( c->op == LDAP_MOD_DELETE ) {
2215 if ( c->valx < 0 ) {
2216 ber_bvarray_free( c->be->be_suffix );
2217 ber_bvarray_free( c->be->be_nsuffix );
2218 c->be->be_suffix = NULL;
2219 c->be->be_nsuffix = NULL;
2222 ch_free( c->be->be_suffix[i].bv_val );
2223 ch_free( c->be->be_nsuffix[i].bv_val );
2225 c->be->be_suffix[i] = c->be->be_suffix[i+1];
2226 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
2228 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
2233 #ifdef SLAPD_MONITOR_DN
2234 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
2235 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> DN is reserved for monitoring slapd",
2237 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2238 c->log, c->cr_msg, SLAPD_MONITOR_DN);
2245 if (SLAP_DBHIDDEN( c->be ))
2248 tbe = select_backend(&ndn, 0);
2250 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
2256 BackendDB *b2 = tbe;
2258 /* Does tbe precede be? */
2259 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
2262 char *type = tbe->bd_info->bi_type;
2264 if ( overlay_is_over( tbe ) ) {
2265 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
2266 type = oi->oi_orig->bi_type;
2269 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> namingContext \"%s\" "
2270 "already served by a preceding %s database",
2271 c->argv[0], pdn.bv_val, type );
2272 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
2273 c->log, c->cr_msg, tbe->be_suffix[0].bv_val);
2279 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
2280 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
2281 "base provided \"%s\" (assuming okay)\n",
2282 c->log, default_search_base.bv_val, 0);
2284 ber_bvarray_add(&c->be->be_suffix, &pdn);
2285 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
2290 config_rootdn(ConfigArgs *c) {
2291 if (c->op == SLAP_CONFIG_EMIT) {
2292 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2293 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
2294 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
2299 } else if ( c->op == LDAP_MOD_DELETE ) {
2300 ch_free( c->be->be_rootdn.bv_val );
2301 ch_free( c->be->be_rootndn.bv_val );
2302 BER_BVZERO( &c->be->be_rootdn );
2303 BER_BVZERO( &c->be->be_rootndn );
2306 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2307 ch_free( c->be->be_rootdn.bv_val );
2308 ch_free( c->be->be_rootndn.bv_val );
2310 c->be->be_rootdn = c->value_dn;
2311 c->be->be_rootndn = c->value_ndn;
2316 config_rootpw(ConfigArgs *c) {
2319 if (c->op == SLAP_CONFIG_EMIT) {
2320 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
2321 /* don't copy, because "rootpw" is marked
2323 c->value_bv = c->be->be_rootpw;
2327 } else if ( c->op == LDAP_MOD_DELETE ) {
2328 ch_free( c->be->be_rootpw.bv_val );
2329 BER_BVZERO( &c->be->be_rootpw );
2333 tbe = select_backend(&c->be->be_rootndn, 0);
2335 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> can only be set when rootdn is under suffix",
2337 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2338 c->log, c->cr_msg, 0);
2341 if ( !BER_BVISNULL( &c->be->be_rootpw ))
2342 ch_free( c->be->be_rootpw.bv_val );
2343 c->be->be_rootpw = c->value_bv;
2348 config_restrict(ConfigArgs *c) {
2349 slap_mask_t restrictops = 0;
2351 slap_verbmasks restrictable_ops[] = {
2352 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
2353 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
2354 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
2355 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
2356 { BER_BVC("modrdn"), 0 },
2357 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
2358 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
2359 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
2360 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
2361 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
2362 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
2363 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
2364 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
2365 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
2366 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
2367 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
2371 if (c->op == SLAP_CONFIG_EMIT) {
2372 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
2374 } else if ( c->op == LDAP_MOD_DELETE ) {
2376 c->be->be_restrictops = 0;
2378 restrictops = verb_to_mask( c->line, restrictable_ops );
2379 c->be->be_restrictops ^= restrictops;
2383 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
2385 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown operation", c->argv[0] );
2386 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2387 c->log, c->cr_msg, c->argv[i]);
2390 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
2391 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
2392 c->be->be_restrictops |= restrictops;
2397 config_allows(ConfigArgs *c) {
2398 slap_mask_t allows = 0;
2400 slap_verbmasks allowable_ops[] = {
2401 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
2402 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
2403 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
2404 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
2405 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
2408 if (c->op == SLAP_CONFIG_EMIT) {
2409 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
2410 } else if ( c->op == LDAP_MOD_DELETE ) {
2414 allows = verb_to_mask( c->line, allowable_ops );
2415 global_allows ^= allows;
2419 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
2421 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
2422 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2423 c->log, c->cr_msg, c->argv[i]);
2426 global_allows |= allows;
2431 config_disallows(ConfigArgs *c) {
2432 slap_mask_t disallows = 0;
2434 slap_verbmasks disallowable_ops[] = {
2435 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
2436 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
2437 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
2438 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
2441 if (c->op == SLAP_CONFIG_EMIT) {
2442 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
2443 } else if ( c->op == LDAP_MOD_DELETE ) {
2445 global_disallows = 0;
2447 disallows = verb_to_mask( c->line, disallowable_ops );
2448 global_disallows ^= disallows;
2452 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
2454 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
2455 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2456 c->log, c->cr_msg, c->argv[i]);
2459 global_disallows |= disallows;
2464 config_requires(ConfigArgs *c) {
2465 slap_mask_t requires = frontendDB->be_requires;
2466 int i, argc = c->argc;
2467 char **argv = c->argv;
2469 slap_verbmasks requires_ops[] = {
2470 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
2471 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
2472 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
2473 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
2474 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
2477 if (c->op == SLAP_CONFIG_EMIT) {
2478 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
2479 } else if ( c->op == LDAP_MOD_DELETE ) {
2481 c->be->be_requires = 0;
2483 requires = verb_to_mask( c->line, requires_ops );
2484 c->be->be_requires ^= requires;
2488 /* "none" can only be first, to wipe out default/global values */
2489 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
2494 i = verbs_to_mask(argc, argv, requires_ops, &requires);
2496 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
2497 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
2498 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2499 c->log, c->cr_msg, 0);
2501 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
2502 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2503 c->log, c->cr_msg, c->argv[i]);
2507 c->be->be_requires = requires;
2511 static slap_verbmasks *loglevel_ops;
2514 loglevel_init( void )
2516 slap_verbmasks lo[] = {
2517 { BER_BVC("Any"), -1 },
2518 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
2519 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
2520 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
2521 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
2522 { BER_BVC("BER"), LDAP_DEBUG_BER },
2523 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
2524 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
2525 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
2526 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
2527 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
2528 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
2529 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
2530 #if 0 /* no longer used (nor supported) */
2531 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
2532 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
2534 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
2535 { BER_BVC("None"), LDAP_DEBUG_NONE },
2539 return slap_verbmasks_init( &loglevel_ops, lo );
2543 loglevel_destroy( void )
2545 if ( loglevel_ops ) {
2546 (void)slap_verbmasks_destroy( loglevel_ops );
2548 loglevel_ops = NULL;
2551 static slap_mask_t loglevel_ignore[] = { -1, 0 };
2554 slap_loglevel_register( slap_mask_t m, struct berval *s )
2558 if ( loglevel_ops == NULL ) {
2562 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
2565 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
2573 slap_loglevel_get( struct berval *s, int *l )
2578 if ( loglevel_ops == NULL ) {
2582 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
2583 m |= loglevel_ops[ i ].mask;
2586 for ( i = 1; m & i; i <<= 1 )
2593 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
2596 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
2607 str2loglevel( const char *s, int *l )
2611 if ( loglevel_ops == NULL ) {
2615 i = verb_to_mask( s, loglevel_ops );
2617 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
2621 *l = loglevel_ops[ i ].mask;
2627 loglevel2str( int l )
2629 struct berval bv = BER_BVNULL;
2631 loglevel2bv( l, &bv );
2637 loglevel2bv( int l, struct berval *bv )
2639 if ( loglevel_ops == NULL ) {
2645 return enum_to_verb( loglevel_ops, l, bv ) == -1;
2649 loglevel2bvarray( int l, BerVarray *bva )
2651 if ( loglevel_ops == NULL ) {
2655 return mask_to_verbs( loglevel_ops, l, bva );
2659 loglevel_print( FILE *out )
2663 if ( loglevel_ops == NULL ) {
2667 fprintf( out, "Installed log subsystems:\n\n" );
2668 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
2669 fprintf( out, "\t%-30s (%lu)\n",
2670 loglevel_ops[ i ].word.bv_val,
2671 loglevel_ops[ i ].mask );
2674 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
2675 "by specific code\n\n" );
2680 static int config_syslog;
2683 config_loglevel(ConfigArgs *c) {
2686 if ( loglevel_ops == NULL ) {
2690 if (c->op == SLAP_CONFIG_EMIT) {
2691 /* Get default or commandline slapd setting */
2692 if ( ldap_syslog && !config_syslog )
2693 config_syslog = ldap_syslog;
2694 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
2696 } else if ( c->op == LDAP_MOD_DELETE ) {
2700 int level = verb_to_mask( c->line, loglevel_ops );
2701 config_syslog ^= level;
2703 if ( slapMode & SLAP_SERVER_MODE ) {
2704 ldap_syslog = config_syslog;
2709 for( i=1; i < c->argc; i++ ) {
2712 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
2713 if( lutil_atoi( &level, c->argv[i] ) != 0 ) {
2714 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse level", c->argv[0] );
2715 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2716 c->log, c->cr_msg, c->argv[i]);
2720 if ( str2loglevel( c->argv[i], &level ) ) {
2721 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown level", c->argv[0] );
2722 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2723 c->log, c->cr_msg, c->argv[i]);
2727 /* Explicitly setting a zero clears all the levels */
2729 config_syslog |= level;
2733 if ( slapMode & SLAP_SERVER_MODE ) {
2734 ldap_syslog = config_syslog;
2740 config_referral(ConfigArgs *c) {
2742 if (c->op == SLAP_CONFIG_EMIT) {
2743 if ( default_referral ) {
2744 value_add( &c->rvalue_vals, default_referral );
2749 } else if ( c->op == LDAP_MOD_DELETE ) {
2750 if ( c->valx < 0 ) {
2751 ber_bvarray_free( default_referral );
2752 default_referral = NULL;
2755 ch_free( default_referral[i].bv_val );
2756 for (; default_referral[i].bv_val; i++ )
2757 default_referral[i] = default_referral[i+1];
2761 if(validate_global_referral(c->argv[1])) {
2762 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
2763 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2764 c->log, c->cr_msg, c->argv[1]);
2768 ber_str2bv(c->argv[1], 0, 0, &val);
2769 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
2777 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
2778 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
2779 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
2780 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
2781 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
2782 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
2783 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
2784 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
2785 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
2790 config_security(ConfigArgs *c) {
2791 slap_ssf_set_t *set = &c->be->be_ssf_set;
2794 if (c->op == SLAP_CONFIG_EMIT) {
2800 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
2801 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
2804 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
2805 if ( bv.bv_len >= sizeof( numbuf ) ) {
2806 ber_bvarray_free_x( c->rvalue_vals, NULL );
2807 c->rvalue_vals = NULL;
2811 bv.bv_len += sec_keys[i].key.bv_len;
2812 bv.bv_val = ch_malloc( bv.bv_len + 1);
2813 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
2814 strcpy( next, numbuf );
2815 ber_bvarray_add( &c->rvalue_vals, &bv );
2820 for(i = 1; i < c->argc; i++) {
2821 slap_ssf_t *tgt = NULL;
2823 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
2824 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
2825 sec_keys[j].key.bv_len)) {
2826 src = c->argv[i] + sec_keys[j].key.bv_len;
2827 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
2832 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown factor", c->argv[0] );
2833 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2834 c->log, c->cr_msg, c->argv[i]);
2838 if ( lutil_atou( tgt, src ) != 0 ) {
2839 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse factor", c->argv[0] );
2840 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2841 c->log, c->cr_msg, c->argv[i]);
2849 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
2853 for (; !BER_BVISNULL( &an->an_name ); an++) {
2854 /* if buflen == 0, assume the buffer size has been
2855 * already checked otherwise */
2856 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
2857 if ( comma ) *ptr++ = ',';
2858 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
2865 config_updatedn(ConfigArgs *c) {
2866 if (c->op == SLAP_CONFIG_EMIT) {
2867 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
2868 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
2869 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
2873 } else if ( c->op == LDAP_MOD_DELETE ) {
2874 ch_free( c->be->be_update_ndn.bv_val );
2875 BER_BVZERO( &c->be->be_update_ndn );
2876 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
2879 if(SLAP_SHADOW(c->be)) {
2880 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database already shadowed", c->argv[0] );
2881 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2882 c->log, c->cr_msg, 0);
2886 ber_memfree_x( c->value_dn.bv_val, NULL );
2887 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
2888 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
2890 c->be->be_update_ndn = c->value_ndn;
2891 BER_BVZERO( &c->value_dn );
2892 BER_BVZERO( &c->value_ndn );
2894 return config_slurp_shadow( c );
2898 config_shadow( ConfigArgs *c, int flag )
2900 char *notallowed = NULL;
2902 if ( c->be == frontendDB ) {
2903 notallowed = "frontend";
2905 } else if ( SLAP_MONITOR(c->be) ) {
2906 notallowed = "monitor";
2909 if ( notallowed != NULL ) {
2910 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
2914 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SINGLE_SHADOW | flag);
2920 config_updateref(ConfigArgs *c) {
2922 if (c->op == SLAP_CONFIG_EMIT) {
2923 if ( c->be->be_update_refs ) {
2924 value_add( &c->rvalue_vals, c->be->be_update_refs );
2929 } else if ( c->op == LDAP_MOD_DELETE ) {
2930 if ( c->valx < 0 ) {
2931 ber_bvarray_free( c->be->be_update_refs );
2932 c->be->be_update_refs = NULL;
2935 ch_free( c->be->be_update_refs[i].bv_val );
2936 for (; c->be->be_update_refs[i].bv_val; i++)
2937 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
2941 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
2942 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must appear after syncrepl or updatedn",
2944 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2945 c->log, c->cr_msg, 0);
2949 if(validate_global_referral(c->argv[1])) {
2950 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
2951 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2952 c->log, c->cr_msg, c->argv[1]);
2955 ber_str2bv(c->argv[1], 0, 0, &val);
2956 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
2961 config_obsolete(ConfigArgs *c) {
2962 if (c->op == SLAP_CONFIG_EMIT)
2965 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> keyword is obsolete (ignored)",
2967 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0);
2972 config_include(ConfigArgs *c) {
2973 int savelineno = c->lineno;
2976 ConfigFile *cfsave = cfn;
2977 ConfigFile *cf2 = NULL;
2979 /* Leftover from RE23. No dynamic config for include files */
2980 if ( c->op == SLAP_CONFIG_EMIT || c->op == LDAP_MOD_DELETE )
2983 cf = ch_calloc( 1, sizeof(ConfigFile));
2984 if ( cfn->c_kids ) {
2985 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
2991 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
2992 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
2993 c->lineno = savelineno - 1;
2996 if ( cf2 ) cf2->c_sibs = NULL;
2997 else cfn->c_kids = NULL;
2998 ch_free( cf->c_file.bv_val );
3008 config_tls_option(ConfigArgs *c) {
3010 LDAP *ld = slap_tls_ld;
3012 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
3013 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
3014 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
3015 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
3016 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
3017 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
3018 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
3020 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
3022 default: Debug(LDAP_DEBUG_ANY, "%s: "
3023 "unknown tls_option <0x%x>\n",
3024 c->log, c->type, 0);
3027 if (c->op == SLAP_CONFIG_EMIT) {
3028 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
3029 } else if ( c->op == LDAP_MOD_DELETE ) {
3030 return ldap_pvt_tls_set_option( ld, flag, NULL );
3032 ch_free(c->value_string);
3033 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
3036 /* FIXME: this ought to be provided by libldap */
3038 config_tls_config(ConfigArgs *c) {
3041 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
3042 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
3044 Debug(LDAP_DEBUG_ANY, "%s: "
3045 "unknown tls_option <0x%x>\n",
3046 c->log, c->type, 0);
3049 if (c->op == SLAP_CONFIG_EMIT) {
3050 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
3051 } else if ( c->op == LDAP_MOD_DELETE ) {
3053 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
3055 ch_free( c->value_string );
3056 if ( isdigit( (unsigned char)c->argv[1][0] ) ) {
3057 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
3058 Debug(LDAP_DEBUG_ANY, "%s: "
3059 "unable to parse %s \"%s\"\n",
3060 c->log, c->argv[0], c->argv[1] );
3063 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
3065 return(ldap_int_tls_config(slap_tls_ld, flag, c->argv[1]));
3070 static CfEntryInfo *
3071 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
3081 if ( dn_match( &root->ce_entry->e_nname, dn ))
3084 c = dn->bv_val+dn->bv_len;
3085 for (;*c != ',';c--);
3089 for (--c;c>dn->bv_val && *c != ',';c--);
3093 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
3095 root = root->ce_kids;
3097 for (;root;root=root->ce_sibs) {
3098 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
3099 if ( cdn.bv_val == dn->bv_val ) {
3109 typedef struct setup_cookie {
3119 config_ldif_resp( Operation *op, SlapReply *rs )
3121 if ( rs->sr_type == REP_SEARCH ) {
3122 setup_cookie *sc = op->o_callback->sc_private;
3124 sc->cfb->cb_got_ldif = 1;
3125 /* Does the frontend exist? */
3126 if ( !sc->got_frontend ) {
3127 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
3128 "olcDatabase", STRLENOF( "olcDatabase" ))) {
3129 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3130 STRLENOF( "olcDatabase" ), "={-1}frontend",
3131 STRLENOF( "={-1}frontend" ))) {
3134 sc->ca->be = frontendDB;
3135 sc->ca->bi = frontendDB->bd_info;
3136 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
3137 rdn.bv_val = sc->ca->log;
3138 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3139 "%s=" SLAP_X_ORDERED_FMT "%s",
3140 cfAd_database->ad_cname.bv_val, -1,
3141 sc->ca->bi->bi_type);
3143 sc->frontend = config_build_entry( op, rs,
3144 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
3145 sc->ca->be->be_cf_ocs );
3154 /* Does the configDB exist? */
3155 if ( sc->got_frontend && !sc->got_config &&
3156 !strncmp( rs->sr_entry->e_nname.bv_val,
3157 "olcDatabase", STRLENOF( "olcDatabase" ))) {
3158 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3159 STRLENOF( "olcDatabase" ), "={0}config",
3160 STRLENOF( "={0}config" ))) {
3163 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
3164 sc->ca->bi = sc->ca->be->bd_info;
3165 rdn.bv_val = sc->ca->log;
3166 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3167 "%s=" SLAP_X_ORDERED_FMT "%s",
3168 cfAd_database->ad_cname.bv_val, 0,
3169 sc->ca->bi->bi_type);
3171 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
3172 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
3179 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
3180 if ( rs->sr_err != LDAP_SUCCESS ) {
3181 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
3182 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg, 0 );
3188 /* Configure and read the underlying back-ldif store */
3190 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
3191 CfBackInfo *cfb = be->be_private;
3197 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
3198 Connection conn = {0};
3199 OperationBuffer opbuf;
3201 SlapReply rs = {REP_RESULT};
3202 Filter filter = { LDAP_FILTER_PRESENT };
3203 struct berval filterstr = BER_BVC("(objectclass=*)");
3206 /* Is the config directory available? */
3207 if ( stat( dir, &st ) < 0 ) {
3208 /* No, so don't bother using the backing store.
3209 * All changes will be in-memory only.
3214 cfb->cb_db.bd_info = backend_info( "ldif" );
3215 if ( !cfb->cb_db.bd_info )
3216 return 0; /* FIXME: eventually this will be a fatal error */
3218 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
3221 cfb->cb_db.be_suffix = be->be_suffix;
3222 cfb->cb_db.be_nsuffix = be->be_nsuffix;
3224 /* The suffix is always "cn=config". The underlying DB's rootdn
3225 * is always the same as the suffix.
3227 cfb->cb_db.be_rootdn = be->be_suffix[0];
3228 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
3230 ber_str2bv( dir, 0, 1, &cfdir );
3235 argv[0] = "directory";
3236 argv[1] = (char *)dir;
3241 c.table = Cft_Database;
3243 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
3247 if ( config_add_vals( ct, &c ))
3250 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
3254 void *thrctx = ldap_pvt_thread_pool_context();
3257 connection_fake_init( &conn, &opbuf, thrctx );
3260 filter.f_desc = slap_schema.si_ad_objectClass;
3262 op->o_tag = LDAP_REQ_SEARCH;
3264 op->ors_filter = &filter;
3265 op->ors_filterstr = filterstr;
3266 op->ors_scope = LDAP_SCOPE_SUBTREE;
3268 op->o_dn = c.be->be_rootdn;
3269 op->o_ndn = c.be->be_rootndn;
3271 op->o_req_dn = be->be_suffix[0];
3272 op->o_req_ndn = be->be_nsuffix[0];
3274 op->ors_tlimit = SLAP_NO_LIMIT;
3275 op->ors_slimit = SLAP_NO_LIMIT;
3277 op->ors_attrs = slap_anlist_all_attributes;
3278 op->ors_attrsonly = 0;
3280 op->o_callback = &cb;
3283 cb.sc_private = ≻
3284 sc.got_frontend = 0;
3289 op->o_bd = &cfb->cb_db;
3291 /* Allow unknown attrs in DNs */
3292 prev_DN_strict = slap_DN_strict;
3295 rc = op->o_bd->be_search( op, &rs );
3297 /* Restore normal DN validation */
3298 slap_DN_strict = prev_DN_strict;
3300 op->o_tag = LDAP_REQ_ADD;
3301 if ( rc == LDAP_SUCCESS && sc.frontend ) {
3302 op->ora_e = sc.frontend;
3303 rc = op->o_bd->be_add( op, &rs );
3305 if ( rc == LDAP_SUCCESS && sc.config ) {
3306 op->ora_e = sc.config;
3307 rc = op->o_bd->be_add( op, &rs );
3309 ldap_pvt_thread_pool_context_reset( thrctx );
3312 /* ITS#4194 - only use if it's present, or we're converting. */
3313 if ( !readit || rc == LDAP_SUCCESS )
3314 cfb->cb_use_ldif = 1;
3320 CfOc_cmp( const void *c1, const void *c2 ) {
3321 const ConfigOCs *co1 = c1;
3322 const ConfigOCs *co2 = c2;
3324 return ber_bvcmp( co1->co_name, co2->co_name );
3328 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
3331 i = init_config_attrs( ct );
3334 /* set up the objectclasses */
3335 i = init_config_ocs( ocs );
3338 for (i=0; ocs[i].co_def; i++) {
3339 if ( ocs[i].co_oc ) {
3340 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
3341 if ( !ocs[i].co_table )
3342 ocs[i].co_table = ct;
3343 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
3350 read_config(const char *fname, const char *dir) {
3353 const char *cfdir, *cfname;
3356 /* Setup the config backend */
3357 be = backend_db_init( "config", NULL, 0, NULL );
3361 cfb = be->be_private;
3362 be->be_dfltaccess = ACL_NONE;
3364 /* If no .conf, or a dir was specified, setup the dir */
3365 if ( !fname || dir ) {
3367 /* If explicitly given, check for existence */
3370 if ( stat( dir, &st ) < 0 ) {
3371 Debug( LDAP_DEBUG_ANY,
3372 "invalid config directory %s, error %d\n",
3378 cfdir = SLAPD_DEFAULT_CONFIGDIR;
3380 /* if fname is defaulted, try reading .d */
3381 rc = config_setup_ldif( be, cfdir, !fname );
3384 /* It may be OK if the base object doesn't exist yet. */
3385 if ( rc != LDAP_NO_SUCH_OBJECT )
3387 /* ITS#4194: But if dir was specified and no fname,
3388 * then we were supposed to read the dir. Unless we're
3389 * trying to slapadd the dir...
3391 if ( dir && !fname ) {
3392 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
3394 /* Assume it's slapadd with a config dir, let it continue */
3396 cfb->cb_got_ldif = 1;
3397 cfb->cb_use_ldif = 1;
3402 /* If we read the config from back-ldif, nothing to do here */
3403 if ( cfb->cb_got_ldif ) {
3412 cfname = SLAPD_DEFAULT_CONFIGFILE;
3414 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
3417 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
3420 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
3421 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
3422 &frontendDB->be_schemadn );
3423 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
3424 if ( rc != LDAP_SUCCESS ) {
3425 Debug(LDAP_DEBUG_ANY, "read_config: "
3426 "unable to normalize default schema DN \"%s\"\n",
3427 frontendDB->be_schemadn.bv_val, 0, 0 );
3428 /* must not happen */
3436 config_back_bind( Operation *op, SlapReply *rs )
3438 if ( be_isroot_pw( op ) ) {
3439 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
3440 /* frontend sends result */
3441 return LDAP_SUCCESS;
3444 rs->sr_err = LDAP_INVALID_CREDENTIALS;
3445 send_ldap_result( op, rs );
3451 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
3455 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
3457 rs->sr_attrs = op->ors_attrs;
3458 rs->sr_entry = ce->ce_entry;
3460 rc = send_search_entry( op, rs );
3462 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
3463 if ( ce->ce_kids ) {
3464 rc = config_send( op, rs, ce->ce_kids, 1 );
3465 if ( rc ) return rc;
3468 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
3469 rc = config_send( op, rs, ce, 0 );
3477 static ConfigTable *
3478 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
3483 for (j=0; j<nocs; j++) {
3484 for (i=0; colst[j]->co_table[i].name; i++)
3485 if ( colst[j]->co_table[i].ad == ad ) {
3486 ca->table = colst[j]->co_type;
3487 return &colst[j]->co_table[i];
3493 /* Sort the attributes of the entry according to the order defined
3494 * in the objectclass, with required attributes occurring before
3495 * allowed attributes. For any attributes with sequencing dependencies
3496 * (e.g., rootDN must be defined after suffix) the objectclass must
3497 * list the attributes in the desired sequence.
3500 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
3502 Attribute *a, *head = NULL, *tail = NULL, **prev;
3505 for (i=0; i<nocs; i++) {
3506 if ( colst[i]->co_oc->soc_required ) {
3507 AttributeType **at = colst[i]->co_oc->soc_required;
3508 for (j=0; at[j]; j++) {
3509 for (a=e->e_attrs, prev=&e->e_attrs; a;
3510 prev = &(*prev)->a_next, a=a->a_next) {
3511 if ( a->a_desc == at[j]->sat_ad ) {
3525 if ( colst[i]->co_oc->soc_allowed ) {
3526 AttributeType **at = colst[i]->co_oc->soc_allowed;
3527 for (j=0; at[j]; j++) {
3528 for (a=e->e_attrs, prev=&e->e_attrs; a;
3529 prev = &(*prev)->a_next, a=a->a_next) {
3530 if ( a->a_desc == at[j]->sat_ad ) {
3546 tail->a_next = e->e_attrs;
3552 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
3554 Attribute *a = NULL;
3555 AttributeDescription *ad;
3565 Modifications *ml = ptr;
3567 vals = ml->sml_values;
3570 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
3571 rc = ordered_value_sort( a, 1 );
3573 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
3574 ad->ad_cname.bv_val );
3578 for ( i=0; vals[i].bv_val; i++ ) {
3579 ca->line = vals[i].bv_val;
3580 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
3581 ca->line[0] == '{' ) {
3582 char *idx = strchr( ca->line, '}' );
3583 if ( idx ) ca->line = idx+1;
3585 rc = config_parse_vals( ct, ca, i );
3594 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
3597 struct berval rtype, rval;
3599 AttributeDescription *ad = NULL;
3601 dnRdn( &e->e_name, rdn );
3602 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
3603 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
3604 rtype.bv_val = rdn->bv_val;
3605 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
3608 slap_bv2ad( &rtype, &ad, &rs->sr_text );
3609 a = attr_find( e->e_attrs, ad );
3610 if (!a ) return LDAP_NAMING_VIOLATION;
3617 config_rename_kids( CfEntryInfo *ce )
3620 struct berval rdn, nrdn;
3622 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
3623 dnRdn ( &ce2->ce_entry->e_name, &rdn );
3624 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
3625 free( ce2->ce_entry->e_name.bv_val );
3626 free( ce2->ce_entry->e_nname.bv_val );
3627 build_new_dn( &ce2->ce_entry->e_name, &ce->ce_entry->e_name,
3629 build_new_dn( &ce2->ce_entry->e_nname, &ce->ce_entry->e_nname,
3631 config_rename_kids( ce2 );
3636 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
3637 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
3638 struct berval *nnewrdn, int use_ldif )
3642 struct berval odn, ondn;
3646 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
3647 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
3650 free( a->a_vals[0].bv_val );
3651 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
3652 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
3653 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
3654 strcpy( a->a_vals[0].bv_val, ptr1 );
3656 if ( a->a_nvals != a->a_vals ) {
3657 free( a->a_nvals[0].bv_val );
3658 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
3659 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
3660 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
3661 strcpy( a->a_nvals[0].bv_val, ptr1 );
3664 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
3665 BackendDB *be = op->o_bd;
3666 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
3667 struct berval dn, ndn, xdn, xndn;
3669 op->o_bd = &cfb->cb_db;
3671 /* Save current rootdn; use the underlying DB's rootdn */
3675 xndn = op->o_req_ndn;
3676 op->o_dn = op->o_bd->be_rootdn;
3677 op->o_ndn = op->o_bd->be_rootndn;
3679 op->o_req_ndn = ondn;
3681 scp = op->o_callback;
3682 op->o_callback = ≻
3683 op->orr_newrdn = *newrdn;
3684 op->orr_nnewrdn = *nnewrdn;
3685 op->orr_newSup = NULL;
3686 op->orr_nnewSup = NULL;
3687 op->orr_deleteoldrdn = 1;
3688 op->orr_modlist = NULL;
3689 slap_modrdn2mods( op, rs );
3690 slap_mods_opattrs( op, &op->orr_modlist, 1 );
3691 rc = op->o_bd->be_modrdn( op, rs );
3692 slap_mods_free( op->orr_modlist, 1 );
3695 op->o_callback = scp;
3699 op->o_req_ndn = xndn;
3702 free( ondn.bv_val );
3704 config_rename_kids( e->e_private );
3709 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
3710 Entry *e, int idx, int tailindex, int use_ldif )
3712 struct berval ival, newrdn, nnewrdn;
3715 char ibuf[32], *ptr1, *ptr2 = NULL;
3718 rc = config_rename_attr( rs, e, &rdn, &a );
3719 if ( rc ) return rc;
3722 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
3723 if ( ival.bv_len >= sizeof( ibuf ) ) {
3724 return LDAP_NAMING_VIOLATION;
3727 newrdn.bv_len = rdn.bv_len + ival.bv_len;
3728 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
3731 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
3732 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3735 ptr2 = ber_bvchr( &rdn, '}' );
3739 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
3741 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
3742 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
3743 a->a_desc->ad_cname.bv_len );
3745 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3746 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
3750 /* Do the equivalent of ModRDN */
3751 /* Replace DN / NDN */
3752 newrdn.bv_len = ptr1 - newrdn.bv_val;
3753 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
3754 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
3756 free( nnewrdn.bv_val );
3757 free( newrdn.bv_val );
3762 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
3763 SlapReply *rs, int *renum, int *ibase )
3766 int index = -1, gotindex = 0, nsibs, rc = 0;
3767 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
3768 char *ptr1, *ptr2 = NULL;
3771 if ( renum ) *renum = 0;
3773 /* These entries don't get indexed/renumbered */
3774 if ( ce_type == Cft_Global ) return 0;
3775 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
3777 if ( ce_type == Cft_Module )
3780 /* See if the rdn has an index already */
3781 dnRdn( &e->e_name, &rdn );
3782 if ( ce_type == Cft_Database ) {
3783 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
3784 "frontend", STRLENOF("frontend") ))
3786 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
3787 "config", STRLENOF("config") ))
3790 ptr1 = ber_bvchr( &e->e_name, '{' );
3791 if ( ptr1 && ptr1 - e->e_name.bv_val < rdn.bv_len ) {
3793 ptr2 = strchr( ptr1, '}' );
3794 if (!ptr2 || ptr2 - e->e_name.bv_val > rdn.bv_len)
3795 return LDAP_NAMING_VIOLATION;
3796 if ( ptr2-ptr1 == 1)
3797 return LDAP_NAMING_VIOLATION;
3799 index = strtol( ptr1 + 1, &next, 10 );
3800 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
3801 return LDAP_NAMING_VIOLATION;
3804 /* Special case, we allow -1 for the frontendDB */
3805 if ( index != -1 || !isfrontend )
3806 return LDAP_NAMING_VIOLATION;
3808 if ( isconfig && index != 0 ){
3809 return LDAP_NAMING_VIOLATION;
3813 /* count related kids */
3814 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
3815 if ( ce->ce_type == ce_type ) nsibs++;
3818 /* account for -1 frontend */
3819 if ( ce_type == Cft_Database )
3822 if ( index != nsibs ) {
3824 if ( index < nsibs ) {
3825 if ( tailindex ) return LDAP_NAMING_VIOLATION;
3826 /* Siblings need to be renumbered */
3827 if ( index != -1 || !isfrontend )
3831 /* config DB is always "0" */
3832 if ( isconfig && index == -1 ) {
3835 if ( !isfrontend && index == -1 ) {
3839 /* just make index = nsibs */
3841 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
3844 if ( ibase ) *ibase = index;
3845 if ( renum ) *renum = renumber;
3850 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
3855 co.co_name = &oc->soc_cname;
3856 cop = avl_find( CfOcTree, &co, CfOc_cmp );
3860 /* check for duplicates */
3861 for ( i = 0; i < *nocs; i++ ) {
3862 if ( *copp && (*copp)[i] == cop ) {
3868 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
3869 if ( tmp == NULL ) {
3873 (*copp)[*nocs] = cop;
3878 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
3879 if ( count_oc( *sups, copp, nocs ) ) {
3888 count_ocs( Attribute *oc_at, int *nocs )
3891 ConfigOCs **colst = NULL;
3895 for ( i = 0; !BER_BVISNULL( &oc_at->a_nvals[i] ); i++ )
3899 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
3901 assert( oc != NULL );
3902 if ( count_oc( oc, &colst, nocs ) ) {
3912 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
3914 /* Leftover from RE23. Never parse this entry */
3915 return LDAP_COMPARE_TRUE;
3919 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
3923 /* This entry is hardcoded, don't re-parse it */
3924 if ( p->ce_type == Cft_Global ) {
3925 cfn = p->ce_private;
3927 return LDAP_COMPARE_TRUE;
3929 if ( p->ce_type != Cft_Schema )
3930 return LDAP_CONSTRAINT_VIOLATION;
3932 cfn = ch_calloc( 1, sizeof(ConfigFile) );
3934 cfo = p->ce_private;
3935 cfn->c_sibs = cfo->c_kids;
3937 return LDAP_SUCCESS;
3941 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3943 if ( p->ce_type != Cft_Global ) {
3944 return LDAP_CONSTRAINT_VIOLATION;
3946 ca->be = frontendDB; /* just to get past check_vals */
3947 return LDAP_SUCCESS;
3951 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3953 if ( p->ce_type != Cft_Global ) {
3954 return LDAP_CONSTRAINT_VIOLATION;
3956 return LDAP_SUCCESS;
3960 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3962 if ( p->ce_type != Cft_Global ) {
3963 return LDAP_CONSTRAINT_VIOLATION;
3965 return LDAP_SUCCESS;
3969 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3971 if ( p->ce_type != Cft_Database ) {
3972 return LDAP_CONSTRAINT_VIOLATION;
3975 return LDAP_SUCCESS;
3979 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
3984 AttributeDescription *ad;
3989 if ( cfn->c_cr_head ) {
3990 struct berval bv = BER_BVC("olcDitContentRules");
3992 slap_bv2ad( &bv, &ad, &text );
3993 ct = config_find_table( colst, nocs, ad, ca );
3994 config_del_vals( ct, ca );
3996 if ( cfn->c_oc_head ) {
3997 struct berval bv = BER_BVC("olcObjectClasses");
3999 slap_bv2ad( &bv, &ad, &text );
4000 ct = config_find_table( colst, nocs, ad, ca );
4001 config_del_vals( ct, ca );
4003 if ( cfn->c_at_head ) {
4004 struct berval bv = BER_BVC("olcAttributeTypes");
4006 slap_bv2ad( &bv, &ad, &text );
4007 ct = config_find_table( colst, nocs, ad, ca );
4008 config_del_vals( ct, ca );
4010 if ( cfn->c_om_head ) {
4011 struct berval bv = BER_BVC("olcObjectIdentifier");
4013 slap_bv2ad( &bv, &ad, &text );
4014 ct = config_find_table( colst, nocs, ad, ca );
4015 config_del_vals( ct, ca );
4017 cfo = p->ce_private;
4018 cfo->c_kids = cfn->c_sibs;
4023 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
4025 int rc = LDAP_CONSTRAINT_VIOLATION;
4028 if ( (*cop)->co_ldadd ) {
4029 rc = (*cop)->co_ldadd( last, e, ca );
4030 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4035 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
4036 ConfigOCs co = { 0 };
4038 co.co_name = &(*ocp)->soc_cname;
4039 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
4040 if ( *cop == NULL ) {
4044 rc = config_add_oc( cop, last, e, ca );
4045 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4053 /* Parse an LDAP entry into config directives */
4055 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
4056 int *renum, Operation *op )
4058 CfEntryInfo *ce, *last = NULL;
4059 ConfigOCs co, *coptr, **colst;
4060 Attribute *a, *oc_at, *soc_at;
4061 int i, ibase = -1, nocs, rc = 0;
4064 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
4066 memset( ca, 0, sizeof(ConfigArgs));
4068 /* Make sure parent exists and entry does not. But allow
4069 * Databases and Overlays to be inserted. Don't do any
4070 * auto-renumbering if manageDSAit control is present.
4072 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
4074 if ( ( op && op->o_managedsait ) ||
4075 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
4076 ce->ce_type != Cft_Module ) )
4078 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4079 "DN=\"%s\" already exists\n",
4080 log_prefix, e->e_name.bv_val, 0 );
4081 return LDAP_ALREADY_EXISTS;
4085 dnParent( &e->e_nname, &pdn );
4087 /* If last is NULL, the new entry is the root/suffix entry,
4088 * otherwise last should be the parent.
4090 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
4092 rs->sr_matched = last->ce_entry->e_name.bv_val;
4094 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4095 "DN=\"%s\" not child of DN=\"%s\"\n",
4096 log_prefix, e->e_name.bv_val,
4097 last->ce_entry->e_name.bv_val );
4098 return LDAP_NO_SUCH_OBJECT;
4102 /* No parent, must be root. This will never happen... */
4103 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
4104 return LDAP_NO_SUCH_OBJECT;
4107 if ( last && !access_allowed( op, last->ce_entry,
4108 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
4110 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4111 "DN=\"%s\" no write access to \"children\" of parent\n",
4112 log_prefix, e->e_name.bv_val, 0 );
4113 return LDAP_INSUFFICIENT_ACCESS;
4117 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4119 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4120 "DN=\"%s\" no objectClass\n",
4121 log_prefix, e->e_name.bv_val, 0 );
4122 return LDAP_OBJECT_CLASS_VIOLATION;
4125 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4127 ObjectClass *soc = NULL;
4128 char textbuf[ SLAP_TEXT_BUFLEN ];
4129 const char *text = textbuf;
4131 /* FIXME: check result */
4132 rc = structural_class( oc_at->a_nvals, &soc, NULL,
4133 &text, textbuf, sizeof(textbuf), NULL );
4134 if ( rc != LDAP_SUCCESS ) {
4135 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4136 "DN=\"%s\" no structural objectClass (%s)\n",
4137 log_prefix, e->e_name.bv_val, text );
4140 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
4141 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4142 if ( soc_at == NULL ) {
4143 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4144 "DN=\"%s\" no structural objectClass; "
4145 "unable to merge computed class %s\n",
4146 log_prefix, e->e_name.bv_val,
4147 soc->soc_cname.bv_val );
4148 return LDAP_OBJECT_CLASS_VIOLATION;
4151 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4152 "DN=\"%s\" no structural objectClass; "
4153 "computed objectClass %s merged\n",
4154 log_prefix, e->e_name.bv_val,
4155 soc->soc_cname.bv_val );
4158 /* Fake the coordinates based on whether we're part of an
4159 * LDAP Add or if reading the config dir
4162 ca->fname = "slapd";
4165 ca->fname = cfdir.bv_val;
4170 co.co_name = &soc_at->a_nvals[0];
4171 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
4172 if ( coptr == NULL ) {
4173 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4174 "DN=\"%s\" no structural objectClass in configuration table\n",
4175 log_prefix, e->e_name.bv_val, 0 );
4176 return LDAP_OBJECT_CLASS_VIOLATION;
4179 /* Only the root can be Cft_Global, everything else must
4180 * have a parent. Only limited nesting arrangements are allowed.
4182 rc = LDAP_CONSTRAINT_VIOLATION;
4183 if ( coptr->co_type == Cft_Global && !last ) {
4184 cfn = cfb->cb_config;
4186 ca->be = frontendDB; /* just to get past check_vals */
4190 colst = count_ocs( oc_at, &nocs );
4192 /* Check whether the Add is allowed by its parent, and do
4193 * any necessary arg setup
4196 rc = config_add_oc( &coptr, last, e, ca );
4197 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4198 for ( i = 0; i<nocs; i++ ) {
4199 /* Already checked these */
4200 if ( colst[i]->co_oc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
4202 if ( colst[i]->co_ldadd &&
4203 ( rc = colst[i]->co_ldadd( last, e, ca ))
4204 != LDAP_CONSTRAINT_VIOLATION ) {
4210 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4211 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4212 "DN=\"%s\" no structural objectClass add function\n",
4213 log_prefix, e->e_name.bv_val, 0 );
4214 return LDAP_OBJECT_CLASS_VIOLATION;
4218 /* Add the entry but don't parse it, we already have its contents */
4219 if ( rc == LDAP_COMPARE_TRUE ) {
4224 if ( rc != LDAP_SUCCESS )
4227 /* Parse all the values and check for simple syntax errors before
4228 * performing any set actions.
4230 * If doing an LDAPadd, check for indexed names and any necessary
4231 * renaming/renumbering. Entries that don't need indexed names are
4232 * ignored. Entries that need an indexed name and arrive without one
4233 * are assigned to the end. Entries that arrive with an index may
4234 * cause the following entries to be renumbered/bumped down.
4236 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
4237 * don't allow Adding an entry with an index that's already in use.
4238 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
4240 * These entries can have auto-assigned indexes (appended to the end)
4241 * but only the other types support auto-renumbering of siblings.
4244 rc = check_name_index( last, coptr->co_type, e, rs, renum,
4249 if ( renum && *renum && coptr->co_type != Cft_Database &&
4250 coptr->co_type != Cft_Overlay )
4252 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
4253 "operation requires sibling renumbering" );
4254 rc = LDAP_UNWILLING_TO_PERFORM;
4259 init_config_argv( ca );
4261 /* Make sure we process attrs in the required order */
4262 sort_attrs( e, colst, nocs );
4264 for ( a = e->e_attrs; a; a = a->a_next ) {
4265 if ( a == oc_at ) continue;
4266 ct = config_find_table( colst, nocs, a->a_desc, ca );
4267 if ( !ct ) continue; /* user data? */
4268 rc = check_vals( ct, ca, a, 1 );
4269 if ( rc ) goto done_noop;
4272 /* Basic syntax checks are OK. Do the actual settings. */
4273 for ( a=e->e_attrs; a; a=a->a_next ) {
4274 if ( a == oc_at ) continue;
4275 ct = config_find_table( colst, nocs, a->a_desc, ca );
4276 if ( !ct ) continue; /* user data? */
4277 for (i=0; a->a_vals[i].bv_val; i++) {
4279 ca->line = a->a_vals[i].bv_val;
4280 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
4281 ptr = strchr( ca->line, '}' );
4283 iptr = strchr( ca->line, '{' );
4287 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
4289 ca->valx = strtol( iptr+1, NULL, 0 );
4296 rc = config_parse_add( ct, ca, i );
4304 /* Newly added databases and overlays need to be started up */
4305 if ( CONFIG_ONLINE_ADD( ca )) {
4306 if ( colst[0]->co_type == Cft_Database ) {
4307 rc = backend_startup_one( ca->be, &ca->reply );
4309 } else if ( colst[0]->co_type == Cft_Overlay ) {
4310 if ( ca->bi->bi_db_open ) {
4311 BackendInfo *bi_orig = ca->be->bd_info;
4312 ca->be->bd_info = ca->bi;
4313 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
4314 ca->be->bd_info = bi_orig;
4316 } else if ( ca->cleanup ) {
4317 rc = ca->cleanup( ca );
4320 if (ca->cr_msg[0] == '\0')
4321 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
4323 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
4324 ca->log, ca->cr_msg, ca->argv[1] );
4331 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
4332 ce->ce_parent = last;
4333 ce->ce_entry = entry_dup( e );
4334 ce->ce_entry->e_private = ce;
4335 ce->ce_type = colst[0]->co_type;
4338 ce->ce_private = ca->private;
4339 ca->ca_entry = ce->ce_entry;
4342 } else if ( last->ce_kids ) {
4343 CfEntryInfo *c2, **cprev;
4345 /* Advance to first of this type */
4346 cprev = &last->ce_kids;
4347 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
4348 cprev = &c2->ce_sibs;
4351 /* Account for the (-1) frontendDB entry */
4352 if ( ce->ce_type == Cft_Database ) {
4353 if ( ca->be == frontendDB )
4355 else if ( ibase != -1 )
4360 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
4361 cprev = &c2->ce_sibs;
4367 for ( i=0; i<ibase; i++ ) {
4369 cprev = &c2->ce_sibs;
4372 ce->ce_sibs = *cprev;
4380 if ( (colst[0]->co_type == Cft_Database) && ca->be ) {
4381 if ( ca->be != frontendDB )
4382 backend_destroy_one( ca->be, 1 );
4383 } else if ( (colst[0]->co_type == Cft_Overlay) && ca->bi ) {
4384 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
4385 } else if ( colst[0]->co_type == Cft_Schema ) {
4386 schema_destroy_one( ca, colst, nocs, last );
4391 ch_free( ca->argv );
4392 if ( colst ) ch_free( colst );
4396 #define BIGTMP 10000
4398 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
4399 int base, int rebase, int max, int use_ldif )
4401 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
4402 ConfigType etype = ce->ce_type;
4403 int count = 0, rc = 0;
4405 /* Reverse ce list */
4406 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
4407 if (ce2->ce_type != etype) {
4412 ce2->ce_sibs = cetmp;
4415 if ( max && count >= max ) {
4421 /* Move original to a temp name until increments are done */
4423 ce->ce_entry->e_private = NULL;
4424 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4425 base+BIGTMP, 0, use_ldif );
4426 ce->ce_entry->e_private = ce;
4428 /* start incrementing */
4429 for (ce2=cetmp; ce2; ce2=ce3) {
4431 ce2->ce_sibs = cerem;
4434 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
4435 count+base, 0, use_ldif );
4439 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4440 base, 0, use_ldif );
4445 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
4446 CfEntryInfo *ce2, int old, int use_ldif )
4450 /* Renumber original to a temp value */
4451 ce->ce_entry->e_private = NULL;
4452 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4453 old+BIGTMP, 0, use_ldif );
4454 ce->ce_entry->e_private = ce;
4456 /* start decrementing */
4457 for (; ce2 != ce; ce2=ce2->ce_sibs) {
4458 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
4459 count+old, 0, use_ldif );
4462 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4463 count+old, 0, use_ldif );
4466 /* Parse an LDAP entry into config directives, then store in underlying
4470 config_back_add( Operation *op, SlapReply *rs )
4476 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
4477 NULL, ACL_WADD, NULL )) {
4478 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4482 cfb = (CfBackInfo *)op->o_bd->be_private;
4484 /* add opattrs for syncprov */
4486 char textbuf[SLAP_TEXT_BUFLEN];
4487 size_t textlen = sizeof textbuf;
4488 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1,
4489 &rs->sr_text, textbuf, sizeof( textbuf ) );
4490 if ( rs->sr_err != LDAP_SUCCESS )
4492 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
4493 if ( rs->sr_err != LDAP_SUCCESS ) {
4494 Debug( LDAP_DEBUG_TRACE,
4495 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
4496 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
4501 ldap_pvt_thread_pool_pause( &connection_pool );
4504 * 1) check for existence of entry
4505 * 2) check for sibling renumbering
4506 * 3) perform internal add
4507 * 4) perform any necessary renumbering
4508 * 5) store entry in underlying database
4510 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
4511 if ( rs->sr_err != LDAP_SUCCESS ) {
4512 rs->sr_text = ca.cr_msg;
4517 CfEntryInfo *ce = ca.ca_entry->e_private;
4518 req_add_s addr = op->oq_add;
4519 op->o_tag = LDAP_REQ_MODRDN;
4520 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
4521 op->o_tag = LDAP_REQ_ADD;
4523 if ( rs->sr_err != LDAP_SUCCESS ) {
4528 if ( cfb->cb_use_ldif ) {
4529 BackendDB *be = op->o_bd;
4530 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4531 struct berval dn, ndn;
4533 op->o_bd = &cfb->cb_db;
4535 /* Save current rootdn; use the underlying DB's rootdn */
4538 op->o_dn = op->o_bd->be_rootdn;
4539 op->o_ndn = op->o_bd->be_rootndn;
4541 scp = op->o_callback;
4542 op->o_callback = ≻
4543 op->o_bd->be_add( op, rs );
4545 op->o_callback = scp;
4551 ldap_pvt_thread_pool_resume( &connection_pool );
4554 send_ldap_result( op, rs );
4555 slap_graduate_commit_csn( op );
4559 typedef struct delrec {
4560 struct delrec *next;
4566 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
4571 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
4572 ca->line[0] == '{' )
4574 char *ptr = strchr( ca->line + 1, '}' );
4578 ca->valx = strtol( ca->line + 1, &next, 0 );
4579 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
4585 rc = config_parse_add( ct, ca, i );
4593 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
4596 int rc = LDAP_UNWILLING_TO_PERFORM;
4598 Entry *e = ce->ce_entry;
4599 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
4604 delrec *dels = NULL, *deltail = NULL;
4606 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4607 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
4609 colst = count_ocs( oc_at, &nocs );
4611 /* make sure add/del flags are clear; should always be true */
4612 for ( s = save_attrs; s; s = s->a_next ) {
4613 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
4616 e->e_attrs = attrs_dup( e->e_attrs );
4618 init_config_argv( ca );
4621 ca->private = ce->ce_private;
4623 ca->fname = "slapd";
4625 strcpy( ca->log, "back-config" );
4627 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
4628 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
4629 switch (ml->sml_op) {
4630 case LDAP_MOD_DELETE:
4631 case LDAP_MOD_REPLACE: {
4632 BerVarray vals = NULL, nvals = NULL;
4634 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
4636 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
4637 ml->sml_desc->ad_cname.bv_val );
4640 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4641 vals = ml->sml_values;
4642 nvals = ml->sml_nvalues;
4643 ml->sml_values = NULL;
4644 ml->sml_nvalues = NULL;
4646 /* If we're deleting by values, remember the indexes of the
4647 * values we deleted.
4649 if ( ct && ml->sml_values ) {
4651 i = ml->sml_numvals;
4652 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
4663 rc = modify_delete_vindex(e, &ml->sml_mod,
4664 get_permissiveModify(op),
4665 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
4666 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4667 ml->sml_values = vals;
4668 ml->sml_nvalues = nvals;
4673 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
4676 case SLAP_MOD_SOFTADD: {
4677 int mop = ml->sml_op;
4679 ml->sml_op = LDAP_MOD_ADD;
4681 if ( ct->arg_type & ARG_NO_INSERT ) {
4682 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
4684 navals = a->a_numvals;
4687 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
4688 if ( ml->sml_values[i].bv_val[0] == '{' &&
4691 char *next, *val = ml->sml_values[i].bv_val + 1;
4694 j = strtol( val, &next, 0 );
4695 if ( next == val || next[ 0 ] != '}' || j < navals ) {
4697 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
4698 ml->sml_desc->ad_cname.bv_val );
4702 rc = check_vals( ct, ca, ml, 0 );
4703 if ( rc ) goto out_noop;
4706 rc = modify_add_values(e, &ml->sml_mod,
4707 get_permissiveModify(op),
4708 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
4710 /* If value already exists, show success here
4711 * and ignore this operation down below.
4713 if ( mop == SLAP_MOD_SOFTADD ) {
4714 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
4724 case LDAP_MOD_INCREMENT: /* FIXME */
4729 if(rc != LDAP_SUCCESS) break;
4732 if ( rc == LDAP_SUCCESS) {
4733 /* check that the entry still obeys the schema */
4734 rc = entry_schema_check(op, e, NULL, 0, 0,
4735 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
4736 if ( rc ) goto out_noop;
4738 /* Basic syntax checks are OK. Do the actual settings. */
4739 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
4740 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
4741 if ( !ct ) continue;
4743 s = attr_find( save_attrs, ml->sml_desc );
4744 a = attr_find( e->e_attrs, ml->sml_desc );
4746 switch (ml->sml_op) {
4747 case LDAP_MOD_DELETE:
4748 case LDAP_MOD_REPLACE: {
4749 BerVarray vals = NULL, nvals = NULL;
4752 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4753 vals = ml->sml_values;
4754 nvals = ml->sml_nvalues;
4755 ml->sml_values = NULL;
4756 ml->sml_nvalues = NULL;
4759 if ( ml->sml_values )
4762 /* If we didn't delete the whole attribute */
4763 if ( ml->sml_values && a ) {
4764 struct berval *mvals;
4767 if ( ml->sml_nvalues )
4768 mvals = ml->sml_nvalues;
4770 mvals = ml->sml_values;
4772 /* use the indexes we saved up above */
4773 for (i=0; i < d->nidx; i++) {
4774 struct berval bv = *mvals++;
4775 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
4776 bv.bv_val[0] == '{' ) {
4777 ptr = strchr( bv.bv_val, '}' ) + 1;
4778 bv.bv_len -= ptr - bv.bv_val;
4781 ca->line = bv.bv_val;
4782 ca->valx = d->idx[i];
4783 rc = config_del_vals( ct, ca );
4784 if ( rc != LDAP_SUCCESS ) break;
4786 s->a_flags |= SLAP_ATTR_IXDEL;
4787 for (j=i+1; j < d->nidx; j++)
4788 if ( d->idx[j] >d->idx[i] )
4794 rc = config_del_vals( ct, ca );
4795 if ( rc ) rc = LDAP_OTHER;
4797 s->a_flags |= SLAP_ATTR_IXDEL;
4799 if ( ml->sml_values ) {
4804 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4805 ml->sml_values = vals;
4806 ml->sml_nvalues = nvals;
4808 if ( !vals || rc != LDAP_SUCCESS )
4811 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
4814 for (i=0; ml->sml_values[i].bv_val; i++) {
4815 ca->line = ml->sml_values[i].bv_val;
4817 rc = config_modify_add( ct, ca, ml->sml_desc, i );
4820 a->a_flags |= SLAP_ATTR_IXADD;
4827 /* Undo for a failed operation */
4828 if ( rc != LDAP_SUCCESS ) {
4829 for ( s = save_attrs; s; s = s->a_next ) {
4830 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
4831 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
4832 ct = config_find_table( colst, nocs, s->a_desc, ca );
4833 a = attr_find( e->e_attrs, s->a_desc );
4835 /* clear the flag so the add check below will skip it */
4836 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
4839 config_del_vals( ct, ca );
4841 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
4842 ca->line = s->a_vals[i].bv_val;
4844 config_modify_add( ct, ca, s->a_desc, i );
4848 for ( a = e->e_attrs; a; a = a->a_next ) {
4849 if ( a->a_flags & SLAP_ATTR_IXADD ) {
4850 ct = config_find_table( colst, nocs, a->a_desc, ca );
4853 config_del_vals( ct, ca );
4854 s = attr_find( save_attrs, a->a_desc );
4856 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
4857 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
4858 ca->line = s->a_vals[i].bv_val;
4860 config_modify_add( ct, ca, s->a_desc, i );
4870 if ( rc == LDAP_SUCCESS ) {
4871 attrs_free( save_attrs );
4873 attrs_free( e->e_attrs );
4874 e->e_attrs = save_attrs;
4876 ch_free( ca->argv );
4877 if ( colst ) ch_free( colst );
4879 deltail = dels->next;
4888 config_back_modify( Operation *op, SlapReply *rs )
4891 CfEntryInfo *ce, *last;
4893 ConfigArgs ca = {0};
4896 AttributeDescription *rad = NULL;
4898 cfb = (CfBackInfo *)op->o_bd->be_private;
4900 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
4903 rs->sr_matched = last->ce_entry->e_name.bv_val;
4904 rs->sr_err = LDAP_NO_SUCH_OBJECT;
4908 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
4909 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4913 /* Get type of RDN */
4914 rdn = ce->ce_entry->e_nname;
4915 ptr = strchr( rdn.bv_val, '=' );
4916 rdn.bv_len = ptr - rdn.bv_val;
4917 slap_bv2ad( &rdn, &rad, &rs->sr_text );
4919 /* Some basic validation... */
4920 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
4921 /* Don't allow Modify of RDN; must use ModRdn for that. */
4922 if ( ml->sml_desc == rad ) {
4923 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
4924 rs->sr_text = "Use modrdn to change the entry name";
4929 slap_mods_opattrs( op, &op->orm_modlist, 1 );
4931 ldap_pvt_thread_pool_pause( &connection_pool );
4934 * 1) perform the Modify on the cached Entry.
4935 * 2) verify that the Entry still satisfies the schema.
4936 * 3) perform the individual config operations.
4937 * 4) store Modified entry in underlying LDIF backend.
4939 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
4941 rs->sr_text = ca.cr_msg;
4942 } else if ( cfb->cb_use_ldif ) {
4943 BackendDB *be = op->o_bd;
4944 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4945 struct berval dn, ndn;
4947 op->o_bd = &cfb->cb_db;
4951 op->o_dn = op->o_bd->be_rootdn;
4952 op->o_ndn = op->o_bd->be_rootndn;
4954 scp = op->o_callback;
4955 op->o_callback = ≻
4956 op->o_bd->be_modify( op, rs );
4958 op->o_callback = scp;
4963 ldap_pvt_thread_pool_resume( &connection_pool );
4965 send_ldap_result( op, rs );
4966 slap_graduate_commit_csn( op );
4971 config_back_modrdn( Operation *op, SlapReply *rs )
4974 CfEntryInfo *ce, *last;
4978 cfb = (CfBackInfo *)op->o_bd->be_private;
4980 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
4983 rs->sr_matched = last->ce_entry->e_name.bv_val;
4984 rs->sr_err = LDAP_NO_SUCH_OBJECT;
4987 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
4988 NULL, ACL_WRITE, NULL )) {
4989 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4993 if ( ce->ce_parent )
4994 parent = ce->ce_parent->ce_entry;
4996 parent = (Entry *)&slap_entry_root;
4997 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
4998 NULL, ACL_WRITE, NULL )) {
4999 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5004 /* We don't allow moving objects to new parents.
5005 * Generally we only allow reordering a set of ordered entries.
5007 if ( op->orr_newSup ) {
5008 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5012 /* If newRDN == oldRDN, quietly succeed */
5013 dnRdn( &op->o_req_ndn, &rdn );
5014 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
5015 rs->sr_err = LDAP_SUCCESS;
5019 /* Current behavior, subject to change as needed:
5021 * For backends and overlays, we only allow renumbering.
5022 * For schema, we allow renaming with the same number.
5023 * Otherwise, the op is not allowed.
5026 if ( ce->ce_type == Cft_Schema ) {
5030 /* Can't alter the main cn=schema entry */
5031 if ( ce->ce_parent->ce_type == Cft_Global ) {
5032 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5033 rs->sr_text = "renaming not allowed for this entry";
5037 /* We could support this later if desired */
5038 ptr1 = ber_bvchr( &rdn, '}' );
5039 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5040 len = ptr1 - rdn.bv_val;
5041 if ( len != ptr2 - op->orr_newrdn.bv_val ||
5042 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
5043 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5044 rs->sr_text = "schema reordering not supported";
5047 } else if ( ce->ce_type == Cft_Database ||
5048 ce->ce_type == Cft_Overlay ) {
5049 char *ptr1, *ptr2, *iptr1, *iptr2;
5052 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
5053 if ( *iptr2 != '{' ) {
5054 rs->sr_err = LDAP_NAMING_VIOLATION;
5055 rs->sr_text = "new ordering index is required";
5059 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
5060 ptr1 = ber_bvchr( &rdn, '}' );
5061 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5063 rs->sr_err = LDAP_NAMING_VIOLATION;
5064 rs->sr_text = "new ordering index is required";
5068 len1 = ptr1 - rdn.bv_val;
5069 len2 = ptr2 - op->orr_newrdn.bv_val;
5071 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
5072 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
5073 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5074 rs->sr_text = "changing database/overlay type not allowed";
5077 ixold = strtol( iptr1, NULL, 0 );
5078 ixnew = strtol( iptr2, &ptr1, 0 );
5079 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
5080 rs->sr_err = LDAP_NAMING_VIOLATION;
5083 /* config DB is always 0, cannot be changed */
5084 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
5085 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
5089 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5090 rs->sr_text = "renaming not supported for this entry";
5094 ldap_pvt_thread_pool_pause( &connection_pool );
5096 if ( ce->ce_type == Cft_Schema ) {
5097 req_modrdn_s modr = op->oq_modrdn;
5100 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
5101 if ( rs->sr_err == LDAP_SUCCESS ) {
5102 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
5103 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
5106 op->oq_modrdn = modr;
5108 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
5109 req_modrdn_s modr = op->oq_modrdn;
5112 /* Advance to first of this type */
5113 cprev = &ce->ce_parent->ce_kids;
5114 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
5115 cprev = &ce2->ce_sibs;
5118 /* Skip the -1 entry */
5119 if ( ce->ce_type == Cft_Database ) {
5120 cprev = &ce2->ce_sibs;
5126 /* Remove from old slot */
5127 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
5128 cprev = &ce2->ce_sibs;
5129 *cprev = ce->ce_sibs;
5130 ceold = ce->ce_sibs;
5132 /* Insert into new slot */
5134 for ( i=0; i<ixnew; i++ ) {
5138 cprev = &ce2->ce_sibs;
5140 ce->ce_sibs = *cprev;
5145 /* NOTE: These should be encoded in the OC tables, not inline here */
5146 if ( ce->ce_type == Cft_Database )
5147 backend_db_move( ce->ce_be, ixnew );
5148 else if ( ce->ce_type == Cft_Overlay )
5149 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
5151 if ( ixold < ixnew ) {
5152 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
5155 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
5156 ixold - ixnew, cfb->cb_use_ldif );
5158 op->oq_modrdn = modr;
5161 ldap_pvt_thread_pool_resume( &connection_pool );
5163 send_ldap_result( op, rs );
5168 config_back_delete( Operation *op, SlapReply *rs )
5170 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM, NULL );
5175 config_back_search( Operation *op, SlapReply *rs )
5178 CfEntryInfo *ce, *last;
5181 cfb = (CfBackInfo *)op->o_bd->be_private;
5183 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5186 rs->sr_matched = last->ce_entry->e_name.bv_val;
5187 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5190 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
5191 ACL_SEARCH, NULL, &mask ))
5193 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
5194 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5196 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5200 switch ( op->ors_scope ) {
5201 case LDAP_SCOPE_BASE:
5202 case LDAP_SCOPE_SUBTREE:
5203 config_send( op, rs, ce, 0 );
5206 case LDAP_SCOPE_ONELEVEL:
5207 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
5208 config_send( op, rs, ce, 1 );
5213 rs->sr_err = LDAP_SUCCESS;
5215 send_ldap_result( op, rs );
5219 /* no-op, we never free entries */
5220 int config_entry_release(
5225 if ( !e->e_private ) {
5228 return LDAP_SUCCESS;
5231 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
5233 int config_back_entry_get(
5237 AttributeDescription *at,
5242 CfEntryInfo *ce, *last;
5244 cfb = (CfBackInfo *)op->o_bd->be_private;
5246 ce = config_find_base( cfb->cb_root, ndn, &last );
5248 *ent = ce->ce_entry;
5249 if ( *ent && oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
5254 return ( *ent == NULL ? 1 : 0 );
5258 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
5259 ConfigTable *ct, ConfigArgs *c )
5263 for (; at && *at; at++) {
5264 /* Skip the naming attr */
5265 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
5267 for (i=0;ct[i].name;i++) {
5268 if (ct[i].ad == (*at)->sat_ad) {
5269 rc = config_get_vals(&ct[i], c);
5270 /* NOTE: tolerate that config_get_vals()
5271 * returns success with no values */
5272 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
5273 if ( c->rvalue_nvals )
5274 attr_merge(e, ct[i].ad, c->rvalue_vals,
5277 attr_merge_normalize(e, ct[i].ad,
5278 c->rvalue_vals, NULL);
5279 ber_bvarray_free( c->rvalue_nvals );
5280 ber_bvarray_free( c->rvalue_vals );
5289 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
5290 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
5292 Entry *e = entry_alloc();
5293 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5295 struct berval ad_name;
5296 AttributeDescription *ad = NULL;
5303 CfEntryInfo *ceprev = NULL;
5305 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
5308 ce->ce_type = main->co_type;
5309 ce->ce_parent = parent;
5311 pdn = parent->ce_entry->e_nname;
5312 if ( parent->ce_kids )
5313 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
5314 ceprev->ce_type <= ce->ce_type;
5315 ceprev = ceprev->ce_sibs );
5320 ce->ce_private = c->private;
5324 build_new_dn( &e->e_name, &pdn, rdn, NULL );
5325 ber_dupbv( &e->e_nname, &e->e_name );
5327 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
5328 main->co_name, NULL );
5330 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
5331 extra->co_name, NULL );
5332 ptr = strchr(rdn->bv_val, '=');
5333 ad_name.bv_val = rdn->bv_val;
5334 ad_name.bv_len = ptr - rdn->bv_val;
5335 rc = slap_bv2ad( &ad_name, &ad, &text );
5340 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
5341 attr_merge_normalize_one(e, ad, &val, NULL );
5344 c->table = main->co_type;
5345 if ( oc->soc_required )
5346 config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
5348 if ( oc->soc_allowed )
5349 config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
5353 c->table = extra->co_type;
5354 if ( oc->soc_required )
5355 config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
5357 if ( oc->soc_allowed )
5358 config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
5361 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5362 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
5363 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
5364 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
5365 if ( op && !op->o_noop ) {
5367 op->ora_modlist = NULL;
5368 op->o_bd->be_add( op, rs );
5369 if ( ( rs->sr_err != LDAP_SUCCESS )
5370 && (rs->sr_err != LDAP_ALREADY_EXISTS) ) {
5375 ce->ce_sibs = ceprev->ce_sibs;
5376 ceprev->ce_sibs = ce;
5377 } else if ( parent ) {
5378 ce->ce_sibs = parent->ce_kids;
5379 parent->ce_kids = ce;
5386 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
5387 Operation *op, SlapReply *rs )
5390 ConfigFile *cf = c->private;
5394 for (; cf; cf=cf->c_sibs, c->depth++) {
5395 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
5396 !cf->c_om_head ) continue;
5397 c->value_dn.bv_val = c->log;
5398 LUTIL_SLASHPATH( cf->c_file.bv_val );
5399 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
5404 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
5406 ptr = strchr( bv.bv_val, '.' );
5408 bv.bv_len = ptr - bv.bv_val;
5409 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
5410 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
5411 /* FIXME: how can indicate error? */
5414 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
5416 c->value_dn.bv_len += bv.bv_len;
5417 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
5420 e = config_build_entry( op, rs, ceparent, c, &c->value_dn,
5421 &CFOC_SCHEMA, NULL );
5424 } else if ( e && cf->c_kids ) {
5425 c->private = cf->c_kids;
5426 config_build_schema_inc( c, e->e_private, op, rs );
5432 #ifdef SLAPD_MODULES
5435 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
5436 Operation *op, SlapReply *rs )
5441 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
5442 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
5444 c->value_dn.bv_val = c->log;
5445 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
5446 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
5447 /* FIXME: how can indicate error? */
5451 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
5460 config_check_schema(Operation *op, CfBackInfo *cfb)
5462 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
5464 CfEntryInfo *ce, *last;
5467 /* If there's no root entry, we must be in the midst of converting */
5468 if ( !cfb->cb_root )
5471 /* Make sure the main schema entry exists */
5472 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
5479 /* Make sure it's up to date */
5480 if ( cf_om_tail != om_sys_tail ) {
5481 a = attr_find( e->e_attrs, cfAd_om );
5483 if ( a->a_nvals != a->a_vals )
5484 ber_bvarray_free( a->a_nvals );
5485 ber_bvarray_free( a->a_vals );
5490 oidm_unparse( &bv, NULL, NULL, 1 );
5491 attr_merge_normalize( e, cfAd_om, bv, NULL );
5492 ber_bvarray_free( bv );
5493 cf_om_tail = om_sys_tail;
5495 if ( cf_at_tail != at_sys_tail ) {
5496 a = attr_find( e->e_attrs, cfAd_attr );
5498 if ( a->a_nvals != a->a_vals )
5499 ber_bvarray_free( a->a_nvals );
5500 ber_bvarray_free( a->a_vals );
5505 at_unparse( &bv, NULL, NULL, 1 );
5506 attr_merge_normalize( e, cfAd_attr, bv, NULL );
5507 ber_bvarray_free( bv );
5508 cf_at_tail = at_sys_tail;
5510 if ( cf_oc_tail != oc_sys_tail ) {
5511 a = attr_find( e->e_attrs, cfAd_oc );
5513 if ( a->a_nvals != a->a_vals )
5514 ber_bvarray_free( a->a_nvals );
5515 ber_bvarray_free( a->a_vals );
5520 oc_unparse( &bv, NULL, NULL, 1 );
5521 attr_merge_normalize( e, cfAd_oc, bv, NULL );
5522 ber_bvarray_free( bv );
5523 cf_oc_tail = oc_sys_tail;
5526 SlapReply rs = {REP_RESULT};
5528 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
5529 &CFOC_SCHEMA, NULL );
5534 ce->ce_private = cfb->cb_config;
5535 cf_at_tail = at_sys_tail;
5536 cf_oc_tail = oc_sys_tail;
5537 cf_om_tail = om_sys_tail;
5542 static const char *defacl[] = {
5543 NULL, "to", "*", "by", "*", "none", NULL
5547 config_back_db_open( BackendDB *be, ConfigReply *cr )
5549 CfBackInfo *cfb = be->be_private;
5552 CfEntryInfo *ce, *ceparent;
5556 Connection conn = {0};
5557 OperationBuffer opbuf;
5559 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
5560 SlapReply rs = {REP_RESULT};
5561 void *thrctx = NULL;
5563 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
5565 /* If we have no explicitly configured ACLs, don't just use
5566 * the global ACLs. Explicitly deny access to everything.
5568 if ( frontendDB->be_acl && be->be_acl == frontendDB->be_acl ) {
5569 parse_acl(be, "config_back_db_open", 0, 6, (char **)defacl, 0 );
5572 thrctx = ldap_pvt_thread_pool_context();
5573 connection_fake_init( &conn, &opbuf, thrctx );
5576 op->o_tag = LDAP_REQ_ADD;
5577 op->o_callback = &cb;
5578 op->o_bd = &cfb->cb_db;
5579 op->o_dn = op->o_bd->be_rootdn;
5580 op->o_ndn = op->o_bd->be_rootndn;
5582 if ( !cfb->cb_use_ldif ) {
5586 /* If we read the config from back-ldif, do some quick sanity checks */
5587 if ( cfb->cb_got_ldif ) {
5588 return config_check_schema( op, cfb );
5591 /* create root of tree */
5593 c.private = cfb->cb_config;
5595 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
5605 #ifdef SLAPD_MODULES
5606 /* Create Module nodes... */
5607 if ( modpaths.mp_loads ) {
5608 if ( config_build_modules( &c, ceparent, op, &rs ) ){
5614 /* Create schema nodes... cn=schema will contain the hardcoded core
5615 * schema, read-only. Child objects will contain runtime loaded schema
5620 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
5625 ce->ce_private = cfb->cb_config;
5626 cf_at_tail = at_sys_tail;
5627 cf_oc_tail = oc_sys_tail;
5628 cf_om_tail = om_sys_tail;
5630 /* Create schema nodes for included schema... */
5631 if ( cfb->cb_config->c_kids ) {
5633 c.private = cfb->cb_config->c_kids;
5634 if (config_build_schema_inc( &c, ce, op, &rs )) {
5639 /* Create backend nodes. Skip if they don't provide a cf_table.
5640 * There usually aren't any of these.
5644 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
5645 if (!bi->bi_cf_ocs) {
5646 /* If it only supports the old config mech, complain. */
5647 if ( bi->bi_config ) {
5648 Debug( LDAP_DEBUG_ANY,
5649 "WARNING: No dynamic config support for backend %s.\n",
5650 bi->bi_type, 0, 0 );
5655 if (!bi->bi_private) continue;
5658 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
5659 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
5660 if ( rdn.bv_len >= sizeof( c.log ) ) {
5661 /* FIXME: holler ... */ ;
5664 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
5671 /* Create database nodes... */
5672 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
5673 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
5674 for ( i = -1, be = frontendDB ; be;
5675 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
5676 slap_overinfo *oi = NULL;
5678 if ( overlay_is_over( be )) {
5679 oi = be->bd_info->bi_private;
5685 /* If this backend supports the old config mechanism, but not
5686 * the new mech, complain.
5688 if ( !be->be_cf_ocs && bi->bi_db_config ) {
5689 Debug( LDAP_DEBUG_ANY,
5690 "WARNING: No dynamic config support for database %s.\n",
5691 bi->bi_type, 0, 0 );
5695 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
5696 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
5698 if ( rdn.bv_len >= sizeof( c.log ) ) {
5699 /* FIXME: holler ... */ ;
5703 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
5709 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd )
5710 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
5711 /* Iterate through overlays */
5717 for (j=0,on=oi->oi_list; on; j++,on=on->on_next) {
5718 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
5719 Debug( LDAP_DEBUG_ANY,
5720 "WARNING: No dynamic config support for overlay %s.\n",
5721 on->on_bi.bi_type, 0, 0 );
5725 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
5726 "%s=" SLAP_X_ORDERED_FMT "%s",
5727 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
5728 if ( rdn.bv_len >= sizeof( c.log ) ) {
5729 /* FIXME: holler ... */ ;
5733 oe = config_build_entry( op, &rs, ce, &c, &rdn,
5734 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
5738 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd )
5739 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
5744 ldap_pvt_thread_pool_context_reset( thrctx );
5746 if ( unsupp && cfb->cb_use_ldif ) {
5747 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
5748 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
5755 cfb_free_cffile( ConfigFile *cf )
5759 for (; cf; cf=next) {
5762 cfb_free_cffile( cf->c_kids );
5763 ch_free( cf->c_file.bv_val );
5764 ber_bvarray_free( cf->c_dseFiles );
5770 cfb_free_entries( CfEntryInfo *ce )
5774 for (; ce; ce=next) {
5777 cfb_free_entries( ce->ce_kids );
5778 ce->ce_entry->e_private = NULL;
5779 entry_free( ce->ce_entry );
5785 config_back_db_close( BackendDB *be, ConfigReply *cr )
5787 CfBackInfo *cfb = be->be_private;
5789 cfb_free_entries( cfb->cb_root );
5790 cfb->cb_root = NULL;
5792 if ( cfb->cb_db.bd_info ) {
5793 backend_shutdown( &cfb->cb_db );
5800 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
5802 CfBackInfo *cfb = be->be_private;
5804 cfb_free_cffile( cfb->cb_config );
5806 ch_free( cfdir.bv_val );
5808 avl_free( CfOcTree, NULL );
5810 if ( cfb->cb_db.bd_info ) {
5811 cfb->cb_db.be_suffix = NULL;
5812 cfb->cb_db.be_nsuffix = NULL;
5813 BER_BVZERO( &cfb->cb_db.be_rootdn );
5814 BER_BVZERO( &cfb->cb_db.be_rootndn );
5816 backend_destroy_one( &cfb->cb_db, 0 );
5825 config_back_db_init( BackendDB *be, ConfigReply* cr )
5831 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
5832 cfn = cfb->cb_config;
5833 be->be_private = cfb;
5835 ber_dupbv( &be->be_rootdn, &config_rdn );
5836 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
5837 ber_dupbv( &dn, &be->be_rootdn );
5838 ber_bvarray_add( &be->be_suffix, &dn );
5839 ber_dupbv( &dn, &be->be_rootdn );
5840 ber_bvarray_add( &be->be_nsuffix, &dn );
5842 /* Hide from namingContexts */
5843 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
5849 config_back_destroy( BackendInfo *bi )
5851 ldif_must_b64_encode_release();
5856 config_tool_entry_open( BackendDB *be, int mode )
5858 CfBackInfo *cfb = be->be_private;
5859 BackendInfo *bi = cfb->cb_db.bd_info;
5861 if ( bi && bi->bi_tool_entry_open )
5862 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
5869 config_tool_entry_close( BackendDB *be )
5871 CfBackInfo *cfb = be->be_private;
5872 BackendInfo *bi = cfb->cb_db.bd_info;
5874 if ( bi && bi->bi_tool_entry_close )
5875 return bi->bi_tool_entry_close( &cfb->cb_db );
5881 config_tool_entry_first( BackendDB *be )
5883 CfBackInfo *cfb = be->be_private;
5884 BackendInfo *bi = cfb->cb_db.bd_info;
5886 if ( bi && bi->bi_tool_entry_first )
5887 return bi->bi_tool_entry_first( &cfb->cb_db );
5893 config_tool_entry_next( BackendDB *be )
5895 CfBackInfo *cfb = be->be_private;
5896 BackendInfo *bi = cfb->cb_db.bd_info;
5898 if ( bi && bi->bi_tool_entry_next )
5899 return bi->bi_tool_entry_next( &cfb->cb_db );
5905 config_tool_entry_get( BackendDB *be, ID id )
5907 CfBackInfo *cfb = be->be_private;
5908 BackendInfo *bi = cfb->cb_db.bd_info;
5910 if ( bi && bi->bi_tool_entry_get )
5911 return bi->bi_tool_entry_get( &cfb->cb_db, id );
5916 static int entry_put_got_frontend=0;
5917 static int entry_put_got_config=0;
5919 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
5921 CfBackInfo *cfb = be->be_private;
5922 BackendInfo *bi = cfb->cb_db.bd_info;
5924 struct berval rdn, vals[ 2 ];
5926 OperationBuffer opbuf;
5928 Connection conn = {0};
5929 Operation *op = NULL;
5932 /* Create entry for frontend database if it does not exist already */
5933 if ( !entry_put_got_frontend ) {
5934 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
5935 STRLENOF( "olcDatabase" ))) {
5936 if ( strncmp( e->e_nname.bv_val +
5937 STRLENOF( "olcDatabase" ), "={-1}frontend",
5938 STRLENOF( "={-1}frontend" )) &&
5939 strncmp( e->e_nname.bv_val +
5940 STRLENOF( "olcDatabase" ), "=frontend",
5941 STRLENOF( "=frontend" ))) {
5943 vals[1].bv_val = NULL;
5944 memset( &ca, 0, sizeof(ConfigArgs));
5946 ca.bi = frontendDB->bd_info;
5947 ca.be->be_cf_ocs = &CFOC_FRONTEND;
5948 rdn.bv_val = ca.log;
5949 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
5950 "%s=" SLAP_X_ORDERED_FMT "%s",
5951 cfAd_database->ad_cname.bv_val, -1,
5953 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
5954 &CFOC_DATABASE, ca.be->be_cf_ocs );
5955 thrctx = ldap_pvt_thread_pool_context();
5956 connection_fake_init2( &conn, &opbuf, thrctx,0 );
5958 op->o_bd = &cfb->cb_db;
5959 op->o_tag = LDAP_REQ_ADD;
5961 op->o_dn = be->be_rootdn;
5962 op->o_ndn = be->be_rootndn;
5963 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
5964 if ( rc != LDAP_SUCCESS ) {
5965 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
5966 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
5970 if ( ce && bi && bi->bi_tool_entry_put &&
5971 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
5972 entry_put_got_frontend++;
5974 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
5975 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
5979 entry_put_got_frontend++;
5983 /* Create entry for config database if it does not exist already */
5984 if ( !entry_put_got_config ) {
5985 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
5986 STRLENOF( "olcDatabase" ))) {
5987 if ( strncmp( e->e_nname.bv_val +
5988 STRLENOF( "olcDatabase" ), "={0}config",
5989 STRLENOF( "={0}config" )) &&
5990 strncmp( e->e_nname.bv_val +
5991 STRLENOF( "olcDatabase" ), "=config",
5992 STRLENOF( "=config" )) ) {
5994 vals[1].bv_val = NULL;
5995 memset( &ca, 0, sizeof(ConfigArgs));
5996 ca.be = LDAP_STAILQ_FIRST( &backendDB );
5997 ca.bi = ca.be->bd_info;
5998 rdn.bv_val = ca.log;
5999 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
6000 "%s=" SLAP_X_ORDERED_FMT "%s",
6001 cfAd_database->ad_cname.bv_val, 0,
6003 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
6006 thrctx = ldap_pvt_thread_pool_context();
6007 connection_fake_init2( &conn, &opbuf, thrctx,0 );
6009 op->o_bd = &cfb->cb_db;
6010 op->o_tag = LDAP_REQ_ADD;
6011 op->o_dn = be->be_rootdn;
6012 op->o_ndn = be->be_rootndn;
6015 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
6016 if ( rc != LDAP_SUCCESS ) {
6017 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
6018 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
6021 if (ce && bi && bi->bi_tool_entry_put &&
6022 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
6023 entry_put_got_config++;
6025 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
6026 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
6030 entry_put_got_config++;
6034 if ( bi && bi->bi_tool_entry_put &&
6035 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
6036 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
6043 AttributeDescription **desc;
6045 { "attribute", &cfAd_attr },
6046 { "backend", &cfAd_backend },
6047 { "database", &cfAd_database },
6048 { "include", &cfAd_include },
6049 { "objectclass", &cfAd_oc },
6050 { "objectidentifier", &cfAd_om },
6051 { "overlay", &cfAd_overlay },
6056 * add / delete: all types that may be added or deleted must use an
6057 * X-ORDERED attributeType for their RDN. Adding and deleting entries
6058 * should automatically renumber the index of any siblings as needed,
6059 * so that no gaps in the numbering sequence exist after the add/delete
6061 * What can be added:
6063 * backend objects for backend-specific config directives
6067 * delete: probably no support this time around.
6069 * modrdn: generally not done. Will be invoked automatically by add/
6070 * delete to update numbering sequence. Perform as an explicit operation
6071 * so that the renumbering effect may be replicated. Subtree rename must
6072 * be supported, since renumbering a database will affect all its child
6075 * modify: must be fully supported.
6079 config_back_initialize( BackendInfo *bi )
6081 ConfigTable *ct = config_back_cf_table;
6085 AttributeDescription *ad = NULL;
6087 static char *controls[] = {
6088 LDAP_CONTROL_MANAGEDSAIT,
6092 /* Make sure we don't exceed the bits reserved for userland */
6093 config_check_userland( CFG_LAST );
6095 bi->bi_controls = controls;
6100 bi->bi_destroy = config_back_destroy;
6102 bi->bi_db_init = config_back_db_init;
6103 bi->bi_db_config = 0;
6104 bi->bi_db_open = config_back_db_open;
6105 bi->bi_db_close = config_back_db_close;
6106 bi->bi_db_destroy = config_back_db_destroy;
6108 bi->bi_op_bind = config_back_bind;
6109 bi->bi_op_unbind = 0;
6110 bi->bi_op_search = config_back_search;
6111 bi->bi_op_compare = 0;
6112 bi->bi_op_modify = config_back_modify;
6113 bi->bi_op_modrdn = config_back_modrdn;
6114 bi->bi_op_add = config_back_add;
6115 bi->bi_op_delete = config_back_delete;
6116 bi->bi_op_abandon = 0;
6118 bi->bi_extended = 0;
6120 bi->bi_chk_referrals = 0;
6122 bi->bi_access_allowed = slap_access_allowed;
6124 bi->bi_connection_init = 0;
6125 bi->bi_connection_destroy = 0;
6127 bi->bi_entry_release_rw = config_entry_release;
6128 bi->bi_entry_get_rw = config_back_entry_get;
6130 bi->bi_tool_entry_open = config_tool_entry_open;
6131 bi->bi_tool_entry_close = config_tool_entry_close;
6132 bi->bi_tool_entry_first = config_tool_entry_first;
6133 bi->bi_tool_entry_next = config_tool_entry_next;
6134 bi->bi_tool_entry_get = config_tool_entry_get;
6135 bi->bi_tool_entry_put = config_tool_entry_put;
6138 argv[ 0 ] = "slapd";
6144 for (i=0; OidMacros[i].name; i++ ) {
6145 argv[1] = OidMacros[i].name;
6146 argv[2] = OidMacros[i].oid;
6147 parse_oidm( &ca, 0, NULL );
6150 bi->bi_cf_ocs = cf_ocs;
6152 i = config_register_schema( ct, cf_ocs );
6155 /* setup olcRootPW to be base64-encoded when written in LDIF form;
6156 * basically, we don't care if it fails */
6157 i = slap_str2ad( "olcRootPW", &ad, &text );
6159 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
6160 "warning, unable to get \"olcRootPW\" "
6161 "attribute description: %d: %s\n",
6164 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
6165 ad->ad_type->sat_oid );
6168 /* set up the notable AttributeDescriptions */
6170 for (;ct->name;ct++) {
6171 if (strcmp(ct->name, ads[i].name)) continue;
6172 *ads[i].desc = ct->ad;
6174 if (!ads[i].name) break;