1 /* bconfig.c - the config backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005-2009 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;
148 CFG_TLS_PROTOCOL_MIN,
197 static OidRec OidMacros[] = {
198 /* OpenLDAProot:1.12.2 */
199 { "OLcfg", "1.3.6.1.4.1.4203.1.12.2" },
200 { "OLcfgAt", "OLcfg:3" },
201 { "OLcfgGlAt", "OLcfgAt:0" },
202 { "OLcfgBkAt", "OLcfgAt:1" },
203 { "OLcfgDbAt", "OLcfgAt:2" },
204 { "OLcfgOvAt", "OLcfgAt:3" },
205 { "OLcfgCtAt", "OLcfgAt:4" }, /* contrib modules */
206 { "OLcfgOc", "OLcfg:4" },
207 { "OLcfgGlOc", "OLcfgOc:0" },
208 { "OLcfgBkOc", "OLcfgOc:1" },
209 { "OLcfgDbOc", "OLcfgOc:2" },
210 { "OLcfgOvOc", "OLcfgOc:3" },
211 { "OLcfgCtOc", "OLcfgOc:4" }, /* contrib modules */
213 /* Syntaxes. We should just start using the standard names and
214 * document that they are predefined and available for users
215 * to reference in their own schema. Defining schema without
216 * OID macros is for masochists...
218 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
219 { "OMsBoolean", "OMsyn:7" },
220 { "OMsDN", "OMsyn:12" },
221 { "OMsDirectoryString", "OMsyn:15" },
222 { "OMsIA5String", "OMsyn:26" },
223 { "OMsInteger", "OMsyn:27" },
224 { "OMsOID", "OMsyn:38" },
225 { "OMsOctetString", "OMsyn:40" },
230 * Backend/Database registry
232 * OLcfg{Bk|Db}{Oc|At}:0 -> common
233 * OLcfg{Bk|Db}{Oc|At}:1 -> back-bdb(/back-hdb)
234 * OLcfg{Bk|Db}{Oc|At}:2 -> back-ldif
235 * OLcfg{Bk|Db}{Oc|At}:3 -> back-ldap
236 * OLcfg{Bk|Db}{Oc|At}:4 -> back-monitor
237 * OLcfg{Bk|Db}{Oc|At}:5 -> back-relay
238 * OLcfg{Bk|Db}{Oc|At}:6 -> back-sql
239 * OLcfg{Bk|Db}{Oc|At}:7 -> back-sock
245 * OLcfgOv{Oc|At}:1 -> syncprov
246 * OLcfgOv{Oc|At}:2 -> pcache
247 * OLcfgOv{Oc|At}:3 -> chain
248 * OLcfgOv{Oc|At}:4 -> accesslog
249 * OLcfgOv{Oc|At}:5 -> valsort
250 * OLcfgOv{Oc|At}:7 -> distproc
251 * OLcfgOv{Oc|At}:8 -> dynlist
252 * OLcfgOv{Oc|At}:9 -> dds
253 * OLcfgOv{Oc|At}:10 -> unique
254 * OLcfgOv{Oc|At}:11 -> refint
255 * OLcfgOv{Oc|At}:12 -> ppolicy
256 * OLcfgOv{Oc|At}:13 -> constraint
257 * OLcfgOv{Oc|At}:14 -> translucent
258 * OLcfgOv{Oc|At}:15 -> auditlog
259 * OLcfgOv{Oc|At}:16 -> rwm
260 * OLcfgOv{Oc|At}:17 -> dyngroup
261 * OLcfgOv{Oc|At}:18 -> memberof
262 * OLcfgOv{Oc|At}:19 -> collect
263 * OLcfgOv{Oc|At}:20 -> retcode
266 /* alphabetical ordering */
268 static ConfigTable config_back_cf_table[] = {
269 /* This attr is read-only */
270 { "", "", 0, 0, 0, ARG_MAGIC,
271 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
272 "DESC 'File for slapd configuration directives' "
273 "EQUALITY caseIgnoreMatch "
274 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
275 { "", "", 0, 0, 0, ARG_MAGIC,
276 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
277 "DESC 'Directory for slapd configuration backend' "
278 "EQUALITY caseIgnoreMatch "
279 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
280 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
281 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
282 "DESC 'Access Control List' "
283 "EQUALITY caseIgnoreMatch "
284 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
285 { "add_content_acl", NULL, 0, 0, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_ACL_ADD,
286 &config_generic, "( OLcfgGlAt:86 NAME 'olcAddContentAcl' "
287 "DESC 'Check ACLs against content of Add ops' "
288 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
289 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
290 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
291 "DESC 'Allowed set of deprecated features' "
292 "EQUALITY caseIgnoreMatch "
293 "SYNTAX OMsDirectoryString )", NULL, NULL },
294 { "argsfile", "file", 2, 2, 0, ARG_STRING,
295 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
296 "DESC 'File for slapd command line options' "
297 "EQUALITY caseIgnoreMatch "
298 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
299 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
300 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
301 "EQUALITY caseIgnoreMatch "
302 "SYNTAX OMsDirectoryString )", NULL, NULL },
303 { "attribute", "attribute", 2, 0, STRLENOF( "attribute" ),
304 ARG_PAREN|ARG_MAGIC|CFG_ATTR,
305 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
306 "DESC 'OpenLDAP attributeTypes' "
307 "EQUALITY caseIgnoreMatch "
308 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
310 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
311 #ifdef SLAP_AUTH_REWRITE
312 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
316 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
317 "EQUALITY caseIgnoreMatch "
318 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
319 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
320 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
321 "EQUALITY caseIgnoreMatch "
322 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
323 { "authz-regexp", "regexp> <DN", 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
324 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
325 "EQUALITY caseIgnoreMatch "
326 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
327 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
328 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
329 "DESC 'A type of backend' "
330 "EQUALITY caseIgnoreMatch "
331 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
333 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
334 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
335 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
336 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
337 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
338 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
339 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
340 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
341 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
342 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
343 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
344 "DESC 'The backend type for a database instance' "
345 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
346 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
347 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
348 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
349 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
350 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
351 "EQUALITY caseIgnoreMatch "
352 "SYNTAX OMsDirectoryString )", NULL, NULL },
353 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
354 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
355 "DESC 'OpenLDAP DIT content rules' "
356 "EQUALITY caseIgnoreMatch "
357 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
359 { "gentlehup", "on|off", 2, 2, 0,
361 ARG_ON_OFF, &global_gentlehup,
365 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
366 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
367 { "hidden", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_HIDDEN,
368 &config_generic, "( OLcfgDbAt:0.17 NAME 'olcHidden' "
369 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
370 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
371 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
372 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
373 { "include", "file", 2, 2, 0, ARG_MAGIC,
374 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
375 "SUP labeledURI )", NULL, NULL },
376 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
377 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
378 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
379 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
380 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
381 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
382 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
383 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
384 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
385 { "index_substr_any_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
386 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
387 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
388 { "index_intlen", "len", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_IX_INTLEN,
389 &config_generic, "( OLcfgGlAt:84 NAME 'olcIndexIntLen' "
390 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
391 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
392 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
393 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
394 { "ldapsyntax", "syntax", 2, 0, 0,
395 ARG_PAREN|ARG_MAGIC|CFG_SYNTAX,
396 &config_generic, "( OLcfgGlAt:85 NAME 'olcLdapSyntaxes' "
397 "DESC 'OpenLDAP ldapSyntax' "
398 "EQUALITY caseIgnoreMatch "
399 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
401 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
402 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
403 "EQUALITY caseIgnoreMatch "
404 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
405 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
406 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
407 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
408 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
409 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
410 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
411 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
412 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
413 "EQUALITY caseIgnoreMatch "
414 "SYNTAX OMsDirectoryString )", NULL, NULL },
415 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
416 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
417 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
418 { "mirrormode", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_MIRRORMODE,
419 &config_generic, "( OLcfgDbAt:0.16 NAME 'olcMirrorMode' "
420 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
421 { "moduleload", "file", 2, 0, 0,
423 ARG_MAGIC|CFG_MODLOAD|ARG_NO_DELETE, &config_generic,
427 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
428 "EQUALITY caseIgnoreMatch "
429 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
430 { "modulepath", "path", 2, 2, 0,
432 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
436 "( OLcfgGlAt:31 NAME 'olcModulePath' "
437 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
438 { "monitoring", "TRUE|FALSE", 2, 2, 0,
439 ARG_MAGIC|CFG_MONITORING|ARG_DB|ARG_ON_OFF, &config_generic,
440 "( OLcfgDbAt:0.18 NAME 'olcMonitoring' "
441 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
442 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
443 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
444 "DESC 'OpenLDAP object classes' "
445 "EQUALITY caseIgnoreMatch "
446 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
448 { "objectidentifier", "name> <oid", 3, 3, 0, ARG_MAGIC|CFG_OID,
449 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
450 "EQUALITY caseIgnoreMatch "
451 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
452 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
453 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
454 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
455 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
456 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
457 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
458 { "password-hash", "hash", 2, 2, 0, ARG_MAGIC,
459 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
460 "EQUALITY caseIgnoreMatch "
461 "SYNTAX OMsDirectoryString )", NULL, NULL },
462 { "pidfile", "file", 2, 2, 0, ARG_STRING,
463 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
464 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
465 { "plugin", NULL, 0, 0, 0,
467 ARG_MAGIC|CFG_PLUGIN, &config_generic,
471 "( OLcfgGlAt:38 NAME 'olcPlugin' "
472 "EQUALITY caseIgnoreMatch "
473 "SYNTAX OMsDirectoryString )", NULL, NULL },
474 { "pluginlog", "filename", 2, 2, 0,
476 ARG_STRING, &slapi_log_file,
480 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
481 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
482 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
483 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
484 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
485 { "referral", "url", 2, 2, 0, ARG_MAGIC,
486 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
487 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
488 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
489 &config_obsolete, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
490 "EQUALITY caseIgnoreMatch "
491 "SUP labeledURI X-ORDERED 'VALUES' )", NULL, NULL },
492 { "replica-argsfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
493 &config_obsolete, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
494 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
495 { "replica-pidfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
496 &config_obsolete, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
497 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
498 { "replicationInterval", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
499 &config_obsolete, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
500 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
501 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC,
502 &config_obsolete, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
503 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
504 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
505 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
506 "EQUALITY caseIgnoreMatch "
507 "SYNTAX OMsDirectoryString )", NULL, NULL },
508 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
509 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
510 "EQUALITY caseIgnoreMatch "
511 "SYNTAX OMsDirectoryString )", NULL, NULL },
512 { "reverse-lookup", "on|off", 2, 2, 0,
513 #ifdef SLAPD_RLOOKUPS
514 ARG_ON_OFF, &use_reverse_lookup,
518 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
519 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
520 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
521 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
522 "EQUALITY distinguishedNameMatch "
523 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
524 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
525 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
526 "EQUALITY caseIgnoreMatch "
527 "SYNTAX OMsDirectoryString )", NULL, NULL },
528 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
529 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
530 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
531 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
532 &config_generic, NULL, NULL, NULL },
533 { "sasl-host", "host", 2, 2, 0,
534 #ifdef HAVE_CYRUS_SASL
535 ARG_STRING|ARG_UNIQUE, &sasl_host,
539 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
540 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
541 { "sasl-realm", "realm", 2, 2, 0,
542 #ifdef HAVE_CYRUS_SASL
543 ARG_STRING|ARG_UNIQUE, &global_realm,
547 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
548 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
549 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
550 &config_generic, NULL, NULL, NULL },
551 { "sasl-secprops", "properties", 2, 2, 0,
552 #ifdef HAVE_CYRUS_SASL
553 ARG_MAGIC|CFG_SASLSECP, &config_generic,
557 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
558 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
559 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
560 &config_generic, NULL, NULL, NULL },
561 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
562 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
563 "EQUALITY distinguishedNameMatch "
564 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
565 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
566 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
567 "EQUALITY caseIgnoreMatch "
568 "SYNTAX OMsDirectoryString )", NULL, NULL },
569 { "serverID", "number> <[URI]", 2, 3, 0, ARG_MAGIC|CFG_SERVERID,
570 &config_generic, "( OLcfgGlAt:81 NAME 'olcServerID' "
571 "EQUALITY caseIgnoreMatch "
572 "SYNTAX OMsDirectoryString )", NULL, NULL },
573 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
574 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
575 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
576 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
577 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
578 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
579 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
580 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
581 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
582 { "sortvals", "attr", 2, 0, 0, ARG_MAGIC|CFG_SORTVALS,
583 &config_generic, "( OLcfgGlAt:83 NAME 'olcSortVals' "
584 "DESC 'Attributes whose values will always be sorted' "
585 "EQUALITY caseIgnoreMatch "
586 "SYNTAX OMsDirectoryString )", NULL, NULL },
587 { "subordinate", "[advertise]", 1, 2, 0, ARG_DB|ARG_MAGIC,
588 &config_subordinate, "( OLcfgDbAt:0.15 NAME 'olcSubordinate' "
589 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
590 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
591 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
592 "EQUALITY distinguishedNameMatch "
593 "SYNTAX OMsDN )", NULL, NULL },
594 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
595 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
596 "EQUALITY caseIgnoreMatch "
597 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
598 { "threads", "count", 2, 2, 0,
602 ARG_INT|ARG_MAGIC|CFG_THREADS, &config_generic,
604 "( OLcfgGlAt:66 NAME 'olcThreads' "
605 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
606 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
607 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
608 "SYNTAX OMsDirectoryString )", NULL, NULL },
609 { "TLSCACertificateFile", NULL, 0, 0, 0,
611 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
615 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
616 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
617 { "TLSCACertificatePath", NULL, 0, 0, 0,
619 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
623 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
624 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
625 { "TLSCertificateFile", NULL, 0, 0, 0,
627 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
631 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
632 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
633 { "TLSCertificateKeyFile", NULL, 0, 0, 0,
635 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
639 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
640 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
641 { "TLSCipherSuite", NULL, 0, 0, 0,
643 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
647 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
648 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
649 { "TLSCRLCheck", NULL, 0, 0, 0,
650 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
651 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
655 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
656 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
657 { "TLSCRLFile", NULL, 0, 0, 0,
658 #if defined(HAVE_GNUTLS)
659 CFG_TLS_CRL_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
663 "( OLcfgGlAt:82 NAME 'olcTLSCRLFile' "
664 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
665 { "TLSRandFile", NULL, 0, 0, 0,
667 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
671 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
672 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
673 { "TLSVerifyClient", NULL, 0, 0, 0,
675 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
679 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
680 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
681 { "TLSDHParamFile", NULL, 0, 0, 0,
683 CFG_TLS_DH_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
687 "( OLcfgGlAt:77 NAME 'olcTLSDHParamFile' "
688 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
689 { "TLSProtocolMin", NULL, 0, 0, 0,
691 CFG_TLS_PROTOCOL_MIN|ARG_STRING|ARG_MAGIC, &config_tls_config,
695 "( OLcfgGlAt:87 NAME 'olcTLSProtocolMin' "
696 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
697 { "tool-threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_TTHREADS,
698 &config_generic, "( OLcfgGlAt:80 NAME 'olcToolThreads' "
699 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
700 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
701 NULL, NULL, NULL, NULL },
702 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
703 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
704 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
705 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
706 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
707 "EQUALITY caseIgnoreMatch "
708 "SUP labeledURI )", NULL, NULL },
709 { "writetimeout", "timeout", 2, 2, 0, ARG_INT,
710 &global_writetimeout, "( OLcfgGlAt:88 NAME 'olcWriteTimeout' "
711 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
712 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
713 NULL, NULL, NULL, NULL }
716 /* Need to no-op this keyword for dynamic config */
717 ConfigTable olcDatabaseDummy[] = {
718 { "", "", 0, 0, 0, ARG_IGNORED,
719 NULL, "( OLcfgGlAt:13 NAME 'olcDatabase' "
720 "DESC 'The backend type for a database instance' "
721 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
722 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
725 /* Routines to check if a child can be added to this type */
726 static ConfigLDAPadd cfAddSchema, cfAddInclude, cfAddDatabase,
727 cfAddBackend, cfAddModule, cfAddOverlay;
729 /* NOTE: be careful when defining array members
730 * that can be conditionally compiled */
731 #define CFOC_GLOBAL cf_ocs[1]
732 #define CFOC_SCHEMA cf_ocs[2]
733 #define CFOC_BACKEND cf_ocs[3]
734 #define CFOC_DATABASE cf_ocs[4]
735 #define CFOC_OVERLAY cf_ocs[5]
736 #define CFOC_INCLUDE cf_ocs[6]
737 #define CFOC_FRONTEND cf_ocs[7]
739 #define CFOC_MODULE cf_ocs[8]
740 #endif /* SLAPD_MODULES */
742 static ConfigOCs cf_ocs[] = {
745 "DESC 'OpenLDAP configuration object' "
746 "ABSTRACT SUP top )", Cft_Abstract, NULL },
749 "DESC 'OpenLDAP Global configuration options' "
750 "SUP olcConfig STRUCTURAL "
751 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
752 "olcAttributeOptions $ olcAuthIDRewrite $ "
753 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
754 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
755 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
756 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
757 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcIndexIntLen $ "
758 "olcLocalSSF $ olcLogFile $ olcLogLevel $ "
759 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
760 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
761 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
763 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
764 "olcSecurity $ olcServerID $ olcSizeLimit $ "
765 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ "
766 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
767 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
768 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
769 "olcTLSRandFile $ olcTLSVerifyClient $ olcTLSDHParamFile $ "
770 "olcTLSCRLFile $ olcToolThreads $ olcWriteTimeout $ "
771 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
772 "olcDitContentRules $ olcLdapSyntaxes ) )", Cft_Global },
774 "NAME 'olcSchemaConfig' "
775 "DESC 'OpenLDAP schema object' "
776 "SUP olcConfig STRUCTURAL "
777 "MAY ( cn $ olcObjectIdentifier $ olcAttributeTypes $ "
778 "olcObjectClasses $ olcDitContentRules $ olcLdapSyntaxes ) )",
779 Cft_Schema, NULL, cfAddSchema },
781 "NAME 'olcBackendConfig' "
782 "DESC 'OpenLDAP Backend-specific options' "
783 "SUP olcConfig STRUCTURAL "
784 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
786 "NAME 'olcDatabaseConfig' "
787 "DESC 'OpenLDAP Database-specific options' "
788 "SUP olcConfig STRUCTURAL "
790 "MAY ( olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
791 "olcAddContentAcl $ olcLastMod $ olcLimits $ "
792 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
793 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
794 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
795 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncrepl $ "
796 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef $ olcMirrorMode $ "
798 Cft_Database, NULL, cfAddDatabase },
800 "NAME 'olcOverlayConfig' "
801 "DESC 'OpenLDAP Overlay-specific options' "
802 "SUP olcConfig STRUCTURAL "
803 "MUST olcOverlay )", Cft_Overlay, NULL, cfAddOverlay },
805 "NAME 'olcIncludeFile' "
806 "DESC 'OpenLDAP configuration include file' "
807 "SUP olcConfig STRUCTURAL "
809 "MAY ( cn $ olcRootDSE ) )",
810 /* Used to be Cft_Include, that def has been removed */
811 Cft_Abstract, NULL, cfAddInclude },
812 /* This should be STRUCTURAL like all the other database classes, but
813 * that would mean inheriting all of the olcDatabaseConfig attributes,
814 * which causes them to be merged twice in config_build_entry.
817 "NAME 'olcFrontendConfig' "
818 "DESC 'OpenLDAP frontend configuration' "
820 "MAY ( olcDefaultSearchBase $ olcPasswordHash $ olcSortVals ) )",
821 Cft_Database, NULL, NULL },
824 "NAME 'olcModuleList' "
825 "DESC 'OpenLDAP dynamic module info' "
826 "SUP olcConfig STRUCTURAL "
827 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
828 Cft_Module, NULL, cfAddModule },
833 typedef struct ServerID {
834 struct ServerID *si_next;
835 struct berval si_url;
839 static ServerID *sid_list;
841 typedef struct voidList {
842 struct voidList *vl_next;
846 typedef struct ADlist {
847 struct ADlist *al_next;
848 AttributeDescription *al_desc;
851 static ADlist *sortVals;
854 config_generic(ConfigArgs *c) {
857 if ( c->op == SLAP_CONFIG_EMIT ) {
861 c->value_int = ldap_pvt_thread_get_concurrency();
864 c->value_int = connection_pool_max;
867 c->value_int = slap_tool_thread_max;
871 c->value_string = ch_strdup( passwd_salt );
876 if ( c->be->be_limits ) {
880 for ( i=0; c->be->be_limits[i]; i++ ) {
881 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
882 if ( bv.bv_len >= sizeof( buf ) ) {
883 ber_bvarray_free_x( c->rvalue_vals, NULL );
884 c->rvalue_vals = NULL;
888 bv.bv_val = buf + bv.bv_len;
889 limits_unparse( c->be->be_limits[i], &bv,
890 sizeof( buf ) - ( bv.bv_val - buf ) );
891 bv.bv_len += bv.bv_val - buf;
893 value_add_one( &c->rvalue_vals, &bv );
896 if ( !c->rvalue_vals ) rc = 1;
899 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_READONLY);
902 c->value_string = ch_strdup( slap_sasl_getpolicy());
905 slap_sasl_regexp_unparse( &c->rvalue_vals );
906 if ( !c->rvalue_vals ) rc = 1;
908 #ifdef HAVE_CYRUS_SASL
910 struct berval bv = BER_BVNULL;
911 slap_sasl_secprops_unparse( &bv );
912 if ( !BER_BVISNULL( &bv )) {
913 ber_bvarray_add( &c->rvalue_vals, &bv );
921 c->value_int = c->be->be_max_deref_depth;
924 if ( SLAP_DBHIDDEN( c->be )) {
931 ConfigFile *cf = c->ca_private;
933 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
934 else if ( cf->c_om_head )
935 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
937 if ( !c->rvalue_vals )
942 ad_unparse_options( &c->rvalue_vals );
945 ConfigFile *cf = c->ca_private;
947 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
948 else if ( cf->c_oc_head )
949 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
951 if ( !c->rvalue_vals )
956 ConfigFile *cf = c->ca_private;
958 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
959 else if ( cf->c_at_head )
960 at_unparse( &c->rvalue_vals, cf->c_at_head,
962 if ( !c->rvalue_vals )
967 ConfigFile *cf = c->ca_private;
969 syn_unparse( &c->rvalue_vals, NULL, NULL, 1 );
970 else if ( cf->c_syn_head )
971 syn_unparse( &c->rvalue_vals, cf->c_syn_head,
973 if ( !c->rvalue_vals )
978 ConfigFile *cf = c->ca_private;
980 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
981 else if ( cf->c_cr_head )
982 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
984 if ( !c->rvalue_vals )
991 char *src, *dst, ibuf[11];
992 struct berval bv, abv;
993 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
994 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
995 if ( abv.bv_len >= sizeof( ibuf ) ) {
996 ber_bvarray_free_x( c->rvalue_vals, NULL );
997 c->rvalue_vals = NULL;
1001 acl_unparse( a, &bv );
1002 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
1003 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
1004 /* Turn TAB / EOL into plain space */
1005 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
1006 if (isspace((unsigned char)*src)) *dst++ = ' ';
1010 if (dst[-1] == ' ') {
1014 abv.bv_len = dst - abv.bv_val;
1015 ber_bvarray_add( &c->rvalue_vals, &abv );
1021 c->value_int = (SLAP_DBACL_ADD(c->be) != 0);
1024 ConfigFile *cf = c->ca_private;
1025 if ( cf->c_dseFiles ) {
1026 value_add( &c->rvalue_vals, cf->c_dseFiles );
1037 for ( si = sid_list; si; si=si->si_next ) {
1038 assert( si->si_num >= 0 && si->si_num <= SLAP_SYNC_SID_MAX );
1039 if ( !BER_BVISEMPTY( &si->si_url )) {
1040 bv.bv_len = si->si_url.bv_len + 6;
1041 bv.bv_val = ch_malloc( bv.bv_len );
1042 bv.bv_len = sprintf( bv.bv_val, "%d %s", si->si_num,
1043 si->si_url.bv_val );
1044 ber_bvarray_add( &c->rvalue_vals, &bv );
1048 bv.bv_len = sprintf( buf, "%d", si->si_num );
1049 value_add_one( &c->rvalue_vals, &bv );
1058 c->value_string = ch_strdup( logfileName );
1063 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1065 case CFG_MIRRORMODE:
1066 if ( SLAP_SHADOW(c->be))
1067 c->value_int = (SLAP_SINGLE_SHADOW(c->be) == 0);
1071 case CFG_MONITORING:
1072 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
1074 case CFG_SSTR_IF_MAX:
1075 c->value_int = index_substr_if_maxlen;
1077 case CFG_SSTR_IF_MIN:
1078 c->value_int = index_substr_if_minlen;
1081 c->value_int = index_intlen;
1083 case CFG_SORTVALS: {
1086 for ( sv = sortVals; sv; sv = sv->al_next ) {
1087 value_add_one( &c->rvalue_vals, &sv->al_desc->ad_cname );
1091 #ifdef SLAPD_MODULES
1093 ModPaths *mp = c->ca_private;
1096 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
1099 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
1100 SLAP_X_ORDERED_FMT "%s", i,
1101 mp->mp_loads[i].bv_val );
1102 if ( bv.bv_len >= sizeof( c->log ) ) {
1103 ber_bvarray_free_x( c->rvalue_vals, NULL );
1104 c->rvalue_vals = NULL;
1107 value_add_one( &c->rvalue_vals, &bv );
1111 rc = c->rvalue_vals ? 0 : 1;
1115 ModPaths *mp = c->ca_private;
1116 if ( !BER_BVISNULL( &mp->mp_path ))
1117 value_add_one( &c->rvalue_vals, &mp->mp_path );
1119 rc = c->rvalue_vals ? 0 : 1;
1125 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1126 if ( !c->rvalue_vals ) rc = 1;
1129 #ifdef SLAP_AUTH_REWRITE
1131 if ( authz_rewrites ) {
1132 struct berval bv, idx;
1137 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1138 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1139 if ( idx.bv_len >= sizeof( ibuf ) ) {
1140 ber_bvarray_free_x( c->rvalue_vals, NULL );
1141 c->rvalue_vals = NULL;
1144 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1145 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1146 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1147 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1148 authz_rewrites[i].bv_val,
1149 authz_rewrites[i].bv_len + 1 );
1150 ber_bvarray_add( &c->rvalue_vals, &bv );
1153 if ( !c->rvalue_vals ) rc = 1;
1160 } else if ( c->op == LDAP_MOD_DELETE ) {
1163 /* single-valued attrs, no-ops */
1171 case CFG_MIRRORMODE:
1172 case CFG_MONITORING:
1174 case CFG_SSTR_IF_MAX:
1175 case CFG_SSTR_IF_MIN:
1179 /* no-ops, requires slapd restart */
1184 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1188 ch_free( passwd_salt );
1193 ch_free( logfileName );
1201 case CFG_SERVERID: {
1202 ServerID *si, **sip;
1204 for ( i=0, si = sid_list, sip = &sid_list;
1205 si; si = *sip, i++ ) {
1206 if ( c->valx == -1 || i == c->valx ) {
1218 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1222 index_intlen = SLAP_INDEX_INTLEN_DEFAULT;
1223 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1224 SLAP_INDEX_INTLEN_DEFAULT );
1228 if ( c->valx < 0 ) {
1229 acl_destroy( c->be->be_acl );
1230 c->be->be_acl = NULL;
1233 AccessControl **prev, *a;
1235 for (i=0, prev = &c->be->be_acl; i < c->valx;
1238 prev = &a->acl_next;
1241 *prev = a->acl_next;
1248 /* Can be NULL when undoing a failed add */
1249 if ( c->ca_entry ) {
1250 ce = c->ca_entry->e_private;
1251 /* can't modify the hardcoded schema */
1252 if ( ce->ce_parent->ce_type == Cft_Global )
1256 cfn = c->ca_private;
1257 if ( c->valx < 0 ) {
1260 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1262 if ( oc == cfn->c_oc_tail )
1265 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1267 ObjectClass *oc, *prev = NULL;
1269 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1274 if ( cfn->c_oc_tail == oc ) {
1275 cfn->c_oc_tail = prev;
1277 if ( cfn->c_oc_head == oc ) {
1279 cfn->c_oc_head = oc;
1286 /* Can be NULL when undoing a failed add */
1287 if ( c->ca_entry ) {
1288 ce = c->ca_entry->e_private;
1289 /* can't modify the hardcoded schema */
1290 if ( ce->ce_parent->ce_type == Cft_Global )
1294 cfn = c->ca_private;
1295 if ( c->valx < 0 ) {
1298 for( at = cfn->c_at_head; at; at_next( &at )) {
1300 if ( at == cfn->c_at_tail )
1303 cfn->c_at_head = cfn->c_at_tail = NULL;
1305 AttributeType *at, *prev = NULL;
1307 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1312 if ( cfn->c_at_tail == at ) {
1313 cfn->c_at_tail = prev;
1315 if ( cfn->c_at_head == at ) {
1317 cfn->c_at_head = at;
1324 /* Can be NULL when undoing a failed add */
1325 if ( c->ca_entry ) {
1326 ce = c->ca_entry->e_private;
1327 /* can't modify the hardcoded schema */
1328 if ( ce->ce_parent->ce_type == Cft_Global )
1332 cfn = c->ca_private;
1333 if ( c->valx < 0 ) {
1336 for( syn = cfn->c_syn_head; syn; syn_next( &syn )) {
1338 if ( syn == cfn->c_syn_tail )
1341 cfn->c_syn_head = cfn->c_syn_tail = NULL;
1343 Syntax *syn, *prev = NULL;
1345 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++) {
1350 if ( cfn->c_syn_tail == syn ) {
1351 cfn->c_syn_tail = prev;
1353 if ( cfn->c_syn_head == syn ) {
1355 cfn->c_syn_head = syn;
1360 if ( c->valx < 0 ) {
1362 for ( sv = sortVals; sv; sv = sortVals ) {
1363 sortVals = sv->al_next;
1364 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1371 for ( prev = &sortVals, sv = sortVals; i < c->valx; i++ ) {
1372 prev = &sv->al_next;
1375 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1376 *prev = sv->al_next;
1382 /* FIXME: there is no limits_free function */
1384 /* FIXME: there is no ad_option_free function */
1386 /* FIXME: there is no way to remove attributes added by
1400 if(!(c->bi = backend_info(c->argv[1]))) {
1401 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1402 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1403 c->log, c->cr_msg, c->argv[1] );
1410 /* NOTE: config is always the first backend!
1412 if ( !strcasecmp( c->argv[1], "config" )) {
1413 c->be = LDAP_STAILQ_FIRST(&backendDB);
1414 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1417 c->be = backend_db_init(c->argv[1], NULL, c->valx, &c->reply);
1419 if ( c->cr_msg[0] == 0 )
1420 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1421 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n", c->log, c->cr_msg, c->argv[1] );
1428 ldap_pvt_thread_set_concurrency(c->value_int);
1432 if ( c->value_int < 2 ) {
1433 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1434 "threads=%d smaller than minimum value 2",
1436 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1437 c->log, c->cr_msg, 0 );
1440 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1441 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1442 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1443 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1444 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1445 c->log, c->cr_msg, 0 );
1447 if ( slapMode & SLAP_SERVER_MODE )
1448 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1449 connection_pool_max = c->value_int; /* save for reference */
1453 if ( slapMode & SLAP_TOOL_MODE )
1454 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1455 slap_tool_thread_max = c->value_int; /* save for reference */
1459 if ( passwd_salt ) ch_free( passwd_salt );
1460 passwd_salt = c->value_string;
1461 lutil_salt_format(passwd_salt);
1465 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1471 c->be->be_restrictops |= SLAP_RESTRICT_READONLY;
1473 c->be->be_restrictops &= ~SLAP_RESTRICT_READONLY;
1477 ch_free(c->value_string);
1478 if (slap_sasl_setpolicy( c->argv[1] )) {
1479 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
1480 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1481 c->log, c->cr_msg, c->argv[1] );
1487 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1491 #ifdef HAVE_CYRUS_SASL
1494 char *txt = slap_sasl_secprops( c->argv[1] );
1496 snprintf( c->cr_msg, sizeof(c->cr_msg), "<%s> %s",
1498 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0 );
1506 c->be->be_max_deref_depth = c->value_int;
1512 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1513 cfn = c->ca_private;
1514 if(parse_oidm(c, 1, &om))
1516 if (!cfn->c_om_head) cfn->c_om_head = om;
1517 cfn->c_om_tail = om;
1522 ObjectClass *oc, *prev;
1524 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1525 cfn = c->ca_private;
1526 if ( c->valx < 0 ) {
1527 prev = cfn->c_oc_tail;
1530 /* If adding anything after the first, prev is easy */
1533 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
1538 /* If adding the first, and head exists, find its prev */
1539 if (cfn->c_oc_head) {
1540 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
1545 /* else prev is NULL, append to end of global list */
1547 if(parse_oc(c, &oc, prev)) return(1);
1548 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1549 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
1554 AttributeType *at, *prev;
1556 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1557 cfn = c->ca_private;
1558 if ( c->valx < 0 ) {
1559 prev = cfn->c_at_tail;
1562 /* If adding anything after the first, prev is easy */
1565 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
1570 /* If adding the first, and head exists, find its prev */
1571 if (cfn->c_at_head) {
1572 for ( at_start( &at ); at != cfn->c_at_head; ) {
1577 /* else prev is NULL, append to end of global list */
1579 if(parse_at(c, &at, prev)) return(1);
1580 if (!cfn->c_at_head) cfn->c_at_head = at;
1581 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
1588 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1589 cfn = c->ca_private;
1590 if ( c->valx < 0 ) {
1591 prev = cfn->c_syn_tail;
1594 /* If adding anything after the first, prev is easy */
1597 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++ ) {
1602 /* If adding the first, and head exists, find its prev */
1603 if (cfn->c_syn_head) {
1604 for ( syn_start( &syn ); syn != cfn->c_syn_head; ) {
1609 /* else prev is NULL, append to end of global list */
1611 if ( parse_syn( c, &syn, prev ) ) return(1);
1612 if ( !cfn->c_syn_head ) cfn->c_syn_head = syn;
1613 if ( cfn->c_syn_tail == prev ) cfn->c_syn_tail = syn;
1620 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1621 cfn = c->ca_private;
1622 if(parse_cr(c, &cr)) return(1);
1623 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1624 cfn->c_cr_tail = cr;
1629 ad_define_option(NULL, NULL, 0);
1630 for(i = 1; i < c->argc; i++)
1631 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1636 if ( c->value_int < SLAP_INDEX_INTLEN_DEFAULT )
1637 c->value_int = SLAP_INDEX_INTLEN_DEFAULT;
1638 else if ( c->value_int > 255 )
1640 index_intlen = c->value_int;
1641 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1645 case CFG_SORTVALS: {
1646 ADlist *svnew = NULL, *svtail, *sv;
1648 for ( i = 1; i < c->argc; i++ ) {
1649 AttributeDescription *ad = NULL;
1653 rc = slap_str2ad( c->argv[i], &ad, &text );
1655 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown attribute type #%d",
1658 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1659 c->log, c->cr_msg, c->argv[i] );
1660 for ( sv = svnew; sv; sv = svnew ) {
1661 svnew = sv->al_next;
1666 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) ||
1667 ad->ad_type->sat_single_value ) {
1668 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> inappropriate attribute type #%d",
1670 goto sortval_reject;
1672 sv = ch_malloc( sizeof( ADlist ));
1677 svtail->al_next = sv;
1682 for ( sv = svnew; sv; sv = sv->al_next )
1683 sv->al_desc->ad_type->sat_flags |= SLAP_AT_SORTED_VAL;
1684 for ( sv = sortVals; sv && sv->al_next; sv = sv->al_next );
1686 sv->al_next = svnew;
1693 /* Don't append to the global ACL if we're on a specific DB */
1695 if ( c->valx == -1 ) {
1698 for ( a=c->be->be_acl; a; a = a->acl_next )
1701 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
1708 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_ACL_ADD;
1710 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_ACL_ADD;
1714 if(root_dse_read_file(c->argv[1])) {
1715 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> could not read file", c->argv[0] );
1716 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1717 c->log, c->cr_msg, c->argv[1] );
1722 ber_str2bv( c->argv[1], 0, 1, &bv );
1723 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1724 cfn = c->ca_private;
1725 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1731 ServerID *si, **sip;
1734 if ( lutil_atoi( &num, c->argv[1] ) ||
1735 num < 0 || num > SLAP_SYNC_SID_MAX )
1737 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1738 "<%s> illegal server ID", c->argv[0] );
1739 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1740 c->log, c->cr_msg, c->argv[1] );
1743 /* only one value allowed if no URL is given */
1744 if ( c->argc > 2 ) {
1747 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
1748 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1749 "<%s> only one server ID allowed now", c->argv[0] );
1750 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1751 c->log, c->cr_msg, c->argv[1] );
1755 if ( ldap_url_parse( c->argv[2], &lud )) {
1756 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1757 "<%s> invalid URL", c->argv[0] );
1758 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1759 c->log, c->cr_msg, c->argv[2] );
1762 len = strlen( c->argv[2] );
1763 si = ch_malloc( sizeof(ServerID) + len + 1 );
1764 si->si_url.bv_val = (char *)(si+1);
1765 si->si_url.bv_len = len;
1766 strcpy( si->si_url.bv_val, c->argv[2] );
1769 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1770 "<%s> unqualified server ID not allowed now", c->argv[0] );
1771 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1772 c->log, c->cr_msg, c->argv[1] );
1775 si = ch_malloc( sizeof(ServerID) );
1776 BER_BVZERO( &si->si_url );
1777 slap_serverID = num;
1778 Debug( LDAP_DEBUG_CONFIG,
1780 c->log, slap_serverID, 0 );
1784 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
1787 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
1788 Listener **l = slapd_get_listeners();
1791 /* Try a straight compare with Listener strings */
1792 for ( i=0; l && l[i]; i++ ) {
1793 if ( !strcasecmp( c->argv[2], l[i]->sl_url.bv_val )) {
1799 /* If hostname is empty, or is localhost, or matches
1800 * our hostname, this serverID refers to this host.
1801 * Compare it against listeners and ports.
1803 if ( !isMe && ( !lud->lud_host || !lud->lud_host[0] ||
1804 !strncasecmp("localhost", lud->lud_host,
1805 STRLENOF("localhost")) ||
1806 !strcasecmp( global_host, lud->lud_host ))) {
1808 for ( i=0; l && l[i]; i++ ) {
1810 ldap_url_parse( l[i]->sl_url.bv_val, &lu2 );
1812 if ( strcasecmp( lud->lud_scheme,
1815 if ( lud->lud_port != lu2->lud_port )
1817 /* Listener on ANY address */
1818 if ( !lu2->lud_host || !lu2->lud_host[0] ) {
1822 /* URL on ANY address */
1823 if ( !lud->lud_host || !lud->lud_host[0] ) {
1827 /* Listener has specific host, must
1830 if ( !strcasecmp( lud->lud_host,
1836 ldap_free_urldesc( lu2 );
1843 slap_serverID = si->si_num;
1844 Debug( LDAP_DEBUG_CONFIG,
1845 "%s: SID=%d (listener=%s)\n",
1846 c->log, slap_serverID,
1847 l[i]->sl_url.bv_val );
1851 ldap_free_urldesc( lud );
1855 if ( logfileName ) ch_free( logfileName );
1856 logfileName = c->value_string;
1857 logfile = fopen(logfileName, "w");
1858 if(logfile) lutil_debug_file(logfile);
1862 if(SLAP_NOLASTMODCMD(c->be)) {
1863 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> not available for %s database",
1864 c->argv[0], c->be->bd_info->bi_type );
1865 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1866 c->log, c->cr_msg, 0 );
1870 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1872 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1875 case CFG_MIRRORMODE:
1876 if(!SLAP_SHADOW(c->be)) {
1877 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database is not a shadow",
1879 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1880 c->log, c->cr_msg, 0 );
1884 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
1886 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1889 case CFG_MONITORING:
1891 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
1893 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
1898 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
1900 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
1903 case CFG_SSTR_IF_MAX:
1904 if (c->value_int < index_substr_if_minlen) {
1905 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1906 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1907 c->log, c->cr_msg, c->value_int );
1910 index_substr_if_maxlen = c->value_int;
1913 case CFG_SSTR_IF_MIN:
1914 if (c->value_int > index_substr_if_maxlen) {
1915 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1916 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1917 c->log, c->cr_msg, c->value_int );
1920 index_substr_if_minlen = c->value_int;
1923 #ifdef SLAPD_MODULES
1925 /* If we're just adding a module on an existing modpath,
1926 * make sure we've selected the current path.
1928 if ( c->op == LDAP_MOD_ADD && c->ca_private && modcur != c->ca_private ) {
1929 modcur = c->ca_private;
1930 /* This should never fail */
1931 if ( module_path( modcur->mp_path.bv_val )) {
1932 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> module path no longer valid",
1934 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1935 c->log, c->cr_msg, modcur->mp_path.bv_val );
1939 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1941 /* Record this load on the current path */
1945 if ( c->op == SLAP_CONFIG_ADD ) {
1946 ptr = c->line + STRLENOF("moduleload");
1947 while (!isspace((unsigned char) *ptr)) ptr++;
1948 while (isspace((unsigned char) *ptr)) ptr++;
1952 ber_str2bv(ptr, 0, 1, &bv);
1953 ber_bvarray_add( &modcur->mp_loads, &bv );
1955 /* Check for any new hardcoded schema */
1956 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
1957 config_check_schema( NULL, &cfBackInfo );
1962 if(module_path(c->argv[1])) return(1);
1963 /* Record which path was used with each module */
1967 if (!modpaths.mp_loads) {
1970 mp = ch_malloc( sizeof( ModPaths ));
1971 modlast->mp_next = mp;
1973 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1975 mp->mp_loads = NULL;
1986 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
1988 slapi_plugins_used++;
1992 #ifdef SLAP_AUTH_REWRITE
1997 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
2000 if ( c->argc > 1 ) {
2003 /* quote all args but the first */
2004 line = ldap_charray2str( c->argv, "\" \"" );
2005 ber_str2bv( line, 0, 0, &bv );
2006 s = ber_bvchr( &bv, '"' );
2007 assert( s != NULL );
2008 /* move the trailing quote of argv[0] to the end */
2009 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
2010 bv.bv_val[ bv.bv_len - 1 ] = '"';
2013 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
2016 ber_bvarray_add( &authz_rewrites, &bv );
2023 Debug( LDAP_DEBUG_ANY,
2024 "%s: unknown CFG_TYPE %d.\n",
2025 c->log, c->type, 0 );
2034 config_fname(ConfigArgs *c) {
2035 if(c->op == SLAP_CONFIG_EMIT) {
2036 if (c->ca_private) {
2037 ConfigFile *cf = c->ca_private;
2038 value_add_one( &c->rvalue_vals, &cf->c_file );
2047 config_cfdir(ConfigArgs *c) {
2048 if(c->op == SLAP_CONFIG_EMIT) {
2049 if ( !BER_BVISEMPTY( &cfdir )) {
2050 value_add_one( &c->rvalue_vals, &cfdir );
2059 config_search_base(ConfigArgs *c) {
2060 if(c->op == SLAP_CONFIG_EMIT) {
2062 if (!BER_BVISEMPTY(&default_search_base)) {
2063 value_add_one(&c->rvalue_vals, &default_search_base);
2064 value_add_one(&c->rvalue_nvals, &default_search_nbase);
2068 } else if( c->op == LDAP_MOD_DELETE ) {
2069 ch_free( default_search_base.bv_val );
2070 ch_free( default_search_nbase.bv_val );
2071 BER_BVZERO( &default_search_base );
2072 BER_BVZERO( &default_search_nbase );
2076 if(c->bi || c->be != frontendDB) {
2077 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
2078 "prior to any backend or database definition\n",
2083 if(default_search_nbase.bv_len) {
2084 free(default_search_base.bv_val);
2085 free(default_search_nbase.bv_val);
2088 default_search_base = c->value_dn;
2089 default_search_nbase = c->value_ndn;
2093 /* For RE23 compatibility we allow this in the global entry
2094 * but we now defer it to the frontend entry to allow modules
2095 * to load new hash types.
2098 config_passwd_hash(ConfigArgs *c) {
2100 if (c->op == SLAP_CONFIG_EMIT) {
2102 /* Don't generate it in the global entry */
2103 if ( c->table == Cft_Global )
2105 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
2106 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
2107 value_add_one(&c->rvalue_vals, &bv);
2110 } else if ( c->op == LDAP_MOD_DELETE ) {
2111 /* Deleting from global is a no-op, only the frontendDB entry matters */
2112 if ( c->table == Cft_Global )
2114 if ( c->valx < 0 ) {
2115 ldap_charray_free( default_passwd_hash );
2116 default_passwd_hash = NULL;
2119 ch_free( default_passwd_hash[i] );
2120 for (; default_passwd_hash[i]; i++ )
2121 default_passwd_hash[i] = default_passwd_hash[i+1];
2125 for(i = 1; i < c->argc; i++) {
2126 if(!lutil_passwd_scheme(c->argv[i])) {
2127 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> scheme not available", c->argv[0] );
2128 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2129 c->log, c->cr_msg, c->argv[i]);
2131 ldap_charray_add(&default_passwd_hash, c->argv[i]);
2134 if(!default_passwd_hash) {
2135 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> no valid hashes found", c->argv[0] );
2136 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2137 c->log, c->cr_msg, 0 );
2144 config_schema_dn(ConfigArgs *c) {
2145 if ( c->op == SLAP_CONFIG_EMIT ) {
2147 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
2148 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
2149 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
2153 } else if ( c->op == LDAP_MOD_DELETE ) {
2154 ch_free( c->be->be_schemadn.bv_val );
2155 ch_free( c->be->be_schemandn.bv_val );
2156 BER_BVZERO( &c->be->be_schemadn );
2157 BER_BVZERO( &c->be->be_schemandn );
2160 ch_free( c->be->be_schemadn.bv_val );
2161 ch_free( c->be->be_schemandn.bv_val );
2162 c->be->be_schemadn = c->value_dn;
2163 c->be->be_schemandn = c->value_ndn;
2168 config_sizelimit(ConfigArgs *c) {
2170 struct slap_limits_set *lim = &c->be->be_def_limit;
2171 if (c->op == SLAP_CONFIG_EMIT) {
2176 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
2177 if ( !BER_BVISEMPTY( &bv ))
2178 value_add_one( &c->rvalue_vals, &bv );
2182 } else if ( c->op == LDAP_MOD_DELETE ) {
2183 /* Reset to defaults */
2184 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
2185 lim->lms_s_hard = 0;
2186 lim->lms_s_unchecked = -1;
2188 lim->lms_s_pr_hide = 0;
2189 lim->lms_s_pr_total = 0;
2192 for(i = 1; i < c->argc; i++) {
2193 if(!strncasecmp(c->argv[i], "size", 4)) {
2194 rc = limits_parse_one(c->argv[i], lim);
2196 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2197 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2198 c->log, c->cr_msg, c->argv[i]);
2202 if(!strcasecmp(c->argv[i], "unlimited")) {
2203 lim->lms_s_soft = -1;
2205 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
2206 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2207 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2208 c->log, c->cr_msg, c->argv[i]);
2212 lim->lms_s_hard = 0;
2219 config_timelimit(ConfigArgs *c) {
2221 struct slap_limits_set *lim = &c->be->be_def_limit;
2222 if (c->op == SLAP_CONFIG_EMIT) {
2227 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
2228 if ( !BER_BVISEMPTY( &bv ))
2229 value_add_one( &c->rvalue_vals, &bv );
2233 } else if ( c->op == LDAP_MOD_DELETE ) {
2234 /* Reset to defaults */
2235 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
2236 lim->lms_t_hard = 0;
2239 for(i = 1; i < c->argc; i++) {
2240 if(!strncasecmp(c->argv[i], "time", 4)) {
2241 rc = limits_parse_one(c->argv[i], lim);
2243 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2244 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2245 c->log, c->cr_msg, c->argv[i]);
2249 if(!strcasecmp(c->argv[i], "unlimited")) {
2250 lim->lms_t_soft = -1;
2252 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
2253 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2254 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2255 c->log, c->cr_msg, c->argv[i]);
2259 lim->lms_t_hard = 0;
2266 config_overlay(ConfigArgs *c) {
2267 if (c->op == SLAP_CONFIG_EMIT) {
2269 } else if ( c->op == LDAP_MOD_DELETE ) {
2272 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2273 c->valx, &c->bi, &c->reply)) {
2275 Debug( LDAP_DEBUG_ANY,
2276 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2277 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2279 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi, &c->reply)) {
2286 config_subordinate(ConfigArgs *c)
2292 case SLAP_CONFIG_EMIT:
2293 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2296 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2297 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2300 value_add_one( &c->rvalue_vals, &bv );
2304 case LDAP_MOD_DELETE:
2305 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2306 glue_sub_del( c->be );
2308 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2313 case SLAP_CONFIG_ADD:
2314 advertise = ( c->argc == 2 && !strcasecmp( c->argv[1], "advertise" ));
2315 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2322 config_suffix(ConfigArgs *c)
2325 struct berval pdn, ndn;
2326 char *notallowed = NULL;
2328 if ( c->be == frontendDB ) {
2329 notallowed = "frontend";
2331 } else if ( SLAP_MONITOR(c->be) ) {
2332 notallowed = "monitor";
2334 } else if ( SLAP_CONFIG(c->be) ) {
2335 notallowed = "config";
2338 if ( notallowed != NULL ) {
2339 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
2343 case LDAP_MOD_DELETE:
2344 case LDAP_MOD_REPLACE:
2345 case LDAP_MOD_INCREMENT:
2346 case SLAP_CONFIG_ADD:
2347 if ( !BER_BVISNULL( &c->value_dn ) ) {
2348 snprintf( buf, sizeof( buf ), "<%s> ",
2349 c->value_dn.bv_val );
2352 Debug(LDAP_DEBUG_ANY,
2353 "%s: suffix %snot allowed in %s database.\n",
2354 c->log, buf, notallowed );
2357 case SLAP_CONFIG_EMIT:
2358 /* don't complain when emitting... */
2362 /* FIXME: don't know what values may be valid;
2363 * please remove assertion, or add legal values
2364 * to either block */
2372 if (c->op == SLAP_CONFIG_EMIT) {
2373 if ( c->be->be_suffix == NULL
2374 || BER_BVISNULL( &c->be->be_suffix[0] ) )
2378 value_add( &c->rvalue_vals, c->be->be_suffix );
2379 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
2382 } else if ( c->op == LDAP_MOD_DELETE ) {
2383 if ( c->valx < 0 ) {
2384 ber_bvarray_free( c->be->be_suffix );
2385 ber_bvarray_free( c->be->be_nsuffix );
2386 c->be->be_suffix = NULL;
2387 c->be->be_nsuffix = NULL;
2390 ch_free( c->be->be_suffix[i].bv_val );
2391 ch_free( c->be->be_nsuffix[i].bv_val );
2393 c->be->be_suffix[i] = c->be->be_suffix[i+1];
2394 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
2396 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
2401 #ifdef SLAPD_MONITOR_DN
2402 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
2403 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> DN is reserved for monitoring slapd",
2405 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2406 c->log, c->cr_msg, SLAPD_MONITOR_DN);
2411 if (SLAP_DB_ONE_SUFFIX( c->be ) && c->be->be_suffix ) {
2412 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> Only one suffix is allowed on this %s backend",
2413 c->argv[0], c->be->bd_info->bi_type );
2414 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2415 c->log, c->cr_msg, 0);
2422 if (SLAP_DBHIDDEN( c->be ))
2425 tbe = select_backend(&ndn, 0);
2427 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
2433 BackendDB *b2 = tbe;
2435 /* Does tbe precede be? */
2436 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
2439 char *type = tbe->bd_info->bi_type;
2441 if ( overlay_is_over( tbe ) ) {
2442 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
2443 type = oi->oi_orig->bi_type;
2446 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> namingContext \"%s\" "
2447 "already served by a preceding %s database",
2448 c->argv[0], pdn.bv_val, type );
2449 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
2450 c->log, c->cr_msg, tbe->be_suffix[0].bv_val);
2456 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
2457 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
2458 "base provided \"%s\" (assuming okay)\n",
2459 c->log, default_search_base.bv_val, 0);
2461 ber_bvarray_add(&c->be->be_suffix, &pdn);
2462 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
2467 config_rootdn(ConfigArgs *c) {
2468 if (c->op == SLAP_CONFIG_EMIT) {
2469 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2470 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
2471 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
2476 } else if ( c->op == LDAP_MOD_DELETE ) {
2477 ch_free( c->be->be_rootdn.bv_val );
2478 ch_free( c->be->be_rootndn.bv_val );
2479 BER_BVZERO( &c->be->be_rootdn );
2480 BER_BVZERO( &c->be->be_rootndn );
2483 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2484 ch_free( c->be->be_rootdn.bv_val );
2485 ch_free( c->be->be_rootndn.bv_val );
2487 c->be->be_rootdn = c->value_dn;
2488 c->be->be_rootndn = c->value_ndn;
2493 config_rootpw(ConfigArgs *c) {
2496 if (c->op == SLAP_CONFIG_EMIT) {
2497 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
2498 /* don't copy, because "rootpw" is marked
2500 c->value_bv = c->be->be_rootpw;
2504 } else if ( c->op == LDAP_MOD_DELETE ) {
2505 ch_free( c->be->be_rootpw.bv_val );
2506 BER_BVZERO( &c->be->be_rootpw );
2510 tbe = select_backend(&c->be->be_rootndn, 0);
2512 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> can only be set when rootdn is under suffix",
2514 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2515 c->log, c->cr_msg, 0);
2518 if ( !BER_BVISNULL( &c->be->be_rootpw ))
2519 ch_free( c->be->be_rootpw.bv_val );
2520 c->be->be_rootpw = c->value_bv;
2525 config_restrict(ConfigArgs *c) {
2526 slap_mask_t restrictops = 0;
2528 slap_verbmasks restrictable_ops[] = {
2529 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
2530 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
2531 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
2532 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
2533 { BER_BVC("modrdn"), 0 },
2534 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
2535 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
2536 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
2537 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
2538 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
2539 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
2540 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
2541 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
2542 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
2543 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
2544 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
2548 if (c->op == SLAP_CONFIG_EMIT) {
2549 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
2551 } else if ( c->op == LDAP_MOD_DELETE ) {
2553 c->be->be_restrictops = 0;
2555 restrictops = verb_to_mask( c->line, restrictable_ops );
2556 c->be->be_restrictops ^= restrictops;
2560 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
2562 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown operation", c->argv[0] );
2563 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2564 c->log, c->cr_msg, c->argv[i]);
2567 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
2568 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
2569 c->be->be_restrictops |= restrictops;
2574 config_allows(ConfigArgs *c) {
2575 slap_mask_t allows = 0;
2577 slap_verbmasks allowable_ops[] = {
2578 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
2579 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
2580 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
2581 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
2582 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
2585 if (c->op == SLAP_CONFIG_EMIT) {
2586 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
2587 } else if ( c->op == LDAP_MOD_DELETE ) {
2591 allows = verb_to_mask( c->line, allowable_ops );
2592 global_allows ^= allows;
2596 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
2598 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
2599 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2600 c->log, c->cr_msg, c->argv[i]);
2603 global_allows |= allows;
2608 config_disallows(ConfigArgs *c) {
2609 slap_mask_t disallows = 0;
2611 slap_verbmasks disallowable_ops[] = {
2612 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
2613 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
2614 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
2615 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
2616 { BER_BVC("proxy_authz_non_critical"), SLAP_DISALLOW_PROXY_AUTHZ_N_CRIT },
2617 { BER_BVC("dontusecopy_non_critical"), SLAP_DISALLOW_DONTUSECOPY_N_CRIT },
2620 if (c->op == SLAP_CONFIG_EMIT) {
2621 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
2622 } else if ( c->op == LDAP_MOD_DELETE ) {
2624 global_disallows = 0;
2626 disallows = verb_to_mask( c->line, disallowable_ops );
2627 global_disallows ^= disallows;
2631 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
2633 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
2634 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2635 c->log, c->cr_msg, c->argv[i]);
2638 global_disallows |= disallows;
2643 config_requires(ConfigArgs *c) {
2644 slap_mask_t requires = frontendDB->be_requires;
2645 int i, argc = c->argc;
2646 char **argv = c->argv;
2648 slap_verbmasks requires_ops[] = {
2649 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
2650 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
2651 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
2652 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
2653 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
2656 if (c->op == SLAP_CONFIG_EMIT) {
2657 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
2658 } else if ( c->op == LDAP_MOD_DELETE ) {
2660 c->be->be_requires = 0;
2662 requires = verb_to_mask( c->line, requires_ops );
2663 c->be->be_requires ^= requires;
2667 /* "none" can only be first, to wipe out default/global values */
2668 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
2673 i = verbs_to_mask(argc, argv, requires_ops, &requires);
2675 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
2676 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
2677 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2678 c->log, c->cr_msg, 0);
2680 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
2681 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2682 c->log, c->cr_msg, c->argv[i]);
2686 c->be->be_requires = requires;
2690 static slap_verbmasks *loglevel_ops;
2693 loglevel_init( void )
2695 slap_verbmasks lo[] = {
2696 { BER_BVC("Any"), -1 },
2697 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
2698 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
2699 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
2700 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
2701 { BER_BVC("BER"), LDAP_DEBUG_BER },
2702 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
2703 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
2704 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
2705 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
2706 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
2707 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
2708 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
2709 #if 0 /* no longer used (nor supported) */
2710 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
2711 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
2713 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
2714 { BER_BVC("None"), LDAP_DEBUG_NONE },
2718 return slap_verbmasks_init( &loglevel_ops, lo );
2722 loglevel_destroy( void )
2724 if ( loglevel_ops ) {
2725 (void)slap_verbmasks_destroy( loglevel_ops );
2727 loglevel_ops = NULL;
2730 static slap_mask_t loglevel_ignore[] = { -1, 0 };
2733 slap_loglevel_register( slap_mask_t m, struct berval *s )
2737 if ( loglevel_ops == NULL ) {
2741 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
2744 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
2752 slap_loglevel_get( struct berval *s, int *l )
2757 if ( loglevel_ops == NULL ) {
2761 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
2762 m |= loglevel_ops[ i ].mask;
2765 for ( i = 1; m & i; i <<= 1 )
2772 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
2775 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
2786 str2loglevel( const char *s, int *l )
2790 if ( loglevel_ops == NULL ) {
2794 i = verb_to_mask( s, loglevel_ops );
2796 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
2800 *l = loglevel_ops[ i ].mask;
2806 loglevel2str( int l )
2808 struct berval bv = BER_BVNULL;
2810 loglevel2bv( l, &bv );
2816 loglevel2bv( int l, struct berval *bv )
2818 if ( loglevel_ops == NULL ) {
2824 return enum_to_verb( loglevel_ops, l, bv ) == -1;
2828 loglevel2bvarray( int l, BerVarray *bva )
2830 if ( loglevel_ops == NULL ) {
2834 return mask_to_verbs( loglevel_ops, l, bva );
2838 loglevel_print( FILE *out )
2842 if ( loglevel_ops == NULL ) {
2846 fprintf( out, "Installed log subsystems:\n\n" );
2847 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
2848 fprintf( out, "\t%-30s (%lu)\n",
2849 loglevel_ops[ i ].word.bv_val,
2850 loglevel_ops[ i ].mask );
2853 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
2854 "by specific code\n\n" );
2859 static int config_syslog;
2862 config_loglevel(ConfigArgs *c) {
2865 if ( loglevel_ops == NULL ) {
2869 if (c->op == SLAP_CONFIG_EMIT) {
2870 /* Get default or commandline slapd setting */
2871 if ( ldap_syslog && !config_syslog )
2872 config_syslog = ldap_syslog;
2873 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
2875 } else if ( c->op == LDAP_MOD_DELETE ) {
2879 int level = verb_to_mask( c->line, loglevel_ops );
2880 config_syslog ^= level;
2882 if ( slapMode & SLAP_SERVER_MODE ) {
2883 ldap_syslog = config_syslog;
2888 for( i=1; i < c->argc; i++ ) {
2891 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
2892 if( lutil_atoi( &level, c->argv[i] ) != 0 ) {
2893 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse level", c->argv[0] );
2894 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2895 c->log, c->cr_msg, c->argv[i]);
2899 if ( str2loglevel( c->argv[i], &level ) ) {
2900 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown level", c->argv[0] );
2901 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2902 c->log, c->cr_msg, c->argv[i]);
2906 /* Explicitly setting a zero clears all the levels */
2908 config_syslog |= level;
2912 if ( slapMode & SLAP_SERVER_MODE ) {
2913 ldap_syslog = config_syslog;
2919 config_referral(ConfigArgs *c) {
2921 if (c->op == SLAP_CONFIG_EMIT) {
2922 if ( default_referral ) {
2923 value_add( &c->rvalue_vals, default_referral );
2928 } else if ( c->op == LDAP_MOD_DELETE ) {
2929 if ( c->valx < 0 ) {
2930 ber_bvarray_free( default_referral );
2931 default_referral = NULL;
2934 ch_free( default_referral[i].bv_val );
2935 for (; default_referral[i].bv_val; i++ )
2936 default_referral[i] = default_referral[i+1];
2940 if(validate_global_referral(c->argv[1])) {
2941 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
2942 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2943 c->log, c->cr_msg, c->argv[1]);
2947 ber_str2bv(c->argv[1], 0, 0, &val);
2948 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
2956 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
2957 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
2958 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
2959 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
2960 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
2961 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
2962 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
2963 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
2964 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
2969 config_security(ConfigArgs *c) {
2970 slap_ssf_set_t *set = &c->be->be_ssf_set;
2973 if (c->op == SLAP_CONFIG_EMIT) {
2979 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
2980 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
2983 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
2984 if ( bv.bv_len >= sizeof( numbuf ) ) {
2985 ber_bvarray_free_x( c->rvalue_vals, NULL );
2986 c->rvalue_vals = NULL;
2990 bv.bv_len += sec_keys[i].key.bv_len;
2991 bv.bv_val = ch_malloc( bv.bv_len + 1);
2992 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
2993 strcpy( next, numbuf );
2994 ber_bvarray_add( &c->rvalue_vals, &bv );
2999 for(i = 1; i < c->argc; i++) {
3000 slap_ssf_t *tgt = NULL;
3002 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
3003 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
3004 sec_keys[j].key.bv_len)) {
3005 src = c->argv[i] + sec_keys[j].key.bv_len;
3006 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
3011 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown factor", c->argv[0] );
3012 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3013 c->log, c->cr_msg, c->argv[i]);
3017 if ( lutil_atou( tgt, src ) != 0 ) {
3018 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse factor", c->argv[0] );
3019 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3020 c->log, c->cr_msg, c->argv[i]);
3028 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
3032 for (; !BER_BVISNULL( &an->an_name ); an++) {
3033 /* if buflen == 0, assume the buffer size has been
3034 * already checked otherwise */
3035 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
3036 if ( comma ) *ptr++ = ',';
3037 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
3044 config_updatedn(ConfigArgs *c) {
3045 if (c->op == SLAP_CONFIG_EMIT) {
3046 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
3047 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
3048 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
3052 } else if ( c->op == LDAP_MOD_DELETE ) {
3053 ch_free( c->be->be_update_ndn.bv_val );
3054 BER_BVZERO( &c->be->be_update_ndn );
3055 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
3058 if(SLAP_SHADOW(c->be)) {
3059 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database already shadowed", c->argv[0] );
3060 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3061 c->log, c->cr_msg, 0);
3065 ber_memfree_x( c->value_dn.bv_val, NULL );
3066 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
3067 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
3069 c->be->be_update_ndn = c->value_ndn;
3070 BER_BVZERO( &c->value_dn );
3071 BER_BVZERO( &c->value_ndn );
3073 return config_slurp_shadow( c );
3077 config_shadow( ConfigArgs *c, int flag )
3079 char *notallowed = NULL;
3081 if ( c->be == frontendDB ) {
3082 notallowed = "frontend";
3084 } else if ( SLAP_MONITOR(c->be) ) {
3085 notallowed = "monitor";
3088 if ( notallowed != NULL ) {
3089 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
3093 if ( SLAP_SHADOW(c->be) ) {
3094 /* if already shadow, only check consistency */
3095 if ( ( SLAP_DBFLAGS(c->be) & flag ) != flag ) {
3096 Debug( LDAP_DEBUG_ANY, "%s: inconsistent shadow flag 0x%x.\n", c->log, flag, 0 );
3101 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SINGLE_SHADOW | flag);
3108 config_updateref(ConfigArgs *c) {
3110 if (c->op == SLAP_CONFIG_EMIT) {
3111 if ( c->be->be_update_refs ) {
3112 value_add( &c->rvalue_vals, c->be->be_update_refs );
3117 } else if ( c->op == LDAP_MOD_DELETE ) {
3118 if ( c->valx < 0 ) {
3119 ber_bvarray_free( c->be->be_update_refs );
3120 c->be->be_update_refs = NULL;
3123 ch_free( c->be->be_update_refs[i].bv_val );
3124 for (; c->be->be_update_refs[i].bv_val; i++)
3125 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
3129 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
3130 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must appear after syncrepl or updatedn",
3132 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3133 c->log, c->cr_msg, 0);
3137 if(validate_global_referral(c->argv[1])) {
3138 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3139 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3140 c->log, c->cr_msg, c->argv[1]);
3143 ber_str2bv(c->argv[1], 0, 0, &val);
3144 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
3149 config_obsolete(ConfigArgs *c) {
3150 if (c->op == SLAP_CONFIG_EMIT)
3153 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> keyword is obsolete (ignored)",
3155 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0);
3160 config_include(ConfigArgs *c) {
3161 int savelineno = c->lineno;
3164 ConfigFile *cfsave = cfn;
3165 ConfigFile *cf2 = NULL;
3167 /* Leftover from RE23. No dynamic config for include files */
3168 if ( c->op == SLAP_CONFIG_EMIT || c->op == LDAP_MOD_DELETE )
3171 cf = ch_calloc( 1, sizeof(ConfigFile));
3172 if ( cfn->c_kids ) {
3173 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
3179 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
3180 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
3181 c->lineno = savelineno - 1;
3184 if ( cf2 ) cf2->c_sibs = NULL;
3185 else cfn->c_kids = NULL;
3186 ch_free( cf->c_file.bv_val );
3196 config_tls_option(ConfigArgs *c) {
3198 LDAP *ld = slap_tls_ld;
3200 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
3201 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
3202 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
3203 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
3204 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
3205 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
3206 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
3208 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
3210 default: Debug(LDAP_DEBUG_ANY, "%s: "
3211 "unknown tls_option <0x%x>\n",
3212 c->log, c->type, 0);
3215 if (c->op == SLAP_CONFIG_EMIT) {
3216 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
3217 } else if ( c->op == LDAP_MOD_DELETE ) {
3218 return ldap_pvt_tls_set_option( ld, flag, NULL );
3220 ch_free(c->value_string);
3221 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
3224 /* FIXME: this ought to be provided by libldap */
3226 config_tls_config(ConfigArgs *c) {
3229 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
3230 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
3231 case CFG_TLS_PROTOCOL_MIN: flag = LDAP_OPT_X_TLS_PROTOCOL_MIN; break;
3233 Debug(LDAP_DEBUG_ANY, "%s: "
3234 "unknown tls_option <0x%x>\n",
3235 c->log, c->type, 0);
3238 if (c->op == SLAP_CONFIG_EMIT) {
3239 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
3240 } else if ( c->op == LDAP_MOD_DELETE ) {
3242 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
3244 ch_free( c->value_string );
3245 if ( isdigit( (unsigned char)c->argv[1][0] ) ) {
3246 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
3247 Debug(LDAP_DEBUG_ANY, "%s: "
3248 "unable to parse %s \"%s\"\n",
3249 c->log, c->argv[0], c->argv[1] );
3252 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
3254 return(ldap_pvt_tls_config(slap_tls_ld, flag, c->argv[1]));
3259 static CfEntryInfo *
3260 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
3270 if ( dn_match( &root->ce_entry->e_nname, dn ))
3273 c = dn->bv_val+dn->bv_len;
3274 for (;*c != ',';c--);
3278 for (--c;c>dn->bv_val && *c != ',';c--);
3282 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
3284 root = root->ce_kids;
3286 for (;root;root=root->ce_sibs) {
3287 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
3288 if ( cdn.bv_val == dn->bv_val ) {
3298 typedef struct setup_cookie {
3308 config_ldif_resp( Operation *op, SlapReply *rs )
3310 if ( rs->sr_type == REP_SEARCH ) {
3311 setup_cookie *sc = op->o_callback->sc_private;
3314 sc->cfb->cb_got_ldif = 1;
3315 /* Does the frontend exist? */
3316 if ( !sc->got_frontend ) {
3317 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
3318 "olcDatabase", STRLENOF( "olcDatabase" )))
3320 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3321 STRLENOF( "olcDatabase" ), "={-1}frontend",
3322 STRLENOF( "={-1}frontend" )))
3326 sc->ca->be = frontendDB;
3327 sc->ca->bi = frontendDB->bd_info;
3328 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
3329 rdn.bv_val = sc->ca->log;
3330 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3331 "%s=" SLAP_X_ORDERED_FMT "%s",
3332 cfAd_database->ad_cname.bv_val, -1,
3333 sc->ca->bi->bi_type);
3335 sc->frontend = config_build_entry( op, rs,
3336 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
3337 sc->ca->be->be_cf_ocs );
3347 dnParent( &rs->sr_entry->e_nname, &pdn );
3349 /* Does the configDB exist? */
3350 if ( sc->got_frontend && !sc->got_config &&
3351 !strncmp( rs->sr_entry->e_nname.bv_val,
3352 "olcDatabase", STRLENOF( "olcDatabase" )) &&
3353 dn_match( &config_rdn, &pdn ) )
3355 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3356 STRLENOF( "olcDatabase" ), "={0}config",
3357 STRLENOF( "={0}config" )))
3361 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
3362 sc->ca->bi = sc->ca->be->bd_info;
3363 rdn.bv_val = sc->ca->log;
3364 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3365 "%s=" SLAP_X_ORDERED_FMT "%s",
3366 cfAd_database->ad_cname.bv_val, 0,
3367 sc->ca->bi->bi_type);
3369 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
3370 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
3377 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
3378 if ( rs->sr_err != LDAP_SUCCESS ) {
3379 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
3380 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg, 0 );
3386 /* Configure and read the underlying back-ldif store */
3388 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
3389 CfBackInfo *cfb = be->be_private;
3395 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
3396 Connection conn = {0};
3397 OperationBuffer opbuf;
3399 SlapReply rs = {REP_RESULT};
3400 Filter filter = { LDAP_FILTER_PRESENT };
3401 struct berval filterstr = BER_BVC("(objectclass=*)");
3404 /* Is the config directory available? */
3405 if ( stat( dir, &st ) < 0 ) {
3406 /* No, so don't bother using the backing store.
3407 * All changes will be in-memory only.
3412 cfb->cb_db.bd_info = backend_info( "ldif" );
3413 if ( !cfb->cb_db.bd_info )
3414 return 0; /* FIXME: eventually this will be a fatal error */
3416 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
3419 cfb->cb_db.be_suffix = be->be_suffix;
3420 cfb->cb_db.be_nsuffix = be->be_nsuffix;
3422 /* The suffix is always "cn=config". The underlying DB's rootdn
3423 * is always the same as the suffix.
3425 cfb->cb_db.be_rootdn = be->be_suffix[0];
3426 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
3428 ber_str2bv( dir, 0, 1, &cfdir );
3433 argv[0] = "directory";
3434 argv[1] = (char *)dir;
3439 c.table = Cft_Database;
3441 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
3445 if ( config_add_vals( ct, &c ))
3448 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
3452 void *thrctx = ldap_pvt_thread_pool_context();
3455 connection_fake_init( &conn, &opbuf, thrctx );
3458 filter.f_desc = slap_schema.si_ad_objectClass;
3460 op->o_tag = LDAP_REQ_SEARCH;
3462 op->ors_filter = &filter;
3463 op->ors_filterstr = filterstr;
3464 op->ors_scope = LDAP_SCOPE_SUBTREE;
3466 op->o_dn = c.be->be_rootdn;
3467 op->o_ndn = c.be->be_rootndn;
3469 op->o_req_dn = be->be_suffix[0];
3470 op->o_req_ndn = be->be_nsuffix[0];
3472 op->ors_tlimit = SLAP_NO_LIMIT;
3473 op->ors_slimit = SLAP_NO_LIMIT;
3475 op->ors_attrs = slap_anlist_all_attributes;
3476 op->ors_attrsonly = 0;
3478 op->o_callback = &cb;
3481 cb.sc_private = ≻
3482 sc.got_frontend = 0;
3487 op->o_bd = &cfb->cb_db;
3489 /* Allow unknown attrs in DNs */
3490 prev_DN_strict = slap_DN_strict;
3493 rc = op->o_bd->be_search( op, &rs );
3495 /* Restore normal DN validation */
3496 slap_DN_strict = prev_DN_strict;
3498 op->o_tag = LDAP_REQ_ADD;
3499 if ( rc == LDAP_SUCCESS && sc.frontend ) {
3500 op->ora_e = sc.frontend;
3501 rc = op->o_bd->be_add( op, &rs );
3503 if ( rc == LDAP_SUCCESS && sc.config ) {
3504 op->ora_e = sc.config;
3505 rc = op->o_bd->be_add( op, &rs );
3507 ldap_pvt_thread_pool_context_reset( thrctx );
3510 /* ITS#4194 - only use if it's present, or we're converting. */
3511 if ( !readit || rc == LDAP_SUCCESS )
3512 cfb->cb_use_ldif = 1;
3518 CfOc_cmp( const void *c1, const void *c2 ) {
3519 const ConfigOCs *co1 = c1;
3520 const ConfigOCs *co2 = c2;
3522 return ber_bvcmp( co1->co_name, co2->co_name );
3526 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
3529 i = init_config_attrs( ct );
3532 /* set up the objectclasses */
3533 i = init_config_ocs( ocs );
3536 for (i=0; ocs[i].co_def; i++) {
3537 if ( ocs[i].co_oc ) {
3538 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
3539 if ( !ocs[i].co_table )
3540 ocs[i].co_table = ct;
3541 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
3548 read_config(const char *fname, const char *dir) {
3551 const char *cfdir, *cfname;
3554 /* Setup the config backend */
3555 be = backend_db_init( "config", NULL, 0, NULL );
3559 cfb = be->be_private;
3560 be->be_dfltaccess = ACL_NONE;
3562 /* If no .conf, or a dir was specified, setup the dir */
3563 if ( !fname || dir ) {
3565 /* If explicitly given, check for existence */
3568 if ( stat( dir, &st ) < 0 ) {
3569 Debug( LDAP_DEBUG_ANY,
3570 "invalid config directory %s, error %d\n",
3576 cfdir = SLAPD_DEFAULT_CONFIGDIR;
3578 /* if fname is defaulted, try reading .d */
3579 rc = config_setup_ldif( be, cfdir, !fname );
3582 /* It may be OK if the base object doesn't exist yet. */
3583 if ( rc != LDAP_NO_SUCH_OBJECT )
3585 /* ITS#4194: But if dir was specified and no fname,
3586 * then we were supposed to read the dir. Unless we're
3587 * trying to slapadd the dir...
3589 if ( dir && !fname ) {
3590 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
3592 /* Assume it's slapadd with a config dir, let it continue */
3594 cfb->cb_got_ldif = 1;
3595 cfb->cb_use_ldif = 1;
3600 /* If we read the config from back-ldif, nothing to do here */
3601 if ( cfb->cb_got_ldif ) {
3610 cfname = SLAPD_DEFAULT_CONFIGFILE;
3612 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
3615 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
3618 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
3619 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
3620 &frontendDB->be_schemadn );
3621 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
3622 if ( rc != LDAP_SUCCESS ) {
3623 Debug(LDAP_DEBUG_ANY, "read_config: "
3624 "unable to normalize default schema DN \"%s\"\n",
3625 frontendDB->be_schemadn.bv_val, 0, 0 );
3626 /* must not happen */
3634 config_back_bind( Operation *op, SlapReply *rs )
3636 if ( be_isroot_pw( op ) ) {
3637 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
3638 /* frontend sends result */
3639 return LDAP_SUCCESS;
3642 rs->sr_err = LDAP_INVALID_CREDENTIALS;
3643 send_ldap_result( op, rs );
3649 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
3653 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
3655 rs->sr_attrs = op->ors_attrs;
3656 rs->sr_entry = ce->ce_entry;
3658 rc = send_search_entry( op, rs );
3659 if ( rc != LDAP_SUCCESS ) {
3663 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
3664 if ( ce->ce_kids ) {
3665 rc = config_send( op, rs, ce->ce_kids, 1 );
3666 if ( rc ) return rc;
3669 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
3670 rc = config_send( op, rs, ce, 0 );
3678 static ConfigTable *
3679 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
3684 for (j=0; j<nocs; j++) {
3685 for (i=0; colst[j]->co_table[i].name; i++)
3686 if ( colst[j]->co_table[i].ad == ad ) {
3687 ca->table = colst[j]->co_type;
3688 return &colst[j]->co_table[i];
3694 /* Sort the attributes of the entry according to the order defined
3695 * in the objectclass, with required attributes occurring before
3696 * allowed attributes. For any attributes with sequencing dependencies
3697 * (e.g., rootDN must be defined after suffix) the objectclass must
3698 * list the attributes in the desired sequence.
3701 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
3703 Attribute *a, *head = NULL, *tail = NULL, **prev;
3706 for (i=0; i<nocs; i++) {
3707 if ( colst[i]->co_oc->soc_required ) {
3708 AttributeType **at = colst[i]->co_oc->soc_required;
3709 for (j=0; at[j]; j++) {
3710 for (a=e->e_attrs, prev=&e->e_attrs; a;
3711 prev = &(*prev)->a_next, a=a->a_next) {
3712 if ( a->a_desc == at[j]->sat_ad ) {
3726 if ( colst[i]->co_oc->soc_allowed ) {
3727 AttributeType **at = colst[i]->co_oc->soc_allowed;
3728 for (j=0; at[j]; j++) {
3729 for (a=e->e_attrs, prev=&e->e_attrs; a;
3730 prev = &(*prev)->a_next, a=a->a_next) {
3731 if ( a->a_desc == at[j]->sat_ad ) {
3747 tail->a_next = e->e_attrs;
3753 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
3755 Attribute *a = NULL;
3756 AttributeDescription *ad;
3766 Modifications *ml = ptr;
3768 vals = ml->sml_values;
3771 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
3772 rc = ordered_value_sort( a, 1 );
3774 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
3775 ad->ad_cname.bv_val );
3779 for ( i=0; vals[i].bv_val; i++ ) {
3780 ca->line = vals[i].bv_val;
3781 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
3782 ca->line[0] == '{' ) {
3783 char *idx = strchr( ca->line, '}' );
3784 if ( idx ) ca->line = idx+1;
3786 rc = config_parse_vals( ct, ca, i );
3795 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
3798 struct berval rtype, rval;
3800 AttributeDescription *ad = NULL;
3802 dnRdn( &e->e_name, rdn );
3803 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
3804 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
3805 rtype.bv_val = rdn->bv_val;
3806 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
3809 slap_bv2ad( &rtype, &ad, &rs->sr_text );
3810 a = attr_find( e->e_attrs, ad );
3811 if (!a ) return LDAP_NAMING_VIOLATION;
3818 config_rename_kids( CfEntryInfo *ce )
3821 struct berval rdn, nrdn;
3823 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
3824 struct berval newdn, newndn;
3825 dnRdn ( &ce2->ce_entry->e_name, &rdn );
3826 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
3827 build_new_dn( &newdn, &ce->ce_entry->e_name, &rdn, NULL );
3828 build_new_dn( &newndn, &ce->ce_entry->e_nname, &nrdn, NULL );
3829 free( ce2->ce_entry->e_name.bv_val );
3830 free( ce2->ce_entry->e_nname.bv_val );
3831 ce2->ce_entry->e_name = newdn;
3832 ce2->ce_entry->e_nname = newndn;
3833 config_rename_kids( ce2 );
3838 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
3839 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
3840 struct berval *nnewrdn, int use_ldif )
3844 struct berval odn, ondn;
3848 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
3849 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
3852 free( a->a_vals[0].bv_val );
3853 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
3854 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
3855 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
3856 strcpy( a->a_vals[0].bv_val, ptr1 );
3858 if ( a->a_nvals != a->a_vals ) {
3859 free( a->a_nvals[0].bv_val );
3860 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
3861 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
3862 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
3863 strcpy( a->a_nvals[0].bv_val, ptr1 );
3866 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
3867 BackendDB *be = op->o_bd;
3868 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
3869 struct berval dn, ndn, xdn, xndn;
3871 op->o_bd = &cfb->cb_db;
3873 /* Save current rootdn; use the underlying DB's rootdn */
3877 xndn = op->o_req_ndn;
3878 op->o_dn = op->o_bd->be_rootdn;
3879 op->o_ndn = op->o_bd->be_rootndn;
3881 op->o_req_ndn = ondn;
3883 scp = op->o_callback;
3884 op->o_callback = ≻
3885 op->orr_newrdn = *newrdn;
3886 op->orr_nnewrdn = *nnewrdn;
3887 op->orr_newSup = NULL;
3888 op->orr_nnewSup = NULL;
3889 op->orr_deleteoldrdn = 1;
3890 op->orr_modlist = NULL;
3891 slap_modrdn2mods( op, rs );
3892 slap_mods_opattrs( op, &op->orr_modlist, 1 );
3893 rc = op->o_bd->be_modrdn( op, rs );
3894 slap_mods_free( op->orr_modlist, 1 );
3897 op->o_callback = scp;
3901 op->o_req_ndn = xndn;
3904 free( ondn.bv_val );
3906 config_rename_kids( e->e_private );
3911 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
3912 Entry *e, int idx, int tailindex, int use_ldif )
3914 struct berval ival, newrdn, nnewrdn;
3917 char ibuf[32], *ptr1, *ptr2 = NULL;
3920 rc = config_rename_attr( rs, e, &rdn, &a );
3921 if ( rc ) return rc;
3924 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
3925 if ( ival.bv_len >= sizeof( ibuf ) ) {
3926 return LDAP_NAMING_VIOLATION;
3929 newrdn.bv_len = rdn.bv_len + ival.bv_len;
3930 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
3933 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
3934 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3937 ptr2 = ber_bvchr( &rdn, '}' );
3941 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
3943 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
3944 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
3945 a->a_desc->ad_cname.bv_len );
3947 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3948 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
3952 /* Do the equivalent of ModRDN */
3953 /* Replace DN / NDN */
3954 newrdn.bv_len = ptr1 - newrdn.bv_val;
3955 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
3956 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
3958 free( nnewrdn.bv_val );
3959 free( newrdn.bv_val );
3964 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
3965 SlapReply *rs, int *renum, int *ibase )
3968 int index = -1, gotindex = 0, nsibs, rc = 0;
3969 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
3970 char *ptr1, *ptr2 = NULL;
3973 if ( renum ) *renum = 0;
3975 /* These entries don't get indexed/renumbered */
3976 if ( ce_type == Cft_Global ) return 0;
3977 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
3979 if ( ce_type == Cft_Module )
3982 /* See if the rdn has an index already */
3983 dnRdn( &e->e_name, &rdn );
3984 if ( ce_type == Cft_Database ) {
3985 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
3986 "frontend", STRLENOF("frontend") ))
3988 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
3989 "config", STRLENOF("config") ))
3992 ptr1 = ber_bvchr( &e->e_name, '{' );
3993 if ( ptr1 && ptr1 < &e->e_name.bv_val[ rdn.bv_len ] ) {
3995 ptr2 = strchr( ptr1, '}' );
3996 if ( !ptr2 || ptr2 > &e->e_name.bv_val[ rdn.bv_len ] )
3997 return LDAP_NAMING_VIOLATION;
3998 if ( ptr2-ptr1 == 1)
3999 return LDAP_NAMING_VIOLATION;
4001 index = strtol( ptr1 + 1, &next, 10 );
4002 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
4003 return LDAP_NAMING_VIOLATION;
4006 /* Special case, we allow -1 for the frontendDB */
4007 if ( index != -1 || !isfrontend )
4008 return LDAP_NAMING_VIOLATION;
4010 if ( isconfig && index != 0 ){
4011 return LDAP_NAMING_VIOLATION;
4015 /* count related kids */
4016 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
4017 if ( ce->ce_type == ce_type ) nsibs++;
4020 /* account for -1 frontend */
4021 if ( ce_type == Cft_Database )
4024 if ( index != nsibs ) {
4026 if ( index < nsibs ) {
4027 if ( tailindex ) return LDAP_NAMING_VIOLATION;
4028 /* Siblings need to be renumbered */
4029 if ( index != -1 || !isfrontend )
4033 /* config DB is always "0" */
4034 if ( isconfig && index == -1 ) {
4037 if (( !isfrontend && index == -1 ) || ( index > nsibs ) ){
4041 /* just make index = nsibs */
4043 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
4046 if ( ibase ) *ibase = index;
4047 if ( renum ) *renum = renumber;
4052 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
4057 co.co_name = &oc->soc_cname;
4058 cop = avl_find( CfOcTree, &co, CfOc_cmp );
4062 /* check for duplicates */
4063 for ( i = 0; i < *nocs; i++ ) {
4064 if ( *copp && (*copp)[i] == cop ) {
4070 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
4071 if ( tmp == NULL ) {
4075 (*copp)[*nocs] = cop;
4080 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
4081 if ( count_oc( *sups, copp, nocs ) ) {
4090 count_ocs( Attribute *oc_at, int *nocs )
4093 ConfigOCs **colst = NULL;
4097 for ( i = 0; !BER_BVISNULL( &oc_at->a_nvals[i] ); i++ )
4101 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
4103 assert( oc != NULL );
4104 if ( count_oc( oc, &colst, nocs ) ) {
4114 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4116 /* Leftover from RE23. Never parse this entry */
4117 return LDAP_COMPARE_TRUE;
4121 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4125 /* This entry is hardcoded, don't re-parse it */
4126 if ( p->ce_type == Cft_Global ) {
4127 cfn = p->ce_private;
4128 ca->ca_private = cfn;
4129 return LDAP_COMPARE_TRUE;
4131 if ( p->ce_type != Cft_Schema )
4132 return LDAP_CONSTRAINT_VIOLATION;
4134 cfn = ch_calloc( 1, sizeof(ConfigFile) );
4135 ca->ca_private = cfn;
4136 cfo = p->ce_private;
4137 cfn->c_sibs = cfo->c_kids;
4139 return LDAP_SUCCESS;
4143 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4145 if ( p->ce_type != Cft_Global ) {
4146 return LDAP_CONSTRAINT_VIOLATION;
4148 /* config must be {0}, nothing else allowed */
4149 if ( !strncmp( e->e_nname.bv_val, "olcDatabase={0}", STRLENOF("olcDatabase={0}")) &&
4150 strncmp( e->e_nname.bv_val + STRLENOF("olcDatabase={0}"), "config,", STRLENOF("config,") )) {
4151 return LDAP_CONSTRAINT_VIOLATION;
4153 ca->be = frontendDB; /* just to get past check_vals */
4154 return LDAP_SUCCESS;
4158 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4160 if ( p->ce_type != Cft_Global ) {
4161 return LDAP_CONSTRAINT_VIOLATION;
4163 return LDAP_SUCCESS;
4167 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4169 if ( p->ce_type != Cft_Global ) {
4170 return LDAP_CONSTRAINT_VIOLATION;
4172 return LDAP_SUCCESS;
4176 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4178 if ( p->ce_type != Cft_Database ) {
4179 return LDAP_CONSTRAINT_VIOLATION;
4182 return LDAP_SUCCESS;
4186 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
4191 AttributeDescription *ad;
4196 if ( cfn->c_cr_head ) {
4197 struct berval bv = BER_BVC("olcDitContentRules");
4199 slap_bv2ad( &bv, &ad, &text );
4200 ct = config_find_table( colst, nocs, ad, ca );
4201 config_del_vals( ct, ca );
4203 if ( cfn->c_oc_head ) {
4204 struct berval bv = BER_BVC("olcObjectClasses");
4206 slap_bv2ad( &bv, &ad, &text );
4207 ct = config_find_table( colst, nocs, ad, ca );
4208 config_del_vals( ct, ca );
4210 if ( cfn->c_at_head ) {
4211 struct berval bv = BER_BVC("olcAttributeTypes");
4213 slap_bv2ad( &bv, &ad, &text );
4214 ct = config_find_table( colst, nocs, ad, ca );
4215 config_del_vals( ct, ca );
4217 if ( cfn->c_syn_head ) {
4218 struct berval bv = BER_BVC("olcLdapSyntaxes");
4220 slap_bv2ad( &bv, &ad, &text );
4221 ct = config_find_table( colst, nocs, ad, ca );
4222 config_del_vals( ct, ca );
4224 if ( cfn->c_om_head ) {
4225 struct berval bv = BER_BVC("olcObjectIdentifier");
4227 slap_bv2ad( &bv, &ad, &text );
4228 ct = config_find_table( colst, nocs, ad, ca );
4229 config_del_vals( ct, ca );
4231 cfo = p->ce_private;
4232 cfo->c_kids = cfn->c_sibs;
4237 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
4239 int rc = LDAP_CONSTRAINT_VIOLATION;
4242 if ( (*cop)->co_ldadd ) {
4243 rc = (*cop)->co_ldadd( last, e, ca );
4244 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4249 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
4250 ConfigOCs co = { 0 };
4252 co.co_name = &(*ocp)->soc_cname;
4253 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
4254 if ( *cop == NULL ) {
4258 rc = config_add_oc( cop, last, e, ca );
4259 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4267 /* Parse an LDAP entry into config directives */
4269 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
4270 int *renum, Operation *op )
4272 CfEntryInfo *ce, *last = NULL;
4273 ConfigOCs co, *coptr, **colst;
4274 Attribute *a, *oc_at, *soc_at;
4275 int i, ibase = -1, nocs, rc = 0;
4278 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
4280 memset( ca, 0, sizeof(ConfigArgs));
4282 /* Make sure parent exists and entry does not. But allow
4283 * Databases and Overlays to be inserted. Don't do any
4284 * auto-renumbering if manageDSAit control is present.
4286 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
4288 if ( ( op && op->o_managedsait ) ||
4289 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
4290 ce->ce_type != Cft_Module ) )
4292 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4293 "DN=\"%s\" already exists\n",
4294 log_prefix, e->e_name.bv_val, 0 );
4295 return LDAP_ALREADY_EXISTS;
4299 dnParent( &e->e_nname, &pdn );
4301 /* If last is NULL, the new entry is the root/suffix entry,
4302 * otherwise last should be the parent.
4304 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
4306 rs->sr_matched = last->ce_entry->e_name.bv_val;
4308 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4309 "DN=\"%s\" not child of DN=\"%s\"\n",
4310 log_prefix, e->e_name.bv_val,
4311 last->ce_entry->e_name.bv_val );
4312 return LDAP_NO_SUCH_OBJECT;
4316 /* No parent, must be root. This will never happen... */
4317 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
4318 return LDAP_NO_SUCH_OBJECT;
4321 if ( last && !access_allowed( op, last->ce_entry,
4322 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
4324 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4325 "DN=\"%s\" no write access to \"children\" of parent\n",
4326 log_prefix, e->e_name.bv_val, 0 );
4327 return LDAP_INSUFFICIENT_ACCESS;
4331 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4333 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4334 "DN=\"%s\" no objectClass\n",
4335 log_prefix, e->e_name.bv_val, 0 );
4336 return LDAP_OBJECT_CLASS_VIOLATION;
4339 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4341 ObjectClass *soc = NULL;
4342 char textbuf[ SLAP_TEXT_BUFLEN ];
4343 const char *text = textbuf;
4345 /* FIXME: check result */
4346 rc = structural_class( oc_at->a_nvals, &soc, NULL,
4347 &text, textbuf, sizeof(textbuf), NULL );
4348 if ( rc != LDAP_SUCCESS ) {
4349 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4350 "DN=\"%s\" no structural objectClass (%s)\n",
4351 log_prefix, e->e_name.bv_val, text );
4354 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
4355 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4356 if ( soc_at == NULL ) {
4357 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4358 "DN=\"%s\" no structural objectClass; "
4359 "unable to merge computed class %s\n",
4360 log_prefix, e->e_name.bv_val,
4361 soc->soc_cname.bv_val );
4362 return LDAP_OBJECT_CLASS_VIOLATION;
4365 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4366 "DN=\"%s\" no structural objectClass; "
4367 "computed objectClass %s merged\n",
4368 log_prefix, e->e_name.bv_val,
4369 soc->soc_cname.bv_val );
4372 /* Fake the coordinates based on whether we're part of an
4373 * LDAP Add or if reading the config dir
4376 ca->fname = "slapd";
4379 ca->fname = cfdir.bv_val;
4384 co.co_name = &soc_at->a_nvals[0];
4385 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
4386 if ( coptr == NULL ) {
4387 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4388 "DN=\"%s\" no structural objectClass in configuration table\n",
4389 log_prefix, e->e_name.bv_val, 0 );
4390 return LDAP_OBJECT_CLASS_VIOLATION;
4393 /* Only the root can be Cft_Global, everything else must
4394 * have a parent. Only limited nesting arrangements are allowed.
4396 rc = LDAP_CONSTRAINT_VIOLATION;
4397 if ( coptr->co_type == Cft_Global && !last ) {
4398 cfn = cfb->cb_config;
4399 ca->ca_private = cfn;
4400 ca->be = frontendDB; /* just to get past check_vals */
4404 colst = count_ocs( oc_at, &nocs );
4406 /* Check whether the Add is allowed by its parent, and do
4407 * any necessary arg setup
4410 rc = config_add_oc( &coptr, last, e, ca );
4411 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4412 for ( i = 0; i<nocs; i++ ) {
4413 /* Already checked these */
4414 if ( colst[i]->co_oc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
4416 if ( colst[i]->co_ldadd &&
4417 ( rc = colst[i]->co_ldadd( last, e, ca ))
4418 != LDAP_CONSTRAINT_VIOLATION ) {
4424 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4425 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4426 "DN=\"%s\" no structural objectClass add function\n",
4427 log_prefix, e->e_name.bv_val, 0 );
4428 return LDAP_OBJECT_CLASS_VIOLATION;
4432 /* Add the entry but don't parse it, we already have its contents */
4433 if ( rc == LDAP_COMPARE_TRUE ) {
4438 if ( rc != LDAP_SUCCESS )
4441 /* Parse all the values and check for simple syntax errors before
4442 * performing any set actions.
4444 * If doing an LDAPadd, check for indexed names and any necessary
4445 * renaming/renumbering. Entries that don't need indexed names are
4446 * ignored. Entries that need an indexed name and arrive without one
4447 * are assigned to the end. Entries that arrive with an index may
4448 * cause the following entries to be renumbered/bumped down.
4450 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
4451 * don't allow Adding an entry with an index that's already in use.
4452 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
4454 * These entries can have auto-assigned indexes (appended to the end)
4455 * but only the other types support auto-renumbering of siblings.
4458 rc = check_name_index( last, coptr->co_type, e, rs, renum,
4463 if ( renum && *renum && coptr->co_type != Cft_Database &&
4464 coptr->co_type != Cft_Overlay )
4466 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
4467 "operation requires sibling renumbering" );
4468 rc = LDAP_UNWILLING_TO_PERFORM;
4473 init_config_argv( ca );
4475 /* Make sure we process attrs in the required order */
4476 sort_attrs( e, colst, nocs );
4478 for ( a = e->e_attrs; a; a = a->a_next ) {
4479 if ( a == oc_at ) continue;
4480 ct = config_find_table( colst, nocs, a->a_desc, ca );
4481 if ( !ct ) continue; /* user data? */
4482 rc = check_vals( ct, ca, a, 1 );
4483 if ( rc ) goto done_noop;
4486 /* Basic syntax checks are OK. Do the actual settings. */
4487 for ( a=e->e_attrs; a; a=a->a_next ) {
4488 if ( a == oc_at ) continue;
4489 ct = config_find_table( colst, nocs, a->a_desc, ca );
4490 if ( !ct ) continue; /* user data? */
4491 for (i=0; a->a_vals[i].bv_val; i++) {
4494 ca->line = a->a_vals[i].bv_val;
4495 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
4496 ptr = strchr( ca->line, '}' );
4498 iptr = strchr( ca->line, '{' );
4502 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
4504 ca->valx = strtol( iptr+1, NULL, 0 );
4509 rc = config_parse_add( ct, ca, i );
4517 /* Newly added databases and overlays need to be started up */
4518 if ( CONFIG_ONLINE_ADD( ca )) {
4519 if ( colst[0]->co_type == Cft_Database ) {
4520 rc = backend_startup_one( ca->be, &ca->reply );
4522 } else if ( colst[0]->co_type == Cft_Overlay ) {
4523 if ( ca->bi->bi_db_open ) {
4524 BackendInfo *bi_orig = ca->be->bd_info;
4525 ca->be->bd_info = ca->bi;
4526 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
4527 ca->be->bd_info = bi_orig;
4529 } else if ( ca->cleanup ) {
4530 rc = ca->cleanup( ca );
4533 if (ca->cr_msg[0] == '\0')
4534 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
4536 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
4537 ca->log, ca->cr_msg, ca->argv[1] );
4544 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
4545 ce->ce_parent = last;
4546 ce->ce_entry = entry_dup( e );
4547 ce->ce_entry->e_private = ce;
4548 ce->ce_type = colst[0]->co_type;
4551 ce->ce_private = ca->ca_private;
4552 ca->ca_entry = ce->ce_entry;
4555 } else if ( last->ce_kids ) {
4556 CfEntryInfo *c2, **cprev;
4558 /* Advance to first of this type */
4559 cprev = &last->ce_kids;
4560 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
4561 cprev = &c2->ce_sibs;
4564 /* Account for the (-1) frontendDB entry */
4565 if ( ce->ce_type == Cft_Database ) {
4566 if ( ca->be == frontendDB )
4568 else if ( ibase != -1 )
4573 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
4574 cprev = &c2->ce_sibs;
4580 for ( i=0; i<ibase; i++ ) {
4582 cprev = &c2->ce_sibs;
4585 ce->ce_sibs = *cprev;
4593 if ( (colst[0]->co_type == Cft_Database) && ca->be ) {
4594 if ( ca->be != frontendDB )
4595 backend_destroy_one( ca->be, 1 );
4596 } else if ( (colst[0]->co_type == Cft_Overlay) && ca->bi ) {
4597 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
4598 } else if ( colst[0]->co_type == Cft_Schema ) {
4599 schema_destroy_one( ca, colst, nocs, last );
4604 ch_free( ca->argv );
4605 if ( colst ) ch_free( colst );
4609 #define BIGTMP 10000
4611 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
4612 int base, int rebase, int max, int use_ldif )
4614 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
4615 ConfigType etype = ce->ce_type;
4616 int count = 0, rc = 0;
4618 /* Reverse ce list */
4619 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
4620 if (ce2->ce_type != etype) {
4625 ce2->ce_sibs = cetmp;
4628 if ( max && count >= max ) {
4634 /* Move original to a temp name until increments are done */
4636 ce->ce_entry->e_private = NULL;
4637 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4638 base+BIGTMP, 0, use_ldif );
4639 ce->ce_entry->e_private = ce;
4641 /* start incrementing */
4642 for (ce2=cetmp; ce2; ce2=ce3) {
4644 ce2->ce_sibs = cerem;
4647 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
4648 count+base, 0, use_ldif );
4652 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4653 base, 0, use_ldif );
4658 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
4659 CfEntryInfo *ce2, int old, int use_ldif )
4663 /* Renumber original to a temp value */
4664 ce->ce_entry->e_private = NULL;
4665 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4666 old+BIGTMP, 0, use_ldif );
4667 ce->ce_entry->e_private = ce;
4669 /* start decrementing */
4670 for (; ce2 != ce; ce2=ce2->ce_sibs) {
4671 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
4672 count+old, 0, use_ldif );
4675 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4676 count+old, 0, use_ldif );
4679 /* Parse an LDAP entry into config directives, then store in underlying
4683 config_back_add( Operation *op, SlapReply *rs )
4689 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
4690 NULL, ACL_WADD, NULL )) {
4691 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4696 * Check for attribute ACL
4698 if ( !acl_check_modlist( op, op->ora_e, op->orm_modlist )) {
4699 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4700 rs->sr_text = "no write access to attribute";
4704 cfb = (CfBackInfo *)op->o_bd->be_private;
4706 /* add opattrs for syncprov */
4708 char textbuf[SLAP_TEXT_BUFLEN];
4709 size_t textlen = sizeof textbuf;
4710 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1, NULL,
4711 &rs->sr_text, textbuf, sizeof( textbuf ) );
4712 if ( rs->sr_err != LDAP_SUCCESS )
4714 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
4715 if ( rs->sr_err != LDAP_SUCCESS ) {
4716 Debug( LDAP_DEBUG_TRACE,
4717 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
4718 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
4723 ldap_pvt_thread_pool_pause( &connection_pool );
4726 * 1) check for existence of entry
4727 * 2) check for sibling renumbering
4728 * 3) perform internal add
4729 * 4) perform any necessary renumbering
4730 * 5) store entry in underlying database
4732 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
4733 if ( rs->sr_err != LDAP_SUCCESS ) {
4734 rs->sr_text = ca.cr_msg;
4739 CfEntryInfo *ce = ca.ca_entry->e_private;
4740 req_add_s addr = op->oq_add;
4741 op->o_tag = LDAP_REQ_MODRDN;
4742 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
4743 op->o_tag = LDAP_REQ_ADD;
4745 if ( rs->sr_err != LDAP_SUCCESS ) {
4750 if ( cfb->cb_use_ldif ) {
4751 BackendDB *be = op->o_bd;
4752 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4753 struct berval dn, ndn;
4755 op->o_bd = &cfb->cb_db;
4757 /* Save current rootdn; use the underlying DB's rootdn */
4760 op->o_dn = op->o_bd->be_rootdn;
4761 op->o_ndn = op->o_bd->be_rootndn;
4763 scp = op->o_callback;
4764 op->o_callback = ≻
4765 op->o_bd->be_add( op, rs );
4767 op->o_callback = scp;
4773 ldap_pvt_thread_pool_resume( &connection_pool );
4776 send_ldap_result( op, rs );
4777 slap_graduate_commit_csn( op );
4781 typedef struct delrec {
4782 struct delrec *next;
4788 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
4794 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
4795 ca->line[0] == '{' )
4797 char *ptr = strchr( ca->line + 1, '}' );
4801 ca->valx = strtol( ca->line + 1, &next, 0 );
4802 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
4808 rc = config_parse_add( ct, ca, i );
4816 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
4819 int rc = LDAP_UNWILLING_TO_PERFORM;
4821 Entry *e = ce->ce_entry;
4822 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
4827 delrec *dels = NULL, *deltail = NULL;
4829 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4830 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
4832 colst = count_ocs( oc_at, &nocs );
4834 /* make sure add/del flags are clear; should always be true */
4835 for ( s = save_attrs; s; s = s->a_next ) {
4836 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
4839 e->e_attrs = attrs_dup( e->e_attrs );
4841 init_config_argv( ca );
4844 ca->ca_private = ce->ce_private;
4846 ca->fname = "slapd";
4848 strcpy( ca->log, "back-config" );
4850 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
4851 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
4852 switch (ml->sml_op) {
4853 case LDAP_MOD_DELETE:
4854 case LDAP_MOD_REPLACE: {
4855 BerVarray vals = NULL, nvals = NULL;
4857 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
4859 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
4860 ml->sml_desc->ad_cname.bv_val );
4863 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4864 vals = ml->sml_values;
4865 nvals = ml->sml_nvalues;
4866 ml->sml_values = NULL;
4867 ml->sml_nvalues = NULL;
4869 /* If we're deleting by values, remember the indexes of the
4870 * values we deleted.
4872 if ( ct && ml->sml_values ) {
4874 i = ml->sml_numvals;
4875 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
4886 rc = modify_delete_vindex(e, &ml->sml_mod,
4887 get_permissiveModify(op),
4888 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
4889 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4890 ml->sml_values = vals;
4891 ml->sml_nvalues = nvals;
4896 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
4899 case SLAP_MOD_SOFTADD: {
4900 int mop = ml->sml_op;
4902 ml->sml_op = LDAP_MOD_ADD;
4904 if ( ct->arg_type & ARG_NO_INSERT ) {
4905 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
4907 navals = a->a_numvals;
4910 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
4911 if ( ml->sml_values[i].bv_val[0] == '{' &&
4914 char *next, *val = ml->sml_values[i].bv_val + 1;
4917 j = strtol( val, &next, 0 );
4918 if ( next == val || next[ 0 ] != '}' || j < navals ) {
4920 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
4921 ml->sml_desc->ad_cname.bv_val );
4925 rc = check_vals( ct, ca, ml, 0 );
4926 if ( rc ) goto out_noop;
4929 rc = modify_add_values(e, &ml->sml_mod,
4930 get_permissiveModify(op),
4931 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
4933 /* If value already exists, show success here
4934 * and ignore this operation down below.
4936 if ( mop == SLAP_MOD_SOFTADD ) {
4937 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
4947 case LDAP_MOD_INCREMENT: /* FIXME */
4952 if(rc != LDAP_SUCCESS) break;
4955 if ( rc == LDAP_SUCCESS) {
4956 /* check that the entry still obeys the schema */
4957 rc = entry_schema_check(op, e, NULL, 0, 0, NULL,
4958 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
4960 if ( rc ) goto out_noop;
4962 /* Basic syntax checks are OK. Do the actual settings. */
4963 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
4964 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
4965 if ( !ct ) continue;
4967 s = attr_find( save_attrs, ml->sml_desc );
4968 a = attr_find( e->e_attrs, ml->sml_desc );
4970 switch (ml->sml_op) {
4971 case LDAP_MOD_DELETE:
4972 case LDAP_MOD_REPLACE: {
4973 BerVarray vals = NULL, nvals = NULL;
4976 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4977 vals = ml->sml_values;
4978 nvals = ml->sml_nvalues;
4979 ml->sml_values = NULL;
4980 ml->sml_nvalues = NULL;
4983 if ( ml->sml_values )
4986 /* If we didn't delete the whole attribute */
4987 if ( ml->sml_values && a ) {
4988 struct berval *mvals;
4991 if ( ml->sml_nvalues )
4992 mvals = ml->sml_nvalues;
4994 mvals = ml->sml_values;
4996 /* use the indexes we saved up above */
4997 for (i=0; i < d->nidx; i++) {
4998 struct berval bv = *mvals++;
4999 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
5000 bv.bv_val[0] == '{' ) {
5001 ptr = strchr( bv.bv_val, '}' ) + 1;
5002 bv.bv_len -= ptr - bv.bv_val;
5005 ca->line = bv.bv_val;
5006 ca->valx = d->idx[i];
5007 rc = config_del_vals( ct, ca );
5008 if ( rc != LDAP_SUCCESS ) break;
5010 s->a_flags |= SLAP_ATTR_IXDEL;
5011 for (j=i+1; j < d->nidx; j++)
5012 if ( d->idx[j] >d->idx[i] )
5018 rc = config_del_vals( ct, ca );
5019 if ( rc ) rc = LDAP_OTHER;
5021 s->a_flags |= SLAP_ATTR_IXDEL;
5023 if ( ml->sml_values ) {
5028 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5029 ml->sml_values = vals;
5030 ml->sml_nvalues = nvals;
5032 if ( !vals || rc != LDAP_SUCCESS )
5035 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5038 for (i=0; ml->sml_values[i].bv_val; i++) {
5039 ca->line = ml->sml_values[i].bv_val;
5041 rc = config_modify_add( ct, ca, ml->sml_desc, i );
5044 a->a_flags |= SLAP_ATTR_IXADD;
5051 /* Undo for a failed operation */
5052 if ( rc != LDAP_SUCCESS ) {
5053 ConfigReply msg = ca->reply;
5054 for ( s = save_attrs; s; s = s->a_next ) {
5055 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
5056 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5057 ct = config_find_table( colst, nocs, s->a_desc, ca );
5058 a = attr_find( e->e_attrs, s->a_desc );
5060 /* clear the flag so the add check below will skip it */
5061 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5064 config_del_vals( ct, ca );
5066 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5067 ca->line = s->a_vals[i].bv_val;
5069 config_modify_add( ct, ca, s->a_desc, i );
5073 for ( a = e->e_attrs; a; a = a->a_next ) {
5074 if ( a->a_flags & SLAP_ATTR_IXADD ) {
5075 ct = config_find_table( colst, nocs, a->a_desc, ca );
5078 config_del_vals( ct, ca );
5079 s = attr_find( save_attrs, a->a_desc );
5081 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5082 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5083 ca->line = s->a_vals[i].bv_val;
5085 config_modify_add( ct, ca, s->a_desc, i );
5096 if ( rc == LDAP_SUCCESS ) {
5097 attrs_free( save_attrs );
5099 attrs_free( e->e_attrs );
5100 e->e_attrs = save_attrs;
5102 ch_free( ca->argv );
5103 if ( colst ) ch_free( colst );
5105 deltail = dels->next;
5114 config_back_modify( Operation *op, SlapReply *rs )
5117 CfEntryInfo *ce, *last;
5119 ConfigArgs ca = {0};
5122 AttributeDescription *rad = NULL;
5125 cfb = (CfBackInfo *)op->o_bd->be_private;
5127 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5130 rs->sr_matched = last->ce_entry->e_name.bv_val;
5131 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5135 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
5136 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5140 /* Get type of RDN */
5141 rdn = ce->ce_entry->e_nname;
5142 ptr = strchr( rdn.bv_val, '=' );
5143 rdn.bv_len = ptr - rdn.bv_val;
5144 slap_bv2ad( &rdn, &rad, &rs->sr_text );
5146 /* Some basic validation... */
5147 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5148 /* Don't allow Modify of RDN; must use ModRdn for that. */
5149 if ( ml->sml_desc == rad ) {
5150 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
5151 rs->sr_text = "Use modrdn to change the entry name";
5154 /* Internal update of contextCSN? */
5155 if ( ml->sml_desc == slap_schema.si_ad_contextCSN && op->o_conn->c_conn_idx == -1 ) {
5161 slap_mods_opattrs( op, &op->orm_modlist, 1 );
5164 ldap_pvt_thread_pool_pause( &connection_pool );
5167 * 1) perform the Modify on the cached Entry.
5168 * 2) verify that the Entry still satisfies the schema.
5169 * 3) perform the individual config operations.
5170 * 4) store Modified entry in underlying LDIF backend.
5172 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
5174 rs->sr_text = ca.cr_msg;
5175 } else if ( cfb->cb_use_ldif ) {
5176 BackendDB *be = op->o_bd;
5177 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5178 struct berval dn, ndn;
5180 op->o_bd = &cfb->cb_db;
5184 op->o_dn = op->o_bd->be_rootdn;
5185 op->o_ndn = op->o_bd->be_rootndn;
5187 scp = op->o_callback;
5188 op->o_callback = ≻
5189 op->o_bd->be_modify( op, rs );
5191 op->o_callback = scp;
5197 ldap_pvt_thread_pool_resume( &connection_pool );
5199 send_ldap_result( op, rs );
5200 slap_graduate_commit_csn( op );
5205 config_back_modrdn( Operation *op, SlapReply *rs )
5208 CfEntryInfo *ce, *last;
5212 cfb = (CfBackInfo *)op->o_bd->be_private;
5214 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5217 rs->sr_matched = last->ce_entry->e_name.bv_val;
5218 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5221 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
5222 NULL, ACL_WRITE, NULL )) {
5223 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5227 if ( ce->ce_parent )
5228 parent = ce->ce_parent->ce_entry;
5230 parent = (Entry *)&slap_entry_root;
5231 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
5232 NULL, ACL_WRITE, NULL )) {
5233 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5238 /* We don't allow moving objects to new parents.
5239 * Generally we only allow reordering a set of ordered entries.
5241 if ( op->orr_newSup ) {
5242 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5246 /* If newRDN == oldRDN, quietly succeed */
5247 dnRdn( &op->o_req_ndn, &rdn );
5248 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
5249 rs->sr_err = LDAP_SUCCESS;
5253 /* Current behavior, subject to change as needed:
5255 * For backends and overlays, we only allow renumbering.
5256 * For schema, we allow renaming with the same number.
5257 * Otherwise, the op is not allowed.
5260 if ( ce->ce_type == Cft_Schema ) {
5264 /* Can't alter the main cn=schema entry */
5265 if ( ce->ce_parent->ce_type == Cft_Global ) {
5266 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5267 rs->sr_text = "renaming not allowed for this entry";
5271 /* We could support this later if desired */
5272 ptr1 = ber_bvchr( &rdn, '}' );
5273 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5274 len = ptr1 - rdn.bv_val;
5275 if ( len != ptr2 - op->orr_newrdn.bv_val ||
5276 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
5277 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5278 rs->sr_text = "schema reordering not supported";
5281 } else if ( ce->ce_type == Cft_Database ||
5282 ce->ce_type == Cft_Overlay ) {
5283 char *ptr1, *ptr2, *iptr1, *iptr2;
5286 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
5287 if ( *iptr2 != '{' ) {
5288 rs->sr_err = LDAP_NAMING_VIOLATION;
5289 rs->sr_text = "new ordering index is required";
5293 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
5294 ptr1 = ber_bvchr( &rdn, '}' );
5295 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5297 rs->sr_err = LDAP_NAMING_VIOLATION;
5298 rs->sr_text = "new ordering index is required";
5302 len1 = ptr1 - rdn.bv_val;
5303 len2 = ptr2 - op->orr_newrdn.bv_val;
5305 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
5306 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
5307 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5308 rs->sr_text = "changing database/overlay type not allowed";
5311 ixold = strtol( iptr1, NULL, 0 );
5312 ixnew = strtol( iptr2, &ptr1, 0 );
5313 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
5314 rs->sr_err = LDAP_NAMING_VIOLATION;
5317 /* config DB is always 0, cannot be changed */
5318 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
5319 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
5323 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5324 rs->sr_text = "renaming not supported for this entry";
5328 ldap_pvt_thread_pool_pause( &connection_pool );
5330 if ( ce->ce_type == Cft_Schema ) {
5331 req_modrdn_s modr = op->oq_modrdn;
5334 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
5335 if ( rs->sr_err == LDAP_SUCCESS ) {
5336 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
5337 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
5340 op->oq_modrdn = modr;
5342 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
5343 req_modrdn_s modr = op->oq_modrdn;
5346 /* Advance to first of this type */
5347 cprev = &ce->ce_parent->ce_kids;
5348 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
5349 cprev = &ce2->ce_sibs;
5352 /* Skip the -1 entry */
5353 if ( ce->ce_type == Cft_Database ) {
5354 cprev = &ce2->ce_sibs;
5360 /* Remove from old slot */
5361 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
5362 cprev = &ce2->ce_sibs;
5363 *cprev = ce->ce_sibs;
5364 ceold = ce->ce_sibs;
5366 /* Insert into new slot */
5368 for ( i=0; i<ixnew; i++ ) {
5372 cprev = &ce2->ce_sibs;
5374 ce->ce_sibs = *cprev;
5379 /* NOTE: These should be encoded in the OC tables, not inline here */
5380 if ( ce->ce_type == Cft_Database )
5381 backend_db_move( ce->ce_be, ixnew );
5382 else if ( ce->ce_type == Cft_Overlay )
5383 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
5385 if ( ixold < ixnew ) {
5386 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
5389 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
5390 ixold - ixnew, cfb->cb_use_ldif );
5392 op->oq_modrdn = modr;
5395 ldap_pvt_thread_pool_resume( &connection_pool );
5397 send_ldap_result( op, rs );
5402 config_back_delete( Operation *op, SlapReply *rs )
5404 #ifdef SLAP_CONFIG_DELETE
5406 CfEntryInfo *ce, *last, *ce2;
5408 cfb = (CfBackInfo *)op->o_bd->be_private;
5410 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5413 rs->sr_matched = last->ce_entry->e_name.bv_val;
5414 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5415 } else if ( ce->ce_kids ) {
5416 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5417 } else if ( ce->ce_type == Cft_Overlay || ce->ce_type == Cft_Database ){
5421 ldap_pvt_thread_pool_pause( &connection_pool );
5423 if ( ce->ce_type == Cft_Overlay ){
5424 overlay_remove( ce->ce_be, (slap_overinst *)ce->ce_bi );
5425 } else { /* Cft_Database*/
5426 if ( ce->ce_be == frontendDB || ce->ce_be == op->o_bd ){
5427 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5428 rs->sr_text = "Cannot delete config or frontend database";
5429 ldap_pvt_thread_pool_resume( &connection_pool );
5432 if ( ce->ce_be->bd_info->bi_db_close ) {
5433 ce->ce_be->bd_info->bi_db_close( ce->ce_be, NULL );
5435 backend_destroy_one( ce->ce_be, 1);
5438 /* remove CfEntryInfo from the siblings list */
5439 if ( ce->ce_parent->ce_kids == ce ) {
5440 ce->ce_parent->ce_kids = ce->ce_sibs;
5442 for ( ce2 = ce->ce_parent->ce_kids ; ce2; ce2 = ce2->ce_sibs ) {
5443 if ( ce2->ce_sibs == ce ) {
5444 ce2->ce_sibs = ce->ce_sibs;
5450 /* remove from underlying database */
5451 if ( cfb->cb_use_ldif ) {
5452 BackendDB *be = op->o_bd;
5453 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5454 struct berval dn, ndn, req_dn, req_ndn;
5456 op->o_bd = &cfb->cb_db;
5460 req_dn = op->o_req_dn;
5461 req_ndn = op->o_req_ndn;
5463 op->o_dn = op->o_bd->be_rootdn;
5464 op->o_ndn = op->o_bd->be_rootndn;
5465 op->o_req_dn = ce->ce_entry->e_name;
5466 op->o_req_ndn = ce->ce_entry->e_nname;
5468 scp = op->o_callback;
5469 op->o_callback = ≻
5470 op->o_bd->be_delete( op, rs );
5472 op->o_callback = scp;
5475 op->o_req_dn = req_dn;
5476 op->o_req_ndn = req_ndn;
5479 /* renumber siblings */
5480 iptr = ber_bvchr( &op->o_req_ndn, '{' ) + 1;
5481 ixold = strtol( iptr, NULL, 0 );
5482 for (ce2 = ce->ce_sibs, count=0; ce2; ce2=ce2->ce_sibs) {
5483 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5484 count+ixold, 0, cfb->cb_use_ldif );
5488 ce->ce_entry->e_private=NULL;
5489 entry_free(ce->ce_entry);
5491 ldap_pvt_thread_pool_resume( &connection_pool );
5493 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5496 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5497 #endif /* SLAP_CONFIG_DELETE */
5499 send_ldap_result( op, rs );
5504 config_back_search( Operation *op, SlapReply *rs )
5507 CfEntryInfo *ce, *last;
5510 cfb = (CfBackInfo *)op->o_bd->be_private;
5512 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5515 rs->sr_matched = last->ce_entry->e_name.bv_val;
5516 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5519 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
5520 ACL_SEARCH, NULL, &mask ))
5522 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
5523 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5525 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5529 switch ( op->ors_scope ) {
5530 case LDAP_SCOPE_BASE:
5531 case LDAP_SCOPE_SUBTREE:
5532 rs->sr_err = config_send( op, rs, ce, 0 );
5535 case LDAP_SCOPE_ONELEVEL:
5536 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
5537 rs->sr_err = config_send( op, rs, ce, 1 );
5546 send_ldap_result( op, rs );
5550 /* no-op, we never free entries */
5551 int config_entry_release(
5556 if ( !e->e_private ) {
5559 return LDAP_SUCCESS;
5562 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
5564 int config_back_entry_get(
5568 AttributeDescription *at,
5573 CfEntryInfo *ce, *last;
5574 int rc = LDAP_NO_SUCH_OBJECT;
5576 cfb = (CfBackInfo *)op->o_bd->be_private;
5578 ce = config_find_base( cfb->cb_root, ndn, &last );
5580 *ent = ce->ce_entry;
5583 if ( oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
5584 rc = LDAP_NO_SUCH_ATTRIBUTE;
5594 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
5595 ConfigTable *ct, ConfigArgs *c )
5599 for (; at && *at; at++) {
5600 /* Skip the naming attr */
5601 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
5603 for (i=0;ct[i].name;i++) {
5604 if (ct[i].ad == (*at)->sat_ad) {
5605 rc = config_get_vals(&ct[i], c);
5606 /* NOTE: tolerate that config_get_vals()
5607 * returns success with no values */
5608 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
5609 if ( c->rvalue_nvals )
5610 rc = attr_merge(e, ct[i].ad, c->rvalue_vals,
5613 slap_syntax_validate_func *validate =
5614 ct[i].ad->ad_type->sat_syntax->ssyn_validate;
5617 for ( j=0; c->rvalue_vals[j].bv_val; j++ ) {
5618 rc = ordered_value_validate( ct[i].ad,
5619 &c->rvalue_vals[j], LDAP_MOD_ADD );
5621 Debug( LDAP_DEBUG_ANY,
5622 "config_build_attrs: error %d on %s value #%d\n",
5623 rc, ct[i].ad->ad_cname.bv_val, j );
5629 rc = attr_merge_normalize(e, ct[i].ad,
5630 c->rvalue_vals, NULL);
5632 ber_bvarray_free( c->rvalue_nvals );
5633 ber_bvarray_free( c->rvalue_vals );
5635 Debug( LDAP_DEBUG_ANY,
5636 "config_build_attrs: error %d on %s\n",
5637 rc, ct[i].ad->ad_cname.bv_val, 0 );
5649 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
5650 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
5652 Entry *e = entry_alloc();
5653 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5655 struct berval ad_name;
5656 AttributeDescription *ad = NULL;
5659 const char *text = "";
5663 CfEntryInfo *ceprev = NULL;
5665 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
5668 ce->ce_type = main->co_type;
5669 ce->ce_parent = parent;
5671 pdn = parent->ce_entry->e_nname;
5672 if ( parent->ce_kids && parent->ce_kids->ce_type <= ce->ce_type )
5673 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
5674 ceprev->ce_type <= ce->ce_type;
5675 ceprev = ceprev->ce_sibs );
5680 ce->ce_private = c->ca_private;
5684 build_new_dn( &e->e_name, &pdn, rdn, NULL );
5685 ber_dupbv( &e->e_nname, &e->e_name );
5687 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
5688 main->co_name, NULL );
5690 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
5691 extra->co_name, NULL );
5692 ptr = strchr(rdn->bv_val, '=');
5693 ad_name.bv_val = rdn->bv_val;
5694 ad_name.bv_len = ptr - rdn->bv_val;
5695 rc = slap_bv2ad( &ad_name, &ad, &text );
5700 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
5701 attr_merge_normalize_one(e, ad, &val, NULL );
5704 c->table = main->co_type;
5705 if ( oc->soc_required ) {
5706 rc = config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
5707 if ( rc ) goto fail;
5710 if ( oc->soc_allowed ) {
5711 rc = config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
5712 if ( rc ) goto fail;
5717 c->table = extra->co_type;
5718 if ( oc->soc_required ) {
5719 rc = config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
5720 if ( rc ) goto fail;
5723 if ( oc->soc_allowed ) {
5724 rc = config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
5725 if ( rc ) goto fail;
5729 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5730 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
5731 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
5732 if ( rc != LDAP_SUCCESS ) {
5734 Debug( LDAP_DEBUG_ANY,
5735 "config_build_entry: build \"%s\" failed: \"%s\"\n",
5736 rdn->bv_val, text, 0);
5739 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
5742 op->ora_modlist = NULL;
5743 slap_add_opattrs( op, NULL, NULL, 0, 0 );
5744 if ( !op->o_noop ) {
5745 op->o_bd->be_add( op, rs );
5746 if ( ( rs->sr_err != LDAP_SUCCESS )
5747 && (rs->sr_err != LDAP_ALREADY_EXISTS) ) {
5753 ce->ce_sibs = ceprev->ce_sibs;
5754 ceprev->ce_sibs = ce;
5755 } else if ( parent ) {
5756 ce->ce_sibs = parent->ce_kids;
5757 parent->ce_kids = ce;
5764 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
5765 Operation *op, SlapReply *rs )
5768 ConfigFile *cf = c->ca_private;
5770 struct berval bv, rdn;
5772 for (; cf; cf=cf->c_sibs, c->depth++) {
5773 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
5774 !cf->c_om_head && !cf->c_syn_head ) continue;
5775 c->value_dn.bv_val = c->log;
5776 LUTIL_SLASHPATH( cf->c_file.bv_val );
5777 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
5782 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
5784 ptr = strchr( bv.bv_val, '.' );
5786 bv.bv_len = ptr - bv.bv_val;
5787 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
5788 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
5789 /* FIXME: how can indicate error? */
5792 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
5794 c->value_dn.bv_len += bv.bv_len;
5795 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
5799 e = config_build_entry( op, rs, ceparent, c, &rdn,
5800 &CFOC_SCHEMA, NULL );
5803 } else if ( e && cf->c_kids ) {
5804 c->ca_private = cf->c_kids;
5805 config_build_schema_inc( c, e->e_private, op, rs );
5811 #ifdef SLAPD_MODULES
5814 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
5815 Operation *op, SlapReply *rs )
5820 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
5821 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
5823 c->value_dn.bv_val = c->log;
5824 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
5825 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
5826 /* FIXME: how can indicate error? */
5830 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
5839 config_check_schema(Operation *op, CfBackInfo *cfb)
5841 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
5843 CfEntryInfo *ce, *last;
5846 /* If there's no root entry, we must be in the midst of converting */
5847 if ( !cfb->cb_root )
5850 /* Make sure the main schema entry exists */
5851 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
5858 /* Make sure it's up to date */
5859 if ( cf_om_tail != om_sys_tail ) {
5860 a = attr_find( e->e_attrs, cfAd_om );
5862 if ( a->a_nvals != a->a_vals )
5863 ber_bvarray_free( a->a_nvals );
5864 ber_bvarray_free( a->a_vals );
5869 oidm_unparse( &bv, NULL, NULL, 1 );
5870 attr_merge_normalize( e, cfAd_om, bv, NULL );
5871 ber_bvarray_free( bv );
5872 cf_om_tail = om_sys_tail;
5874 if ( cf_at_tail != at_sys_tail ) {
5875 a = attr_find( e->e_attrs, cfAd_attr );
5877 if ( a->a_nvals != a->a_vals )
5878 ber_bvarray_free( a->a_nvals );
5879 ber_bvarray_free( a->a_vals );
5884 at_unparse( &bv, NULL, NULL, 1 );
5885 attr_merge_normalize( e, cfAd_attr, bv, NULL );
5886 ber_bvarray_free( bv );
5887 cf_at_tail = at_sys_tail;
5889 if ( cf_oc_tail != oc_sys_tail ) {
5890 a = attr_find( e->e_attrs, cfAd_oc );
5892 if ( a->a_nvals != a->a_vals )
5893 ber_bvarray_free( a->a_nvals );
5894 ber_bvarray_free( a->a_vals );
5899 oc_unparse( &bv, NULL, NULL, 1 );
5900 attr_merge_normalize( e, cfAd_oc, bv, NULL );
5901 ber_bvarray_free( bv );
5902 cf_oc_tail = oc_sys_tail;
5904 if ( cf_syn_tail != syn_sys_tail ) {
5905 a = attr_find( e->e_attrs, cfAd_syntax );
5907 if ( a->a_nvals != a->a_vals )
5908 ber_bvarray_free( a->a_nvals );
5909 ber_bvarray_free( a->a_vals );
5914 syn_unparse( &bv, NULL, NULL, 1 );
5915 attr_merge_normalize( e, cfAd_syntax, bv, NULL );
5916 ber_bvarray_free( bv );
5917 cf_syn_tail = syn_sys_tail;
5920 SlapReply rs = {REP_RESULT};
5921 c.ca_private = NULL;
5922 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
5923 &CFOC_SCHEMA, NULL );
5928 ce->ce_private = cfb->cb_config;
5929 cf_at_tail = at_sys_tail;
5930 cf_oc_tail = oc_sys_tail;
5931 cf_om_tail = om_sys_tail;
5932 cf_syn_tail = syn_sys_tail;
5937 static const char *defacl[] = {
5938 NULL, "to", "*", "by", "*", "none", NULL
5942 config_back_db_open( BackendDB *be, ConfigReply *cr )
5944 CfBackInfo *cfb = be->be_private;
5947 CfEntryInfo *ce, *ceparent;
5951 Connection conn = {0};
5952 OperationBuffer opbuf;
5954 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
5955 SlapReply rs = {REP_RESULT};
5956 void *thrctx = NULL;
5958 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
5960 /* If we have no explicitly configured ACLs, don't just use
5961 * the global ACLs. Explicitly deny access to everything.
5963 if ( !be->be_acl ) {
5964 parse_acl(be, "config_back_db_open", 0, 6, (char **)defacl, 0 );
5967 thrctx = ldap_pvt_thread_pool_context();
5968 connection_fake_init( &conn, &opbuf, thrctx );
5971 op->o_tag = LDAP_REQ_ADD;
5972 op->o_callback = &cb;
5973 op->o_bd = &cfb->cb_db;
5974 op->o_dn = op->o_bd->be_rootdn;
5975 op->o_ndn = op->o_bd->be_rootndn;
5977 if ( !cfb->cb_use_ldif ) {
5981 /* If we read the config from back-ldif, do some quick sanity checks */
5982 if ( cfb->cb_got_ldif ) {
5983 return config_check_schema( op, cfb );
5986 /* create root of tree */
5988 c.ca_private = cfb->cb_config;
5990 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
6000 #ifdef SLAPD_MODULES
6001 /* Create Module nodes... */
6002 if ( modpaths.mp_loads ) {
6003 if ( config_build_modules( &c, ceparent, op, &rs ) ){
6009 /* Create schema nodes... cn=schema will contain the hardcoded core
6010 * schema, read-only. Child objects will contain runtime loaded schema
6014 c.ca_private = NULL;
6015 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
6020 ce->ce_private = cfb->cb_config;
6021 cf_at_tail = at_sys_tail;
6022 cf_oc_tail = oc_sys_tail;
6023 cf_om_tail = om_sys_tail;
6024 cf_syn_tail = syn_sys_tail;
6026 /* Create schema nodes for included schema... */
6027 if ( cfb->cb_config->c_kids ) {
6029 c.ca_private = cfb->cb_config->c_kids;
6030 if (config_build_schema_inc( &c, ce, op, &rs )) {
6035 /* Create backend nodes. Skip if they don't provide a cf_table.
6036 * There usually aren't any of these.
6040 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
6041 if (!bi->bi_cf_ocs) {
6042 /* If it only supports the old config mech, complain. */
6043 if ( bi->bi_config ) {
6044 Debug( LDAP_DEBUG_ANY,
6045 "WARNING: No dynamic config support for backend %s.\n",
6046 bi->bi_type, 0, 0 );
6051 if (!bi->bi_private) continue;
6054 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6055 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
6056 if ( rdn.bv_len >= sizeof( c.log ) ) {
6057 /* FIXME: holler ... */ ;
6060 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
6067 /* Create database nodes... */
6068 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
6069 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
6070 for ( i = -1, be = frontendDB ; be;
6071 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
6072 slap_overinfo *oi = NULL;
6074 if ( overlay_is_over( be )) {
6075 oi = be->bd_info->bi_private;
6081 /* If this backend supports the old config mechanism, but not
6082 * the new mech, complain.
6084 if ( !be->be_cf_ocs && bi->bi_db_config ) {
6085 Debug( LDAP_DEBUG_ANY,
6086 "WARNING: No dynamic config support for database %s.\n",
6087 bi->bi_type, 0, 0 );
6091 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6092 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
6094 if ( rdn.bv_len >= sizeof( c.log ) ) {
6095 /* FIXME: holler ... */ ;
6099 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
6105 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd )
6106 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
6107 /* Iterate through overlays */
6112 voidList *vl, *v0 = NULL;
6114 /* overlays are in LIFO order, must reverse stack */
6115 for (on=oi->oi_list; on; on=on->on_next) {
6116 vl = ch_malloc( sizeof( voidList ));
6121 for (j=0; vl; j++,vl=v0) {
6125 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
6126 Debug( LDAP_DEBUG_ANY,
6127 "WARNING: No dynamic config support for overlay %s.\n",
6128 on->on_bi.bi_type, 0, 0 );
6132 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6133 "%s=" SLAP_X_ORDERED_FMT "%s",
6134 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
6135 if ( rdn.bv_len >= sizeof( c.log ) ) {
6136 /* FIXME: holler ... */ ;
6140 oe = config_build_entry( op, &rs, ce, &c, &rdn,
6141 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
6145 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd )
6146 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
6151 ldap_pvt_thread_pool_context_reset( thrctx );
6153 if ( unsupp && cfb->cb_use_ldif ) {
6154 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
6155 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
6162 cfb_free_cffile( ConfigFile *cf )
6166 for (; cf; cf=next) {
6169 cfb_free_cffile( cf->c_kids );
6170 ch_free( cf->c_file.bv_val );
6171 ber_bvarray_free( cf->c_dseFiles );
6177 cfb_free_entries( CfEntryInfo *ce )
6181 for (; ce; ce=next) {
6184 cfb_free_entries( ce->ce_kids );
6185 ce->ce_entry->e_private = NULL;
6186 entry_free( ce->ce_entry );
6192 config_back_db_close( BackendDB *be, ConfigReply *cr )
6194 CfBackInfo *cfb = be->be_private;
6196 cfb_free_entries( cfb->cb_root );
6197 cfb->cb_root = NULL;
6199 if ( cfb->cb_db.bd_info ) {
6200 backend_shutdown( &cfb->cb_db );
6207 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
6209 CfBackInfo *cfb = be->be_private;
6211 cfb_free_cffile( cfb->cb_config );
6213 ch_free( cfdir.bv_val );
6215 avl_free( CfOcTree, NULL );
6217 if ( cfb->cb_db.bd_info ) {
6218 cfb->cb_db.be_suffix = NULL;
6219 cfb->cb_db.be_nsuffix = NULL;
6220 BER_BVZERO( &cfb->cb_db.be_rootdn );
6221 BER_BVZERO( &cfb->cb_db.be_rootndn );
6223 backend_destroy_one( &cfb->cb_db, 0 );
6232 config_back_db_init( BackendDB *be, ConfigReply* cr )
6238 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
6239 cfn = cfb->cb_config;
6240 be->be_private = cfb;
6242 ber_dupbv( &be->be_rootdn, &config_rdn );
6243 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
6244 ber_dupbv( &dn, &be->be_rootdn );
6245 ber_bvarray_add( &be->be_suffix, &dn );
6246 ber_dupbv( &dn, &be->be_rootdn );
6247 ber_bvarray_add( &be->be_nsuffix, &dn );
6249 /* Hide from namingContexts */
6250 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
6252 /* Check ACLs on content of Adds by default */
6253 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_ACL_ADD;
6259 config_back_destroy( BackendInfo *bi )
6261 ldif_must_b64_encode_release();
6266 config_tool_entry_open( BackendDB *be, int mode )
6268 CfBackInfo *cfb = be->be_private;
6269 BackendInfo *bi = cfb->cb_db.bd_info;
6271 if ( bi && bi->bi_tool_entry_open )
6272 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
6279 config_tool_entry_close( BackendDB *be )
6281 CfBackInfo *cfb = be->be_private;
6282 BackendInfo *bi = cfb->cb_db.bd_info;
6284 if ( bi && bi->bi_tool_entry_close )
6285 return bi->bi_tool_entry_close( &cfb->cb_db );
6291 config_tool_entry_first( BackendDB *be )
6293 CfBackInfo *cfb = be->be_private;
6294 BackendInfo *bi = cfb->cb_db.bd_info;
6296 if ( bi && bi->bi_tool_entry_first )
6297 return bi->bi_tool_entry_first( &cfb->cb_db );
6303 config_tool_entry_next( BackendDB *be )
6305 CfBackInfo *cfb = be->be_private;
6306 BackendInfo *bi = cfb->cb_db.bd_info;
6308 if ( bi && bi->bi_tool_entry_next )
6309 return bi->bi_tool_entry_next( &cfb->cb_db );
6315 config_tool_entry_get( BackendDB *be, ID id )
6317 CfBackInfo *cfb = be->be_private;
6318 BackendInfo *bi = cfb->cb_db.bd_info;
6320 if ( bi && bi->bi_tool_entry_get )
6321 return bi->bi_tool_entry_get( &cfb->cb_db, id );
6326 static int entry_put_got_frontend=0;
6327 static int entry_put_got_config=0;
6329 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
6331 CfBackInfo *cfb = be->be_private;
6332 BackendInfo *bi = cfb->cb_db.bd_info;
6334 struct berval rdn, vals[ 2 ];
6336 OperationBuffer opbuf;
6338 Connection conn = {0};
6339 Operation *op = NULL;
6343 /* Create entry for frontend database if it does not exist already */
6344 if ( !entry_put_got_frontend ) {
6345 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
6346 STRLENOF( "olcDatabase" ))) {
6347 if ( strncmp( e->e_nname.bv_val +
6348 STRLENOF( "olcDatabase" ), "={-1}frontend",
6349 STRLENOF( "={-1}frontend" )) &&
6350 strncmp( e->e_nname.bv_val +
6351 STRLENOF( "olcDatabase" ), "=frontend",
6352 STRLENOF( "=frontend" ))) {
6354 vals[1].bv_val = NULL;
6355 memset( &ca, 0, sizeof(ConfigArgs));
6357 ca.bi = frontendDB->bd_info;
6358 ca.be->be_cf_ocs = &CFOC_FRONTEND;
6359 rdn.bv_val = ca.log;
6360 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
6361 "%s=" SLAP_X_ORDERED_FMT "%s",
6362 cfAd_database->ad_cname.bv_val, -1,
6364 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
6365 &CFOC_DATABASE, ca.be->be_cf_ocs );
6366 thrctx = ldap_pvt_thread_pool_context();
6367 connection_fake_init2( &conn, &opbuf, thrctx,0 );
6369 op->o_bd = &cfb->cb_db;
6370 op->o_tag = LDAP_REQ_ADD;
6372 op->o_dn = be->be_rootdn;
6373 op->o_ndn = be->be_rootndn;
6374 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
6375 if ( rc != LDAP_SUCCESS ) {
6376 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
6377 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
6381 if ( ce && bi && bi->bi_tool_entry_put &&
6382 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
6383 entry_put_got_frontend++;
6385 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
6386 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
6390 entry_put_got_frontend++;
6395 /* Create entry for config database if it does not exist already */
6396 if ( !entry_put_got_config && !isFrontend ) {
6397 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
6398 STRLENOF( "olcDatabase" ))) {
6399 if ( strncmp( e->e_nname.bv_val +
6400 STRLENOF( "olcDatabase" ), "={0}config",
6401 STRLENOF( "={0}config" )) &&
6402 strncmp( e->e_nname.bv_val +
6403 STRLENOF( "olcDatabase" ), "=config",
6404 STRLENOF( "=config" )) ) {
6406 vals[1].bv_val = NULL;
6407 memset( &ca, 0, sizeof(ConfigArgs));
6408 ca.be = LDAP_STAILQ_FIRST( &backendDB );
6409 ca.bi = ca.be->bd_info;
6410 rdn.bv_val = ca.log;
6411 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
6412 "%s=" SLAP_X_ORDERED_FMT "%s",
6413 cfAd_database->ad_cname.bv_val, 0,
6415 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
6418 thrctx = ldap_pvt_thread_pool_context();
6419 connection_fake_init2( &conn, &opbuf, thrctx,0 );
6421 op->o_bd = &cfb->cb_db;
6422 op->o_tag = LDAP_REQ_ADD;
6423 op->o_dn = be->be_rootdn;
6424 op->o_ndn = be->be_rootndn;
6427 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
6428 if ( rc != LDAP_SUCCESS ) {
6429 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
6430 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
6433 if (ce && bi && bi->bi_tool_entry_put &&
6434 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
6435 entry_put_got_config++;
6437 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
6438 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
6442 entry_put_got_config++;
6446 if ( bi && bi->bi_tool_entry_put &&
6447 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
6448 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
6455 AttributeDescription **desc;
6457 { "attribute", &cfAd_attr },
6458 { "backend", &cfAd_backend },
6459 { "database", &cfAd_database },
6460 { "include", &cfAd_include },
6461 { "ldapsyntax", &cfAd_syntax },
6462 { "objectclass", &cfAd_oc },
6463 { "objectidentifier", &cfAd_om },
6464 { "overlay", &cfAd_overlay },
6469 * add / delete: all types that may be added or deleted must use an
6470 * X-ORDERED attributeType for their RDN. Adding and deleting entries
6471 * should automatically renumber the index of any siblings as needed,
6472 * so that no gaps in the numbering sequence exist after the add/delete
6474 * What can be added:
6476 * backend objects for backend-specific config directives
6480 * delete: probably no support this time around.
6482 * modrdn: generally not done. Will be invoked automatically by add/
6483 * delete to update numbering sequence. Perform as an explicit operation
6484 * so that the renumbering effect may be replicated. Subtree rename must
6485 * be supported, since renumbering a database will affect all its child
6488 * modify: must be fully supported.
6492 config_back_initialize( BackendInfo *bi )
6494 ConfigTable *ct = config_back_cf_table;
6498 AttributeDescription *ad = NULL;
6500 static char *controls[] = {
6501 LDAP_CONTROL_MANAGEDSAIT,
6505 /* Make sure we don't exceed the bits reserved for userland */
6506 config_check_userland( CFG_LAST );
6508 bi->bi_controls = controls;
6513 bi->bi_destroy = config_back_destroy;
6515 bi->bi_db_init = config_back_db_init;
6516 bi->bi_db_config = 0;
6517 bi->bi_db_open = config_back_db_open;
6518 bi->bi_db_close = config_back_db_close;
6519 bi->bi_db_destroy = config_back_db_destroy;
6521 bi->bi_op_bind = config_back_bind;
6522 bi->bi_op_unbind = 0;
6523 bi->bi_op_search = config_back_search;
6524 bi->bi_op_compare = 0;
6525 bi->bi_op_modify = config_back_modify;
6526 bi->bi_op_modrdn = config_back_modrdn;
6527 bi->bi_op_add = config_back_add;
6528 bi->bi_op_delete = config_back_delete;
6529 bi->bi_op_abandon = 0;
6531 bi->bi_extended = 0;
6533 bi->bi_chk_referrals = 0;
6535 bi->bi_access_allowed = slap_access_allowed;
6537 bi->bi_connection_init = 0;
6538 bi->bi_connection_destroy = 0;
6540 bi->bi_entry_release_rw = config_entry_release;
6541 bi->bi_entry_get_rw = config_back_entry_get;
6543 bi->bi_tool_entry_open = config_tool_entry_open;
6544 bi->bi_tool_entry_close = config_tool_entry_close;
6545 bi->bi_tool_entry_first = config_tool_entry_first;
6546 bi->bi_tool_entry_next = config_tool_entry_next;
6547 bi->bi_tool_entry_get = config_tool_entry_get;
6548 bi->bi_tool_entry_put = config_tool_entry_put;
6551 argv[ 0 ] = "slapd";
6557 for (i=0; OidMacros[i].name; i++ ) {
6558 argv[1] = OidMacros[i].name;
6559 argv[2] = OidMacros[i].oid;
6560 parse_oidm( &ca, 0, NULL );
6563 bi->bi_cf_ocs = cf_ocs;
6565 i = config_register_schema( ct, cf_ocs );
6568 i = slap_str2ad( "olcDatabase", &olcDatabaseDummy[0].ad, &text );
6571 /* setup olcRootPW to be base64-encoded when written in LDIF form;
6572 * basically, we don't care if it fails */
6573 i = slap_str2ad( "olcRootPW", &ad, &text );
6575 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
6576 "warning, unable to get \"olcRootPW\" "
6577 "attribute description: %d: %s\n",
6580 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
6581 ad->ad_type->sat_oid );
6584 /* set up the notable AttributeDescriptions */
6586 for (;ct->name;ct++) {
6587 if (strcmp(ct->name, ads[i].name)) continue;
6588 *ads[i].desc = ct->ad;
6590 if (!ads[i].name) break;