1 /* bconfig.c - the config backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005-2008 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was originally developed by Howard Chu for inclusion
18 * in OpenLDAP Software.
24 #include <ac/string.h>
32 #include "slapi/slapi.h"
40 #define CONFIG_RDN "cn=config"
41 #define SCHEMA_RDN "cn=schema"
43 static struct berval config_rdn = BER_BVC(CONFIG_RDN);
44 static struct berval schema_rdn = BER_BVC(SCHEMA_RDN);
46 extern int slap_DN_strict; /* dn.c */
49 typedef struct modpath_s {
50 struct modpath_s *mp_next;
51 struct berval mp_path;
55 static ModPaths modpaths, *modlast = &modpaths, *modcur = &modpaths;
58 typedef struct ConfigFile {
59 struct ConfigFile *c_sibs;
60 struct ConfigFile *c_kids;
62 AttributeType *c_at_head, *c_at_tail;
63 ContentRule *c_cr_head, *c_cr_tail;
64 ObjectClass *c_oc_head, *c_oc_tail;
65 OidMacro *c_om_head, *c_om_tail;
70 ConfigFile *cb_config;
72 BackendDB cb_db; /* underlying database */
77 static CfBackInfo cfBackInfo;
79 static char *passwd_salt;
81 static char *logfileName;
82 #ifdef SLAP_AUTH_REWRITE
83 static BerVarray authz_rewrites;
86 static struct berval cfdir;
89 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
90 *cfAd_include, *cfAd_attr, *cfAd_oc, *cfAd_om;
92 static ConfigFile *cfn;
94 static Avlnode *CfOcTree;
96 /* System schema state */
97 extern AttributeType *at_sys_tail; /* at.c */
98 extern ObjectClass *oc_sys_tail; /* oc.c */
99 extern OidMacro *om_sys_tail; /* oidm.c */
100 static AttributeType *cf_at_tail;
101 static ObjectClass *cf_oc_tail;
102 static OidMacro *cf_om_tail;
104 static int config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca,
105 SlapReply *rs, int *renumber, Operation *op );
107 static int config_check_schema( Operation *op, CfBackInfo *cfb );
109 static ConfigDriver config_fname;
110 static ConfigDriver config_cfdir;
111 static ConfigDriver config_generic;
112 static ConfigDriver config_search_base;
113 static ConfigDriver config_passwd_hash;
114 static ConfigDriver config_schema_dn;
115 static ConfigDriver config_sizelimit;
116 static ConfigDriver config_timelimit;
117 static ConfigDriver config_overlay;
118 static ConfigDriver config_subordinate;
119 static ConfigDriver config_suffix;
120 static ConfigDriver config_rootdn;
121 static ConfigDriver config_rootpw;
122 static ConfigDriver config_restrict;
123 static ConfigDriver config_allows;
124 static ConfigDriver config_disallows;
125 static ConfigDriver config_requires;
126 static ConfigDriver config_security;
127 static ConfigDriver config_referral;
128 static ConfigDriver config_loglevel;
129 static ConfigDriver config_updatedn;
130 static ConfigDriver config_updateref;
131 static ConfigDriver config_include;
132 static ConfigDriver config_obsolete;
134 static ConfigDriver config_tls_option;
135 static ConfigDriver config_tls_config;
137 extern ConfigDriver syncrepl_config;
191 static OidRec OidMacros[] = {
192 /* OpenLDAProot:666.11.1 */
193 { "OLcfg", "1.3.6.1.4.1.4203.666.11.1" },
194 { "OLcfgAt", "OLcfg:3" },
195 { "OLcfgGlAt", "OLcfgAt:0" },
196 { "OLcfgBkAt", "OLcfgAt:1" },
197 { "OLcfgDbAt", "OLcfgAt:2" },
198 { "OLcfgOvAt", "OLcfgAt:3" },
199 { "OLcfgCtAt", "OLcfgAt:4" }, /* contrib modules */
200 { "OLcfgOc", "OLcfg:4" },
201 { "OLcfgGlOc", "OLcfgOc:0" },
202 { "OLcfgBkOc", "OLcfgOc:1" },
203 { "OLcfgDbOc", "OLcfgOc:2" },
204 { "OLcfgOvOc", "OLcfgOc:3" },
205 { "OLcfgCtOc", "OLcfgOc:4" }, /* contrib modules */
207 /* Syntaxes. We should just start using the standard names and
208 * document that they are predefined and available for users
209 * to reference in their own schema. Defining schema without
210 * OID macros is for masochists...
212 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
213 { "OMsBoolean", "OMsyn:7" },
214 { "OMsDN", "OMsyn:12" },
215 { "OMsDirectoryString", "OMsyn:15" },
216 { "OMsIA5String", "OMsyn:26" },
217 { "OMsInteger", "OMsyn:27" },
218 { "OMsOID", "OMsyn:38" },
219 { "OMsOctetString", "OMsyn:40" },
224 * Backend/Database registry
226 * OLcfg{Bk|Db}{Oc|At}:0 -> common
227 * OLcfg{Bk|Db}{Oc|At}:1 -> back-bdb(/back-hdb)
228 * OLcfg{Bk|Db}{Oc|At}:2 -> back-ldif
229 * OLcfg{Bk|Db}{Oc|At}:3 -> back-ldap
230 * OLcfg{Bk|Db}{Oc|At}:4 -> back-monitor
231 * OLcfg{Bk|Db}{Oc|At}:5 -> back-relay
232 * OLcfg{Bk|Db}{Oc|At}:6 -> back-sql
233 * OLcfg{Bk|Db}{Oc|At}:7 -> back-sock
239 * OLcfgOv{Oc|At}:1 -> syncprov
240 * OLcfgOv{Oc|At}:2 -> pcache
241 * OLcfgOv{Oc|At}:3 -> chain
242 * OLcfgOv{Oc|At}:4 -> accesslog
243 * OLcfgOv{Oc|At}:5 -> valsort
244 * OLcfgOv{Oc|At}:7 -> distproc
245 * OLcfgOv{Oc|At}:8 -> dynlist
246 * OLcfgOv{Oc|At}:9 -> dds
247 * OLcfgOv{Oc|At}:10 -> unique
248 * OLcfgOv{Oc|At}:11 -> refint
249 * OLcfgOv{Oc|At}:12 -> ppolicy
250 * OLcfgOv{Oc|At}:13 -> constraint
251 * OLcfgOv{Oc|At}:14 -> translucent
252 * OLcfgOv{Oc|At}:15 -> auditlog
253 * OLcfgOv{Oc|At}:16 -> rwm
254 * OLcfgOv{Oc|At}:17 -> dyngroup
255 * OLcfgOv{Oc|At}:18 -> memberof
256 * OLcfgOv{Oc|At}:19 -> collect
259 /* alphabetical ordering */
261 static ConfigTable config_back_cf_table[] = {
262 /* This attr is read-only */
263 { "", "", 0, 0, 0, ARG_MAGIC,
264 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
265 "DESC 'File for slapd configuration directives' "
266 "EQUALITY caseIgnoreMatch "
267 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
268 { "", "", 0, 0, 0, ARG_MAGIC,
269 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
270 "DESC 'Directory for slapd configuration backend' "
271 "EQUALITY caseIgnoreMatch "
272 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
273 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
274 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
275 "DESC 'Access Control List' "
276 "EQUALITY caseIgnoreMatch "
277 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
278 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
279 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
280 "DESC 'Allowed set of deprecated features' "
281 "EQUALITY caseIgnoreMatch "
282 "SYNTAX OMsDirectoryString )", NULL, NULL },
283 { "argsfile", "file", 2, 2, 0, ARG_STRING,
284 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
285 "DESC 'File for slapd command line options' "
286 "EQUALITY caseIgnoreMatch "
287 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
288 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
289 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
290 "EQUALITY caseIgnoreMatch "
291 "SYNTAX OMsDirectoryString )", NULL, NULL },
292 { "attribute", "attribute", 2, 0, STRLENOF( "attribute" ),
293 ARG_PAREN|ARG_MAGIC|CFG_ATTR,
294 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
295 "DESC 'OpenLDAP attributeTypes' "
296 "EQUALITY caseIgnoreMatch "
297 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
299 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
300 #ifdef SLAP_AUTH_REWRITE
301 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
305 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
306 "EQUALITY caseIgnoreMatch "
307 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
308 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
309 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
310 "EQUALITY caseIgnoreMatch "
311 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
312 { "authz-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
313 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
314 "EQUALITY caseIgnoreMatch "
315 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
316 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
317 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
318 "DESC 'A type of backend' "
319 "EQUALITY caseIgnoreMatch "
320 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
322 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
323 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
324 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
325 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
326 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
327 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
328 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
329 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
330 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
331 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
332 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
333 "DESC 'The backend type for a database instance' "
334 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
335 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
336 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
337 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
338 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
339 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
340 "EQUALITY caseIgnoreMatch "
341 "SYNTAX OMsDirectoryString )", NULL, NULL },
342 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
343 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
344 "DESC 'OpenLDAP DIT content rules' "
345 "EQUALITY caseIgnoreMatch "
346 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
348 { "gentlehup", "on|off", 2, 2, 0,
350 ARG_ON_OFF, &global_gentlehup,
354 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
355 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
356 { "hidden", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_HIDDEN,
357 &config_generic, "( OLcfgDbAt:0.17 NAME 'olcHidden' "
358 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
359 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
360 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
361 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
362 { "include", "file", 2, 2, 0, ARG_MAGIC,
363 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
364 "SUP labeledURI )", NULL, NULL },
365 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
366 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
367 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
368 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
369 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
370 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
371 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
372 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
373 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
374 { "index_substr_any_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
375 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
376 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
377 { "index_intlen", "len", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_IX_INTLEN,
378 &config_generic, "( OLcfgGlAt:84 NAME 'olcIndexIntLen' "
379 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
380 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
381 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
382 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
383 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
384 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
385 "EQUALITY caseIgnoreMatch "
386 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
387 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
388 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
389 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
390 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
391 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
392 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
393 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
394 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
395 "EQUALITY caseIgnoreMatch "
396 "SYNTAX OMsDirectoryString )", NULL, NULL },
397 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
398 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
399 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
400 { "mirrormode", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_MIRRORMODE,
401 &config_generic, "( OLcfgDbAt:0.16 NAME 'olcMirrorMode' "
402 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
403 { "moduleload", "file", 2, 0, 0,
405 ARG_MAGIC|CFG_MODLOAD|ARG_NO_DELETE, &config_generic,
409 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
410 "EQUALITY caseIgnoreMatch "
411 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
412 { "modulepath", "path", 2, 2, 0,
414 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
418 "( OLcfgGlAt:31 NAME 'olcModulePath' "
419 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
420 { "monitoring", "TRUE|FALSE", 2, 2, 0,
421 ARG_MAGIC|CFG_MONITORING|ARG_DB|ARG_ON_OFF, &config_generic,
422 "( OLcfgDbAt:0.18 NAME 'olcMonitoring' "
423 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
424 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
425 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
426 "DESC 'OpenLDAP object classes' "
427 "EQUALITY caseIgnoreMatch "
428 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
430 { "objectidentifier", "name> <oid", 3, 3, 0, ARG_MAGIC|CFG_OID,
431 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
432 "EQUALITY caseIgnoreMatch "
433 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
434 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
435 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
436 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
437 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
438 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
439 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
440 { "password-hash", "hash", 2, 2, 0, ARG_MAGIC,
441 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
442 "EQUALITY caseIgnoreMatch "
443 "SYNTAX OMsDirectoryString )", NULL, NULL },
444 { "pidfile", "file", 2, 2, 0, ARG_STRING,
445 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
446 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
447 { "plugin", NULL, 0, 0, 0,
449 ARG_MAGIC|CFG_PLUGIN, &config_generic,
453 "( OLcfgGlAt:38 NAME 'olcPlugin' "
454 "EQUALITY caseIgnoreMatch "
455 "SYNTAX OMsDirectoryString )", NULL, NULL },
456 { "pluginlog", "filename", 2, 2, 0,
458 ARG_STRING, &slapi_log_file,
462 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
463 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
464 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
465 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
466 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
467 { "referral", "url", 2, 2, 0, ARG_MAGIC,
468 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
469 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
470 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
471 &config_obsolete, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
472 "EQUALITY caseIgnoreMatch "
473 "SUP labeledURI X-ORDERED 'VALUES' )", NULL, NULL },
474 { "replica-argsfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
475 &config_obsolete, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
476 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
477 { "replica-pidfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
478 &config_obsolete, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
479 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
480 { "replicationInterval", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
481 &config_obsolete, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
482 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
483 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC,
484 &config_obsolete, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
485 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
486 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
487 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
488 "EQUALITY caseIgnoreMatch "
489 "SYNTAX OMsDirectoryString )", NULL, NULL },
490 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
491 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
492 "EQUALITY caseIgnoreMatch "
493 "SYNTAX OMsDirectoryString )", NULL, NULL },
494 { "reverse-lookup", "on|off", 2, 2, 0,
495 #ifdef SLAPD_RLOOKUPS
496 ARG_ON_OFF, &use_reverse_lookup,
500 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
501 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
502 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
503 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
504 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
505 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
506 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
507 "EQUALITY caseIgnoreMatch "
508 "SYNTAX OMsDirectoryString )", NULL, NULL },
509 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
510 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
511 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
512 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
513 &config_generic, NULL, NULL, NULL },
514 { "sasl-host", "host", 2, 2, 0,
515 #ifdef HAVE_CYRUS_SASL
516 ARG_STRING|ARG_UNIQUE, &sasl_host,
520 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
521 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
522 { "sasl-realm", "realm", 2, 2, 0,
523 #ifdef HAVE_CYRUS_SASL
524 ARG_STRING|ARG_UNIQUE, &global_realm,
528 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
529 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
530 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
531 &config_generic, NULL, NULL, NULL },
532 { "sasl-secprops", "properties", 2, 2, 0,
533 #ifdef HAVE_CYRUS_SASL
534 ARG_MAGIC|CFG_SASLSECP, &config_generic,
538 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
539 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
540 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
541 &config_generic, NULL, NULL, NULL },
542 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
543 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
544 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
545 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
546 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
547 "EQUALITY caseIgnoreMatch "
548 "SYNTAX OMsDirectoryString )", NULL, NULL },
549 { "serverID", "number> <[URI]", 2, 3, 0, ARG_MAGIC|CFG_SERVERID,
550 &config_generic, "( OLcfgGlAt:81 NAME 'olcServerID' "
551 "EQUALITY caseIgnoreMatch "
552 "SYNTAX OMsDirectoryString )", NULL, NULL },
553 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
554 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
555 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
556 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
557 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
558 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
559 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
560 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
561 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
562 { "sortvals", "attr", 2, 0, 0, ARG_MAGIC|CFG_SORTVALS,
563 &config_generic, "( OLcfgGlAt:83 NAME 'olcSortVals' "
564 "DESC 'Attributes whose values will always be sorted' "
565 "EQUALITY caseIgnoreMatch "
566 "SYNTAX OMsDirectoryString )", NULL, NULL },
567 { "subordinate", "[advertise]", 1, 2, 0, ARG_DB|ARG_MAGIC,
568 &config_subordinate, "( OLcfgDbAt:0.15 NAME 'olcSubordinate' "
569 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
570 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
571 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
572 "EQUALITY distinguishedNameMatch "
573 "SYNTAX OMsDN )", NULL, NULL },
574 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
575 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
576 "EQUALITY caseIgnoreMatch "
577 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
578 { "threads", "count", 2, 2, 0,
582 ARG_INT|ARG_MAGIC|CFG_THREADS, &config_generic,
584 "( OLcfgGlAt:66 NAME 'olcThreads' "
585 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
586 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
587 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
588 "SYNTAX OMsDirectoryString )", NULL, NULL },
589 { "TLSCACertificateFile", NULL, 0, 0, 0,
591 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
595 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
596 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
597 { "TLSCACertificatePath", NULL, 0, 0, 0,
599 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
603 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
604 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
605 { "TLSCertificateFile", NULL, 0, 0, 0,
607 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
611 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
612 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
613 { "TLSCertificateKeyFile", NULL, 0, 0, 0,
615 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
619 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
620 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
621 { "TLSCipherSuite", NULL, 0, 0, 0,
623 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
627 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
628 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
629 { "TLSCRLCheck", NULL, 0, 0, 0,
630 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
631 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
635 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
636 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
637 { "TLSCRLFile", NULL, 0, 0, 0,
638 #if defined(HAVE_GNUTLS)
639 CFG_TLS_CRL_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
643 "( OLcfgGlAt:82 NAME 'olcTLSCRLFile' "
644 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
645 { "TLSRandFile", NULL, 0, 0, 0,
647 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
651 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
652 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
653 { "TLSVerifyClient", NULL, 0, 0, 0,
655 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
659 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
660 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
661 { "TLSDHParamFile", NULL, 0, 0, 0,
663 CFG_TLS_DH_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
667 "( OLcfgGlAt:77 NAME 'olcTLSDHParamFile' "
668 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
669 { "tool-threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_TTHREADS,
670 &config_generic, "( OLcfgGlAt:80 NAME 'olcToolThreads' "
671 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
672 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
673 NULL, NULL, NULL, NULL },
674 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
675 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
676 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
677 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
678 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
679 "EQUALITY caseIgnoreMatch "
680 "SUP labeledURI )", NULL, NULL },
681 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
682 NULL, NULL, NULL, NULL }
685 /* Routines to check if a child can be added to this type */
686 static ConfigLDAPadd cfAddSchema, cfAddInclude, cfAddDatabase,
687 cfAddBackend, cfAddModule, cfAddOverlay;
689 /* NOTE: be careful when defining array members
690 * that can be conditionally compiled */
691 #define CFOC_GLOBAL cf_ocs[1]
692 #define CFOC_SCHEMA cf_ocs[2]
693 #define CFOC_BACKEND cf_ocs[3]
694 #define CFOC_DATABASE cf_ocs[4]
695 #define CFOC_OVERLAY cf_ocs[5]
696 #define CFOC_INCLUDE cf_ocs[6]
697 #define CFOC_FRONTEND cf_ocs[7]
699 #define CFOC_MODULE cf_ocs[8]
700 #endif /* SLAPD_MODULES */
702 static ConfigOCs cf_ocs[] = {
705 "DESC 'OpenLDAP configuration object' "
706 "ABSTRACT SUP top )", Cft_Abstract, NULL },
709 "DESC 'OpenLDAP Global configuration options' "
710 "SUP olcConfig STRUCTURAL "
711 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
712 "olcAttributeOptions $ olcAuthIDRewrite $ "
713 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
714 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
715 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
716 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
717 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcIndexIntLen $ "
718 "olcLocalSSF $ olcLogLevel $ "
719 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
720 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
721 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
723 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
724 "olcSecurity $ olcServerID $ olcSizeLimit $ "
725 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ "
726 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
727 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
728 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
729 "olcTLSRandFile $ olcTLSVerifyClient $ olcTLSDHParamFile $ "
730 "olcTLSCRLFile $ olcToolThreads $ "
731 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
732 "olcDitContentRules ) )", Cft_Global },
734 "NAME 'olcSchemaConfig' "
735 "DESC 'OpenLDAP schema object' "
736 "SUP olcConfig STRUCTURAL "
737 "MAY ( cn $ olcObjectIdentifier $ olcAttributeTypes $ "
738 "olcObjectClasses $ olcDitContentRules ) )",
739 Cft_Schema, NULL, cfAddSchema },
741 "NAME 'olcBackendConfig' "
742 "DESC 'OpenLDAP Backend-specific options' "
743 "SUP olcConfig STRUCTURAL "
744 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
746 "NAME 'olcDatabaseConfig' "
747 "DESC 'OpenLDAP Database-specific options' "
748 "SUP olcConfig STRUCTURAL "
750 "MAY ( olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
751 "olcLastMod $ olcLimits $ "
752 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
753 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
754 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
755 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncrepl $ "
756 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef $ olcMirrorMode $ "
758 Cft_Database, NULL, cfAddDatabase },
760 "NAME 'olcOverlayConfig' "
761 "DESC 'OpenLDAP Overlay-specific options' "
762 "SUP olcConfig STRUCTURAL "
763 "MUST olcOverlay )", Cft_Overlay, NULL, cfAddOverlay },
765 "NAME 'olcIncludeFile' "
766 "DESC 'OpenLDAP configuration include file' "
767 "SUP olcConfig STRUCTURAL "
769 "MAY ( cn $ olcRootDSE ) )",
770 /* Used to be Cft_Include, that def has been removed */
771 Cft_Abstract, NULL, cfAddInclude },
772 /* This should be STRUCTURAL like all the other database classes, but
773 * that would mean inheriting all of the olcDatabaseConfig attributes,
774 * which causes them to be merged twice in config_build_entry.
777 "NAME 'olcFrontendConfig' "
778 "DESC 'OpenLDAP frontend configuration' "
780 "MAY ( olcDefaultSearchBase $ olcPasswordHash $ olcSortVals ) )",
781 Cft_Database, NULL, NULL },
784 "NAME 'olcModuleList' "
785 "DESC 'OpenLDAP dynamic module info' "
786 "SUP olcConfig STRUCTURAL "
787 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
788 Cft_Module, NULL, cfAddModule },
793 typedef struct ServerID {
794 struct ServerID *si_next;
795 struct berval si_url;
799 static ServerID *sid_list;
801 typedef struct voidList {
802 struct voidList *vl_next;
806 typedef struct ADlist {
807 struct ADlist *al_next;
808 AttributeDescription *al_desc;
811 static ADlist *sortVals;
814 config_generic(ConfigArgs *c) {
817 if ( c->op == SLAP_CONFIG_EMIT ) {
821 c->value_int = ldap_pvt_thread_get_concurrency();
824 c->value_int = connection_pool_max;
827 c->value_int = slap_tool_thread_max;
831 c->value_string = ch_strdup( passwd_salt );
836 if ( c->be->be_limits ) {
840 for ( i=0; c->be->be_limits[i]; i++ ) {
841 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
842 if ( bv.bv_len >= sizeof( buf ) ) {
843 ber_bvarray_free_x( c->rvalue_vals, NULL );
844 c->rvalue_vals = NULL;
848 bv.bv_val = buf + bv.bv_len;
849 limits_unparse( c->be->be_limits[i], &bv,
850 sizeof( buf ) - ( bv.bv_val - buf ) );
851 bv.bv_len += bv.bv_val - buf;
853 value_add_one( &c->rvalue_vals, &bv );
856 if ( !c->rvalue_vals ) rc = 1;
859 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_OP_WRITES) ==
860 SLAP_RESTRICT_OP_WRITES;
863 c->value_string = ch_strdup( slap_sasl_getpolicy());
866 slap_sasl_regexp_unparse( &c->rvalue_vals );
867 if ( !c->rvalue_vals ) rc = 1;
869 #ifdef HAVE_CYRUS_SASL
871 struct berval bv = BER_BVNULL;
872 slap_sasl_secprops_unparse( &bv );
873 if ( !BER_BVISNULL( &bv )) {
874 ber_bvarray_add( &c->rvalue_vals, &bv );
882 c->value_int = c->be->be_max_deref_depth;
885 if ( SLAP_DBHIDDEN( c->be )) {
892 ConfigFile *cf = c->ca_private;
894 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
895 else if ( cf->c_om_head )
896 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
898 if ( !c->rvalue_vals )
903 ad_unparse_options( &c->rvalue_vals );
906 ConfigFile *cf = c->ca_private;
908 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
909 else if ( cf->c_oc_head )
910 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
912 if ( !c->rvalue_vals )
917 ConfigFile *cf = c->ca_private;
919 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
920 else if ( cf->c_at_head )
921 at_unparse( &c->rvalue_vals, cf->c_at_head,
923 if ( !c->rvalue_vals )
928 ConfigFile *cf = c->ca_private;
930 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
931 else if ( cf->c_cr_head )
932 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
934 if ( !c->rvalue_vals )
941 char *src, *dst, ibuf[11];
942 struct berval bv, abv;
944 if ( c->be == frontendDB )
947 end = frontendDB->be_acl;
948 for (i=0, a=c->be->be_acl; a && a != end; i++,a=a->acl_next) {
949 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
950 if ( abv.bv_len >= sizeof( ibuf ) ) {
951 ber_bvarray_free_x( c->rvalue_vals, NULL );
952 c->rvalue_vals = NULL;
956 acl_unparse( a, &bv );
957 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
958 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
959 /* Turn TAB / EOL into plain space */
960 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
961 if (isspace((unsigned char)*src)) *dst++ = ' ';
965 if (dst[-1] == ' ') {
969 abv.bv_len = dst - abv.bv_val;
970 ber_bvarray_add( &c->rvalue_vals, &abv );
976 ConfigFile *cf = c->ca_private;
977 if ( cf->c_dseFiles ) {
978 value_add( &c->rvalue_vals, cf->c_dseFiles );
989 for ( si = sid_list; si; si=si->si_next ) {
990 assert( si->si_num >= 0 && si->si_num <= SLAP_SYNC_SID_MAX );
991 if ( !BER_BVISEMPTY( &si->si_url )) {
992 bv.bv_len = si->si_url.bv_len + 6;
993 bv.bv_val = ch_malloc( bv.bv_len );
994 sprintf( bv.bv_val, "%d %s", si->si_num,
996 ber_bvarray_add( &c->rvalue_vals, &bv );
1000 bv.bv_len = sprintf( buf, "%d", si->si_num );
1001 value_add_one( &c->rvalue_vals, &bv );
1010 c->value_string = ch_strdup( logfileName );
1015 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1017 case CFG_MIRRORMODE:
1018 if ( SLAP_SHADOW(c->be))
1019 c->value_int = (SLAP_SINGLE_SHADOW(c->be) == 0);
1023 case CFG_MONITORING:
1024 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
1026 case CFG_SSTR_IF_MAX:
1027 c->value_int = index_substr_if_maxlen;
1029 case CFG_SSTR_IF_MIN:
1030 c->value_int = index_substr_if_minlen;
1033 c->value_int = index_intlen;
1035 case CFG_SORTVALS: {
1038 for ( sv = sortVals; sv; sv = sv->al_next ) {
1039 value_add_one( &c->rvalue_vals, &sv->al_desc->ad_cname );
1043 #ifdef SLAPD_MODULES
1045 ModPaths *mp = c->ca_private;
1048 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
1051 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
1052 SLAP_X_ORDERED_FMT "%s", i,
1053 mp->mp_loads[i].bv_val );
1054 if ( bv.bv_len >= sizeof( c->log ) ) {
1055 ber_bvarray_free_x( c->rvalue_vals, NULL );
1056 c->rvalue_vals = NULL;
1059 value_add_one( &c->rvalue_vals, &bv );
1063 rc = c->rvalue_vals ? 0 : 1;
1067 ModPaths *mp = c->ca_private;
1068 if ( !BER_BVISNULL( &mp->mp_path ))
1069 value_add_one( &c->rvalue_vals, &mp->mp_path );
1071 rc = c->rvalue_vals ? 0 : 1;
1077 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1078 if ( !c->rvalue_vals ) rc = 1;
1081 #ifdef SLAP_AUTH_REWRITE
1083 if ( authz_rewrites ) {
1084 struct berval bv, idx;
1089 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1090 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1091 if ( idx.bv_len >= sizeof( ibuf ) ) {
1092 ber_bvarray_free_x( c->rvalue_vals, NULL );
1093 c->rvalue_vals = NULL;
1096 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1097 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1098 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1099 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1100 authz_rewrites[i].bv_val,
1101 authz_rewrites[i].bv_len + 1 );
1102 ber_bvarray_add( &c->rvalue_vals, &bv );
1105 if ( !c->rvalue_vals ) rc = 1;
1112 } else if ( c->op == LDAP_MOD_DELETE ) {
1115 /* single-valued attrs, no-ops */
1123 case CFG_MIRRORMODE:
1124 case CFG_MONITORING:
1126 case CFG_SSTR_IF_MAX:
1127 case CFG_SSTR_IF_MIN:
1130 /* no-ops, requires slapd restart */
1135 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1139 ch_free( passwd_salt );
1144 ch_free( logfileName );
1152 case CFG_SERVERID: {
1153 ServerID *si, **sip;
1155 for ( i=0, si = sid_list, sip = &sid_list;
1156 si; si = *sip, i++ ) {
1157 if ( c->valx == -1 || i == c->valx ) {
1169 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1173 index_intlen = SLAP_INDEX_INTLEN_DEFAULT;
1174 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1175 SLAP_INDEX_INTLEN_DEFAULT );
1179 if ( c->valx < 0 ) {
1181 if ( c->be == frontendDB )
1184 end = frontendDB->be_acl;
1185 acl_destroy( c->be->be_acl, end );
1186 c->be->be_acl = end;
1189 AccessControl **prev, *a;
1191 for (i=0, prev = &c->be->be_acl; i < c->valx;
1194 prev = &a->acl_next;
1197 *prev = a->acl_next;
1204 /* Can be NULL when undoing a failed add */
1205 if ( c->ca_entry ) {
1206 ce = c->ca_entry->e_private;
1207 /* can't modify the hardcoded schema */
1208 if ( ce->ce_parent->ce_type == Cft_Global )
1212 cfn = c->ca_private;
1213 if ( c->valx < 0 ) {
1216 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1218 if ( oc == cfn->c_oc_tail )
1221 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1223 ObjectClass *oc, *prev = NULL;
1225 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1230 if ( cfn->c_oc_tail == oc ) {
1231 cfn->c_oc_tail = prev;
1233 if ( cfn->c_oc_head == oc ) {
1235 cfn->c_oc_head = oc;
1242 /* Can be NULL when undoing a failed add */
1243 if ( c->ca_entry ) {
1244 ce = c->ca_entry->e_private;
1245 /* can't modify the hardcoded schema */
1246 if ( ce->ce_parent->ce_type == Cft_Global )
1250 cfn = c->ca_private;
1251 if ( c->valx < 0 ) {
1254 for( at = cfn->c_at_head; at; at_next( &at )) {
1256 if ( at == cfn->c_at_tail )
1259 cfn->c_at_head = cfn->c_at_tail = NULL;
1261 AttributeType *at, *prev = NULL;
1263 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1268 if ( cfn->c_at_tail == at ) {
1269 cfn->c_at_tail = prev;
1271 if ( cfn->c_at_head == at ) {
1273 cfn->c_at_head = at;
1278 if ( c->valx < 0 ) {
1280 for ( sv = sortVals; sv; sv = sortVals ) {
1281 sortVals = sv->al_next;
1282 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1289 for ( prev = &sortVals, sv = sortVals; i < c->valx; i++ ) {
1290 prev = &sv->al_next;
1293 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1294 *prev = sv->al_next;
1300 /* FIXME: there is no limits_free function */
1302 /* FIXME: there is no ad_option_free function */
1304 /* FIXME: there is no way to remove attributes added by
1318 if(!(c->bi = backend_info(c->argv[1]))) {
1319 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1320 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1321 c->log, c->cr_msg, c->argv[1] );
1328 /* NOTE: config is always the first backend!
1330 if ( !strcasecmp( c->argv[1], "config" )) {
1331 c->be = LDAP_STAILQ_FIRST(&backendDB);
1332 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1335 c->be = backend_db_init(c->argv[1], NULL, c->valx, &c->reply);
1337 if ( c->cr_msg[0] == 0 )
1338 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1339 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n", c->log, c->cr_msg, c->argv[1] );
1346 ldap_pvt_thread_set_concurrency(c->value_int);
1350 if ( c->value_int < 2 ) {
1351 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1352 "threads=%d smaller than minimum value 2",
1354 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1355 c->log, c->cr_msg, 0 );
1358 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1359 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1360 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1361 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1362 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1363 c->log, c->cr_msg, 0 );
1365 if ( slapMode & SLAP_SERVER_MODE )
1366 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1367 connection_pool_max = c->value_int; /* save for reference */
1371 if ( slapMode & SLAP_TOOL_MODE )
1372 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1373 slap_tool_thread_max = c->value_int; /* save for reference */
1377 if ( passwd_salt ) ch_free( passwd_salt );
1378 passwd_salt = c->value_string;
1379 lutil_salt_format(passwd_salt);
1383 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1389 c->be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1391 c->be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1395 ch_free(c->value_string);
1396 if (slap_sasl_setpolicy( c->argv[1] )) {
1397 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
1398 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1399 c->log, c->cr_msg, c->argv[1] );
1405 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1409 #ifdef HAVE_CYRUS_SASL
1412 char *txt = slap_sasl_secprops( c->argv[1] );
1414 snprintf( c->cr_msg, sizeof(c->cr_msg), "<%s> %s",
1416 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0 );
1424 c->be->be_max_deref_depth = c->value_int;
1430 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1431 cfn = c->ca_private;
1432 if(parse_oidm(c, 1, &om))
1434 if (!cfn->c_om_head) cfn->c_om_head = om;
1435 cfn->c_om_tail = om;
1440 ObjectClass *oc, *prev;
1442 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1443 cfn = c->ca_private;
1444 if ( c->valx < 0 ) {
1445 prev = cfn->c_oc_tail;
1448 /* If adding anything after the first, prev is easy */
1451 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
1456 /* If adding the first, and head exists, find its prev */
1457 if (cfn->c_oc_head) {
1458 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
1463 /* else prev is NULL, append to end of global list */
1465 if(parse_oc(c, &oc, prev)) return(1);
1466 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1467 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
1472 AttributeType *at, *prev;
1474 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1475 cfn = c->ca_private;
1476 if ( c->valx < 0 ) {
1477 prev = cfn->c_at_tail;
1480 /* If adding anything after the first, prev is easy */
1483 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
1488 /* If adding the first, and head exists, find its prev */
1489 if (cfn->c_at_head) {
1490 for ( at_start( &at ); at != cfn->c_at_head; ) {
1495 /* else prev is NULL, append to end of global list */
1497 if(parse_at(c, &at, prev)) return(1);
1498 if (!cfn->c_at_head) cfn->c_at_head = at;
1499 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
1506 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1507 cfn = c->ca_private;
1508 if(parse_cr(c, &cr)) return(1);
1509 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1510 cfn->c_cr_tail = cr;
1515 ad_define_option(NULL, NULL, 0);
1516 for(i = 1; i < c->argc; i++)
1517 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1522 if ( c->value_int < SLAP_INDEX_INTLEN_DEFAULT )
1523 c->value_int = SLAP_INDEX_INTLEN_DEFAULT;
1524 else if ( c->value_int > 255 )
1526 index_intlen = c->value_int;
1527 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1531 case CFG_SORTVALS: {
1532 ADlist *svnew = NULL, *svtail, *sv;
1534 for ( i = 1; i < c->argc; i++ ) {
1535 AttributeDescription *ad = NULL;
1539 rc = slap_str2ad( c->argv[i], &ad, &text );
1541 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown attribute type #%d",
1544 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1545 c->log, c->cr_msg, c->argv[i] );
1546 for ( sv = svnew; sv; sv = svnew ) {
1547 svnew = sv->al_next;
1552 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) ||
1553 ad->ad_type->sat_single_value ) {
1554 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> inappropriate attribute type #%d",
1556 goto sortval_reject;
1558 sv = ch_malloc( sizeof( ADlist ));
1563 svtail->al_next = sv;
1568 for ( sv = svnew; sv; sv = sv->al_next )
1569 sv->al_desc->ad_type->sat_flags |= SLAP_AT_SORTED_VAL;
1570 for ( sv = sortVals; sv && sv->al_next; sv = sv->al_next );
1572 sv->al_next = svnew;
1579 /* Don't append to the global ACL if we're on a specific DB */
1581 if ( c->be != frontendDB && frontendDB->be_acl && c->valx == -1 ) {
1584 for ( a=c->be->be_acl; a && a != frontendDB->be_acl;
1588 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
1594 if(root_dse_read_file(c->argv[1])) {
1595 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> could not read file", c->argv[0] );
1596 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1597 c->log, c->cr_msg, c->argv[1] );
1602 ber_str2bv( c->argv[1], 0, 1, &bv );
1603 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1604 cfn = c->ca_private;
1605 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1611 ServerID *si, **sip;
1614 if ( lutil_atoi( &num, c->argv[1] ) ||
1615 num < 0 || num > SLAP_SYNC_SID_MAX )
1617 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1618 "<%s> illegal server ID", c->argv[0] );
1619 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1620 c->log, c->cr_msg, c->argv[1] );
1623 /* only one value allowed if no URL is given */
1624 if ( c->argc > 2 ) {
1627 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
1628 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1629 "<%s> only one server ID allowed now", c->argv[0] );
1630 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1631 c->log, c->cr_msg, c->argv[1] );
1635 if ( ldap_url_parse( c->argv[2], &lud )) {
1636 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1637 "<%s> invalid URL", c->argv[0] );
1638 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1639 c->log, c->cr_msg, c->argv[2] );
1642 len = strlen( c->argv[2] );
1643 si = ch_malloc( sizeof(ServerID) + len + 1 );
1644 si->si_url.bv_val = (char *)(si+1);
1645 si->si_url.bv_len = len;
1646 strcpy( si->si_url.bv_val, c->argv[2] );
1649 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1650 "<%s> unqualified server ID not allowed now", c->argv[0] );
1651 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1652 c->log, c->cr_msg, c->argv[1] );
1655 si = ch_malloc( sizeof(ServerID) );
1656 BER_BVZERO( &si->si_url );
1657 slap_serverID = num;
1658 Debug( LDAP_DEBUG_CONFIG,
1660 c->log, slap_serverID, 0 );
1664 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
1667 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
1668 /* If hostname is empty, or is localhost, or matches
1669 * our hostname, this serverID refers to this host.
1670 * Compare it against listeners and ports.
1672 if ( !lud->lud_host || !lud->lud_host[0] ||
1673 !strncasecmp("localhost", lud->lud_host,
1674 STRLENOF("localhost")) ||
1675 !strcasecmp( global_host, lud->lud_host )) {
1676 Listener **l = slapd_get_listeners();
1679 for ( i=0; l[i]; i++ ) {
1682 ldap_url_parse( l[i]->sl_url.bv_val, &lu2 );
1684 if ( strcasecmp( lud->lud_scheme,
1687 if ( lud->lud_port != lu2->lud_port )
1689 /* Listener on ANY address */
1690 if ( !lu2->lud_host || !lu2->lud_host[0] ) {
1694 /* URL on ANY address */
1695 if ( !lud->lud_host || !lud->lud_host[0] ) {
1699 /* Listener has specific host, must
1702 if ( !strcasecmp( lud->lud_host,
1708 ldap_free_urldesc( lu2 );
1710 slap_serverID = si->si_num;
1711 Debug( LDAP_DEBUG_CONFIG,
1712 "%s: SID=%d (listener=%s)\n",
1713 c->log, slap_serverID,
1714 l[i]->sl_url.bv_val );
1721 ldap_free_urldesc( lud );
1725 if ( logfileName ) ch_free( logfileName );
1726 logfileName = c->value_string;
1727 logfile = fopen(logfileName, "w");
1728 if(logfile) lutil_debug_file(logfile);
1732 if(SLAP_NOLASTMODCMD(c->be)) {
1733 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> not available for %s database",
1734 c->argv[0], c->be->bd_info->bi_type );
1735 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1736 c->log, c->cr_msg, 0 );
1740 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1742 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1745 case CFG_MIRRORMODE:
1746 if(!SLAP_SHADOW(c->be)) {
1747 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database is not a shadow",
1749 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1750 c->log, c->cr_msg, 0 );
1754 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
1756 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1759 case CFG_MONITORING:
1761 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
1763 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
1768 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
1770 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
1773 case CFG_SSTR_IF_MAX:
1774 if (c->value_int < index_substr_if_minlen) {
1775 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1776 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1777 c->log, c->cr_msg, c->value_int );
1780 index_substr_if_maxlen = c->value_int;
1783 case CFG_SSTR_IF_MIN:
1784 if (c->value_int > index_substr_if_maxlen) {
1785 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1786 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1787 c->log, c->cr_msg, c->value_int );
1790 index_substr_if_minlen = c->value_int;
1793 #ifdef SLAPD_MODULES
1795 /* If we're just adding a module on an existing modpath,
1796 * make sure we've selected the current path.
1798 if ( c->op == LDAP_MOD_ADD && c->ca_private && modcur != c->ca_private ) {
1799 modcur = c->ca_private;
1800 /* This should never fail */
1801 if ( module_path( modcur->mp_path.bv_val )) {
1802 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> module path no longer valid",
1804 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1805 c->log, c->cr_msg, modcur->mp_path.bv_val );
1809 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1811 /* Record this load on the current path */
1815 if ( c->op == SLAP_CONFIG_ADD ) {
1816 ptr = c->line + STRLENOF("moduleload");
1817 while (!isspace((unsigned char) *ptr)) ptr++;
1818 while (isspace((unsigned char) *ptr)) ptr++;
1822 ber_str2bv(ptr, 0, 1, &bv);
1823 ber_bvarray_add( &modcur->mp_loads, &bv );
1825 /* Check for any new hardcoded schema */
1826 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
1827 config_check_schema( NULL, &cfBackInfo );
1832 if(module_path(c->argv[1])) return(1);
1833 /* Record which path was used with each module */
1837 if (!modpaths.mp_loads) {
1840 mp = ch_malloc( sizeof( ModPaths ));
1841 modlast->mp_next = mp;
1843 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1845 mp->mp_loads = NULL;
1856 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
1858 slapi_plugins_used++;
1862 #ifdef SLAP_AUTH_REWRITE
1867 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
1870 if ( c->argc > 1 ) {
1873 /* quote all args but the first */
1874 line = ldap_charray2str( c->argv, "\" \"" );
1875 ber_str2bv( line, 0, 0, &bv );
1876 s = ber_bvchr( &bv, '"' );
1877 assert( s != NULL );
1878 /* move the trailing quote of argv[0] to the end */
1879 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
1880 bv.bv_val[ bv.bv_len - 1 ] = '"';
1883 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
1886 ber_bvarray_add( &authz_rewrites, &bv );
1893 Debug( LDAP_DEBUG_ANY,
1894 "%s: unknown CFG_TYPE %d.\n",
1895 c->log, c->type, 0 );
1904 config_fname(ConfigArgs *c) {
1905 if(c->op == SLAP_CONFIG_EMIT) {
1906 if (c->ca_private) {
1907 ConfigFile *cf = c->ca_private;
1908 value_add_one( &c->rvalue_vals, &cf->c_file );
1917 config_cfdir(ConfigArgs *c) {
1918 if(c->op == SLAP_CONFIG_EMIT) {
1919 if ( !BER_BVISEMPTY( &cfdir )) {
1920 value_add_one( &c->rvalue_vals, &cfdir );
1929 config_search_base(ConfigArgs *c) {
1930 if(c->op == SLAP_CONFIG_EMIT) {
1932 if (!BER_BVISEMPTY(&default_search_base)) {
1933 value_add_one(&c->rvalue_vals, &default_search_base);
1934 value_add_one(&c->rvalue_nvals, &default_search_nbase);
1938 } else if( c->op == LDAP_MOD_DELETE ) {
1939 ch_free( default_search_base.bv_val );
1940 ch_free( default_search_nbase.bv_val );
1941 BER_BVZERO( &default_search_base );
1942 BER_BVZERO( &default_search_nbase );
1946 if(c->bi || c->be != frontendDB) {
1947 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
1948 "prior to any backend or database definition\n",
1953 if(default_search_nbase.bv_len) {
1954 free(default_search_base.bv_val);
1955 free(default_search_nbase.bv_val);
1958 default_search_base = c->value_dn;
1959 default_search_nbase = c->value_ndn;
1963 /* For RE23 compatibility we allow this in the global entry
1964 * but we now defer it to the frontend entry to allow modules
1965 * to load new hash types.
1968 config_passwd_hash(ConfigArgs *c) {
1970 if (c->op == SLAP_CONFIG_EMIT) {
1972 /* Don't generate it in the global entry */
1973 if ( c->table == Cft_Global )
1975 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
1976 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
1977 value_add_one(&c->rvalue_vals, &bv);
1980 } else if ( c->op == LDAP_MOD_DELETE ) {
1981 /* Deleting from global is a no-op, only the frontendDB entry matters */
1982 if ( c->table == Cft_Global )
1984 if ( c->valx < 0 ) {
1985 ldap_charray_free( default_passwd_hash );
1986 default_passwd_hash = NULL;
1989 ch_free( default_passwd_hash[i] );
1990 for (; default_passwd_hash[i]; i++ )
1991 default_passwd_hash[i] = default_passwd_hash[i+1];
1995 for(i = 1; i < c->argc; i++) {
1996 if(!lutil_passwd_scheme(c->argv[i])) {
1997 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> scheme not available", c->argv[0] );
1998 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1999 c->log, c->cr_msg, c->argv[i]);
2001 ldap_charray_add(&default_passwd_hash, c->argv[i]);
2004 if(!default_passwd_hash) {
2005 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> no valid hashes found", c->argv[0] );
2006 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2007 c->log, c->cr_msg, 0 );
2014 config_schema_dn(ConfigArgs *c) {
2015 if ( c->op == SLAP_CONFIG_EMIT ) {
2017 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
2018 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
2019 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
2023 } else if ( c->op == LDAP_MOD_DELETE ) {
2024 ch_free( c->be->be_schemadn.bv_val );
2025 ch_free( c->be->be_schemandn.bv_val );
2026 BER_BVZERO( &c->be->be_schemadn );
2027 BER_BVZERO( &c->be->be_schemandn );
2030 ch_free( c->be->be_schemadn.bv_val );
2031 ch_free( c->be->be_schemandn.bv_val );
2032 c->be->be_schemadn = c->value_dn;
2033 c->be->be_schemandn = c->value_ndn;
2038 config_sizelimit(ConfigArgs *c) {
2040 struct slap_limits_set *lim = &c->be->be_def_limit;
2041 if (c->op == SLAP_CONFIG_EMIT) {
2046 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
2047 if ( !BER_BVISEMPTY( &bv ))
2048 value_add_one( &c->rvalue_vals, &bv );
2052 } else if ( c->op == LDAP_MOD_DELETE ) {
2053 /* Reset to defaults */
2054 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
2055 lim->lms_s_hard = 0;
2056 lim->lms_s_unchecked = -1;
2058 lim->lms_s_pr_hide = 0;
2059 lim->lms_s_pr_total = 0;
2062 for(i = 1; i < c->argc; i++) {
2063 if(!strncasecmp(c->argv[i], "size", 4)) {
2064 rc = limits_parse_one(c->argv[i], lim);
2066 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2067 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2068 c->log, c->cr_msg, c->argv[i]);
2072 if(!strcasecmp(c->argv[i], "unlimited")) {
2073 lim->lms_s_soft = -1;
2075 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
2076 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2077 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2078 c->log, c->cr_msg, c->argv[i]);
2082 lim->lms_s_hard = 0;
2089 config_timelimit(ConfigArgs *c) {
2091 struct slap_limits_set *lim = &c->be->be_def_limit;
2092 if (c->op == SLAP_CONFIG_EMIT) {
2097 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
2098 if ( !BER_BVISEMPTY( &bv ))
2099 value_add_one( &c->rvalue_vals, &bv );
2103 } else if ( c->op == LDAP_MOD_DELETE ) {
2104 /* Reset to defaults */
2105 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
2106 lim->lms_t_hard = 0;
2109 for(i = 1; i < c->argc; i++) {
2110 if(!strncasecmp(c->argv[i], "time", 4)) {
2111 rc = limits_parse_one(c->argv[i], lim);
2113 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2114 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2115 c->log, c->cr_msg, c->argv[i]);
2119 if(!strcasecmp(c->argv[i], "unlimited")) {
2120 lim->lms_t_soft = -1;
2122 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
2123 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2124 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2125 c->log, c->cr_msg, c->argv[i]);
2129 lim->lms_t_hard = 0;
2136 config_overlay(ConfigArgs *c) {
2137 if (c->op == SLAP_CONFIG_EMIT) {
2139 } else if ( c->op == LDAP_MOD_DELETE ) {
2142 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2145 Debug( LDAP_DEBUG_ANY,
2146 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2147 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2149 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi)) {
2156 config_subordinate(ConfigArgs *c)
2162 case SLAP_CONFIG_EMIT:
2163 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2166 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2167 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2170 value_add_one( &c->rvalue_vals, &bv );
2174 case LDAP_MOD_DELETE:
2175 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2176 glue_sub_del( c->be );
2178 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2183 case SLAP_CONFIG_ADD:
2184 advertise = ( c->argc == 2 && !strcasecmp( c->argv[1], "advertise" ));
2185 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2192 config_suffix(ConfigArgs *c)
2195 struct berval pdn, ndn;
2196 char *notallowed = NULL;
2198 if ( c->be == frontendDB ) {
2199 notallowed = "frontend";
2201 } else if ( SLAP_MONITOR(c->be) ) {
2202 notallowed = "monitor";
2204 } else if ( SLAP_CONFIG(c->be) ) {
2205 notallowed = "config";
2208 if ( notallowed != NULL ) {
2209 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
2213 case LDAP_MOD_DELETE:
2214 case LDAP_MOD_REPLACE:
2215 case LDAP_MOD_INCREMENT:
2216 case SLAP_CONFIG_ADD:
2217 if ( !BER_BVISNULL( &c->value_dn ) ) {
2218 snprintf( buf, sizeof( buf ), "<%s> ",
2219 c->value_dn.bv_val );
2222 Debug(LDAP_DEBUG_ANY,
2223 "%s: suffix %snot allowed in %s database.\n",
2224 c->log, buf, notallowed );
2227 case SLAP_CONFIG_EMIT:
2228 /* don't complain when emitting... */
2232 /* FIXME: don't know what values may be valid;
2233 * please remove assertion, or add legal values
2234 * to either block */
2242 if (c->op == SLAP_CONFIG_EMIT) {
2243 if ( c->be->be_suffix == NULL
2244 || BER_BVISNULL( &c->be->be_suffix[0] ) )
2248 value_add( &c->rvalue_vals, c->be->be_suffix );
2249 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
2252 } else if ( c->op == LDAP_MOD_DELETE ) {
2253 if ( c->valx < 0 ) {
2254 ber_bvarray_free( c->be->be_suffix );
2255 ber_bvarray_free( c->be->be_nsuffix );
2256 c->be->be_suffix = NULL;
2257 c->be->be_nsuffix = NULL;
2260 ch_free( c->be->be_suffix[i].bv_val );
2261 ch_free( c->be->be_nsuffix[i].bv_val );
2263 c->be->be_suffix[i] = c->be->be_suffix[i+1];
2264 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
2266 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
2271 #ifdef SLAPD_MONITOR_DN
2272 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
2273 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> DN is reserved for monitoring slapd",
2275 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2276 c->log, c->cr_msg, SLAPD_MONITOR_DN);
2281 if (SLAP_DB_ONE_SUFFIX( c->be ) && c->be->be_suffix ) {
2282 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> Only one suffix is allowed on this %s backend",
2283 c->argv[0], c->be->bd_info->bi_type );
2284 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2285 c->log, c->cr_msg, 0);
2292 if (SLAP_DBHIDDEN( c->be ))
2295 tbe = select_backend(&ndn, 0);
2297 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
2303 BackendDB *b2 = tbe;
2305 /* Does tbe precede be? */
2306 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
2309 char *type = tbe->bd_info->bi_type;
2311 if ( overlay_is_over( tbe ) ) {
2312 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
2313 type = oi->oi_orig->bi_type;
2316 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> namingContext \"%s\" "
2317 "already served by a preceding %s database",
2318 c->argv[0], pdn.bv_val, type );
2319 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
2320 c->log, c->cr_msg, tbe->be_suffix[0].bv_val);
2326 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
2327 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
2328 "base provided \"%s\" (assuming okay)\n",
2329 c->log, default_search_base.bv_val, 0);
2331 ber_bvarray_add(&c->be->be_suffix, &pdn);
2332 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
2337 config_rootdn(ConfigArgs *c) {
2338 if (c->op == SLAP_CONFIG_EMIT) {
2339 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2340 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
2341 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
2346 } else if ( c->op == LDAP_MOD_DELETE ) {
2347 ch_free( c->be->be_rootdn.bv_val );
2348 ch_free( c->be->be_rootndn.bv_val );
2349 BER_BVZERO( &c->be->be_rootdn );
2350 BER_BVZERO( &c->be->be_rootndn );
2353 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2354 ch_free( c->be->be_rootdn.bv_val );
2355 ch_free( c->be->be_rootndn.bv_val );
2357 c->be->be_rootdn = c->value_dn;
2358 c->be->be_rootndn = c->value_ndn;
2363 config_rootpw(ConfigArgs *c) {
2366 if (c->op == SLAP_CONFIG_EMIT) {
2367 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
2368 /* don't copy, because "rootpw" is marked
2370 c->value_bv = c->be->be_rootpw;
2374 } else if ( c->op == LDAP_MOD_DELETE ) {
2375 ch_free( c->be->be_rootpw.bv_val );
2376 BER_BVZERO( &c->be->be_rootpw );
2380 tbe = select_backend(&c->be->be_rootndn, 0);
2382 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> can only be set when rootdn is under suffix",
2384 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2385 c->log, c->cr_msg, 0);
2388 if ( !BER_BVISNULL( &c->be->be_rootpw ))
2389 ch_free( c->be->be_rootpw.bv_val );
2390 c->be->be_rootpw = c->value_bv;
2395 config_restrict(ConfigArgs *c) {
2396 slap_mask_t restrictops = 0;
2398 slap_verbmasks restrictable_ops[] = {
2399 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
2400 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
2401 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
2402 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
2403 { BER_BVC("modrdn"), 0 },
2404 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
2405 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
2406 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
2407 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
2408 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
2409 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
2410 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
2411 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
2412 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
2413 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
2414 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
2418 if (c->op == SLAP_CONFIG_EMIT) {
2419 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
2421 } else if ( c->op == LDAP_MOD_DELETE ) {
2423 c->be->be_restrictops = 0;
2425 restrictops = verb_to_mask( c->line, restrictable_ops );
2426 c->be->be_restrictops ^= restrictops;
2430 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
2432 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown operation", c->argv[0] );
2433 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2434 c->log, c->cr_msg, c->argv[i]);
2437 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
2438 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
2439 c->be->be_restrictops |= restrictops;
2444 config_allows(ConfigArgs *c) {
2445 slap_mask_t allows = 0;
2447 slap_verbmasks allowable_ops[] = {
2448 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
2449 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
2450 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
2451 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
2452 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
2455 if (c->op == SLAP_CONFIG_EMIT) {
2456 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
2457 } else if ( c->op == LDAP_MOD_DELETE ) {
2461 allows = verb_to_mask( c->line, allowable_ops );
2462 global_allows ^= allows;
2466 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
2468 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
2469 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2470 c->log, c->cr_msg, c->argv[i]);
2473 global_allows |= allows;
2478 config_disallows(ConfigArgs *c) {
2479 slap_mask_t disallows = 0;
2481 slap_verbmasks disallowable_ops[] = {
2482 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
2483 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
2484 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
2485 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
2488 if (c->op == SLAP_CONFIG_EMIT) {
2489 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
2490 } else if ( c->op == LDAP_MOD_DELETE ) {
2492 global_disallows = 0;
2494 disallows = verb_to_mask( c->line, disallowable_ops );
2495 global_disallows ^= disallows;
2499 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
2501 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
2502 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2503 c->log, c->cr_msg, c->argv[i]);
2506 global_disallows |= disallows;
2511 config_requires(ConfigArgs *c) {
2512 slap_mask_t requires = frontendDB->be_requires;
2513 int i, argc = c->argc;
2514 char **argv = c->argv;
2516 slap_verbmasks requires_ops[] = {
2517 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
2518 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
2519 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
2520 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
2521 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
2524 if (c->op == SLAP_CONFIG_EMIT) {
2525 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
2526 } else if ( c->op == LDAP_MOD_DELETE ) {
2528 c->be->be_requires = 0;
2530 requires = verb_to_mask( c->line, requires_ops );
2531 c->be->be_requires ^= requires;
2535 /* "none" can only be first, to wipe out default/global values */
2536 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
2541 i = verbs_to_mask(argc, argv, requires_ops, &requires);
2543 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
2544 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
2545 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2546 c->log, c->cr_msg, 0);
2548 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
2549 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2550 c->log, c->cr_msg, c->argv[i]);
2554 c->be->be_requires = requires;
2558 static slap_verbmasks *loglevel_ops;
2561 loglevel_init( void )
2563 slap_verbmasks lo[] = {
2564 { BER_BVC("Any"), -1 },
2565 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
2566 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
2567 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
2568 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
2569 { BER_BVC("BER"), LDAP_DEBUG_BER },
2570 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
2571 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
2572 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
2573 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
2574 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
2575 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
2576 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
2577 #if 0 /* no longer used (nor supported) */
2578 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
2579 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
2581 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
2582 { BER_BVC("None"), LDAP_DEBUG_NONE },
2586 return slap_verbmasks_init( &loglevel_ops, lo );
2590 loglevel_destroy( void )
2592 if ( loglevel_ops ) {
2593 (void)slap_verbmasks_destroy( loglevel_ops );
2595 loglevel_ops = NULL;
2598 static slap_mask_t loglevel_ignore[] = { -1, 0 };
2601 slap_loglevel_register( slap_mask_t m, struct berval *s )
2605 if ( loglevel_ops == NULL ) {
2609 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
2612 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
2620 slap_loglevel_get( struct berval *s, int *l )
2625 if ( loglevel_ops == NULL ) {
2629 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
2630 m |= loglevel_ops[ i ].mask;
2633 for ( i = 1; m & i; i <<= 1 )
2640 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
2643 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
2654 str2loglevel( const char *s, int *l )
2658 if ( loglevel_ops == NULL ) {
2662 i = verb_to_mask( s, loglevel_ops );
2664 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
2668 *l = loglevel_ops[ i ].mask;
2674 loglevel2str( int l )
2676 struct berval bv = BER_BVNULL;
2678 loglevel2bv( l, &bv );
2684 loglevel2bv( int l, struct berval *bv )
2686 if ( loglevel_ops == NULL ) {
2692 return enum_to_verb( loglevel_ops, l, bv ) == -1;
2696 loglevel2bvarray( int l, BerVarray *bva )
2698 if ( loglevel_ops == NULL ) {
2702 return mask_to_verbs( loglevel_ops, l, bva );
2706 loglevel_print( FILE *out )
2710 if ( loglevel_ops == NULL ) {
2714 fprintf( out, "Installed log subsystems:\n\n" );
2715 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
2716 fprintf( out, "\t%-30s (%lu)\n",
2717 loglevel_ops[ i ].word.bv_val,
2718 loglevel_ops[ i ].mask );
2721 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
2722 "by specific code\n\n" );
2727 static int config_syslog;
2730 config_loglevel(ConfigArgs *c) {
2733 if ( loglevel_ops == NULL ) {
2737 if (c->op == SLAP_CONFIG_EMIT) {
2738 /* Get default or commandline slapd setting */
2739 if ( ldap_syslog && !config_syslog )
2740 config_syslog = ldap_syslog;
2741 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
2743 } else if ( c->op == LDAP_MOD_DELETE ) {
2747 int level = verb_to_mask( c->line, loglevel_ops );
2748 config_syslog ^= level;
2750 if ( slapMode & SLAP_SERVER_MODE ) {
2751 ldap_syslog = config_syslog;
2756 for( i=1; i < c->argc; i++ ) {
2759 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
2760 if( lutil_atoi( &level, c->argv[i] ) != 0 ) {
2761 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse level", c->argv[0] );
2762 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2763 c->log, c->cr_msg, c->argv[i]);
2767 if ( str2loglevel( c->argv[i], &level ) ) {
2768 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown level", c->argv[0] );
2769 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2770 c->log, c->cr_msg, c->argv[i]);
2774 /* Explicitly setting a zero clears all the levels */
2776 config_syslog |= level;
2780 if ( slapMode & SLAP_SERVER_MODE ) {
2781 ldap_syslog = config_syslog;
2787 config_referral(ConfigArgs *c) {
2789 if (c->op == SLAP_CONFIG_EMIT) {
2790 if ( default_referral ) {
2791 value_add( &c->rvalue_vals, default_referral );
2796 } else if ( c->op == LDAP_MOD_DELETE ) {
2797 if ( c->valx < 0 ) {
2798 ber_bvarray_free( default_referral );
2799 default_referral = NULL;
2802 ch_free( default_referral[i].bv_val );
2803 for (; default_referral[i].bv_val; i++ )
2804 default_referral[i] = default_referral[i+1];
2808 if(validate_global_referral(c->argv[1])) {
2809 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
2810 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2811 c->log, c->cr_msg, c->argv[1]);
2815 ber_str2bv(c->argv[1], 0, 0, &val);
2816 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
2824 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
2825 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
2826 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
2827 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
2828 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
2829 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
2830 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
2831 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
2832 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
2837 config_security(ConfigArgs *c) {
2838 slap_ssf_set_t *set = &c->be->be_ssf_set;
2841 if (c->op == SLAP_CONFIG_EMIT) {
2847 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
2848 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
2851 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
2852 if ( bv.bv_len >= sizeof( numbuf ) ) {
2853 ber_bvarray_free_x( c->rvalue_vals, NULL );
2854 c->rvalue_vals = NULL;
2858 bv.bv_len += sec_keys[i].key.bv_len;
2859 bv.bv_val = ch_malloc( bv.bv_len + 1);
2860 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
2861 strcpy( next, numbuf );
2862 ber_bvarray_add( &c->rvalue_vals, &bv );
2867 for(i = 1; i < c->argc; i++) {
2868 slap_ssf_t *tgt = NULL;
2870 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
2871 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
2872 sec_keys[j].key.bv_len)) {
2873 src = c->argv[i] + sec_keys[j].key.bv_len;
2874 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
2879 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown factor", c->argv[0] );
2880 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2881 c->log, c->cr_msg, c->argv[i]);
2885 if ( lutil_atou( tgt, src ) != 0 ) {
2886 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse factor", c->argv[0] );
2887 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2888 c->log, c->cr_msg, c->argv[i]);
2896 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
2900 for (; !BER_BVISNULL( &an->an_name ); an++) {
2901 /* if buflen == 0, assume the buffer size has been
2902 * already checked otherwise */
2903 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
2904 if ( comma ) *ptr++ = ',';
2905 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
2912 config_updatedn(ConfigArgs *c) {
2913 if (c->op == SLAP_CONFIG_EMIT) {
2914 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
2915 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
2916 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
2920 } else if ( c->op == LDAP_MOD_DELETE ) {
2921 ch_free( c->be->be_update_ndn.bv_val );
2922 BER_BVZERO( &c->be->be_update_ndn );
2923 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
2926 if(SLAP_SHADOW(c->be)) {
2927 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database already shadowed", c->argv[0] );
2928 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2929 c->log, c->cr_msg, 0);
2933 ber_memfree_x( c->value_dn.bv_val, NULL );
2934 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
2935 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
2937 c->be->be_update_ndn = c->value_ndn;
2938 BER_BVZERO( &c->value_dn );
2939 BER_BVZERO( &c->value_ndn );
2941 return config_slurp_shadow( c );
2945 config_shadow( ConfigArgs *c, int flag )
2947 char *notallowed = NULL;
2949 if ( c->be == frontendDB ) {
2950 notallowed = "frontend";
2952 } else if ( SLAP_MONITOR(c->be) ) {
2953 notallowed = "monitor";
2956 if ( notallowed != NULL ) {
2957 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
2961 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SINGLE_SHADOW | flag);
2967 config_updateref(ConfigArgs *c) {
2969 if (c->op == SLAP_CONFIG_EMIT) {
2970 if ( c->be->be_update_refs ) {
2971 value_add( &c->rvalue_vals, c->be->be_update_refs );
2976 } else if ( c->op == LDAP_MOD_DELETE ) {
2977 if ( c->valx < 0 ) {
2978 ber_bvarray_free( c->be->be_update_refs );
2979 c->be->be_update_refs = NULL;
2982 ch_free( c->be->be_update_refs[i].bv_val );
2983 for (; c->be->be_update_refs[i].bv_val; i++)
2984 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
2988 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
2989 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must appear after syncrepl or updatedn",
2991 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2992 c->log, c->cr_msg, 0);
2996 if(validate_global_referral(c->argv[1])) {
2997 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
2998 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2999 c->log, c->cr_msg, c->argv[1]);
3002 ber_str2bv(c->argv[1], 0, 0, &val);
3003 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
3008 config_obsolete(ConfigArgs *c) {
3009 if (c->op == SLAP_CONFIG_EMIT)
3012 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> keyword is obsolete (ignored)",
3014 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0);
3019 config_include(ConfigArgs *c) {
3020 int savelineno = c->lineno;
3023 ConfigFile *cfsave = cfn;
3024 ConfigFile *cf2 = NULL;
3026 /* Leftover from RE23. No dynamic config for include files */
3027 if ( c->op == SLAP_CONFIG_EMIT || c->op == LDAP_MOD_DELETE )
3030 cf = ch_calloc( 1, sizeof(ConfigFile));
3031 if ( cfn->c_kids ) {
3032 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
3038 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
3039 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
3040 c->lineno = savelineno - 1;
3043 if ( cf2 ) cf2->c_sibs = NULL;
3044 else cfn->c_kids = NULL;
3045 ch_free( cf->c_file.bv_val );
3055 config_tls_option(ConfigArgs *c) {
3057 LDAP *ld = slap_tls_ld;
3059 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
3060 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
3061 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
3062 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
3063 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
3064 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
3065 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
3067 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
3069 default: Debug(LDAP_DEBUG_ANY, "%s: "
3070 "unknown tls_option <0x%x>\n",
3071 c->log, c->type, 0);
3074 if (c->op == SLAP_CONFIG_EMIT) {
3075 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
3076 } else if ( c->op == LDAP_MOD_DELETE ) {
3077 return ldap_pvt_tls_set_option( ld, flag, NULL );
3079 ch_free(c->value_string);
3080 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
3083 /* FIXME: this ought to be provided by libldap */
3085 config_tls_config(ConfigArgs *c) {
3088 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
3089 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
3091 Debug(LDAP_DEBUG_ANY, "%s: "
3092 "unknown tls_option <0x%x>\n",
3093 c->log, c->type, 0);
3096 if (c->op == SLAP_CONFIG_EMIT) {
3097 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
3098 } else if ( c->op == LDAP_MOD_DELETE ) {
3100 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
3102 ch_free( c->value_string );
3103 if ( isdigit( (unsigned char)c->argv[1][0] ) ) {
3104 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
3105 Debug(LDAP_DEBUG_ANY, "%s: "
3106 "unable to parse %s \"%s\"\n",
3107 c->log, c->argv[0], c->argv[1] );
3110 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
3112 return(ldap_int_tls_config(slap_tls_ld, flag, c->argv[1]));
3117 static CfEntryInfo *
3118 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
3128 if ( dn_match( &root->ce_entry->e_nname, dn ))
3131 c = dn->bv_val+dn->bv_len;
3132 for (;*c != ',';c--);
3136 for (--c;c>dn->bv_val && *c != ',';c--);
3140 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
3142 root = root->ce_kids;
3144 for (;root;root=root->ce_sibs) {
3145 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
3146 if ( cdn.bv_val == dn->bv_val ) {
3156 typedef struct setup_cookie {
3166 config_ldif_resp( Operation *op, SlapReply *rs )
3168 if ( rs->sr_type == REP_SEARCH ) {
3169 setup_cookie *sc = op->o_callback->sc_private;
3171 sc->cfb->cb_got_ldif = 1;
3172 /* Does the frontend exist? */
3173 if ( !sc->got_frontend ) {
3174 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
3175 "olcDatabase", STRLENOF( "olcDatabase" ))) {
3176 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3177 STRLENOF( "olcDatabase" ), "={-1}frontend",
3178 STRLENOF( "={-1}frontend" ))) {
3181 sc->ca->be = frontendDB;
3182 sc->ca->bi = frontendDB->bd_info;
3183 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
3184 rdn.bv_val = sc->ca->log;
3185 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3186 "%s=" SLAP_X_ORDERED_FMT "%s",
3187 cfAd_database->ad_cname.bv_val, -1,
3188 sc->ca->bi->bi_type);
3190 sc->frontend = config_build_entry( op, rs,
3191 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
3192 sc->ca->be->be_cf_ocs );
3201 /* Does the configDB exist? */
3202 if ( sc->got_frontend && !sc->got_config &&
3203 !strncmp( rs->sr_entry->e_nname.bv_val,
3204 "olcDatabase", STRLENOF( "olcDatabase" ))) {
3205 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3206 STRLENOF( "olcDatabase" ), "={0}config",
3207 STRLENOF( "={0}config" ))) {
3210 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
3211 sc->ca->bi = sc->ca->be->bd_info;
3212 rdn.bv_val = sc->ca->log;
3213 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3214 "%s=" SLAP_X_ORDERED_FMT "%s",
3215 cfAd_database->ad_cname.bv_val, 0,
3216 sc->ca->bi->bi_type);
3218 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
3219 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
3226 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
3227 if ( rs->sr_err != LDAP_SUCCESS ) {
3228 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
3229 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg, 0 );
3235 /* Configure and read the underlying back-ldif store */
3237 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
3238 CfBackInfo *cfb = be->be_private;
3244 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
3245 Connection conn = {0};
3246 OperationBuffer opbuf;
3248 SlapReply rs = {REP_RESULT};
3249 Filter filter = { LDAP_FILTER_PRESENT };
3250 struct berval filterstr = BER_BVC("(objectclass=*)");
3253 /* Is the config directory available? */
3254 if ( stat( dir, &st ) < 0 ) {
3255 /* No, so don't bother using the backing store.
3256 * All changes will be in-memory only.
3261 cfb->cb_db.bd_info = backend_info( "ldif" );
3262 if ( !cfb->cb_db.bd_info )
3263 return 0; /* FIXME: eventually this will be a fatal error */
3265 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
3268 cfb->cb_db.be_suffix = be->be_suffix;
3269 cfb->cb_db.be_nsuffix = be->be_nsuffix;
3271 /* The suffix is always "cn=config". The underlying DB's rootdn
3272 * is always the same as the suffix.
3274 cfb->cb_db.be_rootdn = be->be_suffix[0];
3275 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
3277 ber_str2bv( dir, 0, 1, &cfdir );
3282 argv[0] = "directory";
3283 argv[1] = (char *)dir;
3288 c.table = Cft_Database;
3290 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
3294 if ( config_add_vals( ct, &c ))
3297 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
3301 void *thrctx = ldap_pvt_thread_pool_context();
3304 connection_fake_init( &conn, &opbuf, thrctx );
3307 filter.f_desc = slap_schema.si_ad_objectClass;
3309 op->o_tag = LDAP_REQ_SEARCH;
3311 op->ors_filter = &filter;
3312 op->ors_filterstr = filterstr;
3313 op->ors_scope = LDAP_SCOPE_SUBTREE;
3315 op->o_dn = c.be->be_rootdn;
3316 op->o_ndn = c.be->be_rootndn;
3318 op->o_req_dn = be->be_suffix[0];
3319 op->o_req_ndn = be->be_nsuffix[0];
3321 op->ors_tlimit = SLAP_NO_LIMIT;
3322 op->ors_slimit = SLAP_NO_LIMIT;
3324 op->ors_attrs = slap_anlist_all_attributes;
3325 op->ors_attrsonly = 0;
3327 op->o_callback = &cb;
3330 cb.sc_private = ≻
3331 sc.got_frontend = 0;
3336 op->o_bd = &cfb->cb_db;
3338 /* Allow unknown attrs in DNs */
3339 prev_DN_strict = slap_DN_strict;
3342 rc = op->o_bd->be_search( op, &rs );
3344 /* Restore normal DN validation */
3345 slap_DN_strict = prev_DN_strict;
3347 op->o_tag = LDAP_REQ_ADD;
3348 if ( rc == LDAP_SUCCESS && sc.frontend ) {
3349 op->ora_e = sc.frontend;
3350 rc = op->o_bd->be_add( op, &rs );
3352 if ( rc == LDAP_SUCCESS && sc.config ) {
3353 op->ora_e = sc.config;
3354 rc = op->o_bd->be_add( op, &rs );
3356 ldap_pvt_thread_pool_context_reset( thrctx );
3359 /* ITS#4194 - only use if it's present, or we're converting. */
3360 if ( !readit || rc == LDAP_SUCCESS )
3361 cfb->cb_use_ldif = 1;
3367 CfOc_cmp( const void *c1, const void *c2 ) {
3368 const ConfigOCs *co1 = c1;
3369 const ConfigOCs *co2 = c2;
3371 return ber_bvcmp( co1->co_name, co2->co_name );
3375 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
3378 i = init_config_attrs( ct );
3381 /* set up the objectclasses */
3382 i = init_config_ocs( ocs );
3385 for (i=0; ocs[i].co_def; i++) {
3386 if ( ocs[i].co_oc ) {
3387 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
3388 if ( !ocs[i].co_table )
3389 ocs[i].co_table = ct;
3390 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
3397 read_config(const char *fname, const char *dir) {
3400 const char *cfdir, *cfname;
3403 /* Setup the config backend */
3404 be = backend_db_init( "config", NULL, 0, NULL );
3408 cfb = be->be_private;
3409 be->be_dfltaccess = ACL_NONE;
3411 /* If no .conf, or a dir was specified, setup the dir */
3412 if ( !fname || dir ) {
3414 /* If explicitly given, check for existence */
3417 if ( stat( dir, &st ) < 0 ) {
3418 Debug( LDAP_DEBUG_ANY,
3419 "invalid config directory %s, error %d\n",
3425 cfdir = SLAPD_DEFAULT_CONFIGDIR;
3427 /* if fname is defaulted, try reading .d */
3428 rc = config_setup_ldif( be, cfdir, !fname );
3431 /* It may be OK if the base object doesn't exist yet. */
3432 if ( rc != LDAP_NO_SUCH_OBJECT )
3434 /* ITS#4194: But if dir was specified and no fname,
3435 * then we were supposed to read the dir. Unless we're
3436 * trying to slapadd the dir...
3438 if ( dir && !fname ) {
3439 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
3441 /* Assume it's slapadd with a config dir, let it continue */
3443 cfb->cb_got_ldif = 1;
3444 cfb->cb_use_ldif = 1;
3449 /* If we read the config from back-ldif, nothing to do here */
3450 if ( cfb->cb_got_ldif ) {
3459 cfname = SLAPD_DEFAULT_CONFIGFILE;
3461 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
3464 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
3467 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
3468 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
3469 &frontendDB->be_schemadn );
3470 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
3471 if ( rc != LDAP_SUCCESS ) {
3472 Debug(LDAP_DEBUG_ANY, "read_config: "
3473 "unable to normalize default schema DN \"%s\"\n",
3474 frontendDB->be_schemadn.bv_val, 0, 0 );
3475 /* must not happen */
3483 config_back_bind( Operation *op, SlapReply *rs )
3485 if ( be_isroot_pw( op ) ) {
3486 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
3487 /* frontend sends result */
3488 return LDAP_SUCCESS;
3491 rs->sr_err = LDAP_INVALID_CREDENTIALS;
3492 send_ldap_result( op, rs );
3498 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
3502 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
3504 rs->sr_attrs = op->ors_attrs;
3505 rs->sr_entry = ce->ce_entry;
3507 rc = send_search_entry( op, rs );
3509 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
3510 if ( ce->ce_kids ) {
3511 rc = config_send( op, rs, ce->ce_kids, 1 );
3512 if ( rc ) return rc;
3515 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
3516 rc = config_send( op, rs, ce, 0 );
3524 static ConfigTable *
3525 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
3530 for (j=0; j<nocs; j++) {
3531 for (i=0; colst[j]->co_table[i].name; i++)
3532 if ( colst[j]->co_table[i].ad == ad ) {
3533 ca->table = colst[j]->co_type;
3534 return &colst[j]->co_table[i];
3540 /* Sort the attributes of the entry according to the order defined
3541 * in the objectclass, with required attributes occurring before
3542 * allowed attributes. For any attributes with sequencing dependencies
3543 * (e.g., rootDN must be defined after suffix) the objectclass must
3544 * list the attributes in the desired sequence.
3547 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
3549 Attribute *a, *head = NULL, *tail = NULL, **prev;
3552 for (i=0; i<nocs; i++) {
3553 if ( colst[i]->co_oc->soc_required ) {
3554 AttributeType **at = colst[i]->co_oc->soc_required;
3555 for (j=0; at[j]; j++) {
3556 for (a=e->e_attrs, prev=&e->e_attrs; a;
3557 prev = &(*prev)->a_next, a=a->a_next) {
3558 if ( a->a_desc == at[j]->sat_ad ) {
3572 if ( colst[i]->co_oc->soc_allowed ) {
3573 AttributeType **at = colst[i]->co_oc->soc_allowed;
3574 for (j=0; at[j]; j++) {
3575 for (a=e->e_attrs, prev=&e->e_attrs; a;
3576 prev = &(*prev)->a_next, a=a->a_next) {
3577 if ( a->a_desc == at[j]->sat_ad ) {
3593 tail->a_next = e->e_attrs;
3599 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
3601 Attribute *a = NULL;
3602 AttributeDescription *ad;
3612 Modifications *ml = ptr;
3614 vals = ml->sml_values;
3617 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
3618 rc = ordered_value_sort( a, 1 );
3620 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
3621 ad->ad_cname.bv_val );
3625 for ( i=0; vals[i].bv_val; i++ ) {
3626 ca->line = vals[i].bv_val;
3627 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
3628 ca->line[0] == '{' ) {
3629 char *idx = strchr( ca->line, '}' );
3630 if ( idx ) ca->line = idx+1;
3632 rc = config_parse_vals( ct, ca, i );
3641 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
3644 struct berval rtype, rval;
3646 AttributeDescription *ad = NULL;
3648 dnRdn( &e->e_name, rdn );
3649 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
3650 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
3651 rtype.bv_val = rdn->bv_val;
3652 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
3655 slap_bv2ad( &rtype, &ad, &rs->sr_text );
3656 a = attr_find( e->e_attrs, ad );
3657 if (!a ) return LDAP_NAMING_VIOLATION;
3664 config_rename_kids( CfEntryInfo *ce )
3667 struct berval rdn, nrdn;
3669 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
3670 dnRdn ( &ce2->ce_entry->e_name, &rdn );
3671 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
3672 free( ce2->ce_entry->e_name.bv_val );
3673 free( ce2->ce_entry->e_nname.bv_val );
3674 build_new_dn( &ce2->ce_entry->e_name, &ce->ce_entry->e_name,
3676 build_new_dn( &ce2->ce_entry->e_nname, &ce->ce_entry->e_nname,
3678 config_rename_kids( ce2 );
3683 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
3684 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
3685 struct berval *nnewrdn, int use_ldif )
3689 struct berval odn, ondn;
3693 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
3694 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
3697 free( a->a_vals[0].bv_val );
3698 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
3699 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
3700 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
3701 strcpy( a->a_vals[0].bv_val, ptr1 );
3703 if ( a->a_nvals != a->a_vals ) {
3704 free( a->a_nvals[0].bv_val );
3705 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
3706 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
3707 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
3708 strcpy( a->a_nvals[0].bv_val, ptr1 );
3711 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
3712 BackendDB *be = op->o_bd;
3713 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
3714 struct berval dn, ndn, xdn, xndn;
3716 op->o_bd = &cfb->cb_db;
3718 /* Save current rootdn; use the underlying DB's rootdn */
3722 xndn = op->o_req_ndn;
3723 op->o_dn = op->o_bd->be_rootdn;
3724 op->o_ndn = op->o_bd->be_rootndn;
3726 op->o_req_ndn = ondn;
3728 scp = op->o_callback;
3729 op->o_callback = ≻
3730 op->orr_newrdn = *newrdn;
3731 op->orr_nnewrdn = *nnewrdn;
3732 op->orr_newSup = NULL;
3733 op->orr_nnewSup = NULL;
3734 op->orr_deleteoldrdn = 1;
3735 op->orr_modlist = NULL;
3736 slap_modrdn2mods( op, rs );
3737 slap_mods_opattrs( op, &op->orr_modlist, 1 );
3738 rc = op->o_bd->be_modrdn( op, rs );
3739 slap_mods_free( op->orr_modlist, 1 );
3742 op->o_callback = scp;
3746 op->o_req_ndn = xndn;
3749 free( ondn.bv_val );
3751 config_rename_kids( e->e_private );
3756 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
3757 Entry *e, int idx, int tailindex, int use_ldif )
3759 struct berval ival, newrdn, nnewrdn;
3762 char ibuf[32], *ptr1, *ptr2 = NULL;
3765 rc = config_rename_attr( rs, e, &rdn, &a );
3766 if ( rc ) return rc;
3769 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
3770 if ( ival.bv_len >= sizeof( ibuf ) ) {
3771 return LDAP_NAMING_VIOLATION;
3774 newrdn.bv_len = rdn.bv_len + ival.bv_len;
3775 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
3778 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
3779 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3782 ptr2 = ber_bvchr( &rdn, '}' );
3786 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
3788 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
3789 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
3790 a->a_desc->ad_cname.bv_len );
3792 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3793 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
3797 /* Do the equivalent of ModRDN */
3798 /* Replace DN / NDN */
3799 newrdn.bv_len = ptr1 - newrdn.bv_val;
3800 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
3801 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
3803 free( nnewrdn.bv_val );
3804 free( newrdn.bv_val );
3809 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
3810 SlapReply *rs, int *renum, int *ibase )
3813 int index = -1, gotindex = 0, nsibs, rc = 0;
3814 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
3815 char *ptr1, *ptr2 = NULL;
3818 if ( renum ) *renum = 0;
3820 /* These entries don't get indexed/renumbered */
3821 if ( ce_type == Cft_Global ) return 0;
3822 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
3824 if ( ce_type == Cft_Module )
3827 /* See if the rdn has an index already */
3828 dnRdn( &e->e_name, &rdn );
3829 if ( ce_type == Cft_Database ) {
3830 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
3831 "frontend", STRLENOF("frontend") ))
3833 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
3834 "config", STRLENOF("config") ))
3837 ptr1 = ber_bvchr( &e->e_name, '{' );
3838 if ( ptr1 && ptr1 - e->e_name.bv_val < rdn.bv_len ) {
3840 ptr2 = strchr( ptr1, '}' );
3841 if (!ptr2 || ptr2 - e->e_name.bv_val > rdn.bv_len)
3842 return LDAP_NAMING_VIOLATION;
3843 if ( ptr2-ptr1 == 1)
3844 return LDAP_NAMING_VIOLATION;
3846 index = strtol( ptr1 + 1, &next, 10 );
3847 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
3848 return LDAP_NAMING_VIOLATION;
3851 /* Special case, we allow -1 for the frontendDB */
3852 if ( index != -1 || !isfrontend )
3853 return LDAP_NAMING_VIOLATION;
3855 if ( isconfig && index != 0 ){
3856 return LDAP_NAMING_VIOLATION;
3860 /* count related kids */
3861 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
3862 if ( ce->ce_type == ce_type ) nsibs++;
3865 /* account for -1 frontend */
3866 if ( ce_type == Cft_Database )
3869 if ( index != nsibs ) {
3871 if ( index < nsibs ) {
3872 if ( tailindex ) return LDAP_NAMING_VIOLATION;
3873 /* Siblings need to be renumbered */
3874 if ( index != -1 || !isfrontend )
3878 /* config DB is always "0" */
3879 if ( isconfig && index == -1 ) {
3882 if ( !isfrontend && index == -1 ) {
3886 /* just make index = nsibs */
3888 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
3891 if ( ibase ) *ibase = index;
3892 if ( renum ) *renum = renumber;
3897 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
3902 co.co_name = &oc->soc_cname;
3903 cop = avl_find( CfOcTree, &co, CfOc_cmp );
3907 /* check for duplicates */
3908 for ( i = 0; i < *nocs; i++ ) {
3909 if ( *copp && (*copp)[i] == cop ) {
3915 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
3916 if ( tmp == NULL ) {
3920 (*copp)[*nocs] = cop;
3925 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
3926 if ( count_oc( *sups, copp, nocs ) ) {
3935 count_ocs( Attribute *oc_at, int *nocs )
3938 ConfigOCs **colst = NULL;
3942 for ( i = 0; !BER_BVISNULL( &oc_at->a_nvals[i] ); i++ )
3946 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
3948 assert( oc != NULL );
3949 if ( count_oc( oc, &colst, nocs ) ) {
3959 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
3961 /* Leftover from RE23. Never parse this entry */
3962 return LDAP_COMPARE_TRUE;
3966 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
3970 /* This entry is hardcoded, don't re-parse it */
3971 if ( p->ce_type == Cft_Global ) {
3972 cfn = p->ce_private;
3973 ca->ca_private = cfn;
3974 return LDAP_COMPARE_TRUE;
3976 if ( p->ce_type != Cft_Schema )
3977 return LDAP_CONSTRAINT_VIOLATION;
3979 cfn = ch_calloc( 1, sizeof(ConfigFile) );
3980 ca->ca_private = cfn;
3981 cfo = p->ce_private;
3982 cfn->c_sibs = cfo->c_kids;
3984 return LDAP_SUCCESS;
3988 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
3990 if ( p->ce_type != Cft_Global ) {
3991 return LDAP_CONSTRAINT_VIOLATION;
3993 ca->be = frontendDB; /* just to get past check_vals */
3994 return LDAP_SUCCESS;
3998 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4000 if ( p->ce_type != Cft_Global ) {
4001 return LDAP_CONSTRAINT_VIOLATION;
4003 return LDAP_SUCCESS;
4007 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4009 if ( p->ce_type != Cft_Global ) {
4010 return LDAP_CONSTRAINT_VIOLATION;
4012 return LDAP_SUCCESS;
4016 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4018 if ( p->ce_type != Cft_Database ) {
4019 return LDAP_CONSTRAINT_VIOLATION;
4022 return LDAP_SUCCESS;
4026 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
4031 AttributeDescription *ad;
4036 if ( cfn->c_cr_head ) {
4037 struct berval bv = BER_BVC("olcDitContentRules");
4039 slap_bv2ad( &bv, &ad, &text );
4040 ct = config_find_table( colst, nocs, ad, ca );
4041 config_del_vals( ct, ca );
4043 if ( cfn->c_oc_head ) {
4044 struct berval bv = BER_BVC("olcObjectClasses");
4046 slap_bv2ad( &bv, &ad, &text );
4047 ct = config_find_table( colst, nocs, ad, ca );
4048 config_del_vals( ct, ca );
4050 if ( cfn->c_at_head ) {
4051 struct berval bv = BER_BVC("olcAttributeTypes");
4053 slap_bv2ad( &bv, &ad, &text );
4054 ct = config_find_table( colst, nocs, ad, ca );
4055 config_del_vals( ct, ca );
4057 if ( cfn->c_om_head ) {
4058 struct berval bv = BER_BVC("olcObjectIdentifier");
4060 slap_bv2ad( &bv, &ad, &text );
4061 ct = config_find_table( colst, nocs, ad, ca );
4062 config_del_vals( ct, ca );
4064 cfo = p->ce_private;
4065 cfo->c_kids = cfn->c_sibs;
4070 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
4072 int rc = LDAP_CONSTRAINT_VIOLATION;
4075 if ( (*cop)->co_ldadd ) {
4076 rc = (*cop)->co_ldadd( last, e, ca );
4077 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4082 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
4083 ConfigOCs co = { 0 };
4085 co.co_name = &(*ocp)->soc_cname;
4086 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
4087 if ( *cop == NULL ) {
4091 rc = config_add_oc( cop, last, e, ca );
4092 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4100 /* Parse an LDAP entry into config directives */
4102 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
4103 int *renum, Operation *op )
4105 CfEntryInfo *ce, *last = NULL;
4106 ConfigOCs co, *coptr, **colst;
4107 Attribute *a, *oc_at, *soc_at;
4108 int i, ibase = -1, nocs, rc = 0;
4111 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
4113 memset( ca, 0, sizeof(ConfigArgs));
4115 /* Make sure parent exists and entry does not. But allow
4116 * Databases and Overlays to be inserted. Don't do any
4117 * auto-renumbering if manageDSAit control is present.
4119 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
4121 if ( ( op && op->o_managedsait ) ||
4122 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
4123 ce->ce_type != Cft_Module ) )
4125 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4126 "DN=\"%s\" already exists\n",
4127 log_prefix, e->e_name.bv_val, 0 );
4128 return LDAP_ALREADY_EXISTS;
4132 dnParent( &e->e_nname, &pdn );
4134 /* If last is NULL, the new entry is the root/suffix entry,
4135 * otherwise last should be the parent.
4137 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
4139 rs->sr_matched = last->ce_entry->e_name.bv_val;
4141 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4142 "DN=\"%s\" not child of DN=\"%s\"\n",
4143 log_prefix, e->e_name.bv_val,
4144 last->ce_entry->e_name.bv_val );
4145 return LDAP_NO_SUCH_OBJECT;
4149 /* No parent, must be root. This will never happen... */
4150 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
4151 return LDAP_NO_SUCH_OBJECT;
4154 if ( last && !access_allowed( op, last->ce_entry,
4155 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
4157 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4158 "DN=\"%s\" no write access to \"children\" of parent\n",
4159 log_prefix, e->e_name.bv_val, 0 );
4160 return LDAP_INSUFFICIENT_ACCESS;
4164 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4166 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4167 "DN=\"%s\" no objectClass\n",
4168 log_prefix, e->e_name.bv_val, 0 );
4169 return LDAP_OBJECT_CLASS_VIOLATION;
4172 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4174 ObjectClass *soc = NULL;
4175 char textbuf[ SLAP_TEXT_BUFLEN ];
4176 const char *text = textbuf;
4178 /* FIXME: check result */
4179 rc = structural_class( oc_at->a_nvals, &soc, NULL,
4180 &text, textbuf, sizeof(textbuf), NULL );
4181 if ( rc != LDAP_SUCCESS ) {
4182 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4183 "DN=\"%s\" no structural objectClass (%s)\n",
4184 log_prefix, e->e_name.bv_val, text );
4187 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
4188 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4189 if ( soc_at == NULL ) {
4190 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4191 "DN=\"%s\" no structural objectClass; "
4192 "unable to merge computed class %s\n",
4193 log_prefix, e->e_name.bv_val,
4194 soc->soc_cname.bv_val );
4195 return LDAP_OBJECT_CLASS_VIOLATION;
4198 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4199 "DN=\"%s\" no structural objectClass; "
4200 "computed objectClass %s merged\n",
4201 log_prefix, e->e_name.bv_val,
4202 soc->soc_cname.bv_val );
4205 /* Fake the coordinates based on whether we're part of an
4206 * LDAP Add or if reading the config dir
4209 ca->fname = "slapd";
4212 ca->fname = cfdir.bv_val;
4217 co.co_name = &soc_at->a_nvals[0];
4218 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
4219 if ( coptr == NULL ) {
4220 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4221 "DN=\"%s\" no structural objectClass in configuration table\n",
4222 log_prefix, e->e_name.bv_val, 0 );
4223 return LDAP_OBJECT_CLASS_VIOLATION;
4226 /* Only the root can be Cft_Global, everything else must
4227 * have a parent. Only limited nesting arrangements are allowed.
4229 rc = LDAP_CONSTRAINT_VIOLATION;
4230 if ( coptr->co_type == Cft_Global && !last ) {
4231 cfn = cfb->cb_config;
4232 ca->ca_private = cfn;
4233 ca->be = frontendDB; /* just to get past check_vals */
4237 colst = count_ocs( oc_at, &nocs );
4239 /* Check whether the Add is allowed by its parent, and do
4240 * any necessary arg setup
4243 rc = config_add_oc( &coptr, last, e, ca );
4244 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4245 for ( i = 0; i<nocs; i++ ) {
4246 /* Already checked these */
4247 if ( colst[i]->co_oc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
4249 if ( colst[i]->co_ldadd &&
4250 ( rc = colst[i]->co_ldadd( last, e, ca ))
4251 != LDAP_CONSTRAINT_VIOLATION ) {
4257 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4258 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4259 "DN=\"%s\" no structural objectClass add function\n",
4260 log_prefix, e->e_name.bv_val, 0 );
4261 return LDAP_OBJECT_CLASS_VIOLATION;
4265 /* Add the entry but don't parse it, we already have its contents */
4266 if ( rc == LDAP_COMPARE_TRUE ) {
4271 if ( rc != LDAP_SUCCESS )
4274 /* Parse all the values and check for simple syntax errors before
4275 * performing any set actions.
4277 * If doing an LDAPadd, check for indexed names and any necessary
4278 * renaming/renumbering. Entries that don't need indexed names are
4279 * ignored. Entries that need an indexed name and arrive without one
4280 * are assigned to the end. Entries that arrive with an index may
4281 * cause the following entries to be renumbered/bumped down.
4283 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
4284 * don't allow Adding an entry with an index that's already in use.
4285 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
4287 * These entries can have auto-assigned indexes (appended to the end)
4288 * but only the other types support auto-renumbering of siblings.
4291 rc = check_name_index( last, coptr->co_type, e, rs, renum,
4296 if ( renum && *renum && coptr->co_type != Cft_Database &&
4297 coptr->co_type != Cft_Overlay )
4299 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
4300 "operation requires sibling renumbering" );
4301 rc = LDAP_UNWILLING_TO_PERFORM;
4306 init_config_argv( ca );
4308 /* Make sure we process attrs in the required order */
4309 sort_attrs( e, colst, nocs );
4311 for ( a = e->e_attrs; a; a = a->a_next ) {
4312 if ( a == oc_at ) continue;
4313 ct = config_find_table( colst, nocs, a->a_desc, ca );
4314 if ( !ct ) continue; /* user data? */
4315 rc = check_vals( ct, ca, a, 1 );
4316 if ( rc ) goto done_noop;
4319 /* Basic syntax checks are OK. Do the actual settings. */
4320 for ( a=e->e_attrs; a; a=a->a_next ) {
4321 if ( a == oc_at ) continue;
4322 ct = config_find_table( colst, nocs, a->a_desc, ca );
4323 if ( !ct ) continue; /* user data? */
4324 for (i=0; a->a_vals[i].bv_val; i++) {
4326 ca->line = a->a_vals[i].bv_val;
4327 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
4328 ptr = strchr( ca->line, '}' );
4330 iptr = strchr( ca->line, '{' );
4334 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
4336 ca->valx = strtol( iptr+1, NULL, 0 );
4343 rc = config_parse_add( ct, ca, i );
4351 /* Newly added databases and overlays need to be started up */
4352 if ( CONFIG_ONLINE_ADD( ca )) {
4353 if ( colst[0]->co_type == Cft_Database ) {
4354 rc = backend_startup_one( ca->be, &ca->reply );
4356 } else if ( colst[0]->co_type == Cft_Overlay ) {
4357 if ( ca->bi->bi_db_open ) {
4358 BackendInfo *bi_orig = ca->be->bd_info;
4359 ca->be->bd_info = ca->bi;
4360 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
4361 ca->be->bd_info = bi_orig;
4363 } else if ( ca->cleanup ) {
4364 rc = ca->cleanup( ca );
4367 if (ca->cr_msg[0] == '\0')
4368 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
4370 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
4371 ca->log, ca->cr_msg, ca->argv[1] );
4378 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
4379 ce->ce_parent = last;
4380 ce->ce_entry = entry_dup( e );
4381 ce->ce_entry->e_private = ce;
4382 ce->ce_type = colst[0]->co_type;
4385 ce->ce_private = ca->ca_private;
4386 ca->ca_entry = ce->ce_entry;
4389 } else if ( last->ce_kids ) {
4390 CfEntryInfo *c2, **cprev;
4392 /* Advance to first of this type */
4393 cprev = &last->ce_kids;
4394 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
4395 cprev = &c2->ce_sibs;
4398 /* Account for the (-1) frontendDB entry */
4399 if ( ce->ce_type == Cft_Database ) {
4400 if ( ca->be == frontendDB )
4402 else if ( ibase != -1 )
4407 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
4408 cprev = &c2->ce_sibs;
4414 for ( i=0; i<ibase; i++ ) {
4416 cprev = &c2->ce_sibs;
4419 ce->ce_sibs = *cprev;
4427 if ( (colst[0]->co_type == Cft_Database) && ca->be ) {
4428 if ( ca->be != frontendDB )
4429 backend_destroy_one( ca->be, 1 );
4430 } else if ( (colst[0]->co_type == Cft_Overlay) && ca->bi ) {
4431 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
4432 } else if ( colst[0]->co_type == Cft_Schema ) {
4433 schema_destroy_one( ca, colst, nocs, last );
4438 ch_free( ca->argv );
4439 if ( colst ) ch_free( colst );
4443 #define BIGTMP 10000
4445 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
4446 int base, int rebase, int max, int use_ldif )
4448 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
4449 ConfigType etype = ce->ce_type;
4450 int count = 0, rc = 0;
4452 /* Reverse ce list */
4453 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
4454 if (ce2->ce_type != etype) {
4459 ce2->ce_sibs = cetmp;
4462 if ( max && count >= max ) {
4468 /* Move original to a temp name until increments are done */
4470 ce->ce_entry->e_private = NULL;
4471 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4472 base+BIGTMP, 0, use_ldif );
4473 ce->ce_entry->e_private = ce;
4475 /* start incrementing */
4476 for (ce2=cetmp; ce2; ce2=ce3) {
4478 ce2->ce_sibs = cerem;
4481 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
4482 count+base, 0, use_ldif );
4486 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4487 base, 0, use_ldif );
4492 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
4493 CfEntryInfo *ce2, int old, int use_ldif )
4497 /* Renumber original to a temp value */
4498 ce->ce_entry->e_private = NULL;
4499 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4500 old+BIGTMP, 0, use_ldif );
4501 ce->ce_entry->e_private = ce;
4503 /* start decrementing */
4504 for (; ce2 != ce; ce2=ce2->ce_sibs) {
4505 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
4506 count+old, 0, use_ldif );
4509 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4510 count+old, 0, use_ldif );
4513 /* Parse an LDAP entry into config directives, then store in underlying
4517 config_back_add( Operation *op, SlapReply *rs )
4523 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
4524 NULL, ACL_WADD, NULL )) {
4525 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4529 cfb = (CfBackInfo *)op->o_bd->be_private;
4531 /* add opattrs for syncprov */
4533 char textbuf[SLAP_TEXT_BUFLEN];
4534 size_t textlen = sizeof textbuf;
4535 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1,
4536 &rs->sr_text, textbuf, sizeof( textbuf ) );
4537 if ( rs->sr_err != LDAP_SUCCESS )
4539 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
4540 if ( rs->sr_err != LDAP_SUCCESS ) {
4541 Debug( LDAP_DEBUG_TRACE,
4542 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
4543 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
4548 ldap_pvt_thread_pool_pause( &connection_pool );
4551 * 1) check for existence of entry
4552 * 2) check for sibling renumbering
4553 * 3) perform internal add
4554 * 4) perform any necessary renumbering
4555 * 5) store entry in underlying database
4557 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
4558 if ( rs->sr_err != LDAP_SUCCESS ) {
4559 rs->sr_text = ca.cr_msg;
4564 CfEntryInfo *ce = ca.ca_entry->e_private;
4565 req_add_s addr = op->oq_add;
4566 op->o_tag = LDAP_REQ_MODRDN;
4567 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
4568 op->o_tag = LDAP_REQ_ADD;
4570 if ( rs->sr_err != LDAP_SUCCESS ) {
4575 if ( cfb->cb_use_ldif ) {
4576 BackendDB *be = op->o_bd;
4577 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4578 struct berval dn, ndn;
4580 op->o_bd = &cfb->cb_db;
4582 /* Save current rootdn; use the underlying DB's rootdn */
4585 op->o_dn = op->o_bd->be_rootdn;
4586 op->o_ndn = op->o_bd->be_rootndn;
4588 scp = op->o_callback;
4589 op->o_callback = ≻
4590 op->o_bd->be_add( op, rs );
4592 op->o_callback = scp;
4598 ldap_pvt_thread_pool_resume( &connection_pool );
4601 send_ldap_result( op, rs );
4602 slap_graduate_commit_csn( op );
4606 typedef struct delrec {
4607 struct delrec *next;
4613 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
4618 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
4619 ca->line[0] == '{' )
4621 char *ptr = strchr( ca->line + 1, '}' );
4625 ca->valx = strtol( ca->line + 1, &next, 0 );
4626 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
4632 rc = config_parse_add( ct, ca, i );
4640 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
4643 int rc = LDAP_UNWILLING_TO_PERFORM;
4645 Entry *e = ce->ce_entry;
4646 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
4651 delrec *dels = NULL, *deltail = NULL;
4653 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4654 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
4656 colst = count_ocs( oc_at, &nocs );
4658 /* make sure add/del flags are clear; should always be true */
4659 for ( s = save_attrs; s; s = s->a_next ) {
4660 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
4663 e->e_attrs = attrs_dup( e->e_attrs );
4665 init_config_argv( ca );
4668 ca->ca_private = ce->ce_private;
4670 ca->fname = "slapd";
4672 strcpy( ca->log, "back-config" );
4674 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
4675 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
4676 switch (ml->sml_op) {
4677 case LDAP_MOD_DELETE:
4678 case LDAP_MOD_REPLACE: {
4679 BerVarray vals = NULL, nvals = NULL;
4681 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
4683 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
4684 ml->sml_desc->ad_cname.bv_val );
4687 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4688 vals = ml->sml_values;
4689 nvals = ml->sml_nvalues;
4690 ml->sml_values = NULL;
4691 ml->sml_nvalues = NULL;
4693 /* If we're deleting by values, remember the indexes of the
4694 * values we deleted.
4696 if ( ct && ml->sml_values ) {
4698 i = ml->sml_numvals;
4699 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
4710 rc = modify_delete_vindex(e, &ml->sml_mod,
4711 get_permissiveModify(op),
4712 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
4713 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4714 ml->sml_values = vals;
4715 ml->sml_nvalues = nvals;
4720 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
4723 case SLAP_MOD_SOFTADD: {
4724 int mop = ml->sml_op;
4726 ml->sml_op = LDAP_MOD_ADD;
4728 if ( ct->arg_type & ARG_NO_INSERT ) {
4729 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
4731 navals = a->a_numvals;
4734 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
4735 if ( ml->sml_values[i].bv_val[0] == '{' &&
4738 char *next, *val = ml->sml_values[i].bv_val + 1;
4741 j = strtol( val, &next, 0 );
4742 if ( next == val || next[ 0 ] != '}' || j < navals ) {
4744 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
4745 ml->sml_desc->ad_cname.bv_val );
4749 rc = check_vals( ct, ca, ml, 0 );
4750 if ( rc ) goto out_noop;
4753 rc = modify_add_values(e, &ml->sml_mod,
4754 get_permissiveModify(op),
4755 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
4757 /* If value already exists, show success here
4758 * and ignore this operation down below.
4760 if ( mop == SLAP_MOD_SOFTADD ) {
4761 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
4771 case LDAP_MOD_INCREMENT: /* FIXME */
4776 if(rc != LDAP_SUCCESS) break;
4779 if ( rc == LDAP_SUCCESS) {
4780 /* check that the entry still obeys the schema */
4781 rc = entry_schema_check(op, e, NULL, 0, 0,
4782 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
4784 if ( rc ) goto out_noop;
4786 /* Basic syntax checks are OK. Do the actual settings. */
4787 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
4788 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
4789 if ( !ct ) continue;
4791 s = attr_find( save_attrs, ml->sml_desc );
4792 a = attr_find( e->e_attrs, ml->sml_desc );
4794 switch (ml->sml_op) {
4795 case LDAP_MOD_DELETE:
4796 case LDAP_MOD_REPLACE: {
4797 BerVarray vals = NULL, nvals = NULL;
4800 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4801 vals = ml->sml_values;
4802 nvals = ml->sml_nvalues;
4803 ml->sml_values = NULL;
4804 ml->sml_nvalues = NULL;
4807 if ( ml->sml_values )
4810 /* If we didn't delete the whole attribute */
4811 if ( ml->sml_values && a ) {
4812 struct berval *mvals;
4815 if ( ml->sml_nvalues )
4816 mvals = ml->sml_nvalues;
4818 mvals = ml->sml_values;
4820 /* use the indexes we saved up above */
4821 for (i=0; i < d->nidx; i++) {
4822 struct berval bv = *mvals++;
4823 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
4824 bv.bv_val[0] == '{' ) {
4825 ptr = strchr( bv.bv_val, '}' ) + 1;
4826 bv.bv_len -= ptr - bv.bv_val;
4829 ca->line = bv.bv_val;
4830 ca->valx = d->idx[i];
4831 rc = config_del_vals( ct, ca );
4832 if ( rc != LDAP_SUCCESS ) break;
4834 s->a_flags |= SLAP_ATTR_IXDEL;
4835 for (j=i+1; j < d->nidx; j++)
4836 if ( d->idx[j] >d->idx[i] )
4842 rc = config_del_vals( ct, ca );
4843 if ( rc ) rc = LDAP_OTHER;
4845 s->a_flags |= SLAP_ATTR_IXDEL;
4847 if ( ml->sml_values ) {
4852 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4853 ml->sml_values = vals;
4854 ml->sml_nvalues = nvals;
4856 if ( !vals || rc != LDAP_SUCCESS )
4859 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
4862 for (i=0; ml->sml_values[i].bv_val; i++) {
4863 ca->line = ml->sml_values[i].bv_val;
4865 rc = config_modify_add( ct, ca, ml->sml_desc, i );
4868 a->a_flags |= SLAP_ATTR_IXADD;
4875 /* Undo for a failed operation */
4876 if ( rc != LDAP_SUCCESS ) {
4877 ConfigReply msg = ca->reply;
4878 for ( s = save_attrs; s; s = s->a_next ) {
4879 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
4880 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
4881 ct = config_find_table( colst, nocs, s->a_desc, ca );
4882 a = attr_find( e->e_attrs, s->a_desc );
4884 /* clear the flag so the add check below will skip it */
4885 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
4888 config_del_vals( ct, ca );
4890 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
4891 ca->line = s->a_vals[i].bv_val;
4893 config_modify_add( ct, ca, s->a_desc, i );
4897 for ( a = e->e_attrs; a; a = a->a_next ) {
4898 if ( a->a_flags & SLAP_ATTR_IXADD ) {
4899 ct = config_find_table( colst, nocs, a->a_desc, ca );
4902 config_del_vals( ct, ca );
4903 s = attr_find( save_attrs, a->a_desc );
4905 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
4906 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
4907 ca->line = s->a_vals[i].bv_val;
4909 config_modify_add( ct, ca, s->a_desc, i );
4920 if ( rc == LDAP_SUCCESS ) {
4921 attrs_free( save_attrs );
4923 attrs_free( e->e_attrs );
4924 e->e_attrs = save_attrs;
4926 ch_free( ca->argv );
4927 if ( colst ) ch_free( colst );
4929 deltail = dels->next;
4938 config_back_modify( Operation *op, SlapReply *rs )
4941 CfEntryInfo *ce, *last;
4943 ConfigArgs ca = {0};
4946 AttributeDescription *rad = NULL;
4949 cfb = (CfBackInfo *)op->o_bd->be_private;
4951 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
4954 rs->sr_matched = last->ce_entry->e_name.bv_val;
4955 rs->sr_err = LDAP_NO_SUCH_OBJECT;
4959 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
4960 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4964 /* Get type of RDN */
4965 rdn = ce->ce_entry->e_nname;
4966 ptr = strchr( rdn.bv_val, '=' );
4967 rdn.bv_len = ptr - rdn.bv_val;
4968 slap_bv2ad( &rdn, &rad, &rs->sr_text );
4970 /* Some basic validation... */
4971 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
4972 /* Don't allow Modify of RDN; must use ModRdn for that. */
4973 if ( ml->sml_desc == rad ) {
4974 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
4975 rs->sr_text = "Use modrdn to change the entry name";
4978 /* Internal update of contextCSN? */
4979 if ( ml->sml_desc == slap_schema.si_ad_contextCSN && op->o_conn->c_conn_idx == -1 ) {
4985 slap_mods_opattrs( op, &op->orm_modlist, 1 );
4988 ldap_pvt_thread_pool_pause( &connection_pool );
4991 * 1) perform the Modify on the cached Entry.
4992 * 2) verify that the Entry still satisfies the schema.
4993 * 3) perform the individual config operations.
4994 * 4) store Modified entry in underlying LDIF backend.
4996 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
4998 rs->sr_text = ca.cr_msg;
4999 } else if ( cfb->cb_use_ldif ) {
5000 BackendDB *be = op->o_bd;
5001 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5002 struct berval dn, ndn;
5004 op->o_bd = &cfb->cb_db;
5008 op->o_dn = op->o_bd->be_rootdn;
5009 op->o_ndn = op->o_bd->be_rootndn;
5011 scp = op->o_callback;
5012 op->o_callback = ≻
5013 op->o_bd->be_modify( op, rs );
5015 op->o_callback = scp;
5021 ldap_pvt_thread_pool_resume( &connection_pool );
5023 send_ldap_result( op, rs );
5024 slap_graduate_commit_csn( op );
5029 config_back_modrdn( Operation *op, SlapReply *rs )
5032 CfEntryInfo *ce, *last;
5036 cfb = (CfBackInfo *)op->o_bd->be_private;
5038 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5041 rs->sr_matched = last->ce_entry->e_name.bv_val;
5042 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5045 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
5046 NULL, ACL_WRITE, NULL )) {
5047 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5051 if ( ce->ce_parent )
5052 parent = ce->ce_parent->ce_entry;
5054 parent = (Entry *)&slap_entry_root;
5055 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
5056 NULL, ACL_WRITE, NULL )) {
5057 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5062 /* We don't allow moving objects to new parents.
5063 * Generally we only allow reordering a set of ordered entries.
5065 if ( op->orr_newSup ) {
5066 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5070 /* If newRDN == oldRDN, quietly succeed */
5071 dnRdn( &op->o_req_ndn, &rdn );
5072 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
5073 rs->sr_err = LDAP_SUCCESS;
5077 /* Current behavior, subject to change as needed:
5079 * For backends and overlays, we only allow renumbering.
5080 * For schema, we allow renaming with the same number.
5081 * Otherwise, the op is not allowed.
5084 if ( ce->ce_type == Cft_Schema ) {
5088 /* Can't alter the main cn=schema entry */
5089 if ( ce->ce_parent->ce_type == Cft_Global ) {
5090 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5091 rs->sr_text = "renaming not allowed for this entry";
5095 /* We could support this later if desired */
5096 ptr1 = ber_bvchr( &rdn, '}' );
5097 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5098 len = ptr1 - rdn.bv_val;
5099 if ( len != ptr2 - op->orr_newrdn.bv_val ||
5100 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
5101 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5102 rs->sr_text = "schema reordering not supported";
5105 } else if ( ce->ce_type == Cft_Database ||
5106 ce->ce_type == Cft_Overlay ) {
5107 char *ptr1, *ptr2, *iptr1, *iptr2;
5110 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
5111 if ( *iptr2 != '{' ) {
5112 rs->sr_err = LDAP_NAMING_VIOLATION;
5113 rs->sr_text = "new ordering index is required";
5117 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
5118 ptr1 = ber_bvchr( &rdn, '}' );
5119 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5121 rs->sr_err = LDAP_NAMING_VIOLATION;
5122 rs->sr_text = "new ordering index is required";
5126 len1 = ptr1 - rdn.bv_val;
5127 len2 = ptr2 - op->orr_newrdn.bv_val;
5129 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
5130 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
5131 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5132 rs->sr_text = "changing database/overlay type not allowed";
5135 ixold = strtol( iptr1, NULL, 0 );
5136 ixnew = strtol( iptr2, &ptr1, 0 );
5137 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
5138 rs->sr_err = LDAP_NAMING_VIOLATION;
5141 /* config DB is always 0, cannot be changed */
5142 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
5143 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
5147 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5148 rs->sr_text = "renaming not supported for this entry";
5152 ldap_pvt_thread_pool_pause( &connection_pool );
5154 if ( ce->ce_type == Cft_Schema ) {
5155 req_modrdn_s modr = op->oq_modrdn;
5158 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
5159 if ( rs->sr_err == LDAP_SUCCESS ) {
5160 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
5161 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
5164 op->oq_modrdn = modr;
5166 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
5167 req_modrdn_s modr = op->oq_modrdn;
5170 /* Advance to first of this type */
5171 cprev = &ce->ce_parent->ce_kids;
5172 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
5173 cprev = &ce2->ce_sibs;
5176 /* Skip the -1 entry */
5177 if ( ce->ce_type == Cft_Database ) {
5178 cprev = &ce2->ce_sibs;
5184 /* Remove from old slot */
5185 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
5186 cprev = &ce2->ce_sibs;
5187 *cprev = ce->ce_sibs;
5188 ceold = ce->ce_sibs;
5190 /* Insert into new slot */
5192 for ( i=0; i<ixnew; i++ ) {
5196 cprev = &ce2->ce_sibs;
5198 ce->ce_sibs = *cprev;
5203 /* NOTE: These should be encoded in the OC tables, not inline here */
5204 if ( ce->ce_type == Cft_Database )
5205 backend_db_move( ce->ce_be, ixnew );
5206 else if ( ce->ce_type == Cft_Overlay )
5207 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
5209 if ( ixold < ixnew ) {
5210 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
5213 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
5214 ixold - ixnew, cfb->cb_use_ldif );
5216 op->oq_modrdn = modr;
5219 ldap_pvt_thread_pool_resume( &connection_pool );
5221 send_ldap_result( op, rs );
5226 config_back_delete( Operation *op, SlapReply *rs )
5228 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM, NULL );
5233 config_back_search( Operation *op, SlapReply *rs )
5236 CfEntryInfo *ce, *last;
5239 cfb = (CfBackInfo *)op->o_bd->be_private;
5241 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5244 rs->sr_matched = last->ce_entry->e_name.bv_val;
5245 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5248 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
5249 ACL_SEARCH, NULL, &mask ))
5251 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
5252 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5254 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5258 switch ( op->ors_scope ) {
5259 case LDAP_SCOPE_BASE:
5260 case LDAP_SCOPE_SUBTREE:
5261 config_send( op, rs, ce, 0 );
5264 case LDAP_SCOPE_ONELEVEL:
5265 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
5266 config_send( op, rs, ce, 1 );
5271 rs->sr_err = LDAP_SUCCESS;
5273 send_ldap_result( op, rs );
5277 /* no-op, we never free entries */
5278 int config_entry_release(
5283 if ( !e->e_private ) {
5286 return LDAP_SUCCESS;
5289 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
5291 int config_back_entry_get(
5295 AttributeDescription *at,
5300 CfEntryInfo *ce, *last;
5302 cfb = (CfBackInfo *)op->o_bd->be_private;
5304 ce = config_find_base( cfb->cb_root, ndn, &last );
5306 *ent = ce->ce_entry;
5307 if ( *ent && oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
5312 return ( *ent == NULL ? 1 : 0 );
5316 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
5317 ConfigTable *ct, ConfigArgs *c )
5321 for (; at && *at; at++) {
5322 /* Skip the naming attr */
5323 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
5325 for (i=0;ct[i].name;i++) {
5326 if (ct[i].ad == (*at)->sat_ad) {
5327 rc = config_get_vals(&ct[i], c);
5328 /* NOTE: tolerate that config_get_vals()
5329 * returns success with no values */
5330 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
5331 if ( c->rvalue_nvals )
5332 attr_merge(e, ct[i].ad, c->rvalue_vals,
5335 attr_merge_normalize(e, ct[i].ad,
5336 c->rvalue_vals, NULL);
5337 ber_bvarray_free( c->rvalue_nvals );
5338 ber_bvarray_free( c->rvalue_vals );
5347 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
5348 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
5350 Entry *e = entry_alloc();
5351 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5353 struct berval ad_name;
5354 AttributeDescription *ad = NULL;
5361 CfEntryInfo *ceprev = NULL;
5363 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
5366 ce->ce_type = main->co_type;
5367 ce->ce_parent = parent;
5369 pdn = parent->ce_entry->e_nname;
5370 if ( parent->ce_kids )
5371 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
5372 ceprev->ce_type <= ce->ce_type;
5373 ceprev = ceprev->ce_sibs );
5378 ce->ce_private = c->ca_private;
5382 build_new_dn( &e->e_name, &pdn, rdn, NULL );
5383 ber_dupbv( &e->e_nname, &e->e_name );
5385 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
5386 main->co_name, NULL );
5388 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
5389 extra->co_name, NULL );
5390 ptr = strchr(rdn->bv_val, '=');
5391 ad_name.bv_val = rdn->bv_val;
5392 ad_name.bv_len = ptr - rdn->bv_val;
5393 rc = slap_bv2ad( &ad_name, &ad, &text );
5398 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
5399 attr_merge_normalize_one(e, ad, &val, NULL );
5402 c->table = main->co_type;
5403 if ( oc->soc_required )
5404 config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
5406 if ( oc->soc_allowed )
5407 config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
5411 c->table = extra->co_type;
5412 if ( oc->soc_required )
5413 config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
5415 if ( oc->soc_allowed )
5416 config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
5419 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5420 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
5421 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
5422 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
5425 op->ora_modlist = NULL;
5426 slap_add_opattrs( op, NULL, NULL, 0, 0 );
5427 if ( !op->o_noop ) {
5428 op->o_bd->be_add( op, rs );
5429 if ( ( rs->sr_err != LDAP_SUCCESS )
5430 && (rs->sr_err != LDAP_ALREADY_EXISTS) ) {
5436 ce->ce_sibs = ceprev->ce_sibs;
5437 ceprev->ce_sibs = ce;
5438 } else if ( parent ) {
5439 ce->ce_sibs = parent->ce_kids;
5440 parent->ce_kids = ce;
5447 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
5448 Operation *op, SlapReply *rs )
5451 ConfigFile *cf = c->ca_private;
5455 for (; cf; cf=cf->c_sibs, c->depth++) {
5456 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
5457 !cf->c_om_head ) continue;
5458 c->value_dn.bv_val = c->log;
5459 LUTIL_SLASHPATH( cf->c_file.bv_val );
5460 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
5465 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
5467 ptr = strchr( bv.bv_val, '.' );
5469 bv.bv_len = ptr - bv.bv_val;
5470 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
5471 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
5472 /* FIXME: how can indicate error? */
5475 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
5477 c->value_dn.bv_len += bv.bv_len;
5478 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
5481 e = config_build_entry( op, rs, ceparent, c, &c->value_dn,
5482 &CFOC_SCHEMA, NULL );
5485 } else if ( e && cf->c_kids ) {
5486 c->ca_private = cf->c_kids;
5487 config_build_schema_inc( c, e->e_private, op, rs );
5493 #ifdef SLAPD_MODULES
5496 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
5497 Operation *op, SlapReply *rs )
5502 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
5503 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
5505 c->value_dn.bv_val = c->log;
5506 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
5507 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
5508 /* FIXME: how can indicate error? */
5512 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
5521 config_check_schema(Operation *op, CfBackInfo *cfb)
5523 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
5525 CfEntryInfo *ce, *last;
5528 /* If there's no root entry, we must be in the midst of converting */
5529 if ( !cfb->cb_root )
5532 /* Make sure the main schema entry exists */
5533 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
5540 /* Make sure it's up to date */
5541 if ( cf_om_tail != om_sys_tail ) {
5542 a = attr_find( e->e_attrs, cfAd_om );
5544 if ( a->a_nvals != a->a_vals )
5545 ber_bvarray_free( a->a_nvals );
5546 ber_bvarray_free( a->a_vals );
5551 oidm_unparse( &bv, NULL, NULL, 1 );
5552 attr_merge_normalize( e, cfAd_om, bv, NULL );
5553 ber_bvarray_free( bv );
5554 cf_om_tail = om_sys_tail;
5556 if ( cf_at_tail != at_sys_tail ) {
5557 a = attr_find( e->e_attrs, cfAd_attr );
5559 if ( a->a_nvals != a->a_vals )
5560 ber_bvarray_free( a->a_nvals );
5561 ber_bvarray_free( a->a_vals );
5566 at_unparse( &bv, NULL, NULL, 1 );
5567 attr_merge_normalize( e, cfAd_attr, bv, NULL );
5568 ber_bvarray_free( bv );
5569 cf_at_tail = at_sys_tail;
5571 if ( cf_oc_tail != oc_sys_tail ) {
5572 a = attr_find( e->e_attrs, cfAd_oc );
5574 if ( a->a_nvals != a->a_vals )
5575 ber_bvarray_free( a->a_nvals );
5576 ber_bvarray_free( a->a_vals );
5581 oc_unparse( &bv, NULL, NULL, 1 );
5582 attr_merge_normalize( e, cfAd_oc, bv, NULL );
5583 ber_bvarray_free( bv );
5584 cf_oc_tail = oc_sys_tail;
5587 SlapReply rs = {REP_RESULT};
5588 c.ca_private = NULL;
5589 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
5590 &CFOC_SCHEMA, NULL );
5595 ce->ce_private = cfb->cb_config;
5596 cf_at_tail = at_sys_tail;
5597 cf_oc_tail = oc_sys_tail;
5598 cf_om_tail = om_sys_tail;
5603 static const char *defacl[] = {
5604 NULL, "to", "*", "by", "*", "none", NULL
5608 config_back_db_open( BackendDB *be, ConfigReply *cr )
5610 CfBackInfo *cfb = be->be_private;
5613 CfEntryInfo *ce, *ceparent;
5617 Connection conn = {0};
5618 OperationBuffer opbuf;
5620 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
5621 SlapReply rs = {REP_RESULT};
5622 void *thrctx = NULL;
5624 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
5626 /* If we have no explicitly configured ACLs, don't just use
5627 * the global ACLs. Explicitly deny access to everything.
5629 if ( frontendDB->be_acl && be->be_acl == frontendDB->be_acl ) {
5630 parse_acl(be, "config_back_db_open", 0, 6, (char **)defacl, 0 );
5633 thrctx = ldap_pvt_thread_pool_context();
5634 connection_fake_init( &conn, &opbuf, thrctx );
5637 op->o_tag = LDAP_REQ_ADD;
5638 op->o_callback = &cb;
5639 op->o_bd = &cfb->cb_db;
5640 op->o_dn = op->o_bd->be_rootdn;
5641 op->o_ndn = op->o_bd->be_rootndn;
5643 if ( !cfb->cb_use_ldif ) {
5647 /* If we read the config from back-ldif, do some quick sanity checks */
5648 if ( cfb->cb_got_ldif ) {
5649 return config_check_schema( op, cfb );
5652 /* create root of tree */
5654 c.ca_private = cfb->cb_config;
5656 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
5666 #ifdef SLAPD_MODULES
5667 /* Create Module nodes... */
5668 if ( modpaths.mp_loads ) {
5669 if ( config_build_modules( &c, ceparent, op, &rs ) ){
5675 /* Create schema nodes... cn=schema will contain the hardcoded core
5676 * schema, read-only. Child objects will contain runtime loaded schema
5680 c.ca_private = NULL;
5681 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
5686 ce->ce_private = cfb->cb_config;
5687 cf_at_tail = at_sys_tail;
5688 cf_oc_tail = oc_sys_tail;
5689 cf_om_tail = om_sys_tail;
5691 /* Create schema nodes for included schema... */
5692 if ( cfb->cb_config->c_kids ) {
5694 c.ca_private = cfb->cb_config->c_kids;
5695 if (config_build_schema_inc( &c, ce, op, &rs )) {
5700 /* Create backend nodes. Skip if they don't provide a cf_table.
5701 * There usually aren't any of these.
5705 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
5706 if (!bi->bi_cf_ocs) {
5707 /* If it only supports the old config mech, complain. */
5708 if ( bi->bi_config ) {
5709 Debug( LDAP_DEBUG_ANY,
5710 "WARNING: No dynamic config support for backend %s.\n",
5711 bi->bi_type, 0, 0 );
5716 if (!bi->bi_private) continue;
5719 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
5720 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
5721 if ( rdn.bv_len >= sizeof( c.log ) ) {
5722 /* FIXME: holler ... */ ;
5725 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
5732 /* Create database nodes... */
5733 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
5734 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
5735 for ( i = -1, be = frontendDB ; be;
5736 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
5737 slap_overinfo *oi = NULL;
5739 if ( overlay_is_over( be )) {
5740 oi = be->bd_info->bi_private;
5746 /* If this backend supports the old config mechanism, but not
5747 * the new mech, complain.
5749 if ( !be->be_cf_ocs && bi->bi_db_config ) {
5750 Debug( LDAP_DEBUG_ANY,
5751 "WARNING: No dynamic config support for database %s.\n",
5752 bi->bi_type, 0, 0 );
5756 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
5757 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
5759 if ( rdn.bv_len >= sizeof( c.log ) ) {
5760 /* FIXME: holler ... */ ;
5764 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
5770 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd )
5771 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
5772 /* Iterate through overlays */
5777 voidList *vl, *v0 = NULL;
5779 /* overlays are in LIFO order, must reverse stack */
5780 for (on=oi->oi_list; on; on=on->on_next) {
5781 vl = ch_malloc( sizeof( voidList ));
5786 for (j=0; vl; j++,vl=v0) {
5790 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
5791 Debug( LDAP_DEBUG_ANY,
5792 "WARNING: No dynamic config support for overlay %s.\n",
5793 on->on_bi.bi_type, 0, 0 );
5797 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
5798 "%s=" SLAP_X_ORDERED_FMT "%s",
5799 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
5800 if ( rdn.bv_len >= sizeof( c.log ) ) {
5801 /* FIXME: holler ... */ ;
5805 oe = config_build_entry( op, &rs, ce, &c, &rdn,
5806 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
5810 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd )
5811 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
5816 ldap_pvt_thread_pool_context_reset( thrctx );
5818 if ( unsupp && cfb->cb_use_ldif ) {
5819 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
5820 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
5827 cfb_free_cffile( ConfigFile *cf )
5831 for (; cf; cf=next) {
5834 cfb_free_cffile( cf->c_kids );
5835 ch_free( cf->c_file.bv_val );
5836 ber_bvarray_free( cf->c_dseFiles );
5842 cfb_free_entries( CfEntryInfo *ce )
5846 for (; ce; ce=next) {
5849 cfb_free_entries( ce->ce_kids );
5850 ce->ce_entry->e_private = NULL;
5851 entry_free( ce->ce_entry );
5857 config_back_db_close( BackendDB *be, ConfigReply *cr )
5859 CfBackInfo *cfb = be->be_private;
5861 cfb_free_entries( cfb->cb_root );
5862 cfb->cb_root = NULL;
5864 if ( cfb->cb_db.bd_info ) {
5865 backend_shutdown( &cfb->cb_db );
5872 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
5874 CfBackInfo *cfb = be->be_private;
5876 cfb_free_cffile( cfb->cb_config );
5878 ch_free( cfdir.bv_val );
5880 avl_free( CfOcTree, NULL );
5882 if ( cfb->cb_db.bd_info ) {
5883 cfb->cb_db.be_suffix = NULL;
5884 cfb->cb_db.be_nsuffix = NULL;
5885 BER_BVZERO( &cfb->cb_db.be_rootdn );
5886 BER_BVZERO( &cfb->cb_db.be_rootndn );
5888 backend_destroy_one( &cfb->cb_db, 0 );
5897 config_back_db_init( BackendDB *be, ConfigReply* cr )
5903 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
5904 cfn = cfb->cb_config;
5905 be->be_private = cfb;
5907 ber_dupbv( &be->be_rootdn, &config_rdn );
5908 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
5909 ber_dupbv( &dn, &be->be_rootdn );
5910 ber_bvarray_add( &be->be_suffix, &dn );
5911 ber_dupbv( &dn, &be->be_rootdn );
5912 ber_bvarray_add( &be->be_nsuffix, &dn );
5914 /* Hide from namingContexts */
5915 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
5921 config_back_destroy( BackendInfo *bi )
5923 ldif_must_b64_encode_release();
5928 config_tool_entry_open( BackendDB *be, int mode )
5930 CfBackInfo *cfb = be->be_private;
5931 BackendInfo *bi = cfb->cb_db.bd_info;
5933 if ( bi && bi->bi_tool_entry_open )
5934 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
5941 config_tool_entry_close( BackendDB *be )
5943 CfBackInfo *cfb = be->be_private;
5944 BackendInfo *bi = cfb->cb_db.bd_info;
5946 if ( bi && bi->bi_tool_entry_close )
5947 return bi->bi_tool_entry_close( &cfb->cb_db );
5953 config_tool_entry_first( BackendDB *be )
5955 CfBackInfo *cfb = be->be_private;
5956 BackendInfo *bi = cfb->cb_db.bd_info;
5958 if ( bi && bi->bi_tool_entry_first )
5959 return bi->bi_tool_entry_first( &cfb->cb_db );
5965 config_tool_entry_next( BackendDB *be )
5967 CfBackInfo *cfb = be->be_private;
5968 BackendInfo *bi = cfb->cb_db.bd_info;
5970 if ( bi && bi->bi_tool_entry_next )
5971 return bi->bi_tool_entry_next( &cfb->cb_db );
5977 config_tool_entry_get( BackendDB *be, ID id )
5979 CfBackInfo *cfb = be->be_private;
5980 BackendInfo *bi = cfb->cb_db.bd_info;
5982 if ( bi && bi->bi_tool_entry_get )
5983 return bi->bi_tool_entry_get( &cfb->cb_db, id );
5988 static int entry_put_got_frontend=0;
5989 static int entry_put_got_config=0;
5991 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
5993 CfBackInfo *cfb = be->be_private;
5994 BackendInfo *bi = cfb->cb_db.bd_info;
5996 struct berval rdn, vals[ 2 ];
5998 OperationBuffer opbuf;
6000 Connection conn = {0};
6001 Operation *op = NULL;
6005 /* Create entry for frontend database if it does not exist already */
6006 if ( !entry_put_got_frontend ) {
6007 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
6008 STRLENOF( "olcDatabase" ))) {
6009 if ( strncmp( e->e_nname.bv_val +
6010 STRLENOF( "olcDatabase" ), "={-1}frontend",
6011 STRLENOF( "={-1}frontend" )) &&
6012 strncmp( e->e_nname.bv_val +
6013 STRLENOF( "olcDatabase" ), "=frontend",
6014 STRLENOF( "=frontend" ))) {
6016 vals[1].bv_val = NULL;
6017 memset( &ca, 0, sizeof(ConfigArgs));
6019 ca.bi = frontendDB->bd_info;
6020 ca.be->be_cf_ocs = &CFOC_FRONTEND;
6021 rdn.bv_val = ca.log;
6022 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
6023 "%s=" SLAP_X_ORDERED_FMT "%s",
6024 cfAd_database->ad_cname.bv_val, -1,
6026 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
6027 &CFOC_DATABASE, ca.be->be_cf_ocs );
6028 thrctx = ldap_pvt_thread_pool_context();
6029 connection_fake_init2( &conn, &opbuf, thrctx,0 );
6031 op->o_bd = &cfb->cb_db;
6032 op->o_tag = LDAP_REQ_ADD;
6034 op->o_dn = be->be_rootdn;
6035 op->o_ndn = be->be_rootndn;
6036 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
6037 if ( rc != LDAP_SUCCESS ) {
6038 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
6039 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
6043 if ( ce && bi && bi->bi_tool_entry_put &&
6044 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
6045 entry_put_got_frontend++;
6047 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
6048 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
6052 entry_put_got_frontend++;
6057 /* Create entry for config database if it does not exist already */
6058 if ( !entry_put_got_config && !isFrontend ) {
6059 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
6060 STRLENOF( "olcDatabase" ))) {
6061 if ( strncmp( e->e_nname.bv_val +
6062 STRLENOF( "olcDatabase" ), "={0}config",
6063 STRLENOF( "={0}config" )) &&
6064 strncmp( e->e_nname.bv_val +
6065 STRLENOF( "olcDatabase" ), "=config",
6066 STRLENOF( "=config" )) ) {
6068 vals[1].bv_val = NULL;
6069 memset( &ca, 0, sizeof(ConfigArgs));
6070 ca.be = LDAP_STAILQ_FIRST( &backendDB );
6071 ca.bi = ca.be->bd_info;
6072 rdn.bv_val = ca.log;
6073 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
6074 "%s=" SLAP_X_ORDERED_FMT "%s",
6075 cfAd_database->ad_cname.bv_val, 0,
6077 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
6080 thrctx = ldap_pvt_thread_pool_context();
6081 connection_fake_init2( &conn, &opbuf, thrctx,0 );
6083 op->o_bd = &cfb->cb_db;
6084 op->o_tag = LDAP_REQ_ADD;
6085 op->o_dn = be->be_rootdn;
6086 op->o_ndn = be->be_rootndn;
6089 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
6090 if ( rc != LDAP_SUCCESS ) {
6091 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
6092 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
6095 if (ce && bi && bi->bi_tool_entry_put &&
6096 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
6097 entry_put_got_config++;
6099 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
6100 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
6104 entry_put_got_config++;
6108 if ( bi && bi->bi_tool_entry_put &&
6109 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
6110 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
6117 AttributeDescription **desc;
6119 { "attribute", &cfAd_attr },
6120 { "backend", &cfAd_backend },
6121 { "database", &cfAd_database },
6122 { "include", &cfAd_include },
6123 { "objectclass", &cfAd_oc },
6124 { "objectidentifier", &cfAd_om },
6125 { "overlay", &cfAd_overlay },
6130 * add / delete: all types that may be added or deleted must use an
6131 * X-ORDERED attributeType for their RDN. Adding and deleting entries
6132 * should automatically renumber the index of any siblings as needed,
6133 * so that no gaps in the numbering sequence exist after the add/delete
6135 * What can be added:
6137 * backend objects for backend-specific config directives
6141 * delete: probably no support this time around.
6143 * modrdn: generally not done. Will be invoked automatically by add/
6144 * delete to update numbering sequence. Perform as an explicit operation
6145 * so that the renumbering effect may be replicated. Subtree rename must
6146 * be supported, since renumbering a database will affect all its child
6149 * modify: must be fully supported.
6153 config_back_initialize( BackendInfo *bi )
6155 ConfigTable *ct = config_back_cf_table;
6159 AttributeDescription *ad = NULL;
6161 static char *controls[] = {
6162 LDAP_CONTROL_MANAGEDSAIT,
6166 /* Make sure we don't exceed the bits reserved for userland */
6167 config_check_userland( CFG_LAST );
6169 bi->bi_controls = controls;
6174 bi->bi_destroy = config_back_destroy;
6176 bi->bi_db_init = config_back_db_init;
6177 bi->bi_db_config = 0;
6178 bi->bi_db_open = config_back_db_open;
6179 bi->bi_db_close = config_back_db_close;
6180 bi->bi_db_destroy = config_back_db_destroy;
6182 bi->bi_op_bind = config_back_bind;
6183 bi->bi_op_unbind = 0;
6184 bi->bi_op_search = config_back_search;
6185 bi->bi_op_compare = 0;
6186 bi->bi_op_modify = config_back_modify;
6187 bi->bi_op_modrdn = config_back_modrdn;
6188 bi->bi_op_add = config_back_add;
6189 bi->bi_op_delete = config_back_delete;
6190 bi->bi_op_abandon = 0;
6192 bi->bi_extended = 0;
6194 bi->bi_chk_referrals = 0;
6196 bi->bi_access_allowed = slap_access_allowed;
6198 bi->bi_connection_init = 0;
6199 bi->bi_connection_destroy = 0;
6201 bi->bi_entry_release_rw = config_entry_release;
6202 bi->bi_entry_get_rw = config_back_entry_get;
6204 bi->bi_tool_entry_open = config_tool_entry_open;
6205 bi->bi_tool_entry_close = config_tool_entry_close;
6206 bi->bi_tool_entry_first = config_tool_entry_first;
6207 bi->bi_tool_entry_next = config_tool_entry_next;
6208 bi->bi_tool_entry_get = config_tool_entry_get;
6209 bi->bi_tool_entry_put = config_tool_entry_put;
6212 argv[ 0 ] = "slapd";
6218 for (i=0; OidMacros[i].name; i++ ) {
6219 argv[1] = OidMacros[i].name;
6220 argv[2] = OidMacros[i].oid;
6221 parse_oidm( &ca, 0, NULL );
6224 bi->bi_cf_ocs = cf_ocs;
6226 i = config_register_schema( ct, cf_ocs );
6229 /* setup olcRootPW to be base64-encoded when written in LDIF form;
6230 * basically, we don't care if it fails */
6231 i = slap_str2ad( "olcRootPW", &ad, &text );
6233 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
6234 "warning, unable to get \"olcRootPW\" "
6235 "attribute description: %d: %s\n",
6238 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
6239 ad->ad_type->sat_oid );
6242 /* set up the notable AttributeDescriptions */
6244 for (;ct->name;ct++) {
6245 if (strcmp(ct->name, ads[i].name)) continue;
6246 *ads[i].desc = ct->ad;
6248 if (!ads[i].name) break;