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;
983 if ( c->be == frontendDB )
986 end = frontendDB->be_acl;
987 for (i=0, a=c->be->be_acl; a && a != end; i++,a=a->acl_next) {
988 abv.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
989 if ( abv.bv_len >= sizeof( ibuf ) ) {
990 ber_bvarray_free_x( c->rvalue_vals, NULL );
991 c->rvalue_vals = NULL;
995 acl_unparse( a, &bv );
996 abv.bv_val = ch_malloc( abv.bv_len + bv.bv_len + 1 );
997 AC_MEMCPY( abv.bv_val, ibuf, abv.bv_len );
998 /* Turn TAB / EOL into plain space */
999 for (src=bv.bv_val,dst=abv.bv_val+abv.bv_len; *src; src++) {
1000 if (isspace((unsigned char)*src)) *dst++ = ' ';
1004 if (dst[-1] == ' ') {
1008 abv.bv_len = dst - abv.bv_val;
1009 ber_bvarray_add( &c->rvalue_vals, &abv );
1015 c->value_int = (SLAP_DBACL_ADD(c->be) != 0);
1018 ConfigFile *cf = c->ca_private;
1019 if ( cf->c_dseFiles ) {
1020 value_add( &c->rvalue_vals, cf->c_dseFiles );
1031 for ( si = sid_list; si; si=si->si_next ) {
1032 assert( si->si_num >= 0 && si->si_num <= SLAP_SYNC_SID_MAX );
1033 if ( !BER_BVISEMPTY( &si->si_url )) {
1034 bv.bv_len = si->si_url.bv_len + 6;
1035 bv.bv_val = ch_malloc( bv.bv_len );
1036 sprintf( bv.bv_val, "%d %s", si->si_num,
1037 si->si_url.bv_val );
1038 ber_bvarray_add( &c->rvalue_vals, &bv );
1042 bv.bv_len = sprintf( buf, "%d", si->si_num );
1043 value_add_one( &c->rvalue_vals, &bv );
1052 c->value_string = ch_strdup( logfileName );
1057 c->value_int = (SLAP_NOLASTMOD(c->be) == 0);
1059 case CFG_MIRRORMODE:
1060 if ( SLAP_SHADOW(c->be))
1061 c->value_int = (SLAP_SINGLE_SHADOW(c->be) == 0);
1065 case CFG_MONITORING:
1066 c->value_int = (SLAP_DBMONITORING(c->be) != 0);
1068 case CFG_SSTR_IF_MAX:
1069 c->value_int = index_substr_if_maxlen;
1071 case CFG_SSTR_IF_MIN:
1072 c->value_int = index_substr_if_minlen;
1075 c->value_int = index_intlen;
1077 case CFG_SORTVALS: {
1080 for ( sv = sortVals; sv; sv = sv->al_next ) {
1081 value_add_one( &c->rvalue_vals, &sv->al_desc->ad_cname );
1085 #ifdef SLAPD_MODULES
1087 ModPaths *mp = c->ca_private;
1090 for (i=0; !BER_BVISNULL(&mp->mp_loads[i]); i++) {
1093 bv.bv_len = snprintf( bv.bv_val, sizeof( c->log ),
1094 SLAP_X_ORDERED_FMT "%s", i,
1095 mp->mp_loads[i].bv_val );
1096 if ( bv.bv_len >= sizeof( c->log ) ) {
1097 ber_bvarray_free_x( c->rvalue_vals, NULL );
1098 c->rvalue_vals = NULL;
1101 value_add_one( &c->rvalue_vals, &bv );
1105 rc = c->rvalue_vals ? 0 : 1;
1109 ModPaths *mp = c->ca_private;
1110 if ( !BER_BVISNULL( &mp->mp_path ))
1111 value_add_one( &c->rvalue_vals, &mp->mp_path );
1113 rc = c->rvalue_vals ? 0 : 1;
1119 slapi_int_plugin_unparse( c->be, &c->rvalue_vals );
1120 if ( !c->rvalue_vals ) rc = 1;
1123 #ifdef SLAP_AUTH_REWRITE
1125 if ( authz_rewrites ) {
1126 struct berval bv, idx;
1131 for ( i=0; !BER_BVISNULL( &authz_rewrites[i] ); i++ ) {
1132 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), SLAP_X_ORDERED_FMT, i );
1133 if ( idx.bv_len >= sizeof( ibuf ) ) {
1134 ber_bvarray_free_x( c->rvalue_vals, NULL );
1135 c->rvalue_vals = NULL;
1138 bv.bv_len = idx.bv_len + authz_rewrites[i].bv_len;
1139 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1140 AC_MEMCPY( bv.bv_val, idx.bv_val, idx.bv_len );
1141 AC_MEMCPY( &bv.bv_val[ idx.bv_len ],
1142 authz_rewrites[i].bv_val,
1143 authz_rewrites[i].bv_len + 1 );
1144 ber_bvarray_add( &c->rvalue_vals, &bv );
1147 if ( !c->rvalue_vals ) rc = 1;
1154 } else if ( c->op == LDAP_MOD_DELETE ) {
1157 /* single-valued attrs, no-ops */
1165 case CFG_MIRRORMODE:
1166 case CFG_MONITORING:
1168 case CFG_SSTR_IF_MAX:
1169 case CFG_SSTR_IF_MIN:
1173 /* no-ops, requires slapd restart */
1178 snprintf(c->log, sizeof( c->log ), "change requires slapd restart");
1182 ch_free( passwd_salt );
1187 ch_free( logfileName );
1195 case CFG_SERVERID: {
1196 ServerID *si, **sip;
1198 for ( i=0, si = sid_list, sip = &sid_list;
1199 si; si = *sip, i++ ) {
1200 if ( c->valx == -1 || i == c->valx ) {
1212 c->be->be_flags &= ~SLAP_DBFLAG_HIDDEN;
1216 index_intlen = SLAP_INDEX_INTLEN_DEFAULT;
1217 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1218 SLAP_INDEX_INTLEN_DEFAULT );
1222 if ( c->valx < 0 ) {
1224 if ( c->be == frontendDB )
1227 end = frontendDB->be_acl;
1228 acl_destroy( c->be->be_acl, end );
1229 c->be->be_acl = end;
1232 AccessControl **prev, *a;
1234 for (i=0, prev = &c->be->be_acl; i < c->valx;
1237 prev = &a->acl_next;
1240 *prev = a->acl_next;
1247 /* Can be NULL when undoing a failed add */
1248 if ( c->ca_entry ) {
1249 ce = c->ca_entry->e_private;
1250 /* can't modify the hardcoded schema */
1251 if ( ce->ce_parent->ce_type == Cft_Global )
1255 cfn = c->ca_private;
1256 if ( c->valx < 0 ) {
1259 for( oc = cfn->c_oc_head; oc; oc_next( &oc )) {
1261 if ( oc == cfn->c_oc_tail )
1264 cfn->c_oc_head = cfn->c_oc_tail = NULL;
1266 ObjectClass *oc, *prev = NULL;
1268 for ( i=0, oc=cfn->c_oc_head; i<c->valx; i++) {
1273 if ( cfn->c_oc_tail == oc ) {
1274 cfn->c_oc_tail = prev;
1276 if ( cfn->c_oc_head == oc ) {
1278 cfn->c_oc_head = oc;
1285 /* Can be NULL when undoing a failed add */
1286 if ( c->ca_entry ) {
1287 ce = c->ca_entry->e_private;
1288 /* can't modify the hardcoded schema */
1289 if ( ce->ce_parent->ce_type == Cft_Global )
1293 cfn = c->ca_private;
1294 if ( c->valx < 0 ) {
1297 for( at = cfn->c_at_head; at; at_next( &at )) {
1299 if ( at == cfn->c_at_tail )
1302 cfn->c_at_head = cfn->c_at_tail = NULL;
1304 AttributeType *at, *prev = NULL;
1306 for ( i=0, at=cfn->c_at_head; i<c->valx; i++) {
1311 if ( cfn->c_at_tail == at ) {
1312 cfn->c_at_tail = prev;
1314 if ( cfn->c_at_head == at ) {
1316 cfn->c_at_head = at;
1323 /* Can be NULL when undoing a failed add */
1324 if ( c->ca_entry ) {
1325 ce = c->ca_entry->e_private;
1326 /* can't modify the hardcoded schema */
1327 if ( ce->ce_parent->ce_type == Cft_Global )
1331 cfn = c->ca_private;
1332 if ( c->valx < 0 ) {
1335 for( syn = cfn->c_syn_head; syn; syn_next( &syn )) {
1337 if ( syn == cfn->c_syn_tail )
1340 cfn->c_syn_head = cfn->c_syn_tail = NULL;
1342 Syntax *syn, *prev = NULL;
1344 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++) {
1349 if ( cfn->c_syn_tail == syn ) {
1350 cfn->c_syn_tail = prev;
1352 if ( cfn->c_syn_head == syn ) {
1354 cfn->c_syn_head = syn;
1359 if ( c->valx < 0 ) {
1361 for ( sv = sortVals; sv; sv = sortVals ) {
1362 sortVals = sv->al_next;
1363 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1370 for ( prev = &sortVals, sv = sortVals; i < c->valx; i++ ) {
1371 prev = &sv->al_next;
1374 sv->al_desc->ad_type->sat_flags &= ~SLAP_AT_SORTED_VAL;
1375 *prev = sv->al_next;
1381 /* FIXME: there is no limits_free function */
1383 /* FIXME: there is no ad_option_free function */
1385 /* FIXME: there is no way to remove attributes added by
1399 if(!(c->bi = backend_info(c->argv[1]))) {
1400 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1401 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
1402 c->log, c->cr_msg, c->argv[1] );
1409 /* NOTE: config is always the first backend!
1411 if ( !strcasecmp( c->argv[1], "config" )) {
1412 c->be = LDAP_STAILQ_FIRST(&backendDB);
1413 } else if ( !strcasecmp( c->argv[1], "frontend" )) {
1416 c->be = backend_db_init(c->argv[1], NULL, c->valx, &c->reply);
1418 if ( c->cr_msg[0] == 0 )
1419 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> failed init", c->argv[0] );
1420 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n", c->log, c->cr_msg, c->argv[1] );
1427 ldap_pvt_thread_set_concurrency(c->value_int);
1431 if ( c->value_int < 2 ) {
1432 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1433 "threads=%d smaller than minimum value 2",
1435 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1436 c->log, c->cr_msg, 0 );
1439 } else if ( c->value_int > 2 * SLAP_MAX_WORKER_THREADS ) {
1440 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1441 "warning, threads=%d larger than twice the default (2*%d=%d); YMMV",
1442 c->value_int, SLAP_MAX_WORKER_THREADS, 2 * SLAP_MAX_WORKER_THREADS );
1443 Debug(LDAP_DEBUG_ANY, "%s: %s.\n",
1444 c->log, c->cr_msg, 0 );
1446 if ( slapMode & SLAP_SERVER_MODE )
1447 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1448 connection_pool_max = c->value_int; /* save for reference */
1452 if ( slapMode & SLAP_TOOL_MODE )
1453 ldap_pvt_thread_pool_maxthreads(&connection_pool, c->value_int);
1454 slap_tool_thread_max = c->value_int; /* save for reference */
1458 if ( passwd_salt ) ch_free( passwd_salt );
1459 passwd_salt = c->value_string;
1460 lutil_salt_format(passwd_salt);
1464 if(limits_parse(c->be, c->fname, c->lineno, c->argc, c->argv))
1470 c->be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1472 c->be->be_restrictops &= ~SLAP_RESTRICT_OP_WRITES;
1476 ch_free(c->value_string);
1477 if (slap_sasl_setpolicy( c->argv[1] )) {
1478 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
1479 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
1480 c->log, c->cr_msg, c->argv[1] );
1486 if (slap_sasl_regexp_config( c->argv[1], c->argv[2] ))
1490 #ifdef HAVE_CYRUS_SASL
1493 char *txt = slap_sasl_secprops( c->argv[1] );
1495 snprintf( c->cr_msg, sizeof(c->cr_msg), "<%s> %s",
1497 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0 );
1505 c->be->be_max_deref_depth = c->value_int;
1511 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1512 cfn = c->ca_private;
1513 if(parse_oidm(c, 1, &om))
1515 if (!cfn->c_om_head) cfn->c_om_head = om;
1516 cfn->c_om_tail = om;
1521 ObjectClass *oc, *prev;
1523 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1524 cfn = c->ca_private;
1525 if ( c->valx < 0 ) {
1526 prev = cfn->c_oc_tail;
1529 /* If adding anything after the first, prev is easy */
1532 for (i=0, oc = cfn->c_oc_head; i<c->valx; i++) {
1537 /* If adding the first, and head exists, find its prev */
1538 if (cfn->c_oc_head) {
1539 for ( oc_start( &oc ); oc != cfn->c_oc_head; ) {
1544 /* else prev is NULL, append to end of global list */
1546 if(parse_oc(c, &oc, prev)) return(1);
1547 if (!cfn->c_oc_head) cfn->c_oc_head = oc;
1548 if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc;
1553 AttributeType *at, *prev;
1555 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1556 cfn = c->ca_private;
1557 if ( c->valx < 0 ) {
1558 prev = cfn->c_at_tail;
1561 /* If adding anything after the first, prev is easy */
1564 for (i=0, at = cfn->c_at_head; i<c->valx; i++) {
1569 /* If adding the first, and head exists, find its prev */
1570 if (cfn->c_at_head) {
1571 for ( at_start( &at ); at != cfn->c_at_head; ) {
1576 /* else prev is NULL, append to end of global list */
1578 if(parse_at(c, &at, prev)) return(1);
1579 if (!cfn->c_at_head) cfn->c_at_head = at;
1580 if (cfn->c_at_tail == prev) cfn->c_at_tail = at;
1587 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1588 cfn = c->ca_private;
1589 if ( c->valx < 0 ) {
1590 prev = cfn->c_syn_tail;
1593 /* If adding anything after the first, prev is easy */
1596 for ( i = 0, syn = cfn->c_syn_head; i < c->valx; i++ ) {
1601 /* If adding the first, and head exists, find its prev */
1602 if (cfn->c_syn_head) {
1603 for ( syn_start( &syn ); syn != cfn->c_syn_head; ) {
1608 /* else prev is NULL, append to end of global list */
1610 if ( parse_syn( c, &syn, prev ) ) return(1);
1611 if ( !cfn->c_syn_head ) cfn->c_syn_head = syn;
1612 if ( cfn->c_syn_tail == prev ) cfn->c_syn_tail = syn;
1619 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1620 cfn = c->ca_private;
1621 if(parse_cr(c, &cr)) return(1);
1622 if (!cfn->c_cr_head) cfn->c_cr_head = cr;
1623 cfn->c_cr_tail = cr;
1628 ad_define_option(NULL, NULL, 0);
1629 for(i = 1; i < c->argc; i++)
1630 if(ad_define_option(c->argv[i], c->fname, c->lineno))
1635 if ( c->value_int < SLAP_INDEX_INTLEN_DEFAULT )
1636 c->value_int = SLAP_INDEX_INTLEN_DEFAULT;
1637 else if ( c->value_int > 255 )
1639 index_intlen = c->value_int;
1640 index_intlen_strlen = SLAP_INDEX_INTLEN_STRLEN(
1644 case CFG_SORTVALS: {
1645 ADlist *svnew = NULL, *svtail, *sv;
1647 for ( i = 1; i < c->argc; i++ ) {
1648 AttributeDescription *ad = NULL;
1652 rc = slap_str2ad( c->argv[i], &ad, &text );
1654 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown attribute type #%d",
1657 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1658 c->log, c->cr_msg, c->argv[i] );
1659 for ( sv = svnew; sv; sv = svnew ) {
1660 svnew = sv->al_next;
1665 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) ||
1666 ad->ad_type->sat_single_value ) {
1667 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> inappropriate attribute type #%d",
1669 goto sortval_reject;
1671 sv = ch_malloc( sizeof( ADlist ));
1676 svtail->al_next = sv;
1681 for ( sv = svnew; sv; sv = sv->al_next )
1682 sv->al_desc->ad_type->sat_flags |= SLAP_AT_SORTED_VAL;
1683 for ( sv = sortVals; sv && sv->al_next; sv = sv->al_next );
1685 sv->al_next = svnew;
1692 /* Don't append to the global ACL if we're on a specific DB */
1694 if ( c->be != frontendDB && frontendDB->be_acl && c->valx == -1 ) {
1697 for ( a=c->be->be_acl; a && a != frontendDB->be_acl;
1701 if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) {
1708 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_ACL_ADD;
1710 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_ACL_ADD;
1714 if(root_dse_read_file(c->argv[1])) {
1715 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> could not read file", c->argv[0] );
1716 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1717 c->log, c->cr_msg, c->argv[1] );
1722 ber_str2bv( c->argv[1], 0, 1, &bv );
1723 if ( c->op == LDAP_MOD_ADD && c->ca_private && cfn != c->ca_private )
1724 cfn = c->ca_private;
1725 ber_bvarray_add( &cfn->c_dseFiles, &bv );
1731 ServerID *si, **sip;
1734 if ( lutil_atoi( &num, c->argv[1] ) ||
1735 num < 0 || num > SLAP_SYNC_SID_MAX )
1737 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1738 "<%s> illegal server ID", c->argv[0] );
1739 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1740 c->log, c->cr_msg, c->argv[1] );
1743 /* only one value allowed if no URL is given */
1744 if ( c->argc > 2 ) {
1747 if ( sid_list && BER_BVISEMPTY( &sid_list->si_url )) {
1748 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1749 "<%s> only one server ID allowed now", c->argv[0] );
1750 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1751 c->log, c->cr_msg, c->argv[1] );
1755 if ( ldap_url_parse( c->argv[2], &lud )) {
1756 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1757 "<%s> invalid URL", c->argv[0] );
1758 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1759 c->log, c->cr_msg, c->argv[2] );
1762 len = strlen( c->argv[2] );
1763 si = ch_malloc( sizeof(ServerID) + len + 1 );
1764 si->si_url.bv_val = (char *)(si+1);
1765 si->si_url.bv_len = len;
1766 strcpy( si->si_url.bv_val, c->argv[2] );
1769 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1770 "<%s> unqualified server ID not allowed now", c->argv[0] );
1771 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
1772 c->log, c->cr_msg, c->argv[1] );
1775 si = ch_malloc( sizeof(ServerID) );
1776 BER_BVZERO( &si->si_url );
1777 slap_serverID = num;
1778 Debug( LDAP_DEBUG_CONFIG,
1780 c->log, slap_serverID, 0 );
1784 for ( sip = &sid_list; *sip; sip = &(*sip)->si_next );
1787 if (( slapMode & SLAP_SERVER_MODE ) && c->argc > 2 ) {
1788 /* If hostname is empty, or is localhost, or matches
1789 * our hostname, this serverID refers to this host.
1790 * Compare it against listeners and ports.
1792 if ( !lud->lud_host || !lud->lud_host[0] ||
1793 !strncasecmp("localhost", lud->lud_host,
1794 STRLENOF("localhost")) ||
1795 !strcasecmp( global_host, lud->lud_host )) {
1796 Listener **l = slapd_get_listeners();
1799 for ( i=0; l && l[i]; i++ ) {
1802 ldap_url_parse( l[i]->sl_url.bv_val, &lu2 );
1804 if ( strcasecmp( lud->lud_scheme,
1807 if ( lud->lud_port != lu2->lud_port )
1809 /* Listener on ANY address */
1810 if ( !lu2->lud_host || !lu2->lud_host[0] ) {
1814 /* URL on ANY address */
1815 if ( !lud->lud_host || !lud->lud_host[0] ) {
1819 /* Listener has specific host, must
1822 if ( !strcasecmp( lud->lud_host,
1828 ldap_free_urldesc( lu2 );
1830 slap_serverID = si->si_num;
1831 Debug( LDAP_DEBUG_CONFIG,
1832 "%s: SID=%d (listener=%s)\n",
1833 c->log, slap_serverID,
1834 l[i]->sl_url.bv_val );
1841 ldap_free_urldesc( lud );
1845 if ( logfileName ) ch_free( logfileName );
1846 logfileName = c->value_string;
1847 logfile = fopen(logfileName, "w");
1848 if(logfile) lutil_debug_file(logfile);
1852 if(SLAP_NOLASTMODCMD(c->be)) {
1853 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> not available for %s database",
1854 c->argv[0], c->be->bd_info->bi_type );
1855 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1856 c->log, c->cr_msg, 0 );
1860 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_NOLASTMOD;
1862 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_NOLASTMOD;
1865 case CFG_MIRRORMODE:
1866 if(!SLAP_SHADOW(c->be)) {
1867 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database is not a shadow",
1869 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
1870 c->log, c->cr_msg, 0 );
1874 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_SINGLE_SHADOW;
1876 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_SINGLE_SHADOW;
1879 case CFG_MONITORING:
1881 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_MONITORING;
1883 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_MONITORING;
1888 SLAP_DBFLAGS(c->be) |= SLAP_DBFLAG_HIDDEN;
1890 SLAP_DBFLAGS(c->be) &= ~SLAP_DBFLAG_HIDDEN;
1893 case CFG_SSTR_IF_MAX:
1894 if (c->value_int < index_substr_if_minlen) {
1895 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1896 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1897 c->log, c->cr_msg, c->value_int );
1900 index_substr_if_maxlen = c->value_int;
1903 case CFG_SSTR_IF_MIN:
1904 if (c->value_int > index_substr_if_maxlen) {
1905 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid value", c->argv[0] );
1906 Debug(LDAP_DEBUG_ANY, "%s: %s (%d)\n",
1907 c->log, c->cr_msg, c->value_int );
1910 index_substr_if_minlen = c->value_int;
1913 #ifdef SLAPD_MODULES
1915 /* If we're just adding a module on an existing modpath,
1916 * make sure we've selected the current path.
1918 if ( c->op == LDAP_MOD_ADD && c->ca_private && modcur != c->ca_private ) {
1919 modcur = c->ca_private;
1920 /* This should never fail */
1921 if ( module_path( modcur->mp_path.bv_val )) {
1922 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> module path no longer valid",
1924 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
1925 c->log, c->cr_msg, modcur->mp_path.bv_val );
1929 if(module_load(c->argv[1], c->argc - 2, (c->argc > 2) ? c->argv + 2 : NULL))
1931 /* Record this load on the current path */
1935 if ( c->op == SLAP_CONFIG_ADD ) {
1936 ptr = c->line + STRLENOF("moduleload");
1937 while (!isspace((unsigned char) *ptr)) ptr++;
1938 while (isspace((unsigned char) *ptr)) ptr++;
1942 ber_str2bv(ptr, 0, 1, &bv);
1943 ber_bvarray_add( &modcur->mp_loads, &bv );
1945 /* Check for any new hardcoded schema */
1946 if ( c->op == LDAP_MOD_ADD && CONFIG_ONLINE_ADD( c )) {
1947 config_check_schema( NULL, &cfBackInfo );
1952 if(module_path(c->argv[1])) return(1);
1953 /* Record which path was used with each module */
1957 if (!modpaths.mp_loads) {
1960 mp = ch_malloc( sizeof( ModPaths ));
1961 modlast->mp_next = mp;
1963 ber_str2bv(c->argv[1], 0, 1, &mp->mp_path);
1965 mp->mp_loads = NULL;
1976 if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv) != LDAP_SUCCESS)
1978 slapi_plugins_used++;
1982 #ifdef SLAP_AUTH_REWRITE
1987 if(slap_sasl_rewrite_config(c->fname, c->lineno, c->argc, c->argv))
1990 if ( c->argc > 1 ) {
1993 /* quote all args but the first */
1994 line = ldap_charray2str( c->argv, "\" \"" );
1995 ber_str2bv( line, 0, 0, &bv );
1996 s = ber_bvchr( &bv, '"' );
1997 assert( s != NULL );
1998 /* move the trailing quote of argv[0] to the end */
1999 AC_MEMCPY( s, s + 1, bv.bv_len - ( s - bv.bv_val ) );
2000 bv.bv_val[ bv.bv_len - 1 ] = '"';
2003 ber_str2bv( c->argv[ 0 ], 0, 1, &bv );
2006 ber_bvarray_add( &authz_rewrites, &bv );
2013 Debug( LDAP_DEBUG_ANY,
2014 "%s: unknown CFG_TYPE %d.\n",
2015 c->log, c->type, 0 );
2024 config_fname(ConfigArgs *c) {
2025 if(c->op == SLAP_CONFIG_EMIT) {
2026 if (c->ca_private) {
2027 ConfigFile *cf = c->ca_private;
2028 value_add_one( &c->rvalue_vals, &cf->c_file );
2037 config_cfdir(ConfigArgs *c) {
2038 if(c->op == SLAP_CONFIG_EMIT) {
2039 if ( !BER_BVISEMPTY( &cfdir )) {
2040 value_add_one( &c->rvalue_vals, &cfdir );
2049 config_search_base(ConfigArgs *c) {
2050 if(c->op == SLAP_CONFIG_EMIT) {
2052 if (!BER_BVISEMPTY(&default_search_base)) {
2053 value_add_one(&c->rvalue_vals, &default_search_base);
2054 value_add_one(&c->rvalue_nvals, &default_search_nbase);
2058 } else if( c->op == LDAP_MOD_DELETE ) {
2059 ch_free( default_search_base.bv_val );
2060 ch_free( default_search_nbase.bv_val );
2061 BER_BVZERO( &default_search_base );
2062 BER_BVZERO( &default_search_nbase );
2066 if(c->bi || c->be != frontendDB) {
2067 Debug(LDAP_DEBUG_ANY, "%s: defaultSearchBase line must appear "
2068 "prior to any backend or database definition\n",
2073 if(default_search_nbase.bv_len) {
2074 free(default_search_base.bv_val);
2075 free(default_search_nbase.bv_val);
2078 default_search_base = c->value_dn;
2079 default_search_nbase = c->value_ndn;
2083 /* For RE23 compatibility we allow this in the global entry
2084 * but we now defer it to the frontend entry to allow modules
2085 * to load new hash types.
2088 config_passwd_hash(ConfigArgs *c) {
2090 if (c->op == SLAP_CONFIG_EMIT) {
2092 /* Don't generate it in the global entry */
2093 if ( c->table == Cft_Global )
2095 for (i=0; default_passwd_hash && default_passwd_hash[i]; i++) {
2096 ber_str2bv(default_passwd_hash[i], 0, 0, &bv);
2097 value_add_one(&c->rvalue_vals, &bv);
2100 } else if ( c->op == LDAP_MOD_DELETE ) {
2101 /* Deleting from global is a no-op, only the frontendDB entry matters */
2102 if ( c->table == Cft_Global )
2104 if ( c->valx < 0 ) {
2105 ldap_charray_free( default_passwd_hash );
2106 default_passwd_hash = NULL;
2109 ch_free( default_passwd_hash[i] );
2110 for (; default_passwd_hash[i]; i++ )
2111 default_passwd_hash[i] = default_passwd_hash[i+1];
2115 for(i = 1; i < c->argc; i++) {
2116 if(!lutil_passwd_scheme(c->argv[i])) {
2117 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> scheme not available", c->argv[0] );
2118 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2119 c->log, c->cr_msg, c->argv[i]);
2121 ldap_charray_add(&default_passwd_hash, c->argv[i]);
2124 if(!default_passwd_hash) {
2125 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> no valid hashes found", c->argv[0] );
2126 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2127 c->log, c->cr_msg, 0 );
2134 config_schema_dn(ConfigArgs *c) {
2135 if ( c->op == SLAP_CONFIG_EMIT ) {
2137 if ( !BER_BVISEMPTY( &c->be->be_schemadn )) {
2138 value_add_one(&c->rvalue_vals, &c->be->be_schemadn);
2139 value_add_one(&c->rvalue_nvals, &c->be->be_schemandn);
2143 } else if ( c->op == LDAP_MOD_DELETE ) {
2144 ch_free( c->be->be_schemadn.bv_val );
2145 ch_free( c->be->be_schemandn.bv_val );
2146 BER_BVZERO( &c->be->be_schemadn );
2147 BER_BVZERO( &c->be->be_schemandn );
2150 ch_free( c->be->be_schemadn.bv_val );
2151 ch_free( c->be->be_schemandn.bv_val );
2152 c->be->be_schemadn = c->value_dn;
2153 c->be->be_schemandn = c->value_ndn;
2158 config_sizelimit(ConfigArgs *c) {
2160 struct slap_limits_set *lim = &c->be->be_def_limit;
2161 if (c->op == SLAP_CONFIG_EMIT) {
2166 limits_unparse_one( lim, SLAP_LIMIT_SIZE, &bv, sizeof( buf ) );
2167 if ( !BER_BVISEMPTY( &bv ))
2168 value_add_one( &c->rvalue_vals, &bv );
2172 } else if ( c->op == LDAP_MOD_DELETE ) {
2173 /* Reset to defaults */
2174 lim->lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;
2175 lim->lms_s_hard = 0;
2176 lim->lms_s_unchecked = -1;
2178 lim->lms_s_pr_hide = 0;
2179 lim->lms_s_pr_total = 0;
2182 for(i = 1; i < c->argc; i++) {
2183 if(!strncasecmp(c->argv[i], "size", 4)) {
2184 rc = limits_parse_one(c->argv[i], lim);
2186 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2187 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2188 c->log, c->cr_msg, c->argv[i]);
2192 if(!strcasecmp(c->argv[i], "unlimited")) {
2193 lim->lms_s_soft = -1;
2195 if ( lutil_atoix( &lim->lms_s_soft, c->argv[i], 0 ) != 0 ) {
2196 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2197 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2198 c->log, c->cr_msg, c->argv[i]);
2202 lim->lms_s_hard = 0;
2209 config_timelimit(ConfigArgs *c) {
2211 struct slap_limits_set *lim = &c->be->be_def_limit;
2212 if (c->op == SLAP_CONFIG_EMIT) {
2217 limits_unparse_one( lim, SLAP_LIMIT_TIME, &bv, sizeof( buf ) );
2218 if ( !BER_BVISEMPTY( &bv ))
2219 value_add_one( &c->rvalue_vals, &bv );
2223 } else if ( c->op == LDAP_MOD_DELETE ) {
2224 /* Reset to defaults */
2225 lim->lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;
2226 lim->lms_t_hard = 0;
2229 for(i = 1; i < c->argc; i++) {
2230 if(!strncasecmp(c->argv[i], "time", 4)) {
2231 rc = limits_parse_one(c->argv[i], lim);
2233 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse value", c->argv[0] );
2234 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2235 c->log, c->cr_msg, c->argv[i]);
2239 if(!strcasecmp(c->argv[i], "unlimited")) {
2240 lim->lms_t_soft = -1;
2242 if ( lutil_atoix( &lim->lms_t_soft, c->argv[i], 0 ) != 0 ) {
2243 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse limit", c->argv[0]);
2244 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2245 c->log, c->cr_msg, c->argv[i]);
2249 lim->lms_t_hard = 0;
2256 config_overlay(ConfigArgs *c) {
2257 if (c->op == SLAP_CONFIG_EMIT) {
2259 } else if ( c->op == LDAP_MOD_DELETE ) {
2262 if(c->argv[1][0] == '-' && overlay_config(c->be, &c->argv[1][1],
2263 c->valx, &c->bi, &c->reply)) {
2265 Debug( LDAP_DEBUG_ANY,
2266 "%s: (optional) %s overlay \"%s\" configuration failed.\n",
2267 c->log, c->be == frontendDB ? "global " : "", &c->argv[1][1]);
2269 } else if(overlay_config(c->be, c->argv[1], c->valx, &c->bi, &c->reply)) {
2276 config_subordinate(ConfigArgs *c)
2282 case SLAP_CONFIG_EMIT:
2283 if ( SLAP_GLUE_SUBORDINATE( c->be )) {
2286 bv.bv_val = SLAP_GLUE_ADVERTISE( c->be ) ? "advertise" : "TRUE";
2287 bv.bv_len = SLAP_GLUE_ADVERTISE( c->be ) ? STRLENOF("advertise") :
2290 value_add_one( &c->rvalue_vals, &bv );
2294 case LDAP_MOD_DELETE:
2295 if ( !c->line || strcasecmp( c->line, "advertise" )) {
2296 glue_sub_del( c->be );
2298 SLAP_DBFLAGS( c->be ) &= ~SLAP_DBFLAG_GLUE_ADVERTISE;
2303 case SLAP_CONFIG_ADD:
2304 advertise = ( c->argc == 2 && !strcasecmp( c->argv[1], "advertise" ));
2305 rc = glue_sub_add( c->be, advertise, CONFIG_ONLINE_ADD( c ));
2312 config_suffix(ConfigArgs *c)
2315 struct berval pdn, ndn;
2316 char *notallowed = NULL;
2318 if ( c->be == frontendDB ) {
2319 notallowed = "frontend";
2321 } else if ( SLAP_MONITOR(c->be) ) {
2322 notallowed = "monitor";
2324 } else if ( SLAP_CONFIG(c->be) ) {
2325 notallowed = "config";
2328 if ( notallowed != NULL ) {
2329 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
2333 case LDAP_MOD_DELETE:
2334 case LDAP_MOD_REPLACE:
2335 case LDAP_MOD_INCREMENT:
2336 case SLAP_CONFIG_ADD:
2337 if ( !BER_BVISNULL( &c->value_dn ) ) {
2338 snprintf( buf, sizeof( buf ), "<%s> ",
2339 c->value_dn.bv_val );
2342 Debug(LDAP_DEBUG_ANY,
2343 "%s: suffix %snot allowed in %s database.\n",
2344 c->log, buf, notallowed );
2347 case SLAP_CONFIG_EMIT:
2348 /* don't complain when emitting... */
2352 /* FIXME: don't know what values may be valid;
2353 * please remove assertion, or add legal values
2354 * to either block */
2362 if (c->op == SLAP_CONFIG_EMIT) {
2363 if ( c->be->be_suffix == NULL
2364 || BER_BVISNULL( &c->be->be_suffix[0] ) )
2368 value_add( &c->rvalue_vals, c->be->be_suffix );
2369 value_add( &c->rvalue_nvals, c->be->be_nsuffix );
2372 } else if ( c->op == LDAP_MOD_DELETE ) {
2373 if ( c->valx < 0 ) {
2374 ber_bvarray_free( c->be->be_suffix );
2375 ber_bvarray_free( c->be->be_nsuffix );
2376 c->be->be_suffix = NULL;
2377 c->be->be_nsuffix = NULL;
2380 ch_free( c->be->be_suffix[i].bv_val );
2381 ch_free( c->be->be_nsuffix[i].bv_val );
2383 c->be->be_suffix[i] = c->be->be_suffix[i+1];
2384 c->be->be_nsuffix[i] = c->be->be_nsuffix[i+1];
2386 } while ( !BER_BVISNULL( &c->be->be_suffix[i] ) );
2391 #ifdef SLAPD_MONITOR_DN
2392 if(!strcasecmp(c->argv[1], SLAPD_MONITOR_DN)) {
2393 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> DN is reserved for monitoring slapd",
2395 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2396 c->log, c->cr_msg, SLAPD_MONITOR_DN);
2401 if (SLAP_DB_ONE_SUFFIX( c->be ) && c->be->be_suffix ) {
2402 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> Only one suffix is allowed on this %s backend",
2403 c->argv[0], c->be->bd_info->bi_type );
2404 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2405 c->log, c->cr_msg, 0);
2412 if (SLAP_DBHIDDEN( c->be ))
2415 tbe = select_backend(&ndn, 0);
2417 Debug( LDAP_DEBUG_ANY, "%s: suffix already served by this backend!.\n",
2423 BackendDB *b2 = tbe;
2425 /* Does tbe precede be? */
2426 while (( b2 = LDAP_STAILQ_NEXT(b2, be_next )) && b2 && b2 != c->be );
2429 char *type = tbe->bd_info->bi_type;
2431 if ( overlay_is_over( tbe ) ) {
2432 slap_overinfo *oi = (slap_overinfo *)tbe->bd_info->bi_private;
2433 type = oi->oi_orig->bi_type;
2436 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> namingContext \"%s\" "
2437 "already served by a preceding %s database",
2438 c->argv[0], pdn.bv_val, type );
2439 Debug(LDAP_DEBUG_ANY, "%s: %s serving namingContext \"%s\"\n",
2440 c->log, c->cr_msg, tbe->be_suffix[0].bv_val);
2446 if(pdn.bv_len == 0 && default_search_nbase.bv_len) {
2447 Debug(LDAP_DEBUG_ANY, "%s: suffix DN empty and default search "
2448 "base provided \"%s\" (assuming okay)\n",
2449 c->log, default_search_base.bv_val, 0);
2451 ber_bvarray_add(&c->be->be_suffix, &pdn);
2452 ber_bvarray_add(&c->be->be_nsuffix, &ndn);
2457 config_rootdn(ConfigArgs *c) {
2458 if (c->op == SLAP_CONFIG_EMIT) {
2459 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2460 value_add_one(&c->rvalue_vals, &c->be->be_rootdn);
2461 value_add_one(&c->rvalue_nvals, &c->be->be_rootndn);
2466 } else if ( c->op == LDAP_MOD_DELETE ) {
2467 ch_free( c->be->be_rootdn.bv_val );
2468 ch_free( c->be->be_rootndn.bv_val );
2469 BER_BVZERO( &c->be->be_rootdn );
2470 BER_BVZERO( &c->be->be_rootndn );
2473 if ( !BER_BVISNULL( &c->be->be_rootdn )) {
2474 ch_free( c->be->be_rootdn.bv_val );
2475 ch_free( c->be->be_rootndn.bv_val );
2477 c->be->be_rootdn = c->value_dn;
2478 c->be->be_rootndn = c->value_ndn;
2483 config_rootpw(ConfigArgs *c) {
2486 if (c->op == SLAP_CONFIG_EMIT) {
2487 if (!BER_BVISEMPTY(&c->be->be_rootpw)) {
2488 /* don't copy, because "rootpw" is marked
2490 c->value_bv = c->be->be_rootpw;
2494 } else if ( c->op == LDAP_MOD_DELETE ) {
2495 ch_free( c->be->be_rootpw.bv_val );
2496 BER_BVZERO( &c->be->be_rootpw );
2500 tbe = select_backend(&c->be->be_rootndn, 0);
2502 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> can only be set when rootdn is under suffix",
2504 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2505 c->log, c->cr_msg, 0);
2508 if ( !BER_BVISNULL( &c->be->be_rootpw ))
2509 ch_free( c->be->be_rootpw.bv_val );
2510 c->be->be_rootpw = c->value_bv;
2515 config_restrict(ConfigArgs *c) {
2516 slap_mask_t restrictops = 0;
2518 slap_verbmasks restrictable_ops[] = {
2519 { BER_BVC("bind"), SLAP_RESTRICT_OP_BIND },
2520 { BER_BVC("add"), SLAP_RESTRICT_OP_ADD },
2521 { BER_BVC("modify"), SLAP_RESTRICT_OP_MODIFY },
2522 { BER_BVC("rename"), SLAP_RESTRICT_OP_RENAME },
2523 { BER_BVC("modrdn"), 0 },
2524 { BER_BVC("delete"), SLAP_RESTRICT_OP_DELETE },
2525 { BER_BVC("search"), SLAP_RESTRICT_OP_SEARCH },
2526 { BER_BVC("compare"), SLAP_RESTRICT_OP_COMPARE },
2527 { BER_BVC("read"), SLAP_RESTRICT_OP_READS },
2528 { BER_BVC("write"), SLAP_RESTRICT_OP_WRITES },
2529 { BER_BVC("extended"), SLAP_RESTRICT_OP_EXTENDED },
2530 { BER_BVC("extended=" LDAP_EXOP_START_TLS ), SLAP_RESTRICT_EXOP_START_TLS },
2531 { BER_BVC("extended=" LDAP_EXOP_MODIFY_PASSWD ), SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
2532 { BER_BVC("extended=" LDAP_EXOP_X_WHO_AM_I ), SLAP_RESTRICT_EXOP_WHOAMI },
2533 { BER_BVC("extended=" LDAP_EXOP_X_CANCEL ), SLAP_RESTRICT_EXOP_CANCEL },
2534 { BER_BVC("all"), SLAP_RESTRICT_OP_ALL },
2538 if (c->op == SLAP_CONFIG_EMIT) {
2539 return mask_to_verbs( restrictable_ops, c->be->be_restrictops,
2541 } else if ( c->op == LDAP_MOD_DELETE ) {
2543 c->be->be_restrictops = 0;
2545 restrictops = verb_to_mask( c->line, restrictable_ops );
2546 c->be->be_restrictops ^= restrictops;
2550 i = verbs_to_mask( c->argc, c->argv, restrictable_ops, &restrictops );
2552 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown operation", c->argv[0] );
2553 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2554 c->log, c->cr_msg, c->argv[i]);
2557 if ( restrictops & SLAP_RESTRICT_OP_EXTENDED )
2558 restrictops &= ~SLAP_RESTRICT_EXOP_MASK;
2559 c->be->be_restrictops |= restrictops;
2564 config_allows(ConfigArgs *c) {
2565 slap_mask_t allows = 0;
2567 slap_verbmasks allowable_ops[] = {
2568 { BER_BVC("bind_v2"), SLAP_ALLOW_BIND_V2 },
2569 { BER_BVC("bind_anon_cred"), SLAP_ALLOW_BIND_ANON_CRED },
2570 { BER_BVC("bind_anon_dn"), SLAP_ALLOW_BIND_ANON_DN },
2571 { BER_BVC("update_anon"), SLAP_ALLOW_UPDATE_ANON },
2572 { BER_BVC("proxy_authz_anon"), SLAP_ALLOW_PROXY_AUTHZ_ANON },
2575 if (c->op == SLAP_CONFIG_EMIT) {
2576 return mask_to_verbs( allowable_ops, global_allows, &c->rvalue_vals );
2577 } else if ( c->op == LDAP_MOD_DELETE ) {
2581 allows = verb_to_mask( c->line, allowable_ops );
2582 global_allows ^= allows;
2586 i = verbs_to_mask(c->argc, c->argv, allowable_ops, &allows);
2588 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
2589 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2590 c->log, c->cr_msg, c->argv[i]);
2593 global_allows |= allows;
2598 config_disallows(ConfigArgs *c) {
2599 slap_mask_t disallows = 0;
2601 slap_verbmasks disallowable_ops[] = {
2602 { BER_BVC("bind_anon"), SLAP_DISALLOW_BIND_ANON },
2603 { BER_BVC("bind_simple"), SLAP_DISALLOW_BIND_SIMPLE },
2604 { BER_BVC("tls_2_anon"), SLAP_DISALLOW_TLS_2_ANON },
2605 { BER_BVC("tls_authc"), SLAP_DISALLOW_TLS_AUTHC },
2606 { BER_BVC("proxy_authz_non_critical"), SLAP_DISALLOW_PROXY_AUTHZ_N_CRIT },
2607 { BER_BVC("dontusecopy_non_critical"), SLAP_DISALLOW_DONTUSECOPY_N_CRIT },
2610 if (c->op == SLAP_CONFIG_EMIT) {
2611 return mask_to_verbs( disallowable_ops, global_disallows, &c->rvalue_vals );
2612 } else if ( c->op == LDAP_MOD_DELETE ) {
2614 global_disallows = 0;
2616 disallows = verb_to_mask( c->line, disallowable_ops );
2617 global_disallows ^= disallows;
2621 i = verbs_to_mask(c->argc, c->argv, disallowable_ops, &disallows);
2623 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature", c->argv[0] );
2624 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
2625 c->log, c->cr_msg, c->argv[i]);
2628 global_disallows |= disallows;
2633 config_requires(ConfigArgs *c) {
2634 slap_mask_t requires = frontendDB->be_requires;
2635 int i, argc = c->argc;
2636 char **argv = c->argv;
2638 slap_verbmasks requires_ops[] = {
2639 { BER_BVC("bind"), SLAP_REQUIRE_BIND },
2640 { BER_BVC("LDAPv3"), SLAP_REQUIRE_LDAP_V3 },
2641 { BER_BVC("authc"), SLAP_REQUIRE_AUTHC },
2642 { BER_BVC("sasl"), SLAP_REQUIRE_SASL },
2643 { BER_BVC("strong"), SLAP_REQUIRE_STRONG },
2646 if (c->op == SLAP_CONFIG_EMIT) {
2647 return mask_to_verbs( requires_ops, c->be->be_requires, &c->rvalue_vals );
2648 } else if ( c->op == LDAP_MOD_DELETE ) {
2650 c->be->be_requires = 0;
2652 requires = verb_to_mask( c->line, requires_ops );
2653 c->be->be_requires ^= requires;
2657 /* "none" can only be first, to wipe out default/global values */
2658 if ( strcasecmp( c->argv[ 1 ], "none" ) == 0 ) {
2663 i = verbs_to_mask(argc, argv, requires_ops, &requires);
2665 if (strcasecmp( c->argv[ i ], "none" ) == 0 ) {
2666 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> \"none\" (#%d) must be listed first", c->argv[0], i - 1 );
2667 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
2668 c->log, c->cr_msg, 0);
2670 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown feature #%d", c->argv[0], i - 1 );
2671 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2672 c->log, c->cr_msg, c->argv[i]);
2676 c->be->be_requires = requires;
2680 static slap_verbmasks *loglevel_ops;
2683 loglevel_init( void )
2685 slap_verbmasks lo[] = {
2686 { BER_BVC("Any"), -1 },
2687 { BER_BVC("Trace"), LDAP_DEBUG_TRACE },
2688 { BER_BVC("Packets"), LDAP_DEBUG_PACKETS },
2689 { BER_BVC("Args"), LDAP_DEBUG_ARGS },
2690 { BER_BVC("Conns"), LDAP_DEBUG_CONNS },
2691 { BER_BVC("BER"), LDAP_DEBUG_BER },
2692 { BER_BVC("Filter"), LDAP_DEBUG_FILTER },
2693 { BER_BVC("Config"), LDAP_DEBUG_CONFIG },
2694 { BER_BVC("ACL"), LDAP_DEBUG_ACL },
2695 { BER_BVC("Stats"), LDAP_DEBUG_STATS },
2696 { BER_BVC("Stats2"), LDAP_DEBUG_STATS2 },
2697 { BER_BVC("Shell"), LDAP_DEBUG_SHELL },
2698 { BER_BVC("Parse"), LDAP_DEBUG_PARSE },
2699 #if 0 /* no longer used (nor supported) */
2700 { BER_BVC("Cache"), LDAP_DEBUG_CACHE },
2701 { BER_BVC("Index"), LDAP_DEBUG_INDEX },
2703 { BER_BVC("Sync"), LDAP_DEBUG_SYNC },
2704 { BER_BVC("None"), LDAP_DEBUG_NONE },
2708 return slap_verbmasks_init( &loglevel_ops, lo );
2712 loglevel_destroy( void )
2714 if ( loglevel_ops ) {
2715 (void)slap_verbmasks_destroy( loglevel_ops );
2717 loglevel_ops = NULL;
2720 static slap_mask_t loglevel_ignore[] = { -1, 0 };
2723 slap_loglevel_register( slap_mask_t m, struct berval *s )
2727 if ( loglevel_ops == NULL ) {
2731 rc = slap_verbmasks_append( &loglevel_ops, m, s, loglevel_ignore );
2734 Debug( LDAP_DEBUG_ANY, "slap_loglevel_register(%lu, \"%s\") failed\n",
2742 slap_loglevel_get( struct berval *s, int *l )
2747 if ( loglevel_ops == NULL ) {
2751 for ( m = 0, i = 1; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
2752 m |= loglevel_ops[ i ].mask;
2755 for ( i = 1; m & i; i <<= 1 )
2762 rc = slap_verbmasks_append( &loglevel_ops, i, s, loglevel_ignore );
2765 Debug( LDAP_DEBUG_ANY, "slap_loglevel_get(%lu, \"%s\") failed\n",
2776 str2loglevel( const char *s, int *l )
2780 if ( loglevel_ops == NULL ) {
2784 i = verb_to_mask( s, loglevel_ops );
2786 if ( BER_BVISNULL( &loglevel_ops[ i ].word ) ) {
2790 *l = loglevel_ops[ i ].mask;
2796 loglevel2str( int l )
2798 struct berval bv = BER_BVNULL;
2800 loglevel2bv( l, &bv );
2806 loglevel2bv( int l, struct berval *bv )
2808 if ( loglevel_ops == NULL ) {
2814 return enum_to_verb( loglevel_ops, l, bv ) == -1;
2818 loglevel2bvarray( int l, BerVarray *bva )
2820 if ( loglevel_ops == NULL ) {
2824 return mask_to_verbs( loglevel_ops, l, bva );
2828 loglevel_print( FILE *out )
2832 if ( loglevel_ops == NULL ) {
2836 fprintf( out, "Installed log subsystems:\n\n" );
2837 for ( i = 0; !BER_BVISNULL( &loglevel_ops[ i ].word ); i++ ) {
2838 fprintf( out, "\t%-30s (%lu)\n",
2839 loglevel_ops[ i ].word.bv_val,
2840 loglevel_ops[ i ].mask );
2843 fprintf( out, "\nNOTE: custom log subsystems may be later installed "
2844 "by specific code\n\n" );
2849 static int config_syslog;
2852 config_loglevel(ConfigArgs *c) {
2855 if ( loglevel_ops == NULL ) {
2859 if (c->op == SLAP_CONFIG_EMIT) {
2860 /* Get default or commandline slapd setting */
2861 if ( ldap_syslog && !config_syslog )
2862 config_syslog = ldap_syslog;
2863 return loglevel2bvarray( config_syslog, &c->rvalue_vals );
2865 } else if ( c->op == LDAP_MOD_DELETE ) {
2869 int level = verb_to_mask( c->line, loglevel_ops );
2870 config_syslog ^= level;
2872 if ( slapMode & SLAP_SERVER_MODE ) {
2873 ldap_syslog = config_syslog;
2878 for( i=1; i < c->argc; i++ ) {
2881 if ( isdigit((unsigned char)c->argv[i][0]) || c->argv[i][0] == '-' ) {
2882 if( lutil_atoi( &level, c->argv[i] ) != 0 ) {
2883 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse level", c->argv[0] );
2884 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2885 c->log, c->cr_msg, c->argv[i]);
2889 if ( str2loglevel( c->argv[i], &level ) ) {
2890 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown level", c->argv[0] );
2891 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
2892 c->log, c->cr_msg, c->argv[i]);
2896 /* Explicitly setting a zero clears all the levels */
2898 config_syslog |= level;
2902 if ( slapMode & SLAP_SERVER_MODE ) {
2903 ldap_syslog = config_syslog;
2909 config_referral(ConfigArgs *c) {
2911 if (c->op == SLAP_CONFIG_EMIT) {
2912 if ( default_referral ) {
2913 value_add( &c->rvalue_vals, default_referral );
2918 } else if ( c->op == LDAP_MOD_DELETE ) {
2919 if ( c->valx < 0 ) {
2920 ber_bvarray_free( default_referral );
2921 default_referral = NULL;
2924 ch_free( default_referral[i].bv_val );
2925 for (; default_referral[i].bv_val; i++ )
2926 default_referral[i] = default_referral[i+1];
2930 if(validate_global_referral(c->argv[1])) {
2931 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
2932 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
2933 c->log, c->cr_msg, c->argv[1]);
2937 ber_str2bv(c->argv[1], 0, 0, &val);
2938 if(value_add_one(&default_referral, &val)) return(LDAP_OTHER);
2946 { BER_BVC("ssf="), offsetof(slap_ssf_set_t, sss_ssf) },
2947 { BER_BVC("transport="), offsetof(slap_ssf_set_t, sss_transport) },
2948 { BER_BVC("tls="), offsetof(slap_ssf_set_t, sss_tls) },
2949 { BER_BVC("sasl="), offsetof(slap_ssf_set_t, sss_sasl) },
2950 { BER_BVC("update_ssf="), offsetof(slap_ssf_set_t, sss_update_ssf) },
2951 { BER_BVC("update_transport="), offsetof(slap_ssf_set_t, sss_update_transport) },
2952 { BER_BVC("update_tls="), offsetof(slap_ssf_set_t, sss_update_tls) },
2953 { BER_BVC("update_sasl="), offsetof(slap_ssf_set_t, sss_update_sasl) },
2954 { BER_BVC("simple_bind="), offsetof(slap_ssf_set_t, sss_simple_bind) },
2959 config_security(ConfigArgs *c) {
2960 slap_ssf_set_t *set = &c->be->be_ssf_set;
2963 if (c->op == SLAP_CONFIG_EMIT) {
2969 for (i=0; !BER_BVISNULL( &sec_keys[i].key ); i++) {
2970 tgt = (slap_ssf_t *)((char *)set + sec_keys[i].off);
2973 bv.bv_len = snprintf( numbuf, sizeof( numbuf ), "%u", *tgt );
2974 if ( bv.bv_len >= sizeof( numbuf ) ) {
2975 ber_bvarray_free_x( c->rvalue_vals, NULL );
2976 c->rvalue_vals = NULL;
2980 bv.bv_len += sec_keys[i].key.bv_len;
2981 bv.bv_val = ch_malloc( bv.bv_len + 1);
2982 next = lutil_strcopy( bv.bv_val, sec_keys[i].key.bv_val );
2983 strcpy( next, numbuf );
2984 ber_bvarray_add( &c->rvalue_vals, &bv );
2989 for(i = 1; i < c->argc; i++) {
2990 slap_ssf_t *tgt = NULL;
2992 for ( j=0; !BER_BVISNULL( &sec_keys[j].key ); j++ ) {
2993 if(!strncasecmp(c->argv[i], sec_keys[j].key.bv_val,
2994 sec_keys[j].key.bv_len)) {
2995 src = c->argv[i] + sec_keys[j].key.bv_len;
2996 tgt = (slap_ssf_t *)((char *)set + sec_keys[j].off);
3001 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown factor", c->argv[0] );
3002 Debug(LDAP_DEBUG_ANY, "%s: %s %s\n",
3003 c->log, c->cr_msg, c->argv[i]);
3007 if ( lutil_atou( tgt, src ) != 0 ) {
3008 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unable to parse factor", c->argv[0] );
3009 Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
3010 c->log, c->cr_msg, c->argv[i]);
3018 anlist_unparse( AttributeName *an, char *ptr, ber_len_t buflen ) {
3022 for (; !BER_BVISNULL( &an->an_name ); an++) {
3023 /* if buflen == 0, assume the buffer size has been
3024 * already checked otherwise */
3025 if ( buflen > 0 && buflen - ( ptr - start ) < comma + an->an_name.bv_len ) return NULL;
3026 if ( comma ) *ptr++ = ',';
3027 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
3034 config_updatedn(ConfigArgs *c) {
3035 if (c->op == SLAP_CONFIG_EMIT) {
3036 if (!BER_BVISEMPTY(&c->be->be_update_ndn)) {
3037 value_add_one(&c->rvalue_vals, &c->be->be_update_ndn);
3038 value_add_one(&c->rvalue_nvals, &c->be->be_update_ndn);
3042 } else if ( c->op == LDAP_MOD_DELETE ) {
3043 ch_free( c->be->be_update_ndn.bv_val );
3044 BER_BVZERO( &c->be->be_update_ndn );
3045 SLAP_DBFLAGS(c->be) ^= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW);
3048 if(SLAP_SHADOW(c->be)) {
3049 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> database already shadowed", c->argv[0] );
3050 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3051 c->log, c->cr_msg, 0);
3055 ber_memfree_x( c->value_dn.bv_val, NULL );
3056 if ( !BER_BVISNULL( &c->be->be_update_ndn ) ) {
3057 ber_memfree_x( c->be->be_update_ndn.bv_val, NULL );
3059 c->be->be_update_ndn = c->value_ndn;
3060 BER_BVZERO( &c->value_dn );
3061 BER_BVZERO( &c->value_ndn );
3063 return config_slurp_shadow( c );
3067 config_shadow( ConfigArgs *c, int flag )
3069 char *notallowed = NULL;
3071 if ( c->be == frontendDB ) {
3072 notallowed = "frontend";
3074 } else if ( SLAP_MONITOR(c->be) ) {
3075 notallowed = "monitor";
3078 if ( notallowed != NULL ) {
3079 Debug( LDAP_DEBUG_ANY, "%s: %s database cannot be shadow.\n", c->log, notallowed, 0 );
3083 SLAP_DBFLAGS(c->be) |= (SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SINGLE_SHADOW | flag);
3089 config_updateref(ConfigArgs *c) {
3091 if (c->op == SLAP_CONFIG_EMIT) {
3092 if ( c->be->be_update_refs ) {
3093 value_add( &c->rvalue_vals, c->be->be_update_refs );
3098 } else if ( c->op == LDAP_MOD_DELETE ) {
3099 if ( c->valx < 0 ) {
3100 ber_bvarray_free( c->be->be_update_refs );
3101 c->be->be_update_refs = NULL;
3104 ch_free( c->be->be_update_refs[i].bv_val );
3105 for (; c->be->be_update_refs[i].bv_val; i++)
3106 c->be->be_update_refs[i] = c->be->be_update_refs[i+1];
3110 if(!SLAP_SHADOW(c->be) && !c->be->be_syncinfo) {
3111 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> must appear after syncrepl or updatedn",
3113 Debug(LDAP_DEBUG_ANY, "%s: %s\n",
3114 c->log, c->cr_msg, 0);
3118 if(validate_global_referral(c->argv[1])) {
3119 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> invalid URL", c->argv[0] );
3120 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)\n",
3121 c->log, c->cr_msg, c->argv[1]);
3124 ber_str2bv(c->argv[1], 0, 0, &val);
3125 if(value_add_one(&c->be->be_update_refs, &val)) return(LDAP_OTHER);
3130 config_obsolete(ConfigArgs *c) {
3131 if (c->op == SLAP_CONFIG_EMIT)
3134 snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> keyword is obsolete (ignored)",
3136 Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg, 0);
3141 config_include(ConfigArgs *c) {
3142 int savelineno = c->lineno;
3145 ConfigFile *cfsave = cfn;
3146 ConfigFile *cf2 = NULL;
3148 /* Leftover from RE23. No dynamic config for include files */
3149 if ( c->op == SLAP_CONFIG_EMIT || c->op == LDAP_MOD_DELETE )
3152 cf = ch_calloc( 1, sizeof(ConfigFile));
3153 if ( cfn->c_kids ) {
3154 for (cf2=cfn->c_kids; cf2 && cf2->c_sibs; cf2=cf2->c_sibs) ;
3160 ber_str2bv( c->argv[1], 0, 1, &cf->c_file );
3161 rc = read_config_file(c->argv[1], c->depth + 1, c, config_back_cf_table);
3162 c->lineno = savelineno - 1;
3165 if ( cf2 ) cf2->c_sibs = NULL;
3166 else cfn->c_kids = NULL;
3167 ch_free( cf->c_file.bv_val );
3177 config_tls_option(ConfigArgs *c) {
3179 LDAP *ld = slap_tls_ld;
3181 case CFG_TLS_RAND: flag = LDAP_OPT_X_TLS_RANDOM_FILE; ld = NULL; break;
3182 case CFG_TLS_CIPHER: flag = LDAP_OPT_X_TLS_CIPHER_SUITE; break;
3183 case CFG_TLS_CERT_FILE: flag = LDAP_OPT_X_TLS_CERTFILE; break;
3184 case CFG_TLS_CERT_KEY: flag = LDAP_OPT_X_TLS_KEYFILE; break;
3185 case CFG_TLS_CA_PATH: flag = LDAP_OPT_X_TLS_CACERTDIR; break;
3186 case CFG_TLS_CA_FILE: flag = LDAP_OPT_X_TLS_CACERTFILE; break;
3187 case CFG_TLS_DH_FILE: flag = LDAP_OPT_X_TLS_DHFILE; break;
3189 case CFG_TLS_CRL_FILE: flag = LDAP_OPT_X_TLS_CRLFILE; break;
3191 default: Debug(LDAP_DEBUG_ANY, "%s: "
3192 "unknown tls_option <0x%x>\n",
3193 c->log, c->type, 0);
3196 if (c->op == SLAP_CONFIG_EMIT) {
3197 return ldap_pvt_tls_get_option( ld, flag, &c->value_string );
3198 } else if ( c->op == LDAP_MOD_DELETE ) {
3199 return ldap_pvt_tls_set_option( ld, flag, NULL );
3201 ch_free(c->value_string);
3202 return(ldap_pvt_tls_set_option(ld, flag, c->argv[1]));
3205 /* FIXME: this ought to be provided by libldap */
3207 config_tls_config(ConfigArgs *c) {
3210 case CFG_TLS_CRLCHECK: flag = LDAP_OPT_X_TLS_CRLCHECK; break;
3211 case CFG_TLS_VERIFY: flag = LDAP_OPT_X_TLS_REQUIRE_CERT; break;
3213 Debug(LDAP_DEBUG_ANY, "%s: "
3214 "unknown tls_option <0x%x>\n",
3215 c->log, c->type, 0);
3218 if (c->op == SLAP_CONFIG_EMIT) {
3219 return slap_tls_get_config( slap_tls_ld, flag, &c->value_string );
3220 } else if ( c->op == LDAP_MOD_DELETE ) {
3222 return ldap_pvt_tls_set_option( slap_tls_ld, flag, &i );
3224 ch_free( c->value_string );
3225 if ( isdigit( (unsigned char)c->argv[1][0] ) ) {
3226 if ( lutil_atoi( &i, c->argv[1] ) != 0 ) {
3227 Debug(LDAP_DEBUG_ANY, "%s: "
3228 "unable to parse %s \"%s\"\n",
3229 c->log, c->argv[0], c->argv[1] );
3232 return(ldap_pvt_tls_set_option(slap_tls_ld, flag, &i));
3234 return(ldap_int_tls_config(slap_tls_ld, flag, c->argv[1]));
3239 static CfEntryInfo *
3240 config_find_base( CfEntryInfo *root, struct berval *dn, CfEntryInfo **last )
3250 if ( dn_match( &root->ce_entry->e_nname, dn ))
3253 c = dn->bv_val+dn->bv_len;
3254 for (;*c != ',';c--);
3258 for (--c;c>dn->bv_val && *c != ',';c--);
3262 cdn.bv_len = dn->bv_len - (cdn.bv_val - dn->bv_val);
3264 root = root->ce_kids;
3266 for (;root;root=root->ce_sibs) {
3267 if ( dn_match( &root->ce_entry->e_nname, &cdn )) {
3268 if ( cdn.bv_val == dn->bv_val ) {
3278 typedef struct setup_cookie {
3288 config_ldif_resp( Operation *op, SlapReply *rs )
3290 if ( rs->sr_type == REP_SEARCH ) {
3291 setup_cookie *sc = op->o_callback->sc_private;
3294 sc->cfb->cb_got_ldif = 1;
3295 /* Does the frontend exist? */
3296 if ( !sc->got_frontend ) {
3297 if ( !strncmp( rs->sr_entry->e_nname.bv_val,
3298 "olcDatabase", STRLENOF( "olcDatabase" )))
3300 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3301 STRLENOF( "olcDatabase" ), "={-1}frontend",
3302 STRLENOF( "={-1}frontend" )))
3306 sc->ca->be = frontendDB;
3307 sc->ca->bi = frontendDB->bd_info;
3308 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
3309 rdn.bv_val = sc->ca->log;
3310 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3311 "%s=" SLAP_X_ORDERED_FMT "%s",
3312 cfAd_database->ad_cname.bv_val, -1,
3313 sc->ca->bi->bi_type);
3315 sc->frontend = config_build_entry( op, rs,
3316 sc->cfb->cb_root, sc->ca, &rdn, &CFOC_DATABASE,
3317 sc->ca->be->be_cf_ocs );
3327 dnParent( &rs->sr_entry->e_nname, &pdn );
3329 /* Does the configDB exist? */
3330 if ( sc->got_frontend && !sc->got_config &&
3331 !strncmp( rs->sr_entry->e_nname.bv_val,
3332 "olcDatabase", STRLENOF( "olcDatabase" )) &&
3333 dn_match( &config_rdn, &pdn ) )
3335 if ( strncmp( rs->sr_entry->e_nname.bv_val +
3336 STRLENOF( "olcDatabase" ), "={0}config",
3337 STRLENOF( "={0}config" )))
3341 sc->ca->be = LDAP_STAILQ_FIRST( &backendDB );
3342 sc->ca->bi = sc->ca->be->bd_info;
3343 rdn.bv_val = sc->ca->log;
3344 rdn.bv_len = snprintf(rdn.bv_val, sizeof( sc->ca->log ),
3345 "%s=" SLAP_X_ORDERED_FMT "%s",
3346 cfAd_database->ad_cname.bv_val, 0,
3347 sc->ca->bi->bi_type);
3349 sc->config = config_build_entry( op, rs, sc->cfb->cb_root,
3350 sc->ca, &rdn, &CFOC_DATABASE, sc->ca->be->be_cf_ocs );
3357 rs->sr_err = config_add_internal( sc->cfb, rs->sr_entry, sc->ca, NULL, NULL, NULL );
3358 if ( rs->sr_err != LDAP_SUCCESS ) {
3359 Debug( LDAP_DEBUG_ANY, "config error processing %s: %s\n",
3360 rs->sr_entry->e_name.bv_val, sc->ca->cr_msg, 0 );
3366 /* Configure and read the underlying back-ldif store */
3368 config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
3369 CfBackInfo *cfb = be->be_private;
3375 slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
3376 Connection conn = {0};
3377 OperationBuffer opbuf;
3379 SlapReply rs = {REP_RESULT};
3380 Filter filter = { LDAP_FILTER_PRESENT };
3381 struct berval filterstr = BER_BVC("(objectclass=*)");
3384 /* Is the config directory available? */
3385 if ( stat( dir, &st ) < 0 ) {
3386 /* No, so don't bother using the backing store.
3387 * All changes will be in-memory only.
3392 cfb->cb_db.bd_info = backend_info( "ldif" );
3393 if ( !cfb->cb_db.bd_info )
3394 return 0; /* FIXME: eventually this will be a fatal error */
3396 if ( backend_db_init( "ldif", &cfb->cb_db, -1, NULL ) == NULL )
3399 cfb->cb_db.be_suffix = be->be_suffix;
3400 cfb->cb_db.be_nsuffix = be->be_nsuffix;
3402 /* The suffix is always "cn=config". The underlying DB's rootdn
3403 * is always the same as the suffix.
3405 cfb->cb_db.be_rootdn = be->be_suffix[0];
3406 cfb->cb_db.be_rootndn = be->be_nsuffix[0];
3408 ber_str2bv( dir, 0, 1, &cfdir );
3413 argv[0] = "directory";
3414 argv[1] = (char *)dir;
3419 c.table = Cft_Database;
3421 ct = config_find_keyword( c.be->be_cf_ocs->co_table, &c );
3425 if ( config_add_vals( ct, &c ))
3428 if ( backend_startup_one( &cfb->cb_db, &c.reply ))
3432 void *thrctx = ldap_pvt_thread_pool_context();
3435 connection_fake_init( &conn, &opbuf, thrctx );
3438 filter.f_desc = slap_schema.si_ad_objectClass;
3440 op->o_tag = LDAP_REQ_SEARCH;
3442 op->ors_filter = &filter;
3443 op->ors_filterstr = filterstr;
3444 op->ors_scope = LDAP_SCOPE_SUBTREE;
3446 op->o_dn = c.be->be_rootdn;
3447 op->o_ndn = c.be->be_rootndn;
3449 op->o_req_dn = be->be_suffix[0];
3450 op->o_req_ndn = be->be_nsuffix[0];
3452 op->ors_tlimit = SLAP_NO_LIMIT;
3453 op->ors_slimit = SLAP_NO_LIMIT;
3455 op->ors_attrs = slap_anlist_all_attributes;
3456 op->ors_attrsonly = 0;
3458 op->o_callback = &cb;
3461 cb.sc_private = ≻
3462 sc.got_frontend = 0;
3467 op->o_bd = &cfb->cb_db;
3469 /* Allow unknown attrs in DNs */
3470 prev_DN_strict = slap_DN_strict;
3473 rc = op->o_bd->be_search( op, &rs );
3475 /* Restore normal DN validation */
3476 slap_DN_strict = prev_DN_strict;
3478 op->o_tag = LDAP_REQ_ADD;
3479 if ( rc == LDAP_SUCCESS && sc.frontend ) {
3480 op->ora_e = sc.frontend;
3481 rc = op->o_bd->be_add( op, &rs );
3483 if ( rc == LDAP_SUCCESS && sc.config ) {
3484 op->ora_e = sc.config;
3485 rc = op->o_bd->be_add( op, &rs );
3487 ldap_pvt_thread_pool_context_reset( thrctx );
3490 /* ITS#4194 - only use if it's present, or we're converting. */
3491 if ( !readit || rc == LDAP_SUCCESS )
3492 cfb->cb_use_ldif = 1;
3498 CfOc_cmp( const void *c1, const void *c2 ) {
3499 const ConfigOCs *co1 = c1;
3500 const ConfigOCs *co2 = c2;
3502 return ber_bvcmp( co1->co_name, co2->co_name );
3506 config_register_schema(ConfigTable *ct, ConfigOCs *ocs) {
3509 i = init_config_attrs( ct );
3512 /* set up the objectclasses */
3513 i = init_config_ocs( ocs );
3516 for (i=0; ocs[i].co_def; i++) {
3517 if ( ocs[i].co_oc ) {
3518 ocs[i].co_name = &ocs[i].co_oc->soc_cname;
3519 if ( !ocs[i].co_table )
3520 ocs[i].co_table = ct;
3521 avl_insert( &CfOcTree, &ocs[i], CfOc_cmp, avl_dup_error );
3528 read_config(const char *fname, const char *dir) {
3531 const char *cfdir, *cfname;
3534 /* Setup the config backend */
3535 be = backend_db_init( "config", NULL, 0, NULL );
3539 cfb = be->be_private;
3540 be->be_dfltaccess = ACL_NONE;
3542 /* If no .conf, or a dir was specified, setup the dir */
3543 if ( !fname || dir ) {
3545 /* If explicitly given, check for existence */
3548 if ( stat( dir, &st ) < 0 ) {
3549 Debug( LDAP_DEBUG_ANY,
3550 "invalid config directory %s, error %d\n",
3556 cfdir = SLAPD_DEFAULT_CONFIGDIR;
3558 /* if fname is defaulted, try reading .d */
3559 rc = config_setup_ldif( be, cfdir, !fname );
3562 /* It may be OK if the base object doesn't exist yet. */
3563 if ( rc != LDAP_NO_SUCH_OBJECT )
3565 /* ITS#4194: But if dir was specified and no fname,
3566 * then we were supposed to read the dir. Unless we're
3567 * trying to slapadd the dir...
3569 if ( dir && !fname ) {
3570 if ( slapMode & (SLAP_SERVER_MODE|SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY))
3572 /* Assume it's slapadd with a config dir, let it continue */
3574 cfb->cb_got_ldif = 1;
3575 cfb->cb_use_ldif = 1;
3580 /* If we read the config from back-ldif, nothing to do here */
3581 if ( cfb->cb_got_ldif ) {
3590 cfname = SLAPD_DEFAULT_CONFIGFILE;
3592 rc = read_config_file(cfname, 0, NULL, config_back_cf_table);
3595 ber_str2bv( cfname, 0, 1, &cfb->cb_config->c_file );
3598 if ( rc == 0 && BER_BVISNULL( &frontendDB->be_schemadn ) ) {
3599 ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
3600 &frontendDB->be_schemadn );
3601 rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
3602 if ( rc != LDAP_SUCCESS ) {
3603 Debug(LDAP_DEBUG_ANY, "read_config: "
3604 "unable to normalize default schema DN \"%s\"\n",
3605 frontendDB->be_schemadn.bv_val, 0, 0 );
3606 /* must not happen */
3614 config_back_bind( Operation *op, SlapReply *rs )
3616 if ( be_isroot_pw( op ) ) {
3617 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ));
3618 /* frontend sends result */
3619 return LDAP_SUCCESS;
3622 rs->sr_err = LDAP_INVALID_CREDENTIALS;
3623 send_ldap_result( op, rs );
3629 config_send( Operation *op, SlapReply *rs, CfEntryInfo *ce, int depth )
3633 if ( test_filter( op, ce->ce_entry, op->ors_filter ) == LDAP_COMPARE_TRUE )
3635 rs->sr_attrs = op->ors_attrs;
3636 rs->sr_entry = ce->ce_entry;
3638 rc = send_search_entry( op, rs );
3640 if ( op->ors_scope == LDAP_SCOPE_SUBTREE ) {
3641 if ( ce->ce_kids ) {
3642 rc = config_send( op, rs, ce->ce_kids, 1 );
3643 if ( rc ) return rc;
3646 for (ce=ce->ce_sibs; ce; ce=ce->ce_sibs) {
3647 rc = config_send( op, rs, ce, 0 );
3655 static ConfigTable *
3656 config_find_table( ConfigOCs **colst, int nocs, AttributeDescription *ad,
3661 for (j=0; j<nocs; j++) {
3662 for (i=0; colst[j]->co_table[i].name; i++)
3663 if ( colst[j]->co_table[i].ad == ad ) {
3664 ca->table = colst[j]->co_type;
3665 return &colst[j]->co_table[i];
3671 /* Sort the attributes of the entry according to the order defined
3672 * in the objectclass, with required attributes occurring before
3673 * allowed attributes. For any attributes with sequencing dependencies
3674 * (e.g., rootDN must be defined after suffix) the objectclass must
3675 * list the attributes in the desired sequence.
3678 sort_attrs( Entry *e, ConfigOCs **colst, int nocs )
3680 Attribute *a, *head = NULL, *tail = NULL, **prev;
3683 for (i=0; i<nocs; i++) {
3684 if ( colst[i]->co_oc->soc_required ) {
3685 AttributeType **at = colst[i]->co_oc->soc_required;
3686 for (j=0; at[j]; j++) {
3687 for (a=e->e_attrs, prev=&e->e_attrs; a;
3688 prev = &(*prev)->a_next, a=a->a_next) {
3689 if ( a->a_desc == at[j]->sat_ad ) {
3703 if ( colst[i]->co_oc->soc_allowed ) {
3704 AttributeType **at = colst[i]->co_oc->soc_allowed;
3705 for (j=0; at[j]; j++) {
3706 for (a=e->e_attrs, prev=&e->e_attrs; a;
3707 prev = &(*prev)->a_next, a=a->a_next) {
3708 if ( a->a_desc == at[j]->sat_ad ) {
3724 tail->a_next = e->e_attrs;
3730 check_vals( ConfigTable *ct, ConfigArgs *ca, void *ptr, int isAttr )
3732 Attribute *a = NULL;
3733 AttributeDescription *ad;
3743 Modifications *ml = ptr;
3745 vals = ml->sml_values;
3748 if ( a && ( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL )) {
3749 rc = ordered_value_sort( a, 1 );
3751 snprintf(ca->cr_msg, sizeof( ca->cr_msg ), "ordered_value_sort failed on attr %s\n",
3752 ad->ad_cname.bv_val );
3756 for ( i=0; vals[i].bv_val; i++ ) {
3757 ca->line = vals[i].bv_val;
3758 if (( ad->ad_type->sat_flags & SLAP_AT_ORDERED_VAL ) &&
3759 ca->line[0] == '{' ) {
3760 char *idx = strchr( ca->line, '}' );
3761 if ( idx ) ca->line = idx+1;
3763 rc = config_parse_vals( ct, ca, i );
3772 config_rename_attr( SlapReply *rs, Entry *e, struct berval *rdn,
3775 struct berval rtype, rval;
3777 AttributeDescription *ad = NULL;
3779 dnRdn( &e->e_name, rdn );
3780 rval.bv_val = strchr(rdn->bv_val, '=' ) + 1;
3781 rval.bv_len = rdn->bv_len - (rval.bv_val - rdn->bv_val);
3782 rtype.bv_val = rdn->bv_val;
3783 rtype.bv_len = rval.bv_val - rtype.bv_val - 1;
3786 slap_bv2ad( &rtype, &ad, &rs->sr_text );
3787 a = attr_find( e->e_attrs, ad );
3788 if (!a ) return LDAP_NAMING_VIOLATION;
3795 config_rename_kids( CfEntryInfo *ce )
3798 struct berval rdn, nrdn;
3800 for (ce2 = ce->ce_kids; ce2; ce2 = ce2->ce_sibs) {
3801 dnRdn ( &ce2->ce_entry->e_name, &rdn );
3802 dnRdn ( &ce2->ce_entry->e_nname, &nrdn );
3803 free( ce2->ce_entry->e_name.bv_val );
3804 free( ce2->ce_entry->e_nname.bv_val );
3805 build_new_dn( &ce2->ce_entry->e_name, &ce->ce_entry->e_name,
3807 build_new_dn( &ce2->ce_entry->e_nname, &ce->ce_entry->e_nname,
3809 config_rename_kids( ce2 );
3814 config_rename_one( Operation *op, SlapReply *rs, Entry *e,
3815 CfEntryInfo *parent, Attribute *a, struct berval *newrdn,
3816 struct berval *nnewrdn, int use_ldif )
3820 struct berval odn, ondn;
3824 build_new_dn( &e->e_name, &parent->ce_entry->e_name, newrdn, NULL );
3825 build_new_dn( &e->e_nname, &parent->ce_entry->e_nname, nnewrdn, NULL );
3828 free( a->a_vals[0].bv_val );
3829 ptr1 = strchr( newrdn->bv_val, '=' ) + 1;
3830 a->a_vals[0].bv_len = newrdn->bv_len - (ptr1 - newrdn->bv_val);
3831 a->a_vals[0].bv_val = ch_malloc( a->a_vals[0].bv_len + 1 );
3832 strcpy( a->a_vals[0].bv_val, ptr1 );
3834 if ( a->a_nvals != a->a_vals ) {
3835 free( a->a_nvals[0].bv_val );
3836 ptr1 = strchr( nnewrdn->bv_val, '=' ) + 1;
3837 a->a_nvals[0].bv_len = nnewrdn->bv_len - (ptr1 - nnewrdn->bv_val);
3838 a->a_nvals[0].bv_val = ch_malloc( a->a_nvals[0].bv_len + 1 );
3839 strcpy( a->a_nvals[0].bv_val, ptr1 );
3842 CfBackInfo *cfb = (CfBackInfo *)op->o_bd->be_private;
3843 BackendDB *be = op->o_bd;
3844 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
3845 struct berval dn, ndn, xdn, xndn;
3847 op->o_bd = &cfb->cb_db;
3849 /* Save current rootdn; use the underlying DB's rootdn */
3853 xndn = op->o_req_ndn;
3854 op->o_dn = op->o_bd->be_rootdn;
3855 op->o_ndn = op->o_bd->be_rootndn;
3857 op->o_req_ndn = ondn;
3859 scp = op->o_callback;
3860 op->o_callback = ≻
3861 op->orr_newrdn = *newrdn;
3862 op->orr_nnewrdn = *nnewrdn;
3863 op->orr_newSup = NULL;
3864 op->orr_nnewSup = NULL;
3865 op->orr_deleteoldrdn = 1;
3866 op->orr_modlist = NULL;
3867 slap_modrdn2mods( op, rs );
3868 slap_mods_opattrs( op, &op->orr_modlist, 1 );
3869 rc = op->o_bd->be_modrdn( op, rs );
3870 slap_mods_free( op->orr_modlist, 1 );
3873 op->o_callback = scp;
3877 op->o_req_ndn = xndn;
3880 free( ondn.bv_val );
3882 config_rename_kids( e->e_private );
3887 config_renumber_one( Operation *op, SlapReply *rs, CfEntryInfo *parent,
3888 Entry *e, int idx, int tailindex, int use_ldif )
3890 struct berval ival, newrdn, nnewrdn;
3893 char ibuf[32], *ptr1, *ptr2 = NULL;
3896 rc = config_rename_attr( rs, e, &rdn, &a );
3897 if ( rc ) return rc;
3900 ival.bv_len = snprintf( ibuf, sizeof( ibuf ), SLAP_X_ORDERED_FMT, idx );
3901 if ( ival.bv_len >= sizeof( ibuf ) ) {
3902 return LDAP_NAMING_VIOLATION;
3905 newrdn.bv_len = rdn.bv_len + ival.bv_len;
3906 newrdn.bv_val = ch_malloc( newrdn.bv_len+1 );
3909 ptr1 = lutil_strncopy( newrdn.bv_val, rdn.bv_val, rdn.bv_len );
3910 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3913 ptr2 = ber_bvchr( &rdn, '}' );
3917 ptr2 = rdn.bv_val + a->a_desc->ad_cname.bv_len + 1;
3919 xlen = rdn.bv_len - (ptr2 - rdn.bv_val);
3920 ptr1 = lutil_strncopy( newrdn.bv_val, a->a_desc->ad_cname.bv_val,
3921 a->a_desc->ad_cname.bv_len );
3923 ptr1 = lutil_strcopy( ptr1, ival.bv_val );
3924 ptr1 = lutil_strncopy( ptr1, ptr2, xlen );
3928 /* Do the equivalent of ModRDN */
3929 /* Replace DN / NDN */
3930 newrdn.bv_len = ptr1 - newrdn.bv_val;
3931 rdnNormalize( 0, NULL, NULL, &newrdn, &nnewrdn, NULL );
3932 rc = config_rename_one( op, rs, e, parent, a, &newrdn, &nnewrdn, use_ldif );
3934 free( nnewrdn.bv_val );
3935 free( newrdn.bv_val );
3940 check_name_index( CfEntryInfo *parent, ConfigType ce_type, Entry *e,
3941 SlapReply *rs, int *renum, int *ibase )
3944 int index = -1, gotindex = 0, nsibs, rc = 0;
3945 int renumber = 0, tailindex = 0, isfrontend = 0, isconfig = 0;
3946 char *ptr1, *ptr2 = NULL;
3949 if ( renum ) *renum = 0;
3951 /* These entries don't get indexed/renumbered */
3952 if ( ce_type == Cft_Global ) return 0;
3953 if ( ce_type == Cft_Schema && parent->ce_type == Cft_Global ) return 0;
3955 if ( ce_type == Cft_Module )
3958 /* See if the rdn has an index already */
3959 dnRdn( &e->e_name, &rdn );
3960 if ( ce_type == Cft_Database ) {
3961 if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("frontend"),
3962 "frontend", STRLENOF("frontend") ))
3964 else if ( !strncmp( rdn.bv_val + rdn.bv_len - STRLENOF("config"),
3965 "config", STRLENOF("config") ))
3968 ptr1 = ber_bvchr( &e->e_name, '{' );
3969 if ( ptr1 && ptr1 < &e->e_name.bv_val[ rdn.bv_len ] ) {
3971 ptr2 = strchr( ptr1, '}' );
3972 if ( !ptr2 || ptr2 > &e->e_name.bv_val[ rdn.bv_len ] )
3973 return LDAP_NAMING_VIOLATION;
3974 if ( ptr2-ptr1 == 1)
3975 return LDAP_NAMING_VIOLATION;
3977 index = strtol( ptr1 + 1, &next, 10 );
3978 if ( next == ptr1 + 1 || next[ 0 ] != '}' ) {
3979 return LDAP_NAMING_VIOLATION;
3982 /* Special case, we allow -1 for the frontendDB */
3983 if ( index != -1 || !isfrontend )
3984 return LDAP_NAMING_VIOLATION;
3986 if ( isconfig && index != 0 ){
3987 return LDAP_NAMING_VIOLATION;
3991 /* count related kids */
3992 for (nsibs=0, ce=parent->ce_kids; ce; ce=ce->ce_sibs) {
3993 if ( ce->ce_type == ce_type ) nsibs++;
3996 /* account for -1 frontend */
3997 if ( ce_type == Cft_Database )
4000 if ( index != nsibs ) {
4002 if ( index < nsibs ) {
4003 if ( tailindex ) return LDAP_NAMING_VIOLATION;
4004 /* Siblings need to be renumbered */
4005 if ( index != -1 || !isfrontend )
4009 /* config DB is always "0" */
4010 if ( isconfig && index == -1 ) {
4013 if (( !isfrontend && index == -1 ) || ( index > nsibs ) ){
4017 /* just make index = nsibs */
4019 rc = config_renumber_one( NULL, rs, parent, e, index, tailindex, 0 );
4022 if ( ibase ) *ibase = index;
4023 if ( renum ) *renum = renumber;
4028 count_oc( ObjectClass *oc, ConfigOCs ***copp, int *nocs )
4033 co.co_name = &oc->soc_cname;
4034 cop = avl_find( CfOcTree, &co, CfOc_cmp );
4038 /* check for duplicates */
4039 for ( i = 0; i < *nocs; i++ ) {
4040 if ( *copp && (*copp)[i] == cop ) {
4046 ConfigOCs **tmp = ch_realloc( *copp, (*nocs + 1)*sizeof( ConfigOCs * ) );
4047 if ( tmp == NULL ) {
4051 (*copp)[*nocs] = cop;
4056 for ( sups = oc->soc_sups; sups && *sups; sups++ ) {
4057 if ( count_oc( *sups, copp, nocs ) ) {
4066 count_ocs( Attribute *oc_at, int *nocs )
4069 ConfigOCs **colst = NULL;
4073 for ( i = 0; !BER_BVISNULL( &oc_at->a_nvals[i] ); i++ )
4077 ObjectClass *oc = oc_bvfind( &oc_at->a_nvals[i] );
4079 assert( oc != NULL );
4080 if ( count_oc( oc, &colst, nocs ) ) {
4090 cfAddInclude( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4092 /* Leftover from RE23. Never parse this entry */
4093 return LDAP_COMPARE_TRUE;
4097 cfAddSchema( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
4101 /* This entry is hardcoded, don't re-parse it */
4102 if ( p->ce_type == Cft_Global ) {
4103 cfn = p->ce_private;
4104 ca->ca_private = cfn;
4105 return LDAP_COMPARE_TRUE;
4107 if ( p->ce_type != Cft_Schema )
4108 return LDAP_CONSTRAINT_VIOLATION;
4110 cfn = ch_calloc( 1, sizeof(ConfigFile) );
4111 ca->ca_private = cfn;
4112 cfo = p->ce_private;
4113 cfn->c_sibs = cfo->c_kids;
4115 return LDAP_SUCCESS;
4119 cfAddDatabase( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4121 if ( p->ce_type != Cft_Global ) {
4122 return LDAP_CONSTRAINT_VIOLATION;
4124 /* config must be {0}, nothing else allowed */
4125 if ( !strncmp( e->e_nname.bv_val, "olcDatabase={0}", STRLENOF("olcDatabase={0}")) &&
4126 strncmp( e->e_nname.bv_val + STRLENOF("olcDatabase={0}"), "config,", STRLENOF("config,") )) {
4127 return LDAP_CONSTRAINT_VIOLATION;
4129 ca->be = frontendDB; /* just to get past check_vals */
4130 return LDAP_SUCCESS;
4134 cfAddBackend( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4136 if ( p->ce_type != Cft_Global ) {
4137 return LDAP_CONSTRAINT_VIOLATION;
4139 return LDAP_SUCCESS;
4143 cfAddModule( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4145 if ( p->ce_type != Cft_Global ) {
4146 return LDAP_CONSTRAINT_VIOLATION;
4148 return LDAP_SUCCESS;
4152 cfAddOverlay( CfEntryInfo *p, Entry *e, struct config_args_s *ca )
4154 if ( p->ce_type != Cft_Database ) {
4155 return LDAP_CONSTRAINT_VIOLATION;
4158 return LDAP_SUCCESS;
4162 schema_destroy_one( ConfigArgs *ca, ConfigOCs **colst, int nocs,
4167 AttributeDescription *ad;
4172 if ( cfn->c_cr_head ) {
4173 struct berval bv = BER_BVC("olcDitContentRules");
4175 slap_bv2ad( &bv, &ad, &text );
4176 ct = config_find_table( colst, nocs, ad, ca );
4177 config_del_vals( ct, ca );
4179 if ( cfn->c_oc_head ) {
4180 struct berval bv = BER_BVC("olcObjectClasses");
4182 slap_bv2ad( &bv, &ad, &text );
4183 ct = config_find_table( colst, nocs, ad, ca );
4184 config_del_vals( ct, ca );
4186 if ( cfn->c_at_head ) {
4187 struct berval bv = BER_BVC("olcAttributeTypes");
4189 slap_bv2ad( &bv, &ad, &text );
4190 ct = config_find_table( colst, nocs, ad, ca );
4191 config_del_vals( ct, ca );
4193 if ( cfn->c_syn_head ) {
4194 struct berval bv = BER_BVC("olcLdapSyntaxes");
4196 slap_bv2ad( &bv, &ad, &text );
4197 ct = config_find_table( colst, nocs, ad, ca );
4198 config_del_vals( ct, ca );
4200 if ( cfn->c_om_head ) {
4201 struct berval bv = BER_BVC("olcObjectIdentifier");
4203 slap_bv2ad( &bv, &ad, &text );
4204 ct = config_find_table( colst, nocs, ad, ca );
4205 config_del_vals( ct, ca );
4207 cfo = p->ce_private;
4208 cfo->c_kids = cfn->c_sibs;
4213 config_add_oc( ConfigOCs **cop, CfEntryInfo *last, Entry *e, ConfigArgs *ca )
4215 int rc = LDAP_CONSTRAINT_VIOLATION;
4218 if ( (*cop)->co_ldadd ) {
4219 rc = (*cop)->co_ldadd( last, e, ca );
4220 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4225 for ( ocp = (*cop)->co_oc->soc_sups; ocp && *ocp; ocp++ ) {
4226 ConfigOCs co = { 0 };
4228 co.co_name = &(*ocp)->soc_cname;
4229 *cop = avl_find( CfOcTree, &co, CfOc_cmp );
4230 if ( *cop == NULL ) {
4234 rc = config_add_oc( cop, last, e, ca );
4235 if ( rc != LDAP_CONSTRAINT_VIOLATION ) {
4243 /* Parse an LDAP entry into config directives */
4245 config_add_internal( CfBackInfo *cfb, Entry *e, ConfigArgs *ca, SlapReply *rs,
4246 int *renum, Operation *op )
4248 CfEntryInfo *ce, *last = NULL;
4249 ConfigOCs co, *coptr, **colst;
4250 Attribute *a, *oc_at, *soc_at;
4251 int i, ibase = -1, nocs, rc = 0;
4254 char *ptr, *log_prefix = op ? op->o_log_prefix : "";
4256 memset( ca, 0, sizeof(ConfigArgs));
4258 /* Make sure parent exists and entry does not. But allow
4259 * Databases and Overlays to be inserted. Don't do any
4260 * auto-renumbering if manageDSAit control is present.
4262 ce = config_find_base( cfb->cb_root, &e->e_nname, &last );
4264 if ( ( op && op->o_managedsait ) ||
4265 ( ce->ce_type != Cft_Database && ce->ce_type != Cft_Overlay &&
4266 ce->ce_type != Cft_Module ) )
4268 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4269 "DN=\"%s\" already exists\n",
4270 log_prefix, e->e_name.bv_val, 0 );
4271 return LDAP_ALREADY_EXISTS;
4275 dnParent( &e->e_nname, &pdn );
4277 /* If last is NULL, the new entry is the root/suffix entry,
4278 * otherwise last should be the parent.
4280 if ( last && !dn_match( &last->ce_entry->e_nname, &pdn ) ) {
4282 rs->sr_matched = last->ce_entry->e_name.bv_val;
4284 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4285 "DN=\"%s\" not child of DN=\"%s\"\n",
4286 log_prefix, e->e_name.bv_val,
4287 last->ce_entry->e_name.bv_val );
4288 return LDAP_NO_SUCH_OBJECT;
4292 /* No parent, must be root. This will never happen... */
4293 if ( !last && !be_isroot( op ) && !be_shadow_update( op ) ) {
4294 return LDAP_NO_SUCH_OBJECT;
4297 if ( last && !access_allowed( op, last->ce_entry,
4298 slap_schema.si_ad_children, NULL, ACL_WADD, NULL ) )
4300 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4301 "DN=\"%s\" no write access to \"children\" of parent\n",
4302 log_prefix, e->e_name.bv_val, 0 );
4303 return LDAP_INSUFFICIENT_ACCESS;
4307 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4309 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4310 "DN=\"%s\" no objectClass\n",
4311 log_prefix, e->e_name.bv_val, 0 );
4312 return LDAP_OBJECT_CLASS_VIOLATION;
4315 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4317 ObjectClass *soc = NULL;
4318 char textbuf[ SLAP_TEXT_BUFLEN ];
4319 const char *text = textbuf;
4321 /* FIXME: check result */
4322 rc = structural_class( oc_at->a_nvals, &soc, NULL,
4323 &text, textbuf, sizeof(textbuf), NULL );
4324 if ( rc != LDAP_SUCCESS ) {
4325 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4326 "DN=\"%s\" no structural objectClass (%s)\n",
4327 log_prefix, e->e_name.bv_val, text );
4330 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &soc->soc_cname, NULL );
4331 soc_at = attr_find( e->e_attrs, slap_schema.si_ad_structuralObjectClass );
4332 if ( soc_at == NULL ) {
4333 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4334 "DN=\"%s\" no structural objectClass; "
4335 "unable to merge computed class %s\n",
4336 log_prefix, e->e_name.bv_val,
4337 soc->soc_cname.bv_val );
4338 return LDAP_OBJECT_CLASS_VIOLATION;
4341 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4342 "DN=\"%s\" no structural objectClass; "
4343 "computed objectClass %s merged\n",
4344 log_prefix, e->e_name.bv_val,
4345 soc->soc_cname.bv_val );
4348 /* Fake the coordinates based on whether we're part of an
4349 * LDAP Add or if reading the config dir
4352 ca->fname = "slapd";
4355 ca->fname = cfdir.bv_val;
4360 co.co_name = &soc_at->a_nvals[0];
4361 coptr = avl_find( CfOcTree, &co, CfOc_cmp );
4362 if ( coptr == NULL ) {
4363 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4364 "DN=\"%s\" no structural objectClass in configuration table\n",
4365 log_prefix, e->e_name.bv_val, 0 );
4366 return LDAP_OBJECT_CLASS_VIOLATION;
4369 /* Only the root can be Cft_Global, everything else must
4370 * have a parent. Only limited nesting arrangements are allowed.
4372 rc = LDAP_CONSTRAINT_VIOLATION;
4373 if ( coptr->co_type == Cft_Global && !last ) {
4374 cfn = cfb->cb_config;
4375 ca->ca_private = cfn;
4376 ca->be = frontendDB; /* just to get past check_vals */
4380 colst = count_ocs( oc_at, &nocs );
4382 /* Check whether the Add is allowed by its parent, and do
4383 * any necessary arg setup
4386 rc = config_add_oc( &coptr, last, e, ca );
4387 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4388 for ( i = 0; i<nocs; i++ ) {
4389 /* Already checked these */
4390 if ( colst[i]->co_oc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
4392 if ( colst[i]->co_ldadd &&
4393 ( rc = colst[i]->co_ldadd( last, e, ca ))
4394 != LDAP_CONSTRAINT_VIOLATION ) {
4400 if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
4401 Debug( LDAP_DEBUG_TRACE, "%s: config_add_internal: "
4402 "DN=\"%s\" no structural objectClass add function\n",
4403 log_prefix, e->e_name.bv_val, 0 );
4404 return LDAP_OBJECT_CLASS_VIOLATION;
4408 /* Add the entry but don't parse it, we already have its contents */
4409 if ( rc == LDAP_COMPARE_TRUE ) {
4414 if ( rc != LDAP_SUCCESS )
4417 /* Parse all the values and check for simple syntax errors before
4418 * performing any set actions.
4420 * If doing an LDAPadd, check for indexed names and any necessary
4421 * renaming/renumbering. Entries that don't need indexed names are
4422 * ignored. Entries that need an indexed name and arrive without one
4423 * are assigned to the end. Entries that arrive with an index may
4424 * cause the following entries to be renumbered/bumped down.
4426 * Note that "pseudo-indexed" entries (cn=Include{xx}, cn=Module{xx})
4427 * don't allow Adding an entry with an index that's already in use.
4428 * This is flagged as an error (LDAP_ALREADY_EXISTS) up above.
4430 * These entries can have auto-assigned indexes (appended to the end)
4431 * but only the other types support auto-renumbering of siblings.
4434 rc = check_name_index( last, coptr->co_type, e, rs, renum,
4439 if ( renum && *renum && coptr->co_type != Cft_Database &&
4440 coptr->co_type != Cft_Overlay )
4442 snprintf( ca->cr_msg, sizeof( ca->cr_msg ),
4443 "operation requires sibling renumbering" );
4444 rc = LDAP_UNWILLING_TO_PERFORM;
4449 init_config_argv( ca );
4451 /* Make sure we process attrs in the required order */
4452 sort_attrs( e, colst, nocs );
4454 for ( a = e->e_attrs; a; a = a->a_next ) {
4455 if ( a == oc_at ) continue;
4456 ct = config_find_table( colst, nocs, a->a_desc, ca );
4457 if ( !ct ) continue; /* user data? */
4458 rc = check_vals( ct, ca, a, 1 );
4459 if ( rc ) goto done_noop;
4462 /* Basic syntax checks are OK. Do the actual settings. */
4463 for ( a=e->e_attrs; a; a=a->a_next ) {
4464 if ( a == oc_at ) continue;
4465 ct = config_find_table( colst, nocs, a->a_desc, ca );
4466 if ( !ct ) continue; /* user data? */
4467 for (i=0; a->a_vals[i].bv_val; i++) {
4469 ca->line = a->a_vals[i].bv_val;
4470 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED ) {
4471 ptr = strchr( ca->line, '}' );
4473 iptr = strchr( ca->line, '{' );
4477 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED_SIB ) {
4479 ca->valx = strtol( iptr+1, NULL, 0 );
4486 rc = config_parse_add( ct, ca, i );
4494 /* Newly added databases and overlays need to be started up */
4495 if ( CONFIG_ONLINE_ADD( ca )) {
4496 if ( colst[0]->co_type == Cft_Database ) {
4497 rc = backend_startup_one( ca->be, &ca->reply );
4499 } else if ( colst[0]->co_type == Cft_Overlay ) {
4500 if ( ca->bi->bi_db_open ) {
4501 BackendInfo *bi_orig = ca->be->bd_info;
4502 ca->be->bd_info = ca->bi;
4503 rc = ca->bi->bi_db_open( ca->be, &ca->reply );
4504 ca->be->bd_info = bi_orig;
4506 } else if ( ca->cleanup ) {
4507 rc = ca->cleanup( ca );
4510 if (ca->cr_msg[0] == '\0')
4511 snprintf( ca->cr_msg, sizeof( ca->cr_msg ), "<%s> failed startup", ca->argv[0] );
4513 Debug(LDAP_DEBUG_ANY, "%s: %s (%s)!\n",
4514 ca->log, ca->cr_msg, ca->argv[1] );
4521 ce = ch_calloc( 1, sizeof(CfEntryInfo) );
4522 ce->ce_parent = last;
4523 ce->ce_entry = entry_dup( e );
4524 ce->ce_entry->e_private = ce;
4525 ce->ce_type = colst[0]->co_type;
4528 ce->ce_private = ca->ca_private;
4529 ca->ca_entry = ce->ce_entry;
4532 } else if ( last->ce_kids ) {
4533 CfEntryInfo *c2, **cprev;
4535 /* Advance to first of this type */
4536 cprev = &last->ce_kids;
4537 for ( c2 = *cprev; c2 && c2->ce_type < ce->ce_type; ) {
4538 cprev = &c2->ce_sibs;
4541 /* Account for the (-1) frontendDB entry */
4542 if ( ce->ce_type == Cft_Database ) {
4543 if ( ca->be == frontendDB )
4545 else if ( ibase != -1 )
4550 for (c2 = *cprev; c2 && c2->ce_type == ce->ce_type;) {
4551 cprev = &c2->ce_sibs;
4557 for ( i=0; i<ibase; i++ ) {
4559 cprev = &c2->ce_sibs;
4562 ce->ce_sibs = *cprev;
4570 if ( (colst[0]->co_type == Cft_Database) && ca->be ) {
4571 if ( ca->be != frontendDB )
4572 backend_destroy_one( ca->be, 1 );
4573 } else if ( (colst[0]->co_type == Cft_Overlay) && ca->bi ) {
4574 overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
4575 } else if ( colst[0]->co_type == Cft_Schema ) {
4576 schema_destroy_one( ca, colst, nocs, last );
4581 ch_free( ca->argv );
4582 if ( colst ) ch_free( colst );
4586 #define BIGTMP 10000
4588 config_rename_add( Operation *op, SlapReply *rs, CfEntryInfo *ce,
4589 int base, int rebase, int max, int use_ldif )
4591 CfEntryInfo *ce2, *ce3, *cetmp = NULL, *cerem = NULL;
4592 ConfigType etype = ce->ce_type;
4593 int count = 0, rc = 0;
4595 /* Reverse ce list */
4596 for (ce2 = ce->ce_sibs;ce2;ce2 = ce3) {
4597 if (ce2->ce_type != etype) {
4602 ce2->ce_sibs = cetmp;
4605 if ( max && count >= max ) {
4611 /* Move original to a temp name until increments are done */
4613 ce->ce_entry->e_private = NULL;
4614 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4615 base+BIGTMP, 0, use_ldif );
4616 ce->ce_entry->e_private = ce;
4618 /* start incrementing */
4619 for (ce2=cetmp; ce2; ce2=ce3) {
4621 ce2->ce_sibs = cerem;
4624 rc = config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
4625 count+base, 0, use_ldif );
4629 rc = config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4630 base, 0, use_ldif );
4635 config_rename_del( Operation *op, SlapReply *rs, CfEntryInfo *ce,
4636 CfEntryInfo *ce2, int old, int use_ldif )
4640 /* Renumber original to a temp value */
4641 ce->ce_entry->e_private = NULL;
4642 config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4643 old+BIGTMP, 0, use_ldif );
4644 ce->ce_entry->e_private = ce;
4646 /* start decrementing */
4647 for (; ce2 != ce; ce2=ce2->ce_sibs) {
4648 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
4649 count+old, 0, use_ldif );
4652 return config_renumber_one( op, rs, ce->ce_parent, ce->ce_entry,
4653 count+old, 0, use_ldif );
4656 /* Parse an LDAP entry into config directives, then store in underlying
4660 config_back_add( Operation *op, SlapReply *rs )
4666 if ( !access_allowed( op, op->ora_e, slap_schema.si_ad_entry,
4667 NULL, ACL_WADD, NULL )) {
4668 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4673 * Check for attribute ACL
4675 if ( !acl_check_modlist( op, op->ora_e, op->orm_modlist )) {
4676 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
4677 rs->sr_text = "no write access to attribute";
4681 cfb = (CfBackInfo *)op->o_bd->be_private;
4683 /* add opattrs for syncprov */
4685 char textbuf[SLAP_TEXT_BUFLEN];
4686 size_t textlen = sizeof textbuf;
4687 rs->sr_err = entry_schema_check(op, op->ora_e, NULL, 0, 1,
4688 &rs->sr_text, textbuf, sizeof( textbuf ) );
4689 if ( rs->sr_err != LDAP_SUCCESS )
4691 rs->sr_err = slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
4692 if ( rs->sr_err != LDAP_SUCCESS ) {
4693 Debug( LDAP_DEBUG_TRACE,
4694 LDAP_XSTRING(config_back_add) ": entry failed op attrs add: "
4695 "%s (%d)\n", rs->sr_text, rs->sr_err, 0 );
4700 ldap_pvt_thread_pool_pause( &connection_pool );
4703 * 1) check for existence of entry
4704 * 2) check for sibling renumbering
4705 * 3) perform internal add
4706 * 4) perform any necessary renumbering
4707 * 5) store entry in underlying database
4709 rs->sr_err = config_add_internal( cfb, op->ora_e, &ca, rs, &renumber, op );
4710 if ( rs->sr_err != LDAP_SUCCESS ) {
4711 rs->sr_text = ca.cr_msg;
4716 CfEntryInfo *ce = ca.ca_entry->e_private;
4717 req_add_s addr = op->oq_add;
4718 op->o_tag = LDAP_REQ_MODRDN;
4719 rs->sr_err = config_rename_add( op, rs, ce, ca.valx, 0, 0, cfb->cb_use_ldif );
4720 op->o_tag = LDAP_REQ_ADD;
4722 if ( rs->sr_err != LDAP_SUCCESS ) {
4727 if ( cfb->cb_use_ldif ) {
4728 BackendDB *be = op->o_bd;
4729 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
4730 struct berval dn, ndn;
4732 op->o_bd = &cfb->cb_db;
4734 /* Save current rootdn; use the underlying DB's rootdn */
4737 op->o_dn = op->o_bd->be_rootdn;
4738 op->o_ndn = op->o_bd->be_rootndn;
4740 scp = op->o_callback;
4741 op->o_callback = ≻
4742 op->o_bd->be_add( op, rs );
4744 op->o_callback = scp;
4750 ldap_pvt_thread_pool_resume( &connection_pool );
4753 send_ldap_result( op, rs );
4754 slap_graduate_commit_csn( op );
4758 typedef struct delrec {
4759 struct delrec *next;
4765 config_modify_add( ConfigTable *ct, ConfigArgs *ca, AttributeDescription *ad,
4770 if (ad->ad_type->sat_flags & SLAP_AT_ORDERED &&
4771 ca->line[0] == '{' )
4773 char *ptr = strchr( ca->line + 1, '}' );
4777 ca->valx = strtol( ca->line + 1, &next, 0 );
4778 if ( next == ca->line + 1 || next[ 0 ] != '}' ) {
4784 rc = config_parse_add( ct, ca, i );
4792 config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs,
4795 int rc = LDAP_UNWILLING_TO_PERFORM;
4797 Entry *e = ce->ce_entry;
4798 Attribute *save_attrs = e->e_attrs, *oc_at, *s, *a;
4803 delrec *dels = NULL, *deltail = NULL;
4805 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
4806 if ( !oc_at ) return LDAP_OBJECT_CLASS_VIOLATION;
4808 colst = count_ocs( oc_at, &nocs );
4810 /* make sure add/del flags are clear; should always be true */
4811 for ( s = save_attrs; s; s = s->a_next ) {
4812 s->a_flags &= ~(SLAP_ATTR_IXADD|SLAP_ATTR_IXDEL);
4815 e->e_attrs = attrs_dup( e->e_attrs );
4817 init_config_argv( ca );
4820 ca->ca_private = ce->ce_private;
4822 ca->fname = "slapd";
4824 strcpy( ca->log, "back-config" );
4826 for (ml = op->orm_modlist; ml; ml=ml->sml_next) {
4827 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
4828 switch (ml->sml_op) {
4829 case LDAP_MOD_DELETE:
4830 case LDAP_MOD_REPLACE: {
4831 BerVarray vals = NULL, nvals = NULL;
4833 if ( ct && ( ct->arg_type & ARG_NO_DELETE )) {
4835 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot delete %s",
4836 ml->sml_desc->ad_cname.bv_val );
4839 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4840 vals = ml->sml_values;
4841 nvals = ml->sml_nvalues;
4842 ml->sml_values = NULL;
4843 ml->sml_nvalues = NULL;
4845 /* If we're deleting by values, remember the indexes of the
4846 * values we deleted.
4848 if ( ct && ml->sml_values ) {
4850 i = ml->sml_numvals;
4851 d = ch_malloc( sizeof(delrec) + (i - 1)* sizeof(int));
4862 rc = modify_delete_vindex(e, &ml->sml_mod,
4863 get_permissiveModify(op),
4864 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg), idx );
4865 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4866 ml->sml_values = vals;
4867 ml->sml_nvalues = nvals;
4872 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
4875 case SLAP_MOD_SOFTADD: {
4876 int mop = ml->sml_op;
4878 ml->sml_op = LDAP_MOD_ADD;
4880 if ( ct->arg_type & ARG_NO_INSERT ) {
4881 Attribute *a = attr_find( e->e_attrs, ml->sml_desc );
4883 navals = a->a_numvals;
4886 for ( i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++ ) {
4887 if ( ml->sml_values[i].bv_val[0] == '{' &&
4890 char *next, *val = ml->sml_values[i].bv_val + 1;
4893 j = strtol( val, &next, 0 );
4894 if ( next == val || next[ 0 ] != '}' || j < navals ) {
4896 snprintf(ca->cr_msg, sizeof(ca->cr_msg), "cannot insert %s",
4897 ml->sml_desc->ad_cname.bv_val );
4901 rc = check_vals( ct, ca, ml, 0 );
4902 if ( rc ) goto out_noop;
4905 rc = modify_add_values(e, &ml->sml_mod,
4906 get_permissiveModify(op),
4907 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
4909 /* If value already exists, show success here
4910 * and ignore this operation down below.
4912 if ( mop == SLAP_MOD_SOFTADD ) {
4913 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS )
4923 case LDAP_MOD_INCREMENT: /* FIXME */
4928 if(rc != LDAP_SUCCESS) break;
4931 if ( rc == LDAP_SUCCESS) {
4932 /* check that the entry still obeys the schema */
4933 rc = entry_schema_check(op, e, NULL, 0, 0,
4934 &rs->sr_text, ca->cr_msg, sizeof(ca->cr_msg) );
4936 if ( rc ) goto out_noop;
4938 /* Basic syntax checks are OK. Do the actual settings. */
4939 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
4940 ct = config_find_table( colst, nocs, ml->sml_desc, ca );
4941 if ( !ct ) continue;
4943 s = attr_find( save_attrs, ml->sml_desc );
4944 a = attr_find( e->e_attrs, ml->sml_desc );
4946 switch (ml->sml_op) {
4947 case LDAP_MOD_DELETE:
4948 case LDAP_MOD_REPLACE: {
4949 BerVarray vals = NULL, nvals = NULL;
4952 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
4953 vals = ml->sml_values;
4954 nvals = ml->sml_nvalues;
4955 ml->sml_values = NULL;
4956 ml->sml_nvalues = NULL;
4959 if ( ml->sml_values )
4962 /* If we didn't delete the whole attribute */
4963 if ( ml->sml_values && a ) {
4964 struct berval *mvals;
4967 if ( ml->sml_nvalues )
4968 mvals = ml->sml_nvalues;
4970 mvals = ml->sml_values;
4972 /* use the indexes we saved up above */
4973 for (i=0; i < d->nidx; i++) {
4974 struct berval bv = *mvals++;
4975 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_ORDERED &&
4976 bv.bv_val[0] == '{' ) {
4977 ptr = strchr( bv.bv_val, '}' ) + 1;
4978 bv.bv_len -= ptr - bv.bv_val;
4981 ca->line = bv.bv_val;
4982 ca->valx = d->idx[i];
4983 rc = config_del_vals( ct, ca );
4984 if ( rc != LDAP_SUCCESS ) break;
4986 s->a_flags |= SLAP_ATTR_IXDEL;
4987 for (j=i+1; j < d->nidx; j++)
4988 if ( d->idx[j] >d->idx[i] )
4994 rc = config_del_vals( ct, ca );
4995 if ( rc ) rc = LDAP_OTHER;
4997 s->a_flags |= SLAP_ATTR_IXDEL;
4999 if ( ml->sml_values ) {
5004 if ( ml->sml_op == LDAP_MOD_REPLACE ) {
5005 ml->sml_values = vals;
5006 ml->sml_nvalues = nvals;
5008 if ( !vals || rc != LDAP_SUCCESS )
5011 /* FALLTHRU: LDAP_MOD_REPLACE && vals */
5014 for (i=0; ml->sml_values[i].bv_val; i++) {
5015 ca->line = ml->sml_values[i].bv_val;
5017 rc = config_modify_add( ct, ca, ml->sml_desc, i );
5020 a->a_flags |= SLAP_ATTR_IXADD;
5027 /* Undo for a failed operation */
5028 if ( rc != LDAP_SUCCESS ) {
5029 ConfigReply msg = ca->reply;
5030 for ( s = save_attrs; s; s = s->a_next ) {
5031 if ( s->a_flags & SLAP_ATTR_IXDEL ) {
5032 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5033 ct = config_find_table( colst, nocs, s->a_desc, ca );
5034 a = attr_find( e->e_attrs, s->a_desc );
5036 /* clear the flag so the add check below will skip it */
5037 a->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5040 config_del_vals( ct, ca );
5042 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5043 ca->line = s->a_vals[i].bv_val;
5045 config_modify_add( ct, ca, s->a_desc, i );
5049 for ( a = e->e_attrs; a; a = a->a_next ) {
5050 if ( a->a_flags & SLAP_ATTR_IXADD ) {
5051 ct = config_find_table( colst, nocs, a->a_desc, ca );
5054 config_del_vals( ct, ca );
5055 s = attr_find( save_attrs, a->a_desc );
5057 s->a_flags &= ~(SLAP_ATTR_IXDEL|SLAP_ATTR_IXADD);
5058 for ( i=0; !BER_BVISNULL( &s->a_vals[i] ); i++ ) {
5059 ca->line = s->a_vals[i].bv_val;
5061 config_modify_add( ct, ca, s->a_desc, i );
5072 if ( rc == LDAP_SUCCESS ) {
5073 attrs_free( save_attrs );
5075 attrs_free( e->e_attrs );
5076 e->e_attrs = save_attrs;
5078 ch_free( ca->argv );
5079 if ( colst ) ch_free( colst );
5081 deltail = dels->next;
5090 config_back_modify( Operation *op, SlapReply *rs )
5093 CfEntryInfo *ce, *last;
5095 ConfigArgs ca = {0};
5098 AttributeDescription *rad = NULL;
5101 cfb = (CfBackInfo *)op->o_bd->be_private;
5103 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5106 rs->sr_matched = last->ce_entry->e_name.bv_val;
5107 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5111 if ( !acl_check_modlist( op, ce->ce_entry, op->orm_modlist )) {
5112 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5116 /* Get type of RDN */
5117 rdn = ce->ce_entry->e_nname;
5118 ptr = strchr( rdn.bv_val, '=' );
5119 rdn.bv_len = ptr - rdn.bv_val;
5120 slap_bv2ad( &rdn, &rad, &rs->sr_text );
5122 /* Some basic validation... */
5123 for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
5124 /* Don't allow Modify of RDN; must use ModRdn for that. */
5125 if ( ml->sml_desc == rad ) {
5126 rs->sr_err = LDAP_NOT_ALLOWED_ON_RDN;
5127 rs->sr_text = "Use modrdn to change the entry name";
5130 /* Internal update of contextCSN? */
5131 if ( ml->sml_desc == slap_schema.si_ad_contextCSN && op->o_conn->c_conn_idx == -1 ) {
5137 slap_mods_opattrs( op, &op->orm_modlist, 1 );
5140 ldap_pvt_thread_pool_pause( &connection_pool );
5143 * 1) perform the Modify on the cached Entry.
5144 * 2) verify that the Entry still satisfies the schema.
5145 * 3) perform the individual config operations.
5146 * 4) store Modified entry in underlying LDIF backend.
5148 rs->sr_err = config_modify_internal( ce, op, rs, &ca );
5150 rs->sr_text = ca.cr_msg;
5151 } else if ( cfb->cb_use_ldif ) {
5152 BackendDB *be = op->o_bd;
5153 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5154 struct berval dn, ndn;
5156 op->o_bd = &cfb->cb_db;
5160 op->o_dn = op->o_bd->be_rootdn;
5161 op->o_ndn = op->o_bd->be_rootndn;
5163 scp = op->o_callback;
5164 op->o_callback = ≻
5165 op->o_bd->be_modify( op, rs );
5167 op->o_callback = scp;
5173 ldap_pvt_thread_pool_resume( &connection_pool );
5175 send_ldap_result( op, rs );
5176 slap_graduate_commit_csn( op );
5181 config_back_modrdn( Operation *op, SlapReply *rs )
5184 CfEntryInfo *ce, *last;
5188 cfb = (CfBackInfo *)op->o_bd->be_private;
5190 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5193 rs->sr_matched = last->ce_entry->e_name.bv_val;
5194 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5197 if ( !access_allowed( op, ce->ce_entry, slap_schema.si_ad_entry,
5198 NULL, ACL_WRITE, NULL )) {
5199 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5203 if ( ce->ce_parent )
5204 parent = ce->ce_parent->ce_entry;
5206 parent = (Entry *)&slap_entry_root;
5207 if ( !access_allowed( op, parent, slap_schema.si_ad_children,
5208 NULL, ACL_WRITE, NULL )) {
5209 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5214 /* We don't allow moving objects to new parents.
5215 * Generally we only allow reordering a set of ordered entries.
5217 if ( op->orr_newSup ) {
5218 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5222 /* If newRDN == oldRDN, quietly succeed */
5223 dnRdn( &op->o_req_ndn, &rdn );
5224 if ( dn_match( &rdn, &op->orr_nnewrdn )) {
5225 rs->sr_err = LDAP_SUCCESS;
5229 /* Current behavior, subject to change as needed:
5231 * For backends and overlays, we only allow renumbering.
5232 * For schema, we allow renaming with the same number.
5233 * Otherwise, the op is not allowed.
5236 if ( ce->ce_type == Cft_Schema ) {
5240 /* Can't alter the main cn=schema entry */
5241 if ( ce->ce_parent->ce_type == Cft_Global ) {
5242 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5243 rs->sr_text = "renaming not allowed for this entry";
5247 /* We could support this later if desired */
5248 ptr1 = ber_bvchr( &rdn, '}' );
5249 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5250 len = ptr1 - rdn.bv_val;
5251 if ( len != ptr2 - op->orr_newrdn.bv_val ||
5252 strncmp( rdn.bv_val, op->orr_newrdn.bv_val, len )) {
5253 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5254 rs->sr_text = "schema reordering not supported";
5257 } else if ( ce->ce_type == Cft_Database ||
5258 ce->ce_type == Cft_Overlay ) {
5259 char *ptr1, *ptr2, *iptr1, *iptr2;
5262 iptr2 = ber_bvchr( &op->orr_newrdn, '=' ) + 1;
5263 if ( *iptr2 != '{' ) {
5264 rs->sr_err = LDAP_NAMING_VIOLATION;
5265 rs->sr_text = "new ordering index is required";
5269 iptr1 = ber_bvchr( &rdn, '{' ) + 1;
5270 ptr1 = ber_bvchr( &rdn, '}' );
5271 ptr2 = ber_bvchr( &op->orr_newrdn, '}' );
5273 rs->sr_err = LDAP_NAMING_VIOLATION;
5274 rs->sr_text = "new ordering index is required";
5278 len1 = ptr1 - rdn.bv_val;
5279 len2 = ptr2 - op->orr_newrdn.bv_val;
5281 if ( rdn.bv_len - len1 != op->orr_newrdn.bv_len - len2 ||
5282 strncmp( ptr1, ptr2, rdn.bv_len - len1 )) {
5283 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5284 rs->sr_text = "changing database/overlay type not allowed";
5287 ixold = strtol( iptr1, NULL, 0 );
5288 ixnew = strtol( iptr2, &ptr1, 0 );
5289 if ( ptr1 != ptr2 || ixold < 0 || ixnew < 0 ) {
5290 rs->sr_err = LDAP_NAMING_VIOLATION;
5293 /* config DB is always 0, cannot be changed */
5294 if ( ce->ce_type == Cft_Database && ( ixold == 0 || ixnew == 0 )) {
5295 rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
5299 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5300 rs->sr_text = "renaming not supported for this entry";
5304 ldap_pvt_thread_pool_pause( &connection_pool );
5306 if ( ce->ce_type == Cft_Schema ) {
5307 req_modrdn_s modr = op->oq_modrdn;
5310 rs->sr_err = config_rename_attr( rs, ce->ce_entry, &rdn, &a );
5311 if ( rs->sr_err == LDAP_SUCCESS ) {
5312 rs->sr_err = config_rename_one( op, rs, ce->ce_entry,
5313 ce->ce_parent, a, &op->orr_newrdn, &op->orr_nnewrdn,
5316 op->oq_modrdn = modr;
5318 CfEntryInfo *ce2, *cebase, **cprev, **cbprev, *ceold;
5319 req_modrdn_s modr = op->oq_modrdn;
5322 /* Advance to first of this type */
5323 cprev = &ce->ce_parent->ce_kids;
5324 for ( ce2 = *cprev; ce2 && ce2->ce_type != ce->ce_type; ) {
5325 cprev = &ce2->ce_sibs;
5328 /* Skip the -1 entry */
5329 if ( ce->ce_type == Cft_Database ) {
5330 cprev = &ce2->ce_sibs;
5336 /* Remove from old slot */
5337 for ( ce2 = *cprev; ce2 && ce2 != ce; ce2 = ce2->ce_sibs )
5338 cprev = &ce2->ce_sibs;
5339 *cprev = ce->ce_sibs;
5340 ceold = ce->ce_sibs;
5342 /* Insert into new slot */
5344 for ( i=0; i<ixnew; i++ ) {
5348 cprev = &ce2->ce_sibs;
5350 ce->ce_sibs = *cprev;
5355 /* NOTE: These should be encoded in the OC tables, not inline here */
5356 if ( ce->ce_type == Cft_Database )
5357 backend_db_move( ce->ce_be, ixnew );
5358 else if ( ce->ce_type == Cft_Overlay )
5359 overlay_move( ce->ce_be, (slap_overinst *)ce->ce_bi, ixnew );
5361 if ( ixold < ixnew ) {
5362 rs->sr_err = config_rename_del( op, rs, ce, ceold, ixold,
5365 rs->sr_err = config_rename_add( op, rs, ce, ixnew, 1,
5366 ixold - ixnew, cfb->cb_use_ldif );
5368 op->oq_modrdn = modr;
5371 ldap_pvt_thread_pool_resume( &connection_pool );
5373 send_ldap_result( op, rs );
5378 config_back_delete( Operation *op, SlapReply *rs )
5380 #ifdef SLAP_CONFIG_DELETE
5382 CfEntryInfo *ce, *last, *ce2;
5384 cfb = (CfBackInfo *)op->o_bd->be_private;
5386 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5389 rs->sr_matched = last->ce_entry->e_name.bv_val;
5390 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5391 } else if ( ce->ce_kids ) {
5392 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5393 } else if ( ce->ce_type == Cft_Overlay ){
5397 ldap_pvt_thread_pool_pause( &connection_pool );
5399 overlay_remove( ce->ce_be, (slap_overinst *)ce->ce_bi );
5401 /* remove CfEntryInfo from the siblings list */
5402 if ( ce->ce_parent->ce_kids == ce ) {
5403 ce->ce_parent->ce_kids = ce->ce_sibs;
5405 for ( ce2 = ce->ce_parent->ce_kids ; ce2; ce2 = ce2->ce_sibs ) {
5406 if ( ce2->ce_sibs == ce ) {
5407 ce2->ce_sibs = ce->ce_sibs;
5413 /* remove from underlying database */
5414 if ( cfb->cb_use_ldif ) {
5415 BackendDB *be = op->o_bd;
5416 slap_callback sc = { NULL, slap_null_cb, NULL, NULL }, *scp;
5417 struct berval dn, ndn, req_dn, req_ndn;
5419 op->o_bd = &cfb->cb_db;
5423 req_dn = op->o_req_dn;
5424 req_ndn = op->o_req_ndn;
5426 op->o_dn = op->o_bd->be_rootdn;
5427 op->o_ndn = op->o_bd->be_rootndn;
5428 op->o_req_dn = ce->ce_entry->e_name;
5429 op->o_req_ndn = ce->ce_entry->e_nname;
5431 scp = op->o_callback;
5432 op->o_callback = ≻
5433 op->o_bd->be_delete( op, rs );
5435 op->o_callback = scp;
5438 op->o_req_dn = req_dn;
5439 op->o_req_ndn = req_ndn;
5442 /* renumber siblings */
5443 iptr = ber_bvchr( &op->o_req_ndn, '{' ) + 1;
5444 ixold = strtol( iptr, NULL, 0 );
5445 for (ce2 = ce->ce_sibs, count=0; ce2; ce2=ce2->ce_sibs) {
5446 config_renumber_one( op, rs, ce2->ce_parent, ce2->ce_entry,
5447 count+ixold, 0, cfb->cb_use_ldif );
5451 ce->ce_entry->e_private=NULL;
5452 entry_free(ce->ce_entry);
5454 ldap_pvt_thread_pool_resume( &connection_pool );
5456 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5459 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
5460 #endif /* SLAP_CONFIG_DELETE */
5461 send_ldap_result( op, rs );
5466 config_back_search( Operation *op, SlapReply *rs )
5469 CfEntryInfo *ce, *last;
5472 cfb = (CfBackInfo *)op->o_bd->be_private;
5474 ce = config_find_base( cfb->cb_root, &op->o_req_ndn, &last );
5477 rs->sr_matched = last->ce_entry->e_name.bv_val;
5478 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5481 if ( !access_allowed_mask( op, ce->ce_entry, slap_schema.si_ad_entry, NULL,
5482 ACL_SEARCH, NULL, &mask ))
5484 if ( !ACL_GRANT( mask, ACL_DISCLOSE )) {
5485 rs->sr_err = LDAP_NO_SUCH_OBJECT;
5487 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
5491 switch ( op->ors_scope ) {
5492 case LDAP_SCOPE_BASE:
5493 case LDAP_SCOPE_SUBTREE:
5494 config_send( op, rs, ce, 0 );
5497 case LDAP_SCOPE_ONELEVEL:
5498 for (ce = ce->ce_kids; ce; ce=ce->ce_sibs) {
5499 config_send( op, rs, ce, 1 );
5504 rs->sr_err = LDAP_SUCCESS;
5506 send_ldap_result( op, rs );
5510 /* no-op, we never free entries */
5511 int config_entry_release(
5516 if ( !e->e_private ) {
5519 return LDAP_SUCCESS;
5522 /* return LDAP_SUCCESS IFF we can retrieve the specified entry.
5524 int config_back_entry_get(
5528 AttributeDescription *at,
5533 CfEntryInfo *ce, *last;
5534 int rc = LDAP_NO_SUCH_OBJECT;
5536 cfb = (CfBackInfo *)op->o_bd->be_private;
5538 ce = config_find_base( cfb->cb_root, ndn, &last );
5540 *ent = ce->ce_entry;
5543 if ( oc && !is_entry_objectclass_or_sub( *ent, oc ) ) {
5544 rc = LDAP_NO_SUCH_ATTRIBUTE;
5554 config_build_attrs( Entry *e, AttributeType **at, AttributeDescription *ad,
5555 ConfigTable *ct, ConfigArgs *c )
5559 for (; at && *at; at++) {
5560 /* Skip the naming attr */
5561 if ((*at)->sat_ad == ad || (*at)->sat_ad == slap_schema.si_ad_cn )
5563 for (i=0;ct[i].name;i++) {
5564 if (ct[i].ad == (*at)->sat_ad) {
5565 rc = config_get_vals(&ct[i], c);
5566 /* NOTE: tolerate that config_get_vals()
5567 * returns success with no values */
5568 if (rc == LDAP_SUCCESS && c->rvalue_vals != NULL ) {
5569 if ( c->rvalue_nvals )
5570 rc = attr_merge(e, ct[i].ad, c->rvalue_vals,
5573 slap_syntax_validate_func *validate =
5574 ct[i].ad->ad_type->sat_syntax->ssyn_validate;
5577 for ( j=0; c->rvalue_vals[j].bv_val; j++ ) {
5578 rc = ordered_value_validate( ct[i].ad,
5579 &c->rvalue_vals[j], LDAP_MOD_ADD );
5581 Debug( LDAP_DEBUG_ANY,
5582 "config_build_attrs: error %d on %s value #%d\n",
5583 rc, ct[i].ad->ad_cname.bv_val, j );
5589 rc = attr_merge_normalize(e, ct[i].ad,
5590 c->rvalue_vals, NULL);
5592 ber_bvarray_free( c->rvalue_nvals );
5593 ber_bvarray_free( c->rvalue_vals );
5595 Debug( LDAP_DEBUG_ANY,
5596 "config_build_attrs: error %d on %s\n",
5597 rc, ct[i].ad->ad_cname.bv_val, 0 );
5609 config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
5610 ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra )
5612 Entry *e = entry_alloc();
5613 CfEntryInfo *ce = ch_calloc( 1, sizeof(CfEntryInfo) );
5615 struct berval ad_name;
5616 AttributeDescription *ad = NULL;
5619 const char *text = "";
5623 CfEntryInfo *ceprev = NULL;
5625 Debug( LDAP_DEBUG_TRACE, "config_build_entry: \"%s\"\n", rdn->bv_val, 0, 0);
5628 ce->ce_type = main->co_type;
5629 ce->ce_parent = parent;
5631 pdn = parent->ce_entry->e_nname;
5632 if ( parent->ce_kids && parent->ce_kids->ce_type <= ce->ce_type )
5633 for ( ceprev = parent->ce_kids; ceprev->ce_sibs &&
5634 ceprev->ce_type <= ce->ce_type;
5635 ceprev = ceprev->ce_sibs );
5640 ce->ce_private = c->ca_private;
5644 build_new_dn( &e->e_name, &pdn, rdn, NULL );
5645 ber_dupbv( &e->e_nname, &e->e_name );
5647 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
5648 main->co_name, NULL );
5650 attr_merge_normalize_one(e, slap_schema.si_ad_objectClass,
5651 extra->co_name, NULL );
5652 ptr = strchr(rdn->bv_val, '=');
5653 ad_name.bv_val = rdn->bv_val;
5654 ad_name.bv_len = ptr - rdn->bv_val;
5655 rc = slap_bv2ad( &ad_name, &ad, &text );
5660 val.bv_len = rdn->bv_len - (val.bv_val - rdn->bv_val);
5661 attr_merge_normalize_one(e, ad, &val, NULL );
5664 c->table = main->co_type;
5665 if ( oc->soc_required ) {
5666 rc = config_build_attrs( e, oc->soc_required, ad, main->co_table, c );
5667 if ( rc ) goto fail;
5670 if ( oc->soc_allowed ) {
5671 rc = config_build_attrs( e, oc->soc_allowed, ad, main->co_table, c );
5672 if ( rc ) goto fail;
5677 c->table = extra->co_type;
5678 if ( oc->soc_required ) {
5679 rc = config_build_attrs( e, oc->soc_required, ad, extra->co_table, c );
5680 if ( rc ) goto fail;
5683 if ( oc->soc_allowed ) {
5684 rc = config_build_attrs( e, oc->soc_allowed, ad, extra->co_table, c );
5685 if ( rc ) goto fail;
5689 oc_at = attr_find( e->e_attrs, slap_schema.si_ad_objectClass );
5690 rc = structural_class(oc_at->a_vals, &oc, NULL, &text, c->cr_msg,
5691 sizeof(c->cr_msg), op ? op->o_tmpmemctx : NULL );
5692 if ( rc != LDAP_SUCCESS ) {
5694 Debug( LDAP_DEBUG_ANY,
5695 "config_build_entry: build \"%s\" failed: \"%s\"\n",
5696 rdn->bv_val, text, 0);
5699 attr_merge_normalize_one(e, slap_schema.si_ad_structuralObjectClass, &oc->soc_cname, NULL );
5702 op->ora_modlist = NULL;
5703 slap_add_opattrs( op, NULL, NULL, 0, 0 );
5704 if ( !op->o_noop ) {
5705 op->o_bd->be_add( op, rs );
5706 if ( ( rs->sr_err != LDAP_SUCCESS )
5707 && (rs->sr_err != LDAP_ALREADY_EXISTS) ) {
5713 ce->ce_sibs = ceprev->ce_sibs;
5714 ceprev->ce_sibs = ce;
5715 } else if ( parent ) {
5716 ce->ce_sibs = parent->ce_kids;
5717 parent->ce_kids = ce;
5724 config_build_schema_inc( ConfigArgs *c, CfEntryInfo *ceparent,
5725 Operation *op, SlapReply *rs )
5728 ConfigFile *cf = c->ca_private;
5730 struct berval bv, rdn;
5732 for (; cf; cf=cf->c_sibs, c->depth++) {
5733 if ( !cf->c_at_head && !cf->c_cr_head && !cf->c_oc_head &&
5734 !cf->c_om_head && !cf->c_syn_head ) continue;
5735 c->value_dn.bv_val = c->log;
5736 LUTIL_SLASHPATH( cf->c_file.bv_val );
5737 bv.bv_val = strrchr(cf->c_file.bv_val, LDAP_DIRSEP[0]);
5742 bv.bv_len = cf->c_file.bv_len - (bv.bv_val - cf->c_file.bv_val);
5744 ptr = strchr( bv.bv_val, '.' );
5746 bv.bv_len = ptr - bv.bv_val;
5747 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=" SLAP_X_ORDERED_FMT, c->depth);
5748 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
5749 /* FIXME: how can indicate error? */
5752 strncpy( c->value_dn.bv_val + c->value_dn.bv_len, bv.bv_val,
5754 c->value_dn.bv_len += bv.bv_len;
5755 c->value_dn.bv_val[c->value_dn.bv_len] ='\0';
5759 e = config_build_entry( op, rs, ceparent, c, &rdn,
5760 &CFOC_SCHEMA, NULL );
5763 } else if ( e && cf->c_kids ) {
5764 c->ca_private = cf->c_kids;
5765 config_build_schema_inc( c, e->e_private, op, rs );
5771 #ifdef SLAPD_MODULES
5774 config_build_modules( ConfigArgs *c, CfEntryInfo *ceparent,
5775 Operation *op, SlapReply *rs )
5780 for (i=0, mp=&modpaths; mp; mp=mp->mp_next, i++) {
5781 if ( BER_BVISNULL( &mp->mp_path ) && !mp->mp_loads )
5783 c->value_dn.bv_val = c->log;
5784 c->value_dn.bv_len = snprintf(c->value_dn.bv_val, sizeof( c->log ), "cn=module" SLAP_X_ORDERED_FMT, i);
5785 if ( c->value_dn.bv_len >= sizeof( c->log ) ) {
5786 /* FIXME: how can indicate error? */
5790 if ( ! config_build_entry( op, rs, ceparent, c, &c->value_dn, &CFOC_MODULE, NULL )) {
5799 config_check_schema(Operation *op, CfBackInfo *cfb)
5801 struct berval schema_dn = BER_BVC(SCHEMA_RDN "," CONFIG_RDN);
5803 CfEntryInfo *ce, *last;
5806 /* If there's no root entry, we must be in the midst of converting */
5807 if ( !cfb->cb_root )
5810 /* Make sure the main schema entry exists */
5811 ce = config_find_base( cfb->cb_root, &schema_dn, &last );
5818 /* Make sure it's up to date */
5819 if ( cf_om_tail != om_sys_tail ) {
5820 a = attr_find( e->e_attrs, cfAd_om );
5822 if ( a->a_nvals != a->a_vals )
5823 ber_bvarray_free( a->a_nvals );
5824 ber_bvarray_free( a->a_vals );
5829 oidm_unparse( &bv, NULL, NULL, 1 );
5830 attr_merge_normalize( e, cfAd_om, bv, NULL );
5831 ber_bvarray_free( bv );
5832 cf_om_tail = om_sys_tail;
5834 if ( cf_at_tail != at_sys_tail ) {
5835 a = attr_find( e->e_attrs, cfAd_attr );
5837 if ( a->a_nvals != a->a_vals )
5838 ber_bvarray_free( a->a_nvals );
5839 ber_bvarray_free( a->a_vals );
5844 at_unparse( &bv, NULL, NULL, 1 );
5845 attr_merge_normalize( e, cfAd_attr, bv, NULL );
5846 ber_bvarray_free( bv );
5847 cf_at_tail = at_sys_tail;
5849 if ( cf_oc_tail != oc_sys_tail ) {
5850 a = attr_find( e->e_attrs, cfAd_oc );
5852 if ( a->a_nvals != a->a_vals )
5853 ber_bvarray_free( a->a_nvals );
5854 ber_bvarray_free( a->a_vals );
5859 oc_unparse( &bv, NULL, NULL, 1 );
5860 attr_merge_normalize( e, cfAd_oc, bv, NULL );
5861 ber_bvarray_free( bv );
5862 cf_oc_tail = oc_sys_tail;
5864 if ( cf_syn_tail != syn_sys_tail ) {
5865 a = attr_find( e->e_attrs, cfAd_syntax );
5867 if ( a->a_nvals != a->a_vals )
5868 ber_bvarray_free( a->a_nvals );
5869 ber_bvarray_free( a->a_vals );
5874 syn_unparse( &bv, NULL, NULL, 1 );
5875 attr_merge_normalize( e, cfAd_syntax, bv, NULL );
5876 ber_bvarray_free( bv );
5877 cf_syn_tail = syn_sys_tail;
5880 SlapReply rs = {REP_RESULT};
5881 c.ca_private = NULL;
5882 e = config_build_entry( op, &rs, cfb->cb_root, &c, &schema_rdn,
5883 &CFOC_SCHEMA, NULL );
5888 ce->ce_private = cfb->cb_config;
5889 cf_at_tail = at_sys_tail;
5890 cf_oc_tail = oc_sys_tail;
5891 cf_om_tail = om_sys_tail;
5892 cf_syn_tail = syn_sys_tail;
5897 static const char *defacl[] = {
5898 NULL, "to", "*", "by", "*", "none", NULL
5902 config_back_db_open( BackendDB *be, ConfigReply *cr )
5904 CfBackInfo *cfb = be->be_private;
5907 CfEntryInfo *ce, *ceparent;
5911 Connection conn = {0};
5912 OperationBuffer opbuf;
5914 slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
5915 SlapReply rs = {REP_RESULT};
5916 void *thrctx = NULL;
5918 Debug( LDAP_DEBUG_TRACE, "config_back_db_open\n", 0, 0, 0);
5920 /* If we have no explicitly configured ACLs, don't just use
5921 * the global ACLs. Explicitly deny access to everything.
5923 if ( frontendDB->be_acl && be->be_acl == frontendDB->be_acl ) {
5924 parse_acl(be, "config_back_db_open", 0, 6, (char **)defacl, 0 );
5927 thrctx = ldap_pvt_thread_pool_context();
5928 connection_fake_init( &conn, &opbuf, thrctx );
5931 op->o_tag = LDAP_REQ_ADD;
5932 op->o_callback = &cb;
5933 op->o_bd = &cfb->cb_db;
5934 op->o_dn = op->o_bd->be_rootdn;
5935 op->o_ndn = op->o_bd->be_rootndn;
5937 if ( !cfb->cb_use_ldif ) {
5941 /* If we read the config from back-ldif, do some quick sanity checks */
5942 if ( cfb->cb_got_ldif ) {
5943 return config_check_schema( op, cfb );
5946 /* create root of tree */
5948 c.ca_private = cfb->cb_config;
5950 e = config_build_entry( op, &rs, NULL, &c, &rdn, &CFOC_GLOBAL, NULL );
5960 #ifdef SLAPD_MODULES
5961 /* Create Module nodes... */
5962 if ( modpaths.mp_loads ) {
5963 if ( config_build_modules( &c, ceparent, op, &rs ) ){
5969 /* Create schema nodes... cn=schema will contain the hardcoded core
5970 * schema, read-only. Child objects will contain runtime loaded schema
5974 c.ca_private = NULL;
5975 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_SCHEMA, NULL );
5980 ce->ce_private = cfb->cb_config;
5981 cf_at_tail = at_sys_tail;
5982 cf_oc_tail = oc_sys_tail;
5983 cf_om_tail = om_sys_tail;
5984 cf_syn_tail = syn_sys_tail;
5986 /* Create schema nodes for included schema... */
5987 if ( cfb->cb_config->c_kids ) {
5989 c.ca_private = cfb->cb_config->c_kids;
5990 if (config_build_schema_inc( &c, ce, op, &rs )) {
5995 /* Create backend nodes. Skip if they don't provide a cf_table.
5996 * There usually aren't any of these.
6000 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next) {
6001 if (!bi->bi_cf_ocs) {
6002 /* If it only supports the old config mech, complain. */
6003 if ( bi->bi_config ) {
6004 Debug( LDAP_DEBUG_ANY,
6005 "WARNING: No dynamic config support for backend %s.\n",
6006 bi->bi_type, 0, 0 );
6011 if (!bi->bi_private) continue;
6014 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6015 "%s=%s", cfAd_backend->ad_cname.bv_val, bi->bi_type);
6016 if ( rdn.bv_len >= sizeof( c.log ) ) {
6017 /* FIXME: holler ... */ ;
6020 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_BACKEND,
6027 /* Create database nodes... */
6028 frontendDB->be_cf_ocs = &CFOC_FRONTEND;
6029 LDAP_STAILQ_NEXT(frontendDB, be_next) = LDAP_STAILQ_FIRST(&backendDB);
6030 for ( i = -1, be = frontendDB ; be;
6031 i++, be = LDAP_STAILQ_NEXT( be, be_next )) {
6032 slap_overinfo *oi = NULL;
6034 if ( overlay_is_over( be )) {
6035 oi = be->bd_info->bi_private;
6041 /* If this backend supports the old config mechanism, but not
6042 * the new mech, complain.
6044 if ( !be->be_cf_ocs && bi->bi_db_config ) {
6045 Debug( LDAP_DEBUG_ANY,
6046 "WARNING: No dynamic config support for database %s.\n",
6047 bi->bi_type, 0, 0 );
6051 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6052 "%s=" SLAP_X_ORDERED_FMT "%s", cfAd_database->ad_cname.bv_val,
6054 if ( rdn.bv_len >= sizeof( c.log ) ) {
6055 /* FIXME: holler ... */ ;
6059 e = config_build_entry( op, &rs, ceparent, &c, &rdn, &CFOC_DATABASE,
6065 if ( be->be_cf_ocs && be->be_cf_ocs->co_cfadd )
6066 be->be_cf_ocs->co_cfadd( op, &rs, e, &c );
6067 /* Iterate through overlays */
6072 voidList *vl, *v0 = NULL;
6074 /* overlays are in LIFO order, must reverse stack */
6075 for (on=oi->oi_list; on; on=on->on_next) {
6076 vl = ch_malloc( sizeof( voidList ));
6081 for (j=0; vl; j++,vl=v0) {
6085 if ( on->on_bi.bi_db_config && !on->on_bi.bi_cf_ocs ) {
6086 Debug( LDAP_DEBUG_ANY,
6087 "WARNING: No dynamic config support for overlay %s.\n",
6088 on->on_bi.bi_type, 0, 0 );
6092 rdn.bv_len = snprintf(rdn.bv_val, sizeof( c.log ),
6093 "%s=" SLAP_X_ORDERED_FMT "%s",
6094 cfAd_overlay->ad_cname.bv_val, j, on->on_bi.bi_type );
6095 if ( rdn.bv_len >= sizeof( c.log ) ) {
6096 /* FIXME: holler ... */ ;
6100 oe = config_build_entry( op, &rs, ce, &c, &rdn,
6101 &CFOC_OVERLAY, c.bi->bi_cf_ocs );
6105 if ( c.bi->bi_cf_ocs && c.bi->bi_cf_ocs->co_cfadd )
6106 c.bi->bi_cf_ocs->co_cfadd( op, &rs, oe, &c );
6111 ldap_pvt_thread_pool_context_reset( thrctx );
6113 if ( unsupp && cfb->cb_use_ldif ) {
6114 Debug( LDAP_DEBUG_ANY, "\nWARNING: The converted cn=config "
6115 "directory is incomplete and may not work.\n\n", 0, 0, 0 );
6122 cfb_free_cffile( ConfigFile *cf )
6126 for (; cf; cf=next) {
6129 cfb_free_cffile( cf->c_kids );
6130 ch_free( cf->c_file.bv_val );
6131 ber_bvarray_free( cf->c_dseFiles );
6137 cfb_free_entries( CfEntryInfo *ce )
6141 for (; ce; ce=next) {
6144 cfb_free_entries( ce->ce_kids );
6145 ce->ce_entry->e_private = NULL;
6146 entry_free( ce->ce_entry );
6152 config_back_db_close( BackendDB *be, ConfigReply *cr )
6154 CfBackInfo *cfb = be->be_private;
6156 cfb_free_entries( cfb->cb_root );
6157 cfb->cb_root = NULL;
6159 if ( cfb->cb_db.bd_info ) {
6160 backend_shutdown( &cfb->cb_db );
6167 config_back_db_destroy( BackendDB *be, ConfigReply *cr )
6169 CfBackInfo *cfb = be->be_private;
6171 cfb_free_cffile( cfb->cb_config );
6173 ch_free( cfdir.bv_val );
6175 avl_free( CfOcTree, NULL );
6177 if ( cfb->cb_db.bd_info ) {
6178 cfb->cb_db.be_suffix = NULL;
6179 cfb->cb_db.be_nsuffix = NULL;
6180 BER_BVZERO( &cfb->cb_db.be_rootdn );
6181 BER_BVZERO( &cfb->cb_db.be_rootndn );
6183 backend_destroy_one( &cfb->cb_db, 0 );
6192 config_back_db_init( BackendDB *be, ConfigReply* cr )
6198 cfb->cb_config = ch_calloc( 1, sizeof(ConfigFile));
6199 cfn = cfb->cb_config;
6200 be->be_private = cfb;
6202 ber_dupbv( &be->be_rootdn, &config_rdn );
6203 ber_dupbv( &be->be_rootndn, &be->be_rootdn );
6204 ber_dupbv( &dn, &be->be_rootdn );
6205 ber_bvarray_add( &be->be_suffix, &dn );
6206 ber_dupbv( &dn, &be->be_rootdn );
6207 ber_bvarray_add( &be->be_nsuffix, &dn );
6209 /* Hide from namingContexts */
6210 SLAP_BFLAGS(be) |= SLAP_BFLAG_CONFIG;
6212 /* Check ACLs on content of Adds by default */
6213 SLAP_DBFLAGS(be) |= SLAP_DBFLAG_ACL_ADD;
6219 config_back_destroy( BackendInfo *bi )
6221 ldif_must_b64_encode_release();
6226 config_tool_entry_open( BackendDB *be, int mode )
6228 CfBackInfo *cfb = be->be_private;
6229 BackendInfo *bi = cfb->cb_db.bd_info;
6231 if ( bi && bi->bi_tool_entry_open )
6232 return bi->bi_tool_entry_open( &cfb->cb_db, mode );
6239 config_tool_entry_close( BackendDB *be )
6241 CfBackInfo *cfb = be->be_private;
6242 BackendInfo *bi = cfb->cb_db.bd_info;
6244 if ( bi && bi->bi_tool_entry_close )
6245 return bi->bi_tool_entry_close( &cfb->cb_db );
6251 config_tool_entry_first( BackendDB *be )
6253 CfBackInfo *cfb = be->be_private;
6254 BackendInfo *bi = cfb->cb_db.bd_info;
6256 if ( bi && bi->bi_tool_entry_first )
6257 return bi->bi_tool_entry_first( &cfb->cb_db );
6263 config_tool_entry_next( BackendDB *be )
6265 CfBackInfo *cfb = be->be_private;
6266 BackendInfo *bi = cfb->cb_db.bd_info;
6268 if ( bi && bi->bi_tool_entry_next )
6269 return bi->bi_tool_entry_next( &cfb->cb_db );
6275 config_tool_entry_get( BackendDB *be, ID id )
6277 CfBackInfo *cfb = be->be_private;
6278 BackendInfo *bi = cfb->cb_db.bd_info;
6280 if ( bi && bi->bi_tool_entry_get )
6281 return bi->bi_tool_entry_get( &cfb->cb_db, id );
6286 static int entry_put_got_frontend=0;
6287 static int entry_put_got_config=0;
6289 config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
6291 CfBackInfo *cfb = be->be_private;
6292 BackendInfo *bi = cfb->cb_db.bd_info;
6294 struct berval rdn, vals[ 2 ];
6296 OperationBuffer opbuf;
6298 Connection conn = {0};
6299 Operation *op = NULL;
6303 /* Create entry for frontend database if it does not exist already */
6304 if ( !entry_put_got_frontend ) {
6305 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
6306 STRLENOF( "olcDatabase" ))) {
6307 if ( strncmp( e->e_nname.bv_val +
6308 STRLENOF( "olcDatabase" ), "={-1}frontend",
6309 STRLENOF( "={-1}frontend" )) &&
6310 strncmp( e->e_nname.bv_val +
6311 STRLENOF( "olcDatabase" ), "=frontend",
6312 STRLENOF( "=frontend" ))) {
6314 vals[1].bv_val = NULL;
6315 memset( &ca, 0, sizeof(ConfigArgs));
6317 ca.bi = frontendDB->bd_info;
6318 ca.be->be_cf_ocs = &CFOC_FRONTEND;
6319 rdn.bv_val = ca.log;
6320 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
6321 "%s=" SLAP_X_ORDERED_FMT "%s",
6322 cfAd_database->ad_cname.bv_val, -1,
6324 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
6325 &CFOC_DATABASE, ca.be->be_cf_ocs );
6326 thrctx = ldap_pvt_thread_pool_context();
6327 connection_fake_init2( &conn, &opbuf, thrctx,0 );
6329 op->o_bd = &cfb->cb_db;
6330 op->o_tag = LDAP_REQ_ADD;
6332 op->o_dn = be->be_rootdn;
6333 op->o_ndn = be->be_rootndn;
6334 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
6335 if ( rc != LDAP_SUCCESS ) {
6336 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
6337 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
6341 if ( ce && bi && bi->bi_tool_entry_put &&
6342 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
6343 entry_put_got_frontend++;
6345 text->bv_val = "autocreation of \"olcDatabase={-1}frontend\" failed";
6346 text->bv_len = STRLENOF("autocreation of \"olcDatabase={-1}frontend\" failed");
6350 entry_put_got_frontend++;
6355 /* Create entry for config database if it does not exist already */
6356 if ( !entry_put_got_config && !isFrontend ) {
6357 if ( !strncmp( e->e_nname.bv_val, "olcDatabase",
6358 STRLENOF( "olcDatabase" ))) {
6359 if ( strncmp( e->e_nname.bv_val +
6360 STRLENOF( "olcDatabase" ), "={0}config",
6361 STRLENOF( "={0}config" )) &&
6362 strncmp( e->e_nname.bv_val +
6363 STRLENOF( "olcDatabase" ), "=config",
6364 STRLENOF( "=config" )) ) {
6366 vals[1].bv_val = NULL;
6367 memset( &ca, 0, sizeof(ConfigArgs));
6368 ca.be = LDAP_STAILQ_FIRST( &backendDB );
6369 ca.bi = ca.be->bd_info;
6370 rdn.bv_val = ca.log;
6371 rdn.bv_len = snprintf(rdn.bv_val, sizeof( ca.log ),
6372 "%s=" SLAP_X_ORDERED_FMT "%s",
6373 cfAd_database->ad_cname.bv_val, 0,
6375 ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn, &CFOC_DATABASE,
6378 thrctx = ldap_pvt_thread_pool_context();
6379 connection_fake_init2( &conn, &opbuf, thrctx,0 );
6381 op->o_bd = &cfb->cb_db;
6382 op->o_tag = LDAP_REQ_ADD;
6383 op->o_dn = be->be_rootdn;
6384 op->o_ndn = be->be_rootndn;
6387 rc = slap_add_opattrs(op, NULL, NULL, 0, 0);
6388 if ( rc != LDAP_SUCCESS ) {
6389 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
6390 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
6393 if (ce && bi && bi->bi_tool_entry_put &&
6394 bi->bi_tool_entry_put( &cfb->cb_db, ce, text ) != NOID ) {
6395 entry_put_got_config++;
6397 text->bv_val = "autocreation of \"olcDatabase={0}config\" failed";
6398 text->bv_len = STRLENOF("autocreation of \"olcDatabase={0}config\" failed");
6402 entry_put_got_config++;
6406 if ( bi && bi->bi_tool_entry_put &&
6407 config_add_internal( cfb, e, &ca, NULL, NULL, NULL ) == 0 )
6408 return bi->bi_tool_entry_put( &cfb->cb_db, e, text );
6415 AttributeDescription **desc;
6417 { "attribute", &cfAd_attr },
6418 { "backend", &cfAd_backend },
6419 { "database", &cfAd_database },
6420 { "include", &cfAd_include },
6421 { "ldapsyntax", &cfAd_syntax },
6422 { "objectclass", &cfAd_oc },
6423 { "objectidentifier", &cfAd_om },
6424 { "overlay", &cfAd_overlay },
6429 * add / delete: all types that may be added or deleted must use an
6430 * X-ORDERED attributeType for their RDN. Adding and deleting entries
6431 * should automatically renumber the index of any siblings as needed,
6432 * so that no gaps in the numbering sequence exist after the add/delete
6434 * What can be added:
6436 * backend objects for backend-specific config directives
6440 * delete: probably no support this time around.
6442 * modrdn: generally not done. Will be invoked automatically by add/
6443 * delete to update numbering sequence. Perform as an explicit operation
6444 * so that the renumbering effect may be replicated. Subtree rename must
6445 * be supported, since renumbering a database will affect all its child
6448 * modify: must be fully supported.
6452 config_back_initialize( BackendInfo *bi )
6454 ConfigTable *ct = config_back_cf_table;
6458 AttributeDescription *ad = NULL;
6460 static char *controls[] = {
6461 LDAP_CONTROL_MANAGEDSAIT,
6465 /* Make sure we don't exceed the bits reserved for userland */
6466 config_check_userland( CFG_LAST );
6468 bi->bi_controls = controls;
6473 bi->bi_destroy = config_back_destroy;
6475 bi->bi_db_init = config_back_db_init;
6476 bi->bi_db_config = 0;
6477 bi->bi_db_open = config_back_db_open;
6478 bi->bi_db_close = config_back_db_close;
6479 bi->bi_db_destroy = config_back_db_destroy;
6481 bi->bi_op_bind = config_back_bind;
6482 bi->bi_op_unbind = 0;
6483 bi->bi_op_search = config_back_search;
6484 bi->bi_op_compare = 0;
6485 bi->bi_op_modify = config_back_modify;
6486 bi->bi_op_modrdn = config_back_modrdn;
6487 bi->bi_op_add = config_back_add;
6488 bi->bi_op_delete = config_back_delete;
6489 bi->bi_op_abandon = 0;
6491 bi->bi_extended = 0;
6493 bi->bi_chk_referrals = 0;
6495 bi->bi_access_allowed = slap_access_allowed;
6497 bi->bi_connection_init = 0;
6498 bi->bi_connection_destroy = 0;
6500 bi->bi_entry_release_rw = config_entry_release;
6501 bi->bi_entry_get_rw = config_back_entry_get;
6503 bi->bi_tool_entry_open = config_tool_entry_open;
6504 bi->bi_tool_entry_close = config_tool_entry_close;
6505 bi->bi_tool_entry_first = config_tool_entry_first;
6506 bi->bi_tool_entry_next = config_tool_entry_next;
6507 bi->bi_tool_entry_get = config_tool_entry_get;
6508 bi->bi_tool_entry_put = config_tool_entry_put;
6511 argv[ 0 ] = "slapd";
6517 for (i=0; OidMacros[i].name; i++ ) {
6518 argv[1] = OidMacros[i].name;
6519 argv[2] = OidMacros[i].oid;
6520 parse_oidm( &ca, 0, NULL );
6523 bi->bi_cf_ocs = cf_ocs;
6525 i = config_register_schema( ct, cf_ocs );
6528 i = slap_str2ad( "olcDatabase", &olcDatabaseDummy[0].ad, &text );
6531 /* setup olcRootPW to be base64-encoded when written in LDIF form;
6532 * basically, we don't care if it fails */
6533 i = slap_str2ad( "olcRootPW", &ad, &text );
6535 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
6536 "warning, unable to get \"olcRootPW\" "
6537 "attribute description: %d: %s\n",
6540 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
6541 ad->ad_type->sat_oid );
6544 /* set up the notable AttributeDescriptions */
6546 for (;ct->name;ct++) {
6547 if (strcmp(ct->name, ads[i].name)) continue;
6548 *ads[i].desc = ct->ad;
6550 if (!ads[i].name) break;