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;
66 Syntax *c_syn_head, *c_syn_tail;
71 ConfigFile *cb_config;
73 BackendDB cb_db; /* underlying database */
78 static CfBackInfo cfBackInfo;
80 static char *passwd_salt;
82 static char *logfileName;
83 #ifdef SLAP_AUTH_REWRITE
84 static BerVarray authz_rewrites;
87 static struct berval cfdir;
90 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
91 *cfAd_include, *cfAd_attr, *cfAd_oc, *cfAd_om, *cfAd_syntax;
93 static ConfigFile *cfn;
95 static Avlnode *CfOcTree;
97 /* System schema state */
98 extern AttributeType *at_sys_tail; /* at.c */
99 extern ObjectClass *oc_sys_tail; /* oc.c */
100 extern OidMacro *om_sys_tail; /* oidm.c */
101 extern Syntax *syn_sys_tail; /* syntax.c */
102 static AttributeType *cf_at_tail;
103 static ObjectClass *cf_oc_tail;
104 static OidMacro *cf_om_tail;
105 static Syntax *cf_syn_tail;
107 static int config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca,
108 SlapReply *rs, int *renumber, Operation *op );
110 static int config_check_schema( Operation *op, CfBackInfo *cfb );
112 static ConfigDriver config_fname;
113 static ConfigDriver config_cfdir;
114 static ConfigDriver config_generic;
115 static ConfigDriver config_search_base;
116 static ConfigDriver config_passwd_hash;
117 static ConfigDriver config_schema_dn;
118 static ConfigDriver config_sizelimit;
119 static ConfigDriver config_timelimit;
120 static ConfigDriver config_overlay;
121 static ConfigDriver config_subordinate;
122 static ConfigDriver config_suffix;
123 static ConfigDriver config_rootdn;
124 static ConfigDriver config_rootpw;
125 static ConfigDriver config_restrict;
126 static ConfigDriver config_allows;
127 static ConfigDriver config_disallows;
128 static ConfigDriver config_requires;
129 static ConfigDriver config_security;
130 static ConfigDriver config_referral;
131 static ConfigDriver config_loglevel;
132 static ConfigDriver config_updatedn;
133 static ConfigDriver config_updateref;
134 static ConfigDriver config_include;
135 static ConfigDriver config_obsolete;
137 static ConfigDriver config_tls_option;
138 static ConfigDriver config_tls_config;
140 extern ConfigDriver syncrepl_config;
195 static OidRec OidMacros[] = {
196 /* OpenLDAProot:1.12.2 */
197 { "OLcfg", "1.3.6.1.4.1.4203.1.12.2" },
198 { "OLcfgAt", "OLcfg:3" },
199 { "OLcfgGlAt", "OLcfgAt:0" },
200 { "OLcfgBkAt", "OLcfgAt:1" },
201 { "OLcfgDbAt", "OLcfgAt:2" },
202 { "OLcfgOvAt", "OLcfgAt:3" },
203 { "OLcfgCtAt", "OLcfgAt:4" }, /* contrib modules */
204 { "OLcfgOc", "OLcfg:4" },
205 { "OLcfgGlOc", "OLcfgOc:0" },
206 { "OLcfgBkOc", "OLcfgOc:1" },
207 { "OLcfgDbOc", "OLcfgOc:2" },
208 { "OLcfgOvOc", "OLcfgOc:3" },
209 { "OLcfgCtOc", "OLcfgOc:4" }, /* contrib modules */
211 /* Syntaxes. We should just start using the standard names and
212 * document that they are predefined and available for users
213 * to reference in their own schema. Defining schema without
214 * OID macros is for masochists...
216 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
217 { "OMsBoolean", "OMsyn:7" },
218 { "OMsDN", "OMsyn:12" },
219 { "OMsDirectoryString", "OMsyn:15" },
220 { "OMsIA5String", "OMsyn:26" },
221 { "OMsInteger", "OMsyn:27" },
222 { "OMsOID", "OMsyn:38" },
223 { "OMsOctetString", "OMsyn:40" },
228 * Backend/Database registry
230 * OLcfg{Bk|Db}{Oc|At}:0 -> common
231 * OLcfg{Bk|Db}{Oc|At}:1 -> back-bdb(/back-hdb)
232 * OLcfg{Bk|Db}{Oc|At}:2 -> back-ldif
233 * OLcfg{Bk|Db}{Oc|At}:3 -> back-ldap
234 * OLcfg{Bk|Db}{Oc|At}:4 -> back-monitor
235 * OLcfg{Bk|Db}{Oc|At}:5 -> back-relay
236 * OLcfg{Bk|Db}{Oc|At}:6 -> back-sql
237 * OLcfg{Bk|Db}{Oc|At}:7 -> back-sock
243 * OLcfgOv{Oc|At}:1 -> syncprov
244 * OLcfgOv{Oc|At}:2 -> pcache
245 * OLcfgOv{Oc|At}:3 -> chain
246 * OLcfgOv{Oc|At}:4 -> accesslog
247 * OLcfgOv{Oc|At}:5 -> valsort
248 * OLcfgOv{Oc|At}:7 -> distproc
249 * OLcfgOv{Oc|At}:8 -> dynlist
250 * OLcfgOv{Oc|At}:9 -> dds
251 * OLcfgOv{Oc|At}:10 -> unique
252 * OLcfgOv{Oc|At}:11 -> refint
253 * OLcfgOv{Oc|At}:12 -> ppolicy
254 * OLcfgOv{Oc|At}:13 -> constraint
255 * OLcfgOv{Oc|At}:14 -> translucent
256 * OLcfgOv{Oc|At}:15 -> auditlog
257 * OLcfgOv{Oc|At}:16 -> rwm
258 * OLcfgOv{Oc|At}:17 -> dyngroup
259 * OLcfgOv{Oc|At}:18 -> memberof
260 * OLcfgOv{Oc|At}:19 -> collect
261 * OLcfgOv{Oc|At}:20 -> retcode
264 /* alphabetical ordering */
266 static ConfigTable config_back_cf_table[] = {
267 /* This attr is read-only */
268 { "", "", 0, 0, 0, ARG_MAGIC,
269 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
270 "DESC 'File for slapd configuration directives' "
271 "EQUALITY caseIgnoreMatch "
272 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
273 { "", "", 0, 0, 0, ARG_MAGIC,
274 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
275 "DESC 'Directory for slapd configuration backend' "
276 "EQUALITY caseIgnoreMatch "
277 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
278 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
279 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
280 "DESC 'Access Control List' "
281 "EQUALITY caseIgnoreMatch "
282 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
283 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
284 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
285 "DESC 'Allowed set of deprecated features' "
286 "EQUALITY caseIgnoreMatch "
287 "SYNTAX OMsDirectoryString )", NULL, NULL },
288 { "argsfile", "file", 2, 2, 0, ARG_STRING,
289 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
290 "DESC 'File for slapd command line options' "
291 "EQUALITY caseIgnoreMatch "
292 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
293 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
294 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
295 "EQUALITY caseIgnoreMatch "
296 "SYNTAX OMsDirectoryString )", NULL, NULL },
297 { "attribute", "attribute", 2, 0, STRLENOF( "attribute" ),
298 ARG_PAREN|ARG_MAGIC|CFG_ATTR,
299 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
300 "DESC 'OpenLDAP attributeTypes' "
301 "EQUALITY caseIgnoreMatch "
302 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
304 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
305 #ifdef SLAP_AUTH_REWRITE
306 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
310 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
311 "EQUALITY caseIgnoreMatch "
312 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
313 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
314 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
315 "EQUALITY caseIgnoreMatch "
316 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
317 { "authz-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
318 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
319 "EQUALITY caseIgnoreMatch "
320 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
321 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
322 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
323 "DESC 'A type of backend' "
324 "EQUALITY caseIgnoreMatch "
325 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
327 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
328 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
329 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
330 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
331 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
332 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
333 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
334 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
335 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
336 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
337 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
338 "DESC 'The backend type for a database instance' "
339 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
340 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
341 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
342 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
343 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
344 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
345 "EQUALITY caseIgnoreMatch "
346 "SYNTAX OMsDirectoryString )", NULL, NULL },
347 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
348 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
349 "DESC 'OpenLDAP DIT content rules' "
350 "EQUALITY caseIgnoreMatch "
351 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
353 { "gentlehup", "on|off", 2, 2, 0,
355 ARG_ON_OFF, &global_gentlehup,
359 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
360 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
361 { "hidden", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_HIDDEN,
362 &config_generic, "( OLcfgDbAt:0.17 NAME 'olcHidden' "
363 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
364 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
365 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
366 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
367 { "include", "file", 2, 2, 0, ARG_MAGIC,
368 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
369 "SUP labeledURI )", NULL, NULL },
370 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
371 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
372 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
373 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
374 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
375 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
376 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
377 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
378 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
379 { "index_substr_any_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
380 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
381 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
382 { "index_intlen", "len", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_IX_INTLEN,
383 &config_generic, "( OLcfgGlAt:84 NAME 'olcIndexIntLen' "
384 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
385 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
386 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
387 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
388 { "ldapsyntax", "syntax", 2, 0, 0,
389 ARG_PAREN|ARG_MAGIC|CFG_SYNTAX,
390 &config_generic, "( OLcfgGlAt:85 NAME 'olcLdapSyntaxes' "
391 "DESC 'OpenLDAP ldapSyntax' "
392 "EQUALITY caseIgnoreMatch "
393 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
395 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
396 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
397 "EQUALITY caseIgnoreMatch "
398 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
399 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
400 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
401 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
402 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
403 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
404 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
405 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
406 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
407 "EQUALITY caseIgnoreMatch "
408 "SYNTAX OMsDirectoryString )", NULL, NULL },
409 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
410 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
411 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
412 { "mirrormode", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_MIRRORMODE,
413 &config_generic, "( OLcfgDbAt:0.16 NAME 'olcMirrorMode' "
414 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
415 { "moduleload", "file", 2, 0, 0,
417 ARG_MAGIC|CFG_MODLOAD|ARG_NO_DELETE, &config_generic,
421 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
422 "EQUALITY caseIgnoreMatch "
423 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
424 { "modulepath", "path", 2, 2, 0,
426 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
430 "( OLcfgGlAt:31 NAME 'olcModulePath' "
431 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
432 { "monitoring", "TRUE|FALSE", 2, 2, 0,
433 ARG_MAGIC|CFG_MONITORING|ARG_DB|ARG_ON_OFF, &config_generic,
434 "( OLcfgDbAt:0.18 NAME 'olcMonitoring' "
435 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
436 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
437 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
438 "DESC 'OpenLDAP object classes' "
439 "EQUALITY caseIgnoreMatch "
440 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
442 { "objectidentifier", "name> <oid", 3, 3, 0, ARG_MAGIC|CFG_OID,
443 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
444 "EQUALITY caseIgnoreMatch "
445 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
446 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
447 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
448 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
449 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
450 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
451 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
452 { "password-hash", "hash", 2, 2, 0, ARG_MAGIC,
453 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
454 "EQUALITY caseIgnoreMatch "
455 "SYNTAX OMsDirectoryString )", NULL, NULL },
456 { "pidfile", "file", 2, 2, 0, ARG_STRING,
457 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
458 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
459 { "plugin", NULL, 0, 0, 0,
461 ARG_MAGIC|CFG_PLUGIN, &config_generic,
465 "( OLcfgGlAt:38 NAME 'olcPlugin' "
466 "EQUALITY caseIgnoreMatch "
467 "SYNTAX OMsDirectoryString )", NULL, NULL },
468 { "pluginlog", "filename", 2, 2, 0,
470 ARG_STRING, &slapi_log_file,
474 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
475 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
476 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
477 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
478 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
479 { "referral", "url", 2, 2, 0, ARG_MAGIC,
480 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
481 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
482 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
483 &config_obsolete, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
484 "EQUALITY caseIgnoreMatch "
485 "SUP labeledURI X-ORDERED 'VALUES' )", NULL, NULL },
486 { "replica-argsfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
487 &config_obsolete, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
488 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
489 { "replica-pidfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
490 &config_obsolete, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
491 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
492 { "replicationInterval", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
493 &config_obsolete, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
494 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
495 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC,
496 &config_obsolete, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
497 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
498 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
499 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
500 "EQUALITY caseIgnoreMatch "
501 "SYNTAX OMsDirectoryString )", NULL, NULL },
502 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
503 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
504 "EQUALITY caseIgnoreMatch "
505 "SYNTAX OMsDirectoryString )", NULL, NULL },
506 { "reverse-lookup", "on|off", 2, 2, 0,
507 #ifdef SLAPD_RLOOKUPS
508 ARG_ON_OFF, &use_reverse_lookup,
512 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
513 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
514 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
515 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
516 "EQUALITY distinguishedNameMatch "
517 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
518 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
519 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
520 "EQUALITY caseIgnoreMatch "
521 "SYNTAX OMsDirectoryString )", NULL, NULL },
522 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
523 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
524 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
525 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
526 &config_generic, NULL, NULL, NULL },
527 { "sasl-host", "host", 2, 2, 0,
528 #ifdef HAVE_CYRUS_SASL
529 ARG_STRING|ARG_UNIQUE, &sasl_host,
533 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
534 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
535 { "sasl-realm", "realm", 2, 2, 0,
536 #ifdef HAVE_CYRUS_SASL
537 ARG_STRING|ARG_UNIQUE, &global_realm,
541 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
542 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
543 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
544 &config_generic, NULL, NULL, NULL },
545 { "sasl-secprops", "properties", 2, 2, 0,
546 #ifdef HAVE_CYRUS_SASL
547 ARG_MAGIC|CFG_SASLSECP, &config_generic,
551 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
552 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
553 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
554 &config_generic, NULL, NULL, NULL },
555 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
556 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
557 "EQUALITY distinguishedNameMatch "
558 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
559 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
560 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
561 "EQUALITY caseIgnoreMatch "
562 "SYNTAX OMsDirectoryString )", NULL, NULL },
563 { "serverID", "number> <[URI]", 2, 3, 0, ARG_MAGIC|CFG_SERVERID,
564 &config_generic, "( OLcfgGlAt:81 NAME 'olcServerID' "
565 "EQUALITY caseIgnoreMatch "
566 "SYNTAX OMsDirectoryString )", NULL, NULL },
567 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
568 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
569 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
570 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
571 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
572 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
573 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
574 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
575 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
576 { "sortvals", "attr", 2, 0, 0, ARG_MAGIC|CFG_SORTVALS,
577 &config_generic, "( OLcfgGlAt:83 NAME 'olcSortVals' "
578 "DESC 'Attributes whose values will always be sorted' "
579 "EQUALITY caseIgnoreMatch "
580 "SYNTAX OMsDirectoryString )", NULL, NULL },
581 { "subordinate", "[advertise]", 1, 2, 0, ARG_DB|ARG_MAGIC,
582 &config_subordinate, "( OLcfgDbAt:0.15 NAME 'olcSubordinate' "
583 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
584 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
585 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
586 "EQUALITY distinguishedNameMatch "
587 "SYNTAX OMsDN )", NULL, NULL },
588 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
589 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
590 "EQUALITY caseIgnoreMatch "
591 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
592 { "threads", "count", 2, 2, 0,
596 ARG_INT|ARG_MAGIC|CFG_THREADS, &config_generic,
598 "( OLcfgGlAt:66 NAME 'olcThreads' "
599 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
600 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
601 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
602 "SYNTAX OMsDirectoryString )", NULL, NULL },
603 { "TLSCACertificateFile", NULL, 0, 0, 0,
605 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
609 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
610 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
611 { "TLSCACertificatePath", NULL, 0, 0, 0,
613 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
617 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
618 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
619 { "TLSCertificateFile", NULL, 0, 0, 0,
621 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
625 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
626 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
627 { "TLSCertificateKeyFile", NULL, 0, 0, 0,
629 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
633 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
634 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
635 { "TLSCipherSuite", NULL, 0, 0, 0,
637 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
641 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
642 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
643 { "TLSCRLCheck", NULL, 0, 0, 0,
644 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
645 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
649 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
650 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
651 { "TLSCRLFile", NULL, 0, 0, 0,
652 #if defined(HAVE_GNUTLS)
653 CFG_TLS_CRL_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
657 "( OLcfgGlAt:82 NAME 'olcTLSCRLFile' "
658 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
659 { "TLSRandFile", NULL, 0, 0, 0,
661 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
665 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
666 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
667 { "TLSVerifyClient", NULL, 0, 0, 0,
669 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
673 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
674 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
675 { "TLSDHParamFile", NULL, 0, 0, 0,
677 CFG_TLS_DH_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
681 "( OLcfgGlAt:77 NAME 'olcTLSDHParamFile' "
682 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
683 { "tool-threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_TTHREADS,
684 &config_generic, "( OLcfgGlAt:80 NAME 'olcToolThreads' "
685 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
686 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
687 NULL, NULL, NULL, NULL },
688 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
689 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
690 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
691 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
692 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
693 "EQUALITY caseIgnoreMatch "
694 "SUP labeledURI )", NULL, NULL },
695 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
696 NULL, NULL, NULL, NULL }
699 /* Need to no-op this keyword for dynamic config */
700 ConfigTable olcDatabaseDummy[] = {
701 { "", "", 0, 0, 0, ARG_IGNORED,
702 NULL, "( OLcfgGlAt:13 NAME 'olcDatabase' "
703 "DESC 'The backend type for a database instance' "
704 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
705 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
708 /* Routines to check if a child can be added to this type */
709 static ConfigLDAPadd cfAddSchema, cfAddInclude, cfAddDatabase,
710 cfAddBackend, cfAddModule, cfAddOverlay;
712 /* NOTE: be careful when defining array members
713 * that can be conditionally compiled */
714 #define CFOC_GLOBAL cf_ocs[1]
715 #define CFOC_SCHEMA cf_ocs[2]
716 #define CFOC_BACKEND cf_ocs[3]
717 #define CFOC_DATABASE cf_ocs[4]
718 #define CFOC_OVERLAY cf_ocs[5]
719 #define CFOC_INCLUDE cf_ocs[6]
720 #define CFOC_FRONTEND cf_ocs[7]
722 #define CFOC_MODULE cf_ocs[8]
723 #endif /* SLAPD_MODULES */
725 static ConfigOCs cf_ocs[] = {
728 "DESC 'OpenLDAP configuration object' "
729 "ABSTRACT SUP top )", Cft_Abstract, NULL },
732 "DESC 'OpenLDAP Global configuration options' "
733 "SUP olcConfig STRUCTURAL "
734 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
735 "olcAttributeOptions $ olcAuthIDRewrite $ "
736 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
737 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
738 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
739 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
740 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcIndexIntLen $ "
741 "olcLocalSSF $ olcLogFile $ olcLogLevel $ "
742 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
743 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
744 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
746 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
747 "olcSecurity $ olcServerID $ olcSizeLimit $ "
748 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ "
749 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
750 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
751 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
752 "olcTLSRandFile $ olcTLSVerifyClient $ olcTLSDHParamFile $ "
753 "olcTLSCRLFile $ olcToolThreads $ "
754 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
755 "olcDitContentRules $ olcLdapSyntaxes ) )", Cft_Global },
757 "NAME 'olcSchemaConfig' "
758 "DESC 'OpenLDAP schema object' "
759 "SUP olcConfig STRUCTURAL "
760 "MAY ( cn $ olcObjectIdentifier $ olcAttributeTypes $ "
761 "olcObjectClasses $ olcDitContentRules $ olcLdapSyntaxes ) )",
762 Cft_Schema, NULL, cfAddSchema },
764 "NAME 'olcBackendConfig' "
765 "DESC 'OpenLDAP Backend-specific options' "
766 "SUP olcConfig STRUCTURAL "
767 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
769 "NAME 'olcDatabaseConfig' "
770 "DESC 'OpenLDAP Database-specific options' "
771 "SUP olcConfig STRUCTURAL "
773 "MAY ( olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
774 "olcLastMod $ olcLimits $ "
775 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
776 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
777 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
778 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncrepl $ "
779 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef $ olcMirrorMode $ "
781 Cft_Database, NULL, cfAddDatabase },
783 "NAME 'olcOverlayConfig' "
784 "DESC 'OpenLDAP Overlay-specific options' "
785 "SUP olcConfig STRUCTURAL "
786 "MUST olcOverlay )", Cft_Overlay, NULL, cfAddOverlay },
788 "NAME 'olcIncludeFile' "
789 "DESC 'OpenLDAP configuration include file' "
790 "SUP olcConfig STRUCTURAL "
792 "MAY ( cn $ olcRootDSE ) )",
793 /* Used to be Cft_Include, that def has been removed */
794 Cft_Abstract, NULL, cfAddInclude },
795 /* This should be STRUCTURAL like all the other database classes, but
796 * that would mean inheriting all of the olcDatabaseConfig attributes,
797 * which causes them to be merged twice in config_build_entry.
800 "NAME 'olcFrontendConfig' "
801 "DESC 'OpenLDAP frontend configuration' "
803 "MAY ( olcDefaultSearchBase $ olcPasswordHash $ olcSortVals ) )",
804 Cft_Database, NULL, NULL },
807 "NAME 'olcModuleList' "
808 "DESC 'OpenLDAP dynamic module info' "
809 "SUP olcConfig STRUCTURAL "
810 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
811 Cft_Module, NULL, cfAddModule },
816 typedef struct ServerID {
817 struct ServerID *si_next;
818 struct berval si_url;
822 static ServerID *sid_list;
824 typedef struct voidList {
825 struct voidList *vl_next;
829 typedef struct ADlist {
830 struct ADlist *al_next;
831 AttributeDescription *al_desc;
834 static ADlist *sortVals;
837 config_generic(ConfigArgs *c) {
840 if ( c->op == SLAP_CONFIG_EMIT ) {
844 c->value_int = ldap_pvt_thread_get_concurrency();
847 c->value_int = connection_pool_max;
850 c->value_int = slap_tool_thread_max;
854 c->value_string = ch_strdup( passwd_salt );
859 if ( c->be->be_limits ) {
863 for ( i=0; c->be->be_limits[i]; i++ ) {
864 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
865 if ( bv.bv_len >= sizeof( buf ) ) {
866 ber_bvarray_free_x( c->rvalue_vals, NULL );
867 c->rvalue_vals = NULL;
871 bv.bv_val = buf + bv.bv_len;
872 limits_unparse( c->be->be_limits[i], &bv,
873 sizeof( buf ) - ( bv.bv_val - buf ) );
874 bv.bv_len += bv.bv_val - buf;
876 value_add_one( &c->rvalue_vals, &bv );
879 if ( !c->rvalue_vals ) rc = 1;
882 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_OP_WRITES) ==
883 SLAP_RESTRICT_OP_WRITES;
886 c->value_string = ch_strdup( slap_sasl_getpolicy());
889 slap_sasl_regexp_unparse( &c->rvalue_vals );
890 if ( !c->rvalue_vals ) rc = 1;
892 #ifdef HAVE_CYRUS_SASL
894 struct berval bv = BER_BVNULL;
895 slap_sasl_secprops_unparse( &bv );
896 if ( !BER_BVISNULL( &bv )) {
897 ber_bvarray_add( &c->rvalue_vals, &bv );
905 c->value_int = c->be->be_max_deref_depth;
908 if ( SLAP_DBHIDDEN( c->be )) {
915 ConfigFile *cf = c->ca_private;
917 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
918 else if ( cf->c_om_head )
919 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
921 if ( !c->rvalue_vals )
926 ad_unparse_options( &c->rvalue_vals );
929 ConfigFile *cf = c->ca_private;
931 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
932 else if ( cf->c_oc_head )
933 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
935 if ( !c->rvalue_vals )
940 ConfigFile *cf = c->ca_private;
942 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
943 else if ( cf->c_at_head )
944 at_unparse( &c->rvalue_vals, cf->c_at_head,
946 if ( !c->rvalue_vals )
951 ConfigFile *cf = c->ca_private;
953 syn_unparse( &c->rvalue_vals, NULL, NULL, 1 );
954 else if ( cf->c_syn_head )
955 syn_unparse( &c->rvalue_vals, cf->c_syn_head,
957 if ( !c->rvalue_vals )
962 ConfigFile *cf = c->ca_private;
964 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
965 else if ( cf->c_cr_head )
966 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
968 if ( !c->rvalue_vals )
975 char *src, *dst, ibuf[11];
976 struct berval bv, abv;
978 if ( c->be == frontendDB )
981 end = frontendDB->be_acl;
982 for (i=0, a=c->be->be_acl; a && a != end; i++,a=a->acl_next) {
983 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
984 if ( abv.bv_len >= sizeof( ibuf ) ) {
985 ber_bvarray_free_x( c->rvalue_vals, NULL );
986 c->rvalue_vals = NULL;
990 acl_unparse( a, &bv );
991 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
992 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
993 /* Turn TAB / EOL into plain space */
994 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
995 if (isspace((unsigned char)*src)) *dst++ = ' ';
999 if (dst[-1] == ' ') {
1003 abv.bv_len = dst - abv.bv_val;
1004 ber_bvarray_add( &c->rvalue_vals, &abv );
1010 ConfigFile *cf = c->ca_private;
1011 if ( cf->c_dseFiles ) {
1012 value_add( &c->rvalue_vals, cf->c_dseFiles );
1023 for ( si = sid_list; si; si=si->si_next ) {
1024 assert( si->si_num >= 0 && si->si_num <= SLAP_SYNC_SID_MAX );
1025 if ( !BER_BVISEMPTY( &si->si_url )) {
1026 bv.bv_len = si->si_url.bv_len + 6;
1027 bv.bv_val = ch_malloc( bv.bv_len );
1028 sprintf( bv.bv_val, "%d %s", si->si_num,
1029 si->si_url.bv_val );
1030 ber_bvarray_add( &c->rvalue_vals, &bv );
1034 bv.bv_len = sprintf( buf, "%d", si->si_num );
1035 value_add_one( &c->rvalue_vals, &bv );
1044 c->value_string = ch_strdup( logfileName );
1049 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1051 case CFG_MIRRORMODE:
1052 if ( SLAP_SHADOW(c->be))
1053 c->value_int = (SLAP_SINGLE_SHADOW(c->be) == 0);
1057 case CFG_MONITORING:
1058 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
1060 case CFG_SSTR_IF_MAX:
1061 c->value_int = index_substr_if_maxlen;
1063 case CFG_SSTR_IF_MIN:
1064 c->value_int = index_substr_if_minlen;
1067 c->value_int = index_intlen;
1069 case CFG_SORTVALS: {
1072 for ( sv = sortVals; sv; sv = sv->al_next ) {
1073 value_add_one( &c->rvalue_vals, &sv->al_desc->ad_cname );
1077 #ifdef SLAPD_MODULES
1079 ModPaths *mp = c->ca_private;
1082 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
1085 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
1086 SLAP_X_ORDERED_FMT "%s", i,
1087 mp->mp_loads[i].bv_val );
1088 if ( bv.bv_len >= sizeof( c->log ) ) {
1089 ber_bvarray_free_x( c->rvalue_vals, NULL );
1090 c->rvalue_vals = NULL;
1093 value_add_one( &c->rvalue_vals, &bv );
1097 rc = c->rvalue_vals ? 0 : 1;
1101 ModPaths *mp = c->ca_private;
1102 if ( !BER_BVISNULL( &mp->mp_path ))
1103 value_add_one( &c->rvalue_vals, &mp->mp_path );
1105 rc = c->rvalue_vals ? 0 : 1;
1111 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1112 if ( !c->rvalue_vals ) rc = 1;
1115 #ifdef SLAP_AUTH_REWRITE
1117 if ( authz_rewrites ) {
1118 struct berval bv, idx;
1123 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1124 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1125 if ( idx.bv_len >= sizeof( ibuf ) ) {
1126 ber_bvarray_free_x( c->rvalue_vals, NULL );
1127 c->rvalue_vals = NULL;
1130 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1131 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1132 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1133 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1134 authz_rewrites[i].bv_val,
1135 authz_rewrites[i].bv_len + 1 );
1136 ber_bvarray_add( &c->rvalue_vals, &bv );
1139 if ( !c->rvalue_vals ) rc = 1;
1146 } else if ( c->op == LDAP_MOD_DELETE ) {
1149 /* single-valued attrs, no-ops */
1157 case CFG_MIRRORMODE:
1158 case CFG_MONITORING:
1160 case CFG_SSTR_IF_MAX:
1161 case CFG_SSTR_IF_MIN:
1164 /* no-ops, requires slapd restart */
1169 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1173 ch_free( passwd_salt );
1178 ch_free( logfileName );
1186 case CFG_SERVERID: {
1187 ServerID *si, **sip;
1189 for ( i=0, si = sid_list, sip = &sid_list;
1190 si; si = *sip, i++ ) {
1191 if ( c->valx == -1 || i == c->valx ) {
1203 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1207 index_intlen = SLAP_INDEX_INTLEN_DEFAULT;
1208 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1209 SLAP_INDEX_INTLEN_DEFAULT );
1213 if ( c->valx < 0 ) {
1215 if ( c->be == frontendDB )
1218 end = frontendDB->be_acl;
1219 acl_destroy( c->be->be_acl, end );
1220 c->be->be_acl = end;
1223 AccessControl **prev, *a;
1225 for (i=0, prev = &c->be->be_acl; i < c->valx;
1228 prev = &a->acl_next;
1231 *prev = a->acl_next;
1238 /* Can be NULL when undoing a failed add */
1239 if ( c->ca_entry ) {
1240 ce = c->ca_entry->e_private;
1241 /* can't modify the hardcoded schema */
1242 if ( ce->ce_parent->ce_type == Cft_Global )
1246 cfn = c->ca_private;
1247 if ( c->valx < 0 ) {
1250 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1252 if ( oc == cfn->c_oc_tail )
1255 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1257 ObjectClass *oc, *prev = NULL;
1259 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1264 if ( cfn->c_oc_tail == oc ) {
1265 cfn->c_oc_tail = prev;
1267 if ( cfn->c_oc_head == oc ) {
1269 cfn->c_oc_head = oc;
1276 /* Can be NULL when undoing a failed add */
1277 if ( c->ca_entry ) {
1278 ce = c->ca_entry->e_private;
1279 /* can't modify the hardcoded schema */
1280 if ( ce->ce_parent->ce_type == Cft_Global )
1284 cfn = c->ca_private;
1285 if ( c->valx < 0 ) {
1288 for( at = cfn->c_at_head; at; at_next( &at )) {
1290 if ( at == cfn->c_at_tail )
1293 cfn->c_at_head = cfn->c_at_tail = NULL;
1295 AttributeType *at, *prev = NULL;
1297 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1302 if ( cfn->c_at_tail == at ) {
1303 cfn->c_at_tail = prev;
1305 if ( cfn->c_at_head == at ) {
1307 cfn->c_at_head = at;
1314 /* Can be NULL when undoing a failed add */
1315 if ( c->ca_entry ) {
1316 ce = c->ca_entry->e_private;
1317 /* can't modify the hardcoded schema */
1318 if ( ce->ce_parent->ce_type == Cft_Global )
1322 cfn = c->ca_private;
1323 if ( c->valx < 0 ) {
1326 for( syn = cfn->c_syn_head; syn; syn_next( &syn )) {
1328 if ( syn == cfn->c_syn_tail )
1331 cfn->c_syn_head = cfn->c_syn_tail = NULL;
1333 Syntax *syn, *prev = NULL;
1335 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++) {
1340 if ( cfn->c_syn_tail == syn ) {
1341 cfn->c_syn_tail = prev;
1343 if ( cfn->c_syn_head == syn ) {
1345 cfn->c_syn_head = syn;
1350 if ( c->valx < 0 ) {
1352 for ( sv = sortVals; sv; sv = sortVals ) {
1353 sortVals = sv->al_next;
1354 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1361 for ( prev = &sortVals, sv = sortVals; i < c->valx; i++ ) {
1362 prev = &sv->al_next;
1365 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1366 *prev = sv->al_next;
1372 /* FIXME: there is no limits_free function */
1374 /* FIXME: there is no ad_option_free function */
1376 /* FIXME: there is no way to remove attributes added by
1390 if(!(c->bi = backend_info(c->argv[1]))) {
1391 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1392 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1393 c->log, c->cr_msg, c->argv[1] );
1400 /* NOTE: config is always the first backend!
1402 if ( !strcasecmp( c->argv[1], "config" )) {
1403 c->be = LDAP_STAILQ_FIRST(&backendDB);
1404 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1407 c->be = backend_db_init(c->argv[1], NULL, c->valx, &c->reply);
1409 if ( c->cr_msg[0] == 0 )
1410 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1411 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n", c->log, c->cr_msg, c->argv[1] );
1418 ldap_pvt_thread_set_concurrency(c->value_int);
1422 if ( c->value_int < 2 ) {
1423 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1424 "threads=%d smaller than minimum value 2",
1426 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1427 c->log, c->cr_msg, 0 );
1430 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1431 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1432 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1433 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1434 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1435 c->log, c->cr_msg, 0 );
1437 if ( slapMode & SLAP_SERVER_MODE )
1438 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1439 connection_pool_max = c->value_int; /* save for reference */
1443 if ( slapMode & SLAP_TOOL_MODE )
1444 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1445 slap_tool_thread_max = c->value_int; /* save for reference */
1449 if ( passwd_salt ) ch_free( passwd_salt );
1450 passwd_salt = c->value_string;
1451 lutil_salt_format(passwd_salt);
1455 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1461 c->be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1463 c->be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1467 ch_free(c->value_string);
1468 if (slap_sasl_setpolicy( c->argv[1] )) {
1469 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
1470 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1471 c->log, c->cr_msg, c->argv[1] );
1477 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1481 #ifdef HAVE_CYRUS_SASL
1484 char *txt = slap_sasl_secprops( c->argv[1] );
1486 snprintf( c->cr_msg, sizeof(c->cr_msg), "<%s> %s",
1488 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0 );
1496 c->be->be_max_deref_depth = c->value_int;
1502 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1503 cfn = c->ca_private;
1504 if(parse_oidm(c, 1, &om))
1506 if (!cfn->c_om_head) cfn->c_om_head = om;
1507 cfn->c_om_tail = om;
1512 ObjectClass *oc, *prev;
1514 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1515 cfn = c->ca_private;
1516 if ( c->valx < 0 ) {
1517 prev = cfn->c_oc_tail;
1520 /* If adding anything after the first, prev is easy */
1523 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
1528 /* If adding the first, and head exists, find its prev */
1529 if (cfn->c_oc_head) {
1530 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
1535 /* else prev is NULL, append to end of global list */
1537 if(parse_oc(c, &oc, prev)) return(1);
1538 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1539 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
1544 AttributeType *at, *prev;
1546 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1547 cfn = c->ca_private;
1548 if ( c->valx < 0 ) {
1549 prev = cfn->c_at_tail;
1552 /* If adding anything after the first, prev is easy */
1555 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
1560 /* If adding the first, and head exists, find its prev */
1561 if (cfn->c_at_head) {
1562 for ( at_start( &at ); at != cfn->c_at_head; ) {
1567 /* else prev is NULL, append to end of global list */
1569 if(parse_at(c, &at, prev)) return(1);
1570 if (!cfn->c_at_head) cfn->c_at_head = at;
1571 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
1578 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1579 cfn = c->ca_private;
1580 if ( c->valx < 0 ) {
1581 prev = cfn->c_syn_tail;
1584 /* If adding anything after the first, prev is easy */
1587 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++ ) {
1592 /* If adding the first, and head exists, find its prev */
1593 if (cfn->c_syn_head) {
1594 for ( syn_start( &syn ); syn != cfn->c_syn_head; ) {
1599 /* else prev is NULL, append to end of global list */
1601 if ( parse_syn( c, &syn, prev ) ) return(1);
1602 if ( !cfn->c_syn_head ) cfn->c_syn_head = syn;
1603 if ( cfn->c_syn_tail == prev ) cfn->c_syn_tail = syn;
1610 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1611 cfn = c->ca_private;
1612 if(parse_cr(c, &cr)) return(1);
1613 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1614 cfn->c_cr_tail = cr;
1619 ad_define_option(NULL, NULL, 0);
1620 for(i = 1; i < c->argc; i++)
1621 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1626 if ( c->value_int < SLAP_INDEX_INTLEN_DEFAULT )
1627 c->value_int = SLAP_INDEX_INTLEN_DEFAULT;
1628 else if ( c->value_int > 255 )
1630 index_intlen = c->value_int;
1631 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1635 case CFG_SORTVALS: {
1636 ADlist *svnew = NULL, *svtail, *sv;
1638 for ( i = 1; i < c->argc; i++ ) {
1639 AttributeDescription *ad = NULL;
1643 rc = slap_str2ad( c->argv[i], &ad, &text );
1645 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown attribute type #%d",
1648 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1649 c->log, c->cr_msg, c->argv[i] );
1650 for ( sv = svnew; sv; sv = svnew ) {
1651 svnew = sv->al_next;
1656 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) ||
1657 ad->ad_type->sat_single_value ) {
1658 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> inappropriate attribute type #%d",
1660 goto sortval_reject;
1662 sv = ch_malloc( sizeof( ADlist ));
1667 svtail->al_next = sv;
1672 for ( sv = svnew; sv; sv = sv->al_next )
1673 sv->al_desc->ad_type->sat_flags |= SLAP_AT_SORTED_VAL;
1674 for ( sv = sortVals; sv && sv->al_next; sv = sv->al_next );
1676 sv->al_next = svnew;
1683 /* Don't append to the global ACL if we're on a specific DB */
1685 if ( c->be != frontendDB && frontendDB->be_acl && c->valx == -1 ) {
1688 for ( a=c->be->be_acl; a && a != frontendDB->be_acl;
1692 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
1698 if(root_dse_read_file(c->argv[1])) {
1699 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> could not read file", c->argv[0] );
1700 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1701 c->log, c->cr_msg, c->argv[1] );
1706 ber_str2bv( c->argv[1], 0, 1, &bv );
1707 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1708 cfn = c->ca_private;
1709 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1715 ServerID *si, **sip;
1718 if ( lutil_atoi( &num, c->argv[1] ) ||
1719 num < 0 || num > SLAP_SYNC_SID_MAX )
1721 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1722 "<%s> illegal server ID", c->argv[0] );
1723 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1724 c->log, c->cr_msg, c->argv[1] );
1727 /* only one value allowed if no URL is given */
1728 if ( c->argc > 2 ) {
1731 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
1732 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1733 "<%s> only one server ID allowed now", c->argv[0] );
1734 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1735 c->log, c->cr_msg, c->argv[1] );
1739 if ( ldap_url_parse( c->argv[2], &lud )) {
1740 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1741 "<%s> invalid URL", c->argv[0] );
1742 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1743 c->log, c->cr_msg, c->argv[2] );
1746 len = strlen( c->argv[2] );
1747 si = ch_malloc( sizeof(ServerID) + len + 1 );
1748 si->si_url.bv_val = (char *)(si+1);
1749 si->si_url.bv_len = len;
1750 strcpy( si->si_url.bv_val, c->argv[2] );
1753 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1754 "<%s> unqualified server ID not allowed now", c->argv[0] );
1755 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1756 c->log, c->cr_msg, c->argv[1] );
1759 si = ch_malloc( sizeof(ServerID) );
1760 BER_BVZERO( &si->si_url );
1761 slap_serverID = num;
1762 Debug( LDAP_DEBUG_CONFIG,
1764 c->log, slap_serverID, 0 );
1768 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
1771 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
1772 /* If hostname is empty, or is localhost, or matches
1773 * our hostname, this serverID refers to this host.
1774 * Compare it against listeners and ports.
1776 if ( !lud->lud_host || !lud->lud_host[0] ||
1777 !strncasecmp("localhost", lud->lud_host,
1778 STRLENOF("localhost")) ||
1779 !strcasecmp( global_host, lud->lud_host )) {
1780 Listener **l = slapd_get_listeners();
1783 for ( i=0; l && l[i]; i++ ) {
1786 ldap_url_parse( l[i]->sl_url.bv_val, &lu2 );
1788 if ( strcasecmp( lud->lud_scheme,
1791 if ( lud->lud_port != lu2->lud_port )
1793 /* Listener on ANY address */
1794 if ( !lu2->lud_host || !lu2->lud_host[0] ) {
1798 /* URL on ANY address */
1799 if ( !lud->lud_host || !lud->lud_host[0] ) {
1803 /* Listener has specific host, must
1806 if ( !strcasecmp( lud->lud_host,
1812 ldap_free_urldesc( lu2 );
1814 slap_serverID = si->si_num;
1815 Debug( LDAP_DEBUG_CONFIG,
1816 "%s: SID=%d (listener=%s)\n",
1817 c->log, slap_serverID,
1818 l[i]->sl_url.bv_val );
1825 ldap_free_urldesc( lud );
1829 if ( logfileName ) ch_free( logfileName );
1830 logfileName = c->value_string;
1831 logfile = fopen(logfileName, "w");
1832 if(logfile) lutil_debug_file(logfile);
1836 if(SLAP_NOLASTMODCMD(c->be)) {
1837 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> not available for %s database",
1838 c->argv[0], c->be->bd_info->bi_type );
1839 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1840 c->log, c->cr_msg, 0 );
1844 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1846 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1849 case CFG_MIRRORMODE:
1850 if(!SLAP_SHADOW(c->be)) {
1851 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database is not a shadow",
1853 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1854 c->log, c->cr_msg, 0 );
1858 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
1860 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1863 case CFG_MONITORING:
1865 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
1867 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
1872 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
1874 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
1877 case CFG_SSTR_IF_MAX:
1878 if (c->value_int < index_substr_if_minlen) {
1879 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1880 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1881 c->log, c->cr_msg, c->value_int );
1884 index_substr_if_maxlen = c->value_int;
1887 case CFG_SSTR_IF_MIN:
1888 if (c->value_int > index_substr_if_maxlen) {
1889 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1890 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1891 c->log, c->cr_msg, c->value_int );
1894 index_substr_if_minlen = c->value_int;
1897 #ifdef SLAPD_MODULES
1899 /* If we're just adding a module on an existing modpath,
1900 * make sure we've selected the current path.
1902 if ( c->op == LDAP_MOD_ADD && c->ca_private && modcur != c->ca_private ) {
1903 modcur = c->ca_private;
1904 /* This should never fail */
1905 if ( module_path( modcur->mp_path.bv_val )) {
1906 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> module path no longer valid",
1908 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1909 c->log, c->cr_msg, modcur->mp_path.bv_val );
1913 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1915 /* Record this load on the current path */
1919 if ( c->op == SLAP_CONFIG_ADD ) {
1920 ptr = c->line + STRLENOF("moduleload");
1921 while (!isspace((unsigned char) *ptr)) ptr++;
1922 while (isspace((unsigned char) *ptr)) ptr++;
1926 ber_str2bv(ptr, 0, 1, &bv);
1927 ber_bvarray_add( &modcur->mp_loads, &bv );
1929 /* Check for any new hardcoded schema */
1930 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
1931 config_check_schema( NULL, &cfBackInfo );
1936 if(module_path(c->argv[1])) return(1);
1937 /* Record which path was used with each module */
1941 if (!modpaths.mp_loads) {
1944 mp = ch_malloc( sizeof( ModPaths ));
1945 modlast->mp_next = mp;
1947 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1949 mp->mp_loads = NULL;
1960 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
1962 slapi_plugins_used++;
1966 #ifdef SLAP_AUTH_REWRITE
1971 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
1974 if ( c->argc > 1 ) {
1977 /* quote all args but the first */
1978 line = ldap_charray2str( c->argv, "\" \"" );
1979 ber_str2bv( line, 0, 0, &bv );
1980 s = ber_bvchr( &bv, '"' );
1981 assert( s != NULL );
1982 /* move the trailing quote of argv[0] to the end */
1983 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
1984 bv.bv_val[ bv.bv_len - 1 ] = '"';
1987 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
1990 ber_bvarray_add( &authz_rewrites, &bv );
1997 Debug( LDAP_DEBUG_ANY,
1998 "%s: unknown CFG_TYPE %d.\n",
1999 c->log, c->type, 0 );
2008 config_fname(ConfigArgs *c) {
2009 if(c->op == SLAP_CONFIG_EMIT) {
2010 if (c->ca_private) {
2011 ConfigFile *cf = c->ca_private;
2012 value_add_one( &c->rvalue_vals, &cf->c_file );
2021 config_cfdir(ConfigArgs *c) {
2022 if(c->op == SLAP_CONFIG_EMIT) {
2023 if ( !BER_BVISEMPTY( &cfdir )) {
2024 value_add_one( &c->rvalue_vals, &cfdir );
2033 config_search_base(ConfigArgs *c) {
2034 if(c->op == SLAP_CONFIG_EMIT) {
2036 if (!BER_BVISEMPTY(&default_search_base)) {
2037 value_add_one(&c->rvalue_vals, &default_search_base);
2038 value_add_one(&c->rvalue_nvals, &default_search_nbase);
2042 } else if( c->op == LDAP_MOD_DELETE ) {
2043 ch_free( default_search_base.bv_val );
2044 ch_free( default_search_nbase.bv_val );
2045 BER_BVZERO( &default_search_base );
2046 BER_BVZERO( &default_search_nbase );
2050 if(c->bi || c->be != frontendDB) {
2051 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
2052 "prior to any backend or database definition\n",
2057 if(default_search_nbase.bv_len) {
2058 free(default_search_base.bv_val);
2059 free(default_search_nbase.bv_val);
2062 default_search_base = c->value_dn;
2063 default_search_nbase = c->value_ndn;
2067 /* For RE23 compatibility we allow this in the global entry
2068 * but we now defer it to the frontend entry to allow modules
2069 * to load new hash types.
2072 config_passwd_hash(ConfigArgs *c) {
2074 if (c->op == SLAP_CONFIG_EMIT) {
2076 /* Don't generate it in the global entry */
2077 if ( c->table == Cft_Global )
2079 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
2080 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
2081 value_add_one(&c->rvalue_vals, &bv);
2084 } else if ( c->op == LDAP_MOD_DELETE ) {
2085 /* Deleting from global is a no-op, only the frontendDB entry matters */
2086 if ( c->table == Cft_Global )
2088 if ( c->valx < 0 ) {
2089 ldap_charray_free( default_passwd_hash );
2090 default_passwd_hash = NULL;
2093 ch_free( default_passwd_hash[i] );
2094 for (; default_passwd_hash[i]; i++ )
2095 default_passwd_hash[i] = default_passwd_hash[i+1];
2099 for(i = 1; i < c->argc; i++) {
2100 if(!lutil_passwd_scheme(c->argv[i])) {
2101 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> scheme not available", c->argv[0] );
2102 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2103 c->log, c->cr_msg, c->argv[i]);
2105 ldap_charray_add(&default_passwd_hash, c->argv[i]);
2108 if(!default_passwd_hash) {
2109 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> no valid hashes found", c->argv[0] );
2110 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2111 c->log, c->cr_msg, 0 );
2118 config_schema_dn(ConfigArgs *c) {
2119 if ( c->op == SLAP_CONFIG_EMIT ) {
2121 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
2122 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
2123 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
2127 } else if ( c->op == LDAP_MOD_DELETE ) {
2128 ch_free( c->be->be_schemadn.bv_val );
2129 ch_free( c->be->be_schemandn.bv_val );
2130 BER_BVZERO( &c->be->be_schemadn );
2131 BER_BVZERO( &c->be->be_schemandn );
2134 ch_free( c->be->be_schemadn.bv_val );
2135 ch_free( c->be->be_schemandn.bv_val );
2136 c->be->be_schemadn = c->value_dn;
2137 c->be->be_schemandn = c->value_ndn;
2142 config_sizelimit(ConfigArgs *c) {
2144 struct slap_limits_set *lim = &c->be->be_def_limit;
2145 if (c->op == SLAP_CONFIG_EMIT) {
2150 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
2151 if ( !BER_BVISEMPTY( &bv ))
2152 value_add_one( &c->rvalue_vals, &bv );
2156 } else if ( c->op == LDAP_MOD_DELETE ) {
2157 /* Reset to defaults */
2158 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
2159 lim->lms_s_hard = 0;
2160 lim->lms_s_unchecked = -1;
2162 lim->lms_s_pr_hide = 0;
2163 lim->lms_s_pr_total = 0;
2166 for(i = 1; i < c->argc; i++) {
2167 if(!strncasecmp(c->argv[i], "size", 4)) {
2168 rc = limits_parse_one(c->argv[i], lim);
2170 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2171 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2172 c->log, c->cr_msg, c->argv[i]);
2176 if(!strcasecmp(c->argv[i], "unlimited")) {
2177 lim->lms_s_soft = -1;
2179 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
2180 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2181 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2182 c->log, c->cr_msg, c->argv[i]);
2186 lim->lms_s_hard = 0;
2193 config_timelimit(ConfigArgs *c) {
2195 struct slap_limits_set *lim = &c->be->be_def_limit;
2196 if (c->op == SLAP_CONFIG_EMIT) {
2201 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
2202 if ( !BER_BVISEMPTY( &bv ))
2203 value_add_one( &c->rvalue_vals, &bv );
2207 } else if ( c->op == LDAP_MOD_DELETE ) {
2208 /* Reset to defaults */
2209 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
2210 lim->lms_t_hard = 0;
2213 for(i = 1; i < c->argc; i++) {
2214 if(!strncasecmp(c->argv[i], "time", 4)) {
2215 rc = limits_parse_one(c->argv[i], lim);
2217 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2218 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2219 c->log, c->cr_msg, c->argv[i]);
2223 if(!strcasecmp(c->argv[i], "unlimited")) {
2224 lim->lms_t_soft = -1;
2226 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
2227 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2228 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2229 c->log, c->cr_msg, c->argv[i]);
2233 lim->lms_t_hard = 0;
2240 config_overlay(ConfigArgs *c) {
2241 if (c->op == SLAP_CONFIG_EMIT) {
2243 } else if ( c->op == LDAP_MOD_DELETE ) {
2246 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2247 c->valx, &c->bi, &c->reply)) {
2249 Debug( LDAP_DEBUG_ANY,
2250 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2251 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2253 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi, &c->reply)) {
2260 config_subordinate(ConfigArgs *c)
2266 case SLAP_CONFIG_EMIT:
2267 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2270 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2271 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2274 value_add_one( &c->rvalue_vals, &bv );
2278 case LDAP_MOD_DELETE:
2279 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2280 glue_sub_del( c->be );
2282 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2287 case SLAP_CONFIG_ADD:
2288 advertise = ( c->argc == 2 && !strcasecmp( c->argv[1], "advertise" ));
2289 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2296 config_suffix(ConfigArgs *c)
2299 struct berval pdn, ndn;
2300 char *notallowed = NULL;
2302 if ( c->be == frontendDB ) {
2303 notallowed = "frontend";
2305 } else if ( SLAP_MONITOR(c->be) ) {
2306 notallowed = "monitor";
2308 } else if ( SLAP_CONFIG(c->be) ) {
2309 notallowed = "config";
2312 if ( notallowed != NULL ) {
2313 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
2317 case LDAP_MOD_DELETE:
2318 case LDAP_MOD_REPLACE:
2319 case LDAP_MOD_INCREMENT:
2320 case SLAP_CONFIG_ADD:
2321 if ( !BER_BVISNULL( &c->value_dn ) ) {
2322 snprintf( buf, sizeof( buf ), "<%s> ",
2323 c->value_dn.bv_val );
2326 Debug(LDAP_DEBUG_ANY,
2327 "%s: suffix %snot allowed in %s database.\n",
2328 c->log, buf, notallowed );
2331 case SLAP_CONFIG_EMIT:
2332 /* don't complain when emitting... */
2336 /* FIXME: don't know what values may be valid;
2337 * please remove assertion, or add legal values
2338 * to either block */
2346 if (c->op == SLAP_CONFIG_EMIT) {
2347 if ( c->be->be_suffix == NULL
2348 || BER_BVISNULL( &c->be->be_suffix[0] ) )
2352 value_add( &c->rvalue_vals, c->be->be_suffix );
2353 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
2356 } else if ( c->op == LDAP_MOD_DELETE ) {
2357 if ( c->valx < 0 ) {
2358 ber_bvarray_free( c->be->be_suffix );
2359 ber_bvarray_free( c->be->be_nsuffix );
2360 c->be->be_suffix = NULL;
2361 c->be->be_nsuffix = NULL;
2364 ch_free( c->be->be_suffix[i].bv_val );
2365 ch_free( c->be->be_nsuffix[i].bv_val );
2367 c->be->be_suffix[i] = c->be->be_suffix[i+1];
2368 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
2370 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
2375 #ifdef SLAPD_MONITOR_DN
2376 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
2377 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> DN is reserved for monitoring slapd",
2379 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2380 c->log, c->cr_msg, SLAPD_MONITOR_DN);
2385 if (SLAP_DB_ONE_SUFFIX( c->be ) && c->be->be_suffix ) {
2386 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> Only one suffix is allowed on this %s backend",
2387 c->argv[0], c->be->bd_info->bi_type );
2388 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2389 c->log, c->cr_msg, 0);
2396 if (SLAP_DBHIDDEN( c->be ))
2399 tbe = select_backend(&ndn, 0);
2401 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
2407 BackendDB *b2 = tbe;
2409 /* Does tbe precede be? */
2410 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
2413 char *type = tbe->bd_info->bi_type;
2415 if ( overlay_is_over( tbe ) ) {
2416 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
2417 type = oi->oi_orig->bi_type;
2420 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> namingContext \"%s\" "
2421 "already served by a preceding %s database",
2422 c->argv[0], pdn.bv_val, type );
2423 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
2424 c->log, c->cr_msg, tbe->be_suffix[0].bv_val);
2430 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
2431 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
2432 "base provided \"%s\" (assuming okay)\n",
2433 c->log, default_search_base.bv_val, 0);
2435 ber_bvarray_add(&c->be->be_suffix, &pdn);
2436 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
2441 config_rootdn(ConfigArgs *c) {
2442 if (c->op == SLAP_CONFIG_EMIT) {
2443 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2444 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
2445 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
2450 } else if ( c->op == LDAP_MOD_DELETE ) {
2451 ch_free( c->be->be_rootdn.bv_val );
2452 ch_free( c->be->be_rootndn.bv_val );
2453 BER_BVZERO( &c->be->be_rootdn );
2454 BER_BVZERO( &c->be->be_rootndn );
2457 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2458 ch_free( c->be->be_rootdn.bv_val );
2459 ch_free( c->be->be_rootndn.bv_val );
2461 c->be->be_rootdn = c->value_dn;
2462 c->be->be_rootndn = c->value_ndn;
2467 config_rootpw(ConfigArgs *c) {
2470 if (c->op == SLAP_CONFIG_EMIT) {
2471 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
2472 /* don't copy, because "rootpw" is marked
2474 c->value_bv = c->be->be_rootpw;
2478 } else if ( c->op == LDAP_MOD_DELETE ) {
2479 ch_free( c->be->be_rootpw.bv_val );
2480 BER_BVZERO( &c->be->be_rootpw );
2484 tbe = select_backend(&c->be->be_rootndn, 0);
2486 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> can only be set when rootdn is under suffix",
2488 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2489 c->log, c->cr_msg, 0);
2492 if ( !BER_BVISNULL( &c->be->be_rootpw ))
2493 ch_free( c->be->be_rootpw.bv_val );
2494 c->be->be_rootpw = c->value_bv;
2499 config_restrict(ConfigArgs *c) {
2500 slap_mask_t restrictops = 0;
2502 slap_verbmasks restrictable_ops[] = {
2503 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
2504 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
2505 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
2506 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
2507 { BER_BVC("modrdn"), 0 },
2508 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
2509 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
2510 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
2511 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
2512 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
2513 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
2514 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
2515 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
2516 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
2517 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
2518 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
2522 if (c->op == SLAP_CONFIG_EMIT) {
2523 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
2525 } else if ( c->op == LDAP_MOD_DELETE ) {
2527 c->be->be_restrictops = 0;
2529 restrictops = verb_to_mask( c->line, restrictable_ops );
2530 c->be->be_restrictops ^= restrictops;
2534 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
2536 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown operation", c->argv[0] );
2537 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2538 c->log, c->cr_msg, c->argv[i]);
2541 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
2542 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
2543 c->be->be_restrictops |= restrictops;
2548 config_allows(ConfigArgs *c) {
2549 slap_mask_t allows = 0;
2551 slap_verbmasks allowable_ops[] = {
2552 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
2553 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
2554 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
2555 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
2556 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
2559 if (c->op == SLAP_CONFIG_EMIT) {
2560 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
2561 } else if ( c->op == LDAP_MOD_DELETE ) {
2565 allows = verb_to_mask( c->line, allowable_ops );
2566 global_allows ^= allows;
2570 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
2572 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
2573 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2574 c->log, c->cr_msg, c->argv[i]);
2577 global_allows |= allows;
2582 config_disallows(ConfigArgs *c) {
2583 slap_mask_t disallows = 0;
2585 slap_verbmasks disallowable_ops[] = {
2586 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
2587 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
2588 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
2589 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
2590 { BER_BVC("proxy_authz_non_critical"), SLAP_DISALLOW_PROXY_AUTHZ_N_CRIT },
2591 { BER_BVC("dontusecopy_non_critical"), SLAP_DISALLOW_DONTUSECOPY_N_CRIT },
2594 if (c->op == SLAP_CONFIG_EMIT) {
2595 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
2596 } else if ( c->op == LDAP_MOD_DELETE ) {
2598 global_disallows = 0;
2600 disallows = verb_to_mask( c->line, disallowable_ops );
2601 global_disallows ^= disallows;
2605 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
2607 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
2608 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2609 c->log, c->cr_msg, c->argv[i]);
2612 global_disallows |= disallows;
2617 config_requires(ConfigArgs *c) {
2618 slap_mask_t requires = frontendDB->be_requires;
2619 int i, argc = c->argc;
2620 char **argv = c->argv;
2622 slap_verbmasks requires_ops[] = {
2623 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
2624 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
2625 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
2626 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
2627 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
2630 if (c->op == SLAP_CONFIG_EMIT) {
2631 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
2632 } else if ( c->op == LDAP_MOD_DELETE ) {
2634 c->be->be_requires = 0;
2636 requires = verb_to_mask( c->line, requires_ops );
2637 c->be->be_requires ^= requires;
2641 /* "none" can only be first, to wipe out default/global values */
2642 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
2647 i = verbs_to_mask(argc, argv, requires_ops, &requires);
2649 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
2650 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
2651 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2652 c->log, c->cr_msg, 0);
2654 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
2655 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2656 c->log, c->cr_msg, c->argv[i]);
2660 c->be->be_requires = requires;
2664 static slap_verbmasks *loglevel_ops;
2667 loglevel_init( void )
2669 slap_verbmasks lo[] = {
2670 { BER_BVC("Any"), -1 },
2671 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
2672 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
2673 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
2674 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
2675 { BER_BVC("BER"), LDAP_DEBUG_BER },
2676 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
2677 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
2678 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
2679 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
2680 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
2681 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
2682 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
2683 #if 0 /* no longer used (nor supported) */
2684 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
2685 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
2687 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
2688 { BER_BVC("None"), LDAP_DEBUG_NONE },
2692 return slap_verbmasks_init( &loglevel_ops, lo );
2696 loglevel_destroy( void )
2698 if ( loglevel_ops ) {
2699 (void)slap_verbmasks_destroy( loglevel_ops );
2701 loglevel_ops = NULL;
2704 static slap_mask_t loglevel_ignore[] = { -1, 0 };
2707 slap_loglevel_register( slap_mask_t m, struct berval *s )
2711 if ( loglevel_ops == NULL ) {
2715 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
2718 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
2726 slap_loglevel_get( struct berval *s, int *l )
2731 if ( loglevel_ops == NULL ) {
2735 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
2736 m |= loglevel_ops[ i ].mask;
2739 for ( i = 1; m & i; i <<= 1 )
2746 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
2749 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
2760 str2loglevel( const char *s, int *l )
2764 if ( loglevel_ops == NULL ) {
2768 i = verb_to_mask( s, loglevel_ops );
2770 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
2774 *l = loglevel_ops[ i ].mask;
2780 loglevel2str( int l )
2782 struct berval bv = BER_BVNULL;
2784 loglevel2bv( l, &bv );
2790 loglevel2bv( int l, struct berval *bv )
2792 if ( loglevel_ops == NULL ) {
2798 return enum_to_verb( loglevel_ops, l, bv ) == -1;
2802 loglevel2bvarray( int l, BerVarray *bva )
2804 if ( loglevel_ops == NULL ) {
2808 return mask_to_verbs( loglevel_ops, l, bva );
2812 loglevel_print( FILE *out )
2816 if ( loglevel_ops == NULL ) {
2820 fprintf( out, "Installed log subsystems:\n\n" );
2821 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
2822 fprintf( out, "\t%-30s (%lu)\n",
2823 loglevel_ops[ i ].word.bv_val,
2824 loglevel_ops[ i ].mask );
2827 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
2828 "by specific code\n\n" );
2833 static int config_syslog;
2836 config_loglevel(ConfigArgs *c) {
2839 if ( loglevel_ops == NULL ) {
2843 if (c->op == SLAP_CONFIG_EMIT) {
2844 /* Get default or commandline slapd setting */
2845 if ( ldap_syslog && !config_syslog )
2846 config_syslog = ldap_syslog;
2847 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
2849 } else if ( c->op == LDAP_MOD_DELETE ) {
2853 int level = verb_to_mask( c->line, loglevel_ops );
2854 config_syslog ^= level;
2856 if ( slapMode & SLAP_SERVER_MODE ) {
2857 ldap_syslog = config_syslog;
2862 for( i=1; i < c->argc; i++ ) {
2865 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
2866 if( lutil_atoi( &level, c->argv[i] ) != 0 ) {
2867 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse level", c->argv[0] );
2868 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2869 c->log, c->cr_msg, c->argv[i]);
2873 if ( str2loglevel( c->argv[i], &level ) ) {
2874 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown level", c->argv[0] );
2875 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2876 c->log, c->cr_msg, c->argv[i]);
2880 /* Explicitly setting a zero clears all the levels */
2882 config_syslog |= level;
2886 if ( slapMode & SLAP_SERVER_MODE ) {
2887 ldap_syslog = config_syslog;
2893 config_referral(ConfigArgs *c) {
2895 if (c->op == SLAP_CONFIG_EMIT) {
2896 if ( default_referral ) {
2897 value_add( &c->rvalue_vals, default_referral );
2902 } else if ( c->op == LDAP_MOD_DELETE ) {
2903 if ( c->valx < 0 ) {
2904 ber_bvarray_free( default_referral );
2905 default_referral = NULL;
2908 ch_free( default_referral[i].bv_val );
2909 for (; default_referral[i].bv_val; i++ )
2910 default_referral[i] = default_referral[i+1];
2914 if(validate_global_referral(c->argv[1])) {
2915 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
2916 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2917 c->log, c->cr_msg, c->argv[1]);
2921 ber_str2bv(c->argv[1], 0, 0, &val);
2922 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
2930 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
2931 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
2932 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
2933 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
2934 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
2935 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
2936 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
2937 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
2938 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
2943 config_security(ConfigArgs *c) {
2944 slap_ssf_set_t *set = &c->be->be_ssf_set;
2947 if (c->op == SLAP_CONFIG_EMIT) {
2953 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
2954 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
2957 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
2958 if ( bv.bv_len >= sizeof( numbuf ) ) {
2959 ber_bvarray_free_x( c->rvalue_vals, NULL );
2960 c->rvalue_vals = NULL;
2964 bv.bv_len += sec_keys[i].key.bv_len;
2965 bv.bv_val = ch_malloc( bv.bv_len + 1);
2966 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
2967 strcpy( next, numbuf );
2968 ber_bvarray_add( &c->rvalue_vals, &bv );
2973 for(i = 1; i < c->argc; i++) {
2974 slap_ssf_t *tgt = NULL;
2976 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
2977 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
2978 sec_keys[j].key.bv_len)) {
2979 src = c->argv[i] + sec_keys[j].key.bv_len;
2980 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
2985 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown factor", c->argv[0] );
2986 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2987 c->log, c->cr_msg, c->argv[i]);
2991 if ( lutil_atou( tgt, src ) != 0 ) {
2992 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse factor", c->argv[0] );
2993 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2994 c->log, c->cr_msg, c->argv[i]);
3002 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
3006 for (; !BER_BVISNULL( &an->an_name ); an++) {
3007 /* if buflen == 0, assume the buffer size has been
3008 * already checked otherwise */
3009 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
3010 if ( comma ) *ptr++ = ',';
3011 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
3018 config_updatedn(ConfigArgs *c) {
3019 if (c->op == SLAP_CONFIG_EMIT) {
3020 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
3021 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
3022 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
3026 } else if ( c->op == LDAP_MOD_DELETE ) {
3027 ch_free( c->be->be_update_ndn.bv_val );
3028 BER_BVZERO( &c->be->be_update_ndn );
3029 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
3032 if(SLAP_SHADOW(c->be)) {
3033 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database already shadowed", c->argv[0] );
3034 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3035 c->log, c->cr_msg, 0);
3039 ber_memfree_x( c->value_dn.bv_val, NULL );
3040 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
3041 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
3043 c->be->be_update_ndn = c->value_ndn;
3044 BER_BVZERO( &c->value_dn );
3045 BER_BVZERO( &c->value_ndn );
3047 return config_slurp_shadow( c );
3051 config_shadow( ConfigArgs *c, int flag )
3053 char *notallowed = NULL;
3055 if ( c->be == frontendDB ) {
3056 notallowed = "frontend";
3058 } else if ( SLAP_MONITOR(c->be) ) {
3059 notallowed = "monitor";
3062 if ( notallowed != NULL ) {
3063 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
3067 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SINGLE_SHADOW | flag);
3073 config_updateref(ConfigArgs *c) {
3075 if (c->op == SLAP_CONFIG_EMIT) {
3076 if ( c->be->be_update_refs ) {
3077 value_add( &c->rvalue_vals, c->be->be_update_refs );
3082 } else if ( c->op == LDAP_MOD_DELETE ) {
3083 if ( c->valx < 0 ) {
3084 ber_bvarray_free( c->be->be_update_refs );
3085 c->be->be_update_refs = NULL;
3088 ch_free( c->be->be_update_refs[i].bv_val );
3089 for (; c->be->be_update_refs[i].bv_val; i++)
3090 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
3094 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
3095 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must appear after syncrepl or updatedn",
3097 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3098 c->log, c->cr_msg, 0);
3102 if(validate_global_referral(c->argv[1])) {
3103 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3104 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3105 c->log, c->cr_msg, c->argv[1]);
3108 ber_str2bv(c->argv[1], 0, 0, &val);
3109 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
3114 config_obsolete(ConfigArgs *c) {
3115 if (c->op == SLAP_CONFIG_EMIT)
3118 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> keyword is obsolete (ignored)",
3120 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0);
3125 config_include(ConfigArgs *c) {
3126 int savelineno = c->lineno;
3129 ConfigFile *cfsave = cfn;
3130 ConfigFile *cf2 = NULL;
3132 /* Leftover from RE23. No dynamic config for include files */
3133 if ( c->op == SLAP_CONFIG_EMIT || c->op == LDAP_MOD_DELETE )
3136 cf = ch_calloc( 1, sizeof(ConfigFile));
3137 if ( cfn->c_kids ) {
3138 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
3144 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
3145 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
3146 c->lineno = savelineno - 1;
3149 if ( cf2 ) cf2->c_sibs = NULL;
3150 else cfn->c_kids = NULL;
3151 ch_free( cf->c_file.bv_val );
3161 config_tls_option(ConfigArgs *c) {
3163 LDAP *ld = slap_tls_ld;
3165 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
3166 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
3167 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
3168 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
3169 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
3170 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
3171 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
3173 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
3175 default: Debug(LDAP_DEBUG_ANY, "%s: "
3176 "unknown tls_option <0x%x>\n",
3177 c->log, c->type, 0);
3180 if (c->op == SLAP_CONFIG_EMIT) {
3181 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
3182 } else if ( c->op == LDAP_MOD_DELETE ) {
3183 return ldap_pvt_tls_set_option( ld, flag, NULL );
3185 ch_free(c->value_string);
3186 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
3189 /* FIXME: this ought to be provided by libldap */
3191 config_tls_config(ConfigArgs *c) {
3194 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
3195 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
3197 Debug(LDAP_DEBUG_ANY, "%s: "
3198 "unknown tls_option <0x%x>\n",
3199 c->log, c->type, 0);
3202 if (c->op == SLAP_CONFIG_EMIT) {
3203 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
3204 } else if ( c->op == LDAP_MOD_DELETE ) {
3206 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
3208 ch_free( c->value_string );
3209 if ( isdigit( (unsigned char)c->argv[1][0] ) ) {
3210 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
3211 Debug(LDAP_DEBUG_ANY, "%s: "
3212 "unable to parse %s \"%s\"\n",
3213 c->log, c->argv[0], c->argv[1] );
3216 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
3218 return(ldap_int_tls_config(slap_tls_ld, flag, c->argv[1]));
3223 static CfEntryInfo *
3224 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
3234 if ( dn_match( &root->ce_entry->e_nname, dn ))
3237 c = dn->bv_val+dn->bv_len;
3238 for (;*c != ',';c--);
3242 for (--c;c>dn->bv_val && *c != ',';c--);
3246 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
3248 root = root->ce_kids;
3250 for (;root;root=root->ce_sibs) {
3251 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
3252 if ( cdn.bv_val == dn->bv_val ) {
3262 typedef struct setup_cookie {
3272 config_ldif_resp( Operation *op, SlapReply *rs )
3274 if ( rs->sr_type == REP_SEARCH ) {
3275 setup_cookie *sc = op->o_callback->sc_private;
3278 sc->cfb->cb_got_ldif = 1;
3279 /* Does the frontend exist? */
3280 if ( !sc->got_frontend ) {
3281 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
3282 "olcDatabase", STRLENOF( "olcDatabase" )))
3284 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3285 STRLENOF( "olcDatabase" ), "={-1}frontend",
3286 STRLENOF( "={-1}frontend" )))
3290 sc->ca->be = frontendDB;
3291 sc->ca->bi = frontendDB->bd_info;
3292 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
3293 rdn.bv_val = sc->ca->log;
3294 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3295 "%s=" SLAP_X_ORDERED_FMT "%s",
3296 cfAd_database->ad_cname.bv_val, -1,
3297 sc->ca->bi->bi_type);
3299 sc->frontend = config_build_entry( op, rs,
3300 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
3301 sc->ca->be->be_cf_ocs );
3311 dnParent( &rs->sr_entry->e_nname, &pdn );
3313 /* Does the configDB exist? */
3314 if ( sc->got_frontend && !sc->got_config &&
3315 !strncmp( rs->sr_entry->e_nname.bv_val,
3316 "olcDatabase", STRLENOF( "olcDatabase" )) &&
3317 dn_match( &config_rdn, &pdn ) )
3319 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3320 STRLENOF( "olcDatabase" ), "={0}config",
3321 STRLENOF( "={0}config" )))
3325 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
3326 sc->ca->bi = sc->ca->be->bd_info;
3327 rdn.bv_val = sc->ca->log;
3328 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3329 "%s=" SLAP_X_ORDERED_FMT "%s",
3330 cfAd_database->ad_cname.bv_val, 0,
3331 sc->ca->bi->bi_type);
3333 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
3334 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
3341 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
3342 if ( rs->sr_err != LDAP_SUCCESS ) {
3343 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
3344 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg, 0 );
3350 /* Configure and read the underlying back-ldif store */
3352 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
3353 CfBackInfo *cfb = be->be_private;
3359 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
3360 Connection conn = {0};
3361 OperationBuffer opbuf;
3363 SlapReply rs = {REP_RESULT};
3364 Filter filter = { LDAP_FILTER_PRESENT };
3365 struct berval filterstr = BER_BVC("(objectclass=*)");
3368 /* Is the config directory available? */
3369 if ( stat( dir, &st ) < 0 ) {
3370 /* No, so don't bother using the backing store.
3371 * All changes will be in-memory only.
3376 cfb->cb_db.bd_info = backend_info( "ldif" );
3377 if ( !cfb->cb_db.bd_info )
3378 return 0; /* FIXME: eventually this will be a fatal error */
3380 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
3383 cfb->cb_db.be_suffix = be->be_suffix;
3384 cfb->cb_db.be_nsuffix = be->be_nsuffix;
3386 /* The suffix is always "cn=config". The underlying DB's rootdn
3387 * is always the same as the suffix.
3389 cfb->cb_db.be_rootdn = be->be_suffix[0];
3390 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
3392 ber_str2bv( dir, 0, 1, &cfdir );
3397 argv[0] = "directory";
3398 argv[1] = (char *)dir;
3403 c.table = Cft_Database;
3405 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
3409 if ( config_add_vals( ct, &c ))
3412 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
3416 void *thrctx = ldap_pvt_thread_pool_context();
3419 connection_fake_init( &conn, &opbuf, thrctx );
3422 filter.f_desc = slap_schema.si_ad_objectClass;
3424 op->o_tag = LDAP_REQ_SEARCH;
3426 op->ors_filter = &filter;
3427 op->ors_filterstr = filterstr;
3428 op->ors_scope = LDAP_SCOPE_SUBTREE;
3430 op->o_dn = c.be->be_rootdn;
3431 op->o_ndn = c.be->be_rootndn;
3433 op->o_req_dn = be->be_suffix[0];
3434 op->o_req_ndn = be->be_nsuffix[0];
3436 op->ors_tlimit = SLAP_NO_LIMIT;
3437 op->ors_slimit = SLAP_NO_LIMIT;
3439 op->ors_attrs = slap_anlist_all_attributes;
3440 op->ors_attrsonly = 0;
3442 op->o_callback = &cb;
3445 cb.sc_private = ≻
3446 sc.got_frontend = 0;
3451 op->o_bd = &cfb->cb_db;
3453 /* Allow unknown attrs in DNs */
3454 prev_DN_strict = slap_DN_strict;
3457 rc = op->o_bd->be_search( op, &rs );
3459 /* Restore normal DN validation */
3460 slap_DN_strict = prev_DN_strict;
3462 op->o_tag = LDAP_REQ_ADD;
3463 if ( rc == LDAP_SUCCESS && sc.frontend ) {
3464 op->ora_e = sc.frontend;
3465 rc = op->o_bd->be_add( op, &rs );
3467 if ( rc == LDAP_SUCCESS && sc.config ) {
3468 op->ora_e = sc.config;
3469 rc = op->o_bd->be_add( op, &rs );
3471 ldap_pvt_thread_pool_context_reset( thrctx );
3474 /* ITS#4194 - only use if it's present, or we're converting. */
3475 if ( !readit || rc == LDAP_SUCCESS )
3476 cfb->cb_use_ldif = 1;
3482 CfOc_cmp( const void *c1, const void *c2 ) {
3483 const ConfigOCs *co1 = c1;
3484 const ConfigOCs *co2 = c2;
3486 return ber_bvcmp( co1->co_name, co2->co_name );
3490 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
3493 i = init_config_attrs( ct );
3496 /* set up the objectclasses */
3497 i = init_config_ocs( ocs );
3500 for (i=0; ocs[i].co_def; i++) {
3501 if ( ocs[i].co_oc ) {
3502 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
3503 if ( !ocs[i].co_table )
3504 ocs[i].co_table = ct;
3505 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
3512 read_config(const char *fname, const char *dir) {
3515 const char *cfdir, *cfname;
3518 /* Setup the config backend */
3519 be = backend_db_init( "config", NULL, 0, NULL );
3523 cfb = be->be_private;
3524 be->be_dfltaccess = ACL_NONE;
3526 /* If no .conf, or a dir was specified, setup the dir */
3527 if ( !fname || dir ) {
3529 /* If explicitly given, check for existence */
3532 if ( stat( dir, &st ) < 0 ) {
3533 Debug( LDAP_DEBUG_ANY,
3534 "invalid config directory %s, error %d\n",
3540 cfdir = SLAPD_DEFAULT_CONFIGDIR;
3542 /* if fname is defaulted, try reading .d */
3543 rc = config_setup_ldif( be, cfdir, !fname );
3546 /* It may be OK if the base object doesn't exist yet. */
3547 if ( rc != LDAP_NO_SUCH_OBJECT )
3549 /* ITS#4194: But if dir was specified and no fname,
3550 * then we were supposed to read the dir. Unless we're
3551 * trying to slapadd the dir...
3553 if ( dir && !fname ) {
3554 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
3556 /* Assume it's slapadd with a config dir, let it continue */
3558 cfb->cb_got_ldif = 1;
3559 cfb->cb_use_ldif = 1;
3564 /* If we read the config from back-ldif, nothing to do here */
3565 if ( cfb->cb_got_ldif ) {
3574 cfname = SLAPD_DEFAULT_CONFIGFILE;
3576 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
3579 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
3582 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
3583 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
3584 &frontendDB->be_schemadn );
3585 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
3586 if ( rc != LDAP_SUCCESS ) {
3587 Debug(LDAP_DEBUG_ANY, "read_config: "
3588 "unable to normalize default schema DN \"%s\"\n",
3589 frontendDB->be_schemadn.bv_val, 0, 0 );
3590 /* must not happen */
3598 config_back_bind( Operation *op, SlapReply *rs )
3600 if ( be_isroot_pw( op ) ) {
3601 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
3602 /* frontend sends result */
3603 return LDAP_SUCCESS;
3606 rs->sr_err = LDAP_INVALID_CREDENTIALS;
3607 send_ldap_result( op, rs );
3613 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
3617 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
3619 rs->sr_attrs = op->ors_attrs;
3620 rs->sr_entry = ce->ce_entry;
3622 rc = send_search_entry( op, rs );
3624 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
3625 if ( ce->ce_kids ) {
3626 rc = config_send( op, rs, ce->ce_kids, 1 );
3627 if ( rc ) return rc;
3630 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
3631 rc = config_send( op, rs, ce, 0 );
3639 static ConfigTable *
3640 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
3645 for (j=0; j<nocs; j++) {
3646 for (i=0; colst[j]->co_table[i].name; i++)
3647 if ( colst[j]->co_table[i].ad == ad ) {
3648 ca->table = colst[j]->co_type;
3649 return &colst[j]->co_table[i];
3655 /* Sort the attributes of the entry according to the order defined
3656 * in the objectclass, with required attributes occurring before
3657 * allowed attributes. For any attributes with sequencing dependencies
3658 * (e.g., rootDN must be defined after suffix) the objectclass must
3659 * list the attributes in the desired sequence.
3662 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
3664 Attribute *a, *head = NULL, *tail = NULL, **prev;
3667 for (i=0; i<nocs; i++) {
3668 if ( colst[i]->co_oc->soc_required ) {
3669 AttributeType **at = colst[i]->co_oc->soc_required;
3670 for (j=0; at[j]; j++) {
3671 for (a=e->e_attrs, prev=&e->e_attrs; a;
3672 prev = &(*prev)->a_next, a=a->a_next) {
3673 if ( a->a_desc == at[j]->sat_ad ) {
3687 if ( colst[i]->co_oc->soc_allowed ) {
3688 AttributeType **at = colst[i]->co_oc->soc_allowed;
3689 for (j=0; at[j]; j++) {
3690 for (a=e->e_attrs, prev=&e->e_attrs; a;
3691 prev = &(*prev)->a_next, a=a->a_next) {
3692 if ( a->a_desc == at[j]->sat_ad ) {
3708 tail->a_next = e->e_attrs;
3714 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
3716 Attribute *a = NULL;
3717 AttributeDescription *ad;
3727 Modifications *ml = ptr;
3729 vals = ml->sml_values;
3732 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
3733 rc = ordered_value_sort( a, 1 );
3735 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
3736 ad->ad_cname.bv_val );
3740 for ( i=0; vals[i].bv_val; i++ ) {
3741 ca->line = vals[i].bv_val;
3742 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
3743 ca->line[0] == '{' ) {
3744 char *idx = strchr( ca->line, '}' );
3745 if ( idx ) ca->line = idx+1;
3747 rc = config_parse_vals( ct, ca, i );
3756 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
3759 struct berval rtype, rval;
3761 AttributeDescription *ad = NULL;
3763 dnRdn( &e->e_name, rdn );
3764 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
3765 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
3766 rtype.bv_val = rdn->bv_val;
3767 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
3770 slap_bv2ad( &rtype, &ad, &rs->sr_text );
3771 a = attr_find( e->e_attrs, ad );
3772 if (!a ) return LDAP_NAMING_VIOLATION;
3779 config_rename_kids( CfEntryInfo *ce )
3782 struct berval rdn, nrdn;
3784 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
3785 dnRdn ( &ce2->ce_entry->e_name, &rdn );
3786 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
3787 free( ce2->ce_entry->e_name.bv_val );
3788 free( ce2->ce_entry->e_nname.bv_val );
3789 build_new_dn( &ce2->ce_entry->e_name, &ce->ce_entry->e_name,
3791 build_new_dn( &ce2->ce_entry->e_nname, &ce->ce_entry->e_nname,
3793 config_rename_kids( ce2 );
3798 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
3799 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
3800 struct berval *nnewrdn, int use_ldif )
3804 struct berval odn, ondn;
3808 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
3809 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
3812 free( a->a_vals[0].bv_val );
3813 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
3814 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
3815 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
3816 strcpy( a->a_vals[0].bv_val, ptr1 );
3818 if ( a->a_nvals != a->a_vals ) {
3819 free( a->a_nvals[0].bv_val );
3820 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
3821 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
3822 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
3823 strcpy( a->a_nvals[0].bv_val, ptr1 );
3826 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
3827 BackendDB *be = op->o_bd;
3828 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
3829 struct berval dn, ndn, xdn, xndn;
3831 op->o_bd = &cfb->cb_db;
3833 /* Save current rootdn; use the underlying DB's rootdn */
3837 xndn = op->o_req_ndn;
3838 op->o_dn = op->o_bd->be_rootdn;
3839 op->o_ndn = op->o_bd->be_rootndn;
3841 op->o_req_ndn = ondn;
3843 scp = op->o_callback;
3844 op->o_callback = ≻
3845 op->orr_newrdn = *newrdn;
3846 op->orr_nnewrdn = *nnewrdn;
3847 op->orr_newSup = NULL;
3848 op->orr_nnewSup = NULL;
3849 op->orr_deleteoldrdn = 1;
3850 op->orr_modlist = NULL;
3851 slap_modrdn2mods( op, rs );
3852 slap_mods_opattrs( op, &op->orr_modlist, 1 );
3853 rc = op->o_bd->be_modrdn( op, rs );
3854 slap_mods_free( op->orr_modlist, 1 );
3857 op->o_callback = scp;
3861 op->o_req_ndn = xndn;
3864 free( ondn.bv_val );
3866 config_rename_kids( e->e_private );
3871 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
3872 Entry *e, int idx, int tailindex, int use_ldif )
3874 struct berval ival, newrdn, nnewrdn;
3877 char ibuf[32], *ptr1, *ptr2 = NULL;
3880 rc = config_rename_attr( rs, e, &rdn, &a );
3881 if ( rc ) return rc;
3884 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
3885 if ( ival.bv_len >= sizeof( ibuf ) ) {
3886 return LDAP_NAMING_VIOLATION;
3889 newrdn.bv_len = rdn.bv_len + ival.bv_len;
3890 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
3893 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
3894 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3897 ptr2 = ber_bvchr( &rdn, '}' );
3901 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
3903 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
3904 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
3905 a->a_desc->ad_cname.bv_len );
3907 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3908 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
3912 /* Do the equivalent of ModRDN */
3913 /* Replace DN / NDN */
3914 newrdn.bv_len = ptr1 - newrdn.bv_val;
3915 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
3916 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
3918 free( nnewrdn.bv_val );
3919 free( newrdn.bv_val );
3924 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
3925 SlapReply *rs, int *renum, int *ibase )
3928 int index = -1, gotindex = 0, nsibs, rc = 0;
3929 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
3930 char *ptr1, *ptr2 = NULL;
3933 if ( renum ) *renum = 0;
3935 /* These entries don't get indexed/renumbered */
3936 if ( ce_type == Cft_Global ) return 0;
3937 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
3939 if ( ce_type == Cft_Module )
3942 /* See if the rdn has an index already */
3943 dnRdn( &e->e_name, &rdn );
3944 if ( ce_type == Cft_Database ) {
3945 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
3946 "frontend", STRLENOF("frontend") ))
3948 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
3949 "config", STRLENOF("config") ))
3952 ptr1 = ber_bvchr( &e->e_name, '{' );
3953 if ( ptr1 && ptr1 < &e->e_name.bv_val[ rdn.bv_len ] ) {
3955 ptr2 = strchr( ptr1, '}' );
3956 if ( !ptr2 || ptr2 > &e->e_name.bv_val[ rdn.bv_len ] )
3957 return LDAP_NAMING_VIOLATION;
3958 if ( ptr2-ptr1 == 1)
3959 return LDAP_NAMING_VIOLATION;
3961 index = strtol( ptr1 + 1, &next, 10 );
3962 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
3963 return LDAP_NAMING_VIOLATION;
3966 /* Special case, we allow -1 for the frontendDB */
3967 if ( index != -1 || !isfrontend )
3968 return LDAP_NAMING_VIOLATION;
3970 if ( isconfig && index != 0 ){
3971 return LDAP_NAMING_VIOLATION;
3975 /* count related kids */
3976 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
3977 if ( ce->ce_type == ce_type ) nsibs++;
3980 /* account for -1 frontend */
3981 if ( ce_type == Cft_Database )
3984 if ( index != nsibs ) {
3986 if ( index < nsibs ) {
3987 if ( tailindex ) return LDAP_NAMING_VIOLATION;
3988 /* Siblings need to be renumbered */
3989 if ( index != -1 || !isfrontend )
3993 /* config DB is always "0" */
3994 if ( isconfig && index == -1 ) {
3997 if (( !isfrontend && index == -1 ) || ( index > nsibs ) ){
4001 /* just make index = nsibs */
4003 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
4006 if ( ibase ) *ibase = index;
4007 if ( renum ) *renum = renumber;
4012 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
4017 co.co_name = &oc->soc_cname;
4018 cop = avl_find( CfOcTree, &co, CfOc_cmp );
4022 /* check for duplicates */
4023 for ( i = 0; i < *nocs; i++ ) {
4024 if ( *copp && (*copp)[i] == cop ) {
4030 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
4031 if ( tmp == NULL ) {
4035 (*copp)[*nocs] = cop;
4040 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
4041 if ( count_oc( *sups, copp, nocs ) ) {
4050 count_ocs( Attribute *oc_at, int *nocs )
4053 ConfigOCs **colst = NULL;
4057 for ( i = 0; !BER_BVISNULL( &oc_at->a_nvals[i] ); i++ )
4061 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
4063 assert( oc != NULL );
4064 if ( count_oc( oc, &colst, nocs ) ) {
4074 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4076 /* Leftover from RE23. Never parse this entry */
4077 return LDAP_COMPARE_TRUE;
4081 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4085 /* This entry is hardcoded, don't re-parse it */
4086 if ( p->ce_type == Cft_Global ) {
4087 cfn = p->ce_private;
4088 ca->ca_private = cfn;
4089 return LDAP_COMPARE_TRUE;
4091 if ( p->ce_type != Cft_Schema )
4092 return LDAP_CONSTRAINT_VIOLATION;
4094 cfn = ch_calloc( 1, sizeof(ConfigFile) );
4095 ca->ca_private = cfn;
4096 cfo = p->ce_private;
4097 cfn->c_sibs = cfo->c_kids;
4099 return LDAP_SUCCESS;
4103 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4105 if ( p->ce_type != Cft_Global ) {
4106 return LDAP_CONSTRAINT_VIOLATION;
4108 /* config must be {0}, nothing else allowed */
4109 if ( !strncmp( e->e_nname.bv_val, "olcDatabase={0}", STRLENOF("olcDatabase={0}")) &&
4110 strncmp( e->e_nname.bv_val + STRLENOF("olcDatabase={0}"), "config,", STRLENOF("config,") )) {
4111 return LDAP_CONSTRAINT_VIOLATION;
4113 ca->be = frontendDB; /* just to get past check_vals */
4114 return LDAP_SUCCESS;
4118 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4120 if ( p->ce_type != Cft_Global ) {
4121 return LDAP_CONSTRAINT_VIOLATION;
4123 return LDAP_SUCCESS;
4127 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4129 if ( p->ce_type != Cft_Global ) {
4130 return LDAP_CONSTRAINT_VIOLATION;
4132 return LDAP_SUCCESS;
4136 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4138 if ( p->ce_type != Cft_Database ) {
4139 return LDAP_CONSTRAINT_VIOLATION;
4142 return LDAP_SUCCESS;
4146 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
4151 AttributeDescription *ad;
4156 if ( cfn->c_cr_head ) {
4157 struct berval bv = BER_BVC("olcDitContentRules");
4159 slap_bv2ad( &bv, &ad, &text );
4160 ct = config_find_table( colst, nocs, ad, ca );
4161 config_del_vals( ct, ca );
4163 if ( cfn->c_oc_head ) {
4164 struct berval bv = BER_BVC("olcObjectClasses");
4166 slap_bv2ad( &bv, &ad, &text );
4167 ct = config_find_table( colst, nocs, ad, ca );
4168 config_del_vals( ct, ca );
4170 if ( cfn->c_at_head ) {
4171 struct berval bv = BER_BVC("olcAttributeTypes");
4173 slap_bv2ad( &bv, &ad, &text );
4174 ct = config_find_table( colst, nocs, ad, ca );
4175 config_del_vals( ct, ca );
4177 if ( cfn->c_syn_head ) {
4178 struct berval bv = BER_BVC("olcLdapSyntaxes");
4180 slap_bv2ad( &bv, &ad, &text );
4181 ct = config_find_table( colst, nocs, ad, ca );
4182 config_del_vals( ct, ca );
4184 if ( cfn->c_om_head ) {
4185 struct berval bv = BER_BVC("olcObjectIdentifier");
4187 slap_bv2ad( &bv, &ad, &text );
4188 ct = config_find_table( colst, nocs, ad, ca );
4189 config_del_vals( ct, ca );
4191 cfo = p->ce_private;
4192 cfo->c_kids = cfn->c_sibs;
4197 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
4199 int rc = LDAP_CONSTRAINT_VIOLATION;
4202 if ( (*cop)->co_ldadd ) {
4203 rc = (*cop)->co_ldadd( last, e, ca );
4204 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4209 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
4210 ConfigOCs co = { 0 };
4212 co.co_name = &(*ocp)->soc_cname;
4213 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
4214 if ( *cop == NULL ) {
4218 rc = config_add_oc( cop, last, e, ca );
4219 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4227 /* Parse an LDAP entry into config directives */
4229 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
4230 int *renum, Operation *op )
4232 CfEntryInfo *ce, *last = NULL;
4233 ConfigOCs co, *coptr, **colst;
4234 Attribute *a, *oc_at, *soc_at;
4235 int i, ibase = -1, nocs, rc = 0;
4238 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
4240 memset( ca, 0, sizeof(ConfigArgs));
4242 /* Make sure parent exists and entry does not. But allow
4243 * Databases and Overlays to be inserted. Don't do any
4244 * auto-renumbering if manageDSAit control is present.
4246 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
4248 if ( ( op && op->o_managedsait ) ||
4249 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
4250 ce->ce_type != Cft_Module ) )
4252 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4253 "DN=\"%s\" already exists\n",
4254 log_prefix, e->e_name.bv_val, 0 );
4255 return LDAP_ALREADY_EXISTS;
4259 dnParent( &e->e_nname, &pdn );
4261 /* If last is NULL, the new entry is the root/suffix entry,
4262 * otherwise last should be the parent.
4264 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
4266 rs->sr_matched = last->ce_entry->e_name.bv_val;
4268 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4269 "DN=\"%s\" not child of DN=\"%s\"\n",
4270 log_prefix, e->e_name.bv_val,
4271 last->ce_entry->e_name.bv_val );
4272 return LDAP_NO_SUCH_OBJECT;
4276 /* No parent, must be root. This will never happen... */
4277 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
4278 return LDAP_NO_SUCH_OBJECT;
4281 if ( last && !access_allowed( op, last->ce_entry,
4282 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
4284 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4285 "DN=\"%s\" no write access to \"children\" of parent\n",
4286 log_prefix, e->e_name.bv_val, 0 );
4287 return LDAP_INSUFFICIENT_ACCESS;
4291 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4293 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4294 "DN=\"%s\" no objectClass\n",
4295 log_prefix, e->e_name.bv_val, 0 );
4296 return LDAP_OBJECT_CLASS_VIOLATION;
4299 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4301 ObjectClass *soc = NULL;
4302 char textbuf[ SLAP_TEXT_BUFLEN ];
4303 const char *text = textbuf;
4305 /* FIXME: check result */
4306 rc = structural_class( oc_at->a_nvals, &soc, NULL,
4307 &text, textbuf, sizeof(textbuf), NULL );
4308 if ( rc != LDAP_SUCCESS ) {
4309 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4310 "DN=\"%s\" no structural objectClass (%s)\n",
4311 log_prefix, e->e_name.bv_val, text );
4314 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
4315 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4316 if ( soc_at == NULL ) {
4317 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4318 "DN=\"%s\" no structural objectClass; "
4319 "unable to merge computed class %s\n",
4320 log_prefix, e->e_name.bv_val,
4321 soc->soc_cname.bv_val );
4322 return LDAP_OBJECT_CLASS_VIOLATION;
4325 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4326 "DN=\"%s\" no structural objectClass; "
4327 "computed objectClass %s merged\n",
4328 log_prefix, e->e_name.bv_val,
4329 soc->soc_cname.bv_val );
4332 /* Fake the coordinates based on whether we're part of an
4333 * LDAP Add or if reading the config dir
4336 ca->fname = "slapd";
4339 ca->fname = cfdir.bv_val;
4344 co.co_name = &soc_at->a_nvals[0];
4345 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
4346 if ( coptr == NULL ) {
4347 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4348 "DN=\"%s\" no structural objectClass in configuration table\n",
4349 log_prefix, e->e_name.bv_val, 0 );
4350 return LDAP_OBJECT_CLASS_VIOLATION;
4353 /* Only the root can be Cft_Global, everything else must
4354 * have a parent. Only limited nesting arrangements are allowed.
4356 rc = LDAP_CONSTRAINT_VIOLATION;
4357 if ( coptr->co_type == Cft_Global && !last ) {
4358 cfn = cfb->cb_config;
4359 ca->ca_private = cfn;
4360 ca->be = frontendDB; /* just to get past check_vals */
4364 colst = count_ocs( oc_at, &nocs );
4366 /* Check whether the Add is allowed by its parent, and do
4367 * any necessary arg setup
4370 rc = config_add_oc( &coptr, last, e, ca );
4371 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4372 for ( i = 0; i<nocs; i++ ) {
4373 /* Already checked these */
4374 if ( colst[i]->co_oc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
4376 if ( colst[i]->co_ldadd &&
4377 ( rc = colst[i]->co_ldadd( last, e, ca ))
4378 != LDAP_CONSTRAINT_VIOLATION ) {
4384 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4385 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4386 "DN=\"%s\" no structural objectClass add function\n",
4387 log_prefix, e->e_name.bv_val, 0 );
4388 return LDAP_OBJECT_CLASS_VIOLATION;
4392 /* Add the entry but don't parse it, we already have its contents */
4393 if ( rc == LDAP_COMPARE_TRUE ) {
4398 if ( rc != LDAP_SUCCESS )
4401 /* Parse all the values and check for simple syntax errors before
4402 * performing any set actions.
4404 * If doing an LDAPadd, check for indexed names and any necessary
4405 * renaming/renumbering. Entries that don't need indexed names are
4406 * ignored. Entries that need an indexed name and arrive without one
4407 * are assigned to the end. Entries that arrive with an index may
4408 * cause the following entries to be renumbered/bumped down.
4410 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
4411 * don't allow Adding an entry with an index that's already in use.
4412 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
4414 * These entries can have auto-assigned indexes (appended to the end)
4415 * but only the other types support auto-renumbering of siblings.
4418 rc = check_name_index( last, coptr->co_type, e, rs, renum,
4423 if ( renum && *renum && coptr->co_type != Cft_Database &&
4424 coptr->co_type != Cft_Overlay )
4426 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
4427 "operation requires sibling renumbering" );
4428 rc = LDAP_UNWILLING_TO_PERFORM;
4433 init_config_argv( ca );
4435 /* Make sure we process attrs in the required order */
4436 sort_attrs( e, colst, nocs );
4438 for ( a = e->e_attrs; a; a = a->a_next ) {
4439 if ( a == oc_at ) continue;
4440 ct = config_find_table( colst, nocs, a->a_desc, ca );
4441 if ( !ct ) continue; /* user data? */
4442 rc = check_vals( ct, ca, a, 1 );
4443 if ( rc ) goto done_noop;
4446 /* Basic syntax checks are OK. Do the actual settings. */
4447 for ( a=e->e_attrs; a; a=a->a_next ) {
4448 if ( a == oc_at ) continue;
4449 ct = config_find_table( colst, nocs, a->a_desc, ca );
4450 if ( !ct ) continue; /* user data? */
4451 for (i=0; a->a_vals[i].bv_val; i++) {
4453 ca->line = a->a_vals[i].bv_val;
4454 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
4455 ptr = strchr( ca->line, '}' );
4457 iptr = strchr( ca->line, '{' );
4461 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
4463 ca->valx = strtol( iptr+1, NULL, 0 );
4470 rc = config_parse_add( ct, ca, i );
4478 /* Newly added databases and overlays need to be started up */
4479 if ( CONFIG_ONLINE_ADD( ca )) {
4480 if ( colst[0]->co_type == Cft_Database ) {
4481 rc = backend_startup_one( ca->be, &ca->reply );
4483 } else if ( colst[0]->co_type == Cft_Overlay ) {
4484 if ( ca->bi->bi_db_open ) {
4485 BackendInfo *bi_orig = ca->be->bd_info;
4486 ca->be->bd_info = ca->bi;
4487 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
4488 ca->be->bd_info = bi_orig;
4490 } else if ( ca->cleanup ) {
4491 rc = ca->cleanup( ca );
4494 if (ca->cr_msg[0] == '\0')
4495 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
4497 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
4498 ca->log, ca->cr_msg, ca->argv[1] );
4505 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
4506 ce->ce_parent = last;
4507 ce->ce_entry = entry_dup( e );
4508 ce->ce_entry->e_private = ce;
4509 ce->ce_type = colst[0]->co_type;
4512 ce->ce_private = ca->ca_private;
4513 ca->ca_entry = ce->ce_entry;
4516 } else if ( last->ce_kids ) {
4517 CfEntryInfo *c2, **cprev;
4519 /* Advance to first of this type */
4520 cprev = &last->ce_kids;
4521 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
4522 cprev = &c2->ce_sibs;
4525 /* Account for the (-1) frontendDB entry */
4526 if ( ce->ce_type == Cft_Database ) {
4527 if ( ca->be == frontendDB )
4529 else if ( ibase != -1 )
4534 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
4535 cprev = &c2->ce_sibs;
4541 for ( i=0; i<ibase; i++ ) {
4543 cprev = &c2->ce_sibs;
4546 ce->ce_sibs = *cprev;
4554 if ( (colst[0]->co_type == Cft_Database) && ca->be ) {
4555 if ( ca->be != frontendDB )
4556 backend_destroy_one( ca->be, 1 );
4557 } else if ( (colst[0]->co_type == Cft_Overlay) && ca->bi ) {
4558 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
4559 } else if ( colst[0]->co_type == Cft_Schema ) {
4560 schema_destroy_one( ca, colst, nocs, last );
4565 ch_free( ca->argv );
4566 if ( colst ) ch_free( colst );
4570 #define BIGTMP 10000
4572 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
4573 int base, int rebase, int max, int use_ldif )
4575 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
4576 ConfigType etype = ce->ce_type;
4577 int count = 0, rc = 0;
4579 /* Reverse ce list */
4580 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
4581 if (ce2->ce_type != etype) {
4586 ce2->ce_sibs = cetmp;
4589 if ( max && count >= max ) {
4595 /* Move original to a temp name until increments are done */
4597 ce->ce_entry->e_private = NULL;
4598 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4599 base+BIGTMP, 0, use_ldif );
4600 ce->ce_entry->e_private = ce;
4602 /* start incrementing */
4603 for (ce2=cetmp; ce2; ce2=ce3) {
4605 ce2->ce_sibs = cerem;
4608 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
4609 count+base, 0, use_ldif );
4613 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4614 base, 0, use_ldif );
4619 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
4620 CfEntryInfo *ce2, int old, int use_ldif )
4624 /* Renumber original to a temp value */
4625 ce->ce_entry->e_private = NULL;
4626 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4627 old+BIGTMP, 0, use_ldif );
4628 ce->ce_entry->e_private = ce;
4630 /* start decrementing */
4631 for (; ce2 != ce; ce2=ce2->ce_sibs) {
4632 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
4633 count+old, 0, use_ldif );
4636 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4637 count+old, 0, use_ldif );
4640 /* Parse an LDAP entry into config directives, then store in underlying
4644 config_back_add( Operation *op, SlapReply *rs )
4650 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
4651 NULL, ACL_WADD, NULL )) {
4652 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4657 * Check for attribute ACL
4659 if ( !acl_check_modlist( op, op->ora_e, op->orm_modlist )) {
4660 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4661 rs->sr_text = "no write access to attribute";
4665 cfb = (CfBackInfo *)op->o_bd->be_private;
4667 /* add opattrs for syncprov */
4669 char textbuf[SLAP_TEXT_BUFLEN];
4670 size_t textlen = sizeof textbuf;
4671 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1,
4672 &rs->sr_text, textbuf, sizeof( textbuf ) );
4673 if ( rs->sr_err != LDAP_SUCCESS )
4675 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
4676 if ( rs->sr_err != LDAP_SUCCESS ) {
4677 Debug( LDAP_DEBUG_TRACE,
4678 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
4679 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
4684 ldap_pvt_thread_pool_pause( &connection_pool );
4687 * 1) check for existence of entry
4688 * 2) check for sibling renumbering
4689 * 3) perform internal add
4690 * 4) perform any necessary renumbering
4691 * 5) store entry in underlying database
4693 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
4694 if ( rs->sr_err != LDAP_SUCCESS ) {
4695 rs->sr_text = ca.cr_msg;
4700 CfEntryInfo *ce = ca.ca_entry->e_private;
4701 req_add_s addr = op->oq_add;
4702 op->o_tag = LDAP_REQ_MODRDN;
4703 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
4704 op->o_tag = LDAP_REQ_ADD;
4706 if ( rs->sr_err != LDAP_SUCCESS ) {
4711 if ( cfb->cb_use_ldif ) {
4712 BackendDB *be = op->o_bd;
4713 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4714 struct berval dn, ndn;
4716 op->o_bd = &cfb->cb_db;
4718 /* Save current rootdn; use the underlying DB's rootdn */
4721 op->o_dn = op->o_bd->be_rootdn;
4722 op->o_ndn = op->o_bd->be_rootndn;
4724 scp = op->o_callback;
4725 op->o_callback = ≻
4726 op->o_bd->be_add( op, rs );
4728 op->o_callback = scp;
4734 ldap_pvt_thread_pool_resume( &connection_pool );
4737 send_ldap_result( op, rs );
4738 slap_graduate_commit_csn( op );
4742 typedef struct delrec {
4743 struct delrec *next;
4749 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
4754 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
4755 ca->line[0] == '{' )
4757 char *ptr = strchr( ca->line + 1, '}' );
4761 ca->valx = strtol( ca->line + 1, &next, 0 );
4762 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
4768 rc = config_parse_add( ct, ca, i );
4776 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
4779 int rc = LDAP_UNWILLING_TO_PERFORM;
4781 Entry *e = ce->ce_entry;
4782 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
4787 delrec *dels = NULL, *deltail = NULL;
4789 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4790 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
4792 colst = count_ocs( oc_at, &nocs );
4794 /* make sure add/del flags are clear; should always be true */
4795 for ( s = save_attrs; s; s = s->a_next ) {
4796 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
4799 e->e_attrs = attrs_dup( e->e_attrs );
4801 init_config_argv( ca );
4804 ca->ca_private = ce->ce_private;
4806 ca->fname = "slapd";
4808 strcpy( ca->log, "back-config" );
4810 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
4811 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
4812 switch (ml->sml_op) {
4813 case LDAP_MOD_DELETE:
4814 case LDAP_MOD_REPLACE: {
4815 BerVarray vals = NULL, nvals = NULL;
4817 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
4819 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
4820 ml->sml_desc->ad_cname.bv_val );
4823 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4824 vals = ml->sml_values;
4825 nvals = ml->sml_nvalues;
4826 ml->sml_values = NULL;
4827 ml->sml_nvalues = NULL;
4829 /* If we're deleting by values, remember the indexes of the
4830 * values we deleted.
4832 if ( ct && ml->sml_values ) {
4834 i = ml->sml_numvals;
4835 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
4846 rc = modify_delete_vindex(e, &ml->sml_mod,
4847 get_permissiveModify(op),
4848 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
4849 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4850 ml->sml_values = vals;
4851 ml->sml_nvalues = nvals;
4856 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
4859 case SLAP_MOD_SOFTADD: {
4860 int mop = ml->sml_op;
4862 ml->sml_op = LDAP_MOD_ADD;
4864 if ( ct->arg_type & ARG_NO_INSERT ) {
4865 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
4867 navals = a->a_numvals;
4870 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
4871 if ( ml->sml_values[i].bv_val[0] == '{' &&
4874 char *next, *val = ml->sml_values[i].bv_val + 1;
4877 j = strtol( val, &next, 0 );
4878 if ( next == val || next[ 0 ] != '}' || j < navals ) {
4880 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
4881 ml->sml_desc->ad_cname.bv_val );
4885 rc = check_vals( ct, ca, ml, 0 );
4886 if ( rc ) goto out_noop;
4889 rc = modify_add_values(e, &ml->sml_mod,
4890 get_permissiveModify(op),
4891 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
4893 /* If value already exists, show success here
4894 * and ignore this operation down below.
4896 if ( mop == SLAP_MOD_SOFTADD ) {
4897 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
4907 case LDAP_MOD_INCREMENT: /* FIXME */
4912 if(rc != LDAP_SUCCESS) break;
4915 if ( rc == LDAP_SUCCESS) {
4916 /* check that the entry still obeys the schema */
4917 rc = entry_schema_check(op, e, NULL, 0, 0,
4918 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
4920 if ( rc ) goto out_noop;
4922 /* Basic syntax checks are OK. Do the actual settings. */
4923 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
4924 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
4925 if ( !ct ) continue;
4927 s = attr_find( save_attrs, ml->sml_desc );
4928 a = attr_find( e->e_attrs, ml->sml_desc );
4930 switch (ml->sml_op) {
4931 case LDAP_MOD_DELETE:
4932 case LDAP_MOD_REPLACE: {
4933 BerVarray vals = NULL, nvals = NULL;
4936 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4937 vals = ml->sml_values;
4938 nvals = ml->sml_nvalues;
4939 ml->sml_values = NULL;
4940 ml->sml_nvalues = NULL;
4943 if ( ml->sml_values )
4946 /* If we didn't delete the whole attribute */
4947 if ( ml->sml_values && a ) {
4948 struct berval *mvals;
4951 if ( ml->sml_nvalues )
4952 mvals = ml->sml_nvalues;
4954 mvals = ml->sml_values;
4956 /* use the indexes we saved up above */
4957 for (i=0; i < d->nidx; i++) {
4958 struct berval bv = *mvals++;
4959 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
4960 bv.bv_val[0] == '{' ) {
4961 ptr = strchr( bv.bv_val, '}' ) + 1;
4962 bv.bv_len -= ptr - bv.bv_val;
4965 ca->line = bv.bv_val;
4966 ca->valx = d->idx[i];
4967 rc = config_del_vals( ct, ca );
4968 if ( rc != LDAP_SUCCESS ) break;
4970 s->a_flags |= SLAP_ATTR_IXDEL;
4971 for (j=i+1; j < d->nidx; j++)
4972 if ( d->idx[j] >d->idx[i] )
4978 rc = config_del_vals( ct, ca );
4979 if ( rc ) rc = LDAP_OTHER;
4981 s->a_flags |= SLAP_ATTR_IXDEL;
4983 if ( ml->sml_values ) {
4988 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4989 ml->sml_values = vals;
4990 ml->sml_nvalues = nvals;
4992 if ( !vals || rc != LDAP_SUCCESS )
4995 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
4998 for (i=0; ml->sml_values[i].bv_val; i++) {
4999 ca->line = ml->sml_values[i].bv_val;
5001 rc = config_modify_add( ct, ca, ml->sml_desc, i );
5004 a->a_flags |= SLAP_ATTR_IXADD;
5011 /* Undo for a failed operation */
5012 if ( rc != LDAP_SUCCESS ) {
5013 ConfigReply msg = ca->reply;
5014 for ( s = save_attrs; s; s = s->a_next ) {
5015 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
5016 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5017 ct = config_find_table( colst, nocs, s->a_desc, ca );
5018 a = attr_find( e->e_attrs, s->a_desc );
5020 /* clear the flag so the add check below will skip it */
5021 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5024 config_del_vals( ct, ca );
5026 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5027 ca->line = s->a_vals[i].bv_val;
5029 config_modify_add( ct, ca, s->a_desc, i );
5033 for ( a = e->e_attrs; a; a = a->a_next ) {
5034 if ( a->a_flags & SLAP_ATTR_IXADD ) {
5035 ct = config_find_table( colst, nocs, a->a_desc, ca );
5038 config_del_vals( ct, ca );
5039 s = attr_find( save_attrs, a->a_desc );
5041 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5042 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5043 ca->line = s->a_vals[i].bv_val;
5045 config_modify_add( ct, ca, s->a_desc, i );
5056 if ( rc == LDAP_SUCCESS ) {
5057 attrs_free( save_attrs );
5059 attrs_free( e->e_attrs );
5060 e->e_attrs = save_attrs;
5062 ch_free( ca->argv );
5063 if ( colst ) ch_free( colst );
5065 deltail = dels->next;
5074 config_back_modify( Operation *op, SlapReply *rs )
5077 CfEntryInfo *ce, *last;
5079 ConfigArgs ca = {0};
5082 AttributeDescription *rad = NULL;
5085 cfb = (CfBackInfo *)op->o_bd->be_private;
5087 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5090 rs->sr_matched = last->ce_entry->e_name.bv_val;
5091 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5095 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
5096 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5100 /* Get type of RDN */
5101 rdn = ce->ce_entry->e_nname;
5102 ptr = strchr( rdn.bv_val, '=' );
5103 rdn.bv_len = ptr - rdn.bv_val;
5104 slap_bv2ad( &rdn, &rad, &rs->sr_text );
5106 /* Some basic validation... */
5107 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5108 /* Don't allow Modify of RDN; must use ModRdn for that. */
5109 if ( ml->sml_desc == rad ) {
5110 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
5111 rs->sr_text = "Use modrdn to change the entry name";
5114 /* Internal update of contextCSN? */
5115 if ( ml->sml_desc == slap_schema.si_ad_contextCSN && op->o_conn->c_conn_idx == -1 ) {
5121 slap_mods_opattrs( op, &op->orm_modlist, 1 );
5124 ldap_pvt_thread_pool_pause( &connection_pool );
5127 * 1) perform the Modify on the cached Entry.
5128 * 2) verify that the Entry still satisfies the schema.
5129 * 3) perform the individual config operations.
5130 * 4) store Modified entry in underlying LDIF backend.
5132 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
5134 rs->sr_text = ca.cr_msg;
5135 } else if ( cfb->cb_use_ldif ) {
5136 BackendDB *be = op->o_bd;
5137 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5138 struct berval dn, ndn;
5140 op->o_bd = &cfb->cb_db;
5144 op->o_dn = op->o_bd->be_rootdn;
5145 op->o_ndn = op->o_bd->be_rootndn;
5147 scp = op->o_callback;
5148 op->o_callback = ≻
5149 op->o_bd->be_modify( op, rs );
5151 op->o_callback = scp;
5157 ldap_pvt_thread_pool_resume( &connection_pool );
5159 send_ldap_result( op, rs );
5160 slap_graduate_commit_csn( op );
5165 config_back_modrdn( Operation *op, SlapReply *rs )
5168 CfEntryInfo *ce, *last;
5172 cfb = (CfBackInfo *)op->o_bd->be_private;
5174 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5177 rs->sr_matched = last->ce_entry->e_name.bv_val;
5178 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5181 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
5182 NULL, ACL_WRITE, NULL )) {
5183 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5187 if ( ce->ce_parent )
5188 parent = ce->ce_parent->ce_entry;
5190 parent = (Entry *)&slap_entry_root;
5191 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
5192 NULL, ACL_WRITE, NULL )) {
5193 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5198 /* We don't allow moving objects to new parents.
5199 * Generally we only allow reordering a set of ordered entries.
5201 if ( op->orr_newSup ) {
5202 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5206 /* If newRDN == oldRDN, quietly succeed */
5207 dnRdn( &op->o_req_ndn, &rdn );
5208 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
5209 rs->sr_err = LDAP_SUCCESS;
5213 /* Current behavior, subject to change as needed:
5215 * For backends and overlays, we only allow renumbering.
5216 * For schema, we allow renaming with the same number.
5217 * Otherwise, the op is not allowed.
5220 if ( ce->ce_type == Cft_Schema ) {
5224 /* Can't alter the main cn=schema entry */
5225 if ( ce->ce_parent->ce_type == Cft_Global ) {
5226 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5227 rs->sr_text = "renaming not allowed for this entry";
5231 /* We could support this later if desired */
5232 ptr1 = ber_bvchr( &rdn, '}' );
5233 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5234 len = ptr1 - rdn.bv_val;
5235 if ( len != ptr2 - op->orr_newrdn.bv_val ||
5236 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
5237 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5238 rs->sr_text = "schema reordering not supported";
5241 } else if ( ce->ce_type == Cft_Database ||
5242 ce->ce_type == Cft_Overlay ) {
5243 char *ptr1, *ptr2, *iptr1, *iptr2;
5246 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
5247 if ( *iptr2 != '{' ) {
5248 rs->sr_err = LDAP_NAMING_VIOLATION;
5249 rs->sr_text = "new ordering index is required";
5253 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
5254 ptr1 = ber_bvchr( &rdn, '}' );
5255 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5257 rs->sr_err = LDAP_NAMING_VIOLATION;
5258 rs->sr_text = "new ordering index is required";
5262 len1 = ptr1 - rdn.bv_val;
5263 len2 = ptr2 - op->orr_newrdn.bv_val;
5265 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
5266 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
5267 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5268 rs->sr_text = "changing database/overlay type not allowed";
5271 ixold = strtol( iptr1, NULL, 0 );
5272 ixnew = strtol( iptr2, &ptr1, 0 );
5273 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
5274 rs->sr_err = LDAP_NAMING_VIOLATION;
5277 /* config DB is always 0, cannot be changed */
5278 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
5279 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
5283 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5284 rs->sr_text = "renaming not supported for this entry";
5288 ldap_pvt_thread_pool_pause( &connection_pool );
5290 if ( ce->ce_type == Cft_Schema ) {
5291 req_modrdn_s modr = op->oq_modrdn;
5294 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
5295 if ( rs->sr_err == LDAP_SUCCESS ) {
5296 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
5297 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
5300 op->oq_modrdn = modr;
5302 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
5303 req_modrdn_s modr = op->oq_modrdn;
5306 /* Advance to first of this type */
5307 cprev = &ce->ce_parent->ce_kids;
5308 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
5309 cprev = &ce2->ce_sibs;
5312 /* Skip the -1 entry */
5313 if ( ce->ce_type == Cft_Database ) {
5314 cprev = &ce2->ce_sibs;
5320 /* Remove from old slot */
5321 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
5322 cprev = &ce2->ce_sibs;
5323 *cprev = ce->ce_sibs;
5324 ceold = ce->ce_sibs;
5326 /* Insert into new slot */
5328 for ( i=0; i<ixnew; i++ ) {
5332 cprev = &ce2->ce_sibs;
5334 ce->ce_sibs = *cprev;
5339 /* NOTE: These should be encoded in the OC tables, not inline here */
5340 if ( ce->ce_type == Cft_Database )
5341 backend_db_move( ce->ce_be, ixnew );
5342 else if ( ce->ce_type == Cft_Overlay )
5343 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
5345 if ( ixold < ixnew ) {
5346 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
5349 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
5350 ixold - ixnew, cfb->cb_use_ldif );
5352 op->oq_modrdn = modr;
5355 ldap_pvt_thread_pool_resume( &connection_pool );
5357 send_ldap_result( op, rs );
5362 config_back_delete( Operation *op, SlapReply *rs )
5364 #ifdef SLAP_CONFIG_DELETE
5366 CfEntryInfo *ce, *last, *ce2;
5368 cfb = (CfBackInfo *)op->o_bd->be_private;
5370 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5373 rs->sr_matched = last->ce_entry->e_name.bv_val;
5374 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5375 } else if ( ce->ce_kids ) {
5376 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5377 } else if ( ce->ce_type == Cft_Overlay || ce->ce_type == Cft_Database ){
5381 ldap_pvt_thread_pool_pause( &connection_pool );
5383 if ( ce->ce_type == Cft_Overlay ){
5384 overlay_remove( ce->ce_be, (slap_overinst *)ce->ce_bi );
5385 } else { /* Cft_Database*/
5386 if ( ce->ce_be == frontendDB || ce->ce_be == op->o_bd ){
5387 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5388 rs->sr_text = "Cannot delete config or frontend database";
5389 ldap_pvt_thread_pool_resume( &connection_pool );
5392 if ( ce->ce_be->bd_info->bi_db_close ) {
5393 ce->ce_be->bd_info->bi_db_close( ce->ce_be, NULL );
5395 backend_destroy_one( ce->ce_be, 1);
5398 /* remove CfEntryInfo from the siblings list */
5399 if ( ce->ce_parent->ce_kids == ce ) {
5400 ce->ce_parent->ce_kids = ce->ce_sibs;
5402 for ( ce2 = ce->ce_parent->ce_kids ; ce2; ce2 = ce2->ce_sibs ) {
5403 if ( ce2->ce_sibs == ce ) {
5404 ce2->ce_sibs = ce->ce_sibs;
5410 /* remove from underlying database */
5411 if ( cfb->cb_use_ldif ) {
5412 BackendDB *be = op->o_bd;
5413 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5414 struct berval dn, ndn, req_dn, req_ndn;
5416 op->o_bd = &cfb->cb_db;
5420 req_dn = op->o_req_dn;
5421 req_ndn = op->o_req_ndn;
5423 op->o_dn = op->o_bd->be_rootdn;
5424 op->o_ndn = op->o_bd->be_rootndn;
5425 op->o_req_dn = ce->ce_entry->e_name;
5426 op->o_req_ndn = ce->ce_entry->e_nname;
5428 scp = op->o_callback;
5429 op->o_callback = ≻
5430 op->o_bd->be_delete( op, rs );
5432 op->o_callback = scp;
5435 op->o_req_dn = req_dn;
5436 op->o_req_ndn = req_ndn;
5439 /* renumber siblings */
5440 iptr = ber_bvchr( &op->o_req_ndn, '{' ) + 1;
5441 ixold = strtol( iptr, NULL, 0 );
5442 for (ce2 = ce->ce_sibs, count=0; ce2; ce2=ce2->ce_sibs) {
5443 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5444 count+ixold, 0, cfb->cb_use_ldif );
5448 ce->ce_entry->e_private=NULL;
5449 entry_free(ce->ce_entry);
5451 ldap_pvt_thread_pool_resume( &connection_pool );
5453 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5456 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5457 #endif /* SLAP_CONFIG_DELETE */
5459 send_ldap_result( op, rs );
5464 config_back_search( Operation *op, SlapReply *rs )
5467 CfEntryInfo *ce, *last;
5470 cfb = (CfBackInfo *)op->o_bd->be_private;
5472 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5475 rs->sr_matched = last->ce_entry->e_name.bv_val;
5476 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5479 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
5480 ACL_SEARCH, NULL, &mask ))
5482 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
5483 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5485 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5489 switch ( op->ors_scope ) {
5490 case LDAP_SCOPE_BASE:
5491 case LDAP_SCOPE_SUBTREE:
5492 config_send( op, rs, ce, 0 );
5495 case LDAP_SCOPE_ONELEVEL:
5496 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
5497 config_send( op, rs, ce, 1 );
5502 rs->sr_err = LDAP_SUCCESS;
5504 send_ldap_result( op, rs );
5508 /* no-op, we never free entries */
5509 int config_entry_release(
5514 if ( !e->e_private ) {
5517 return LDAP_SUCCESS;
5520 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
5522 int config_back_entry_get(
5526 AttributeDescription *at,
5531 CfEntryInfo *ce, *last;
5532 int rc = LDAP_NO_SUCH_OBJECT;
5534 cfb = (CfBackInfo *)op->o_bd->be_private;
5536 ce = config_find_base( cfb->cb_root, ndn, &last );
5538 *ent = ce->ce_entry;
5541 if ( oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
5542 rc = LDAP_NO_SUCH_ATTRIBUTE;
5552 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
5553 ConfigTable *ct, ConfigArgs *c )
5557 for (; at && *at; at++) {
5558 /* Skip the naming attr */
5559 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
5561 for (i=0;ct[i].name;i++) {
5562 if (ct[i].ad == (*at)->sat_ad) {
5563 rc = config_get_vals(&ct[i], c);
5564 /* NOTE: tolerate that config_get_vals()
5565 * returns success with no values */
5566 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
5567 if ( c->rvalue_nvals )
5568 rc = attr_merge(e, ct[i].ad, c->rvalue_vals,
5571 slap_syntax_validate_func *validate =
5572 ct[i].ad->ad_type->sat_syntax->ssyn_validate;
5575 for ( j=0; c->rvalue_vals[j].bv_val; j++ ) {
5576 rc = ordered_value_validate( ct[i].ad,
5577 &c->rvalue_vals[j], LDAP_MOD_ADD );
5579 Debug( LDAP_DEBUG_ANY,
5580 "config_build_attrs: error %d on %s value #%d\n",
5581 rc, ct[i].ad->ad_cname.bv_val, j );
5587 rc = attr_merge_normalize(e, ct[i].ad,
5588 c->rvalue_vals, NULL);
5590 ber_bvarray_free( c->rvalue_nvals );
5591 ber_bvarray_free( c->rvalue_vals );
5593 Debug( LDAP_DEBUG_ANY,
5594 "config_build_attrs: error %d on %s\n",
5595 rc, ct[i].ad->ad_cname.bv_val, 0 );
5607 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
5608 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
5610 Entry *e = entry_alloc();
5611 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5613 struct berval ad_name;
5614 AttributeDescription *ad = NULL;
5617 const char *text = "";
5621 CfEntryInfo *ceprev = NULL;
5623 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
5626 ce->ce_type = main->co_type;
5627 ce->ce_parent = parent;
5629 pdn = parent->ce_entry->e_nname;
5630 if ( parent->ce_kids && parent->ce_kids->ce_type <= ce->ce_type )
5631 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
5632 ceprev->ce_type <= ce->ce_type;
5633 ceprev = ceprev->ce_sibs );
5638 ce->ce_private = c->ca_private;
5642 build_new_dn( &e->e_name, &pdn, rdn, NULL );
5643 ber_dupbv( &e->e_nname, &e->e_name );
5645 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
5646 main->co_name, NULL );
5648 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
5649 extra->co_name, NULL );
5650 ptr = strchr(rdn->bv_val, '=');
5651 ad_name.bv_val = rdn->bv_val;
5652 ad_name.bv_len = ptr - rdn->bv_val;
5653 rc = slap_bv2ad( &ad_name, &ad, &text );
5658 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
5659 attr_merge_normalize_one(e, ad, &val, NULL );
5662 c->table = main->co_type;
5663 if ( oc->soc_required ) {
5664 rc = config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
5665 if ( rc ) goto fail;
5668 if ( oc->soc_allowed ) {
5669 rc = config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
5670 if ( rc ) goto fail;
5675 c->table = extra->co_type;
5676 if ( oc->soc_required ) {
5677 rc = config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
5678 if ( rc ) goto fail;
5681 if ( oc->soc_allowed ) {
5682 rc = config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
5683 if ( rc ) goto fail;
5687 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5688 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
5689 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
5690 if ( rc != LDAP_SUCCESS ) {
5692 Debug( LDAP_DEBUG_ANY,
5693 "config_build_entry: build \"%s\" failed: \"%s\"\n",
5694 rdn->bv_val, text, 0);
5697 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
5700 op->ora_modlist = NULL;
5701 slap_add_opattrs( op, NULL, NULL, 0, 0 );
5702 if ( !op->o_noop ) {
5703 op->o_bd->be_add( op, rs );
5704 if ( ( rs->sr_err != LDAP_SUCCESS )
5705 && (rs->sr_err != LDAP_ALREADY_EXISTS) ) {
5711 ce->ce_sibs = ceprev->ce_sibs;
5712 ceprev->ce_sibs = ce;
5713 } else if ( parent ) {
5714 ce->ce_sibs = parent->ce_kids;
5715 parent->ce_kids = ce;
5722 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
5723 Operation *op, SlapReply *rs )
5726 ConfigFile *cf = c->ca_private;
5728 struct berval bv, rdn;
5730 for (; cf; cf=cf->c_sibs, c->depth++) {
5731 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
5732 !cf->c_om_head && !cf->c_syn_head ) continue;
5733 c->value_dn.bv_val = c->log;
5734 LUTIL_SLASHPATH( cf->c_file.bv_val );
5735 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
5740 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
5742 ptr = strchr( bv.bv_val, '.' );
5744 bv.bv_len = ptr - bv.bv_val;
5745 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
5746 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
5747 /* FIXME: how can indicate error? */
5750 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
5752 c->value_dn.bv_len += bv.bv_len;
5753 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
5757 e = config_build_entry( op, rs, ceparent, c, &rdn,
5758 &CFOC_SCHEMA, NULL );
5761 } else if ( e && cf->c_kids ) {
5762 c->ca_private = cf->c_kids;
5763 config_build_schema_inc( c, e->e_private, op, rs );
5769 #ifdef SLAPD_MODULES
5772 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
5773 Operation *op, SlapReply *rs )
5778 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
5779 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
5781 c->value_dn.bv_val = c->log;
5782 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
5783 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
5784 /* FIXME: how can indicate error? */
5788 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
5797 config_check_schema(Operation *op, CfBackInfo *cfb)
5799 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
5801 CfEntryInfo *ce, *last;
5804 /* If there's no root entry, we must be in the midst of converting */
5805 if ( !cfb->cb_root )
5808 /* Make sure the main schema entry exists */
5809 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
5816 /* Make sure it's up to date */
5817 if ( cf_om_tail != om_sys_tail ) {
5818 a = attr_find( e->e_attrs, cfAd_om );
5820 if ( a->a_nvals != a->a_vals )
5821 ber_bvarray_free( a->a_nvals );
5822 ber_bvarray_free( a->a_vals );
5827 oidm_unparse( &bv, NULL, NULL, 1 );
5828 attr_merge_normalize( e, cfAd_om, bv, NULL );
5829 ber_bvarray_free( bv );
5830 cf_om_tail = om_sys_tail;
5832 if ( cf_at_tail != at_sys_tail ) {
5833 a = attr_find( e->e_attrs, cfAd_attr );
5835 if ( a->a_nvals != a->a_vals )
5836 ber_bvarray_free( a->a_nvals );
5837 ber_bvarray_free( a->a_vals );
5842 at_unparse( &bv, NULL, NULL, 1 );
5843 attr_merge_normalize( e, cfAd_attr, bv, NULL );
5844 ber_bvarray_free( bv );
5845 cf_at_tail = at_sys_tail;
5847 if ( cf_oc_tail != oc_sys_tail ) {
5848 a = attr_find( e->e_attrs, cfAd_oc );
5850 if ( a->a_nvals != a->a_vals )
5851 ber_bvarray_free( a->a_nvals );
5852 ber_bvarray_free( a->a_vals );
5857 oc_unparse( &bv, NULL, NULL, 1 );
5858 attr_merge_normalize( e, cfAd_oc, bv, NULL );
5859 ber_bvarray_free( bv );
5860 cf_oc_tail = oc_sys_tail;
5862 if ( cf_syn_tail != syn_sys_tail ) {
5863 a = attr_find( e->e_attrs, cfAd_syntax );
5865 if ( a->a_nvals != a->a_vals )
5866 ber_bvarray_free( a->a_nvals );
5867 ber_bvarray_free( a->a_vals );
5872 syn_unparse( &bv, NULL, NULL, 1 );
5873 attr_merge_normalize( e, cfAd_syntax, bv, NULL );
5874 ber_bvarray_free( bv );
5875 cf_syn_tail = syn_sys_tail;
5878 SlapReply rs = {REP_RESULT};
5879 c.ca_private = NULL;
5880 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
5881 &CFOC_SCHEMA, NULL );
5886 ce->ce_private = cfb->cb_config;
5887 cf_at_tail = at_sys_tail;
5888 cf_oc_tail = oc_sys_tail;
5889 cf_om_tail = om_sys_tail;
5890 cf_syn_tail = syn_sys_tail;
5895 static const char *defacl[] = {
5896 NULL, "to", "*", "by", "*", "none", NULL
5900 config_back_db_open( BackendDB *be, ConfigReply *cr )
5902 CfBackInfo *cfb = be->be_private;
5905 CfEntryInfo *ce, *ceparent;
5909 Connection conn = {0};
5910 OperationBuffer opbuf;
5912 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
5913 SlapReply rs = {REP_RESULT};
5914 void *thrctx = NULL;
5916 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
5918 /* If we have no explicitly configured ACLs, don't just use
5919 * the global ACLs. Explicitly deny access to everything.
5921 if ( frontendDB->be_acl && be->be_acl == frontendDB->be_acl ) {
5922 parse_acl(be, "config_back_db_open", 0, 6, (char **)defacl, 0 );
5925 thrctx = ldap_pvt_thread_pool_context();
5926 connection_fake_init( &conn, &opbuf, thrctx );
5929 op->o_tag = LDAP_REQ_ADD;
5930 op->o_callback = &cb;
5931 op->o_bd = &cfb->cb_db;
5932 op->o_dn = op->o_bd->be_rootdn;
5933 op->o_ndn = op->o_bd->be_rootndn;
5935 if ( !cfb->cb_use_ldif ) {
5939 /* If we read the config from back-ldif, do some quick sanity checks */
5940 if ( cfb->cb_got_ldif ) {
5941 return config_check_schema( op, cfb );
5944 /* create root of tree */
5946 c.ca_private = cfb->cb_config;
5948 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
5958 #ifdef SLAPD_MODULES
5959 /* Create Module nodes... */
5960 if ( modpaths.mp_loads ) {
5961 if ( config_build_modules( &c, ceparent, op, &rs ) ){
5967 /* Create schema nodes... cn=schema will contain the hardcoded core
5968 * schema, read-only. Child objects will contain runtime loaded schema
5972 c.ca_private = NULL;
5973 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
5978 ce->ce_private = cfb->cb_config;
5979 cf_at_tail = at_sys_tail;
5980 cf_oc_tail = oc_sys_tail;
5981 cf_om_tail = om_sys_tail;
5982 cf_syn_tail = syn_sys_tail;
5984 /* Create schema nodes for included schema... */
5985 if ( cfb->cb_config->c_kids ) {
5987 c.ca_private = cfb->cb_config->c_kids;
5988 if (config_build_schema_inc( &c, ce, op, &rs )) {
5993 /* Create backend nodes. Skip if they don't provide a cf_table.
5994 * There usually aren't any of these.
5998 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
5999 if (!bi->bi_cf_ocs) {
6000 /* If it only supports the old config mech, complain. */
6001 if ( bi->bi_config ) {
6002 Debug( LDAP_DEBUG_ANY,
6003 "WARNING: No dynamic config support for backend %s.\n",
6004 bi->bi_type, 0, 0 );
6009 if (!bi->bi_private) continue;
6012 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6013 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
6014 if ( rdn.bv_len >= sizeof( c.log ) ) {
6015 /* FIXME: holler ... */ ;
6018 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
6025 /* Create database nodes... */
6026 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
6027 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
6028 for ( i = -1, be = frontendDB ; be;
6029 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
6030 slap_overinfo *oi = NULL;
6032 if ( overlay_is_over( be )) {
6033 oi = be->bd_info->bi_private;
6039 /* If this backend supports the old config mechanism, but not
6040 * the new mech, complain.
6042 if ( !be->be_cf_ocs && bi->bi_db_config ) {
6043 Debug( LDAP_DEBUG_ANY,
6044 "WARNING: No dynamic config support for database %s.\n",
6045 bi->bi_type, 0, 0 );
6049 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6050 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
6052 if ( rdn.bv_len >= sizeof( c.log ) ) {
6053 /* FIXME: holler ... */ ;
6057 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
6063 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd )
6064 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
6065 /* Iterate through overlays */
6070 voidList *vl, *v0 = NULL;
6072 /* overlays are in LIFO order, must reverse stack */
6073 for (on=oi->oi_list; on; on=on->on_next) {
6074 vl = ch_malloc( sizeof( voidList ));
6079 for (j=0; vl; j++,vl=v0) {
6083 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
6084 Debug( LDAP_DEBUG_ANY,
6085 "WARNING: No dynamic config support for overlay %s.\n",
6086 on->on_bi.bi_type, 0, 0 );
6090 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6091 "%s=" SLAP_X_ORDERED_FMT "%s",
6092 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
6093 if ( rdn.bv_len >= sizeof( c.log ) ) {
6094 /* FIXME: holler ... */ ;
6098 oe = config_build_entry( op, &rs, ce, &c, &rdn,
6099 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
6103 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd )
6104 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
6109 ldap_pvt_thread_pool_context_reset( thrctx );
6111 if ( unsupp && cfb->cb_use_ldif ) {
6112 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
6113 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
6120 cfb_free_cffile( ConfigFile *cf )
6124 for (; cf; cf=next) {
6127 cfb_free_cffile( cf->c_kids );
6128 ch_free( cf->c_file.bv_val );
6129 ber_bvarray_free( cf->c_dseFiles );
6135 cfb_free_entries( CfEntryInfo *ce )
6139 for (; ce; ce=next) {
6142 cfb_free_entries( ce->ce_kids );
6143 ce->ce_entry->e_private = NULL;
6144 entry_free( ce->ce_entry );
6150 config_back_db_close( BackendDB *be, ConfigReply *cr )
6152 CfBackInfo *cfb = be->be_private;
6154 cfb_free_entries( cfb->cb_root );
6155 cfb->cb_root = NULL;
6157 if ( cfb->cb_db.bd_info ) {
6158 backend_shutdown( &cfb->cb_db );
6165 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
6167 CfBackInfo *cfb = be->be_private;
6169 cfb_free_cffile( cfb->cb_config );
6171 ch_free( cfdir.bv_val );
6173 avl_free( CfOcTree, NULL );
6175 if ( cfb->cb_db.bd_info ) {
6176 cfb->cb_db.be_suffix = NULL;
6177 cfb->cb_db.be_nsuffix = NULL;
6178 BER_BVZERO( &cfb->cb_db.be_rootdn );
6179 BER_BVZERO( &cfb->cb_db.be_rootndn );
6181 backend_destroy_one( &cfb->cb_db, 0 );
6190 config_back_db_init( BackendDB *be, ConfigReply* cr )
6196 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
6197 cfn = cfb->cb_config;
6198 be->be_private = cfb;
6200 ber_dupbv( &be->be_rootdn, &config_rdn );
6201 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
6202 ber_dupbv( &dn, &be->be_rootdn );
6203 ber_bvarray_add( &be->be_suffix, &dn );
6204 ber_dupbv( &dn, &be->be_rootdn );
6205 ber_bvarray_add( &be->be_nsuffix, &dn );
6207 /* Hide from namingContexts */
6208 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
6214 config_back_destroy( BackendInfo *bi )
6216 ldif_must_b64_encode_release();
6221 config_tool_entry_open( BackendDB *be, int mode )
6223 CfBackInfo *cfb = be->be_private;
6224 BackendInfo *bi = cfb->cb_db.bd_info;
6226 if ( bi && bi->bi_tool_entry_open )
6227 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
6234 config_tool_entry_close( BackendDB *be )
6236 CfBackInfo *cfb = be->be_private;
6237 BackendInfo *bi = cfb->cb_db.bd_info;
6239 if ( bi && bi->bi_tool_entry_close )
6240 return bi->bi_tool_entry_close( &cfb->cb_db );
6246 config_tool_entry_first( BackendDB *be )
6248 CfBackInfo *cfb = be->be_private;
6249 BackendInfo *bi = cfb->cb_db.bd_info;
6251 if ( bi && bi->bi_tool_entry_first )
6252 return bi->bi_tool_entry_first( &cfb->cb_db );
6258 config_tool_entry_next( BackendDB *be )
6260 CfBackInfo *cfb = be->be_private;
6261 BackendInfo *bi = cfb->cb_db.bd_info;
6263 if ( bi && bi->bi_tool_entry_next )
6264 return bi->bi_tool_entry_next( &cfb->cb_db );
6270 config_tool_entry_get( BackendDB *be, ID id )
6272 CfBackInfo *cfb = be->be_private;
6273 BackendInfo *bi = cfb->cb_db.bd_info;
6275 if ( bi && bi->bi_tool_entry_get )
6276 return bi->bi_tool_entry_get( &cfb->cb_db, id );
6281 static int entry_put_got_frontend=0;
6282 static int entry_put_got_config=0;
6284 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
6286 CfBackInfo *cfb = be->be_private;
6287 BackendInfo *bi = cfb->cb_db.bd_info;
6289 struct berval rdn, vals[ 2 ];
6291 OperationBuffer opbuf;
6293 Connection conn = {0};
6294 Operation *op = NULL;
6298 /* Create entry for frontend database if it does not exist already */
6299 if ( !entry_put_got_frontend ) {
6300 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
6301 STRLENOF( "olcDatabase" ))) {
6302 if ( strncmp( e->e_nname.bv_val +
6303 STRLENOF( "olcDatabase" ), "={-1}frontend",
6304 STRLENOF( "={-1}frontend" )) &&
6305 strncmp( e->e_nname.bv_val +
6306 STRLENOF( "olcDatabase" ), "=frontend",
6307 STRLENOF( "=frontend" ))) {
6309 vals[1].bv_val = NULL;
6310 memset( &ca, 0, sizeof(ConfigArgs));
6312 ca.bi = frontendDB->bd_info;
6313 ca.be->be_cf_ocs = &CFOC_FRONTEND;
6314 rdn.bv_val = ca.log;
6315 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
6316 "%s=" SLAP_X_ORDERED_FMT "%s",
6317 cfAd_database->ad_cname.bv_val, -1,
6319 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
6320 &CFOC_DATABASE, ca.be->be_cf_ocs );
6321 thrctx = ldap_pvt_thread_pool_context();
6322 connection_fake_init2( &conn, &opbuf, thrctx,0 );
6324 op->o_bd = &cfb->cb_db;
6325 op->o_tag = LDAP_REQ_ADD;
6327 op->o_dn = be->be_rootdn;
6328 op->o_ndn = be->be_rootndn;
6329 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
6330 if ( rc != LDAP_SUCCESS ) {
6331 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
6332 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
6336 if ( ce && bi && bi->bi_tool_entry_put &&
6337 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
6338 entry_put_got_frontend++;
6340 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
6341 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
6345 entry_put_got_frontend++;
6350 /* Create entry for config database if it does not exist already */
6351 if ( !entry_put_got_config && !isFrontend ) {
6352 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
6353 STRLENOF( "olcDatabase" ))) {
6354 if ( strncmp( e->e_nname.bv_val +
6355 STRLENOF( "olcDatabase" ), "={0}config",
6356 STRLENOF( "={0}config" )) &&
6357 strncmp( e->e_nname.bv_val +
6358 STRLENOF( "olcDatabase" ), "=config",
6359 STRLENOF( "=config" )) ) {
6361 vals[1].bv_val = NULL;
6362 memset( &ca, 0, sizeof(ConfigArgs));
6363 ca.be = LDAP_STAILQ_FIRST( &backendDB );
6364 ca.bi = ca.be->bd_info;
6365 rdn.bv_val = ca.log;
6366 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
6367 "%s=" SLAP_X_ORDERED_FMT "%s",
6368 cfAd_database->ad_cname.bv_val, 0,
6370 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
6373 thrctx = ldap_pvt_thread_pool_context();
6374 connection_fake_init2( &conn, &opbuf, thrctx,0 );
6376 op->o_bd = &cfb->cb_db;
6377 op->o_tag = LDAP_REQ_ADD;
6378 op->o_dn = be->be_rootdn;
6379 op->o_ndn = be->be_rootndn;
6382 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
6383 if ( rc != LDAP_SUCCESS ) {
6384 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
6385 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
6388 if (ce && bi && bi->bi_tool_entry_put &&
6389 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
6390 entry_put_got_config++;
6392 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
6393 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
6397 entry_put_got_config++;
6401 if ( bi && bi->bi_tool_entry_put &&
6402 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
6403 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
6410 AttributeDescription **desc;
6412 { "attribute", &cfAd_attr },
6413 { "backend", &cfAd_backend },
6414 { "database", &cfAd_database },
6415 { "include", &cfAd_include },
6416 { "ldapsyntax", &cfAd_syntax },
6417 { "objectclass", &cfAd_oc },
6418 { "objectidentifier", &cfAd_om },
6419 { "overlay", &cfAd_overlay },
6424 * add / delete: all types that may be added or deleted must use an
6425 * X-ORDERED attributeType for their RDN. Adding and deleting entries
6426 * should automatically renumber the index of any siblings as needed,
6427 * so that no gaps in the numbering sequence exist after the add/delete
6429 * What can be added:
6431 * backend objects for backend-specific config directives
6435 * delete: probably no support this time around.
6437 * modrdn: generally not done. Will be invoked automatically by add/
6438 * delete to update numbering sequence. Perform as an explicit operation
6439 * so that the renumbering effect may be replicated. Subtree rename must
6440 * be supported, since renumbering a database will affect all its child
6443 * modify: must be fully supported.
6447 config_back_initialize( BackendInfo *bi )
6449 ConfigTable *ct = config_back_cf_table;
6453 AttributeDescription *ad = NULL;
6455 static char *controls[] = {
6456 LDAP_CONTROL_MANAGEDSAIT,
6460 /* Make sure we don't exceed the bits reserved for userland */
6461 config_check_userland( CFG_LAST );
6463 bi->bi_controls = controls;
6468 bi->bi_destroy = config_back_destroy;
6470 bi->bi_db_init = config_back_db_init;
6471 bi->bi_db_config = 0;
6472 bi->bi_db_open = config_back_db_open;
6473 bi->bi_db_close = config_back_db_close;
6474 bi->bi_db_destroy = config_back_db_destroy;
6476 bi->bi_op_bind = config_back_bind;
6477 bi->bi_op_unbind = 0;
6478 bi->bi_op_search = config_back_search;
6479 bi->bi_op_compare = 0;
6480 bi->bi_op_modify = config_back_modify;
6481 bi->bi_op_modrdn = config_back_modrdn;
6482 bi->bi_op_add = config_back_add;
6483 bi->bi_op_delete = config_back_delete;
6484 bi->bi_op_abandon = 0;
6486 bi->bi_extended = 0;
6488 bi->bi_chk_referrals = 0;
6490 bi->bi_access_allowed = slap_access_allowed;
6492 bi->bi_connection_init = 0;
6493 bi->bi_connection_destroy = 0;
6495 bi->bi_entry_release_rw = config_entry_release;
6496 bi->bi_entry_get_rw = config_back_entry_get;
6498 bi->bi_tool_entry_open = config_tool_entry_open;
6499 bi->bi_tool_entry_close = config_tool_entry_close;
6500 bi->bi_tool_entry_first = config_tool_entry_first;
6501 bi->bi_tool_entry_next = config_tool_entry_next;
6502 bi->bi_tool_entry_get = config_tool_entry_get;
6503 bi->bi_tool_entry_put = config_tool_entry_put;
6506 argv[ 0 ] = "slapd";
6512 for (i=0; OidMacros[i].name; i++ ) {
6513 argv[1] = OidMacros[i].name;
6514 argv[2] = OidMacros[i].oid;
6515 parse_oidm( &ca, 0, NULL );
6518 bi->bi_cf_ocs = cf_ocs;
6520 i = config_register_schema( ct, cf_ocs );
6523 i = slap_str2ad( "olcDatabase", &olcDatabaseDummy[0].ad, &text );
6526 /* setup olcRootPW to be base64-encoded when written in LDIF form;
6527 * basically, we don't care if it fails */
6528 i = slap_str2ad( "olcRootPW", &ad, &text );
6530 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
6531 "warning, unable to get \"olcRootPW\" "
6532 "attribute description: %d: %s\n",
6535 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
6536 ad->ad_type->sat_oid );
6539 /* set up the notable AttributeDescriptions */
6541 for (;ct->name;ct++) {
6542 if (strcmp(ct->name, ads[i].name)) continue;
6543 *ads[i].desc = ct->ad;
6545 if (!ads[i].name) break;