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", NULL, 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 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
710 NULL, NULL, NULL, NULL }
713 /* Need to no-op this keyword for dynamic config */
714 ConfigTable olcDatabaseDummy[] = {
715 { "", "", 0, 0, 0, ARG_IGNORED,
716 NULL, "( OLcfgGlAt:13 NAME 'olcDatabase' "
717 "DESC 'The backend type for a database instance' "
718 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
719 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
722 /* Routines to check if a child can be added to this type */
723 static ConfigLDAPadd cfAddSchema, cfAddInclude, cfAddDatabase,
724 cfAddBackend, cfAddModule, cfAddOverlay;
726 /* NOTE: be careful when defining array members
727 * that can be conditionally compiled */
728 #define CFOC_GLOBAL cf_ocs[1]
729 #define CFOC_SCHEMA cf_ocs[2]
730 #define CFOC_BACKEND cf_ocs[3]
731 #define CFOC_DATABASE cf_ocs[4]
732 #define CFOC_OVERLAY cf_ocs[5]
733 #define CFOC_INCLUDE cf_ocs[6]
734 #define CFOC_FRONTEND cf_ocs[7]
736 #define CFOC_MODULE cf_ocs[8]
737 #endif /* SLAPD_MODULES */
739 static ConfigOCs cf_ocs[] = {
742 "DESC 'OpenLDAP configuration object' "
743 "ABSTRACT SUP top )", Cft_Abstract, NULL },
746 "DESC 'OpenLDAP Global configuration options' "
747 "SUP olcConfig STRUCTURAL "
748 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
749 "olcAttributeOptions $ olcAuthIDRewrite $ "
750 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
751 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
752 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
753 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
754 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcIndexIntLen $ "
755 "olcLocalSSF $ olcLogFile $ olcLogLevel $ "
756 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
757 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
758 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
760 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
761 "olcSecurity $ olcServerID $ olcSizeLimit $ "
762 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ "
763 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
764 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
765 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
766 "olcTLSRandFile $ olcTLSVerifyClient $ olcTLSDHParamFile $ "
767 "olcTLSCRLFile $ olcToolThreads $ "
768 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
769 "olcDitContentRules $ olcLdapSyntaxes ) )", Cft_Global },
771 "NAME 'olcSchemaConfig' "
772 "DESC 'OpenLDAP schema object' "
773 "SUP olcConfig STRUCTURAL "
774 "MAY ( cn $ olcObjectIdentifier $ olcAttributeTypes $ "
775 "olcObjectClasses $ olcDitContentRules $ olcLdapSyntaxes ) )",
776 Cft_Schema, NULL, cfAddSchema },
778 "NAME 'olcBackendConfig' "
779 "DESC 'OpenLDAP Backend-specific options' "
780 "SUP olcConfig STRUCTURAL "
781 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
783 "NAME 'olcDatabaseConfig' "
784 "DESC 'OpenLDAP Database-specific options' "
785 "SUP olcConfig STRUCTURAL "
787 "MAY ( olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
788 "olcAddContentAcl $ olcLastMod $ olcLimits $ "
789 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
790 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
791 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
792 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncrepl $ "
793 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef $ olcMirrorMode $ "
795 Cft_Database, NULL, cfAddDatabase },
797 "NAME 'olcOverlayConfig' "
798 "DESC 'OpenLDAP Overlay-specific options' "
799 "SUP olcConfig STRUCTURAL "
800 "MUST olcOverlay )", Cft_Overlay, NULL, cfAddOverlay },
802 "NAME 'olcIncludeFile' "
803 "DESC 'OpenLDAP configuration include file' "
804 "SUP olcConfig STRUCTURAL "
806 "MAY ( cn $ olcRootDSE ) )",
807 /* Used to be Cft_Include, that def has been removed */
808 Cft_Abstract, NULL, cfAddInclude },
809 /* This should be STRUCTURAL like all the other database classes, but
810 * that would mean inheriting all of the olcDatabaseConfig attributes,
811 * which causes them to be merged twice in config_build_entry.
814 "NAME 'olcFrontendConfig' "
815 "DESC 'OpenLDAP frontend configuration' "
817 "MAY ( olcDefaultSearchBase $ olcPasswordHash $ olcSortVals ) )",
818 Cft_Database, NULL, NULL },
821 "NAME 'olcModuleList' "
822 "DESC 'OpenLDAP dynamic module info' "
823 "SUP olcConfig STRUCTURAL "
824 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
825 Cft_Module, NULL, cfAddModule },
830 typedef struct ServerID {
831 struct ServerID *si_next;
832 struct berval si_url;
836 static ServerID *sid_list;
838 typedef struct voidList {
839 struct voidList *vl_next;
843 typedef struct ADlist {
844 struct ADlist *al_next;
845 AttributeDescription *al_desc;
848 static ADlist *sortVals;
851 config_generic(ConfigArgs *c) {
854 if ( c->op == SLAP_CONFIG_EMIT ) {
858 c->value_int = ldap_pvt_thread_get_concurrency();
861 c->value_int = connection_pool_max;
864 c->value_int = slap_tool_thread_max;
868 c->value_string = ch_strdup( passwd_salt );
873 if ( c->be->be_limits ) {
877 for ( i=0; c->be->be_limits[i]; i++ ) {
878 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
879 if ( bv.bv_len >= sizeof( buf ) ) {
880 ber_bvarray_free_x( c->rvalue_vals, NULL );
881 c->rvalue_vals = NULL;
885 bv.bv_val = buf + bv.bv_len;
886 limits_unparse( c->be->be_limits[i], &bv,
887 sizeof( buf ) - ( bv.bv_val - buf ) );
888 bv.bv_len += bv.bv_val - buf;
890 value_add_one( &c->rvalue_vals, &bv );
893 if ( !c->rvalue_vals ) rc = 1;
896 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_OP_WRITES) ==
897 SLAP_RESTRICT_OP_WRITES;
900 c->value_string = ch_strdup( slap_sasl_getpolicy());
903 slap_sasl_regexp_unparse( &c->rvalue_vals );
904 if ( !c->rvalue_vals ) rc = 1;
906 #ifdef HAVE_CYRUS_SASL
908 struct berval bv = BER_BVNULL;
909 slap_sasl_secprops_unparse( &bv );
910 if ( !BER_BVISNULL( &bv )) {
911 ber_bvarray_add( &c->rvalue_vals, &bv );
919 c->value_int = c->be->be_max_deref_depth;
922 if ( SLAP_DBHIDDEN( c->be )) {
929 ConfigFile *cf = c->ca_private;
931 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
932 else if ( cf->c_om_head )
933 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
935 if ( !c->rvalue_vals )
940 ad_unparse_options( &c->rvalue_vals );
943 ConfigFile *cf = c->ca_private;
945 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
946 else if ( cf->c_oc_head )
947 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
949 if ( !c->rvalue_vals )
954 ConfigFile *cf = c->ca_private;
956 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
957 else if ( cf->c_at_head )
958 at_unparse( &c->rvalue_vals, cf->c_at_head,
960 if ( !c->rvalue_vals )
965 ConfigFile *cf = c->ca_private;
967 syn_unparse( &c->rvalue_vals, NULL, NULL, 1 );
968 else if ( cf->c_syn_head )
969 syn_unparse( &c->rvalue_vals, cf->c_syn_head,
971 if ( !c->rvalue_vals )
976 ConfigFile *cf = c->ca_private;
978 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
979 else if ( cf->c_cr_head )
980 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
982 if ( !c->rvalue_vals )
989 char *src, *dst, ibuf[11];
990 struct berval bv, abv;
991 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
992 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
993 if ( abv.bv_len >= sizeof( ibuf ) ) {
994 ber_bvarray_free_x( c->rvalue_vals, NULL );
995 c->rvalue_vals = NULL;
999 acl_unparse( a, &bv );
1000 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
1001 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
1002 /* Turn TAB / EOL into plain space */
1003 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
1004 if (isspace((unsigned char)*src)) *dst++ = ' ';
1008 if (dst[-1] == ' ') {
1012 abv.bv_len = dst - abv.bv_val;
1013 ber_bvarray_add( &c->rvalue_vals, &abv );
1019 c->value_int = (SLAP_DBACL_ADD(c->be) != 0);
1022 ConfigFile *cf = c->ca_private;
1023 if ( cf->c_dseFiles ) {
1024 value_add( &c->rvalue_vals, cf->c_dseFiles );
1035 for ( si = sid_list; si; si=si->si_next ) {
1036 assert( si->si_num >= 0 && si->si_num <= SLAP_SYNC_SID_MAX );
1037 if ( !BER_BVISEMPTY( &si->si_url )) {
1038 bv.bv_len = si->si_url.bv_len + 6;
1039 bv.bv_val = ch_malloc( bv.bv_len );
1040 bv.bv_len = sprintf( bv.bv_val, "%d %s", si->si_num,
1041 si->si_url.bv_val );
1042 ber_bvarray_add( &c->rvalue_vals, &bv );
1046 bv.bv_len = sprintf( buf, "%d", si->si_num );
1047 value_add_one( &c->rvalue_vals, &bv );
1056 c->value_string = ch_strdup( logfileName );
1061 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1063 case CFG_MIRRORMODE:
1064 if ( SLAP_SHADOW(c->be))
1065 c->value_int = (SLAP_SINGLE_SHADOW(c->be) == 0);
1069 case CFG_MONITORING:
1070 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
1072 case CFG_SSTR_IF_MAX:
1073 c->value_int = index_substr_if_maxlen;
1075 case CFG_SSTR_IF_MIN:
1076 c->value_int = index_substr_if_minlen;
1079 c->value_int = index_intlen;
1081 case CFG_SORTVALS: {
1084 for ( sv = sortVals; sv; sv = sv->al_next ) {
1085 value_add_one( &c->rvalue_vals, &sv->al_desc->ad_cname );
1089 #ifdef SLAPD_MODULES
1091 ModPaths *mp = c->ca_private;
1094 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
1097 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
1098 SLAP_X_ORDERED_FMT "%s", i,
1099 mp->mp_loads[i].bv_val );
1100 if ( bv.bv_len >= sizeof( c->log ) ) {
1101 ber_bvarray_free_x( c->rvalue_vals, NULL );
1102 c->rvalue_vals = NULL;
1105 value_add_one( &c->rvalue_vals, &bv );
1109 rc = c->rvalue_vals ? 0 : 1;
1113 ModPaths *mp = c->ca_private;
1114 if ( !BER_BVISNULL( &mp->mp_path ))
1115 value_add_one( &c->rvalue_vals, &mp->mp_path );
1117 rc = c->rvalue_vals ? 0 : 1;
1123 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1124 if ( !c->rvalue_vals ) rc = 1;
1127 #ifdef SLAP_AUTH_REWRITE
1129 if ( authz_rewrites ) {
1130 struct berval bv, idx;
1135 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1136 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1137 if ( idx.bv_len >= sizeof( ibuf ) ) {
1138 ber_bvarray_free_x( c->rvalue_vals, NULL );
1139 c->rvalue_vals = NULL;
1142 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1143 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1144 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1145 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1146 authz_rewrites[i].bv_val,
1147 authz_rewrites[i].bv_len + 1 );
1148 ber_bvarray_add( &c->rvalue_vals, &bv );
1151 if ( !c->rvalue_vals ) rc = 1;
1158 } else if ( c->op == LDAP_MOD_DELETE ) {
1161 /* single-valued attrs, no-ops */
1169 case CFG_MIRRORMODE:
1170 case CFG_MONITORING:
1172 case CFG_SSTR_IF_MAX:
1173 case CFG_SSTR_IF_MIN:
1177 /* no-ops, requires slapd restart */
1182 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1186 ch_free( passwd_salt );
1191 ch_free( logfileName );
1199 case CFG_SERVERID: {
1200 ServerID *si, **sip;
1202 for ( i=0, si = sid_list, sip = &sid_list;
1203 si; si = *sip, i++ ) {
1204 if ( c->valx == -1 || i == c->valx ) {
1216 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1220 index_intlen = SLAP_INDEX_INTLEN_DEFAULT;
1221 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1222 SLAP_INDEX_INTLEN_DEFAULT );
1226 if ( c->valx < 0 ) {
1227 acl_destroy( c->be->be_acl );
1228 c->be->be_acl = NULL;
1231 AccessControl **prev, *a;
1233 for (i=0, prev = &c->be->be_acl; i < c->valx;
1236 prev = &a->acl_next;
1239 *prev = a->acl_next;
1246 /* Can be NULL when undoing a failed add */
1247 if ( c->ca_entry ) {
1248 ce = c->ca_entry->e_private;
1249 /* can't modify the hardcoded schema */
1250 if ( ce->ce_parent->ce_type == Cft_Global )
1254 cfn = c->ca_private;
1255 if ( c->valx < 0 ) {
1258 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1260 if ( oc == cfn->c_oc_tail )
1263 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1265 ObjectClass *oc, *prev = NULL;
1267 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1272 if ( cfn->c_oc_tail == oc ) {
1273 cfn->c_oc_tail = prev;
1275 if ( cfn->c_oc_head == oc ) {
1277 cfn->c_oc_head = oc;
1284 /* Can be NULL when undoing a failed add */
1285 if ( c->ca_entry ) {
1286 ce = c->ca_entry->e_private;
1287 /* can't modify the hardcoded schema */
1288 if ( ce->ce_parent->ce_type == Cft_Global )
1292 cfn = c->ca_private;
1293 if ( c->valx < 0 ) {
1296 for( at = cfn->c_at_head; at; at_next( &at )) {
1298 if ( at == cfn->c_at_tail )
1301 cfn->c_at_head = cfn->c_at_tail = NULL;
1303 AttributeType *at, *prev = NULL;
1305 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1310 if ( cfn->c_at_tail == at ) {
1311 cfn->c_at_tail = prev;
1313 if ( cfn->c_at_head == at ) {
1315 cfn->c_at_head = at;
1322 /* Can be NULL when undoing a failed add */
1323 if ( c->ca_entry ) {
1324 ce = c->ca_entry->e_private;
1325 /* can't modify the hardcoded schema */
1326 if ( ce->ce_parent->ce_type == Cft_Global )
1330 cfn = c->ca_private;
1331 if ( c->valx < 0 ) {
1334 for( syn = cfn->c_syn_head; syn; syn_next( &syn )) {
1336 if ( syn == cfn->c_syn_tail )
1339 cfn->c_syn_head = cfn->c_syn_tail = NULL;
1341 Syntax *syn, *prev = NULL;
1343 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++) {
1348 if ( cfn->c_syn_tail == syn ) {
1349 cfn->c_syn_tail = prev;
1351 if ( cfn->c_syn_head == syn ) {
1353 cfn->c_syn_head = syn;
1358 if ( c->valx < 0 ) {
1360 for ( sv = sortVals; sv; sv = sortVals ) {
1361 sortVals = sv->al_next;
1362 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1369 for ( prev = &sortVals, sv = sortVals; i < c->valx; i++ ) {
1370 prev = &sv->al_next;
1373 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1374 *prev = sv->al_next;
1380 /* FIXME: there is no limits_free function */
1382 /* FIXME: there is no ad_option_free function */
1384 /* FIXME: there is no way to remove attributes added by
1398 if(!(c->bi = backend_info(c->argv[1]))) {
1399 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1400 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1401 c->log, c->cr_msg, c->argv[1] );
1408 /* NOTE: config is always the first backend!
1410 if ( !strcasecmp( c->argv[1], "config" )) {
1411 c->be = LDAP_STAILQ_FIRST(&backendDB);
1412 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1415 c->be = backend_db_init(c->argv[1], NULL, c->valx, &c->reply);
1417 if ( c->cr_msg[0] == 0 )
1418 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1419 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n", c->log, c->cr_msg, c->argv[1] );
1426 ldap_pvt_thread_set_concurrency(c->value_int);
1430 if ( c->value_int < 2 ) {
1431 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1432 "threads=%d smaller than minimum value 2",
1434 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1435 c->log, c->cr_msg, 0 );
1438 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1439 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1440 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1441 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1442 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1443 c->log, c->cr_msg, 0 );
1445 if ( slapMode & SLAP_SERVER_MODE )
1446 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1447 connection_pool_max = c->value_int; /* save for reference */
1451 if ( slapMode & SLAP_TOOL_MODE )
1452 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1453 slap_tool_thread_max = c->value_int; /* save for reference */
1457 if ( passwd_salt ) ch_free( passwd_salt );
1458 passwd_salt = c->value_string;
1459 lutil_salt_format(passwd_salt);
1463 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1469 c->be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1471 c->be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1475 ch_free(c->value_string);
1476 if (slap_sasl_setpolicy( c->argv[1] )) {
1477 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
1478 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1479 c->log, c->cr_msg, c->argv[1] );
1485 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1489 #ifdef HAVE_CYRUS_SASL
1492 char *txt = slap_sasl_secprops( c->argv[1] );
1494 snprintf( c->cr_msg, sizeof(c->cr_msg), "<%s> %s",
1496 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0 );
1504 c->be->be_max_deref_depth = c->value_int;
1510 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1511 cfn = c->ca_private;
1512 if(parse_oidm(c, 1, &om))
1514 if (!cfn->c_om_head) cfn->c_om_head = om;
1515 cfn->c_om_tail = om;
1520 ObjectClass *oc, *prev;
1522 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1523 cfn = c->ca_private;
1524 if ( c->valx < 0 ) {
1525 prev = cfn->c_oc_tail;
1528 /* If adding anything after the first, prev is easy */
1531 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
1536 /* If adding the first, and head exists, find its prev */
1537 if (cfn->c_oc_head) {
1538 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
1543 /* else prev is NULL, append to end of global list */
1545 if(parse_oc(c, &oc, prev)) return(1);
1546 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1547 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
1552 AttributeType *at, *prev;
1554 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1555 cfn = c->ca_private;
1556 if ( c->valx < 0 ) {
1557 prev = cfn->c_at_tail;
1560 /* If adding anything after the first, prev is easy */
1563 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
1568 /* If adding the first, and head exists, find its prev */
1569 if (cfn->c_at_head) {
1570 for ( at_start( &at ); at != cfn->c_at_head; ) {
1575 /* else prev is NULL, append to end of global list */
1577 if(parse_at(c, &at, prev)) return(1);
1578 if (!cfn->c_at_head) cfn->c_at_head = at;
1579 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
1586 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1587 cfn = c->ca_private;
1588 if ( c->valx < 0 ) {
1589 prev = cfn->c_syn_tail;
1592 /* If adding anything after the first, prev is easy */
1595 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++ ) {
1600 /* If adding the first, and head exists, find its prev */
1601 if (cfn->c_syn_head) {
1602 for ( syn_start( &syn ); syn != cfn->c_syn_head; ) {
1607 /* else prev is NULL, append to end of global list */
1609 if ( parse_syn( c, &syn, prev ) ) return(1);
1610 if ( !cfn->c_syn_head ) cfn->c_syn_head = syn;
1611 if ( cfn->c_syn_tail == prev ) cfn->c_syn_tail = syn;
1618 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1619 cfn = c->ca_private;
1620 if(parse_cr(c, &cr)) return(1);
1621 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1622 cfn->c_cr_tail = cr;
1627 ad_define_option(NULL, NULL, 0);
1628 for(i = 1; i < c->argc; i++)
1629 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1634 if ( c->value_int < SLAP_INDEX_INTLEN_DEFAULT )
1635 c->value_int = SLAP_INDEX_INTLEN_DEFAULT;
1636 else if ( c->value_int > 255 )
1638 index_intlen = c->value_int;
1639 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1643 case CFG_SORTVALS: {
1644 ADlist *svnew = NULL, *svtail, *sv;
1646 for ( i = 1; i < c->argc; i++ ) {
1647 AttributeDescription *ad = NULL;
1651 rc = slap_str2ad( c->argv[i], &ad, &text );
1653 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown attribute type #%d",
1656 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1657 c->log, c->cr_msg, c->argv[i] );
1658 for ( sv = svnew; sv; sv = svnew ) {
1659 svnew = sv->al_next;
1664 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) ||
1665 ad->ad_type->sat_single_value ) {
1666 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> inappropriate attribute type #%d",
1668 goto sortval_reject;
1670 sv = ch_malloc( sizeof( ADlist ));
1675 svtail->al_next = sv;
1680 for ( sv = svnew; sv; sv = sv->al_next )
1681 sv->al_desc->ad_type->sat_flags |= SLAP_AT_SORTED_VAL;
1682 for ( sv = sortVals; sv && sv->al_next; sv = sv->al_next );
1684 sv->al_next = svnew;
1691 /* Don't append to the global ACL if we're on a specific DB */
1693 if ( c->valx == -1 ) {
1696 for ( a=c->be->be_acl; a; a = a->acl_next )
1699 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
1706 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_ACL_ADD;
1708 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_ACL_ADD;
1712 if(root_dse_read_file(c->argv[1])) {
1713 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> could not read file", c->argv[0] );
1714 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1715 c->log, c->cr_msg, c->argv[1] );
1720 ber_str2bv( c->argv[1], 0, 1, &bv );
1721 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1722 cfn = c->ca_private;
1723 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1729 ServerID *si, **sip;
1732 if ( lutil_atoi( &num, c->argv[1] ) ||
1733 num < 0 || num > SLAP_SYNC_SID_MAX )
1735 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1736 "<%s> illegal server ID", c->argv[0] );
1737 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1738 c->log, c->cr_msg, c->argv[1] );
1741 /* only one value allowed if no URL is given */
1742 if ( c->argc > 2 ) {
1745 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
1746 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1747 "<%s> only one server ID allowed now", c->argv[0] );
1748 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1749 c->log, c->cr_msg, c->argv[1] );
1753 if ( ldap_url_parse( c->argv[2], &lud )) {
1754 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1755 "<%s> invalid URL", c->argv[0] );
1756 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1757 c->log, c->cr_msg, c->argv[2] );
1760 len = strlen( c->argv[2] );
1761 si = ch_malloc( sizeof(ServerID) + len + 1 );
1762 si->si_url.bv_val = (char *)(si+1);
1763 si->si_url.bv_len = len;
1764 strcpy( si->si_url.bv_val, c->argv[2] );
1767 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1768 "<%s> unqualified server ID not allowed now", c->argv[0] );
1769 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1770 c->log, c->cr_msg, c->argv[1] );
1773 si = ch_malloc( sizeof(ServerID) );
1774 BER_BVZERO( &si->si_url );
1775 slap_serverID = num;
1776 Debug( LDAP_DEBUG_CONFIG,
1778 c->log, slap_serverID, 0 );
1782 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
1785 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
1786 /* If hostname is empty, or is localhost, or matches
1787 * our hostname, this serverID refers to this host.
1788 * Compare it against listeners and ports.
1790 if ( !lud->lud_host || !lud->lud_host[0] ||
1791 !strncasecmp("localhost", lud->lud_host,
1792 STRLENOF("localhost")) ||
1793 !strcasecmp( global_host, lud->lud_host )) {
1794 Listener **l = slapd_get_listeners();
1797 for ( i=0; l && l[i]; i++ ) {
1800 ldap_url_parse( l[i]->sl_url.bv_val, &lu2 );
1802 if ( strcasecmp( lud->lud_scheme,
1805 if ( lud->lud_port != lu2->lud_port )
1807 /* Listener on ANY address */
1808 if ( !lu2->lud_host || !lu2->lud_host[0] ) {
1812 /* URL on ANY address */
1813 if ( !lud->lud_host || !lud->lud_host[0] ) {
1817 /* Listener has specific host, must
1820 if ( !strcasecmp( lud->lud_host,
1826 ldap_free_urldesc( lu2 );
1828 slap_serverID = si->si_num;
1829 Debug( LDAP_DEBUG_CONFIG,
1830 "%s: SID=%d (listener=%s)\n",
1831 c->log, slap_serverID,
1832 l[i]->sl_url.bv_val );
1839 ldap_free_urldesc( lud );
1843 if ( logfileName ) ch_free( logfileName );
1844 logfileName = c->value_string;
1845 logfile = fopen(logfileName, "w");
1846 if(logfile) lutil_debug_file(logfile);
1850 if(SLAP_NOLASTMODCMD(c->be)) {
1851 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> not available for %s database",
1852 c->argv[0], c->be->bd_info->bi_type );
1853 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1854 c->log, c->cr_msg, 0 );
1858 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1860 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1863 case CFG_MIRRORMODE:
1864 if(!SLAP_SHADOW(c->be)) {
1865 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database is not a shadow",
1867 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1868 c->log, c->cr_msg, 0 );
1872 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
1874 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1877 case CFG_MONITORING:
1879 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
1881 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
1886 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
1888 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
1891 case CFG_SSTR_IF_MAX:
1892 if (c->value_int < index_substr_if_minlen) {
1893 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1894 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1895 c->log, c->cr_msg, c->value_int );
1898 index_substr_if_maxlen = c->value_int;
1901 case CFG_SSTR_IF_MIN:
1902 if (c->value_int > index_substr_if_maxlen) {
1903 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1904 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1905 c->log, c->cr_msg, c->value_int );
1908 index_substr_if_minlen = c->value_int;
1911 #ifdef SLAPD_MODULES
1913 /* If we're just adding a module on an existing modpath,
1914 * make sure we've selected the current path.
1916 if ( c->op == LDAP_MOD_ADD && c->ca_private && modcur != c->ca_private ) {
1917 modcur = c->ca_private;
1918 /* This should never fail */
1919 if ( module_path( modcur->mp_path.bv_val )) {
1920 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> module path no longer valid",
1922 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1923 c->log, c->cr_msg, modcur->mp_path.bv_val );
1927 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1929 /* Record this load on the current path */
1933 if ( c->op == SLAP_CONFIG_ADD ) {
1934 ptr = c->line + STRLENOF("moduleload");
1935 while (!isspace((unsigned char) *ptr)) ptr++;
1936 while (isspace((unsigned char) *ptr)) ptr++;
1940 ber_str2bv(ptr, 0, 1, &bv);
1941 ber_bvarray_add( &modcur->mp_loads, &bv );
1943 /* Check for any new hardcoded schema */
1944 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
1945 config_check_schema( NULL, &cfBackInfo );
1950 if(module_path(c->argv[1])) return(1);
1951 /* Record which path was used with each module */
1955 if (!modpaths.mp_loads) {
1958 mp = ch_malloc( sizeof( ModPaths ));
1959 modlast->mp_next = mp;
1961 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1963 mp->mp_loads = NULL;
1974 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
1976 slapi_plugins_used++;
1980 #ifdef SLAP_AUTH_REWRITE
1985 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
1988 if ( c->argc > 1 ) {
1991 /* quote all args but the first */
1992 line = ldap_charray2str( c->argv, "\" \"" );
1993 ber_str2bv( line, 0, 0, &bv );
1994 s = ber_bvchr( &bv, '"' );
1995 assert( s != NULL );
1996 /* move the trailing quote of argv[0] to the end */
1997 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
1998 bv.bv_val[ bv.bv_len - 1 ] = '"';
2001 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
2004 ber_bvarray_add( &authz_rewrites, &bv );
2011 Debug( LDAP_DEBUG_ANY,
2012 "%s: unknown CFG_TYPE %d.\n",
2013 c->log, c->type, 0 );
2022 config_fname(ConfigArgs *c) {
2023 if(c->op == SLAP_CONFIG_EMIT) {
2024 if (c->ca_private) {
2025 ConfigFile *cf = c->ca_private;
2026 value_add_one( &c->rvalue_vals, &cf->c_file );
2035 config_cfdir(ConfigArgs *c) {
2036 if(c->op == SLAP_CONFIG_EMIT) {
2037 if ( !BER_BVISEMPTY( &cfdir )) {
2038 value_add_one( &c->rvalue_vals, &cfdir );
2047 config_search_base(ConfigArgs *c) {
2048 if(c->op == SLAP_CONFIG_EMIT) {
2050 if (!BER_BVISEMPTY(&default_search_base)) {
2051 value_add_one(&c->rvalue_vals, &default_search_base);
2052 value_add_one(&c->rvalue_nvals, &default_search_nbase);
2056 } else if( c->op == LDAP_MOD_DELETE ) {
2057 ch_free( default_search_base.bv_val );
2058 ch_free( default_search_nbase.bv_val );
2059 BER_BVZERO( &default_search_base );
2060 BER_BVZERO( &default_search_nbase );
2064 if(c->bi || c->be != frontendDB) {
2065 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
2066 "prior to any backend or database definition\n",
2071 if(default_search_nbase.bv_len) {
2072 free(default_search_base.bv_val);
2073 free(default_search_nbase.bv_val);
2076 default_search_base = c->value_dn;
2077 default_search_nbase = c->value_ndn;
2081 /* For RE23 compatibility we allow this in the global entry
2082 * but we now defer it to the frontend entry to allow modules
2083 * to load new hash types.
2086 config_passwd_hash(ConfigArgs *c) {
2088 if (c->op == SLAP_CONFIG_EMIT) {
2090 /* Don't generate it in the global entry */
2091 if ( c->table == Cft_Global )
2093 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
2094 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
2095 value_add_one(&c->rvalue_vals, &bv);
2098 } else if ( c->op == LDAP_MOD_DELETE ) {
2099 /* Deleting from global is a no-op, only the frontendDB entry matters */
2100 if ( c->table == Cft_Global )
2102 if ( c->valx < 0 ) {
2103 ldap_charray_free( default_passwd_hash );
2104 default_passwd_hash = NULL;
2107 ch_free( default_passwd_hash[i] );
2108 for (; default_passwd_hash[i]; i++ )
2109 default_passwd_hash[i] = default_passwd_hash[i+1];
2113 for(i = 1; i < c->argc; i++) {
2114 if(!lutil_passwd_scheme(c->argv[i])) {
2115 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> scheme not available", c->argv[0] );
2116 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2117 c->log, c->cr_msg, c->argv[i]);
2119 ldap_charray_add(&default_passwd_hash, c->argv[i]);
2122 if(!default_passwd_hash) {
2123 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> no valid hashes found", c->argv[0] );
2124 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2125 c->log, c->cr_msg, 0 );
2132 config_schema_dn(ConfigArgs *c) {
2133 if ( c->op == SLAP_CONFIG_EMIT ) {
2135 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
2136 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
2137 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
2141 } else if ( c->op == LDAP_MOD_DELETE ) {
2142 ch_free( c->be->be_schemadn.bv_val );
2143 ch_free( c->be->be_schemandn.bv_val );
2144 BER_BVZERO( &c->be->be_schemadn );
2145 BER_BVZERO( &c->be->be_schemandn );
2148 ch_free( c->be->be_schemadn.bv_val );
2149 ch_free( c->be->be_schemandn.bv_val );
2150 c->be->be_schemadn = c->value_dn;
2151 c->be->be_schemandn = c->value_ndn;
2156 config_sizelimit(ConfigArgs *c) {
2158 struct slap_limits_set *lim = &c->be->be_def_limit;
2159 if (c->op == SLAP_CONFIG_EMIT) {
2164 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
2165 if ( !BER_BVISEMPTY( &bv ))
2166 value_add_one( &c->rvalue_vals, &bv );
2170 } else if ( c->op == LDAP_MOD_DELETE ) {
2171 /* Reset to defaults */
2172 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
2173 lim->lms_s_hard = 0;
2174 lim->lms_s_unchecked = -1;
2176 lim->lms_s_pr_hide = 0;
2177 lim->lms_s_pr_total = 0;
2180 for(i = 1; i < c->argc; i++) {
2181 if(!strncasecmp(c->argv[i], "size", 4)) {
2182 rc = limits_parse_one(c->argv[i], lim);
2184 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2185 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2186 c->log, c->cr_msg, c->argv[i]);
2190 if(!strcasecmp(c->argv[i], "unlimited")) {
2191 lim->lms_s_soft = -1;
2193 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
2194 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2195 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2196 c->log, c->cr_msg, c->argv[i]);
2200 lim->lms_s_hard = 0;
2207 config_timelimit(ConfigArgs *c) {
2209 struct slap_limits_set *lim = &c->be->be_def_limit;
2210 if (c->op == SLAP_CONFIG_EMIT) {
2215 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
2216 if ( !BER_BVISEMPTY( &bv ))
2217 value_add_one( &c->rvalue_vals, &bv );
2221 } else if ( c->op == LDAP_MOD_DELETE ) {
2222 /* Reset to defaults */
2223 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
2224 lim->lms_t_hard = 0;
2227 for(i = 1; i < c->argc; i++) {
2228 if(!strncasecmp(c->argv[i], "time", 4)) {
2229 rc = limits_parse_one(c->argv[i], lim);
2231 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2232 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2233 c->log, c->cr_msg, c->argv[i]);
2237 if(!strcasecmp(c->argv[i], "unlimited")) {
2238 lim->lms_t_soft = -1;
2240 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
2241 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2242 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2243 c->log, c->cr_msg, c->argv[i]);
2247 lim->lms_t_hard = 0;
2254 config_overlay(ConfigArgs *c) {
2255 if (c->op == SLAP_CONFIG_EMIT) {
2257 } else if ( c->op == LDAP_MOD_DELETE ) {
2260 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2261 c->valx, &c->bi, &c->reply)) {
2263 Debug( LDAP_DEBUG_ANY,
2264 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2265 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2267 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi, &c->reply)) {
2274 config_subordinate(ConfigArgs *c)
2280 case SLAP_CONFIG_EMIT:
2281 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2284 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2285 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2288 value_add_one( &c->rvalue_vals, &bv );
2292 case LDAP_MOD_DELETE:
2293 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2294 glue_sub_del( c->be );
2296 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2301 case SLAP_CONFIG_ADD:
2302 advertise = ( c->argc == 2 && !strcasecmp( c->argv[1], "advertise" ));
2303 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2310 config_suffix(ConfigArgs *c)
2313 struct berval pdn, ndn;
2314 char *notallowed = NULL;
2316 if ( c->be == frontendDB ) {
2317 notallowed = "frontend";
2319 } else if ( SLAP_MONITOR(c->be) ) {
2320 notallowed = "monitor";
2322 } else if ( SLAP_CONFIG(c->be) ) {
2323 notallowed = "config";
2326 if ( notallowed != NULL ) {
2327 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
2331 case LDAP_MOD_DELETE:
2332 case LDAP_MOD_REPLACE:
2333 case LDAP_MOD_INCREMENT:
2334 case SLAP_CONFIG_ADD:
2335 if ( !BER_BVISNULL( &c->value_dn ) ) {
2336 snprintf( buf, sizeof( buf ), "<%s> ",
2337 c->value_dn.bv_val );
2340 Debug(LDAP_DEBUG_ANY,
2341 "%s: suffix %snot allowed in %s database.\n",
2342 c->log, buf, notallowed );
2345 case SLAP_CONFIG_EMIT:
2346 /* don't complain when emitting... */
2350 /* FIXME: don't know what values may be valid;
2351 * please remove assertion, or add legal values
2352 * to either block */
2360 if (c->op == SLAP_CONFIG_EMIT) {
2361 if ( c->be->be_suffix == NULL
2362 || BER_BVISNULL( &c->be->be_suffix[0] ) )
2366 value_add( &c->rvalue_vals, c->be->be_suffix );
2367 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
2370 } else if ( c->op == LDAP_MOD_DELETE ) {
2371 if ( c->valx < 0 ) {
2372 ber_bvarray_free( c->be->be_suffix );
2373 ber_bvarray_free( c->be->be_nsuffix );
2374 c->be->be_suffix = NULL;
2375 c->be->be_nsuffix = NULL;
2378 ch_free( c->be->be_suffix[i].bv_val );
2379 ch_free( c->be->be_nsuffix[i].bv_val );
2381 c->be->be_suffix[i] = c->be->be_suffix[i+1];
2382 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
2384 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
2389 #ifdef SLAPD_MONITOR_DN
2390 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
2391 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> DN is reserved for monitoring slapd",
2393 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2394 c->log, c->cr_msg, SLAPD_MONITOR_DN);
2399 if (SLAP_DB_ONE_SUFFIX( c->be ) && c->be->be_suffix ) {
2400 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> Only one suffix is allowed on this %s backend",
2401 c->argv[0], c->be->bd_info->bi_type );
2402 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2403 c->log, c->cr_msg, 0);
2410 if (SLAP_DBHIDDEN( c->be ))
2413 tbe = select_backend(&ndn, 0);
2415 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
2421 BackendDB *b2 = tbe;
2423 /* Does tbe precede be? */
2424 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
2427 char *type = tbe->bd_info->bi_type;
2429 if ( overlay_is_over( tbe ) ) {
2430 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
2431 type = oi->oi_orig->bi_type;
2434 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> namingContext \"%s\" "
2435 "already served by a preceding %s database",
2436 c->argv[0], pdn.bv_val, type );
2437 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
2438 c->log, c->cr_msg, tbe->be_suffix[0].bv_val);
2444 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
2445 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
2446 "base provided \"%s\" (assuming okay)\n",
2447 c->log, default_search_base.bv_val, 0);
2449 ber_bvarray_add(&c->be->be_suffix, &pdn);
2450 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
2455 config_rootdn(ConfigArgs *c) {
2456 if (c->op == SLAP_CONFIG_EMIT) {
2457 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2458 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
2459 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
2464 } else if ( c->op == LDAP_MOD_DELETE ) {
2465 ch_free( c->be->be_rootdn.bv_val );
2466 ch_free( c->be->be_rootndn.bv_val );
2467 BER_BVZERO( &c->be->be_rootdn );
2468 BER_BVZERO( &c->be->be_rootndn );
2471 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2472 ch_free( c->be->be_rootdn.bv_val );
2473 ch_free( c->be->be_rootndn.bv_val );
2475 c->be->be_rootdn = c->value_dn;
2476 c->be->be_rootndn = c->value_ndn;
2481 config_rootpw(ConfigArgs *c) {
2484 if (c->op == SLAP_CONFIG_EMIT) {
2485 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
2486 /* don't copy, because "rootpw" is marked
2488 c->value_bv = c->be->be_rootpw;
2492 } else if ( c->op == LDAP_MOD_DELETE ) {
2493 ch_free( c->be->be_rootpw.bv_val );
2494 BER_BVZERO( &c->be->be_rootpw );
2498 tbe = select_backend(&c->be->be_rootndn, 0);
2500 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> can only be set when rootdn is under suffix",
2502 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2503 c->log, c->cr_msg, 0);
2506 if ( !BER_BVISNULL( &c->be->be_rootpw ))
2507 ch_free( c->be->be_rootpw.bv_val );
2508 c->be->be_rootpw = c->value_bv;
2513 config_restrict(ConfigArgs *c) {
2514 slap_mask_t restrictops = 0;
2516 slap_verbmasks restrictable_ops[] = {
2517 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
2518 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
2519 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
2520 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
2521 { BER_BVC("modrdn"), 0 },
2522 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
2523 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
2524 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
2525 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
2526 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
2527 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
2528 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
2529 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
2530 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
2531 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
2532 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
2536 if (c->op == SLAP_CONFIG_EMIT) {
2537 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
2539 } else if ( c->op == LDAP_MOD_DELETE ) {
2541 c->be->be_restrictops = 0;
2543 restrictops = verb_to_mask( c->line, restrictable_ops );
2544 c->be->be_restrictops ^= restrictops;
2548 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
2550 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown operation", c->argv[0] );
2551 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2552 c->log, c->cr_msg, c->argv[i]);
2555 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
2556 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
2557 c->be->be_restrictops |= restrictops;
2562 config_allows(ConfigArgs *c) {
2563 slap_mask_t allows = 0;
2565 slap_verbmasks allowable_ops[] = {
2566 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
2567 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
2568 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
2569 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
2570 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
2573 if (c->op == SLAP_CONFIG_EMIT) {
2574 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
2575 } else if ( c->op == LDAP_MOD_DELETE ) {
2579 allows = verb_to_mask( c->line, allowable_ops );
2580 global_allows ^= allows;
2584 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
2586 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
2587 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2588 c->log, c->cr_msg, c->argv[i]);
2591 global_allows |= allows;
2596 config_disallows(ConfigArgs *c) {
2597 slap_mask_t disallows = 0;
2599 slap_verbmasks disallowable_ops[] = {
2600 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
2601 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
2602 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
2603 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
2604 { BER_BVC("proxy_authz_non_critical"), SLAP_DISALLOW_PROXY_AUTHZ_N_CRIT },
2605 { BER_BVC("dontusecopy_non_critical"), SLAP_DISALLOW_DONTUSECOPY_N_CRIT },
2608 if (c->op == SLAP_CONFIG_EMIT) {
2609 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
2610 } else if ( c->op == LDAP_MOD_DELETE ) {
2612 global_disallows = 0;
2614 disallows = verb_to_mask( c->line, disallowable_ops );
2615 global_disallows ^= disallows;
2619 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
2621 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
2622 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2623 c->log, c->cr_msg, c->argv[i]);
2626 global_disallows |= disallows;
2631 config_requires(ConfigArgs *c) {
2632 slap_mask_t requires = frontendDB->be_requires;
2633 int i, argc = c->argc;
2634 char **argv = c->argv;
2636 slap_verbmasks requires_ops[] = {
2637 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
2638 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
2639 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
2640 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
2641 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
2644 if (c->op == SLAP_CONFIG_EMIT) {
2645 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
2646 } else if ( c->op == LDAP_MOD_DELETE ) {
2648 c->be->be_requires = 0;
2650 requires = verb_to_mask( c->line, requires_ops );
2651 c->be->be_requires ^= requires;
2655 /* "none" can only be first, to wipe out default/global values */
2656 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
2661 i = verbs_to_mask(argc, argv, requires_ops, &requires);
2663 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
2664 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
2665 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2666 c->log, c->cr_msg, 0);
2668 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
2669 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2670 c->log, c->cr_msg, c->argv[i]);
2674 c->be->be_requires = requires;
2678 static slap_verbmasks *loglevel_ops;
2681 loglevel_init( void )
2683 slap_verbmasks lo[] = {
2684 { BER_BVC("Any"), -1 },
2685 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
2686 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
2687 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
2688 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
2689 { BER_BVC("BER"), LDAP_DEBUG_BER },
2690 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
2691 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
2692 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
2693 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
2694 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
2695 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
2696 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
2697 #if 0 /* no longer used (nor supported) */
2698 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
2699 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
2701 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
2702 { BER_BVC("None"), LDAP_DEBUG_NONE },
2706 return slap_verbmasks_init( &loglevel_ops, lo );
2710 loglevel_destroy( void )
2712 if ( loglevel_ops ) {
2713 (void)slap_verbmasks_destroy( loglevel_ops );
2715 loglevel_ops = NULL;
2718 static slap_mask_t loglevel_ignore[] = { -1, 0 };
2721 slap_loglevel_register( slap_mask_t m, struct berval *s )
2725 if ( loglevel_ops == NULL ) {
2729 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
2732 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
2740 slap_loglevel_get( struct berval *s, int *l )
2745 if ( loglevel_ops == NULL ) {
2749 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
2750 m |= loglevel_ops[ i ].mask;
2753 for ( i = 1; m & i; i <<= 1 )
2760 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
2763 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
2774 str2loglevel( const char *s, int *l )
2778 if ( loglevel_ops == NULL ) {
2782 i = verb_to_mask( s, loglevel_ops );
2784 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
2788 *l = loglevel_ops[ i ].mask;
2794 loglevel2str( int l )
2796 struct berval bv = BER_BVNULL;
2798 loglevel2bv( l, &bv );
2804 loglevel2bv( int l, struct berval *bv )
2806 if ( loglevel_ops == NULL ) {
2812 return enum_to_verb( loglevel_ops, l, bv ) == -1;
2816 loglevel2bvarray( int l, BerVarray *bva )
2818 if ( loglevel_ops == NULL ) {
2822 return mask_to_verbs( loglevel_ops, l, bva );
2826 loglevel_print( FILE *out )
2830 if ( loglevel_ops == NULL ) {
2834 fprintf( out, "Installed log subsystems:\n\n" );
2835 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
2836 fprintf( out, "\t%-30s (%lu)\n",
2837 loglevel_ops[ i ].word.bv_val,
2838 loglevel_ops[ i ].mask );
2841 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
2842 "by specific code\n\n" );
2847 static int config_syslog;
2850 config_loglevel(ConfigArgs *c) {
2853 if ( loglevel_ops == NULL ) {
2857 if (c->op == SLAP_CONFIG_EMIT) {
2858 /* Get default or commandline slapd setting */
2859 if ( ldap_syslog && !config_syslog )
2860 config_syslog = ldap_syslog;
2861 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
2863 } else if ( c->op == LDAP_MOD_DELETE ) {
2867 int level = verb_to_mask( c->line, loglevel_ops );
2868 config_syslog ^= level;
2870 if ( slapMode & SLAP_SERVER_MODE ) {
2871 ldap_syslog = config_syslog;
2876 for( i=1; i < c->argc; i++ ) {
2879 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
2880 if( lutil_atoi( &level, c->argv[i] ) != 0 ) {
2881 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse level", c->argv[0] );
2882 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2883 c->log, c->cr_msg, c->argv[i]);
2887 if ( str2loglevel( c->argv[i], &level ) ) {
2888 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown level", c->argv[0] );
2889 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2890 c->log, c->cr_msg, c->argv[i]);
2894 /* Explicitly setting a zero clears all the levels */
2896 config_syslog |= level;
2900 if ( slapMode & SLAP_SERVER_MODE ) {
2901 ldap_syslog = config_syslog;
2907 config_referral(ConfigArgs *c) {
2909 if (c->op == SLAP_CONFIG_EMIT) {
2910 if ( default_referral ) {
2911 value_add( &c->rvalue_vals, default_referral );
2916 } else if ( c->op == LDAP_MOD_DELETE ) {
2917 if ( c->valx < 0 ) {
2918 ber_bvarray_free( default_referral );
2919 default_referral = NULL;
2922 ch_free( default_referral[i].bv_val );
2923 for (; default_referral[i].bv_val; i++ )
2924 default_referral[i] = default_referral[i+1];
2928 if(validate_global_referral(c->argv[1])) {
2929 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
2930 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2931 c->log, c->cr_msg, c->argv[1]);
2935 ber_str2bv(c->argv[1], 0, 0, &val);
2936 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
2944 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
2945 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
2946 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
2947 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
2948 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
2949 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
2950 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
2951 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
2952 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
2957 config_security(ConfigArgs *c) {
2958 slap_ssf_set_t *set = &c->be->be_ssf_set;
2961 if (c->op == SLAP_CONFIG_EMIT) {
2967 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
2968 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
2971 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
2972 if ( bv.bv_len >= sizeof( numbuf ) ) {
2973 ber_bvarray_free_x( c->rvalue_vals, NULL );
2974 c->rvalue_vals = NULL;
2978 bv.bv_len += sec_keys[i].key.bv_len;
2979 bv.bv_val = ch_malloc( bv.bv_len + 1);
2980 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
2981 strcpy( next, numbuf );
2982 ber_bvarray_add( &c->rvalue_vals, &bv );
2987 for(i = 1; i < c->argc; i++) {
2988 slap_ssf_t *tgt = NULL;
2990 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
2991 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
2992 sec_keys[j].key.bv_len)) {
2993 src = c->argv[i] + sec_keys[j].key.bv_len;
2994 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
2999 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown factor", c->argv[0] );
3000 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3001 c->log, c->cr_msg, c->argv[i]);
3005 if ( lutil_atou( tgt, src ) != 0 ) {
3006 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse factor", c->argv[0] );
3007 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3008 c->log, c->cr_msg, c->argv[i]);
3016 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
3020 for (; !BER_BVISNULL( &an->an_name ); an++) {
3021 /* if buflen == 0, assume the buffer size has been
3022 * already checked otherwise */
3023 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
3024 if ( comma ) *ptr++ = ',';
3025 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
3032 config_updatedn(ConfigArgs *c) {
3033 if (c->op == SLAP_CONFIG_EMIT) {
3034 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
3035 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
3036 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
3040 } else if ( c->op == LDAP_MOD_DELETE ) {
3041 ch_free( c->be->be_update_ndn.bv_val );
3042 BER_BVZERO( &c->be->be_update_ndn );
3043 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
3046 if(SLAP_SHADOW(c->be)) {
3047 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database already shadowed", c->argv[0] );
3048 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3049 c->log, c->cr_msg, 0);
3053 ber_memfree_x( c->value_dn.bv_val, NULL );
3054 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
3055 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
3057 c->be->be_update_ndn = c->value_ndn;
3058 BER_BVZERO( &c->value_dn );
3059 BER_BVZERO( &c->value_ndn );
3061 return config_slurp_shadow( c );
3065 config_shadow( ConfigArgs *c, int flag )
3067 char *notallowed = NULL;
3069 if ( c->be == frontendDB ) {
3070 notallowed = "frontend";
3072 } else if ( SLAP_MONITOR(c->be) ) {
3073 notallowed = "monitor";
3076 if ( notallowed != NULL ) {
3077 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
3081 if ( SLAP_SHADOW(c->be) ) {
3082 /* if already shadow, only check consistency */
3083 if ( ( SLAP_DBFLAGS(c->be) & flag ) != flag ) {
3084 Debug( LDAP_DEBUG_ANY, "%s: inconsistent shadow flag 0x%x.\n", c->log, flag, 0 );
3089 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SINGLE_SHADOW | flag);
3096 config_updateref(ConfigArgs *c) {
3098 if (c->op == SLAP_CONFIG_EMIT) {
3099 if ( c->be->be_update_refs ) {
3100 value_add( &c->rvalue_vals, c->be->be_update_refs );
3105 } else if ( c->op == LDAP_MOD_DELETE ) {
3106 if ( c->valx < 0 ) {
3107 ber_bvarray_free( c->be->be_update_refs );
3108 c->be->be_update_refs = NULL;
3111 ch_free( c->be->be_update_refs[i].bv_val );
3112 for (; c->be->be_update_refs[i].bv_val; i++)
3113 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
3117 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
3118 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must appear after syncrepl or updatedn",
3120 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3121 c->log, c->cr_msg, 0);
3125 if(validate_global_referral(c->argv[1])) {
3126 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3127 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3128 c->log, c->cr_msg, c->argv[1]);
3131 ber_str2bv(c->argv[1], 0, 0, &val);
3132 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
3137 config_obsolete(ConfigArgs *c) {
3138 if (c->op == SLAP_CONFIG_EMIT)
3141 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> keyword is obsolete (ignored)",
3143 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0);
3148 config_include(ConfigArgs *c) {
3149 int savelineno = c->lineno;
3152 ConfigFile *cfsave = cfn;
3153 ConfigFile *cf2 = NULL;
3155 /* Leftover from RE23. No dynamic config for include files */
3156 if ( c->op == SLAP_CONFIG_EMIT || c->op == LDAP_MOD_DELETE )
3159 cf = ch_calloc( 1, sizeof(ConfigFile));
3160 if ( cfn->c_kids ) {
3161 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
3167 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
3168 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
3169 c->lineno = savelineno - 1;
3172 if ( cf2 ) cf2->c_sibs = NULL;
3173 else cfn->c_kids = NULL;
3174 ch_free( cf->c_file.bv_val );
3184 config_tls_option(ConfigArgs *c) {
3186 LDAP *ld = slap_tls_ld;
3188 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
3189 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
3190 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
3191 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
3192 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
3193 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
3194 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
3196 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
3198 default: Debug(LDAP_DEBUG_ANY, "%s: "
3199 "unknown tls_option <0x%x>\n",
3200 c->log, c->type, 0);
3203 if (c->op == SLAP_CONFIG_EMIT) {
3204 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
3205 } else if ( c->op == LDAP_MOD_DELETE ) {
3206 return ldap_pvt_tls_set_option( ld, flag, NULL );
3208 ch_free(c->value_string);
3209 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
3212 /* FIXME: this ought to be provided by libldap */
3214 config_tls_config(ConfigArgs *c) {
3217 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
3218 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
3219 case CFG_TLS_PROTOCOL_MIN: flag = LDAP_OPT_X_TLS_PROTOCOL_MIN; break;
3221 Debug(LDAP_DEBUG_ANY, "%s: "
3222 "unknown tls_option <0x%x>\n",
3223 c->log, c->type, 0);
3226 if (c->op == SLAP_CONFIG_EMIT) {
3227 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
3228 } else if ( c->op == LDAP_MOD_DELETE ) {
3230 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
3232 ch_free( c->value_string );
3233 if ( isdigit( (unsigned char)c->argv[1][0] ) ) {
3234 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
3235 Debug(LDAP_DEBUG_ANY, "%s: "
3236 "unable to parse %s \"%s\"\n",
3237 c->log, c->argv[0], c->argv[1] );
3240 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
3242 return(ldap_int_tls_config(slap_tls_ld, flag, c->argv[1]));
3247 static CfEntryInfo *
3248 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
3258 if ( dn_match( &root->ce_entry->e_nname, dn ))
3261 c = dn->bv_val+dn->bv_len;
3262 for (;*c != ',';c--);
3266 for (--c;c>dn->bv_val && *c != ',';c--);
3270 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
3272 root = root->ce_kids;
3274 for (;root;root=root->ce_sibs) {
3275 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
3276 if ( cdn.bv_val == dn->bv_val ) {
3286 typedef struct setup_cookie {
3296 config_ldif_resp( Operation *op, SlapReply *rs )
3298 if ( rs->sr_type == REP_SEARCH ) {
3299 setup_cookie *sc = op->o_callback->sc_private;
3302 sc->cfb->cb_got_ldif = 1;
3303 /* Does the frontend exist? */
3304 if ( !sc->got_frontend ) {
3305 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
3306 "olcDatabase", STRLENOF( "olcDatabase" )))
3308 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3309 STRLENOF( "olcDatabase" ), "={-1}frontend",
3310 STRLENOF( "={-1}frontend" )))
3314 sc->ca->be = frontendDB;
3315 sc->ca->bi = frontendDB->bd_info;
3316 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
3317 rdn.bv_val = sc->ca->log;
3318 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3319 "%s=" SLAP_X_ORDERED_FMT "%s",
3320 cfAd_database->ad_cname.bv_val, -1,
3321 sc->ca->bi->bi_type);
3323 sc->frontend = config_build_entry( op, rs,
3324 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
3325 sc->ca->be->be_cf_ocs );
3335 dnParent( &rs->sr_entry->e_nname, &pdn );
3337 /* Does the configDB exist? */
3338 if ( sc->got_frontend && !sc->got_config &&
3339 !strncmp( rs->sr_entry->e_nname.bv_val,
3340 "olcDatabase", STRLENOF( "olcDatabase" )) &&
3341 dn_match( &config_rdn, &pdn ) )
3343 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3344 STRLENOF( "olcDatabase" ), "={0}config",
3345 STRLENOF( "={0}config" )))
3349 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
3350 sc->ca->bi = sc->ca->be->bd_info;
3351 rdn.bv_val = sc->ca->log;
3352 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3353 "%s=" SLAP_X_ORDERED_FMT "%s",
3354 cfAd_database->ad_cname.bv_val, 0,
3355 sc->ca->bi->bi_type);
3357 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
3358 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
3365 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
3366 if ( rs->sr_err != LDAP_SUCCESS ) {
3367 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
3368 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg, 0 );
3374 /* Configure and read the underlying back-ldif store */
3376 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
3377 CfBackInfo *cfb = be->be_private;
3383 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
3384 Connection conn = {0};
3385 OperationBuffer opbuf;
3387 SlapReply rs = {REP_RESULT};
3388 Filter filter = { LDAP_FILTER_PRESENT };
3389 struct berval filterstr = BER_BVC("(objectclass=*)");
3392 /* Is the config directory available? */
3393 if ( stat( dir, &st ) < 0 ) {
3394 /* No, so don't bother using the backing store.
3395 * All changes will be in-memory only.
3400 cfb->cb_db.bd_info = backend_info( "ldif" );
3401 if ( !cfb->cb_db.bd_info )
3402 return 0; /* FIXME: eventually this will be a fatal error */
3404 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
3407 cfb->cb_db.be_suffix = be->be_suffix;
3408 cfb->cb_db.be_nsuffix = be->be_nsuffix;
3410 /* The suffix is always "cn=config". The underlying DB's rootdn
3411 * is always the same as the suffix.
3413 cfb->cb_db.be_rootdn = be->be_suffix[0];
3414 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
3416 ber_str2bv( dir, 0, 1, &cfdir );
3421 argv[0] = "directory";
3422 argv[1] = (char *)dir;
3427 c.table = Cft_Database;
3429 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
3433 if ( config_add_vals( ct, &c ))
3436 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
3440 void *thrctx = ldap_pvt_thread_pool_context();
3443 connection_fake_init( &conn, &opbuf, thrctx );
3446 filter.f_desc = slap_schema.si_ad_objectClass;
3448 op->o_tag = LDAP_REQ_SEARCH;
3450 op->ors_filter = &filter;
3451 op->ors_filterstr = filterstr;
3452 op->ors_scope = LDAP_SCOPE_SUBTREE;
3454 op->o_dn = c.be->be_rootdn;
3455 op->o_ndn = c.be->be_rootndn;
3457 op->o_req_dn = be->be_suffix[0];
3458 op->o_req_ndn = be->be_nsuffix[0];
3460 op->ors_tlimit = SLAP_NO_LIMIT;
3461 op->ors_slimit = SLAP_NO_LIMIT;
3463 op->ors_attrs = slap_anlist_all_attributes;
3464 op->ors_attrsonly = 0;
3466 op->o_callback = &cb;
3469 cb.sc_private = ≻
3470 sc.got_frontend = 0;
3475 op->o_bd = &cfb->cb_db;
3477 /* Allow unknown attrs in DNs */
3478 prev_DN_strict = slap_DN_strict;
3481 rc = op->o_bd->be_search( op, &rs );
3483 /* Restore normal DN validation */
3484 slap_DN_strict = prev_DN_strict;
3486 op->o_tag = LDAP_REQ_ADD;
3487 if ( rc == LDAP_SUCCESS && sc.frontend ) {
3488 op->ora_e = sc.frontend;
3489 rc = op->o_bd->be_add( op, &rs );
3491 if ( rc == LDAP_SUCCESS && sc.config ) {
3492 op->ora_e = sc.config;
3493 rc = op->o_bd->be_add( op, &rs );
3495 ldap_pvt_thread_pool_context_reset( thrctx );
3498 /* ITS#4194 - only use if it's present, or we're converting. */
3499 if ( !readit || rc == LDAP_SUCCESS )
3500 cfb->cb_use_ldif = 1;
3506 CfOc_cmp( const void *c1, const void *c2 ) {
3507 const ConfigOCs *co1 = c1;
3508 const ConfigOCs *co2 = c2;
3510 return ber_bvcmp( co1->co_name, co2->co_name );
3514 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
3517 i = init_config_attrs( ct );
3520 /* set up the objectclasses */
3521 i = init_config_ocs( ocs );
3524 for (i=0; ocs[i].co_def; i++) {
3525 if ( ocs[i].co_oc ) {
3526 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
3527 if ( !ocs[i].co_table )
3528 ocs[i].co_table = ct;
3529 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
3536 read_config(const char *fname, const char *dir) {
3539 const char *cfdir, *cfname;
3542 /* Setup the config backend */
3543 be = backend_db_init( "config", NULL, 0, NULL );
3547 cfb = be->be_private;
3548 be->be_dfltaccess = ACL_NONE;
3550 /* If no .conf, or a dir was specified, setup the dir */
3551 if ( !fname || dir ) {
3553 /* If explicitly given, check for existence */
3556 if ( stat( dir, &st ) < 0 ) {
3557 Debug( LDAP_DEBUG_ANY,
3558 "invalid config directory %s, error %d\n",
3564 cfdir = SLAPD_DEFAULT_CONFIGDIR;
3566 /* if fname is defaulted, try reading .d */
3567 rc = config_setup_ldif( be, cfdir, !fname );
3570 /* It may be OK if the base object doesn't exist yet. */
3571 if ( rc != LDAP_NO_SUCH_OBJECT )
3573 /* ITS#4194: But if dir was specified and no fname,
3574 * then we were supposed to read the dir. Unless we're
3575 * trying to slapadd the dir...
3577 if ( dir && !fname ) {
3578 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
3580 /* Assume it's slapadd with a config dir, let it continue */
3582 cfb->cb_got_ldif = 1;
3583 cfb->cb_use_ldif = 1;
3588 /* If we read the config from back-ldif, nothing to do here */
3589 if ( cfb->cb_got_ldif ) {
3598 cfname = SLAPD_DEFAULT_CONFIGFILE;
3600 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
3603 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
3606 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
3607 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
3608 &frontendDB->be_schemadn );
3609 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
3610 if ( rc != LDAP_SUCCESS ) {
3611 Debug(LDAP_DEBUG_ANY, "read_config: "
3612 "unable to normalize default schema DN \"%s\"\n",
3613 frontendDB->be_schemadn.bv_val, 0, 0 );
3614 /* must not happen */
3622 config_back_bind( Operation *op, SlapReply *rs )
3624 if ( be_isroot_pw( op ) ) {
3625 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
3626 /* frontend sends result */
3627 return LDAP_SUCCESS;
3630 rs->sr_err = LDAP_INVALID_CREDENTIALS;
3631 send_ldap_result( op, rs );
3637 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
3641 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
3643 rs->sr_attrs = op->ors_attrs;
3644 rs->sr_entry = ce->ce_entry;
3646 rc = send_search_entry( op, rs );
3647 if ( rc != LDAP_SUCCESS ) {
3651 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
3652 if ( ce->ce_kids ) {
3653 rc = config_send( op, rs, ce->ce_kids, 1 );
3654 if ( rc ) return rc;
3657 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
3658 rc = config_send( op, rs, ce, 0 );
3666 static ConfigTable *
3667 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
3672 for (j=0; j<nocs; j++) {
3673 for (i=0; colst[j]->co_table[i].name; i++)
3674 if ( colst[j]->co_table[i].ad == ad ) {
3675 ca->table = colst[j]->co_type;
3676 return &colst[j]->co_table[i];
3682 /* Sort the attributes of the entry according to the order defined
3683 * in the objectclass, with required attributes occurring before
3684 * allowed attributes. For any attributes with sequencing dependencies
3685 * (e.g., rootDN must be defined after suffix) the objectclass must
3686 * list the attributes in the desired sequence.
3689 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
3691 Attribute *a, *head = NULL, *tail = NULL, **prev;
3694 for (i=0; i<nocs; i++) {
3695 if ( colst[i]->co_oc->soc_required ) {
3696 AttributeType **at = colst[i]->co_oc->soc_required;
3697 for (j=0; at[j]; j++) {
3698 for (a=e->e_attrs, prev=&e->e_attrs; a;
3699 prev = &(*prev)->a_next, a=a->a_next) {
3700 if ( a->a_desc == at[j]->sat_ad ) {
3714 if ( colst[i]->co_oc->soc_allowed ) {
3715 AttributeType **at = colst[i]->co_oc->soc_allowed;
3716 for (j=0; at[j]; j++) {
3717 for (a=e->e_attrs, prev=&e->e_attrs; a;
3718 prev = &(*prev)->a_next, a=a->a_next) {
3719 if ( a->a_desc == at[j]->sat_ad ) {
3735 tail->a_next = e->e_attrs;
3741 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
3743 Attribute *a = NULL;
3744 AttributeDescription *ad;
3754 Modifications *ml = ptr;
3756 vals = ml->sml_values;
3759 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
3760 rc = ordered_value_sort( a, 1 );
3762 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
3763 ad->ad_cname.bv_val );
3767 for ( i=0; vals[i].bv_val; i++ ) {
3768 ca->line = vals[i].bv_val;
3769 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
3770 ca->line[0] == '{' ) {
3771 char *idx = strchr( ca->line, '}' );
3772 if ( idx ) ca->line = idx+1;
3774 rc = config_parse_vals( ct, ca, i );
3783 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
3786 struct berval rtype, rval;
3788 AttributeDescription *ad = NULL;
3790 dnRdn( &e->e_name, rdn );
3791 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
3792 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
3793 rtype.bv_val = rdn->bv_val;
3794 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
3797 slap_bv2ad( &rtype, &ad, &rs->sr_text );
3798 a = attr_find( e->e_attrs, ad );
3799 if (!a ) return LDAP_NAMING_VIOLATION;
3806 config_rename_kids( CfEntryInfo *ce )
3809 struct berval rdn, nrdn;
3811 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
3812 dnRdn ( &ce2->ce_entry->e_name, &rdn );
3813 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
3814 free( ce2->ce_entry->e_name.bv_val );
3815 free( ce2->ce_entry->e_nname.bv_val );
3816 build_new_dn( &ce2->ce_entry->e_name, &ce->ce_entry->e_name,
3818 build_new_dn( &ce2->ce_entry->e_nname, &ce->ce_entry->e_nname,
3820 config_rename_kids( ce2 );
3825 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
3826 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
3827 struct berval *nnewrdn, int use_ldif )
3831 struct berval odn, ondn;
3835 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
3836 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
3839 free( a->a_vals[0].bv_val );
3840 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
3841 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
3842 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
3843 strcpy( a->a_vals[0].bv_val, ptr1 );
3845 if ( a->a_nvals != a->a_vals ) {
3846 free( a->a_nvals[0].bv_val );
3847 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
3848 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
3849 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
3850 strcpy( a->a_nvals[0].bv_val, ptr1 );
3853 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
3854 BackendDB *be = op->o_bd;
3855 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
3856 struct berval dn, ndn, xdn, xndn;
3858 op->o_bd = &cfb->cb_db;
3860 /* Save current rootdn; use the underlying DB's rootdn */
3864 xndn = op->o_req_ndn;
3865 op->o_dn = op->o_bd->be_rootdn;
3866 op->o_ndn = op->o_bd->be_rootndn;
3868 op->o_req_ndn = ondn;
3870 scp = op->o_callback;
3871 op->o_callback = ≻
3872 op->orr_newrdn = *newrdn;
3873 op->orr_nnewrdn = *nnewrdn;
3874 op->orr_newSup = NULL;
3875 op->orr_nnewSup = NULL;
3876 op->orr_deleteoldrdn = 1;
3877 op->orr_modlist = NULL;
3878 slap_modrdn2mods( op, rs );
3879 slap_mods_opattrs( op, &op->orr_modlist, 1 );
3880 rc = op->o_bd->be_modrdn( op, rs );
3881 slap_mods_free( op->orr_modlist, 1 );
3884 op->o_callback = scp;
3888 op->o_req_ndn = xndn;
3891 free( ondn.bv_val );
3893 config_rename_kids( e->e_private );
3898 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
3899 Entry *e, int idx, int tailindex, int use_ldif )
3901 struct berval ival, newrdn, nnewrdn;
3904 char ibuf[32], *ptr1, *ptr2 = NULL;
3907 rc = config_rename_attr( rs, e, &rdn, &a );
3908 if ( rc ) return rc;
3911 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
3912 if ( ival.bv_len >= sizeof( ibuf ) ) {
3913 return LDAP_NAMING_VIOLATION;
3916 newrdn.bv_len = rdn.bv_len + ival.bv_len;
3917 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
3920 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
3921 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3924 ptr2 = ber_bvchr( &rdn, '}' );
3928 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
3930 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
3931 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
3932 a->a_desc->ad_cname.bv_len );
3934 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3935 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
3939 /* Do the equivalent of ModRDN */
3940 /* Replace DN / NDN */
3941 newrdn.bv_len = ptr1 - newrdn.bv_val;
3942 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
3943 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
3945 free( nnewrdn.bv_val );
3946 free( newrdn.bv_val );
3951 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
3952 SlapReply *rs, int *renum, int *ibase )
3955 int index = -1, gotindex = 0, nsibs, rc = 0;
3956 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
3957 char *ptr1, *ptr2 = NULL;
3960 if ( renum ) *renum = 0;
3962 /* These entries don't get indexed/renumbered */
3963 if ( ce_type == Cft_Global ) return 0;
3964 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
3966 if ( ce_type == Cft_Module )
3969 /* See if the rdn has an index already */
3970 dnRdn( &e->e_name, &rdn );
3971 if ( ce_type == Cft_Database ) {
3972 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
3973 "frontend", STRLENOF("frontend") ))
3975 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
3976 "config", STRLENOF("config") ))
3979 ptr1 = ber_bvchr( &e->e_name, '{' );
3980 if ( ptr1 && ptr1 < &e->e_name.bv_val[ rdn.bv_len ] ) {
3982 ptr2 = strchr( ptr1, '}' );
3983 if ( !ptr2 || ptr2 > &e->e_name.bv_val[ rdn.bv_len ] )
3984 return LDAP_NAMING_VIOLATION;
3985 if ( ptr2-ptr1 == 1)
3986 return LDAP_NAMING_VIOLATION;
3988 index = strtol( ptr1 + 1, &next, 10 );
3989 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
3990 return LDAP_NAMING_VIOLATION;
3993 /* Special case, we allow -1 for the frontendDB */
3994 if ( index != -1 || !isfrontend )
3995 return LDAP_NAMING_VIOLATION;
3997 if ( isconfig && index != 0 ){
3998 return LDAP_NAMING_VIOLATION;
4002 /* count related kids */
4003 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
4004 if ( ce->ce_type == ce_type ) nsibs++;
4007 /* account for -1 frontend */
4008 if ( ce_type == Cft_Database )
4011 if ( index != nsibs ) {
4013 if ( index < nsibs ) {
4014 if ( tailindex ) return LDAP_NAMING_VIOLATION;
4015 /* Siblings need to be renumbered */
4016 if ( index != -1 || !isfrontend )
4020 /* config DB is always "0" */
4021 if ( isconfig && index == -1 ) {
4024 if (( !isfrontend && index == -1 ) || ( index > nsibs ) ){
4028 /* just make index = nsibs */
4030 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
4033 if ( ibase ) *ibase = index;
4034 if ( renum ) *renum = renumber;
4039 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
4044 co.co_name = &oc->soc_cname;
4045 cop = avl_find( CfOcTree, &co, CfOc_cmp );
4049 /* check for duplicates */
4050 for ( i = 0; i < *nocs; i++ ) {
4051 if ( *copp && (*copp)[i] == cop ) {
4057 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
4058 if ( tmp == NULL ) {
4062 (*copp)[*nocs] = cop;
4067 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
4068 if ( count_oc( *sups, copp, nocs ) ) {
4077 count_ocs( Attribute *oc_at, int *nocs )
4080 ConfigOCs **colst = NULL;
4084 for ( i = 0; !BER_BVISNULL( &oc_at->a_nvals[i] ); i++ )
4088 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
4090 assert( oc != NULL );
4091 if ( count_oc( oc, &colst, nocs ) ) {
4101 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4103 /* Leftover from RE23. Never parse this entry */
4104 return LDAP_COMPARE_TRUE;
4108 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4112 /* This entry is hardcoded, don't re-parse it */
4113 if ( p->ce_type == Cft_Global ) {
4114 cfn = p->ce_private;
4115 ca->ca_private = cfn;
4116 return LDAP_COMPARE_TRUE;
4118 if ( p->ce_type != Cft_Schema )
4119 return LDAP_CONSTRAINT_VIOLATION;
4121 cfn = ch_calloc( 1, sizeof(ConfigFile) );
4122 ca->ca_private = cfn;
4123 cfo = p->ce_private;
4124 cfn->c_sibs = cfo->c_kids;
4126 return LDAP_SUCCESS;
4130 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4132 if ( p->ce_type != Cft_Global ) {
4133 return LDAP_CONSTRAINT_VIOLATION;
4135 /* config must be {0}, nothing else allowed */
4136 if ( !strncmp( e->e_nname.bv_val, "olcDatabase={0}", STRLENOF("olcDatabase={0}")) &&
4137 strncmp( e->e_nname.bv_val + STRLENOF("olcDatabase={0}"), "config,", STRLENOF("config,") )) {
4138 return LDAP_CONSTRAINT_VIOLATION;
4140 ca->be = frontendDB; /* just to get past check_vals */
4141 return LDAP_SUCCESS;
4145 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4147 if ( p->ce_type != Cft_Global ) {
4148 return LDAP_CONSTRAINT_VIOLATION;
4150 return LDAP_SUCCESS;
4154 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4156 if ( p->ce_type != Cft_Global ) {
4157 return LDAP_CONSTRAINT_VIOLATION;
4159 return LDAP_SUCCESS;
4163 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4165 if ( p->ce_type != Cft_Database ) {
4166 return LDAP_CONSTRAINT_VIOLATION;
4169 return LDAP_SUCCESS;
4173 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
4178 AttributeDescription *ad;
4183 if ( cfn->c_cr_head ) {
4184 struct berval bv = BER_BVC("olcDitContentRules");
4186 slap_bv2ad( &bv, &ad, &text );
4187 ct = config_find_table( colst, nocs, ad, ca );
4188 config_del_vals( ct, ca );
4190 if ( cfn->c_oc_head ) {
4191 struct berval bv = BER_BVC("olcObjectClasses");
4193 slap_bv2ad( &bv, &ad, &text );
4194 ct = config_find_table( colst, nocs, ad, ca );
4195 config_del_vals( ct, ca );
4197 if ( cfn->c_at_head ) {
4198 struct berval bv = BER_BVC("olcAttributeTypes");
4200 slap_bv2ad( &bv, &ad, &text );
4201 ct = config_find_table( colst, nocs, ad, ca );
4202 config_del_vals( ct, ca );
4204 if ( cfn->c_syn_head ) {
4205 struct berval bv = BER_BVC("olcLdapSyntaxes");
4207 slap_bv2ad( &bv, &ad, &text );
4208 ct = config_find_table( colst, nocs, ad, ca );
4209 config_del_vals( ct, ca );
4211 if ( cfn->c_om_head ) {
4212 struct berval bv = BER_BVC("olcObjectIdentifier");
4214 slap_bv2ad( &bv, &ad, &text );
4215 ct = config_find_table( colst, nocs, ad, ca );
4216 config_del_vals( ct, ca );
4218 cfo = p->ce_private;
4219 cfo->c_kids = cfn->c_sibs;
4224 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
4226 int rc = LDAP_CONSTRAINT_VIOLATION;
4229 if ( (*cop)->co_ldadd ) {
4230 rc = (*cop)->co_ldadd( last, e, ca );
4231 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4236 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
4237 ConfigOCs co = { 0 };
4239 co.co_name = &(*ocp)->soc_cname;
4240 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
4241 if ( *cop == NULL ) {
4245 rc = config_add_oc( cop, last, e, ca );
4246 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4254 /* Parse an LDAP entry into config directives */
4256 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
4257 int *renum, Operation *op )
4259 CfEntryInfo *ce, *last = NULL;
4260 ConfigOCs co, *coptr, **colst;
4261 Attribute *a, *oc_at, *soc_at;
4262 int i, ibase = -1, nocs, rc = 0;
4265 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
4267 memset( ca, 0, sizeof(ConfigArgs));
4269 /* Make sure parent exists and entry does not. But allow
4270 * Databases and Overlays to be inserted. Don't do any
4271 * auto-renumbering if manageDSAit control is present.
4273 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
4275 if ( ( op && op->o_managedsait ) ||
4276 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
4277 ce->ce_type != Cft_Module ) )
4279 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4280 "DN=\"%s\" already exists\n",
4281 log_prefix, e->e_name.bv_val, 0 );
4282 return LDAP_ALREADY_EXISTS;
4286 dnParent( &e->e_nname, &pdn );
4288 /* If last is NULL, the new entry is the root/suffix entry,
4289 * otherwise last should be the parent.
4291 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
4293 rs->sr_matched = last->ce_entry->e_name.bv_val;
4295 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4296 "DN=\"%s\" not child of DN=\"%s\"\n",
4297 log_prefix, e->e_name.bv_val,
4298 last->ce_entry->e_name.bv_val );
4299 return LDAP_NO_SUCH_OBJECT;
4303 /* No parent, must be root. This will never happen... */
4304 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
4305 return LDAP_NO_SUCH_OBJECT;
4308 if ( last && !access_allowed( op, last->ce_entry,
4309 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
4311 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4312 "DN=\"%s\" no write access to \"children\" of parent\n",
4313 log_prefix, e->e_name.bv_val, 0 );
4314 return LDAP_INSUFFICIENT_ACCESS;
4318 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4320 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4321 "DN=\"%s\" no objectClass\n",
4322 log_prefix, e->e_name.bv_val, 0 );
4323 return LDAP_OBJECT_CLASS_VIOLATION;
4326 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4328 ObjectClass *soc = NULL;
4329 char textbuf[ SLAP_TEXT_BUFLEN ];
4330 const char *text = textbuf;
4332 /* FIXME: check result */
4333 rc = structural_class( oc_at->a_nvals, &soc, NULL,
4334 &text, textbuf, sizeof(textbuf), NULL );
4335 if ( rc != LDAP_SUCCESS ) {
4336 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4337 "DN=\"%s\" no structural objectClass (%s)\n",
4338 log_prefix, e->e_name.bv_val, text );
4341 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
4342 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4343 if ( soc_at == NULL ) {
4344 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4345 "DN=\"%s\" no structural objectClass; "
4346 "unable to merge computed class %s\n",
4347 log_prefix, e->e_name.bv_val,
4348 soc->soc_cname.bv_val );
4349 return LDAP_OBJECT_CLASS_VIOLATION;
4352 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4353 "DN=\"%s\" no structural objectClass; "
4354 "computed objectClass %s merged\n",
4355 log_prefix, e->e_name.bv_val,
4356 soc->soc_cname.bv_val );
4359 /* Fake the coordinates based on whether we're part of an
4360 * LDAP Add or if reading the config dir
4363 ca->fname = "slapd";
4366 ca->fname = cfdir.bv_val;
4371 co.co_name = &soc_at->a_nvals[0];
4372 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
4373 if ( coptr == NULL ) {
4374 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4375 "DN=\"%s\" no structural objectClass in configuration table\n",
4376 log_prefix, e->e_name.bv_val, 0 );
4377 return LDAP_OBJECT_CLASS_VIOLATION;
4380 /* Only the root can be Cft_Global, everything else must
4381 * have a parent. Only limited nesting arrangements are allowed.
4383 rc = LDAP_CONSTRAINT_VIOLATION;
4384 if ( coptr->co_type == Cft_Global && !last ) {
4385 cfn = cfb->cb_config;
4386 ca->ca_private = cfn;
4387 ca->be = frontendDB; /* just to get past check_vals */
4391 colst = count_ocs( oc_at, &nocs );
4393 /* Check whether the Add is allowed by its parent, and do
4394 * any necessary arg setup
4397 rc = config_add_oc( &coptr, last, e, ca );
4398 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4399 for ( i = 0; i<nocs; i++ ) {
4400 /* Already checked these */
4401 if ( colst[i]->co_oc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
4403 if ( colst[i]->co_ldadd &&
4404 ( rc = colst[i]->co_ldadd( last, e, ca ))
4405 != LDAP_CONSTRAINT_VIOLATION ) {
4411 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4412 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4413 "DN=\"%s\" no structural objectClass add function\n",
4414 log_prefix, e->e_name.bv_val, 0 );
4415 return LDAP_OBJECT_CLASS_VIOLATION;
4419 /* Add the entry but don't parse it, we already have its contents */
4420 if ( rc == LDAP_COMPARE_TRUE ) {
4425 if ( rc != LDAP_SUCCESS )
4428 /* Parse all the values and check for simple syntax errors before
4429 * performing any set actions.
4431 * If doing an LDAPadd, check for indexed names and any necessary
4432 * renaming/renumbering. Entries that don't need indexed names are
4433 * ignored. Entries that need an indexed name and arrive without one
4434 * are assigned to the end. Entries that arrive with an index may
4435 * cause the following entries to be renumbered/bumped down.
4437 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
4438 * don't allow Adding an entry with an index that's already in use.
4439 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
4441 * These entries can have auto-assigned indexes (appended to the end)
4442 * but only the other types support auto-renumbering of siblings.
4445 rc = check_name_index( last, coptr->co_type, e, rs, renum,
4450 if ( renum && *renum && coptr->co_type != Cft_Database &&
4451 coptr->co_type != Cft_Overlay )
4453 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
4454 "operation requires sibling renumbering" );
4455 rc = LDAP_UNWILLING_TO_PERFORM;
4460 init_config_argv( ca );
4462 /* Make sure we process attrs in the required order */
4463 sort_attrs( e, colst, nocs );
4465 for ( a = e->e_attrs; a; a = a->a_next ) {
4466 if ( a == oc_at ) continue;
4467 ct = config_find_table( colst, nocs, a->a_desc, ca );
4468 if ( !ct ) continue; /* user data? */
4469 rc = check_vals( ct, ca, a, 1 );
4470 if ( rc ) goto done_noop;
4473 /* Basic syntax checks are OK. Do the actual settings. */
4474 for ( a=e->e_attrs; a; a=a->a_next ) {
4475 if ( a == oc_at ) continue;
4476 ct = config_find_table( colst, nocs, a->a_desc, ca );
4477 if ( !ct ) continue; /* user data? */
4478 for (i=0; a->a_vals[i].bv_val; i++) {
4480 ca->line = a->a_vals[i].bv_val;
4481 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
4482 ptr = strchr( ca->line, '}' );
4484 iptr = strchr( ca->line, '{' );
4488 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
4490 ca->valx = strtol( iptr+1, NULL, 0 );
4497 rc = config_parse_add( ct, ca, i );
4505 /* Newly added databases and overlays need to be started up */
4506 if ( CONFIG_ONLINE_ADD( ca )) {
4507 if ( colst[0]->co_type == Cft_Database ) {
4508 rc = backend_startup_one( ca->be, &ca->reply );
4510 } else if ( colst[0]->co_type == Cft_Overlay ) {
4511 if ( ca->bi->bi_db_open ) {
4512 BackendInfo *bi_orig = ca->be->bd_info;
4513 ca->be->bd_info = ca->bi;
4514 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
4515 ca->be->bd_info = bi_orig;
4517 } else if ( ca->cleanup ) {
4518 rc = ca->cleanup( ca );
4521 if (ca->cr_msg[0] == '\0')
4522 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
4524 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
4525 ca->log, ca->cr_msg, ca->argv[1] );
4532 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
4533 ce->ce_parent = last;
4534 ce->ce_entry = entry_dup( e );
4535 ce->ce_entry->e_private = ce;
4536 ce->ce_type = colst[0]->co_type;
4539 ce->ce_private = ca->ca_private;
4540 ca->ca_entry = ce->ce_entry;
4543 } else if ( last->ce_kids ) {
4544 CfEntryInfo *c2, **cprev;
4546 /* Advance to first of this type */
4547 cprev = &last->ce_kids;
4548 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
4549 cprev = &c2->ce_sibs;
4552 /* Account for the (-1) frontendDB entry */
4553 if ( ce->ce_type == Cft_Database ) {
4554 if ( ca->be == frontendDB )
4556 else if ( ibase != -1 )
4561 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
4562 cprev = &c2->ce_sibs;
4568 for ( i=0; i<ibase; i++ ) {
4570 cprev = &c2->ce_sibs;
4573 ce->ce_sibs = *cprev;
4581 if ( (colst[0]->co_type == Cft_Database) && ca->be ) {
4582 if ( ca->be != frontendDB )
4583 backend_destroy_one( ca->be, 1 );
4584 } else if ( (colst[0]->co_type == Cft_Overlay) && ca->bi ) {
4585 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
4586 } else if ( colst[0]->co_type == Cft_Schema ) {
4587 schema_destroy_one( ca, colst, nocs, last );
4592 ch_free( ca->argv );
4593 if ( colst ) ch_free( colst );
4597 #define BIGTMP 10000
4599 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
4600 int base, int rebase, int max, int use_ldif )
4602 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
4603 ConfigType etype = ce->ce_type;
4604 int count = 0, rc = 0;
4606 /* Reverse ce list */
4607 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
4608 if (ce2->ce_type != etype) {
4613 ce2->ce_sibs = cetmp;
4616 if ( max && count >= max ) {
4622 /* Move original to a temp name until increments are done */
4624 ce->ce_entry->e_private = NULL;
4625 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4626 base+BIGTMP, 0, use_ldif );
4627 ce->ce_entry->e_private = ce;
4629 /* start incrementing */
4630 for (ce2=cetmp; ce2; ce2=ce3) {
4632 ce2->ce_sibs = cerem;
4635 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
4636 count+base, 0, use_ldif );
4640 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4641 base, 0, use_ldif );
4646 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
4647 CfEntryInfo *ce2, int old, int use_ldif )
4651 /* Renumber original to a temp value */
4652 ce->ce_entry->e_private = NULL;
4653 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4654 old+BIGTMP, 0, use_ldif );
4655 ce->ce_entry->e_private = ce;
4657 /* start decrementing */
4658 for (; ce2 != ce; ce2=ce2->ce_sibs) {
4659 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
4660 count+old, 0, use_ldif );
4663 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4664 count+old, 0, use_ldif );
4667 /* Parse an LDAP entry into config directives, then store in underlying
4671 config_back_add( Operation *op, SlapReply *rs )
4677 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
4678 NULL, ACL_WADD, NULL )) {
4679 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4684 * Check for attribute ACL
4686 if ( !acl_check_modlist( op, op->ora_e, op->orm_modlist )) {
4687 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4688 rs->sr_text = "no write access to attribute";
4692 cfb = (CfBackInfo *)op->o_bd->be_private;
4694 /* add opattrs for syncprov */
4696 char textbuf[SLAP_TEXT_BUFLEN];
4697 size_t textlen = sizeof textbuf;
4698 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1,
4699 &rs->sr_text, textbuf, sizeof( textbuf ) );
4700 if ( rs->sr_err != LDAP_SUCCESS )
4702 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
4703 if ( rs->sr_err != LDAP_SUCCESS ) {
4704 Debug( LDAP_DEBUG_TRACE,
4705 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
4706 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
4711 ldap_pvt_thread_pool_pause( &connection_pool );
4714 * 1) check for existence of entry
4715 * 2) check for sibling renumbering
4716 * 3) perform internal add
4717 * 4) perform any necessary renumbering
4718 * 5) store entry in underlying database
4720 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
4721 if ( rs->sr_err != LDAP_SUCCESS ) {
4722 rs->sr_text = ca.cr_msg;
4727 CfEntryInfo *ce = ca.ca_entry->e_private;
4728 req_add_s addr = op->oq_add;
4729 op->o_tag = LDAP_REQ_MODRDN;
4730 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
4731 op->o_tag = LDAP_REQ_ADD;
4733 if ( rs->sr_err != LDAP_SUCCESS ) {
4738 if ( cfb->cb_use_ldif ) {
4739 BackendDB *be = op->o_bd;
4740 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4741 struct berval dn, ndn;
4743 op->o_bd = &cfb->cb_db;
4745 /* Save current rootdn; use the underlying DB's rootdn */
4748 op->o_dn = op->o_bd->be_rootdn;
4749 op->o_ndn = op->o_bd->be_rootndn;
4751 scp = op->o_callback;
4752 op->o_callback = ≻
4753 op->o_bd->be_add( op, rs );
4755 op->o_callback = scp;
4761 ldap_pvt_thread_pool_resume( &connection_pool );
4764 send_ldap_result( op, rs );
4765 slap_graduate_commit_csn( op );
4769 typedef struct delrec {
4770 struct delrec *next;
4776 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
4781 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
4782 ca->line[0] == '{' )
4784 char *ptr = strchr( ca->line + 1, '}' );
4788 ca->valx = strtol( ca->line + 1, &next, 0 );
4789 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
4795 rc = config_parse_add( ct, ca, i );
4803 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
4806 int rc = LDAP_UNWILLING_TO_PERFORM;
4808 Entry *e = ce->ce_entry;
4809 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
4814 delrec *dels = NULL, *deltail = NULL;
4816 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4817 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
4819 colst = count_ocs( oc_at, &nocs );
4821 /* make sure add/del flags are clear; should always be true */
4822 for ( s = save_attrs; s; s = s->a_next ) {
4823 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
4826 e->e_attrs = attrs_dup( e->e_attrs );
4828 init_config_argv( ca );
4831 ca->ca_private = ce->ce_private;
4833 ca->fname = "slapd";
4835 strcpy( ca->log, "back-config" );
4837 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
4838 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
4839 switch (ml->sml_op) {
4840 case LDAP_MOD_DELETE:
4841 case LDAP_MOD_REPLACE: {
4842 BerVarray vals = NULL, nvals = NULL;
4844 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
4846 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
4847 ml->sml_desc->ad_cname.bv_val );
4850 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4851 vals = ml->sml_values;
4852 nvals = ml->sml_nvalues;
4853 ml->sml_values = NULL;
4854 ml->sml_nvalues = NULL;
4856 /* If we're deleting by values, remember the indexes of the
4857 * values we deleted.
4859 if ( ct && ml->sml_values ) {
4861 i = ml->sml_numvals;
4862 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
4873 rc = modify_delete_vindex(e, &ml->sml_mod,
4874 get_permissiveModify(op),
4875 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
4876 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4877 ml->sml_values = vals;
4878 ml->sml_nvalues = nvals;
4883 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
4886 case SLAP_MOD_SOFTADD: {
4887 int mop = ml->sml_op;
4889 ml->sml_op = LDAP_MOD_ADD;
4891 if ( ct->arg_type & ARG_NO_INSERT ) {
4892 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
4894 navals = a->a_numvals;
4897 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
4898 if ( ml->sml_values[i].bv_val[0] == '{' &&
4901 char *next, *val = ml->sml_values[i].bv_val + 1;
4904 j = strtol( val, &next, 0 );
4905 if ( next == val || next[ 0 ] != '}' || j < navals ) {
4907 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
4908 ml->sml_desc->ad_cname.bv_val );
4912 rc = check_vals( ct, ca, ml, 0 );
4913 if ( rc ) goto out_noop;
4916 rc = modify_add_values(e, &ml->sml_mod,
4917 get_permissiveModify(op),
4918 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
4920 /* If value already exists, show success here
4921 * and ignore this operation down below.
4923 if ( mop == SLAP_MOD_SOFTADD ) {
4924 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
4934 case LDAP_MOD_INCREMENT: /* FIXME */
4939 if(rc != LDAP_SUCCESS) break;
4942 if ( rc == LDAP_SUCCESS) {
4943 /* check that the entry still obeys the schema */
4944 rc = entry_schema_check(op, e, NULL, 0, 0,
4945 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
4947 if ( rc ) goto out_noop;
4949 /* Basic syntax checks are OK. Do the actual settings. */
4950 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
4951 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
4952 if ( !ct ) continue;
4954 s = attr_find( save_attrs, ml->sml_desc );
4955 a = attr_find( e->e_attrs, ml->sml_desc );
4957 switch (ml->sml_op) {
4958 case LDAP_MOD_DELETE:
4959 case LDAP_MOD_REPLACE: {
4960 BerVarray vals = NULL, nvals = NULL;
4963 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4964 vals = ml->sml_values;
4965 nvals = ml->sml_nvalues;
4966 ml->sml_values = NULL;
4967 ml->sml_nvalues = NULL;
4970 if ( ml->sml_values )
4973 /* If we didn't delete the whole attribute */
4974 if ( ml->sml_values && a ) {
4975 struct berval *mvals;
4978 if ( ml->sml_nvalues )
4979 mvals = ml->sml_nvalues;
4981 mvals = ml->sml_values;
4983 /* use the indexes we saved up above */
4984 for (i=0; i < d->nidx; i++) {
4985 struct berval bv = *mvals++;
4986 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
4987 bv.bv_val[0] == '{' ) {
4988 ptr = strchr( bv.bv_val, '}' ) + 1;
4989 bv.bv_len -= ptr - bv.bv_val;
4992 ca->line = bv.bv_val;
4993 ca->valx = d->idx[i];
4994 rc = config_del_vals( ct, ca );
4995 if ( rc != LDAP_SUCCESS ) break;
4997 s->a_flags |= SLAP_ATTR_IXDEL;
4998 for (j=i+1; j < d->nidx; j++)
4999 if ( d->idx[j] >d->idx[i] )
5005 rc = config_del_vals( ct, ca );
5006 if ( rc ) rc = LDAP_OTHER;
5008 s->a_flags |= SLAP_ATTR_IXDEL;
5010 if ( ml->sml_values ) {
5015 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5016 ml->sml_values = vals;
5017 ml->sml_nvalues = nvals;
5019 if ( !vals || rc != LDAP_SUCCESS )
5022 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5025 for (i=0; ml->sml_values[i].bv_val; i++) {
5026 ca->line = ml->sml_values[i].bv_val;
5028 rc = config_modify_add( ct, ca, ml->sml_desc, i );
5031 a->a_flags |= SLAP_ATTR_IXADD;
5038 /* Undo for a failed operation */
5039 if ( rc != LDAP_SUCCESS ) {
5040 ConfigReply msg = ca->reply;
5041 for ( s = save_attrs; s; s = s->a_next ) {
5042 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
5043 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5044 ct = config_find_table( colst, nocs, s->a_desc, ca );
5045 a = attr_find( e->e_attrs, s->a_desc );
5047 /* clear the flag so the add check below will skip it */
5048 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5051 config_del_vals( ct, ca );
5053 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5054 ca->line = s->a_vals[i].bv_val;
5056 config_modify_add( ct, ca, s->a_desc, i );
5060 for ( a = e->e_attrs; a; a = a->a_next ) {
5061 if ( a->a_flags & SLAP_ATTR_IXADD ) {
5062 ct = config_find_table( colst, nocs, a->a_desc, ca );
5065 config_del_vals( ct, ca );
5066 s = attr_find( save_attrs, a->a_desc );
5068 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5069 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5070 ca->line = s->a_vals[i].bv_val;
5072 config_modify_add( ct, ca, s->a_desc, i );
5083 if ( rc == LDAP_SUCCESS ) {
5084 attrs_free( save_attrs );
5086 attrs_free( e->e_attrs );
5087 e->e_attrs = save_attrs;
5089 ch_free( ca->argv );
5090 if ( colst ) ch_free( colst );
5092 deltail = dels->next;
5101 config_back_modify( Operation *op, SlapReply *rs )
5104 CfEntryInfo *ce, *last;
5106 ConfigArgs ca = {0};
5109 AttributeDescription *rad = NULL;
5112 cfb = (CfBackInfo *)op->o_bd->be_private;
5114 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5117 rs->sr_matched = last->ce_entry->e_name.bv_val;
5118 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5122 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
5123 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5127 /* Get type of RDN */
5128 rdn = ce->ce_entry->e_nname;
5129 ptr = strchr( rdn.bv_val, '=' );
5130 rdn.bv_len = ptr - rdn.bv_val;
5131 slap_bv2ad( &rdn, &rad, &rs->sr_text );
5133 /* Some basic validation... */
5134 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5135 /* Don't allow Modify of RDN; must use ModRdn for that. */
5136 if ( ml->sml_desc == rad ) {
5137 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
5138 rs->sr_text = "Use modrdn to change the entry name";
5141 /* Internal update of contextCSN? */
5142 if ( ml->sml_desc == slap_schema.si_ad_contextCSN && op->o_conn->c_conn_idx == -1 ) {
5148 slap_mods_opattrs( op, &op->orm_modlist, 1 );
5151 ldap_pvt_thread_pool_pause( &connection_pool );
5154 * 1) perform the Modify on the cached Entry.
5155 * 2) verify that the Entry still satisfies the schema.
5156 * 3) perform the individual config operations.
5157 * 4) store Modified entry in underlying LDIF backend.
5159 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
5161 rs->sr_text = ca.cr_msg;
5162 } else if ( cfb->cb_use_ldif ) {
5163 BackendDB *be = op->o_bd;
5164 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5165 struct berval dn, ndn;
5167 op->o_bd = &cfb->cb_db;
5171 op->o_dn = op->o_bd->be_rootdn;
5172 op->o_ndn = op->o_bd->be_rootndn;
5174 scp = op->o_callback;
5175 op->o_callback = ≻
5176 op->o_bd->be_modify( op, rs );
5178 op->o_callback = scp;
5184 ldap_pvt_thread_pool_resume( &connection_pool );
5186 send_ldap_result( op, rs );
5187 slap_graduate_commit_csn( op );
5192 config_back_modrdn( Operation *op, SlapReply *rs )
5195 CfEntryInfo *ce, *last;
5199 cfb = (CfBackInfo *)op->o_bd->be_private;
5201 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5204 rs->sr_matched = last->ce_entry->e_name.bv_val;
5205 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5208 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
5209 NULL, ACL_WRITE, NULL )) {
5210 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5214 if ( ce->ce_parent )
5215 parent = ce->ce_parent->ce_entry;
5217 parent = (Entry *)&slap_entry_root;
5218 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
5219 NULL, ACL_WRITE, NULL )) {
5220 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5225 /* We don't allow moving objects to new parents.
5226 * Generally we only allow reordering a set of ordered entries.
5228 if ( op->orr_newSup ) {
5229 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5233 /* If newRDN == oldRDN, quietly succeed */
5234 dnRdn( &op->o_req_ndn, &rdn );
5235 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
5236 rs->sr_err = LDAP_SUCCESS;
5240 /* Current behavior, subject to change as needed:
5242 * For backends and overlays, we only allow renumbering.
5243 * For schema, we allow renaming with the same number.
5244 * Otherwise, the op is not allowed.
5247 if ( ce->ce_type == Cft_Schema ) {
5251 /* Can't alter the main cn=schema entry */
5252 if ( ce->ce_parent->ce_type == Cft_Global ) {
5253 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5254 rs->sr_text = "renaming not allowed for this entry";
5258 /* We could support this later if desired */
5259 ptr1 = ber_bvchr( &rdn, '}' );
5260 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5261 len = ptr1 - rdn.bv_val;
5262 if ( len != ptr2 - op->orr_newrdn.bv_val ||
5263 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
5264 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5265 rs->sr_text = "schema reordering not supported";
5268 } else if ( ce->ce_type == Cft_Database ||
5269 ce->ce_type == Cft_Overlay ) {
5270 char *ptr1, *ptr2, *iptr1, *iptr2;
5273 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
5274 if ( *iptr2 != '{' ) {
5275 rs->sr_err = LDAP_NAMING_VIOLATION;
5276 rs->sr_text = "new ordering index is required";
5280 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
5281 ptr1 = ber_bvchr( &rdn, '}' );
5282 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5284 rs->sr_err = LDAP_NAMING_VIOLATION;
5285 rs->sr_text = "new ordering index is required";
5289 len1 = ptr1 - rdn.bv_val;
5290 len2 = ptr2 - op->orr_newrdn.bv_val;
5292 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
5293 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
5294 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5295 rs->sr_text = "changing database/overlay type not allowed";
5298 ixold = strtol( iptr1, NULL, 0 );
5299 ixnew = strtol( iptr2, &ptr1, 0 );
5300 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
5301 rs->sr_err = LDAP_NAMING_VIOLATION;
5304 /* config DB is always 0, cannot be changed */
5305 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
5306 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
5310 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5311 rs->sr_text = "renaming not supported for this entry";
5315 ldap_pvt_thread_pool_pause( &connection_pool );
5317 if ( ce->ce_type == Cft_Schema ) {
5318 req_modrdn_s modr = op->oq_modrdn;
5321 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
5322 if ( rs->sr_err == LDAP_SUCCESS ) {
5323 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
5324 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
5327 op->oq_modrdn = modr;
5329 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
5330 req_modrdn_s modr = op->oq_modrdn;
5333 /* Advance to first of this type */
5334 cprev = &ce->ce_parent->ce_kids;
5335 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
5336 cprev = &ce2->ce_sibs;
5339 /* Skip the -1 entry */
5340 if ( ce->ce_type == Cft_Database ) {
5341 cprev = &ce2->ce_sibs;
5347 /* Remove from old slot */
5348 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
5349 cprev = &ce2->ce_sibs;
5350 *cprev = ce->ce_sibs;
5351 ceold = ce->ce_sibs;
5353 /* Insert into new slot */
5355 for ( i=0; i<ixnew; i++ ) {
5359 cprev = &ce2->ce_sibs;
5361 ce->ce_sibs = *cprev;
5366 /* NOTE: These should be encoded in the OC tables, not inline here */
5367 if ( ce->ce_type == Cft_Database )
5368 backend_db_move( ce->ce_be, ixnew );
5369 else if ( ce->ce_type == Cft_Overlay )
5370 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
5372 if ( ixold < ixnew ) {
5373 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
5376 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
5377 ixold - ixnew, cfb->cb_use_ldif );
5379 op->oq_modrdn = modr;
5382 ldap_pvt_thread_pool_resume( &connection_pool );
5384 send_ldap_result( op, rs );
5389 config_back_delete( Operation *op, SlapReply *rs )
5391 #ifdef SLAP_CONFIG_DELETE
5393 CfEntryInfo *ce, *last, *ce2;
5395 cfb = (CfBackInfo *)op->o_bd->be_private;
5397 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5400 rs->sr_matched = last->ce_entry->e_name.bv_val;
5401 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5402 } else if ( ce->ce_kids ) {
5403 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5404 } else if ( ce->ce_type == Cft_Overlay || ce->ce_type == Cft_Database ){
5408 ldap_pvt_thread_pool_pause( &connection_pool );
5410 if ( ce->ce_type == Cft_Overlay ){
5411 overlay_remove( ce->ce_be, (slap_overinst *)ce->ce_bi );
5412 } else { /* Cft_Database*/
5413 if ( ce->ce_be == frontendDB || ce->ce_be == op->o_bd ){
5414 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5415 rs->sr_text = "Cannot delete config or frontend database";
5416 ldap_pvt_thread_pool_resume( &connection_pool );
5419 if ( ce->ce_be->bd_info->bi_db_close ) {
5420 ce->ce_be->bd_info->bi_db_close( ce->ce_be, NULL );
5422 backend_destroy_one( ce->ce_be, 1);
5425 /* remove CfEntryInfo from the siblings list */
5426 if ( ce->ce_parent->ce_kids == ce ) {
5427 ce->ce_parent->ce_kids = ce->ce_sibs;
5429 for ( ce2 = ce->ce_parent->ce_kids ; ce2; ce2 = ce2->ce_sibs ) {
5430 if ( ce2->ce_sibs == ce ) {
5431 ce2->ce_sibs = ce->ce_sibs;
5437 /* remove from underlying database */
5438 if ( cfb->cb_use_ldif ) {
5439 BackendDB *be = op->o_bd;
5440 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5441 struct berval dn, ndn, req_dn, req_ndn;
5443 op->o_bd = &cfb->cb_db;
5447 req_dn = op->o_req_dn;
5448 req_ndn = op->o_req_ndn;
5450 op->o_dn = op->o_bd->be_rootdn;
5451 op->o_ndn = op->o_bd->be_rootndn;
5452 op->o_req_dn = ce->ce_entry->e_name;
5453 op->o_req_ndn = ce->ce_entry->e_nname;
5455 scp = op->o_callback;
5456 op->o_callback = ≻
5457 op->o_bd->be_delete( op, rs );
5459 op->o_callback = scp;
5462 op->o_req_dn = req_dn;
5463 op->o_req_ndn = req_ndn;
5466 /* renumber siblings */
5467 iptr = ber_bvchr( &op->o_req_ndn, '{' ) + 1;
5468 ixold = strtol( iptr, NULL, 0 );
5469 for (ce2 = ce->ce_sibs, count=0; ce2; ce2=ce2->ce_sibs) {
5470 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5471 count+ixold, 0, cfb->cb_use_ldif );
5475 ce->ce_entry->e_private=NULL;
5476 entry_free(ce->ce_entry);
5478 ldap_pvt_thread_pool_resume( &connection_pool );
5480 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5483 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5484 #endif /* SLAP_CONFIG_DELETE */
5486 send_ldap_result( op, rs );
5491 config_back_search( Operation *op, SlapReply *rs )
5494 CfEntryInfo *ce, *last;
5497 cfb = (CfBackInfo *)op->o_bd->be_private;
5499 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5502 rs->sr_matched = last->ce_entry->e_name.bv_val;
5503 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5506 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
5507 ACL_SEARCH, NULL, &mask ))
5509 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
5510 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5512 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5516 switch ( op->ors_scope ) {
5517 case LDAP_SCOPE_BASE:
5518 case LDAP_SCOPE_SUBTREE:
5519 rs->sr_err = config_send( op, rs, ce, 0 );
5522 case LDAP_SCOPE_ONELEVEL:
5523 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
5524 rs->sr_err = config_send( op, rs, ce, 1 );
5533 send_ldap_result( op, rs );
5537 /* no-op, we never free entries */
5538 int config_entry_release(
5543 if ( !e->e_private ) {
5546 return LDAP_SUCCESS;
5549 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
5551 int config_back_entry_get(
5555 AttributeDescription *at,
5560 CfEntryInfo *ce, *last;
5561 int rc = LDAP_NO_SUCH_OBJECT;
5563 cfb = (CfBackInfo *)op->o_bd->be_private;
5565 ce = config_find_base( cfb->cb_root, ndn, &last );
5567 *ent = ce->ce_entry;
5570 if ( oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
5571 rc = LDAP_NO_SUCH_ATTRIBUTE;
5581 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
5582 ConfigTable *ct, ConfigArgs *c )
5586 for (; at && *at; at++) {
5587 /* Skip the naming attr */
5588 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
5590 for (i=0;ct[i].name;i++) {
5591 if (ct[i].ad == (*at)->sat_ad) {
5592 rc = config_get_vals(&ct[i], c);
5593 /* NOTE: tolerate that config_get_vals()
5594 * returns success with no values */
5595 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
5596 if ( c->rvalue_nvals )
5597 rc = attr_merge(e, ct[i].ad, c->rvalue_vals,
5600 slap_syntax_validate_func *validate =
5601 ct[i].ad->ad_type->sat_syntax->ssyn_validate;
5604 for ( j=0; c->rvalue_vals[j].bv_val; j++ ) {
5605 rc = ordered_value_validate( ct[i].ad,
5606 &c->rvalue_vals[j], LDAP_MOD_ADD );
5608 Debug( LDAP_DEBUG_ANY,
5609 "config_build_attrs: error %d on %s value #%d\n",
5610 rc, ct[i].ad->ad_cname.bv_val, j );
5616 rc = attr_merge_normalize(e, ct[i].ad,
5617 c->rvalue_vals, NULL);
5619 ber_bvarray_free( c->rvalue_nvals );
5620 ber_bvarray_free( c->rvalue_vals );
5622 Debug( LDAP_DEBUG_ANY,
5623 "config_build_attrs: error %d on %s\n",
5624 rc, ct[i].ad->ad_cname.bv_val, 0 );
5636 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
5637 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
5639 Entry *e = entry_alloc();
5640 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5642 struct berval ad_name;
5643 AttributeDescription *ad = NULL;
5646 const char *text = "";
5650 CfEntryInfo *ceprev = NULL;
5652 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
5655 ce->ce_type = main->co_type;
5656 ce->ce_parent = parent;
5658 pdn = parent->ce_entry->e_nname;
5659 if ( parent->ce_kids && parent->ce_kids->ce_type <= ce->ce_type )
5660 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
5661 ceprev->ce_type <= ce->ce_type;
5662 ceprev = ceprev->ce_sibs );
5667 ce->ce_private = c->ca_private;
5671 build_new_dn( &e->e_name, &pdn, rdn, NULL );
5672 ber_dupbv( &e->e_nname, &e->e_name );
5674 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
5675 main->co_name, NULL );
5677 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
5678 extra->co_name, NULL );
5679 ptr = strchr(rdn->bv_val, '=');
5680 ad_name.bv_val = rdn->bv_val;
5681 ad_name.bv_len = ptr - rdn->bv_val;
5682 rc = slap_bv2ad( &ad_name, &ad, &text );
5687 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
5688 attr_merge_normalize_one(e, ad, &val, NULL );
5691 c->table = main->co_type;
5692 if ( oc->soc_required ) {
5693 rc = config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
5694 if ( rc ) goto fail;
5697 if ( oc->soc_allowed ) {
5698 rc = config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
5699 if ( rc ) goto fail;
5704 c->table = extra->co_type;
5705 if ( oc->soc_required ) {
5706 rc = config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
5707 if ( rc ) goto fail;
5710 if ( oc->soc_allowed ) {
5711 rc = config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
5712 if ( rc ) goto fail;
5716 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5717 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
5718 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
5719 if ( rc != LDAP_SUCCESS ) {
5721 Debug( LDAP_DEBUG_ANY,
5722 "config_build_entry: build \"%s\" failed: \"%s\"\n",
5723 rdn->bv_val, text, 0);
5726 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
5729 op->ora_modlist = NULL;
5730 slap_add_opattrs( op, NULL, NULL, 0, 0 );
5731 if ( !op->o_noop ) {
5732 op->o_bd->be_add( op, rs );
5733 if ( ( rs->sr_err != LDAP_SUCCESS )
5734 && (rs->sr_err != LDAP_ALREADY_EXISTS) ) {
5740 ce->ce_sibs = ceprev->ce_sibs;
5741 ceprev->ce_sibs = ce;
5742 } else if ( parent ) {
5743 ce->ce_sibs = parent->ce_kids;
5744 parent->ce_kids = ce;
5751 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
5752 Operation *op, SlapReply *rs )
5755 ConfigFile *cf = c->ca_private;
5757 struct berval bv, rdn;
5759 for (; cf; cf=cf->c_sibs, c->depth++) {
5760 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
5761 !cf->c_om_head && !cf->c_syn_head ) continue;
5762 c->value_dn.bv_val = c->log;
5763 LUTIL_SLASHPATH( cf->c_file.bv_val );
5764 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
5769 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
5771 ptr = strchr( bv.bv_val, '.' );
5773 bv.bv_len = ptr - bv.bv_val;
5774 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
5775 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
5776 /* FIXME: how can indicate error? */
5779 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
5781 c->value_dn.bv_len += bv.bv_len;
5782 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
5786 e = config_build_entry( op, rs, ceparent, c, &rdn,
5787 &CFOC_SCHEMA, NULL );
5790 } else if ( e && cf->c_kids ) {
5791 c->ca_private = cf->c_kids;
5792 config_build_schema_inc( c, e->e_private, op, rs );
5798 #ifdef SLAPD_MODULES
5801 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
5802 Operation *op, SlapReply *rs )
5807 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
5808 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
5810 c->value_dn.bv_val = c->log;
5811 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
5812 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
5813 /* FIXME: how can indicate error? */
5817 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
5826 config_check_schema(Operation *op, CfBackInfo *cfb)
5828 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
5830 CfEntryInfo *ce, *last;
5833 /* If there's no root entry, we must be in the midst of converting */
5834 if ( !cfb->cb_root )
5837 /* Make sure the main schema entry exists */
5838 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
5845 /* Make sure it's up to date */
5846 if ( cf_om_tail != om_sys_tail ) {
5847 a = attr_find( e->e_attrs, cfAd_om );
5849 if ( a->a_nvals != a->a_vals )
5850 ber_bvarray_free( a->a_nvals );
5851 ber_bvarray_free( a->a_vals );
5856 oidm_unparse( &bv, NULL, NULL, 1 );
5857 attr_merge_normalize( e, cfAd_om, bv, NULL );
5858 ber_bvarray_free( bv );
5859 cf_om_tail = om_sys_tail;
5861 if ( cf_at_tail != at_sys_tail ) {
5862 a = attr_find( e->e_attrs, cfAd_attr );
5864 if ( a->a_nvals != a->a_vals )
5865 ber_bvarray_free( a->a_nvals );
5866 ber_bvarray_free( a->a_vals );
5871 at_unparse( &bv, NULL, NULL, 1 );
5872 attr_merge_normalize( e, cfAd_attr, bv, NULL );
5873 ber_bvarray_free( bv );
5874 cf_at_tail = at_sys_tail;
5876 if ( cf_oc_tail != oc_sys_tail ) {
5877 a = attr_find( e->e_attrs, cfAd_oc );
5879 if ( a->a_nvals != a->a_vals )
5880 ber_bvarray_free( a->a_nvals );
5881 ber_bvarray_free( a->a_vals );
5886 oc_unparse( &bv, NULL, NULL, 1 );
5887 attr_merge_normalize( e, cfAd_oc, bv, NULL );
5888 ber_bvarray_free( bv );
5889 cf_oc_tail = oc_sys_tail;
5891 if ( cf_syn_tail != syn_sys_tail ) {
5892 a = attr_find( e->e_attrs, cfAd_syntax );
5894 if ( a->a_nvals != a->a_vals )
5895 ber_bvarray_free( a->a_nvals );
5896 ber_bvarray_free( a->a_vals );
5901 syn_unparse( &bv, NULL, NULL, 1 );
5902 attr_merge_normalize( e, cfAd_syntax, bv, NULL );
5903 ber_bvarray_free( bv );
5904 cf_syn_tail = syn_sys_tail;
5907 SlapReply rs = {REP_RESULT};
5908 c.ca_private = NULL;
5909 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
5910 &CFOC_SCHEMA, NULL );
5915 ce->ce_private = cfb->cb_config;
5916 cf_at_tail = at_sys_tail;
5917 cf_oc_tail = oc_sys_tail;
5918 cf_om_tail = om_sys_tail;
5919 cf_syn_tail = syn_sys_tail;
5924 static const char *defacl[] = {
5925 NULL, "to", "*", "by", "*", "none", NULL
5929 config_back_db_open( BackendDB *be, ConfigReply *cr )
5931 CfBackInfo *cfb = be->be_private;
5934 CfEntryInfo *ce, *ceparent;
5938 Connection conn = {0};
5939 OperationBuffer opbuf;
5941 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
5942 SlapReply rs = {REP_RESULT};
5943 void *thrctx = NULL;
5945 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
5947 /* If we have no explicitly configured ACLs, don't just use
5948 * the global ACLs. Explicitly deny access to everything.
5950 if ( !be->be_acl ) {
5951 parse_acl(be, "config_back_db_open", 0, 6, (char **)defacl, 0 );
5954 thrctx = ldap_pvt_thread_pool_context();
5955 connection_fake_init( &conn, &opbuf, thrctx );
5958 op->o_tag = LDAP_REQ_ADD;
5959 op->o_callback = &cb;
5960 op->o_bd = &cfb->cb_db;
5961 op->o_dn = op->o_bd->be_rootdn;
5962 op->o_ndn = op->o_bd->be_rootndn;
5964 if ( !cfb->cb_use_ldif ) {
5968 /* If we read the config from back-ldif, do some quick sanity checks */
5969 if ( cfb->cb_got_ldif ) {
5970 return config_check_schema( op, cfb );
5973 /* create root of tree */
5975 c.ca_private = cfb->cb_config;
5977 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
5987 #ifdef SLAPD_MODULES
5988 /* Create Module nodes... */
5989 if ( modpaths.mp_loads ) {
5990 if ( config_build_modules( &c, ceparent, op, &rs ) ){
5996 /* Create schema nodes... cn=schema will contain the hardcoded core
5997 * schema, read-only. Child objects will contain runtime loaded schema
6001 c.ca_private = NULL;
6002 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
6007 ce->ce_private = cfb->cb_config;
6008 cf_at_tail = at_sys_tail;
6009 cf_oc_tail = oc_sys_tail;
6010 cf_om_tail = om_sys_tail;
6011 cf_syn_tail = syn_sys_tail;
6013 /* Create schema nodes for included schema... */
6014 if ( cfb->cb_config->c_kids ) {
6016 c.ca_private = cfb->cb_config->c_kids;
6017 if (config_build_schema_inc( &c, ce, op, &rs )) {
6022 /* Create backend nodes. Skip if they don't provide a cf_table.
6023 * There usually aren't any of these.
6027 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
6028 if (!bi->bi_cf_ocs) {
6029 /* If it only supports the old config mech, complain. */
6030 if ( bi->bi_config ) {
6031 Debug( LDAP_DEBUG_ANY,
6032 "WARNING: No dynamic config support for backend %s.\n",
6033 bi->bi_type, 0, 0 );
6038 if (!bi->bi_private) continue;
6041 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6042 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
6043 if ( rdn.bv_len >= sizeof( c.log ) ) {
6044 /* FIXME: holler ... */ ;
6047 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
6054 /* Create database nodes... */
6055 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
6056 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
6057 for ( i = -1, be = frontendDB ; be;
6058 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
6059 slap_overinfo *oi = NULL;
6061 if ( overlay_is_over( be )) {
6062 oi = be->bd_info->bi_private;
6068 /* If this backend supports the old config mechanism, but not
6069 * the new mech, complain.
6071 if ( !be->be_cf_ocs && bi->bi_db_config ) {
6072 Debug( LDAP_DEBUG_ANY,
6073 "WARNING: No dynamic config support for database %s.\n",
6074 bi->bi_type, 0, 0 );
6078 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6079 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
6081 if ( rdn.bv_len >= sizeof( c.log ) ) {
6082 /* FIXME: holler ... */ ;
6086 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
6092 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd )
6093 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
6094 /* Iterate through overlays */
6099 voidList *vl, *v0 = NULL;
6101 /* overlays are in LIFO order, must reverse stack */
6102 for (on=oi->oi_list; on; on=on->on_next) {
6103 vl = ch_malloc( sizeof( voidList ));
6108 for (j=0; vl; j++,vl=v0) {
6112 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
6113 Debug( LDAP_DEBUG_ANY,
6114 "WARNING: No dynamic config support for overlay %s.\n",
6115 on->on_bi.bi_type, 0, 0 );
6119 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6120 "%s=" SLAP_X_ORDERED_FMT "%s",
6121 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
6122 if ( rdn.bv_len >= sizeof( c.log ) ) {
6123 /* FIXME: holler ... */ ;
6127 oe = config_build_entry( op, &rs, ce, &c, &rdn,
6128 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
6132 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd )
6133 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
6138 ldap_pvt_thread_pool_context_reset( thrctx );
6140 if ( unsupp && cfb->cb_use_ldif ) {
6141 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
6142 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
6149 cfb_free_cffile( ConfigFile *cf )
6153 for (; cf; cf=next) {
6156 cfb_free_cffile( cf->c_kids );
6157 ch_free( cf->c_file.bv_val );
6158 ber_bvarray_free( cf->c_dseFiles );
6164 cfb_free_entries( CfEntryInfo *ce )
6168 for (; ce; ce=next) {
6171 cfb_free_entries( ce->ce_kids );
6172 ce->ce_entry->e_private = NULL;
6173 entry_free( ce->ce_entry );
6179 config_back_db_close( BackendDB *be, ConfigReply *cr )
6181 CfBackInfo *cfb = be->be_private;
6183 cfb_free_entries( cfb->cb_root );
6184 cfb->cb_root = NULL;
6186 if ( cfb->cb_db.bd_info ) {
6187 backend_shutdown( &cfb->cb_db );
6194 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
6196 CfBackInfo *cfb = be->be_private;
6198 cfb_free_cffile( cfb->cb_config );
6200 ch_free( cfdir.bv_val );
6202 avl_free( CfOcTree, NULL );
6204 if ( cfb->cb_db.bd_info ) {
6205 cfb->cb_db.be_suffix = NULL;
6206 cfb->cb_db.be_nsuffix = NULL;
6207 BER_BVZERO( &cfb->cb_db.be_rootdn );
6208 BER_BVZERO( &cfb->cb_db.be_rootndn );
6210 backend_destroy_one( &cfb->cb_db, 0 );
6219 config_back_db_init( BackendDB *be, ConfigReply* cr )
6225 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
6226 cfn = cfb->cb_config;
6227 be->be_private = cfb;
6229 ber_dupbv( &be->be_rootdn, &config_rdn );
6230 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
6231 ber_dupbv( &dn, &be->be_rootdn );
6232 ber_bvarray_add( &be->be_suffix, &dn );
6233 ber_dupbv( &dn, &be->be_rootdn );
6234 ber_bvarray_add( &be->be_nsuffix, &dn );
6236 /* Hide from namingContexts */
6237 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
6239 /* Check ACLs on content of Adds by default */
6240 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_ACL_ADD;
6246 config_back_destroy( BackendInfo *bi )
6248 ldif_must_b64_encode_release();
6253 config_tool_entry_open( BackendDB *be, int mode )
6255 CfBackInfo *cfb = be->be_private;
6256 BackendInfo *bi = cfb->cb_db.bd_info;
6258 if ( bi && bi->bi_tool_entry_open )
6259 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
6266 config_tool_entry_close( BackendDB *be )
6268 CfBackInfo *cfb = be->be_private;
6269 BackendInfo *bi = cfb->cb_db.bd_info;
6271 if ( bi && bi->bi_tool_entry_close )
6272 return bi->bi_tool_entry_close( &cfb->cb_db );
6278 config_tool_entry_first( BackendDB *be )
6280 CfBackInfo *cfb = be->be_private;
6281 BackendInfo *bi = cfb->cb_db.bd_info;
6283 if ( bi && bi->bi_tool_entry_first )
6284 return bi->bi_tool_entry_first( &cfb->cb_db );
6290 config_tool_entry_next( BackendDB *be )
6292 CfBackInfo *cfb = be->be_private;
6293 BackendInfo *bi = cfb->cb_db.bd_info;
6295 if ( bi && bi->bi_tool_entry_next )
6296 return bi->bi_tool_entry_next( &cfb->cb_db );
6302 config_tool_entry_get( BackendDB *be, ID id )
6304 CfBackInfo *cfb = be->be_private;
6305 BackendInfo *bi = cfb->cb_db.bd_info;
6307 if ( bi && bi->bi_tool_entry_get )
6308 return bi->bi_tool_entry_get( &cfb->cb_db, id );
6313 static int entry_put_got_frontend=0;
6314 static int entry_put_got_config=0;
6316 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
6318 CfBackInfo *cfb = be->be_private;
6319 BackendInfo *bi = cfb->cb_db.bd_info;
6321 struct berval rdn, vals[ 2 ];
6323 OperationBuffer opbuf;
6325 Connection conn = {0};
6326 Operation *op = NULL;
6330 /* Create entry for frontend database if it does not exist already */
6331 if ( !entry_put_got_frontend ) {
6332 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
6333 STRLENOF( "olcDatabase" ))) {
6334 if ( strncmp( e->e_nname.bv_val +
6335 STRLENOF( "olcDatabase" ), "={-1}frontend",
6336 STRLENOF( "={-1}frontend" )) &&
6337 strncmp( e->e_nname.bv_val +
6338 STRLENOF( "olcDatabase" ), "=frontend",
6339 STRLENOF( "=frontend" ))) {
6341 vals[1].bv_val = NULL;
6342 memset( &ca, 0, sizeof(ConfigArgs));
6344 ca.bi = frontendDB->bd_info;
6345 ca.be->be_cf_ocs = &CFOC_FRONTEND;
6346 rdn.bv_val = ca.log;
6347 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
6348 "%s=" SLAP_X_ORDERED_FMT "%s",
6349 cfAd_database->ad_cname.bv_val, -1,
6351 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
6352 &CFOC_DATABASE, ca.be->be_cf_ocs );
6353 thrctx = ldap_pvt_thread_pool_context();
6354 connection_fake_init2( &conn, &opbuf, thrctx,0 );
6356 op->o_bd = &cfb->cb_db;
6357 op->o_tag = LDAP_REQ_ADD;
6359 op->o_dn = be->be_rootdn;
6360 op->o_ndn = be->be_rootndn;
6361 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
6362 if ( rc != LDAP_SUCCESS ) {
6363 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
6364 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
6368 if ( ce && bi && bi->bi_tool_entry_put &&
6369 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
6370 entry_put_got_frontend++;
6372 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
6373 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
6377 entry_put_got_frontend++;
6382 /* Create entry for config database if it does not exist already */
6383 if ( !entry_put_got_config && !isFrontend ) {
6384 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
6385 STRLENOF( "olcDatabase" ))) {
6386 if ( strncmp( e->e_nname.bv_val +
6387 STRLENOF( "olcDatabase" ), "={0}config",
6388 STRLENOF( "={0}config" )) &&
6389 strncmp( e->e_nname.bv_val +
6390 STRLENOF( "olcDatabase" ), "=config",
6391 STRLENOF( "=config" )) ) {
6393 vals[1].bv_val = NULL;
6394 memset( &ca, 0, sizeof(ConfigArgs));
6395 ca.be = LDAP_STAILQ_FIRST( &backendDB );
6396 ca.bi = ca.be->bd_info;
6397 rdn.bv_val = ca.log;
6398 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
6399 "%s=" SLAP_X_ORDERED_FMT "%s",
6400 cfAd_database->ad_cname.bv_val, 0,
6402 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
6405 thrctx = ldap_pvt_thread_pool_context();
6406 connection_fake_init2( &conn, &opbuf, thrctx,0 );
6408 op->o_bd = &cfb->cb_db;
6409 op->o_tag = LDAP_REQ_ADD;
6410 op->o_dn = be->be_rootdn;
6411 op->o_ndn = be->be_rootndn;
6414 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
6415 if ( rc != LDAP_SUCCESS ) {
6416 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
6417 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
6420 if (ce && bi && bi->bi_tool_entry_put &&
6421 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
6422 entry_put_got_config++;
6424 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
6425 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
6429 entry_put_got_config++;
6433 if ( bi && bi->bi_tool_entry_put &&
6434 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
6435 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
6442 AttributeDescription **desc;
6444 { "attribute", &cfAd_attr },
6445 { "backend", &cfAd_backend },
6446 { "database", &cfAd_database },
6447 { "include", &cfAd_include },
6448 { "ldapsyntax", &cfAd_syntax },
6449 { "objectclass", &cfAd_oc },
6450 { "objectidentifier", &cfAd_om },
6451 { "overlay", &cfAd_overlay },
6456 * add / delete: all types that may be added or deleted must use an
6457 * X-ORDERED attributeType for their RDN. Adding and deleting entries
6458 * should automatically renumber the index of any siblings as needed,
6459 * so that no gaps in the numbering sequence exist after the add/delete
6461 * What can be added:
6463 * backend objects for backend-specific config directives
6467 * delete: probably no support this time around.
6469 * modrdn: generally not done. Will be invoked automatically by add/
6470 * delete to update numbering sequence. Perform as an explicit operation
6471 * so that the renumbering effect may be replicated. Subtree rename must
6472 * be supported, since renumbering a database will affect all its child
6475 * modify: must be fully supported.
6479 config_back_initialize( BackendInfo *bi )
6481 ConfigTable *ct = config_back_cf_table;
6485 AttributeDescription *ad = NULL;
6487 static char *controls[] = {
6488 LDAP_CONTROL_MANAGEDSAIT,
6492 /* Make sure we don't exceed the bits reserved for userland */
6493 config_check_userland( CFG_LAST );
6495 bi->bi_controls = controls;
6500 bi->bi_destroy = config_back_destroy;
6502 bi->bi_db_init = config_back_db_init;
6503 bi->bi_db_config = 0;
6504 bi->bi_db_open = config_back_db_open;
6505 bi->bi_db_close = config_back_db_close;
6506 bi->bi_db_destroy = config_back_db_destroy;
6508 bi->bi_op_bind = config_back_bind;
6509 bi->bi_op_unbind = 0;
6510 bi->bi_op_search = config_back_search;
6511 bi->bi_op_compare = 0;
6512 bi->bi_op_modify = config_back_modify;
6513 bi->bi_op_modrdn = config_back_modrdn;
6514 bi->bi_op_add = config_back_add;
6515 bi->bi_op_delete = config_back_delete;
6516 bi->bi_op_abandon = 0;
6518 bi->bi_extended = 0;
6520 bi->bi_chk_referrals = 0;
6522 bi->bi_access_allowed = slap_access_allowed;
6524 bi->bi_connection_init = 0;
6525 bi->bi_connection_destroy = 0;
6527 bi->bi_entry_release_rw = config_entry_release;
6528 bi->bi_entry_get_rw = config_back_entry_get;
6530 bi->bi_tool_entry_open = config_tool_entry_open;
6531 bi->bi_tool_entry_close = config_tool_entry_close;
6532 bi->bi_tool_entry_first = config_tool_entry_first;
6533 bi->bi_tool_entry_next = config_tool_entry_next;
6534 bi->bi_tool_entry_get = config_tool_entry_get;
6535 bi->bi_tool_entry_put = config_tool_entry_put;
6538 argv[ 0 ] = "slapd";
6544 for (i=0; OidMacros[i].name; i++ ) {
6545 argv[1] = OidMacros[i].name;
6546 argv[2] = OidMacros[i].oid;
6547 parse_oidm( &ca, 0, NULL );
6550 bi->bi_cf_ocs = cf_ocs;
6552 i = config_register_schema( ct, cf_ocs );
6555 i = slap_str2ad( "olcDatabase", &olcDatabaseDummy[0].ad, &text );
6558 /* setup olcRootPW to be base64-encoded when written in LDIF form;
6559 * basically, we don't care if it fails */
6560 i = slap_str2ad( "olcRootPW", &ad, &text );
6562 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
6563 "warning, unable to get \"olcRootPW\" "
6564 "attribute description: %d: %s\n",
6567 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
6568 ad->ad_type->sat_oid );
6571 /* set up the notable AttributeDescriptions */
6573 for (;ct->name;ct++) {
6574 if (strcmp(ct->name, ads[i].name)) continue;
6575 *ads[i].desc = ct->ad;
6577 if (!ads[i].name) break;