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;
1528 for ( sv = svnew; sv; sv = sv->al_next )
1529 sv->al_desc->ad_type->sat_flags |= SLAP_AT_SORTED_VAL;
1530 for ( sv = sortVals; sv && sv->al_next; sv = sv->al_next );
1532 sv->al_next = svnew;
1539 /* Don't append to the global ACL if we're on a specific DB */
1541 if ( c->be != frontendDB && frontendDB->be_acl && c->valx == -1 ) {
1544 for ( a=c->be->be_acl; a && a != frontendDB->be_acl;
1548 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
1554 if(root_dse_read_file(c->argv[1])) {
1555 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> could not read file", c->argv[0] );
1556 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1557 c->log, c->cr_msg, c->argv[1] );
1562 ber_str2bv( c->argv[1], 0, 1, &bv );
1563 if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private )
1565 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1571 ServerID *si, **sip;
1574 if ( lutil_atoi( &num, c->argv[1] ) ||
1575 num < 0 || num > SLAP_SYNC_SID_MAX )
1577 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1578 "<%s> illegal server ID", c->argv[0] );
1579 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1580 c->log, c->cr_msg, c->argv[1] );
1583 /* only one value allowed if no URL is given */
1584 if ( c->argc > 2 ) {
1587 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
1588 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1589 "<%s> only one server ID allowed now", c->argv[0] );
1590 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1591 c->log, c->cr_msg, c->argv[1] );
1595 if ( ldap_url_parse( c->argv[2], &lud )) {
1596 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1597 "<%s> invalid URL", c->argv[0] );
1598 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1599 c->log, c->cr_msg, c->argv[2] );
1602 len = strlen( c->argv[2] );
1603 si = ch_malloc( sizeof(ServerID) + len + 1 );
1604 si->si_url.bv_val = (char *)(si+1);
1605 si->si_url.bv_len = len;
1606 strcpy( si->si_url.bv_val, c->argv[2] );
1609 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1610 "<%s> unqualified server ID not allowed now", c->argv[0] );
1611 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1612 c->log, c->cr_msg, c->argv[1] );
1615 si = ch_malloc( sizeof(ServerID) );
1616 BER_BVZERO( &si->si_url );
1617 slap_serverID = num;
1618 Debug( LDAP_DEBUG_CONFIG,
1620 c->log, slap_serverID, 0 );
1624 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
1627 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
1628 /* If hostname is empty, or is localhost, or matches
1629 * our hostname, this serverID refers to this host.
1630 * Compare it against listeners and ports.
1632 if ( !lud->lud_host || !lud->lud_host[0] ||
1633 !strncasecmp("localhost", lud->lud_host,
1634 STRLENOF("localhost")) ||
1635 !strcasecmp( global_host, lud->lud_host )) {
1636 Listener **l = slapd_get_listeners();
1639 for ( i=0; l[i]; i++ ) {
1642 ldap_url_parse( l[i]->sl_url.bv_val, &lu2 );
1644 if ( strcasecmp( lud->lud_scheme,
1647 if ( lud->lud_port != lu2->lud_port )
1649 /* Listener on ANY address */
1650 if ( !lu2->lud_host || !lu2->lud_host[0] ) {
1654 /* URL on ANY address */
1655 if ( !lud->lud_host || !lud->lud_host[0] ) {
1659 /* Listener has specific host, must
1662 if ( !strcasecmp( lud->lud_host,
1668 ldap_free_urldesc( lu2 );
1670 slap_serverID = si->si_num;
1671 Debug( LDAP_DEBUG_CONFIG,
1672 "%s: SID=%d (listener=%s)\n",
1673 c->log, slap_serverID,
1674 l[i]->sl_url.bv_val );
1681 ldap_free_urldesc( lud );
1686 if ( logfileName ) ch_free( logfileName );
1687 logfileName = c->value_string;
1688 logfile = fopen(logfileName, "w");
1689 if(logfile) lutil_debug_file(logfile);
1693 if(SLAP_NOLASTMODCMD(c->be)) {
1694 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> not available for %s database",
1695 c->argv[0], c->be->bd_info->bi_type );
1696 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1697 c->log, c->cr_msg, 0 );
1701 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1703 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1706 case CFG_MIRRORMODE:
1707 if(!SLAP_SHADOW(c->be)) {
1708 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database is not a shadow",
1710 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1711 c->log, c->cr_msg, 0 );
1715 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
1717 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1720 case CFG_MONITORING:
1722 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
1724 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
1729 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
1731 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
1734 case CFG_SSTR_IF_MAX:
1735 if (c->value_int < index_substr_if_minlen) {
1736 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1737 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1738 c->log, c->cr_msg, c->value_int );
1741 index_substr_if_maxlen = c->value_int;
1744 case CFG_SSTR_IF_MIN:
1745 if (c->value_int > index_substr_if_maxlen) {
1746 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1747 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1748 c->log, c->cr_msg, c->value_int );
1751 index_substr_if_minlen = c->value_int;
1754 #ifdef SLAPD_MODULES
1756 /* If we're just adding a module on an existing modpath,
1757 * make sure we've selected the current path.
1759 if ( c->op == LDAP_MOD_ADD && c->private && modcur != c->private ) {
1760 modcur = c->private;
1761 /* This should never fail */
1762 if ( module_path( modcur->mp_path.bv_val )) {
1763 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> module path no longer valid",
1765 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1766 c->log, c->cr_msg, modcur->mp_path.bv_val );
1770 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1772 /* Record this load on the current path */
1776 if ( c->op == SLAP_CONFIG_ADD ) {
1777 ptr = c->line + STRLENOF("moduleload");
1778 while (!isspace((unsigned char) *ptr)) ptr++;
1779 while (isspace((unsigned char) *ptr)) ptr++;
1783 ber_str2bv(ptr, 0, 1, &bv);
1784 ber_bvarray_add( &modcur->mp_loads, &bv );
1786 /* Check for any new hardcoded schema */
1787 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
1788 config_check_schema( NULL, &cfBackInfo );
1793 if(module_path(c->argv[1])) return(1);
1794 /* Record which path was used with each module */
1798 if (!modpaths.mp_loads) {
1801 mp = ch_malloc( sizeof( ModPaths ));
1802 modlast->mp_next = mp;
1804 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1806 mp->mp_loads = NULL;
1817 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
1819 slapi_plugins_used++;
1823 #ifdef SLAP_AUTH_REWRITE
1828 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
1831 if ( c->argc > 1 ) {
1834 /* quote all args but the first */
1835 line = ldap_charray2str( c->argv, "\" \"" );
1836 ber_str2bv( line, 0, 0, &bv );
1837 s = ber_bvchr( &bv, '"' );
1838 assert( s != NULL );
1839 /* move the trailing quote of argv[0] to the end */
1840 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
1841 bv.bv_val[ bv.bv_len - 1 ] = '"';
1844 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
1847 ber_bvarray_add( &authz_rewrites, &bv );
1854 Debug( LDAP_DEBUG_ANY,
1855 "%s: unknown CFG_TYPE %d.\n",
1856 c->log, c->type, 0 );
1865 config_fname(ConfigArgs *c) {
1866 if(c->op == SLAP_CONFIG_EMIT) {
1868 ConfigFile *cf = c->private;
1869 value_add_one( &c->rvalue_vals, &cf->c_file );
1878 config_cfdir(ConfigArgs *c) {
1879 if(c->op == SLAP_CONFIG_EMIT) {
1880 if ( !BER_BVISEMPTY( &cfdir )) {
1881 value_add_one( &c->rvalue_vals, &cfdir );
1890 config_search_base(ConfigArgs *c) {
1891 if(c->op == SLAP_CONFIG_EMIT) {
1893 if (!BER_BVISEMPTY(&default_search_base)) {
1894 value_add_one(&c->rvalue_vals, &default_search_base);
1895 value_add_one(&c->rvalue_nvals, &default_search_nbase);
1899 } else if( c->op == LDAP_MOD_DELETE ) {
1900 ch_free( default_search_base.bv_val );
1901 ch_free( default_search_nbase.bv_val );
1902 BER_BVZERO( &default_search_base );
1903 BER_BVZERO( &default_search_nbase );
1907 if(c->bi || c->be != frontendDB) {
1908 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
1909 "prior to any backend or database definition\n",
1914 if(default_search_nbase.bv_len) {
1915 free(default_search_base.bv_val);
1916 free(default_search_nbase.bv_val);
1919 default_search_base = c->value_dn;
1920 default_search_nbase = c->value_ndn;
1924 /* For RE23 compatibility we allow this in the global entry
1925 * but we now defer it to the frontend entry to allow modules
1926 * to load new hash types.
1929 config_passwd_hash(ConfigArgs *c) {
1931 if (c->op == SLAP_CONFIG_EMIT) {
1933 /* Don't generate it in the global entry */
1934 if ( c->table == Cft_Global )
1936 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
1937 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
1938 value_add_one(&c->rvalue_vals, &bv);
1941 } else if ( c->op == LDAP_MOD_DELETE ) {
1942 /* Deleting from global is a no-op, only the frontendDB entry matters */
1943 if ( c->table == Cft_Global )
1945 if ( c->valx < 0 ) {
1946 ldap_charray_free( default_passwd_hash );
1947 default_passwd_hash = NULL;
1950 ch_free( default_passwd_hash[i] );
1951 for (; default_passwd_hash[i]; i++ )
1952 default_passwd_hash[i] = default_passwd_hash[i+1];
1956 for(i = 1; i < c->argc; i++) {
1957 if(!lutil_passwd_scheme(c->argv[i])) {
1958 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> scheme not available", c->argv[0] );
1959 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1960 c->log, c->cr_msg, c->argv[i]);
1962 ldap_charray_add(&default_passwd_hash, c->argv[i]);
1965 if(!default_passwd_hash) {
1966 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> no valid hashes found", c->argv[0] );
1967 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1968 c->log, c->cr_msg, 0 );
1975 config_schema_dn(ConfigArgs *c) {
1976 if ( c->op == SLAP_CONFIG_EMIT ) {
1978 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
1979 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
1980 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
1984 } else if ( c->op == LDAP_MOD_DELETE ) {
1985 ch_free( c->be->be_schemadn.bv_val );
1986 ch_free( c->be->be_schemandn.bv_val );
1987 BER_BVZERO( &c->be->be_schemadn );
1988 BER_BVZERO( &c->be->be_schemandn );
1991 ch_free( c->be->be_schemadn.bv_val );
1992 ch_free( c->be->be_schemandn.bv_val );
1993 c->be->be_schemadn = c->value_dn;
1994 c->be->be_schemandn = c->value_ndn;
1999 config_sizelimit(ConfigArgs *c) {
2001 struct slap_limits_set *lim = &c->be->be_def_limit;
2002 if (c->op == SLAP_CONFIG_EMIT) {
2007 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
2008 if ( !BER_BVISEMPTY( &bv ))
2009 value_add_one( &c->rvalue_vals, &bv );
2013 } else if ( c->op == LDAP_MOD_DELETE ) {
2014 /* Reset to defaults */
2015 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
2016 lim->lms_s_hard = 0;
2017 lim->lms_s_unchecked = -1;
2019 lim->lms_s_pr_hide = 0;
2020 lim->lms_s_pr_total = 0;
2023 for(i = 1; i < c->argc; i++) {
2024 if(!strncasecmp(c->argv[i], "size", 4)) {
2025 rc = limits_parse_one(c->argv[i], lim);
2027 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2028 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2029 c->log, c->cr_msg, c->argv[i]);
2033 if(!strcasecmp(c->argv[i], "unlimited")) {
2034 lim->lms_s_soft = -1;
2036 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
2037 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2038 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2039 c->log, c->cr_msg, c->argv[i]);
2043 lim->lms_s_hard = 0;
2050 config_timelimit(ConfigArgs *c) {
2052 struct slap_limits_set *lim = &c->be->be_def_limit;
2053 if (c->op == SLAP_CONFIG_EMIT) {
2058 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
2059 if ( !BER_BVISEMPTY( &bv ))
2060 value_add_one( &c->rvalue_vals, &bv );
2064 } else if ( c->op == LDAP_MOD_DELETE ) {
2065 /* Reset to defaults */
2066 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
2067 lim->lms_t_hard = 0;
2070 for(i = 1; i < c->argc; i++) {
2071 if(!strncasecmp(c->argv[i], "time", 4)) {
2072 rc = limits_parse_one(c->argv[i], lim);
2074 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2075 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2076 c->log, c->cr_msg, c->argv[i]);
2080 if(!strcasecmp(c->argv[i], "unlimited")) {
2081 lim->lms_t_soft = -1;
2083 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
2084 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2085 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2086 c->log, c->cr_msg, c->argv[i]);
2090 lim->lms_t_hard = 0;
2097 config_overlay(ConfigArgs *c) {
2098 if (c->op == SLAP_CONFIG_EMIT) {
2100 } else if ( c->op == LDAP_MOD_DELETE ) {
2103 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2106 Debug( LDAP_DEBUG_ANY,
2107 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2108 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2110 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi)) {
2117 config_subordinate(ConfigArgs *c)
2123 case SLAP_CONFIG_EMIT:
2124 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2127 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2128 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2131 value_add_one( &c->rvalue_vals, &bv );
2135 case LDAP_MOD_DELETE:
2136 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2137 glue_sub_del( c->be );
2139 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2144 case SLAP_CONFIG_ADD:
2145 advertise = ( c->argc == 2 && !strcasecmp( c->argv[1], "advertise" ));
2146 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2153 config_suffix(ConfigArgs *c)
2156 struct berval pdn, ndn;
2157 char *notallowed = NULL;
2159 if ( c->be == frontendDB ) {
2160 notallowed = "frontend";
2162 } else if ( SLAP_MONITOR(c->be) ) {
2163 notallowed = "monitor";
2165 } else if ( SLAP_CONFIG(c->be) ) {
2166 notallowed = "config";
2169 if ( notallowed != NULL ) {
2170 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
2174 case LDAP_MOD_DELETE:
2175 case LDAP_MOD_REPLACE:
2176 case LDAP_MOD_INCREMENT:
2177 case SLAP_CONFIG_ADD:
2178 if ( !BER_BVISNULL( &c->value_dn ) ) {
2179 snprintf( buf, sizeof( buf ), "<%s> ",
2180 c->value_dn.bv_val );
2183 Debug(LDAP_DEBUG_ANY,
2184 "%s: suffix %snot allowed in %s database.\n",
2185 c->log, buf, notallowed );
2188 case SLAP_CONFIG_EMIT:
2189 /* don't complain when emitting... */
2193 /* FIXME: don't know what values may be valid;
2194 * please remove assertion, or add legal values
2195 * to either block */
2203 if (c->op == SLAP_CONFIG_EMIT) {
2204 if ( c->be->be_suffix == NULL
2205 || BER_BVISNULL( &c->be->be_suffix[0] ) )
2209 value_add( &c->rvalue_vals, c->be->be_suffix );
2210 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
2213 } else if ( c->op == LDAP_MOD_DELETE ) {
2214 if ( c->valx < 0 ) {
2215 ber_bvarray_free( c->be->be_suffix );
2216 ber_bvarray_free( c->be->be_nsuffix );
2217 c->be->be_suffix = NULL;
2218 c->be->be_nsuffix = NULL;
2221 ch_free( c->be->be_suffix[i].bv_val );
2222 ch_free( c->be->be_nsuffix[i].bv_val );
2224 c->be->be_suffix[i] = c->be->be_suffix[i+1];
2225 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
2227 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
2232 #ifdef SLAPD_MONITOR_DN
2233 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
2234 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> DN is reserved for monitoring slapd",
2236 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2237 c->log, c->cr_msg, SLAPD_MONITOR_DN);
2244 if (SLAP_DBHIDDEN( c->be ))
2247 tbe = select_backend(&ndn, 0);
2249 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
2255 BackendDB *b2 = tbe;
2257 /* Does tbe precede be? */
2258 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
2261 char *type = tbe->bd_info->bi_type;
2263 if ( overlay_is_over( tbe ) ) {
2264 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
2265 type = oi->oi_orig->bi_type;
2268 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> namingContext \"%s\" "
2269 "already served by a preceding %s database",
2270 c->argv[0], pdn.bv_val, type );
2271 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
2272 c->log, c->cr_msg, tbe->be_suffix[0].bv_val);
2278 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
2279 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
2280 "base provided \"%s\" (assuming okay)\n",
2281 c->log, default_search_base.bv_val, 0);
2283 ber_bvarray_add(&c->be->be_suffix, &pdn);
2284 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
2289 config_rootdn(ConfigArgs *c) {
2290 if (c->op == SLAP_CONFIG_EMIT) {
2291 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2292 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
2293 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
2298 } else if ( c->op == LDAP_MOD_DELETE ) {
2299 ch_free( c->be->be_rootdn.bv_val );
2300 ch_free( c->be->be_rootndn.bv_val );
2301 BER_BVZERO( &c->be->be_rootdn );
2302 BER_BVZERO( &c->be->be_rootndn );
2305 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2306 ch_free( c->be->be_rootdn.bv_val );
2307 ch_free( c->be->be_rootndn.bv_val );
2309 c->be->be_rootdn = c->value_dn;
2310 c->be->be_rootndn = c->value_ndn;
2315 config_rootpw(ConfigArgs *c) {
2318 if (c->op == SLAP_CONFIG_EMIT) {
2319 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
2320 /* don't copy, because "rootpw" is marked
2322 c->value_bv = c->be->be_rootpw;
2326 } else if ( c->op == LDAP_MOD_DELETE ) {
2327 ch_free( c->be->be_rootpw.bv_val );
2328 BER_BVZERO( &c->be->be_rootpw );
2332 tbe = select_backend(&c->be->be_rootndn, 0);
2334 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> can only be set when rootdn is under suffix",
2336 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2337 c->log, c->cr_msg, 0);
2340 if ( !BER_BVISNULL( &c->be->be_rootpw ))
2341 ch_free( c->be->be_rootpw.bv_val );
2342 c->be->be_rootpw = c->value_bv;
2347 config_restrict(ConfigArgs *c) {
2348 slap_mask_t restrictops = 0;
2350 slap_verbmasks restrictable_ops[] = {
2351 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
2352 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
2353 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
2354 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
2355 { BER_BVC("modrdn"), 0 },
2356 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
2357 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
2358 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
2359 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
2360 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
2361 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
2362 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
2363 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
2364 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
2365 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
2366 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
2370 if (c->op == SLAP_CONFIG_EMIT) {
2371 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
2373 } else if ( c->op == LDAP_MOD_DELETE ) {
2375 c->be->be_restrictops = 0;
2377 restrictops = verb_to_mask( c->line, restrictable_ops );
2378 c->be->be_restrictops ^= restrictops;
2382 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
2384 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown operation", c->argv[0] );
2385 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2386 c->log, c->cr_msg, c->argv[i]);
2389 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
2390 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
2391 c->be->be_restrictops |= restrictops;
2396 config_allows(ConfigArgs *c) {
2397 slap_mask_t allows = 0;
2399 slap_verbmasks allowable_ops[] = {
2400 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
2401 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
2402 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
2403 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
2404 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
2407 if (c->op == SLAP_CONFIG_EMIT) {
2408 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
2409 } else if ( c->op == LDAP_MOD_DELETE ) {
2413 allows = verb_to_mask( c->line, allowable_ops );
2414 global_allows ^= allows;
2418 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
2420 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
2421 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2422 c->log, c->cr_msg, c->argv[i]);
2425 global_allows |= allows;
2430 config_disallows(ConfigArgs *c) {
2431 slap_mask_t disallows = 0;
2433 slap_verbmasks disallowable_ops[] = {
2434 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
2435 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
2436 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
2437 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
2440 if (c->op == SLAP_CONFIG_EMIT) {
2441 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
2442 } else if ( c->op == LDAP_MOD_DELETE ) {
2444 global_disallows = 0;
2446 disallows = verb_to_mask( c->line, disallowable_ops );
2447 global_disallows ^= disallows;
2451 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
2453 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
2454 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2455 c->log, c->cr_msg, c->argv[i]);
2458 global_disallows |= disallows;
2463 config_requires(ConfigArgs *c) {
2464 slap_mask_t requires = frontendDB->be_requires;
2465 int i, argc = c->argc;
2466 char **argv = c->argv;
2468 slap_verbmasks requires_ops[] = {
2469 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
2470 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
2471 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
2472 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
2473 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
2476 if (c->op == SLAP_CONFIG_EMIT) {
2477 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
2478 } else if ( c->op == LDAP_MOD_DELETE ) {
2480 c->be->be_requires = 0;
2482 requires = verb_to_mask( c->line, requires_ops );
2483 c->be->be_requires ^= requires;
2487 /* "none" can only be first, to wipe out default/global values */
2488 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
2493 i = verbs_to_mask(argc, argv, requires_ops, &requires);
2495 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
2496 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
2497 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2498 c->log, c->cr_msg, 0);
2500 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
2501 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2502 c->log, c->cr_msg, c->argv[i]);
2506 c->be->be_requires = requires;
2510 static slap_verbmasks *loglevel_ops;
2513 loglevel_init( void )
2515 slap_verbmasks lo[] = {
2516 { BER_BVC("Any"), -1 },
2517 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
2518 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
2519 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
2520 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
2521 { BER_BVC("BER"), LDAP_DEBUG_BER },
2522 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
2523 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
2524 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
2525 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
2526 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
2527 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
2528 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
2529 #if 0 /* no longer used (nor supported) */
2530 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
2531 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
2533 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
2534 { BER_BVC("None"), LDAP_DEBUG_NONE },
2538 return slap_verbmasks_init( &loglevel_ops, lo );
2542 loglevel_destroy( void )
2544 if ( loglevel_ops ) {
2545 (void)slap_verbmasks_destroy( loglevel_ops );
2547 loglevel_ops = NULL;
2550 static slap_mask_t loglevel_ignore[] = { -1, 0 };
2553 slap_loglevel_register( slap_mask_t m, struct berval *s )
2557 if ( loglevel_ops == NULL ) {
2561 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
2564 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
2572 slap_loglevel_get( struct berval *s, int *l )
2577 if ( loglevel_ops == NULL ) {
2581 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
2582 m |= loglevel_ops[ i ].mask;
2585 for ( i = 1; m & i; i <<= 1 )
2592 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
2595 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
2606 str2loglevel( const char *s, int *l )
2610 if ( loglevel_ops == NULL ) {
2614 i = verb_to_mask( s, loglevel_ops );
2616 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
2620 *l = loglevel_ops[ i ].mask;
2626 loglevel2str( int l )
2628 struct berval bv = BER_BVNULL;
2630 loglevel2bv( l, &bv );
2636 loglevel2bv( int l, struct berval *bv )
2638 if ( loglevel_ops == NULL ) {
2644 return enum_to_verb( loglevel_ops, l, bv ) == -1;
2648 loglevel2bvarray( int l, BerVarray *bva )
2650 if ( loglevel_ops == NULL ) {
2654 return mask_to_verbs( loglevel_ops, l, bva );
2658 loglevel_print( FILE *out )
2662 if ( loglevel_ops == NULL ) {
2666 fprintf( out, "Installed log subsystems:\n\n" );
2667 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
2668 fprintf( out, "\t%-30s (%lu)\n",
2669 loglevel_ops[ i ].word.bv_val,
2670 loglevel_ops[ i ].mask );
2673 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
2674 "by specific code\n\n" );
2679 static int config_syslog;
2682 config_loglevel(ConfigArgs *c) {
2685 if ( loglevel_ops == NULL ) {
2689 if (c->op == SLAP_CONFIG_EMIT) {
2690 /* Get default or commandline slapd setting */
2691 if ( ldap_syslog && !config_syslog )
2692 config_syslog = ldap_syslog;
2693 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
2695 } else if ( c->op == LDAP_MOD_DELETE ) {
2699 int level = verb_to_mask( c->line, loglevel_ops );
2700 config_syslog ^= level;
2702 if ( slapMode & SLAP_SERVER_MODE ) {
2703 ldap_syslog = config_syslog;
2708 for( i=1; i < c->argc; i++ ) {
2711 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
2712 if( lutil_atoi( &level, c->argv[i] ) != 0 ) {
2713 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse level", c->argv[0] );
2714 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2715 c->log, c->cr_msg, c->argv[i]);
2719 if ( str2loglevel( c->argv[i], &level ) ) {
2720 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown level", c->argv[0] );
2721 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2722 c->log, c->cr_msg, c->argv[i]);
2726 /* Explicitly setting a zero clears all the levels */
2728 config_syslog |= level;
2732 if ( slapMode & SLAP_SERVER_MODE ) {
2733 ldap_syslog = config_syslog;
2739 config_referral(ConfigArgs *c) {
2741 if (c->op == SLAP_CONFIG_EMIT) {
2742 if ( default_referral ) {
2743 value_add( &c->rvalue_vals, default_referral );
2748 } else if ( c->op == LDAP_MOD_DELETE ) {
2749 if ( c->valx < 0 ) {
2750 ber_bvarray_free( default_referral );
2751 default_referral = NULL;
2754 ch_free( default_referral[i].bv_val );
2755 for (; default_referral[i].bv_val; i++ )
2756 default_referral[i] = default_referral[i+1];
2760 if(validate_global_referral(c->argv[1])) {
2761 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
2762 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2763 c->log, c->cr_msg, c->argv[1]);
2767 ber_str2bv(c->argv[1], 0, 0, &val);
2768 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
2776 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
2777 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
2778 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
2779 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
2780 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
2781 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
2782 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
2783 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
2784 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
2789 config_security(ConfigArgs *c) {
2790 slap_ssf_set_t *set = &c->be->be_ssf_set;
2793 if (c->op == SLAP_CONFIG_EMIT) {
2799 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
2800 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
2803 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
2804 if ( bv.bv_len >= sizeof( numbuf ) ) {
2805 ber_bvarray_free_x( c->rvalue_vals, NULL );
2806 c->rvalue_vals = NULL;
2810 bv.bv_len += sec_keys[i].key.bv_len;
2811 bv.bv_val = ch_malloc( bv.bv_len + 1);
2812 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
2813 strcpy( next, numbuf );
2814 ber_bvarray_add( &c->rvalue_vals, &bv );
2819 for(i = 1; i < c->argc; i++) {
2820 slap_ssf_t *tgt = NULL;
2822 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
2823 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
2824 sec_keys[j].key.bv_len)) {
2825 src = c->argv[i] + sec_keys[j].key.bv_len;
2826 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
2831 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown factor", c->argv[0] );
2832 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2833 c->log, c->cr_msg, c->argv[i]);
2837 if ( lutil_atou( tgt, src ) != 0 ) {
2838 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse factor", c->argv[0] );
2839 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2840 c->log, c->cr_msg, c->argv[i]);
2848 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
2852 for (; !BER_BVISNULL( &an->an_name ); an++) {
2853 /* if buflen == 0, assume the buffer size has been
2854 * already checked otherwise */
2855 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
2856 if ( comma ) *ptr++ = ',';
2857 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
2864 config_updatedn(ConfigArgs *c) {
2865 if (c->op == SLAP_CONFIG_EMIT) {
2866 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
2867 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
2868 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
2872 } else if ( c->op == LDAP_MOD_DELETE ) {
2873 ch_free( c->be->be_update_ndn.bv_val );
2874 BER_BVZERO( &c->be->be_update_ndn );
2875 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
2878 if(SLAP_SHADOW(c->be)) {
2879 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database already shadowed", c->argv[0] );
2880 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2881 c->log, c->cr_msg, 0);
2885 ber_memfree_x( c->value_dn.bv_val, NULL );
2886 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
2887 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
2889 c->be->be_update_ndn = c->value_ndn;
2890 BER_BVZERO( &c->value_dn );
2891 BER_BVZERO( &c->value_ndn );
2893 return config_slurp_shadow( c );
2897 config_shadow( ConfigArgs *c, int flag )
2899 char *notallowed = NULL;
2901 if ( c->be == frontendDB ) {
2902 notallowed = "frontend";
2904 } else if ( SLAP_MONITOR(c->be) ) {
2905 notallowed = "monitor";
2908 if ( notallowed != NULL ) {
2909 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
2913 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SINGLE_SHADOW | flag);
2919 config_updateref(ConfigArgs *c) {
2921 if (c->op == SLAP_CONFIG_EMIT) {
2922 if ( c->be->be_update_refs ) {
2923 value_add( &c->rvalue_vals, c->be->be_update_refs );
2928 } else if ( c->op == LDAP_MOD_DELETE ) {
2929 if ( c->valx < 0 ) {
2930 ber_bvarray_free( c->be->be_update_refs );
2931 c->be->be_update_refs = NULL;
2934 ch_free( c->be->be_update_refs[i].bv_val );
2935 for (; c->be->be_update_refs[i].bv_val; i++)
2936 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
2940 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
2941 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must appear after syncrepl or updatedn",
2943 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2944 c->log, c->cr_msg, 0);
2948 if(validate_global_referral(c->argv[1])) {
2949 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
2950 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2951 c->log, c->cr_msg, c->argv[1]);
2954 ber_str2bv(c->argv[1], 0, 0, &val);
2955 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
2960 config_obsolete(ConfigArgs *c) {
2961 if (c->op == SLAP_CONFIG_EMIT)
2964 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> keyword is obsolete (ignored)",
2966 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0);
2971 config_include(ConfigArgs *c) {
2972 int savelineno = c->lineno;
2975 ConfigFile *cfsave = cfn;
2976 ConfigFile *cf2 = NULL;
2978 /* Leftover from RE23. No dynamic config for include files */
2979 if ( c->op == SLAP_CONFIG_EMIT || c->op == LDAP_MOD_DELETE )
2982 cf = ch_calloc( 1, sizeof(ConfigFile));
2983 if ( cfn->c_kids ) {
2984 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
2990 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
2991 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
2992 c->lineno = savelineno - 1;
2995 if ( cf2 ) cf2->c_sibs = NULL;
2996 else cfn->c_kids = NULL;
2997 ch_free( cf->c_file.bv_val );
3007 config_tls_option(ConfigArgs *c) {
3009 LDAP *ld = slap_tls_ld;
3011 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
3012 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
3013 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
3014 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
3015 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
3016 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
3017 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
3019 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
3021 default: Debug(LDAP_DEBUG_ANY, "%s: "
3022 "unknown tls_option <0x%x>\n",
3023 c->log, c->type, 0);
3026 if (c->op == SLAP_CONFIG_EMIT) {
3027 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
3028 } else if ( c->op == LDAP_MOD_DELETE ) {
3029 return ldap_pvt_tls_set_option( ld, flag, NULL );
3031 ch_free(c->value_string);
3032 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
3035 /* FIXME: this ought to be provided by libldap */
3037 config_tls_config(ConfigArgs *c) {
3040 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
3041 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
3043 Debug(LDAP_DEBUG_ANY, "%s: "
3044 "unknown tls_option <0x%x>\n",
3045 c->log, c->type, 0);
3048 if (c->op == SLAP_CONFIG_EMIT) {
3049 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
3050 } else if ( c->op == LDAP_MOD_DELETE ) {
3052 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
3054 ch_free( c->value_string );
3055 if ( isdigit( (unsigned char)c->argv[1][0] ) ) {
3056 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
3057 Debug(LDAP_DEBUG_ANY, "%s: "
3058 "unable to parse %s \"%s\"\n",
3059 c->log, c->argv[0], c->argv[1] );
3062 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
3064 return(ldap_int_tls_config(slap_tls_ld, flag, c->argv[1]));
3069 static CfEntryInfo *
3070 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
3080 if ( dn_match( &root->ce_entry->e_nname, dn ))
3083 c = dn->bv_val+dn->bv_len;
3084 for (;*c != ',';c--);
3088 for (--c;c>dn->bv_val && *c != ',';c--);
3092 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
3094 root = root->ce_kids;
3096 for (;root;root=root->ce_sibs) {
3097 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
3098 if ( cdn.bv_val == dn->bv_val ) {
3108 typedef struct setup_cookie {
3118 config_ldif_resp( Operation *op, SlapReply *rs )
3120 if ( rs->sr_type == REP_SEARCH ) {
3121 setup_cookie *sc = op->o_callback->sc_private;
3123 sc->cfb->cb_got_ldif = 1;
3124 /* Does the frontend exist? */
3125 if ( !sc->got_frontend ) {
3126 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
3127 "olcDatabase", STRLENOF( "olcDatabase" ))) {
3128 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3129 STRLENOF( "olcDatabase" ), "={-1}frontend",
3130 STRLENOF( "={-1}frontend" ))) {
3133 sc->ca->be = frontendDB;
3134 sc->ca->bi = frontendDB->bd_info;
3135 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
3136 rdn.bv_val = sc->ca->log;
3137 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3138 "%s=" SLAP_X_ORDERED_FMT "%s",
3139 cfAd_database->ad_cname.bv_val, -1,
3140 sc->ca->bi->bi_type);
3142 sc->frontend = config_build_entry( op, rs,
3143 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
3144 sc->ca->be->be_cf_ocs );
3153 /* Does the configDB exist? */
3154 if ( sc->got_frontend && !sc->got_config &&
3155 !strncmp( rs->sr_entry->e_nname.bv_val,
3156 "olcDatabase", STRLENOF( "olcDatabase" ))) {
3157 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3158 STRLENOF( "olcDatabase" ), "={0}config",
3159 STRLENOF( "={0}config" ))) {
3162 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
3163 sc->ca->bi = sc->ca->be->bd_info;
3164 rdn.bv_val = sc->ca->log;
3165 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3166 "%s=" SLAP_X_ORDERED_FMT "%s",
3167 cfAd_database->ad_cname.bv_val, 0,
3168 sc->ca->bi->bi_type);
3170 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
3171 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
3178 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
3179 if ( rs->sr_err != LDAP_SUCCESS ) {
3180 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
3181 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg, 0 );
3187 /* Configure and read the underlying back-ldif store */
3189 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
3190 CfBackInfo *cfb = be->be_private;
3196 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
3197 Connection conn = {0};
3198 OperationBuffer opbuf;
3200 SlapReply rs = {REP_RESULT};
3201 Filter filter = { LDAP_FILTER_PRESENT };
3202 struct berval filterstr = BER_BVC("(objectclass=*)");
3205 /* Is the config directory available? */
3206 if ( stat( dir, &st ) < 0 ) {
3207 /* No, so don't bother using the backing store.
3208 * All changes will be in-memory only.
3213 cfb->cb_db.bd_info = backend_info( "ldif" );
3214 if ( !cfb->cb_db.bd_info )
3215 return 0; /* FIXME: eventually this will be a fatal error */
3217 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
3220 cfb->cb_db.be_suffix = be->be_suffix;
3221 cfb->cb_db.be_nsuffix = be->be_nsuffix;
3223 /* The suffix is always "cn=config". The underlying DB's rootdn
3224 * is always the same as the suffix.
3226 cfb->cb_db.be_rootdn = be->be_suffix[0];
3227 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
3229 ber_str2bv( dir, 0, 1, &cfdir );
3234 argv[0] = "directory";
3235 argv[1] = (char *)dir;
3240 c.table = Cft_Database;
3242 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
3246 if ( config_add_vals( ct, &c ))
3249 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
3253 void *thrctx = ldap_pvt_thread_pool_context();
3256 connection_fake_init( &conn, &opbuf, thrctx );
3259 filter.f_desc = slap_schema.si_ad_objectClass;
3261 op->o_tag = LDAP_REQ_SEARCH;
3263 op->ors_filter = &filter;
3264 op->ors_filterstr = filterstr;
3265 op->ors_scope = LDAP_SCOPE_SUBTREE;
3267 op->o_dn = c.be->be_rootdn;
3268 op->o_ndn = c.be->be_rootndn;
3270 op->o_req_dn = be->be_suffix[0];
3271 op->o_req_ndn = be->be_nsuffix[0];
3273 op->ors_tlimit = SLAP_NO_LIMIT;
3274 op->ors_slimit = SLAP_NO_LIMIT;
3276 op->ors_attrs = slap_anlist_all_attributes;
3277 op->ors_attrsonly = 0;
3279 op->o_callback = &cb;
3282 cb.sc_private = ≻
3283 sc.got_frontend = 0;
3288 op->o_bd = &cfb->cb_db;
3290 /* Allow unknown attrs in DNs */
3291 prev_DN_strict = slap_DN_strict;
3294 rc = op->o_bd->be_search( op, &rs );
3296 /* Restore normal DN validation */
3297 slap_DN_strict = prev_DN_strict;
3299 op->o_tag = LDAP_REQ_ADD;
3300 if ( rc == LDAP_SUCCESS && sc.frontend ) {
3301 op->ora_e = sc.frontend;
3302 rc = op->o_bd->be_add( op, &rs );
3304 if ( rc == LDAP_SUCCESS && sc.config ) {
3305 op->ora_e = sc.config;
3306 rc = op->o_bd->be_add( op, &rs );
3308 ldap_pvt_thread_pool_context_reset( thrctx );
3311 /* ITS#4194 - only use if it's present, or we're converting. */
3312 if ( !readit || rc == LDAP_SUCCESS )
3313 cfb->cb_use_ldif = 1;
3319 CfOc_cmp( const void *c1, const void *c2 ) {
3320 const ConfigOCs *co1 = c1;
3321 const ConfigOCs *co2 = c2;
3323 return ber_bvcmp( co1->co_name, co2->co_name );
3327 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
3330 i = init_config_attrs( ct );
3333 /* set up the objectclasses */
3334 i = init_config_ocs( ocs );
3337 for (i=0; ocs[i].co_def; i++) {
3338 if ( ocs[i].co_oc ) {
3339 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
3340 if ( !ocs[i].co_table )
3341 ocs[i].co_table = ct;
3342 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
3349 read_config(const char *fname, const char *dir) {
3352 const char *cfdir, *cfname;
3355 /* Setup the config backend */
3356 be = backend_db_init( "config", NULL, 0, NULL );
3360 cfb = be->be_private;
3361 be->be_dfltaccess = ACL_NONE;
3363 /* If no .conf, or a dir was specified, setup the dir */
3364 if ( !fname || dir ) {
3366 /* If explicitly given, check for existence */
3369 if ( stat( dir, &st ) < 0 ) {
3370 Debug( LDAP_DEBUG_ANY,
3371 "invalid config directory %s, error %d\n",
3377 cfdir = SLAPD_DEFAULT_CONFIGDIR;
3379 /* if fname is defaulted, try reading .d */
3380 rc = config_setup_ldif( be, cfdir, !fname );
3383 /* It may be OK if the base object doesn't exist yet. */
3384 if ( rc != LDAP_NO_SUCH_OBJECT )
3386 /* ITS#4194: But if dir was specified and no fname,
3387 * then we were supposed to read the dir. Unless we're
3388 * trying to slapadd the dir...
3390 if ( dir && !fname ) {
3391 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
3393 /* Assume it's slapadd with a config dir, let it continue */
3395 cfb->cb_got_ldif = 1;
3396 cfb->cb_use_ldif = 1;
3401 /* If we read the config from back-ldif, nothing to do here */
3402 if ( cfb->cb_got_ldif ) {
3411 cfname = SLAPD_DEFAULT_CONFIGFILE;
3413 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
3416 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
3419 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
3420 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
3421 &frontendDB->be_schemadn );
3422 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
3423 if ( rc != LDAP_SUCCESS ) {
3424 Debug(LDAP_DEBUG_ANY, "read_config: "
3425 "unable to normalize default schema DN \"%s\"\n",
3426 frontendDB->be_schemadn.bv_val, 0, 0 );
3427 /* must not happen */
3435 config_back_bind( Operation *op, SlapReply *rs )
3437 if ( be_isroot_pw( op ) ) {
3438 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
3439 /* frontend sends result */
3440 return LDAP_SUCCESS;
3443 rs->sr_err = LDAP_INVALID_CREDENTIALS;
3444 send_ldap_result( op, rs );
3450 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
3454 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
3456 rs->sr_attrs = op->ors_attrs;
3457 rs->sr_entry = ce->ce_entry;
3459 rc = send_search_entry( op, rs );
3461 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
3462 if ( ce->ce_kids ) {
3463 rc = config_send( op, rs, ce->ce_kids, 1 );
3464 if ( rc ) return rc;
3467 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
3468 rc = config_send( op, rs, ce, 0 );
3476 static ConfigTable *
3477 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
3482 for (j=0; j<nocs; j++) {
3483 for (i=0; colst[j]->co_table[i].name; i++)
3484 if ( colst[j]->co_table[i].ad == ad ) {
3485 ca->table = colst[j]->co_type;
3486 return &colst[j]->co_table[i];
3492 /* Sort the attributes of the entry according to the order defined
3493 * in the objectclass, with required attributes occurring before
3494 * allowed attributes. For any attributes with sequencing dependencies
3495 * (e.g., rootDN must be defined after suffix) the objectclass must
3496 * list the attributes in the desired sequence.
3499 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
3501 Attribute *a, *head = NULL, *tail = NULL, **prev;
3504 for (i=0; i<nocs; i++) {
3505 if ( colst[i]->co_oc->soc_required ) {
3506 AttributeType **at = colst[i]->co_oc->soc_required;
3507 for (j=0; at[j]; j++) {
3508 for (a=e->e_attrs, prev=&e->e_attrs; a;
3509 prev = &(*prev)->a_next, a=a->a_next) {
3510 if ( a->a_desc == at[j]->sat_ad ) {
3524 if ( colst[i]->co_oc->soc_allowed ) {
3525 AttributeType **at = colst[i]->co_oc->soc_allowed;
3526 for (j=0; at[j]; j++) {
3527 for (a=e->e_attrs, prev=&e->e_attrs; a;
3528 prev = &(*prev)->a_next, a=a->a_next) {
3529 if ( a->a_desc == at[j]->sat_ad ) {
3545 tail->a_next = e->e_attrs;
3551 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
3553 Attribute *a = NULL;
3554 AttributeDescription *ad;
3564 Modifications *ml = ptr;
3566 vals = ml->sml_values;
3569 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
3570 rc = ordered_value_sort( a, 1 );
3572 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
3573 ad->ad_cname.bv_val );
3577 for ( i=0; vals[i].bv_val; i++ ) {
3578 ca->line = vals[i].bv_val;
3579 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
3580 ca->line[0] == '{' ) {
3581 char *idx = strchr( ca->line, '}' );
3582 if ( idx ) ca->line = idx+1;
3584 rc = config_parse_vals( ct, ca, i );
3593 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
3596 struct berval rtype, rval;
3598 AttributeDescription *ad = NULL;
3600 dnRdn( &e->e_name, rdn );
3601 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
3602 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
3603 rtype.bv_val = rdn->bv_val;
3604 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
3607 slap_bv2ad( &rtype, &ad, &rs->sr_text );
3608 a = attr_find( e->e_attrs, ad );
3609 if (!a ) return LDAP_NAMING_VIOLATION;
3616 config_rename_kids( CfEntryInfo *ce )
3619 struct berval rdn, nrdn;
3621 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
3622 dnRdn ( &ce2->ce_entry->e_name, &rdn );
3623 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
3624 free( ce2->ce_entry->e_name.bv_val );
3625 free( ce2->ce_entry->e_nname.bv_val );
3626 build_new_dn( &ce2->ce_entry->e_name, &ce->ce_entry->e_name,
3628 build_new_dn( &ce2->ce_entry->e_nname, &ce->ce_entry->e_nname,
3630 config_rename_kids( ce2 );
3635 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
3636 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
3637 struct berval *nnewrdn, int use_ldif )
3641 struct berval odn, ondn;
3645 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
3646 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
3649 free( a->a_vals[0].bv_val );
3650 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
3651 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
3652 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
3653 strcpy( a->a_vals[0].bv_val, ptr1 );
3655 if ( a->a_nvals != a->a_vals ) {
3656 free( a->a_nvals[0].bv_val );
3657 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
3658 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
3659 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
3660 strcpy( a->a_nvals[0].bv_val, ptr1 );
3663 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
3664 BackendDB *be = op->o_bd;
3665 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
3666 struct berval dn, ndn, xdn, xndn;
3668 op->o_bd = &cfb->cb_db;
3670 /* Save current rootdn; use the underlying DB's rootdn */
3674 xndn = op->o_req_ndn;
3675 op->o_dn = op->o_bd->be_rootdn;
3676 op->o_ndn = op->o_bd->be_rootndn;
3678 op->o_req_ndn = ondn;
3680 scp = op->o_callback;
3681 op->o_callback = ≻
3682 op->orr_newrdn = *newrdn;
3683 op->orr_nnewrdn = *nnewrdn;
3684 op->orr_newSup = NULL;
3685 op->orr_nnewSup = NULL;
3686 op->orr_deleteoldrdn = 1;
3687 op->orr_modlist = NULL;
3688 slap_modrdn2mods( op, rs );
3689 slap_mods_opattrs( op, &op->orr_modlist, 1 );
3690 rc = op->o_bd->be_modrdn( op, rs );
3691 slap_mods_free( op->orr_modlist, 1 );
3694 op->o_callback = scp;
3698 op->o_req_ndn = xndn;
3701 free( ondn.bv_val );
3703 config_rename_kids( e->e_private );
3708 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
3709 Entry *e, int idx, int tailindex, int use_ldif )
3711 struct berval ival, newrdn, nnewrdn;
3714 char ibuf[32], *ptr1, *ptr2 = NULL;
3717 rc = config_rename_attr( rs, e, &rdn, &a );
3718 if ( rc ) return rc;
3721 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
3722 if ( ival.bv_len >= sizeof( ibuf ) ) {
3723 return LDAP_NAMING_VIOLATION;
3726 newrdn.bv_len = rdn.bv_len + ival.bv_len;
3727 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
3730 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
3731 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3734 ptr2 = ber_bvchr( &rdn, '}' );
3738 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
3740 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
3741 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
3742 a->a_desc->ad_cname.bv_len );
3744 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3745 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
3749 /* Do the equivalent of ModRDN */
3750 /* Replace DN / NDN */
3751 newrdn.bv_len = ptr1 - newrdn.bv_val;
3752 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
3753 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
3755 free( nnewrdn.bv_val );
3756 free( newrdn.bv_val );
3761 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
3762 SlapReply *rs, int *renum, int *ibase )
3765 int index = -1, gotindex = 0, nsibs, rc = 0;
3766 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
3767 char *ptr1, *ptr2 = NULL;
3770 if ( renum ) *renum = 0;
3772 /* These entries don't get indexed/renumbered */
3773 if ( ce_type == Cft_Global ) return 0;
3774 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
3776 if ( ce_type == Cft_Module )
3779 /* See if the rdn has an index already */
3780 dnRdn( &e->e_name, &rdn );
3781 if ( ce_type == Cft_Database ) {
3782 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
3783 "frontend", STRLENOF("frontend") ))
3785 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
3786 "config", STRLENOF("config") ))
3789 ptr1 = ber_bvchr( &e->e_name, '{' );
3790 if ( ptr1 && ptr1 - e->e_name.bv_val < rdn.bv_len ) {
3792 ptr2 = strchr( ptr1, '}' );
3793 if (!ptr2 || ptr2 - e->e_name.bv_val > rdn.bv_len)
3794 return LDAP_NAMING_VIOLATION;
3795 if ( ptr2-ptr1 == 1)
3796 return LDAP_NAMING_VIOLATION;
3798 index = strtol( ptr1 + 1, &next, 10 );
3799 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
3800 return LDAP_NAMING_VIOLATION;
3803 /* Special case, we allow -1 for the frontendDB */
3804 if ( index != -1 || !isfrontend )
3805 return LDAP_NAMING_VIOLATION;
3807 if ( isconfig && index != 0 ){
3808 return LDAP_NAMING_VIOLATION;
3812 /* count related kids */
3813 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
3814 if ( ce->ce_type == ce_type ) nsibs++;
3817 /* account for -1 frontend */
3818 if ( ce_type == Cft_Database )
3821 if ( index != nsibs ) {
3823 if ( index < nsibs ) {
3824 if ( tailindex ) return LDAP_NAMING_VIOLATION;
3825 /* Siblings need to be renumbered */
3826 if ( index != -1 || !isfrontend )
3830 /* config DB is always "0" */
3831 if ( isconfig && index == -1 ) {
3834 if ( !isfrontend && index == -1 ) {
3838 /* just make index = nsibs */
3840 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
3843 if ( ibase ) *ibase = index;
3844 if ( renum ) *renum = renumber;
3849 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
3854 co.co_name = &oc->soc_cname;
3855 cop = avl_find( CfOcTree, &co, CfOc_cmp );
3859 /* check for duplicates */
3860 for ( i = 0; i < *nocs; i++ ) {
3861 if ( *copp && (*copp)[i] == cop ) {
3867 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
3868 if ( tmp == NULL ) {
3872 (*copp)[*nocs] = cop;
3877 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
3878 if ( count_oc( *sups, copp, nocs ) ) {
3887 count_ocs( Attribute *oc_at, int *nocs )
3890 ConfigOCs **colst = NULL;
3894 for ( i = 0; !BER_BVISNULL( &oc_at->a_nvals[i] ); i++ )
3898 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
3900 assert( oc != NULL );
3901 if ( count_oc( oc, &colst, nocs ) ) {
3911 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
3913 /* Leftover from RE23. Never parse this entry */
3914 return LDAP_COMPARE_TRUE;
3918 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
3922 /* This entry is hardcoded, don't re-parse it */
3923 if ( p->ce_type == Cft_Global ) {
3924 cfn = p->ce_private;
3926 return LDAP_COMPARE_TRUE;
3928 if ( p->ce_type != Cft_Schema )
3929 return LDAP_CONSTRAINT_VIOLATION;
3931 cfn = ch_calloc( 1, sizeof(ConfigFile) );
3933 cfo = p->ce_private;
3934 cfn->c_sibs = cfo->c_kids;
3936 return LDAP_SUCCESS;
3940 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3942 if ( p->ce_type != Cft_Global ) {
3943 return LDAP_CONSTRAINT_VIOLATION;
3945 ca->be = frontendDB; /* just to get past check_vals */
3946 return LDAP_SUCCESS;
3950 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3952 if ( p->ce_type != Cft_Global ) {
3953 return LDAP_CONSTRAINT_VIOLATION;
3955 return LDAP_SUCCESS;
3959 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3961 if ( p->ce_type != Cft_Global ) {
3962 return LDAP_CONSTRAINT_VIOLATION;
3964 return LDAP_SUCCESS;
3968 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3970 if ( p->ce_type != Cft_Database ) {
3971 return LDAP_CONSTRAINT_VIOLATION;
3974 return LDAP_SUCCESS;
3978 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
3983 AttributeDescription *ad;
3988 if ( cfn->c_cr_head ) {
3989 struct berval bv = BER_BVC("olcDitContentRules");
3991 slap_bv2ad( &bv, &ad, &text );
3992 ct = config_find_table( colst, nocs, ad, ca );
3993 config_del_vals( ct, ca );
3995 if ( cfn->c_oc_head ) {
3996 struct berval bv = BER_BVC("olcObjectClasses");
3998 slap_bv2ad( &bv, &ad, &text );
3999 ct = config_find_table( colst, nocs, ad, ca );
4000 config_del_vals( ct, ca );
4002 if ( cfn->c_at_head ) {
4003 struct berval bv = BER_BVC("olcAttributeTypes");
4005 slap_bv2ad( &bv, &ad, &text );
4006 ct = config_find_table( colst, nocs, ad, ca );
4007 config_del_vals( ct, ca );
4009 if ( cfn->c_om_head ) {
4010 struct berval bv = BER_BVC("olcObjectIdentifier");
4012 slap_bv2ad( &bv, &ad, &text );
4013 ct = config_find_table( colst, nocs, ad, ca );
4014 config_del_vals( ct, ca );
4016 cfo = p->ce_private;
4017 cfo->c_kids = cfn->c_sibs;
4022 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
4024 int rc = LDAP_CONSTRAINT_VIOLATION;
4027 if ( (*cop)->co_ldadd ) {
4028 rc = (*cop)->co_ldadd( last, e, ca );
4029 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4034 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
4035 ConfigOCs co = { 0 };
4037 co.co_name = &(*ocp)->soc_cname;
4038 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
4039 if ( *cop == NULL ) {
4043 rc = config_add_oc( cop, last, e, ca );
4044 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4052 /* Parse an LDAP entry into config directives */
4054 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
4055 int *renum, Operation *op )
4057 CfEntryInfo *ce, *last = NULL;
4058 ConfigOCs co, *coptr, **colst;
4059 Attribute *a, *oc_at, *soc_at;
4060 int i, ibase = -1, nocs, rc = 0;
4063 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
4065 memset( ca, 0, sizeof(ConfigArgs));
4067 /* Make sure parent exists and entry does not. But allow
4068 * Databases and Overlays to be inserted. Don't do any
4069 * auto-renumbering if manageDSAit control is present.
4071 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
4073 if ( ( op && op->o_managedsait ) ||
4074 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
4075 ce->ce_type != Cft_Module ) )
4077 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4078 "DN=\"%s\" already exists\n",
4079 log_prefix, e->e_name.bv_val, 0 );
4080 return LDAP_ALREADY_EXISTS;
4084 dnParent( &e->e_nname, &pdn );
4086 /* If last is NULL, the new entry is the root/suffix entry,
4087 * otherwise last should be the parent.
4089 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
4091 rs->sr_matched = last->ce_entry->e_name.bv_val;
4093 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4094 "DN=\"%s\" not child of DN=\"%s\"\n",
4095 log_prefix, e->e_name.bv_val,
4096 last->ce_entry->e_name.bv_val );
4097 return LDAP_NO_SUCH_OBJECT;
4101 /* No parent, must be root. This will never happen... */
4102 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
4103 return LDAP_NO_SUCH_OBJECT;
4106 if ( last && !access_allowed( op, last->ce_entry,
4107 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
4109 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4110 "DN=\"%s\" no write access to \"children\" of parent\n",
4111 log_prefix, e->e_name.bv_val, 0 );
4112 return LDAP_INSUFFICIENT_ACCESS;
4116 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4118 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4119 "DN=\"%s\" no objectClass\n",
4120 log_prefix, e->e_name.bv_val, 0 );
4121 return LDAP_OBJECT_CLASS_VIOLATION;
4124 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4126 ObjectClass *soc = NULL;
4127 char textbuf[ SLAP_TEXT_BUFLEN ];
4128 const char *text = textbuf;
4130 /* FIXME: check result */
4131 rc = structural_class( oc_at->a_nvals, &soc, NULL,
4132 &text, textbuf, sizeof(textbuf), NULL );
4133 if ( rc != LDAP_SUCCESS ) {
4134 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4135 "DN=\"%s\" no structural objectClass (%s)\n",
4136 log_prefix, e->e_name.bv_val, text );
4139 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
4140 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4141 if ( soc_at == NULL ) {
4142 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4143 "DN=\"%s\" no structural objectClass; "
4144 "unable to merge computed class %s\n",
4145 log_prefix, e->e_name.bv_val,
4146 soc->soc_cname.bv_val );
4147 return LDAP_OBJECT_CLASS_VIOLATION;
4150 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4151 "DN=\"%s\" no structural objectClass; "
4152 "computed objectClass %s merged\n",
4153 log_prefix, e->e_name.bv_val,
4154 soc->soc_cname.bv_val );
4157 /* Fake the coordinates based on whether we're part of an
4158 * LDAP Add or if reading the config dir
4161 ca->fname = "slapd";
4164 ca->fname = cfdir.bv_val;
4169 co.co_name = &soc_at->a_nvals[0];
4170 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
4171 if ( coptr == NULL ) {
4172 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4173 "DN=\"%s\" no structural objectClass in configuration table\n",
4174 log_prefix, e->e_name.bv_val, 0 );
4175 return LDAP_OBJECT_CLASS_VIOLATION;
4178 /* Only the root can be Cft_Global, everything else must
4179 * have a parent. Only limited nesting arrangements are allowed.
4181 rc = LDAP_CONSTRAINT_VIOLATION;
4182 if ( coptr->co_type == Cft_Global && !last ) {
4183 cfn = cfb->cb_config;
4185 ca->be = frontendDB; /* just to get past check_vals */
4189 /* Check whether the Add is allowed by its parent, and do
4190 * any necessary arg setup
4193 rc = config_add_oc( &coptr, last, e, ca );
4194 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4195 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4196 "DN=\"%s\" no structural objectClass add function\n",
4197 log_prefix, e->e_name.bv_val, 0 );
4198 return LDAP_OBJECT_CLASS_VIOLATION;
4202 colst = count_ocs( oc_at, &nocs );
4204 /* Add the entry but don't parse it, we already have its contents */
4205 if ( rc == LDAP_COMPARE_TRUE ) {
4210 if ( rc != LDAP_SUCCESS )
4213 /* Parse all the values and check for simple syntax errors before
4214 * performing any set actions.
4216 * If doing an LDAPadd, check for indexed names and any necessary
4217 * renaming/renumbering. Entries that don't need indexed names are
4218 * ignored. Entries that need an indexed name and arrive without one
4219 * are assigned to the end. Entries that arrive with an index may
4220 * cause the following entries to be renumbered/bumped down.
4222 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
4223 * don't allow Adding an entry with an index that's already in use.
4224 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
4226 * These entries can have auto-assigned indexes (appended to the end)
4227 * but only the other types support auto-renumbering of siblings.
4230 rc = check_name_index( last, coptr->co_type, e, rs, renum,
4235 if ( renum && *renum && coptr->co_type != Cft_Database &&
4236 coptr->co_type != Cft_Overlay )
4238 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
4239 "operation requires sibling renumbering" );
4240 rc = LDAP_UNWILLING_TO_PERFORM;
4245 init_config_argv( ca );
4247 /* Make sure we process attrs in the required order */
4248 sort_attrs( e, colst, nocs );
4250 for ( a = e->e_attrs; a; a = a->a_next ) {
4251 if ( a == oc_at ) continue;
4252 ct = config_find_table( colst, nocs, a->a_desc, ca );
4253 if ( !ct ) continue; /* user data? */
4254 rc = check_vals( ct, ca, a, 1 );
4255 if ( rc ) goto done_noop;
4258 /* Basic syntax checks are OK. Do the actual settings. */
4259 for ( a=e->e_attrs; a; a=a->a_next ) {
4260 if ( a == oc_at ) continue;
4261 ct = config_find_table( colst, nocs, a->a_desc, ca );
4262 if ( !ct ) continue; /* user data? */
4263 for (i=0; a->a_vals[i].bv_val; i++) {
4265 ca->line = a->a_vals[i].bv_val;
4266 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
4267 ptr = strchr( ca->line, '}' );
4269 iptr = strchr( ca->line, '{' );
4273 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
4275 ca->valx = strtol( iptr+1, NULL, 0 );
4282 rc = config_parse_add( ct, ca, i );
4290 /* Newly added databases and overlays need to be started up */
4291 if ( CONFIG_ONLINE_ADD( ca )) {
4292 if ( colst[0]->co_type == Cft_Database ) {
4293 rc = backend_startup_one( ca->be, &ca->reply );
4295 } else if ( colst[0]->co_type == Cft_Overlay ) {
4296 if ( ca->bi->bi_db_open ) {
4297 BackendInfo *bi_orig = ca->be->bd_info;
4298 ca->be->bd_info = ca->bi;
4299 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
4300 ca->be->bd_info = bi_orig;
4304 if (ca->cr_msg[0] == '\0')
4305 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
4307 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
4308 ca->log, ca->cr_msg, ca->argv[1] );
4315 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
4316 ce->ce_parent = last;
4317 ce->ce_entry = entry_dup( e );
4318 ce->ce_entry->e_private = ce;
4319 ce->ce_type = colst[0]->co_type;
4322 ce->ce_private = ca->private;
4323 ca->ca_entry = ce->ce_entry;
4326 } else if ( last->ce_kids ) {
4327 CfEntryInfo *c2, **cprev;
4329 /* Advance to first of this type */
4330 cprev = &last->ce_kids;
4331 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
4332 cprev = &c2->ce_sibs;
4335 /* Account for the (-1) frontendDB entry */
4336 if ( ce->ce_type == Cft_Database ) {
4337 if ( ca->be == frontendDB )
4339 else if ( ibase != -1 )
4344 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
4345 cprev = &c2->ce_sibs;
4351 for ( i=0; i<ibase; i++ ) {
4353 cprev = &c2->ce_sibs;
4356 ce->ce_sibs = *cprev;
4364 if ( (colst[0]->co_type == Cft_Database) && ca->be ) {
4365 if ( ca->be != frontendDB )
4366 backend_destroy_one( ca->be, 1 );
4367 } else if ( (colst[0]->co_type == Cft_Overlay) && ca->bi ) {
4368 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
4369 } else if ( colst[0]->co_type == Cft_Schema ) {
4370 schema_destroy_one( ca, colst, nocs, last );
4375 ch_free( ca->argv );
4376 if ( colst ) ch_free( colst );
4380 #define BIGTMP 10000
4382 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
4383 int base, int rebase, int max, int use_ldif )
4385 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
4386 ConfigType etype = ce->ce_type;
4387 int count = 0, rc = 0;
4389 /* Reverse ce list */
4390 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
4391 if (ce2->ce_type != etype) {
4396 ce2->ce_sibs = cetmp;
4399 if ( max && count >= max ) {
4405 /* Move original to a temp name until increments are done */
4407 ce->ce_entry->e_private = NULL;
4408 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4409 base+BIGTMP, 0, use_ldif );
4410 ce->ce_entry->e_private = ce;
4412 /* start incrementing */
4413 for (ce2=cetmp; ce2; ce2=ce3) {
4415 ce2->ce_sibs = cerem;
4418 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
4419 count+base, 0, use_ldif );
4423 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4424 base, 0, use_ldif );
4429 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
4430 CfEntryInfo *ce2, int old, int use_ldif )
4434 /* Renumber original to a temp value */
4435 ce->ce_entry->e_private = NULL;
4436 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4437 old+BIGTMP, 0, use_ldif );
4438 ce->ce_entry->e_private = ce;
4440 /* start decrementing */
4441 for (; ce2 != ce; ce2=ce2->ce_sibs) {
4442 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
4443 count+old, 0, use_ldif );
4446 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4447 count+old, 0, use_ldif );
4450 /* Parse an LDAP entry into config directives, then store in underlying
4454 config_back_add( Operation *op, SlapReply *rs )
4460 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
4461 NULL, ACL_WADD, NULL )) {
4462 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4466 cfb = (CfBackInfo *)op->o_bd->be_private;
4468 /* add opattrs for syncprov */
4470 char textbuf[SLAP_TEXT_BUFLEN];
4471 size_t textlen = sizeof textbuf;
4472 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1,
4473 &rs->sr_text, textbuf, sizeof( textbuf ) );
4474 if ( rs->sr_err != LDAP_SUCCESS )
4476 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
4477 if ( rs->sr_err != LDAP_SUCCESS ) {
4478 Debug( LDAP_DEBUG_TRACE,
4479 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
4480 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
4485 ldap_pvt_thread_pool_pause( &connection_pool );
4488 * 1) check for existence of entry
4489 * 2) check for sibling renumbering
4490 * 3) perform internal add
4491 * 4) perform any necessary renumbering
4492 * 5) store entry in underlying database
4494 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
4495 if ( rs->sr_err != LDAP_SUCCESS ) {
4496 rs->sr_text = ca.cr_msg;
4501 CfEntryInfo *ce = ca.ca_entry->e_private;
4502 req_add_s addr = op->oq_add;
4503 op->o_tag = LDAP_REQ_MODRDN;
4504 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
4505 op->o_tag = LDAP_REQ_ADD;
4507 if ( rs->sr_err != LDAP_SUCCESS ) {
4512 if ( cfb->cb_use_ldif ) {
4513 BackendDB *be = op->o_bd;
4514 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4515 struct berval dn, ndn;
4517 op->o_bd = &cfb->cb_db;
4519 /* Save current rootdn; use the underlying DB's rootdn */
4522 op->o_dn = op->o_bd->be_rootdn;
4523 op->o_ndn = op->o_bd->be_rootndn;
4525 scp = op->o_callback;
4526 op->o_callback = ≻
4527 op->o_bd->be_add( op, rs );
4529 op->o_callback = scp;
4535 ldap_pvt_thread_pool_resume( &connection_pool );
4538 send_ldap_result( op, rs );
4539 slap_graduate_commit_csn( op );
4543 typedef struct delrec {
4544 struct delrec *next;
4550 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
4555 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
4556 ca->line[0] == '{' )
4558 char *ptr = strchr( ca->line + 1, '}' );
4562 ca->valx = strtol( ca->line + 1, &next, 0 );
4563 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
4569 rc = config_parse_add( ct, ca, i );
4577 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
4580 int rc = LDAP_UNWILLING_TO_PERFORM;
4582 Entry *e = ce->ce_entry;
4583 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
4588 delrec *dels = NULL, *deltail = NULL;
4590 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4591 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
4593 colst = count_ocs( oc_at, &nocs );
4595 /* make sure add/del flags are clear; should always be true */
4596 for ( s = save_attrs; s; s = s->a_next ) {
4597 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
4600 e->e_attrs = attrs_dup( e->e_attrs );
4602 init_config_argv( ca );
4605 ca->private = ce->ce_private;
4607 ca->fname = "slapd";
4609 strcpy( ca->log, "back-config" );
4611 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
4612 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
4613 switch (ml->sml_op) {
4614 case LDAP_MOD_DELETE:
4615 case LDAP_MOD_REPLACE: {
4616 BerVarray vals = NULL, nvals = NULL;
4618 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
4620 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
4621 ml->sml_desc->ad_cname.bv_val );
4624 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4625 vals = ml->sml_values;
4626 nvals = ml->sml_nvalues;
4627 ml->sml_values = NULL;
4628 ml->sml_nvalues = NULL;
4630 /* If we're deleting by values, remember the indexes of the
4631 * values we deleted.
4633 if ( ct && ml->sml_values ) {
4635 i = ml->sml_numvals;
4636 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
4647 rc = modify_delete_vindex(e, &ml->sml_mod,
4648 get_permissiveModify(op),
4649 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
4650 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4651 ml->sml_values = vals;
4652 ml->sml_nvalues = nvals;
4657 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
4660 case SLAP_MOD_SOFTADD: {
4661 int mop = ml->sml_op;
4663 ml->sml_op = LDAP_MOD_ADD;
4665 if ( ct->arg_type & ARG_NO_INSERT ) {
4666 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
4668 navals = a->a_numvals;
4671 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
4672 if ( ml->sml_values[i].bv_val[0] == '{' &&
4675 char *next, *val = ml->sml_values[i].bv_val + 1;
4678 j = strtol( val, &next, 0 );
4679 if ( next == val || next[ 0 ] != '}' || j < navals ) {
4681 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
4682 ml->sml_desc->ad_cname.bv_val );
4686 rc = check_vals( ct, ca, ml, 0 );
4687 if ( rc ) goto out_noop;
4690 rc = modify_add_values(e, &ml->sml_mod,
4691 get_permissiveModify(op),
4692 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
4694 /* If value already exists, show success here
4695 * and ignore this operation down below.
4697 if ( mop == SLAP_MOD_SOFTADD ) {
4698 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
4708 case LDAP_MOD_INCREMENT: /* FIXME */
4713 if(rc != LDAP_SUCCESS) break;
4716 if ( rc == LDAP_SUCCESS) {
4717 /* check that the entry still obeys the schema */
4718 rc = entry_schema_check(op, e, NULL, 0, 0,
4719 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
4720 if ( rc ) goto out_noop;
4722 /* Basic syntax checks are OK. Do the actual settings. */
4723 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
4724 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
4725 if ( !ct ) continue;
4727 s = attr_find( save_attrs, ml->sml_desc );
4728 a = attr_find( e->e_attrs, ml->sml_desc );
4730 switch (ml->sml_op) {
4731 case LDAP_MOD_DELETE:
4732 case LDAP_MOD_REPLACE: {
4733 BerVarray vals = NULL, nvals = NULL;
4736 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4737 vals = ml->sml_values;
4738 nvals = ml->sml_nvalues;
4739 ml->sml_values = NULL;
4740 ml->sml_nvalues = NULL;
4743 if ( ml->sml_values )
4746 /* If we didn't delete the whole attribute */
4747 if ( ml->sml_values && a ) {
4748 struct berval *mvals;
4751 if ( ml->sml_nvalues )
4752 mvals = ml->sml_nvalues;
4754 mvals = ml->sml_values;
4756 /* use the indexes we saved up above */
4757 for (i=0; i < d->nidx; i++) {
4758 struct berval bv = *mvals++;
4759 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
4760 bv.bv_val[0] == '{' ) {
4761 ptr = strchr( bv.bv_val, '}' ) + 1;
4762 bv.bv_len -= ptr - bv.bv_val;
4765 ca->line = bv.bv_val;
4766 ca->valx = d->idx[i];
4767 rc = config_del_vals( ct, ca );
4768 if ( rc != LDAP_SUCCESS ) break;
4770 s->a_flags |= SLAP_ATTR_IXDEL;
4771 for (j=i+1; j < d->nidx; j++)
4772 if ( d->idx[j] >d->idx[i] )
4778 rc = config_del_vals( ct, ca );
4779 if ( rc ) rc = LDAP_OTHER;
4781 s->a_flags |= SLAP_ATTR_IXDEL;
4783 if ( ml->sml_values ) {
4788 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4789 ml->sml_values = vals;
4790 ml->sml_nvalues = nvals;
4792 if ( !vals || rc != LDAP_SUCCESS )
4795 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
4798 for (i=0; ml->sml_values[i].bv_val; i++) {
4799 ca->line = ml->sml_values[i].bv_val;
4801 rc = config_modify_add( ct, ca, ml->sml_desc, i );
4804 a->a_flags |= SLAP_ATTR_IXADD;
4811 /* Undo for a failed operation */
4812 if ( rc != LDAP_SUCCESS ) {
4813 for ( s = save_attrs; s; s = s->a_next ) {
4814 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
4815 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
4816 ct = config_find_table( colst, nocs, s->a_desc, ca );
4817 a = attr_find( e->e_attrs, s->a_desc );
4819 /* clear the flag so the add check below will skip it */
4820 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
4823 config_del_vals( ct, ca );
4825 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
4826 ca->line = s->a_vals[i].bv_val;
4828 config_modify_add( ct, ca, s->a_desc, i );
4832 for ( a = e->e_attrs; a; a = a->a_next ) {
4833 if ( a->a_flags & SLAP_ATTR_IXADD ) {
4834 ct = config_find_table( colst, nocs, a->a_desc, ca );
4837 config_del_vals( ct, ca );
4838 s = attr_find( save_attrs, a->a_desc );
4840 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
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 );
4854 if ( rc == LDAP_SUCCESS ) {
4855 attrs_free( save_attrs );
4857 attrs_free( e->e_attrs );
4858 e->e_attrs = save_attrs;
4860 ch_free( ca->argv );
4861 if ( colst ) ch_free( colst );
4863 deltail = dels->next;
4872 config_back_modify( Operation *op, SlapReply *rs )
4875 CfEntryInfo *ce, *last;
4877 ConfigArgs ca = {0};
4880 AttributeDescription *rad = NULL;
4882 cfb = (CfBackInfo *)op->o_bd->be_private;
4884 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
4887 rs->sr_matched = last->ce_entry->e_name.bv_val;
4888 rs->sr_err = LDAP_NO_SUCH_OBJECT;
4892 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
4893 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4897 /* Get type of RDN */
4898 rdn = ce->ce_entry->e_nname;
4899 ptr = strchr( rdn.bv_val, '=' );
4900 rdn.bv_len = ptr - rdn.bv_val;
4901 slap_bv2ad( &rdn, &rad, &rs->sr_text );
4903 /* Some basic validation... */
4904 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
4905 /* Don't allow Modify of RDN; must use ModRdn for that. */
4906 if ( ml->sml_desc == rad ) {
4907 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
4908 rs->sr_text = "Use modrdn to change the entry name";
4913 slap_mods_opattrs( op, &op->orm_modlist, 1 );
4915 if ( !slapd_shutdown )
4916 ldap_pvt_thread_pool_pause( &connection_pool );
4919 * 1) perform the Modify on the cached Entry.
4920 * 2) verify that the Entry still satisfies the schema.
4921 * 3) perform the individual config operations.
4922 * 4) store Modified entry in underlying LDIF backend.
4924 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
4926 rs->sr_text = ca.cr_msg;
4927 } else if ( cfb->cb_use_ldif ) {
4928 BackendDB *be = op->o_bd;
4929 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4930 struct berval dn, ndn;
4932 op->o_bd = &cfb->cb_db;
4936 op->o_dn = op->o_bd->be_rootdn;
4937 op->o_ndn = op->o_bd->be_rootndn;
4939 scp = op->o_callback;
4940 op->o_callback = ≻
4941 op->o_bd->be_modify( op, rs );
4943 op->o_callback = scp;
4948 if ( !slapd_shutdown )
4949 ldap_pvt_thread_pool_resume( &connection_pool );
4951 send_ldap_result( op, rs );
4952 slap_graduate_commit_csn( op );
4957 config_back_modrdn( Operation *op, SlapReply *rs )
4960 CfEntryInfo *ce, *last;
4964 cfb = (CfBackInfo *)op->o_bd->be_private;
4966 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
4969 rs->sr_matched = last->ce_entry->e_name.bv_val;
4970 rs->sr_err = LDAP_NO_SUCH_OBJECT;
4973 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
4974 NULL, ACL_WRITE, NULL )) {
4975 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4979 if ( ce->ce_parent )
4980 parent = ce->ce_parent->ce_entry;
4982 parent = (Entry *)&slap_entry_root;
4983 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
4984 NULL, ACL_WRITE, NULL )) {
4985 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4990 /* We don't allow moving objects to new parents.
4991 * Generally we only allow reordering a set of ordered entries.
4993 if ( op->orr_newSup ) {
4994 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
4998 /* If newRDN == oldRDN, quietly succeed */
4999 dnRdn( &op->o_req_ndn, &rdn );
5000 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
5001 rs->sr_err = LDAP_SUCCESS;
5005 /* Current behavior, subject to change as needed:
5007 * For backends and overlays, we only allow renumbering.
5008 * For schema, we allow renaming with the same number.
5009 * Otherwise, the op is not allowed.
5012 if ( ce->ce_type == Cft_Schema ) {
5016 /* Can't alter the main cn=schema entry */
5017 if ( ce->ce_parent->ce_type == Cft_Global ) {
5018 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5019 rs->sr_text = "renaming not allowed for this entry";
5023 /* We could support this later if desired */
5024 ptr1 = ber_bvchr( &rdn, '}' );
5025 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5026 len = ptr1 - rdn.bv_val;
5027 if ( len != ptr2 - op->orr_newrdn.bv_val ||
5028 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
5029 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5030 rs->sr_text = "schema reordering not supported";
5033 } else if ( ce->ce_type == Cft_Database ||
5034 ce->ce_type == Cft_Overlay ) {
5035 char *ptr1, *ptr2, *iptr1, *iptr2;
5038 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
5039 if ( *iptr2 != '{' ) {
5040 rs->sr_err = LDAP_NAMING_VIOLATION;
5041 rs->sr_text = "new ordering index is required";
5045 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
5046 ptr1 = ber_bvchr( &rdn, '}' );
5047 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5049 rs->sr_err = LDAP_NAMING_VIOLATION;
5050 rs->sr_text = "new ordering index is required";
5054 len1 = ptr1 - rdn.bv_val;
5055 len2 = ptr2 - op->orr_newrdn.bv_val;
5057 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
5058 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
5059 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5060 rs->sr_text = "changing database/overlay type not allowed";
5063 ixold = strtol( iptr1, NULL, 0 );
5064 ixnew = strtol( iptr2, &ptr1, 0 );
5065 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
5066 rs->sr_err = LDAP_NAMING_VIOLATION;
5069 /* config DB is always 0, cannot be changed */
5070 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
5071 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
5075 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5076 rs->sr_text = "renaming not supported for this entry";
5080 ldap_pvt_thread_pool_pause( &connection_pool );
5082 if ( ce->ce_type == Cft_Schema ) {
5083 req_modrdn_s modr = op->oq_modrdn;
5086 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
5087 if ( rs->sr_err == LDAP_SUCCESS ) {
5088 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
5089 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
5092 op->oq_modrdn = modr;
5094 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
5095 req_modrdn_s modr = op->oq_modrdn;
5098 /* Advance to first of this type */
5099 cprev = &ce->ce_parent->ce_kids;
5100 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
5101 cprev = &ce2->ce_sibs;
5104 /* Skip the -1 entry */
5105 if ( ce->ce_type == Cft_Database ) {
5106 cprev = &ce2->ce_sibs;
5112 /* Remove from old slot */
5113 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
5114 cprev = &ce2->ce_sibs;
5115 *cprev = ce->ce_sibs;
5116 ceold = ce->ce_sibs;
5118 /* Insert into new slot */
5120 for ( i=0; i<ixnew; i++ ) {
5124 cprev = &ce2->ce_sibs;
5126 ce->ce_sibs = *cprev;
5131 /* NOTE: These should be encoded in the OC tables, not inline here */
5132 if ( ce->ce_type == Cft_Database )
5133 backend_db_move( ce->ce_be, ixnew );
5134 else if ( ce->ce_type == Cft_Overlay )
5135 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
5137 if ( ixold < ixnew ) {
5138 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
5141 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
5142 ixold - ixnew, cfb->cb_use_ldif );
5144 op->oq_modrdn = modr;
5147 ldap_pvt_thread_pool_resume( &connection_pool );
5149 send_ldap_result( op, rs );
5154 config_back_delete( Operation *op, SlapReply *rs )
5156 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM, NULL );
5161 config_back_search( Operation *op, SlapReply *rs )
5164 CfEntryInfo *ce, *last;
5167 cfb = (CfBackInfo *)op->o_bd->be_private;
5169 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5172 rs->sr_matched = last->ce_entry->e_name.bv_val;
5173 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5176 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
5177 ACL_SEARCH, NULL, &mask ))
5179 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
5180 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5182 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5186 switch ( op->ors_scope ) {
5187 case LDAP_SCOPE_BASE:
5188 case LDAP_SCOPE_SUBTREE:
5189 config_send( op, rs, ce, 0 );
5192 case LDAP_SCOPE_ONELEVEL:
5193 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
5194 config_send( op, rs, ce, 1 );
5199 rs->sr_err = LDAP_SUCCESS;
5201 send_ldap_result( op, rs );
5205 /* no-op, we never free entries */
5206 int config_entry_release(
5211 if ( !e->e_private ) {
5214 return LDAP_SUCCESS;
5217 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
5219 int config_back_entry_get(
5223 AttributeDescription *at,
5228 CfEntryInfo *ce, *last;
5230 cfb = (CfBackInfo *)op->o_bd->be_private;
5232 ce = config_find_base( cfb->cb_root, ndn, &last );
5234 *ent = ce->ce_entry;
5235 if ( *ent && oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
5240 return ( *ent == NULL ? 1 : 0 );
5244 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
5245 ConfigTable *ct, ConfigArgs *c )
5249 for (; at && *at; at++) {
5250 /* Skip the naming attr */
5251 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
5253 for (i=0;ct[i].name;i++) {
5254 if (ct[i].ad == (*at)->sat_ad) {
5255 rc = config_get_vals(&ct[i], c);
5256 /* NOTE: tolerate that config_get_vals()
5257 * returns success with no values */
5258 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
5259 if ( c->rvalue_nvals )
5260 attr_merge(e, ct[i].ad, c->rvalue_vals,
5263 attr_merge_normalize(e, ct[i].ad,
5264 c->rvalue_vals, NULL);
5265 ber_bvarray_free( c->rvalue_nvals );
5266 ber_bvarray_free( c->rvalue_vals );
5275 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
5276 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
5278 Entry *e = entry_alloc();
5279 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5281 struct berval ad_name;
5282 AttributeDescription *ad = NULL;
5289 CfEntryInfo *ceprev = NULL;
5291 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
5294 ce->ce_type = main->co_type;
5295 ce->ce_parent = parent;
5297 pdn = parent->ce_entry->e_nname;
5298 if ( parent->ce_kids )
5299 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
5300 ceprev->ce_type <= ce->ce_type;
5301 ceprev = ceprev->ce_sibs );
5306 ce->ce_private = c->private;
5310 build_new_dn( &e->e_name, &pdn, rdn, NULL );
5311 ber_dupbv( &e->e_nname, &e->e_name );
5313 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
5314 main->co_name, NULL );
5316 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
5317 extra->co_name, NULL );
5318 ptr = strchr(rdn->bv_val, '=');
5319 ad_name.bv_val = rdn->bv_val;
5320 ad_name.bv_len = ptr - rdn->bv_val;
5321 rc = slap_bv2ad( &ad_name, &ad, &text );
5326 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
5327 attr_merge_normalize_one(e, ad, &val, NULL );
5330 c->table = main->co_type;
5331 if ( oc->soc_required )
5332 config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
5334 if ( oc->soc_allowed )
5335 config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
5339 c->table = extra->co_type;
5340 if ( oc->soc_required )
5341 config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
5343 if ( oc->soc_allowed )
5344 config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
5347 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5348 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
5349 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
5350 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
5351 if ( op && !op->o_noop ) {
5353 op->ora_modlist = NULL;
5354 op->o_bd->be_add( op, rs );
5355 if ( ( rs->sr_err != LDAP_SUCCESS )
5356 && (rs->sr_err != LDAP_ALREADY_EXISTS) ) {
5361 ce->ce_sibs = ceprev->ce_sibs;
5362 ceprev->ce_sibs = ce;
5363 } else if ( parent ) {
5364 ce->ce_sibs = parent->ce_kids;
5365 parent->ce_kids = ce;
5372 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
5373 Operation *op, SlapReply *rs )
5376 ConfigFile *cf = c->private;
5380 for (; cf; cf=cf->c_sibs, c->depth++) {
5381 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
5382 !cf->c_om_head ) continue;
5383 c->value_dn.bv_val = c->log;
5384 LUTIL_SLASHPATH( cf->c_file.bv_val );
5385 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
5390 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
5392 ptr = strchr( bv.bv_val, '.' );
5394 bv.bv_len = ptr - bv.bv_val;
5395 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
5396 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
5397 /* FIXME: how can indicate error? */
5400 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
5402 c->value_dn.bv_len += bv.bv_len;
5403 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
5406 e = config_build_entry( op, rs, ceparent, c, &c->value_dn,
5407 &CFOC_SCHEMA, NULL );
5410 } else if ( e && cf->c_kids ) {
5411 c->private = cf->c_kids;
5412 config_build_schema_inc( c, e->e_private, op, rs );
5418 #ifdef SLAPD_MODULES
5421 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
5422 Operation *op, SlapReply *rs )
5427 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
5428 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
5430 c->value_dn.bv_val = c->log;
5431 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
5432 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
5433 /* FIXME: how can indicate error? */
5437 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
5446 config_check_schema(Operation *op, CfBackInfo *cfb)
5448 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
5450 CfEntryInfo *ce, *last;
5453 /* If there's no root entry, we must be in the midst of converting */
5454 if ( !cfb->cb_root )
5457 /* Make sure the main schema entry exists */
5458 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
5465 /* Make sure it's up to date */
5466 if ( cf_om_tail != om_sys_tail ) {
5467 a = attr_find( e->e_attrs, cfAd_om );
5469 if ( a->a_nvals != a->a_vals )
5470 ber_bvarray_free( a->a_nvals );
5471 ber_bvarray_free( a->a_vals );
5476 oidm_unparse( &bv, NULL, NULL, 1 );
5477 attr_merge_normalize( e, cfAd_om, bv, NULL );
5478 ber_bvarray_free( bv );
5479 cf_om_tail = om_sys_tail;
5481 if ( cf_at_tail != at_sys_tail ) {
5482 a = attr_find( e->e_attrs, cfAd_attr );
5484 if ( a->a_nvals != a->a_vals )
5485 ber_bvarray_free( a->a_nvals );
5486 ber_bvarray_free( a->a_vals );
5491 at_unparse( &bv, NULL, NULL, 1 );
5492 attr_merge_normalize( e, cfAd_attr, bv, NULL );
5493 ber_bvarray_free( bv );
5494 cf_at_tail = at_sys_tail;
5496 if ( cf_oc_tail != oc_sys_tail ) {
5497 a = attr_find( e->e_attrs, cfAd_oc );
5499 if ( a->a_nvals != a->a_vals )
5500 ber_bvarray_free( a->a_nvals );
5501 ber_bvarray_free( a->a_vals );
5506 oc_unparse( &bv, NULL, NULL, 1 );
5507 attr_merge_normalize( e, cfAd_oc, bv, NULL );
5508 ber_bvarray_free( bv );
5509 cf_oc_tail = oc_sys_tail;
5512 SlapReply rs = {REP_RESULT};
5514 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
5515 &CFOC_SCHEMA, NULL );
5520 ce->ce_private = cfb->cb_config;
5521 cf_at_tail = at_sys_tail;
5522 cf_oc_tail = oc_sys_tail;
5523 cf_om_tail = om_sys_tail;
5528 static const char *defacl[] = {
5529 NULL, "to", "*", "by", "*", "none", NULL
5533 config_back_db_open( BackendDB *be, ConfigReply *cr )
5535 CfBackInfo *cfb = be->be_private;
5538 CfEntryInfo *ce, *ceparent;
5542 Connection conn = {0};
5543 OperationBuffer opbuf;
5545 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
5546 SlapReply rs = {REP_RESULT};
5547 void *thrctx = NULL;
5549 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
5551 /* If we have no explicitly configured ACLs, don't just use
5552 * the global ACLs. Explicitly deny access to everything.
5554 if ( frontendDB->be_acl && be->be_acl == frontendDB->be_acl ) {
5555 parse_acl(be, "config_back_db_open", 0, 6, (char **)defacl, 0 );
5558 thrctx = ldap_pvt_thread_pool_context();
5559 connection_fake_init( &conn, &opbuf, thrctx );
5562 op->o_tag = LDAP_REQ_ADD;
5563 op->o_callback = &cb;
5564 op->o_bd = &cfb->cb_db;
5565 op->o_dn = op->o_bd->be_rootdn;
5566 op->o_ndn = op->o_bd->be_rootndn;
5568 if ( !cfb->cb_use_ldif ) {
5572 /* If we read the config from back-ldif, do some quick sanity checks */
5573 if ( cfb->cb_got_ldif ) {
5574 return config_check_schema( op, cfb );
5577 /* create root of tree */
5579 c.private = cfb->cb_config;
5581 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
5591 #ifdef SLAPD_MODULES
5592 /* Create Module nodes... */
5593 if ( modpaths.mp_loads ) {
5594 if ( config_build_modules( &c, ceparent, op, &rs ) ){
5600 /* Create schema nodes... cn=schema will contain the hardcoded core
5601 * schema, read-only. Child objects will contain runtime loaded schema
5606 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
5611 ce->ce_private = cfb->cb_config;
5612 cf_at_tail = at_sys_tail;
5613 cf_oc_tail = oc_sys_tail;
5614 cf_om_tail = om_sys_tail;
5616 /* Create schema nodes for included schema... */
5617 if ( cfb->cb_config->c_kids ) {
5619 c.private = cfb->cb_config->c_kids;
5620 if (config_build_schema_inc( &c, ce, op, &rs )) {
5625 /* Create backend nodes. Skip if they don't provide a cf_table.
5626 * There usually aren't any of these.
5630 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
5631 if (!bi->bi_cf_ocs) {
5632 /* If it only supports the old config mech, complain. */
5633 if ( bi->bi_config ) {
5634 Debug( LDAP_DEBUG_ANY,
5635 "WARNING: No dynamic config support for backend %s.\n",
5636 bi->bi_type, 0, 0 );
5641 if (!bi->bi_private) continue;
5644 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
5645 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
5646 if ( rdn.bv_len >= sizeof( c.log ) ) {
5647 /* FIXME: holler ... */ ;
5650 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
5657 /* Create database nodes... */
5658 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
5659 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
5660 for ( i = -1, be = frontendDB ; be;
5661 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
5662 slap_overinfo *oi = NULL;
5664 if ( overlay_is_over( be )) {
5665 oi = be->bd_info->bi_private;
5671 /* If this backend supports the old config mechanism, but not
5672 * the new mech, complain.
5674 if ( !be->be_cf_ocs && bi->bi_db_config ) {
5675 Debug( LDAP_DEBUG_ANY,
5676 "WARNING: No dynamic config support for database %s.\n",
5677 bi->bi_type, 0, 0 );
5681 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
5682 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
5684 if ( rdn.bv_len >= sizeof( c.log ) ) {
5685 /* FIXME: holler ... */ ;
5689 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
5695 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd )
5696 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
5697 /* Iterate through overlays */
5703 for (j=0,on=oi->oi_list; on; j++,on=on->on_next) {
5704 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
5705 Debug( LDAP_DEBUG_ANY,
5706 "WARNING: No dynamic config support for overlay %s.\n",
5707 on->on_bi.bi_type, 0, 0 );
5711 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
5712 "%s=" SLAP_X_ORDERED_FMT "%s",
5713 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
5714 if ( rdn.bv_len >= sizeof( c.log ) ) {
5715 /* FIXME: holler ... */ ;
5719 oe = config_build_entry( op, &rs, ce, &c, &rdn,
5720 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
5724 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd )
5725 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
5730 ldap_pvt_thread_pool_context_reset( thrctx );
5732 if ( unsupp && cfb->cb_use_ldif ) {
5733 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
5734 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
5741 cfb_free_cffile( ConfigFile *cf )
5745 for (; cf; cf=next) {
5748 cfb_free_cffile( cf->c_kids );
5749 ch_free( cf->c_file.bv_val );
5750 ber_bvarray_free( cf->c_dseFiles );
5756 cfb_free_entries( CfEntryInfo *ce )
5760 for (; ce; ce=next) {
5763 cfb_free_entries( ce->ce_kids );
5764 ce->ce_entry->e_private = NULL;
5765 entry_free( ce->ce_entry );
5771 config_back_db_close( BackendDB *be, ConfigReply *cr )
5773 CfBackInfo *cfb = be->be_private;
5775 cfb_free_entries( cfb->cb_root );
5776 cfb->cb_root = NULL;
5778 if ( cfb->cb_db.bd_info ) {
5779 backend_shutdown( &cfb->cb_db );
5786 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
5788 CfBackInfo *cfb = be->be_private;
5790 cfb_free_cffile( cfb->cb_config );
5792 ch_free( cfdir.bv_val );
5794 avl_free( CfOcTree, NULL );
5796 if ( cfb->cb_db.bd_info ) {
5797 cfb->cb_db.be_suffix = NULL;
5798 cfb->cb_db.be_nsuffix = NULL;
5799 BER_BVZERO( &cfb->cb_db.be_rootdn );
5800 BER_BVZERO( &cfb->cb_db.be_rootndn );
5802 backend_destroy_one( &cfb->cb_db, 0 );
5811 config_back_db_init( BackendDB *be, ConfigReply* cr )
5817 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
5818 cfn = cfb->cb_config;
5819 be->be_private = cfb;
5821 ber_dupbv( &be->be_rootdn, &config_rdn );
5822 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
5823 ber_dupbv( &dn, &be->be_rootdn );
5824 ber_bvarray_add( &be->be_suffix, &dn );
5825 ber_dupbv( &dn, &be->be_rootdn );
5826 ber_bvarray_add( &be->be_nsuffix, &dn );
5828 /* Hide from namingContexts */
5829 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
5835 config_back_destroy( BackendInfo *bi )
5837 ldif_must_b64_encode_release();
5842 config_tool_entry_open( BackendDB *be, int mode )
5844 CfBackInfo *cfb = be->be_private;
5845 BackendInfo *bi = cfb->cb_db.bd_info;
5847 if ( bi && bi->bi_tool_entry_open )
5848 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
5855 config_tool_entry_close( BackendDB *be )
5857 CfBackInfo *cfb = be->be_private;
5858 BackendInfo *bi = cfb->cb_db.bd_info;
5860 if ( bi && bi->bi_tool_entry_close )
5861 return bi->bi_tool_entry_close( &cfb->cb_db );
5867 config_tool_entry_first( BackendDB *be )
5869 CfBackInfo *cfb = be->be_private;
5870 BackendInfo *bi = cfb->cb_db.bd_info;
5872 if ( bi && bi->bi_tool_entry_first )
5873 return bi->bi_tool_entry_first( &cfb->cb_db );
5879 config_tool_entry_next( BackendDB *be )
5881 CfBackInfo *cfb = be->be_private;
5882 BackendInfo *bi = cfb->cb_db.bd_info;
5884 if ( bi && bi->bi_tool_entry_next )
5885 return bi->bi_tool_entry_next( &cfb->cb_db );
5891 config_tool_entry_get( BackendDB *be, ID id )
5893 CfBackInfo *cfb = be->be_private;
5894 BackendInfo *bi = cfb->cb_db.bd_info;
5896 if ( bi && bi->bi_tool_entry_get )
5897 return bi->bi_tool_entry_get( &cfb->cb_db, id );
5902 static int entry_put_got_frontend=0;
5903 static int entry_put_got_config=0;
5905 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
5907 CfBackInfo *cfb = be->be_private;
5908 BackendInfo *bi = cfb->cb_db.bd_info;
5910 struct berval rdn, vals[ 2 ];
5912 OperationBuffer opbuf;
5914 Connection conn = {0};
5915 Operation *op = NULL;
5918 /* Create entry for frontend database if it does not exist already */
5919 if ( !entry_put_got_frontend ) {
5920 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
5921 STRLENOF( "olcDatabase" ))) {
5922 if ( strncmp( e->e_nname.bv_val +
5923 STRLENOF( "olcDatabase" ), "={-1}frontend",
5924 STRLENOF( "={-1}frontend" )) &&
5925 strncmp( e->e_nname.bv_val +
5926 STRLENOF( "olcDatabase" ), "=frontend",
5927 STRLENOF( "=frontend" ))) {
5929 vals[1].bv_val = NULL;
5930 memset( &ca, 0, sizeof(ConfigArgs));
5932 ca.bi = frontendDB->bd_info;
5933 ca.be->be_cf_ocs = &CFOC_FRONTEND;
5934 rdn.bv_val = ca.log;
5935 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
5936 "%s=" SLAP_X_ORDERED_FMT "%s",
5937 cfAd_database->ad_cname.bv_val, -1,
5939 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
5940 &CFOC_DATABASE, ca.be->be_cf_ocs );
5941 thrctx = ldap_pvt_thread_pool_context();
5942 connection_fake_init2( &conn, &opbuf, thrctx,0 );
5944 op->o_bd = &cfb->cb_db;
5945 op->o_tag = LDAP_REQ_ADD;
5947 op->o_dn = be->be_rootdn;
5948 op->o_ndn = be->be_rootndn;
5949 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
5950 if ( rc != LDAP_SUCCESS ) {
5951 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
5952 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
5956 if ( ce && bi && bi->bi_tool_entry_put &&
5957 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
5958 entry_put_got_frontend++;
5960 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
5961 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
5965 entry_put_got_frontend++;
5969 /* Create entry for config database if it does not exist already */
5970 if ( !entry_put_got_config ) {
5971 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
5972 STRLENOF( "olcDatabase" ))) {
5973 if ( strncmp( e->e_nname.bv_val +
5974 STRLENOF( "olcDatabase" ), "={0}config",
5975 STRLENOF( "={0}config" )) &&
5976 strncmp( e->e_nname.bv_val +
5977 STRLENOF( "olcDatabase" ), "=config",
5978 STRLENOF( "=config" )) ) {
5980 vals[1].bv_val = NULL;
5981 memset( &ca, 0, sizeof(ConfigArgs));
5982 ca.be = LDAP_STAILQ_FIRST( &backendDB );
5983 ca.bi = ca.be->bd_info;
5984 rdn.bv_val = ca.log;
5985 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
5986 "%s=" SLAP_X_ORDERED_FMT "%s",
5987 cfAd_database->ad_cname.bv_val, 0,
5989 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
5992 thrctx = ldap_pvt_thread_pool_context();
5993 connection_fake_init2( &conn, &opbuf, thrctx,0 );
5995 op->o_bd = &cfb->cb_db;
5996 op->o_tag = LDAP_REQ_ADD;
5997 op->o_dn = be->be_rootdn;
5998 op->o_ndn = be->be_rootndn;
6001 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
6002 if ( rc != LDAP_SUCCESS ) {
6003 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
6004 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
6007 if (ce && bi && bi->bi_tool_entry_put &&
6008 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
6009 entry_put_got_config++;
6011 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
6012 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
6016 entry_put_got_config++;
6020 if ( bi && bi->bi_tool_entry_put &&
6021 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
6022 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
6029 AttributeDescription **desc;
6031 { "attribute", &cfAd_attr },
6032 { "backend", &cfAd_backend },
6033 { "database", &cfAd_database },
6034 { "include", &cfAd_include },
6035 { "objectclass", &cfAd_oc },
6036 { "objectidentifier", &cfAd_om },
6037 { "overlay", &cfAd_overlay },
6042 * add / delete: all types that may be added or deleted must use an
6043 * X-ORDERED attributeType for their RDN. Adding and deleting entries
6044 * should automatically renumber the index of any siblings as needed,
6045 * so that no gaps in the numbering sequence exist after the add/delete
6047 * What can be added:
6049 * backend objects for backend-specific config directives
6053 * delete: probably no support this time around.
6055 * modrdn: generally not done. Will be invoked automatically by add/
6056 * delete to update numbering sequence. Perform as an explicit operation
6057 * so that the renumbering effect may be replicated. Subtree rename must
6058 * be supported, since renumbering a database will affect all its child
6061 * modify: must be fully supported.
6065 config_back_initialize( BackendInfo *bi )
6067 ConfigTable *ct = config_back_cf_table;
6071 AttributeDescription *ad = NULL;
6073 static char *controls[] = {
6074 LDAP_CONTROL_MANAGEDSAIT,
6078 /* Make sure we don't exceed the bits reserved for userland */
6079 config_check_userland( CFG_LAST );
6081 bi->bi_controls = controls;
6086 bi->bi_destroy = config_back_destroy;
6088 bi->bi_db_init = config_back_db_init;
6089 bi->bi_db_config = 0;
6090 bi->bi_db_open = config_back_db_open;
6091 bi->bi_db_close = config_back_db_close;
6092 bi->bi_db_destroy = config_back_db_destroy;
6094 bi->bi_op_bind = config_back_bind;
6095 bi->bi_op_unbind = 0;
6096 bi->bi_op_search = config_back_search;
6097 bi->bi_op_compare = 0;
6098 bi->bi_op_modify = config_back_modify;
6099 bi->bi_op_modrdn = config_back_modrdn;
6100 bi->bi_op_add = config_back_add;
6101 bi->bi_op_delete = config_back_delete;
6102 bi->bi_op_abandon = 0;
6104 bi->bi_extended = 0;
6106 bi->bi_chk_referrals = 0;
6108 bi->bi_access_allowed = slap_access_allowed;
6110 bi->bi_connection_init = 0;
6111 bi->bi_connection_destroy = 0;
6113 bi->bi_entry_release_rw = config_entry_release;
6114 bi->bi_entry_get_rw = config_back_entry_get;
6116 bi->bi_tool_entry_open = config_tool_entry_open;
6117 bi->bi_tool_entry_close = config_tool_entry_close;
6118 bi->bi_tool_entry_first = config_tool_entry_first;
6119 bi->bi_tool_entry_next = config_tool_entry_next;
6120 bi->bi_tool_entry_get = config_tool_entry_get;
6121 bi->bi_tool_entry_put = config_tool_entry_put;
6124 argv[ 0 ] = "slapd";
6130 for (i=0; OidMacros[i].name; i++ ) {
6131 argv[1] = OidMacros[i].name;
6132 argv[2] = OidMacros[i].oid;
6133 parse_oidm( &ca, 0, NULL );
6136 bi->bi_cf_ocs = cf_ocs;
6138 i = config_register_schema( ct, cf_ocs );
6141 /* setup olcRootPW to be base64-encoded when written in LDIF form;
6142 * basically, we don't care if it fails */
6143 i = slap_str2ad( "olcRootPW", &ad, &text );
6145 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
6146 "warning, unable to get \"olcRootPW\" "
6147 "attribute description: %d: %s\n",
6150 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
6151 ad->ad_type->sat_oid );
6154 /* set up the notable AttributeDescriptions */
6156 for (;ct->name;ct++) {
6157 if (strcmp(ct->name, ads[i].name)) continue;
6158 *ads[i].desc = ct->ad;
6160 if (!ads[i].name) break;