1 /* bconfig.c - the config backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005-2008 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was originally developed by Howard Chu for inclusion
18 * in OpenLDAP Software.
24 #include <ac/string.h>
32 #include "slapi/slapi.h"
40 #define CONFIG_RDN "cn=config"
41 #define SCHEMA_RDN "cn=schema"
43 static struct berval config_rdn = BER_BVC(CONFIG_RDN);
44 static struct berval schema_rdn = BER_BVC(SCHEMA_RDN);
46 extern int slap_DN_strict; /* dn.c */
49 typedef struct modpath_s {
50 struct modpath_s *mp_next;
51 struct berval mp_path;
55 static ModPaths modpaths, *modlast = &modpaths, *modcur = &modpaths;
58 typedef struct ConfigFile {
59 struct ConfigFile *c_sibs;
60 struct ConfigFile *c_kids;
62 AttributeType *c_at_head, *c_at_tail;
63 ContentRule *c_cr_head, *c_cr_tail;
64 ObjectClass *c_oc_head, *c_oc_tail;
65 OidMacro *c_om_head, *c_om_tail;
66 Syntax *c_syn_head, *c_syn_tail;
71 ConfigFile *cb_config;
73 BackendDB cb_db; /* underlying database */
78 static CfBackInfo cfBackInfo;
80 static char *passwd_salt;
82 static char *logfileName;
83 #ifdef SLAP_AUTH_REWRITE
84 static BerVarray authz_rewrites;
87 static struct berval cfdir;
90 static AttributeDescription *cfAd_backend, *cfAd_database, *cfAd_overlay,
91 *cfAd_include, *cfAd_attr, *cfAd_oc, *cfAd_om, *cfAd_syntax;
93 static ConfigFile *cfn;
95 static Avlnode *CfOcTree;
97 /* System schema state */
98 extern AttributeType *at_sys_tail; /* at.c */
99 extern ObjectClass *oc_sys_tail; /* oc.c */
100 extern OidMacro *om_sys_tail; /* oidm.c */
101 extern Syntax *syn_sys_tail; /* syntax.c */
102 static AttributeType *cf_at_tail;
103 static ObjectClass *cf_oc_tail;
104 static OidMacro *cf_om_tail;
105 static Syntax *cf_syn_tail;
107 static int config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca,
108 SlapReply *rs, int *renumber, Operation *op );
110 static int config_check_schema( Operation *op, CfBackInfo *cfb );
112 static ConfigDriver config_fname;
113 static ConfigDriver config_cfdir;
114 static ConfigDriver config_generic;
115 static ConfigDriver config_search_base;
116 static ConfigDriver config_passwd_hash;
117 static ConfigDriver config_schema_dn;
118 static ConfigDriver config_sizelimit;
119 static ConfigDriver config_timelimit;
120 static ConfigDriver config_overlay;
121 static ConfigDriver config_subordinate;
122 static ConfigDriver config_suffix;
123 static ConfigDriver config_rootdn;
124 static ConfigDriver config_rootpw;
125 static ConfigDriver config_restrict;
126 static ConfigDriver config_allows;
127 static ConfigDriver config_disallows;
128 static ConfigDriver config_requires;
129 static ConfigDriver config_security;
130 static ConfigDriver config_referral;
131 static ConfigDriver config_loglevel;
132 static ConfigDriver config_updatedn;
133 static ConfigDriver config_updateref;
134 static ConfigDriver config_include;
135 static ConfigDriver config_obsolete;
137 static ConfigDriver config_tls_option;
138 static ConfigDriver config_tls_config;
140 extern ConfigDriver syncrepl_config;
196 static OidRec OidMacros[] = {
197 /* OpenLDAProot:1.12.2 */
198 { "OLcfg", "1.3.6.1.4.1.4203.1.12.2" },
199 { "OLcfgAt", "OLcfg:3" },
200 { "OLcfgGlAt", "OLcfgAt:0" },
201 { "OLcfgBkAt", "OLcfgAt:1" },
202 { "OLcfgDbAt", "OLcfgAt:2" },
203 { "OLcfgOvAt", "OLcfgAt:3" },
204 { "OLcfgCtAt", "OLcfgAt:4" }, /* contrib modules */
205 { "OLcfgOc", "OLcfg:4" },
206 { "OLcfgGlOc", "OLcfgOc:0" },
207 { "OLcfgBkOc", "OLcfgOc:1" },
208 { "OLcfgDbOc", "OLcfgOc:2" },
209 { "OLcfgOvOc", "OLcfgOc:3" },
210 { "OLcfgCtOc", "OLcfgOc:4" }, /* contrib modules */
212 /* Syntaxes. We should just start using the standard names and
213 * document that they are predefined and available for users
214 * to reference in their own schema. Defining schema without
215 * OID macros is for masochists...
217 { "OMsyn", "1.3.6.1.4.1.1466.115.121.1" },
218 { "OMsBoolean", "OMsyn:7" },
219 { "OMsDN", "OMsyn:12" },
220 { "OMsDirectoryString", "OMsyn:15" },
221 { "OMsIA5String", "OMsyn:26" },
222 { "OMsInteger", "OMsyn:27" },
223 { "OMsOID", "OMsyn:38" },
224 { "OMsOctetString", "OMsyn:40" },
229 * Backend/Database registry
231 * OLcfg{Bk|Db}{Oc|At}:0 -> common
232 * OLcfg{Bk|Db}{Oc|At}:1 -> back-bdb(/back-hdb)
233 * OLcfg{Bk|Db}{Oc|At}:2 -> back-ldif
234 * OLcfg{Bk|Db}{Oc|At}:3 -> back-ldap
235 * OLcfg{Bk|Db}{Oc|At}:4 -> back-monitor
236 * OLcfg{Bk|Db}{Oc|At}:5 -> back-relay
237 * OLcfg{Bk|Db}{Oc|At}:6 -> back-sql
238 * OLcfg{Bk|Db}{Oc|At}:7 -> back-sock
244 * OLcfgOv{Oc|At}:1 -> syncprov
245 * OLcfgOv{Oc|At}:2 -> pcache
246 * OLcfgOv{Oc|At}:3 -> chain
247 * OLcfgOv{Oc|At}:4 -> accesslog
248 * OLcfgOv{Oc|At}:5 -> valsort
249 * OLcfgOv{Oc|At}:7 -> distproc
250 * OLcfgOv{Oc|At}:8 -> dynlist
251 * OLcfgOv{Oc|At}:9 -> dds
252 * OLcfgOv{Oc|At}:10 -> unique
253 * OLcfgOv{Oc|At}:11 -> refint
254 * OLcfgOv{Oc|At}:12 -> ppolicy
255 * OLcfgOv{Oc|At}:13 -> constraint
256 * OLcfgOv{Oc|At}:14 -> translucent
257 * OLcfgOv{Oc|At}:15 -> auditlog
258 * OLcfgOv{Oc|At}:16 -> rwm
259 * OLcfgOv{Oc|At}:17 -> dyngroup
260 * OLcfgOv{Oc|At}:18 -> memberof
261 * OLcfgOv{Oc|At}:19 -> collect
262 * OLcfgOv{Oc|At}:20 -> retcode
265 /* alphabetical ordering */
267 static ConfigTable config_back_cf_table[] = {
268 /* This attr is read-only */
269 { "", "", 0, 0, 0, ARG_MAGIC,
270 &config_fname, "( OLcfgGlAt:78 NAME 'olcConfigFile' "
271 "DESC 'File for slapd configuration directives' "
272 "EQUALITY caseIgnoreMatch "
273 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
274 { "", "", 0, 0, 0, ARG_MAGIC,
275 &config_cfdir, "( OLcfgGlAt:79 NAME 'olcConfigDir' "
276 "DESC 'Directory for slapd configuration backend' "
277 "EQUALITY caseIgnoreMatch "
278 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
279 { "access", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC|CFG_ACL,
280 &config_generic, "( OLcfgGlAt:1 NAME 'olcAccess' "
281 "DESC 'Access Control List' "
282 "EQUALITY caseIgnoreMatch "
283 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
284 { "add_content_acl", NULL, 0, 0, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_ACL_ADD,
285 &config_generic, "( OLcfgGlAt:86 NAME 'olcAddContentAcl' "
286 "DESC 'Check ACLs against content of Add ops' "
287 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
288 { "allows", "features", 2, 0, 5, ARG_PRE_DB|ARG_MAGIC,
289 &config_allows, "( OLcfgGlAt:2 NAME 'olcAllows' "
290 "DESC 'Allowed set of deprecated features' "
291 "EQUALITY caseIgnoreMatch "
292 "SYNTAX OMsDirectoryString )", NULL, NULL },
293 { "argsfile", "file", 2, 2, 0, ARG_STRING,
294 &slapd_args_file, "( OLcfgGlAt:3 NAME 'olcArgsFile' "
295 "DESC 'File for slapd command line options' "
296 "EQUALITY caseIgnoreMatch "
297 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
298 { "attributeoptions", NULL, 0, 0, 0, ARG_MAGIC|CFG_ATOPT,
299 &config_generic, "( OLcfgGlAt:5 NAME 'olcAttributeOptions' "
300 "EQUALITY caseIgnoreMatch "
301 "SYNTAX OMsDirectoryString )", NULL, NULL },
302 { "attribute", "attribute", 2, 0, STRLENOF( "attribute" ),
303 ARG_PAREN|ARG_MAGIC|CFG_ATTR,
304 &config_generic, "( OLcfgGlAt:4 NAME 'olcAttributeTypes' "
305 "DESC 'OpenLDAP attributeTypes' "
306 "EQUALITY caseIgnoreMatch "
307 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
309 { "authid-rewrite", NULL, 2, 0, STRLENOF( "authid-rewrite" ),
310 #ifdef SLAP_AUTH_REWRITE
311 ARG_MAGIC|CFG_REWRITE|ARG_NO_INSERT, &config_generic,
315 "( OLcfgGlAt:6 NAME 'olcAuthIDRewrite' "
316 "EQUALITY caseIgnoreMatch "
317 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
318 { "authz-policy", "policy", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_AZPOLICY,
319 &config_generic, "( OLcfgGlAt:7 NAME 'olcAuthzPolicy' "
320 "EQUALITY caseIgnoreMatch "
321 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
322 { "authz-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP|ARG_NO_INSERT,
323 &config_generic, "( OLcfgGlAt:8 NAME 'olcAuthzRegexp' "
324 "EQUALITY caseIgnoreMatch "
325 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
326 { "backend", "type", 2, 2, 0, ARG_PRE_DB|ARG_MAGIC|CFG_BACKEND,
327 &config_generic, "( OLcfgGlAt:9 NAME 'olcBackend' "
328 "DESC 'A type of backend' "
329 "EQUALITY caseIgnoreMatch "
330 "SYNTAX OMsDirectoryString SINGLE-VALUE X-ORDERED 'SIBLINGS' )",
332 { "concurrency", "level", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_CONCUR,
333 &config_generic, "( OLcfgGlAt:10 NAME 'olcConcurrency' "
334 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
335 { "conn_max_pending", "max", 2, 2, 0, ARG_INT,
336 &slap_conn_max_pending, "( OLcfgGlAt:11 NAME 'olcConnMaxPending' "
337 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
338 { "conn_max_pending_auth", "max", 2, 2, 0, ARG_INT,
339 &slap_conn_max_pending_auth, "( OLcfgGlAt:12 NAME 'olcConnMaxPendingAuth' "
340 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
341 { "database", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE,
342 &config_generic, "( OLcfgGlAt:13 NAME 'olcDatabase' "
343 "DESC 'The backend type for a database instance' "
344 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
345 { "defaultSearchBase", "dn", 2, 2, 0, ARG_PRE_BI|ARG_PRE_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
346 &config_search_base, "( OLcfgGlAt:14 NAME 'olcDefaultSearchBase' "
347 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
348 { "disallows", "features", 2, 0, 8, ARG_PRE_DB|ARG_MAGIC,
349 &config_disallows, "( OLcfgGlAt:15 NAME 'olcDisallows' "
350 "EQUALITY caseIgnoreMatch "
351 "SYNTAX OMsDirectoryString )", NULL, NULL },
352 { "ditcontentrule", NULL, 0, 0, 0, ARG_MAGIC|CFG_DIT|ARG_NO_DELETE|ARG_NO_INSERT,
353 &config_generic, "( OLcfgGlAt:16 NAME 'olcDitContentRules' "
354 "DESC 'OpenLDAP DIT content rules' "
355 "EQUALITY caseIgnoreMatch "
356 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
358 { "gentlehup", "on|off", 2, 2, 0,
360 ARG_ON_OFF, &global_gentlehup,
364 "( OLcfgGlAt:17 NAME 'olcGentleHUP' "
365 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
366 { "hidden", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_HIDDEN,
367 &config_generic, "( OLcfgDbAt:0.17 NAME 'olcHidden' "
368 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
369 { "idletimeout", "timeout", 2, 2, 0, ARG_INT,
370 &global_idletimeout, "( OLcfgGlAt:18 NAME 'olcIdleTimeout' "
371 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
372 { "include", "file", 2, 2, 0, ARG_MAGIC,
373 &config_include, "( OLcfgGlAt:19 NAME 'olcInclude' "
374 "SUP labeledURI )", NULL, NULL },
375 { "index_substr_if_minlen", "min", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MIN,
376 &config_generic, "( OLcfgGlAt:20 NAME 'olcIndexSubstrIfMinLen' "
377 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
378 { "index_substr_if_maxlen", "max", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_MAGIC|CFG_SSTR_IF_MAX,
379 &config_generic, "( OLcfgGlAt:21 NAME 'olcIndexSubstrIfMaxLen' "
380 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
381 { "index_substr_any_len", "len", 2, 2, 0, ARG_INT|ARG_NONZERO,
382 &index_substr_any_len, "( OLcfgGlAt:22 NAME 'olcIndexSubstrAnyLen' "
383 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
384 { "index_substr_any_step", "step", 2, 2, 0, ARG_INT|ARG_NONZERO,
385 &index_substr_any_step, "( OLcfgGlAt:23 NAME 'olcIndexSubstrAnyStep' "
386 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
387 { "index_intlen", "len", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_IX_INTLEN,
388 &config_generic, "( OLcfgGlAt:84 NAME 'olcIndexIntLen' "
389 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
390 { "lastmod", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_LASTMOD,
391 &config_generic, "( OLcfgDbAt:0.4 NAME 'olcLastMod' "
392 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
393 { "ldapsyntax", "syntax", 2, 0, 0,
394 ARG_PAREN|ARG_MAGIC|CFG_SYNTAX,
395 &config_generic, "( OLcfgGlAt:85 NAME 'olcLdapSyntaxes' "
396 "DESC 'OpenLDAP ldapSyntax' "
397 "EQUALITY caseIgnoreMatch "
398 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
400 { "limits", "limits", 2, 0, 0, ARG_DB|ARG_MAGIC|CFG_LIMITS,
401 &config_generic, "( OLcfgDbAt:0.5 NAME 'olcLimits' "
402 "EQUALITY caseIgnoreMatch "
403 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
404 { "localSSF", "ssf", 2, 2, 0, ARG_INT,
405 &local_ssf, "( OLcfgGlAt:26 NAME 'olcLocalSSF' "
406 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
407 { "logfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_LOGFILE,
408 &config_generic, "( OLcfgGlAt:27 NAME 'olcLogFile' "
409 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
410 { "loglevel", "level", 2, 0, 0, ARG_MAGIC,
411 &config_loglevel, "( OLcfgGlAt:28 NAME 'olcLogLevel' "
412 "EQUALITY caseIgnoreMatch "
413 "SYNTAX OMsDirectoryString )", NULL, NULL },
414 { "maxDerefDepth", "depth", 2, 2, 0, ARG_DB|ARG_INT|ARG_MAGIC|CFG_DEPTH,
415 &config_generic, "( OLcfgDbAt:0.6 NAME 'olcMaxDerefDepth' "
416 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
417 { "mirrormode", "on|off", 2, 2, 0, ARG_DB|ARG_ON_OFF|ARG_MAGIC|CFG_MIRRORMODE,
418 &config_generic, "( OLcfgDbAt:0.16 NAME 'olcMirrorMode' "
419 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
420 { "moduleload", "file", 2, 0, 0,
422 ARG_MAGIC|CFG_MODLOAD|ARG_NO_DELETE, &config_generic,
426 "( OLcfgGlAt:30 NAME 'olcModuleLoad' "
427 "EQUALITY caseIgnoreMatch "
428 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
429 { "modulepath", "path", 2, 2, 0,
431 ARG_MAGIC|CFG_MODPATH|ARG_NO_DELETE|ARG_NO_INSERT, &config_generic,
435 "( OLcfgGlAt:31 NAME 'olcModulePath' "
436 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
437 { "monitoring", "TRUE|FALSE", 2, 2, 0,
438 ARG_MAGIC|CFG_MONITORING|ARG_DB|ARG_ON_OFF, &config_generic,
439 "( OLcfgDbAt:0.18 NAME 'olcMonitoring' "
440 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
441 { "objectclass", "objectclass", 2, 0, 0, ARG_PAREN|ARG_MAGIC|CFG_OC,
442 &config_generic, "( OLcfgGlAt:32 NAME 'olcObjectClasses' "
443 "DESC 'OpenLDAP object classes' "
444 "EQUALITY caseIgnoreMatch "
445 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )",
447 { "objectidentifier", "name> <oid", 3, 3, 0, ARG_MAGIC|CFG_OID,
448 &config_generic, "( OLcfgGlAt:33 NAME 'olcObjectIdentifier' "
449 "EQUALITY caseIgnoreMatch "
450 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
451 { "overlay", "overlay", 2, 2, 0, ARG_MAGIC,
452 &config_overlay, "( OLcfgGlAt:34 NAME 'olcOverlay' "
453 "SUP olcDatabase SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
454 { "password-crypt-salt-format", "salt", 2, 2, 0, ARG_STRING|ARG_MAGIC|CFG_SALT,
455 &config_generic, "( OLcfgGlAt:35 NAME 'olcPasswordCryptSaltFormat' "
456 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
457 { "password-hash", "hash", 2, 2, 0, ARG_MAGIC,
458 &config_passwd_hash, "( OLcfgGlAt:36 NAME 'olcPasswordHash' "
459 "EQUALITY caseIgnoreMatch "
460 "SYNTAX OMsDirectoryString )", NULL, NULL },
461 { "pidfile", "file", 2, 2, 0, ARG_STRING,
462 &slapd_pid_file, "( OLcfgGlAt:37 NAME 'olcPidFile' "
463 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
464 { "plugin", NULL, 0, 0, 0,
466 ARG_MAGIC|CFG_PLUGIN, &config_generic,
470 "( OLcfgGlAt:38 NAME 'olcPlugin' "
471 "EQUALITY caseIgnoreMatch "
472 "SYNTAX OMsDirectoryString )", NULL, NULL },
473 { "pluginlog", "filename", 2, 2, 0,
475 ARG_STRING, &slapi_log_file,
479 "( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
480 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
481 { "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
482 &config_generic, "( OLcfgGlAt:40 NAME 'olcReadOnly' "
483 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
484 { "referral", "url", 2, 2, 0, ARG_MAGIC,
485 &config_referral, "( OLcfgGlAt:41 NAME 'olcReferral' "
486 "SUP labeledURI SINGLE-VALUE )", NULL, NULL },
487 { "replica", "host or uri", 2, 0, 0, ARG_DB|ARG_MAGIC,
488 &config_obsolete, "( OLcfgDbAt:0.7 NAME 'olcReplica' "
489 "EQUALITY caseIgnoreMatch "
490 "SUP labeledURI X-ORDERED 'VALUES' )", NULL, NULL },
491 { "replica-argsfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
492 &config_obsolete, "( OLcfgGlAt:43 NAME 'olcReplicaArgsFile' "
493 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
494 { "replica-pidfile", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
495 &config_obsolete, "( OLcfgGlAt:44 NAME 'olcReplicaPidFile' "
496 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
497 { "replicationInterval", NULL, 0, 0, 0, ARG_MAY_DB|ARG_MAGIC,
498 &config_obsolete, "( OLcfgGlAt:45 NAME 'olcReplicationInterval' "
499 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
500 { "replogfile", "filename", 2, 2, 0, ARG_MAY_DB|ARG_MAGIC,
501 &config_obsolete, "( OLcfgGlAt:46 NAME 'olcReplogFile' "
502 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
503 { "require", "features", 2, 0, 7, ARG_MAY_DB|ARG_MAGIC,
504 &config_requires, "( OLcfgGlAt:47 NAME 'olcRequires' "
505 "EQUALITY caseIgnoreMatch "
506 "SYNTAX OMsDirectoryString )", NULL, NULL },
507 { "restrict", "op_list", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
508 &config_restrict, "( OLcfgGlAt:48 NAME 'olcRestrict' "
509 "EQUALITY caseIgnoreMatch "
510 "SYNTAX OMsDirectoryString )", NULL, NULL },
511 { "reverse-lookup", "on|off", 2, 2, 0,
512 #ifdef SLAPD_RLOOKUPS
513 ARG_ON_OFF, &use_reverse_lookup,
517 "( OLcfgGlAt:49 NAME 'olcReverseLookup' "
518 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
519 { "rootdn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
520 &config_rootdn, "( OLcfgDbAt:0.8 NAME 'olcRootDN' "
521 "EQUALITY distinguishedNameMatch "
522 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
523 { "rootDSE", "file", 2, 2, 0, ARG_MAGIC|CFG_ROOTDSE,
524 &config_generic, "( OLcfgGlAt:51 NAME 'olcRootDSE' "
525 "EQUALITY caseIgnoreMatch "
526 "SYNTAX OMsDirectoryString )", NULL, NULL },
527 { "rootpw", "password", 2, 2, 0, ARG_BERVAL|ARG_DB|ARG_MAGIC,
528 &config_rootpw, "( OLcfgDbAt:0.9 NAME 'olcRootPW' "
529 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
530 { "sasl-authz-policy", NULL, 2, 2, 0, ARG_MAGIC|CFG_AZPOLICY,
531 &config_generic, NULL, NULL, NULL },
532 { "sasl-host", "host", 2, 2, 0,
533 #ifdef HAVE_CYRUS_SASL
534 ARG_STRING|ARG_UNIQUE, &sasl_host,
538 "( OLcfgGlAt:53 NAME 'olcSaslHost' "
539 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
540 { "sasl-realm", "realm", 2, 2, 0,
541 #ifdef HAVE_CYRUS_SASL
542 ARG_STRING|ARG_UNIQUE, &global_realm,
546 "( OLcfgGlAt:54 NAME 'olcSaslRealm' "
547 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
548 { "sasl-regexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
549 &config_generic, NULL, NULL, NULL },
550 { "sasl-secprops", "properties", 2, 2, 0,
551 #ifdef HAVE_CYRUS_SASL
552 ARG_MAGIC|CFG_SASLSECP, &config_generic,
556 "( OLcfgGlAt:56 NAME 'olcSaslSecProps' "
557 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
558 { "saslRegexp", NULL, 3, 3, 0, ARG_MAGIC|CFG_AZREGEXP,
559 &config_generic, NULL, NULL, NULL },
560 { "schemadn", "dn", 2, 2, 0, ARG_MAY_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
561 &config_schema_dn, "( OLcfgGlAt:58 NAME 'olcSchemaDN' "
562 "EQUALITY distinguishedNameMatch "
563 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
564 { "security", "factors", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
565 &config_security, "( OLcfgGlAt:59 NAME 'olcSecurity' "
566 "EQUALITY caseIgnoreMatch "
567 "SYNTAX OMsDirectoryString )", NULL, NULL },
568 { "serverID", "number> <[URI]", 2, 3, 0, ARG_MAGIC|CFG_SERVERID,
569 &config_generic, "( OLcfgGlAt:81 NAME 'olcServerID' "
570 "EQUALITY caseIgnoreMatch "
571 "SYNTAX OMsDirectoryString )", NULL, NULL },
572 { "sizelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
573 &config_sizelimit, "( OLcfgGlAt:60 NAME 'olcSizeLimit' "
574 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
575 { "sockbuf_max_incoming", "max", 2, 2, 0, ARG_BER_LEN_T,
576 &sockbuf_max_incoming, "( OLcfgGlAt:61 NAME 'olcSockbufMaxIncoming' "
577 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
578 { "sockbuf_max_incoming_auth", "max", 2, 2, 0, ARG_BER_LEN_T,
579 &sockbuf_max_incoming_auth, "( OLcfgGlAt:62 NAME 'olcSockbufMaxIncomingAuth' "
580 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
581 { "sortvals", "attr", 2, 0, 0, ARG_MAGIC|CFG_SORTVALS,
582 &config_generic, "( OLcfgGlAt:83 NAME 'olcSortVals' "
583 "DESC 'Attributes whose values will always be sorted' "
584 "EQUALITY caseIgnoreMatch "
585 "SYNTAX OMsDirectoryString )", NULL, NULL },
586 { "subordinate", "[advertise]", 1, 2, 0, ARG_DB|ARG_MAGIC,
587 &config_subordinate, "( OLcfgDbAt:0.15 NAME 'olcSubordinate' "
588 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
589 { "suffix", "suffix", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
590 &config_suffix, "( OLcfgDbAt:0.10 NAME 'olcSuffix' "
591 "EQUALITY distinguishedNameMatch "
592 "SYNTAX OMsDN )", NULL, NULL },
593 { "syncrepl", NULL, 0, 0, 0, ARG_DB|ARG_MAGIC,
594 &syncrepl_config, "( OLcfgDbAt:0.11 NAME 'olcSyncrepl' "
595 "EQUALITY caseIgnoreMatch "
596 "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL },
597 { "threads", "count", 2, 2, 0,
601 ARG_INT|ARG_MAGIC|CFG_THREADS, &config_generic,
603 "( OLcfgGlAt:66 NAME 'olcThreads' "
604 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
605 { "timelimit", "limit", 2, 0, 0, ARG_MAY_DB|ARG_MAGIC,
606 &config_timelimit, "( OLcfgGlAt:67 NAME 'olcTimeLimit' "
607 "SYNTAX OMsDirectoryString )", NULL, NULL },
608 { "TLSCACertificateFile", NULL, 0, 0, 0,
610 CFG_TLS_CA_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
614 "( OLcfgGlAt:68 NAME 'olcTLSCACertificateFile' "
615 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
616 { "TLSCACertificatePath", NULL, 0, 0, 0,
618 CFG_TLS_CA_PATH|ARG_STRING|ARG_MAGIC, &config_tls_option,
622 "( OLcfgGlAt:69 NAME 'olcTLSCACertificatePath' "
623 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
624 { "TLSCertificateFile", NULL, 0, 0, 0,
626 CFG_TLS_CERT_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
630 "( OLcfgGlAt:70 NAME 'olcTLSCertificateFile' "
631 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
632 { "TLSCertificateKeyFile", NULL, 0, 0, 0,
634 CFG_TLS_CERT_KEY|ARG_STRING|ARG_MAGIC, &config_tls_option,
638 "( OLcfgGlAt:71 NAME 'olcTLSCertificateKeyFile' "
639 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
640 { "TLSCipherSuite", NULL, 0, 0, 0,
642 CFG_TLS_CIPHER|ARG_STRING|ARG_MAGIC, &config_tls_option,
646 "( OLcfgGlAt:72 NAME 'olcTLSCipherSuite' "
647 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
648 { "TLSCRLCheck", NULL, 0, 0, 0,
649 #if defined(HAVE_TLS) && defined(HAVE_OPENSSL_CRL)
650 CFG_TLS_CRLCHECK|ARG_STRING|ARG_MAGIC, &config_tls_config,
654 "( OLcfgGlAt:73 NAME 'olcTLSCRLCheck' "
655 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
656 { "TLSCRLFile", NULL, 0, 0, 0,
657 #if defined(HAVE_GNUTLS)
658 CFG_TLS_CRL_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
662 "( OLcfgGlAt:82 NAME 'olcTLSCRLFile' "
663 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
664 { "TLSRandFile", NULL, 0, 0, 0,
666 CFG_TLS_RAND|ARG_STRING|ARG_MAGIC, &config_tls_option,
670 "( OLcfgGlAt:74 NAME 'olcTLSRandFile' "
671 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
672 { "TLSVerifyClient", NULL, 0, 0, 0,
674 CFG_TLS_VERIFY|ARG_STRING|ARG_MAGIC, &config_tls_config,
678 "( OLcfgGlAt:75 NAME 'olcTLSVerifyClient' "
679 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
680 { "TLSDHParamFile", NULL, 0, 0, 0,
682 CFG_TLS_DH_FILE|ARG_STRING|ARG_MAGIC, &config_tls_option,
686 "( OLcfgGlAt:77 NAME 'olcTLSDHParamFile' "
687 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
688 { "tool-threads", "count", 2, 2, 0, ARG_INT|ARG_MAGIC|CFG_TTHREADS,
689 &config_generic, "( OLcfgGlAt:80 NAME 'olcToolThreads' "
690 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
691 { "ucdata-path", "path", 2, 2, 0, ARG_IGNORED,
692 NULL, NULL, NULL, NULL },
693 { "updatedn", "dn", 2, 2, 0, ARG_DB|ARG_DN|ARG_QUOTE|ARG_MAGIC,
694 &config_updatedn, "( OLcfgDbAt:0.12 NAME 'olcUpdateDN' "
695 "SYNTAX OMsDN SINGLE-VALUE )", NULL, NULL },
696 { "updateref", "url", 2, 2, 0, ARG_DB|ARG_MAGIC,
697 &config_updateref, "( OLcfgDbAt:0.13 NAME 'olcUpdateRef' "
698 "EQUALITY caseIgnoreMatch "
699 "SUP labeledURI )", NULL, NULL },
700 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
701 NULL, NULL, NULL, NULL }
704 /* Need to no-op this keyword for dynamic config */
705 ConfigTable olcDatabaseDummy[] = {
706 { "", "", 0, 0, 0, ARG_IGNORED,
707 NULL, "( OLcfgGlAt:13 NAME 'olcDatabase' "
708 "DESC 'The backend type for a database instance' "
709 "SUP olcBackend SINGLE-VALUE X-ORDERED 'SIBLINGS' )", NULL, NULL },
710 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
713 /* Routines to check if a child can be added to this type */
714 static ConfigLDAPadd cfAddSchema, cfAddInclude, cfAddDatabase,
715 cfAddBackend, cfAddModule, cfAddOverlay;
717 /* NOTE: be careful when defining array members
718 * that can be conditionally compiled */
719 #define CFOC_GLOBAL cf_ocs[1]
720 #define CFOC_SCHEMA cf_ocs[2]
721 #define CFOC_BACKEND cf_ocs[3]
722 #define CFOC_DATABASE cf_ocs[4]
723 #define CFOC_OVERLAY cf_ocs[5]
724 #define CFOC_INCLUDE cf_ocs[6]
725 #define CFOC_FRONTEND cf_ocs[7]
727 #define CFOC_MODULE cf_ocs[8]
728 #endif /* SLAPD_MODULES */
730 static ConfigOCs cf_ocs[] = {
733 "DESC 'OpenLDAP configuration object' "
734 "ABSTRACT SUP top )", Cft_Abstract, NULL },
737 "DESC 'OpenLDAP Global configuration options' "
738 "SUP olcConfig STRUCTURAL "
739 "MAY ( cn $ olcConfigFile $ olcConfigDir $ olcAllows $ olcArgsFile $ "
740 "olcAttributeOptions $ olcAuthIDRewrite $ "
741 "olcAuthzPolicy $ olcAuthzRegexp $ olcConcurrency $ "
742 "olcConnMaxPending $ olcConnMaxPendingAuth $ "
743 "olcDisallows $ olcGentleHUP $ olcIdleTimeout $ "
744 "olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
745 "olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcIndexIntLen $ "
746 "olcLocalSSF $ olcLogFile $ olcLogLevel $ "
747 "olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
748 "olcPluginLogFile $ olcReadOnly $ olcReferral $ "
749 "olcReplogFile $ olcRequires $ olcRestrict $ olcReverseLookup $ "
751 "olcSaslHost $ olcSaslRealm $ olcSaslSecProps $ "
752 "olcSecurity $ olcServerID $ olcSizeLimit $ "
753 "olcSockbufMaxIncoming $ olcSockbufMaxIncomingAuth $ "
754 "olcThreads $ olcTimeLimit $ olcTLSCACertificateFile $ "
755 "olcTLSCACertificatePath $ olcTLSCertificateFile $ "
756 "olcTLSCertificateKeyFile $ olcTLSCipherSuite $ olcTLSCRLCheck $ "
757 "olcTLSRandFile $ olcTLSVerifyClient $ olcTLSDHParamFile $ "
758 "olcTLSCRLFile $ olcToolThreads $ "
759 "olcObjectIdentifier $ olcAttributeTypes $ olcObjectClasses $ "
760 "olcDitContentRules $ olcLdapSyntaxes ) )", Cft_Global },
762 "NAME 'olcSchemaConfig' "
763 "DESC 'OpenLDAP schema object' "
764 "SUP olcConfig STRUCTURAL "
765 "MAY ( cn $ olcObjectIdentifier $ olcAttributeTypes $ "
766 "olcObjectClasses $ olcDitContentRules $ olcLdapSyntaxes ) )",
767 Cft_Schema, NULL, cfAddSchema },
769 "NAME 'olcBackendConfig' "
770 "DESC 'OpenLDAP Backend-specific options' "
771 "SUP olcConfig STRUCTURAL "
772 "MUST olcBackend )", Cft_Backend, NULL, cfAddBackend },
774 "NAME 'olcDatabaseConfig' "
775 "DESC 'OpenLDAP Database-specific options' "
776 "SUP olcConfig STRUCTURAL "
778 "MAY ( olcHidden $ olcSuffix $ olcSubordinate $ olcAccess $ "
779 "olcAddContentAcl $ olcLastMod $ olcLimits $ "
780 "olcMaxDerefDepth $ olcPlugin $ olcReadOnly $ olcReplica $ "
781 "olcReplicaArgsFile $ olcReplicaPidFile $ olcReplicationInterval $ "
782 "olcReplogFile $ olcRequires $ olcRestrict $ olcRootDN $ olcRootPW $ "
783 "olcSchemaDN $ olcSecurity $ olcSizeLimit $ olcSyncrepl $ "
784 "olcTimeLimit $ olcUpdateDN $ olcUpdateRef $ olcMirrorMode $ "
786 Cft_Database, NULL, cfAddDatabase },
788 "NAME 'olcOverlayConfig' "
789 "DESC 'OpenLDAP Overlay-specific options' "
790 "SUP olcConfig STRUCTURAL "
791 "MUST olcOverlay )", Cft_Overlay, NULL, cfAddOverlay },
793 "NAME 'olcIncludeFile' "
794 "DESC 'OpenLDAP configuration include file' "
795 "SUP olcConfig STRUCTURAL "
797 "MAY ( cn $ olcRootDSE ) )",
798 /* Used to be Cft_Include, that def has been removed */
799 Cft_Abstract, NULL, cfAddInclude },
800 /* This should be STRUCTURAL like all the other database classes, but
801 * that would mean inheriting all of the olcDatabaseConfig attributes,
802 * which causes them to be merged twice in config_build_entry.
805 "NAME 'olcFrontendConfig' "
806 "DESC 'OpenLDAP frontend configuration' "
808 "MAY ( olcDefaultSearchBase $ olcPasswordHash $ olcSortVals ) )",
809 Cft_Database, NULL, NULL },
812 "NAME 'olcModuleList' "
813 "DESC 'OpenLDAP dynamic module info' "
814 "SUP olcConfig STRUCTURAL "
815 "MAY ( cn $ olcModulePath $ olcModuleLoad ) )",
816 Cft_Module, NULL, cfAddModule },
821 typedef struct ServerID {
822 struct ServerID *si_next;
823 struct berval si_url;
827 static ServerID *sid_list;
829 typedef struct voidList {
830 struct voidList *vl_next;
834 typedef struct ADlist {
835 struct ADlist *al_next;
836 AttributeDescription *al_desc;
839 static ADlist *sortVals;
842 config_generic(ConfigArgs *c) {
845 if ( c->op == SLAP_CONFIG_EMIT ) {
849 c->value_int = ldap_pvt_thread_get_concurrency();
852 c->value_int = connection_pool_max;
855 c->value_int = slap_tool_thread_max;
859 c->value_string = ch_strdup( passwd_salt );
864 if ( c->be->be_limits ) {
868 for ( i=0; c->be->be_limits[i]; i++ ) {
869 bv.bv_len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
870 if ( bv.bv_len >= sizeof( buf ) ) {
871 ber_bvarray_free_x( c->rvalue_vals, NULL );
872 c->rvalue_vals = NULL;
876 bv.bv_val = buf + bv.bv_len;
877 limits_unparse( c->be->be_limits[i], &bv,
878 sizeof( buf ) - ( bv.bv_val - buf ) );
879 bv.bv_len += bv.bv_val - buf;
881 value_add_one( &c->rvalue_vals, &bv );
884 if ( !c->rvalue_vals ) rc = 1;
887 c->value_int = (c->be->be_restrictops & SLAP_RESTRICT_OP_WRITES) ==
888 SLAP_RESTRICT_OP_WRITES;
891 c->value_string = ch_strdup( slap_sasl_getpolicy());
894 slap_sasl_regexp_unparse( &c->rvalue_vals );
895 if ( !c->rvalue_vals ) rc = 1;
897 #ifdef HAVE_CYRUS_SASL
899 struct berval bv = BER_BVNULL;
900 slap_sasl_secprops_unparse( &bv );
901 if ( !BER_BVISNULL( &bv )) {
902 ber_bvarray_add( &c->rvalue_vals, &bv );
910 c->value_int = c->be->be_max_deref_depth;
913 if ( SLAP_DBHIDDEN( c->be )) {
920 ConfigFile *cf = c->ca_private;
922 oidm_unparse( &c->rvalue_vals, NULL, NULL, 1 );
923 else if ( cf->c_om_head )
924 oidm_unparse( &c->rvalue_vals, cf->c_om_head,
926 if ( !c->rvalue_vals )
931 ad_unparse_options( &c->rvalue_vals );
934 ConfigFile *cf = c->ca_private;
936 oc_unparse( &c->rvalue_vals, NULL, NULL, 1 );
937 else if ( cf->c_oc_head )
938 oc_unparse( &c->rvalue_vals, cf->c_oc_head,
940 if ( !c->rvalue_vals )
945 ConfigFile *cf = c->ca_private;
947 at_unparse( &c->rvalue_vals, NULL, NULL, 1 );
948 else if ( cf->c_at_head )
949 at_unparse( &c->rvalue_vals, cf->c_at_head,
951 if ( !c->rvalue_vals )
956 ConfigFile *cf = c->ca_private;
958 syn_unparse( &c->rvalue_vals, NULL, NULL, 1 );
959 else if ( cf->c_syn_head )
960 syn_unparse( &c->rvalue_vals, cf->c_syn_head,
962 if ( !c->rvalue_vals )
967 ConfigFile *cf = c->ca_private;
969 cr_unparse( &c->rvalue_vals, NULL, NULL, 1 );
970 else if ( cf->c_cr_head )
971 cr_unparse( &c->rvalue_vals, cf->c_cr_head,
973 if ( !c->rvalue_vals )
980 char *src, *dst, ibuf[11];
981 struct berval bv, abv;
982 for (i=0, a=c->be->be_acl; a; i++,a=a->acl_next) {
983 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
984 if ( abv.bv_len >= sizeof( ibuf ) ) {
985 ber_bvarray_free_x( c->rvalue_vals, NULL );
986 c->rvalue_vals = NULL;
990 acl_unparse( a, &bv );
991 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
992 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
993 /* Turn TAB / EOL into plain space */
994 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
995 if (isspace((unsigned char)*src)) *dst++ = ' ';
999 if (dst[-1] == ' ') {
1003 abv.bv_len = dst - abv.bv_val;
1004 ber_bvarray_add( &c->rvalue_vals, &abv );
1010 c->value_int = (SLAP_DBACL_ADD(c->be) != 0);
1013 ConfigFile *cf = c->ca_private;
1014 if ( cf->c_dseFiles ) {
1015 value_add( &c->rvalue_vals, cf->c_dseFiles );
1026 for ( si = sid_list; si; si=si->si_next ) {
1027 assert( si->si_num >= 0 && si->si_num <= SLAP_SYNC_SID_MAX );
1028 if ( !BER_BVISEMPTY( &si->si_url )) {
1029 bv.bv_len = si->si_url.bv_len + 6;
1030 bv.bv_val = ch_malloc( bv.bv_len );
1031 sprintf( bv.bv_val, "%d %s", si->si_num,
1032 si->si_url.bv_val );
1033 ber_bvarray_add( &c->rvalue_vals, &bv );
1037 bv.bv_len = sprintf( buf, "%d", si->si_num );
1038 value_add_one( &c->rvalue_vals, &bv );
1047 c->value_string = ch_strdup( logfileName );
1052 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1054 case CFG_MIRRORMODE:
1055 if ( SLAP_SHADOW(c->be))
1056 c->value_int = (SLAP_SINGLE_SHADOW(c->be) == 0);
1060 case CFG_MONITORING:
1061 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
1063 case CFG_SSTR_IF_MAX:
1064 c->value_int = index_substr_if_maxlen;
1066 case CFG_SSTR_IF_MIN:
1067 c->value_int = index_substr_if_minlen;
1070 c->value_int = index_intlen;
1072 case CFG_SORTVALS: {
1075 for ( sv = sortVals; sv; sv = sv->al_next ) {
1076 value_add_one( &c->rvalue_vals, &sv->al_desc->ad_cname );
1080 #ifdef SLAPD_MODULES
1082 ModPaths *mp = c->ca_private;
1085 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
1088 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
1089 SLAP_X_ORDERED_FMT "%s", i,
1090 mp->mp_loads[i].bv_val );
1091 if ( bv.bv_len >= sizeof( c->log ) ) {
1092 ber_bvarray_free_x( c->rvalue_vals, NULL );
1093 c->rvalue_vals = NULL;
1096 value_add_one( &c->rvalue_vals, &bv );
1100 rc = c->rvalue_vals ? 0 : 1;
1104 ModPaths *mp = c->ca_private;
1105 if ( !BER_BVISNULL( &mp->mp_path ))
1106 value_add_one( &c->rvalue_vals, &mp->mp_path );
1108 rc = c->rvalue_vals ? 0 : 1;
1114 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1115 if ( !c->rvalue_vals ) rc = 1;
1118 #ifdef SLAP_AUTH_REWRITE
1120 if ( authz_rewrites ) {
1121 struct berval bv, idx;
1126 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1127 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1128 if ( idx.bv_len >= sizeof( ibuf ) ) {
1129 ber_bvarray_free_x( c->rvalue_vals, NULL );
1130 c->rvalue_vals = NULL;
1133 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1134 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1135 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1136 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1137 authz_rewrites[i].bv_val,
1138 authz_rewrites[i].bv_len + 1 );
1139 ber_bvarray_add( &c->rvalue_vals, &bv );
1142 if ( !c->rvalue_vals ) rc = 1;
1149 } else if ( c->op == LDAP_MOD_DELETE ) {
1152 /* single-valued attrs, no-ops */
1160 case CFG_MIRRORMODE:
1161 case CFG_MONITORING:
1163 case CFG_SSTR_IF_MAX:
1164 case CFG_SSTR_IF_MIN:
1168 /* no-ops, requires slapd restart */
1173 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1177 ch_free( passwd_salt );
1182 ch_free( logfileName );
1190 case CFG_SERVERID: {
1191 ServerID *si, **sip;
1193 for ( i=0, si = sid_list, sip = &sid_list;
1194 si; si = *sip, i++ ) {
1195 if ( c->valx == -1 || i == c->valx ) {
1207 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1211 index_intlen = SLAP_INDEX_INTLEN_DEFAULT;
1212 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1213 SLAP_INDEX_INTLEN_DEFAULT );
1217 if ( c->valx < 0 ) {
1218 acl_destroy( c->be->be_acl );
1219 c->be->be_acl = NULL;
1222 AccessControl **prev, *a;
1224 for (i=0, prev = &c->be->be_acl; i < c->valx;
1227 prev = &a->acl_next;
1230 *prev = a->acl_next;
1237 /* Can be NULL when undoing a failed add */
1238 if ( c->ca_entry ) {
1239 ce = c->ca_entry->e_private;
1240 /* can't modify the hardcoded schema */
1241 if ( ce->ce_parent->ce_type == Cft_Global )
1245 cfn = c->ca_private;
1246 if ( c->valx < 0 ) {
1249 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1251 if ( oc == cfn->c_oc_tail )
1254 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1256 ObjectClass *oc, *prev = NULL;
1258 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1263 if ( cfn->c_oc_tail == oc ) {
1264 cfn->c_oc_tail = prev;
1266 if ( cfn->c_oc_head == oc ) {
1268 cfn->c_oc_head = oc;
1275 /* Can be NULL when undoing a failed add */
1276 if ( c->ca_entry ) {
1277 ce = c->ca_entry->e_private;
1278 /* can't modify the hardcoded schema */
1279 if ( ce->ce_parent->ce_type == Cft_Global )
1283 cfn = c->ca_private;
1284 if ( c->valx < 0 ) {
1287 for( at = cfn->c_at_head; at; at_next( &at )) {
1289 if ( at == cfn->c_at_tail )
1292 cfn->c_at_head = cfn->c_at_tail = NULL;
1294 AttributeType *at, *prev = NULL;
1296 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1301 if ( cfn->c_at_tail == at ) {
1302 cfn->c_at_tail = prev;
1304 if ( cfn->c_at_head == at ) {
1306 cfn->c_at_head = at;
1313 /* Can be NULL when undoing a failed add */
1314 if ( c->ca_entry ) {
1315 ce = c->ca_entry->e_private;
1316 /* can't modify the hardcoded schema */
1317 if ( ce->ce_parent->ce_type == Cft_Global )
1321 cfn = c->ca_private;
1322 if ( c->valx < 0 ) {
1325 for( syn = cfn->c_syn_head; syn; syn_next( &syn )) {
1327 if ( syn == cfn->c_syn_tail )
1330 cfn->c_syn_head = cfn->c_syn_tail = NULL;
1332 Syntax *syn, *prev = NULL;
1334 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++) {
1339 if ( cfn->c_syn_tail == syn ) {
1340 cfn->c_syn_tail = prev;
1342 if ( cfn->c_syn_head == syn ) {
1344 cfn->c_syn_head = syn;
1349 if ( c->valx < 0 ) {
1351 for ( sv = sortVals; sv; sv = sortVals ) {
1352 sortVals = sv->al_next;
1353 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1360 for ( prev = &sortVals, sv = sortVals; i < c->valx; i++ ) {
1361 prev = &sv->al_next;
1364 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1365 *prev = sv->al_next;
1371 /* FIXME: there is no limits_free function */
1373 /* FIXME: there is no ad_option_free function */
1375 /* FIXME: there is no way to remove attributes added by
1389 if(!(c->bi = backend_info(c->argv[1]))) {
1390 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1391 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1392 c->log, c->cr_msg, c->argv[1] );
1399 /* NOTE: config is always the first backend!
1401 if ( !strcasecmp( c->argv[1], "config" )) {
1402 c->be = LDAP_STAILQ_FIRST(&backendDB);
1403 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1406 c->be = backend_db_init(c->argv[1], NULL, c->valx, &c->reply);
1408 if ( c->cr_msg[0] == 0 )
1409 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1410 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n", c->log, c->cr_msg, c->argv[1] );
1417 ldap_pvt_thread_set_concurrency(c->value_int);
1421 if ( c->value_int < 2 ) {
1422 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1423 "threads=%d smaller than minimum value 2",
1425 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1426 c->log, c->cr_msg, 0 );
1429 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1430 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1431 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1432 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1433 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1434 c->log, c->cr_msg, 0 );
1436 if ( slapMode & SLAP_SERVER_MODE )
1437 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1438 connection_pool_max = c->value_int; /* save for reference */
1442 if ( slapMode & SLAP_TOOL_MODE )
1443 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1444 slap_tool_thread_max = c->value_int; /* save for reference */
1448 if ( passwd_salt ) ch_free( passwd_salt );
1449 passwd_salt = c->value_string;
1450 lutil_salt_format(passwd_salt);
1454 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1460 c->be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1462 c->be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1466 ch_free(c->value_string);
1467 if (slap_sasl_setpolicy( c->argv[1] )) {
1468 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
1469 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1470 c->log, c->cr_msg, c->argv[1] );
1476 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1480 #ifdef HAVE_CYRUS_SASL
1483 char *txt = slap_sasl_secprops( c->argv[1] );
1485 snprintf( c->cr_msg, sizeof(c->cr_msg), "<%s> %s",
1487 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0 );
1495 c->be->be_max_deref_depth = c->value_int;
1501 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1502 cfn = c->ca_private;
1503 if(parse_oidm(c, 1, &om))
1505 if (!cfn->c_om_head) cfn->c_om_head = om;
1506 cfn->c_om_tail = om;
1511 ObjectClass *oc, *prev;
1513 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1514 cfn = c->ca_private;
1515 if ( c->valx < 0 ) {
1516 prev = cfn->c_oc_tail;
1519 /* If adding anything after the first, prev is easy */
1522 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
1527 /* If adding the first, and head exists, find its prev */
1528 if (cfn->c_oc_head) {
1529 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
1534 /* else prev is NULL, append to end of global list */
1536 if(parse_oc(c, &oc, prev)) return(1);
1537 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1538 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
1543 AttributeType *at, *prev;
1545 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1546 cfn = c->ca_private;
1547 if ( c->valx < 0 ) {
1548 prev = cfn->c_at_tail;
1551 /* If adding anything after the first, prev is easy */
1554 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
1559 /* If adding the first, and head exists, find its prev */
1560 if (cfn->c_at_head) {
1561 for ( at_start( &at ); at != cfn->c_at_head; ) {
1566 /* else prev is NULL, append to end of global list */
1568 if(parse_at(c, &at, prev)) return(1);
1569 if (!cfn->c_at_head) cfn->c_at_head = at;
1570 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
1577 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1578 cfn = c->ca_private;
1579 if ( c->valx < 0 ) {
1580 prev = cfn->c_syn_tail;
1583 /* If adding anything after the first, prev is easy */
1586 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++ ) {
1591 /* If adding the first, and head exists, find its prev */
1592 if (cfn->c_syn_head) {
1593 for ( syn_start( &syn ); syn != cfn->c_syn_head; ) {
1598 /* else prev is NULL, append to end of global list */
1600 if ( parse_syn( c, &syn, prev ) ) return(1);
1601 if ( !cfn->c_syn_head ) cfn->c_syn_head = syn;
1602 if ( cfn->c_syn_tail == prev ) cfn->c_syn_tail = syn;
1609 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1610 cfn = c->ca_private;
1611 if(parse_cr(c, &cr)) return(1);
1612 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1613 cfn->c_cr_tail = cr;
1618 ad_define_option(NULL, NULL, 0);
1619 for(i = 1; i < c->argc; i++)
1620 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1625 if ( c->value_int < SLAP_INDEX_INTLEN_DEFAULT )
1626 c->value_int = SLAP_INDEX_INTLEN_DEFAULT;
1627 else if ( c->value_int > 255 )
1629 index_intlen = c->value_int;
1630 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1634 case CFG_SORTVALS: {
1635 ADlist *svnew = NULL, *svtail, *sv;
1637 for ( i = 1; i < c->argc; i++ ) {
1638 AttributeDescription *ad = NULL;
1642 rc = slap_str2ad( c->argv[i], &ad, &text );
1644 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown attribute type #%d",
1647 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1648 c->log, c->cr_msg, c->argv[i] );
1649 for ( sv = svnew; sv; sv = svnew ) {
1650 svnew = sv->al_next;
1655 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) ||
1656 ad->ad_type->sat_single_value ) {
1657 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> inappropriate attribute type #%d",
1659 goto sortval_reject;
1661 sv = ch_malloc( sizeof( ADlist ));
1666 svtail->al_next = sv;
1671 for ( sv = svnew; sv; sv = sv->al_next )
1672 sv->al_desc->ad_type->sat_flags |= SLAP_AT_SORTED_VAL;
1673 for ( sv = sortVals; sv && sv->al_next; sv = sv->al_next );
1675 sv->al_next = svnew;
1682 /* Don't append to the global ACL if we're on a specific DB */
1684 if ( c->valx == -1 ) {
1687 for ( a=c->be->be_acl; a; a = a->acl_next )
1690 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
1697 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_ACL_ADD;
1699 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_ACL_ADD;
1703 if(root_dse_read_file(c->argv[1])) {
1704 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> could not read file", c->argv[0] );
1705 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1706 c->log, c->cr_msg, c->argv[1] );
1711 ber_str2bv( c->argv[1], 0, 1, &bv );
1712 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1713 cfn = c->ca_private;
1714 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1720 ServerID *si, **sip;
1723 if ( lutil_atoi( &num, c->argv[1] ) ||
1724 num < 0 || num > SLAP_SYNC_SID_MAX )
1726 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1727 "<%s> illegal server ID", c->argv[0] );
1728 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1729 c->log, c->cr_msg, c->argv[1] );
1732 /* only one value allowed if no URL is given */
1733 if ( c->argc > 2 ) {
1736 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
1737 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1738 "<%s> only one server ID allowed now", c->argv[0] );
1739 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1740 c->log, c->cr_msg, c->argv[1] );
1744 if ( ldap_url_parse( c->argv[2], &lud )) {
1745 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1746 "<%s> invalid URL", c->argv[0] );
1747 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1748 c->log, c->cr_msg, c->argv[2] );
1751 len = strlen( c->argv[2] );
1752 si = ch_malloc( sizeof(ServerID) + len + 1 );
1753 si->si_url.bv_val = (char *)(si+1);
1754 si->si_url.bv_len = len;
1755 strcpy( si->si_url.bv_val, c->argv[2] );
1758 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1759 "<%s> unqualified server ID not allowed now", c->argv[0] );
1760 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1761 c->log, c->cr_msg, c->argv[1] );
1764 si = ch_malloc( sizeof(ServerID) );
1765 BER_BVZERO( &si->si_url );
1766 slap_serverID = num;
1767 Debug( LDAP_DEBUG_CONFIG,
1769 c->log, slap_serverID, 0 );
1773 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
1776 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
1777 /* If hostname is empty, or is localhost, or matches
1778 * our hostname, this serverID refers to this host.
1779 * Compare it against listeners and ports.
1781 if ( !lud->lud_host || !lud->lud_host[0] ||
1782 !strncasecmp("localhost", lud->lud_host,
1783 STRLENOF("localhost")) ||
1784 !strcasecmp( global_host, lud->lud_host )) {
1785 Listener **l = slapd_get_listeners();
1788 for ( i=0; l && l[i]; i++ ) {
1791 ldap_url_parse( l[i]->sl_url.bv_val, &lu2 );
1793 if ( strcasecmp( lud->lud_scheme,
1796 if ( lud->lud_port != lu2->lud_port )
1798 /* Listener on ANY address */
1799 if ( !lu2->lud_host || !lu2->lud_host[0] ) {
1803 /* URL on ANY address */
1804 if ( !lud->lud_host || !lud->lud_host[0] ) {
1808 /* Listener has specific host, must
1811 if ( !strcasecmp( lud->lud_host,
1817 ldap_free_urldesc( lu2 );
1819 slap_serverID = si->si_num;
1820 Debug( LDAP_DEBUG_CONFIG,
1821 "%s: SID=%d (listener=%s)\n",
1822 c->log, slap_serverID,
1823 l[i]->sl_url.bv_val );
1830 ldap_free_urldesc( lud );
1834 if ( logfileName ) ch_free( logfileName );
1835 logfileName = c->value_string;
1836 logfile = fopen(logfileName, "w");
1837 if(logfile) lutil_debug_file(logfile);
1841 if(SLAP_NOLASTMODCMD(c->be)) {
1842 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> not available for %s database",
1843 c->argv[0], c->be->bd_info->bi_type );
1844 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1845 c->log, c->cr_msg, 0 );
1849 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1851 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1854 case CFG_MIRRORMODE:
1855 if(!SLAP_SHADOW(c->be)) {
1856 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database is not a shadow",
1858 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1859 c->log, c->cr_msg, 0 );
1863 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
1865 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1868 case CFG_MONITORING:
1870 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
1872 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
1877 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
1879 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
1882 case CFG_SSTR_IF_MAX:
1883 if (c->value_int < index_substr_if_minlen) {
1884 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1885 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1886 c->log, c->cr_msg, c->value_int );
1889 index_substr_if_maxlen = c->value_int;
1892 case CFG_SSTR_IF_MIN:
1893 if (c->value_int > index_substr_if_maxlen) {
1894 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1895 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1896 c->log, c->cr_msg, c->value_int );
1899 index_substr_if_minlen = c->value_int;
1902 #ifdef SLAPD_MODULES
1904 /* If we're just adding a module on an existing modpath,
1905 * make sure we've selected the current path.
1907 if ( c->op == LDAP_MOD_ADD && c->ca_private && modcur != c->ca_private ) {
1908 modcur = c->ca_private;
1909 /* This should never fail */
1910 if ( module_path( modcur->mp_path.bv_val )) {
1911 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> module path no longer valid",
1913 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1914 c->log, c->cr_msg, modcur->mp_path.bv_val );
1918 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1920 /* Record this load on the current path */
1924 if ( c->op == SLAP_CONFIG_ADD ) {
1925 ptr = c->line + STRLENOF("moduleload");
1926 while (!isspace((unsigned char) *ptr)) ptr++;
1927 while (isspace((unsigned char) *ptr)) ptr++;
1931 ber_str2bv(ptr, 0, 1, &bv);
1932 ber_bvarray_add( &modcur->mp_loads, &bv );
1934 /* Check for any new hardcoded schema */
1935 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
1936 config_check_schema( NULL, &cfBackInfo );
1941 if(module_path(c->argv[1])) return(1);
1942 /* Record which path was used with each module */
1946 if (!modpaths.mp_loads) {
1949 mp = ch_malloc( sizeof( ModPaths ));
1950 modlast->mp_next = mp;
1952 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1954 mp->mp_loads = NULL;
1965 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
1967 slapi_plugins_used++;
1971 #ifdef SLAP_AUTH_REWRITE
1976 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
1979 if ( c->argc > 1 ) {
1982 /* quote all args but the first */
1983 line = ldap_charray2str( c->argv, "\" \"" );
1984 ber_str2bv( line, 0, 0, &bv );
1985 s = ber_bvchr( &bv, '"' );
1986 assert( s != NULL );
1987 /* move the trailing quote of argv[0] to the end */
1988 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
1989 bv.bv_val[ bv.bv_len - 1 ] = '"';
1992 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
1995 ber_bvarray_add( &authz_rewrites, &bv );
2002 Debug( LDAP_DEBUG_ANY,
2003 "%s: unknown CFG_TYPE %d.\n",
2004 c->log, c->type, 0 );
2013 config_fname(ConfigArgs *c) {
2014 if(c->op == SLAP_CONFIG_EMIT) {
2015 if (c->ca_private) {
2016 ConfigFile *cf = c->ca_private;
2017 value_add_one( &c->rvalue_vals, &cf->c_file );
2026 config_cfdir(ConfigArgs *c) {
2027 if(c->op == SLAP_CONFIG_EMIT) {
2028 if ( !BER_BVISEMPTY( &cfdir )) {
2029 value_add_one( &c->rvalue_vals, &cfdir );
2038 config_search_base(ConfigArgs *c) {
2039 if(c->op == SLAP_CONFIG_EMIT) {
2041 if (!BER_BVISEMPTY(&default_search_base)) {
2042 value_add_one(&c->rvalue_vals, &default_search_base);
2043 value_add_one(&c->rvalue_nvals, &default_search_nbase);
2047 } else if( c->op == LDAP_MOD_DELETE ) {
2048 ch_free( default_search_base.bv_val );
2049 ch_free( default_search_nbase.bv_val );
2050 BER_BVZERO( &default_search_base );
2051 BER_BVZERO( &default_search_nbase );
2055 if(c->bi || c->be != frontendDB) {
2056 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
2057 "prior to any backend or database definition\n",
2062 if(default_search_nbase.bv_len) {
2063 free(default_search_base.bv_val);
2064 free(default_search_nbase.bv_val);
2067 default_search_base = c->value_dn;
2068 default_search_nbase = c->value_ndn;
2072 /* For RE23 compatibility we allow this in the global entry
2073 * but we now defer it to the frontend entry to allow modules
2074 * to load new hash types.
2077 config_passwd_hash(ConfigArgs *c) {
2079 if (c->op == SLAP_CONFIG_EMIT) {
2081 /* Don't generate it in the global entry */
2082 if ( c->table == Cft_Global )
2084 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
2085 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
2086 value_add_one(&c->rvalue_vals, &bv);
2089 } else if ( c->op == LDAP_MOD_DELETE ) {
2090 /* Deleting from global is a no-op, only the frontendDB entry matters */
2091 if ( c->table == Cft_Global )
2093 if ( c->valx < 0 ) {
2094 ldap_charray_free( default_passwd_hash );
2095 default_passwd_hash = NULL;
2098 ch_free( default_passwd_hash[i] );
2099 for (; default_passwd_hash[i]; i++ )
2100 default_passwd_hash[i] = default_passwd_hash[i+1];
2104 for(i = 1; i < c->argc; i++) {
2105 if(!lutil_passwd_scheme(c->argv[i])) {
2106 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> scheme not available", c->argv[0] );
2107 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2108 c->log, c->cr_msg, c->argv[i]);
2110 ldap_charray_add(&default_passwd_hash, c->argv[i]);
2113 if(!default_passwd_hash) {
2114 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> no valid hashes found", c->argv[0] );
2115 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2116 c->log, c->cr_msg, 0 );
2123 config_schema_dn(ConfigArgs *c) {
2124 if ( c->op == SLAP_CONFIG_EMIT ) {
2126 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
2127 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
2128 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
2132 } else if ( c->op == LDAP_MOD_DELETE ) {
2133 ch_free( c->be->be_schemadn.bv_val );
2134 ch_free( c->be->be_schemandn.bv_val );
2135 BER_BVZERO( &c->be->be_schemadn );
2136 BER_BVZERO( &c->be->be_schemandn );
2139 ch_free( c->be->be_schemadn.bv_val );
2140 ch_free( c->be->be_schemandn.bv_val );
2141 c->be->be_schemadn = c->value_dn;
2142 c->be->be_schemandn = c->value_ndn;
2147 config_sizelimit(ConfigArgs *c) {
2149 struct slap_limits_set *lim = &c->be->be_def_limit;
2150 if (c->op == SLAP_CONFIG_EMIT) {
2155 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
2156 if ( !BER_BVISEMPTY( &bv ))
2157 value_add_one( &c->rvalue_vals, &bv );
2161 } else if ( c->op == LDAP_MOD_DELETE ) {
2162 /* Reset to defaults */
2163 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
2164 lim->lms_s_hard = 0;
2165 lim->lms_s_unchecked = -1;
2167 lim->lms_s_pr_hide = 0;
2168 lim->lms_s_pr_total = 0;
2171 for(i = 1; i < c->argc; i++) {
2172 if(!strncasecmp(c->argv[i], "size", 4)) {
2173 rc = limits_parse_one(c->argv[i], lim);
2175 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2176 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2177 c->log, c->cr_msg, c->argv[i]);
2181 if(!strcasecmp(c->argv[i], "unlimited")) {
2182 lim->lms_s_soft = -1;
2184 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
2185 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2186 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2187 c->log, c->cr_msg, c->argv[i]);
2191 lim->lms_s_hard = 0;
2198 config_timelimit(ConfigArgs *c) {
2200 struct slap_limits_set *lim = &c->be->be_def_limit;
2201 if (c->op == SLAP_CONFIG_EMIT) {
2206 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
2207 if ( !BER_BVISEMPTY( &bv ))
2208 value_add_one( &c->rvalue_vals, &bv );
2212 } else if ( c->op == LDAP_MOD_DELETE ) {
2213 /* Reset to defaults */
2214 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
2215 lim->lms_t_hard = 0;
2218 for(i = 1; i < c->argc; i++) {
2219 if(!strncasecmp(c->argv[i], "time", 4)) {
2220 rc = limits_parse_one(c->argv[i], lim);
2222 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2223 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2224 c->log, c->cr_msg, c->argv[i]);
2228 if(!strcasecmp(c->argv[i], "unlimited")) {
2229 lim->lms_t_soft = -1;
2231 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
2232 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2233 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2234 c->log, c->cr_msg, c->argv[i]);
2238 lim->lms_t_hard = 0;
2245 config_overlay(ConfigArgs *c) {
2246 if (c->op == SLAP_CONFIG_EMIT) {
2248 } else if ( c->op == LDAP_MOD_DELETE ) {
2251 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2252 c->valx, &c->bi, &c->reply)) {
2254 Debug( LDAP_DEBUG_ANY,
2255 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2256 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2258 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi, &c->reply)) {
2265 config_subordinate(ConfigArgs *c)
2271 case SLAP_CONFIG_EMIT:
2272 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2275 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2276 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2279 value_add_one( &c->rvalue_vals, &bv );
2283 case LDAP_MOD_DELETE:
2284 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2285 glue_sub_del( c->be );
2287 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2292 case SLAP_CONFIG_ADD:
2293 advertise = ( c->argc == 2 && !strcasecmp( c->argv[1], "advertise" ));
2294 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2301 config_suffix(ConfigArgs *c)
2304 struct berval pdn, ndn;
2305 char *notallowed = NULL;
2307 if ( c->be == frontendDB ) {
2308 notallowed = "frontend";
2310 } else if ( SLAP_MONITOR(c->be) ) {
2311 notallowed = "monitor";
2313 } else if ( SLAP_CONFIG(c->be) ) {
2314 notallowed = "config";
2317 if ( notallowed != NULL ) {
2318 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
2322 case LDAP_MOD_DELETE:
2323 case LDAP_MOD_REPLACE:
2324 case LDAP_MOD_INCREMENT:
2325 case SLAP_CONFIG_ADD:
2326 if ( !BER_BVISNULL( &c->value_dn ) ) {
2327 snprintf( buf, sizeof( buf ), "<%s> ",
2328 c->value_dn.bv_val );
2331 Debug(LDAP_DEBUG_ANY,
2332 "%s: suffix %snot allowed in %s database.\n",
2333 c->log, buf, notallowed );
2336 case SLAP_CONFIG_EMIT:
2337 /* don't complain when emitting... */
2341 /* FIXME: don't know what values may be valid;
2342 * please remove assertion, or add legal values
2343 * to either block */
2351 if (c->op == SLAP_CONFIG_EMIT) {
2352 if ( c->be->be_suffix == NULL
2353 || BER_BVISNULL( &c->be->be_suffix[0] ) )
2357 value_add( &c->rvalue_vals, c->be->be_suffix );
2358 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
2361 } else if ( c->op == LDAP_MOD_DELETE ) {
2362 if ( c->valx < 0 ) {
2363 ber_bvarray_free( c->be->be_suffix );
2364 ber_bvarray_free( c->be->be_nsuffix );
2365 c->be->be_suffix = NULL;
2366 c->be->be_nsuffix = NULL;
2369 ch_free( c->be->be_suffix[i].bv_val );
2370 ch_free( c->be->be_nsuffix[i].bv_val );
2372 c->be->be_suffix[i] = c->be->be_suffix[i+1];
2373 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
2375 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
2380 #ifdef SLAPD_MONITOR_DN
2381 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
2382 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> DN is reserved for monitoring slapd",
2384 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2385 c->log, c->cr_msg, SLAPD_MONITOR_DN);
2390 if (SLAP_DB_ONE_SUFFIX( c->be ) && c->be->be_suffix ) {
2391 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> Only one suffix is allowed on this %s backend",
2392 c->argv[0], c->be->bd_info->bi_type );
2393 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2394 c->log, c->cr_msg, 0);
2401 if (SLAP_DBHIDDEN( c->be ))
2404 tbe = select_backend(&ndn, 0);
2406 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
2412 BackendDB *b2 = tbe;
2414 /* Does tbe precede be? */
2415 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
2418 char *type = tbe->bd_info->bi_type;
2420 if ( overlay_is_over( tbe ) ) {
2421 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
2422 type = oi->oi_orig->bi_type;
2425 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> namingContext \"%s\" "
2426 "already served by a preceding %s database",
2427 c->argv[0], pdn.bv_val, type );
2428 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
2429 c->log, c->cr_msg, tbe->be_suffix[0].bv_val);
2435 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
2436 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
2437 "base provided \"%s\" (assuming okay)\n",
2438 c->log, default_search_base.bv_val, 0);
2440 ber_bvarray_add(&c->be->be_suffix, &pdn);
2441 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
2446 config_rootdn(ConfigArgs *c) {
2447 if (c->op == SLAP_CONFIG_EMIT) {
2448 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2449 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
2450 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
2455 } else if ( c->op == LDAP_MOD_DELETE ) {
2456 ch_free( c->be->be_rootdn.bv_val );
2457 ch_free( c->be->be_rootndn.bv_val );
2458 BER_BVZERO( &c->be->be_rootdn );
2459 BER_BVZERO( &c->be->be_rootndn );
2462 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2463 ch_free( c->be->be_rootdn.bv_val );
2464 ch_free( c->be->be_rootndn.bv_val );
2466 c->be->be_rootdn = c->value_dn;
2467 c->be->be_rootndn = c->value_ndn;
2472 config_rootpw(ConfigArgs *c) {
2475 if (c->op == SLAP_CONFIG_EMIT) {
2476 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
2477 /* don't copy, because "rootpw" is marked
2479 c->value_bv = c->be->be_rootpw;
2483 } else if ( c->op == LDAP_MOD_DELETE ) {
2484 ch_free( c->be->be_rootpw.bv_val );
2485 BER_BVZERO( &c->be->be_rootpw );
2489 tbe = select_backend(&c->be->be_rootndn, 0);
2491 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> can only be set when rootdn is under suffix",
2493 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2494 c->log, c->cr_msg, 0);
2497 if ( !BER_BVISNULL( &c->be->be_rootpw ))
2498 ch_free( c->be->be_rootpw.bv_val );
2499 c->be->be_rootpw = c->value_bv;
2504 config_restrict(ConfigArgs *c) {
2505 slap_mask_t restrictops = 0;
2507 slap_verbmasks restrictable_ops[] = {
2508 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
2509 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
2510 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
2511 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
2512 { BER_BVC("modrdn"), 0 },
2513 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
2514 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
2515 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
2516 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
2517 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
2518 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
2519 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
2520 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
2521 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
2522 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
2523 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
2527 if (c->op == SLAP_CONFIG_EMIT) {
2528 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
2530 } else if ( c->op == LDAP_MOD_DELETE ) {
2532 c->be->be_restrictops = 0;
2534 restrictops = verb_to_mask( c->line, restrictable_ops );
2535 c->be->be_restrictops ^= restrictops;
2539 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
2541 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown operation", c->argv[0] );
2542 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2543 c->log, c->cr_msg, c->argv[i]);
2546 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
2547 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
2548 c->be->be_restrictops |= restrictops;
2553 config_allows(ConfigArgs *c) {
2554 slap_mask_t allows = 0;
2556 slap_verbmasks allowable_ops[] = {
2557 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
2558 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
2559 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
2560 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
2561 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
2564 if (c->op == SLAP_CONFIG_EMIT) {
2565 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
2566 } else if ( c->op == LDAP_MOD_DELETE ) {
2570 allows = verb_to_mask( c->line, allowable_ops );
2571 global_allows ^= allows;
2575 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
2577 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
2578 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2579 c->log, c->cr_msg, c->argv[i]);
2582 global_allows |= allows;
2587 config_disallows(ConfigArgs *c) {
2588 slap_mask_t disallows = 0;
2590 slap_verbmasks disallowable_ops[] = {
2591 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
2592 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
2593 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
2594 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
2595 { BER_BVC("proxy_authz_non_critical"), SLAP_DISALLOW_PROXY_AUTHZ_N_CRIT },
2596 { BER_BVC("dontusecopy_non_critical"), SLAP_DISALLOW_DONTUSECOPY_N_CRIT },
2599 if (c->op == SLAP_CONFIG_EMIT) {
2600 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
2601 } else if ( c->op == LDAP_MOD_DELETE ) {
2603 global_disallows = 0;
2605 disallows = verb_to_mask( c->line, disallowable_ops );
2606 global_disallows ^= disallows;
2610 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
2612 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
2613 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2614 c->log, c->cr_msg, c->argv[i]);
2617 global_disallows |= disallows;
2622 config_requires(ConfigArgs *c) {
2623 slap_mask_t requires = frontendDB->be_requires;
2624 int i, argc = c->argc;
2625 char **argv = c->argv;
2627 slap_verbmasks requires_ops[] = {
2628 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
2629 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
2630 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
2631 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
2632 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
2635 if (c->op == SLAP_CONFIG_EMIT) {
2636 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
2637 } else if ( c->op == LDAP_MOD_DELETE ) {
2639 c->be->be_requires = 0;
2641 requires = verb_to_mask( c->line, requires_ops );
2642 c->be->be_requires ^= requires;
2646 /* "none" can only be first, to wipe out default/global values */
2647 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
2652 i = verbs_to_mask(argc, argv, requires_ops, &requires);
2654 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
2655 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
2656 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2657 c->log, c->cr_msg, 0);
2659 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
2660 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2661 c->log, c->cr_msg, c->argv[i]);
2665 c->be->be_requires = requires;
2669 static slap_verbmasks *loglevel_ops;
2672 loglevel_init( void )
2674 slap_verbmasks lo[] = {
2675 { BER_BVC("Any"), -1 },
2676 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
2677 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
2678 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
2679 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
2680 { BER_BVC("BER"), LDAP_DEBUG_BER },
2681 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
2682 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
2683 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
2684 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
2685 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
2686 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
2687 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
2688 #if 0 /* no longer used (nor supported) */
2689 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
2690 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
2692 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
2693 { BER_BVC("None"), LDAP_DEBUG_NONE },
2697 return slap_verbmasks_init( &loglevel_ops, lo );
2701 loglevel_destroy( void )
2703 if ( loglevel_ops ) {
2704 (void)slap_verbmasks_destroy( loglevel_ops );
2706 loglevel_ops = NULL;
2709 static slap_mask_t loglevel_ignore[] = { -1, 0 };
2712 slap_loglevel_register( slap_mask_t m, struct berval *s )
2716 if ( loglevel_ops == NULL ) {
2720 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
2723 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
2731 slap_loglevel_get( struct berval *s, int *l )
2736 if ( loglevel_ops == NULL ) {
2740 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
2741 m |= loglevel_ops[ i ].mask;
2744 for ( i = 1; m & i; i <<= 1 )
2751 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
2754 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
2765 str2loglevel( const char *s, int *l )
2769 if ( loglevel_ops == NULL ) {
2773 i = verb_to_mask( s, loglevel_ops );
2775 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
2779 *l = loglevel_ops[ i ].mask;
2785 loglevel2str( int l )
2787 struct berval bv = BER_BVNULL;
2789 loglevel2bv( l, &bv );
2795 loglevel2bv( int l, struct berval *bv )
2797 if ( loglevel_ops == NULL ) {
2803 return enum_to_verb( loglevel_ops, l, bv ) == -1;
2807 loglevel2bvarray( int l, BerVarray *bva )
2809 if ( loglevel_ops == NULL ) {
2813 return mask_to_verbs( loglevel_ops, l, bva );
2817 loglevel_print( FILE *out )
2821 if ( loglevel_ops == NULL ) {
2825 fprintf( out, "Installed log subsystems:\n\n" );
2826 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
2827 fprintf( out, "\t%-30s (%lu)\n",
2828 loglevel_ops[ i ].word.bv_val,
2829 loglevel_ops[ i ].mask );
2832 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
2833 "by specific code\n\n" );
2838 static int config_syslog;
2841 config_loglevel(ConfigArgs *c) {
2844 if ( loglevel_ops == NULL ) {
2848 if (c->op == SLAP_CONFIG_EMIT) {
2849 /* Get default or commandline slapd setting */
2850 if ( ldap_syslog && !config_syslog )
2851 config_syslog = ldap_syslog;
2852 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
2854 } else if ( c->op == LDAP_MOD_DELETE ) {
2858 int level = verb_to_mask( c->line, loglevel_ops );
2859 config_syslog ^= level;
2861 if ( slapMode & SLAP_SERVER_MODE ) {
2862 ldap_syslog = config_syslog;
2867 for( i=1; i < c->argc; i++ ) {
2870 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
2871 if( lutil_atoi( &level, c->argv[i] ) != 0 ) {
2872 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse level", c->argv[0] );
2873 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2874 c->log, c->cr_msg, c->argv[i]);
2878 if ( str2loglevel( c->argv[i], &level ) ) {
2879 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown level", c->argv[0] );
2880 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2881 c->log, c->cr_msg, c->argv[i]);
2885 /* Explicitly setting a zero clears all the levels */
2887 config_syslog |= level;
2891 if ( slapMode & SLAP_SERVER_MODE ) {
2892 ldap_syslog = config_syslog;
2898 config_referral(ConfigArgs *c) {
2900 if (c->op == SLAP_CONFIG_EMIT) {
2901 if ( default_referral ) {
2902 value_add( &c->rvalue_vals, default_referral );
2907 } else if ( c->op == LDAP_MOD_DELETE ) {
2908 if ( c->valx < 0 ) {
2909 ber_bvarray_free( default_referral );
2910 default_referral = NULL;
2913 ch_free( default_referral[i].bv_val );
2914 for (; default_referral[i].bv_val; i++ )
2915 default_referral[i] = default_referral[i+1];
2919 if(validate_global_referral(c->argv[1])) {
2920 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
2921 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2922 c->log, c->cr_msg, c->argv[1]);
2926 ber_str2bv(c->argv[1], 0, 0, &val);
2927 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
2935 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
2936 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
2937 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
2938 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
2939 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
2940 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
2941 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
2942 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
2943 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
2948 config_security(ConfigArgs *c) {
2949 slap_ssf_set_t *set = &c->be->be_ssf_set;
2952 if (c->op == SLAP_CONFIG_EMIT) {
2958 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
2959 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
2962 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
2963 if ( bv.bv_len >= sizeof( numbuf ) ) {
2964 ber_bvarray_free_x( c->rvalue_vals, NULL );
2965 c->rvalue_vals = NULL;
2969 bv.bv_len += sec_keys[i].key.bv_len;
2970 bv.bv_val = ch_malloc( bv.bv_len + 1);
2971 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
2972 strcpy( next, numbuf );
2973 ber_bvarray_add( &c->rvalue_vals, &bv );
2978 for(i = 1; i < c->argc; i++) {
2979 slap_ssf_t *tgt = NULL;
2981 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
2982 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
2983 sec_keys[j].key.bv_len)) {
2984 src = c->argv[i] + sec_keys[j].key.bv_len;
2985 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
2990 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown factor", c->argv[0] );
2991 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2992 c->log, c->cr_msg, c->argv[i]);
2996 if ( lutil_atou( tgt, src ) != 0 ) {
2997 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse factor", c->argv[0] );
2998 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2999 c->log, c->cr_msg, c->argv[i]);
3007 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
3011 for (; !BER_BVISNULL( &an->an_name ); an++) {
3012 /* if buflen == 0, assume the buffer size has been
3013 * already checked otherwise */
3014 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
3015 if ( comma ) *ptr++ = ',';
3016 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
3023 config_updatedn(ConfigArgs *c) {
3024 if (c->op == SLAP_CONFIG_EMIT) {
3025 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
3026 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
3027 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
3031 } else if ( c->op == LDAP_MOD_DELETE ) {
3032 ch_free( c->be->be_update_ndn.bv_val );
3033 BER_BVZERO( &c->be->be_update_ndn );
3034 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
3037 if(SLAP_SHADOW(c->be)) {
3038 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database already shadowed", c->argv[0] );
3039 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3040 c->log, c->cr_msg, 0);
3044 ber_memfree_x( c->value_dn.bv_val, NULL );
3045 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
3046 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
3048 c->be->be_update_ndn = c->value_ndn;
3049 BER_BVZERO( &c->value_dn );
3050 BER_BVZERO( &c->value_ndn );
3052 return config_slurp_shadow( c );
3056 config_shadow( ConfigArgs *c, int flag )
3058 char *notallowed = NULL;
3060 if ( c->be == frontendDB ) {
3061 notallowed = "frontend";
3063 } else if ( SLAP_MONITOR(c->be) ) {
3064 notallowed = "monitor";
3067 if ( notallowed != NULL ) {
3068 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
3072 if ( SLAP_SHADOW(c->be) ) {
3073 /* if already shadow, only check consistency */
3074 if ( ( SLAP_DBFLAGS(c->be) & flag ) != flag ) {
3075 Debug( LDAP_DEBUG_ANY, "%s: inconsistent shadow flag 0x%x.\n", c->log, flag, 0 );
3080 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SINGLE_SHADOW | flag);
3087 config_updateref(ConfigArgs *c) {
3089 if (c->op == SLAP_CONFIG_EMIT) {
3090 if ( c->be->be_update_refs ) {
3091 value_add( &c->rvalue_vals, c->be->be_update_refs );
3096 } else if ( c->op == LDAP_MOD_DELETE ) {
3097 if ( c->valx < 0 ) {
3098 ber_bvarray_free( c->be->be_update_refs );
3099 c->be->be_update_refs = NULL;
3102 ch_free( c->be->be_update_refs[i].bv_val );
3103 for (; c->be->be_update_refs[i].bv_val; i++)
3104 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
3108 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
3109 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must appear after syncrepl or updatedn",
3111 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3112 c->log, c->cr_msg, 0);
3116 if(validate_global_referral(c->argv[1])) {
3117 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3118 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3119 c->log, c->cr_msg, c->argv[1]);
3122 ber_str2bv(c->argv[1], 0, 0, &val);
3123 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
3128 config_obsolete(ConfigArgs *c) {
3129 if (c->op == SLAP_CONFIG_EMIT)
3132 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> keyword is obsolete (ignored)",
3134 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0);
3139 config_include(ConfigArgs *c) {
3140 int savelineno = c->lineno;
3143 ConfigFile *cfsave = cfn;
3144 ConfigFile *cf2 = NULL;
3146 /* Leftover from RE23. No dynamic config for include files */
3147 if ( c->op == SLAP_CONFIG_EMIT || c->op == LDAP_MOD_DELETE )
3150 cf = ch_calloc( 1, sizeof(ConfigFile));
3151 if ( cfn->c_kids ) {
3152 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
3158 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
3159 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
3160 c->lineno = savelineno - 1;
3163 if ( cf2 ) cf2->c_sibs = NULL;
3164 else cfn->c_kids = NULL;
3165 ch_free( cf->c_file.bv_val );
3175 config_tls_option(ConfigArgs *c) {
3177 LDAP *ld = slap_tls_ld;
3179 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
3180 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
3181 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
3182 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
3183 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
3184 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
3185 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
3187 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
3189 default: Debug(LDAP_DEBUG_ANY, "%s: "
3190 "unknown tls_option <0x%x>\n",
3191 c->log, c->type, 0);
3194 if (c->op == SLAP_CONFIG_EMIT) {
3195 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
3196 } else if ( c->op == LDAP_MOD_DELETE ) {
3197 return ldap_pvt_tls_set_option( ld, flag, NULL );
3199 ch_free(c->value_string);
3200 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
3203 /* FIXME: this ought to be provided by libldap */
3205 config_tls_config(ConfigArgs *c) {
3208 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
3209 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
3211 Debug(LDAP_DEBUG_ANY, "%s: "
3212 "unknown tls_option <0x%x>\n",
3213 c->log, c->type, 0);
3216 if (c->op == SLAP_CONFIG_EMIT) {
3217 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
3218 } else if ( c->op == LDAP_MOD_DELETE ) {
3220 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
3222 ch_free( c->value_string );
3223 if ( isdigit( (unsigned char)c->argv[1][0] ) ) {
3224 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
3225 Debug(LDAP_DEBUG_ANY, "%s: "
3226 "unable to parse %s \"%s\"\n",
3227 c->log, c->argv[0], c->argv[1] );
3230 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
3232 return(ldap_int_tls_config(slap_tls_ld, flag, c->argv[1]));
3237 static CfEntryInfo *
3238 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
3248 if ( dn_match( &root->ce_entry->e_nname, dn ))
3251 c = dn->bv_val+dn->bv_len;
3252 for (;*c != ',';c--);
3256 for (--c;c>dn->bv_val && *c != ',';c--);
3260 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
3262 root = root->ce_kids;
3264 for (;root;root=root->ce_sibs) {
3265 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
3266 if ( cdn.bv_val == dn->bv_val ) {
3276 typedef struct setup_cookie {
3286 config_ldif_resp( Operation *op, SlapReply *rs )
3288 if ( rs->sr_type == REP_SEARCH ) {
3289 setup_cookie *sc = op->o_callback->sc_private;
3292 sc->cfb->cb_got_ldif = 1;
3293 /* Does the frontend exist? */
3294 if ( !sc->got_frontend ) {
3295 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
3296 "olcDatabase", STRLENOF( "olcDatabase" )))
3298 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3299 STRLENOF( "olcDatabase" ), "={-1}frontend",
3300 STRLENOF( "={-1}frontend" )))
3304 sc->ca->be = frontendDB;
3305 sc->ca->bi = frontendDB->bd_info;
3306 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
3307 rdn.bv_val = sc->ca->log;
3308 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3309 "%s=" SLAP_X_ORDERED_FMT "%s",
3310 cfAd_database->ad_cname.bv_val, -1,
3311 sc->ca->bi->bi_type);
3313 sc->frontend = config_build_entry( op, rs,
3314 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
3315 sc->ca->be->be_cf_ocs );
3325 dnParent( &rs->sr_entry->e_nname, &pdn );
3327 /* Does the configDB exist? */
3328 if ( sc->got_frontend && !sc->got_config &&
3329 !strncmp( rs->sr_entry->e_nname.bv_val,
3330 "olcDatabase", STRLENOF( "olcDatabase" )) &&
3331 dn_match( &config_rdn, &pdn ) )
3333 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3334 STRLENOF( "olcDatabase" ), "={0}config",
3335 STRLENOF( "={0}config" )))
3339 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
3340 sc->ca->bi = sc->ca->be->bd_info;
3341 rdn.bv_val = sc->ca->log;
3342 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3343 "%s=" SLAP_X_ORDERED_FMT "%s",
3344 cfAd_database->ad_cname.bv_val, 0,
3345 sc->ca->bi->bi_type);
3347 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
3348 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
3355 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
3356 if ( rs->sr_err != LDAP_SUCCESS ) {
3357 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
3358 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg, 0 );
3364 /* Configure and read the underlying back-ldif store */
3366 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
3367 CfBackInfo *cfb = be->be_private;
3373 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
3374 Connection conn = {0};
3375 OperationBuffer opbuf;
3377 SlapReply rs = {REP_RESULT};
3378 Filter filter = { LDAP_FILTER_PRESENT };
3379 struct berval filterstr = BER_BVC("(objectclass=*)");
3382 /* Is the config directory available? */
3383 if ( stat( dir, &st ) < 0 ) {
3384 /* No, so don't bother using the backing store.
3385 * All changes will be in-memory only.
3390 cfb->cb_db.bd_info = backend_info( "ldif" );
3391 if ( !cfb->cb_db.bd_info )
3392 return 0; /* FIXME: eventually this will be a fatal error */
3394 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
3397 cfb->cb_db.be_suffix = be->be_suffix;
3398 cfb->cb_db.be_nsuffix = be->be_nsuffix;
3400 /* The suffix is always "cn=config". The underlying DB's rootdn
3401 * is always the same as the suffix.
3403 cfb->cb_db.be_rootdn = be->be_suffix[0];
3404 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
3406 ber_str2bv( dir, 0, 1, &cfdir );
3411 argv[0] = "directory";
3412 argv[1] = (char *)dir;
3417 c.table = Cft_Database;
3419 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
3423 if ( config_add_vals( ct, &c ))
3426 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
3430 void *thrctx = ldap_pvt_thread_pool_context();
3433 connection_fake_init( &conn, &opbuf, thrctx );
3436 filter.f_desc = slap_schema.si_ad_objectClass;
3438 op->o_tag = LDAP_REQ_SEARCH;
3440 op->ors_filter = &filter;
3441 op->ors_filterstr = filterstr;
3442 op->ors_scope = LDAP_SCOPE_SUBTREE;
3444 op->o_dn = c.be->be_rootdn;
3445 op->o_ndn = c.be->be_rootndn;
3447 op->o_req_dn = be->be_suffix[0];
3448 op->o_req_ndn = be->be_nsuffix[0];
3450 op->ors_tlimit = SLAP_NO_LIMIT;
3451 op->ors_slimit = SLAP_NO_LIMIT;
3453 op->ors_attrs = slap_anlist_all_attributes;
3454 op->ors_attrsonly = 0;
3456 op->o_callback = &cb;
3459 cb.sc_private = ≻
3460 sc.got_frontend = 0;
3465 op->o_bd = &cfb->cb_db;
3467 /* Allow unknown attrs in DNs */
3468 prev_DN_strict = slap_DN_strict;
3471 rc = op->o_bd->be_search( op, &rs );
3473 /* Restore normal DN validation */
3474 slap_DN_strict = prev_DN_strict;
3476 op->o_tag = LDAP_REQ_ADD;
3477 if ( rc == LDAP_SUCCESS && sc.frontend ) {
3478 op->ora_e = sc.frontend;
3479 rc = op->o_bd->be_add( op, &rs );
3481 if ( rc == LDAP_SUCCESS && sc.config ) {
3482 op->ora_e = sc.config;
3483 rc = op->o_bd->be_add( op, &rs );
3485 ldap_pvt_thread_pool_context_reset( thrctx );
3488 /* ITS#4194 - only use if it's present, or we're converting. */
3489 if ( !readit || rc == LDAP_SUCCESS )
3490 cfb->cb_use_ldif = 1;
3496 CfOc_cmp( const void *c1, const void *c2 ) {
3497 const ConfigOCs *co1 = c1;
3498 const ConfigOCs *co2 = c2;
3500 return ber_bvcmp( co1->co_name, co2->co_name );
3504 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
3507 i = init_config_attrs( ct );
3510 /* set up the objectclasses */
3511 i = init_config_ocs( ocs );
3514 for (i=0; ocs[i].co_def; i++) {
3515 if ( ocs[i].co_oc ) {
3516 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
3517 if ( !ocs[i].co_table )
3518 ocs[i].co_table = ct;
3519 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
3526 read_config(const char *fname, const char *dir) {
3529 const char *cfdir, *cfname;
3532 /* Setup the config backend */
3533 be = backend_db_init( "config", NULL, 0, NULL );
3537 cfb = be->be_private;
3538 be->be_dfltaccess = ACL_NONE;
3540 /* If no .conf, or a dir was specified, setup the dir */
3541 if ( !fname || dir ) {
3543 /* If explicitly given, check for existence */
3546 if ( stat( dir, &st ) < 0 ) {
3547 Debug( LDAP_DEBUG_ANY,
3548 "invalid config directory %s, error %d\n",
3554 cfdir = SLAPD_DEFAULT_CONFIGDIR;
3556 /* if fname is defaulted, try reading .d */
3557 rc = config_setup_ldif( be, cfdir, !fname );
3560 /* It may be OK if the base object doesn't exist yet. */
3561 if ( rc != LDAP_NO_SUCH_OBJECT )
3563 /* ITS#4194: But if dir was specified and no fname,
3564 * then we were supposed to read the dir. Unless we're
3565 * trying to slapadd the dir...
3567 if ( dir && !fname ) {
3568 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
3570 /* Assume it's slapadd with a config dir, let it continue */
3572 cfb->cb_got_ldif = 1;
3573 cfb->cb_use_ldif = 1;
3578 /* If we read the config from back-ldif, nothing to do here */
3579 if ( cfb->cb_got_ldif ) {
3588 cfname = SLAPD_DEFAULT_CONFIGFILE;
3590 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
3593 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
3596 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
3597 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
3598 &frontendDB->be_schemadn );
3599 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
3600 if ( rc != LDAP_SUCCESS ) {
3601 Debug(LDAP_DEBUG_ANY, "read_config: "
3602 "unable to normalize default schema DN \"%s\"\n",
3603 frontendDB->be_schemadn.bv_val, 0, 0 );
3604 /* must not happen */
3612 config_back_bind( Operation *op, SlapReply *rs )
3614 if ( be_isroot_pw( op ) ) {
3615 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
3616 /* frontend sends result */
3617 return LDAP_SUCCESS;
3620 rs->sr_err = LDAP_INVALID_CREDENTIALS;
3621 send_ldap_result( op, rs );
3627 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
3631 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
3633 rs->sr_attrs = op->ors_attrs;
3634 rs->sr_entry = ce->ce_entry;
3636 rc = send_search_entry( op, rs );
3638 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
3639 if ( ce->ce_kids ) {
3640 rc = config_send( op, rs, ce->ce_kids, 1 );
3641 if ( rc ) return rc;
3644 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
3645 rc = config_send( op, rs, ce, 0 );
3653 static ConfigTable *
3654 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
3659 for (j=0; j<nocs; j++) {
3660 for (i=0; colst[j]->co_table[i].name; i++)
3661 if ( colst[j]->co_table[i].ad == ad ) {
3662 ca->table = colst[j]->co_type;
3663 return &colst[j]->co_table[i];
3669 /* Sort the attributes of the entry according to the order defined
3670 * in the objectclass, with required attributes occurring before
3671 * allowed attributes. For any attributes with sequencing dependencies
3672 * (e.g., rootDN must be defined after suffix) the objectclass must
3673 * list the attributes in the desired sequence.
3676 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
3678 Attribute *a, *head = NULL, *tail = NULL, **prev;
3681 for (i=0; i<nocs; i++) {
3682 if ( colst[i]->co_oc->soc_required ) {
3683 AttributeType **at = colst[i]->co_oc->soc_required;
3684 for (j=0; at[j]; j++) {
3685 for (a=e->e_attrs, prev=&e->e_attrs; a;
3686 prev = &(*prev)->a_next, a=a->a_next) {
3687 if ( a->a_desc == at[j]->sat_ad ) {
3701 if ( colst[i]->co_oc->soc_allowed ) {
3702 AttributeType **at = colst[i]->co_oc->soc_allowed;
3703 for (j=0; at[j]; j++) {
3704 for (a=e->e_attrs, prev=&e->e_attrs; a;
3705 prev = &(*prev)->a_next, a=a->a_next) {
3706 if ( a->a_desc == at[j]->sat_ad ) {
3722 tail->a_next = e->e_attrs;
3728 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
3730 Attribute *a = NULL;
3731 AttributeDescription *ad;
3741 Modifications *ml = ptr;
3743 vals = ml->sml_values;
3746 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
3747 rc = ordered_value_sort( a, 1 );
3749 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
3750 ad->ad_cname.bv_val );
3754 for ( i=0; vals[i].bv_val; i++ ) {
3755 ca->line = vals[i].bv_val;
3756 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
3757 ca->line[0] == '{' ) {
3758 char *idx = strchr( ca->line, '}' );
3759 if ( idx ) ca->line = idx+1;
3761 rc = config_parse_vals( ct, ca, i );
3770 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
3773 struct berval rtype, rval;
3775 AttributeDescription *ad = NULL;
3777 dnRdn( &e->e_name, rdn );
3778 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
3779 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
3780 rtype.bv_val = rdn->bv_val;
3781 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
3784 slap_bv2ad( &rtype, &ad, &rs->sr_text );
3785 a = attr_find( e->e_attrs, ad );
3786 if (!a ) return LDAP_NAMING_VIOLATION;
3793 config_rename_kids( CfEntryInfo *ce )
3796 struct berval rdn, nrdn;
3798 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
3799 dnRdn ( &ce2->ce_entry->e_name, &rdn );
3800 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
3801 free( ce2->ce_entry->e_name.bv_val );
3802 free( ce2->ce_entry->e_nname.bv_val );
3803 build_new_dn( &ce2->ce_entry->e_name, &ce->ce_entry->e_name,
3805 build_new_dn( &ce2->ce_entry->e_nname, &ce->ce_entry->e_nname,
3807 config_rename_kids( ce2 );
3812 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
3813 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
3814 struct berval *nnewrdn, int use_ldif )
3818 struct berval odn, ondn;
3822 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
3823 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
3826 free( a->a_vals[0].bv_val );
3827 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
3828 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
3829 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
3830 strcpy( a->a_vals[0].bv_val, ptr1 );
3832 if ( a->a_nvals != a->a_vals ) {
3833 free( a->a_nvals[0].bv_val );
3834 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
3835 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
3836 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
3837 strcpy( a->a_nvals[0].bv_val, ptr1 );
3840 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
3841 BackendDB *be = op->o_bd;
3842 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
3843 struct berval dn, ndn, xdn, xndn;
3845 op->o_bd = &cfb->cb_db;
3847 /* Save current rootdn; use the underlying DB's rootdn */
3851 xndn = op->o_req_ndn;
3852 op->o_dn = op->o_bd->be_rootdn;
3853 op->o_ndn = op->o_bd->be_rootndn;
3855 op->o_req_ndn = ondn;
3857 scp = op->o_callback;
3858 op->o_callback = ≻
3859 op->orr_newrdn = *newrdn;
3860 op->orr_nnewrdn = *nnewrdn;
3861 op->orr_newSup = NULL;
3862 op->orr_nnewSup = NULL;
3863 op->orr_deleteoldrdn = 1;
3864 op->orr_modlist = NULL;
3865 slap_modrdn2mods( op, rs );
3866 slap_mods_opattrs( op, &op->orr_modlist, 1 );
3867 rc = op->o_bd->be_modrdn( op, rs );
3868 slap_mods_free( op->orr_modlist, 1 );
3871 op->o_callback = scp;
3875 op->o_req_ndn = xndn;
3878 free( ondn.bv_val );
3880 config_rename_kids( e->e_private );
3885 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
3886 Entry *e, int idx, int tailindex, int use_ldif )
3888 struct berval ival, newrdn, nnewrdn;
3891 char ibuf[32], *ptr1, *ptr2 = NULL;
3894 rc = config_rename_attr( rs, e, &rdn, &a );
3895 if ( rc ) return rc;
3898 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
3899 if ( ival.bv_len >= sizeof( ibuf ) ) {
3900 return LDAP_NAMING_VIOLATION;
3903 newrdn.bv_len = rdn.bv_len + ival.bv_len;
3904 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
3907 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
3908 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3911 ptr2 = ber_bvchr( &rdn, '}' );
3915 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
3917 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
3918 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
3919 a->a_desc->ad_cname.bv_len );
3921 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3922 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
3926 /* Do the equivalent of ModRDN */
3927 /* Replace DN / NDN */
3928 newrdn.bv_len = ptr1 - newrdn.bv_val;
3929 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
3930 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
3932 free( nnewrdn.bv_val );
3933 free( newrdn.bv_val );
3938 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
3939 SlapReply *rs, int *renum, int *ibase )
3942 int index = -1, gotindex = 0, nsibs, rc = 0;
3943 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
3944 char *ptr1, *ptr2 = NULL;
3947 if ( renum ) *renum = 0;
3949 /* These entries don't get indexed/renumbered */
3950 if ( ce_type == Cft_Global ) return 0;
3951 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
3953 if ( ce_type == Cft_Module )
3956 /* See if the rdn has an index already */
3957 dnRdn( &e->e_name, &rdn );
3958 if ( ce_type == Cft_Database ) {
3959 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
3960 "frontend", STRLENOF("frontend") ))
3962 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
3963 "config", STRLENOF("config") ))
3966 ptr1 = ber_bvchr( &e->e_name, '{' );
3967 if ( ptr1 && ptr1 < &e->e_name.bv_val[ rdn.bv_len ] ) {
3969 ptr2 = strchr( ptr1, '}' );
3970 if ( !ptr2 || ptr2 > &e->e_name.bv_val[ rdn.bv_len ] )
3971 return LDAP_NAMING_VIOLATION;
3972 if ( ptr2-ptr1 == 1)
3973 return LDAP_NAMING_VIOLATION;
3975 index = strtol( ptr1 + 1, &next, 10 );
3976 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
3977 return LDAP_NAMING_VIOLATION;
3980 /* Special case, we allow -1 for the frontendDB */
3981 if ( index != -1 || !isfrontend )
3982 return LDAP_NAMING_VIOLATION;
3984 if ( isconfig && index != 0 ){
3985 return LDAP_NAMING_VIOLATION;
3989 /* count related kids */
3990 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
3991 if ( ce->ce_type == ce_type ) nsibs++;
3994 /* account for -1 frontend */
3995 if ( ce_type == Cft_Database )
3998 if ( index != nsibs ) {
4000 if ( index < nsibs ) {
4001 if ( tailindex ) return LDAP_NAMING_VIOLATION;
4002 /* Siblings need to be renumbered */
4003 if ( index != -1 || !isfrontend )
4007 /* config DB is always "0" */
4008 if ( isconfig && index == -1 ) {
4011 if (( !isfrontend && index == -1 ) || ( index > nsibs ) ){
4015 /* just make index = nsibs */
4017 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
4020 if ( ibase ) *ibase = index;
4021 if ( renum ) *renum = renumber;
4026 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
4031 co.co_name = &oc->soc_cname;
4032 cop = avl_find( CfOcTree, &co, CfOc_cmp );
4036 /* check for duplicates */
4037 for ( i = 0; i < *nocs; i++ ) {
4038 if ( *copp && (*copp)[i] == cop ) {
4044 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
4045 if ( tmp == NULL ) {
4049 (*copp)[*nocs] = cop;
4054 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
4055 if ( count_oc( *sups, copp, nocs ) ) {
4064 count_ocs( Attribute *oc_at, int *nocs )
4067 ConfigOCs **colst = NULL;
4071 for ( i = 0; !BER_BVISNULL( &oc_at->a_nvals[i] ); i++ )
4075 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
4077 assert( oc != NULL );
4078 if ( count_oc( oc, &colst, nocs ) ) {
4088 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4090 /* Leftover from RE23. Never parse this entry */
4091 return LDAP_COMPARE_TRUE;
4095 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4099 /* This entry is hardcoded, don't re-parse it */
4100 if ( p->ce_type == Cft_Global ) {
4101 cfn = p->ce_private;
4102 ca->ca_private = cfn;
4103 return LDAP_COMPARE_TRUE;
4105 if ( p->ce_type != Cft_Schema )
4106 return LDAP_CONSTRAINT_VIOLATION;
4108 cfn = ch_calloc( 1, sizeof(ConfigFile) );
4109 ca->ca_private = cfn;
4110 cfo = p->ce_private;
4111 cfn->c_sibs = cfo->c_kids;
4113 return LDAP_SUCCESS;
4117 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4119 if ( p->ce_type != Cft_Global ) {
4120 return LDAP_CONSTRAINT_VIOLATION;
4122 /* config must be {0}, nothing else allowed */
4123 if ( !strncmp( e->e_nname.bv_val, "olcDatabase={0}", STRLENOF("olcDatabase={0}")) &&
4124 strncmp( e->e_nname.bv_val + STRLENOF("olcDatabase={0}"), "config,", STRLENOF("config,") )) {
4125 return LDAP_CONSTRAINT_VIOLATION;
4127 ca->be = frontendDB; /* just to get past check_vals */
4128 return LDAP_SUCCESS;
4132 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4134 if ( p->ce_type != Cft_Global ) {
4135 return LDAP_CONSTRAINT_VIOLATION;
4137 return LDAP_SUCCESS;
4141 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4143 if ( p->ce_type != Cft_Global ) {
4144 return LDAP_CONSTRAINT_VIOLATION;
4146 return LDAP_SUCCESS;
4150 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4152 if ( p->ce_type != Cft_Database ) {
4153 return LDAP_CONSTRAINT_VIOLATION;
4156 return LDAP_SUCCESS;
4160 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
4165 AttributeDescription *ad;
4170 if ( cfn->c_cr_head ) {
4171 struct berval bv = BER_BVC("olcDitContentRules");
4173 slap_bv2ad( &bv, &ad, &text );
4174 ct = config_find_table( colst, nocs, ad, ca );
4175 config_del_vals( ct, ca );
4177 if ( cfn->c_oc_head ) {
4178 struct berval bv = BER_BVC("olcObjectClasses");
4180 slap_bv2ad( &bv, &ad, &text );
4181 ct = config_find_table( colst, nocs, ad, ca );
4182 config_del_vals( ct, ca );
4184 if ( cfn->c_at_head ) {
4185 struct berval bv = BER_BVC("olcAttributeTypes");
4187 slap_bv2ad( &bv, &ad, &text );
4188 ct = config_find_table( colst, nocs, ad, ca );
4189 config_del_vals( ct, ca );
4191 if ( cfn->c_syn_head ) {
4192 struct berval bv = BER_BVC("olcLdapSyntaxes");
4194 slap_bv2ad( &bv, &ad, &text );
4195 ct = config_find_table( colst, nocs, ad, ca );
4196 config_del_vals( ct, ca );
4198 if ( cfn->c_om_head ) {
4199 struct berval bv = BER_BVC("olcObjectIdentifier");
4201 slap_bv2ad( &bv, &ad, &text );
4202 ct = config_find_table( colst, nocs, ad, ca );
4203 config_del_vals( ct, ca );
4205 cfo = p->ce_private;
4206 cfo->c_kids = cfn->c_sibs;
4211 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
4213 int rc = LDAP_CONSTRAINT_VIOLATION;
4216 if ( (*cop)->co_ldadd ) {
4217 rc = (*cop)->co_ldadd( last, e, ca );
4218 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4223 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
4224 ConfigOCs co = { 0 };
4226 co.co_name = &(*ocp)->soc_cname;
4227 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
4228 if ( *cop == NULL ) {
4232 rc = config_add_oc( cop, last, e, ca );
4233 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4241 /* Parse an LDAP entry into config directives */
4243 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
4244 int *renum, Operation *op )
4246 CfEntryInfo *ce, *last = NULL;
4247 ConfigOCs co, *coptr, **colst;
4248 Attribute *a, *oc_at, *soc_at;
4249 int i, ibase = -1, nocs, rc = 0;
4252 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
4254 memset( ca, 0, sizeof(ConfigArgs));
4256 /* Make sure parent exists and entry does not. But allow
4257 * Databases and Overlays to be inserted. Don't do any
4258 * auto-renumbering if manageDSAit control is present.
4260 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
4262 if ( ( op && op->o_managedsait ) ||
4263 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
4264 ce->ce_type != Cft_Module ) )
4266 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4267 "DN=\"%s\" already exists\n",
4268 log_prefix, e->e_name.bv_val, 0 );
4269 return LDAP_ALREADY_EXISTS;
4273 dnParent( &e->e_nname, &pdn );
4275 /* If last is NULL, the new entry is the root/suffix entry,
4276 * otherwise last should be the parent.
4278 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
4280 rs->sr_matched = last->ce_entry->e_name.bv_val;
4282 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4283 "DN=\"%s\" not child of DN=\"%s\"\n",
4284 log_prefix, e->e_name.bv_val,
4285 last->ce_entry->e_name.bv_val );
4286 return LDAP_NO_SUCH_OBJECT;
4290 /* No parent, must be root. This will never happen... */
4291 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
4292 return LDAP_NO_SUCH_OBJECT;
4295 if ( last && !access_allowed( op, last->ce_entry,
4296 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
4298 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4299 "DN=\"%s\" no write access to \"children\" of parent\n",
4300 log_prefix, e->e_name.bv_val, 0 );
4301 return LDAP_INSUFFICIENT_ACCESS;
4305 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4307 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4308 "DN=\"%s\" no objectClass\n",
4309 log_prefix, e->e_name.bv_val, 0 );
4310 return LDAP_OBJECT_CLASS_VIOLATION;
4313 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4315 ObjectClass *soc = NULL;
4316 char textbuf[ SLAP_TEXT_BUFLEN ];
4317 const char *text = textbuf;
4319 /* FIXME: check result */
4320 rc = structural_class( oc_at->a_nvals, &soc, NULL,
4321 &text, textbuf, sizeof(textbuf), NULL );
4322 if ( rc != LDAP_SUCCESS ) {
4323 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4324 "DN=\"%s\" no structural objectClass (%s)\n",
4325 log_prefix, e->e_name.bv_val, text );
4328 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
4329 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4330 if ( soc_at == NULL ) {
4331 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4332 "DN=\"%s\" no structural objectClass; "
4333 "unable to merge computed class %s\n",
4334 log_prefix, e->e_name.bv_val,
4335 soc->soc_cname.bv_val );
4336 return LDAP_OBJECT_CLASS_VIOLATION;
4339 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4340 "DN=\"%s\" no structural objectClass; "
4341 "computed objectClass %s merged\n",
4342 log_prefix, e->e_name.bv_val,
4343 soc->soc_cname.bv_val );
4346 /* Fake the coordinates based on whether we're part of an
4347 * LDAP Add or if reading the config dir
4350 ca->fname = "slapd";
4353 ca->fname = cfdir.bv_val;
4358 co.co_name = &soc_at->a_nvals[0];
4359 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
4360 if ( coptr == NULL ) {
4361 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4362 "DN=\"%s\" no structural objectClass in configuration table\n",
4363 log_prefix, e->e_name.bv_val, 0 );
4364 return LDAP_OBJECT_CLASS_VIOLATION;
4367 /* Only the root can be Cft_Global, everything else must
4368 * have a parent. Only limited nesting arrangements are allowed.
4370 rc = LDAP_CONSTRAINT_VIOLATION;
4371 if ( coptr->co_type == Cft_Global && !last ) {
4372 cfn = cfb->cb_config;
4373 ca->ca_private = cfn;
4374 ca->be = frontendDB; /* just to get past check_vals */
4378 colst = count_ocs( oc_at, &nocs );
4380 /* Check whether the Add is allowed by its parent, and do
4381 * any necessary arg setup
4384 rc = config_add_oc( &coptr, last, e, ca );
4385 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4386 for ( i = 0; i<nocs; i++ ) {
4387 /* Already checked these */
4388 if ( colst[i]->co_oc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
4390 if ( colst[i]->co_ldadd &&
4391 ( rc = colst[i]->co_ldadd( last, e, ca ))
4392 != LDAP_CONSTRAINT_VIOLATION ) {
4398 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4399 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4400 "DN=\"%s\" no structural objectClass add function\n",
4401 log_prefix, e->e_name.bv_val, 0 );
4402 return LDAP_OBJECT_CLASS_VIOLATION;
4406 /* Add the entry but don't parse it, we already have its contents */
4407 if ( rc == LDAP_COMPARE_TRUE ) {
4412 if ( rc != LDAP_SUCCESS )
4415 /* Parse all the values and check for simple syntax errors before
4416 * performing any set actions.
4418 * If doing an LDAPadd, check for indexed names and any necessary
4419 * renaming/renumbering. Entries that don't need indexed names are
4420 * ignored. Entries that need an indexed name and arrive without one
4421 * are assigned to the end. Entries that arrive with an index may
4422 * cause the following entries to be renumbered/bumped down.
4424 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
4425 * don't allow Adding an entry with an index that's already in use.
4426 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
4428 * These entries can have auto-assigned indexes (appended to the end)
4429 * but only the other types support auto-renumbering of siblings.
4432 rc = check_name_index( last, coptr->co_type, e, rs, renum,
4437 if ( renum && *renum && coptr->co_type != Cft_Database &&
4438 coptr->co_type != Cft_Overlay )
4440 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
4441 "operation requires sibling renumbering" );
4442 rc = LDAP_UNWILLING_TO_PERFORM;
4447 init_config_argv( ca );
4449 /* Make sure we process attrs in the required order */
4450 sort_attrs( e, colst, nocs );
4452 for ( a = e->e_attrs; a; a = a->a_next ) {
4453 if ( a == oc_at ) continue;
4454 ct = config_find_table( colst, nocs, a->a_desc, ca );
4455 if ( !ct ) continue; /* user data? */
4456 rc = check_vals( ct, ca, a, 1 );
4457 if ( rc ) goto done_noop;
4460 /* Basic syntax checks are OK. Do the actual settings. */
4461 for ( a=e->e_attrs; a; a=a->a_next ) {
4462 if ( a == oc_at ) continue;
4463 ct = config_find_table( colst, nocs, a->a_desc, ca );
4464 if ( !ct ) continue; /* user data? */
4465 for (i=0; a->a_vals[i].bv_val; i++) {
4467 ca->line = a->a_vals[i].bv_val;
4468 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
4469 ptr = strchr( ca->line, '}' );
4471 iptr = strchr( ca->line, '{' );
4475 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
4477 ca->valx = strtol( iptr+1, NULL, 0 );
4484 rc = config_parse_add( ct, ca, i );
4492 /* Newly added databases and overlays need to be started up */
4493 if ( CONFIG_ONLINE_ADD( ca )) {
4494 if ( colst[0]->co_type == Cft_Database ) {
4495 rc = backend_startup_one( ca->be, &ca->reply );
4497 } else if ( colst[0]->co_type == Cft_Overlay ) {
4498 if ( ca->bi->bi_db_open ) {
4499 BackendInfo *bi_orig = ca->be->bd_info;
4500 ca->be->bd_info = ca->bi;
4501 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
4502 ca->be->bd_info = bi_orig;
4504 } else if ( ca->cleanup ) {
4505 rc = ca->cleanup( ca );
4508 if (ca->cr_msg[0] == '\0')
4509 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
4511 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
4512 ca->log, ca->cr_msg, ca->argv[1] );
4519 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
4520 ce->ce_parent = last;
4521 ce->ce_entry = entry_dup( e );
4522 ce->ce_entry->e_private = ce;
4523 ce->ce_type = colst[0]->co_type;
4526 ce->ce_private = ca->ca_private;
4527 ca->ca_entry = ce->ce_entry;
4530 } else if ( last->ce_kids ) {
4531 CfEntryInfo *c2, **cprev;
4533 /* Advance to first of this type */
4534 cprev = &last->ce_kids;
4535 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
4536 cprev = &c2->ce_sibs;
4539 /* Account for the (-1) frontendDB entry */
4540 if ( ce->ce_type == Cft_Database ) {
4541 if ( ca->be == frontendDB )
4543 else if ( ibase != -1 )
4548 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
4549 cprev = &c2->ce_sibs;
4555 for ( i=0; i<ibase; i++ ) {
4557 cprev = &c2->ce_sibs;
4560 ce->ce_sibs = *cprev;
4568 if ( (colst[0]->co_type == Cft_Database) && ca->be ) {
4569 if ( ca->be != frontendDB )
4570 backend_destroy_one( ca->be, 1 );
4571 } else if ( (colst[0]->co_type == Cft_Overlay) && ca->bi ) {
4572 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
4573 } else if ( colst[0]->co_type == Cft_Schema ) {
4574 schema_destroy_one( ca, colst, nocs, last );
4579 ch_free( ca->argv );
4580 if ( colst ) ch_free( colst );
4584 #define BIGTMP 10000
4586 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
4587 int base, int rebase, int max, int use_ldif )
4589 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
4590 ConfigType etype = ce->ce_type;
4591 int count = 0, rc = 0;
4593 /* Reverse ce list */
4594 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
4595 if (ce2->ce_type != etype) {
4600 ce2->ce_sibs = cetmp;
4603 if ( max && count >= max ) {
4609 /* Move original to a temp name until increments are done */
4611 ce->ce_entry->e_private = NULL;
4612 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4613 base+BIGTMP, 0, use_ldif );
4614 ce->ce_entry->e_private = ce;
4616 /* start incrementing */
4617 for (ce2=cetmp; ce2; ce2=ce3) {
4619 ce2->ce_sibs = cerem;
4622 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
4623 count+base, 0, use_ldif );
4627 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4628 base, 0, use_ldif );
4633 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
4634 CfEntryInfo *ce2, int old, int use_ldif )
4638 /* Renumber original to a temp value */
4639 ce->ce_entry->e_private = NULL;
4640 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4641 old+BIGTMP, 0, use_ldif );
4642 ce->ce_entry->e_private = ce;
4644 /* start decrementing */
4645 for (; ce2 != ce; ce2=ce2->ce_sibs) {
4646 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
4647 count+old, 0, use_ldif );
4650 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4651 count+old, 0, use_ldif );
4654 /* Parse an LDAP entry into config directives, then store in underlying
4658 config_back_add( Operation *op, SlapReply *rs )
4664 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
4665 NULL, ACL_WADD, NULL )) {
4666 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4671 * Check for attribute ACL
4673 if ( !acl_check_modlist( op, op->ora_e, op->orm_modlist )) {
4674 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4675 rs->sr_text = "no write access to attribute";
4679 cfb = (CfBackInfo *)op->o_bd->be_private;
4681 /* add opattrs for syncprov */
4683 char textbuf[SLAP_TEXT_BUFLEN];
4684 size_t textlen = sizeof textbuf;
4685 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1,
4686 &rs->sr_text, textbuf, sizeof( textbuf ) );
4687 if ( rs->sr_err != LDAP_SUCCESS )
4689 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
4690 if ( rs->sr_err != LDAP_SUCCESS ) {
4691 Debug( LDAP_DEBUG_TRACE,
4692 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
4693 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
4698 ldap_pvt_thread_pool_pause( &connection_pool );
4701 * 1) check for existence of entry
4702 * 2) check for sibling renumbering
4703 * 3) perform internal add
4704 * 4) perform any necessary renumbering
4705 * 5) store entry in underlying database
4707 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
4708 if ( rs->sr_err != LDAP_SUCCESS ) {
4709 rs->sr_text = ca.cr_msg;
4714 CfEntryInfo *ce = ca.ca_entry->e_private;
4715 req_add_s addr = op->oq_add;
4716 op->o_tag = LDAP_REQ_MODRDN;
4717 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
4718 op->o_tag = LDAP_REQ_ADD;
4720 if ( rs->sr_err != LDAP_SUCCESS ) {
4725 if ( cfb->cb_use_ldif ) {
4726 BackendDB *be = op->o_bd;
4727 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4728 struct berval dn, ndn;
4730 op->o_bd = &cfb->cb_db;
4732 /* Save current rootdn; use the underlying DB's rootdn */
4735 op->o_dn = op->o_bd->be_rootdn;
4736 op->o_ndn = op->o_bd->be_rootndn;
4738 scp = op->o_callback;
4739 op->o_callback = ≻
4740 op->o_bd->be_add( op, rs );
4742 op->o_callback = scp;
4748 ldap_pvt_thread_pool_resume( &connection_pool );
4751 send_ldap_result( op, rs );
4752 slap_graduate_commit_csn( op );
4756 typedef struct delrec {
4757 struct delrec *next;
4763 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
4768 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
4769 ca->line[0] == '{' )
4771 char *ptr = strchr( ca->line + 1, '}' );
4775 ca->valx = strtol( ca->line + 1, &next, 0 );
4776 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
4782 rc = config_parse_add( ct, ca, i );
4790 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
4793 int rc = LDAP_UNWILLING_TO_PERFORM;
4795 Entry *e = ce->ce_entry;
4796 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
4801 delrec *dels = NULL, *deltail = NULL;
4803 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4804 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
4806 colst = count_ocs( oc_at, &nocs );
4808 /* make sure add/del flags are clear; should always be true */
4809 for ( s = save_attrs; s; s = s->a_next ) {
4810 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
4813 e->e_attrs = attrs_dup( e->e_attrs );
4815 init_config_argv( ca );
4818 ca->ca_private = ce->ce_private;
4820 ca->fname = "slapd";
4822 strcpy( ca->log, "back-config" );
4824 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
4825 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
4826 switch (ml->sml_op) {
4827 case LDAP_MOD_DELETE:
4828 case LDAP_MOD_REPLACE: {
4829 BerVarray vals = NULL, nvals = NULL;
4831 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
4833 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
4834 ml->sml_desc->ad_cname.bv_val );
4837 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4838 vals = ml->sml_values;
4839 nvals = ml->sml_nvalues;
4840 ml->sml_values = NULL;
4841 ml->sml_nvalues = NULL;
4843 /* If we're deleting by values, remember the indexes of the
4844 * values we deleted.
4846 if ( ct && ml->sml_values ) {
4848 i = ml->sml_numvals;
4849 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
4860 rc = modify_delete_vindex(e, &ml->sml_mod,
4861 get_permissiveModify(op),
4862 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
4863 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4864 ml->sml_values = vals;
4865 ml->sml_nvalues = nvals;
4870 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
4873 case SLAP_MOD_SOFTADD: {
4874 int mop = ml->sml_op;
4876 ml->sml_op = LDAP_MOD_ADD;
4878 if ( ct->arg_type & ARG_NO_INSERT ) {
4879 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
4881 navals = a->a_numvals;
4884 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
4885 if ( ml->sml_values[i].bv_val[0] == '{' &&
4888 char *next, *val = ml->sml_values[i].bv_val + 1;
4891 j = strtol( val, &next, 0 );
4892 if ( next == val || next[ 0 ] != '}' || j < navals ) {
4894 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
4895 ml->sml_desc->ad_cname.bv_val );
4899 rc = check_vals( ct, ca, ml, 0 );
4900 if ( rc ) goto out_noop;
4903 rc = modify_add_values(e, &ml->sml_mod,
4904 get_permissiveModify(op),
4905 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
4907 /* If value already exists, show success here
4908 * and ignore this operation down below.
4910 if ( mop == SLAP_MOD_SOFTADD ) {
4911 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
4921 case LDAP_MOD_INCREMENT: /* FIXME */
4926 if(rc != LDAP_SUCCESS) break;
4929 if ( rc == LDAP_SUCCESS) {
4930 /* check that the entry still obeys the schema */
4931 rc = entry_schema_check(op, e, NULL, 0, 0,
4932 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
4934 if ( rc ) goto out_noop;
4936 /* Basic syntax checks are OK. Do the actual settings. */
4937 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
4938 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
4939 if ( !ct ) continue;
4941 s = attr_find( save_attrs, ml->sml_desc );
4942 a = attr_find( e->e_attrs, ml->sml_desc );
4944 switch (ml->sml_op) {
4945 case LDAP_MOD_DELETE:
4946 case LDAP_MOD_REPLACE: {
4947 BerVarray vals = NULL, nvals = NULL;
4950 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4951 vals = ml->sml_values;
4952 nvals = ml->sml_nvalues;
4953 ml->sml_values = NULL;
4954 ml->sml_nvalues = NULL;
4957 if ( ml->sml_values )
4960 /* If we didn't delete the whole attribute */
4961 if ( ml->sml_values && a ) {
4962 struct berval *mvals;
4965 if ( ml->sml_nvalues )
4966 mvals = ml->sml_nvalues;
4968 mvals = ml->sml_values;
4970 /* use the indexes we saved up above */
4971 for (i=0; i < d->nidx; i++) {
4972 struct berval bv = *mvals++;
4973 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
4974 bv.bv_val[0] == '{' ) {
4975 ptr = strchr( bv.bv_val, '}' ) + 1;
4976 bv.bv_len -= ptr - bv.bv_val;
4979 ca->line = bv.bv_val;
4980 ca->valx = d->idx[i];
4981 rc = config_del_vals( ct, ca );
4982 if ( rc != LDAP_SUCCESS ) break;
4984 s->a_flags |= SLAP_ATTR_IXDEL;
4985 for (j=i+1; j < d->nidx; j++)
4986 if ( d->idx[j] >d->idx[i] )
4992 rc = config_del_vals( ct, ca );
4993 if ( rc ) rc = LDAP_OTHER;
4995 s->a_flags |= SLAP_ATTR_IXDEL;
4997 if ( ml->sml_values ) {
5002 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5003 ml->sml_values = vals;
5004 ml->sml_nvalues = nvals;
5006 if ( !vals || rc != LDAP_SUCCESS )
5009 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5012 for (i=0; ml->sml_values[i].bv_val; i++) {
5013 ca->line = ml->sml_values[i].bv_val;
5015 rc = config_modify_add( ct, ca, ml->sml_desc, i );
5018 a->a_flags |= SLAP_ATTR_IXADD;
5025 /* Undo for a failed operation */
5026 if ( rc != LDAP_SUCCESS ) {
5027 ConfigReply msg = ca->reply;
5028 for ( s = save_attrs; s; s = s->a_next ) {
5029 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
5030 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5031 ct = config_find_table( colst, nocs, s->a_desc, ca );
5032 a = attr_find( e->e_attrs, s->a_desc );
5034 /* clear the flag so the add check below will skip it */
5035 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5038 config_del_vals( ct, ca );
5040 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5041 ca->line = s->a_vals[i].bv_val;
5043 config_modify_add( ct, ca, s->a_desc, i );
5047 for ( a = e->e_attrs; a; a = a->a_next ) {
5048 if ( a->a_flags & SLAP_ATTR_IXADD ) {
5049 ct = config_find_table( colst, nocs, a->a_desc, ca );
5052 config_del_vals( ct, ca );
5053 s = attr_find( save_attrs, a->a_desc );
5055 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5056 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5057 ca->line = s->a_vals[i].bv_val;
5059 config_modify_add( ct, ca, s->a_desc, i );
5070 if ( rc == LDAP_SUCCESS ) {
5071 attrs_free( save_attrs );
5073 attrs_free( e->e_attrs );
5074 e->e_attrs = save_attrs;
5076 ch_free( ca->argv );
5077 if ( colst ) ch_free( colst );
5079 deltail = dels->next;
5088 config_back_modify( Operation *op, SlapReply *rs )
5091 CfEntryInfo *ce, *last;
5093 ConfigArgs ca = {0};
5096 AttributeDescription *rad = NULL;
5099 cfb = (CfBackInfo *)op->o_bd->be_private;
5101 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5104 rs->sr_matched = last->ce_entry->e_name.bv_val;
5105 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5109 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
5110 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5114 /* Get type of RDN */
5115 rdn = ce->ce_entry->e_nname;
5116 ptr = strchr( rdn.bv_val, '=' );
5117 rdn.bv_len = ptr - rdn.bv_val;
5118 slap_bv2ad( &rdn, &rad, &rs->sr_text );
5120 /* Some basic validation... */
5121 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5122 /* Don't allow Modify of RDN; must use ModRdn for that. */
5123 if ( ml->sml_desc == rad ) {
5124 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
5125 rs->sr_text = "Use modrdn to change the entry name";
5128 /* Internal update of contextCSN? */
5129 if ( ml->sml_desc == slap_schema.si_ad_contextCSN && op->o_conn->c_conn_idx == -1 ) {
5135 slap_mods_opattrs( op, &op->orm_modlist, 1 );
5138 ldap_pvt_thread_pool_pause( &connection_pool );
5141 * 1) perform the Modify on the cached Entry.
5142 * 2) verify that the Entry still satisfies the schema.
5143 * 3) perform the individual config operations.
5144 * 4) store Modified entry in underlying LDIF backend.
5146 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
5148 rs->sr_text = ca.cr_msg;
5149 } else if ( cfb->cb_use_ldif ) {
5150 BackendDB *be = op->o_bd;
5151 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5152 struct berval dn, ndn;
5154 op->o_bd = &cfb->cb_db;
5158 op->o_dn = op->o_bd->be_rootdn;
5159 op->o_ndn = op->o_bd->be_rootndn;
5161 scp = op->o_callback;
5162 op->o_callback = ≻
5163 op->o_bd->be_modify( op, rs );
5165 op->o_callback = scp;
5171 ldap_pvt_thread_pool_resume( &connection_pool );
5173 send_ldap_result( op, rs );
5174 slap_graduate_commit_csn( op );
5179 config_back_modrdn( Operation *op, SlapReply *rs )
5182 CfEntryInfo *ce, *last;
5186 cfb = (CfBackInfo *)op->o_bd->be_private;
5188 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5191 rs->sr_matched = last->ce_entry->e_name.bv_val;
5192 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5195 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
5196 NULL, ACL_WRITE, NULL )) {
5197 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5201 if ( ce->ce_parent )
5202 parent = ce->ce_parent->ce_entry;
5204 parent = (Entry *)&slap_entry_root;
5205 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
5206 NULL, ACL_WRITE, NULL )) {
5207 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5212 /* We don't allow moving objects to new parents.
5213 * Generally we only allow reordering a set of ordered entries.
5215 if ( op->orr_newSup ) {
5216 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5220 /* If newRDN == oldRDN, quietly succeed */
5221 dnRdn( &op->o_req_ndn, &rdn );
5222 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
5223 rs->sr_err = LDAP_SUCCESS;
5227 /* Current behavior, subject to change as needed:
5229 * For backends and overlays, we only allow renumbering.
5230 * For schema, we allow renaming with the same number.
5231 * Otherwise, the op is not allowed.
5234 if ( ce->ce_type == Cft_Schema ) {
5238 /* Can't alter the main cn=schema entry */
5239 if ( ce->ce_parent->ce_type == Cft_Global ) {
5240 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5241 rs->sr_text = "renaming not allowed for this entry";
5245 /* We could support this later if desired */
5246 ptr1 = ber_bvchr( &rdn, '}' );
5247 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5248 len = ptr1 - rdn.bv_val;
5249 if ( len != ptr2 - op->orr_newrdn.bv_val ||
5250 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
5251 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5252 rs->sr_text = "schema reordering not supported";
5255 } else if ( ce->ce_type == Cft_Database ||
5256 ce->ce_type == Cft_Overlay ) {
5257 char *ptr1, *ptr2, *iptr1, *iptr2;
5260 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
5261 if ( *iptr2 != '{' ) {
5262 rs->sr_err = LDAP_NAMING_VIOLATION;
5263 rs->sr_text = "new ordering index is required";
5267 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
5268 ptr1 = ber_bvchr( &rdn, '}' );
5269 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5271 rs->sr_err = LDAP_NAMING_VIOLATION;
5272 rs->sr_text = "new ordering index is required";
5276 len1 = ptr1 - rdn.bv_val;
5277 len2 = ptr2 - op->orr_newrdn.bv_val;
5279 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
5280 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
5281 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5282 rs->sr_text = "changing database/overlay type not allowed";
5285 ixold = strtol( iptr1, NULL, 0 );
5286 ixnew = strtol( iptr2, &ptr1, 0 );
5287 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
5288 rs->sr_err = LDAP_NAMING_VIOLATION;
5291 /* config DB is always 0, cannot be changed */
5292 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
5293 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
5297 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5298 rs->sr_text = "renaming not supported for this entry";
5302 ldap_pvt_thread_pool_pause( &connection_pool );
5304 if ( ce->ce_type == Cft_Schema ) {
5305 req_modrdn_s modr = op->oq_modrdn;
5308 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
5309 if ( rs->sr_err == LDAP_SUCCESS ) {
5310 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
5311 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
5314 op->oq_modrdn = modr;
5316 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
5317 req_modrdn_s modr = op->oq_modrdn;
5320 /* Advance to first of this type */
5321 cprev = &ce->ce_parent->ce_kids;
5322 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
5323 cprev = &ce2->ce_sibs;
5326 /* Skip the -1 entry */
5327 if ( ce->ce_type == Cft_Database ) {
5328 cprev = &ce2->ce_sibs;
5334 /* Remove from old slot */
5335 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
5336 cprev = &ce2->ce_sibs;
5337 *cprev = ce->ce_sibs;
5338 ceold = ce->ce_sibs;
5340 /* Insert into new slot */
5342 for ( i=0; i<ixnew; i++ ) {
5346 cprev = &ce2->ce_sibs;
5348 ce->ce_sibs = *cprev;
5353 /* NOTE: These should be encoded in the OC tables, not inline here */
5354 if ( ce->ce_type == Cft_Database )
5355 backend_db_move( ce->ce_be, ixnew );
5356 else if ( ce->ce_type == Cft_Overlay )
5357 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
5359 if ( ixold < ixnew ) {
5360 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
5363 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
5364 ixold - ixnew, cfb->cb_use_ldif );
5366 op->oq_modrdn = modr;
5369 ldap_pvt_thread_pool_resume( &connection_pool );
5371 send_ldap_result( op, rs );
5376 config_back_delete( Operation *op, SlapReply *rs )
5378 #ifdef SLAP_CONFIG_DELETE
5380 CfEntryInfo *ce, *last, *ce2;
5382 cfb = (CfBackInfo *)op->o_bd->be_private;
5384 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5387 rs->sr_matched = last->ce_entry->e_name.bv_val;
5388 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5389 } else if ( ce->ce_kids ) {
5390 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5391 } else if ( ce->ce_type == Cft_Overlay || ce->ce_type == Cft_Database ){
5395 ldap_pvt_thread_pool_pause( &connection_pool );
5397 if ( ce->ce_type == Cft_Overlay ){
5398 overlay_remove( ce->ce_be, (slap_overinst *)ce->ce_bi );
5399 } else { /* Cft_Database*/
5400 if ( ce->ce_be == frontendDB || ce->ce_be == op->o_bd ){
5401 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5402 rs->sr_text = "Cannot delete config or frontend database";
5403 ldap_pvt_thread_pool_resume( &connection_pool );
5406 if ( ce->ce_be->bd_info->bi_db_close ) {
5407 ce->ce_be->bd_info->bi_db_close( ce->ce_be, NULL );
5409 backend_destroy_one( ce->ce_be, 1);
5412 /* remove CfEntryInfo from the siblings list */
5413 if ( ce->ce_parent->ce_kids == ce ) {
5414 ce->ce_parent->ce_kids = ce->ce_sibs;
5416 for ( ce2 = ce->ce_parent->ce_kids ; ce2; ce2 = ce2->ce_sibs ) {
5417 if ( ce2->ce_sibs == ce ) {
5418 ce2->ce_sibs = ce->ce_sibs;
5424 /* remove from underlying database */
5425 if ( cfb->cb_use_ldif ) {
5426 BackendDB *be = op->o_bd;
5427 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5428 struct berval dn, ndn, req_dn, req_ndn;
5430 op->o_bd = &cfb->cb_db;
5434 req_dn = op->o_req_dn;
5435 req_ndn = op->o_req_ndn;
5437 op->o_dn = op->o_bd->be_rootdn;
5438 op->o_ndn = op->o_bd->be_rootndn;
5439 op->o_req_dn = ce->ce_entry->e_name;
5440 op->o_req_ndn = ce->ce_entry->e_nname;
5442 scp = op->o_callback;
5443 op->o_callback = ≻
5444 op->o_bd->be_delete( op, rs );
5446 op->o_callback = scp;
5449 op->o_req_dn = req_dn;
5450 op->o_req_ndn = req_ndn;
5453 /* renumber siblings */
5454 iptr = ber_bvchr( &op->o_req_ndn, '{' ) + 1;
5455 ixold = strtol( iptr, NULL, 0 );
5456 for (ce2 = ce->ce_sibs, count=0; ce2; ce2=ce2->ce_sibs) {
5457 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5458 count+ixold, 0, cfb->cb_use_ldif );
5462 ce->ce_entry->e_private=NULL;
5463 entry_free(ce->ce_entry);
5465 ldap_pvt_thread_pool_resume( &connection_pool );
5467 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5470 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5471 #endif /* SLAP_CONFIG_DELETE */
5473 send_ldap_result( op, rs );
5478 config_back_search( Operation *op, SlapReply *rs )
5481 CfEntryInfo *ce, *last;
5484 cfb = (CfBackInfo *)op->o_bd->be_private;
5486 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5489 rs->sr_matched = last->ce_entry->e_name.bv_val;
5490 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5493 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
5494 ACL_SEARCH, NULL, &mask ))
5496 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
5497 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5499 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5503 switch ( op->ors_scope ) {
5504 case LDAP_SCOPE_BASE:
5505 case LDAP_SCOPE_SUBTREE:
5506 config_send( op, rs, ce, 0 );
5509 case LDAP_SCOPE_ONELEVEL:
5510 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
5511 config_send( op, rs, ce, 1 );
5516 rs->sr_err = LDAP_SUCCESS;
5518 send_ldap_result( op, rs );
5522 /* no-op, we never free entries */
5523 int config_entry_release(
5528 if ( !e->e_private ) {
5531 return LDAP_SUCCESS;
5534 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
5536 int config_back_entry_get(
5540 AttributeDescription *at,
5545 CfEntryInfo *ce, *last;
5546 int rc = LDAP_NO_SUCH_OBJECT;
5548 cfb = (CfBackInfo *)op->o_bd->be_private;
5550 ce = config_find_base( cfb->cb_root, ndn, &last );
5552 *ent = ce->ce_entry;
5555 if ( oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
5556 rc = LDAP_NO_SUCH_ATTRIBUTE;
5566 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
5567 ConfigTable *ct, ConfigArgs *c )
5571 for (; at && *at; at++) {
5572 /* Skip the naming attr */
5573 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
5575 for (i=0;ct[i].name;i++) {
5576 if (ct[i].ad == (*at)->sat_ad) {
5577 rc = config_get_vals(&ct[i], c);
5578 /* NOTE: tolerate that config_get_vals()
5579 * returns success with no values */
5580 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
5581 if ( c->rvalue_nvals )
5582 rc = attr_merge(e, ct[i].ad, c->rvalue_vals,
5585 slap_syntax_validate_func *validate =
5586 ct[i].ad->ad_type->sat_syntax->ssyn_validate;
5589 for ( j=0; c->rvalue_vals[j].bv_val; j++ ) {
5590 rc = ordered_value_validate( ct[i].ad,
5591 &c->rvalue_vals[j], LDAP_MOD_ADD );
5593 Debug( LDAP_DEBUG_ANY,
5594 "config_build_attrs: error %d on %s value #%d\n",
5595 rc, ct[i].ad->ad_cname.bv_val, j );
5601 rc = attr_merge_normalize(e, ct[i].ad,
5602 c->rvalue_vals, NULL);
5604 ber_bvarray_free( c->rvalue_nvals );
5605 ber_bvarray_free( c->rvalue_vals );
5607 Debug( LDAP_DEBUG_ANY,
5608 "config_build_attrs: error %d on %s\n",
5609 rc, ct[i].ad->ad_cname.bv_val, 0 );
5621 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
5622 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
5624 Entry *e = entry_alloc();
5625 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5627 struct berval ad_name;
5628 AttributeDescription *ad = NULL;
5631 const char *text = "";
5635 CfEntryInfo *ceprev = NULL;
5637 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
5640 ce->ce_type = main->co_type;
5641 ce->ce_parent = parent;
5643 pdn = parent->ce_entry->e_nname;
5644 if ( parent->ce_kids && parent->ce_kids->ce_type <= ce->ce_type )
5645 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
5646 ceprev->ce_type <= ce->ce_type;
5647 ceprev = ceprev->ce_sibs );
5652 ce->ce_private = c->ca_private;
5656 build_new_dn( &e->e_name, &pdn, rdn, NULL );
5657 ber_dupbv( &e->e_nname, &e->e_name );
5659 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
5660 main->co_name, NULL );
5662 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
5663 extra->co_name, NULL );
5664 ptr = strchr(rdn->bv_val, '=');
5665 ad_name.bv_val = rdn->bv_val;
5666 ad_name.bv_len = ptr - rdn->bv_val;
5667 rc = slap_bv2ad( &ad_name, &ad, &text );
5672 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
5673 attr_merge_normalize_one(e, ad, &val, NULL );
5676 c->table = main->co_type;
5677 if ( oc->soc_required ) {
5678 rc = config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
5679 if ( rc ) goto fail;
5682 if ( oc->soc_allowed ) {
5683 rc = config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
5684 if ( rc ) goto fail;
5689 c->table = extra->co_type;
5690 if ( oc->soc_required ) {
5691 rc = config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
5692 if ( rc ) goto fail;
5695 if ( oc->soc_allowed ) {
5696 rc = config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
5697 if ( rc ) goto fail;
5701 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5702 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
5703 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
5704 if ( rc != LDAP_SUCCESS ) {
5706 Debug( LDAP_DEBUG_ANY,
5707 "config_build_entry: build \"%s\" failed: \"%s\"\n",
5708 rdn->bv_val, text, 0);
5711 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
5714 op->ora_modlist = NULL;
5715 slap_add_opattrs( op, NULL, NULL, 0, 0 );
5716 if ( !op->o_noop ) {
5717 op->o_bd->be_add( op, rs );
5718 if ( ( rs->sr_err != LDAP_SUCCESS )
5719 && (rs->sr_err != LDAP_ALREADY_EXISTS) ) {
5725 ce->ce_sibs = ceprev->ce_sibs;
5726 ceprev->ce_sibs = ce;
5727 } else if ( parent ) {
5728 ce->ce_sibs = parent->ce_kids;
5729 parent->ce_kids = ce;
5736 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
5737 Operation *op, SlapReply *rs )
5740 ConfigFile *cf = c->ca_private;
5742 struct berval bv, rdn;
5744 for (; cf; cf=cf->c_sibs, c->depth++) {
5745 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
5746 !cf->c_om_head && !cf->c_syn_head ) continue;
5747 c->value_dn.bv_val = c->log;
5748 LUTIL_SLASHPATH( cf->c_file.bv_val );
5749 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
5754 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
5756 ptr = strchr( bv.bv_val, '.' );
5758 bv.bv_len = ptr - bv.bv_val;
5759 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
5760 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
5761 /* FIXME: how can indicate error? */
5764 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
5766 c->value_dn.bv_len += bv.bv_len;
5767 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
5771 e = config_build_entry( op, rs, ceparent, c, &rdn,
5772 &CFOC_SCHEMA, NULL );
5775 } else if ( e && cf->c_kids ) {
5776 c->ca_private = cf->c_kids;
5777 config_build_schema_inc( c, e->e_private, op, rs );
5783 #ifdef SLAPD_MODULES
5786 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
5787 Operation *op, SlapReply *rs )
5792 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
5793 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
5795 c->value_dn.bv_val = c->log;
5796 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
5797 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
5798 /* FIXME: how can indicate error? */
5802 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
5811 config_check_schema(Operation *op, CfBackInfo *cfb)
5813 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
5815 CfEntryInfo *ce, *last;
5818 /* If there's no root entry, we must be in the midst of converting */
5819 if ( !cfb->cb_root )
5822 /* Make sure the main schema entry exists */
5823 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
5830 /* Make sure it's up to date */
5831 if ( cf_om_tail != om_sys_tail ) {
5832 a = attr_find( e->e_attrs, cfAd_om );
5834 if ( a->a_nvals != a->a_vals )
5835 ber_bvarray_free( a->a_nvals );
5836 ber_bvarray_free( a->a_vals );
5841 oidm_unparse( &bv, NULL, NULL, 1 );
5842 attr_merge_normalize( e, cfAd_om, bv, NULL );
5843 ber_bvarray_free( bv );
5844 cf_om_tail = om_sys_tail;
5846 if ( cf_at_tail != at_sys_tail ) {
5847 a = attr_find( e->e_attrs, cfAd_attr );
5849 if ( a->a_nvals != a->a_vals )
5850 ber_bvarray_free( a->a_nvals );
5851 ber_bvarray_free( a->a_vals );
5856 at_unparse( &bv, NULL, NULL, 1 );
5857 attr_merge_normalize( e, cfAd_attr, bv, NULL );
5858 ber_bvarray_free( bv );
5859 cf_at_tail = at_sys_tail;
5861 if ( cf_oc_tail != oc_sys_tail ) {
5862 a = attr_find( e->e_attrs, cfAd_oc );
5864 if ( a->a_nvals != a->a_vals )
5865 ber_bvarray_free( a->a_nvals );
5866 ber_bvarray_free( a->a_vals );
5871 oc_unparse( &bv, NULL, NULL, 1 );
5872 attr_merge_normalize( e, cfAd_oc, bv, NULL );
5873 ber_bvarray_free( bv );
5874 cf_oc_tail = oc_sys_tail;
5876 if ( cf_syn_tail != syn_sys_tail ) {
5877 a = attr_find( e->e_attrs, cfAd_syntax );
5879 if ( a->a_nvals != a->a_vals )
5880 ber_bvarray_free( a->a_nvals );
5881 ber_bvarray_free( a->a_vals );
5886 syn_unparse( &bv, NULL, NULL, 1 );
5887 attr_merge_normalize( e, cfAd_syntax, bv, NULL );
5888 ber_bvarray_free( bv );
5889 cf_syn_tail = syn_sys_tail;
5892 SlapReply rs = {REP_RESULT};
5893 c.ca_private = NULL;
5894 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
5895 &CFOC_SCHEMA, NULL );
5900 ce->ce_private = cfb->cb_config;
5901 cf_at_tail = at_sys_tail;
5902 cf_oc_tail = oc_sys_tail;
5903 cf_om_tail = om_sys_tail;
5904 cf_syn_tail = syn_sys_tail;
5909 static const char *defacl[] = {
5910 NULL, "to", "*", "by", "*", "none", NULL
5914 config_back_db_open( BackendDB *be, ConfigReply *cr )
5916 CfBackInfo *cfb = be->be_private;
5919 CfEntryInfo *ce, *ceparent;
5923 Connection conn = {0};
5924 OperationBuffer opbuf;
5926 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
5927 SlapReply rs = {REP_RESULT};
5928 void *thrctx = NULL;
5930 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
5932 /* If we have no explicitly configured ACLs, don't just use
5933 * the global ACLs. Explicitly deny access to everything.
5935 if ( !be->be_acl ) {
5936 parse_acl(be, "config_back_db_open", 0, 6, (char **)defacl, 0 );
5939 thrctx = ldap_pvt_thread_pool_context();
5940 connection_fake_init( &conn, &opbuf, thrctx );
5943 op->o_tag = LDAP_REQ_ADD;
5944 op->o_callback = &cb;
5945 op->o_bd = &cfb->cb_db;
5946 op->o_dn = op->o_bd->be_rootdn;
5947 op->o_ndn = op->o_bd->be_rootndn;
5949 if ( !cfb->cb_use_ldif ) {
5953 /* If we read the config from back-ldif, do some quick sanity checks */
5954 if ( cfb->cb_got_ldif ) {
5955 return config_check_schema( op, cfb );
5958 /* create root of tree */
5960 c.ca_private = cfb->cb_config;
5962 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
5972 #ifdef SLAPD_MODULES
5973 /* Create Module nodes... */
5974 if ( modpaths.mp_loads ) {
5975 if ( config_build_modules( &c, ceparent, op, &rs ) ){
5981 /* Create schema nodes... cn=schema will contain the hardcoded core
5982 * schema, read-only. Child objects will contain runtime loaded schema
5986 c.ca_private = NULL;
5987 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
5992 ce->ce_private = cfb->cb_config;
5993 cf_at_tail = at_sys_tail;
5994 cf_oc_tail = oc_sys_tail;
5995 cf_om_tail = om_sys_tail;
5996 cf_syn_tail = syn_sys_tail;
5998 /* Create schema nodes for included schema... */
5999 if ( cfb->cb_config->c_kids ) {
6001 c.ca_private = cfb->cb_config->c_kids;
6002 if (config_build_schema_inc( &c, ce, op, &rs )) {
6007 /* Create backend nodes. Skip if they don't provide a cf_table.
6008 * There usually aren't any of these.
6012 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
6013 if (!bi->bi_cf_ocs) {
6014 /* If it only supports the old config mech, complain. */
6015 if ( bi->bi_config ) {
6016 Debug( LDAP_DEBUG_ANY,
6017 "WARNING: No dynamic config support for backend %s.\n",
6018 bi->bi_type, 0, 0 );
6023 if (!bi->bi_private) continue;
6026 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6027 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
6028 if ( rdn.bv_len >= sizeof( c.log ) ) {
6029 /* FIXME: holler ... */ ;
6032 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
6039 /* Create database nodes... */
6040 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
6041 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
6042 for ( i = -1, be = frontendDB ; be;
6043 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
6044 slap_overinfo *oi = NULL;
6046 if ( overlay_is_over( be )) {
6047 oi = be->bd_info->bi_private;
6053 /* If this backend supports the old config mechanism, but not
6054 * the new mech, complain.
6056 if ( !be->be_cf_ocs && bi->bi_db_config ) {
6057 Debug( LDAP_DEBUG_ANY,
6058 "WARNING: No dynamic config support for database %s.\n",
6059 bi->bi_type, 0, 0 );
6063 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6064 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
6066 if ( rdn.bv_len >= sizeof( c.log ) ) {
6067 /* FIXME: holler ... */ ;
6071 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
6077 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd )
6078 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
6079 /* Iterate through overlays */
6084 voidList *vl, *v0 = NULL;
6086 /* overlays are in LIFO order, must reverse stack */
6087 for (on=oi->oi_list; on; on=on->on_next) {
6088 vl = ch_malloc( sizeof( voidList ));
6093 for (j=0; vl; j++,vl=v0) {
6097 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
6098 Debug( LDAP_DEBUG_ANY,
6099 "WARNING: No dynamic config support for overlay %s.\n",
6100 on->on_bi.bi_type, 0, 0 );
6104 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6105 "%s=" SLAP_X_ORDERED_FMT "%s",
6106 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
6107 if ( rdn.bv_len >= sizeof( c.log ) ) {
6108 /* FIXME: holler ... */ ;
6112 oe = config_build_entry( op, &rs, ce, &c, &rdn,
6113 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
6117 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd )
6118 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
6123 ldap_pvt_thread_pool_context_reset( thrctx );
6125 if ( unsupp && cfb->cb_use_ldif ) {
6126 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
6127 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
6134 cfb_free_cffile( ConfigFile *cf )
6138 for (; cf; cf=next) {
6141 cfb_free_cffile( cf->c_kids );
6142 ch_free( cf->c_file.bv_val );
6143 ber_bvarray_free( cf->c_dseFiles );
6149 cfb_free_entries( CfEntryInfo *ce )
6153 for (; ce; ce=next) {
6156 cfb_free_entries( ce->ce_kids );
6157 ce->ce_entry->e_private = NULL;
6158 entry_free( ce->ce_entry );
6164 config_back_db_close( BackendDB *be, ConfigReply *cr )
6166 CfBackInfo *cfb = be->be_private;
6168 cfb_free_entries( cfb->cb_root );
6169 cfb->cb_root = NULL;
6171 if ( cfb->cb_db.bd_info ) {
6172 backend_shutdown( &cfb->cb_db );
6179 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
6181 CfBackInfo *cfb = be->be_private;
6183 cfb_free_cffile( cfb->cb_config );
6185 ch_free( cfdir.bv_val );
6187 avl_free( CfOcTree, NULL );
6189 if ( cfb->cb_db.bd_info ) {
6190 cfb->cb_db.be_suffix = NULL;
6191 cfb->cb_db.be_nsuffix = NULL;
6192 BER_BVZERO( &cfb->cb_db.be_rootdn );
6193 BER_BVZERO( &cfb->cb_db.be_rootndn );
6195 backend_destroy_one( &cfb->cb_db, 0 );
6204 config_back_db_init( BackendDB *be, ConfigReply* cr )
6210 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
6211 cfn = cfb->cb_config;
6212 be->be_private = cfb;
6214 ber_dupbv( &be->be_rootdn, &config_rdn );
6215 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
6216 ber_dupbv( &dn, &be->be_rootdn );
6217 ber_bvarray_add( &be->be_suffix, &dn );
6218 ber_dupbv( &dn, &be->be_rootdn );
6219 ber_bvarray_add( &be->be_nsuffix, &dn );
6221 /* Hide from namingContexts */
6222 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
6224 /* Check ACLs on content of Adds by default */
6225 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_ACL_ADD;
6231 config_back_destroy( BackendInfo *bi )
6233 ldif_must_b64_encode_release();
6238 config_tool_entry_open( BackendDB *be, int mode )
6240 CfBackInfo *cfb = be->be_private;
6241 BackendInfo *bi = cfb->cb_db.bd_info;
6243 if ( bi && bi->bi_tool_entry_open )
6244 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
6251 config_tool_entry_close( BackendDB *be )
6253 CfBackInfo *cfb = be->be_private;
6254 BackendInfo *bi = cfb->cb_db.bd_info;
6256 if ( bi && bi->bi_tool_entry_close )
6257 return bi->bi_tool_entry_close( &cfb->cb_db );
6263 config_tool_entry_first( BackendDB *be )
6265 CfBackInfo *cfb = be->be_private;
6266 BackendInfo *bi = cfb->cb_db.bd_info;
6268 if ( bi && bi->bi_tool_entry_first )
6269 return bi->bi_tool_entry_first( &cfb->cb_db );
6275 config_tool_entry_next( BackendDB *be )
6277 CfBackInfo *cfb = be->be_private;
6278 BackendInfo *bi = cfb->cb_db.bd_info;
6280 if ( bi && bi->bi_tool_entry_next )
6281 return bi->bi_tool_entry_next( &cfb->cb_db );
6287 config_tool_entry_get( BackendDB *be, ID id )
6289 CfBackInfo *cfb = be->be_private;
6290 BackendInfo *bi = cfb->cb_db.bd_info;
6292 if ( bi && bi->bi_tool_entry_get )
6293 return bi->bi_tool_entry_get( &cfb->cb_db, id );
6298 static int entry_put_got_frontend=0;
6299 static int entry_put_got_config=0;
6301 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
6303 CfBackInfo *cfb = be->be_private;
6304 BackendInfo *bi = cfb->cb_db.bd_info;
6306 struct berval rdn, vals[ 2 ];
6308 OperationBuffer opbuf;
6310 Connection conn = {0};
6311 Operation *op = NULL;
6315 /* Create entry for frontend database if it does not exist already */
6316 if ( !entry_put_got_frontend ) {
6317 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
6318 STRLENOF( "olcDatabase" ))) {
6319 if ( strncmp( e->e_nname.bv_val +
6320 STRLENOF( "olcDatabase" ), "={-1}frontend",
6321 STRLENOF( "={-1}frontend" )) &&
6322 strncmp( e->e_nname.bv_val +
6323 STRLENOF( "olcDatabase" ), "=frontend",
6324 STRLENOF( "=frontend" ))) {
6326 vals[1].bv_val = NULL;
6327 memset( &ca, 0, sizeof(ConfigArgs));
6329 ca.bi = frontendDB->bd_info;
6330 ca.be->be_cf_ocs = &CFOC_FRONTEND;
6331 rdn.bv_val = ca.log;
6332 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
6333 "%s=" SLAP_X_ORDERED_FMT "%s",
6334 cfAd_database->ad_cname.bv_val, -1,
6336 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
6337 &CFOC_DATABASE, ca.be->be_cf_ocs );
6338 thrctx = ldap_pvt_thread_pool_context();
6339 connection_fake_init2( &conn, &opbuf, thrctx,0 );
6341 op->o_bd = &cfb->cb_db;
6342 op->o_tag = LDAP_REQ_ADD;
6344 op->o_dn = be->be_rootdn;
6345 op->o_ndn = be->be_rootndn;
6346 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
6347 if ( rc != LDAP_SUCCESS ) {
6348 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
6349 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
6353 if ( ce && bi && bi->bi_tool_entry_put &&
6354 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
6355 entry_put_got_frontend++;
6357 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
6358 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
6362 entry_put_got_frontend++;
6367 /* Create entry for config database if it does not exist already */
6368 if ( !entry_put_got_config && !isFrontend ) {
6369 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
6370 STRLENOF( "olcDatabase" ))) {
6371 if ( strncmp( e->e_nname.bv_val +
6372 STRLENOF( "olcDatabase" ), "={0}config",
6373 STRLENOF( "={0}config" )) &&
6374 strncmp( e->e_nname.bv_val +
6375 STRLENOF( "olcDatabase" ), "=config",
6376 STRLENOF( "=config" )) ) {
6378 vals[1].bv_val = NULL;
6379 memset( &ca, 0, sizeof(ConfigArgs));
6380 ca.be = LDAP_STAILQ_FIRST( &backendDB );
6381 ca.bi = ca.be->bd_info;
6382 rdn.bv_val = ca.log;
6383 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
6384 "%s=" SLAP_X_ORDERED_FMT "%s",
6385 cfAd_database->ad_cname.bv_val, 0,
6387 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
6390 thrctx = ldap_pvt_thread_pool_context();
6391 connection_fake_init2( &conn, &opbuf, thrctx,0 );
6393 op->o_bd = &cfb->cb_db;
6394 op->o_tag = LDAP_REQ_ADD;
6395 op->o_dn = be->be_rootdn;
6396 op->o_ndn = be->be_rootndn;
6399 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
6400 if ( rc != LDAP_SUCCESS ) {
6401 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
6402 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
6405 if (ce && bi && bi->bi_tool_entry_put &&
6406 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
6407 entry_put_got_config++;
6409 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
6410 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
6414 entry_put_got_config++;
6418 if ( bi && bi->bi_tool_entry_put &&
6419 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
6420 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
6427 AttributeDescription **desc;
6429 { "attribute", &cfAd_attr },
6430 { "backend", &cfAd_backend },
6431 { "database", &cfAd_database },
6432 { "include", &cfAd_include },
6433 { "ldapsyntax", &cfAd_syntax },
6434 { "objectclass", &cfAd_oc },
6435 { "objectidentifier", &cfAd_om },
6436 { "overlay", &cfAd_overlay },
6441 * add / delete: all types that may be added or deleted must use an
6442 * X-ORDERED attributeType for their RDN. Adding and deleting entries
6443 * should automatically renumber the index of any siblings as needed,
6444 * so that no gaps in the numbering sequence exist after the add/delete
6446 * What can be added:
6448 * backend objects for backend-specific config directives
6452 * delete: probably no support this time around.
6454 * modrdn: generally not done. Will be invoked automatically by add/
6455 * delete to update numbering sequence. Perform as an explicit operation
6456 * so that the renumbering effect may be replicated. Subtree rename must
6457 * be supported, since renumbering a database will affect all its child
6460 * modify: must be fully supported.
6464 config_back_initialize( BackendInfo *bi )
6466 ConfigTable *ct = config_back_cf_table;
6470 AttributeDescription *ad = NULL;
6472 static char *controls[] = {
6473 LDAP_CONTROL_MANAGEDSAIT,
6477 /* Make sure we don't exceed the bits reserved for userland */
6478 config_check_userland( CFG_LAST );
6480 bi->bi_controls = controls;
6485 bi->bi_destroy = config_back_destroy;
6487 bi->bi_db_init = config_back_db_init;
6488 bi->bi_db_config = 0;
6489 bi->bi_db_open = config_back_db_open;
6490 bi->bi_db_close = config_back_db_close;
6491 bi->bi_db_destroy = config_back_db_destroy;
6493 bi->bi_op_bind = config_back_bind;
6494 bi->bi_op_unbind = 0;
6495 bi->bi_op_search = config_back_search;
6496 bi->bi_op_compare = 0;
6497 bi->bi_op_modify = config_back_modify;
6498 bi->bi_op_modrdn = config_back_modrdn;
6499 bi->bi_op_add = config_back_add;
6500 bi->bi_op_delete = config_back_delete;
6501 bi->bi_op_abandon = 0;
6503 bi->bi_extended = 0;
6505 bi->bi_chk_referrals = 0;
6507 bi->bi_access_allowed = slap_access_allowed;
6509 bi->bi_connection_init = 0;
6510 bi->bi_connection_destroy = 0;
6512 bi->bi_entry_release_rw = config_entry_release;
6513 bi->bi_entry_get_rw = config_back_entry_get;
6515 bi->bi_tool_entry_open = config_tool_entry_open;
6516 bi->bi_tool_entry_close = config_tool_entry_close;
6517 bi->bi_tool_entry_first = config_tool_entry_first;
6518 bi->bi_tool_entry_next = config_tool_entry_next;
6519 bi->bi_tool_entry_get = config_tool_entry_get;
6520 bi->bi_tool_entry_put = config_tool_entry_put;
6523 argv[ 0 ] = "slapd";
6529 for (i=0; OidMacros[i].name; i++ ) {
6530 argv[1] = OidMacros[i].name;
6531 argv[2] = OidMacros[i].oid;
6532 parse_oidm( &ca, 0, NULL );
6535 bi->bi_cf_ocs = cf_ocs;
6537 i = config_register_schema( ct, cf_ocs );
6540 i = slap_str2ad( "olcDatabase", &olcDatabaseDummy[0].ad, &text );
6543 /* setup olcRootPW to be base64-encoded when written in LDIF form;
6544 * basically, we don't care if it fails */
6545 i = slap_str2ad( "olcRootPW", &ad, &text );
6547 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
6548 "warning, unable to get \"olcRootPW\" "
6549 "attribute description: %d: %s\n",
6552 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
6553 ad->ad_type->sat_oid );
6556 /* set up the notable AttributeDescriptions */
6558 for (;ct->name;ct++) {
6559 if (strcmp(ct->name, ads[i].name)) continue;
6560 *ads[i].desc = ct->ad;
6562 if (!ads[i].name) break;